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

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