Skip to content

Commit 4ef4636

Browse files
endriftdtor
authored andcommitted
Input: xpad - fix Share button on Xbox One controllers
The Share button, if present, is always one of two offsets from the end of the file, depending on the presence of a specific interface. As we lack parsing for the identify packet we can't automatically determine the presence of that interface, but we can hardcode which of these offsets is correct for a given controller. More controllers are probably fixable by adding the MAP_SHARE_BUTTON in the future, but for now I only added the ones that I have the ability to test directly. Signed-off-by: Vicki Pfau <vi@endrift.com> Link: https://lore.kernel.org/r/20250328234345.989761-2-vi@endrift.com Cc: stable@vger.kernel.org Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent d05a424 commit 4ef4636

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

drivers/input/joystick/xpad.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@
7777
* xbox d-pads should map to buttons, as is required for DDR pads
7878
* but we map them to axes when possible to simplify things
7979
*/
80-
#define MAP_DPAD_TO_BUTTONS (1 << 0)
81-
#define MAP_TRIGGERS_TO_BUTTONS (1 << 1)
82-
#define MAP_STICKS_TO_NULL (1 << 2)
83-
#define MAP_SELECT_BUTTON (1 << 3)
84-
#define MAP_PADDLES (1 << 4)
85-
#define MAP_PROFILE_BUTTON (1 << 5)
80+
#define MAP_DPAD_TO_BUTTONS BIT(0)
81+
#define MAP_TRIGGERS_TO_BUTTONS BIT(1)
82+
#define MAP_STICKS_TO_NULL BIT(2)
83+
#define MAP_SHARE_BUTTON BIT(3)
84+
#define MAP_PADDLES BIT(4)
85+
#define MAP_PROFILE_BUTTON BIT(5)
86+
#define MAP_SHARE_OFFSET BIT(6)
8687

8788
#define DANCEPAD_MAP_CONFIG (MAP_DPAD_TO_BUTTONS | \
8889
MAP_TRIGGERS_TO_BUTTONS | MAP_STICKS_TO_NULL)
@@ -135,7 +136,7 @@ static const struct xpad_device {
135136
{ 0x03f0, 0x048D, "HyperX Clutch", 0, XTYPE_XBOX360 }, /* wireless */
136137
{ 0x03f0, 0x0495, "HyperX Clutch Gladiate", 0, XTYPE_XBOXONE },
137138
{ 0x03f0, 0x07A0, "HyperX Clutch Gladiate RGB", 0, XTYPE_XBOXONE },
138-
{ 0x03f0, 0x08B6, "HyperX Clutch Gladiate", 0, XTYPE_XBOXONE }, /* v2 */
139+
{ 0x03f0, 0x08B6, "HyperX Clutch Gladiate", MAP_SHARE_BUTTON, XTYPE_XBOXONE }, /* v2 */
139140
{ 0x03f0, 0x09B4, "HyperX Clutch Tanto", 0, XTYPE_XBOXONE },
140141
{ 0x044f, 0x0f00, "Thrustmaster Wheel", 0, XTYPE_XBOX },
141142
{ 0x044f, 0x0f03, "Thrustmaster Wheel", 0, XTYPE_XBOX },
@@ -159,7 +160,7 @@ static const struct xpad_device {
159160
{ 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
160161
{ 0x045e, 0x0b00, "Microsoft X-Box One Elite 2 pad", MAP_PADDLES, XTYPE_XBOXONE },
161162
{ 0x045e, 0x0b0a, "Microsoft X-Box Adaptive Controller", MAP_PROFILE_BUTTON, XTYPE_XBOXONE },
162-
{ 0x045e, 0x0b12, "Microsoft Xbox Series S|X Controller", MAP_SELECT_BUTTON, XTYPE_XBOXONE },
163+
{ 0x045e, 0x0b12, "Microsoft Xbox Series S|X Controller", MAP_SHARE_BUTTON | MAP_SHARE_OFFSET, XTYPE_XBOXONE },
163164
{ 0x046d, 0xc21d, "Logitech Gamepad F310", 0, XTYPE_XBOX360 },
164165
{ 0x046d, 0xc21e, "Logitech Gamepad F510", 0, XTYPE_XBOX360 },
165166
{ 0x046d, 0xc21f, "Logitech Gamepad F710", 0, XTYPE_XBOX360 },
@@ -211,7 +212,7 @@ static const struct xpad_device {
211212
{ 0x0738, 0xcb29, "Saitek Aviator Stick AV8R02", 0, XTYPE_XBOX360 },
212213
{ 0x0738, 0xf738, "Super SFIV FightStick TE S", 0, XTYPE_XBOX360 },
213214
{ 0x07ff, 0xffff, "Mad Catz GamePad", 0, XTYPE_XBOX360 },
214-
{ 0x0b05, 0x1a38, "ASUS ROG RAIKIRI", 0, XTYPE_XBOXONE },
215+
{ 0x0b05, 0x1a38, "ASUS ROG RAIKIRI", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
215216
{ 0x0b05, 0x1abb, "ASUS ROG RAIKIRI PRO", 0, XTYPE_XBOXONE },
216217
{ 0x0c12, 0x0005, "Intec wireless", 0, XTYPE_XBOX },
217218
{ 0x0c12, 0x8801, "Nyko Xbox Controller", 0, XTYPE_XBOX },
@@ -391,7 +392,7 @@ static const struct xpad_device {
391392
{ 0x2dc8, 0x6001, "8BitDo SN30 Pro", 0, XTYPE_XBOX360 },
392393
{ 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE },
393394
{ 0x2e24, 0x1688, "Hyperkin X91 X-Box One pad", 0, XTYPE_XBOXONE },
394-
{ 0x2e95, 0x0504, "SCUF Gaming Controller", MAP_SELECT_BUTTON, XTYPE_XBOXONE },
395+
{ 0x2e95, 0x0504, "SCUF Gaming Controller", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
395396
{ 0x31e3, 0x1100, "Wooting One", 0, XTYPE_XBOX360 },
396397
{ 0x31e3, 0x1200, "Wooting Two", 0, XTYPE_XBOX360 },
397398
{ 0x31e3, 0x1210, "Wooting Lekker", 0, XTYPE_XBOX360 },
@@ -1028,7 +1029,7 @@ static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned cha
10281029
* The report format was gleaned from
10291030
* https://github.com/kylelemons/xbox/blob/master/xbox.go
10301031
*/
1031-
static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
1032+
static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data, u32 len)
10321033
{
10331034
struct input_dev *dev = xpad->dev;
10341035
bool do_sync = false;
@@ -1069,8 +1070,12 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
10691070
/* menu/view buttons */
10701071
input_report_key(dev, BTN_START, data[4] & BIT(2));
10711072
input_report_key(dev, BTN_SELECT, data[4] & BIT(3));
1072-
if (xpad->mapping & MAP_SELECT_BUTTON)
1073-
input_report_key(dev, KEY_RECORD, data[22] & BIT(0));
1073+
if (xpad->mapping & MAP_SHARE_BUTTON) {
1074+
if (xpad->mapping & MAP_SHARE_OFFSET)
1075+
input_report_key(dev, KEY_RECORD, data[len - 26] & BIT(0));
1076+
else
1077+
input_report_key(dev, KEY_RECORD, data[len - 18] & BIT(0));
1078+
}
10741079

10751080
/* buttons A,B,X,Y */
10761081
input_report_key(dev, BTN_A, data[4] & BIT(4));
@@ -1218,7 +1223,7 @@ static void xpad_irq_in(struct urb *urb)
12181223
xpad360w_process_packet(xpad, 0, xpad->idata);
12191224
break;
12201225
case XTYPE_XBOXONE:
1221-
xpadone_process_packet(xpad, 0, xpad->idata);
1226+
xpadone_process_packet(xpad, 0, xpad->idata, urb->actual_length);
12221227
break;
12231228
default:
12241229
xpad_process_packet(xpad, 0, xpad->idata);
@@ -1945,7 +1950,7 @@ static int xpad_init_input(struct usb_xpad *xpad)
19451950
xpad->xtype == XTYPE_XBOXONE) {
19461951
for (i = 0; xpad360_btn[i] >= 0; i++)
19471952
input_set_capability(input_dev, EV_KEY, xpad360_btn[i]);
1948-
if (xpad->mapping & MAP_SELECT_BUTTON)
1953+
if (xpad->mapping & MAP_SHARE_BUTTON)
19491954
input_set_capability(input_dev, EV_KEY, KEY_RECORD);
19501955
} else {
19511956
for (i = 0; xpad_btn[i] >= 0; i++)

0 commit comments

Comments
 (0)