]> err.no Git - linux-2.6/blob - arch/ppc/platforms/radstone_ppc7d.c
df2ea051380a67dd6d1425808fb8e78e4527627c
[linux-2.6] / arch / ppc / platforms / radstone_ppc7d.c
1 /*
2  * arch/ppc/platforms/radstone_ppc7d.c
3  *
4  * Board setup routines for the Radstone PPC7D boards.
5  *
6  * Author: James Chapman <jchapman@katalix.com>
7  *
8  * Based on code done by Rabeeh Khoury - rabeeh@galileo.co.il
9  * Based on code done by - Mark A. Greer <mgreer@mvista.com>
10  *
11  * This program is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU General Public License as published by the
13  * Free Software Foundation; either version 2 of the License, or (at your
14  * option) any later version.
15  */
16
17 /* Radstone PPC7D boards are rugged VME boards with PPC 7447A CPUs,
18  * Discovery-II, dual gigabit ethernet, dual PMC, USB, keyboard/mouse,
19  * 4 serial ports, 2 high speed serial ports (MPSCs) and optional
20  * SCSI / VGA.
21  */
22
23 #include <linux/config.h>
24 #include <linux/stddef.h>
25 #include <linux/kernel.h>
26 #include <linux/init.h>
27 #include <linux/errno.h>
28 #include <linux/reboot.h>
29 #include <linux/pci.h>
30 #include <linux/kdev_t.h>
31 #include <linux/major.h>
32 #include <linux/initrd.h>
33 #include <linux/console.h>
34 #include <linux/delay.h>
35 #include <linux/irq.h>
36 #include <linux/ide.h>
37 #include <linux/seq_file.h>
38 #include <linux/root_dev.h>
39 #include <linux/serial.h>
40 #include <linux/tty.h>          /* for linux/serial_core.h */
41 #include <linux/serial_core.h>
42 #include <linux/mv643xx.h>
43 #include <linux/netdevice.h>
44
45 #include <asm/system.h>
46 #include <asm/pgtable.h>
47 #include <asm/page.h>
48 #include <asm/time.h>
49 #include <asm/dma.h>
50 #include <asm/io.h>
51 #include <asm/machdep.h>
52 #include <asm/prom.h>
53 #include <asm/smp.h>
54 #include <asm/vga.h>
55 #include <asm/open_pic.h>
56 #include <asm/i8259.h>
57 #include <asm/todc.h>
58 #include <asm/bootinfo.h>
59 #include <asm/mpc10x.h>
60 #include <asm/pci-bridge.h>
61 #include <asm/mv64x60.h>
62 #include <asm/i8259.h>
63
64 #include "radstone_ppc7d.h"
65
66 #undef DEBUG
67
68 #define PPC7D_RST_PIN                   17      /* GPP17 */
69
70 extern u32 mv64360_irq_base;
71
72 static struct mv64x60_handle bh;
73 static int ppc7d_has_alma;
74
75 extern void gen550_progress(char *, unsigned short);
76 extern void gen550_init(int, struct uart_port *);
77
78 /* residual data */
79 unsigned char __res[sizeof(bd_t)];
80
81 /*****************************************************************************
82  * Serial port code
83  *****************************************************************************/
84
85 #if defined(CONFIG_KGDB) || defined(CONFIG_SERIAL_TEXT_DEBUG)
86 static void __init ppc7d_early_serial_map(void)
87 {
88 #if defined(CONFIG_SERIAL_MPSC_CONSOLE)
89         mv64x60_progress_init(CONFIG_MV64X60_NEW_BASE);
90 #elif defined(CONFIG_SERIAL_8250)
91         struct uart_port serial_req;
92
93         /* Setup serial port access */
94         memset(&serial_req, 0, sizeof(serial_req));
95         serial_req.uartclk = UART_CLK;
96         serial_req.irq = 4;
97         serial_req.flags = STD_COM_FLAGS;
98         serial_req.iotype = SERIAL_IO_MEM;
99         serial_req.membase = (u_char *) PPC7D_SERIAL_0;
100
101         gen550_init(0, &serial_req);
102         if (early_serial_setup(&serial_req) != 0)
103                 printk(KERN_ERR "Early serial init of port 0 failed\n");
104
105         /* Assume early_serial_setup() doesn't modify serial_req */
106         serial_req.line = 1;
107         serial_req.irq = 3;
108         serial_req.membase = (u_char *) PPC7D_SERIAL_1;
109
110         gen550_init(1, &serial_req);
111         if (early_serial_setup(&serial_req) != 0)
112                 printk(KERN_ERR "Early serial init of port 1 failed\n");
113 #else
114 #error CONFIG_KGDB || CONFIG_SERIAL_TEXT_DEBUG has no supported CONFIG_SERIAL_XXX
115 #endif
116 }
117 #endif /* CONFIG_KGDB || CONFIG_SERIAL_TEXT_DEBUG */
118
119 /*****************************************************************************
120  * Low-level board support code
121  *****************************************************************************/
122
123 static unsigned long __init ppc7d_find_end_of_memory(void)
124 {
125         bd_t *bp = (bd_t *) __res;
126
127         if (bp->bi_memsize)
128                 return bp->bi_memsize;
129
130         return (256 * 1024 * 1024);
131 }
132
133 static void __init ppc7d_map_io(void)
134 {
135         /* remove temporary mapping */
136         mtspr(SPRN_DBAT3U, 0x00000000);
137         mtspr(SPRN_DBAT3L, 0x00000000);
138
139         io_block_mapping(0xe8000000, 0xe8000000, 0x08000000, _PAGE_IO);
140         io_block_mapping(0xfe000000, 0xfe000000, 0x02000000, _PAGE_IO);
141 }
142
143 static void ppc7d_restart(char *cmd)
144 {
145         u32 data;
146
147         /* Disable GPP17 interrupt */
148         data = mv64x60_read(&bh, MV64x60_GPP_INTR_MASK);
149         data &= ~(1 << PPC7D_RST_PIN);
150         mv64x60_write(&bh, MV64x60_GPP_INTR_MASK, data);
151
152         /* Configure MPP17 as GPP */
153         data = mv64x60_read(&bh, MV64x60_MPP_CNTL_2);
154         data &= ~(0x0000000f << 4);
155         mv64x60_write(&bh, MV64x60_MPP_CNTL_2, data);
156
157         /* Enable pin GPP17 for output */
158         data = mv64x60_read(&bh, MV64x60_GPP_IO_CNTL);
159         data |= (1 << PPC7D_RST_PIN);
160         mv64x60_write(&bh, MV64x60_GPP_IO_CNTL, data);
161
162         /* Toggle GPP9 pin to reset the board */
163         mv64x60_write(&bh, MV64x60_GPP_VALUE_CLR, 1 << PPC7D_RST_PIN);
164         mv64x60_write(&bh, MV64x60_GPP_VALUE_SET, 1 << PPC7D_RST_PIN);
165
166         for (;;) ;              /* Spin until reset happens */
167         /* NOTREACHED */
168 }
169
170 static void ppc7d_power_off(void)
171 {
172         u32 data;
173
174         local_irq_disable();
175
176         /* Ensure that internal MV643XX watchdog is disabled.
177          * The Disco watchdog uses MPP17 on this hardware.
178          */
179         data = mv64x60_read(&bh, MV64x60_MPP_CNTL_2);
180         data &= ~(0x0000000f << 4);
181         mv64x60_write(&bh, MV64x60_MPP_CNTL_2, data);
182
183         data = mv64x60_read(&bh, MV64x60_WDT_WDC);
184         if (data & 0x80000000) {
185                 mv64x60_write(&bh, MV64x60_WDT_WDC, 1 << 24);
186                 mv64x60_write(&bh, MV64x60_WDT_WDC, 2 << 24);
187         }
188
189         for (;;) ;              /* No way to shut power off with software */
190         /* NOTREACHED */
191 }
192
193 static void ppc7d_halt(void)
194 {
195         ppc7d_power_off();
196         /* NOTREACHED */
197 }
198
199 static unsigned long ppc7d_led_no_pulse;
200
201 static int __init ppc7d_led_pulse_disable(char *str)
202 {
203         ppc7d_led_no_pulse = 1;
204         return 1;
205 }
206
207 /* This kernel option disables the heartbeat pulsing of a board LED */
208 __setup("ledoff", ppc7d_led_pulse_disable);
209
210 static void ppc7d_heartbeat(void)
211 {
212         u32 data32;
213         u8 data8;
214         static int max706_wdog = 0;
215
216         /* Unfortunately we can't access the LED control registers
217          * during early init because they're on the CPLD which is the
218          * other side of a PCI bridge which goes unreachable during
219          * PCI scan. So write the LEDs only if the MV64360 watchdog is
220          * enabled (i.e. userspace apps are running so kernel is up)..
221          */
222         data32 = mv64x60_read(&bh, MV64x60_WDT_WDC);
223         if (data32 & 0x80000000) {
224                 /* Enable MAX706 watchdog if not done already */
225                 if (!max706_wdog) {
226                         outb(3, PPC7D_CPLD_RESET);
227                         max706_wdog = 1;
228                 }
229
230                 /* Hit the MAX706 watchdog */
231                 outb(0, PPC7D_CPLD_WATCHDOG_TRIG);
232
233                 /* Pulse LED DS219 if not disabled */
234                 if (!ppc7d_led_no_pulse) {
235                         static int led_on = 0;
236
237                         data8 = inb(PPC7D_CPLD_LEDS);
238                         if (led_on)
239                                 data8 &= ~PPC7D_CPLD_LEDS_DS219_MASK;
240                         else
241                                 data8 |= PPC7D_CPLD_LEDS_DS219_MASK;
242
243                         outb(data8, PPC7D_CPLD_LEDS);
244                         led_on = !led_on;
245                 }
246         }
247         ppc_md.heartbeat_count = ppc_md.heartbeat_reset;
248 }
249
250 static int ppc7d_show_cpuinfo(struct seq_file *m)
251 {
252         u8 val;
253         u8 val1, val2;
254         static int flash_sizes[4] = { 64, 32, 0, 16 };
255         static int flash_banks[4] = { 4, 3, 2, 1 };
256         static int sdram_bank_sizes[4] = { 128, 256, 512, 1 };
257         int sdram_num_banks = 2;
258         static char *pci_modes[] = { "PCI33", "PCI66",
259                 "Unknown", "Unknown",
260                 "PCIX33", "PCIX66",
261                 "PCIX100", "PCIX133"
262         };
263
264         seq_printf(m, "vendor\t\t: Radstone Technology\n");
265         seq_printf(m, "machine\t\t: PPC7D\n");
266
267         val = inb(PPC7D_CPLD_BOARD_REVISION);
268         val1 = (val & PPC7D_CPLD_BOARD_REVISION_NUMBER_MASK) >> 5;
269         val2 = (val & PPC7D_CPLD_BOARD_REVISION_LETTER_MASK);
270         seq_printf(m, "revision\t: %hd%c%c\n",
271                    val1,
272                    (val2 <= 0x18) ? 'A' + val2 : 'Y',
273                    (val2 > 0x18) ? 'A' + (val2 - 0x19) : ' ');
274
275         val = inb(PPC7D_CPLD_MOTHERBOARD_TYPE);
276         val1 = val & PPC7D_CPLD_MB_TYPE_PLL_MASK;
277         val2 = val & (PPC7D_CPLD_MB_TYPE_ECC_FITTED_MASK |
278                       PPC7D_CPLD_MB_TYPE_ECC_ENABLE_MASK);
279         seq_printf(m, "bus speed\t: %dMHz\n",
280                    (val1 == PPC7D_CPLD_MB_TYPE_PLL_133) ? 133 :
281                    (val1 == PPC7D_CPLD_MB_TYPE_PLL_100) ? 100 :
282                    (val1 == PPC7D_CPLD_MB_TYPE_PLL_64) ? 64 : 0);
283
284         val = inb(PPC7D_CPLD_MEM_CONFIG);
285         if (val & PPC7D_CPLD_SDRAM_BANK_NUM_MASK) sdram_num_banks--;
286
287         val = inb(PPC7D_CPLD_MEM_CONFIG_EXTEND);
288         val1 = (val & PPC7D_CPLD_SDRAM_BANK_SIZE_MASK) >> 6;
289         seq_printf(m, "SDRAM\t\t: %d banks of %d%c, total %d%c",
290                    sdram_num_banks,
291                    sdram_bank_sizes[val1],
292                    (sdram_bank_sizes[val1] < 128) ? 'G' : 'M',
293                    sdram_num_banks * sdram_bank_sizes[val1],
294                    (sdram_bank_sizes[val1] < 128) ? 'G' : 'M');
295         if (val2 & PPC7D_CPLD_MB_TYPE_ECC_FITTED_MASK) {
296                 seq_printf(m, " [ECC %sabled]",
297                            (val2 & PPC7D_CPLD_MB_TYPE_ECC_ENABLE_MASK) ? "en" :
298                            "dis");
299         }
300         seq_printf(m, "\n");
301
302         val1 = (val & PPC7D_CPLD_FLASH_DEV_SIZE_MASK);
303         val2 = (val & PPC7D_CPLD_FLASH_BANK_NUM_MASK) >> 2;
304         seq_printf(m, "FLASH\t\t: %d banks of %dM, total %dM\n",
305                    flash_banks[val2], flash_sizes[val1],
306                    flash_banks[val2] * flash_sizes[val1]);
307
308         val = inb(PPC7D_CPLD_FLASH_WRITE_CNTL);
309         val1 = inb(PPC7D_CPLD_SW_FLASH_WRITE_PROTECT);
310         seq_printf(m, "  write links\t: %s%s%s%s\n",
311                    (val & PPD7D_CPLD_FLASH_CNTL_WR_LINK_MASK) ? "WRITE " : "",
312                    (val & PPD7D_CPLD_FLASH_CNTL_BOOT_LINK_MASK) ? "BOOT " : "",
313                    (val & PPD7D_CPLD_FLASH_CNTL_USER_LINK_MASK) ? "USER " : "",
314                    (val & (PPD7D_CPLD_FLASH_CNTL_WR_LINK_MASK |
315                            PPD7D_CPLD_FLASH_CNTL_BOOT_LINK_MASK |
316                            PPD7D_CPLD_FLASH_CNTL_USER_LINK_MASK)) ==
317                    0 ? "NONE" : "");
318         seq_printf(m, "  write sector h/w enables: %s%s%s%s%s\n",
319                    (val & PPD7D_CPLD_FLASH_CNTL_RECO_WR_MASK) ? "RECOVERY " :
320                    "",
321                    (val & PPD7D_CPLD_FLASH_CNTL_BOOT_WR_MASK) ? "BOOT " : "",
322                    (val & PPD7D_CPLD_FLASH_CNTL_USER_WR_MASK) ? "USER " : "",
323                    (val1 & PPC7D_CPLD_FLASH_CNTL_NVRAM_PROT_MASK) ? "NVRAM " :
324                    "",
325                    (((val &
326                       (PPD7D_CPLD_FLASH_CNTL_RECO_WR_MASK |
327                        PPD7D_CPLD_FLASH_CNTL_BOOT_WR_MASK |
328                        PPD7D_CPLD_FLASH_CNTL_BOOT_WR_MASK)) == 0)
329                     && ((val1 & PPC7D_CPLD_FLASH_CNTL_NVRAM_PROT_MASK) ==
330                         0)) ? "NONE" : "");
331         val1 =
332             inb(PPC7D_CPLD_SW_FLASH_WRITE_PROTECT) &
333             (PPC7D_CPLD_SW_FLASH_WRPROT_SYSBOOT_MASK |
334              PPC7D_CPLD_SW_FLASH_WRPROT_USER_MASK);
335         seq_printf(m, "  software sector enables: %s%s%s\n",
336                    (val1 & PPC7D_CPLD_SW_FLASH_WRPROT_SYSBOOT_MASK) ? "SYSBOOT "
337                    : "",
338                    (val1 & PPC7D_CPLD_SW_FLASH_WRPROT_USER_MASK) ? "USER " : "",
339                    (val1 == 0) ? "NONE " : "");
340
341         seq_printf(m, "Boot options\t: %s%s%s%s\n",
342                    (val & PPC7D_CPLD_FLASH_CNTL_ALTBOOT_LINK_MASK) ?
343                    "ALTERNATE " : "",
344                    (val & PPC7D_CPLD_FLASH_CNTL_VMEBOOT_LINK_MASK) ? "VME " :
345                    "",
346                    (val & PPC7D_CPLD_FLASH_CNTL_RECBOOT_LINK_MASK) ? "RECOVERY "
347                    : "",
348                    ((val &
349                      (PPC7D_CPLD_FLASH_CNTL_ALTBOOT_LINK_MASK |
350                       PPC7D_CPLD_FLASH_CNTL_VMEBOOT_LINK_MASK |
351                       PPC7D_CPLD_FLASH_CNTL_RECBOOT_LINK_MASK)) ==
352                     0) ? "NONE" : "");
353
354         val = inb(PPC7D_CPLD_EQUIPMENT_PRESENT_1);
355         seq_printf(m, "Fitted modules\t: %s%s%s%s\n",
356                    (val & PPC7D_CPLD_EQPT_PRES_1_PMC1_MASK) ? "" : "PMC1 ",
357                    (val & PPC7D_CPLD_EQPT_PRES_1_PMC2_MASK) ? "" : "PMC2 ",
358                    (val & PPC7D_CPLD_EQPT_PRES_1_AFIX_MASK) ? "AFIX " : "",
359                    ((val & (PPC7D_CPLD_EQPT_PRES_1_PMC1_MASK |
360                             PPC7D_CPLD_EQPT_PRES_1_PMC2_MASK |
361                             PPC7D_CPLD_EQPT_PRES_1_AFIX_MASK)) ==
362                     (PPC7D_CPLD_EQPT_PRES_1_PMC1_MASK |
363                      PPC7D_CPLD_EQPT_PRES_1_PMC2_MASK)) ? "NONE" : "");
364
365         if (val & PPC7D_CPLD_EQPT_PRES_1_AFIX_MASK) {
366                 static const char *ids[] = {
367                         "unknown",
368                         "1553 (Dual Channel)",
369                         "1553 (Single Channel)",
370                         "8-bit SCSI + VGA",
371                         "16-bit SCSI + VGA",
372                         "1553 (Single Channel with sideband)",
373                         "1553 (Dual Channel with sideband)",
374                         NULL
375                 };
376                 u8 id = __raw_readb((void *)PPC7D_AFIX_REG_BASE + 0x03);
377                 seq_printf(m, "AFIX module\t: 0x%hx [%s]\n", id,
378                            id < 7 ? ids[id] : "unknown");
379         }
380
381         val = inb(PPC7D_CPLD_PCI_CONFIG);
382         val1 = (val & PPC7D_CPLD_PCI_CONFIG_PCI0_MASK) >> 4;
383         val2 = (val & PPC7D_CPLD_PCI_CONFIG_PCI1_MASK);
384         seq_printf(m, "PCI#0\t\t: %s\nPCI#1\t\t: %s\n",
385                    pci_modes[val1], pci_modes[val2]);
386
387         val = inb(PPC7D_CPLD_EQUIPMENT_PRESENT_2);
388         seq_printf(m, "PMC1\t\t: %s\nPMC2\t\t: %s\n",
389                    (val & PPC7D_CPLD_EQPT_PRES_3_PMC1_V_MASK) ? "3.3v" : "5v",
390                    (val & PPC7D_CPLD_EQPT_PRES_3_PMC2_V_MASK) ? "3.3v" : "5v");
391         seq_printf(m, "PMC power source: %s\n",
392                    (val & PPC7D_CPLD_EQPT_PRES_3_PMC_POWER_MASK) ? "VME" :
393                    "internal");
394
395         val = inb(PPC7D_CPLD_EQUIPMENT_PRESENT_4);
396         val2 = inb(PPC7D_CPLD_EQUIPMENT_PRESENT_2);
397         seq_printf(m, "Fit options\t: %s%s%s%s%s%s%s\n",
398                    (val & PPC7D_CPLD_EQPT_PRES_4_LPT_MASK) ? "LPT " : "",
399                    (val & PPC7D_CPLD_EQPT_PRES_4_PS2_FITTED) ? "PS2 " : "",
400                    (val & PPC7D_CPLD_EQPT_PRES_4_USB2_FITTED) ? "USB2 " : "",
401                    (val2 & PPC7D_CPLD_EQPT_PRES_2_UNIVERSE_MASK) ? "VME " : "",
402                    (val2 & PPC7D_CPLD_EQPT_PRES_2_COM36_MASK) ? "COM3-6 " : "",
403                    (val2 & PPC7D_CPLD_EQPT_PRES_2_GIGE_MASK) ? "eth0 " : "",
404                    (val2 & PPC7D_CPLD_EQPT_PRES_2_DUALGIGE_MASK) ? "eth1 " :
405                    "");
406
407         val = inb(PPC7D_CPLD_ID_LINK);
408         val1 = val & (PPC7D_CPLD_ID_LINK_E6_MASK |
409                       PPC7D_CPLD_ID_LINK_E7_MASK |
410                       PPC7D_CPLD_ID_LINK_E12_MASK |
411                       PPC7D_CPLD_ID_LINK_E13_MASK);
412
413         val = inb(PPC7D_CPLD_FLASH_WRITE_CNTL) &
414             (PPD7D_CPLD_FLASH_CNTL_WR_LINK_MASK |
415              PPD7D_CPLD_FLASH_CNTL_BOOT_LINK_MASK |
416              PPD7D_CPLD_FLASH_CNTL_USER_LINK_MASK);
417
418         seq_printf(m, "Board links present: %s%s%s%s%s%s%s%s\n",
419                    (val1 & PPC7D_CPLD_ID_LINK_E6_MASK) ? "E6 " : "",
420                    (val1 & PPC7D_CPLD_ID_LINK_E7_MASK) ? "E7 " : "",
421                    (val & PPD7D_CPLD_FLASH_CNTL_WR_LINK_MASK) ? "E9 " : "",
422                    (val & PPD7D_CPLD_FLASH_CNTL_BOOT_LINK_MASK) ? "E10 " : "",
423                    (val & PPD7D_CPLD_FLASH_CNTL_USER_LINK_MASK) ? "E11 " : "",
424                    (val1 & PPC7D_CPLD_ID_LINK_E12_MASK) ? "E12 " : "",
425                    (val1 & PPC7D_CPLD_ID_LINK_E13_MASK) ? "E13 " : "",
426                    ((val == 0) && (val1 == 0)) ? "NONE" : "");
427
428         val = inb(PPC7D_CPLD_WDOG_RESETSW_MASK);
429         seq_printf(m, "Front panel reset switch: %sabled\n",
430                    (val & PPC7D_CPLD_WDOG_RESETSW_MASK) ? "dis" : "en");
431
432         return 0;
433 }
434
435 static void __init ppc7d_calibrate_decr(void)
436 {
437         ulong freq;
438
439         freq = 100000000 / 4;
440
441         pr_debug("time_init: decrementer frequency = %lu.%.6lu MHz\n",
442                  freq / 1000000, freq % 1000000);
443
444         tb_ticks_per_jiffy = freq / HZ;
445         tb_to_us = mulhwu_scale_factor(freq, 1000000);
446 }
447
448 /*****************************************************************************
449  * Interrupt stuff
450  *****************************************************************************/
451
452 static irqreturn_t ppc7d_i8259_intr(int irq, void *dev_id, struct pt_regs *regs)
453 {
454         u32 temp = mv64x60_read(&bh, MV64x60_GPP_INTR_CAUSE);
455         if (temp & (1 << 28)) {
456                 i8259_irq(regs);
457                 mv64x60_write(&bh, MV64x60_GPP_INTR_CAUSE, temp & (~(1 << 28)));
458                 return IRQ_HANDLED;
459         }
460
461         return IRQ_NONE;
462 }
463
464 /*
465  * Each interrupt cause is assigned an IRQ number.
466  * Southbridge has 16*2 (two 8259's) interrupts.
467  * Discovery-II has 96 interrupts (cause-hi, cause-lo, gpp x 32).
468  * If multiple interrupts are pending, get_irq() returns the
469  * lowest pending irq number first.
470  *
471  *
472  * IRQ #   Source                              Trig   Active
473  * =============================================================
474  *
475  * Southbridge
476  * -----------
477  * IRQ #   Source                              Trig
478  * =============================================================
479  * 0       ISA High Resolution Counter         Edge
480  * 1       Keyboard                            Edge
481  * 2       Cascade From (IRQ 8-15)             Edge
482  * 3       Com 2 (Uart 2)                      Edge
483  * 4       Com 1 (Uart 1)                      Edge
484  * 5       PCI Int D/AFIX IRQZ ID4 (2,7)       Level
485  * 6       GPIO                                Level
486  * 7       LPT                                 Edge
487  * 8       RTC Alarm                           Edge
488  * 9       PCI Int A/PMC 2/AFIX IRQW ID1 (2,0) Level
489  * 10      PCI Int B/PMC 1/AFIX IRQX ID2 (2,1) Level
490  * 11      USB2                                Level
491  * 12      Mouse                               Edge
492  * 13      Reserved internally by Ali M1535+
493  * 14      PCI Int C/VME/AFIX IRQY ID3 (2,6)   Level
494  * 15      COM 5/6                             Level
495  *
496  * 16..112 Discovery-II...
497  *
498  * MPP28   Southbridge                         Edge   High
499  *
500  *
501  * Interrupts are cascaded through to the Discovery-II.
502  *
503  *  PCI ---
504  *         \
505  * CPLD --> ALI1535 -------> DISCOVERY-II
506  *        INTF           MPP28
507  */
508 static void __init ppc7d_init_irq(void)
509 {
510         int irq;
511
512         pr_debug("%s\n", __FUNCTION__);
513         i8259_init(0);
514         mv64360_init_irq();
515
516         /* IRQ 0..15 are handled by the cascaded 8259's of the Ali1535 */
517         for (irq = 0; irq < 16; irq++) {
518                 irq_desc[irq].handler = &i8259_pic;
519         }
520         /* IRQs 5,6,9,10,11,14,15 are level sensitive */
521         irq_desc[5].status |= IRQ_LEVEL;
522         irq_desc[6].status |= IRQ_LEVEL;
523         irq_desc[9].status |= IRQ_LEVEL;
524         irq_desc[10].status |= IRQ_LEVEL;
525         irq_desc[11].status |= IRQ_LEVEL;
526         irq_desc[14].status |= IRQ_LEVEL;
527         irq_desc[15].status |= IRQ_LEVEL;
528
529         /* GPP28 is edge triggered */
530         irq_desc[mv64360_irq_base + MV64x60_IRQ_GPP28].status &= ~IRQ_LEVEL;
531 }
532
533 static u32 ppc7d_irq_canonicalize(u32 irq)
534 {
535         if ((irq >= 16) && (irq < (16 + 96)))
536                 irq -= 16;
537
538         return irq;
539 }
540
541 static int ppc7d_get_irq(struct pt_regs *regs)
542 {
543         int irq;
544
545         irq = mv64360_get_irq(regs);
546         if (irq == (mv64360_irq_base + MV64x60_IRQ_GPP28))
547                 irq = i8259_irq(regs);
548         return irq;
549 }
550
551 /*
552  * 9       PCI Int A/PMC 2/AFIX IRQW ID1 (2,0) Level
553  * 10      PCI Int B/PMC 1/AFIX IRQX ID2 (2,1) Level
554  * 14      PCI Int C/VME/AFIX IRQY ID3 (2,6)   Level
555  * 5       PCI Int D/AFIX IRQZ ID4 (2,7)       Level
556  */
557 static int __init ppc7d_map_irq(struct pci_dev *dev, unsigned char idsel,
558                                 unsigned char pin)
559 {
560         static const char pci_irq_table[][4] =
561             /*
562              *      PCI IDSEL/INTPIN->INTLINE
563              *         A   B   C   D
564              */
565         {
566                 {10, 14, 5, 9}, /* IDSEL 10 - PMC2 / AFIX IRQW */
567                 {9, 10, 14, 5}, /* IDSEL 11 - PMC1 / AFIX IRQX */
568                 {5, 9, 10, 14}, /* IDSEL 12 - AFIX IRQY */
569                 {14, 5, 9, 10}, /* IDSEL 13 - AFIX IRQZ */
570         };
571         const long min_idsel = 10, max_idsel = 14, irqs_per_slot = 4;
572
573         pr_debug("%s: %04x/%04x/%x: idsel=%hx pin=%hu\n", __FUNCTION__,
574                  dev->vendor, dev->device, PCI_FUNC(dev->devfn), idsel, pin);
575
576         return PCI_IRQ_TABLE_LOOKUP;
577 }
578
579 void __init ppc7d_intr_setup(void)
580 {
581         u32 data;
582
583         /*
584          * Define GPP 28 interrupt polarity as active high
585          * input signal and level triggered
586          */
587         data = mv64x60_read(&bh, MV64x60_GPP_LEVEL_CNTL);
588         data &= ~(1 << 28);
589         mv64x60_write(&bh, MV64x60_GPP_LEVEL_CNTL, data);
590         data = mv64x60_read(&bh, MV64x60_GPP_IO_CNTL);
591         data &= ~(1 << 28);
592         mv64x60_write(&bh, MV64x60_GPP_IO_CNTL, data);
593
594         /* Config GPP intr ctlr to respond to level trigger */
595         data = mv64x60_read(&bh, MV64x60_COMM_ARBITER_CNTL);
596         data |= (1 << 10);
597         mv64x60_write(&bh, MV64x60_COMM_ARBITER_CNTL, data);
598
599         /* XXXX Erranum FEr PCI-#8 */
600         data = mv64x60_read(&bh, MV64x60_PCI0_CMD);
601         data &= ~((1 << 5) | (1 << 9));
602         mv64x60_write(&bh, MV64x60_PCI0_CMD, data);
603         data = mv64x60_read(&bh, MV64x60_PCI1_CMD);
604         data &= ~((1 << 5) | (1 << 9));
605         mv64x60_write(&bh, MV64x60_PCI1_CMD, data);
606
607         /*
608          * Dismiss and then enable interrupt on GPP interrupt cause
609          * for CPU #0
610          */
611         mv64x60_write(&bh, MV64x60_GPP_INTR_CAUSE, ~(1 << 28));
612         data = mv64x60_read(&bh, MV64x60_GPP_INTR_MASK);
613         data |= (1 << 28);
614         mv64x60_write(&bh, MV64x60_GPP_INTR_MASK, data);
615
616         /*
617          * Dismiss and then enable interrupt on CPU #0 high cause reg
618          * BIT27 summarizes GPP interrupts 23-31
619          */
620         mv64x60_write(&bh, MV64360_IC_MAIN_CAUSE_HI, ~(1 << 27));
621         data = mv64x60_read(&bh, MV64360_IC_CPU0_INTR_MASK_HI);
622         data |= (1 << 27);
623         mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_HI, data);
624 }
625
626 /*****************************************************************************
627  * Platform device data fixup routines.
628  *****************************************************************************/
629
630 #if defined(CONFIG_SERIAL_MPSC)
631 static void __init ppc7d_fixup_mpsc_pdata(struct platform_device *pdev)
632 {
633         struct mpsc_pdata *pdata;
634
635         pdata = (struct mpsc_pdata *)pdev->dev.platform_data;
636
637         pdata->max_idle = 40;
638         pdata->default_baud = PPC7D_DEFAULT_BAUD;
639         pdata->brg_clk_src = PPC7D_MPSC_CLK_SRC;
640         pdata->brg_clk_freq = PPC7D_MPSC_CLK_FREQ;
641
642         return;
643 }
644 #endif
645
646 #if defined(CONFIG_MV643XX_ETH)
647 static void __init ppc7d_fixup_eth_pdata(struct platform_device *pdev)
648 {
649         struct mv643xx_eth_platform_data *eth_pd;
650         static u16 phy_addr[] = {
651                 PPC7D_ETH0_PHY_ADDR,
652                 PPC7D_ETH1_PHY_ADDR,
653                 PPC7D_ETH2_PHY_ADDR,
654         };
655         int i;
656
657         eth_pd = pdev->dev.platform_data;
658         eth_pd->force_phy_addr = 1;
659         eth_pd->phy_addr = phy_addr[pdev->id];
660         eth_pd->tx_queue_size = PPC7D_ETH_TX_QUEUE_SIZE;
661         eth_pd->rx_queue_size = PPC7D_ETH_RX_QUEUE_SIZE;
662
663         /* Adjust IRQ by mv64360_irq_base */
664         for (i = 0; i < pdev->num_resources; i++) {
665                 struct resource *r = &pdev->resource[i];
666
667                 if (r->flags & IORESOURCE_IRQ) {
668                         r->start += mv64360_irq_base;
669                         r->end += mv64360_irq_base;
670                         pr_debug("%s, uses IRQ %d\n", pdev->name,
671                                  (int)r->start);
672                 }
673         }
674
675 }
676 #endif
677
678 #if defined(CONFIG_I2C_MV64XXX)
679 static void __init
680 ppc7d_fixup_i2c_pdata(struct platform_device *pdev)
681 {
682         struct mv64xxx_i2c_pdata *pdata;
683         int i;
684
685         pdata = pdev->dev.platform_data;
686         if (pdata == NULL) {
687                 pdata = kmalloc(sizeof(*pdata), GFP_KERNEL);
688                 if (pdata == NULL)
689                         return;
690
691                 memset(pdata, 0, sizeof(*pdata));
692                 pdev->dev.platform_data = pdata;
693         }
694
695         /* divisors M=8, N=3 for 100kHz I2C from 133MHz system clock */
696         pdata->freq_m = 8;
697         pdata->freq_n = 3;
698         pdata->timeout = 500;
699         pdata->retries = 3;
700
701         /* Adjust IRQ by mv64360_irq_base */
702         for (i = 0; i < pdev->num_resources; i++) {
703                 struct resource *r = &pdev->resource[i];
704
705                 if (r->flags & IORESOURCE_IRQ) {
706                         r->start += mv64360_irq_base;
707                         r->end += mv64360_irq_base;
708                         pr_debug("%s, uses IRQ %d\n", pdev->name, (int) r->start);
709                 }
710         }
711 }
712 #endif
713
714 static int __init ppc7d_platform_notify(struct device *dev)
715 {
716         static struct {
717                 char *bus_id;
718                 void ((*rtn) (struct platform_device * pdev));
719         } dev_map[] = {
720 #if defined(CONFIG_SERIAL_MPSC)
721                 { MPSC_CTLR_NAME ".0", ppc7d_fixup_mpsc_pdata },
722                 { MPSC_CTLR_NAME ".1", ppc7d_fixup_mpsc_pdata },
723 #endif
724 #if defined(CONFIG_MV643XX_ETH)
725                 { MV643XX_ETH_NAME ".0", ppc7d_fixup_eth_pdata },
726                 { MV643XX_ETH_NAME ".1", ppc7d_fixup_eth_pdata },
727                 { MV643XX_ETH_NAME ".2", ppc7d_fixup_eth_pdata },
728 #endif
729 #if defined(CONFIG_I2C_MV64XXX)
730                 { MV64XXX_I2C_CTLR_NAME ".0", ppc7d_fixup_i2c_pdata },
731 #endif
732         };
733         struct platform_device *pdev;
734         int i;
735
736         if (dev && dev->bus_id)
737                 for (i = 0; i < ARRAY_SIZE(dev_map); i++)
738                         if (!strncmp(dev->bus_id, dev_map[i].bus_id,
739                                      BUS_ID_SIZE)) {
740
741                                 pdev = container_of(dev,
742                                                     struct platform_device,
743                                                     dev);
744                                 dev_map[i].rtn(pdev);
745                         }
746
747         return 0;
748 }
749
750 /*****************************************************************************
751  * PCI device fixups.
752  * These aren't really fixups per se. They are used to init devices as they
753  * are found during PCI scan.
754  *
755  * The PPC7D has an HB8 PCI-X bridge which must be set up during a PCI
756  * scan in order to find other devices on its secondary side.
757  *****************************************************************************/
758
759 static void __init ppc7d_fixup_hb8(struct pci_dev *dev)
760 {
761         u16 val16;
762
763         if (dev->bus->number == 0) {
764                 pr_debug("PCI: HB8 init\n");
765
766                 pci_write_config_byte(dev, 0x1c,
767                                       ((PPC7D_PCI0_IO_START_PCI_ADDR & 0xf000)
768                                        >> 8) | 0x01);
769                 pci_write_config_byte(dev, 0x1d,
770                                       (((PPC7D_PCI0_IO_START_PCI_ADDR +
771                                          PPC7D_PCI0_IO_SIZE -
772                                          1) & 0xf000) >> 8) | 0x01);
773                 pci_write_config_word(dev, 0x30,
774                                       PPC7D_PCI0_IO_START_PCI_ADDR >> 16);
775                 pci_write_config_word(dev, 0x32,
776                                       ((PPC7D_PCI0_IO_START_PCI_ADDR +
777                                         PPC7D_PCI0_IO_SIZE -
778                                         1) >> 16) & 0xffff);
779
780                 pci_write_config_word(dev, 0x20,
781                                       PPC7D_PCI0_MEM0_START_PCI_LO_ADDR >> 16);
782                 pci_write_config_word(dev, 0x22,
783                                       ((PPC7D_PCI0_MEM0_START_PCI_LO_ADDR +
784                                         PPC7D_PCI0_MEM0_SIZE -
785                                         1) >> 16) & 0xffff);
786                 pci_write_config_word(dev, 0x24, 0);
787                 pci_write_config_word(dev, 0x26, 0);
788                 pci_write_config_dword(dev, 0x28, 0);
789                 pci_write_config_dword(dev, 0x2c, 0);
790
791                 pci_read_config_word(dev, 0x3e, &val16);
792                 val16 |= ((1 << 5) | (1 << 1)); /* signal master aborts and
793                                                  * SERR to primary
794                                                  */
795                 val16 &= ~(1 << 2);             /* ISA disable, so all ISA
796                                                  * ports forwarded to secondary
797                                                  */
798                 pci_write_config_word(dev, 0x3e, val16);
799         }
800 }
801
802 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_HINT, 0x0028, ppc7d_fixup_hb8);
803
804 /* This should perhaps be a separate driver as we're actually initializing
805  * the chip for this board here. It's hardly a fixup...
806  */
807 static void __init ppc7d_fixup_ali1535(struct pci_dev *dev)
808 {
809         pr_debug("PCI: ALI1535 init\n");
810
811         if (dev->bus->number == 1) {
812                 /* Configure the ISA Port Settings */
813                 pci_write_config_byte(dev, 0x43, 0x00);
814
815                 /* Disable PCI Interrupt polling mode */
816                 pci_write_config_byte(dev, 0x45, 0x00);
817
818                 /* Multifunction pin select INTFJ -> INTF */
819                 pci_write_config_byte(dev, 0x78, 0x00);
820
821                 /* Set PCI INT -> IRQ Routing control in for external
822                  * pins south bridge.
823                  */
824                 pci_write_config_byte(dev, 0x48, 0x31); /* [7-4] INT B -> IRQ10
825                                                          * [3-0] INT A -> IRQ9
826                                                          */
827                 pci_write_config_byte(dev, 0x49, 0x5D); /* [7-4] INT D -> IRQ5
828                                                          * [3-0] INT C -> IRQ14
829                                                          */
830
831                 /* PPC7D setup */
832                 /* NEC USB device on IRQ 11 (INTE) - INTF disabled */
833                 pci_write_config_byte(dev, 0x4A, 0x09);
834
835                 /* GPIO on IRQ 6 */
836                 pci_write_config_byte(dev, 0x76, 0x07);
837
838                 /* SIRQ I (COMS 5/6) use IRQ line 15.
839                  * Positive (not subtractive) address decode.
840                  */
841                 pci_write_config_byte(dev, 0x44, 0x0f);
842
843                 /* SIRQ II disabled */
844                 pci_write_config_byte(dev, 0x75, 0x0);
845
846                 /* On board USB and RTC disabled */
847                 pci_write_config_word(dev, 0x52, (1 << 14));
848                 pci_write_config_byte(dev, 0x74, 0x00);
849
850                 /* On board IDE disabled */
851                 pci_write_config_byte(dev, 0x58, 0x00);
852
853                 /* Decode 32-bit addresses */
854                 pci_write_config_byte(dev, 0x5b, 0);
855
856                 /* Disable docking IO */
857                 pci_write_config_word(dev, 0x5c, 0x0000);
858
859                 /* Disable modem, enable sound */
860                 pci_write_config_byte(dev, 0x77, (1 << 6));
861
862                 /* Disable hot-docking mode */
863                 pci_write_config_byte(dev, 0x7d, 0x00);
864         }
865 }
866
867 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1533, ppc7d_fixup_ali1535);
868
869 static int ppc7d_pci_exclude_device(u8 bus, u8 devfn)
870 {
871         /* Early versions of this board were fitted with IBM ALMA
872          * PCI-VME bridge chips. The PCI config space of these devices
873          * was not set up correctly and causes PCI scan problems.
874          */
875         if ((bus == 1) && (PCI_SLOT(devfn) == 4) && ppc7d_has_alma)
876                 return PCIBIOS_DEVICE_NOT_FOUND;
877
878         return mv64x60_pci_exclude_device(bus, devfn);
879 }
880
881 /* This hook is called when each PCI bus is probed.
882  */
883 static void ppc7d_pci_fixup_bus(struct pci_bus *bus)
884 {
885         pr_debug("PCI BUS %hu: %lx/%lx %lx/%lx %lx/%lx %lx/%lx\n",
886                  bus->number,
887                  bus->resource[0] ? bus->resource[0]->start : 0,
888                  bus->resource[0] ? bus->resource[0]->end : 0,
889                  bus->resource[1] ? bus->resource[1]->start : 0,
890                  bus->resource[1] ? bus->resource[1]->end : 0,
891                  bus->resource[2] ? bus->resource[2]->start : 0,
892                  bus->resource[2] ? bus->resource[2]->end : 0,
893                  bus->resource[3] ? bus->resource[3]->start : 0,
894                  bus->resource[3] ? bus->resource[3]->end : 0);
895
896         if ((bus->number == 1) && (bus->resource[2] != NULL)) {
897                 /* Hide PCI window 2 of Bus 1 which is used only to
898                  * map legacy ISA memory space.
899                  */
900                 bus->resource[2]->start = 0;
901                 bus->resource[2]->end = 0;
902                 bus->resource[2]->flags = 0;
903         }
904 }
905
906 /*****************************************************************************
907  * Board device setup code
908  *****************************************************************************/
909
910 void __init ppc7d_setup_peripherals(void)
911 {
912         u32 val32;
913
914         /* Set up windows for boot CS */
915         mv64x60_set_32bit_window(&bh, MV64x60_CPU2BOOT_WIN,
916                                  PPC7D_BOOT_WINDOW_BASE, PPC7D_BOOT_WINDOW_SIZE,
917                                  0);
918         bh.ci->enable_window_32bit(&bh, MV64x60_CPU2BOOT_WIN);
919
920         /* Boot firmware configures the following DevCS addresses.
921          * DevCS0 - board control/status
922          * DevCS1 - test registers
923          * DevCS2 - AFIX port/address registers (for identifying)
924          * DevCS3 - FLASH
925          *
926          * We don't use DevCS0, DevCS1.
927          */
928         val32 = mv64x60_read(&bh, MV64360_CPU_BAR_ENABLE);
929         val32 |= ((1 << 4) | (1 << 5));
930         mv64x60_write(&bh, MV64360_CPU_BAR_ENABLE, val32);
931         mv64x60_write(&bh, MV64x60_CPU2DEV_0_BASE, 0);
932         mv64x60_write(&bh, MV64x60_CPU2DEV_0_SIZE, 0);
933         mv64x60_write(&bh, MV64x60_CPU2DEV_1_BASE, 0);
934         mv64x60_write(&bh, MV64x60_CPU2DEV_1_SIZE, 0);
935
936         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_2_WIN,
937                                  PPC7D_AFIX_REG_BASE, PPC7D_AFIX_REG_SIZE, 0);
938         bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_2_WIN);
939
940         mv64x60_set_32bit_window(&bh, MV64x60_CPU2DEV_3_WIN,
941                                  PPC7D_FLASH_BASE, PPC7D_FLASH_SIZE_ACTUAL, 0);
942         bh.ci->enable_window_32bit(&bh, MV64x60_CPU2DEV_3_WIN);
943
944         mv64x60_set_32bit_window(&bh, MV64x60_CPU2SRAM_WIN,
945                                  PPC7D_INTERNAL_SRAM_BASE, MV64360_SRAM_SIZE,
946                                  0);
947         bh.ci->enable_window_32bit(&bh, MV64x60_CPU2SRAM_WIN);
948
949         /* Set up Enet->SRAM window */
950         mv64x60_set_32bit_window(&bh, MV64x60_ENET2MEM_4_WIN,
951                                  PPC7D_INTERNAL_SRAM_BASE, MV64360_SRAM_SIZE,
952                                  0x2);
953         bh.ci->enable_window_32bit(&bh, MV64x60_ENET2MEM_4_WIN);
954
955         /* Give enet r/w access to memory region */
956         val32 = mv64x60_read(&bh, MV64360_ENET2MEM_ACC_PROT_0);
957         val32 |= (0x3 << (4 << 1));
958         mv64x60_write(&bh, MV64360_ENET2MEM_ACC_PROT_0, val32);
959         val32 = mv64x60_read(&bh, MV64360_ENET2MEM_ACC_PROT_1);
960         val32 |= (0x3 << (4 << 1));
961         mv64x60_write(&bh, MV64360_ENET2MEM_ACC_PROT_1, val32);
962         val32 = mv64x60_read(&bh, MV64360_ENET2MEM_ACC_PROT_2);
963         val32 |= (0x3 << (4 << 1));
964         mv64x60_write(&bh, MV64360_ENET2MEM_ACC_PROT_2, val32);
965
966         val32 = mv64x60_read(&bh, MV64x60_TIMR_CNTR_0_3_CNTL);
967         val32 &= ~((1 << 0) | (1 << 8) | (1 << 16) | (1 << 24));
968         mv64x60_write(&bh, MV64x60_TIMR_CNTR_0_3_CNTL, val32);
969
970         /* Enumerate pci bus.
971          *
972          * We scan PCI#0 first (the bus with the HB8 and other
973          * on-board peripherals). We must configure the 64360 before
974          * each scan, according to the bus number assignments.  Busses
975          * are assigned incrementally, starting at 0.  PCI#0 is
976          * usually assigned bus#0, the secondary side of the HB8 gets
977          * bus#1 and PCI#1 (second PMC site) gets bus#2.  However, if
978          * any PMC card has a PCI bridge, these bus assignments will
979          * change.
980          */
981
982         /* Turn off PCI retries */
983         val32 = mv64x60_read(&bh, MV64x60_CPU_CONFIG);
984         val32 |= (1 << 17);
985         mv64x60_write(&bh, MV64x60_CPU_CONFIG, val32);
986
987         /* Scan PCI#0 */
988         mv64x60_set_bus(&bh, 0, 0);
989         bh.hose_a->first_busno = 0;
990         bh.hose_a->last_busno = 0xff;
991         bh.hose_a->last_busno = pciauto_bus_scan(bh.hose_a, 0);
992         printk(KERN_INFO "PCI#0: first=%d last=%d\n",
993                bh.hose_a->first_busno, bh.hose_a->last_busno);
994
995         /* Scan PCI#1 */
996         bh.hose_b->first_busno = bh.hose_a->last_busno + 1;
997         mv64x60_set_bus(&bh, 1, bh.hose_b->first_busno);
998         bh.hose_b->last_busno = 0xff;
999         bh.hose_b->last_busno = pciauto_bus_scan(bh.hose_b,
1000                 bh.hose_b->first_busno);
1001         printk(KERN_INFO "PCI#1: first=%d last=%d\n",
1002                bh.hose_b->first_busno, bh.hose_b->last_busno);
1003
1004         /* Turn on PCI retries */
1005         val32 = mv64x60_read(&bh, MV64x60_CPU_CONFIG);
1006         val32 &= ~(1 << 17);
1007         mv64x60_write(&bh, MV64x60_CPU_CONFIG, val32);
1008
1009         /* Setup interrupts */
1010         ppc7d_intr_setup();
1011 }
1012
1013 static void __init ppc7d_setup_bridge(void)
1014 {
1015         struct mv64x60_setup_info si;
1016         int i;
1017         u32 temp;
1018
1019         mv64360_irq_base = 16;  /* first 16 intrs are 2 x 8259's */
1020
1021         memset(&si, 0, sizeof(si));
1022
1023         si.phys_reg_base = CONFIG_MV64X60_NEW_BASE;
1024
1025         si.pci_0.enable_bus = 1;
1026         si.pci_0.pci_io.cpu_base = PPC7D_PCI0_IO_START_PROC_ADDR;
1027         si.pci_0.pci_io.pci_base_hi = 0;
1028         si.pci_0.pci_io.pci_base_lo = PPC7D_PCI0_IO_START_PCI_ADDR;
1029         si.pci_0.pci_io.size = PPC7D_PCI0_IO_SIZE;
1030         si.pci_0.pci_io.swap = MV64x60_CPU2PCI_SWAP_NONE;
1031         si.pci_0.pci_mem[0].cpu_base = PPC7D_PCI0_MEM0_START_PROC_ADDR;
1032         si.pci_0.pci_mem[0].pci_base_hi = PPC7D_PCI0_MEM0_START_PCI_HI_ADDR;
1033         si.pci_0.pci_mem[0].pci_base_lo = PPC7D_PCI0_MEM0_START_PCI_LO_ADDR;
1034         si.pci_0.pci_mem[0].size = PPC7D_PCI0_MEM0_SIZE;
1035         si.pci_0.pci_mem[0].swap = MV64x60_CPU2PCI_SWAP_NONE;
1036         si.pci_0.pci_mem[1].cpu_base = PPC7D_PCI0_MEM1_START_PROC_ADDR;
1037         si.pci_0.pci_mem[1].pci_base_hi = PPC7D_PCI0_MEM1_START_PCI_HI_ADDR;
1038         si.pci_0.pci_mem[1].pci_base_lo = PPC7D_PCI0_MEM1_START_PCI_LO_ADDR;
1039         si.pci_0.pci_mem[1].size = PPC7D_PCI0_MEM1_SIZE;
1040         si.pci_0.pci_mem[1].swap = MV64x60_CPU2PCI_SWAP_NONE;
1041         si.pci_0.pci_cmd_bits = 0;
1042         si.pci_0.latency_timer = 0x80;
1043
1044         si.pci_1.enable_bus = 1;
1045         si.pci_1.pci_io.cpu_base = PPC7D_PCI1_IO_START_PROC_ADDR;
1046         si.pci_1.pci_io.pci_base_hi = 0;
1047         si.pci_1.pci_io.pci_base_lo = PPC7D_PCI1_IO_START_PCI_ADDR;
1048         si.pci_1.pci_io.size = PPC7D_PCI1_IO_SIZE;
1049         si.pci_1.pci_io.swap = MV64x60_CPU2PCI_SWAP_NONE;
1050         si.pci_1.pci_mem[0].cpu_base = PPC7D_PCI1_MEM0_START_PROC_ADDR;
1051         si.pci_1.pci_mem[0].pci_base_hi = PPC7D_PCI1_MEM0_START_PCI_HI_ADDR;
1052         si.pci_1.pci_mem[0].pci_base_lo = PPC7D_PCI1_MEM0_START_PCI_LO_ADDR;
1053         si.pci_1.pci_mem[0].size = PPC7D_PCI1_MEM0_SIZE;
1054         si.pci_1.pci_mem[0].swap = MV64x60_CPU2PCI_SWAP_NONE;
1055         si.pci_1.pci_mem[1].cpu_base = PPC7D_PCI1_MEM1_START_PROC_ADDR;
1056         si.pci_1.pci_mem[1].pci_base_hi = PPC7D_PCI1_MEM1_START_PCI_HI_ADDR;
1057         si.pci_1.pci_mem[1].pci_base_lo = PPC7D_PCI1_MEM1_START_PCI_LO_ADDR;
1058         si.pci_1.pci_mem[1].size = PPC7D_PCI1_MEM1_SIZE;
1059         si.pci_1.pci_mem[1].swap = MV64x60_CPU2PCI_SWAP_NONE;
1060         si.pci_1.pci_cmd_bits = 0;
1061         si.pci_1.latency_timer = 0x80;
1062
1063         /* Don't clear the SRAM window since we use it for debug */
1064         si.window_preserve_mask_32_lo = (1 << MV64x60_CPU2SRAM_WIN);
1065
1066         printk(KERN_INFO "PCI: MV64360 PCI#0 IO at %x, size %x\n",
1067                si.pci_0.pci_io.cpu_base, si.pci_0.pci_io.size);
1068         printk(KERN_INFO "PCI: MV64360 PCI#1 IO at %x, size %x\n",
1069                si.pci_1.pci_io.cpu_base, si.pci_1.pci_io.size);
1070
1071         for (i = 0; i < MV64x60_CPU2MEM_WINDOWS; i++) {
1072 #if defined(CONFIG_NOT_COHERENT_CACHE)
1073                 si.cpu_prot_options[i] = 0;
1074                 si.enet_options[i] = MV64360_ENET2MEM_SNOOP_NONE;
1075                 si.mpsc_options[i] = MV64360_MPSC2MEM_SNOOP_NONE;
1076                 si.idma_options[i] = MV64360_IDMA2MEM_SNOOP_NONE;
1077
1078                 si.pci_0.acc_cntl_options[i] =
1079                     MV64360_PCI_ACC_CNTL_SNOOP_NONE |
1080                     MV64360_PCI_ACC_CNTL_SWAP_NONE |
1081                     MV64360_PCI_ACC_CNTL_MBURST_128_BYTES |
1082                     MV64360_PCI_ACC_CNTL_RDSIZE_256_BYTES;
1083
1084                 si.pci_1.acc_cntl_options[i] =
1085                     MV64360_PCI_ACC_CNTL_SNOOP_NONE |
1086                     MV64360_PCI_ACC_CNTL_SWAP_NONE |
1087                     MV64360_PCI_ACC_CNTL_MBURST_128_BYTES |
1088                     MV64360_PCI_ACC_CNTL_RDSIZE_256_BYTES;
1089 #else
1090                 si.cpu_prot_options[i] = 0;
1091                 /* All PPC7D hardware uses B0 or newer MV64360 silicon which
1092                  * does not have snoop bugs.
1093                  */
1094                 si.enet_options[i] = MV64360_ENET2MEM_SNOOP_WB;
1095                 si.mpsc_options[i] = MV64360_MPSC2MEM_SNOOP_WB;
1096                 si.idma_options[i] = MV64360_IDMA2MEM_SNOOP_WB;
1097
1098                 si.pci_0.acc_cntl_options[i] =
1099                     MV64360_PCI_ACC_CNTL_SNOOP_WB |
1100                     MV64360_PCI_ACC_CNTL_SWAP_NONE |
1101                     MV64360_PCI_ACC_CNTL_MBURST_32_BYTES |
1102                     MV64360_PCI_ACC_CNTL_RDSIZE_32_BYTES;
1103
1104                 si.pci_1.acc_cntl_options[i] =
1105                     MV64360_PCI_ACC_CNTL_SNOOP_WB |
1106                     MV64360_PCI_ACC_CNTL_SWAP_NONE |
1107                     MV64360_PCI_ACC_CNTL_MBURST_32_BYTES |
1108                     MV64360_PCI_ACC_CNTL_RDSIZE_32_BYTES;
1109 #endif
1110         }
1111
1112         /* Lookup PCI host bridges */
1113         if (mv64x60_init(&bh, &si))
1114                 printk(KERN_ERR "MV64360 initialization failed.\n");
1115
1116         pr_debug("MV64360 regs @ %lx/%p\n", bh.p_base, bh.v_base);
1117
1118         /* Enable WB Cache coherency on SRAM */
1119         temp = mv64x60_read(&bh, MV64360_SRAM_CONFIG);
1120         pr_debug("SRAM_CONFIG: %x\n", temp);
1121 #if defined(CONFIG_NOT_COHERENT_CACHE)
1122         mv64x60_write(&bh, MV64360_SRAM_CONFIG, temp & ~0x2);
1123 #else
1124         mv64x60_write(&bh, MV64360_SRAM_CONFIG, temp | 0x2);
1125 #endif
1126         /* If system operates with internal bus arbiter (CPU master
1127          * control bit8) clear AACK Delay bit [25] in CPU
1128          * configuration register.
1129          */
1130         temp = mv64x60_read(&bh, MV64x60_CPU_MASTER_CNTL);
1131         if (temp & (1 << 8)) {
1132                 temp = mv64x60_read(&bh, MV64x60_CPU_CONFIG);
1133                 mv64x60_write(&bh, MV64x60_CPU_CONFIG, (temp & ~(1 << 25)));
1134         }
1135
1136         /* Data and address parity is enabled */
1137         temp = mv64x60_read(&bh, MV64x60_CPU_CONFIG);
1138         mv64x60_write(&bh, MV64x60_CPU_CONFIG,
1139                       (temp | (1 << 26) | (1 << 19)));
1140
1141         pci_dram_offset = 0;    /* sys mem at same addr on PCI & cpu bus */
1142         ppc_md.pci_swizzle = common_swizzle;
1143         ppc_md.pci_map_irq = ppc7d_map_irq;
1144         ppc_md.pci_exclude_device = ppc7d_pci_exclude_device;
1145
1146         mv64x60_set_bus(&bh, 0, 0);
1147         bh.hose_a->first_busno = 0;
1148         bh.hose_a->last_busno = 0xff;
1149         bh.hose_a->mem_space.start = PPC7D_PCI0_MEM0_START_PCI_LO_ADDR;
1150         bh.hose_a->mem_space.end =
1151             PPC7D_PCI0_MEM0_START_PCI_LO_ADDR + PPC7D_PCI0_MEM0_SIZE;
1152
1153         /* These will be set later, as a result of PCI0 scan */
1154         bh.hose_b->first_busno = 0;
1155         bh.hose_b->last_busno = 0xff;
1156         bh.hose_b->mem_space.start = PPC7D_PCI1_MEM0_START_PCI_LO_ADDR;
1157         bh.hose_b->mem_space.end =
1158             PPC7D_PCI1_MEM0_START_PCI_LO_ADDR + PPC7D_PCI1_MEM0_SIZE;
1159
1160         pr_debug("MV64360: PCI#0 IO decode %08x/%08x IO remap %08x\n",
1161                  mv64x60_read(&bh, 0x48), mv64x60_read(&bh, 0x50),
1162                  mv64x60_read(&bh, 0xf0));
1163 }
1164
1165 static void __init ppc7d_setup_arch(void)
1166 {
1167         int port;
1168
1169         loops_per_jiffy = 100000000 / HZ;
1170
1171 #ifdef CONFIG_BLK_DEV_INITRD
1172         if (initrd_start)
1173                 ROOT_DEV = Root_RAM0;
1174         else
1175 #endif
1176 #ifdef  CONFIG_ROOT_NFS
1177                 ROOT_DEV = Root_NFS;
1178 #else
1179                 ROOT_DEV = Root_HDA1;
1180 #endif
1181
1182         if ((cur_cpu_spec[0]->cpu_features & CPU_FTR_SPEC7450) ||
1183             (cur_cpu_spec[0]->cpu_features & CPU_FTR_L3CR))
1184                 /* 745x is different.  We only want to pass along enable. */
1185                 _set_L2CR(L2CR_L2E);
1186         else if (cur_cpu_spec[0]->cpu_features & CPU_FTR_L2CR)
1187                 /* All modules have 1MB of L2.  We also assume that an
1188                  * L2 divisor of 3 will work.
1189                  */
1190                 _set_L2CR(L2CR_L2E | L2CR_L2SIZ_1MB | L2CR_L2CLK_DIV3
1191                           | L2CR_L2RAM_PIPE | L2CR_L2OH_1_0 | L2CR_L2DF);
1192
1193         if (cur_cpu_spec[0]->cpu_features & CPU_FTR_L3CR)
1194                 /* No L3 cache */
1195                 _set_L3CR(0);
1196
1197 #ifdef CONFIG_DUMMY_CONSOLE
1198         conswitchp = &dummy_con;
1199 #endif
1200
1201         /* Lookup PCI host bridges */
1202         if (ppc_md.progress)
1203                 ppc_md.progress("ppc7d_setup_arch: calling setup_bridge", 0);
1204
1205         ppc7d_setup_bridge();
1206         ppc7d_setup_peripherals();
1207
1208         /* Disable ethernet. It might have been setup by the bootrom */
1209         for (port = 0; port < 3; port++)
1210                 mv64x60_write(&bh, MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port),
1211                               0x0000ff00);
1212
1213         /* Clear queue pointers to ensure they are all initialized,
1214          * otherwise since queues 1-7 are unused, they have random
1215          * pointers which look strange in register dumps. Don't bother
1216          * with queue 0 since it will be initialized later.
1217          */
1218         for (port = 0; port < 3; port++) {
1219                 mv64x60_write(&bh,
1220                               MV643XX_ETH_RX_CURRENT_QUEUE_DESC_PTR_1(port),
1221                               0x00000000);
1222                 mv64x60_write(&bh,
1223                               MV643XX_ETH_RX_CURRENT_QUEUE_DESC_PTR_2(port),
1224                               0x00000000);
1225                 mv64x60_write(&bh,
1226                               MV643XX_ETH_RX_CURRENT_QUEUE_DESC_PTR_3(port),
1227                               0x00000000);
1228                 mv64x60_write(&bh,
1229                               MV643XX_ETH_RX_CURRENT_QUEUE_DESC_PTR_4(port),
1230                               0x00000000);
1231                 mv64x60_write(&bh,
1232                               MV643XX_ETH_RX_CURRENT_QUEUE_DESC_PTR_5(port),
1233                               0x00000000);
1234                 mv64x60_write(&bh,
1235                               MV643XX_ETH_RX_CURRENT_QUEUE_DESC_PTR_6(port),
1236                               0x00000000);
1237                 mv64x60_write(&bh,
1238                               MV643XX_ETH_RX_CURRENT_QUEUE_DESC_PTR_7(port),
1239                               0x00000000);
1240         }
1241
1242         printk(KERN_INFO "Radstone Technology PPC7D\n");
1243         if (ppc_md.progress)
1244                 ppc_md.progress("ppc7d_setup_arch: exit", 0);
1245 }
1246
1247 /* This kernel command line parameter can be used to have the target
1248  * wait for a JTAG debugger to attach. Of course, a JTAG debugger
1249  * with hardware breakpoint support can have the target stop at any
1250  * location during init, but this is a convenience feature that makes
1251  * it easier in the common case of loading the code using the ppcboot
1252  * bootloader..
1253  */
1254 static unsigned long ppc7d_wait_debugger;
1255
1256 static int __init ppc7d_waitdbg(char *str)
1257 {
1258         ppc7d_wait_debugger = 1;
1259         return 1;
1260 }
1261
1262 __setup("waitdbg", ppc7d_waitdbg);
1263
1264 /* Second phase board init, called after other (architecture common)
1265  * low-level services have been initialized.
1266  */
1267 static void ppc7d_init2(void)
1268 {
1269         unsigned long flags;
1270         u32 data;
1271         u8 data8;
1272
1273         pr_debug("%s: enter\n", __FUNCTION__);
1274
1275         /* Wait for debugger? */
1276         if (ppc7d_wait_debugger) {
1277                 printk("Waiting for debugger...\n");
1278
1279                 while (readl(&ppc7d_wait_debugger)) ;
1280         }
1281
1282         /* Hook up i8259 interrupt which is connected to GPP28 */
1283         request_irq(mv64360_irq_base + MV64x60_IRQ_GPP28, ppc7d_i8259_intr,
1284                     SA_INTERRUPT, "I8259 (GPP28) interrupt", (void *)0);
1285
1286         /* Configure MPP16 as watchdog NMI, MPP17 as watchdog WDE */
1287         spin_lock_irqsave(&mv64x60_lock, flags);
1288         data = mv64x60_read(&bh, MV64x60_MPP_CNTL_2);
1289         data &= ~(0x0000000f << 0);
1290         data |= (0x00000004 << 0);
1291         data &= ~(0x0000000f << 4);
1292         data |= (0x00000004 << 4);
1293         mv64x60_write(&bh, MV64x60_MPP_CNTL_2, data);
1294         spin_unlock_irqrestore(&mv64x60_lock, flags);
1295
1296         /* All LEDs off */
1297         data8 = inb(PPC7D_CPLD_LEDS);
1298         data8 &= ~0x08;
1299         data8 |= 0x07;
1300         outb(data8, PPC7D_CPLD_LEDS);
1301
1302         pr_debug("%s: exit\n", __FUNCTION__);
1303 }
1304
1305 /* Called from machine_init(), early, before any of the __init functions
1306  * have run. We must init software-configurable pins before other functions
1307  * such as interrupt controllers are initialised.
1308  */
1309 void __init platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
1310                           unsigned long r6, unsigned long r7)
1311 {
1312         u8 val8;
1313         u8 rev_num;
1314
1315         /* Map 0xe0000000-0xffffffff early because we need access to SRAM
1316          * and the ISA memory space (for serial port) here. This mapping
1317          * is redone properly in ppc7d_map_io() later.
1318          */
1319         mtspr(SPRN_DBAT3U, 0xe0003fff);
1320         mtspr(SPRN_DBAT3L, 0xe000002a);
1321
1322         /*
1323          * Zero SRAM. Note that this generates parity errors on
1324          * internal data path in SRAM if it's first time accessing it
1325          * after reset.
1326          *
1327          * We do this ASAP to avoid parity errors when reading
1328          * uninitialized SRAM.
1329          */
1330         memset((void *)PPC7D_INTERNAL_SRAM_BASE, 0, MV64360_SRAM_SIZE);
1331
1332         pr_debug("platform_init: r3-r7: %lx %lx %lx %lx %lx\n",
1333                  r3, r4, r5, r6, r7);
1334
1335         parse_bootinfo(find_bootinfo());
1336
1337         /* ASSUMPTION:  If both r3 (bd_t pointer) and r6 (cmdline pointer)
1338          * are non-zero, then we should use the board info from the bd_t
1339          * structure and the cmdline pointed to by r6 instead of the
1340          * information from birecs, if any.  Otherwise, use the information
1341          * from birecs as discovered by the preceeding call to
1342          * parse_bootinfo().  This rule should work with both PPCBoot, which
1343          * uses a bd_t board info structure, and the kernel boot wrapper,
1344          * which uses birecs.
1345          */
1346         if (r3 && r6) {
1347                 bd_t *bp = (bd_t *) __res;
1348
1349                 /* copy board info structure */
1350                 memcpy((void *)__res, (void *)(r3 + KERNELBASE), sizeof(bd_t));
1351                 /* copy command line */
1352                 *(char *)(r7 + KERNELBASE) = 0;
1353                 strcpy(cmd_line, (char *)(r6 + KERNELBASE));
1354
1355                 printk(KERN_INFO "Board info data:-\n");
1356                 printk(KERN_INFO "  Internal freq: %lu MHz, bus freq: %lu MHz\n",
1357                        bp->bi_intfreq, bp->bi_busfreq);
1358                 printk(KERN_INFO "  Memory: %lx, size %lx\n", bp->bi_memstart,
1359                        bp->bi_memsize);
1360                 printk(KERN_INFO "  Console baudrate: %lu\n", bp->bi_baudrate);
1361                 printk(KERN_INFO "  Ethernet address: "
1362                        "%02x:%02x:%02x:%02x:%02x:%02x\n",
1363                        bp->bi_enetaddr[0], bp->bi_enetaddr[1],
1364                        bp->bi_enetaddr[2], bp->bi_enetaddr[3],
1365                        bp->bi_enetaddr[4], bp->bi_enetaddr[5]);
1366         }
1367 #ifdef CONFIG_BLK_DEV_INITRD
1368         /* take care of initrd if we have one */
1369         if (r4) {
1370                 initrd_start = r4 + KERNELBASE;
1371                 initrd_end = r5 + KERNELBASE;
1372                 printk(KERN_INFO "INITRD @ %lx/%lx\n", initrd_start, initrd_end);
1373         }
1374 #endif /* CONFIG_BLK_DEV_INITRD */
1375
1376         /* Map in board regs, etc. */
1377         isa_io_base = 0xe8000000;
1378         isa_mem_base = 0xe8000000;
1379         pci_dram_offset = 0x00000000;
1380         ISA_DMA_THRESHOLD = 0x00ffffff;
1381         DMA_MODE_READ = 0x44;
1382         DMA_MODE_WRITE = 0x48;
1383
1384         ppc_md.setup_arch = ppc7d_setup_arch;
1385         ppc_md.init = ppc7d_init2;
1386         ppc_md.show_cpuinfo = ppc7d_show_cpuinfo;
1387         ppc_md.irq_canonicalize = ppc7d_irq_canonicalize;
1388         ppc_md.init_IRQ = ppc7d_init_irq;
1389         ppc_md.get_irq = ppc7d_get_irq;
1390
1391         ppc_md.restart = ppc7d_restart;
1392         ppc_md.power_off = ppc7d_power_off;
1393         ppc_md.halt = ppc7d_halt;
1394
1395         ppc_md.find_end_of_memory = ppc7d_find_end_of_memory;
1396         ppc_md.setup_io_mappings = ppc7d_map_io;
1397
1398         ppc_md.time_init = NULL;
1399         ppc_md.set_rtc_time = NULL;
1400         ppc_md.get_rtc_time = NULL;
1401         ppc_md.calibrate_decr = ppc7d_calibrate_decr;
1402         ppc_md.nvram_read_val = NULL;
1403         ppc_md.nvram_write_val = NULL;
1404
1405         ppc_md.heartbeat = ppc7d_heartbeat;
1406         ppc_md.heartbeat_reset = HZ;
1407         ppc_md.heartbeat_count = ppc_md.heartbeat_reset;
1408
1409         ppc_md.pcibios_fixup_bus = ppc7d_pci_fixup_bus;
1410
1411 #if defined(CONFIG_SERIAL_MPSC) || defined(CONFIG_MV643XX_ETH) || \
1412     defined(CONFIG_I2C_MV64XXX)
1413         platform_notify = ppc7d_platform_notify;
1414 #endif
1415
1416 #ifdef CONFIG_SERIAL_MPSC
1417         /* On PPC7D, we must configure MPSC support via CPLD control
1418          * registers.
1419          */
1420         outb(PPC7D_CPLD_RTS_COM4_SCLK |
1421              PPC7D_CPLD_RTS_COM56_ENABLED, PPC7D_CPLD_RTS);
1422         outb(PPC7D_CPLD_COMS_COM3_TCLKEN |
1423              PPC7D_CPLD_COMS_COM3_TXEN |
1424              PPC7D_CPLD_COMS_COM4_TCLKEN |
1425              PPC7D_CPLD_COMS_COM4_TXEN, PPC7D_CPLD_COMS);
1426 #endif /* CONFIG_SERIAL_MPSC */
1427
1428 #if defined(CONFIG_KGDB) || defined(CONFIG_SERIAL_TEXT_DEBUG)
1429         ppc7d_early_serial_map();
1430 #ifdef  CONFIG_SERIAL_TEXT_DEBUG
1431 #if defined(CONFIG_SERIAL_MPSC_CONSOLE)
1432         ppc_md.progress = mv64x60_mpsc_progress;
1433 #elif defined(CONFIG_SERIAL_8250)
1434         ppc_md.progress = gen550_progress;
1435 #else
1436 #error CONFIG_KGDB || CONFIG_SERIAL_TEXT_DEBUG has no supported CONFIG_SERIAL_XXX
1437 #endif /* CONFIG_SERIAL_8250 */
1438 #endif /* CONFIG_SERIAL_TEXT_DEBUG */
1439 #endif /* CONFIG_KGDB || CONFIG_SERIAL_TEXT_DEBUG */
1440
1441         /* Enable write access to user flash.  This is necessary for
1442          * flash probe.
1443          */
1444         val8 = readb((void *)isa_io_base + PPC7D_CPLD_SW_FLASH_WRITE_PROTECT);
1445         writeb(val8 | (PPC7D_CPLD_SW_FLASH_WRPROT_ENABLED &
1446                        PPC7D_CPLD_SW_FLASH_WRPROT_USER_MASK),
1447                (void *)isa_io_base + PPC7D_CPLD_SW_FLASH_WRITE_PROTECT);
1448
1449         /* Determine if this board has IBM ALMA VME devices */
1450         val8 = readb((void *)isa_io_base + PPC7D_CPLD_BOARD_REVISION);
1451         rev_num = (val8 & PPC7D_CPLD_BOARD_REVISION_NUMBER_MASK) >> 5;
1452         if (rev_num <= 1)
1453                 ppc7d_has_alma = 1;
1454
1455 #ifdef DEBUG
1456         console_printk[0] = 8;
1457 #endif
1458 }