clock.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. struct clk_omap_divider {
  19. struct clk_hw hw;
  20. struct clk_omap_reg reg;
  21. u8 shift;
  22. u8 width;
  23. u8 flags;
  24. const struct clk_div_table *table;
  25. };
  26. #define to_clk_omap_divider(_hw) container_of(_hw, struct clk_omap_divider, hw)
  27. struct clk_omap_mux {
  28. struct clk_hw hw;
  29. struct clk_omap_reg reg;
  30. u32 *table;
  31. u32 mask;
  32. u8 shift;
  33. u8 flags;
  34. };
  35. #define to_clk_omap_mux(_hw) container_of(_hw, struct clk_omap_mux, hw)
  36. enum {
  37. TI_CLK_FIXED,
  38. TI_CLK_MUX,
  39. TI_CLK_DIVIDER,
  40. TI_CLK_COMPOSITE,
  41. TI_CLK_FIXED_FACTOR,
  42. TI_CLK_GATE,
  43. TI_CLK_DPLL,
  44. };
  45. /* Global flags */
  46. #define CLKF_INDEX_POWER_OF_TWO (1 << 0)
  47. #define CLKF_INDEX_STARTS_AT_ONE (1 << 1)
  48. #define CLKF_SET_RATE_PARENT (1 << 2)
  49. #define CLKF_OMAP3 (1 << 3)
  50. #define CLKF_AM35XX (1 << 4)
  51. /* Gate flags */
  52. #define CLKF_SET_BIT_TO_DISABLE (1 << 5)
  53. #define CLKF_INTERFACE (1 << 6)
  54. #define CLKF_SSI (1 << 7)
  55. #define CLKF_DSS (1 << 8)
  56. #define CLKF_HSOTGUSB (1 << 9)
  57. #define CLKF_WAIT (1 << 10)
  58. #define CLKF_NO_WAIT (1 << 11)
  59. #define CLKF_HSDIV (1 << 12)
  60. #define CLKF_CLKDM (1 << 13)
  61. /* DPLL flags */
  62. #define CLKF_LOW_POWER_STOP (1 << 5)
  63. #define CLKF_LOCK (1 << 6)
  64. #define CLKF_LOW_POWER_BYPASS (1 << 7)
  65. #define CLKF_PER (1 << 8)
  66. #define CLKF_CORE (1 << 9)
  67. #define CLKF_J_TYPE (1 << 10)
  68. #define CLK(dev, con, ck) \
  69. { \
  70. .lk = { \
  71. .dev_id = dev, \
  72. .con_id = con, \
  73. }, \
  74. .clk = ck, \
  75. }
  76. struct ti_clk {
  77. const char *name;
  78. const char *clkdm_name;
  79. int type;
  80. void *data;
  81. struct ti_clk *patch;
  82. struct clk *clk;
  83. };
  84. struct ti_clk_alias {
  85. struct ti_clk *clk;
  86. struct clk_lookup lk;
  87. struct list_head link;
  88. };
  89. struct ti_clk_fixed {
  90. u32 frequency;
  91. u16 flags;
  92. };
  93. struct ti_clk_mux {
  94. u8 bit_shift;
  95. int num_parents;
  96. u16 reg;
  97. u8 module;
  98. const char * const *parents;
  99. u16 flags;
  100. };
  101. struct ti_clk_divider {
  102. const char *parent;
  103. u8 bit_shift;
  104. u16 max_div;
  105. u16 reg;
  106. u8 module;
  107. int *dividers;
  108. int num_dividers;
  109. u16 flags;
  110. };
  111. struct ti_clk_fixed_factor {
  112. const char *parent;
  113. u16 div;
  114. u16 mult;
  115. u16 flags;
  116. };
  117. struct ti_clk_gate {
  118. const char *parent;
  119. u8 bit_shift;
  120. u16 reg;
  121. u8 module;
  122. u16 flags;
  123. };
  124. struct ti_clk_composite {
  125. struct ti_clk_divider *divider;
  126. struct ti_clk_mux *mux;
  127. struct ti_clk_gate *gate;
  128. u16 flags;
  129. };
  130. struct ti_clk_clkdm_gate {
  131. const char *parent;
  132. u16 flags;
  133. };
  134. struct ti_clk_dpll {
  135. int num_parents;
  136. u16 control_reg;
  137. u16 idlest_reg;
  138. u16 autoidle_reg;
  139. u16 mult_div1_reg;
  140. u8 module;
  141. const char **parents;
  142. u16 flags;
  143. u8 modes;
  144. u32 mult_mask;
  145. u32 div1_mask;
  146. u32 enable_mask;
  147. u32 autoidle_mask;
  148. u32 freqsel_mask;
  149. u32 idlest_mask;
  150. u32 dco_mask;
  151. u32 sddiv_mask;
  152. u16 max_multiplier;
  153. u16 max_divider;
  154. u8 min_divider;
  155. u8 auto_recal_bit;
  156. u8 recal_en_bit;
  157. u8 recal_st_bit;
  158. };
  159. /* Composite clock component types */
  160. enum {
  161. CLK_COMPONENT_TYPE_GATE = 0,
  162. CLK_COMPONENT_TYPE_DIVIDER,
  163. CLK_COMPONENT_TYPE_MUX,
  164. CLK_COMPONENT_TYPE_MAX,
  165. };
  166. /**
  167. * struct ti_dt_clk - OMAP DT clock alias declarations
  168. * @lk: clock lookup definition
  169. * @node_name: clock DT node to map to
  170. */
  171. struct ti_dt_clk {
  172. struct clk_lookup lk;
  173. char *node_name;
  174. };
  175. #define DT_CLK(dev, con, name) \
  176. { \
  177. .lk = { \
  178. .dev_id = dev, \
  179. .con_id = con, \
  180. }, \
  181. .node_name = name, \
  182. }
  183. typedef void (*ti_of_clk_init_cb_t)(struct clk_hw *, struct device_node *);
  184. struct clk *ti_clk_register_gate(struct ti_clk *setup);
  185. struct clk *ti_clk_register_interface(struct ti_clk *setup);
  186. struct clk *ti_clk_register_mux(struct ti_clk *setup);
  187. struct clk *ti_clk_register_divider(struct ti_clk *setup);
  188. struct clk *ti_clk_register_composite(struct ti_clk *setup);
  189. struct clk *ti_clk_register_dpll(struct ti_clk *setup);
  190. struct clk *ti_clk_register(struct device *dev, struct clk_hw *hw,
  191. const char *con);
  192. int ti_clk_add_alias(struct device *dev, struct clk *clk, const char *con);
  193. void ti_clk_add_aliases(void);
  194. struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup);
  195. struct clk_hw *ti_clk_build_component_gate(struct ti_clk_gate *setup);
  196. struct clk_hw *ti_clk_build_component_mux(struct ti_clk_mux *setup);
  197. int ti_clk_parse_divider_data(int *div_table, int num_dividers, int max_div,
  198. u8 flags, u8 *width,
  199. const struct clk_div_table **table);
  200. void ti_clk_patch_legacy_clks(struct ti_clk **patch);
  201. struct clk *ti_clk_register_clk(struct ti_clk *setup);
  202. int ti_clk_register_legacy_clks(struct ti_clk_alias *clks);
  203. int ti_clk_get_reg_addr(struct device_node *node, int index,
  204. struct clk_omap_reg *reg);
  205. void ti_dt_clocks_register(struct ti_dt_clk *oclks);
  206. int ti_clk_retry_init(struct device_node *node, struct clk_hw *hw,
  207. ti_of_clk_init_cb_t func);
  208. int ti_clk_add_component(struct device_node *node, struct clk_hw *hw, int type);
  209. void omap2_init_clk_hw_omap_clocks(struct clk_hw *hw);
  210. int of_ti_clk_autoidle_setup(struct device_node *node);
  211. void omap2_clk_enable_init_clocks(const char **clk_names, u8 num_clocks);
  212. extern const struct clk_hw_omap_ops clkhwops_omap3_dpll;
  213. extern const struct clk_hw_omap_ops clkhwops_omap4_dpllmx;
  214. extern const struct clk_hw_omap_ops clkhwops_wait;
  215. extern const struct clk_hw_omap_ops clkhwops_iclk;
  216. extern const struct clk_hw_omap_ops clkhwops_iclk_wait;
  217. extern const struct clk_hw_omap_ops clkhwops_omap2430_i2chs_wait;
  218. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait;
  219. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_hsotgusb_wait;
  220. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_dss_usbhost_wait;
  221. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_ssi_wait;
  222. extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait;
  223. extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_wait;
  224. extern const struct clk_ops ti_clk_divider_ops;
  225. extern const struct clk_ops ti_clk_mux_ops;
  226. extern const struct clk_ops omap_gate_clk_ops;
  227. void omap2_init_clk_clkdm(struct clk_hw *hw);
  228. int omap2_clkops_enable_clkdm(struct clk_hw *hw);
  229. void omap2_clkops_disable_clkdm(struct clk_hw *hw);
  230. int omap2_dflt_clk_enable(struct clk_hw *hw);
  231. void omap2_dflt_clk_disable(struct clk_hw *hw);
  232. int omap2_dflt_clk_is_enabled(struct clk_hw *hw);
  233. void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk,
  234. struct clk_omap_reg *other_reg,
  235. u8 *other_bit);
  236. void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk,
  237. struct clk_omap_reg *idlest_reg,
  238. u8 *idlest_bit, u8 *idlest_val);
  239. void omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk);
  240. void omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk);
  241. u8 omap2_init_dpll_parent(struct clk_hw *hw);
  242. int omap3_noncore_dpll_enable(struct clk_hw *hw);
  243. void omap3_noncore_dpll_disable(struct clk_hw *hw);
  244. int omap3_noncore_dpll_set_parent(struct clk_hw *hw, u8 index);
  245. int omap3_noncore_dpll_set_rate(struct clk_hw *hw, unsigned long rate,
  246. unsigned long parent_rate);
  247. int omap3_noncore_dpll_set_rate_and_parent(struct clk_hw *hw,
  248. unsigned long rate,
  249. unsigned long parent_rate,
  250. u8 index);
  251. int omap3_noncore_dpll_determine_rate(struct clk_hw *hw,
  252. struct clk_rate_request *req);
  253. long omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate,
  254. unsigned long *parent_rate);
  255. unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw,
  256. unsigned long parent_rate);
  257. /*
  258. * OMAP3_DPLL5_FREQ_FOR_USBHOST: USBHOST and USBTLL are the only clocks
  259. * that are sourced by DPLL5, and both of these require this clock
  260. * to be at 120 MHz for proper operation.
  261. */
  262. #define OMAP3_DPLL5_FREQ_FOR_USBHOST 120000000
  263. unsigned long omap3_dpll_recalc(struct clk_hw *hw, unsigned long parent_rate);
  264. int omap3_dpll4_set_rate(struct clk_hw *clk, unsigned long rate,
  265. unsigned long parent_rate);
  266. int omap3_dpll4_set_rate_and_parent(struct clk_hw *hw, unsigned long rate,
  267. unsigned long parent_rate, u8 index);
  268. int omap3_dpll5_set_rate(struct clk_hw *hw, unsigned long rate,
  269. unsigned long parent_rate);
  270. void omap3_clk_lock_dpll5(void);
  271. unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw,
  272. unsigned long parent_rate);
  273. long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw,
  274. unsigned long target_rate,
  275. unsigned long *parent_rate);
  276. int omap4_dpll_regm4xen_determine_rate(struct clk_hw *hw,
  277. struct clk_rate_request *req);
  278. extern struct ti_clk_ll_ops *ti_clk_ll_ops;
  279. #endif