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; 61a712b65cSKumar Gala struct device_node *np; 6216d24060SKumar Gala #ifdef CONFIG_PPC_I8259 6316d24060SKumar Gala struct device_node *cascade_node = NULL; 6416d24060SKumar Gala int cascade_irq; 6516d24060SKumar Gala #endif 6606be64a3SHaiying Wang unsigned long root = of_get_flat_dt_root(); 6716d24060SKumar Gala 68b93eeba4SJason Jin np = of_find_node_by_type(NULL, "open-pic"); 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 8006be64a3SHaiying Wang if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS-CAMP")) { 8106be64a3SHaiying Wang mpic = mpic_alloc(np, r.start, 8206be64a3SHaiying Wang MPIC_PRIMARY | 8306be64a3SHaiying Wang MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS, 8406be64a3SHaiying Wang 0, 256, " OpenPIC "); 8506be64a3SHaiying Wang } else { 8616d24060SKumar Gala mpic = mpic_alloc(np, r.start, 87741edc49SJason Jin MPIC_PRIMARY | MPIC_WANTS_RESET | 883c10c9c4SKumar Gala MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS | 893c10c9c4SKumar Gala MPIC_SINGLE_DEST_CPU, 9016d24060SKumar Gala 0, 256, " OpenPIC "); 9106be64a3SHaiying Wang } 9206be64a3SHaiying Wang 9316d24060SKumar Gala BUG_ON(mpic == NULL); 94a712b65cSKumar Gala of_node_put(np); 9516d24060SKumar Gala 9616d24060SKumar Gala mpic_init(mpic); 9716d24060SKumar Gala 9816d24060SKumar Gala #ifdef CONFIG_PPC_I8259 9916d24060SKumar Gala /* Initialize the i8259 controller */ 10016d24060SKumar Gala for_each_node_by_type(np, "interrupt-controller") 10116d24060SKumar Gala if (of_device_is_compatible(np, "chrp,iic")) { 10216d24060SKumar Gala cascade_node = np; 10316d24060SKumar Gala break; 10416d24060SKumar Gala } 10516d24060SKumar Gala 10616d24060SKumar Gala if (cascade_node == NULL) { 10716d24060SKumar Gala printk(KERN_DEBUG "Could not find i8259 PIC\n"); 10816d24060SKumar Gala return; 10916d24060SKumar Gala } 11016d24060SKumar Gala 11116d24060SKumar Gala cascade_irq = irq_of_parse_and_map(cascade_node, 0); 11216d24060SKumar Gala if (cascade_irq == NO_IRQ) { 11316d24060SKumar Gala printk(KERN_ERR "Failed to map cascade interrupt\n"); 11416d24060SKumar Gala return; 11516d24060SKumar Gala } 11616d24060SKumar Gala 1177f50382dSKumar Gala DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq); 11816d24060SKumar Gala 11916d24060SKumar Gala i8259_init(cascade_node, 0); 12016d24060SKumar Gala of_node_put(cascade_node); 12116d24060SKumar Gala 1227f50382dSKumar Gala set_irq_chained_handler(cascade_irq, mpc85xx_8259_cascade); 12316d24060SKumar Gala #endif /* CONFIG_PPC_I8259 */ 12416d24060SKumar Gala } 12516d24060SKumar Gala 12616d24060SKumar Gala #ifdef CONFIG_PCI 1277f50382dSKumar Gala static int primary_phb_addr; 12816d24060SKumar Gala extern int uli_exclude_device(struct pci_controller *hose, 12916d24060SKumar Gala u_char bus, u_char devfn); 13016d24060SKumar Gala 13116d24060SKumar Gala static int mpc85xx_exclude_device(struct pci_controller *hose, 13216d24060SKumar Gala u_char bus, u_char devfn) 13316d24060SKumar Gala { 13416d24060SKumar Gala struct device_node* node; 13516d24060SKumar Gala struct resource rsrc; 13616d24060SKumar Gala 13744ef3390SStephen Rothwell node = hose->dn; 13816d24060SKumar Gala of_address_to_resource(node, 0, &rsrc); 13916d24060SKumar Gala 1407f50382dSKumar Gala if ((rsrc.start & 0xfffff) == primary_phb_addr) { 14116d24060SKumar Gala return uli_exclude_device(hose, bus, devfn); 14216d24060SKumar Gala } 14316d24060SKumar Gala 14416d24060SKumar Gala return PCIBIOS_SUCCESSFUL; 14516d24060SKumar Gala } 14616d24060SKumar Gala #endif /* CONFIG_PCI */ 14716d24060SKumar Gala 14816d24060SKumar Gala /* 14916d24060SKumar Gala * Setup the architecture 15016d24060SKumar Gala */ 151*8bd3947aSKumar Gala #ifdef CONFIG_SMP 152*8bd3947aSKumar Gala extern void __init mpc85xx_smp_init(void); 153*8bd3947aSKumar Gala #endif 1547f50382dSKumar Gala static void __init mpc85xx_ds_setup_arch(void) 15516d24060SKumar Gala { 15616d24060SKumar Gala #ifdef CONFIG_PCI 15716d24060SKumar Gala struct device_node *np; 15816d24060SKumar Gala #endif 15916d24060SKumar Gala 16016d24060SKumar Gala if (ppc_md.progress) 1617f50382dSKumar Gala ppc_md.progress("mpc85xx_ds_setup_arch()", 0); 16216d24060SKumar Gala 16316d24060SKumar Gala #ifdef CONFIG_PCI 164c9438affSKumar Gala for_each_node_by_type(np, "pci") { 165c9438affSKumar Gala if (of_device_is_compatible(np, "fsl,mpc8540-pci") || 166c9438affSKumar Gala of_device_is_compatible(np, "fsl,mpc8548-pcie")) { 16716d24060SKumar Gala struct resource rsrc; 16816d24060SKumar Gala of_address_to_resource(np, 0, &rsrc); 1697f50382dSKumar Gala if ((rsrc.start & 0xfffff) == primary_phb_addr) 17016d24060SKumar Gala fsl_add_bridge(np, 1); 17116d24060SKumar Gala else 17216d24060SKumar Gala fsl_add_bridge(np, 0); 17316d24060SKumar Gala } 174c9438affSKumar Gala } 175c9438affSKumar Gala 17616d24060SKumar Gala ppc_md.pci_exclude_device = mpc85xx_exclude_device; 17716d24060SKumar Gala #endif 17816d24060SKumar Gala 179*8bd3947aSKumar Gala #ifdef CONFIG_SMP 180*8bd3947aSKumar Gala mpc85xx_smp_init(); 181*8bd3947aSKumar Gala #endif 182*8bd3947aSKumar Gala 1837f50382dSKumar Gala printk("MPC85xx DS board from Freescale Semiconductor\n"); 18416d24060SKumar Gala } 18516d24060SKumar Gala 18616d24060SKumar Gala /* 18716d24060SKumar Gala * Called very early, device-tree isn't unflattened 18816d24060SKumar Gala */ 18916d24060SKumar Gala static int __init mpc8544_ds_probe(void) 19016d24060SKumar Gala { 19116d24060SKumar Gala unsigned long root = of_get_flat_dt_root(); 19216d24060SKumar Gala 1937f50382dSKumar Gala if (of_flat_dt_is_compatible(root, "MPC8544DS")) { 1947f50382dSKumar Gala #ifdef CONFIG_PCI 1957f50382dSKumar Gala primary_phb_addr = 0xb000; 1967f50382dSKumar Gala #endif 1977f50382dSKumar Gala return 1; 1987f50382dSKumar Gala } else { 1997f50382dSKumar Gala return 0; 2007f50382dSKumar Gala } 20116d24060SKumar Gala } 20216d24060SKumar Gala 203a712b65cSKumar Gala static struct of_device_id __initdata mpc85xxds_ids[] = { 2041028d4f1SSebastian Siewior { .type = "soc", }, 2051028d4f1SSebastian Siewior { .compatible = "soc", }, 206cf0d19fbSKim Phillips { .compatible = "simple-bus", }, 2071028d4f1SSebastian Siewior {}, 2081028d4f1SSebastian Siewior }; 2091028d4f1SSebastian Siewior 2101028d4f1SSebastian Siewior static int __init mpc85xxds_publish_devices(void) 2111028d4f1SSebastian Siewior { 2121028d4f1SSebastian Siewior return of_platform_bus_probe(NULL, mpc85xxds_ids, NULL); 2131028d4f1SSebastian Siewior } 2141028d4f1SSebastian Siewior machine_device_initcall(mpc8544_ds, mpc85xxds_publish_devices); 215741edc49SJason Jin machine_device_initcall(mpc8572_ds, mpc85xxds_publish_devices); 2161028d4f1SSebastian Siewior 2175d54ddcbSKumar Gala /* 2185d54ddcbSKumar Gala * Called very early, device-tree isn't unflattened 2195d54ddcbSKumar Gala */ 2205d54ddcbSKumar Gala static int __init mpc8572_ds_probe(void) 2215d54ddcbSKumar Gala { 2225d54ddcbSKumar Gala unsigned long root = of_get_flat_dt_root(); 2235d54ddcbSKumar Gala 2245d54ddcbSKumar Gala if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) { 2255d54ddcbSKumar Gala #ifdef CONFIG_PCI 2265d54ddcbSKumar Gala primary_phb_addr = 0x8000; 2275d54ddcbSKumar Gala #endif 2285d54ddcbSKumar Gala return 1; 2295d54ddcbSKumar Gala } else { 2305d54ddcbSKumar Gala return 0; 2315d54ddcbSKumar Gala } 2325d54ddcbSKumar Gala } 2335d54ddcbSKumar Gala 23416d24060SKumar Gala define_machine(mpc8544_ds) { 23516d24060SKumar Gala .name = "MPC8544 DS", 23616d24060SKumar Gala .probe = mpc8544_ds_probe, 2377f50382dSKumar Gala .setup_arch = mpc85xx_ds_setup_arch, 2387f50382dSKumar Gala .init_IRQ = mpc85xx_ds_pic_init, 23916d24060SKumar Gala #ifdef CONFIG_PCI 24016d24060SKumar Gala .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 24116d24060SKumar Gala #endif 24216d24060SKumar Gala .get_irq = mpic_get_irq, 243e1c1575fSKumar Gala .restart = fsl_rstcr_restart, 24416d24060SKumar Gala .calibrate_decr = generic_calibrate_decr, 24516d24060SKumar Gala .progress = udbg_progress, 24616d24060SKumar Gala }; 2475d54ddcbSKumar Gala 2485d54ddcbSKumar Gala define_machine(mpc8572_ds) { 2495d54ddcbSKumar Gala .name = "MPC8572 DS", 2505d54ddcbSKumar Gala .probe = mpc8572_ds_probe, 2515d54ddcbSKumar Gala .setup_arch = mpc85xx_ds_setup_arch, 2525d54ddcbSKumar Gala .init_IRQ = mpc85xx_ds_pic_init, 2535d54ddcbSKumar Gala #ifdef CONFIG_PCI 2545d54ddcbSKumar Gala .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 2555d54ddcbSKumar Gala #endif 2565d54ddcbSKumar Gala .get_irq = mpic_get_irq, 257e1c1575fSKumar Gala .restart = fsl_rstcr_restart, 2585d54ddcbSKumar Gala .calibrate_decr = generic_calibrate_decr, 2595d54ddcbSKumar Gala .progress = udbg_progress, 2605d54ddcbSKumar Gala }; 261