linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mintu Patel <mintupatel89@gmail.com>
Cc: Mintu Patel <mintupatel89@gmail.com>,
	Saurabh Kumar <saurabhsingh14june@gmail.com>,
	Shahid Kagadgar <shahidkagadgar3821@gmail.com>,
	Dilshad Alam <Dil.alam@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-pm@vger.kernel.org
Subject: [PATCH] Dumping GPIOs state during suspend state
Date: Sat,  6 Dec 2025 22:00:51 +0530	[thread overview]
Message-ID: <20251206163101.828-1-mintupatel89@gmail.com> (raw)

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


             reply	other threads:[~2025-12-06 16:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-06 16:30 Mintu Patel [this message]
2025-12-07 20:28 ` [PATCH] Dumping GPIOs state during suspend state Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251206163101.828-1-mintupatel89@gmail.com \
    --to=mintupatel89@gmail.com \
    --cc=Dil.alam@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=len.brown@intel.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    --cc=saurabhsingh14june@gmail.com \
    --cc=shahidkagadgar3821@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).