Input: xpad - fix stuck mode button on Xbox One S pad
authorCameron Gutman <aicommander@gmail.com>
Mon, 6 Feb 2017 21:56:10 +0000 (13:56 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 6 Feb 2017 22:15:15 +0000 (14:15 -0800)
The Xbox One S requires an ack to its mode button report, otherwise it
continuously retransmits the report. This makes the mode button appear to
be stuck down after it is pressed for the first time.

Signed-off-by: Cameron Gutman <aicommander@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/joystick/xpad.c

index 247fd3a..03e24f5 100644 (file)
@@ -389,6 +389,7 @@ struct usb_xpad {
 
 static int xpad_init_input(struct usb_xpad *xpad);
 static void xpad_deinit_input(struct usb_xpad *xpad);
+static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num);
 
 /*
  *     xpad_process_packet
@@ -622,6 +623,14 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
 
        /* the xbox button has its own special report */
        if (data[0] == 0X07) {
+               /*
+                * The Xbox One S controller requires these reports to be
+                * acked otherwise it continues sending them forever and
+                * won't report further mode button events.
+                */
+               if (data[1] == 0x30)
+                       xpadone_ack_mode_report(xpad, data[2]);
+
                input_report_key(dev, BTN_MODE, data[4] & 0x01);
                input_sync(dev);
                return;
@@ -954,6 +963,30 @@ static int xpad_start_xbox_one(struct usb_xpad *xpad)
        return retval;
 }
 
+static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num)
+{
+       unsigned long flags;
+       struct xpad_output_packet *packet =
+                       &xpad->out_packets[XPAD_OUT_CMD_IDX];
+       static const u8 mode_report_ack[] = {
+               0x01, 0x20, 0x00, 0x09, 0x00, 0x07, 0x20, 0x02,
+               0x00, 0x00, 0x00, 0x00, 0x00
+       };
+
+       spin_lock_irqsave(&xpad->odata_lock, flags);
+
+       packet->len = sizeof(mode_report_ack);
+       memcpy(packet->data, mode_report_ack, packet->len);
+       packet->data[2] = seq_num;
+       packet->pending = true;
+
+       /* Reset the sequence so we send out the ack now */
+       xpad->last_out_packet = -1;
+       xpad_try_sending_next_out_packet(xpad);
+
+       spin_unlock_irqrestore(&xpad->odata_lock, flags);
+}
+
 #ifdef CONFIG_JOYSTICK_XPAD_FF
 static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect)
 {