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 <asm/mpc85xx.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 4016d24060SKumar Gala #define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __FUNCTION__, ## 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, 8116d24060SKumar Gala MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN, 8216d24060SKumar Gala 0, 256, " OpenPIC "); 8316d24060SKumar Gala BUG_ON(mpic == NULL); 8416d24060SKumar Gala 8516d24060SKumar Gala mpic_init(mpic); 8616d24060SKumar Gala 8716d24060SKumar Gala #ifdef CONFIG_PPC_I8259 8816d24060SKumar Gala /* Initialize the i8259 controller */ 8916d24060SKumar Gala for_each_node_by_type(np, "interrupt-controller") 9016d24060SKumar Gala if (of_device_is_compatible(np, "chrp,iic")) { 9116d24060SKumar Gala cascade_node = np; 9216d24060SKumar Gala break; 9316d24060SKumar Gala } 9416d24060SKumar Gala 9516d24060SKumar Gala if (cascade_node == NULL) { 9616d24060SKumar Gala printk(KERN_DEBUG "Could not find i8259 PIC\n"); 9716d24060SKumar Gala return; 9816d24060SKumar Gala } 9916d24060SKumar Gala 10016d24060SKumar Gala cascade_irq = irq_of_parse_and_map(cascade_node, 0); 10116d24060SKumar Gala if (cascade_irq == NO_IRQ) { 10216d24060SKumar Gala printk(KERN_ERR "Failed to map cascade interrupt\n"); 10316d24060SKumar Gala return; 10416d24060SKumar Gala } 10516d24060SKumar Gala 1067f50382dSKumar Gala DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq); 10716d24060SKumar Gala 10816d24060SKumar Gala i8259_init(cascade_node, 0); 10916d24060SKumar Gala of_node_put(cascade_node); 11016d24060SKumar Gala 1117f50382dSKumar Gala set_irq_chained_handler(cascade_irq, mpc85xx_8259_cascade); 11216d24060SKumar Gala #endif /* CONFIG_PPC_I8259 */ 11316d24060SKumar Gala } 11416d24060SKumar Gala 11516d24060SKumar Gala #ifdef CONFIG_PCI 1167f50382dSKumar Gala static int primary_phb_addr; 11716d24060SKumar Gala extern int uses_fsl_uli_m1575; 11816d24060SKumar Gala extern int uli_exclude_device(struct pci_controller *hose, 11916d24060SKumar Gala u_char bus, u_char devfn); 12016d24060SKumar Gala 12116d24060SKumar Gala static int mpc85xx_exclude_device(struct pci_controller *hose, 12216d24060SKumar Gala u_char bus, u_char devfn) 12316d24060SKumar Gala { 12416d24060SKumar Gala struct device_node* node; 12516d24060SKumar Gala struct resource rsrc; 12616d24060SKumar Gala 12716d24060SKumar Gala node = (struct device_node *)hose->arch_data; 12816d24060SKumar Gala of_address_to_resource(node, 0, &rsrc); 12916d24060SKumar Gala 1307f50382dSKumar Gala if ((rsrc.start & 0xfffff) == primary_phb_addr) { 13116d24060SKumar Gala return uli_exclude_device(hose, bus, devfn); 13216d24060SKumar Gala } 13316d24060SKumar Gala 13416d24060SKumar Gala return PCIBIOS_SUCCESSFUL; 13516d24060SKumar Gala } 13616d24060SKumar Gala #endif /* CONFIG_PCI */ 13716d24060SKumar Gala 13816d24060SKumar Gala /* 13916d24060SKumar Gala * Setup the architecture 14016d24060SKumar Gala */ 1417f50382dSKumar Gala static void __init mpc85xx_ds_setup_arch(void) 14216d24060SKumar Gala { 14316d24060SKumar Gala #ifdef CONFIG_PCI 14416d24060SKumar Gala struct device_node *np; 14516d24060SKumar Gala #endif 14616d24060SKumar Gala 14716d24060SKumar Gala if (ppc_md.progress) 1487f50382dSKumar Gala ppc_md.progress("mpc85xx_ds_setup_arch()", 0); 14916d24060SKumar Gala 15016d24060SKumar Gala #ifdef CONFIG_PCI 151c9438affSKumar Gala for_each_node_by_type(np, "pci") { 152c9438affSKumar Gala if (of_device_is_compatible(np, "fsl,mpc8540-pci") || 153c9438affSKumar Gala of_device_is_compatible(np, "fsl,mpc8548-pcie")) { 15416d24060SKumar Gala struct resource rsrc; 15516d24060SKumar Gala of_address_to_resource(np, 0, &rsrc); 1567f50382dSKumar Gala if ((rsrc.start & 0xfffff) == primary_phb_addr) 15716d24060SKumar Gala fsl_add_bridge(np, 1); 15816d24060SKumar Gala else 15916d24060SKumar Gala fsl_add_bridge(np, 0); 16016d24060SKumar Gala } 161c9438affSKumar Gala } 162c9438affSKumar Gala 16316d24060SKumar Gala uses_fsl_uli_m1575 = 1; 16416d24060SKumar Gala ppc_md.pci_exclude_device = mpc85xx_exclude_device; 16516d24060SKumar Gala #endif 16616d24060SKumar Gala 1677f50382dSKumar Gala printk("MPC85xx DS board from Freescale Semiconductor\n"); 16816d24060SKumar Gala } 16916d24060SKumar Gala 17016d24060SKumar Gala /* 17116d24060SKumar Gala * Called very early, device-tree isn't unflattened 17216d24060SKumar Gala */ 17316d24060SKumar Gala static int __init mpc8544_ds_probe(void) 17416d24060SKumar Gala { 17516d24060SKumar Gala unsigned long root = of_get_flat_dt_root(); 17616d24060SKumar Gala 1777f50382dSKumar Gala if (of_flat_dt_is_compatible(root, "MPC8544DS")) { 1787f50382dSKumar Gala #ifdef CONFIG_PCI 1797f50382dSKumar Gala primary_phb_addr = 0xb000; 1807f50382dSKumar Gala #endif 1817f50382dSKumar Gala return 1; 1827f50382dSKumar Gala } else { 1837f50382dSKumar Gala return 0; 1847f50382dSKumar Gala } 18516d24060SKumar Gala } 18616d24060SKumar Gala 1875d54ddcbSKumar Gala /* 1885d54ddcbSKumar Gala * Called very early, device-tree isn't unflattened 1895d54ddcbSKumar Gala */ 1905d54ddcbSKumar Gala static int __init mpc8572_ds_probe(void) 1915d54ddcbSKumar Gala { 1925d54ddcbSKumar Gala unsigned long root = of_get_flat_dt_root(); 1935d54ddcbSKumar Gala 1945d54ddcbSKumar Gala if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) { 1955d54ddcbSKumar Gala #ifdef CONFIG_PCI 1965d54ddcbSKumar Gala primary_phb_addr = 0x8000; 1975d54ddcbSKumar Gala #endif 1985d54ddcbSKumar Gala return 1; 1995d54ddcbSKumar Gala } else { 2005d54ddcbSKumar Gala return 0; 2015d54ddcbSKumar Gala } 2025d54ddcbSKumar Gala } 2035d54ddcbSKumar Gala 20416d24060SKumar Gala define_machine(mpc8544_ds) { 20516d24060SKumar Gala .name = "MPC8544 DS", 20616d24060SKumar Gala .probe = mpc8544_ds_probe, 2077f50382dSKumar Gala .setup_arch = mpc85xx_ds_setup_arch, 2087f50382dSKumar Gala .init_IRQ = mpc85xx_ds_pic_init, 20916d24060SKumar Gala #ifdef CONFIG_PCI 21016d24060SKumar Gala .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 21116d24060SKumar Gala #endif 21216d24060SKumar Gala .get_irq = mpic_get_irq, 213*e1c1575fSKumar Gala .restart = fsl_rstcr_restart, 21416d24060SKumar Gala .calibrate_decr = generic_calibrate_decr, 21516d24060SKumar Gala .progress = udbg_progress, 21616d24060SKumar Gala }; 2175d54ddcbSKumar Gala 2185d54ddcbSKumar Gala define_machine(mpc8572_ds) { 2195d54ddcbSKumar Gala .name = "MPC8572 DS", 2205d54ddcbSKumar Gala .probe = mpc8572_ds_probe, 2215d54ddcbSKumar Gala .setup_arch = mpc85xx_ds_setup_arch, 2225d54ddcbSKumar Gala .init_IRQ = mpc85xx_ds_pic_init, 2235d54ddcbSKumar Gala #ifdef CONFIG_PCI 2245d54ddcbSKumar Gala .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 2255d54ddcbSKumar Gala #endif 2265d54ddcbSKumar Gala .get_irq = mpic_get_irq, 227*e1c1575fSKumar Gala .restart = fsl_rstcr_restart, 2285d54ddcbSKumar Gala .calibrate_decr = generic_calibrate_decr, 2295d54ddcbSKumar Gala .progress = udbg_progress, 2305d54ddcbSKumar Gala }; 231