aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clk/clk-vt8500.c
diff options
context:
space:
mode:
authorTony Prisk <linux@prisktech.co.nz>2012-12-27 20:24:41 -0500
committerMike Turquette <mturquette@linaro.org>2013-01-15 19:16:25 -0500
commitabb165a80b42a5dd6ca001597422f0d28b2cd59a (patch)
treed747ff2399970635b902ad9c910b8b2a5ff86129 /drivers/clk/clk-vt8500.c
parent58eb5a6763deab71208fbff15b09055fac884b11 (diff)
clk: vt8500: Add support for WM8750/WM8850 PLL clocks
This patch adds support for the new PLL module found in WM8750 and WM8850 SoCs. Signed-off-by: Tony Prisk <linux@prisktech.co.nz> Signed-off-by: Mike Turquette <mturquette@linaro.org>
Diffstat (limited to 'drivers/clk/clk-vt8500.c')
-rw-r--r--drivers/clk/clk-vt8500.c102
1 files changed, 100 insertions, 2 deletions
diff --git a/drivers/clk/clk-vt8500.c b/drivers/clk/clk-vt8500.c
index db7d41f25046..2515d4f31758 100644
--- a/drivers/clk/clk-vt8500.c
+++ b/drivers/clk/clk-vt8500.c
@@ -41,6 +41,7 @@ struct clk_device {
41 41
42#define PLL_TYPE_VT8500 0 42#define PLL_TYPE_VT8500 0
43#define PLL_TYPE_WM8650 1 43#define PLL_TYPE_WM8650 1
44#define PLL_TYPE_WM8750 2
44 45
45struct clk_pll { 46struct clk_pll {
46 struct clk_hw hw; 47 struct clk_hw hw;
@@ -316,6 +317,16 @@ static __init void vtwm_device_clk_init(struct device_node *node)
316#define WM8650_BITS_TO_VAL(m, d1, d2) \ 317#define WM8650_BITS_TO_VAL(m, d1, d2) \
317 ((d2 << 13) | (d1 << 10) | (m & 0x3FF)) 318 ((d2 << 13) | (d1 << 10) | (m & 0x3FF))
318 319
320/* Helper macros for PLL_WM8750 */
321#define WM8750_PLL_MUL(x) (((x >> 16) & 0xFF) + 1)
322#define WM8750_PLL_DIV(x) ((((x >> 8) & 1) + 1) * (1 << (x & 7)))
323
324#define WM8750_BITS_TO_FREQ(r, m, d1, d2) \
325 (r * (m+1) / ((d1+1) * (1 << d2)))
326
327#define WM8750_BITS_TO_VAL(f, m, d1, d2) \
328 ((f << 24) | ((m - 1) << 16) | ((d1 - 1) << 8) | d2)
329
319 330
320static void vt8500_find_pll_bits(unsigned long rate, unsigned long parent_rate, 331static void vt8500_find_pll_bits(unsigned long rate, unsigned long parent_rate,
321 u32 *multiplier, u32 *prediv) 332 u32 *multiplier, u32 *prediv)
@@ -384,11 +395,82 @@ static void wm8650_find_pll_bits(unsigned long rate, unsigned long parent_rate,
384 *divisor2 = best_div2; 395 *divisor2 = best_div2;
385} 396}
386 397
398static u32 wm8750_get_filter(u32 parent_rate, u32 divisor1)
399{
400 /* calculate frequency (MHz) after pre-divisor */
401 u32 freq = (parent_rate / 1000000) / (divisor1 + 1);
402
403 if ((freq < 10) || (freq > 200))
404 pr_warn("%s: PLL recommended input frequency 10..200Mhz (requested %d Mhz)\n",
405 __func__, freq);
406
407 if (freq >= 166)
408 return 7;
409 else if (freq >= 104)
410 return 6;
411 else if (freq >= 65)
412 return 5;
413 else if (freq >= 42)
414 return 4;
415 else if (freq >= 26)
416 return 3;
417 else if (freq >= 16)
418 return 2;
419 else if (freq >= 10)
420 return 1;
421
422 return 0;
423}
424
425static void wm8750_find_pll_bits(unsigned long rate, unsigned long parent_rate,
426 u32 *filter, u32 *multiplier, u32 *divisor1, u32 *divisor2)
427{
428 u32 mul, div1, div2;
429 u32 best_mul, best_div1, best_div2;
430 unsigned long tclk, rate_err, best_err;
431
432 best_err = (unsigned long)-1;
433
434 /* Find the closest match (lower or equal to requested) */
435 for (div1 = 1; div1 >= 0; div1--)
436 for (div2 = 7; div2 >= 0; div2--)
437 for (mul = 0; mul <= 255; mul++) {
438 tclk = parent_rate * (mul + 1) / ((div1 + 1) * (1 << div2));
439 if (tclk > rate)
440 continue;
441 /* error will always be +ve */
442 rate_err = rate - tclk;
443 if (rate_err == 0) {
444 *filter = wm8750_get_filter(parent_rate, div1);
445 *multiplier = mul;
446 *divisor1 = div1;
447 *divisor2 = div2;
448 return;
449 }
450
451 if (rate_err < best_err) {
452 best_err = rate_err;
453 best_mul = mul;
454 best_div1 = div1;
455 best_div2 = div2;
456 }
457 }
458
459 /* if we got here, it wasn't an exact match */
460 pr_warn("%s: requested rate %lu, found rate %lu\n", __func__, rate,
461 rate - best_err);
462
463 *filter = wm8750_get_filter(parent_rate, best_div1);
464 *multiplier = best_mul;
465 *divisor1 = best_div1;
466 *divisor2 = best_div2;
467}
468
387static int vtwm_pll_set_rate(struct clk_hw *hw, unsigned long rate, 469static int vtwm_pll_set_rate(struct clk_hw *hw, unsigned long rate,
388 unsigned long parent_rate) 470 unsigned long parent_rate)
389{ 471{
390 struct clk_pll *pll = to_clk_pll(hw); 472 struct clk_pll *pll = to_clk_pll(hw);
391 u32 mul, div1, div2; 473 u32 filter, mul, div1, div2;
392 u32 pll_val; 474 u32 pll_val;
393 unsigned long flags = 0; 475 unsigned long flags = 0;
394 476
@@ -403,6 +485,9 @@ static int vtwm_pll_set_rate(struct clk_hw *hw, unsigned long rate,
403 wm8650_find_pll_bits(rate, parent_rate, &mul, &div1, &div2); 485 wm8650_find_pll_bits(rate, parent_rate, &mul, &div1, &div2);
404 pll_val = WM8650_BITS_TO_VAL(mul, div1, div2); 486 pll_val = WM8650_BITS_TO_VAL(mul, div1, div2);
405 break; 487 break;
488 case PLL_TYPE_WM8750:
489 wm8750_find_pll_bits(rate, parent_rate, &filter, &mul, &div1, &div2);
490 pll_val = WM8750_BITS_TO_VAL(filter, mul, div1, div2);
406 default: 491 default:
407 pr_err("%s: invalid pll type\n", __func__); 492 pr_err("%s: invalid pll type\n", __func__);
408 return 0; 493 return 0;
@@ -423,7 +508,7 @@ static long vtwm_pll_round_rate(struct clk_hw *hw, unsigned long rate,
423 unsigned long *prate) 508 unsigned long *prate)
424{ 509{
425 struct clk_pll *pll = to_clk_pll(hw); 510 struct clk_pll *pll = to_clk_pll(hw);
426 u32 mul, div1, div2; 511 u32 filter, mul, div1, div2;
427 long round_rate; 512 long round_rate;
428 513
429 switch (pll->type) { 514 switch (pll->type) {
@@ -435,6 +520,9 @@ static long vtwm_pll_round_rate(struct clk_hw *hw, unsigned long rate,
435 wm8650_find_pll_bits(rate, *prate, &mul, &div1, &div2); 520 wm8650_find_pll_bits(rate, *prate, &mul, &div1, &div2);
436 round_rate = WM8650_BITS_TO_FREQ(*prate, mul, div1, div2); 521 round_rate = WM8650_BITS_TO_FREQ(*prate, mul, div1, div2);
437 break; 522 break;
523 case PLL_TYPE_WM8750:
524 wm8750_find_pll_bits(rate, *prate, &filter, &mul, &div1, &div2);
525 round_rate = WM8750_BITS_TO_FREQ(*prate, mul, div1, div2);
438 default: 526 default:
439 round_rate = 0; 527 round_rate = 0;
440 } 528 }
@@ -458,6 +546,10 @@ static unsigned long vtwm_pll_recalc_rate(struct clk_hw *hw,
458 pll_freq = parent_rate * WM8650_PLL_MUL(pll_val); 546 pll_freq = parent_rate * WM8650_PLL_MUL(pll_val);
459 pll_freq /= WM8650_PLL_DIV(pll_val); 547 pll_freq /= WM8650_PLL_DIV(pll_val);
460 break; 548 break;
549 case PLL_TYPE_WM8750:
550 pll_freq = parent_rate * WM8750_PLL_MUL(pll_val);
551 pll_freq /= WM8750_PLL_DIV(pll_val);
552 break;
461 default: 553 default:
462 pll_freq = 0; 554 pll_freq = 0;
463 } 555 }
@@ -526,10 +618,16 @@ static void __init wm8650_pll_init(struct device_node *node)
526 vtwm_pll_clk_init(node, PLL_TYPE_WM8650); 618 vtwm_pll_clk_init(node, PLL_TYPE_WM8650);
527} 619}
528 620
621static void __init wm8750_pll_init(struct device_node *node)
622{
623 vtwm_pll_clk_init(node, PLL_TYPE_WM8750);
624}
625
529static const __initconst struct of_device_id clk_match[] = { 626static const __initconst struct of_device_id clk_match[] = {
530 { .compatible = "fixed-clock", .data = of_fixed_clk_setup, }, 627 { .compatible = "fixed-clock", .data = of_fixed_clk_setup, },
531 { .compatible = "via,vt8500-pll-clock", .data = vt8500_pll_init, }, 628 { .compatible = "via,vt8500-pll-clock", .data = vt8500_pll_init, },
532 { .compatible = "wm,wm8650-pll-clock", .data = wm8650_pll_init, }, 629 { .compatible = "wm,wm8650-pll-clock", .data = wm8650_pll_init, },
630 { .compatible = "wm,wm8750-pll-clock", .data = wm8750_pll_init, },
533 { .compatible = "via,vt8500-device-clock", 631 { .compatible = "via,vt8500-device-clock",
534 .data = vtwm_device_clk_init, }, 632 .data = vtwm_device_clk_init, },
535 { /* sentinel */ } 633 { /* sentinel */ }