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