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,
30 #include <asm/immap.h>
32 #if defined(CONFIG_M5271)
35 #ifndef CONFIG_WATCHDOG
36 /* Disable the watchdog if we aren't using it */
37 mbar_writeShort(MCF_WTM_WCR, 0);
40 /* Set clockspeed to 100MHz */
41 mbar_writeShort(MCF_FMPLL_SYNCR,
42 MCF_FMPLL_SYNCR_MFD(0) | MCF_FMPLL_SYNCR_RFD(0));
43 while (!mbar_readByte(MCF_FMPLL_SYNSR) & MCF_FMPLL_SYNSR_LOCK) ;
47 * initialize higher level parts of CPU like timers
54 void uart_port_conf(void)
57 switch (CFG_UART_PORT) {
59 mbar_writeShort(MCF_GPIO_PAR_UART, MCF_GPIO_PAR_UART_U0TXD |
60 MCF_GPIO_PAR_UART_U0RXD);
63 mbar_writeShort(MCF_GPIO_PAR_UART,
64 MCF_GPIO_PAR_UART_U1RXD_UART1 |
65 MCF_GPIO_PAR_UART_U1TXD_UART1);
68 mbar_writeShort(MCF_GPIO_PAR_UART, 0x3000);
74 #if defined(CONFIG_M5272)
76 * Breath some life into the CPU...
78 * Set up the memory map,
79 * initialize a bunch of registers,
80 * initialize the UPM's
84 /* if we come from RAM we assume the CPU is
85 * already initialized.
87 #ifndef CONFIG_MONITOR_IS_IN_RAM
88 volatile sysctrl_t *sysctrl = (sysctrl_t *) (CFG_MBAR);
89 volatile gpio_t *gpio = (gpio_t *) (MMAP_GPIO);
90 volatile csctrl_t *csctrl = (csctrl_t *) (MMAP_FBCS);
92 sysctrl->sc_scr = CFG_SCR;
93 sysctrl->sc_spr = CFG_SPR;
96 gpio->gpio_pacnt = CFG_PACNT;
97 gpio->gpio_paddr = CFG_PADDR;
98 gpio->gpio_padat = CFG_PADAT;
99 gpio->gpio_pbcnt = CFG_PBCNT;
100 gpio->gpio_pbddr = CFG_PBDDR;
101 gpio->gpio_pbdat = CFG_PBDAT;
102 gpio->gpio_pdcnt = CFG_PDCNT;
104 /* Memory Controller: */
105 csctrl->cs_br0 = CFG_BR0_PRELIM;
106 csctrl->cs_or0 = CFG_OR0_PRELIM;
108 #if (defined(CFG_OR1_PRELIM) && defined(CFG_BR1_PRELIM))
109 csctrl->cs_br1 = CFG_BR1_PRELIM;
110 csctrl->cs_or1 = CFG_OR1_PRELIM;
113 #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
114 csctrl->cs_br2 = CFG_BR2_PRELIM;
115 csctrl->cs_or2 = CFG_OR2_PRELIM;
118 #if defined(CFG_OR3_PRELIM) && defined(CFG_BR3_PRELIM)
119 csctrl->cs_br3 = CFG_BR3_PRELIM;
120 csctrl->cs_or3 = CFG_OR3_PRELIM;
123 #if defined(CFG_OR4_PRELIM) && defined(CFG_BR4_PRELIM)
124 csctrl->cs_br4 = CFG_BR4_PRELIM;
125 csctrl->cs_or4 = CFG_OR4_PRELIM;
128 #if defined(CFG_OR5_PRELIM) && defined(CFG_BR5_PRELIM)
129 csctrl->cs_br5 = CFG_BR5_PRELIM;
130 csctrl->cs_or5 = CFG_OR5_PRELIM;
133 #if defined(CFG_OR6_PRELIM) && defined(CFG_BR6_PRELIM)
134 csctrl->cs_br6 = CFG_BR6_PRELIM;
135 csctrl->cs_or6 = CFG_OR6_PRELIM;
138 #if defined(CFG_OR7_PRELIM) && defined(CFG_BR7_PRELIM)
139 csctrl->cs_br7 = CFG_BR7_PRELIM;
140 csctrl->cs_or7 = CFG_OR7_PRELIM;
143 #endif /* #ifndef CONFIG_MONITOR_IS_IN_RAM */
145 /* enable instruction cache now */
151 * initialize higher level parts of CPU like timers
158 void uart_port_conf(void)
160 volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
163 switch (CFG_UART_PORT) {
165 gpio->gpio_pbcnt &= ~(GPIO_PBCNT_PB0MSK | GPIO_PBCNT_PB1MSK);
166 gpio->gpio_pbcnt |= (GPIO_PBCNT_URT0_TXD | GPIO_PBCNT_URT0_RXD);
169 gpio->gpio_pdcnt &= ~(GPIO_PDCNT_PD1MSK | GPIO_PDCNT_PD4MSK);
170 gpio->gpio_pdcnt |= (GPIO_PDCNT_URT1_RXD | GPIO_PDCNT_URT1_TXD);
174 #endif /* #if defined(CONFIG_M5272) */
176 #if defined(CONFIG_M5282)
178 * Breath some life into the CPU...
180 * Set up the memory map,
181 * initialize a bunch of registers,
182 * initialize the UPM's
184 void cpu_init_f(void)
186 #ifndef CONFIG_WATCHDOG
187 /* disable watchdog if we aren't using it */
191 #ifndef CONFIG_MONITOR_IS_IN_RAM
194 MCFCLOCK_SYNCR_MFD(CFG_MFD) | MCFCLOCK_SYNCR_RFD(CFG_RFD);
195 while (!(MCFCLOCK_SYNSR & MCFCLOCK_SYNSR_LOCK)) ;
197 MCFGPIO_PBCDPAR = 0xc0;
199 /* Set up the GPIO ports */
201 MCFGPIO_PEPAR = CFG_PEPAR;
204 MCFGPIO_PFPAR = CFG_PFPAR;
207 MCFGPIO_PJPAR = CFG_PJPAR;
210 MCFGPIO_PSDPAR = CFG_PSDPAR;
213 MCFGPIO_PASPAR = CFG_PASPAR;
216 MCFGPIO_PEHLPAR = CFG_PEHLPAR;
219 MCFGPIO_PQSPAR = CFG_PQSPAR;
222 MCFGPIO_PTCPAR = CFG_PTCPAR;
225 MCFGPIO_PTDPAR = CFG_PTDPAR;
228 MCFGPIO_PUAPAR = CFG_PUAPAR;
232 MCFGPIO_DDRUA = CFG_DDRUA;
235 /* This is probably a bad place to setup chip selects, but everyone
238 #if defined(CFG_CS0_BASE) & defined(CFG_CS0_SIZE) & \
239 defined(CFG_CS0_WIDTH) & defined(CFG_CS0_RO) & \
242 MCFCSM_CSAR0 = (CFG_CS0_BASE >> 16) & 0xFFFF;
244 #if (CFG_CS0_WIDTH == 8)
245 #define CFG_CS0_PS MCFCSM_CSCR_PS_8
246 #elif (CFG_CS0_WIDTH == 16)
247 #define CFG_CS0_PS MCFCSM_CSCR_PS_16
248 #elif (CFG_CS0_WIDTH == 32)
249 #define CFG_CS0_PS MCFCSM_CSCR_PS_32
251 #error "CFG_CS0_WIDTH: Fault - wrong bus with for CS0"
253 MCFCSM_CSCR0 = MCFCSM_CSCR_WS(CFG_CS0_WS)
254 | CFG_CS0_PS | MCFCSM_CSCR_AA;
256 #if (CFG_CS0_RO != 0)
257 MCFCSM_CSMR0 = MCFCSM_CSMR_BAM(CFG_CS0_SIZE - 1)
258 | MCFCSM_CSMR_WP | MCFCSM_CSMR_V;
260 MCFCSM_CSMR0 = MCFCSM_CSMR_BAM(CFG_CS0_SIZE - 1) | MCFCSM_CSMR_V;
263 #waring "Chip Select 0 are not initialized/used"
266 #if defined(CFG_CS1_BASE) & defined(CFG_CS1_SIZE) & \
267 defined(CFG_CS1_WIDTH) & defined(CFG_CS1_RO) & \
270 MCFCSM_CSAR1 = (CFG_CS1_BASE >> 16) & 0xFFFF;
272 #if (CFG_CS1_WIDTH == 8)
273 #define CFG_CS1_PS MCFCSM_CSCR_PS_8
274 #elif (CFG_CS1_WIDTH == 16)
275 #define CFG_CS1_PS MCFCSM_CSCR_PS_16
276 #elif (CFG_CS1_WIDTH == 32)
277 #define CFG_CS1_PS MCFCSM_CSCR_PS_32
279 #error "CFG_CS1_WIDTH: Fault - wrong bus with for CS1"
281 MCFCSM_CSCR1 = MCFCSM_CSCR_WS(CFG_CS1_WS)
282 | CFG_CS1_PS | MCFCSM_CSCR_AA;
284 #if (CFG_CS1_RO != 0)
285 MCFCSM_CSMR1 = MCFCSM_CSMR_BAM(CFG_CS1_SIZE - 1)
286 | MCFCSM_CSMR_WP | MCFCSM_CSMR_V;
288 MCFCSM_CSMR1 = MCFCSM_CSMR_BAM(CFG_CS1_SIZE - 1)
292 #warning "Chip Select 1 are not initialized/used"
295 #if defined(CFG_CS2_BASE) & defined(CFG_CS2_SIZE) & \
296 defined(CFG_CS2_WIDTH) & defined(CFG_CS2_RO) & \
299 MCFCSM_CSAR2 = (CFG_CS2_BASE >> 16) & 0xFFFF;
301 #if (CFG_CS2_WIDTH == 8)
302 #define CFG_CS2_PS MCFCSM_CSCR_PS_8
303 #elif (CFG_CS2_WIDTH == 16)
304 #define CFG_CS2_PS MCFCSM_CSCR_PS_16
305 #elif (CFG_CS2_WIDTH == 32)
306 #define CFG_CS2_PS MCFCSM_CSCR_PS_32
308 #error "CFG_CS2_WIDTH: Fault - wrong bus with for CS2"
310 MCFCSM_CSCR2 = MCFCSM_CSCR_WS(CFG_CS2_WS)
311 | CFG_CS2_PS | MCFCSM_CSCR_AA;
313 #if (CFG_CS2_RO != 0)
314 MCFCSM_CSMR2 = MCFCSM_CSMR_BAM(CFG_CS2_SIZE - 1)
315 | MCFCSM_CSMR_WP | MCFCSM_CSMR_V;
317 MCFCSM_CSMR2 = MCFCSM_CSMR_BAM(CFG_CS2_SIZE - 1)
321 #warning "Chip Select 2 are not initialized/used"
324 #if defined(CFG_CS3_BASE) & defined(CFG_CS3_SIZE) & \
325 defined(CFG_CS3_WIDTH) & defined(CFG_CS3_RO) & \
328 MCFCSM_CSAR3 = (CFG_CS3_BASE >> 16) & 0xFFFF;
330 #if (CFG_CS3_WIDTH == 8)
331 #define CFG_CS3_PS MCFCSM_CSCR_PS_8
332 #elif (CFG_CS3_WIDTH == 16)
333 #define CFG_CS3_PS MCFCSM_CSCR_PS_16
334 #elif (CFG_CS3_WIDTH == 32)
335 #define CFG_CS3_PS MCFCSM_CSCR_PS_32
337 #error "CFG_CS3_WIDTH: Fault - wrong bus with for CS1"
339 MCFCSM_CSCR3 = MCFCSM_CSCR_WS(CFG_CS3_WS)
340 | CFG_CS3_PS | MCFCSM_CSCR_AA;
342 #if (CFG_CS3_RO != 0)
343 MCFCSM_CSMR3 = MCFCSM_CSMR_BAM(CFG_CS3_SIZE - 1)
344 | MCFCSM_CSMR_WP | MCFCSM_CSMR_V;
346 MCFCSM_CSMR3 = MCFCSM_CSMR_BAM(CFG_CS3_SIZE - 1)
350 #warning "Chip Select 3 are not initialized/used"
353 #endif /* CONFIG_MONITOR_IS_IN_RAM */
355 /* defer enabling cache until boot (see do_go) */
356 /* icache_enable(); */
360 * initialize higher level parts of CPU like timers
367 void uart_port_conf(void)
370 switch (CFG_UART_PORT) {
372 MCFGPIO_PUAPAR &= 0xFc;
373 MCFGPIO_PUAPAR |= 0x03;
376 MCFGPIO_PUAPAR &= 0xF3;
377 MCFGPIO_PUAPAR |= 0x0C;
380 MCFGPIO_PASPAR &= 0xFF0F;
381 MCFGPIO_PASPAR |= 0x00A0;
387 #if defined(CONFIG_M5249)
389 * Breath some life into the CPU...
391 * Set up the memory map,
392 * initialize a bunch of registers,
393 * initialize the UPM's
395 void cpu_init_f(void)
397 #ifndef CFG_PLL_BYPASS
399 * Setup the PLL to run at the specified speed
402 volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
405 pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
407 pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
409 cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
410 mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
411 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
412 pllcr ^= 0x00000001; /* Set pll bypass to 1 */
413 mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
414 udelay(0x20); /* Wait for a lock ... */
415 #endif /* #ifndef CFG_PLL_BYPASS */
418 * NOTE: by setting the GPIO_FUNCTION registers, we ensure that the UART pins
419 * (UART0: gpio 30,27, UART1: gpio 31, 28) will be used as UART pins
420 * which is their primary function.
423 mbar2_writeLong(MCFSIM_GPIO_FUNC, CFG_GPIO_FUNC);
424 mbar2_writeLong(MCFSIM_GPIO1_FUNC, CFG_GPIO1_FUNC);
425 mbar2_writeLong(MCFSIM_GPIO_EN, CFG_GPIO_EN);
426 mbar2_writeLong(MCFSIM_GPIO1_EN, CFG_GPIO1_EN);
427 mbar2_writeLong(MCFSIM_GPIO_OUT, CFG_GPIO_OUT);
428 mbar2_writeLong(MCFSIM_GPIO1_OUT, CFG_GPIO1_OUT);
432 * You can verify these values by using dBug's 'ird'
433 * (Internal Register Display) command
437 mbar_writeByte(MCFSIM_MPARK, 0x30); /* 5249 Internal Core takes priority over DMA */
438 mbar_writeByte(MCFSIM_SYPCR, 0x00);
439 mbar_writeByte(MCFSIM_SWIVR, 0x0f);
440 mbar_writeByte(MCFSIM_SWSR, 0x00);
441 mbar_writeLong(MCFSIM_IMR, 0xfffffbff);
442 mbar_writeByte(MCFSIM_SWDICR, 0x00);
443 mbar_writeByte(MCFSIM_TIMER1ICR, 0x00);
444 mbar_writeByte(MCFSIM_TIMER2ICR, 0x88);
445 mbar_writeByte(MCFSIM_I2CICR, 0x00);
446 mbar_writeByte(MCFSIM_UART1ICR, 0x00);
447 mbar_writeByte(MCFSIM_UART2ICR, 0x00);
448 mbar_writeByte(MCFSIM_ICR6, 0x00);
449 mbar_writeByte(MCFSIM_ICR7, 0x00);
450 mbar_writeByte(MCFSIM_ICR8, 0x00);
451 mbar_writeByte(MCFSIM_ICR9, 0x00);
452 mbar_writeByte(MCFSIM_QSPIICR, 0x00);
454 mbar2_writeLong(MCFSIM_GPIO_INT_EN, 0x00000080);
455 mbar2_writeByte(MCFSIM_INTBASE, 0x40); /* Base interrupts at 64 */
456 mbar2_writeByte(MCFSIM_SPURVEC, 0x00);
457 mbar2_writeLong(MCFSIM_IDECONFIG1, 0x00000020); /* Enable a 1 cycle pre-drive cycle on CS1 */
459 /* Setup interrupt priorities for gpio7 */
460 /* mbar2_writeLong(MCFSIM_INTLEV5, 0x70000000); */
462 /* IDE Config registers */
463 mbar2_writeLong(MCFSIM_IDECONFIG1, 0x00000020);
464 mbar2_writeLong(MCFSIM_IDECONFIG2, 0x00000000);
467 * Setup chip selects...
470 mbar_writeShort(MCFSIM_CSAR1, CFG_CSAR1);
471 mbar_writeShort(MCFSIM_CSCR1, CFG_CSCR1);
472 mbar_writeLong(MCFSIM_CSMR1, CFG_CSMR1);
474 mbar_writeShort(MCFSIM_CSAR0, CFG_CSAR0);
475 mbar_writeShort(MCFSIM_CSCR0, CFG_CSCR0);
476 mbar_writeLong(MCFSIM_CSMR0, CFG_CSMR0);
478 /* enable instruction cache now */
483 * initialize higher level parts of CPU like timers
490 void uart_port_conf(void)
493 switch (CFG_UART_PORT) {
500 #endif /* #if defined(CONFIG_M5249) */