From nobody Fri Dec 19 12:46:20 2025 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A57D18C332 for ; Sat, 6 Dec 2025 16:30:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765038659; cv=none; b=AnEQad7rd7+Mh8OppRy7w7Wl3Ng+QZTfmfO0b/3CLidjaqnBPaSuQpvbK5IcRYSqCMs6VQCAlszp4pteGQkQH7hRGxhpjtotTI2qAO1ZS71eBfftR/IkSs37MIgjn9Zyw/m/qXHPm0EejMkpildZZeqVBby+Ey3AqrSrAGBYTgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765038659; c=relaxed/simple; bh=Pjqq3IhQZEU0T+kr+l+SJxkmnGc2LedDezow2IDI6B4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=b9PL8y0u0eBkAWOHvvaiC0wsUOMU+Vp3ZC5n399o0jG7WH0tNas2ozb3aNQJ7wEPX6QaYNJ8zPs/6ZdyXEMrnJSzvq/rriOippU0N+/HYjFBXoHxpJiaACzjwdF2oYXKRwgAN1x1siKR5NByfzwP9ne8jIzzFiLY+LqbDLF8l5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZrwUrSTs; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZrwUrSTs" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-297dd95ffe4so28847585ad.3 for ; Sat, 06 Dec 2025 08:30:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765038657; x=1765643457; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TDSd8Vdq8giSc188TspRF54MXu3sfJ1VJvqYKX7oxLI=; b=ZrwUrSTs8wsy6Ou6QubTXVrSqRDcqZJ45vmJ5ClP1cyqaaeOEyyrlGQfryqOWhVLiT moMrUBRx/Ds2PjNhbafuQc+mEweOIr7ps5ZSrvWSoop73K9FlefZUh8jqiuvbhAESj6g ijzZqTi0v9kR8lmOaInXnDO/w0l+mlL2Np4OtgIslwE8Xkl1v/xJRRFmrau+80xy+R/n 1NpzMojOwv1rT9SHfNjRHh27U+Igl76qj4v6JnsVHisST17EdhxVIroVo+ElDKcJX/xK tXncZTxKqZIWl9HBIbOfhNMY69KOF8RnB+VP+rkxNN0MG8p8QELT81vMLVHGvgY6hB4D ZtkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765038657; x=1765643457; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TDSd8Vdq8giSc188TspRF54MXu3sfJ1VJvqYKX7oxLI=; b=NvNLp9GSPpIij6uTlN51wAdUKAJ3Nu5W9WSiVpRzYlF0rfi1wy5m7N0qdQcnXPq4pQ WKq3jZOBtpGPkUBfsyj6Ao3y70kemjiDoGlixm20mmtnw2cIKoCgjAfj2wd4/mBtuD4l 01SScOLBGkLoAX075DhY9xmkTCDqLeEKT3vuXGbUnMFI9UCud2RmHMDiuDldywd0JLXY Xajl2TeSP5JVR6PTuUpM9dbkvGmvNwC0nnOE0/Ep8UxkRQJHONCxm087ANYq4V1U1XTu GOhImGGcN70LxAr0t2gK/3RIVOxidXP43M5FsmV4KnXvVZJ1WQs+DTYpWJ/PHTjHbfRc PbZw== X-Forwarded-Encrypted: i=1; AJvYcCWI7FOUAvd8QLfcAfiBtf6jdA6ZcvOwBntPMWFCS/40KqejMpK5v99UvdN6Pn8XwiTkXwSl6aI++MKbOPw=@vger.kernel.org X-Gm-Message-State: AOJu0Ywdh6VyDlh3pPbwsz4o1Tr1/p/XRMGG+QssajxXy0FnNEAyiKxV 6pGIy1O9aRBguuB+GJXX+0gOhfMCqiyxNmUW7jMN5ySJyWRC2ffczYhY X-Gm-Gg: ASbGncvl7cgtiAJvzhh89JAFF4gqgV/uKi5jt5KQUwHhKVBT8kcqClR0vM1b9FkX8ZQ nutqQBsR8zuW/exs1hTS3rFg/QhTGzmG57Bt+3cYH39e35SLtTBrtSGDGttZXZV4DbC+E+Xeh0m Ooj9VgJuxIPUZlL3YKRqOEEqGeZysm2wdOavU+3E5EriEqeTxiuNIJI5cHgzcubT6AkkNtURXul IytMexUevegS+wCqSG53grrr1OSKvJFqHIZ4J9wHgEmd/93cx2PkWly6eJnho1EU2aPsTzCJw+d dWlNuO9VdZkEnlvhQz/x0LpXCci1uJVsW+nxinSmsODBDXacVk0LEmhYBaO5TW8BUzxBKmEk8FY 76YmhS/MO9njIi5u7xK2l4+YnuPrQL2DFTNC8pWJ7p9O2EXCc+Y9qs5jQzm3usR+Xn6dlAe7HWO WPQW0E6oRDFoEW6mowJDFFq6bFoI/YxIGjhw== X-Google-Smtp-Source: AGHT+IGjvoE4fTOveWBDEffY1step8XtJFOeFdFKl3HR5Zhlm5TuQ08EkqpDdpzaQhfZMWQaABB/pw== X-Received: by 2002:a17:902:d2c8:b0:298:42ba:c422 with SMTP id d9443c01a7336-29df5e1dfe6mr24842845ad.31.1765038656777; Sat, 06 Dec 2025 08:30:56 -0800 (PST) Received: from DESKTOP-IM4PCEA.localdomain ([49.207.52.239]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-29daeaabbb1sm78468455ad.82.2025.12.06.08.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Dec 2025 08:30:55 -0800 (PST) From: Mintu Patel To: Cc: Mintu Patel , Saurabh Kumar , Shahid Kagadgar , Dilshad Alam , Linus Walleij , Bartosz Golaszewski , "Rafael J. Wysocki" , Len Brown , Pavel Machek , 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 Message-Id: <20251206163101.828-1-mintupatel89@gmail.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Saurabh Kumar Co-developed-by: Shahid Kagadgar Signed-off-by: Shahid Kagadgar Co-developed-by: Dilshad Alam Signed-off-by: Dilshad Alam Signed-off-by: Mintu Patel --- 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 */ =20 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); =20 +#ifdef CONFIG_DEBUG_FS +static void fetching_gpios_state_suspend(struct gpio_chip *chip) { + + int gpio_num, value =3D 0; + + pr_info("GPIO Chip : %s\n",chip->label); + pr_info("GPIO Suspend state\n"); + for (gpio_num =3D 0; gpio_num ngpio; gpio_num++ ) { + value =3D chip->get(chip, gpio_num); + if(value !=3D 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 !=3D 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 @@ =20 #include "power.h" =20 +#ifdef CONFIG_DEBUG_FS +extern void gpio_state_fetch_at_suspend(void); +#endif + const char * const pm_labels[] =3D { [PM_SUSPEND_TO_IDLE] =3D "freeze", [PM_SUSPEND_STANDBY] =3D "standby", @@ -429,6 +433,10 @@ static int suspend_enter(suspend_state_t state, bool *= wakeup) if (suspend_test(TEST_PLATFORM)) goto Platform_wake; =20 +#ifdef CONFIG_DEBUG_FS + gpio_state_fetch_at_suspend(); +#endif + if (state =3D=3D PM_SUSPEND_TO_IDLE) { s2idle_loop(); goto Platform_wake; --=20 2.25.1