HID: Use wVersionID for device version
Subsystems (2)
cover HID: Use wVersionID for device version
The motivation for this patch series is that the touchpads on Framework Laptops expose their firmware version in the I2C HID device descriptor. So the vendor's windows tool uses that to check the firmware version, but Linux does not expose it to userspace at all.
We have added vendor specific HID reports to newer firmware for reading the firmware version -that means however, the old firmware still cannot reports its version to Linux at all.
I found that Mario has been planning to add a way for the kernel to report HID firmware versions to userspace and added support to fwupd. There's a kernel patch in flight that also exports this:
https://lwn.net/ml/all/[email protected]/
While adding this for I2C HID devices, I noticed that the goodix-spi and surface drivers also expose the HID protocol version, which is not very useful. I do not have hardware to test those
The i2c-hid and core changes were tested on Framework Laptop 16. I also added support to hidapi for reading the new uevent, if not provided by USB already: https://github.com/libusb/hidapi/pull/777
Daniel Schaefer (4):
HID: i2c-hid: Use wVersionID for device version
HID: goodix-spi: Use version_id for device version
HID: surface: Use device version instead of HID spec version
HID: core: Export device version via HID_FIRMWARE_VERSION uevent
drivers/hid/hid-core.c | 3 +++ drivers/hid/hid-goodix-spi.c | 2 +- drivers/hid/i2c-hid/i2c-hid-core.c | 2 +- drivers/hid/surface-hid/surface_hid_core.c | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/4 HID: i2c-hid: Use wVersionID for device version
Use wVersionID instead of bcdVersion for hid->version. Per the HID over I2C Protocol Specification (Rev 1.0, Section 4.2), the HID descriptor contains two version fields with distinct purposes:
- bcdVersion: HID specification version (always 0x0100 for HID 1.0)
- wVersionID: Device-specific version number
The current code incorrectly uses bcdVersion, which always reports the HID spec version rather than the actual device/firmware version. This change aligns I2C HID behavior with USB HID, which correctly uses bcdDevice (the device version) for hid->version.
Currently wVersionID is not exposed to userspace at all. It is useful because some firmwares use this as their firmware version. It's not possible to check those device's firmware version on Linux, only Windows.
--- drivers/hid/i2c-hid/i2c-hid-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/i2c-hid/i2c-hid-core.c +1 -1
@@ -1056,7 +1056,7 @@ static int __i2c_hid_core_probe(struct i2c_hid *ihid)return ret; } - hid->version =le16_to_cpu (ihid->hdesc.bcdVersion); + hid->version =le16_to_cpu (ihid->hdesc.wVersionID); hid->vendor =le16_to_cpu (ihid->hdesc.wVendorID); hid->product =le16_to_cpu (ihid->hdesc.wProductID);
Signature · 1 line
2.52.0
PATCH 2/4 HID: goodix-spi: Use version_id for device version
In reply to Daniel SchaeferUse version_id instead of bcd_version for hid->version. The HID descriptor contains two version fields:
- bcd_version: HID specification version (e.g., 0x0100 for HID 1.0)
- version_id: Device-specific version number
The current code incorrectly uses bcd_version, which reports the HID spec version rather than the actual device/firmware version.
--- drivers/hid/hid-goodix-spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-goodix-spi.c +1 -1
@@ -653,7 +653,7 @@ static int goodix_hid_init(struct goodix_ts_data *ts) hid->bus =BUS_SPI ; hid->dev.parent = &ts->spi->dev; - hid->version =le16_to_cpu (ts->hid_desc.bcd_version); + hid->version =le16_to_cpu (ts->hid_desc.version_id); hid->vendor =le16_to_cpu (ts->hid_desc.vendor_id); hid->product =le16_to_cpu (ts->hid_desc.product_id); snprintf(hid->name, sizeof(hid->name), "%s %04X:%04X", "hid-gdix",
Signature · 1 line
2.52.0
PATCH 3/4 HID: surface: Use device version instead of HID spec version
In reply to Daniel SchaeferUse attrs.version instead of hid_desc.hid_version for hid->version. The driver has two structures with version information:
- hid_desc.hid_version: HID specification version
- attrs.version: Device-specific version number
The current code incorrectly uses hid_version from the HID descriptor, which reports the HID spec version rather than the actual device version. This change aligns with how other HID drivers report device version and matches the attrs structure which already provides vendor and product IDs.
--- drivers/hid/surface-hid/surface_hid_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/surface-hid/surface_hid_core.c +1 -1
@@ -206,7 +206,7 @@ int surface_hid_device_add(struct surface_hid_device *shid) shid->hid->bus =BUS_HOST ; shid->hid->vendor =get_unaligned_le16 (&shid->attrs.vendor); shid->hid->product =get_unaligned_le16 (&shid->attrs.product); - shid->hid->version =get_unaligned_le16 (&shid->hid_desc.hid_version); + shid->hid->version =get_unaligned_le16 (&shid->attrs.version); shid->hid->country = shid->hid_desc.country_code; snprintf(shid->hid->name, sizeof(shid->hid->name), "Microsoft Surface %04X:%04X",
Signature · 1 line
2.52.0
PATCH 4/4 HID: core: Export device version via HID_FIRMWARE_VERSION uevent
In reply to Daniel SchaeferExpose the HID device version to userspace via the new HID_FIRMWARE_VERSION uevent property. This enables userspace tools (such as fwupd and hidapi) to retrieve device firmware version information, providing parity with Windows HidD_GetAttributes() API which returns VID, PID, and VersionNumber.
The version is exported as a 4-digit uppercase hexadecimal value (e.g., "0100" for version 1.0), consistent with how USB devices report bcdDevice.
fwupd can handle this since:
https://github.com/fwupd/fwupd/commit/fb0d4cc98abe253003ea0e1837277fd42971e0de
But the kernel hasn't yet exposed this.
hidapi patch is in-flight: https://github.com/libusb/hidapi/pull/777
--- drivers/hid/hid-core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/hid/hid-core.c +3 -0
@@ -2884,6 +2884,9 @@ static int hid_uevent(const struct device *dev, struct kobj_uevent_env *env)if (add_uevent_var (env,"HID_UNIQ=%s" , hdev->uniq))return -ENOMEM ; +if (add_uevent_var (env,"HID_FIRMWARE_VERSION=%04X" , hdev->version)) +return -ENOMEM ; +if (add_uevent_var (env,"MODALIAS=hid:b%04Xg%04Xv%08Xp%08X" , hdev->bus, hdev->group, hdev->vendor, hdev->product))return -ENOMEM ;
Signature · 1 line
2.52.0
Re: [PATCH 4/4] HID: core: Export device version via HID_FIRMWARE_VERSION uevent
Quoted 31 lines · Daniel Schaefer
Expose the HID device version to userspace via the new
HID_FIRMWARE_VERSIONuevent property. This enables userspace tools (such as fwupd and hidapi) to retrieve device firmware version information, providing parity with WindowsHidD_GetAttributes()API which returns VID, PID, and VersionNumber.The version is exported as a 4-digit uppercase hexadecimal value (e.g., "0100" for version 1.0), consistent with how USB devices report bcdDevice.
fwupd can handle this since:
https://github.com/fwupd/fwupd/commit/fb0d4cc98abe253003ea0e1837277fd42971e0de
But the kernel hasn't yet exposed this.hidapi patch is in-flight: https://github.com/libusb/hidapi/pull/777
Cc Richard Hughes <[email protected]>Cc Mario Limonciello <[email protected]>Cc Jiri Kosina <[email protected]>Cc Benjamin Tissoires <[email protected]>Signed-off-by Daniel Schaefer <[email protected]>--- drivers/hid/hid-core.c | 3 +++ 1 file changed, 3 insertions(+)drivers/hid/hid-core.c +0
-0
drivers/hid/hid-core.c static int hid_uevent(const struct device *dev, struct kobj_uevent_env *env) · line 2892
Quoted 9 lines
drivers/hid/hid-core.c +3
-0@@ -2884,6 +2884,9 @@ static int hid_uevent(const struct device *dev, struct kobj_uevent_env *env)if (add_uevent_var (env,"HID_UNIQ=%s" , hdev->uniq))return -ENOMEM ; +if (add_uevent_var (env,"HID_FIRMWARE_VERSION=%04X" , hdev->version)) +return -ENOMEM ; +if (add_uevent_var (env,"MODALIAS=hid:b%04Xg%04Xv%08Xp%08X" , hdev->bus, hdev->group, hdev->vendor, hdev->product))return -ENOMEM ;
Isn't this in
hid.git#for-7.1/lenovo-v2
Re: [PATCH 4/4] HID: core: Export device version via HID_FIRMWARE_VERSION uevent
Quoted 2 lines
Isn't this in
hid.git#for-7.1/lenovo-v2
Oh yes okay, I with this already in place, I should make my patches set hdev->firmware_version instead of hdev->version. Will send another series and drop my last patch in favor of yours:
https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git/commit/?h=for-7.1/lenovo-v2&id=6ca9029c823b7853e980585e757343e0e84227cd
Quoted 48 lines · Mario Limonciello
Quoted 31 lines · Daniel Schaefer
Expose the HID device version to userspace via the new
HID_FIRMWARE_VERSIONuevent property. This enables userspace tools (such as fwupd and hidapi) to retrieve device firmware version information, providing parity with WindowsHidD_GetAttributes()API which returns VID, PID, and VersionNumber.The version is exported as a 4-digit uppercase hexadecimal value (e.g., "0100" for version 1.0), consistent with how USB devices report bcdDevice.
fwupd can handle this since:
https://github.com/fwupd/fwupd/commit/fb0d4cc98abe253003ea0e1837277fd42971e0de
But the kernel hasn't yet exposed this.hidapi patch is in-flight: https://github.com/libusb/hidapi/pull/777
Cc Richard Hughes <[email protected]>Cc Mario Limonciello <[email protected]>Cc Jiri Kosina <[email protected]>Cc Benjamin Tissoires <[email protected]>Signed-off-by Daniel Schaefer <[email protected]>--- drivers/hid/hid-core.c | 3 +++ 1 file changed, 3 insertions(+)drivers/hid/hid-core.c +0
-0drivers/hid/hid-core.c static int hid_uevent(const struct device *dev, struct kobj_uevent_env *env) · line 2892
Quoted 9 lines
drivers/hid/hid-core.c +3
-0@@ -2884,6 +2884,9 @@ static int hid_uevent(const struct device *dev, struct kobj_uevent_env *env)if (add_uevent_var (env,"HID_UNIQ=%s" , hdev->uniq))return -ENOMEM ; +if (add_uevent_var (env,"HID_FIRMWARE_VERSION=%04X" , hdev->version)) +return -ENOMEM ; +if (add_uevent_var (env,"MODALIAS=hid:b%04Xg%04Xv%08Xp%08X" , hdev->bus, hdev->group, hdev->vendor, hdev->product))return -ENOMEM ;Isn't this in
hid.git#for-7.1/lenovo-v2