From: Cristian Mazzotta <cmmazzo@icloud.com>
To: aer@tuxedocomputers.com
Cc: W_Armin@gmx.de, bentiss@kernel.org, jikos@kernel.org,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
wse@tuxedocomputers.com, Cristian Mazzotta <cmmazzo@icloud.com>
Subject: [PATCH 4/4] HID: lamparray: blank lamps across suspend and restore on resume
Date: Wed, 9 Sep 2026 11:52:57 -0500 [thread overview]
Message-ID: <20260909165257.352597-5-cmmazzo@icloud.com> (raw)
In-Reply-To: <20260909165257.352597-1-cmmazzo@icloud.com>
The helper installs no PM callbacks, so lamps keep their last state
across suspend. Firmware is not required to turn them off in low power
states, and on devices where it does not, they stay lit for the whole
suspend.
On an Acer Predator PT14-52T, system power draw during s2idle is 12.35W
with the lamps lit and 3.14W with them blanked, measured at the charger.
Add lamparray_suspend(), which writes zeroes to the color channels
while leaving the cached RGB and brightness untouched, and
lamparray_resume(), which restores that cache. Both return early when
use_leds_uapi is 0 so a userspace driver keeps full control. hid-generic
gains suspend and resume callbacks to drive them, and calls
lamparray_resume() from reset_resume as well.
Some devices return to firmware control across a hibernate transition
while still reporting AutonomousMode = 0, and ignore host lamp updates
until the value genuinely transitions. Force a 1 -> 0 on resume
before restoring state.
Signed-off-by: Cristian Mazzotta <cmmazzo@icloud.com>
---
drivers/hid/hid-generic.c | 27 +++++++++++++++++++
drivers/hid/hid-lamparray.c | 51 +++++++++++++++++++++++++++++++++++
include/linux/hid-lamparray.h | 35 ++++++++++++++++++++++++
3 files changed, 113 insertions(+)
diff --git a/drivers/hid/hid-generic.c b/drivers/hid/hid-generic.c
index c3d2283198e8..dc1cca45d599 100644
--- a/drivers/hid/hid-generic.c
+++ b/drivers/hid/hid-generic.c
@@ -99,9 +99,34 @@ static int hid_generic_probe(struct hid_device *hdev,
static int hid_generic_reset_resume(struct hid_device *hdev)
{
+ struct lamparray *la = hid_get_drvdata(hdev);
+
if (hdev->claimed & HID_CLAIMED_INPUT)
hidinput_reset_resume(hdev);
+ if (IS_ENABLED(CONFIG_HID_LAMPARRAY) && la)
+ lamparray_resume(la);
+
+ return 0;
+}
+
+static int hid_generic_suspend(struct hid_device *hdev, pm_message_t message)
+{
+ struct lamparray *la = hid_get_drvdata(hdev);
+
+ if (IS_ENABLED(CONFIG_HID_LAMPARRAY) && la)
+ lamparray_suspend(la);
+
+ return 0;
+}
+
+static int hid_generic_resume(struct hid_device *hdev)
+{
+ struct lamparray *la = hid_get_drvdata(hdev);
+
+ if (IS_ENABLED(CONFIG_HID_LAMPARRAY) && la)
+ lamparray_resume(la);
+
return 0;
}
@@ -127,6 +152,8 @@ static struct hid_driver hid_generic = {
.match = hid_generic_match,
.probe = hid_generic_probe,
.reset_resume = hid_generic_reset_resume,
+ .suspend = hid_generic_suspend,
+ .resume = hid_generic_resume,
.remove = hid_generic_remove,
};
module_hid_driver(hid_generic);
diff --git a/drivers/hid/hid-lamparray.c b/drivers/hid/hid-lamparray.c
index bbde006d119b..dec9d7883887 100644
--- a/drivers/hid/hid-lamparray.c
+++ b/drivers/hid/hid-lamparray.c
@@ -869,6 +869,57 @@ void lamparray_unregister(struct lamparray *la)
}
EXPORT_SYMBOL_GPL(lamparray_unregister);
+/*
+ * Blank all lamps on suspend rather than handing control back to the firmware,
+ * which may not turn them off in low power states. On an Acer Predator PT14-52T,
+ * system power draw during s2idle was ~12.35W with lamps lit, and ~2.84W with
+ * them blanked; the lighting accounted for ~77% of the power draw during suspend.
+ * Since writing zeroes is well defined on all lamparray devices, always do it.
+ * This is ignored if use_leds_uapi is 0; let userspace keep full control.
+ *
+ * Lamps are written to without holding the lock because PM will freeze userspace
+ * first, which makes concurrent writes impossible.
+ */
+int lamparray_suspend(struct lamparray *la)
+{
+ if (!la)
+ return 0;
+
+ struct lamparray_device *ldev = &la->ldev;
+
+ if (!ldev->use_leds_uapi)
+ return 0;
+
+ lamparray_hw_set_state(ldev, 0, 0, 0, ldev->last_brightness);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lamparray_suspend);
+
+int lamparray_resume(struct lamparray *la)
+{
+ if (!la)
+ return 0;
+
+ struct lamparray_device *ldev = &la->ldev;
+
+ if (!ldev->use_leds_uapi)
+ return 0;
+
+ /*
+ * After a S4 transition, some devices report
+ * AutonomousMode = 0 while still ignoring host lamp updates.
+ * Writing 0 again does nothing; forcing a 1 -> 0
+ * will guarantee the device will update.
+ */
+ lamparray_hw_set_autonomous(ldev, true);
+ lamparray_hw_set_autonomous(ldev, false);
+ lamparray_restore_state(ldev);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lamparray_resume);
+
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Tim Guttzeit <tgu@tuxedocomputers.com>");
MODULE_AUTHOR("Aaron Erhardt <aer@tuxedocomputers.com>");
diff --git a/include/linux/hid-lamparray.h b/include/linux/hid-lamparray.h
index a77869728d12..a9f827743baa 100644
--- a/include/linux/hid-lamparray.h
+++ b/include/linux/hid-lamparray.h
@@ -65,6 +65,31 @@ struct lamparray *lamparray_register(struct hid_device *hdev,
*/
void lamparray_unregister(struct lamparray *la);
+/**
+ * lamparray_suspend() - blank all lamps ahead of sleep transition
+ * @la: LampArray handle returned by lamparray_register()
+ *
+ * Writes zeroes to the rgb values only, keeping the brightness, unless the
+ * use_leds_uapi sysfs attribute is 0, in which case, it will return early
+ * before writing anything. The cached state is left untouched so
+ * lamparray_resume() can restore it.
+ *
+ * Return: 0
+ */
+int lamparray_suspend(struct lamparray *la);
+
+/**
+ * lamparray_resume() - restore host control and LampArray state
+ * @la: LampArray handle returned by lamparray_register()
+ *
+ * Disables autonomous mode (in case device returns to firmware control after suspend)
+ * and restores the cached state of the device. If the use_leds_uapi attribute is 0,
+ * it will return early and prevent any unwanted writing.
+ *
+ * Return: 0
+ */
+int lamparray_resume(struct lamparray *la);
+
#else /* !CONFIG_HID_LAMPARRAY */
static inline bool lamparray_is_supported_device(struct hid_device *hdev)
@@ -83,6 +108,16 @@ static inline void lamparray_unregister(struct lamparray *la)
{
}
+static inline int lamparray_suspend(struct lamparray *la)
+{
+ return 0;
+}
+
+static inline int lamparray_resume(struct lamparray *la)
+{
+ return 0;
+}
+
#endif /* CONFIG_HID_LAMPARRAY */
#endif /* _HID_LAMPARRAY_H */
--
2.55.0
next prev parent reply other threads:[~2026-09-09 16:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 7:35 [PATCH v5 0/2] HID: generic: add LampArray support via hid-lamparray helper Aaron Erhardt
2026-09-03 7:35 ` [PATCH v5 1/2] HID: lamparray: add new LampArray helper module Aaron Erhardt
2026-09-03 20:07 ` Werner Sembach
2026-09-04 8:51 ` Aaron Erhardt
2026-09-04 21:30 ` Armin Wolf
2026-09-07 16:13 ` Aaron Erhardt
2026-09-03 7:35 ` [PATCH v5 2/2] HID: generic: add LampArray support via hid-lamparray helper Aaron Erhardt
2026-09-04 20:49 ` [PATCH v5 0/2] " Armin Wolf
2026-09-07 16:30 ` Aaron Erhardt
2026-09-09 16:52 ` [PATCH 0/4] HID: lamparray: fixes from testing on Acer Predator PT14-52T Cristian Mazzotta
2026-09-09 16:52 ` [PATCH 1/4] HID: lamparray: read attribute reports synchronously Cristian Mazzotta
2026-09-09 16:52 ` [PATCH 2/4] HID: lamparray: raise log level of fatal probe errors Cristian Mazzotta
2026-09-09 16:52 ` [PATCH 3/4] HID: lamparray: transfer control when use_leds_uapi changes Cristian Mazzotta
2026-09-09 16:52 ` Cristian Mazzotta [this message]
2026-09-11 10:38 ` [PATCH 0/4] HID: lamparray: fixes from testing on Acer Predator PT14-52T Aaron Erhardt
2026-09-09 22:36 ` [PATCH v5 0/2] HID: generic: add LampArray support via hid-lamparray helper Armin Wolf
2026-09-11 10:01 ` Aaron Erhardt
2026-09-14 13:32 ` Aaron Erhardt
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=20260909165257.352597-5-cmmazzo@icloud.com \
--to=cmmazzo@icloud.com \
--cc=W_Armin@gmx.de \
--cc=aer@tuxedocomputers.com \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wse@tuxedocomputers.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
all inboxes | Powered by JetHome®