Albert Herranz | 5a7ee31 | 2009-12-12 06:31:48 +0000 | [diff] [blame] | 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/kexec.h> |
| 22 | #include <linux/of_platform.h> |
Albert Herranz | de32400 | 2009-12-12 06:31:53 +0000 | [diff] [blame^] | 23 | #include <linux/lmb.h> |
| 24 | #include <mm/mmu_decl.h> |
Albert Herranz | 5a7ee31 | 2009-12-12 06:31:48 +0000 | [diff] [blame] | 25 | |
| 26 | #include <asm/io.h> |
| 27 | #include <asm/machdep.h> |
| 28 | #include <asm/prom.h> |
| 29 | #include <asm/time.h> |
| 30 | #include <asm/udbg.h> |
| 31 | |
| 32 | #include "flipper-pic.h" |
| 33 | #include "hlwd-pic.h" |
| 34 | #include "usbgecko_udbg.h" |
| 35 | |
| 36 | /* control block */ |
| 37 | #define HW_CTRL_COMPATIBLE "nintendo,hollywood-control" |
| 38 | |
| 39 | #define HW_CTRL_RESETS 0x94 |
| 40 | #define HW_CTRL_RESETS_SYS (1<<0) |
| 41 | |
| 42 | /* gpio */ |
| 43 | #define HW_GPIO_COMPATIBLE "nintendo,hollywood-gpio" |
| 44 | |
| 45 | #define HW_GPIO_BASE(idx) (idx * 0x20) |
| 46 | #define HW_GPIO_OUT(idx) (HW_GPIO_BASE(idx) + 0) |
| 47 | #define HW_GPIO_DIR(idx) (HW_GPIO_BASE(idx) + 4) |
| 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 | |
Albert Herranz | de32400 | 2009-12-12 06:31:53 +0000 | [diff] [blame^] | 57 | unsigned long wii_hole_start; |
| 58 | unsigned long wii_hole_size; |
| 59 | |
| 60 | |
| 61 | static int __init page_aligned(unsigned long x) |
| 62 | { |
| 63 | return !(x & (PAGE_SIZE-1)); |
| 64 | } |
| 65 | |
| 66 | void __init wii_memory_fixups(void) |
| 67 | { |
| 68 | struct lmb_property *p = lmb.memory.region; |
| 69 | |
| 70 | /* |
| 71 | * This is part of a workaround to allow the use of two |
| 72 | * discontiguous RAM ranges on the Wii, even if this is |
| 73 | * currently unsupported on 32-bit PowerPC Linux. |
| 74 | * |
| 75 | * We coealesce the two memory ranges of the Wii into a |
| 76 | * single range, then create a reservation for the "hole" |
| 77 | * between both ranges. |
| 78 | */ |
| 79 | |
| 80 | BUG_ON(lmb.memory.cnt != 2); |
| 81 | BUG_ON(!page_aligned(p[0].base) || !page_aligned(p[1].base)); |
| 82 | |
| 83 | p[0].size = _ALIGN_DOWN(p[0].size, PAGE_SIZE); |
| 84 | p[1].size = _ALIGN_DOWN(p[1].size, PAGE_SIZE); |
| 85 | |
| 86 | wii_hole_start = p[0].base + p[0].size; |
| 87 | wii_hole_size = p[1].base - wii_hole_start; |
| 88 | |
| 89 | pr_info("MEM1: <%08llx %08llx>\n", p[0].base, p[0].size); |
| 90 | pr_info("HOLE: <%08lx %08lx>\n", wii_hole_start, wii_hole_size); |
| 91 | pr_info("MEM2: <%08llx %08llx>\n", p[1].base, p[1].size); |
| 92 | |
| 93 | p[0].size += wii_hole_size + p[1].size; |
| 94 | |
| 95 | lmb.memory.cnt = 1; |
| 96 | lmb_analyze(); |
| 97 | |
| 98 | /* reserve the hole */ |
| 99 | lmb_reserve(wii_hole_start, wii_hole_size); |
| 100 | } |
| 101 | |
| 102 | unsigned long __init wii_mmu_mapin_mem2(unsigned long top) |
| 103 | { |
| 104 | unsigned long delta, size, bl; |
| 105 | unsigned long max_size = (256<<20); |
| 106 | |
| 107 | /* MEM2 64MB@0x10000000 */ |
| 108 | delta = wii_hole_start + wii_hole_size; |
| 109 | size = top - delta; |
| 110 | for (bl = 128<<10; bl < max_size; bl <<= 1) { |
| 111 | if (bl * 2 > size) |
| 112 | break; |
| 113 | } |
| 114 | setbat(4, PAGE_OFFSET+delta, delta, bl, PAGE_KERNEL_X); |
| 115 | return delta + bl; |
| 116 | } |
| 117 | |
Albert Herranz | 5a7ee31 | 2009-12-12 06:31:48 +0000 | [diff] [blame] | 118 | static void wii_spin(void) |
| 119 | { |
| 120 | local_irq_disable(); |
| 121 | for (;;) |
| 122 | cpu_relax(); |
| 123 | } |
| 124 | |
| 125 | static void __iomem *wii_ioremap_hw_regs(char *name, char *compatible) |
| 126 | { |
| 127 | void __iomem *hw_regs = NULL; |
| 128 | struct device_node *np; |
| 129 | struct resource res; |
| 130 | int error = -ENODEV; |
| 131 | |
| 132 | np = of_find_compatible_node(NULL, NULL, compatible); |
| 133 | if (!np) { |
| 134 | pr_err("no compatible node found for %s\n", compatible); |
| 135 | goto out; |
| 136 | } |
| 137 | error = of_address_to_resource(np, 0, &res); |
| 138 | if (error) { |
| 139 | pr_err("no valid reg found for %s\n", np->name); |
| 140 | goto out_put; |
| 141 | } |
| 142 | |
| 143 | hw_regs = ioremap(res.start, resource_size(&res)); |
| 144 | if (hw_regs) { |
| 145 | pr_info("%s at 0x%08x mapped to 0x%p\n", name, |
| 146 | res.start, hw_regs); |
| 147 | } |
| 148 | |
| 149 | out_put: |
| 150 | of_node_put(np); |
| 151 | out: |
| 152 | return hw_regs; |
| 153 | } |
| 154 | |
| 155 | static void __init wii_setup_arch(void) |
| 156 | { |
| 157 | hw_ctrl = wii_ioremap_hw_regs("hw_ctrl", HW_CTRL_COMPATIBLE); |
| 158 | hw_gpio = wii_ioremap_hw_regs("hw_gpio", HW_GPIO_COMPATIBLE); |
| 159 | if (hw_gpio) { |
| 160 | /* turn off the front blue led and IR light */ |
| 161 | clrbits32(hw_gpio + HW_GPIO_OUT(0), |
| 162 | HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | static void wii_restart(char *cmd) |
| 167 | { |
| 168 | local_irq_disable(); |
| 169 | |
| 170 | if (hw_ctrl) { |
| 171 | /* clear the system reset pin to cause a reset */ |
| 172 | clrbits32(hw_ctrl + HW_CTRL_RESETS, HW_CTRL_RESETS_SYS); |
| 173 | } |
| 174 | wii_spin(); |
| 175 | } |
| 176 | |
| 177 | static void wii_power_off(void) |
| 178 | { |
| 179 | local_irq_disable(); |
| 180 | |
| 181 | if (hw_gpio) { |
| 182 | /* make sure that the poweroff GPIO is configured as output */ |
| 183 | setbits32(hw_gpio + HW_GPIO_DIR(1), HW_GPIO_SHUTDOWN); |
| 184 | |
| 185 | /* drive the poweroff GPIO high */ |
| 186 | setbits32(hw_gpio + HW_GPIO_OUT(1), HW_GPIO_SHUTDOWN); |
| 187 | } |
| 188 | wii_spin(); |
| 189 | } |
| 190 | |
| 191 | static void wii_halt(void) |
| 192 | { |
| 193 | if (ppc_md.restart) |
| 194 | ppc_md.restart(NULL); |
| 195 | wii_spin(); |
| 196 | } |
| 197 | |
| 198 | static void __init wii_init_early(void) |
| 199 | { |
| 200 | ug_udbg_init(); |
| 201 | } |
| 202 | |
| 203 | static void __init wii_pic_probe(void) |
| 204 | { |
| 205 | flipper_pic_probe(); |
| 206 | hlwd_pic_probe(); |
| 207 | } |
| 208 | |
| 209 | static int __init wii_probe(void) |
| 210 | { |
| 211 | unsigned long dt_root; |
| 212 | |
| 213 | dt_root = of_get_flat_dt_root(); |
| 214 | if (!of_flat_dt_is_compatible(dt_root, "nintendo,wii")) |
| 215 | return 0; |
| 216 | |
| 217 | return 1; |
| 218 | } |
| 219 | |
| 220 | static void wii_shutdown(void) |
| 221 | { |
| 222 | hlwd_quiesce(); |
| 223 | flipper_quiesce(); |
| 224 | } |
| 225 | |
| 226 | #ifdef CONFIG_KEXEC |
| 227 | static int wii_machine_kexec_prepare(struct kimage *image) |
| 228 | { |
| 229 | return 0; |
| 230 | } |
| 231 | #endif /* CONFIG_KEXEC */ |
| 232 | |
| 233 | define_machine(wii) { |
| 234 | .name = "wii", |
| 235 | .probe = wii_probe, |
| 236 | .init_early = wii_init_early, |
| 237 | .setup_arch = wii_setup_arch, |
| 238 | .restart = wii_restart, |
| 239 | .power_off = wii_power_off, |
| 240 | .halt = wii_halt, |
| 241 | .init_IRQ = wii_pic_probe, |
| 242 | .get_irq = flipper_pic_get_irq, |
| 243 | .calibrate_decr = generic_calibrate_decr, |
| 244 | .progress = udbg_progress, |
| 245 | .machine_shutdown = wii_shutdown, |
| 246 | #ifdef CONFIG_KEXEC |
| 247 | .machine_kexec_prepare = wii_machine_kexec_prepare, |
| 248 | #endif |
| 249 | }; |
| 250 | |
| 251 | static struct of_device_id wii_of_bus[] = { |
| 252 | { .compatible = "nintendo,hollywood", }, |
| 253 | { }, |
| 254 | }; |
| 255 | |
| 256 | static int __init wii_device_probe(void) |
| 257 | { |
| 258 | if (!machine_is(wii)) |
| 259 | return 0; |
| 260 | |
| 261 | of_platform_bus_probe(NULL, wii_of_bus, NULL); |
| 262 | return 0; |
| 263 | } |
| 264 | device_initcall(wii_device_probe); |
| 265 | |