0001
0002
0003
0004
0005
0006
0007
0008
0009 #define DRV_MODULE_NAME "wii"
0010 #define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt
0011
0012 #include <linux/kernel.h>
0013 #include <linux/init.h>
0014 #include <linux/irq.h>
0015 #include <linux/seq_file.h>
0016 #include <linux/of_address.h>
0017 #include <linux/of_platform.h>
0018 #include <linux/memblock.h>
0019 #include <mm/mmu_decl.h>
0020
0021 #include <asm/io.h>
0022 #include <asm/machdep.h>
0023 #include <asm/time.h>
0024 #include <asm/udbg.h>
0025
0026 #include "flipper-pic.h"
0027 #include "hlwd-pic.h"
0028 #include "usbgecko_udbg.h"
0029
0030
0031 #define HW_CTRL_COMPATIBLE "nintendo,hollywood-control"
0032
0033 #define HW_CTRL_RESETS 0x94
0034 #define HW_CTRL_RESETS_SYS (1<<0)
0035
0036
0037 #define HW_GPIO_COMPATIBLE "nintendo,hollywood-gpio"
0038
0039 #define HW_GPIO_BASE(idx) (idx * 0x20)
0040 #define HW_GPIO_OUT(idx) (HW_GPIO_BASE(idx) + 0)
0041 #define HW_GPIO_DIR(idx) (HW_GPIO_BASE(idx) + 4)
0042 #define HW_GPIO_OWNER (HW_GPIO_BASE(1) + 0x1c)
0043
0044 #define HW_GPIO_SHUTDOWN (1<<1)
0045 #define HW_GPIO_SLOT_LED (1<<5)
0046 #define HW_GPIO_SENSOR_BAR (1<<8)
0047
0048
0049 static void __iomem *hw_ctrl;
0050 static void __iomem *hw_gpio;
0051
0052 static int __init page_aligned(unsigned long x)
0053 {
0054 return !(x & (PAGE_SIZE-1));
0055 }
0056
0057 void __init wii_memory_fixups(void)
0058 {
0059 struct memblock_region *p = memblock.memory.regions;
0060
0061 BUG_ON(memblock.memory.cnt != 2);
0062 BUG_ON(!page_aligned(p[0].base) || !page_aligned(p[1].base));
0063 }
0064
0065 static void __noreturn wii_spin(void)
0066 {
0067 local_irq_disable();
0068 for (;;)
0069 cpu_relax();
0070 }
0071
0072 static void __iomem *__init wii_ioremap_hw_regs(char *name, char *compatible)
0073 {
0074 void __iomem *hw_regs = NULL;
0075 struct device_node *np;
0076 struct resource res;
0077 int error = -ENODEV;
0078
0079 np = of_find_compatible_node(NULL, NULL, compatible);
0080 if (!np) {
0081 pr_err("no compatible node found for %s\n", compatible);
0082 goto out;
0083 }
0084 error = of_address_to_resource(np, 0, &res);
0085 if (error) {
0086 pr_err("no valid reg found for %pOFn\n", np);
0087 goto out_put;
0088 }
0089
0090 hw_regs = ioremap(res.start, resource_size(&res));
0091 if (hw_regs) {
0092 pr_info("%s at 0x%08x mapped to 0x%p\n", name,
0093 res.start, hw_regs);
0094 }
0095
0096 out_put:
0097 of_node_put(np);
0098 out:
0099 return hw_regs;
0100 }
0101
0102 static void __init wii_setup_arch(void)
0103 {
0104 hw_ctrl = wii_ioremap_hw_regs("hw_ctrl", HW_CTRL_COMPATIBLE);
0105 hw_gpio = wii_ioremap_hw_regs("hw_gpio", HW_GPIO_COMPATIBLE);
0106 if (hw_gpio) {
0107
0108 clrbits32(hw_gpio + HW_GPIO_OUT(0),
0109 HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);
0110 }
0111 }
0112
0113 static void __noreturn wii_restart(char *cmd)
0114 {
0115 local_irq_disable();
0116
0117 if (hw_ctrl) {
0118
0119 clrbits32(hw_ctrl + HW_CTRL_RESETS, HW_CTRL_RESETS_SYS);
0120 }
0121 wii_spin();
0122 }
0123
0124 static void wii_power_off(void)
0125 {
0126 local_irq_disable();
0127
0128 if (hw_gpio) {
0129
0130
0131
0132
0133 clrbits32(hw_gpio + HW_GPIO_OWNER, HW_GPIO_SHUTDOWN);
0134
0135
0136 setbits32(hw_gpio + HW_GPIO_DIR(1), HW_GPIO_SHUTDOWN);
0137
0138
0139 setbits32(hw_gpio + HW_GPIO_OUT(1), HW_GPIO_SHUTDOWN);
0140 }
0141 wii_spin();
0142 }
0143
0144 static void __noreturn wii_halt(void)
0145 {
0146 if (ppc_md.restart)
0147 ppc_md.restart(NULL);
0148 wii_spin();
0149 }
0150
0151 static void __init wii_pic_probe(void)
0152 {
0153 flipper_pic_probe();
0154 hlwd_pic_probe();
0155 }
0156
0157 static int __init wii_probe(void)
0158 {
0159 if (!of_machine_is_compatible("nintendo,wii"))
0160 return 0;
0161
0162 pm_power_off = wii_power_off;
0163
0164 ug_udbg_init();
0165
0166 return 1;
0167 }
0168
0169 static void wii_shutdown(void)
0170 {
0171 hlwd_quiesce();
0172 flipper_quiesce();
0173 }
0174
0175 static const struct of_device_id wii_of_bus[] = {
0176 { .compatible = "nintendo,hollywood", },
0177 { },
0178 };
0179
0180 static int __init wii_device_probe(void)
0181 {
0182 if (!machine_is(wii))
0183 return 0;
0184
0185 of_platform_populate(NULL, wii_of_bus, NULL, NULL);
0186 return 0;
0187 }
0188 device_initcall(wii_device_probe);
0189
0190 define_machine(wii) {
0191 .name = "wii",
0192 .probe = wii_probe,
0193 .setup_arch = wii_setup_arch,
0194 .restart = wii_restart,
0195 .halt = wii_halt,
0196 .init_IRQ = wii_pic_probe,
0197 .get_irq = flipper_pic_get_irq,
0198 .calibrate_decr = generic_calibrate_decr,
0199 .progress = udbg_progress,
0200 .machine_shutdown = wii_shutdown,
0201 };