config.c 12 KB

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