linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / arch / ppc / platforms / pplus.c
1 /*
2  * arch/ppc/platforms/pplus.c
3  *
4  * Board and PCI setup routines for MCG PowerPlus
5  *
6  * Author: Randy Vinson <rvinson@mvista.com>
7  *
8  * Derived from original PowerPlus PReP work by
9  * Cort Dougan, Johnnie Peters, Matt Porter, and
10  * Troy Benjegerdes.
11  *
12  * 2001-2004 (c) MontaVista, Software, Inc.  This file is licensed under
13  * the terms of the GNU General Public License version 2.  This program
14  * is licensed "as is" without any warranty of any kind, whether express
15  * or implied.
16  */
17
18 #include <linux/config.h>
19 #include <linux/kernel.h>
20 #include <linux/interrupt.h>
21 #include <linux/init.h>
22 #include <linux/ioport.h>
23 #include <linux/console.h>
24 #include <linux/pci.h>
25 #include <linux/ide.h>
26 #include <linux/seq_file.h>
27 #include <linux/root_dev.h>
28
29 #include <asm/system.h>
30 #include <asm/io.h>
31 #include <asm/pgtable.h>
32 #include <asm/dma.h>
33 #include <asm/machdep.h>
34 #include <asm/prep_nvram.h>
35 #include <asm/vga.h>
36 #include <asm/i8259.h>
37 #include <asm/open_pic.h>
38 #include <asm/hawk.h>
39 #include <asm/todc.h>
40 #include <asm/bootinfo.h>
41 #include <asm/kgdb.h>
42 #include <asm/reg.h>
43
44 #include "pplus.h"
45
46 #undef DUMP_DBATS
47
48 TODC_ALLOC();
49
50 extern void pplus_setup_hose(void);
51 extern void pplus_set_VIA_IDE_native(void);
52
53 extern unsigned long loops_per_jiffy;
54 unsigned char *Motherboard_map_name;
55
56 /* Tables for known hardware */
57
58 /* Motorola Mesquite */
59 static inline int
60 mesquite_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
61 {
62         static char pci_irq_table[][4] =
63             /*
64              *      MPIC interrupts for various IDSEL values (MPIC IRQ0 =
65              *      Linux IRQ16 (to leave room for ISA IRQs at 0-15).
66              *      PCI IDSEL/INTPIN->INTLINE
67              *         A   B   C   D
68              */
69         {
70                 {18,  0,  0,  0},       /* IDSEL 14 - Enet 0 */
71                 { 0,  0,  0,  0},       /* IDSEL 15 - unused */
72                 {19, 19, 19, 19},       /* IDSEL 16 - PMC Slot 1 */
73                 { 0,  0,  0,  0},       /* IDSEL 17 - unused */
74                 { 0,  0,  0,  0},       /* IDSEL 18 - unused */
75                 { 0,  0,  0,  0},       /* IDSEL 19 - unused */
76                 {24, 25, 26, 27},       /* IDSEL 20 - P2P bridge (to cPCI 1) */
77                 { 0,  0,  0,  0},       /* IDSEL 21 - unused */
78                 {28, 29, 30, 31}        /* IDSEL 22 - P2P bridge (to cPCI 2) */
79         };
80
81         const long min_idsel = 14, max_idsel = 22, irqs_per_slot = 4;
82         return PCI_IRQ_TABLE_LOOKUP;
83 }
84
85 /* Motorola Sitka */
86 static inline int
87 sitka_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
88 {
89         static char pci_irq_table[][4] =
90             /*
91              *      MPIC interrupts for various IDSEL values (MPIC IRQ0 =
92              *      Linux IRQ16 (to leave room for ISA IRQs at 0-15).
93              *      PCI IDSEL/INTPIN->INTLINE
94              *         A   B   C   D
95              */
96         {
97                 {18,  0,  0,  0},       /* IDSEL 14 - Enet 0 */
98                 { 0,  0,  0,  0},       /* IDSEL 15 - unused */
99                 {25, 26, 27, 28},       /* IDSEL 16 - PMC Slot 1 */
100                 {28, 25, 26, 27},       /* IDSEL 17 - PMC Slot 2 */
101                 { 0,  0,  0,  0},       /* IDSEL 18 - unused */
102                 { 0,  0,  0,  0},       /* IDSEL 19 - unused */
103                 {20,  0,  0,  0}        /* IDSEL 20 - P2P bridge (to cPCI) */
104         };
105
106         const long min_idsel = 14, max_idsel = 20, irqs_per_slot = 4;
107         return PCI_IRQ_TABLE_LOOKUP;
108 }
109
110 /* Motorola MTX */
111 static inline int
112 MTX_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
113 {
114         static char pci_irq_table[][4] =
115             /*
116              *      MPIC interrupts for various IDSEL values (MPIC IRQ0 =
117              *      Linux IRQ16 (to leave room for ISA IRQs at 0-15).
118              *      PCI IDSEL/INTPIN->INTLINE
119              *         A   B   C   D
120              */
121         {
122                 {19,  0,  0,  0},       /* IDSEL 12 - SCSI   */
123                 { 0,  0,  0,  0},       /* IDSEL 13 - unused */
124                 {18,  0,  0,  0},       /* IDSEL 14 - Enet   */
125                 { 0,  0,  0,  0},       /* IDSEL 15 - unused */
126                 {25, 26, 27, 28},       /* IDSEL 16 - PMC Slot 1 */
127                 {26, 27, 28, 25},       /* IDSEL 17 - PMC Slot 2 */
128                 {27, 28, 25, 26}        /* IDSEL 18 - PCI Slot 3 */
129         };
130
131         const long min_idsel = 12, max_idsel = 18, irqs_per_slot = 4;
132         return PCI_IRQ_TABLE_LOOKUP;
133 }
134
135 /* Motorola MTX Plus */
136 /* Secondary bus interrupt routing is not supported yet */
137 static inline int
138 MTXplus_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
139 {
140         static char pci_irq_table[][4] =
141             /*
142              *      MPIC interrupts for various IDSEL values (MPIC IRQ0 =
143              *      Linux IRQ16 (to leave room for ISA IRQs at 0-15).
144              *      PCI IDSEL/INTPIN->INTLINE
145              *         A   B   C   D
146              */
147         {
148                 {19,  0,  0,  0},       /* IDSEL 12 - SCSI   */
149                 { 0,  0,  0,  0},       /* IDSEL 13 - unused */
150                 {18,  0,  0,  0},       /* IDSEL 14 - Enet 1 */
151                 { 0,  0,  0,  0},       /* IDSEL 15 - unused */
152                 {25, 26, 27, 28},       /* IDSEL 16 - PCI Slot 1P */
153                 {26, 27, 28, 25},       /* IDSEL 17 - PCI Slot 2P */
154                 {27, 28, 25, 26},       /* IDSEL 18 - PCI Slot 3P */
155                 {26,  0,  0,  0},       /* IDSEL 19 - Enet 2 */
156                 { 0,  0,  0,  0}        /* IDSEL 20 - P2P Bridge */
157         };
158
159         const long min_idsel = 12, max_idsel = 20, irqs_per_slot = 4;
160         return PCI_IRQ_TABLE_LOOKUP;
161 }
162
163 static inline int
164 Genesis2_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
165 {
166         /* 2600
167          * Raven 31
168          * ISA   11
169          * SCSI  12 - IRQ3
170          * Univ  13
171          * eth   14 - IRQ2
172          * VGA   15 - IRQ4
173          * PMC1  16 - IRQ9,10,11,12 = PMC1 A-D
174          * PMC2  17 - IRQ12,9,10,11 = A-D
175          * SCSI2 18 - IRQ11
176          * eth2  19 - IRQ10
177          * PCIX  20 - IRQ9,10,11,12 = PCI A-D
178          */
179
180         /* 2400
181          * Hawk 31
182          * ISA  11
183          * Univ 13
184          * eth  14 - IRQ2
185          * PMC1 16 - IRQ9,10,11,12 = PMC A-D
186          * PMC2 17 - IRQ12,9,10,11 = PMC A-D
187          * PCIX 20 - IRQ9,10,11,12 = PMC A-D
188          */
189
190         /* 2300
191          * Raven 31
192          * ISA   11
193          * Univ  13
194          * eth   14 - IRQ2
195          * PMC1  16 - 9,10,11,12 = A-D
196          * PMC2  17 - 9,10,11,12 = B,C,D,A
197          */
198
199         static char pci_irq_table[][4] =
200             /*
201              *      MPIC interrupts for various IDSEL values (MPIC IRQ0 =
202              *      Linux IRQ16 (to leave room for ISA IRQs at 0-15).
203              *      PCI IDSEL/INTPIN->INTLINE
204              *         A   B   C   D
205              */
206         {
207                 {19,  0,  0,  0},       /* IDSEL 12 - SCSI   */
208                 { 0,  0,  0,  0},       /* IDSEL 13 - Universe PCI - VME */
209                 {18,  0,  0,  0},       /* IDSEL 14 - Enet 1 */
210                 { 0,  0,  0,  0},       /* IDSEL 15 - unused */
211                 {25, 26, 27, 28},       /* IDSEL 16 - PCI/PMC Slot 1P */
212                 {28, 25, 26, 27},       /* IDSEL 17 - PCI/PMC Slot 2P */
213                 {27, 28, 25, 26},       /* IDSEL 18 - PCI Slot 3P */
214                 {26,  0,  0,  0},       /* IDSEL 19 - Enet 2 */
215                 {25, 26, 27, 28}        /* IDSEL 20 - P2P Bridge */
216         };
217
218         const long min_idsel = 12, max_idsel = 20, irqs_per_slot = 4;
219         return PCI_IRQ_TABLE_LOOKUP;
220 }
221
222 #define MOTOROLA_CPUTYPE_REG    0x800
223 #define MOTOROLA_BASETYPE_REG   0x803
224 #define MPIC_RAVEN_ID           0x48010000
225 #define MPIC_HAWK_ID            0x48030000
226 #define MOT_PROC2_BIT           0x800
227
228 static u_char pplus_openpic_initsenses[] __initdata = {
229         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE), /* MVME2600_INT_SIO */
230         (IRQ_SENSE_EDGE | IRQ_POLARITY_NEGATIVE),/*MVME2600_INT_FALCN_ECC_ERR */
231         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),/*MVME2600_INT_PCI_ETHERNET */
232         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_SCSI */
233         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),/*MVME2600_INT_PCI_GRAPHICS */
234         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_VME0 */
235         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_VME1 */
236         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_VME2 */
237         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_VME3 */
238         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_INTA */
239         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_INTB */
240         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_INTC */
241         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_PCI_INTD */
242         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_LM_SIG0 */
243         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE), /* MVME2600_INT_LM_SIG1 */
244         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),
245 };
246
247 int mot_entry = -1;
248 int prep_keybd_present = 1;
249 int mot_multi = 0;
250
251 struct brd_info {
252         /* 0x100 mask assumes for Raven and Hawk boards that the level/edge
253          * are set */
254         int cpu_type;
255         /* 0x200 if this board has a Hawk chip. */
256         int base_type;
257         /* or'ed with 0x80 if this board should be checked for multi CPU */
258         int max_cpu;
259         const char *name;
260         int (*map_irq) (struct pci_dev *, unsigned char, unsigned char);
261 };
262 struct brd_info mot_info[] = {
263         {0x300, 0x00, 0x00, "MVME 2400", Genesis2_map_irq},
264         {0x1E0, 0xE0, 0x00, "Mesquite cPCI (MCP750)", mesquite_map_irq},
265         {0x1E0, 0xE1, 0x00, "Sitka cPCI (MCPN750)", sitka_map_irq},
266         {0x1E0, 0xE2, 0x00, "Mesquite cPCI (MCP750) w/ HAC", mesquite_map_irq},
267         {0x1E0, 0xF6, 0x80, "MTX Plus", MTXplus_map_irq},
268         {0x1E0, 0xF6, 0x81, "Dual MTX Plus", MTXplus_map_irq},
269         {0x1E0, 0xF7, 0x80, "MTX wo/ Parallel Port", MTX_map_irq},
270         {0x1E0, 0xF7, 0x81, "Dual MTX wo/ Parallel Port", MTX_map_irq},
271         {0x1E0, 0xF8, 0x80, "MTX w/ Parallel Port", MTX_map_irq},
272         {0x1E0, 0xF8, 0x81, "Dual MTX w/ Parallel Port", MTX_map_irq},
273         {0x1E0, 0xF9, 0x00, "MVME 2300", Genesis2_map_irq},
274         {0x1E0, 0xFA, 0x00, "MVME 2300SC/2600", Genesis2_map_irq},
275         {0x1E0, 0xFB, 0x00, "MVME 2600 with MVME712M", Genesis2_map_irq},
276         {0x1E0, 0xFC, 0x00, "MVME 2600/2700 with MVME761", Genesis2_map_irq},
277         {0x1E0, 0xFD, 0x80, "MVME 3600 with MVME712M", Genesis2_map_irq},
278         {0x1E0, 0xFD, 0x81, "MVME 4600 with MVME712M", Genesis2_map_irq},
279         {0x1E0, 0xFE, 0x80, "MVME 3600 with MVME761", Genesis2_map_irq},
280         {0x1E0, 0xFE, 0x81, "MVME 4600 with MVME761", Genesis2_map_irq},
281         {0x000, 0x00, 0x00, "", NULL}
282 };
283
284 void __init pplus_set_board_type(void)
285 {
286         unsigned char cpu_type;
287         unsigned char base_mod;
288         int entry;
289         unsigned short devid;
290         unsigned long *ProcInfo = NULL;
291
292         cpu_type = inb(MOTOROLA_CPUTYPE_REG) & 0xF0;
293         base_mod = inb(MOTOROLA_BASETYPE_REG);
294         early_read_config_word(0, 0, 0, PCI_VENDOR_ID, &devid);
295
296         for (entry = 0; mot_info[entry].cpu_type != 0; entry++) {
297                 /* Check for Hawk chip */
298                 if (mot_info[entry].cpu_type & 0x200) {
299                         if (devid != PCI_DEVICE_ID_MOTOROLA_HAWK)
300                                 continue;
301                 } else {
302                         /* store the system config register for later use. */
303                         ProcInfo =
304                             (unsigned long *)ioremap(PPLUS_SYS_CONFIG_REG, 4);
305
306                         /* Check non hawk boards */
307                         if ((mot_info[entry].cpu_type & 0xff) != cpu_type)
308                                 continue;
309
310                         if (mot_info[entry].base_type == 0) {
311                                 mot_entry = entry;
312                                 break;
313                         }
314
315                         if (mot_info[entry].base_type != base_mod)
316                                 continue;
317                 }
318
319                 if (!(mot_info[entry].max_cpu & 0x80)) {
320                         mot_entry = entry;
321                         break;
322                 }
323
324                 /* processor 1 not present and max processor zero indicated */
325                 if ((*ProcInfo & MOT_PROC2_BIT)
326                     && !(mot_info[entry].max_cpu & 0x7f)) {
327                         mot_entry = entry;
328                         break;
329                 }
330
331                 /* processor 1 present and max processor zero indicated */
332                 if (!(*ProcInfo & MOT_PROC2_BIT)
333                     && (mot_info[entry].max_cpu & 0x7f)) {
334                         mot_entry = entry;
335                         break;
336                 }
337
338                 /* Indicate to system if this is a multiprocessor board */
339                 if (!(*ProcInfo & MOT_PROC2_BIT))
340                         mot_multi = 1;
341         }
342
343         if (mot_entry == -1)
344                 /* No particular cpu type found - assume Mesquite (MCP750) */
345                 mot_entry = 1;
346
347         Motherboard_map_name = (unsigned char *)mot_info[mot_entry].name;
348         ppc_md.pci_map_irq = mot_info[mot_entry].map_irq;
349 }
350 void __init pplus_pib_init(void)
351 {
352         unsigned char reg;
353         unsigned short short_reg;
354
355         struct pci_dev *dev = NULL;
356
357         /*
358          * Perform specific configuration for the Via Tech or
359          * or Winbond PCI-ISA-Bridge part.
360          */
361         if ((dev = pci_get_device(PCI_VENDOR_ID_VIA,
362                                    PCI_DEVICE_ID_VIA_82C586_1, dev))) {
363                 /*
364                  * PPCBUG does not set the enable bits
365                  * for the IDE device. Force them on here.
366                  */
367                 pci_read_config_byte(dev, 0x40, &reg);
368
369                 reg |= 0x03;    /* IDE: Chip Enable Bits */
370                 pci_write_config_byte(dev, 0x40, reg);
371         }
372
373         if ((dev = pci_get_device(PCI_VENDOR_ID_VIA,
374                                    PCI_DEVICE_ID_VIA_82C586_2,
375                                    dev)) && (dev->devfn = 0x5a)) {
376                 /* Force correct USB interrupt */
377                 dev->irq = 11;
378                 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
379         }
380
381         if ((dev = pci_get_device(PCI_VENDOR_ID_WINBOND,
382                                    PCI_DEVICE_ID_WINBOND_83C553, dev))) {
383                 /* Clear PCI Interrupt Routing Control Register. */
384                 short_reg = 0x0000;
385                 pci_write_config_word(dev, 0x44, short_reg);
386                 /* Route IDE interrupts to IRQ 14 */
387                 reg = 0xEE;
388                 pci_write_config_byte(dev, 0x43, reg);
389         }
390
391         if ((dev = pci_get_device(PCI_VENDOR_ID_WINBOND,
392                                    PCI_DEVICE_ID_WINBOND_82C105, dev))) {
393                 /*
394                  * Disable LEGIRQ mode so PCI INTS are routed
395                  * directly to the 8259 and enable both channels
396                  */
397                 pci_write_config_dword(dev, 0x40, 0x10ff0033);
398
399                 /* Force correct IDE interrupt */
400                 dev->irq = 14;
401                 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
402         }
403         pci_dev_put(dev);
404 }
405
406 void __init pplus_set_VIA_IDE_legacy(void)
407 {
408         unsigned short vend, dev;
409
410         early_read_config_word(0, 0, PCI_DEVFN(0xb, 1), PCI_VENDOR_ID, &vend);
411         early_read_config_word(0, 0, PCI_DEVFN(0xb, 1), PCI_DEVICE_ID, &dev);
412
413         if ((vend == PCI_VENDOR_ID_VIA) &&
414                         (dev == PCI_DEVICE_ID_VIA_82C586_1)) {
415                 unsigned char temp;
416
417                 /* put back original "standard" port base addresses */
418                 early_write_config_dword(0, 0, PCI_DEVFN(0xb, 1),
419                                          PCI_BASE_ADDRESS_0, 0x1f1);
420                 early_write_config_dword(0, 0, PCI_DEVFN(0xb, 1),
421                                          PCI_BASE_ADDRESS_1, 0x3f5);
422                 early_write_config_dword(0, 0, PCI_DEVFN(0xb, 1),
423                                          PCI_BASE_ADDRESS_2, 0x171);
424                 early_write_config_dword(0, 0, PCI_DEVFN(0xb, 1),
425                                          PCI_BASE_ADDRESS_3, 0x375);
426                 early_write_config_dword(0, 0, PCI_DEVFN(0xb, 1),
427                                          PCI_BASE_ADDRESS_4, 0xcc01);
428
429                 /* put into legacy mode */
430                 early_read_config_byte(0, 0, PCI_DEVFN(0xb, 1), PCI_CLASS_PROG,
431                                        &temp);
432                 temp &= ~0x05;
433                 early_write_config_byte(0, 0, PCI_DEVFN(0xb, 1), PCI_CLASS_PROG,
434                                         temp);
435         }
436 }
437
438 void pplus_set_VIA_IDE_native(void)
439 {
440         unsigned short vend, dev;
441
442         early_read_config_word(0, 0, PCI_DEVFN(0xb, 1), PCI_VENDOR_ID, &vend);
443         early_read_config_word(0, 0, PCI_DEVFN(0xb, 1), PCI_DEVICE_ID, &dev);
444
445         if ((vend == PCI_VENDOR_ID_VIA) &&
446                         (dev == PCI_DEVICE_ID_VIA_82C586_1)) {
447                 unsigned char temp;
448
449                 /* put into native mode */
450                 early_read_config_byte(0, 0, PCI_DEVFN(0xb, 1), PCI_CLASS_PROG,
451                                        &temp);
452                 temp |= 0x05;
453                 early_write_config_byte(0, 0, PCI_DEVFN(0xb, 1), PCI_CLASS_PROG,
454                                         temp);
455         }
456 }
457
458 void __init pplus_pcibios_fixup(void)
459 {
460
461         unsigned char reg;
462         unsigned short devid;
463         unsigned char base_mod;
464
465         printk(KERN_INFO "Setting PCI interrupts for a \"%s\"\n",
466                         Motherboard_map_name);
467
468         /* Setup the Winbond or Via PIB */
469         pplus_pib_init();
470
471         /* Set up floppy in PS/2 mode */
472         outb(0x09, SIO_CONFIG_RA);
473         reg = inb(SIO_CONFIG_RD);
474         reg = (reg & 0x3F) | 0x40;
475         outb(reg, SIO_CONFIG_RD);
476         outb(reg, SIO_CONFIG_RD);       /* Have to write twice to change! */
477
478         /* This is a hack.  If this is a 2300 or 2400 mot board then there is
479          * no keyboard controller and we have to indicate that.
480          */
481
482         early_read_config_word(0, 0, 0, PCI_VENDOR_ID, &devid);
483         base_mod = inb(MOTOROLA_BASETYPE_REG);
484         if ((devid == PCI_DEVICE_ID_MOTOROLA_HAWK) ||
485             (base_mod == 0xF9) || (base_mod == 0xFA) || (base_mod == 0xE1))
486                 prep_keybd_present = 0;
487 }
488
489 void __init pplus_find_bridges(void)
490 {
491         struct pci_controller *hose;
492
493         hose = pcibios_alloc_controller();
494         if (!hose)
495                 return;
496
497         hose->first_busno = 0;
498         hose->last_busno = 0xff;
499
500         hose->pci_mem_offset = PREP_ISA_MEM_BASE;
501         hose->io_base_virt = (void *)PREP_ISA_IO_BASE;
502
503         pci_init_resource(&hose->io_resource, PPLUS_PCI_IO_START,
504                           PPLUS_PCI_IO_END, IORESOURCE_IO, "PCI host bridge");
505         pci_init_resource(&hose->mem_resources[0], PPLUS_PROC_PCI_MEM_START,
506                           PPLUS_PROC_PCI_MEM_END, IORESOURCE_MEM,
507                           "PCI host bridge");
508
509         hose->io_space.start = PPLUS_PCI_IO_START;
510         hose->io_space.end = PPLUS_PCI_IO_END;
511         hose->mem_space.start = PPLUS_PCI_MEM_START;
512         hose->mem_space.end = PPLUS_PCI_MEM_END - HAWK_MPIC_SIZE;
513
514         if (hawk_init(hose, PPLUS_HAWK_PPC_REG_BASE, PPLUS_PROC_PCI_MEM_START,
515                                 PPLUS_PROC_PCI_MEM_END - HAWK_MPIC_SIZE,
516                                 PPLUS_PROC_PCI_IO_START, PPLUS_PROC_PCI_IO_END,
517                                 PPLUS_PROC_PCI_MEM_END - HAWK_MPIC_SIZE + 1)
518                         != 0) {
519                 printk(KERN_CRIT "Could not initialize host bridge\n");
520
521         }
522
523         pplus_set_VIA_IDE_legacy();
524
525         hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
526
527         ppc_md.pcibios_fixup = pplus_pcibios_fixup;
528         ppc_md.pci_swizzle = common_swizzle;
529 }
530
531 static int pplus_show_cpuinfo(struct seq_file *m)
532 {
533         seq_printf(m, "vendor\t\t: Motorola MCG\n");
534         seq_printf(m, "machine\t\t: %s\n", Motherboard_map_name);
535
536         return 0;
537 }
538
539 static void __init pplus_setup_arch(void)
540 {
541         struct pci_controller *hose;
542
543         if (ppc_md.progress)
544                 ppc_md.progress("pplus_setup_arch: enter", 0);
545
546         /* init to some ~sane value until calibrate_delay() runs */
547         loops_per_jiffy = 50000000;
548
549         if (ppc_md.progress)
550                 ppc_md.progress("pplus_setup_arch: find_bridges", 0);
551
552         /* Setup PCI host bridge */
553         pplus_find_bridges();
554
555         hose = pci_bus_to_hose(0);
556         isa_io_base = (ulong) hose->io_base_virt;
557
558         if (ppc_md.progress)
559                 ppc_md.progress("pplus_setup_arch: set_board_type", 0);
560
561         pplus_set_board_type();
562
563         /* Enable L2.  Assume we don't need to flush -- Cort */
564         *(unsigned char *)(PPLUS_L2_CONTROL_REG) |= 3;
565
566 #ifdef CONFIG_BLK_DEV_INITRD
567         if (initrd_start)
568                 ROOT_DEV = Root_RAM0;
569         else
570 #endif
571 #ifdef CONFIG_ROOT_NFS
572                 ROOT_DEV = Root_NFS;
573 #else
574                 ROOT_DEV = Root_SDA2;
575 #endif
576
577         printk(KERN_INFO "Motorola PowerPlus Platform\n");
578         printk(KERN_INFO
579                "Port by MontaVista Software, Inc. (source@mvista.com)\n");
580
581 #ifdef CONFIG_VGA_CONSOLE
582         /* remap the VGA memory */
583         vgacon_remap_base = (unsigned long)ioremap(PPLUS_ISA_MEM_BASE,
584                                                    0x08000000);
585         conswitchp = &vga_con;
586 #endif
587 #ifdef CONFIG_PPCBUG_NVRAM
588         /* Read in NVRAM data */
589         init_prep_nvram();
590
591         /* if no bootargs, look in NVRAM */
592         if (cmd_line[0] == '\0') {
593                 char *bootargs;
594                 bootargs = prep_nvram_get_var("bootargs");
595                 if (bootargs != NULL) {
596                         strcpy(cmd_line, bootargs);
597                         /* again.. */
598                         strcpy(saved_command_line, cmd_line);
599                 }
600         }
601 #endif
602         if (ppc_md.progress)
603                 ppc_md.progress("pplus_setup_arch: exit", 0);
604 }
605
606 static void pplus_restart(char *cmd)
607 {
608         unsigned long i = 10000;
609
610         local_irq_disable();
611
612         /* set VIA IDE controller into native mode */
613         pplus_set_VIA_IDE_native();
614
615         /* set exception prefix high - to the prom */
616         _nmask_and_or_msr(0, MSR_IP);
617
618         /* make sure bit 0 (reset) is a 0 */
619         outb(inb(0x92) & ~1L, 0x92);
620         /* signal a reset to system control port A - soft reset */
621         outb(inb(0x92) | 1, 0x92);
622
623         while (i != 0)
624                 i++;
625         panic("restart failed\n");
626 }
627
628 static void pplus_halt(void)
629 {
630         /* set exception prefix high - to the prom */
631         _nmask_and_or_msr(MSR_EE, MSR_IP);
632
633         /* make sure bit 0 (reset) is a 0 */
634         outb(inb(0x92) & ~1L, 0x92);
635         /* signal a reset to system control port A - soft reset */
636         outb(inb(0x92) | 1, 0x92);
637
638         while (1) ;
639         /*
640          * Not reached
641          */
642 }
643
644 static void pplus_power_off(void)
645 {
646         pplus_halt();
647 }
648
649 static void __init pplus_init_IRQ(void)
650 {
651         int i;
652
653         if (ppc_md.progress)
654                 ppc_md.progress("init_irq: enter", 0);
655
656         OpenPIC_InitSenses = pplus_openpic_initsenses;
657         OpenPIC_NumInitSenses = sizeof(pplus_openpic_initsenses);
658
659         if (OpenPIC_Addr != NULL) {
660
661                 openpic_set_sources(0, 16, OpenPIC_Addr + 0x10000);
662                 openpic_init(NUM_8259_INTERRUPTS);
663                 openpic_hookup_cascade(NUM_8259_INTERRUPTS, "82c59 cascade",
664                                         i8259_irq);
665                 ppc_md.get_irq = openpic_get_irq;
666         }
667
668         i8259_init(0, 0);
669
670         if (ppc_md.progress)
671                 ppc_md.progress("init_irq: exit", 0);
672 }
673
674 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
675 /*
676  * IDE stuff.
677  */
678 static int pplus_ide_default_irq(unsigned long base)
679 {
680         switch (base) {
681         case 0x1f0:
682                 return 14;
683         case 0x170:
684                 return 15;
685         default:
686                 return 0;
687         }
688 }
689
690 static unsigned long pplus_ide_default_io_base(int index)
691 {
692         switch (index) {
693         case 0:
694                 return 0x1f0;
695         case 1:
696                 return 0x170;
697         default:
698                 return 0;
699         }
700 }
701
702 static void __init
703 pplus_ide_init_hwif_ports(hw_regs_t * hw, unsigned long data_port,
704                           unsigned long ctrl_port, int *irq)
705 {
706         unsigned long reg = data_port;
707         int i;
708
709         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
710                 hw->io_ports[i] = reg;
711                 reg += 1;
712         }
713
714         if (ctrl_port)
715                 hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
716         else
717                 hw->io_ports[IDE_CONTROL_OFFSET] =
718                     hw->io_ports[IDE_DATA_OFFSET] + 0x206;
719
720         if (irq != NULL)
721                 *irq = pplus_ide_default_irq(data_port);
722 }
723 #endif
724
725 #ifdef CONFIG_SMP
726 /* PowerPlus (MTX) support */
727 static int __init smp_pplus_probe(void)
728 {
729         extern int mot_multi;
730
731         if (mot_multi) {
732                 openpic_request_IPIs();
733                 smp_hw_index[1] = 1;
734                 return 2;
735         }
736
737         return 1;
738 }
739
740 static void __init smp_pplus_kick_cpu(int nr)
741 {
742         *(unsigned long *)KERNELBASE = nr;
743         asm volatile ("dcbf 0,%0"::"r" (KERNELBASE):"memory");
744         printk(KERN_INFO "CPU1 reset, waiting\n");
745 }
746
747 static void __init smp_pplus_setup_cpu(int cpu_nr)
748 {
749         if (OpenPIC_Addr)
750                 do_openpic_setup_cpu();
751 }
752
753 static struct smp_ops_t pplus_smp_ops = {
754         smp_openpic_message_pass,
755         smp_pplus_probe,
756         smp_pplus_kick_cpu,
757         smp_pplus_setup_cpu,
758         .give_timebase = smp_generic_give_timebase,
759         .take_timebase = smp_generic_take_timebase,
760 };
761 #endif                          /* CONFIG_SMP */
762
763 #ifdef DUMP_DBATS
764 static void print_dbat(int idx, u32 bat)
765 {
766
767         char str[64];
768
769         sprintf(str, "DBAT%c%c = 0x%08x\n",
770                 (char)((idx - DBAT0U) / 2) + '0', (idx & 1) ? 'L' : 'U', bat);
771         ppc_md.progress(str, 0);
772 }
773
774 #define DUMP_DBAT(x) \
775         do { \
776         u32 __temp = mfspr(x);\
777         print_dbat(x, __temp); \
778         } while (0)
779
780 static void dump_dbats(void)
781 {
782         if (ppc_md.progress) {
783                 DUMP_DBAT(DBAT0U);
784                 DUMP_DBAT(DBAT0L);
785                 DUMP_DBAT(DBAT1U);
786                 DUMP_DBAT(DBAT1L);
787                 DUMP_DBAT(DBAT2U);
788                 DUMP_DBAT(DBAT2L);
789                 DUMP_DBAT(DBAT3U);
790                 DUMP_DBAT(DBAT3L);
791         }
792 }
793 #endif
794
795 static unsigned long __init pplus_find_end_of_memory(void)
796 {
797         unsigned long total;
798
799         if (ppc_md.progress)
800                 ppc_md.progress("pplus_find_end_of_memory", 0);
801
802 #ifdef DUMP_DBATS
803         dump_dbats();
804 #endif
805
806         total = hawk_get_mem_size(PPLUS_HAWK_SMC_BASE);
807         return (total);
808 }
809
810 static void __init pplus_map_io(void)
811 {
812         io_block_mapping(PPLUS_ISA_IO_BASE, PPLUS_ISA_IO_BASE, 0x10000000,
813                          _PAGE_IO);
814         io_block_mapping(0xfef80000, 0xfef80000, 0x00080000, _PAGE_IO);
815 }
816
817 static void __init pplus_init2(void)
818 {
819 #ifdef CONFIG_NVRAM
820         request_region(PREP_NVRAM_AS0, 0x8, "nvram");
821 #endif
822         request_region(0x20, 0x20, "pic1");
823         request_region(0xa0, 0x20, "pic2");
824         request_region(0x00, 0x20, "dma1");
825         request_region(0x40, 0x20, "timer");
826         request_region(0x80, 0x10, "dma page reg");
827         request_region(0xc0, 0x20, "dma2");
828 }
829
830 /*
831  * Set BAT 2 to access 0x8000000 so progress messages will work and set BAT 3
832  * to 0xf0000000 to access Falcon/Raven or Hawk registers
833  */
834 static __inline__ void pplus_set_bat(void)
835 {
836         /* wait for all outstanding memory accesses to complete */
837         mb();
838
839         /* setup DBATs */
840         mtspr(SPRN_DBAT2U, 0x80001ffe);
841         mtspr(SPRN_DBAT2L, 0x8000002a);
842         mtspr(SPRN_DBAT3U, 0xf0001ffe);
843         mtspr(SPRN_DBAT3L, 0xf000002a);
844
845         /* wait for updates */
846         mb();
847 }
848
849 void __init
850 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
851               unsigned long r6, unsigned long r7)
852 {
853         parse_bootinfo(find_bootinfo());
854
855         /* Map in board regs, etc. */
856         pplus_set_bat();
857
858         isa_io_base = PREP_ISA_IO_BASE;
859         isa_mem_base = PREP_ISA_MEM_BASE;
860         pci_dram_offset = PREP_PCI_DRAM_OFFSET;
861         ISA_DMA_THRESHOLD = 0x00ffffff;
862         DMA_MODE_READ = 0x44;
863         DMA_MODE_WRITE = 0x48;
864         ppc_do_canonicalize_irqs = 1;
865
866         ppc_md.setup_arch = pplus_setup_arch;
867         ppc_md.show_cpuinfo = pplus_show_cpuinfo;
868         ppc_md.init_IRQ = pplus_init_IRQ;
869         /* this gets changed later on if we have an OpenPIC -- Cort */
870         ppc_md.get_irq = i8259_irq;
871         ppc_md.init = pplus_init2;
872
873         ppc_md.restart = pplus_restart;
874         ppc_md.power_off = pplus_power_off;
875         ppc_md.halt = pplus_halt;
876
877         TODC_INIT(TODC_TYPE_MK48T59, PREP_NVRAM_AS0, PREP_NVRAM_AS1,
878                   PREP_NVRAM_DATA, 8);
879
880         ppc_md.time_init = todc_time_init;
881         ppc_md.set_rtc_time = todc_set_rtc_time;
882         ppc_md.get_rtc_time = todc_get_rtc_time;
883         ppc_md.calibrate_decr = todc_calibrate_decr;
884         ppc_md.nvram_read_val = todc_m48txx_read_val;
885         ppc_md.nvram_write_val = todc_m48txx_write_val;
886
887         ppc_md.find_end_of_memory = pplus_find_end_of_memory;
888         ppc_md.setup_io_mappings = pplus_map_io;
889
890 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
891         ppc_ide_md.default_irq = pplus_ide_default_irq;
892         ppc_ide_md.default_io_base = pplus_ide_default_io_base;
893         ppc_ide_md.ide_init_hwif = pplus_ide_init_hwif_ports;
894 #endif
895
896 #ifdef CONFIG_SERIAL_TEXT_DEBUG
897         ppc_md.progress = gen550_progress;
898 #endif                          /* CONFIG_SERIAL_TEXT_DEBUG */
899 #ifdef CONFIG_KGDB
900         ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
901 #endif
902 #ifdef CONFIG_SMP
903         smp_ops = &pplus_smp_ops;
904 #endif                          /* CONFIG_SMP */
905 }