HID: Add Legion Go and Go S Drivers
Subsystems (4)
Derek J. Clark
maintainerv6 cover HID: Add Legion Go and Go S Drivers
This series adds configuration driver support for the Legion Go S, Legion Go, and Legion Go 2 built-in controller HID interfaces. This allows for configuring hardware specific attributes such as the auso sleep timeout, rumble intensity, etc. non-configuration reports are forwarded to the HID subsystem to ensure no loss of functionality in userspace. Basic gamepad functionality is provided through xpad, while advanced features are currently only implemented in userspace daemons such as InputPlumber[1]. I plan to move this functionality into the kernel in a later patch series.
Three new device.h macros are added that solve a fairly specific problem. Many of the attributes need to have the same name as other attributes when they are in separate attribute subdirectories. The previous version of this series, along with the upcoming his-asus-ally driver[2] use this macro to simplify the sysfs by removing redundancy. An upcoming out of tree driver for the Zotac Zone [3] also found this macro to be useful. This greatly reduces the path length and term redundancy of file paths in the sysfs, while also allowing for cleaner subdirectories that are grouped by functionality. Rather than carry the same macro in four drivers, it seems beneficial to me that we include the macro with the other device macros.
A new HID uevent property is also added, HID_FIRMWARE_VERSION, so as to permit fwupd to read the firmware version of the Go S HID interface without detaching the kernel driver.
Finally, there are some checkpatch warnings that will need to be supressed:
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 drivers are removed.
[1]: https://github.com/ShadowBlip/InputPlumber/tree/main/src/drivers/lego
[2]: https://lore.kernel.org/all/[email protected]/
[3]: https://github.com/flukejones/linux/tree/wip/zotac-zone-6.15/drivers/hid/zotac-zone-hid
---
Change Log
v6:
- Include multiple bug fixes from Ethan Tidmore.
- Make all local attributes static.
- Invert the rgb_speed logic for the go driver. On the Go this
attribute sets a delay, so flip the logic to match Go S where the
larger number means faster so userspace can target this consistently.
- Include 3 new patches that fix formatting issues with v5 authored by additional developers.
v5: https://lore.kernel.org/linux-input/[email protected]/
- Make all RO attributes cache the data during probe using delayed
work for both drivers. All RW attributes are read in realtime to
ensure they match the device current state in the event of firmware reset or a userspace application.
- Fix endianness of version strings and print as hex for Go driver.
- Remove reset__esume function. It was not being hit as the MCU of
both devices disconnects of suspend, forcing a reinit of the driver. Udev or userpsace will need to set the OS Mode upon resume.
v4: https://lore.kernel.org/linux-input/[email protected]/
- Use dmabuf allocated per request for both drivers instead of a devm preallocated buffer that is reused. This solves a bug where some attributes couldn't be restored without manual writing after resume.
- Reduce the number of quirks and flags in the Go S init to only those necessary. Previously they were duplicated from the Go driver but everything except HID_CONNECT_HIDRAW was found to be unnessary
during operational testing.
- Clean up formatting for debug prints in Go S driver.
- Fix bugs in RGB driver for Go that caused the effect to switch to
solid when the speed or brightness was changed.
- Remove extraneous setting of os_mode member of drvdata when setting os_mode. It will be read from the hardware in _show.
v3: https://lore.kernel.org/linux-input/[email protected]/
- Fix Documentation formatting by removing extra + characters.
- Fix bugs in hid-lenovo-go-s IMU & TP RO attributes being tied to the wrong _show function.
- Rename enume os_mode_index to os_mode_types_index to fix collision
with os_mode_index attribute.
- Remove accidental rename for enabled->enable attributes in patch 4
- Add SOB for Mario in patch 10 as Co-Developer.
v2: https://lore.kernel.org/linux-input/[email protected]/
- Break up adding the Go S driver into feature specific patches.
- Rename Go S driver from lenovo-legos-hid to hid-lenovo-go-s and move
it out of a subdirectory.
- Drop the arbitrary uevent properties patch.
- Add Go series driver.
- Move DEVICE_ATTR_NAMED macros to device.h.
v1: https://lore.kernel.org/linux-input/[email protected]/
Chen Ni (2):
HID: hid-lenovo-go-s: Remove unneeded semicolon
HID: hid-lenovo-go: Remove unneeded semicolon
Colin Ian King (1):
HID: hid-lenovo-go-s: Fix spelling mistake "configuratiion" ->
"configuration"
Derek J. Clark (15):
include: device.h: Add named device attributes
HID: hid-lenovo-go: Add Lenovo Legion Go Series HID Driver
HID: hid-lenovo-go: Add Feature Status Attributes
HID: hid-lenovo-go: Add Rumble and Haptic Settings
HID: hid-lenovo-go: Add FPS Mode DPI settings
HID: hid-lenovo-go: Add RGB LED control interface
HID: hid-lenovo-go: Add Calibration Settings
HID: hid-lenovo-go: Add OS Mode Toggle
HID: hid-lenovo-go-s: Add Lenovo Legion Go S Series HID Driver
HID: hid-lenovo-go-s: Add MCU ID Attribute
HID: hid-lenovo-go-s: Add Feature Status Attributes
HID: hid-lenovo-go-s: Add Touchpad Mode Attributes
HID: hid-lenovo-go-s: Add RGB LED control interface
HID: hid-lenovo-go-s: Add IMU and Touchpad RO Attributes
HID: Add documentation for Lenovo Legion Go drivers
Mario Limonciello (1):
HID: Include firmware version in the uevent
.../ABI/testing/sysfs-driver-hid-lenovo-go | 724 +++++ .../ABI/testing/sysfs-driver-hid-lenovo-go-s | 304 ++ MAINTAINERS | 11 + drivers/hid/Kconfig | 24 + drivers/hid/Makefile | 2 + drivers/hid/hid-core.c | 5 + drivers/hid/hid-ids.h | 7 + drivers/hid/hid-lenovo-go-s.c | 1506 ++++++++++ drivers/hid/hid-lenovo-go.c | 2502 +++++++++++++++++ include/linux/device.h | 46 + include/linux/hid.h | 1 + 11 files changed, 5132 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-lenovo-go create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s create mode 100644 drivers/hid/hid-lenovo-go-s.c create mode 100644 drivers/hid/hid-lenovo-go.c
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 1/19 include: device.h: Add named device attributes
Adds DEVICE_ATTR_[RW|RO|WO]_NAMED macros for adding attributes that reuse the same sysfs name in a driver under separate subdirectories.
When dealing with some devices it can be useful to be able to reuse the same name for similar attributes under a different subdirectory. For example, a single logical HID endpoint may provide a configuration interface for multiple physical devices. In such a case it is useful to provide symmetrical attribute names under different subdirectories on the configuration device. The Lenovo Legion Go is one such device, providing configuration to a detachable left controller, detachable right controller, the wireless transmission dongle, and the MCU. It is therefore beneficial to treat each of these as individual devices in the driver, providing a subdirectory for each physical device in the sysfs. As some attributes are reused by each physical device, it provides a much cleaner interface if the same driver can reuse the same attribute name in sysfs while uniquely distinguishing the store/show functions in the driver, rather than repeat string portions.
Example new WO attrs:
ATTRS{left_handle/reset}=="(not readable)"
ATTRS{right_handle/reset}=="(not readable)"
ATTRS{tx_dongle/reset}=="(not readable)"
vs old WO attrs in a subdir:
ATTRS{left_handle/left_handle_reset}=="(not readable)" ATTRS{right_handle/right_handle_reset}=="(not readable)" ATTRS{tx_dongle/tx_dongle_reset}=="(not readable)"
or old WO attrs with no subdir:
ATTRS{left_handle_reset}=="(not readable)"
ATTRS{right_handle_reset}=="(not readable)"
ATTRS{tx_dongle_reset}=="(not readable)"
While the third option is usable, it doesn't logically break up the physical devices and creates a device directory with over 80 attributes once all attrs are defined.
--- include/linux/device.h | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
include/linux/device.h +46 -0
@@ -189,6 +189,22 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,#define DEVICE_ATTR_ADMIN_RW (_name) \ struct device_attribute dev_attr_##_name = __ATTR_RW_MODE(_name, 0600) +/** +* DEVICE_ATTR_RW_NAMED - Define a read-write device attribute with a sysfs name +* that differs from the function name. +* @_name: Attribute function preface +* @_attrname: Attribute name as it wil be exposed in the sysfs. +* +* Like DEVICE_ATTR_RW(), but allows for reusing names under separate paths in +* the same driver. +*/ +#define DEVICE_ATTR_RW_NAMED (_name, _attrname) \ + struct device_attribute dev_attr_##_name = { \ + .attr = { .name = _attrname, .mode = 0644 }, \ + .show = _name##_show, \ + .store = _name##_store, \ + } +/** * DEVICE_ATTR_RO - Define a readable device attribute. * @_name: Attribute name.
@@ -207,6 +223,21 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,#define DEVICE_ATTR_ADMIN_RO (_name) \ struct device_attribute dev_attr_##_name = __ATTR_RO_MODE(_name, 0400) +/** +* DEVICE_ATTR_RO_NAMED - Define a read-only device attribute with a sysfs name +* that differs from the function name. +* @_name: Attribute function preface +* @_attrname: Attribute name as it wil be exposed in the sysfs. +* +* Like DEVICE_ATTR_RO(), but allows for reusing names under separate paths in +* the same driver. +*/ +#define DEVICE_ATTR_RO_NAMED (_name, _attrname) \ + struct device_attribute dev_attr_##_name = { \ + .attr = { .name = _attrname, .mode = 0444 }, \ + .show = _name##_show, \ + } +/** * DEVICE_ATTR_WO - Define an admin-only writable device attribute. * @_name: Attribute name.
@@ -216,6 +247,21 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr,#define DEVICE_ATTR_WO (_name) \ struct device_attribute dev_attr_##_name = __ATTR_WO(_name) +/** +* DEVICE_ATTR_WO_NAMED - Define a read-only device attribute with a sysfs name +* that differs from the function name. +* @_name: Attribute function preface +* @_attrname: Attribute name as it wil be exposed in the sysfs. +* +* Like DEVICE_ATTR_WO(), but allows for reusing names under separate paths in +* the same driver. +*/ +#define DEVICE_ATTR_WO_NAMED (_name, _attrname) \ + struct device_attribute dev_attr_##_name = { \ + .attr = { .name = _attrname, .mode = 0200 }, \ + .store = _name##_store, \ + } +/** * DEVICE_ULONG_ATTR - Define a device attribute backed by an unsigned long. * @_name: Attribute name.
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 2/19 HID: hid-lenovo-go: Add Lenovo Legion Go Series HID Driver
In reply to Derek J. ClarkAdds initial framework for a new HID driver, hid-lenovo-go, along with attributes that report the firmware and hardware version for each component of the HID device, of which there are 4 parts: The MCU, the transmission dongle, the left "handle" controller half, and the right "handle" controller half. Each of these devices are provided an attribute group to contain its device specific attributes. Additionally, the touchpad device attributes are logically separated from the other components in another attribute group.
This driver primarily provides access to the configurable settings of the Lenovo Legion Go and Lenovo Legion Go 2 controllers running the latest firmware. As previously noted, the Legion Go controllers recently had a firmware update[1] which switched from the original "SepentiaUSB" protocol to a brand new protocol for the Go 2, primarily to ensure backwards and forwards compatibility between the Go and Go 2 devices. As part of that update the PIDs for the controllers were changed, so there is no risk of this driver attaching to controller firmware that it doesn't support.
--
v6:
- Make attributes static.
- Use NULL instead of 0 in mcu_propery_out when there is no data.
v5:
- Make version attributes static, retrieve them using delayed work during probe.
- Fix endianness of version strings and print as hex.
v3:
- Add hid-lenovo.c and Mark Pearson to LENOVO HID DRIVERS entry in MAINTAINERS
--- MAINTAINERS | 8 + drivers/hid/Kconfig | 12 + drivers/hid/Makefile | 1 + drivers/hid/hid-ids.h | 3 + drivers/hid/hid-lenovo-go.c | 914 ++++++++++++++++++++++++++++++++++++ 5 files changed, 938 insertions(+) create mode 100644 drivers/hid/hid-lenovo-go.c
MAINTAINERS +8 -0
@@ -14415,6 +14415,14 @@ L: [email protected] S: Maintained F: drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +LENOVO HID drivers +M: Derek J. Clark <[email protected]> +M: Mark Pearson <[email protected]> +L: [email protected] +S: Maintained +F: drivers/hid/hid-lenovo-go.c +F: drivers/hid/hid-lenovo.c + LETSKETCH HID TABLET DRIVER M: Hans de Goede <[email protected]> L: [email protected]
drivers/hid/Kconfig +12 -0
@@ -623,6 +623,18 @@ config HID_LENOVO - ThinkPad Compact Bluetooth Keyboard with TrackPoint (supports Fn keys) - ThinkPad Compact USB Keyboard with TrackPoint (supports Fn keys) +config HID_LENOVO_GO + tristate "HID Driver for Lenovo Legion Go Series Controllers" + depends on USB_HID + select LEDS_CLASS + select LEDS_CLASS_MULTICOLOR + help + Support for Lenovo Legion Go devices with detachable controllers. + + Say Y here to include configuration interface support for the Lenovo Legion Go + and Legion Go 2 Handheld Console Controllers. Say M here to compile this + driver as a module. The module will be called hid-lenovo-go. + config HID_LETSKETCH tristate "Letsketch WP9620N tablets" depends on USB_HID
drivers/hid/Makefile +1 -0
@@ -76,6 +76,7 @@ obj-$(CONFIG_HID_KYE) += hid-kye.o obj-$(CONFIG_HID_KYSONA) += hid-kysona.o obj-$(CONFIG_HID_LCPOWER) += hid-lcpower.o obj-$(CONFIG_HID_LENOVO) += hid-lenovo.o +obj-$(CONFIG_HID_LENOVO_GO) += hid-lenovo-go.o obj-$(CONFIG_HID_LETSKETCH) += hid-letsketch.o obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o obj-$(CONFIG_HID_LOGITECH) += hid-lg-g15.o
drivers/hid/hid-ids.h +3 -0
@@ -858,7 +858,10 @@#define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_602E 0x602e#define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_6093 0x6093#define USB_DEVICE_ID_LENOVO_LEGION_GO_DUAL_DINPUT 0x6184 +#define USB_DEVICE_ID_LENOVO_LEGION_GO2_XINPUT 0x61eb +#define USB_DEVICE_ID_LENOVO_LEGION_GO2_DINPUT 0x61ec#define USB_DEVICE_ID_LENOVO_LEGION_GO2_DUAL_DINPUT 0x61ed +#define USB_DEVICE_ID_LENOVO_LEGION_GO2_FPS 0x61ee#define USB_VENDOR_ID_LETSKETCH 0x6161#define USB_DEVICE_ID_WP9620N 0x4d15
drivers/hid/hid-lenovo-go.c new file +914 -0
914 lines not on this page · raw message
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 3/19 HID: hid-lenovo-go: Add Feature Status Attributes
In reply to Derek J. ClarkAdds various feature status indicators and toggles to hid-lenovo-go, including the FPS mode switch setting, touchpad enable toggle, handle automatic sleep timer, etc.
---
v6:
- Make local attributes static.
- Use NULL instead of 0 in mcu_propery_out when there is no data.
--- drivers/hid/hid-lenovo-go.c | 396 +++++++++++++++++++++++++++++++++++- 1 file changed, 395 insertions(+), 1 deletion(-)
drivers/hid/hid-lenovo-go.c +395 -1
@@ -39,21 +39,31 @@ static struct hid_go_cfg {struct completion send_cmd_complete;struct hid_device *hdev;struct mutex cfg_mutex;/*ensure single synchronous output report*/ +u8 fps_mode; +u8 gp_left_auto_sleep_time;u32 gp_left_version_firmware;u8 gp_left_version_gen;u32 gp_left_version_hardware;u32 gp_left_version_product;u32 gp_left_version_protocol; +u8 gp_mode; +u8 gp_right_auto_sleep_time;u32 gp_right_version_firmware;u8 gp_right_version_gen;u32 gp_right_version_hardware;u32 gp_right_version_product;u32 gp_right_version_protocol; +u8 imu_left_bypass_en; +u8 imu_left_sensor_en; +u8 imu_right_bypass_en; +u8 imu_right_sensor_en;u32 mcu_version_firmware;u8 mcu_version_gen;u32 mcu_version_hardware;u32 mcu_version_product;u32 mcu_version_protocol; +u8 rgb_en; +u8 tp_en;u32 tx_dongle_version_firmware;u8 tx_dongle_version_gen;u32 tx_dongle_version_hardware;
@@ -105,6 +115,18 @@ enum dev_type { RIGHT_CONTROLLER, }; +enum enabled_status_index { +FEATURE_UNKNOWN , +FEATURE_ENABLED , +FEATURE_DISABLED , +}; + +static const char *const enabled_status_text[] = { + [FEATURE_UNKNOWN ] ="unknown" , + [FEATURE_ENABLED ] ="true" , + [FEATURE_DISABLED ] ="false" , +}; +enum version_data_index {PRODUCT_VERSION =0x02 ,PROTOCOL_VERSION ,
@@ -113,6 +135,41 @@ enum version_data_index { HARDWARE_GENERATION, }; +enum feature_status_index { +FEATURE_RESET_GAMEPAD =0x02 , +FEATURE_IMU_BYPASS , +FEATURE_IMU_ENABLE =0x05 , +FEATURE_TOUCHPAD_ENABLE =0x07 , +FEATURE_LIGHT_ENABLE , +FEATURE_AUTO_SLEEP_TIME , +FEATURE_FPS_SWITCH_STATUS =0x0b , +FEATURE_GAMEPAD_MODE =0x0e , +}; + +enum fps_switch_status_index { +FPS_STATUS_UNKNOWN , +GAMEPAD , +FPS , +}; + +static const char *const fps_switch_text[] = { + [FPS_STATUS_UNKNOWN ] ="unknown" , + [GAMEPAD ] ="gamepad" , + [FPS ] ="fps" , +}; + +enum gamepad_mode_index { +GAMEPAD_MODE_UNKNOWN , +XINPUT , +DINPUT , +}; + +static const char *const gamepad_mode_text[] = { + [GAMEPAD_MODE_UNKNOWN ] ="unknown" , + [XINPUT ] ="xinput" , + [DINPUT ] ="dinput" , +}; +static int hid_go_version_event (struct command_report *cmd_rep) {switch (cmd_rep->sub_cmd) {
@@ -222,6 +279,71 @@ static int hid_go_version_event(struct command_report *cmd_rep) } } +static int hid_go_feature_status_event (struct command_report *cmd_rep) +{ +switch (cmd_rep->sub_cmd) { +case FEATURE_RESET_GAMEPAD : +return 0 ; +case FEATURE_IMU_ENABLE : +switch (cmd_rep->device_type) { +case LEFT_CONTROLLER : + drvdata.imu_left_sensor_en = cmd_rep->data[0 ]; +return 0 ; +case RIGHT_CONTROLLER : + drvdata.imu_right_sensor_en = cmd_rep->data[0 ]; +return 0 ; +default : +return -EINVAL ; + }; +case FEATURE_IMU_BYPASS : +switch (cmd_rep->device_type) { +case LEFT_CONTROLLER : + drvdata.imu_left_bypass_en = cmd_rep->data[0 ]; +return 0 ; +case RIGHT_CONTROLLER : + drvdata.imu_right_bypass_en = cmd_rep->data[0 ]; +return 0 ; +default : +return -EINVAL ; + }; +break ; +case FEATURE_LIGHT_ENABLE : + drvdata.rgb_en = cmd_rep->data[0 ]; +return 0 ; +case FEATURE_AUTO_SLEEP_TIME : +switch (cmd_rep->device_type) { +case LEFT_CONTROLLER : + drvdata.gp_left_auto_sleep_time = cmd_rep->data[0 ]; +return 0 ; +case RIGHT_CONTROLLER : + drvdata.gp_right_auto_sleep_time = cmd_rep->data[0 ]; +return 0 ; +default : +return -EINVAL ; + }; +break ; +case FEATURE_TOUCHPAD_ENABLE : + drvdata.tp_en = cmd_rep->data[0 ]; +return 0 ; +case FEATURE_GAMEPAD_MODE : + drvdata.gp_mode = cmd_rep->data[0 ]; +return 0 ; +case FEATURE_FPS_SWITCH_STATUS : + drvdata.fps_mode = cmd_rep->data[0 ]; +return 0 ; +default : +return -EINVAL ; + } +} + +static int hid_go_set_event_return (struct command_report *cmd_rep) +{ +if (cmd_rep->data[0 ] !=0 ) +return -EIO ; + +return 0 ; +} +static int get_endpoint_address (struct hid_device *hdev) {struct usb_interface *intf =to_usb_interface (hdev->dev.parent);
@@ -258,6 +380,12 @@ static int hid_go_raw_event(struct hid_device *hdev, struct hid_report *report,case GET_VERSION_DATA : ret =hid_go_version_event (cmd_rep);break ; +case GET_FEATURE_STATUS : + ret =hid_go_feature_status_event (cmd_rep); +break ; +case SET_FEATURE_STATUS : + ret =hid_go_set_event_return (cmd_rep); +break ;default : ret = -EINVAL ;break ;
@@ -442,6 +570,195 @@ static ssize_t version_show(struct device *dev, struct device_attribute *attr,return count; } +static ssize_t feature_status_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count, +enum feature_status_index index, +enum dev_type device_type) +{ +size_t size =1 ; +u8 val =0 ; +int ret; + +switch (index) { +case FEATURE_IMU_ENABLE : +case FEATURE_IMU_BYPASS : +case FEATURE_LIGHT_ENABLE : +case FEATURE_TOUCHPAD_ENABLE : + ret =sysfs_match_string (enabled_status_text, buf); + val = ret; +break ; +case FEATURE_AUTO_SLEEP_TIME : + ret =kstrtou8 (buf,10 , &val); +break ; +case FEATURE_RESET_GAMEPAD : + ret =kstrtou8 (buf,10 , &val); +if (val !=GO_GP_RESET_SUCCESS ) +return -EINVAL ; +break ; +case FEATURE_FPS_SWITCH_STATUS : + ret =sysfs_match_string (fps_switch_text, buf); + val = ret; +break ; +case FEATURE_GAMEPAD_MODE : + ret =sysfs_match_string (gamepad_mode_text, buf); + val = ret; +break ; +default : +return -EINVAL ; + }; + +if (ret <0 ) +return ret; + +if (!val) + size =0 ; + + ret =mcu_property_out (drvdata.hdev,MCU_CONFIG_DATA , +SET_FEATURE_STATUS , index, device_type, &val, + size); +if (ret <0 ) +return ret; + +return count; +} + +static ssize_t feature_status_show (struct device *dev, +struct device_attribute *attr,char *buf, +enum feature_status_index index, +enum dev_type device_type) +{ +ssize_t count =0 ; +int ret; +u8 i; + + ret =mcu_property_out (drvdata.hdev,MCU_CONFIG_DATA , +GET_FEATURE_STATUS , index, device_type,NULL ,0 ); +if (ret) +return ret; + +switch (index) { +case FEATURE_IMU_ENABLE : +switch (device_type) { +case LEFT_CONTROLLER : + i = drvdata.imu_left_sensor_en; +break ; +case RIGHT_CONTROLLER : + i = drvdata.imu_right_sensor_en; +break ; +default : +return -EINVAL ; + } +if (i >=ARRAY_SIZE (enabled_status_text)) +return -EINVAL ; + + count =sysfs_emit (buf,"%s\n" , enabled_status_text[i]); +break ; +case FEATURE_IMU_BYPASS : +switch (device_type) { +case LEFT_CONTROLLER : + i = drvdata.imu_left_bypass_en; +break ; +case RIGHT_CONTROLLER : + i = drvdata.imu_right_bypass_en; +break ; +default : +return -EINVAL ; + } +if (i >=ARRAY_SIZE (enabled_status_text)) +return -EINVAL ; + + count =sysfs_emit (buf,"%s\n" , enabled_status_text[i]); +break ; +case FEATURE_LIGHT_ENABLE : + i = drvdata.rgb_en; +if (i >=ARRAY_SIZE (enabled_status_text)) +return -EINVAL ; + + count =sysfs_emit (buf,"%s\n" , enabled_status_text[i]); +break ; +case FEATURE_TOUCHPAD_ENABLE : + i = drvdata.tp_en; +if (i >=ARRAY_SIZE (enabled_status_text)) +return -EINVAL ; + + count =sysfs_emit (buf,"%s\n" , enabled_status_text[i]); +break ; +case FEATURE_AUTO_SLEEP_TIME : +switch (device_type) { +case LEFT_CONTROLLER : + i = drvdata.gp_left_auto_sleep_time; +break ; +case RIGHT_CONTROLLER : + i = drvdata.gp_right_auto_sleep_time; +break ; +default : +return -EINVAL ; + }; + count =sysfs_emit (buf,"%u\n" , i); +break ; +case FEATURE_FPS_SWITCH_STATUS : + i = drvdata.fps_mode; +if (i >=ARRAY_SIZE (fps_switch_text)) +return -EINVAL ; + + count =sysfs_emit (buf,"%s\n" , fps_switch_text[i]); +break ; +case FEATURE_GAMEPAD_MODE : + i = drvdata.gp_mode; +if (i >=ARRAY_SIZE (gamepad_mode_text)) +return -EINVAL ; + + count =sysfs_emit (buf,"%s\n" , gamepad_mode_text[i]); +break ; +default : +return -EINVAL ; + }; + +return count; +} + +static ssize_t feature_status_options (struct device *dev, +struct device_attribute *attr,char *buf, +enum feature_status_index index) +{ +ssize_t count =0 ; +unsigned int i; + +switch (index) { +case FEATURE_IMU_ENABLE : +case FEATURE_IMU_BYPASS : +case FEATURE_LIGHT_ENABLE : +case FEATURE_TOUCHPAD_ENABLE : +for (i =1 ; i <ARRAY_SIZE (enabled_status_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + enabled_status_text[i]); + } +break ; +case FEATURE_AUTO_SLEEP_TIME : +return sysfs_emit (buf,"0-255\n" ); +case FEATURE_FPS_SWITCH_STATUS : +for (i =1 ; i <ARRAY_SIZE (fps_switch_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + fps_switch_text[i]); + } +break ; +case FEATURE_GAMEPAD_MODE : +for (i =1 ; i <ARRAY_SIZE (gamepad_mode_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + gamepad_mode_text[i]); + } +break ; +default : +return -EINVAL ; + }; + +if (count) + buf[count -1 ] ='\n' ; + +return count; +} +#define LEGO_DEVICE_ATTR_RW (_name, _attrname, _dtype, _rtype, _group) \ static ssize_t _name##_store(struct device *dev, \ struct device_attribute *attr, \
@@ -496,7 +813,22 @@ LEGO_DEVICE_ATTR_RO(version_hardware_mcu, "hardware_version", USB_MCU, version);static struct go_cfg_attr version_gen_mcu = {HARDWARE_GENERATION };LEGO_DEVICE_ATTR_RO (version_gen_mcu,"hardware_generation" ,USB_MCU , version); +static struct go_cfg_attr fps_switch_status = {FEATURE_FPS_SWITCH_STATUS }; +LEGO_DEVICE_ATTR_RO (fps_switch_status,"fps_switch_status" ,UNSPECIFIED , + feature_status); + +static struct go_cfg_attr gamepad_mode = {FEATURE_GAMEPAD_MODE }; +LEGO_DEVICE_ATTR_RW (gamepad_mode,"mode" ,UNSPECIFIED , index, feature_status); +static DEVICE_ATTR_RO_NAMED(gamepad_mode_index, "mode_index"); + +static struct go_cfg_attr reset_mcu = {FEATURE_RESET_GAMEPAD }; +LEGO_DEVICE_ATTR_WO (reset_mcu,"reset_mcu" ,USB_MCU , feature_status); +static struct attribute *mcu_attrs[] = { + &dev_attr_fps_switch_status.attr, + &dev_attr_gamepad_mode.attr, + &dev_attr_gamepad_mode_index.attr, + &dev_attr_reset_mcu.attr, &dev_attr_version_firmware_mcu.attr, &dev_attr_version_gen_mcu.attr, &dev_attr_version_hardware_mcu.attr,
@@ -525,7 +857,11 @@ LEGO_DEVICE_ATTR_RO(version_hardware_tx_dongle, "hardware_version", TX_DONGLE, vstatic struct go_cfg_attr version_gen_tx_dongle = {HARDWARE_GENERATION };LEGO_DEVICE_ATTR_RO (version_gen_tx_dongle,"hardware_generation" ,TX_DONGLE , version); +static struct go_cfg_attr reset_tx_dongle = {FEATURE_RESET_GAMEPAD }; +LEGO_DEVICE_ATTR_RO (reset_tx_dongle,"reset" ,TX_DONGLE , feature_status); +static struct attribute *tx_dongle_attrs[] = { + &dev_attr_reset_tx_dongle.attr, &dev_attr_version_hardware_tx_dongle.attr, &dev_attr_version_firmware_tx_dongle.attr, &dev_attr_version_gen_tx_dongle.attr,
@@ -555,7 +891,33 @@ LEGO_DEVICE_ATTR_RO(version_hardware_left, "hardware_version", LEFT_CONTROLLER,static struct go_cfg_attr version_gen_left = {HARDWARE_GENERATION };LEGO_DEVICE_ATTR_RO (version_gen_left,"hardware_generation" ,LEFT_CONTROLLER , version); +static struct go_cfg_attr auto_sleep_time_left = {FEATURE_AUTO_SLEEP_TIME }; +LEGO_DEVICE_ATTR_RW (auto_sleep_time_left,"auto_sleep_time" ,LEFT_CONTROLLER , + range, feature_status); +static DEVICE_ATTR_RO_NAMED(auto_sleep_time_left_range, + "auto_sleep_time_range"); + +static struct go_cfg_attr imu_bypass_left = {FEATURE_IMU_BYPASS }; +LEGO_DEVICE_ATTR_RW (imu_bypass_left,"imu_bypass_enabled" ,LEFT_CONTROLLER , + index, feature_status); +static DEVICE_ATTR_RO_NAMED(imu_bypass_left_index, "imu_bypass_enabled_index"); + +static struct go_cfg_attr imu_enabled_left = {FEATURE_IMU_ENABLE }; +LEGO_DEVICE_ATTR_RW (imu_enabled_left,"imu_enabled" ,LEFT_CONTROLLER , index, + feature_status); +static DEVICE_ATTR_RO_NAMED(imu_enabled_left_index, "imu_enabled_index"); + +static struct go_cfg_attr reset_left = {FEATURE_RESET_GAMEPAD }; +LEGO_DEVICE_ATTR_WO (reset_left,"reset" ,LEFT_CONTROLLER , feature_status); +static struct attribute *left_gamepad_attrs[] = { + &dev_attr_auto_sleep_time_left.attr, + &dev_attr_auto_sleep_time_left_range.attr, + &dev_attr_imu_bypass_left.attr, + &dev_attr_imu_bypass_left_index.attr, + &dev_attr_imu_enabled_left.attr, + &dev_attr_imu_enabled_left_index.attr, + &dev_attr_reset_left.attr, &dev_attr_version_hardware_left.attr, &dev_attr_version_firmware_left.attr, &dev_attr_version_gen_left.attr,
@@ -585,7 +947,33 @@ LEGO_DEVICE_ATTR_RO(version_hardware_right, "hardware_version", RIGHT_CONTROLLERstatic struct go_cfg_attr version_gen_right = {HARDWARE_GENERATION };LEGO_DEVICE_ATTR_RO (version_gen_right,"hardware_generation" ,RIGHT_CONTROLLER , version); +static struct go_cfg_attr auto_sleep_time_right = {FEATURE_AUTO_SLEEP_TIME }; +LEGO_DEVICE_ATTR_RW (auto_sleep_time_right,"auto_sleep_time" ,RIGHT_CONTROLLER , + range, feature_status); +static DEVICE_ATTR_RO_NAMED(auto_sleep_time_right_range, + "auto_sleep_time_range"); + +static struct go_cfg_attr imu_bypass_right = {FEATURE_IMU_BYPASS }; +LEGO_DEVICE_ATTR_RW (imu_bypass_right,"imu_bypass_enabled" ,RIGHT_CONTROLLER , + index, feature_status); +static DEVICE_ATTR_RO_NAMED(imu_bypass_right_index, "imu_bypass_enabled_index"); + +static struct go_cfg_attr imu_enabled_right = {FEATURE_IMU_BYPASS }; +LEGO_DEVICE_ATTR_RW (imu_enabled_right,"imu_enabled" ,RIGHT_CONTROLLER , index, + feature_status); +static DEVICE_ATTR_RO_NAMED(imu_enabled_right_index, "imu_enabled_index"); + +static struct go_cfg_attr reset_right = {FEATURE_RESET_GAMEPAD }; +LEGO_DEVICE_ATTR_WO (reset_right,"reset" ,LEFT_CONTROLLER , feature_status); +static struct attribute *right_gamepad_attrs[] = { + &dev_attr_auto_sleep_time_right.attr, + &dev_attr_auto_sleep_time_right_range.attr, + &dev_attr_imu_bypass_right.attr, + &dev_attr_imu_bypass_right_index.attr, + &dev_attr_imu_enabled_right.attr, + &dev_attr_imu_enabled_right_index.attr, + &dev_attr_reset_right.attr, &dev_attr_version_hardware_right.attr, &dev_attr_version_firmware_right.attr, &dev_attr_version_gen_right.attr,
@@ -600,8 +988,14 @@ static const struct attribute_group right_gamepad_attr_group = { };/* Touchpad */ +static struct go_cfg_attr touchpad_enabled = {FEATURE_TOUCHPAD_ENABLE }; +LEGO_DEVICE_ATTR_RW (touchpad_enabled,"enabled" ,UNSPECIFIED , index, + feature_status); +static DEVICE_ATTR_RO_NAMED(touchpad_enabled_index, "enabled_index"); +static struct attribute *touchpad_attrs[] = { -NULL , + &dev_attr_touchpad_enabled.attr, + &dev_attr_touchpad_enabled_index.attr, };static const struct attribute_group touchpad_attr_group = {
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 4/19 HID: hid-lenovo-go: Add Rumble and Haptic Settings
In reply to Derek J. ClarkAdds attributes that control the handles rumble mode and intensity, as well as touchpad haptic feedback settings.
---
v6:
- Make local attributes static.
- Use NULL instead of 0 in mcu_propery_out when there is no data.
v3:
- Remove erroneous renaming of enabled -> enable for some left & right handle attributes.
--- drivers/hid/hid-lenovo-go.c | 312 ++++++++++++++++++++++++++++++++++++ 1 file changed, 312 insertions(+)
drivers/hid/hid-lenovo-go.c +312 -0
@@ -41,6 +41,8 @@ static struct hid_go_cfg {struct mutex cfg_mutex;/*ensure single synchronous output report*/ u8 fps_mode;u8 gp_left_auto_sleep_time; +u8 gp_left_notify_en; +u8 gp_left_rumble_mode;u32 gp_left_version_firmware;u8 gp_left_version_gen;u32 gp_left_version_hardware;
@@ -48,11 +50,14 @@ static struct hid_go_cfg {u32 gp_left_version_protocol;u8 gp_mode;u8 gp_right_auto_sleep_time; +u8 gp_right_notify_en; +u8 gp_right_rumble_mode;u32 gp_right_version_firmware;u8 gp_right_version_gen;u32 gp_right_version_hardware;u32 gp_right_version_product;u32 gp_right_version_protocol; +u8 gp_rumble_intensity;u8 imu_left_bypass_en;u8 imu_left_sensor_en;u8 imu_right_bypass_en;
@@ -64,6 +69,8 @@ static struct hid_go_cfg {u32 mcu_version_protocol;u8 rgb_en;u8 tp_en; +u8 tp_vibration_en; +u8 tp_vibration_intensity;u32 tx_dongle_version_firmware;u8 tx_dongle_version_gen;u32 tx_dongle_version_hardware;
@@ -170,6 +177,49 @@ static const char *const gamepad_mode_text[] = { [DINPUT] = "dinput", }; +enum motor_cfg_index { +MOTOR_CFG_ALL =0x01 , +MOTOR_INTENSITY , +VIBRATION_NOTIFY_ENABLE , +RUMBLE_MODE , +TP_VIBRATION_ENABLE , +TP_VIBRATION_INTENSITY , +}; + +enum intensity_index { +INTENSITY_UNKNOWN , +INTENSITY_OFF , +INTENSITY_LOW , +INTENSITY_MEDIUM , +INTENSITY_HIGH , +}; + +static const char *const intensity_text[] = { + [INTENSITY_UNKNOWN ] ="unknown" , + [INTENSITY_OFF ] ="off" , + [INTENSITY_LOW ] ="low" , + [INTENSITY_MEDIUM ] ="medium" , + [INTENSITY_HIGH ] ="high" , +}; + +enum rumble_mode_index { +RUMBLE_MODE_UNKNOWN , +RUMBLE_MODE_FPS , +RUMBLE_MODE_RACE , +RUMBLE_MODE_AVERAGE , +RUMBLE_MODE_SPG , +RUMBLE_MODE_RPG , +}; + +static const char *const rumble_mode_text[] = { + [RUMBLE_MODE_UNKNOWN ] ="unknown" , + [RUMBLE_MODE_FPS ] ="fps" , + [RUMBLE_MODE_RACE ] ="racing" , + [RUMBLE_MODE_AVERAGE ] ="standard" , + [RUMBLE_MODE_SPG ] ="spg" , + [RUMBLE_MODE_RPG ] ="rpg" , +}; +static int hid_go_version_event (struct command_report *cmd_rep) {switch (cmd_rep->sub_cmd) {
@@ -336,6 +386,47 @@ static int hid_go_feature_status_event(struct command_report *cmd_rep) } } +static int hid_go_motor_event (struct command_report *cmd_rep) +{ +switch (cmd_rep->sub_cmd) { +case MOTOR_CFG_ALL : +return -EINVAL ; +case MOTOR_INTENSITY : + drvdata.gp_rumble_intensity = cmd_rep->data[0 ]; +return 0 ; +case VIBRATION_NOTIFY_ENABLE : +switch (cmd_rep->device_type) { +case LEFT_CONTROLLER : + drvdata.gp_left_notify_en = cmd_rep->data[0 ]; +return 0 ; +case RIGHT_CONTROLLER : + drvdata.gp_right_notify_en = cmd_rep->data[0 ]; +return 0 ; +default : +return -EINVAL ; + }; +break ; +case RUMBLE_MODE : +switch (cmd_rep->device_type) { +case LEFT_CONTROLLER : + drvdata.gp_left_rumble_mode = cmd_rep->data[0 ]; +return 0 ; +case RIGHT_CONTROLLER : + drvdata.gp_right_rumble_mode = cmd_rep->data[0 ]; +return 0 ; +default : +return -EINVAL ; + }; +case TP_VIBRATION_ENABLE : + drvdata.tp_vibration_en = cmd_rep->data[0 ]; +return 0 ; +case TP_VIBRATION_INTENSITY : + drvdata.tp_vibration_intensity = cmd_rep->data[0 ]; +return 0 ; + } +return -EINVAL ; +} +static int hid_go_set_event_return (struct command_report *cmd_rep) {if (cmd_rep->data[0 ] !=0 )
@@ -383,7 +474,11 @@ static int hid_go_raw_event(struct hid_device *hdev, struct hid_report *report,case GET_FEATURE_STATUS : ret =hid_go_feature_status_event (cmd_rep);break ; +case GET_MOTOR_CFG : + ret =hid_go_motor_event (cmd_rep); +break ;case SET_FEATURE_STATUS : +case SET_MOTOR_CFG : ret =hid_go_set_event_return (cmd_rep);break ;default :
@@ -759,6 +854,168 @@ static ssize_t feature_status_options(struct device *dev,return count; } +static ssize_t motor_config_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count, +enum motor_cfg_index index, +enum dev_type device_type) +{ +size_t size =1 ; +u8 val =0 ; +int ret; + +switch (index) { +case MOTOR_CFG_ALL : +return -EINVAL ; +case MOTOR_INTENSITY : + ret =sysfs_match_string (intensity_text, buf); + val = ret; +break ; +case VIBRATION_NOTIFY_ENABLE : + ret =sysfs_match_string (enabled_status_text, buf); + val = ret; +break ; +case RUMBLE_MODE : + ret =sysfs_match_string (rumble_mode_text, buf); + val = ret; +break ; +case TP_VIBRATION_ENABLE : + ret =sysfs_match_string (enabled_status_text, buf); + val = ret; +break ; +case TP_VIBRATION_INTENSITY : + ret =sysfs_match_string (intensity_text, buf); + val = ret; +break ; + }; + +if (ret <0 ) +return ret; + +if (!val) + size =0 ; + + ret =mcu_property_out (drvdata.hdev,MCU_CONFIG_DATA ,SET_MOTOR_CFG , + index, device_type, &val, size); +if (ret <0 ) +return ret; + +return count; +} + +static ssize_t motor_config_show (struct device *dev, +struct device_attribute *attr,char *buf, +enum motor_cfg_index index, +enum dev_type device_type) +{ +ssize_t count =0 ; +int ret; +u8 i; + + ret =mcu_property_out (drvdata.hdev,MCU_CONFIG_DATA ,GET_MOTOR_CFG , + index, device_type,NULL ,0 ); +if (ret) +return ret; + +switch (index) { +case MOTOR_CFG_ALL : +return -EINVAL ; +case MOTOR_INTENSITY : + i = drvdata.gp_rumble_intensity; +if (i >=ARRAY_SIZE (intensity_text)) +return -EINVAL ; + + count =sysfs_emit (buf,"%s\n" , intensity_text[i]); +break ; +case VIBRATION_NOTIFY_ENABLE : +switch (device_type) { +case LEFT_CONTROLLER : + i = drvdata.gp_left_notify_en; +break ; +case RIGHT_CONTROLLER : + i = drvdata.gp_right_notify_en; +break ; +default : +return -EINVAL ; + }; +if (i >=ARRAY_SIZE (enabled_status_text)) +return -EINVAL ; + + count =sysfs_emit (buf,"%s\n" , enabled_status_text[i]); +break ; +case RUMBLE_MODE : +switch (device_type) { +case LEFT_CONTROLLER : + i = drvdata.gp_left_rumble_mode; +break ; +case RIGHT_CONTROLLER : + i = drvdata.gp_right_rumble_mode; +break ; +default : +return -EINVAL ; + }; +if (i >=ARRAY_SIZE (rumble_mode_text)) +return -EINVAL ; + + count =sysfs_emit (buf,"%s\n" , rumble_mode_text[i]); +break ; +case TP_VIBRATION_ENABLE : + i = drvdata.tp_vibration_en; +if (i >=ARRAY_SIZE (enabled_status_text)) +return -EINVAL ; + + count =sysfs_emit (buf,"%s\n" , enabled_status_text[i]); +break ; +case TP_VIBRATION_INTENSITY : + i = drvdata.tp_vibration_intensity; +if (i >=ARRAY_SIZE (intensity_text)) +return -EINVAL ; + + count =sysfs_emit (buf,"%s\n" , intensity_text[i]); +break ; + }; + +return count; +} + +static ssize_t motor_config_options (struct device *dev, +struct device_attribute *attr,char *buf, +enum motor_cfg_index index) +{ +ssize_t count =0 ; +unsigned int i; + +switch (index) { +case MOTOR_CFG_ALL : +break ; +case RUMBLE_MODE : +for (i =1 ; i <ARRAY_SIZE (rumble_mode_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + rumble_mode_text[i]); + } +break ; +case MOTOR_INTENSITY : +case TP_VIBRATION_INTENSITY : +for (i =1 ; i <ARRAY_SIZE (intensity_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + intensity_text[i]); + } +break ; +case VIBRATION_NOTIFY_ENABLE : +case TP_VIBRATION_ENABLE : +for (i =1 ; i <ARRAY_SIZE (enabled_status_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + enabled_status_text[i]); + } +break ; + }; + +if (count) + buf[count -1 ] ='\n' ; + +return count; +} +#define LEGO_DEVICE_ATTR_RW (_name, _attrname, _dtype, _rtype, _group) \ static ssize_t _name##_store(struct device *dev, \ struct device_attribute *attr, \
@@ -824,10 +1081,18 @@ static DEVICE_ATTR_RO_NAMED(gamepad_mode_index, "mode_index");static struct go_cfg_attr reset_mcu = {FEATURE_RESET_GAMEPAD };LEGO_DEVICE_ATTR_WO (reset_mcu,"reset_mcu" ,USB_MCU , feature_status); +static struct go_cfg_attr gamepad_rumble_intensity = {MOTOR_INTENSITY }; +LEGO_DEVICE_ATTR_RW (gamepad_rumble_intensity,"rumble_intensity" ,UNSPECIFIED , + index, motor_config); +static DEVICE_ATTR_RO_NAMED(gamepad_rumble_intensity_index, + "rumble_intensity_index"); +static struct attribute *mcu_attrs[] = { &dev_attr_fps_switch_status.attr, &dev_attr_gamepad_mode.attr, &dev_attr_gamepad_mode_index.attr, + &dev_attr_gamepad_rumble_intensity.attr, + &dev_attr_gamepad_rumble_intensity_index.attr, &dev_attr_reset_mcu.attr, &dev_attr_version_firmware_mcu.attr, &dev_attr_version_gen_mcu.attr,
@@ -910,6 +1175,17 @@ static DEVICE_ATTR_RO_NAMED(imu_enabled_left_index, "imu_enabled_index");static struct go_cfg_attr reset_left = {FEATURE_RESET_GAMEPAD };LEGO_DEVICE_ATTR_WO (reset_left,"reset" ,LEFT_CONTROLLER , feature_status); +static struct go_cfg_attr rumble_mode_left = {RUMBLE_MODE }; +LEGO_DEVICE_ATTR_RW (rumble_mode_left,"rumble_mode" ,LEFT_CONTROLLER , index, + motor_config); +static DEVICE_ATTR_RO_NAMED(rumble_mode_left_index, "rumble_mode_index"); + +static struct go_cfg_attr rumble_notification_left = {VIBRATION_NOTIFY_ENABLE }; +LEGO_DEVICE_ATTR_RW (rumble_notification_left,"rumble_notification" , +LEFT_CONTROLLER , index, motor_config); +static DEVICE_ATTR_RO_NAMED(rumble_notification_left_index, + "rumble_notification_index"); +static struct attribute *left_gamepad_attrs[] = { &dev_attr_auto_sleep_time_left.attr, &dev_attr_auto_sleep_time_left_range.attr,
@@ -918,6 +1194,10 @@ static struct attribute *left_gamepad_attrs[] = { &dev_attr_imu_enabled_left.attr, &dev_attr_imu_enabled_left_index.attr, &dev_attr_reset_left.attr, + &dev_attr_rumble_mode_left.attr, + &dev_attr_rumble_mode_left_index.attr, + &dev_attr_rumble_notification_left.attr, + &dev_attr_rumble_notification_left_index.attr, &dev_attr_version_hardware_left.attr, &dev_attr_version_firmware_left.attr, &dev_attr_version_gen_left.attr,
@@ -966,6 +1246,17 @@ static DEVICE_ATTR_RO_NAMED(imu_enabled_right_index, "imu_enabled_index");static struct go_cfg_attr reset_right = {FEATURE_RESET_GAMEPAD };LEGO_DEVICE_ATTR_WO (reset_right,"reset" ,LEFT_CONTROLLER , feature_status); +static struct go_cfg_attr rumble_mode_right = {RUMBLE_MODE }; +LEGO_DEVICE_ATTR_RW (rumble_mode_right,"rumble_mode" ,RIGHT_CONTROLLER , index, + motor_config); +static DEVICE_ATTR_RO_NAMED(rumble_mode_right_index, "rumble_mode_index"); + +static struct go_cfg_attr rumble_notification_right = {VIBRATION_NOTIFY_ENABLE }; +LEGO_DEVICE_ATTR_RW (rumble_notification_right,"rumble_notification" , +RIGHT_CONTROLLER , index, motor_config); +static DEVICE_ATTR_RO_NAMED(rumble_notification_right_index, + "rumble_notification_index"); +static struct attribute *right_gamepad_attrs[] = { &dev_attr_auto_sleep_time_right.attr, &dev_attr_auto_sleep_time_right_range.attr,
@@ -974,6 +1265,10 @@ static struct attribute *right_gamepad_attrs[] = { &dev_attr_imu_enabled_right.attr, &dev_attr_imu_enabled_right_index.attr, &dev_attr_reset_right.attr, + &dev_attr_rumble_mode_right.attr, + &dev_attr_rumble_mode_right_index.attr, + &dev_attr_rumble_notification_right.attr, + &dev_attr_rumble_notification_right_index.attr, &dev_attr_version_hardware_right.attr, &dev_attr_version_firmware_right.attr, &dev_attr_version_gen_right.attr,
@@ -993,9 +1288,26 @@ LEGO_DEVICE_ATTR_RW(touchpad_enabled, "enabled", UNSPECIFIED, index, feature_status); static DEVICE_ATTR_RO_NAMED(touchpad_enabled_index, "enabled_index"); +static struct go_cfg_attr touchpad_vibration_enabled = {TP_VIBRATION_ENABLE }; +LEGO_DEVICE_ATTR_RW (touchpad_vibration_enabled,"vibration_enabled" ,UNSPECIFIED , + index, motor_config); +static DEVICE_ATTR_RO_NAMED(touchpad_vibration_enabled_index, + "vibration_enabled_index"); + +static struct go_cfg_attr touchpad_vibration_intensity = {TP_VIBRATION_INTENSITY }; +LEGO_DEVICE_ATTR_RW (touchpad_vibration_intensity,"vibration_intensity" , +UNSPECIFIED , index, motor_config); +static DEVICE_ATTR_RO_NAMED(touchpad_vibration_intensity_index, + "vibration_intensity_index"); +static struct attribute *touchpad_attrs[] = { &dev_attr_touchpad_enabled.attr, &dev_attr_touchpad_enabled_index.attr, + &dev_attr_touchpad_vibration_enabled.attr, + &dev_attr_touchpad_vibration_enabled_index.attr, + &dev_attr_touchpad_vibration_intensity.attr, + &dev_attr_touchpad_vibration_intensity_index.attr, +NULL , };static const struct attribute_group touchpad_attr_group = {
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 5/19 HID: hid-lenovo-go: Add FPS Mode DPI settings
In reply to Derek J. ClarkAdds attribute that enables selection of the DPI of the optical sensor when the right handle toggle is set to FPS mode.
---
v6:
- Use NULL instead of 0 in mcu_propery_out when there is no data.
--- drivers/hid/hid-lenovo-go.c | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
drivers/hid/hid-lenovo-go.c +68 -0
@@ -67,6 +67,7 @@ static struct hid_go_cfg {u32 mcu_version_hardware;u32 mcu_version_product;u32 mcu_version_protocol; +u32 mouse_dpi;u8 rgb_en;u8 tp_en;u8 tp_vibration_en;
@@ -220,6 +221,8 @@ static const char *const rumble_mode_text[] = { [RUMBLE_MODE_RPG] = "rpg", }; +#define FPS_MODE_DPI 0x02 +static int hid_go_version_event (struct command_report *cmd_rep) {switch (cmd_rep->sub_cmd) {
@@ -427,6 +430,16 @@ static int hid_go_motor_event(struct command_report *cmd_rep)return -EINVAL ; } +static int hid_go_fps_dpi_event (struct command_report *cmd_rep) +{ +if (cmd_rep->sub_cmd !=FPS_MODE_DPI ) +return -EINVAL ; + + drvdata.mouse_dpi =get_unaligned_le32 (cmd_rep->data); + +return 0 ; +} +static int hid_go_set_event_return (struct command_report *cmd_rep) {if (cmd_rep->data[0 ] !=0 )
@@ -477,8 +490,12 @@ static int hid_go_raw_event(struct hid_device *hdev, struct hid_report *report,case GET_MOTOR_CFG : ret =hid_go_motor_event (cmd_rep);break ; +case GET_DPI_CFG : + ret =hid_go_fps_dpi_event (cmd_rep); +break ;case SET_FEATURE_STATUS :case SET_MOTOR_CFG : +case SET_DPI_CFG : ret =hid_go_set_event_return (cmd_rep);break ;default :
@@ -1016,6 +1033,52 @@ static ssize_t motor_config_options(struct device *dev,return count; } +static ssize_t fps_mode_dpi_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) + +{ +size_t size =4 ; +u32 value; +u8 val[4 ]; +int ret; + + ret =kstrtou32 (buf,10 , &value); +if (ret) +return ret; + +if (value !=500 && value !=800 && value !=1200 && value !=1800 ) +return -EINVAL ; + +put_unaligned_le32 (value, val); + + ret =mcu_property_out (drvdata.hdev,MCU_CONFIG_DATA ,SET_DPI_CFG , +FPS_MODE_DPI ,UNSPECIFIED , val, size); +if (ret <0 ) +return ret; + +return count; +} + +static ssize_t fps_mode_dpi_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +int ret; + + ret =mcu_property_out (drvdata.hdev,MCU_CONFIG_DATA ,GET_DPI_CFG , +FPS_MODE_DPI ,UNSPECIFIED ,NULL ,0 ); +if (ret <0 ) +return ret; + +return sysfs_emit (buf,"%u\n" , drvdata.mouse_dpi); +} + +static ssize_t fps_mode_dpi_index_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"500 800 1200 1800\n" ); +} +#define LEGO_DEVICE_ATTR_RW (_name, _attrname, _dtype, _rtype, _group) \ static ssize_t _name##_store(struct device *dev, \ struct device_attribute *attr, \
@@ -1087,7 +1150,12 @@ LEGO_DEVICE_ATTR_RW(gamepad_rumble_intensity, "rumble_intensity", UNSPECIFIED, static DEVICE_ATTR_RO_NAMED(gamepad_rumble_intensity_index, "rumble_intensity_index"); +static DEVICE_ATTR_RW (fps_mode_dpi); +static DEVICE_ATTR_RO (fps_mode_dpi_index); +static struct attribute *mcu_attrs[] = { + &dev_attr_fps_mode_dpi.attr, + &dev_attr_fps_mode_dpi_index.attr, &dev_attr_fps_switch_status.attr, &dev_attr_gamepad_mode.attr, &dev_attr_gamepad_mode_index.attr,
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 6/19 HID: hid-lenovo-go: Add RGB LED control interface
In reply to Derek J. ClarkAdds an LED multicolor class device and attribute group for controlling the RGB of the Left and right handles. In addition to the standard led_cdev attributes, additional attributes that allow for the control of the effect (monocolor, breathe, rainbow, and chroma), speed of the effect change, an enable toggle, and profile.
---
v6:
- Invert the rgb_speed logic so larger number is faster.
- Make local attributes static.
- Use NULL instead of 0 in mcu_propery_out when there is no data.
v5:
- Don't retrieve RGB state during delayed work.
--- drivers/hid/hid-lenovo-go.c | 429 ++++++++++++++++++++++++++++++++++++ 1 file changed, 429 insertions(+)
drivers/hid/hid-lenovo-go.c +429 -0
@@ -18,6 +18,7 @@#include <linux/hid.h> #include <linux/jiffies.h> #include <linux/kstrtox.h> +#include <linux/led-class-multicolor.h> #include <linux/mutex.h> #include <linux/printk.h> #include <linux/sysfs.h>
@@ -37,6 +38,7 @@ static struct hid_go_cfg { struct delayed_work go_cfg_setup; struct completion send_cmd_complete; + struct led_classdev *led_cdev; struct hid_device *hdev; struct mutex cfg_mutex; /*ensure single synchronous output report*/ u8 fps_mode;
@@ -68,7 +70,11 @@ static struct hid_go_cfg {u32 mcu_version_product;u32 mcu_version_protocol;u32 mouse_dpi; +u8 rgb_effect;u8 rgb_en; +u8 rgb_mode; +u8 rgb_profile; +u8 rgb_speed;u8 tp_en;u8 tp_vibration_en;u8 tp_vibration_intensity;
@@ -223,6 +229,41 @@ static const char *const rumble_mode_text[] = {#define FPS_MODE_DPI 0x02 +enum rgb_config_index { +LIGHT_CFG_ALL =0x01 , +LIGHT_MODE_SEL , +LIGHT_PROFILE_SEL , +USR_LIGHT_PROFILE_1 , +USR_LIGHT_PROFILE_2 , +USR_LIGHT_PROFILE_3 , +}; + +enum rgb_mode_index { +RGB_MODE_UNKNOWN , +RGB_MODE_DYNAMIC , +RGB_MODE_CUSTOM , +}; + +static const char *const rgb_mode_text[] = { + [RGB_MODE_UNKNOWN ] ="unknown" , + [RGB_MODE_DYNAMIC ] ="dynamic" , + [RGB_MODE_CUSTOM ] ="custom" , +}; + +enum rgb_effect_index { +RGB_EFFECT_MONO , +RGB_EFFECT_BREATHE , +RGB_EFFECT_CHROMA , +RGB_EFFECT_RAINBOW , +}; + +static const char *const rgb_effect_text[] = { + [RGB_EFFECT_MONO ] ="monocolor" , + [RGB_EFFECT_BREATHE ] ="breathe" , + [RGB_EFFECT_CHROMA ] ="chroma" , + [RGB_EFFECT_RAINBOW ] ="rainbow" , +}; +static int hid_go_version_event (struct command_report *cmd_rep) {switch (cmd_rep->sub_cmd) {
@@ -440,6 +481,33 @@ static int hid_go_fps_dpi_event(struct command_report *cmd_rep)return 0 ; } +static int hid_go_light_event (struct command_report *cmd_rep) +{ +struct led_classdev_mc *mc_cdev; + +switch (cmd_rep->sub_cmd) { +case LIGHT_MODE_SEL : + drvdata.rgb_mode = cmd_rep->data[0 ]; +return 0 ; +case LIGHT_PROFILE_SEL : + drvdata.rgb_profile = cmd_rep->data[0 ]; +return 0 ; +case USR_LIGHT_PROFILE_1 : +case USR_LIGHT_PROFILE_2 : +case USR_LIGHT_PROFILE_3 : + mc_cdev =lcdev_to_mccdev (drvdata.led_cdev); + drvdata.rgb_effect = cmd_rep->data[0 ]; + mc_cdev->subled_info[0 ].intensity = cmd_rep->data[1 ]; + mc_cdev->subled_info[1 ].intensity = cmd_rep->data[2 ]; + mc_cdev->subled_info[2 ].intensity = cmd_rep->data[3 ]; + drvdata.led_cdev->brightness = cmd_rep->data[4 ]; + drvdata.rgb_speed =100 - cmd_rep->data[5 ]; +return 0 ; +default : +return -EINVAL ; + } +} +static int hid_go_set_event_return (struct command_report *cmd_rep) {if (cmd_rep->data[0 ] !=0 )
@@ -493,9 +561,13 @@ static int hid_go_raw_event(struct hid_device *hdev, struct hid_report *report,case GET_DPI_CFG : ret =hid_go_fps_dpi_event (cmd_rep);break ; +case GET_RGB_CFG : + ret =hid_go_light_event (cmd_rep); +break ;case SET_FEATURE_STATUS :case SET_MOTOR_CFG :case SET_DPI_CFG : +case SET_RGB_CFG : ret =hid_go_set_event_return (cmd_rep);break ;default :
@@ -565,6 +637,12 @@ static ssize_t version_show(struct device *dev, struct device_attribute *attr, enum dev_type device_type) {ssize_t count =0 ; +int ret; + + ret =mcu_property_out (drvdata.hdev,MCU_CONFIG_DATA ,GET_VERSION_DATA , + index, device_type,NULL ,0 ); +if (ret) +return ret;switch (index) {case PRODUCT_VERSION :
@@ -1079,6 +1157,277 @@ static ssize_t fps_mode_dpi_index_show(struct device *dev,return sysfs_emit (buf,"500 800 1200 1800\n" ); } +static int rgb_cfg_call (struct hid_device *hdev,enum mcu_command_index cmd, +enum rgb_config_index index,u8 *val,size_t size) +{ +if (cmd !=SET_RGB_CFG && cmd !=GET_RGB_CFG ) +return -EINVAL ; + +if (index <LIGHT_CFG_ALL || index >USR_LIGHT_PROFILE_3 ) +return -EINVAL ; + +return mcu_property_out (hdev,MCU_CONFIG_DATA , cmd, index,UNSPECIFIED , + val, size); +} + +static int rgb_attr_show (void ) +{ +enum rgb_config_index index; + + index = drvdata.rgb_profile +3 ; + +return rgb_cfg_call (drvdata.hdev,GET_RGB_CFG , index,NULL ,0 ); +}; + +static ssize_t rgb_effect_store (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t count) +{ +struct led_classdev_mc *mc_cdev =lcdev_to_mccdev (drvdata.led_cdev); +enum rgb_config_index index; +u8 effect; +int ret; + + ret =sysfs_match_string (rgb_effect_text, buf); +if (ret <0 ) +return ret; + + effect = ret; + index = drvdata.rgb_profile +3 ; +u8 rgb_profile[6 ] = { effect, + mc_cdev->subled_info[0 ].intensity, + mc_cdev->subled_info[1 ].intensity, + mc_cdev->subled_info[2 ].intensity, + drvdata.led_cdev->brightness, + drvdata.rgb_speed }; + + ret =rgb_cfg_call (drvdata.hdev,SET_RGB_CFG , index, rgb_profile,6 ); +if (ret) +return ret; + + drvdata.rgb_effect = effect; +return count; +}; + +static ssize_t rgb_effect_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +int ret; + + ret =rgb_attr_show (); +if (ret) +return ret; + +if (drvdata.rgb_effect >=ARRAY_SIZE (rgb_effect_text)) +return -EINVAL ; + +return sysfs_emit (buf,"%s\n" , rgb_effect_text[drvdata.rgb_effect]); +} + +static ssize_t rgb_effect_index_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +ssize_t count =0 ; +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (rgb_effect_text); i++) + count +=sysfs_emit_at (buf, count,"%s " , rgb_effect_text[i]); + +if (count) + buf[count -1 ] ='\n' ; + +return count; +} + +static ssize_t rgb_speed_store (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t count) +{ +struct led_classdev_mc *mc_cdev =lcdev_to_mccdev (drvdata.led_cdev); +enum rgb_config_index index; +int val =0 ; +int ret; + + ret =kstrtoint (buf,10 , &val); +if (ret) +return ret; + +if (val <0 || val >100 ) +return -EINVAL ; + +/* This is a delay setting, invert logic for consistency with other drivers */ + val =100 - val; + + index = drvdata.rgb_profile +3 ; +u8 rgb_profile[6 ] = { drvdata.rgb_effect, + mc_cdev->subled_info[0 ].intensity, + mc_cdev->subled_info[1 ].intensity, + mc_cdev->subled_info[2 ].intensity, + drvdata.led_cdev->brightness, + val }; + + ret =rgb_cfg_call (drvdata.hdev,SET_RGB_CFG , index, rgb_profile,6 ); +if (ret) +return ret; + + drvdata.rgb_speed = val; + +return count; +}; + +static ssize_t rgb_speed_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +int ret, val; + + ret =rgb_attr_show (); +if (ret) +return ret; + +if (drvdata.rgb_speed >100 ) +return -EINVAL ; + + val = drvdata.rgb_speed; + +return sysfs_emit (buf,"%hhu\n" , val); +} + +static ssize_t rgb_speed_range_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"0-100\n" ); +} + +static ssize_t rgb_mode_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +int ret; +u8 val; + + ret =sysfs_match_string (rgb_mode_text, buf); +if (ret <=0 ) +return ret; + + val = ret; + + ret =rgb_cfg_call (drvdata.hdev,SET_RGB_CFG ,LIGHT_MODE_SEL , &val,1 ); +if (ret) +return ret; + + drvdata.rgb_mode = val; + +return count; +}; + +static ssize_t rgb_mode_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +int ret; + + ret =rgb_cfg_call (drvdata.hdev,GET_RGB_CFG ,LIGHT_MODE_SEL ,NULL ,0 ); +if (ret) +return ret; + +if (drvdata.rgb_mode >=ARRAY_SIZE (rgb_mode_text)) +return -EINVAL ; + +return sysfs_emit (buf,"%s\n" , rgb_mode_text[drvdata.rgb_mode]); +}; + +static ssize_t rgb_mode_index_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +ssize_t count =0 ; +unsigned int i; + +for (i =1 ; i <ARRAY_SIZE (rgb_mode_text); i++) + count +=sysfs_emit_at (buf, count,"%s " , rgb_mode_text[i]); + +if (count) + buf[count -1 ] ='\n' ; + +return count; +} + +static ssize_t rgb_profile_store (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t count) +{ +size_t size =1 ; +int ret; +u8 val; + + ret =kstrtou8 (buf,10 , &val); +if (ret <0 ) +return ret; + +if (val <1 || val >3 ) +return -EINVAL ; + + ret =rgb_cfg_call (drvdata.hdev,SET_RGB_CFG ,LIGHT_PROFILE_SEL , &val, size); +if (ret) +return ret; + + drvdata.rgb_profile = val; + +return count; +}; + +static ssize_t rgb_profile_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +int ret; + + ret =rgb_cfg_call (drvdata.hdev,GET_RGB_CFG ,LIGHT_PROFILE_SEL ,NULL ,0 ); +if (ret) +return ret; + +if (drvdata.rgb_profile <1 || drvdata.rgb_profile >3 ) +return -EINVAL ; + +return sysfs_emit (buf,"%hhu\n" , drvdata.rgb_profile); +}; + +static ssize_t rgb_profile_range_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"1-3\n" ); +} + +static void hid_go_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct led_classdev_mc *mc_cdev =lcdev_to_mccdev (drvdata.led_cdev); +enum rgb_config_index index; +int ret; + +if (brightness > led_cdev->max_brightness) { +dev_err (led_cdev->dev,"Invalid argument\n" ); +return ; + } + + index = drvdata.rgb_profile +3 ; +u8 rgb_profile[6 ] = { drvdata.rgb_effect, + mc_cdev->subled_info[0 ].intensity, + mc_cdev->subled_info[1 ].intensity, + mc_cdev->subled_info[2 ].intensity, + brightness, + drvdata.rgb_speed }; + + ret =rgb_cfg_call (drvdata.hdev,SET_RGB_CFG , index, rgb_profile,6 ); +switch (ret) { +case 0 : + led_cdev->brightness = brightness; +break ; +case -ENODEV :/* during switch to IAP -ENODEV is expected */ +case -ENOSYS :/* during rmmod -ENOSYS is expected */ +dev_dbg (led_cdev->dev,"Failed to write RGB profile: %i\n" , ret); +break ; +default : +dev_err (led_cdev->dev,"Failed to write RGB profile: %i\n" , ret); + }; +} +#define LEGO_DEVICE_ATTR_RW (_name, _attrname, _dtype, _rtype, _group) \ static ssize_t _name##_store(struct device *dev, \ struct device_attribute *attr, \
@@ -1389,6 +1738,71 @@ static const struct attribute_group *top_level_attr_groups[] = { &touchpad_attr_group, NULL, }; +/* RGB */ +static struct go_cfg_attr rgb_enabled = {FEATURE_LIGHT_ENABLE }; + +LEGO_DEVICE_ATTR_RW (rgb_enabled,"enabled" ,UNSPECIFIED , index, feature_status); +static DEVICE_ATTR_RO_NAMED(rgb_effect_index, "effect_index"); +static DEVICE_ATTR_RO_NAMED(rgb_enabled_index, "enabled_index"); +static DEVICE_ATTR_RO_NAMED(rgb_mode_index, "mode_index"); +static DEVICE_ATTR_RO_NAMED(rgb_profile_range, "profile_range"); +static DEVICE_ATTR_RO_NAMED(rgb_speed_range, "speed_range"); +static DEVICE_ATTR_RW_NAMED(rgb_effect, "effect"); +static DEVICE_ATTR_RW_NAMED(rgb_mode, "mode"); +static DEVICE_ATTR_RW_NAMED(rgb_profile, "profile"); +static DEVICE_ATTR_RW_NAMED(rgb_speed, "speed"); + +static struct attribute *go_rgb_attrs[] = { + &dev_attr_rgb_effect.attr, + &dev_attr_rgb_effect_index.attr, + &dev_attr_rgb_enabled.attr, + &dev_attr_rgb_enabled_index.attr, + &dev_attr_rgb_mode.attr, + &dev_attr_rgb_mode_index.attr, + &dev_attr_rgb_profile.attr, + &dev_attr_rgb_profile_range.attr, + &dev_attr_rgb_speed.attr, + &dev_attr_rgb_speed_range.attr, +NULL , +}; + +static struct attribute_group rgb_attr_group = { + .attrs = go_rgb_attrs, +}; + +static struct mc_subled go_rgb_subled_info[] = { + { + .color_index =LED_COLOR_ID_RED , + .brightness =0x50 , + .intensity =0x24 , + .channel =0x1 , + }, + { + .color_index =LED_COLOR_ID_GREEN , + .brightness =0x50 , + .intensity =0x22 , + .channel =0x2 , + }, + { + .color_index =LED_COLOR_ID_BLUE , + .brightness =0x50 , + .intensity =0x99 , + .channel =0x3 , + }, +}; + +static struct led_classdev_mc go_cdev_rgb = { + .led_cdev = { + .name ="go:rgb:joystick_rings" , + .color =LED_COLOR_ID_RGB , + .brightness =0x50 , + .max_brightness =0x64 , + .brightness_set = hid_go_brightness_set, + }, + .num_colors =ARRAY_SIZE (go_rgb_subled_info), + .subled_info = go_rgb_subled_info, +}; +static void cfg_setup (struct work_struct *work) {int ret;
@@ -1579,6 +1993,21 @@ static int hid_go_cfg_probe(struct hid_device *hdev,return ret; } + ret =devm_led_classdev_multicolor_register (&hdev->dev, &go_cdev_rgb); +if (ret) { +dev_err_probe (&hdev->dev, ret,"Failed to create RGB device\n" ); +return ret; + } + + ret =devm_device_add_group (go_cdev_rgb.led_cdev.dev, &rgb_attr_group); +if (ret) { +dev_err_probe (&hdev->dev, ret, +"Failed to create RGB configuration attributes\n" ); +return ret; + } + + drvdata.led_cdev = &go_cdev_rgb.led_cdev; +init_completion (&drvdata.send_cmd_complete);/* Executing calls prior to returning from probe will lock the MCU. Schedule
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 7/19 HID: hid-lenovo-go: Add Calibration Settings
In reply to Derek J. ClarkAdds calibration enable and last calibration status indicators for the triggers, joysticks, and handle gyros.
---
v6:
- Make local attributes static.
--- drivers/hid/hid-lenovo-go.c | 284 +++++++++++++++++++++++++++++++++++- 1 file changed, 283 insertions(+), 1 deletion(-)
drivers/hid/hid-lenovo-go.c +283 -1
@@ -43,8 +43,11 @@ static struct hid_go_cfg {struct mutex cfg_mutex;/*ensure single synchronous output report*/ u8 fps_mode;u8 gp_left_auto_sleep_time; +u8 gp_left_gyro_cal_status; +u8 gp_left_joy_cal_status;u8 gp_left_notify_en;u8 gp_left_rumble_mode; +u8 gp_left_trigg_cal_status;u32 gp_left_version_firmware;u8 gp_left_version_gen;u32 gp_left_version_hardware;
@@ -52,8 +55,11 @@ static struct hid_go_cfg {u32 gp_left_version_protocol;u8 gp_mode;u8 gp_right_auto_sleep_time; +u8 gp_right_gyro_cal_status; +u8 gp_right_joy_cal_status;u8 gp_right_notify_en;u8 gp_right_rumble_mode; +u8 gp_right_trigg_cal_status;u32 gp_right_version_firmware;u8 gp_right_version_gen;u32 gp_right_version_hardware;
@@ -227,7 +233,41 @@ static const char *const rumble_mode_text[] = { [RUMBLE_MODE_RPG] = "rpg", }; -#define FPS_MODE_DPI 0x02 +#define FPS_MODE_DPI 0x02 +#define TRIGGER_CALIBRATE 0x04 +#define JOYSTICK_CALIBRATE 0x04 +#define GYRO_CALIBRATE 0x06 + +enum cal_device_type { +CALDEV_GYROSCOPE =0x01 , +CALDEV_JOYSTICK , +CALDEV_TRIGGER , +CALDEV_JOY_TRIGGER , +}; + +enum cal_enable { +CAL_UNKNOWN , +CAL_START , +CAL_STOP , +}; + +static const char *const cal_enabled_text[] = { + [CAL_UNKNOWN ] ="unknown" , + [CAL_START ] ="start" , + [CAL_STOP ] ="stop" , +}; + +enum cal_status_index { +CAL_STAT_UNKNOWN , +CAL_STAT_SUCCESS , +CAL_STAT_FAILURE , +}; + +static const char *const cal_status_text[] = { + [CAL_STAT_UNKNOWN ] ="unknown" , + [CAL_STAT_SUCCESS ] ="success" , + [CAL_STAT_FAILURE ] ="failure" , +};enum rgb_config_index {LIGHT_CFG_ALL =0x01 ,
@@ -264,6 +304,13 @@ static const char *const rgb_effect_text[] = { [RGB_EFFECT_RAINBOW] = "rainbow", }; +enum device_status_index { +GET_CAL_STATUS =0x02 , +GET_UPGRADE_STATUS , +GET_MACRO_REC_STATUS , +GET_HOTKEY_TRIGG_STATUS , +}; +static int hid_go_version_event (struct command_report *cmd_rep) {switch (cmd_rep->sub_cmd) {
@@ -508,6 +555,44 @@ static int hid_go_light_event(struct command_report *cmd_rep) } } +static int hid_go_device_status_event (struct command_report *cmd_rep) +{ +switch (cmd_rep->device_type) { +case LEFT_CONTROLLER : +switch (cmd_rep->data[0 ]) { +case CALDEV_GYROSCOPE : + drvdata.gp_left_gyro_cal_status = cmd_rep->data[1 ]; +return 0 ; +case CALDEV_JOYSTICK : + drvdata.gp_left_joy_cal_status = cmd_rep->data[1 ]; +return 0 ; +case CALDEV_TRIGGER : + drvdata.gp_left_trigg_cal_status = cmd_rep->data[1 ]; +return 0 ; +default : +return -EINVAL ; + } +break ; +case RIGHT_CONTROLLER : +switch (cmd_rep->data[0 ]) { +case CALDEV_GYROSCOPE : + drvdata.gp_right_gyro_cal_status = cmd_rep->data[1 ]; +return 0 ; +case CALDEV_JOYSTICK : + drvdata.gp_right_joy_cal_status = cmd_rep->data[1 ]; +return 0 ; +case CALDEV_TRIGGER : + drvdata.gp_right_trigg_cal_status = cmd_rep->data[1 ]; +return 0 ; +default : +return -EINVAL ; + } +break ; +default : +return -EINVAL ; + } +} +static int hid_go_set_event_return (struct command_report *cmd_rep) {if (cmd_rep->data[0 ] !=0 )
@@ -564,10 +649,16 @@ static int hid_go_raw_event(struct hid_device *hdev, struct hid_report *report,case GET_RGB_CFG : ret =hid_go_light_event (cmd_rep);break ; +case GET_DEVICE_STATUS : + ret =hid_go_device_status_event (cmd_rep); +break ;case SET_FEATURE_STATUS :case SET_MOTOR_CFG :case SET_DPI_CFG :case SET_RGB_CFG : +case SET_TRIGGER_CFG : +case SET_JOYSTICK_CFG : +case SET_GYRO_CFG : ret =hid_go_set_event_return (cmd_rep);break ;default :
@@ -1157,6 +1248,101 @@ static ssize_t fps_mode_dpi_index_show(struct device *dev,return sysfs_emit (buf,"500 800 1200 1800\n" ); } +static ssize_t device_status_show (struct device *dev, +struct device_attribute *attr,char *buf, +enum device_status_index index, +enum dev_type device_type, +enum cal_device_type cal_type) +{ +u8 i; + +switch (index) { +case GET_CAL_STATUS : +switch (device_type) { +case LEFT_CONTROLLER : +switch (cal_type) { +case CALDEV_GYROSCOPE : + i = drvdata.gp_left_gyro_cal_status; +break ; +case CALDEV_JOYSTICK : + i = drvdata.gp_left_joy_cal_status; +break ; +case CALDEV_TRIGGER : + i = drvdata.gp_left_trigg_cal_status; +break ; +default : +return -EINVAL ; + } +break ; +case RIGHT_CONTROLLER : +switch (cal_type) { +case CALDEV_GYROSCOPE : + i = drvdata.gp_right_gyro_cal_status; +break ; +case CALDEV_JOYSTICK : + i = drvdata.gp_right_joy_cal_status; +break ; +case CALDEV_TRIGGER : + i = drvdata.gp_right_trigg_cal_status; +break ; +default : +return -EINVAL ; + } +break ; +default : +return -EINVAL ; + } +break ; +default : +return -EINVAL ; + }; + +if (i >=ARRAY_SIZE (cal_status_text)) +return -EINVAL ; + +return sysfs_emit (buf,"%s\n" , cal_status_text[i]); +} + +static ssize_t calibrate_config_store (struct device *dev, +struct device_attribute *attr, +const char *buf,u8 cmd,u8 sub_cmd, +size_t count,enum dev_type device_type) +{ +size_t size =1 ; +u8 val =0 ; +int ret; + + ret =sysfs_match_string (cal_enabled_text, buf); +if (ret <0 ) +return ret; + + val = ret; +if (!val) + size =0 ; + + ret =mcu_property_out (drvdata.hdev,MCU_CONFIG_DATA , cmd, sub_cmd, + device_type, &val, size); +if (ret <0 ) +return ret; + +return count; +} + +static ssize_t calibrate_config_options (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +ssize_t count =0 ; +unsigned int i; + +for (i =1 ; i <ARRAY_SIZE (cal_enabled_text); i++) + count +=sysfs_emit_at (buf, count,"%s " , cal_enabled_text[i]); + + buf[count -1 ] ='\n' ; + +return count; +} +static int rgb_cfg_call (struct hid_device *hdev,enum mcu_command_index cmd,enum rgb_config_index index,u8 *val,size_t size) {
@@ -1466,6 +1652,30 @@ static void hid_go_brightness_set(struct led_classdev *led_cdev, } \ static DEVICE_ATTR_RO_NAMED(_name, _attrname) +#define LEGO_CAL_DEVICE_ATTR (_name, _attrname, _scmd, _dtype, _rtype) \ + static ssize_t _name##_store(struct device *dev, \ + struct device_attribute *attr, \ + const char *buf, size_t count) \ + { \ + return calibrate_config_store(dev, attr, buf, _name.index, \ + _scmd, count, _dtype); \ + } \ + static ssize_t _name##_##_rtype##_show( \ + struct device *dev, struct device_attribute *attr, char *buf) \ + { \ + return calibrate_config_options(dev, attr, buf); \ + } \ + static DEVICE_ATTR_WO_NAMED(_name, _attrname) + +#define LEGO_DEVICE_STATUS_ATTR (_name, _attrname, _scmd, _dtype) \ + static ssize_t _name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ + { \ + return device_status_show(dev, attr, buf, _name.index, _scmd, \ + _dtype); \ + } \ + static DEVICE_ATTR_RO_NAMED(_name, _attrname) +/* Gamepad - MCU */ static struct go_cfg_attr version_product_mcu = {PRODUCT_VERSION };LEGO_DEVICE_ATTR_RO (version_product_mcu,"product_version" ,USB_MCU , version);
@@ -1603,9 +1813,45 @@ LEGO_DEVICE_ATTR_RW(rumble_notification_left, "rumble_notification", static DEVICE_ATTR_RO_NAMED(rumble_notification_left_index, "rumble_notification_index"); +static struct go_cfg_attr cal_trigg_left = {TRIGGER_CALIBRATE }; +LEGO_CAL_DEVICE_ATTR (cal_trigg_left,"calibrate_trigger" ,SET_TRIGGER_CFG , +LEFT_CONTROLLER , index); +static DEVICE_ATTR_RO_NAMED(cal_trigg_left_index, "calibrate_trigger_index"); + +static struct go_cfg_attr cal_joy_left = {JOYSTICK_CALIBRATE }; +LEGO_CAL_DEVICE_ATTR (cal_joy_left,"calibrate_joystick" ,SET_JOYSTICK_CFG , +LEFT_CONTROLLER , index); +static DEVICE_ATTR_RO_NAMED(cal_joy_left_index, "calibrate_joystick_index"); + +static struct go_cfg_attr cal_gyro_left = {GYRO_CALIBRATE }; +LEGO_CAL_DEVICE_ATTR (cal_gyro_left,"calibrate_gyro" ,SET_GYRO_CFG , +LEFT_CONTROLLER , index); +static DEVICE_ATTR_RO_NAMED(cal_gyro_left_index, "calibrate_gyro_index"); + +static struct go_cfg_attr cal_trigg_left_status = {GET_CAL_STATUS }; +LEGO_DEVICE_STATUS_ATTR (cal_trigg_left_status,"calibrate_trigger_status" , +LEFT_CONTROLLER ,CALDEV_TRIGGER ); + +static struct go_cfg_attr cal_joy_left_status = {GET_CAL_STATUS }; +LEGO_DEVICE_STATUS_ATTR (cal_joy_left_status,"calibrate_joystick_status" , +LEFT_CONTROLLER ,CALDEV_JOYSTICK ); + +static struct go_cfg_attr cal_gyro_left_status = {GET_CAL_STATUS }; +LEGO_DEVICE_STATUS_ATTR (cal_gyro_left_status,"calibrate_gyro_status" , +LEFT_CONTROLLER ,CALDEV_GYROSCOPE ); +static struct attribute *left_gamepad_attrs[] = { &dev_attr_auto_sleep_time_left.attr, &dev_attr_auto_sleep_time_left_range.attr, + &dev_attr_cal_gyro_left.attr, + &dev_attr_cal_gyro_left_index.attr, + &dev_attr_cal_gyro_left_status.attr, + &dev_attr_cal_joy_left.attr, + &dev_attr_cal_joy_left_index.attr, + &dev_attr_cal_joy_left_status.attr, + &dev_attr_cal_trigg_left.attr, + &dev_attr_cal_trigg_left_index.attr, + &dev_attr_cal_trigg_left_status.attr, &dev_attr_imu_bypass_left.attr, &dev_attr_imu_bypass_left_index.attr, &dev_attr_imu_enabled_left.attr,
@@ -1674,9 +1920,45 @@ LEGO_DEVICE_ATTR_RW(rumble_notification_right, "rumble_notification", static DEVICE_ATTR_RO_NAMED(rumble_notification_right_index, "rumble_notification_index"); +static struct go_cfg_attr cal_trigg_right = {TRIGGER_CALIBRATE }; +LEGO_CAL_DEVICE_ATTR (cal_trigg_right,"calibrate_trigger" ,SET_TRIGGER_CFG , +RIGHT_CONTROLLER , index); +static DEVICE_ATTR_RO_NAMED(cal_trigg_right_index, "calibrate_trigger_index"); + +static struct go_cfg_attr cal_joy_right = {JOYSTICK_CALIBRATE }; +LEGO_CAL_DEVICE_ATTR (cal_joy_right,"calibrate_joystick" ,SET_JOYSTICK_CFG , +RIGHT_CONTROLLER , index); +static DEVICE_ATTR_RO_NAMED(cal_joy_right_index, "calibrate_joystick_index"); + +static struct go_cfg_attr cal_gyro_right = {GYRO_CALIBRATE }; +LEGO_CAL_DEVICE_ATTR (cal_gyro_right,"calibrate_gyro" ,SET_GYRO_CFG , +RIGHT_CONTROLLER , index); +static DEVICE_ATTR_RO_NAMED(cal_gyro_right_index, "calibrate_gyro_index"); + +static struct go_cfg_attr cal_trigg_right_status = {GET_CAL_STATUS }; +LEGO_DEVICE_STATUS_ATTR (cal_trigg_right_status,"calibrate_trigger_status" , +RIGHT_CONTROLLER ,CALDEV_TRIGGER ); + +static struct go_cfg_attr cal_joy_right_status = {GET_CAL_STATUS }; +LEGO_DEVICE_STATUS_ATTR (cal_joy_right_status,"calibrate_joystick_status" , +RIGHT_CONTROLLER ,CALDEV_JOYSTICK ); + +static struct go_cfg_attr cal_gyro_right_status = {GET_CAL_STATUS }; +LEGO_DEVICE_STATUS_ATTR (cal_gyro_right_status,"calibrate_gyro_status" , +RIGHT_CONTROLLER ,CALDEV_GYROSCOPE ); +static struct attribute *right_gamepad_attrs[] = { &dev_attr_auto_sleep_time_right.attr, &dev_attr_auto_sleep_time_right_range.attr, + &dev_attr_cal_gyro_right.attr, + &dev_attr_cal_gyro_right_index.attr, + &dev_attr_cal_gyro_right_status.attr, + &dev_attr_cal_joy_right.attr, + &dev_attr_cal_joy_right_index.attr, + &dev_attr_cal_joy_right_status.attr, + &dev_attr_cal_trigg_right.attr, + &dev_attr_cal_trigg_right_index.attr, + &dev_attr_cal_trigg_right_status.attr, &dev_attr_imu_bypass_right.attr, &dev_attr_imu_bypass_right_index.attr, &dev_attr_imu_enabled_right.attr,
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 8/19 HID: hid-lenovo-go: Add OS Mode Toggle
In reply to Derek J. ClarkAdds OS Mode toggle, who's primary function is to change the built-in functional chords to use the right handle legion button instead of the left handle legion button as the mode shift key.
---
v6:
- Use NULL instead of 0 in mcu_propery_out when there is no data.
v5:
- Remove reset_resume as it doesn't run, the device disconnects are reconnects during suspend. Udev or userspace will reset os_mode after resume.
v3:
- Fix collision with os_mode_index attribute and os_mode_index enum.
--- drivers/hid/hid-lenovo-go.c | 101 ++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+)
drivers/hid/hid-lenovo-go.c +101 -0
@@ -76,6 +76,7 @@ static struct hid_go_cfg {u32 mcu_version_product;u32 mcu_version_protocol;u32 mouse_dpi; +u8 os_mode;u8 rgb_effect;u8 rgb_en;u8 rgb_mode;
@@ -166,6 +167,8 @@ enum feature_status_index { FEATURE_GAMEPAD_MODE = 0x0e, }; +#define FEATURE_OS_MODE 0x69 +enum fps_switch_status_index {FPS_STATUS_UNKNOWN ,GAMEPAD ,
@@ -311,6 +314,23 @@ enum device_status_index { GET_HOTKEY_TRIGG_STATUS, }; +enum os_mode_cfg_index { +SET_OS_MODE =0x09 , +GET_OS_MODE , +}; + +enum os_mode_type_index { +OS_UNKNOWN , +WINDOWS , +LINUX , +}; + +static const char *const os_mode_text[] = { + [OS_UNKNOWN ] ="unknown" , + [WINDOWS ] ="windows" , + [LINUX ] ="linux" , +}; +static int hid_go_version_event (struct command_report *cmd_rep) {switch (cmd_rep->sub_cmd) {
@@ -593,6 +613,21 @@ static int hid_go_device_status_event(struct command_report *cmd_rep) } } +static int hid_go_os_mode_cfg_event (struct command_report *cmd_rep) +{ +switch (cmd_rep->sub_cmd) { +case SET_OS_MODE : +if (cmd_rep->data[0 ] !=1 ) +return -EIO ; +return 0 ; +case GET_OS_MODE : + drvdata.os_mode = cmd_rep->data[0 ]; +return 0 ; +default : +return -EINVAL ; + }; +} +static int hid_go_set_event_return (struct command_report *cmd_rep) {if (cmd_rep->data[0 ] !=0 )
@@ -666,6 +701,9 @@ static int hid_go_raw_event(struct hid_device *hdev, struct hid_report *report,break ; };break ; +case OS_MODE_DATA : + ret =hid_go_os_mode_cfg_event (cmd_rep); +break ;default : goto passthrough; };
@@ -1343,6 +1381,64 @@ static ssize_t calibrate_config_options(struct device *dev,return count; } +static ssize_t os_mode_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +size_t size =1 ; +int ret; +u8 val; + + ret =sysfs_match_string (os_mode_text, buf); +if (ret <=0 ) +return ret; + + val = ret; + ret =mcu_property_out (drvdata.hdev,OS_MODE_DATA ,FEATURE_OS_MODE , +SET_OS_MODE ,USB_MCU , &val, size); +if (ret <0 ) +return ret; + + drvdata.os_mode = val; + +return count; +} + +static ssize_t os_mode_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +ssize_t count =0 ; +int ret; +u8 i; + + ret =mcu_property_out (drvdata.hdev,OS_MODE_DATA ,FEATURE_OS_MODE , +GET_OS_MODE ,USB_MCU ,NULL ,0 ); +if (ret) +return ret; + + i = drvdata.os_mode; +if (i >=ARRAY_SIZE (os_mode_text)) +return -EINVAL ; + + count =sysfs_emit (buf,"%s\n" , os_mode_text[i]); + +return count; +} + +static ssize_t os_mode_index_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +ssize_t count =0 ; +unsigned int i; + +for (i =1 ; i <ARRAY_SIZE (os_mode_text); i++) + count +=sysfs_emit_at (buf, count,"%s " , os_mode_text[i]); + +if (count) + buf[count -1 ] ='\n' ; + +return count; +} +static int rgb_cfg_call (struct hid_device *hdev,enum mcu_command_index cmd,enum rgb_config_index index,u8 *val,size_t size) {
@@ -1712,6 +1808,9 @@ static DEVICE_ATTR_RO_NAMED(gamepad_rumble_intensity_index,static DEVICE_ATTR_RW (fps_mode_dpi);static DEVICE_ATTR_RO (fps_mode_dpi_index); +static DEVICE_ATTR_RW (os_mode); +static DEVICE_ATTR_RO (os_mode_index); +static struct attribute *mcu_attrs[] = { &dev_attr_fps_mode_dpi.attr, &dev_attr_fps_mode_dpi_index.attr,
@@ -1720,6 +1819,8 @@ static struct attribute *mcu_attrs[] = { &dev_attr_gamepad_mode_index.attr, &dev_attr_gamepad_rumble_intensity.attr, &dev_attr_gamepad_rumble_intensity_index.attr, + &dev_attr_os_mode.attr, + &dev_attr_os_mode_index.attr, &dev_attr_reset_mcu.attr, &dev_attr_version_firmware_mcu.attr, &dev_attr_version_gen_mcu.attr,
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 9/19 HID: Include firmware version in the uevent
In reply to Derek J. ClarkFrom: 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
@@ -2887,6 +2887,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
@@ -698,6 +698,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.53.0
Derek J. Clark
maintainerPATCH v6 10/19 HID: hid-lenovo-go-s: Add Lenovo Legion Go S Series HID Driver
In reply to Derek J. ClarkAdds initial framework for a new HID driver, hid-lenovo-go-s, along with a uevent to report the firmware version for the MCU.
This driver primarily provides access to the configurable settings of the Lenovo Legion Go S controller. It will attach if the controller is in xinput or dinput mode. Non-configuration raw reports are forwarded to ensure the other endpoints continue to function as normal.
---
v6:
- Include signdedness bug fix by Ethan Tidmore.
- Make local attributes static.
- Use NULL instead of 0 in mcu_propery_out when there is no data.
v4:
- Use dmabuf per request instead of devm allocated static buffer. Resolves bug with side effects during suspend.
- Remove unnecessary HID quirks and return to HID_CONNECT_HIDRAW.
- Adjust delayed work time to 5ms to fix some side effects during resume when the MCU disconnects in some circumstances.
- Cleaner formatting on multiple debug messages.
v3:
- Include Mario's SOB tag
--- MAINTAINERS | 1 + drivers/hid/Kconfig | 12 ++ drivers/hid/Makefile | 1 + drivers/hid/hid-ids.h | 4 + drivers/hid/hid-lenovo-go-s.c | 278 ++++++++++++++++++++++++++++++++++ 5 files changed, 296 insertions(+) create mode 100644 drivers/hid/hid-lenovo-go-s.c
MAINTAINERS +1 -0
@@ -14420,6 +14420,7 @@ M: Derek J. Clark <[email protected]> M: Mark Pearson <[email protected]> L: [email protected] S: Maintained +F: drivers/hid/hid-lenovo-go-s.c F: drivers/hid/hid-lenovo-go.c F: drivers/hid/hid-lenovo.c
drivers/hid/Kconfig +12 -0
@@ -635,6 +635,18 @@ config HID_LENOVO_GO and Legion Go 2 Handheld Console Controllers. Say M here to compile this driver as a module. The module will be called hid-lenovo-go. +config HID_LENOVO_GO_S + tristate "HID Driver for Lenovo Legion Go S Controller" + depends on USB_HID + select LEDS_CLASS + select LEDS_CLASS_MULTICOLOR + help + Support for Lenovo Legion Go S Handheld Console Controller. + + Say Y here to include configuration interface support for the Lenovo Legion Go + S. Say M here to compile this driver as a module. The module will be called + hid-lenovo-go-s. + config HID_LETSKETCH tristate "Letsketch WP9620N tablets" depends on USB_HID
drivers/hid/Makefile +1 -0
@@ -77,6 +77,7 @@ obj-$(CONFIG_HID_KYSONA) += hid-kysona.o obj-$(CONFIG_HID_LCPOWER) += hid-lcpower.o obj-$(CONFIG_HID_LENOVO) += hid-lenovo.o obj-$(CONFIG_HID_LENOVO_GO) += hid-lenovo-go.o +obj-$(CONFIG_HID_LENOVO_GO_S) += hid-lenovo-go-s.o obj-$(CONFIG_HID_LETSKETCH) += hid-letsketch.o obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o obj-$(CONFIG_HID_LOGITECH) += hid-lg-g15.o
drivers/hid/hid-ids.h +4 -0
@@ -739,6 +739,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
drivers/hid/hid-lenovo-go-s.c new file +278 -0
278 lines not on this page · raw message
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 11/19 HID: hid-lenovo-go-s: Add MCU ID Attribute
In reply to Derek J. ClarkAdds command to probe for the MCU ID of the Lenovo Legion Go S Controller and assign it to a device attribute.
---
v6:
- Use NULL instead of 0 in mcu_propery_out when there is no data.
--- drivers/hid/hid-lenovo-go-s.c | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
drivers/hid/hid-lenovo-go-s.c +56 -0
@@ -18,6 +18,7 @@#include <linux/mutex.h> #include <linux/printk.h> #include <linux/string.h> +#include <linux/sysfs.h> #include <linux/types.h> #include <linux/unaligned.h> #include <linux/usb.h>
@@ -34,8 +35,13 @@ static struct hid_gos_cfg {struct completion send_cmd_complete;struct hid_device *hdev;struct mutex cfg_mutex;/*ensure single synchronous output report*/ +u8 mcu_id[12 ]; } drvdata; +struct gos_cfg_attr { +u8 index; +}; +struct command_report {u8 cmd;u8 sub_cmd;
@@ -70,6 +76,14 @@ static int hid_gos_version_event(u8 *data)return 0 ; } +static int hid_gos_mcu_id_event (struct command_report *cmd_rep) +{ + drvdata.mcu_id[0 ] = cmd_rep->sub_cmd; +memcpy (&drvdata.mcu_id[1 ], cmd_rep->data,11 ); + +return 0 ; +} +static int get_endpoint_address (struct hid_device *hdev) {struct usb_interface *intf =to_usb_interface (hdev->dev.parent);
@@ -103,6 +117,9 @@ static int hid_gos_raw_event(struct hid_device *hdev, struct hid_report *report,case GET_VERSION : ret =hid_gos_version_event (data);break ; +case GET_MCU_ID : + ret =hid_gos_mcu_id_event (cmd_rep); +break ;default : ret = -EINVAL ;break ;
@@ -157,10 +174,41 @@ static int mcu_property_out(struct hid_device *hdev, u8 command, u8 index,return 0 ; } +static ssize_t mcu_id_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +return sysfs_emit (buf,"%*phN\n" ,12 , &drvdata.mcu_id); +} + +/* MCU */ +static DEVICE_ATTR_RO (mcu_id); + +static struct attribute *legos_mcu_attrs[] = { + &dev_attr_mcu_id.attr, +NULL , +}; + +static const struct attribute_group mcu_attr_group = { + .attrs = legos_mcu_attrs, +}; + +static const struct attribute_group *top_level_attr_groups[] = { + &mcu_attr_group, +NULL , +}; +static void cfg_setup (struct work_struct *work) {int ret; +/* MCU */ + ret =mcu_property_out (drvdata.hdev,GET_MCU_ID ,FEATURE_NONE ,NULL ,0 ); +if (ret) { +dev_err (&drvdata.hdev->dev,"Failed to retrieve MCU ID: %i\n" , + ret); +return ; + } + ret =mcu_property_out (drvdata.hdev,GET_VERSION ,FEATURE_NONE ,NULL ,0 );if (ret) {dev_err (&drvdata.hdev->dev,"Failed to retrieve MCU Version: %i\n" , ret);
@@ -177,6 +225,13 @@ static int hid_gos_cfg_probe(struct hid_device *hdev, drvdata.hdev = hdev;mutex_init (&drvdata.cfg_mutex); + ret =sysfs_create_groups (&hdev->dev.kobj, top_level_attr_groups); +if (ret) { +dev_err_probe (&hdev->dev, ret, +"Failed to create gamepad configuration attributes\n" ); +return ret; + } +init_completion (&drvdata.send_cmd_complete);/* Executing calls prior to returning from probe will lock the MCU. Schedule
@@ -196,6 +251,7 @@ static void hid_gos_cfg_remove(struct hid_device *hdev) {guard (mutex)(&drvdata.cfg_mutex);cancel_delayed_work_sync (&drvdata.gos_cfg_setup); +sysfs_remove_groups (&hdev->dev.kobj, top_level_attr_groups);hid_hw_close (hdev);hid_hw_stop (hdev);hid_set_drvdata (hdev,NULL );
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 12/19 HID: hid-lenovo-go-s: Add Feature Status Attributes
In reply to Derek J. ClarkAdds features status attributes for the gamepad, MCU, touchpad/mouse, and IMU devices.
---
v6:
- Include positive promotion bug fix from Ethan Tidmore.
- Include impossible condition bug fix from Ethan Tidmore.
- Make local attributes static.
- Use NULL instead of 0 in mcu_propery_out when there is no data.
v4:
- Cleaner formatting on debug message.
--- drivers/hid/hid-lenovo-go-s.c | 484 +++++++++++++++++++++++++++++++++- 1 file changed, 483 insertions(+), 1 deletion(-)
drivers/hid/hid-lenovo-go-s.c +483 -1
@@ -15,6 +15,7 @@#include <linux/device.h> #include <linux/hid.h> #include <linux/jiffies.h> +#include <linux/kstrtox.h> #include <linux/mutex.h> #include <linux/printk.h> #include <linux/string.h>
@@ -35,7 +36,17 @@ static struct hid_gos_cfg {struct completion send_cmd_complete;struct hid_device *hdev;struct mutex cfg_mutex;/*ensure single synchronous output report*/ +u8 gp_auto_sleep_time; +u8 gp_dpad_mode; +u8 gp_mode; +u8 gp_poll_rate; +u8 imu_bypass_en; +u8 imu_sensor_en;u8 mcu_id[12 ]; +u8 mouse_step; +u8 os_mode; +u8 rgb_en; +u8 tp_en; } drvdata;struct gos_cfg_attr {
@@ -66,7 +77,73 @@ enum mcu_command_index { GET_PL_TEST = 0xdf, }; -#define FEATURE_NONE 0x00 +enum feature_enabled_index { +FEATURE_DISABLED , +FEATURE_ENABLED , +}; + +static const char *const feature_enabled_text[] = { + [FEATURE_DISABLED ] ="false" , + [FEATURE_ENABLED ] ="true" , +}; + +enum feature_status_index { +FEATURE_NONE =0x00 , +FEATURE_GAMEPAD_MODE =0x01 , +FEATURE_AUTO_SLEEP_TIME =0x04 , +FEATURE_IMU_BYPASS , +FEATURE_RGB_ENABLE , +FEATURE_IMU_ENABLE , +FEATURE_TOUCHPAD_ENABLE , +FEATURE_OS_MODE =0x0A , +FEATURE_POLL_RATE =0x10 , +FEATURE_DPAD_MODE , +FEATURE_MOUSE_WHEEL_STEP , +}; + +enum gamepad_mode_index { +XINPUT , +DINPUT , +}; + +static const char *const gamepad_mode_text[] = { + [XINPUT ] ="xinput" , + [DINPUT ] ="dinput" , +}; + +enum os_type_index { +WINDOWS , +LINUX , +}; + +static const char *const os_type_text[] = { + [WINDOWS ] ="windows" , + [LINUX ] ="linux" , +}; + +enum poll_rate_index { +HZ125 , +HZ250 , +HZ500 , +HZ1000 , +}; + +static const char *const poll_rate_text[] = { + [HZ125 ] ="125" , + [HZ250 ] ="250" , + [HZ500 ] ="500" , + [HZ1000 ] ="1000" , +}; + +enum dpad_mode_index { +DIR8 , +DIR4 , +}; + +static const char *const dpad_mode_text[] = { + [DIR8 ] ="8-way" , + [DIR4 ] ="4-way" , +};static int hid_gos_version_event (u8 *data) {
@@ -84,6 +161,57 @@ static int hid_gos_mcu_id_event(struct command_report *cmd_rep)return 0 ; } +static int hid_gos_gamepad_cfg_event (struct command_report *cmd_rep) +{ +int ret =0 ; + +switch (cmd_rep->sub_cmd) { +case FEATURE_GAMEPAD_MODE : + drvdata.gp_mode = cmd_rep->data[0 ]; +break ; +case FEATURE_AUTO_SLEEP_TIME : + drvdata.gp_auto_sleep_time = cmd_rep->data[0 ]; +break ; +case FEATURE_IMU_BYPASS : + drvdata.imu_bypass_en = cmd_rep->data[0 ]; +break ; +case FEATURE_RGB_ENABLE : + drvdata.rgb_en = cmd_rep->data[0 ]; +break ; +case FEATURE_IMU_ENABLE : + drvdata.imu_sensor_en = cmd_rep->data[0 ]; +break ; +case FEATURE_TOUCHPAD_ENABLE : + drvdata.tp_en = cmd_rep->data[0 ]; +break ; +case FEATURE_OS_MODE : + drvdata.os_mode = cmd_rep->data[0 ]; +break ; +case FEATURE_POLL_RATE : + drvdata.gp_poll_rate = cmd_rep->data[0 ]; +break ; +case FEATURE_DPAD_MODE : + drvdata.gp_dpad_mode = cmd_rep->data[0 ]; +break ; +case FEATURE_MOUSE_WHEEL_STEP : + drvdata.mouse_step = cmd_rep->data[0 ]; +break ; +default : + ret = -EINVAL ; +break ; + } + +return ret; +} + +static int hid_gos_set_event_return (struct command_report *cmd_rep) +{ +if (cmd_rep->data[0 ] !=0 ) +return -EIO ; + +return 0 ; +} +static int get_endpoint_address (struct hid_device *hdev) {struct usb_interface *intf =to_usb_interface (hdev->dev.parent);
@@ -120,6 +248,12 @@ static int hid_gos_raw_event(struct hid_device *hdev, struct hid_report *report,case GET_MCU_ID : ret =hid_gos_mcu_id_event (cmd_rep);break ; +case GET_GAMEPAD_CFG : + ret =hid_gos_gamepad_cfg_event (cmd_rep); +break ; +case SET_GAMEPAD_CFG : + ret =hid_gos_set_event_return (cmd_rep); +break ;default : ret = -EINVAL ;break ;
@@ -174,17 +308,329 @@ static int mcu_property_out(struct hid_device *hdev, u8 command, u8 index,return 0 ; } +static ssize_t gamepad_property_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count, +enum feature_status_index index) +{ +size_t size =1 ; +u8 val =0 ; +int ret; + +switch (index) { +case FEATURE_GAMEPAD_MODE : + ret =sysfs_match_string (gamepad_mode_text, buf); +if (ret <0 ) +return ret; + val = ret; +break ; +case FEATURE_AUTO_SLEEP_TIME : + ret =kstrtou8 (buf,10 , &val); +if (ret) +return ret; +break ; +case FEATURE_IMU_ENABLE : + ret =sysfs_match_string (feature_enabled_text, buf); +if (ret <0 ) +return ret; + val = ret; +break ; +case FEATURE_IMU_BYPASS : + ret =sysfs_match_string (feature_enabled_text, buf); +if (ret <0 ) +return ret; + val = ret; +break ; +case FEATURE_RGB_ENABLE : + ret =sysfs_match_string (feature_enabled_text, buf); +if (ret <0 ) +return ret; + val = ret; +break ; +case FEATURE_TOUCHPAD_ENABLE : + ret =sysfs_match_string (feature_enabled_text, buf); +if (ret <0 ) +return ret; + val = ret; +break ; +case FEATURE_OS_MODE : + ret =sysfs_match_string (os_type_text, buf); +if (ret <0 ) +return ret; + val = ret; +break ; +case FEATURE_POLL_RATE : + ret =sysfs_match_string (poll_rate_text, buf); +if (ret <0 ) +return ret; + val = ret; +break ; +case FEATURE_DPAD_MODE : + ret =sysfs_match_string (dpad_mode_text, buf); +if (ret <0 ) +return ret; + val = ret; +break ; +case FEATURE_MOUSE_WHEEL_STEP : + ret =kstrtou8 (buf,10 , &val); +if (ret) +return ret; +if (val <1 || val >127 ) +return -EINVAL ; +break ; +default : +return -EINVAL ; + } + +if (!val) + size =0 ; + + ret =mcu_property_out (drvdata.hdev,SET_GAMEPAD_CFG , index, &val, + size); +if (ret <0 ) +return ret; + +return count; +} + +static ssize_t gamepad_property_show (struct device *dev, +struct device_attribute *attr,char *buf, +enum feature_status_index index) +{ +ssize_t count =0 ; +u8 i; + + count =mcu_property_out (drvdata.hdev,GET_GAMEPAD_CFG , index,NULL ,0 ); +if (count <0 ) +return count; + +switch (index) { +case FEATURE_GAMEPAD_MODE : + i = drvdata.gp_mode; +if (i >=ARRAY_SIZE (gamepad_mode_text)) +return -EINVAL ; + count =sysfs_emit (buf,"%s\n" , gamepad_mode_text[i]); +break ; +case FEATURE_AUTO_SLEEP_TIME : + count =sysfs_emit (buf,"%u\n" , drvdata.gp_auto_sleep_time); +break ; +case FEATURE_IMU_ENABLE : + i = drvdata.imu_sensor_en; +if (i >=ARRAY_SIZE (feature_enabled_text)) +return -EINVAL ; + count =sysfs_emit (buf,"%s\n" , feature_enabled_text[i]); +break ; +case FEATURE_IMU_BYPASS : + i = drvdata.imu_bypass_en; +if (i >=ARRAY_SIZE (feature_enabled_text)) +return -EINVAL ; + count =sysfs_emit (buf,"%s\n" , feature_enabled_text[i]); +break ; +case FEATURE_RGB_ENABLE : + i = drvdata.rgb_en; +if (i >=ARRAY_SIZE (feature_enabled_text)) +return -EINVAL ; + count =sysfs_emit (buf,"%s\n" , feature_enabled_text[i]); +break ; +case FEATURE_TOUCHPAD_ENABLE : + i = drvdata.tp_en; +if (i >=ARRAY_SIZE (feature_enabled_text)) +return -EINVAL ; + count =sysfs_emit (buf,"%s\n" , feature_enabled_text[i]); +break ; +case FEATURE_OS_MODE : + i = drvdata.os_mode; +if (i >=ARRAY_SIZE (os_type_text)) +return -EINVAL ; + count =sysfs_emit (buf,"%s\n" , os_type_text[i]); +break ; +case FEATURE_POLL_RATE : + i = drvdata.gp_poll_rate; +if (i >=ARRAY_SIZE (poll_rate_text)) +return -EINVAL ; + count =sysfs_emit (buf,"%s\n" , poll_rate_text[i]); +break ; +case FEATURE_DPAD_MODE : + i = drvdata.gp_dpad_mode; +if (i >=ARRAY_SIZE (dpad_mode_text)) +return -EINVAL ; + count =sysfs_emit (buf,"%s\n" , dpad_mode_text[i]); +break ; +case FEATURE_MOUSE_WHEEL_STEP : + i = drvdata.mouse_step; +if (i <1 || i >127 ) +return -EINVAL ; + count =sysfs_emit (buf,"%u\n" , i); +break ; +default : +return -EINVAL ; + } + +return count; +} + +static ssize_t gamepad_property_options (struct device *dev, +struct device_attribute *attr, +char *buf, +enum feature_status_index index) +{ +size_t count =0 ; +unsigned int i; + +switch (index) { +case FEATURE_GAMEPAD_MODE : +for (i =0 ; i <ARRAY_SIZE (gamepad_mode_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + gamepad_mode_text[i]); + } +break ; +case FEATURE_AUTO_SLEEP_TIME : +return sysfs_emit (buf,"0-255\n" ); +case FEATURE_IMU_ENABLE : +for (i =0 ; i <ARRAY_SIZE (feature_enabled_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + feature_enabled_text[i]); + } +break ; +case FEATURE_IMU_BYPASS : +case FEATURE_RGB_ENABLE : +case FEATURE_TOUCHPAD_ENABLE : +for (i =0 ; i <ARRAY_SIZE (feature_enabled_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + feature_enabled_text[i]); + } +break ; +case FEATURE_OS_MODE : +for (i =0 ; i <ARRAY_SIZE (os_type_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + os_type_text[i]); + } +break ; +case FEATURE_POLL_RATE : +for (i =0 ; i <ARRAY_SIZE (poll_rate_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + poll_rate_text[i]); + } +break ; +case FEATURE_DPAD_MODE : +for (i =0 ; i <ARRAY_SIZE (dpad_mode_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + dpad_mode_text[i]); + } +break ; +case FEATURE_MOUSE_WHEEL_STEP : +return sysfs_emit (buf,"1-127\n" ); +default : +return count; + } + +if (count) + buf[count -1 ] ='\n' ; + +return count; +} +static ssize_t mcu_id_show (struct device *dev,struct device_attribute *attr,char *buf) {return sysfs_emit (buf,"%*phN\n" ,12 , &drvdata.mcu_id); } +#define LEGOS_DEVICE_ATTR_RW (_name, _attrname, _rtype, _group) \ + static ssize_t _name##_store(struct device *dev, \ + struct device_attribute *attr, \ + const char *buf, size_t count) \ + { \ + return _group##_property_store(dev, attr, buf, count, \ + _name.index); \ + } \ + static ssize_t _name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ + { \ + return _group##_property_show(dev, attr, buf, _name.index); \ + } \ + static ssize_t _name##_##_rtype##_show( \ + struct device *dev, struct device_attribute *attr, char *buf) \ + { \ + return _group##_property_options(dev, attr, buf, _name.index); \ + } \ + static DEVICE_ATTR_RW_NAMED(_name, _attrname) + +#define LEGOS_DEVICE_ATTR_RO (_name, _attrname, _group) \ + static ssize_t _name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ + { \ + return _group##_property_show(dev, attr, buf, _name.index); \ + } \ + static DEVICE_ATTR_RO_NAMED(_name, _attrname) + +/* Gamepad */ +static struct gos_cfg_attr auto_sleep_time = {FEATURE_AUTO_SLEEP_TIME }; +LEGOS_DEVICE_ATTR_RW (auto_sleep_time,"auto_sleep_time" , range, gamepad); +static DEVICE_ATTR_RO (auto_sleep_time_range); + +static struct gos_cfg_attr dpad_mode = {FEATURE_DPAD_MODE }; +LEGOS_DEVICE_ATTR_RW (dpad_mode,"dpad_mode" , index, gamepad); +static DEVICE_ATTR_RO (dpad_mode_index); + +static struct gos_cfg_attr gamepad_mode = {FEATURE_GAMEPAD_MODE }; +LEGOS_DEVICE_ATTR_RW (gamepad_mode,"mode" , index, gamepad); +static DEVICE_ATTR_RO_NAMED(gamepad_mode_index, "mode_index"); + +static struct gos_cfg_attr gamepad_poll_rate = {FEATURE_POLL_RATE }; +LEGOS_DEVICE_ATTR_RW (gamepad_poll_rate,"poll_rate" , index, gamepad); +static DEVICE_ATTR_RO_NAMED(gamepad_poll_rate_index, "poll_rate_index"); + +static struct attribute *legos_gamepad_attrs[] = { + &dev_attr_auto_sleep_time.attr, + &dev_attr_auto_sleep_time_range.attr, + &dev_attr_dpad_mode.attr, + &dev_attr_dpad_mode_index.attr, + &dev_attr_gamepad_mode.attr, + &dev_attr_gamepad_mode_index.attr, + &dev_attr_gamepad_poll_rate.attr, + &dev_attr_gamepad_poll_rate_index.attr, +NULL , +}; + +static const struct attribute_group gamepad_attr_group = { + .name ="gamepad" , + .attrs = legos_gamepad_attrs, +}; + +/* IMU */ +static struct gos_cfg_attr imu_bypass_enabled = {FEATURE_IMU_BYPASS }; +LEGOS_DEVICE_ATTR_RW (imu_bypass_enabled,"bypass_enabled" , index, gamepad); +static DEVICE_ATTR_RO_NAMED(imu_bypass_enabled_index, "bypass_enabled_index"); + +static struct gos_cfg_attr imu_sensor_enabled = {FEATURE_IMU_ENABLE }; +LEGOS_DEVICE_ATTR_RW (imu_sensor_enabled,"sensor_enabled" , index, gamepad); +static DEVICE_ATTR_RO_NAMED(imu_sensor_enabled_index, "sensor_enabled_index"); + +static struct attribute *legos_imu_attrs[] = { + &dev_attr_imu_bypass_enabled.attr, + &dev_attr_imu_bypass_enabled_index.attr, + &dev_attr_imu_sensor_enabled.attr, + &dev_attr_imu_sensor_enabled_index.attr, +NULL , +}; + +static const struct attribute_group imu_attr_group = { + .name ="imu" , + .attrs = legos_imu_attrs, +}; +/* MCU */ static DEVICE_ATTR_RO (mcu_id); +static struct gos_cfg_attr os_mode = {FEATURE_OS_MODE }; +LEGOS_DEVICE_ATTR_RW (os_mode,"os_mode" , index, gamepad); +static DEVICE_ATTR_RO (os_mode_index); +static struct attribute *legos_mcu_attrs[] = { &dev_attr_mcu_id.attr, + &dev_attr_os_mode.attr, + &dev_attr_os_mode_index.attr,NULL , };
@@ -192,8 +638,44 @@ static const struct attribute_group mcu_attr_group = { .attrs = legos_mcu_attrs, }; +/* Mouse */ +static struct gos_cfg_attr mouse_wheel_step = {FEATURE_MOUSE_WHEEL_STEP }; +LEGOS_DEVICE_ATTR_RW (mouse_wheel_step,"step" , range, gamepad); +static DEVICE_ATTR_RO_NAMED(mouse_wheel_step_range, "step_range"); + +static struct attribute *legos_mouse_attrs[] = { + &dev_attr_mouse_wheel_step.attr, + &dev_attr_mouse_wheel_step_range.attr, +NULL , +}; + +static const struct attribute_group mouse_attr_group = { + .name ="mouse" , + .attrs = legos_mouse_attrs, +}; + +/* Touchpad */ +static struct gos_cfg_attr touchpad_enabled = {FEATURE_TOUCHPAD_ENABLE }; +LEGOS_DEVICE_ATTR_RW (touchpad_enabled,"enabled" , index, gamepad); +static DEVICE_ATTR_RO_NAMED(touchpad_enabled_index, "enabled_index"); + +static struct attribute *legos_touchpad_attrs[] = { + &dev_attr_touchpad_enabled.attr, + &dev_attr_touchpad_enabled_index.attr, +NULL , +}; + +static const struct attribute_group touchpad_attr_group = { + .name ="touchpad" , + .attrs = legos_touchpad_attrs, +}; +static const struct attribute_group *top_level_attr_groups[] = { + &gamepad_attr_group, + &imu_attr_group, &mcu_attr_group, + &mouse_attr_group, + &touchpad_attr_group,NULL , };
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 13/19 HID: hid-lenovo-go-s: Add Touchpad Mode Attributes
In reply to Derek J. ClarkAdds attributes for managing the touchpad operating modes.
---
v6:
- Make local attributes static.
- Use NULL instead of 0 in mcu_propery_out when there is no data.
--- drivers/hid/hid-lenovo-go-s.c | 142 ++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+)
drivers/hid/hid-lenovo-go-s.c +142 -0
@@ -47,6 +47,8 @@ static struct hid_gos_cfg {u8 os_mode;u8 rgb_en;u8 tp_en; +u8 tp_linux_mode; +u8 tp_windows_mode; } drvdata;struct gos_cfg_attr {
@@ -145,6 +147,22 @@ static const char *const dpad_mode_text[] = { [DIR4] = "4-way", }; +enum touchpad_mode_index { +TP_REL , +TP_ABS , +}; + +static const char *const touchpad_mode_text[] = { + [TP_REL ] ="relative" , + [TP_ABS ] ="absolute" , +}; + +enum touchpad_config_index { +CFG_WINDOWS_MODE =0x03 , +CFG_LINUX_MODE , + +}; +static int hid_gos_version_event (u8 *data) {struct version_report *ver_rep = (struct version_report *)data;
@@ -204,6 +222,25 @@ static int hid_gos_gamepad_cfg_event(struct command_report *cmd_rep)return ret; } +static int hid_gos_touchpad_event (struct command_report *cmd_rep) +{ +int ret =0 ; + +switch (cmd_rep->sub_cmd) { +case CFG_LINUX_MODE : + drvdata.tp_linux_mode = cmd_rep->data[0 ]; +break ; +case CFG_WINDOWS_MODE : + drvdata.tp_windows_mode = cmd_rep->data[0 ]; +break ; +default : + ret = -EINVAL ; +break ; + } + +return ret; +} +static int hid_gos_set_event_return (struct command_report *cmd_rep) {if (cmd_rep->data[0 ] !=0 )
@@ -251,7 +288,11 @@ static int hid_gos_raw_event(struct hid_device *hdev, struct hid_report *report,case GET_GAMEPAD_CFG : ret =hid_gos_gamepad_cfg_event (cmd_rep);break ; +case GET_TP_PARAM : + ret =hid_gos_touchpad_event (cmd_rep); +break ;case SET_GAMEPAD_CFG : +case SET_TP_PARAM : ret =hid_gos_set_event_return (cmd_rep);break ;default :
@@ -530,6 +571,95 @@ static ssize_t gamepad_property_options(struct device *dev,return count; } +static ssize_t touchpad_property_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count, +enum touchpad_config_index index) +{ +size_t size =1 ; +u8 val =0 ; +int ret; + +switch (index) { +case CFG_WINDOWS_MODE : + ret =sysfs_match_string (touchpad_mode_text, buf); +if (ret <0 ) +return ret; + val = ret; +break ; +case CFG_LINUX_MODE : + ret =sysfs_match_string (touchpad_mode_text, buf); +if (ret <0 ) +return ret; + val = ret; +break ; +default : +return -EINVAL ; + } +if (!val) + size =0 ; + + ret =mcu_property_out (drvdata.hdev,SET_TP_PARAM , index, &val, size); +if (ret <0 ) +return ret; + +return count; +} + +static ssize_t touchpad_property_show (struct device *dev, +struct device_attribute *attr,char *buf, +enum touchpad_config_index index) +{ +int ret =0 ; +u8 i; + + ret =mcu_property_out (drvdata.hdev,GET_TP_PARAM , index,NULL ,0 ); +if (ret <0 ) +return ret; + +switch (index) { +case CFG_WINDOWS_MODE : + i = drvdata.tp_windows_mode; +break ; +case CFG_LINUX_MODE : + i = drvdata.tp_linux_mode; +break ; +default : +return -EINVAL ; + } + +if (i >=ARRAY_SIZE (touchpad_mode_text)) +return -EINVAL ; + +return sysfs_emit (buf,"%s\n" , touchpad_mode_text[i]); +} + +static ssize_t touchpad_property_options (struct device *dev, +struct device_attribute *attr, +char *buf, +enum touchpad_config_index index) +{ +size_t count =0 ; +unsigned int i; + +switch (index) { +case CFG_WINDOWS_MODE : +case CFG_LINUX_MODE : +for (i =0 ; i <ARRAY_SIZE (touchpad_mode_text); i++) { + count +=sysfs_emit_at (buf, count,"%s " , + touchpad_mode_text[i]); + } +break ; +default : +return count; + } + +if (count) + buf[count -1 ] ='\n' ; + +return count; +} +static ssize_t mcu_id_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -659,9 +789,21 @@ static struct gos_cfg_attr touchpad_enabled = { FEATURE_TOUCHPAD_ENABLE };LEGOS_DEVICE_ATTR_RW (touchpad_enabled,"enabled" , index, gamepad); static DEVICE_ATTR_RO_NAMED(touchpad_enabled_index, "enabled_index"); +static struct gos_cfg_attr touchpad_linux_mode = {CFG_LINUX_MODE }; +LEGOS_DEVICE_ATTR_RW (touchpad_linux_mode,"linux_mode" , index, touchpad); +static DEVICE_ATTR_RO_NAMED(touchpad_linux_mode_index, "linux_mode_index"); + +static struct gos_cfg_attr touchpad_windows_mode = {CFG_WINDOWS_MODE }; +LEGOS_DEVICE_ATTR_RW (touchpad_windows_mode,"windows_mode" , index, touchpad); +static DEVICE_ATTR_RO_NAMED(touchpad_windows_mode_index, "windows_mode_index"); +static struct attribute *legos_touchpad_attrs[] = { &dev_attr_touchpad_enabled.attr, &dev_attr_touchpad_enabled_index.attr, + &dev_attr_touchpad_linux_mode.attr, + &dev_attr_touchpad_linux_mode_index.attr, + &dev_attr_touchpad_windows_mode.attr, + &dev_attr_touchpad_windows_mode_index.attr,NULL , };
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 14/19 HID: hid-lenovo-go-s: Add RGB LED control interface
In reply to Derek J. ClarkAdds an LED multicolor class device and attribute group for controlling the RGB of the Left and right joystick rings. In addition to the standard led_cdev attributes, additional attributes that allow for the control of the effect (monocolor, breathe, rainbow, and chroma), speed of the effect change, an enable toggle, and profile.
---
v6:
- Make local attributes static.
- Use NULL instead of 0 in mcu_propery_out when there is no data.
v4:
- Cleaner formatting on multiple debug messages.
--- drivers/hid/hid-lenovo-go-s.c | 422 ++++++++++++++++++++++++++++++++++ 1 file changed, 422 insertions(+)
drivers/hid/hid-lenovo-go-s.c +422 -0
@@ -16,6 +16,7 @@#include <linux/hid.h> #include <linux/jiffies.h> #include <linux/kstrtox.h> +#include <linux/led-class-multicolor.h> #include <linux/mutex.h> #include <linux/printk.h> #include <linux/string.h>
@@ -34,6 +35,7 @@ static struct hid_gos_cfg { struct delayed_work gos_cfg_setup; struct completion send_cmd_complete; + struct led_classdev *led_cdev; struct hid_device *hdev; struct mutex cfg_mutex; /*ensure single synchronous output report*/ u8 gp_auto_sleep_time;
@@ -45,7 +47,11 @@ static struct hid_gos_cfg {u8 mcu_id[12 ];u8 mouse_step;u8 os_mode; +u8 rgb_effect;u8 rgb_en; +u8 rgb_mode; +u8 rgb_profile; +u8 rgb_speed;u8 tp_en;u8 tp_linux_mode;u8 tp_windows_mode;
@@ -163,6 +169,38 @@ enum touchpad_config_index { }; +enum rgb_mode_index { +RGB_MODE_DYNAMIC , +RGB_MODE_CUSTOM , +}; + +static const char *const rgb_mode_text[] = { + [RGB_MODE_DYNAMIC ] ="dynamic" , + [RGB_MODE_CUSTOM ] ="custom" , +}; + +enum rgb_effect_index { +RGB_EFFECT_MONO , +RGB_EFFECT_BREATHE , +RGB_EFFECT_CHROMA , +RGB_EFFECT_RAINBOW , +}; + +static const char *const rgb_effect_text[] = { + [RGB_EFFECT_MONO ] ="monocolor" , + [RGB_EFFECT_BREATHE ] ="breathe" , + [RGB_EFFECT_CHROMA ] ="chroma" , + [RGB_EFFECT_RAINBOW ] ="rainbow" , +}; + +enum rgb_config_index { +LIGHT_MODE_SEL =0x01 , +LIGHT_PROFILE_SEL , +USR_LIGHT_PROFILE_1 , +USR_LIGHT_PROFILE_2 , +USR_LIGHT_PROFILE_3 , +}; +static int hid_gos_version_event (u8 *data) {struct version_report *ver_rep = (struct version_report *)data;
@@ -241,6 +279,39 @@ static int hid_gos_touchpad_event(struct command_report *cmd_rep)return ret; } +static int hid_gos_light_event (struct command_report *cmd_rep) +{ +struct led_classdev_mc *mc_cdev; +int ret =0 ; + +switch (cmd_rep->sub_cmd) { +case LIGHT_MODE_SEL : + drvdata.rgb_mode = cmd_rep->data[0 ]; + ret =0 ; +break ; +case LIGHT_PROFILE_SEL : + drvdata.rgb_profile = cmd_rep->data[0 ]; + ret =0 ; +break ; +case USR_LIGHT_PROFILE_1 : +case USR_LIGHT_PROFILE_2 : +case USR_LIGHT_PROFILE_3 : + mc_cdev =lcdev_to_mccdev (drvdata.led_cdev); + drvdata.rgb_effect = cmd_rep->data[0 ]; + mc_cdev->subled_info[0 ].intensity = cmd_rep->data[1 ]; + mc_cdev->subled_info[1 ].intensity = cmd_rep->data[2 ]; + mc_cdev->subled_info[2 ].intensity = cmd_rep->data[3 ]; + drvdata.led_cdev->brightness = cmd_rep->data[4 ]; + drvdata.rgb_speed = cmd_rep->data[5 ]; + ret =0 ; +break ; +default : + ret = -EINVAL ; +break ; + } +return ret; +} +static int hid_gos_set_event_return (struct command_report *cmd_rep) {if (cmd_rep->data[0 ] !=0 )
@@ -291,7 +362,11 @@ static int hid_gos_raw_event(struct hid_device *hdev, struct hid_report *report,case GET_TP_PARAM : ret =hid_gos_touchpad_event (cmd_rep);break ; +case GET_RGB_CFG : + ret =hid_gos_light_event (cmd_rep); +break ;case SET_GAMEPAD_CFG : +case SET_RGB_CFG :case SET_TP_PARAM : ret =hid_gos_set_event_return (cmd_rep);break ;
@@ -666,6 +741,274 @@ static ssize_t mcu_id_show(struct device *dev, struct device_attribute *attr,return sysfs_emit (buf,"%*phN\n" ,12 , &drvdata.mcu_id); } +static int rgb_cfg_call (struct hid_device *hdev,enum mcu_command_index cmd, +enum rgb_config_index index,u8 *val,size_t size) +{ +if (cmd !=SET_RGB_CFG && cmd !=GET_RGB_CFG ) +return -EINVAL ; + +if (index <LIGHT_MODE_SEL || index >USR_LIGHT_PROFILE_3 ) +return -EINVAL ; + +return mcu_property_out (hdev, cmd, index, val, size); +} + +static int rgb_attr_show (void ) +{ +enum rgb_config_index index; + + index = drvdata.rgb_profile +2 ; + +return rgb_cfg_call (drvdata.hdev,GET_RGB_CFG , index,NULL ,0 ); +}; + +static ssize_t rgb_effect_store (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t count) +{ +struct led_classdev_mc *mc_cdev =lcdev_to_mccdev (drvdata.led_cdev); +enum rgb_config_index index; +u8 effect; +int ret; + + ret =sysfs_match_string (rgb_effect_text, buf); +if (ret <0 ) +return ret; + + effect = ret; + index = drvdata.rgb_profile +2 ; +u8 rgb_profile[6 ] = { effect, + mc_cdev->subled_info[0 ].intensity, + mc_cdev->subled_info[1 ].intensity, + mc_cdev->subled_info[2 ].intensity, + drvdata.led_cdev->brightness, + drvdata.rgb_speed }; + + ret =rgb_cfg_call (drvdata.hdev,SET_RGB_CFG , index, rgb_profile,6 ); +if (ret) +return ret; + + drvdata.rgb_effect = effect; +return count; +}; + +static ssize_t rgb_effect_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +int ret; + + ret =rgb_attr_show (); +if (ret) +return ret; + +if (drvdata.rgb_effect >=ARRAY_SIZE (rgb_effect_text)) +return -EINVAL ; + +return sysfs_emit (buf,"%s\n" , rgb_effect_text[drvdata.rgb_effect]); +} + +static ssize_t rgb_effect_index_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +ssize_t count =0 ; +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (rgb_effect_text); i++) + count +=sysfs_emit_at (buf, count,"%s " , rgb_effect_text[i]); + +if (count) + buf[count -1 ] ='\n' ; + +return count; +} + +static ssize_t rgb_speed_store (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t count) +{ +struct led_classdev_mc *mc_cdev =lcdev_to_mccdev (drvdata.led_cdev); +enum rgb_config_index index; +int val =0 ; +int ret; + + ret =kstrtoint (buf,10 , &val); +if (ret) +return ret; + +if (val <0 || val >100 ) +return -EINVAL ; + + index = drvdata.rgb_profile +2 ; +u8 rgb_profile[6 ] = { drvdata.rgb_effect, + mc_cdev->subled_info[0 ].intensity, + mc_cdev->subled_info[1 ].intensity, + mc_cdev->subled_info[2 ].intensity, + drvdata.led_cdev->brightness, + val }; + + ret =rgb_cfg_call (drvdata.hdev,SET_RGB_CFG , index, rgb_profile,6 ); +if (ret) +return ret; + + drvdata.rgb_speed = val; + +return count; +}; + +static ssize_t rgb_speed_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +int ret; + + ret =rgb_attr_show (); +if (ret) +return ret; + +if (drvdata.rgb_speed >100 ) +return -EINVAL ; + +return sysfs_emit (buf,"%hhu\n" , drvdata.rgb_speed); +} + +static ssize_t rgb_speed_range_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"0-100\n" ); +} + +static ssize_t rgb_mode_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +int ret; +u8 val; + + ret =sysfs_match_string (rgb_mode_text, buf); +if (ret <=0 ) +return ret; + + val = ret; + + ret =rgb_cfg_call (drvdata.hdev,SET_RGB_CFG ,LIGHT_MODE_SEL , &val, +1 ); +if (ret) +return ret; + + drvdata.rgb_mode = val; + +return count; +}; + +static ssize_t rgb_mode_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +int ret; + + ret =rgb_cfg_call (drvdata.hdev,GET_RGB_CFG ,LIGHT_MODE_SEL ,NULL ,0 ); +if (ret) +return ret; + +if (drvdata.rgb_mode >=ARRAY_SIZE (rgb_mode_text)) +return -EINVAL ; + +return sysfs_emit (buf,"%s\n" , rgb_mode_text[drvdata.rgb_mode]); +}; + +static ssize_t rgb_mode_index_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +ssize_t count =0 ; +unsigned int i; + +for (i =1 ; i <ARRAY_SIZE (rgb_mode_text); i++) + count +=sysfs_emit_at (buf, count,"%s " , rgb_mode_text[i]); + +if (count) + buf[count -1 ] ='\n' ; + +return count; +} + +static ssize_t rgb_profile_store (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t count) +{ +size_t size =1 ; +int ret; +u8 val; + + ret =kstrtou8 (buf,10 , &val); +if (ret <0 ) +return ret; + +if (val <1 || val >3 ) +return -EINVAL ; + + ret =rgb_cfg_call (drvdata.hdev,SET_RGB_CFG ,LIGHT_PROFILE_SEL , &val, size); +if (ret) +return ret; + + drvdata.rgb_profile = val; + +return count; +}; + +static ssize_t rgb_profile_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +int ret; + + ret =rgb_cfg_call (drvdata.hdev,GET_RGB_CFG ,LIGHT_PROFILE_SEL ,NULL ,0 ); +if (ret) +return ret; + +if (drvdata.rgb_profile <1 || drvdata.rgb_profile >3 ) +return -EINVAL ; + +return sysfs_emit (buf,"%hhu\n" , drvdata.rgb_profile); +}; + +static ssize_t rgb_profile_range_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"1-3\n" ); +} + +static void hid_gos_brightness_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct led_classdev_mc *mc_cdev =lcdev_to_mccdev (drvdata.led_cdev); +enum rgb_config_index index; +int ret; + +if (brightness > led_cdev->max_brightness) { +dev_err (led_cdev->dev,"Invalid argument\n" ); +return ; + } + + index = drvdata.rgb_profile +2 ; +u8 rgb_profile[6 ] = { drvdata.rgb_effect, + mc_cdev->subled_info[0 ].intensity, + mc_cdev->subled_info[1 ].intensity, + mc_cdev->subled_info[2 ].intensity, + brightness, + drvdata.rgb_speed }; + + ret =rgb_cfg_call (drvdata.hdev,SET_RGB_CFG , index, rgb_profile,6 ); +switch (ret) { +case 0 : + led_cdev->brightness = brightness; +break ; +case -ENODEV :/* during switch to IAP -ENODEV is expected */ +case -ENOSYS :/* during rmmod -ENOSYS is expected */ +dev_dbg (led_cdev->dev,"Failed to write RGB profile: %i\n" , + ret); +break ; +default : +dev_err (led_cdev->dev,"Failed to write RGB profile: %i\n" , + ret); + }; +} +#define LEGOS_DEVICE_ATTR_RW (_name, _attrname, _rtype, _group) \ static ssize_t _name##_store(struct device *dev, \ struct device_attribute *attr, \
@@ -821,6 +1164,70 @@ static const struct attribute_group *top_level_attr_groups[] = { NULL, }; +/* RGB */ +static struct gos_cfg_attr rgb_enabled = {FEATURE_RGB_ENABLE }; +LEGOS_DEVICE_ATTR_RW (rgb_enabled,"enabled" , index, gamepad); +static DEVICE_ATTR_RO_NAMED(rgb_enabled_index, "enabled_index"); + +static DEVICE_ATTR_RW_NAMED(rgb_effect, "effect"); +static DEVICE_ATTR_RO_NAMED(rgb_effect_index, "effect_index"); +static DEVICE_ATTR_RW_NAMED(rgb_mode, "mode"); +static DEVICE_ATTR_RO_NAMED(rgb_mode_index, "mode_index"); +static DEVICE_ATTR_RW_NAMED(rgb_profile, "profile"); +static DEVICE_ATTR_RO_NAMED(rgb_profile_range, "profile_range"); +static DEVICE_ATTR_RW_NAMED(rgb_speed, "speed"); +static DEVICE_ATTR_RO_NAMED(rgb_speed_range, "speed_range"); + +static struct attribute *gos_rgb_attrs[] = { + &dev_attr_rgb_enabled.attr, + &dev_attr_rgb_enabled_index.attr, + &dev_attr_rgb_effect.attr, + &dev_attr_rgb_effect_index.attr, + &dev_attr_rgb_mode.attr, + &dev_attr_rgb_mode_index.attr, + &dev_attr_rgb_profile.attr, + &dev_attr_rgb_profile_range.attr, + &dev_attr_rgb_speed.attr, + &dev_attr_rgb_speed_range.attr, +NULL , +}; + +static struct attribute_group rgb_attr_group = { + .attrs = gos_rgb_attrs, +}; + +static struct mc_subled gos_rgb_subled_info[] = { + { + .color_index =LED_COLOR_ID_RED , + .brightness =0x50 , + .intensity =0x24 , + .channel =0x1 , + }, + { + .color_index =LED_COLOR_ID_GREEN , + .brightness =0x50 , + .intensity =0x22 , + .channel =0x2 , + }, + { + .color_index =LED_COLOR_ID_BLUE , + .brightness =0x50 , + .intensity =0x99 , + .channel =0x3 , + }, +}; + +static struct led_classdev_mc gos_cdev_rgb = { + .led_cdev = { + .name ="go_s:rgb:joystick_rings" , + .brightness =0x50 , + .max_brightness =0x64 , + .brightness_set = hid_gos_brightness_set, + }, + .num_colors =ARRAY_SIZE (gos_rgb_subled_info), + .subled_info = gos_rgb_subled_info, +}; +static void cfg_setup (struct work_struct *work) {int ret;
@@ -856,6 +1263,21 @@ static int hid_gos_cfg_probe(struct hid_device *hdev,return ret; } + ret =devm_led_classdev_multicolor_register (&hdev->dev, &gos_cdev_rgb); +if (ret) { +dev_err_probe (&hdev->dev, ret,"Failed to create RGB device\n" ); +return ret; + } + + ret =devm_device_add_group (gos_cdev_rgb.led_cdev.dev, &rgb_attr_group); +if (ret) { +dev_err_probe (&hdev->dev, ret, +"Failed to create RGB configuratiion attributes\n" ); +return ret; + } + + drvdata.led_cdev = &gos_cdev_rgb.led_cdev; +init_completion (&drvdata.send_cmd_complete);/* Executing calls prior to returning from probe will lock the MCU. Schedule
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 15/19 HID: hid-lenovo-go-s: Add IMU and Touchpad RO Attributes
In reply to Derek J. ClarkAdds attributes for reporting the touchpad manufacturer, version, and IMU manufacturer.
---
v6:
- Make local attributes static.
- Use NULL instead of 0 in mcu_propery_out when there is no data.
v4:
- Cache RO values at probe instead of calling them at request. Values don't change and reading the touchpad data is slow.
v3:
- Fix bug where the touchpad attributes were assigned to the touchpad _show function instead of the test _show function.
--- drivers/hid/hid-lenovo-go-s.c | 124 ++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+)
drivers/hid/hid-lenovo-go-s.c +124 -0
@@ -43,6 +43,7 @@ static struct hid_gos_cfg {u8 gp_mode;u8 gp_poll_rate;u8 imu_bypass_en; +u8 imu_manufacturer;u8 imu_sensor_en;u8 mcu_id[12 ];u8 mouse_step;
@@ -55,6 +56,8 @@ static struct hid_gos_cfg {u8 tp_en;u8 tp_linux_mode;u8 tp_windows_mode; +u8 tp_version; +u8 tp_manufacturer; } drvdata;struct gos_cfg_attr {
@@ -201,6 +204,36 @@ enum rgb_config_index { USR_LIGHT_PROFILE_3, }; +enum test_command_index { +TEST_TP_MFR =0x02 , +TEST_IMU_MFR , +TEST_TP_VER , +}; + +enum tp_mfr_index { +TP_NONE , +TP_BETTERLIFE , +TP_SIPO , +}; + +static const char *const touchpad_manufacturer_text[] = { + [TP_NONE ] ="none" , + [TP_BETTERLIFE ] ="BetterLife" , + [TP_SIPO ] ="SIPO" , +}; + +enum imu_mfr_index { +IMU_NONE , +IMU_BOSCH , +IMU_ST , +}; + +static const char *const imu_manufacturer_text[] = { + [IMU_NONE ] ="none" , + [IMU_BOSCH ] ="Bosch" , + [IMU_ST ] ="ST" , +}; +static int hid_gos_version_event (u8 *data) {struct version_report *ver_rep = (struct version_report *)data;
@@ -279,6 +312,30 @@ static int hid_gos_touchpad_event(struct command_report *cmd_rep)return ret; } +static int hid_gos_pl_test_event (struct command_report *cmd_rep) +{ +int ret =0 ; + +switch (cmd_rep->sub_cmd) { +case TEST_TP_MFR : + drvdata.tp_manufacturer = cmd_rep->data[0 ]; + ret =0 ; +break ; +case TEST_IMU_MFR : + drvdata.imu_manufacturer = cmd_rep->data[0 ]; + ret =0 ; +break ; +case TEST_TP_VER : + drvdata.tp_version = cmd_rep->data[0 ]; + ret =0 ; +break ; +default : + ret = -EINVAL ; +break ; + } +return ret; +} +static int hid_gos_light_event (struct command_report *cmd_rep) {struct led_classdev_mc *mc_cdev;
@@ -362,6 +419,9 @@ static int hid_gos_raw_event(struct hid_device *hdev, struct hid_report *report,case GET_TP_PARAM : ret =hid_gos_touchpad_event (cmd_rep);break ; +case GET_PL_TEST : + ret =hid_gos_pl_test_event (cmd_rep); +break ;case GET_RGB_CFG : ret =hid_gos_light_event (cmd_rep);break ;
@@ -735,6 +795,37 @@ static ssize_t touchpad_property_options(struct device *dev,return count; } +static ssize_t test_property_show (struct device *dev, +struct device_attribute *attr,char *buf, +enum test_command_index index) +{ +size_t count =0 ; +u8 i; + +switch (index) { +case TEST_TP_MFR : + i = drvdata.tp_manufacturer; +if (i >=ARRAY_SIZE (touchpad_manufacturer_text)) +return -EINVAL ; + count =sysfs_emit (buf,"%s\n" , touchpad_manufacturer_text[i]); +break ; +case TEST_IMU_MFR : + i = drvdata.imu_manufacturer; +if (i >=ARRAY_SIZE (imu_manufacturer_text)) +return -EINVAL ; + count =sysfs_emit (buf,"%s\n" , imu_manufacturer_text[i]); +break ; +case TEST_TP_VER : + count =sysfs_emit (buf,"%u\n" , drvdata.tp_version); +break ; +default : + count = -EINVAL ; +break ; + } + +return count; +} +static ssize_t mcu_id_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -1076,6 +1167,9 @@ static struct gos_cfg_attr imu_bypass_enabled = { FEATURE_IMU_BYPASS };LEGOS_DEVICE_ATTR_RW (imu_bypass_enabled,"bypass_enabled" , index, gamepad); static DEVICE_ATTR_RO_NAMED(imu_bypass_enabled_index, "bypass_enabled_index"); +static struct gos_cfg_attr imu_manufacturer = {TEST_IMU_MFR }; +LEGOS_DEVICE_ATTR_RO (imu_manufacturer,"manufacturer" , test); +static struct gos_cfg_attr imu_sensor_enabled = {FEATURE_IMU_ENABLE };LEGOS_DEVICE_ATTR_RW (imu_sensor_enabled,"sensor_enabled" , index, gamepad); static DEVICE_ATTR_RO_NAMED(imu_sensor_enabled_index, "sensor_enabled_index");
@@ -1083,6 +1177,7 @@ static DEVICE_ATTR_RO_NAMED(imu_sensor_enabled_index, "sensor_enabled_index");static struct attribute *legos_imu_attrs[] = { &dev_attr_imu_bypass_enabled.attr, &dev_attr_imu_bypass_enabled_index.attr, + &dev_attr_imu_manufacturer.attr, &dev_attr_imu_sensor_enabled.attr, &dev_attr_imu_sensor_enabled_index.attr,NULL ,
@@ -1136,6 +1231,12 @@ static struct gos_cfg_attr touchpad_linux_mode = { CFG_LINUX_MODE };LEGOS_DEVICE_ATTR_RW (touchpad_linux_mode,"linux_mode" , index, touchpad); static DEVICE_ATTR_RO_NAMED(touchpad_linux_mode_index, "linux_mode_index"); +static struct gos_cfg_attr touchpad_manufacturer = {TEST_TP_MFR }; +LEGOS_DEVICE_ATTR_RO (touchpad_manufacturer,"manufacturer" , test); + +static struct gos_cfg_attr touchpad_version = {TEST_TP_VER }; +LEGOS_DEVICE_ATTR_RO (touchpad_version,"version" , test); +static struct gos_cfg_attr touchpad_windows_mode = {CFG_WINDOWS_MODE };LEGOS_DEVICE_ATTR_RW (touchpad_windows_mode,"windows_mode" , index, touchpad); static DEVICE_ATTR_RO_NAMED(touchpad_windows_mode_index, "windows_mode_index");
@@ -1145,6 +1246,8 @@ static struct attribute *legos_touchpad_attrs[] = { &dev_attr_touchpad_enabled_index.attr, &dev_attr_touchpad_linux_mode.attr, &dev_attr_touchpad_linux_mode_index.attr, + &dev_attr_touchpad_manufacturer.attr, + &dev_attr_touchpad_version.attr, &dev_attr_touchpad_windows_mode.attr, &dev_attr_touchpad_windows_mode_index.attr, NULL,
@@ -1245,6 +1348,27 @@ static void cfg_setup(struct work_struct *work)dev_err (&drvdata.hdev->dev,"Failed to retrieve MCU Version: %i\n" , ret);return ; } + + ret =mcu_property_out (drvdata.hdev,GET_PL_TEST ,TEST_TP_MFR ,NULL ,0 ); +if (ret) { +dev_err (&drvdata.hdev->dev, +"Failed to retrieve Touchpad Manufacturer: %i\n" , ret); +return ; + } + + ret =mcu_property_out (drvdata.hdev,GET_PL_TEST ,TEST_TP_VER ,NULL ,0 ); +if (ret) { +dev_err (&drvdata.hdev->dev, +"Failed to retrieve Touchpad Firmware Version: %i\n" , ret); +return ; + } + + ret =mcu_property_out (drvdata.hdev,GET_PL_TEST ,TEST_IMU_MFR ,NULL ,0 ); +if (ret) { +dev_err (&drvdata.hdev->dev, +"Failed to retrieve IMU Manufacturer: %i\n" , ret); +return ; + } } static int hid_gos_cfg_probe(struct hid_device *hdev,
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 16/19 HID: Add documentation for Lenovo Legion Go drivers
In reply to Derek J. ClarkAdds ABI documentation for the hid-lenovo-go-s and hid-lenovo-go drivers.
---
v3:
- Remove excess + from every line of patch.
--- .../ABI/testing/sysfs-driver-hid-lenovo-go | 724 ++++++++++++++++++ .../ABI/testing/sysfs-driver-hid-lenovo-go-s | 304 ++++++++ MAINTAINERS | 2 + 3 files changed, 1030 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-lenovo-go create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s
Documentation/ABI/testing/sysfs-driver-hid-lenovo-go new file +724 -0
@@ -0,0 +1,724 @@ +What: /sys/class/leds/go:rgb:joystick_rings/effect +Date: April 2026 +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 and Go 2 line of handheld devices. + +What: /sys/class/leds/go:rgb:joystick_rings/effect_index +Date: April 2026 +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 and Go 2 line of handheld devices. + +What: /sys/class/leds/go:rgb:joystick_rings/enabled +Date: April 2026 +Contact: [email protected] +Description: This controls enabling or disabling the RGB interface. + + Values are true or false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/class/leds/go:rgb:joystick_rings/enabled_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the enabled attribute. + + Values are true or false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/class/leds/go:rgb:joystick_rings/mode +Date: April 2026 +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 and Go 2 line of handheld devices. + +What: /sys/class/leds/go:rgb:joystick_rings/mode_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the mode attribute. + + Values are dynamic or custom. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/class/leds/go:rgb:joystick_rings/profile +Date: April 2026 +Contact: [email protected] +Description: This controls selecting the configured RGB profile. + + Values are 1-3. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/class/leds/go:rgb:joystick_rings/profile_range +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the profile attribute. + + Values are 1-3. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/class/leds/go:rgb:joystick_rings/speed +Date: April 2026 +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 and Go 2 line of handheld devices. + +What: /sys/class/leds/go:rgb:joystick_rings/speed_range +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the speed attribute. + + Values are 0-100. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/firmware_version +Date: April 2026 +Contact: [email protected] +Description: This displays the firmware version of the internal MCU. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/fps_mode_dpi +Date: April 2026 +Contact: [email protected] +Description: This displays the DPI of the right handle when the FPS mode switch is on. + + Values are 500, 800, 1200, and 1800. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/fps_mode_dpi_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the fps_mode_dpi attribute. + + Values are 500, 800, 1200, and 1800. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/hardware_generation +Date: April 2026 +Contact: [email protected] +Description: This displays the hardware generation of the internal MCU. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/hardware_version +Date: April 2026 +Contact: [email protected] +Description: This displays the hardware version of the internal MCU. + + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/auto_sleep_time +Date: April 2026 +Contact: [email protected] +Description: This controls the sleep timer due to inactivity for the left removable controller. + + Values are 0-255. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/auto_sleep_time_range +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the left_handle/auto_sleep_time attribute. + + Values are 0-255. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/calibrate_gyro +Date: April 2026 +Contact: [email protected] +Description: This initiates or halts calibration of the left removable controller's IMU. + + Values are start, stop. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/calibrate_gyro_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the left_handle/calibrate_gyro attribute. + + Values are start, stop. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/calibrate_gyro_status +Date: April 2026 +Contact: [email protected] +Description: This displays the result of the last attempted calibration of the left removable controller's IMU. + + Values are unknown, success, failure. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/calibrate_joystick +Date: April 2026 +Contact: [email protected] +Description: This initiates or halts calibration of the left removable controller's joystick. + + Values are start, stop. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/calibrate_joystick_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the left_handle/calibrate_jotstick attribute. + + Values are start, stop. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/calibrate_joystick_status +Date: April 2026 +Contact: [email protected] +Description: This displays the result of the last attempted calibration of the left removable controller's joystick. + + Values are unknown, success, failure. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/calibrate_tirgger +Date: April 2026 +Contact: [email protected] +Description: This initiates or halts calibration of the left removable controller's trigger. + + Values are start, stop. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/calibrate_gyro_trigger +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the left_handle/calibrate_trigger attribute. + + Values are start, stop. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/calibrate_trigger_status +Date: April 2026 +Contact: [email protected] +Description: This displays the result of the last attempted calibration of the left removable controller's trigger. + + Values are unknown, success, failure. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/firmware_version +Date: April 2026 +Contact: [email protected] +Description: This displays the left removable controller's firmware version. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/hardware_generation +Date: April 2026 +Contact: [email protected] +Description: This displays the hardware generation of the left removable controller. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/hardware_version +Date: April 2026 +Contact: [email protected] +Description: This displays the hardware version of the left removable controller. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/imu_bypass_enabled +Date: April 2026 +Contact: [email protected] +Description: This controls enabling or disabling the IMU bypass function of the left removable controller. + + Values are true or false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/imu_bypass_enabled_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the left_handle/imu_bypass_enabled attribute. + + Values are true or false. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/imu_enabled +Date: April 2026 +Contact: [email protected] +Description: This controls enabling or disabling the IMU of the left removable controller. + + Values are true or false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/imu_enabled_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the left_handle/imu_enabled attribute. + + Values are true or false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/product_version +Date: April 2026 +Contact: [email protected] +Description: This displays the product version of the left removable controller. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/protocol_version +Date: April 2026 +Contact: [email protected] +Description: This displays the protocol version of the left removable controller. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/reset +Date: April 2026 +Contact: [email protected] +Description: Resets the left removable controller to factory defaults. + + Writing 1 to this path initiates. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/rumble_mode +Date: April 2026 +Contact: [email protected] +Description: This controls setting the response behavior for rumble events for the left removable controller. + + Values are fps, racing, standarg, spg, rpg. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/rumble_mode_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the left_handle/rumble_mode attribute. + + Values are fps, racing, standarg, spg, rpg. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/rumble_notification +Date: April 2026 +Contact: [email protected] +Description: This controls enabling haptic rumble events for the left removable controller. + + Values are true, false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/rumble_notification_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the left_handle/rumble_notification attribute. + + Values are true, false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/mode +Date: April 2026 +Contact: [email protected] +Description: This controls the operating mode of the built-in controller. + + Values are xinput or dinput. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/left_handle/mode_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the mode attribute. + + Values are xinput or dinput. + + Applies to Lenovo Legion Go and Go 2 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: April 2026 +Contact: [email protected] +Description: This controls the behavior of built in chord combinations. + + Values are windows or linux. + + Applies to Lenovo Legion Go and Go 2 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: April 2026 +Contact: [email protected] +Description: This displays the available options for the os_mode attribute. + + Values are windows or linux. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/product_version +Date: April 2026 +Contact: [email protected] +Description: This displays the product version of the internal MCU. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/protocol_version +Date: April 2026 +Contact: [email protected] +Description: This displays the protocol version of the internal MCU. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/reset_mcu +Date: April 2026 +Contact: [email protected] +Description: Resets the internal MCU to factory defaults. + + Writing 1 to this path initiates. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/auto_sleep_time +Date: April 2026 +Contact: [email protected] +Description: This controls the sleep timer due to inactivity for the right removable controller. + + Values are 0-255. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/auto_sleep_time_range +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the right_handle/auto_sleep_time attribute. + + Values are 0-255. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/calibrate_gyro +Date: April 2026 +Contact: [email protected] +Description: This initiates or halts calibration of the right removable controller's IMU. + + Values are start, stop. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/calibrate_gyro_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the right_handle/calibrate_gyro attribute. + + Values are start, stop. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/calibrate_gyro_status +Date: April 2026 +Contact: [email protected] +Description: This displays the result of the last attempted calibration of the right removable controller's IMU. + + Values are unknown, success, failure. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/calibrate_joystick +Date: April 2026 +Contact: [email protected] +Description: This initiates or halts calibration of the right removable controller's joystick. + + Values are start, stop. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/calibrate_joystick_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the right_handle/calibrate_jotstick attribute. + + Values are start, stop. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/calibrate_joystick_status +Date: April 2026 +Contact: [email protected] +Description: This displays the result of the last attempted calibration of the right removable controller's joystick. + + Values are unknown, success, failure. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/calibrate_tirgger +Date: April 2026 +Contact: [email protected] +Description: This initiates or halts calibration of the right removable controller's trigger. + + Values are start, stop. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/calibrate_gyro_trigger +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the right_handle/calibrate_trigger attribute. + + Values are start, stop. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/calibrate_trigger_status +Date: April 2026 +Contact: [email protected] +Description: This displays the result of the last attempted calibration of the right removable controller's trigger. + + Values are unknown, success, failure. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/firmware_version +Date: April 2026 +Contact: [email protected] +Description: This displays the right removable controller's firmware version. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/hardware_generation +Date: April 2026 +Contact: [email protected] +Description: This displays the hardware generation of the right removable controller. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/hardware_version +Date: April 2026 +Contact: [email protected] +Description: This displays the hardware version of the right removable controller. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/imu_bypass_enabled +Date: April 2026 +Contact: [email protected] +Description: This controls enabling or disabling the IMU bypass function of the right removable controller. + + Values are true or false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/imu_bypass_enabled_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the right_handle/imu_bypass_enabled attribute. + + Values are true or false. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/imu_enabled +Date: April 2026 +Contact: [email protected] +Description: This controls enabling or disabling the IMU of the right removable controller. + + Values are true or false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/imu_enabled_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the right_handle/imu_enabled attribute. + + Values are true or false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/product_version +Date: April 2026 +Contact: [email protected] +Description: This displays the product version of the right removable controller. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/protocol_version +Date: April 2026 +Contact: [email protected] +Description: This displays the protocol version of the right removable controller. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/reset +Date: April 2026 +Contact: [email protected] +Description: Resets the right removable controller to factory defaults. + + Writing 1 to this path initiates. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/rumble_mode +Date: April 2026 +Contact: [email protected] +Description: This controls setting the response behavior for rumble events for the right removable controller. + + Values are fps, racing, standarg, spg, rpg. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/rumble_mode_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the right_handle/rumble_mode attribute. + + Values are fps, racing, standarg, spg, rpg. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/rumble_notification +Date: April 2026 +Contact: [email protected] +Description: This controls enabling haptic rumble events for the right removable controller. + + Values are true, false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/right_handle/rumble_notification_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the right_handle/rumble_notification attribute. + + Values are true, false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/rumble_intensity +Date: April 2026 +Contact: [email protected] +Description: This controls setting the rumble intensity for both removable controllers. + + Values are off, low, medium, high. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/rumble_intensity_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the rumble_intensity attribute. + + Values are off, low, medium, high. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/enabled +Date: April 2026 +Contact: [email protected] +Description: This controls enabling or disabling the touchpad. + + Values are true, false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/enabled_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the touchpad/enabled attribute. + + Values are true, false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/vibration_enabled +Date: April 2026 +Contact: [email protected] +Description: This controls enabling haptic rumble events for the touchpad. + + Values are true, false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/vibration_enabled_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the touchpad/vibration_enabled attribute. + + Values are true, false. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/vibration_intensity +Date: April 2026 +Contact: [email protected] +Description: This controls setting the intensity of the touchpad haptics. + + Values are off, low, medium, high. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/vibration_intensity_index +Date: April 2026 +Contact: [email protected] +Description: This displays the available options for the touchpad/vibration_intensity attribute. + + Values are off, low, medium, high. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/tx_dongle/firmware_version +Date: April 2026 +Contact: [email protected] +Description: This displays the firmware version of the internal wireless transmission dongle. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/tx_dongle/hardware_generation +Date: April 2026 +Contact: [email protected] +Description: This displays the hardware generation of the internal wireless transmission dongle. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/tx_dongle/hardware_version +Date: April 2026 +Contact: [email protected] +Description: This displays the hardware version of the internal wireless transmission dongle. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/tx_dongle/product_version +Date: April 2026 +Contact: [email protected] +Description: This displays the product version of the internal wireless transmission dongle. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/tx_dongle/protocol_version +Date: April 2026 +Contact: [email protected] +Description: This displays the protocol version of the internal wireless transmission dongle. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. +
Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s new file +304 -0
304 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -14420,6 +14420,8 @@ M: Derek J. Clark <[email protected]> M: Mark Pearson <[email protected]> L: [email protected] S: Maintained +F: Documentation/ABI/testing/sysfs-driver-hid-lenovo-go +F: Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s F: drivers/hid/hid-lenovo-go-s.c F: drivers/hid/hid-lenovo-go.c F: drivers/hid/hid-lenovo.c
Signature · 1 line
2.53.0
Re: [PATCH v6 16/19] HID: Add documentation for Lenovo Legion Go drivers
Hi,
Quoted 8 lines · Derek J. Clark
Adds ABI documentation for the hid-lenovo-go-s and hid-lenovo-go drivers.
Reviewed-by Mark Pearson <[email protected]>Signed-off-by Derek J. Clark <[email protected]>---
v3:
- Remove excess + from every line of patch.
Quoted 7 lines
--- .../ABI/testing/sysfs-driver-hid-lenovo-go | 724 ++++++++++++++++++ .../ABI/testing/sysfs-driver-hid-lenovo-go-s | 304 ++++++++ MAINTAINERS | 2 + 3 files changed, 1030 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-lenovo-go create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s
This (commit 168c91839139 in next-20260311) causes a lot of new warnings in "make htmldocs" such as:
WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/os_mode is defined 2 times: /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:364; /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:234
WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/os_mode_index is defined 2 times: /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:373; /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:243
WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/enabled is defined 2 times: /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:636; /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:252 [snip]
Please fix.
Thanks, Akira
Derek John Clark
maintainerRe: [PATCH v6 16/19] HID: Add documentation for Lenovo Legion Go drivers
Quoted 23 lines · Akira Yokosawa
Hi,
Quoted 8 lines · Derek J. Clark
Adds ABI documentation for the hid-lenovo-go-s and hid-lenovo-go drivers.
Reviewed-by Mark Pearson <[email protected]>Signed-off-by Derek J. Clark <[email protected]>---
v3:
- Remove excess + from every line of patch.Quoted 7 lines
--- .../ABI/testing/sysfs-driver-hid-lenovo-go | 724 ++++++++++++++++++ .../ABI/testing/sysfs-driver-hid-lenovo-go-s | 304 ++++++++ MAINTAINERS | 2 + 3 files changed, 1030 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-lenovo-go create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-sThis (commit
168c91839139in next-20260311) causes a lot of new warnings in "make htmldocs" such as:
Quoted 8 lines
WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/os_mode is defined 2 times: /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:364; /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:234
WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/os_mode_index is defined 2 times: /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:373; /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:243
WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/enabled is defined 2 times: /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:636; /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:252 [snip]Please fix.
Thanks, Akira
Akira,
What would an appropriate solution look like? There are two separate drivers in this series that are modeled to provide a sysfs that is as close to each other as possible. Because of that, they do end up having identical attributes for many of the implemented features. In most cases they are prefixed in the sysfs by a different component name, but that isn't the case for os_mode or touchpad/enabled. I could combine documentation for both drivers and de-duplicate, but I'm not sure what that would be called, sysfs-driver-hid-lenovo-go? Add them all to hid-lenovo docs?
If I do that there are some additional de-duplication that could reduce the total number of lines. I.E
What: /sys/class/leds/[go|go_s]:rgb:joystick_rings/effect
Would that syntax be alright? Some of them get a little excessive, for
example the auto sleep time is defined three times and would be
combined to something like this:
What: /sys/bus/usb/devices/<busnum>-<devnum>:<config
num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/[left_handle|right_handle|gamepad]/auto_sleep_time
Otherwise, is there some way to flag the same attribute defined in two separate documents provided by two drivers as not being duplicates? Thanks,
Derek
Re: [PATCH v6 16/19] HID: Add documentation for Lenovo Legion Go drivers
Hi!
Quoted 28 lines · Derek John Clark
Quoted 27 lines · Akira Yokosawa
Quoted 8 lines · Derek J. Clark
Adds ABI documentation for the hid-lenovo-go-s and hid-lenovo-go drivers.
Reviewed-by Mark Pearson <[email protected]>Signed-off-by Derek J. Clark <[email protected]>---
v3:
- Remove excess + from every line of patch.Quoted 7 lines
--- .../ABI/testing/sysfs-driver-hid-lenovo-go | 724 ++++++++++++++++++ .../ABI/testing/sysfs-driver-hid-lenovo-go-s | 304 ++++++++ MAINTAINERS | 2 + 3 files changed, 1030 insertions(+)create mode 100644
Documentation/ABI/testing/sysfs-driver-hid-lenovo-gocreate mode 100644Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-sThis (commit
168c91839139in next-20260311) causes a lot of new warnings in "make htmldocs" such as:WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/os_mode is defined 2 times: /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:364; /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:234
WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/os_mode_index is defined 2 times: /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:373; /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:243
WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/enabled is defined 2 times: /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:636; /<...>/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:252 [snip]Please fix.
Quoted 8 lines
Quoted 1 line
Thanks, Akira
Akira,
What would an appropriate solution look like? There are two separate drivers in this series that are modeled to provide a sysfs that is as close to each other as possible. Because of that, they do end up having identical attributes for many of the implemented features.
Just an idea, not sure whether it's feasible since I don't have the hardware for checking: Looking at drivers/hid/hid-lenovo-go-s.c and drivers/hid/hid-lenovo-go.c, it seems like they use different vendor IDs (USB_VENDOR_ID_QHE vs. USB_VENDOR_ID_LENOVO), so maybe the "<vendor-id>" part could be replaced with the real value in the entries to distinguish them in the kerneldocs?
Thomas
Derek J. Clark
maintainerPATCH v6 17/19 HID: hid-lenovo-go-s: Remove unneeded semicolon
In reply to Derek J. ClarkFrom: Chen Ni <[email protected]>
Remove unnecessary semicolons reported by Coccinelle/coccicheck and the semantic patch at scripts/coccinelle/misc/semicolon.cocci.
--- drivers/hid/hid-lenovo-go-s.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-lenovo-go-s.c +1 -1
@@ -1097,7 +1097,7 @@ static void hid_gos_brightness_set(struct led_classdev *led_cdev,default :dev_err (led_cdev->dev,"Failed to write RGB profile: %i\n" , ret); - }; + } }#define LEGOS_DEVICE_ATTR_RW (_name, _attrname, _rtype, _group) \
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 18/19 HID: hid-lenovo-go: Remove unneeded semicolon
In reply to Derek J. ClarkFrom: Chen Ni <[email protected]>
Remove unnecessary semicolons after switch statements and function bodies. Most issues were reported by Coccinelle/coccicheck using the semantic patch at scripts/coccinelle/misc/semicolon.cocci. Additional instances found during manual code review were also fixed.
--- drivers/hid/hid-lenovo-go.c | 52 ++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 26 deletions(-)
drivers/hid/hid-lenovo-go.c +26 -26
@@ -455,7 +455,7 @@ static int hid_go_feature_status_event(struct command_report *cmd_rep)return 0 ;default :return -EINVAL ; - }; + }case FEATURE_IMU_BYPASS :switch (cmd_rep->device_type) {case LEFT_CONTROLLER :
@@ -466,7 +466,7 @@ static int hid_go_feature_status_event(struct command_report *cmd_rep)return 0 ;default :return -EINVAL ; - }; + }break ;case FEATURE_LIGHT_ENABLE : drvdata.rgb_en = cmd_rep->data[0 ];
@@ -481,7 +481,7 @@ static int hid_go_feature_status_event(struct command_report *cmd_rep)return 0 ;default :return -EINVAL ; - }; + }break ;case FEATURE_TOUCHPAD_ENABLE : drvdata.tp_en = cmd_rep->data[0 ];
@@ -515,7 +515,7 @@ static int hid_go_motor_event(struct command_report *cmd_rep)return 0 ;default :return -EINVAL ; - }; + }break ;case RUMBLE_MODE :switch (cmd_rep->device_type) {
@@ -527,7 +527,7 @@ static int hid_go_motor_event(struct command_report *cmd_rep)return 0 ;default :return -EINVAL ; - }; + }case TP_VIBRATION_ENABLE : drvdata.tp_vibration_en = cmd_rep->data[0 ];return 0 ;
@@ -625,7 +625,7 @@ static int hid_go_os_mode_cfg_event(struct command_report *cmd_rep)return 0 ;default :return -EINVAL ; - }; + } }static int hid_go_set_event_return (struct command_report *cmd_rep)
@@ -699,14 +699,14 @@ static int hid_go_raw_event(struct hid_device *hdev, struct hid_report *report,default : ret = -EINVAL ;break ; - }; + }break ;case OS_MODE_DATA : ret =hid_go_os_mode_cfg_event (cmd_rep);break ;default : goto passthrough; - }; + }dev_dbg (&hdev->dev,"Rx data as raw input report: [%*ph]\n" ,GO_PACKET_SIZE , data);
@@ -925,7 +925,7 @@ static ssize_t feature_status_store(struct device *dev,break ;default :return -EINVAL ; - }; + }if (ret <0 )return ret;
@@ -1013,7 +1013,7 @@ static ssize_t feature_status_show(struct device *dev,break ;default :return -EINVAL ; - }; + } count =sysfs_emit (buf,"%u\n" , i);break ;case FEATURE_FPS_SWITCH_STATUS :
@@ -1032,7 +1032,7 @@ static ssize_t feature_status_show(struct device *dev,break ;default :return -EINVAL ; - }; + }return count; }
@@ -1070,7 +1070,7 @@ static ssize_t feature_status_options(struct device *dev,break ;default :return -EINVAL ; - }; + }if (count) buf[count -1 ] ='\n' ;
@@ -1111,7 +1111,7 @@ static ssize_t motor_config_store(struct device *dev, ret =sysfs_match_string (intensity_text, buf); val = ret;break ; - }; + }if (ret <0 )return ret;
@@ -1161,7 +1161,7 @@ static ssize_t motor_config_show(struct device *dev,break ;default :return -EINVAL ; - }; + }if (i >=ARRAY_SIZE (enabled_status_text))return -EINVAL ;
@@ -1177,7 +1177,7 @@ static ssize_t motor_config_show(struct device *dev,break ;default :return -EINVAL ; - }; + }if (i >=ARRAY_SIZE (rumble_mode_text))return -EINVAL ;
@@ -1197,7 +1197,7 @@ static ssize_t motor_config_show(struct device *dev, count =sysfs_emit (buf,"%s\n" , intensity_text[i]);break ; - }; + }return count; }
@@ -1232,7 +1232,7 @@ static ssize_t motor_config_options(struct device *dev, enabled_status_text[i]); }break ; - }; + }if (count) buf[count -1 ] ='\n' ;
@@ -1333,7 +1333,7 @@ static ssize_t device_status_show(struct device *dev,break ;default :return -EINVAL ; - }; + }if (i >=ARRAY_SIZE (cal_status_text))return -EINVAL ;
@@ -1459,7 +1459,7 @@ static int rgb_attr_show(void) index = drvdata.rgb_profile +3 ;return rgb_cfg_call (drvdata.hdev,GET_RGB_CFG , index,NULL ,0 ); -}; +} static ssize_t rgb_effect_store(struct device *dev, struct device_attribute *attr, const char *buf,
@@ -1489,7 +1489,7 @@ static ssize_t rgb_effect_store(struct device *dev, drvdata.rgb_effect = effect;return count; -}; +}static ssize_t rgb_effect_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -1555,7 +1555,7 @@ static ssize_t rgb_speed_store(struct device *dev, drvdata.rgb_speed = val;return count; -}; +}static ssize_t rgb_speed_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -1599,7 +1599,7 @@ static ssize_t rgb_mode_store(struct device *dev, struct device_attribute *attr, drvdata.rgb_mode = val;return count; -}; +}static ssize_t rgb_mode_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -1614,7 +1614,7 @@ static ssize_t rgb_mode_show(struct device *dev, struct device_attribute *attr,return -EINVAL ;return sysfs_emit (buf,"%s\n" , rgb_mode_text[drvdata.rgb_mode]); -}; +}static ssize_t rgb_mode_index_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -1653,7 +1653,7 @@ static ssize_t rgb_profile_store(struct device *dev, drvdata.rgb_profile = val;return count; -}; +}static ssize_t rgb_profile_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -1668,7 +1668,7 @@ static ssize_t rgb_profile_show(struct device *dev,return -EINVAL ;return sysfs_emit (buf,"%hhu\n" , drvdata.rgb_profile); -}; +}static ssize_t rgb_profile_range_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -1707,7 +1707,7 @@ static void hid_go_brightness_set(struct led_classdev *led_cdev,break ;default :dev_err (led_cdev->dev,"Failed to write RGB profile: %i\n" , ret); - }; + } }#define LEGO_DEVICE_ATTR_RW (_name, _attrname, _dtype, _rtype, _group) \
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v6 19/19 HID: hid-lenovo-go-s: Fix spelling mistake "configuratiion" -> "configuration"
In reply to Derek J. ClarkFrom: Colin Ian King <[email protected]>
There is a spelling mistake in a dev_err_probe message. Fix it.
--- drivers/hid/hid-lenovo-go-s.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-lenovo-go-s.c +1 -1
@@ -1396,7 +1396,7 @@ static int hid_gos_cfg_probe(struct hid_device *hdev, ret =devm_device_add_group (gos_cdev_rgb.led_cdev.dev, &rgb_attr_group);if (ret) {dev_err_probe (&hdev->dev, ret, -"Failed to create RGB configuratiion attributes\n" ); +"Failed to create RGB configuration attributes\n" );return ret; }
Signature · 1 line
2.53.0
Jiri Kosina
maintainerQuoted 9 lines · Derek J. Clark
Change Log
v6:
- Include multiple bug fixes from Ethan Tidmore.
- Make all local attributes static.
- Invert thergb_speedlogic for the go driver. On the Go this attribute sets a delay, so flip the logic to match Go S where the larger number means faster so userspace can target this consistently.
- Include 3 new patches that fix formatting issues with v5 authored by additional developers.
I've just finished going through the patchdiff and all the reports, and it seems that you've indeed addressed all of it.
This is now in hid.git#for-7.1/lenovo-v2.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs