This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / ppc / platforms / ev64260.c
1 /*
2  * arch/ppc/platforms/ev64260.c
3  *
4  * Board setup routines for the Marvell/Galileo EV-64260-BP Evaluation Board.
5  *
6  * Author: Mark A. Greer <mgreer@mvista.com>
7  *
8  * 2001-2003 (c) MontaVista, Software, Inc.  This file is licensed under
9  * the terms of the GNU General Public License version 2.  This program
10  * is licensed "as is" without any warranty of any kind, whether express
11  * or implied.
12  */
13
14 /*
15  * The EV-64260-BP port is the result of hard work from many people from
16  * many companies.  In particular, employees of Marvell/Galileo, Mission
17  * Critical Linux, Xyterra, and MontaVista Software were heavily involved.
18  *
19  * Note: I have not been able to get *all* PCI slots to work reliably
20  *      at 66 MHz.  I recommend setting jumpers J15 & J16 to short pins 1&2
21  *      so that 33 MHz is used. --MAG
22  * Note: The 750CXe and 7450 are not stable with a 125MHz or 133MHz TCLK/SYSCLK.
23  *      At 100MHz, they are solid.
24  */
25 #include <linux/config.h>
26
27 #include <linux/delay.h>
28 #include <linux/pci.h>
29 #include <linux/ide.h>
30 #include <linux/irq.h>
31 #include <linux/fs.h>
32 #include <linux/seq_file.h>
33 #include <linux/console.h>
34 #include <linux/initrd.h>
35 #include <linux/root_dev.h>
36 #if !defined(CONFIG_SERIAL_MPSC_CONSOLE)
37 #include <linux/serial.h>
38 #include <linux/tty.h>
39 #include <linux/serial_core.h>
40 #endif
41 #include <asm/bootinfo.h>
42 #include <asm/machdep.h>
43 #include <asm/mv64x60.h>
44 #include <asm/ppcboot.h>
45 #include <asm/todc.h>
46 #include <asm/time.h>
47 #include <asm/ocp.h>
48
49 #include <platforms/ev64260.h>
50
51 #define BOARD_VENDOR    "Marvell/Galileo"
52 #define BOARD_MACHINE   "EV-64260-BP"
53
54 /* Set IDE controllers into Native mode? */
55 /* XXXX
56 #define SET_PCI_IDE_NATIVE
57 */
58
59 ulong   ev64260_mem_size = 0;
60 bd_t    ppcboot_bd;
61 int     ppcboot_bd_valid=0;
62
63 static mv64x60_handle_t bh;
64
65 #if !defined(CONFIG_SERIAL_MPSC_CONSOLE)
66 extern void gen550_progress(char *, unsigned short);
67 extern void gen550_init(int, struct serial_struct *);
68 #endif
69
70 static const unsigned int cpu_7xx[16] = { /* 7xx & 74xx (but not 745x) */
71         18, 15, 14, 2, 4, 13, 5, 9, 6, 11, 8, 10, 16, 12, 7, 0
72 };
73 static const unsigned int cpu_745x[2][16] = { /* PLL_EXT 0 & 1 */
74         { 1, 15, 14,  2,  4, 13,  5,  9,  6, 11,  8, 10, 16, 12,  7,  0 },
75         { 0, 30,  0,  2,  0, 26,  0, 18,  0, 22, 20, 24, 28, 32,  0,  0 }
76 };
77
78
79 TODC_ALLOC();
80
81 static int
82 ev64260_get_bus_speed(void)
83 {
84         int     speed;
85
86         if (ppcboot_bd_valid) {
87                 speed = ppcboot_bd.bi_busfreq;
88         }
89         else {
90                 speed = 100000000; /* Only 100MHz is stable */
91         }
92
93         return speed;
94 }
95
96 static int
97 ev64260_get_cpu_speed(void)
98 {
99         unsigned long   pvr, hid1, pll_ext;
100
101         pvr = PVR_VER(mfspr(PVR));
102
103         if (pvr != PVR_VER(PVR_7450)) {
104                 hid1 = mfspr(HID1) >> 28;
105                 return ev64260_get_bus_speed() * cpu_7xx[hid1]/2;
106         }
107         else {
108                 hid1 = (mfspr(HID1) & 0x0001e000) >> 13;
109                 pll_ext = 0; /* No way to read; must get from schematic */
110                 return ev64260_get_bus_speed() * cpu_745x[pll_ext][hid1]/2;
111         }
112 }
113
114 unsigned long __init
115 ev64260_find_end_of_memory(void)
116 {
117         if(!ppcboot_bd_valid) {
118                 return mv64x60_get_mem_size(CONFIG_MV64X60_NEW_BASE,
119                         MV64x60_TYPE_GT64260A);
120         }
121         return ppcboot_bd.bi_memsize;
122 }
123
124 #if 0   /* XXXX */
125 #ifdef SET_PCI_IDE_NATIVE
126 static void __init
127 set_pci_native_mode(void)
128 {
129         struct pci_dev *dev;
130
131         /* Better way of doing this ??? */
132         pci_for_each_dev(dev) { 
133                 int class = dev->class >> 8;
134
135                 /* enable pci native mode */
136                 if (class == PCI_CLASS_STORAGE_IDE) {
137                         u8 reg;
138
139                         pci_read_config_byte(dev, 0x9, &reg);
140                         if (reg == 0x8a) {
141                                 printk("PCI: Enabling PCI IDE native mode on %s\n", dev->slot_name); 
142                                 pci_write_config_byte(dev, 0x9,  0x8f);
143
144                                 /* let the pci code set this device up after we change it */
145                                 pci_setup_device(dev); 
146                         } else if (reg != 0x8f) {
147                                 printk("PCI: IDE chip in unknown mode 0x%02x on %s", reg, dev->slot_name);
148                         }
149                 }
150         }
151 }
152 #endif
153 #endif
154
155 static void __init
156 ev64260_pci_fixups(void)
157 {
158 #ifdef SET_PCI_IDE_NATIVE
159         set_pci_native_mode();
160 #endif
161 }
162
163
164 /*
165  * Marvell/Galileo EV-64260-BP Evaluation Board PCI interrupt routing.
166  * Note: By playing with J8 and JP1-4, you can get 2 IRQ's from the first
167  *      PCI bus (in which cast, INTPIN B would be EV64260_PCI_1_IRQ).
168  *      This is the most IRQs you can get from one bus with this board, though.
169  */
170 static int __init
171 ev64260_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
172 {
173         struct pci_controller   *hose = pci_bus_to_hose(dev->bus->number);
174
175         if (hose->index == 0) {
176                 static char pci_irq_table[][4] =
177                 /*
178                  *      PCI IDSEL/INTPIN->INTLINE 
179                  *         A   B   C   D
180                  */
181                 {
182                         {EV64260_PCI_0_IRQ,0,0,0}, /* IDSEL 7 - PCI bus 0 */
183                         {EV64260_PCI_0_IRQ,0,0,0}, /* IDSEL 8 - PCI bus 0 */
184                 };
185
186                 const long min_idsel = 7, max_idsel = 8, irqs_per_slot = 4;
187                 return PCI_IRQ_TABLE_LOOKUP;
188         }
189         else {
190                 static char pci_irq_table[][4] =
191                 /*
192                  *      PCI IDSEL/INTPIN->INTLINE 
193                  *         A   B   C   D
194                  */
195                 {
196                         { EV64260_PCI_1_IRQ,0,0,0}, /* IDSEL 7 - PCI bus 1 */
197                         { EV64260_PCI_1_IRQ,0,0,0}, /* IDSEL 8 - PCI bus 1 */
198                 };
199
200                 const long min_idsel = 7, max_idsel = 8, irqs_per_slot = 4;
201                 return PCI_IRQ_TABLE_LOOKUP;
202         }
203 }
204
205 static void __init
206 ev64260_setup_peripherals(void)
207 {
208         mv64x60_set_32bit_window(&bh, MV64x60_CPU2BOOT_WIN,
209                 EV64260_EMB_FLASH_BASE, EV64260_EMB_FLASH_SIZE, 0);
210         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_0_WIN,
211                 EV64260_EXT_SRAM_BASE, EV64260_EXT_SRAM_SIZE, 0);
212         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_1_WIN,
213                 EV64260_TODC_BASE, EV64260_TODC_SIZE, 0);
214         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_2_WIN,
215                 EV64260_UART_BASE, EV64260_UART_SIZE, 0);
216         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_3_WIN,
217                 EV64260_EXT_FLASH_BASE, EV64260_EXT_FLASH_SIZE, 0);
218
219         TODC_INIT(TODC_TYPE_DS1501, 0, 0,
220                         ioremap(EV64260_TODC_BASE, EV64260_TODC_SIZE), 8);
221
222         mv64x60_clr_bits(&bh, MV64x60_CPU_CONFIG, ((1<<28) | (1<<29)));
223         mv64x60_set_bits(&bh, MV64x60_CPU_CONFIG, (1<<27));
224
225         if (ev64260_get_bus_speed() > 100000000) {
226                 mv64x60_set_bits(&bh, MV64x60_CPU_CONFIG, (1<<23));
227         }
228
229         mv64x60_set_bits(&bh, MV64x60_PCI0_PCI_DECODE_CNTL,((1<<0) | (1<<3)));
230         mv64x60_set_bits(&bh, MV64x60_PCI1_PCI_DECODE_CNTL,((1<<0) | (1<<3)));
231
232         /*
233          * Enabling of PCI internal-vs-external arbitration
234          * is a platform- and errata-dependent decision.
235          */
236         if (bh.type == MV64x60_TYPE_GT64260A )  {
237                 mv64x60_set_bits(&bh, MV64x60_PCI0_ARBITER_CNTL, (1<<31));
238                 mv64x60_set_bits(&bh, MV64x60_PCI1_ARBITER_CNTL, (1<<31));
239         }
240
241         mv64x60_set_bits(&bh, MV64x60_CPU_MASTER_CNTL, (1<<9)); /* Only 1 cpu */
242
243         /*
244          * The EV-64260-BP uses several Multi-Purpose Pins (MPP) on the 64260
245          * bridge as interrupt inputs (via the General Purpose Ports (GPP)
246          * register).  Need to route the MPP inputs to the GPP and set the
247          * polarity correctly.
248          *
249          * In MPP Control 2 Register
250          *   MPP 21 -> GPP 21 (DUART channel A intr) bits 20-23 -> 0
251          *   MPP 22 -> GPP 22 (DUART channel B intr) bits 24-27 -> 0
252          */
253         mv64x60_clr_bits(&bh, MV64x60_MPP_CNTL_2, (0xf<<20) | (0xf<<24) );
254
255         /*
256          * In MPP Control 3 Register
257          *   MPP 26 -> GPP 26 (RTC INT)         bits  8-11 -> 0
258          *   MPP 27 -> GPP 27 (PCI 0 INTA)      bits 12-15 -> 0
259          *   MPP 29 -> GPP 29 (PCI 1 INTA)      bits 20-23 -> 0
260          */
261         mv64x60_clr_bits(&bh, MV64x60_MPP_CNTL_3,
262                 (0xf<<8) | (0xf<<12) | (0xf<<20));
263
264 #define GPP_EXTERNAL_INTERRUPTS \
265                 ((1<<21) | (1<<22) | (1<<26) | (1<<27) | (1<<29))
266         /* DUART & PCI interrupts are inputs */
267         mv64x60_clr_bits(&bh, MV64x60_GPP_IO_CNTL, GPP_EXTERNAL_INTERRUPTS);
268         /* DUART & PCI interrupts are active low */
269         mv64x60_set_bits(&bh, MV64x60_GPP_LEVEL_CNTL, GPP_EXTERNAL_INTERRUPTS);
270
271         /* Clear any pending interrupts for these inputs and enable them. */
272         mv64x60_write(&bh, MV64x60_GPP_INTR_CAUSE, ~GPP_EXTERNAL_INTERRUPTS);
273         mv64x60_set_bits(&bh, MV64x60_GPP_INTR_MASK, GPP_EXTERNAL_INTERRUPTS);
274
275         /*
276          * Set MPSC Multiplex RMII
277          * NOTE: ethernet driver modifies bit 0 and 1
278          */
279         mv64x60_write(&bh, GT64260_MPP_SERIAL_PORTS_MULTIPLEX, 0x00001102);
280         return;
281 }
282
283
284 static void __init
285 ev64260_setup_bridge(void)
286 {
287         mv64x60_setup_info_t    si;
288         int                     i;
289
290         memset(&si, 0, sizeof(si));
291
292         si.phys_reg_base = CONFIG_MV64X60_NEW_BASE;
293         si.map_irq = ev64260_map_irq;
294
295         si.pci_0.enable_bus = 1;
296         si.pci_0.enumerate_bus = 1;
297         si.pci_0.pci_io.cpu_base = 0xa0000000;
298         si.pci_0.pci_io.pci_base_hi = 0;
299         si.pci_0.pci_io.pci_base_lo = 0;
300         si.pci_0.pci_io.size = 0x01000000;
301         si.pci_0.pci_io.swap = 0x01000000; /* XXXX No swapping */
302         si.pci_0.pci_mem[0].cpu_base = 0x80000000;
303         si.pci_0.pci_mem[0].pci_base_hi = 0;
304         si.pci_0.pci_mem[0].pci_base_lo = 0x80000000;
305         si.pci_0.pci_mem[0].size = 0x10000000;
306         si.pci_0.pci_mem[0].swap = 0x01000000; /* XXXX No swapping */
307         si.pci_0.pci_mem[1].cpu_base = 0;
308         si.pci_0.pci_mem[1].pci_base_hi = 0;
309         si.pci_0.pci_mem[1].pci_base_lo = 0;
310         si.pci_0.pci_mem[1].size = 0;   /* Don't use this window */
311         si.pci_0.pci_mem[1].swap = 0;
312         si.pci_0.pci_mem[2].cpu_base = 0;
313         si.pci_0.pci_mem[2].pci_base_hi = 0;
314         si.pci_0.pci_mem[2].pci_base_lo = 0;
315         si.pci_0.pci_mem[2].size = 0;   /* Don't use this window */
316         si.pci_0.pci_mem[1].swap = 0;
317         si.pci_0.pci_cmd_bits = 0;
318         si.pci_0.latency_timer = 0x8;
319
320         si.pci_1.enable_bus = 1;
321         si.pci_1.enumerate_bus = 1;
322         si.pci_1.pci_io.cpu_base = 0xa1000000;
323         si.pci_1.pci_io.pci_base_hi = 0;
324         si.pci_1.pci_io.pci_base_lo = 0x01000000;
325         si.pci_1.pci_io.size = 0x01000000;
326         si.pci_1.pci_io.swap = 0x01000000; /* XXXX No swapping */
327         si.pci_1.pci_mem[0].cpu_base = 0x90000000;
328         si.pci_1.pci_mem[0].pci_base_hi = 0;
329         si.pci_1.pci_mem[0].pci_base_lo = 0x90000000;
330         si.pci_1.pci_mem[0].size = 0x10000000;
331         si.pci_1.pci_mem[0].swap = 0x01000000; /* XXXX No swapping */
332         si.pci_1.pci_mem[1].cpu_base = 0;
333         si.pci_1.pci_mem[1].pci_base_hi = 0;
334         si.pci_1.pci_mem[1].pci_base_lo = 0;
335         si.pci_1.pci_mem[1].size = 0;   /* Don't use this window */
336         si.pci_1.pci_mem[1].swap = 0;
337         si.pci_1.pci_mem[2].cpu_base = 0;
338         si.pci_1.pci_mem[2].pci_base_hi = 0;
339         si.pci_1.pci_mem[2].pci_base_lo = 0;
340         si.pci_1.pci_mem[2].size = 0;   /* Don't use this window */
341         si.pci_1.pci_mem[1].swap = 0;
342         si.pci_1.pci_cmd_bits = 0;
343         si.pci_1.latency_timer = 0x8;
344         si.pci_1.pci_cmd_bits = 0;
345         si.pci_1.latency_timer = 0x8;
346
347         for (i=0; i<MV64x60_CPU2MEM_WINDOWS; i++) {
348                 si.cpu_prot_options[i] = 0;
349                 si.cpu_snoop_options[i] = GT64260_CPU_SNOOP_WB;
350                 si.pci_0.acc_cntl_options[i] =
351                         /* Breaks PCI (especially slot 4)
352                         GT64260_PCI_ACC_CNTL_PREFETCHEN |
353                         */
354                         GT64260_PCI_ACC_CNTL_DREADEN |
355                         GT64260_PCI_ACC_CNTL_RDPREFETCH |
356                         GT64260_PCI_ACC_CNTL_RDLINEPREFETCH |
357                         GT64260_PCI_ACC_CNTL_RDMULPREFETCH |
358                         GT64260_PCI_ACC_CNTL_SWAP_NONE |
359                         GT64260_PCI_ACC_CNTL_MBURST_32_BTYES;
360                 si.pci_0.snoop_options[i] = GT64260_PCI_SNOOP_WB;
361                 si.pci_1.acc_cntl_options[i] =
362                         /* Breaks PCI (especially slot 4)
363                         GT64260_PCI_ACC_CNTL_PREFETCHEN |
364                         */
365                         GT64260_PCI_ACC_CNTL_DREADEN |
366                         GT64260_PCI_ACC_CNTL_RDPREFETCH |
367                         GT64260_PCI_ACC_CNTL_RDLINEPREFETCH |
368                         GT64260_PCI_ACC_CNTL_RDMULPREFETCH |
369                         GT64260_PCI_ACC_CNTL_SWAP_NONE |
370                         GT64260_PCI_ACC_CNTL_MBURST_32_BTYES;
371                 si.pci_1.snoop_options[i] = GT64260_PCI_SNOOP_WB;
372         }
373
374         /* Lookup PCI host bridges */
375         if (mv64x60_init(&bh, &si)) {
376                 printk("Bridge initialization failed.\n");
377         }
378
379         return;
380 }
381
382 #if defined(CONFIG_SERIAL_8250) && !defined(CONFIG_SERIAL_MPSC_CONSOLE)
383 static void __init
384 ev64260_early_serial_map(void)
385 {
386         struct uart_port        port;
387         static char             first_time = 1;
388
389         if (first_time) {
390                 memset(&port, 0, sizeof(port));
391
392                 port.membase = ioremap(EV64260_SERIAL_0, EV64260_UART_SIZE);
393                 port.irq = EV64260_UART_0_IRQ;
394                 port.uartclk = BASE_BAUD * 16;
395                 port.regshift = 2;
396                 port.iotype = SERIAL_IO_MEM;
397                 port.flags = STD_COM_FLAGS;
398
399 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
400                 gen550_init(0, &port);
401 #endif
402
403                 if (early_serial_setup(&port) != 0) {
404                         printk("Early serial init of port 0 failed\n");
405                 }
406
407 #if 0   /* XXXX */
408                 /* Assume early_serial_setup() doesn't modify port */
409                 port.membase = ioremap(EV64260_SERIAL_1, EV64260_UART_SIZE);
410                 port.irq = EV64260_UART_1_IRQ;
411
412 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
413                 gen550_init(1, &port);
414 #endif
415
416                 if (early_serial_setup(&port) != 0) {
417                         printk("Early serial init of port 1 failed\n");
418                 }
419 #endif
420
421                 first_time = 0;
422         }
423
424         return;
425 }
426 #elif defined(CONFIG_SERIAL_MPSC_CONSOLE)
427 static void __init
428 ev64260_early_serial_map(void)
429 {
430 #ifdef  CONFIG_KGDB
431         static char     first_time = 1;
432
433
434 #if defined(CONFIG_KGDB_TTYS0)
435 #define KGDB_PORT 0
436 #elif defined(CONFIG_KGDB_TTYS1)
437 #define KGDB_PORT 1
438 #else
439 #error "Invalid kgdb_tty port"
440 #endif
441
442         if (first_time) {
443                 gt_early_mpsc_init(KGDB_PORT, B9600|CS8|CREAD|HUPCL|CLOCAL);
444                 first_time = 0;
445         }
446
447         return;
448 #endif
449 }
450 #endif
451
452 static void __init
453 ev64260_fixup_ocp(void)
454 {
455 #if defined(CONFIG_SERIAL_MPSC)
456         struct ocp_device       *dev;
457         mv64x60_ocp_mpsc_data_t *dp;
458
459         if ((dev = ocp_find_device(OCP_VENDOR_MARVELL, OCP_FUNC_MPSC, 0))
460                                                                 != NULL) {
461                 dp = (mv64x60_ocp_mpsc_data_t *)dev->def->additions;
462
463                 dp->max_idle = 40;      /* XXXX what should this be? */
464                 dp->default_baud = EV64260_DEFAULT_BAUD;
465                 dp->brg_clk_src = EV64260_MPSC_CLK_SRC;
466                 dp->brg_clk_freq = EV64260_MPSC_CLK_FREQ;
467         }
468
469         if ((dev = ocp_find_device(OCP_VENDOR_MARVELL, OCP_FUNC_MPSC, 1))
470                                                                 != NULL) {
471                 dp = (mv64x60_ocp_mpsc_data_t *)dev->def->additions;
472
473                 dp->max_idle = 40;      /* XXXX what should this be? */
474                 dp->default_baud = 9600;        /* XXXX */
475                 dp->brg_clk_src = EV64260_MPSC_CLK_SRC;
476                 dp->brg_clk_freq = EV64260_MPSC_CLK_FREQ;
477         }
478 #endif
479
480         return;
481 }
482
483 static void __init
484 ev64260_setup_arch(void)
485 {
486         if ( ppc_md.progress )
487                 ppc_md.progress("ev64260_setup_arch: enter", 0);
488
489 #ifdef CONFIG_BLK_DEV_INITRD
490         if (initrd_start)
491                 ROOT_DEV = Root_RAM0;
492         else
493 #endif
494 #ifdef  CONFIG_ROOT_NFS
495                 ROOT_DEV = Root_NFS;
496 #else
497                 ROOT_DEV = Root_SDA2;
498 #endif
499
500         if ( ppc_md.progress )
501                 ppc_md.progress("ev64260_setup_arch: Enabling L2 cache", 0);
502
503         /* Enable L2 and L3 caches (if 745x) */
504         _set_L2CR(_get_L2CR() | L2CR_L2E);
505         _set_L3CR(_get_L3CR() | L3CR_L3E);
506
507         if ( ppc_md.progress )
508                 ppc_md.progress("ev64260_setup_arch: Initializing bridge", 0);
509
510         ev64260_setup_bridge();         /* set up PCI bridge(s) */
511         ev64260_setup_peripherals();    /* set up chip selects/GPP/MPP etc */
512
513         if ( ppc_md.progress )
514                 ppc_md.progress("ev64260_setup_arch: bridge init complete", 0);
515
516         /* Set OCP values to reflect this board's setup */
517         ev64260_fixup_ocp();
518
519 #ifdef  CONFIG_DUMMY_CONSOLE
520         conswitchp = &dummy_con;
521 #endif
522 #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_MPSC_CONSOLE)
523         ev64260_early_serial_map();
524 #endif
525
526         printk(BOARD_VENDOR " " BOARD_MACHINE "\n");
527         printk("EV-64260-BP port (C) 2001 MontaVista Software, Inc. (source@mvista.com)\n");
528
529         if ( ppc_md.progress )
530                 ppc_md.progress("ev64260_setup_arch: exit", 0);
531
532         return;
533 }
534
535 static void
536 ev64260_reset_board(void *addr)
537 {
538         local_irq_disable();
539
540         /* disable and invalidate the L2 cache */
541         _set_L2CR(0);
542         _set_L2CR(0x200000);
543
544         /* flush and disable L1 I/D cache */
545         __asm__ __volatile__
546         ("mfspr   3,1008\n\t"
547          "ori   5,5,0xcc00\n\t"
548          "ori   4,3,0xc00\n\t"
549          "andc  5,3,5\n\t"
550          "sync\n\t"
551          "mtspr 1008,4\n\t"
552          "isync\n\t"
553          "sync\n\t"
554          "mtspr 1008,5\n\t"
555          "isync\n\t"
556          "sync\n\t");
557
558         /* unmap any other random cs's that might overlap with bootcs */
559         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_0_WIN, 0, 0, 0);
560         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_1_WIN, 0, 0, 0);
561         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_2_WIN, 0, 0, 0);
562         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_3_WIN, 0, 0, 0);
563
564         /* map bootrom back in to gt @ reset defaults */
565         mv64x60_set_32bit_window(&bh, MV64x60_CPU2BOOT_WIN,
566                                                 0xff800000, 8*1024*1024, 0);
567
568         /* move gt reg base back to default, setup default pci0 swapping
569          * config... */
570         mv64x60_write(&bh, MV64x60_INTERNAL_SPACE_DECODE,
571                 (1<<24) | MV64x60_INTERNAL_SPACE_DEFAULT_ADDR>>20);
572
573         /* NOTE: FROM NOW ON no more GT_REGS accesses.. 0x1 is not mapped
574          * via BAT or MMU, and MSR IR/DR is ON */
575 #if 0
576         /* BROKEN... IR/DR is still on !!  won't work!! */
577         /* Set exception prefix high - to the firmware */
578         _nmask_and_or_msr(0, MSR_IP);
579
580         out_8((u_char *)EV64260_BOARD_MODRST_REG, 0x01);
581 #else
582         /* SRR0 has system reset vector, SRR1 has default MSR value */
583         /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
584         /* NOTE: assumes reset vector is at 0xfff00100 */
585         __asm__ __volatile__
586         ("mtspr   26, %0\n\t"
587          "li      4,(1<<6)\n\t"
588          "mtspr   27,4\n\t"
589          "rfi\n\t"
590          :: "r" (addr):"r4");
591 #endif
592         return;
593 }
594
595 static void
596 ev64260_restart(char *cmd)
597 {
598         volatile ulong  i = 10000000;
599
600         ev64260_reset_board((void *)0xfff00100);
601
602         while (i-- > 0);
603         panic("restart failed\n");
604 }
605
606 static void
607 ev64260_halt(void)
608 {
609         local_irq_disable();
610         while (1);
611         /* NOTREACHED */
612 }
613
614 static void
615 ev64260_power_off(void)
616 {
617         ev64260_halt();
618         /* NOTREACHED */
619 }
620
621 static int
622 ev64260_show_cpuinfo(struct seq_file *m)
623 {
624         uint pvid;
625
626         pvid = mfspr(PVR);
627         seq_printf(m, "vendor\t\t: " BOARD_VENDOR "\n");
628         seq_printf(m, "machine\t\t: " BOARD_MACHINE "\n");
629         seq_printf(m, "cpu MHz\t\t: %d\n", ev64260_get_cpu_speed()/1000/1000);
630         seq_printf(m, "bus MHz\t\t: %d\n", ev64260_get_bus_speed()/1000/1000);
631
632         return 0;
633 }
634
635 /* DS1501 RTC has too much variation to use RTC for calibration */
636 static void __init
637 ev64260_calibrate_decr(void)
638 {
639         ulong freq;
640
641         freq = ev64260_get_bus_speed()/4;
642
643         printk("time_init: decrementer frequency = %lu.%.6lu MHz\n",
644                freq/1000000, freq%1000000);
645
646         tb_ticks_per_jiffy = freq / HZ;
647         tb_to_us = mulhwu_scale_factor(freq, 1000000);
648
649         return;
650 }
651
652 #if 0   /* XXXX */
653 #ifdef CONFIG_USE_PPCBOOT
654 static void parse_ppcbootinfo(unsigned long r3,
655         unsigned long r4, unsigned long r5,
656         unsigned long r6, unsigned long r7)
657 {
658     bd_t *bd=NULL;
659     char *cmdline_start=NULL;
660     int cmdline_len=0;
661
662     if(r3) {
663         if((r3 & 0xf0000000) == 0) r3 += KERNELBASE;
664         if((r3 & 0xf0000000) == KERNELBASE) {
665             bd=(void *)r3;
666
667             /* hack for ppcboot loaders that report freqs in Mhz */
668             if(bd->bi_intfreq<1000000) bd->bi_intfreq*=1000000;
669             if(bd->bi_busfreq<1000000) bd->bi_busfreq*=1000000;
670
671             memcpy(&ppcboot_bd,bd,sizeof(ppcboot_bd));
672             ppcboot_bd_valid=1;
673         }
674     }
675
676 #ifdef CONFIG_BLK_DEV_INITRD
677     if(r4 && r5 && r5>r4) {
678         if((r4 & 0xf0000000) == 0) r4 += KERNELBASE;
679         if((r5 & 0xf0000000) == 0) r5 += KERNELBASE;
680         if((r4 & 0xf0000000) == KERNELBASE) {
681             initrd_start=r4;
682             initrd_end=r5;
683             initrd_below_start_ok = 1;
684         }
685     }
686 #endif /* CONFIG_BLK_DEV_INITRD */
687
688     if(r6 && r7 && r7>r6) {
689         if((r6 & 0xf0000000) == 0) r6 += KERNELBASE;
690         if((r7 & 0xf0000000) == 0) r7 += KERNELBASE;
691         if((r6 & 0xf0000000) == KERNELBASE) {
692             cmdline_start=(void *)r6;
693             cmdline_len=(r7-r6);
694             strncpy(cmd_line,cmdline_start,cmdline_len);
695         }
696     }
697
698     if(ppcboot_bd_valid) {                      
699         printk("found bd_t @%p\n", bd);
700         printk("memstart=%08lx\n", bd->bi_memstart);
701         printk("memsize=%08lx\n", bd->bi_memsize);
702         printk("enetaddr=%02x%02x%02x%02x%02x%02x\n",
703                 bd->bi_enetaddr[0],
704                 bd->bi_enetaddr[1],
705                 bd->bi_enetaddr[2],
706                 bd->bi_enetaddr[3],
707                 bd->bi_enetaddr[4],
708                 bd->bi_enetaddr[5]
709                 );
710         printk("intfreq=%ld\n", bd->bi_intfreq);
711         printk("busfreq=%ld\n", bd->bi_busfreq);
712         printk("baudrate=%ld\n", bd->bi_baudrate);
713     }
714
715 #ifdef CONFIG_BLK_DEV_INITRD
716     if(initrd_start) {
717         printk("found initrd @%lx-%lx\n", initrd_start, initrd_end);
718     }
719 #endif /* CONFIG_BLK_DEV_INITRD */
720
721     if(cmdline_start && cmdline_len) {
722         printk("found cmdline: '%s'\n", cmd_line);
723     }
724 }
725 #endif  /* USE PPC_BOOT */
726 #endif
727
728 #if 0   /* XXXX */
729 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
730 static int
731 ev64260_ide_check_region(ide_ioreg_t from, unsigned int extent)
732 {
733         return check_region(from, extent);
734 }
735
736 static void
737 ev64260_ide_request_region(ide_ioreg_t from,
738                         unsigned int extent,
739                         const char *name)
740 {
741         request_region(from, extent, name);
742         return;
743 }
744
745 static void
746 ev64260_ide_release_region(ide_ioreg_t from,
747                         unsigned int extent)
748 {
749         release_region(from, extent);
750         return;
751 }
752
753 static void __init
754 ev64260_ide_pci_init_hwif_ports(hw_regs_t *hw, ide_ioreg_t data_port,
755                 ide_ioreg_t ctrl_port, int *irq)
756 {
757         struct pci_dev  *dev;
758 #if 1 /* NTL */
759         int i;
760
761         //printk("regs %d to %d @ 0x%x\n", IDE_DATA_OFFSET, IDE_STATUS_OFFSET, data_port);
762         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
763                 hw->io_ports[i] = data_port;
764                 data_port++;
765         }
766
767         //printk("ctrl %d @ 0x%x\n", IDE_CONTROL_OFFSET, ctrl_port);
768         hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
769 #endif
770
771         pci_for_each_dev(dev) {
772                 if (((dev->class >> 8) == PCI_CLASS_STORAGE_IDE) ||
773                     ((dev->class >> 8) == PCI_CLASS_STORAGE_RAID)) {
774                         hw->irq = dev->irq;
775
776                         if (irq != NULL) {
777                                 *irq = dev->irq;
778                         }
779                 }
780         }
781
782         return;
783 }
784 #endif
785 #endif
786
787 #if !defined(CONFIG_USE_PPCBOOT)
788 /*
789  * Set BAT 3 to map 0xfb000000 to 0xfc000000 of physical memory space.
790  */
791 static __inline__ void
792 ev64260_set_bat(void)
793 {
794         mb();
795         mtspr(DBAT1U, 0xfb0001fe);
796         mtspr(DBAT1L, 0xfb00002a);
797         mb();
798
799         return;
800 }
801 #endif
802
803 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
804 static void __init
805 ev64260_map_io(void)
806 {
807         io_block_mapping(0xfb000000, 0xfb000000, 0x01000000, _PAGE_IO);
808 }
809 #endif
810
811 void __init
812 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
813               unsigned long r6, unsigned long r7)
814 {
815 #ifdef CONFIG_BLK_DEV_INITRD
816         extern int      initrd_below_start_ok;
817
818         initrd_start=initrd_end=0;
819         initrd_below_start_ok=0;
820 #endif /* CONFIG_BLK_DEV_INITRD */
821
822         ppcboot_bd_valid=0;
823         memset(&ppcboot_bd,0,sizeof(ppcboot_bd));
824
825 #ifdef CONFIG_USE_PPCBOOT
826         parse_ppcbootinfo(r3, r4, r5, r6, r7);
827 #else
828         parse_bootinfo(find_bootinfo());
829 #endif
830
831         isa_mem_base = 0;
832         isa_io_base = 0xa0000000;       /* XXXX */
833         pci_dram_offset = 0x80000000;   /* XXXX */
834
835         loops_per_jiffy = ev64260_get_cpu_speed() / HZ;
836
837         ppc_md.setup_arch = ev64260_setup_arch;
838         ppc_md.show_cpuinfo = ev64260_show_cpuinfo;
839         ppc_md.init_IRQ = gt64260_init_irq;
840         ppc_md.get_irq = gt64260_get_irq;
841
842         ppc_md.pcibios_fixup = ev64260_pci_fixups;
843
844         ppc_md.restart = ev64260_restart;
845         ppc_md.power_off = ev64260_power_off;
846         ppc_md.halt = ev64260_halt;
847
848         ppc_md.find_end_of_memory = ev64260_find_end_of_memory;
849
850         ppc_md.init = NULL;
851
852         ppc_md.time_init = todc_time_init;
853         ppc_md.set_rtc_time = todc_set_rtc_time;
854         ppc_md.get_rtc_time = todc_get_rtc_time;
855
856         ppc_md.nvram_read_val = todc_direct_read_val;
857         ppc_md.nvram_write_val = todc_direct_write_val;
858
859         ppc_md.calibrate_decr = ev64260_calibrate_decr;
860
861 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
862         ppc_ide_md.ide_init_hwif = ev64260_ide_pci_init_hwif_ports;
863 #endif
864
865         bh.p_base = CONFIG_MV64X60_NEW_BASE;
866
867 #if !defined(CONFIG_USE_PPCBOOT)
868         ev64260_set_bat();
869 #endif
870
871 #ifdef  CONFIG_SERIAL_8250
872 #if defined(CONFIG_SERIAL_TEXT_DEBUG)
873         ppc_md.setup_io_mappings = ev64260_map_io;
874         ppc_md.progress = gen550_progress;
875 #endif
876 #if defined(CONFIG_KGDB)
877         ppc_md.setup_io_mappings = ev64260_map_io;
878         ppc_md.early_serial_map = ev64260_early_serial_map;
879 #endif
880 #elif defined(CONFIG_SERIAL_MPSC_CONSOLE)
881 #ifdef  CONFIG_SERIAL_TEXT_DEBUG
882         ppc_md.setup_io_mappings = ev64260_map_io;
883         ppc_md.progress = gt64260_mpsc_progress;
884 #endif  /* CONFIG_SERIAL_TEXT_DEBUG */
885 #ifdef  CONFIG_KGDB
886         ppc_md.setup_io_mappings = ev64260_map_io;
887         ppc_md.early_serial_map = ev64260_early_serial_map;
888 #endif  /* CONFIG_KGDB */
889
890 #endif
891
892         return;
893 }