port more changes to make PCI work
[linux-2.4.git] / arch / ppc / platforms / sandpoint.c
1 /*
2  * arch/ppc/platforms/sandpoint.c
3  *
4  * Board setup routines for the Motorola SPS Sandpoint Test Platform.
5  *
6  * Author: Mark A. Greer
7  *         mgreer@mvista.com
8  *
9  * 2000-2003 (c) MontaVista, Software, Inc.  This file is licensed under
10  * the terms of the GNU General Public License version 2.  This program
11  * is licensed "as is" without any warranty of any kind, whether express
12  * or implied.
13  */
14
15 /*
16  * This file adds support for the Motorola SPS Sandpoint Test Platform.
17  * These boards have a PPMC slot for the processor so any combination
18  * of cpu and host bridge can be attached.  This port is for an 8240 PPMC
19  * module from Motorola SPS and other closely related cpu/host bridge
20  * combinations (e.g., 750/755/7400 with MPC107 host bridge).
21  * The sandpoint itself has a Windbond 83c553 (PCI-ISA bridge, 2 DMA ctlrs, 2
22  * cascaded 8259 interrupt ctlrs, 8254 Timer/Counter, and an IDE ctlr), a
23  * National 87308 (RTC, 2 UARTs, Keyboard & mouse ctlrs, and a floppy ctlr),
24  * and 4 PCI slots (only 2 of which are usable; the other 2 are keyed for 3.3V
25  * but are really 5V).
26  *
27  * The firmware on the sandpoint is called DINK (not my acronym :).  This port
28  * depends on DINK to do some basic initialization (e.g., initialize the memory
29  * ctlr) and to ensure that the processor is using MAP B (CHRP map).
30  *
31  * The switch settings for the Sandpoint board MUST be as follows:
32  *      S3: down
33  *      S4: up
34  *      S5: up
35  *      S6: down
36  *
37  * 'down' is in the direction from the PCI slots towards the PPMC slot;
38  * 'up' is in the direction from the PPMC slot towards the PCI slots.
39  * Be careful, the way the sandpoint board is installed in XT chasses will
40  * make the directions reversed.
41  *
42  * Since Motorola listened to our suggestions for improvement, we now have
43  * the Sandpoint X3 board.  All of the PCI slots are available, it uses
44  * the serial interrupt interface (just a hardware thing we need to
45  * configure properly).
46  *
47  * Use the default X3 switch settings.  The interrupts are then:
48  *              EPIC    Source
49  *                0     SIOINT          (8259, active low)
50  *                1     PCI #1
51  *                2     PCI #2
52  *                3     PCI #3
53  *                4     PCI #4
54  *                7     Winbond INTC    (IDE interrupt)
55  *                8     Winbond INTD    (IDE interrupt)
56  *
57  * It is important to note that this code only supports the Sandpoint X3
58  * (all flavors) platform, and it does not support the X2 anymore.  Code
59  * that at one time worked on the X2 can be found at:
60  * ftp://source.mvista.com/pub/linuxppc/obsolete/sandpoint/
61  */
62 #include <linux/config.h>
63 #include <linux/stddef.h>
64 #include <linux/kernel.h>
65 #include <linux/init.h>
66 #include <linux/errno.h>
67 #include <linux/reboot.h>
68 #include <linux/pci.h>
69 #include <linux/kdev_t.h>
70 #include <linux/major.h>
71 #include <linux/blk.h>
72 #include <linux/console.h>
73 #include <linux/delay.h>
74 #include <linux/irq.h>
75 #include <linux/ide.h>
76 #include <linux/irq.h>
77 #include <linux/seq_file.h>
78 #include <linux/serial.h>
79
80 #include <asm/system.h>
81 #include <asm/pgtable.h>
82 #include <asm/page.h>
83 #include <asm/time.h>
84 #include <asm/dma.h>
85 #include <asm/io.h>
86 #include <asm/machdep.h>
87 #include <asm/prom.h>
88 #include <asm/smp.h>
89 #include <asm/keyboard.h>
90 #include <asm/vga.h>
91 #include <asm/open_pic.h>
92 #include <asm/i8259.h>
93 #include <asm/todc.h>
94 #include <asm/bootinfo.h>
95 #include <asm/mpc10x.h>
96 #include <asm/pci-bridge.h>
97 #include <asm/ppcboot.h>
98
99 #include "sandpoint_serial.h"
100
101 #include "sandpoint.h"
102
103 //#define SYS_266 1
104 #define SYS_200 1
105 //#define SYS_166 1
106
107 //REX:
108 #if 0
109 extern int pckbd_setkeycode(unsigned int scancode, unsigned int keycode);
110 extern int pckbd_getkeycode(unsigned int scancode);
111 extern int pckbd_translate(unsigned char scancode, unsigned char *keycode,
112                            char raw_mode);
113 extern char pckbd_unexpected_up(unsigned char keycode);
114 extern void pckbd_leds(unsigned char leds);
115 extern void pckbd_init_hw(void);
116 extern unsigned char pckbd_sysrq_xlate[128];
117 #endif 
118
119 extern void gen550_progress(char *, unsigned short);
120 extern void gen550_init(int, struct serial_struct *);
121
122 unsigned char __res[sizeof (bd_t)];
123
124 static void sandpoint_halt(void);
125
126 #ifdef CONFIG_SERIAL_TEXT_DEBUG
127 #include <linux/serial.h>
128 #include <linux/serialP.h>
129 #include <linux/serial_reg.h>
130 #include <asm/serial.h>
131
132 static struct serial_state rs_table[RS_TABLE_SIZE] = {
133         SERIAL_PORT_DFNS        /* Defined in <asm/serial.h> */
134 };
135
136 #endif
137
138 /*
139  * Define all of the IRQ senses and polarities.  Taken from the
140  * Sandpoint X3 User's manual.
141  */
142 static u_char sandpoint_openpic_initsenses[] __initdata = {
143 // REX
144 #if 0
145         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 0: SIOINT */
146         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 2: PCI Slot 1 */
147         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 3: PCI Slot 2 */
148         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 4: PCI Slot 3 */
149         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 5: PCI Slot 4 */
150         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 8: IDE (INT C) */
151         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE)       /* 9: IDE (INT D) */
152 #else
153         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 17, EPIC IRQ 1 - PCI1 - flash*/
154         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 18, EPIC IRQ 2 - LAN*/
155         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 19, EPIC IRQ 3 - Not used*/
156         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* 20, EPIC IRQ 4 - Not used*/
157         1
158 #endif
159 };
160
161 /*
162  * Motorola SPS Sandpoint interrupt routing.
163  */
164 #if 0 //REX: by MUSENKI
165 static inline int
166 sandpoint_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
167 {
168         static char pci_irq_table[][4] =
169         /*
170          *      PCI IDSEL/INTPIN->INTLINE 
171          *         A   B   C   D
172          */
173         {
174                 { SANDPOINT_SIO_IRQ,
175                        0,  0,  0 },     /* IDSEL 11 - i8259 on Winbond */
176                 {  0,  0,  0,  0 },     /* IDSEL 12 - unused */
177 #ifdef CONFIG_SANDPOINT_X3
178                { 17, 18, 19, 20 },     /* IDSEL 13 - PCI slot 1 */
179                { 18, 19, 20, 17 },     /* IDSEL 14 - PCI slot 2 */
180                { 19, 20, 17, 18 },     /* IDSEL 15 - PCI slot 3 */
181                { 20, 17, 18, 19 },     /* IDSEL 16 - PCI slot 4 */
182 #else
183                 { 16, 19, 18, 17 },     /* IDSEL 13 - PCI slot 1 */
184                 { 17, 16, 19, 18 },     /* IDSEL 14 - PCI slot 2 */
185                 { 18, 17, 16, 19 },     /* IDSEL 15 - PCI slot 3 */
186                 { 19, 18, 17, 16 },     /* IDSEL 16 - PCI slot 4 */
187 #endif
188         };
189
190         const long min_idsel = 11, max_idsel = 16, irqs_per_slot = 4;
191         return PCI_IRQ_TABLE_LOOKUP;
192 }
193 #endif
194 #if 0           //+Bing modified 11252004
195 static inline int
196 sandpoint_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
197 {
198         static char pci_irq_table[][4] =
199         /*
200          *      PCI IDSEL/INTPIN->INTLINE 
201          *         A   B   C   D
202          */
203         {
204                 {   3,  0,  0,  0 },    /* IDSEL 17 - disable */
205                 {   0,  0,  0,  0 },    /* IDSEL 18 - PCI slot1*/
206                 {   2,  0,  0,  0 },    /* IDSEL 19 - LAN 83815 */
207                 {   1,  0,  4,  0 }     /* IDSEL 20 - PCI slot2 */
208         };
209
210         const long min_idsel = 17, max_idsel = 20, irqs_per_slot = 4;
211         return PCI_IRQ_TABLE_LOOKUP;
212 }
213 #else
214 static inline int
215 sandpoint_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
216 {
217         static char pci_irq_table[][4] =
218         /*
219          *      PCI IDSEL/INTPIN->INTLINE 
220          *         A   B   C   D
221          */
222         {
223                 {   0,  0,  0,  0 },    /* IDSEL 13 - mini-PCI */
224                 {   1,  -1,  2,  0 },    /* IDSEL 14 - NEC USB2.0 */
225                 {   3,  0,  0,  0 },    /* IDSEL 15 - ADM983 */
226                 {   4,  0,  0,  0 }
227         };
228
229         const long min_idsel = 13, max_idsel = 16, irqs_per_slot = 4;
230         return PCI_IRQ_TABLE_LOOKUP;
231 }
232 #endif  //+Bing modified 11252004
233
234
235 #if 0 //REX
236 static void __init
237 sandpoint_setup_winbond_83553(struct pci_controller *hose)
238 {
239         int devfn;
240
241         /*
242          * Route IDE interrupts directly to the 8259's IRQ 14 & 15.
243          * We can't route the IDE interrupt to PCI INTC# or INTD# because those
244          * woule interfere with the PMC's INTC# and INTD# lines.
245          */
246         /*
247          * Winbond Fcn 0
248          */
249         devfn = PCI_DEVFN(11, 0);
250
251         /* IDE Interrupt Routing Control */
252         early_write_config_byte(hose, 0, devfn, 0x43, 0xef);
253
254         /* PCI Interrupt Routing Control */
255         early_write_config_word(hose, 0, devfn, 0x44, 0x0000);
256
257         /* Want ISA memory cycles to be forwarded to PCI bus.
258          * ISA-to-PCI Addr Decoder Control.
259          */
260         early_write_config_byte(hose, 0, devfn, 0x48, 0xf0);
261
262         /* Enable RTC and Keyboard address locations. */
263         early_write_config_byte(hose, 0, devfn, 0x4d, 0x00);
264
265         /* Enable Port 92.  */
266         early_write_config_byte(hose, 0, devfn, 0x4e, 0x06);
267
268         /*
269          * Winbond Fcn 1
270          */
271         devfn = PCI_DEVFN(11, 1);
272
273         /* Put IDE controller into native mode (via PIR). */
274         early_write_config_byte(hose, 0, devfn, 0x09, 0x8f);
275
276         /* Init IRQ routing, enable both ports, disable fast 16, via
277          * IDE Control/Status Register.
278          */
279         early_write_config_dword(hose, 0, devfn, 0x40, 0x00ff0011);
280 }
281 #endif
282
283 #ifndef CONFIG_SANDPOINT_X3
284 /* On the sandpoint X2, we must avoid sending configuration cycles to
285  * device #12 (IDSEL addr = AD12).
286  */
287 static int                     
288 sandpoint_exclude_device(u_char bus, u_char devfn)
289 {
290 #if 0
291         if ((bus == 0) && (PCI_SLOT(devfn) == SANDPOINT_HOST_BRIDGE_IDSEL))
292                 return PCIBIOS_DEVICE_NOT_FOUND;
293         else
294                 return PCIBIOS_SUCCESSFUL;
295 #endif
296 #ifdef REX_DBG_PCI
297         printk("REX_DBG_PCI: dev-fun is %X:%X.\n",PCI_SLOT(devfn), PCI_FUNC(devfn));
298 #endif  
299         if ((bus == 0) && (PCI_SLOT(devfn) == SANDPOINT_HOST_BRIDGE_IDSEL))
300         {
301                 return PCIBIOS_DEVICE_NOT_FOUND;
302         }
303         else
304         {
305                 return PCIBIOS_SUCCESSFUL;
306         }       
307
308 }
309 #endif
310
311 static void __init
312 sandpoint_find_bridges(void)
313 {
314         struct pci_controller *hose;
315
316         hose = pcibios_alloc_controller();
317
318         if (!hose)
319                 return;
320
321         hose->first_busno = 0;
322         hose->last_busno = 0xff;
323
324 //REX
325 #if 0
326         if (mpc10x_bridge_init(hose,
327                                MPC10X_MEM_MAP_B,
328                                MPC10X_MEM_MAP_B, MPC10X_MAPB_EUMB_BASE) == 0) {
329 #endif
330         if (mpc10x_bridge_init(hose,
331                                MPC10X_MEM_MAP_B,
332                                MPC10X_MEM_MAP_B,
333                                0xfc000000) == 0) {
334
335                 /* Do early winbond init, then scan PCI bus */
336                 //sandpoint_setup_winbond_83553(hose);
337 #ifndef CONFIG_SANDPOINT_X3
338                 ppc_md.pci_exclude_device = sandpoint_exclude_device;
339 #endif
340                 hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
341
342                 ppc_md.pcibios_fixup = NULL;
343                 ppc_md.pcibios_fixup_bus = NULL;
344                 ppc_md.pci_swizzle = common_swizzle;
345                 ppc_md.pci_map_irq = sandpoint_map_irq;
346         } else {
347                 if (ppc_md.progress)
348                         ppc_md.progress("Bridge init failed", 0x100);
349                 printk("Host bridge init failed\n");
350         }
351
352         return;
353 }
354
355 #ifdef CONFIG_SERIAL
356 static void __init
357 sandpoint_early_serial_map(void)
358 {
359         struct serial_struct serial_req;
360
361         /* Setup serial port access */
362         memset(&serial_req, 0, sizeof (serial_req));
363         serial_req.baud_base = BASE_BAUD;
364         serial_req.line = 0;
365         serial_req.port = 0;
366         serial_req.irq = 4;
367         serial_req.flags = ASYNC_BOOT_AUTOCONF;
368         serial_req.io_type = SERIAL_IO_MEM;
369         serial_req.iomem_base = (u_char *) SANDPOINT_SERIAL_0;
370         serial_req.iomem_reg_shift = 0;
371
372 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
373         gen550_init(0, &serial_req);
374 #endif
375
376         if (early_serial_setup(&serial_req) != 0)
377                 printk("Early serial init of port 0 failed\n");
378
379         /* Assume early_serial_setup() doesn't modify serial_req */
380         serial_req.line = 1;
381         serial_req.port = 1;
382         serial_req.irq = 3;     /* XXXX */
383         serial_req.iomem_base = (u_char *) SANDPOINT_SERIAL_1;
384
385 #if defined(CONFIG_SERIAL_TEXT_DEBUG) || defined(CONFIG_KGDB)
386         gen550_init(1, &serial_req);
387 #endif
388
389         if (early_serial_setup(&serial_req) != 0)
390                 printk("Early serial init of port 1 failed\n");
391 }
392 #endif
393
394 static void __init
395 sandpoint_setup_arch(void)
396 {
397         loops_per_jiffy = 100000000 / HZ;
398
399 #ifdef CONFIG_BLK_DEV_INITRD
400         if (initrd_start)
401                 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
402         else
403 #endif
404 #ifdef  CONFIG_ROOT_NFS
405                 ROOT_DEV = to_kdev_t(0x00FF);   /* /dev/nfs pseudo device */
406 #else
407                 ROOT_DEV = to_kdev_t(0x0301);   /* /dev/hda1 IDE disk */
408 #endif
409
410         /* Lookup PCI host bridges */
411         sandpoint_find_bridges();
412
413 #ifdef CONFIG_SERIAL
414         sandpoint_early_serial_map();
415 #endif
416
417 #ifdef CONFIG_DUMMY_CONSOLE
418         conswitchp = &dummy_con;
419 #endif
420
421         printk(KERN_INFO "Motorola SPS Sandpoint Test Platform\n");
422
423         /* DINK32 12.3 and below do not correctly enable any caches.
424          * We will do this now with good known values.  Future versions
425          * of DINK32 are supposed to get this correct.
426          */
427         if (cur_cpu_spec[0]->cpu_features & CPU_FTR_SPEC7450)
428                 /* 745x is different.  We only want to pass along enable. */
429                 _set_L2CR(L2CR_L2E);
430         else if (cur_cpu_spec[0]->cpu_features & CPU_FTR_L2CR)
431                 /* All modules have 1MB of L2.  We also assume that an
432                  * L2 divisor of 3 will work.
433                  */
434                 _set_L2CR(L2CR_L2E | L2CR_L2SIZ_1MB | L2CR_L2CLK_DIV3
435                           | L2CR_L2RAM_PIPE | L2CR_L2OH_1_0 | L2CR_L2DF);
436 #if 0
437         /* Untested right now. */
438         if (cur_cpu_spec[0]->cpu_features & CPU_FTR_L3CR) {
439                 /* Magic value. */
440                 _set_L3CR(0x8f032000);
441         }
442 #endif
443 }
444 #if 0 //REX:
445 #define SANDPOINT_87308_CFG_ADDR                0x15c
446 #define SANDPOINT_87308_CFG_DATA                0x15d
447
448 #define SANDPOINT_87308_CFG_INB(addr, byte) {                           \
449         outb((addr), SANDPOINT_87308_CFG_ADDR);                         \
450         (byte) = inb(SANDPOINT_87308_CFG_DATA);                         \
451 }
452
453 #define SANDPOINT_87308_CFG_OUTB(addr, byte) {                          \
454         outb((addr), SANDPOINT_87308_CFG_ADDR);                         \
455         outb((byte), SANDPOINT_87308_CFG_DATA);                         \
456 }
457
458 #define SANDPOINT_87308_SELECT_DEV(dev_num) {                           \
459         SANDPOINT_87308_CFG_OUTB(0x07, (dev_num));                      \
460 }
461
462 #define SANDPOINT_87308_DEV_ENABLE(dev_num) {                           \
463         SANDPOINT_87308_SELECT_DEV(dev_num);                            \
464         SANDPOINT_87308_CFG_OUTB(0x30, 0x01);                           \
465 }
466
467 /*
468  * Initialize the ISA devices on the Nat'l PC87308VUL SuperIO chip.
469  */
470 static void __init
471 sandpoint_setup_natl_87308(void)
472 {
473         u_char reg;
474
475         /*
476          * Enable all the devices on the Super I/O chip.
477          */
478         SANDPOINT_87308_SELECT_DEV(0x00);       /* Select kbd logical device */
479         SANDPOINT_87308_CFG_OUTB(0xf0, 0x00);   /* Set KBC clock to 8 Mhz */
480         SANDPOINT_87308_DEV_ENABLE(0x00);       /* Enable keyboard */
481         SANDPOINT_87308_DEV_ENABLE(0x01);       /* Enable mouse */
482         SANDPOINT_87308_DEV_ENABLE(0x02);       /* Enable rtc */
483         SANDPOINT_87308_DEV_ENABLE(0x03);       /* Enable fdc (floppy) */
484         SANDPOINT_87308_DEV_ENABLE(0x04);       /* Enable parallel */
485         SANDPOINT_87308_DEV_ENABLE(0x05);       /* Enable UART 2 */
486         SANDPOINT_87308_CFG_OUTB(0xf0, 0x82);   /* Enable bank select regs */
487         SANDPOINT_87308_DEV_ENABLE(0x06);       /* Enable UART 1 */
488         SANDPOINT_87308_CFG_OUTB(0xf0, 0x82);   /* Enable bank select regs */
489
490         /* Set up floppy in PS/2 mode */
491         outb(0x09, SIO_CONFIG_RA);
492         reg = inb(SIO_CONFIG_RD);
493         reg = (reg & 0x3F) | 0x40;
494         outb(reg, SIO_CONFIG_RD);
495         outb(reg, SIO_CONFIG_RD);       /* Have to write twice to change! */
496
497         return;
498 }
499
500 /*
501  * Fix IDE interrupts.
502  */
503 static void __init
504 sandpoint_fix_winbond_83553(void)
505 {
506         /* Make all 8259 interrupt level sensitive */
507         outb(0xf8, 0x4d0);
508         outb(0xde, 0x4d1);
509
510         return;
511 }
512 #endif //REX:
513
514 static void __init
515 sandpoint_init2(void)
516 {
517         /* Do Sandpoint board specific initialization.  */
518 #if 0   
519         sandpoint_fix_winbond_83553();
520         sandpoint_setup_natl_87308();
521
522         request_region(0x00, 0x20, "dma1");
523         request_region(0x20, 0x20, "pic1");
524         request_region(0x40, 0x20, "timer");
525         request_region(0x80, 0x10, "dma page reg");
526         request_region(0xa0, 0x20, "pic2");
527         request_region(0xc0, 0x20, "dma2");
528 #endif //REX:
529         return;
530 }
531
532 /*
533  * Interrupt setup and service.  The i8259 is cascaded from EPIC IRQ0,
534  * IRQ1-4 map to PCI slots 1-4, IDE is on EPIC 7 and 8.
535  */
536 static void __init
537 sandpoint_init_IRQ(void)
538 {
539         int i;
540
541         OpenPIC_InitSenses = sandpoint_openpic_initsenses;
542         OpenPIC_NumInitSenses = sizeof (sandpoint_openpic_initsenses);
543
544         /*
545          * We need to tell openpic_set_sources where things actually are.
546          * mpc10x_common will setup OpenPIC_Addr at ioremap(EUMB phys base +
547          * EPIC offset (0x40000));  The EPIC IRQ Register Address Map -
548          * Interrupt Source Configuration Registers gives these numbers
549          * as offsets starting at 0x50200, we need to adjust occordinly.
550          */
551
552 #if 1
553 #ifdef CONFIG_SANDPOINT_X3
554 //REX
555         /* Map serial interrupt 0 */
556         openpic_set_sources(0, 1, OpenPIC_Addr + 0x10200);
557         /* Map serial interrupts 2-5 */
558         openpic_set_sources(1, 4, OpenPIC_Addr + 0x10240);
559         /* Map serial interrupts 8-9 */
560         openpic_set_sources(5, 2, OpenPIC_Addr + 0x10300);
561         /* Skip reserved space and map i2c and DMA Ch[01] */
562         openpic_set_sources(7, 3, OpenPIC_Addr + 0x11020);
563         /* Skip reserved space and map Message Unit Interrupt (I2O) */
564         openpic_set_sources(10, 1, OpenPIC_Addr + 0x110C0);
565
566         openpic_set_sources(0, 138, NULL);
567 #else
568         /* Map EPIC IRQs 0-3 */
569         openpic_set_sources(0, 5, OpenPIC_Addr + 0x10200);
570         /* Skip reserved space and map i2c and DMA Ch[01] */
571         openpic_set_sources(113, 3, OpenPIC_Addr + 0x11020);
572         /* Skip reserved space and map Message Unit Interrupt (I2O) */
573         openpic_set_sources(118, 1, OpenPIC_Addr + 0x110C0);
574         //REX: UART
575         openpic_set_sources(121, 1, OpenPIC_Addr + 0x11120); //ttyS0
576         
577         openpic_set_sources(122, 1, OpenPIC_Addr + 0x11140);    //ttyS1 jackl
578 #endif
579 #endif  
580 #if 1 //REX:
581 #if 0//by Musenki, cause it will panic!
582         openpic_set_sources(0, 32, NULL);
583         openpic_set_sources(129, 3, NULL);//I2C
584         openpic_set_sources(134, 1, NULL);//Mesg
585         openpic_set_sources(137, 2, NULL);//DUART
586 #endif  
587         //openpic_init(1, 0, 0, -1);
588         openpic_init(0);
589         /* The cascade is either on EPIC IRQ 1 or 2 on an X2 or on X3 it's
590          * on EPIC IRQ 0.
591          */
592         //openpic_hookup_cascade(SANDPOINT_SIO_IRQ, "8259 cascade to EPIC",
593         //              &i8259_irq);
594
595         /*
596          * openpic_init() has set up irq_desc[0-23] to be openpic
597          * interrupts.  We need to set irq_desc[0-15] to be 8259 interrupts.
598          * We then need to request and enable the 8259 irq.
599          */
600         //for (i = 0; i < NUM_8259_INTERRUPTS; i++)
601         //      irq_desc[i].handler = &i8259_pic;
602
603         /*
604          * The EPIC allows for a read in the range of 0xFEF00000 ->
605          * 0xFEFFFFFF to generate a PCI interrupt-acknowledge transaction.
606          */
607         //i8259_init(0xfef00000);
608 #endif //REX:   
609 }
610
611 /*
612  * Because the Sandpoint X2 has the i8259 cascade sharing an IRQ with a
613  * PCI device, if we have a possible cascade IRQ we need to see if the
614  * i8259 has something pending.  The only issue here is that the cascade
615  * IRQs will get a higher priority than an OpenPIC one, but this should be
616  * OK.
617  */
618 static int
619 sandpoint_get_irq(struct pt_regs *regs)
620 {
621         int irq, cascade_irq;
622
623         irq = openpic_irq();
624         //REX:
625 #if 0
626         if ((irq != 127)&&(irq != 2)&&(irq!=121))
627                 printk("sandpoint_get_irq: irq = %d\n", irq);
628 #endif  
629         //if (irq == SANDPOINT_SIO_IRQ) 
630         //REX:
631         if (0)
632         {
633                 cascade_irq = i8259_irq(regs);
634
635                 if (cascade_irq != -1) {
636                         irq = cascade_irq;
637                         openpic_eoi();
638                 }
639         } else if (irq == OPENPIC_VEC_SPURIOUS) 
640                 irq = -1;
641
642         return irq;
643 }
644 //REX:
645 #if 0
646 static u32
647 sandpoint_irq_cannonicalize(u32 irq)
648 {
649         if (irq == 2)
650                 return 9;
651         else
652                 return irq;
653 }
654 #endif
655
656 static unsigned long __init
657 sandpoint_find_end_of_memory(void)
658 {
659         bd_t *bp = (bd_t *) __res;
660
661         if (bp->bi_memsize)
662         {
663         //REX:  
664                 printk("Total memory %d MB.\n", bp->bi_memsize);
665                 return bp->bi_memsize;
666         }
667
668         /* This might be fixed in DINK32 12.4, or we'll have another
669          * way to determine the correct memory size anyhow. */
670         /* return mpc10x_get_mem_size(MPC10X_MEM_MAP_B); */
671         return 32 * 1024 * 1024;
672 }
673
674 static void __init
675 sandpoint_map_io(void)
676 {
677         io_block_mapping(0xfc000000, 0xfc000000, 0x04000000, _PAGE_IO);
678         //REX:
679         //rs_table[0].iomem_base = ioremap_base - 0x100000 + 0x4500; 
680 }
681
682 /*
683  * Due to Sandpoint X2 errata, the Port 92 will not work.
684  */
685 static void
686 sandpoint_restart(char *cmd)
687 {
688         ulong msr, addr;
689         //printk("Jumping to start address...\n");
690
691         __cli();
692 //REX:
693 #if 1
694         /* Set exception prefix high - to the firmware */
695         _nmask_and_or_msr(0, MSR_IP);
696
697         /* Reset system via Port 92 */
698         //outb(0x00, 0x92);
699         //outb(0x01, 0x92);
700 #endif
701
702         /* Interrupts and MMU off */
703         __asm__ ("mtspr    81, 0");
704
705         /* Interrupts and MMU off */
706         __asm__ __volatile__ ("mfmsr    %0":"=r" (msr):);
707
708         msr &= ~0x1030;
709         __asm__ __volatile__ ("mtmsr    %0"::"r" (msr));        
710         /*
711          *          * Trying to execute the next instruction at a non-existing address
712          *          * should cause a machine check, resulting in reset
713          **/
714                 addr = 0xFFF00100;
715         ((void (*)(void)) addr) ();
716         for (;;) ;              /* Spin until reset happens */
717 }
718
719 static void
720 sandpoint_power_off(void)
721 {
722         __cli();
723         for (;;) ;              /* No way to shut power off with software */
724         /* NOTREACHED */
725 }
726
727 static void
728 sandpoint_halt(void)
729 {
730         sandpoint_power_off();
731         /* NOTREACHED */
732 }
733
734 static int
735 sandpoint_show_cpuinfo(struct seq_file *m)
736 {
737         seq_printf(m, "vendor\t\t: Motorola SPS\n");
738         seq_printf(m, "machine\t\t: Sandpoint\n");
739
740         return 0;
741 }
742 #if 0 //REX:
743 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
744 /*
745  * IDE support.
746  */
747 static int sandpoint_ide_ports_known = 0;
748 static ide_ioreg_t sandpoint_ide_regbase[MAX_HWIFS];
749 static ide_ioreg_t sandpoint_ide_ctl_regbase[MAX_HWIFS];
750 static ide_ioreg_t sandpoint_idedma_regbase;
751
752 static void
753 sandpoint_ide_probe(void)
754 {
755         struct pci_dev *pdev = pci_find_device(PCI_VENDOR_ID_WINBOND,
756                                                PCI_DEVICE_ID_WINBOND_82C105,
757                                                NULL);
758
759         if (pdev) {
760                 sandpoint_ide_regbase[0] = pdev->resource[0].start;
761                 sandpoint_ide_regbase[1] = pdev->resource[2].start;
762                 sandpoint_ide_ctl_regbase[0] = pdev->resource[1].start;
763                 sandpoint_ide_ctl_regbase[1] = pdev->resource[3].start;
764                 sandpoint_idedma_regbase = pdev->resource[4].start;
765         }
766
767         sandpoint_ide_ports_known = 1;
768         return;
769 }
770
771 /* The Sandpoint X3 allows the IDE interrupt to be directly connected
772  * from the Windbond (PCI INTC or INTD) to the serial EPIC.  Someday
773  * we should try this, but it was easier to use the existing 83c553
774  * initialization than change it to route the different interrupts :-).
775  *      -- Dan
776  */
777 #if 0
778 #define SANDPOINT_IDE_INT0      23      /* EPIC 7 */
779 #define SANDPOINT_IDE_INT1      24      /* EPIC 8 */
780 #else
781 #define SANDPOINT_IDE_INT0      14      /* 8259 Test */
782 #define SANDPOINT_IDE_INT1      15      /* 8259 Test */
783 #endif
784 static int
785 sandpoint_ide_default_irq(ide_ioreg_t base)
786 {
787         if (sandpoint_ide_ports_known == 0)
788                 sandpoint_ide_probe();
789
790         if (base == sandpoint_ide_regbase[0])
791                 return SANDPOINT_IDE_INT0;
792         else if (base == sandpoint_ide_regbase[1])
793                 return SANDPOINT_IDE_INT1;
794         else
795                 return 0;
796 }
797
798 static ide_ioreg_t
799 sandpoint_ide_default_io_base(int index)
800 {
801         if (sandpoint_ide_ports_known == 0)
802                 sandpoint_ide_probe();
803
804         return sandpoint_ide_regbase[index];
805 }
806
807 static void __init
808 sandpoint_ide_init_hwif_ports(hw_regs_t * hw, ide_ioreg_t data_port,
809                               ide_ioreg_t ctrl_port, int *irq)
810 {
811         ide_ioreg_t reg = data_port;
812         unsigned int alt_status_base;
813         int i;
814
815         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
816                 hw->io_ports[i] = reg++;
817
818         if (data_port == sandpoint_ide_regbase[0]) {
819                 alt_status_base = sandpoint_ide_ctl_regbase[0] + 2;
820                 hw->irq = 14;
821         } else if (data_port == sandpoint_ide_regbase[1]) {
822                 alt_status_base = sandpoint_ide_ctl_regbase[1] + 2;
823                 hw->irq = 15;
824         } else {
825                 alt_status_base = 0;
826                 hw->irq = 0;
827         }
828
829         if (ctrl_port)
830                 hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
831         else
832                 hw->io_ports[IDE_CONTROL_OFFSET] = alt_status_base;
833
834         if (irq != NULL)
835                 *irq = hw->irq;
836
837         return;
838 }
839 #endif
840 #endif //REX:
841
842 /*
843  * Set BAT 3 to map 0xf8000000 to end of physical memory space 1-to-1.
844  */
845 static __inline__ void
846 sandpoint_set_bat(void)
847 {
848 //REX:
849 #if 0
850         mb();
851         mtspr(DBAT1U, 0xf8000ffe);
852         mtspr(DBAT1L, 0xf800002a);
853         mb();
854         unsigned long bat3u, bat3l;
855
856         __asm__ __volatile__(" lis %0,0xf800\n  \
857                         ori %1,%0,0x002a\n      \
858                         ori %0,%0,0x0ffe\n      \
859                         mtspr 0x21e,%0\n        \
860                         mtspr 0x21f,%1\n        \
861                         isync\n                 \
862                         sync ":"=r"(bat3u), "=r"(bat3l));
863 #endif
864         unsigned long bat3u, bat3l;
865
866         __asm__ __volatile__(
867                         " lis %0,0xf000\n       \
868                         ori %1,%0,0x002a\n      \
869                         ori %0,%0,0x1fff\n      \
870                         mtspr 0x21e,%0\n        \
871                         mtspr 0x21f,%1\n        \
872                         isync\n                 \
873                         sync "
874                         : "=r" (bat3u), "=r" (bat3l));
875         
876         
877 }
878
879 #ifdef CONFIG_SERIAL_TEXT_DEBUG
880 #include <linux/serial.h>
881 #include <linux/serialP.h>
882 #include <linux/serial_reg.h>
883 #include <asm/serial.h>
884
885
886 volatile unsigned char *com_port;
887 volatile unsigned char *com_port_lsr;
888
889 static void
890 serial_writechar(char c)
891 {
892         while ((*com_port_lsr & UART_LSR_THRE) == 0)
893                 ;
894         *com_port = c;
895 }
896
897 void
898 sandpoint_progress(char *s, unsigned short hex)
899 {
900         volatile char c;
901
902         //jackl
903         com_port = (volatile unsigned char *) rs_table[0].port;
904         //com_port = (volatile unsigned char *) rs_table[1].port;  //jackl
905         com_port_lsr = com_port + UART_LSR;
906
907         while ((c = *s++) != 0)
908                 serial_writechar(c);
909
910         /* Most messages don't have a newline in them */
911         serial_writechar('\n');
912         serial_writechar('\r');
913 }
914 #endif  /* CONFIG_SERIAL_TEXT_DEBUG */
915 //REX: 
916 void calibrate_decr() {                                                      
917         int freq, divisor;                                                   
918         
919         //jackl system_clock
920         #ifdef SYS_266
921         freq = 133000000;
922         #endif
923         #ifdef SYS_200
924         freq = 100000000;
925         #endif
926         #ifdef SYS_166
927         freq = 66000000;
928         #endif
929         //REX: to avoid slow time!
930         divisor = 4;                                                         
931         tb_ticks_per_jiffy = freq / HZ / divisor;                            
932         tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);             
933 }                                                                            
934 TODC_ALLOC();
935
936 void __init
937 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
938               unsigned long r6, unsigned long r7)
939 {
940         parse_bootinfo(find_bootinfo());
941
942         /* ASSUMPTION:  If both r3 (bd_t pointer) and r6 (cmdline pointer)
943          * are non-zero, then we should use the board info from the bd_t
944          * structure and the cmdline pointed to by r6 instead of the
945          * information from birecs, if any.  Otherwise, use the information
946          * from birecs as discovered by the preceeding call to
947          * parse_bootinfo().  This rule should work with both PPCBoot, which
948          * uses a bd_t board info structure, and the kernel boot wrapper,
949          * which uses birecs.
950          */
951         if (r3 && r6) {
952                 /* copy board info structure */
953                 memcpy((void *) __res, (void *) (r3 + KERNELBASE),
954                        sizeof (bd_t));
955                 /* copy command line */
956                 *(char *) (r7 + KERNELBASE) = 0;
957                 strcpy(cmd_line, (char *) (r6 + KERNELBASE));
958         }
959 #ifdef CONFIG_BLK_DEV_INITRD
960         /* take care of initrd if we have one */
961         if (r4) {
962                 initrd_start = r4 + KERNELBASE;
963                 initrd_end = r5 + KERNELBASE;
964         }
965 #endif                          /* CONFIG_BLK_DEV_INITRD */
966
967         /* Map in board regs, etc. */
968         sandpoint_set_bat();
969 //REX:
970 #if 0
971         isa_io_base = MPC10X_MAPB_ISA_IO_BASE;
972         isa_mem_base = MPC10X_MAPB_ISA_MEM_BASE;
973         pci_dram_offset = MPC10X_MAPB_DRAM_OFFSET;
974         ISA_DMA_THRESHOLD = 0x00ffffff;
975         DMA_MODE_READ = 0x44;
976         DMA_MODE_WRITE = 0x48;
977 #endif
978         ppc_md.setup_arch = sandpoint_setup_arch;
979         ppc_md.show_cpuinfo = sandpoint_show_cpuinfo;
980         //ppc_md.irq_cannonicalize = sandpoint_irq_cannonicalize;
981         ppc_md.init_IRQ = sandpoint_init_IRQ;
982         //ppc_md.get_irq = openpic_get_irq;
983         ppc_md.get_irq = sandpoint_get_irq;
984         ppc_md.init = sandpoint_init2;
985
986         ppc_md.restart = sandpoint_restart;
987         ppc_md.power_off = sandpoint_power_off;
988         ppc_md.halt = sandpoint_halt;
989
990         ppc_md.find_end_of_memory = sandpoint_find_end_of_memory;
991         ppc_md.setup_io_mappings = sandpoint_map_io;
992         ppc_md.calibrate_decr = calibrate_decr;
993 #ifdef REX_TODC
994         TODC_INIT(TODC_TYPE_PC97307, 0x70, 0x00, 0x71, 8);
995         ppc_md.time_init = todc_time_init;
996         ppc_md.set_rtc_time = todc_set_rtc_time;
997         ppc_md.get_rtc_time = todc_get_rtc_time;
998         ppc_md.calibrate_decr = todc_calibrate_decr;
999
1000         ppc_md.nvram_read_val = todc_mc146818_read_val;
1001         ppc_md.nvram_write_val = todc_mc146818_write_val;
1002 #endif
1003
1004 #ifdef CONFIG_SERIAL
1005 #ifdef CONFIG_SERIAL_TEXT_DEBUG
1006         //ppc_md.progress = gen550_progress;
1007         ppc_md.progress = sandpoint_progress;
1008 #endif
1009         ppc_md.early_serial_map = sandpoint_early_serial_map;
1010 #endif
1011
1012 #ifdef CONFIG_VT
1013         ppc_md.kbd_setkeycode = pckbd_setkeycode;
1014         ppc_md.kbd_getkeycode = pckbd_getkeycode;
1015         ppc_md.kbd_translate = pckbd_translate;
1016         ppc_md.kbd_unexpected_up = pckbd_unexpected_up;
1017         ppc_md.kbd_leds = pckbd_leds;
1018         ppc_md.kbd_init_hw = pckbd_init_hw;
1019 #ifdef CONFIG_MAGIC_SYSRQ
1020         ppc_md.ppc_kbd_sysrq_xlate = pckbd_sysrq_xlate;
1021         SYSRQ_KEY = 0x54;
1022 #endif
1023 #endif
1024
1025 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
1026         ppc_ide_md.default_irq = sandpoint_ide_default_irq;
1027         ppc_ide_md.default_io_base = sandpoint_ide_default_io_base;
1028         ppc_ide_md.ide_init_hwif = sandpoint_ide_init_hwif_ports;
1029 #endif
1030
1031         return;
1032 }