clock.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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 mpu_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_mpu_dpll_param();
  242. /* Moving to the right sysclk and ES rev base */
  243. ptr = ptr + (3 * clk_index) + sil_index;
  244. /* MPU DPLL (unlocked already) */
  245. /* M2 (MPU_DPLL_CLKOUT_DIV) : CM_CLKSEL2_PLL_MPU[0:4] */
  246. sr32(&prcm_base->clksel2_pll_mpu, 0, 5, ptr->m2);
  247. /* M (MPU_DPLL_MULT) : CM_CLKSEL2_PLL_MPU[8:18] */
  248. sr32(&prcm_base->clksel1_pll_mpu, 8, 11, ptr->m);
  249. /* N (MPU_DPLL_DIV) : CM_CLKSEL2_PLL_MPU[0:6] */
  250. sr32(&prcm_base->clksel1_pll_mpu, 0, 7, ptr->n);
  251. /* FREQSEL (MPU_DPLL_FREQSEL) : CM_CLKEN_PLL_MPU[4:7] */
  252. sr32(&prcm_base->clken_pll_mpu, 4, 4, ptr->fsel);
  253. }
  254. static void iva_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_iva_dpll_param();
  258. /* Moving to the right sysclk and ES rev base */
  259. ptr = ptr + (3 * clk_index) + sil_index;
  260. /* IVA DPLL */
  261. /* EN_IVA2_DPLL : CM_CLKEN_PLL_IVA2[0:2] */
  262. sr32(&prcm_base->clken_pll_iva2, 0, 3, PLL_STOP);
  263. wait_on_value(ST_IVA2_CLK, 0, &prcm_base->idlest_pll_iva2, LDELAY);
  264. /* M2 (IVA2_DPLL_CLKOUT_DIV) : CM_CLKSEL2_PLL_IVA2[0:4] */
  265. sr32(&prcm_base->clksel2_pll_iva2, 0, 5, ptr->m2);
  266. /* M (IVA2_DPLL_MULT) : CM_CLKSEL1_PLL_IVA2[8:18] */
  267. sr32(&prcm_base->clksel1_pll_iva2, 8, 11, ptr->m);
  268. /* N (IVA2_DPLL_DIV) : CM_CLKSEL1_PLL_IVA2[0:6] */
  269. sr32(&prcm_base->clksel1_pll_iva2, 0, 7, ptr->n);
  270. /* FREQSEL (IVA2_DPLL_FREQSEL) : CM_CLKEN_PLL_IVA2[4:7] */
  271. sr32(&prcm_base->clken_pll_iva2, 4, 4, ptr->fsel);
  272. /* LOCK MODE (EN_IVA2_DPLL) : CM_CLKEN_PLL_IVA2[0:2] */
  273. sr32(&prcm_base->clken_pll_iva2, 0, 3, PLL_LOCK);
  274. wait_on_value(ST_IVA2_CLK, 1, &prcm_base->idlest_pll_iva2, LDELAY);
  275. }
  276. /*
  277. * OMAP3630 specific functions
  278. */
  279. static void dpll3_init_36xx(u32 sil_index, u32 clk_index)
  280. {
  281. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  282. dpll_param *ptr = (dpll_param *) get_36x_core_dpll_param();
  283. void (*f_lock_pll) (u32, u32, u32, u32);
  284. int xip_safe, p0, p1, p2, p3;
  285. xip_safe = is_running_in_sram();
  286. /* Moving it to the right sysclk base */
  287. ptr += clk_index;
  288. if (xip_safe) {
  289. /* CORE DPLL */
  290. /* Select relock bypass: CM_CLKEN_PLL[0:2] */
  291. sr32(&prcm_base->clken_pll, 0, 3, PLL_FAST_RELOCK_BYPASS);
  292. wait_on_value(ST_CORE_CLK, 0, &prcm_base->idlest_ckgen,
  293. LDELAY);
  294. /* CM_CLKSEL1_EMU[DIV_DPLL3] */
  295. sr32(&prcm_base->clksel1_emu, 16, 5, CORE_M3X2);
  296. /* M2 (CORE_DPLL_CLKOUT_DIV): CM_CLKSEL1_PLL[27:31] */
  297. sr32(&prcm_base->clksel1_pll, 27, 5, ptr->m2);
  298. /* M (CORE_DPLL_MULT): CM_CLKSEL1_PLL[16:26] */
  299. sr32(&prcm_base->clksel1_pll, 16, 11, ptr->m);
  300. /* N (CORE_DPLL_DIV): CM_CLKSEL1_PLL[8:14] */
  301. sr32(&prcm_base->clksel1_pll, 8, 7, ptr->n);
  302. /* Source is the CM_96M_FCLK: CM_CLKSEL1_PLL[6] */
  303. sr32(&prcm_base->clksel1_pll, 6, 1, 0);
  304. /* SSI */
  305. sr32(&prcm_base->clksel_core, 8, 4, CORE_SSI_DIV);
  306. /* FSUSB */
  307. sr32(&prcm_base->clksel_core, 4, 2, CORE_FUSB_DIV);
  308. /* L4 */
  309. sr32(&prcm_base->clksel_core, 2, 2, CORE_L4_DIV);
  310. /* L3 */
  311. sr32(&prcm_base->clksel_core, 0, 2, CORE_L3_DIV);
  312. /* GFX */
  313. sr32(&prcm_base->clksel_gfx, 0, 3, GFX_DIV);
  314. /* RESET MGR */
  315. sr32(&prcm_base->clksel_wkup, 1, 2, WKUP_RSM);
  316. /* FREQSEL (CORE_DPLL_FREQSEL): CM_CLKEN_PLL[4:7] */
  317. sr32(&prcm_base->clken_pll, 4, 4, ptr->fsel);
  318. /* LOCK MODE */
  319. sr32(&prcm_base->clken_pll, 0, 3, PLL_LOCK);
  320. wait_on_value(ST_CORE_CLK, 1, &prcm_base->idlest_ckgen,
  321. LDELAY);
  322. } else if (is_running_in_flash()) {
  323. /*
  324. * if running from flash, jump to small relocated code
  325. * area in SRAM.
  326. */
  327. f_lock_pll = (void *) ((u32) &_end_vect - (u32) &_start +
  328. SRAM_VECT_CODE);
  329. p0 = readl(&prcm_base->clken_pll);
  330. sr32(&p0, 0, 3, PLL_FAST_RELOCK_BYPASS);
  331. /* FREQSEL (CORE_DPLL_FREQSEL): CM_CLKEN_PLL[4:7] */
  332. sr32(&p0, 4, 4, ptr->fsel);
  333. p1 = readl(&prcm_base->clksel1_pll);
  334. /* M2 (CORE_DPLL_CLKOUT_DIV): CM_CLKSEL1_PLL[27:31] */
  335. sr32(&p1, 27, 5, ptr->m2);
  336. /* M (CORE_DPLL_MULT): CM_CLKSEL1_PLL[16:26] */
  337. sr32(&p1, 16, 11, ptr->m);
  338. /* N (CORE_DPLL_DIV): CM_CLKSEL1_PLL[8:14] */
  339. sr32(&p1, 8, 7, ptr->n);
  340. /* Source is the CM_96M_FCLK: CM_CLKSEL1_PLL[6] */
  341. sr32(&p1, 6, 1, 0);
  342. p2 = readl(&prcm_base->clksel_core);
  343. /* SSI */
  344. sr32(&p2, 8, 4, CORE_SSI_DIV);
  345. /* FSUSB */
  346. sr32(&p2, 4, 2, CORE_FUSB_DIV);
  347. /* L4 */
  348. sr32(&p2, 2, 2, CORE_L4_DIV);
  349. /* L3 */
  350. sr32(&p2, 0, 2, CORE_L3_DIV);
  351. p3 = (u32)&prcm_base->idlest_ckgen;
  352. (*f_lock_pll) (p0, p1, p2, p3);
  353. }
  354. }
  355. static void dpll4_init_36xx(u32 sil_index, u32 clk_index)
  356. {
  357. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  358. struct dpll_per_36x_param *ptr;
  359. ptr = (struct dpll_per_36x_param *)get_36x_per_dpll_param();
  360. /* Moving it to the right sysclk base */
  361. ptr += clk_index;
  362. /* EN_PERIPH_DPLL: CM_CLKEN_PLL[16:18] */
  363. sr32(&prcm_base->clken_pll, 16, 3, PLL_STOP);
  364. wait_on_value(ST_PERIPH_CLK, 0, &prcm_base->idlest_ckgen, LDELAY);
  365. /* M6 (DIV_DPLL4): CM_CLKSEL1_EMU[24:29] */
  366. sr32(&prcm_base->clksel1_emu, 24, 6, ptr->m6);
  367. /* M5 (CLKSEL_CAM): CM_CLKSEL1_EMU[0:5] */
  368. sr32(&prcm_base->clksel_cam, 0, 6, ptr->m5);
  369. /* M4 (CLKSEL_DSS1): CM_CLKSEL_DSS[0:5] */
  370. sr32(&prcm_base->clksel_dss, 0, 6, ptr->m4);
  371. /* M3 (CLKSEL_DSS1): CM_CLKSEL_DSS[8:13] */
  372. sr32(&prcm_base->clksel_dss, 8, 6, ptr->m3);
  373. /* M2 (DIV_96M): CM_CLKSEL3_PLL[0:4] */
  374. sr32(&prcm_base->clksel3_pll, 0, 5, ptr->m2);
  375. /* M (PERIPH_DPLL_MULT): CM_CLKSEL2_PLL[8:19] */
  376. sr32(&prcm_base->clksel2_pll, 8, 12, ptr->m);
  377. /* N (PERIPH_DPLL_DIV): CM_CLKSEL2_PLL[0:6] */
  378. sr32(&prcm_base->clksel2_pll, 0, 7, ptr->n);
  379. /* M2DIV (CLKSEL_96M): CM_CLKSEL_CORE[12:13] */
  380. sr32(&prcm_base->clksel_core, 12, 2, ptr->m2div);
  381. /* LOCK MODE (EN_PERIPH_DPLL): CM_CLKEN_PLL[16:18] */
  382. sr32(&prcm_base->clken_pll, 16, 3, PLL_LOCK);
  383. wait_on_value(ST_PERIPH_CLK, 2, &prcm_base->idlest_ckgen, LDELAY);
  384. }
  385. static void mpu_init_36xx(u32 sil_index, u32 clk_index)
  386. {
  387. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  388. dpll_param *ptr = (dpll_param *) get_36x_mpu_dpll_param();
  389. /* Moving to the right sysclk */
  390. ptr += clk_index;
  391. /* MPU DPLL (unlocked already */
  392. /* M2 (MPU_DPLL_CLKOUT_DIV) : CM_CLKSEL2_PLL_MPU[0:4] */
  393. sr32(&prcm_base->clksel2_pll_mpu, 0, 5, ptr->m2);
  394. /* M (MPU_DPLL_MULT) : CM_CLKSEL2_PLL_MPU[8:18] */
  395. sr32(&prcm_base->clksel1_pll_mpu, 8, 11, ptr->m);
  396. /* N (MPU_DPLL_DIV) : CM_CLKSEL2_PLL_MPU[0:6] */
  397. sr32(&prcm_base->clksel1_pll_mpu, 0, 7, ptr->n);
  398. }
  399. static void iva_init_36xx(u32 sil_index, u32 clk_index)
  400. {
  401. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  402. dpll_param *ptr = (dpll_param *)get_36x_iva_dpll_param();
  403. /* Moving to the right sysclk */
  404. ptr += clk_index;
  405. /* IVA DPLL */
  406. /* EN_IVA2_DPLL : CM_CLKEN_PLL_IVA2[0:2] */
  407. sr32(&prcm_base->clken_pll_iva2, 0, 3, PLL_STOP);
  408. wait_on_value(ST_IVA2_CLK, 0, &prcm_base->idlest_pll_iva2, LDELAY);
  409. /* M2 (IVA2_DPLL_CLKOUT_DIV) : CM_CLKSEL2_PLL_IVA2[0:4] */
  410. sr32(&prcm_base->clksel2_pll_iva2, 0, 5, ptr->m2);
  411. /* M (IVA2_DPLL_MULT) : CM_CLKSEL1_PLL_IVA2[8:18] */
  412. sr32(&prcm_base->clksel1_pll_iva2, 8, 11, ptr->m);
  413. /* N (IVA2_DPLL_DIV) : CM_CLKSEL1_PLL_IVA2[0:6] */
  414. sr32(&prcm_base->clksel1_pll_iva2, 0, 7, ptr->n);
  415. /* LOCK (MODE (EN_IVA2_DPLL) : CM_CLKEN_PLL_IVA2[0:2] */
  416. sr32(&prcm_base->clken_pll_iva2, 0, 3, PLL_LOCK);
  417. wait_on_value(ST_IVA2_CLK, 1, &prcm_base->idlest_pll_iva2, LDELAY);
  418. }
  419. /******************************************************************************
  420. * prcm_init() - inits clocks for PRCM as defined in clocks.h
  421. * called from SRAM, or Flash (using temp SRAM stack).
  422. *****************************************************************************/
  423. void prcm_init(void)
  424. {
  425. u32 osc_clk = 0, sys_clkin_sel;
  426. u32 clk_index, sil_index = 0;
  427. struct prm *prm_base = (struct prm *)PRM_BASE;
  428. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  429. /*
  430. * Gauge the input clock speed and find out the sys_clkin_sel
  431. * value corresponding to the input clock.
  432. */
  433. osc_clk = get_osc_clk_speed();
  434. get_sys_clkin_sel(osc_clk, &sys_clkin_sel);
  435. /* set input crystal speed */
  436. sr32(&prm_base->clksel, 0, 3, sys_clkin_sel);
  437. /* If the input clock is greater than 19.2M always divide/2 */
  438. if (sys_clkin_sel > 2) {
  439. /* input clock divider */
  440. sr32(&prm_base->clksrc_ctrl, 6, 2, 2);
  441. clk_index = sys_clkin_sel / 2;
  442. } else {
  443. /* input clock divider */
  444. sr32(&prm_base->clksrc_ctrl, 6, 2, 1);
  445. clk_index = sys_clkin_sel;
  446. }
  447. if (get_cpu_family() == CPU_OMAP36XX) {
  448. /* Unlock MPU DPLL (slows things down, and needed later) */
  449. sr32(&prcm_base->clken_pll_mpu, 0, 3, PLL_LOW_POWER_BYPASS);
  450. wait_on_value(ST_MPU_CLK, 0, &prcm_base->idlest_pll_mpu,
  451. LDELAY);
  452. dpll3_init_36xx(0, clk_index);
  453. dpll4_init_36xx(0, clk_index);
  454. iva_init_36xx(0, clk_index);
  455. mpu_init_36xx(0, clk_index);
  456. /* Lock MPU DPLL to set frequency */
  457. sr32(&prcm_base->clken_pll_mpu, 0, 3, PLL_LOCK);
  458. wait_on_value(ST_MPU_CLK, 1, &prcm_base->idlest_pll_mpu,
  459. LDELAY);
  460. } else {
  461. /*
  462. * The DPLL tables are defined according to sysclk value and
  463. * silicon revision. The clk_index value will be used to get
  464. * the values for that input sysclk from the DPLL param table
  465. * and sil_index will get the values for that SysClk for the
  466. * appropriate silicon rev.
  467. */
  468. if (((get_cpu_family() == CPU_OMAP34XX)
  469. && (get_cpu_rev() >= CPU_3XX_ES20)) ||
  470. (get_cpu_family() == CPU_AM35XX))
  471. sil_index = 1;
  472. /* Unlock MPU DPLL (slows things down, and needed later) */
  473. sr32(&prcm_base->clken_pll_mpu, 0, 3, PLL_LOW_POWER_BYPASS);
  474. wait_on_value(ST_MPU_CLK, 0, &prcm_base->idlest_pll_mpu,
  475. LDELAY);
  476. dpll3_init_34xx(sil_index, clk_index);
  477. dpll4_init_34xx(sil_index, clk_index);
  478. iva_init_34xx(sil_index, clk_index);
  479. mpu_init_34xx(sil_index, clk_index);
  480. /* Lock MPU DPLL to set frequency */
  481. sr32(&prcm_base->clken_pll_mpu, 0, 3, PLL_LOCK);
  482. wait_on_value(ST_MPU_CLK, 1, &prcm_base->idlest_pll_mpu,
  483. LDELAY);
  484. }
  485. /* Set up GPTimers to sys_clk source only */
  486. sr32(&prcm_base->clksel_per, 0, 8, 0xff);
  487. sr32(&prcm_base->clksel_wkup, 0, 1, 1);
  488. sdelay(5000);
  489. }
  490. /******************************************************************************
  491. * peripheral_enable() - Enable the clks & power for perifs (GPT2, UART1,...)
  492. *****************************************************************************/
  493. void per_clocks_enable(void)
  494. {
  495. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  496. /* Enable GP2 timer. */
  497. sr32(&prcm_base->clksel_per, 0, 1, 0x1); /* GPT2 = sys clk */
  498. sr32(&prcm_base->iclken_per, 3, 1, 0x1); /* ICKen GPT2 */
  499. sr32(&prcm_base->fclken_per, 3, 1, 0x1); /* FCKen GPT2 */
  500. #ifdef CONFIG_SYS_NS16550
  501. /* Enable UART1 clocks */
  502. sr32(&prcm_base->fclken1_core, 13, 1, 0x1);
  503. sr32(&prcm_base->iclken1_core, 13, 1, 0x1);
  504. /* UART 3 Clocks */
  505. sr32(&prcm_base->fclken_per, 11, 1, 0x1);
  506. sr32(&prcm_base->iclken_per, 11, 1, 0x1);
  507. #endif
  508. #ifdef CONFIG_OMAP3_GPIO_2
  509. sr32(&prcm_base->fclken_per, 13, 1, 1);
  510. sr32(&prcm_base->iclken_per, 13, 1, 1);
  511. #endif
  512. #ifdef CONFIG_OMAP3_GPIO_3
  513. sr32(&prcm_base->fclken_per, 14, 1, 1);
  514. sr32(&prcm_base->iclken_per, 14, 1, 1);
  515. #endif
  516. #ifdef CONFIG_OMAP3_GPIO_4
  517. sr32(&prcm_base->fclken_per, 15, 1, 1);
  518. sr32(&prcm_base->iclken_per, 15, 1, 1);
  519. #endif
  520. #ifdef CONFIG_OMAP3_GPIO_5
  521. sr32(&prcm_base->fclken_per, 16, 1, 1);
  522. sr32(&prcm_base->iclken_per, 16, 1, 1);
  523. #endif
  524. #ifdef CONFIG_OMAP3_GPIO_6
  525. sr32(&prcm_base->fclken_per, 17, 1, 1);
  526. sr32(&prcm_base->iclken_per, 17, 1, 1);
  527. #endif
  528. #ifdef CONFIG_DRIVER_OMAP34XX_I2C
  529. /* Turn on all 3 I2C clocks */
  530. sr32(&prcm_base->fclken1_core, 15, 3, 0x7);
  531. sr32(&prcm_base->iclken1_core, 15, 3, 0x7); /* I2C1,2,3 = on */
  532. #endif
  533. /* Enable the ICLK for 32K Sync Timer as its used in udelay */
  534. sr32(&prcm_base->iclken_wkup, 2, 1, 0x1);
  535. sr32(&prcm_base->fclken_iva2, 0, 32, FCK_IVA2_ON);
  536. sr32(&prcm_base->fclken1_core, 0, 32, FCK_CORE1_ON);
  537. sr32(&prcm_base->iclken1_core, 0, 32, ICK_CORE1_ON);
  538. sr32(&prcm_base->iclken2_core, 0, 32, ICK_CORE2_ON);
  539. sr32(&prcm_base->fclken_wkup, 0, 32, FCK_WKUP_ON);
  540. sr32(&prcm_base->iclken_wkup, 0, 32, ICK_WKUP_ON);
  541. sr32(&prcm_base->fclken_dss, 0, 32, FCK_DSS_ON);
  542. sr32(&prcm_base->iclken_dss, 0, 32, ICK_DSS_ON);
  543. sr32(&prcm_base->fclken_cam, 0, 32, FCK_CAM_ON);
  544. sr32(&prcm_base->iclken_cam, 0, 32, ICK_CAM_ON);
  545. sr32(&prcm_base->fclken_per, 0, 32, FCK_PER_ON);
  546. sr32(&prcm_base->iclken_per, 0, 32, ICK_PER_ON);
  547. sdelay(1000);
  548. }