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