Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input: xpad - initialize 360 controllers #120

Closed
wants to merge 10 commits into from
79 changes: 79 additions & 0 deletions xpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,79 @@ static int xpad_start_xbox_one(struct usb_xpad *xpad)
return retval;
}

static int xpad_start_xbox_360(struct usb_xpad *xpad)
{
int status;

char *data = kzalloc(20, GFP_KERNEL);

#define TIMEOUT 100

status = usb_control_msg(xpad->udev,
usb_rcvctrlpipe(xpad->udev, 0),
0x1, 0xc1,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using constants defined in uapi/linux/usb/ch9.h instead of magic values (0x1, 0xc1, etc.)

0x1 = USB_REQ_CLEAR_FETAURE
0xc1 = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE
0x100 = USB_DEVICE_REMOTE_WAKEUP

cpu_to_le16(0x100), cpu_to_le16(0x0), data, cpu_to_le16(20),
TIMEOUT);

#ifdef DEBUG
dev_dbg(&xpad->intf->dev,
"%s - control message 1 returned %d\n", __func__, status);
#endif

if (status < 0) {
goto err_free_ctrl_data;
}
#ifdef DEBUG
else {
print_hex_dump(KERN_DEBUG, "xpad-dbg: ", DUMP_PREFIX_OFFSET, 32, 1, data, 20, 0);
}
#endif

status = usb_control_msg(xpad->udev,
usb_rcvctrlpipe(xpad->udev, 0),
0x1, 0xc1,
cpu_to_le16(0x0), cpu_to_le16(0x0), data, cpu_to_le16(8),
TIMEOUT);
#ifdef DEBUG
dev_dbg(&xpad->intf->dev,
"%s - control message 2 returned %d\n", __func__, status);
#endif

if (status < 0) {
goto err_free_ctrl_data;
}
#ifdef DEBUG
else {
print_hex_dump(KERN_DEBUG, "xpad-dbg: ", DUMP_PREFIX_OFFSET, 32, 1, data, 8, 0);
}
#endif

status = usb_control_msg(xpad->udev,
usb_rcvctrlpipe(xpad->udev, 0),
0x1, 0xc0,
cpu_to_le16(0x0), cpu_to_le16(0x0), data, cpu_to_le16(4),
TIMEOUT);
#ifdef DEBUG
dev_dbg(&xpad->intf->dev,
"%s - control message 3 returned %d\n", __func__, status);
#endif

if (status < 0) {
goto err_free_ctrl_data;
}
#ifdef DEBUG
else {
print_hex_dump(KERN_DEBUG, "xpad-dbg: ", DUMP_PREFIX_OFFSET, 32, 1, data, 4, 0);
}
#endif

status = 0;

err_free_ctrl_data:
kfree(data);
return status;
}

static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num)
{
unsigned long flags;
Expand Down Expand Up @@ -1497,6 +1570,12 @@ static int xpad_start_input(struct usb_xpad *xpad)
{
int error;

if (xpad->xtype == XTYPE_XBOX360) {
error = xpad_start_xbox_360(xpad);
if (error)
return error;
}

if (usb_submit_urb(xpad->irq_in, GFP_KERNEL))
return -EIO;

Expand Down