clock.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. struct omap_clk {
  22. u16 cpu;
  23. struct clk_lookup lk;
  24. };
  25. #define CLK(dev, con, ck) \
  26. { \
  27. .lk = { \
  28. .dev_id = dev, \
  29. .con_id = con, \
  30. .clk = ck, \
  31. }, \
  32. }
  33. struct clockdomain;
  34. #define to_clk_hw_omap(_hw) container_of(_hw, struct clk_hw_omap, hw)
  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. /**
  163. * struct dpll_data - DPLL registers and integration data
  164. * @mult_div1_reg: register containing the DPLL M and N bitfields
  165. * @mult_mask: mask of the DPLL M bitfield in @mult_div1_reg
  166. * @div1_mask: mask of the DPLL N bitfield in @mult_div1_reg
  167. * @clk_bypass: struct clk pointer to the clock's bypass clock input
  168. * @clk_ref: struct clk pointer to the clock's reference clock input
  169. * @control_reg: register containing the DPLL mode bitfield
  170. * @enable_mask: mask of the DPLL mode bitfield in @control_reg
  171. * @last_rounded_rate: cache of the last rate result of omap2_dpll_round_rate()
  172. * @last_rounded_m: cache of the last M result of omap2_dpll_round_rate()
  173. * @last_rounded_m4xen: cache of the last M4X result of
  174. * omap4_dpll_regm4xen_round_rate()
  175. * @last_rounded_lpmode: cache of the last lpmode result of
  176. * omap4_dpll_lpmode_recalc()
  177. * @max_multiplier: maximum valid non-bypass multiplier value (actual)
  178. * @last_rounded_n: cache of the last N result of omap2_dpll_round_rate()
  179. * @min_divider: minimum valid non-bypass divider value (actual)
  180. * @max_divider: maximum valid non-bypass divider value (actual)
  181. * @modes: possible values of @enable_mask
  182. * @autoidle_reg: register containing the DPLL autoidle mode bitfield
  183. * @idlest_reg: register containing the DPLL idle status bitfield
  184. * @autoidle_mask: mask of the DPLL autoidle mode bitfield in @autoidle_reg
  185. * @freqsel_mask: mask of the DPLL jitter correction bitfield in @control_reg
  186. * @idlest_mask: mask of the DPLL idle status bitfield in @idlest_reg
  187. * @lpmode_mask: mask of the DPLL low-power mode bitfield in @control_reg
  188. * @m4xen_mask: mask of the DPLL M4X multiplier bitfield in @control_reg
  189. * @auto_recal_bit: bitshift of the driftguard enable bit in @control_reg
  190. * @recal_en_bit: bitshift of the PRM_IRQENABLE_* bit for recalibration IRQs
  191. * @recal_st_bit: bitshift of the PRM_IRQSTATUS_* bit for recalibration IRQs
  192. * @flags: DPLL type/features (see below)
  193. *
  194. * Possible values for @flags:
  195. * DPLL_J_TYPE: "J-type DPLL" (only some 36xx, 4xxx DPLLs)
  196. *
  197. * @freqsel_mask is only used on the OMAP34xx family and AM35xx.
  198. *
  199. * XXX Some DPLLs have multiple bypass inputs, so it's not technically
  200. * correct to only have one @clk_bypass pointer.
  201. *
  202. * XXX The runtime-variable fields (@last_rounded_rate, @last_rounded_m,
  203. * @last_rounded_n) should be separated from the runtime-fixed fields
  204. * and placed into a different structure, so that the runtime-fixed data
  205. * can be placed into read-only space.
  206. */
  207. struct dpll_data {
  208. void __iomem *mult_div1_reg;
  209. u32 mult_mask;
  210. u32 div1_mask;
  211. struct clk *clk_bypass;
  212. struct clk *clk_ref;
  213. void __iomem *control_reg;
  214. u32 enable_mask;
  215. unsigned long last_rounded_rate;
  216. u16 last_rounded_m;
  217. u8 last_rounded_m4xen;
  218. u8 last_rounded_lpmode;
  219. u16 max_multiplier;
  220. u8 last_rounded_n;
  221. u8 min_divider;
  222. u16 max_divider;
  223. u8 modes;
  224. void __iomem *autoidle_reg;
  225. void __iomem *idlest_reg;
  226. u32 autoidle_mask;
  227. u32 freqsel_mask;
  228. u32 idlest_mask;
  229. u32 dco_mask;
  230. u32 sddiv_mask;
  231. u32 lpmode_mask;
  232. u32 m4xen_mask;
  233. u8 auto_recal_bit;
  234. u8 recal_en_bit;
  235. u8 recal_st_bit;
  236. u8 flags;
  237. };
  238. /*
  239. * struct clk.flags possibilities
  240. *
  241. * XXX document the rest of the clock flags here
  242. *
  243. * CLOCK_CLKOUTX2: (OMAP4 only) DPLL CLKOUT and CLKOUTX2 GATE_CTRL
  244. * bits share the same register. This flag allows the
  245. * omap4_dpllmx*() code to determine which GATE_CTRL bit field
  246. * should be used. This is a temporary solution - a better approach
  247. * would be to associate clock type-specific data with the clock,
  248. * similar to the struct dpll_data approach.
  249. */
  250. #define ENABLE_REG_32BIT (1 << 0) /* Use 32-bit access */
  251. #define CLOCK_IDLE_CONTROL (1 << 1)
  252. #define CLOCK_NO_IDLE_PARENT (1 << 2)
  253. #define ENABLE_ON_INIT (1 << 3) /* Enable upon framework init */
  254. #define INVERT_ENABLE (1 << 4) /* 0 enables, 1 disables */
  255. #define CLOCK_CLKOUTX2 (1 << 5)
  256. /**
  257. * struct clk_hw_omap - OMAP struct clk
  258. * @node: list_head connecting this clock into the full clock list
  259. * @enable_reg: register to write to enable the clock (see @enable_bit)
  260. * @enable_bit: bitshift to write to enable/disable the clock (see @enable_reg)
  261. * @flags: see "struct clk.flags possibilities" above
  262. * @clksel_reg: for clksel clks, register va containing src/divisor select
  263. * @clksel_mask: bitmask in @clksel_reg for the src/divisor selector
  264. * @clksel: for clksel clks, pointer to struct clksel for this clock
  265. * @dpll_data: for DPLLs, pointer to struct dpll_data for this clock
  266. * @clkdm_name: clockdomain name that this clock is contained in
  267. * @clkdm: pointer to struct clockdomain, resolved from @clkdm_name at runtime
  268. * @rate_offset: bitshift for rate selection bitfield (OMAP1 only)
  269. * @src_offset: bitshift for source selection bitfield (OMAP1 only)
  270. *
  271. * XXX @rate_offset, @src_offset should probably be removed and OMAP1
  272. * clock code converted to use clksel.
  273. *
  274. */
  275. struct clk_hw_omap_ops;
  276. struct clk_hw_omap {
  277. struct clk_hw hw;
  278. struct list_head node;
  279. unsigned long fixed_rate;
  280. u8 fixed_div;
  281. void __iomem *enable_reg;
  282. u8 enable_bit;
  283. u8 flags;
  284. void __iomem *clksel_reg;
  285. u32 clksel_mask;
  286. const struct clksel *clksel;
  287. struct dpll_data *dpll_data;
  288. const char *clkdm_name;
  289. struct clockdomain *clkdm;
  290. const struct clk_hw_omap_ops *ops;
  291. };
  292. struct clk_hw_omap_ops {
  293. void (*find_idlest)(struct clk_hw_omap *oclk,
  294. void __iomem **idlest_reg,
  295. u8 *idlest_bit, u8 *idlest_val);
  296. void (*find_companion)(struct clk_hw_omap *oclk,
  297. void __iomem **other_reg,
  298. u8 *other_bit);
  299. void (*allow_idle)(struct clk_hw_omap *oclk);
  300. void (*deny_idle)(struct clk_hw_omap *oclk);
  301. };
  302. unsigned long omap_fixed_divisor_recalc(struct clk_hw *hw,
  303. unsigned long parent_rate);
  304. /* CM_CLKSEL2_PLL.CORE_CLK_SRC bits (2XXX) */
  305. #define CORE_CLK_SRC_32K 0x0
  306. #define CORE_CLK_SRC_DPLL 0x1
  307. #define CORE_CLK_SRC_DPLL_X2 0x2
  308. /* OMAP2xxx CM_CLKEN_PLL.EN_DPLL bits - for omap2_get_dpll_rate() */
  309. #define OMAP2XXX_EN_DPLL_LPBYPASS 0x1
  310. #define OMAP2XXX_EN_DPLL_FRBYPASS 0x2
  311. #define OMAP2XXX_EN_DPLL_LOCKED 0x3
  312. /* OMAP3xxx CM_CLKEN_PLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
  313. #define OMAP3XXX_EN_DPLL_LPBYPASS 0x5
  314. #define OMAP3XXX_EN_DPLL_FRBYPASS 0x6
  315. #define OMAP3XXX_EN_DPLL_LOCKED 0x7
  316. /* OMAP4xxx CM_CLKMODE_DPLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
  317. #define OMAP4XXX_EN_DPLL_MNBYPASS 0x4
  318. #define OMAP4XXX_EN_DPLL_LPBYPASS 0x5
  319. #define OMAP4XXX_EN_DPLL_FRBYPASS 0x6
  320. #define OMAP4XXX_EN_DPLL_LOCKED 0x7
  321. /* CM_CLKEN_PLL*.EN* bit values - not all are available for every DPLL */
  322. #define DPLL_LOW_POWER_STOP 0x1
  323. #define DPLL_LOW_POWER_BYPASS 0x5
  324. #define DPLL_LOCKED 0x7
  325. /* DPLL Type and DCO Selection Flags */
  326. #define DPLL_J_TYPE 0x1
  327. long omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate,
  328. unsigned long *parent_rate);
  329. unsigned long omap3_dpll_recalc(struct clk_hw *hw, unsigned long parent_rate);
  330. int omap3_noncore_dpll_enable(struct clk_hw *hw);
  331. void omap3_noncore_dpll_disable(struct clk_hw *hw);
  332. int omap3_noncore_dpll_set_rate(struct clk_hw *hw, unsigned long rate,
  333. unsigned long parent_rate);
  334. u32 omap3_dpll_autoidle_read(struct clk_hw_omap *clk);
  335. void omap3_dpll_allow_idle(struct clk_hw_omap *clk);
  336. void omap3_dpll_deny_idle(struct clk_hw_omap *clk);
  337. unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw,
  338. unsigned long parent_rate);
  339. int omap4_dpllmx_gatectrl_read(struct clk_hw_omap *clk);
  340. void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk);
  341. void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk);
  342. unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw,
  343. unsigned long parent_rate);
  344. long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw,
  345. unsigned long target_rate,
  346. unsigned long *parent_rate);
  347. void omap2_init_clk_clkdm(struct clk_hw *clk);
  348. void __init omap2_clk_disable_clkdm_control(void);
  349. /* clkt_clksel.c public functions */
  350. u32 omap2_clksel_round_rate_div(struct clk_hw_omap *clk,
  351. unsigned long target_rate,
  352. u32 *new_div);
  353. u8 omap2_clksel_find_parent_index(struct clk_hw *hw);
  354. unsigned long omap2_clksel_recalc(struct clk_hw *hw, unsigned long parent_rate);
  355. long omap2_clksel_round_rate(struct clk_hw *hw, unsigned long target_rate,
  356. unsigned long *parent_rate);
  357. int omap2_clksel_set_rate(struct clk_hw *hw, unsigned long rate,
  358. unsigned long parent_rate);
  359. int omap2_clksel_set_parent(struct clk_hw *hw, u8 field_val);
  360. /* clkt_iclk.c public functions */
  361. extern void omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk);
  362. extern void omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk);
  363. u8 omap2_init_dpll_parent(struct clk_hw *hw);
  364. unsigned long omap2_get_dpll_rate(struct clk_hw_omap *clk);
  365. int omap2_dflt_clk_enable(struct clk_hw *hw);
  366. void omap2_dflt_clk_disable(struct clk_hw *hw);
  367. int omap2_dflt_clk_is_enabled(struct clk_hw *hw);
  368. void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk,
  369. void __iomem **other_reg,
  370. u8 *other_bit);
  371. void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk,
  372. void __iomem **idlest_reg,
  373. u8 *idlest_bit, u8 *idlest_val);
  374. void omap2_init_clk_hw_omap_clocks(struct clk *clk);
  375. int omap2_clk_enable_autoidle_all(void);
  376. int omap2_clk_disable_autoidle_all(void);
  377. void omap2_clk_enable_init_clocks(const char **clk_names, u8 num_clocks);
  378. int omap2_clk_switch_mpurate_at_boot(const char *mpurate_ck_name);
  379. void omap2_clk_print_new_rates(const char *hfclkin_ck_name,
  380. const char *core_ck_name,
  381. const char *mpu_ck_name);
  382. extern u16 cpu_mask;
  383. extern const struct clkops clkops_omap2_dflt_wait;
  384. extern const struct clkops clkops_dummy;
  385. extern const struct clkops clkops_omap2_dflt;
  386. extern struct clk_functions omap2_clk_functions;
  387. extern const struct clksel_rate gpt_32k_rates[];
  388. extern const struct clksel_rate gpt_sys_rates[];
  389. extern const struct clksel_rate gfx_l3_rates[];
  390. extern const struct clksel_rate dsp_ick_rates[];
  391. extern struct clk dummy_ck;
  392. extern const struct clk_hw_omap_ops clkhwops_omap3_dpll;
  393. extern const struct clk_hw_omap_ops clkhwops_iclk_wait;
  394. extern const struct clk_hw_omap_ops clkhwops_wait;
  395. extern const struct clk_hw_omap_ops clkhwops_omap4_dpllmx;
  396. extern const struct clk_hw_omap_ops clkhwops_iclk;
  397. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_ssi_wait;
  398. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_ssi_wait;
  399. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait;
  400. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_dss_usbhost_wait;
  401. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_hsotgusb_wait;
  402. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_hsotgusb_wait;
  403. extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait;
  404. extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_wait;
  405. extern const struct clk_hw_omap_ops clkhwops_apll54;
  406. extern const struct clk_hw_omap_ops clkhwops_apll96;
  407. extern const struct clk_hw_omap_ops clkhwops_omap2xxx_dpll;
  408. extern const struct clk_hw_omap_ops clkhwops_omap2430_i2chs_wait;
  409. /* clksel_rate blocks shared between OMAP44xx and AM33xx */
  410. extern const struct clksel_rate div_1_0_rates[];
  411. extern const struct clksel_rate div3_1to4_rates[];
  412. extern const struct clksel_rate div_1_1_rates[];
  413. extern const struct clksel_rate div_1_2_rates[];
  414. extern const struct clksel_rate div_1_3_rates[];
  415. extern const struct clksel_rate div_1_4_rates[];
  416. extern const struct clksel_rate div31_1to31_rates[];
  417. extern int am33xx_clk_init(void);
  418. extern int omap2_clkops_enable_clkdm(struct clk_hw *hw);
  419. extern void omap2_clkops_disable_clkdm(struct clk_hw *hw);
  420. extern void omap_clocks_register(struct omap_clk *oclks, int cnt);
  421. #endif