From: Aaron Erhardt <aer@tuxedocomputers.com>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: Cristian Mazzotta <cmmazzo@icloud.com>,
Werner Sembach <wse@tuxedocomputers.com>,
Armin Wolf <W_Armin@gmx.de>,
linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
linux-leds@vger.kernel.org,
Aaron Erhardt <aer@tuxedocomputers.com>
Subject: [PATCH v7 3/3] HID: lamparray: blank lamps across suspend and restore on resume
Date: Tue, 20 Oct 2026 11:51:49 +0200 [thread overview]
Message-ID: <20261020-hid-lamparray-v7-3-47418b667b47@tuxedocomputers.com> (raw)
In-Reply-To: <20261020-hid-lamparray-v7-0-47418b667b47@tuxedocomputers.com>
From: Cristian Mazzotta <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.
Co-developed-by: Aaron Erhardt <aer@tuxedocomputers.com>
Signed-off-by: Aaron Erhardt <aer@tuxedocomputers.com>
Signed-off-by: Cristian Mazzotta <cmmazzo@icloud.com>
---
drivers/hid/hid-generic.c | 29 ++++++++++++++++++++++-
drivers/hid/hid-lamparray.c | 54 +++++++++++++++++++++++++++++++++++++++++++
include/linux/hid-lamparray.h | 29 +++++++++++++++++++++++
3 files changed, 111 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-generic.c b/drivers/hid/hid-generic.c
index fde772c5014bb..f78c62f796fbb 100644
--- a/drivers/hid/hid-generic.c
+++ b/drivers/hid/hid-generic.c
@@ -102,9 +102,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;
}
@@ -129,8 +154,10 @@ static struct hid_driver hid_generic = {
.id_table = hid_table,
.match = hid_generic_match,
.probe = hid_generic_probe,
- .reset_resume = hid_generic_reset_resume,
.remove = hid_generic_remove,
+ .reset_resume = pm_ptr(hid_generic_reset_resume),
+ .suspend = pm_ptr(hid_generic_suspend),
+ .resume = pm_ptr(hid_generic_resume),
};
module_hid_driver(hid_generic);
diff --git a/drivers/hid/hid-lamparray.c b/drivers/hid/hid-lamparray.c
index fb3082f6d19a0..5c97cafbd25d2 100644
--- a/drivers/hid/hid-lamparray.c
+++ b/drivers/hid/hid-lamparray.c
@@ -852,6 +852,60 @@ 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 ~3.14W with
+ * them blanked; the lighting accounted for ~75% 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.
+ */
+void lamparray_suspend(struct lamparray *la)
+{
+ struct lamparray_device *ldev;
+
+ if (!la)
+ return;
+
+ ldev = &la->ldev;
+
+ if (!ldev->use_leds_uapi)
+ return;
+
+ mutex_lock(&ldev->dev_lock);
+ lamparray_hw_set_state(ldev, 0, 0, 0, 0);
+ mutex_unlock(&ldev->dev_lock);
+
+ hid_hw_wait(ldev->hdev);
+}
+EXPORT_SYMBOL_GPL(lamparray_suspend);
+
+void lamparray_resume(struct lamparray *la)
+{
+ struct lamparray_device *ldev;
+
+ if (!la)
+ return;
+
+ ldev = &la->ldev;
+
+ if (!ldev->use_leds_uapi)
+ return;
+
+ /*
+ * 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);
+ hid_hw_wait(ldev->hdev);
+ lamparray_hw_set_autonomous(ldev, false);
+
+ lamparray_restore_state(ldev);
+}
+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 6124878859392..dc9df938e5b7e 100644
--- a/include/linux/hid-lamparray.h
+++ b/include/linux/hid-lamparray.h
@@ -66,6 +66,27 @@ 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 and brightness values, 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.
+ */
+void 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.
+ */
+void lamparray_resume(struct lamparray *la);
+
#else /* !CONFIG_HID_LAMPARRAY */
static inline bool lamparray_is_supported_device(struct hid_device *hdev)
@@ -84,6 +105,14 @@ static inline void lamparray_unregister(struct lamparray *la)
{
}
+static inline void lamparray_suspend(struct lamparray *la)
+{
+}
+
+static inline void lamparray_resume(struct lamparray *la)
+{
+}
+
#endif /* CONFIG_HID_LAMPARRAY */
#endif /* _HID_LAMPARRAY_H */
--
2.43.0
prev parent reply other threads:[~2026-10-20 9:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 9:51 [PATCH v7 0/3] HID: generic: add LampArray support via hid-lamparray helper Aaron Erhardt
2026-10-20 9:51 ` [PATCH v7 1/3] HID: lamparray: add new LampArray helper module Aaron Erhardt
2026-10-20 9:51 ` [PATCH v7 2/3] HID: generic: add LampArray support via hid-lamparray helper Aaron Erhardt
2026-10-20 9:51 ` Aaron Erhardt [this message]
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=20261020-hid-lamparray-v7-3-47418b667b47@tuxedocomputers.com \
--to=aer@tuxedocomputers.com \
--cc=W_Armin@gmx.de \
--cc=bentiss@kernel.org \
--cc=cmmazzo@icloud.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@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®