clock.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * TI Clock driver internal definitions
  3. *
  4. * Copyright (C) 2014 Texas Instruments, Inc
  5. * Tero Kristo (t-kristo@ti.com)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation version 2.
  10. *
  11. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  12. * kind, whether express or implied; without even the implied warranty
  13. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #ifndef __DRIVERS_CLK_TI_CLOCK__
  17. #define __DRIVERS_CLK_TI_CLOCK__
  18. enum {
  19. TI_CLK_FIXED,
  20. TI_CLK_MUX,
  21. TI_CLK_DIVIDER,
  22. TI_CLK_COMPOSITE,
  23. TI_CLK_FIXED_FACTOR,
  24. TI_CLK_GATE,
  25. TI_CLK_DPLL,
  26. };
  27. /* Global flags */
  28. #define CLKF_INDEX_POWER_OF_TWO (1 << 0)
  29. #define CLKF_INDEX_STARTS_AT_ONE (1 << 1)
  30. #define CLKF_SET_RATE_PARENT (1 << 2)
  31. #define CLKF_OMAP3 (1 << 3)
  32. #define CLKF_AM35XX (1 << 4)
  33. /* Gate flags */
  34. #define CLKF_SET_BIT_TO_DISABLE (1 << 5)
  35. #define CLKF_INTERFACE (1 << 6)
  36. #define CLKF_SSI (1 << 7)
  37. #define CLKF_DSS (1 << 8)
  38. #define CLKF_HSOTGUSB (1 << 9)
  39. #define CLKF_WAIT (1 << 10)
  40. #define CLKF_NO_WAIT (1 << 11)
  41. #define CLKF_HSDIV (1 << 12)
  42. #define CLKF_CLKDM (1 << 13)
  43. /* DPLL flags */
  44. #define CLKF_LOW_POWER_STOP (1 << 5)
  45. #define CLKF_LOCK (1 << 6)
  46. #define CLKF_LOW_POWER_BYPASS (1 << 7)
  47. #define CLKF_PER (1 << 8)
  48. #define CLKF_CORE (1 << 9)
  49. #define CLKF_J_TYPE (1 << 10)
  50. #define CLK(dev, con, ck) \
  51. { \
  52. .lk = { \
  53. .dev_id = dev, \
  54. .con_id = con, \
  55. }, \
  56. .clk = ck, \
  57. }
  58. struct ti_clk {
  59. const char *name;
  60. const char *clkdm_name;
  61. int type;
  62. void *data;
  63. struct ti_clk *patch;
  64. struct clk *clk;
  65. };
  66. struct ti_clk_alias {
  67. struct ti_clk *clk;
  68. struct clk_lookup lk;
  69. struct list_head link;
  70. };
  71. struct ti_clk_fixed {
  72. u32 frequency;
  73. u16 flags;
  74. };
  75. struct ti_clk_mux {
  76. u8 bit_shift;
  77. int num_parents;
  78. u16 reg;
  79. u8 module;
  80. const char **parents;
  81. u16 flags;
  82. };
  83. struct ti_clk_divider {
  84. const char *parent;
  85. u8 bit_shift;
  86. u16 max_div;
  87. u16 reg;
  88. u8 module;
  89. int *dividers;
  90. int num_dividers;
  91. u16 flags;
  92. };
  93. struct ti_clk_fixed_factor {
  94. const char *parent;
  95. u16 div;
  96. u16 mult;
  97. u16 flags;
  98. };
  99. struct ti_clk_gate {
  100. const char *parent;
  101. u8 bit_shift;
  102. u16 reg;
  103. u8 module;
  104. u16 flags;
  105. };
  106. struct ti_clk_composite {
  107. struct ti_clk_divider *divider;
  108. struct ti_clk_mux *mux;
  109. struct ti_clk_gate *gate;
  110. u16 flags;
  111. };
  112. struct ti_clk_clkdm_gate {
  113. const char *parent;
  114. u16 flags;
  115. };
  116. struct ti_clk_dpll {
  117. int num_parents;
  118. u16 control_reg;
  119. u16 idlest_reg;
  120. u16 autoidle_reg;
  121. u16 mult_div1_reg;
  122. u8 module;
  123. const char **parents;
  124. u16 flags;
  125. u8 modes;
  126. u32 mult_mask;
  127. u32 div1_mask;
  128. u32 enable_mask;
  129. u32 autoidle_mask;
  130. u32 freqsel_mask;
  131. u32 idlest_mask;
  132. u32 dco_mask;
  133. u32 sddiv_mask;
  134. u16 max_multiplier;
  135. u16 max_divider;
  136. u8 min_divider;
  137. u8 auto_recal_bit;
  138. u8 recal_en_bit;
  139. u8 recal_st_bit;
  140. };
  141. /* Composite clock component types */
  142. enum {
  143. CLK_COMPONENT_TYPE_GATE = 0,
  144. CLK_COMPONENT_TYPE_DIVIDER,
  145. CLK_COMPONENT_TYPE_MUX,
  146. CLK_COMPONENT_TYPE_MAX,
  147. };
  148. /**
  149. * struct ti_dt_clk - OMAP DT clock alias declarations
  150. * @lk: clock lookup definition
  151. * @node_name: clock DT node to map to
  152. */
  153. struct ti_dt_clk {
  154. struct clk_lookup lk;
  155. char *node_name;
  156. };
  157. #define DT_CLK(dev, con, name) \
  158. { \
  159. .lk = { \
  160. .dev_id = dev, \
  161. .con_id = con, \
  162. }, \
  163. .node_name = name, \
  164. }
  165. typedef void (*ti_of_clk_init_cb_t)(struct clk_hw *, struct device_node *);
  166. struct clk *ti_clk_register_gate(struct ti_clk *setup);
  167. struct clk *ti_clk_register_interface(struct ti_clk *setup);
  168. struct clk *ti_clk_register_mux(struct ti_clk *setup);
  169. struct clk *ti_clk_register_divider(struct ti_clk *setup);
  170. struct clk *ti_clk_register_composite(struct ti_clk *setup);
  171. struct clk *ti_clk_register_dpll(struct ti_clk *setup);
  172. struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup);
  173. struct clk_hw *ti_clk_build_component_gate(struct ti_clk_gate *setup);
  174. struct clk_hw *ti_clk_build_component_mux(struct ti_clk_mux *setup);
  175. void ti_clk_patch_legacy_clks(struct ti_clk **patch);
  176. struct clk *ti_clk_register_clk(struct ti_clk *setup);
  177. int ti_clk_register_legacy_clks(struct ti_clk_alias *clks);
  178. void __iomem *ti_clk_get_reg_addr(struct device_node *node, int index);
  179. void ti_dt_clocks_register(struct ti_dt_clk *oclks);
  180. int ti_clk_retry_init(struct device_node *node, struct clk_hw *hw,
  181. ti_of_clk_init_cb_t func);
  182. int ti_clk_add_component(struct device_node *node, struct clk_hw *hw, int type);
  183. void omap2_init_clk_hw_omap_clocks(struct clk_hw *hw);
  184. int of_ti_clk_autoidle_setup(struct device_node *node);
  185. void omap2_clk_enable_init_clocks(const char **clk_names, u8 num_clocks);
  186. extern const struct clk_hw_omap_ops clkhwops_omap3_dpll;
  187. extern const struct clk_hw_omap_ops clkhwops_omap4_dpllmx;
  188. extern const struct clk_hw_omap_ops clkhwops_wait;
  189. extern const struct clk_hw_omap_ops clkhwops_iclk;
  190. extern const struct clk_hw_omap_ops clkhwops_iclk_wait;
  191. extern const struct clk_hw_omap_ops clkhwops_omap2430_i2chs_wait;
  192. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait;
  193. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_hsotgusb_wait;
  194. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_dss_usbhost_wait;
  195. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_ssi_wait;
  196. extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait;
  197. extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_wait;
  198. extern const struct clk_ops ti_clk_divider_ops;
  199. extern const struct clk_ops ti_clk_mux_ops;
  200. int omap2_clkops_enable_clkdm(struct clk_hw *hw);
  201. void omap2_clkops_disable_clkdm(struct clk_hw *hw);
  202. int omap2_dflt_clk_enable(struct clk_hw *hw);
  203. void omap2_dflt_clk_disable(struct clk_hw *hw);
  204. int omap2_dflt_clk_is_enabled(struct clk_hw *hw);
  205. void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk,
  206. void __iomem **other_reg,
  207. u8 *other_bit);
  208. void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk,
  209. void __iomem **idlest_reg,
  210. u8 *idlest_bit, u8 *idlest_val);
  211. void omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk);
  212. void omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk);
  213. u8 omap2_init_dpll_parent(struct clk_hw *hw);
  214. int omap3_noncore_dpll_enable(struct clk_hw *hw);
  215. void omap3_noncore_dpll_disable(struct clk_hw *hw);
  216. int omap3_noncore_dpll_set_parent(struct clk_hw *hw, u8 index);
  217. int omap3_noncore_dpll_set_rate(struct clk_hw *hw, unsigned long rate,
  218. unsigned long parent_rate);
  219. int omap3_noncore_dpll_set_rate_and_parent(struct clk_hw *hw,
  220. unsigned long rate,
  221. unsigned long parent_rate,
  222. u8 index);
  223. int omap3_noncore_dpll_determine_rate(struct clk_hw *hw,
  224. struct clk_rate_request *req);
  225. long omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate,
  226. unsigned long *parent_rate);
  227. unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw,
  228. unsigned long parent_rate);
  229. /*
  230. * OMAP3_DPLL5_FREQ_FOR_USBHOST: USBHOST and USBTLL are the only clocks
  231. * that are sourced by DPLL5, and both of these require this clock
  232. * to be at 120 MHz for proper operation.
  233. */
  234. #define OMAP3_DPLL5_FREQ_FOR_USBHOST 120000000
  235. unsigned long omap3_dpll_recalc(struct clk_hw *hw, unsigned long parent_rate);
  236. int omap3_dpll4_set_rate(struct clk_hw *clk, unsigned long rate,
  237. unsigned long parent_rate);
  238. int omap3_dpll4_set_rate_and_parent(struct clk_hw *hw, unsigned long rate,
  239. unsigned long parent_rate, u8 index);
  240. int omap3_dpll5_set_rate(struct clk_hw *hw, unsigned long rate,
  241. unsigned long parent_rate);
  242. void omap3_clk_lock_dpll5(void);
  243. unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw,
  244. unsigned long parent_rate);
  245. long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw,
  246. unsigned long target_rate,
  247. unsigned long *parent_rate);
  248. int omap4_dpll_regm4xen_determine_rate(struct clk_hw *hw,
  249. struct clk_rate_request *req);
  250. extern struct ti_clk_ll_ops *ti_clk_ll_ops;
  251. #endif