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