[PATCH] ppc32: Added support for all MPC8548 internal interrupts
[safe/jmp/linux-2.6] / arch / ppc / platforms / 85xx / stx_gp3.c
1 /*
2  * arch/ppc/platforms/85xx/stx_gp3.c
3  *
4  * STx GP3 board specific routines
5  *
6  * Dan Malek <dan@embeddededge.com>
7  * Copyright 2004 Embedded Edge, LLC
8  *
9  * Copied from mpc8560_ads.c
10  * Copyright 2002, 2003 Motorola Inc.
11  *
12  * Ported to 2.6, Matt Porter <mporter@kernel.crashing.org>
13  * Copyright 2004-2005 MontaVista Software, Inc.
14  *
15  * This program is free software; you can redistribute  it and/or modify it
16  * under  the terms of  the GNU General  Public License as published by the
17  * Free Software Foundation;  either version 2 of the  License, or (at your
18  * option) any later version.
19  */
20
21 #include <linux/config.h>
22 #include <linux/stddef.h>
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/errno.h>
26 #include <linux/reboot.h>
27 #include <linux/pci.h>
28 #include <linux/kdev_t.h>
29 #include <linux/major.h>
30 #include <linux/blkdev.h>
31 #include <linux/console.h>
32 #include <linux/delay.h>
33 #include <linux/irq.h>
34 #include <linux/root_dev.h>
35 #include <linux/seq_file.h>
36 #include <linux/serial.h>
37 #include <linux/initrd.h>
38 #include <linux/module.h>
39 #include <linux/fsl_devices.h>
40 #include <linux/interrupt.h>
41
42 #include <asm/system.h>
43 #include <asm/pgtable.h>
44 #include <asm/page.h>
45 #include <asm/atomic.h>
46 #include <asm/time.h>
47 #include <asm/io.h>
48 #include <asm/machdep.h>
49 #include <asm/prom.h>
50 #include <asm/open_pic.h>
51 #include <asm/bootinfo.h>
52 #include <asm/pci-bridge.h>
53 #include <asm/mpc85xx.h>
54 #include <asm/irq.h>
55 #include <asm/immap_85xx.h>
56 #include <asm/immap_cpm2.h>
57 #include <asm/mpc85xx.h>
58 #include <asm/ppc_sys.h>
59
60 #include <syslib/cpm2_pic.h>
61 #include <syslib/ppc85xx_common.h>
62
63 extern void cpm2_reset(void);
64
65 unsigned char __res[sizeof(bd_t)];
66
67 #ifndef CONFIG_PCI
68 unsigned long isa_io_base = 0;
69 unsigned long isa_mem_base = 0;
70 unsigned long pci_dram_offset = 0;
71 #endif
72
73 /* Internal interrupts are all Level Sensitive, and Positive Polarity */
74 static u8 gp3_openpic_initsenses[] __initdata = {
75         MPC85XX_INTERNAL_IRQ_SENSES,
76         0x0,                                            /* External  0: */
77 #if defined(CONFIG_PCI)
78         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 1: PCI slot 0 */
79         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 2: PCI slot 1 */
80         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 3: PCI slot 2 */
81         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 4: PCI slot 3 */
82 #else
83         0x0,                            /* External  1: */
84         0x0,                            /* External  2: */
85         0x0,                            /* External  3: */
86         0x0,                            /* External  4: */
87 #endif
88         0x0,                            /* External  5: */
89         0x0,                            /* External  6: */
90         0x0,                            /* External  7: */
91         0x0,                            /* External  8: */
92         0x0,                            /* External  9: */
93         0x0,                            /* External 10: */
94         0x0,                            /* External 11: */
95 };
96
97 /*
98  * Setup the architecture
99  */
100 static void __init
101 gp3_setup_arch(void)
102 {
103         bd_t *binfo = (bd_t *) __res;
104         unsigned int freq;
105         struct gianfar_platform_data *pdata;
106
107         cpm2_reset();
108
109         /* get the core frequency */
110         freq = binfo->bi_intfreq;
111
112         if (ppc_md.progress)
113                 ppc_md.progress("gp3_setup_arch()", 0);
114
115         /* Set loops_per_jiffy to a half-way reasonable value,
116            for use until calibrate_delay gets called. */
117         loops_per_jiffy = freq / HZ;
118
119 #ifdef CONFIG_PCI
120         /* setup PCI host bridges */
121         mpc85xx_setup_hose();
122 #endif
123
124         /* setup the board related information for the enet controllers */
125         pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_TSEC1);
126 /*      pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR; */
127         pdata->interruptPHY = MPC85xx_IRQ_EXT5;
128         pdata->phyid = 2;
129         pdata->phy_reg_addr += binfo->bi_immr_base;
130         memcpy(pdata->mac_addr, binfo->bi_enetaddr, 6);
131
132         pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_TSEC2);
133 /*      pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR; */
134         pdata->interruptPHY = MPC85xx_IRQ_EXT5;
135         pdata->phyid = 4;
136         /* fixup phy address */
137         pdata->phy_reg_addr += binfo->bi_immr_base;
138         memcpy(pdata->mac_addr, binfo->bi_enet1addr, 6);
139
140 #ifdef CONFIG_BLK_DEV_INITRD
141         if (initrd_start)
142                 ROOT_DEV = Root_RAM0;
143         else
144 #endif
145 #ifdef  CONFIG_ROOT_NFS
146                 ROOT_DEV = Root_NFS;
147 #else
148                 ROOT_DEV = Root_HDA1;
149 #endif
150
151         printk ("bi_immr_base = %8.8lx\n", binfo->bi_immr_base);
152 }
153
154 static irqreturn_t cpm2_cascade(int irq, void *dev_id, struct pt_regs *regs)
155 {
156         while ((irq = cpm2_get_irq(regs)) >= 0)
157                 __do_IRQ(irq, regs);
158
159         return IRQ_HANDLED;
160 }
161
162 static struct irqaction cpm2_irqaction = {
163         .handler        = cpm2_cascade,
164         .flags          = SA_INTERRUPT,
165         .mask           = CPU_MASK_NONE,
166         .name           = "cpm2_cascade",
167 };
168
169 static void __init
170 gp3_init_IRQ(void)
171 {
172         bd_t *binfo = (bd_t *) __res;
173
174         /*
175          * Setup OpenPIC
176          */
177
178         /* Determine the Physical Address of the OpenPIC regs */
179         phys_addr_t OpenPIC_PAddr =
180             binfo->bi_immr_base + MPC85xx_OPENPIC_OFFSET;
181         OpenPIC_Addr = ioremap(OpenPIC_PAddr, MPC85xx_OPENPIC_SIZE);
182         OpenPIC_InitSenses = gp3_openpic_initsenses;
183         OpenPIC_NumInitSenses = sizeof (gp3_openpic_initsenses);
184
185         /* Skip reserved space and internal sources */
186         openpic_set_sources(0, 32, OpenPIC_Addr + 0x10200);
187
188         /* Map PIC IRQs 0-11 */
189         openpic_set_sources(48, 12, OpenPIC_Addr + 0x10000);
190
191         /*
192          * Let openpic interrupts starting from an offset, to
193          * leave space for cascading interrupts underneath.
194          */
195         openpic_init(MPC85xx_OPENPIC_IRQ_OFFSET);
196
197         /* Setup CPM2 PIC */
198         cpm2_init_IRQ();
199
200         setup_irq(MPC85xx_IRQ_CPM, &cpm2_irqaction);
201
202         return;
203 }
204
205 static int
206 gp3_show_cpuinfo(struct seq_file *m)
207 {
208         uint pvid, svid, phid1;
209         bd_t *binfo = (bd_t *) __res;
210         uint    memsize;
211         unsigned int freq;
212         extern unsigned long total_memory;      /* in mm/init */
213
214         /* get the core frequency */
215         freq = binfo->bi_intfreq;
216
217         pvid = mfspr(SPRN_PVR);
218         svid = mfspr(SPRN_SVR);
219
220         memsize = total_memory;
221
222         seq_printf(m, "Vendor\t\t: RPC Electronics STx \n");
223         seq_printf(m, "Machine\t\t: GP3 - MPC%s\n", cur_ppc_sys_spec->ppc_sys_name);
224         seq_printf(m, "bus freq\t: %u.%.6u MHz\n", freq / 1000000,
225                    freq % 1000000);
226         seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
227         seq_printf(m, "SVR\t\t: 0x%x\n", svid);
228
229         /* Display cpu Pll setting */
230         phid1 = mfspr(SPRN_HID1);
231         seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
232
233         /* Display the amount of memory */
234         seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
235
236         return 0;
237 }
238
239 #ifdef CONFIG_PCI
240 int mpc85xx_map_irq(struct pci_dev *dev, unsigned char idsel,
241                     unsigned char pin)
242 {
243         static char pci_irq_table[][4] =
244             /*
245              *      PCI IDSEL/INTPIN->INTLINE
246              *        A      B      C      D
247              */
248         {
249                 {PIRQA, PIRQB, PIRQC, PIRQD},
250                 {PIRQD, PIRQA, PIRQB, PIRQC},
251                 {PIRQC, PIRQD, PIRQA, PIRQB},
252                 {PIRQB, PIRQC, PIRQD, PIRQA},
253         };
254
255         const long min_idsel = 12, max_idsel = 15, irqs_per_slot = 4;
256         return PCI_IRQ_TABLE_LOOKUP;
257 }
258
259 int mpc85xx_exclude_device(u_char bus, u_char devfn)
260 {
261         if (bus == 0 && PCI_SLOT(devfn) == 0)
262                 return PCIBIOS_DEVICE_NOT_FOUND;
263         else
264                 return PCIBIOS_SUCCESSFUL;
265 }
266 #endif /* CONFIG_PCI */
267
268 void __init
269 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
270               unsigned long r6, unsigned long r7)
271 {
272         /* parse_bootinfo must always be called first */
273         parse_bootinfo(find_bootinfo());
274
275         /*
276          * If we were passed in a board information, copy it into the
277          * residual data area.
278          */
279         if (r3) {
280                 memcpy((void *) __res, (void *) (r3 + KERNELBASE),
281                        sizeof (bd_t));
282
283         }
284 #if defined(CONFIG_BLK_DEV_INITRD)
285         /*
286          * If the init RAM disk has been configured in, and there's a valid
287          * starting address for it, set it up.
288          */
289         if (r4) {
290                 initrd_start = r4 + KERNELBASE;
291                 initrd_end = r5 + KERNELBASE;
292         }
293 #endif                          /* CONFIG_BLK_DEV_INITRD */
294
295         /* Copy the kernel command line arguments to a safe place. */
296
297         if (r6) {
298                 *(char *) (r7 + KERNELBASE) = 0;
299                 strcpy(cmd_line, (char *) (r6 + KERNELBASE));
300         }
301
302         identify_ppc_sys_by_id(mfspr(SPRN_SVR));
303
304         /* setup the PowerPC module struct */
305         ppc_md.setup_arch = gp3_setup_arch;
306         ppc_md.show_cpuinfo = gp3_show_cpuinfo;
307
308         ppc_md.init_IRQ = gp3_init_IRQ;
309         ppc_md.get_irq = openpic_get_irq;
310
311         ppc_md.restart = mpc85xx_restart;
312         ppc_md.power_off = mpc85xx_power_off;
313         ppc_md.halt = mpc85xx_halt;
314
315         ppc_md.find_end_of_memory = mpc85xx_find_end_of_memory;
316
317         ppc_md.calibrate_decr = mpc85xx_calibrate_decr;
318
319         if (ppc_md.progress)
320                 ppc_md.progress("platform_init(): exit", 0);
321
322         return;
323 }