xref: /linux/arch/powerpc/platforms/44x/ppc476.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
26b11930fSAlistair Popple /*
36b11930fSAlistair Popple  * PowerPC 476FPE board specific routines
46b11930fSAlistair Popple  *
52a2c74b2SAlistair Popple  * Copyright © 2013 Tony Breeds IBM Corporation
62a2c74b2SAlistair Popple  * Copyright © 2013 Alistair Popple IBM Corporation
76b11930fSAlistair Popple  *
86b11930fSAlistair Popple  * Based on earlier code:
96b11930fSAlistair Popple  *    Matt Porter <mporter@kernel.crashing.org>
106b11930fSAlistair Popple  *    Copyright 2002-2005 MontaVista Software Inc.
116b11930fSAlistair Popple  *
126b11930fSAlistair Popple  *    Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
136b11930fSAlistair Popple  *    Copyright (c) 2003-2005 Zultys Technologies
146b11930fSAlistair Popple  *
156b11930fSAlistair Popple  *    Rewritten and ported to the merged powerpc tree:
166b11930fSAlistair Popple  *    Copyright 2007 David Gibson <dwg@au1.ibm.com>, IBM Corporation.
176b11930fSAlistair Popple  *    Copyright © 2011 David Kliekamp IBM Corporation
186b11930fSAlistair Popple  */
196b11930fSAlistair Popple 
206b11930fSAlistair Popple #include <linux/init.h>
216b11930fSAlistair Popple #include <linux/of.h>
22e6f6390aSChristophe Leroy #include <linux/of_address.h>
236b11930fSAlistair Popple #include <linux/of_platform.h>
246b11930fSAlistair Popple #include <linux/rtc.h>
256b11930fSAlistair Popple 
266b11930fSAlistair Popple #include <asm/machdep.h>
276b11930fSAlistair Popple #include <asm/udbg.h>
286b11930fSAlistair Popple #include <asm/time.h>
296b11930fSAlistair Popple #include <asm/uic.h>
306b11930fSAlistair Popple #include <asm/ppc4xx.h>
316b11930fSAlistair Popple #include <asm/mpic.h>
326b11930fSAlistair Popple #include <asm/mmu.h>
334a605e2dSChristoph Hellwig #include <asm/swiotlb.h>
346b11930fSAlistair Popple 
356b11930fSAlistair Popple #include <linux/pci.h>
362a2c74b2SAlistair Popple #include <linux/i2c.h>
376b11930fSAlistair Popple 
38ce6d73c9SUwe Kleine-König static const struct of_device_id ppc47x_of_bus[] __initconst = {
396b11930fSAlistair Popple 	{ .compatible = "ibm,plb4", },
406b11930fSAlistair Popple 	{ .compatible = "ibm,plb6", },
416b11930fSAlistair Popple 	{ .compatible = "ibm,opb", },
426b11930fSAlistair Popple 	{ .compatible = "ibm,ebc", },
436b11930fSAlistair Popple 	{},
446b11930fSAlistair Popple };
456b11930fSAlistair Popple 
466b11930fSAlistair Popple /* The EEPROM is missing and the default values are bogus.  This forces USB in
476b11930fSAlistair Popple  * to EHCI mode */
quirk_ppc_currituck_usb_fixup(struct pci_dev * dev)486b11930fSAlistair Popple static void quirk_ppc_currituck_usb_fixup(struct pci_dev *dev)
496b11930fSAlistair Popple {
506b11930fSAlistair Popple 	if (of_machine_is_compatible("ibm,currituck")) {
516b11930fSAlistair Popple 		pci_write_config_dword(dev, 0xe0, 0x0114231f);
526b11930fSAlistair Popple 		pci_write_config_dword(dev, 0xe4, 0x00006c40);
536b11930fSAlistair Popple 	}
546b11930fSAlistair Popple }
556b11930fSAlistair Popple DECLARE_PCI_FIXUP_HEADER(0x1033, 0x0035, quirk_ppc_currituck_usb_fixup);
566b11930fSAlistair Popple 
572a2c74b2SAlistair Popple /* Akebono has an AVR microcontroller attached to the I2C bus
582a2c74b2SAlistair Popple  * which is used to power off/reset the system. */
592a2c74b2SAlistair Popple 
602a2c74b2SAlistair Popple /* AVR I2C Commands */
612a2c74b2SAlistair Popple #define AVR_PWRCTL_CMD (0x26)
622a2c74b2SAlistair Popple 
632a2c74b2SAlistair Popple /* Flags for the power control I2C commands */
642a2c74b2SAlistair Popple #define AVR_PWRCTL_PWROFF (0x01)
652a2c74b2SAlistair Popple #define AVR_PWRCTL_RESET (0x02)
662a2c74b2SAlistair Popple 
672a2c74b2SAlistair Popple static struct i2c_client *avr_i2c_client;
avr_halt_system(int pwrctl_flags)6895ec77c0SDaniel Axtens static void __noreturn avr_halt_system(int pwrctl_flags)
692a2c74b2SAlistair Popple {
702a2c74b2SAlistair Popple 	/* Request the AVR to reset the system */
712a2c74b2SAlistair Popple 	i2c_smbus_write_byte_data(avr_i2c_client,
722a2c74b2SAlistair Popple 				  AVR_PWRCTL_CMD, pwrctl_flags);
732a2c74b2SAlistair Popple 
742a2c74b2SAlistair Popple 	/* Wait for system to be reset */
752a2c74b2SAlistair Popple 	while (1)
762a2c74b2SAlistair Popple 		;
772a2c74b2SAlistair Popple }
782a2c74b2SAlistair Popple 
avr_power_off_system(void)792a2c74b2SAlistair Popple static void avr_power_off_system(void)
802a2c74b2SAlistair Popple {
812a2c74b2SAlistair Popple 	avr_halt_system(AVR_PWRCTL_PWROFF);
822a2c74b2SAlistair Popple }
832a2c74b2SAlistair Popple 
avr_reset_system(char * cmd)8495ec77c0SDaniel Axtens static void __noreturn avr_reset_system(char *cmd)
852a2c74b2SAlistair Popple {
862a2c74b2SAlistair Popple 	avr_halt_system(AVR_PWRCTL_RESET);
872a2c74b2SAlistair Popple }
882a2c74b2SAlistair Popple 
avr_probe(struct i2c_client * client)896c9100eaSStephen Kitt static int avr_probe(struct i2c_client *client)
902a2c74b2SAlistair Popple {
912a2c74b2SAlistair Popple 	avr_i2c_client = client;
922a2c74b2SAlistair Popple 	ppc_md.restart = avr_reset_system;
939178ba29SAlexander Graf 	pm_power_off = avr_power_off_system;
942a2c74b2SAlistair Popple 	return 0;
952a2c74b2SAlistair Popple }
962a2c74b2SAlistair Popple 
972a2c74b2SAlistair Popple static const struct i2c_device_id avr_id[] = {
98*c4afe3ebSUwe Kleine-König 	{ "akebono-avr" },
992a2c74b2SAlistair Popple 	{ }
1002a2c74b2SAlistair Popple };
1012a2c74b2SAlistair Popple 
1022a2c74b2SAlistair Popple static struct i2c_driver avr_driver = {
1032a2c74b2SAlistair Popple 	.driver = {
1042a2c74b2SAlistair Popple 		.name = "akebono-avr",
1052a2c74b2SAlistair Popple 	},
10648f2444eSUwe Kleine-König 	.probe = avr_probe,
1072a2c74b2SAlistair Popple 	.id_table = avr_id,
1082a2c74b2SAlistair Popple };
1092a2c74b2SAlistair Popple 
ppc47x_device_probe(void)1106b11930fSAlistair Popple static int __init ppc47x_device_probe(void)
1116b11930fSAlistair Popple {
1122a2c74b2SAlistair Popple 	i2c_add_driver(&avr_driver);
1136b11930fSAlistair Popple 	of_platform_bus_probe(NULL, ppc47x_of_bus, NULL);
1146b11930fSAlistair Popple 
1156b11930fSAlistair Popple 	return 0;
1166b11930fSAlistair Popple }
117357f8239SChristophe Leroy machine_device_initcall(ppc47x_akebono, ppc47x_device_probe);
118357f8239SChristophe Leroy machine_device_initcall(ppc47x_currituck, ppc47x_device_probe);
1196b11930fSAlistair Popple 
ppc47x_init_irq(void)1206b11930fSAlistair Popple static void __init ppc47x_init_irq(void)
1216b11930fSAlistair Popple {
1226b11930fSAlistair Popple 	struct device_node *np;
1236b11930fSAlistair Popple 
1246b11930fSAlistair Popple 	/* Find top level interrupt controller */
1256b11930fSAlistair Popple 	for_each_node_with_property(np, "interrupt-controller") {
126857d423cSRob Herring 		if (!of_property_present(np, "interrupts"))
1276b11930fSAlistair Popple 			break;
1286b11930fSAlistair Popple 	}
1296b11930fSAlistair Popple 	if (np == NULL)
1306b11930fSAlistair Popple 		panic("Can't find top level interrupt controller");
1316b11930fSAlistair Popple 
1326b11930fSAlistair Popple 	/* Check type and do appropriate initialization */
1336b11930fSAlistair Popple 	if (of_device_is_compatible(np, "chrp,open-pic")) {
1346b11930fSAlistair Popple 		/* The MPIC driver will get everything it needs from the
1356b11930fSAlistair Popple 		 * device-tree, just pass 0 to all arguments
1366b11930fSAlistair Popple 		 */
1376b11930fSAlistair Popple 		struct mpic *mpic =
1386b11930fSAlistair Popple 			mpic_alloc(np, 0, MPIC_NO_RESET, 0, 0, " MPIC     ");
1396b11930fSAlistair Popple 		BUG_ON(mpic == NULL);
1406b11930fSAlistair Popple 		mpic_init(mpic);
1416b11930fSAlistair Popple 		ppc_md.get_irq = mpic_get_irq;
1426b11930fSAlistair Popple 	} else
1436b11930fSAlistair Popple 		panic("Unrecognized top level interrupt controller");
1449d86f091SLiang He 
1459d86f091SLiang He 	of_node_put(np);
1466b11930fSAlistair Popple }
1476b11930fSAlistair Popple 
1486b11930fSAlistair Popple #ifdef CONFIG_SMP
smp_ppc47x_setup_cpu(int cpu)1496b11930fSAlistair Popple static void smp_ppc47x_setup_cpu(int cpu)
1506b11930fSAlistair Popple {
1516b11930fSAlistair Popple 	mpic_setup_this_cpu();
1526b11930fSAlistair Popple }
1536b11930fSAlistair Popple 
smp_ppc47x_kick_cpu(int cpu)1546b11930fSAlistair Popple static int smp_ppc47x_kick_cpu(int cpu)
1556b11930fSAlistair Popple {
1566b11930fSAlistair Popple 	struct device_node *cpunode = of_get_cpu_node(cpu, NULL);
1576b11930fSAlistair Popple 	const u64 *spin_table_addr_prop;
1586b11930fSAlistair Popple 	u32 *spin_table;
1596b11930fSAlistair Popple 	extern void start_secondary_47x(void);
1606b11930fSAlistair Popple 
1616b11930fSAlistair Popple 	BUG_ON(cpunode == NULL);
1626b11930fSAlistair Popple 
1636b11930fSAlistair Popple 	/* Assume spin table. We could test for the enable-method in
1646b11930fSAlistair Popple 	 * the device-tree but currently there's little point as it's
1656b11930fSAlistair Popple 	 * our only supported method
1666b11930fSAlistair Popple 	 */
1676b11930fSAlistair Popple 	spin_table_addr_prop =
1686b11930fSAlistair Popple 		of_get_property(cpunode, "cpu-release-addr", NULL);
1696b11930fSAlistair Popple 
1706b11930fSAlistair Popple 	if (spin_table_addr_prop == NULL) {
1716b11930fSAlistair Popple 		pr_err("CPU%d: Can't start, missing cpu-release-addr !\n",
1726b11930fSAlistair Popple 		       cpu);
1736b11930fSAlistair Popple 		return 1;
1746b11930fSAlistair Popple 	}
1756b11930fSAlistair Popple 
1766b11930fSAlistair Popple 	/* Assume it's mapped as part of the linear mapping. This is a bit
1776b11930fSAlistair Popple 	 * fishy but will work fine for now
1786b11930fSAlistair Popple 	 *
1796b11930fSAlistair Popple 	 * XXX: Is there any reason to assume differently?
1806b11930fSAlistair Popple 	 */
1816b11930fSAlistair Popple 	spin_table = (u32 *)__va(*spin_table_addr_prop);
1826b11930fSAlistair Popple 	pr_debug("CPU%d: Spin table mapped at %p\n", cpu, spin_table);
1836b11930fSAlistair Popple 
1846b11930fSAlistair Popple 	spin_table[3] = cpu;
1856b11930fSAlistair Popple 	smp_wmb();
1866b11930fSAlistair Popple 	spin_table[1] = __pa(start_secondary_47x);
1876b11930fSAlistair Popple 	mb();
1886b11930fSAlistair Popple 
1896b11930fSAlistair Popple 	return 0;
1906b11930fSAlistair Popple }
1916b11930fSAlistair Popple 
1926b11930fSAlistair Popple static struct smp_ops_t ppc47x_smp_ops = {
1936b11930fSAlistair Popple 	.probe		= smp_mpic_probe,
1946b11930fSAlistair Popple 	.message_pass	= smp_mpic_message_pass,
1956b11930fSAlistair Popple 	.setup_cpu	= smp_ppc47x_setup_cpu,
1966b11930fSAlistair Popple 	.kick_cpu	= smp_ppc47x_kick_cpu,
1976b11930fSAlistair Popple 	.give_timebase	= smp_generic_give_timebase,
1986b11930fSAlistair Popple 	.take_timebase	= smp_generic_take_timebase,
1996b11930fSAlistair Popple };
2006b11930fSAlistair Popple 
ppc47x_smp_init(void)2016b11930fSAlistair Popple static void __init ppc47x_smp_init(void)
2026b11930fSAlistair Popple {
2036b11930fSAlistair Popple 	if (mmu_has_feature(MMU_FTR_TYPE_47x))
2046b11930fSAlistair Popple 		smp_ops = &ppc47x_smp_ops;
2056b11930fSAlistair Popple }
2066b11930fSAlistair Popple 
2076b11930fSAlistair Popple #else /* CONFIG_SMP */
ppc47x_smp_init(void)2086b11930fSAlistair Popple static void __init ppc47x_smp_init(void) { }
2096b11930fSAlistair Popple #endif /* CONFIG_SMP */
2106b11930fSAlistair Popple 
ppc47x_setup_arch(void)2116b11930fSAlistair Popple static void __init ppc47x_setup_arch(void)
2126b11930fSAlistair Popple {
2136b11930fSAlistair Popple 
2146b11930fSAlistair Popple 	/* No need to check the DMA config as we /know/ our windows are all of
2156b11930fSAlistair Popple 	 * RAM.  Lets hope that doesn't change */
2166b11930fSAlistair Popple 	swiotlb_detect_4g();
2176b11930fSAlistair Popple 
2186b11930fSAlistair Popple 	ppc47x_smp_init();
2196b11930fSAlistair Popple }
2206b11930fSAlistair Popple 
2216b11930fSAlistair Popple static int board_rev = -1;
ppc47x_get_board_rev(void)2226b11930fSAlistair Popple static int __init ppc47x_get_board_rev(void)
2236b11930fSAlistair Popple {
2242a2c74b2SAlistair Popple 	int reg;
225494f238aSChristophe Leroy 	u8 __iomem *fpga;
2262a2c74b2SAlistair Popple 	struct device_node *np = NULL;
2276b11930fSAlistair Popple 
2282a2c74b2SAlistair Popple 	if (of_machine_is_compatible("ibm,currituck")) {
2296b11930fSAlistair Popple 		np = of_find_compatible_node(NULL, NULL, "ibm,currituck-fpga");
2302a2c74b2SAlistair Popple 		reg = 0;
2312a2c74b2SAlistair Popple 	} else if (of_machine_is_compatible("ibm,akebono")) {
2322a2c74b2SAlistair Popple 		np = of_find_compatible_node(NULL, NULL, "ibm,akebono-fpga");
2332a2c74b2SAlistair Popple 		reg = 2;
2342a2c74b2SAlistair Popple 	}
2352a2c74b2SAlistair Popple 
2366b11930fSAlistair Popple 	if (!np)
2376b11930fSAlistair Popple 		goto fail;
2386b11930fSAlistair Popple 
239494f238aSChristophe Leroy 	fpga = of_iomap(np, 0);
2406b11930fSAlistair Popple 	of_node_put(np);
2416b11930fSAlistair Popple 	if (!fpga)
2426b11930fSAlistair Popple 		goto fail;
2436b11930fSAlistair Popple 
2442a2c74b2SAlistair Popple 	board_rev = ioread8(fpga + reg) & 0x03;
2456b11930fSAlistair Popple 	pr_info("%s: Found board revision %d\n", __func__, board_rev);
2466b11930fSAlistair Popple 	iounmap(fpga);
2476b11930fSAlistair Popple 	return 0;
2486b11930fSAlistair Popple 
2496b11930fSAlistair Popple fail:
2506b11930fSAlistair Popple 	pr_info("%s: Unable to find board revision\n", __func__);
2516b11930fSAlistair Popple 	return 0;
2526b11930fSAlistair Popple }
253357f8239SChristophe Leroy machine_arch_initcall(ppc47x_akebono, ppc47x_get_board_rev);
254357f8239SChristophe Leroy machine_arch_initcall(ppc47x_currituck, ppc47x_get_board_rev);
2556b11930fSAlistair Popple 
2566b11930fSAlistair Popple /* Use USB controller should have been hardware swizzled but it wasn't :( */
ppc47x_pci_irq_fixup(struct pci_dev * dev)2576b11930fSAlistair Popple static void ppc47x_pci_irq_fixup(struct pci_dev *dev)
2586b11930fSAlistair Popple {
2596b11930fSAlistair Popple 	if (dev->vendor == 0x1033 && (dev->device == 0x0035 ||
2606b11930fSAlistair Popple 				      dev->device == 0x00e0)) {
2616b11930fSAlistair Popple 		if (board_rev == 0) {
2626b11930fSAlistair Popple 			dev->irq = irq_create_mapping(NULL, 47);
2636b11930fSAlistair Popple 			pr_info("%s: Mapping irq %d\n", __func__, dev->irq);
2646b11930fSAlistair Popple 		} else if (board_rev == 2) {
2656b11930fSAlistair Popple 			dev->irq = irq_create_mapping(NULL, 49);
2666b11930fSAlistair Popple 			pr_info("%s: Mapping irq %d\n", __func__, dev->irq);
2676b11930fSAlistair Popple 		} else {
2686b11930fSAlistair Popple 			pr_alert("%s: Unknown board revision\n", __func__);
2696b11930fSAlistair Popple 		}
2706b11930fSAlistair Popple 	}
2716b11930fSAlistair Popple }
2726b11930fSAlistair Popple 
define_machine(ppc47x_akebono)273357f8239SChristophe Leroy define_machine(ppc47x_akebono) {
274357f8239SChristophe Leroy 	.name			= "PowerPC 47x (akebono)",
275357f8239SChristophe Leroy 	.compatible		= "ibm,akebono",
2766b11930fSAlistair Popple 	.progress		= udbg_progress,
2776b11930fSAlistair Popple 	.init_IRQ		= ppc47x_init_irq,
2786b11930fSAlistair Popple 	.setup_arch		= ppc47x_setup_arch,
2796b11930fSAlistair Popple 	.restart		= ppc4xx_reset_system,
2806b11930fSAlistair Popple };
281357f8239SChristophe Leroy 
define_machine(ppc47x_currituck)282357f8239SChristophe Leroy define_machine(ppc47x_currituck) {
283357f8239SChristophe Leroy 	.name			= "PowerPC 47x (currituck)",
284357f8239SChristophe Leroy 	.compatible		= "ibm,currituck",
285357f8239SChristophe Leroy 	.progress		= udbg_progress,
286357f8239SChristophe Leroy 	.init_IRQ		= ppc47x_init_irq,
287357f8239SChristophe Leroy 	.pci_irq_fixup		= ppc47x_pci_irq_fixup,
288357f8239SChristophe Leroy 	.setup_arch		= ppc47x_setup_arch,
289357f8239SChristophe Leroy 	.restart		= ppc4xx_reset_system,
290357f8239SChristophe Leroy };
291