3 * Josef Baumgartner <josef.baumgartner@telex.de>
7 * BuS Elektronik GmbH & Co. KG <esw@bus-elektronik.de>
9 * See file CREDITS for list of people who contributed to this
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.
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.
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,
32 #include <asm/m5271.h>
33 #include <asm/immap_5271.h>
37 #include <asm/m5272.h>
38 #include <asm/immap_5272.h>
42 #include <asm/m5282.h>
43 #include <asm/immap_5282.h>
47 #include <asm/m5249.h>
50 #if defined(CONFIG_M5271)
51 void cpu_init_f (void)
53 #ifndef CONFIG_WATCHDOG
54 /* Disable the watchdog if we aren't using it */
55 mbar_writeShort(MCF_WTM_WCR, 0);
58 /* Set clockspeed to 100MHz */
59 mbar_writeShort(MCF_FMPLL_SYNCR,
60 MCF_FMPLL_SYNCR_MFD(0) | MCF_FMPLL_SYNCR_RFD(0));
61 while (!mbar_readByte(MCF_FMPLL_SYNSR) & MCF_FMPLL_SYNSR_LOCK);
63 /* Enable UART pins */
64 mbar_writeShort(MCF_GPIO_PAR_UART, MCF_GPIO_PAR_UART_U0TXD |
65 MCF_GPIO_PAR_UART_U0RXD |
66 MCF_GPIO_PAR_UART_U1RXD_UART1 |
67 MCF_GPIO_PAR_UART_U1TXD_UART1);
69 /* Enable Ethernet pins */
70 mbar_writeByte(MCF_GPIO_PAR_FECI2C, CFG_FECI2C);
74 * initialize higher level parts of CPU like timers
82 #if defined(CONFIG_M5272)
84 * Breath some life into the CPU...
86 * Set up the memory map,
87 * initialize a bunch of registers,
88 * initialize the UPM's
90 void cpu_init_f (void)
92 /* if we come from RAM we assume the CPU is
93 * already initialized.
95 #ifndef CONFIG_MONITOR_IS_IN_RAM
96 volatile immap_t *regp = (immap_t *)CFG_MBAR;
98 volatile unsigned char *mbar;
99 mbar = (volatile unsigned char *) CFG_MBAR;
101 regp->sysctrl_reg.sc_scr = CFG_SCR;
102 regp->sysctrl_reg.sc_spr = CFG_SPR;
105 regp->gpio_reg.gpio_pacnt = CFG_PACNT;
106 regp->gpio_reg.gpio_paddr = CFG_PADDR;
107 regp->gpio_reg.gpio_padat = CFG_PADAT;
108 regp->gpio_reg.gpio_pbcnt = CFG_PBCNT;
109 regp->gpio_reg.gpio_pbddr = CFG_PBDDR;
110 regp->gpio_reg.gpio_pbdat = CFG_PBDAT;
111 regp->gpio_reg.gpio_pdcnt = CFG_PDCNT;
113 /* Memory Controller: */
114 regp->csctrl_reg.cs_br0 = CFG_BR0_PRELIM;
115 regp->csctrl_reg.cs_or0 = CFG_OR0_PRELIM;
117 #if (defined(CFG_OR1_PRELIM) && defined(CFG_BR1_PRELIM))
118 regp->csctrl_reg.cs_br1 = CFG_BR1_PRELIM;
119 regp->csctrl_reg.cs_or1 = CFG_OR1_PRELIM;
122 #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
123 regp->csctrl_reg.cs_br2 = CFG_BR2_PRELIM;
124 regp->csctrl_reg.cs_or2 = CFG_OR2_PRELIM;
127 #if defined(CFG_OR3_PRELIM) && defined(CFG_BR3_PRELIM)
128 regp->csctrl_reg.cs_br3 = CFG_BR3_PRELIM;
129 regp->csctrl_reg.cs_or3 = CFG_OR3_PRELIM;
132 #if defined(CFG_OR4_PRELIM) && defined(CFG_BR4_PRELIM)
133 regp->csctrl_reg.cs_br4 = CFG_BR4_PRELIM;
134 regp->csctrl_reg.cs_or4 = CFG_OR4_PRELIM;
137 #if defined(CFG_OR5_PRELIM) && defined(CFG_BR5_PRELIM)
138 regp->csctrl_reg.cs_br5 = CFG_BR5_PRELIM;
139 regp->csctrl_reg.cs_or5 = CFG_OR5_PRELIM;
142 #if defined(CFG_OR6_PRELIM) && defined(CFG_BR6_PRELIM)
143 regp->csctrl_reg.cs_br6 = CFG_BR6_PRELIM;
144 regp->csctrl_reg.cs_or6 = CFG_OR6_PRELIM;
147 #if defined(CFG_OR7_PRELIM) && defined(CFG_BR7_PRELIM)
148 regp->csctrl_reg.cs_br7 = CFG_BR7_PRELIM;
149 regp->csctrl_reg.cs_or7 = CFG_OR7_PRELIM;
152 #endif /* #ifndef CONFIG_MONITOR_IS_IN_RAM */
154 /* enable instruction cache now */
160 * initialize higher level parts of CPU like timers
162 int cpu_init_r (void)
166 #endif /* #if defined(CONFIG_M5272) */
171 * Breath some life into the CPU...
173 * Set up the memory map,
174 * initialize a bunch of registers,
175 * initialize the UPM's
177 void cpu_init_f (void)
179 #ifndef CONFIG_WATCHDOG
180 /* disable watchdog if we aren't using it */
184 #ifndef CONFIG_MONITOR_IS_IN_RAM
186 MCFCLOCK_SYNCR = MCFCLOCK_SYNCR_MFD(CFG_MFD) | MCFCLOCK_SYNCR_RFD(CFG_RFD);
188 /* Set up the GPIO ports */
190 MCFGPIO_PEPAR = CFG_PEPAR;
193 MCFGPIO_PFPAR = CFG_PFPAR;
196 MCFGPIO_PJPAR = CFG_PJPAR;
199 MCFGPIO_PSDPAR = CFG_PSDPAR;
202 MCFGPIO_PASPAR = CFG_PASPAR;
205 MCFGPIO_PEHLPAR = CFG_PEHLPAR;
208 MCFGPIO_PQSPAR = CFG_PQSPAR;
211 MCFGPIO_PTCPAR = CFG_PTCPAR;
214 MCFGPIO_PTDPAR = CFG_PTDPAR;
217 MCFGPIO_PUAPAR = CFG_PUAPAR;
221 MCFGPIO_DDRUA = CFG_DDRUA;
224 /* This is probably a bad place to setup chip selects, but everyone
227 #if defined(CFG_CS0_BASE) & defined(CFG_CS0_SIZE) & \
228 defined(CFG_CS0_WIDTH) & defined(CFG_CS0_RO) & \
231 MCFCSM_CSAR0 = (CFG_CS0_BASE >> 16) & 0xFFFF;
233 #if (CFG_CS0_WIDTH == 8)
234 #define CFG_CS0_PS MCFCSM_CSCR_PS_8
235 #elif (CFG_CS0_WIDTH == 16)
236 #define CFG_CS0_PS MCFCSM_CSCR_PS_16
237 #elif (CFG_CS0_WIDTH == 32)
238 #define CFG_CS0_PS MCFCSM_CSCR_PS_32
240 #error "CFG_CS0_WIDTH: Fault - wrong bus with for CS0"
242 MCFCSM_CSCR0 = MCFCSM_CSCR_WS(CFG_CS0_WS)
246 #if (CFG_CS0_RO != 0)
247 MCFCSM_CSMR0 = MCFCSM_CSMR_BAM(CFG_CS0_SIZE-1)
248 |MCFCSM_CSMR_WP|MCFCSM_CSMR_V;
250 MCFCSM_CSMR0 = MCFCSM_CSMR_BAM(CFG_CS0_SIZE-1)|MCFCSM_CSMR_V;
253 #waring "Chip Select 0 are not initialized/used"
256 #if defined(CFG_CS1_BASE) & defined(CFG_CS1_SIZE) & \
257 defined(CFG_CS1_WIDTH) & defined(CFG_CS1_RO) & \
260 MCFCSM_CSAR1 = (CFG_CS1_BASE >> 16) & 0xFFFF;
262 #if (CFG_CS1_WIDTH == 8)
263 #define CFG_CS1_PS MCFCSM_CSCR_PS_8
264 #elif (CFG_CS1_WIDTH == 16)
265 #define CFG_CS1_PS MCFCSM_CSCR_PS_16
266 #elif (CFG_CS1_WIDTH == 32)
267 #define CFG_CS1_PS MCFCSM_CSCR_PS_32
269 #error "CFG_CS1_WIDTH: Fault - wrong bus with for CS1"
271 MCFCSM_CSCR1 = MCFCSM_CSCR_WS(CFG_CS1_WS)
275 #if (CFG_CS1_RO != 0)
276 MCFCSM_CSMR1 = MCFCSM_CSMR_BAM(CFG_CS1_SIZE-1)
280 MCFCSM_CSMR1 = MCFCSM_CSMR_BAM(CFG_CS1_SIZE-1)
284 #warning "Chip Select 1 are not initialized/used"
287 #if defined(CFG_CS2_BASE) & defined(CFG_CS2_SIZE) & \
288 defined(CFG_CS2_WIDTH) & defined(CFG_CS2_RO) & \
291 MCFCSM_CSAR2 = (CFG_CS2_BASE >> 16) & 0xFFFF;
293 #if (CFG_CS2_WIDTH == 8)
294 #define CFG_CS2_PS MCFCSM_CSCR_PS_8
295 #elif (CFG_CS2_WIDTH == 16)
296 #define CFG_CS2_PS MCFCSM_CSCR_PS_16
297 #elif (CFG_CS2_WIDTH == 32)
298 #define CFG_CS2_PS MCFCSM_CSCR_PS_32
300 #error "CFG_CS2_WIDTH: Fault - wrong bus with for CS2"
302 MCFCSM_CSCR2 = MCFCSM_CSCR_WS(CFG_CS2_WS)
306 #if (CFG_CS2_RO != 0)
307 MCFCSM_CSMR2 = MCFCSM_CSMR_BAM(CFG_CS2_SIZE-1)
311 MCFCSM_CSMR2 = MCFCSM_CSMR_BAM(CFG_CS2_SIZE-1)
315 #warning "Chip Select 2 are not initialized/used"
318 #if defined(CFG_CS3_BASE) & defined(CFG_CS3_SIZE) & \
319 defined(CFG_CS3_WIDTH) & defined(CFG_CS3_RO) & \
322 MCFCSM_CSAR3 = (CFG_CS3_BASE >> 16) & 0xFFFF;
324 #if (CFG_CS3_WIDTH == 8)
325 #define CFG_CS3_PS MCFCSM_CSCR_PS_8
326 #elif (CFG_CS3_WIDTH == 16)
327 #define CFG_CS3_PS MCFCSM_CSCR_PS_16
328 #elif (CFG_CS3_WIDTH == 32)
329 #define CFG_CS3_PS MCFCSM_CSCR_PS_32
331 #error "CFG_CS3_WIDTH: Fault - wrong bus with for CS1"
333 MCFCSM_CSCR3 = MCFCSM_CSCR_WS(CFG_CS3_WS)
337 #if (CFG_CS3_RO != 0)
338 MCFCSM_CSMR3 = MCFCSM_CSMR_BAM(CFG_CS3_SIZE-1)
342 MCFCSM_CSMR3 = MCFCSM_CSMR_BAM(CFG_CS3_SIZE-1)
346 #warning "Chip Select 3 are not initialized/used"
349 #endif /* CONFIG_MONITOR_IS_IN_RAM */
351 /* defer enabling cache until boot (see do_go) */
352 /* icache_enable(); */
356 * initialize higher level parts of CPU like timers
358 int cpu_init_r (void)
364 #if defined(CONFIG_M5249)
366 * Breath some life into the CPU...
368 * Set up the memory map,
369 * initialize a bunch of registers,
370 * initialize the UPM's
372 void cpu_init_f (void)
374 #ifndef CFG_PLL_BYPASS
376 * Setup the PLL to run at the specified speed
379 volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
382 pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
384 pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
386 cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
387 mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
388 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
389 pllcr ^= 0x00000001; /* Set pll bypass to 1 */
390 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
391 udelay(0x20); /* Wait for a lock ... */
392 #endif /* #ifndef CFG_PLL_BYPASS */
395 * NOTE: by setting the GPIO_FUNCTION registers, we ensure that the UART pins
396 * (UART0: gpio 30,27, UART1: gpio 31, 28) will be used as UART pins
397 * which is their primary function.
400 mbar2_writeLong(MCFSIM_GPIO_FUNC, CFG_GPIO_FUNC);
401 mbar2_writeLong(MCFSIM_GPIO1_FUNC, CFG_GPIO1_FUNC);
402 mbar2_writeLong(MCFSIM_GPIO_EN, CFG_GPIO_EN);
403 mbar2_writeLong(MCFSIM_GPIO1_EN, CFG_GPIO1_EN);
404 mbar2_writeLong(MCFSIM_GPIO_OUT, CFG_GPIO_OUT);
405 mbar2_writeLong(MCFSIM_GPIO1_OUT, CFG_GPIO1_OUT);
409 * You can verify these values by using dBug's 'ird'
410 * (Internal Register Display) command
414 mbar_writeByte(MCFSIM_MPARK, 0x30); /* 5249 Internal Core takes priority over DMA */
415 mbar_writeByte(MCFSIM_SYPCR, 0x00);
416 mbar_writeByte(MCFSIM_SWIVR, 0x0f);
417 mbar_writeByte(MCFSIM_SWSR, 0x00);
418 mbar_writeLong(MCFSIM_IMR, 0xfffffbff);
419 mbar_writeByte(MCFSIM_SWDICR, 0x00);
420 mbar_writeByte(MCFSIM_TIMER1ICR, 0x00);
421 mbar_writeByte(MCFSIM_TIMER2ICR, 0x88);
422 mbar_writeByte(MCFSIM_I2CICR, 0x00);
423 mbar_writeByte(MCFSIM_UART1ICR, 0x00);
424 mbar_writeByte(MCFSIM_UART2ICR, 0x00);
425 mbar_writeByte(MCFSIM_ICR6, 0x00);
426 mbar_writeByte(MCFSIM_ICR7, 0x00);
427 mbar_writeByte(MCFSIM_ICR8, 0x00);
428 mbar_writeByte(MCFSIM_ICR9, 0x00);
429 mbar_writeByte(MCFSIM_QSPIICR, 0x00);
431 mbar2_writeLong(MCFSIM_GPIO_INT_EN, 0x00000080);
432 mbar2_writeByte(MCFSIM_INTBASE, 0x40); /* Base interrupts at 64 */
433 mbar2_writeByte(MCFSIM_SPURVEC, 0x00);
434 mbar2_writeLong(MCFSIM_IDECONFIG1, 0x00000020); /* Enable a 1 cycle pre-drive cycle on CS1 */
436 /* Setup interrupt priorities for gpio7 */
437 /* mbar2_writeLong(MCFSIM_INTLEV5, 0x70000000); */
439 /* IDE Config registers */
440 mbar2_writeLong(MCFSIM_IDECONFIG1, 0x00000020);
441 mbar2_writeLong(MCFSIM_IDECONFIG2, 0x00000000);
444 * Setup chip selects...
447 mbar_writeShort(MCFSIM_CSAR1, CFG_CSAR1);
448 mbar_writeShort(MCFSIM_CSCR1, CFG_CSCR1);
449 mbar_writeLong(MCFSIM_CSMR1, CFG_CSMR1);
451 mbar_writeShort(MCFSIM_CSAR0, CFG_CSAR0);
452 mbar_writeShort(MCFSIM_CSCR0, CFG_CSCR0);
453 mbar_writeLong(MCFSIM_CSMR0, CFG_CSMR0);
455 /* enable instruction cache now */
460 * initialize higher level parts of CPU like timers
462 int cpu_init_r (void)
466 #endif /* #if defined(CONFIG_M5249) */