Skip to content

Commit 64575cb

Browse files
endriftSasha Levin
authored andcommitted
Input: xpad - fix Share button on Xbox One controllers
commit 4ef4636 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 51b1b39 commit 64575cb

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 },
@@ -390,7 +391,7 @@ static const struct xpad_device {
390391
{ 0x2dc8, 0x6001, "8BitDo SN30 Pro", 0, XTYPE_XBOX360 },
391392
{ 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE },
392393
{ 0x2e24, 0x1688, "Hyperkin X91 X-Box One pad", 0, XTYPE_XBOXONE },
393-
{ 0x2e95, 0x0504, "SCUF Gaming Controller", MAP_SELECT_BUTTON, XTYPE_XBOXONE },
394+
{ 0x2e95, 0x0504, "SCUF Gaming Controller", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
394395
{ 0x31e3, 0x1100, "Wooting One", 0, XTYPE_XBOX360 },
395396
{ 0x31e3, 0x1200, "Wooting Two", 0, XTYPE_XBOX360 },
396397
{ 0x31e3, 0x1210, "Wooting Lekker", 0, XTYPE_XBOX360 },
@@ -1027,7 +1028,7 @@ static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned cha
10271028
* The report format was gleaned from
10281029
* https://github.com/kylelemons/xbox/blob/master/xbox.go
10291030
*/
1030-
static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
1031+
static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data, u32 len)
10311032
{
10321033
struct input_dev *dev = xpad->dev;
10331034
bool do_sync = false;
@@ -1068,8 +1069,12 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
10681069
/* menu/view buttons */
10691070
input_report_key(dev, BTN_START, data[4] & BIT(2));
10701071
input_report_key(dev, BTN_SELECT, data[4] & BIT(3));
1071-
if (xpad->mapping & MAP_SELECT_BUTTON)
1072-
input_report_key(dev, KEY_RECORD, data[22] & BIT(0));
1072+
if (xpad->mapping & MAP_SHARE_BUTTON) {
1073+
if (xpad->mapping & MAP_SHARE_OFFSET)
1074+
input_report_key(dev, KEY_RECORD, data[len - 26] & BIT(0));
1075+
else
1076+
input_report_key(dev, KEY_RECORD, data[len - 18] & BIT(0));
1077+
}
10731078

10741079
/* buttons A,B,X,Y */
10751080
input_report_key(dev, BTN_A, data[4] & BIT(4));
@@ -1217,7 +1222,7 @@ static void xpad_irq_in(struct urb *urb)
12171222
xpad360w_process_packet(xpad, 0, xpad->idata);
12181223
break;
12191224
case XTYPE_XBOXONE:
1220-
xpadone_process_packet(xpad, 0, xpad->idata);
1225+
xpadone_process_packet(xpad, 0, xpad->idata, urb->actual_length);
12211226
break;
12221227
default:
12231228
xpad_process_packet(xpad, 0, xpad->idata);
@@ -1974,7 +1979,7 @@ static int xpad_init_input(struct usb_xpad *xpad)
19741979
xpad->xtype == XTYPE_XBOXONE) {
19751980
for (i = 0; xpad360_btn[i] >= 0; i++)
19761981
input_set_capability(input_dev, EV_KEY, xpad360_btn[i]);
1977-
if (xpad->mapping & MAP_SELECT_BUTTON)
1982+
if (xpad->mapping & MAP_SHARE_BUTTON)
19781983
input_set_capability(input_dev, EV_KEY, KEY_RECORD);
19791984
} else {
19801985
for (i = 0; xpad_btn[i] >= 0; i++)

0 commit comments

Comments
 (0)