From cfba8dec897277687288b8dd7546a0ec252cc32c Mon Sep 17 00:00:00 2001 From: Emmanuel Vadot Date: Fri, 15 Jun 2018 08:36:21 +0000 Subject: allwinner: ccung: Fully subclass the clock drivers Each clock drivers if now fully subclassed, this have the advantage that we can control the probe order. Some clocks can have parents from other drivers, for example clocks in the sun8i_r driver uses clocks from the main clock driver. This worked before because the sun8i_r node is after the main ccu node in the dtb and driver are probed in DTB order. This cannot work with the Display Engine clocks as it is the first node in the DTB. Tested on: A83T, H5 A64 Tested on: A20 (kevans) --- sys/arm/allwinner/clkng/aw_ccung.c | 167 +++++--------------------- sys/arm/allwinner/clkng/aw_ccung.h | 51 +++++--- sys/arm/allwinner/clkng/ccu_a10.c | 158 +++++++++++++------------ sys/arm/allwinner/clkng/ccu_a10.h | 36 ------ sys/arm/allwinner/clkng/ccu_a13.c | 131 +++++++++++---------- sys/arm/allwinner/clkng/ccu_a13.h | 34 ------ sys/arm/allwinner/clkng/ccu_a31.c | 215 +++++++++++++++++----------------- sys/arm/allwinner/clkng/ccu_a31.h | 34 ------ sys/arm/allwinner/clkng/ccu_a64.c | 189 ++++++++++++++++-------------- sys/arm/allwinner/clkng/ccu_a64.h | 34 ------ sys/arm/allwinner/clkng/ccu_a83t.c | 190 +++++++++++++++--------------- sys/arm/allwinner/clkng/ccu_a83t.h | 35 ------ sys/arm/allwinner/clkng/ccu_h3.c | 193 +++++++++++++++++------------- sys/arm/allwinner/clkng/ccu_h3.h | 34 ------ sys/arm/allwinner/clkng/ccu_sun8i_r.c | 155 +++++++++++++++++------- sys/arm/allwinner/clkng/ccu_sun8i_r.h | 34 ------ 16 files changed, 749 insertions(+), 941 deletions(-) delete mode 100644 sys/arm/allwinner/clkng/ccu_a10.h delete mode 100644 sys/arm/allwinner/clkng/ccu_a13.h delete mode 100644 sys/arm/allwinner/clkng/ccu_a31.h delete mode 100644 sys/arm/allwinner/clkng/ccu_a64.h delete mode 100644 sys/arm/allwinner/clkng/ccu_a83t.h delete mode 100644 sys/arm/allwinner/clkng/ccu_h3.h delete mode 100644 sys/arm/allwinner/clkng/ccu_sun8i_r.h (limited to 'sys') diff --git a/sys/arm/allwinner/clkng/aw_ccung.c b/sys/arm/allwinner/clkng/aw_ccung.c index 4c5a0c40fc05..3d40e4be16b1 100644 --- a/sys/arm/allwinner/clkng/aw_ccung.c +++ b/sys/arm/allwinner/clkng/aw_ccung.c @@ -1,6 +1,7 @@ /*- - * Copyright (c) 2017 Emmanuel Vadot - * All rights reserved. + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017,2018 Emmanuel Vadot * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -58,33 +59,6 @@ __FBSDID("$FreeBSD$"); #include "opt_soc.h" #endif -#if defined(SOC_ALLWINNER_A10) || defined(SOC_ALLWINNER_A20) -#include -#endif - -#if defined(SOC_ALLWINNER_A13) -#include -#endif - -#if defined(SOC_ALLWINNER_A31) -#include -#endif - -#if defined(SOC_ALLWINNER_A64) -#include -#include -#endif - -#if defined(SOC_ALLWINNER_H3) || defined(SOC_ALLWINNER_H5) -#include -#include -#endif - -#if defined(SOC_ALLWINNER_A83T) -#include -#include -#endif - #include "clkdev_if.h" #include "hwreset_if.h" @@ -93,35 +67,6 @@ static struct resource_spec aw_ccung_spec[] = { { -1, 0 } }; -static struct ofw_compat_data compat_data[] = { -#if defined(SOC_ALLWINNER_A10) - { "allwinner,sun4i-a10-ccu", A10_CCU }, -#endif -#if defined(SOC_ALLWINNER_A31) - { "allwinner,sun5i-a13-ccu", A13_CCU}, -#endif -#if defined(SOC_ALLWINNER_A20) - { "allwinner,sun7i-a20-ccu", A20_CCU }, -#endif -#if defined(SOC_ALLWINNER_H3) || defined(SOC_ALLWINNER_H5) - { "allwinner,sun8i-h3-ccu", H3_CCU }, - { "allwinner,sun50i-h5-ccu", H3_CCU }, - { "allwinner,sun8i-h3-r-ccu", H3_R_CCU }, -#endif -#if defined(SOC_ALLWINNER_A31) - { "allwinner,sun6i-a31-ccu", A31_CCU }, -#endif -#if defined(SOC_ALLWINNER_A64) - { "allwinner,sun50i-a64-ccu", A64_CCU }, - { "allwinner,sun50i-a64-r-ccu", A64_R_CCU }, -#endif -#if defined(SOC_ALLWINNER_A83T) - { "allwinner,sun8i-a83t-ccu", A83T_CCU }, - { "allwinner,sun8i-a83t-r-ccu", A83T_R_CCU }, -#endif - {NULL, 0 } -}; - #define CCU_READ4(sc, reg) bus_read_4((sc)->res, (reg)) #define CCU_WRITE4(sc, reg, val) bus_write_4((sc)->res, (reg), (val)) @@ -222,20 +167,6 @@ aw_ccung_device_unlock(device_t dev) mtx_unlock(&sc->mtx); } -static int -aw_ccung_probe(device_t dev) -{ - - if (!ofw_bus_status_okay(dev)) - return (ENXIO); - - if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) - return (ENXIO); - - device_set_desc(dev, "Allwinner Clock Control Unit NG"); - return (BUS_PROBE_DEFAULT); -} - static int aw_ccung_register_gates(struct aw_ccung_softc *sc) { @@ -313,10 +244,11 @@ aw_ccung_init_clocks(struct aw_ccung_softc *sc) } } -static int +int aw_ccung_attach(device_t dev) { struct aw_ccung_softc *sc; + int i; sc = device_get_softc(dev); sc->dev = dev; @@ -328,57 +260,35 @@ aw_ccung_attach(device_t dev) mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF); - sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data; - sc->clkdom = clkdom_create(dev); if (sc->clkdom == NULL) panic("Cannot create clkdom\n"); - switch (sc->type) { -#if defined(SOC_ALLWINNER_A10) - case A10_CCU: - ccu_a10_register_clocks(sc); - break; -#endif -#if defined(SOC_ALLWINNER_A13) - case A13_CCU: - ccu_a13_register_clocks(sc); - break; -#endif -#if defined(SOC_ALLWINNER_A20) - case A20_CCU: - ccu_a20_register_clocks(sc); - break; -#endif -#if defined(SOC_ALLWINNER_H3) || defined(SOC_ALLWINNER_H5) - case H3_CCU: - ccu_h3_register_clocks(sc); - break; - case H3_R_CCU: - ccu_sun8i_r_register_clocks(sc); - break; -#endif -#if defined(SOC_ALLWINNER_A31) - case A31_CCU: - ccu_a31_register_clocks(sc); - break; -#endif -#if defined(SOC_ALLWINNER_A64) - case A64_CCU: - ccu_a64_register_clocks(sc); - break; - case A64_R_CCU: - ccu_sun8i_r_register_clocks(sc); - break; -#endif -#if defined(SOC_ALLWINNER_A83T) - case A83T_CCU: - ccu_a83t_register_clocks(sc); - break; - case A83T_R_CCU: - ccu_sun8i_r_register_clocks(sc); - break; -#endif + for (i = 0; i < sc->nclks; i++) { + switch (sc->clks[i].type) { + case AW_CLK_UNDEFINED: + break; + case AW_CLK_MUX: + clknode_mux_register(sc->clkdom, sc->clks[i].clk.mux); + break; + case AW_CLK_DIV: + clknode_div_register(sc->clkdom, sc->clks[i].clk.div); + break; + case AW_CLK_FIXED: + clknode_fixed_register(sc->clkdom, + sc->clks[i].clk.fixed); + break; + case AW_CLK_NKMP: + aw_clk_nkmp_register(sc->clkdom, sc->clks[i].clk.nkmp); + break; + case AW_CLK_NM: + aw_clk_nm_register(sc->clkdom, sc->clks[i].clk.nm); + break; + case AW_CLK_PREDIV_MUX: + aw_clk_prediv_mux_register(sc->clkdom, + sc->clks[i].clk.prediv_mux); + break; + } } if (sc->gates) @@ -401,10 +311,6 @@ aw_ccung_attach(device_t dev) } static device_method_t aw_ccung_methods[] = { - /* Device interface */ - DEVMETHOD(device_probe, aw_ccung_probe), - DEVMETHOD(device_attach, aw_ccung_attach), - /* clkdev interface */ DEVMETHOD(clkdev_write_4, aw_ccung_write_4), DEVMETHOD(clkdev_read_4, aw_ccung_read_4), @@ -419,14 +325,5 @@ static device_method_t aw_ccung_methods[] = { DEVMETHOD_END }; -static driver_t aw_ccung_driver = { - "aw_ccung", - aw_ccung_methods, - sizeof(struct aw_ccung_softc), -}; - -static devclass_t aw_ccung_devclass; - -EARLY_DRIVER_MODULE(aw_ccung, simplebus, aw_ccung_driver, aw_ccung_devclass, - 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); -MODULE_VERSION(aw_ccung, 1); +DEFINE_CLASS_0(aw_ccung, aw_ccung_driver, aw_ccung_methods, + sizeof(struct aw_ccung_softc)); diff --git a/sys/arm/allwinner/clkng/aw_ccung.h b/sys/arm/allwinner/clkng/aw_ccung.h index d8f686075a5b..c6159e13fa8b 100644 --- a/sys/arm/allwinner/clkng/aw_ccung.h +++ b/sys/arm/allwinner/clkng/aw_ccung.h @@ -1,6 +1,7 @@ /*- - * Copyright (c) 2017 Emmanuel Vadot - * All rights reserved. + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017,2018 Emmanuel Vadot * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,17 +30,34 @@ #ifndef __CCU_NG_H__ #define __CCU_NG_H__ -enum aw_ccung_type { - H3_CCU = 1, - H3_R_CCU, - A31_CCU, - A64_CCU, - A64_R_CCU, - A13_CCU, - A83T_CCU, - A83T_R_CCU, - A10_CCU, - A20_CCU, +#include +#include +#include +#include +#include +#include +#include + +enum aw_ccung_clk_type { + AW_CLK_UNDEFINED = 0, + AW_CLK_MUX, + AW_CLK_DIV, + AW_CLK_FIXED, + AW_CLK_NKMP, + AW_CLK_NM, + AW_CLK_PREDIV_MUX, +}; + +struct aw_ccung_clk { + enum aw_ccung_clk_type type; + union { + struct clk_mux_def *mux; + struct clk_div_def *div; + struct clk_fixed_def *fixed; + struct aw_clk_nkmp_def *nkmp; + struct aw_clk_nm_def *nm; + struct aw_clk_prediv_mux_def *prediv_mux; + } clk; }; struct aw_ccung_softc { @@ -47,11 +65,12 @@ struct aw_ccung_softc { struct resource *res; struct clkdom *clkdom; struct mtx mtx; - int type; struct aw_ccung_reset *resets; int nresets; struct aw_ccung_gate *gates; int ngates; + struct aw_ccung_clk *clks; + int nclks; struct aw_clk_init *clk_init; int n_clk_init; }; @@ -69,4 +88,8 @@ struct aw_ccung_gate { uint32_t shift; }; +DECLARE_CLASS(aw_ccung_driver); + +int aw_ccung_attach(device_t dev); + #endif /* __CCU_NG_H__ */ diff --git a/sys/arm/allwinner/clkng/ccu_a10.c b/sys/arm/allwinner/clkng/ccu_a10.c index a8de41648f36..b8b83d70763b 100644 --- a/sys/arm/allwinner/clkng/ccu_a10.c +++ b/sys/arm/allwinner/clkng/ccu_a10.c @@ -33,23 +33,26 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include +#include +#include + +#include + +#include +#include #include #include #include #include -#include -#include -#include -#include #include #include #include -#include "ccu_a10.h" - /* Non-exported resets */ /* Non-exported clocks */ #define CLK_PLL_CORE 2 @@ -524,89 +527,98 @@ NM_CLK(spi3_clk, /* MISSING CLK_I2S1, CLK_I2S2, DE Clocks */ -static struct aw_clk_nkmp_def *nkmp_clks[] = { - &pll_core_clk, - &pll_ddr_other_clk, - &pll_ddr_clk, - &pll6_clk, - &pll_periph_sata_clk, +static struct aw_ccung_clk a10_ccu_clks[] = { + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_core_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_ddr_other_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_ddr_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll6_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_periph_sata_clk}, + { .type = AW_CLK_NM, .clk.nm = &axi_clk}, + { .type = AW_CLK_NM, .clk.nm = &ahb_clk}, + { .type = AW_CLK_NM, .clk.nm = &apb0_clk}, + { .type = AW_CLK_NM, .clk.nm = &apb1_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_video0_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_video1_clk}, + { .type = AW_CLK_NM, .clk.nm = &nand_clk}, + { .type = AW_CLK_NM, .clk.nm = &ms_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc0_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc1_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc2_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc3_clk}, + { .type = AW_CLK_NM, .clk.nm = &ts_clk}, + { .type = AW_CLK_NM, .clk.nm = &ss_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi0_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi1_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi2_clk}, + { .type = AW_CLK_NM, .clk.nm = &ir0_clk}, + { .type = AW_CLK_NM, .clk.nm = &ir1_clk}, + { .type = AW_CLK_NM, .clk.nm = &keypad_clk}, + { .type = AW_CLK_NM, .clk.nm = &sata_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi3_clk}, + { .type = AW_CLK_MUX, .clk.mux = &cpu_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_periph_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_video0_2x_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_video1_2x_clk}, }; -static struct aw_clk_nm_def *nm_clks[] = { - &axi_clk, - &ahb_clk, - &apb0_clk, - &apb1_clk, - &pll_video0_clk, - &pll_video1_clk, - &nand_clk, - &ms_clk, - &mmc0_clk, - &mmc1_clk, - &mmc2_clk, - &mmc3_clk, - &ts_clk, - &ss_clk, - &spi0_clk, - &spi1_clk, - &spi2_clk, - &ir0_clk, - &ir1_clk, - &keypad_clk, - &sata_clk, - &spi3_clk, +static struct aw_clk_init a10_init_clks[] = { }; -static struct aw_clk_prediv_mux_def *prediv_mux_clks[] = { +static struct ofw_compat_data compat_data[] = { +#if defined(SOC_ALLWINNER_A10) + { "allwinner,sun4i-a10-ccu", 1 }, +#endif +#if defined(SOC_ALLWINNER_A20) + { "allwinner,sun7i-a20-ccu", 1 }, +#endif + { NULL, 0}, }; -static struct clk_mux_def *mux_clks[] = { - &cpu_clk, -}; +static int +ccu_a10_probe(device_t dev) +{ -static struct clk_div_def *div_clks[] = { -}; + if (!ofw_bus_status_okay(dev)) + return (ENXIO); -static struct clk_fixed_def *fixed_factor_clks[] = { - &pll_periph_clk, - &pll_video0_2x_clk, - &pll_video1_2x_clk, -}; + if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) + return (ENXIO); -static struct aw_clk_init init_clks[] = { -}; + device_set_desc(dev, "Allwinner A10/A20 Clock Control Unit NG"); + return (BUS_PROBE_DEFAULT); +} -void -ccu_a10_register_clocks(struct aw_ccung_softc *sc) +static int +ccu_a10_attach(device_t dev) { - int i; + struct aw_ccung_softc *sc; + + sc = device_get_softc(dev); sc->resets = a10_ccu_resets; sc->nresets = nitems(a10_ccu_resets); sc->gates = a10_ccu_gates; sc->ngates = nitems(a10_ccu_gates); - sc->clk_init = init_clks; - sc->n_clk_init = nitems(init_clks); - - for (i = 0; i < nitems(nkmp_clks); i++) - aw_clk_nkmp_register(sc->clkdom, nkmp_clks[i]); - for (i = 0; i < nitems(nm_clks); i++) - aw_clk_nm_register(sc->clkdom, nm_clks[i]); - for (i = 0; i < nitems(prediv_mux_clks); i++) - aw_clk_prediv_mux_register(sc->clkdom, prediv_mux_clks[i]); - - for (i = 0; i < nitems(mux_clks); i++) - clknode_mux_register(sc->clkdom, mux_clks[i]); - for (i = 0; i < nitems(div_clks); i++) - clknode_div_register(sc->clkdom, div_clks[i]); - for (i = 0; i < nitems(fixed_factor_clks); i++) - clknode_fixed_register(sc->clkdom, fixed_factor_clks[i]); + sc->clks = a10_ccu_clks; + sc->nclks = nitems(a10_ccu_clks); + sc->clk_init = a10_init_clks; + sc->n_clk_init = nitems(a10_init_clks); + + return (aw_ccung_attach(dev)); } -void -ccu_a20_register_clocks(struct aw_ccung_softc *sc) -{ +static device_method_t ccu_a10ng_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, ccu_a10_probe), + DEVMETHOD(device_attach, ccu_a10_attach), - /* XXX TODO: Implement the A20-specific clocks */ - ccu_a10_register_clocks(sc); -} + DEVMETHOD_END +}; + +static devclass_t ccu_a10ng_devclass; + +DEFINE_CLASS_1(ccu_a10ng, ccu_a10ng_driver, ccu_a10ng_methods, + sizeof(struct aw_ccung_softc), aw_ccung_driver); + +EARLY_DRIVER_MODULE(ccu_a10ng, simplebus, ccu_a10ng_driver, + ccu_a10ng_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); diff --git a/sys/arm/allwinner/clkng/ccu_a10.h b/sys/arm/allwinner/clkng/ccu_a10.h deleted file mode 100644 index 93856b333b67..000000000000 --- a/sys/arm/allwinner/clkng/ccu_a10.h +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2018 Kyle Evans - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __CCU_A10_H__ -#define __CCU_A10_H__ - -void ccu_a10_register_clocks(struct aw_ccung_softc *sc); -void ccu_a20_register_clocks(struct aw_ccung_softc *sc); - -#endif /* __CCU_A10_H__ */ diff --git a/sys/arm/allwinner/clkng/ccu_a13.c b/sys/arm/allwinner/clkng/ccu_a13.c index c950fa8d4fd6..35f81f5c4565 100644 --- a/sys/arm/allwinner/clkng/ccu_a13.c +++ b/sys/arm/allwinner/clkng/ccu_a13.c @@ -1,6 +1,7 @@ /*- - * Copyright (c) 2017 Emmanuel Vadot - * All rights reserved. + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017,2018 Emmanuel Vadot * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,22 +33,25 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include +#include +#include + +#include + +#include +#include #include #include #include #include -#include -#include -#include -#include #include #include -#include "ccu_a13.h" - /* Non-exported clocks */ #define CLK_PLL_CORE 2 @@ -496,71 +500,72 @@ static struct aw_clk_nm_def ir_clk = { /* Clocks list */ - -static struct aw_clk_nkmp_def *nkmp_clks[] = { - &pll_core, - &pll_audio, - &pll_ddr_base, - &pll_periph, -}; - -static struct aw_clk_nm_def *nm_clks[] = { - &apb1_clk, - &nand_clk, - &mmc0_clk, - &mmc1_clk, - &mmc2_clk, - &ss_clk, - &spi0_clk, - &spi1_clk, - &spi2_clk, - &ir_clk, +static struct aw_ccung_clk a13_ccu_clks[] = { + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_core}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_audio}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_ddr_base}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_periph}, + { .type = AW_CLK_NM, .clk.nm = &apb1_clk}, + { .type = AW_CLK_NM, .clk.nm = &nand_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc0_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc1_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc2_clk}, + { .type = AW_CLK_NM, .clk.nm = &ss_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi0_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi1_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi2_clk}, + { .type = AW_CLK_NM, .clk.nm = &ir_clk}, + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &cpu_clk}, + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &ahb_clk}, + { .type = AW_CLK_DIV, .clk.div = &pll_ddr}, + { .type = AW_CLK_DIV, .clk.div = &pll_ddr_other}, + { .type = AW_CLK_DIV, .clk.div = &axi_clk}, + { .type = AW_CLK_DIV, .clk.div = &apb0_clk}, }; -static struct aw_clk_prediv_mux_def *prediv_mux_clks[] = { - &cpu_clk, - &ahb_clk, -}; +static int +ccu_a13_probe(device_t dev) +{ -static struct clk_div_def *div_clks[] = { - &pll_ddr, - &pll_ddr_other, - &axi_clk, - &apb0_clk, -}; + if (!ofw_bus_status_okay(dev)) + return (ENXIO); -static struct clk_mux_def *mux_clks[] = { -}; + if (!ofw_bus_is_compatible(dev, "allwinner,sun5i-a13-ccu")) + return (ENXIO); -static struct clk_fixed_def *fixed_factor_clks[] = { -}; - -static struct aw_clk_init init_clks[] = { -}; + device_set_desc(dev, "Allwinner A13 Clock Control Unit NG"); + return (BUS_PROBE_DEFAULT); +} -void -ccu_a13_register_clocks(struct aw_ccung_softc *sc) +static int +ccu_a13_attach(device_t dev) { - int i; + struct aw_ccung_softc *sc; + + sc = device_get_softc(dev); sc->resets = a13_ccu_resets; sc->nresets = nitems(a13_ccu_resets); sc->gates = a13_ccu_gates; sc->ngates = nitems(a13_ccu_gates); - sc->clk_init = init_clks; - sc->n_clk_init = nitems(init_clks); - - for (i = 0; i < nitems(nkmp_clks); i++) - aw_clk_nkmp_register(sc->clkdom, nkmp_clks[i]); - for (i = 0; i < nitems(nm_clks); i++) - aw_clk_nm_register(sc->clkdom, nm_clks[i]); - for (i = 0; i < nitems(prediv_mux_clks); i++) - aw_clk_prediv_mux_register(sc->clkdom, prediv_mux_clks[i]); - - for (i = 0; i < nitems(mux_clks); i++) - clknode_mux_register(sc->clkdom, mux_clks[i]); - for (i = 0; i < nitems(div_clks); i++) - clknode_div_register(sc->clkdom, div_clks[i]); - for (i = 0; i < nitems(fixed_factor_clks); i++) - clknode_fixed_register(sc->clkdom, fixed_factor_clks[i]); + sc->clks = a13_ccu_clks; + sc->nclks = nitems(a13_ccu_clks); + + return (aw_ccung_attach(dev)); } + +static device_method_t ccu_a13ng_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, ccu_a13_probe), + DEVMETHOD(device_attach, ccu_a13_attach), + + DEVMETHOD_END +}; + +static devclass_t ccu_a13ng_devclass; + +DEFINE_CLASS_1(ccu_a13ng, ccu_a13ng_driver, ccu_a13ng_methods, + sizeof(struct aw_ccung_softc), aw_ccung_driver); + +EARLY_DRIVER_MODULE(ccu_a13ng, simplebus, ccu_a13ng_driver, + ccu_a13ng_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); diff --git a/sys/arm/allwinner/clkng/ccu_a13.h b/sys/arm/allwinner/clkng/ccu_a13.h deleted file mode 100644 index 1271dd2318eb..000000000000 --- a/sys/arm/allwinner/clkng/ccu_a13.h +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * Copyright (c) 2017 Emmanuel Vadot - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __CCU_A13_H__ -#define __CCU_A13_H__ - -void ccu_a13_register_clocks(struct aw_ccung_softc *sc); - -#endif /* __CCU_a13 H__ */ diff --git a/sys/arm/allwinner/clkng/ccu_a31.c b/sys/arm/allwinner/clkng/ccu_a31.c index 5fdc28c82b96..5a8b197be8d1 100644 --- a/sys/arm/allwinner/clkng/ccu_a31.c +++ b/sys/arm/allwinner/clkng/ccu_a31.c @@ -1,6 +1,7 @@ /*- - * Copyright (c) 2017 Emmanuel Vadot - * All rights reserved. + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017,2018 Emmanuel Vadot * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,22 +33,25 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include +#include +#include + +#include + +#include +#include #include #include #include #include -#include -#include -#include -#include #include #include -#include "ccu_a31.h" - /* Non-exported clocks */ #define CLK_PLL_CPU 0 #define CLK_PLL_AUDIO_BASE 1 @@ -859,113 +863,114 @@ PREDIV_CLK(gpu_hyd_clk, /* ATS 0x1B0 */ /* Trace 0x1B4 */ - -static struct aw_clk_nkmp_def *nkmp_clks[] = { - &pll_cpu_clk, - &pll_audio_clk, - &pll_periph_clk, - &pll_ddr_clk, - &pll_mipi_clk, -}; - -static struct aw_clk_nm_def *nm_clks[] = { - &pll_video0_clk, - &pll_ve_clk, - &pll_video1_clk, - &pll_gpu_clk, - &pll9_clk, - &pll10_clk, - &apb2_clk, - &nand0_clk, - &nand1_clk, - &mmc0_clk, - &mmc1_clk, - &mmc2_clk, - &mmc3_clk, - &ts_clk, - &ss_clk, - &spi0_clk, - &spi1_clk, - &spi2_clk, - &spi3_clk, - &mdfs_clk, - &sdram0_clk, - &sdram1_clk, - &be0_clk, - &be1_clk, - &fe0_clk, - &fe1_clk, - &mp_clk, - &lcd0_ch0_clk, - &lcd1_ch0_clk, - &lcd0_ch1_clk, - &lcd1_ch1_clk, - &ve_clk, - &hdmi_clk, - &mbus0_clk, - &mbus1_clk, - &mipi_dsi_clk, - &mipi_dsi_dphy_clk, - &mipi_csi_dphy_clk, - &iep_drc0_clk, - &iep_drc1_clk, - &iep_deu0_clk, - &iep_deu1_clk, +static struct aw_ccung_clk a31_ccu_clks[] = { + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_cpu_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_audio_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_periph_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_ddr_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_mipi_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_video0_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_ve_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_video1_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_gpu_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll9_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll10_clk}, + { .type = AW_CLK_NM, .clk.nm = &apb2_clk}, + { .type = AW_CLK_NM, .clk.nm = &nand0_clk}, + { .type = AW_CLK_NM, .clk.nm = &nand1_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc0_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc1_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc2_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc3_clk}, + { .type = AW_CLK_NM, .clk.nm = &ts_clk}, + { .type = AW_CLK_NM, .clk.nm = &ss_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi0_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi1_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi2_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi3_clk}, + { .type = AW_CLK_NM, .clk.nm = &mdfs_clk}, + { .type = AW_CLK_NM, .clk.nm = &sdram0_clk}, + { .type = AW_CLK_NM, .clk.nm = &sdram1_clk}, + { .type = AW_CLK_NM, .clk.nm = &be0_clk}, + { .type = AW_CLK_NM, .clk.nm = &be1_clk}, + { .type = AW_CLK_NM, .clk.nm = &fe0_clk}, + { .type = AW_CLK_NM, .clk.nm = &fe1_clk}, + { .type = AW_CLK_NM, .clk.nm = &mp_clk}, + { .type = AW_CLK_NM, .clk.nm = &lcd0_ch0_clk}, + { .type = AW_CLK_NM, .clk.nm = &lcd1_ch0_clk}, + { .type = AW_CLK_NM, .clk.nm = &lcd0_ch1_clk}, + { .type = AW_CLK_NM, .clk.nm = &lcd1_ch1_clk}, + { .type = AW_CLK_NM, .clk.nm = &ve_clk}, + { .type = AW_CLK_NM, .clk.nm = &hdmi_clk}, + { .type = AW_CLK_NM, .clk.nm = &mbus0_clk}, + { .type = AW_CLK_NM, .clk.nm = &mbus1_clk}, + { .type = AW_CLK_NM, .clk.nm = &mipi_dsi_clk}, + { .type = AW_CLK_NM, .clk.nm = &mipi_dsi_dphy_clk}, + { .type = AW_CLK_NM, .clk.nm = &mipi_csi_dphy_clk}, + { .type = AW_CLK_NM, .clk.nm = &iep_drc0_clk}, + { .type = AW_CLK_NM, .clk.nm = &iep_drc1_clk}, + { .type = AW_CLK_NM, .clk.nm = &iep_deu0_clk}, + { .type = AW_CLK_NM, .clk.nm = &iep_deu1_clk}, + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &ahb1_clk}, + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &gpu_core_clk}, + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &gpu_memory_clk}, + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &gpu_hyd_clk}, + { .type = AW_CLK_DIV, .clk.div = &axi_clk}, + { .type = AW_CLK_DIV, .clk.div = &apb1_clk}, + { .type = AW_CLK_MUX, .clk.mux = &cpu_clk}, + { .type = AW_CLK_MUX, .clk.mux = &daudio0mux_clk}, + { .type = AW_CLK_MUX, .clk.mux = &daudio1mux_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_audio_2x_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_audio_4x_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_audio_8x_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_video0_2x_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_periph_2x_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_video1_2x_clk}, }; -static struct aw_clk_prediv_mux_def *prediv_mux_clks[] = { - &ahb1_clk, - &gpu_core_clk, - &gpu_memory_clk, - &gpu_hyd_clk, -}; +static int +ccu_a31_probe(device_t dev) +{ -static struct clk_div_def *div_clks[] = { - &axi_clk, - &apb1_clk, -}; + if (!ofw_bus_status_okay(dev)) + return (ENXIO); -static struct clk_mux_def *mux_clks[] = { - &cpu_clk, - &daudio0mux_clk, - &daudio1mux_clk, -}; + if (!ofw_bus_is_compatible(dev, "allwinner,sun6i-a31-ccu")) + return (ENXIO); -static struct clk_fixed_def *fixed_factor_clks[] = { - &pll_audio_2x_clk, - &pll_audio_4x_clk, - &pll_audio_8x_clk, - &pll_video0_2x_clk, - &pll_periph_2x_clk, - &pll_video1_2x_clk, -}; - -static struct aw_clk_init init_clks[] = { -}; + device_set_desc(dev, "Allwinner A31 Clock Control Unit NG"); + return (BUS_PROBE_DEFAULT); +} -void -ccu_a31_register_clocks(struct aw_ccung_softc *sc) +static int +ccu_a31_attach(device_t dev) { - int i; + struct aw_ccung_softc *sc; + + sc = device_get_softc(dev); sc->resets = a31_ccu_resets; sc->nresets = nitems(a31_ccu_resets); sc->gates = a31_ccu_gates; sc->ngates = nitems(a31_ccu_gates); - sc->clk_init = init_clks; - sc->n_clk_init = nitems(init_clks); - - for (i = 0; i < nitems(nkmp_clks); i++) - aw_clk_nkmp_register(sc->clkdom, nkmp_clks[i]); - for (i = 0; i < nitems(nm_clks); i++) - aw_clk_nm_register(sc->clkdom, nm_clks[i]); - for (i = 0; i < nitems(prediv_mux_clks); i++) - aw_clk_prediv_mux_register(sc->clkdom, prediv_mux_clks[i]); - - for (i = 0; i < nitems(mux_clks); i++) - clknode_mux_register(sc->clkdom, mux_clks[i]); - for (i = 0; i < nitems(div_clks); i++) - clknode_div_register(sc->clkdom, div_clks[i]); - for (i = 0; i < nitems(fixed_factor_clks); i++) - clknode_fixed_register(sc->clkdom, fixed_factor_clks[i]); + sc->clks = a31_ccu_clks; + sc->nclks = nitems(a31_ccu_clks); + + return (aw_ccung_attach(dev)); } + +static device_method_t ccu_a31ng_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, ccu_a31_probe), + DEVMETHOD(device_attach, ccu_a31_attach), + + DEVMETHOD_END +}; + +static devclass_t ccu_a31ng_devclass; + +DEFINE_CLASS_1(ccu_a31ng, ccu_a31ng_driver, ccu_a31ng_methods, + sizeof(struct aw_ccung_softc), aw_ccung_driver); + +EARLY_DRIVER_MODULE(ccu_a31ng, simplebus, ccu_a31ng_driver, + ccu_a31ng_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); diff --git a/sys/arm/allwinner/clkng/ccu_a31.h b/sys/arm/allwinner/clkng/ccu_a31.h deleted file mode 100644 index 2295485e6376..000000000000 --- a/sys/arm/allwinner/clkng/ccu_a31.h +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * Copyright (c) 2017 Emmanuel Vadot - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __CCU_A31_H__ -#define __CCU_A31_H__ - -void ccu_a31_register_clocks(struct aw_ccung_softc *sc); - -#endif /* __CCU_A31 H__ */ diff --git a/sys/arm/allwinner/clkng/ccu_a64.c b/sys/arm/allwinner/clkng/ccu_a64.c index bb061e7ee24e..662f6d1826ad 100644 --- a/sys/arm/allwinner/clkng/ccu_a64.c +++ b/sys/arm/allwinner/clkng/ccu_a64.c @@ -1,6 +1,7 @@ /*- - * Copyright (c) 2017 Emmanuel Vadot - * All rights reserved. + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017,2018 Emmanuel Vadot * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,22 +33,25 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include +#include +#include + +#include + +#include +#include #include #include #include #include -#include -#include -#include -#include #include #include -#include "ccu_a64.h" - /* Non-exported clocks */ #define CLK_OSC_12M 0 @@ -680,99 +684,106 @@ NM_CLK(gpu_clk, 31, /* gate */ AW_CLK_HAS_GATE); /* flags */ -static struct aw_clk_nkmp_def *nkmp_clks[] = { - &pll_cpux_clk, - &pll_audio_clk, - &pll_periph0_2x_clk, - &pll_periph1_2x_clk, - &pll_ddr0_clk, - &pll_ddr1_clk, +static struct aw_ccung_clk a64_ccu_clks[] = { + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_cpux_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_audio_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_periph0_2x_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_periph1_2x_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_ddr0_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_ddr1_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_video0_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_video1_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_ve_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_gpu_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_de_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_hsic_clk}, + { .type = AW_CLK_NM, .clk.nm = &apb2_clk}, + { .type = AW_CLK_NM, .clk.nm = &nand_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc0_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc1_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc2_clk}, + { .type = AW_CLK_NM, .clk.nm = &ts_clk}, + { .type = AW_CLK_NM, .clk.nm = &ce_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi0_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi1_clk}, + { .type = AW_CLK_NM, .clk.nm = &spdif_clk}, + { .type = AW_CLK_NM, .clk.nm = &dram_clk}, + { .type = AW_CLK_NM, .clk.nm = &de_clk}, + { .type = AW_CLK_NM, .clk.nm = &deinterlace_clk}, + { .type = AW_CLK_NM, .clk.nm = &csi_sclk_clk}, + { .type = AW_CLK_NM, .clk.nm = &csi_mclk_clk}, + { .type = AW_CLK_NM, .clk.nm = &ve_clk}, + { .type = AW_CLK_NM, .clk.nm = &hdmi_clk}, + { .type = AW_CLK_NM, .clk.nm = &mbus_clk}, + { .type = AW_CLK_NM, .clk.nm = &gpu_clk}, + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &ahb1_clk}, + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &ahb2_clk}, + { .type = AW_CLK_MUX, .clk.mux = &cpux_clk}, + { .type = AW_CLK_MUX, .clk.mux = &i2s0mux_clk}, + { .type = AW_CLK_MUX, .clk.mux = &i2s1mux_clk}, + { .type = AW_CLK_MUX, .clk.mux = &i2s2mux_clk}, + { .type = AW_CLK_DIV, .clk.div = &axi_clk}, + { .type = AW_CLK_DIV, .clk.div = &apb1_clk}, + { .type = AW_CLK_DIV, .clk.div = &apb_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &osc12m_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_periph0_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_periph1_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_audio_2x_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_audio_4x_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_audio_8x_clk}, }; -static struct aw_clk_nm_def *nm_clks[] = { - &pll_video0_clk, - &pll_video1_clk, - &pll_ve_clk, - &pll_gpu_clk, - &pll_de_clk, - &pll_hsic_clk, - &apb2_clk, - &nand_clk, - &mmc0_clk, - &mmc1_clk, - &mmc2_clk, - &ts_clk, - &ce_clk, - &spi0_clk, - &spi1_clk, - &spdif_clk, - &dram_clk, - &de_clk, - &deinterlace_clk, - &csi_sclk_clk, - &csi_mclk_clk, - &ve_clk, - &hdmi_clk, - &mbus_clk, - &gpu_clk, -}; - -static struct aw_clk_prediv_mux_def *prediv_mux_clks[] = { - &ahb1_clk, - &ahb2_clk, +static struct aw_clk_init a64_init_clks[] = { + {"ahb1", "pll_periph0", 0, false}, + {"ahb2", "pll_periph0", 0, false}, + {"dram", "pll_ddr0", 0, false}, }; -static struct clk_mux_def *mux_clks[] = { - &cpux_clk, - &i2s0mux_clk, - &i2s1mux_clk, - &i2s2mux_clk, -}; +static int +ccu_a64_probe(device_t dev) +{ -static struct clk_div_def *div_clks[] = { - &axi_clk, - &apb1_clk, - &apb_clk, -}; + if (!ofw_bus_status_okay(dev)) + return (ENXIO); -static struct clk_fixed_def *fixed_factor_clks[] = { - &osc12m_clk, - &pll_periph0_clk, - &pll_periph1_clk, - &pll_audio_2x_clk, - &pll_audio_4x_clk, - &pll_audio_8x_clk, -}; + if (!ofw_bus_is_compatible(dev, "allwinner,sun50i-a64-ccu")) + return (ENXIO); -static struct aw_clk_init init_clks[] = { - {"ahb1", "pll_periph0", 0, false}, - {"ahb2", "pll_periph0", 0, false}, - {"dram", "pll_ddr0", 0, false}, -}; + device_set_desc(dev, "Allwinner A64 Clock Control Unit NG"); + return (BUS_PROBE_DEFAULT); +} -void -ccu_a64_register_clocks(struct aw_ccung_softc *sc) +static int +ccu_a64_attach(device_t dev) { - int i; + struct aw_ccung_softc *sc; + + sc = device_get_softc(dev); sc->resets = a64_ccu_resets; sc->nresets = nitems(a64_ccu_resets); sc->gates = a64_ccu_gates; sc->ngates = nitems(a64_ccu_gates); - sc->clk_init = init_clks; - sc->n_clk_init = nitems(init_clks); - - for (i = 0; i < nitems(nkmp_clks); i++) - aw_clk_nkmp_register(sc->clkdom, nkmp_clks[i]); - for (i = 0; i < nitems(nm_clks); i++) - aw_clk_nm_register(sc->clkdom, nm_clks[i]); - for (i = 0; i < nitems(prediv_mux_clks); i++) - aw_clk_prediv_mux_register(sc->clkdom, prediv_mux_clks[i]); - - for (i = 0; i < nitems(mux_clks); i++) - clknode_mux_register(sc->clkdom, mux_clks[i]); - for (i = 0; i < nitems(div_clks); i++) - clknode_div_register(sc->clkdom, div_clks[i]); - for (i = 0; i < nitems(fixed_factor_clks); i++) - clknode_fixed_register(sc->clkdom, fixed_factor_clks[i]); + sc->clks = a64_ccu_clks; + sc->nclks = nitems(a64_ccu_clks); + sc->clk_init = a64_init_clks; + sc->n_clk_init = nitems(a64_init_clks); + + return (aw_ccung_attach(dev)); } + +static device_method_t ccu_a64ng_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, ccu_a64_probe), + DEVMETHOD(device_attach, ccu_a64_attach), + + DEVMETHOD_END +}; + +static devclass_t ccu_a64ng_devclass; + +DEFINE_CLASS_1(ccu_a64ng, ccu_a64ng_driver, ccu_a64ng_methods, + sizeof(struct aw_ccung_softc), aw_ccung_driver); + +EARLY_DRIVER_MODULE(ccu_a64ng, simplebus, ccu_a64ng_driver, + ccu_a64ng_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); diff --git a/sys/arm/allwinner/clkng/ccu_a64.h b/sys/arm/allwinner/clkng/ccu_a64.h deleted file mode 100644 index bfa3dd4e61a8..000000000000 --- a/sys/arm/allwinner/clkng/ccu_a64.h +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * Copyright (c) 2017 Emmanuel Vadot - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __CCU_A64_H__ -#define __CCU_A64_H__ - -void ccu_a64_register_clocks(struct aw_ccung_softc *sc); - -#endif /* __CCU_A64_H__ */ diff --git a/sys/arm/allwinner/clkng/ccu_a83t.c b/sys/arm/allwinner/clkng/ccu_a83t.c index c23f02535e9d..458c7b0317a1 100644 --- a/sys/arm/allwinner/clkng/ccu_a83t.c +++ b/sys/arm/allwinner/clkng/ccu_a83t.c @@ -33,27 +33,25 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include +#include +#include + +#include + +#include +#include #include #include #include #include -#include -#include -#include -#include #include #include -#include "ccu_a83t.h" - -/* Non-exported resets */ -/* -#define RST_BUS_SCR 53 -*/ - /* Non-exported clocks */ #define CLK_PLL_C0CPUX 0 @@ -681,100 +679,106 @@ NM_CLK(gpu_hyd_clk, 31, /* gate */ AW_CLK_HAS_GATE); - -static struct aw_clk_nkmp_def *nkmp_clks[] = { - &pll_audio_clk, - &pll_video0_clk, - &pll_ve_clk, - &pll_ddr_clk, - &pll_periph_clk, - &pll_gpu_clk, - &pll_hsic_clk, - &pll_de_clk, - &pll_video1_clk, -}; - -static struct aw_clk_nm_def *nm_clks[] = { - &pll_c0cpux_clk, - &pll_c1cpux_clk, - &apb2_clk, - &nand_clk, - &mmc0_clk, - &mmc1_clk, - &mmc2_clk, - &ss_clk, - &spi0_clk, - &spi1_clk, - &i2s0_clk, - &i2s1_clk, - &i2s2_clk, - &tdm_clk, - &spdif_clk, - &dram_clk, - &tcon1_clk, - &csi_mclk_clk, - &csi_sclk_clk, - &ve_clk, - &hdmi_clk, - &mbus_clk, - &mipi_dsi0_clk, - &mipi_dsi1_clk, - &gpu_core_clk, - &gpu_memory_clk, - &gpu_hyd_clk, +static struct aw_ccung_clk a83t_clks[] = { + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_audio_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_video0_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_ve_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_ddr_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_periph_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_gpu_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_hsic_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_de_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_video1_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_c0cpux_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_c1cpux_clk}, + { .type = AW_CLK_NM, .clk.nm = &apb2_clk}, + { .type = AW_CLK_NM, .clk.nm = &nand_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc0_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc1_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc2_clk}, + { .type = AW_CLK_NM, .clk.nm = &ss_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi0_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi1_clk}, + { .type = AW_CLK_NM, .clk.nm = &i2s0_clk}, + { .type = AW_CLK_NM, .clk.nm = &i2s1_clk}, + { .type = AW_CLK_NM, .clk.nm = &i2s2_clk}, + { .type = AW_CLK_NM, .clk.nm = &tdm_clk}, + { .type = AW_CLK_NM, .clk.nm = &spdif_clk}, + { .type = AW_CLK_NM, .clk.nm = &dram_clk}, + { .type = AW_CLK_NM, .clk.nm = &tcon1_clk}, + { .type = AW_CLK_NM, .clk.nm = &csi_mclk_clk}, + { .type = AW_CLK_NM, .clk.nm = &csi_sclk_clk}, + { .type = AW_CLK_NM, .clk.nm = &ve_clk}, + { .type = AW_CLK_NM, .clk.nm = &hdmi_clk}, + { .type = AW_CLK_NM, .clk.nm = &mbus_clk}, + { .type = AW_CLK_NM, .clk.nm = &mipi_dsi0_clk}, + { .type = AW_CLK_NM, .clk.nm = &mipi_dsi1_clk}, + { .type = AW_CLK_NM, .clk.nm = &gpu_core_clk}, + { .type = AW_CLK_NM, .clk.nm = &gpu_memory_clk}, + { .type = AW_CLK_NM, .clk.nm = &gpu_hyd_clk}, + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &ahb1_clk}, + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &ahb2_clk}, + { .type = AW_CLK_MUX, .clk.mux = &c0cpux_clk}, + { .type = AW_CLK_MUX, .clk.mux = &c1cpux_clk}, + { .type = AW_CLK_MUX, .clk.mux = &cci400_clk}, + { .type = AW_CLK_MUX, .clk.mux = &tcon0_clk}, + { .type = AW_CLK_DIV, .clk.div = &axi0_clk}, + { .type = AW_CLK_DIV, .clk.div = &axi1_clk}, + { .type = AW_CLK_DIV, .clk.div = &apb1_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &osc12m_clk}, }; -static struct aw_clk_prediv_mux_def *prediv_mux_clks[] = { - &ahb1_clk, - &ahb2_clk, +static struct aw_clk_init a83t_init_clks[] = { + {"ahb1", "pll_periph", 0, false}, + {"ahb2", "ahb1", 0, false}, + {"dram", "pll_ddr", 0, false}, }; -static struct clk_mux_def *mux_clks[] = { - &c0cpux_clk, - &c1cpux_clk, - &cci400_clk, - &tcon0_clk, -}; +static int +ccu_a83t_probe(device_t dev) +{ -static struct clk_div_def *div_clks[] = { - &axi0_clk, - &axi1_clk, - &apb1_clk, -}; + if (!ofw_bus_status_okay(dev)) + return (ENXIO); -static struct clk_fixed_def *fixed_factor_clks[] = { - &osc12m_clk, -}; + if (!ofw_bus_is_compatible(dev, "allwinner,sun8i-a83t-ccu")) + return (ENXIO); -static struct aw_clk_init init_clks[] = { - {"ahb1", "pll_periph", 0, false}, - {"ahb2", "ahb1", 0, false}, - {"dram", "pll_ddr", 0, false}, -}; + device_set_desc(dev, "Allwinner A83T Clock Control Unit NG"); + return (BUS_PROBE_DEFAULT); +} -void -ccu_a83t_register_clocks(struct aw_ccung_softc *sc) +static int +ccu_a83t_attach(device_t dev) { - int i; + struct aw_ccung_softc *sc; + + sc = device_get_softc(dev); sc->resets = a83t_ccu_resets; sc->nresets = nitems(a83t_ccu_resets); sc->gates = a83t_ccu_gates; sc->ngates = nitems(a83t_ccu_gates); - sc->clk_init = init_clks; - sc->n_clk_init = nitems(init_clks); - - for (i = 0; i < nitems(nkmp_clks); i++) - aw_clk_nkmp_register(sc->clkdom, nkmp_clks[i]); - for (i = 0; i < nitems(nm_clks); i++) - aw_clk_nm_register(sc->clkdom, nm_clks[i]); - for (i = 0; i < nitems(prediv_mux_clks); i++) - aw_clk_prediv_mux_register(sc->clkdom, prediv_mux_clks[i]); - - for (i = 0; i < nitems(mux_clks); i++) - clknode_mux_register(sc->clkdom, mux_clks[i]); - for (i = 0; i < nitems(div_clks); i++) - clknode_div_register(sc->clkdom, div_clks[i]); - for (i = 0; i < nitems(fixed_factor_clks); i++) - clknode_fixed_register(sc->clkdom, fixed_factor_clks[i]); + sc->clks = a83t_clks; + sc->nclks = nitems(a83t_clks); + sc->clk_init = a83t_init_clks; + sc->n_clk_init = nitems(a83t_init_clks); + + return (aw_ccung_attach(dev)); } + +static device_method_t ccu_a83tng_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, ccu_a83t_probe), + DEVMETHOD(device_attach, ccu_a83t_attach), + + DEVMETHOD_END +}; + +static devclass_t ccu_a83tng_devclass; + +DEFINE_CLASS_1(ccu_a83tng, ccu_a83tng_driver, ccu_a83tng_methods, + sizeof(struct aw_ccung_softc), aw_ccung_driver); + +EARLY_DRIVER_MODULE(ccu_a83tng, simplebus, ccu_a83tng_driver, + ccu_a83tng_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); diff --git a/sys/arm/allwinner/clkng/ccu_a83t.h b/sys/arm/allwinner/clkng/ccu_a83t.h deleted file mode 100644 index 604c0f1b6844..000000000000 --- a/sys/arm/allwinner/clkng/ccu_a83t.h +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2017 Kyle Evans - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __CCU_A83T_H__ -#define __CCU_A83T_H__ - -void ccu_a83t_register_clocks(struct aw_ccung_softc *sc); - -#endif /* __CCU_A83T_H__ */ diff --git a/sys/arm/allwinner/clkng/ccu_h3.c b/sys/arm/allwinner/clkng/ccu_h3.c index 4322814291b1..8bef5f1f6b50 100644 --- a/sys/arm/allwinner/clkng/ccu_h3.c +++ b/sys/arm/allwinner/clkng/ccu_h3.c @@ -1,6 +1,7 @@ /*- - * Copyright (c) 2017 Emmanuel Vadot - * All rights reserved. + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017,2018 Emmanuel Vadot * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,6 +30,19 @@ #include __FBSDID("$FreeBSD$"); +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + #include #include #include @@ -42,16 +56,10 @@ __FBSDID("$FreeBSD$"); #endif #include -#include -#include -#include -#include #include #include -#include "ccu_h3.h" - /* Non-exported resets */ #define RST_BUS_SCR 53 @@ -670,96 +678,113 @@ NM_CLK(gpu_clk, 31, /* gate */ AW_CLK_HAS_GATE); /* flags */ -static struct aw_clk_nkmp_def *nkmp_clks[] = { - &pll_cpux_clk, - &pll_audio_clk, - &pll_periph0_clk, - &pll_periph1_clk, - &pll_ddr_clk, +static struct aw_ccung_clk h3_ccu_clks[] = { + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_cpux_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_audio_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_periph0_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_periph1_clk}, + { .type = AW_CLK_NKMP, .clk.nkmp = &pll_ddr_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_video_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_ve_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_gpu_clk}, + { .type = AW_CLK_NM, .clk.nm = &pll_de_clk}, + { .type = AW_CLK_NM, .clk.nm = &apb2_clk}, + { .type = AW_CLK_NM, .clk.nm = &nand_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc0_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc1_clk}, + { .type = AW_CLK_NM, .clk.nm = &mmc2_clk}, + { .type = AW_CLK_NM, .clk.nm = &ts_clk}, + { .type = AW_CLK_NM, .clk.nm = &ce_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi0_clk}, + { .type = AW_CLK_NM, .clk.nm = &spi1_clk}, + { .type = AW_CLK_NM, .clk.nm = &spdif_clk}, + { .type = AW_CLK_NM, .clk.nm = &dram_clk}, + { .type = AW_CLK_NM, .clk.nm = &de_clk}, + { .type = AW_CLK_NM, .clk.nm = &tcon0_clk}, + { .type = AW_CLK_NM, .clk.nm = &tve_clk}, + { .type = AW_CLK_NM, .clk.nm = &deinterlace_clk}, + { .type = AW_CLK_NM, .clk.nm = &csi_sclk_clk}, + { .type = AW_CLK_NM, .clk.nm = &csi_mclk_clk}, + { .type = AW_CLK_NM, .clk.nm = &ve_clk}, + { .type = AW_CLK_NM, .clk.nm = &hdmi_clk}, + { .type = AW_CLK_NM, .clk.nm = &mbus_clk}, + { .type = AW_CLK_NM, .clk.nm = &gpu_clk}, + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &ahb1_clk}, + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &ahb2_clk}, + { .type = AW_CLK_MUX, .clk.mux = &cpux_clk}, + { .type = AW_CLK_MUX, .clk.mux = &i2s0mux_clk}, + { .type = AW_CLK_MUX, .clk.mux = &i2s1mux_clk}, + { .type = AW_CLK_MUX, .clk.mux = &i2s2mux_clk}, + { .type = AW_CLK_DIV, .clk.div = &axi_clk}, + { .type = AW_CLK_DIV, .clk.div = &apb1_clk}, + { .type = AW_CLK_DIV, .clk.div = &thsdiv_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_periph0_2x_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_audio_2x_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_audio_4x_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &pll_audio_8x_clk}, }; -static struct aw_clk_nm_def *nm_clks[] = { - &pll_video_clk, - &pll_ve_clk, - &pll_gpu_clk, - &pll_de_clk, - &apb2_clk, - &nand_clk, - &mmc0_clk, - &mmc1_clk, - &mmc2_clk, - &ts_clk, - &ce_clk, - &spi0_clk, - &spi1_clk, - &spdif_clk, - &dram_clk, - &de_clk, - &tcon0_clk, - &tve_clk, - &deinterlace_clk, - &csi_sclk_clk, - &csi_mclk_clk, - &ve_clk, - &hdmi_clk, - &mbus_clk, - &gpu_clk, +static struct aw_clk_init h3_init_clks[] = { + {"ahb1", "pll_periph0", 0, false}, + {"ahb2", "pll_periph0", 0, false}, + {"dram", "pll_ddr", 0, false}, }; -static struct aw_clk_prediv_mux_def *prediv_mux_clks[] = { - &ahb1_clk, - &ahb2_clk, +static struct ofw_compat_data compat_data[] = { +#if defined(SOC_ALLWINNER_H3) + { "allwinner,sun8i-h3-ccu", 1 }, +#endif +#if defined(SOC_ALLWINNER_H5) + { "allwinner,sun50i-h5-ccu", 1 }, +#endif + { NULL, 0}, }; -static struct clk_mux_def *mux_clks[] = { - &cpux_clk, - &i2s0mux_clk, - &i2s1mux_clk, - &i2s2mux_clk, -}; +static int +ccu_h3_probe(device_t dev) +{ -static struct clk_div_def *div_clks[] = { - &axi_clk, - &apb1_clk, - &thsdiv_clk, -}; + if (!ofw_bus_status_okay(dev)) + return (ENXIO); -static struct clk_fixed_def *fixed_factor_clks[] = { - &pll_periph0_2x_clk, - &pll_audio_2x_clk, - &pll_audio_4x_clk, - &pll_audio_8x_clk, -}; + if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) + return (ENXIO); -static struct aw_clk_init init_clks[] = { - {"ahb1", "pll_periph0", 0, false}, - {"ahb2", "pll_periph0", 0, false}, - {"dram", "pll_ddr", 0, false}, -}; + device_set_desc(dev, "Allwinner H3/H5 Clock Control Unit NG"); + return (BUS_PROBE_DEFAULT); +} -void -ccu_h3_register_clocks(struct aw_ccung_softc *sc) +static int +ccu_h3_attach(device_t dev) { - int i; + struct aw_ccung_softc *sc; + + sc = device_get_softc(dev); sc->resets = h3_ccu_resets; sc->nresets = nitems(h3_ccu_resets); sc->gates = h3_ccu_gates; sc->ngates = nitems(h3_ccu_gates); - sc->clk_init = init_clks; - sc->n_clk_init = nitems(init_clks); - - for (i = 0; i < nitems(nkmp_clks); i++) - aw_clk_nkmp_register(sc->clkdom, nkmp_clks[i]); - for (i = 0; i < nitems(nm_clks); i++) - aw_clk_nm_register(sc->clkdom, nm_clks[i]); - for (i = 0; i < nitems(prediv_mux_clks); i++) - aw_clk_prediv_mux_register(sc->clkdom, prediv_mux_clks[i]); - - for (i = 0; i < nitems(mux_clks); i++) - clknode_mux_register(sc->clkdom, mux_clks[i]); - for (i = 0; i < nitems(div_clks); i++) - clknode_div_register(sc->clkdom, div_clks[i]); - for (i = 0; i < nitems(fixed_factor_clks); i++) - clknode_fixed_register(sc->clkdom, fixed_factor_clks[i]); + sc->clks = h3_ccu_clks; + sc->nclks = nitems(h3_ccu_clks); + sc->clk_init = h3_init_clks; + sc->n_clk_init = nitems(h3_init_clks); + + return (aw_ccung_attach(dev)); } + +static device_method_t ccu_h3ng_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, ccu_h3_probe), + DEVMETHOD(device_attach, ccu_h3_attach), + + DEVMETHOD_END +}; + +static devclass_t ccu_h3ng_devclass; + +DEFINE_CLASS_1(ccu_h3ng, ccu_h3ng_driver, ccu_h3ng_methods, + sizeof(struct aw_ccung_softc), aw_ccung_driver); + +EARLY_DRIVER_MODULE(ccu_h3ng, simplebus, ccu_h3ng_driver, + ccu_h3ng_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); diff --git a/sys/arm/allwinner/clkng/ccu_h3.h b/sys/arm/allwinner/clkng/ccu_h3.h deleted file mode 100644 index 26569cd69692..000000000000 --- a/sys/arm/allwinner/clkng/ccu_h3.h +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * Copyright (c) 2017 Emmanuel Vadot - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __CCU_H3_H__ -#define __CCU_H3_H__ - -void ccu_h3_register_clocks(struct aw_ccung_softc *sc); - -#endif /* __CCU_H3_H__ */ diff --git a/sys/arm/allwinner/clkng/ccu_sun8i_r.c b/sys/arm/allwinner/clkng/ccu_sun8i_r.c index 540088777f55..af534c0dcc88 100644 --- a/sys/arm/allwinner/clkng/ccu_sun8i_r.c +++ b/sys/arm/allwinner/clkng/ccu_sun8i_r.c @@ -1,6 +1,7 @@ /*- - * Copyright (c) 2017 Emmanuel Vadot - * All rights reserved. + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2017,2018 Emmanuel Vadot * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,6 +33,15 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include +#include +#include + +#include + +#include +#include #if defined(__aarch64__) #include "opt_soc.h" @@ -42,12 +52,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include -#include -#include -#include - -#include #include #include @@ -141,57 +145,120 @@ static struct aw_clk_nm_def a83t_ir_clk = { .flags = AW_CLK_HAS_MUX | AW_CLK_HAS_PREDIV, }; -static struct aw_clk_prediv_mux_def *r_ccu_prediv_mux_clks[] = { - &ar100_clk, +static struct aw_ccung_clk clks[] = { + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &ar100_clk}, + { .type = AW_CLK_DIV, .clk.div = &apb0_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &ahb0_clk}, + { .type = AW_CLK_NM, .clk.nm = &r_ccu_ir_clk}, }; -static struct aw_clk_prediv_mux_def *a83t_r_ccu_prediv_mux_clks[] = { - &a83t_ar100_clk, +static struct aw_ccung_clk a83t_clks[] = { + { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &a83t_ar100_clk}, + { .type = AW_CLK_DIV, .clk.div = &apb0_clk}, + { .type = AW_CLK_FIXED, .clk.fixed = &ahb0_clk}, + { .type = AW_CLK_NM, .clk.nm = &a83t_ir_clk}, }; -static struct clk_div_def *div_clks[] = { - &apb0_clk, +static struct ofw_compat_data compat_data[] = { +#if defined(SOC_ALLWINNER_H3) || defined(SOC_ALLWINNER_H5) + { "allwinner,sun8i-h3-r-ccu", 1 }, +#endif +#if defined(SOC_ALLWINNER_A64) + { "allwinner,sun50i-a64-r-ccu", 1 }, +#endif + { NULL, 0}, }; -static struct clk_fixed_def *fixed_factor_clks[] = { - &ahb0_clk, -}; +static int +ccu_sun8i_r_probe(device_t dev) +{ -static struct aw_clk_nm_def *r_ccu_nm_clks[] = { - &r_ccu_ir_clk, -}; + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) + return (ENXIO); + + device_set_desc(dev, "Allwinner SUN8I_R Clock Control Unit NG"); + return (BUS_PROBE_DEFAULT); +} + +static int +ccu_sun8i_r_attach(device_t dev) +{ + struct aw_ccung_softc *sc; + + sc = device_get_softc(dev); + + sc->resets = ccu_sun8i_r_resets; + sc->nresets = nitems(ccu_sun8i_r_resets); + sc->gates = ccu_sun8i_r_gates; + sc->ngates = nitems(ccu_sun8i_r_gates); + sc->clks = clks; + sc->nclks = nitems(clks); -static struct aw_clk_nm_def *a83t_nm_clks[] = { - &a83t_ir_clk, + return (aw_ccung_attach(dev)); +} + +static device_method_t ccu_sun8i_r_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, ccu_sun8i_r_probe), + DEVMETHOD(device_attach, ccu_sun8i_r_attach), + + DEVMETHOD_END }; -void -ccu_sun8i_r_register_clocks(struct aw_ccung_softc *sc) +static devclass_t ccu_sun8i_r_devclass; + +DEFINE_CLASS_1(ccu_sun8i_r, ccu_sun8i_r_driver, ccu_sun8i_r_methods, + sizeof(struct aw_ccung_softc), aw_ccung_driver); + +EARLY_DRIVER_MODULE(ccu_sun8i_r, simplebus, ccu_sun8i_r_driver, + ccu_sun8i_r_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_LAST); + +static int +ccu_a83t_r_probe(device_t dev) { - int i; - struct aw_clk_prediv_mux_def **prediv_mux_clks; - struct aw_clk_nm_def **nm_clks; + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (!ofw_bus_is_compatible(dev, "allwinner,sun8i-a83t-r-ccu")) + return (ENXIO); + + device_set_desc(dev, "Allwinner A83T_R Clock Control Unit NG"); + return (BUS_PROBE_DEFAULT); +} + +static int +ccu_a83t_r_attach(device_t dev) +{ + struct aw_ccung_softc *sc; + + sc = device_get_softc(dev); sc->resets = ccu_sun8i_r_resets; sc->nresets = nitems(ccu_sun8i_r_resets); sc->gates = ccu_sun8i_r_gates; sc->ngates = nitems(ccu_sun8i_r_gates); + sc->clks = a83t_clks; + sc->nclks = nitems(a83t_clks); - /* a83t names the parents differently than the others */ - if (sc->type == A83T_R_CCU) { - prediv_mux_clks = a83t_r_ccu_prediv_mux_clks; - nm_clks = a83t_nm_clks; - } else { - prediv_mux_clks = r_ccu_prediv_mux_clks; - nm_clks = r_ccu_nm_clks; - } - - for (i = 0; i < nitems(prediv_mux_clks); i++) - aw_clk_prediv_mux_register(sc->clkdom, prediv_mux_clks[i]); - for (i = 0; i < nitems(div_clks); i++) - clknode_div_register(sc->clkdom, div_clks[i]); - for (i = 0; i < nitems(fixed_factor_clks); i++) - clknode_fixed_register(sc->clkdom, fixed_factor_clks[i]); - for (i = 0; i < nitems(nm_clks); i++) - aw_clk_nm_register(sc->clkdom, nm_clks[i]); + return (aw_ccung_attach(dev)); } + +static device_method_t ccu_a83t_r_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, ccu_a83t_r_probe), + DEVMETHOD(device_attach, ccu_a83t_r_attach), + + DEVMETHOD_END +}; + +static devclass_t ccu_a83t_r_devclass; + +DEFINE_CLASS_1(ccu_a83t_r, ccu_a83t_r_driver, ccu_a83t_r_methods, + sizeof(struct aw_ccung_softc), aw_ccung_driver); + +EARLY_DRIVER_MODULE(ccu_a83t_r, simplebus, ccu_a83t_r_driver, + ccu_a83t_r_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_LAST); diff --git a/sys/arm/allwinner/clkng/ccu_sun8i_r.h b/sys/arm/allwinner/clkng/ccu_sun8i_r.h deleted file mode 100644 index 10e741640f99..000000000000 --- a/sys/arm/allwinner/clkng/ccu_sun8i_r.h +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * Copyright (c) 2017 Emmanuel Vadot - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __CCU_SUN8I_R_H__ -#define __CCU_SUN8I_R_H__ - -void ccu_sun8i_r_register_clocks(struct aw_ccung_softc *sc); - -#endif /* __CCU_SUN8I_R_H__ */ -- cgit v1.2.3