]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/allwinner/clkng/ccu_de2.c
Update apr-util to 1.6.1. See contrib/apr-util/CHANGES for a summary of
[FreeBSD/FreeBSD.git] / sys / arm / allwinner / clkng / ccu_de2.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2018 Emmanuel Vadot <manu@freebsd.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
14  *
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
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/bus.h>
36 #include <sys/rman.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <machine/bus.h>
40
41 #include <dev/fdt/simplebus.h>
42
43 #include <dev/ofw/ofw_bus.h>
44 #include <dev/ofw/ofw_bus_subr.h>
45
46 #include "opt_soc.h"
47
48 #include <dev/extres/clk/clk_div.h>
49 #include <dev/extres/clk/clk_fixed.h>
50 #include <dev/extres/clk/clk_mux.h>
51
52 #include <arm/allwinner/clkng/aw_ccung.h>
53
54 #include <gnu/dts/include/dt-bindings/clock/sun8i-de2.h>
55 #include <gnu/dts/include/dt-bindings/reset/sun8i-de2.h>
56
57 /* Non exported clocks */
58 #define CLK_MIXER0_DIV  3
59 #define CLK_MIXER1_DIV  4
60 #define CLK_WB_DIV      5
61
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)
66 };
67
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)
72
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)
76 };
77
78 static const char *div_parents[] = {"de"};
79
80 NM_CLK(mixer0_div_clk,
81     CLK_MIXER0_DIV,                     /* id */
82     "mixer0-div", div_parents,          /* names, parents */
83     0x0C,                               /* offset */
84     0, 0, 1, AW_CLK_FACTOR_FIXED,       /* N factor (fake)*/
85     0, 4, 0, 0,                         /* M flags */
86     0, 0,                               /* mux */
87     0,                                  /* gate */
88     AW_CLK_SCALE_CHANGE);       /* flags */
89
90 NM_CLK(mixer1_div_clk,
91     CLK_MIXER1_DIV,                     /* id */
92     "mixer1-div", div_parents,          /* names, parents */
93     0x0C,                               /* offset */
94     0, 0, 1, AW_CLK_FACTOR_FIXED,       /* N factor (fake)*/
95     4, 4, 0, 0,                         /* M flags */
96     0, 0,                               /* mux */
97     0,                                  /* gate */
98     AW_CLK_SCALE_CHANGE);       /* flags */
99
100 NM_CLK(wb_div_clk,
101     CLK_WB_DIV,                         /* id */
102     "wb-div", div_parents,              /* names, parents */
103     0x0C,                               /* offset */
104     0, 0, 1, AW_CLK_FACTOR_FIXED,       /* N factor (fake)*/
105     8, 4, 0, 0,                         /* M flags */
106     0, 0,                               /* mux */
107     0,                                  /* gate */
108     AW_CLK_SCALE_CHANGE);       /* flags */
109
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},
114 };
115
116 static struct ofw_compat_data compat_data[] = {
117         {"allwinner,sun50i-a64-de2-clk", 1},
118         {NULL,             0}
119 };
120
121 static int
122 ccu_de2_probe(device_t dev)
123 {
124
125         if (!ofw_bus_status_okay(dev))
126                 return (ENXIO);
127
128         if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
129                 return (ENXIO);
130
131         device_set_desc(dev, "Allwinner DE2 Clock Control Unit");
132         return (BUS_PROBE_DEFAULT);
133 }
134
135 static int
136 ccu_de2_attach(device_t dev)
137 {
138         struct aw_ccung_softc *sc;
139
140         sc = device_get_softc(dev);
141
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);
148
149         return (aw_ccung_attach(dev));
150 }
151
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),
156
157         DEVMETHOD_END
158 };
159
160 static devclass_t ccu_de2ng_devclass;
161
162 DEFINE_CLASS_1(ccu_de2, ccu_de2_driver, ccu_de2_methods,
163   sizeof(struct aw_ccung_softc), aw_ccung_driver);
164
165 EARLY_DRIVER_MODULE(ccu_de2, simplebus, ccu_de2_driver,
166     ccu_de2ng_devclass, 0, 0, BUS_PASS_RESOURCE + BUS_PASS_ORDER_LAST);