Skip to content

Commit 6bb925f

Browse files
committed
linux: Parse HID_FIRMWARE_VERSION from uevent for release_number
Parse the HID_FIRMWARE_VERSION uevent property to populate release_number for all HID devices. This provides device version information for I2C, Bluetooth, SPI, and virtual HID devices. For USB devices, the existing bcdDevice lookup from sysfs still takes precedence, maintaining backward compatibility. The HID_FIRMWARE_VERSION property is being added to the Linux kernel (patch series submitted to linux-input@vger.kernel.org). On kernels without this property, release_number will remain 0 for non-USB devices, preserving existing behavior. Link: https://lore.kernel.org/linux-input/ [kernel patch series] Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 55aab02 commit 6bb925f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

linux/hid.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ static int get_hid_report_descriptor_from_hidraw(hid_device *dev, struct hidraw_
571571
*/
572572
static int parse_uevent_info(const char *uevent, unsigned *bus_type,
573573
unsigned short *vendor_id, unsigned short *product_id,
574-
char **serial_number_utf8, char **product_name_utf8)
574+
char **serial_number_utf8, char **product_name_utf8,
575+
unsigned short *version)
575576
{
576577
char tmp[1024];
577578

@@ -622,6 +623,9 @@ static int parse_uevent_info(const char *uevent, unsigned *bus_type,
622623
/* The caller has to free the serial number */
623624
*serial_number_utf8 = strdup(value);
624625
found_serial = 1;
626+
} else if (strcmp(key, "HID_FIRMWARE_VERSION") == 0) {
627+
/* Device version from kernel */
628+
*version = (unsigned short)strtol(value, NULL, 16);
625629
}
626630

627631
next_line:
@@ -648,6 +652,7 @@ static struct hid_device_info * create_device_info_for_device(struct udev_device
648652
char *serial_number_utf8 = NULL;
649653
char *product_name_utf8 = NULL;
650654
unsigned bus_type;
655+
unsigned short hid_version = 0;
651656
int result;
652657
struct hidraw_report_descriptor report_desc;
653658

@@ -670,7 +675,8 @@ static struct hid_device_info * create_device_info_for_device(struct udev_device
670675
&dev_vid,
671676
&dev_pid,
672677
&serial_number_utf8,
673-
&product_name_utf8);
678+
&product_name_utf8,
679+
&hid_version);
674680

675681
if (!result) {
676682
/* parse_uevent_info() failed for at least one field. */
@@ -709,7 +715,7 @@ static struct hid_device_info * create_device_info_for_device(struct udev_device
709715
cur_dev->serial_number = utf8_to_wchar_t(serial_number_utf8);
710716

711717
/* Release Number */
712-
cur_dev->release_number = 0x0;
718+
cur_dev->release_number = hid_version;
713719

714720
/* Interface Number */
715721
cur_dev->interface_number = -1;

0 commit comments

Comments
 (0)