From patchwork Sat Mar 23 16:46:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Salvatore X-Patchwork-Id: 10866877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC0701575 for ; Sat, 23 Mar 2019 16:47:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98BB52A01F for ; Sat, 23 Mar 2019 16:47:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 884072A02D; Sat, 23 Mar 2019 16:47:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3C6F2A01F for ; Sat, 23 Mar 2019 16:47:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727706AbfCWQqw (ORCPT ); Sat, 23 Mar 2019 12:46:52 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:36798 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727298AbfCWQqw (ORCPT ); Sat, 23 Mar 2019 12:46:52 -0400 Received: from c-73-130-187-69.hsd1.pa.comcast.net ([73.130.187.69] helo=[172.25.50.30]) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1h7jnE-0002wn-Cq; Sat, 23 Mar 2019 16:46:48 +0000 From: Mike Salvatore Subject: [PATCH] xpad.c: Send necessary control transfer to certain Xbox controllers Openpgp: preference=signencrypt Autocrypt: addr=mike.salvatore@canonical.com; keydata= xsFNBFtOHV4BEADAIuSzHrb7cmg24E0MGMRrIPQ/CxdHXs2aQi49SeYR+5HZO7Co9qh6k9/O pBsMgq3DflchsKpAEoB125S+riF2F3wdd22aXXQwainKWiGXX0kJRYaNM8uxIFtBEKq+Wco3 D3QedtG7Is8NNP0e/M0FbN1FlNFJGyIHvm3/bd4g7o7A4AAqlsgD0u9dh24HOlitdJwiQHvg c0kPKmpTStpC7l0OxH6/ljlHM3UIlGYLUIQz837jIvr/L3E8Ytgxk5K3jwwvIIhLoHLl4xN0 3bzzMUAddUnTOCfSp1v7oB/zHUenOIkNi7FSUTU4G3+gC2rigIx0Tijs1GPYjIkUsfNoH0sP aBSLmRirGObYlNPWLS2J1mSXBQsFcaIvHF4/vuiQUFudth/vgltdhjI0xsL8pQQ4VmC2dfZs 0S3v3T3brrOwGE7T4XwgL1HmveBVnnyMB6YvW2puv8+B4vmqG2A6ildpqLXSpSioo1ZmFG6H /XXwTaRDgAyLC0KzTLSSYwFgQU4w3hp8WFFKhBMVG5FM5YlpaVBV0IVbiwzfO1fB1D0+l8gR 4jt+1BHHfwRXhD8fzgiRHiMY+CcfEikpMRyfwKrWt18BWmUL13JU/7pV8772uFcLkielb7/k j1GcTFI3e2YA7iQycJY8YTntkn2iKgfMX39ZtiKcz4z+LNGyTQARAQABzS1NaWtlIFNhbHZh dG9yZSA8bWlrZS5zYWx2YXRvcmVAY2Fub25pY2FsLmNvbT7CwY4EEwEKADgWIQTBlt73qQl5 aHY4hNF3KDVDPShdfQUCW04dXgIbAwULCQgHAwUVCgkICwUWAgMBAAIeAQIXgAAKCRB3KDVD PShdfWr1D/9OXL8s143lnBb2DdGA1nVhoHvmmJl6tdWtxj0InmsUfgzaN5fRWC8n78hnwu76 qHKUw7hZV+bmq/BLCJLU4WpfaK/vxyQKCJOlqF3XpRZhndOYn1NVf31KpGTcLIiB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AIEM17Irf4JCjXW2aJnnR/7Xyr0 yhCJ1G+hmvrDJeno/qFTyC5IMxpQfbdHUPGZBH3fg9DSGk/yTFUD8AWB8DRbiWFVo97AuHBu h7zQhx59TyvuVG8bthN6NK8NKvOualTig9okhixz5854Zfp+zngYurFepOdveFITR0OCj7mN 6+T/feyN9ErTqKWKTtlKdUUAEQEAAcLBdgQYAQoAIBYhBMGW3vepCXlodjiE0XcoNUM9KF19 BQJbTh1eAhsMAAoJEHcoNUM9KF192tIP/RdBvin4pNEkqx1mYw7GB2l+vcx3UBtGccntlFzC O7xBWrs+ZEgpHrEVLSXBphlogCCS1Kbro1iQYxrMLRGEOfiQtXPRXOMdnfEvmGwPEuqlvzLL J3Yr8IzkgzadkeDTMzW3o5dpgVVjpXklRATcFMEA5TaYNayzeK+C2S6tcFJDCgnvcZGmiVTb tSE3FPSc4IueMCUo8MOG4ScLtEilBhhYcdjojxGY+2Dcmqc7O0kUMfVh37DyI04LJA+q7vBF ViRTtNnjpw0vxCx0s148foX6aNucEgo38RtV4G9ny5xqR0nkdDZBgMLEb2bDsuecy9vCXjZ3 zEXCyr0pO5Ytac6Q4wHFaLFGr+r9aybouv0l2gLIPunvyP/cmKq3Dz3M8W+eCAwExchKijeM TaDCzr/EfLI6AqUvMfbytcXBRan71sswixbkS6NsZ90TMfGJ7HiJ9muCZE9Wz2eYDvFf5LrT 1wHvtN2Qa5rIZ9928l3/3rjI1lQmmg77oanrqxMiIYNY1xTa3iYdBEYQgm7BNEWfs0yMQmj0 929aV/bkh7i36vcPud06DnV0Y45Pk1pyYmFrl9r95TbdtgzTA4LlkufEiTVIztJwh8FUOKiJ 5tc7NiImHPIIq0zKGpLuEum9DkMa9KmsISYB4wkS7H2suO74umCmFo74E9FyJGOPAVbI To: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org Cc: ramzeto@gmail.com, marcus.folkesson@gmail.com, flibitijibibo@gmail.com, aicommander@gmail.com, leosperling97@gmail.com, gottox@voidlinux.eu, frtherien@gmail.com, linux-kernel@vger.kernel.org Message-ID: Date: Sat, 23 Mar 2019 12:46:38 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, I recently purchased an Xbox controller with USB ID 045e:028e. When I plugged the device in, it was recognized as a joystick but button presses were not recognized. Using evtest, I confirmed that the device was not sending any information to the host when I pressed its buttons. After doing some research, I found that this particular device requires that the host send a control transfer before the device will begin sending any data to the host. Below is a patch that introduces a mechanism into xpad.c for sending control transfers to specific Xbox controllers at initialization. After applying this patch to the xpad module, the Xbox controller is properly initialized when plugged in and functions as expected. Other Xbox controllers may also require control transfers at initialization, but I don't know which (if any). Regards, Mike Salvatore From 3051524e62d68b920019bcb50a713e736fcf4234 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 13 Mar 2019 22:11:37 -0400 Subject: [PATCH] Input: xpad - send control init message to certain Xbox controllers The Xbox controller with idVendor == 0x045e and idProduct == 0x028e requires that a specific control transfer be sent from the host to the device before the device will send data to the host. This patch introduces an xboxone_control_packet struct and a mechanism for sending control packets to devices that require them at initialization. Signed-off-by: Mike Salvatore Signed-off-by: Mike Salvatore --- drivers/input/joystick/xpad.c | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index cfc8b94527b9..f45522b9ff1f 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -460,6 +460,25 @@ struct xboxone_init_packet { .len = ARRAY_SIZE(_data), \ } +struct xboxone_control_packet { + u16 idVendor; + u16 idProduct; + struct usb_ctrlrequest ctrlrequest; +}; + +#define XBOXONE_CONTROL_PKT(_vid, _pid, _reqtype, _req, _value, _index, _len) \ + { \ + .idVendor = (_vid), \ + .idProduct = (_pid), \ + .ctrlrequest = { \ + .bRequestType = (_reqtype), \ + .bRequest = (_req), \ + .wValue = (_value), \ + .wIndex = (_index), \ + .wLength = (_len), \ + }, \ + } + /* * This packet is required for all Xbox One pads with 2015 @@ -537,6 +556,13 @@ static const struct xboxone_init_packet xboxone_init_packets[] = { XBOXONE_INIT_PKT(0x24c6, 0x543a, xboxone_rumbleend_init), }; +static const struct xboxone_control_packet xboxone_control_packets[] = { + XBOXONE_CONTROL_PKT(0x045e, 0x028e, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, + USB_REQ_CLEAR_FEATURE, + USB_DEVICE_REMOTE_WAKEUP, 0, 0), +}; + struct xpad_output_packet { u8 data[XPAD_PKT_LEN]; u8 len; @@ -1119,6 +1145,31 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad, return error; } +static int xpad_init_control_msg(struct usb_xpad *xpad) +{ + struct usb_device *udev = xpad->udev; + size_t i; + + for (i = 0; i < ARRAY_SIZE(xboxone_control_packets); i++) { + u16 idVendor = xboxone_control_packets[i].idVendor; + u16 idProduct = xboxone_control_packets[i].idProduct; + + if (le16_to_cpu(udev->descriptor.idVendor) == idVendor + && le16_to_cpu(udev->descriptor.idProduct) == idProduct) { + const struct usb_ctrlrequest *ctrlrequest = + &(xboxone_control_packets[i].ctrlrequest); + + return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + ctrlrequest->bRequest, + ctrlrequest->bRequestType, ctrlrequest->wValue, + ctrlrequest->wIndex, NULL, ctrlrequest->wLength, + 2 * HZ); + } + } + + return 0; +} + static void xpad_stop_output(struct usb_xpad *xpad) { if (xpad->xtype != XTYPE_UNKNOWN) { @@ -1839,6 +1890,11 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id if (error) goto err_deinit_output; } + + error = xpad_init_control_msg(xpad); + if (error) + goto err_deinit_output; + return 0; err_deinit_output: