clock.h 8.3 KB

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