clk-3xxx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OMAP3 Clock init
  4. *
  5. * Copyright (C) 2013 Texas Instruments, Inc
  6. * Tero Kristo ([email protected])
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/list.h>
  10. #include <linux/clk.h>
  11. #include <linux/clk-provider.h>
  12. #include <linux/clk/ti.h>
  13. #include "clock.h"
  14. #define OMAP3430ES2_ST_DSS_IDLE_SHIFT 1
  15. #define OMAP3430ES2_ST_HSOTGUSB_IDLE_SHIFT 5
  16. #define OMAP3430ES2_ST_SSI_IDLE_SHIFT 8
  17. #define OMAP34XX_CM_IDLEST_VAL 1
  18. /*
  19. * In AM35xx IPSS, the {ICK,FCK} enable bits for modules are exported
  20. * in the same register at a bit offset of 0x8. The EN_ACK for ICK is
  21. * at an offset of 4 from ICK enable bit.
  22. */
  23. #define AM35XX_IPSS_ICK_MASK 0xF
  24. #define AM35XX_IPSS_ICK_EN_ACK_OFFSET 0x4
  25. #define AM35XX_IPSS_ICK_FCK_OFFSET 0x8
  26. #define AM35XX_IPSS_CLK_IDLEST_VAL 0
  27. #define AM35XX_ST_IPSS_SHIFT 5
  28. /**
  29. * omap3430es2_clk_ssi_find_idlest - return CM_IDLEST info for SSI
  30. * @clk: struct clk * being enabled
  31. * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
  32. * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
  33. * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
  34. *
  35. * The OMAP3430ES2 SSI target CM_IDLEST bit is at a different shift
  36. * from the CM_{I,F}CLKEN bit. Pass back the correct info via
  37. * @idlest_reg and @idlest_bit. No return value.
  38. */
  39. static void omap3430es2_clk_ssi_find_idlest(struct clk_hw_omap *clk,
  40. struct clk_omap_reg *idlest_reg,
  41. u8 *idlest_bit,
  42. u8 *idlest_val)
  43. {
  44. memcpy(idlest_reg, &clk->enable_reg, sizeof(*idlest_reg));
  45. idlest_reg->offset &= ~0xf0;
  46. idlest_reg->offset |= 0x20;
  47. *idlest_bit = OMAP3430ES2_ST_SSI_IDLE_SHIFT;
  48. *idlest_val = OMAP34XX_CM_IDLEST_VAL;
  49. }
  50. const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_ssi_wait = {
  51. .allow_idle = omap2_clkt_iclk_allow_idle,
  52. .deny_idle = omap2_clkt_iclk_deny_idle,
  53. .find_idlest = omap3430es2_clk_ssi_find_idlest,
  54. .find_companion = omap2_clk_dflt_find_companion,
  55. };
  56. /**
  57. * omap3430es2_clk_dss_usbhost_find_idlest - CM_IDLEST info for DSS, USBHOST
  58. * @clk: struct clk * being enabled
  59. * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
  60. * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
  61. * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
  62. *
  63. * Some OMAP modules on OMAP3 ES2+ chips have both initiator and
  64. * target IDLEST bits. For our purposes, we are concerned with the
  65. * target IDLEST bits, which exist at a different bit position than
  66. * the *CLKEN bit position for these modules (DSS and USBHOST) (The
  67. * default find_idlest code assumes that they are at the same
  68. * position.) No return value.
  69. */
  70. static void
  71. omap3430es2_clk_dss_usbhost_find_idlest(struct clk_hw_omap *clk,
  72. struct clk_omap_reg *idlest_reg,
  73. u8 *idlest_bit, u8 *idlest_val)
  74. {
  75. memcpy(idlest_reg, &clk->enable_reg, sizeof(*idlest_reg));
  76. idlest_reg->offset &= ~0xf0;
  77. idlest_reg->offset |= 0x20;
  78. /* USBHOST_IDLE has same shift */
  79. *idlest_bit = OMAP3430ES2_ST_DSS_IDLE_SHIFT;
  80. *idlest_val = OMAP34XX_CM_IDLEST_VAL;
  81. }
  82. const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait = {
  83. .find_idlest = omap3430es2_clk_dss_usbhost_find_idlest,
  84. .find_companion = omap2_clk_dflt_find_companion,
  85. };
  86. const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_dss_usbhost_wait = {
  87. .allow_idle = omap2_clkt_iclk_allow_idle,
  88. .deny_idle = omap2_clkt_iclk_deny_idle,
  89. .find_idlest = omap3430es2_clk_dss_usbhost_find_idlest,
  90. .find_companion = omap2_clk_dflt_find_companion,
  91. };
  92. /**
  93. * omap3430es2_clk_hsotgusb_find_idlest - return CM_IDLEST info for HSOTGUSB
  94. * @clk: struct clk * being enabled
  95. * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
  96. * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
  97. * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
  98. *
  99. * The OMAP3430ES2 HSOTGUSB target CM_IDLEST bit is at a different
  100. * shift from the CM_{I,F}CLKEN bit. Pass back the correct info via
  101. * @idlest_reg and @idlest_bit. No return value.
  102. */
  103. static void
  104. omap3430es2_clk_hsotgusb_find_idlest(struct clk_hw_omap *clk,
  105. struct clk_omap_reg *idlest_reg,
  106. u8 *idlest_bit,
  107. u8 *idlest_val)
  108. {
  109. memcpy(idlest_reg, &clk->enable_reg, sizeof(*idlest_reg));
  110. idlest_reg->offset &= ~0xf0;
  111. idlest_reg->offset |= 0x20;
  112. *idlest_bit = OMAP3430ES2_ST_HSOTGUSB_IDLE_SHIFT;
  113. *idlest_val = OMAP34XX_CM_IDLEST_VAL;
  114. }
  115. const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_hsotgusb_wait = {
  116. .allow_idle = omap2_clkt_iclk_allow_idle,
  117. .deny_idle = omap2_clkt_iclk_deny_idle,
  118. .find_idlest = omap3430es2_clk_hsotgusb_find_idlest,
  119. .find_companion = omap2_clk_dflt_find_companion,
  120. };
  121. /**
  122. * am35xx_clk_find_idlest - return clock ACK info for AM35XX IPSS
  123. * @clk: struct clk * being enabled
  124. * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
  125. * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
  126. * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
  127. *
  128. * The interface clocks on AM35xx IPSS reflects the clock idle status
  129. * in the enable register itsel at a bit offset of 4 from the enable
  130. * bit. A value of 1 indicates that clock is enabled.
  131. */
  132. static void am35xx_clk_find_idlest(struct clk_hw_omap *clk,
  133. struct clk_omap_reg *idlest_reg,
  134. u8 *idlest_bit,
  135. u8 *idlest_val)
  136. {
  137. memcpy(idlest_reg, &clk->enable_reg, sizeof(*idlest_reg));
  138. *idlest_bit = clk->enable_bit + AM35XX_IPSS_ICK_EN_ACK_OFFSET;
  139. *idlest_val = AM35XX_IPSS_CLK_IDLEST_VAL;
  140. }
  141. /**
  142. * am35xx_clk_find_companion - find companion clock to @clk
  143. * @clk: struct clk * to find the companion clock of
  144. * @other_reg: void __iomem ** to return the companion clock CM_*CLKEN va in
  145. * @other_bit: u8 ** to return the companion clock bit shift in
  146. *
  147. * Some clocks don't have companion clocks. For example, modules with
  148. * only an interface clock (such as HECC) don't have a companion
  149. * clock. Right now, this code relies on the hardware exporting a bit
  150. * in the correct companion register that indicates that the
  151. * nonexistent 'companion clock' is active. Future patches will
  152. * associate this type of code with per-module data structures to
  153. * avoid this issue, and remove the casts. No return value.
  154. */
  155. static void am35xx_clk_find_companion(struct clk_hw_omap *clk,
  156. struct clk_omap_reg *other_reg,
  157. u8 *other_bit)
  158. {
  159. memcpy(other_reg, &clk->enable_reg, sizeof(*other_reg));
  160. if (clk->enable_bit & AM35XX_IPSS_ICK_MASK)
  161. *other_bit = clk->enable_bit + AM35XX_IPSS_ICK_FCK_OFFSET;
  162. else
  163. *other_bit = clk->enable_bit - AM35XX_IPSS_ICK_FCK_OFFSET;
  164. }
  165. const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait = {
  166. .find_idlest = am35xx_clk_find_idlest,
  167. .find_companion = am35xx_clk_find_companion,
  168. };
  169. /**
  170. * am35xx_clk_ipss_find_idlest - return CM_IDLEST info for IPSS
  171. * @clk: struct clk * being enabled
  172. * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
  173. * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
  174. * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
  175. *
  176. * The IPSS target CM_IDLEST bit is at a different shift from the
  177. * CM_{I,F}CLKEN bit. Pass back the correct info via @idlest_reg
  178. * and @idlest_bit. No return value.
  179. */
  180. static void am35xx_clk_ipss_find_idlest(struct clk_hw_omap *clk,
  181. struct clk_omap_reg *idlest_reg,
  182. u8 *idlest_bit,
  183. u8 *idlest_val)
  184. {
  185. memcpy(idlest_reg, &clk->enable_reg, sizeof(*idlest_reg));
  186. idlest_reg->offset &= ~0xf0;
  187. idlest_reg->offset |= 0x20;
  188. *idlest_bit = AM35XX_ST_IPSS_SHIFT;
  189. *idlest_val = OMAP34XX_CM_IDLEST_VAL;
  190. }
  191. const struct clk_hw_omap_ops clkhwops_am35xx_ipss_wait = {
  192. .allow_idle = omap2_clkt_iclk_allow_idle,
  193. .deny_idle = omap2_clkt_iclk_deny_idle,
  194. .find_idlest = am35xx_clk_ipss_find_idlest,
  195. .find_companion = omap2_clk_dflt_find_companion,
  196. };
  197. static struct ti_dt_clk omap3xxx_clks[] = {
  198. DT_CLK(NULL, "timer_32k_ck", "omap_32k_fck"),
  199. DT_CLK(NULL, "timer_sys_ck", "sys_ck"),
  200. { .node_name = NULL },
  201. };
  202. static struct ti_dt_clk omap36xx_omap3430es2plus_clks[] = {
  203. DT_CLK(NULL, "ssi_ssr_fck", "ssi_ssr_fck_3430es2"),
  204. DT_CLK(NULL, "ssi_sst_fck", "ssi_sst_fck_3430es2"),
  205. DT_CLK(NULL, "hsotgusb_ick", "hsotgusb_ick_3430es2"),
  206. DT_CLK(NULL, "ssi_ick", "ssi_ick_3430es2"),
  207. { .node_name = NULL },
  208. };
  209. static struct ti_dt_clk omap3430es1_clks[] = {
  210. DT_CLK(NULL, "ssi_ssr_fck", "ssi_ssr_fck_3430es1"),
  211. DT_CLK(NULL, "ssi_sst_fck", "ssi_sst_fck_3430es1"),
  212. DT_CLK(NULL, "hsotgusb_ick", "hsotgusb_ick_3430es1"),
  213. DT_CLK(NULL, "ssi_ick", "ssi_ick_3430es1"),
  214. DT_CLK(NULL, "dss1_alwon_fck", "dss1_alwon_fck_3430es1"),
  215. DT_CLK(NULL, "dss_ick", "dss_ick_3430es1"),
  216. { .node_name = NULL },
  217. };
  218. static struct ti_dt_clk omap36xx_am35xx_omap3430es2plus_clks[] = {
  219. DT_CLK(NULL, "dss1_alwon_fck", "dss1_alwon_fck_3430es2"),
  220. DT_CLK(NULL, "dss_ick", "dss_ick_3430es2"),
  221. { .node_name = NULL },
  222. };
  223. static struct ti_dt_clk am35xx_clks[] = {
  224. DT_CLK(NULL, "hsotgusb_ick", "hsotgusb_ick_am35xx"),
  225. DT_CLK(NULL, "hsotgusb_fck", "hsotgusb_fck_am35xx"),
  226. DT_CLK(NULL, "uart4_ick", "uart4_ick_am35xx"),
  227. DT_CLK(NULL, "uart4_fck", "uart4_fck_am35xx"),
  228. { .node_name = NULL },
  229. };
  230. static const char *enable_init_clks[] = {
  231. "sdrc_ick",
  232. "gpmc_fck",
  233. "omapctrl_ick",
  234. };
  235. enum {
  236. OMAP3_SOC_AM35XX,
  237. OMAP3_SOC_OMAP3430_ES1,
  238. OMAP3_SOC_OMAP3430_ES2_PLUS,
  239. OMAP3_SOC_OMAP3630,
  240. };
  241. /**
  242. * omap3_clk_lock_dpll5 - locks DPLL5
  243. *
  244. * Locks DPLL5 to a pre-defined frequency. This is required for proper
  245. * operation of USB.
  246. */
  247. void __init omap3_clk_lock_dpll5(void)
  248. {
  249. struct clk *dpll5_clk;
  250. struct clk *dpll5_m2_clk;
  251. /*
  252. * Errata sprz319f advisory 2.1 documents a USB host clock drift issue
  253. * that can be worked around using specially crafted dpll5 settings
  254. * with a dpll5_m2 divider set to 8. Set the dpll5 rate to 8x the USB
  255. * host clock rate, its .set_rate handler() will detect that frequency
  256. * and use the errata settings.
  257. */
  258. dpll5_clk = clk_get(NULL, "dpll5_ck");
  259. clk_set_rate(dpll5_clk, OMAP3_DPLL5_FREQ_FOR_USBHOST * 8);
  260. clk_prepare_enable(dpll5_clk);
  261. /* Program dpll5_m2_clk divider */
  262. dpll5_m2_clk = clk_get(NULL, "dpll5_m2_ck");
  263. clk_prepare_enable(dpll5_m2_clk);
  264. clk_set_rate(dpll5_m2_clk, OMAP3_DPLL5_FREQ_FOR_USBHOST);
  265. clk_disable_unprepare(dpll5_m2_clk);
  266. clk_disable_unprepare(dpll5_clk);
  267. }
  268. static int __init omap3xxx_dt_clk_init(int soc_type)
  269. {
  270. if (soc_type == OMAP3_SOC_AM35XX || soc_type == OMAP3_SOC_OMAP3630 ||
  271. soc_type == OMAP3_SOC_OMAP3430_ES1 ||
  272. soc_type == OMAP3_SOC_OMAP3430_ES2_PLUS)
  273. ti_dt_clocks_register(omap3xxx_clks);
  274. if (soc_type == OMAP3_SOC_AM35XX)
  275. ti_dt_clocks_register(am35xx_clks);
  276. if (soc_type == OMAP3_SOC_OMAP3630 || soc_type == OMAP3_SOC_AM35XX ||
  277. soc_type == OMAP3_SOC_OMAP3430_ES2_PLUS)
  278. ti_dt_clocks_register(omap36xx_am35xx_omap3430es2plus_clks);
  279. if (soc_type == OMAP3_SOC_OMAP3430_ES1)
  280. ti_dt_clocks_register(omap3430es1_clks);
  281. if (soc_type == OMAP3_SOC_OMAP3430_ES2_PLUS ||
  282. soc_type == OMAP3_SOC_OMAP3630)
  283. ti_dt_clocks_register(omap36xx_omap3430es2plus_clks);
  284. omap2_clk_disable_autoidle_all();
  285. ti_clk_add_aliases();
  286. omap2_clk_enable_init_clocks(enable_init_clks,
  287. ARRAY_SIZE(enable_init_clks));
  288. pr_info("Clocking rate (Crystal/Core/MPU): %ld.%01ld/%ld/%ld MHz\n",
  289. (clk_get_rate(clk_get_sys(NULL, "osc_sys_ck")) / 1000000),
  290. (clk_get_rate(clk_get_sys(NULL, "osc_sys_ck")) / 100000) % 10,
  291. (clk_get_rate(clk_get_sys(NULL, "core_ck")) / 1000000),
  292. (clk_get_rate(clk_get_sys(NULL, "arm_fck")) / 1000000));
  293. if (soc_type != OMAP3_SOC_OMAP3430_ES1)
  294. omap3_clk_lock_dpll5();
  295. return 0;
  296. }
  297. int __init omap3430_dt_clk_init(void)
  298. {
  299. return omap3xxx_dt_clk_init(OMAP3_SOC_OMAP3430_ES2_PLUS);
  300. }
  301. int __init omap3630_dt_clk_init(void)
  302. {
  303. return omap3xxx_dt_clk_init(OMAP3_SOC_OMAP3630);
  304. }
  305. int __init am35xx_dt_clk_init(void)
  306. {
  307. return omap3xxx_dt_clk_init(OMAP3_SOC_AM35XX);
  308. }