2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2019 Emmanuel Vadot <manu@freebsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <machine/bus.h>
41 #include <dev/fdt/simplebus.h>
43 #include <dev/ofw/ofw_bus.h>
44 #include <dev/ofw/ofw_bus_subr.h>
46 #include <dev/extres/clk/clk_div.h>
47 #include <dev/extres/clk/clk_fixed.h>
48 #include <dev/extres/clk/clk_mux.h>
50 #include <arm/allwinner/clkng/aw_ccung.h>
52 #include <dt-bindings/clock/sun50i-h6-r-ccu.h>
53 #include <dt-bindings/reset/sun50i-h6-r-ccu.h>
55 /* Non-exported clocks */
59 static struct aw_ccung_reset ccu_sun50i_h6_r_resets[] = {
60 CCU_RESET(RST_R_APB1_TIMER, 0x11c, 16)
61 CCU_RESET(RST_R_APB1_TWD, 0x12c, 16)
62 CCU_RESET(RST_R_APB1_PWM, 0x13c, 16)
63 CCU_RESET(RST_R_APB2_UART, 0x18c, 16)
64 CCU_RESET(RST_R_APB2_I2C, 0x19c, 16)
65 CCU_RESET(RST_R_APB1_IR, 0x1cc, 16)
66 CCU_RESET(RST_R_APB1_W1, 0x1ec, 16)
69 static struct aw_ccung_gate ccu_sun50i_h6_r_gates[] = {
70 CCU_GATE(CLK_R_APB1_TIMER, "r_apb1-timer", "r_apb1", 0x11c, 0)
71 CCU_GATE(CLK_R_APB1_TWD, "r_apb1-twd", "r_apb1", 0x12c, 0)
72 CCU_GATE(CLK_R_APB1_PWM, "r_apb1-pwm", "r_apb1", 0x13c, 0)
73 CCU_GATE(CLK_R_APB2_UART, "r_apb1-uart", "r_apb2", 0x18c, 0)
74 CCU_GATE(CLK_R_APB2_I2C, "r_apb1-i2c", "r_apb2", 0x19c, 0)
75 CCU_GATE(CLK_R_APB1_IR, "r_apb1-ir", "r_apb1", 0x1cc, 0)
76 CCU_GATE(CLK_R_APB1_W1, "r_apb1-w1", "r_apb1", 0x1ec, 0)
79 static const char *ar100_parents[] = {"osc24M", "osc32k", "pll_periph0", "iosc"};
80 PREDIV_CLK(ar100_clk, CLK_AR100, /* id */
81 "ar100", ar100_parents, /* name, parents */
84 4, 2, 0, AW_CLK_FACTOR_POWER_OF_TWO, /* div */
85 8, 5, 0, AW_CLK_FACTOR_HAS_COND, /* prediv */
86 16, 2, 2); /* prediv condition */
88 static const char *r_ahb_parents[] = {"ar100"};
92 r_ahb_parents, /* parent */
98 static const char *r_apb1_parents[] = {"r_ahb"};
101 "r_apb1", r_apb1_parents, /* name, parents */
103 0, 2, /* shift, width */
104 0, NULL); /* flags, div table */
106 static const char *r_apb2_parents[] = {"osc24M", "osc32k", "pll_periph0", "iosc"};
107 PREDIV_CLK(r_apb2_clk, CLK_R_APB2, /* id */
108 "r_apb2", r_apb2_parents, /* name, parents */
111 4, 2, 0, AW_CLK_FACTOR_POWER_OF_TWO, /* div */
112 8, 5, 0, AW_CLK_FACTOR_HAS_COND, /* prediv */
113 16, 2, 2); /* prediv condition */
115 static struct aw_ccung_clk clks[] = {
116 { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &ar100_clk},
117 { .type = AW_CLK_FIXED, .clk.fixed = &r_ahb_clk},
118 { .type = AW_CLK_DIV, .clk.div = &r_apb1_clk},
119 { .type = AW_CLK_PREDIV_MUX, .clk.prediv_mux = &r_apb2_clk},
122 static struct ofw_compat_data compat_data[] = {
123 { "allwinner,sun50i-h6-r-ccu", 1 },
128 ccu_sun50i_h6_r_probe(device_t dev)
131 if (!ofw_bus_status_okay(dev))
134 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
137 device_set_desc(dev, "Allwinner SUN50I_H6_R Clock Control Unit NG");
138 return (BUS_PROBE_DEFAULT);
142 ccu_sun50i_h6_r_attach(device_t dev)
144 struct aw_ccung_softc *sc;
146 sc = device_get_softc(dev);
148 sc->resets = ccu_sun50i_h6_r_resets;
149 sc->nresets = nitems(ccu_sun50i_h6_r_resets);
150 sc->gates = ccu_sun50i_h6_r_gates;
151 sc->ngates = nitems(ccu_sun50i_h6_r_gates);
153 sc->nclks = nitems(clks);
155 return (aw_ccung_attach(dev));
158 static device_method_t ccu_sun50i_h6_r_methods[] = {
159 /* Device interface */
160 DEVMETHOD(device_probe, ccu_sun50i_h6_r_probe),
161 DEVMETHOD(device_attach, ccu_sun50i_h6_r_attach),
166 DEFINE_CLASS_1(ccu_sun50i_h6_r, ccu_sun50i_h6_r_driver, ccu_sun50i_h6_r_methods,
167 sizeof(struct aw_ccung_softc), aw_ccung_driver);
169 EARLY_DRIVER_MODULE(ccu_sun50i_h6_r, simplebus, ccu_sun50i_h6_r_driver, 0, 0,
170 BUS_PASS_RESOURCE + BUS_PASS_ORDER_MIDDLE);