From 3ca543f3a38803a2d72ec0d73992879a272ae1a8 Mon Sep 17 00:00:00 2001 From: Goran Ferenc <goran.ferenc@imgtec.com> Date: Thu, 21 Jul 2016 16:10:18 +0200 Subject: [PATCH] MIPS: Attach ranchu machine reset and power-off routines If "reboot" or "reboot -p" are requested from the emulator, these routines will be triggered which in return should reset or power-off the machine. In order to enable this power management device, appropriate device tree node "goldfish_reset" is expected in the device tree to acquire device memory map location. This simple device contains only one register, which holds commands to be performed. GORESET: 0x42 command for reboot GOPOWEROFF: 0x43 command for shutdown Change-Id: I151b518a3982cb6c871dedf566846fa07c9304c6 Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com> --- arch/mips/goldfish/Makefile | 1 + arch/mips/goldfish/goldfish-reset.c | 67 +++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 arch/mips/goldfish/goldfish-reset.c diff --git a/arch/mips/goldfish/Makefile b/arch/mips/goldfish/Makefile index 98c6e1a36ee5..2d2a0d3e0d71 100644 --- a/arch/mips/goldfish/Makefile +++ b/arch/mips/goldfish/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_GOLDFISH) += goldfish-platform.o obj-$(CONFIG_GOLDFISH) += goldfish-interrupt.o obj-$(CONFIG_GOLDFISH) += goldfish-time.o obj-$(CONFIG_GOLDFISH) += pm.o +obj-$(CONFIG_GOLDFISH) += goldfish-reset.o obj-$(CONFIG_MIPS_GOLDFISH_SWITCH) += switch.o diff --git a/arch/mips/goldfish/goldfish-reset.c b/arch/mips/goldfish/goldfish-reset.c new file mode 100644 index 000000000000..1da473d9efba --- /dev/null +++ b/arch/mips/goldfish/goldfish-reset.c @@ -0,0 +1,67 @@ +/* arch/mips/goldfish/goldfish-reset.c + * + * Goldfish Machine Reset Routines + * + * Copyright (C) 2007 Google, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include <linux/init.h> +#include <linux/pm.h> +#include <linux/io.h> +#include <linux/of.h> + +#include <asm/idle.h> +#include <asm/reboot.h> +#include <asm/mips-boards/generic.h> + +#define GORESET 0x42 +#define GOSHUTDOWN 0x43 + +static struct device_node *dn; +static uint32_t base; +static unsigned int __iomem *softres_reg; + +static void mips_machine_restart(char *command) +{ + writel(GORESET, softres_reg); +} + +static void mips_machine_halt(void) +{ + writel(GOSHUTDOWN, softres_reg); +} + +static int __init mips_reboot_setup(void) +{ + if ((dn = of_find_node_by_name(NULL, "goldfish_reset")) == NULL) { + printk(KERN_WARNING "mips_reboot_setup() failed to " + "fetch device node \'goldfish_reset\'!\n"); + return -1; + } + + if (of_property_read_u32(dn, "reg", &base) < 0) { + printk(KERN_WARNING "mips_reboot_setup() failed to " + "fetch device base address property \'reg\'! %x\n", base); + return -1; + } + + softres_reg = ioremap(base, sizeof(unsigned int)); + + _machine_restart = mips_machine_restart; + _machine_halt = mips_machine_halt; + pm_power_off = mips_machine_halt; + + return 0; +} + +arch_initcall(mips_reboot_setup); -- GitLab