From patchwork Sat Dec 31 20:43:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cameron Gutman X-Patchwork-Id: 9492783 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C6C1660416 for ; Sat, 31 Dec 2016 20:46:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8C321FF1D for ; Sat, 31 Dec 2016 20:46:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD0DC203C0; Sat, 31 Dec 2016 20:46:17 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 55E7B1FF1D for ; Sat, 31 Dec 2016 20:46:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754575AbcLaUqQ (ORCPT ); Sat, 31 Dec 2016 15:46:16 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:36018 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753296AbcLaUqP (ORCPT ); Sat, 31 Dec 2016 15:46:15 -0500 Received: by mail-io0-f194.google.com with SMTP id m204so18808470ioe.3; Sat, 31 Dec 2016 12:46:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=PTfksO6Cht1jq7e/MZocL/Xx9n4O1o81YBViMdqxHWY=; b=nKq5xunqynTZT5gKOGNVMNGgzUJdAw695FzMBGBOdyvoYSRI4+X4eGLhsysCiP/nOm dysIJ0rm4vu6/8EobmY/9a7cRbzyhpGltACah97MeExxwBBrQuOEk16Na7udVm4WRJNT miXZlndahSZERjAcl+2AOZaZz7jtQf7HTvTnmY0Yyogx3Wr2hvEWRUmpZueG1MdQmguX kMjkNEGSvmX2VsLwWhb3QLFxBFc+8WTjI8WEg7gxXd8fIQpR5HIvHqhb8rtAdVYfQPJc hFD5dXSDg7LLUJzwcb2hRWwc3e6qBlW9f4BuwMAtZTXrq4hDX3ssbwlrkwQMTXtI4Wob WAfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PTfksO6Cht1jq7e/MZocL/Xx9n4O1o81YBViMdqxHWY=; b=rDVqnttUo0/GfGO3NwJbQ0xptdBqKsBVQ6cL6jJsWqaKMTng+n9q8q9RjFiTJTABLS iEIg9Tit9OC38UOFHK2EOE71zuMgdbz8B6vIFXcoSbDs1dFrznOmKvjnzsbn20d0WvSH upBHNdXTJDubIjCQFpaV+qFyZxz4UcBbY2/4niPGkB/mi2h+trwQ7fa8bDqRQXrQwPOX 9vF5eJhty5jMdZQmKEfHMY7hBi+nQUeAIYzG4VDpxXHzzaKVQr0obxU9ifMhTAtLFz+S 5X01WBZatAYZAUpfpFSHJVCFrx03kUuis9ovD7LRuGi5g2WD745dTgG+gHD4QYbsxjEM Gh+w== X-Gm-Message-State: AIkVDXIZ2ppA30wAigTbR7oEjhOFkUfiOnaUutIqlLbYFIkJRvNWVDSqTOPyrVDxajjkcA== X-Received: by 10.107.130.207 with SMTP id m76mr31214348ioi.38.1483217174110; Sat, 31 Dec 2016 12:46:14 -0800 (PST) Received: from isys.cwru.edu (isys.student.CWRU.Edu. [129.22.149.112]) by smtp.gmail.com with ESMTPSA id f187sm21501179ita.7.2016.12.31.12.46.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 31 Dec 2016 12:46:13 -0800 (PST) From: Cameron Gutman To: dmitry.torokhov@gmail.com, rojtberg@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Cameron Gutman Subject: [PATCH] Input: xpad - Don't depend on endpoint order Date: Sat, 31 Dec 2016 15:43:38 -0500 Message-Id: <1483217018-21150-1-git-send-email-aicommander@gmail.com> X-Mailer: git-send-email 2.7.4 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 The order of endpoints is well defined on official Xbox pads, but we have found at least one 3rd-party pad that doesn't follow the standard ("Titanfall 2 Xbox One controller" 0e6f:0165). Fortunately, we get lucky with this specific pad because it uses endpoint addresses that differ only by direction. We know that there are other pads out where this is not true, so let's go ahead and fix this. Signed-off-by: Cameron Gutman --- drivers/input/joystick/xpad.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index c7d5b2b..f264d5e 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -850,15 +850,11 @@ 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) - return 0; - init_usb_anchor(&xpad->irq_out_anchor); xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN, @@ -876,10 +872,6 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) goto fail2; } - /* 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, @@ -1468,8 +1460,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) @@ -1539,13 +1530,22 @@ 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++) { + if (usb_endpoint_dir_in(&intf->cur_altsetting->endpoint[i].desc)) + ep_irq_in = &intf->cur_altsetting->endpoint[i].desc; + else + ep_irq_out = &intf->cur_altsetting->endpoint[i].desc; + } + + 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),