clock.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * linux/arch/arm/mach-omap2/clock.h
  3. *
  4. * Copyright (C) 2005-2009 Texas Instruments, Inc.
  5. * Copyright (C) 2004-2011 Nokia Corporation
  6. *
  7. * Contacts:
  8. * Richard Woodruff <r-woodruff2@ti.com>
  9. * Paul Walmsley
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #ifndef __ARCH_ARM_MACH_OMAP2_CLOCK_H
  16. #define __ARCH_ARM_MACH_OMAP2_CLOCK_H
  17. #include <linux/kernel.h>
  18. #include <linux/list.h>
  19. #include <linux/clkdev.h>
  20. #include <linux/clk-provider.h>
  21. #include <linux/clk/ti.h>
  22. struct omap_clk {
  23. u16 cpu;
  24. struct clk_lookup lk;
  25. };
  26. #define CLK(dev, con, ck) \
  27. { \
  28. .lk = { \
  29. .dev_id = dev, \
  30. .con_id = con, \
  31. .clk = ck, \
  32. }, \
  33. }
  34. struct clockdomain;
  35. #define DEFINE_STRUCT_CLK(_name, _parent_array_name, _clkops_name) \
  36. static struct clk _name = { \
  37. .name = #_name, \
  38. .hw = &_name##_hw.hw, \
  39. .parent_names = _parent_array_name, \
  40. .num_parents = ARRAY_SIZE(_parent_array_name), \
  41. .ops = &_clkops_name, \
  42. };
  43. #define DEFINE_STRUCT_CLK_FLAGS(_name, _parent_array_name, \
  44. _clkops_name, _flags) \
  45. static struct clk _name = { \
  46. .name = #_name, \
  47. .hw = &_name##_hw.hw, \
  48. .parent_names = _parent_array_name, \
  49. .num_parents = ARRAY_SIZE(_parent_array_name), \
  50. .ops = &_clkops_name, \
  51. .flags = _flags, \
  52. };
  53. #define DEFINE_STRUCT_CLK_HW_OMAP(_name, _clkdm_name) \
  54. static struct clk_hw_omap _name##_hw = { \
  55. .hw = { \
  56. .clk = &_name, \
  57. }, \
  58. .clkdm_name = _clkdm_name, \
  59. };
  60. #define DEFINE_CLK_OMAP_MUX(_name, _clkdm_name, _clksel, \
  61. _clksel_reg, _clksel_mask, \
  62. _parent_names, _ops) \
  63. static struct clk _name; \
  64. static struct clk_hw_omap _name##_hw = { \
  65. .hw = { \
  66. .clk = &_name, \
  67. }, \
  68. .clksel = _clksel, \
  69. .clksel_reg = _clksel_reg, \
  70. .clksel_mask = _clksel_mask, \
  71. .clkdm_name = _clkdm_name, \
  72. }; \
  73. DEFINE_STRUCT_CLK(_name, _parent_names, _ops);
  74. #define DEFINE_CLK_OMAP_MUX_GATE(_name, _clkdm_name, _clksel, \
  75. _clksel_reg, _clksel_mask, \
  76. _enable_reg, _enable_bit, \
  77. _hwops, _parent_names, _ops) \
  78. static struct clk _name; \
  79. static struct clk_hw_omap _name##_hw = { \
  80. .hw = { \
  81. .clk = &_name, \
  82. }, \
  83. .ops = _hwops, \
  84. .enable_reg = _enable_reg, \
  85. .enable_bit = _enable_bit, \
  86. .clksel = _clksel, \
  87. .clksel_reg = _clksel_reg, \
  88. .clksel_mask = _clksel_mask, \
  89. .clkdm_name = _clkdm_name, \
  90. }; \
  91. DEFINE_STRUCT_CLK(_name, _parent_names, _ops);
  92. /* struct clksel_rate.flags possibilities */
  93. #define RATE_IN_242X (1 << 0)
  94. #define RATE_IN_243X (1 << 1)
  95. #define RATE_IN_3430ES1 (1 << 2) /* 3430ES1 rates only */
  96. #define RATE_IN_3430ES2PLUS (1 << 3) /* 3430 ES >= 2 rates only */
  97. #define RATE_IN_36XX (1 << 4)
  98. #define RATE_IN_4430 (1 << 5)
  99. #define RATE_IN_TI816X (1 << 6)
  100. #define RATE_IN_4460 (1 << 7)
  101. #define RATE_IN_AM33XX (1 << 8)
  102. #define RATE_IN_TI814X (1 << 9)
  103. #define RATE_IN_24XX (RATE_IN_242X | RATE_IN_243X)
  104. #define RATE_IN_34XX (RATE_IN_3430ES1 | RATE_IN_3430ES2PLUS)
  105. #define RATE_IN_3XXX (RATE_IN_34XX | RATE_IN_36XX)
  106. #define RATE_IN_44XX (RATE_IN_4430 | RATE_IN_4460)
  107. /* RATE_IN_3430ES2PLUS_36XX includes 34xx/35xx with ES >=2, and all 36xx/37xx */
  108. #define RATE_IN_3430ES2PLUS_36XX (RATE_IN_3430ES2PLUS | RATE_IN_36XX)
  109. /**
  110. * struct clksel_rate - register bitfield values corresponding to clk divisors
  111. * @val: register bitfield value (shifted to bit 0)
  112. * @div: clock divisor corresponding to @val
  113. * @flags: (see "struct clksel_rate.flags possibilities" above)
  114. *
  115. * @val should match the value of a read from struct clk.clksel_reg
  116. * AND'ed with struct clk.clksel_mask, shifted right to bit 0.
  117. *
  118. * @div is the divisor that should be applied to the parent clock's rate
  119. * to produce the current clock's rate.
  120. */
  121. struct clksel_rate {
  122. u32 val;
  123. u8 div;
  124. u16 flags;
  125. };
  126. /**
  127. * struct clksel - available parent clocks, and a pointer to their divisors
  128. * @parent: struct clk * to a possible parent clock
  129. * @rates: available divisors for this parent clock
  130. *
  131. * A struct clksel is always associated with one or more struct clks
  132. * and one or more struct clksel_rates.
  133. */
  134. struct clksel {
  135. struct clk *parent;
  136. const struct clksel_rate *rates;
  137. };
  138. /* CM_CLKSEL2_PLL.CORE_CLK_SRC bits (2XXX) */
  139. #define CORE_CLK_SRC_32K 0x0
  140. #define CORE_CLK_SRC_DPLL 0x1
  141. #define CORE_CLK_SRC_DPLL_X2 0x2
  142. /* OMAP2xxx CM_CLKEN_PLL.EN_DPLL bits - for omap2_get_dpll_rate() */
  143. #define OMAP2XXX_EN_DPLL_LPBYPASS 0x1
  144. #define OMAP2XXX_EN_DPLL_FRBYPASS 0x2
  145. #define OMAP2XXX_EN_DPLL_LOCKED 0x3
  146. /* OMAP3xxx CM_CLKEN_PLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
  147. #define OMAP3XXX_EN_DPLL_LPBYPASS 0x5
  148. #define OMAP3XXX_EN_DPLL_FRBYPASS 0x6
  149. #define OMAP3XXX_EN_DPLL_LOCKED 0x7
  150. /* OMAP4xxx CM_CLKMODE_DPLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
  151. #define OMAP4XXX_EN_DPLL_MNBYPASS 0x4
  152. #define OMAP4XXX_EN_DPLL_LPBYPASS 0x5
  153. #define OMAP4XXX_EN_DPLL_FRBYPASS 0x6
  154. #define OMAP4XXX_EN_DPLL_LOCKED 0x7
  155. u32 omap3_dpll_autoidle_read(struct clk_hw_omap *clk);
  156. void omap3_dpll_allow_idle(struct clk_hw_omap *clk);
  157. void omap3_dpll_deny_idle(struct clk_hw_omap *clk);
  158. int omap4_dpllmx_gatectrl_read(struct clk_hw_omap *clk);
  159. void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk);
  160. void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk);
  161. void __init omap2_clk_disable_clkdm_control(void);
  162. /* clkt_clksel.c public functions */
  163. u32 omap2_clksel_round_rate_div(struct clk_hw_omap *clk,
  164. unsigned long target_rate,
  165. u32 *new_div);
  166. u8 omap2_clksel_find_parent_index(struct clk_hw *hw);
  167. unsigned long omap2_clksel_recalc(struct clk_hw *hw, unsigned long parent_rate);
  168. long omap2_clksel_round_rate(struct clk_hw *hw, unsigned long target_rate,
  169. unsigned long *parent_rate);
  170. int omap2_clksel_set_rate(struct clk_hw *hw, unsigned long rate,
  171. unsigned long parent_rate);
  172. int omap2_clksel_set_parent(struct clk_hw *hw, u8 field_val);
  173. /* clkt_iclk.c public functions */
  174. extern void omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk);
  175. extern void omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk);
  176. unsigned long omap2_get_dpll_rate(struct clk_hw_omap *clk);
  177. void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk,
  178. void __iomem **other_reg,
  179. u8 *other_bit);
  180. void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk,
  181. void __iomem **idlest_reg,
  182. u8 *idlest_bit, u8 *idlest_val);
  183. int omap2_clk_enable_autoidle_all(void);
  184. int omap2_clk_allow_idle(struct clk *clk);
  185. int omap2_clk_deny_idle(struct clk *clk);
  186. int omap2_clk_switch_mpurate_at_boot(const char *mpurate_ck_name);
  187. void omap2_clk_print_new_rates(const char *hfclkin_ck_name,
  188. const char *core_ck_name,
  189. const char *mpu_ck_name);
  190. u32 omap2_clk_readl(struct clk_hw_omap *clk, void __iomem *reg);
  191. void omap2_clk_writel(u32 val, struct clk_hw_omap *clk, void __iomem *reg);
  192. extern u16 cpu_mask;
  193. /*
  194. * Clock features setup. Used instead of CPU type checks.
  195. */
  196. struct ti_clk_features {
  197. u32 flags;
  198. long fint_min;
  199. long fint_max;
  200. long fint_band1_max;
  201. long fint_band2_min;
  202. u8 dpll_bypass_vals;
  203. u8 cm_idlest_val;
  204. };
  205. #define TI_CLK_DPLL_HAS_FREQSEL (1 << 0)
  206. extern struct ti_clk_features ti_clk_features;
  207. extern const struct clkops clkops_omap2_dflt_wait;
  208. extern const struct clkops clkops_dummy;
  209. extern const struct clkops clkops_omap2_dflt;
  210. extern struct clk_functions omap2_clk_functions;
  211. extern const struct clksel_rate gpt_32k_rates[];
  212. extern const struct clksel_rate gpt_sys_rates[];
  213. extern const struct clksel_rate gfx_l3_rates[];
  214. extern const struct clksel_rate dsp_ick_rates[];
  215. extern struct clk dummy_ck;
  216. extern const struct clk_hw_omap_ops clkhwops_iclk_wait;
  217. extern const struct clk_hw_omap_ops clkhwops_wait;
  218. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_ssi_wait;
  219. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait;
  220. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_hsotgusb_wait;
  221. extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait;
  222. extern const struct clk_hw_omap_ops clkhwops_apll54;
  223. extern const struct clk_hw_omap_ops clkhwops_apll96;
  224. /* clksel_rate blocks shared between OMAP44xx and AM33xx */
  225. extern const struct clksel_rate div_1_0_rates[];
  226. extern const struct clksel_rate div3_1to4_rates[];
  227. extern const struct clksel_rate div_1_1_rates[];
  228. extern const struct clksel_rate div_1_2_rates[];
  229. extern const struct clksel_rate div_1_3_rates[];
  230. extern const struct clksel_rate div_1_4_rates[];
  231. extern const struct clksel_rate div31_1to31_rates[];
  232. extern void __iomem *clk_memmaps[];
  233. extern int am33xx_clk_init(void);
  234. extern int omap2_clkops_enable_clkdm(struct clk_hw *hw);
  235. extern void omap2_clkops_disable_clkdm(struct clk_hw *hw);
  236. extern void omap_clocks_register(struct omap_clk *oclks, int cnt);
  237. void __init ti_clk_init_features(void);
  238. #endif