Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7cca9b8b authored by Linus Walleij's avatar Linus Walleij Committed by Michal Simek
Browse files

microblaze: Switch to standard restart handler



The microblaze uses the legacy APIs to dig out a GPIO pin
defined in the root of the device tree to issue a hard
reset of the platform.

Asserting a hard reset should be done using the standard
DT-enabled and fully GPIO descriptor aware driver in
drivers/power/reset/gpio-restart.c using the bindings
from Documentation/devicetree/bindings/power/reset/gpio-restart.txt

To achieve this, first make sure microblaze makes use of
the standard kernel restart path utilizing do_kernel_restart()
from <linux/reboot.h>. Put in some grace time and an
emergency print if the restart does not properly assert.

As this is basic platform functionality we patch the DTS
file and defconfig in one go for a lockstep change.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Michal Simek <monstr@monstr.eu>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
[ Michal: Move machine_restart back to reset.c ]
Signed-off-by: default avatarMichal Simek <michal.simek@xilinx.com>
parent 1c62ed90
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@
	#address-cells = <1>;
	#size-cells = <1>;
	compatible = "xlnx,microblaze";
	hard-reset-gpios = <&LEDs_8Bit 2 1>;
	model = "testing";
	DDR2_SDRAM: memory@90000000 {
		device_type = "memory";
@@ -281,6 +280,21 @@
				gpios = <&LEDs_8Bit 7 1>;
			};
		} ;

		gpio-restart {
			compatible = "gpio-restart";
			/*
			 * FIXME: is this active low or active high?
			 * the current flag (1) indicates active low.
			 * delay measures are templates, should be adjusted
			 * to datasheet or trial-and-error with real hardware.
			 */
			gpios = <&LEDs_8Bit 2 1>;
			active-delay = <100>;
			inactive-delay = <10>;
			wait-delay = <100>;
		};

		RS232_Uart_1: serial@84000000 {
			clock-frequency = <125000000>;
			compatible = "xlnx,xps-uartlite-1.00.a";
+2 −0
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ CONFIG_SPI_XILINX=y
CONFIG_GPIOLIB=y
CONFIG_GPIO_SYSFS=y
CONFIG_GPIO_XILINX=y
CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_GPIO_RESTART=y
# CONFIG_HWMON is not set
CONFIG_WATCHDOG=y
CONFIG_XILINX_WATCHDOG=y
+2 −0
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ CONFIG_SPI_XILINX=y
CONFIG_GPIOLIB=y
CONFIG_GPIO_SYSFS=y
CONFIG_GPIO_XILINX=y
CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_GPIO_RESTART=y
# CONFIG_HWMON is not set
CONFIG_WATCHDOG=y
CONFIG_XILINX_WATCHDOG=y
+11 −76
Original line number Diff line number Diff line
@@ -8,83 +8,9 @@
 */

#include <linux/init.h>
#include <linux/delay.h>
#include <linux/of_platform.h>

/* Trigger specific functions */
#ifdef CONFIG_GPIOLIB

#include <linux/of_gpio.h>

static int handle; /* reset pin handle */
static unsigned int reset_val;

static int of_platform_reset_gpio_probe(void)
{
	int ret;
	handle = of_get_named_gpio(of_find_node_by_path("/"),
				   "hard-reset-gpios", 0);

	if (!gpio_is_valid(handle)) {
		pr_info("Skipping unavailable RESET gpio %d (%s)\n",
				handle, "reset");
		return -ENODEV;
	}

	ret = gpio_request(handle, "reset");
	if (ret < 0) {
		pr_info("GPIO pin is already allocated\n");
		return ret;
	}

	/* get current setup value */
	reset_val = gpio_get_value(handle);
	/* FIXME maybe worth to perform any action */
	pr_debug("Reset: Gpio output state: 0x%x\n", reset_val);

	/* Setup GPIO as output */
	ret = gpio_direction_output(handle, 0);
	if (ret < 0)
		goto err;

	/* Setup output direction */
	gpio_set_value(handle, 0);

	pr_info("RESET: Registered gpio device: %d, current val: %d\n",
							handle, reset_val);
	return 0;
err:
	gpio_free(handle);
	return ret;
}
device_initcall(of_platform_reset_gpio_probe);


static void gpio_system_reset(void)
{
	if (gpio_is_valid(handle))
		gpio_set_value(handle, 1 - reset_val);
	else
		pr_notice("Reset GPIO unavailable - halting!\n");
}
#else
static void gpio_system_reset(void)
{
	pr_notice("No reset GPIO present - halting!\n");
}

void of_platform_reset_gpio_probe(void)
{
	return;
}
#endif

void machine_restart(char *cmd)
{
	pr_notice("Machine restart...\n");
	gpio_system_reset();
	while (1)
		;
}
#include <linux/reboot.h>

void machine_shutdown(void)
{
@@ -106,3 +32,12 @@ void machine_power_off(void)
	while (1)
		;
}

void machine_restart(char *cmd)
{
	do_kernel_restart(cmd);
	/* Give the restart hook 1 s to take us down */
	mdelay(1000);
	pr_emerg("Reboot failed -- System halted\n");
	while (1);
}