gate.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * OMAP gate clock support
  3. *
  4. * Copyright (C) 2013 Texas Instruments, Inc.
  5. *
  6. * Tero Kristo <t-kristo@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  13. * kind, whether express or implied; without even the implied warranty
  14. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/clk-provider.h>
  18. #include <linux/slab.h>
  19. #include <linux/io.h>
  20. #include <linux/of.h>
  21. #include <linux/of_address.h>
  22. #include <linux/clk/ti.h>
  23. #define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
  24. #undef pr_fmt
  25. #define pr_fmt(fmt) "%s: " fmt, __func__
  26. static int omap36xx_gate_clk_enable_with_hsdiv_restore(struct clk_hw *clk);
  27. static const struct clk_ops omap_gate_clkdm_clk_ops = {
  28. .init = &omap2_init_clk_clkdm,
  29. .enable = &omap2_clkops_enable_clkdm,
  30. .disable = &omap2_clkops_disable_clkdm,
  31. };
  32. static const struct clk_ops omap_gate_clk_ops = {
  33. .init = &omap2_init_clk_clkdm,
  34. .enable = &omap2_dflt_clk_enable,
  35. .disable = &omap2_dflt_clk_disable,
  36. .is_enabled = &omap2_dflt_clk_is_enabled,
  37. };
  38. static const struct clk_ops omap_gate_clk_hsdiv_restore_ops = {
  39. .init = &omap2_init_clk_clkdm,
  40. .enable = &omap36xx_gate_clk_enable_with_hsdiv_restore,
  41. .disable = &omap2_dflt_clk_disable,
  42. .is_enabled = &omap2_dflt_clk_is_enabled,
  43. };
  44. /**
  45. * omap36xx_gate_clk_enable_with_hsdiv_restore - enable clocks suffering
  46. * from HSDivider PWRDN problem Implements Errata ID: i556.
  47. * @clk: DPLL output struct clk
  48. *
  49. * 3630 only: dpll3_m3_ck, dpll4_m2_ck, dpll4_m3_ck, dpll4_m4_ck,
  50. * dpll4_m5_ck & dpll4_m6_ck dividers gets loaded with reset
  51. * valueafter their respective PWRDN bits are set. Any dummy write
  52. * (Any other value different from the Read value) to the
  53. * corresponding CM_CLKSEL register will refresh the dividers.
  54. */
  55. static int omap36xx_gate_clk_enable_with_hsdiv_restore(struct clk_hw *clk)
  56. {
  57. struct clk_divider *parent;
  58. struct clk_hw *parent_hw;
  59. u32 dummy_v, orig_v;
  60. int ret;
  61. /* Clear PWRDN bit of HSDIVIDER */
  62. ret = omap2_dflt_clk_enable(clk);
  63. /* Parent is the x2 node, get parent of parent for the m2 div */
  64. parent_hw = __clk_get_hw(__clk_get_parent(__clk_get_parent(clk->clk)));
  65. parent = to_clk_divider(parent_hw);
  66. /* Restore the dividers */
  67. if (!ret) {
  68. orig_v = ti_clk_ll_ops->clk_readl(parent->reg);
  69. dummy_v = orig_v;
  70. /* Write any other value different from the Read value */
  71. dummy_v ^= (1 << parent->shift);
  72. ti_clk_ll_ops->clk_writel(dummy_v, parent->reg);
  73. /* Write the original divider */
  74. ti_clk_ll_ops->clk_writel(orig_v, parent->reg);
  75. }
  76. return ret;
  77. }
  78. static void __init _of_ti_gate_clk_setup(struct device_node *node,
  79. const struct clk_ops *ops,
  80. const struct clk_hw_omap_ops *hw_ops)
  81. {
  82. struct clk *clk;
  83. struct clk_init_data init = { NULL };
  84. struct clk_hw_omap *clk_hw;
  85. const char *clk_name = node->name;
  86. const char *parent_name;
  87. u32 val;
  88. clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
  89. if (!clk_hw)
  90. return;
  91. clk_hw->hw.init = &init;
  92. init.name = clk_name;
  93. init.ops = ops;
  94. if (ops != &omap_gate_clkdm_clk_ops) {
  95. clk_hw->enable_reg = ti_clk_get_reg_addr(node, 0);
  96. if (!clk_hw->enable_reg)
  97. goto cleanup;
  98. if (!of_property_read_u32(node, "ti,bit-shift", &val))
  99. clk_hw->enable_bit = val;
  100. }
  101. clk_hw->ops = hw_ops;
  102. clk_hw->flags = MEMMAP_ADDRESSING;
  103. if (of_clk_get_parent_count(node) != 1) {
  104. pr_err("%s must have 1 parent\n", clk_name);
  105. goto cleanup;
  106. }
  107. parent_name = of_clk_get_parent_name(node, 0);
  108. init.parent_names = &parent_name;
  109. init.num_parents = 1;
  110. if (of_property_read_bool(node, "ti,set-rate-parent"))
  111. init.flags |= CLK_SET_RATE_PARENT;
  112. if (of_property_read_bool(node, "ti,set-bit-to-disable"))
  113. clk_hw->flags |= INVERT_ENABLE;
  114. clk = clk_register(NULL, &clk_hw->hw);
  115. if (!IS_ERR(clk)) {
  116. of_clk_add_provider(node, of_clk_src_simple_get, clk);
  117. return;
  118. }
  119. cleanup:
  120. kfree(clk_hw);
  121. }
  122. static void __init
  123. _of_ti_composite_gate_clk_setup(struct device_node *node,
  124. const struct clk_hw_omap_ops *hw_ops)
  125. {
  126. struct clk_hw_omap *gate;
  127. u32 val = 0;
  128. gate = kzalloc(sizeof(*gate), GFP_KERNEL);
  129. if (!gate)
  130. return;
  131. gate->enable_reg = ti_clk_get_reg_addr(node, 0);
  132. if (!gate->enable_reg)
  133. goto cleanup;
  134. of_property_read_u32(node, "ti,bit-shift", &val);
  135. gate->enable_bit = val;
  136. gate->ops = hw_ops;
  137. gate->flags = MEMMAP_ADDRESSING;
  138. if (!ti_clk_add_component(node, &gate->hw, CLK_COMPONENT_TYPE_GATE))
  139. return;
  140. cleanup:
  141. kfree(gate);
  142. }
  143. static void __init
  144. of_ti_composite_no_wait_gate_clk_setup(struct device_node *node)
  145. {
  146. _of_ti_composite_gate_clk_setup(node, NULL);
  147. }
  148. CLK_OF_DECLARE(ti_composite_no_wait_gate_clk, "ti,composite-no-wait-gate-clock",
  149. of_ti_composite_no_wait_gate_clk_setup);
  150. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  151. static void __init of_ti_composite_interface_clk_setup(struct device_node *node)
  152. {
  153. _of_ti_composite_gate_clk_setup(node, &clkhwops_iclk_wait);
  154. }
  155. CLK_OF_DECLARE(ti_composite_interface_clk, "ti,composite-interface-clock",
  156. of_ti_composite_interface_clk_setup);
  157. #endif
  158. static void __init of_ti_composite_gate_clk_setup(struct device_node *node)
  159. {
  160. _of_ti_composite_gate_clk_setup(node, &clkhwops_wait);
  161. }
  162. CLK_OF_DECLARE(ti_composite_gate_clk, "ti,composite-gate-clock",
  163. of_ti_composite_gate_clk_setup);
  164. static void __init of_ti_clkdm_gate_clk_setup(struct device_node *node)
  165. {
  166. _of_ti_gate_clk_setup(node, &omap_gate_clkdm_clk_ops, NULL);
  167. }
  168. CLK_OF_DECLARE(ti_clkdm_gate_clk, "ti,clkdm-gate-clock",
  169. of_ti_clkdm_gate_clk_setup);
  170. static void __init of_ti_hsdiv_gate_clk_setup(struct device_node *node)
  171. {
  172. _of_ti_gate_clk_setup(node, &omap_gate_clk_hsdiv_restore_ops,
  173. &clkhwops_wait);
  174. }
  175. CLK_OF_DECLARE(ti_hsdiv_gate_clk, "ti,hsdiv-gate-clock",
  176. of_ti_hsdiv_gate_clk_setup);
  177. static void __init of_ti_gate_clk_setup(struct device_node *node)
  178. {
  179. _of_ti_gate_clk_setup(node, &omap_gate_clk_ops, NULL);
  180. }
  181. CLK_OF_DECLARE(ti_gate_clk, "ti,gate-clock", of_ti_gate_clk_setup);
  182. static void __init of_ti_wait_gate_clk_setup(struct device_node *node)
  183. {
  184. _of_ti_gate_clk_setup(node, &omap_gate_clk_ops, &clkhwops_wait);
  185. }
  186. CLK_OF_DECLARE(ti_wait_gate_clk, "ti,wait-gate-clock",
  187. of_ti_wait_gate_clk_setup);
  188. #ifdef CONFIG_ARCH_OMAP3
  189. static void __init of_ti_am35xx_gate_clk_setup(struct device_node *node)
  190. {
  191. _of_ti_gate_clk_setup(node, &omap_gate_clk_ops,
  192. &clkhwops_am35xx_ipss_module_wait);
  193. }
  194. CLK_OF_DECLARE(ti_am35xx_gate_clk, "ti,am35xx-gate-clock",
  195. of_ti_am35xx_gate_clk_setup);
  196. static void __init of_ti_dss_gate_clk_setup(struct device_node *node)
  197. {
  198. _of_ti_gate_clk_setup(node, &omap_gate_clk_ops,
  199. &clkhwops_omap3430es2_dss_usbhost_wait);
  200. }
  201. CLK_OF_DECLARE(ti_dss_gate_clk, "ti,dss-gate-clock",
  202. of_ti_dss_gate_clk_setup);
  203. #endif