public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Gustavo Arantes <dev.gustavoa@gmail.com>
To: gregkh@linuxfoundation.org, marvin24@gmx.de
Cc: linux-staging@lists.linux.dev, ac100@lists.launchpad.net,
	linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org,
	dev.gustavoa@gmail.com
Subject: [PATCH 2/2] staging: nvec_power: stop EC queries during system suspend
Date: Thu, 12 Mar 2026 18:11:51 -0300	[thread overview]
Message-ID: <20260312211151.85379-3-dev.gustavoa@gmail.com> (raw)
In-Reply-To: <20260312211151.85379-1-dev.gustavoa@gmail.com>

The nvec_power driver continues to schedule its polling and battery
metadata work across system sleep, even though the parent nvec core
suspends the controller.

Track when each nvec_power instance is suspended, stop scheduling new
work once suspend begins, cancel the pending work items, and restart
them on resume. This keeps the driver's EC traffic quiesced while
the parent controller is asleep.

Signed-off-by: Gustavo Arantes <dev.gustavoa@gmail.com>
---
 drivers/staging/nvec/nvec_power.c | 52 +++++++++++++++++++++++++++++--
 1 file changed, 50 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/nvec/nvec_power.c b/drivers/staging/nvec/nvec_power.c
index 6b3235f41d07..54e5c5cdaf63 100644
--- a/drivers/staging/nvec/nvec_power.c
+++ b/drivers/staging/nvec/nvec_power.c
@@ -25,6 +25,7 @@ struct nvec_power {
 	struct delayed_work poller;
 	struct work_struct bat_init;
 	struct nvec_chip *nvec;
+	bool suspended;
 	int on;
 	int bat_present;
 	int bat_status;
@@ -158,7 +159,8 @@ static int nvec_power_bat_notifier(struct notifier_block *nb,
 		if (res->plc[0] & 1) {
 			if (power->bat_present == 0) {
 				status_changed = 1;
-				schedule_work(&power->bat_init);
+				if (!READ_ONCE(power->suspended))
+					schedule_work(&power->bat_init);
 			}
 
 			power->bat_present = 1;
@@ -398,7 +400,9 @@ static void nvec_power_poll(struct work_struct *work)
 		dev_warn(power->nvec->dev,
 			 "failed to query battery status: %d\n", ret);
 
-	schedule_delayed_work(to_delayed_work(work), msecs_to_jiffies(5000));
+	if (!READ_ONCE(power->suspended))
+		schedule_delayed_work(to_delayed_work(work),
+				      msecs_to_jiffies(5000));
 };
 
 static int nvec_power_probe(struct platform_device *pdev)
@@ -471,11 +475,55 @@ static void nvec_power_remove(struct platform_device *pdev)
 	}
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int nvec_power_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct nvec_power *power = dev_get_drvdata(dev);
+
+	WRITE_ONCE(power->suspended, true);
+
+	switch (pdev->id) {
+	case AC:
+		cancel_delayed_work_sync(&power->poller);
+		break;
+	case BAT:
+		cancel_work_sync(&power->bat_init);
+		break;
+	}
+
+	return 0;
+}
+
+static int nvec_power_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct nvec_power *power = dev_get_drvdata(dev);
+
+	WRITE_ONCE(power->suspended, false);
+
+	switch (pdev->id) {
+	case AC:
+		schedule_delayed_work(&power->poller, msecs_to_jiffies(5000));
+		break;
+	case BAT:
+		schedule_work(&power->bat_init);
+		break;
+	}
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(nvec_power_pm_ops, nvec_power_suspend,
+			 nvec_power_resume);
+
 static struct platform_driver nvec_power_driver = {
 	.probe = nvec_power_probe,
 	.remove = nvec_power_remove,
 	.driver = {
 		.name = "nvec-power",
+		.pm = &nvec_power_pm_ops,
 	}
 };
 
-- 
2.53.0


  parent reply	other threads:[~2026-03-12 21:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 21:11 [PATCH 0/2] staging: nvec_power: quiesce EC queries for system suspend Gustavo Arantes
2026-03-12 21:11 ` [PATCH 1/2] staging: nvec_power: make EC queries synchronous Gustavo Arantes
2026-03-12 21:11 ` Gustavo Arantes [this message]
2026-03-15 20:48 ` [PATCH 0/2] staging: nvec_power: quiesce EC queries for system suspend Marc Dietrich
2026-03-15 21:48   ` Gustavo Arantes

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=20260312211151.85379-3-dev.gustavoa@gmail.com \
    --to=dev.gustavoa@gmail.com \
    --cc=ac100@lists.launchpad.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=linux-tegra@vger.kernel.org \
    --cc=marvin24@gmx.de \
    /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