HID: Add Legion Go S Driver
Subsystems (2)
cover HID: Add Legion Go S Driver
This series adds initial support for the Legion Go S's built-in controller HID configuration interface. In the first patch a new HID uevent property is added, HID_FIRMWARE_VERSION, so as to permit fwupd to read the firmware version of the HID interface without detaching the kernel driver. The second patch adds the ability for an hid_driver to assign new/arbitrary uevent properties for static data that doesn't benefit from having a sysfs entry. The third patch adds the VID and PID for the Lenovo Legion Go S MCU. The fourth patch adds ABI documentation for the config interface introduced in the final patch. The fifth patch introduces the core lenovo-legos-hid driver which acts as a routing interface for the different endpoints. The sixth path introduces the config lenovo-legos-hid driver wich uses both the HID_FIRMWARE_VERSION as well as arbitrary uevent properties. Additional interfaces and config properties are planned to be added in a future series.
Patch 6 introduces a checkpatch WARNING that I'm unable to resolve:
WARNING: ENOSYS means 'invalid syscall nr' and nothing else 1292: FILE: drivers/hid/lenovo-legos-hid/lenovo-legos-hid-config.c:1085:
+ case -ENOSYS: /* during rmmod -ENOSYS is expected */
This error handling case was added as it is experienced in the real world when the driver is rmmod. The LED subsystem produces this error code in its legacy code and this is not a new novel use of -ENOSYS, we are simply catching the case to avoid spurious errors in dmesg when the driver is removed. If there is a way to prevent this error from being triggered by checkpatch in the first place, that would be an ideal remedy, but I'm not aware how that can be done at this time.
Derek J. Clark (4):
HID: Add Legion Go S ID's
HID: Add documentation for lenovo-legos-hid driver
HID: Add lenovo-legos-hid core
HID: Add lenovo-legos-hid configuration endpoint interface
Mario Limonciello (2):
HID: Include firmware version in the uevent
HID: Allow HID drivers to add more uevent variables
.../ABI/testing/sysfs-driver-lenovo-legos-hid | 269 +++ MAINTAINERS | 7 + drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 2 + drivers/hid/hid-core.c | 11 + drivers/hid/hid-ids.h | 4 + drivers/hid/lenovo-legos-hid/Kconfig | 11 + drivers/hid/lenovo-legos-hid/Makefile | 6 + drivers/hid/lenovo-legos-hid/config.c | 1518 +++++++++++++++++ drivers/hid/lenovo-legos-hid/config.h | 19 + drivers/hid/lenovo-legos-hid/core.c | 122 ++ drivers/hid/lenovo-legos-hid/core.h | 25 + include/linux/hid.h | 2 + 13 files changed, 1998 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-lenovo-legos-hid create mode 100644 drivers/hid/lenovo-legos-hid/Kconfig create mode 100644 drivers/hid/lenovo-legos-hid/Makefile create mode 100644 drivers/hid/lenovo-legos-hid/config.c create mode 100644 drivers/hid/lenovo-legos-hid/config.h create mode 100644 drivers/hid/lenovo-legos-hid/core.c create mode 100644 drivers/hid/lenovo-legos-hid/core.h
Signature · 1 line
2.50.0
PATCH 1/6 HID: Include firmware version in the uevent
From: Mario Limonciello <[email protected]>
Userspace software fwupd probes some HID devices when the daemon starts up to determine the current firmware version in order to be able to offer updated firmware if the manufacturer has made it available.
In order to do this fwupd will detach the existing kernel driver if one is present, send a HID command and then reattach the kernel driver.
This can be problematic if the user is using the HID device at the time that fwupd probes the hardware and can cause a few frames of input to be dropped. In some cases HID drivers already have a command to look up the firmware version, and so if that is exported to userspace fwupd can discover it and avoid needing to detach the kernel driver until it's time to update the device.
Introduce a new member in the struct hid_device for the version and export a new uevent variable HID_FIRMWARE_VERSION that will display the version that HID drivers obtained.
--- drivers/hid/hid-core.c | 5 +++++ include/linux/hid.h | 1 + 2 files changed, 6 insertions(+)
drivers/hid/hid-core.c +5 -0
@@ -2839,6 +2839,11 @@ static int hid_uevent(const struct device *dev, struct kobj_uevent_env *env)if (add_uevent_var (env,"MODALIAS=hid:b%04Xg%04Xv%08Xp%08X" , hdev->bus, hdev->group, hdev->vendor, hdev->product))return -ENOMEM ; +if (hdev->firmware_version) { +if (add_uevent_var (env,"HID_FIRMWARE_VERSION=0x%04llX" , + hdev->firmware_version)) +return -ENOMEM ; + }return 0 ; }
include/linux/hid.h +1 -0
@@ -667,6 +667,7 @@ struct hid_device {char name[128 ];/* Device name */ char phys[64 ];/* Device physical location */ char uniq[64 ];/* Device unique identifier (serial #) */ +u64 firmware_version;/* Firmware version */ void *driver_data;
Signature · 1 line
2.50.0
PATCH 2/6 HID: Allow HID drivers to add more uevent variables
In reply to Derek J. ClarkFrom: Mario Limonciello <[email protected]>
Some drivers have static information that can be useful for userspace to have, but maintaining a sysfs file is overkill. Add an optional callback for drivers to be able to add their own uevent variables.
--- drivers/hid/hid-core.c | 6 ++++++ include/linux/hid.h | 1 + 2 files changed, 7 insertions(+)
drivers/hid/hid-core.c +6 -0
@@ -2844,6 +2844,12 @@ static int hid_uevent(const struct device *dev, struct kobj_uevent_env *env) hdev->firmware_version))return -ENOMEM ; } +if (hdev->uevent) { +int ret = hdev->uevent (dev, env); + +if (ret) +return ret; + }return 0 ; }
include/linux/hid.h +1 -0
@@ -680,6 +680,7 @@ struct hid_device {void (*hiddev_hid_event) (struct hid_device *,struct hid_field *field,struct hid_usage *,__s32 );void (*hiddev_report_event) (struct hid_device *,struct hid_report *); +int (*uevent)(const struct device *dev,struct kobj_uevent_env *env);/* debugging support via debugfs */ unsigned short debug;
Signature · 1 line
2.50.0
PATCH 3/6 HID: Add Legion Go S ID's
In reply to Derek J. ClarkAdds QHE vendor ID for Legion Go S Controller
Adds xinput and dinput mode Product ID for Legion Go S controller
--- drivers/hid/hid-ids.h | 4 ++++ 1 file changed, 4 insertions(+)
drivers/hid/hid-ids.h +4 -0
@@ -716,6 +716,10 @@#define USB_DEVICE_ID_ITE8595 0x8595#define USB_DEVICE_ID_ITE_MEDION_E1239T 0xce50 +#define USB_VENDOR_ID_QHE 0x1a86 +#define USB_DEVICE_ID_LENOVO_LEGION_GO_S_XINPUT 0xe310 +#define USB_DEVICE_ID_LENOVO_LEGION_GO_S_DINPUT 0xe311 +#define USB_VENDOR_ID_JABRA 0x0b0e#define USB_DEVICE_ID_JABRA_SPEAK_410 0x0412#define USB_DEVICE_ID_JABRA_SPEAK_510 0x0420
Signature · 1 line
2.50.0
PATCH 4/6 HID: Add documentation for lenovo-legos-hid driver
In reply to Derek J. ClarkAdds ABI documentation for the lenovo-legos-hid driver
--- .../ABI/testing/sysfs-driver-lenovo-legos-hid | 270 ++++++++++++++++++ MAINTAINERS | 6 + 2 files changed, 276 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-lenovo-legos-hid
Documentation/ABI/testing/sysfs-driver-lenovo-legos-hid new file +270 -0
@@ -0,0 +1,270 @@ +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/leds/go_s:rgb:joystick_rings/effect +Date: July 2025 +Contact: [email protected] +Description: This controls the display effect of the RGB interface. + + Values are monocolor, breathe, chroma, or rainbow. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/leds/go_s:rgb:joystick_rings/effect_index +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the effect attribute. + + Values are monocolor, breathe, chroma, or rainbow. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/leds/go_s:rgb:joystick_rings/enable +Date: July 2025 +Contact: [email protected] +Description: This controls enabling or disabling the RGB interface. + + Values are true or false. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/enable_index +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the enable attribute. + + Values are true or false. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/mode +Date: July 2025 +Contact: [email protected] +Description: This controls the operating mode of the RGB interface. + + Values are dynamic or custom. Custom allows setting the RGB effect and color. + Dynamic is a Windows mode for syncing Lenovo RGB interfaces not currently + supported under Linux. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/mode_index +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the mode attribute. + + Values are dynamic or custom. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/profile +Date: July 2025 +Contact: [email protected] +Description: This controls selecting the configured RGB profile. + + Values are 1-3. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/profile_range +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the profile attribute. + + Values are 1-3. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/speed +Date: July 2025 +Contact: [email protected] +Description: This controls the change rate for the breathe, chroma, and rainbow effects. + + Values are 0-100. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/speed_range +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the speed attribute. + + Values are 0-100. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad_config/auto_sleep_time +Date: July 2025 +Contact: [email protected] +Description: This controls the sleep timer due to inactivity for the built-in controller. + + Values are 0-255. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad_config/auto_sleep_time_range +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the gamepad_config/auto_sleep_time attribute. + + Values are 0-255. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad_config/dpad_mode +Date: July 2025 +Contact: [email protected] +Description: This controls the operating mode of the built-in controllers D-pad. + + Values are 4-way or 8-way. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad_config/dpad_mode_index +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the gamepad_config/dpad_mode attribute. + + Values are 4-way or 8-way. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad_config/mode +Date: July 2025 +Contact: [email protected] +Description: This controls the operating mode of the built-in controller. + + Values are xinput or dinput. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad_config/mode_index +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the gamepad_config/mode attribute. + + Values are xinput or dinput. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad_config/poll_rate +Date: July 2025 +Contact: [email protected] +Description: This controls the poll rate in Hz of the built-in controller. + + Values are 125, 250, 500, or 1000. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad_config/poll_rate_index +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the gamepad_config/poll_rate attribute. + + Values are 125, 250, 500, or 1000. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/imu_config/bypass_enable +Date: July 2025 +Contact: [email protected] +Description: This controls enabling or disabling the IMU bypass function. When enabled the IMU data is directly reported to the OS through +an HIDRAW interface. + + Values are true or false. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/imu_config/bypass_enable_index +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the imu_config/bypass_enable attribute. + + Values are true or false. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/imu_config/sensor_enable +Date: July 2025 +Contact: [email protected] +Description: This controls enabling or disabling the IMU. + + Values are true, false, or wake-2s. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/imu_config/sensor_enable_index +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the imu_config/sensor_enable attribute. + + Values are true, false, or wake-2s. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/os_mode +Date: July 2025 +Contact: [email protected] +Description: This controls which value is used for the touchpads operating mode. + + Values are windows or linux. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/os_mode_index +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the os_mode attribute. + + Values are windows or linux. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad_config/enable +Date: July 2025 +Contact: [email protected] +Description: This controls enabling or disabling the built-in touchpad. + + Values are true or false. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad_config/enable_index +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the touchpad_config/enable attribute. + + Values are true or false. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad_config/linux_mode +Date: July 2025 +Contact: [email protected] +Description: This controls behavior of the touchpad events when os_mode is set to linux. + + Values are absolute or relative. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad_config/linux_mode_index +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the touchpad_config/linux_mode attribute. + + Values are absolute or relative. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad_config/windows_mode +Date: July 2025 +Contact: [email protected] +Description: This controls behavior of the touchpad events when os_mode is set to windows. + + Values are absolute or relative. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad_config/windows_mode_index +Date: July 2025 +Contact: [email protected] +Description: This displays the available options for the touchpad_config/windows_mode attribute. + + Values are absolute or relative. + + Applies to Lenovo Legion Go S line of handheld devices.
MAINTAINERS +6 -0
@@ -13746,6 +13746,12 @@ L: [email protected] S: Maintained F: drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +LENOVO LEGION GO S HID +M: Derek J. Clark <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/ABI/testing/sysfs-driver-lenovo-legos-hid + LETSKETCH HID TABLET DRIVER M: Hans de Goede <[email protected]> L: [email protected]
Signature · 1 line
2.50.0
PATCH 5/6 HID: Add lenovo-legos-hid core
In reply to Derek J. ClarkAdds core interface for the lenovo-legos-hid driver. The purpose of core is to identify each available endpoint for the MCU in the Lenovo Legion Go S and route each one to the appropriate initialization and event handling functions. Endpoint specific logic will be implemented in subsequent patches.
--- MAINTAINERS | 1 + drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 2 + drivers/hid/lenovo-legos-hid/Kconfig | 11 +++ drivers/hid/lenovo-legos-hid/Makefile | 6 ++ drivers/hid/lenovo-legos-hid/core.c | 113 ++++++++++++++++++++++++++ drivers/hid/lenovo-legos-hid/core.h | 25 ++++++ 7 files changed, 160 insertions(+) create mode 100644 drivers/hid/lenovo-legos-hid/Kconfig create mode 100644 drivers/hid/lenovo-legos-hid/Makefile create mode 100644 drivers/hid/lenovo-legos-hid/core.c create mode 100644 drivers/hid/lenovo-legos-hid/core.h
MAINTAINERS +1 -0
@@ -13751,6 +13751,7 @@ M: Derek J. Clark <[email protected]> L: [email protected] S: Maintained F: Documentation/ABI/testing/sysfs-driver-lenovo-legos-hid +F: drivers/hid/lenovo-legos-hid/* LETSKETCH HID TABLET DRIVER M: Hans de Goede <[email protected]>
drivers/hid/Kconfig +2 -0
@@ -1436,4 +1436,6 @@ endif # HID source "drivers/hid/usbhid/Kconfig" +source "drivers/hid/lenovo-legos-hid/Kconfig" + endif # HID_SUPPORT
drivers/hid/Makefile +2 -0
@@ -175,3 +175,5 @@ obj-$(CONFIG_AMD_SFH_HID) += amd-sfh-hid/ obj-$(CONFIG_SURFACE_HID_CORE) += surface-hid/ obj-$(CONFIG_INTEL_THC_HID) += intel-thc-hid/ + +obj-$(CONFIG_LENOVO_LEGOS_HID) += lenovo-legos-hid/
drivers/hid/lenovo-legos-hid/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +config LENOVO_LEGOS_HID + tristate "Lenovo Legion Go S HID" + depends on USB_HID + depends on LEDS_CLASS + depends on LEDS_CLASS_MULTICOLOR + help + Say Y here to include support for the Lenovo Legion Go S Handheld + Console Controller. + + To compile this driver as a module, choose M here: the module will + be called lenovo-legos-hid.
drivers/hid/lenovo-legos-hid/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Makefile - Lenovo Legion Go S Handheld Console Controller driver +# +lenovo-legos-hid-y := core.o +obj-$(CONFIG_LENOVO_LEGOS_HID) := lenovo-legos-hid.o
drivers/hid/lenovo-legos-hid/core.c new file +113 -0
113 lines not on this page · raw message
drivers/hid/lenovo-legos-hid/core.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* Copyright(C) 2025 Derek J. Clark <[email protected]> */ + +#ifndef _LENOVO_LEGOS_HID_CORE_ +#define _LENOVO_LEGOS_HID_CORE_ + +#include <linux/types.h> + +#define GO_S_PACKET_SIZE 64 + +struct hid_device ; + +enum legos_interface { +LEGION_GO_S_IAP_INTF_IN =0x81 , +LEGION_GO_S_TP_INTF_IN =0x83 , +LEGION_GO_S_CFG_INTF_IN , +LEGION_GO_S_IMU_INTF_IN , +LEGION_GO_S_GP_INFT_IN , +LEGION_GO_S_UNK_INTF_IN , +}; + +u8 get_endpoint_address (struct hid_device *hdev); + +#endif /* !_LENOVO_LEGOS_HID_CORE_*/
Signature · 1 line
2.50.0
PATCH 6/6 HID: Add lenovo-legos-hid configuration endpoint interface
In reply to Derek J. ClarkAdds the logical interface for the Lenovo Legion Go S configuration endpoint. This endpoint provides settings for the gamepad, trackpad, joystick RGB, and MCU information.
The MCU only responds to raw data through hid_raw_output_report. Returns from this interface take ~800usec and multiple requests will lock the MCU, so a mutex is used to block additional calls until it can return. After 5ms the return call is aborted for normal MCU commands. The touchpad is queried through the MCU over I2C and as such takes longer to respond. The response for those calls aborts after 200ms.
--- drivers/hid/lenovo-legos-hid/Makefile | 2 +- drivers/hid/lenovo-legos-hid/config.c | 1509 +++++++++++++++++++++++++ drivers/hid/lenovo-legos-hid/config.h | 19 + drivers/hid/lenovo-legos-hid/core.c | 9 + 4 files changed, 1538 insertions(+), 1 deletion(-) create mode 100644 drivers/hid/lenovo-legos-hid/config.c create mode 100644 drivers/hid/lenovo-legos-hid/config.h
drivers/hid/lenovo-legos-hid/Makefile +1 -1
@@ -2,5 +2,5 @@ # # Makefile - Lenovo Legion Go S Handheld Console Controller driver # -lenovo-legos-hid-y := core.o +lenovo-legos-hid-y := core.o config.o obj-$(CONFIG_LENOVO_LEGOS_HID) := lenovo-legos-hid.o
drivers/hid/lenovo-legos-hid/config.c new file +1509 -0
1,509 lines not on this page · raw message
drivers/hid/lenovo-legos-hid/config.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* Copyright(C) 2025 Derek J. Clark <[email protected]> */ + +#ifndef _LENOVO_LEGOS_HID_CONFIG_ +#define _LENOVO_LEGOS_HID_CONFIG_ + +#include <linux/types.h> + +struct hid_device ; +struct hid_device_id ; +struct work_struct ; + +int legos_cfg_raw_event (u8 *data,int size); +void cfg_setup (struct work_struct *work); +int legos_cfg_probe (struct hid_device *hdev,const struct hid_device_id *_id); +void legos_cfg_remove (struct hid_device *hdev); + +#endif /* !_LENOVO_LEGOS_HID_CONFIG_*/
drivers/hid/lenovo-legos-hid/core.c +9 -0
@@ -11,6 +11,7 @@#include <linux/usb.h> #include "core.h" +#include "config.h" #include "../hid-ids.h" u8 get_endpoint_address (struct hid_device *hdev)
@@ -35,6 +36,8 @@ static int lenovo_legos_raw_event(struct hid_device *hdev, ep =get_endpoint_address (hdev);switch (ep) { +case LEGION_GO_S_CFG_INTF_IN : +return legos_cfg_raw_event (data, size);default :break ; }
@@ -70,6 +73,9 @@ static int lenovo_legos_hid_probe(struct hid_device *hdev, }switch (ep) { +case LEGION_GO_S_CFG_INTF_IN : + ret =legos_cfg_probe (hdev, id); +break ;default :break ; }
@@ -82,6 +88,9 @@ static void lenovo_legos_hid_remove(struct hid_device *hdev)int ep =get_endpoint_address (hdev);switch (ep) { +case LEGION_GO_S_CFG_INTF_IN : +legos_cfg_remove (hdev); +break ;default :hid_hw_close (hdev);hid_hw_stop (hdev);
Signature · 1 line
2.50.0
Benjamin Tissoires
maintainerHi Derek,
[I'll answer to this email with a very high level overview of it, as I'm not sure I'll have time to dig much deeper in 6/6 today.]
Quoted 5 lines · Derek J. Clark
This series adds initial support for the Legion Go S's built-in controller HID configuration interface. In the first patch a new HID uevent property is added,
HID_FIRMWARE_VERSION, so as to permit fwupd to read the firmware version of the HID interface without detaching the kernel driver.
That immediately raise red flags on my side. HID_FIRMWARE_VERSION will likely be used only for this new driver, and that means a special case in each and every client.
We had to deal with firmware versions in the past in the HID drivers, and we ended up relying on the uniq field of the hid_device (because the serial+firmware version uniquely identify the device).
Quoted 3 lines
The second patch adds the ability for an
hid_driverto assign new/arbitrary uevent properties for static data that doesn't benefit from having a sysfs entry.
That, in my mind, is even worse (for the reasons above).
Quoted 2 lines
The third patch adds the VID and PID
for the Lenovo Legion Go S MCU.
Which shouldn't be in its own patch, but part of the driver initial patch.
Quoted 4 lines
The fourth patch adds ABI documentation
for the config interface introduced in the final patch. The fifth patch introduces the core lenovo-legos-hid driver which acts as a routing interface for the different endpoints.
That "core" patch is IMO useless. All it does is:
- check for the USB endpoint (but in the wrong way, because if you insert a device through uhid with the same PID/VID it will crash)
- replace the HID-core core functions with the same code
Really, this should be squashed into the next patch (with 3/6 then).
Also, why adding a new subdirectory? All the hid drivers are flat in the drivers/hid/ directory, and the subdirs are for transport layers. There is one exception for the surface driver but I don't see why you need such an exception (yeah, the code is big, but what's the difference in having a 1500 lines of code source in its own subdir vs at the root?)
Quoted 4 lines
The sixth path introduces the
config lenovo-legos-hid driver wich uses both theHID_FIRMWARE_VERSIONas well as arbitrary uevent properties. Additional interfaces and config properties are planned to be added in a future series.
That one is too big for my liking. Generally speaking, a commit descrition which says "this does this and that" can be split into 2 patches at least :)
What kind of future interfaces and config properties are you planning?
Quoted 5 lines
Patch 6 introduces a checkpatch WARNING that I'm unable to resolve:
WARNING: ENOSYS means 'invalid syscall nr' and nothing else 1292: FILE:drivers/hid/lenovo-legos-hid/lenovo-legos-hid-config.c:1085:
+ case-ENOSYS: /* during rmmod-ENOSYSis expected */
We can losely waive those while merging. We do it quite often actually.
But trying to minimize checkpatch warnings is a good thing, so thanks for that.
Quoted 8 lines
This error handling case was added as it is experienced in the real world when the driver is rmmod. The LED subsystem produces this error code in its legacy code and this is not a new novel use of
-ENOSYS, we are simply catching the case to avoid spurious errors in dmesg when the driver is removed. If there is a way to prevent this error from being triggered by checkpatch in the first place, that would be an ideal remedy, but I'm not aware how that can be done at this time.
Again, nothing to worry about.
Cheers,
Benjamin
Quoted 39 lines
Signed-off-by Derek J. Clark <[email protected]>Derek J. Clark (4):
HID: Add Legion Go S ID's
HID: Add documentation for lenovo-legos-hid driver
HID: Add lenovo-legos-hid core
HID: Add lenovo-legos-hid configuration endpoint interfaceMario Limonciello (2):
HID: Include firmware version in the uevent
HID: Allow HID drivers to add more uevent variables.../ABI/testing/sysfs-driver-lenovo-legos-hid | 269 +++ MAINTAINERS | 7 + drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 2 + drivers/hid/hid-core.c | 11 + drivers/hid/hid-ids.h | 4 + drivers/hid/lenovo-legos-hid/Kconfig | 11 + drivers/hid/lenovo-legos-hid/Makefile | 6 + drivers/hid/lenovo-legos-hid/config.c | 1518 +++++++++++++++++ drivers/hid/lenovo-legos-hid/config.h | 19 + drivers/hid/lenovo-legos-hid/core.c | 122 ++ drivers/hid/lenovo-legos-hid/core.h | 25 + include/linux/hid.h | 2 + 13 files changed, 1998 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-lenovo-legos-hid create mode 100644 drivers/hid/lenovo-legos-hid/Kconfig create mode 100644 drivers/hid/lenovo-legos-hid/Makefile create mode 100644 drivers/hid/lenovo-legos-hid/config.c create mode 100644 drivers/hid/lenovo-legos-hid/config.h create mode 100644 drivers/hid/lenovo-legos-hid/core.c create mode 100644 drivers/hid/lenovo-legos-hid/core.hSignature · 1 line
2.50.0
Quoted 4 lines · Benjamin Tissoires
Hi Derek,
[I'll answer to this email with a very high level overview of it, as I'm not sure I'll have time to dig much deeper in 6/6 today.]
I'll touch on my two patches at the front of the series and let Derek get to the questions/comments on the later ones.
Quoted 11 lines · Derek J. Clark
Quoted 5 lines
This series adds initial support for the Legion Go S's built-in controller HID configuration interface. In the first patch a new HID uevent property is added,
HID_FIRMWARE_VERSION, so as to permit fwupd to read the firmware version of the HID interface without detaching the kernel driver.That immediately raise red flags on my side.
HID_FIRMWARE_VERSIONwill likely be used only for this new driver, and that means a special case in each and every client.
Actually Richard and I had envisioned that all updatable HID devices would start exporting their firmware version through this HID property. lenovo-legos-hid was just the first.
The idea would then be that userspace software like fwupd would know to parse this property to show the current version and never need to interrogate the device directly unless it was actually being updated.
Quoted 4 lines
We had to deal with firmware versions in the past in the HID drivers, and we ended up relying on the uniq field of the
hid_device(because the serial+firmware version uniquely identify the device).
I think this is a different case. We don't care so much about the unique identification of the device as much as we care about the stream of firmware applied to the device.
If HID_UNIQ is the right way to get the firmware version but some drivers encode a serial+firmware and others encode firmware that's going to make for a very messy "generic" property to read the firmware version of a device.
Quoted 6 lines
Quoted 4 lines
The second patch adds the ability for an
hid_driverto assign new/arbitrary uevent properties for static data that doesn't benefit from having a sysfs entry.That, in my mind, is even worse (for the reasons above).
Do clients actually need to know about all the properties? My thought was that if a client encounters a property it doesn't care about it can just ignore it.
If that's misplaced; what would you prefer for all this static information? A pile of sysfs files?
Quoted 100 lines
Quoted 3 lines
The third patch adds the VID and PID
for the Lenovo Legion Go S MCU.Which shouldn't be in its own patch, but part of the driver initial patch.
Quoted 4 lines
The fourth patch adds ABI documentation
for the config interface introduced in the final patch. The fifth patch introduces the core lenovo-legos-hid driver which acts as a routing interface for the different endpoints.That "core" patch is IMO useless. All it does is:
- check for the USB endpoint (but in the wrong way, because if you insert a device through uhid with the same PID/VID it will crash)
- replace the HID-core core functions with the same codeReally, this should be squashed into the next patch (with 3/6 then).
Also, why adding a new subdirectory? All the hid drivers are flat in the
drivers/hid/directory, and the subdirs are for transport layers. There is one exception for the surface driver but I don't see why you need such an exception (yeah, the code is big, but what's the difference in having a 1500 lines of code source in its own subdir vs at the root?)Quoted 4 lines
The sixth path introduces the
config lenovo-legos-hid driver wich uses both theHID_FIRMWARE_VERSIONas well as arbitrary uevent properties. Additional interfaces and config properties are planned to be added in a future series.That one is too big for my liking. Generally speaking, a commit descrition which says "this does this and that" can be split into 2 patches at least :)
What kind of future interfaces and config properties are you planning?
Quoted 5 lines
Patch 6 introduces a checkpatch WARNING that I'm unable to resolve:
WARNING: ENOSYS means 'invalid syscall nr' and nothing else 1292: FILE:drivers/hid/lenovo-legos-hid/lenovo-legos-hid-config.c:1085:
+ case-ENOSYS: /* during rmmod-ENOSYSis expected */We can losely waive those while merging. We do it quite often actually.
But trying to minimize checkpatch warnings is a good thing, so thanks for that.
Quoted 8 lines
This error handling case was added as it is experienced in the real world when the driver is rmmod. The LED subsystem produces this error code in its legacy code and this is not a new novel use of
-ENOSYS, we are simply catching the case to avoid spurious errors in dmesg when the driver is removed. If there is a way to prevent this error from being triggered by checkpatch in the first place, that would be an ideal remedy, but I'm not aware how that can be done at this time.Again, nothing to worry about.
Cheers,
BenjaminQuoted 39 lines
Signed-off-by Derek J. Clark <[email protected]>Derek J. Clark (4):
HID: Add Legion Go S ID's
HID: Add documentation for lenovo-legos-hid driver
HID: Add lenovo-legos-hid core
HID: Add lenovo-legos-hid configuration endpoint interfaceMario Limonciello (2):
HID: Include firmware version in the uevent
HID: Allow HID drivers to add more uevent variables.../ABI/testing/sysfs-driver-lenovo-legos-hid | 269 +++ MAINTAINERS | 7 + drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 2 + drivers/hid/hid-core.c | 11 + drivers/hid/hid-ids.h | 4 + drivers/hid/lenovo-legos-hid/Kconfig | 11 + drivers/hid/lenovo-legos-hid/Makefile | 6 + drivers/hid/lenovo-legos-hid/config.c | 1518 +++++++++++++++++ drivers/hid/lenovo-legos-hid/config.h | 19 + drivers/hid/lenovo-legos-hid/core.c | 122 ++ drivers/hid/lenovo-legos-hid/core.h | 25 + include/linux/hid.h | 2 + 13 files changed, 1998 insertions(+)create mode 100644
Documentation/ABI/testing/sysfs-driver-lenovo-legos-hidcreate mode 100644drivers/hid/lenovo-legos-hid/Kconfig
create mode 100644drivers/hid/lenovo-legos-hid/Makefilecreate mode 100644drivers/hid/lenovo-legos-hid/config.ccreate mode 100644drivers/hid/lenovo-legos-hid/config.hcreate mode 100644drivers/hid/lenovo-legos-hid/core.c
create mode 100644drivers/hid/lenovo-legos-hid/core.hSignature · 1 line
2.50.0
Quoted 4 lines · Mario Limonciello
If
HID_UNIQis the right way to get the firmware version but some drivers encode a serial+firmware and others encode firmware that's going to make for a very messy "generic" property to read the firmware version of a device.
I think I've also changed my mind on HID_UNIQ -- IIUC the whole point of HID_UNIQ is to be unique comparing devices with the same VID&PID. If I plug in two identical devices with the same firmware version then HID_UNIQ would be the same -- so I think HID_UNIQ should probably always be the serial number. I think HID_UNIQ should also stay the same during the firmware update too, so we don't want to jam two things into one property like "HID_UNIQ=serial:1234,fwver=12.34"
Certainly exposing the firmware version as a HID property makes enumerating devices much easier in fwupd; the kernel driver often just knows the firmware version already and for userspace to re-query the firmware version using a per-device custom protocol seems pointless at best and dangerous at worse -- given we're typically doing a SetReport and GetReport with no sequence number available.
I don't have much to comment on wrt the implementation, but providing a way for the hidraw kernel driver to export the current firmware version up to userspace makes a lot of sense to me.
Richard
Quoted 21 lines · Benjamin Tissoires
Hi Derek,
[I'll answer to this email with a very high level overview of it, as I'm not sure I'll have time to dig much deeper in 6/6 today.]
Quoted 5 lines · Derek J. Clark
This series adds initial support for the Legion Go S's built-in controller HID configuration interface. In the first patch a new HID uevent property is added,
HID_FIRMWARE_VERSION, so as to permit fwupd to read the firmware version of the HID interface without detaching the kernel driver.That immediately raise red flags on my side.
HID_FIRMWARE_VERSIONwill likely be used only for this new driver, and that means a special case in each and every client.We had to deal with firmware versions in the past in the HID drivers, and we ended up relying on the uniq field of the
hid_device(because the serial+firmware version uniquely identify the device).
Quoted 6 lines
Quoted 3 lines
The second patch adds the ability for an
hid_driverto assign new/arbitrary uevent properties for static data that doesn't benefit from having a sysfs entry.That, in my mind, is even worse (for the reasons above).
Hi Benjamin,
Sorry abtthe late reply. Travel & holidays have me a bit behind.
I'll let Mario and Richard hash out the specifics on these points. I'll just add a bit of context to why they're in this series. Prior to this, the fwupd plugin would disconnect this driver to query this information to see if there was an available update. As this can be triggered by a system daemon during gameplay that's not a reasonable expectation. Originally we had these as sysfs entries, and returning to them, would be simple enough, but we felt like this is a fairly standard piece of information that should be available. I wasn't aware of the uniq property being used for this historically, but from an outside looking in perspective this seems a bit convoluted. Apart from just being unintuitive if you're not familiar, userspace is going to need bespoke ways to interpret this anyway as serial numbers and firmware formatting are not consistent between manufacturers.
I'll wait to adjust this until a more thorough discussion has taken place.
Quoted 5 lines
Quoted 2 lines
The third patch adds the VID and PID
for the Lenovo Legion Go S MCU.Which shouldn't be in its own patch, but part of the driver initial patch.
I can do that. My reasoning was simply that if another patch becomes reliant on the VID and you needed to revert the other patches for any reason there would be a conflict.
Quoted 9 lines
Quoted 4 lines
The fourth patch adds ABI documentation
for the config interface introduced in the final patch. The fifth patch introduces the core lenovo-legos-hid driver which acts as a routing interface for the different endpoints.That "core" patch is IMO useless. All it does is:
- check for the USB endpoint (but in the wrong way, because if you insert a device through uhid with the same PID/VID it will crash)
- replace the HID-core core functions with the same code
Can you point me to a better way?
This series only implements the config endpoint. ATM the gamepad, touchpad, and IMU are combined into a single Steam Deck like interface in root level userspace as a uhid device. I do have some plans for how to do this in the kernel instead, but the proposal isn't ready yet so I need to keep the hidraw devices available to userspace that aren't implemented yet for backwards compatibility.
Quoted 7 lines
Really, this should be squashed into the next patch (with 3/6 then).
Also, why adding a new subdirectory? All the hid drivers are flat in the
drivers/hid/directory, and the subdirs are for transport layers. There is one exception for the surface driver but I don't see why you need such an exception (yeah, the code is big, but what's the difference in having a 1500 lines of code source in its own subdir vs at the root?)
Sure, I can change it to a single file if that's preferable in this subsystem. This is my first foray into kernel HID drivers so I'm not super familiar with the style preferences yet. Breaking everything up by logical subset made sense to me but I'm not married to it. There
Quoted 8 lines
Quoted 4 lines
The sixth path introduces the
config lenovo-legos-hid driver wich uses both theHID_FIRMWARE_VERSIONas well as arbitrary uevent properties. Additional interfaces and config properties are planned to be added in a future series.That one is too big for my liking. Generally speaking, a commit descrition which says "this does this and that" can be split into 2 patches at least :)
I figured, but I wasn't sure how you'd prefer I break it up. I was thinking that one patch per attribute group would make sense but wanted some feedback before I did that to avoid going down the wrong path with them.
Quoted 1 line
What kind of future interfaces and config properties are you planning?
The MCU has a gamepad interface that is more complete than what the xpad driver uses, which includes some back paddles as well as native gyro data which is passed through from the IMU. There's also a separate IMU endpoint so there are a couple options how this can be used. My thoughts are that a sysfs attribute could toggle if gyro is added to one of the joysticks using the IMU data included in the gamepad report, and the external one could be exposed as a motion sensor with the same uniq. Then userspace can determine how to use it.
The touchpad works in both abs and rel modes with the default kernel implementations but additional functionality can be gained through Steam Input if this is integrated into the gamepad.
As far as additional attributes for the config interface, there is hardware level button remapping and calibration for all axes that need to be added but weren't considered critical for initial support from Lenovo.
Quoted 10 lines
Quoted 5 lines
Patch 6 introduces a checkpatch WARNING that I'm unable to resolve:
WARNING: ENOSYS means 'invalid syscall nr' and nothing else 1292: FILE:drivers/hid/lenovo-legos-hid/lenovo-legos-hid-config.c:1085:
+ case-ENOSYS: /* during rmmod-ENOSYSis expected */We can losely waive those while merging. We do it quite often actually.
But trying to minimize checkpatch warnings is a good thing, so thanks for that.
Cool, I'll keep a brief note for posterity.
Thanks,
Derek
Quoted 53 lines
Quoted 8 lines
This error handling case was added as it is experienced in the real world when the driver is rmmod. The LED subsystem produces this error code in its legacy code and this is not a new novel use of
-ENOSYS, we are simply catching the case to avoid spurious errors in dmesg when the driver is removed. If there is a way to prevent this error from being triggered by checkpatch in the first place, that would be an ideal remedy, but I'm not aware how that can be done at this time.Again, nothing to worry about.
Cheers,
BenjaminQuoted 39 lines
Signed-off-by Derek J. Clark <[email protected]>Derek J. Clark (4):
HID: Add Legion Go S ID's
HID: Add documentation for lenovo-legos-hid driver
HID: Add lenovo-legos-hid core
HID: Add lenovo-legos-hid configuration endpoint interfaceMario Limonciello (2):
HID: Include firmware version in the uevent
HID: Allow HID drivers to add more uevent variables.../ABI/testing/sysfs-driver-lenovo-legos-hid | 269 +++ MAINTAINERS | 7 + drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 2 + drivers/hid/hid-core.c | 11 + drivers/hid/hid-ids.h | 4 + drivers/hid/lenovo-legos-hid/Kconfig | 11 + drivers/hid/lenovo-legos-hid/Makefile | 6 + drivers/hid/lenovo-legos-hid/config.c | 1518 +++++++++++++++++ drivers/hid/lenovo-legos-hid/config.h | 19 + drivers/hid/lenovo-legos-hid/core.c | 122 ++ drivers/hid/lenovo-legos-hid/core.h | 25 + include/linux/hid.h | 2 + 13 files changed, 1998 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-lenovo-legos-hid create mode 100644 drivers/hid/lenovo-legos-hid/Kconfig create mode 100644 drivers/hid/lenovo-legos-hid/Makefile create mode 100644 drivers/hid/lenovo-legos-hid/config.c create mode 100644 drivers/hid/lenovo-legos-hid/config.h create mode 100644 drivers/hid/lenovo-legos-hid/core.c create mode 100644 drivers/hid/lenovo-legos-hid/core.hSignature · 1 line
2.50.0