x86/mm: Add TLB purge to free pmd/pte page interfaces
[linux/fpc-iii.git] / drivers / clk / bcm / clk-bcm2835.c
blob73aab6e984cd727f0c45d8df63940eab84c60805
1 /*
2 * Copyright (C) 2010,2015 Broadcom
3 * Copyright (C) 2012 Stephen Warren
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 /**
18 * DOC: BCM2835 CPRMAN (clock manager for the "audio" domain)
20 * The clock tree on the 2835 has several levels. There's a root
21 * oscillator running at 19.2Mhz. After the oscillator there are 5
22 * PLLs, roughly divided as "camera", "ARM", "core", "DSI displays",
23 * and "HDMI displays". Those 5 PLLs each can divide their output to
24 * produce up to 4 channels. Finally, there is the level of clocks to
25 * be consumed by other hardware components (like "H264" or "HDMI
26 * state machine"), which divide off of some subset of the PLL
27 * channels.
29 * All of the clocks in the tree are exposed in the DT, because the DT
30 * may want to make assignments of the final layer of clocks to the
31 * PLL channels, and some components of the hardware will actually
32 * skip layers of the tree (for example, the pixel clock comes
33 * directly from the PLLH PIX channel without using a CM_*CTL clock
34 * generator).
37 #include <linux/clk-provider.h>
38 #include <linux/clkdev.h>
39 #include <linux/clk.h>
40 #include <linux/clk/bcm2835.h>
41 #include <linux/debugfs.h>
42 #include <linux/module.h>
43 #include <linux/of.h>
44 #include <linux/platform_device.h>
45 #include <linux/slab.h>
46 #include <dt-bindings/clock/bcm2835.h>
48 #define CM_PASSWORD 0x5a000000
50 #define CM_GNRICCTL 0x000
51 #define CM_GNRICDIV 0x004
52 # define CM_DIV_FRAC_BITS 12
53 # define CM_DIV_FRAC_MASK GENMASK(CM_DIV_FRAC_BITS - 1, 0)
55 #define CM_VPUCTL 0x008
56 #define CM_VPUDIV 0x00c
57 #define CM_SYSCTL 0x010
58 #define CM_SYSDIV 0x014
59 #define CM_PERIACTL 0x018
60 #define CM_PERIADIV 0x01c
61 #define CM_PERIICTL 0x020
62 #define CM_PERIIDIV 0x024
63 #define CM_H264CTL 0x028
64 #define CM_H264DIV 0x02c
65 #define CM_ISPCTL 0x030
66 #define CM_ISPDIV 0x034
67 #define CM_V3DCTL 0x038
68 #define CM_V3DDIV 0x03c
69 #define CM_CAM0CTL 0x040
70 #define CM_CAM0DIV 0x044
71 #define CM_CAM1CTL 0x048
72 #define CM_CAM1DIV 0x04c
73 #define CM_CCP2CTL 0x050
74 #define CM_CCP2DIV 0x054
75 #define CM_DSI0ECTL 0x058
76 #define CM_DSI0EDIV 0x05c
77 #define CM_DSI0PCTL 0x060
78 #define CM_DSI0PDIV 0x064
79 #define CM_DPICTL 0x068
80 #define CM_DPIDIV 0x06c
81 #define CM_GP0CTL 0x070
82 #define CM_GP0DIV 0x074
83 #define CM_GP1CTL 0x078
84 #define CM_GP1DIV 0x07c
85 #define CM_GP2CTL 0x080
86 #define CM_GP2DIV 0x084
87 #define CM_HSMCTL 0x088
88 #define CM_HSMDIV 0x08c
89 #define CM_OTPCTL 0x090
90 #define CM_OTPDIV 0x094
91 #define CM_PCMCTL 0x098
92 #define CM_PCMDIV 0x09c
93 #define CM_PWMCTL 0x0a0
94 #define CM_PWMDIV 0x0a4
95 #define CM_SLIMCTL 0x0a8
96 #define CM_SLIMDIV 0x0ac
97 #define CM_SMICTL 0x0b0
98 #define CM_SMIDIV 0x0b4
99 /* no definition for 0x0b8 and 0x0bc */
100 #define CM_TCNTCTL 0x0c0
101 #define CM_TCNTDIV 0x0c4
102 #define CM_TECCTL 0x0c8
103 #define CM_TECDIV 0x0cc
104 #define CM_TD0CTL 0x0d0
105 #define CM_TD0DIV 0x0d4
106 #define CM_TD1CTL 0x0d8
107 #define CM_TD1DIV 0x0dc
108 #define CM_TSENSCTL 0x0e0
109 #define CM_TSENSDIV 0x0e4
110 #define CM_TIMERCTL 0x0e8
111 #define CM_TIMERDIV 0x0ec
112 #define CM_UARTCTL 0x0f0
113 #define CM_UARTDIV 0x0f4
114 #define CM_VECCTL 0x0f8
115 #define CM_VECDIV 0x0fc
116 #define CM_PULSECTL 0x190
117 #define CM_PULSEDIV 0x194
118 #define CM_SDCCTL 0x1a8
119 #define CM_SDCDIV 0x1ac
120 #define CM_ARMCTL 0x1b0
121 #define CM_AVEOCTL 0x1b8
122 #define CM_AVEODIV 0x1bc
123 #define CM_EMMCCTL 0x1c0
124 #define CM_EMMCDIV 0x1c4
126 /* General bits for the CM_*CTL regs */
127 # define CM_ENABLE BIT(4)
128 # define CM_KILL BIT(5)
129 # define CM_GATE_BIT 6
130 # define CM_GATE BIT(CM_GATE_BIT)
131 # define CM_BUSY BIT(7)
132 # define CM_BUSYD BIT(8)
133 # define CM_FRAC BIT(9)
134 # define CM_SRC_SHIFT 0
135 # define CM_SRC_BITS 4
136 # define CM_SRC_MASK 0xf
137 # define CM_SRC_GND 0
138 # define CM_SRC_OSC 1
139 # define CM_SRC_TESTDEBUG0 2
140 # define CM_SRC_TESTDEBUG1 3
141 # define CM_SRC_PLLA_CORE 4
142 # define CM_SRC_PLLA_PER 4
143 # define CM_SRC_PLLC_CORE0 5
144 # define CM_SRC_PLLC_PER 5
145 # define CM_SRC_PLLC_CORE1 8
146 # define CM_SRC_PLLD_CORE 6
147 # define CM_SRC_PLLD_PER 6
148 # define CM_SRC_PLLH_AUX 7
149 # define CM_SRC_PLLC_CORE1 8
150 # define CM_SRC_PLLC_CORE2 9
152 #define CM_OSCCOUNT 0x100
154 #define CM_PLLA 0x104
155 # define CM_PLL_ANARST BIT(8)
156 # define CM_PLLA_HOLDPER BIT(7)
157 # define CM_PLLA_LOADPER BIT(6)
158 # define CM_PLLA_HOLDCORE BIT(5)
159 # define CM_PLLA_LOADCORE BIT(4)
160 # define CM_PLLA_HOLDCCP2 BIT(3)
161 # define CM_PLLA_LOADCCP2 BIT(2)
162 # define CM_PLLA_HOLDDSI0 BIT(1)
163 # define CM_PLLA_LOADDSI0 BIT(0)
165 #define CM_PLLC 0x108
166 # define CM_PLLC_HOLDPER BIT(7)
167 # define CM_PLLC_LOADPER BIT(6)
168 # define CM_PLLC_HOLDCORE2 BIT(5)
169 # define CM_PLLC_LOADCORE2 BIT(4)
170 # define CM_PLLC_HOLDCORE1 BIT(3)
171 # define CM_PLLC_LOADCORE1 BIT(2)
172 # define CM_PLLC_HOLDCORE0 BIT(1)
173 # define CM_PLLC_LOADCORE0 BIT(0)
175 #define CM_PLLD 0x10c
176 # define CM_PLLD_HOLDPER BIT(7)
177 # define CM_PLLD_LOADPER BIT(6)
178 # define CM_PLLD_HOLDCORE BIT(5)
179 # define CM_PLLD_LOADCORE BIT(4)
180 # define CM_PLLD_HOLDDSI1 BIT(3)
181 # define CM_PLLD_LOADDSI1 BIT(2)
182 # define CM_PLLD_HOLDDSI0 BIT(1)
183 # define CM_PLLD_LOADDSI0 BIT(0)
185 #define CM_PLLH 0x110
186 # define CM_PLLH_LOADRCAL BIT(2)
187 # define CM_PLLH_LOADAUX BIT(1)
188 # define CM_PLLH_LOADPIX BIT(0)
190 #define CM_LOCK 0x114
191 # define CM_LOCK_FLOCKH BIT(12)
192 # define CM_LOCK_FLOCKD BIT(11)
193 # define CM_LOCK_FLOCKC BIT(10)
194 # define CM_LOCK_FLOCKB BIT(9)
195 # define CM_LOCK_FLOCKA BIT(8)
197 #define CM_EVENT 0x118
198 #define CM_DSI1ECTL 0x158
199 #define CM_DSI1EDIV 0x15c
200 #define CM_DSI1PCTL 0x160
201 #define CM_DSI1PDIV 0x164
202 #define CM_DFTCTL 0x168
203 #define CM_DFTDIV 0x16c
205 #define CM_PLLB 0x170
206 # define CM_PLLB_HOLDARM BIT(1)
207 # define CM_PLLB_LOADARM BIT(0)
209 #define A2W_PLLA_CTRL 0x1100
210 #define A2W_PLLC_CTRL 0x1120
211 #define A2W_PLLD_CTRL 0x1140
212 #define A2W_PLLH_CTRL 0x1160
213 #define A2W_PLLB_CTRL 0x11e0
214 # define A2W_PLL_CTRL_PRST_DISABLE BIT(17)
215 # define A2W_PLL_CTRL_PWRDN BIT(16)
216 # define A2W_PLL_CTRL_PDIV_MASK 0x000007000
217 # define A2W_PLL_CTRL_PDIV_SHIFT 12
218 # define A2W_PLL_CTRL_NDIV_MASK 0x0000003ff
219 # define A2W_PLL_CTRL_NDIV_SHIFT 0
221 #define A2W_PLLA_ANA0 0x1010
222 #define A2W_PLLC_ANA0 0x1030
223 #define A2W_PLLD_ANA0 0x1050
224 #define A2W_PLLH_ANA0 0x1070
225 #define A2W_PLLB_ANA0 0x10f0
227 #define A2W_PLL_KA_SHIFT 7
228 #define A2W_PLL_KA_MASK GENMASK(9, 7)
229 #define A2W_PLL_KI_SHIFT 19
230 #define A2W_PLL_KI_MASK GENMASK(21, 19)
231 #define A2W_PLL_KP_SHIFT 15
232 #define A2W_PLL_KP_MASK GENMASK(18, 15)
234 #define A2W_PLLH_KA_SHIFT 19
235 #define A2W_PLLH_KA_MASK GENMASK(21, 19)
236 #define A2W_PLLH_KI_LOW_SHIFT 22
237 #define A2W_PLLH_KI_LOW_MASK GENMASK(23, 22)
238 #define A2W_PLLH_KI_HIGH_SHIFT 0
239 #define A2W_PLLH_KI_HIGH_MASK GENMASK(0, 0)
240 #define A2W_PLLH_KP_SHIFT 1
241 #define A2W_PLLH_KP_MASK GENMASK(4, 1)
243 #define A2W_XOSC_CTRL 0x1190
244 # define A2W_XOSC_CTRL_PLLB_ENABLE BIT(7)
245 # define A2W_XOSC_CTRL_PLLA_ENABLE BIT(6)
246 # define A2W_XOSC_CTRL_PLLD_ENABLE BIT(5)
247 # define A2W_XOSC_CTRL_DDR_ENABLE BIT(4)
248 # define A2W_XOSC_CTRL_CPR1_ENABLE BIT(3)
249 # define A2W_XOSC_CTRL_USB_ENABLE BIT(2)
250 # define A2W_XOSC_CTRL_HDMI_ENABLE BIT(1)
251 # define A2W_XOSC_CTRL_PLLC_ENABLE BIT(0)
253 #define A2W_PLLA_FRAC 0x1200
254 #define A2W_PLLC_FRAC 0x1220
255 #define A2W_PLLD_FRAC 0x1240
256 #define A2W_PLLH_FRAC 0x1260
257 #define A2W_PLLB_FRAC 0x12e0
258 # define A2W_PLL_FRAC_MASK ((1 << A2W_PLL_FRAC_BITS) - 1)
259 # define A2W_PLL_FRAC_BITS 20
261 #define A2W_PLL_CHANNEL_DISABLE BIT(8)
262 #define A2W_PLL_DIV_BITS 8
263 #define A2W_PLL_DIV_SHIFT 0
265 #define A2W_PLLA_DSI0 0x1300
266 #define A2W_PLLA_CORE 0x1400
267 #define A2W_PLLA_PER 0x1500
268 #define A2W_PLLA_CCP2 0x1600
270 #define A2W_PLLC_CORE2 0x1320
271 #define A2W_PLLC_CORE1 0x1420
272 #define A2W_PLLC_PER 0x1520
273 #define A2W_PLLC_CORE0 0x1620
275 #define A2W_PLLD_DSI0 0x1340
276 #define A2W_PLLD_CORE 0x1440
277 #define A2W_PLLD_PER 0x1540
278 #define A2W_PLLD_DSI1 0x1640
280 #define A2W_PLLH_AUX 0x1360
281 #define A2W_PLLH_RCAL 0x1460
282 #define A2W_PLLH_PIX 0x1560
283 #define A2W_PLLH_STS 0x1660
285 #define A2W_PLLH_CTRLR 0x1960
286 #define A2W_PLLH_FRACR 0x1a60
287 #define A2W_PLLH_AUXR 0x1b60
288 #define A2W_PLLH_RCALR 0x1c60
289 #define A2W_PLLH_PIXR 0x1d60
290 #define A2W_PLLH_STSR 0x1e60
292 #define A2W_PLLB_ARM 0x13e0
293 #define A2W_PLLB_SP0 0x14e0
294 #define A2W_PLLB_SP1 0x15e0
295 #define A2W_PLLB_SP2 0x16e0
297 #define LOCK_TIMEOUT_NS 100000000
298 #define BCM2835_MAX_FB_RATE 1750000000u
300 struct bcm2835_cprman {
301 struct device *dev;
302 void __iomem *regs;
303 spinlock_t regs_lock; /* spinlock for all clocks */
304 const char *osc_name;
306 /* Must be last */
307 struct clk_hw_onecell_data onecell;
310 static inline void cprman_write(struct bcm2835_cprman *cprman, u32 reg, u32 val)
312 writel(CM_PASSWORD | val, cprman->regs + reg);
315 static inline u32 cprman_read(struct bcm2835_cprman *cprman, u32 reg)
317 return readl(cprman->regs + reg);
320 static int bcm2835_debugfs_regset(struct bcm2835_cprman *cprman, u32 base,
321 struct debugfs_reg32 *regs, size_t nregs,
322 struct dentry *dentry)
324 struct dentry *regdump;
325 struct debugfs_regset32 *regset;
327 regset = devm_kzalloc(cprman->dev, sizeof(*regset), GFP_KERNEL);
328 if (!regset)
329 return -ENOMEM;
331 regset->regs = regs;
332 regset->nregs = nregs;
333 regset->base = cprman->regs + base;
335 regdump = debugfs_create_regset32("regdump", S_IRUGO, dentry,
336 regset);
338 return regdump ? 0 : -ENOMEM;
342 * These are fixed clocks. They're probably not all root clocks and it may
343 * be possible to turn them on and off but until this is mapped out better
344 * it's the only way they can be used.
346 void __init bcm2835_init_clocks(void)
348 struct clk_hw *hw;
349 int ret;
351 hw = clk_hw_register_fixed_rate(NULL, "apb_pclk", NULL, 0, 126000000);
352 if (IS_ERR(hw))
353 pr_err("apb_pclk not registered\n");
355 hw = clk_hw_register_fixed_rate(NULL, "uart0_pclk", NULL, 0, 3000000);
356 if (IS_ERR(hw))
357 pr_err("uart0_pclk not registered\n");
358 ret = clk_hw_register_clkdev(hw, NULL, "20201000.uart");
359 if (ret)
360 pr_err("uart0_pclk alias not registered\n");
362 hw = clk_hw_register_fixed_rate(NULL, "uart1_pclk", NULL, 0, 125000000);
363 if (IS_ERR(hw))
364 pr_err("uart1_pclk not registered\n");
365 ret = clk_hw_register_clkdev(hw, NULL, "20215000.uart");
366 if (ret)
367 pr_err("uart1_pclk alias not registered\n");
370 struct bcm2835_pll_data {
371 const char *name;
372 u32 cm_ctrl_reg;
373 u32 a2w_ctrl_reg;
374 u32 frac_reg;
375 u32 ana_reg_base;
376 u32 reference_enable_mask;
377 /* Bit in CM_LOCK to indicate when the PLL has locked. */
378 u32 lock_mask;
380 const struct bcm2835_pll_ana_bits *ana;
382 unsigned long min_rate;
383 unsigned long max_rate;
385 * Highest rate for the VCO before we have to use the
386 * pre-divide-by-2.
388 unsigned long max_fb_rate;
391 struct bcm2835_pll_ana_bits {
392 u32 mask0;
393 u32 set0;
394 u32 mask1;
395 u32 set1;
396 u32 mask3;
397 u32 set3;
398 u32 fb_prediv_mask;
401 static const struct bcm2835_pll_ana_bits bcm2835_ana_default = {
402 .mask0 = 0,
403 .set0 = 0,
404 .mask1 = A2W_PLL_KI_MASK | A2W_PLL_KP_MASK,
405 .set1 = (2 << A2W_PLL_KI_SHIFT) | (8 << A2W_PLL_KP_SHIFT),
406 .mask3 = A2W_PLL_KA_MASK,
407 .set3 = (2 << A2W_PLL_KA_SHIFT),
408 .fb_prediv_mask = BIT(14),
411 static const struct bcm2835_pll_ana_bits bcm2835_ana_pllh = {
412 .mask0 = A2W_PLLH_KA_MASK | A2W_PLLH_KI_LOW_MASK,
413 .set0 = (2 << A2W_PLLH_KA_SHIFT) | (2 << A2W_PLLH_KI_LOW_SHIFT),
414 .mask1 = A2W_PLLH_KI_HIGH_MASK | A2W_PLLH_KP_MASK,
415 .set1 = (6 << A2W_PLLH_KP_SHIFT),
416 .mask3 = 0,
417 .set3 = 0,
418 .fb_prediv_mask = BIT(11),
421 struct bcm2835_pll_divider_data {
422 const char *name;
423 const char *source_pll;
425 u32 cm_reg;
426 u32 a2w_reg;
428 u32 load_mask;
429 u32 hold_mask;
430 u32 fixed_divider;
433 struct bcm2835_clock_data {
434 const char *name;
436 const char *const *parents;
437 int num_mux_parents;
439 u32 ctl_reg;
440 u32 div_reg;
442 /* Number of integer bits in the divider */
443 u32 int_bits;
444 /* Number of fractional bits in the divider */
445 u32 frac_bits;
447 u32 flags;
449 bool is_vpu_clock;
450 bool is_mash_clock;
453 struct bcm2835_gate_data {
454 const char *name;
455 const char *parent;
457 u32 ctl_reg;
460 struct bcm2835_pll {
461 struct clk_hw hw;
462 struct bcm2835_cprman *cprman;
463 const struct bcm2835_pll_data *data;
466 static int bcm2835_pll_is_on(struct clk_hw *hw)
468 struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
469 struct bcm2835_cprman *cprman = pll->cprman;
470 const struct bcm2835_pll_data *data = pll->data;
472 return cprman_read(cprman, data->a2w_ctrl_reg) &
473 A2W_PLL_CTRL_PRST_DISABLE;
476 static void bcm2835_pll_choose_ndiv_and_fdiv(unsigned long rate,
477 unsigned long parent_rate,
478 u32 *ndiv, u32 *fdiv)
480 u64 div;
482 div = (u64)rate << A2W_PLL_FRAC_BITS;
483 do_div(div, parent_rate);
485 *ndiv = div >> A2W_PLL_FRAC_BITS;
486 *fdiv = div & ((1 << A2W_PLL_FRAC_BITS) - 1);
489 static long bcm2835_pll_rate_from_divisors(unsigned long parent_rate,
490 u32 ndiv, u32 fdiv, u32 pdiv)
492 u64 rate;
494 if (pdiv == 0)
495 return 0;
497 rate = (u64)parent_rate * ((ndiv << A2W_PLL_FRAC_BITS) + fdiv);
498 do_div(rate, pdiv);
499 return rate >> A2W_PLL_FRAC_BITS;
502 static long bcm2835_pll_round_rate(struct clk_hw *hw, unsigned long rate,
503 unsigned long *parent_rate)
505 struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
506 const struct bcm2835_pll_data *data = pll->data;
507 u32 ndiv, fdiv;
509 rate = clamp(rate, data->min_rate, data->max_rate);
511 bcm2835_pll_choose_ndiv_and_fdiv(rate, *parent_rate, &ndiv, &fdiv);
513 return bcm2835_pll_rate_from_divisors(*parent_rate, ndiv, fdiv, 1);
516 static unsigned long bcm2835_pll_get_rate(struct clk_hw *hw,
517 unsigned long parent_rate)
519 struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
520 struct bcm2835_cprman *cprman = pll->cprman;
521 const struct bcm2835_pll_data *data = pll->data;
522 u32 a2wctrl = cprman_read(cprman, data->a2w_ctrl_reg);
523 u32 ndiv, pdiv, fdiv;
524 bool using_prediv;
526 if (parent_rate == 0)
527 return 0;
529 fdiv = cprman_read(cprman, data->frac_reg) & A2W_PLL_FRAC_MASK;
530 ndiv = (a2wctrl & A2W_PLL_CTRL_NDIV_MASK) >> A2W_PLL_CTRL_NDIV_SHIFT;
531 pdiv = (a2wctrl & A2W_PLL_CTRL_PDIV_MASK) >> A2W_PLL_CTRL_PDIV_SHIFT;
532 using_prediv = cprman_read(cprman, data->ana_reg_base + 4) &
533 data->ana->fb_prediv_mask;
535 if (using_prediv)
536 ndiv *= 2;
538 return bcm2835_pll_rate_from_divisors(parent_rate, ndiv, fdiv, pdiv);
541 static void bcm2835_pll_off(struct clk_hw *hw)
543 struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
544 struct bcm2835_cprman *cprman = pll->cprman;
545 const struct bcm2835_pll_data *data = pll->data;
547 spin_lock(&cprman->regs_lock);
548 cprman_write(cprman, data->cm_ctrl_reg, CM_PLL_ANARST);
549 cprman_write(cprman, data->a2w_ctrl_reg,
550 cprman_read(cprman, data->a2w_ctrl_reg) |
551 A2W_PLL_CTRL_PWRDN);
552 spin_unlock(&cprman->regs_lock);
555 static int bcm2835_pll_on(struct clk_hw *hw)
557 struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
558 struct bcm2835_cprman *cprman = pll->cprman;
559 const struct bcm2835_pll_data *data = pll->data;
560 ktime_t timeout;
562 cprman_write(cprman, data->a2w_ctrl_reg,
563 cprman_read(cprman, data->a2w_ctrl_reg) &
564 ~A2W_PLL_CTRL_PWRDN);
566 /* Take the PLL out of reset. */
567 spin_lock(&cprman->regs_lock);
568 cprman_write(cprman, data->cm_ctrl_reg,
569 cprman_read(cprman, data->cm_ctrl_reg) & ~CM_PLL_ANARST);
570 spin_unlock(&cprman->regs_lock);
572 /* Wait for the PLL to lock. */
573 timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
574 while (!(cprman_read(cprman, CM_LOCK) & data->lock_mask)) {
575 if (ktime_after(ktime_get(), timeout)) {
576 dev_err(cprman->dev, "%s: couldn't lock PLL\n",
577 clk_hw_get_name(hw));
578 return -ETIMEDOUT;
581 cpu_relax();
584 cprman_write(cprman, data->a2w_ctrl_reg,
585 cprman_read(cprman, data->a2w_ctrl_reg) |
586 A2W_PLL_CTRL_PRST_DISABLE);
588 return 0;
591 static void
592 bcm2835_pll_write_ana(struct bcm2835_cprman *cprman, u32 ana_reg_base, u32 *ana)
594 int i;
597 * ANA register setup is done as a series of writes to
598 * ANA3-ANA0, in that order. This lets us write all 4
599 * registers as a single cycle of the serdes interface (taking
600 * 100 xosc clocks), whereas if we were to update ana0, 1, and
601 * 3 individually through their partial-write registers, each
602 * would be their own serdes cycle.
604 for (i = 3; i >= 0; i--)
605 cprman_write(cprman, ana_reg_base + i * 4, ana[i]);
608 static int bcm2835_pll_set_rate(struct clk_hw *hw,
609 unsigned long rate, unsigned long parent_rate)
611 struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
612 struct bcm2835_cprman *cprman = pll->cprman;
613 const struct bcm2835_pll_data *data = pll->data;
614 bool was_using_prediv, use_fb_prediv, do_ana_setup_first;
615 u32 ndiv, fdiv, a2w_ctl;
616 u32 ana[4];
617 int i;
619 if (rate > data->max_fb_rate) {
620 use_fb_prediv = true;
621 rate /= 2;
622 } else {
623 use_fb_prediv = false;
626 bcm2835_pll_choose_ndiv_and_fdiv(rate, parent_rate, &ndiv, &fdiv);
628 for (i = 3; i >= 0; i--)
629 ana[i] = cprman_read(cprman, data->ana_reg_base + i * 4);
631 was_using_prediv = ana[1] & data->ana->fb_prediv_mask;
633 ana[0] &= ~data->ana->mask0;
634 ana[0] |= data->ana->set0;
635 ana[1] &= ~data->ana->mask1;
636 ana[1] |= data->ana->set1;
637 ana[3] &= ~data->ana->mask3;
638 ana[3] |= data->ana->set3;
640 if (was_using_prediv && !use_fb_prediv) {
641 ana[1] &= ~data->ana->fb_prediv_mask;
642 do_ana_setup_first = true;
643 } else if (!was_using_prediv && use_fb_prediv) {
644 ana[1] |= data->ana->fb_prediv_mask;
645 do_ana_setup_first = false;
646 } else {
647 do_ana_setup_first = true;
650 /* Unmask the reference clock from the oscillator. */
651 spin_lock(&cprman->regs_lock);
652 cprman_write(cprman, A2W_XOSC_CTRL,
653 cprman_read(cprman, A2W_XOSC_CTRL) |
654 data->reference_enable_mask);
655 spin_unlock(&cprman->regs_lock);
657 if (do_ana_setup_first)
658 bcm2835_pll_write_ana(cprman, data->ana_reg_base, ana);
660 /* Set the PLL multiplier from the oscillator. */
661 cprman_write(cprman, data->frac_reg, fdiv);
663 a2w_ctl = cprman_read(cprman, data->a2w_ctrl_reg);
664 a2w_ctl &= ~A2W_PLL_CTRL_NDIV_MASK;
665 a2w_ctl |= ndiv << A2W_PLL_CTRL_NDIV_SHIFT;
666 a2w_ctl &= ~A2W_PLL_CTRL_PDIV_MASK;
667 a2w_ctl |= 1 << A2W_PLL_CTRL_PDIV_SHIFT;
668 cprman_write(cprman, data->a2w_ctrl_reg, a2w_ctl);
670 if (!do_ana_setup_first)
671 bcm2835_pll_write_ana(cprman, data->ana_reg_base, ana);
673 return 0;
676 static int bcm2835_pll_debug_init(struct clk_hw *hw,
677 struct dentry *dentry)
679 struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
680 struct bcm2835_cprman *cprman = pll->cprman;
681 const struct bcm2835_pll_data *data = pll->data;
682 struct debugfs_reg32 *regs;
684 regs = devm_kzalloc(cprman->dev, 7 * sizeof(*regs), GFP_KERNEL);
685 if (!regs)
686 return -ENOMEM;
688 regs[0].name = "cm_ctrl";
689 regs[0].offset = data->cm_ctrl_reg;
690 regs[1].name = "a2w_ctrl";
691 regs[1].offset = data->a2w_ctrl_reg;
692 regs[2].name = "frac";
693 regs[2].offset = data->frac_reg;
694 regs[3].name = "ana0";
695 regs[3].offset = data->ana_reg_base + 0 * 4;
696 regs[4].name = "ana1";
697 regs[4].offset = data->ana_reg_base + 1 * 4;
698 regs[5].name = "ana2";
699 regs[5].offset = data->ana_reg_base + 2 * 4;
700 regs[6].name = "ana3";
701 regs[6].offset = data->ana_reg_base + 3 * 4;
703 return bcm2835_debugfs_regset(cprman, 0, regs, 7, dentry);
706 static const struct clk_ops bcm2835_pll_clk_ops = {
707 .is_prepared = bcm2835_pll_is_on,
708 .prepare = bcm2835_pll_on,
709 .unprepare = bcm2835_pll_off,
710 .recalc_rate = bcm2835_pll_get_rate,
711 .set_rate = bcm2835_pll_set_rate,
712 .round_rate = bcm2835_pll_round_rate,
713 .debug_init = bcm2835_pll_debug_init,
716 struct bcm2835_pll_divider {
717 struct clk_divider div;
718 struct bcm2835_cprman *cprman;
719 const struct bcm2835_pll_divider_data *data;
722 static struct bcm2835_pll_divider *
723 bcm2835_pll_divider_from_hw(struct clk_hw *hw)
725 return container_of(hw, struct bcm2835_pll_divider, div.hw);
728 static int bcm2835_pll_divider_is_on(struct clk_hw *hw)
730 struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
731 struct bcm2835_cprman *cprman = divider->cprman;
732 const struct bcm2835_pll_divider_data *data = divider->data;
734 return !(cprman_read(cprman, data->a2w_reg) & A2W_PLL_CHANNEL_DISABLE);
737 static long bcm2835_pll_divider_round_rate(struct clk_hw *hw,
738 unsigned long rate,
739 unsigned long *parent_rate)
741 return clk_divider_ops.round_rate(hw, rate, parent_rate);
744 static unsigned long bcm2835_pll_divider_get_rate(struct clk_hw *hw,
745 unsigned long parent_rate)
747 return clk_divider_ops.recalc_rate(hw, parent_rate);
750 static void bcm2835_pll_divider_off(struct clk_hw *hw)
752 struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
753 struct bcm2835_cprman *cprman = divider->cprman;
754 const struct bcm2835_pll_divider_data *data = divider->data;
756 spin_lock(&cprman->regs_lock);
757 cprman_write(cprman, data->cm_reg,
758 (cprman_read(cprman, data->cm_reg) &
759 ~data->load_mask) | data->hold_mask);
760 cprman_write(cprman, data->a2w_reg,
761 cprman_read(cprman, data->a2w_reg) |
762 A2W_PLL_CHANNEL_DISABLE);
763 spin_unlock(&cprman->regs_lock);
766 static int bcm2835_pll_divider_on(struct clk_hw *hw)
768 struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
769 struct bcm2835_cprman *cprman = divider->cprman;
770 const struct bcm2835_pll_divider_data *data = divider->data;
772 spin_lock(&cprman->regs_lock);
773 cprman_write(cprman, data->a2w_reg,
774 cprman_read(cprman, data->a2w_reg) &
775 ~A2W_PLL_CHANNEL_DISABLE);
777 cprman_write(cprman, data->cm_reg,
778 cprman_read(cprman, data->cm_reg) & ~data->hold_mask);
779 spin_unlock(&cprman->regs_lock);
781 return 0;
784 static int bcm2835_pll_divider_set_rate(struct clk_hw *hw,
785 unsigned long rate,
786 unsigned long parent_rate)
788 struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
789 struct bcm2835_cprman *cprman = divider->cprman;
790 const struct bcm2835_pll_divider_data *data = divider->data;
791 u32 cm, div, max_div = 1 << A2W_PLL_DIV_BITS;
793 div = DIV_ROUND_UP_ULL(parent_rate, rate);
795 div = min(div, max_div);
796 if (div == max_div)
797 div = 0;
799 cprman_write(cprman, data->a2w_reg, div);
800 cm = cprman_read(cprman, data->cm_reg);
801 cprman_write(cprman, data->cm_reg, cm | data->load_mask);
802 cprman_write(cprman, data->cm_reg, cm & ~data->load_mask);
804 return 0;
807 static int bcm2835_pll_divider_debug_init(struct clk_hw *hw,
808 struct dentry *dentry)
810 struct bcm2835_pll_divider *divider = bcm2835_pll_divider_from_hw(hw);
811 struct bcm2835_cprman *cprman = divider->cprman;
812 const struct bcm2835_pll_divider_data *data = divider->data;
813 struct debugfs_reg32 *regs;
815 regs = devm_kzalloc(cprman->dev, 7 * sizeof(*regs), GFP_KERNEL);
816 if (!regs)
817 return -ENOMEM;
819 regs[0].name = "cm";
820 regs[0].offset = data->cm_reg;
821 regs[1].name = "a2w";
822 regs[1].offset = data->a2w_reg;
824 return bcm2835_debugfs_regset(cprman, 0, regs, 2, dentry);
827 static const struct clk_ops bcm2835_pll_divider_clk_ops = {
828 .is_prepared = bcm2835_pll_divider_is_on,
829 .prepare = bcm2835_pll_divider_on,
830 .unprepare = bcm2835_pll_divider_off,
831 .recalc_rate = bcm2835_pll_divider_get_rate,
832 .set_rate = bcm2835_pll_divider_set_rate,
833 .round_rate = bcm2835_pll_divider_round_rate,
834 .debug_init = bcm2835_pll_divider_debug_init,
838 * The CM dividers do fixed-point division, so we can't use the
839 * generic integer divider code like the PLL dividers do (and we can't
840 * fake it by having some fixed shifts preceding it in the clock tree,
841 * because we'd run out of bits in a 32-bit unsigned long).
843 struct bcm2835_clock {
844 struct clk_hw hw;
845 struct bcm2835_cprman *cprman;
846 const struct bcm2835_clock_data *data;
849 static struct bcm2835_clock *bcm2835_clock_from_hw(struct clk_hw *hw)
851 return container_of(hw, struct bcm2835_clock, hw);
854 static int bcm2835_clock_is_on(struct clk_hw *hw)
856 struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
857 struct bcm2835_cprman *cprman = clock->cprman;
858 const struct bcm2835_clock_data *data = clock->data;
860 return (cprman_read(cprman, data->ctl_reg) & CM_ENABLE) != 0;
863 static u32 bcm2835_clock_choose_div(struct clk_hw *hw,
864 unsigned long rate,
865 unsigned long parent_rate,
866 bool round_up)
868 struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
869 const struct bcm2835_clock_data *data = clock->data;
870 u32 unused_frac_mask =
871 GENMASK(CM_DIV_FRAC_BITS - data->frac_bits, 0) >> 1;
872 u64 temp = (u64)parent_rate << CM_DIV_FRAC_BITS;
873 u64 rem;
874 u32 div, mindiv, maxdiv;
876 rem = do_div(temp, rate);
877 div = temp;
879 /* Round up and mask off the unused bits */
880 if (round_up && ((div & unused_frac_mask) != 0 || rem != 0))
881 div += unused_frac_mask + 1;
882 div &= ~unused_frac_mask;
884 /* different clamping limits apply for a mash clock */
885 if (data->is_mash_clock) {
886 /* clamp to min divider of 2 */
887 mindiv = 2 << CM_DIV_FRAC_BITS;
888 /* clamp to the highest possible integer divider */
889 maxdiv = (BIT(data->int_bits) - 1) << CM_DIV_FRAC_BITS;
890 } else {
891 /* clamp to min divider of 1 */
892 mindiv = 1 << CM_DIV_FRAC_BITS;
893 /* clamp to the highest possible fractional divider */
894 maxdiv = GENMASK(data->int_bits + CM_DIV_FRAC_BITS - 1,
895 CM_DIV_FRAC_BITS - data->frac_bits);
898 /* apply the clamping limits */
899 div = max_t(u32, div, mindiv);
900 div = min_t(u32, div, maxdiv);
902 return div;
905 static long bcm2835_clock_rate_from_divisor(struct bcm2835_clock *clock,
906 unsigned long parent_rate,
907 u32 div)
909 const struct bcm2835_clock_data *data = clock->data;
910 u64 temp;
913 * The divisor is a 12.12 fixed point field, but only some of
914 * the bits are populated in any given clock.
916 div >>= CM_DIV_FRAC_BITS - data->frac_bits;
917 div &= (1 << (data->int_bits + data->frac_bits)) - 1;
919 if (div == 0)
920 return 0;
922 temp = (u64)parent_rate << data->frac_bits;
924 do_div(temp, div);
926 return temp;
929 static unsigned long bcm2835_clock_get_rate(struct clk_hw *hw,
930 unsigned long parent_rate)
932 struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
933 struct bcm2835_cprman *cprman = clock->cprman;
934 const struct bcm2835_clock_data *data = clock->data;
935 u32 div = cprman_read(cprman, data->div_reg);
937 return bcm2835_clock_rate_from_divisor(clock, parent_rate, div);
940 static void bcm2835_clock_wait_busy(struct bcm2835_clock *clock)
942 struct bcm2835_cprman *cprman = clock->cprman;
943 const struct bcm2835_clock_data *data = clock->data;
944 ktime_t timeout = ktime_add_ns(ktime_get(), LOCK_TIMEOUT_NS);
946 while (cprman_read(cprman, data->ctl_reg) & CM_BUSY) {
947 if (ktime_after(ktime_get(), timeout)) {
948 dev_err(cprman->dev, "%s: couldn't lock PLL\n",
949 clk_hw_get_name(&clock->hw));
950 return;
952 cpu_relax();
956 static void bcm2835_clock_off(struct clk_hw *hw)
958 struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
959 struct bcm2835_cprman *cprman = clock->cprman;
960 const struct bcm2835_clock_data *data = clock->data;
962 spin_lock(&cprman->regs_lock);
963 cprman_write(cprman, data->ctl_reg,
964 cprman_read(cprman, data->ctl_reg) & ~CM_ENABLE);
965 spin_unlock(&cprman->regs_lock);
967 /* BUSY will remain high until the divider completes its cycle. */
968 bcm2835_clock_wait_busy(clock);
971 static int bcm2835_clock_on(struct clk_hw *hw)
973 struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
974 struct bcm2835_cprman *cprman = clock->cprman;
975 const struct bcm2835_clock_data *data = clock->data;
977 spin_lock(&cprman->regs_lock);
978 cprman_write(cprman, data->ctl_reg,
979 cprman_read(cprman, data->ctl_reg) |
980 CM_ENABLE |
981 CM_GATE);
982 spin_unlock(&cprman->regs_lock);
984 return 0;
987 static int bcm2835_clock_set_rate(struct clk_hw *hw,
988 unsigned long rate, unsigned long parent_rate)
990 struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
991 struct bcm2835_cprman *cprman = clock->cprman;
992 const struct bcm2835_clock_data *data = clock->data;
993 u32 div = bcm2835_clock_choose_div(hw, rate, parent_rate, false);
994 u32 ctl;
996 spin_lock(&cprman->regs_lock);
999 * Setting up frac support
1001 * In principle it is recommended to stop/start the clock first,
1002 * but as we set CLK_SET_RATE_GATE during registration of the
1003 * clock this requirement should be take care of by the
1004 * clk-framework.
1006 ctl = cprman_read(cprman, data->ctl_reg) & ~CM_FRAC;
1007 ctl |= (div & CM_DIV_FRAC_MASK) ? CM_FRAC : 0;
1008 cprman_write(cprman, data->ctl_reg, ctl);
1010 cprman_write(cprman, data->div_reg, div);
1012 spin_unlock(&cprman->regs_lock);
1014 return 0;
1017 static bool
1018 bcm2835_clk_is_pllc(struct clk_hw *hw)
1020 if (!hw)
1021 return false;
1023 return strncmp(clk_hw_get_name(hw), "pllc", 4) == 0;
1026 static int bcm2835_clock_determine_rate(struct clk_hw *hw,
1027 struct clk_rate_request *req)
1029 struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
1030 struct clk_hw *parent, *best_parent = NULL;
1031 bool current_parent_is_pllc;
1032 unsigned long rate, best_rate = 0;
1033 unsigned long prate, best_prate = 0;
1034 size_t i;
1035 u32 div;
1037 current_parent_is_pllc = bcm2835_clk_is_pllc(clk_hw_get_parent(hw));
1040 * Select parent clock that results in the closest but lower rate
1042 for (i = 0; i < clk_hw_get_num_parents(hw); ++i) {
1043 parent = clk_hw_get_parent_by_index(hw, i);
1044 if (!parent)
1045 continue;
1048 * Don't choose a PLLC-derived clock as our parent
1049 * unless it had been manually set that way. PLLC's
1050 * frequency gets adjusted by the firmware due to
1051 * over-temp or under-voltage conditions, without
1052 * prior notification to our clock consumer.
1054 if (bcm2835_clk_is_pllc(parent) && !current_parent_is_pllc)
1055 continue;
1057 prate = clk_hw_get_rate(parent);
1058 div = bcm2835_clock_choose_div(hw, req->rate, prate, true);
1059 rate = bcm2835_clock_rate_from_divisor(clock, prate, div);
1060 if (rate > best_rate && rate <= req->rate) {
1061 best_parent = parent;
1062 best_prate = prate;
1063 best_rate = rate;
1067 if (!best_parent)
1068 return -EINVAL;
1070 req->best_parent_hw = best_parent;
1071 req->best_parent_rate = best_prate;
1073 req->rate = best_rate;
1075 return 0;
1078 static int bcm2835_clock_set_parent(struct clk_hw *hw, u8 index)
1080 struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
1081 struct bcm2835_cprman *cprman = clock->cprman;
1082 const struct bcm2835_clock_data *data = clock->data;
1083 u8 src = (index << CM_SRC_SHIFT) & CM_SRC_MASK;
1085 cprman_write(cprman, data->ctl_reg, src);
1086 return 0;
1089 static u8 bcm2835_clock_get_parent(struct clk_hw *hw)
1091 struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
1092 struct bcm2835_cprman *cprman = clock->cprman;
1093 const struct bcm2835_clock_data *data = clock->data;
1094 u32 src = cprman_read(cprman, data->ctl_reg);
1096 return (src & CM_SRC_MASK) >> CM_SRC_SHIFT;
1099 static struct debugfs_reg32 bcm2835_debugfs_clock_reg32[] = {
1101 .name = "ctl",
1102 .offset = 0,
1105 .name = "div",
1106 .offset = 4,
1110 static int bcm2835_clock_debug_init(struct clk_hw *hw,
1111 struct dentry *dentry)
1113 struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
1114 struct bcm2835_cprman *cprman = clock->cprman;
1115 const struct bcm2835_clock_data *data = clock->data;
1117 return bcm2835_debugfs_regset(
1118 cprman, data->ctl_reg,
1119 bcm2835_debugfs_clock_reg32,
1120 ARRAY_SIZE(bcm2835_debugfs_clock_reg32),
1121 dentry);
1124 static const struct clk_ops bcm2835_clock_clk_ops = {
1125 .is_prepared = bcm2835_clock_is_on,
1126 .prepare = bcm2835_clock_on,
1127 .unprepare = bcm2835_clock_off,
1128 .recalc_rate = bcm2835_clock_get_rate,
1129 .set_rate = bcm2835_clock_set_rate,
1130 .determine_rate = bcm2835_clock_determine_rate,
1131 .set_parent = bcm2835_clock_set_parent,
1132 .get_parent = bcm2835_clock_get_parent,
1133 .debug_init = bcm2835_clock_debug_init,
1136 static int bcm2835_vpu_clock_is_on(struct clk_hw *hw)
1138 return true;
1142 * The VPU clock can never be disabled (it doesn't have an ENABLE
1143 * bit), so it gets its own set of clock ops.
1145 static const struct clk_ops bcm2835_vpu_clock_clk_ops = {
1146 .is_prepared = bcm2835_vpu_clock_is_on,
1147 .recalc_rate = bcm2835_clock_get_rate,
1148 .set_rate = bcm2835_clock_set_rate,
1149 .determine_rate = bcm2835_clock_determine_rate,
1150 .set_parent = bcm2835_clock_set_parent,
1151 .get_parent = bcm2835_clock_get_parent,
1152 .debug_init = bcm2835_clock_debug_init,
1155 static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman,
1156 const struct bcm2835_pll_data *data)
1158 struct bcm2835_pll *pll;
1159 struct clk_init_data init;
1160 int ret;
1162 memset(&init, 0, sizeof(init));
1164 /* All of the PLLs derive from the external oscillator. */
1165 init.parent_names = &cprman->osc_name;
1166 init.num_parents = 1;
1167 init.name = data->name;
1168 init.ops = &bcm2835_pll_clk_ops;
1169 init.flags = CLK_IGNORE_UNUSED;
1171 pll = kzalloc(sizeof(*pll), GFP_KERNEL);
1172 if (!pll)
1173 return NULL;
1175 pll->cprman = cprman;
1176 pll->data = data;
1177 pll->hw.init = &init;
1179 ret = devm_clk_hw_register(cprman->dev, &pll->hw);
1180 if (ret)
1181 return NULL;
1182 return &pll->hw;
1185 static struct clk_hw *
1186 bcm2835_register_pll_divider(struct bcm2835_cprman *cprman,
1187 const struct bcm2835_pll_divider_data *data)
1189 struct bcm2835_pll_divider *divider;
1190 struct clk_init_data init;
1191 const char *divider_name;
1192 int ret;
1194 if (data->fixed_divider != 1) {
1195 divider_name = devm_kasprintf(cprman->dev, GFP_KERNEL,
1196 "%s_prediv", data->name);
1197 if (!divider_name)
1198 return NULL;
1199 } else {
1200 divider_name = data->name;
1203 memset(&init, 0, sizeof(init));
1205 init.parent_names = &data->source_pll;
1206 init.num_parents = 1;
1207 init.name = divider_name;
1208 init.ops = &bcm2835_pll_divider_clk_ops;
1209 init.flags = CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED;
1211 divider = devm_kzalloc(cprman->dev, sizeof(*divider), GFP_KERNEL);
1212 if (!divider)
1213 return NULL;
1215 divider->div.reg = cprman->regs + data->a2w_reg;
1216 divider->div.shift = A2W_PLL_DIV_SHIFT;
1217 divider->div.width = A2W_PLL_DIV_BITS;
1218 divider->div.flags = CLK_DIVIDER_MAX_AT_ZERO;
1219 divider->div.lock = &cprman->regs_lock;
1220 divider->div.hw.init = &init;
1221 divider->div.table = NULL;
1223 divider->cprman = cprman;
1224 divider->data = data;
1226 ret = devm_clk_hw_register(cprman->dev, &divider->div.hw);
1227 if (ret)
1228 return ERR_PTR(ret);
1231 * PLLH's channels have a fixed divide by 10 afterwards, which
1232 * is what our consumers are actually using.
1234 if (data->fixed_divider != 1) {
1235 return clk_hw_register_fixed_factor(cprman->dev, data->name,
1236 divider_name,
1237 CLK_SET_RATE_PARENT,
1239 data->fixed_divider);
1242 return &divider->div.hw;
1245 static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
1246 const struct bcm2835_clock_data *data)
1248 struct bcm2835_clock *clock;
1249 struct clk_init_data init;
1250 const char *parents[1 << CM_SRC_BITS];
1251 size_t i;
1252 int ret;
1255 * Replace our "xosc" references with the oscillator's
1256 * actual name.
1258 for (i = 0; i < data->num_mux_parents; i++) {
1259 if (strcmp(data->parents[i], "xosc") == 0)
1260 parents[i] = cprman->osc_name;
1261 else
1262 parents[i] = data->parents[i];
1265 memset(&init, 0, sizeof(init));
1266 init.parent_names = parents;
1267 init.num_parents = data->num_mux_parents;
1268 init.name = data->name;
1269 init.flags = data->flags | CLK_IGNORE_UNUSED;
1271 if (data->is_vpu_clock) {
1272 init.ops = &bcm2835_vpu_clock_clk_ops;
1273 } else {
1274 init.ops = &bcm2835_clock_clk_ops;
1275 init.flags |= CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE;
1277 /* If the clock wasn't actually enabled at boot, it's not
1278 * critical.
1280 if (!(cprman_read(cprman, data->ctl_reg) & CM_ENABLE))
1281 init.flags &= ~CLK_IS_CRITICAL;
1284 clock = devm_kzalloc(cprman->dev, sizeof(*clock), GFP_KERNEL);
1285 if (!clock)
1286 return NULL;
1288 clock->cprman = cprman;
1289 clock->data = data;
1290 clock->hw.init = &init;
1292 ret = devm_clk_hw_register(cprman->dev, &clock->hw);
1293 if (ret)
1294 return ERR_PTR(ret);
1295 return &clock->hw;
1298 static struct clk *bcm2835_register_gate(struct bcm2835_cprman *cprman,
1299 const struct bcm2835_gate_data *data)
1301 return clk_register_gate(cprman->dev, data->name, data->parent,
1302 CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
1303 cprman->regs + data->ctl_reg,
1304 CM_GATE_BIT, 0, &cprman->regs_lock);
1307 typedef struct clk_hw *(*bcm2835_clk_register)(struct bcm2835_cprman *cprman,
1308 const void *data);
1309 struct bcm2835_clk_desc {
1310 bcm2835_clk_register clk_register;
1311 const void *data;
1314 /* assignment helper macros for different clock types */
1315 #define _REGISTER(f, ...) { .clk_register = (bcm2835_clk_register)f, \
1316 .data = __VA_ARGS__ }
1317 #define REGISTER_PLL(...) _REGISTER(&bcm2835_register_pll, \
1318 &(struct bcm2835_pll_data) \
1319 {__VA_ARGS__})
1320 #define REGISTER_PLL_DIV(...) _REGISTER(&bcm2835_register_pll_divider, \
1321 &(struct bcm2835_pll_divider_data) \
1322 {__VA_ARGS__})
1323 #define REGISTER_CLK(...) _REGISTER(&bcm2835_register_clock, \
1324 &(struct bcm2835_clock_data) \
1325 {__VA_ARGS__})
1326 #define REGISTER_GATE(...) _REGISTER(&bcm2835_register_gate, \
1327 &(struct bcm2835_gate_data) \
1328 {__VA_ARGS__})
1330 /* parent mux arrays plus helper macros */
1332 /* main oscillator parent mux */
1333 static const char *const bcm2835_clock_osc_parents[] = {
1334 "gnd",
1335 "xosc",
1336 "testdebug0",
1337 "testdebug1"
1340 #define REGISTER_OSC_CLK(...) REGISTER_CLK( \
1341 .num_mux_parents = ARRAY_SIZE(bcm2835_clock_osc_parents), \
1342 .parents = bcm2835_clock_osc_parents, \
1343 __VA_ARGS__)
1345 /* main peripherial parent mux */
1346 static const char *const bcm2835_clock_per_parents[] = {
1347 "gnd",
1348 "xosc",
1349 "testdebug0",
1350 "testdebug1",
1351 "plla_per",
1352 "pllc_per",
1353 "plld_per",
1354 "pllh_aux",
1357 #define REGISTER_PER_CLK(...) REGISTER_CLK( \
1358 .num_mux_parents = ARRAY_SIZE(bcm2835_clock_per_parents), \
1359 .parents = bcm2835_clock_per_parents, \
1360 __VA_ARGS__)
1362 /* main vpu parent mux */
1363 static const char *const bcm2835_clock_vpu_parents[] = {
1364 "gnd",
1365 "xosc",
1366 "testdebug0",
1367 "testdebug1",
1368 "plla_core",
1369 "pllc_core0",
1370 "plld_core",
1371 "pllh_aux",
1372 "pllc_core1",
1373 "pllc_core2",
1376 #define REGISTER_VPU_CLK(...) REGISTER_CLK( \
1377 .num_mux_parents = ARRAY_SIZE(bcm2835_clock_vpu_parents), \
1378 .parents = bcm2835_clock_vpu_parents, \
1379 __VA_ARGS__)
1382 * the real definition of all the pll, pll_dividers and clocks
1383 * these make use of the above REGISTER_* macros
1385 static const struct bcm2835_clk_desc clk_desc_array[] = {
1386 /* the PLL + PLL dividers */
1389 * PLLA is the auxiliary PLL, used to drive the CCP2
1390 * (Compact Camera Port 2) transmitter clock.
1392 * It is in the PX LDO power domain, which is on when the
1393 * AUDIO domain is on.
1395 [BCM2835_PLLA] = REGISTER_PLL(
1396 .name = "plla",
1397 .cm_ctrl_reg = CM_PLLA,
1398 .a2w_ctrl_reg = A2W_PLLA_CTRL,
1399 .frac_reg = A2W_PLLA_FRAC,
1400 .ana_reg_base = A2W_PLLA_ANA0,
1401 .reference_enable_mask = A2W_XOSC_CTRL_PLLA_ENABLE,
1402 .lock_mask = CM_LOCK_FLOCKA,
1404 .ana = &bcm2835_ana_default,
1406 .min_rate = 600000000u,
1407 .max_rate = 2400000000u,
1408 .max_fb_rate = BCM2835_MAX_FB_RATE),
1409 [BCM2835_PLLA_CORE] = REGISTER_PLL_DIV(
1410 .name = "plla_core",
1411 .source_pll = "plla",
1412 .cm_reg = CM_PLLA,
1413 .a2w_reg = A2W_PLLA_CORE,
1414 .load_mask = CM_PLLA_LOADCORE,
1415 .hold_mask = CM_PLLA_HOLDCORE,
1416 .fixed_divider = 1),
1417 [BCM2835_PLLA_PER] = REGISTER_PLL_DIV(
1418 .name = "plla_per",
1419 .source_pll = "plla",
1420 .cm_reg = CM_PLLA,
1421 .a2w_reg = A2W_PLLA_PER,
1422 .load_mask = CM_PLLA_LOADPER,
1423 .hold_mask = CM_PLLA_HOLDPER,
1424 .fixed_divider = 1),
1425 [BCM2835_PLLA_DSI0] = REGISTER_PLL_DIV(
1426 .name = "plla_dsi0",
1427 .source_pll = "plla",
1428 .cm_reg = CM_PLLA,
1429 .a2w_reg = A2W_PLLA_DSI0,
1430 .load_mask = CM_PLLA_LOADDSI0,
1431 .hold_mask = CM_PLLA_HOLDDSI0,
1432 .fixed_divider = 1),
1433 [BCM2835_PLLA_CCP2] = REGISTER_PLL_DIV(
1434 .name = "plla_ccp2",
1435 .source_pll = "plla",
1436 .cm_reg = CM_PLLA,
1437 .a2w_reg = A2W_PLLA_CCP2,
1438 .load_mask = CM_PLLA_LOADCCP2,
1439 .hold_mask = CM_PLLA_HOLDCCP2,
1440 .fixed_divider = 1),
1442 /* PLLB is used for the ARM's clock. */
1443 [BCM2835_PLLB] = REGISTER_PLL(
1444 .name = "pllb",
1445 .cm_ctrl_reg = CM_PLLB,
1446 .a2w_ctrl_reg = A2W_PLLB_CTRL,
1447 .frac_reg = A2W_PLLB_FRAC,
1448 .ana_reg_base = A2W_PLLB_ANA0,
1449 .reference_enable_mask = A2W_XOSC_CTRL_PLLB_ENABLE,
1450 .lock_mask = CM_LOCK_FLOCKB,
1452 .ana = &bcm2835_ana_default,
1454 .min_rate = 600000000u,
1455 .max_rate = 3000000000u,
1456 .max_fb_rate = BCM2835_MAX_FB_RATE),
1457 [BCM2835_PLLB_ARM] = REGISTER_PLL_DIV(
1458 .name = "pllb_arm",
1459 .source_pll = "pllb",
1460 .cm_reg = CM_PLLB,
1461 .a2w_reg = A2W_PLLB_ARM,
1462 .load_mask = CM_PLLB_LOADARM,
1463 .hold_mask = CM_PLLB_HOLDARM,
1464 .fixed_divider = 1),
1467 * PLLC is the core PLL, used to drive the core VPU clock.
1469 * It is in the PX LDO power domain, which is on when the
1470 * AUDIO domain is on.
1472 [BCM2835_PLLC] = REGISTER_PLL(
1473 .name = "pllc",
1474 .cm_ctrl_reg = CM_PLLC,
1475 .a2w_ctrl_reg = A2W_PLLC_CTRL,
1476 .frac_reg = A2W_PLLC_FRAC,
1477 .ana_reg_base = A2W_PLLC_ANA0,
1478 .reference_enable_mask = A2W_XOSC_CTRL_PLLC_ENABLE,
1479 .lock_mask = CM_LOCK_FLOCKC,
1481 .ana = &bcm2835_ana_default,
1483 .min_rate = 600000000u,
1484 .max_rate = 3000000000u,
1485 .max_fb_rate = BCM2835_MAX_FB_RATE),
1486 [BCM2835_PLLC_CORE0] = REGISTER_PLL_DIV(
1487 .name = "pllc_core0",
1488 .source_pll = "pllc",
1489 .cm_reg = CM_PLLC,
1490 .a2w_reg = A2W_PLLC_CORE0,
1491 .load_mask = CM_PLLC_LOADCORE0,
1492 .hold_mask = CM_PLLC_HOLDCORE0,
1493 .fixed_divider = 1),
1494 [BCM2835_PLLC_CORE1] = REGISTER_PLL_DIV(
1495 .name = "pllc_core1",
1496 .source_pll = "pllc",
1497 .cm_reg = CM_PLLC,
1498 .a2w_reg = A2W_PLLC_CORE1,
1499 .load_mask = CM_PLLC_LOADCORE1,
1500 .hold_mask = CM_PLLC_HOLDCORE1,
1501 .fixed_divider = 1),
1502 [BCM2835_PLLC_CORE2] = REGISTER_PLL_DIV(
1503 .name = "pllc_core2",
1504 .source_pll = "pllc",
1505 .cm_reg = CM_PLLC,
1506 .a2w_reg = A2W_PLLC_CORE2,
1507 .load_mask = CM_PLLC_LOADCORE2,
1508 .hold_mask = CM_PLLC_HOLDCORE2,
1509 .fixed_divider = 1),
1510 [BCM2835_PLLC_PER] = REGISTER_PLL_DIV(
1511 .name = "pllc_per",
1512 .source_pll = "pllc",
1513 .cm_reg = CM_PLLC,
1514 .a2w_reg = A2W_PLLC_PER,
1515 .load_mask = CM_PLLC_LOADPER,
1516 .hold_mask = CM_PLLC_HOLDPER,
1517 .fixed_divider = 1),
1520 * PLLD is the display PLL, used to drive DSI display panels.
1522 * It is in the PX LDO power domain, which is on when the
1523 * AUDIO domain is on.
1525 [BCM2835_PLLD] = REGISTER_PLL(
1526 .name = "plld",
1527 .cm_ctrl_reg = CM_PLLD,
1528 .a2w_ctrl_reg = A2W_PLLD_CTRL,
1529 .frac_reg = A2W_PLLD_FRAC,
1530 .ana_reg_base = A2W_PLLD_ANA0,
1531 .reference_enable_mask = A2W_XOSC_CTRL_DDR_ENABLE,
1532 .lock_mask = CM_LOCK_FLOCKD,
1534 .ana = &bcm2835_ana_default,
1536 .min_rate = 600000000u,
1537 .max_rate = 2400000000u,
1538 .max_fb_rate = BCM2835_MAX_FB_RATE),
1539 [BCM2835_PLLD_CORE] = REGISTER_PLL_DIV(
1540 .name = "plld_core",
1541 .source_pll = "plld",
1542 .cm_reg = CM_PLLD,
1543 .a2w_reg = A2W_PLLD_CORE,
1544 .load_mask = CM_PLLD_LOADCORE,
1545 .hold_mask = CM_PLLD_HOLDCORE,
1546 .fixed_divider = 1),
1547 [BCM2835_PLLD_PER] = REGISTER_PLL_DIV(
1548 .name = "plld_per",
1549 .source_pll = "plld",
1550 .cm_reg = CM_PLLD,
1551 .a2w_reg = A2W_PLLD_PER,
1552 .load_mask = CM_PLLD_LOADPER,
1553 .hold_mask = CM_PLLD_HOLDPER,
1554 .fixed_divider = 1),
1555 [BCM2835_PLLD_DSI0] = REGISTER_PLL_DIV(
1556 .name = "plld_dsi0",
1557 .source_pll = "plld",
1558 .cm_reg = CM_PLLD,
1559 .a2w_reg = A2W_PLLD_DSI0,
1560 .load_mask = CM_PLLD_LOADDSI0,
1561 .hold_mask = CM_PLLD_HOLDDSI0,
1562 .fixed_divider = 1),
1563 [BCM2835_PLLD_DSI1] = REGISTER_PLL_DIV(
1564 .name = "plld_dsi1",
1565 .source_pll = "plld",
1566 .cm_reg = CM_PLLD,
1567 .a2w_reg = A2W_PLLD_DSI1,
1568 .load_mask = CM_PLLD_LOADDSI1,
1569 .hold_mask = CM_PLLD_HOLDDSI1,
1570 .fixed_divider = 1),
1573 * PLLH is used to supply the pixel clock or the AUX clock for the
1574 * TV encoder.
1576 * It is in the HDMI power domain.
1578 [BCM2835_PLLH] = REGISTER_PLL(
1579 "pllh",
1580 .cm_ctrl_reg = CM_PLLH,
1581 .a2w_ctrl_reg = A2W_PLLH_CTRL,
1582 .frac_reg = A2W_PLLH_FRAC,
1583 .ana_reg_base = A2W_PLLH_ANA0,
1584 .reference_enable_mask = A2W_XOSC_CTRL_PLLC_ENABLE,
1585 .lock_mask = CM_LOCK_FLOCKH,
1587 .ana = &bcm2835_ana_pllh,
1589 .min_rate = 600000000u,
1590 .max_rate = 3000000000u,
1591 .max_fb_rate = BCM2835_MAX_FB_RATE),
1592 [BCM2835_PLLH_RCAL] = REGISTER_PLL_DIV(
1593 .name = "pllh_rcal",
1594 .source_pll = "pllh",
1595 .cm_reg = CM_PLLH,
1596 .a2w_reg = A2W_PLLH_RCAL,
1597 .load_mask = CM_PLLH_LOADRCAL,
1598 .hold_mask = 0,
1599 .fixed_divider = 10),
1600 [BCM2835_PLLH_AUX] = REGISTER_PLL_DIV(
1601 .name = "pllh_aux",
1602 .source_pll = "pllh",
1603 .cm_reg = CM_PLLH,
1604 .a2w_reg = A2W_PLLH_AUX,
1605 .load_mask = CM_PLLH_LOADAUX,
1606 .hold_mask = 0,
1607 .fixed_divider = 1),
1608 [BCM2835_PLLH_PIX] = REGISTER_PLL_DIV(
1609 .name = "pllh_pix",
1610 .source_pll = "pllh",
1611 .cm_reg = CM_PLLH,
1612 .a2w_reg = A2W_PLLH_PIX,
1613 .load_mask = CM_PLLH_LOADPIX,
1614 .hold_mask = 0,
1615 .fixed_divider = 10),
1617 /* the clocks */
1619 /* clocks with oscillator parent mux */
1621 /* One Time Programmable Memory clock. Maximum 10Mhz. */
1622 [BCM2835_CLOCK_OTP] = REGISTER_OSC_CLK(
1623 .name = "otp",
1624 .ctl_reg = CM_OTPCTL,
1625 .div_reg = CM_OTPDIV,
1626 .int_bits = 4,
1627 .frac_bits = 0),
1629 * Used for a 1Mhz clock for the system clocksource, and also used
1630 * bythe watchdog timer and the camera pulse generator.
1632 [BCM2835_CLOCK_TIMER] = REGISTER_OSC_CLK(
1633 .name = "timer",
1634 .ctl_reg = CM_TIMERCTL,
1635 .div_reg = CM_TIMERDIV,
1636 .int_bits = 6,
1637 .frac_bits = 12),
1639 * Clock for the temperature sensor.
1640 * Generally run at 2Mhz, max 5Mhz.
1642 [BCM2835_CLOCK_TSENS] = REGISTER_OSC_CLK(
1643 .name = "tsens",
1644 .ctl_reg = CM_TSENSCTL,
1645 .div_reg = CM_TSENSDIV,
1646 .int_bits = 5,
1647 .frac_bits = 0),
1648 [BCM2835_CLOCK_TEC] = REGISTER_OSC_CLK(
1649 .name = "tec",
1650 .ctl_reg = CM_TECCTL,
1651 .div_reg = CM_TECDIV,
1652 .int_bits = 6,
1653 .frac_bits = 0),
1655 /* clocks with vpu parent mux */
1656 [BCM2835_CLOCK_H264] = REGISTER_VPU_CLK(
1657 .name = "h264",
1658 .ctl_reg = CM_H264CTL,
1659 .div_reg = CM_H264DIV,
1660 .int_bits = 4,
1661 .frac_bits = 8),
1662 [BCM2835_CLOCK_ISP] = REGISTER_VPU_CLK(
1663 .name = "isp",
1664 .ctl_reg = CM_ISPCTL,
1665 .div_reg = CM_ISPDIV,
1666 .int_bits = 4,
1667 .frac_bits = 8),
1670 * Secondary SDRAM clock. Used for low-voltage modes when the PLL
1671 * in the SDRAM controller can't be used.
1673 [BCM2835_CLOCK_SDRAM] = REGISTER_VPU_CLK(
1674 .name = "sdram",
1675 .ctl_reg = CM_SDCCTL,
1676 .div_reg = CM_SDCDIV,
1677 .int_bits = 6,
1678 .frac_bits = 0),
1679 [BCM2835_CLOCK_V3D] = REGISTER_VPU_CLK(
1680 .name = "v3d",
1681 .ctl_reg = CM_V3DCTL,
1682 .div_reg = CM_V3DDIV,
1683 .int_bits = 4,
1684 .frac_bits = 8),
1686 * VPU clock. This doesn't have an enable bit, since it drives
1687 * the bus for everything else, and is special so it doesn't need
1688 * to be gated for rate changes. It is also known as "clk_audio"
1689 * in various hardware documentation.
1691 [BCM2835_CLOCK_VPU] = REGISTER_VPU_CLK(
1692 .name = "vpu",
1693 .ctl_reg = CM_VPUCTL,
1694 .div_reg = CM_VPUDIV,
1695 .int_bits = 12,
1696 .frac_bits = 8,
1697 .flags = CLK_IS_CRITICAL,
1698 .is_vpu_clock = true),
1700 /* clocks with per parent mux */
1701 [BCM2835_CLOCK_AVEO] = REGISTER_PER_CLK(
1702 .name = "aveo",
1703 .ctl_reg = CM_AVEOCTL,
1704 .div_reg = CM_AVEODIV,
1705 .int_bits = 4,
1706 .frac_bits = 0),
1707 [BCM2835_CLOCK_CAM0] = REGISTER_PER_CLK(
1708 .name = "cam0",
1709 .ctl_reg = CM_CAM0CTL,
1710 .div_reg = CM_CAM0DIV,
1711 .int_bits = 4,
1712 .frac_bits = 8),
1713 [BCM2835_CLOCK_CAM1] = REGISTER_PER_CLK(
1714 .name = "cam1",
1715 .ctl_reg = CM_CAM1CTL,
1716 .div_reg = CM_CAM1DIV,
1717 .int_bits = 4,
1718 .frac_bits = 8),
1719 [BCM2835_CLOCK_DFT] = REGISTER_PER_CLK(
1720 .name = "dft",
1721 .ctl_reg = CM_DFTCTL,
1722 .div_reg = CM_DFTDIV,
1723 .int_bits = 5,
1724 .frac_bits = 0),
1725 [BCM2835_CLOCK_DPI] = REGISTER_PER_CLK(
1726 .name = "dpi",
1727 .ctl_reg = CM_DPICTL,
1728 .div_reg = CM_DPIDIV,
1729 .int_bits = 4,
1730 .frac_bits = 8),
1732 /* Arasan EMMC clock */
1733 [BCM2835_CLOCK_EMMC] = REGISTER_PER_CLK(
1734 .name = "emmc",
1735 .ctl_reg = CM_EMMCCTL,
1736 .div_reg = CM_EMMCDIV,
1737 .int_bits = 4,
1738 .frac_bits = 8),
1740 /* General purpose (GPIO) clocks */
1741 [BCM2835_CLOCK_GP0] = REGISTER_PER_CLK(
1742 .name = "gp0",
1743 .ctl_reg = CM_GP0CTL,
1744 .div_reg = CM_GP0DIV,
1745 .int_bits = 12,
1746 .frac_bits = 12,
1747 .is_mash_clock = true),
1748 [BCM2835_CLOCK_GP1] = REGISTER_PER_CLK(
1749 .name = "gp1",
1750 .ctl_reg = CM_GP1CTL,
1751 .div_reg = CM_GP1DIV,
1752 .int_bits = 12,
1753 .frac_bits = 12,
1754 .flags = CLK_IS_CRITICAL,
1755 .is_mash_clock = true),
1756 [BCM2835_CLOCK_GP2] = REGISTER_PER_CLK(
1757 .name = "gp2",
1758 .ctl_reg = CM_GP2CTL,
1759 .div_reg = CM_GP2DIV,
1760 .int_bits = 12,
1761 .frac_bits = 12,
1762 .flags = CLK_IS_CRITICAL),
1764 /* HDMI state machine */
1765 [BCM2835_CLOCK_HSM] = REGISTER_PER_CLK(
1766 .name = "hsm",
1767 .ctl_reg = CM_HSMCTL,
1768 .div_reg = CM_HSMDIV,
1769 .int_bits = 4,
1770 .frac_bits = 8),
1771 [BCM2835_CLOCK_PCM] = REGISTER_PER_CLK(
1772 .name = "pcm",
1773 .ctl_reg = CM_PCMCTL,
1774 .div_reg = CM_PCMDIV,
1775 .int_bits = 12,
1776 .frac_bits = 12,
1777 .is_mash_clock = true),
1778 [BCM2835_CLOCK_PWM] = REGISTER_PER_CLK(
1779 .name = "pwm",
1780 .ctl_reg = CM_PWMCTL,
1781 .div_reg = CM_PWMDIV,
1782 .int_bits = 12,
1783 .frac_bits = 12,
1784 .is_mash_clock = true),
1785 [BCM2835_CLOCK_SLIM] = REGISTER_PER_CLK(
1786 .name = "slim",
1787 .ctl_reg = CM_SLIMCTL,
1788 .div_reg = CM_SLIMDIV,
1789 .int_bits = 12,
1790 .frac_bits = 12,
1791 .is_mash_clock = true),
1792 [BCM2835_CLOCK_SMI] = REGISTER_PER_CLK(
1793 .name = "smi",
1794 .ctl_reg = CM_SMICTL,
1795 .div_reg = CM_SMIDIV,
1796 .int_bits = 4,
1797 .frac_bits = 8),
1798 [BCM2835_CLOCK_UART] = REGISTER_PER_CLK(
1799 .name = "uart",
1800 .ctl_reg = CM_UARTCTL,
1801 .div_reg = CM_UARTDIV,
1802 .int_bits = 10,
1803 .frac_bits = 12),
1805 /* TV encoder clock. Only operating frequency is 108Mhz. */
1806 [BCM2835_CLOCK_VEC] = REGISTER_PER_CLK(
1807 .name = "vec",
1808 .ctl_reg = CM_VECCTL,
1809 .div_reg = CM_VECDIV,
1810 .int_bits = 4,
1811 .frac_bits = 0),
1813 /* dsi clocks */
1814 [BCM2835_CLOCK_DSI0E] = REGISTER_PER_CLK(
1815 .name = "dsi0e",
1816 .ctl_reg = CM_DSI0ECTL,
1817 .div_reg = CM_DSI0EDIV,
1818 .int_bits = 4,
1819 .frac_bits = 8),
1820 [BCM2835_CLOCK_DSI1E] = REGISTER_PER_CLK(
1821 .name = "dsi1e",
1822 .ctl_reg = CM_DSI1ECTL,
1823 .div_reg = CM_DSI1EDIV,
1824 .int_bits = 4,
1825 .frac_bits = 8),
1827 /* the gates */
1830 * CM_PERIICTL (and CM_PERIACTL, CM_SYSCTL and CM_VPUCTL if
1831 * you have the debug bit set in the power manager, which we
1832 * don't bother exposing) are individual gates off of the
1833 * non-stop vpu clock.
1835 [BCM2835_CLOCK_PERI_IMAGE] = REGISTER_GATE(
1836 .name = "peri_image",
1837 .parent = "vpu",
1838 .ctl_reg = CM_PERIICTL),
1842 * Permanently take a reference on the parent of the SDRAM clock.
1844 * While the SDRAM is being driven by its dedicated PLL most of the
1845 * time, there is a little loop running in the firmware that
1846 * periodically switches the SDRAM to using our CM clock to do PVT
1847 * recalibration, with the assumption that the previously configured
1848 * SDRAM parent is still enabled and running.
1850 static int bcm2835_mark_sdc_parent_critical(struct clk *sdc)
1852 struct clk *parent = clk_get_parent(sdc);
1854 if (IS_ERR(parent))
1855 return PTR_ERR(parent);
1857 return clk_prepare_enable(parent);
1860 static int bcm2835_clk_probe(struct platform_device *pdev)
1862 struct device *dev = &pdev->dev;
1863 struct clk_hw **hws;
1864 struct bcm2835_cprman *cprman;
1865 struct resource *res;
1866 const struct bcm2835_clk_desc *desc;
1867 const size_t asize = ARRAY_SIZE(clk_desc_array);
1868 size_t i;
1869 int ret;
1871 cprman = devm_kzalloc(dev, sizeof(*cprman) +
1872 sizeof(*cprman->onecell.hws) * asize,
1873 GFP_KERNEL);
1874 if (!cprman)
1875 return -ENOMEM;
1877 spin_lock_init(&cprman->regs_lock);
1878 cprman->dev = dev;
1879 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1880 cprman->regs = devm_ioremap_resource(dev, res);
1881 if (IS_ERR(cprman->regs))
1882 return PTR_ERR(cprman->regs);
1884 cprman->osc_name = of_clk_get_parent_name(dev->of_node, 0);
1885 if (!cprman->osc_name)
1886 return -ENODEV;
1888 platform_set_drvdata(pdev, cprman);
1890 cprman->onecell.num = asize;
1891 hws = cprman->onecell.hws;
1893 for (i = 0; i < asize; i++) {
1894 desc = &clk_desc_array[i];
1895 if (desc->clk_register && desc->data)
1896 hws[i] = desc->clk_register(cprman, desc->data);
1899 ret = bcm2835_mark_sdc_parent_critical(hws[BCM2835_CLOCK_SDRAM]->clk);
1900 if (ret)
1901 return ret;
1903 return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
1904 &cprman->onecell);
1907 static const struct of_device_id bcm2835_clk_of_match[] = {
1908 { .compatible = "brcm,bcm2835-cprman", },
1911 MODULE_DEVICE_TABLE(of, bcm2835_clk_of_match);
1913 static struct platform_driver bcm2835_clk_driver = {
1914 .driver = {
1915 .name = "bcm2835-clk",
1916 .of_match_table = bcm2835_clk_of_match,
1918 .probe = bcm2835_clk_probe,
1921 builtin_platform_driver(bcm2835_clk_driver);
1923 MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
1924 MODULE_DESCRIPTION("BCM2835 clock driver");
1925 MODULE_LICENSE("GPL v2");