meson8b_clkc.c revision 1.3.4.2 1 1.3.4.2 christos /* $NetBSD: meson8b_clkc.c,v 1.3.4.2 2019/06/10 22:05:51 christos 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.2 christos __KERNEL_RCSID(1, "$NetBSD: meson8b_clkc.c,v 1.3.4.2 2019/06/10 22:05:51 christos 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.2 christos "amlogic,meson8b-clkc",
78 1.3.4.2 christos NULL
79 1.3.4.2 christos };
80 1.3.4.2 christos
81 1.3.4.2 christos CFATTACH_DECL_NEW(meson8b_clkc, sizeof(struct meson_clk_softc),
82 1.3.4.2 christos meson8b_clkc_match, meson8b_clkc_attach, NULL, NULL);
83 1.3.4.2 christos
84 1.3.4.2 christos static struct meson_clk_reset meson8b_clkc_resets[] = {
85 1.3.4.2 christos MESON_CLK_RESET(MESON8B_RESET_CPU0_SOFT_RESET, HHI_SYS_CPU_CLK_CNTL0, 24),
86 1.3.4.2 christos MESON_CLK_RESET(MESON8B_RESET_CPU1_SOFT_RESET, HHI_SYS_CPU_CLK_CNTL0, 25),
87 1.3.4.2 christos MESON_CLK_RESET(MESON8B_RESET_CPU2_SOFT_RESET, HHI_SYS_CPU_CLK_CNTL0, 26),
88 1.3.4.2 christos MESON_CLK_RESET(MESON8B_RESET_CPU3_SOFT_RESET, HHI_SYS_CPU_CLK_CNTL0, 27),
89 1.3.4.2 christos };
90 1.3.4.2 christos
91 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" };
92 1.3.4.2 christos static const char *cpu_in_sel_parents[] = { "xtal", "sys_pll" };
93 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" };
94 1.3.4.2 christos static const char *cpu_clk_parents[] = { "xtal", "cpu_scale_out_sel" };
95 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" };
96 1.3.4.2 christos
97 1.3.4.2 christos static int
98 1.3.4.2 christos meson8b_clkc_pll_sys_set_rate(struct meson_clk_softc *sc,
99 1.3.4.2 christos struct meson_clk_clk *clk, u_int rate)
100 1.3.4.2 christos {
101 1.3.4.2 christos struct clk *clkp, *clkp_parent;
102 1.3.4.2 christos int error;
103 1.3.4.2 christos
104 1.3.4.2 christos KASSERT(clk->type == MESON_CLK_PLL);
105 1.3.4.2 christos
106 1.3.4.2 christos clkp = &clk->base;
107 1.3.4.2 christos clkp_parent = clk_get_parent(clkp);
108 1.3.4.2 christos if (clkp_parent == NULL)
109 1.3.4.2 christos return ENXIO;
110 1.3.4.2 christos
111 1.3.4.2 christos const u_int old_rate = clk_get_rate(clkp);
112 1.3.4.2 christos if (old_rate == rate)
113 1.3.4.2 christos return 0;
114 1.3.4.2 christos
115 1.3.4.2 christos const u_int parent_rate = clk_get_rate(clkp_parent);
116 1.3.4.2 christos if (parent_rate == 0)
117 1.3.4.2 christos return EIO;
118 1.3.4.2 christos
119 1.3.4.2 christos CLK_LOCK(sc);
120 1.3.4.2 christos
121 1.3.4.2 christos uint32_t cntl0 = CLK_READ(sc, HHI_SYS_CPU_CLK_CNTL0);
122 1.3.4.2 christos uint32_t cntl = CLK_READ(sc, HHI_SYS_PLL_CNTL);
123 1.3.4.2 christos
124 1.3.4.2 christos u_int new_mul = rate / parent_rate;
125 1.3.4.2 christos u_int new_div = 1;
126 1.3.4.2 christos u_int new_od = 0;
127 1.3.4.2 christos
128 1.3.4.2 christos if (rate < 600 * 1000000) {
129 1.3.4.2 christos new_od = 2;
130 1.3.4.2 christos new_mul *= 4;
131 1.3.4.2 christos } else if (rate < 1200 * 1000000) {
132 1.3.4.2 christos new_od = 1;
133 1.3.4.2 christos new_mul *= 2;
134 1.3.4.2 christos }
135 1.3.4.2 christos
136 1.3.4.2 christos if ((cntl0 & HHI_SYS_CPU_CLK_CNTL0_CLKSEL) == 0) {
137 1.3.4.2 christos error = EIO;
138 1.3.4.2 christos goto done;
139 1.3.4.2 christos }
140 1.3.4.2 christos if (__SHIFTOUT(cntl0, HHI_SYS_CPU_CLK_CNTL0_PLLSEL) != 1) {
141 1.3.4.2 christos error = EIO;
142 1.3.4.2 christos goto done;
143 1.3.4.2 christos }
144 1.3.4.2 christos if (__SHIFTOUT(cntl0, HHI_SYS_CPU_CLK_CNTL0_SOUTSEL) != 0) {
145 1.3.4.2 christos error = EIO;
146 1.3.4.2 christos goto done;
147 1.3.4.2 christos }
148 1.3.4.2 christos
149 1.3.4.2 christos cntl &= ~HHI_SYS_PLL_CNTL_MUL;
150 1.3.4.2 christos cntl |= __SHIFTIN(new_mul, HHI_SYS_PLL_CNTL_MUL);
151 1.3.4.2 christos cntl &= ~HHI_SYS_PLL_CNTL_DIV;
152 1.3.4.2 christos cntl |= __SHIFTIN(new_div, HHI_SYS_PLL_CNTL_DIV);
153 1.3.4.2 christos cntl &= ~HHI_SYS_PLL_CNTL_OD;
154 1.3.4.2 christos cntl |= __SHIFTIN(new_od, HHI_SYS_PLL_CNTL_OD);
155 1.3.4.2 christos
156 1.3.4.2 christos /* Switch CPU to XTAL clock */
157 1.3.4.2 christos cntl0 &= ~HHI_SYS_CPU_CLK_CNTL0_CLKSEL;
158 1.3.4.2 christos CLK_WRITE(sc, HHI_SYS_CPU_CLK_CNTL0, cntl0);
159 1.3.4.2 christos
160 1.3.4.2 christos delay((100 * old_rate) / parent_rate);
161 1.3.4.2 christos
162 1.3.4.2 christos /* Update multiplier */
163 1.3.4.2 christos do {
164 1.3.4.2 christos CLK_WRITE(sc, HHI_SYS_PLL_CNTL, cntl);
165 1.3.4.2 christos
166 1.3.4.2 christos /* Switch CPU to sys pll */
167 1.3.4.2 christos cntl0 |= HHI_SYS_CPU_CLK_CNTL0_CLKSEL;
168 1.3.4.2 christos CLK_WRITE(sc, HHI_SYS_CPU_CLK_CNTL0, cntl0);
169 1.3.4.2 christos } while ((CLK_READ(sc, HHI_SYS_PLL_CNTL) & HHI_SYS_PLL_CNTL_LOCK) == 0);
170 1.3.4.2 christos
171 1.3.4.2 christos error = 0;
172 1.3.4.2 christos
173 1.3.4.2 christos done:
174 1.3.4.2 christos CLK_UNLOCK(sc);
175 1.3.4.2 christos
176 1.3.4.2 christos return error;
177 1.3.4.2 christos }
178 1.3.4.2 christos
179 1.3.4.2 christos static struct meson_clk_clk meson8b_clkc_clks[] = {
180 1.3.4.2 christos
181 1.3.4.2 christos MESON_CLK_FIXED(MESON8B_CLOCK_XTAL, "xtal", 24000000),
182 1.3.4.2 christos
183 1.3.4.2 christos MESON_CLK_PLL_RATE(MESON8B_CLOCK_PLL_SYS_DCO, "pll_sys_dco", "xtal",
184 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BIT(30)), /* enable */
185 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BITS(8,0)), /* m */
186 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BITS(13,9)), /* n */
187 1.3.4.2 christos MESON_CLK_PLL_REG_INVALID, /* frac */
188 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BIT(31)), /* l */
189 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_SYS_PLL_CNTL, __BIT(29)), /* reset */
190 1.3.4.2 christos meson8b_clkc_pll_sys_set_rate,
191 1.3.4.2 christos 0),
192 1.3.4.2 christos
193 1.3.4.2 christos MESON_CLK_DIV(MESON8B_CLOCK_PLL_SYS, "sys_pll", "pll_sys_dco",
194 1.3.4.2 christos HHI_SYS_PLL_CNTL, /* reg */
195 1.3.4.2 christos __BITS(17,16), /* div */
196 1.3.4.2 christos MESON_CLK_DIV_POWER_OF_TWO | MESON_CLK_DIV_SET_RATE_PARENT),
197 1.3.4.2 christos
198 1.3.4.2 christos MESON_CLK_MUX(MESON8B_CLOCK_CPU_IN_SEL, "cpu_in_sel", cpu_in_sel_parents,
199 1.3.4.2 christos HHI_SYS_CPU_CLK_CNTL0, /* reg */
200 1.3.4.2 christos __BIT(0), /* sel */
201 1.3.4.2 christos 0),
202 1.3.4.2 christos
203 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_IN_DIV2, "cpu_in_div2", "cpu_in_sel", 2, 1),
204 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_IN_DIV3, "cpu_in_div3", "cpu_in_sel", 3, 1),
205 1.3.4.2 christos
206 1.3.4.2 christos MESON_CLK_DIV(MESON8B_CLOCK_CPU_SCALE_DIV, "cpu_scale_div", "cpu_in_sel",
207 1.3.4.2 christos HHI_SYS_CPU_CLK_CNTL1, /* reg */
208 1.3.4.2 christos __BITS(29,20), /* div */
209 1.3.4.2 christos MESON_CLK_DIV_CPU_SCALE_TABLE | MESON_CLK_DIV_SET_RATE_PARENT),
210 1.3.4.2 christos
211 1.3.4.2 christos MESON_CLK_MUX(MESON8B_CLOCK_CPU_SCALE_OUT_SEL, "cpu_scale_out_sel", cpu_scale_out_sel_parents,
212 1.3.4.2 christos HHI_SYS_CPU_CLK_CNTL0, /* reg */
213 1.3.4.2 christos __BITS(3,2), /* sel */
214 1.3.4.2 christos 0),
215 1.3.4.2 christos
216 1.3.4.2 christos MESON_CLK_MUX(MESON8B_CLOCK_CPUCLK, "cpu_clk", cpu_clk_parents,
217 1.3.4.2 christos HHI_SYS_CPU_CLK_CNTL0, /* reg */
218 1.3.4.2 christos __BIT(7), /* sel */
219 1.3.4.2 christos 0),
220 1.3.4.2 christos
221 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV2, "cpu_clk_div2", "cpu_clk", 2, 1),
222 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV3, "cpu_clk_div3", "cpu_clk", 3, 1),
223 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV4, "cpu_clk_div4", "cpu_clk", 4, 1),
224 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV5, "cpu_clk_div5", "cpu_clk", 5, 1),
225 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV6, "cpu_clk_div6", "cpu_clk", 6, 1),
226 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV7, "cpu_clk_div7", "cpu_clk", 7, 1),
227 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_CPU_CLK_DIV8, "cpu_clk_div8", "cpu_clk", 8, 1),
228 1.3.4.2 christos
229 1.3.4.2 christos MESON_CLK_MUX(MESON8B_CLOCK_PERIPH_SEL, "periph_clk_sel", periph_clk_sel_parents,
230 1.3.4.2 christos HHI_SYS_CPU_CLK_CNTL1, /* reg */
231 1.3.4.2 christos __BITS(8,6), /* sel */
232 1.3.4.2 christos 0),
233 1.3.4.2 christos MESON_CLK_GATE_FLAGS(MESON8B_CLOCK_PERIPH, "periph_clk_dis", "periph_clk_sel",
234 1.3.4.2 christos HHI_SYS_CPU_CLK_CNTL1, /* reg */
235 1.3.4.2 christos 17, /* bit */
236 1.3.4.2 christos MESON_CLK_GATE_SET_TO_DISABLE),
237 1.3.4.2 christos
238 1.3.4.2 christos MESON_CLK_PLL(MESON8B_CLOCK_PLL_FIXED_DCO, "pll_fixed_dco", "xtal",
239 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BIT(30)), /* enable */
240 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BITS(8,0)), /* m */
241 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BITS(13,9)), /* n */
242 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL2, __BITS(11,0)), /* frac */
243 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BIT(31)), /* l */
244 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BIT(29)), /* reset */
245 1.3.4.2 christos 0),
246 1.3.4.2 christos
247 1.3.4.2 christos MESON_CLK_DIV(MESON8B_CLOCK_PLL_FIXED, "pll_fixed", "pll_fixed_dco",
248 1.3.4.2 christos HHI_MPLL_CNTL, /* reg */
249 1.3.4.2 christos __BITS(17,16), /* div */
250 1.3.4.2 christos MESON_CLK_DIV_POWER_OF_TWO),
251 1.3.4.2 christos
252 1.3.4.2 christos MESON_CLK_DIV(MESON8B_CLOCK_MPLL_PREDIV, "mpll_prediv", "pll_fixed",
253 1.3.4.2 christos HHI_MPLL_CNTL5, /* reg */
254 1.3.4.2 christos __BIT(12), /* div */
255 1.3.4.2 christos 0),
256 1.3.4.2 christos
257 1.3.4.2 christos MESON_CLK_MPLL(MESON8B_CLOCK_MPLL0_DIV, "mpll0_div", "mpll_prediv",
258 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL7, __BITS(13,0)), /* sdm */
259 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL7, __BIT(15)), /* sdm_enable */
260 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL7, __BITS(24,16)), /* n2 */
261 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL, __BIT(25)), /* ssen */
262 1.3.4.2 christos 0),
263 1.3.4.2 christos MESON_CLK_MPLL(MESON8B_CLOCK_MPLL1_DIV, "mpll1_div", "mpll_prediv",
264 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BITS(13,0)), /* sdm */
265 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BIT(15)), /* sdm_enable */
266 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BITS(24,16)), /* n2 */
267 1.3.4.2 christos MESON_CLK_PLL_REG_INVALID, /* ssen */
268 1.3.4.2 christos 0),
269 1.3.4.2 christos MESON_CLK_MPLL(MESON8B_CLOCK_MPLL2_DIV, "mpll2_div", "mpll_prediv",
270 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BITS(13,0)), /* sdm */
271 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BIT(15)), /* sdm_enable */
272 1.3.4.2 christos MESON_CLK_PLL_REG(HHI_MPLL_CNTL8, __BITS(24,16)), /* n2 */
273 1.3.4.2 christos MESON_CLK_PLL_REG_INVALID, /* ssen */
274 1.3.4.2 christos 0),
275 1.3.4.2 christos
276 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_MPLL0, "mpll0", "mpll0_div", HHI_MPLL_CNTL7, 14),
277 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_MPLL1, "mpll1", "mpll1_div", HHI_MPLL_CNTL8, 14),
278 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_MPLL2, "mpll2", "mpll2_div", HHI_MPLL_CNTL9, 14),
279 1.3.4.2 christos
280 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV2_DIV, "fclk_div2_div", "pll_fixed", 2, 1),
281 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV3_DIV, "fclk_div3_div", "pll_fixed", 3, 1),
282 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV4_DIV, "fclk_div4_div", "pll_fixed", 4, 1),
283 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV5_DIV, "fclk_div5_div", "pll_fixed", 5, 1),
284 1.3.4.2 christos MESON_CLK_FIXED_FACTOR(MESON8B_CLOCK_FCLK_DIV7_DIV, "fclk_div7_div", "pll_fixed", 7, 1),
285 1.3.4.2 christos
286 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV2, "fclk_div2", "fclk_div2_div", HHI_MPLL_CNTL6, 27),
287 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV3, "fclk_div3", "fclk_div3_div", HHI_MPLL_CNTL6, 28),
288 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV4, "fclk_div4", "fclk_div4_div", HHI_MPLL_CNTL6, 29),
289 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV5, "fclk_div5", "fclk_div5_div", HHI_MPLL_CNTL6, 30),
290 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_FCLK_DIV7, "fclk_div7", "fclk_div7_div", HHI_MPLL_CNTL6, 31),
291 1.3.4.2 christos
292 1.3.4.2 christos MESON_CLK_MUX(MESON8B_CLOCK_MPEG_SEL, "mpeg_sel", mpeg_sel_parents,
293 1.3.4.2 christos HHI_MPEG_CLK_CNTL, /* reg */
294 1.3.4.2 christos __BITS(14,12), /* sel */
295 1.3.4.2 christos 0),
296 1.3.4.2 christos
297 1.3.4.2 christos MESON_CLK_DIV(MESON8B_CLOCK_MPEG_DIV, "mpeg_div", "mpeg_sel",
298 1.3.4.2 christos HHI_MPEG_CLK_CNTL, /* reg */
299 1.3.4.2 christos __BITS(6,0), /* div */
300 1.3.4.2 christos 0),
301 1.3.4.2 christos
302 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_CLK81, "clk81", "mpeg_div", HHI_MPEG_CLK_CNTL, 7),
303 1.3.4.2 christos
304 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_I2C, "i2c", "clk81", HHI_GCLK_MPEG0, 9),
305 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_SAR_ADC, "sar_adc", "clk81", HHI_GCLK_MPEG0, 10),
306 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_RNG0, "rng0", "clk81", HHI_GCLK_MPEG0, 12),
307 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_UART0, "uart0", "clk81", HHI_GCLK_MPEG0, 13),
308 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_SDHC, "sdhc", "clk81", HHI_GCLK_MPEG0, 14),
309 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_SDIO, "sdio", "clk81", HHI_GCLK_MPEG0, 17),
310 1.3.4.2 christos
311 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_ETH, "eth", "clk81", HHI_GCLK_MPEG1, 3),
312 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_UART1, "uart1", "clk81", HHI_GCLK_MPEG1, 16),
313 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_USB0, "usb0", "clk81", HHI_GCLK_MPEG1, 21),
314 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_USB1, "usb1", "clk81", HHI_GCLK_MPEG1, 22),
315 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_USB, "usb", "clk81", HHI_GCLK_MPEG1, 26),
316 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_EFUSE, "efuse", "clk81", HHI_GCLK_MPEG1, 30),
317 1.3.4.2 christos
318 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_USB1_DDR_BRIDGE, "usb1_ddr_bridge", "clk81", HHI_GCLK_MPEG2, 8),
319 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_USB0_DDR_BRIDGE, "usb0_ddr_bridge", "clk81", HHI_GCLK_MPEG2, 9),
320 1.3.4.2 christos MESON_CLK_GATE(MESON8B_CLOCK_UART2, "uart2", "clk81", HHI_GCLK_MPEG2, 15),
321 1.3.4.2 christos };
322 1.3.4.2 christos
323 1.3.4.2 christos static int
324 1.3.4.2 christos meson8b_clkc_match(device_t parent, cfdata_t cf, void *aux)
325 1.3.4.2 christos {
326 1.3.4.2 christos struct fdt_attach_args * const faa = aux;
327 1.3.4.2 christos
328 1.3.4.2 christos return of_match_compatible(faa->faa_phandle, compatible);
329 1.3.4.2 christos }
330 1.3.4.2 christos
331 1.3.4.2 christos static void
332 1.3.4.2 christos meson8b_clkc_attach(device_t parent, device_t self, void *aux)
333 1.3.4.2 christos {
334 1.3.4.2 christos struct meson_clk_softc * const sc = device_private(self);
335 1.3.4.2 christos struct fdt_attach_args * const faa = aux;
336 1.3.4.2 christos bus_addr_t addr;
337 1.3.4.2 christos bus_size_t size;
338 1.3.4.2 christos
339 1.3.4.2 christos sc->sc_dev = self;
340 1.3.4.2 christos sc->sc_phandle = faa->faa_phandle;
341 1.3.4.2 christos sc->sc_bst = faa->faa_bst;
342 1.3.4.2 christos if (fdtbus_get_reg(sc->sc_phandle, MESON8B_CLKC_REG_INDEX, &addr, &size) != 0) {
343 1.3.4.2 christos aprint_error(": couldn't get registers\n");
344 1.3.4.2 christos return;
345 1.3.4.2 christos }
346 1.3.4.2 christos if (bus_space_map(sc->sc_bst, addr, size, 0, &sc->sc_bsh) != 0) {
347 1.3.4.2 christos aprint_error(": couldn't map registers\n");
348 1.3.4.2 christos return;
349 1.3.4.2 christos }
350 1.3.4.2 christos
351 1.3.4.2 christos sc->sc_resets = meson8b_clkc_resets;
352 1.3.4.2 christos sc->sc_nresets = __arraycount(meson8b_clkc_resets);
353 1.3.4.2 christos
354 1.3.4.2 christos sc->sc_clks = meson8b_clkc_clks;
355 1.3.4.2 christos sc->sc_nclks = __arraycount(meson8b_clkc_clks);
356 1.3.4.2 christos
357 1.3.4.2 christos meson_clk_attach(sc);
358 1.3.4.2 christos
359 1.3.4.2 christos aprint_naive("\n");
360 1.3.4.2 christos aprint_normal(": Meson8b clock controller\n");
361 1.3.4.2 christos
362 1.3.4.2 christos meson_clk_print(sc);
363 1.3.4.2 christos }
364