ti.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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/clkdev.h>
  18. /**
  19. * struct dpll_data - DPLL registers and integration data
  20. * @mult_div1_reg: register containing the DPLL M and N bitfields
  21. * @mult_mask: mask of the DPLL M bitfield in @mult_div1_reg
  22. * @div1_mask: mask of the DPLL N bitfield in @mult_div1_reg
  23. * @clk_bypass: struct clk pointer to the clock's bypass clock input
  24. * @clk_ref: struct clk pointer to the clock's reference clock input
  25. * @control_reg: register containing the DPLL mode bitfield
  26. * @enable_mask: mask of the DPLL mode bitfield in @control_reg
  27. * @last_rounded_rate: cache of the last rate result of omap2_dpll_round_rate()
  28. * @last_rounded_m: cache of the last M result of omap2_dpll_round_rate()
  29. * @last_rounded_m4xen: cache of the last M4X result of
  30. * omap4_dpll_regm4xen_round_rate()
  31. * @last_rounded_lpmode: cache of the last lpmode result of
  32. * omap4_dpll_lpmode_recalc()
  33. * @max_multiplier: maximum valid non-bypass multiplier value (actual)
  34. * @last_rounded_n: cache of the last N result of omap2_dpll_round_rate()
  35. * @min_divider: minimum valid non-bypass divider value (actual)
  36. * @max_divider: maximum valid non-bypass divider value (actual)
  37. * @modes: possible values of @enable_mask
  38. * @autoidle_reg: register containing the DPLL autoidle mode bitfield
  39. * @idlest_reg: register containing the DPLL idle status bitfield
  40. * @autoidle_mask: mask of the DPLL autoidle mode bitfield in @autoidle_reg
  41. * @freqsel_mask: mask of the DPLL jitter correction bitfield in @control_reg
  42. * @dcc_mask: mask of the DPLL DCC correction bitfield @mult_div1_reg
  43. * @dcc_rate: rate atleast which DCC @dcc_mask must be set
  44. * @idlest_mask: mask of the DPLL idle status bitfield in @idlest_reg
  45. * @lpmode_mask: mask of the DPLL low-power mode bitfield in @control_reg
  46. * @m4xen_mask: mask of the DPLL M4X multiplier bitfield in @control_reg
  47. * @auto_recal_bit: bitshift of the driftguard enable bit in @control_reg
  48. * @recal_en_bit: bitshift of the PRM_IRQENABLE_* bit for recalibration IRQs
  49. * @recal_st_bit: bitshift of the PRM_IRQSTATUS_* bit for recalibration IRQs
  50. * @flags: DPLL type/features (see below)
  51. *
  52. * Possible values for @flags:
  53. * DPLL_J_TYPE: "J-type DPLL" (only some 36xx, 4xxx DPLLs)
  54. *
  55. * @freqsel_mask is only used on the OMAP34xx family and AM35xx.
  56. *
  57. * XXX Some DPLLs have multiple bypass inputs, so it's not technically
  58. * correct to only have one @clk_bypass pointer.
  59. *
  60. * XXX The runtime-variable fields (@last_rounded_rate, @last_rounded_m,
  61. * @last_rounded_n) should be separated from the runtime-fixed fields
  62. * and placed into a different structure, so that the runtime-fixed data
  63. * can be placed into read-only space.
  64. */
  65. struct dpll_data {
  66. void __iomem *mult_div1_reg;
  67. u32 mult_mask;
  68. u32 div1_mask;
  69. struct clk *clk_bypass;
  70. struct clk *clk_ref;
  71. void __iomem *control_reg;
  72. u32 enable_mask;
  73. unsigned long last_rounded_rate;
  74. u16 last_rounded_m;
  75. u8 last_rounded_m4xen;
  76. u8 last_rounded_lpmode;
  77. u16 max_multiplier;
  78. u8 last_rounded_n;
  79. u8 min_divider;
  80. u16 max_divider;
  81. u8 modes;
  82. void __iomem *autoidle_reg;
  83. void __iomem *idlest_reg;
  84. u32 autoidle_mask;
  85. u32 freqsel_mask;
  86. u32 idlest_mask;
  87. u32 dco_mask;
  88. u32 sddiv_mask;
  89. u32 dcc_mask;
  90. unsigned long dcc_rate;
  91. u32 lpmode_mask;
  92. u32 m4xen_mask;
  93. u8 auto_recal_bit;
  94. u8 recal_en_bit;
  95. u8 recal_st_bit;
  96. u8 flags;
  97. };
  98. struct clk_hw_omap;
  99. /**
  100. * struct clk_hw_omap_ops - OMAP clk ops
  101. * @find_idlest: find idlest register information for a clock
  102. * @find_companion: find companion clock register information for a clock,
  103. * basically converts CM_ICLKEN* <-> CM_FCLKEN*
  104. * @allow_idle: enables autoidle hardware functionality for a clock
  105. * @deny_idle: prevent autoidle hardware functionality for a clock
  106. */
  107. struct clk_hw_omap_ops {
  108. void (*find_idlest)(struct clk_hw_omap *oclk,
  109. void __iomem **idlest_reg,
  110. u8 *idlest_bit, u8 *idlest_val);
  111. void (*find_companion)(struct clk_hw_omap *oclk,
  112. void __iomem **other_reg,
  113. u8 *other_bit);
  114. void (*allow_idle)(struct clk_hw_omap *oclk);
  115. void (*deny_idle)(struct clk_hw_omap *oclk);
  116. };
  117. /**
  118. * struct clk_hw_omap - OMAP struct clk
  119. * @node: list_head connecting this clock into the full clock list
  120. * @enable_reg: register to write to enable the clock (see @enable_bit)
  121. * @enable_bit: bitshift to write to enable/disable the clock (see @enable_reg)
  122. * @flags: see "struct clk.flags possibilities" above
  123. * @clksel_reg: for clksel clks, register va containing src/divisor select
  124. * @clksel_mask: bitmask in @clksel_reg for the src/divisor selector
  125. * @clksel: for clksel clks, pointer to struct clksel for this clock
  126. * @dpll_data: for DPLLs, pointer to struct dpll_data for this clock
  127. * @clkdm_name: clockdomain name that this clock is contained in
  128. * @clkdm: pointer to struct clockdomain, resolved from @clkdm_name at runtime
  129. * @ops: clock ops for this clock
  130. */
  131. struct clk_hw_omap {
  132. struct clk_hw hw;
  133. struct list_head node;
  134. unsigned long fixed_rate;
  135. u8 fixed_div;
  136. void __iomem *enable_reg;
  137. u8 enable_bit;
  138. u8 flags;
  139. void __iomem *clksel_reg;
  140. u32 clksel_mask;
  141. const struct clksel *clksel;
  142. struct dpll_data *dpll_data;
  143. const char *clkdm_name;
  144. struct clockdomain *clkdm;
  145. const struct clk_hw_omap_ops *ops;
  146. };
  147. /*
  148. * struct clk_hw_omap.flags possibilities
  149. *
  150. * XXX document the rest of the clock flags here
  151. *
  152. * ENABLE_REG_32BIT: (OMAP1 only) clock control register must be accessed
  153. * with 32bit ops, by default OMAP1 uses 16bit ops.
  154. * CLOCK_IDLE_CONTROL: (OMAP1 only) clock has autoidle support.
  155. * CLOCK_NO_IDLE_PARENT: (OMAP1 only) when clock is enabled, its parent
  156. * clock is put to no-idle mode.
  157. * ENABLE_ON_INIT: Clock is enabled on init.
  158. * INVERT_ENABLE: By default, clock enable bit behavior is '1' enable, '0'
  159. * disable. This inverts the behavior making '0' enable and '1' disable.
  160. * CLOCK_CLKOUTX2: (OMAP4 only) DPLL CLKOUT and CLKOUTX2 GATE_CTRL
  161. * bits share the same register. This flag allows the
  162. * omap4_dpllmx*() code to determine which GATE_CTRL bit field
  163. * should be used. This is a temporary solution - a better approach
  164. * would be to associate clock type-specific data with the clock,
  165. * similar to the struct dpll_data approach.
  166. * MEMMAP_ADDRESSING: Use memmap addressing to access clock registers.
  167. */
  168. #define ENABLE_REG_32BIT (1 << 0) /* Use 32-bit access */
  169. #define CLOCK_IDLE_CONTROL (1 << 1)
  170. #define CLOCK_NO_IDLE_PARENT (1 << 2)
  171. #define ENABLE_ON_INIT (1 << 3) /* Enable upon framework init */
  172. #define INVERT_ENABLE (1 << 4) /* 0 enables, 1 disables */
  173. #define CLOCK_CLKOUTX2 (1 << 5)
  174. #define MEMMAP_ADDRESSING (1 << 6)
  175. /* CM_CLKEN_PLL*.EN* bit values - not all are available for every DPLL */
  176. #define DPLL_LOW_POWER_STOP 0x1
  177. #define DPLL_LOW_POWER_BYPASS 0x5
  178. #define DPLL_LOCKED 0x7
  179. /* DPLL Type and DCO Selection Flags */
  180. #define DPLL_J_TYPE 0x1
  181. /* Composite clock component types */
  182. enum {
  183. CLK_COMPONENT_TYPE_GATE = 0,
  184. CLK_COMPONENT_TYPE_DIVIDER,
  185. CLK_COMPONENT_TYPE_MUX,
  186. CLK_COMPONENT_TYPE_MAX,
  187. };
  188. /**
  189. * struct ti_dt_clk - OMAP DT clock alias declarations
  190. * @lk: clock lookup definition
  191. * @node_name: clock DT node to map to
  192. */
  193. struct ti_dt_clk {
  194. struct clk_lookup lk;
  195. char *node_name;
  196. };
  197. #define DT_CLK(dev, con, name) \
  198. { \
  199. .lk = { \
  200. .dev_id = dev, \
  201. .con_id = con, \
  202. }, \
  203. .node_name = name, \
  204. }
  205. /* Maximum number of clock memmaps */
  206. #define CLK_MAX_MEMMAPS 4
  207. typedef void (*ti_of_clk_init_cb_t)(struct clk_hw *, struct device_node *);
  208. /**
  209. * struct clk_omap_reg - OMAP register declaration
  210. * @offset: offset from the master IP module base address
  211. * @index: index of the master IP module
  212. */
  213. struct clk_omap_reg {
  214. u16 offset;
  215. u16 index;
  216. };
  217. /**
  218. * struct ti_clk_ll_ops - low-level register access ops for a clock
  219. * @clk_readl: pointer to register read function
  220. * @clk_writel: pointer to register write function
  221. *
  222. * Low-level register access ops are generally used by the basic clock types
  223. * (clk-gate, clk-mux, clk-divider etc.) to provide support for various
  224. * low-level hardware interfaces (direct MMIO, regmap etc.), but can also be
  225. * used by other hardware-specific clock drivers if needed.
  226. */
  227. struct ti_clk_ll_ops {
  228. u32 (*clk_readl)(void __iomem *reg);
  229. void (*clk_writel)(u32 val, void __iomem *reg);
  230. };
  231. extern struct ti_clk_ll_ops *ti_clk_ll_ops;
  232. extern const struct clk_ops ti_clk_divider_ops;
  233. extern const struct clk_ops ti_clk_mux_ops;
  234. #define to_clk_hw_omap(_hw) container_of(_hw, struct clk_hw_omap, hw)
  235. void omap2_init_clk_hw_omap_clocks(struct clk *clk);
  236. int omap3_noncore_dpll_enable(struct clk_hw *hw);
  237. void omap3_noncore_dpll_disable(struct clk_hw *hw);
  238. int omap3_noncore_dpll_set_rate(struct clk_hw *hw, unsigned long rate,
  239. unsigned long parent_rate);
  240. unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw,
  241. unsigned long parent_rate);
  242. long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw,
  243. unsigned long target_rate,
  244. unsigned long *parent_rate);
  245. u8 omap2_init_dpll_parent(struct clk_hw *hw);
  246. unsigned long omap3_dpll_recalc(struct clk_hw *hw, unsigned long parent_rate);
  247. long omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate,
  248. unsigned long *parent_rate);
  249. void omap2_init_clk_clkdm(struct clk_hw *clk);
  250. unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw,
  251. unsigned long parent_rate);
  252. int omap3_clkoutx2_set_rate(struct clk_hw *hw, unsigned long rate,
  253. unsigned long parent_rate);
  254. long omap3_clkoutx2_round_rate(struct clk_hw *hw, unsigned long rate,
  255. unsigned long *prate);
  256. int omap2_clkops_enable_clkdm(struct clk_hw *hw);
  257. void omap2_clkops_disable_clkdm(struct clk_hw *hw);
  258. int omap2_clk_disable_autoidle_all(void);
  259. void omap2_clk_enable_init_clocks(const char **clk_names, u8 num_clocks);
  260. int omap3_dpll4_set_rate(struct clk_hw *clk, unsigned long rate,
  261. unsigned long parent_rate);
  262. int omap2_dflt_clk_enable(struct clk_hw *hw);
  263. void omap2_dflt_clk_disable(struct clk_hw *hw);
  264. int omap2_dflt_clk_is_enabled(struct clk_hw *hw);
  265. void omap3_clk_lock_dpll5(void);
  266. unsigned long omap2_dpllcore_recalc(struct clk_hw *hw,
  267. unsigned long parent_rate);
  268. int omap2_reprogram_dpllcore(struct clk_hw *clk, unsigned long rate,
  269. unsigned long parent_rate);
  270. void omap2xxx_clkt_dpllcore_init(struct clk_hw *hw);
  271. void omap2xxx_clkt_vps_init(void);
  272. void __iomem *ti_clk_get_reg_addr(struct device_node *node, int index);
  273. void ti_dt_clocks_register(struct ti_dt_clk *oclks);
  274. void ti_dt_clk_init_provider(struct device_node *np, int index);
  275. void ti_dt_clk_init_retry_clks(void);
  276. void ti_dt_clockdomains_setup(void);
  277. int ti_clk_retry_init(struct device_node *node, struct clk_hw *hw,
  278. ti_of_clk_init_cb_t func);
  279. int of_ti_clk_autoidle_setup(struct device_node *node);
  280. int ti_clk_add_component(struct device_node *node, struct clk_hw *hw, int type);
  281. int omap3430_dt_clk_init(void);
  282. int omap3630_dt_clk_init(void);
  283. int am35xx_dt_clk_init(void);
  284. int ti81xx_dt_clk_init(void);
  285. int omap4xxx_dt_clk_init(void);
  286. int omap5xxx_dt_clk_init(void);
  287. int dra7xx_dt_clk_init(void);
  288. int am33xx_dt_clk_init(void);
  289. int am43xx_dt_clk_init(void);
  290. int omap2420_dt_clk_init(void);
  291. int omap2430_dt_clk_init(void);
  292. #ifdef CONFIG_OF
  293. void of_ti_clk_allow_autoidle_all(void);
  294. void of_ti_clk_deny_autoidle_all(void);
  295. #else
  296. static inline void of_ti_clk_allow_autoidle_all(void) { }
  297. static inline void of_ti_clk_deny_autoidle_all(void) { }
  298. #endif
  299. extern const struct clk_hw_omap_ops clkhwops_omap2xxx_dpll;
  300. extern const struct clk_hw_omap_ops clkhwops_omap2430_i2chs_wait;
  301. extern const struct clk_hw_omap_ops clkhwops_omap3_dpll;
  302. extern const struct clk_hw_omap_ops clkhwops_omap4_dpllmx;
  303. extern const struct clk_hw_omap_ops clkhwops_wait;
  304. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait;
  305. extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait;
  306. extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_wait;
  307. extern const struct clk_hw_omap_ops clkhwops_iclk;
  308. extern const struct clk_hw_omap_ops clkhwops_iclk_wait;
  309. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_ssi_wait;
  310. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_dss_usbhost_wait;
  311. extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_hsotgusb_wait;
  312. #endif