ti.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. * TI clock drivers support
  3. *
  4. * Copyright (C) 2013 Texas Instruments, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  11. * kind, whether express or implied; without even the implied warranty
  12. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef __LINUX_CLK_TI_H__
  16. #define __LINUX_CLK_TI_H__
  17. #include <linux/clk-provider.h>
  18. #include <linux/clkdev.h>
  19. /**
  20. * struct clk_omap_reg - OMAP register declaration
  21. * @offset: offset from the master IP module base address
  22. * @index: index of the master IP module
  23. */
  24. struct clk_omap_reg {
  25. void __iomem *ptr;
  26. u16 offset;
  27. u8 index;
  28. u8 flags;
  29. };
  30. /**
  31. * struct dpll_data - DPLL registers and integration data
  32. * @mult_div1_reg: register containing the DPLL M and N bitfields
  33. * @mult_mask: mask of the DPLL M bitfield in @mult_div1_reg
  34. * @div1_mask: mask of the DPLL N bitfield in @mult_div1_reg
  35. * @clk_bypass: struct clk_hw pointer to the clock's bypass clock input
  36. * @clk_ref: struct clk_hw pointer to the clock's reference clock input
  37. * @control_reg: register containing the DPLL mode bitfield
  38. * @enable_mask: mask of the DPLL mode bitfield in @control_reg
  39. * @last_rounded_rate: cache of the last rate result of omap2_dpll_round_rate()
  40. * @last_rounded_m: cache of the last M result of omap2_dpll_round_rate()
  41. * @last_rounded_m4xen: cache of the last M4X result of
  42. * omap4_dpll_regm4xen_round_rate()
  43. * @last_rounded_lpmode: cache of the last lpmode result of
  44. * omap4_dpll_lpmode_recalc()
  45. * @max_multiplier: maximum valid non-bypass multiplier value (actual)
  46. * @last_rounded_n: cache of the last N result of omap2_dpll_round_rate()
  47. * @min_divider: minimum valid non-bypass divider value (actual)
  48. * @max_divider: maximum valid non-bypass divider value (actual)
  49. * @max_rate: maximum clock rate for the DPLL
  50. * @modes: possible values of @enable_mask
  51. * @autoidle_reg: register containing the DPLL autoidle mode bitfield
  52. * @idlest_reg: register containing the DPLL idle status bitfield
  53. * @autoidle_mask: mask of the DPLL autoidle mode bitfield in @autoidle_reg
  54. * @freqsel_mask: mask of the DPLL jitter correction bitfield in @control_reg
  55. * @dcc_mask: mask of the DPLL DCC correction bitfield @mult_div1_reg
  56. * @dcc_rate: rate atleast which DCC @dcc_mask must be set
  57. * @idlest_mask: mask of the DPLL idle status bitfield in @idlest_reg
  58. * @lpmode_mask: mask of the DPLL low-power mode bitfield in @control_reg
  59. * @m4xen_mask: mask of the DPLL M4X multiplier bitfield in @control_reg
  60. * @auto_recal_bit: bitshift of the driftguard enable bit in @control_reg
  61. * @recal_en_bit: bitshift of the PRM_IRQENABLE_* bit for recalibration IRQs
  62. * @recal_st_bit: bitshift of the PRM_IRQSTATUS_* bit for recalibration IRQs
  63. * @flags: DPLL type/features (see below)
  64. *
  65. * Possible values for @flags:
  66. * DPLL_J_TYPE: "J-type DPLL" (only some 36xx, 4xxx DPLLs)
  67. *
  68. * @freqsel_mask is only used on the OMAP34xx family and AM35xx.
  69. *
  70. * XXX Some DPLLs have multiple bypass inputs, so it's not technically
  71. * correct to only have one @clk_bypass pointer.
  72. *
  73. * XXX The runtime-variable fields (@last_rounded_rate, @last_rounded_m,
  74. * @last_rounded_n) should be separated from the runtime-fixed fields
  75. * and placed into a different structure, so that the runtime-fixed data
  76. * can be placed into read-only space.
  77. */
  78. struct dpll_data {
  79. struct clk_omap_reg mult_div1_reg;
  80. u32 mult_mask;
  81. u32 div1_mask;
  82. struct clk_hw *clk_bypass;
  83. struct clk_hw *clk_ref;
  84. struct clk_omap_reg control_reg;
  85. u32 enable_mask;
  86. unsigned long last_rounded_rate;
  87. u16 last_rounded_m;
  88. u8 last_rounded_m4xen;
  89. u8 last_rounded_lpmode;
  90. u16 max_multiplier;
  91. u8 last_rounded_n;
  92. u8 min_divider;
  93. u16 max_divider;
  94. unsigned long max_rate;
  95. u8 modes;
  96. struct clk_omap_reg autoidle_reg;
  97. struct clk_omap_reg idlest_reg;
  98. u32 autoidle_mask;
  99. u32 freqsel_mask;
  100. u32 idlest_mask;
  101. u32 dco_mask;
  102. u32 sddiv_mask;
  103. u32 dcc_mask;
  104. unsigned long dcc_rate;
  105. u32 lpmode_mask;
  106. u32 m4xen_mask;
  107. u8 auto_recal_bit;
  108. u8 recal_en_bit;
  109. u8 recal_st_bit;
  110. u8 flags;
  111. };
  112. struct clk_hw_omap;
  113. /**
  114. * struct clk_hw_omap_ops - OMAP clk ops
  115. * @find_idlest: find idlest register information for a clock
  116. * @find_companion: find companion clock register information for a clock,
  117. * basically converts CM_ICLKEN* <-> CM_FCLKEN*
  118. * @allow_idle: enables autoidle hardware functionality for a clock
  119. * @deny_idle: prevent autoidle hardware functionality for a clock
  120. */
  121. struct clk_hw_omap_ops {
  122. void (*find_idlest)(struct clk_hw_omap *oclk,
  123. struct clk_omap_reg *idlest_reg,
  124. u8 *idlest_bit, u8 *idlest_val);
  125. void (*find_companion)(struct clk_hw_omap *oclk,
  126. struct clk_omap_reg *other_reg,
  127. u8 *other_bit);
  128. void (*allow_idle)(struct clk_hw_omap *oclk);
  129. void (*deny_idle)(struct clk_hw_omap *oclk);
  130. };
  131. /**
  132. * struct clk_hw_omap - OMAP struct clk
  133. * @node: list_head connecting this clock into the full clock list
  134. * @enable_reg: register to write to enable the clock (see @enable_bit)
  135. * @enable_bit: bitshift to write to enable/disable the clock (see @enable_reg)
  136. * @flags: see "struct clk.flags possibilities" above
  137. * @clksel_reg: for clksel clks, register va containing src/divisor select
  138. * @dpll_data: for DPLLs, pointer to struct dpll_data for this clock
  139. * @clkdm_name: clockdomain name that this clock is contained in
  140. * @clkdm: pointer to struct clockdomain, resolved from @clkdm_name at runtime
  141. * @ops: clock ops for this clock
  142. */
  143. struct clk_hw_omap {
  144. struct clk_hw hw;
  145. struct list_head node;
  146. unsigned long fixed_rate;
  147. u8 fixed_div;
  148. struct clk_omap_reg enable_reg;
  149. u8 enable_bit;
  150. u8 flags;
  151. struct clk_omap_reg clksel_reg;
  152. struct dpll_data *dpll_data;
  153. const char *clkdm_name;
  154. struct clockdomain *clkdm;
  155. const struct clk_hw_omap_ops *ops;
  156. u32 context;
  157. };
  158. /*
  159. * struct clk_hw_omap.flags possibilities
  160. *
  161. * XXX document the rest of the clock flags here
  162. *
  163. * ENABLE_REG_32BIT: (OMAP1 only) clock control register must be accessed
  164. * with 32bit ops, by default OMAP1 uses 16bit ops.
  165. * CLOCK_IDLE_CONTROL: (OMAP1 only) clock has autoidle support.
  166. * CLOCK_NO_IDLE_PARENT: (OMAP1 only) when clock is enabled, its parent
  167. * clock is put to no-idle mode.
  168. * ENABLE_ON_INIT: Clock is enabled on init.
  169. * INVERT_ENABLE: By default, clock enable bit behavior is '1' enable, '0'
  170. * disable. This inverts the behavior making '0' enable and '1' disable.
  171. * CLOCK_CLKOUTX2: (OMAP4 only) DPLL CLKOUT and CLKOUTX2 GATE_CTRL
  172. * bits share the same register. This flag allows the
  173. * omap4_dpllmx*() code to determine which GATE_CTRL bit field
  174. * should be used. This is a temporary solution - a better approach
  175. * would be to associate clock type-specific data with the clock,
  176. * similar to the struct dpll_data approach.
  177. */
  178. #define ENABLE_REG_32BIT (1 << 0) /* Use 32-bit access */
  179. #define CLOCK_IDLE_CONTROL (1 << 1)
  180. #define CLOCK_NO_IDLE_PARENT (1 << 2)
  181. #define ENABLE_ON_INIT (1 << 3) /* Enable upon framework init */
  182. #define INVERT_ENABLE (1 << 4) /* 0 enables, 1 disables */
  183. #define CLOCK_CLKOUTX2 (1 << 5)
  184. /* CM_CLKEN_PLL*.EN* bit values - not all are available for every DPLL */
  185. #define DPLL_LOW_POWER_STOP 0x1
  186. #define DPLL_LOW_POWER_BYPASS 0x5
  187. #define DPLL_LOCKED 0x7
  188. /* DPLL Type and DCO Selection Flags */
  189. #define DPLL_J_TYPE 0x1
  190. /* Static memmap indices */
  191. enum {
  192. TI_CLKM_CM = 0,
  193. TI_CLKM_CM2,
  194. TI_CLKM_PRM,
  195. TI_CLKM_SCRM,
  196. TI_CLKM_CTRL,
  197. TI_CLKM_PLLSS,
  198. CLK_MAX_MEMMAPS
  199. };
  200. /**
  201. * struct ti_clk_ll_ops - low-level ops for clocks
  202. * @clk_readl: pointer to register read function
  203. * @clk_writel: pointer to register write function
  204. * @clk_rmw: pointer to register read-modify-write function
  205. * @clkdm_clk_enable: pointer to clockdomain enable function
  206. * @clkdm_clk_disable: pointer to clockdomain disable function
  207. * @clkdm_lookup: pointer to clockdomain lookup function
  208. * @cm_wait_module_ready: pointer to CM module wait ready function
  209. * @cm_split_idlest_reg: pointer to CM module function to split idlest reg
  210. *
  211. * Low-level ops are generally used by the basic clock types (clk-gate,
  212. * clk-mux, clk-divider etc.) to provide support for various low-level
  213. * hadrware interfaces (direct MMIO, regmap etc.), and is initialized
  214. * by board code. Low-level ops also contain some other platform specific
  215. * operations not provided directly by clock drivers.
  216. */
  217. struct ti_clk_ll_ops {
  218. u32 (*clk_readl)(const struct clk_omap_reg *reg);
  219. void (*clk_writel)(u32 val, const struct clk_omap_reg *reg);
  220. void (*clk_rmw)(u32 val, u32 mask, const struct clk_omap_reg *reg);
  221. int (*clkdm_clk_enable)(struct clockdomain *clkdm, struct clk *clk);
  222. int (*clkdm_clk_disable)(struct clockdomain *clkdm,
  223. struct clk *clk);
  224. struct clockdomain * (*clkdm_lookup)(const char *name);
  225. int (*cm_wait_module_ready)(u8 part, s16 prcm_mod, u16 idlest_reg,
  226. u8 idlest_shift);
  227. int (*cm_split_idlest_reg)(struct clk_omap_reg *idlest_reg,
  228. s16 *prcm_inst, u8 *idlest_reg_id);
  229. };
  230. #define to_clk_hw_omap(_hw) container_of(_hw, struct clk_hw_omap, hw)
  231. int omap2_clk_disable_autoidle_all(void);
  232. int omap2_clk_enable_autoidle_all(void);
  233. int omap2_clk_allow_idle(struct clk *clk);
  234. int omap2_clk_deny_idle(struct clk *clk);
  235. unsigned long omap2_dpllcore_recalc(struct clk_hw *hw,
  236. unsigned long parent_rate);
  237. int omap2_reprogram_dpllcore(struct clk_hw *clk, unsigned long rate,
  238. unsigned long parent_rate);
  239. void omap2xxx_clkt_dpllcore_init(struct clk_hw *hw);
  240. void omap2xxx_clkt_vps_init(void);
  241. unsigned long omap2_get_dpll_rate(struct clk_hw_omap *clk);
  242. void ti_dt_clk_init_retry_clks(void);
  243. void ti_dt_clockdomains_setup(void);
  244. int ti_clk_setup_ll_ops(struct ti_clk_ll_ops *ops);
  245. struct regmap;
  246. int omap2_clk_provider_init(struct device_node *parent, int index,
  247. struct regmap *syscon, void __iomem *mem);
  248. void omap2_clk_legacy_provider_init(int index, void __iomem *mem);
  249. int omap3430_dt_clk_init(void);
  250. int omap3630_dt_clk_init(void);
  251. int am35xx_dt_clk_init(void);
  252. int dm814x_dt_clk_init(void);
  253. int dm816x_dt_clk_init(void);
  254. int omap4xxx_dt_clk_init(void);
  255. int omap5xxx_dt_clk_init(void);
  256. int dra7xx_dt_clk_init(void);
  257. int am33xx_dt_clk_init(void);
  258. int am43xx_dt_clk_init(void);
  259. int omap2420_dt_clk_init(void);
  260. int omap2430_dt_clk_init(void);
  261. struct ti_clk_features {
  262. u32 flags;
  263. long fint_min;
  264. long fint_max;
  265. long fint_band1_max;
  266. long fint_band2_min;
  267. u8 dpll_bypass_vals;
  268. u8 cm_idlest_val;
  269. };
  270. #define TI_CLK_DPLL_HAS_FREQSEL BIT(0)
  271. #define TI_CLK_DPLL4_DENY_REPROGRAM BIT(1)
  272. #define TI_CLK_DISABLE_CLKDM_CONTROL BIT(2)
  273. #define TI_CLK_ERRATA_I810 BIT(3)
  274. void ti_clk_setup_features(struct ti_clk_features *features);
  275. const struct ti_clk_features *ti_clk_get_features(void);
  276. int omap3_noncore_dpll_save_context(struct clk_hw *hw);
  277. void omap3_noncore_dpll_restore_context(struct clk_hw *hw);
  278. int omap3_core_dpll_save_context(struct clk_hw *hw);
  279. void omap3_core_dpll_restore_context(struct clk_hw *hw);
  280. extern const struct clk_hw_omap_ops clkhwops_omap2xxx_dpll;
  281. #ifdef CONFIG_ATAGS
  282. int omap3430_clk_legacy_init(void);
  283. int omap3430es1_clk_legacy_init(void);
  284. int omap36xx_clk_legacy_init(void);
  285. int am35xx_clk_legacy_init(void);
  286. #else
  287. static inline int omap3430_clk_legacy_init(void) { return -ENXIO; }
  288. static inline int omap3430es1_clk_legacy_init(void) { return -ENXIO; }
  289. static inline int omap36xx_clk_legacy_init(void) { return -ENXIO; }
  290. static inline int am35xx_clk_legacy_init(void) { return -ENXIO; }
  291. #endif
  292. #endif