cpu_init.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /*
  2. * (C) Copyright 2003
  3. * Josef Baumgartner <josef.baumgartner@telex.de>
  4. *
  5. * MCF5282 additionals
  6. * (C) Copyright 2005
  7. * BuS Elektronik GmbH & Co. KG <esw@bus-elektronik.de>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <watchdog.h>
  29. #include <asm/immap.h>
  30. #if defined(CONFIG_M5271)
  31. void cpu_init_f(void)
  32. {
  33. #ifndef CONFIG_WATCHDOG
  34. /* Disable the watchdog if we aren't using it */
  35. mbar_writeShort(MCF_WTM_WCR, 0);
  36. #endif
  37. /* Set clockspeed to 100MHz */
  38. mbar_writeShort(MCF_FMPLL_SYNCR,
  39. MCF_FMPLL_SYNCR_MFD(0) | MCF_FMPLL_SYNCR_RFD(0));
  40. while (!mbar_readByte(MCF_FMPLL_SYNSR) & MCF_FMPLL_SYNSR_LOCK) ;
  41. }
  42. /*
  43. * initialize higher level parts of CPU like timers
  44. */
  45. int cpu_init_r(void)
  46. {
  47. return (0);
  48. }
  49. void uart_port_conf(void)
  50. {
  51. /* Setup Ports: */
  52. switch (CFG_UART_PORT) {
  53. case 0:
  54. mbar_writeShort(MCF_GPIO_PAR_UART, MCF_GPIO_PAR_UART_U0TXD |
  55. MCF_GPIO_PAR_UART_U0RXD);
  56. break;
  57. case 1:
  58. mbar_writeShort(MCF_GPIO_PAR_UART,
  59. MCF_GPIO_PAR_UART_U1RXD_UART1 |
  60. MCF_GPIO_PAR_UART_U1TXD_UART1);
  61. break;
  62. case 2:
  63. mbar_writeShort(MCF_GPIO_PAR_UART, 0x3000);
  64. break;
  65. }
  66. }
  67. #endif
  68. #if defined(CONFIG_M5272)
  69. /*
  70. * Breath some life into the CPU...
  71. *
  72. * Set up the memory map,
  73. * initialize a bunch of registers,
  74. * initialize the UPM's
  75. */
  76. void cpu_init_f(void)
  77. {
  78. /* if we come from RAM we assume the CPU is
  79. * already initialized.
  80. */
  81. #ifndef CONFIG_MONITOR_IS_IN_RAM
  82. volatile sysctrl_t *sysctrl = (sysctrl_t *) (CFG_MBAR);
  83. volatile gpio_t *gpio = (gpio_t *) (MMAP_GPIO);
  84. volatile csctrl_t *csctrl = (csctrl_t *) (MMAP_FBCS);
  85. sysctrl->sc_scr = CFG_SCR;
  86. sysctrl->sc_spr = CFG_SPR;
  87. /* Setup Ports: */
  88. gpio->gpio_pacnt = CFG_PACNT;
  89. gpio->gpio_paddr = CFG_PADDR;
  90. gpio->gpio_padat = CFG_PADAT;
  91. gpio->gpio_pbcnt = CFG_PBCNT;
  92. gpio->gpio_pbddr = CFG_PBDDR;
  93. gpio->gpio_pbdat = CFG_PBDAT;
  94. gpio->gpio_pdcnt = CFG_PDCNT;
  95. /* Memory Controller: */
  96. csctrl->cs_br0 = CFG_BR0_PRELIM;
  97. csctrl->cs_or0 = CFG_OR0_PRELIM;
  98. #if (defined(CFG_OR1_PRELIM) && defined(CFG_BR1_PRELIM))
  99. csctrl->cs_br1 = CFG_BR1_PRELIM;
  100. csctrl->cs_or1 = CFG_OR1_PRELIM;
  101. #endif
  102. #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
  103. csctrl->cs_br2 = CFG_BR2_PRELIM;
  104. csctrl->cs_or2 = CFG_OR2_PRELIM;
  105. #endif
  106. #if defined(CFG_OR3_PRELIM) && defined(CFG_BR3_PRELIM)
  107. csctrl->cs_br3 = CFG_BR3_PRELIM;
  108. csctrl->cs_or3 = CFG_OR3_PRELIM;
  109. #endif
  110. #if defined(CFG_OR4_PRELIM) && defined(CFG_BR4_PRELIM)
  111. csctrl->cs_br4 = CFG_BR4_PRELIM;
  112. csctrl->cs_or4 = CFG_OR4_PRELIM;
  113. #endif
  114. #if defined(CFG_OR5_PRELIM) && defined(CFG_BR5_PRELIM)
  115. csctrl->cs_br5 = CFG_BR5_PRELIM;
  116. csctrl->cs_or5 = CFG_OR5_PRELIM;
  117. #endif
  118. #if defined(CFG_OR6_PRELIM) && defined(CFG_BR6_PRELIM)
  119. csctrl->cs_br6 = CFG_BR6_PRELIM;
  120. csctrl->cs_or6 = CFG_OR6_PRELIM;
  121. #endif
  122. #if defined(CFG_OR7_PRELIM) && defined(CFG_BR7_PRELIM)
  123. csctrl->cs_br7 = CFG_BR7_PRELIM;
  124. csctrl->cs_or7 = CFG_OR7_PRELIM;
  125. #endif
  126. #endif /* #ifndef CONFIG_MONITOR_IS_IN_RAM */
  127. /* enable instruction cache now */
  128. icache_enable();
  129. }
  130. /*
  131. * initialize higher level parts of CPU like timers
  132. */
  133. int cpu_init_r(void)
  134. {
  135. return (0);
  136. }
  137. void uart_port_conf(void)
  138. {
  139. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  140. /* Setup Ports: */
  141. switch (CFG_UART_PORT) {
  142. case 0:
  143. gpio->gpio_pbcnt &= ~(GPIO_PBCNT_PB0MSK | GPIO_PBCNT_PB1MSK);
  144. gpio->gpio_pbcnt |= (GPIO_PBCNT_URT0_TXD | GPIO_PBCNT_URT0_RXD);
  145. break;
  146. case 1:
  147. gpio->gpio_pdcnt &= ~(GPIO_PDCNT_PD1MSK | GPIO_PDCNT_PD4MSK);
  148. gpio->gpio_pdcnt |= (GPIO_PDCNT_URT1_RXD | GPIO_PDCNT_URT1_TXD);
  149. break;
  150. }
  151. }
  152. #endif /* #if defined(CONFIG_M5272) */
  153. #if defined(CONFIG_M5282)
  154. /*
  155. * Breath some life into the CPU...
  156. *
  157. * Set up the memory map,
  158. * initialize a bunch of registers,
  159. * initialize the UPM's
  160. */
  161. void cpu_init_f(void)
  162. {
  163. #ifndef CONFIG_WATCHDOG
  164. /* disable watchdog if we aren't using it */
  165. MCFWTM_WCR = 0;
  166. #endif
  167. #ifndef CONFIG_MONITOR_IS_IN_RAM
  168. /* Set speed /PLL */
  169. MCFCLOCK_SYNCR =
  170. MCFCLOCK_SYNCR_MFD(CFG_MFD) | MCFCLOCK_SYNCR_RFD(CFG_RFD);
  171. while (!(MCFCLOCK_SYNSR & MCFCLOCK_SYNSR_LOCK)) ;
  172. MCFGPIO_PBCDPAR = 0xc0;
  173. /* Set up the GPIO ports */
  174. #ifdef CFG_PEPAR
  175. MCFGPIO_PEPAR = CFG_PEPAR;
  176. #endif
  177. #ifdef CFG_PFPAR
  178. MCFGPIO_PFPAR = CFG_PFPAR;
  179. #endif
  180. #ifdef CFG_PJPAR
  181. MCFGPIO_PJPAR = CFG_PJPAR;
  182. #endif
  183. #ifdef CFG_PSDPAR
  184. MCFGPIO_PSDPAR = CFG_PSDPAR;
  185. #endif
  186. #ifdef CFG_PASPAR
  187. MCFGPIO_PASPAR = CFG_PASPAR;
  188. #endif
  189. #ifdef CFG_PEHLPAR
  190. MCFGPIO_PEHLPAR = CFG_PEHLPAR;
  191. #endif
  192. #ifdef CFG_PQSPAR
  193. MCFGPIO_PQSPAR = CFG_PQSPAR;
  194. #endif
  195. #ifdef CFG_PTCPAR
  196. MCFGPIO_PTCPAR = CFG_PTCPAR;
  197. #endif
  198. #ifdef CFG_PTDPAR
  199. MCFGPIO_PTDPAR = CFG_PTDPAR;
  200. #endif
  201. #ifdef CFG_PUAPAR
  202. MCFGPIO_PUAPAR = CFG_PUAPAR;
  203. #endif
  204. #ifdef CFG_DDRUA
  205. MCFGPIO_DDRUA = CFG_DDRUA;
  206. #endif
  207. /* This is probably a bad place to setup chip selects, but everyone
  208. else is doing it! */
  209. #if defined(CFG_CS0_BASE) & defined(CFG_CS0_SIZE) & \
  210. defined(CFG_CS0_WIDTH) & defined(CFG_CS0_RO) & \
  211. defined(CFG_CS0_WS)
  212. MCFCSM_CSAR0 = (CFG_CS0_BASE >> 16) & 0xFFFF;
  213. #if (CFG_CS0_WIDTH == 8)
  214. #define CFG_CS0_PS MCFCSM_CSCR_PS_8
  215. #elif (CFG_CS0_WIDTH == 16)
  216. #define CFG_CS0_PS MCFCSM_CSCR_PS_16
  217. #elif (CFG_CS0_WIDTH == 32)
  218. #define CFG_CS0_PS MCFCSM_CSCR_PS_32
  219. #else
  220. #error "CFG_CS0_WIDTH: Fault - wrong bus with for CS0"
  221. #endif
  222. MCFCSM_CSCR0 = MCFCSM_CSCR_WS(CFG_CS0_WS)
  223. | CFG_CS0_PS | MCFCSM_CSCR_AA;
  224. #if (CFG_CS0_RO != 0)
  225. MCFCSM_CSMR0 = MCFCSM_CSMR_BAM(CFG_CS0_SIZE - 1)
  226. | MCFCSM_CSMR_WP | MCFCSM_CSMR_V;
  227. #else
  228. MCFCSM_CSMR0 = MCFCSM_CSMR_BAM(CFG_CS0_SIZE - 1) | MCFCSM_CSMR_V;
  229. #endif
  230. #else
  231. #waring "Chip Select 0 are not initialized/used"
  232. #endif
  233. #if defined(CFG_CS1_BASE) & defined(CFG_CS1_SIZE) & \
  234. defined(CFG_CS1_WIDTH) & defined(CFG_CS1_RO) & \
  235. defined(CFG_CS1_WS)
  236. MCFCSM_CSAR1 = (CFG_CS1_BASE >> 16) & 0xFFFF;
  237. #if (CFG_CS1_WIDTH == 8)
  238. #define CFG_CS1_PS MCFCSM_CSCR_PS_8
  239. #elif (CFG_CS1_WIDTH == 16)
  240. #define CFG_CS1_PS MCFCSM_CSCR_PS_16
  241. #elif (CFG_CS1_WIDTH == 32)
  242. #define CFG_CS1_PS MCFCSM_CSCR_PS_32
  243. #else
  244. #error "CFG_CS1_WIDTH: Fault - wrong bus with for CS1"
  245. #endif
  246. MCFCSM_CSCR1 = MCFCSM_CSCR_WS(CFG_CS1_WS)
  247. | CFG_CS1_PS | MCFCSM_CSCR_AA;
  248. #if (CFG_CS1_RO != 0)
  249. MCFCSM_CSMR1 = MCFCSM_CSMR_BAM(CFG_CS1_SIZE - 1)
  250. | MCFCSM_CSMR_WP | MCFCSM_CSMR_V;
  251. #else
  252. MCFCSM_CSMR1 = MCFCSM_CSMR_BAM(CFG_CS1_SIZE - 1)
  253. | MCFCSM_CSMR_V;
  254. #endif
  255. #else
  256. #warning "Chip Select 1 are not initialized/used"
  257. #endif
  258. #if defined(CFG_CS2_BASE) & defined(CFG_CS2_SIZE) & \
  259. defined(CFG_CS2_WIDTH) & defined(CFG_CS2_RO) & \
  260. defined(CFG_CS2_WS)
  261. MCFCSM_CSAR2 = (CFG_CS2_BASE >> 16) & 0xFFFF;
  262. #if (CFG_CS2_WIDTH == 8)
  263. #define CFG_CS2_PS MCFCSM_CSCR_PS_8
  264. #elif (CFG_CS2_WIDTH == 16)
  265. #define CFG_CS2_PS MCFCSM_CSCR_PS_16
  266. #elif (CFG_CS2_WIDTH == 32)
  267. #define CFG_CS2_PS MCFCSM_CSCR_PS_32
  268. #else
  269. #error "CFG_CS2_WIDTH: Fault - wrong bus with for CS2"
  270. #endif
  271. MCFCSM_CSCR2 = MCFCSM_CSCR_WS(CFG_CS2_WS)
  272. | CFG_CS2_PS | MCFCSM_CSCR_AA;
  273. #if (CFG_CS2_RO != 0)
  274. MCFCSM_CSMR2 = MCFCSM_CSMR_BAM(CFG_CS2_SIZE - 1)
  275. | MCFCSM_CSMR_WP | MCFCSM_CSMR_V;
  276. #else
  277. MCFCSM_CSMR2 = MCFCSM_CSMR_BAM(CFG_CS2_SIZE - 1)
  278. | MCFCSM_CSMR_V;
  279. #endif
  280. #else
  281. #warning "Chip Select 2 are not initialized/used"
  282. #endif
  283. #if defined(CFG_CS3_BASE) & defined(CFG_CS3_SIZE) & \
  284. defined(CFG_CS3_WIDTH) & defined(CFG_CS3_RO) & \
  285. defined(CFG_CS3_WS)
  286. MCFCSM_CSAR3 = (CFG_CS3_BASE >> 16) & 0xFFFF;
  287. #if (CFG_CS3_WIDTH == 8)
  288. #define CFG_CS3_PS MCFCSM_CSCR_PS_8
  289. #elif (CFG_CS3_WIDTH == 16)
  290. #define CFG_CS3_PS MCFCSM_CSCR_PS_16
  291. #elif (CFG_CS3_WIDTH == 32)
  292. #define CFG_CS3_PS MCFCSM_CSCR_PS_32
  293. #else
  294. #error "CFG_CS3_WIDTH: Fault - wrong bus with for CS1"
  295. #endif
  296. MCFCSM_CSCR3 = MCFCSM_CSCR_WS(CFG_CS3_WS)
  297. | CFG_CS3_PS | MCFCSM_CSCR_AA;
  298. #if (CFG_CS3_RO != 0)
  299. MCFCSM_CSMR3 = MCFCSM_CSMR_BAM(CFG_CS3_SIZE - 1)
  300. | MCFCSM_CSMR_WP | MCFCSM_CSMR_V;
  301. #else
  302. MCFCSM_CSMR3 = MCFCSM_CSMR_BAM(CFG_CS3_SIZE - 1)
  303. | MCFCSM_CSMR_V;
  304. #endif
  305. #else
  306. #warning "Chip Select 3 are not initialized/used"
  307. #endif
  308. #endif /* CONFIG_MONITOR_IS_IN_RAM */
  309. /* defer enabling cache until boot (see do_go) */
  310. /* icache_enable(); */
  311. }
  312. /*
  313. * initialize higher level parts of CPU like timers
  314. */
  315. int cpu_init_r(void)
  316. {
  317. return (0);
  318. }
  319. void uart_port_conf(void)
  320. {
  321. /* Setup Ports: */
  322. switch (CFG_UART_PORT) {
  323. case 0:
  324. MCFGPIO_PUAPAR &= 0xFc;
  325. MCFGPIO_PUAPAR |= 0x03;
  326. break;
  327. case 1:
  328. MCFGPIO_PUAPAR &= 0xF3;
  329. MCFGPIO_PUAPAR |= 0x0C;
  330. break;
  331. case 2:
  332. MCFGPIO_PASPAR &= 0xFF0F;
  333. MCFGPIO_PASPAR |= 0x00A0;
  334. break;
  335. }
  336. }
  337. #endif
  338. #if defined(CONFIG_M5249)
  339. /*
  340. * Breath some life into the CPU...
  341. *
  342. * Set up the memory map,
  343. * initialize a bunch of registers,
  344. * initialize the UPM's
  345. */
  346. void cpu_init_f(void)
  347. {
  348. #ifndef CFG_PLL_BYPASS
  349. /*
  350. * Setup the PLL to run at the specified speed
  351. *
  352. */
  353. volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
  354. unsigned long pllcr;
  355. #ifdef CFG_FAST_CLK
  356. pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
  357. #else
  358. pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
  359. #endif
  360. cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
  361. mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
  362. mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
  363. pllcr ^= 0x00000001; /* Set pll bypass to 1 */
  364. mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
  365. udelay(0x20); /* Wait for a lock ... */
  366. #endif /* #ifndef CFG_PLL_BYPASS */
  367. /*
  368. * NOTE: by setting the GPIO_FUNCTION registers, we ensure that the UART pins
  369. * (UART0: gpio 30,27, UART1: gpio 31, 28) will be used as UART pins
  370. * which is their primary function.
  371. * ~Jeremy
  372. */
  373. mbar2_writeLong(MCFSIM_GPIO_FUNC, CFG_GPIO_FUNC);
  374. mbar2_writeLong(MCFSIM_GPIO1_FUNC, CFG_GPIO1_FUNC);
  375. mbar2_writeLong(MCFSIM_GPIO_EN, CFG_GPIO_EN);
  376. mbar2_writeLong(MCFSIM_GPIO1_EN, CFG_GPIO1_EN);
  377. mbar2_writeLong(MCFSIM_GPIO_OUT, CFG_GPIO_OUT);
  378. mbar2_writeLong(MCFSIM_GPIO1_OUT, CFG_GPIO1_OUT);
  379. /*
  380. * dBug Compliance:
  381. * You can verify these values by using dBug's 'ird'
  382. * (Internal Register Display) command
  383. * ~Jeremy
  384. *
  385. */
  386. mbar_writeByte(MCFSIM_MPARK, 0x30); /* 5249 Internal Core takes priority over DMA */
  387. mbar_writeByte(MCFSIM_SYPCR, 0x00);
  388. mbar_writeByte(MCFSIM_SWIVR, 0x0f);
  389. mbar_writeByte(MCFSIM_SWSR, 0x00);
  390. mbar_writeLong(MCFSIM_IMR, 0xfffffbff);
  391. mbar_writeByte(MCFSIM_SWDICR, 0x00);
  392. mbar_writeByte(MCFSIM_TIMER1ICR, 0x00);
  393. mbar_writeByte(MCFSIM_TIMER2ICR, 0x88);
  394. mbar_writeByte(MCFSIM_I2CICR, 0x00);
  395. mbar_writeByte(MCFSIM_UART1ICR, 0x00);
  396. mbar_writeByte(MCFSIM_UART2ICR, 0x00);
  397. mbar_writeByte(MCFSIM_ICR6, 0x00);
  398. mbar_writeByte(MCFSIM_ICR7, 0x00);
  399. mbar_writeByte(MCFSIM_ICR8, 0x00);
  400. mbar_writeByte(MCFSIM_ICR9, 0x00);
  401. mbar_writeByte(MCFSIM_QSPIICR, 0x00);
  402. mbar2_writeLong(MCFSIM_GPIO_INT_EN, 0x00000080);
  403. mbar2_writeByte(MCFSIM_INTBASE, 0x40); /* Base interrupts at 64 */
  404. mbar2_writeByte(MCFSIM_SPURVEC, 0x00);
  405. mbar2_writeLong(MCFSIM_IDECONFIG1, 0x00000020); /* Enable a 1 cycle pre-drive cycle on CS1 */
  406. /* Setup interrupt priorities for gpio7 */
  407. /* mbar2_writeLong(MCFSIM_INTLEV5, 0x70000000); */
  408. /* IDE Config registers */
  409. mbar2_writeLong(MCFSIM_IDECONFIG1, 0x00000020);
  410. mbar2_writeLong(MCFSIM_IDECONFIG2, 0x00000000);
  411. /*
  412. * Setup chip selects...
  413. */
  414. mbar_writeShort(MCFSIM_CSAR1, CFG_CSAR1);
  415. mbar_writeShort(MCFSIM_CSCR1, CFG_CSCR1);
  416. mbar_writeLong(MCFSIM_CSMR1, CFG_CSMR1);
  417. mbar_writeShort(MCFSIM_CSAR0, CFG_CSAR0);
  418. mbar_writeShort(MCFSIM_CSCR0, CFG_CSCR0);
  419. mbar_writeLong(MCFSIM_CSMR0, CFG_CSMR0);
  420. /* enable instruction cache now */
  421. icache_enable();
  422. }
  423. /*
  424. * initialize higher level parts of CPU like timers
  425. */
  426. int cpu_init_r(void)
  427. {
  428. return (0);
  429. }
  430. void uart_port_conf(void)
  431. {
  432. /* Setup Ports: */
  433. switch (CFG_UART_PORT) {
  434. case 0:
  435. break;
  436. case 1:
  437. break;
  438. }
  439. }
  440. #endif /* #if defined(CONFIG_M5249) */