clock.h 8.8 KB

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