xref: /linux/arch/powerpc/platforms/embedded6xx/wii.c (revision dec1c62e91ba268ab2a6e339d4d7a59287d5eba1)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * arch/powerpc/platforms/embedded6xx/wii.c
4  *
5  * Nintendo Wii board-specific support
6  * Copyright (C) 2008-2009 The GameCube Linux Team
7  * Copyright (C) 2008,2009 Albert Herranz
8  */
9 #define DRV_MODULE_NAME "wii"
10 #define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt
11 
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/irq.h>
15 #include <linux/seq_file.h>
16 #include <linux/of_address.h>
17 #include <linux/of_platform.h>
18 #include <linux/memblock.h>
19 #include <mm/mmu_decl.h>
20 
21 #include <asm/io.h>
22 #include <asm/machdep.h>
23 #include <asm/time.h>
24 #include <asm/udbg.h>
25 
26 #include "flipper-pic.h"
27 #include "hlwd-pic.h"
28 #include "usbgecko_udbg.h"
29 
30 /* control block */
31 #define HW_CTRL_COMPATIBLE	"nintendo,hollywood-control"
32 
33 #define HW_CTRL_RESETS		0x94
34 #define HW_CTRL_RESETS_SYS	(1<<0)
35 
36 /* gpio */
37 #define HW_GPIO_COMPATIBLE	"nintendo,hollywood-gpio"
38 
39 #define HW_GPIO_BASE(idx)	(idx * 0x20)
40 #define HW_GPIO_OUT(idx)	(HW_GPIO_BASE(idx) + 0)
41 #define HW_GPIO_DIR(idx)	(HW_GPIO_BASE(idx) + 4)
42 #define HW_GPIO_OWNER		(HW_GPIO_BASE(1) + 0x1c)
43 
44 #define HW_GPIO_SHUTDOWN	(1<<1)
45 #define HW_GPIO_SLOT_LED	(1<<5)
46 #define HW_GPIO_SENSOR_BAR	(1<<8)
47 
48 
49 static void __iomem *hw_ctrl;
50 static void __iomem *hw_gpio;
51 
52 static int __init page_aligned(unsigned long x)
53 {
54 	return !(x & (PAGE_SIZE-1));
55 }
56 
57 void __init wii_memory_fixups(void)
58 {
59 	struct memblock_region *p = memblock.memory.regions;
60 
61 	BUG_ON(memblock.memory.cnt != 2);
62 	BUG_ON(!page_aligned(p[0].base) || !page_aligned(p[1].base));
63 }
64 
65 static void __noreturn wii_spin(void)
66 {
67 	local_irq_disable();
68 	for (;;)
69 		cpu_relax();
70 }
71 
72 static void __iomem *__init wii_ioremap_hw_regs(char *name, char *compatible)
73 {
74 	void __iomem *hw_regs = NULL;
75 	struct device_node *np;
76 	struct resource res;
77 	int error = -ENODEV;
78 
79 	np = of_find_compatible_node(NULL, NULL, compatible);
80 	if (!np) {
81 		pr_err("no compatible node found for %s\n", compatible);
82 		goto out;
83 	}
84 	error = of_address_to_resource(np, 0, &res);
85 	if (error) {
86 		pr_err("no valid reg found for %pOFn\n", np);
87 		goto out_put;
88 	}
89 
90 	hw_regs = ioremap(res.start, resource_size(&res));
91 	if (hw_regs) {
92 		pr_info("%s at 0x%08x mapped to 0x%p\n", name,
93 			res.start, hw_regs);
94 	}
95 
96 out_put:
97 	of_node_put(np);
98 out:
99 	return hw_regs;
100 }
101 
102 static void __init wii_setup_arch(void)
103 {
104 	hw_ctrl = wii_ioremap_hw_regs("hw_ctrl", HW_CTRL_COMPATIBLE);
105 	hw_gpio = wii_ioremap_hw_regs("hw_gpio", HW_GPIO_COMPATIBLE);
106 	if (hw_gpio) {
107 		/* turn off the front blue led and IR light */
108 		clrbits32(hw_gpio + HW_GPIO_OUT(0),
109 			  HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);
110 	}
111 }
112 
113 static void __noreturn wii_restart(char *cmd)
114 {
115 	local_irq_disable();
116 
117 	if (hw_ctrl) {
118 		/* clear the system reset pin to cause a reset */
119 		clrbits32(hw_ctrl + HW_CTRL_RESETS, HW_CTRL_RESETS_SYS);
120 	}
121 	wii_spin();
122 }
123 
124 static void wii_power_off(void)
125 {
126 	local_irq_disable();
127 
128 	if (hw_gpio) {
129 		/*
130 		 * set the owner of the shutdown pin to ARM, because it is
131 		 * accessed through the registers for the ARM, below
132 		 */
133 		clrbits32(hw_gpio + HW_GPIO_OWNER, HW_GPIO_SHUTDOWN);
134 
135 		/* make sure that the poweroff GPIO is configured as output */
136 		setbits32(hw_gpio + HW_GPIO_DIR(1), HW_GPIO_SHUTDOWN);
137 
138 		/* drive the poweroff GPIO high */
139 		setbits32(hw_gpio + HW_GPIO_OUT(1), HW_GPIO_SHUTDOWN);
140 	}
141 	wii_spin();
142 }
143 
144 static void __noreturn wii_halt(void)
145 {
146 	if (ppc_md.restart)
147 		ppc_md.restart(NULL);
148 	wii_spin();
149 }
150 
151 static void __init wii_pic_probe(void)
152 {
153 	flipper_pic_probe();
154 	hlwd_pic_probe();
155 }
156 
157 static int __init wii_probe(void)
158 {
159 	if (!of_machine_is_compatible("nintendo,wii"))
160 		return 0;
161 
162 	pm_power_off = wii_power_off;
163 
164 	ug_udbg_init();
165 
166 	return 1;
167 }
168 
169 static void wii_shutdown(void)
170 {
171 	hlwd_quiesce();
172 	flipper_quiesce();
173 }
174 
175 static const struct of_device_id wii_of_bus[] = {
176 	{ .compatible = "nintendo,hollywood", },
177 	{ },
178 };
179 
180 static int __init wii_device_probe(void)
181 {
182 	if (!machine_is(wii))
183 		return 0;
184 
185 	of_platform_populate(NULL, wii_of_bus, NULL, NULL);
186 	return 0;
187 }
188 device_initcall(wii_device_probe);
189 
190 define_machine(wii) {
191 	.name			= "wii",
192 	.probe			= wii_probe,
193 	.setup_arch		= wii_setup_arch,
194 	.restart		= wii_restart,
195 	.halt			= wii_halt,
196 	.init_IRQ		= wii_pic_probe,
197 	.get_irq		= flipper_pic_get_irq,
198 	.calibrate_decr		= generic_calibrate_decr,
199 	.progress		= udbg_progress,
200 	.machine_shutdown	= wii_shutdown,
201 };
202