Skip to contentSkip to conversation

WIP: import gpio-poweroff driver from linux kernel

RFC In review Antony Pavlov 2 participants 2 messages Nov 8, 2019 Reset controller framework

lore
Share & tools
lore
#0 lore raw

RFC 1/1 WIP: import gpio-poweroff driver from linux kernel

---
 drivers/reset/Kconfig         |  7 +++
 drivers/reset/Makefile        |  1 +
 drivers/reset/gpio-poweroff.c | 86 +++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+)
drivers/reset/Kconfig +7 -0
index 048f2081f8..21b61e036f 100644
@@ -26,4 +26,11 @@ config RESET_STM32
 	help
 	  This enables the reset controller driver for STM32MP and STM32 MCUs.
 
+config RESET_GPIO_POWEROFF
+	bool "GPIO power-off driver"
+	help
+	  This driver supports turning off your board via a GPIO line.
+	  If your board needs a GPIO high/low to power down, say Y and
+	  create a binding in your devicetree.
+
 endif
drivers/reset/Makefile +1 -0
index 8460c4b154..efd9c951f3 100644
@@ -2,3 +2,4 @@ obj-$(CONFIG_RESET_CONTROLLER) += core.o
 obj-$(CONFIG_ARCH_SOCFPGA) += reset-socfpga.o
 obj-$(CONFIG_RESET_IMX7) += reset-imx7.o
 obj-$(CONFIG_RESET_STM32) += reset-stm32.o
+obj-$(CONFIG_RESET_GPIO_POWEROFF) += gpio-poweroff.o
drivers/reset/gpio-poweroff.c new file +86 -0

86 lines not on this page · raw message

Signature · 7 lines
2.23.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

Hi Antony,

Quoted 83 lines · Antony Pavlov
---
 drivers/reset/Kconfig         |  7 +++
 drivers/reset/Makefile        |  1 +
 drivers/reset/gpio-poweroff.c | 86 +++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+)
drivers/reset/Kconfig +7 -0
index 048f2081f8..21b61e036f 100644
@@ -26,4 +26,11 @@ config RESET_STM32
 	help
 	  This enables the reset controller driver for STM32MP and STM32 MCUs.
 
+config RESET_GPIO_POWEROFF
+	bool "GPIO power-off driver"
+	help
+	  This driver supports turning off your board via a GPIO line.
+	  If your board needs a GPIO high/low to power down, say Y and
+	  create a binding in your devicetree.
+
 endif
drivers/reset/Makefile +1 -0
index 8460c4b154..efd9c951f3 100644
@@ -2,3 +2,4 @@ obj-$(CONFIG_RESET_CONTROLLER) += core.o
 obj-$(CONFIG_ARCH_SOCFPGA) += reset-socfpga.o
 obj-$(CONFIG_RESET_IMX7) += reset-imx7.o
 obj-$(CONFIG_RESET_STM32) += reset-stm32.o
+obj-$(CONFIG_RESET_GPIO_POWEROFF) += gpio-poweroff.o
drivers/reset/gpio-poweroff.c new file +45 -0
new file mode 100644
index 0000000000..89f9ff69c5
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Toggles a GPIO pin to power down a device
+ *
+ * Copyright (C) 2019 Antony Pavlov <[email protected]>
+ *
+ * Based on linux/drivers/power/reset/gpio-poweroff.c
+ *
+ * Jamie Lentin <[email protected]>
+ * Andrew Lunn <[email protected]>
+ *
+ * Copyright (C) 2012 Jamie Lentin
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <init.h>
+#include <gpio.h>
+#include <of_gpio.h>
+#include <poweroff.h>
+
+/*
+ * Hold configuration here.
+ * Cannot be more than one instance of the driver.
+ */
+static int reset_gpio;
+
+static void gpio_poweroff_do_poweroff(struct poweroff_handler *handler)
+{
+	shutdown_barebox();
+
+	/* drive it active, also inactive->active edge */
+	gpio_direction_output(reset_gpio, 1);
+	mdelay(100);
+	/* drive inactive, also active->inactive edge */
+	gpio_set_value(reset_gpio, 0);
+	mdelay(100);
+
+	/* drive it active, also inactive->active edge */
+	gpio_set_value(reset_gpio, 1);
+
+	/* give it some time */
+	mdelay(3000);
+
+	WARN_ON(1);

drivers/reset/gpio-poweroff.c line 55

Quoted 10 lines
drivers/reset/gpio-poweroff.c new file +10 -0
+	unreachable();
+}
+
+static int __init gpio_poweroff_probe(struct device_d *dev)
+{
+	int ret, reset_gpio;
+	enum of_gpio_flags flags;
+
+	if (!IS_ENABLED(CONFIG_OFDEVICE) || !IS_ENABLED(CONFIG_OF_GPIO))
+		return -ENODEV;

You could use depends on in Kconfig. No need to compile in a driver which doesn't work.

drivers/reset/gpio-poweroff.c line 57

Quoted 2 lines
drivers/reset/gpio-poweroff.c new file +2 -0
+
+	reset_gpio = of_get_named_gpio_flags(dev->device_node, "gpios", 0, &flags);

As flags are unused, use of_get_named_gpio()?

drivers/reset/gpio-poweroff.c line 67

Quoted 10 lines
drivers/reset/gpio-poweroff.c new file +10 -0
+	if (reset_gpio < 0) {
+		if (reset_gpio != -EPROBE_DEFER)
+			dev_err(dev, "failed to get gpio for %s: %d\n",
+				dev->device_node, reset_gpio);
+		return reset_gpio;
+	}
+
+	ret = gpio_request(reset_gpio, "gpio_poweroff");
+	if (ret) {
+		pr_err("gpio_poweroff: (%d) can not be requested\n", reset_gpio);

dev_err please.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox