2 * MPC86xx HPCN board specific routines
4 * Recode: ZHANG WEI <wei.zhang@freescale.com>
5 * Initial author: Xianghua Xiao <x.xiao@freescale.com>
7 * Copyright 2006 Freescale Semiconductor Inc.
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.
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>
23 #include <asm/system.h>
25 #include <asm/machdep.h>
26 #include <asm/pci-bridge.h>
27 #include <asm/mpc86xx.h>
29 #include <mm/mmu_decl.h>
31 #include <asm/i8259.h>
35 #include <sysdev/fsl_soc.h>
38 #include "mpc8641_hpcn.h"
43 #define DBG(fmt...) do { printk(KERN_ERR fmt); } while(0)
45 #define DBG(fmt...) do { } while(0)
49 unsigned long isa_io_base = 0;
50 unsigned long isa_mem_base = 0;
51 unsigned long pci_dram_offset = 0;
55 static void mpc86xx_8259_cascade(unsigned int irq, struct irq_desc *desc,
58 unsigned int cascade_irq = i8259_irq(regs);
59 if (cascade_irq != NO_IRQ)
60 generic_handle_irq(cascade_irq, regs);
65 mpc86xx_hpcn_init_irq(void)
68 struct device_node *np, *cascade_node = NULL;
70 phys_addr_t openpic_paddr;
72 np = of_find_node_by_type(NULL, "open-pic");
76 /* Determine the Physical Address of the OpenPIC regs */
77 openpic_paddr = get_immrbase() + MPC86xx_OPENPIC_OFFSET;
79 /* Alloc mpic structure and per isu has 16 INT entries. */
80 mpic1 = mpic_alloc(np, openpic_paddr,
81 MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
84 BUG_ON(mpic1 == NULL);
86 mpic_assign_isu(mpic1, 0, openpic_paddr + 0x10000);
88 /* 48 Internal Interrupts */
89 mpic_assign_isu(mpic1, 1, openpic_paddr + 0x10200);
90 mpic_assign_isu(mpic1, 2, openpic_paddr + 0x10400);
91 mpic_assign_isu(mpic1, 3, openpic_paddr + 0x10600);
93 /* 16 External interrupts
94 * Moving them from [0 - 15] to [64 - 79]
96 mpic_assign_isu(mpic1, 4, openpic_paddr + 0x10000);
101 /* Initialize i8259 controller */
102 for_each_node_by_type(np, "interrupt-controller")
103 if (device_is_compatible(np, "chrp,iic")) {
107 if (cascade_node == NULL) {
108 printk(KERN_DEBUG "mpc86xxhpcn: no ISA interrupt controller\n");
112 cascade_irq = irq_of_parse_and_map(cascade_node, 0);
113 if (cascade_irq == NO_IRQ) {
114 printk(KERN_ERR "mpc86xxhpcn: failed to map cascade interrupt");
117 DBG("mpc86xxhpcn: cascade mapped to irq %d\n", cascade_irq);
119 i8259_init(cascade_node, 0);
120 set_irq_chained_handler(cascade_irq, mpc86xx_8259_cascade);
126 enum pirq{PIRQA = 8, PIRQB, PIRQC, PIRQD, PIRQE, PIRQF, PIRQG, PIRQH};
127 const unsigned char uli1575_irq_route_table[16] = {
138 0x3, /* 10: 0b0011 */
139 0x9, /* 11: 0b1001 */
140 0xb, /* 12: 0b1011 */
141 0, /* 13: Reserved */
142 0xd, /* 14, 0b1101 */
143 0xf, /* 15, 0b1111 */
147 get_pci_irq_from_of(struct pci_controller *hose, int slot, int pin)
151 struct device_node *hosenode = hose ? hose->arch_data : NULL;
153 if (!hosenode) return -EINVAL;
155 laddr[0] = (hose->first_busno << 16) | (PCI_DEVFN(slot, 0) << 8);
156 laddr[1] = laddr[2] = 0;
157 of_irq_map_raw(hosenode, &pin, laddr, &oirq);
158 DBG("mpc86xx_hpcn: pci irq addr %x, slot %d, pin %d, irq %d\n",
159 laddr[0], slot, pin, oirq.specifier[0]);
160 return oirq.specifier[0];
163 static void __devinit quirk_uli1575(struct pci_dev *dev)
166 struct pci_controller *hose = pci_bus_to_host(dev->bus);
167 unsigned char irq2pin[16];
168 unsigned long pirq_map_word = 0;
173 * ULI1575 interrupts route setup
175 memset(irq2pin, 0, 16); /* Initialize default value 0 */
178 * PIRQA -> PIRQD mapping read from OF-tree
180 * interrupts for PCI slot0 -- PIRQA / PIRQB / PIRQC / PIRQD
181 * PCI slot1 -- PIRQB / PIRQC / PIRQD / PIRQA
183 for (i = 0; i < 4; i++){
184 irq = get_pci_irq_from_of(hose, 17, i + 1);
185 if (irq > 0 && irq < 16)
186 irq2pin[irq] = PIRQA + i;
188 printk(KERN_WARNING "ULI1575 device"
189 "(slot %d, pin %d) irq %d is invalid.\n",
194 * PIRQE -> PIRQF mapping set manually
202 for (i = 0; i < 4; i++) irq2pin[i + 9] = PIRQE + i;
204 /* Set IRQ-PIRQ Mapping to ULI1575 */
205 for (i = 0; i < 16; i++)
207 pirq_map_word |= (uli1575_irq_route_table[i] & 0xf)
208 << ((irq2pin[i] - PIRQA) * 4);
210 /* ULI1575 IRQ mapping conf register default value is 0xb9317542 */
211 DBG("Setup ULI1575 IRQ mapping configuration register value = 0x%x\n",
213 pci_write_config_dword(dev, 0x48, pirq_map_word);
215 #define ULI1575_SET_DEV_IRQ(slot, pin, reg) \
218 irq = get_pci_irq_from_of(hose, slot, pin); \
219 if (irq > 0 && irq < 16) \
220 pci_write_config_byte(dev, reg, irq2pin[irq]); \
222 printk(KERN_WARNING "ULI1575 device" \
223 "(slot %d, pin %d) irq %d is invalid.\n", \
227 /* USB 1.1 OHCI controller 1, slot 28, pin 1 */
228 ULI1575_SET_DEV_IRQ(28, 1, 0x86);
230 /* USB 1.1 OHCI controller 2, slot 28, pin 2 */
231 ULI1575_SET_DEV_IRQ(28, 2, 0x87);
233 /* USB 1.1 OHCI controller 3, slot 28, pin 3 */
234 ULI1575_SET_DEV_IRQ(28, 3, 0x88);
236 /* USB 2.0 controller, slot 28, pin 4 */
237 irq = get_pci_irq_from_of(hose, 28, 4);
238 if (irq >= 0 && irq <=15)
239 pci_write_config_dword(dev, 0x74, uli1575_irq_route_table[irq]);
241 /* Audio controller, slot 29, pin 1 */
242 ULI1575_SET_DEV_IRQ(29, 1, 0x8a);
244 /* Modem controller, slot 29, pin 2 */
245 ULI1575_SET_DEV_IRQ(29, 2, 0x8b);
247 /* HD audio controller, slot 29, pin 3 */
248 ULI1575_SET_DEV_IRQ(29, 3, 0x8c);
250 /* SMB interrupt: slot 30, pin 1 */
251 ULI1575_SET_DEV_IRQ(30, 1, 0x8e);
253 /* PMU ACPI SCI interrupt: slot 30, pin 2 */
254 ULI1575_SET_DEV_IRQ(30, 2, 0x8f);
256 /* Serial ATA interrupt: slot 31, pin 1 */
257 ULI1575_SET_DEV_IRQ(31, 1, 0x8d);
259 /* Primary PATA IDE IRQ: 14
260 * Secondary PATA IDE IRQ: 15
262 pci_write_config_byte(dev, 0x44, 0x30 | uli1575_irq_route_table[14]);
263 pci_write_config_byte(dev, 0x75, uli1575_irq_route_table[15]);
265 /* Set IRQ14 and IRQ15 to legacy IRQs */
266 pci_read_config_word(dev, 0x46, &temp);
268 pci_write_config_word(dev, 0x46, temp);
270 /* Set i8259 interrupt trigger
286 #undef ULI1575_SET_DEV_IRQ
289 static void __devinit quirk_uli5288(struct pci_dev *dev)
293 pci_read_config_byte(dev,0x83,&c);
295 pci_write_config_byte(dev, 0x83, c);
297 pci_write_config_byte(dev, 0x09, 0x01);
298 pci_write_config_byte(dev, 0x0a, 0x06);
300 pci_read_config_byte(dev,0x83,&c);
302 pci_write_config_byte(dev, 0x83, c);
304 pci_read_config_byte(dev,0x84,&c);
306 pci_write_config_byte(dev, 0x84, c);
309 static void __devinit quirk_uli5229(struct pci_dev *dev)
312 pci_write_config_word(dev, 0x04, 0x0405);
313 pci_read_config_word(dev, 0x4a, &temp);
315 pci_write_config_word(dev, 0x4a, temp);
318 static void __devinit early_uli5249(struct pci_dev *dev)
321 pci_write_config_word(dev, 0x04, 0x0007);
322 pci_read_config_byte(dev, 0x7c, &temp);
323 pci_write_config_byte(dev, 0x7c, 0x80);
324 pci_write_config_byte(dev, 0x09, 0x01);
325 pci_write_config_byte(dev, 0x7c, temp);
329 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x1575, quirk_uli1575);
330 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5288, quirk_uli5288);
331 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);
332 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AL, 0x5249, early_uli5249);
333 #endif /* CONFIG_PCI */
337 mpc86xx_hpcn_setup_arch(void)
339 struct device_node *np;
342 ppc_md.progress("mpc86xx_hpcn_setup_arch()", 0);
344 np = of_find_node_by_type(NULL, "cpu");
348 fp = (int *)get_property(np, "clock-frequency", NULL);
350 loops_per_jiffy = *fp / HZ;
352 loops_per_jiffy = 50000000 / HZ;
357 for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
360 ppc_md.pci_exclude_device = mpc86xx_exclude_device;
363 printk("MPC86xx HPCN board from Freescale Semiconductor\n");
365 #ifdef CONFIG_ROOT_NFS
368 ROOT_DEV = Root_HDA1;
378 mpc86xx_hpcn_show_cpuinfo(struct seq_file *m)
380 struct device_node *root;
381 uint memsize = total_memory;
382 const char *model = "";
383 uint svid = mfspr(SPRN_SVR);
385 seq_printf(m, "Vendor\t\t: Freescale Semiconductor\n");
387 root = of_find_node_by_path("/");
389 model = get_property(root, "model", NULL);
390 seq_printf(m, "Machine\t\t: %s\n", model);
393 seq_printf(m, "SVR\t\t: 0x%x\n", svid);
394 seq_printf(m, "Memory\t\t: %d MB\n", memsize / (1024 * 1024));
398 void __init mpc86xx_hpcn_pcibios_fixup(void)
400 struct pci_dev *dev = NULL;
402 for_each_pci_dev(dev)
403 pci_read_irq_line(dev);
408 * Called very early, device-tree isn't unflattened
410 static int __init mpc86xx_hpcn_probe(void)
412 unsigned long root = of_get_flat_dt_root();
414 if (of_flat_dt_is_compatible(root, "mpc86xx"))
415 return 1; /* Looks good */
422 mpc86xx_restart(char *cmd)
426 rstcr = ioremap(get_immrbase() + MPC86XX_RSTCR_OFFSET, 0x100);
430 /* Assert reset request to Reset Control Register */
431 out_be32(rstcr, 0x2);
438 mpc86xx_time_init(void)
442 /* Set the time base to zero */
446 temp = mfspr(SPRN_HID0);
448 mtspr(SPRN_HID0, temp);
449 asm volatile("isync");
455 define_machine(mpc86xx_hpcn) {
456 .name = "MPC86xx HPCN",
457 .probe = mpc86xx_hpcn_probe,
458 .setup_arch = mpc86xx_hpcn_setup_arch,
459 .init_IRQ = mpc86xx_hpcn_init_irq,
460 .show_cpuinfo = mpc86xx_hpcn_show_cpuinfo,
461 .pcibios_fixup = mpc86xx_hpcn_pcibios_fixup,
462 .get_irq = mpic_get_irq,
463 .restart = mpc86xx_restart,
464 .time_init = mpc86xx_time_init,
465 .calibrate_decr = generic_calibrate_decr,
466 .progress = udbg_progress,