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/m5272.h>
33 #include <asm/immap_5272.h>
37 #include <asm/m5282.h>
38 #include <asm/immap_5282.h>
42 #include <asm/m5249.h>
45 #if defined(CONFIG_M5272)
47 * Breath some life into the CPU...
49 * Set up the memory map,
50 * initialize a bunch of registers,
51 * initialize the UPM's
53 void cpu_init_f (void)
55 /* if we come from RAM we assume the CPU is
56 * already initialized.
58 #ifndef CONFIG_MONITOR_IS_IN_RAM
59 volatile immap_t *regp = (immap_t *)CFG_MBAR;
61 volatile unsigned char *mbar;
62 mbar = (volatile unsigned char *) CFG_MBAR;
64 regp->sysctrl_reg.sc_scr = CFG_SCR;
65 regp->sysctrl_reg.sc_spr = CFG_SPR;
68 regp->gpio_reg.gpio_pacnt = CFG_PACNT;
69 regp->gpio_reg.gpio_paddr = CFG_PADDR;
70 regp->gpio_reg.gpio_padat = CFG_PADAT;
71 regp->gpio_reg.gpio_pbcnt = CFG_PBCNT;
72 regp->gpio_reg.gpio_pbddr = CFG_PBDDR;
73 regp->gpio_reg.gpio_pbdat = CFG_PBDAT;
74 regp->gpio_reg.gpio_pdcnt = CFG_PDCNT;
76 /* Memory Controller: */
77 regp->csctrl_reg.cs_br0 = CFG_BR0_PRELIM;
78 regp->csctrl_reg.cs_or0 = CFG_OR0_PRELIM;
80 #if (defined(CFG_OR1_PRELIM) && defined(CFG_BR1_PRELIM))
81 regp->csctrl_reg.cs_br1 = CFG_BR1_PRELIM;
82 regp->csctrl_reg.cs_or1 = CFG_OR1_PRELIM;
85 #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
86 regp->csctrl_reg.cs_br2 = CFG_BR2_PRELIM;
87 regp->csctrl_reg.cs_or2 = CFG_OR2_PRELIM;
90 #if defined(CFG_OR3_PRELIM) && defined(CFG_BR3_PRELIM)
91 regp->csctrl_reg.cs_br3 = CFG_BR3_PRELIM;
92 regp->csctrl_reg.cs_or3 = CFG_OR3_PRELIM;
95 #if defined(CFG_OR4_PRELIM) && defined(CFG_BR4_PRELIM)
96 regp->csctrl_reg.cs_br4 = CFG_BR4_PRELIM;
97 regp->csctrl_reg.cs_or4 = CFG_OR4_PRELIM;
100 #if defined(CFG_OR5_PRELIM) && defined(CFG_BR5_PRELIM)
101 regp->csctrl_reg.cs_br5 = CFG_BR5_PRELIM;
102 regp->csctrl_reg.cs_or5 = CFG_OR5_PRELIM;
105 #if defined(CFG_OR6_PRELIM) && defined(CFG_BR6_PRELIM)
106 regp->csctrl_reg.cs_br6 = CFG_BR6_PRELIM;
107 regp->csctrl_reg.cs_or6 = CFG_OR6_PRELIM;
110 #if defined(CFG_OR7_PRELIM) && defined(CFG_BR7_PRELIM)
111 regp->csctrl_reg.cs_br7 = CFG_BR7_PRELIM;
112 regp->csctrl_reg.cs_or7 = CFG_OR7_PRELIM;
115 #endif /* #ifndef CONFIG_MONITOR_IS_IN_RAM */
117 /* enable instruction cache now */
123 * initialize higher level parts of CPU like timers
125 int cpu_init_r (void)
129 #endif /* #if defined(CONFIG_M5272) */
134 * Breath some life into the CPU...
136 * Set up the memory map,
137 * initialize a bunch of registers,
138 * initialize the UPM's
140 void cpu_init_f (void)
142 #ifndef CONFIG_WATCHDOG
143 /* disable watchdog if we aren't using it */
147 #ifndef CONFIG_MONITOR_IS_IN_RAM
149 MCFCLOCK_SYNCR = MCFCLOCK_SYNCR_MFD(CFG_MFD) | MCFCLOCK_SYNCR_RFD(CFG_RFD);
151 /* Set up the GPIO ports */
153 MCFGPIO_PEPAR = CFG_PEPAR;
156 MCFGPIO_PFPAR = CFG_PFPAR;
159 MCFGPIO_PJPAR = CFG_PJPAR;
162 MCFGPIO_PSDPAR = CFG_PSDPAR;
165 MCFGPIO_PASPAR = CFG_PASPAR;
168 MCFGPIO_PEHLPAR = CFG_PEHLPAR;
171 MCFGPIO_PQSPAR = CFG_PQSPAR;
174 MCFGPIO_PTCPAR = CFG_PTCPAR;
177 MCFGPIO_PTDPAR = CFG_PTDPAR;
180 MCFGPIO_PUAPAR = CFG_PUAPAR;
184 MCFGPIO_DDRUA = CFG_DDRUA;
187 /* This is probably a bad place to setup chip selects, but everyone
190 #if defined(CFG_CS0_BASE) & defined(CFG_CS0_SIZE) & \
191 defined(CFG_CS0_WIDTH) & defined(CFG_CS0_RO) & \
194 MCFCSM_CSAR0 = (CFG_CS0_BASE >> 16) & 0xFFFF;
196 #if (CFG_CS0_WIDTH == 8)
197 #define CFG_CS0_PS MCFCSM_CSCR_PS_8
198 #elif (CFG_CS0_WIDTH == 16)
199 #define CFG_CS0_PS MCFCSM_CSCR_PS_16
200 #elif (CFG_CS0_WIDTH == 32)
201 #define CFG_CS0_PS MCFCSM_CSCR_PS_32
203 #error "CFG_CS0_WIDTH: Fault - wrong bus with for CS0"
205 MCFCSM_CSCR0 = MCFCSM_CSCR_WS(CFG_CS0_WS)
209 #if (CFG_CS0_RO != 0)
210 MCFCSM_CSMR0 = MCFCSM_CSMR_BAM(CFG_CS0_SIZE-1)
211 |MCFCSM_CSMR_WP|MCFCSM_CSMR_V;
213 MCFCSM_CSMR0 = MCFCSM_CSMR_BAM(CFG_CS0_SIZE-1)|MCFCSM_CSMR_V;
216 #waring "Chip Select 0 are not initialized/used"
219 #if defined(CFG_CS1_BASE) & defined(CFG_CS1_SIZE) & \
220 defined(CFG_CS1_WIDTH) & defined(CFG_CS1_RO) & \
223 MCFCSM_CSAR1 = (CFG_CS1_BASE >> 16) & 0xFFFF;
225 #if (CFG_CS1_WIDTH == 8)
226 #define CFG_CS1_PS MCFCSM_CSCR_PS_8
227 #elif (CFG_CS1_WIDTH == 16)
228 #define CFG_CS1_PS MCFCSM_CSCR_PS_16
229 #elif (CFG_CS1_WIDTH == 32)
230 #define CFG_CS1_PS MCFCSM_CSCR_PS_32
232 #error "CFG_CS1_WIDTH: Fault - wrong bus with for CS1"
234 MCFCSM_CSCR1 = MCFCSM_CSCR_WS(CFG_CS1_WS)
238 #if (CFG_CS1_RO != 0)
239 MCFCSM_CSMR1 = MCFCSM_CSMR_BAM(CFG_CS1_SIZE-1)
243 MCFCSM_CSMR1 = MCFCSM_CSMR_BAM(CFG_CS1_SIZE-1)
247 #warning "Chip Select 1 are not initialized/used"
250 #if defined(CFG_CS2_BASE) & defined(CFG_CS2_SIZE) & \
251 defined(CFG_CS2_WIDTH) & defined(CFG_CS2_RO) & \
254 MCFCSM_CSAR2 = (CFG_CS2_BASE >> 16) & 0xFFFF;
256 #if (CFG_CS2_WIDTH == 8)
257 #define CFG_CS2_PS MCFCSM_CSCR_PS_8
258 #elif (CFG_CS2_WIDTH == 16)
259 #define CFG_CS2_PS MCFCSM_CSCR_PS_16
260 #elif (CFG_CS2_WIDTH == 32)
261 #define CFG_CS2_PS MCFCSM_CSCR_PS_32
263 #error "CFG_CS2_WIDTH: Fault - wrong bus with for CS2"
265 MCFCSM_CSCR2 = MCFCSM_CSCR_WS(CFG_CS2_WS)
269 #if (CFG_CS2_RO != 0)
270 MCFCSM_CSMR2 = MCFCSM_CSMR_BAM(CFG_CS2_SIZE-1)
274 MCFCSM_CSMR2 = MCFCSM_CSMR_BAM(CFG_CS2_SIZE-1)
278 #warning "Chip Select 2 are not initialized/used"
281 #if defined(CFG_CS3_BASE) & defined(CFG_CS3_SIZE) & \
282 defined(CFG_CS3_WIDTH) & defined(CFG_CS3_RO) & \
285 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
294 #error "CFG_CS3_WIDTH: Fault - wrong bus with for CS1"
296 MCFCSM_CSCR3 = MCFCSM_CSCR_WS(CFG_CS3_WS)
300 #if (CFG_CS3_RO != 0)
301 MCFCSM_CSMR3 = MCFCSM_CSMR_BAM(CFG_CS3_SIZE-1)
305 MCFCSM_CSMR3 = MCFCSM_CSMR_BAM(CFG_CS3_SIZE-1)
309 #warning "Chip Select 3 are not initialized/used"
312 #endif /* CONFIG_MONITOR_IS_IN_RAM */
314 /* defer enabling cache until boot (see do_go) */
315 /* icache_enable(); */
319 * initialize higher level parts of CPU like timers
321 int cpu_init_r (void)
327 #if defined(CONFIG_M5249)
329 * Breath some life into the CPU...
331 * Set up the memory map,
332 * initialize a bunch of registers,
333 * initialize the UPM's
335 void cpu_init_f (void)
337 #ifndef CFG_PLL_BYPASS
339 * Setup the PLL to run at the specified speed
342 volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
345 pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
347 pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
349 cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
350 mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
351 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
352 pllcr ^= 0x00000001; /* Set pll bypass to 1 */
353 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
354 udelay(0x20); /* Wait for a lock ... */
355 #endif /* #ifndef CFG_PLL_BYPASS */
358 * NOTE: by setting the GPIO_FUNCTION registers, we ensure that the UART pins
359 * (UART0: gpio 30,27, UART1: gpio 31, 28) will be used as UART pins
360 * which is their primary function.
363 mbar2_writeLong(MCFSIM_GPIO_FUNC, CFG_GPIO_FUNC);
364 mbar2_writeLong(MCFSIM_GPIO1_FUNC, CFG_GPIO1_FUNC);
365 mbar2_writeLong(MCFSIM_GPIO_EN, CFG_GPIO_EN);
366 mbar2_writeLong(MCFSIM_GPIO1_EN, CFG_GPIO1_EN);
367 mbar2_writeLong(MCFSIM_GPIO_OUT, CFG_GPIO_OUT);
368 mbar2_writeLong(MCFSIM_GPIO1_OUT, CFG_GPIO1_OUT);
372 * You can verify these values by using dBug's 'ird'
373 * (Internal Register Display) command
377 mbar_writeByte(MCFSIM_MPARK, 0x30); /* 5249 Internal Core takes priority over DMA */
378 mbar_writeByte(MCFSIM_SYPCR, 0x00);
379 mbar_writeByte(MCFSIM_SWIVR, 0x0f);
380 mbar_writeByte(MCFSIM_SWSR, 0x00);
381 mbar_writeLong(MCFSIM_IMR, 0xfffffbff);
382 mbar_writeByte(MCFSIM_SWDICR, 0x00);
383 mbar_writeByte(MCFSIM_TIMER1ICR, 0x00);
384 mbar_writeByte(MCFSIM_TIMER2ICR, 0x88);
385 mbar_writeByte(MCFSIM_I2CICR, 0x00);
386 mbar_writeByte(MCFSIM_UART1ICR, 0x00);
387 mbar_writeByte(MCFSIM_UART2ICR, 0x00);
388 mbar_writeByte(MCFSIM_ICR6, 0x00);
389 mbar_writeByte(MCFSIM_ICR7, 0x00);
390 mbar_writeByte(MCFSIM_ICR8, 0x00);
391 mbar_writeByte(MCFSIM_ICR9, 0x00);
392 mbar_writeByte(MCFSIM_QSPIICR, 0x00);
394 mbar2_writeLong(MCFSIM_GPIO_INT_EN, 0x00000080);
395 mbar2_writeByte(MCFSIM_INTBASE, 0x40); /* Base interrupts at 64 */
396 mbar2_writeByte(MCFSIM_SPURVEC, 0x00);
397 mbar2_writeLong(MCFSIM_IDECONFIG1, 0x00000020); /* Enable a 1 cycle pre-drive cycle on CS1 */
399 /* Setup interrupt priorities for gpio7 */
400 /* mbar2_writeLong(MCFSIM_INTLEV5, 0x70000000); */
402 /* IDE Config registers */
403 mbar2_writeLong(MCFSIM_IDECONFIG1, 0x00000020);
404 mbar2_writeLong(MCFSIM_IDECONFIG2, 0x00000000);
407 * Setup chip selects...
410 mbar_writeShort(MCFSIM_CSAR1, CFG_CSAR1);
411 mbar_writeShort(MCFSIM_CSCR1, CFG_CSCR1);
412 mbar_writeLong(MCFSIM_CSMR1, CFG_CSMR1);
414 mbar_writeShort(MCFSIM_CSAR0, CFG_CSAR0);
415 mbar_writeShort(MCFSIM_CSCR0, CFG_CSCR0);
416 mbar_writeLong(MCFSIM_CSMR0, CFG_CSMR0);
418 /* enable instruction cache now */
423 * initialize higher level parts of CPU like timers
425 int cpu_init_r (void)
429 #endif /* #if defined(CONFIG_M5249) */