[PATCH 11/37] Input: xpad - match xbox 360 devices with interface info

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <unlisted-recipients@...>, <@...>
Cc: <linux-kernel@...>, <jkosina@...>, <akpm@...>
Date: Thursday, April 3, 2008 - 4:17 pm

Match Xbox 360 controllers using the interface info, i.e. interface
class 255 (Vendor specific), subclass 93 and protocol 1, instead of
specifying the device ids individually. As the class is vendor-specific,
we have to still match against vendor id as well, though.

Signed-off-by: Anssi Hannula <anssi.hannula@gmail.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---
 drivers/input/joystick/xpad.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 0380597..8804ad3 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -91,6 +91,7 @@
 
 #define XTYPE_XBOX        0
 #define XTYPE_XBOX360     1
+#define XTYPE_UNKNOWN     2
 
 static int dpad_to_buttons;
 module_param(dpad_to_buttons, bool, S_IRUGO);
@@ -138,7 +139,7 @@ static const struct xpad_device {
 	{ 0x1430, 0x8888, "TX6500+ Dance Pad (first generation)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
 	{ 0x045e, 0x028e, "Microsoft X-Box 360 pad", MAP_DPAD_TO_AXES, XTYPE_XBOX360 },
 	{ 0xffff, 0xffff, "Chinese-made Xbox Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX },
-	{ 0x0000, 0x0000, "Generic X-Box pad", MAP_DPAD_UNKNOWN, XTYPE_XBOX }
+	{ 0x0000, 0x0000, "Generic X-Box pad", MAP_DPAD_UNKNOWN, XTYPE_UNKNOWN }
 };
 
 static const signed short xpad_btn[] = {
@@ -173,12 +174,20 @@ static const signed short xpad_abs_pad[] = {
 	-1			/* terminating entry */
 };
 
-/* Xbox 360 has a vendor-specific (sub)class, so we cannot match it with only
- * USB_INTERFACE_INFO, more to that this device has 4 InterfaceProtocols,
- * but we need only one of them. */
+/* Xbox 360 has a vendor-specific class, so we cannot match it with only
+ * USB_INTERFACE_INFO (also specifically refused by USB subsystem), so we
+ * match against vendor id as well. Also, some Xbox 360 devices have multiple
+ * interface protocols, we only need protocol 1. */
+#define XPAD_XBOX360_VENDOR(vend) \
+	.match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_INFO, \
+	.idVendor = (vend), \
+	.bInterfaceClass = USB_CLASS_VENDOR_SPEC, \
+	.bInterfaceSubClass = 93, \
+	.bInterfaceProtocol = 1
+
 static struct usb_device_id xpad_table [] = {
 	{ USB_INTERFACE_INFO('X', 'B', 0) },	/* X-Box USB-IF not approved class */
-	{ USB_DEVICE_INTERFACE_PROTOCOL(0x045e, 0x028e, 1) },	/* X-Box 360 controller */
+	{ XPAD_XBOX360_VENDOR(0x045e) },	/* Microsoft X-Box 360 controllers */
 	{ }
 };
 
@@ -645,6 +654,8 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
 	xpad->xtype = xpad_device[i].xtype;
 	if (xpad->dpad_mapping == MAP_DPAD_UNKNOWN)
 		xpad->dpad_mapping = dpad_to_buttons;
+	if (xpad->xtype == XTYPE_UNKNOWN)
+		xpad->xtype = (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC);
 	xpad->dev = input_dev;
 	usb_make_path(udev, xpad->phys, sizeof(xpad->phys));
 	strlcat(xpad->phys, "/input0", sizeof(xpad->phys));
-- 
1.5.5.rc2.6.gf58d


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/37] Input queue for 2.6.26 merge window, Dmitry Torokhov, (Mon Apr 21, 9:14 am)
Re: [PATCH 00/37] Input queue for 2.6.26 merge window, Henrique de Moraes Holschuh..., (Mon Apr 21, 11:11 am)
Re: [PATCH 00/37] Input queue for 2.6.26 merge window, Dmitry Torokhov, (Mon Apr 21, 11:44 am)
Re: [PATCH 00/37] Input queue for 2.6.26 merge window, Henrique de Moraes Holschuh..., (Mon Apr 21, 12:58 pm)
[PATCH 28/37] Input: add Zhen Hua driver, Martin Kebert, (Mon Mar 10, 8:40 am)
[PATCH 10/37] Input: tosakbd - fix suspend, Dmitry Baryshkov, (Wed Apr 2, 11:22 am)
[PATCH 35/37] Input: bf54x-keys - add infrastructure for key..., Michael Hennerich, (Fri Apr 18, 12:25 am)
[PATCH 19/37] Input: xpad - don't use GFP_ATOMIC, Oliver Neukum, (Thu Apr 3, 4:19 pm)
[PATCH 11/37] Input: xpad - match xbox 360 devices with inte..., Anssi Hannula, (Thu Apr 3, 4:17 pm)
[PATCH 29/37] Input: fix ordering in joystick Makefile, Jiri Kosina, (Mon Mar 10, 8:43 am)
Re: [PATCH 29/37] Input: fix ordering in joystick Makefile, Dmitry Torokhov, (Mon Apr 21, 11:39 am)
Re: [PATCH 29/37] Input: fix ordering in joystick Makefile, Dmitry Torokhov, (Mon Apr 21, 12:20 pm)
[PATCH 24/37] Input: omap-keypad - fix build warning, David Brownell, (Tue Apr 15, 1:31 am)
[PATCH 22/37] Input: add PS/2 serio driver for AVR32 devices, Hans-Christian Egtvedt, (Tue Apr 15, 1:30 am)
Re: [PATCH 22/37] Input: add PS/2 serio driver for AVR32 dev..., Hans-Christian Egtvedt, (Mon Apr 21, 9:33 am)
[PATCH 23/37] Input: gpio_keys - irq handling cleanup, David Brownell, (Tue Apr 15, 1:31 am)
[PATCH 13/37] Input: xpad - fix inverted Y and RY axes, Anssi Hannula, (Thu Apr 3, 4:18 pm)