Path: blob/master/arch/powerpc/platforms/embedded6xx/wii.c
26489 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* arch/powerpc/platforms/embedded6xx/wii.c3*4* Nintendo Wii board-specific support5* Copyright (C) 2008-2009 The GameCube Linux Team6* Copyright (C) 2008,2009 Albert Herranz7*/8#define DRV_MODULE_NAME "wii"9#define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt1011#include <linux/kernel.h>12#include <linux/init.h>13#include <linux/irq.h>14#include <linux/seq_file.h>15#include <linux/of_address.h>16#include <linux/of_platform.h>1718#include <asm/io.h>19#include <asm/machdep.h>20#include <asm/time.h>21#include <asm/udbg.h>2223#include "flipper-pic.h"24#include "hlwd-pic.h"25#include "usbgecko_udbg.h"2627/* control block */28#define HW_CTRL_COMPATIBLE "nintendo,hollywood-control"2930#define HW_CTRL_RESETS 0x9431#define HW_CTRL_RESETS_SYS (1<<0)3233/* gpio */34#define HW_GPIO_COMPATIBLE "nintendo,hollywood-gpio"3536#define HW_GPIO_BASE(idx) (idx * 0x20)37#define HW_GPIO_OUT(idx) (HW_GPIO_BASE(idx) + 0)38#define HW_GPIO_DIR(idx) (HW_GPIO_BASE(idx) + 4)39#define HW_GPIO_OWNER (HW_GPIO_BASE(1) + 0x1c)4041#define HW_GPIO_SHUTDOWN (1<<1)42#define HW_GPIO_SLOT_LED (1<<5)43#define HW_GPIO_SENSOR_BAR (1<<8)444546static void __iomem *hw_ctrl;47static void __iomem *hw_gpio;4849static void __noreturn wii_spin(void)50{51local_irq_disable();52for (;;)53cpu_relax();54}5556static void __iomem *__init wii_ioremap_hw_regs(char *name, char *compatible)57{58void __iomem *hw_regs = NULL;59struct device_node *np;60struct resource res;61int error = -ENODEV;6263np = of_find_compatible_node(NULL, NULL, compatible);64if (!np) {65pr_err("no compatible node found for %s\n", compatible);66goto out;67}68error = of_address_to_resource(np, 0, &res);69if (error) {70pr_err("no valid reg found for %pOFn\n", np);71goto out_put;72}7374hw_regs = ioremap(res.start, resource_size(&res));75if (hw_regs) {76pr_info("%s at 0x%pa mapped to 0x%p\n", name,77&res.start, hw_regs);78}7980out_put:81of_node_put(np);82out:83return hw_regs;84}8586static void __init wii_setup_arch(void)87{88hw_ctrl = wii_ioremap_hw_regs("hw_ctrl", HW_CTRL_COMPATIBLE);89hw_gpio = wii_ioremap_hw_regs("hw_gpio", HW_GPIO_COMPATIBLE);90if (hw_gpio) {91/* turn off the front blue led and IR light */92clrbits32(hw_gpio + HW_GPIO_OUT(0),93HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);94}95}9697static void __noreturn wii_restart(char *cmd)98{99local_irq_disable();100101if (hw_ctrl) {102/* clear the system reset pin to cause a reset */103clrbits32(hw_ctrl + HW_CTRL_RESETS, HW_CTRL_RESETS_SYS);104}105wii_spin();106}107108static void wii_power_off(void)109{110local_irq_disable();111112if (hw_gpio) {113/*114* set the owner of the shutdown pin to ARM, because it is115* accessed through the registers for the ARM, below116*/117clrbits32(hw_gpio + HW_GPIO_OWNER, HW_GPIO_SHUTDOWN);118119/* make sure that the poweroff GPIO is configured as output */120setbits32(hw_gpio + HW_GPIO_DIR(1), HW_GPIO_SHUTDOWN);121122/* drive the poweroff GPIO high */123setbits32(hw_gpio + HW_GPIO_OUT(1), HW_GPIO_SHUTDOWN);124}125wii_spin();126}127128static void __noreturn wii_halt(void)129{130if (ppc_md.restart)131ppc_md.restart(NULL);132wii_spin();133}134135static void __init wii_pic_probe(void)136{137flipper_pic_probe();138hlwd_pic_probe();139}140141static int __init wii_probe(void)142{143pm_power_off = wii_power_off;144145ug_udbg_init();146147return 1;148}149150static void wii_shutdown(void)151{152hlwd_quiesce();153flipper_quiesce();154}155156static const struct of_device_id wii_of_bus[] = {157{ .compatible = "nintendo,hollywood", },158{ },159};160161static int __init wii_device_probe(void)162{163of_platform_populate(NULL, wii_of_bus, NULL, NULL);164return 0;165}166machine_device_initcall(wii, wii_device_probe);167168define_machine(wii) {169.name = "wii",170.compatible = "nintendo,wii",171.probe = wii_probe,172.setup_arch = wii_setup_arch,173.restart = wii_restart,174.halt = wii_halt,175.init_IRQ = wii_pic_probe,176.get_irq = flipper_pic_get_irq,177.progress = udbg_progress,178.machine_shutdown = wii_shutdown,179};180181182