clock.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. /*
  2. * (C) Copyright 2008
  3. * Texas Instruments, <www.ti.com>
  4. *
  5. * Author :
  6. * Manikandan Pillai <mani.pillai@ti.com>
  7. *
  8. * Derived from Beagle Board and OMAP3 SDP code by
  9. * Richard Woodruff <r-woodruff2@ti.com>
  10. * Syed Mohammed Khasim <khasim@ti.com>
  11. *
  12. * SPDX-License-Identifier: GPL-2.0+
  13. */
  14. #include <common.h>
  15. #include <asm/io.h>
  16. #include <asm/arch/clock.h>
  17. #include <asm/arch/clocks_omap3.h>
  18. #include <asm/arch/mem.h>
  19. #include <asm/arch/sys_proto.h>
  20. #include <environment.h>
  21. #include <command.h>
  22. /******************************************************************************
  23. * get_sys_clk_speed() - determine reference oscillator speed
  24. * based on known 32kHz clock and gptimer.
  25. *****************************************************************************/
  26. u32 get_osc_clk_speed(void)
  27. {
  28. u32 start, cstart, cend, cdiff, cdiv, val;
  29. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  30. struct prm *prm_base = (struct prm *)PRM_BASE;
  31. struct gptimer *gpt1_base = (struct gptimer *)OMAP34XX_GPT1;
  32. struct s32ktimer *s32k_base = (struct s32ktimer *)SYNC_32KTIMER_BASE;
  33. val = readl(&prm_base->clksrc_ctrl);
  34. if (val & SYSCLKDIV_2)
  35. cdiv = 2;
  36. else
  37. cdiv = 1;
  38. /* enable timer2 */
  39. val = readl(&prcm_base->clksel_wkup) | CLKSEL_GPT1;
  40. /* select sys_clk for GPT1 */
  41. writel(val, &prcm_base->clksel_wkup);
  42. /* Enable I and F Clocks for GPT1 */
  43. val = readl(&prcm_base->iclken_wkup) | EN_GPT1 | EN_32KSYNC;
  44. writel(val, &prcm_base->iclken_wkup);
  45. val = readl(&prcm_base->fclken_wkup) | EN_GPT1;
  46. writel(val, &prcm_base->fclken_wkup);
  47. writel(0, &gpt1_base->tldr); /* start counting at 0 */
  48. writel(GPT_EN, &gpt1_base->tclr); /* enable clock */
  49. /* enable 32kHz source, determine sys_clk via gauging */
  50. /* start time in 20 cycles */
  51. start = 20 + readl(&s32k_base->s32k_cr);
  52. /* dead loop till start time */
  53. while (readl(&s32k_base->s32k_cr) < start);
  54. /* get start sys_clk count */
  55. cstart = readl(&gpt1_base->tcrr);
  56. /* wait for 40 cycles */
  57. while (readl(&s32k_base->s32k_cr) < (start + 20)) ;
  58. cend = readl(&gpt1_base->tcrr); /* get end sys_clk count */
  59. cdiff = cend - cstart; /* get elapsed ticks */
  60. cdiff *= cdiv;
  61. /* based on number of ticks assign speed */
  62. if (cdiff > 19000)
  63. return S38_4M;
  64. else if (cdiff > 15200)
  65. return S26M;
  66. else if (cdiff > 13000)
  67. return S24M;
  68. else if (cdiff > 9000)
  69. return S19_2M;
  70. else if (cdiff > 7600)
  71. return S13M;
  72. else
  73. return S12M;
  74. }
  75. /******************************************************************************
  76. * get_sys_clkin_sel() - returns the sys_clkin_sel field value based on
  77. * input oscillator clock frequency.
  78. *****************************************************************************/
  79. void get_sys_clkin_sel(u32 osc_clk, u32 *sys_clkin_sel)
  80. {
  81. switch(osc_clk) {
  82. case S38_4M:
  83. *sys_clkin_sel = 4;
  84. break;
  85. case S26M:
  86. *sys_clkin_sel = 3;
  87. break;
  88. case S19_2M:
  89. *sys_clkin_sel = 2;
  90. break;
  91. case S13M:
  92. *sys_clkin_sel = 1;
  93. break;
  94. case S12M:
  95. default:
  96. *sys_clkin_sel = 0;
  97. }
  98. }
  99. /*
  100. * OMAP34XX/35XX specific functions
  101. */
  102. static void dpll3_init_34xx(u32 sil_index, u32 clk_index)
  103. {
  104. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  105. dpll_param *ptr = (dpll_param *) get_core_dpll_param();
  106. void (*f_lock_pll) (u32, u32, u32, u32);
  107. int xip_safe, p0, p1, p2, p3;
  108. xip_safe = is_running_in_sram();
  109. /* Moving to the right sysclk and ES rev base */
  110. ptr = ptr + (3 * clk_index) + sil_index;
  111. if (xip_safe) {
  112. /*
  113. * CORE DPLL
  114. * sr32(CM_CLKSEL2_EMU) set override to work when asleep
  115. */
  116. sr32(&prcm_base->clken_pll, 0, 3, PLL_FAST_RELOCK_BYPASS);
  117. wait_on_value(ST_CORE_CLK, 0, &prcm_base->idlest_ckgen,
  118. LDELAY);
  119. /*
  120. * For OMAP3 ES1.0 Errata 1.50, default value directly doesn't
  121. * work. write another value and then default value.
  122. */
  123. /* CM_CLKSEL1_EMU[DIV_DPLL3] */
  124. sr32(&prcm_base->clksel1_emu, 16, 5, (CORE_M3X2 + 1)) ;
  125. sr32(&prcm_base->clksel1_emu, 16, 5, CORE_M3X2);
  126. /* M2 (CORE_DPLL_CLKOUT_DIV): CM_CLKSEL1_PLL[27:31] */
  127. sr32(&prcm_base->clksel1_pll, 27, 5, ptr->m2);
  128. /* M (CORE_DPLL_MULT): CM_CLKSEL1_PLL[16:26] */
  129. sr32(&prcm_base->clksel1_pll, 16, 11, ptr->m);
  130. /* N (CORE_DPLL_DIV): CM_CLKSEL1_PLL[8:14] */
  131. sr32(&prcm_base->clksel1_pll, 8, 7, ptr->n);
  132. /* Source is the CM_96M_FCLK: CM_CLKSEL1_PLL[6] */
  133. sr32(&prcm_base->clksel1_pll, 6, 1, 0);
  134. /* SSI */
  135. sr32(&prcm_base->clksel_core, 8, 4, CORE_SSI_DIV);
  136. /* FSUSB */
  137. sr32(&prcm_base->clksel_core, 4, 2, CORE_FUSB_DIV);
  138. /* L4 */
  139. sr32(&prcm_base->clksel_core, 2, 2, CORE_L4_DIV);
  140. /* L3 */
  141. sr32(&prcm_base->clksel_core, 0, 2, CORE_L3_DIV);
  142. /* GFX */
  143. sr32(&prcm_base->clksel_gfx, 0, 3, GFX_DIV);
  144. /* RESET MGR */
  145. sr32(&prcm_base->clksel_wkup, 1, 2, WKUP_RSM);
  146. /* FREQSEL (CORE_DPLL_FREQSEL): CM_CLKEN_PLL[4:7] */
  147. sr32(&prcm_base->clken_pll, 4, 4, ptr->fsel);
  148. /* LOCK MODE */
  149. sr32(&prcm_base->clken_pll, 0, 3, PLL_LOCK);
  150. wait_on_value(ST_CORE_CLK, 1, &prcm_base->idlest_ckgen,
  151. LDELAY);
  152. } else if (is_running_in_flash()) {
  153. /*
  154. * if running from flash, jump to small relocated code
  155. * area in SRAM.
  156. */
  157. f_lock_pll = (void *) ((u32) &_end_vect - (u32) &_start +
  158. SRAM_VECT_CODE);
  159. p0 = readl(&prcm_base->clken_pll);
  160. sr32(&p0, 0, 3, PLL_FAST_RELOCK_BYPASS);
  161. /* FREQSEL (CORE_DPLL_FREQSEL): CM_CLKEN_PLL[4:7] */
  162. sr32(&p0, 4, 4, ptr->fsel);
  163. p1 = readl(&prcm_base->clksel1_pll);
  164. /* M2 (CORE_DPLL_CLKOUT_DIV): CM_CLKSEL1_PLL[27:31] */
  165. sr32(&p1, 27, 5, ptr->m2);
  166. /* M (CORE_DPLL_MULT): CM_CLKSEL1_PLL[16:26] */
  167. sr32(&p1, 16, 11, ptr->m);
  168. /* N (CORE_DPLL_DIV): CM_CLKSEL1_PLL[8:14] */
  169. sr32(&p1, 8, 7, ptr->n);
  170. /* Source is the CM_96M_FCLK: CM_CLKSEL1_PLL[6] */
  171. sr32(&p1, 6, 1, 0);
  172. p2 = readl(&prcm_base->clksel_core);
  173. /* SSI */
  174. sr32(&p2, 8, 4, CORE_SSI_DIV);
  175. /* FSUSB */
  176. sr32(&p2, 4, 2, CORE_FUSB_DIV);
  177. /* L4 */
  178. sr32(&p2, 2, 2, CORE_L4_DIV);
  179. /* L3 */
  180. sr32(&p2, 0, 2, CORE_L3_DIV);
  181. p3 = (u32)&prcm_base->idlest_ckgen;
  182. (*f_lock_pll) (p0, p1, p2, p3);
  183. }
  184. }
  185. static void dpll4_init_34xx(u32 sil_index, u32 clk_index)
  186. {
  187. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  188. dpll_param *ptr = (dpll_param *) get_per_dpll_param();
  189. /* Moving it to the right sysclk base */
  190. ptr = ptr + clk_index;
  191. /* EN_PERIPH_DPLL: CM_CLKEN_PLL[16:18] */
  192. sr32(&prcm_base->clken_pll, 16, 3, PLL_STOP);
  193. wait_on_value(ST_PERIPH_CLK, 0, &prcm_base->idlest_ckgen, LDELAY);
  194. /*
  195. * Errata 1.50 Workaround for OMAP3 ES1.0 only
  196. * If using default divisors, write default divisor + 1
  197. * and then the actual divisor value
  198. */
  199. /* M6 */
  200. sr32(&prcm_base->clksel1_emu, 24, 5, (PER_M6X2 + 1));
  201. sr32(&prcm_base->clksel1_emu, 24, 5, PER_M6X2);
  202. /* M5 */
  203. sr32(&prcm_base->clksel_cam, 0, 5, (PER_M5X2 + 1));
  204. sr32(&prcm_base->clksel_cam, 0, 5, PER_M5X2);
  205. /* M4 */
  206. sr32(&prcm_base->clksel_dss, 0, 5, (PER_M4X2 + 1));
  207. sr32(&prcm_base->clksel_dss, 0, 5, PER_M4X2);
  208. /* M3 */
  209. sr32(&prcm_base->clksel_dss, 8, 5, (PER_M3X2 + 1));
  210. sr32(&prcm_base->clksel_dss, 8, 5, PER_M3X2);
  211. /* M2 (DIV_96M): CM_CLKSEL3_PLL[0:4] */
  212. sr32(&prcm_base->clksel3_pll, 0, 5, (ptr->m2 + 1));
  213. sr32(&prcm_base->clksel3_pll, 0, 5, ptr->m2);
  214. /* Workaround end */
  215. /* M (PERIPH_DPLL_MULT): CM_CLKSEL2_PLL[8:18] */
  216. sr32(&prcm_base->clksel2_pll, 8, 11, ptr->m);
  217. /* N (PERIPH_DPLL_DIV): CM_CLKSEL2_PLL[0:6] */
  218. sr32(&prcm_base->clksel2_pll, 0, 7, ptr->n);
  219. /* FREQSEL (PERIPH_DPLL_FREQSEL): CM_CLKEN_PLL[20:23] */
  220. sr32(&prcm_base->clken_pll, 20, 4, ptr->fsel);
  221. /* LOCK MODE (EN_PERIPH_DPLL): CM_CLKEN_PLL[16:18] */
  222. sr32(&prcm_base->clken_pll, 16, 3, PLL_LOCK);
  223. wait_on_value(ST_PERIPH_CLK, 2, &prcm_base->idlest_ckgen, LDELAY);
  224. }
  225. static void dpll5_init_34xx(u32 sil_index, u32 clk_index)
  226. {
  227. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  228. dpll_param *ptr = (dpll_param *) get_per2_dpll_param();
  229. /* Moving it to the right sysclk base */
  230. ptr = ptr + clk_index;
  231. /* PER2 DPLL (DPLL5) */
  232. sr32(&prcm_base->clken2_pll, 0, 3, PLL_STOP);
  233. wait_on_value(1, 0, &prcm_base->idlest2_ckgen, LDELAY);
  234. sr32(&prcm_base->clksel5_pll, 0, 5, ptr->m2); /* set M2 (usbtll_fck) */
  235. sr32(&prcm_base->clksel4_pll, 8, 11, ptr->m); /* set m (11-bit multiplier) */
  236. sr32(&prcm_base->clksel4_pll, 0, 7, ptr->n); /* set n (7-bit divider)*/
  237. sr32(&prcm_base->clken_pll, 4, 4, ptr->fsel); /* FREQSEL */
  238. sr32(&prcm_base->clken2_pll, 0, 3, PLL_LOCK); /* lock mode */
  239. wait_on_value(1, 1, &prcm_base->idlest2_ckgen, LDELAY);
  240. }
  241. static void mpu_init_34xx(u32 sil_index, u32 clk_index)
  242. {
  243. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  244. dpll_param *ptr = (dpll_param *) get_mpu_dpll_param();
  245. /* Moving to the right sysclk and ES rev base */
  246. ptr = ptr + (3 * clk_index) + sil_index;
  247. /* MPU DPLL (unlocked already) */
  248. /* M2 (MPU_DPLL_CLKOUT_DIV) : CM_CLKSEL2_PLL_MPU[0:4] */
  249. sr32(&prcm_base->clksel2_pll_mpu, 0, 5, ptr->m2);
  250. /* M (MPU_DPLL_MULT) : CM_CLKSEL2_PLL_MPU[8:18] */
  251. sr32(&prcm_base->clksel1_pll_mpu, 8, 11, ptr->m);
  252. /* N (MPU_DPLL_DIV) : CM_CLKSEL2_PLL_MPU[0:6] */
  253. sr32(&prcm_base->clksel1_pll_mpu, 0, 7, ptr->n);
  254. /* FREQSEL (MPU_DPLL_FREQSEL) : CM_CLKEN_PLL_MPU[4:7] */
  255. sr32(&prcm_base->clken_pll_mpu, 4, 4, ptr->fsel);
  256. }
  257. static void iva_init_34xx(u32 sil_index, u32 clk_index)
  258. {
  259. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  260. dpll_param *ptr = (dpll_param *) get_iva_dpll_param();
  261. /* Moving to the right sysclk and ES rev base */
  262. ptr = ptr + (3 * clk_index) + sil_index;
  263. /* IVA DPLL */
  264. /* EN_IVA2_DPLL : CM_CLKEN_PLL_IVA2[0:2] */
  265. sr32(&prcm_base->clken_pll_iva2, 0, 3, PLL_STOP);
  266. wait_on_value(ST_IVA2_CLK, 0, &prcm_base->idlest_pll_iva2, LDELAY);
  267. /* M2 (IVA2_DPLL_CLKOUT_DIV) : CM_CLKSEL2_PLL_IVA2[0:4] */
  268. sr32(&prcm_base->clksel2_pll_iva2, 0, 5, ptr->m2);
  269. /* M (IVA2_DPLL_MULT) : CM_CLKSEL1_PLL_IVA2[8:18] */
  270. sr32(&prcm_base->clksel1_pll_iva2, 8, 11, ptr->m);
  271. /* N (IVA2_DPLL_DIV) : CM_CLKSEL1_PLL_IVA2[0:6] */
  272. sr32(&prcm_base->clksel1_pll_iva2, 0, 7, ptr->n);
  273. /* FREQSEL (IVA2_DPLL_FREQSEL) : CM_CLKEN_PLL_IVA2[4:7] */
  274. sr32(&prcm_base->clken_pll_iva2, 4, 4, ptr->fsel);
  275. /* LOCK MODE (EN_IVA2_DPLL) : CM_CLKEN_PLL_IVA2[0:2] */
  276. sr32(&prcm_base->clken_pll_iva2, 0, 3, PLL_LOCK);
  277. wait_on_value(ST_IVA2_CLK, 1, &prcm_base->idlest_pll_iva2, LDELAY);
  278. }
  279. /*
  280. * OMAP3630 specific functions
  281. */
  282. static void dpll3_init_36xx(u32 sil_index, u32 clk_index)
  283. {
  284. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  285. dpll_param *ptr = (dpll_param *) get_36x_core_dpll_param();
  286. void (*f_lock_pll) (u32, u32, u32, u32);
  287. int xip_safe, p0, p1, p2, p3;
  288. xip_safe = is_running_in_sram();
  289. /* Moving it to the right sysclk base */
  290. ptr += clk_index;
  291. if (xip_safe) {
  292. /* CORE DPLL */
  293. /* Select relock bypass: CM_CLKEN_PLL[0:2] */
  294. sr32(&prcm_base->clken_pll, 0, 3, PLL_FAST_RELOCK_BYPASS);
  295. wait_on_value(ST_CORE_CLK, 0, &prcm_base->idlest_ckgen,
  296. LDELAY);
  297. /* CM_CLKSEL1_EMU[DIV_DPLL3] */
  298. sr32(&prcm_base->clksel1_emu, 16, 5, CORE_M3X2);
  299. /* M2 (CORE_DPLL_CLKOUT_DIV): CM_CLKSEL1_PLL[27:31] */
  300. sr32(&prcm_base->clksel1_pll, 27, 5, ptr->m2);
  301. /* M (CORE_DPLL_MULT): CM_CLKSEL1_PLL[16:26] */
  302. sr32(&prcm_base->clksel1_pll, 16, 11, ptr->m);
  303. /* N (CORE_DPLL_DIV): CM_CLKSEL1_PLL[8:14] */
  304. sr32(&prcm_base->clksel1_pll, 8, 7, ptr->n);
  305. /* Source is the CM_96M_FCLK: CM_CLKSEL1_PLL[6] */
  306. sr32(&prcm_base->clksel1_pll, 6, 1, 0);
  307. /* SSI */
  308. sr32(&prcm_base->clksel_core, 8, 4, CORE_SSI_DIV);
  309. /* FSUSB */
  310. sr32(&prcm_base->clksel_core, 4, 2, CORE_FUSB_DIV);
  311. /* L4 */
  312. sr32(&prcm_base->clksel_core, 2, 2, CORE_L4_DIV);
  313. /* L3 */
  314. sr32(&prcm_base->clksel_core, 0, 2, CORE_L3_DIV);
  315. /* GFX */
  316. sr32(&prcm_base->clksel_gfx, 0, 3, GFX_DIV_36X);
  317. /* RESET MGR */
  318. sr32(&prcm_base->clksel_wkup, 1, 2, WKUP_RSM);
  319. /* FREQSEL (CORE_DPLL_FREQSEL): CM_CLKEN_PLL[4:7] */
  320. sr32(&prcm_base->clken_pll, 4, 4, ptr->fsel);
  321. /* LOCK MODE */
  322. sr32(&prcm_base->clken_pll, 0, 3, PLL_LOCK);
  323. wait_on_value(ST_CORE_CLK, 1, &prcm_base->idlest_ckgen,
  324. LDELAY);
  325. } else if (is_running_in_flash()) {
  326. /*
  327. * if running from flash, jump to small relocated code
  328. * area in SRAM.
  329. */
  330. f_lock_pll = (void *) ((u32) &_end_vect - (u32) &_start +
  331. SRAM_VECT_CODE);
  332. p0 = readl(&prcm_base->clken_pll);
  333. sr32(&p0, 0, 3, PLL_FAST_RELOCK_BYPASS);
  334. /* FREQSEL (CORE_DPLL_FREQSEL): CM_CLKEN_PLL[4:7] */
  335. sr32(&p0, 4, 4, ptr->fsel);
  336. p1 = readl(&prcm_base->clksel1_pll);
  337. /* M2 (CORE_DPLL_CLKOUT_DIV): CM_CLKSEL1_PLL[27:31] */
  338. sr32(&p1, 27, 5, ptr->m2);
  339. /* M (CORE_DPLL_MULT): CM_CLKSEL1_PLL[16:26] */
  340. sr32(&p1, 16, 11, ptr->m);
  341. /* N (CORE_DPLL_DIV): CM_CLKSEL1_PLL[8:14] */
  342. sr32(&p1, 8, 7, ptr->n);
  343. /* Source is the CM_96M_FCLK: CM_CLKSEL1_PLL[6] */
  344. sr32(&p1, 6, 1, 0);
  345. p2 = readl(&prcm_base->clksel_core);
  346. /* SSI */
  347. sr32(&p2, 8, 4, CORE_SSI_DIV);
  348. /* FSUSB */
  349. sr32(&p2, 4, 2, CORE_FUSB_DIV);
  350. /* L4 */
  351. sr32(&p2, 2, 2, CORE_L4_DIV);
  352. /* L3 */
  353. sr32(&p2, 0, 2, CORE_L3_DIV);
  354. p3 = (u32)&prcm_base->idlest_ckgen;
  355. (*f_lock_pll) (p0, p1, p2, p3);
  356. }
  357. }
  358. static void dpll4_init_36xx(u32 sil_index, u32 clk_index)
  359. {
  360. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  361. struct dpll_per_36x_param *ptr;
  362. ptr = (struct dpll_per_36x_param *)get_36x_per_dpll_param();
  363. /* Moving it to the right sysclk base */
  364. ptr += clk_index;
  365. /* EN_PERIPH_DPLL: CM_CLKEN_PLL[16:18] */
  366. sr32(&prcm_base->clken_pll, 16, 3, PLL_STOP);
  367. wait_on_value(ST_PERIPH_CLK, 0, &prcm_base->idlest_ckgen, LDELAY);
  368. /* M6 (DIV_DPLL4): CM_CLKSEL1_EMU[24:29] */
  369. sr32(&prcm_base->clksel1_emu, 24, 6, ptr->m6);
  370. /* M5 (CLKSEL_CAM): CM_CLKSEL1_EMU[0:5] */
  371. sr32(&prcm_base->clksel_cam, 0, 6, ptr->m5);
  372. /* M4 (CLKSEL_DSS1): CM_CLKSEL_DSS[0:5] */
  373. sr32(&prcm_base->clksel_dss, 0, 6, ptr->m4);
  374. /* M3 (CLKSEL_DSS1): CM_CLKSEL_DSS[8:13] */
  375. sr32(&prcm_base->clksel_dss, 8, 6, ptr->m3);
  376. /* M2 (DIV_96M): CM_CLKSEL3_PLL[0:4] */
  377. sr32(&prcm_base->clksel3_pll, 0, 5, ptr->m2);
  378. /* M (PERIPH_DPLL_MULT): CM_CLKSEL2_PLL[8:19] */
  379. sr32(&prcm_base->clksel2_pll, 8, 12, ptr->m);
  380. /* N (PERIPH_DPLL_DIV): CM_CLKSEL2_PLL[0:6] */
  381. sr32(&prcm_base->clksel2_pll, 0, 7, ptr->n);
  382. /* M2DIV (CLKSEL_96M): CM_CLKSEL_CORE[12:13] */
  383. sr32(&prcm_base->clksel_core, 12, 2, ptr->m2div);
  384. /* LOCK MODE (EN_PERIPH_DPLL): CM_CLKEN_PLL[16:18] */
  385. sr32(&prcm_base->clken_pll, 16, 3, PLL_LOCK);
  386. wait_on_value(ST_PERIPH_CLK, 2, &prcm_base->idlest_ckgen, LDELAY);
  387. }
  388. static void dpll5_init_36xx(u32 sil_index, u32 clk_index)
  389. {
  390. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  391. dpll_param *ptr = (dpll_param *) get_36x_per2_dpll_param();
  392. /* Moving it to the right sysclk base */
  393. ptr = ptr + clk_index;
  394. /* PER2 DPLL (DPLL5) */
  395. sr32(&prcm_base->clken2_pll, 0, 3, PLL_STOP);
  396. wait_on_value(1, 0, &prcm_base->idlest2_ckgen, LDELAY);
  397. sr32(&prcm_base->clksel5_pll, 0, 5, ptr->m2); /* set M2 (usbtll_fck) */
  398. sr32(&prcm_base->clksel4_pll, 8, 11, ptr->m); /* set m (11-bit multiplier) */
  399. sr32(&prcm_base->clksel4_pll, 0, 7, ptr->n); /* set n (7-bit divider)*/
  400. sr32(&prcm_base->clken2_pll, 0, 3, PLL_LOCK); /* lock mode */
  401. wait_on_value(1, 1, &prcm_base->idlest2_ckgen, LDELAY);
  402. }
  403. static void mpu_init_36xx(u32 sil_index, u32 clk_index)
  404. {
  405. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  406. dpll_param *ptr = (dpll_param *) get_36x_mpu_dpll_param();
  407. /* Moving to the right sysclk */
  408. ptr += clk_index;
  409. /* MPU DPLL (unlocked already */
  410. /* M2 (MPU_DPLL_CLKOUT_DIV) : CM_CLKSEL2_PLL_MPU[0:4] */
  411. sr32(&prcm_base->clksel2_pll_mpu, 0, 5, ptr->m2);
  412. /* M (MPU_DPLL_MULT) : CM_CLKSEL2_PLL_MPU[8:18] */
  413. sr32(&prcm_base->clksel1_pll_mpu, 8, 11, ptr->m);
  414. /* N (MPU_DPLL_DIV) : CM_CLKSEL2_PLL_MPU[0:6] */
  415. sr32(&prcm_base->clksel1_pll_mpu, 0, 7, ptr->n);
  416. }
  417. static void iva_init_36xx(u32 sil_index, u32 clk_index)
  418. {
  419. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  420. dpll_param *ptr = (dpll_param *)get_36x_iva_dpll_param();
  421. /* Moving to the right sysclk */
  422. ptr += clk_index;
  423. /* IVA DPLL */
  424. /* EN_IVA2_DPLL : CM_CLKEN_PLL_IVA2[0:2] */
  425. sr32(&prcm_base->clken_pll_iva2, 0, 3, PLL_STOP);
  426. wait_on_value(ST_IVA2_CLK, 0, &prcm_base->idlest_pll_iva2, LDELAY);
  427. /* M2 (IVA2_DPLL_CLKOUT_DIV) : CM_CLKSEL2_PLL_IVA2[0:4] */
  428. sr32(&prcm_base->clksel2_pll_iva2, 0, 5, ptr->m2);
  429. /* M (IVA2_DPLL_MULT) : CM_CLKSEL1_PLL_IVA2[8:18] */
  430. sr32(&prcm_base->clksel1_pll_iva2, 8, 11, ptr->m);
  431. /* N (IVA2_DPLL_DIV) : CM_CLKSEL1_PLL_IVA2[0:6] */
  432. sr32(&prcm_base->clksel1_pll_iva2, 0, 7, ptr->n);
  433. /* LOCK (MODE (EN_IVA2_DPLL) : CM_CLKEN_PLL_IVA2[0:2] */
  434. sr32(&prcm_base->clken_pll_iva2, 0, 3, PLL_LOCK);
  435. wait_on_value(ST_IVA2_CLK, 1, &prcm_base->idlest_pll_iva2, LDELAY);
  436. }
  437. /******************************************************************************
  438. * prcm_init() - inits clocks for PRCM as defined in clocks.h
  439. * called from SRAM, or Flash (using temp SRAM stack).
  440. *****************************************************************************/
  441. void prcm_init(void)
  442. {
  443. u32 osc_clk = 0, sys_clkin_sel;
  444. u32 clk_index, sil_index = 0;
  445. struct prm *prm_base = (struct prm *)PRM_BASE;
  446. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  447. /*
  448. * Gauge the input clock speed and find out the sys_clkin_sel
  449. * value corresponding to the input clock.
  450. */
  451. osc_clk = get_osc_clk_speed();
  452. get_sys_clkin_sel(osc_clk, &sys_clkin_sel);
  453. /* set input crystal speed */
  454. sr32(&prm_base->clksel, 0, 3, sys_clkin_sel);
  455. /* If the input clock is greater than 19.2M always divide/2 */
  456. if (sys_clkin_sel > 2) {
  457. /* input clock divider */
  458. sr32(&prm_base->clksrc_ctrl, 6, 2, 2);
  459. clk_index = sys_clkin_sel / 2;
  460. } else {
  461. /* input clock divider */
  462. sr32(&prm_base->clksrc_ctrl, 6, 2, 1);
  463. clk_index = sys_clkin_sel;
  464. }
  465. if (get_cpu_family() == CPU_OMAP36XX) {
  466. /*
  467. * In warm reset conditions on OMAP36xx/AM/DM37xx
  468. * the rom code incorrectly sets the DPLL4 clock
  469. * input divider to /6.5. Section 3.5.3.3.3.2.1 of
  470. * the AM/DM37x TRM explains that the /6.5 divider
  471. * is used only when the input clock is 13MHz.
  472. *
  473. * If the part is in this cpu family *and* the input
  474. * clock *is not* 13 MHz, then reset the DPLL4 clock
  475. * input divider to /1 as it should never set to /6.5
  476. * in this case.
  477. */
  478. if (sys_clkin_sel != 1) /* 13 MHz */
  479. /* Bit 8: DPLL4_CLKINP_DIV */
  480. sr32(&prm_base->clksrc_ctrl, 8, 1, 0);
  481. /* Unlock MPU DPLL (slows things down, and needed later) */
  482. sr32(&prcm_base->clken_pll_mpu, 0, 3, PLL_LOW_POWER_BYPASS);
  483. wait_on_value(ST_MPU_CLK, 0, &prcm_base->idlest_pll_mpu,
  484. LDELAY);
  485. dpll3_init_36xx(0, clk_index);
  486. dpll4_init_36xx(0, clk_index);
  487. dpll5_init_36xx(0, clk_index);
  488. iva_init_36xx(0, clk_index);
  489. mpu_init_36xx(0, clk_index);
  490. /* Lock MPU DPLL to set frequency */
  491. sr32(&prcm_base->clken_pll_mpu, 0, 3, PLL_LOCK);
  492. wait_on_value(ST_MPU_CLK, 1, &prcm_base->idlest_pll_mpu,
  493. LDELAY);
  494. } else {
  495. /*
  496. * The DPLL tables are defined according to sysclk value and
  497. * silicon revision. The clk_index value will be used to get
  498. * the values for that input sysclk from the DPLL param table
  499. * and sil_index will get the values for that SysClk for the
  500. * appropriate silicon rev.
  501. */
  502. if (((get_cpu_family() == CPU_OMAP34XX)
  503. && (get_cpu_rev() >= CPU_3XX_ES20)) ||
  504. (get_cpu_family() == CPU_AM35XX))
  505. sil_index = 1;
  506. /* Unlock MPU DPLL (slows things down, and needed later) */
  507. sr32(&prcm_base->clken_pll_mpu, 0, 3, PLL_LOW_POWER_BYPASS);
  508. wait_on_value(ST_MPU_CLK, 0, &prcm_base->idlest_pll_mpu,
  509. LDELAY);
  510. dpll3_init_34xx(sil_index, clk_index);
  511. dpll4_init_34xx(sil_index, clk_index);
  512. dpll5_init_34xx(sil_index, clk_index);
  513. if (get_cpu_family() != CPU_AM35XX)
  514. iva_init_34xx(sil_index, clk_index);
  515. mpu_init_34xx(sil_index, clk_index);
  516. /* Lock MPU DPLL to set frequency */
  517. sr32(&prcm_base->clken_pll_mpu, 0, 3, PLL_LOCK);
  518. wait_on_value(ST_MPU_CLK, 1, &prcm_base->idlest_pll_mpu,
  519. LDELAY);
  520. }
  521. /* Set up GPTimers to sys_clk source only */
  522. sr32(&prcm_base->clksel_per, 0, 8, 0xff);
  523. sr32(&prcm_base->clksel_wkup, 0, 1, 1);
  524. sdelay(5000);
  525. }
  526. /*
  527. * Enable usb ehci uhh, tll clocks
  528. */
  529. void ehci_clocks_enable(void)
  530. {
  531. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  532. /* Enable USBHOST_L3_ICLK (USBHOST_MICLK) */
  533. sr32(&prcm_base->iclken_usbhost, 0, 1, 1);
  534. /*
  535. * Enable USBHOST_48M_FCLK (USBHOST_FCLK1)
  536. * and USBHOST_120M_FCLK (USBHOST_FCLK2)
  537. */
  538. sr32(&prcm_base->fclken_usbhost, 0, 2, 3);
  539. /* Enable USBTTL_ICLK */
  540. sr32(&prcm_base->iclken3_core, 2, 1, 1);
  541. /* Enable USBTTL_FCLK */
  542. sr32(&prcm_base->fclken3_core, 2, 1, 1);
  543. }
  544. /******************************************************************************
  545. * peripheral_enable() - Enable the clks & power for perifs (GPT2, UART1,...)
  546. *****************************************************************************/
  547. void per_clocks_enable(void)
  548. {
  549. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  550. /* Enable GP2 timer. */
  551. sr32(&prcm_base->clksel_per, 0, 1, 0x1); /* GPT2 = sys clk */
  552. sr32(&prcm_base->iclken_per, 3, 1, 0x1); /* ICKen GPT2 */
  553. sr32(&prcm_base->fclken_per, 3, 1, 0x1); /* FCKen GPT2 */
  554. #ifdef CONFIG_SYS_NS16550
  555. /* Enable UART1 clocks */
  556. sr32(&prcm_base->fclken1_core, 13, 1, 0x1);
  557. sr32(&prcm_base->iclken1_core, 13, 1, 0x1);
  558. /* UART 3 Clocks */
  559. sr32(&prcm_base->fclken_per, 11, 1, 0x1);
  560. sr32(&prcm_base->iclken_per, 11, 1, 0x1);
  561. #endif
  562. #ifdef CONFIG_OMAP3_GPIO_2
  563. sr32(&prcm_base->fclken_per, 13, 1, 1);
  564. sr32(&prcm_base->iclken_per, 13, 1, 1);
  565. #endif
  566. #ifdef CONFIG_OMAP3_GPIO_3
  567. sr32(&prcm_base->fclken_per, 14, 1, 1);
  568. sr32(&prcm_base->iclken_per, 14, 1, 1);
  569. #endif
  570. #ifdef CONFIG_OMAP3_GPIO_4
  571. sr32(&prcm_base->fclken_per, 15, 1, 1);
  572. sr32(&prcm_base->iclken_per, 15, 1, 1);
  573. #endif
  574. #ifdef CONFIG_OMAP3_GPIO_5
  575. sr32(&prcm_base->fclken_per, 16, 1, 1);
  576. sr32(&prcm_base->iclken_per, 16, 1, 1);
  577. #endif
  578. #ifdef CONFIG_OMAP3_GPIO_6
  579. sr32(&prcm_base->fclken_per, 17, 1, 1);
  580. sr32(&prcm_base->iclken_per, 17, 1, 1);
  581. #endif
  582. #ifdef CONFIG_DRIVER_OMAP34XX_I2C
  583. /* Turn on all 3 I2C clocks */
  584. sr32(&prcm_base->fclken1_core, 15, 3, 0x7);
  585. sr32(&prcm_base->iclken1_core, 15, 3, 0x7); /* I2C1,2,3 = on */
  586. #endif
  587. /* Enable the ICLK for 32K Sync Timer as its used in udelay */
  588. sr32(&prcm_base->iclken_wkup, 2, 1, 0x1);
  589. if (get_cpu_family() != CPU_AM35XX)
  590. sr32(&prcm_base->fclken_iva2, 0, 32, FCK_IVA2_ON);
  591. sr32(&prcm_base->fclken1_core, 0, 32, FCK_CORE1_ON);
  592. sr32(&prcm_base->iclken1_core, 0, 32, ICK_CORE1_ON);
  593. sr32(&prcm_base->iclken2_core, 0, 32, ICK_CORE2_ON);
  594. sr32(&prcm_base->fclken_wkup, 0, 32, FCK_WKUP_ON);
  595. sr32(&prcm_base->iclken_wkup, 0, 32, ICK_WKUP_ON);
  596. sr32(&prcm_base->fclken_dss, 0, 32, FCK_DSS_ON);
  597. sr32(&prcm_base->iclken_dss, 0, 32, ICK_DSS_ON);
  598. if (get_cpu_family() != CPU_AM35XX) {
  599. sr32(&prcm_base->fclken_cam, 0, 32, FCK_CAM_ON);
  600. sr32(&prcm_base->iclken_cam, 0, 32, ICK_CAM_ON);
  601. }
  602. sr32(&prcm_base->fclken_per, 0, 32, FCK_PER_ON);
  603. sr32(&prcm_base->iclken_per, 0, 32, ICK_PER_ON);
  604. sdelay(1000);
  605. }