clock.h 8.6 KB

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