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> 2395f72d1eSYinghai Lu #include <linux/memblock.h> 2416d24060SKumar Gala 2516d24060SKumar Gala #include <asm/system.h> 2616d24060SKumar Gala #include <asm/time.h> 2716d24060SKumar Gala #include <asm/machdep.h> 2816d24060SKumar Gala #include <asm/pci-bridge.h> 2916d24060SKumar Gala #include <mm/mmu_decl.h> 3016d24060SKumar Gala #include <asm/prom.h> 3116d24060SKumar Gala #include <asm/udbg.h> 3216d24060SKumar Gala #include <asm/mpic.h> 3316d24060SKumar Gala #include <asm/i8259.h> 34152d0182SKumar Gala #include <asm/swiotlb.h> 3516d24060SKumar Gala 3616d24060SKumar Gala #include <sysdev/fsl_soc.h> 3716d24060SKumar Gala #include <sysdev/fsl_pci.h> 38582d3e09SKyle Moffett #include "smp.h" 3916d24060SKumar Gala 40543a07b1SDmitry Eremin-Solenikov #include "mpc85xx.h" 41543a07b1SDmitry Eremin-Solenikov 4216d24060SKumar Gala #undef DEBUG 4316d24060SKumar Gala 4416d24060SKumar Gala #ifdef DEBUG 45e48b1b45SHarvey Harrison #define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args) 4616d24060SKumar Gala #else 4716d24060SKumar Gala #define DBG(fmt, args...) 4816d24060SKumar Gala #endif 4916d24060SKumar Gala 5016d24060SKumar Gala #ifdef CONFIG_PPC_I8259 517f50382dSKumar Gala static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc) 5216d24060SKumar Gala { 53ec775d0eSThomas Gleixner struct irq_chip *chip = irq_desc_get_chip(desc); 5416d24060SKumar Gala unsigned int cascade_irq = i8259_irq(); 5516d24060SKumar Gala 5616d24060SKumar Gala if (cascade_irq != NO_IRQ) { 5716d24060SKumar Gala generic_handle_irq(cascade_irq); 5816d24060SKumar Gala } 59712d5d79SLennert Buytenhek chip->irq_eoi(&desc->irq_data); 6016d24060SKumar Gala } 6116d24060SKumar Gala #endif /* CONFIG_PPC_I8259 */ 6216d24060SKumar Gala 637f50382dSKumar Gala void __init mpc85xx_ds_pic_init(void) 6416d24060SKumar Gala { 6516d24060SKumar Gala struct mpic *mpic; 6616d24060SKumar Gala #ifdef CONFIG_PPC_I8259 67996983b7SKyle Moffett struct device_node *np; 6816d24060SKumar Gala struct device_node *cascade_node = NULL; 6916d24060SKumar Gala int cascade_irq; 7016d24060SKumar Gala #endif 7106be64a3SHaiying Wang unsigned long root = of_get_flat_dt_root(); 7216d24060SKumar Gala 7306be64a3SHaiying Wang if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS-CAMP")) { 74996983b7SKyle Moffett mpic = mpic_alloc(NULL, 0, 75*5019609fSKyle Moffett MPIC_BIG_ENDIAN | 76a63e23b9SFabio Baltieri MPIC_SINGLE_DEST_CPU, 7706be64a3SHaiying Wang 0, 256, " OpenPIC "); 7806be64a3SHaiying Wang } else { 79996983b7SKyle Moffett mpic = mpic_alloc(NULL, 0, 80be8bec56SKyle Moffett MPIC_WANTS_RESET | 81*5019609fSKyle Moffett MPIC_BIG_ENDIAN | 823c10c9c4SKumar Gala MPIC_SINGLE_DEST_CPU, 8316d24060SKumar Gala 0, 256, " OpenPIC "); 8406be64a3SHaiying Wang } 8506be64a3SHaiying Wang 8616d24060SKumar Gala BUG_ON(mpic == NULL); 8716d24060SKumar Gala mpic_init(mpic); 8816d24060SKumar Gala 8916d24060SKumar Gala #ifdef CONFIG_PPC_I8259 9016d24060SKumar Gala /* Initialize the i8259 controller */ 9116d24060SKumar Gala for_each_node_by_type(np, "interrupt-controller") 9216d24060SKumar Gala if (of_device_is_compatible(np, "chrp,iic")) { 9316d24060SKumar Gala cascade_node = np; 9416d24060SKumar Gala break; 9516d24060SKumar Gala } 9616d24060SKumar Gala 9716d24060SKumar Gala if (cascade_node == NULL) { 9816d24060SKumar Gala printk(KERN_DEBUG "Could not find i8259 PIC\n"); 9916d24060SKumar Gala return; 10016d24060SKumar Gala } 10116d24060SKumar Gala 10216d24060SKumar Gala cascade_irq = irq_of_parse_and_map(cascade_node, 0); 10316d24060SKumar Gala if (cascade_irq == NO_IRQ) { 10416d24060SKumar Gala printk(KERN_ERR "Failed to map cascade interrupt\n"); 10516d24060SKumar Gala return; 10616d24060SKumar Gala } 10716d24060SKumar Gala 1087f50382dSKumar Gala DBG("mpc85xxds: cascade mapped to irq %d\n", cascade_irq); 10916d24060SKumar Gala 11016d24060SKumar Gala i8259_init(cascade_node, 0); 11116d24060SKumar Gala of_node_put(cascade_node); 11216d24060SKumar Gala 113ec775d0eSThomas Gleixner irq_set_chained_handler(cascade_irq, mpc85xx_8259_cascade); 11416d24060SKumar Gala #endif /* CONFIG_PPC_I8259 */ 11516d24060SKumar Gala } 11616d24060SKumar Gala 11716d24060SKumar Gala #ifdef CONFIG_PCI 1187f50382dSKumar Gala static int primary_phb_addr; 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; 146152d0182SKumar Gala struct pci_controller *hose; 14716d24060SKumar Gala #endif 148152d0182SKumar Gala dma_addr_t max = 0xffffffff; 14916d24060SKumar Gala 15016d24060SKumar Gala if (ppc_md.progress) 1517f50382dSKumar Gala ppc_md.progress("mpc85xx_ds_setup_arch()", 0); 15216d24060SKumar Gala 15316d24060SKumar Gala #ifdef CONFIG_PCI 154c9438affSKumar Gala for_each_node_by_type(np, "pci") { 155c9438affSKumar Gala if (of_device_is_compatible(np, "fsl,mpc8540-pci") || 15601af9507SKumar Gala of_device_is_compatible(np, "fsl,mpc8548-pcie") || 15701af9507SKumar Gala of_device_is_compatible(np, "fsl,p2020-pcie")) { 15816d24060SKumar Gala struct resource rsrc; 15916d24060SKumar Gala of_address_to_resource(np, 0, &rsrc); 1607f50382dSKumar Gala if ((rsrc.start & 0xfffff) == primary_phb_addr) 16116d24060SKumar Gala fsl_add_bridge(np, 1); 16216d24060SKumar Gala else 16316d24060SKumar Gala fsl_add_bridge(np, 0); 164152d0182SKumar Gala 165152d0182SKumar Gala hose = pci_find_hose_for_OF_device(np); 166152d0182SKumar Gala max = min(max, hose->dma_window_base_cur + 167152d0182SKumar Gala hose->dma_window_size); 16816d24060SKumar Gala } 169c9438affSKumar Gala } 170c9438affSKumar Gala 17116d24060SKumar Gala ppc_md.pci_exclude_device = mpc85xx_exclude_device; 17216d24060SKumar Gala #endif 17316d24060SKumar Gala 1748bd3947aSKumar Gala mpc85xx_smp_init(); 1758bd3947aSKumar Gala 176152d0182SKumar Gala #ifdef CONFIG_SWIOTLB 17795f72d1eSYinghai Lu if (memblock_end_of_DRAM() > max) { 178152d0182SKumar Gala ppc_swiotlb_enable = 1; 1793702977fSFUJITA Tomonori set_pci_dma_ops(&swiotlb_dma_ops); 180762afb73SFUJITA Tomonori ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_swiotlb; 181152d0182SKumar Gala } 182152d0182SKumar Gala #endif 183152d0182SKumar Gala 1847f50382dSKumar Gala printk("MPC85xx DS board from Freescale Semiconductor\n"); 18516d24060SKumar Gala } 18616d24060SKumar Gala 18716d24060SKumar Gala /* 18816d24060SKumar Gala * Called very early, device-tree isn't unflattened 18916d24060SKumar Gala */ 19016d24060SKumar Gala static int __init mpc8544_ds_probe(void) 19116d24060SKumar Gala { 19216d24060SKumar Gala unsigned long root = of_get_flat_dt_root(); 19316d24060SKumar Gala 1947f50382dSKumar Gala if (of_flat_dt_is_compatible(root, "MPC8544DS")) { 1957f50382dSKumar Gala #ifdef CONFIG_PCI 1967f50382dSKumar Gala primary_phb_addr = 0xb000; 1977f50382dSKumar Gala #endif 1987f50382dSKumar Gala return 1; 1997f50382dSKumar Gala } 20001af9507SKumar Gala 20101af9507SKumar Gala return 0; 20216d24060SKumar Gala } 20316d24060SKumar Gala 20446d026acSDmitry Eremin-Solenikov machine_device_initcall(mpc8544_ds, mpc85xx_common_publish_devices); 20546d026acSDmitry Eremin-Solenikov machine_device_initcall(mpc8572_ds, mpc85xx_common_publish_devices); 20646d026acSDmitry Eremin-Solenikov machine_device_initcall(p2020_ds, mpc85xx_common_publish_devices); 2071028d4f1SSebastian Siewior 208152d0182SKumar Gala machine_arch_initcall(mpc8544_ds, swiotlb_setup_bus_notifier); 209152d0182SKumar Gala machine_arch_initcall(mpc8572_ds, swiotlb_setup_bus_notifier); 210152d0182SKumar Gala machine_arch_initcall(p2020_ds, swiotlb_setup_bus_notifier); 211152d0182SKumar Gala 2125d54ddcbSKumar Gala /* 2135d54ddcbSKumar Gala * Called very early, device-tree isn't unflattened 2145d54ddcbSKumar Gala */ 2155d54ddcbSKumar Gala static int __init mpc8572_ds_probe(void) 2165d54ddcbSKumar Gala { 2175d54ddcbSKumar Gala unsigned long root = of_get_flat_dt_root(); 2185d54ddcbSKumar Gala 2195d54ddcbSKumar Gala if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) { 2205d54ddcbSKumar Gala #ifdef CONFIG_PCI 2215d54ddcbSKumar Gala primary_phb_addr = 0x8000; 2225d54ddcbSKumar Gala #endif 2235d54ddcbSKumar Gala return 1; 22401af9507SKumar Gala } 22501af9507SKumar Gala 2265d54ddcbSKumar Gala return 0; 2275d54ddcbSKumar Gala } 22801af9507SKumar Gala 22901af9507SKumar Gala /* 23001af9507SKumar Gala * Called very early, device-tree isn't unflattened 23101af9507SKumar Gala */ 23201af9507SKumar Gala static int __init p2020_ds_probe(void) 23301af9507SKumar Gala { 23401af9507SKumar Gala unsigned long root = of_get_flat_dt_root(); 23501af9507SKumar Gala 23601af9507SKumar Gala if (of_flat_dt_is_compatible(root, "fsl,P2020DS")) { 23701af9507SKumar Gala #ifdef CONFIG_PCI 23801af9507SKumar Gala primary_phb_addr = 0x9000; 23901af9507SKumar Gala #endif 24001af9507SKumar Gala return 1; 24101af9507SKumar Gala } 24201af9507SKumar Gala 24301af9507SKumar Gala return 0; 2445d54ddcbSKumar Gala } 2455d54ddcbSKumar Gala 24616d24060SKumar Gala define_machine(mpc8544_ds) { 24716d24060SKumar Gala .name = "MPC8544 DS", 24816d24060SKumar Gala .probe = mpc8544_ds_probe, 2497f50382dSKumar Gala .setup_arch = mpc85xx_ds_setup_arch, 2507f50382dSKumar Gala .init_IRQ = mpc85xx_ds_pic_init, 25116d24060SKumar Gala #ifdef CONFIG_PCI 25216d24060SKumar Gala .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 25316d24060SKumar Gala #endif 25416d24060SKumar Gala .get_irq = mpic_get_irq, 255e1c1575fSKumar Gala .restart = fsl_rstcr_restart, 25616d24060SKumar Gala .calibrate_decr = generic_calibrate_decr, 25716d24060SKumar Gala .progress = udbg_progress, 25816d24060SKumar Gala }; 2595d54ddcbSKumar Gala 2605d54ddcbSKumar Gala define_machine(mpc8572_ds) { 2615d54ddcbSKumar Gala .name = "MPC8572 DS", 2625d54ddcbSKumar Gala .probe = mpc8572_ds_probe, 2635d54ddcbSKumar Gala .setup_arch = mpc85xx_ds_setup_arch, 2645d54ddcbSKumar Gala .init_IRQ = mpc85xx_ds_pic_init, 2655d54ddcbSKumar Gala #ifdef CONFIG_PCI 2665d54ddcbSKumar Gala .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 2675d54ddcbSKumar Gala #endif 2685d54ddcbSKumar Gala .get_irq = mpic_get_irq, 269e1c1575fSKumar Gala .restart = fsl_rstcr_restart, 2705d54ddcbSKumar Gala .calibrate_decr = generic_calibrate_decr, 2715d54ddcbSKumar Gala .progress = udbg_progress, 2725d54ddcbSKumar Gala }; 27301af9507SKumar Gala 27401af9507SKumar Gala define_machine(p2020_ds) { 27501af9507SKumar Gala .name = "P2020 DS", 27601af9507SKumar Gala .probe = p2020_ds_probe, 27701af9507SKumar Gala .setup_arch = mpc85xx_ds_setup_arch, 27801af9507SKumar Gala .init_IRQ = mpc85xx_ds_pic_init, 27901af9507SKumar Gala #ifdef CONFIG_PCI 28001af9507SKumar Gala .pcibios_fixup_bus = fsl_pcibios_fixup_bus, 28101af9507SKumar Gala #endif 28201af9507SKumar Gala .get_irq = mpic_get_irq, 28301af9507SKumar Gala .restart = fsl_rstcr_restart, 28401af9507SKumar Gala .calibrate_decr = generic_calibrate_decr, 28501af9507SKumar Gala .progress = udbg_progress, 28601af9507SKumar Gala }; 287