config.c 12 KB

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