116d24060SKumar Gala /* 27f50382dSKumar Gala * MPC85xx DS Board Setup 316d24060SKumar Gala * 416d24060SKumar Gala * Author Xianghua Xiao (x.xiao@freescale.com) 516d24060SKumar Gala * Roy Zang <tie-fei.zang@freescale.com> 616d24060SKumar Gala * - Add PCI/PCI Exprees support 716d24060SKumar Gala * Copyright 2007 Freescale Semiconductor Inc. 816d24060SKumar Gala * 916d24060SKumar Gala * This program is free software; you can redistribute it and/or modify it 1016d24060SKumar Gala * under the terms of the GNU General Public License as published by the 1116d24060SKumar Gala * Free Software Foundation; either version 2 of the License, or (at your 1216d24060SKumar Gala * option) any later version. 1316d24060SKumar Gala */ 1416d24060SKumar Gala 1516d24060SKumar Gala #include <linux/stddef.h> 1616d24060SKumar Gala #include <linux/kernel.h> 1716d24060SKumar Gala #include <linux/pci.h> 1816d24060SKumar Gala #include <linux/kdev_t.h> 1916d24060SKumar Gala #include <linux/delay.h> 2016d24060SKumar Gala #include <linux/seq_file.h> 2116d24060SKumar Gala #include <linux/interrupt.h> 221028d4f1SSebastian Siewior #include <linux/of_platform.h> 2316d24060SKumar Gala 2416d24060SKumar Gala #include <asm/system.h> 2516d24060SKumar Gala #include <asm/time.h> 2616d24060SKumar Gala #include <asm/machdep.h> 2716d24060SKumar Gala #include <asm/pci-bridge.h> 2816d24060SKumar Gala #include <mm/mmu_decl.h> 2916d24060SKumar Gala #include <asm/prom.h> 3016d24060SKumar Gala #include <asm/udbg.h> 3116d24060SKumar Gala #include <asm/mpic.h> 3216d24060SKumar Gala #include <asm/i8259.h> 3316d24060SKumar Gala 3416d24060SKumar Gala #include <sysdev/fsl_soc.h> 3516d24060SKumar Gala #include <sysdev/fsl_pci.h> 3616d24060SKumar Gala 3716d24060SKumar Gala #undef DEBUG 3816d24060SKumar Gala 3916d24060SKumar Gala #ifdef DEBUG 40e48b1b45SHarvey Harrison #define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args) 4116d24060SKumar Gala #else 4216d24060SKumar Gala #define DBG(fmt, args...) 4316d24060SKumar Gala #endif 4416d24060SKumar Gala 4516d24060SKumar Gala #ifdef CONFIG_PPC_I8259 467f50382dSKumar Gala static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc) 4716d24060SKumar Gala { 4816d24060SKumar Gala unsigned int cascade_irq = i8259_irq(); 4916d24060SKumar Gala 5016d24060SKumar Gala if (cascade_irq != NO_IRQ) { 5116d24060SKumar Gala generic_handle_irq(cascade_irq); 5216d24060SKumar Gala } 5316d24060SKumar Gala desc->chip->eoi(irq); 5416d24060SKumar Gala } 5516d24060SKumar Gala #endif /* CONFIG_PPC_I8259 */ 5616d24060SKumar Gala 577f50382dSKumar Gala void __init mpc85xx_ds_pic_init(void) 5816d24060SKumar Gala { 5916d24060SKumar Gala struct mpic *mpic; 6016d24060SKumar Gala struct resource r; 6116d24060SKumar Gala struct device_node *np = NULL; 6216d24060SKumar Gala #ifdef CONFIG_PPC_I8259 6316d24060SKumar Gala struct device_node *cascade_node = NULL; 6416d24060SKumar Gala int cascade_irq; 6516d24060SKumar Gala #endif 6616d24060SKumar Gala 6716d24060SKumar Gala np = of_find_node_by_type(np, "open-pic"); 6816d24060SKumar Gala 6916d24060SKumar Gala if (np == NULL) { 7016d24060SKumar Gala printk(KERN_ERR "Could not find open-pic node\n"); 7116d24060SKumar Gala return; 7216d24060SKumar Gala } 7316d24060SKumar Gala 7416d24060SKumar Gala if (of_address_to_resource(np, 0, &r)) { 7516d24060SKumar Gala printk(KERN_ERR "Failed to map mpic register space\n"); 7616d24060SKumar Gala of_node_put(np); 7716d24060SKumar Gala return; 7816d24060SKumar Gala } 7916d24060SKumar Gala 8016d24060SKumar Gala mpic = mpic_alloc(np, r.start, 81*741edc49SJason Jin MPIC_PRIMARY | MPIC_WANTS_RESET | 82*741edc49SJason Jin MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS, 8316d24060SKumar Gala 0, 256, " OpenPIC "); 8416d24060SKumar Gala BUG_ON(mpic == NULL); 8516d24060SKumar Gala 8616d24060SKumar Gala mpic_init(mpic); 8716d24060SKumar Gala 8816d24060SKumar Gala #ifdef CONFIG_PPC_I8259 8916d24060SKumar Gala /* Initialize the i8259 controller */ 9016d24060SKumar Gala for_each_node_by_type(np, "interrupt-controller") 9116d24060SKumar Gala if (of_device_is_compatible(np, "chrp,iic")) { 9216d24060SKumar Gala cascade_node = np; 9316d24060SKumar Gala break; 9416d24060SKumar Gala } 9516d24060SKumar Gala 9616d24060SKumar Gala if (cascade_node == NULL) { 9716d24060SKumar Gala printk(KERN_DEBUG "Could not find i8259 PIC\n"); 9816d24060SKumar Gala return; 9916d24060SKumar Gala } 10016d24060SKumar Gala 10116d24060SKumar Gala cascade_irq = irq_of_parse_and_map(cascade_node, 0); 10216d24060SKumar Gala if (cascade_irq == NO_IRQ) { 10316d24060SKumar Gala printk(KERN_ERR "Failed to map cascade interrupt\n"); 10416d24060SKumar Gala return; 10516d24060SKumar Gala } 10616d24060SKumar Gala 1077f50382dSKumar Gala DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq); 10816d24060SKumar Gala 10916d24060SKumar Gala i8259_init(cascade_node, 0); 11016d24060SKumar Gala of_node_put(cascade_node); 11116d24060SKumar Gala 1127f50382dSKumar Gala set_irq_chained_handler(cascade_irq, mpc85xx_8259_cascade); 11316d24060SKumar Gala #endif /* CONFIG_PPC_I8259 */ 11416d24060SKumar Gala } 11516d24060SKumar Gala 11616d24060SKumar Gala #ifdef CONFIG_PCI 1177f50382dSKumar Gala static int primary_phb_addr; 11816d24060SKumar Gala extern int uses_fsl_uli_m1575; 11916d24060SKumar Gala extern int uli_exclude_device(struct pci_controller *hose, 12016d24060SKumar Gala u_char bus, u_char devfn); 12116d24060SKumar Gala 12216d24060SKumar Gala static int mpc85xx_exclude_device(struct pci_controller *hose, 12316d24060SKumar Gala u_char bus, u_char devfn) 12416d24060SKumar Gala { 12516d24060SKumar Gala struct device_node* node; 12616d24060SKumar Gala struct resource rsrc; 12716d24060SKumar Gala 12844ef3390SStephen Rothwell node = hose->dn; 12916d24060SKumar Gala of_address_to_resource(node, 0, &rsrc); 13016d24060SKumar Gala 1317f50382dSKumar Gala if ((rsrc.start & 0xfffff) == primary_phb_addr) { 13216d24060SKumar Gala return uli_exclude_device(hose, bus, devfn); 13316d24060SKumar Gala } 13416d24060SKumar Gala 13516d24060SKumar Gala return PCIBIOS_SUCCESSFUL; 13616d24060SKumar Gala } 13716d24060SKumar Gala #endif /* CONFIG_PCI */ 13816d24060SKumar Gala 13916d24060SKumar Gala /* 14016d24060SKumar Gala * Setup the architecture 14116d24060SKumar Gala */ 1427f50382dSKumar Gala static void __init mpc85xx_ds_setup_arch(void) 14316d24060SKumar Gala { 14416d24060SKumar Gala #ifdef CONFIG_PCI 14516d24060SKumar Gala struct device_node *np; 14616d24060SKumar Gala #endif 14716d24060SKumar Gala 14816d24060SKumar Gala if (ppc_md.progress) 1497f50382dSKumar Gala ppc_md.progress("mpc85xx_ds_setup_arch()", 0); 15016d24060SKumar Gala 15116d24060SKumar Gala #ifdef CONFIG_PCI 152c9438affSKumar Gala for_each_node_by_type(np, "pci") { 153c9438affSKumar Gala if (of_device_is_compatible(np, "fsl,mpc8540-pci") || 154c9438affSKumar Gala of_device_is_compatible(np, "fsl,mpc8548-pcie")) { 15516d24060SKumar Gala struct resource rsrc; 15616d24060SKumar Gala of_address_to_resource(np, 0, &rsrc); 1577f50382dSKumar Gala if ((rsrc.start & 0xfffff) == primary_phb_addr) 15816d24060SKumar Gala fsl_add_bridge(np, 1); 15916d24060SKumar Gala else 16016d24060SKumar Gala fsl_add_bridge(np, 0); 16116d24060SKumar Gala } 162c9438affSKumar Gala } 163c9438affSKumar Gala 16416d24060SKumar Gala uses_fsl_uli_m1575 = 1; 16516d24060SKumar Gala ppc_md.pci_exclude_device = mpc85xx_exclude_device; 16616d24060SKumar Gala #endif 16716d24060SKumar Gala 1687f50382dSKumar Gala printk("MPC85xx DS board from Freescale Semiconductor\n"); 16916d24060SKumar Gala } 17016d24060SKumar Gala 17116d24060SKumar Gala /* 17216d24060SKumar Gala * Called very early, device-tree isn't unflattened 17316d24060SKumar Gala */ 17416d24060SKumar Gala static int __init mpc8544_ds_probe(void) 17516d24060SKumar Gala { 17616d24060SKumar Gala unsigned long root = of_get_flat_dt_root(); 17716d24060SKumar Gala 1787f50382dSKumar Gala if (of_flat_dt_is_compatible(root, "MPC8544DS")) { 1797f50382dSKumar Gala #ifdef CONFIG_PCI 1807f50382dSKumar Gala primary_phb_addr = 0xb000; 1817f50382dSKumar Gala #endif 1827f50382dSKumar Gala return 1; 1837f50382dSKumar Gala } else { 1847f50382dSKumar Gala return 0; 1857f50382dSKumar Gala } 18616d24060SKumar Gala } 18716d24060SKumar Gala 1881028d4f1SSebastian Siewior static struct of_device_id mpc85xxds_ids[] = { 1891028d4f1SSebastian Siewior { .type = "soc", }, 1901028d4f1SSebastian Siewior { .compatible = "soc", }, 1911028d4f1SSebastian Siewior {}, 1921028d4f1SSebastian Siewior }; 1931028d4f1SSebastian Siewior 1941028d4f1SSebastian Siewior static int __init mpc85xxds_publish_devices(void) 1951028d4f1SSebastian Siewior { 1961028d4f1SSebastian Siewior return of_platform_bus_probe(NULL, mpc85xxds_ids, NULL); 1971028d4f1SSebastian Siewior } 1981028d4f1SSebastian Siewior machine_device_initcall(mpc8544_ds, mpc85xxds_publish_devices); 199*741edc49SJason Jin machine_device_initcall(mpc8572_ds, mpc85xxds_publish_devices); 2001028d4f1SSebastian Siewior 2015d54ddcbSKumar Gala /* 2025d54ddcbSKumar Gala * Called very early, device-tree isn't unflattened 2035d54ddcbSKumar Gala */ 2045d54ddcbSKumar Gala static int __init mpc8572_ds_probe(void) 2055d54ddcbSKumar Gala { 2065d54ddcbSKumar Gala unsigned long root = of_get_flat_dt_root(); 2075d54ddcbSKumar Gala 2085d54ddcbSKumar Gala if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) { 2095d54ddcbSKumar Gala #ifdef CONFIG_PCI 2105d54ddcbSKumar Gala primary_phb_addr = 0x8000; 2115d54ddcbSKumar Gala #endif 2125d54ddcbSKumar Gala return 1; 2135d54ddcbSKumar Gala } else { 2145d54ddcbSKumar Gala return 0; 2155d54ddcbSKumar Gala } 2165d54ddcbSKumar Gala } 2175d54ddcbSKumar Gala 21816d24060SKumar Gala define_machine(mpc8544_ds) { 21916d24060SKumar Gala .name = "MPC8544 DS", 22016d24060SKumar Gala .probe = mpc8544_ds_probe, 2217f50382dSKumar Gala .setup_arch = mpc85xx_ds_setup_arch, 2227f50382dSKumar Gala .init_IRQ = mpc85xx_ds_pic_init, 22316d24060SKumar Gala #ifdef CONFIG_PCI 22416d24060SKumar Gala .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 22516d24060SKumar Gala #endif 22616d24060SKumar Gala .get_irq = mpic_get_irq, 227e1c1575fSKumar Gala .restart = fsl_rstcr_restart, 22816d24060SKumar Gala .calibrate_decr = generic_calibrate_decr, 22916d24060SKumar Gala .progress = udbg_progress, 23016d24060SKumar Gala }; 2315d54ddcbSKumar Gala 2325d54ddcbSKumar Gala define_machine(mpc8572_ds) { 2335d54ddcbSKumar Gala .name = "MPC8572 DS", 2345d54ddcbSKumar Gala .probe = mpc8572_ds_probe, 2355d54ddcbSKumar Gala .setup_arch = mpc85xx_ds_setup_arch, 2365d54ddcbSKumar Gala .init_IRQ = mpc85xx_ds_pic_init, 2375d54ddcbSKumar Gala #ifdef CONFIG_PCI 2385d54ddcbSKumar Gala .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 2395d54ddcbSKumar Gala #endif 2405d54ddcbSKumar Gala .get_irq = mpic_get_irq, 241e1c1575fSKumar Gala .restart = fsl_rstcr_restart, 2425d54ddcbSKumar Gala .calibrate_decr = generic_calibrate_decr, 2435d54ddcbSKumar Gala .progress = udbg_progress, 2445d54ddcbSKumar Gala }; 245