config.c 12 KB

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