~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/platforms/embedded6xx/wii.c

Version: ~ [ linux-6.3-rc3 ] ~ [ linux-6.2.7 ] ~ [ linux-6.1.20 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.103 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.175 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.237 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.278 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.310 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 
 48 #define HW_GPIO_SHUTDOWN        (1<<1)
 49 #define HW_GPIO_SLOT_LED        (1<<5)
 50 #define HW_GPIO_SENSOR_BAR      (1<<8)
 51 
 52 
 53 static void __iomem *hw_ctrl;
 54 static void __iomem *hw_gpio;
 55 
 56 unsigned long wii_hole_start;
 57 unsigned long wii_hole_size;
 58 
 59 
 60 static int __init page_aligned(unsigned long x)
 61 {
 62         return !(x & (PAGE_SIZE-1));
 63 }
 64 
 65 void __init wii_memory_fixups(void)
 66 {
 67         struct memblock_region *p = memblock.memory.regions;
 68 
 69         /*
 70          * This is part of a workaround to allow the use of two
 71          * discontinuous RAM ranges on the Wii, even if this is
 72          * currently unsupported on 32-bit PowerPC Linux.
 73          *
 74          * We coalesce the two memory ranges of the Wii into a
 75          * single range, then create a reservation for the "hole"
 76          * between both ranges.
 77          */
 78 
 79         BUG_ON(memblock.memory.cnt != 2);
 80         BUG_ON(!page_aligned(p[0].base) || !page_aligned(p[1].base));
 81 
 82         /* trim unaligned tail */
 83         memblock_remove(ALIGN(p[1].base + p[1].size, PAGE_SIZE),
 84                         (phys_addr_t)ULLONG_MAX);
 85 
 86         /* determine hole, add & reserve them */
 87         wii_hole_start = ALIGN(p[0].base + p[0].size, PAGE_SIZE);
 88         wii_hole_size = p[1].base - wii_hole_start;
 89         memblock_add(wii_hole_start, wii_hole_size);
 90         memblock_reserve(wii_hole_start, wii_hole_size);
 91 
 92         BUG_ON(memblock.memory.cnt != 1);
 93         __memblock_dump_all();
 94 
 95         /* allow ioremapping the address space in the hole */
 96         __allow_ioremap_reserved = 1;
 97 }
 98 
 99 unsigned long __init wii_mmu_mapin_mem2(unsigned long top)
100 {
101         unsigned long delta, size, bl;
102         unsigned long max_size = (256<<20);
103 
104         /* MEM2 64MB@0x10000000 */
105         delta = wii_hole_start + wii_hole_size;
106         size = top - delta;
107         for (bl = 128<<10; bl < max_size; bl <<= 1) {
108                 if (bl * 2 > size)
109                         break;
110         }
111         setbat(4, PAGE_OFFSET+delta, delta, bl, PAGE_KERNEL_X);
112         return delta + bl;
113 }
114 
115 static void __noreturn wii_spin(void)
116 {
117         local_irq_disable();
118         for (;;)
119                 cpu_relax();
120 }
121 
122 static void __iomem *wii_ioremap_hw_regs(char *name, char *compatible)
123 {
124         void __iomem *hw_regs = NULL;
125         struct device_node *np;
126         struct resource res;
127         int error = -ENODEV;
128 
129         np = of_find_compatible_node(NULL, NULL, compatible);
130         if (!np) {
131                 pr_err("no compatible node found for %s\n", compatible);
132                 goto out;
133         }
134         error = of_address_to_resource(np, 0, &res);
135         if (error) {
136                 pr_err("no valid reg found for %s\n", np->name);
137                 goto out_put;
138         }
139 
140         hw_regs = ioremap(res.start, resource_size(&res));
141         if (hw_regs) {
142                 pr_info("%s at 0x%08x mapped to 0x%p\n", name,
143                         res.start, hw_regs);
144         }
145 
146 out_put:
147         of_node_put(np);
148 out:
149         return hw_regs;
150 }
151 
152 static void __init wii_setup_arch(void)
153 {
154         hw_ctrl = wii_ioremap_hw_regs("hw_ctrl", HW_CTRL_COMPATIBLE);
155         hw_gpio = wii_ioremap_hw_regs("hw_gpio", HW_GPIO_COMPATIBLE);
156         if (hw_gpio) {
157                 /* turn off the front blue led and IR light */
158                 clrbits32(hw_gpio + HW_GPIO_OUT(0),
159                           HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);
160         }
161 }
162 
163 static void __noreturn wii_restart(char *cmd)
164 {
165         local_irq_disable();
166 
167         if (hw_ctrl) {
168                 /* clear the system reset pin to cause a reset */
169                 clrbits32(hw_ctrl + HW_CTRL_RESETS, HW_CTRL_RESETS_SYS);
170         }
171         wii_spin();
172 }
173 
174 static void wii_power_off(void)
175 {
176         local_irq_disable();
177 
178         if (hw_gpio) {
179                 /* make sure that the poweroff GPIO is configured as output */
180                 setbits32(hw_gpio + HW_GPIO_DIR(1), HW_GPIO_SHUTDOWN);
181 
182                 /* drive the poweroff GPIO high */
183                 setbits32(hw_gpio + HW_GPIO_OUT(1), HW_GPIO_SHUTDOWN);
184         }
185         wii_spin();
186 }
187 
188 static void __noreturn wii_halt(void)
189 {
190         if (ppc_md.restart)
191                 ppc_md.restart(NULL);
192         wii_spin();
193 }
194 
195 static void __init wii_pic_probe(void)
196 {
197         flipper_pic_probe();
198         hlwd_pic_probe();
199 }
200 
201 static int __init wii_probe(void)
202 {
203         if (!of_machine_is_compatible("nintendo,wii"))
204                 return 0;
205 
206         pm_power_off = wii_power_off;
207 
208         ug_udbg_init();
209 
210         return 1;
211 }
212 
213 static void wii_shutdown(void)
214 {
215         hlwd_quiesce();
216         flipper_quiesce();
217 }
218 
219 define_machine(wii) {
220         .name                   = "wii",
221         .probe                  = wii_probe,
222         .setup_arch             = wii_setup_arch,
223         .restart                = wii_restart,
224         .halt                   = wii_halt,
225         .init_IRQ               = wii_pic_probe,
226         .get_irq                = flipper_pic_get_irq,
227         .calibrate_decr         = generic_calibrate_decr,
228         .progress               = udbg_progress,
229         .machine_shutdown       = wii_shutdown,
230 };
231 
232 static const struct of_device_id wii_of_bus[] = {
233         { .compatible = "nintendo,hollywood", },
234         { },
235 };
236 
237 static int __init wii_device_probe(void)
238 {
239         if (!machine_is(wii))
240                 return 0;
241 
242         of_platform_bus_probe(NULL, wii_of_bus, NULL);
243         return 0;
244 }
245 device_initcall(wii_device_probe);
246 
247 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp