Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux-2.6
[pandora-kernel.git] / arch / ppc / platforms / sandpoint.c
1 /*
2  * Board setup routines for the Motorola SPS Sandpoint Test Platform.
3  *
4  * Author: Mark A. Greer
5  *       mgreer@mvista.com
6  *
7  * 2000-2003 (c) MontaVista Software, Inc.  This file is licensed under
8  * the terms of the GNU General Public License version 2.  This program
9  * is licensed "as is" without any warranty of any kind, whether express
10  * or implied.
11  */
12
13 /*
14  * This file adds support for the Motorola SPS Sandpoint Test Platform.
15  * These boards have a PPMC slot for the processor so any combination
16  * of cpu and host bridge can be attached.  This port is for an 8240 PPMC
17  * module from Motorola SPS and other closely related cpu/host bridge
18  * combinations (e.g., 750/755/7400 with MPC107 host bridge).
19  * The sandpoint itself has a Windbond 83c553 (PCI-ISA bridge, 2 DMA ctlrs, 2
20  * cascaded 8259 interrupt ctlrs, 8254 Timer/Counter, and an IDE ctlr), a
21  * National 87308 (RTC, 2 UARTs, Keyboard & mouse ctlrs, and a floppy ctlr),
22  * and 4 PCI slots (only 2 of which are usable; the other 2 are keyed for 3.3V
23  * but are really 5V).
24  *
25  * The firmware on the sandpoint is called DINK (not my acronym :).  This port
26  * depends on DINK to do some basic initialization (e.g., initialize the memory
27  * ctlr) and to ensure that the processor is using MAP B (CHRP map).
28  *
29  * The switch settings for the Sandpoint board MUST be as follows:
30  *      S3: down
31  *      S4: up
32  *      S5: up
33  *      S6: down
34  *
35  * 'down' is in the direction from the PCI slots towards the PPMC slot;
36  * 'up' is in the direction from the PPMC slot towards the PCI slots.
37  * Be careful, the way the sandpoint board is installed in XT chasses will
38  * make the directions reversed.
39  *
40  * Since Motorola listened to our suggestions for improvement, we now have
41  * the Sandpoint X3 board.  All of the PCI slots are available, it uses
42  * the serial interrupt interface (just a hardware thing we need to
43  * configure properly).
44  *
45  * Use the default X3 switch settings.  The interrupts are then:
46  *              EPIC    Source
47  *                0     SIOINT          (8259, active low)
48  *                1     PCI #1
49  *                2     PCI #2
50  *                3     PCI #3
51  *                4     PCI #4
52  *                7     Winbond INTC    (IDE interrupt)
53  *                8     Winbond INTD    (IDE interrupt)
54  *
55  *
56  * Motorola has finally released a version of DINK32 that correctly
57  * (seemingly) initalizes the memory controller correctly, regardless
58  * of the amount of memory in the system.  Once a method of determining
59  * what version of DINK initializes the system for us, if applicable, is
60  * found, we can hopefully stop hardcoding 32MB of RAM.
61  */
62
63 #include <linux/config.h>
64 #include <linux/stddef.h>
65 #include <linux/kernel.h>
66 #include <linux/init.h>
67 #include <linux/errno.h>
68 #include <linux/reboot.h>
69 #include <linux/pci.h>
70 #include <linux/kdev_t.h>
71 #include <linux/major.h>
72 #include <linux/initrd.h>
73 #include <linux/console.h>
74 #include <linux/delay.h>
75 #include <linux/ide.h>
76 #include <linux/seq_file.h>
77 #include <linux/root_dev.h>
78 #include <linux/serial.h>
79 #include <linux/tty.h>  /* for linux/serial_core.h */
80 #include <linux/serial_core.h>
81 #include <linux/serial_8250.h>
82
83 #include <asm/system.h>
84 #include <asm/pgtable.h>
85 #include <asm/page.h>
86 #include <asm/time.h>
87 #include <asm/dma.h>
88 #include <asm/io.h>
89 #include <asm/machdep.h>
90 #include <asm/prom.h>
91 #include <asm/smp.h>
92 #include <asm/vga.h>
93 #include <asm/open_pic.h>
94 #include <asm/i8259.h>
95 #include <asm/todc.h>
96 #include <asm/bootinfo.h>
97 #include <asm/mpc10x.h>
98 #include <asm/pci-bridge.h>
99 #include <asm/kgdb.h>
100 #include <asm/ppc_sys.h>
101
102 #include "sandpoint.h"
103
104 /* Set non-zero if an X2 Sandpoint detected. */
105 static int sandpoint_is_x2;
106
107 unsigned char __res[sizeof(bd_t)];
108
109 static void sandpoint_halt(void);
110 static void sandpoint_probe_type(void);
111
112 /*
113  * Define all of the IRQ senses and polarities.  Taken from the
114  * Sandpoint X3 User's manual.
115  */
116 static u_char sandpoint_openpic_initsenses[] __initdata = {
117         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 0: SIOINT */
118         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 2: PCI Slot 1 */
119         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 3: PCI Slot 2 */
120         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 4: PCI Slot 3 */
121         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 5: PCI Slot 4 */
122         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 8: IDE (INT C) */
123         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE)       /* 9: IDE (INT D) */
124 };
125
126 /*
127  * Motorola SPS Sandpoint interrupt routing.
128  */
129 static inline int
130 x3_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
131 {
132         static char pci_irq_table[][4] =
133         /*
134          *      PCI IDSEL/INTPIN->INTLINE
135          *         A   B   C   D
136          */
137         {
138                 { 16,  0,  0,  0 },     /* IDSEL 11 - i8259 on Winbond */
139                 {  0,  0,  0,  0 },     /* IDSEL 12 - unused */
140                 { 18, 21, 20, 19 },     /* IDSEL 13 - PCI slot 1 */
141                 { 19, 18, 21, 20 },     /* IDSEL 14 - PCI slot 2 */
142                 { 20, 19, 18, 21 },     /* IDSEL 15 - PCI slot 3 */
143                 { 21, 20, 19, 18 },     /* IDSEL 16 - PCI slot 4 */
144         };
145
146         const long min_idsel = 11, max_idsel = 16, irqs_per_slot = 4;
147         return PCI_IRQ_TABLE_LOOKUP;
148 }
149
150 static inline int
151 x2_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
152 {
153         static char pci_irq_table[][4] =
154         /*
155          *      PCI IDSEL/INTPIN->INTLINE
156          *         A   B   C   D
157          */
158         {
159                 { 18,  0,  0,  0 },     /* IDSEL 11 - i8259 on Windbond */
160                 {  0,  0,  0,  0 },     /* IDSEL 12 - unused */
161                 { 16, 17, 18, 19 },     /* IDSEL 13 - PCI slot 1 */
162                 { 17, 18, 19, 16 },     /* IDSEL 14 - PCI slot 2 */
163                 { 18, 19, 16, 17 },     /* IDSEL 15 - PCI slot 3 */
164                 { 19, 16, 17, 18 },     /* IDSEL 16 - PCI slot 4 */
165         };
166
167         const long min_idsel = 11, max_idsel = 16, irqs_per_slot = 4;
168         return PCI_IRQ_TABLE_LOOKUP;
169 }
170
171 static void __init
172 sandpoint_setup_winbond_83553(struct pci_controller *hose)
173 {
174         int             devfn;
175
176         /*
177          * Route IDE interrupts directly to the 8259's IRQ 14 & 15.
178          * We can't route the IDE interrupt to PCI INTC# or INTD# because those
179          * woule interfere with the PMC's INTC# and INTD# lines.
180          */
181         /*
182          * Winbond Fcn 0
183          */
184         devfn = PCI_DEVFN(11,0);
185
186         early_write_config_byte(hose,
187                                 0,
188                                 devfn,
189                                 0x43, /* IDE Interrupt Routing Control */
190                                 0xef);
191         early_write_config_word(hose,
192                                 0,
193                                 devfn,
194                                 0x44, /* PCI Interrupt Routing Control */
195                                 0x0000);
196
197         /* Want ISA memory cycles to be forwarded to PCI bus */
198         early_write_config_byte(hose,
199                                 0,
200                                 devfn,
201                                 0x48, /* ISA-to-PCI Addr Decoder Control */
202                                 0xf0);
203
204         /* Enable Port 92.  */
205         early_write_config_byte(hose,
206                                 0,
207                                 devfn,
208                                 0x4e,   /* AT System Control Register */
209                                 0x06);
210         /*
211          * Winbond Fcn 1
212          */
213         devfn = PCI_DEVFN(11,1);
214
215         /* Put IDE controller into native mode. */
216         early_write_config_byte(hose,
217                                 0,
218                                 devfn,
219                                 0x09,   /* Programming interface Register */
220                                 0x8f);
221
222         /* Init IRQ routing, enable both ports, disable fast 16 */
223         early_write_config_dword(hose,
224                                 0,
225                                 devfn,
226                                 0x40,   /* IDE Control/Status Register */
227                                 0x00ff0011);
228         return;
229 }
230
231 /* On the sandpoint X2, we must avoid sending configuration cycles to
232  * device #12 (IDSEL addr = AD12).
233  */
234 static int
235 x2_exclude_device(u_char bus, u_char devfn)
236 {
237         if ((bus == 0) && (PCI_SLOT(devfn) == SANDPOINT_HOST_BRIDGE_IDSEL))
238                 return PCIBIOS_DEVICE_NOT_FOUND;
239         else
240                 return PCIBIOS_SUCCESSFUL;
241 }
242
243 static void __init
244 sandpoint_find_bridges(void)
245 {
246         struct pci_controller   *hose;
247
248         hose = pcibios_alloc_controller();
249
250         if (!hose)
251                 return;
252
253         hose->first_busno = 0;
254         hose->last_busno = 0xff;
255
256         if (mpc10x_bridge_init(hose,
257                                MPC10X_MEM_MAP_B,
258                                MPC10X_MEM_MAP_B,
259                                MPC10X_MAPB_EUMB_BASE) == 0) {
260
261                 /* Do early winbond init, then scan PCI bus */
262                 sandpoint_setup_winbond_83553(hose);
263                 hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
264
265                 ppc_md.pcibios_fixup = NULL;
266                 ppc_md.pcibios_fixup_bus = NULL;
267                 ppc_md.pci_swizzle = common_swizzle;
268                 if (sandpoint_is_x2) {
269                         ppc_md.pci_map_irq = x2_map_irq;
270                         ppc_md.pci_exclude_device = x2_exclude_device;
271                 } else
272                         ppc_md.pci_map_irq = x3_map_irq;
273         }
274         else {
275                 if (ppc_md.progress)
276                         ppc_md.progress("Bridge init failed", 0x100);
277                 printk("Host bridge init failed\n");
278         }
279
280         return;
281 }
282
283 static void __init
284 sandpoint_setup_arch(void)
285 {
286         /* Probe for Sandpoint model */
287         sandpoint_probe_type();
288         if (sandpoint_is_x2)
289                 epic_serial_mode = 0;
290
291         loops_per_jiffy = 100000000 / HZ;
292
293 #ifdef CONFIG_BLK_DEV_INITRD
294         if (initrd_start)
295                 ROOT_DEV = Root_RAM0;
296         else
297 #endif
298 #ifdef  CONFIG_ROOT_NFS
299                 ROOT_DEV = Root_NFS;
300 #else
301                 ROOT_DEV = Root_HDA1;
302 #endif
303
304         /* Lookup PCI host bridges */
305         sandpoint_find_bridges();
306
307         if (strncmp (cur_ppc_sys_spec->ppc_sys_name, "8245", 4) == 0)
308         {
309                 bd_t *bp = (bd_t *)__res;
310                 struct plat_serial8250_port *pdata;
311
312                 pdata = (struct plat_serial8250_port *) ppc_sys_get_pdata(MPC10X_UART0);
313                 if (pdata)
314                 {
315                         pdata[0].uartclk = bp->bi_busfreq;
316                 }
317
318 #ifdef CONFIG_SANDPOINT_ENABLE_UART1
319                 pdata = (struct plat_serial8250_port *) ppc_sys_get_pdata(MPC10X_UART1);
320                 if (pdata)
321                 {
322                         pdata[0].uartclk = bp->bi_busfreq;
323                 }
324 #else
325                 ppc_sys_device_remove(MPC10X_UART1);
326 #endif
327         }
328
329         printk(KERN_INFO "Motorola SPS Sandpoint Test Platform\n");
330         printk(KERN_INFO "Port by MontaVista Software, Inc. (source@mvista.com)\n");
331
332         /* DINK32 12.3 and below do not correctly enable any caches.
333          * We will do this now with good known values.  Future versions
334          * of DINK32 are supposed to get this correct.
335          */
336         if (cpu_has_feature(CPU_FTR_SPEC7450))
337                 /* 745x is different.  We only want to pass along enable. */
338                 _set_L2CR(L2CR_L2E);
339         else if (cpu_has_feature(CPU_FTR_L2CR))
340                 /* All modules have 1MB of L2.  We also assume that an
341                  * L2 divisor of 3 will work.
342                  */
343                 _set_L2CR(L2CR_L2E | L2CR_L2SIZ_1MB | L2CR_L2CLK_DIV3
344                                 | L2CR_L2RAM_PIPE | L2CR_L2OH_1_0 | L2CR_L2DF);
345 #if 0
346         /* Untested right now. */
347         if (cpu_has_feature(CPU_FTR_L3CR)) {
348                 /* Magic value. */
349                 _set_L3CR(0x8f032000);
350         }
351 #endif
352 }
353
354 #define SANDPOINT_87308_CFG_ADDR                0x15c
355 #define SANDPOINT_87308_CFG_DATA                0x15d
356
357 #define SANDPOINT_87308_CFG_INB(addr, byte) {                           \
358         outb((addr), SANDPOINT_87308_CFG_ADDR);                         \
359         (byte) = inb(SANDPOINT_87308_CFG_DATA);                         \
360 }
361
362 #define SANDPOINT_87308_CFG_OUTB(addr, byte) {                          \
363         outb((addr), SANDPOINT_87308_CFG_ADDR);                         \
364         outb((byte), SANDPOINT_87308_CFG_DATA);                         \
365 }
366
367 #define SANDPOINT_87308_SELECT_DEV(dev_num) {                           \
368         SANDPOINT_87308_CFG_OUTB(0x07, (dev_num));                      \
369 }
370
371 #define SANDPOINT_87308_DEV_ENABLE(dev_num) {                           \
372         SANDPOINT_87308_SELECT_DEV(dev_num);                            \
373         SANDPOINT_87308_CFG_OUTB(0x30, 0x01);                           \
374 }
375
376 /*
377  * To probe the Sandpoint type, we need to check for a connection between GPIO
378  * pins 6 and 7 on the NS87308 SuperIO.
379  */
380 static void __init sandpoint_probe_type(void)
381 {
382         u8 x;
383         /* First, ensure that the GPIO pins are enabled. */
384         SANDPOINT_87308_SELECT_DEV(0x07); /* Select GPIO logical device */
385         SANDPOINT_87308_CFG_OUTB(0x60, 0x07); /* Base address 0x700 */
386         SANDPOINT_87308_CFG_OUTB(0x61, 0x00);
387         SANDPOINT_87308_CFG_OUTB(0x30, 0x01); /* Enable */
388
389         /* Now, set pin 7 to output and pin 6 to input. */
390         outb((inb(0x701) | 0x80) & 0xbf, 0x701);
391         /* Set push-pull output */
392         outb(inb(0x702) | 0x80, 0x702);
393         /* Set pull-up on input */
394         outb(inb(0x703) | 0x40, 0x703);
395         /* Set output high and check */
396         x = inb(0x700);
397         outb(x | 0x80, 0x700);
398         x = inb(0x700);
399         sandpoint_is_x2 = ! (x & 0x40);
400         if (ppc_md.progress && sandpoint_is_x2)
401                 ppc_md.progress("High output says X2", 0);
402         /* Set output low and check */
403         outb(x & 0x7f, 0x700);
404         sandpoint_is_x2 |= inb(0x700) & 0x40;
405         if (ppc_md.progress && sandpoint_is_x2)
406                 ppc_md.progress("Low output says X2", 0);
407         if (ppc_md.progress && ! sandpoint_is_x2)
408                 ppc_md.progress("Sandpoint is X3", 0);
409 }
410
411 /*
412  * Fix IDE interrupts.
413  */
414 static int __init
415 sandpoint_fix_winbond_83553(void)
416 {
417         /* Make some 8259 interrupt level sensitive */
418         outb(0xe0, 0x4d0);
419         outb(0xde, 0x4d1);
420
421         return 0;
422 }
423
424 arch_initcall(sandpoint_fix_winbond_83553);
425
426 /*
427  * Initialize the ISA devices on the Nat'l PC87308VUL SuperIO chip.
428  */
429 static int __init
430 sandpoint_setup_natl_87308(void)
431 {
432         u_char  reg;
433
434         /*
435          * Enable all the devices on the Super I/O chip.
436          */
437         SANDPOINT_87308_SELECT_DEV(0x00); /* Select kbd logical device */
438         SANDPOINT_87308_CFG_OUTB(0xf0, 0x00); /* Set KBC clock to 8 Mhz */
439         SANDPOINT_87308_DEV_ENABLE(0x00); /* Enable keyboard */
440         SANDPOINT_87308_DEV_ENABLE(0x01); /* Enable mouse */
441         SANDPOINT_87308_DEV_ENABLE(0x02); /* Enable rtc */
442         SANDPOINT_87308_DEV_ENABLE(0x03); /* Enable fdc (floppy) */
443         SANDPOINT_87308_DEV_ENABLE(0x04); /* Enable parallel */
444         SANDPOINT_87308_DEV_ENABLE(0x05); /* Enable UART 2 */
445         SANDPOINT_87308_CFG_OUTB(0xf0, 0x82); /* Enable bank select regs */
446         SANDPOINT_87308_DEV_ENABLE(0x06); /* Enable UART 1 */
447         SANDPOINT_87308_CFG_OUTB(0xf0, 0x82); /* Enable bank select regs */
448
449         /* Set up floppy in PS/2 mode */
450         outb(0x09, SIO_CONFIG_RA);
451         reg = inb(SIO_CONFIG_RD);
452         reg = (reg & 0x3F) | 0x40;
453         outb(reg, SIO_CONFIG_RD);
454         outb(reg, SIO_CONFIG_RD);       /* Have to write twice to change! */
455
456         return 0;
457 }
458
459 arch_initcall(sandpoint_setup_natl_87308);
460
461 static int __init
462 sandpoint_request_io(void)
463 {
464         request_region(0x00,0x20,"dma1");
465         request_region(0x20,0x20,"pic1");
466         request_region(0x40,0x20,"timer");
467         request_region(0x80,0x10,"dma page reg");
468         request_region(0xa0,0x20,"pic2");
469         request_region(0xc0,0x20,"dma2");
470
471         return 0;
472 }
473
474 arch_initcall(sandpoint_request_io);
475
476 /*
477  * Interrupt setup and service.  Interrrupts on the Sandpoint come
478  * from the four PCI slots plus the 8259 in the Winbond Super I/O (SIO).
479  * The 8259 is cascaded from EPIC IRQ0, IRQ1-4 map to PCI slots 1-4,
480  * IDE is on EPIC 7 and 8.
481  */
482 static void __init
483 sandpoint_init_IRQ(void)
484 {
485         int i;
486
487         OpenPIC_InitSenses = sandpoint_openpic_initsenses;
488         OpenPIC_NumInitSenses = sizeof(sandpoint_openpic_initsenses);
489
490         mpc10x_set_openpic();
491         openpic_hookup_cascade(sandpoint_is_x2 ? 17 : NUM_8259_INTERRUPTS, "82c59 cascade",
492                         i8259_irq);
493
494         /*
495          * The EPIC allows for a read in the range of 0xFEF00000 ->
496          * 0xFEFFFFFF to generate a PCI interrupt-acknowledge transaction.
497          */
498         i8259_init(0xfef00000, 0);
499 }
500
501 static unsigned long __init
502 sandpoint_find_end_of_memory(void)
503 {
504         bd_t *bp = (bd_t *)__res;
505
506         if (bp->bi_memsize)
507                 return bp->bi_memsize;
508
509         /* DINK32 13.0 correctly initalizes things, so iff you use
510          * this you _should_ be able to change this instead of a
511          * hardcoded value. */
512 #if 0
513         return mpc10x_get_mem_size(MPC10X_MEM_MAP_B);
514 #else
515         return 32*1024*1024;
516 #endif
517 }
518
519 static void __init
520 sandpoint_map_io(void)
521 {
522         io_block_mapping(0xfe000000, 0xfe000000, 0x02000000, _PAGE_IO);
523 }
524
525 static void
526 sandpoint_restart(char *cmd)
527 {
528         local_irq_disable();
529
530         /* Set exception prefix high - to the firmware */
531         _nmask_and_or_msr(0, MSR_IP);
532
533         /* Reset system via Port 92 */
534         outb(0x00, 0x92);
535         outb(0x01, 0x92);
536         for(;;);        /* Spin until reset happens */
537 }
538
539 static void
540 sandpoint_power_off(void)
541 {
542         local_irq_disable();
543         for(;;);        /* No way to shut power off with software */
544         /* NOTREACHED */
545 }
546
547 static void
548 sandpoint_halt(void)
549 {
550         sandpoint_power_off();
551         /* NOTREACHED */
552 }
553
554 static int
555 sandpoint_show_cpuinfo(struct seq_file *m)
556 {
557         seq_printf(m, "vendor\t\t: Motorola SPS\n");
558         seq_printf(m, "machine\t\t: Sandpoint\n");
559
560         return 0;
561 }
562
563 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
564 /*
565  * IDE support.
566  */
567 static int              sandpoint_ide_ports_known = 0;
568 static unsigned long    sandpoint_ide_regbase[MAX_HWIFS];
569 static unsigned long    sandpoint_ide_ctl_regbase[MAX_HWIFS];
570 static unsigned long    sandpoint_idedma_regbase;
571
572 static void
573 sandpoint_ide_probe(void)
574 {
575         struct pci_dev *pdev = pci_get_device(PCI_VENDOR_ID_WINBOND,
576                         PCI_DEVICE_ID_WINBOND_82C105, NULL);
577
578         if (pdev) {
579                 sandpoint_ide_regbase[0]=pdev->resource[0].start;
580                 sandpoint_ide_regbase[1]=pdev->resource[2].start;
581                 sandpoint_ide_ctl_regbase[0]=pdev->resource[1].start;
582                 sandpoint_ide_ctl_regbase[1]=pdev->resource[3].start;
583                 sandpoint_idedma_regbase=pdev->resource[4].start;
584                 pci_dev_put(pdev);
585         }
586
587         sandpoint_ide_ports_known = 1;
588 }
589
590 static int
591 sandpoint_ide_default_irq(unsigned long base)
592 {
593         if (sandpoint_ide_ports_known == 0)
594                 sandpoint_ide_probe();
595
596         if (base == sandpoint_ide_regbase[0])
597                 return SANDPOINT_IDE_INT0;
598         else if (base == sandpoint_ide_regbase[1])
599                 return SANDPOINT_IDE_INT1;
600         else
601                 return 0;
602 }
603
604 static unsigned long
605 sandpoint_ide_default_io_base(int index)
606 {
607         if (sandpoint_ide_ports_known == 0)
608                 sandpoint_ide_probe();
609
610         return sandpoint_ide_regbase[index];
611 }
612
613 static void __init
614 sandpoint_ide_init_hwif_ports(hw_regs_t *hw, unsigned long data_port,
615                 unsigned long ctrl_port, int *irq)
616 {
617         unsigned long reg = data_port;
618         uint    alt_status_base;
619         int     i;
620
621         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
622                 hw->io_ports[i] = reg++;
623         }
624
625         if (data_port == sandpoint_ide_regbase[0]) {
626                 alt_status_base = sandpoint_ide_ctl_regbase[0] + 2;
627                 hw->irq = 14;
628         }
629         else if (data_port == sandpoint_ide_regbase[1]) {
630                 alt_status_base = sandpoint_ide_ctl_regbase[1] + 2;
631                 hw->irq = 15;
632         }
633         else {
634                 alt_status_base = 0;
635                 hw->irq = 0;
636         }
637
638         if (ctrl_port) {
639                 hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
640         } else {
641                 hw->io_ports[IDE_CONTROL_OFFSET] = alt_status_base;
642         }
643
644         if (irq != NULL) {
645                 *irq = hw->irq;
646         }
647 }
648 #endif
649
650 /*
651  * Set BAT 3 to map 0xf8000000 to end of physical memory space 1-to-1.
652  */
653 static __inline__ void
654 sandpoint_set_bat(void)
655 {
656         unsigned long bat3u, bat3l;
657
658         __asm__ __volatile__(
659                         " lis %0,0xf800\n       \
660                         ori %1,%0,0x002a\n      \
661                         ori %0,%0,0x0ffe\n      \
662                         mtspr 0x21e,%0\n        \
663                         mtspr 0x21f,%1\n        \
664                         isync\n                 \
665                         sync "
666                         : "=r" (bat3u), "=r" (bat3l));
667 }
668
669 TODC_ALLOC();
670
671 void __init
672 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
673                 unsigned long r6, unsigned long r7)
674 {
675         parse_bootinfo(find_bootinfo());
676
677         /* ASSUMPTION:  If both r3 (bd_t pointer) and r6 (cmdline pointer)
678          * are non-zero, then we should use the board info from the bd_t
679          * structure and the cmdline pointed to by r6 instead of the
680          * information from birecs, if any.  Otherwise, use the information
681          * from birecs as discovered by the preceeding call to
682          * parse_bootinfo().  This rule should work with both PPCBoot, which
683          * uses a bd_t board info structure, and the kernel boot wrapper,
684          * which uses birecs.
685          */
686         if (r3 && r6) {
687                 /* copy board info structure */
688                 memcpy( (void *)__res,(void *)(r3+KERNELBASE), sizeof(bd_t) );
689                 /* copy command line */
690                 *(char *)(r7+KERNELBASE) = 0;
691                 strcpy(cmd_line, (char *)(r6+KERNELBASE));
692         }
693
694 #ifdef CONFIG_BLK_DEV_INITRD
695         /* take care of initrd if we have one */
696         if (r4) {
697                 initrd_start = r4 + KERNELBASE;
698                 initrd_end = r5 + KERNELBASE;
699         }
700 #endif /* CONFIG_BLK_DEV_INITRD */
701
702         /* Map in board regs, etc. */
703         sandpoint_set_bat();
704
705         isa_io_base = MPC10X_MAPB_ISA_IO_BASE;
706         isa_mem_base = MPC10X_MAPB_ISA_MEM_BASE;
707         pci_dram_offset = MPC10X_MAPB_DRAM_OFFSET;
708         ISA_DMA_THRESHOLD = 0x00ffffff;
709         DMA_MODE_READ = 0x44;
710         DMA_MODE_WRITE = 0x48;
711         ppc_do_canonicalize_irqs = 1;
712
713         ppc_md.setup_arch = sandpoint_setup_arch;
714         ppc_md.show_cpuinfo = sandpoint_show_cpuinfo;
715         ppc_md.init_IRQ = sandpoint_init_IRQ;
716         ppc_md.get_irq = openpic_get_irq;
717
718         ppc_md.restart = sandpoint_restart;
719         ppc_md.power_off = sandpoint_power_off;
720         ppc_md.halt = sandpoint_halt;
721
722         ppc_md.find_end_of_memory = sandpoint_find_end_of_memory;
723         ppc_md.setup_io_mappings = sandpoint_map_io;
724
725         TODC_INIT(TODC_TYPE_PC97307, 0x70, 0x00, 0x71, 8);
726         ppc_md.time_init = todc_time_init;
727         ppc_md.set_rtc_time = todc_set_rtc_time;
728         ppc_md.get_rtc_time = todc_get_rtc_time;
729         ppc_md.calibrate_decr = todc_calibrate_decr;
730
731         ppc_md.nvram_read_val = todc_mc146818_read_val;
732         ppc_md.nvram_write_val = todc_mc146818_write_val;
733
734 #ifdef CONFIG_KGDB
735         ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
736 #endif
737 #ifdef CONFIG_SERIAL_TEXT_DEBUG
738         ppc_md.progress = gen550_progress;
739 #endif
740
741 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
742         ppc_ide_md.default_irq = sandpoint_ide_default_irq;
743         ppc_ide_md.default_io_base = sandpoint_ide_default_io_base;
744         ppc_ide_md.ide_init_hwif = sandpoint_ide_init_hwif_ports;
745 #endif
746 }