ti.h 12 KB

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