public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Dumping GPIOs state during suspend state
@ 2025-12-06 16:30 Mintu Patel
  2025-12-07 20:28 ` Linus Walleij
  0 siblings, 1 reply; 2+ messages in thread
From: Mintu Patel @ 2025-12-06 16:30 UTC (permalink / raw)
  Cc: Mintu Patel, Saurabh Kumar, Shahid Kagadgar, Dilshad Alam,
	Linus Walleij, Bartosz Golaszewski, Rafael J. Wysocki, Len Brown,
	Pavel Machek, linux-gpio, linux-kernel, linux-pm

It is difficult to find out which GPIOs are going high during suspend
without manual probing with multimeters or oscilloscopes.
In order to save the power especifically for battery operated devices,
It becomes must to pull GPIOs low during suspend.

As of now there is no way to trace which GPIOs are high during suspend
without manual probing with multimeters or oscilloscopes.
This patch would help the developer to find the GPIOs are high during
suspend state without struggling with hardware devices.

The patch would print the below logs:

[  244.029392] GPIO Chip : 3000000.pinctrl
[  244.029394] GPIO   Suspend state
[  244.029404] 3      1
[  244.029418] 17      1
[  244.029424] 21      1
[  244.029431] 30      1
[  244.029436] 32      1
[  244.029440] 33      1
[  244.029444] 34      1
[  244.029447] 35      1
[  244.029453] 41      1
[  244.029462] 51      1
[  244.029470] 57      1
[  244.029492] 90      1
[  244.029496] 91      1
[  244.029515] 114      1
[  244.029519] 115      1
[  244.029523] 117      1

Based on the above logs, GPIOs 3, 17, etc are high during suspend state.
Thus particular driver/submodule can be modified for configuring
the GPIOs accordingly for suspend and resume states.

Co-developed-by: Saurabh Kumar <saurabhsingh14june@gmail.com>
Signed-off-by: Saurabh Kumar <saurabhsingh14june@gmail.com>
Co-developed-by: Shahid Kagadgar <shahidkagadgar3821@gmail.com>
Signed-off-by: Shahid Kagadgar <shahidkagadgar3821@gmail.com>
Co-developed-by: Dilshad Alam <Dil.alam@gmail.com>
Signed-off-by: Dilshad Alam <Dil.alam@gmail.com>
Signed-off-by: Mintu Patel <mintupatel89@gmail.com>
---
 drivers/gpio/gpiolib.c | 36 ++++++++++++++++++++++++++++++++++++
 kernel/power/suspend.c |  8 ++++++++
 2 files changed, 44 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 94903fc1c145..65a8d2150d90 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -51,6 +51,10 @@
 /* Device and char device-related information */
 static DEFINE_IDA(gpio_ida);
 static dev_t gpio_devt;
+#ifdef CONFIG_DEBUG_FS
+void gpio_state_fetch_at_suspend(void);
+DEFINE_SPINLOCK(gpio_lock);
+#endif
 #define GPIO_DEV_MAX 256 /* 256 GPIO chip devices supported */
 
 static int gpio_bus_match(struct device *dev, struct device_driver *drv)
@@ -4702,6 +4706,38 @@ void gpiod_put_array(struct gpio_descs *descs)
 }
 EXPORT_SYMBOL_GPL(gpiod_put_array);
 
+#ifdef CONFIG_DEBUG_FS
+static void fetching_gpios_state_suspend(struct gpio_chip *chip) {
+
+	int gpio_num, value = 0;
+
+	pr_info("GPIO Chip : %s\n",chip->label);
+	pr_info("GPIO   Suspend state\n");
+	for (gpio_num = 0; gpio_num <chip->ngpio; gpio_num++ ) {
+		value = chip->get(chip, gpio_num);
+			if(value != 0) {
+			pr_info("%d      %d\n",gpio_num, value);
+			}
+	}
+	}
+
+void gpio_state_fetch_at_suspend() {
+
+	struct gpio_device *gdev;
+	unsigned long flags;
+
+	spin_lock_irqsave(&gpio_lock, flags);
+	list_for_each_entry(gdev, &gpio_devices, list)
+		if (gdev->chip != NULL) {
+			fetching_gpios_state_suspend( gdev->chip);
+		}
+
+	spin_unlock_irqrestore(&gpio_lock, flags);
+}
+
+EXPORT_SYMBOL_GPL(gpio_state_fetch_at_suspend);
+#endif
+
 static int gpio_stub_drv_probe(struct device *dev)
 {
 	/*
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 09f8397bae15..e8d28206b053 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -33,6 +33,10 @@
 
 #include "power.h"
 
+#ifdef CONFIG_DEBUG_FS
+extern void gpio_state_fetch_at_suspend(void);
+#endif
+
 const char * const pm_labels[] = {
 	[PM_SUSPEND_TO_IDLE] = "freeze",
 	[PM_SUSPEND_STANDBY] = "standby",
@@ -429,6 +433,10 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
 	if (suspend_test(TEST_PLATFORM))
 		goto Platform_wake;
 
+#ifdef CONFIG_DEBUG_FS
+	gpio_state_fetch_at_suspend();
+#endif
+
 	if (state == PM_SUSPEND_TO_IDLE) {
 		s2idle_loop();
 		goto Platform_wake;
-- 
2.25.1


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

end of thread, other threads:[~2025-12-07 20:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-06 16:30 [PATCH] Dumping GPIOs state during suspend state Mintu Patel
2025-12-07 20:28 ` Linus Walleij

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