1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * PowerPC 476FPE board specific routines
5 * Copyright © 2013 Tony Breeds IBM Corporation
6 * Copyright © 2013 Alistair Popple IBM Corporation
8 * Based on earlier code:
9 * Matt Porter <mporter@kernel.crashing.org>
10 * Copyright 2002-2005 MontaVista Software Inc.
12 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
13 * Copyright (c) 2003-2005 Zultys Technologies
15 * Rewritten and ported to the merged powerpc tree:
16 * Copyright 2007 David Gibson <dwg@au1.ibm.com>, IBM Corporation.
17 * Copyright © 2011 David Kliekamp IBM Corporation
20 #include <linux/init.h>
22 #include <linux/of_platform.h>
23 #include <linux/rtc.h>
25 #include <asm/machdep.h>
30 #include <asm/ppc4xx.h>
33 #include <asm/swiotlb.h>
35 #include <linux/pci.h>
36 #include <linux/i2c.h>
38 static const struct of_device_id ppc47x_of_bus[] __initconst = {
39 { .compatible = "ibm,plb4", },
40 { .compatible = "ibm,plb6", },
41 { .compatible = "ibm,opb", },
42 { .compatible = "ibm,ebc", },
46 /* The EEPROM is missing and the default values are bogus. This forces USB in
48 static void quirk_ppc_currituck_usb_fixup(struct pci_dev *dev)
50 if (of_machine_is_compatible("ibm,currituck")) {
51 pci_write_config_dword(dev, 0xe0, 0x0114231f);
52 pci_write_config_dword(dev, 0xe4, 0x00006c40);
55 DECLARE_PCI_FIXUP_HEADER(0x1033, 0x0035, quirk_ppc_currituck_usb_fixup);
57 /* Akebono has an AVR microcontroller attached to the I2C bus
58 * which is used to power off/reset the system. */
60 /* AVR I2C Commands */
61 #define AVR_PWRCTL_CMD (0x26)
63 /* Flags for the power control I2C commands */
64 #define AVR_PWRCTL_PWROFF (0x01)
65 #define AVR_PWRCTL_RESET (0x02)
67 static struct i2c_client *avr_i2c_client;
68 static void __noreturn avr_halt_system(int pwrctl_flags)
70 /* Request the AVR to reset the system */
71 i2c_smbus_write_byte_data(avr_i2c_client,
72 AVR_PWRCTL_CMD, pwrctl_flags);
74 /* Wait for system to be reset */
79 static void avr_power_off_system(void)
81 avr_halt_system(AVR_PWRCTL_PWROFF);
84 static void __noreturn avr_reset_system(char *cmd)
86 avr_halt_system(AVR_PWRCTL_RESET);
89 static int avr_probe(struct i2c_client *client,
90 const struct i2c_device_id *id)
92 avr_i2c_client = client;
93 ppc_md.restart = avr_reset_system;
94 pm_power_off = avr_power_off_system;
98 static const struct i2c_device_id avr_id[] = {
103 static struct i2c_driver avr_driver = {
105 .name = "akebono-avr",
111 static int __init ppc47x_device_probe(void)
113 i2c_add_driver(&avr_driver);
114 of_platform_bus_probe(NULL, ppc47x_of_bus, NULL);
118 machine_device_initcall(ppc47x, ppc47x_device_probe);
120 static void __init ppc47x_init_irq(void)
122 struct device_node *np;
124 /* Find top level interrupt controller */
125 for_each_node_with_property(np, "interrupt-controller") {
126 if (of_get_property(np, "interrupts", NULL) == NULL)
130 panic("Can't find top level interrupt controller");
132 /* Check type and do appropriate initialization */
133 if (of_device_is_compatible(np, "chrp,open-pic")) {
134 /* The MPIC driver will get everything it needs from the
135 * device-tree, just pass 0 to all arguments
138 mpic_alloc(np, 0, MPIC_NO_RESET, 0, 0, " MPIC ");
139 BUG_ON(mpic == NULL);
141 ppc_md.get_irq = mpic_get_irq;
143 panic("Unrecognized top level interrupt controller");
147 static void smp_ppc47x_setup_cpu(int cpu)
149 mpic_setup_this_cpu();
152 static int smp_ppc47x_kick_cpu(int cpu)
154 struct device_node *cpunode = of_get_cpu_node(cpu, NULL);
155 const u64 *spin_table_addr_prop;
157 extern void start_secondary_47x(void);
159 BUG_ON(cpunode == NULL);
161 /* Assume spin table. We could test for the enable-method in
162 * the device-tree but currently there's little point as it's
163 * our only supported method
165 spin_table_addr_prop =
166 of_get_property(cpunode, "cpu-release-addr", NULL);
168 if (spin_table_addr_prop == NULL) {
169 pr_err("CPU%d: Can't start, missing cpu-release-addr !\n",
174 /* Assume it's mapped as part of the linear mapping. This is a bit
175 * fishy but will work fine for now
177 * XXX: Is there any reason to assume differently?
179 spin_table = (u32 *)__va(*spin_table_addr_prop);
180 pr_debug("CPU%d: Spin table mapped at %p\n", cpu, spin_table);
184 spin_table[1] = __pa(start_secondary_47x);
190 static struct smp_ops_t ppc47x_smp_ops = {
191 .probe = smp_mpic_probe,
192 .message_pass = smp_mpic_message_pass,
193 .setup_cpu = smp_ppc47x_setup_cpu,
194 .kick_cpu = smp_ppc47x_kick_cpu,
195 .give_timebase = smp_generic_give_timebase,
196 .take_timebase = smp_generic_take_timebase,
199 static void __init ppc47x_smp_init(void)
201 if (mmu_has_feature(MMU_FTR_TYPE_47x))
202 smp_ops = &ppc47x_smp_ops;
205 #else /* CONFIG_SMP */
206 static void __init ppc47x_smp_init(void) { }
207 #endif /* CONFIG_SMP */
209 static void __init ppc47x_setup_arch(void)
212 /* No need to check the DMA config as we /know/ our windows are all of
213 * RAM. Lets hope that doesn't change */
219 static int board_rev = -1;
220 static int __init ppc47x_get_board_rev(void)
224 struct device_node *np = NULL;
226 if (of_machine_is_compatible("ibm,currituck")) {
227 np = of_find_compatible_node(NULL, NULL, "ibm,currituck-fpga");
229 } else if (of_machine_is_compatible("ibm,akebono")) {
230 np = of_find_compatible_node(NULL, NULL, "ibm,akebono-fpga");
237 fpga = (u8 *) of_iomap(np, 0);
242 board_rev = ioread8(fpga + reg) & 0x03;
243 pr_info("%s: Found board revision %d\n", __func__, board_rev);
248 pr_info("%s: Unable to find board revision\n", __func__);
251 machine_arch_initcall(ppc47x, ppc47x_get_board_rev);
253 /* Use USB controller should have been hardware swizzled but it wasn't :( */
254 static void ppc47x_pci_irq_fixup(struct pci_dev *dev)
256 if (dev->vendor == 0x1033 && (dev->device == 0x0035 ||
257 dev->device == 0x00e0)) {
258 if (board_rev == 0) {
259 dev->irq = irq_create_mapping(NULL, 47);
260 pr_info("%s: Mapping irq %d\n", __func__, dev->irq);
261 } else if (board_rev == 2) {
262 dev->irq = irq_create_mapping(NULL, 49);
263 pr_info("%s: Mapping irq %d\n", __func__, dev->irq);
265 pr_alert("%s: Unknown board revision\n", __func__);
271 * Called very early, MMU is off, device-tree isn't unflattened
273 static int __init ppc47x_probe(void)
275 if (of_machine_is_compatible("ibm,akebono"))
278 if (of_machine_is_compatible("ibm,currituck")) {
279 ppc_md.pci_irq_fixup = ppc47x_pci_irq_fixup;
286 define_machine(ppc47x) {
287 .name = "PowerPC 47x",
288 .probe = ppc47x_probe,
289 .progress = udbg_progress,
290 .init_IRQ = ppc47x_init_irq,
291 .setup_arch = ppc47x_setup_arch,
292 .restart = ppc4xx_reset_system,
293 .calibrate_decr = generic_calibrate_decr,