210-clk-sunxi-add-a20-output-clk.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. From 5ca9eadcb5f5cd9af6f1650029ad64052a1a0b10 Mon Sep 17 00:00:00 2001
  2. From: Chen-Yu Tsai <[email protected]>
  3. Date: Tue, 24 Dec 2013 21:26:17 +0800
  4. Subject: [PATCH] clk: sunxi: Allwinner A20 output clock support
  5. This patch adds support for the external clock outputs on the
  6. Allwinner A20 SoC. The clock outputs are similar to "module 0"
  7. type clocks, with different offsets and widths for clock factors.
  8. Signed-off-by: Chen-Yu Tsai <[email protected]>
  9. ---
  10. Documentation/devicetree/bindings/clock/sunxi.txt | 1 +
  11. drivers/clk/sunxi/clk-sunxi.c | 57 +++++++++++++++++++++++
  12. 2 files changed, 58 insertions(+)
  13. --- a/Documentation/devicetree/bindings/clock/sunxi.txt
  14. +++ b/Documentation/devicetree/bindings/clock/sunxi.txt
  15. @@ -37,6 +37,7 @@ Required properties:
  16. "allwinner,sun6i-a31-apb2-div-clk" - for the APB2 gates on A31
  17. "allwinner,sun6i-a31-apb2-gates-clk" - for the APB2 gates on A31
  18. "allwinner,sun4i-mod0-clk" - for the module 0 family of clocks
  19. + "allwinner,sun7i-a20-out-clk" - for the external output clocks
  20. Required properties for all clocks:
  21. - reg : shall be the control register address for the clock.
  22. --- a/drivers/clk/sunxi/clk-sunxi.c
  23. +++ b/drivers/clk/sunxi/clk-sunxi.c
  24. @@ -396,6 +396,47 @@ void clk_sunxi_mmc_phase_control(struct
  25. /**
  26. + * sun7i_a20_get_out_factors() - calculates m, p factors for CLK_OUT_A/B
  27. + * CLK_OUT rate is calculated as follows
  28. + * rate = (parent_rate >> p) / (m + 1);
  29. + */
  30. +
  31. +static void sun7i_a20_get_out_factors(u32 *freq, u32 parent_rate,
  32. + u8 *n, u8 *k, u8 *m, u8 *p)
  33. +{
  34. + u8 div, calcm, calcp;
  35. +
  36. + /* These clocks can only divide, so we will never be able to achieve
  37. + * frequencies higher than the parent frequency */
  38. + if (*freq > parent_rate)
  39. + *freq = parent_rate;
  40. +
  41. + div = parent_rate / *freq;
  42. +
  43. + if (div < 32)
  44. + calcp = 0;
  45. + else if (div / 2 < 32)
  46. + calcp = 1;
  47. + else if (div / 4 < 32)
  48. + calcp = 2;
  49. + else
  50. + calcp = 3;
  51. +
  52. + calcm = DIV_ROUND_UP(div, 1 << calcp);
  53. +
  54. + *freq = (parent_rate >> calcp) / calcm;
  55. +
  56. + /* we were called to round the frequency, we can now return */
  57. + if (n == NULL)
  58. + return;
  59. +
  60. + *m = calcm - 1;
  61. + *p = calcp;
  62. +}
  63. +
  64. +
  65. +
  66. +/**
  67. * sunxi_factors_clk_setup() - Setup function for factor clocks
  68. */
  69. @@ -455,6 +496,14 @@ static struct clk_factors_config sun4i_m
  70. .pwidth = 2,
  71. };
  72. +/* user manual says "n" but it's really "p" */
  73. +static struct clk_factors_config sun7i_a20_out_config = {
  74. + .mshift = 8,
  75. + .mwidth = 5,
  76. + .pshift = 20,
  77. + .pwidth = 2,
  78. +};
  79. +
  80. static const struct factors_data sun4i_pll1_data __initconst = {
  81. .enable = 31,
  82. .table = &sun4i_pll1_config,
  83. @@ -491,6 +540,13 @@ static const struct factors_data sun4i_m
  84. .getter = sun4i_get_mod0_factors,
  85. };
  86. +static const struct factors_data sun7i_a20_out_data __initconst = {
  87. + .enable = 31,
  88. + .mux = 24,
  89. + .table = &sun7i_a20_out_config,
  90. + .getter = sun7i_a20_get_out_factors,
  91. +};
  92. +
  93. static struct clk * __init sunxi_factors_clk_setup(struct device_node *node,
  94. const struct factors_data *data)
  95. {
  96. @@ -998,6 +1054,7 @@ static const struct of_device_id clk_fac
  97. {.compatible = "allwinner,sun5i-a13-ahb-clk", .data = &sun5i_a13_ahb_data,},
  98. {.compatible = "allwinner,sun4i-apb1-clk", .data = &sun4i_apb1_data,},
  99. {.compatible = "allwinner,sun4i-mod0-clk", .data = &sun4i_mod0_data,},
  100. + {.compatible = "allwinner,sun7i-a20-out-clk", .data = &sun7i_a20_out_data,},
  101. {}
  102. };