config.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /***************************************************************************/
  2. /*
  3. * linux/arch/m68knommu/platform/532x/config.c
  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 <sh@emlix.com>
  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 <linux/spi/spi.h>
  22. #include <linux/gpio.h>
  23. #include <asm/machdep.h>
  24. #include <asm/coldfire.h>
  25. #include <asm/mcfsim.h>
  26. #include <asm/mcfuart.h>
  27. #include <asm/mcfdma.h>
  28. #include <asm/mcfwdebug.h>
  29. #include <asm/mcfqspi.h>
  30. /***************************************************************************/
  31. static struct resource m532x_fec_resources[] = {
  32. {
  33. .start = 0xfc030000,
  34. .end = 0xfc0307ff,
  35. .flags = IORESOURCE_MEM,
  36. },
  37. {
  38. .start = 64 + 36,
  39. .end = 64 + 36,
  40. .flags = IORESOURCE_IRQ,
  41. },
  42. {
  43. .start = 64 + 40,
  44. .end = 64 + 40,
  45. .flags = IORESOURCE_IRQ,
  46. },
  47. {
  48. .start = 64 + 42,
  49. .end = 64 + 42,
  50. .flags = IORESOURCE_IRQ,
  51. },
  52. };
  53. static struct platform_device m532x_fec = {
  54. .name = "fec",
  55. .id = 0,
  56. .num_resources = ARRAY_SIZE(m532x_fec_resources),
  57. .resource = m532x_fec_resources,
  58. };
  59. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  60. static struct resource m532x_qspi_resources[] = {
  61. {
  62. .start = MCFQSPI_IOBASE,
  63. .end = MCFQSPI_IOBASE + MCFQSPI_IOSIZE - 1,
  64. .flags = IORESOURCE_MEM,
  65. },
  66. {
  67. .start = MCFINT_VECBASE + MCFINT_QSPI,
  68. .end = MCFINT_VECBASE + MCFINT_QSPI,
  69. .flags = IORESOURCE_IRQ,
  70. },
  71. };
  72. #define MCFQSPI_CS0 84
  73. #define MCFQSPI_CS1 85
  74. #define MCFQSPI_CS2 86
  75. static int m532x_cs_setup(struct mcfqspi_cs_control *cs_control)
  76. {
  77. int status;
  78. status = gpio_request(MCFQSPI_CS0, "MCFQSPI_CS0");
  79. if (status) {
  80. pr_debug("gpio_request for MCFQSPI_CS0 failed\n");
  81. goto fail0;
  82. }
  83. status = gpio_direction_output(MCFQSPI_CS0, 1);
  84. if (status) {
  85. pr_debug("gpio_direction_output for MCFQSPI_CS0 failed\n");
  86. goto fail1;
  87. }
  88. status = gpio_request(MCFQSPI_CS1, "MCFQSPI_CS1");
  89. if (status) {
  90. pr_debug("gpio_request for MCFQSPI_CS1 failed\n");
  91. goto fail1;
  92. }
  93. status = gpio_direction_output(MCFQSPI_CS1, 1);
  94. if (status) {
  95. pr_debug("gpio_direction_output for MCFQSPI_CS1 failed\n");
  96. goto fail2;
  97. }
  98. status = gpio_request(MCFQSPI_CS2, "MCFQSPI_CS2");
  99. if (status) {
  100. pr_debug("gpio_request for MCFQSPI_CS2 failed\n");
  101. goto fail2;
  102. }
  103. status = gpio_direction_output(MCFQSPI_CS2, 1);
  104. if (status) {
  105. pr_debug("gpio_direction_output for MCFQSPI_CS2 failed\n");
  106. goto fail3;
  107. }
  108. return 0;
  109. fail3:
  110. gpio_free(MCFQSPI_CS2);
  111. fail2:
  112. gpio_free(MCFQSPI_CS1);
  113. fail1:
  114. gpio_free(MCFQSPI_CS0);
  115. fail0:
  116. return status;
  117. }
  118. static void m532x_cs_teardown(struct mcfqspi_cs_control *cs_control)
  119. {
  120. gpio_free(MCFQSPI_CS2);
  121. gpio_free(MCFQSPI_CS1);
  122. gpio_free(MCFQSPI_CS0);
  123. }
  124. static void m532x_cs_select(struct mcfqspi_cs_control *cs_control,
  125. u8 chip_select, bool cs_high)
  126. {
  127. gpio_set_value(MCFQSPI_CS0 + chip_select, cs_high);
  128. }
  129. static void m532x_cs_deselect(struct mcfqspi_cs_control *cs_control,
  130. u8 chip_select, bool cs_high)
  131. {
  132. gpio_set_value(MCFQSPI_CS0 + chip_select, !cs_high);
  133. }
  134. static struct mcfqspi_cs_control m532x_cs_control = {
  135. .setup = m532x_cs_setup,
  136. .teardown = m532x_cs_teardown,
  137. .select = m532x_cs_select,
  138. .deselect = m532x_cs_deselect,
  139. };
  140. static struct mcfqspi_platform_data m532x_qspi_data = {
  141. .bus_num = 0,
  142. .num_chipselect = 3,
  143. .cs_control = &m532x_cs_control,
  144. };
  145. static struct platform_device m532x_qspi = {
  146. .name = "mcfqspi",
  147. .id = 0,
  148. .num_resources = ARRAY_SIZE(m532x_qspi_resources),
  149. .resource = m532x_qspi_resources,
  150. .dev.platform_data = &m532x_qspi_data,
  151. };
  152. static void __init m532x_qspi_init(void)
  153. {
  154. /* setup QSPS pins for QSPI with gpio CS control */
  155. writew(0x01f0, MCF_GPIO_PAR_QSPI);
  156. }
  157. #endif /* defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE) */
  158. static struct platform_device *m532x_devices[] __initdata = {
  159. &m532x_fec,
  160. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  161. &m532x_qspi,
  162. #endif
  163. };
  164. /***************************************************************************/
  165. static void __init m532x_uarts_init(void)
  166. {
  167. /* UART GPIO initialization */
  168. MCF_GPIO_PAR_UART |= 0x0FFF;
  169. }
  170. /***************************************************************************/
  171. static void __init m532x_fec_init(void)
  172. {
  173. /* Set multi-function pins to ethernet mode for fec0 */
  174. MCF_GPIO_PAR_FECI2C |= (MCF_GPIO_PAR_FECI2C_PAR_MDC_EMDC |
  175. MCF_GPIO_PAR_FECI2C_PAR_MDIO_EMDIO);
  176. MCF_GPIO_PAR_FEC = (MCF_GPIO_PAR_FEC_PAR_FEC_7W_FEC |
  177. MCF_GPIO_PAR_FEC_PAR_FEC_MII_FEC);
  178. }
  179. /***************************************************************************/
  180. static void m532x_cpu_reset(void)
  181. {
  182. local_irq_disable();
  183. __raw_writeb(MCF_RCR_SWRESET, MCF_RCR);
  184. }
  185. /***************************************************************************/
  186. void __init config_BSP(char *commandp, int size)
  187. {
  188. #if !defined(CONFIG_BOOTPARAM)
  189. /* Copy command line from FLASH to local buffer... */
  190. memcpy(commandp, (char *) 0x4000, 4);
  191. if(strncmp(commandp, "kcl ", 4) == 0){
  192. memcpy(commandp, (char *) 0x4004, size);
  193. commandp[size-1] = 0;
  194. } else {
  195. memset(commandp, 0, size);
  196. }
  197. #endif
  198. mach_sched_init = hw_timer_init;
  199. #ifdef CONFIG_BDM_DISABLE
  200. /*
  201. * Disable the BDM clocking. This also turns off most of the rest of
  202. * the BDM device. This is good for EMC reasons. This option is not
  203. * incompatible with the memory protection option.
  204. */
  205. wdebug(MCFDEBUG_CSR, MCFDEBUG_CSR_PSTCLK);
  206. #endif
  207. }
  208. /***************************************************************************/
  209. static int __init init_BSP(void)
  210. {
  211. m532x_uarts_init();
  212. m532x_fec_init();
  213. #if defined(CONFIG_SPI_COLDFIRE_QSPI) || defined(CONFIG_SPI_COLDFIRE_QSPI_MODULE)
  214. m532x_qspi_init();
  215. #endif
  216. platform_add_devices(m532x_devices, ARRAY_SIZE(m532x_devices));
  217. return 0;
  218. }
  219. arch_initcall(init_BSP);
  220. /***************************************************************************/
  221. /* Board initialization */
  222. /***************************************************************************/
  223. /*
  224. * PLL min/max specifications
  225. */
  226. #define MAX_FVCO 500000 /* KHz */
  227. #define MAX_FSYS 80000 /* KHz */
  228. #define MIN_FSYS 58333 /* KHz */
  229. #define FREF 16000 /* KHz */
  230. #define MAX_MFD 135 /* Multiplier */
  231. #define MIN_MFD 88 /* Multiplier */
  232. #define BUSDIV 6 /* Divider */
  233. /*
  234. * Low Power Divider specifications
  235. */
  236. #define MIN_LPD (1 << 0) /* Divider (not encoded) */
  237. #define MAX_LPD (1 << 15) /* Divider (not encoded) */
  238. #define DEFAULT_LPD (1 << 1) /* Divider (not encoded) */
  239. #define SYS_CLK_KHZ 80000
  240. #define SYSTEM_PERIOD 12.5
  241. /*
  242. * SDRAM Timing Parameters
  243. */
  244. #define SDRAM_BL 8 /* # of beats in a burst */
  245. #define SDRAM_TWR 2 /* in clocks */
  246. #define SDRAM_CASL 2.5 /* CASL in clocks */
  247. #define SDRAM_TRCD 2 /* in clocks */
  248. #define SDRAM_TRP 2 /* in clocks */
  249. #define SDRAM_TRFC 7 /* in clocks */
  250. #define SDRAM_TREFI 7800 /* in ns */
  251. #define EXT_SRAM_ADDRESS (0xC0000000)
  252. #define FLASH_ADDRESS (0x00000000)
  253. #define SDRAM_ADDRESS (0x40000000)
  254. #define NAND_FLASH_ADDRESS (0xD0000000)
  255. int sys_clk_khz = 0;
  256. int sys_clk_mhz = 0;
  257. void wtm_init(void);
  258. void scm_init(void);
  259. void gpio_init(void);
  260. void fbcs_init(void);
  261. void sdramc_init(void);
  262. int clock_pll (int fsys, int flags);
  263. int clock_limp (int);
  264. int clock_exit_limp (void);
  265. int get_sys_clock (void);
  266. asmlinkage void __init sysinit(void)
  267. {
  268. sys_clk_khz = clock_pll(0, 0);
  269. sys_clk_mhz = sys_clk_khz/1000;
  270. wtm_init();
  271. scm_init();
  272. gpio_init();
  273. fbcs_init();
  274. sdramc_init();
  275. }
  276. void wtm_init(void)
  277. {
  278. /* Disable watchdog timer */
  279. MCF_WTM_WCR = 0;
  280. }
  281. #define MCF_SCM_BCR_GBW (0x00000100)
  282. #define MCF_SCM_BCR_GBR (0x00000200)
  283. void scm_init(void)
  284. {
  285. /* All masters are trusted */
  286. MCF_SCM_MPR = 0x77777777;
  287. /* Allow supervisor/user, read/write, and trusted/untrusted
  288. access to all slaves */
  289. MCF_SCM_PACRA = 0;
  290. MCF_SCM_PACRB = 0;
  291. MCF_SCM_PACRC = 0;
  292. MCF_SCM_PACRD = 0;
  293. MCF_SCM_PACRE = 0;
  294. MCF_SCM_PACRF = 0;
  295. /* Enable bursts */
  296. MCF_SCM_BCR = (MCF_SCM_BCR_GBR | MCF_SCM_BCR_GBW);
  297. }
  298. void fbcs_init(void)
  299. {
  300. MCF_GPIO_PAR_CS = 0x0000003E;
  301. /* Latch chip select */
  302. MCF_FBCS1_CSAR = 0x10080000;
  303. MCF_FBCS1_CSCR = 0x002A3780;
  304. MCF_FBCS1_CSMR = (MCF_FBCS_CSMR_BAM_2M | MCF_FBCS_CSMR_V);
  305. /* Initialize latch to drive signals to inactive states */
  306. *((u16 *)(0x10080000)) = 0xFFFF;
  307. /* External SRAM */
  308. MCF_FBCS1_CSAR = EXT_SRAM_ADDRESS;
  309. MCF_FBCS1_CSCR = (MCF_FBCS_CSCR_PS_16
  310. | MCF_FBCS_CSCR_AA
  311. | MCF_FBCS_CSCR_SBM
  312. | MCF_FBCS_CSCR_WS(1));
  313. MCF_FBCS1_CSMR = (MCF_FBCS_CSMR_BAM_512K
  314. | MCF_FBCS_CSMR_V);
  315. /* Boot Flash connected to FBCS0 */
  316. MCF_FBCS0_CSAR = FLASH_ADDRESS;
  317. MCF_FBCS0_CSCR = (MCF_FBCS_CSCR_PS_16
  318. | MCF_FBCS_CSCR_BEM
  319. | MCF_FBCS_CSCR_AA
  320. | MCF_FBCS_CSCR_SBM
  321. | MCF_FBCS_CSCR_WS(7));
  322. MCF_FBCS0_CSMR = (MCF_FBCS_CSMR_BAM_32M
  323. | MCF_FBCS_CSMR_V);
  324. }
  325. void sdramc_init(void)
  326. {
  327. /*
  328. * Check to see if the SDRAM has already been initialized
  329. * by a run control tool
  330. */
  331. if (!(MCF_SDRAMC_SDCR & MCF_SDRAMC_SDCR_REF)) {
  332. /* SDRAM chip select initialization */
  333. /* Initialize SDRAM chip select */
  334. MCF_SDRAMC_SDCS0 = (0
  335. | MCF_SDRAMC_SDCS_BA(SDRAM_ADDRESS)
  336. | MCF_SDRAMC_SDCS_CSSZ(MCF_SDRAMC_SDCS_CSSZ_32MBYTE));
  337. /*
  338. * Basic configuration and initialization
  339. */
  340. MCF_SDRAMC_SDCFG1 = (0
  341. | MCF_SDRAMC_SDCFG1_SRD2RW((int)((SDRAM_CASL + 2) + 0.5 ))
  342. | MCF_SDRAMC_SDCFG1_SWT2RD(SDRAM_TWR + 1)
  343. | MCF_SDRAMC_SDCFG1_RDLAT((int)((SDRAM_CASL*2) + 2))
  344. | MCF_SDRAMC_SDCFG1_ACT2RW((int)((SDRAM_TRCD ) + 0.5))
  345. | MCF_SDRAMC_SDCFG1_PRE2ACT((int)((SDRAM_TRP ) + 0.5))
  346. | MCF_SDRAMC_SDCFG1_REF2ACT((int)(((SDRAM_TRFC) ) + 0.5))
  347. | MCF_SDRAMC_SDCFG1_WTLAT(3));
  348. MCF_SDRAMC_SDCFG2 = (0
  349. | MCF_SDRAMC_SDCFG2_BRD2PRE(SDRAM_BL/2 + 1)
  350. | MCF_SDRAMC_SDCFG2_BWT2RW(SDRAM_BL/2 + SDRAM_TWR)
  351. | MCF_SDRAMC_SDCFG2_BRD2WT((int)((SDRAM_CASL+SDRAM_BL/2-1.0)+0.5))
  352. | MCF_SDRAMC_SDCFG2_BL(SDRAM_BL-1));
  353. /*
  354. * Precharge and enable write to SDMR
  355. */
  356. MCF_SDRAMC_SDCR = (0
  357. | MCF_SDRAMC_SDCR_MODE_EN
  358. | MCF_SDRAMC_SDCR_CKE
  359. | MCF_SDRAMC_SDCR_DDR
  360. | MCF_SDRAMC_SDCR_MUX(1)
  361. | MCF_SDRAMC_SDCR_RCNT((int)(((SDRAM_TREFI/(SYSTEM_PERIOD*64)) - 1) + 0.5))
  362. | MCF_SDRAMC_SDCR_PS_16
  363. | MCF_SDRAMC_SDCR_IPALL);
  364. /*
  365. * Write extended mode register
  366. */
  367. MCF_SDRAMC_SDMR = (0
  368. | MCF_SDRAMC_SDMR_BNKAD_LEMR
  369. | MCF_SDRAMC_SDMR_AD(0x0)
  370. | MCF_SDRAMC_SDMR_CMD);
  371. /*
  372. * Write mode register and reset DLL
  373. */
  374. MCF_SDRAMC_SDMR = (0
  375. | MCF_SDRAMC_SDMR_BNKAD_LMR
  376. | MCF_SDRAMC_SDMR_AD(0x163)
  377. | MCF_SDRAMC_SDMR_CMD);
  378. /*
  379. * Execute a PALL command
  380. */
  381. MCF_SDRAMC_SDCR |= MCF_SDRAMC_SDCR_IPALL;
  382. /*
  383. * Perform two REF cycles
  384. */
  385. MCF_SDRAMC_SDCR |= MCF_SDRAMC_SDCR_IREF;
  386. MCF_SDRAMC_SDCR |= MCF_SDRAMC_SDCR_IREF;
  387. /*
  388. * Write mode register and clear reset DLL
  389. */
  390. MCF_SDRAMC_SDMR = (0
  391. | MCF_SDRAMC_SDMR_BNKAD_LMR
  392. | MCF_SDRAMC_SDMR_AD(0x063)
  393. | MCF_SDRAMC_SDMR_CMD);
  394. /*
  395. * Enable auto refresh and lock SDMR
  396. */
  397. MCF_SDRAMC_SDCR &= ~MCF_SDRAMC_SDCR_MODE_EN;
  398. MCF_SDRAMC_SDCR |= (0
  399. | MCF_SDRAMC_SDCR_REF
  400. | MCF_SDRAMC_SDCR_DQS_OE(0xC));
  401. }
  402. }
  403. void gpio_init(void)
  404. {
  405. /* Enable UART0 pins */
  406. MCF_GPIO_PAR_UART = ( 0
  407. | MCF_GPIO_PAR_UART_PAR_URXD0
  408. | MCF_GPIO_PAR_UART_PAR_UTXD0);
  409. /* Initialize TIN3 as a GPIO output to enable the write
  410. half of the latch */
  411. MCF_GPIO_PAR_TIMER = 0x00;
  412. __raw_writeb(0x08, MCFGPIO_PDDR_TIMER);
  413. __raw_writeb(0x00, MCFGPIO_PCLRR_TIMER);
  414. }
  415. int clock_pll(int fsys, int flags)
  416. {
  417. int fref, temp, fout, mfd;
  418. u32 i;
  419. fref = FREF;
  420. if (fsys == 0) {
  421. /* Return current PLL output */
  422. mfd = MCF_PLL_PFDR;
  423. return (fref * mfd / (BUSDIV * 4));
  424. }
  425. /* Check bounds of requested system clock */
  426. if (fsys > MAX_FSYS)
  427. fsys = MAX_FSYS;
  428. if (fsys < MIN_FSYS)
  429. fsys = MIN_FSYS;
  430. /* Multiplying by 100 when calculating the temp value,
  431. and then dividing by 100 to calculate the mfd allows
  432. for exact values without needing to include floating
  433. point libraries. */
  434. temp = 100 * fsys / fref;
  435. mfd = 4 * BUSDIV * temp / 100;
  436. /* Determine the output frequency for selected values */
  437. fout = (fref * mfd / (BUSDIV * 4));
  438. /*
  439. * Check to see if the SDRAM has already been initialized.
  440. * If it has then the SDRAM needs to be put into self refresh
  441. * mode before reprogramming the PLL.
  442. */
  443. if (MCF_SDRAMC_SDCR & MCF_SDRAMC_SDCR_REF)
  444. /* Put SDRAM into self refresh mode */
  445. MCF_SDRAMC_SDCR &= ~MCF_SDRAMC_SDCR_CKE;
  446. /*
  447. * Initialize the PLL to generate the new system clock frequency.
  448. * The device must be put into LIMP mode to reprogram the PLL.
  449. */
  450. /* Enter LIMP mode */
  451. clock_limp(DEFAULT_LPD);
  452. /* Reprogram PLL for desired fsys */
  453. MCF_PLL_PODR = (0
  454. | MCF_PLL_PODR_CPUDIV(BUSDIV/3)
  455. | MCF_PLL_PODR_BUSDIV(BUSDIV));
  456. MCF_PLL_PFDR = mfd;
  457. /* Exit LIMP mode */
  458. clock_exit_limp();
  459. /*
  460. * Return the SDRAM to normal operation if it is in use.
  461. */
  462. if (MCF_SDRAMC_SDCR & MCF_SDRAMC_SDCR_REF)
  463. /* Exit self refresh mode */
  464. MCF_SDRAMC_SDCR |= MCF_SDRAMC_SDCR_CKE;
  465. /* Errata - workaround for SDRAM opeartion after exiting LIMP mode */
  466. MCF_SDRAMC_LIMP_FIX = MCF_SDRAMC_REFRESH;
  467. /* wait for DQS logic to relock */
  468. for (i = 0; i < 0x200; i++)
  469. ;
  470. return fout;
  471. }
  472. int clock_limp(int div)
  473. {
  474. u32 temp;
  475. /* Check bounds of divider */
  476. if (div < MIN_LPD)
  477. div = MIN_LPD;
  478. if (div > MAX_LPD)
  479. div = MAX_LPD;
  480. /* Save of the current value of the SSIDIV so we don't
  481. overwrite the value*/
  482. temp = (MCF_CCM_CDR & MCF_CCM_CDR_SSIDIV(0xF));
  483. /* Apply the divider to the system clock */
  484. MCF_CCM_CDR = ( 0
  485. | MCF_CCM_CDR_LPDIV(div)
  486. | MCF_CCM_CDR_SSIDIV(temp));
  487. MCF_CCM_MISCCR |= MCF_CCM_MISCCR_LIMP;
  488. return (FREF/(3*(1 << div)));
  489. }
  490. int clock_exit_limp(void)
  491. {
  492. int fout;
  493. /* Exit LIMP mode */
  494. MCF_CCM_MISCCR = (MCF_CCM_MISCCR & ~ MCF_CCM_MISCCR_LIMP);
  495. /* Wait for PLL to lock */
  496. while (!(MCF_CCM_MISCCR & MCF_CCM_MISCCR_PLL_LOCK))
  497. ;
  498. fout = get_sys_clock();
  499. return fout;
  500. }
  501. int get_sys_clock(void)
  502. {
  503. int divider;
  504. /* Test to see if device is in LIMP mode */
  505. if (MCF_CCM_MISCCR & MCF_CCM_MISCCR_LIMP) {
  506. divider = MCF_CCM_CDR & MCF_CCM_CDR_LPDIV(0xF);
  507. return (FREF/(2 << divider));
  508. }
  509. else
  510. return ((FREF * MCF_PLL_PFDR) / (BUSDIV * 4));
  511. }