]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/input/joystick/xpad.c
Merge tag 'v4.10-rc5' into next
[mirror_ubuntu-bionic-kernel.git] / drivers / input / joystick / xpad.c
index 6d949965867190458abaa653636ed4ab6702a4aa..247fd3a6fc035753083792fbfb8a4fc3b04e807e 100644 (file)
@@ -320,18 +320,18 @@ static struct usb_device_id xpad_table[] = {
        XPAD_XBOXONE_VENDOR(0x0738),            /* Mad Catz FightStick TE 2 */
        XPAD_XBOX360_VENDOR(0x0e6f),            /* 0x0e6f X-Box 360 controllers */
        XPAD_XBOXONE_VENDOR(0x0e6f),            /* 0x0e6f X-Box One controllers */
+       XPAD_XBOX360_VENDOR(0x0f0d),            /* Hori Controllers */
+       XPAD_XBOXONE_VENDOR(0x0f0d),            /* Hori Controllers */
        XPAD_XBOX360_VENDOR(0x12ab),            /* X-Box 360 dance pads */
        XPAD_XBOX360_VENDOR(0x1430),            /* RedOctane X-Box 360 controllers */
        XPAD_XBOX360_VENDOR(0x146b),            /* BigBen Interactive Controllers */
-       XPAD_XBOX360_VENDOR(0x1bad),            /* Harminix Rock Band Guitar and Drums */
-       XPAD_XBOX360_VENDOR(0x0f0d),            /* Hori Controllers */
-       XPAD_XBOXONE_VENDOR(0x0f0d),            /* Hori Controllers */
-       XPAD_XBOX360_VENDOR(0x1689),            /* Razer Onza */
-       XPAD_XBOX360_VENDOR(0x24c6),            /* PowerA Controllers */
-       XPAD_XBOXONE_VENDOR(0x24c6),            /* PowerA Controllers */
        XPAD_XBOX360_VENDOR(0x1532),            /* Razer Sabertooth */
        XPAD_XBOX360_VENDOR(0x15e4),            /* Numark X-Box 360 controllers */
        XPAD_XBOX360_VENDOR(0x162e),            /* Joytech X-Box 360 controllers */
+       XPAD_XBOX360_VENDOR(0x1689),            /* Razer Onza */
+       XPAD_XBOX360_VENDOR(0x1bad),            /* Harminix Rock Band Guitar and Drums */
+       XPAD_XBOX360_VENDOR(0x24c6),            /* PowerA Controllers */
+       XPAD_XBOXONE_VENDOR(0x24c6),            /* PowerA Controllers */
        { }
 };
 
@@ -608,14 +608,28 @@ static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned cha
 }
 
 /*
- *     xpadone_process_buttons
+ *     xpadone_process_packet
  *
- *     Process a button update packet from an Xbox one controller.
+ *     Completes a request by converting the data into events for the
+ *     input subsystem. This version is for the Xbox One controller.
+ *
+ *     The report format was gleaned from
+ *     https://github.com/kylelemons/xbox/blob/master/xbox.go
  */
-static void xpadone_process_buttons(struct usb_xpad *xpad,
-                               struct input_dev *dev,
-                               unsigned char *data)
+static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
 {
+       struct input_dev *dev = xpad->dev;
+
+       /* the xbox button has its own special report */
+       if (data[0] == 0X07) {
+               input_report_key(dev, BTN_MODE, data[4] & 0x01);
+               input_sync(dev);
+               return;
+       }
+       /* check invalid packet */
+       else if (data[0] != 0X20)
+               return;
+
        /* menu/view buttons */
        input_report_key(dev, BTN_START,  data[4] & 0x04);
        input_report_key(dev, BTN_SELECT, data[4] & 0x08);
@@ -678,34 +692,6 @@ static void xpadone_process_buttons(struct usb_xpad *xpad,
        input_sync(dev);
 }
 
-/*
- *     xpadone_process_packet
- *
- *     Completes a request by converting the data into events for the
- *     input subsystem. This version is for the Xbox One controller.
- *
- *     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)
-{
-       struct input_dev *dev = xpad->dev;
-
-       switch (data[0]) {
-       case 0x20:
-               xpadone_process_buttons(xpad, dev, data);
-               break;
-
-       case 0x07:
-               /* the xbox button has its own special report */
-               input_report_key(dev, BTN_MODE, data[4] & 0x01);
-               input_sync(dev);
-               break;
-       }
-}
-
 static void xpad_irq_in(struct urb *urb)
 {
        struct usb_xpad *xpad = urb->context;
@@ -850,10 +836,9 @@ static void xpad_irq_out(struct urb *urb)
        spin_unlock_irqrestore(&xpad->odata_lock, flags);
 }
 
-static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
+static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad,
+                       struct usb_endpoint_descriptor *ep_irq_out)
 {
-       struct usb_endpoint_descriptor *ep_irq_out;
-       int ep_irq_out_idx;
        int error;
 
        if (xpad->xtype == XTYPE_UNKNOWN)
@@ -863,23 +848,17 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
 
        xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN,
                                         GFP_KERNEL, &xpad->odata_dma);
-       if (!xpad->odata) {
-               error = -ENOMEM;
-               goto fail1;
-       }
+       if (!xpad->odata)
+               return -ENOMEM;
 
        spin_lock_init(&xpad->odata_lock);
 
        xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL);
        if (!xpad->irq_out) {
                error = -ENOMEM;
-               goto fail2;
+               goto err_free_coherent;
        }
 
-       /* Xbox One controller has in/out endpoints swapped. */
-       ep_irq_out_idx = xpad->xtype == XTYPE_XBOXONE ? 0 : 1;
-       ep_irq_out = &intf->cur_altsetting->endpoint[ep_irq_out_idx].desc;
-
        usb_fill_int_urb(xpad->irq_out, xpad->udev,
                         usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress),
                         xpad->odata, XPAD_PKT_LEN,
@@ -889,8 +868,9 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
 
        return 0;
 
- fail2:        usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma);
- fail1:        return error;
+err_free_coherent:
+       usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma);
+       return error;
 }
 
 static void xpad_stop_output(struct usb_xpad *xpad)
@@ -1377,6 +1357,12 @@ static int xpad_init_input(struct usb_xpad *xpad)
        input_dev->name = xpad->name;
        input_dev->phys = xpad->phys;
        usb_to_input_id(xpad->udev, &input_dev->id);
+
+       if (xpad->xtype == XTYPE_XBOX360W) {
+               /* x360w controllers and the receiver have different ids */
+               input_dev->id.product = 0x02a1;
+       }
+
        input_dev->dev.parent = &xpad->intf->dev;
 
        input_set_drvdata(input_dev, xpad);
@@ -1462,8 +1448,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
 {
        struct usb_device *udev = interface_to_usbdev(intf);
        struct usb_xpad *xpad;
-       struct usb_endpoint_descriptor *ep_irq_in;
-       int ep_irq_in_idx;
+       struct usb_endpoint_descriptor *ep_irq_in, *ep_irq_out;
        int i, error;
 
        if (intf->cur_altsetting->desc.bNumEndpoints != 2)
@@ -1533,13 +1518,26 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
                goto err_free_in_urb;
        }
 
-       error = xpad_init_output(intf, xpad);
-       if (error)
+       ep_irq_in = ep_irq_out = NULL;
+
+       for (i = 0; i < 2; i++) {
+               struct usb_endpoint_descriptor *ep =
+                               &intf->cur_altsetting->endpoint[i].desc;
+
+               if (usb_endpoint_dir_in(ep))
+                       ep_irq_in = ep;
+               else
+                       ep_irq_out = ep;
+       }
+
+       if (!ep_irq_in || !ep_irq_out) {
+               error = -ENODEV;
                goto err_free_in_urb;
+       }
 
-       /* Xbox One controller has in/out endpoints swapped. */
-       ep_irq_in_idx = xpad->xtype == XTYPE_XBOXONE ? 1 : 0;
-       ep_irq_in = &intf->cur_altsetting->endpoint[ep_irq_in_idx].desc;
+       error = xpad_init_output(intf, xpad, ep_irq_out);
+       if (error)
+               goto err_free_in_urb;
 
        usb_fill_int_urb(xpad->irq_in, udev,
                         usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),