diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2026-04-17 11:24:00 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2026-04-17 11:24:00 -0700 |
| commit | d97e7d7c304f87419921f740743f7baa99f40539 (patch) | |
| tree | af6b5ff258e9854490e205fb4ea348e08c6c125f | |
| parent | 87768582a440e7049a04e8af7383b86738d15b38 (diff) | |
| parent | b8a5774cd49996e8ef83b1637a9b547158f18de9 (diff) | |
| download | lwn-d97e7d7c304f87419921f740743f7baa99f40539.tar.gz lwn-d97e7d7c304f87419921f740743f7baa99f40539.zip | |
Merge tag 'hid-for-linus-2026041601' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid
Pull HID updates from Jiri Kosina:
"Core:
- fixed handling of 0-sized reports (Dmitry Torokhov)
- convert core code to __free() (Dmitry Torokhov)
- support for multiple batteries per HID device (Lucas Zampieri)
Drivers:
- support for rumble effects in winwing driver (Ivan Gorinov)
- new support for a variety of Sony Rock Band and Sony DJ Hero
Turntable devices (Rosalie Wanders)
- new driver for Lenovo Legion Go / S devices (Derek J. Clark)
- power management improvements to intel-thc-hid driver (Even Xu)
... other assorted cleanups, fixes and device-specific quirks"
* tag 'hid-for-linus-2026041601' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid: (73 commits)
HID: core: clamp report_size in s32ton() to avoid undefined shift
HID: logitech-dj: fix wrong detection of bad DJ_SHORT output report
HID: logitech-hidpp: fix race condition when accessing stale stack pointer
HID: winwing: Enable rumble effects
HID: core: do not allow parsing 0-sized reports
HID: usbhid: refactor endpoint lookup
HID: huawei: fix CD30 keyboard report descriptor issue
HID: playstation: validate num_touch_reports in DualShock 4 reports
HID: drop 'default !EXPERT' from tristate symbols
HID: usbhid: fix deadlock in hid_post_reset()
HID: apple: ensure the keyboard backlight is off if suspending
HID: quirks: Set ALWAYS_POLL for LOGITECH_BOLT_RECEIVER
HID: alps: fix NULL pointer dereference in alps_raw_event()
HID: logitech-dj: Prevent REPORT_ID_DJ_SHORT related user initiated OOB write
HID: logitech-dj: Standardise hid_report_enum variable nomenclature
HID: sony: update module description
HID: logitech-hidpp: Check bounds when deleting force-feedback effects
HID: sony: add battery status support for Rock Band 4 PS5 guitars
HID: sony: fix style issues
HID: quirks: update hid-sony supported devices
...
43 files changed, 10173 insertions, 497 deletions
diff --git a/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go b/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go new file mode 100644 index 000000000000..c8221373ef76 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go @@ -0,0 +1,724 @@ +What: /sys/class/leds/go:rgb:joystick_rings/effect +Date: April 2026 +Contact: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +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: linux-input@vger.kernel.org +Description: This displays the protocol version of the internal wireless transmission dongle. + + Applies to Lenovo Legion Go and Go 2 line of handheld devices. + diff --git a/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s b/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s new file mode 100644 index 000000000000..4d317074bb7e --- /dev/null +++ b/Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s @@ -0,0 +1,304 @@ +What: /sys/class/leds/go_s:rgb:joystick_rings/effect +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls the display effect of the RGB interface. + + Values are monocolor, breathe, chroma, or rainbow. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/effect_index +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the effect attribute. + + Values are monocolor, breathe, chroma, or rainbow. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/enabled +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls enabling or disabling the RGB interface. + + Values are true or false. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/enabled_index +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the enabled attribute. + + Values are true or false. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/mode +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls the operating mode of the RGB interface. + + Values are dynamic or custom. Custom allows setting the RGB effect and color. + Dynamic is a Windows mode for syncing Lenovo RGB interfaces not currently + supported under Linux. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/mode_index +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the mode attribute. + + Values are dynamic or custom. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/profile +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls selecting the configured RGB profile. + + Values are 1-3. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/profile_range +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the profile attribute. + + Values are 1-3. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/speed +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls the change rate for the breathe, chroma, and rainbow effects. + + Values are 0-100. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/class/leds/go_s:rgb:joystick_rings/speed_range +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the speed attribute. + + Values are 0-100. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad/auto_sleep_time +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls the sleep timer due to inactivity for the built-in controller. + + Values are 0-255. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad/auto_sleep_time_range +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the gamepad/auto_sleep_time attribute. + + Values are 0-255. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad/dpad_mode +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls the operating mode of the built-in controllers D-pad. + + Values are 4-way or 8-way. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad/dpad_mode_index +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the gamepad/dpad_mode attribute. + + Values are 4-way or 8-way. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad/mode +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls the operating mode of the built-in controller. + + Values are xinput or dinput. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad/mode_index +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the gamepad/mode attribute. + + Values are xinput or dinput. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad/poll_rate +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls the poll rate in Hz of the built-in controller. + + Values are 125, 250, 500, or 1000. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/gamepad/poll_rate_index +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the gamepad/poll_rate attribute. + + Values are 125, 250, 500, or 1000. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/imu/bypass_enabled +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls enabling or disabling the IMU bypass function. When enabled the IMU data is directly reported to the OS through +an HIDRAW interface. + + Values are true or false. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/imu/bypass_enabled_index +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the 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>/imu/manufacturer +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the manufacturer of the intertial measurment unit. + + Values are Bosch or ST. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/imu/sensor_enabled +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls enabling or disabling the IMU. + + Values are true, false, or wake-2s. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/imu/sensor_enabled_index +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the imu/sensor_enabled attribute. + + Values are true, false, or wake-2s. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/mcu_id +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the MCU Identification Number + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/mouse/step +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls which value is used for the mouse sensitivity. + + Values are 1-127. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/mouse/step_range +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the mouse/step attribute. + + Values are 1-127. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/os_mode +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls which value is used for the touchpads operating mode. + + Values are windows or linux. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/os_mode_index +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the os_mode attribute. + + Values are windows or linux. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/enabled +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls enabling or disabling the built-in touchpad. + + Values are true or false. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/enabled_index +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the touchpad/enabled attribute. + + Values are true or false. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/linux_mode +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls behavior of the touchpad events when os_mode is set to linux. + + Values are absolute or relative. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/linux_mode_index +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the touchpad/linux_mode attribute. + + Values are absolute or relative. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/windows_mode +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This controls behavior of the touchpad events when os_mode is set to windows. + + Values are absolute or relative. + + Applies to Lenovo Legion Go S line of handheld devices. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/windows_mode_index +Date: April 2026 +Contact: linux-input@vger.kernel.org +Description: This displays the available options for the touchpad/windows_mode attribute. + + Values are absolute or relative. + + Applies to Lenovo Legion Go S line of handheld devices. diff --git a/MAINTAINERS b/MAINTAINERS index 5fcb7b991776..8b721e8ad919 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11432,14 +11432,6 @@ F: drivers/hid/hid-sensor-* F: drivers/iio/*/hid-* F: include/linux/hid-sensor-* -HID UNIVERSAL PIDFF DRIVER -M: Tomasz Pakuła <tomasz.pakula.oficjalny@gmail.com> -M: Oleg Makarenko <oleg@makarenk.ooo> -L: linux-input@vger.kernel.org -S: Maintained -B: https://github.com/JacKeTUs/universal-pidff/issues -F: drivers/hid/hid-universal-pidff.c - HID VRC-2 CAR CONTROLLER DRIVER M: Marcus Folkesson <marcus.folkesson@gmail.com> L: linux-input@vger.kernel.org @@ -14555,6 +14547,17 @@ L: platform-driver-x86@vger.kernel.org S: Maintained F: drivers/platform/x86/lenovo/wmi-hotkey-utilities.c +LENOVO HID drivers +M: Derek J. Clark <derekjohn.clark@gmail.com> +M: Mark Pearson <mpearson-lenovo@squebb.ca> +L: linux-input@vger.kernel.org +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 + LETSKETCH HID TABLET DRIVER M: Hans de Goede <hansg@kernel.org> L: linux-input@vger.kernel.org @@ -27492,6 +27495,15 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git F: Documentation/hid/hiddev.rst F: drivers/hid/usbhid/ +USB HID PID DRIVERS (USB WHEELBASES, JOYSTICKS, RUDDERS, ...) +M: Tomasz Pakuła <tomasz.pakula.oficjalny@gmail.com> +M: Oleg Makarenko <oleg@makarenk.ooo> +L: linux-input@vger.kernel.org +S: Maintained +B: https://github.com/JacKeTUs/universal-pidff/issues +F: drivers/hid/usbhid/hid-pidff* +F: drivers/hid/hid-universal-pidff.c + USB INTEL XHCI ROLE MUX DRIVER M: Hans de Goede <hansg@kernel.org> L: linux-usb@vger.kernel.org diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index c1d9f7c6a5f2..ff2f580b660b 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig @@ -107,7 +107,6 @@ menu "Special HID drivers" config HID_A4TECH tristate "A4TECH mice" - default !EXPERT help Support for some A4TECH mice with two scroll wheels. @@ -140,7 +139,6 @@ config HID_APPLE tristate "Apple {i,Power,Mac}Books" depends on LEDS_CLASS depends on NEW_LEDS - default !EXPERT help Support for some Apple devices which less or more break HID specification. @@ -209,7 +207,6 @@ config HID_AUREAL config HID_BELKIN tristate "Belkin Flip KVM and Wireless keyboard" - default !EXPERT help Support for Belkin Flip KVM and Wireless keyboard. @@ -237,14 +234,12 @@ config HID_BIGBEN_FF config HID_CHERRY tristate "Cherry Cymotion keyboard" - default !EXPERT help Support for Cherry Cymotion keyboard. config HID_CHICONY tristate "Chicony devices" depends on USB_HID - default !EXPERT help Support for Chicony Tactical pad and special keys on Chicony keyboards. @@ -322,7 +317,6 @@ config HID_CREATIVE_SB0540 config HID_CYPRESS tristate "Cypress mouse and barcode readers" - default !EXPERT help Support for cypress mouse and barcode readers. @@ -388,7 +382,6 @@ config HID_EVISION config HID_EZKEY tristate "Ezkey BTC 8193 keyboard" - default !EXPERT help Support for Ezkey BTC 8193 keyboard. @@ -564,7 +557,6 @@ config HID_ICADE config HID_ITE tristate "ITE devices" - default !EXPERT help Support for ITE devices not fully compliant with HID standard. @@ -585,7 +577,6 @@ config HID_TWINHAN config HID_KENSINGTON tristate "Kensington Slimblade Trackball" - default !EXPERT help Support for Kensington Slimblade Trackball. @@ -610,8 +601,7 @@ config HID_LED config HID_LENOVO tristate "Lenovo / Thinkpad devices" - select NEW_LEDS - select LEDS_CLASS + depends on LEDS_CLASS help Support for IBM/Lenovo devices that are not fully compliant with HID standard. @@ -623,6 +613,28 @@ 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 + depends on 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_LENOVO_GO_S + tristate "HID Driver for Lenovo Legion Go S Controller" + depends on USB_HID + depends on 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 @@ -642,7 +654,6 @@ config HID_LOGITECH depends on USB_HID depends on LEDS_CLASS depends on LEDS_CLASS_MULTICOLOR - default !EXPERT help Support for Logitech devices that are not fully compliant with HID standard. @@ -757,20 +768,17 @@ config HID_MEGAWORLD_FF config HID_REDRAGON tristate "Redragon keyboards" - default !EXPERT help Support for Redragon keyboards that need fix-ups to work properly. config HID_MICROSOFT tristate "Microsoft non-fully HID-compliant devices" - default !EXPERT select INPUT_FF_MEMLESS help Support for Microsoft devices that are not fully compliant with HID standard. config HID_MONTEREY tristate "Monterey Genius KB29E keyboard" - default !EXPERT help Support for Monterey Genius KB29E. @@ -1100,13 +1108,15 @@ config HID_SONY help Support for - * Sony PS3 6-axis controllers + * Sixaxis controllers for PS3 * Buzz controllers - * Sony PS3 Blue-ray Disk Remote Control (Bluetooth) - * Logitech Harmony adapter for Sony Playstation 3 (Bluetooth) - * Guitar Hero Live PS3, Wii U and PS4 guitar dongles - * Guitar Hero PS3 and PC guitar dongles + * Blu-ray Disc Remote Control for PS3 + * Logitech Harmony adapter for PS3 + * Guitar Hero Live PS3, Wii U and PS4 guitars + * Guitar Hero PS3 and PC guitars + * Rock Band 1, 2 and 3 PS3 and Wii instruments * Rock Band 4 PS4 and PS5 guitars + * DJ Hero Turntable for PS3 config SONY_FF bool "Sony PS2/3/4 accessories force feedback support" @@ -1435,6 +1445,13 @@ config HID_KUNIT_TEST If in doubt, say "N". +config HID_HUAWEI + tristate "Huawei HID devices support" + depends on USB_HID + help + Support for huawei cd30 keyboard or other hid devices + that need fix-ups to work properly. + endmenu source "drivers/hid/bpf/Kconfig" diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index e01838239ae6..0597fd6a4ffd 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile @@ -76,6 +76,8 @@ 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_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 @@ -152,6 +154,7 @@ obj-$(CONFIG_HID_ZEROPLUS) += hid-zpff.o obj-$(CONFIG_HID_ZYDACRON) += hid-zydacron.o obj-$(CONFIG_HID_VIEWSONIC) += hid-viewsonic.o obj-$(CONFIG_HID_VRC2) += hid-vrc2.o +obj-$(CONFIG_HID_HUAWEI) += hid-huawei.o wacom-objs := wacom_wac.o wacom_sys.o obj-$(CONFIG_HID_WACOM) += wacom.o diff --git a/drivers/hid/bpf/progs/Generic__touchpad.bpf.c b/drivers/hid/bpf/progs/Generic__touchpad.bpf.c new file mode 100644 index 000000000000..b9f2cac91724 --- /dev/null +++ b/drivers/hid/bpf/progs/Generic__touchpad.bpf.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2025 Benjamin Tissoires + */ + +#include "vmlinux.h" +#include "hid_bpf.h" +#include "hid_bpf_helpers.h" +#include "hid_report_helpers.h" +#include "hid_usages.h" +#include <bpf/bpf_tracing.h> + +HID_BPF_CONFIG( + HID_DEVICE(BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8, HID_VID_ANY, HID_PID_ANY), +); + +EXPORT_UDEV_PROP(HID_DIGITIZER_PAD_TYPE, 32); + +__u8 hw_req_buf[1024]; + +/* to be filled by udev-hid-bpf */ +struct hid_rdesc_descriptor HID_REPORT_DESCRIPTOR; + +SEC("syscall") +int probe(struct hid_bpf_probe_args *ctx) +{ + struct hid_rdesc_report *pad_type_feature = NULL; + struct hid_rdesc_field *pad_type = NULL; + struct hid_rdesc_report *feature; + struct hid_bpf_ctx *hid_ctx; + char *pad_type_str = ""; + int ret; + + hid_bpf_for_each_feature_report(&HID_REPORT_DESCRIPTOR, feature) { + struct hid_rdesc_field *field; + + hid_bpf_for_each_field(feature, field) { + if (field->usage_page == HidUsagePage_Digitizers && + field->usage_id == HidUsage_Dig_PadType) { + pad_type = field; + pad_type_feature = feature; + break; + } + } + if (pad_type) + break; + } + + if (!pad_type || !pad_type_feature) { + ctx->retval = -EINVAL; + return 0; + } + + hid_ctx = hid_bpf_allocate_context(ctx->hid); + + if (!hid_ctx) + return -1; /* EPERM check */ + + hw_req_buf[0] = pad_type_feature->report_id; + + ret = hid_bpf_hw_request(hid_ctx, hw_req_buf, sizeof(hw_req_buf), + HID_FEATURE_REPORT, HID_REQ_GET_REPORT); + hid_bpf_release_context(hid_ctx); + + if (ret < 0) { + ctx->retval = ret; + return 0; + } + + ctx->retval = 0; + + switch (EXTRACT_BITS(hw_req_buf, pad_type)) { + case 0: + pad_type_str = "Clickpad"; + break; + case 1: + pad_type_str = "Pressurepad"; + break; + case 2: + pad_type_str = "Discrete"; + break; + default: + pad_type_str = "Unknown"; + } + + UDEV_PROP_SPRINTF(HID_DIGITIZER_PAD_TYPE, "%s", pad_type_str); + + return 0; +} + +char _license[] SEC("license") = "GPL"; diff --git a/drivers/hid/bpf/progs/Huion__KeydialK20-Bluetooth.bpf.c b/drivers/hid/bpf/progs/Huion__KeydialK20-Bluetooth.bpf.c new file mode 100644 index 000000000000..d0769e990039 --- /dev/null +++ b/drivers/hid/bpf/progs/Huion__KeydialK20-Bluetooth.bpf.c @@ -0,0 +1,492 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2024 Red Hat, Inc + */ + +#include "vmlinux.h" +#include "hid_bpf.h" +#include "hid_bpf_helpers.h" +#include "hid_report_helpers.h" +#include <bpf/bpf_tracing.h> + +#define VID_HUION 0x256C +#define PID_KEYDIAL_K20_BLUETOOTH 0x8251 + +HID_BPF_CONFIG( + HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_GENERIC, VID_HUION, PID_KEYDIAL_K20_BLUETOOTH), +); + +/* This is the same device as in 0010-Huion__KeydialK20 but connected via Bluetooth. + * It does not need (to support?) switching to a vendor mode so we just modify the + * existing mode. + * + * By default it exports two hidraw nodes, only the second one sends events. + * + * This is the first hidraw node which we disable: + * + * # Keydial mini-050 + * # Report descriptor length: 114 bytes + * # Bytes // Field Name Offset + * # ---------------------------------------------------------------------------------- + * # 🮥 0x05, 0x01, // Usage Page (Generic Desktop) 0 + * # 🭬 0x09, 0x0e, // Usage (System Multi-Axis Controller) 2 + * # 0xa1, 0x01, // Collection (Application) 4 + * # ┅ 0x85, 0x03, // Report ID (3) 6 + * # 🮥 0x05, 0x0d, // Usage Page (Digitizers) 8 + * # 0x75, 0x08, // Report Size (8) 10 + * # 0x95, 0x01, // Report Count (1) 12 + * # ┇ 0x81, 0x01, // Input (Cnst,Arr,Abs) 14 + * # 🭬 0x09, 0x21, // Usage (Puck) 16 + * # 0xa1, 0x02, // Collection (Logical) 18 + * # 0x15, 0x00, // Logical Minimum (0) 20 + * # 0x25, 0x01, // Logical Maximum (1) 22 + * # 0x75, 0x01, // Report Size (1) 24 + * # 0x95, 0x01, // Report Count (1) 26 + * # 0xa1, 0x00, // Collection (Physical) 28 + * # 🮥 0x05, 0x09, // Usage Page (Button) 30 + * # 🭬 0x09, 0x01, // Usage (Button 1) 32 + * # ┇ 0x81, 0x02, // Input (Data,Var,Abs) 34 + * # 🮥 0x05, 0x0d, // Usage Page (Digitizers) 36 + * # 🭬 0x09, 0x33, // Usage (Touch) 38 + * # ┇ 0x81, 0x02, // Input (Data,Var,Abs) 40 + * # 0x95, 0x06, // Report Count (6) 42 + * # ┇ 0x81, 0x03, // Input (Cnst,Var,Abs) 44 + * # 0xa1, 0x02, // Collection (Logical) 46 + * # 🮥 0x05, 0x01, // Usage Page (Generic Desktop) 48 + * # 🭬 0x09, 0x37, // Usage (Dial) 50 + * # 0x16, 0x00, 0x80, // Logical Minimum (32768) 52 + * # 0x26, 0xff, 0x7f, // Logical Maximum (32767) 55 + * # 0x75, 0x10, // Report Size (16) 58 + * # 0x95, 0x01, // Report Count (1) 60 + * # ┇ 0x81, 0x06, // Input (Data,Var,Rel) 62 + * # 0x35, 0x00, // Physical Minimum (0) 64 + * # 0x46, 0x10, 0x0e, // Physical Maximum (3600) 66 + * # 0x15, 0x00, // Logical Minimum (0) 69 + * # 0x26, 0x10, 0x0e, // Logical Maximum (3600) 71 + * # 🭬 0x09, 0x48, // Usage (Resolution Multiplier) 74 + * # ║ 0xb1, 0x02, // Feature (Data,Var,Abs) 76 + * # 0x45, 0x00, // Physical Maximum (0) 78 + * # 0xc0, // End Collection 80 + * # 0x75, 0x08, // Report Size (8) 81 + * # 0x95, 0x01, // Report Count (1) 83 + * # ┇ 0x81, 0x01, // Input (Cnst,Arr,Abs) 85 + * # 0x75, 0x08, // Report Size (8) 87 + * # 0x95, 0x01, // Report Count (1) 89 + * # ┇ 0x81, 0x01, // Input (Cnst,Arr,Abs) 91 + * # 0x75, 0x08, // Report Size (8) 93 + * # 0x95, 0x01, // Report Count (1) 95 + * # ┇ 0x81, 0x01, // Input (Cnst,Arr,Abs) 97 + * # 0x75, 0x08, // Report Size (8) 99 + * # 0x95, 0x01, // Report Count (1) 101 + * # ┇ 0x81, 0x01, // Input (Cnst,Arr,Abs) 103 + * # 0x75, 0x08, // Report Size (8) 105 + * # 0x95, 0x01, // Report Count (1) 107 + * # ┇ 0x81, 0x01, // Input (Cnst,Arr,Abs) 109 + * # 0xc0, // End Collection 111 + * # 0xc0, // End Collection 112 + * # 0xc0, // End Collection 113 + * R: 114 05 01 09 0e a1 01 85 03 05 0d 75 08 95 01 81 01 09 21 a1 02 15 00 25 01 75 01 95 01 a1 00 05 09 09 01 81 02 05 0d 09 33 81 02 95 06 81 03 a1 02 05 01 09 37 16 00 80 26 ff 7f 75 10 95 01 81 06 35 00 46 10 0e 15 00 26 10 0e 09 48 b1 02 45 00 c0 75 08 95 01 81 01 75 08 95 01 81 01 75 08 95 01 81 01 75 08 95 01 81 01 75 08 95 01 81 01 c0 c0 c0 + * N: Keydial mini-050 + * I: 5 256c 8251 + * + * The second hidraw node is what sends events: + * + * # Keydial mini-050 + * # Report descriptor length: 160 bytes + * # Bytes // Field Name Offset + * # ---------------------------------------------------------------------------------- + * # 🮥 0x05, 0x01, // Usage Page (Generic Desktop) 0 + * # 🭬 0x09, 0x06, // Usage (Keyboard) 2 + * # 0xa1, 0x01, // Collection (Application) 4 + * # ┅ 0x85, 0x01, // Report ID (1) 6 + * # 🮥 0x05, 0x07, // Usage Page (Keyboard/Keypad) 8 + * # 🭬 0x19, 0xe0, // Usage Minimum (224) 10 + * # 🭬 0x29, 0xe7, // Usage Maximum (231) 12 + * # 0x15, 0x00, // Logical Minimum (0) 14 + * # 0x25, 0x01, // Logical Maximum (1) 16 + * # 0x75, 0x01, // Report Size (1) 18 + * # 0x95, 0x08, // Report Count (8) 20 + * # ┇ 0x81, 0x02, // Input (Data,Var,Abs) 22 + * # 0x95, 0x01, // Report Count (1) 24 + * # 0x75, 0x08, // Report Size (8) 26 + * # ┇ 0x81, 0x01, // Input (Cnst,Arr,Abs) 28 + * # 0x95, 0x05, // Report Count (5) 30 + * # 0x75, 0x01, // Report Size (1) 32 + * # 🮥 0x05, 0x08, // Usage Page (LED) 34 + * # 🭬 0x19, 0x01, // Usage Minimum (1) 36 + * # 🭬 0x29, 0x05, // Usage Maximum (5) 38 + * # ┊ 0x91, 0x02, // Output (Data,Var,Abs) 40 + * # 0x95, 0x01, // Report Count (1) 42 + * # 0x75, 0x03, // Report Size (3) 44 + * # ┊ 0x91, 0x01, // Output (Cnst,Arr,Abs) 46 + * # 0x95, 0x06, // Report Count (6) 48 + * # 0x75, 0x08, // Report Size (8) 50 + * # 0x15, 0x00, // Logical Minimum (0) 52 + * # 0x25, 0xf1, // Logical Maximum (241) 54 + * # 🮥 0x05, 0x07, // Usage Page (Keyboard/Keypad) 56 + * # 🭬 0x19, 0x00, // Usage Minimum (0) 58 + * # 🭬 0x29, 0xf1, // Usage Maximum (241) 60 + * # ┇ 0x81, 0x00, // Input (Data,Arr,Abs) 62 + * # 0xc0, // End Collection 64 + * # 🮥 0x05, 0x0c, // Usage Page (Consumer) 65 + * # 🭬 0x09, 0x01, // Usage (Consumer Control) 67 + * # 0xa1, 0x01, // Collection (Application) 69 + * # ┅ 0x85, 0x02, // Report ID (2) 71 + * # 🮥 0x05, 0x0c, // Usage Page (Consumer) 73 + * # 🭬 0x19, 0x00, // Usage Minimum (0) 75 + * # 🭬 0x2a, 0x80, 0x03, // Usage Maximum (896) 77 + * # 0x15, 0x00, // Logical Minimum (0) 80 + * # 0x26, 0x80, 0x03, // Logical Maximum (896) 82 + * # 0x75, 0x10, // Report Size (16) 85 + * # 0x95, 0x01, // Report Count (1) 87 + * # ┇ 0x81, 0x00, // Input (Data,Arr,Abs) 89 + * # 0xc0, // End Collection 91 + * # 🮥 0x05, 0x01, // Usage Page (Generic Desktop) 92 + * # 🭬 0x09, 0x02, // Usage (Mouse) 94 + * # 0xa1, 0x01, // Collection (Application) 96 + * # 🭬 0x09, 0x01, // Usage (Pointer) 98 + * # ┅ 0x85, 0x05, // Report ID (5) 100 + * # 0xa1, 0x00, // Collection (Physical) 102 + * # 🮥 0x05, 0x09, // Usage Page (Button) 104 + * # 🭬 0x19, 0x01, // Usage Minimum (1) 106 + * # 🭬 0x29, 0x05, // Usage Maximum (5) 108 + * # 0x15, 0x00, // Logical Minimum (0) 110 + * # 0x25, 0x01, // Logical Maximum (1) 112 + * # 0x95, 0x05, // Report Count (5) 114 + * # 0x75, 0x01, // Report Size (1) 116 + * # ┇ 0x81, 0x02, // Input (Data,Var,Abs) 118 + * # 0x95, 0x01, // Report Count (1) 120 + * # 0x75, 0x03, // Report Size (3) 122 + * # ┇ 0x81, 0x01, // Input (Cnst,Arr,Abs) 124 + * # 🮥 0x05, 0x01, // Usage Page (Generic Desktop) 126 + * # 🭬 0x09, 0x30, // Usage (X) 128 + * # 🭬 0x09, 0x31, // Usage (Y) 130 + * # 0x16, 0x01, 0x80, // Logical Minimum (32769) 132 + * # 0x26, 0xff, 0x7f, // Logical Maximum (32767) 135 + * # 0x75, 0x10, // Report Size (16) 138 + * # 0x95, 0x02, // Report Count (2) 140 + * # ┇ 0x81, 0x06, // Input (Data,Var,Rel) 142 + * # 🮥 0x05, 0x01, // Usage Page (Generic Desktop) 144 + * # 🭬 0x09, 0x38, // Usage (Wheel) 146 + * # 0x15, 0x81, // Logical Minimum (129) 148 + * # 0x25, 0x7f, // Logical Maximum (127) 150 + * # 0x95, 0x01, // Report Count (1) 152 + * # 0x75, 0x08, // Report Size (8) 154 + * # ┇ 0x81, 0x06, // Input (Data,Var,Rel) 156 + * # 0xc0, // End Collection 158 + * # 0xc0, // End Collection 159 + * R: 160 05 01 09 06 a1 01 85 01 05 07 19 e0 29 e7 15 00 25 01 75 01 95 08 81 02 95 01 75 08 81 01 95 05 75 01 05 08 19 01 29 05 91 02 95 01 75 03 91 01 95 06 75 08 15 00 25 f1 05 07 19 00 29 f1 81 00 c0 05 0c 09 01 a1 01 85 02 05 0c 19 00 2a 80 03 15 00 26 80 03 75 10 95 01 81 00 c0 05 01 09 02 a1 01 09 01 85 05 a1 00 05 09 19 01 29 05 15 00 25 01 95 05 75 01 81 02 95 01 75 03 81 01 05 01 09 30 09 31 16 01 80 26 ff 7f 75 10 95 02 81 06 05 01 09 38 15 81 25 7f 95 01 75 08 81 06 c0 c0 + * N: Keydial mini-050 + * I: 5 256c 8251 + * # Report descriptor: + * # ------- Input Report ------- + * # ░ Report ID: 1 + * # ░ | Report size: 72 bits + * # ░ Bit: 8 Usage: 0007/00e0: Keyboard/Keypad / Keyboard LeftControl Logical Range: 0..=1 + * # ░ Bit: 9 Usage: 0007/00e1: Keyboard/Keypad / Keyboard LeftShift Logical Range: 0..=1 + * # ░ Bit: 10 Usage: 0007/00e2: Keyboard/Keypad / Keyboard LeftAlt Logical Range: 0..=1 + * # ░ Bit: 11 Usage: 0007/00e3: Keyboard/Keypad / Keyboard Left GUI Logical Range: 0..=1 + * # ░ Bit: 12 Usage: 0007/00e4: Keyboard/Keypad / Keyboard RightControl Logical Range: 0..=1 + * # ░ Bit: 13 Usage: 0007/00e5: Keyboard/Keypad / Keyboard RightShift Logical Range: 0..=1 + * # ░ Bit: 14 Usage: 0007/00e6: Keyboard/Keypad / Keyboard RightAlt Logical Range: 0..=1 + * # ░ Bit: 15 Usage: 0007/00e7: Keyboard/Keypad / Keyboard Right GUI Logical Range: 0..=1 + * # ░ Bits: 16..=23 ######### Padding + * # ░ Bits: 24..=71 Usages: Logical Range: 0..=241 + * # ░ 0007/0000: <unknown> + * # ░ 0007/0001: Keyboard/Keypad / ErrorRollOver + * # ░ 0007/0002: Keyboard/Keypad / POSTFail + * # ░ 0007/0003: Keyboard/Keypad / ErrorUndefined + * # ░ 0007/0004: Keyboard/Keypad / Keyboard A + * # ░ ... use --full to see all usages + * # ------- Input Report ------- + * # ▒ Report ID: 2 + * # ▒ | Report size: 24 bits + * # ▒ Bits: 8..=23 Usages: Logical Range: 0..=896 + * # ▒ 000c/0000: <unknown> + * # ▒ 000c/0001: Consumer / Consumer Control + * # ▒ 000c/0002: Consumer / Numeric Key Pad + * # ▒ 000c/0003: Consumer / Programmable Buttons + * # ▒ 000c/0004: Consumer / Microphone + * # ▒ ... use --full to see all usages + * # ------- Input Report ------- + * # ▞ Report ID: 5 + * # ▞ | Report size: 56 bits + * # ▞ Bit: 8 Usage: 0009/0001: Button / Button 1 Logical Range: 0..=1 + * # ▞ Bit: 9 Usage: 0009/0002: Button / Button 2 Logical Range: 0..=1 + * # ▞ Bit: 10 Usage: 0009/0003: Button / Button 3 Logical Range: 0..=1 + * # ▞ Bit: 11 Usage: 0009/0004: Button / Button 4 Logical Range: 0..=1 + * # ▞ Bit: 12 Usage: 0009/0005: Button / Button 5 Logical Range: 0..=1 + * # ▞ Bits: 13..=15 ######### Padding + * # ▞ Bits: 16..=31 Usage: 0001/0030: Generic Desktop / X Logical Range: 32769..=32767 + * # ▞ Bits: 32..=47 Usage: 0001/0031: Generic Desktop / Y Logical Range: 32769..=32767 + * # ▞ Bits: 48..=55 Usage: 0001/0038: Generic Desktop / Wheel Logical Range: 129..=127 + * # ------- Output Report ------- + * # ░ Report ID: 1 + * # ░ | Report size: 16 bits + * # ░ Bit: 8 Usage: 0008/0001: LED / Num Lock Logical Range: 0..=1 + * # ░ Bit: 9 Usage: 0008/0002: LED / Caps Lock Logical Range: 0..=1 + * # ░ Bit: 10 Usage: 0008/0003: LED / Scroll Lock Logical Range: 0..=1 + * # ░ Bit: 11 Usage: 0008/0004: LED / Compose Logical Range: 0..=1 + * # ░ Bit: 12 Usage: 0008/0005: LED / Kana Logical Range: 0..=1 + * # ░ Bits: 13..=15 ######### Padding + * ############################################################################## + * # Event nodes: + * # - /dev/input/event12: "Keydial mini-050 Keyboard" + * # - /dev/input/event14: "Keydial mini-050 Mouse" + * ############################################################################## + * # Recorded events below in format: + * # E: <seconds>.<microseconds> <length-in-bytes> [bytes ...] + * # + * + * - Report ID 1 sends keyboard shortcuts when pressing the buttons, e.g. + * + * # ░ Report ID: 1 / + * # ░ Keyboard LeftControl: 0 |Keyboard LeftShift: 0 |Keyboard LeftAlt: 0 |Keyboard Left GUI: 0 |Keyboard RightControl: 0 |Keyboard RightShift: 0 |Keyboard RightAlt: 0 |Keyboard Right GUI: 0 |<8 bits padding> |0007/0000: 0| Keyboard K: 14| 0007/0000: 0| 0007/0000: 0| 0007/0000: 0| 0007/0000: 0 + * E: 000000.000292 9 01 00 00 00 0e 00 00 00 00 + * + * - Report ID 2 sends the button inside the wheel/dial thing + * # ▒ Report ID: 2 / + * # ▒ Play/Pause: 205 + * E: 000134.347845 3 02 cd 00 + * # ▒ Report ID: 2 / + * # ▒ 000c/0000: 0 + * E: 000134.444965 3 02 00 00 + * + * - Report ID 5 sends the wheel relative events (always a double-event with the second as zero) + * # ▞ Report ID: 5 / + * # ▞ Button 1: 0 |Button 2: 0 |Button 3: 0 |Button 4: 0 |Button 5: 0 |<3 bits padding> |X: 0 |Y: 0 |Wheel: 255 + * E: 000064.859915 7 05 00 00 00 00 00 ff + * # ▞ Report ID: 5 / + * # ▞ Button 1: 0 |Button 2: 0 |Button 3: 0 |Button 4: 0 |Button 5: 0 |<3 bits padding> |X: 0 |Y: 0 |Wheel: 0 + * E: 000064.882009 7 05 00 00 00 00 00 00 + */ + +#define BT_PAD_REPORT_DESCRIPTOR_LENGTH 160 +#define BT_PUCK_REPORT_DESCRIPTOR_LENGTH 114 // This one doesn't send events +#define BT_PAD_KBD_REPORT_ID 1 +#define BT_PAD_CC_REPORT_ID 2 +#define BT_PAD_MOUSE_REPORT_ID 5 +#define BT_PAD_KBD_REPORT_LENGTH 9 +#define BT_PAD_CC_REPORT_LENGTH 3 +#define BT_PAD_MOUSE_REPORT_LENGTH 7 +#define OUR_REPORT_ID 11 /* "randomly" picked report ID for our reports */ + +__u32 last_button_state = 0; + +static const __u8 disabled_rdesc_puck[] = { + FixedSizeVendorReport(BT_PUCK_REPORT_DESCRIPTOR_LENGTH) +}; + +static const __u8 fixed_rdesc_pad[] = { + UsagePage_GenericDesktop + Usage_GD_Keypad + CollectionApplication( + // Byte 0 + ReportId(OUR_REPORT_ID) + UsagePage_Digitizers + Usage_Dig_TabletFunctionKeys + CollectionPhysical( + // Byte 1 is a button so we look like a tablet + Usage_Dig_BarrelSwitch // BTN_STYLUS, needed so we get to be a tablet pad + ReportCount(1) + ReportSize(1) + Input(Var|Abs) + ReportCount(7) // Padding + Input(Const) + // Bytes 2/3 - x/y just exist so we get to be a tablet pad + UsagePage_GenericDesktop + Usage_GD_X + Usage_GD_Y + LogicalMinimum_i8(0x0) + LogicalMaximum_i8(0x1) + ReportCount(2) + ReportSize(8) + Input(Var|Abs) + // Bytes 4-7 are the button state for 19 buttons + pad out to u32 + // We send the first 10 buttons as buttons 1-10 which is BTN_0 -> BTN_9 + UsagePage_Button + UsageMinimum_i8(1) + UsageMaximum_i8(10) + LogicalMinimum_i8(0x0) + LogicalMaximum_i8(0x1) + ReportCount(10) + ReportSize(1) + Input(Var|Abs) + // We send the other 9 buttons as buttons 0x31 and above -> BTN_A - BTN_TL2 + UsageMinimum_i8(0x31) + UsageMaximum_i8(0x3a) + ReportCount(9) + ReportSize(1) + Input(Var|Abs) + ReportCount(13) + ReportSize(1) + Input(Const) // padding + // Byte 8 is the wheel + UsagePage_GenericDesktop + Usage_GD_Wheel + LogicalMinimum_i8(-1) + LogicalMaximum_i8(1) + ReportCount(1) + ReportSize(8) + Input(Var|Rel) + ) + // Make sure we match our original report length + FixedSizeVendorReport(BT_PAD_KBD_REPORT_LENGTH) + ) +}; + +SEC(HID_BPF_RDESC_FIXUP) +int BPF_PROG(k20_bt_fix_rdesc, struct hid_bpf_ctx *hctx) +{ + __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, HID_MAX_DESCRIPTOR_SIZE /* size */); + __s32 rdesc_size = hctx->size; + + if (!data) + return 0; /* EPERM check */ + + if (rdesc_size == BT_PAD_REPORT_DESCRIPTOR_LENGTH) { + __builtin_memcpy(data, fixed_rdesc_pad, sizeof(fixed_rdesc_pad)); + return sizeof(fixed_rdesc_pad); + } + if (rdesc_size == BT_PUCK_REPORT_DESCRIPTOR_LENGTH) { + // This hidraw node doesn't send anything and can be ignored + __builtin_memcpy(data, disabled_rdesc_puck, sizeof(disabled_rdesc_puck)); + return sizeof(disabled_rdesc_puck); + } + + return 0; +} + +SEC(HID_BPF_DEVICE_EVENT) +int BPF_PROG(k20_bt_fix_events, struct hid_bpf_ctx *hctx) +{ + __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 12 /* size */); + struct pad_report { + __u8 report_id; + __u8 btn_stylus:1; + __u8 pad:7; + __u8 x; + __u8 y; + __u32 buttons; + __u8 wheel; + } __packed * pad_report = (struct pad_report *)data; + + if (!data) + return 0; /* EPERM check */ + + /* Report ID 1 - Keyboard events (button presses) */ + if (data[0] == BT_PAD_KBD_REPORT_ID) { + const __u8 button_mapping[] = { + 0x0e, /* Button 1: K */ + 0x0a, /* Button 2: G */ + 0x0f, /* Button 3: L */ + 0x4c, /* Button 4: Delete */ + 0x0c, /* Button 5: I */ + 0x07, /* Button 6: D */ + 0x05, /* Button 7: B */ + 0x08, /* Button 8: E */ + 0x16, /* Button 9: S */ + 0x1d, /* Button 10: Z */ + 0x06, /* Button 11: C */ + 0x19, /* Button 12: V */ + 0xff, /* Button 13: LeftControl */ + 0xff, /* Button 14: LeftAlt */ + 0xff, /* Button 15: LeftShift */ + 0x28, /* Button 16: Return Enter */ + 0x2c, /* Button 17: Spacebar */ + 0x11, /* Button 18: N */ + }; + + __u8 modifiers = data[1]; + __u32 buttons = 0; + + if (modifiers & 0x01) { /* Control */ + buttons |= BIT(12); + } + if (modifiers & 0x02) { /* Shift */ + buttons |= BIT(14); + } + if (modifiers & 0x04) { /* Alt */ + buttons |= BIT(13); + } + + for (int i = 4; i < BT_PAD_KBD_REPORT_LENGTH; i++) { + if (!data[i]) + break; + + for (size_t b = 0; b < ARRAY_SIZE(button_mapping); b++) { + if (data[i] != 0xff && data[i] == button_mapping[b]) { + buttons |= BIT(b); + break; + } + } + } + + last_button_state = buttons; + + pad_report->report_id = OUR_REPORT_ID; + pad_report->btn_stylus = 0; + pad_report->x = 0; + pad_report->y = 0; + pad_report->buttons = buttons; + pad_report->wheel = 0; + + return sizeof(struct pad_report); + } + + /* Report ID 2 - Consumer control events (the button inside the wheel) */ + if (data[0] == BT_PAD_CC_REPORT_ID) { + const __u8 PlayPause = 0xcd; + + if (data[1] == PlayPause) + last_button_state |= BIT(18); + else + last_button_state &= ~BIT(18); + + pad_report->report_id = OUR_REPORT_ID; + pad_report->btn_stylus = 0; + pad_report->x = 0; + pad_report->y = 0; + pad_report->buttons = last_button_state; + pad_report->wheel = 0; + + return sizeof(struct pad_report); + } + + /* Report ID 5 - Mouse events (wheel rotation) */ + if (data[0] == BT_PAD_MOUSE_REPORT_ID) { + __u8 wheel_delta = data[6]; + + pad_report->report_id = OUR_REPORT_ID; + pad_report->btn_stylus = 0; + pad_report->x = 0; + pad_report->y = 0; + pad_report->buttons = last_button_state; + pad_report->wheel = wheel_delta; + + return sizeof(struct pad_report); + } + + return 0; +} + +HID_BPF_OPS(keydial_k20_bluetooth) = { + .hid_device_event = (void *)k20_bt_fix_events, + .hid_rdesc_fixup = (void *)k20_bt_fix_rdesc, +}; + +SEC("syscall") +int probe(struct hid_bpf_probe_args *ctx) +{ + switch (ctx->rdesc_size) { + case BT_PAD_REPORT_DESCRIPTOR_LENGTH: + case BT_PUCK_REPORT_DESCRIPTOR_LENGTH: + ctx->retval = 0; + break; + default: + ctx->retval = -EINVAL; + } + + return 0; +} + +char _license[] SEC("license") = "GPL"; diff --git a/drivers/hid/bpf/progs/Huion__KeydialK20.bpf.c b/drivers/hid/bpf/progs/Huion__KeydialK20.bpf.c index ec360d71130f..c562c2d684fe 100644 --- a/drivers/hid/bpf/progs/Huion__KeydialK20.bpf.c +++ b/drivers/hid/bpf/progs/Huion__KeydialK20.bpf.c @@ -462,7 +462,8 @@ int BPF_PROG(k20_fix_events, struct hid_bpf_ctx *hctx) __u32 buttons; __u8 wheel; } __attribute__((packed)) *pad_report; - int i, b; + int i; + size_t b; __u8 modifiers = data[1]; __u32 buttons = 0; diff --git a/drivers/hid/bpf/progs/IOGEAR__Kaliber-MMOmentum.bpf.c b/drivers/hid/bpf/progs/IOGEAR__Kaliber-MMOmentum.bpf.c index 82f1950445dd..253b96458c58 100644 --- a/drivers/hid/bpf/progs/IOGEAR__Kaliber-MMOmentum.bpf.c +++ b/drivers/hid/bpf/progs/IOGEAR__Kaliber-MMOmentum.bpf.c @@ -34,7 +34,7 @@ int BPF_PROG(hid_fix_rdesc, struct hid_bpf_ctx *hctx) if (data[3] != 0x06) return 0; - for (int idx = 0; idx < ARRAY_SIZE(offsets); idx++) { + for (size_t idx = 0; idx < ARRAY_SIZE(offsets); idx++) { u8 offset = offsets[idx]; /* if Input (Cnst,Var,Abs) , make it Input (Data,Var,Abs) */ diff --git a/drivers/hid/bpf/progs/Trust__Philips-SPK6327.bpf.c b/drivers/hid/bpf/progs/Trust__Philips-SPK6327.bpf.c new file mode 100644 index 000000000000..bc7ff27eac9f --- /dev/null +++ b/drivers/hid/bpf/progs/Trust__Philips-SPK6327.bpf.c @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Fix for Trust Philips SPK6327 (145f:024b) + * Modifier keys report as Array (0x00) instead of Variable (0x02) + * causing LCtrl, LAlt, Super etc. to all act as LShift + */ +#include "vmlinux.h" +#include "hid_bpf.h" +#include "hid_bpf_helpers.h" +#include <bpf/bpf_tracing.h> + +#define VID_TRUST 0x145F +#define PID_SPK6327 0x024B + +HID_BPF_CONFIG( + HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, VID_TRUST, PID_SPK6327) +); + +SEC(HID_BPF_RDESC_FIXUP) +int BPF_PROG(hid_fix_rdesc, struct hid_bpf_ctx *hctx) +{ + __u8 *data = hid_bpf_get_data(hctx, 0, 4096); + + if (!data) + return 0; + + /* Fix modifier keys: Input Array (0x00) -> Input Variable (0x02) */ + if (data[101] == 0x00) + data[101] = 0x02; + + return 0; +} + +HID_BPF_OPS(trust_spk6327) = { + .hid_rdesc_fixup = (void *)hid_fix_rdesc, +}; + +SEC("syscall") +int probe(struct hid_bpf_probe_args *ctx) +{ + /* Only apply to interface 1 (169 bytes) not interface 0 (62 bytes) */ + if (ctx->rdesc_size == 169) + ctx->retval = 0; + else + ctx->retval = -EINVAL; + + return 0; +} + +char _license[] SEC("license") = "GPL"; diff --git a/drivers/hid/bpf/progs/Wacom__ArtPen.bpf.c b/drivers/hid/bpf/progs/Wacom__ArtPen.bpf.c index 2da680bc4e11..ed60a660cc1a 100644 --- a/drivers/hid/bpf/progs/Wacom__ArtPen.bpf.c +++ b/drivers/hid/bpf/progs/Wacom__ArtPen.bpf.c @@ -148,7 +148,7 @@ int probe(struct hid_bpf_probe_args *ctx) { struct hid_bpf_ctx *hid_ctx; __u16 pid; - int i; + size_t i; /* get a struct hid_device to access the actual pid of the device */ hid_ctx = hid_bpf_allocate_context(ctx->hid); diff --git a/drivers/hid/bpf/progs/XPPen__DecoMini4.bpf.c b/drivers/hid/bpf/progs/XPPen__DecoMini4.bpf.c index 46d5c459d0c9..ac07216f5b67 100644 --- a/drivers/hid/bpf/progs/XPPen__DecoMini4.bpf.c +++ b/drivers/hid/bpf/progs/XPPen__DecoMini4.bpf.c @@ -173,7 +173,7 @@ int BPF_PROG(hid_device_event_xppen_deco_mini_4, struct hid_bpf_ctx *hctx) { __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 8 /* size */); __u8 button_mask = 0; - int d, b; + size_t d, b; if (!data) return 0; /* EPERM check */ diff --git a/drivers/hid/bpf/progs/hid_bpf_async.h b/drivers/hid/bpf/progs/hid_bpf_async.h index 9ab585434239..877bb7e81f03 100644 --- a/drivers/hid/bpf/progs/hid_bpf_async.h +++ b/drivers/hid/bpf/progs/hid_bpf_async.h @@ -116,15 +116,14 @@ static int hid_bpf_async_find_empty_key(void) if (!elem) return -ENOMEM; /* should never happen */ - bpf_spin_lock(&elem->lock); + { + guard(bpf_spin)(&elem->lock); - if (elem->state == HID_BPF_ASYNC_STATE_UNSET) { - elem->state = HID_BPF_ASYNC_STATE_INITIALIZING; - bpf_spin_unlock(&elem->lock); - return i; + if (elem->state == HID_BPF_ASYNC_STATE_UNSET) { + elem->state = HID_BPF_ASYNC_STATE_INITIALIZING; + return i; + } } - - bpf_spin_unlock(&elem->lock); } return -EINVAL; @@ -175,18 +174,19 @@ static int hid_bpf_async_delayed_call(struct hid_bpf_ctx *hctx, u64 milliseconds if (!elem) return -EINVAL; - bpf_spin_lock(&elem->lock); - /* The wq must be: - * - HID_BPF_ASYNC_STATE_INITIALIZED -> it's been initialized and ready to be called - * - HID_BPF_ASYNC_STATE_RUNNING -> possible re-entry from the wq itself - */ - if (elem->state != HID_BPF_ASYNC_STATE_INITIALIZED && - elem->state != HID_BPF_ASYNC_STATE_RUNNING) { - bpf_spin_unlock(&elem->lock); - return -EINVAL; + { + guard(bpf_spin)(&elem->lock); + + /* The wq must be: + * - HID_BPF_ASYNC_STATE_INITIALIZED -> it's been initialized and ready to be called + * - HID_BPF_ASYNC_STATE_RUNNING -> possible re-entry from the wq itself + */ + if (elem->state != HID_BPF_ASYNC_STATE_INITIALIZED && + elem->state != HID_BPF_ASYNC_STATE_RUNNING) + return -EINVAL; + + elem->state = HID_BPF_ASYNC_STATE_STARTING; } - elem->state = HID_BPF_ASYNC_STATE_STARTING; - bpf_spin_unlock(&elem->lock); elem->hid = hctx->hid->id; diff --git a/drivers/hid/bpf/progs/hid_bpf_helpers.h b/drivers/hid/bpf/progs/hid_bpf_helpers.h index 228f8d787567..0fd8e7d90742 100644 --- a/drivers/hid/bpf/progs/hid_bpf_helpers.h +++ b/drivers/hid/bpf/progs/hid_bpf_helpers.h @@ -7,7 +7,18 @@ #include "vmlinux.h" #include <bpf/bpf_helpers.h> +#include <bpf/bpf_endian.h> #include <linux/errno.h> +#include "hid_report_descriptor_helpers.h" + +/* Compiler attributes */ +#ifndef __packed +#define __packed __attribute__((packed)) +#endif + +#ifndef __maybe_unused +#define __maybe_unused __attribute__((__unused__)) +#endif extern __u8 *hid_bpf_get_data(struct hid_bpf_ctx *ctx, unsigned int offset, @@ -40,6 +51,86 @@ extern int bpf_wq_set_callback(struct bpf_wq *wq, #define HID_MAX_DESCRIPTOR_SIZE 4096 #define HID_IGNORE_EVENT -1 +/** + * Use: _cleanup_(somefunction) struct foo *bar; + */ +#define _cleanup_(_x) __attribute__((cleanup(_x))) + +/** + * Use: _release_(foo) *bar; + * + * This requires foo_releasep() to be present, use DEFINE_RELEASE_CLEANUP_FUNC. + */ +#define _release_(_type) struct _type __attribute__((cleanup(_type##_releasep))) + +/** + * Define a cleanup function for the struct type foo with a matching + * foo_release(). Use: + * DEFINE_RELEASE_CLEANUP_FUNC(foo) + * _unref_(foo) struct foo *bar; + */ +#define DEFINE_RELEASE_CLEANUP_FUNC(_type) \ + static inline void _type##_releasep(struct _type **_p) { \ + if (*_p) \ + _type##_release(*_p); \ + } \ + struct __useless_struct_to_allow_trailing_semicolon__ + +/* for being able to have a cleanup function */ +#define hid_bpf_ctx_release hid_bpf_release_context +DEFINE_RELEASE_CLEANUP_FUNC(hid_bpf_ctx); + +/* + * Kernel-style guard macros adapted for BPF + * Based on include/linux/cleanup.h from the Linux kernel + * + * These provide automatic lock/unlock using __attribute__((cleanup)) + * similar to how _release_() works for contexts. + */ + +/** + * DEFINE_GUARD(name, type, lock, unlock): + * Define a guard for automatic lock/unlock using the same pattern as _release_() + * @name: identifier for the guard (e.g., bpf_spin) + * @type: lock variable type (e.g., struct bpf_spin_lock) + * @lock: lock function name (e.g., bpf_spin_lock) + * @unlock: unlock function name (e.g., bpf_spin_unlock) + * + * guard(name): + * Declare and lock in one statement - lock held until end of scope + * + * Example: + * DEFINE_GUARD(bpf_spin, struct bpf_spin_lock, bpf_spin_lock, bpf_spin_unlock) + * + * void foo(struct bpf_spin_lock *lock) { + * guard(bpf_spin)(lock); + * // lock held until end of scope + * } + */ + +/* Guard helper struct - stores lock pointer for cleanup */ +#define DEFINE_GUARD(_name, _type, _lock, _unlock) \ +struct _name##_guard { \ + _type *lock; \ +}; \ +static inline void _name##_guard_cleanup(struct _name##_guard *g) { \ + if (g && g->lock) \ + _unlock(g->lock); \ +} \ +static inline struct _name##_guard _name##_guard_init(_type *l) { \ + if (l) \ + _lock(l); \ + return (struct _name##_guard){.lock = l}; \ +} \ +struct __useless_struct_to_allow_trailing_semicolon__ + +#define guard(_name) \ + struct _name##_guard COMBINE(guard, __LINE__) __attribute__((cleanup(_name##_guard_cleanup))) = \ + _name##_guard_init + +/* Define BPF spinlock guard */ +DEFINE_GUARD(bpf_spin, struct bpf_spin_lock, bpf_spin_lock, bpf_spin_unlock); + /* extracted from <linux/input.h> */ #define BUS_ANY 0x00 #define BUS_PCI 0x01 @@ -183,4 +274,234 @@ extern int bpf_wq_set_callback(struct bpf_wq *wq, _EXPAND(_ARG, __VA_ARGS__) \ } _device_ids SEC(".hid_bpf_config") + +/* Equivalency macros for bpf_htons and friends which are + * Big Endian only - HID needs little endian so these are the + * corresponding macros for that. See bpf/bpf_endian.h + */ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define __hid_bpf_le16_to_cpu(x) (x) +# define __hid_bpf_le32_to_cpu(x) (x) +# define __hid_bpf_le64_to_cpu(x) (x) +# define __hid_bpf_cpu_to_le16(x) (x) +# define __hid_bpf_cpu_to_le32(x) (x) +# define __hid_bpf_cpu_to_le64(x) (x) +# define __hid_bpf_constant_le16_to_cpu(x) (x) +# define __hid_bpf_constant_le32_to_cpu(x) (x) +# define __hid_bpf_constant_le64_to_cpu(x) (x) +# define __hid_bpf_constant_cpu_to_le16(x) (x) +# define __hid_bpf_constant_cpu_to_le32(x) (x) +# define __hid_bpf_constant_cpu_to_le64(x) (x) +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define __hid_bpf_le16_to_cpu(x) __builtin_bswap16(x) +# define __hid_bpf_le32_to_cpu(x) __builtin_bswap32(x) +# define __hid_bpf_le64_to_cpu(x) __builtin_bswap64(x) +# define __hid_bpf_cpu_to_le16(x) __builtin_bswap16(x) +# define __hid_bpf_cpu_to_le32(x) __builtin_bswap32(x) +# define __hid_bpf_cpu_to_le64(x) __builtin_bswap64(x) +# define __hid_bpf_constant_le16_to_cpu(x) __bpf_swab16(x) +# define __hid_bpf_constant_le32_to_cpu(x) __bpf_swab32(x) +# define __hid_bpf_constant_le64_to_cpu(x) __bpf_swab64(x) +# define __hid_bpf_constant_cpu_to_le16(x) __bpf_swab16(x) +# define __hid_bpf_constant_cpu_to_le32(x) __bpf_swab32(x) +# define __hid_bpf_constant_cpu_to_le64(x) __bpf_swab64(x) +#else +# error "Invalid __BYTE_ORDER__" +#endif + +#define hid_bpf_le16_to_cpu(x) \ + (__builtin_constant_p(x) ? \ + __hid_bpf_constant_le16_to_cpu(x) : __hid_bpf_le16_to_cpu(x)) + +#define hid_bpf_le32_to_cpu(x) \ + (__builtin_constant_p(x) ? \ + __hid_bpf_constant_le32_to_cpu(x) : __hid_bpf_le32_to_cpu(x)) + +#define hid_bpf_le64_to_cpu(x) \ + (__builtin_constant_p(x) ? \ + __hid_bpf_constant_le64_to_cpu(x) : __hid_bpf_le64_to_cpu(x)) + +#define hid_bpf_cpu_to_le16(x) \ + (__builtin_constant_p(x) ? \ + __hid_bpf_constant_cpu_to_le16(x) : __hid_bpf_cpu_to_le16(x)) + +#define hid_bpf_cpu_to_le32(x) \ + (__builtin_constant_p(x) ? \ + __hid_bpf_constant_cpu_to_le32(x) : __hid_bpf_cpu_to_le32(x)) + +#define hid_bpf_cpu_to_le64(x) \ + (__builtin_constant_p(x) ? \ + __hid_bpf_constant_cpu_to_le64(x) : __hid_bpf_cpu_to_le64(x)) + +#define hid_bpf_be16_to_cpu(x) bpf_ntohs(x) +#define hid_bpf_be32_to_cpu(x) bpf_ntohl(x) +#define hid_bpf_be64_to_cpu(x) bpf_be64_to_cpu(x) +#define hid_bpf_cpu_to_be16(x) bpf_htons(x) +#define hid_bpf_cpu_to_be32(x) bpf_htonl(x) +#define hid_bpf_cpu_to_be64(x) bpf_cpu_to_be64(x) + +/* + * The following macros are helpers for exporting udev properties: + * + * EXPORT_UDEV_PROP(name, len) generates: + * - a map with a single element UDEV_PROP_##name, of size len + * - a const global declaration of that len: SIZEOF_##name + * + * udev_prop_ptr(name) retrieves the data pointer behind the map. + * + * UDEV_PROP_SPRINTF(name, fmt, ...) writes data into the udev property. + * + * Can be used as such: + * EXPORT_UDEV_PROP(HID_FOO, 32); + * + * SEC("syscall") + * int probe(struct hid_bpf_probe_args *ctx) + * { + * const char *foo = "foo"; + * UDEV_PROP_SPRINTF(HID_FOO, "%s", foo); + * + * return 0; + * } + */ +#define EXPORT_UDEV_PROP(name, len) \ + const __u32 SIZEOF_##name = len; \ + struct COMBINE(udev_prop, __LINE__) { \ + __uint(type, BPF_MAP_TYPE_ARRAY); \ + __uint(max_entries, 1); \ + __type(key, __u32); \ + __type(value, __u8[len]); \ + } UDEV_PROP_##name SEC(".maps"); + +#define udev_prop_ptr(name) \ + bpf_map_lookup_elem(&UDEV_PROP_##name, &(__u32){0}) + +#define UDEV_PROP_SPRINTF(name, fmt, ...) \ + BPF_SNPRINTF(udev_prop_ptr(name), SIZEOF_##name, fmt, ##__VA_ARGS__) + +static inline __maybe_unused __u16 field_start_byte(struct hid_rdesc_field *field) +{ + return field->bits_start / 8; +} + +static inline __maybe_unused __u16 field_end_byte(struct hid_rdesc_field *field) +{ + if (!field->bits_end) + return 0; + + return (__u16)(field->bits_end - 1) / 8; +} + +static __maybe_unused __u32 extract_bits(__u8 *buffer, const size_t size, struct hid_rdesc_field *field) +{ + __s32 nbits = field->bits_end - field->bits_start; + __u32 start = field_start_byte(field); + __u32 end = field_end_byte(field); + __u8 base_shift = field->bits_start % 8; + + if (nbits <= 0 || nbits > 32 || start >= size || end >= size) + return 0; + + /* Fast path for byte-aligned standard-sized reads */ + if (base_shift == 0) { + /* 8-bit aligned read */ + if (nbits == 8 && start < size) + return buffer[start]; + + /* 16-bit aligned read - use separate variables for verifier */ + if (nbits == 16) { + __u32 off0 = start; + __u32 off1 = start + 1; + + if (off0 < size && off1 < size) { + return buffer[off0] | + ((__u32)buffer[off1] << 8); + } + } + + /* 32-bit aligned read - use separate variables for verifier */ + if (nbits == 32) { + __u32 off0 = start; + __u32 off1 = start + 1; + __u32 off2 = start + 2; + __u32 off3 = start + 3; + + if (off0 < size && off1 < size && + off2 < size && off3 < size) { + return buffer[off0] | + ((__u32)buffer[off1] << 8) | + ((__u32)buffer[off2] << 16) | + ((__u32)buffer[off3] << 24); + } + } + } + + /* General case: bit manipulation for unaligned or non-standard sizes */ + int mask = 0xffffffff >> (32 - nbits); + __u64 value = 0; + __u32 i; + + bpf_for (i, start, end + 1) { + value |= (__u64)buffer[i] << ((i - start) * 8); + } + + return (value >> base_shift) & mask; +} + +#define EXTRACT_BITS(buffer, field) extract_bits(buffer, sizeof(buffer), field) + +/* Base macro for iterating over HID arrays with bounds checking. + * Follows the bpf_for pattern from libbpf. + */ +#define __hid_bpf_for_each_array(array, num_elements, max_elements, var) \ + for ( \ + /* initialize and define destructor */ \ + struct bpf_iter_num ___it __attribute__((aligned(8), \ + cleanup(bpf_iter_num_destroy))), \ + /* ___p pointer is necessary to call bpf_iter_num_new() *once* */ \ + *___p __attribute__((unused)) = ( \ + /* always initialize iterator; if bounds fail, iterate 0 times */ \ + bpf_iter_num_new(&___it, 0, \ + (num_elements) > (max_elements) ? \ + 0 : (num_elements)), \ + /* workaround for Clang bug */ \ + (void)bpf_iter_num_destroy, (void *)0); \ + ({ \ + /* iteration step */ \ + int *___t = bpf_iter_num_next(&___it); \ + int ___i; \ + /* termination and bounds check, assign var */ \ + (___t && (___i = *___t, ___i >= 0 && ___i < (num_elements)) && \ + ((num_elements) <= (max_elements)) && \ + (var = &(array)[___i], 1)); \ + }); \ + ) + +/* Iterate over input reports in a descriptor */ +#define hid_bpf_for_each_input_report(descriptor, report_var) \ + __hid_bpf_for_each_array((descriptor)->input_reports, \ + (descriptor)->num_input_reports, \ + HID_MAX_REPORTS, report_var) + +/* Iterate over feature reports in a descriptor */ +#define hid_bpf_for_each_feature_report(descriptor, report_var) \ + __hid_bpf_for_each_array((descriptor)->feature_reports, \ + (descriptor)->num_feature_reports, \ + HID_MAX_REPORTS, report_var) + +/* Iterate over output reports in a descriptor */ +#define hid_bpf_for_each_output_report(descriptor, report_var) \ + __hid_bpf_for_each_array((descriptor)->output_reports, \ + (descriptor)->num_output_reports, \ + HID_MAX_REPORTS, report_var) + +/* Iterate over fields in a report */ +#define hid_bpf_for_each_field(report, field_var) \ + __hid_bpf_for_each_array((report)->fields, (report)->num_fields, \ + HID_MAX_FIELDS, field_var) + +/* Iterate over collections in a field */ +#define hid_bpf_for_each_collection(field, collection_var) \ + __hid_bpf_for_each_array((field)->collections, (field)->num_collections, \ + HID_MAX_COLLECTIONS, collection_var) + #endif /* __HID_BPF_HELPERS_H */ diff --git a/drivers/hid/bpf/progs/hid_report_descriptor_helpers.h b/drivers/hid/bpf/progs/hid_report_descriptor_helpers.h new file mode 100644 index 000000000000..2aed5c0a6ad4 --- /dev/null +++ b/drivers/hid/bpf/progs/hid_report_descriptor_helpers.h @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2022 Benjamin Tissoires + */ + +#ifndef __HID_REPORT_DESCRIPTOR_HELPERS_H +#define __HID_REPORT_DESCRIPTOR_HELPERS_H + +#include "vmlinux.h" + +/* Compiler attributes */ +#ifndef __packed +#define __packed __attribute__((packed)) +#endif + +#ifndef __maybe_unused +#define __maybe_unused __attribute__((__unused__)) +#endif + +/* Report Descriptor Structures */ +#define HID_MAX_COLLECTIONS 32 +#define HID_MAX_FIELDS 64 +#define HID_MAX_REPORTS 16 + +enum hid_rdesc_field_type { + HID_FIELD_VARIABLE = 0, + HID_FIELD_ARRAY = 1, + HID_FIELD_CONSTANT = 2, +}; + +struct hid_rdesc_collection { + __u16 usage_page; + __u16 usage_id; + __u8 collection_type; +} __packed; + +struct hid_rdesc_field { + __u8 field_type; /* enum hid_rdesc_field_type */ + __u8 num_collections; + __u16 bits_start; + __u16 bits_end; + __u16 usage_page; + union { + __u16 usage_id; /* For Variable fields */ + struct __packed { /* For Array fields */ + __u16 usage_minimum; + __u16 usage_maximum; + }; + }; + __s32 logical_minimum; + __s32 logical_maximum; + struct { + __u8 is_relative:1; /* Data is relative to previous value */ + __u8 wraps:1; /* Value wraps around (e.g., rotary encoder) */ + __u8 is_nonlinear:1; /* Non-linear relationship between logical/physical */ + __u8 has_no_preferred_state:1; /* No rest position (e.g., free-floating joystick) */ + __u8 has_null_state:1; /* Can report null/no-data values */ + __u8 is_volatile:1; /* Volatile (Output/Feature) - NOT POPULATED, always 0 */ + __u8 is_buffered_bytes:1; /* Fixed-size byte stream vs bitfield */ + __u8 reserved:1; /* Reserved for future use */ + } flags; + struct hid_rdesc_collection collections[HID_MAX_COLLECTIONS]; +} __packed; + +struct hid_rdesc_report { + __u8 report_id; /* 0 means no report ID */ + __u16 size_in_bits; + __u8 num_fields; + struct hid_rdesc_field fields[HID_MAX_FIELDS]; +} __packed; + +struct hid_rdesc_descriptor { + __u8 num_input_reports; + __u8 num_output_reports; + __u8 num_feature_reports; + struct hid_rdesc_report input_reports[HID_MAX_REPORTS]; + struct hid_rdesc_report output_reports[HID_MAX_REPORTS]; + struct hid_rdesc_report feature_reports[HID_MAX_REPORTS]; +} __packed; + +#endif /* __HID_REPORT_DESCRIPTOR_HELPERS_H */ diff --git a/drivers/hid/bpf/progs/hid_usages.h b/drivers/hid/bpf/progs/hid_usages.h new file mode 100644 index 000000000000..5469b25c9f79 --- /dev/null +++ b/drivers/hid/bpf/progs/hid_usages.h @@ -0,0 +1,2810 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2025 Red Hat, Inc + */ + +// THIS FILE IS GENERATED, DO NOT EDIT + +#pragma once + +/* ----- Generated Usage Pages and Usages ------ */ +#define HidUsagePage_GenericDesktop 0x01 +#define HidUsagePage_SimulationControls 0x02 +#define HidUsagePage_VRControls 0x03 +#define HidUsagePage_SportControls 0x04 +#define HidUsagePage_GameControls 0x05 +#define HidUsagePage_GenericDeviceControls 0x06 +#define HidUsagePage_KeyboardKeypad 0x07 +#define HidUsagePage_LED 0x08 +#define HidUsagePage_Button 0x09 +#define HidUsagePage_Ordinal 0x0a +#define HidUsagePage_TelephonyDevice 0x0b +#define HidUsagePage_Consumer 0x0c +#define HidUsagePage_Digitizers 0x0d +#define HidUsagePage_Haptics 0x0e +#define HidUsagePage_PhysicalInputDevice 0x0f +#define HidUsagePage_Unicode 0x10 +#define HidUsagePage_SoC 0x11 +#define HidUsagePage_EyeandHeadTrackers 0x12 +#define HidUsagePage_AuxiliaryDisplay 0x14 +#define HidUsagePage_Sensors 0x20 +#define HidUsagePage_MedicalInstrument 0x40 +#define HidUsagePage_BrailleDisplay 0x41 +#define HidUsagePage_LightingAndIllumination 0x59 +#define HidUsagePage_Monitor 0x80 +#define HidUsagePage_MonitorEnumerated 0x81 +#define HidUsagePage_VESAVirtualControls 0x82 +#define HidUsagePage_Power 0x84 +#define HidUsagePage_BatterySystem 0x85 +#define HidUsagePage_BarcodeScanner 0x8c +#define HidUsagePage_Scales 0x8d +#define HidUsagePage_MagneticStripeReader 0x8e +#define HidUsagePage_CameraControl 0x90 +#define HidUsagePage_Arcade 0x91 +#define HidUsagePage_FIDOAlliance 0xf1d0 + +#define HidUsage_GD_Pointer 0x01 +#define HidUsage_GD_Mouse 0x02 +#define HidUsage_GD_Joystick 0x04 +#define HidUsage_GD_Gamepad 0x05 +#define HidUsage_GD_Keyboard 0x06 +#define HidUsage_GD_Keypad 0x07 +#define HidUsage_GD_MultiaxisController 0x08 +#define HidUsage_GD_TabletPCSystemControls 0x09 +#define HidUsage_GD_WaterCoolingDevice 0x0a +#define HidUsage_GD_ComputerChassisDevice 0x0b +#define HidUsage_GD_WirelessRadioControls 0x0c +#define HidUsage_GD_PortableDeviceControl 0x0d +#define HidUsage_GD_SystemMultiAxisController 0x0e +#define HidUsage_GD_SpatialController 0x0f +#define HidUsage_GD_AssistiveControl 0x10 +#define HidUsage_GD_DeviceDock 0x11 +#define HidUsage_GD_DockableDevice 0x12 +#define HidUsage_GD_CallStateManagementControl 0x13 +#define HidUsage_GD_X 0x30 +#define HidUsage_GD_Y 0x31 +#define HidUsage_GD_Z 0x32 +#define HidUsage_GD_Rx 0x33 +#define HidUsage_GD_Ry 0x34 +#define HidUsage_GD_Rz 0x35 +#define HidUsage_GD_Slider 0x36 +#define HidUsage_GD_Dial 0x37 +#define HidUsage_GD_Wheel 0x38 +#define HidUsage_GD_HatSwitch 0x39 +#define HidUsage_GD_CountedBuffer 0x3a +#define HidUsage_GD_ByteCount 0x3b +#define HidUsage_GD_MotionWakeup 0x3c +#define HidUsage_GD_Start 0x3d +#define HidUsage_GD_Select 0x3e +#define HidUsage_GD_Vx 0x40 +#define HidUsage_GD_Vy 0x41 +#define HidUsage_GD_Vz 0x42 +#define HidUsage_GD_Vbrx 0x43 +#define HidUsage_GD_Vbry 0x44 +#define HidUsage_GD_Vbrz 0x45 +#define HidUsage_GD_Vno 0x46 +#define HidUsage_GD_FeatureNotification 0x47 +#define HidUsage_GD_ResolutionMultiplier 0x48 +#define HidUsage_GD_Qx 0x49 +#define HidUsage_GD_Qy 0x4a +#define HidUsage_GD_Qz 0x4b +#define HidUsage_GD_Qw 0x4c +#define HidUsage_GD_SystemControl 0x80 +#define HidUsage_GD_SystemPowerDown 0x81 +#define HidUsage_GD_SystemSleep 0x82 +#define HidUsage_GD_SystemWakeUp 0x83 +#define HidUsage_GD_SystemContextMenu 0x84 +#define HidUsage_GD_SystemMainMenu 0x85 +#define HidUsage_GD_SystemAppMenu 0x86 +#define HidUsage_GD_SystemMenuHelp 0x87 +#define HidUsage_GD_SystemMenuExit 0x88 +#define HidUsage_GD_SystemMenuSelect 0x89 +#define HidUsage_GD_SystemMenuRight 0x8a +#define HidUsage_GD_SystemMenuLeft 0x8b +#define HidUsage_GD_SystemMenuUp 0x8c +#define HidUsage_GD_SystemMenuDown 0x8d +#define HidUsage_GD_SystemColdRestart 0x8e +#define HidUsage_GD_SystemWarmRestart 0x8f +#define HidUsage_GD_DpadUp 0x90 +#define HidUsage_GD_DpadDown 0x91 +#define HidUsage_GD_DpadRight 0x92 +#define HidUsage_GD_DpadLeft 0x93 +#define HidUsage_GD_IndexTrigger 0x94 +#define HidUsage_GD_PalmTrigger 0x95 +#define HidUsage_GD_Thumbstick 0x96 +#define HidUsage_GD_SystemFunctionShift 0x97 +#define HidUsage_GD_SystemFunctionShiftLock 0x98 +#define HidUsage_GD_SystemFunctionShiftLockIndicator 0x99 +#define HidUsage_GD_SystemDismissNotification 0x9a +#define HidUsage_GD_SystemDoNotDisturb 0x9b +#define HidUsage_GD_SystemDock 0xa0 +#define HidUsage_GD_SystemUndock 0xa1 +#define HidUsage_GD_SystemSetup 0xa2 +#define HidUsage_GD_SystemBreak 0xa3 +#define HidUsage_GD_SystemDebuggerBreak 0xa4 +#define HidUsage_GD_ApplicationBreak 0xa5 +#define HidUsage_GD_ApplicationDebuggerBreak 0xa6 +#define HidUsage_GD_SystemSpeakerMute 0xa7 +#define HidUsage_GD_SystemHibernate 0xa8 +#define HidUsage_GD_SystemMicrophoneMute 0xa9 +#define HidUsage_GD_SystemAccessibilityBinding 0xaa +#define HidUsage_GD_SystemDisplayInvert 0xb0 +#define HidUsage_GD_SystemDisplayInternal 0xb1 +#define HidUsage_GD_SystemDisplayExternal 0xb2 +#define HidUsage_GD_SystemDisplayBoth 0xb3 +#define HidUsage_GD_SystemDisplayDual 0xb4 +#define HidUsage_GD_SystemDisplayToggleIntExtMode 0xb5 +#define HidUsage_GD_SystemDisplaySwapPrimarySecondary 0xb6 +#define HidUsage_GD_SystemDisplayToggleLCDAutoscale 0xb7 +#define HidUsage_GD_SensorZone 0xc0 +#define HidUsage_GD_RPM 0xc1 +#define HidUsage_GD_CoolantLevel 0xc2 +#define HidUsage_GD_CoolantCriticalLevel 0xc3 +#define HidUsage_GD_CoolantPump 0xc4 +#define HidUsage_GD_ChassisEnclosure 0xc5 +#define HidUsage_GD_WirelessRadioButton 0xc6 +#define HidUsage_GD_WirelessRadioLED 0xc7 +#define HidUsage_GD_WirelessRadioSliderSwitch 0xc8 +#define HidUsage_GD_SystemDisplayRotationLockButton 0xc9 +#define HidUsage_GD_SystemDisplayRotationLockSliderSwitch 0xca +#define HidUsage_GD_ControlEnable 0xcb +#define HidUsage_GD_DockableDeviceUniqueID 0xd0 +#define HidUsage_GD_DockableDeviceVendorID 0xd1 +#define HidUsage_GD_DockableDevicePrimaryUsagePage 0xd2 +#define HidUsage_GD_DockableDevicePrimaryUsageID 0xd3 +#define HidUsage_GD_DockableDeviceDockingState 0xd4 +#define HidUsage_GD_DockableDeviceDisplayOcclusion 0xd5 +#define HidUsage_GD_DockableDeviceObjectType 0xd6 +#define HidUsage_GD_CallActiveLED 0xe0 +#define HidUsage_GD_CallMuteToggle 0xe1 +#define HidUsage_GD_CallMuteLED 0xe2 +#define HidUsage_SC_FlightSimulationDevice 0x01 +#define HidUsage_SC_AutomobileSimulationDevice 0x02 +#define HidUsage_SC_TankSimulationDevice 0x03 +#define HidUsage_SC_SpaceshipSimulationDevice 0x04 +#define HidUsage_SC_SubmarineSimulationDevice 0x05 +#define HidUsage_SC_SailingSimulationDevice 0x06 +#define HidUsage_SC_MotorcycleSimulationDevice 0x07 +#define HidUsage_SC_SportsSimulationDevice 0x08 +#define HidUsage_SC_AirplaneSimulationDevice 0x09 +#define HidUsage_SC_HelicopterSimulationDevice 0x0a +#define HidUsage_SC_MagicCarpetSimulationDevice 0x0b +#define HidUsage_SC_BicycleSimulationDevice 0x0c +#define HidUsage_SC_FlightControlStick 0x20 +#define HidUsage_SC_FlightStick 0x21 +#define HidUsage_SC_CyclicControl 0x22 +#define HidUsage_SC_CyclicTrim 0x23 +#define HidUsage_SC_FlightYoke 0x24 +#define HidUsage_SC_TrackControl 0x25 +#define HidUsage_SC_Aileron 0xb0 +#define HidUsage_SC_AileronTrim 0xb1 +#define HidUsage_SC_AntiTorqueControl 0xb2 +#define HidUsage_SC_AutopilotEnable 0xb3 +#define HidUsage_SC_ChaffRelease 0xb4 +#define HidUsage_SC_CollectiveControl 0xb5 +#define HidUsage_SC_DiveBrake 0xb6 +#define HidUsage_SC_ElectronicCountermeasures 0xb7 +#define HidUsage_SC_Elevator 0xb8 +#define HidUsage_SC_ElevatorTrim 0xb9 +#define HidUsage_SC_Rudder 0xba +#define HidUsage_SC_Throttle 0xbb +#define HidUsage_SC_FlightCommunications 0xbc +#define HidUsage_SC_FlareRelease 0xbd +#define HidUsage_SC_LandingGear 0xbe +#define HidUsage_SC_ToeBrake 0xbf +#define HidUsage_SC_Trigger 0xc0 +#define HidUsage_SC_WeaponsArm 0xc1 +#define HidUsage_SC_WeaponsSelect 0xc2 +#define HidUsage_SC_WingFlaps 0xc3 +#define HidUsage_SC_Accelerator 0xc4 +#define HidUsage_SC_Brake 0xc5 +#define HidUsage_SC_Clutch 0xc6 +#define HidUsage_SC_Shifter 0xc7 +#define HidUsage_SC_Steering 0xc8 +#define HidUsage_SC_TurretDirection 0xc9 +#define HidUsage_SC_BarrelElevation 0xca +#define HidUsage_SC_DivePlane 0xcb +#define HidUsage_SC_Ballast 0xcc +#define HidUsage_SC_BicycleCrank 0xcd +#define HidUsage_SC_HandleBars 0xce +#define HidUsage_SC_FrontBrake 0xcf +#define HidUsage_SC_RearBrake 0xd0 +#define HidUsage_VRC_Belt 0x01 +#define HidUsage_VRC_BodySuit 0x02 +#define HidUsage_VRC_Flexor 0x03 +#define HidUsage_VRC_Glove 0x04 +#define HidUsage_VRC_HeadTracker 0x05 +#define HidUsage_VRC_HeadMountedDisplay 0x06 +#define HidUsage_VRC_HandTracker 0x07 +#define HidUsage_VRC_Oculometer 0x08 +#define HidUsage_VRC_Vest 0x09 +#define HidUsage_VRC_AnimatronicDevice 0x0a +#define HidUsage_VRC_StereoEnable 0x20 +#define HidUsage_VRC_DisplayEnable 0x21 +#define HidUsage_SC_BaseballBat 0x01 +#define HidUsage_SC_GolfClub 0x02 +#define HidUsage_SC_RowingMachine 0x03 +#define HidUsage_SC_Treadmill 0x04 +#define HidUsage_SC_Oar 0x30 +#define HidUsage_SC_Slope 0x31 +#define HidUsage_SC_Rate 0x32 +#define HidUsage_SC_StickSpeed 0x33 +#define HidUsage_SC_StickFaceAngle 0x34 +#define HidUsage_SC_StickHeelToe 0x35 +#define HidUsage_SC_StickFollowThrough 0x36 +#define HidUsage_SC_StickTempo 0x37 +#define HidUsage_SC_StickType 0x38 +#define HidUsage_SC_StickHeight 0x39 +#define HidUsage_SC_Putter 0x50 +#define HidUsage_SC_OneIron 0x51 +#define HidUsage_SC_TwoIron 0x52 +#define HidUsage_SC_ThreeIron 0x53 +#define HidUsage_SC_FourIron 0x54 +#define HidUsage_SC_FiveIron 0x55 +#define HidUsage_SC_SixIron 0x56 +#define HidUsage_SC_SevenIron 0x57 +#define HidUsage_SC_EightIron 0x58 +#define HidUsage_SC_NineIron 0x59 +#define HidUsage_SC_One0Iron 0x5a +#define HidUsage_SC_One1Iron 0x5b +#define HidUsage_SC_SandWedge 0x5c +#define HidUsage_SC_LoftWedge 0x5d +#define HidUsage_SC_PowerWedge 0x5e +#define HidUsage_SC_OneWood 0x5f +#define HidUsage_SC_ThreeWood 0x60 +#define HidUsage_SC_FiveWood 0x61 +#define HidUsage_SC_SevenWood 0x62 +#define HidUsage_SC_NineWood 0x63 +#define HidUsage_GC_ThreeDGameController 0x01 +#define HidUsage_GC_PinballDevice 0x02 +#define HidUsage_GC_GunDevice 0x03 +#define HidUsage_GC_PointofView 0x20 +#define HidUsage_GC_TurnRightLeft 0x21 +#define HidUsage_GC_PitchForwardBackward 0x22 +#define HidUsage_GC_RollRightLeft 0x23 +#define HidUsage_GC_MoveRightLeft 0x24 +#define HidUsage_GC_MoveForwardBackward 0x25 +#define HidUsage_GC_MoveUpDown 0x26 +#define HidUsage_GC_LeanRightLeft 0x27 +#define HidUsage_GC_LeanForwardBackward 0x28 +#define HidUsage_GC_HeightofPOV 0x29 +#define HidUsage_GC_Flipper 0x2a +#define HidUsage_GC_SecondaryFlipper 0x2b +#define HidUsage_GC_Bump 0x2c +#define HidUsage_GC_NewGame 0x2d +#define HidUsage_GC_ShootBall 0x2e +#define HidUsage_GC_Player 0x2f +#define HidUsage_GC_GunBolt 0x30 +#define HidUsage_GC_GunClip 0x31 +#define HidUsage_GC_GunSelector 0x32 +#define HidUsage_GC_GunSingleShot 0x33 +#define HidUsage_GC_GunBurst 0x34 +#define HidUsage_GC_GunAutomatic 0x35 +#define HidUsage_GC_GunSafety 0x36 +#define HidUsage_GC_GamepadFireJump 0x37 +#define HidUsage_GC_GamepadTrigger 0x39 +#define HidUsage_GC_FormfittingGamepad 0x3a +#define HidUsage_GDC_BackgroundNonuserControls 0x01 +#define HidUsage_GDC_BatteryStrength 0x20 +#define HidUsage_GDC_WirelessChannel 0x21 +#define HidUsage_GDC_WirelessID 0x22 +#define HidUsage_GDC_DiscoverWirelessControl 0x23 +#define HidUsage_GDC_SecurityCodeCharacterEntered 0x24 +#define HidUsage_GDC_SecurityCodeCharacterErased 0x25 +#define HidUsage_GDC_SecurityCodeCleared 0x26 +#define HidUsage_GDC_SequenceID 0x27 +#define HidUsage_GDC_SequenceIDReset 0x28 +#define HidUsage_GDC_RFSignalStrength 0x29 +#define HidUsage_GDC_SoftwareVersion 0x2a +#define HidUsage_GDC_ProtocolVersion 0x2b +#define HidUsage_GDC_HardwareVersion 0x2c +#define HidUsage_GDC_Major 0x2d +#define HidUsage_GDC_Minor 0x2e +#define HidUsage_GDC_Revision 0x2f +#define HidUsage_GDC_Handedness 0x30 +#define HidUsage_GDC_EitherHand 0x31 +#define HidUsage_GDC_LeftHand 0x32 +#define HidUsage_GDC_RightHand 0x33 +#define HidUsage_GDC_BothHands 0x34 +#define HidUsage_GDC_GripPoseOffset 0x40 +#define HidUsage_GDC_PointerPoseOffset 0x41 +#define HidUsage_KK_ErrorRollOver 0x01 +#define HidUsage_KK_POSTFail 0x02 +#define HidUsage_KK_ErrorUndefined 0x03 +#define HidUsage_KK_KeyboardA 0x04 +#define HidUsage_KK_KeyboardB 0x05 +#define HidUsage_KK_KeyboardC 0x06 +#define HidUsage_KK_KeyboardD 0x07 +#define HidUsage_KK_KeyboardE 0x08 +#define HidUsage_KK_KeyboardF 0x09 +#define HidUsage_KK_KeyboardG 0x0a +#define HidUsage_KK_KeyboardH 0x0b +#define HidUsage_KK_KeyboardI 0x0c +#define HidUsage_KK_KeyboardJ 0x0d +#define HidUsage_KK_KeyboardK 0x0e +#define HidUsage_KK_KeyboardL 0x0f +#define HidUsage_KK_KeyboardM 0x10 +#define HidUsage_KK_KeyboardN 0x11 +#define HidUsage_KK_KeyboardO 0x12 +#define HidUsage_KK_KeyboardP 0x13 +#define HidUsage_KK_KeyboardQ 0x14 +#define HidUsage_KK_KeyboardR 0x15 +#define HidUsage_KK_KeyboardS 0x16 +#define HidUsage_KK_KeyboardT 0x17 +#define HidUsage_KK_KeyboardU 0x18 +#define HidUsage_KK_KeyboardV 0x19 +#define HidUsage_KK_KeyboardW 0x1a +#define HidUsage_KK_KeyboardX 0x1b +#define HidUsage_KK_KeyboardY 0x1c +#define HidUsage_KK_KeyboardZ 0x1d +#define HidUsage_KK_Keyboard1andBang 0x1e +#define HidUsage_KK_Keyboard2andAt 0x1f +#define HidUsage_KK_Keyboard3andHash 0x20 +#define HidUsage_KK_Keyboard4andDollar 0x21 +#define HidUsage_KK_Keyboard5andPercent 0x22 +#define HidUsage_KK_Keyboard6andCaret 0x23 +#define HidUsage_KK_Keyboard7andAmpersand 0x24 +#define HidUsage_KK_Keyboard8andStar 0x25 +#define HidUsage_KK_Keyboard9andLeftBracket 0x26 +#define HidUsage_KK_Keyboard0andRightBracket 0x27 +#define HidUsage_KK_KeyboardReturnEnter 0x28 +#define HidUsage_KK_KeyboardEscape 0x29 +#define HidUsage_KK_KeyboardDelete 0x2a +#define HidUsage_KK_KeyboardTab 0x2b +#define HidUsage_KK_KeyboardSpacebar 0x2c +#define HidUsage_KK_KeyboardDashandUnderscore 0x2d +#define HidUsage_KK_KeyboardEqualsandPlus 0x2e +#define HidUsage_KK_KeyboardLeftBrace 0x2f +#define HidUsage_KK_KeyboardRightBrace 0x30 +#define HidUsage_KK_KeyboardBackslashandPipe 0x31 +#define HidUsage_KK_KeyboardNonUSHashandTilde 0x32 +#define HidUsage_KK_KeyboardSemiColonandColon 0x33 +#define HidUsage_KK_KeyboardLeftAposandDouble 0x34 +#define HidUsage_KK_KeyboardGraveAccentandTilde 0x35 +#define HidUsage_KK_KeyboardCommaandLessThan 0x36 +#define HidUsage_KK_KeyboardPeriodandGreaterThan 0x37 +#define HidUsage_KK_KeyboardForwardSlashandQuestionMark 0x38 +#define HidUsage_KK_KeyboardCapsLock 0x39 +#define HidUsage_KK_KeyboardF1 0x3a +#define HidUsage_KK_KeyboardF2 0x3b +#define HidUsage_KK_KeyboardF3 0x3c +#define HidUsage_KK_KeyboardF4 0x3d +#define HidUsage_KK_KeyboardF5 0x3e +#define HidUsage_KK_KeyboardF6 0x3f +#define HidUsage_KK_KeyboardF7 0x40 +#define HidUsage_KK_KeyboardF8 0x41 +#define HidUsage_KK_KeyboardF9 0x42 +#define HidUsage_KK_KeyboardF10 0x43 +#define HidUsage_KK_KeyboardF11 0x44 +#define HidUsage_KK_KeyboardF12 0x45 +#define HidUsage_KK_KeyboardPrintScreen 0x46 +#define HidUsage_KK_KeyboardScrollLock 0x47 +#define HidUsage_KK_KeyboardPause 0x48 +#define HidUsage_KK_KeyboardInsert 0x49 +#define HidUsage_KK_KeyboardHome 0x4a +#define HidUsage_KK_KeyboardPageUp 0x4b +#define HidUsage_KK_KeyboardDeleteForward 0x4c +#define HidUsage_KK_KeyboardEnd 0x4d +#define HidUsage_KK_KeyboardPageDown 0x4e +#define HidUsage_KK_KeyboardRightArrow 0x4f +#define HidUsage_KK_KeyboardLeftArrow 0x50 +#define HidUsage_KK_KeyboardDownArrow 0x51 +#define HidUsage_KK_KeyboardUpArrow 0x52 +#define HidUsage_KK_KeypadNumLockandClear 0x53 +#define HidUsage_KK_KeypadForwardSlash 0x54 +#define HidUsage_KK_KeypadStar 0x55 +#define HidUsage_KK_KeypadDash 0x56 +#define HidUsage_KK_KeypadPlus 0x57 +#define HidUsage_KK_KeypadENTER 0x58 +#define HidUsage_KK_Keypad1andEnd 0x59 +#define HidUsage_KK_Keypad2andDownArrow 0x5a +#define HidUsage_KK_Keypad3andPageDn 0x5b +#define HidUsage_KK_Keypad4andLeftArrow 0x5c +#define HidUsage_KK_Keypad5 0x5d +#define HidUsage_KK_Keypad6andRightArrow 0x5e +#define HidUsage_KK_Keypad7andHome 0x5f +#define HidUsage_KK_Keypad8andUpArrow 0x60 +#define HidUsage_KK_Keypad9andPageUp 0x61 +#define HidUsage_KK_Keypad0andInsert 0x62 +#define HidUsage_KK_KeypadPeriodandDelete 0x63 +#define HidUsage_KK_KeyboardNonUSBackslashandPipe 0x64 +#define HidUsage_KK_KeyboardApplication 0x65 +#define HidUsage_KK_KeyboardPower 0x66 +#define HidUsage_KK_KeypadEquals 0x67 +#define HidUsage_KK_KeyboardF13 0x68 +#define HidUsage_KK_KeyboardF14 0x69 +#define HidUsage_KK_KeyboardF15 0x6a +#define HidUsage_KK_KeyboardF16 0x6b +#define HidUsage_KK_KeyboardF17 0x6c +#define HidUsage_KK_KeyboardF18 0x6d +#define HidUsage_KK_KeyboardF19 0x6e +#define HidUsage_KK_KeyboardF20 0x6f +#define HidUsage_KK_KeyboardF21 0x70 +#define HidUsage_KK_KeyboardF22 0x71 +#define HidUsage_KK_KeyboardF23 0x72 +#define HidUsage_KK_KeyboardF24 0x73 +#define HidUsage_KK_KeyboardExecute 0x74 +#define HidUsage_KK_KeyboardHelp 0x75 +#define HidUsage_KK_KeyboardMenu 0x76 +#define HidUsage_KK_KeyboardSelect 0x77 +#define HidUsage_KK_KeyboardStop 0x78 +#define HidUsage_KK_KeyboardAgain 0x79 +#define HidUsage_KK_KeyboardUndo 0x7a +#define HidUsage_KK_KeyboardCut 0x7b +#define HidUsage_KK_KeyboardCopy 0x7c +#define HidUsage_KK_KeyboardPaste 0x7d +#define HidUsage_KK_KeyboardFind 0x7e +#define HidUsage_KK_KeyboardMute 0x7f +#define HidUsage_KK_KeyboardVolumeUp 0x80 +#define HidUsage_KK_KeyboardVolumeDown 0x81 +#define HidUsage_KK_KeyboardLockingCapsLock 0x82 +#define HidUsage_KK_KeyboardLockingNumLock 0x83 +#define HidUsage_KK_KeyboardLockingScrollLock 0x84 +#define HidUsage_KK_KeypadComma 0x85 +#define HidUsage_KK_KeypadEqualSign 0x86 +#define HidUsage_KK_KeyboardInternational1 0x87 +#define HidUsage_KK_KeyboardInternational2 0x88 +#define HidUsage_KK_KeyboardInternational3 0x89 +#define HidUsage_KK_KeyboardInternational4 0x8a +#define HidUsage_KK_KeyboardInternational5 0x8b +#define HidUsage_KK_KeyboardInternational6 0x8c +#define HidUsage_KK_KeyboardInternational7 0x8d +#define HidUsage_KK_KeyboardInternational8 0x8e +#define HidUsage_KK_KeyboardInternational9 0x8f +#define HidUsage_KK_KeyboardLANG1 0x90 +#define HidUsage_KK_KeyboardLANG2 0x91 +#define HidUsage_KK_KeyboardLANG3 0x92 +#define HidUsage_KK_KeyboardLANG4 0x93 +#define HidUsage_KK_KeyboardLANG5 0x94 +#define HidUsage_KK_KeyboardLANG6 0x95 +#define HidUsage_KK_KeyboardLANG7 0x96 +#define HidUsage_KK_KeyboardLANG8 0x97 +#define HidUsage_KK_KeyboardLANG9 0x98 +#define HidUsage_KK_KeyboardAlternateErase 0x99 +#define HidUsage_KK_KeyboardSysReqAttention 0x9a +#define HidUsage_KK_KeyboardCancel 0x9b +#define HidUsage_KK_KeyboardClear 0x9c +#define HidUsage_KK_KeyboardPrior 0x9d +#define HidUsage_KK_KeyboardReturn 0x9e +#define HidUsage_KK_KeyboardSeparator 0x9f +#define HidUsage_KK_KeyboardOut 0xa0 +#define HidUsage_KK_KeyboardOper 0xa1 +#define HidUsage_KK_KeyboardClearAgain 0xa2 +#define HidUsage_KK_KeyboardCrSelProps 0xa3 +#define HidUsage_KK_KeyboardExSel 0xa4 +#define HidUsage_KK_KeypadDouble0 0xb0 +#define HidUsage_KK_KeypadTriple0 0xb1 +#define HidUsage_KK_ThousandsSeparator 0xb2 +#define HidUsage_KK_DecimalSeparator 0xb3 +#define HidUsage_KK_CurrencyUnit 0xb4 +#define HidUsage_KK_CurrencySubunit 0xb5 +#define HidUsage_KK_KeypadLeftBracket 0xb6 +#define HidUsage_KK_KeypadRightBracket 0xb7 +#define HidUsage_KK_KeypadLeftBrace 0xb8 +#define HidUsage_KK_KeypadRightBrace 0xb9 +#define HidUsage_KK_KeypadTab 0xba +#define HidUsage_KK_KeypadBackspace 0xbb +#define HidUsage_KK_KeypadA 0xbc +#define HidUsage_KK_KeypadB 0xbd +#define HidUsage_KK_KeypadC 0xbe +#define HidUsage_KK_KeypadD 0xbf +#define HidUsage_KK_KeypadE 0xc0 +#define HidUsage_KK_KeypadF 0xc1 +#define HidUsage_KK_KeypadXOR 0xc2 +#define HidUsage_KK_KeypadCaret 0xc3 +#define HidUsage_KK_KeypadPercentage 0xc4 +#define HidUsage_KK_KeypadLess 0xc5 +#define HidUsage_KK_KeypadGreater 0xc6 +#define HidUsage_KK_KeypadAmpersand 0xc7 +#define HidUsage_KK_KeypadDoubleAmpersand 0xc8 +#define HidUsage_KK_KeypadBar 0xc9 +#define HidUsage_KK_KeypadDoubleBar 0xca +#define HidUsage_KK_KeypadColon 0xcb +#define HidUsage_KK_KeypadHash 0xcc +#define HidUsage_KK_KeypadSpace 0xcd +#define HidUsage_KK_KeypadAt 0xce +#define HidUsage_KK_KeypadBang 0xcf +#define HidUsage_KK_KeypadMemoryStore 0xd0 +#define HidUsage_KK_KeypadMemoryRecall 0xd1 +#define HidUsage_KK_KeypadMemoryClear 0xd2 +#define HidUsage_KK_KeypadMemoryAdd 0xd3 +#define HidUsage_KK_KeypadMemorySubtract 0xd4 +#define HidUsage_KK_KeypadMemoryMultiply 0xd5 +#define HidUsage_KK_KeypadMemoryDivide 0xd6 +#define HidUsage_KK_KeypadPlusMinus 0xd7 +#define HidUsage_KK_KeypadClear 0xd8 +#define HidUsage_KK_KeypadClearEntry 0xd9 +#define HidUsage_KK_KeypadBinary 0xda +#define HidUsage_KK_KeypadOctal 0xdb +#define HidUsage_KK_KeypadDecimal 0xdc +#define HidUsage_KK_KeypadHexadecimal 0xdd +#define HidUsage_KK_KeyboardLeftControl 0xe0 +#define HidUsage_KK_KeyboardLeftShift 0xe1 +#define HidUsage_KK_KeyboardLeftAlt 0xe2 +#define HidUsage_KK_KeyboardLeftGUI 0xe3 +#define HidUsage_KK_KeyboardRightControl 0xe4 +#define HidUsage_KK_KeyboardRightShift 0xe5 +#define HidUsage_KK_KeyboardRightAlt 0xe6 +#define HidUsage_KK_KeyboardRightGUI 0xe7 +#define HidUsage_LED_NumLock 0x01 +#define HidUsage_LED_CapsLock 0x02 +#define HidUsage_LED_ScrollLock 0x03 +#define HidUsage_LED_Compose 0x04 +#define HidUsage_LED_Kana 0x05 +#define HidUsage_LED_Power 0x06 +#define HidUsage_LED_Shift 0x07 +#define HidUsage_LED_DoNotDisturb 0x08 +#define HidUsage_LED_Mute 0x09 +#define HidUsage_LED_ToneEnable 0x0a +#define HidUsage_LED_HighCutFilter 0x0b +#define HidUsage_LED_LowCutFilter 0x0c +#define HidUsage_LED_EqualizerEnable 0x0d +#define HidUsage_LED_SoundFieldOn 0x0e +#define HidUsage_LED_SurroundOn 0x0f +#define HidUsage_LED_Repeat 0x10 +#define HidUsage_LED_Stereo 0x11 +#define HidUsage_LED_SamplingRateDetect 0x12 +#define HidUsage_LED_Spinning 0x13 +#define HidUsage_LED_CAV 0x14 +#define HidUsage_LED_CLV 0x15 +#define HidUsage_LED_RecordingFormatDetect 0x16 +#define HidUsage_LED_OffHook 0x17 +#define HidUsage_LED_Ring 0x18 +#define HidUsage_LED_MessageWaiting 0x19 +#define HidUsage_LED_DataMode 0x1a +#define HidUsage_LED_BatteryOperation 0x1b +#define HidUsage_LED_BatteryOK 0x1c +#define HidUsage_LED_BatteryLow 0x1d +#define HidUsage_LED_Speaker 0x1e +#define HidUsage_LED_Headset 0x1f +#define HidUsage_LED_Hold 0x20 +#define HidUsage_LED_Microphone 0x21 +#define HidUsage_LED_Coverage 0x22 +#define HidUsage_LED_NightMode 0x23 +#define HidUsage_LED_SendCalls 0x24 +#define HidUsage_LED_CallPickup 0x25 +#define HidUsage_LED_Conference 0x26 +#define HidUsage_LED_Standby 0x27 +#define HidUsage_LED_CameraOn 0x28 +#define HidUsage_LED_CameraOff 0x29 +#define HidUsage_LED_OnLine 0x2a +#define HidUsage_LED_OffLine 0x2b +#define HidUsage_LED_Busy 0x2c +#define HidUsage_LED_Ready 0x2d +#define HidUsage_LED_PaperOut 0x2e +#define HidUsage_LED_PaperJam 0x2f +#define HidUsage_LED_Remote 0x30 +#define HidUsage_LED_Forward 0x31 +#define HidUsage_LED_Reverse 0x32 +#define HidUsage_LED_Stop 0x33 +#define HidUsage_LED_Rewind 0x34 +#define HidUsage_LED_FastForward 0x35 +#define HidUsage_LED_Play 0x36 +#define HidUsage_LED_Pause 0x37 +#define HidUsage_LED_Record 0x38 +#define HidUsage_LED_Error 0x39 +#define HidUsage_LED_UsageSelectedIndicator 0x3a +#define HidUsage_LED_UsageInUseIndicator 0x3b +#define HidUsage_LED_UsageMultiModeIndicator 0x3c +#define HidUsage_LED_IndicatorOn 0x3d +#define HidUsage_LED_IndicatorFlash 0x3e +#define HidUsage_LED_IndicatorSlowBlink 0x3f +#define HidUsage_LED_IndicatorFastBlink 0x40 +#define HidUsage_LED_IndicatorOff 0x41 +#define HidUsage_LED_FlashOnTime 0x42 +#define HidUsage_LED_SlowBlinkOnTime 0x43 +#define HidUsage_LED_SlowBlinkOffTime 0x44 +#define HidUsage_LED_FastBlinkOnTime 0x45 +#define HidUsage_LED_FastBlinkOffTime 0x46 +#define HidUsage_LED_UsageIndicatorColor 0x47 +#define HidUsage_LED_IndicatorRed 0x48 +#define HidUsage_LED_IndicatorGreen 0x49 +#define HidUsage_LED_IndicatorAmber 0x4a +#define HidUsage_LED_GenericIndicator 0x4b +#define HidUsage_LED_SystemSuspend 0x4c +#define HidUsage_LED_ExternalPowerConnected 0x4d +#define HidUsage_LED_IndicatorBlue 0x4e +#define HidUsage_LED_IndicatorOrange 0x4f +#define HidUsage_LED_GoodStatus 0x50 +#define HidUsage_LED_WarningStatus 0x51 +#define HidUsage_LED_RGBLED 0x52 +#define HidUsage_LED_RedLEDChannel 0x53 +#define HidUsage_LED_BlueLEDChannel 0x54 +#define HidUsage_LED_GreenLEDChannel 0x55 +#define HidUsage_LED_LEDIntensity 0x56 +#define HidUsage_LED_SystemMicrophoneMute 0x57 +#define HidUsage_LED_PlayerIndicator 0x60 +#define HidUsage_LED_Player1 0x61 +#define HidUsage_LED_Player2 0x62 +#define HidUsage_LED_Player3 0x63 +#define HidUsage_LED_Player4 0x64 +#define HidUsage_LED_Player5 0x65 +#define HidUsage_LED_Player6 0x66 +#define HidUsage_LED_Player7 0x67 +#define HidUsage_LED_Player8 0x68 +#define HidUsage_TD_Phone 0x01 +#define HidUsage_TD_AnsweringMachine 0x02 +#define HidUsage_TD_MessageControls 0x03 +#define HidUsage_TD_Handset 0x04 +#define HidUsage_TD_Headset 0x05 +#define HidUsage_TD_TelephonyKeyPad 0x06 +#define HidUsage_TD_ProgrammableButton 0x07 +#define HidUsage_TD_HookSwitch 0x20 +#define HidUsage_TD_Flash 0x21 +#define HidUsage_TD_Feature 0x22 +#define HidUsage_TD_Hold 0x23 +#define HidUsage_TD_Redial 0x24 +#define HidUsage_TD_Transfer 0x25 +#define HidUsage_TD_Drop 0x26 +#define HidUsage_TD_Park 0x27 +#define HidUsage_TD_ForwardCalls 0x28 +#define HidUsage_TD_AlternateFunction 0x29 +#define HidUsage_TD_Line 0x2a +#define HidUsage_TD_SpeakerPhone 0x2b +#define HidUsage_TD_Conference 0x2c +#define HidUsage_TD_RingEnable 0x2d +#define HidUsage_TD_RingSelect 0x2e +#define HidUsage_TD_PhoneMute 0x2f +#define HidUsage_TD_CallerID 0x30 +#define HidUsage_TD_Send 0x31 +#define HidUsage_TD_SpeedDial 0x50 +#define HidUsage_TD_StoreNumber 0x51 +#define HidUsage_TD_RecallNumber 0x52 +#define HidUsage_TD_PhoneDirectory 0x53 +#define HidUsage_TD_VoiceMail 0x70 +#define HidUsage_TD_ScreenCalls 0x71 +#define HidUsage_TD_DoNotDisturb 0x72 +#define HidUsage_TD_Message 0x73 +#define HidUsage_TD_AnswerOnOff 0x74 +#define HidUsage_TD_InsideDialTone 0x90 +#define HidUsage_TD_OutsideDialTone 0x91 +#define HidUsage_TD_InsideRingTone 0x92 +#define HidUsage_TD_OutsideRingTone 0x93 +#define HidUsage_TD_PriorityRingTone 0x94 +#define HidUsage_TD_InsideRingback 0x95 +#define HidUsage_TD_PriorityRingback 0x96 +#define HidUsage_TD_LineBusyTone 0x97 +#define HidUsage_TD_ReorderTone 0x98 +#define HidUsage_TD_CallWaitingTone 0x99 +#define HidUsage_TD_ConfirmationTone1 0x9a +#define HidUsage_TD_ConfirmationTone2 0x9b +#define HidUsage_TD_TonesOff 0x9c +#define HidUsage_TD_OutsideRingback 0x9d +#define HidUsage_TD_Ringer 0x9e +#define HidUsage_TD_PhoneKey0 0xb0 +#define HidUsage_TD_PhoneKey1 0xb1 +#define HidUsage_TD_PhoneKey2 0xb2 +#define HidUsage_TD_PhoneKey3 0xb3 +#define HidUsage_TD_PhoneKey4 0xb4 +#define HidUsage_TD_PhoneKey5 0xb5 +#define HidUsage_TD_PhoneKey6 0xb6 +#define HidUsage_TD_PhoneKey7 0xb7 +#define HidUsage_TD_PhoneKey8 0xb8 +#define HidUsage_TD_PhoneKey9 0xb9 +#define HidUsage_TD_PhoneKeyStar 0xba +#define HidUsage_TD_PhoneKeyPound 0xbb +#define HidUsage_TD_PhoneKeyA 0xbc +#define HidUsage_TD_PhoneKeyB 0xbd +#define HidUsage_TD_PhoneKeyC 0xbe +#define HidUsage_TD_PhoneKeyD 0xbf +#define HidUsage_TD_PhoneCallHistoryKey 0xc0 +#define HidUsage_TD_PhoneCallerIDKey 0xc1 +#define HidUsage_TD_PhoneSettingsKey 0xc2 +#define HidUsage_TD_HostControl 0xf0 +#define HidUsage_TD_HostAvailable 0xf1 +#define HidUsage_TD_HostCallActive 0xf2 +#define HidUsage_TD_ActivateHandsetAudio 0xf3 +#define HidUsage_TD_RingType 0xf4 +#define HidUsage_TD_RedialablePhoneNumber 0xf5 +#define HidUsage_TD_StopRingTone 0xf8 +#define HidUsage_TD_PSTNRingTone 0xf9 +#define HidUsage_TD_HostRingTone 0xfa +#define HidUsage_TD_AlertSoundError 0xfb +#define HidUsage_TD_AlertSoundConfirm 0xfc +#define HidUsage_TD_AlertSoundNotification 0xfd +#define HidUsage_TD_SilentRing 0xfe +#define HidUsage_TD_EmailMessageWaiting 0x108 +#define HidUsage_TD_VoicemailMessageWaiting 0x109 +#define HidUsage_TD_HostHold 0x10a +#define HidUsage_TD_IncomingCallHistoryCount 0x110 +#define HidUsage_TD_OutgoingCallHistoryCount 0x111 +#define HidUsage_TD_IncomingCallHistory 0x112 +#define HidUsage_TD_OutgoingCallHistory 0x113 +#define HidUsage_TD_PhoneLocale 0x114 +#define HidUsage_TD_PhoneTimeSecond 0x140 +#define HidUsage_TD_PhoneTimeMinute 0x141 +#define HidUsage_TD_PhoneTimeHour 0x142 +#define HidUsage_TD_PhoneDateDay 0x143 +#define HidUsage_TD_PhoneDateMonth 0x144 +#define HidUsage_TD_PhoneDateYear 0x145 +#define HidUsage_TD_HandsetNickname 0x146 +#define HidUsage_TD_AddressBookID 0x147 +#define HidUsage_TD_CallDuration 0x14a +#define HidUsage_TD_DualModePhone 0x14b +#define HidUsage_Con_ConsumerControl 0x01 +#define HidUsage_Con_NumericKeyPad 0x02 +#define HidUsage_Con_ProgrammableButtons 0x03 +#define HidUsage_Con_Microphone 0x04 +#define HidUsage_Con_Headphone 0x05 +#define HidUsage_Con_GraphicEqualizer 0x06 +#define HidUsage_Con_Plus10 0x20 +#define HidUsage_Con_Plus100 0x21 +#define HidUsage_Con_AMPM 0x22 +#define HidUsage_Con_Power 0x30 +#define HidUsage_Con_Reset 0x31 +#define HidUsage_Con_Sleep 0x32 +#define HidUsage_Con_SleepAfter 0x33 +#define HidUsage_Con_SleepMode 0x34 +#define HidUsage_Con_Illumination 0x35 +#define HidUsage_Con_FunctionButtons 0x36 +#define HidUsage_Con_Menu 0x40 +#define HidUsage_Con_MenuPick 0x41 +#define HidUsage_Con_MenuUp 0x42 +#define HidUsage_Con_MenuDown 0x43 +#define HidUsage_Con_MenuLeft 0x44 +#define HidUsage_Con_MenuRight 0x45 +#define HidUsage_Con_MenuEscape 0x46 +#define HidUsage_Con_MenuValueIncrease 0x47 +#define HidUsage_Con_MenuValueDecrease 0x48 +#define HidUsage_Con_DataOnScreen 0x60 +#define HidUsage_Con_ClosedCaption 0x61 +#define HidUsage_Con_ClosedCaptionSelect 0x62 +#define HidUsage_Con_VCRTV 0x63 +#define HidUsage_Con_BroadcastMode 0x64 +#define HidUsage_Con_Snapshot 0x65 +#define HidUsage_Con_Still 0x66 +#define HidUsage_Con_PictureinPictureToggle 0x67 +#define HidUsage_Con_PictureinPictureSwap 0x68 +#define HidUsage_Con_RedMenuButton 0x69 +#define HidUsage_Con_GreenMenuButton 0x6a +#define HidUsage_Con_BlueMenuButton 0x6b +#define HidUsage_Con_YellowMenuButton 0x6c +#define HidUsage_Con_Aspect 0x6d +#define HidUsage_Con_ThreeDModeSelect 0x6e +#define HidUsage_Con_DisplayBrightnessIncrement 0x6f +#define HidUsage_Con_DisplayBrightnessDecrement 0x70 +#define HidUsage_Con_DisplayBrightness 0x71 +#define HidUsage_Con_DisplayBacklightToggle 0x72 +#define HidUsage_Con_DisplaySetBrightnesstoMinimum 0x73 +#define HidUsage_Con_DisplaySetBrightnesstoMaximum 0x74 +#define HidUsage_Con_DisplaySetAutoBrightness 0x75 +#define HidUsage_Con_CameraAccessEnabled 0x76 +#define HidUsage_Con_CameraAccessDisabled 0x77 +#define HidUsage_Con_CameraAccessToggle 0x78 +#define HidUsage_Con_KeyboardBrightnessIncrement 0x79 +#define HidUsage_Con_KeyboardBrightnessDecrement 0x7a +#define HidUsage_Con_KeyboardBacklightSetLevel 0x7b +#define HidUsage_Con_KeyboardBacklightOOC 0x7c +#define HidUsage_Con_KeyboardBacklightSetMinimum 0x7d +#define HidUsage_Con_KeyboardBacklightSetMaximum 0x7e +#define HidUsage_Con_KeyboardBacklightAuto 0x7f +#define HidUsage_Con_Selection 0x80 +#define HidUsage_Con_AssignSelection 0x81 +#define HidUsage_Con_ModeStep 0x82 +#define HidUsage_Con_RecallLast 0x83 +#define HidUsage_Con_EnterChannel 0x84 +#define HidUsage_Con_OrderMovie 0x85 +#define HidUsage_Con_Channel 0x86 +#define HidUsage_Con_MediaSelection 0x87 +#define HidUsage_Con_MediaSelectComputer 0x88 +#define HidUsage_Con_MediaSelectTV 0x89 +#define HidUsage_Con_MediaSelectWWW 0x8a +#define HidUsage_Con_MediaSelectDVD 0x8b +#define HidUsage_Con_MediaSelectTelephone 0x8c +#define HidUsage_Con_MediaSelectProgramGuide 0x8d +#define HidUsage_Con_MediaSelectVideoPhone 0x8e +#define HidUsage_Con_MediaSelectGames 0x8f +#define HidUsage_Con_MediaSelectMessages 0x90 +#define HidUsage_Con_MediaSelectCD 0x91 +#define HidUsage_Con_MediaSelectVCR 0x92 +#define HidUsage_Con_MediaSelectTuner 0x93 +#define HidUsage_Con_Quit 0x94 +#define HidUsage_Con_Help 0x95 +#define HidUsage_Con_MediaSelectTape 0x96 +#define HidUsage_Con_MediaSelectCable 0x97 +#define HidUsage_Con_MediaSelectSatellite 0x98 +#define HidUsage_Con_MediaSelectSecurity 0x99 +#define HidUsage_Con_MediaSelectHome 0x9a +#define HidUsage_Con_MediaSelectCall 0x9b +#define HidUsage_Con_ChannelIncrement 0x9c +#define HidUsage_Con_ChannelDecrement 0x9d +#define HidUsage_Con_MediaSelectSAP 0x9e +#define HidUsage_Con_VCRPlus 0xa0 +#define HidUsage_Con_Once 0xa1 +#define HidUsage_Con_Daily 0xa2 +#define HidUsage_Con_Weekly 0xa3 +#define HidUsage_Con_Monthly 0xa4 +#define HidUsage_Con_Play 0xb0 +#define HidUsage_Con_Pause 0xb1 +#define HidUsage_Con_Record 0xb2 +#define HidUsage_Con_FastForward 0xb3 +#define HidUsage_Con_Rewind 0xb4 +#define HidUsage_Con_ScanNextTrack 0xb5 +#define HidUsage_Con_ScanPreviousTrack 0xb6 +#define HidUsage_Con_Stop 0xb7 +#define HidUsage_Con_Eject 0xb8 +#define HidUsage_Con_RandomPlay 0xb9 +#define HidUsage_Con_SelectDisc 0xba +#define HidUsage_Con_EnterDisc 0xbb +#define HidUsage_Con_Repeat 0xbc +#define HidUsage_Con_Tracking 0xbd +#define HidUsage_Con_TrackNormal 0xbe +#define HidUsage_Con_SlowTracking 0xbf +#define HidUsage_Con_FrameForward 0xc0 +#define HidUsage_Con_FrameBack 0xc1 +#define HidUsage_Con_Mark 0xc2 +#define HidUsage_Con_ClearMark 0xc3 +#define HidUsage_Con_RepeatFromMark 0xc4 +#define HidUsage_Con_ReturnToMark 0xc5 +#define HidUsage_Con_SearchMarkForward 0xc6 +#define HidUsage_Con_SearchMarkBackwards 0xc7 +#define HidUsage_Con_CounterReset 0xc8 +#define HidUsage_Con_ShowCounter 0xc9 +#define HidUsage_Con_TrackingIncrement 0xca +#define HidUsage_Con_TrackingDecrement 0xcb +#define HidUsage_Con_StopEject 0xcc +#define HidUsage_Con_PlayPause 0xcd +#define HidUsage_Con_PlaySkip 0xce +#define HidUsage_Con_VoiceCommand 0xcf +#define HidUsage_Con_InvokeCaptureInterface 0xd0 +#define HidUsage_Con_StartorStopGameRecording 0xd1 +#define HidUsage_Con_HistoricalGameCapture 0xd2 +#define HidUsage_Con_CaptureGameScreenshot 0xd3 +#define HidUsage_Con_ShoworHideRecordingIndicator 0xd4 +#define HidUsage_Con_StartorStopMicrophoneCapture 0xd5 +#define HidUsage_Con_StartorStopCameraCapture 0xd6 +#define HidUsage_Con_StartorStopGameBroadcast 0xd7 +#define HidUsage_Con_StartorStopVoiceDictationSession 0xd8 +#define HidUsage_Con_InvokeDismissEmojiPicker 0xd9 +#define HidUsage_Con_Volume 0xe0 +#define HidUsage_Con_Balance 0xe1 +#define HidUsage_Con_Mute 0xe2 +#define HidUsage_Con_Bass 0xe3 +#define HidUsage_Con_Treble 0xe4 +#define HidUsage_Con_BassBoost 0xe5 +#define HidUsage_Con_SurroundMode 0xe6 +#define HidUsage_Con_Loudness 0xe7 +#define HidUsage_Con_MPX 0xe8 +#define HidUsage_Con_VolumeIncrement 0xe9 +#define HidUsage_Con_VolumeDecrement 0xea +#define HidUsage_Con_SpeedSelect 0xf0 +#define HidUsage_Con_PlaybackSpeed 0xf1 +#define HidUsage_Con_StandardPlay 0xf2 +#define HidUsage_Con_LongPlay 0xf3 +#define HidUsage_Con_ExtendedPlay 0xf4 +#define HidUsage_Con_Slow 0xf5 +#define HidUsage_Con_FanEnable 0x100 +#define HidUsage_Con_FanSpeed 0x101 +#define HidUsage_Con_LightEnable 0x102 +#define HidUsage_Con_LightIlluminationLevel 0x103 +#define HidUsage_Con_ClimateControlEnable 0x104 +#define HidUsage_Con_RoomTemperature 0x105 +#define HidUsage_Con_SecurityEnable 0x106 +#define HidUsage_Con_FireAlarm 0x107 +#define HidUsage_Con_PoliceAlarm 0x108 +#define HidUsage_Con_Proximity 0x109 +#define HidUsage_Con_Motion 0x10a +#define HidUsage_Con_DuressAlarm 0x10b +#define HidUsage_Con_HoldupAlarm 0x10c +#define HidUsage_Con_MedicalAlarm 0x10d +#define HidUsage_Con_BalanceRight 0x150 +#define HidUsage_Con_BalanceLeft 0x151 +#define HidUsage_Con_BassIncrement 0x152 +#define HidUsage_Con_BassDecrement 0x153 +#define HidUsage_Con_TrebleIncrement 0x154 +#define HidUsage_Con_TrebleDecrement 0x155 +#define HidUsage_Con_SpeakerSystem 0x160 +#define HidUsage_Con_ChannelLeft 0x161 +#define HidUsage_Con_ChannelRight 0x162 +#define HidUsage_Con_ChannelCenter 0x163 +#define HidUsage_Con_ChannelFront 0x164 +#define HidUsage_Con_ChannelCenterFront 0x165 +#define HidUsage_Con_ChannelSide 0x166 +#define HidUsage_Con_ChannelSurround 0x167 +#define HidUsage_Con_ChannelLowFrequencyEnhancement 0x168 +#define HidUsage_Con_ChannelTop 0x169 +#define HidUsage_Con_ChannelUnknown 0x16a +#define HidUsage_Con_Subchannel 0x170 +#define HidUsage_Con_SubchannelIncrement 0x171 +#define HidUsage_Con_SubchannelDecrement 0x172 +#define HidUsage_Con_AlternateAudioIncrement 0x173 +#define HidUsage_Con_AlternateAudioDecrement 0x174 +#define HidUsage_Con_ApplicationLaunchButtons 0x180 +#define HidUsage_Con_ALLaunchButtonConfigurationTool 0x181 +#define HidUsage_Con_ALProgrammableButtonConfiguration 0x182 +#define HidUsage_Con_ALConsumerControlConfiguration 0x183 +#define HidUsage_Con_ALWordProcessor 0x184 +#define HidUsage_Con_ALTextEditor 0x185 +#define HidUsage_Con_ALSpreadsheet 0x186 +#define HidUsage_Con_ALGraphicsEditor 0x187 +#define HidUsage_Con_ALPresentationApp 0x188 +#define HidUsage_Con_ALDatabaseApp 0x189 +#define HidUsage_Con_ALEmailReader 0x18a +#define HidUsage_Con_ALNewsreader 0x18b +#define HidUsage_Con_ALVoicemail 0x18c +#define HidUsage_Con_ALContactsAddressBook 0x18d +#define HidUsage_Con_ALCalendarSchedule 0x18e +#define HidUsage_Con_ALTaskProjectManager 0x18f +#define HidUsage_Con_ALLogJournalTimecard 0x190 +#define HidUsage_Con_ALCheckbookFinance 0x191 +#define HidUsage_Con_ALCalculator 0x192 +#define HidUsage_Con_ALAVCapturePlayback 0x193 +#define HidUsage_Con_ALLocalMachineBrowser 0x194 +#define HidUsage_Con_ALLANWANBrowser 0x195 +#define HidUsage_Con_ALInternetBrowser 0x196 +#define HidUsage_Con_ALRemoteNetworkingISPConnect 0x197 +#define HidUsage_Con_ALNetworkConference 0x198 +#define HidUsage_Con_ALNetworkChat 0x199 +#define HidUsage_Con_ALTelephonyDialer 0x19a +#define HidUsage_Con_ALLogon 0x19b +#define HidUsage_Con_ALLogoff 0x19c +#define HidUsage_Con_ALLogonLogoff 0x19d +#define HidUsage_Con_ALTerminalLockScreensaver 0x19e +#define HidUsage_Con_ALControlPanel 0x19f +#define HidUsage_Con_ALCommandLineProcessorRun 0x1a0 +#define HidUsage_Con_ALProcessTaskManager 0x1a1 +#define HidUsage_Con_ALSelectTaskApplication 0x1a2 +#define HidUsage_Con_ALNextTaskApplication 0x1a3 +#define HidUsage_Con_ALPreviousTaskApplication 0x1a4 +#define HidUsage_Con_ALPreemptiveHaltTaskApplication 0x1a5 +#define HidUsage_Con_ALIntegratedHelpCenter 0x1a6 +#define HidUsage_Con_ALDocuments 0x1a7 +#define HidUsage_Con_ALThesaurus 0x1a8 +#define HidUsage_Con_ALDictionary 0x1a9 +#define HidUsage_Con_ALDesktop 0x1aa +#define HidUsage_Con_ALSpellCheck 0x1ab +#define HidUsage_Con_ALGrammarCheck 0x1ac +#define HidUsage_Con_ALWirelessStatus 0x1ad +#define HidUsage_Con_ALKeyboardLayout 0x1ae +#define HidUsage_Con_ALVirusProtection 0x1af +#define HidUsage_Con_ALEncryption 0x1b0 +#define HidUsage_Con_ALScreenSaver 0x1b1 +#define HidUsage_Con_ALAlarms 0x1b2 +#define HidUsage_Con_ALClock 0x1b3 +#define HidUsage_Con_ALFileBrowser 0x1b4 +#define HidUsage_Con_ALPowerStatus 0x1b5 +#define HidUsage_Con_ALImageBrowser 0x1b6 +#define HidUsage_Con_ALAudioBrowser 0x1b7 +#define HidUsage_Con_ALMovieBrowser 0x1b8 +#define HidUsage_Con_ALDigitalRightsManager 0x1b9 +#define HidUsage_Con_ALDigitalWallet 0x1ba +#define HidUsage_Con_ALInstantMessaging 0x1bc +#define HidUsage_Con_ALOEMFeaturesTipsTutorialBrowser 0x1bd +#define HidUsage_Con_ALOEMHelp 0x1be +#define HidUsage_Con_ALOnlineCommunity 0x1bf +#define HidUsage_Con_ALEntertainmentContentBrowser 0x1c0 +#define HidUsage_Con_ALOnlineShoppingBrowser 0x1c1 +#define HidUsage_Con_ALSmartCardInformationHelp 0x1c2 +#define HidUsage_Con_ALMarketMonitorFinanceBrowser 0x1c3 +#define HidUsage_Con_ALCustomizedCorporateNewsBrowser 0x1c4 +#define HidUsage_Con_ALOnlineActivityBrowser 0x1c5 +#define HidUsage_Con_ALResearchSearchBrowser 0x1c6 +#define HidUsage_Con_ALAudioPlayer 0x1c7 +#define HidUsage_Con_ALMessageStatus 0x1c8 +#define HidUsage_Con_ALContactSync 0x1c9 +#define HidUsage_Con_ALNavigation 0x1ca +#define HidUsage_Con_ALContextawareDesktopAssistant 0x1cb +#define HidUsage_Con_GenericGUIApplicationControls 0x200 +#define HidUsage_Con_ACNew 0x201 +#define HidUsage_Con_ACOpen 0x202 +#define HidUsage_Con_ACClose 0x203 +#define HidUsage_Con_ACExit 0x204 +#define HidUsage_Con_ACMaximize 0x205 +#define HidUsage_Con_ACMinimize 0x206 +#define HidUsage_Con_ACSave 0x207 +#define HidUsage_Con_ACPrint 0x208 +#define HidUsage_Con_ACProperties 0x209 +#define HidUsage_Con_ACUndo 0x21a +#define HidUsage_Con_ACCopy 0x21b +#define HidUsage_Con_ACCut 0x21c +#define HidUsage_Con_ACPaste 0x21d +#define HidUsage_Con_ACSelectAll 0x21e +#define HidUsage_Con_ACFind 0x21f +#define HidUsage_Con_ACFindandReplace 0x220 +#define HidUsage_Con_ACSearch 0x221 +#define HidUsage_Con_ACGoTo 0x222 +#define HidUsage_Con_ACHome 0x223 +#define HidUsage_Con_ACBack 0x224 +#define HidUsage_Con_ACForward 0x225 +#define HidUsage_Con_ACStop 0x226 +#define HidUsage_Con_ACRefresh 0x227 +#define HidUsage_Con_ACPreviousLink 0x228 +#define HidUsage_Con_ACNextLink 0x229 +#define HidUsage_Con_ACBookmarks 0x22a +#define HidUsage_Con_ACHistory 0x22b +#define HidUsage_Con_ACSubscriptions 0x22c +#define HidUsage_Con_ACZoomIn 0x22d +#define HidUsage_Con_ACZoomOut 0x22e +#define HidUsage_Con_ACZoom 0x22f +#define HidUsage_Con_ACFullScreenView 0x230 +#define HidUsage_Con_ACNormalView 0x231 +#define HidUsage_Con_ACViewToggle 0x232 +#define HidUsage_Con_ACScrollUp 0x233 +#define HidUsage_Con_ACScrollDown 0x234 +#define HidUsage_Con_ACScroll 0x235 +#define HidUsage_Con_ACPanLeft 0x236 +#define HidUsage_Con_ACPanRight 0x237 +#define HidUsage_Con_ACPan 0x238 +#define HidUsage_Con_ACNewWindow 0x239 +#define HidUsage_Con_ACTileHorizontally 0x23a +#define HidUsage_Con_ACTileVertically 0x23b +#define HidUsage_Con_ACFormat 0x23c +#define HidUsage_Con_ACEdit 0x23d +#define HidUsage_Con_ACBold 0x23e +#define HidUsage_Con_ACItalics 0x23f +#define HidUsage_Con_ACUnderline 0x240 +#define HidUsage_Con_ACStrikethrough 0x241 +#define HidUsage_Con_ACSubscript 0x242 +#define HidUsage_Con_ACSuperscript 0x243 +#define HidUsage_Con_ACAllCaps 0x244 +#define HidUsage_Con_ACRotate 0x245 +#define HidUsage_Con_ACResize 0x246 +#define HidUsage_Con_ACFlipHorizontal 0x247 +#define HidUsage_Con_ACFlipVertical 0x248 +#define HidUsage_Con_ACMirrorHorizontal 0x249 +#define HidUsage_Con_ACMirrorVertical 0x24a +#define HidUsage_Con_ACFontSelect 0x24b +#define HidUsage_Con_ACFontColor 0x24c +#define HidUsage_Con_ACFontSize 0x24d +#define HidUsage_Con_ACJustifyLeft 0x24e +#define HidUsage_Con_ACJustifyCenterH 0x24f +#define HidUsage_Con_ACJustifyRight 0x250 +#define HidUsage_Con_ACJustifyBlockH 0x251 +#define HidUsage_Con_ACJustifyTop 0x252 +#define HidUsage_Con_ACJustifyCenterV 0x253 +#define HidUsage_Con_ACJustifyBottom 0x254 +#define HidUsage_Con_ACJustifyBlockV 0x255 +#define HidUsage_Con_ACIndentDecrease 0x256 +#define HidUsage_Con_ACIndentIncrease 0x257 +#define HidUsage_Con_ACNumberedList 0x258 +#define HidUsage_Con_ACRestartNumbering 0x259 +#define HidUsage_Con_ACBulletedList 0x25a +#define HidUsage_Con_ACPromote 0x25b +#define HidUsage_Con_ACDemote 0x25c +#define HidUsage_Con_ACYes 0x25d +#define HidUsage_Con_ACNo 0x25e +#define HidUsage_Con_ACCancel 0x25f +#define HidUsage_Con_ACCatalog 0x260 +#define HidUsage_Con_ACBuyCheckout 0x261 +#define HidUsage_Con_ACAddtoCart 0x262 +#define HidUsage_Con_ACExpand 0x263 +#define HidUsage_Con_ACExpandAll 0x264 +#define HidUsage_Con_ACCollapse 0x265 +#define HidUsage_Con_ACCollapseAll 0x266 +#define HidUsage_Con_ACPrintPreview 0x267 +#define HidUsage_Con_ACPasteSpecial 0x268 +#define HidUsage_Con_ACInsertMode 0x269 +#define HidUsage_Con_ACDelete 0x26a +#define HidUsage_Con_ACLock 0x26b +#define HidUsage_Con_ACUnlock 0x26c +#define HidUsage_Con_ACProtect 0x26d +#define HidUsage_Con_ACUnprotect 0x26e +#define HidUsage_Con_ACAttachComment 0x26f +#define HidUsage_Con_ACDeleteComment 0x270 +#define HidUsage_Con_ACViewComment 0x271 +#define HidUsage_Con_ACSelectWord 0x272 +#define HidUsage_Con_ACSelectSentence 0x273 +#define HidUsage_Con_ACSelectParagraph 0x274 +#define HidUsage_Con_ACSelectColumn 0x275 +#define HidUsage_Con_ACSelectRow 0x276 +#define HidUsage_Con_ACSelectTable 0x277 +#define HidUsage_Con_ACSelectObject 0x278 +#define HidUsage_Con_ACRedoRepeat 0x279 +#define HidUsage_Con_ACSort 0x27a +#define HidUsage_Con_ACSortAscending 0x27b +#define HidUsage_Con_ACSortDescending 0x27c +#define HidUsage_Con_ACFilter 0x27d +#define HidUsage_Con_ACSetClock 0x27e +#define HidUsage_Con_ACViewClock 0x27f +#define HidUsage_Con_ACSelectTimeZone 0x280 +#define HidUsage_Con_ACEditTimeZones 0x281 +#define HidUsage_Con_ACSetAlarm 0x282 +#define HidUsage_Con_ACClearAlarm 0x283 +#define HidUsage_Con_ACSnoozeAlarm 0x284 +#define HidUsage_Con_ACResetAlarm 0x285 +#define HidUsage_Con_ACSynchronize 0x286 +#define HidUsage_Con_ACSendReceive 0x287 +#define HidUsage_Con_ACSendTo 0x288 +#define HidUsage_Con_ACReply 0x289 +#define HidUsage_Con_ACReplyAll 0x28a +#define HidUsage_Con_ACForwardMsg 0x28b +#define HidUsage_Con_ACSend 0x28c +#define HidUsage_Con_ACAttachFile 0x28d +#define HidUsage_Con_ACUpload 0x28e +#define HidUsage_Con_ACDownloadSaveTargetAs 0x28f +#define HidUsage_Con_ACSetBorders 0x290 +#define HidUsage_Con_ACInsertRow 0x291 +#define HidUsage_Con_ACInsertColumn 0x292 +#define HidUsage_Con_ACInsertFile 0x293 +#define HidUsage_Con_ACInsertPicture 0x294 +#define HidUsage_Con_ACInsertObject 0x295 +#define HidUsage_Con_ACInsertSymbol 0x296 +#define HidUsage_Con_ACSaveandClose 0x297 +#define HidUsage_Con_ACRename 0x298 +#define HidUsage_Con_ACMerge 0x299 +#define HidUsage_Con_ACSplit 0x29a +#define HidUsage_Con_ACDisributeHorizontally 0x29b +#define HidUsage_Con_ACDistributeVertically 0x29c +#define HidUsage_Con_ACNextKeyboardLayoutSelect 0x29d +#define HidUsage_Con_ACNavigationGuidance 0x29e +#define HidUsage_Con_ACDesktopShowAllWindows 0x29f +#define HidUsage_Con_ACSoftKeyLeft 0x2a0 +#define HidUsage_Con_ACSoftKeyRight 0x2a1 +#define HidUsage_Con_ACDesktopShowAllApplications 0x2a2 +#define HidUsage_Con_ACIdleKeepAlive 0x2b0 +#define HidUsage_Con_ExtendedKeyboardAttributesCollection 0x2c0 +#define HidUsage_Con_KeyboardFormFactor 0x2c1 +#define HidUsage_Con_KeyboardKeyType 0x2c2 +#define HidUsage_Con_KeyboardPhysicalLayout 0x2c3 +#define HidUsage_Con_VendorSpecificKeyboardPhysicalLayout 0x2c4 +#define HidUsage_Con_KeyboardIETFLanguageTagIndex 0x2c5 +#define HidUsage_Con_ImplementedKeyboardInputAssistControls 0x2c6 +#define HidUsage_Con_KeyboardInputAssistPrevious 0x2c7 +#define HidUsage_Con_KeyboardInputAssistNext 0x2c8 +#define HidUsage_Con_KeyboardInputAssistPreviousGroup 0x2c9 +#define HidUsage_Con_KeyboardInputAssistNextGroup 0x2ca +#define HidUsage_Con_KeyboardInputAssistAccept 0x2cb +#define HidUsage_Con_KeyboardInputAssistCancel 0x2cc +#define HidUsage_Con_PrivacyScreenToggle 0x2d0 +#define HidUsage_Con_PrivacyScreenLevelDecrement 0x2d1 +#define HidUsage_Con_PrivacyScreenLevelIncrement 0x2d2 +#define HidUsage_Con_PrivacyScreenLevelMinimum 0x2d3 +#define HidUsage_Con_PrivacyScreenLevelMaximum 0x2d4 +#define HidUsage_Con_ContactEdited 0x500 +#define HidUsage_Con_ContactAdded 0x501 +#define HidUsage_Con_ContactRecordActive 0x502 +#define HidUsage_Con_ContactIndex 0x503 +#define HidUsage_Con_ContactNickname 0x504 +#define HidUsage_Con_ContactFirstName 0x505 +#define HidUsage_Con_ContactLastName 0x506 +#define HidUsage_Con_ContactFullName 0x507 +#define HidUsage_Con_ContactPhoneNumberPersonal 0x508 +#define HidUsage_Con_ContactPhoneNumberBusiness 0x509 +#define HidUsage_Con_ContactPhoneNumberMobile 0x50a +#define HidUsage_Con_ContactPhoneNumberPager 0x50b +#define HidUsage_Con_ContactPhoneNumberFax 0x50c +#define HidUsage_Con_ContactPhoneNumberOther 0x50d +#define HidUsage_Con_ContactEmailPersonal 0x50e +#define HidUsage_Con_ContactEmailBusiness 0x50f +#define HidUsage_Con_ContactEmailOther 0x510 +#define HidUsage_Con_ContactEmailMain 0x511 +#define HidUsage_Con_ContactSpeedDialNumber 0x512 +#define HidUsage_Con_ContactStatusFlag 0x513 +#define HidUsage_Con_ContactMisc 0x514 +#define HidUsage_Dig_Digitizer 0x01 +#define HidUsage_Dig_Pen 0x02 +#define HidUsage_Dig_LightPen 0x03 +#define HidUsage_Dig_TouchScreen 0x04 +#define HidUsage_Dig_TouchPad 0x05 +#define HidUsage_Dig_Whiteboard 0x06 +#define HidUsage_Dig_CoordinateMeasuringMachine 0x07 +#define HidUsage_Dig_ThreeDDigitizer 0x08 +#define HidUsage_Dig_StereoPlotter 0x09 +#define HidUsage_Dig_ArticulatedArm 0x0a +#define HidUsage_Dig_Armature 0x0b +#define HidUsage_Dig_MultiplePointDigitizer 0x0c +#define HidUsage_Dig_FreeSpaceWand 0x0d +#define HidUsage_Dig_DeviceConfiguration 0x0e +#define HidUsage_Dig_CapacitiveHeatMapDigitizer 0x0f +#define HidUsage_Dig_Stylus 0x20 +#define HidUsage_Dig_Puck 0x21 +#define HidUsage_Dig_Finger 0x22 +#define HidUsage_Dig_Devicesettings 0x23 +#define HidUsage_Dig_CharacterGesture 0x24 +#define HidUsage_Dig_TipPressure 0x30 +#define HidUsage_Dig_BarrelPressure 0x31 +#define HidUsage_Dig_InRange 0x32 +#define HidUsage_Dig_Touch 0x33 +#define HidUsage_Dig_Untouch 0x34 +#define HidUsage_Dig_Tap 0x35 +#define HidUsage_Dig_Quality 0x36 +#define HidUsage_Dig_DataValid 0x37 +#define HidUsage_Dig_TransducerIndex 0x38 +#define HidUsage_Dig_TabletFunctionKeys 0x39 +#define HidUsage_Dig_ProgramChangeKeys 0x3a +#define HidUsage_Dig_BatteryStrength 0x3b +#define HidUsage_Dig_Invert 0x3c +#define HidUsage_Dig_XTilt 0x3d +#define HidUsage_Dig_YTilt 0x3e +#define HidUsage_Dig_Azimuth 0x3f +#define HidUsage_Dig_Altitude 0x40 +#define HidUsage_Dig_Twist 0x41 +#define HidUsage_Dig_TipSwitch 0x42 +#define HidUsage_Dig_SecondaryTipSwitch 0x43 +#define HidUsage_Dig_BarrelSwitch 0x44 +#define HidUsage_Dig_Eraser 0x45 +#define HidUsage_Dig_TabletPick 0x46 +#define HidUsage_Dig_TouchValid 0x47 +#define HidUsage_Dig_Width 0x48 +#define HidUsage_Dig_Height 0x49 +#define HidUsage_Dig_ContactIdentifier 0x51 +#define HidUsage_Dig_DeviceMode 0x52 +#define HidUsage_Dig_DeviceIdentifier 0x53 +#define HidUsage_Dig_ContactCount 0x54 +#define HidUsage_Dig_ContactCountMaximum 0x55 +#define HidUsage_Dig_ScanTime 0x56 +#define HidUsage_Dig_SurfaceSwitch 0x57 +#define HidUsage_Dig_ButtonSwitch 0x58 +#define HidUsage_Dig_PadType 0x59 +#define HidUsage_Dig_SecondaryBarrelSwitch 0x5a +#define HidUsage_Dig_TransducerSerialNumber 0x5b +#define HidUsage_Dig_PreferredColor 0x5c +#define HidUsage_Dig_PreferredColorisLocked 0x5d +#define HidUsage_Dig_PreferredLineWidth 0x5e +#define HidUsage_Dig_PreferredLineWidthisLocked 0x5f +#define HidUsage_Dig_LatencyMode 0x60 +#define HidUsage_Dig_GestureCharacterQuality 0x61 +#define HidUsage_Dig_CharacterGestureDataLength 0x62 +#define HidUsage_Dig_CharacterGestureData 0x63 +#define HidUsage_Dig_GestureCharacterEncoding 0x64 +#define HidUsage_Dig_UTF8CharacterGestureEncoding 0x65 +#define HidUsage_Dig_UTF16LittleEndianCharacterGestureEncoding 0x66 +#define HidUsage_Dig_UTF16BigEndianCharacterGestureEncoding 0x67 +#define HidUsage_Dig_UTF32LittleEndianCharacterGestureEncoding 0x68 +#define HidUsage_Dig_UTF32BigEndianCharacterGestureEncoding 0x69 +#define HidUsage_Dig_CapacitiveHeatMapProtocolVendorID 0x6a +#define HidUsage_Dig_CapacitiveHeatMapProtocolVersion 0x6b +#define HidUsage_Dig_CapacitiveHeatMapFrameData 0x6c +#define HidUsage_Dig_GestureCharacterEnable 0x6d +#define HidUsage_Dig_TransducerSerialNumberPart2 0x6e +#define HidUsage_Dig_NoPreferredColor 0x6f +#define HidUsage_Dig_PreferredLineStyle 0x70 +#define HidUsage_Dig_PreferredLineStyleisLocked 0x71 +#define HidUsage_Dig_Ink 0x72 +#define HidUsage_Dig_Pencil 0x73 +#define HidUsage_Dig_Highlighter 0x74 +#define HidUsage_Dig_ChiselMarker 0x75 +#define HidUsage_Dig_Brush 0x76 +#define HidUsage_Dig_NoPreference 0x77 +#define HidUsage_Dig_DigitizerDiagnostic 0x80 +#define HidUsage_Dig_DigitizerError 0x81 +#define HidUsage_Dig_ErrNormalStatus 0x82 +#define HidUsage_Dig_ErrTransducersExceeded 0x83 +#define HidUsage_Dig_ErrFullTransFeaturesUnavailable 0x84 +#define HidUsage_Dig_ErrChargeLow 0x85 +#define HidUsage_Dig_TransducerSoftwareInfo 0x90 +#define HidUsage_Dig_TransducerVendorId 0x91 +#define HidUsage_Dig_TransducerProductId 0x92 +#define HidUsage_Dig_DeviceSupportedProtocols 0x93 +#define HidUsage_Dig_TransducerSupportedProtocols 0x94 +#define HidUsage_Dig_NoProtocol 0x95 +#define HidUsage_Dig_WacomAESProtocol 0x96 +#define HidUsage_Dig_USIProtocol 0x97 +#define HidUsage_Dig_MicrosoftPenProtocol 0x98 +#define HidUsage_Dig_SupportedReportRates 0xa0 +#define HidUsage_Dig_ReportRate 0xa1 +#define HidUsage_Dig_TransducerConnected 0xa2 +#define HidUsage_Dig_SwitchDisabled 0xa3 +#define HidUsage_Dig_SwitchUnimplemented 0xa4 +#define HidUsage_Dig_TransducerSwitches 0xa5 +#define HidUsage_Dig_TransducerIndexSelector 0xa6 +#define HidUsage_Dig_ButtonPressThreshold 0xb0 +#define HidUsage_Hap_SimpleHapticController 0x01 +#define HidUsage_Hap_WaveformList 0x10 +#define HidUsage_Hap_DurationList 0x11 +#define HidUsage_Hap_AutoTrigger 0x20 +#define HidUsage_Hap_ManualTrigger 0x21 +#define HidUsage_Hap_AutoTriggerAssociatedControl 0x22 +#define HidUsage_Hap_Intensity 0x23 +#define HidUsage_Hap_RepeatCount 0x24 +#define HidUsage_Hap_RetriggerPeriod 0x25 +#define HidUsage_Hap_WaveformVendorPage 0x26 +#define HidUsage_Hap_WaveformVendorID 0x27 +#define HidUsage_Hap_WaveformCutoffTime 0x28 +#define HidUsage_Hap_WaveformNone 0x1001 +#define HidUsage_Hap_WaveformStop 0x1002 +#define HidUsage_Hap_WaveformClick 0x1003 +#define HidUsage_Hap_WaveformBuzzContinuous 0x1004 +#define HidUsage_Hap_WaveformRumbleContinuous 0x1005 +#define HidUsage_Hap_WaveformPress 0x1006 +#define HidUsage_Hap_WaveformRelease 0x1007 +#define HidUsage_Hap_WaveformHover 0x1008 +#define HidUsage_Hap_WaveformSuccess 0x1009 +#define HidUsage_Hap_WaveformError 0x100a +#define HidUsage_Hap_WaveformInkContinuous 0x100b +#define HidUsage_Hap_WaveformPencilContinuous 0x100c +#define HidUsage_Hap_WaveformMarkerContinuous 0x100d +#define HidUsage_Hap_WaveformChiselMarkerContinuous 0x100e +#define HidUsage_Hap_WaveformBrushContinuous 0x100f +#define HidUsage_Hap_WaveformEraserContinuous 0x1010 +#define HidUsage_Hap_WaveformSparkleContinuous 0x1011 +#define HidUsage_PID_PhysicalInputDevice 0x01 +#define HidUsage_PID_Normal 0x20 +#define HidUsage_PID_SetEffectReport 0x21 +#define HidUsage_PID_EffectParameterBlockIndex 0x22 +#define HidUsage_PID_ParameterBlockOffset 0x23 +#define HidUsage_PID_ROMFlag 0x24 +#define HidUsage_PID_EffectType 0x25 +#define HidUsage_PID_ETConstantForce 0x26 +#define HidUsage_PID_ETRamp 0x27 +#define HidUsage_PID_ETCustomForce 0x28 +#define HidUsage_PID_ETSquare 0x30 +#define HidUsage_PID_ETSine 0x31 +#define HidUsage_PID_ETTriangle 0x32 +#define HidUsage_PID_ETSawtoothUp 0x33 +#define HidUsage_PID_ETSawtoothDown 0x34 +#define HidUsage_PID_ETSpring 0x40 +#define HidUsage_PID_ETDamper 0x41 +#define HidUsage_PID_ETInertia 0x42 +#define HidUsage_PID_ETFriction 0x43 +#define HidUsage_PID_Duration 0x50 +#define HidUsage_PID_SamplePeriod 0x51 +#define HidUsage_PID_Gain 0x52 +#define HidUsage_PID_TriggerButton 0x53 +#define HidUsage_PID_TriggerRepeatInterval 0x54 +#define HidUsage_PID_AxesEnable 0x55 +#define HidUsage_PID_DirectionEnable 0x56 +#define HidUsage_PID_Direction 0x57 +#define HidUsage_PID_TypeSpecificBlockOffset 0x58 +#define HidUsage_PID_BlockType 0x59 +#define HidUsage_PID_SetEnvelopeReport 0x5a +#define HidUsage_PID_AttackLevel 0x5b +#define HidUsage_PID_AttackTime 0x5c +#define HidUsage_PID_FadeLevel 0x5d +#define HidUsage_PID_FadeTime 0x5e +#define HidUsage_PID_SetConditionReport 0x5f +#define HidUsage_PID_CenterPointOffset 0x60 +#define HidUsage_PID_PositiveCoefficient 0x61 +#define HidUsage_PID_NegativeCoefficient 0x62 +#define HidUsage_PID_PositiveSaturation 0x63 +#define HidUsage_PID_NegativeSaturation 0x64 +#define HidUsage_PID_DeadBand 0x65 +#define HidUsage_PID_DownloadForceSample 0x66 +#define HidUsage_PID_IsochCustomForceEnable 0x67 +#define HidUsage_PID_CustomForceDataReport 0x68 +#define HidUsage_PID_CustomForceData 0x69 +#define HidUsage_PID_CustomForceVendorDefinedData 0x6a +#define HidUsage_PID_SetCustomForceReport 0x6b +#define HidUsage_PID_CustomForceDataOffset 0x6c +#define HidUsage_PID_SampleCount 0x6d +#define HidUsage_PID_SetPeriodicReport 0x6e +#define HidUsage_PID_Offset 0x6f +#define HidUsage_PID_Magnitude 0x70 +#define HidUsage_PID_Phase 0x71 +#define HidUsage_PID_Period 0x72 +#define HidUsage_PID_SetConstantForceReport 0x73 +#define HidUsage_PID_SetRampForceReport 0x74 +#define HidUsage_PID_RampStart 0x75 +#define HidUsage_PID_RampEnd 0x76 +#define HidUsage_PID_EffectOperationReport 0x77 +#define HidUsage_PID_EffectOperation 0x78 +#define HidUsage_PID_OpEffectStart 0x79 +#define HidUsage_PID_OpEffectStartSolo 0x7a +#define HidUsage_PID_OpEffectStop 0x7b +#define HidUsage_PID_LoopCount 0x7c +#define HidUsage_PID_DeviceGainReport 0x7d +#define HidUsage_PID_DeviceGain 0x7e +#define HidUsage_PID_ParameterBlockPoolsReport 0x7f +#define HidUsage_PID_RAMPoolSize 0x80 +#define HidUsage_PID_ROMPoolSize 0x81 +#define HidUsage_PID_ROMEffectBlockCount 0x82 +#define HidUsage_PID_SimultaneousEffectsMax 0x83 +#define HidUsage_PID_PoolAlignment 0x84 +#define HidUsage_PID_ParameterBlockMoveReport 0x85 +#define HidUsage_PID_MoveSource 0x86 +#define HidUsage_PID_MoveDestination 0x87 +#define HidUsage_PID_MoveLength 0x88 +#define HidUsage_PID_EffectParameterBlockLoadReport 0x89 +#define HidUsage_PID_EffectParameterBlockLoadStatus 0x8b +#define HidUsage_PID_BlockLoadSuccess 0x8c +#define HidUsage_PID_BlockLoadFull 0x8d +#define HidUsage_PID_BlockLoadError 0x8e +#define HidUsage_PID_BlockHandle 0x8f +#define HidUsage_PID_EffectParameterBlockFreeReport 0x90 +#define HidUsage_PID_TypeSpecificBlockHandle 0x91 +#define HidUsage_PID_PIDStateReport 0x92 +#define HidUsage_PID_EffectPlaying 0x94 +#define HidUsage_PID_PIDDeviceControlReport 0x95 +#define HidUsage_PID_PIDDeviceControl 0x96 +#define HidUsage_PID_DCEnableActuators 0x97 +#define HidUsage_PID_DCDisableActuators 0x98 +#define HidUsage_PID_DCStopAllEffects 0x99 +#define HidUsage_PID_DCReset 0x9a +#define HidUsage_PID_DCPause 0x9b +#define HidUsage_PID_DCContinue 0x9c +#define HidUsage_PID_DevicePaused 0x9f +#define HidUsage_PID_ActuatorsEnabled 0xa0 +#define HidUsage_PID_SafetySwitch 0xa4 +#define HidUsage_PID_ActuatorOverrideSwitch 0xa5 +#define HidUsage_PID_ActuatorPower 0xa6 +#define HidUsage_PID_StartDelay 0xa7 +#define HidUsage_PID_ParameterBlockSize 0xa8 +#define HidUsage_PID_DeviceManagedPool 0xa9 +#define HidUsage_PID_SharedParameterBlocks 0xaa +#define HidUsage_PID_CreateNewEffectParameterBlockReport 0xab +#define HidUsage_PID_RAMPoolAvailable 0xac +#define HidUsage_SC_SocControl 0x01 +#define HidUsage_SC_FirmwareTransfer 0x02 +#define HidUsage_SC_FirmwareFileId 0x03 +#define HidUsage_SC_FileOffsetInBytes 0x04 +#define HidUsage_SC_FileTransferSizeMaxInBytes 0x05 +#define HidUsage_SC_FilePayload 0x06 +#define HidUsage_SC_FilePayloadSizeInBytes 0x07 +#define HidUsage_SC_FilePayloadContainsLastBytes 0x08 +#define HidUsage_SC_FileTransferStop 0x09 +#define HidUsage_SC_FileTransferTillEnd 0x0a +#define HidUsage_EHT_EyeTracker 0x01 +#define HidUsage_EHT_HeadTracker 0x02 +#define HidUsage_EHT_TrackingData 0x10 +#define HidUsage_EHT_Capabilities 0x11 +#define HidUsage_EHT_Configuration 0x12 +#define HidUsage_EHT_Status 0x13 +#define HidUsage_EHT_Control 0x14 +#define HidUsage_EHT_SensorTimestamp 0x20 +#define HidUsage_EHT_PositionX 0x21 +#define HidUsage_EHT_PositionY 0x22 +#define HidUsage_EHT_PositionZ 0x23 +#define HidUsage_EHT_GazePoint 0x24 +#define HidUsage_EHT_LeftEyePosition 0x25 +#define HidUsage_EHT_RightEyePosition 0x26 +#define HidUsage_EHT_HeadPosition 0x27 +#define HidUsage_EHT_HeadDirectionPoint 0x28 +#define HidUsage_EHT_RotationaboutXaxis 0x29 +#define HidUsage_EHT_RotationaboutYaxis 0x2a +#define HidUsage_EHT_RotationaboutZaxis 0x2b +#define HidUsage_EHT_TrackerQuality 0x100 +#define HidUsage_EHT_MinimumTrackingDistance 0x101 +#define HidUsage_EHT_OptimumTrackingDistance 0x102 +#define HidUsage_EHT_MaximumTrackingDistance 0x103 +#define HidUsage_EHT_MaximumScreenPlaneWidth 0x104 +#define HidUsage_EHT_MaximumScreenPlaneHeight 0x105 +#define HidUsage_EHT_DisplayManufacturerID 0x200 +#define HidUsage_EHT_DisplayProductID 0x201 +#define HidUsage_EHT_DisplaySerialNumber 0x202 +#define HidUsage_EHT_DisplayManufacturerDate 0x203 +#define HidUsage_EHT_CalibratedScreenWidth 0x204 +#define HidUsage_EHT_CalibratedScreenHeight 0x205 +#define HidUsage_EHT_SamplingFrequency 0x300 +#define HidUsage_EHT_ConfigurationStatus 0x301 +#define HidUsage_EHT_DeviceModeRequest 0x400 +#define HidUsage_AD_AlphanumericDisplay 0x01 +#define HidUsage_AD_AuxiliaryDisplay 0x02 +#define HidUsage_AD_DisplayAttributesReport 0x20 +#define HidUsage_AD_ASCIICharacterSet 0x21 +#define HidUsage_AD_DataReadBack 0x22 +#define HidUsage_AD_FontReadBack 0x23 +#define HidUsage_AD_DisplayControlReport 0x24 +#define HidUsage_AD_ClearDisplay 0x25 +#define HidUsage_AD_DisplayEnable 0x26 +#define HidUsage_AD_ScreenSaverDelay 0x27 +#define HidUsage_AD_ScreenSaverEnable 0x28 +#define HidUsage_AD_VerticalScroll 0x29 +#define HidUsage_AD_HorizontalScroll 0x2a +#define HidUsage_AD_CharacterReport 0x2b +#define HidUsage_AD_DisplayData 0x2c +#define HidUsage_AD_DisplayStatus 0x2d +#define HidUsage_AD_StatNotReady 0x2e +#define HidUsage_AD_StatReady 0x2f +#define HidUsage_AD_ErrNotaloadablecharacter 0x30 +#define HidUsage_AD_ErrFontdatacannotberead 0x31 +#define HidUsage_AD_CursorPositionReport 0x32 +#define HidUsage_AD_Row 0x33 +#define HidUsage_AD_Column 0x34 +#define HidUsage_AD_Rows 0x35 +#define HidUsage_AD_Columns 0x36 +#define HidUsage_AD_CursorPixelPositioning 0x37 +#define HidUsage_AD_CursorMode 0x38 +#define HidUsage_AD_CursorEnable 0x39 +#define HidUsage_AD_CursorBlink 0x3a +#define HidUsage_AD_FontReport 0x3b +#define HidUsage_AD_FontData 0x3c +#define HidUsage_AD_CharacterWidth 0x3d +#define HidUsage_AD_CharacterHeight 0x3e +#define HidUsage_AD_CharacterSpacingHorizontal 0x3f +#define HidUsage_AD_CharacterSpacingVertical 0x40 +#define HidUsage_AD_UnicodeCharacterSet 0x41 +#define HidUsage_AD_Font7Segment 0x42 +#define HidUsage_AD_SevenSegmentDirectMap 0x43 +#define HidUsage_AD_Font14Segment 0x44 +#define HidUsage_AD_One4SegmentDirectMap 0x45 +#define HidUsage_AD_DisplayBrightness 0x46 +#define HidUsage_AD_DisplayContrast 0x47 +#define HidUsage_AD_CharacterAttribute 0x48 +#define HidUsage_AD_AttributeReadback 0x49 +#define HidUsage_AD_AttributeData 0x4a +#define HidUsage_AD_CharAttrEnhance 0x4b +#define HidUsage_AD_CharAttrUnderline 0x4c +#define HidUsage_AD_CharAttrBlink 0x4d +#define HidUsage_AD_BitmapSizeX 0x80 +#define HidUsage_AD_BitmapSizeY 0x81 +#define HidUsage_AD_MaxBlitSize 0x82 +#define HidUsage_AD_BitDepthFormat 0x83 +#define HidUsage_AD_DisplayOrientation 0x84 +#define HidUsage_AD_PaletteReport 0x85 +#define HidUsage_AD_PaletteDataSize 0x86 +#define HidUsage_AD_PaletteDataOffset 0x87 +#define HidUsage_AD_PaletteData 0x88 +#define HidUsage_AD_BlitReport 0x8a +#define HidUsage_AD_BlitRectangleX1 0x8b +#define HidUsage_AD_BlitRectangleY1 0x8c +#define HidUsage_AD_BlitRectangleX2 0x8d +#define HidUsage_AD_BlitRectangleY2 0x8e +#define HidUsage_AD_BlitData 0x8f +#define HidUsage_AD_SoftButton 0x90 +#define HidUsage_AD_SoftButtonID 0x91 +#define HidUsage_AD_SoftButtonSide 0x92 +#define HidUsage_AD_SoftButtonOffset1 0x93 +#define HidUsage_AD_SoftButtonOffset2 0x94 +#define HidUsage_AD_SoftButtonReport 0x95 +#define HidUsage_AD_SoftKeys 0xc2 +#define HidUsage_AD_DisplayDataExtensions 0xcc +#define HidUsage_AD_CharacterMapping 0xcf +#define HidUsage_AD_UnicodeEquivalent 0xdd +#define HidUsage_AD_CharacterPageMapping 0xdf +#define HidUsage_AD_RequestReport 0xff +#define HidUsage_Sen_Sensor 0x01 +#define HidUsage_Sen_Biometric 0x10 +#define HidUsage_Sen_BiometricHumanPresence 0x11 +#define HidUsage_Sen_BiometricHumanProximity 0x12 +#define HidUsage_Sen_BiometricHumanTouch 0x13 +#define HidUsage_Sen_BiometricBloodPressure 0x14 +#define HidUsage_Sen_BiometricBodyTemperature 0x15 +#define HidUsage_Sen_BiometricHeartRate 0x16 +#define HidUsage_Sen_BiometricHeartRateVariability 0x17 +#define HidUsage_Sen_BiometricPeripheralOxygenSaturation 0x18 +#define HidUsage_Sen_BiometricRespiratoryRate 0x19 +#define HidUsage_Sen_Electrical 0x20 +#define HidUsage_Sen_ElectricalCapacitance 0x21 +#define HidUsage_Sen_ElectricalCurrent 0x22 +#define HidUsage_Sen_ElectricalPower 0x23 +#define HidUsage_Sen_ElectricalInductance 0x24 +#define HidUsage_Sen_ElectricalResistance 0x25 +#define HidUsage_Sen_ElectricalVoltage 0x26 +#define HidUsage_Sen_ElectricalPotentiometer 0x27 +#define HidUsage_Sen_ElectricalFrequency 0x28 +#define HidUsage_Sen_ElectricalPeriod 0x29 +#define HidUsage_Sen_Environmental 0x30 +#define HidUsage_Sen_EnvironmentalAtmosphericPressure 0x31 +#define HidUsage_Sen_EnvironmentalHumidity 0x32 +#define HidUsage_Sen_EnvironmentalTemperature 0x33 +#define HidUsage_Sen_EnvironmentalWindDirection 0x34 +#define HidUsage_Sen_EnvironmentalWindSpeed 0x35 +#define HidUsage_Sen_EnvironmentalAirQuality 0x36 +#define HidUsage_Sen_EnvironmentalHeatIndex 0x37 +#define HidUsage_Sen_EnvironmentalSurfaceTemperature 0x38 +#define HidUsage_Sen_EnvironmentalVolatileOrganicCompounds 0x39 +#define HidUsage_Sen_EnvironmentalObjectPresence 0x3a +#define HidUsage_Sen_EnvironmentalObjectProximity 0x3b +#define HidUsage_Sen_Light 0x40 +#define HidUsage_Sen_LightAmbientLight 0x41 +#define HidUsage_Sen_LightConsumerInfrared 0x42 +#define HidUsage_Sen_LightInfraredLight 0x43 +#define HidUsage_Sen_LightVisibleLight 0x44 +#define HidUsage_Sen_LightUltravioletLight 0x45 +#define HidUsage_Sen_Location 0x50 +#define HidUsage_Sen_LocationBroadcast 0x51 +#define HidUsage_Sen_LocationDeadReckoning 0x52 +#define HidUsage_Sen_LocationGPSGlobalPositioningSystem 0x53 +#define HidUsage_Sen_LocationLookup 0x54 +#define HidUsage_Sen_LocationOther 0x55 +#define HidUsage_Sen_LocationStatic 0x56 +#define HidUsage_Sen_LocationTriangulation 0x57 +#define HidUsage_Sen_Mechanical 0x60 +#define HidUsage_Sen_MechanicalBooleanSwitch 0x61 +#define HidUsage_Sen_MechanicalBooleanSwitchArray 0x62 +#define HidUsage_Sen_MechanicalMultivalueSwitch 0x63 +#define HidUsage_Sen_MechanicalForce 0x64 +#define HidUsage_Sen_MechanicalPressure 0x65 +#define HidUsage_Sen_MechanicalStrain 0x66 +#define HidUsage_Sen_MechanicalWeight 0x67 +#define HidUsage_Sen_MechanicalHapticVibrator 0x68 +#define HidUsage_Sen_MechanicalHallEffectSwitch 0x69 +#define HidUsage_Sen_Motion 0x70 +#define HidUsage_Sen_MotionAccelerometer1D 0x71 +#define HidUsage_Sen_MotionAccelerometer2D 0x72 +#define HidUsage_Sen_MotionAccelerometer3D 0x73 +#define HidUsage_Sen_MotionGyrometer1D 0x74 +#define HidUsage_Sen_MotionGyrometer2D 0x75 +#define HidUsage_Sen_MotionGyrometer3D 0x76 +#define HidUsage_Sen_MotionMotionDetector 0x77 +#define HidUsage_Sen_MotionSpeedometer 0x78 +#define HidUsage_Sen_MotionAccelerometer 0x79 +#define HidUsage_Sen_MotionGyrometer 0x7a +#define HidUsage_Sen_MotionGravityVector 0x7b +#define HidUsage_Sen_MotionLinearAccelerometer 0x7c +#define HidUsage_Sen_Orientation 0x80 +#define HidUsage_Sen_OrientationCompass1D 0x81 +#define HidUsage_Sen_OrientationCompass2D 0x82 +#define HidUsage_Sen_OrientationCompass3D 0x83 +#define HidUsage_Sen_OrientationInclinometer1D 0x84 +#define HidUsage_Sen_OrientationInclinometer2D 0x85 +#define HidUsage_Sen_OrientationInclinometer3D 0x86 +#define HidUsage_Sen_OrientationDistance1D 0x87 +#define HidUsage_Sen_OrientationDistance2D 0x88 +#define HidUsage_Sen_OrientationDistance3D 0x89 +#define HidUsage_Sen_OrientationDeviceOrientation 0x8a +#define HidUsage_Sen_OrientationCompass 0x8b +#define HidUsage_Sen_OrientationInclinometer 0x8c +#define HidUsage_Sen_OrientationDistance 0x8d +#define HidUsage_Sen_OrientationRelativeOrientation 0x8e +#define HidUsage_Sen_OrientationSimpleOrientation 0x8f +#define HidUsage_Sen_Scanner 0x90 +#define HidUsage_Sen_ScannerBarcode 0x91 +#define HidUsage_Sen_ScannerRFID 0x92 +#define HidUsage_Sen_ScannerNFC 0x93 +#define HidUsage_Sen_Time 0xa0 +#define HidUsage_Sen_TimeAlarmTimer 0xa1 +#define HidUsage_Sen_TimeRealTimeClock 0xa2 +#define HidUsage_Sen_PersonalActivity 0xb0 +#define HidUsage_Sen_PersonalActivityActivityDetection 0xb1 +#define HidUsage_Sen_PersonalActivityDevicePosition 0xb2 +#define HidUsage_Sen_PersonalActivityFloorTracker 0xb3 +#define HidUsage_Sen_PersonalActivityPedometer 0xb4 +#define HidUsage_Sen_PersonalActivityStepDetection 0xb5 +#define HidUsage_Sen_OrientationExtended 0xc0 +#define HidUsage_Sen_OrientationExtendedGeomagneticOrientation 0xc1 +#define HidUsage_Sen_OrientationExtendedMagnetometer 0xc2 +#define HidUsage_Sen_Gesture 0xd0 +#define HidUsage_Sen_GestureChassisFlipGesture 0xd1 +#define HidUsage_Sen_GestureHingeFoldGesture 0xd2 +#define HidUsage_Sen_Other 0xe0 +#define HidUsage_Sen_OtherCustom 0xe1 +#define HidUsage_Sen_OtherGeneric 0xe2 +#define HidUsage_Sen_OtherGenericEnumerator 0xe3 +#define HidUsage_Sen_OtherHingeAngle 0xe4 +#define HidUsage_Sen_VendorReserved1 0xf0 +#define HidUsage_Sen_VendorReserved2 0xf1 +#define HidUsage_Sen_VendorReserved3 0xf2 +#define HidUsage_Sen_VendorReserved4 0xf3 +#define HidUsage_Sen_VendorReserved5 0xf4 +#define HidUsage_Sen_VendorReserved6 0xf5 +#define HidUsage_Sen_VendorReserved7 0xf6 +#define HidUsage_Sen_VendorReserved8 0xf7 +#define HidUsage_Sen_VendorReserved9 0xf8 +#define HidUsage_Sen_VendorReserved10 0xf9 +#define HidUsage_Sen_VendorReserved11 0xfa +#define HidUsage_Sen_VendorReserved12 0xfb +#define HidUsage_Sen_VendorReserved13 0xfc +#define HidUsage_Sen_VendorReserved14 0xfd +#define HidUsage_Sen_VendorReserved15 0xfe +#define HidUsage_Sen_VendorReserved16 0xff +#define HidUsage_Sen_Event 0x200 +#define HidUsage_Sen_EventSensorState 0x201 +#define HidUsage_Sen_EventSensorEvent 0x202 +#define HidUsage_Sen_Property 0x300 +#define HidUsage_Sen_PropertyFriendlyName 0x301 +#define HidUsage_Sen_PropertyPersistentUniqueID 0x302 +#define HidUsage_Sen_PropertySensorStatus 0x303 +#define HidUsage_Sen_PropertyMinimumReportInterval 0x304 +#define HidUsage_Sen_PropertySensorManufacturer 0x305 +#define HidUsage_Sen_PropertySensorModel 0x306 +#define HidUsage_Sen_PropertySensorSerialNumber 0x307 +#define HidUsage_Sen_PropertySensorDescription 0x308 +#define HidUsage_Sen_PropertySensorConnectionType 0x309 +#define HidUsage_Sen_PropertySensorDevicePath 0x30a +#define HidUsage_Sen_PropertyHardwareRevision 0x30b +#define HidUsage_Sen_PropertyFirmwareVersion 0x30c +#define HidUsage_Sen_PropertyReleaseDate 0x30d +#define HidUsage_Sen_PropertyReportInterval 0x30e +#define HidUsage_Sen_PropertyChangeSensitivityAbsolute 0x30f +#define HidUsage_Sen_PropertyChangeSensitivityPercentofRange 0x310 +#define HidUsage_Sen_PropertyChangeSensitivityPercentRelative 0x311 +#define HidUsage_Sen_PropertyAccuracy 0x312 +#define HidUsage_Sen_PropertyResolution 0x313 +#define HidUsage_Sen_PropertyMaximum 0x314 +#define HidUsage_Sen_PropertyMinimum 0x315 +#define HidUsage_Sen_PropertyReportingState 0x316 +#define HidUsage_Sen_PropertySamplingRate 0x317 +#define HidUsage_Sen_PropertyResponseCurve 0x318 +#define HidUsage_Sen_PropertyPowerState 0x319 +#define HidUsage_Sen_PropertyMaximumFIFOEvents 0x31a +#define HidUsage_Sen_PropertyReportLatency 0x31b +#define HidUsage_Sen_PropertyFlushFIFOEvents 0x31c +#define HidUsage_Sen_PropertyMaximumPowerConsumption 0x31d +#define HidUsage_Sen_PropertyIsPrimary 0x31e +#define HidUsage_Sen_PropertyHumanPresenceDetectionType 0x31f +#define HidUsage_Sen_DataFieldLocation 0x400 +#define HidUsage_Sen_DataFieldAltitudeAntennaSeaLevel 0x402 +#define HidUsage_Sen_DataFieldDifferentialReferenceStationID 0x403 +#define HidUsage_Sen_DataFieldAltitudeEllipsoidError 0x404 +#define HidUsage_Sen_DataFieldAltitudeEllipsoid 0x405 +#define HidUsage_Sen_DataFieldAltitudeSeaLevelError 0x406 +#define HidUsage_Sen_DataFieldAltitudeSeaLevel 0x407 +#define HidUsage_Sen_DataFieldDifferentialGPSDataAge 0x408 +#define HidUsage_Sen_DataFieldErrorRadius 0x409 +#define HidUsage_Sen_DataFieldFixQuality 0x40a +#define HidUsage_Sen_DataFieldFixType 0x40b +#define HidUsage_Sen_DataFieldGeoidalSeparation 0x40c +#define HidUsage_Sen_DataFieldGPSOperationMode 0x40d +#define HidUsage_Sen_DataFieldGPSSelectionMode 0x40e +#define HidUsage_Sen_DataFieldGPSStatus 0x40f +#define HidUsage_Sen_DataFieldPositionDilutionofPrecision 0x410 +#define HidUsage_Sen_DataFieldHorizontalDilutionofPrecision 0x411 +#define HidUsage_Sen_DataFieldVerticalDilutionofPrecision 0x412 +#define HidUsage_Sen_DataFieldLatitude 0x413 +#define HidUsage_Sen_DataFieldLongitude 0x414 +#define HidUsage_Sen_DataFieldTrueHeading 0x415 +#define HidUsage_Sen_DataFieldMagneticHeading 0x416 +#define HidUsage_Sen_DataFieldMagneticVariation 0x417 +#define HidUsage_Sen_DataFieldSpeed 0x418 +#define HidUsage_Sen_DataFieldSatellitesinView 0x419 +#define HidUsage_Sen_DataFieldSatellitesinViewAzimuth 0x41a +#define HidUsage_Sen_DataFieldSatellitesinViewElevation 0x41b +#define HidUsage_Sen_DataFieldSatellitesinViewIDs 0x41c +#define HidUsage_Sen_DataFieldSatellitesinViewPRNs 0x41d +#define HidUsage_Sen_DataFieldSatellitesinViewSNRatios 0x41e +#define HidUsage_Sen_DataFieldSatellitesUsedCount 0x41f +#define HidUsage_Sen_DataFieldSatellitesUsedPRNs 0x420 +#define HidUsage_Sen_DataFieldNMEASentence 0x421 +#define HidUsage_Sen_DataFieldAddressLine1 0x422 +#define HidUsage_Sen_DataFieldAddressLine2 0x423 +#define HidUsage_Sen_DataFieldCity 0x424 +#define HidUsage_Sen_DataFieldStateorProvince 0x425 +#define HidUsage_Sen_DataFieldCountryorRegion 0x426 +#define HidUsage_Sen_DataFieldPostalCode 0x427 +#define HidUsage_Sen_PropertyLocation 0x42a +#define HidUsage_Sen_PropertyLocationDesiredAccuracy 0x42b +#define HidUsage_Sen_DataFieldEnvironmental 0x430 +#define HidUsage_Sen_DataFieldAtmosphericPressure 0x431 +#define HidUsage_Sen_DataFieldRelativeHumidity 0x433 +#define HidUsage_Sen_DataFieldTemperature 0x434 +#define HidUsage_Sen_DataFieldWindDirection 0x435 +#define HidUsage_Sen_DataFieldWindSpeed 0x436 +#define HidUsage_Sen_DataFieldAirQualityIndex 0x437 +#define HidUsage_Sen_DataFieldEquivalentCO2 0x438 +#define HidUsage_Sen_DataFieldVolatileOrganicCompoundConcentration 0x439 +#define HidUsage_Sen_DataFieldObjectPresence 0x43a +#define HidUsage_Sen_DataFieldObjectProximityRange 0x43b +#define HidUsage_Sen_DataFieldObjectProximityOutofRange 0x43c +#define HidUsage_Sen_PropertyEnvironmental 0x440 +#define HidUsage_Sen_PropertyReferencePressure 0x441 +#define HidUsage_Sen_DataFieldMotion 0x450 +#define HidUsage_Sen_DataFieldMotionState 0x451 +#define HidUsage_Sen_DataFieldAcceleration 0x452 +#define HidUsage_Sen_DataFieldAccelerationAxisX 0x453 +#define HidUsage_Sen_DataFieldAccelerationAxisY 0x454 +#define HidUsage_Sen_DataFieldAccelerationAxisZ 0x455 +#define HidUsage_Sen_DataFieldAngularVelocity 0x456 +#define HidUsage_Sen_DataFieldAngularVelocityaboutXAxis 0x457 +#define HidUsage_Sen_DataFieldAngularVelocityaboutYAxis 0x458 +#define HidUsage_Sen_DataFieldAngularVelocityaboutZAxis 0x459 +#define HidUsage_Sen_DataFieldAngularPosition 0x45a +#define HidUsage_Sen_DataFieldAngularPositionaboutXAxis 0x45b +#define HidUsage_Sen_DataFieldAngularPositionaboutYAxis 0x45c +#define HidUsage_Sen_DataFieldAngularPositionaboutZAxis 0x45d +#define HidUsage_Sen_DataFieldMotionSpeed 0x45e +#define HidUsage_Sen_DataFieldMotionIntensity 0x45f +#define HidUsage_Sen_DataFieldOrientation 0x470 +#define HidUsage_Sen_DataFieldHeading 0x471 +#define HidUsage_Sen_DataFieldHeadingXAxis 0x472 +#define HidUsage_Sen_DataFieldHeadingYAxis 0x473 +#define HidUsage_Sen_DataFieldHeadingZAxis 0x474 +#define HidUsage_Sen_DataFieldHeadingCompensatedMagneticNorth 0x475 +#define HidUsage_Sen_DataFieldHeadingCompensatedTrueNorth 0x476 +#define HidUsage_Sen_DataFieldHeadingMagneticNorth 0x477 +#define HidUsage_Sen_DataFieldHeadingTrueNorth 0x478 +#define HidUsage_Sen_DataFieldDistance 0x479 +#define HidUsage_Sen_DataFieldDistanceXAxis 0x47a +#define HidUsage_Sen_DataFieldDistanceYAxis 0x47b +#define HidUsage_Sen_DataFieldDistanceZAxis 0x47c +#define HidUsage_Sen_DataFieldDistanceOutofRange 0x47d +#define HidUsage_Sen_DataFieldTilt 0x47e +#define HidUsage_Sen_DataFieldTiltXAxis 0x47f +#define HidUsage_Sen_DataFieldTiltYAxis 0x480 +#define HidUsage_Sen_DataFieldTiltZAxis 0x481 +#define HidUsage_Sen_DataFieldRotationMatrix 0x482 +#define HidUsage_Sen_DataFieldQuaternion 0x483 +#define HidUsage_Sen_DataFieldMagneticFlux 0x484 +#define HidUsage_Sen_DataFieldMagneticFluxXAxis 0x485 +#define HidUsage_Sen_DataFieldMagneticFluxYAxis 0x486 +#define HidUsage_Sen_DataFieldMagneticFluxZAxis 0x487 +#define HidUsage_Sen_DataFieldMagnetometerAccuracy 0x488 +#define HidUsage_Sen_DataFieldSimpleOrientationDirection 0x489 +#define HidUsage_Sen_DataFieldMechanical 0x490 +#define HidUsage_Sen_DataFieldBooleanSwitchState 0x491 +#define HidUsage_Sen_DataFieldBooleanSwitchArrayStates 0x492 +#define HidUsage_Sen_DataFieldMultivalueSwitchValue 0x493 +#define HidUsage_Sen_DataFieldForce 0x494 +#define HidUsage_Sen_DataFieldAbsolutePressure 0x495 +#define HidUsage_Sen_DataFieldGaugePressure 0x496 +#define HidUsage_Sen_DataFieldStrain 0x497 +#define HidUsage_Sen_DataFieldWeight 0x498 +#define HidUsage_Sen_PropertyMechanical 0x4a0 +#define HidUsage_Sen_PropertyVibrationState 0x4a1 +#define HidUsage_Sen_PropertyForwardVibrationSpeed 0x4a2 +#define HidUsage_Sen_PropertyBackwardVibrationSpeed 0x4a3 +#define HidUsage_Sen_DataFieldBiometric 0x4b0 +#define HidUsage_Sen_DataFieldHumanPresence 0x4b1 +#define HidUsage_Sen_DataFieldHumanProximityRange 0x4b2 +#define HidUsage_Sen_DataFieldHumanProximityOutofRange 0x4b3 +#define HidUsage_Sen_DataFieldHumanTouchState 0x4b4 +#define HidUsage_Sen_DataFieldBloodPressure 0x4b5 +#define HidUsage_Sen_DataFieldBloodPressureDiastolic 0x4b6 +#define HidUsage_Sen_DataFieldBloodPressureSystolic 0x4b7 +#define HidUsage_Sen_DataFieldHeartRate 0x4b8 +#define HidUsage_Sen_DataFieldRestingHeartRate 0x4b9 +#define HidUsage_Sen_DataFieldHeartbeatInterval 0x4ba +#define HidUsage_Sen_DataFieldRespiratoryRate 0x4bb +#define HidUsage_Sen_DataFieldSpO2 0x4bc +#define HidUsage_Sen_DataFieldHumanAttentionDetected 0x4bd +#define HidUsage_Sen_DataFieldHumanHeadAzimuth 0x4be +#define HidUsage_Sen_DataFieldHumanHeadAltitude 0x4bf +#define HidUsage_Sen_DataFieldHumanHeadRoll 0x4c0 +#define HidUsage_Sen_DataFieldHumanHeadPitch 0x4c1 +#define HidUsage_Sen_DataFieldHumanHeadYaw 0x4c2 +#define HidUsage_Sen_DataFieldHumanCorrelationId 0x4c3 +#define HidUsage_Sen_DataFieldLight 0x4d0 +#define HidUsage_Sen_DataFieldIlluminance 0x4d1 +#define HidUsage_Sen_DataFieldColorTemperature 0x4d2 +#define HidUsage_Sen_DataFieldChromaticity 0x4d3 +#define HidUsage_Sen_DataFieldChromaticityX 0x4d4 +#define HidUsage_Sen_DataFieldChromaticityY 0x4d5 +#define HidUsage_Sen_DataFieldConsumerIRSentenceReceive 0x4d6 +#define HidUsage_Sen_DataFieldInfraredLight 0x4d7 +#define HidUsage_Sen_DataFieldRedLight 0x4d8 +#define HidUsage_Sen_DataFieldGreenLight 0x4d9 +#define HidUsage_Sen_DataFieldBlueLight 0x4da +#define HidUsage_Sen_DataFieldUltravioletALight 0x4db +#define HidUsage_Sen_DataFieldUltravioletBLight 0x4dc +#define HidUsage_Sen_DataFieldUltravioletIndex 0x4dd +#define HidUsage_Sen_DataFieldNearInfraredLight 0x4de +#define HidUsage_Sen_PropertyLight 0x4df +#define HidUsage_Sen_PropertyConsumerIRSentenceSend 0x4e0 +#define HidUsage_Sen_PropertyAutoBrightnessPreferred 0x4e2 +#define HidUsage_Sen_PropertyAutoColorPreferred 0x4e3 +#define HidUsage_Sen_DataFieldScanner 0x4f0 +#define HidUsage_Sen_DataFieldRFIDTag40Bit 0x4f1 +#define HidUsage_Sen_DataFieldNFCSentenceReceive 0x4f2 +#define HidUsage_Sen_PropertyScanner 0x4f8 +#define HidUsage_Sen_PropertyNFCSentenceSend 0x4f9 +#define HidUsage_Sen_DataFieldElectrical 0x500 +#define HidUsage_Sen_DataFieldCapacitance 0x501 +#define HidUsage_Sen_DataFieldCurrent 0x502 +#define HidUsage_Sen_DataFieldElectricalPower 0x503 +#define HidUsage_Sen_DataFieldInductance 0x504 +#define HidUsage_Sen_DataFieldResistance 0x505 +#define HidUsage_Sen_DataFieldVoltage 0x506 +#define HidUsage_Sen_DataFieldFrequency 0x507 +#define HidUsage_Sen_DataFieldPeriod 0x508 +#define HidUsage_Sen_DataFieldPercentofRange 0x509 +#define HidUsage_Sen_DataFieldTime 0x520 +#define HidUsage_Sen_DataFieldYear 0x521 +#define HidUsage_Sen_DataFieldMonth 0x522 +#define HidUsage_Sen_DataFieldDay 0x523 +#define HidUsage_Sen_DataFieldDayofWeek 0x524 +#define HidUsage_Sen_DataFieldHour 0x525 +#define HidUsage_Sen_DataFieldMinute 0x526 +#define HidUsage_Sen_DataFieldSecond 0x527 +#define HidUsage_Sen_DataFieldMillisecond 0x528 +#define HidUsage_Sen_DataFieldTimestamp 0x529 +#define HidUsage_Sen_DataFieldJulianDayofYear 0x52a +#define HidUsage_Sen_DataFieldTimeSinceSystemBoot 0x52b +#define HidUsage_Sen_PropertyTime 0x530 +#define HidUsage_Sen_PropertyTimeZoneOffsetfromUTC 0x531 +#define HidUsage_Sen_PropertyTimeZoneName 0x532 +#define HidUsage_Sen_PropertyDaylightSavingsTimeObserved 0x533 +#define HidUsage_Sen_PropertyTimeTrimAdjustment 0x534 +#define HidUsage_Sen_PropertyArmAlarm 0x535 +#define HidUsage_Sen_DataFieldCustom 0x540 +#define HidUsage_Sen_DataFieldCustomUsage 0x541 +#define HidUsage_Sen_DataFieldCustomBooleanArray 0x542 +#define HidUsage_Sen_DataFieldCustomValue 0x543 +#define HidUsage_Sen_DataFieldCustomValue1 0x544 +#define HidUsage_Sen_DataFieldCustomValue2 0x545 +#define HidUsage_Sen_DataFieldCustomValue3 0x546 +#define HidUsage_Sen_DataFieldCustomValue4 0x547 +#define HidUsage_Sen_DataFieldCustomValue5 0x548 +#define HidUsage_Sen_DataFieldCustomValue6 0x549 +#define HidUsage_Sen_DataFieldCustomValue7 0x54a +#define HidUsage_Sen_DataFieldCustomValue8 0x54b +#define HidUsage_Sen_DataFieldCustomValue9 0x54c +#define HidUsage_Sen_DataFieldCustomValue10 0x54d +#define HidUsage_Sen_DataFieldCustomValue11 0x54e +#define HidUsage_Sen_DataFieldCustomValue12 0x54f +#define HidUsage_Sen_DataFieldCustomValue13 0x550 +#define HidUsage_Sen_DataFieldCustomValue14 0x551 +#define HidUsage_Sen_DataFieldCustomValue15 0x552 +#define HidUsage_Sen_DataFieldCustomValue16 0x553 +#define HidUsage_Sen_DataFieldCustomValue17 0x554 +#define HidUsage_Sen_DataFieldCustomValue18 0x555 +#define HidUsage_Sen_DataFieldCustomValue19 0x556 +#define HidUsage_Sen_DataFieldCustomValue20 0x557 +#define HidUsage_Sen_DataFieldCustomValue21 0x558 +#define HidUsage_Sen_DataFieldCustomValue22 0x559 +#define HidUsage_Sen_DataFieldCustomValue23 0x55a +#define HidUsage_Sen_DataFieldCustomValue24 0x55b +#define HidUsage_Sen_DataFieldCustomValue25 0x55c +#define HidUsage_Sen_DataFieldCustomValue26 0x55d +#define HidUsage_Sen_DataFieldCustomValue27 0x55e +#define HidUsage_Sen_DataFieldCustomValue28 0x55f +#define HidUsage_Sen_DataFieldGeneric 0x560 +#define HidUsage_Sen_DataFieldGenericGUIDorPROPERTYKEY 0x561 +#define HidUsage_Sen_DataFieldGenericCategoryGUID 0x562 +#define HidUsage_Sen_DataFieldGenericTypeGUID 0x563 +#define HidUsage_Sen_DataFieldGenericEventPROPERTYKEY 0x564 +#define HidUsage_Sen_DataFieldGenericPropertyPROPERTYKEY 0x565 +#define HidUsage_Sen_DataFieldGenericDataFieldPROPERTYKEY 0x566 +#define HidUsage_Sen_DataFieldGenericEvent 0x567 +#define HidUsage_Sen_DataFieldGenericProperty 0x568 +#define HidUsage_Sen_DataFieldGenericDataField 0x569 +#define HidUsage_Sen_DataFieldEnumeratorTableRowIndex 0x56a +#define HidUsage_Sen_DataFieldEnumeratorTableRowCount 0x56b +#define HidUsage_Sen_DataFieldGenericGUIDorPROPERTYKEYkind 0x56c +#define HidUsage_Sen_DataFieldGenericGUID 0x56d +#define HidUsage_Sen_DataFieldGenericPROPERTYKEY 0x56e +#define HidUsage_Sen_DataFieldGenericTopLevelCollectionID 0x56f +#define HidUsage_Sen_DataFieldGenericReportID 0x570 +#define HidUsage_Sen_DataFieldGenericReportItemPositionIndex 0x571 +#define HidUsage_Sen_DataFieldGenericFirmwareVARTYPE 0x572 +#define HidUsage_Sen_DataFieldGenericUnitofMeasure 0x573 +#define HidUsage_Sen_DataFieldGenericUnitExponent 0x574 +#define HidUsage_Sen_DataFieldGenericReportSize 0x575 +#define HidUsage_Sen_DataFieldGenericReportCount 0x576 +#define HidUsage_Sen_PropertyGeneric 0x580 +#define HidUsage_Sen_PropertyEnumeratorTableRowIndex 0x581 +#define HidUsage_Sen_PropertyEnumeratorTableRowCount 0x582 +#define HidUsage_Sen_DataFieldPersonalActivity 0x590 +#define HidUsage_Sen_DataFieldActivityType 0x591 +#define HidUsage_Sen_DataFieldActivityState 0x592 +#define HidUsage_Sen_DataFieldDevicePosition 0x593 +#define HidUsage_Sen_DataFieldStepCount 0x594 +#define HidUsage_Sen_DataFieldStepCountReset 0x595 +#define HidUsage_Sen_DataFieldStepDuration 0x596 +#define HidUsage_Sen_DataFieldStepType 0x597 +#define HidUsage_Sen_PropertyMinimumActivityDetectionInterval 0x5a0 +#define HidUsage_Sen_PropertySupportedActivityTypes 0x5a1 +#define HidUsage_Sen_PropertySubscribedActivityTypes 0x5a2 +#define HidUsage_Sen_PropertySupportedStepTypes 0x5a3 +#define HidUsage_Sen_PropertySubscribedStepTypes 0x5a4 +#define HidUsage_Sen_PropertyFloorHeight 0x5a5 +#define HidUsage_Sen_DataFieldCustomTypeID 0x5b0 +#define HidUsage_Sen_PropertyCustom 0x5c0 +#define HidUsage_Sen_PropertyCustomValue1 0x5c1 +#define HidUsage_Sen_PropertyCustomValue2 0x5c2 +#define HidUsage_Sen_PropertyCustomValue3 0x5c3 +#define HidUsage_Sen_PropertyCustomValue4 0x5c4 +#define HidUsage_Sen_PropertyCustomValue5 0x5c5 +#define HidUsage_Sen_PropertyCustomValue6 0x5c6 +#define HidUsage_Sen_PropertyCustomValue7 0x5c7 +#define HidUsage_Sen_PropertyCustomValue8 0x5c8 +#define HidUsage_Sen_PropertyCustomValue9 0x5c9 +#define HidUsage_Sen_PropertyCustomValue10 0x5ca +#define HidUsage_Sen_PropertyCustomValue11 0x5cb +#define HidUsage_Sen_PropertyCustomValue12 0x5cc +#define HidUsage_Sen_PropertyCustomValue13 0x5cd +#define HidUsage_Sen_PropertyCustomValue14 0x5ce +#define HidUsage_Sen_PropertyCustomValue15 0x5cf +#define HidUsage_Sen_PropertyCustomValue16 0x5d0 +#define HidUsage_Sen_DataFieldHinge 0x5e0 +#define HidUsage_Sen_DataFieldHingeAngle 0x5e1 +#define HidUsage_Sen_DataFieldGestureSensor 0x5f0 +#define HidUsage_Sen_DataFieldGestureState 0x5f1 +#define HidUsage_Sen_DataFieldHingeFoldInitialAngle 0x5f2 +#define HidUsage_Sen_DataFieldHingeFoldFinalAngle 0x5f3 +#define HidUsage_Sen_DataFieldHingeFoldContributingPanel 0x5f4 +#define HidUsage_Sen_DataFieldHingeFoldType 0x5f5 +#define HidUsage_Sen_SensorStateUndefined 0x800 +#define HidUsage_Sen_SensorStateReady 0x801 +#define HidUsage_Sen_SensorStateNotAvailable 0x802 +#define HidUsage_Sen_SensorStateNoData 0x803 +#define HidUsage_Sen_SensorStateInitializing 0x804 +#define HidUsage_Sen_SensorStateAccessDenied 0x805 +#define HidUsage_Sen_SensorStateError 0x806 +#define HidUsage_Sen_SensorEventUnknown 0x810 +#define HidUsage_Sen_SensorEventStateChanged 0x811 +#define HidUsage_Sen_SensorEventPropertyChanged 0x812 +#define HidUsage_Sen_SensorEventDataUpdated 0x813 +#define HidUsage_Sen_SensorEventPollResponse 0x814 +#define HidUsage_Sen_SensorEventChangeSensitivity 0x815 +#define HidUsage_Sen_SensorEventRangeMaximumReached 0x816 +#define HidUsage_Sen_SensorEventRangeMinimumReached 0x817 +#define HidUsage_Sen_SensorEventHighThresholdCrossUpward 0x818 +#define HidUsage_Sen_SensorEventHighThresholdCrossDownward 0x819 +#define HidUsage_Sen_SensorEventLowThresholdCrossUpward 0x81a +#define HidUsage_Sen_SensorEventLowThresholdCrossDownward 0x81b +#define HidUsage_Sen_SensorEventZeroThresholdCrossUpward 0x81c +#define HidUsage_Sen_SensorEventZeroThresholdCrossDownward 0x81d +#define HidUsage_Sen_SensorEventPeriodExceeded 0x81e +#define HidUsage_Sen_SensorEventFrequencyExceeded 0x81f +#define HidUsage_Sen_SensorEventComplexTrigger 0x820 +#define HidUsage_Sen_ConnectionTypePCIntegrated 0x830 +#define HidUsage_Sen_ConnectionTypePCAttached 0x831 +#define HidUsage_Sen_ConnectionTypePCExternal 0x832 +#define HidUsage_Sen_ReportingStateReportNoEvents 0x840 +#define HidUsage_Sen_ReportingStateReportAllEvents 0x841 +#define HidUsage_Sen_ReportingStateReportThresholdEvents 0x842 +#define HidUsage_Sen_ReportingStateWakeOnNoEvents 0x843 +#define HidUsage_Sen_ReportingStateWakeOnAllEvents 0x844 +#define HidUsage_Sen_ReportingStateWakeOnThresholdEvents 0x845 +#define HidUsage_Sen_ReportingStateAnytime 0x846 +#define HidUsage_Sen_PowerStateUndefined 0x850 +#define HidUsage_Sen_PowerStateD0FullPower 0x851 +#define HidUsage_Sen_PowerStateD1LowPower 0x852 +#define HidUsage_Sen_PowerStateD2StandbyPowerwithWakeup 0x853 +#define HidUsage_Sen_PowerStateD3SleepwithWakeup 0x854 +#define HidUsage_Sen_PowerStateD4PowerOff 0x855 +#define HidUsage_Sen_AccuracyDefault 0x860 +#define HidUsage_Sen_AccuracyHigh 0x861 +#define HidUsage_Sen_AccuracyMedium 0x862 +#define HidUsage_Sen_AccuracyLow 0x863 +#define HidUsage_Sen_FixQualityNoFix 0x870 +#define HidUsage_Sen_FixQualityGPS 0x871 +#define HidUsage_Sen_FixQualityDGPS 0x872 +#define HidUsage_Sen_FixTypeNoFix 0x880 +#define HidUsage_Sen_FixTypeGPSSPSModeFixValid 0x881 +#define HidUsage_Sen_FixTypeDGPSSPSModeFixValid 0x882 +#define HidUsage_Sen_FixTypeGPSPPSModeFixValid 0x883 +#define HidUsage_Sen_FixTypeRealTimeKinematic 0x884 +#define HidUsage_Sen_FixTypeFloatRTK 0x885 +#define HidUsage_Sen_FixTypeEstimateddeadreckoned 0x886 +#define HidUsage_Sen_FixTypeManualInputMode 0x887 +#define HidUsage_Sen_FixTypeSimulatorMode 0x888 +#define HidUsage_Sen_GPSOperationModeManual 0x890 +#define HidUsage_Sen_GPSOperationModeAutomatic 0x891 +#define HidUsage_Sen_GPSSelectionModeAutonomous 0x8a0 +#define HidUsage_Sen_GPSSelectionModeDGPS 0x8a1 +#define HidUsage_Sen_GPSSelectionModeEstimateddeadreckoned 0x8a2 +#define HidUsage_Sen_GPSSelectionModeManualInput 0x8a3 +#define HidUsage_Sen_GPSSelectionModeSimulator 0x8a4 +#define HidUsage_Sen_GPSSelectionModeDataNotValid 0x8a5 +#define HidUsage_Sen_GPSStatusDataValid 0x8b0 +#define HidUsage_Sen_GPSStatusDataNotValid 0x8b1 +#define HidUsage_Sen_DayofWeekSunday 0x8c0 +#define HidUsage_Sen_DayofWeekMonday 0x8c1 +#define HidUsage_Sen_DayofWeekTuesday 0x8c2 +#define HidUsage_Sen_DayofWeekWednesday 0x8c3 +#define HidUsage_Sen_DayofWeekThursday 0x8c4 +#define HidUsage_Sen_DayofWeekFriday 0x8c5 +#define HidUsage_Sen_DayofWeekSaturday 0x8c6 +#define HidUsage_Sen_KindCategory 0x8d0 +#define HidUsage_Sen_KindType 0x8d1 +#define HidUsage_Sen_KindEvent 0x8d2 +#define HidUsage_Sen_KindProperty 0x8d3 +#define HidUsage_Sen_KindDataField 0x8d4 +#define HidUsage_Sen_MagnetometerAccuracyLow 0x8e0 +#define HidUsage_Sen_MagnetometerAccuracyMedium 0x8e1 +#define HidUsage_Sen_MagnetometerAccuracyHigh 0x8e2 +#define HidUsage_Sen_SimpleOrientationDirectionNotRotated 0x8f0 +#define HidUsage_Sen_SimpleOrientationDirectionRotated90DegreesCCW 0x8f1 +#define HidUsage_Sen_SimpleOrientationDirectionRotated180DegreesCCW 0x8f2 +#define HidUsage_Sen_SimpleOrientationDirectionRotated270DegreesCCW 0x8f3 +#define HidUsage_Sen_SimpleOrientationDirectionFaceUp 0x8f4 +#define HidUsage_Sen_SimpleOrientationDirectionFaceDown 0x8f5 +#define HidUsage_Sen_VT_NULL 0x900 +#define HidUsage_Sen_VT_BOOL 0x901 +#define HidUsage_Sen_VT_UI1 0x902 +#define HidUsage_Sen_VT_I1 0x903 +#define HidUsage_Sen_VT_UI2 0x904 +#define HidUsage_Sen_VT_I2 0x905 +#define HidUsage_Sen_VT_UI4 0x906 +#define HidUsage_Sen_VT_I4 0x907 +#define HidUsage_Sen_VT_UI8 0x908 +#define HidUsage_Sen_VT_I8 0x909 +#define HidUsage_Sen_VT_R4 0x90a +#define HidUsage_Sen_VT_R8 0x90b +#define HidUsage_Sen_VT_WSTR 0x90c +#define HidUsage_Sen_VT_STR 0x90d +#define HidUsage_Sen_VT_CLSID 0x90e +#define HidUsage_Sen_VT_VECTORVT_UI1 0x90f +#define HidUsage_Sen_VT_F16E0 0x910 +#define HidUsage_Sen_VT_F16E1 0x911 +#define HidUsage_Sen_VT_F16E2 0x912 +#define HidUsage_Sen_VT_F16E3 0x913 +#define HidUsage_Sen_VT_F16E4 0x914 +#define HidUsage_Sen_VT_F16E5 0x915 +#define HidUsage_Sen_VT_F16E6 0x916 +#define HidUsage_Sen_VT_F16E7 0x917 +#define HidUsage_Sen_VT_F16E8 0x918 +#define HidUsage_Sen_VT_F16E9 0x919 +#define HidUsage_Sen_VT_F16EA 0x91a +#define HidUsage_Sen_VT_F16EB 0x91b +#define HidUsage_Sen_VT_F16EC 0x91c +#define HidUsage_Sen_VT_F16ED 0x91d +#define HidUsage_Sen_VT_F16EE 0x91e +#define HidUsage_Sen_VT_F16EF 0x91f +#define HidUsage_Sen_VT_F32E0 0x920 +#define HidUsage_Sen_VT_F32E1 0x921 +#define HidUsage_Sen_VT_F32E2 0x922 +#define HidUsage_Sen_VT_F32E3 0x923 +#define HidUsage_Sen_VT_F32E4 0x924 +#define HidUsage_Sen_VT_F32E5 0x925 +#define HidUsage_Sen_VT_F32E6 0x926 +#define HidUsage_Sen_VT_F32E7 0x927 +#define HidUsage_Sen_VT_F32E8 0x928 +#define HidUsage_Sen_VT_F32E9 0x929 +#define HidUsage_Sen_VT_F32EA 0x92a +#define HidUsage_Sen_VT_F32EB 0x92b +#define HidUsage_Sen_VT_F32EC 0x92c +#define HidUsage_Sen_VT_F32ED 0x92d +#define HidUsage_Sen_VT_F32EE 0x92e +#define HidUsage_Sen_VT_F32EF 0x92f +#define HidUsage_Sen_ActivityTypeUnknown 0x930 +#define HidUsage_Sen_ActivityTypeStationary 0x931 +#define HidUsage_Sen_ActivityTypeFidgeting 0x932 +#define HidUsage_Sen_ActivityTypeWalking 0x933 +#define HidUsage_Sen_ActivityTypeRunning 0x934 +#define HidUsage_Sen_ActivityTypeInVehicle 0x935 +#define HidUsage_Sen_ActivityTypeBiking 0x936 +#define HidUsage_Sen_ActivityTypeIdle 0x937 +#define HidUsage_Sen_UnitNotSpecified 0x940 +#define HidUsage_Sen_UnitLux 0x941 +#define HidUsage_Sen_UnitDegreesKelvin 0x942 +#define HidUsage_Sen_UnitDegreesCelsius 0x943 +#define HidUsage_Sen_UnitPascal 0x944 +#define HidUsage_Sen_UnitNewton 0x945 +#define HidUsage_Sen_UnitMetersSecond 0x946 +#define HidUsage_Sen_UnitKilogram 0x947 +#define HidUsage_Sen_UnitMeter 0x948 +#define HidUsage_Sen_UnitMetersSecondSecond 0x949 +#define HidUsage_Sen_UnitFarad 0x94a +#define HidUsage_Sen_UnitAmpere 0x94b +#define HidUsage_Sen_UnitWatt 0x94c +#define HidUsage_Sen_UnitHenry 0x94d +#define HidUsage_Sen_UnitOhm 0x94e +#define HidUsage_Sen_UnitVolt 0x94f +#define HidUsage_Sen_UnitHertz 0x950 +#define HidUsage_Sen_UnitBar 0x951 +#define HidUsage_Sen_UnitDegreesAnticlockwise 0x952 +#define HidUsage_Sen_UnitDegreesClockwise 0x953 +#define HidUsage_Sen_UnitDegrees 0x954 +#define HidUsage_Sen_UnitDegreesSecond 0x955 +#define HidUsage_Sen_UnitDegreesSecondSecond 0x956 +#define HidUsage_Sen_UnitKnot 0x957 +#define HidUsage_Sen_UnitPercent 0x958 +#define HidUsage_Sen_UnitSecond 0x959 +#define HidUsage_Sen_UnitMillisecond 0x95a +#define HidUsage_Sen_UnitG 0x95b +#define HidUsage_Sen_UnitBytes 0x95c +#define HidUsage_Sen_UnitMilligauss 0x95d +#define HidUsage_Sen_UnitBits 0x95e +#define HidUsage_Sen_ActivityStateNoStateChange 0x960 +#define HidUsage_Sen_ActivityStateStartActivity 0x961 +#define HidUsage_Sen_ActivityStateEndActivity 0x962 +#define HidUsage_Sen_Exponent0 0x970 +#define HidUsage_Sen_Exponent1 0x971 +#define HidUsage_Sen_Exponent2 0x972 +#define HidUsage_Sen_Exponent3 0x973 +#define HidUsage_Sen_Exponent4 0x974 +#define HidUsage_Sen_Exponent5 0x975 +#define HidUsage_Sen_Exponent6 0x976 +#define HidUsage_Sen_Exponent7 0x977 +#define HidUsage_Sen_Exponent8 0x978 +#define HidUsage_Sen_Exponent9 0x979 +#define HidUsage_Sen_ExponentA 0x97a +#define HidUsage_Sen_ExponentB 0x97b +#define HidUsage_Sen_ExponentC 0x97c +#define HidUsage_Sen_ExponentD 0x97d +#define HidUsage_Sen_ExponentE 0x97e +#define HidUsage_Sen_ExponentF 0x97f +#define HidUsage_Sen_DevicePositionUnknown 0x980 +#define HidUsage_Sen_DevicePositionUnchanged 0x981 +#define HidUsage_Sen_DevicePositionOnDesk 0x982 +#define HidUsage_Sen_DevicePositionInHand 0x983 +#define HidUsage_Sen_DevicePositionMovinginBag 0x984 +#define HidUsage_Sen_DevicePositionStationaryinBag 0x985 +#define HidUsage_Sen_StepTypeUnknown 0x990 +#define HidUsage_Sen_StepTypeWalking 0x991 +#define HidUsage_Sen_StepTypeRunning 0x992 +#define HidUsage_Sen_GestureStateUnknown 0x9a0 +#define HidUsage_Sen_GestureStateStarted 0x9a1 +#define HidUsage_Sen_GestureStateCompleted 0x9a2 +#define HidUsage_Sen_GestureStateCancelled 0x9a3 +#define HidUsage_Sen_HingeFoldContributingPanelUnknown 0x9b0 +#define HidUsage_Sen_HingeFoldContributingPanelPanel1 0x9b1 +#define HidUsage_Sen_HingeFoldContributingPanelPanel2 0x9b2 +#define HidUsage_Sen_HingeFoldContributingPanelBoth 0x9b3 +#define HidUsage_Sen_HingeFoldTypeUnknown 0x9b4 +#define HidUsage_Sen_HingeFoldTypeIncreasing 0x9b5 +#define HidUsage_Sen_HingeFoldTypeDecreasing 0x9b6 +#define HidUsage_Sen_HumanPresenceDetectionTypeVendorDefinedNonBiometric 0x9c0 +#define HidUsage_Sen_HumanPresenceDetectionTypeVendorDefinedBiometric 0x9c1 +#define HidUsage_Sen_HumanPresenceDetectionTypeFacialBiometric 0x9c2 +#define HidUsage_Sen_HumanPresenceDetectionTypeAudioBiometric 0x9c3 +#define HidUsage_Sen_ModifierChangeSensitivityAbsolute 0x1000 +#define HidUsage_Sen_ModifierMaximum 0x2000 +#define HidUsage_Sen_ModifierMinimum 0x3000 +#define HidUsage_Sen_ModifierAccuracy 0x4000 +#define HidUsage_Sen_ModifierResolution 0x5000 +#define HidUsage_Sen_ModifierThresholdHigh 0x6000 +#define HidUsage_Sen_ModifierThresholdLow 0x7000 +#define HidUsage_Sen_ModifierCalibrationOffset 0x8000 +#define HidUsage_Sen_ModifierCalibrationMultiplier 0x9000 +#define HidUsage_Sen_ModifierReportInterval 0xa000 +#define HidUsage_Sen_ModifierFrequencyMax 0xb000 +#define HidUsage_Sen_ModifierPeriodMax 0xc000 +#define HidUsage_Sen_ModifierChangeSensitivityPercentofRange 0xd000 +#define HidUsage_Sen_ModifierChangeSensitivityPercentRelative 0xe000 +#define HidUsage_Sen_ModifierVendorReserved 0xf000 +#define HidUsage_MI_MedicalUltrasound 0x01 +#define HidUsage_MI_VCRAcquisition 0x20 +#define HidUsage_MI_FreezeThaw 0x21 +#define HidUsage_MI_ClipStore 0x22 +#define HidUsage_MI_Update 0x23 +#define HidUsage_MI_Next 0x24 +#define HidUsage_MI_Save 0x25 +#define HidUsage_MI_Print 0x26 +#define HidUsage_MI_MicrophoneEnable 0x27 +#define HidUsage_MI_Cine 0x40 +#define HidUsage_MI_TransmitPower 0x41 +#define HidUsage_MI_Volume 0x42 +#define HidUsage_MI_Focus 0x43 +#define HidUsage_MI_Depth 0x44 +#define HidUsage_MI_SoftStepPrimary 0x60 +#define HidUsage_MI_SoftStepSecondary 0x61 +#define HidUsage_MI_DepthGainCompensation 0x70 +#define HidUsage_MI_ZoomSelect 0x80 +#define HidUsage_MI_ZoomAdjust 0x81 +#define HidUsage_MI_SpectralDopplerModeSelect 0x82 +#define HidUsage_MI_SpectralDopplerAdjust 0x83 +#define HidUsage_MI_ColorDopplerModeSelect 0x84 +#define HidUsage_MI_ColorDopplerAdjust 0x85 +#define HidUsage_MI_MotionModeSelect 0x86 +#define HidUsage_MI_MotionModeAdjust 0x87 +#define HidUsage_MI_TwoDModeSelect 0x88 +#define HidUsage_MI_TwoDModeAdjust 0x89 +#define HidUsage_MI_SoftControlSelect 0xa0 +#define HidUsage_MI_SoftControlAdjust 0xa1 +#define HidUsage_BD_BrailleDisplay 0x01 +#define HidUsage_BD_BrailleRow 0x02 +#define HidUsage_BD_EightDotBrailleCell 0x03 +#define HidUsage_BD_SixDotBrailleCell 0x04 +#define HidUsage_BD_NumberofBrailleCells 0x05 +#define HidUsage_BD_ScreenReaderControl 0x06 +#define HidUsage_BD_ScreenReaderIdentifier 0x07 +#define HidUsage_BD_RouterSet1 0xfa +#define HidUsage_BD_RouterSet2 0xfb +#define HidUsage_BD_RouterSet3 0xfc +#define HidUsage_BD_RouterKey 0x100 +#define HidUsage_BD_RowRouterKey 0x101 +#define HidUsage_BD_BrailleButtons 0x200 +#define HidUsage_BD_BrailleKeyboardDot1 0x201 +#define HidUsage_BD_BrailleKeyboardDot2 0x202 +#define HidUsage_BD_BrailleKeyboardDot3 0x203 +#define HidUsage_BD_BrailleKeyboardDot4 0x204 +#define HidUsage_BD_BrailleKeyboardDot5 0x205 +#define HidUsage_BD_BrailleKeyboardDot6 0x206 +#define HidUsage_BD_BrailleKeyboardDot7 0x207 +#define HidUsage_BD_BrailleKeyboardDot8 0x208 +#define HidUsage_BD_BrailleKeyboardSpace 0x209 +#define HidUsage_BD_BrailleKeyboardLeftSpace 0x20a +#define HidUsage_BD_BrailleKeyboardRightSpace 0x20b +#define HidUsage_BD_BrailleFaceControls 0x20c +#define HidUsage_BD_BrailleLeftControls 0x20d +#define HidUsage_BD_BrailleRightControls 0x20e +#define HidUsage_BD_BrailleTopControls 0x20f +#define HidUsage_BD_BrailleJoystickCenter 0x210 +#define HidUsage_BD_BrailleJoystickUp 0x211 +#define HidUsage_BD_BrailleJoystickDown 0x212 +#define HidUsage_BD_BrailleJoystickLeft 0x213 +#define HidUsage_BD_BrailleJoystickRight 0x214 +#define HidUsage_BD_BrailleDPadCenter 0x215 +#define HidUsage_BD_BrailleDPadUp 0x216 +#define HidUsage_BD_BrailleDPadDown 0x217 +#define HidUsage_BD_BrailleDPadLeft 0x218 +#define HidUsage_BD_BrailleDPadRight 0x219 +#define HidUsage_BD_BraillePanLeft 0x21a +#define HidUsage_BD_BraillePanRight 0x21b +#define HidUsage_BD_BrailleRockerUp 0x21c +#define HidUsage_BD_BrailleRockerDown 0x21d +#define HidUsage_BD_BrailleRockerPress 0x21e +#define HidUsage_LAI_LampArray 0x01 +#define HidUsage_LAI_LampArrayAttributesReport 0x02 +#define HidUsage_LAI_LampCount 0x03 +#define HidUsage_LAI_BoundingBoxWidthInMicrometers 0x04 +#define HidUsage_LAI_BoundingBoxHeightInMicrometers 0x05 +#define HidUsage_LAI_BoundingBoxDepthInMicrometers 0x06 +#define HidUsage_LAI_LampArrayKind 0x07 +#define HidUsage_LAI_MinUpdateIntervalInMicroseconds 0x08 +#define HidUsage_LAI_LampAttributesRequestReport 0x20 +#define HidUsage_LAI_LampId 0x21 +#define HidUsage_LAI_LampAttributesResponseReport 0x22 +#define HidUsage_LAI_PositionXInMicrometers 0x23 +#define HidUsage_LAI_PositionYInMicrometers 0x24 +#define HidUsage_LAI_PositionZInMicrometers 0x25 +#define HidUsage_LAI_LampPurposes 0x26 +#define HidUsage_LAI_UpdateLatencyInMicroseconds 0x27 +#define HidUsage_LAI_RedLevelCount 0x28 +#define HidUsage_LAI_GreenLevelCount 0x29 +#define HidUsage_LAI_BlueLevelCount 0x2a +#define HidUsage_LAI_IntensityLevelCount 0x2b +#define HidUsage_LAI_IsProgrammable 0x2c +#define HidUsage_LAI_InputBinding 0x2d +#define HidUsage_LAI_LampMultiUpdateReport 0x50 +#define HidUsage_LAI_RedUpdateChannel 0x51 +#define HidUsage_LAI_GreenUpdateChannel 0x52 +#define HidUsage_LAI_BlueUpdateChannel 0x53 +#define HidUsage_LAI_IntensityUpdateChannel 0x54 +#define HidUsage_LAI_LampUpdateFlags 0x55 +#define HidUsage_LAI_LampRangeUpdateReport 0x60 +#define HidUsage_LAI_LampIdStart 0x61 +#define HidUsage_LAI_LampIdEnd 0x62 +#define HidUsage_LAI_LampArrayControlReport 0x70 +#define HidUsage_LAI_AutonomousMode 0x71 +#define HidUsage_Mon_MonitorControl 0x01 +#define HidUsage_Mon_EDIDInformation 0x02 +#define HidUsage_Mon_VDIFInformation 0x03 +#define HidUsage_Mon_VESAVersion 0x04 +#define HidUsage_VESAVC_Degauss 0x01 +#define HidUsage_VESAVC_Brightness 0x10 +#define HidUsage_VESAVC_Contrast 0x12 +#define HidUsage_VESAVC_RedVideoGain 0x16 +#define HidUsage_VESAVC_GreenVideoGain 0x18 +#define HidUsage_VESAVC_BlueVideoGain 0x1a +#define HidUsage_VESAVC_Focus 0x1c +#define HidUsage_VESAVC_HorizontalPosition 0x20 +#define HidUsage_VESAVC_HorizontalSize 0x22 +#define HidUsage_VESAVC_HorizontalPincushion 0x24 +#define HidUsage_VESAVC_HorizontalPincushionBalance 0x26 +#define HidUsage_VESAVC_HorizontalMisconvergence 0x28 +#define HidUsage_VESAVC_HorizontalLinearity 0x2a +#define HidUsage_VESAVC_HorizontalLinearityBalance 0x2c +#define HidUsage_VESAVC_VerticalPosition 0x30 +#define HidUsage_VESAVC_VerticalSize 0x32 +#define HidUsage_VESAVC_VerticalPincushion 0x34 +#define HidUsage_VESAVC_VerticalPincushionBalance 0x36 +#define HidUsage_VESAVC_VerticalMisconvergence 0x38 +#define HidUsage_VESAVC_VerticalLinearity 0x3a +#define HidUsage_VESAVC_VerticalLinearityBalance 0x3c +#define HidUsage_VESAVC_ParallelogramDistortionKeyBalance 0x40 +#define HidUsage_VESAVC_TrapezoidalDistortionKey 0x42 +#define HidUsage_VESAVC_TiltRotation 0x44 +#define HidUsage_VESAVC_TopCornerDistortionControl 0x46 +#define HidUsage_VESAVC_TopCornerDistortionBalance 0x48 +#define HidUsage_VESAVC_BottomCornerDistortionControl 0x4a +#define HidUsage_VESAVC_BottomCornerDistortionBalance 0x4c +#define HidUsage_VESAVC_HorizontalMoiré 0x56 +#define HidUsage_VESAVC_VerticalMoiré 0x58 +#define HidUsage_VESAVC_InputLevelSelect 0x5e +#define HidUsage_VESAVC_InputSourceSelect 0x60 +#define HidUsage_VESAVC_RedVideoBlackLevel 0x6c +#define HidUsage_VESAVC_GreenVideoBlackLevel 0x6e +#define HidUsage_VESAVC_BlueVideoBlackLevel 0x70 +#define HidUsage_VESAVC_AutoSizeCenter 0xa2 +#define HidUsage_VESAVC_PolarityHorizontalSynchronization 0xa4 +#define HidUsage_VESAVC_PolarityVerticalSynchronization 0xa6 +#define HidUsage_VESAVC_SynchronizationType 0xa8 +#define HidUsage_VESAVC_ScreenOrientation 0xaa +#define HidUsage_VESAVC_HorizontalFrequency 0xac +#define HidUsage_VESAVC_VerticalFrequency 0xae +#define HidUsage_VESAVC_Settings 0xb0 +#define HidUsage_VESAVC_OnScreenDisplay 0xca +#define HidUsage_VESAVC_StereoMode 0xd4 +#define HidUsage_Pow_iName 0x01 +#define HidUsage_Pow_PresentStatus 0x02 +#define HidUsage_Pow_ChangedStatus 0x03 +#define HidUsage_Pow_UPS 0x04 +#define HidUsage_Pow_PowerSupply 0x05 +#define HidUsage_Pow_BatterySystem 0x10 +#define HidUsage_Pow_BatterySystemId 0x11 +#define HidUsage_Pow_Battery 0x12 +#define HidUsage_Pow_BatteryId 0x13 +#define HidUsage_Pow_Charger 0x14 +#define HidUsage_Pow_ChargerId 0x15 +#define HidUsage_Pow_PowerConverter 0x16 +#define HidUsage_Pow_PowerConverterId 0x17 +#define HidUsage_Pow_OutletSystem 0x18 +#define HidUsage_Pow_OutletSystemId 0x19 +#define HidUsage_Pow_Input 0x1a +#define HidUsage_Pow_InputId 0x1b +#define HidUsage_Pow_Output 0x1c +#define HidUsage_Pow_OutputId 0x1d +#define HidUsage_Pow_Flow 0x1e +#define HidUsage_Pow_FlowId 0x1f +#define HidUsage_Pow_Outlet 0x20 +#define HidUsage_Pow_OutletId 0x21 +#define HidUsage_Pow_Gang 0x22 +#define HidUsage_Pow_GangId 0x23 +#define HidUsage_Pow_PowerSummary 0x24 +#define HidUsage_Pow_PowerSummaryId 0x25 +#define HidUsage_Pow_Voltage 0x30 +#define HidUsage_Pow_Current 0x31 +#define HidUsage_Pow_Frequency 0x32 +#define HidUsage_Pow_ApparentPower 0x33 +#define HidUsage_Pow_ActivePower 0x34 +#define HidUsage_Pow_PercentLoad 0x35 +#define HidUsage_Pow_Temperature 0x36 +#define HidUsage_Pow_Humidity 0x37 +#define HidUsage_Pow_BadCount 0x38 +#define HidUsage_Pow_ConfigVoltage 0x40 +#define HidUsage_Pow_ConfigCurrent 0x41 +#define HidUsage_Pow_ConfigFrequency 0x42 +#define HidUsage_Pow_ConfigApparentPower 0x43 +#define HidUsage_Pow_ConfigActivePower 0x44 +#define HidUsage_Pow_ConfigPercentLoad 0x45 +#define HidUsage_Pow_ConfigTemperature 0x46 +#define HidUsage_Pow_ConfigHumidity 0x47 +#define HidUsage_Pow_SwitchOnControl 0x50 +#define HidUsage_Pow_SwitchOffControl 0x51 +#define HidUsage_Pow_ToggleControl 0x52 +#define HidUsage_Pow_LowVoltageTransfer 0x53 +#define HidUsage_Pow_HighVoltageTransfer 0x54 +#define HidUsage_Pow_DelayBeforeReboot 0x55 +#define HidUsage_Pow_DelayBeforeStartup 0x56 +#define HidUsage_Pow_DelayBeforeShutdown 0x57 +#define HidUsage_Pow_Test 0x58 +#define HidUsage_Pow_ModuleReset 0x59 +#define HidUsage_Pow_AudibleAlarmControl 0x5a +#define HidUsage_Pow_Present 0x60 +#define HidUsage_Pow_Good 0x61 +#define HidUsage_Pow_InternalFailure 0x62 +#define HidUsage_Pow_VoltagOutOfRange 0x63 +#define HidUsage_Pow_FrequencyOutOfRange 0x64 +#define HidUsage_Pow_Overload 0x65 +#define HidUsage_Pow_OverCharged 0x66 +#define HidUsage_Pow_OverTemperature 0x67 +#define HidUsage_Pow_ShutdownRequested 0x68 +#define HidUsage_Pow_ShutdownImminent 0x69 +#define HidUsage_Pow_SwitchOnOff 0x6b +#define HidUsage_Pow_Switchable 0x6c +#define HidUsage_Pow_Used 0x6d +#define HidUsage_Pow_Boost 0x6e +#define HidUsage_Pow_Buck 0x6f +#define HidUsage_Pow_Initialized 0x70 +#define HidUsage_Pow_Tested 0x71 +#define HidUsage_Pow_AwaitingPower 0x72 +#define HidUsage_Pow_CommunicationLost 0x73 +#define HidUsage_Pow_iManufacturer 0xfd +#define HidUsage_Pow_iProduct 0xfe +#define HidUsage_Pow_iSerialNumber 0xff +#define HidUsage_BS_SmartBatteryBatteryMode 0x01 +#define HidUsage_BS_SmartBatteryBatteryStatus 0x02 +#define HidUsage_BS_SmartBatteryAlarmWarning 0x03 +#define HidUsage_BS_SmartBatteryChargerMode 0x04 +#define HidUsage_BS_SmartBatteryChargerStatus 0x05 +#define HidUsage_BS_SmartBatteryChargerSpecInfo 0x06 +#define HidUsage_BS_SmartBatterySelectorState 0x07 +#define HidUsage_BS_SmartBatterySelectorPresets 0x08 +#define HidUsage_BS_SmartBatterySelectorInfo 0x09 +#define HidUsage_BS_OptionalMfgFunction1 0x10 +#define HidUsage_BS_OptionalMfgFunction2 0x11 +#define HidUsage_BS_OptionalMfgFunction3 0x12 +#define HidUsage_BS_OptionalMfgFunction4 0x13 +#define HidUsage_BS_OptionalMfgFunction5 0x14 +#define HidUsage_BS_ConnectionToSMBus 0x15 +#define HidUsage_BS_OutputConnection 0x16 +#define HidUsage_BS_ChargerConnection 0x17 +#define HidUsage_BS_BatteryInsertion 0x18 +#define HidUsage_BS_UseNext 0x19 +#define HidUsage_BS_OKToUse 0x1a +#define HidUsage_BS_BatterySupported 0x1b +#define HidUsage_BS_SelectorRevision 0x1c +#define HidUsage_BS_ChargingIndicator 0x1d +#define HidUsage_BS_ManufacturerAccess 0x28 +#define HidUsage_BS_RemainingCapacityLimit 0x29 +#define HidUsage_BS_RemainingTimeLimit 0x2a +#define HidUsage_BS_AtRate 0x2b +#define HidUsage_BS_CapacityMode 0x2c +#define HidUsage_BS_BroadcastToCharger 0x2d +#define HidUsage_BS_PrimaryBattery 0x2e +#define HidUsage_BS_ChargeController 0x2f +#define HidUsage_BS_TerminateCharge 0x40 +#define HidUsage_BS_TerminateDischarge 0x41 +#define HidUsage_BS_BelowRemainingCapacityLimit 0x42 +#define HidUsage_BS_RemainingTimeLimitExpired 0x43 +#define HidUsage_BS_Charging 0x44 +#define HidUsage_BS_Discharging 0x45 +#define HidUsage_BS_FullyCharged 0x46 +#define HidUsage_BS_FullyDischarged 0x47 +#define HidUsage_BS_ConditioningFlag 0x48 +#define HidUsage_BS_AtRateOK 0x49 +#define HidUsage_BS_SmartBatteryErrorCode 0x4a +#define HidUsage_BS_NeedReplacement 0x4b +#define HidUsage_BS_AtRateTimeToFull 0x60 +#define HidUsage_BS_AtRateTimeToEmpty 0x61 +#define HidUsage_BS_AverageCurrent 0x62 +#define HidUsage_BS_MaxError 0x63 +#define HidUsage_BS_RelativeStateOfCharge 0x64 +#define HidUsage_BS_AbsoluteStateOfCharge 0x65 +#define HidUsage_BS_RemainingCapacity 0x66 +#define HidUsage_BS_FullChargeCapacity 0x67 +#define HidUsage_BS_RunTimeToEmpty 0x68 +#define HidUsage_BS_AverageTimeToEmpty 0x69 +#define HidUsage_BS_AverageTimeToFull 0x6a +#define HidUsage_BS_CycleCount 0x6b +#define HidUsage_BS_BatteryPackModelLevel 0x80 +#define HidUsage_BS_InternalChargeController 0x81 +#define HidUsage_BS_PrimaryBatterySupport 0x82 +#define HidUsage_BS_DesignCapacity 0x83 +#define HidUsage_BS_SpecificationInfo 0x84 +#define HidUsage_BS_ManufactureDate 0x85 +#define HidUsage_BS_SerialNumber 0x86 +#define HidUsage_BS_iManufacturerName 0x87 +#define HidUsage_BS_iDeviceName 0x88 +#define HidUsage_BS_iDeviceChemistry 0x89 +#define HidUsage_BS_ManufacturerData 0x8a +#define HidUsage_BS_Rechargeable 0x8b +#define HidUsage_BS_WarningCapacityLimit 0x8c +#define HidUsage_BS_CapacityGranularity1 0x8d +#define HidUsage_BS_CapacityGranularity2 0x8e +#define HidUsage_BS_iOEMInformation 0x8f +#define HidUsage_BS_InhibitCharge 0xc0 +#define HidUsage_BS_EnablePolling 0xc1 +#define HidUsage_BS_ResetToZero 0xc2 +#define HidUsage_BS_ACPresent 0xd0 +#define HidUsage_BS_BatteryPresent 0xd1 +#define HidUsage_BS_PowerFail 0xd2 +#define HidUsage_BS_AlarmInhibited 0xd3 +#define HidUsage_BS_ThermistorUnderRange 0xd4 +#define HidUsage_BS_ThermistorHot 0xd5 +#define HidUsage_BS_ThermistorCold 0xd6 +#define HidUsage_BS_ThermistorOverRange 0xd7 +#define HidUsage_BS_VoltageOutOfRange 0xd8 +#define HidUsage_BS_CurrentOutOfRange 0xd9 +#define HidUsage_BS_CurrentNotRegulated 0xda +#define HidUsage_BS_VoltageNotRegulated 0xdb +#define HidUsage_BS_MasterMode 0xdc +#define HidUsage_BS_ChargerSelectorSupport 0xf0 +#define HidUsage_BS_ChargerSpec 0xf1 +#define HidUsage_BS_Level2 0xf2 +#define HidUsage_BS_Level3 0xf3 +#define HidUsage_BS_BarcodeBadgeReader 0x01 +#define HidUsage_BS_BarcodeScanner 0x02 +#define HidUsage_BS_DumbBarCodeScanner 0x03 +#define HidUsage_BS_CordlessScannerBase 0x04 +#define HidUsage_BS_BarCodeScannerCradle 0x05 +#define HidUsage_BS_AttributeReport 0x10 +#define HidUsage_BS_SettingsReport 0x11 +#define HidUsage_BS_ScannedDataReport 0x12 +#define HidUsage_BS_RawScannedDataReport 0x13 +#define HidUsage_BS_TriggerReport 0x14 +#define HidUsage_BS_StatusReport 0x15 +#define HidUsage_BS_UPCEANControlReport 0x16 +#define HidUsage_BS_EAN23LabelControlReport 0x17 +#define HidUsage_BS_Code39ControlReport 0x18 +#define HidUsage_BS_Interleaved2of5ControlReport 0x19 +#define HidUsage_BS_Standard2of5ControlReport 0x1a +#define HidUsage_BS_MSIPlesseyControlReport 0x1b +#define HidUsage_BS_CodabarControlReport 0x1c +#define HidUsage_BS_Code128ControlReport 0x1d +#define HidUsage_BS_Misc1DControlReport 0x1e +#define HidUsage_BS_TwoDControlReport 0x1f +#define HidUsage_BS_AimingPointerMode 0x30 +#define HidUsage_BS_BarCodePresentSensor 0x31 +#define HidUsage_BS_Class1ALaser 0x32 +#define HidUsage_BS_Class2Laser 0x33 +#define HidUsage_BS_HeaterPresent 0x34 +#define HidUsage_BS_ContactScanner 0x35 +#define HidUsage_BS_ElectronicArticleSurveillanceNotification 0x36 +#define HidUsage_BS_ConstantElectronicArticleSurveillance 0x37 +#define HidUsage_BS_ErrorIndication 0x38 +#define HidUsage_BS_FixedBeeper 0x39 +#define HidUsage_BS_GoodDecodeIndication 0x3a +#define HidUsage_BS_HandsFreeScanning 0x3b +#define HidUsage_BS_IntrinsicallySafe 0x3c +#define HidUsage_BS_KlasseEinsLaser 0x3d +#define HidUsage_BS_LongRangeScanner 0x3e +#define HidUsage_BS_MirrorSpeedControl 0x3f +#define HidUsage_BS_NotOnFileIndication 0x40 +#define HidUsage_BS_ProgrammableBeeper 0x41 +#define HidUsage_BS_Triggerless 0x42 +#define HidUsage_BS_Wand 0x43 +#define HidUsage_BS_WaterResistant 0x44 +#define HidUsage_BS_MultiRangeScanner 0x45 +#define HidUsage_BS_ProximitySensor 0x46 +#define HidUsage_BS_FragmentDecoding 0x4d +#define HidUsage_BS_ScannerReadConfidence 0x4e +#define HidUsage_BS_DataPrefix 0x4f +#define HidUsage_BS_PrefixAIMI 0x50 +#define HidUsage_BS_PrefixNone 0x51 +#define HidUsage_BS_PrefixProprietary 0x52 +#define HidUsage_BS_ActiveTime 0x55 +#define HidUsage_BS_AimingLaserPattern 0x56 +#define HidUsage_BS_BarCodePresent 0x57 +#define HidUsage_BS_BeeperState 0x58 +#define HidUsage_BS_LaserOnTime 0x59 +#define HidUsage_BS_LaserState 0x5a +#define HidUsage_BS_LockoutTime 0x5b +#define HidUsage_BS_MotorState 0x5c +#define HidUsage_BS_MotorTimeout 0x5d +#define HidUsage_BS_PowerOnResetScanner 0x5e +#define HidUsage_BS_PreventReadofBarcodes 0x5f +#define HidUsage_BS_InitiateBarcodeRead 0x60 +#define HidUsage_BS_TriggerState 0x61 +#define HidUsage_BS_TriggerMode 0x62 +#define HidUsage_BS_TriggerModeBlinkingLaserOn 0x63 +#define HidUsage_BS_TriggerModeContinuousLaserOn 0x64 +#define HidUsage_BS_TriggerModeLaseronwhilePulled 0x65 +#define HidUsage_BS_TriggerModeLaserstaysonafterrelease 0x66 +#define HidUsage_BS_CommitParameterstoNVM 0x6d +#define HidUsage_BS_ParameterScanning 0x6e +#define HidUsage_BS_ParametersChanged 0x6f +#define HidUsage_BS_Setparameterdefaultvalues 0x70 +#define HidUsage_BS_ScannerInCradle 0x75 +#define HidUsage_BS_ScannerInRange 0x76 +#define HidUsage_BS_AimDuration 0x7a +#define HidUsage_BS_GoodReadLampDuration 0x7b +#define HidUsage_BS_GoodReadLampIntensity 0x7c +#define HidUsage_BS_GoodReadLED 0x7d +#define HidUsage_BS_GoodReadToneFrequency 0x7e +#define HidUsage_BS_GoodReadToneLength 0x7f +#define HidUsage_BS_GoodReadToneVolume 0x80 +#define HidUsage_BS_NoReadMessage 0x82 +#define HidUsage_BS_NotonFileVolume 0x83 +#define HidUsage_BS_PowerupBeep 0x84 +#define HidUsage_BS_SoundErrorBeep 0x85 +#define HidUsage_BS_SoundGoodReadBeep 0x86 +#define HidUsage_BS_SoundNotOnFileBeep 0x87 +#define HidUsage_BS_GoodReadWhentoWrite 0x88 +#define HidUsage_BS_GRWTIAfterDecode 0x89 +#define HidUsage_BS_GRWTIBeepLampaftertransmit 0x8a +#define HidUsage_BS_GRWTINoBeepLampuseatall 0x8b +#define HidUsage_BS_BooklandEAN 0x91 +#define HidUsage_BS_ConvertEAN8to13Type 0x92 +#define HidUsage_BS_ConvertUPCAtoEAN13 0x93 +#define HidUsage_BS_ConvertUPCEtoA 0x94 +#define HidUsage_BS_EAN13 0x95 +#define HidUsage_BS_EAN8 0x96 +#define HidUsage_BS_EAN99128Mandatory 0x97 +#define HidUsage_BS_EAN99P5128Optional 0x98 +#define HidUsage_BS_EnableEANTwoLabel 0x99 +#define HidUsage_BS_UPCEAN 0x9a +#define HidUsage_BS_UPCEANCouponCode 0x9b +#define HidUsage_BS_UPCEANPeriodicals 0x9c +#define HidUsage_BS_UPCA 0x9d +#define HidUsage_BS_UPCAwith128Mandatory 0x9e +#define HidUsage_BS_UPCAwith128Optional 0x9f +#define HidUsage_BS_UPCAwithP5Optional 0xa0 +#define HidUsage_BS_UPCE 0xa1 +#define HidUsage_BS_UPCE1 0xa2 +#define HidUsage_BS_Periodical 0xa9 +#define HidUsage_BS_PeriodicalAutoDiscriminatePlus2 0xaa +#define HidUsage_BS_PeriodicalOnlyDecodewithPlus2 0xab +#define HidUsage_BS_PeriodicalIgnorePlus2 0xac +#define HidUsage_BS_PeriodicalAutoDiscriminatePlus5 0xad +#define HidUsage_BS_PeriodicalOnlyDecodewithPlus5 0xae +#define HidUsage_BS_PeriodicalIgnorePlus5 0xaf +#define HidUsage_BS_Check 0xb0 +#define HidUsage_BS_CheckDisablePrice 0xb1 +#define HidUsage_BS_CheckEnable4digitPrice 0xb2 +#define HidUsage_BS_CheckEnable5digitPrice 0xb3 +#define HidUsage_BS_CheckEnableEuropean4digitPrice 0xb4 +#define HidUsage_BS_CheckEnableEuropean5digitPrice 0xb5 +#define HidUsage_BS_EANTwoLabel 0xb7 +#define HidUsage_BS_EANThreeLabel 0xb8 +#define HidUsage_BS_EAN8FlagDigit1 0xb9 +#define HidUsage_BS_EAN8FlagDigit2 0xba +#define HidUsage_BS_EAN8FlagDigit3 0xbb +#define HidUsage_BS_EAN13FlagDigit1 0xbc +#define HidUsage_BS_EAN13FlagDigit2 0xbd +#define HidUsage_BS_EAN13FlagDigit3 0xbe +#define HidUsage_BS_AddEAN23LabelDefinition 0xbf +#define HidUsage_BS_ClearallEAN23LabelDefinitions 0xc0 +#define HidUsage_BS_Codabar 0xc3 +#define HidUsage_BS_Code128 0xc4 +#define HidUsage_BS_Code39 0xc7 +#define HidUsage_BS_Code93 0xc8 +#define HidUsage_BS_FullASCIIConversion 0xc9 +#define HidUsage_BS_Interleaved2of5 0xca +#define HidUsage_BS_ItalianPharmacyCode 0xcb +#define HidUsage_BS_MSIPlessey 0xcc +#define HidUsage_BS_Standard2of5IATA 0xcd +#define HidUsage_BS_Standard2of5 0xce +#define HidUsage_BS_TransmitStartStop 0xd3 +#define HidUsage_BS_TriOptic 0xd4 +#define HidUsage_BS_UCCEAN128 0xd5 +#define HidUsage_BS_CheckDigit 0xd6 +#define HidUsage_BS_CheckDigitDisable 0xd7 +#define HidUsage_BS_CheckDigitEnableInterleaved2of5OPCC 0xd8 +#define HidUsage_BS_CheckDigitEnableInterleaved2of5USS 0xd9 +#define HidUsage_BS_CheckDigitEnableStandard2of5OPCC 0xda +#define HidUsage_BS_CheckDigitEnableStandard2of5USS 0xdb +#define HidUsage_BS_CheckDigitEnableOneMSIPlessey 0xdc +#define HidUsage_BS_CheckDigitEnableTwoMSIPlessey 0xdd +#define HidUsage_BS_CheckDigitCodabarEnable 0xde +#define HidUsage_BS_CheckDigitCode39Enable 0xdf +#define HidUsage_BS_TransmitCheckDigit 0xf0 +#define HidUsage_BS_DisableCheckDigitTransmit 0xf1 +#define HidUsage_BS_EnableCheckDigitTransmit 0xf2 +#define HidUsage_BS_SymbologyIdentifier1 0xfb +#define HidUsage_BS_SymbologyIdentifier2 0xfc +#define HidUsage_BS_SymbologyIdentifier3 0xfd +#define HidUsage_BS_DecodedData 0xfe +#define HidUsage_BS_DecodeDataContinued 0xff +#define HidUsage_BS_BarSpaceData 0x100 +#define HidUsage_BS_ScannerDataAccuracy 0x101 +#define HidUsage_BS_RawDataPolarity 0x102 +#define HidUsage_BS_PolarityInvertedBarCode 0x103 +#define HidUsage_BS_PolarityNormalBarCode 0x104 +#define HidUsage_BS_MinimumLengthtoDecode 0x106 +#define HidUsage_BS_MaximumLengthtoDecode 0x107 +#define HidUsage_BS_DiscreteLengthtoDecode1 0x108 +#define HidUsage_BS_DiscreteLengthtoDecode2 0x109 +#define HidUsage_BS_DataLengthMethod 0x10a +#define HidUsage_BS_DLMethodReadany 0x10b +#define HidUsage_BS_DLMethodCheckinRange 0x10c +#define HidUsage_BS_DLMethodCheckforDiscrete 0x10d +#define HidUsage_BS_AztecCode 0x110 +#define HidUsage_BS_BC412 0x111 +#define HidUsage_BS_ChannelCode 0x112 +#define HidUsage_BS_Code16 0x113 +#define HidUsage_BS_Code32 0x114 +#define HidUsage_BS_Code49 0x115 +#define HidUsage_BS_CodeOne 0x116 +#define HidUsage_BS_Colorcode 0x117 +#define HidUsage_BS_DataMatrix 0x118 +#define HidUsage_BS_MaxiCode 0x119 +#define HidUsage_BS_MicroPDF 0x11a +#define HidUsage_BS_PDF417 0x11b +#define HidUsage_BS_PosiCode 0x11c +#define HidUsage_BS_QRCode 0x11d +#define HidUsage_BS_SuperCode 0x11e +#define HidUsage_BS_UltraCode 0x11f +#define HidUsage_BS_USD5SlugCode 0x120 +#define HidUsage_BS_VeriCode 0x121 +#define HidUsage_Sca_Scales 0x01 +#define HidUsage_Sca_ScaleDevice 0x20 +#define HidUsage_Sca_ScaleClass 0x21 +#define HidUsage_Sca_ScaleClassIMetric 0x22 +#define HidUsage_Sca_ScaleClassIIMetric 0x23 +#define HidUsage_Sca_ScaleClassIIIMetric 0x24 +#define HidUsage_Sca_ScaleClassIIILMetric 0x25 +#define HidUsage_Sca_ScaleClassIVMetric 0x26 +#define HidUsage_Sca_ScaleClassIIIEnglish 0x27 +#define HidUsage_Sca_ScaleClassIIILEnglish 0x28 +#define HidUsage_Sca_ScaleClassIVEnglish 0x29 +#define HidUsage_Sca_ScaleClassGeneric 0x2a +#define HidUsage_Sca_ScaleAttributeReport 0x30 +#define HidUsage_Sca_ScaleControlReport 0x31 +#define HidUsage_Sca_ScaleDataReport 0x32 +#define HidUsage_Sca_ScaleStatusReport 0x33 +#define HidUsage_Sca_ScaleWeightLimitReport 0x34 +#define HidUsage_Sca_ScaleStatisticsReport 0x35 +#define HidUsage_Sca_DataWeight 0x40 +#define HidUsage_Sca_DataScaling 0x41 +#define HidUsage_Sca_WeightUnit 0x50 +#define HidUsage_Sca_WeightUnitMilligram 0x51 +#define HidUsage_Sca_WeightUnitGram 0x52 +#define HidUsage_Sca_WeightUnitKilogram 0x53 +#define HidUsage_Sca_WeightUnitCarats 0x54 +#define HidUsage_Sca_WeightUnitTaels 0x55 +#define HidUsage_Sca_WeightUnitGrains 0x56 +#define HidUsage_Sca_WeightUnitPennyweights 0x57 +#define HidUsage_Sca_WeightUnitMetricTon 0x58 +#define HidUsage_Sca_WeightUnitAvoirTon 0x59 +#define HidUsage_Sca_WeightUnitTroyOunce 0x5a +#define HidUsage_Sca_WeightUnitOunce 0x5b +#define HidUsage_Sca_WeightUnitPound 0x5c +#define HidUsage_Sca_CalibrationCount 0x60 +#define HidUsage_Sca_ReZeroCount 0x61 +#define HidUsage_Sca_ScaleStatus 0x70 +#define HidUsage_Sca_ScaleStatusFault 0x71 +#define HidUsage_Sca_ScaleStatusStableatCenterofZero 0x72 +#define HidUsage_Sca_ScaleStatusInMotion 0x73 +#define HidUsage_Sca_ScaleStatusWeightStable 0x74 +#define HidUsage_Sca_ScaleStatusUnderZero 0x75 +#define HidUsage_Sca_ScaleStatusOverWeightLimit 0x76 +#define HidUsage_Sca_ScaleStatusRequiresCalibration 0x77 +#define HidUsage_Sca_ScaleStatusRequiresRezeroing 0x78 +#define HidUsage_Sca_ZeroScale 0x80 +#define HidUsage_Sca_EnforcedZeroReturn 0x81 +#define HidUsage_MSR_MSRDeviceReadOnly 0x01 +#define HidUsage_MSR_Track1Length 0x11 +#define HidUsage_MSR_Track2Length 0x12 +#define HidUsage_MSR_Track3Length 0x13 +#define HidUsage_MSR_TrackJISLength 0x14 +#define HidUsage_MSR_TrackData 0x20 +#define HidUsage_MSR_Track1Data 0x21 +#define HidUsage_MSR_Track2Data 0x22 +#define HidUsage_MSR_Track3Data 0x23 +#define HidUsage_MSR_TrackJISData 0x24 +#define HidUsage_CC_CameraAutofocus 0x20 +#define HidUsage_CC_CameraShutter 0x21 +#define HidUsage_Arc_GeneralPurposeIOCard 0x01 +#define HidUsage_Arc_CoinDoor 0x02 +#define HidUsage_Arc_WatchdogTimer 0x03 +#define HidUsage_Arc_GeneralPurposeAnalogInputState 0x30 +#define HidUsage_Arc_GeneralPurposeDigitalInputState 0x31 +#define HidUsage_Arc_GeneralPurposeOpticalInputState 0x32 +#define HidUsage_Arc_GeneralPurposeDigitalOutputState 0x33 +#define HidUsage_Arc_NumberofCoinDoors 0x34 +#define HidUsage_Arc_CoinDrawerDropCount 0x35 +#define HidUsage_Arc_CoinDrawerStart 0x36 +#define HidUsage_Arc_CoinDrawerService 0x37 +#define HidUsage_Arc_CoinDrawerTilt 0x38 +#define HidUsage_Arc_CoinDoorTest 0x39 +#define HidUsage_Arc_CoinDoorLockout 0x40 +#define HidUsage_Arc_WatchdogTimeout 0x41 +#define HidUsage_Arc_WatchdogAction 0x42 +#define HidUsage_Arc_WatchdogReboot 0x43 +#define HidUsage_Arc_WatchdogRestart 0x44 +#define HidUsage_Arc_AlarmInput 0x45 +#define HidUsage_Arc_CoinDoorCounter 0x46 +#define HidUsage_Arc_IODirectionMapping 0x47 +#define HidUsage_Arc_SetIODirectionMapping 0x48 +#define HidUsage_Arc_ExtendedOpticalInputState 0x49 +#define HidUsage_Arc_PinPadInputState 0x4a +#define HidUsage_Arc_PinPadStatus 0x4b +#define HidUsage_Arc_PinPadOutput 0x4c +#define HidUsage_Arc_PinPadCommand 0x4d +#define HidUsage_FIDOA_U2FAuthenticatorDevice 0x01 +#define HidUsage_FIDOA_InputReportData 0x20 +#define HidUsage_FIDOA_OutputReportData 0x21 diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c index 21e55f3d0d1b..67179e3fe39b 100644 --- a/drivers/hid/hid-alps.c +++ b/drivers/hid/hid-alps.c @@ -437,6 +437,9 @@ static int alps_raw_event(struct hid_device *hdev, int ret = 0; struct alps_dev *hdata = hid_get_drvdata(hdev); + if (!(hdev->claimed & HID_CLAIMED_INPUT) || !hdata->input) + return 0; + switch (hdev->product) { case HID_PRODUCT_ID_T4_BTNLESS: ret = t4_raw_event(hdata, data, size); diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c index fc5897a6bb53..bf7dd0fbf249 100644 --- a/drivers/hid/hid-apple.c +++ b/drivers/hid/hid-apple.c @@ -623,17 +623,19 @@ static int apple_fetch_battery(struct hid_device *hdev) struct apple_sc *asc = hid_get_drvdata(hdev); struct hid_report_enum *report_enum; struct hid_report *report; + struct hid_battery *bat; - if (!(asc->quirks & APPLE_RDESC_BATTERY) || !hdev->battery) + bat = hid_get_battery(hdev); + if (!(asc->quirks & APPLE_RDESC_BATTERY) || !bat) return -1; - report_enum = &hdev->report_enum[hdev->battery_report_type]; - report = report_enum->report_id_hash[hdev->battery_report_id]; + report_enum = &hdev->report_enum[bat->report_type]; + report = report_enum->report_id_hash[bat->report_id]; if (!report || report->maxfield < 1) return -1; - if (hdev->battery_capacity == hdev->battery_max) + if (bat->capacity == bat->max) return -1; hid_hw_request(hdev, report, HID_REQ_GET_REPORT); @@ -858,6 +860,7 @@ static int apple_backlight_init(struct hid_device *hdev) asc->backlight->cdev.name = "apple::kbd_backlight"; asc->backlight->cdev.max_brightness = rep->backlight_on_max; asc->backlight->cdev.brightness_set_blocking = apple_backlight_led_set; + asc->backlight->cdev.flags = LED_CORE_SUSPENDRESUME; ret = apple_backlight_set(hdev, 0, 0); if (ret < 0) { @@ -926,6 +929,7 @@ static int apple_magic_backlight_init(struct hid_device *hdev) backlight->cdev.name = ":white:" LED_FUNCTION_KBD_BACKLIGHT; backlight->cdev.max_brightness = backlight->brightness->field[0]->logical_maximum; backlight->cdev.brightness_set_blocking = apple_magic_backlight_led_set; + backlight->cdev.flags = LED_CORE_SUSPENDRESUME; apple_magic_backlight_set(backlight, 0, 0); diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index bc93b27f9b13..3f5e96900b67 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -20,10 +20,8 @@ * Copyright (c) 2016 Frederik Wenigwieser <frederik.wenigwieser@gmail.com> */ -/* - */ - #include <linux/acpi.h> +#include <linux/cleanup.h> #include <linux/dmi.h> #include <linux/hid.h> #include <linux/module.h> @@ -101,7 +99,6 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad"); #define QUIRK_ROG_CLAYMORE_II_KEYBOARD BIT(12) #define QUIRK_ROG_ALLY_XPAD BIT(13) #define QUIRK_HID_FN_LOCK BIT(14) -#define QUIRK_ROG_NKEY_ID1ID2_INIT BIT(15) #define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ QUIRK_NO_INIT_REPORTS | \ @@ -208,6 +205,12 @@ static const struct asus_touchpad_info medion_e1239t_tp = { .report_size = 32 /* 2 byte header + 5 * 5 + 5 byte footer */, }; +static const u8 asus_report_id_init[] = { + FEATURE_KBD_REPORT_ID, + FEATURE_KBD_LED_REPORT_ID1, + FEATURE_KBD_LED_REPORT_ID2 +}; + static void asus_report_contact_down(struct asus_drvdata *drvdat, int toolType, u8 *data) { @@ -354,7 +357,7 @@ static int asus_event(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage, __s32 value) { struct asus_drvdata *drvdata = hid_get_drvdata(hdev); - + if ((usage->hid & HID_USAGE_PAGE) == HID_UP_ASUSVENDOR && (usage->hid & HID_USAGE) != 0x00 && (usage->hid & HID_USAGE) != 0xff && !usage->type) { @@ -443,21 +446,18 @@ static int asus_raw_event(struct hid_device *hdev, /* * G713 and G733 send these codes on some keypresses, depending on * the key pressed it can trigger a shutdown event if not caught. - */ - if (data[0] == 0x02 && data[1] == 0x30) { + */ + if (data[0] == 0x02 && data[1] == 0x30) return -1; - } } if (drvdata->quirks & QUIRK_ROG_CLAYMORE_II_KEYBOARD) { /* * CLAYMORE II keyboard sends this packet when it goes to sleep * this causes the whole system to go into suspend. - */ - - if(size == 2 && data[0] == 0x02 && data[1] == 0x00) { + */ + if (size == 2 && data[0] == 0x02 && data[1] == 0x00) return -1; - } } return 0; @@ -465,23 +465,16 @@ static int asus_raw_event(struct hid_device *hdev, static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t buf_size) { - unsigned char *dmabuf; - int ret; - - dmabuf = kmemdup(buf, buf_size, GFP_KERNEL); + u8 *dmabuf __free(kfree) = kmemdup(buf, buf_size, GFP_KERNEL); if (!dmabuf) return -ENOMEM; /* * The report ID should be set from the incoming buffer due to LED and key * interfaces having different pages - */ - ret = hid_hw_raw_request(hdev, buf[0], dmabuf, - buf_size, HID_FEATURE_REPORT, - HID_REQ_SET_REPORT); - kfree(dmabuf); - - return ret; + */ + return hid_hw_raw_request(hdev, buf[0], dmabuf, buf_size, HID_FEATURE_REPORT, + HID_REQ_SET_REPORT); } static int asus_kbd_init(struct hid_device *hdev, u8 report_id) @@ -722,6 +715,21 @@ static void validate_mcu_fw_version(struct hid_device *hdev, int idProduct) } } +static bool asus_has_report_id(struct hid_device *hdev, u16 report_id) +{ + struct hid_report *report; + int t; + + for (t = HID_INPUT_REPORT; t <= HID_FEATURE_REPORT; t++) { + list_for_each_entry(report, &hdev->report_enum[t].report_list, list) { + if (report->id == report_id) + return true; + } + } + + return false; +} + static int asus_kbd_register_leds(struct hid_device *hdev) { struct asus_drvdata *drvdata = hid_get_drvdata(hdev); @@ -730,10 +738,6 @@ static int asus_kbd_register_leds(struct hid_device *hdev) unsigned char kbd_func; int ret; - ret = asus_kbd_init(hdev, FEATURE_KBD_REPORT_ID); - if (ret < 0) - return ret; - /* Get keyboard functions */ ret = asus_kbd_get_functions(hdev, &kbd_func, FEATURE_KBD_REPORT_ID); if (ret < 0) @@ -743,11 +747,6 @@ static int asus_kbd_register_leds(struct hid_device *hdev) if (!(kbd_func & SUPPORT_KBD_BACKLIGHT)) return -ENODEV; - if (drvdata->quirks & QUIRK_ROG_NKEY_ID1ID2_INIT) { - asus_kbd_init(hdev, FEATURE_KBD_LED_REPORT_ID1); - asus_kbd_init(hdev, FEATURE_KBD_LED_REPORT_ID2); - } - if (dmi_match(DMI_PRODUCT_FAMILY, "ProArt P16")) { ret = asus_kbd_disable_oobe(hdev); if (ret < 0) @@ -1163,7 +1162,8 @@ static int asus_start_multitouch(struct hid_device *hdev) return 0; } -static int __maybe_unused asus_resume(struct hid_device *hdev) { +static int __maybe_unused asus_resume(struct hid_device *hdev) +{ struct asus_drvdata *drvdata = hid_get_drvdata(hdev); int ret = 0; @@ -1294,8 +1294,19 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) return ret; } + for (int r = 0; r < ARRAY_SIZE(asus_report_id_init); r++) { + if (asus_has_report_id(hdev, asus_report_id_init[r])) { + ret = asus_kbd_init(hdev, asus_report_id_init[r]); + if (ret < 0) + hid_warn(hdev, "Failed to initialize 0x%x: %d.\n", + asus_report_id_init[r], ret); + } + } + + /* Laptops keyboard backlight is always at 0x5a */ if (is_vendor && (drvdata->quirks & QUIRK_USE_KBD_BACKLIGHT) && - asus_kbd_register_leds(hdev)) + (asus_has_report_id(hdev, FEATURE_KBD_REPORT_ID)) && + (asus_kbd_register_leds(hdev))) hid_warn(hdev, "Failed to initialize backlight.\n"); /* @@ -1311,22 +1322,17 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) * were freed during registration due to no usages being mapped, * leaving drvdata->input pointing to freed memory. */ - if (!drvdata->input || !(hdev->claimed & HID_CLAIMED_INPUT)) { - hid_err(hdev, "Asus input not registered\n"); - ret = -ENOMEM; - goto err_stop_hw; - } - - if (drvdata->tp) { - drvdata->input->name = "Asus TouchPad"; - } else { - drvdata->input->name = "Asus Keyboard"; - } + if (drvdata->input && (hdev->claimed & HID_CLAIMED_INPUT)) { + if (drvdata->tp) + drvdata->input->name = "Asus TouchPad"; + else + drvdata->input->name = "Asus Keyboard"; - if (drvdata->tp) { - ret = asus_start_multitouch(hdev); - if (ret) - goto err_stop_hw; + if (drvdata->tp) { + ret = asus_start_multitouch(hdev); + if (ret) + goto err_stop_hw; + } } return 0; @@ -1484,10 +1490,10 @@ static const struct hid_device_id asus_devices[] = { QUIRK_USE_KBD_BACKLIGHT }, { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_ROG_NKEY_ID1ID2_INIT }, + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_ROG_NKEY_KEYBOARD2), - QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_HID_FN_LOCK | QUIRK_ROG_NKEY_ID1ID2_INIT }, + QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD | QUIRK_HID_FN_LOCK }, { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_ROG_Z13_LIGHTBAR), QUIRK_USE_KBD_BACKLIGHT | QUIRK_ROG_NKEY_KEYBOARD }, diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 833df14ef68f..61afec5915ec 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -71,6 +71,9 @@ static u32 s32ton(__s32 value, unsigned int n) if (!value || !n) return 0; + if (n > 32) + n = 32; + a = value >> (n - 1); if (a && a != -1) return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1; @@ -924,7 +927,6 @@ static int hid_scan_main(struct hid_parser *parser, struct hid_item *item) */ static int hid_scan_report(struct hid_device *hid) { - struct hid_parser *parser; struct hid_item item; const __u8 *start = hid->dev_rdesc; const __u8 *end = start + hid->dev_rsize; @@ -936,7 +938,7 @@ static int hid_scan_report(struct hid_device *hid) hid_parser_reserved }; - parser = vzalloc(sizeof(struct hid_parser)); + struct hid_parser *parser __free(kvfree) = vzalloc(sizeof(*parser)); if (!parser) return -ENOMEM; @@ -987,7 +989,6 @@ static int hid_scan_report(struct hid_device *hid) } kfree(parser->collection_stack); - vfree(parser); return 0; } @@ -1244,6 +1245,90 @@ void hid_setup_resolution_multiplier(struct hid_device *hid) } EXPORT_SYMBOL_GPL(hid_setup_resolution_multiplier); +static int hid_parse_collections(struct hid_device *device) +{ + struct hid_item item; + const u8 *start = device->rdesc; + const u8 *end = start + device->rsize; + const u8 *next; + int ret; + static typeof(hid_parser_main) (* const dispatch_type[]) = { + hid_parser_main, + hid_parser_global, + hid_parser_local, + hid_parser_reserved + }; + + struct hid_parser *parser __free(kvfree) = vzalloc(sizeof(*parser)); + if (!parser) + return -ENOMEM; + + parser->device = device; + + device->collection = kzalloc_objs(*device->collection, + HID_DEFAULT_NUM_COLLECTIONS); + if (!device->collection) + return -ENOMEM; + + device->collection_size = HID_DEFAULT_NUM_COLLECTIONS; + for (unsigned int i = 0; i < HID_DEFAULT_NUM_COLLECTIONS; i++) + device->collection[i].parent_idx = -1; + + ret = -EINVAL; + if (start == end) { + hid_err(device, "rejecting 0-sized report descriptor\n"); + goto out; + } + + while ((next = fetch_item(start, end, &item)) != NULL) { + start = next; + + if (item.format != HID_ITEM_FORMAT_SHORT) { + hid_err(device, "unexpected long global item\n"); + goto out; + } + + if (dispatch_type[item.type](parser, &item)) { + hid_err(device, "item %u %u %u %u parsing failed\n", + item.format, + (unsigned int)item.size, + (unsigned int)item.type, + (unsigned int)item.tag); + goto out; + } + } + + if (start != end) { + hid_err(device, "item fetching failed at offset %u/%u\n", + device->rsize - (unsigned int)(end - start), + device->rsize); + goto out; + } + + if (parser->collection_stack_ptr) { + hid_err(device, "unbalanced collection at end of report description\n"); + goto out; + } + + if (parser->local.delimiter_depth) { + hid_err(device, "unbalanced delimiter at end of report description\n"); + goto out; + } + + /* + * fetch initial values in case the device's + * default multiplier isn't the recommended 1 + */ + hid_setup_resolution_multiplier(device); + + device->status |= HID_STAT_PARSED; + ret = 0; + +out: + kfree(parser->collection_stack); + return ret; +} + /** * hid_open_report - open a driver-specific device report * @@ -1258,21 +1343,9 @@ EXPORT_SYMBOL_GPL(hid_setup_resolution_multiplier); */ int hid_open_report(struct hid_device *device) { - struct hid_parser *parser; - struct hid_item item; unsigned int size; - const __u8 *start; - const __u8 *end; - const __u8 *next; - int ret; - int i; - static int (*dispatch_type[])(struct hid_parser *parser, - struct hid_item *item) = { - hid_parser_main, - hid_parser_global, - hid_parser_local, - hid_parser_reserved - }; + const u8 *start; + int error; if (WARN_ON(device->status & HID_STAT_PARSED)) return -EBUSY; @@ -1288,9 +1361,9 @@ int hid_open_report(struct hid_device *device) * on a copy of our report descriptor so it can * change it. */ - __u8 *buf = kmemdup(start, size, GFP_KERNEL); + u8 *buf __free(kfree) = kmemdup(start, size, GFP_KERNEL); - if (buf == NULL) + if (!buf) return -ENOMEM; start = device->driver->report_fixup(device, buf, &size); @@ -1301,82 +1374,20 @@ int hid_open_report(struct hid_device *device) * needs to be cleaned up or not at the end. */ start = kmemdup(start, size, GFP_KERNEL); - kfree(buf); - if (start == NULL) + if (!start) return -ENOMEM; } device->rdesc = start; device->rsize = size; - parser = vzalloc(sizeof(struct hid_parser)); - if (!parser) { - ret = -ENOMEM; - goto alloc_err; - } - - parser->device = device; - - end = start + size; - - device->collection = kzalloc_objs(struct hid_collection, - HID_DEFAULT_NUM_COLLECTIONS); - if (!device->collection) { - ret = -ENOMEM; - goto err; - } - device->collection_size = HID_DEFAULT_NUM_COLLECTIONS; - for (i = 0; i < HID_DEFAULT_NUM_COLLECTIONS; i++) - device->collection[i].parent_idx = -1; - - ret = -EINVAL; - while ((next = fetch_item(start, end, &item)) != NULL) { - start = next; - - if (item.format != HID_ITEM_FORMAT_SHORT) { - hid_err(device, "unexpected long global item\n"); - goto err; - } - - if (dispatch_type[item.type](parser, &item)) { - hid_err(device, "item %u %u %u %u parsing failed\n", - item.format, (unsigned)item.size, - (unsigned)item.type, (unsigned)item.tag); - goto err; - } - - if (start == end) { - if (parser->collection_stack_ptr) { - hid_err(device, "unbalanced collection at end of report description\n"); - goto err; - } - if (parser->local.delimiter_depth) { - hid_err(device, "unbalanced delimiter at end of report description\n"); - goto err; - } - - /* - * fetch initial values in case the device's - * default multiplier isn't the recommended 1 - */ - hid_setup_resolution_multiplier(device); - - kfree(parser->collection_stack); - vfree(parser); - device->status |= HID_STAT_PARSED; - - return 0; - } + error = hid_parse_collections(device); + if (error) { + hid_close_report(device); + return error; } - hid_err(device, "item fetching failed at offset %u/%u\n", - size - (unsigned int)(end - start), size); -err: - kfree(parser->collection_stack); -alloc_err: - vfree(parser); - hid_close_report(device); - return ret; + return 0; } EXPORT_SYMBOL_GPL(hid_open_report); @@ -1989,11 +2000,11 @@ static struct hid_report *hid_get_report(struct hid_report_enum *report_enum, int __hid_request(struct hid_device *hid, struct hid_report *report, enum hid_class_request reqtype) { - char *buf, *data_buf; + u8 *data_buf; int ret; u32 len; - buf = hid_alloc_report_buf(report, GFP_KERNEL); + u8 *buf __free(kfree) = hid_alloc_report_buf(report, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -2012,17 +2023,13 @@ int __hid_request(struct hid_device *hid, struct hid_report *report, ret = hid_hw_raw_request(hid, report->id, buf, len, report->type, reqtype); if (ret < 0) { dbg_hid("unable to complete request: %d\n", ret); - goto out; + return ret; } if (reqtype == HID_REQ_GET_REPORT) hid_input_report(hid, report->type, buf, ret, 0); - ret = 0; - -out: - kfree(buf); - return ret; + return 0; } EXPORT_SYMBOL_GPL(__hid_request); @@ -2888,6 +2895,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; } @@ -2991,6 +3003,10 @@ struct hid_device *hid_allocate_device(void) mutex_init(&hdev->ll_open_lock); kref_init(&hdev->ref); +#ifdef CONFIG_HID_BATTERY_STRENGTH + INIT_LIST_HEAD(&hdev->batteries); +#endif + ret = hid_bpf_device_init(hdev); if (ret) goto out_err; diff --git a/drivers/hid/hid-huawei.c b/drivers/hid/hid-huawei.c new file mode 100644 index 000000000000..6a616bf21b38 --- /dev/null +++ b/drivers/hid/hid-huawei.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * HID driver for some huawei "special" devices + * + * Copyright (c) 2026 Miao Li <limiao@kylinos.cn> + */ + +#include <linux/device.h> +#include <linux/hid.h> +#include <linux/module.h> +#include <linux/usb.h> + +#include "hid-ids.h" + +static const __u8 huawei_cd30_kbd_rdesc_fixed[] = { + 0x05, 0x01, /* Usage Page (Generic Desktop) */ + 0x09, 0x80, /* Usage (System Control) */ + 0xa1, 0x01, /* Collection (Application) */ + 0x85, 0x01, /* Report ID (1) */ + 0x19, 0x81, /* Usage Minimum (System Power Down) */ + 0x29, 0x83, /* Usage Maximum (System Wake Up) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x25, 0x01, /* Logical Maximum (1) */ + 0x75, 0x01, /* Report Size (1 bit) */ + 0x95, 0x03, /* Report Count (3) */ + 0x81, 0x02, /* Input (Data,Var,Abs) */ + 0x95, 0x05, /* Report Count (5) */ + 0x81, 0x01, /* Input (Cnst,Ary,Abs) */ + 0xc0, /* End Collection */ + 0x05, 0x0c, /* Usage Page (Consumer) */ + 0x09, 0x01, /* Usage (Consumer Control) */ + 0xa1, 0x01, /* Collection (Application) */ + 0x85, 0x02, /* Report ID (2) */ + 0x19, 0x00, /* Usage Minimum (0) */ + 0x2a, 0x3c, 0x02, /* Usage Maximum (0x023C) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x26, 0x3c, 0x02, /* Logical Maximum (0x023C) */ + 0x95, 0x01, /* Report Count (1) */ + 0x75, 0x10, /* Report Size (16 bits) */ + 0x81, 0x00, /* Input (Data,Ary,Abs) */ + 0xc0 /* End Collection */ +}; + +static const __u8 *huawei_report_fixup(struct hid_device *hdev, __u8 *rdesc, + unsigned int *rsize) +{ + struct usb_interface *intf = to_usb_interface(hdev->dev.parent); + + switch (hdev->product) { + case USB_DEVICE_ID_HUAWEI_CD30KBD: + if (intf->cur_altsetting->desc.bInterfaceNumber == 1) { + if (*rsize != sizeof(huawei_cd30_kbd_rdesc_fixed) || + memcmp(huawei_cd30_kbd_rdesc_fixed, rdesc, + sizeof(huawei_cd30_kbd_rdesc_fixed)) != 0) { + hid_info(hdev, "Replacing Huawei cd30 keyboard report descriptor.\n"); + *rsize = sizeof(huawei_cd30_kbd_rdesc_fixed); + return huawei_cd30_kbd_rdesc_fixed; + } + } + break; + } + + return rdesc; +} + +static const struct hid_device_id huawei_devices[] = { + /* HUAWEI cd30 keyboard */ + { HID_USB_DEVICE(USB_VENDOR_ID_HUAWEI, USB_DEVICE_ID_HUAWEI_CD30KBD)}, + { } +}; +MODULE_DEVICE_TABLE(hid, huawei_devices); + +static struct hid_driver huawei_driver = { + .name = "huawei", + .id_table = huawei_devices, + .report_fixup = huawei_report_fixup, +}; +module_hid_driver(huawei_driver); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Miao Li <limiao@kylinos.cn>"); +MODULE_DESCRIPTION("HID driver for some huawei \"special\" devices"); diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index c1e4a6ce9631..0cf63742315b 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -667,6 +667,18 @@ #define USB_DEVICE_ID_UGCI_FLYING 0x0020 #define USB_DEVICE_ID_UGCI_FIGHTING 0x0030 +#define USB_VENDOR_ID_HARMONIX 0x1bad +#define USB_DEVICE_ID_HARMONIX_WII_RB1_GUITAR 0x0004 +#define USB_DEVICE_ID_HARMONIX_WII_RB2_GUITAR 0x3010 +#define USB_DEVICE_ID_HARMONIX_WII_RB1_DRUMS 0x0005 +#define USB_DEVICE_ID_HARMONIX_WII_RB2_DRUMS 0x3110 +#define USB_DEVICE_ID_HARMONIX_WII_RB3_MPA_DRUMS_MODE 0x3138 +#define USB_DEVICE_ID_HARMONIX_WII_RB3_MUSTANG_GUITAR 0x3430 +#define USB_DEVICE_ID_HARMONIX_WII_RB3_MPA_MUSTANG_MODE 0x3438 +#define USB_DEVICE_ID_HARMONIX_WII_RB3_MPA_SQUIER_MODE 0x3538 +#define USB_DEVICE_ID_HARMONIX_WII_RB3_KEYBOARD 0x3330 +#define USB_DEVICE_ID_HARMONIX_WII_RB3_MPA_KEYBOARD_MODE 0x3338 + #define USB_VENDOR_ID_HP 0x03f0 #define USB_PRODUCT_ID_HP_ELITE_PRESENTER_MOUSE_464A 0x464a #define USB_PRODUCT_ID_HP_LOGITECH_OEM_USB_OPTICAL_MOUSE_0A4A 0x0a4a @@ -742,6 +754,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 @@ -861,7 +877,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 @@ -1301,8 +1320,18 @@ #define USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER 0x1000 #define USB_VENDOR_ID_SONY_RHYTHM 0x12ba -#define USB_DEVICE_ID_SONY_PS3WIIU_GHLIVE_DONGLE 0x074b -#define USB_DEVICE_ID_SONY_PS3_GUITAR_DONGLE 0x0100 +#define USB_DEVICE_ID_SONY_PS3WIIU_GHLIVE 0x074b +#define USB_DEVICE_ID_SONY_PS3_GH_GUITAR 0x0100 +#define USB_DEVICE_ID_SONY_PS3_GH_DRUMS 0x0120 +#define USB_DEVICE_ID_SONY_PS3_DJH_TURNTABLE 0x0140 +#define USB_DEVICE_ID_SONY_PS3_RB_GUITAR 0x0200 +#define USB_DEVICE_ID_SONY_PS3_RB_DRUMS 0x0210 +#define USB_DEVICE_ID_SONY_PS3_RB3_MPA_DRUMS_MODE 0x0218 +#define USB_DEVICE_ID_SONY_PS3_RB3_MUSTANG_GUITAR 0x2430 +#define USB_DEVICE_ID_SONY_PS3_RB3_MPA_MUSTANG_MODE 0x2438 +#define USB_DEVICE_ID_SONY_PS3_RB3_MPA_SQUIER_MODE 0x2538 +#define USB_DEVICE_ID_SONY_PS3_RB3_KEYBOARD 0x2330 +#define USB_DEVICE_ID_SONY_PS3_RB3_MPA_KEYBOARD_MODE 0x2338 #define USB_VENDOR_ID_SINO_LITE 0x1345 #define USB_DEVICE_ID_SINO_LITE_CONTROLLER 0x3008 @@ -1587,4 +1616,7 @@ #define USB_VENDOR_ID_JIELI_SDK_DEFAULT 0x4c4a #define USB_DEVICE_ID_JIELI_SDK_4155 0x4155 +#define USB_VENDOR_ID_HUAWEI 0x12d1 +#define USB_DEVICE_ID_HUAWEI_CD30KBD 0x109b + #endif diff --git a/drivers/hid/hid-input-test.c b/drivers/hid/hid-input-test.c index 6f5c71660d82..c92008dafddf 100644 --- a/drivers/hid/hid-input-test.c +++ b/drivers/hid/hid-input-test.c @@ -9,54 +9,59 @@ static void hid_test_input_update_battery_charge_status(struct kunit *test) { - struct hid_device *dev; + struct hid_battery *bat; bool handled; - dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + bat = kunit_kzalloc(test, sizeof(*bat), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bat); - handled = hidinput_update_battery_charge_status(dev, HID_DG_HEIGHT, 0); + handled = hidinput_update_battery_charge_status(bat, HID_DG_HEIGHT, 0); KUNIT_EXPECT_FALSE(test, handled); - KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_UNKNOWN); + KUNIT_EXPECT_EQ(test, bat->charge_status, POWER_SUPPLY_STATUS_UNKNOWN); - handled = hidinput_update_battery_charge_status(dev, HID_BAT_CHARGING, 0); + handled = hidinput_update_battery_charge_status(bat, HID_BAT_CHARGING, 0); KUNIT_EXPECT_TRUE(test, handled); - KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_DISCHARGING); + KUNIT_EXPECT_EQ(test, bat->charge_status, POWER_SUPPLY_STATUS_DISCHARGING); - handled = hidinput_update_battery_charge_status(dev, HID_BAT_CHARGING, 1); + handled = hidinput_update_battery_charge_status(bat, HID_BAT_CHARGING, 1); KUNIT_EXPECT_TRUE(test, handled); - KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_CHARGING); + KUNIT_EXPECT_EQ(test, bat->charge_status, POWER_SUPPLY_STATUS_CHARGING); } static void hid_test_input_get_battery_property(struct kunit *test) { struct power_supply *psy; + struct hid_battery *bat; struct hid_device *dev; union power_supply_propval val; int ret; dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); - dev->battery_avoid_query = true; + + bat = kunit_kzalloc(test, sizeof(*bat), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bat); + bat->dev = dev; + bat->avoid_query = true; psy = kunit_kzalloc(test, sizeof(*psy), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, psy); - psy->drv_data = dev; + psy->drv_data = bat; - dev->battery_status = HID_BATTERY_UNKNOWN; - dev->battery_charge_status = POWER_SUPPLY_STATUS_CHARGING; + bat->status = HID_BATTERY_UNKNOWN; + bat->charge_status = POWER_SUPPLY_STATUS_CHARGING; ret = hidinput_get_battery_property(psy, POWER_SUPPLY_PROP_STATUS, &val); KUNIT_EXPECT_EQ(test, ret, 0); KUNIT_EXPECT_EQ(test, val.intval, POWER_SUPPLY_STATUS_UNKNOWN); - dev->battery_status = HID_BATTERY_REPORTED; - dev->battery_charge_status = POWER_SUPPLY_STATUS_CHARGING; + bat->status = HID_BATTERY_REPORTED; + bat->charge_status = POWER_SUPPLY_STATUS_CHARGING; ret = hidinput_get_battery_property(psy, POWER_SUPPLY_PROP_STATUS, &val); KUNIT_EXPECT_EQ(test, ret, 0); KUNIT_EXPECT_EQ(test, val.intval, POWER_SUPPLY_STATUS_CHARGING); - dev->battery_status = HID_BATTERY_REPORTED; - dev->battery_charge_status = POWER_SUPPLY_STATUS_DISCHARGING; + bat->status = HID_BATTERY_REPORTED; + bat->charge_status = POWER_SUPPLY_STATUS_DISCHARGING; ret = hidinput_get_battery_property(psy, POWER_SUPPLY_PROP_STATUS, &val); KUNIT_EXPECT_EQ(test, ret, 0); KUNIT_EXPECT_EQ(test, val.intval, POWER_SUPPLY_STATUS_DISCHARGING); diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index e824c793f669..d73cfa2e73d3 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -416,43 +416,39 @@ static unsigned find_battery_quirk(struct hid_device *hdev) return quirks; } -static int hidinput_scale_battery_capacity(struct hid_device *dev, +static int hidinput_scale_battery_capacity(struct hid_battery *bat, int value) { - if (dev->battery_min < dev->battery_max && - value >= dev->battery_min && value <= dev->battery_max) - value = ((value - dev->battery_min) * 100) / - (dev->battery_max - dev->battery_min); + if (bat->min < bat->max && + value >= bat->min && value <= bat->max) + value = ((value - bat->min) * 100) / + (bat->max - bat->min); return value; } -static int hidinput_query_battery_capacity(struct hid_device *dev) +static int hidinput_query_battery_capacity(struct hid_battery *bat) { - u8 *buf; int ret; - buf = kmalloc(4, GFP_KERNEL); + u8 *buf __free(kfree) = kmalloc(4, GFP_KERNEL); if (!buf) return -ENOMEM; - ret = hid_hw_raw_request(dev, dev->battery_report_id, buf, 4, - dev->battery_report_type, HID_REQ_GET_REPORT); - if (ret < 2) { - kfree(buf); + ret = hid_hw_raw_request(bat->dev, bat->report_id, buf, 4, + bat->report_type, HID_REQ_GET_REPORT); + if (ret < 2) return -ENODATA; - } - ret = hidinput_scale_battery_capacity(dev, buf[1]); - kfree(buf); - return ret; + return hidinput_scale_battery_capacity(bat, buf[1]); } static int hidinput_get_battery_property(struct power_supply *psy, enum power_supply_property prop, union power_supply_propval *val) { - struct hid_device *dev = power_supply_get_drvdata(psy); + struct hid_battery *bat = power_supply_get_drvdata(psy); + struct hid_device *dev = bat->dev; int value; int ret = 0; @@ -462,17 +458,17 @@ static int hidinput_get_battery_property(struct power_supply *psy, break; case POWER_SUPPLY_PROP_PRESENT: - val->intval = dev->battery_present; + val->intval = bat->present; break; case POWER_SUPPLY_PROP_CAPACITY: - if (dev->battery_status != HID_BATTERY_REPORTED && - !dev->battery_avoid_query) { - value = hidinput_query_battery_capacity(dev); + if (bat->status != HID_BATTERY_REPORTED && + !bat->avoid_query) { + value = hidinput_query_battery_capacity(bat); if (value < 0) return value; } else { - value = dev->battery_capacity; + value = bat->capacity; } val->intval = value; @@ -483,20 +479,20 @@ static int hidinput_get_battery_property(struct power_supply *psy, break; case POWER_SUPPLY_PROP_STATUS: - if (dev->battery_status != HID_BATTERY_REPORTED && - !dev->battery_avoid_query) { - value = hidinput_query_battery_capacity(dev); + if (bat->status != HID_BATTERY_REPORTED && + !bat->avoid_query) { + value = hidinput_query_battery_capacity(bat); if (value < 0) return value; - dev->battery_capacity = value; - dev->battery_status = HID_BATTERY_QUERIED; + bat->capacity = value; + bat->status = HID_BATTERY_QUERIED; } - if (dev->battery_status == HID_BATTERY_UNKNOWN) + if (bat->status == HID_BATTERY_UNKNOWN) val->intval = POWER_SUPPLY_STATUS_UNKNOWN; else - val->intval = dev->battery_charge_status; + val->intval = bat->charge_status; break; case POWER_SUPPLY_PROP_SCOPE: @@ -511,36 +507,59 @@ static int hidinput_get_battery_property(struct power_supply *psy, return ret; } +static struct hid_battery *hidinput_find_battery(struct hid_device *dev, + int report_id) +{ + struct hid_battery *bat; + + list_for_each_entry(bat, &dev->batteries, list) { + if (bat->report_id == report_id) + return bat; + } + return NULL; +} + static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type, struct hid_field *field, bool is_percentage) { + struct hid_battery *bat; struct power_supply_desc *psy_desc; - struct power_supply_config psy_cfg = { .drv_data = dev, }; + struct power_supply_config psy_cfg = { 0 }; unsigned quirks; s32 min, max; int error; - if (dev->battery) - return 0; /* already initialized? */ + /* Check if battery for this report ID already exists */ + if (hidinput_find_battery(dev, field->report->id)) + return 0; quirks = find_battery_quirk(dev); - hid_dbg(dev, "device %x:%x:%x %d quirks %d\n", - dev->bus, dev->vendor, dev->product, dev->version, quirks); + hid_dbg(dev, "device %x:%x:%x %d quirks %d report_id %d\n", + dev->bus, dev->vendor, dev->product, dev->version, quirks, + field->report->id); if (quirks & HID_BATTERY_QUIRK_IGNORE) return 0; - psy_desc = kzalloc_obj(*psy_desc); - if (!psy_desc) + bat = devm_kzalloc(&dev->dev, sizeof(*bat), GFP_KERNEL); + if (!bat) return -ENOMEM; - psy_desc->name = kasprintf(GFP_KERNEL, "hid-%s-battery", - strlen(dev->uniq) ? - dev->uniq : dev_name(&dev->dev)); + psy_desc = devm_kzalloc(&dev->dev, sizeof(*psy_desc), GFP_KERNEL); + if (!psy_desc) { + error = -ENOMEM; + goto err_free_bat; + } + + psy_desc->name = devm_kasprintf(&dev->dev, GFP_KERNEL, + "hid-%s-battery-%d", + strlen(dev->uniq) ? + dev->uniq : dev_name(&dev->dev), + field->report->id); if (!psy_desc->name) { error = -ENOMEM; - goto err_free_mem; + goto err_free_desc; } psy_desc->type = POWER_SUPPLY_TYPE_BATTERY; @@ -560,102 +579,95 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type, if (quirks & HID_BATTERY_QUIRK_FEATURE) report_type = HID_FEATURE_REPORT; - dev->battery_min = min; - dev->battery_max = max; - dev->battery_report_type = report_type; - dev->battery_report_id = field->report->id; - dev->battery_charge_status = POWER_SUPPLY_STATUS_DISCHARGING; + bat->dev = dev; + bat->min = min; + bat->max = max; + bat->report_type = report_type; + bat->report_id = field->report->id; + bat->charge_status = POWER_SUPPLY_STATUS_DISCHARGING; + bat->status = HID_BATTERY_UNKNOWN; /* * Stylus is normally not connected to the device and thus we * can't query the device and get meaningful battery strength. * We have to wait for the device to report it on its own. */ - dev->battery_avoid_query = report_type == HID_INPUT_REPORT && - field->physical == HID_DG_STYLUS; + bat->avoid_query = report_type == HID_INPUT_REPORT && + field->physical == HID_DG_STYLUS; if (quirks & HID_BATTERY_QUIRK_AVOID_QUERY) - dev->battery_avoid_query = true; + bat->avoid_query = true; - dev->battery_present = (quirks & HID_BATTERY_QUIRK_DYNAMIC) ? false : true; + bat->present = (quirks & HID_BATTERY_QUIRK_DYNAMIC) ? false : true; - dev->battery = power_supply_register(&dev->dev, psy_desc, &psy_cfg); - if (IS_ERR(dev->battery)) { - error = PTR_ERR(dev->battery); + psy_cfg.drv_data = bat; + bat->ps = devm_power_supply_register(&dev->dev, psy_desc, &psy_cfg); + if (IS_ERR(bat->ps)) { + error = PTR_ERR(bat->ps); hid_warn(dev, "can't register power supply: %d\n", error); goto err_free_name; } - power_supply_powers(dev->battery, &dev->dev); + power_supply_powers(bat->ps, &dev->dev); + list_add_tail(&bat->list, &dev->batteries); return 0; err_free_name: - kfree(psy_desc->name); -err_free_mem: - kfree(psy_desc); - dev->battery = NULL; + devm_kfree(&dev->dev, psy_desc->name); +err_free_desc: + devm_kfree(&dev->dev, psy_desc); +err_free_bat: + devm_kfree(&dev->dev, bat); return error; } -static void hidinput_cleanup_battery(struct hid_device *dev) -{ - const struct power_supply_desc *psy_desc; - - if (!dev->battery) - return; - - psy_desc = dev->battery->desc; - power_supply_unregister(dev->battery); - kfree(psy_desc->name); - kfree(psy_desc); - dev->battery = NULL; -} - -static bool hidinput_update_battery_charge_status(struct hid_device *dev, +static bool hidinput_update_battery_charge_status(struct hid_battery *bat, unsigned int usage, int value) { switch (usage) { case HID_BAT_CHARGING: - dev->battery_charge_status = value ? - POWER_SUPPLY_STATUS_CHARGING : - POWER_SUPPLY_STATUS_DISCHARGING; + bat->charge_status = value ? + POWER_SUPPLY_STATUS_CHARGING : + POWER_SUPPLY_STATUS_DISCHARGING; return true; } return false; } -static void hidinput_update_battery(struct hid_device *dev, unsigned int usage, - int value) +static void hidinput_update_battery(struct hid_device *dev, int report_id, + unsigned int usage, int value) { + struct hid_battery *bat; int capacity; - if (!dev->battery) + bat = hidinput_find_battery(dev, report_id); + if (!bat) return; - if (hidinput_update_battery_charge_status(dev, usage, value)) { - dev->battery_present = true; - power_supply_changed(dev->battery); + if (hidinput_update_battery_charge_status(bat, usage, value)) { + bat->present = true; + power_supply_changed(bat->ps); return; } if ((usage & HID_USAGE_PAGE) == HID_UP_DIGITIZER && value == 0) return; - if (value < dev->battery_min || value > dev->battery_max) + if (value < bat->min || value > bat->max) return; - capacity = hidinput_scale_battery_capacity(dev, value); + capacity = hidinput_scale_battery_capacity(bat, value); - if (dev->battery_status != HID_BATTERY_REPORTED || - capacity != dev->battery_capacity || - ktime_after(ktime_get_coarse(), dev->battery_ratelimit_time)) { - dev->battery_present = true; - dev->battery_capacity = capacity; - dev->battery_status = HID_BATTERY_REPORTED; - dev->battery_ratelimit_time = + if (bat->status != HID_BATTERY_REPORTED || + capacity != bat->capacity || + ktime_after(ktime_get_coarse(), bat->ratelimit_time)) { + bat->present = true; + bat->capacity = capacity; + bat->status = HID_BATTERY_REPORTED; + bat->ratelimit_time = ktime_add_ms(ktime_get_coarse(), 30 * 1000); - power_supply_changed(dev->battery); + power_supply_changed(bat->ps); } } #else /* !CONFIG_HID_BATTERY_STRENGTH */ @@ -665,12 +677,8 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type, return 0; } -static void hidinput_cleanup_battery(struct hid_device *dev) -{ -} - -static void hidinput_update_battery(struct hid_device *dev, unsigned int usage, - int value) +static void hidinput_update_battery(struct hid_device *dev, int report_id, + unsigned int usage, int value) { } #endif /* CONFIG_HID_BATTERY_STRENGTH */ @@ -1557,7 +1565,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct return; if (usage->type == EV_PWR) { - hidinput_update_battery(hid, usage->hid, value); + hidinput_update_battery(hid, report->id, usage->hid, value); return; } @@ -1839,7 +1847,6 @@ static void hidinput_led_worker(struct work_struct *work) struct hid_report *report; int ret; u32 len; - __u8 *buf; field = hidinput_get_led_field(hid); if (!field) @@ -1866,7 +1873,7 @@ static void hidinput_led_worker(struct work_struct *work) /* fall back to generic raw-output-report */ len = hid_report_len(report); - buf = hid_alloc_report_buf(report, GFP_KERNEL); + u8 *buf __free(kfree) = hid_alloc_report_buf(report, GFP_KERNEL); if (!buf) return; @@ -1876,7 +1883,6 @@ static void hidinput_led_worker(struct work_struct *work) if (ret == -ENOSYS) hid_hw_raw_request(hid, report->id, buf, len, HID_OUTPUT_REPORT, HID_REQ_SET_REPORT); - kfree(buf); } static int hidinput_input_event(struct input_dev *dev, unsigned int type, @@ -2403,8 +2409,6 @@ void hidinput_disconnect(struct hid_device *hid) { struct hid_input *hidinput, *next; - hidinput_cleanup_battery(hid); - list_for_each_entry_safe(hidinput, next, &hid->inputs, list) { list_del(&hidinput->list); if (hidinput->registered) diff --git a/drivers/hid/hid-lenovo-go-s.c b/drivers/hid/hid-lenovo-go-s.c new file mode 100644 index 000000000000..01c7bdd4fbe0 --- /dev/null +++ b/drivers/hid/hid-lenovo-go-s.c @@ -0,0 +1,1504 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * HID driver for Lenovo Legion Go S devices. + * + * Copyright (c) 2026 Derek J. Clark <derekjohn.clark@gmail.com> + * Copyright (c) 2026 Valve Corporation + */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include <linux/array_size.h> +#include <linux/cleanup.h> +#include <linux/completion.h> +#include <linux/delay.h> +#include <linux/dev_printk.h> +#include <linux/device.h> +#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> +#include <linux/sysfs.h> +#include <linux/types.h> +#include <linux/unaligned.h> +#include <linux/usb.h> +#include <linux/workqueue.h> +#include <linux/workqueue_types.h> + +#include "hid-ids.h" + +#define GO_S_CFG_INTF_IN 0x84 +#define GO_S_PACKET_SIZE 64 + +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; + u8 gp_dpad_mode; + 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; + 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; + u8 tp_version; + u8 tp_manufacturer; +} drvdata; + +struct gos_cfg_attr { + u8 index; +}; + +struct command_report { + u8 cmd; + u8 sub_cmd; + u8 data[63]; +} __packed; + +struct version_report { + u8 cmd; + u32 version; + u8 reserved[59]; +} __packed; + +enum mcu_command_index { + GET_VERSION = 0x01, + GET_MCU_ID, + GET_GAMEPAD_CFG, + SET_GAMEPAD_CFG, + GET_TP_PARAM, + SET_TP_PARAM, + GET_RGB_CFG = 0x0f, + SET_RGB_CFG, + GET_PL_TEST = 0xdf, +}; + +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", +}; + +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, + +}; + +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, +}; + +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; + + drvdata.hdev->firmware_version = get_unaligned_le32(&ver_rep->version); + 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 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_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_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; + 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) + return -EIO; + + return 0; +} + +static int get_endpoint_address(struct hid_device *hdev) +{ + struct usb_interface *intf = to_usb_interface(hdev->dev.parent); + struct usb_host_endpoint *ep; + + if (intf) { + ep = intf->cur_altsetting->endpoint; + if (ep) + return ep->desc.bEndpointAddress; + } + + return -ENODEV; +} + +static int hid_gos_raw_event(struct hid_device *hdev, struct hid_report *report, + u8 *data, int size) +{ + struct command_report *cmd_rep; + int ep, ret; + + ep = get_endpoint_address(hdev); + if (ep != GO_S_CFG_INTF_IN) + return 0; + + if (size != GO_S_PACKET_SIZE) + return -EINVAL; + + cmd_rep = (struct command_report *)data; + + switch (cmd_rep->cmd) { + case GET_VERSION: + ret = hid_gos_version_event(data); + break; + 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 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; + case SET_GAMEPAD_CFG: + case SET_RGB_CFG: + case SET_TP_PARAM: + ret = hid_gos_set_event_return(cmd_rep); + break; + default: + ret = -EINVAL; + break; + } + dev_dbg(&hdev->dev, "Rx data as raw input report: [%*ph]\n", + GO_S_PACKET_SIZE, data); + + complete(&drvdata.send_cmd_complete); + return ret; +} + +static int mcu_property_out(struct hid_device *hdev, u8 command, u8 index, + u8 *data, size_t len) +{ + unsigned char *dmabuf __free(kfree) = NULL; + u8 header[] = { command, index }; + size_t header_size = ARRAY_SIZE(header); + int timeout, ret; + + if (header_size + len > GO_S_PACKET_SIZE) + return -EINVAL; + + guard(mutex)(&drvdata.cfg_mutex); + /* We can't use a devm_alloc reusable buffer without side effects during suspend */ + dmabuf = kzalloc(GO_S_PACKET_SIZE, GFP_KERNEL); + if (!dmabuf) + return -ENOMEM; + + memcpy(dmabuf, header, header_size); + memcpy(dmabuf + header_size, data, len); + + dev_dbg(&hdev->dev, "Send data as raw output report: [%*ph]\n", + GO_S_PACKET_SIZE, dmabuf); + + ret = hid_hw_output_report(hdev, dmabuf, GO_S_PACKET_SIZE); + if (ret < 0) + return ret; + + ret = ret == GO_S_PACKET_SIZE ? 0 : -EINVAL; + if (ret) + return ret; + + /* PL_TEST commands can take longer because they go out to another device */ + timeout = (command == GET_PL_TEST) ? 200 : 5; + ret = wait_for_completion_interruptible_timeout(&drvdata.send_cmd_complete, + msecs_to_jiffies(timeout)); + + if (ret == 0) /* timeout occurred */ + ret = -EBUSY; + + reinit_completion(&drvdata.send_cmd_complete); + 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 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 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) +{ + 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, \ + 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_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"); + +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, +}; + +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, +}; + +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 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"); + +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_manufacturer.attr, + &dev_attr_touchpad_version.attr, + &dev_attr_touchpad_windows_mode.attr, + &dev_attr_touchpad_windows_mode_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, +}; + +/* 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; + + /* 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); + 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, + const struct hid_device_id *_id) +{ + int ret; + + hid_set_drvdata(hdev, &drvdata); + 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; + } + + 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 configuration 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 + * initial data call after probe has completed and MCU can accept calls. + */ + INIT_DELAYED_WORK(&drvdata.gos_cfg_setup, &cfg_setup); + ret = schedule_delayed_work(&drvdata.gos_cfg_setup, msecs_to_jiffies(2)); + if (!ret) { + dev_err(&hdev->dev, "Failed to schedule startup delayed work\n"); + return -ENODEV; + } + + return 0; +} + +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); +} + +static int hid_gos_probe(struct hid_device *hdev, + const struct hid_device_id *id) +{ + int ret, ep; + + ret = hid_parse(hdev); + if (ret) { + hid_err(hdev, "Parse failed\n"); + return ret; + } + + ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); + if (ret) { + hid_err(hdev, "Failed to start HID device\n"); + return ret; + } + + ret = hid_hw_open(hdev); + if (ret) { + hid_err(hdev, "Failed to open HID device\n"); + hid_hw_stop(hdev); + return ret; + } + + ep = get_endpoint_address(hdev); + if (ep != GO_S_CFG_INTF_IN) { + dev_dbg(&hdev->dev, "Started interface %x as generic HID device.\n", ep); + return 0; + } + + ret = hid_gos_cfg_probe(hdev, id); + if (ret) + dev_err_probe(&hdev->dev, ret, "Failed to start configuration interface"); + + dev_dbg(&hdev->dev, "Started interface %x as Go S configuration interface\n", ep); + return ret; +} + +static void hid_gos_remove(struct hid_device *hdev) +{ + int ep = get_endpoint_address(hdev); + + switch (ep) { + case GO_S_CFG_INTF_IN: + hid_gos_cfg_remove(hdev); + break; + default: + hid_hw_close(hdev); + hid_hw_stop(hdev); + + break; + } +} + +static const struct hid_device_id hid_gos_devices[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_QHE, + USB_DEVICE_ID_LENOVO_LEGION_GO_S_XINPUT) }, + { HID_USB_DEVICE(USB_VENDOR_ID_QHE, + USB_DEVICE_ID_LENOVO_LEGION_GO_S_DINPUT) }, + {} +}; + +MODULE_DEVICE_TABLE(hid, hid_gos_devices); +static struct hid_driver hid_lenovo_go_s = { + .name = "hid-lenovo-go-s", + .id_table = hid_gos_devices, + .probe = hid_gos_probe, + .remove = hid_gos_remove, + .raw_event = hid_gos_raw_event, +}; +module_hid_driver(hid_lenovo_go_s); + +MODULE_AUTHOR("Derek J. Clark"); +MODULE_DESCRIPTION("HID Driver for Lenovo Legion Go S Series gamepad."); +MODULE_LICENSE("GPL"); diff --git a/drivers/hid/hid-lenovo-go.c b/drivers/hid/hid-lenovo-go.c new file mode 100644 index 000000000000..d4d26c783356 --- /dev/null +++ b/drivers/hid/hid-lenovo-go.c @@ -0,0 +1,2500 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * HID driver for Lenovo Legion Go series gamepads. + * + * Copyright (c) 2026 Derek J. Clark <derekjohn.clark@gmail.com> + * Copyright (c) 2026 Valve Corporation + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include <linux/array_size.h> +#include <linux/cleanup.h> +#include <linux/completion.h> +#include <linux/delay.h> +#include <linux/dev_printk.h> +#include <linux/device.h> +#include <linux/device/devres.h> +#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> +#include <linux/types.h> +#include <linux/unaligned.h> +#include <linux/usb.h> +#include <linux/workqueue.h> +#include <linux/workqueue_types.h> + +#include "hid-ids.h" + +#define GO_GP_INTF_IN 0x83 +#define GO_OUTPUT_REPORT_ID 0x05 +#define GO_GP_RESET_SUCCESS 0x01 +#define GO_PACKET_SIZE 64 + +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; + 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; + u32 gp_left_version_product; + 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; + 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; + 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; + u32 mouse_dpi; + u8 os_mode; + 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; + u32 tx_dongle_version_firmware; + u8 tx_dongle_version_gen; + u32 tx_dongle_version_hardware; + u32 tx_dongle_version_product; + u32 tx_dongle_version_protocol; +} drvdata; + +struct go_cfg_attr { + u8 index; +}; + +struct command_report { + u8 report_id; + u8 id; + u8 cmd; + u8 sub_cmd; + u8 device_type; + u8 data[59]; +} __packed; + +enum command_id { + MCU_CONFIG_DATA = 0x00, + OS_MODE_DATA = 0x06, + GAMEPAD_DATA = 0x3c, +}; + +enum mcu_command_index { + GET_VERSION_DATA = 0x02, + GET_FEATURE_STATUS, + SET_FEATURE_STATUS, + GET_MOTOR_CFG, + SET_MOTOR_CFG, + GET_DPI_CFG, + SET_DPI_CFG, + SET_TRIGGER_CFG = 0x0a, + SET_JOYSTICK_CFG = 0x0c, + SET_GYRO_CFG = 0x0e, + GET_RGB_CFG, + SET_RGB_CFG, + GET_DEVICE_STATUS = 0xa0, + +}; + +enum dev_type { + UNSPECIFIED, + USB_MCU, + TX_DONGLE, + LEFT_CONTROLLER, + 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, + FIRMWARE_VERSION, + HARDWARE_VERSION, + 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, +}; + +#define FEATURE_OS_MODE 0x69 + +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", +}; + +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", +}; + +#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, + 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", +}; + +enum device_status_index { + GET_CAL_STATUS = 0x02, + GET_UPGRADE_STATUS, + GET_MACRO_REC_STATUS, + 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) { + case PRODUCT_VERSION: + switch (cmd_rep->device_type) { + case USB_MCU: + drvdata.mcu_version_product = + get_unaligned_be32(cmd_rep->data); + return 0; + case TX_DONGLE: + drvdata.tx_dongle_version_product = + get_unaligned_be32(cmd_rep->data); + return 0; + case LEFT_CONTROLLER: + drvdata.gp_left_version_product = + get_unaligned_be32(cmd_rep->data); + return 0; + case RIGHT_CONTROLLER: + drvdata.gp_right_version_product = + get_unaligned_be32(cmd_rep->data); + return 0; + default: + return -EINVAL; + } + case PROTOCOL_VERSION: + switch (cmd_rep->device_type) { + case USB_MCU: + drvdata.mcu_version_protocol = + get_unaligned_be32(cmd_rep->data); + return 0; + case TX_DONGLE: + drvdata.tx_dongle_version_protocol = + get_unaligned_be32(cmd_rep->data); + return 0; + case LEFT_CONTROLLER: + drvdata.gp_left_version_protocol = + get_unaligned_be32(cmd_rep->data); + return 0; + case RIGHT_CONTROLLER: + drvdata.gp_right_version_protocol = + get_unaligned_be32(cmd_rep->data); + return 0; + default: + return -EINVAL; + } + case FIRMWARE_VERSION: + switch (cmd_rep->device_type) { + case USB_MCU: + drvdata.mcu_version_firmware = + get_unaligned_be32(cmd_rep->data); + return 0; + case TX_DONGLE: + drvdata.tx_dongle_version_firmware = + get_unaligned_be32(cmd_rep->data); + return 0; + case LEFT_CONTROLLER: + drvdata.gp_left_version_firmware = + get_unaligned_be32(cmd_rep->data); + return 0; + case RIGHT_CONTROLLER: + drvdata.gp_right_version_firmware = + get_unaligned_be32(cmd_rep->data); + return 0; + default: + return -EINVAL; + } + case HARDWARE_VERSION: + switch (cmd_rep->device_type) { + case USB_MCU: + drvdata.mcu_version_hardware = + get_unaligned_be32(cmd_rep->data); + return 0; + case TX_DONGLE: + drvdata.tx_dongle_version_hardware = + get_unaligned_be32(cmd_rep->data); + return 0; + case LEFT_CONTROLLER: + drvdata.gp_left_version_hardware = + get_unaligned_be32(cmd_rep->data); + return 0; + case RIGHT_CONTROLLER: + drvdata.gp_right_version_hardware = + get_unaligned_be32(cmd_rep->data); + return 0; + default: + return -EINVAL; + } + case HARDWARE_GENERATION: + switch (cmd_rep->device_type) { + case USB_MCU: + drvdata.mcu_version_gen = cmd_rep->data[0]; + return 0; + case TX_DONGLE: + drvdata.tx_dongle_version_gen = cmd_rep->data[0]; + return 0; + case LEFT_CONTROLLER: + drvdata.gp_left_version_gen = cmd_rep->data[0]; + return 0; + case RIGHT_CONTROLLER: + drvdata.gp_right_version_gen = cmd_rep->data[0]; + return 0; + default: + return -EINVAL; + } + default: + return -EINVAL; + } +} + +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_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_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_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_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_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) + return -EIO; + + return 0; +} + +static int get_endpoint_address(struct hid_device *hdev) +{ + struct usb_interface *intf = to_usb_interface(hdev->dev.parent); + struct usb_host_endpoint *ep; + + if (!intf) + return -ENODEV; + + ep = intf->cur_altsetting->endpoint; + if (!ep) + return -ENODEV; + + return ep->desc.bEndpointAddress; +} + +static int hid_go_raw_event(struct hid_device *hdev, struct hid_report *report, + u8 *data, int size) +{ + struct command_report *cmd_rep; + int ep, ret; + + if (size != GO_PACKET_SIZE) + goto passthrough; + + ep = get_endpoint_address(hdev); + if (ep != GO_GP_INTF_IN) + goto passthrough; + + cmd_rep = (struct command_report *)data; + + switch (cmd_rep->id) { + case MCU_CONFIG_DATA: + switch (cmd_rep->cmd) { + 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 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 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: + 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); + + complete(&drvdata.send_cmd_complete); + return ret; + +passthrough: + /* Forward other HID reports so they generate events */ + hid_input_report(hdev, HID_INPUT_REPORT, data, size, 1); + return 0; +} + +static int mcu_property_out(struct hid_device *hdev, u8 id, u8 command, + u8 index, enum dev_type device, u8 *data, size_t len) +{ + unsigned char *dmabuf __free(kfree) = NULL; + u8 header[] = { GO_OUTPUT_REPORT_ID, id, command, index, device }; + size_t header_size = ARRAY_SIZE(header); + int timeout = 50; + int ret; + + if (header_size + len > GO_PACKET_SIZE) + return -EINVAL; + + guard(mutex)(&drvdata.cfg_mutex); + /* We can't use a devm_alloc reusable buffer without side effects during suspend */ + dmabuf = kzalloc(GO_PACKET_SIZE, GFP_KERNEL); + if (!dmabuf) + return -ENOMEM; + + memcpy(dmabuf, header, header_size); + memcpy(dmabuf + header_size, data, len); + + dev_dbg(&hdev->dev, "Send data as raw output report: [%*ph]\n", + GO_PACKET_SIZE, dmabuf); + + ret = hid_hw_output_report(hdev, dmabuf, GO_PACKET_SIZE); + if (ret < 0) + return ret; + + ret = ret == GO_PACKET_SIZE ? 0 : -EINVAL; + if (ret) + return ret; + + ret = wait_for_completion_interruptible_timeout(&drvdata.send_cmd_complete, + msecs_to_jiffies(timeout)); + + if (ret == 0) /* timeout occurred */ + ret = -EBUSY; + + reinit_completion(&drvdata.send_cmd_complete); + return 0; +} + +static ssize_t version_show(struct device *dev, struct device_attribute *attr, + char *buf, enum version_data_index index, + 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: + switch (device_type) { + case USB_MCU: + count = sysfs_emit(buf, "%x\n", + drvdata.mcu_version_product); + break; + case TX_DONGLE: + count = sysfs_emit(buf, "%x\n", + drvdata.tx_dongle_version_product); + break; + case LEFT_CONTROLLER: + count = sysfs_emit(buf, "%x\n", + drvdata.gp_left_version_product); + break; + case RIGHT_CONTROLLER: + count = sysfs_emit(buf, "%x\n", + drvdata.gp_right_version_product); + break; + default: + return -EINVAL; + } + break; + case PROTOCOL_VERSION: + switch (device_type) { + case USB_MCU: + count = sysfs_emit(buf, "%x\n", + drvdata.mcu_version_protocol); + break; + case TX_DONGLE: + count = sysfs_emit(buf, "%x\n", + drvdata.tx_dongle_version_protocol); + break; + case LEFT_CONTROLLER: + count = sysfs_emit(buf, "%x\n", + drvdata.gp_left_version_protocol); + break; + case RIGHT_CONTROLLER: + count = sysfs_emit(buf, "%x\n", + drvdata.gp_right_version_protocol); + break; + default: + return -EINVAL; + } + break; + case FIRMWARE_VERSION: + switch (device_type) { + case USB_MCU: + count = sysfs_emit(buf, "%x\n", + drvdata.mcu_version_firmware); + break; + case TX_DONGLE: + count = sysfs_emit(buf, "%x\n", + drvdata.tx_dongle_version_firmware); + break; + case LEFT_CONTROLLER: + count = sysfs_emit(buf, "%x\n", + drvdata.gp_left_version_firmware); + break; + case RIGHT_CONTROLLER: + count = sysfs_emit(buf, "%x\n", + drvdata.gp_right_version_firmware); + break; + default: + return -EINVAL; + } + break; + case HARDWARE_VERSION: + switch (device_type) { + case USB_MCU: + count = sysfs_emit(buf, "%x\n", + drvdata.mcu_version_hardware); + break; + case TX_DONGLE: + count = sysfs_emit(buf, "%x\n", + drvdata.tx_dongle_version_hardware); + break; + case LEFT_CONTROLLER: + count = sysfs_emit(buf, "%x\n", + drvdata.gp_left_version_hardware); + break; + case RIGHT_CONTROLLER: + count = sysfs_emit(buf, "%x\n", + drvdata.gp_right_version_hardware); + break; + default: + return -EINVAL; + } + break; + case HARDWARE_GENERATION: + switch (device_type) { + case USB_MCU: + count = sysfs_emit(buf, "%x\n", + drvdata.mcu_version_gen); + break; + case TX_DONGLE: + count = sysfs_emit(buf, "%x\n", + drvdata.tx_dongle_version_gen); + break; + case LEFT_CONTROLLER: + count = sysfs_emit(buf, "%x\n", + drvdata.gp_left_version_gen); + break; + case RIGHT_CONTROLLER: + count = sysfs_emit(buf, "%x\n", + drvdata.gp_right_version_gen); + break; + default: + return -EINVAL; + } + break; + } + + 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; +} + +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; +} + +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"); +} + +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 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) +{ + 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, \ + const char *buf, size_t count) \ + { \ + return _group##_store(dev, attr, buf, count, _name.index, \ + _dtype); \ + } \ + static ssize_t _name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ + { \ + return _group##_show(dev, attr, buf, _name.index, _dtype); \ + } \ + static ssize_t _name##_##_rtype##_show( \ + struct device *dev, struct device_attribute *attr, char *buf) \ + { \ + return _group##_options(dev, attr, buf, _name.index); \ + } \ + static DEVICE_ATTR_RW_NAMED(_name, _attrname) + +#define LEGO_DEVICE_ATTR_WO(_name, _attrname, _dtype, _group) \ + static ssize_t _name##_store(struct device *dev, \ + struct device_attribute *attr, \ + const char *buf, size_t count) \ + { \ + return _group##_store(dev, attr, buf, count, _name.index, \ + _dtype); \ + } \ + static DEVICE_ATTR_WO_NAMED(_name, _attrname) + +#define LEGO_DEVICE_ATTR_RO(_name, _attrname, _dtype, _group) \ + static ssize_t _name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ + { \ + return _group##_show(dev, attr, buf, _name.index, _dtype); \ + } \ + 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); + +static struct go_cfg_attr version_protocol_mcu = { PROTOCOL_VERSION }; +LEGO_DEVICE_ATTR_RO(version_protocol_mcu, "protocol_version", USB_MCU, version); + +static struct go_cfg_attr version_firmware_mcu = { FIRMWARE_VERSION }; +LEGO_DEVICE_ATTR_RO(version_firmware_mcu, "firmware_version", USB_MCU, version); + +static struct go_cfg_attr version_hardware_mcu = { HARDWARE_VERSION }; +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 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 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, + &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_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, + &dev_attr_version_hardware_mcu.attr, + &dev_attr_version_product_mcu.attr, + &dev_attr_version_protocol_mcu.attr, + NULL, +}; + +static const struct attribute_group mcu_attr_group = { + .attrs = mcu_attrs, +}; + +/* Gamepad - TX Dongle */ +static struct go_cfg_attr version_product_tx_dongle = { PRODUCT_VERSION }; +LEGO_DEVICE_ATTR_RO(version_product_tx_dongle, "product_version", TX_DONGLE, version); + +static struct go_cfg_attr version_protocol_tx_dongle = { PROTOCOL_VERSION }; +LEGO_DEVICE_ATTR_RO(version_protocol_tx_dongle, "protocol_version", TX_DONGLE, version); + +static struct go_cfg_attr version_firmware_tx_dongle = { FIRMWARE_VERSION }; +LEGO_DEVICE_ATTR_RO(version_firmware_tx_dongle, "firmware_version", TX_DONGLE, version); + +static struct go_cfg_attr version_hardware_tx_dongle = { HARDWARE_VERSION }; +LEGO_DEVICE_ATTR_RO(version_hardware_tx_dongle, "hardware_version", TX_DONGLE, version); + +static 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, + &dev_attr_version_product_tx_dongle.attr, + &dev_attr_version_protocol_tx_dongle.attr, + NULL, +}; + +static const struct attribute_group tx_dongle_attr_group = { + .name = "tx_dongle", + .attrs = tx_dongle_attrs, +}; + +/* Gamepad - Left */ +static struct go_cfg_attr version_product_left = { PRODUCT_VERSION }; +LEGO_DEVICE_ATTR_RO(version_product_left, "product_version", LEFT_CONTROLLER, version); + +static struct go_cfg_attr version_protocol_left = { PROTOCOL_VERSION }; +LEGO_DEVICE_ATTR_RO(version_protocol_left, "protocol_version", LEFT_CONTROLLER, version); + +static struct go_cfg_attr version_firmware_left = { FIRMWARE_VERSION }; +LEGO_DEVICE_ATTR_RO(version_firmware_left, "firmware_version", LEFT_CONTROLLER, version); + +static struct go_cfg_attr version_hardware_left = { HARDWARE_VERSION }; +LEGO_DEVICE_ATTR_RO(version_hardware_left, "hardware_version", LEFT_CONTROLLER, version); + +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 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 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, + &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, + &dev_attr_version_product_left.attr, + &dev_attr_version_protocol_left.attr, + NULL, +}; + +static const struct attribute_group left_gamepad_attr_group = { + .name = "left_handle", + .attrs = left_gamepad_attrs, +}; + +/* Gamepad - Right */ +static struct go_cfg_attr version_product_right = { PRODUCT_VERSION }; +LEGO_DEVICE_ATTR_RO(version_product_right, "product_version", RIGHT_CONTROLLER, version); + +static struct go_cfg_attr version_protocol_right = { PROTOCOL_VERSION }; +LEGO_DEVICE_ATTR_RO(version_protocol_right, "protocol_version", RIGHT_CONTROLLER, version); + +static struct go_cfg_attr version_firmware_right = { FIRMWARE_VERSION }; +LEGO_DEVICE_ATTR_RO(version_firmware_right, "firmware_version", RIGHT_CONTROLLER, version); + +static struct go_cfg_attr version_hardware_right = { HARDWARE_VERSION }; +LEGO_DEVICE_ATTR_RO(version_hardware_right, "hardware_version", RIGHT_CONTROLLER, version); + +static 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 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 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, + &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, + &dev_attr_version_product_right.attr, + &dev_attr_version_protocol_right.attr, + NULL, +}; + +static const struct attribute_group right_gamepad_attr_group = { + .name = "right_handle", + .attrs = right_gamepad_attrs, +}; + +/* 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 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 = { + .name = "touchpad", + .attrs = touchpad_attrs, +}; + +static const struct attribute_group *top_level_attr_groups[] = { + &mcu_attr_group, &tx_dongle_attr_group, + &left_gamepad_attr_group, &right_gamepad_attr_group, + &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; + + /* MCU Version Attrs */ + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + PRODUCT_VERSION, USB_MCU, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve USB_MCU Product Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + PROTOCOL_VERSION, USB_MCU, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve USB_MCU Protocol Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + FIRMWARE_VERSION, USB_MCU, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve USB_MCU Firmware Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + HARDWARE_VERSION, USB_MCU, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve USB_MCU Hardware Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + HARDWARE_GENERATION, USB_MCU, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve USB_MCU Hardware Generation: %i\n", ret); + return; + } + + /* TX Dongle Version Attrs */ + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + PRODUCT_VERSION, TX_DONGLE, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve TX_DONGLE Product Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + PROTOCOL_VERSION, TX_DONGLE, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve TX_DONGLE Protocol Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + FIRMWARE_VERSION, TX_DONGLE, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve TX_DONGLE Firmware Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + HARDWARE_VERSION, TX_DONGLE, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve TX_DONGLE Hardware Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + HARDWARE_GENERATION, TX_DONGLE, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve TX_DONGLE Hardware Generation: %i\n", ret); + return; + } + + /* Left Handle Version Attrs */ + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + PRODUCT_VERSION, LEFT_CONTROLLER, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve LEFT_CONTROLLER Product Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + PROTOCOL_VERSION, LEFT_CONTROLLER, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve LEFT_CONTROLLER Protocol Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + FIRMWARE_VERSION, LEFT_CONTROLLER, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve LEFT_CONTROLLER Firmware Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + HARDWARE_VERSION, LEFT_CONTROLLER, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve LEFT_CONTROLLER Hardware Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + HARDWARE_GENERATION, LEFT_CONTROLLER, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve LEFT_CONTROLLER Hardware Generation: %i\n", ret); + return; + } + + /* Right Handle Version Attrs */ + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + PRODUCT_VERSION, RIGHT_CONTROLLER, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve RIGHT_CONTROLLER Product Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + PROTOCOL_VERSION, RIGHT_CONTROLLER, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve RIGHT_CONTROLLER Protocol Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + FIRMWARE_VERSION, RIGHT_CONTROLLER, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve RIGHT_CONTROLLER Firmware Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + HARDWARE_VERSION, RIGHT_CONTROLLER, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve RIGHT_CONTROLLER Hardware Version: %i\n", ret); + return; + } + + ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_VERSION_DATA, + HARDWARE_GENERATION, RIGHT_CONTROLLER, NULL, 0); + if (ret < 0) { + dev_err(&drvdata.hdev->dev, + "Failed to retrieve RIGHT_CONTROLLER Hardware Generation: %i\n", ret); + return; + } +} + +static int hid_go_cfg_probe(struct hid_device *hdev, + const struct hid_device_id *_id) +{ + unsigned char *buf; + int ret; + + buf = devm_kzalloc(&hdev->dev, GO_PACKET_SIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + hid_set_drvdata(hdev, &drvdata); + 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; + } + + 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 + * initial data call after probe has completed and MCU can accept calls. + */ + INIT_DELAYED_WORK(&drvdata.go_cfg_setup, &cfg_setup); + ret = schedule_delayed_work(&drvdata.go_cfg_setup, msecs_to_jiffies(2)); + if (!ret) { + dev_err(&hdev->dev, + "Failed to schedule startup delayed work\n"); + return -ENODEV; + } + return 0; +} + +static void hid_go_cfg_remove(struct hid_device *hdev) +{ + guard(mutex)(&drvdata.cfg_mutex); + sysfs_remove_groups(&hdev->dev.kobj, top_level_attr_groups); + hid_hw_close(hdev); + hid_hw_stop(hdev); + hid_set_drvdata(hdev, NULL); +} + +static int hid_go_probe(struct hid_device *hdev, const struct hid_device_id *id) +{ + int ret, ep; + + hdev->quirks |= HID_QUIRK_INPUT_PER_APP | HID_QUIRK_MULTI_INPUT; + + ret = hid_parse(hdev); + if (ret) { + hid_err(hdev, "Parse failed\n"); + return ret; + } + + ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); + if (ret) { + hid_err(hdev, "Failed to start HID device\n"); + return ret; + } + + ret = hid_hw_open(hdev); + if (ret) { + hid_err(hdev, "Failed to open HID device\n"); + hid_hw_stop(hdev); + return ret; + } + + ep = get_endpoint_address(hdev); + if (ep != GO_GP_INTF_IN) { + dev_dbg(&hdev->dev, "Started interface %x as generic HID device\n", ep); + return 0; + } + + ret = hid_go_cfg_probe(hdev, id); + if (ret) + dev_err_probe(&hdev->dev, ret, "Failed to start configuration interface\n"); + + dev_dbg(&hdev->dev, "Started Legion Go HID Device: %x\n", ep); + + return ret; +} + +static void hid_go_remove(struct hid_device *hdev) +{ + int ep = get_endpoint_address(hdev); + + if (ep <= 0) + return; + + switch (ep) { + case GO_GP_INTF_IN: + hid_go_cfg_remove(hdev); + break; + default: + hid_hw_close(hdev); + hid_hw_stop(hdev); + break; + } +} + +static const struct hid_device_id hid_go_devices[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, + USB_DEVICE_ID_LENOVO_LEGION_GO2_XINPUT) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, + USB_DEVICE_ID_LENOVO_LEGION_GO2_DINPUT) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, + USB_DEVICE_ID_LENOVO_LEGION_GO2_DUAL_DINPUT) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, + USB_DEVICE_ID_LENOVO_LEGION_GO2_FPS) }, + {} +}; +MODULE_DEVICE_TABLE(hid, hid_go_devices); + +static struct hid_driver hid_lenovo_go = { + .name = "hid-lenovo-go", + .id_table = hid_go_devices, + .probe = hid_go_probe, + .remove = hid_go_remove, + .raw_event = hid_go_raw_event, +}; +module_hid_driver(hid_lenovo_go); + +MODULE_AUTHOR("Derek J. Clark"); +MODULE_DESCRIPTION("HID Driver for Lenovo Legion Go Series Gamepads."); +MODULE_LICENSE("GPL"); diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c index d9b6c72fc254..381e4dc5aba7 100644 --- a/drivers/hid/hid-logitech-dj.c +++ b/drivers/hid/hid-logitech-dj.c @@ -1858,7 +1858,8 @@ static int logi_dj_raw_event(struct hid_device *hdev, static int logi_dj_probe(struct hid_device *hdev, const struct hid_device_id *id) { - struct hid_report_enum *rep_enum; + struct hid_report_enum *input_report_enum; + struct hid_report_enum *output_report_enum; struct hid_report *rep; struct dj_receiver_dev *djrcv_dev; struct usb_interface *intf; @@ -1903,10 +1904,20 @@ static int logi_dj_probe(struct hid_device *hdev, } } - rep_enum = &hdev->report_enum[HID_INPUT_REPORT]; + output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT]; + rep = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT]; + + if (rep && (rep->maxfield < 1 || + rep->field[0]->report_count != DJREPORT_SHORT_LENGTH - 1)) { + hid_err(hdev, "Expected size of DJ short report is %d, but got %d", + DJREPORT_SHORT_LENGTH - 1, rep->field[0]->report_count); + return -EINVAL; + } + + input_report_enum = &hdev->report_enum[HID_INPUT_REPORT]; /* no input reports, bail out */ - if (list_empty(&rep_enum->report_list)) + if (list_empty(&input_report_enum->report_list)) return -ENODEV; /* @@ -1914,7 +1925,7 @@ static int logi_dj_probe(struct hid_device *hdev, * Note: we should theoretically check for HID++ and DJ * collections, but this will do. */ - list_for_each_entry(rep, &rep_enum->report_list, list) { + list_for_each_entry(rep, &input_report_enum->report_list, list) { if (rep->application == 0xff000001) has_hidpp = true; } @@ -1927,7 +1938,7 @@ static int logi_dj_probe(struct hid_device *hdev, return -ENODEV; /* get the current application attached to the node */ - rep = list_first_entry(&rep_enum->report_list, struct hid_report, list); + rep = list_first_entry(&input_report_enum->report_list, struct hid_report, list); djrcv_dev = dj_get_receiver_dev(hdev, id->driver_data, rep->application, has_hidpp); if (!djrcv_dev) { @@ -1935,7 +1946,7 @@ static int logi_dj_probe(struct hid_device *hdev, return -ENOMEM; } - if (!rep_enum->numbered) + if (!input_report_enum->numbered) djrcv_dev->unnumbered_application = rep->application; /* Starts the usb device and connects to upper interfaces hiddev and diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index d1dea7297712..b1330d23bd2d 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -306,21 +306,22 @@ static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp, if (ret) { dbg_hid("__hidpp_send_report returned err: %d\n", ret); memset(response, 0, sizeof(struct hidpp_report)); - return ret; + goto out; } if (!wait_event_timeout(hidpp->wait, hidpp->answer_available, 5*HZ)) { dbg_hid("%s:timeout waiting for response\n", __func__); memset(response, 0, sizeof(struct hidpp_report)); - return -ETIMEDOUT; + ret = -ETIMEDOUT; + goto out; } if (response->report_id == REPORT_ID_HIDPP_SHORT && response->rap.sub_id == HIDPP_ERROR) { ret = response->rap.params[1]; dbg_hid("%s:got hidpp error %02X\n", __func__, ret); - return ret; + goto out; } if ((response->report_id == REPORT_ID_HIDPP_LONG || @@ -328,10 +329,14 @@ static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp, response->fap.feature_index == HIDPP20_ERROR) { ret = response->fap.params[1]; dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret); - return ret; + goto out; } - return 0; + ret = 0; + +out: + hidpp->send_receive_buf = NULL; + return ret; } /* @@ -2502,12 +2507,15 @@ static void hidpp_ff_work_handler(struct work_struct *w) } break; case HIDPP_FF_DESTROY_EFFECT: - if (wd->effect_id >= 0) - /* regular effect destroyed */ - data->effect_ids[wd->params[0]-1] = -1; - else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER) - /* autocenter spring destroyed */ - data->slot_autocenter = 0; + slot = wd->params[0]; + if (slot > 0 && slot <= data->num_effects) { + if (wd->effect_id >= 0) + /* regular effect destroyed */ + data->effect_ids[slot-1] = -1; + else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER) + /* autocenter spring destroyed */ + data->slot_autocenter = 0; + } break; case HIDPP_FF_SET_GLOBAL_GAINS: data->gain = (wd->params[0] << 8) + wd->params[1]; @@ -3840,8 +3848,7 @@ static int hidpp_input_configured(struct hid_device *hdev, static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data, int size) { - struct hidpp_report *question = hidpp->send_receive_buf; - struct hidpp_report *answer = hidpp->send_receive_buf; + struct hidpp_report *question, *answer; struct hidpp_report *report = (struct hidpp_report *)data; int ret; int last_online; @@ -3851,6 +3858,12 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data, * previously sent command. */ if (unlikely(mutex_is_locked(&hidpp->send_mutex))) { + question = hidpp->send_receive_buf; + answer = hidpp->send_receive_buf; + + if (!question) + return 0; + /* * Check for a correct hidpp20 answer or the corresponding * error diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index 9eadf3252d0d..e70bd3dc07ab 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -817,19 +817,21 @@ static int magicmouse_fetch_battery(struct hid_device *hdev) #ifdef CONFIG_HID_BATTERY_STRENGTH struct hid_report_enum *report_enum; struct hid_report *report; + struct hid_battery *bat; - if (!hdev->battery || + bat = hid_get_battery(hdev); + if (!bat || (!is_usb_magicmouse2(hdev->vendor, hdev->product) && !is_usb_magictrackpad2(hdev->vendor, hdev->product))) return -1; - report_enum = &hdev->report_enum[hdev->battery_report_type]; - report = report_enum->report_id_hash[hdev->battery_report_id]; + report_enum = &hdev->report_enum[bat->report_type]; + report = report_enum->report_id_hash[bat->report_id]; if (!report || report->maxfield < 1) return -1; - if (hdev->battery_capacity == hdev->battery_max) + if (bat->capacity == bat->max) return -1; hid_hw_request(hdev, report, HID_REQ_GET_REPORT); diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c index ef3b5c77c38e..be80970ab48e 100644 --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -19,8 +19,15 @@ #include <linux/gpio/driver.h> #include <linux/iio/iio.h> #include <linux/minmax.h> +#include <linux/moduleparam.h> #include "hid-ids.h" +static bool gpio_mode_enforce; + +module_param(gpio_mode_enforce, bool, 0644); +MODULE_PARM_DESC(gpio_mode_enforce, + "Enforce GPIO mode for GP0 thru GP3 (default: false, will be used for IIO)"); + /* Commands codes in a raw output report */ enum { MCP2221_I2C_WR_DATA = 0x90, @@ -536,10 +543,10 @@ static int mcp_smbus_xfer(struct i2c_adapter *adapter, u16 addr, if (ret) goto exit; - mcp->rxbuf_idx = 0; - mcp->rxbuf = data->block; - mcp->txbuf[0] = MCP2221_I2C_GET_DATA; - ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1); + ret = mcp_i2c_smbus_read(mcp, NULL, + MCP2221_I2C_RD_RPT_START, + addr, data->block[0] + 1, + data->block); if (ret) goto exit; } else { @@ -555,14 +562,14 @@ static int mcp_smbus_xfer(struct i2c_adapter *adapter, u16 addr, case I2C_SMBUS_I2C_BLOCK_DATA: if (read_write == I2C_SMBUS_READ) { ret = mcp_smbus_write(mcp, addr, command, NULL, - 0, MCP2221_I2C_WR_NO_STOP, 1); + 0, MCP2221_I2C_WR_NO_STOP, 0); if (ret) goto exit; - mcp->rxbuf_idx = 0; - mcp->rxbuf = data->block; - mcp->txbuf[0] = MCP2221_I2C_GET_DATA; - ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1); + ret = mcp_i2c_smbus_read(mcp, NULL, + MCP2221_I2C_RD_RPT_START, + addr, data->block[0], + &data->block[1]); if (ret) goto exit; } else { @@ -650,7 +657,7 @@ static int mcp2221_check_gpio_pinfunc(struct mcp2221 *mcp) int needgpiofix = 0; int ret; - if (IS_ENABLED(CONFIG_IIO)) + if (IS_ENABLED(CONFIG_IIO) && !gpio_mode_enforce) return 0; ret = mcp_gpio_read_sram(mcp); @@ -1045,7 +1052,8 @@ static void mcp2221_remove(struct hid_device *hdev) #if IS_REACHABLE(CONFIG_IIO) struct mcp2221 *mcp = hid_get_drvdata(hdev); - cancel_delayed_work_sync(&mcp->init_work); + if (!gpio_mode_enforce) + cancel_delayed_work_sync(&mcp->init_work); #endif } @@ -1319,8 +1327,10 @@ static int mcp2221_probe(struct hid_device *hdev, #endif #if IS_REACHABLE(CONFIG_IIO) - INIT_DELAYED_WORK(&mcp->init_work, mcp_init_work); - schedule_delayed_work(&mcp->init_work, msecs_to_jiffies(100)); + if (!gpio_mode_enforce) { + INIT_DELAYED_WORK(&mcp->init_work, mcp_init_work); + schedule_delayed_work(&mcp->init_work, msecs_to_jiffies(100)); + } #endif return 0; diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c index c6c2961dd574..8bba29ef6c7a 100644 --- a/drivers/hid/hid-pl.c +++ b/drivers/hid/hid-pl.c @@ -24,10 +24,6 @@ */ -/* #define DEBUG */ - -#define debug(format, arg...) pr_debug("hid-plff: " format "\n" , ## arg) - #include <linux/input.h> #include <linux/slab.h> #include <linux/module.h> @@ -53,14 +49,14 @@ static int hid_plff_play(struct input_dev *dev, void *data, left = effect->u.rumble.strong_magnitude; right = effect->u.rumble.weak_magnitude; - debug("called with 0x%04x 0x%04x", left, right); + hid_dbg(dev, "called with 0x%04x 0x%04x", left, right); left = left * plff->maxval / 0xffff; right = right * plff->maxval / 0xffff; *plff->strong = left; *plff->weak = right; - debug("running with 0x%02x 0x%02x", left, right); + hid_dbg(dev, "running with 0x%02x 0x%02x", left, right); hid_hw_request(hid, plff->report, HID_REQ_SET_REPORT); return 0; @@ -119,7 +115,7 @@ static int plff_init(struct hid_device *hid) report->field[0]->value[1] = 0x00; strong = &report->field[0]->value[2]; weak = &report->field[0]->value[3]; - debug("detected single-field device"); + hid_dbg(hid, "detected single-field device"); } else if (report->field[0]->maxusage == 1 && report->field[0]->usage[0].hid == (HID_UP_LED | 0x43) && @@ -134,7 +130,7 @@ static int plff_init(struct hid_device *hid) weak = &report->field[3]->value[0]; if (hid->vendor == USB_VENDOR_ID_JESS2) maxval = 0xff; - debug("detected 4-field device"); + hid_dbg(hid, "detected 4-field device"); } else { hid_err(hid, "not enough fields or values\n"); return -ENODEV; diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index 3c0db8f93c82..c43caac20b61 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -2377,6 +2377,12 @@ static int dualshock4_parse_report(struct ps_device *ps_dev, struct hid_report * struct dualshock4_input_report_usb *usb = (struct dualshock4_input_report_usb *)data; + if (usb->num_touch_reports > ARRAY_SIZE(usb->touch_reports)) { + hid_err(hdev, "DualShock4 USB input report has invalid num_touch_reports=%d\n", + usb->num_touch_reports); + return -EINVAL; + } + ds4_report = &usb->common; num_touch_reports = usb->num_touch_reports; touch_reports = usb->touch_reports; @@ -2391,6 +2397,12 @@ static int dualshock4_parse_report(struct ps_device *ps_dev, struct hid_report * return -EILSEQ; } + if (bt->num_touch_reports > ARRAY_SIZE(bt->touch_reports)) { + hid_err(hdev, "DualShock4 BT input report has invalid num_touch_reports=%d\n", + bt->num_touch_reports); + return -EINVAL; + } + ds4_report = &bt->common; num_touch_reports = bt->num_touch_reports; touch_reports = bt->touch_reports; diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c index 02f7db5c1056..9e88c9d6c6dc 100644 --- a/drivers/hid/hid-quirks.c +++ b/drivers/hid/hid-quirks.c @@ -134,6 +134,7 @@ static const struct hid_device_id hid_quirks[] = { { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_6019), HID_QUIRK_ALWAYS_POLL }, { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_602E), HID_QUIRK_ALWAYS_POLL }, { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_6093), HID_QUIRK_ALWAYS_POLL }, + { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_BOLT_RECEIVER), HID_QUIRK_ALWAYS_POLL }, { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_C007), HID_QUIRK_ALWAYS_POLL }, { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_C077), HID_QUIRK_ALWAYS_POLL }, { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_KEYBOARD_G710_PLUS), HID_QUIRK_NOGET }, @@ -691,22 +692,54 @@ static const struct hid_device_id hid_have_special_driver[] = { { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) }, #endif #if IS_ENABLED(CONFIG_HID_SONY) + { HID_USB_DEVICE(USB_VENDOR_ID_CRKD, USB_DEVICE_ID_CRKD_PS4_GIBSON_SG) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CRKD, USB_DEVICE_ID_CRKD_PS4_GIBSON_SG_DONGLE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CRKD, USB_DEVICE_ID_CRKD_PS5_GIBSON_SG) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CRKD, USB_DEVICE_ID_CRKD_PS5_GIBSON_SG_DONGLE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB1_DRUMS) }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB1_GUITAR) }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB2_DRUMS) }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB2_GUITAR) }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB3_KEYBOARD) }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB3_MPA_DRUMS_MODE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB3_MPA_KEYBOARD_MODE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB3_MPA_MUSTANG_MODE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB3_MPA_SQUIER_MODE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB3_MUSTANG_GUITAR) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) }, - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_PS3_BDREMOTE) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_PS4_STRATOCASTER) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_PDP, USB_DEVICE_ID_PDP_PS4_JAGUAR) }, + { HID_USB_DEVICE(USB_VENDOR_ID_PDP, USB_DEVICE_ID_PDP_PS4_RIFFMASTER) }, + { HID_USB_DEVICE(USB_VENDOR_ID_PDP, USB_DEVICE_ID_PDP_PS5_RIFFMASTER) }, + { HID_USB_DEVICE(USB_VENDOR_ID_REDOCTANE, USB_DEVICE_ID_REDOCTANE_GUITAR_DONGLE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_REDOCTANE, USB_DEVICE_ID_REDOCTANE_PS4_GHLIVE_DONGLE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SINO_LITE, USB_DEVICE_ID_SINO_LITE_CONTROLLER) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_NSG_MR5U_REMOTE) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_NSG_MR7U_REMOTE) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_PS3_BDREMOTE) }, { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER) }, - { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER) }, - { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER) }, - { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE) }, - { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, - { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE) }, - { HID_USB_DEVICE(USB_VENDOR_ID_SINO_LITE, USB_DEVICE_ID_SINO_LITE_CONTROLLER) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3WIIU_GHLIVE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_DJH_TURNTABLE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_GH_DRUMS) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_GH_GUITAR) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB3_KEYBOARD) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB3_MPA_DRUMS_MODE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB3_MPA_KEYBOARD_MODE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB3_MPA_MUSTANG_MODE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB3_MPA_SQUIER_MODE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB3_MUSTANG_GUITAR) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB_DRUMS) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB_GUITAR) }, #endif #if IS_ENABLED(CONFIG_HID_SPEEDLINK) { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) }, diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index a89af14e4acc..b5e724676c1d 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * HID driver for Sony / PS2 / PS3 / PS4 BD devices. + * HID driver for Sony / PS2 / PS3 BD / PS4 / PS5 devices. * * Copyright (c) 1999 Andreas Gal * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> @@ -12,9 +12,10 @@ * Copyright (c) 2014-2016 Frank Praznik <frank.praznik@gmail.com> * Copyright (c) 2018 Todd Kelner * Copyright (c) 2020-2021 Pascal Giard <pascal.giard@etsmtl.ca> - * Copyright (c) 2020 Sanjay Govind <sanjay.govind9@gmail.com> + * Copyright (c) 2020-2026 Sanjay Govind <sanjay.govind9@gmail.com> * Copyright (c) 2021 Daniel Nguyen <daniel.nguyen.1@ens.etsmtl.ca> * Copyright (c) 2026 Rosalie Wanders <rosalie@mailbox.org> + * Copyright (c) 2026 Brenton Simpson <appsforartists@google.com> */ /* @@ -59,12 +60,15 @@ #define NSG_MR5U_REMOTE_BT BIT(11) #define NSG_MR7U_REMOTE_BT BIT(12) #define SHANWAN_GAMEPAD BIT(13) -#define GH_GUITAR_CONTROLLER BIT(14) -#define GHL_GUITAR_PS3WIIU BIT(15) -#define GHL_GUITAR_PS4 BIT(16) -#define RB4_GUITAR_PS4_USB BIT(17) -#define RB4_GUITAR_PS4_BT BIT(18) -#define RB4_GUITAR_PS5 BIT(19) +#define INSTRUMENT BIT(14) +#define GH_GUITAR_TILT BIT(15) +#define GHL_GUITAR_PS3WIIU BIT(16) +#define GHL_GUITAR_PS4 BIT(17) +#define RB4_GUITAR_PS4_USB BIT(18) +#define RB4_GUITAR_PS4_BT BIT(19) +#define RB4_GUITAR_PS5 BIT(20) +#define RB3_PRO_INSTRUMENT BIT(21) +#define DJH_TURNTABLE BIT(22) #define SIXAXIS_CONTROLLER (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT) #define MOTION_CONTROLLER (MOTION_CONTROLLER_USB | MOTION_CONTROLLER_BT) @@ -72,7 +76,8 @@ NAVIGATION_CONTROLLER_BT) #define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER | BUZZ_CONTROLLER |\ MOTION_CONTROLLER | NAVIGATION_CONTROLLER) -#define SONY_BATTERY_SUPPORT (SIXAXIS_CONTROLLER | MOTION_CONTROLLER_BT | NAVIGATION_CONTROLLER) +#define SONY_BATTERY_SUPPORT (SIXAXIS_CONTROLLER | MOTION_CONTROLLER_BT | NAVIGATION_CONTROLLER |\ + RB4_GUITAR_PS5) #define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER | MOTION_CONTROLLER) #define SONY_BT_DEVICE (SIXAXIS_CONTROLLER_BT | MOTION_CONTROLLER_BT | NAVIGATION_CONTROLLER_BT) #define NSG_MRXU_REMOTE (NSG_MR5U_REMOTE_BT | NSG_MR7U_REMOTE_BT) @@ -87,6 +92,10 @@ #define GHL_GUITAR_POKE_INTERVAL 8 /* In seconds */ #define GUITAR_TILT_USAGE 44 +#define TURNTABLE_EFFECTS_KNOB_USAGE 44 +#define TURNTABLE_PLATTER_BUTTONS_USAGE 45 +#define TURNTABLE_CROSS_FADER_USAGE 46 + /* Magic data taken from GHLtarUtility: * https://github.com/ghlre/GHLtarUtility/blob/master/PS3Guitar.cs * Note: The Wii U and PS3 dongles happen to share the same! @@ -427,20 +436,25 @@ static const unsigned int rb4_absmap[] = { [0x31] = ABS_Y, }; -static const unsigned int rb4_keymap[] = { - [0x1] = BTN_WEST, /* Square */ - [0x2] = BTN_SOUTH, /* Cross */ - [0x3] = BTN_EAST, /* Circle */ - [0x4] = BTN_NORTH, /* Triangle */ - [0x5] = BTN_TL, /* L1 */ - [0x6] = BTN_TR, /* R1 */ - [0x7] = BTN_TL2, /* L2 */ - [0x8] = BTN_TR2, /* R2 */ - [0x9] = BTN_SELECT, /* Share */ - [0xa] = BTN_START, /* Options */ - [0xb] = BTN_THUMBL, /* L3 */ - [0xc] = BTN_THUMBR, /* R3 */ - [0xd] = BTN_MODE, /* PS */ +static const unsigned int ps3_turntable_absmap[] = { + [0x32] = ABS_X, + [0x35] = ABS_Y, +}; + +static const unsigned int instrument_keymap[] = { + [0x1] = BTN_WEST, + [0x2] = BTN_SOUTH, + [0x3] = BTN_EAST, + [0x4] = BTN_NORTH, + [0x5] = BTN_TL, + [0x6] = BTN_TR, + [0x7] = BTN_TL2, + [0x8] = BTN_TR2, + [0x9] = BTN_SELECT, + [0xa] = BTN_START, + [0xb] = BTN_THUMBL, + [0xc] = BTN_THUMBR, + [0xd] = BTN_MODE, }; static enum power_supply_property sony_battery_props[] = { @@ -457,6 +471,7 @@ struct sixaxis_led { u8 duty_off; /* % of duty_length the led is off (0xff means 100%) */ u8 duty_on; /* % of duty_length the led is on (0xff mean 100%) */ } __packed; +static_assert(sizeof(struct sixaxis_led) == 5); struct sixaxis_rumble { u8 padding; @@ -465,6 +480,7 @@ struct sixaxis_rumble { u8 left_duration; /* Left motor duration (0xff means forever) */ u8 left_motor_force; /* left (large) motor, supports force values from 0 to 255 */ } __packed; +static_assert(sizeof(struct sixaxis_rumble) == 5); struct sixaxis_output_report { u8 report_id; @@ -474,11 +490,13 @@ struct sixaxis_output_report { struct sixaxis_led led[4]; /* LEDx at (4 - x) */ struct sixaxis_led _reserved; /* LED5, not actually soldered */ } __packed; +static_assert(sizeof(struct sixaxis_output_report) == 36); union sixaxis_output_report_01 { struct sixaxis_output_report data; u8 buf[36]; }; +static_assert(sizeof(union sixaxis_output_report_01) == 36); struct motion_output_report_02 { u8 type, zero; @@ -486,10 +504,12 @@ struct motion_output_report_02 { u8 zero2; u8 rumble; }; +static_assert(sizeof(struct motion_output_report_02) == 7); #define SIXAXIS_REPORT_0xF2_SIZE 17 #define SIXAXIS_REPORT_0xF5_SIZE 8 #define MOTION_REPORT_0x02_SIZE 49 +#define PRO_INSTRUMENT_0x00_SIZE 8 #define SENSOR_SUFFIX " Motion Sensors" #define TOUCHPAD_SUFFIX " Touchpad" @@ -515,7 +535,7 @@ struct sony_sc { struct led_classdev *leds[MAX_LEDS]; unsigned long quirks; struct work_struct state_worker; - void (*send_output_report)(struct sony_sc *); + void (*send_output_report)(struct sony_sc *sc); struct power_supply *battery; struct power_supply_desc battery_desc; int device_id; @@ -539,6 +559,9 @@ struct sony_sc { /* GH Live */ struct urb *ghl_urb; struct timer_list ghl_poke_timer; + + /* Rock Band 3 Pro Instruments */ + unsigned long rb3_pro_poke_jiffies; }; static void sony_set_leds(struct sony_sc *sc); @@ -589,11 +612,11 @@ static int ghl_init_urb(struct sony_sc *sc, struct usb_device *usbdev, pipe = usb_sndctrlpipe(usbdev, 0); cr = devm_kzalloc(&sc->hdev->dev, sizeof(*cr), GFP_ATOMIC); - if (cr == NULL) + if (!cr) return -ENOMEM; databuf = devm_kzalloc(&sc->hdev->dev, poke_size, GFP_ATOMIC); - if (databuf == NULL) + if (!databuf) return -ENOMEM; cr->bRequestType = @@ -610,35 +633,108 @@ static int ghl_init_urb(struct sony_sc *sc, struct usb_device *usbdev, return 0; } -static int gh_guitar_mapping(struct hid_device *hdev, struct hid_input *hi, + + +/* + * Sending HID_REQ_SET_REPORT enables the full report. Without this + * Rock Band 3 Pro instruments only report navigation events + */ +static int rb3_pro_instrument_enable_full_report(struct sony_sc *sc) +{ + struct hid_device *hdev = sc->hdev; + static const u8 report[] = { 0x00, 0xE9, 0x00, 0x89, 0x1B, + 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x89, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xE9, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00 }; + u8 *buf; + int ret; + + buf = kmemdup(report, sizeof(report), GFP_KERNEL); + if (!buf) + return -ENOMEM; + + ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report), + HID_FEATURE_REPORT, HID_REQ_SET_REPORT); + + kfree(buf); + + return ret; +} + +static int djh_turntable_mapping(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) { if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) { unsigned int abs = usage->hid & HID_USAGE; - if (abs == GUITAR_TILT_USAGE) { + if (abs == TURNTABLE_CROSS_FADER_USAGE) { + hid_map_usage_clear(hi, usage, bit, max, EV_ABS, ABS_RX); + return 1; + } else if (abs == TURNTABLE_EFFECTS_KNOB_USAGE) { hid_map_usage_clear(hi, usage, bit, max, EV_ABS, ABS_RY); return 1; + } else if (abs == TURNTABLE_PLATTER_BUTTONS_USAGE) { + hid_map_usage_clear(hi, usage, bit, max, EV_ABS, ABS_RZ); + return 1; } + } else if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK) { + unsigned int abs = usage->hid & HID_USAGE; + + if (abs >= ARRAY_SIZE(ps3_turntable_absmap)) + return -1; + + abs = ps3_turntable_absmap[abs]; + + hid_map_usage_clear(hi, usage, bit, max, EV_ABS, abs); + return 1; } return 0; } -static int rb4_guitar_mapping(struct hid_device *hdev, struct hid_input *hi, +static int instrument_mapping(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) { if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON) { unsigned int key = usage->hid & HID_USAGE; - if (key >= ARRAY_SIZE(rb4_keymap)) + if (key >= ARRAY_SIZE(instrument_keymap)) return 0; - key = rb4_keymap[key]; + key = instrument_keymap[key]; hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key); return 1; - } else if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK) { + } + + return 0; +} + +static int gh_guitar_mapping(struct hid_device *hdev, struct hid_input *hi, + struct hid_field *field, struct hid_usage *usage, + unsigned long **bit, int *max) +{ + if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) { + unsigned int abs = usage->hid & HID_USAGE; + + if (abs == GUITAR_TILT_USAGE) { + hid_map_usage_clear(hi, usage, bit, max, EV_ABS, ABS_RY); + return 1; + } + } + return 0; +} + +static int rb4_guitar_mapping(struct hid_device *hdev, struct hid_input *hi, + struct hid_field *field, struct hid_usage *usage, + unsigned long **bit, int *max) +{ + if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK) { unsigned int abs = usage->hid & HID_USAGE; /* Let the HID parser deal with the HAT. */ @@ -855,6 +951,7 @@ static void sixaxis_parse_report(struct sony_sc *sc, u8 *rd, int size) static const u8 sixaxis_battery_capacity[] = { 0, 1, 25, 50, 75, 100 }; unsigned long flags; int offset; + u8 index; u8 battery_capacity; int battery_status; @@ -870,7 +967,7 @@ static void sixaxis_parse_report(struct sony_sc *sc, u8 *rd, int size) battery_capacity = 100; battery_status = (rd[offset] & 0x01) ? POWER_SUPPLY_STATUS_FULL : POWER_SUPPLY_STATUS_CHARGING; } else { - u8 index = rd[offset] <= 5 ? rd[offset] : 5; + index = rd[offset] <= 5 ? rd[offset] : 5; battery_capacity = sixaxis_battery_capacity[index]; battery_status = POWER_SUPPLY_STATUS_DISCHARGING; } @@ -908,7 +1005,7 @@ static void nsg_mrxu_parse_report(struct sony_sc *sc, u8 *rd, int size) * the touch-related data starts at offset 2. * For the first byte, bit 0 is set when touchpad button is pressed. * Bit 2 is set when a touch is active and the drag (Fn) key is pressed. - * This drag key is mapped to BTN_LEFT. It is operational only when a + * This drag key is mapped to BTN_LEFT. It is operational only when a * touch point is active. * Bit 4 is set when only the first touch point is active. * Bit 6 is set when only the second touch point is active. @@ -991,6 +1088,12 @@ static void rb4_ps4_guitar_parse_report(struct sony_sc *sc, u8 *rd, int size) static void rb4_ps5_guitar_parse_report(struct sony_sc *sc, u8 *rd, int size) { + u8 charging_status; + u8 battery_data; + u8 battery_capacity; + u8 battery_status; + unsigned long flags; + /* * Rock Band 4 PS5 guitars have whammy and * tilt functionality, they're located at @@ -1003,6 +1106,37 @@ static void rb4_ps5_guitar_parse_report(struct sony_sc *sc, u8 *rd, int size) input_report_abs(sc->input_dev, ABS_Z, rd[41]); input_report_abs(sc->input_dev, ABS_RZ, rd[42]); + /* + * Rock Band 4 PS5 guitars also report the + * battery status and level at byte 30. + */ + charging_status = (rd[30] >> 4) & 0x0F; + battery_data = rd[30] & 0x0F; + + switch (charging_status) { + case 0x0: + battery_capacity = min(battery_data * 10 + 5, 100); + battery_status = POWER_SUPPLY_STATUS_DISCHARGING; + break; + case 0x1: + battery_capacity = min(battery_data * 10 + 5, 100); + battery_status = POWER_SUPPLY_STATUS_CHARGING; + break; + case 0x2: + battery_capacity = 100; + battery_status = POWER_SUPPLY_STATUS_FULL; + break; + default: + battery_capacity = 0; + battery_status = POWER_SUPPLY_STATUS_UNKNOWN; + break; + } + + spin_lock_irqsave(&sc->lock, flags); + sc->battery_capacity = battery_capacity; + sc->battery_status = battery_status; + spin_unlock_irqrestore(&sc->lock, flags); + input_sync(sc->input_dev); } @@ -1052,6 +1186,17 @@ static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, return 1; } + /* Rock Band 3 PS3 Pro instruments set rd[24] to 0xE0 when they're + * sending full reports, and 0x02 when only sending navigation. + */ + if ((sc->quirks & RB3_PRO_INSTRUMENT) && rd[24] == 0x02) { + /* Only attempt to enable full report every 8 seconds */ + if (time_after(jiffies, sc->rb3_pro_poke_jiffies)) { + sc->rb3_pro_poke_jiffies = jiffies + secs_to_jiffies(8); + rb3_pro_instrument_enable_full_report(sc); + } + } + if (sc->defer_initialization) { sc->defer_initialization = 0; sony_schedule_work(sc, SONY_WORKER_STATE); @@ -1065,6 +1210,7 @@ static int sony_mapping(struct hid_device *hdev, struct hid_input *hi, unsigned long **bit, int *max) { struct sony_sc *sc = hid_get_drvdata(hdev); + int ret; if (sc->quirks & BUZZ_CONTROLLER) { unsigned int key = usage->hid & HID_USAGE; @@ -1098,9 +1244,19 @@ static int sony_mapping(struct hid_device *hdev, struct hid_input *hi, if (sc->quirks & SIXAXIS_CONTROLLER) return sixaxis_mapping(hdev, hi, field, usage, bit, max); - if (sc->quirks & GH_GUITAR_CONTROLLER) + /* INSTRUMENT quirk is used as a base mapping for instruments */ + if (sc->quirks & INSTRUMENT) { + ret = instrument_mapping(hdev, hi, field, usage, bit, max); + if (ret != 0) + return ret; + } + + if (sc->quirks & GH_GUITAR_TILT) return gh_guitar_mapping(hdev, hi, field, usage, bit, max); + if (sc->quirks & DJH_TURNTABLE) + return djh_turntable_mapping(hdev, hi, field, usage, bit, max); + if (sc->quirks & (RB4_GUITAR_PS4_USB | RB4_GUITAR_PS4_BT)) return rb4_guitar_mapping(hdev, hi, field, usage, bit, max); @@ -1153,19 +1309,18 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count, input_set_abs_params(sc->touchpad, ABS_MT_POSITION_Y, 0, h, 0, 0); if (touch_major > 0) { - input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MAJOR, + input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MAJOR, 0, touch_major, 0, 0); if (touch_minor > 0) - input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MINOR, + input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MINOR, 0, touch_minor, 0, 0); if (orientation > 0) - input_set_abs_params(sc->touchpad, ABS_MT_ORIENTATION, + input_set_abs_params(sc->touchpad, ABS_MT_ORIENTATION, 0, orientation, 0, 0); } - if (sc->quirks & NSG_MRXU_REMOTE) { + if (sc->quirks & NSG_MRXU_REMOTE) __set_bit(EV_REL, sc->touchpad->evbit); - } ret = input_mt_init_slots(sc->touchpad, touch_count, INPUT_MT_POINTER); if (ret < 0) @@ -1320,7 +1475,7 @@ static void sixaxis_set_leds_from_id(struct sony_sc *sc) int id = sc->device_id; - BUILD_BUG_ON(MAX_LEDS < ARRAY_SIZE(sixaxis_leds[0])); + BUILD_BUG_ON(ARRAY_SIZE(sixaxis_leds[0]) > MAX_LEDS); if (id < 0) return; @@ -1338,7 +1493,7 @@ static void buzz_set_leds(struct sony_sc *sc) struct hid_report, list); s32 *value = report->field[0]->value; - BUILD_BUG_ON(MAX_LEDS < 4); + BUILD_BUG_ON(4 > MAX_LEDS); value[0] = 0x00; value[1] = sc->led_state[0] ? 0xff : 0x00; @@ -1535,15 +1690,12 @@ static int sony_leds_init(struct sony_sc *sc) name_sz = strlen(dev_name(&hdev->dev)) + strlen(color_name_str[n]) + 2; led = devm_kzalloc(&hdev->dev, sizeof(struct led_classdev) + name_sz, GFP_KERNEL); - if (!led) { - hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); + if (!led) return -ENOMEM; - } name = (void *)(&led[1]); if (use_color_names) - snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), - color_name_str[n]); + snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), color_name_str[n]); else snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1); led->name = name; @@ -2060,6 +2212,19 @@ static int sony_input_configured(struct hid_device *hdev, } sony_init_output_report(sc, sixaxis_send_output_report); + } else if (sc->quirks & RB3_PRO_INSTRUMENT) { + /* + * Rock Band 3 PS3 Pro Instruments also do not handle HID Output + * Reports on the interrupt EP like they should, so we need to force + * HID output reports to use HID_REQ_SET_REPORT on the Control EP. + * + * There is also another issue about HID Output Reports via USB, + * these instruments do not want the report_id as part of the data + * packet, so we have to discard buf[0] when sending the actual + * control message, even for numbered reports. + */ + hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; + hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID; } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) { /* * The Sony Sixaxis does not handle HID Output Reports on the @@ -2176,10 +2341,8 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) quirks |= SHANWAN_GAMEPAD; sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL); - if (sc == NULL) { - hid_err(hdev, "can't alloc sony descriptor\n"); + if (!sc) return -ENOMEM; - } spin_lock_init(&sc->lock); @@ -2227,6 +2390,9 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) goto err; } + if (sc->quirks & RB3_PRO_INSTRUMENT) + sc->rb3_pro_poke_jiffies = 0; + if (sc->quirks & (GHL_GUITAR_PS3WIIU | GHL_GUITAR_PS4)) { if (!hid_is_usb(hdev)) { ret = -EINVAL; @@ -2364,35 +2530,82 @@ static const struct hid_device_id sony_devices[] = { { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_NSG_MR7U_REMOTE), .driver_data = NSG_MR7U_REMOTE_BT }, /* Guitar Hero Live PS3 and Wii U guitar dongles */ - { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3WIIU_GHLIVE_DONGLE), - .driver_data = GHL_GUITAR_PS3WIIU | GH_GUITAR_CONTROLLER }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3WIIU_GHLIVE), + .driver_data = GHL_GUITAR_PS3WIIU | GH_GUITAR_TILT | INSTRUMENT }, /* Guitar Hero PC Guitar Dongle */ { HID_USB_DEVICE(USB_VENDOR_ID_REDOCTANE, USB_DEVICE_ID_REDOCTANE_GUITAR_DONGLE), - .driver_data = GH_GUITAR_CONTROLLER }, - /* Guitar Hero PS3 World Tour Guitar Dongle */ - { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_GUITAR_DONGLE), - .driver_data = GH_GUITAR_CONTROLLER }, + .driver_data = GH_GUITAR_TILT | INSTRUMENT }, + /* Guitar Hero PS3 Guitar Dongle */ + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_GH_GUITAR), + .driver_data = GH_GUITAR_TILT | INSTRUMENT }, + /* Guitar Hero PS3 Drum Dongle */ + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_GH_DRUMS), + .driver_data = INSTRUMENT }, + /* DJ Hero PS3 Guitar Dongle */ + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_DJH_TURNTABLE), + .driver_data = DJH_TURNTABLE | INSTRUMENT }, /* Guitar Hero Live PS4 guitar dongles */ { HID_USB_DEVICE(USB_VENDOR_ID_REDOCTANE, USB_DEVICE_ID_REDOCTANE_PS4_GHLIVE_DONGLE), - .driver_data = GHL_GUITAR_PS4 | GH_GUITAR_CONTROLLER }, + .driver_data = GHL_GUITAR_PS4 | GH_GUITAR_TILT | INSTRUMENT }, + /* Rock Band 1 Wii instruments */ + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB1_GUITAR), + .driver_data = INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB1_DRUMS), + .driver_data = INSTRUMENT }, + /* Rock Band 2 Wii instruments */ + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB2_GUITAR), + .driver_data = INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB2_DRUMS), + .driver_data = INSTRUMENT }, + /* Rock Band 3 Wii instruments */ + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB3_MPA_DRUMS_MODE), + .driver_data = INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB3_MUSTANG_GUITAR), + .driver_data = INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB3_MPA_MUSTANG_MODE), + .driver_data = INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB3_MPA_SQUIER_MODE), + .driver_data = INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB3_KEYBOARD), + .driver_data = INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_HARMONIX, USB_DEVICE_ID_HARMONIX_WII_RB3_MPA_KEYBOARD_MODE), + .driver_data = INSTRUMENT }, + /* Rock Band 3 PS3 instruments */ + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB_GUITAR), + .driver_data = INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB_DRUMS), + .driver_data = INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB3_MPA_DRUMS_MODE), + .driver_data = INSTRUMENT }, + /* Rock Band 3 PS3 Pro instruments */ + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB3_MUSTANG_GUITAR), + .driver_data = INSTRUMENT | RB3_PRO_INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB3_MPA_MUSTANG_MODE), + .driver_data = INSTRUMENT | RB3_PRO_INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB3_MPA_SQUIER_MODE), + .driver_data = INSTRUMENT | RB3_PRO_INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB3_KEYBOARD), + .driver_data = INSTRUMENT | RB3_PRO_INSTRUMENT }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_RB3_MPA_KEYBOARD_MODE), + .driver_data = INSTRUMENT | RB3_PRO_INSTRUMENT }, /* Rock Band 4 PS4 guitars */ { HID_USB_DEVICE(USB_VENDOR_ID_PDP, USB_DEVICE_ID_PDP_PS4_RIFFMASTER), - .driver_data = RB4_GUITAR_PS4_USB }, + .driver_data = RB4_GUITAR_PS4_USB | INSTRUMENT }, { HID_USB_DEVICE(USB_VENDOR_ID_CRKD, USB_DEVICE_ID_CRKD_PS4_GIBSON_SG), - .driver_data = RB4_GUITAR_PS4_USB }, + .driver_data = RB4_GUITAR_PS4_USB | INSTRUMENT }, { HID_USB_DEVICE(USB_VENDOR_ID_CRKD, USB_DEVICE_ID_CRKD_PS4_GIBSON_SG_DONGLE), - .driver_data = RB4_GUITAR_PS4_USB }, + .driver_data = RB4_GUITAR_PS4_USB | INSTRUMENT }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_PDP, USB_DEVICE_ID_PDP_PS4_JAGUAR), - .driver_data = RB4_GUITAR_PS4_BT }, + .driver_data = RB4_GUITAR_PS4_BT | INSTRUMENT }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_PS4_STRATOCASTER), - .driver_data = RB4_GUITAR_PS4_BT }, + .driver_data = RB4_GUITAR_PS4_BT | INSTRUMENT }, /* Rock Band 4 PS5 guitars */ { HID_USB_DEVICE(USB_VENDOR_ID_PDP, USB_DEVICE_ID_PDP_PS5_RIFFMASTER), - .driver_data = RB4_GUITAR_PS5 }, + .driver_data = RB4_GUITAR_PS5 | INSTRUMENT }, { HID_USB_DEVICE(USB_VENDOR_ID_CRKD, USB_DEVICE_ID_CRKD_PS5_GIBSON_SG), - .driver_data = RB4_GUITAR_PS5 }, + .driver_data = RB4_GUITAR_PS5 | INSTRUMENT }, { HID_USB_DEVICE(USB_VENDOR_ID_CRKD, USB_DEVICE_ID_CRKD_PS5_GIBSON_SG_DONGLE), - .driver_data = RB4_GUITAR_PS5 }, + .driver_data = RB4_GUITAR_PS5 | INSTRUMENT }, { } }; MODULE_DEVICE_TABLE(hid, sony_devices); @@ -2428,5 +2641,5 @@ static void __exit sony_exit(void) module_init(sony_init); module_exit(sony_exit); -MODULE_DESCRIPTION("HID driver for Sony / PS2 / PS3 / PS4 BD devices"); +MODULE_DESCRIPTION("HID driver for Sony / PS2 / PS3 BD / PS4 / PS5 devices"); MODULE_LICENSE("GPL"); diff --git a/drivers/hid/hid-winwing.c b/drivers/hid/hid-winwing.c index ab65dc12d1e0..9cd25a77999e 100644 --- a/drivers/hid/hid-winwing.c +++ b/drivers/hid/hid-winwing.c @@ -12,6 +12,7 @@ #include <linux/kernel.h> #include <linux/module.h> #include <linux/mutex.h> +#include <linux/workqueue.h> #define MAX_REPORT 16 @@ -35,10 +36,14 @@ static const struct winwing_led_info led_info[3] = { struct winwing_drv_data { struct hid_device *hdev; - __u8 *report_buf; - struct mutex lock; - int map_more_buttons; - unsigned int num_leds; + struct mutex lights_lock; + __u8 *report_lights; + __u8 *report_rumble; + struct work_struct rumble_work; + struct ff_rumble_effect rumble; + int rumble_left; + int rumble_right; + int has_grip15; struct winwing_led leds[]; }; @@ -47,11 +52,15 @@ static int winwing_led_write(struct led_classdev *cdev, { struct winwing_led *led = (struct winwing_led *) cdev; struct winwing_drv_data *data = hid_get_drvdata(led->hdev); - __u8 *buf = data->report_buf; + __u8 *buf = data->report_lights; int ret; - mutex_lock(&data->lock); + mutex_lock(&data->lights_lock); + /* + * Mimicking requests captured by usbmon when LEDs + * are controlled by the vendor's app in a VM. + */ buf[0] = 0x02; buf[1] = 0x60; buf[2] = 0xbe; @@ -69,7 +78,7 @@ static int winwing_led_write(struct led_classdev *cdev, ret = hid_hw_output_report(led->hdev, buf, 14); - mutex_unlock(&data->lock); + mutex_unlock(&data->lights_lock); return ret; } @@ -87,9 +96,9 @@ static int winwing_init_led(struct hid_device *hdev, if (!data) return -EINVAL; - data->report_buf = devm_kmalloc(&hdev->dev, MAX_REPORT, GFP_KERNEL); + data->report_lights = devm_kzalloc(&hdev->dev, MAX_REPORT, GFP_KERNEL); - if (!data->report_buf) + if (!data->report_lights) return -ENOMEM; for (i = 0; i < 3; i += 1) { @@ -117,7 +126,7 @@ static int winwing_init_led(struct hid_device *hdev, return ret; } -static int winwing_map_button(int button, int map_more_buttons) +static int winwing_map_button(int button, int has_grip15) { if (button < 1) return KEY_RESERVED; @@ -141,7 +150,7 @@ static int winwing_map_button(int button, int map_more_buttons) return (button - 65) + BTN_TRIGGER_HAPPY17; } - if (!map_more_buttons) { + if (!has_grip15) { /* * Not mapping numbers [33 .. 64] which * are not assigned to any real buttons @@ -194,13 +203,149 @@ static int winwing_input_mapping(struct hid_device *hdev, /* Button numbers start with 1 */ button = usage->hid & HID_USAGE; - code = winwing_map_button(button, data->map_more_buttons); + code = winwing_map_button(button, data->has_grip15); hid_map_usage(hi, usage, bit, max, EV_KEY, code); return 1; } +/* + * If x ≤ 0, return 0; + * if x is in [1 .. 65535], return a value in [1 .. 255] + */ +static inline int convert_magnitude(int x) +{ + if (x < 1) + return 0; + + return ((x * 255) >> 16) + 1; +} + +static int winwing_haptic_rumble(struct winwing_drv_data *data) +{ + __u8 *buf; + __u8 m; + + if (!data) + return -EINVAL; + + if (!data->hdev) + return -EINVAL; + + buf = data->report_rumble; + + if (!buf) + return -EINVAL; + + m = convert_magnitude(data->rumble.strong_magnitude); + if (m != data->rumble_left) { + int ret; + + /* + * Mimicking requests captured by usbmon when rumble + * is activated by the vendor's app in a VM. + */ + buf[0] = 0x02; + buf[1] = 0x01; + buf[2] = 0xbf; + buf[3] = 0x00; + buf[4] = 0x00; + buf[5] = 0x03; + buf[6] = 0x49; + buf[7] = 0x00; + buf[8] = m; + buf[9] = 0x00; + buf[10] = 0; + buf[11] = 0; + buf[12] = 0; + buf[13] = 0; + + ret = hid_hw_output_report(data->hdev, buf, 14); + if (ret < 0) { + hid_err(data->hdev, "error %d (%*ph)\n", ret, 14, buf); + return ret; + } + data->rumble_left = m; + } + + m = convert_magnitude(data->rumble.weak_magnitude); + if (m != data->rumble_right) { + int ret; + + /* + * Mimicking requests captured by usbmon when rumble + * is activated by the vendor's app in a VM. + */ + buf[0] = 0x02; + buf[1] = 0x03; + buf[2] = 0xbf; + buf[3] = 0x00; + buf[4] = 0x00; + buf[5] = 0x03; + buf[6] = 0x49; + buf[7] = 0x00; + buf[8] = m; + buf[9] = 0x00; + buf[10] = 0; + buf[11] = 0; + buf[12] = 0; + buf[13] = 0; + + ret = hid_hw_output_report(data->hdev, buf, 14); + if (ret < 0) { + hid_err(data->hdev, "error %d (%*ph)\n", ret, 14, buf); + return ret; + } + data->rumble_right = m; + } + + return 0; +} + + +static void winwing_haptic_rumble_cb(struct work_struct *work) +{ + struct winwing_drv_data *data; + + data = container_of(work, struct winwing_drv_data, rumble_work); + winwing_haptic_rumble(data); +} + +static int winwing_play_effect(struct input_dev *dev, void *context, + struct ff_effect *effect) +{ + struct winwing_drv_data *data = (struct winwing_drv_data *) context; + + if (effect->type != FF_RUMBLE) + return 0; + + if (!data) + return -EINVAL; + + data->rumble = effect->u.rumble; + + return schedule_work(&data->rumble_work); +} + +static int winwing_init_ff(struct hid_device *hdev, struct hid_input *hidinput) +{ + struct winwing_drv_data *data; + + data = (struct winwing_drv_data *) hid_get_drvdata(hdev); + if (!data) + return -EINVAL; + + data->report_rumble = devm_kzalloc(&hdev->dev, MAX_REPORT, GFP_KERNEL); + data->rumble_left = -1; + data->rumble_right = -1; + + input_set_capability(hidinput->input, EV_FF, FF_RUMBLE); + + return input_ff_create_memless(hidinput->input, data, + winwing_play_effect); +} + static int winwing_probe(struct hid_device *hdev, const struct hid_device_id *id) { @@ -219,10 +364,12 @@ static int winwing_probe(struct hid_device *hdev, if (!data) return -ENOMEM; - data->map_more_buttons = id->driver_data; - + data->hdev = hdev; + data->has_grip15 = id->driver_data; hid_set_drvdata(hdev, data); + INIT_WORK(&data->rumble_work, winwing_haptic_rumble_cb); + ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); if (ret) { hid_err(hdev, "hw start failed\n"); @@ -232,19 +379,39 @@ static int winwing_probe(struct hid_device *hdev, return 0; } +static void winwing_remove(struct hid_device *hdev) +{ + struct winwing_drv_data *data; + + data = (struct winwing_drv_data *) hid_get_drvdata(hdev); + + if (data) + cancel_work_sync(&data->rumble_work); + + hid_hw_close(hdev); + hid_hw_stop(hdev); +} + static int winwing_input_configured(struct hid_device *hdev, struct hid_input *hidinput) { + struct winwing_drv_data *data; int ret; + data = (struct winwing_drv_data *) hid_get_drvdata(hdev); + ret = winwing_init_led(hdev, hidinput->input); if (ret) hid_err(hdev, "led init failed\n"); + if (data->has_grip15) + winwing_init_ff(hdev, hidinput); + return ret; } +/* Set driver_data to 1 for grips with rumble motor and more than 32 buttons */ static const struct hid_device_id winwing_devices[] = { { HID_USB_DEVICE(0x4098, 0xbd65), .driver_data = 1 }, /* TGRIP-15E */ { HID_USB_DEVICE(0x4098, 0xbd64), .driver_data = 1 }, /* TGRIP-15EX */ @@ -261,6 +428,7 @@ static struct hid_driver winwing_driver = { .input_configured = winwing_input_configured, .input_mapping = winwing_input_mapping, .probe = winwing_probe, + .remove = winwing_remove, }; module_hid_driver(winwing_driver); diff --git a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c index b6a69995692c..f669235f1883 100644 --- a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +++ b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c @@ -753,9 +753,11 @@ static int quickspi_suspend(struct device *device) if (!qsdev) return -ENODEV; - ret = quickspi_set_power(qsdev, HIDSPI_SLEEP); - if (ret) - return ret; + if (!device_may_wakeup(qsdev->dev)) { + ret = quickspi_set_power(qsdev, HIDSPI_SLEEP); + if (ret) + return ret; + } ret = thc_interrupt_quiesce(qsdev->thc_hw, true); if (ret) @@ -794,9 +796,8 @@ static int quickspi_resume(struct device *device) if (ret) return ret; - ret = quickspi_set_power(qsdev, HIDSPI_ON); - if (ret) - return ret; + if (!device_may_wakeup(qsdev->dev)) + return quickspi_set_power(qsdev, HIDSPI_ON); return 0; } @@ -855,6 +856,9 @@ static int quickspi_poweroff(struct device *device) if (!qsdev) return -ENODEV; + /* Ignore the return value as platform will be poweroff soon */ + quickspi_set_power(qsdev, HIDSPI_OFF); + ret = thc_interrupt_quiesce(qsdev->thc_hw, true); if (ret) return ret; diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c index d8e195189e4b..9a8449428170 100644 --- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c +++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c @@ -1112,12 +1112,15 @@ int thc_port_select(struct thc_device *dev, enum thc_port_type port_type) EXPORT_SYMBOL_NS_GPL(thc_port_select, "INTEL_THC"); #define THC_SPI_FREQUENCY_7M 7812500 +#define THC_SPI_FREQUENCY_10M 10416700 #define THC_SPI_FREQUENCY_15M 15625000 #define THC_SPI_FREQUENCY_17M 17857100 #define THC_SPI_FREQUENCY_20M 20833000 #define THC_SPI_FREQUENCY_25M 25000000 #define THC_SPI_FREQUENCY_31M 31250000 +#define THC_SPI_FREQUENCY_35M 35714200 #define THC_SPI_FREQUENCY_41M 41666700 +#define THC_SPI_FREQUENCY_50M 50000000 #define THC_SPI_LOW_FREQUENCY THC_SPI_FREQUENCY_17M @@ -1125,21 +1128,27 @@ static u8 thc_get_spi_freq_div_val(struct thc_device *dev, u32 spi_freq_val) { static const int frequency[] = { THC_SPI_FREQUENCY_7M, + THC_SPI_FREQUENCY_10M, THC_SPI_FREQUENCY_15M, THC_SPI_FREQUENCY_17M, THC_SPI_FREQUENCY_20M, THC_SPI_FREQUENCY_25M, THC_SPI_FREQUENCY_31M, + THC_SPI_FREQUENCY_35M, THC_SPI_FREQUENCY_41M, + THC_SPI_FREQUENCY_50M, }; static const u8 frequency_div[] = { THC_SPI_FRQ_DIV_2, THC_SPI_FRQ_DIV_1, + THC_SPI_FRQ_DIV_1, THC_SPI_FRQ_DIV_7, THC_SPI_FRQ_DIV_6, THC_SPI_FRQ_DIV_5, THC_SPI_FRQ_DIV_4, THC_SPI_FRQ_DIV_3, + THC_SPI_FRQ_DIV_3, + THC_SPI_FRQ_DIV_2, }; int size = ARRAY_SIZE(frequency); u32 closest_freq; @@ -1190,6 +1199,25 @@ int thc_spi_read_config(struct thc_device *dev, u32 spi_freq_val, if (spi_freq_val < THC_SPI_LOW_FREQUENCY) is_low_freq = true; + /* 10M, 35M and 50M CLK need 1.5, 3.5 and 2.5 half divider */ + if ((freq_div == THC_SPI_FRQ_DIV_2 && spi_freq_val >= THC_SPI_FREQUENCY_50M) || + (freq_div == THC_SPI_FRQ_DIV_3 && spi_freq_val < THC_SPI_FREQUENCY_41M) || + (freq_div == THC_SPI_FRQ_DIV_1 && spi_freq_val < THC_SPI_FREQUENCY_15M)) { + regmap_write_bits(dev->thc_regmap, THC_M_PRT_SPI_DUTYC_CFG_OFFSET, + THC_M_PRT_SPI_DUTYC_CFG_SPI_TCRF_HALF_DIV_EN, + THC_M_PRT_SPI_DUTYC_CFG_SPI_TCRF_HALF_DIV_EN); + + regmap_write_bits(dev->thc_regmap, THC_M_PRT_SPARE_REG_OFFSET, + THC_M_PRT_SPARE_REG_SPI_CLK_INV_ENABLE, + THC_M_PRT_SPARE_REG_SPI_CLK_INV_ENABLE); + } else { + regmap_write_bits(dev->thc_regmap, THC_M_PRT_SPI_DUTYC_CFG_OFFSET, + THC_M_PRT_SPI_DUTYC_CFG_SPI_TCRF_HALF_DIV_EN, 0); + + regmap_write_bits(dev->thc_regmap, THC_M_PRT_SPARE_REG_OFFSET, + THC_M_PRT_SPARE_REG_SPI_CLK_INV_ENABLE, 0); + } + cfg = FIELD_PREP(THC_M_PRT_SPI_CFG_SPI_TCRF, freq_div) | FIELD_PREP(THC_M_PRT_SPI_CFG_SPI_TRMODE, io_mode) | (is_low_freq ? THC_M_PRT_SPI_CFG_SPI_LOW_FREQ_EN : 0) | @@ -1243,6 +1271,25 @@ int thc_spi_write_config(struct thc_device *dev, u32 spi_freq_val, if (spi_freq_val < THC_SPI_LOW_FREQUENCY) is_low_freq = true; + /* 10M, 35M and 50M CLK need 1.5, 3.5 and 2.5 half divider */ + if ((freq_div == THC_SPI_FRQ_DIV_2 && spi_freq_val >= THC_SPI_FREQUENCY_50M) || + (freq_div == THC_SPI_FRQ_DIV_3 && spi_freq_val < THC_SPI_FREQUENCY_41M) || + (freq_div == THC_SPI_FRQ_DIV_1 && spi_freq_val < THC_SPI_FREQUENCY_15M)) { + regmap_write_bits(dev->thc_regmap, THC_M_PRT_SPI_DUTYC_CFG_OFFSET, + THC_M_PRT_SPI_DUTYC_CFG_SPI_TCWF_HALF_DIV_EN, + THC_M_PRT_SPI_DUTYC_CFG_SPI_TCWF_HALF_DIV_EN); + + regmap_write_bits(dev->thc_regmap, THC_M_PRT_SPARE_REG_OFFSET, + THC_M_PRT_SPARE_REG_SPI_CLK_INV_ENABLE, + THC_M_PRT_SPARE_REG_SPI_CLK_INV_ENABLE); + } else { + regmap_write_bits(dev->thc_regmap, THC_M_PRT_SPI_DUTYC_CFG_OFFSET, + THC_M_PRT_SPI_DUTYC_CFG_SPI_TCWF_HALF_DIV_EN, 0); + + regmap_write_bits(dev->thc_regmap, THC_M_PRT_SPARE_REG_OFFSET, + THC_M_PRT_SPARE_REG_SPI_CLK_INV_ENABLE, 0); + } + cfg = FIELD_PREP(THC_M_PRT_SPI_CFG_SPI_TCWF, freq_div) | FIELD_PREP(THC_M_PRT_SPI_CFG_SPI_TWMODE, io_mode) | (is_low_freq ? THC_M_PRT_SPI_CFG_SPI_LOW_FREQ_EN : 0) | diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-hw.h b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-hw.h index 413730f8e3f7..c6d026686b7a 100644 --- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-hw.h +++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-hw.h @@ -643,6 +643,10 @@ #define THC_M_PRT_SPI_DUTYC_CFG_SPI_CSA_CK_DELAY_VAL GENMASK(3, 0) #define THC_M_PRT_SPI_DUTYC_CFG_SPI_CSA_CK_DELAY_EN BIT(25) +#define THC_M_PRT_SPI_DUTYC_CFG_SPI_TCRF_HALF_DIV_EN BIT(30) +#define THC_M_PRT_SPI_DUTYC_CFG_SPI_TCWF_HALF_DIV_EN BIT(31) + +#define THC_M_PRT_SPARE_REG_SPI_CLK_INV_ENABLE BIT(2) /* CS Assertion delay default value */ #define THC_CSA_CK_DELAY_VAL_DEFAULT 4 diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index ddd5d77fb5a5..fbbfc0f60829 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -1363,19 +1363,17 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id * { struct usb_host_interface *interface = intf->cur_altsetting; struct usb_device *dev = interface_to_usbdev(intf); + struct usb_endpoint_descriptor *ep; struct usbhid_device *usbhid; struct hid_device *hid; - unsigned int n, has_in = 0; size_t len; int ret; dbg_hid("HID probe called for ifnum %d\n", intf->altsetting->desc.bInterfaceNumber); - for (n = 0; n < interface->desc.bNumEndpoints; n++) - if (usb_endpoint_is_int_in(&interface->endpoint[n].desc)) - has_in++; - if (!has_in) { + ret = usb_find_int_in_endpoint(interface, &ep); + if (ret) { hid_err(intf, "couldn't find an input interrupt endpoint\n"); return -ENODEV; } @@ -1552,7 +1550,7 @@ static int hid_post_reset(struct usb_interface *intf) * configuration descriptors passed, we already know that * the size of the HID report descriptor has not changed. */ - rdesc = kmalloc(hid->dev_rsize, GFP_KERNEL); + rdesc = kmalloc(hid->dev_rsize, GFP_NOIO); if (!rdesc) return -ENOMEM; diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index fbf3dbc92e66..aee8a4443305 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -13,6 +13,7 @@ #include <linux/input.h> #include <linux/minmax.h> #include <linux/slab.h> +#include <linux/stringify.h> #include <linux/usb.h> #define PID_EFFECTS_MAX 64 @@ -81,7 +82,7 @@ static const u8 pidff_set_envelope[] = { 0x22, 0x5b, 0x5c, 0x5d, 0x5e }; #define PID_NEG_COEFFICIENT 4 #define PID_POS_SATURATION 5 #define PID_NEG_SATURATION 6 -#define PID_DEAD_BAND 7 +#define PID_DEADBAND 7 static const u8 pidff_set_condition[] = { 0x22, 0x23, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65 }; @@ -618,14 +619,24 @@ static void pidff_set_condition_report(struct pidff_device *pidff, effect->u.condition[i].center); pidff_set_signed(&pidff->set_condition[PID_POS_COEFFICIENT], effect->u.condition[i].right_coeff); - pidff_set_signed(&pidff->set_condition[PID_NEG_COEFFICIENT], - effect->u.condition[i].left_coeff); pidff_set(&pidff->set_condition[PID_POS_SATURATION], effect->u.condition[i].right_saturation); - pidff_set(&pidff->set_condition[PID_NEG_SATURATION], - effect->u.condition[i].left_saturation); - pidff_set(&pidff->set_condition[PID_DEAD_BAND], - effect->u.condition[i].deadband); + + /* Omit Negative Coefficient if missing */ + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_NEG_COEFFICIENT)) + pidff_set_signed(&pidff->set_condition[PID_NEG_COEFFICIENT], + effect->u.condition[i].left_coeff); + + /* Omit Negative Saturation if missing */ + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_NEG_SATURATION)) + pidff_set_signed(&pidff->set_condition[PID_NEG_SATURATION], + effect->u.condition[i].left_saturation); + + /* Omit Deadband field if missing */ + if (!(pidff->quirks & HID_PIDFF_QUIRK_MISSING_DEADBAND)) + pidff_set(&pidff->set_condition[PID_DEADBAND], + effect->u.condition[i].deadband); + hid_hw_request(pidff->hid, pidff->reports[PID_SET_CONDITION], HID_REQ_SET_REPORT); } @@ -1053,6 +1064,11 @@ static int pidff_find_field_with_usage(int *usage_index, return -1; } +#define PIDFF_MISSING_FIELD(name, quirks) \ + ({ pr_debug("%s field not found, but that's OK\n", __stringify(name)); \ + pr_debug("Setting MISSING_%s quirk\n", __stringify(name)); \ + *quirks |= HID_PIDFF_QUIRK_MISSING_ ## name; }) + /* * Find fields from a report and fill a pidff_usage */ @@ -1060,9 +1076,6 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, struct hid_report *report, int count, int strict, u32 *quirks) { - const u8 block_offset = pidff_set_condition[PID_PARAM_BLOCK_OFFSET]; - const u8 delay = pidff_set_effect[PID_START_DELAY]; - if (!report) { pr_debug("%s, null report\n", __func__); return -1; @@ -1080,17 +1093,23 @@ static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, continue; } - if (table[i] == delay) { - pr_debug("Delay field not found, but that's OK\n"); - pr_debug("Setting MISSING_DELAY quirk\n"); - *quirks |= HID_PIDFF_QUIRK_MISSING_DELAY; + /* Field quirks auto-detection */ + if (table[i] == pidff_set_effect[PID_START_DELAY]) + PIDFF_MISSING_FIELD(DELAY, quirks); + + else if (table[i] == pidff_set_condition[PID_PARAM_BLOCK_OFFSET]) + PIDFF_MISSING_FIELD(PBO, quirks); + + else if (table[i] == pidff_set_condition[PID_NEG_COEFFICIENT]) + PIDFF_MISSING_FIELD(NEG_COEFFICIENT, quirks); + + else if (table[i] == pidff_set_condition[PID_NEG_SATURATION]) + PIDFF_MISSING_FIELD(NEG_SATURATION, quirks); - } else if (table[i] == block_offset) { - pr_debug("PBO field not found, but that's OK\n"); - pr_debug("Setting MISSING_PBO quirk\n"); - *quirks |= HID_PIDFF_QUIRK_MISSING_PBO; + else if (table[i] == pidff_set_condition[PID_DEADBAND]) + PIDFF_MISSING_FIELD(DEADBAND, quirks); - } else if (strict) { + else if (strict) { pr_debug("failed to locate %d\n", i); return -1; } diff --git a/drivers/hid/usbhid/hid-pidff.h b/drivers/hid/usbhid/hid-pidff.h index f321f675e131..c413aa732842 100644 --- a/drivers/hid/usbhid/hid-pidff.h +++ b/drivers/hid/usbhid/hid-pidff.h @@ -21,6 +21,15 @@ /* Force all periodic effects to be uploaded as SINE */ #define HID_PIDFF_QUIRK_PERIODIC_SINE_ONLY BIT(4) +/* Allow devices with missing negative coefficient in the set condition usage */ +#define HID_PIDFF_QUIRK_MISSING_NEG_COEFFICIENT BIT(5) + +/* Allow devices with missing negative saturation in the set condition usage */ +#define HID_PIDFF_QUIRK_MISSING_NEG_SATURATION BIT(6) + +/* Allow devices with missing deadband in the set condition usage */ +#define HID_PIDFF_QUIRK_MISSING_DEADBAND BIT(7) + #ifdef CONFIG_HID_PID int hid_pidff_init(struct hid_device *hid); int hid_pidff_init_with_quirks(struct hid_device *hid, u32 initial_quirks); diff --git a/include/linux/device.h b/include/linux/device.h index f0d52e1a6e07..67cec9ec0cd0 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -190,6 +190,22 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr, 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. * @@ -208,6 +224,21 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr, 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. * @@ -217,6 +248,21 @@ ssize_t device_show_string(struct device *dev, struct device_attribute *attr, 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. * @_mode: File mode. diff --git a/include/linux/hid.h b/include/linux/hid.h index 31324609af4d..442a80d79e89 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -634,6 +634,38 @@ enum hid_battery_status { HID_BATTERY_REPORTED, /* Device sent unsolicited battery strength report */ }; +/** + * struct hid_battery - represents a single battery power supply + * @dev: pointer to the parent hid_device + * @ps: the power supply instance + * @min: minimum battery value from HID descriptor + * @max: maximum battery value from HID descriptor + * @report_type: HID report type (input/feature) + * @report_id: HID report ID for this battery + * @charge_status: current charging status + * @status: battery reporting status + * @capacity: current battery capacity (0-100) + * @avoid_query: if true, avoid querying battery (e.g., for stylus) + * @present: if true, battery is present (may be dynamic) + * @ratelimit_time: rate limiting for battery reports + * @list: list node for linking into hid_device's battery list + */ +struct hid_battery { + struct hid_device *dev; + struct power_supply *ps; + __s32 min; + __s32 max; + __s32 report_type; + __s32 report_id; + __s32 charge_status; + enum hid_battery_status status; + __s32 capacity; + bool avoid_query; + bool present; + ktime_t ratelimit_time; + struct list_head list; +}; + struct hid_driver; struct hid_ll_driver; @@ -670,20 +702,10 @@ struct hid_device { #ifdef CONFIG_HID_BATTERY_STRENGTH /* * Power supply information for HID devices which report - * battery strength. power_supply was successfully registered if - * battery is non-NULL. + * battery strength. Each battery is tracked separately in the + * batteries list. */ - struct power_supply *battery; - __s32 battery_capacity; - __s32 battery_min; - __s32 battery_max; - __s32 battery_report_type; - __s32 battery_report_id; - __s32 battery_charge_status; - enum hid_battery_status battery_status; - bool battery_avoid_query; - bool battery_present; - ktime_t battery_ratelimit_time; + struct list_head batteries; #endif unsigned long status; /* see STAT flags above */ @@ -699,6 +721,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; @@ -744,6 +767,15 @@ static inline void hid_set_drvdata(struct hid_device *hdev, void *data) dev_set_drvdata(&hdev->dev, data); } +#ifdef CONFIG_HID_BATTERY_STRENGTH +static inline struct hid_battery *hid_get_battery(struct hid_device *hdev) +{ + if (list_empty(&hdev->batteries)) + return NULL; + return list_first_entry(&hdev->batteries, struct hid_battery, list); +} +#endif + #define HID_GLOBAL_STACK_SIZE 4 #define HID_COLLECTION_STACK_SIZE 4 |
