0259-clk-bcm2835-remove-use-of-BCM2835_CLOCK_COUNT-in-dri.patch 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. From 67071edadb9965b7c9a36443c5d6e6808dfae8d9 Mon Sep 17 00:00:00 2001
  2. From: Martin Sperl <kernel@martin.sperl.org>
  3. Date: Mon, 29 Feb 2016 12:51:41 +0000
  4. Subject: [PATCH] clk: bcm2835: remove use of BCM2835_CLOCK_COUNT in driver
  5. As the use of BCM2835_CLOCK_COUNT in
  6. include/dt-bindings/clock/bcm2835.h is frowned upon as
  7. it needs to get modified every time a new clock gets introduced
  8. this patch changes the clk-bcm2835 driver to use a different
  9. scheme for registration of clocks and pll, so that there
  10. is no more need for BCM2835_CLOCK_COUNT to be defined.
  11. Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
  12. Signed-off-by: Eric Anholt <eric@anholt.net>
  13. Reviewed-by: Eric Anholt <eric@anholt.net>
  14. (cherry picked from commit 56eb3a2ed9726961e1bcfa69d4a3f86d68f0eb52)
  15. ---
  16. drivers/clk/bcm/clk-bcm2835.c | 167 ++++++++++++++++++++----------------
  17. include/dt-bindings/clock/bcm2835.h | 2 -
  18. 2 files changed, 94 insertions(+), 75 deletions(-)
  19. --- a/drivers/clk/bcm/clk-bcm2835.c
  20. +++ b/drivers/clk/bcm/clk-bcm2835.c
  21. @@ -301,7 +301,7 @@ struct bcm2835_cprman {
  22. const char *osc_name;
  23. struct clk_onecell_data onecell;
  24. - struct clk *clks[BCM2835_CLOCK_COUNT];
  25. + struct clk *clks[];
  26. };
  27. static inline void cprman_write(struct bcm2835_cprman *cprman, u32 reg, u32 val)
  28. @@ -853,6 +853,25 @@ static const struct bcm2835_clock_data b
  29. .is_mash_clock = true,
  30. };
  31. +struct bcm2835_gate_data {
  32. + const char *name;
  33. + const char *parent;
  34. +
  35. + u32 ctl_reg;
  36. +};
  37. +
  38. +/*
  39. + * CM_PERIICTL (and CM_PERIACTL, CM_SYSCTL and CM_VPUCTL if
  40. + * you have the debug bit set in the power manager, which we
  41. + * don't bother exposing) are individual gates off of the
  42. + * non-stop vpu clock.
  43. + */
  44. +static const struct bcm2835_gate_data bcm2835_clock_peri_image_data = {
  45. + .name = "peri_image",
  46. + .parent = "vpu",
  47. + .ctl_reg = CM_PERIICTL,
  48. +};
  49. +
  50. struct bcm2835_pll {
  51. struct clk_hw hw;
  52. struct bcm2835_cprman *cprman;
  53. @@ -1666,14 +1685,81 @@ static struct clk *bcm2835_register_cloc
  54. return devm_clk_register(cprman->dev, &clock->hw);
  55. }
  56. +static struct clk *bcm2835_register_gate(struct bcm2835_cprman *cprman,
  57. + const struct bcm2835_gate_data *data)
  58. +{
  59. + return clk_register_gate(cprman->dev, data->name, data->parent,
  60. + CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
  61. + cprman->regs + data->ctl_reg,
  62. + CM_GATE_BIT, 0, &cprman->regs_lock);
  63. +}
  64. +
  65. +typedef struct clk *(*bcm2835_clk_register)(struct bcm2835_cprman *cprman,
  66. + const void *data);
  67. +struct bcm2835_clk_desc {
  68. + bcm2835_clk_register clk_register;
  69. + const void *data;
  70. +};
  71. +
  72. +#define _REGISTER(f, d) { .clk_register = (bcm2835_clk_register)f, \
  73. + .data = d }
  74. +#define REGISTER_PLL(d) _REGISTER(&bcm2835_register_pll, d)
  75. +#define REGISTER_PLL_DIV(d) _REGISTER(&bcm2835_register_pll_divider, d)
  76. +#define REGISTER_CLK(d) _REGISTER(&bcm2835_register_clock, d)
  77. +#define REGISTER_GATE(d) _REGISTER(&bcm2835_register_gate, d)
  78. +
  79. +static const struct bcm2835_clk_desc clk_desc_array[] = {
  80. + /* register PLL */
  81. + [BCM2835_PLLA] = REGISTER_PLL(&bcm2835_plla_data),
  82. + [BCM2835_PLLB] = REGISTER_PLL(&bcm2835_pllb_data),
  83. + [BCM2835_PLLC] = REGISTER_PLL(&bcm2835_pllc_data),
  84. + [BCM2835_PLLD] = REGISTER_PLL(&bcm2835_plld_data),
  85. + [BCM2835_PLLH] = REGISTER_PLL(&bcm2835_pllh_data),
  86. + /* the PLL dividers */
  87. + [BCM2835_PLLA_CORE] = REGISTER_PLL_DIV(&bcm2835_plla_core_data),
  88. + [BCM2835_PLLA_PER] = REGISTER_PLL_DIV(&bcm2835_plla_per_data),
  89. + [BCM2835_PLLC_CORE0] = REGISTER_PLL_DIV(&bcm2835_pllc_core0_data),
  90. + [BCM2835_PLLC_CORE1] = REGISTER_PLL_DIV(&bcm2835_pllc_core1_data),
  91. + [BCM2835_PLLC_CORE2] = REGISTER_PLL_DIV(&bcm2835_pllc_core2_data),
  92. + [BCM2835_PLLC_PER] = REGISTER_PLL_DIV(&bcm2835_pllc_per_data),
  93. + [BCM2835_PLLD_CORE] = REGISTER_PLL_DIV(&bcm2835_plld_core_data),
  94. + [BCM2835_PLLD_PER] = REGISTER_PLL_DIV(&bcm2835_plld_per_data),
  95. + [BCM2835_PLLH_RCAL] = REGISTER_PLL_DIV(&bcm2835_pllh_rcal_data),
  96. + [BCM2835_PLLH_AUX] = REGISTER_PLL_DIV(&bcm2835_pllh_aux_data),
  97. + [BCM2835_PLLH_PIX] = REGISTER_PLL_DIV(&bcm2835_pllh_pix_data),
  98. + /* the clocks */
  99. + [BCM2835_CLOCK_TIMER] = REGISTER_CLK(&bcm2835_clock_timer_data),
  100. + [BCM2835_CLOCK_OTP] = REGISTER_CLK(&bcm2835_clock_otp_data),
  101. + [BCM2835_CLOCK_TSENS] = REGISTER_CLK(&bcm2835_clock_tsens_data),
  102. + [BCM2835_CLOCK_VPU] = REGISTER_CLK(&bcm2835_clock_vpu_data),
  103. + [BCM2835_CLOCK_V3D] = REGISTER_CLK(&bcm2835_clock_v3d_data),
  104. + [BCM2835_CLOCK_ISP] = REGISTER_CLK(&bcm2835_clock_isp_data),
  105. + [BCM2835_CLOCK_H264] = REGISTER_CLK(&bcm2835_clock_h264_data),
  106. + [BCM2835_CLOCK_V3D] = REGISTER_CLK(&bcm2835_clock_v3d_data),
  107. + [BCM2835_CLOCK_SDRAM] = REGISTER_CLK(&bcm2835_clock_sdram_data),
  108. + [BCM2835_CLOCK_UART] = REGISTER_CLK(&bcm2835_clock_uart_data),
  109. + [BCM2835_CLOCK_VEC] = REGISTER_CLK(&bcm2835_clock_vec_data),
  110. + [BCM2835_CLOCK_HSM] = REGISTER_CLK(&bcm2835_clock_hsm_data),
  111. + [BCM2835_CLOCK_EMMC] = REGISTER_CLK(&bcm2835_clock_emmc_data),
  112. + [BCM2835_CLOCK_PWM] = REGISTER_CLK(&bcm2835_clock_pwm_data),
  113. + /* the gates */
  114. + [BCM2835_CLOCK_PERI_IMAGE] = REGISTER_GATE(
  115. + &bcm2835_clock_peri_image_data),
  116. +};
  117. +
  118. static int bcm2835_clk_probe(struct platform_device *pdev)
  119. {
  120. struct device *dev = &pdev->dev;
  121. struct clk **clks;
  122. struct bcm2835_cprman *cprman;
  123. struct resource *res;
  124. + const struct bcm2835_clk_desc *desc;
  125. + const size_t asize = ARRAY_SIZE(clk_desc_array);
  126. + size_t i;
  127. - cprman = devm_kzalloc(dev, sizeof(*cprman), GFP_KERNEL);
  128. + cprman = devm_kzalloc(dev,
  129. + sizeof(*cprman) + asize * sizeof(*clks),
  130. + GFP_KERNEL);
  131. if (!cprman)
  132. return -ENOMEM;
  133. @@ -1690,80 +1776,15 @@ static int bcm2835_clk_probe(struct plat
  134. platform_set_drvdata(pdev, cprman);
  135. - cprman->onecell.clk_num = BCM2835_CLOCK_COUNT;
  136. + cprman->onecell.clk_num = asize;
  137. cprman->onecell.clks = cprman->clks;
  138. clks = cprman->clks;
  139. - clks[BCM2835_PLLA] = bcm2835_register_pll(cprman, &bcm2835_plla_data);
  140. - clks[BCM2835_PLLB] = bcm2835_register_pll(cprman, &bcm2835_pllb_data);
  141. - clks[BCM2835_PLLC] = bcm2835_register_pll(cprman, &bcm2835_pllc_data);
  142. - clks[BCM2835_PLLD] = bcm2835_register_pll(cprman, &bcm2835_plld_data);
  143. - clks[BCM2835_PLLH] = bcm2835_register_pll(cprman, &bcm2835_pllh_data);
  144. -
  145. - clks[BCM2835_PLLA_CORE] =
  146. - bcm2835_register_pll_divider(cprman, &bcm2835_plla_core_data);
  147. - clks[BCM2835_PLLA_PER] =
  148. - bcm2835_register_pll_divider(cprman, &bcm2835_plla_per_data);
  149. - clks[BCM2835_PLLC_CORE0] =
  150. - bcm2835_register_pll_divider(cprman, &bcm2835_pllc_core0_data);
  151. - clks[BCM2835_PLLC_CORE1] =
  152. - bcm2835_register_pll_divider(cprman, &bcm2835_pllc_core1_data);
  153. - clks[BCM2835_PLLC_CORE2] =
  154. - bcm2835_register_pll_divider(cprman, &bcm2835_pllc_core2_data);
  155. - clks[BCM2835_PLLC_PER] =
  156. - bcm2835_register_pll_divider(cprman, &bcm2835_pllc_per_data);
  157. - clks[BCM2835_PLLD_CORE] =
  158. - bcm2835_register_pll_divider(cprman, &bcm2835_plld_core_data);
  159. - clks[BCM2835_PLLD_PER] =
  160. - bcm2835_register_pll_divider(cprman, &bcm2835_plld_per_data);
  161. - clks[BCM2835_PLLH_RCAL] =
  162. - bcm2835_register_pll_divider(cprman, &bcm2835_pllh_rcal_data);
  163. - clks[BCM2835_PLLH_AUX] =
  164. - bcm2835_register_pll_divider(cprman, &bcm2835_pllh_aux_data);
  165. - clks[BCM2835_PLLH_PIX] =
  166. - bcm2835_register_pll_divider(cprman, &bcm2835_pllh_pix_data);
  167. -
  168. - clks[BCM2835_CLOCK_TIMER] =
  169. - bcm2835_register_clock(cprman, &bcm2835_clock_timer_data);
  170. - clks[BCM2835_CLOCK_OTP] =
  171. - bcm2835_register_clock(cprman, &bcm2835_clock_otp_data);
  172. - clks[BCM2835_CLOCK_TSENS] =
  173. - bcm2835_register_clock(cprman, &bcm2835_clock_tsens_data);
  174. - clks[BCM2835_CLOCK_VPU] =
  175. - bcm2835_register_clock(cprman, &bcm2835_clock_vpu_data);
  176. - clks[BCM2835_CLOCK_V3D] =
  177. - bcm2835_register_clock(cprman, &bcm2835_clock_v3d_data);
  178. - clks[BCM2835_CLOCK_ISP] =
  179. - bcm2835_register_clock(cprman, &bcm2835_clock_isp_data);
  180. - clks[BCM2835_CLOCK_H264] =
  181. - bcm2835_register_clock(cprman, &bcm2835_clock_h264_data);
  182. - clks[BCM2835_CLOCK_V3D] =
  183. - bcm2835_register_clock(cprman, &bcm2835_clock_v3d_data);
  184. - clks[BCM2835_CLOCK_SDRAM] =
  185. - bcm2835_register_clock(cprman, &bcm2835_clock_sdram_data);
  186. - clks[BCM2835_CLOCK_UART] =
  187. - bcm2835_register_clock(cprman, &bcm2835_clock_uart_data);
  188. - clks[BCM2835_CLOCK_VEC] =
  189. - bcm2835_register_clock(cprman, &bcm2835_clock_vec_data);
  190. - clks[BCM2835_CLOCK_HSM] =
  191. - bcm2835_register_clock(cprman, &bcm2835_clock_hsm_data);
  192. - clks[BCM2835_CLOCK_EMMC] =
  193. - bcm2835_register_clock(cprman, &bcm2835_clock_emmc_data);
  194. -
  195. - /*
  196. - * CM_PERIICTL (and CM_PERIACTL, CM_SYSCTL and CM_VPUCTL if
  197. - * you have the debug bit set in the power manager, which we
  198. - * don't bother exposing) are individual gates off of the
  199. - * non-stop vpu clock.
  200. - */
  201. - clks[BCM2835_CLOCK_PERI_IMAGE] =
  202. - clk_register_gate(dev, "peri_image", "vpu",
  203. - CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
  204. - cprman->regs + CM_PERIICTL, CM_GATE_BIT,
  205. - 0, &cprman->regs_lock);
  206. -
  207. - clks[BCM2835_CLOCK_PWM] =
  208. - bcm2835_register_clock(cprman, &bcm2835_clock_pwm_data);
  209. + for (i = 0; i < asize; i++) {
  210. + desc = &clk_desc_array[i];
  211. + if (desc->clk_register && desc->data)
  212. + clks[i] = desc->clk_register(cprman, desc->data);
  213. + }
  214. return of_clk_add_provider(dev->of_node, of_clk_src_onecell_get,
  215. &cprman->onecell);
  216. --- a/include/dt-bindings/clock/bcm2835.h
  217. +++ b/include/dt-bindings/clock/bcm2835.h
  218. @@ -44,5 +44,3 @@
  219. #define BCM2835_CLOCK_EMMC 28
  220. #define BCM2835_CLOCK_PERI_IMAGE 29
  221. #define BCM2835_CLOCK_PWM 30
  222. -
  223. -#define BCM2835_CLOCK_COUNT 31