xref: /linux/arch/powerpc/platforms/embedded6xx/wii.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
12874c5fdSThomas 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>
16e6f6390aSChristophe Leroy #include <linux/of_address.h>
175a7ee319SAlbert Herranz #include <linux/of_platform.h>
185a7ee319SAlbert Herranz 
195a7ee319SAlbert Herranz #include <asm/io.h>
205a7ee319SAlbert Herranz #include <asm/machdep.h>
215a7ee319SAlbert Herranz #include <asm/time.h>
225a7ee319SAlbert Herranz #include <asm/udbg.h>
235a7ee319SAlbert Herranz 
245a7ee319SAlbert Herranz #include "flipper-pic.h"
255a7ee319SAlbert Herranz #include "hlwd-pic.h"
265a7ee319SAlbert Herranz #include "usbgecko_udbg.h"
275a7ee319SAlbert Herranz 
285a7ee319SAlbert Herranz /* control block */
295a7ee319SAlbert Herranz #define HW_CTRL_COMPATIBLE	"nintendo,hollywood-control"
305a7ee319SAlbert Herranz 
315a7ee319SAlbert Herranz #define HW_CTRL_RESETS		0x94
325a7ee319SAlbert Herranz #define HW_CTRL_RESETS_SYS	(1<<0)
335a7ee319SAlbert Herranz 
345a7ee319SAlbert Herranz /* gpio */
355a7ee319SAlbert Herranz #define HW_GPIO_COMPATIBLE	"nintendo,hollywood-gpio"
365a7ee319SAlbert Herranz 
375a7ee319SAlbert Herranz #define HW_GPIO_BASE(idx)	(idx * 0x20)
385a7ee319SAlbert Herranz #define HW_GPIO_OUT(idx)	(HW_GPIO_BASE(idx) + 0)
395a7ee319SAlbert Herranz #define HW_GPIO_DIR(idx)	(HW_GPIO_BASE(idx) + 4)
409cbaaec1SJonathan Neuschäfer #define HW_GPIO_OWNER		(HW_GPIO_BASE(1) + 0x1c)
415a7ee319SAlbert Herranz 
425a7ee319SAlbert Herranz #define HW_GPIO_SHUTDOWN	(1<<1)
435a7ee319SAlbert Herranz #define HW_GPIO_SLOT_LED	(1<<5)
445a7ee319SAlbert Herranz #define HW_GPIO_SENSOR_BAR	(1<<8)
455a7ee319SAlbert Herranz 
465a7ee319SAlbert Herranz 
475a7ee319SAlbert Herranz static void __iomem *hw_ctrl;
485a7ee319SAlbert Herranz static void __iomem *hw_gpio;
495a7ee319SAlbert Herranz 
wii_spin(void)5095ec77c0SDaniel Axtens static void __noreturn wii_spin(void)
515a7ee319SAlbert Herranz {
525a7ee319SAlbert Herranz 	local_irq_disable();
535a7ee319SAlbert Herranz 	for (;;)
545a7ee319SAlbert Herranz 		cpu_relax();
555a7ee319SAlbert Herranz }
565a7ee319SAlbert Herranz 
wii_ioremap_hw_regs(char * name,char * compatible)57c0dc225aSNick Child static void __iomem *__init wii_ioremap_hw_regs(char *name, char *compatible)
585a7ee319SAlbert Herranz {
595a7ee319SAlbert Herranz 	void __iomem *hw_regs = NULL;
605a7ee319SAlbert Herranz 	struct device_node *np;
615a7ee319SAlbert Herranz 	struct resource res;
625a7ee319SAlbert Herranz 	int error = -ENODEV;
635a7ee319SAlbert Herranz 
645a7ee319SAlbert Herranz 	np = of_find_compatible_node(NULL, NULL, compatible);
655a7ee319SAlbert Herranz 	if (!np) {
665a7ee319SAlbert Herranz 		pr_err("no compatible node found for %s\n", compatible);
675a7ee319SAlbert Herranz 		goto out;
685a7ee319SAlbert Herranz 	}
695a7ee319SAlbert Herranz 	error = of_address_to_resource(np, 0, &res);
705a7ee319SAlbert Herranz 	if (error) {
71b9ef7b4bSRob Herring 		pr_err("no valid reg found for %pOFn\n", np);
725a7ee319SAlbert Herranz 		goto out_put;
735a7ee319SAlbert Herranz 	}
745a7ee319SAlbert Herranz 
755a7ee319SAlbert Herranz 	hw_regs = ioremap(res.start, resource_size(&res));
765a7ee319SAlbert Herranz 	if (hw_regs) {
77*7b69600dSRandy Dunlap 		pr_info("%s at 0x%pa mapped to 0x%p\n", name,
78*7b69600dSRandy Dunlap 			&res.start, hw_regs);
795a7ee319SAlbert Herranz 	}
805a7ee319SAlbert Herranz 
815a7ee319SAlbert Herranz out_put:
825a7ee319SAlbert Herranz 	of_node_put(np);
835a7ee319SAlbert Herranz out:
845a7ee319SAlbert Herranz 	return hw_regs;
855a7ee319SAlbert Herranz }
865a7ee319SAlbert Herranz 
wii_setup_arch(void)875a7ee319SAlbert Herranz static void __init wii_setup_arch(void)
885a7ee319SAlbert Herranz {
895a7ee319SAlbert Herranz 	hw_ctrl = wii_ioremap_hw_regs("hw_ctrl", HW_CTRL_COMPATIBLE);
905a7ee319SAlbert Herranz 	hw_gpio = wii_ioremap_hw_regs("hw_gpio", HW_GPIO_COMPATIBLE);
915a7ee319SAlbert Herranz 	if (hw_gpio) {
925a7ee319SAlbert Herranz 		/* turn off the front blue led and IR light */
935a7ee319SAlbert Herranz 		clrbits32(hw_gpio + HW_GPIO_OUT(0),
945a7ee319SAlbert Herranz 			  HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);
955a7ee319SAlbert Herranz 	}
965a7ee319SAlbert Herranz }
975a7ee319SAlbert Herranz 
wii_restart(char * cmd)9895ec77c0SDaniel Axtens static void __noreturn wii_restart(char *cmd)
995a7ee319SAlbert Herranz {
1005a7ee319SAlbert Herranz 	local_irq_disable();
1015a7ee319SAlbert Herranz 
1025a7ee319SAlbert Herranz 	if (hw_ctrl) {
1035a7ee319SAlbert Herranz 		/* clear the system reset pin to cause a reset */
1045a7ee319SAlbert Herranz 		clrbits32(hw_ctrl + HW_CTRL_RESETS, HW_CTRL_RESETS_SYS);
1055a7ee319SAlbert Herranz 	}
1065a7ee319SAlbert Herranz 	wii_spin();
1075a7ee319SAlbert Herranz }
1085a7ee319SAlbert Herranz 
wii_power_off(void)1095a7ee319SAlbert Herranz static void wii_power_off(void)
1105a7ee319SAlbert Herranz {
1115a7ee319SAlbert Herranz 	local_irq_disable();
1125a7ee319SAlbert Herranz 
1135a7ee319SAlbert Herranz 	if (hw_gpio) {
1149cbaaec1SJonathan Neuschäfer 		/*
1159cbaaec1SJonathan Neuschäfer 		 * set the owner of the shutdown pin to ARM, because it is
1169cbaaec1SJonathan Neuschäfer 		 * accessed through the registers for the ARM, below
1179cbaaec1SJonathan Neuschäfer 		 */
1189cbaaec1SJonathan Neuschäfer 		clrbits32(hw_gpio + HW_GPIO_OWNER, HW_GPIO_SHUTDOWN);
1199cbaaec1SJonathan Neuschäfer 
1205a7ee319SAlbert Herranz 		/* make sure that the poweroff GPIO is configured as output */
1215a7ee319SAlbert Herranz 		setbits32(hw_gpio + HW_GPIO_DIR(1), HW_GPIO_SHUTDOWN);
1225a7ee319SAlbert Herranz 
1235a7ee319SAlbert Herranz 		/* drive the poweroff GPIO high */
1245a7ee319SAlbert Herranz 		setbits32(hw_gpio + HW_GPIO_OUT(1), HW_GPIO_SHUTDOWN);
1255a7ee319SAlbert Herranz 	}
1265a7ee319SAlbert Herranz 	wii_spin();
1275a7ee319SAlbert Herranz }
1285a7ee319SAlbert Herranz 
wii_halt(void)12995ec77c0SDaniel Axtens static void __noreturn wii_halt(void)
1305a7ee319SAlbert Herranz {
1315a7ee319SAlbert Herranz 	if (ppc_md.restart)
1325a7ee319SAlbert Herranz 		ppc_md.restart(NULL);
1335a7ee319SAlbert Herranz 	wii_spin();
1345a7ee319SAlbert Herranz }
1355a7ee319SAlbert Herranz 
wii_pic_probe(void)1365a7ee319SAlbert Herranz static void __init wii_pic_probe(void)
1375a7ee319SAlbert Herranz {
1385a7ee319SAlbert Herranz 	flipper_pic_probe();
1395a7ee319SAlbert Herranz 	hlwd_pic_probe();
1405a7ee319SAlbert Herranz }
1415a7ee319SAlbert Herranz 
wii_probe(void)1425a7ee319SAlbert Herranz static int __init wii_probe(void)
1435a7ee319SAlbert Herranz {
1449178ba29SAlexander Graf 	pm_power_off = wii_power_off;
1459178ba29SAlexander Graf 
146f2d57694SBenjamin Herrenschmidt 	ug_udbg_init();
147f2d57694SBenjamin Herrenschmidt 
1485a7ee319SAlbert Herranz 	return 1;
1495a7ee319SAlbert Herranz }
1505a7ee319SAlbert Herranz 
wii_shutdown(void)1515a7ee319SAlbert Herranz static void wii_shutdown(void)
1525a7ee319SAlbert Herranz {
1535a7ee319SAlbert Herranz 	hlwd_quiesce();
1545a7ee319SAlbert Herranz 	flipper_quiesce();
1555a7ee319SAlbert Herranz }
1565a7ee319SAlbert Herranz 
157ce6d73c9SUwe Kleine-König static const struct of_device_id wii_of_bus[] = {
1585a7ee319SAlbert Herranz 	{ .compatible = "nintendo,hollywood", },
1595a7ee319SAlbert Herranz 	{ },
1605a7ee319SAlbert Herranz };
1615a7ee319SAlbert Herranz 
wii_device_probe(void)1625a7ee319SAlbert Herranz static int __init wii_device_probe(void)
1635a7ee319SAlbert Herranz {
1647ab96c0aSJonathan Neuschäfer 	of_platform_populate(NULL, wii_of_bus, NULL, NULL);
1655a7ee319SAlbert Herranz 	return 0;
1665a7ee319SAlbert Herranz }
167f47b17d5SChristophe Leroy machine_device_initcall(wii, wii_device_probe);
1685a7ee319SAlbert Herranz 
define_machine(wii)16991ffeaa7SNathan Chancellor define_machine(wii) {
17091ffeaa7SNathan Chancellor 	.name			= "wii",
1711c96fcdeSChristophe Leroy 	.compatible		= "nintendo,wii",
17291ffeaa7SNathan Chancellor 	.probe			= wii_probe,
17391ffeaa7SNathan Chancellor 	.setup_arch		= wii_setup_arch,
17491ffeaa7SNathan Chancellor 	.restart		= wii_restart,
17591ffeaa7SNathan Chancellor 	.halt			= wii_halt,
17691ffeaa7SNathan Chancellor 	.init_IRQ		= wii_pic_probe,
17791ffeaa7SNathan Chancellor 	.get_irq		= flipper_pic_get_irq,
17891ffeaa7SNathan Chancellor 	.progress		= udbg_progress,
17991ffeaa7SNathan Chancellor 	.machine_shutdown	= wii_shutdown,
18091ffeaa7SNathan Chancellor };
181