Add OneXPlayer Configuration HID Driver
Subsystems (3)
Derek J. Clark
maintainercover 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 generation (OneXPlayer F1 series) only provides an RGB control interface over HID. The Second generation (X1 mini series, G1 series, AOKZOE A1X) also includes a hardware level button mapping interface, as well as a "takeover" mode that was added by the ODM for debugging the button map. This takeover mode can be useful for exposing the M1 and M2 accessory buttons as unique inputs with some userspace tools that can consume it.
Derek J. Clark (4):
HID: hid-oxp: Add OneXPlayer configuration driver
HID: hid-oxp: Add Second Generation RGB Control
HID: hid-oxp: Add Second Generation Takeover Mode
HID: hid-oxp: Add Button Mapping Interface
MAINTAINERS | 6 + drivers/hid/Kconfig | 12 + drivers/hid/Makefile | 1 + drivers/hid/hid-ids.h | 6 + drivers/hid/hid-oxp.c | 1340 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1365 insertions(+) create mode 100644 drivers/hid/hid-oxp.c
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH 1/4 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.
--- 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
@@ -19228,6 +19228,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
@@ -920,6 +920,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
@@ -1102,6 +1102,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 2/4 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.
--- drivers/hid/hid-ids.h | 3 ++ drivers/hid/hid-oxp.c | 96 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+)
drivers/hid/hid-ids.h +3 -0
@@ -1105,6 +1105,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 +96 -0
168 lines not on this page · raw message
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH 3/4 HID: hid-oxp: Add Second Generation Takeover Mode
In reply to Derek J. ClarkAdds "takeover_enabled" 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, and allows some userspace tools to consume the interface to add support for features that are unable to be exposed through the evdev, such as treating the M1 and M2 accessory buttons as unique inputs.
--- drivers/hid/hid-oxp.c | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
drivers/hid/hid-oxp.c +81 -0
@@ -32,6 +32,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_RGB_EVENT =0xb8 , };
@@ -39,12 +40,15 @@ static struct oxp_hid_cfg {struct led_classdev_mc *led_mc;struct hid_device *hdev;struct mutex cfg_mutex;/*ensure single synchronous output report*/ +u8 takeover_enabled;u8 rgb_brightness;u8 rgb_effect;u8 rgb_speed;u8 rgb_en; } drvdata; +#define OXP_TAKEOVER_ENABLED_TRUE 0x03 +enum oxp_feature_en_index {OXP_FEAT_DISABLED ,OXP_FEAT_ENABLED ,
@@ -289,6 +293,74 @@ static int oxp_gen_2_property_out(enum oxp_function_index fid, u8 *data, footer_size); } +static ssize_t button_takeover_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 }; +u8 val =0 ; +int ret; + +if (up !=GEN2_USAGE_PAGE ) +return -EINVAL ; + + ret =sysfs_match_string (oxp_feature_en_text, buf); +if (ret <0 ) +return ret; + val = ret; + +switch (val) { +case OXP_FEAT_DISABLED : +break ; +case OXP_FEAT_ENABLED : + data[0 ] =OXP_TAKEOVER_ENABLED_TRUE ; +break ; +default : +return -EINVAL ; + } + + ret =oxp_gen_2_property_out (OXP_FID_GEN2_TOGGLE_MODE , data,3 ); +if (ret) +return ret; + +return count; +} + +static ssize_t button_takeover_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%s\n" , oxp_feature_en_text[drvdata.takeover_enabled]); +} +static DEVICE_ATTR_RW (button_takeover); + +static ssize_t button_takeover_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_feature_en_text); i++) + count +=sysfs_emit_at (buf, count,"%s " , oxp_feature_en_text[i]); + +if (count) + buf[count -1 ] ='\n' ; + +return count; +} +static DEVICE_ATTR_RO (button_takeover_index); + +static struct attribute *oxp_cfg_attrs[] = { + &dev_attr_button_takeover.attr, + &dev_attr_button_takeover_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);
@@ -680,6 +752,15 @@ 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 ; + + 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 ; }
Signature · 1 line
2.53.0
Derek J. Clark
maintainerPATCH 4/4 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.
--- drivers/hid/hid-oxp.c | 510 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 510 insertions(+)
drivers/hid/hid-oxp.c +510 -0
@@ -33,10 +33,126 @@ 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_RGB_EVENT = 0xb8, }; +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 , +JOY_L_UP , +JOY_L_UP_RIGHT , +JOY_L_RIGHT , +JOY_L_DOWN_RIGHT , +JOY_L_DOWN , +JOY_L_DOWN_LEFT , +JOY_L_LEFT , +JOY_L_UP_LEFT , +JOY_R_UP , +JOY_R_UP_RIGHT , +JOY_R_RIGHT , +JOY_R_DOWN_RIGHT , +JOY_R_DOWN , +JOY_R_DOWN_LEFT , +JOY_R_LEFT , +JOY_R_UP_LEFT , +BUTTON_GUIDE =0x22 , +}; + +static const char *const oxp_joybutton_text[] = { + [BUTTON_A ] ="a" , + [BUTTON_B ] ="b" , + [BUTTON_X ] ="x" , + [BUTTON_Y ] ="y" , + [BUTTON_LB ] ="lb" , + [BUTTON_RB ] ="rb" , + [BUTTON_LT ] ="lt" , + [BUTTON_RT ] ="rt" , + [BUTTON_START ] ="start" , + [BUTTON_SELECT ] ="select" , + [BUTTON_L3 ] ="l3" , + [BUTTON_R3 ] ="r3" , + [BUTTON_DUP ] ="d_up" , + [BUTTON_DDOWN ] ="d_down" , + [BUTTON_DLEFT ] ="d_left" , + [BUTTON_DRIGHT ] ="d_right" , + [JOY_L_UP ] ="joy_l_up" , + [JOY_L_UP_RIGHT ] ="joy_l_up_right" , + [JOY_L_RIGHT ] ="joy_l_right" , + [JOY_L_DOWN_RIGHT ] ="joy_l_down_right" , + [JOY_L_DOWN ] ="joy_l_down" , + [JOY_L_DOWN_LEFT ] ="joy_l_down_left" , + [JOY_L_LEFT ] ="joy_l_left" , + [JOY_L_UP_LEFT ] ="joy_l_up_left" , + [JOY_R_UP ] ="joy_r_up" , + [JOY_R_UP_RIGHT ] ="joy_r_up_right" , + [JOY_R_RIGHT ] ="joy_r_right" , + [JOY_R_DOWN_RIGHT ] ="joy_r_down_right" , + [JOY_R_DOWN ] ="joy_r_down" , + [JOY_R_DOWN_LEFT ] ="joy_r_down_left" , + [JOY_R_LEFT ] ="joy_r_left" , + [JOY_R_UP_LEFT ] ="joy_r_up_left" , + [BUTTON_GUIDE ] ="guide" , +}; + +enum oxp_custom_button_index { +BUTTON_M1 =0x22 , +BUTTON_M2 , +/* These are unused currently, reserved for future devices */ +BUTTON_M3 , +BUTTON_M4 , +BUTTON_M5 , +BUTTON_M6 , +}; + +struct oxp_button { +u8 index; +u8 mode; +u8 mapping; +u8 padding[3 ]; +} __packed; + +struct oxp_bmap_page_1 { +struct oxp_button btn_a; +struct oxp_button btn_b; +struct oxp_button btn_x; +struct oxp_button btn_y; +struct oxp_button btn_lb; +struct oxp_button btn_rb; +struct oxp_button btn_lt; +struct oxp_button btn_rt; +struct oxp_button btn_start; +} __packed; + +struct oxp_bmap_page_2 { +struct oxp_button btn_select; +struct oxp_button btn_l3; +struct oxp_button btn_r3; +struct oxp_button btn_dup; +struct oxp_button btn_ddown; +struct oxp_button btn_dleft; +struct oxp_button btn_dright; +struct oxp_button btn_m1; +struct oxp_button btn_m2; +} __packed; + static struct oxp_hid_cfg { + struct oxp_bmap_page_1 *bmap_1; + struct oxp_bmap_page_2 *bmap_2; struct led_classdev_mc *led_mc; struct hid_device *hdev; struct mutex cfg_mutex; /*ensure single synchronous output report*/
@@ -144,6 +260,10 @@ struct oxp_gen_2_rgb_report {u8 effect; } __packed; +struct oxp_button_attr { +u8 index; +}; +static u16 get_usage_page (struct hid_device *hdev) {return hdev->collection[0 ].usage >>16 ;
@@ -351,9 +471,380 @@ static ssize_t button_takeover_index_show(struct device *dev, }static DEVICE_ATTR_RO (button_takeover_index); +static void oxp_set_defaults_bmap_1 (struct oxp_bmap_page_1 *bmap) +{ + bmap->btn_a.index =BUTTON_A ; + bmap->btn_a.mode =0x01 ; + bmap->btn_a.mapping =BUTTON_A ; + bmap->btn_b.index =BUTTON_B ; + bmap->btn_b.mode =0x01 ; + bmap->btn_b.mapping =BUTTON_B ; + bmap->btn_x.index =BUTTON_X ; + bmap->btn_x.mode =0x01 ; + bmap->btn_x.mapping =BUTTON_X ; + bmap->btn_y.index =BUTTON_Y ; + bmap->btn_y.mode =0x01 ; + bmap->btn_y.mapping =BUTTON_Y ; + bmap->btn_lb.index =BUTTON_LB ; + bmap->btn_lb.mode =0x01 ; + bmap->btn_lb.mapping =BUTTON_LB ; + bmap->btn_rb.index =BUTTON_RB ; + bmap->btn_rb.mode =0x01 ; + bmap->btn_rb.mapping =BUTTON_RB ; + bmap->btn_lt.index =BUTTON_LT ; + bmap->btn_lt.mode =0x01 ; + bmap->btn_lt.mapping =BUTTON_LT ; + bmap->btn_rt.index =BUTTON_RT ; + bmap->btn_rt.mode =0x01 ; + bmap->btn_rt.mapping =BUTTON_RT ; + bmap->btn_start.index =BUTTON_START ; + bmap->btn_start.mode =0x01 ; + bmap->btn_start.mapping =BUTTON_START ; +} + +static void oxp_set_defaults_bmap_2 (struct oxp_bmap_page_2 *bmap) +{ + bmap->btn_select.index =BUTTON_SELECT ; + bmap->btn_select.mode =0x01 ; + bmap->btn_select.mapping =BUTTON_SELECT ; + bmap->btn_l3.index =BUTTON_L3 ; + bmap->btn_l3.mode =0x01 ; + bmap->btn_l3.mapping =BUTTON_L3 ; + bmap->btn_r3.index =BUTTON_R3 ; + bmap->btn_r3.mode =0x01 ; + bmap->btn_r3.mapping =BUTTON_R3 ; + bmap->btn_dup.index =BUTTON_DUP ; + bmap->btn_dup.mode =0x01 ; + bmap->btn_dup.mapping =BUTTON_DUP ; + bmap->btn_ddown.index =BUTTON_DDOWN ; + bmap->btn_ddown.mode =0x01 ; + bmap->btn_ddown.mapping =BUTTON_DDOWN ; + bmap->btn_dleft.index =BUTTON_DLEFT ; + bmap->btn_dleft.mode =0x01 ; + bmap->btn_dleft.mapping =BUTTON_DLEFT ; + bmap->btn_dright.index =BUTTON_DRIGHT ; + bmap->btn_dright.mode =0x01 ; + bmap->btn_dright.mapping =BUTTON_DRIGHT ; + bmap->btn_m1.index =BUTTON_M1 ; + bmap->btn_m1.mode =0x01 ; + bmap->btn_m1.mapping =BUTTON_LT ; + bmap->btn_m2.index =BUTTON_M2 ; + bmap->btn_m2.mode =0x01 ; + bmap->btn_m2.mapping =BUTTON_RT ; +} + +static int oxp_set_buttons (void ) +{ +u8 data[59 ] = {0x02 ,0x00 ,0x00 ,0x00 ,0x01 }; +u16 up =get_usage_page (drvdata.hdev); +int ret; + +if (up !=GEN2_USAGE_PAGE ) +return -EINVAL ; + +memcpy (data +5 , drvdata.bmap_1,sizeof (struct oxp_bmap_page_1 )); + ret =oxp_gen_2_property_out (OXP_FID_GEN2_KEY_STATE , data,ARRAY_SIZE (data)); +if (ret) +return ret; + +memcpy (data +5 , drvdata.bmap_2,sizeof (struct oxp_bmap_page_2 )); +return oxp_gen_2_property_out (OXP_FID_GEN2_KEY_STATE , data,ARRAY_SIZE (data)); +} + +static int oxp_reset_buttons (void ) +{ +oxp_set_defaults_bmap_1 (drvdata.bmap_1); +oxp_set_defaults_bmap_2 (drvdata.bmap_2); +return oxp_set_buttons (); +} + +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 ; + + ret =oxp_reset_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 DECLARE_DELAYED_WORK(oxp_btn_queue, oxp_btn_queue_fn); + +static ssize_t map_button_store (struct device *dev, +struct device_attribute *attr,const char *buf, +size_t count,u8 index) +{ +int ret; +u8 val; + + ret =sysfs_match_string (oxp_joybutton_text, buf); +if (ret <0 ) +return ret; + + val = ret; + +switch (index) { +case BUTTON_A : + drvdata.bmap_1->btn_a.mapping = val; +break ; +case BUTTON_B : + drvdata.bmap_1->btn_b.mapping = val; +break ; +case BUTTON_X : + drvdata.bmap_1->btn_x.mapping = val; +break ; +case BUTTON_Y : + drvdata.bmap_1->btn_y.mapping = val; +break ; +case BUTTON_LB : + drvdata.bmap_1->btn_lb.mapping = val; +break ; +case BUTTON_RB : + drvdata.bmap_1->btn_rb.mapping = val; +break ; +case BUTTON_LT : + drvdata.bmap_1->btn_lt.mapping = val; +break ; +case BUTTON_RT : + drvdata.bmap_1->btn_rt.mapping = val; +break ; +case BUTTON_START : + drvdata.bmap_1->btn_start.mapping = val; +break ; +case BUTTON_SELECT : + drvdata.bmap_2->btn_select.mapping = val; +break ; +case BUTTON_L3 : + drvdata.bmap_2->btn_l3.mapping = val; +break ; +case BUTTON_R3 : + drvdata.bmap_2->btn_r3.mapping = val; +break ; +case BUTTON_DUP : + drvdata.bmap_2->btn_dup.mapping = val; +break ; +case BUTTON_DDOWN : + drvdata.bmap_2->btn_ddown.mapping = val; +break ; +case BUTTON_DLEFT : + drvdata.bmap_2->btn_dleft.mapping = val; +break ; +case BUTTON_DRIGHT : + drvdata.bmap_2->btn_dright.mapping = val; +break ; +case BUTTON_M1 : + drvdata.bmap_2->btn_m1.mapping = val; +break ; +case BUTTON_M2 : + drvdata.bmap_2->btn_m2.mapping = val; +break ; +default : +return -EINVAL ; + } + +mod_delayed_work (system_wq, &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; +break ; +case BUTTON_B : + i = drvdata.bmap_1->btn_b.mapping; +break ; +case BUTTON_X : + i = drvdata.bmap_1->btn_x.mapping; +break ; +case BUTTON_Y : + i = drvdata.bmap_1->btn_y.mapping; +break ; +case BUTTON_LB : + i = drvdata.bmap_1->btn_lb.mapping; +break ; +case BUTTON_RB : + i = drvdata.bmap_1->btn_rb.mapping; +break ; +case BUTTON_LT : + i = drvdata.bmap_1->btn_lt.mapping; +break ; +case BUTTON_RT : + i = drvdata.bmap_1->btn_rt.mapping; +break ; +case BUTTON_START : + i = drvdata.bmap_1->btn_start.mapping; +break ; +case BUTTON_SELECT : + i = drvdata.bmap_2->btn_select.mapping; +break ; +case BUTTON_L3 : + i = drvdata.bmap_2->btn_l3.mapping; +break ; +case BUTTON_R3 : + i = drvdata.bmap_2->btn_r3.mapping; +break ; +case BUTTON_DUP : + i = drvdata.bmap_2->btn_dup.mapping; +break ; +case BUTTON_DDOWN : + i = drvdata.bmap_2->btn_ddown.mapping; +break ; +case BUTTON_DLEFT : + i = drvdata.bmap_2->btn_dleft.mapping; +break ; +case BUTTON_DRIGHT : + i = drvdata.bmap_2->btn_dright.mapping; +break ; +case BUTTON_M1 : + i = drvdata.bmap_2->btn_m1.mapping; +break ; +case BUTTON_M2 : + i = drvdata.bmap_2->btn_m2.mapping; +break ; +default : +return -EINVAL ; + } + +if (i >=ARRAY_SIZE (oxp_joybutton_text)) +return -EINVAL ; + +return sysfs_emit (buf,"%s\n" , oxp_joybutton_text[i]); +} + +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_joybutton_text); i++) + count +=sysfs_emit_at (buf, count,"%s " , oxp_joybutton_text[i]); + +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_button_attr button_a = {BUTTON_A }; +OXP_DEVICE_ATTR_RW (button_a, map_button); + +static struct oxp_button_attr button_b = {BUTTON_B }; +OXP_DEVICE_ATTR_RW (button_b, map_button); + +static struct oxp_button_attr button_x = {BUTTON_X }; +OXP_DEVICE_ATTR_RW (button_x, map_button); + +static struct oxp_button_attr button_y = {BUTTON_Y }; +OXP_DEVICE_ATTR_RW (button_y, map_button); + +static struct oxp_button_attr button_lb = {BUTTON_LB }; +OXP_DEVICE_ATTR_RW (button_lb, map_button); + +static struct oxp_button_attr button_rb = {BUTTON_RB }; +OXP_DEVICE_ATTR_RW (button_rb, map_button); + +static struct oxp_button_attr button_lt = {BUTTON_LT }; +OXP_DEVICE_ATTR_RW (button_lt, map_button); + +static struct oxp_button_attr button_rt = {BUTTON_RT }; +OXP_DEVICE_ATTR_RW (button_rt, map_button); + +static struct oxp_button_attr button_start = {BUTTON_START }; +OXP_DEVICE_ATTR_RW (button_start, map_button); + +static struct oxp_button_attr button_select = {BUTTON_SELECT }; +OXP_DEVICE_ATTR_RW (button_select, map_button); + +static struct oxp_button_attr button_l3 = {BUTTON_L3 }; +OXP_DEVICE_ATTR_RW (button_l3, map_button); + +static struct oxp_button_attr button_r3 = {BUTTON_R3 }; +OXP_DEVICE_ATTR_RW (button_r3, map_button); + +static struct oxp_button_attr button_d_up = {BUTTON_DUP }; +OXP_DEVICE_ATTR_RW (button_d_up, map_button); + +static struct oxp_button_attr button_d_down = {BUTTON_DDOWN }; +OXP_DEVICE_ATTR_RW (button_d_down, map_button); + +static struct oxp_button_attr button_d_left = {BUTTON_DLEFT }; +OXP_DEVICE_ATTR_RW (button_d_left, map_button); + +static struct oxp_button_attr button_d_right = {BUTTON_DRIGHT }; +OXP_DEVICE_ATTR_RW (button_d_right, map_button); + +static struct oxp_button_attr button_m1 = {BUTTON_M1 }; +OXP_DEVICE_ATTR_RW (button_m1, map_button); + +static struct oxp_button_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_takeover.attr, &dev_attr_button_takeover_index.attr, + &dev_attr_button_x.attr, + &dev_attr_button_y.attr, + &dev_attr_reset_buttons.attr,NULL , };
@@ -729,6 +1220,8 @@ static struct led_classdev_mc oxp_cdev_rgb = {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);
@@ -756,6 +1249,23 @@ static int oxp_cfg_probe(struct hid_device *hdev, u16 up)if (up !=GEN2_USAGE_PAGE )return 0 ; + 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; + ret =oxp_reset_buttons (); +if (ret) +return dev_err_probe (&hdev->dev, ret, +"Failed to reset button mapping\n" ); + ret =devm_device_add_group (&hdev->dev, &oxp_cfg_attrs_group);if (ret) return dev_err_probe(&hdev->dev, ret,
Signature · 1 line
2.53.0
Derek John Clark
maintainerQuoted 26 lines · Derek J. Clark
Adds an HID driver for OneXPlayer HID configuration devices. There are currently 2 generations of OneXPlayer HID protocol. The first generation (OneXPlayer F1 series) only provides an RGB control interface over HID. The Second generation (X1 mini series, G1 series, AOKZOE A1X) also includes a hardware level button mapping interface, as well as a "takeover" mode that was added by the ODM for debugging the button map. This takeover mode can be useful for exposing the M1 and M2 accessory buttons as unique inputs with some userspace tools that can consume it.
Signed-off-by Derel J. Clark <[email protected]>Derek J. Clark (4):
HID: hid-oxp: Add OneXPlayer configuration driver
HID: hid-oxp: Add Second Generation RGB Control
HID: hid-oxp: Add Second Generation Takeover Mode
HID: hid-oxp: Add Button Mapping InterfaceMAINTAINERS | 6 + drivers/hid/Kconfig | 12 + drivers/hid/Makefile | 1 + drivers/hid/hid-ids.h | 6 + drivers/hid/hid-oxp.c | 1340 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1365 insertions(+) create mode 100644 drivers/hid/hid-oxp.c
Quoted 3 lines
--
2.53.0
Note to everyone: I forgot to rebase to a clean for-next branch before sending this so build bots will likely fail. I'll be sure to update the source branch to the appropriate branch for v2 after a few days to allow time for comments on the patch substance. Sorry about the extra churn here.
Thanks,
Derek