184-clk-sunxi-add-pll6-on-a31.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. From c225f78660cd61914f25dd00499c7ae71d1d6919 Mon Sep 17 00:00:00 2001
  2. From: Maxime Ripard <maxime.ripard@free-electrons.com>
  3. Date: Wed, 5 Feb 2014 14:05:03 +0100
  4. Subject: [PATCH] clk: sunxi: Add support for PLL6 on the A31
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. The A31 has a slightly different PLL6 clock. Add support for this new clock in
  9. our driver.
  10. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
  11. Signed-off-by: Emilio López <emilio@elopez.com.ar>
  12. ---
  13. Documentation/devicetree/bindings/clock/sunxi.txt | 1 +
  14. drivers/clk/sunxi/clk-sunxi.c | 45 +++++++++++++++++++++++
  15. 2 files changed, 46 insertions(+)
  16. --- a/Documentation/devicetree/bindings/clock/sunxi.txt
  17. +++ b/Documentation/devicetree/bindings/clock/sunxi.txt
  18. @@ -11,6 +11,7 @@ Required properties:
  19. "allwinner,sun6i-a31-pll1-clk" - for the main PLL clock on A31
  20. "allwinner,sun4i-pll5-clk" - for the PLL5 clock
  21. "allwinner,sun4i-pll6-clk" - for the PLL6 clock
  22. + "allwinner,sun6i-a31-pll6-clk" - for the PLL6 clock on A31
  23. "allwinner,sun4i-cpu-clk" - for the CPU multiplexer clock
  24. "allwinner,sun4i-axi-clk" - for the AXI clock
  25. "allwinner,sun4i-axi-gates-clk" - for the AXI gates
  26. --- a/drivers/clk/sunxi/clk-sunxi.c
  27. +++ b/drivers/clk/sunxi/clk-sunxi.c
  28. @@ -252,7 +252,38 @@ static void sun4i_get_pll5_factors(u32 *
  29. *n = DIV_ROUND_UP(div, (*k+1));
  30. }
  31. +/**
  32. + * sun6i_a31_get_pll6_factors() - calculates n, k factors for A31 PLL6
  33. + * PLL6 rate is calculated as follows
  34. + * rate = parent_rate * n * (k + 1) / 2
  35. + * parent_rate is always 24Mhz
  36. + */
  37. +
  38. +static void sun6i_a31_get_pll6_factors(u32 *freq, u32 parent_rate,
  39. + u8 *n, u8 *k, u8 *m, u8 *p)
  40. +{
  41. + u8 div;
  42. +
  43. + /*
  44. + * We always have 24MHz / 2, so we can just say that our
  45. + * parent clock is 12MHz.
  46. + */
  47. + parent_rate = parent_rate / 2;
  48. +
  49. + /* Normalize value to a parent_rate multiple (24M / 2) */
  50. + div = *freq / parent_rate;
  51. + *freq = parent_rate * div;
  52. +
  53. + /* we were called to round the frequency, we can now return */
  54. + if (n == NULL)
  55. + return;
  56. + *k = div / 32;
  57. + if (*k > 3)
  58. + *k = 3;
  59. +
  60. + *n = DIV_ROUND_UP(div, (*k+1));
  61. +}
  62. /**
  63. * sun4i_get_apb1_factors() - calculates m, p factors for APB1
  64. @@ -420,6 +451,13 @@ static struct clk_factors_config sun4i_p
  65. .kwidth = 2,
  66. };
  67. +static struct clk_factors_config sun6i_a31_pll6_config = {
  68. + .nshift = 8,
  69. + .nwidth = 5,
  70. + .kshift = 4,
  71. + .kwidth = 2,
  72. +};
  73. +
  74. static struct clk_factors_config sun4i_apb1_config = {
  75. .mshift = 0,
  76. .mwidth = 5,
  77. @@ -469,6 +507,12 @@ static const struct factors_data sun4i_p
  78. .name = "pll6",
  79. };
  80. +static const struct factors_data sun6i_a31_pll6_data __initconst = {
  81. + .enable = 31,
  82. + .table = &sun6i_a31_pll6_config,
  83. + .getter = sun6i_a31_get_pll6_factors,
  84. +};
  85. +
  86. static const struct factors_data sun4i_apb1_data __initconst = {
  87. .table = &sun4i_apb1_config,
  88. .getter = sun4i_get_apb1_factors,
  89. @@ -1069,6 +1113,7 @@ free_clkdata:
  90. static const struct of_device_id clk_factors_match[] __initconst = {
  91. {.compatible = "allwinner,sun4i-pll1-clk", .data = &sun4i_pll1_data,},
  92. {.compatible = "allwinner,sun6i-a31-pll1-clk", .data = &sun6i_a31_pll1_data,},
  93. + {.compatible = "allwinner,sun6i-a31-pll6-clk", .data = &sun6i_a31_pll6_data,},
  94. {.compatible = "allwinner,sun4i-apb1-clk", .data = &sun4i_apb1_data,},
  95. {.compatible = "allwinner,sun4i-mod0-clk", .data = &sun4i_mod0_data,},
  96. {.compatible = "allwinner,sun7i-a20-out-clk", .data = &sun7i_a20_out_data,},