meson8b_clkc.c revision 1.3.4.3 1 1.3.4.3 martin /* $NetBSD: meson8b_clkc.c,v 1.3.4.3 2020/04/13 08:03:32 martin Exp $ */
2 1.3.4.2 christos
3 1.3.4.2 christos /*-
4 1.3.4.2 christos * Copyright (c) 2019 Jared McNeill <jmcneill (at) invisible.ca>
5 1.3.4.2 christos * All rights reserved.
6 1.3.4.2 christos *
7 1.3.4.2 christos * Redistribution and use in source and binary forms, with or without
8 1.3.4.2 christos * modification, are permitted provided that the following conditions
9 1.3.4.2 christos * are met:
10 1.3.4.2 christos * 1. Redistributions of source code must retain the above copyright
11 1.3.4.2 christos * notice, this list of conditions and the following disclaimer.
12 1.3.4.2 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.3.4.2 christos * notice, this list of conditions and the following disclaimer in the
14 1.3.4.2 christos * documentation and/or other materials provided with the distribution.
15 1.3.4.2 christos *
16 1.3.4.2 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.3.4.2 christos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.3.4.2 christos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.3.4.2 christos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.3.4.2 christos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.3.4.2 christos * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.3.4.2 christos * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.3.4.2 christos * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.3.4.2 christos * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.3.4.2 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.3.4.2 christos * SUCH DAMAGE.
27 1.3.4.2 christos */
28 1.3.4.2 christos
29 1.3.4.2 christos #include <sys/cdefs.h>
30 1.3.4.2 christos
31 1.3.4.3 martin __KERNEL_RCSID(1, "$NetBSD: meson8b_clkc.c,v 1.3.4.3 2020/04/13 08:03:32 martin Exp $");
32 1.3.4.2 christos
33 1.3.4.2 christos #include <sys/param.h>
34 1.3.4.2 christos #include <sys/bus.h>
35 1.3.4.2 christos #include <sys/device.h>
36 1.3.4.2 christos #include <sys/systm.h>
37 1.3.4.2 christos
38 1.3.4.2 christos #include <dev/fdt/fdtvar.h>
39 1.3.4.2 christos
40 1.3.4.2 christos #include <arm/amlogic/meson_clk.h>
41 1.3.4.2 christos #include <arm/amlogic/meson8b_clkc.h>
42 1.3.4.2 christos
43 1.3.4.2 christos /*
44 1.3.4.2 christos * The DT for amlogic,meson8b-clkc defines two reg resources. The first
45 1.3.4.2 christos * is not used by this driver.
46 1.3.4.2 christos */
47 1.3.4.2 christos #define MESON8B_CLKC_REG_INDEX 1
48 1.3.4.2 christos
49 1.3.4.2 christos #define CBUS_REG(x) ((x) << 2)
50 1.3.4.2 christos
51 1.3.4.2 christos #define HHI_GCLK_MPEG0 CBUS_REG(0x50)
52 1.3.4.2 christos #define HHI_GCLK_MPEG1 CBUS_REG(0x51)
53 1.3.4.2 christos #define HHI_GCLK_MPEG2 CBUS_REG(0x52)
54 1.3.4.2 christos #define HHI_SYS_CPU_CLK_CNTL1 CBUS_REG(0x57)
55 1.3.4.2 christos #define HHI_MPEG_CLK_CNTL CBUS_REG(0x5d)
56 1.3.4.2 christos #define HHI_SYS_CPU_CLK_CNTL0 CBUS_REG(0x67)
57 1.3.4.2 christos #define HHI_SYS_CPU_CLK_CNTL0_CLKSEL __BIT(7)
58 1.3.4.2 christos #define HHI_SYS_CPU_CLK_CNTL0_SOUTSEL __BITS(3,2)
59 1.3.4.2 christos #define HHI_SYS_CPU_CLK_CNTL0_PLLSEL __BITS(1,0)
60 1.3.4.2 christos #define HHI_MPLL_CNTL CBUS_REG(0xa0)
61 1.3.4.2 christos #define HHI_MPLL_CNTL2 CBUS_REG(0xa1)
62 1.3.4.2 christos #define HHI_MPLL_CNTL5 CBUS_REG(0xa4)
63 1.3.4.2 christos #define HHI_MPLL_CNTL6 CBUS_REG(0xa5)
64 1.3.4.2 christos #define HHI_MPLL_CNTL7 CBUS_REG(0xa6)
65 1.3.4.2 christos #define HHI_MPLL_CNTL8 CBUS_REG(0xa7)
66 1.3.4.2 christos #define HHI_MPLL_CNTL9 CBUS_REG(0xa8)
67 1.3.4.2 christos #define HHI_SYS_PLL_CNTL CBUS_REG(0xc0)
68 1.3.4.2 christos #define HHI_SYS_PLL_CNTL_LOCK __BIT(31)
69 1.3.4.2 christos #define HHI_SYS_PLL_CNTL_OD __BITS(17,16)
70 1.3.4.2 christos #define HHI_SYS_PLL_CNTL_DIV __BITS(14,9)
71 1.3.4.2 christos #define HHI_SYS_PLL_CNTL_MUL __BITS(8,0)
72 1.3.4.2 christos
73 1.3.4.2 christos static int meson8b_clkc_match(device_t, cfdata_t, void *);
74 1.3.4.2 christos static void meson8b_clkc_attach(device_t, device_t, void *);
75 1.3.4.2 christos
76 1.3.4.2 christos static const char * const compatible[] = {
77 1.3.4.3 martin "amlogic,meson8-clkc",
78 1.3.4.2 christos "amlogic,meson8b-clkc",
79 1.3.4.2 christos NULL
80 1.3.4.2 christos };
81 1.3.4.2 christos
82 1.3.4.2 christos CFATTACH_DECL_NEW(meson8b_clkc, sizeof(struct meson_clk_softc),
83 1.3.4.2 christos meson8b_clkc_match, meson8b_clkc_attach, NULL, NULL);
84 1.3.4.2 christos
85 1.3.4.2 christos static struct meson_clk_reset meson8b_clkc_resets[] = {
86 1.3.4.2 christos MESON_CLK_RESET(MESON8B_RESET_CPU0_SOFT_RESET, HHI_SYS_CPU_CLK_CNTL0, 24),
87 1.3.4.2 christos MESON_CLK_RESET(MESON8B_RESET_CPU1_SOFT_RESET, HHI_SYS_CPU_CLK_CNTL0, 25),
88 1.3.4.2 christos MESON_CLK_RESET(MESON8B_RESET_CPU2_SOFT_RESET, HHI_SYS_CPU_CLK_CNTL0, 26),
89 1.3.4.2 christos MESON_CLK_RESET(MESON8B_RESET_CPU3_SOFT_RESET, HHI_SYS_CPU_CLK_CNTL0, 27),
90 1.3.4.2 christos };
91 1.3.4.2 christos
92 1.3.4.2 christos static const char *mpeg_sel_parents[] = { "xtal", NULL, "fclk_div7", "mpll_clkout1", "mpll_clkout2", "fclk_div4", "fclk_div3", "fclk_div5" };
93 1.3.4.2 christos static const char *cpu_in_sel_parents[] = { "xtal", "sys_pll" };
94 1.3.4.2 christos static const char *cpu_scale_out_sel_parents[] = { "cpu_in_sel", "cpu_in_div2", "cpu_in_div3", "cpu_scale_div" };
95 1.3.4.2 christos static const char *cpu_clk_parents[] = { "xtal", "cpu_scale_out_sel" };
96 1.3.4.2 christos static const char *periph_clk_sel_parents[] = { "cpu_clk_div2", "cpu_clk_div3", "cpu_clk_div4", "cpu_clk_div5", "cpu_clk_div6", "cpu_clk_div7", "cpu_clk_div8" };
97 1.3.4.2 christos
98 1.3.4.2 christos static int
99 1.3.4.2 christos meson8b_clkc_pll_sys_set_rate(struct meson_clk_softc *sc,
100 1.3.4.2 christos struct meson_clk_clk *clk, u_int rate)
101 1.3.4.2 christos {
102 1.3.4.2 christos struct clk *clkp, *clkp_parent;
103 1.3.4.2 christos int error;
104 1.3.4.2 christos
105 1.3.4.2 christos KASSERT(clk->type == MESON_CLK_PLL);
106 1.3.4.2 christos
107 1.3.4.2 christos clkp = &clk->base;
108 1.3.4.2 christos clkp_parent = clk_get_parent(clkp);
109 1.3.4.2 christos if (clkp_parent == NULL)
110 1.3.4.2 christos return ENXIO;
111 1.3.4.2 christos
112 1.3.4.2 christos const u_int old_rate = clk_get_rate(clkp);
113 1.3.4.2 christos if (old_rate == rate)
114 1.3.4.2 christos return 0;
115 1.3.4.2 christos
116 1.3.4.2 christos const u_int parent_rate = clk_get_rate(clkp_parent);
117 1.3.4.2 christos if (parent_rate == 0)
118 1.3.4.2 christos return EIO;
119 1.3.4.2 christos
120 1.3.4.2 christos CLK_LOCK(sc);
121 1.3.4.2 christos
122 1.3.4.2 christos uint32_t cntl0 = CLK_READ(sc, HHI_SYS_CPU_CLK_CNTL0);
123 1.3.4.2 christos uint32_t cntl = CLK_READ(sc, HHI_SYS_PLL_CNTL);
124 1.3.4.2 christos
125 1.3.4.2 christos u_int new_mul = rate / parent_rate;
126 1.3.4.2 christos u_int new_div = 1;
127 1.3.4.2 christos u_int new_od = 0;
128 1.3.4.2 christos
129 1.3.4.2 christos if (rate < 600 * 1000000) {
130 1.3.4.2 christos new_od = 2;
131 1.3.4.2 christos new_mul *= 4;
132 1.3.4.2 christos } else if (rate < 1200 * 1000000) {
133 1.3.4.2 christos new_od = 1;
134 1.3.4.2 christos new_mul *= 2;
135 1.3.4.2 christos }
136 1.3.4.2 christos
137 1.3.4.2 christos if ((cntl0 & HHI_SYS_CPU_CLK_CNTL0_CLKSEL) == 0) {
138 1.3.4.2 christos error = EIO;
139 1.3.4.2 christos goto done;
140 1.3.4.2 christos }
141 1.3.4.2 christos if (__SHIFTOUT(cntl0, HHI_SYS_CPU_CLK_CNTL0_PLLSEL) != 1) {
142 1.3.4.2 christos error = EIO;
143 1.3.4.2 christos goto done;
144 1.3.4.2 christos }
145 1.3.4.2 christos if (__SHIFTOUT(cntl0, HHI_SYS_CPU_CLK_CNTL0_SOUTSEL) != 0) {
146 1.3.4.2 christos error = EIO;
147 1.3.4.2 christos goto done;
148 1.3.4.2 christos }
149 1.3.4.2 christos
150 1.3.4.2 christos cntl &= ~HHI_SYS_PLL_CNTL_MUL;
151 1.3.4.2 christos cntl |= __SHIFTIN(new_mul, HHI_SYS_PLL_CNTL_MUL);
152 1.3.4.2 christos cntl &= ~HHI_SYS_PLL_CNTL_DIV;
153 1.3.4.2 christos cntl |= __SHIFTIN(new_div, HHI_SYS_PLL_CNTL_DIV);
154 1.3.4.2 christos cntl &= ~HHI_SYS_PLL_CNTL_OD;
155 1.3.4.2 christos cntl |= __SHIFTIN(new_od, HHI_SYS_PLL_CNTL_OD);
156 1.3.4.2 christos
157 1.3.4.2 christos /* Switch CPU to XTAL clock */
158 1.3.4.2 christos cntl0 &= ~HHI_SYS_CPU_CLK_CNTL0_CLKSEL;
159 1.3.4.2 christos CLK_WRITE(sc, HHI_SYS_CPU_CLK_CNTL0, cntl0);
160 1.3.4.2 christos
161 1.3.4.2 christos delay((100 * old_rate) / parent_rate);
162 1.3.4.2 christos
163 1.3.4.2 christos /* Update multiplier */
164 1.3.4.2 christos do {
165 1.3.4.2 christos CLK_WRITE(sc, HHI_SYS_PLL_CNTL, cntl);
166 1.3.4.2 christos
167 1.3.4.2 christos /* Switch CPU to sys pll */
168 1.3.4.2 christos cntl0 |= HHI_SYS_CPU_CLK_CNTL0_CLKSEL;
169 1.3.4.2 christos CLK_WRITE(sc, HHI_SYS_CPU_CLK_CNTL0, cntl0);
170 1.3.4.2 christos } while ((CLK_READ(sc, HHI_SYS_PLL_CNTL) & HHI_SYS_PLL_CNTL_LOCK) == 0);
171 1.3.4.2 christos
172 1.3.4.2 christos error = 0;
173 1.3.4.2 christos
174 1.3.4.2 christos done:
175 1.3.4.2 christos CLK_UNLOCK(sc);
176 1.3.4.2 christos
177 1.3.4.2 christos return error;
178 1.3.4.2 christos }
179 1.3.4.2 christos
180 1.3.4.2 christos static struct meson_clk_clk meson8b_clkc_clks[] = {
181 1.3.4.2 christos
182 1.3.4.2 christos MESON_CLK_FIXED(MESON8B_CLOCK_XTAL, "xtal", 24000000),
183 1.3.4.2 christos
184 1.3.4.2 christos MESON_CLK_PLL_RATE(MESON8B_CLOCK_PLL_SYS_DCO, "pll_sys_dco", "xtal",
185 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BIT(30)), /* enable */
186 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BITS(8,0)), /* m */
187 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BITS(13,9)), /* n */
188 1.3.4.2 christos MESON_CLK_PLL_REG_INVALID, /* frac */
189 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BIT(31)), /* l */
190 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BIT(29)), /* reset */
191 1.3.4.2 christos meson8b_clkc_pll_sys_set_rate,
192 1.3.4.2 christos 0),
193 1.3.4.2 christos
194 1.3.4.2 christos MESON_CLK_DIV(MESON8B_CLOCK_PLL_SYS, "sys_pll", "pll_sys_dco",
195 1.3.4.2 christos HHI_SYS_PLL_CNTL, /* reg */
196 1.3.4.2 christos __BITS(17,16), /* div */
197 1.3.4.2 christos MESON_CLK_DIV_POWER_OF_TWO | MESON_CLK_DIV_SET_RATE_PARENT),
198 1.3.4.2 christos
199 1.3.4.2 christos MESON_CLK_MUX(MESON8B_CLOCK_CPU_IN_SEL, "cpu_in_sel", cpu_in_sel_parents,
200 1.3.4.2 christos HHI_SYS_CPU_CLK_CNTL0, /* reg */
201 1.3.4.2 christos __BIT(0), /* sel */
202 1.3.4.2 christos 0),
203 1.3.4.2 christos
204 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_IN_DIV2, "cpu_in_div2", "cpu_in_sel", 2, 1),
205 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_IN_DIV3, "cpu_in_div3", "cpu_in_sel", 3, 1),
206 1.3.4.2 christos
207 1.3.4.2 christos MESON_CLK_DIV(MESON8B_CLOCK_CPU_SCALE_DIV, "cpu_scale_div", "cpu_in_sel",
208 1.3.4.2 christos HHI_SYS_CPU_CLK_CNTL1, /* reg */
209 1.3.4.2 christos __BITS(29,20), /* div */
210 1.3.4.2 christos MESON_CLK_DIV_CPU_SCALE_TABLE | MESON_CLK_DIV_SET_RATE_PARENT),
211 1.3.4.2 christos
212 1.3.4.2 christos MESON_CLK_MUX(MESON8B_CLOCK_CPU_SCALE_OUT_SEL, "cpu_scale_out_sel", cpu_scale_out_sel_parents,
213 1.3.4.2 christos HHI_SYS_CPU_CLK_CNTL0, /* reg */
214 1.3.4.2 christos __BITS(3,2), /* sel */
215 1.3.4.2 christos 0),
216 1.3.4.2 christos
217 1.3.4.2 christos MESON_CLK_MUX(MESON8B_CLOCK_CPUCLK, "cpu_clk", cpu_clk_parents,
218 1.3.4.2 christos HHI_SYS_CPU_CLK_CNTL0, /* reg */
219 1.3.4.2 christos __BIT(7), /* sel */
220 1.3.4.2 christos 0),
221 1.3.4.2 christos
222 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV2, "cpu_clk_div2", "cpu_clk", 2, 1),
223 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV3, "cpu_clk_div3", "cpu_clk", 3, 1),
224 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV4, "cpu_clk_div4", "cpu_clk", 4, 1),
225 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV5, "cpu_clk_div5", "cpu_clk", 5, 1),
226 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV6, "cpu_clk_div6", "cpu_clk", 6, 1),
227 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV7, "cpu_clk_div7", "cpu_clk", 7, 1),
228 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV8, "cpu_clk_div8", "cpu_clk", 8, 1),
229 1.3.4.2 christos
230 1.3.4.2 christos MESON_CLK_MUX(MESON8B_CLOCK_PERIPH_SEL, "periph_clk_sel", periph_clk_sel_parents,
231 1.3.4.2 christos HHI_SYS_CPU_CLK_CNTL1, /* reg */
232 1.3.4.2 christos __BITS(8,6), /* sel */
233 1.3.4.2 christos 0),
234 1.3.4.2 christos MESON_CLK_GATE_FLAGS(MESON8B_CLOCK_PERIPH, "periph_clk_dis", "periph_clk_sel",
235 1.3.4.2 christos HHI_SYS_CPU_CLK_CNTL1, /* reg */
236 1.3.4.2 christos 17, /* bit */
237 1.3.4.2 christos MESON_CLK_GATE_SET_TO_DISABLE),
238 1.3.4.2 christos
239 1.3.4.2 christos MESON_CLK_PLL(MESON8B_CLOCK_PLL_FIXED_DCO, "pll_fixed_dco", "xtal",
240 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BIT(30)), /* enable */
241 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BITS(8,0)), /* m */
242 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BITS(13,9)), /* n */
243 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL2, __BITS(11,0)), /* frac */
244 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BIT(31)), /* l */
245 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BIT(29)), /* reset */
246 1.3.4.2 christos 0),
247 1.3.4.2 christos
248 1.3.4.2 christos MESON_CLK_DIV(MESON8B_CLOCK_PLL_FIXED, "pll_fixed", "pll_fixed_dco",
249 1.3.4.2 christos HHI_MPLL_CNTL, /* reg */
250 1.3.4.2 christos __BITS(17,16), /* div */
251 1.3.4.2 christos MESON_CLK_DIV_POWER_OF_TWO),
252 1.3.4.2 christos
253 1.3.4.2 christos MESON_CLK_DIV(MESON8B_CLOCK_MPLL_PREDIV, "mpll_prediv", "pll_fixed",
254 1.3.4.2 christos HHI_MPLL_CNTL5, /* reg */
255 1.3.4.2 christos __BIT(12), /* div */
256 1.3.4.2 christos 0),
257 1.3.4.2 christos
258 1.3.4.2 christos MESON_CLK_MPLL(MESON8B_CLOCK_MPLL0_DIV, "mpll0_div", "mpll_prediv",
259 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL7, __BITS(13,0)), /* sdm */
260 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL7, __BIT(15)), /* sdm_enable */
261 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL7, __BITS(24,16)), /* n2 */
262 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BIT(25)), /* ssen */
263 1.3.4.2 christos 0),
264 1.3.4.2 christos MESON_CLK_MPLL(MESON8B_CLOCK_MPLL1_DIV, "mpll1_div", "mpll_prediv",
265 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BITS(13,0)), /* sdm */
266 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BIT(15)), /* sdm_enable */
267 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BITS(24,16)), /* n2 */
268 1.3.4.2 christos MESON_CLK_PLL_REG_INVALID, /* ssen */
269 1.3.4.2 christos 0),
270 1.3.4.2 christos MESON_CLK_MPLL(MESON8B_CLOCK_MPLL2_DIV, "mpll2_div", "mpll_prediv",
271 1.3.4.3 martin MESON_CLK_PLL_REG(HHI_MPLL_CNTL9, __BITS(13,0)), /* sdm */
272 1.3.4.3 martin MESON_CLK_PLL_REG(HHI_MPLL_CNTL9, __BIT(15)), /* sdm_enable */
273 1.3.4.3 martin MESON_CLK_PLL_REG(HHI_MPLL_CNTL9, __BITS(24,16)), /* n2 */
274 1.3.4.2 christos MESON_CLK_PLL_REG_INVALID, /* ssen */
275 1.3.4.2 christos 0),
276 1.3.4.2 christos
277 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_MPLL0, "mpll0", "mpll0_div", HHI_MPLL_CNTL7, 14),
278 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_MPLL1, "mpll1", "mpll1_div", HHI_MPLL_CNTL8, 14),
279 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_MPLL2, "mpll2", "mpll2_div", HHI_MPLL_CNTL9, 14),
280 1.3.4.2 christos
281 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV2_DIV, "fclk_div2_div", "pll_fixed", 2, 1),
282 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV3_DIV, "fclk_div3_div", "pll_fixed", 3, 1),
283 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV4_DIV, "fclk_div4_div", "pll_fixed", 4, 1),
284 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV5_DIV, "fclk_div5_div", "pll_fixed", 5, 1),
285 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV7_DIV, "fclk_div7_div", "pll_fixed", 7, 1),
286 1.3.4.2 christos
287 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV2, "fclk_div2", "fclk_div2_div", HHI_MPLL_CNTL6, 27),
288 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV3, "fclk_div3", "fclk_div3_div", HHI_MPLL_CNTL6, 28),
289 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV4, "fclk_div4", "fclk_div4_div", HHI_MPLL_CNTL6, 29),
290 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV5, "fclk_div5", "fclk_div5_div", HHI_MPLL_CNTL6, 30),
291 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV7, "fclk_div7", "fclk_div7_div", HHI_MPLL_CNTL6, 31),
292 1.3.4.2 christos
293 1.3.4.2 christos MESON_CLK_MUX(MESON8B_CLOCK_MPEG_SEL, "mpeg_sel", mpeg_sel_parents,
294 1.3.4.2 christos HHI_MPEG_CLK_CNTL, /* reg */
295 1.3.4.2 christos __BITS(14,12), /* sel */
296 1.3.4.2 christos 0),
297 1.3.4.2 christos
298 1.3.4.2 christos MESON_CLK_DIV(MESON8B_CLOCK_MPEG_DIV, "mpeg_div", "mpeg_sel",
299 1.3.4.2 christos HHI_MPEG_CLK_CNTL, /* reg */
300 1.3.4.2 christos __BITS(6,0), /* div */
301 1.3.4.2 christos 0),
302 1.3.4.2 christos
303 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_CLK81, "clk81", "mpeg_div", HHI_MPEG_CLK_CNTL, 7),
304 1.3.4.2 christos
305 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_I2C, "i2c", "clk81", HHI_GCLK_MPEG0, 9),
306 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_SAR_ADC, "sar_adc", "clk81", HHI_GCLK_MPEG0, 10),
307 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_RNG0, "rng0", "clk81", HHI_GCLK_MPEG0, 12),
308 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_UART0, "uart0", "clk81", HHI_GCLK_MPEG0, 13),
309 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_SDHC, "sdhc", "clk81", HHI_GCLK_MPEG0, 14),
310 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_SDIO, "sdio", "clk81", HHI_GCLK_MPEG0, 17),
311 1.3.4.2 christos
312 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_ETH, "eth", "clk81", HHI_GCLK_MPEG1, 3),
313 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_UART1, "uart1", "clk81", HHI_GCLK_MPEG1, 16),
314 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_USB0, "usb0", "clk81", HHI_GCLK_MPEG1, 21),
315 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_USB1, "usb1", "clk81", HHI_GCLK_MPEG1, 22),
316 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_USB, "usb", "clk81", HHI_GCLK_MPEG1, 26),
317 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_EFUSE, "efuse", "clk81", HHI_GCLK_MPEG1, 30),
318 1.3.4.2 christos
319 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_USB1_DDR_BRIDGE, "usb1_ddr_bridge", "clk81", HHI_GCLK_MPEG2, 8),
320 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_USB0_DDR_BRIDGE, "usb0_ddr_bridge", "clk81", HHI_GCLK_MPEG2, 9),
321 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_UART2, "uart2", "clk81", HHI_GCLK_MPEG2, 15),
322 1.3.4.2 christos };
323 1.3.4.2 christos
324 1.3.4.2 christos static int
325 1.3.4.2 christos meson8b_clkc_match(device_t parent, cfdata_t cf, void *aux)
326 1.3.4.2 christos {
327 1.3.4.2 christos struct fdt_attach_args * const faa = aux;
328 1.3.4.2 christos
329 1.3.4.2 christos return of_match_compatible(faa->faa_phandle, compatible);
330 1.3.4.2 christos }
331 1.3.4.2 christos
332 1.3.4.2 christos static void
333 1.3.4.2 christos meson8b_clkc_attach(device_t parent, device_t self, void *aux)
334 1.3.4.2 christos {
335 1.3.4.2 christos struct meson_clk_softc * const sc = device_private(self);
336 1.3.4.2 christos struct fdt_attach_args * const faa = aux;
337 1.3.4.2 christos
338 1.3.4.2 christos sc->sc_dev = self;
339 1.3.4.2 christos sc->sc_phandle = faa->faa_phandle;
340 1.3.4.3 martin sc->sc_syscon = fdtbus_syscon_lookup(OF_parent(sc->sc_phandle));
341 1.3.4.3 martin if (sc->sc_syscon == NULL) {
342 1.3.4.3 martin aprint_error(": couldn't get syscon registers\n");
343 1.3.4.2 christos return;
344 1.3.4.2 christos }
345 1.3.4.2 christos
346 1.3.4.2 christos sc->sc_resets = meson8b_clkc_resets;
347 1.3.4.2 christos sc->sc_nresets = __arraycount(meson8b_clkc_resets);
348 1.3.4.2 christos
349 1.3.4.2 christos sc->sc_clks = meson8b_clkc_clks;
350 1.3.4.2 christos sc->sc_nclks = __arraycount(meson8b_clkc_clks);
351 1.3.4.2 christos
352 1.3.4.2 christos meson_clk_attach(sc);
353 1.3.4.2 christos
354 1.3.4.2 christos aprint_naive("\n");
355 1.3.4.2 christos aprint_normal(": Meson8b clock controller\n");
356 1.3.4.2 christos
357 1.3.4.2 christos meson_clk_print(sc);
358 1.3.4.2 christos }
359