clock.h 8.8 KB

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