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