diff options
author | Simran Rai <ssimran@broadcom.com> | 2016-01-26 20:18:39 -0500 |
---|---|---|
committer | Stephen Boyd <sboyd@codeaurora.org> | 2016-01-29 19:31:38 -0500 |
commit | bcd8be139803f51834347840349c150bf0e4eb96 (patch) | |
tree | 291d7867d7475a73f41cd68f454a4e6348f0c307 | |
parent | 7eb24279d2094eda074527762629d8146b148a22 (diff) |
clk: iproc: Add support for Cygnus audio clocks
This patch adds support for Broadcom Cygnus audio PLL and leaf
clocks
Signed-off-by: Simran Rai <ssimran@broadcom.com>
Reviewed-by: Scott Branden <sbranden@broadcom.com>
Signed-off-by: Ray Jui <rjui@broadcom.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
-rw-r--r-- | drivers/clk/bcm/clk-cygnus.c | 59 | ||||
-rw-r--r-- | drivers/clk/bcm/clk-iproc-pll.c | 41 | ||||
-rw-r--r-- | drivers/clk/bcm/clk-iproc.h | 21 | ||||
-rw-r--r-- | include/dt-bindings/clock/bcm-cygnus.h | 6 |
4 files changed, 122 insertions, 5 deletions
diff --git a/drivers/clk/bcm/clk-cygnus.c b/drivers/clk/bcm/clk-cygnus.c index 3a228b6d4fee..464fdc4bc66b 100644 --- a/drivers/clk/bcm/clk-cygnus.c +++ b/drivers/clk/bcm/clk-cygnus.c | |||
@@ -268,3 +268,62 @@ static void __init cygnus_asiu_init(struct device_node *node) | |||
268 | iproc_asiu_setup(node, asiu_div, asiu_gate, ARRAY_SIZE(asiu_div)); | 268 | iproc_asiu_setup(node, asiu_div, asiu_gate, ARRAY_SIZE(asiu_div)); |
269 | } | 269 | } |
270 | CLK_OF_DECLARE(cygnus_asiu_clk, "brcm,cygnus-asiu-clk", cygnus_asiu_init); | 270 | CLK_OF_DECLARE(cygnus_asiu_clk, "brcm,cygnus-asiu-clk", cygnus_asiu_init); |
271 | |||
272 | /* | ||
273 | * AUDIO PLL VCO frequency parameter table | ||
274 | * | ||
275 | * PLL output frequency = ((ndiv_int + ndiv_frac / 2^20) * | ||
276 | * (parent clock rate / pdiv) | ||
277 | * | ||
278 | * On Cygnus, parent is the 25MHz oscillator | ||
279 | */ | ||
280 | static const struct iproc_pll_vco_param audiopll_vco_params[] = { | ||
281 | /* rate (Hz) ndiv_int ndiv_frac pdiv */ | ||
282 | { 1354750204UL, 54, 199238, 1 }, | ||
283 | { 1769470191UL, 70, 816639, 1 }, | ||
284 | }; | ||
285 | |||
286 | static const struct iproc_pll_ctrl audiopll = { | ||
287 | .flags = IPROC_CLK_PLL_NEEDS_SW_CFG | IPROC_CLK_PLL_HAS_NDIV_FRAC | | ||
288 | IPROC_CLK_PLL_USER_MODE_ON | IPROC_CLK_PLL_RESET_ACTIVE_LOW, | ||
289 | .reset = RESET_VAL(0x5c, 0, 1), | ||
290 | .dig_filter = DF_VAL(0x48, 0, 3, 6, 4, 3, 3), | ||
291 | .sw_ctrl = SW_CTRL_VAL(0x4, 0), | ||
292 | .ndiv_int = REG_VAL(0x8, 0, 10), | ||
293 | .ndiv_frac = REG_VAL(0x8, 10, 20), | ||
294 | .pdiv = REG_VAL(0x44, 0, 4), | ||
295 | .vco_ctrl = VCO_CTRL_VAL(0x0c, 0x10), | ||
296 | .status = REG_VAL(0x54, 0, 1), | ||
297 | .macro_mode = REG_VAL(0x0, 0, 3), | ||
298 | }; | ||
299 | |||
300 | static const struct iproc_clk_ctrl audiopll_clk[] = { | ||
301 | [BCM_CYGNUS_AUDIOPLL_CH0] = { | ||
302 | .channel = BCM_CYGNUS_AUDIOPLL_CH0, | ||
303 | .flags = IPROC_CLK_AON | | ||
304 | IPROC_CLK_MCLK_DIV_BY_2, | ||
305 | .enable = ENABLE_VAL(0x14, 8, 10, 9), | ||
306 | .mdiv = REG_VAL(0x14, 0, 8), | ||
307 | }, | ||
308 | [BCM_CYGNUS_AUDIOPLL_CH1] = { | ||
309 | .channel = BCM_CYGNUS_AUDIOPLL_CH1, | ||
310 | .flags = IPROC_CLK_AON, | ||
311 | .enable = ENABLE_VAL(0x18, 8, 10, 9), | ||
312 | .mdiv = REG_VAL(0x18, 0, 8), | ||
313 | }, | ||
314 | [BCM_CYGNUS_AUDIOPLL_CH2] = { | ||
315 | .channel = BCM_CYGNUS_AUDIOPLL_CH2, | ||
316 | .flags = IPROC_CLK_AON, | ||
317 | .enable = ENABLE_VAL(0x1c, 8, 10, 9), | ||
318 | .mdiv = REG_VAL(0x1c, 0, 8), | ||
319 | }, | ||
320 | }; | ||
321 | |||
322 | static void __init cygnus_audiopll_clk_init(struct device_node *node) | ||
323 | { | ||
324 | iproc_pll_clk_setup(node, &audiopll, audiopll_vco_params, | ||
325 | ARRAY_SIZE(audiopll_vco_params), audiopll_clk, | ||
326 | ARRAY_SIZE(audiopll_clk)); | ||
327 | } | ||
328 | CLK_OF_DECLARE(cygnus_audiopll, "brcm,cygnus-audiopll", | ||
329 | cygnus_audiopll_clk_init); | ||
diff --git a/drivers/clk/bcm/clk-iproc-pll.c b/drivers/clk/bcm/clk-iproc-pll.c index afd5891ac9e6..fd492a5dad12 100644 --- a/drivers/clk/bcm/clk-iproc-pll.c +++ b/drivers/clk/bcm/clk-iproc-pll.c | |||
@@ -25,6 +25,12 @@ | |||
25 | #define PLL_VCO_HIGH_SHIFT 19 | 25 | #define PLL_VCO_HIGH_SHIFT 19 |
26 | #define PLL_VCO_LOW_SHIFT 30 | 26 | #define PLL_VCO_LOW_SHIFT 30 |
27 | 27 | ||
28 | /* | ||
29 | * PLL MACRO_SELECT modes 0 to 5 choose pre-calculated PLL output frequencies | ||
30 | * from a look-up table. Mode 7 allows user to manipulate PLL clock dividers | ||
31 | */ | ||
32 | #define PLL_USER_MODE 7 | ||
33 | |||
28 | /* number of delay loops waiting for PLL to lock */ | 34 | /* number of delay loops waiting for PLL to lock */ |
29 | #define LOCK_DELAY 100 | 35 | #define LOCK_DELAY 100 |
30 | 36 | ||
@@ -215,7 +221,10 @@ static void __pll_put_in_reset(struct iproc_pll *pll) | |||
215 | const struct iproc_pll_reset_ctrl *reset = &ctrl->reset; | 221 | const struct iproc_pll_reset_ctrl *reset = &ctrl->reset; |
216 | 222 | ||
217 | val = readl(pll->control_base + reset->offset); | 223 | val = readl(pll->control_base + reset->offset); |
218 | val &= ~(1 << reset->reset_shift | 1 << reset->p_reset_shift); | 224 | if (ctrl->flags & IPROC_CLK_PLL_RESET_ACTIVE_LOW) |
225 | val |= BIT(reset->reset_shift) | BIT(reset->p_reset_shift); | ||
226 | else | ||
227 | val &= ~(BIT(reset->reset_shift) | BIT(reset->p_reset_shift)); | ||
219 | iproc_pll_write(pll, pll->control_base, reset->offset, val); | 228 | iproc_pll_write(pll, pll->control_base, reset->offset, val); |
220 | } | 229 | } |
221 | 230 | ||
@@ -236,7 +245,10 @@ static void __pll_bring_out_reset(struct iproc_pll *pll, unsigned int kp, | |||
236 | iproc_pll_write(pll, pll->control_base, dig_filter->offset, val); | 245 | iproc_pll_write(pll, pll->control_base, dig_filter->offset, val); |
237 | 246 | ||
238 | val = readl(pll->control_base + reset->offset); | 247 | val = readl(pll->control_base + reset->offset); |
239 | val |= 1 << reset->reset_shift | 1 << reset->p_reset_shift; | 248 | if (ctrl->flags & IPROC_CLK_PLL_RESET_ACTIVE_LOW) |
249 | val &= ~(BIT(reset->reset_shift) | BIT(reset->p_reset_shift)); | ||
250 | else | ||
251 | val |= BIT(reset->reset_shift) | BIT(reset->p_reset_shift); | ||
240 | iproc_pll_write(pll, pll->control_base, reset->offset, val); | 252 | iproc_pll_write(pll, pll->control_base, reset->offset, val); |
241 | } | 253 | } |
242 | 254 | ||
@@ -292,6 +304,16 @@ static int pll_set_rate(struct iproc_clk *clk, unsigned int rate_index, | |||
292 | /* put PLL in reset */ | 304 | /* put PLL in reset */ |
293 | __pll_put_in_reset(pll); | 305 | __pll_put_in_reset(pll); |
294 | 306 | ||
307 | /* set PLL in user mode before modifying PLL controls */ | ||
308 | if (ctrl->flags & IPROC_CLK_PLL_USER_MODE_ON) { | ||
309 | val = readl(pll->control_base + ctrl->macro_mode.offset); | ||
310 | val &= ~(bit_mask(ctrl->macro_mode.width) << | ||
311 | ctrl->macro_mode.shift); | ||
312 | val |= PLL_USER_MODE << ctrl->macro_mode.shift; | ||
313 | iproc_pll_write(pll, pll->control_base, | ||
314 | ctrl->macro_mode.offset, val); | ||
315 | } | ||
316 | |||
295 | iproc_pll_write(pll, pll->control_base, ctrl->vco_ctrl.u_offset, 0); | 317 | iproc_pll_write(pll, pll->control_base, ctrl->vco_ctrl.u_offset, 0); |
296 | 318 | ||
297 | val = readl(pll->control_base + ctrl->vco_ctrl.l_offset); | 319 | val = readl(pll->control_base + ctrl->vco_ctrl.l_offset); |
@@ -505,7 +527,10 @@ static unsigned long iproc_clk_recalc_rate(struct clk_hw *hw, | |||
505 | if (mdiv == 0) | 527 | if (mdiv == 0) |
506 | mdiv = 256; | 528 | mdiv = 256; |
507 | 529 | ||
508 | clk->rate = parent_rate / mdiv; | 530 | if (ctrl->flags & IPROC_CLK_MCLK_DIV_BY_2) |
531 | clk->rate = parent_rate / (mdiv * 2); | ||
532 | else | ||
533 | clk->rate = parent_rate / mdiv; | ||
509 | 534 | ||
510 | return clk->rate; | 535 | return clk->rate; |
511 | } | 536 | } |
@@ -543,7 +568,10 @@ static int iproc_clk_set_rate(struct clk_hw *hw, unsigned long rate, | |||
543 | if (rate == 0 || parent_rate == 0) | 568 | if (rate == 0 || parent_rate == 0) |
544 | return -EINVAL; | 569 | return -EINVAL; |
545 | 570 | ||
546 | div = DIV_ROUND_UP(parent_rate, rate); | 571 | if (ctrl->flags & IPROC_CLK_MCLK_DIV_BY_2) |
572 | div = DIV_ROUND_UP(parent_rate, rate * 2); | ||
573 | else | ||
574 | div = DIV_ROUND_UP(parent_rate, rate); | ||
547 | if (div > 256) | 575 | if (div > 256) |
548 | return -EINVAL; | 576 | return -EINVAL; |
549 | 577 | ||
@@ -555,7 +583,10 @@ static int iproc_clk_set_rate(struct clk_hw *hw, unsigned long rate, | |||
555 | val |= div << ctrl->mdiv.shift; | 583 | val |= div << ctrl->mdiv.shift; |
556 | } | 584 | } |
557 | iproc_pll_write(pll, pll->control_base, ctrl->mdiv.offset, val); | 585 | iproc_pll_write(pll, pll->control_base, ctrl->mdiv.offset, val); |
558 | clk->rate = parent_rate / div; | 586 | if (ctrl->flags & IPROC_CLK_MCLK_DIV_BY_2) |
587 | clk->rate = parent_rate / (div * 2); | ||
588 | else | ||
589 | clk->rate = parent_rate / div; | ||
559 | 590 | ||
560 | return 0; | 591 | return 0; |
561 | } | 592 | } |
diff --git a/drivers/clk/bcm/clk-iproc.h b/drivers/clk/bcm/clk-iproc.h index 8988de70a98c..febae119f9ef 100644 --- a/drivers/clk/bcm/clk-iproc.h +++ b/drivers/clk/bcm/clk-iproc.h | |||
@@ -61,6 +61,26 @@ | |||
61 | #define IPROC_CLK_PLL_SPLIT_STAT_CTRL BIT(6) | 61 | #define IPROC_CLK_PLL_SPLIT_STAT_CTRL BIT(6) |
62 | 62 | ||
63 | /* | 63 | /* |
64 | * Some PLLs have an additional divide by 2 in master clock calculation; | ||
65 | * MCLK = VCO_freq / (Mdiv * 2). Identify this to let the driver know | ||
66 | * of modified calculations | ||
67 | */ | ||
68 | #define IPROC_CLK_MCLK_DIV_BY_2 BIT(7) | ||
69 | |||
70 | /* | ||
71 | * Some PLLs provide a look up table for the leaf clock frequencies and | ||
72 | * auto calculates VCO frequency parameters based on the provided leaf | ||
73 | * clock frequencies. They have a user mode that allows the divider | ||
74 | * controls to be determined by the user | ||
75 | */ | ||
76 | #define IPROC_CLK_PLL_USER_MODE_ON BIT(8) | ||
77 | |||
78 | /* | ||
79 | * Some PLLs have an active low reset | ||
80 | */ | ||
81 | #define IPROC_CLK_PLL_RESET_ACTIVE_LOW BIT(9) | ||
82 | |||
83 | /* | ||
64 | * Parameters for VCO frequency configuration | 84 | * Parameters for VCO frequency configuration |
65 | * | 85 | * |
66 | * VCO frequency = | 86 | * VCO frequency = |
@@ -149,6 +169,7 @@ struct iproc_pll_ctrl { | |||
149 | struct iproc_clk_reg_op pdiv; | 169 | struct iproc_clk_reg_op pdiv; |
150 | struct iproc_pll_vco_ctrl vco_ctrl; | 170 | struct iproc_pll_vco_ctrl vco_ctrl; |
151 | struct iproc_clk_reg_op status; | 171 | struct iproc_clk_reg_op status; |
172 | struct iproc_clk_reg_op macro_mode; | ||
152 | }; | 173 | }; |
153 | 174 | ||
154 | /* | 175 | /* |
diff --git a/include/dt-bindings/clock/bcm-cygnus.h b/include/dt-bindings/clock/bcm-cygnus.h index 32fbc475087a..62ac5d782a00 100644 --- a/include/dt-bindings/clock/bcm-cygnus.h +++ b/include/dt-bindings/clock/bcm-cygnus.h | |||
@@ -65,4 +65,10 @@ | |||
65 | #define BCM_CYGNUS_ASIU_ADC_CLK 1 | 65 | #define BCM_CYGNUS_ASIU_ADC_CLK 1 |
66 | #define BCM_CYGNUS_ASIU_PWM_CLK 2 | 66 | #define BCM_CYGNUS_ASIU_PWM_CLK 2 |
67 | 67 | ||
68 | /* AUDIO clock ID */ | ||
69 | #define BCM_CYGNUS_AUDIOPLL 0 | ||
70 | #define BCM_CYGNUS_AUDIOPLL_CH0 1 | ||
71 | #define BCM_CYGNUS_AUDIOPLL_CH1 2 | ||
72 | #define BCM_CYGNUS_AUDIOPLL_CH2 3 | ||
73 | |||
68 | #endif /* _CLOCK_BCM_CYGNUS_H */ | 74 | #endif /* _CLOCK_BCM_CYGNUS_H */ |