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