]> err.no Git - linux-2.6/blob - arch/powerpc/platforms/86xx/mpc86xx_hpcn.c
[POWERPC] Reworked interrupt numbers for OpenPIC based Freescale chips
[linux-2.6] / arch / powerpc / platforms / 86xx / mpc86xx_hpcn.c
1 /*
2  * MPC86xx HPCN board specific routines
3  *
4  * Recode: ZHANG WEI <wei.zhang@freescale.com>
5  * Initial author: Xianghua Xiao <x.xiao@freescale.com>
6  *
7  * Copyright 2006 Freescale Semiconductor Inc.
8  *
9  * This program is free software; you can redistribute  it and/or modify it
10  * under  the terms of  the GNU General  Public License as published by the
11  * Free Software Foundation;  either version 2 of the  License, or (at your
12  * option) any later version.
13  */
14
15 #include <linux/stddef.h>
16 #include <linux/kernel.h>
17 #include <linux/pci.h>
18 #include <linux/kdev_t.h>
19 #include <linux/delay.h>
20 #include <linux/seq_file.h>
21
22 #include <asm/system.h>
23 #include <asm/time.h>
24 #include <asm/machdep.h>
25 #include <asm/pci-bridge.h>
26 #include <asm/mpc86xx.h>
27 #include <asm/prom.h>
28 #include <mm/mmu_decl.h>
29 #include <asm/udbg.h>
30 #include <asm/i8259.h>
31
32 #include <asm/mpic.h>
33
34 #include <sysdev/fsl_soc.h>
35
36 #include "mpc86xx.h"
37 #include "mpc8641_hpcn.h"
38
39 #undef DEBUG
40
41 #ifdef DEBUG
42 #define DBG(fmt...) do { printk(KERN_ERR fmt); } while(0)
43 #else
44 #define DBG(fmt...) do { } while(0)
45 #endif
46
47 #ifdef CONFIG_PCI
48 static void mpc86xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
49 {
50         unsigned int cascade_irq = i8259_irq();
51         if (cascade_irq != NO_IRQ)
52                 generic_handle_irq(cascade_irq);
53         desc->chip->eoi(irq);
54 }
55 #endif  /* CONFIG_PCI */
56
57 void __init
58 mpc86xx_hpcn_init_irq(void)
59 {
60         struct mpic *mpic1;
61         struct device_node *np;
62         struct resource res;
63 #ifdef CONFIG_PCI
64         struct device_node *cascade_node = NULL;
65         int cascade_irq;
66 #endif
67
68         /* Determine PIC address. */
69         np = of_find_node_by_type(NULL, "open-pic");
70         if (np == NULL)
71                 return;
72         of_address_to_resource(np, 0, &res);
73
74         /* Alloc mpic structure and per isu has 16 INT entries. */
75         mpic1 = mpic_alloc(np, res.start,
76                         MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
77                         0, 256, " MPIC     ");
78         BUG_ON(mpic1 == NULL);
79
80         mpic_init(mpic1);
81
82 #ifdef CONFIG_PCI
83         /* Initialize i8259 controller */
84         for_each_node_by_type(np, "interrupt-controller")
85                 if (of_device_is_compatible(np, "chrp,iic")) {
86                         cascade_node = np;
87                         break;
88                 }
89         if (cascade_node == NULL) {
90                 printk(KERN_DEBUG "mpc86xxhpcn: no ISA interrupt controller\n");
91                 return;
92         }
93
94         cascade_irq = irq_of_parse_and_map(cascade_node, 0);
95         if (cascade_irq == NO_IRQ) {
96                 printk(KERN_ERR "mpc86xxhpcn: failed to map cascade interrupt");
97                 return;
98         }
99         DBG("mpc86xxhpcn: cascade mapped to irq %d\n", cascade_irq);
100
101         i8259_init(cascade_node, 0);
102         of_node_put(cascade_node);
103
104         set_irq_chained_handler(cascade_irq, mpc86xx_8259_cascade);
105 #endif
106 }
107
108 #ifdef CONFIG_PCI
109
110 enum pirq{PIRQA = 8, PIRQB, PIRQC, PIRQD, PIRQE, PIRQF, PIRQG, PIRQH};
111 const unsigned char uli1575_irq_route_table[16] = {
112         0,      /* 0: Reserved */
113         0x8,    /* 1: 0b1000 */
114         0,      /* 2: Reserved */
115         0x2,    /* 3: 0b0010 */
116         0x4,    /* 4: 0b0100 */
117         0x5,    /* 5: 0b0101 */
118         0x7,    /* 6: 0b0111 */
119         0x6,    /* 7: 0b0110 */
120         0,      /* 8: Reserved */
121         0x1,    /* 9: 0b0001 */
122         0x3,    /* 10: 0b0011 */
123         0x9,    /* 11: 0b1001 */
124         0xb,    /* 12: 0b1011 */
125         0,      /* 13: Reserved */
126         0xd,    /* 14, 0b1101 */
127         0xf,    /* 15, 0b1111 */
128 };
129
130 static int __devinit
131 get_pci_irq_from_of(struct pci_controller *hose, int slot, int pin)
132 {
133         struct of_irq oirq;
134         u32 laddr[3];
135         struct device_node *hosenode = hose ? hose->arch_data : NULL;
136
137         if (!hosenode) return -EINVAL;
138
139         laddr[0] = (hose->first_busno << 16) | (PCI_DEVFN(slot, 0) << 8);
140         laddr[1] = laddr[2] = 0;
141         of_irq_map_raw(hosenode, &pin, 1, laddr, &oirq);
142         DBG("mpc86xx_hpcn: pci irq addr %x, slot %d, pin %d, irq %d\n",
143                         laddr[0], slot, pin, oirq.specifier[0]);
144         return oirq.specifier[0];
145 }
146
147 static void __devinit quirk_uli1575(struct pci_dev *dev)
148 {
149         unsigned short temp;
150         struct pci_controller *hose = pci_bus_to_host(dev->bus);
151         unsigned char irq2pin[16], c;
152         unsigned long pirq_map_word = 0;
153         u32 irq;
154         int i;
155
156         /*
157          * ULI1575 interrupts route setup
158          */
159         memset(irq2pin, 0, 16); /* Initialize default value 0 */
160
161         /*
162          * PIRQA -> PIRQD mapping read from OF-tree
163          *
164          * interrupts for PCI slot0 -- PIRQA / PIRQB / PIRQC / PIRQD
165          *                PCI slot1 -- PIRQB / PIRQC / PIRQD / PIRQA
166          */
167         for (i = 0; i < 4; i++){
168                 irq = get_pci_irq_from_of(hose, 17, i + 1);
169                 if (irq > 0 && irq < 16)
170                         irq2pin[irq] = PIRQA + i;
171                 else
172                         printk(KERN_WARNING "ULI1575 device"
173                             "(slot %d, pin %d) irq %d is invalid.\n",
174                             17, i, irq);
175         }
176
177         /*
178          * PIRQE -> PIRQF mapping set manually
179          *
180          * IRQ pin   IRQ#
181          * PIRQE ---- 9
182          * PIRQF ---- 10
183          * PIRQG ---- 11
184          * PIRQH ---- 12
185          */
186         for (i = 0; i < 4; i++) irq2pin[i + 9] = PIRQE + i;
187
188         /* Set IRQ-PIRQ Mapping to ULI1575 */
189         for (i = 0; i < 16; i++)
190                 if (irq2pin[i])
191                         pirq_map_word |= (uli1575_irq_route_table[i] & 0xf)
192                                 << ((irq2pin[i] - PIRQA) * 4);
193
194         /* ULI1575 IRQ mapping conf register default value is 0xb9317542 */
195         DBG("Setup ULI1575 IRQ mapping configuration register value = 0x%x\n",
196                         pirq_map_word);
197         pci_write_config_dword(dev, 0x48, pirq_map_word);
198
199 #define ULI1575_SET_DEV_IRQ(slot, pin, reg)                             \
200         do {                                                            \
201                 int irq;                                                \
202                 irq = get_pci_irq_from_of(hose, slot, pin);             \
203                 if (irq > 0 && irq < 16)                                \
204                         pci_write_config_byte(dev, reg, irq2pin[irq]);  \
205                 else                                                    \
206                         printk(KERN_WARNING "ULI1575 device"            \
207                             "(slot %d, pin %d) irq %d is invalid.\n",   \
208                             slot, pin, irq);                            \
209         } while(0)
210
211         /* USB 1.1 OHCI controller 1, slot 28, pin 1 */
212         ULI1575_SET_DEV_IRQ(28, 1, 0x86);
213
214         /* USB 1.1 OHCI controller 2, slot 28, pin 2 */
215         ULI1575_SET_DEV_IRQ(28, 2, 0x87);
216
217         /* USB 1.1 OHCI controller 3, slot 28, pin 3 */
218         ULI1575_SET_DEV_IRQ(28, 3, 0x88);
219
220         /* USB 2.0 controller, slot 28, pin 4 */
221         irq = get_pci_irq_from_of(hose, 28, 4);
222         if (irq >= 0 && irq <=15)
223                 pci_write_config_dword(dev, 0x74, uli1575_irq_route_table[irq]);
224
225         /* Audio controller, slot 29, pin 1 */
226         ULI1575_SET_DEV_IRQ(29, 1, 0x8a);
227
228         /* Modem controller, slot 29, pin 2 */
229         ULI1575_SET_DEV_IRQ(29, 2, 0x8b);
230
231         /* HD audio controller, slot 29, pin 3 */
232         ULI1575_SET_DEV_IRQ(29, 3, 0x8c);
233
234         /* SMB interrupt: slot 30, pin 1 */
235         ULI1575_SET_DEV_IRQ(30, 1, 0x8e);
236
237         /* PMU ACPI SCI interrupt: slot 30, pin 2 */
238         ULI1575_SET_DEV_IRQ(30, 2, 0x8f);
239
240         /* Serial ATA interrupt: slot 31, pin 1 */
241         ULI1575_SET_DEV_IRQ(31, 1, 0x8d);
242
243         /* Primary PATA IDE IRQ: 14
244          * Secondary PATA IDE IRQ: 15
245          */
246         pci_write_config_byte(dev, 0x44, 0x30 | uli1575_irq_route_table[14]);
247         pci_write_config_byte(dev, 0x75, uli1575_irq_route_table[15]);
248
249         /* Set IRQ14 and IRQ15 to legacy IRQs */
250         pci_read_config_word(dev, 0x46, &temp);
251         temp |= 0xc000;
252         pci_write_config_word(dev, 0x46, temp);
253
254         /* Set i8259 interrupt trigger
255          * IRQ 3:  Level
256          * IRQ 4:  Level
257          * IRQ 5:  Level
258          * IRQ 6:  Level
259          * IRQ 7:  Level
260          * IRQ 9:  Level
261          * IRQ 10: Level
262          * IRQ 11: Level
263          * IRQ 12: Level
264          * IRQ 14: Edge
265          * IRQ 15: Edge
266          */
267         outb(0xfa, 0x4d0);
268         outb(0x1e, 0x4d1);
269
270 #undef ULI1575_SET_DEV_IRQ
271
272         /* Disable the HD interface and enable the AC97 interface. */
273         pci_read_config_byte(dev, 0xb8, &c);
274         c &= 0x7f;
275         pci_write_config_byte(dev, 0xb8, c);
276 }
277
278 static void __devinit quirk_uli5288(struct pci_dev *dev)
279 {
280         unsigned char c;
281
282         pci_read_config_byte(dev,0x83,&c);
283         c |= 0x80;
284         pci_write_config_byte(dev, 0x83, c);
285
286         pci_write_config_byte(dev, 0x09, 0x01);
287         pci_write_config_byte(dev, 0x0a, 0x06);
288
289         pci_read_config_byte(dev,0x83,&c);
290         c &= 0x7f;
291         pci_write_config_byte(dev, 0x83, c);
292
293         pci_read_config_byte(dev,0x84,&c);
294         c |= 0x01;
295         pci_write_config_byte(dev, 0x84, c);
296 }
297
298 static void __devinit quirk_uli5229(struct pci_dev *dev)
299 {
300         unsigned short temp;
301         pci_write_config_word(dev, 0x04, 0x0405);
302         dev->class &= ~0x5;
303         pci_read_config_word(dev, 0x4a, &temp);
304         temp |= 0x1000;
305         pci_write_config_word(dev, 0x4a, temp);
306 }
307
308 static void __devinit early_uli5249(struct pci_dev *dev)
309 {
310         unsigned char temp;
311         pci_write_config_word(dev, 0x04, 0x0007);
312         pci_read_config_byte(dev, 0x7c, &temp);
313         pci_write_config_byte(dev, 0x7c, 0x80);
314         pci_write_config_byte(dev, 0x09, 0x01);
315         pci_write_config_byte(dev, 0x7c, temp);
316         dev->class |= 0x1;
317 }
318
319 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, quirk_uli1575);
320 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5288, quirk_uli5288);
321 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
322 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AL, 0x5249, early_uli5249);
323 #endif /* CONFIG_PCI */
324
325
326 static void __init
327 mpc86xx_hpcn_setup_arch(void)
328 {
329         struct device_node *np;
330
331         if (ppc_md.progress)
332                 ppc_md.progress("mpc86xx_hpcn_setup_arch()", 0);
333
334         np = of_find_node_by_type(NULL, "cpu");
335         if (np != 0) {
336                 const unsigned int *fp;
337
338                 fp = of_get_property(np, "clock-frequency", NULL);
339                 if (fp != 0)
340                         loops_per_jiffy = *fp / HZ;
341                 else
342                         loops_per_jiffy = 50000000 / HZ;
343                 of_node_put(np);
344         }
345
346 #ifdef CONFIG_PCI
347         for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
348                 mpc86xx_add_bridge(np);
349 #endif
350
351         printk("MPC86xx HPCN board from Freescale Semiconductor\n");
352
353 #ifdef CONFIG_SMP
354         mpc86xx_smp_init();
355 #endif
356 }
357
358
359 void
360 mpc86xx_hpcn_show_cpuinfo(struct seq_file *m)
361 {
362         struct device_node *root;
363         uint memsize = total_memory;
364         const char *model = "";
365         uint svid = mfspr(SPRN_SVR);
366
367         seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
368
369         root = of_find_node_by_path("/");
370         if (root)
371                 model = of_get_property(root, "model", NULL);
372         seq_printf(m, "Machine\t\t: %s\n", model);
373         of_node_put(root);
374
375         seq_printf(m, "SVR\t\t: 0x%x\n", svid);
376         seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
377 }
378
379
380 /*
381  * Called very early, device-tree isn't unflattened
382  */
383 static int __init mpc86xx_hpcn_probe(void)
384 {
385         unsigned long root = of_get_flat_dt_root();
386
387         if (of_flat_dt_is_compatible(root, "mpc86xx"))
388                 return 1;       /* Looks good */
389
390         return 0;
391 }
392
393
394 void
395 mpc86xx_restart(char *cmd)
396 {
397         void __iomem *rstcr;
398
399         rstcr = ioremap(get_immrbase() + MPC86XX_RSTCR_OFFSET, 0x100);
400
401         local_irq_disable();
402
403         /* Assert reset request to Reset Control Register */
404         out_be32(rstcr, 0x2);
405
406         /* not reached */
407 }
408
409
410 long __init
411 mpc86xx_time_init(void)
412 {
413         unsigned int temp;
414
415         /* Set the time base to zero */
416         mtspr(SPRN_TBWL, 0);
417         mtspr(SPRN_TBWU, 0);
418
419         temp = mfspr(SPRN_HID0);
420         temp |= HID0_TBEN;
421         mtspr(SPRN_HID0, temp);
422         asm volatile("isync");
423
424         return 0;
425 }
426
427
428 define_machine(mpc86xx_hpcn) {
429         .name                   = "MPC86xx HPCN",
430         .probe                  = mpc86xx_hpcn_probe,
431         .setup_arch             = mpc86xx_hpcn_setup_arch,
432         .init_IRQ               = mpc86xx_hpcn_init_irq,
433         .show_cpuinfo           = mpc86xx_hpcn_show_cpuinfo,
434         .get_irq                = mpic_get_irq,
435         .restart                = mpc86xx_restart,
436         .time_init              = mpc86xx_time_init,
437         .calibrate_decr         = generic_calibrate_decr,
438         .progress               = udbg_progress,
439 };