Hi Jan, Here's the wireless controller patch rebased against the most recent xpad.c. It's a bit slimmer this time. :)
One thing I noticed is that the analog joysticks appear to be inverted from what I would expect. i.e. they operate in "flight simulator" mode where pushing up gets a negative value and down is postive. I don't have a wired xbox360 controller to compare it against so I'm wondering if this is as it should be or that it's somehow inverted for the wireless controller. I didn't enable the rumble function for this because I don't have a convient was to test if it works or not. Do you have a test application? Also, the *process_packet functions all take a u16 cmd argument which is always 0. Is there some future use for this in mind? This patch also includes a one-liner fix to xpad_init_ff. -Brian Signed-off-by: Brian Magnuson <[EMAIL PROTECTED]> --- drivers/input/joystick/xpad.c | 47 +++++++++++++++++++++++++++++++++++----- 1 files changed, 41 insertions(+), 6 deletions(-) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 664c765..4f22932 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -93,6 +93,7 @@ #define XTYPE_XBOX 0 #define XTYPE_XBOX360 1 +#define XTYPE_XBOX360W 2 static int dpad_to_buttons; module_param(dpad_to_buttons, bool, S_IRUGO); @@ -109,6 +110,7 @@ static const struct xpad_device { { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, { 0x045e, 0x0287, "Microsoft Xbox Controller S", MAP_DPAD_TO_AXES, XTYPE_XBOX }, + { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W }, { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, @@ -179,6 +181,7 @@ static const signed short xpad_abs_pad[] = { 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 */ + { USB_DEVICE_INTERFACE_PROTOCOL(0x045e, 0x0719, 129) }, /* X-Box 360 wireless receiver */ { } }; @@ -318,6 +321,34 @@ static void xpad360_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char input_sync(dev); } +/* + * xpad360w_process_packet + * + * Completes a request by converting the data into events for the + * input subsystem. It is version for xbox 360 wireless controller. + * + * As far as I know the format of the status bytes are not + * documented anywhere and these are guesses based on just + * looking at the data receieved. + * + * Byte.Bit + * 00.1 - Status change: The controller or headset has connected/disconnected + * Bits 01.7 and 01.6 are valid + * 01.7 - Controller present + * 01.6 - Headset present + * 01.1 - Pad state (Bytes 4+) valid + * + */ + +static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) +{ + /* Valid pad data */ + if (!(data[1] & 0x1)) + return; + + xpad360_process_packet(xpad, cmd, &data[4]); +} + static void xpad_irq_in(struct urb *urb) { struct usb_xpad *xpad = urb->context; @@ -338,10 +369,14 @@ static void xpad_irq_in(struct urb *urb) goto exit; } - if (xpad->xtype == XTYPE_XBOX360) - xpad360_process_packet(xpad, 0, xpad->idata); - else - xpad_process_packet(xpad, 0, xpad->idata); + switch (xpad->xtype) { + case XTYPE_XBOX360 : + xpad360_process_packet(xpad, 0, xpad->idata); break; + case XTYPE_XBOX360W : + xpad360w_process_packet(xpad, 0, xpad->idata); break; + default : + xpad_process_packet(xpad, 0, xpad->idata); + } exit: retval = usb_submit_urb (urb, GFP_ATOMIC); @@ -408,7 +443,7 @@ static int xpad_init_ff(struct usb_interface *intf, struct usb_xpad *xpad) xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN, GFP_ATOMIC, &xpad->odata_dma ); - if (!xpad->idata) + if (!xpad->odata) goto fail1; xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); @@ -550,7 +585,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id /* set up buttons */ for (i = 0; xpad_btn[i] >= 0; i++) set_bit(xpad_btn[i], input_dev->keybit); - if (xpad->xtype == XTYPE_XBOX360) + if ((xpad->xtype == XTYPE_XBOX360) || (xpad->xtype == XTYPE_XBOX360W)) for (i = 0; xpad360_btn[i] >= 0; i++) set_bit(xpad360_btn[i], input_dev->keybit); if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS) -- 1.4.4.2