OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] lib: utils: identify supported GPIO reset methods
@ 2021-09-28 11:42 Heinrich Schuchardt
  2021-09-29  4:16 ` Anup Patel
  0 siblings, 1 reply; 9+ messages in thread
From: Heinrich Schuchardt @ 2021-09-28 11:42 UTC (permalink / raw)
  To: opensbi

The GPIO reset driver supports reset and poweroff. But not all boards
support both. gpio_system_reset_check() must detect this situation.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 lib/utils/reset/fdt_reset_gpio.c | 44 +++++++++++++++-----------------
 1 file changed, 21 insertions(+), 23 deletions(-)

diff --git a/lib/utils/reset/fdt_reset_gpio.c b/lib/utils/reset/fdt_reset_gpio.c
index 30127f5..77e4d0e 100644
--- a/lib/utils/reset/fdt_reset_gpio.c
+++ b/lib/utils/reset/fdt_reset_gpio.c
@@ -35,21 +35,9 @@ static struct gpio_reset restart = {
 	.inactive_delay = 100
 };
 
-static int gpio_system_reset_check(u32 type, u32 reason)
-{
-	switch (type) {
-	case SBI_SRST_RESET_TYPE_SHUTDOWN:
-	case SBI_SRST_RESET_TYPE_COLD_REBOOT:
-	case SBI_SRST_RESET_TYPE_WARM_REBOOT:
-		return 1;
-	}
-
-	return 0;
-}
-
-static void gpio_system_reset(u32 type, u32 reason)
+static struct gpio_reset *gpio_get_reset_settings(u32 type)
 {
-	struct gpio_reset *reset = NULL;
+	struct gpio_reset *reset;
 
 	switch (type) {
 	case SBI_SRST_RESET_TYPE_SHUTDOWN:
@@ -59,14 +47,26 @@ static void gpio_system_reset(u32 type, u32 reason)
 	case SBI_SRST_RESET_TYPE_WARM_REBOOT:
 		reset = &restart;
 		break;
+	default:
+		reset = NULL;
 	}
 
-	if (reset) {
-		if (!reset->pin.chip) {
-			sbi_printf("%s: gpio pin not available\n", __func__);
-			goto skip_reset;
-		}
+	if (reset && !reset->pin.chip)
+		reset = NULL;
+
+	return reset;
+}
+
+static int gpio_system_reset_check(u32 type, u32 reason)
+{
+	return !!gpio_get_reset_settings(type);
+}
+
+static void gpio_system_reset(u32 type, u32 reason)
+{
+	struct gpio_reset *reset = gpio_get_reset_settings(type);
 
+	if (reset) {
 		/* drive it active, also inactive->active edge */
 		gpio_direction_output(&reset->pin, 1);
 		sbi_timer_mdelay(reset->active_delay);
@@ -77,11 +77,9 @@ static void gpio_system_reset(u32 type, u32 reason)
 
 		/* drive it active, also inactive->active edge */
 		gpio_set(&reset->pin, 1);
-
-skip_reset:
-		/* hang !!! */
-		sbi_hart_hang();
 	}
+	/* hang !!! */
+	sbi_hart_hang();
 }
 
 static struct sbi_system_reset_device gpio_reset = {
-- 
2.32.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-10-01  4:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-28 11:42 [PATCH 1/1] lib: utils: identify supported GPIO reset methods Heinrich Schuchardt
2021-09-29  4:16 ` Anup Patel
2021-09-29  7:01   ` Heinrich Schuchardt
2021-09-29 12:38     ` Anup Patel
2021-09-30 10:29       ` Heinrich Schuchardt
2021-09-30 13:13         ` Anup Patel
2021-09-29  9:14   ` Nikita Shubin
2021-09-29 12:03     ` Heinrich Schuchardt
2021-10-01  4:58   ` Anup Patel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox