clk-gating-ctrl.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * Marvell MVEBU clock gating control.
  3. *
  4. * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
  5. * Andrew Lunn <andrew@lunn.ch>
  6. *
  7. * This file is licensed under the terms of the GNU General Public
  8. * License version 2. This program is licensed "as is" without any
  9. * warranty of any kind, whether express or implied.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/bitops.h>
  13. #include <linux/io.h>
  14. #include <linux/clk.h>
  15. #include <linux/clkdev.h>
  16. #include <linux/clk-provider.h>
  17. #include <linux/clk/mvebu.h>
  18. #include <linux/of.h>
  19. #include <linux/of_address.h>
  20. struct mvebu_gating_ctrl {
  21. spinlock_t lock;
  22. struct clk **gates;
  23. int num_gates;
  24. };
  25. struct mvebu_soc_descr {
  26. const char *name;
  27. const char *parent;
  28. int bit_idx;
  29. unsigned long flags;
  30. };
  31. #define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
  32. static struct clk *mvebu_clk_gating_get_src(
  33. struct of_phandle_args *clkspec, void *data)
  34. {
  35. struct mvebu_gating_ctrl *ctrl = (struct mvebu_gating_ctrl *)data;
  36. int n;
  37. if (clkspec->args_count < 1)
  38. return ERR_PTR(-EINVAL);
  39. for (n = 0; n < ctrl->num_gates; n++) {
  40. struct clk_gate *gate =
  41. to_clk_gate(__clk_get_hw(ctrl->gates[n]));
  42. if (clkspec->args[0] == gate->bit_idx)
  43. return ctrl->gates[n];
  44. }
  45. return ERR_PTR(-ENODEV);
  46. }
  47. static void __init mvebu_clk_gating_setup(
  48. struct device_node *np, const struct mvebu_soc_descr *descr)
  49. {
  50. struct mvebu_gating_ctrl *ctrl;
  51. struct clk *clk;
  52. void __iomem *base;
  53. const char *default_parent = NULL;
  54. int n;
  55. base = of_iomap(np, 0);
  56. clk = of_clk_get(np, 0);
  57. if (!IS_ERR(clk)) {
  58. default_parent = __clk_get_name(clk);
  59. clk_put(clk);
  60. }
  61. ctrl = kzalloc(sizeof(struct mvebu_gating_ctrl), GFP_KERNEL);
  62. if (WARN_ON(!ctrl))
  63. return;
  64. spin_lock_init(&ctrl->lock);
  65. /*
  66. * Count, allocate, and register clock gates
  67. */
  68. for (n = 0; descr[n].name;)
  69. n++;
  70. ctrl->num_gates = n;
  71. ctrl->gates = kzalloc(ctrl->num_gates * sizeof(struct clk *),
  72. GFP_KERNEL);
  73. if (WARN_ON(!ctrl->gates)) {
  74. kfree(ctrl);
  75. return;
  76. }
  77. for (n = 0; n < ctrl->num_gates; n++) {
  78. const char *parent =
  79. (descr[n].parent) ? descr[n].parent : default_parent;
  80. ctrl->gates[n] = clk_register_gate(NULL, descr[n].name, parent,
  81. descr[n].flags, base, descr[n].bit_idx,
  82. 0, &ctrl->lock);
  83. WARN_ON(IS_ERR(ctrl->gates[n]));
  84. }
  85. of_clk_add_provider(np, mvebu_clk_gating_get_src, ctrl);
  86. }
  87. /*
  88. * SoC specific clock gating control
  89. */
  90. #ifdef CONFIG_MACH_ARMADA_370
  91. static const struct mvebu_soc_descr __initconst armada_370_gating_descr[] = {
  92. { "audio", NULL, 0, 0 },
  93. { "pex0_en", NULL, 1, 0 },
  94. { "pex1_en", NULL, 2, 0 },
  95. { "ge1", NULL, 3, 0 },
  96. { "ge0", NULL, 4, 0 },
  97. { "pex0", "pex0_en", 5, 0 },
  98. { "pex1", "pex1_en", 9, 0 },
  99. { "sata0", NULL, 15, 0 },
  100. { "sdio", NULL, 17, 0 },
  101. { "tdm", NULL, 25, 0 },
  102. { "ddr", NULL, 28, CLK_IGNORE_UNUSED },
  103. { "sata1", NULL, 30, 0 },
  104. { }
  105. };
  106. #endif
  107. #ifdef CONFIG_MACH_ARMADA_XP
  108. static const struct mvebu_soc_descr __initconst armada_xp_gating_descr[] = {
  109. { "audio", NULL, 0, 0 },
  110. { "ge3", NULL, 1, 0 },
  111. { "ge2", NULL, 2, 0 },
  112. { "ge1", NULL, 3, 0 },
  113. { "ge0", NULL, 4, 0 },
  114. { "pex00", NULL, 5, 0 },
  115. { "pex01", NULL, 6, 0 },
  116. { "pex02", NULL, 7, 0 },
  117. { "pex03", NULL, 8, 0 },
  118. { "pex10", NULL, 9, 0 },
  119. { "pex11", NULL, 10, 0 },
  120. { "pex12", NULL, 11, 0 },
  121. { "pex13", NULL, 12, 0 },
  122. { "bp", NULL, 13, 0 },
  123. { "sata0lnk", NULL, 14, 0 },
  124. { "sata0", "sata0lnk", 15, 0 },
  125. { "lcd", NULL, 16, 0 },
  126. { "sdio", NULL, 17, 0 },
  127. { "usb0", NULL, 18, 0 },
  128. { "usb1", NULL, 19, 0 },
  129. { "usb2", NULL, 20, 0 },
  130. { "xor0", NULL, 22, 0 },
  131. { "crypto", NULL, 23, 0 },
  132. { "tdm", NULL, 25, 0 },
  133. { "pex20", NULL, 26, 0 },
  134. { "pex30", NULL, 27, 0 },
  135. { "xor1", NULL, 28, 0 },
  136. { "sata1lnk", NULL, 29, 0 },
  137. { "sata1", "sata1lnk", 30, 0 },
  138. { }
  139. };
  140. #endif
  141. #ifdef CONFIG_ARCH_DOVE
  142. static const struct mvebu_soc_descr __initconst dove_gating_descr[] = {
  143. { "usb0", NULL, 0, 0 },
  144. { "usb1", NULL, 1, 0 },
  145. { "ge", "gephy", 2, 0 },
  146. { "sata", NULL, 3, 0 },
  147. { "pex0", NULL, 4, 0 },
  148. { "pex1", NULL, 5, 0 },
  149. { "sdio0", NULL, 8, 0 },
  150. { "sdio1", NULL, 9, 0 },
  151. { "nand", NULL, 10, 0 },
  152. { "camera", NULL, 11, 0 },
  153. { "i2s0", NULL, 12, 0 },
  154. { "i2s1", NULL, 13, 0 },
  155. { "crypto", NULL, 15, 0 },
  156. { "ac97", NULL, 21, 0 },
  157. { "pdma", NULL, 22, 0 },
  158. { "xor0", NULL, 23, 0 },
  159. { "xor1", NULL, 24, 0 },
  160. { "gephy", NULL, 30, 0 },
  161. { }
  162. };
  163. #endif
  164. #ifdef CONFIG_ARCH_KIRKWOOD
  165. static const struct mvebu_soc_descr __initconst kirkwood_gating_descr[] = {
  166. { "ge0", NULL, 0, 0 },
  167. { "pex0", NULL, 2, 0 },
  168. { "usb0", NULL, 3, 0 },
  169. { "sdio", NULL, 4, 0 },
  170. { "tsu", NULL, 5, 0 },
  171. { "runit", NULL, 7, 0 },
  172. { "xor0", NULL, 8, 0 },
  173. { "audio", NULL, 9, 0 },
  174. { "powersave", "cpuclk", 11, 0 },
  175. { "sata0", NULL, 14, 0 },
  176. { "sata1", NULL, 15, 0 },
  177. { "xor1", NULL, 16, 0 },
  178. { "crypto", NULL, 17, 0 },
  179. { "pex1", NULL, 18, 0 },
  180. { "ge1", NULL, 19, 0 },
  181. { "tdm", NULL, 20, 0 },
  182. { }
  183. };
  184. #endif
  185. static const __initdata struct of_device_id clk_gating_match[] = {
  186. #ifdef CONFIG_MACH_ARMADA_370
  187. {
  188. .compatible = "marvell,armada-370-gating-clock",
  189. .data = armada_370_gating_descr,
  190. },
  191. #endif
  192. #ifdef CONFIG_MACH_ARMADA_XP
  193. {
  194. .compatible = "marvell,armada-xp-gating-clock",
  195. .data = armada_xp_gating_descr,
  196. },
  197. #endif
  198. #ifdef CONFIG_ARCH_DOVE
  199. {
  200. .compatible = "marvell,dove-gating-clock",
  201. .data = dove_gating_descr,
  202. },
  203. #endif
  204. #ifdef CONFIG_ARCH_KIRKWOOD
  205. {
  206. .compatible = "marvell,kirkwood-gating-clock",
  207. .data = kirkwood_gating_descr,
  208. },
  209. #endif
  210. { }
  211. };
  212. void __init mvebu_gating_clk_init(void)
  213. {
  214. struct device_node *np;
  215. for_each_matching_node(np, clk_gating_match) {
  216. const struct of_device_id *match =
  217. of_match_node(clk_gating_match, np);
  218. mvebu_clk_gating_setup(np,
  219. (const struct mvebu_soc_descr *)match->data);
  220. }
  221. }