]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Input: xpad - fix Share button on Xbox One controllers
authorVicki Pfau <vi@endrift.com>
Sun, 11 May 2025 05:59:25 +0000 (22:59 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Sun, 11 May 2025 06:08:17 +0000 (23:08 -0700)
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>
drivers/input/joystick/xpad.c

index 2c935cf79ddcc9da4c9d9dafc258ec84e9a8b4df..8ee7d8e5d1c733da5c0ea31b06060b0bfa4f701c 100644 (file)
  * xbox d-pads should map to buttons, as is required for DDR pads
  * but we map them to axes when possible to simplify things
  */
-#define MAP_DPAD_TO_BUTTONS            (1 << 0)
-#define MAP_TRIGGERS_TO_BUTTONS                (1 << 1)
-#define MAP_STICKS_TO_NULL             (1 << 2)
-#define MAP_SELECT_BUTTON              (1 << 3)
-#define MAP_PADDLES                    (1 << 4)
-#define MAP_PROFILE_BUTTON             (1 << 5)
+#define MAP_DPAD_TO_BUTTONS            BIT(0)
+#define MAP_TRIGGERS_TO_BUTTONS                BIT(1)
+#define MAP_STICKS_TO_NULL             BIT(2)
+#define MAP_SHARE_BUTTON               BIT(3)
+#define MAP_PADDLES                    BIT(4)
+#define MAP_PROFILE_BUTTON             BIT(5)
+#define MAP_SHARE_OFFSET               BIT(6)
 
 #define DANCEPAD_MAP_CONFIG    (MAP_DPAD_TO_BUTTONS |                  \
                                MAP_TRIGGERS_TO_BUTTONS | MAP_STICKS_TO_NULL)
@@ -135,7 +136,7 @@ static const struct xpad_device {
        { 0x03f0, 0x048D, "HyperX Clutch", 0, XTYPE_XBOX360 },                  /* wireless */
        { 0x03f0, 0x0495, "HyperX Clutch Gladiate", 0, XTYPE_XBOXONE },
        { 0x03f0, 0x07A0, "HyperX Clutch Gladiate RGB", 0, XTYPE_XBOXONE },
-       { 0x03f0, 0x08B6, "HyperX Clutch Gladiate", 0, XTYPE_XBOXONE },         /* v2 */
+       { 0x03f0, 0x08B6, "HyperX Clutch Gladiate", MAP_SHARE_BUTTON, XTYPE_XBOXONE },          /* v2 */
        { 0x03f0, 0x09B4, "HyperX Clutch Tanto", 0, XTYPE_XBOXONE },
        { 0x044f, 0x0f00, "Thrustmaster Wheel", 0, XTYPE_XBOX },
        { 0x044f, 0x0f03, "Thrustmaster Wheel", 0, XTYPE_XBOX },
@@ -159,7 +160,7 @@ static const struct xpad_device {
        { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
        { 0x045e, 0x0b00, "Microsoft X-Box One Elite 2 pad", MAP_PADDLES, XTYPE_XBOXONE },
        { 0x045e, 0x0b0a, "Microsoft X-Box Adaptive Controller", MAP_PROFILE_BUTTON, XTYPE_XBOXONE },
-       { 0x045e, 0x0b12, "Microsoft Xbox Series S|X Controller", MAP_SELECT_BUTTON, XTYPE_XBOXONE },
+       { 0x045e, 0x0b12, "Microsoft Xbox Series S|X Controller", MAP_SHARE_BUTTON | MAP_SHARE_OFFSET, XTYPE_XBOXONE },
        { 0x046d, 0xc21d, "Logitech Gamepad F310", 0, XTYPE_XBOX360 },
        { 0x046d, 0xc21e, "Logitech Gamepad F510", 0, XTYPE_XBOX360 },
        { 0x046d, 0xc21f, "Logitech Gamepad F710", 0, XTYPE_XBOX360 },
@@ -211,7 +212,7 @@ static const struct xpad_device {
        { 0x0738, 0xcb29, "Saitek Aviator Stick AV8R02", 0, XTYPE_XBOX360 },
        { 0x0738, 0xf738, "Super SFIV FightStick TE S", 0, XTYPE_XBOX360 },
        { 0x07ff, 0xffff, "Mad Catz GamePad", 0, XTYPE_XBOX360 },
-       { 0x0b05, 0x1a38, "ASUS ROG RAIKIRI", 0, XTYPE_XBOXONE },
+       { 0x0b05, 0x1a38, "ASUS ROG RAIKIRI", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
        { 0x0b05, 0x1abb, "ASUS ROG RAIKIRI PRO", 0, XTYPE_XBOXONE },
        { 0x0c12, 0x0005, "Intec wireless", 0, XTYPE_XBOX },
        { 0x0c12, 0x8801, "Nyko Xbox Controller", 0, XTYPE_XBOX },
@@ -391,7 +392,7 @@ static const struct xpad_device {
        { 0x2dc8, 0x6001, "8BitDo SN30 Pro", 0, XTYPE_XBOX360 },
        { 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE },
        { 0x2e24, 0x1688, "Hyperkin X91 X-Box One pad", 0, XTYPE_XBOXONE },
-       { 0x2e95, 0x0504, "SCUF Gaming Controller", MAP_SELECT_BUTTON, XTYPE_XBOXONE },
+       { 0x2e95, 0x0504, "SCUF Gaming Controller", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
        { 0x31e3, 0x1100, "Wooting One", 0, XTYPE_XBOX360 },
        { 0x31e3, 0x1200, "Wooting Two", 0, XTYPE_XBOX360 },
        { 0x31e3, 0x1210, "Wooting Lekker", 0, XTYPE_XBOX360 },
@@ -1028,7 +1029,7 @@ static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned cha
  *     The report format was gleaned from
  *     https://github.com/kylelemons/xbox/blob/master/xbox.go
  */
-static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
+static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data, u32 len)
 {
        struct input_dev *dev = xpad->dev;
        bool do_sync = false;
@@ -1069,8 +1070,12 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
                /* menu/view buttons */
                input_report_key(dev, BTN_START,  data[4] & BIT(2));
                input_report_key(dev, BTN_SELECT, data[4] & BIT(3));
-               if (xpad->mapping & MAP_SELECT_BUTTON)
-                       input_report_key(dev, KEY_RECORD, data[22] & BIT(0));
+               if (xpad->mapping & MAP_SHARE_BUTTON) {
+                       if (xpad->mapping & MAP_SHARE_OFFSET)
+                               input_report_key(dev, KEY_RECORD, data[len - 26] & BIT(0));
+                       else
+                               input_report_key(dev, KEY_RECORD, data[len - 18] & BIT(0));
+               }
 
                /* buttons A,B,X,Y */
                input_report_key(dev, BTN_A,    data[4] & BIT(4));
@@ -1218,7 +1223,7 @@ static void xpad_irq_in(struct urb *urb)
                xpad360w_process_packet(xpad, 0, xpad->idata);
                break;
        case XTYPE_XBOXONE:
-               xpadone_process_packet(xpad, 0, xpad->idata);
+               xpadone_process_packet(xpad, 0, xpad->idata, urb->actual_length);
                break;
        default:
                xpad_process_packet(xpad, 0, xpad->idata);
@@ -1945,7 +1950,7 @@ static int xpad_init_input(struct usb_xpad *xpad)
            xpad->xtype == XTYPE_XBOXONE) {
                for (i = 0; xpad360_btn[i] >= 0; i++)
                        input_set_capability(input_dev, EV_KEY, xpad360_btn[i]);
-               if (xpad->mapping & MAP_SELECT_BUTTON)
+               if (xpad->mapping & MAP_SHARE_BUTTON)
                        input_set_capability(input_dev, EV_KEY, KEY_RECORD);
        } else {
                for (i = 0; xpad_btn[i] >= 0; i++)