2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2018 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>
48 #include <dev/extres/clk/clk_div.h>
49 #include <dev/extres/clk/clk_fixed.h>
50 #include <dev/extres/clk/clk_mux.h>
52 #include <arm/allwinner/clkng/aw_ccung.h>
54 #include <gnu/dts/include/dt-bindings/clock/sun8i-de2.h>
55 #include <gnu/dts/include/dt-bindings/reset/sun8i-de2.h>
57 /* Non exported clocks */
58 #define CLK_MIXER0_DIV 3
59 #define CLK_MIXER1_DIV 4
62 static struct aw_ccung_reset de2_ccu_resets[] = {
63 CCU_RESET(RST_MIXER0, 0x08, 0)
64 CCU_RESET(RST_MIXER1, 0x08, 1)
65 CCU_RESET(RST_WB, 0x08, 2)
68 static struct aw_ccung_gate de2_ccu_gates[] = {
69 CCU_GATE(CLK_BUS_MIXER0, "mixer0", "mixer0-div", 0x00, 0)
70 CCU_GATE(CLK_BUS_MIXER1, "mixer1", "mixer1-div", 0x00, 1)
71 CCU_GATE(CLK_BUS_WB, "wb", "wb-div", 0x00, 2)
73 CCU_GATE(CLK_MIXER0, "bus-mixer0", "bus-de", 0x04, 0)
74 CCU_GATE(CLK_MIXER1, "bus-mixer1", "bus-de", 0x04, 1)
75 CCU_GATE(CLK_WB, "bus-wb", "bus-de", 0x04, 2)
78 static const char *div_parents[] = {"de"};
80 NM_CLK(mixer0_div_clk,
81 CLK_MIXER0_DIV, /* id */
82 "mixer0-div", div_parents, /* names, parents */
84 0, 0, 1, AW_CLK_FACTOR_FIXED, /* N factor (fake)*/
85 0, 4, 0, 0, /* M flags */
88 AW_CLK_SCALE_CHANGE); /* flags */
90 NM_CLK(mixer1_div_clk,
91 CLK_MIXER1_DIV, /* id */
92 "mixer1-div", div_parents, /* names, parents */
94 0, 0, 1, AW_CLK_FACTOR_FIXED, /* N factor (fake)*/
95 4, 4, 0, 0, /* M flags */
98 AW_CLK_SCALE_CHANGE); /* flags */
102 "wb-div", div_parents, /* names, parents */
104 0, 0, 1, AW_CLK_FACTOR_FIXED, /* N factor (fake)*/
105 8, 4, 0, 0, /* M flags */
108 AW_CLK_SCALE_CHANGE); /* flags */
110 static struct aw_ccung_clk de2_ccu_clks[] = {
111 { .type = AW_CLK_NM, .clk.nm = &mixer0_div_clk},
112 { .type = AW_CLK_NM, .clk.nm = &mixer1_div_clk},
113 { .type = AW_CLK_NM, .clk.nm = &wb_div_clk},
116 static struct ofw_compat_data compat_data[] = {
117 {"allwinner,sun50i-a64-de2-clk", 1},
122 ccu_de2_probe(device_t dev)
125 if (!ofw_bus_status_okay(dev))
128 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
131 device_set_desc(dev, "Allwinner DE2 Clock Control Unit");
132 return (BUS_PROBE_DEFAULT);
136 ccu_de2_attach(device_t dev)
138 struct aw_ccung_softc *sc;
140 sc = device_get_softc(dev);
142 sc->resets = de2_ccu_resets;
143 sc->nresets = nitems(de2_ccu_resets);
144 sc->gates = de2_ccu_gates;
145 sc->ngates = nitems(de2_ccu_gates);
146 sc->clks = de2_ccu_clks;
147 sc->nclks = nitems(de2_ccu_clks);
149 return (aw_ccung_attach(dev));
152 static device_method_t ccu_de2_methods[] = {
153 /* Device interface */
154 DEVMETHOD(device_probe, ccu_de2_probe),
155 DEVMETHOD(device_attach, ccu_de2_attach),
160 static devclass_t ccu_de2ng_devclass;
162 DEFINE_CLASS_1(ccu_de2, ccu_de2_driver, ccu_de2_methods,
163 sizeof(struct aw_ccung_softc), aw_ccung_driver);
165 EARLY_DRIVER_MODULE(ccu_de2, simplebus, ccu_de2_driver,
166 ccu_de2ng_devclass, 0, 0, BUS_PASS_RESOURCE + BUS_PASS_ORDER_LAST);