m53xx.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /***************************************************************************/
  2. /*
  3. * m53xx.c -- platform support for ColdFire 53xx based boards
  4. *
  5. * Copyright (C) 1999-2002, Greg Ungerer (gerg@snapgear.com)
  6. * Copyright (C) 2000, Lineo (www.lineo.com)
  7. * Yaroslav Vinogradov yaroslav.vinogradov@freescale.com
  8. * Copyright Freescale Semiconductor, Inc 2006
  9. * Copyright (c) 2006, emlix, Sebastian Hess <shess@hessware.de>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. */
  16. /***************************************************************************/
  17. #include <linux/kernel.h>
  18. #include <linux/param.h>
  19. #include <linux/init.h>
  20. #include <linux/io.h>
  21. #include <asm/machdep.h>
  22. #include <asm/coldfire.h>
  23. #include <asm/mcfsim.h>
  24. #include <asm/mcfuart.h>
  25. #include <asm/mcfdma.h>
  26. #include <asm/mcfwdebug.h>
  27. #include <asm/mcfclk.h>
  28. /***************************************************************************/
  29. DEFINE_CLK(0, "flexbus", 2, MCF_CLK);
  30. DEFINE_CLK(0, "mcfcan.0", 8, MCF_CLK);
  31. DEFINE_CLK(0, "fec.0", 12, MCF_CLK);
  32. DEFINE_CLK(0, "edma", 17, MCF_CLK);
  33. DEFINE_CLK(0, "intc.0", 18, MCF_CLK);
  34. DEFINE_CLK(0, "intc.1", 19, MCF_CLK);
  35. DEFINE_CLK(0, "iack.0", 21, MCF_CLK);
  36. DEFINE_CLK(0, "mcfi2c.0", 22, MCF_CLK);
  37. DEFINE_CLK(0, "mcfqspi.0", 23, MCF_CLK);
  38. DEFINE_CLK(0, "mcfuart.0", 24, MCF_BUSCLK);
  39. DEFINE_CLK(0, "mcfuart.1", 25, MCF_BUSCLK);
  40. DEFINE_CLK(0, "mcfuart.2", 26, MCF_BUSCLK);
  41. DEFINE_CLK(0, "mcftmr.0", 28, MCF_CLK);
  42. DEFINE_CLK(0, "mcftmr.1", 29, MCF_CLK);
  43. DEFINE_CLK(0, "mcftmr.2", 30, MCF_CLK);
  44. DEFINE_CLK(0, "mcftmr.3", 31, MCF_CLK);
  45. DEFINE_CLK(0, "mcfpit.0", 32, MCF_CLK);
  46. DEFINE_CLK(0, "mcfpit.1", 33, MCF_CLK);
  47. DEFINE_CLK(0, "mcfpit.2", 34, MCF_CLK);
  48. DEFINE_CLK(0, "mcfpit.3", 35, MCF_CLK);
  49. DEFINE_CLK(0, "mcfpwm.0", 36, MCF_CLK);
  50. DEFINE_CLK(0, "mcfeport.0", 37, MCF_CLK);
  51. DEFINE_CLK(0, "mcfwdt.0", 38, MCF_CLK);
  52. DEFINE_CLK(0, "sys.0", 40, MCF_BUSCLK);
  53. DEFINE_CLK(0, "gpio.0", 41, MCF_BUSCLK);
  54. DEFINE_CLK(0, "mcfrtc.0", 42, MCF_CLK);
  55. DEFINE_CLK(0, "mcflcd.0", 43, MCF_CLK);
  56. DEFINE_CLK(0, "mcfusb-otg.0", 44, MCF_CLK);
  57. DEFINE_CLK(0, "mcfusb-host.0", 45, MCF_CLK);
  58. DEFINE_CLK(0, "sdram.0", 46, MCF_CLK);
  59. DEFINE_CLK(0, "ssi.0", 47, MCF_CLK);
  60. DEFINE_CLK(0, "pll.0", 48, MCF_CLK);
  61. DEFINE_CLK(1, "mdha.0", 32, MCF_CLK);
  62. DEFINE_CLK(1, "skha.0", 33, MCF_CLK);
  63. DEFINE_CLK(1, "rng.0", 34, MCF_CLK);
  64. struct clk *mcf_clks[] = {
  65. &__clk_0_2, /* flexbus */
  66. &__clk_0_8, /* mcfcan.0 */
  67. &__clk_0_12, /* fec.0 */
  68. &__clk_0_17, /* edma */
  69. &__clk_0_18, /* intc.0 */
  70. &__clk_0_19, /* intc.1 */
  71. &__clk_0_21, /* iack.0 */
  72. &__clk_0_22, /* mcfi2c.0 */
  73. &__clk_0_23, /* mcfqspi.0 */
  74. &__clk_0_24, /* mcfuart.0 */
  75. &__clk_0_25, /* mcfuart.1 */
  76. &__clk_0_26, /* mcfuart.2 */
  77. &__clk_0_28, /* mcftmr.0 */
  78. &__clk_0_29, /* mcftmr.1 */
  79. &__clk_0_30, /* mcftmr.2 */
  80. &__clk_0_31, /* mcftmr.3 */
  81. &__clk_0_32, /* mcfpit.0 */
  82. &__clk_0_33, /* mcfpit.1 */
  83. &__clk_0_34, /* mcfpit.2 */
  84. &__clk_0_35, /* mcfpit.3 */
  85. &__clk_0_36, /* mcfpwm.0 */
  86. &__clk_0_37, /* mcfeport.0 */
  87. &__clk_0_38, /* mcfwdt.0 */
  88. &__clk_0_40, /* sys.0 */
  89. &__clk_0_41, /* gpio.0 */
  90. &__clk_0_42, /* mcfrtc.0 */
  91. &__clk_0_43, /* mcflcd.0 */
  92. &__clk_0_44, /* mcfusb-otg.0 */
  93. &__clk_0_45, /* mcfusb-host.0 */
  94. &__clk_0_46, /* sdram.0 */
  95. &__clk_0_47, /* ssi.0 */
  96. &__clk_0_48, /* pll.0 */
  97. &__clk_1_32, /* mdha.0 */
  98. &__clk_1_33, /* skha.0 */
  99. &__clk_1_34, /* rng.0 */
  100. NULL,
  101. };
  102. static struct clk * const enable_clks[] __initconst = {
  103. &__clk_0_2, /* flexbus */
  104. &__clk_0_18, /* intc.0 */
  105. &__clk_0_19, /* intc.1 */
  106. &__clk_0_21, /* iack.0 */
  107. &__clk_0_24, /* mcfuart.0 */
  108. &__clk_0_25, /* mcfuart.1 */
  109. &__clk_0_26, /* mcfuart.2 */
  110. &__clk_0_28, /* mcftmr.0 */
  111. &__clk_0_29, /* mcftmr.1 */
  112. &__clk_0_32, /* mcfpit.0 */
  113. &__clk_0_33, /* mcfpit.1 */
  114. &__clk_0_37, /* mcfeport.0 */
  115. &__clk_0_40, /* sys.0 */
  116. &__clk_0_41, /* gpio.0 */
  117. &__clk_0_46, /* sdram.0 */
  118. &__clk_0_48, /* pll.0 */
  119. };
  120. static struct clk * const disable_clks[] __initconst = {
  121. &__clk_0_8, /* mcfcan.0 */
  122. &__clk_0_12, /* fec.0 */
  123. &__clk_0_17, /* edma */
  124. &__clk_0_22, /* mcfi2c.0 */
  125. &__clk_0_23, /* mcfqspi.0 */
  126. &__clk_0_30, /* mcftmr.2 */
  127. &__clk_0_31, /* mcftmr.3 */
  128. &__clk_0_34, /* mcfpit.2 */
  129. &__clk_0_35, /* mcfpit.3 */
  130. &__clk_0_36, /* mcfpwm.0 */
  131. &__clk_0_38, /* mcfwdt.0 */
  132. &__clk_0_42, /* mcfrtc.0 */
  133. &__clk_0_43, /* mcflcd.0 */
  134. &__clk_0_44, /* mcfusb-otg.0 */
  135. &__clk_0_45, /* mcfusb-host.0 */
  136. &__clk_0_47, /* ssi.0 */
  137. &__clk_1_32, /* mdha.0 */
  138. &__clk_1_33, /* skha.0 */
  139. &__clk_1_34, /* rng.0 */
  140. };
  141. static void __init m53xx_clk_init(void)
  142. {
  143. unsigned i;
  144. /* make sure these clocks are enabled */
  145. for (i = 0; i < ARRAY_SIZE(enable_clks); ++i)
  146. __clk_init_enabled(enable_clks[i]);
  147. /* make sure these clocks are disabled */
  148. for (i = 0; i < ARRAY_SIZE(disable_clks); ++i)
  149. __clk_init_disabled(disable_clks[i]);
  150. }
  151. /***************************************************************************/
  152. static void __init m53xx_qspi_init(void)
  153. {
  154. #if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
  155. /* setup QSPS pins for QSPI with gpio CS control */
  156. writew(0x01f0, MCFGPIO_PAR_QSPI);
  157. #endif /* IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI) */
  158. }
  159. /***************************************************************************/
  160. static void __init m53xx_uarts_init(void)
  161. {
  162. /* UART GPIO initialization */
  163. writew(readw(MCFGPIO_PAR_UART) | 0x0FFF, MCFGPIO_PAR_UART);
  164. }
  165. /***************************************************************************/
  166. static void __init m53xx_fec_init(void)
  167. {
  168. u8 v;
  169. /* Set multi-function pins to ethernet mode for fec0 */
  170. v = readb(MCFGPIO_PAR_FECI2C);
  171. v |= MCF_GPIO_PAR_FECI2C_PAR_MDC_EMDC |
  172. MCF_GPIO_PAR_FECI2C_PAR_MDIO_EMDIO;
  173. writeb(v, MCFGPIO_PAR_FECI2C);
  174. v = readb(MCFGPIO_PAR_FEC);
  175. v = MCF_GPIO_PAR_FEC_PAR_FEC_7W_FEC | MCF_GPIO_PAR_FEC_PAR_FEC_MII_FEC;
  176. writeb(v, MCFGPIO_PAR_FEC);
  177. }
  178. /***************************************************************************/
  179. void __init config_BSP(char *commandp, int size)
  180. {
  181. #if !defined(CONFIG_BOOTPARAM)
  182. /* Copy command line from FLASH to local buffer... */
  183. memcpy(commandp, (char *) 0x4000, 4);
  184. if(strncmp(commandp, "kcl ", 4) == 0){
  185. memcpy(commandp, (char *) 0x4004, size);
  186. commandp[size-1] = 0;
  187. } else {
  188. memset(commandp, 0, size);
  189. }
  190. #endif
  191. mach_sched_init = hw_timer_init;
  192. m53xx_clk_init();
  193. m53xx_uarts_init();
  194. m53xx_fec_init();
  195. m53xx_qspi_init();
  196. #ifdef CONFIG_BDM_DISABLE
  197. /*
  198. * Disable the BDM clocking. This also turns off most of the rest of
  199. * the BDM device. This is good for EMC reasons. This option is not
  200. * incompatible with the memory protection option.
  201. */
  202. wdebug(MCFDEBUG_CSR, MCFDEBUG_CSR_PSTCLK);
  203. #endif
  204. }
  205. /***************************************************************************/
  206. /* Board initialization */
  207. /***************************************************************************/
  208. /*
  209. * PLL min/max specifications
  210. */
  211. #define MAX_FVCO 500000 /* KHz */
  212. #define MAX_FSYS 80000 /* KHz */
  213. #define MIN_FSYS 58333 /* KHz */
  214. #define FREF 16000 /* KHz */
  215. #define MAX_MFD 135 /* Multiplier */
  216. #define MIN_MFD 88 /* Multiplier */
  217. #define BUSDIV 6 /* Divider */
  218. /*
  219. * Low Power Divider specifications
  220. */
  221. #define MIN_LPD (1 << 0) /* Divider (not encoded) */
  222. #define MAX_LPD (1 << 15) /* Divider (not encoded) */
  223. #define DEFAULT_LPD (1 << 1) /* Divider (not encoded) */
  224. #define SYS_CLK_KHZ 80000
  225. #define SYSTEM_PERIOD 12.5
  226. /*
  227. * SDRAM Timing Parameters
  228. */
  229. #define SDRAM_BL 8 /* # of beats in a burst */
  230. #define SDRAM_TWR 2 /* in clocks */
  231. #define SDRAM_CASL 2.5 /* CASL in clocks */
  232. #define SDRAM_TRCD 2 /* in clocks */
  233. #define SDRAM_TRP 2 /* in clocks */
  234. #define SDRAM_TRFC 7 /* in clocks */
  235. #define SDRAM_TREFI 7800 /* in ns */
  236. #define EXT_SRAM_ADDRESS (0xC0000000)
  237. #define FLASH_ADDRESS (0x00000000)
  238. #define SDRAM_ADDRESS (0x40000000)
  239. #define NAND_FLASH_ADDRESS (0xD0000000)
  240. void wtm_init(void);
  241. void scm_init(void);
  242. void gpio_init(void);
  243. void fbcs_init(void);
  244. void sdramc_init(void);
  245. int clock_pll (int fsys, int flags);
  246. int clock_limp (int);
  247. int clock_exit_limp (void);
  248. int get_sys_clock (void);
  249. asmlinkage void __init sysinit(void)
  250. {
  251. clock_pll(0, 0);
  252. wtm_init();
  253. scm_init();
  254. gpio_init();
  255. fbcs_init();
  256. sdramc_init();
  257. }
  258. void wtm_init(void)
  259. {
  260. /* Disable watchdog timer */
  261. writew(0, MCF_WTM_WCR);
  262. }
  263. #define MCF_SCM_BCR_GBW (0x00000100)
  264. #define MCF_SCM_BCR_GBR (0x00000200)
  265. void scm_init(void)
  266. {
  267. /* All masters are trusted */
  268. writel(0x77777777, MCF_SCM_MPR);
  269. /* Allow supervisor/user, read/write, and trusted/untrusted
  270. access to all slaves */
  271. writel(0, MCF_SCM_PACRA);
  272. writel(0, MCF_SCM_PACRB);
  273. writel(0, MCF_SCM_PACRC);
  274. writel(0, MCF_SCM_PACRD);
  275. writel(0, MCF_SCM_PACRE);
  276. writel(0, MCF_SCM_PACRF);
  277. /* Enable bursts */
  278. writel(MCF_SCM_BCR_GBR | MCF_SCM_BCR_GBW, MCF_SCM_BCR);
  279. }
  280. void fbcs_init(void)
  281. {
  282. writeb(0x3E, MCFGPIO_PAR_CS);
  283. /* Latch chip select */
  284. writel(0x10080000, MCF_FBCS1_CSAR);
  285. writel(0x002A3780, MCF_FBCS1_CSCR);
  286. writel(MCF_FBCS_CSMR_BAM_2M | MCF_FBCS_CSMR_V, MCF_FBCS1_CSMR);
  287. /* Initialize latch to drive signals to inactive states */
  288. writew(0xffff, 0x10080000);
  289. /* External SRAM */
  290. writel(EXT_SRAM_ADDRESS, MCF_FBCS1_CSAR);
  291. writel(MCF_FBCS_CSCR_PS_16 |
  292. MCF_FBCS_CSCR_AA |
  293. MCF_FBCS_CSCR_SBM |
  294. MCF_FBCS_CSCR_WS(1),
  295. MCF_FBCS1_CSCR);
  296. writel(MCF_FBCS_CSMR_BAM_512K | MCF_FBCS_CSMR_V, MCF_FBCS1_CSMR);
  297. /* Boot Flash connected to FBCS0 */
  298. writel(FLASH_ADDRESS, MCF_FBCS0_CSAR);
  299. writel(MCF_FBCS_CSCR_PS_16 |
  300. MCF_FBCS_CSCR_BEM |
  301. MCF_FBCS_CSCR_AA |
  302. MCF_FBCS_CSCR_SBM |
  303. MCF_FBCS_CSCR_WS(7),
  304. MCF_FBCS0_CSCR);
  305. writel(MCF_FBCS_CSMR_BAM_32M | MCF_FBCS_CSMR_V, MCF_FBCS0_CSMR);
  306. }
  307. void sdramc_init(void)
  308. {
  309. /*
  310. * Check to see if the SDRAM has already been initialized
  311. * by a run control tool
  312. */
  313. if (!(readl(MCF_SDRAMC_SDCR) & MCF_SDRAMC_SDCR_REF)) {
  314. /* SDRAM chip select initialization */
  315. /* Initialize SDRAM chip select */
  316. writel(MCF_SDRAMC_SDCS_BA(SDRAM_ADDRESS) |
  317. MCF_SDRAMC_SDCS_CSSZ(MCF_SDRAMC_SDCS_CSSZ_32MBYTE),
  318. MCF_SDRAMC_SDCS0);
  319. /*
  320. * Basic configuration and initialization
  321. */
  322. writel(MCF_SDRAMC_SDCFG1_SRD2RW((int)((SDRAM_CASL + 2) + 0.5)) |
  323. MCF_SDRAMC_SDCFG1_SWT2RD(SDRAM_TWR + 1) |
  324. MCF_SDRAMC_SDCFG1_RDLAT((int)((SDRAM_CASL * 2) + 2)) |
  325. MCF_SDRAMC_SDCFG1_ACT2RW((int)(SDRAM_TRCD + 0.5)) |
  326. MCF_SDRAMC_SDCFG1_PRE2ACT((int)(SDRAM_TRP + 0.5)) |
  327. MCF_SDRAMC_SDCFG1_REF2ACT((int)(SDRAM_TRFC + 0.5)) |
  328. MCF_SDRAMC_SDCFG1_WTLAT(3),
  329. MCF_SDRAMC_SDCFG1);
  330. writel(MCF_SDRAMC_SDCFG2_BRD2PRE(SDRAM_BL / 2 + 1) |
  331. MCF_SDRAMC_SDCFG2_BWT2RW(SDRAM_BL / 2 + SDRAM_TWR) |
  332. MCF_SDRAMC_SDCFG2_BRD2WT((int)((SDRAM_CASL + SDRAM_BL / 2 - 1.0) + 0.5)) |
  333. MCF_SDRAMC_SDCFG2_BL(SDRAM_BL - 1),
  334. MCF_SDRAMC_SDCFG2);
  335. /*
  336. * Precharge and enable write to SDMR
  337. */
  338. writel(MCF_SDRAMC_SDCR_MODE_EN |
  339. MCF_SDRAMC_SDCR_CKE |
  340. MCF_SDRAMC_SDCR_DDR |
  341. MCF_SDRAMC_SDCR_MUX(1) |
  342. MCF_SDRAMC_SDCR_RCNT((int)(((SDRAM_TREFI / (SYSTEM_PERIOD * 64)) - 1) + 0.5)) |
  343. MCF_SDRAMC_SDCR_PS_16 |
  344. MCF_SDRAMC_SDCR_IPALL,
  345. MCF_SDRAMC_SDCR);
  346. /*
  347. * Write extended mode register
  348. */
  349. writel(MCF_SDRAMC_SDMR_BNKAD_LEMR |
  350. MCF_SDRAMC_SDMR_AD(0x0) |
  351. MCF_SDRAMC_SDMR_CMD,
  352. MCF_SDRAMC_SDMR);
  353. /*
  354. * Write mode register and reset DLL
  355. */
  356. writel(MCF_SDRAMC_SDMR_BNKAD_LMR |
  357. MCF_SDRAMC_SDMR_AD(0x163) |
  358. MCF_SDRAMC_SDMR_CMD,
  359. MCF_SDRAMC_SDMR);
  360. /*
  361. * Execute a PALL command
  362. */
  363. writel(readl(MCF_SDRAMC_SDCR) | MCF_SDRAMC_SDCR_IPALL, MCF_SDRAMC_SDCR);
  364. /*
  365. * Perform two REF cycles
  366. */
  367. writel(readl(MCF_SDRAMC_SDCR) | MCF_SDRAMC_SDCR_IREF, MCF_SDRAMC_SDCR);
  368. writel(readl(MCF_SDRAMC_SDCR) | MCF_SDRAMC_SDCR_IREF, MCF_SDRAMC_SDCR);
  369. /*
  370. * Write mode register and clear reset DLL
  371. */
  372. writel(MCF_SDRAMC_SDMR_BNKAD_LMR |
  373. MCF_SDRAMC_SDMR_AD(0x063) |
  374. MCF_SDRAMC_SDMR_CMD,
  375. MCF_SDRAMC_SDMR);
  376. /*
  377. * Enable auto refresh and lock SDMR
  378. */
  379. writel(readl(MCF_SDRAMC_SDCR) & ~MCF_SDRAMC_SDCR_MODE_EN,
  380. MCF_SDRAMC_SDCR);
  381. writel(MCF_SDRAMC_SDCR_REF | MCF_SDRAMC_SDCR_DQS_OE(0xC),
  382. MCF_SDRAMC_SDCR);
  383. }
  384. }
  385. void gpio_init(void)
  386. {
  387. /* Enable UART0 pins */
  388. writew(MCF_GPIO_PAR_UART_PAR_URXD0 | MCF_GPIO_PAR_UART_PAR_UTXD0,
  389. MCFGPIO_PAR_UART);
  390. /*
  391. * Initialize TIN3 as a GPIO output to enable the write
  392. * half of the latch.
  393. */
  394. writeb(0x00, MCFGPIO_PAR_TIMER);
  395. writeb(0x08, MCFGPIO_PDDR_TIMER);
  396. writeb(0x00, MCFGPIO_PCLRR_TIMER);
  397. }
  398. int clock_pll(int fsys, int flags)
  399. {
  400. int fref, temp, fout, mfd;
  401. u32 i;
  402. fref = FREF;
  403. if (fsys == 0) {
  404. /* Return current PLL output */
  405. mfd = readb(MCF_PLL_PFDR);
  406. return (fref * mfd / (BUSDIV * 4));
  407. }
  408. /* Check bounds of requested system clock */
  409. if (fsys > MAX_FSYS)
  410. fsys = MAX_FSYS;
  411. if (fsys < MIN_FSYS)
  412. fsys = MIN_FSYS;
  413. /* Multiplying by 100 when calculating the temp value,
  414. and then dividing by 100 to calculate the mfd allows
  415. for exact values without needing to include floating
  416. point libraries. */
  417. temp = 100 * fsys / fref;
  418. mfd = 4 * BUSDIV * temp / 100;
  419. /* Determine the output frequency for selected values */
  420. fout = (fref * mfd / (BUSDIV * 4));
  421. /*
  422. * Check to see if the SDRAM has already been initialized.
  423. * If it has then the SDRAM needs to be put into self refresh
  424. * mode before reprogramming the PLL.
  425. */
  426. if (readl(MCF_SDRAMC_SDCR) & MCF_SDRAMC_SDCR_REF)
  427. /* Put SDRAM into self refresh mode */
  428. writel(readl(MCF_SDRAMC_SDCR) & ~MCF_SDRAMC_SDCR_CKE,
  429. MCF_SDRAMC_SDCR);
  430. /*
  431. * Initialize the PLL to generate the new system clock frequency.
  432. * The device must be put into LIMP mode to reprogram the PLL.
  433. */
  434. /* Enter LIMP mode */
  435. clock_limp(DEFAULT_LPD);
  436. /* Reprogram PLL for desired fsys */
  437. writeb(MCF_PLL_PODR_CPUDIV(BUSDIV/3) | MCF_PLL_PODR_BUSDIV(BUSDIV),
  438. MCF_PLL_PODR);
  439. writeb(mfd, MCF_PLL_PFDR);
  440. /* Exit LIMP mode */
  441. clock_exit_limp();
  442. /*
  443. * Return the SDRAM to normal operation if it is in use.
  444. */
  445. if (readl(MCF_SDRAMC_SDCR) & MCF_SDRAMC_SDCR_REF)
  446. /* Exit self refresh mode */
  447. writel(readl(MCF_SDRAMC_SDCR) | MCF_SDRAMC_SDCR_CKE,
  448. MCF_SDRAMC_SDCR);
  449. /* Errata - workaround for SDRAM opeartion after exiting LIMP mode */
  450. writel(MCF_SDRAMC_REFRESH, MCF_SDRAMC_LIMP_FIX);
  451. /* wait for DQS logic to relock */
  452. for (i = 0; i < 0x200; i++)
  453. ;
  454. return fout;
  455. }
  456. int clock_limp(int div)
  457. {
  458. u32 temp;
  459. /* Check bounds of divider */
  460. if (div < MIN_LPD)
  461. div = MIN_LPD;
  462. if (div > MAX_LPD)
  463. div = MAX_LPD;
  464. /* Save of the current value of the SSIDIV so we don't
  465. overwrite the value*/
  466. temp = readw(MCF_CCM_CDR) & MCF_CCM_CDR_SSIDIV(0xF);
  467. /* Apply the divider to the system clock */
  468. writew(MCF_CCM_CDR_LPDIV(div) | MCF_CCM_CDR_SSIDIV(temp), MCF_CCM_CDR);
  469. writew(readw(MCF_CCM_MISCCR) | MCF_CCM_MISCCR_LIMP, MCF_CCM_MISCCR);
  470. return (FREF/(3*(1 << div)));
  471. }
  472. int clock_exit_limp(void)
  473. {
  474. int fout;
  475. /* Exit LIMP mode */
  476. writew(readw(MCF_CCM_MISCCR) & ~MCF_CCM_MISCCR_LIMP, MCF_CCM_MISCCR);
  477. /* Wait for PLL to lock */
  478. while (!(readw(MCF_CCM_MISCCR) & MCF_CCM_MISCCR_PLL_LOCK))
  479. ;
  480. fout = get_sys_clock();
  481. return fout;
  482. }
  483. int get_sys_clock(void)
  484. {
  485. int divider;
  486. /* Test to see if device is in LIMP mode */
  487. if (readw(MCF_CCM_MISCCR) & MCF_CCM_MISCCR_LIMP) {
  488. divider = readw(MCF_CCM_CDR) & MCF_CCM_CDR_LPDIV(0xF);
  489. return (FREF/(2 << divider));
  490. }
  491. else
  492. return (FREF * readb(MCF_PLL_PFDR)) / (BUSDIV * 4);
  493. }