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> 2216d24060SKumar Gala 2316d24060SKumar Gala #include <asm/system.h> 2416d24060SKumar Gala #include <asm/time.h> 2516d24060SKumar Gala #include <asm/machdep.h> 2616d24060SKumar Gala #include <asm/pci-bridge.h> 2716d24060SKumar Gala #include <mm/mmu_decl.h> 2816d24060SKumar Gala #include <asm/prom.h> 2916d24060SKumar Gala #include <asm/udbg.h> 3016d24060SKumar Gala #include <asm/mpic.h> 3116d24060SKumar Gala #include <asm/i8259.h> 3216d24060SKumar Gala 3316d24060SKumar Gala #include <sysdev/fsl_soc.h> 3416d24060SKumar Gala #include <sysdev/fsl_pci.h> 3516d24060SKumar Gala 3616d24060SKumar Gala #undef DEBUG 3716d24060SKumar Gala 3816d24060SKumar Gala #ifdef DEBUG 3916d24060SKumar Gala #define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __FUNCTION__, ## args) 4016d24060SKumar Gala #else 4116d24060SKumar Gala #define DBG(fmt, args...) 4216d24060SKumar Gala #endif 4316d24060SKumar Gala 4416d24060SKumar Gala #ifdef CONFIG_PPC_I8259 457f50382dSKumar Gala static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc) 4616d24060SKumar Gala { 4716d24060SKumar Gala unsigned int cascade_irq = i8259_irq(); 4816d24060SKumar Gala 4916d24060SKumar Gala if (cascade_irq != NO_IRQ) { 5016d24060SKumar Gala generic_handle_irq(cascade_irq); 5116d24060SKumar Gala } 5216d24060SKumar Gala desc->chip->eoi(irq); 5316d24060SKumar Gala } 5416d24060SKumar Gala #endif /* CONFIG_PPC_I8259 */ 5516d24060SKumar Gala 567f50382dSKumar Gala void __init mpc85xx_ds_pic_init(void) 5716d24060SKumar Gala { 5816d24060SKumar Gala struct mpic *mpic; 5916d24060SKumar Gala struct resource r; 6016d24060SKumar Gala struct device_node *np = NULL; 6116d24060SKumar Gala #ifdef CONFIG_PPC_I8259 6216d24060SKumar Gala struct device_node *cascade_node = NULL; 6316d24060SKumar Gala int cascade_irq; 6416d24060SKumar Gala #endif 6516d24060SKumar Gala 6616d24060SKumar Gala np = of_find_node_by_type(np, "open-pic"); 6716d24060SKumar Gala 6816d24060SKumar Gala if (np == NULL) { 6916d24060SKumar Gala printk(KERN_ERR "Could not find open-pic node\n"); 7016d24060SKumar Gala return; 7116d24060SKumar Gala } 7216d24060SKumar Gala 7316d24060SKumar Gala if (of_address_to_resource(np, 0, &r)) { 7416d24060SKumar Gala printk(KERN_ERR "Failed to map mpic register space\n"); 7516d24060SKumar Gala of_node_put(np); 7616d24060SKumar Gala return; 7716d24060SKumar Gala } 7816d24060SKumar Gala 7916d24060SKumar Gala mpic = mpic_alloc(np, r.start, 8016d24060SKumar Gala MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN, 8116d24060SKumar Gala 0, 256, " OpenPIC "); 8216d24060SKumar Gala BUG_ON(mpic == NULL); 8316d24060SKumar Gala 8416d24060SKumar Gala mpic_init(mpic); 8516d24060SKumar Gala 8616d24060SKumar Gala #ifdef CONFIG_PPC_I8259 8716d24060SKumar Gala /* Initialize the i8259 controller */ 8816d24060SKumar Gala for_each_node_by_type(np, "interrupt-controller") 8916d24060SKumar Gala if (of_device_is_compatible(np, "chrp,iic")) { 9016d24060SKumar Gala cascade_node = np; 9116d24060SKumar Gala break; 9216d24060SKumar Gala } 9316d24060SKumar Gala 9416d24060SKumar Gala if (cascade_node == NULL) { 9516d24060SKumar Gala printk(KERN_DEBUG "Could not find i8259 PIC\n"); 9616d24060SKumar Gala return; 9716d24060SKumar Gala } 9816d24060SKumar Gala 9916d24060SKumar Gala cascade_irq = irq_of_parse_and_map(cascade_node, 0); 10016d24060SKumar Gala if (cascade_irq == NO_IRQ) { 10116d24060SKumar Gala printk(KERN_ERR "Failed to map cascade interrupt\n"); 10216d24060SKumar Gala return; 10316d24060SKumar Gala } 10416d24060SKumar Gala 1057f50382dSKumar Gala DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq); 10616d24060SKumar Gala 10716d24060SKumar Gala i8259_init(cascade_node, 0); 10816d24060SKumar Gala of_node_put(cascade_node); 10916d24060SKumar Gala 1107f50382dSKumar Gala set_irq_chained_handler(cascade_irq, mpc85xx_8259_cascade); 11116d24060SKumar Gala #endif /* CONFIG_PPC_I8259 */ 11216d24060SKumar Gala } 11316d24060SKumar Gala 11416d24060SKumar Gala #ifdef CONFIG_PCI 1157f50382dSKumar Gala static int primary_phb_addr; 11616d24060SKumar Gala extern int uses_fsl_uli_m1575; 11716d24060SKumar Gala extern int uli_exclude_device(struct pci_controller *hose, 11816d24060SKumar Gala u_char bus, u_char devfn); 11916d24060SKumar Gala 12016d24060SKumar Gala static int mpc85xx_exclude_device(struct pci_controller *hose, 12116d24060SKumar Gala u_char bus, u_char devfn) 12216d24060SKumar Gala { 12316d24060SKumar Gala struct device_node* node; 12416d24060SKumar Gala struct resource rsrc; 12516d24060SKumar Gala 126*44ef3390SStephen Rothwell node = hose->dn; 12716d24060SKumar Gala of_address_to_resource(node, 0, &rsrc); 12816d24060SKumar Gala 1297f50382dSKumar Gala if ((rsrc.start & 0xfffff) == primary_phb_addr) { 13016d24060SKumar Gala return uli_exclude_device(hose, bus, devfn); 13116d24060SKumar Gala } 13216d24060SKumar Gala 13316d24060SKumar Gala return PCIBIOS_SUCCESSFUL; 13416d24060SKumar Gala } 13516d24060SKumar Gala #endif /* CONFIG_PCI */ 13616d24060SKumar Gala 13716d24060SKumar Gala /* 13816d24060SKumar Gala * Setup the architecture 13916d24060SKumar Gala */ 1407f50382dSKumar Gala static void __init mpc85xx_ds_setup_arch(void) 14116d24060SKumar Gala { 14216d24060SKumar Gala #ifdef CONFIG_PCI 14316d24060SKumar Gala struct device_node *np; 14416d24060SKumar Gala #endif 14516d24060SKumar Gala 14616d24060SKumar Gala if (ppc_md.progress) 1477f50382dSKumar Gala ppc_md.progress("mpc85xx_ds_setup_arch()", 0); 14816d24060SKumar Gala 14916d24060SKumar Gala #ifdef CONFIG_PCI 150c9438affSKumar Gala for_each_node_by_type(np, "pci") { 151c9438affSKumar Gala if (of_device_is_compatible(np, "fsl,mpc8540-pci") || 152c9438affSKumar Gala of_device_is_compatible(np, "fsl,mpc8548-pcie")) { 15316d24060SKumar Gala struct resource rsrc; 15416d24060SKumar Gala of_address_to_resource(np, 0, &rsrc); 1557f50382dSKumar Gala if ((rsrc.start & 0xfffff) == primary_phb_addr) 15616d24060SKumar Gala fsl_add_bridge(np, 1); 15716d24060SKumar Gala else 15816d24060SKumar Gala fsl_add_bridge(np, 0); 15916d24060SKumar Gala } 160c9438affSKumar Gala } 161c9438affSKumar Gala 16216d24060SKumar Gala uses_fsl_uli_m1575 = 1; 16316d24060SKumar Gala ppc_md.pci_exclude_device = mpc85xx_exclude_device; 16416d24060SKumar Gala #endif 16516d24060SKumar Gala 1667f50382dSKumar Gala printk("MPC85xx DS board from Freescale Semiconductor\n"); 16716d24060SKumar Gala } 16816d24060SKumar Gala 16916d24060SKumar Gala /* 17016d24060SKumar Gala * Called very early, device-tree isn't unflattened 17116d24060SKumar Gala */ 17216d24060SKumar Gala static int __init mpc8544_ds_probe(void) 17316d24060SKumar Gala { 17416d24060SKumar Gala unsigned long root = of_get_flat_dt_root(); 17516d24060SKumar Gala 1767f50382dSKumar Gala if (of_flat_dt_is_compatible(root, "MPC8544DS")) { 1777f50382dSKumar Gala #ifdef CONFIG_PCI 1787f50382dSKumar Gala primary_phb_addr = 0xb000; 1797f50382dSKumar Gala #endif 1807f50382dSKumar Gala return 1; 1817f50382dSKumar Gala } else { 1827f50382dSKumar Gala return 0; 1837f50382dSKumar Gala } 18416d24060SKumar Gala } 18516d24060SKumar Gala 1865d54ddcbSKumar Gala /* 1875d54ddcbSKumar Gala * Called very early, device-tree isn't unflattened 1885d54ddcbSKumar Gala */ 1895d54ddcbSKumar Gala static int __init mpc8572_ds_probe(void) 1905d54ddcbSKumar Gala { 1915d54ddcbSKumar Gala unsigned long root = of_get_flat_dt_root(); 1925d54ddcbSKumar Gala 1935d54ddcbSKumar Gala if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) { 1945d54ddcbSKumar Gala #ifdef CONFIG_PCI 1955d54ddcbSKumar Gala primary_phb_addr = 0x8000; 1965d54ddcbSKumar Gala #endif 1975d54ddcbSKumar Gala return 1; 1985d54ddcbSKumar Gala } else { 1995d54ddcbSKumar Gala return 0; 2005d54ddcbSKumar Gala } 2015d54ddcbSKumar Gala } 2025d54ddcbSKumar Gala 20316d24060SKumar Gala define_machine(mpc8544_ds) { 20416d24060SKumar Gala .name = "MPC8544 DS", 20516d24060SKumar Gala .probe = mpc8544_ds_probe, 2067f50382dSKumar Gala .setup_arch = mpc85xx_ds_setup_arch, 2077f50382dSKumar Gala .init_IRQ = mpc85xx_ds_pic_init, 20816d24060SKumar Gala #ifdef CONFIG_PCI 20916d24060SKumar Gala .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 21016d24060SKumar Gala #endif 21116d24060SKumar Gala .get_irq = mpic_get_irq, 212e1c1575fSKumar Gala .restart = fsl_rstcr_restart, 21316d24060SKumar Gala .calibrate_decr = generic_calibrate_decr, 21416d24060SKumar Gala .progress = udbg_progress, 21516d24060SKumar Gala }; 2165d54ddcbSKumar Gala 2175d54ddcbSKumar Gala define_machine(mpc8572_ds) { 2185d54ddcbSKumar Gala .name = "MPC8572 DS", 2195d54ddcbSKumar Gala .probe = mpc8572_ds_probe, 2205d54ddcbSKumar Gala .setup_arch = mpc85xx_ds_setup_arch, 2215d54ddcbSKumar Gala .init_IRQ = mpc85xx_ds_pic_init, 2225d54ddcbSKumar Gala #ifdef CONFIG_PCI 2235d54ddcbSKumar Gala .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 2245d54ddcbSKumar Gala #endif 2255d54ddcbSKumar Gala .get_irq = mpic_get_irq, 226e1c1575fSKumar Gala .restart = fsl_rstcr_restart, 2275d54ddcbSKumar Gala .calibrate_decr = generic_calibrate_decr, 2285d54ddcbSKumar Gala .progress = udbg_progress, 2295d54ddcbSKumar Gala }; 230