rk3399_pmucru.c revision 1.2 1 1.2 jmcneill /* $NetBSD: rk3399_pmucru.c,v 1.2 2018/08/12 19:28:41 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2018 Jared McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jmcneill * SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill #include <sys/cdefs.h>
30 1.1 jmcneill
31 1.2 jmcneill __KERNEL_RCSID(1, "$NetBSD: rk3399_pmucru.c,v 1.2 2018/08/12 19:28:41 jmcneill Exp $");
32 1.1 jmcneill
33 1.1 jmcneill #include <sys/param.h>
34 1.1 jmcneill #include <sys/bus.h>
35 1.1 jmcneill #include <sys/device.h>
36 1.1 jmcneill #include <sys/systm.h>
37 1.1 jmcneill
38 1.1 jmcneill #include <dev/fdt/fdtvar.h>
39 1.1 jmcneill
40 1.1 jmcneill #include <arm/rockchip/rk_cru.h>
41 1.1 jmcneill #include <arm/rockchip/rk3399_pmucru.h>
42 1.1 jmcneill
43 1.1 jmcneill #define PLL_CON(n) (0x0000 + (n) * 4)
44 1.1 jmcneill #define CLKSEL_CON(n) (0x0080 + (n) * 4)
45 1.1 jmcneill #define CLKGATE_CON(n) (0x0100 + (n) * 4)
46 1.1 jmcneill #define SOFTRST_CON(n) (0x0110 + (n) * 4)
47 1.1 jmcneill
48 1.1 jmcneill static int rk3399_pmucru_match(device_t, cfdata_t, void *);
49 1.1 jmcneill static void rk3399_pmucru_attach(device_t, device_t, void *);
50 1.1 jmcneill
51 1.1 jmcneill static const char * const compatible[] = {
52 1.1 jmcneill "rockchip,rk3399-pmucru",
53 1.1 jmcneill NULL
54 1.1 jmcneill };
55 1.1 jmcneill
56 1.1 jmcneill CFATTACH_DECL_NEW(rk3399_pmucru, sizeof(struct rk_cru_softc),
57 1.1 jmcneill rk3399_pmucru_match, rk3399_pmucru_attach, NULL, NULL);
58 1.1 jmcneill
59 1.1 jmcneill static const struct rk_cru_pll_rate pll_rates[] = {
60 1.1 jmcneill RK_PLL_RATE(2208000000, 1, 92, 1, 1, 1, 0),
61 1.1 jmcneill RK_PLL_RATE(2184000000, 1, 91, 1, 1, 1, 0),
62 1.1 jmcneill RK_PLL_RATE(2160000000, 1, 90, 1, 1, 1, 0),
63 1.1 jmcneill RK_PLL_RATE(2136000000, 1, 89, 1, 1, 1, 0),
64 1.1 jmcneill RK_PLL_RATE(2112000000, 1, 88, 1, 1, 1, 0),
65 1.1 jmcneill RK_PLL_RATE(2088000000, 1, 87, 1, 1, 1, 0),
66 1.1 jmcneill RK_PLL_RATE(2064000000, 1, 86, 1, 1, 1, 0),
67 1.1 jmcneill RK_PLL_RATE(2040000000, 1, 85, 1, 1, 1, 0),
68 1.1 jmcneill RK_PLL_RATE(2016000000, 1, 84, 1, 1, 1, 0),
69 1.1 jmcneill RK_PLL_RATE(1992000000, 1, 83, 1, 1, 1, 0),
70 1.1 jmcneill RK_PLL_RATE(1968000000, 1, 82, 1, 1, 1, 0),
71 1.1 jmcneill RK_PLL_RATE(1944000000, 1, 81, 1, 1, 1, 0),
72 1.1 jmcneill RK_PLL_RATE(1920000000, 1, 80, 1, 1, 1, 0),
73 1.1 jmcneill RK_PLL_RATE(1896000000, 1, 79, 1, 1, 1, 0),
74 1.1 jmcneill RK_PLL_RATE(1872000000, 1, 78, 1, 1, 1, 0),
75 1.1 jmcneill RK_PLL_RATE(1848000000, 1, 77, 1, 1, 1, 0),
76 1.1 jmcneill RK_PLL_RATE(1824000000, 1, 76, 1, 1, 1, 0),
77 1.1 jmcneill RK_PLL_RATE(1800000000, 1, 75, 1, 1, 1, 0),
78 1.1 jmcneill RK_PLL_RATE(1776000000, 1, 74, 1, 1, 1, 0),
79 1.1 jmcneill RK_PLL_RATE(1752000000, 1, 73, 1, 1, 1, 0),
80 1.1 jmcneill RK_PLL_RATE(1728000000, 1, 72, 1, 1, 1, 0),
81 1.1 jmcneill RK_PLL_RATE(1704000000, 1, 71, 1, 1, 1, 0),
82 1.1 jmcneill RK_PLL_RATE(1680000000, 1, 70, 1, 1, 1, 0),
83 1.1 jmcneill RK_PLL_RATE(1656000000, 1, 69, 1, 1, 1, 0),
84 1.1 jmcneill RK_PLL_RATE(1632000000, 1, 68, 1, 1, 1, 0),
85 1.1 jmcneill RK_PLL_RATE(1608000000, 1, 67, 1, 1, 1, 0),
86 1.1 jmcneill RK_PLL_RATE(1600000000, 3, 200, 1, 1, 1, 0),
87 1.1 jmcneill RK_PLL_RATE(1584000000, 1, 66, 1, 1, 1, 0),
88 1.1 jmcneill RK_PLL_RATE(1560000000, 1, 65, 1, 1, 1, 0),
89 1.1 jmcneill RK_PLL_RATE(1536000000, 1, 64, 1, 1, 1, 0),
90 1.1 jmcneill RK_PLL_RATE(1512000000, 1, 63, 1, 1, 1, 0),
91 1.1 jmcneill RK_PLL_RATE(1488000000, 1, 62, 1, 1, 1, 0),
92 1.1 jmcneill RK_PLL_RATE(1464000000, 1, 61, 1, 1, 1, 0),
93 1.1 jmcneill RK_PLL_RATE(1440000000, 1, 60, 1, 1, 1, 0),
94 1.1 jmcneill RK_PLL_RATE(1416000000, 1, 59, 1, 1, 1, 0),
95 1.1 jmcneill RK_PLL_RATE(1392000000, 1, 58, 1, 1, 1, 0),
96 1.1 jmcneill RK_PLL_RATE(1368000000, 1, 57, 1, 1, 1, 0),
97 1.1 jmcneill RK_PLL_RATE(1344000000, 1, 56, 1, 1, 1, 0),
98 1.1 jmcneill RK_PLL_RATE(1320000000, 1, 55, 1, 1, 1, 0),
99 1.1 jmcneill RK_PLL_RATE(1296000000, 1, 54, 1, 1, 1, 0),
100 1.1 jmcneill RK_PLL_RATE(1272000000, 1, 53, 1, 1, 1, 0),
101 1.1 jmcneill RK_PLL_RATE(1248000000, 1, 52, 1, 1, 1, 0),
102 1.1 jmcneill RK_PLL_RATE(1200000000, 1, 50, 1, 1, 1, 0),
103 1.1 jmcneill RK_PLL_RATE(1188000000, 2, 99, 1, 1, 1, 0),
104 1.1 jmcneill RK_PLL_RATE(1104000000, 1, 46, 1, 1, 1, 0),
105 1.1 jmcneill RK_PLL_RATE(1100000000, 12, 550, 1, 1, 1, 0),
106 1.1 jmcneill RK_PLL_RATE(1008000000, 1, 84, 2, 1, 1, 0),
107 1.1 jmcneill RK_PLL_RATE(1000000000, 1, 125, 3, 1, 1, 0),
108 1.1 jmcneill RK_PLL_RATE( 984000000, 1, 82, 2, 1, 1, 0),
109 1.1 jmcneill RK_PLL_RATE( 960000000, 1, 80, 2, 1, 1, 0),
110 1.1 jmcneill RK_PLL_RATE( 936000000, 1, 78, 2, 1, 1, 0),
111 1.1 jmcneill RK_PLL_RATE( 912000000, 1, 76, 2, 1, 1, 0),
112 1.1 jmcneill RK_PLL_RATE( 900000000, 4, 300, 2, 1, 1, 0),
113 1.1 jmcneill RK_PLL_RATE( 888000000, 1, 74, 2, 1, 1, 0),
114 1.1 jmcneill RK_PLL_RATE( 864000000, 1, 72, 2, 1, 1, 0),
115 1.1 jmcneill RK_PLL_RATE( 840000000, 1, 70, 2, 1, 1, 0),
116 1.1 jmcneill RK_PLL_RATE( 816000000, 1, 68, 2, 1, 1, 0),
117 1.1 jmcneill RK_PLL_RATE( 800000000, 1, 100, 3, 1, 1, 0),
118 1.1 jmcneill RK_PLL_RATE( 700000000, 6, 350, 2, 1, 1, 0),
119 1.1 jmcneill RK_PLL_RATE( 696000000, 1, 58, 2, 1, 1, 0),
120 1.1 jmcneill RK_PLL_RATE( 676000000, 3, 169, 2, 1, 1, 0),
121 1.1 jmcneill RK_PLL_RATE( 600000000, 1, 75, 3, 1, 1, 0),
122 1.1 jmcneill RK_PLL_RATE( 594000000, 1, 99, 4, 1, 1, 0),
123 1.1 jmcneill RK_PLL_RATE( 533250000, 8, 711, 4, 1, 1, 0),
124 1.1 jmcneill RK_PLL_RATE( 504000000, 1, 63, 3, 1, 1, 0),
125 1.1 jmcneill RK_PLL_RATE( 500000000, 6, 250, 2, 1, 1, 0),
126 1.1 jmcneill RK_PLL_RATE( 408000000, 1, 68, 2, 2, 1, 0),
127 1.1 jmcneill RK_PLL_RATE( 312000000, 1, 52, 2, 2, 1, 0),
128 1.1 jmcneill RK_PLL_RATE( 297000000, 1, 99, 4, 2, 1, 0),
129 1.1 jmcneill RK_PLL_RATE( 216000000, 1, 72, 4, 2, 1, 0),
130 1.1 jmcneill RK_PLL_RATE( 148500000, 1, 99, 4, 4, 1, 0),
131 1.1 jmcneill RK_PLL_RATE( 106500000, 1, 71, 4, 4, 1, 0),
132 1.1 jmcneill RK_PLL_RATE( 96000000, 1, 64, 4, 4, 1, 0),
133 1.1 jmcneill RK_PLL_RATE( 74250000, 2, 99, 4, 4, 1, 0),
134 1.1 jmcneill RK_PLL_RATE( 65000000, 1, 65, 6, 4, 1, 0),
135 1.1 jmcneill RK_PLL_RATE( 54000000, 1, 54, 6, 4, 1, 0),
136 1.1 jmcneill RK_PLL_RATE( 27000000, 1, 27, 6, 4, 1, 0),
137 1.1 jmcneill };
138 1.1 jmcneill
139 1.1 jmcneill #define PLL_CON0 0x00
140 1.1 jmcneill #define PLL_FBDIV __BITS(11,0)
141 1.1 jmcneill
142 1.1 jmcneill #define PLL_CON1 0x04
143 1.1 jmcneill #define PLL_POSTDIV2 __BITS(14,12)
144 1.1 jmcneill #define PLL_POSTDIV1 __BITS(10,8)
145 1.1 jmcneill #define PLL_REFDIV __BITS(5,0)
146 1.1 jmcneill
147 1.1 jmcneill #define PLL_CON2 0x08
148 1.1 jmcneill #define PLL_LOCK __BIT(31)
149 1.1 jmcneill #define PLL_FRACDIV __BITS(23,0)
150 1.1 jmcneill
151 1.1 jmcneill #define PLL_CON3 0x0c
152 1.1 jmcneill #define PLL_WORK_MODE __BITS(9,8)
153 1.1 jmcneill #define PLL_WORK_MODE_SLOW 0
154 1.1 jmcneill #define PLL_WORK_MODE_NORMAL 1
155 1.1 jmcneill #define PLL_WORK_MODE_DEEP_SLOW 2
156 1.1 jmcneill #define PLL_DSMPD __BIT(3)
157 1.1 jmcneill
158 1.1 jmcneill #define PLL_WRITE_MASK 0xffff0000
159 1.1 jmcneill
160 1.1 jmcneill static u_int
161 1.1 jmcneill rk3399_pmucru_pll_get_rate(struct rk_cru_softc *sc,
162 1.1 jmcneill struct rk_cru_clk *clk)
163 1.1 jmcneill {
164 1.1 jmcneill struct rk_cru_pll *pll = &clk->u.pll;
165 1.1 jmcneill struct clk *clkp, *clkp_parent;
166 1.1 jmcneill u_int foutvco, foutpostdiv;
167 1.1 jmcneill
168 1.1 jmcneill KASSERT(clk->type == RK_CRU_PLL);
169 1.1 jmcneill
170 1.1 jmcneill clkp = &clk->base;
171 1.1 jmcneill clkp_parent = clk_get_parent(clkp);
172 1.1 jmcneill if (clkp_parent == NULL)
173 1.1 jmcneill return 0;
174 1.1 jmcneill
175 1.1 jmcneill const u_int fref = clk_get_rate(clkp_parent);
176 1.1 jmcneill if (fref == 0)
177 1.1 jmcneill return 0;
178 1.1 jmcneill
179 1.1 jmcneill const uint32_t con0 = CRU_READ(sc, pll->con_base + PLL_CON0);
180 1.1 jmcneill const uint32_t con1 = CRU_READ(sc, pll->con_base + PLL_CON1);
181 1.1 jmcneill const uint32_t con2 = CRU_READ(sc, pll->con_base + PLL_CON2);
182 1.1 jmcneill const uint32_t con3 = CRU_READ(sc, pll->con_base + PLL_CON3);
183 1.1 jmcneill
184 1.1 jmcneill const u_int fbdiv = __SHIFTOUT(con0, PLL_FBDIV);
185 1.1 jmcneill const u_int postdiv2 = __SHIFTOUT(con1, PLL_POSTDIV2);
186 1.1 jmcneill const u_int postdiv1 = __SHIFTOUT(con1, PLL_POSTDIV1);
187 1.1 jmcneill const u_int refdiv = __SHIFTOUT(con1, PLL_REFDIV);
188 1.1 jmcneill const u_int fracdiv = __SHIFTOUT(con2, PLL_FRACDIV);
189 1.1 jmcneill const u_int dsmpd = __SHIFTOUT(con3, PLL_DSMPD);
190 1.1 jmcneill
191 1.1 jmcneill if (dsmpd == 1) {
192 1.1 jmcneill /* integer mode */
193 1.1 jmcneill foutvco = fref / refdiv * fbdiv;
194 1.1 jmcneill } else {
195 1.1 jmcneill /* fractional mode */
196 1.1 jmcneill foutvco = fref / refdiv * fbdiv + ((fref * fracdiv) >> 24);
197 1.1 jmcneill }
198 1.1 jmcneill foutpostdiv = foutvco / postdiv1 / postdiv2;
199 1.1 jmcneill
200 1.1 jmcneill return foutpostdiv;
201 1.1 jmcneill }
202 1.1 jmcneill
203 1.1 jmcneill static int
204 1.1 jmcneill rk3399_pmucru_pll_set_rate(struct rk_cru_softc *sc,
205 1.1 jmcneill struct rk_cru_clk *clk, u_int rate)
206 1.1 jmcneill {
207 1.1 jmcneill struct rk_cru_pll *pll = &clk->u.pll;
208 1.1 jmcneill const struct rk_cru_pll_rate *pll_rate = NULL;
209 1.1 jmcneill uint32_t val;
210 1.1 jmcneill int retry;
211 1.1 jmcneill
212 1.1 jmcneill KASSERT(clk->type == RK_CRU_PLL);
213 1.1 jmcneill
214 1.1 jmcneill if (pll->rates == NULL || rate == 0)
215 1.1 jmcneill return EIO;
216 1.1 jmcneill
217 1.1 jmcneill for (int i = 0; i < pll->nrates; i++)
218 1.1 jmcneill if (pll->rates[i].rate == rate) {
219 1.1 jmcneill pll_rate = &pll->rates[i];
220 1.1 jmcneill break;
221 1.1 jmcneill }
222 1.1 jmcneill if (pll_rate == NULL)
223 1.1 jmcneill return EINVAL;
224 1.1 jmcneill
225 1.1 jmcneill val = __SHIFTIN(PLL_WORK_MODE_SLOW, PLL_WORK_MODE) | (PLL_WORK_MODE << 16);
226 1.1 jmcneill CRU_WRITE(sc, pll->con_base + PLL_CON3, val);
227 1.1 jmcneill
228 1.1 jmcneill CRU_WRITE(sc, pll->con_base + PLL_CON0,
229 1.1 jmcneill __SHIFTIN(pll_rate->fbdiv, PLL_FBDIV) |
230 1.1 jmcneill PLL_WRITE_MASK);
231 1.1 jmcneill
232 1.1 jmcneill CRU_WRITE(sc, pll->con_base + PLL_CON1,
233 1.1 jmcneill __SHIFTIN(pll_rate->postdiv2, PLL_POSTDIV2) |
234 1.1 jmcneill __SHIFTIN(pll_rate->postdiv1, PLL_POSTDIV1) |
235 1.1 jmcneill __SHIFTIN(pll_rate->refdiv, PLL_REFDIV) |
236 1.1 jmcneill PLL_WRITE_MASK);
237 1.1 jmcneill
238 1.1 jmcneill val = CRU_READ(sc, pll->con_base + PLL_CON2);
239 1.1 jmcneill val &= ~PLL_FRACDIV;
240 1.1 jmcneill val |= __SHIFTIN(pll_rate->fracdiv, PLL_FRACDIV);
241 1.1 jmcneill CRU_WRITE(sc, pll->con_base + PLL_CON2, val);
242 1.1 jmcneill
243 1.1 jmcneill val = __SHIFTIN(pll_rate->dsmpd, PLL_DSMPD) | (PLL_DSMPD << 16);
244 1.1 jmcneill CRU_WRITE(sc, pll->con_base + PLL_CON3, val);
245 1.1 jmcneill
246 1.1 jmcneill /* Set PLL work mode to normal */
247 1.1 jmcneill const uint32_t write_mask = pll->mode_mask << 16;
248 1.1 jmcneill const uint32_t write_val = pll->mode_mask;
249 1.1 jmcneill CRU_WRITE(sc, pll->mode_reg, write_mask | write_val);
250 1.1 jmcneill
251 1.1 jmcneill for (retry = 1000; retry > 0; retry--) {
252 1.1 jmcneill if (CRU_READ(sc, pll->con_base + PLL_CON2) & pll->lock_mask)
253 1.1 jmcneill break;
254 1.1 jmcneill delay(1);
255 1.1 jmcneill }
256 1.1 jmcneill
257 1.1 jmcneill if (retry == 0)
258 1.1 jmcneill device_printf(sc->sc_dev, "WARNING: %s failed to lock\n",
259 1.1 jmcneill clk->base.name);
260 1.1 jmcneill
261 1.1 jmcneill val = __SHIFTIN(PLL_WORK_MODE_NORMAL, PLL_WORK_MODE) | (PLL_WORK_MODE << 16);
262 1.1 jmcneill CRU_WRITE(sc, pll->con_base + PLL_CON3, val);
263 1.1 jmcneill
264 1.1 jmcneill return 0;
265 1.1 jmcneill }
266 1.1 jmcneill
267 1.1 jmcneill #define RK3399_PLL(_id, _name, _parents, _con_base, _mode_reg, _mode_mask, _lock_mask, _rates) \
268 1.1 jmcneill { \
269 1.1 jmcneill .id = (_id), \
270 1.1 jmcneill .type = RK_CRU_PLL, \
271 1.1 jmcneill .base.name = (_name), \
272 1.1 jmcneill .base.flags = 0, \
273 1.1 jmcneill .u.pll.parents = (_parents), \
274 1.1 jmcneill .u.pll.nparents = __arraycount(_parents), \
275 1.1 jmcneill .u.pll.con_base = (_con_base), \
276 1.1 jmcneill .u.pll.mode_reg = (_mode_reg), \
277 1.1 jmcneill .u.pll.mode_mask = (_mode_mask), \
278 1.1 jmcneill .u.pll.lock_mask = (_lock_mask), \
279 1.1 jmcneill .u.pll.rates = (_rates), \
280 1.1 jmcneill .u.pll.nrates = __arraycount(_rates), \
281 1.1 jmcneill .get_rate = rk3399_pmucru_pll_get_rate, \
282 1.1 jmcneill .set_rate = rk3399_pmucru_pll_set_rate, \
283 1.1 jmcneill .get_parent = rk_cru_pll_get_parent, \
284 1.1 jmcneill }
285 1.1 jmcneill
286 1.1 jmcneill static const char * pll_parents[] = { "xin24m", "xin32k" };
287 1.1 jmcneill
288 1.1 jmcneill static struct rk_cru_clk rk3399_pmucru_clks[] = {
289 1.1 jmcneill RK3399_PLL(RK3399_PLL_PPLL, "ppll", pll_parents,
290 1.1 jmcneill PLL_CON(0), /* con_base */
291 1.1 jmcneill PLL_CON(3), /* mode_reg */
292 1.1 jmcneill __BIT(8), /* mode_mask */
293 1.1 jmcneill __BIT(31), /* lock_mask */
294 1.1 jmcneill pll_rates),
295 1.1 jmcneill
296 1.2 jmcneill RK_COMPOSITE_NOMUX(RK3399_SCLK_I2C0_PMU, "clk_i2c0_pmu", "ppll",
297 1.2 jmcneill CLKSEL_CON(2), /* div_reg */
298 1.2 jmcneill __BITS(6,0), /* div_mask */
299 1.2 jmcneill CLKGATE_CON(0), /* gate_reg */
300 1.2 jmcneill __BIT(9), /* gate_mask */
301 1.2 jmcneill 0),
302 1.2 jmcneill RK_COMPOSITE_NOMUX(RK3399_SCLK_I2C4_PMU, "clk_i2c4_pmu", "ppll",
303 1.2 jmcneill CLKSEL_CON(3), /* div_reg */
304 1.2 jmcneill __BITS(6,0), /* div_mask */
305 1.2 jmcneill CLKGATE_CON(0), /* gate_reg */
306 1.2 jmcneill __BIT(10), /* gate_mask */
307 1.2 jmcneill 0),
308 1.2 jmcneill RK_COMPOSITE_NOMUX(RK3399_SCLK_I2C8_PMU, "clk_i2c8_pmu", "ppll",
309 1.2 jmcneill CLKSEL_CON(2), /* div_reg */
310 1.2 jmcneill __BITS(14,8), /* div_mask */
311 1.2 jmcneill CLKGATE_CON(0), /* gate_reg */
312 1.2 jmcneill __BIT(11), /* gate_mask */
313 1.2 jmcneill 0),
314 1.2 jmcneill
315 1.1 jmcneill RK_DIV(RK3399_PCLK_SRC_PMU, "pclk_pmu_src", "ppll", CLKSEL_CON(0), __BITS(4,0), 0),
316 1.1 jmcneill
317 1.1 jmcneill RK_GATE(RK3399_PCLK_PMU, "pclk_pmu", "pclk_pmu_src", CLKGATE_CON(1), 0),
318 1.1 jmcneill RK_GATE(RK3399_PCLK_GPIO0_PMU, "pclk_gpio0_pmu", "pclk_pmu_src", CLKGATE_CON(1), 3),
319 1.1 jmcneill RK_GATE(RK3399_PCLK_GPIO1_PMU, "pclk_gpio1_pmu", "pclk_pmu_src", CLKGATE_CON(1), 4),
320 1.2 jmcneill RK_GATE(RK3399_PCLK_I2C0_PMU, "pclk_i2c0_pmu", "pclk_pmu_src", CLKGATE_CON(1), 7),
321 1.2 jmcneill RK_GATE(RK3399_PCLK_I2C4_PMU, "pclk_i2c4_pmu", "pclk_pmu_src", CLKGATE_CON(1), 8),
322 1.2 jmcneill RK_GATE(RK3399_PCLK_I2C8_PMU, "pclk_i2c8_pmu", "pclk_pmu_src", CLKGATE_CON(1), 9),
323 1.1 jmcneill };
324 1.1 jmcneill
325 1.1 jmcneill static int
326 1.1 jmcneill rk3399_pmucru_match(device_t parent, cfdata_t cf, void *aux)
327 1.1 jmcneill {
328 1.1 jmcneill struct fdt_attach_args * const faa = aux;
329 1.1 jmcneill
330 1.1 jmcneill return of_match_compatible(faa->faa_phandle, compatible);
331 1.1 jmcneill }
332 1.1 jmcneill
333 1.1 jmcneill static void
334 1.1 jmcneill rk3399_pmucru_attach(device_t parent, device_t self, void *aux)
335 1.1 jmcneill {
336 1.1 jmcneill struct rk_cru_softc * const sc = device_private(self);
337 1.1 jmcneill struct fdt_attach_args * const faa = aux;
338 1.1 jmcneill
339 1.1 jmcneill sc->sc_dev = self;
340 1.1 jmcneill sc->sc_phandle = faa->faa_phandle;
341 1.1 jmcneill sc->sc_bst = faa->faa_bst;
342 1.1 jmcneill
343 1.1 jmcneill sc->sc_clks = rk3399_pmucru_clks;
344 1.1 jmcneill sc->sc_nclks = __arraycount(rk3399_pmucru_clks);
345 1.1 jmcneill
346 1.1 jmcneill sc->sc_softrst_base = SOFTRST_CON(0);
347 1.1 jmcneill
348 1.1 jmcneill if (rk_cru_attach(sc) != 0)
349 1.1 jmcneill return;
350 1.1 jmcneill
351 1.1 jmcneill aprint_naive("\n");
352 1.1 jmcneill aprint_normal(": RK3399 PMU CRU\n");
353 1.1 jmcneill
354 1.1 jmcneill rk_cru_print(sc);
355 1.1 jmcneill }
356