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