[PATCH v5 2/2] HID: generic: add LampArray support via hid-lamparray helper

From: Aaron Erhardt

Date: Thu Sep 03 2026 - 03:49:52 EST


The hid-generic driver now checks for LampArray support after
hid_parse() and optionally registers a lamparray instance. Failures in
the helper do not abort device probe to keep the device unchanged.

LampArray resources are released on driver remove.

This patch was successfully tested on the Microsoft MacroPad reference
implementation (https://github.com/microsoft/RP2040MacropadHidSample
1d6c3ad) and in combination with the tuxedo_nb04_wmi driver, albeit only
functional with a recent fix posted to the LKML
(https://lore.kernel.org/all/20260728115918.125349-2-aer@xxxxxxxxxxxxxxxxxxx).

Co-developed-by: Tim Guttzeit <tgu@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Tim Guttzeit <tgu@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Aaron Erhardt <aer@xxxxxxxxxxxxxxxxxxx>
---
drivers/hid/Kconfig | 1 +
drivers/hid/hid-generic.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+)

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 4afd80a67b39..a0fcd89c2bb0 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -82,6 +82,7 @@ config UHID

config HID_GENERIC
tristate "Generic HID driver"
+ depends on HID_LAMPARRAY if HID_LAMPARRAY
default HID
help
Support for generic devices on the HID bus. This includes most
diff --git a/drivers/hid/hid-generic.c b/drivers/hid/hid-generic.c
index c2de916747de..c3d2283198e8 100644
--- a/drivers/hid/hid-generic.c
+++ b/drivers/hid/hid-generic.c
@@ -20,6 +20,7 @@
#include <asm/byteorder.h>

#include <linux/hid.h>
+#include <linux/hid-lamparray.h>

static struct hid_driver hid_generic;

@@ -60,6 +61,7 @@ static int hid_generic_probe(struct hid_device *hdev,
const struct hid_device_id *id)
{
int ret;
+ struct lamparray *la;

hdev->quirks |= HID_QUIRK_INPUT_PER_APP;

@@ -67,6 +69,31 @@ static int hid_generic_probe(struct hid_device *hdev,
if (ret)
return ret;

+ /*
+ * Optional: attach LampArray support if present.
+ * Never fail probe on LampArray errors; keep device functional.
+ */
+ if (IS_ENABLED(CONFIG_HID_LAMPARRAY) && lamparray_is_supported_device(hdev)) {
+ /*
+ * Use HID_CONNECT_DRIVER to claim driver to make sure
+ * requests are processed. Needed for performing
+ * hid_hw_request()/hid_hw_wait() to communicate with the
+ * LampArray device.
+ */
+ ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | HID_CONNECT_DRIVER);
+ if (ret)
+ return ret;
+
+ la = lamparray_register(hdev, NULL);
+ if (IS_ERR(la)) {
+ hid_hw_stop(hdev);
+ hid_warn(hdev, "LampArray init failed: %ld\n", PTR_ERR(la));
+ } else {
+ hid_set_drvdata(hdev, la);
+ return 0;
+ }
+ }
+
return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
}

@@ -78,6 +105,16 @@ static int hid_generic_reset_resume(struct hid_device *hdev)
return 0;
}

+static void hid_generic_remove(struct hid_device *hdev)
+{
+ struct lamparray *la = hid_get_drvdata(hdev);
+
+ if (IS_ENABLED(CONFIG_HID_LAMPARRAY) && la)
+ lamparray_unregister(la);
+
+ hid_hw_stop(hdev);
+}
+
static const struct hid_device_id hid_table[] = {
{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_ANY, HID_ANY_ID, HID_ANY_ID) },
{ }
@@ -90,6 +127,7 @@ static struct hid_driver hid_generic = {
.match = hid_generic_match,
.probe = hid_generic_probe,
.reset_resume = hid_generic_reset_resume,
+ .remove = hid_generic_remove,
};
module_hid_driver(hid_generic);

--
2.43.0