clock.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. #define DEFINE_CLK_OMAP_HSDIVIDER(_name, _parent_name, \
  93. _parent_ptr, _flags, \
  94. _clksel_reg, _clksel_mask) \
  95. static const struct clksel _name##_div[] = { \
  96. { \
  97. .parent = _parent_ptr, \
  98. .rates = div31_1to31_rates \
  99. }, \
  100. { .parent = NULL }, \
  101. }; \
  102. static struct clk _name; \
  103. static const char *_name##_parent_names[] = { \
  104. _parent_name, \
  105. }; \
  106. static struct clk_hw_omap _name##_hw = { \
  107. .hw = { \
  108. .clk = &_name, \
  109. }, \
  110. .clksel = _name##_div, \
  111. .clksel_reg = _clksel_reg, \
  112. .clksel_mask = _clksel_mask, \
  113. .ops = &clkhwops_omap4_dpllmx, \
  114. }; \
  115. DEFINE_STRUCT_CLK(_name, _name##_parent_names, omap_hsdivider_ops);
  116. /* struct clksel_rate.flags possibilities */
  117. #define RATE_IN_242X (1 << 0)
  118. #define RATE_IN_243X (1 << 1)
  119. #define RATE_IN_3430ES1 (1 << 2) /* 3430ES1 rates only */
  120. #define RATE_IN_3430ES2PLUS (1 << 3) /* 3430 ES >= 2 rates only */
  121. #define RATE_IN_36XX (1 << 4)
  122. #define RATE_IN_4430 (1 << 5)
  123. #define RATE_IN_TI816X (1 << 6)
  124. #define RATE_IN_4460 (1 << 7)
  125. #define RATE_IN_AM33XX (1 << 8)
  126. #define RATE_IN_TI814X (1 << 9)
  127. #define RATE_IN_24XX (RATE_IN_242X | RATE_IN_243X)
  128. #define RATE_IN_34XX (RATE_IN_3430ES1 | RATE_IN_3430ES2PLUS)
  129. #define RATE_IN_3XXX (RATE_IN_34XX | RATE_IN_36XX)
  130. #define RATE_IN_44XX (RATE_IN_4430 | RATE_IN_4460)
  131. /* RATE_IN_3430ES2PLUS_36XX includes 34xx/35xx with ES >=2, and all 36xx/37xx */
  132. #define RATE_IN_3430ES2PLUS_36XX (RATE_IN_3430ES2PLUS | RATE_IN_36XX)
  133. /**
  134. * struct clksel_rate - register bitfield values corresponding to clk divisors
  135. * @val: register bitfield value (shifted to bit 0)
  136. * @div: clock divisor corresponding to @val
  137. * @flags: (see "struct clksel_rate.flags possibilities" above)
  138. *
  139. * @val should match the value of a read from struct clk.clksel_reg
  140. * AND'ed with struct clk.clksel_mask, shifted right to bit 0.
  141. *
  142. * @div is the divisor that should be applied to the parent clock's rate
  143. * to produce the current clock's rate.
  144. */
  145. struct clksel_rate {
  146. u32 val;
  147. u8 div;
  148. u16 flags;
  149. };
  150. /**
  151. * struct clksel - available parent clocks, and a pointer to their divisors
  152. * @parent: struct clk * to a possible parent clock
  153. * @rates: available divisors for this parent clock
  154. *
  155. * A struct clksel is always associated with one or more struct clks
  156. * and one or more struct clksel_rates.
  157. */
  158. struct clksel {
  159. struct clk *parent;
  160. const struct clksel_rate *rates;
  161. };
  162. unsigned long omap_fixed_divisor_recalc(struct clk_hw *hw,
  163. unsigned long parent_rate);
  164. /* CM_CLKSEL2_PLL.CORE_CLK_SRC bits (2XXX) */
  165. #define CORE_CLK_SRC_32K 0x0
  166. #define CORE_CLK_SRC_DPLL 0x1
  167. #define CORE_CLK_SRC_DPLL_X2 0x2
  168. /* OMAP2xxx CM_CLKEN_PLL.EN_DPLL bits - for omap2_get_dpll_rate() */
  169. #define OMAP2XXX_EN_DPLL_LPBYPASS 0x1
  170. #define OMAP2XXX_EN_DPLL_FRBYPASS 0x2
  171. #define OMAP2XXX_EN_DPLL_LOCKED 0x3
  172. /* OMAP3xxx CM_CLKEN_PLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
  173. #define OMAP3XXX_EN_DPLL_LPBYPASS 0x5
  174. #define OMAP3XXX_EN_DPLL_FRBYPASS 0x6
  175. #define OMAP3XXX_EN_DPLL_LOCKED 0x7
  176. /* OMAP4xxx CM_CLKMODE_DPLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
  177. #define OMAP4XXX_EN_DPLL_MNBYPASS 0x4
  178. #define OMAP4XXX_EN_DPLL_LPBYPASS 0x5
  179. #define OMAP4XXX_EN_DPLL_FRBYPASS 0x6
  180. #define OMAP4XXX_EN_DPLL_LOCKED 0x7
  181. u32 omap3_dpll_autoidle_read(struct clk_hw_omap *clk);
  182. void omap3_dpll_allow_idle(struct clk_hw_omap *clk);
  183. void omap3_dpll_deny_idle(struct clk_hw_omap *clk);
  184. int omap4_dpllmx_gatectrl_read(struct clk_hw_omap *clk);
  185. void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk);
  186. void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk);
  187. void __init omap2_clk_disable_clkdm_control(void);
  188. /* clkt_clksel.c public functions */
  189. u32 omap2_clksel_round_rate_div(struct clk_hw_omap *clk,
  190. unsigned long target_rate,
  191. u32 *new_div);
  192. u8 omap2_clksel_find_parent_index(struct clk_hw *hw);
  193. unsigned long omap2_clksel_recalc(struct clk_hw *hw, unsigned long parent_rate);
  194. long omap2_clksel_round_rate(struct clk_hw *hw, unsigned long target_rate,
  195. unsigned long *parent_rate);
  196. int omap2_clksel_set_rate(struct clk_hw *hw, unsigned long rate,
  197. unsigned long parent_rate);
  198. int omap2_clksel_set_parent(struct clk_hw *hw, u8 field_val);
  199. /* clkt_iclk.c public functions */
  200. extern void omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk);
  201. extern void omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk);
  202. unsigned long omap2_get_dpll_rate(struct clk_hw_omap *clk);
  203. void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk,
  204. void __iomem **other_reg,
  205. u8 *other_bit);
  206. void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk,
  207. void __iomem **idlest_reg,
  208. u8 *idlest_bit, u8 *idlest_val);
  209. int omap2_clk_enable_autoidle_all(void);
  210. int omap2_clk_allow_idle(struct clk *clk);
  211. int omap2_clk_deny_idle(struct clk *clk);
  212. int omap2_clk_switch_mpurate_at_boot(const char *mpurate_ck_name);
  213. void omap2_clk_print_new_rates(const char *hfclkin_ck_name,
  214. const char *core_ck_name,
  215. const char *mpu_ck_name);
  216. u32 omap2_clk_readl(struct clk_hw_omap *clk, void __iomem *reg);
  217. void omap2_clk_writel(u32 val, struct clk_hw_omap *clk, void __iomem *reg);
  218. extern u16 cpu_mask;
  219. extern const struct clkops clkops_omap2_dflt_wait;
  220. extern const struct clkops clkops_dummy;
  221. extern const struct clkops clkops_omap2_dflt;
  222. extern struct clk_functions omap2_clk_functions;
  223. extern const struct clksel_rate gpt_32k_rates[];
  224. extern const struct clksel_rate gpt_sys_rates[];
  225. extern const struct clksel_rate gfx_l3_rates[];
  226. extern const struct clksel_rate dsp_ick_rates[];
  227. extern struct clk dummy_ck;
  228. extern const struct clk_hw_omap_ops clkhwops_iclk_wait;
  229. extern const struct clk_hw_omap_ops clkhwops_wait;
  230. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_ssi_wait;
  231. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait;
  232. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_hsotgusb_wait;
  233. extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait;
  234. extern const struct clk_hw_omap_ops clkhwops_apll54;
  235. extern const struct clk_hw_omap_ops clkhwops_apll96;
  236. /* clksel_rate blocks shared between OMAP44xx and AM33xx */
  237. extern const struct clksel_rate div_1_0_rates[];
  238. extern const struct clksel_rate div3_1to4_rates[];
  239. extern const struct clksel_rate div_1_1_rates[];
  240. extern const struct clksel_rate div_1_2_rates[];
  241. extern const struct clksel_rate div_1_3_rates[];
  242. extern const struct clksel_rate div_1_4_rates[];
  243. extern const struct clksel_rate div31_1to31_rates[];
  244. extern void __iomem *clk_memmaps[];
  245. extern int am33xx_clk_init(void);
  246. extern int omap2_clkops_enable_clkdm(struct clk_hw *hw);
  247. extern void omap2_clkops_disable_clkdm(struct clk_hw *hw);
  248. extern void omap_clocks_register(struct omap_clk *oclks, int cnt);
  249. #endif