Path: blob/master/arch/powerpc/platforms/embedded6xx/wii.c
10818 views
/*1* arch/powerpc/platforms/embedded6xx/wii.c2*3* Nintendo Wii board-specific support4* Copyright (C) 2008-2009 The GameCube Linux Team5* Copyright (C) 2008,2009 Albert Herranz6*7* This program is free software; you can redistribute it and/or8* modify it under the terms of the GNU General Public License9* as published by the Free Software Foundation; either version 210* of the License, or (at your option) any later version.11*12*/13#define DRV_MODULE_NAME "wii"14#define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt1516#include <linux/kernel.h>17#include <linux/init.h>18#include <linux/irq.h>19#include <linux/seq_file.h>20#include <linux/of_platform.h>21#include <linux/memblock.h>22#include <mm/mmu_decl.h>2324#include <asm/io.h>25#include <asm/machdep.h>26#include <asm/prom.h>27#include <asm/time.h>28#include <asm/udbg.h>2930#include "flipper-pic.h"31#include "hlwd-pic.h"32#include "usbgecko_udbg.h"3334/* control block */35#define HW_CTRL_COMPATIBLE "nintendo,hollywood-control"3637#define HW_CTRL_RESETS 0x9438#define HW_CTRL_RESETS_SYS (1<<0)3940/* gpio */41#define HW_GPIO_COMPATIBLE "nintendo,hollywood-gpio"4243#define HW_GPIO_BASE(idx) (idx * 0x20)44#define HW_GPIO_OUT(idx) (HW_GPIO_BASE(idx) + 0)45#define HW_GPIO_DIR(idx) (HW_GPIO_BASE(idx) + 4)4647#define HW_GPIO_SHUTDOWN (1<<1)48#define HW_GPIO_SLOT_LED (1<<5)49#define HW_GPIO_SENSOR_BAR (1<<8)505152static void __iomem *hw_ctrl;53static void __iomem *hw_gpio;5455unsigned long wii_hole_start;56unsigned long wii_hole_size;575859static int __init page_aligned(unsigned long x)60{61return !(x & (PAGE_SIZE-1));62}6364void __init wii_memory_fixups(void)65{66struct memblock_region *p = memblock.memory.regions;6768/*69* This is part of a workaround to allow the use of two70* discontinuous RAM ranges on the Wii, even if this is71* currently unsupported on 32-bit PowerPC Linux.72*73* We coalesce the two memory ranges of the Wii into a74* single range, then create a reservation for the "hole"75* between both ranges.76*/7778BUG_ON(memblock.memory.cnt != 2);79BUG_ON(!page_aligned(p[0].base) || !page_aligned(p[1].base));8081p[0].size = _ALIGN_DOWN(p[0].size, PAGE_SIZE);82p[1].size = _ALIGN_DOWN(p[1].size, PAGE_SIZE);8384wii_hole_start = p[0].base + p[0].size;85wii_hole_size = p[1].base - wii_hole_start;8687pr_info("MEM1: <%08llx %08llx>\n", p[0].base, p[0].size);88pr_info("HOLE: <%08lx %08lx>\n", wii_hole_start, wii_hole_size);89pr_info("MEM2: <%08llx %08llx>\n", p[1].base, p[1].size);9091p[0].size += wii_hole_size + p[1].size;9293memblock.memory.cnt = 1;94memblock_analyze();9596/* reserve the hole */97memblock_reserve(wii_hole_start, wii_hole_size);9899/* allow ioremapping the address space in the hole */100__allow_ioremap_reserved = 1;101}102103unsigned long __init wii_mmu_mapin_mem2(unsigned long top)104{105unsigned long delta, size, bl;106unsigned long max_size = (256<<20);107108/* MEM2 64MB@0x10000000 */109delta = wii_hole_start + wii_hole_size;110size = top - delta;111for (bl = 128<<10; bl < max_size; bl <<= 1) {112if (bl * 2 > size)113break;114}115setbat(4, PAGE_OFFSET+delta, delta, bl, PAGE_KERNEL_X);116return delta + bl;117}118119static void wii_spin(void)120{121local_irq_disable();122for (;;)123cpu_relax();124}125126static void __iomem *wii_ioremap_hw_regs(char *name, char *compatible)127{128void __iomem *hw_regs = NULL;129struct device_node *np;130struct resource res;131int error = -ENODEV;132133np = of_find_compatible_node(NULL, NULL, compatible);134if (!np) {135pr_err("no compatible node found for %s\n", compatible);136goto out;137}138error = of_address_to_resource(np, 0, &res);139if (error) {140pr_err("no valid reg found for %s\n", np->name);141goto out_put;142}143144hw_regs = ioremap(res.start, resource_size(&res));145if (hw_regs) {146pr_info("%s at 0x%08x mapped to 0x%p\n", name,147res.start, hw_regs);148}149150out_put:151of_node_put(np);152out:153return hw_regs;154}155156static void __init wii_setup_arch(void)157{158hw_ctrl = wii_ioremap_hw_regs("hw_ctrl", HW_CTRL_COMPATIBLE);159hw_gpio = wii_ioremap_hw_regs("hw_gpio", HW_GPIO_COMPATIBLE);160if (hw_gpio) {161/* turn off the front blue led and IR light */162clrbits32(hw_gpio + HW_GPIO_OUT(0),163HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);164}165}166167static void wii_restart(char *cmd)168{169local_irq_disable();170171if (hw_ctrl) {172/* clear the system reset pin to cause a reset */173clrbits32(hw_ctrl + HW_CTRL_RESETS, HW_CTRL_RESETS_SYS);174}175wii_spin();176}177178static void wii_power_off(void)179{180local_irq_disable();181182if (hw_gpio) {183/* make sure that the poweroff GPIO is configured as output */184setbits32(hw_gpio + HW_GPIO_DIR(1), HW_GPIO_SHUTDOWN);185186/* drive the poweroff GPIO high */187setbits32(hw_gpio + HW_GPIO_OUT(1), HW_GPIO_SHUTDOWN);188}189wii_spin();190}191192static void wii_halt(void)193{194if (ppc_md.restart)195ppc_md.restart(NULL);196wii_spin();197}198199static void __init wii_init_early(void)200{201ug_udbg_init();202}203204static void __init wii_pic_probe(void)205{206flipper_pic_probe();207hlwd_pic_probe();208}209210static int __init wii_probe(void)211{212unsigned long dt_root;213214dt_root = of_get_flat_dt_root();215if (!of_flat_dt_is_compatible(dt_root, "nintendo,wii"))216return 0;217218return 1;219}220221static void wii_shutdown(void)222{223hlwd_quiesce();224flipper_quiesce();225}226227define_machine(wii) {228.name = "wii",229.probe = wii_probe,230.init_early = wii_init_early,231.setup_arch = wii_setup_arch,232.restart = wii_restart,233.power_off = wii_power_off,234.halt = wii_halt,235.init_IRQ = wii_pic_probe,236.get_irq = flipper_pic_get_irq,237.calibrate_decr = generic_calibrate_decr,238.progress = udbg_progress,239.machine_shutdown = wii_shutdown,240};241242static struct of_device_id wii_of_bus[] = {243{ .compatible = "nintendo,hollywood", },244{ },245};246247static int __init wii_device_probe(void)248{249if (!machine_is(wii))250return 0;251252of_platform_bus_probe(NULL, wii_of_bus, NULL);253return 0;254}255device_initcall(wii_device_probe);256257258259