This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / 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/module.h>
38 #include <linux/fsl_devices.h>
39
40 #include <asm/system.h>
41 #include <asm/pgtable.h>
42 #include <asm/page.h>
43 #include <asm/atomic.h>
44 #include <asm/time.h>
45 #include <asm/io.h>
46 #include <asm/machdep.h>
47 #include <asm/prom.h>
48 #include <asm/open_pic.h>
49 #include <asm/bootinfo.h>
50 #include <asm/pci-bridge.h>
51 #include <asm/mpc85xx.h>
52 #include <asm/irq.h>
53 #include <asm/immap_85xx.h>
54 #include <asm/immap_cpm2.h>
55 #include <asm/mpc85xx.h>
56 #include <asm/ppc_sys.h>
57
58 #include <syslib/cpm2_pic.h>
59 #include <syslib/ppc85xx_common.h>
60
61 extern void cpm2_reset(void);
62
63 unsigned char __res[sizeof(bd_t)];
64
65 #ifndef CONFIG_PCI
66 unsigned long isa_io_base = 0;
67 unsigned long isa_mem_base = 0;
68 unsigned long pci_dram_offset = 0;
69 #endif
70
71 /* Internal interrupts are all Level Sensitive, and Positive Polarity */
72 static u8 gp3_openpic_initsenses[] __initdata = {
73         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal  0: L2 Cache */
74         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal  1: ECM */
75         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal  2: DDR DRAM */
76         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal  3: LBIU */
77         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal  4: DMA 0 */
78         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal  5: DMA 1 */
79         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal  6: DMA 2 */
80         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal  7: DMA 3 */
81         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal  8: PCI/PCI-X */
82         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal  9: RIO Inbound Port Write Error */
83         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 10: RIO Doorbell Inbound */
84         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 11: RIO Outbound Message */
85         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 12: RIO Inbound Message */
86         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 13: TSEC 0 Transmit */
87         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 14: TSEC 0 Receive */
88         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 15: Unused */
89         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 16: Unused */
90         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 17: Unused */
91         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 18: TSEC 0 Receive/Transmit Error */
92         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 19: TSEC 1 Transmit */
93         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 20: TSEC 1 Receive */
94         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 21: Unused */
95         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 22: Unused */
96         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 23: Unused */
97         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 24: TSEC 1 Receive/Transmit Error */
98         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 25: Fast Ethernet */
99         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 26: DUART */
100         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 27: I2C */
101         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 28: Performance Monitor */
102         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 29: Unused */
103         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 30: CPM */
104         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),      /* Internal 31: Unused */
105         0x0,                                            /* External  0: */
106 #if defined(CONFIG_PCI)
107         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 1: PCI slot 0 */
108         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 2: PCI slot 1 */
109         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 3: PCI slot 2 */
110         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 4: PCI slot 3 */
111 #else
112         0x0,                            /* External  1: */
113         0x0,                            /* External  2: */
114         0x0,                            /* External  3: */
115         0x0,                            /* External  4: */
116 #endif
117         0x0,                            /* External  5: */
118         0x0,                            /* External  6: */
119         0x0,                            /* External  7: */
120         0x0,                            /* External  8: */
121         0x0,                            /* External  9: */
122         0x0,                            /* External 10: */
123         0x0,                            /* External 11: */
124 };
125
126 /*
127  * Setup the architecture
128  */
129 static void __init
130 gp3_setup_arch(void)
131 {
132         bd_t *binfo = (bd_t *) __res;
133         unsigned int freq;
134         struct gianfar_platform_data *pdata;
135
136         cpm2_reset();
137
138         /* get the core frequency */
139         freq = binfo->bi_intfreq;
140
141         if (ppc_md.progress)
142                 ppc_md.progress("gp3_setup_arch()", 0);
143
144         /* Set loops_per_jiffy to a half-way reasonable value,
145            for use until calibrate_delay gets called. */
146         loops_per_jiffy = freq / HZ;
147
148 #ifdef CONFIG_PCI
149         /* setup PCI host bridges */
150         mpc85xx_setup_hose();
151 #endif
152
153         /* setup the board related information for the enet controllers */
154         pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_TSEC1);
155 /*      pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR; */
156         pdata->interruptPHY = MPC85xx_IRQ_EXT5;
157         pdata->phyid = 2;
158         pdata->phy_reg_addr += binfo->bi_immr_base;
159         memcpy(pdata->mac_addr, binfo->bi_enetaddr, 6);
160
161         pdata = (struct gianfar_platform_data *) ppc_sys_get_pdata(MPC85xx_TSEC2);
162 /*      pdata->board_flags = FSL_GIANFAR_BRD_HAS_PHY_INTR; */
163         pdata->interruptPHY = MPC85xx_IRQ_EXT5;
164         pdata->phyid = 4;
165         /* fixup phy address */
166         pdata->phy_reg_addr += binfo->bi_immr_base;
167         memcpy(pdata->mac_addr, binfo->bi_enet1addr, 6);
168
169 #ifdef CONFIG_BLK_DEV_INITRD
170         if (initrd_start)
171                 ROOT_DEV = Root_RAM0;
172         else
173 #endif
174 #ifdef  CONFIG_ROOT_NFS
175                 ROOT_DEV = Root_NFS;
176 #else
177                 ROOT_DEV = Root_HDA1;
178 #endif
179
180         printk ("bi_immr_base = %8.8lx\n", binfo->bi_immr_base);
181 }
182
183 static irqreturn_t cpm2_cascade(int irq, void *dev_id, struct pt_regs *regs)
184 {
185         while ((irq = cpm2_get_irq(regs)) >= 0)
186                 __do_IRQ(irq, regs);
187
188         return IRQ_HANDLED;
189 }
190
191 static struct irqaction cpm2_irqaction = {
192         .handler        = cpm2_cascade,
193         .flags          = SA_INTERRUPT,
194         .mask           = CPU_MASK_NONE,
195         .name           = "cpm2_cascade",
196 };
197
198 static void __init
199 gp3_init_IRQ(void)
200 {
201         int i;
202         volatile cpm2_map_t *immap = cpm2_immr;
203         bd_t *binfo = (bd_t *) __res;
204
205         /*
206          * Setup OpenPIC
207          */
208
209         /* Determine the Physical Address of the OpenPIC regs */
210         phys_addr_t OpenPIC_PAddr =
211             binfo->bi_immr_base + MPC85xx_OPENPIC_OFFSET;
212         OpenPIC_Addr = ioremap(OpenPIC_PAddr, MPC85xx_OPENPIC_SIZE);
213         OpenPIC_InitSenses = gp3_openpic_initsenses;
214         OpenPIC_NumInitSenses = sizeof (gp3_openpic_initsenses);
215
216         /* Skip reserved space and internal sources */
217         openpic_set_sources(0, 32, OpenPIC_Addr + 0x10200);
218
219         /* Map PIC IRQs 0-11 */
220         openpic_set_sources(32, 12, OpenPIC_Addr + 0x10000);
221
222         /*
223          * Let openpic interrupts starting from an offset, to
224          * leave space for cascading interrupts underneath.
225          */
226         openpic_init(MPC85xx_OPENPIC_IRQ_OFFSET);
227
228         /*
229          * Setup CPM2 PIC
230          */
231
232         /* disable all CPM interupts */
233         immap->im_intctl.ic_simrh = 0x0;
234         immap->im_intctl.ic_simrl = 0x0;
235
236         for (i = CPM_IRQ_OFFSET; i < (NR_CPM_INTS + CPM_IRQ_OFFSET); i++)
237                 irq_desc[i].handler = &cpm2_pic;
238
239         /*
240          * Initialize the default interrupt mapping priorities,
241          * in case the boot rom changed something on us.
242          */
243         immap->im_intctl.ic_sicr = 0;
244         immap->im_intctl.ic_scprrh = 0x05309770;
245         immap->im_intctl.ic_scprrl = 0x05309770;
246
247         setup_irq(MPC85xx_IRQ_CPM, &cpm2_irqaction);
248
249         return;
250 }
251
252 static int
253 gp3_show_cpuinfo(struct seq_file *m)
254 {
255         uint pvid, svid, phid1;
256         bd_t *binfo = (bd_t *) __res;
257         uint    memsize;
258         unsigned int freq;
259         extern unsigned long total_memory;      /* in mm/init */
260
261         /* get the core frequency */
262         freq = binfo->bi_intfreq;
263
264         pvid = mfspr(PVR);
265         svid = mfspr(SVR);
266
267         memsize = total_memory;
268
269         seq_printf(m, "Vendor\t\t: RPC Electronics STx \n");
270
271         switch (svid & 0xffff0000) {
272         case SVR_8540:
273                 seq_printf(m, "Machine\t\t: GP3 - MPC8540\n");
274                 break;
275         case SVR_8560:
276                 seq_printf(m, "Machine\t\t: GP3 - MPC8560\n");
277                 break;
278         default:
279                 seq_printf(m, "Machine\t\t: unknown\n");
280                 break;
281         }
282         seq_printf(m, "bus freq\t: %u.%.6u MHz\n", freq / 1000000,
283                    freq % 1000000);
284         seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
285         seq_printf(m, "SVR\t\t: 0x%x\n", svid);
286
287         /* Display cpu Pll setting */
288         phid1 = mfspr(HID1);
289         seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
290
291         /* Display the amount of memory */
292         seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
293
294         return 0;
295 }
296
297 #ifdef CONFIG_PCI
298 int mpc85xx_map_irq(struct pci_dev *dev, unsigned char idsel,
299                     unsigned char pin)
300 {
301         static char pci_irq_table[][4] =
302             /*
303              *      PCI IDSEL/INTPIN->INTLINE
304              *        A      B      C      D
305              */
306         {
307                 {PIRQA, PIRQB, PIRQC, PIRQD},
308                 {PIRQD, PIRQA, PIRQB, PIRQC},
309                 {PIRQC, PIRQD, PIRQA, PIRQB},
310                 {PIRQB, PIRQC, PIRQD, PIRQA},
311         };
312
313         const long min_idsel = 12, max_idsel = 15, irqs_per_slot = 4;
314         return PCI_IRQ_TABLE_LOOKUP;
315 }
316
317 int mpc85xx_exclude_device(u_char bus, u_char devfn)
318 {
319         if (bus == 0 && PCI_SLOT(devfn) == 0)
320                 return PCIBIOS_DEVICE_NOT_FOUND;
321         else
322                 return PCIBIOS_SUCCESSFUL;
323 }
324 #endif /* CONFIG_PCI */
325
326 void __init
327 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
328               unsigned long r6, unsigned long r7)
329 {
330         /* parse_bootinfo must always be called first */
331         parse_bootinfo(find_bootinfo());
332
333         /*
334          * If we were passed in a board information, copy it into the
335          * residual data area.
336          */
337         if (r3) {
338                 memcpy((void *) __res, (void *) (r3 + KERNELBASE),
339                        sizeof (bd_t));
340
341         }
342 #if defined(CONFIG_BLK_DEV_INITRD)
343         /*
344          * If the init RAM disk has been configured in, and there's a valid
345          * starting address for it, set it up.
346          */
347         if (r4) {
348                 initrd_start = r4 + KERNELBASE;
349                 initrd_end = r5 + KERNELBASE;
350         }
351 #endif                          /* CONFIG_BLK_DEV_INITRD */
352
353         /* Copy the kernel command line arguments to a safe place. */
354
355         if (r6) {
356                 *(char *) (r7 + KERNELBASE) = 0;
357                 strcpy(cmd_line, (char *) (r6 + KERNELBASE));
358         }
359
360         identify_ppc_sys_by_id(mfspr(SVR));
361
362         /* setup the PowerPC module struct */
363         ppc_md.setup_arch = gp3_setup_arch;
364         ppc_md.show_cpuinfo = gp3_show_cpuinfo;
365
366         ppc_md.init_IRQ = gp3_init_IRQ;
367         ppc_md.get_irq = openpic_get_irq;
368
369         ppc_md.restart = mpc85xx_restart;
370         ppc_md.power_off = mpc85xx_power_off;
371         ppc_md.halt = mpc85xx_halt;
372
373         ppc_md.find_end_of_memory = mpc85xx_find_end_of_memory;
374
375         ppc_md.calibrate_decr = mpc85xx_calibrate_decr;
376
377         if (ppc_md.progress)
378                 ppc_md.progress("platform_init(): exit", 0);
379
380         return;
381 }