xref: /linux/arch/powerpc/platforms/85xx/mpc85xx_ds.c (revision c9438affcb7ac0dda4c6c6961637fb272f7c32d4)
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 #include "mpc85xx.h"
3716d24060SKumar Gala 
3816d24060SKumar Gala #undef DEBUG
3916d24060SKumar Gala 
4016d24060SKumar Gala #ifdef DEBUG
4116d24060SKumar Gala #define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __FUNCTION__, ## args)
4216d24060SKumar Gala #else
4316d24060SKumar Gala #define DBG(fmt, args...)
4416d24060SKumar Gala #endif
4516d24060SKumar Gala 
4616d24060SKumar Gala #ifdef CONFIG_PPC_I8259
477f50382dSKumar Gala static void mpc85xx_8259_cascade(unsigned int irq, struct irq_desc *desc)
4816d24060SKumar Gala {
4916d24060SKumar Gala 	unsigned int cascade_irq = i8259_irq();
5016d24060SKumar Gala 
5116d24060SKumar Gala 	if (cascade_irq != NO_IRQ) {
5216d24060SKumar Gala 		generic_handle_irq(cascade_irq);
5316d24060SKumar Gala 	}
5416d24060SKumar Gala 	desc->chip->eoi(irq);
5516d24060SKumar Gala }
5616d24060SKumar Gala #endif	/* CONFIG_PPC_I8259 */
5716d24060SKumar Gala 
587f50382dSKumar Gala void __init mpc85xx_ds_pic_init(void)
5916d24060SKumar Gala {
6016d24060SKumar Gala 	struct mpic *mpic;
6116d24060SKumar Gala 	struct resource r;
6216d24060SKumar Gala 	struct device_node *np = NULL;
6316d24060SKumar Gala #ifdef CONFIG_PPC_I8259
6416d24060SKumar Gala 	struct device_node *cascade_node = NULL;
6516d24060SKumar Gala 	int cascade_irq;
6616d24060SKumar Gala #endif
6716d24060SKumar Gala 
6816d24060SKumar Gala 	np = of_find_node_by_type(np, "open-pic");
6916d24060SKumar Gala 
7016d24060SKumar Gala 	if (np == NULL) {
7116d24060SKumar Gala 		printk(KERN_ERR "Could not find open-pic node\n");
7216d24060SKumar Gala 		return;
7316d24060SKumar Gala 	}
7416d24060SKumar Gala 
7516d24060SKumar Gala 	if (of_address_to_resource(np, 0, &r)) {
7616d24060SKumar Gala 		printk(KERN_ERR "Failed to map mpic register space\n");
7716d24060SKumar Gala 		of_node_put(np);
7816d24060SKumar Gala 		return;
7916d24060SKumar Gala 	}
8016d24060SKumar Gala 
8116d24060SKumar Gala 	mpic = mpic_alloc(np, r.start,
8216d24060SKumar Gala 			  MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
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 
12816d24060SKumar Gala 	node = (struct device_node *)hose->arch_data;
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
152*c9438affSKumar Gala 	for_each_node_by_type(np, "pci") {
153*c9438affSKumar Gala 		if (of_device_is_compatible(np, "fsl,mpc8540-pci") ||
154*c9438affSKumar 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 		}
162*c9438affSKumar Gala 	}
163*c9438affSKumar 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 
1885d54ddcbSKumar Gala /*
1895d54ddcbSKumar Gala  * Called very early, device-tree isn't unflattened
1905d54ddcbSKumar Gala  */
1915d54ddcbSKumar Gala static int __init mpc8572_ds_probe(void)
1925d54ddcbSKumar Gala {
1935d54ddcbSKumar Gala 	unsigned long root = of_get_flat_dt_root();
1945d54ddcbSKumar Gala 
1955d54ddcbSKumar Gala 	if (of_flat_dt_is_compatible(root, "fsl,MPC8572DS")) {
1965d54ddcbSKumar Gala #ifdef CONFIG_PCI
1975d54ddcbSKumar Gala 		primary_phb_addr = 0x8000;
1985d54ddcbSKumar Gala #endif
1995d54ddcbSKumar Gala 		return 1;
2005d54ddcbSKumar Gala 	} else {
2015d54ddcbSKumar Gala 		return 0;
2025d54ddcbSKumar Gala 	}
2035d54ddcbSKumar Gala }
2045d54ddcbSKumar Gala 
20516d24060SKumar Gala define_machine(mpc8544_ds) {
20616d24060SKumar Gala 	.name			= "MPC8544 DS",
20716d24060SKumar Gala 	.probe			= mpc8544_ds_probe,
2087f50382dSKumar Gala 	.setup_arch		= mpc85xx_ds_setup_arch,
2097f50382dSKumar Gala 	.init_IRQ		= mpc85xx_ds_pic_init,
21016d24060SKumar Gala #ifdef CONFIG_PCI
21116d24060SKumar Gala 	.pcibios_fixup_bus	= fsl_pcibios_fixup_bus,
21216d24060SKumar Gala #endif
21316d24060SKumar Gala 	.get_irq		= mpic_get_irq,
21416d24060SKumar Gala 	.restart		= mpc85xx_restart,
21516d24060SKumar Gala 	.calibrate_decr		= generic_calibrate_decr,
21616d24060SKumar Gala 	.progress		= udbg_progress,
21716d24060SKumar Gala };
2185d54ddcbSKumar Gala 
2195d54ddcbSKumar Gala define_machine(mpc8572_ds) {
2205d54ddcbSKumar Gala 	.name			= "MPC8572 DS",
2215d54ddcbSKumar Gala 	.probe			= mpc8572_ds_probe,
2225d54ddcbSKumar Gala 	.setup_arch		= mpc85xx_ds_setup_arch,
2235d54ddcbSKumar Gala 	.init_IRQ		= mpc85xx_ds_pic_init,
2245d54ddcbSKumar Gala #ifdef CONFIG_PCI
2255d54ddcbSKumar Gala 	.pcibios_fixup_bus	= fsl_pcibios_fixup_bus,
2265d54ddcbSKumar Gala #endif
2275d54ddcbSKumar Gala 	.get_irq		= mpic_get_irq,
2285d54ddcbSKumar Gala 	.restart		= mpc85xx_restart,
2295d54ddcbSKumar Gala 	.calibrate_decr		= generic_calibrate_decr,
2305d54ddcbSKumar Gala 	.progress		= udbg_progress,
2315d54ddcbSKumar Gala };
232