1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 25a7ee319SAlbert Herranz /* 35a7ee319SAlbert Herranz * arch/powerpc/platforms/embedded6xx/wii.c 45a7ee319SAlbert Herranz * 55a7ee319SAlbert Herranz * Nintendo Wii board-specific support 65a7ee319SAlbert Herranz * Copyright (C) 2008-2009 The GameCube Linux Team 75a7ee319SAlbert Herranz * Copyright (C) 2008,2009 Albert Herranz 85a7ee319SAlbert Herranz */ 95a7ee319SAlbert Herranz #define DRV_MODULE_NAME "wii" 105a7ee319SAlbert Herranz #define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt 115a7ee319SAlbert Herranz 125a7ee319SAlbert Herranz #include <linux/kernel.h> 135a7ee319SAlbert Herranz #include <linux/init.h> 145a7ee319SAlbert Herranz #include <linux/irq.h> 155a7ee319SAlbert Herranz #include <linux/seq_file.h> 165a7ee319SAlbert Herranz #include <linux/of_platform.h> 1795f72d1eSYinghai Lu #include <linux/memblock.h> 18de32400dSAlbert Herranz #include <mm/mmu_decl.h> 195a7ee319SAlbert Herranz 205a7ee319SAlbert Herranz #include <asm/io.h> 215a7ee319SAlbert Herranz #include <asm/machdep.h> 225a7ee319SAlbert Herranz #include <asm/prom.h> 235a7ee319SAlbert Herranz #include <asm/time.h> 245a7ee319SAlbert Herranz #include <asm/udbg.h> 255a7ee319SAlbert Herranz 265a7ee319SAlbert Herranz #include "flipper-pic.h" 275a7ee319SAlbert Herranz #include "hlwd-pic.h" 285a7ee319SAlbert Herranz #include "usbgecko_udbg.h" 295a7ee319SAlbert Herranz 305a7ee319SAlbert Herranz /* control block */ 315a7ee319SAlbert Herranz #define HW_CTRL_COMPATIBLE "nintendo,hollywood-control" 325a7ee319SAlbert Herranz 335a7ee319SAlbert Herranz #define HW_CTRL_RESETS 0x94 345a7ee319SAlbert Herranz #define HW_CTRL_RESETS_SYS (1<<0) 355a7ee319SAlbert Herranz 365a7ee319SAlbert Herranz /* gpio */ 375a7ee319SAlbert Herranz #define HW_GPIO_COMPATIBLE "nintendo,hollywood-gpio" 385a7ee319SAlbert Herranz 395a7ee319SAlbert Herranz #define HW_GPIO_BASE(idx) (idx * 0x20) 405a7ee319SAlbert Herranz #define HW_GPIO_OUT(idx) (HW_GPIO_BASE(idx) + 0) 415a7ee319SAlbert Herranz #define HW_GPIO_DIR(idx) (HW_GPIO_BASE(idx) + 4) 429cbaaec1SJonathan Neuschäfer #define HW_GPIO_OWNER (HW_GPIO_BASE(1) + 0x1c) 435a7ee319SAlbert Herranz 445a7ee319SAlbert Herranz #define HW_GPIO_SHUTDOWN (1<<1) 455a7ee319SAlbert Herranz #define HW_GPIO_SLOT_LED (1<<5) 465a7ee319SAlbert Herranz #define HW_GPIO_SENSOR_BAR (1<<8) 475a7ee319SAlbert Herranz 485a7ee319SAlbert Herranz 495a7ee319SAlbert Herranz static void __iomem *hw_ctrl; 505a7ee319SAlbert Herranz static void __iomem *hw_gpio; 515a7ee319SAlbert Herranz 52de32400dSAlbert Herranz static int __init page_aligned(unsigned long x) 53de32400dSAlbert Herranz { 54de32400dSAlbert Herranz return !(x & (PAGE_SIZE-1)); 55de32400dSAlbert Herranz } 56de32400dSAlbert Herranz 57de32400dSAlbert Herranz void __init wii_memory_fixups(void) 58de32400dSAlbert Herranz { 59823108a0SYinghai Lu struct memblock_region *p = memblock.memory.regions; 60de32400dSAlbert Herranz 6195f72d1eSYinghai Lu BUG_ON(memblock.memory.cnt != 2); 62de32400dSAlbert Herranz BUG_ON(!page_aligned(p[0].base) || !page_aligned(p[1].base)); 63de32400dSAlbert Herranz } 64de32400dSAlbert Herranz 6595ec77c0SDaniel Axtens static void __noreturn wii_spin(void) 665a7ee319SAlbert Herranz { 675a7ee319SAlbert Herranz local_irq_disable(); 685a7ee319SAlbert Herranz for (;;) 695a7ee319SAlbert Herranz cpu_relax(); 705a7ee319SAlbert Herranz } 715a7ee319SAlbert Herranz 725a7ee319SAlbert Herranz static void __iomem *wii_ioremap_hw_regs(char *name, char *compatible) 735a7ee319SAlbert Herranz { 745a7ee319SAlbert Herranz void __iomem *hw_regs = NULL; 755a7ee319SAlbert Herranz struct device_node *np; 765a7ee319SAlbert Herranz struct resource res; 775a7ee319SAlbert Herranz int error = -ENODEV; 785a7ee319SAlbert Herranz 795a7ee319SAlbert Herranz np = of_find_compatible_node(NULL, NULL, compatible); 805a7ee319SAlbert Herranz if (!np) { 815a7ee319SAlbert Herranz pr_err("no compatible node found for %s\n", compatible); 825a7ee319SAlbert Herranz goto out; 835a7ee319SAlbert Herranz } 845a7ee319SAlbert Herranz error = of_address_to_resource(np, 0, &res); 855a7ee319SAlbert Herranz if (error) { 86b9ef7b4bSRob Herring pr_err("no valid reg found for %pOFn\n", np); 875a7ee319SAlbert Herranz goto out_put; 885a7ee319SAlbert Herranz } 895a7ee319SAlbert Herranz 905a7ee319SAlbert Herranz hw_regs = ioremap(res.start, resource_size(&res)); 915a7ee319SAlbert Herranz if (hw_regs) { 925a7ee319SAlbert Herranz pr_info("%s at 0x%08x mapped to 0x%p\n", name, 935a7ee319SAlbert Herranz res.start, hw_regs); 945a7ee319SAlbert Herranz } 955a7ee319SAlbert Herranz 965a7ee319SAlbert Herranz out_put: 975a7ee319SAlbert Herranz of_node_put(np); 985a7ee319SAlbert Herranz out: 995a7ee319SAlbert Herranz return hw_regs; 1005a7ee319SAlbert Herranz } 1015a7ee319SAlbert Herranz 1025a7ee319SAlbert Herranz static void __init wii_setup_arch(void) 1035a7ee319SAlbert Herranz { 1045a7ee319SAlbert Herranz hw_ctrl = wii_ioremap_hw_regs("hw_ctrl", HW_CTRL_COMPATIBLE); 1055a7ee319SAlbert Herranz hw_gpio = wii_ioremap_hw_regs("hw_gpio", HW_GPIO_COMPATIBLE); 1065a7ee319SAlbert Herranz if (hw_gpio) { 1075a7ee319SAlbert Herranz /* turn off the front blue led and IR light */ 1085a7ee319SAlbert Herranz clrbits32(hw_gpio + HW_GPIO_OUT(0), 1095a7ee319SAlbert Herranz HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR); 1105a7ee319SAlbert Herranz } 1115a7ee319SAlbert Herranz } 1125a7ee319SAlbert Herranz 11395ec77c0SDaniel Axtens static void __noreturn wii_restart(char *cmd) 1145a7ee319SAlbert Herranz { 1155a7ee319SAlbert Herranz local_irq_disable(); 1165a7ee319SAlbert Herranz 1175a7ee319SAlbert Herranz if (hw_ctrl) { 1185a7ee319SAlbert Herranz /* clear the system reset pin to cause a reset */ 1195a7ee319SAlbert Herranz clrbits32(hw_ctrl + HW_CTRL_RESETS, HW_CTRL_RESETS_SYS); 1205a7ee319SAlbert Herranz } 1215a7ee319SAlbert Herranz wii_spin(); 1225a7ee319SAlbert Herranz } 1235a7ee319SAlbert Herranz 1245a7ee319SAlbert Herranz static void wii_power_off(void) 1255a7ee319SAlbert Herranz { 1265a7ee319SAlbert Herranz local_irq_disable(); 1275a7ee319SAlbert Herranz 1285a7ee319SAlbert Herranz if (hw_gpio) { 1299cbaaec1SJonathan Neuschäfer /* 1309cbaaec1SJonathan Neuschäfer * set the owner of the shutdown pin to ARM, because it is 1319cbaaec1SJonathan Neuschäfer * accessed through the registers for the ARM, below 1329cbaaec1SJonathan Neuschäfer */ 1339cbaaec1SJonathan Neuschäfer clrbits32(hw_gpio + HW_GPIO_OWNER, HW_GPIO_SHUTDOWN); 1349cbaaec1SJonathan Neuschäfer 1355a7ee319SAlbert Herranz /* make sure that the poweroff GPIO is configured as output */ 1365a7ee319SAlbert Herranz setbits32(hw_gpio + HW_GPIO_DIR(1), HW_GPIO_SHUTDOWN); 1375a7ee319SAlbert Herranz 1385a7ee319SAlbert Herranz /* drive the poweroff GPIO high */ 1395a7ee319SAlbert Herranz setbits32(hw_gpio + HW_GPIO_OUT(1), HW_GPIO_SHUTDOWN); 1405a7ee319SAlbert Herranz } 1415a7ee319SAlbert Herranz wii_spin(); 1425a7ee319SAlbert Herranz } 1435a7ee319SAlbert Herranz 14495ec77c0SDaniel Axtens static void __noreturn wii_halt(void) 1455a7ee319SAlbert Herranz { 1465a7ee319SAlbert Herranz if (ppc_md.restart) 1475a7ee319SAlbert Herranz ppc_md.restart(NULL); 1485a7ee319SAlbert Herranz wii_spin(); 1495a7ee319SAlbert Herranz } 1505a7ee319SAlbert Herranz 1515a7ee319SAlbert Herranz static void __init wii_pic_probe(void) 1525a7ee319SAlbert Herranz { 1535a7ee319SAlbert Herranz flipper_pic_probe(); 1545a7ee319SAlbert Herranz hlwd_pic_probe(); 1555a7ee319SAlbert Herranz } 1565a7ee319SAlbert Herranz 1575a7ee319SAlbert Herranz static int __init wii_probe(void) 1585a7ee319SAlbert Herranz { 15956571384SBenjamin Herrenschmidt if (!of_machine_is_compatible("nintendo,wii")) 1605a7ee319SAlbert Herranz return 0; 1615a7ee319SAlbert Herranz 1629178ba29SAlexander Graf pm_power_off = wii_power_off; 1639178ba29SAlexander Graf 164f2d57694SBenjamin Herrenschmidt ug_udbg_init(); 165f2d57694SBenjamin Herrenschmidt 1665a7ee319SAlbert Herranz return 1; 1675a7ee319SAlbert Herranz } 1685a7ee319SAlbert Herranz 1695a7ee319SAlbert Herranz static void wii_shutdown(void) 1705a7ee319SAlbert Herranz { 1715a7ee319SAlbert Herranz hlwd_quiesce(); 1725a7ee319SAlbert Herranz flipper_quiesce(); 1735a7ee319SAlbert Herranz } 1745a7ee319SAlbert Herranz 1755a7ee319SAlbert Herranz define_machine(wii) { 1765a7ee319SAlbert Herranz .name = "wii", 1775a7ee319SAlbert Herranz .probe = wii_probe, 1785a7ee319SAlbert Herranz .setup_arch = wii_setup_arch, 1795a7ee319SAlbert Herranz .restart = wii_restart, 1805a7ee319SAlbert Herranz .halt = wii_halt, 1815a7ee319SAlbert Herranz .init_IRQ = wii_pic_probe, 1825a7ee319SAlbert Herranz .get_irq = flipper_pic_get_irq, 1835a7ee319SAlbert Herranz .calibrate_decr = generic_calibrate_decr, 1845a7ee319SAlbert Herranz .progress = udbg_progress, 1855a7ee319SAlbert Herranz .machine_shutdown = wii_shutdown, 1865a7ee319SAlbert Herranz }; 1875a7ee319SAlbert Herranz 188ce6d73c9SUwe Kleine-König static const struct of_device_id wii_of_bus[] = { 1895a7ee319SAlbert Herranz { .compatible = "nintendo,hollywood", }, 1905a7ee319SAlbert Herranz { }, 1915a7ee319SAlbert Herranz }; 1925a7ee319SAlbert Herranz 1935a7ee319SAlbert Herranz static int __init wii_device_probe(void) 1945a7ee319SAlbert Herranz { 1955a7ee319SAlbert Herranz if (!machine_is(wii)) 1965a7ee319SAlbert Herranz return 0; 1975a7ee319SAlbert Herranz 1987ab96c0aSJonathan Neuschäfer of_platform_populate(NULL, wii_of_bus, NULL, NULL); 1995a7ee319SAlbert Herranz return 0; 2005a7ee319SAlbert Herranz } 2015a7ee319SAlbert Herranz device_initcall(wii_device_probe); 2025a7ee319SAlbert Herranz 203