clock.c 22 KB

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