Add OneXPlayer Configuration HID Driver
Subsystems (3)
Derek J. Clark
maintainerv4 cover Add OneXPlayer Configuration HID Driver
Adds an HID driver for OneXPlayer HID configuration devices. There are currently 2 generations of OneXPlayer HID protocol. The first (OneXPlayer F1 series) only provides an RGB control interface over HID. The Second (X1 mini series, G1 series, AOKZOE A1X) also includes a hardware level button mapping interface, vibration intensity settings, and the ability to switch output between xinput and a debug mode that can be used to debug the button mapping. Some devices (G1 Series, APEX) use a hybrid of Gen1 RGB control and Gen 2 controller settings. To ensure there is no conflicts when the driver is loaded, we skip creating the RGB interface for Gen 2 devices if there is a DMI match.
I'll also add a note that Gen 1 devices also have an interface for setting the key map and debug mode, but that is done entirely over a serial TTY device so it is not able to be added to this driver. There are also some "Gen 0" devices (OneXPlayer 2 Series) also use it, but the TTY interface also handles the RGB control so no support is provided by this driver for those interfaces.
---
v4:
- Make all delayed work part of drvdata & ensure they are canceled during remove.
v3: https://lore.kernel.org/linux-input/[email protected]/
- Ensure default button map is properly init during probe.
v2: https://lore.kernel.org/linux-input/[email protected]/
- Add DMI quirks for certain devices that ship with both GEN1 and GEN2
MCU to avoid clashing when initializing the RGB interface.
- Add left & right vibration intensity attributes.
- Add additional mappings for keyboard inputs.
- Add a delayed work trigger to re-apply settings after the MCU
completes initializing after a suspend/resume cycle.
v1: https://lore.kernel.org/linux-input/[email protected]/
Derek J. Clark (5):
HID: hid-oxp: Add OneXPlayer configuration driver
HID: hid-oxp: Add Second Generation RGB Control
HID: hid-oxp: Add Second Generation Gamepad Mode Switch
HID: hid-oxp: Add Button Mapping Interface
HID: hid-oxp: Add Vibration Intensity Attribute
MAINTAINERS | 6 + drivers/hid/Kconfig | 13 + drivers/hid/Makefile | 1 + drivers/hid/hid-ids.h | 6 + drivers/hid/hid-oxp.c | 1580 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1606 insertions(+) create mode 100644 drivers/hid/hid-oxp.c
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v4 1/5 HID: hid-oxp: Add OneXPlayer configuration driver
Adds OneXPlayer HID configuration driver. In this initial driver patch, add the RGB interface for the first generation of HID based RGB control.
This interface provides the following attributes:
- brightness: provided by the LED core, this works in a fairly unique way on this device. The hardware accepts 5 brightness values (0-4), which affects the brightness of the multicolor and animated effects built into the MCU firmware. For monocolor settings, the device expects the hardware brightness value to be pushed to maximum, then we apply brightness adjustments mathematically based on % (0-100). This leads to some odd conversion as we need the brightness slider to reach the full range, but it has no affect when incrementing between the division points for other effects.
- multi-intensity: provided by the LED core for red, green, and blue.
- effect: Allows the MCU to set 19 individual effects.
- effect_index: Lists the 19 valid effect names for the interface.
- enabled: Allows the MCU to toggle the RGB interface on/off.
- enabled_index: Lists the valid states for enabled.
- speed: Allows the MCU to set the animation rate for the various effects.
- speed_range: Lists the valid range of speed (0-9).
The MCU also has a few odd quirks that make sending multiple synchronous events challenging. It will essentially freeze if it receives another message before it has finished processing the last command. It also will not reply if you wait on it using a completion. To get around this, we do a 200ms sleep inside a work queue thread and debounce all but the most recent message using a 50ms mod_delayed_work. This will cache the last write, queue the work, then return so userspace can release its write thread. The work queue is only used for brightness/multi-intensity as that is the path likely to receive rapid successive writes.
---
v4:
- Make oxp_rgb_queue delayed work struct part of drvdata and properly init, add cancel during remove.
--- MAINTAINERS | 6 + drivers/hid/Kconfig | 12 + drivers/hid/Makefile | 1 + drivers/hid/hid-ids.h | 3 + drivers/hid/hid-oxp.c | 652 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 674 insertions(+) create mode 100644 drivers/hid/hid-oxp.c
MAINTAINERS +6 -0
@@ -19707,6 +19707,12 @@ S: Maintained F: drivers/mtd/nand/onenand/ F: include/linux/mtd/onenand*.h +ONEXPLAYER HID DRIVER +M: Derek J. Clark <[email protected]> +L: [email protected] +S: Maintained +F: drivers/hid/hid-oxp.c + ONEXPLAYER PLATFORM EC DRIVER M: Antheas Kapenekakis <[email protected]> M: Derek John Clark <[email protected]>
drivers/hid/Kconfig +12 -0
@@ -919,6 +919,18 @@ config HID_ORTEK - Ortek WKB-2000 - Skycable wireless presenter +config HID_OXP + tristate "OneXPlayer handheld controller configuration support" + depends on USB_HID + depends on LEDS_CLASS + depends on LEDS_CLASS_MULTICOLOR + help + Say Y here if you would like to enable support for OneXPlayer handheld + devices that come with RGB LED rings around the joysticks and macro buttons. + + To compile this driver as a module, choose M here: the module will + be called hid-oxp. + config HID_PANTHERLORD tristate "Pantherlord/GreenAsia game controller" help
drivers/hid/Makefile +1 -0
@@ -99,6 +99,7 @@ obj-$(CONFIG_HID_NTI) += hid-nti.o obj-$(CONFIG_HID_NTRIG) += hid-ntrig.o obj-$(CONFIG_HID_NVIDIA_SHIELD) += hid-nvidia-shield.o obj-$(CONFIG_HID_ORTEK) += hid-ortek.o +obj-$(CONFIG_HID_OXP) += hid-oxp.o obj-$(CONFIG_HID_PRODIKEYS) += hid-prodikeys.o obj-$(CONFIG_HID_PANTHERLORD) += hid-pl.o obj-$(CONFIG_HID_PENMOUNT) += hid-penmount.o
drivers/hid/hid-ids.h +3 -0
@@ -1131,6 +1131,9 @@#define USB_VENDOR_ID_NVIDIA 0x0955#define USB_DEVICE_ID_NVIDIA_THUNDERSTRIKE_CONTROLLER 0x7214 +#define USB_VENDOR_ID_CRSC 0x1a2c +#define USB_DEVICE_ID_ONEXPLAYER_GEN1 0xb001 +#define USB_VENDOR_ID_ONTRAK 0x0a07#define USB_DEVICE_ID_ONTRAK_ADU100 0x0064
drivers/hid/hid-oxp.c new file +652 -0
652 lines not on this page · raw message
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v4 2/5 HID: hid-oxp: Add Second Generation RGB Control
In reply to Derek J. ClarkAdds support for the second generation of RGB Control for OneXPlayer devices. The interface mirrors the first generation, with some differences to how messages are formatted.
Some devices have both a GEN1 MCU for RGB control and a GEN2 MCU for button mapping. To avoid conflicts, quirk these devices to skip RGB setup for the GEN2_USAGE_PAGE.
---
v2:
- Add DMI quirks table.
--- drivers/hid/Kconfig | 1 + drivers/hid/hid-ids.h | 3 + drivers/hid/hid-oxp.c | 151 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+)
drivers/hid/Kconfig +1 -0
@@ -924,6 +924,7 @@ config HID_OXP depends on USB_HID depends on LEDS_CLASS depends on LEDS_CLASS_MULTICOLOR + depends on DMI help Say Y here if you would like to enable support for OneXPlayer handheld devices that come with RGB LED rings around the joysticks and macro buttons.
drivers/hid/hid-ids.h +3 -0
@@ -1134,6 +1134,9 @@#define USB_VENDOR_ID_CRSC 0x1a2c#define USB_DEVICE_ID_ONEXPLAYER_GEN1 0xb001 +#define USB_VENDOR_ID_WCH 0x1a86 +#define USB_DEVICE_ID_ONEXPLAYER_GEN2 0xfe00 +#define USB_VENDOR_ID_ONTRAK 0x0a07#define USB_DEVICE_ID_ONTRAK_ADU100 0x0064
drivers/hid/hid-oxp.c +151 -0
247 lines not on this page · raw message
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v4 3/5 HID: hid-oxp: Add Second Generation Gamepad Mode Switch
In reply to Derek J. ClarkAdds "gamepad_mode" attribute to second generation OneXPlayer configuration HID devices. This attribute initiates a mode shift in the device MCU that puts it into a state where all events are routed to an hidraw interface instead of the xpad evdev interface. This allows for debugging the hardware input mapping added in the next patch.
---
v4:
- Add oxp_mcu_init delayed work struct to drvdata & properly init, add cancel delayed work during remove.
v2:
- Rename to gamepad_mode & show relevant gamepad modes instead of using a debug enable/disable paradigm, to match other drivers.
--- drivers/hid/hid-oxp.c | 131 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+)
drivers/hid/hid-oxp.c +131 -0
@@ -33,20 +33,33 @@enum oxp_function_index {OXP_FID_GEN1_RGB_SET =0x07 ,OXP_FID_GEN1_RGB_REPLY =0x0f , +OXP_FID_GEN2_TOGGLE_MODE =0xb2 ,OXP_FID_GEN2_STATUS_EVENT =0xb8 , };static struct oxp_hid_cfg {struct delayed_work oxp_rgb_queue; +struct delayed_work oxp_mcu_init;struct led_classdev_mc *led_mc;struct hid_device *hdev;struct mutex cfg_mutex;/*ensure single synchronous output report*/ u8 rgb_brightness; +u8 gamepad_mode;u8 rgb_effect;u8 rgb_speed;u8 rgb_en; } drvdata; +enum oxp_gamepad_mode_index { +OXP_GP_MODE_XINPUT =0x00 , +OXP_GP_MODE_DEBUG =0x03 , +}; + +static const char *const oxp_gamepad_mode_text[] = { + [OXP_GP_MODE_XINPUT ] ="xinput" , + [OXP_GP_MODE_DEBUG ] ="debug" , +}; +enum oxp_feature_en_index {OXP_FEAT_DISABLED ,OXP_FEAT_ENABLED ,
@@ -182,6 +195,30 @@ static int oxp_hid_raw_event_gen_1(struct hid_device *hdev,return 0 ; } +static int oxp_gen_2_property_out (enum oxp_function_index fid,u8 *data,u8 data_size); + +static void oxp_mcu_init_fn (struct work_struct *work) +{ +u8 gp_mode_data[3 ] = {OXP_GP_MODE_DEBUG ,0x01 ,0x02 }; +int ret; + +/* Cycle the gamepad mode */ + ret =oxp_gen_2_property_out (OXP_FID_GEN2_TOGGLE_MODE , gp_mode_data,3 ); +if (ret) +dev_err (&drvdata.hdev->dev, +"Error: Failed to set gamepad mode: %i\n" , ret); + +/* Remainder only applies for xinput mode */ +if (drvdata.gamepad_mode ==OXP_GP_MODE_DEBUG ) +return ; + + gp_mode_data[0 ] =OXP_GP_MODE_XINPUT ; + ret =oxp_gen_2_property_out (OXP_FID_GEN2_TOGGLE_MODE , gp_mode_data,3 ); +if (ret) +dev_err (&drvdata.hdev->dev, +"Error: Failed to set gamepad mode: %i\n" , ret); +} +static int oxp_hid_raw_event_gen_2 (struct hid_device *hdev,struct hid_report *report,u8 *data,int size)
@@ -192,6 +229,14 @@ static int oxp_hid_raw_event_gen_2(struct hid_device *hdev,if (data[0 ] !=OXP_FID_GEN2_STATUS_EVENT )return 0 ; +/* Sent ~6s after resume event, indicating the MCU has fully reset. +* Re-apply our settings after this has been received. +*/ +if (data[3 ] ==OXP_EFFECT_MONO_TRUE ) { +mod_delayed_work (system_wq, &drvdata.oxp_mcu_init,msecs_to_jiffies (50 )); +return 0 ; + } +if (data[3 ] !=OXP_GET_PROPERTY )return 0 ;
@@ -289,6 +334,77 @@ static int oxp_gen_2_property_out(enum oxp_function_index fid, u8 *data, footer_size); } +static ssize_t gamepad_mode_store (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t count) +{ +u16 up =get_usage_page (drvdata.hdev); +u8 data[3 ] = {0x00 ,0x01 ,0x02 }; +int ret = -EINVAL ; +int i; + +if (up !=GEN2_USAGE_PAGE ) +return ret; + +for (i =0 ; i <ARRAY_SIZE (oxp_gamepad_mode_text); i++) { +if (oxp_gamepad_mode_text[i] &&sysfs_streq (buf, oxp_gamepad_mode_text[i])) { + ret = i; +break ; + } + } +if (ret <0 ) +return ret; + + data[0 ] = ret; + + ret =oxp_gen_2_property_out (OXP_FID_GEN2_TOGGLE_MODE , data,3 ); +if (ret) +return ret; + + drvdata.gamepad_mode = data[0 ]; + +return count; +} + +static ssize_t gamepad_mode_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%s\n" , oxp_gamepad_mode_text[drvdata.gamepad_mode]); +} +static DEVICE_ATTR_RW (gamepad_mode); + +static ssize_t gamepad_mode_index_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +ssize_t count =0 ; +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (oxp_gamepad_mode_text); i++) { +if (!oxp_gamepad_mode_text[i] || + oxp_gamepad_mode_text[i][0 ] =='\0' ) +continue ; + + count +=sysfs_emit_at (buf, count,"%s " , oxp_gamepad_mode_text[i]); + } + +if (count) + buf[count -1 ] ='\n' ; + +return count; +} +static DEVICE_ATTR_RO (gamepad_mode_index); + +static struct attribute *oxp_cfg_attrs[] = { + &dev_attr_gamepad_mode.attr, + &dev_attr_gamepad_mode_index.attr, +NULL , +}; + +static const struct attribute_group oxp_cfg_attrs_group = { + .attrs = oxp_cfg_attrs, +}; +static int oxp_rgb_status_store (u8 enabled,u8 speed,u8 brightness) {u16 up =get_usage_page (drvdata.hdev);
@@ -733,7 +849,21 @@ static int oxp_cfg_probe(struct hid_device *hdev, u16 up)dev_warn (drvdata.led_mc->led_cdev.dev,"Failed to query RGB initial state: %i\n" , ret); +/* Below features are only implemented in gen 2 */ +if (up !=GEN2_USAGE_PAGE ) +return 0 ; + skip_rgb: + drvdata.gamepad_mode =OXP_GP_MODE_XINPUT ; + +INIT_DELAYED_WORK (&drvdata.oxp_mcu_init, oxp_mcu_init_fn); +mod_delayed_work (system_wq, &drvdata.oxp_mcu_init,msecs_to_jiffies (50 )); + + ret =devm_device_add_group (&hdev->dev, &oxp_cfg_attrs_group); +if (ret) +return dev_err_probe (&hdev->dev, ret, +"Failed to attach configuration attributes\n" ); +return 0 ; }
@@ -778,6 +908,7 @@ static int oxp_hid_probe(struct hid_device *hdev,static void oxp_hid_remove (struct hid_device *hdev) {cancel_delayed_work (&drvdata.oxp_rgb_queue); +cancel_delayed_work (&drvdata.oxp_mcu_init);hid_hw_close (hdev);hid_hw_stop (hdev); }
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v4 4/5 HID: hid-oxp: Add Button Mapping Interface
In reply to Derek J. ClarkAdds button mapping interface for second generation OneXPlayer configuration HID interfaces. This interface allows the MCU to swap button mappings at the hardware level. The current state cannot be retrieved, and the mappings may have been modified in Windows prior, so we reset the button mapping at init and expose an attribute to allow userspace to do this again at any time.
The interface requires two pages of button mapping data to be sent before the settings will take place. Since the MCU requires a 200ms delay after each message (total 400ms for these attributes) use the same debounce work queue method we used for RGB. This will allow for userspace or udev rules to rapidly map all buttons. The values will be cached before the final write is finally sent to the device.
---
v4:
- Make oxp_btn_queue delayed work struct part of drvdata, add cancel delayed work during remove.
v3:
- Ensure default button map is properly init during probe.
v2:
- Add detection of post-suspend MCU init to trigger setting the button map again.
--- drivers/hid/hid-oxp.c | 568 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 568 insertions(+)
drivers/hid/hid-oxp.c +568 -0
@@ -34,11 +34,147 @@ enum oxp_function_index {OXP_FID_GEN1_RGB_SET =0x07 ,OXP_FID_GEN1_RGB_REPLY =0x0f ,OXP_FID_GEN2_TOGGLE_MODE =0xb2 , +OXP_FID_GEN2_KEY_STATE =0xb4 , OXP_FID_GEN2_STATUS_EVENT = 0xb8, }; +#define OXP_MAPPING_GAMEPAD 0x01 +#define OXP_MAPPING_KEYBOARD 0x02 + +struct oxp_button_data { +u8 mode; +u8 index; +u8 key_id; +u8 padding[2 ]; +} __packed; + +struct oxp_button_entry { +struct oxp_button_data data; +const char *name; +}; + +static const struct oxp_button_entry oxp_button_table[] = { +/* Gamepad Buttons */ + { {OXP_MAPPING_GAMEPAD ,0x01 },"BTN_A" }, + { {OXP_MAPPING_GAMEPAD ,0x02 },"BTN_B" }, + { {OXP_MAPPING_GAMEPAD ,0x03 },"BTN_X" }, + { {OXP_MAPPING_GAMEPAD ,0x04 },"BTN_Y" }, + { {OXP_MAPPING_GAMEPAD ,0x05 },"BTN_LB" }, + { {OXP_MAPPING_GAMEPAD ,0x06 },"BTN_RB" }, + { {OXP_MAPPING_GAMEPAD ,0x07 },"BTN_LT" }, + { {OXP_MAPPING_GAMEPAD ,0x08 },"BTN_RT" }, + { {OXP_MAPPING_GAMEPAD ,0x09 },"BTN_START" }, + { {OXP_MAPPING_GAMEPAD ,0x0a },"BTN_SELECT" }, + { {OXP_MAPPING_GAMEPAD ,0x0b },"BTN_L3" }, + { {OXP_MAPPING_GAMEPAD ,0x0c },"BTN_R3" }, + { {OXP_MAPPING_GAMEPAD ,0x0d },"DPAD_UP" }, + { {OXP_MAPPING_GAMEPAD ,0x0e },"DPAD_DOWN" }, + { {OXP_MAPPING_GAMEPAD ,0x0f },"DPAD_LEFT" }, + { {OXP_MAPPING_GAMEPAD ,0x10 },"DPAD_RIGHT" }, + { {OXP_MAPPING_GAMEPAD ,0x11 },"JOY_L_UP" }, + { {OXP_MAPPING_GAMEPAD ,0x12 },"JOY_L_UP_RIGHT" }, + { {OXP_MAPPING_GAMEPAD ,0x13 },"JOY_L_RIGHT" }, + { {OXP_MAPPING_GAMEPAD ,0x14 },"JOY_L_DOWN_RIGHT" }, + { {OXP_MAPPING_GAMEPAD ,0x15 },"JOY_L_DOWN" }, + { {OXP_MAPPING_GAMEPAD ,0x16 },"JOY_L_DOWN_LEFT" }, + { {OXP_MAPPING_GAMEPAD ,0x17 },"JOY_L_LEFT" }, + { {OXP_MAPPING_GAMEPAD ,0x18 },"JOY_L_UP_LEFT" }, + { {OXP_MAPPING_GAMEPAD ,0x19 },"JOY_R_UP" }, + { {OXP_MAPPING_GAMEPAD ,0x1a },"JOY_R_UP_RIGHT" }, + { {OXP_MAPPING_GAMEPAD ,0x1b },"JOY_R_RIGHT" }, + { {OXP_MAPPING_GAMEPAD ,0x1c },"JOY_R_DOWN_RIGHT" }, + { {OXP_MAPPING_GAMEPAD ,0x1d },"JOY_R_DOWN" }, + { {OXP_MAPPING_GAMEPAD ,0x1e },"JOY_R_DOWN_LEFT" }, + { {OXP_MAPPING_GAMEPAD ,0x1f },"JOY_R_LEFT" }, + { {OXP_MAPPING_GAMEPAD ,0x20 },"JOY_R_UP_LEFT" }, + { {OXP_MAPPING_GAMEPAD ,0x22 },"BTN_GUIDE" }, +/* Keyboard Keys */ + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x5a },"KEY_F1" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x5b },"KEY_F2" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x5c },"KEY_F3" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x5d },"KEY_F4" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x5e },"KEY_F5" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x5f },"KEY_F6" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x60 },"KEY_F7" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x61 },"KEY_F8" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x62 },"KEY_F9" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x63 },"KEY_F10" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x64 },"KEY_F11" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x65 },"KEY_F12" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x66 },"KEY_F13" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x67 },"KEY_F14" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x68 },"KEY_F15" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x69 },"KEY_F16" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x6a },"KEY_F17" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x6b },"KEY_F18" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x6c },"KEY_F19" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x6d },"KEY_F20" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x6e },"KEY_F21" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x6f },"KEY_F22" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x70 },"KEY_F23" }, + { {OXP_MAPPING_KEYBOARD ,0x01 ,0x71 },"KEY_F24" }, +}; + +enum oxp_joybutton_index { +BUTTON_A =0x01 , +BUTTON_B , +BUTTON_X , +BUTTON_Y , +BUTTON_LB , +BUTTON_RB , +BUTTON_LT , +BUTTON_RT , +BUTTON_START , +BUTTON_SELECT , +BUTTON_L3 , +BUTTON_R3 , +BUTTON_DUP , +BUTTON_DDOWN , +BUTTON_DLEFT , +BUTTON_DRIGHT , +BUTTON_M1 =0x22 , +BUTTON_M2 , +/* These are unused currently, reserved for future devices */ +BUTTON_M3 , +BUTTON_M4 , +BUTTON_M5 , +BUTTON_M6 , +}; + +struct oxp_button_idx { +enum oxp_joybutton_index button_idx; +u8 mapping_idx; +} __packed; + +struct oxp_bmap_page_1 { +struct oxp_button_idx btn_a; +struct oxp_button_idx btn_b; +struct oxp_button_idx btn_x; +struct oxp_button_idx btn_y; +struct oxp_button_idx btn_lb; +struct oxp_button_idx btn_rb; +struct oxp_button_idx btn_lt; +struct oxp_button_idx btn_rt; +struct oxp_button_idx btn_start; +} __packed; + +struct oxp_bmap_page_2 { +struct oxp_button_idx btn_select; +struct oxp_button_idx btn_l3; +struct oxp_button_idx btn_r3; +struct oxp_button_idx btn_dup; +struct oxp_button_idx btn_ddown; +struct oxp_button_idx btn_dleft; +struct oxp_button_idx btn_dright; +struct oxp_button_idx btn_m1; +struct oxp_button_idx btn_m2; +} __packed; + static struct oxp_hid_cfg { struct delayed_work oxp_rgb_queue; + struct delayed_work oxp_btn_queue; + struct oxp_bmap_page_1 *bmap_1; + struct oxp_bmap_page_2 *bmap_2; struct delayed_work oxp_mcu_init; struct led_classdev_mc *led_mc; struct hid_device *hdev;
@@ -50,6 +186,10 @@ static struct oxp_hid_cfg {u8 rgb_en; } drvdata; +#define OXP_FILL_PAGE_SLOT (page, btn) \ + { .button_idx = (page)->btn.button_idx, \ + .mapping_idx = (page)->btn.mapping_idx } +enum oxp_gamepad_mode_index {OXP_GP_MODE_XINPUT =0x00 ,OXP_GP_MODE_DEBUG =0x03 ,
@@ -155,6 +295,10 @@ struct oxp_gen_2_rgb_report {u8 effect; } __packed; +struct oxp_attr { +u8 index; +}; +static u16 get_usage_page (struct hid_device *hdev) {return hdev->collection[0 ].usage >>16 ;
@@ -196,12 +340,19 @@ static int oxp_hid_raw_event_gen_1(struct hid_device *hdev, }static int oxp_gen_2_property_out (enum oxp_function_index fid,u8 *data,u8 data_size); +static int oxp_set_buttons (void );static void oxp_mcu_init_fn (struct work_struct *work) {u8 gp_mode_data[3 ] = {OXP_GP_MODE_DEBUG ,0x01 ,0x02 };int ret; +/* Re-apply the button mapping */ + ret =oxp_set_buttons (); +if (ret) +dev_err (&drvdata.hdev->dev, +"Error: Failed to set button mapping: %i\n" , ret); +/* Cycle the gamepad mode */ ret =oxp_gen_2_property_out (OXP_FID_GEN2_TOGGLE_MODE , gp_mode_data,3 );if (ret)
@@ -395,9 +546,408 @@ static ssize_t gamepad_mode_index_show(struct device *dev, }static DEVICE_ATTR_RO (gamepad_mode_index); +static void oxp_set_defaults_bmap_1 (struct oxp_bmap_page_1 *bmap) +{ + bmap->btn_a.button_idx =BUTTON_A ; + bmap->btn_a.mapping_idx =0 ; + bmap->btn_b.button_idx =BUTTON_B ; + bmap->btn_b.mapping_idx =1 ; + bmap->btn_x.button_idx =BUTTON_X ; + bmap->btn_x.mapping_idx =2 ; + bmap->btn_y.button_idx =BUTTON_Y ; + bmap->btn_y.mapping_idx =3 ; + bmap->btn_lb.button_idx =BUTTON_LB ; + bmap->btn_lb.mapping_idx =4 ; + bmap->btn_rb.button_idx =BUTTON_RB ; + bmap->btn_rb.mapping_idx =5 ; + bmap->btn_lt.button_idx =BUTTON_LT ; + bmap->btn_lt.mapping_idx =6 ; + bmap->btn_rt.button_idx =BUTTON_RT ; + bmap->btn_rt.mapping_idx =7 ; + bmap->btn_start.button_idx =BUTTON_START ; + bmap->btn_start.mapping_idx =8 ; +} + +static void oxp_set_defaults_bmap_2 (struct oxp_bmap_page_2 *bmap) +{ + bmap->btn_select.button_idx =BUTTON_SELECT ; + bmap->btn_select.mapping_idx =9 ; + bmap->btn_l3.button_idx =BUTTON_L3 ; + bmap->btn_l3.mapping_idx =10 ; + bmap->btn_r3.button_idx =BUTTON_R3 ; + bmap->btn_r3.mapping_idx =11 ; + bmap->btn_dup.button_idx =BUTTON_DUP ; + bmap->btn_dup.mapping_idx =12 ; + bmap->btn_ddown.button_idx =BUTTON_DDOWN ; + bmap->btn_ddown.mapping_idx =13 ; + bmap->btn_dleft.button_idx =BUTTON_DLEFT ; + bmap->btn_dleft.mapping_idx =14 ; + bmap->btn_dright.button_idx =BUTTON_DRIGHT ; + bmap->btn_dright.mapping_idx =15 ; + bmap->btn_m1.button_idx =BUTTON_M1 ; + bmap->btn_m1.mapping_idx =48 ;/* KEY_F15 */ + bmap->btn_m2.button_idx =BUTTON_M2 ; + bmap->btn_m2.mapping_idx =49 ;/* KEY_F16 */ +} + +static void oxp_page_fill_data (char *buf,const struct oxp_button_idx *buttons, +size_t len) +{ +size_t offset_increment =sizeof (u8) +sizeof (struct oxp_button_idx ); +size_t offset =5 ; +unsigned int i; + +for (i =0 ; i < len; i++, offset += offset_increment) { + buf[offset] = (u8 )buttons[i].button_idx; +memcpy (buf + offset +1 , + &oxp_button_table[buttons[i].mapping_idx].data, +sizeof (struct oxp_button_data )); + } +} + +static int oxp_set_buttons (void ) +{ +u8 page_1[59 ] = {0x02 ,0x38 ,0x20 ,0x01 ,0x01 }; +u8 page_2[59 ] = {0x02 ,0x38 ,0x20 ,0x02 ,0x01 }; +u16 up =get_usage_page (drvdata.hdev); +int ret; + +if (up !=GEN2_USAGE_PAGE ) +return -EINVAL ; + +const struct oxp_button_idx p1[] = { +OXP_FILL_PAGE_SLOT (drvdata.bmap_1, btn_a), +OXP_FILL_PAGE_SLOT (drvdata.bmap_1, btn_b), +OXP_FILL_PAGE_SLOT (drvdata.bmap_1, btn_x), +OXP_FILL_PAGE_SLOT (drvdata.bmap_1, btn_y), +OXP_FILL_PAGE_SLOT (drvdata.bmap_1, btn_lb), +OXP_FILL_PAGE_SLOT (drvdata.bmap_1, btn_rb), +OXP_FILL_PAGE_SLOT (drvdata.bmap_1, btn_lt), +OXP_FILL_PAGE_SLOT (drvdata.bmap_1, btn_rt), +OXP_FILL_PAGE_SLOT (drvdata.bmap_1, btn_start), + }; + +const struct oxp_button_idx p2[] = { +OXP_FILL_PAGE_SLOT (drvdata.bmap_2, btn_select), +OXP_FILL_PAGE_SLOT (drvdata.bmap_2, btn_l3), +OXP_FILL_PAGE_SLOT (drvdata.bmap_2, btn_r3), +OXP_FILL_PAGE_SLOT (drvdata.bmap_2, btn_dup), +OXP_FILL_PAGE_SLOT (drvdata.bmap_2, btn_ddown), +OXP_FILL_PAGE_SLOT (drvdata.bmap_2, btn_dleft), +OXP_FILL_PAGE_SLOT (drvdata.bmap_2, btn_dright), +OXP_FILL_PAGE_SLOT (drvdata.bmap_2, btn_m1), +OXP_FILL_PAGE_SLOT (drvdata.bmap_2, btn_m2), + }; + +oxp_page_fill_data (page_1, p1,ARRAY_SIZE (p1)); +oxp_page_fill_data (page_2, p2,ARRAY_SIZE (p2)); + + ret =oxp_gen_2_property_out (OXP_FID_GEN2_KEY_STATE , page_1,ARRAY_SIZE (page_1)); +if (ret) +return ret; + +return oxp_gen_2_property_out (OXP_FID_GEN2_KEY_STATE , page_2,ARRAY_SIZE (page_2)); +} + +static void oxp_reset_buttons (void ) +{ +oxp_set_defaults_bmap_1 (drvdata.bmap_1); +oxp_set_defaults_bmap_2 (drvdata.bmap_2); +} + +static ssize_t reset_buttons_store (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t count) +{ +int val, ret; + + ret =kstrtoint (buf,10 , &val); +if (ret) +return ret; + +if (val !=1 ) +return -EINVAL ; + +oxp_reset_buttons (); + ret =oxp_set_buttons (); +if (ret) +return ret; + +return count; +} +static DEVICE_ATTR_WO (reset_buttons); + +static void oxp_btn_queue_fn (struct work_struct *work) +{ +int ret; + + ret =oxp_set_buttons (); +if (ret) +dev_err (&drvdata.hdev->dev, +"Error: Failed to write button mapping: %i\n" , ret); +} + +static int oxp_button_idx_from_str (const char *buf) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (oxp_button_table); i++) +if (sysfs_streq (buf, oxp_button_table[i].name)) +return i; + +return -EINVAL ; +} + +static ssize_t map_button_store (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t count,u8 index) +{ +int idx; + + idx =oxp_button_idx_from_str (buf); +if (idx <0 ) +return idx; + +switch (index) { +case BUTTON_A : + drvdata.bmap_1->btn_a.mapping_idx = idx; +break ; +case BUTTON_B : + drvdata.bmap_1->btn_b.mapping_idx = idx; +break ; +case BUTTON_X : + drvdata.bmap_1->btn_x.mapping_idx = idx; +break ; +case BUTTON_Y : + drvdata.bmap_1->btn_y.mapping_idx = idx; +break ; +case BUTTON_LB : + drvdata.bmap_1->btn_lb.mapping_idx = idx; +break ; +case BUTTON_RB : + drvdata.bmap_1->btn_rb.mapping_idx = idx; +break ; +case BUTTON_LT : + drvdata.bmap_1->btn_lt.mapping_idx = idx; +break ; +case BUTTON_RT : + drvdata.bmap_1->btn_rt.mapping_idx = idx; +break ; +case BUTTON_START : + drvdata.bmap_1->btn_start.mapping_idx = idx; +break ; +case BUTTON_SELECT : + drvdata.bmap_2->btn_select.mapping_idx = idx; +break ; +case BUTTON_L3 : + drvdata.bmap_2->btn_l3.mapping_idx = idx; +break ; +case BUTTON_R3 : + drvdata.bmap_2->btn_r3.mapping_idx = idx; +break ; +case BUTTON_DUP : + drvdata.bmap_2->btn_dup.mapping_idx = idx; +break ; +case BUTTON_DDOWN : + drvdata.bmap_2->btn_ddown.mapping_idx = idx; +break ; +case BUTTON_DLEFT : + drvdata.bmap_2->btn_dleft.mapping_idx = idx; +break ; +case BUTTON_DRIGHT : + drvdata.bmap_2->btn_dright.mapping_idx = idx; +break ; +case BUTTON_M1 : + drvdata.bmap_2->btn_m1.mapping_idx = idx; +break ; +case BUTTON_M2 : + drvdata.bmap_2->btn_m2.mapping_idx = idx; +break ; +default : +return -EINVAL ; + } +mod_delayed_work (system_wq, &drvdata.oxp_btn_queue,msecs_to_jiffies (50 )); +return count; +} + +static ssize_t map_button_show (struct device *dev, +struct device_attribute *attr,char *buf, +u8 index) +{ +u8 i; + +switch (index) { +case BUTTON_A : + i = drvdata.bmap_1->btn_a.mapping_idx; +break ; +case BUTTON_B : + i = drvdata.bmap_1->btn_b.mapping_idx; +break ; +case BUTTON_X : + i = drvdata.bmap_1->btn_x.mapping_idx; +break ; +case BUTTON_Y : + i = drvdata.bmap_1->btn_y.mapping_idx; +break ; +case BUTTON_LB : + i = drvdata.bmap_1->btn_lb.mapping_idx; +break ; +case BUTTON_RB : + i = drvdata.bmap_1->btn_rb.mapping_idx; +break ; +case BUTTON_LT : + i = drvdata.bmap_1->btn_lt.mapping_idx; +break ; +case BUTTON_RT : + i = drvdata.bmap_1->btn_rt.mapping_idx; +break ; +case BUTTON_START : + i = drvdata.bmap_1->btn_start.mapping_idx; +break ; +case BUTTON_SELECT : + i = drvdata.bmap_2->btn_select.mapping_idx; +break ; +case BUTTON_L3 : + i = drvdata.bmap_2->btn_l3.mapping_idx; +break ; +case BUTTON_R3 : + i = drvdata.bmap_2->btn_r3.mapping_idx; +break ; +case BUTTON_DUP : + i = drvdata.bmap_2->btn_dup.mapping_idx; +break ; +case BUTTON_DDOWN : + i = drvdata.bmap_2->btn_ddown.mapping_idx; +break ; +case BUTTON_DLEFT : + i = drvdata.bmap_2->btn_dleft.mapping_idx; +break ; +case BUTTON_DRIGHT : + i = drvdata.bmap_2->btn_dright.mapping_idx; +break ; +case BUTTON_M1 : + i = drvdata.bmap_2->btn_m1.mapping_idx; +break ; +case BUTTON_M2 : + i = drvdata.bmap_2->btn_m2.mapping_idx; +break ; +default : +return -EINVAL ; + } + +if (i >=ARRAY_SIZE (oxp_button_table)) +return -EINVAL ; + +return sysfs_emit (buf,"%s\n" , oxp_button_table[i].name); +} + +static ssize_t button_mapping_options_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +ssize_t count =0 ; +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (oxp_button_table); i++) + count +=sysfs_emit_at (buf, count,"%s " , oxp_button_table[i].name); + +if (count) + buf[count -1 ] ='\n' ; + +return count; +} +static DEVICE_ATTR_RO (button_mapping_options); + +#define OXP_DEVICE_ATTR_RW (_name, _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); \ + } \ + static ssize_t _name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ + { \ + return _group##_show(dev, attr, buf, _name.index); \ + } \ + static DEVICE_ATTR_RW(_name) + +static struct oxp_attr button_a = {BUTTON_A }; +OXP_DEVICE_ATTR_RW (button_a, map_button); + +static struct oxp_attr button_b = {BUTTON_B }; +OXP_DEVICE_ATTR_RW (button_b, map_button); + +static struct oxp_attr button_x = {BUTTON_X }; +OXP_DEVICE_ATTR_RW (button_x, map_button); + +static struct oxp_attr button_y = {BUTTON_Y }; +OXP_DEVICE_ATTR_RW (button_y, map_button); + +static struct oxp_attr button_lb = {BUTTON_LB }; +OXP_DEVICE_ATTR_RW (button_lb, map_button); + +static struct oxp_attr button_rb = {BUTTON_RB }; +OXP_DEVICE_ATTR_RW (button_rb, map_button); + +static struct oxp_attr button_lt = {BUTTON_LT }; +OXP_DEVICE_ATTR_RW (button_lt, map_button); + +static struct oxp_attr button_rt = {BUTTON_RT }; +OXP_DEVICE_ATTR_RW (button_rt, map_button); + +static struct oxp_attr button_start = {BUTTON_START }; +OXP_DEVICE_ATTR_RW (button_start, map_button); + +static struct oxp_attr button_select = {BUTTON_SELECT }; +OXP_DEVICE_ATTR_RW (button_select, map_button); + +static struct oxp_attr button_l3 = {BUTTON_L3 }; +OXP_DEVICE_ATTR_RW (button_l3, map_button); + +static struct oxp_attr button_r3 = {BUTTON_R3 }; +OXP_DEVICE_ATTR_RW (button_r3, map_button); + +static struct oxp_attr button_d_up = {BUTTON_DUP }; +OXP_DEVICE_ATTR_RW (button_d_up, map_button); + +static struct oxp_attr button_d_down = {BUTTON_DDOWN }; +OXP_DEVICE_ATTR_RW (button_d_down, map_button); + +static struct oxp_attr button_d_left = {BUTTON_DLEFT }; +OXP_DEVICE_ATTR_RW (button_d_left, map_button); + +static struct oxp_attr button_d_right = {BUTTON_DRIGHT }; +OXP_DEVICE_ATTR_RW (button_d_right, map_button); + +static struct oxp_attr button_m1 = {BUTTON_M1 }; +OXP_DEVICE_ATTR_RW (button_m1, map_button); + +static struct oxp_attr button_m2 = {BUTTON_M2 }; +OXP_DEVICE_ATTR_RW (button_m2, map_button); +static struct attribute *oxp_cfg_attrs[] = { + &dev_attr_button_a.attr, + &dev_attr_button_b.attr, + &dev_attr_button_d_down.attr, + &dev_attr_button_d_left.attr, + &dev_attr_button_d_right.attr, + &dev_attr_button_d_up.attr, + &dev_attr_button_l3.attr, + &dev_attr_button_lb.attr, + &dev_attr_button_lt.attr, + &dev_attr_button_m1.attr, + &dev_attr_button_m2.attr, + &dev_attr_button_mapping_options.attr, + &dev_attr_button_r3.attr, + &dev_attr_button_rb.attr, + &dev_attr_button_rt.attr, + &dev_attr_button_select.attr, + &dev_attr_button_start.attr, + &dev_attr_button_x.attr, + &dev_attr_button_y.attr, &dev_attr_gamepad_mode.attr, &dev_attr_gamepad_mode_index.attr, + &dev_attr_reset_buttons.attr,NULL , };
@@ -821,6 +1371,8 @@ static bool oxp_hybrid_mcu_device(void)static int oxp_cfg_probe (struct hid_device *hdev,u16 up) { +struct oxp_bmap_page_1 *bmap_1; +struct oxp_bmap_page_2 *bmap_2;int ret;hid_set_drvdata (hdev, &drvdata);
@@ -854,6 +1406,21 @@ static int oxp_cfg_probe(struct hid_device *hdev, u16 up)return 0 ; skip_rgb: + bmap_1 =devm_kzalloc (&hdev->dev,sizeof (struct oxp_bmap_page_1 ),GFP_KERNEL ); +if (!bmap_1) +return dev_err_probe (&hdev->dev, -ENOMEM , +"Unable to allocate button map page 1\n" ); + + bmap_2 =devm_kzalloc (&hdev->dev,sizeof (struct oxp_bmap_page_2 ),GFP_KERNEL ); +if (!bmap_2) +return dev_err_probe (&hdev->dev, -ENOMEM , +"Unable to allocate button map page 2\n" ); + + drvdata.bmap_1 = bmap_1; + drvdata.bmap_2 = bmap_2; +oxp_reset_buttons (); +INIT_DELAYED_WORK (&drvdata.oxp_btn_queue, oxp_btn_queue_fn); + drvdata.gamepad_mode =OXP_GP_MODE_XINPUT ;INIT_DELAYED_WORK (&drvdata.oxp_mcu_init, oxp_mcu_init_fn);
@@ -908,6 +1475,7 @@ static int oxp_hid_probe(struct hid_device *hdev,static void oxp_hid_remove (struct hid_device *hdev) {cancel_delayed_work (&drvdata.oxp_rgb_queue); +cancel_delayed_work (&drvdata.oxp_btn_queue);cancel_delayed_work (&drvdata.oxp_mcu_init);hid_hw_close (hdev);hid_hw_stop (hdev);
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH v4 5/5 HID: hid-oxp: Add Vibration Intensity Attribute
In reply to Derek J. ClarkAdds attribute for setting the rumble intensity level. This setting must be re-applied after the gamepad mode is set as doing so resets this to the default value.
--- drivers/hid/hid-oxp.c | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+)
drivers/hid/hid-oxp.c +78 -0
@@ -34,6 +34,7 @@ enum oxp_function_index {OXP_FID_GEN1_RGB_SET =0x07 ,OXP_FID_GEN1_RGB_REPLY =0x0f ,OXP_FID_GEN2_TOGGLE_MODE =0xb2 , +OXP_FID_GEN2_RUMBLE_SET =0xb3 ,OXP_FID_GEN2_KEY_STATE =0xb4 , OXP_FID_GEN2_STATUS_EVENT = 0xb8, };
@@ -181,6 +182,7 @@ static struct oxp_hid_cfg {struct mutex cfg_mutex;/*ensure single synchronous output report*/ u8 rgb_brightness;u8 gamepad_mode; +u8 rumble_intensity;u8 rgb_effect;u8 rgb_speed;u8 rgb_en;
@@ -266,6 +268,11 @@ static const char *const oxp_rgb_effect_text[] = { [OXP_EFFECT_MONO_LIST] = "monocolor", }; +enum oxp_rumble_side_index { +OXP_RUMBLE_LEFT =0x00 , +OXP_RUMBLE_RIGHT , +}; +struct oxp_gen_1_rgb_report {u8 report_id;u8 message_id;
@@ -341,6 +348,7 @@ static int oxp_hid_raw_event_gen_1(struct hid_device *hdev,static int oxp_gen_2_property_out (enum oxp_function_index fid,u8 *data,u8 data_size);static int oxp_set_buttons (void ); +static int oxp_rumble_intensity_set (u8 intensity);static void oxp_mcu_init_fn (struct work_struct *work) {
@@ -368,6 +376,12 @@ static void oxp_mcu_init_fn(struct work_struct *work)if (ret)dev_err (&drvdata.hdev->dev,"Error: Failed to set gamepad mode: %i\n" , ret); + +/* Set vibration level */ + ret =oxp_rumble_intensity_set (drvdata.rumble_intensity); +if (ret) +dev_err (&drvdata.hdev->dev, +"Error: Failed to set rumble intensity: %i\n" , ret); } static int oxp_hid_raw_event_gen_2(struct hid_device *hdev,
@@ -514,6 +528,14 @@ static ssize_t gamepad_mode_store(struct device *dev, drvdata.gamepad_mode = data[0 ]; +if (drvdata.gamepad_mode ==OXP_GP_MODE_DEBUG ) +return count; + +/* Re-apply rumble settings as switching gamepad mode will override */ + ret =oxp_rumble_intensity_set (drvdata.rumble_intensity); +if (ret) +return ret; +return count; }
@@ -857,6 +879,59 @@ static ssize_t button_mapping_options_show(struct device *dev, }static DEVICE_ATTR_RO (button_mapping_options); +static int oxp_rumble_intensity_set (u8 intensity) +{ +u8 header[15 ] = {0x02 ,0x38 ,0x02 ,0xe3 ,0x39 ,0xe3 ,0x39 ,0xe3 , +0x39 ,0x01 , intensity,0x05 ,0xe3 ,0x39 ,0xe3 }; +u8 footer[9 ] = {0x39 ,0xe3 ,0x39 ,0xe3 ,0xe3 ,0x02 ,0x04 ,0x39 ,0x39 }; +size_t footer_size =ARRAY_SIZE (footer); +size_t header_size =ARRAY_SIZE (header); +u8 data[59 ] = {0x0 }; +size_t data_size =ARRAY_SIZE (data); + +memcpy (data, header, header_size); +memcpy (data + data_size - footer_size, footer, footer_size); + +return oxp_gen_2_property_out (OXP_FID_GEN2_RUMBLE_SET , data, data_size); +} + +static ssize_t rumble_intensity_store (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t count) +{ +int ret; +u8 val; + + ret =kstrtou8 (buf,10 , &val); +if (ret) +return ret; + +if (val <0 || val >5 ) +return -EINVAL ; + + ret =oxp_rumble_intensity_set (val); +if (ret) +return ret; + + drvdata.rumble_intensity = val; + +return count; +} + +static ssize_t rumble_intensity_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%i\n" , drvdata.rumble_intensity); +} +static DEVICE_ATTR_RW (rumble_intensity); + +static ssize_t rumble_intensity_range_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"0-5\n" ); +} +static DEVICE_ATTR_RO (rumble_intensity_range); +#define OXP_DEVICE_ATTR_RW (_name, _group) \ static ssize_t _name##_store(struct device *dev, \ struct device_attribute *attr, \
@@ -948,6 +1023,8 @@ static struct attribute *oxp_cfg_attrs[] = { &dev_attr_gamepad_mode.attr, &dev_attr_gamepad_mode_index.attr, &dev_attr_reset_buttons.attr, + &dev_attr_rumble_intensity.attr, + &dev_attr_rumble_intensity_range.attr, NULL, };
@@ -1422,6 +1499,7 @@ static int oxp_cfg_probe(struct hid_device *hdev, u16 up)INIT_DELAYED_WORK (&drvdata.oxp_btn_queue, oxp_btn_queue_fn); drvdata.gamepad_mode =OXP_GP_MODE_XINPUT ; + drvdata.rumble_intensity =5 ;INIT_DELAYED_WORK (&drvdata.oxp_mcu_init, oxp_mcu_init_fn);mod_delayed_work (system_wq, &drvdata.oxp_mcu_init,msecs_to_jiffies (50 ));
Signature · 1 line
2.53.0
Jiri Kosina
maintainerQuoted 35 lines · Derek J. Clark
Adds an HID driver for OneXPlayer HID configuration devices. There are currently 2 generations of OneXPlayer HID protocol. The first (OneXPlayer F1 series) only provides an RGB control interface over HID. The Second (X1 mini series, G1 series, AOKZOE A1X) also includes a hardware level button mapping interface, vibration intensity settings, and the ability to switch output between xinput and a debug mode that can be used to debug the button mapping. Some devices (G1 Series, APEX) use a hybrid of Gen1 RGB control and Gen 2 controller settings. To ensure there is no conflicts when the driver is loaded, we skip creating the RGB interface for Gen 2 devices if there is a DMI match.
I'll also add a note that Gen 1 devices also have an interface for setting the key map and debug mode, but that is done entirely over a serial TTY device so it is not able to be added to this driver. There are also some "Gen 0" devices (OneXPlayer 2 Series) also use it, but the TTY interface also handles the RGB control so no support is provided by this driver for those interfaces.
Signed-off-by Derel J. Clark <[email protected]>---
v4:
- Make all delayed work part of drvdata & ensure they are canceled during remove.v3: https://lore.kernel.org/linux-input/[email protected]/
- Ensure default button map is properly init during probe.v2: https://lore.kernel.org/linux-input/[email protected]/
- Add DMI quirks for certain devices that ship with both GEN1 and GEN2
MCU to avoid clashing when initializing the RGB interface.
- Add left & right vibration intensity attributes.
- Add additional mappings for keyboard inputs.
- Add a delayed work trigger to re-apply settings after the MCU
completes initializing after a suspend/resume cycle.
Quoted 1 line
Now in hid.git#for-7.2/oxp, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs
Hello Derek!
Quoted 11 lines · Derek J. Clark
Adds an HID driver for OneXPlayer HID configuration devices. There are currently 2 generations of OneXPlayer HID protocol. The first (OneXPlayer F1 series) only provides an RGB control interface over HID. The Second (X1 mini series, G1 series, AOKZOE A1X) also includes a hardware level button mapping interface, vibration intensity settings, and the ability to switch output between xinput and a debug mode that can be used to debug the button mapping. Some devices (G1 Series, APEX) use a hybrid of Gen1 RGB control and Gen 2 controller settings. To ensure there is no conflicts when the driver is loaded, we skip creating the RGB interface for Gen 2 devices if there is a DMI match.
Quoted 8 lines
I'll also add a note that Gen 1 devices also have an interface for setting the key map and debug mode, but that is done entirely over a serial TTY device so it is not able to be added to this driver. There are also some "Gen 0" devices (OneXPlayer 2 Series) also use it, but the TTY interface also handles the RGB control so no support is provided by this driver for those interfaces.
Signed-off-by Derel J. Clark <[email protected]>
Sorry I am late to this review, but here are two issues I discovered when looking at the code:
(1) The functions oxp_hid_raw_event_gen_1() and oxp_hid_raw_event_gen_2() are both forgetting to do bounds checks against the "size" argument.
For real devices, which send a real report descriptor, these buffers will be large enough, but a device that sends a faked report descriptor can provoke an out-of-bounds-read here by underspecifying the size for these reports.
(2) oxp_hid_probe() and other functions are populating drvdata, and drvdata is a static variable. If you plug in two of these devices at the same time, they will step on each other's toes, and this leads to all kinds of memory corruption problems when they do.
I believe the right way to go about this is to allocate a separate piece of memory for each device that you are plugging in. Other device drivers do this uing devm_kzalloc().
Disclaimer:
I found these through code inspection and curiosity but have not tried to reproduce the crashes.
Per Linux's official threat model[1], these are not considered security vulnerabilities. An attacker who impersonates a USB device and gains illegitimate access to the USB port might be able to provoke these bugs though, and I wouldn't be surprised if (2) also just leads to system crashes when using two of these devices at the same time.
—Günther