vserver 1.9.3
[linux-2.6.git] / arch / ppc / platforms / 85xx / mpc85xx_cds_common.c
1 /*
2  * arch/ppc/platform/85xx/mpc85xx_cds_common.c
3  *
4  * MPC85xx CDS board specific routines
5  *
6  * Maintainer: Kumar Gala <kumar.gala@freescale.com>
7  *
8  * Copyright 2004 Freescale Semiconductor, Inc
9  *
10  * This program is free software; you can redistribute  it and/or modify it
11  * under  the terms of  the GNU General  Public License as published by the
12  * Free Software Foundation;  either version 2 of the  License, or (at your
13  * option) any later version.
14  */
15
16 #include <linux/config.h>
17 #include <linux/stddef.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/errno.h>
21 #include <linux/reboot.h>
22 #include <linux/pci.h>
23 #include <linux/kdev_t.h>
24 #include <linux/major.h>
25 #include <linux/console.h>
26 #include <linux/delay.h>
27 #include <linux/irq.h>
28 #include <linux/seq_file.h>
29 #include <linux/serial.h>
30 #include <linux/module.h>
31 #include <linux/root_dev.h>
32 #include <linux/initrd.h>
33 #include <linux/tty.h>
34 #include <linux/serial_core.h>
35
36 #include <asm/system.h>
37 #include <asm/pgtable.h>
38 #include <asm/page.h>
39 #include <asm/atomic.h>
40 #include <asm/time.h>
41 #include <asm/io.h>
42 #include <asm/machdep.h>
43 #include <asm/prom.h>
44 #include <asm/open_pic.h>
45 #include <asm/bootinfo.h>
46 #include <asm/pci-bridge.h>
47 #include <asm/mpc85xx.h>
48 #include <asm/irq.h>
49 #include <asm/immap_85xx.h>
50 #include <asm/immap_cpm2.h>
51 #include <asm/ocp.h>
52 #include <asm/kgdb.h>
53
54 #include <mm/mmu_decl.h>
55 #include <syslib/cpm2_pic.h>
56 #include <syslib/ppc85xx_common.h>
57 #include <syslib/ppc85xx_setup.h>
58
59
60 #ifndef CONFIG_PCI
61 unsigned long isa_io_base = 0;
62 unsigned long isa_mem_base = 0;
63 #endif
64
65 extern unsigned long total_memory;      /* in mm/init */
66
67 unsigned char __res[sizeof (bd_t)];
68
69 static int cds_pci_slot = 2;
70 static volatile u8 * cadmus;
71
72 /* Internal interrupts are all Level Sensitive, and Positive Polarity */
73
74 static u_char mpc85xx_cds_openpic_initsenses[] __initdata = {
75         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal  0: L2 Cache */
76         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal  1: ECM */
77         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal  2: DDR DRAM */
78         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal  3: LBIU */
79         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal  4: DMA 0 */
80         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal  5: DMA 1 */
81         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal  6: DMA 2 */
82         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal  7: DMA 3 */
83         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal  8: PCI/PCI-X */
84         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal  9: RIO Inbound Port Write Error */
85         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 10: RIO Doorbell Inbound */
86         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 11: RIO Outbound Message */
87         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 12: RIO Inbound Message */
88         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 13: TSEC 0 Transmit */
89         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 14: TSEC 0 Receive */
90         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 15: Unused */
91         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 16: Unused */
92         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 17: Unused */
93         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 18: TSEC 0 Receive/Transmit Error */
94         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 19: TSEC 1 Transmit */
95         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 20: TSEC 1 Receive */
96         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 21: Unused */
97         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 22: Unused */
98         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 23: Unused */
99         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 24: TSEC 1 Receive/Transmit Error */
100         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 25: Fast Ethernet */
101         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 26: DUART */
102         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 27: I2C */
103         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 28: Performance Monitor */
104         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 29: Unused */
105         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 30: CPM */
106         (IRQ_SENSE_LEVEL | IRQ_POLARITY_POSITIVE),        /* Internal 31: Unused */
107 #if defined(CONFIG_PCI)
108         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 0: PCI1 slot */
109         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 1: PCI1 slot */
110         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 2: PCI1 slot */
111         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 3: PCI1 slot */
112 #else
113         0x0,                            /* External  0: */
114         0x0,                            /* External  1: */
115         0x0,                            /* External  2: */
116         0x0,                            /* External  3: */
117 #endif
118         0x0,                            /* External  4: */
119         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 5: PHY */
120         0x0,                            /* External  6: */
121         0x0,                            /* External  7: */
122         0x0,                            /* External  8: */
123         0x0,                            /* External  9: */
124         0x0,                            /* External 10: */
125 #if defined(CONFIG_85xx_PCI2) && defined(CONFIG_PCI)
126         (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE),      /* External 11: PCI2 slot 0 */
127 #else
128         0x0,                            /* External 11: */
129 #endif
130 };
131
132 struct ocp_gfar_data mpc85xx_tsec1_def = {
133         .interruptTransmit = MPC85xx_IRQ_TSEC1_TX,
134         .interruptError = MPC85xx_IRQ_TSEC1_ERROR,
135         .interruptReceive = MPC85xx_IRQ_TSEC1_RX,
136         .interruptPHY = MPC85xx_IRQ_EXT5,
137         .flags = (GFAR_HAS_GIGABIT | GFAR_HAS_MULTI_INTR |
138                         GFAR_HAS_PHY_INTR),
139         .phyid = 0,
140         .phyregidx = 0,
141 };
142
143 struct ocp_gfar_data mpc85xx_tsec2_def = {
144         .interruptTransmit = MPC85xx_IRQ_TSEC2_TX,
145         .interruptError = MPC85xx_IRQ_TSEC2_ERROR,
146         .interruptReceive = MPC85xx_IRQ_TSEC2_RX,
147         .interruptPHY = MPC85xx_IRQ_EXT5,
148         .flags = (GFAR_HAS_GIGABIT | GFAR_HAS_MULTI_INTR |
149                         GFAR_HAS_PHY_INTR),
150         .phyid = 1,
151         .phyregidx = 0,
152 };
153
154 struct ocp_fs_i2c_data mpc85xx_i2c1_def = {
155         .flags = FS_I2C_SEPARATE_DFSRR,
156 };
157
158 /* ************************************************************************ */
159 int
160 mpc85xx_cds_show_cpuinfo(struct seq_file *m)
161 {
162         uint pvid, svid, phid1;
163         uint memsize = total_memory;
164         bd_t *binfo = (bd_t *) __res;
165         unsigned int freq;
166
167         /* get the core frequency */
168         freq = binfo->bi_intfreq;
169
170         pvid = mfspr(PVR);
171         svid = mfspr(SVR);
172
173         seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
174         seq_printf(m, "Machine\t\t: CDS (%x)\n", cadmus[CM_VER]);
175         seq_printf(m, "bus freq\t: %u.%.6u MHz\n", freq / 1000000,
176                    freq % 1000000);
177         seq_printf(m, "PVR\t\t: 0x%x\n", pvid);
178         seq_printf(m, "SVR\t\t: 0x%x\n", svid);
179
180         /* Display cpu Pll setting */
181         phid1 = mfspr(HID1);
182         seq_printf(m, "PLL setting\t: 0x%x\n", ((phid1 >> 24) & 0x3f));
183
184         /* Display the amount of memory */
185         seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
186
187         return 0;
188 }
189
190 #ifdef CONFIG_CPM2
191 static void cpm2_cascade(int irq, void *dev_id, struct pt_regs *regs)
192 {
193         while((irq = cpm2_get_irq(regs)) >= 0)
194         {
195                 ppc_irq_dispatch_handler(regs,irq);
196         }
197 }
198 #endif /* CONFIG_CPM2 */
199
200 void __init
201 mpc85xx_cds_init_IRQ(void)
202 {
203         bd_t *binfo = (bd_t *) __res;
204 #ifdef CONFIG_CPM2
205         volatile cpm2_map_t *immap = cpm2_immr;
206         int i;
207 #endif
208
209         /* Determine the Physical Address of the OpenPIC regs */
210         phys_addr_t OpenPIC_PAddr = binfo->bi_immr_base + MPC85xx_OPENPIC_OFFSET;
211         OpenPIC_Addr = ioremap(OpenPIC_PAddr, MPC85xx_OPENPIC_SIZE);
212         OpenPIC_InitSenses = mpc85xx_cds_openpic_initsenses;
213         OpenPIC_NumInitSenses = sizeof (mpc85xx_cds_openpic_initsenses);
214
215         /* Skip reserved space and internal sources */
216         openpic_set_sources(0, 32, OpenPIC_Addr + 0x10200);
217         /* Map PIC IRQs 0-11 */
218         openpic_set_sources(32, 12, OpenPIC_Addr + 0x10000);
219
220         /* we let openpic interrupts starting from an offset, to
221          * leave space for cascading interrupts underneath.
222          */
223         openpic_init(MPC85xx_OPENPIC_IRQ_OFFSET);
224
225 #ifdef CONFIG_CPM2
226         /* disable all CPM interupts */
227         immap->im_intctl.ic_simrh = 0x0;
228         immap->im_intctl.ic_simrl = 0x0;
229
230         for (i = CPM_IRQ_OFFSET; i < (NR_CPM_INTS + CPM_IRQ_OFFSET); i++)
231                 irq_desc[i].handler = &cpm2_pic;
232
233         /* Initialize the default interrupt mapping priorities,
234          * in case the boot rom changed something on us.
235          */
236         immap->im_intctl.ic_sicr = 0;
237         immap->im_intctl.ic_scprrh = 0x05309770;
238         immap->im_intctl.ic_scprrl = 0x05309770;
239
240         request_irq(MPC85xx_IRQ_CPM, cpm2_cascade, SA_INTERRUPT, "cpm2_cascade", NULL);
241 #endif
242
243         return;
244 }
245
246 #ifdef CONFIG_PCI
247 /*
248  * interrupt routing
249  */
250 int
251 mpc85xx_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
252 {
253         struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
254
255         if (!hose->index)
256         {
257                 /* Handle PCI1 interrupts */
258                 char pci_irq_table[][4] =
259                         /*
260                          *      PCI IDSEL/INTPIN->INTLINE
261                          *        A      B      C      D
262                          */
263
264                         /* Note IRQ assignment for slots is based on which slot the elysium is
265                          * in -- in this setup elysium is in slot #2 (this PIRQA as first
266                          * interrupt on slot */
267                 {
268                         { 0, 1, 2, 3 }, /* 16 - PMC */
269                         { 3, 0, 0, 0 }, /* 17 P2P (Tsi320) */
270                         { 0, 1, 2, 3 }, /* 18 - Slot 1 */
271                         { 1, 2, 3, 0 }, /* 19 - Slot 2 */
272                         { 2, 3, 0, 1 }, /* 20 - Slot 3 */
273                         { 3, 0, 1, 2 }, /* 21 - Slot 4 */
274                 };
275
276                 const long min_idsel = 16, max_idsel = 21, irqs_per_slot = 4;
277                 int i, j;
278
279                 for (i = 0; i < 6; i++)
280                         for (j = 0; j < 4; j++)
281                                 pci_irq_table[i][j] =
282                                         ((pci_irq_table[i][j] + 5 -
283                                           cds_pci_slot) & 0x3) + PIRQ0A;
284
285                 return PCI_IRQ_TABLE_LOOKUP;
286         } else {
287                 /* Handle PCI2 interrupts (if we have one) */
288                 char pci_irq_table[][4] =
289                 {
290                         /*
291                          * We only have one slot and one interrupt
292                          * going to PIRQA - PIRQD */
293                         { PIRQ1A, PIRQ1A, PIRQ1A, PIRQ1A }, /* 21 - slot 0 */
294                 };
295
296                 const long min_idsel = 21, max_idsel = 21, irqs_per_slot = 4;
297
298                 return PCI_IRQ_TABLE_LOOKUP;
299         }
300 }
301
302 #define ARCADIA_HOST_BRIDGE_IDSEL     17
303 #define ARCADIA_2ND_BRIDGE_IDSEL     3
304
305 int
306 mpc85xx_exclude_device(u_char bus, u_char devfn)
307 {
308         if (bus == 0 && PCI_SLOT(devfn) == 0)
309                 return PCIBIOS_DEVICE_NOT_FOUND;
310 #ifdef CONFIG_85xx_PCI2
311         /* With the current code we know PCI2 will be bus 2, however this may
312          * not be guarnteed */
313         if (bus == 2 && PCI_SLOT(devfn) == 0)
314                 return PCIBIOS_DEVICE_NOT_FOUND;
315 #endif
316         /* We explicitly do not go past the Tundra 320 Bridge */
317         if (bus == 1)
318                 return PCIBIOS_DEVICE_NOT_FOUND;
319         if ((bus == 0) && (PCI_SLOT(devfn) == ARCADIA_2ND_BRIDGE_IDSEL))
320                 return PCIBIOS_DEVICE_NOT_FOUND;
321         else
322                 return PCIBIOS_SUCCESSFUL;
323 }
324 #endif /* CONFIG_PCI */
325
326 /* ************************************************************************
327  *
328  * Setup the architecture
329  *
330  */
331 static void __init
332 mpc85xx_cds_setup_arch(void)
333 {
334         struct ocp_def *def;
335         struct ocp_gfar_data *einfo;
336         bd_t *binfo = (bd_t *) __res;
337         unsigned int freq;
338
339         /* get the core frequency */
340         freq = binfo->bi_intfreq;
341
342         printk("mpc85xx_cds_setup_arch\n");
343
344 #ifdef CONFIG_CPM2
345         cpm2_reset();
346 #endif
347
348         cadmus = ioremap(CADMUS_BASE, CADMUS_SIZE);
349         cds_pci_slot = ((cadmus[CM_CSR] >> 6) & 0x3) + 1;
350         printk("CDS Version = %x in PCI slot %d\n", cadmus[CM_VER], cds_pci_slot);
351
352         /* Set loops_per_jiffy to a half-way reasonable value,
353            for use until calibrate_delay gets called. */
354         loops_per_jiffy = freq / HZ;
355
356 #ifdef CONFIG_PCI
357         /* setup PCI host bridges */
358         mpc85xx_setup_hose();
359 #endif
360
361 #ifdef CONFIG_SERIAL_8250
362         mpc85xx_early_serial_map();
363 #endif
364
365 #ifdef CONFIG_SERIAL_TEXT_DEBUG
366         /* Invalidate the entry we stole earlier the serial ports
367          * should be properly mapped */
368         invalidate_tlbcam_entry(NUM_TLBCAMS - 1);
369 #endif
370
371         def = ocp_get_one_device(OCP_VENDOR_FREESCALE, OCP_FUNC_GFAR, 0);
372         if (def) {
373                 einfo = (struct ocp_gfar_data *) def->additions;
374                 memcpy(einfo->mac_addr, binfo->bi_enetaddr, 6);
375         }
376
377         def = ocp_get_one_device(OCP_VENDOR_FREESCALE, OCP_FUNC_GFAR, 1);
378         if (def) {
379                 einfo = (struct ocp_gfar_data *) def->additions;
380                 memcpy(einfo->mac_addr, binfo->bi_enet1addr, 6);
381         }
382
383 #ifdef CONFIG_BLK_DEV_INITRD
384         if (initrd_start)
385                 ROOT_DEV = Root_RAM0;
386         else
387 #endif
388 #ifdef  CONFIG_ROOT_NFS
389                 ROOT_DEV = Root_NFS;
390 #else
391                 ROOT_DEV = Root_HDA1;
392 #endif
393
394         ocp_for_each_device(mpc85xx_update_paddr_ocp, &(binfo->bi_immr_base));
395 }
396
397 /* ************************************************************************ */
398 void __init
399 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
400               unsigned long r6, unsigned long r7)
401 {
402         /* parse_bootinfo must always be called first */
403         parse_bootinfo(find_bootinfo());
404
405         /*
406          * If we were passed in a board information, copy it into the
407          * residual data area.
408          */
409         if (r3) {
410                 memcpy((void *) __res, (void *) (r3 + KERNELBASE),
411                        sizeof (bd_t));
412
413         }
414 #ifdef CONFIG_SERIAL_TEXT_DEBUG
415         {
416                 bd_t *binfo = (bd_t *) __res;
417
418                 /* Use the last TLB entry to map CCSRBAR to allow access to DUART regs */
419                 settlbcam(NUM_TLBCAMS - 1, binfo->bi_immr_base,
420                         binfo->bi_immr_base, MPC85xx_CCSRBAR_SIZE, _PAGE_IO, 0);
421
422         }
423 #endif
424
425 #if defined(CONFIG_BLK_DEV_INITRD)
426         /*
427          * If the init RAM disk has been configured in, and there's a valid
428          * starting address for it, set it up.
429          */
430         if (r4) {
431                 initrd_start = r4 + KERNELBASE;
432                 initrd_end = r5 + KERNELBASE;
433         }
434 #endif                          /* CONFIG_BLK_DEV_INITRD */
435
436         /* Copy the kernel command line arguments to a safe place. */
437
438         if (r6) {
439                 *(char *) (r7 + KERNELBASE) = 0;
440                 strcpy(cmd_line, (char *) (r6 + KERNELBASE));
441         }
442
443         /* setup the PowerPC module struct */
444         ppc_md.setup_arch = mpc85xx_cds_setup_arch;
445         ppc_md.show_cpuinfo = mpc85xx_cds_show_cpuinfo;
446
447         ppc_md.init_IRQ = mpc85xx_cds_init_IRQ;
448         ppc_md.get_irq = openpic_get_irq;
449
450         ppc_md.restart = mpc85xx_restart;
451         ppc_md.power_off = mpc85xx_power_off;
452         ppc_md.halt = mpc85xx_halt;
453
454         ppc_md.find_end_of_memory = mpc85xx_find_end_of_memory;
455
456         ppc_md.time_init = NULL;
457         ppc_md.set_rtc_time = NULL;
458         ppc_md.get_rtc_time = NULL;
459         ppc_md.calibrate_decr = mpc85xx_calibrate_decr;
460
461 #if defined(CONFIG_SERIAL_8250) && defined(CONFIG_SERIAL_TEXT_DEBUG)
462         ppc_md.progress = gen550_progress;
463 #endif /* CONFIG_SERIAL_8250 && CONFIG_SERIAL_TEXT_DEBUG */
464
465         if (ppc_md.progress)
466                 ppc_md.progress("mpc85xx_cds_init(): exit", 0);
467
468         return;
469 }