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