From patchwork Tue Sep 18 00:47:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603583 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 260CE157B for ; Tue, 18 Sep 2018 00:47:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DF4A2AA08 for ; Tue, 18 Sep 2018 00:47:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0208A2AA19; Tue, 18 Sep 2018 00:47:38 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 A35D02AA08 for ; Tue, 18 Sep 2018 00:47:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726258AbeIRGRa (ORCPT ); Tue, 18 Sep 2018 02:17:30 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:40148 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725807AbeIRGRa (ORCPT ); Tue, 18 Sep 2018 02:17:30 -0400 Received: by mail-pl1-f193.google.com with SMTP id s17-v6so102258plp.7; Mon, 17 Sep 2018 17:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zkjzQCWB8ZZ5VtAYMN5MrijD10AZ6RpRKaEwok1IRjQ=; b=cMynRSCNi8e3Dv/V3CYa55Zm4jzropiPQc0UIWQ9N2ZUNu2df8rKCdJKjLv3biBgdt //2Pb3LSjiVrhlUoXJ1jpgELeVJDGuIs6FVzlB85J7WdTKojezyVvANKHYot24xXWPh4 H+obM98SEjHl4xAwrzdOqTL3rcszDFuBijzrzTpJlZaDQAX3lMFp3yjvCYhnN6rFq4f9 fUYsMg5RxON0APB/I2801LjAfDbco4bVAginlJOeVEiHLdtV1K/w50UI/N8hJeMGvq4B fEK/6C5VGPOxLKv+71+bQxvXzwSQ3yfGWg7ea/xy4dewpJay7wZo+uC0Ac8EBagqQyhk ZHrA== 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:mime-version :content-transfer-encoding; bh=zkjzQCWB8ZZ5VtAYMN5MrijD10AZ6RpRKaEwok1IRjQ=; b=dE2cP5dcVcus9lrV5DN9igahCNHPj1T5eLV0j3rIok+MbQiZ5rr4PKweWveIVb64ne qlHIjNWa6HJSRlMLnG7ndhaBhWBX1sWmZBEvJIOxjBhsdAkFtRLNSBNQYbc+N3QW+Y3D PdKxkqhLgJWAEwKPSjVkHM6ZMJA0MiaxMtyv/4phVUFX7/AHrfKb6kp7sWcheGfp7Yo1 tMw0WUnF/YJg1ylnwg85RlaT/5Yr4eqYpJEK/Y74vjbLMwJZTMdKQaNUI+7iorGfRsGb 7aMstzK6dT7EUt1V6g8M8HtgIvOCOXZ/KtaRNJhIGfxGcnRXlj7cfeeEAfKaBZ/z5VeA abdQ== X-Gm-Message-State: APzg51C058LX8ABh+/uhupv+vGuoA2PpeuqOqLtLzZIydoCjuR9Vf/MZ RrZMzx1a/l0V9oGuQb6fwcIshtAZ X-Google-Smtp-Source: ANB0VdYb64832uGHouizYpMLa0h78RWaKl81TTCnQmdXrlSioqDX1kKM0mX3vB2Q8fbo4KcCLzz0Bg== X-Received: by 2002:a17:902:14d:: with SMTP id 71-v6mr26178364plb.146.1537231656298; Mon, 17 Sep 2018 17:47:36 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:35 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 01/20] Input: iforce - remove "being used" silliness Date: Mon, 17 Sep 2018 17:47:13 -0700 Message-Id: <20180918004732.9875-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog 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 The kernel is supposed to handle multiple devices, static flags in packet handling code will never work. Signed-off-by: Dmitry Torokhov --- This is a random assortment of iforce patches that I made a few weeks back. Tim, I do not have hardware, so I was bound to screw it up, but if you have some time I'd appreciate if you try them out (and if I indeed broke things if you could identify issues that would be even more awesome). Thanks! drivers/input/joystick/iforce/iforce-packets.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c index c10169f4554e..91893c751524 100644 --- a/drivers/input/joystick/iforce/iforce-packets.c +++ b/drivers/input/joystick/iforce/iforce-packets.c @@ -149,12 +149,6 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) { struct input_dev *dev = iforce->dev; int i; - static int being_used = 0; - - if (being_used) - dev_warn(&iforce->dev->dev, - "re-entrant call to iforce_process %d\n", being_used); - being_used++; #ifdef CONFIG_JOYSTICK_IFORCE_232 if (HI(iforce->expect_packet) == HI(cmd)) { @@ -165,10 +159,8 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) #endif wake_up(&iforce->wait); - if (!iforce->type) { - being_used--; + if (!iforce->type) return; - } switch (HI(cmd)) { @@ -233,7 +225,6 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) } break; } - being_used--; } int iforce_get_id_packet(struct iforce *iforce, char *packet) From patchwork Tue Sep 18 00:47:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603621 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 BA282157B for ; Tue, 18 Sep 2018 00:49:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9A5B2A9D5 for ; Tue, 18 Sep 2018 00:49:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DD002A9E7; Tue, 18 Sep 2018 00:49:24 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 215242A9D5 for ; Tue, 18 Sep 2018 00:49:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729015AbeIRGRd (ORCPT ); Tue, 18 Sep 2018 02:17:33 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39213 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725807AbeIRGRc (ORCPT ); Tue, 18 Sep 2018 02:17:32 -0400 Received: by mail-pg1-f194.google.com with SMTP id i190-v6so109368pgc.6; Mon, 17 Sep 2018 17:47:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hjHW6GAdKl25iWmfD9ZbtgysZDtLOgpSph44E0kquHA=; b=rx2YjMxnYL88ikAKC2HG0zluRL6ROhfTH5/N4xq5Nx3OfLdKu96AbMRuE8HuQ26m+8 Q9H2VbgufwhlUsNlGvi2kU6O04QhshbRoAVjj/wegmVMOpgSu9otAIm9m8XteBkG8oTr mPywTbOiirknHf9xyYCMYSjrVOFmYD+ChJO7+qkmuV4tUut1nXYkczYMl26NI+U2hUrQ Zwu6OJahDniIusvRzjt0dxRFbS4ORPTLIm85oFf1Pq3s50bC0xXrHS+oDVePO2zTa4Jf ORdC9vKONjWEdHaCExuklgO+zg1qS4H1M60OSpGm1FoxYDUnlk8IP9A5VKzQ05cqzOXE pWuA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=hjHW6GAdKl25iWmfD9ZbtgysZDtLOgpSph44E0kquHA=; b=XTekhyf46ark/JNY9njulsr5pP6dw3HffEirCtnf8f9WoCHetlEEXfJ8ftWw7GFYlI qH1gfUCLYqN4FzA9BCV5XJFzAUveerhVCc34Od/ptp+YZ9S9zkCIK6UMFtSWpqc4WVfk RxfOxDeWRPOXahmECSFoAyfl6fSdUtl64X8R5xpFzBroN/0aXSCTK2iVGAERcORvUTlV YsFljBpFX9rp4MWejaZ1uX3z4ikkyT0Ozbrt49SJbwjh7rogiGNd/iYH9agZmhpXPFg3 2aUGQ1Nr+ZZQ9GZVtil+SXVnD3MEmLvjWxCZT/VJDd9JYCNsf/d4Zqx3MstV2v8UvQa7 O0oA== X-Gm-Message-State: APzg51AtJAbBXJZZGiHdn8U2O2n8bbdlF90vziOW7HcGpWVXqu2VqOGS Qa4DcNu49LQahph5DNldD3q9F5WF X-Google-Smtp-Source: ANB0VdZTSI8H6U1e7uKOh7dhZFlhgDe66odUfQBl/vCbzIionlJdl8MoR5YjZqd2QrWVW74OncPX3w== X-Received: by 2002:a63:9e0a:: with SMTP id s10-v6mr25810556pgd.326.1537231657662; Mon, 17 Sep 2018 17:47:37 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:36 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 02/20] Input: iforce - introduce transport ops Date: Mon, 17 Sep 2018 17:47:14 -0700 Message-Id: <20180918004732.9875-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 In order to tease apart the driver into core and transport modules, let's introduce transport operations and make "xmit" the very first one such operation. Signed-off-by: Dmitry Torokhov --- .../input/joystick/iforce/iforce-packets.c | 20 ++----------------- drivers/input/joystick/iforce/iforce-serio.c | 9 +++++++-- drivers/input/joystick/iforce/iforce-usb.c | 15 ++++++++++++-- drivers/input/joystick/iforce/iforce.h | 13 ++++++------ 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c index 91893c751524..b8ca9bdfdef8 100644 --- a/drivers/input/joystick/iforce/iforce-packets.c +++ b/drivers/input/joystick/iforce/iforce-packets.c @@ -91,25 +91,9 @@ int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data) /* * If necessary, start the transmission */ - switch (iforce->bus) { - -#ifdef CONFIG_JOYSTICK_IFORCE_232 - case IFORCE_232: - if (empty) - iforce_serial_xmit(iforce); - break; -#endif -#ifdef CONFIG_JOYSTICK_IFORCE_USB - case IFORCE_USB: + if (empty) + iforce->xport_ops->xmit(iforce); - if (iforce->usbdev && empty && - !test_and_set_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags)) { - - iforce_usb_xmit(iforce); - } - break; -#endif - } return 0; } diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index f4ba4a751fe0..c9469209f994 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -23,7 +23,7 @@ #include "iforce.h" -void iforce_serial_xmit(struct iforce *iforce) +static void iforce_serio_xmit(struct iforce *iforce) { unsigned char cs; int i; @@ -67,11 +67,15 @@ void iforce_serial_xmit(struct iforce *iforce) spin_unlock_irqrestore(&iforce->xmit_lock, flags); } +static const struct iforce_xport_ops iforce_serio_xport_ops = { + .xmit = iforce_serio_xmit, +}; + static void iforce_serio_write_wakeup(struct serio *serio) { struct iforce *iforce = serio_get_drvdata(serio); - iforce_serial_xmit(iforce); + iforce_serio_xmit(iforce); } static irqreturn_t iforce_serio_irq(struct serio *serio, @@ -129,6 +133,7 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) if (!iforce) return -ENOMEM; + iforce->xport_ops = &iforce_serio_xport_ops; iforce->bus = IFORCE_232; iforce->serio = serio; diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index 78073259c9a1..d4f7f34db9a0 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c @@ -23,7 +23,7 @@ #include "iforce.h" -void iforce_usb_xmit(struct iforce *iforce) +static void __iforce_usb_xmit(struct iforce *iforce) { int n, c; unsigned long flags; @@ -69,6 +69,16 @@ void iforce_usb_xmit(struct iforce *iforce) spin_unlock_irqrestore(&iforce->xmit_lock, flags); } +static void iforce_usb_xmit(struct iforce *iforce) +{ + if (!test_and_set_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags)) + __iforce_usb_xmit(iforce); +} + +static const struct iforce_xport_ops iforce_usb_xport_ops = { + .xmit = iforce_usb_xmit, +}; + static void iforce_usb_irq(struct urb *urb) { struct iforce *iforce = urb->context; @@ -113,7 +123,7 @@ static void iforce_usb_out(struct urb *urb) return; } - iforce_usb_xmit(iforce); + __iforce_usb_xmit(iforce); wake_up(&iforce->wait); } @@ -155,6 +165,7 @@ static int iforce_usb_probe(struct usb_interface *intf, if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL))) goto fail; + iforce->xport_ops = &iforce_usb_xport_ops; iforce->bus = IFORCE_USB; iforce->usbdev = dev; iforce->intf = intf; diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h index 0e9d01f8bcb6..2fea3be751ed 100644 --- a/drivers/input/joystick/iforce/iforce.h +++ b/drivers/input/joystick/iforce/iforce.h @@ -93,9 +93,16 @@ struct iforce_device { signed short *ff; }; +struct iforce; + +struct iforce_xport_ops { + void (*xmit)(struct iforce *iforce); +}; + struct iforce { struct input_dev *dev; /* Input device interface */ struct iforce_device *type; + const struct iforce_xport_ops *xport_ops; int bus; unsigned char data[IFORCE_MAX_LENGTH]; @@ -141,12 +148,6 @@ struct iforce { /* Public functions */ -/* iforce-serio.c */ -void iforce_serial_xmit(struct iforce *iforce); - -/* iforce-usb.c */ -void iforce_usb_xmit(struct iforce *iforce); - /* iforce-main.c */ int iforce_init_device(struct iforce *iforce); From patchwork Tue Sep 18 00:47:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603585 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 9D446157B for ; Tue, 18 Sep 2018 00:47:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CB732AA08 for ; Tue, 18 Sep 2018 00:47:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80B5E2AA20; Tue, 18 Sep 2018 00:47:46 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 F10A12AA08 for ; Tue, 18 Sep 2018 00:47:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725807AbeIRGRe (ORCPT ); Tue, 18 Sep 2018 02:17:34 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35429 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729069AbeIRGRd (ORCPT ); Tue, 18 Sep 2018 02:17:33 -0400 Received: by mail-pg1-f194.google.com with SMTP id 7-v6so117977pgf.2; Mon, 17 Sep 2018 17:47:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Re7V/+eHmV1ScUdnfZ229caXo8Q+chYJv59OC/pPiXI=; b=CWB52MIbaTOo/B0Z5tsnwYMNBFF3jehAwA0/8P0wD2qKXv95tRcZKJu1DLnL/eSkV/ 8tJy1polvDwUMg5KdqPvvPyuCUVsInbk6L3jINmSvJbehk5LxTl0SizWQwti1ZnH8l+o LfQz3kzzhl3V54Y6cc5VmiUSVp1Aw3AlXgvGEsnMEXFNkYdmKpS1y1yc6HrdNkxAw+0W LfLc8/gr41x2XE/vZctSqrh7nMGrKEpxgCzdpKhlQmz6azOscnC1MXS2nut9O5SjzLMa gGs/iowvhuPhFuf2eevXKCT9S2DvvoZ6vxMC5U8JazHQryCY4DknLJhOfI2YxQxrGcjm eM6g== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Re7V/+eHmV1ScUdnfZ229caXo8Q+chYJv59OC/pPiXI=; b=L/cuitHfqjhkvnUxtvumP/q0S/zj+boc0MOKNjCSRRiIYv7V/lvvpg6jiAqkwvoF4k 7VQIg6A1hyBw7C3G4lpm6z1kiqnxGWzO2XZ6fOSqBmHVZSlQHASBogmSuQYcSlKHIprw goY5vThOpAvSub3FQPq4BEJ6gglEOw1g4KL9ebNIK8c3Bsza9n0vhcbCoQl80w4Y8N3K qbUjpbSOnYAoiGObHqxd8cDAoruXx/nkFt5Lsy5scsnD644ay6zdUFpZwNPxIqrWfDvc g2Rd3eKaPlRm3QBo+razEHmlQUtQJ6mtWbPsTUEaZgH22NWH7VZcZh0B0pxEWlo2ip0H LKbQ== X-Gm-Message-State: APzg51DDjCZOSKID+4vp8RQp/MJXLp2gVvgP7RL0CYKhsAQSDuIfImDb PAyu8EHhtf71h7GUId8Emmy48LJC X-Google-Smtp-Source: ANB0Vdbijjxp9sHCzKpDyrbXkDj5zLHo18NEwqjbXO+dfvmuDPysQOmYyZ8/IBP+TGm11ZYs2v08Zg== X-Received: by 2002:a63:c702:: with SMTP id n2-v6mr25934569pgg.108.1537231659032; Mon, 17 Sep 2018 17:47:39 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:38 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 03/20] Input: iforce - move get_id to the transport operations Date: Mon, 17 Sep 2018 17:47:15 -0700 Message-Id: <20180918004732.9875-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 To avoid #ifdef-ing out parts of the code and having conditionals in normal control flow, let's define "get_id" transport method and move implementation into respective transport modules. Signed-off-by: Dmitry Torokhov --- .../input/joystick/iforce/iforce-packets.c | 64 ------------------- drivers/input/joystick/iforce/iforce-serio.c | 17 +++++ drivers/input/joystick/iforce/iforce-usb.c | 29 +++++++++ drivers/input/joystick/iforce/iforce.h | 6 +- 4 files changed, 51 insertions(+), 65 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c index b8ca9bdfdef8..e677562efc9a 100644 --- a/drivers/input/joystick/iforce/iforce-packets.c +++ b/drivers/input/joystick/iforce/iforce-packets.c @@ -210,67 +210,3 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) break; } } - -int iforce_get_id_packet(struct iforce *iforce, char *packet) -{ - switch (iforce->bus) { - - case IFORCE_USB: { -#ifdef CONFIG_JOYSTICK_IFORCE_USB - int status; - - iforce->cr.bRequest = packet[0]; - iforce->ctrl->dev = iforce->usbdev; - - status = usb_submit_urb(iforce->ctrl, GFP_KERNEL); - if (status) { - dev_err(&iforce->intf->dev, - "usb_submit_urb failed %d\n", status); - return -1; - } - - wait_event_interruptible_timeout(iforce->wait, - iforce->ctrl->status != -EINPROGRESS, HZ); - - if (iforce->ctrl->status) { - dev_dbg(&iforce->intf->dev, - "iforce->ctrl->status = %d\n", - iforce->ctrl->status); - usb_unlink_urb(iforce->ctrl); - return -1; - } -#else - printk(KERN_DEBUG "iforce_get_id_packet: iforce->bus = USB!\n"); -#endif - } - break; - - case IFORCE_232: - -#ifdef CONFIG_JOYSTICK_IFORCE_232 - iforce->expect_packet = FF_CMD_QUERY; - iforce_send_packet(iforce, FF_CMD_QUERY, packet); - - wait_event_interruptible_timeout(iforce->wait, - !iforce->expect_packet, HZ); - - if (iforce->expect_packet) { - iforce->expect_packet = 0; - return -1; - } -#else - dev_err(&iforce->dev->dev, - "iforce_get_id_packet: iforce->bus = SERIO!\n"); -#endif - break; - - default: - dev_err(&iforce->dev->dev, - "iforce_get_id_packet: iforce->bus = %d\n", - iforce->bus); - break; - } - - return -(iforce->edata[0] != packet[0]); -} - diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index c9469209f994..fa45ce425d47 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -67,8 +67,25 @@ static void iforce_serio_xmit(struct iforce *iforce) spin_unlock_irqrestore(&iforce->xmit_lock, flags); } +static int iforce_serio_get_id(struct iforce *iforce, u8 *packet) +{ + iforce->expect_packet = FF_CMD_QUERY; + iforce_send_packet(iforce, FF_CMD_QUERY, packet); + + wait_event_interruptible_timeout(iforce->wait, + !iforce->expect_packet, HZ); + + if (iforce->expect_packet) { + iforce->expect_packet = 0; + return -EIO; + } + + return -(iforce->edata[0] != packet[0]); +} + static const struct iforce_xport_ops iforce_serio_xport_ops = { .xmit = iforce_serio_xmit, + .get_id = iforce_serio_get_id, }; static void iforce_serio_write_wakeup(struct serio *serio) diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index d4f7f34db9a0..f7eeaad92602 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c @@ -75,8 +75,37 @@ static void iforce_usb_xmit(struct iforce *iforce) __iforce_usb_xmit(iforce); } +static int iforce_usb_get_id(struct iforce *iforce, u8 *packet) +{ + int status; + + iforce->cr.bRequest = packet[0]; + iforce->ctrl->dev = iforce->usbdev; + + status = usb_submit_urb(iforce->ctrl, GFP_KERNEL); + if (status) { + dev_err(&iforce->intf->dev, + "usb_submit_urb failed %d\n", status); + return -EIO; + } + + wait_event_interruptible_timeout(iforce->wait, + iforce->ctrl->status != -EINPROGRESS, HZ); + + if (iforce->ctrl->status) { + dev_dbg(&iforce->intf->dev, + "iforce->ctrl->status = %d\n", + iforce->ctrl->status); + usb_unlink_urb(iforce->ctrl); + return -EIO; + } + + return -(iforce->edata[0] != packet[0]); +} + static const struct iforce_xport_ops iforce_usb_xport_ops = { .xmit = iforce_usb_xmit, + .get_id = iforce_usb_get_id, }; static void iforce_usb_irq(struct urb *urb) diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h index 2fea3be751ed..f6636230be31 100644 --- a/drivers/input/joystick/iforce/iforce.h +++ b/drivers/input/joystick/iforce/iforce.h @@ -97,6 +97,7 @@ struct iforce; struct iforce_xport_ops { void (*xmit)(struct iforce *iforce); + int (*get_id)(struct iforce *iforce, u8* id); }; struct iforce { @@ -146,6 +147,10 @@ struct iforce { /* Encode a time value */ #define TIME_SCALE(a) (a) +static inline int iforce_get_id_packet(struct iforce *iforce, u8* id) +{ + return iforce->xport_ops->get_id(iforce, id); +} /* Public functions */ /* iforce-main.c */ @@ -156,7 +161,6 @@ int iforce_control_playback(struct iforce*, u16 id, unsigned int); void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data); int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data); void iforce_dump_packet(struct iforce *iforce, char *msg, u16 cmd, unsigned char *data); -int iforce_get_id_packet(struct iforce *iforce, char *packet); /* iforce-ff.c */ int iforce_upload_periodic(struct iforce *, struct ff_effect *, struct ff_effect *); From patchwork Tue Sep 18 00:47:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603619 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 B6094157B for ; Tue, 18 Sep 2018 00:49:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4D072A9D5 for ; Tue, 18 Sep 2018 00:49:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98A5A2A9E7; Tue, 18 Sep 2018 00:49:19 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 461762A9D5 for ; Tue, 18 Sep 2018 00:49:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728922AbeIRGRf (ORCPT ); Tue, 18 Sep 2018 02:17:35 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36754 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729070AbeIRGRf (ORCPT ); Tue, 18 Sep 2018 02:17:35 -0400 Received: by mail-pg1-f193.google.com with SMTP id d1-v6so116515pgo.3; Mon, 17 Sep 2018 17:47:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ASxqEhgQ7B67xw9F76ph/2Ld0TEHcTytkExevqFD/b0=; b=ietSreGJ/b43bF1W5FBUn72l9loRar2LmBFb/uHdPFfhlGzBrYVbV9jUCj+AVPMaiw Jr3IKH9mi/4nzfxyEHTJnVqQh10umxFLX4bRCjhfyHjEiO2dm95PHwOQvb+GdbwukM5z q2gKA7sA6MEZH/04VQ6568B1oHBGf0JptEvMbBGTJJoiC/hXbLGXYxem52wXl4+BxghJ 5fFqZg1iJcgQLscP3fuz/ueCu6LG4vAeTJlfkVSyjbxBtFliVN6VTNMTUlLgqlYzbX3U OrZGMvHJikpdGRLuI7pu+NiYulf/SWNUQ9HFTBnKhGRxNKBRcAXXz4vIC7WC2mgC3517 5+Yg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=ASxqEhgQ7B67xw9F76ph/2Ld0TEHcTytkExevqFD/b0=; b=DjzVL25lBnRHlPdavR6RxdrIwElhKgmrUDjYx8gcXlLL32Wq6t46jw33E/kT9QPqkL K0ETJ7DV0cq/F3s4toQIQ8xFT8Gti6mdX2VL1XpxP/8pJggXo4Jq3qSI/F91R2AJ/nti 9mTQDYTFPFFT1eU4BEA/opWvxZhbDwChmpTvm7wl1lLCTv+gPuvNtFK7xdi5Ai+Dd+Q1 Dj6ucztTocvsqLFcmeR7i0hOPivddZpn90RyzR2OJwLfxYUCAifNq6AzmG5wjJIDgVQm rOJnlWMhGXQsvZYzNAfRsHLVjxpW6id+M3AvawI+COWP8+wgrTbFwo1HUYUfw+Q3rhb1 ssLw== X-Gm-Message-State: APzg51AbNLZ+u8SZoUSGvhuDO5MuwfMJwvtVFnc+iwq6fRwYT7dHHs8T Rdbl/BJIy0CmTzr5/Ez4VyxnKGVn X-Google-Smtp-Source: ANB0VdbkS3wZLeox1kaP55zyFGfTFtxAtCc7DqT3lxfdpbcbU1z/UUZRh+iFBvLaFpH09ANnSyAKzg== X-Received: by 2002:a63:e949:: with SMTP id q9-v6mr25361765pgj.4.1537231660488; Mon, 17 Sep 2018 17:47:40 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:39 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 04/20] Input: iforce - move command completion handling to serio code Date: Mon, 17 Sep 2018 17:47:16 -0700 Message-Id: <20180918004732.9875-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 Continue teasing apart protocol-specific bits from core into transport modules. This time move RS232-specific command completion handling from core to iforce-serio module. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-packets.c | 7 ------- drivers/input/joystick/iforce/iforce-serio.c | 12 +++++++++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c index e677562efc9a..8a9a152bb595 100644 --- a/drivers/input/joystick/iforce/iforce-packets.c +++ b/drivers/input/joystick/iforce/iforce-packets.c @@ -134,13 +134,6 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) struct input_dev *dev = iforce->dev; int i; -#ifdef CONFIG_JOYSTICK_IFORCE_232 - if (HI(iforce->expect_packet) == HI(cmd)) { - iforce->expect_packet = 0; - iforce->ecmd = cmd; - memcpy(iforce->edata, data, IFORCE_MAX_LENGTH); - } -#endif wake_up(&iforce->wait); if (!iforce->type) diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index fa45ce425d47..eca2f6eca7f0 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -130,7 +130,17 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, } if (iforce->idx == iforce->len) { - iforce_process_packet(iforce, (iforce->id << 8) | iforce->idx, iforce->data); + u16 cmd = (iforce->id << 8) | iforce->idx; + + /* Handle command completion */ + if (HI(iforce->expect_packet) == HI(cmd)) { + iforce->expect_packet = 0; + iforce->ecmd = cmd; + memcpy(iforce->edata, iforce->data, IFORCE_MAX_LENGTH); + } + + iforce_process_packet(iforce, cmd, iforce->data); + iforce->pkt = 0; iforce->id = 0; iforce->len = 0; From patchwork Tue Sep 18 00:47:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603587 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 C43C815E8 for ; Tue, 18 Sep 2018 00:47:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B343E2AA08 for ; Tue, 18 Sep 2018 00:47:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A793D2AA19; Tue, 18 Sep 2018 00:47:47 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 27B652AA12 for ; Tue, 18 Sep 2018 00:47:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729218AbeIRGRh (ORCPT ); Tue, 18 Sep 2018 02:17:37 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:39288 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729070AbeIRGRg (ORCPT ); Tue, 18 Sep 2018 02:17:36 -0400 Received: by mail-pl1-f193.google.com with SMTP id w14-v6so103509plp.6; Mon, 17 Sep 2018 17:47:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I+6YNMxcg8OUbqbH0Mt0mHDfm7vio0fVTRA9D6WdfA0=; b=nko+JCW8qRpn1h8QgWy72A9JJZSFlA7W4KXj0ywB/6KcH0CFxKIVA8aS5s/HfSHa9U KZXbhnXshlOa35Cw8Ap9Dhg1mMd9Yw8S0aM2QY0XnQm065rfos8xyQnQCX+D0I3Bt17S dKdOvt8OMLqWjho+sbFiy5IQlec5fixrceo0TUFuN4HrK+Dw+FNOpM79pITqjTPnA8rP yqYA4iw0fiH13lj/RHqi75v1G7Byus97+otIhIpYpDlUwig1MgTiShggcwuAeGzCHQT1 GaIH+HarH22K2BZTWkZZ+yZGd+VtPpU+Bf1/pbd3t4fIw0L/F5nhmpBvpJ7wV+GSaWzk 4zmQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=I+6YNMxcg8OUbqbH0Mt0mHDfm7vio0fVTRA9D6WdfA0=; b=P2Xo8rwCTSAuNXj01VCmoWNRhbD3uupKqvNYBrKdeAk5sQLzSrKVPYwGwBrRp0Xb6f xXdfuP7Ja2/X7BGIrZ7AwfWPeB08GjC/yPr+cC3SNJhGknzG0OCfrXSUSPlhfdltT5LC gx2jITbS5zj0EYWKOvCeJc4cYrrOlKS5kKf/astEwRU3zf4w+MRvQd87+mUIwsMDPhJo OufO4w3/LW9k9vtZAhfhgmXCzM+RWAZSS5zwm4HMFLobdiLfg5qLWa2lD8UGGr+M/X40 u9P8GKXJ+KsZ1u4a5byuaHj6Xspi4iWKI0DyVp7anSIdJKhu6N68ce1/lzmkQ5Z4kMJO SvwA== X-Gm-Message-State: APzg51A07n3Q3EviNmgxKnSCId6T2YDbwxF2yKJQteJYfexpi7H4kuH3 mjNKTOhpXILAet5bdn7PZ7v8CTjQ X-Google-Smtp-Source: ANB0VdYhmuoeiZUTpzdVDaDwe55QOF4PqbkPs1CkeBT3VuyWJ4jOzP99TmXFNgwpFveEken7PNB0oQ== X-Received: by 2002:a17:902:402:: with SMTP id 2-v6mr26631501ple.277.1537231662492; Mon, 17 Sep 2018 17:47:42 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:40 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 05/20] Input: iforce - introduce start and stop io transport ops Date: Mon, 17 Sep 2018 17:47:17 -0700 Message-Id: <20180918004732.9875-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 Add start_io() and stop_io() transport methods so that core does not have to know the details. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-main.c | 25 ++------------------ drivers/input/joystick/iforce/iforce-serio.c | 13 ++++++++++ drivers/input/joystick/iforce/iforce-usb.c | 17 +++++++++++++ drivers/input/joystick/iforce/iforce.h | 2 ++ 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c index 58d5cfe46526..4401ca4a4c38 100644 --- a/drivers/input/joystick/iforce/iforce-main.c +++ b/drivers/input/joystick/iforce/iforce-main.c @@ -185,15 +185,7 @@ static int iforce_open(struct input_dev *dev) { struct iforce *iforce = input_get_drvdata(dev); - switch (iforce->bus) { -#ifdef CONFIG_JOYSTICK_IFORCE_USB - case IFORCE_USB: - iforce->irq->dev = iforce->usbdev; - if (usb_submit_urb(iforce->irq, GFP_KERNEL)) - return -EIO; - break; -#endif - } + iforce->xport_ops->start_io(iforce); if (test_bit(EV_FF, dev->evbit)) { /* Enable force feedback */ @@ -226,20 +218,7 @@ static void iforce_close(struct input_dev *dev) !test_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags)); } - switch (iforce->bus) { -#ifdef CONFIG_JOYSTICK_IFORCE_USB - case IFORCE_USB: - usb_kill_urb(iforce->irq); - usb_kill_urb(iforce->out); - usb_kill_urb(iforce->ctrl); - break; -#endif -#ifdef CONFIG_JOYSTICK_IFORCE_232 - case IFORCE_232: - //TODO: Wait for the last packets to be sent - break; -#endif - } + iforce->xport_ops->stop_io(iforce); } int iforce_init_device(struct iforce *iforce) diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index eca2f6eca7f0..afc7521b430d 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -83,9 +83,22 @@ static int iforce_serio_get_id(struct iforce *iforce, u8 *packet) return -(iforce->edata[0] != packet[0]); } +static int iforce_serio_start_io(struct iforce *iforce) +{ + /* No special handling required */ + return 0; +} + +static void iforce_serio_stop_io(struct iforce *iforce) +{ + //TODO: Wait for the last packets to be sent +} + static const struct iforce_xport_ops iforce_serio_xport_ops = { .xmit = iforce_serio_xmit, .get_id = iforce_serio_get_id, + .start_io = iforce_serio_start_io, + .stop_io = iforce_serio_stop_io, }; static void iforce_serio_write_wakeup(struct serio *serio) diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index f7eeaad92602..10b583b5fc82 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c @@ -103,9 +103,26 @@ static int iforce_usb_get_id(struct iforce *iforce, u8 *packet) return -(iforce->edata[0] != packet[0]); } +static int iforce_usb_start_io(struct iforce *iforce) +{ + if (usb_submit_urb(iforce->irq, GFP_KERNEL)) + return -EIO; + + return 0; +} + +static void iforce_usb_stop_io(struct iforce *iforce) +{ + usb_kill_urb(iforce->irq); + usb_kill_urb(iforce->out); + usb_kill_urb(iforce->ctrl); +} + static const struct iforce_xport_ops iforce_usb_xport_ops = { .xmit = iforce_usb_xmit, .get_id = iforce_usb_get_id, + .start_io = iforce_usb_start_io, + .stop_io = iforce_usb_stop_io, }; static void iforce_usb_irq(struct urb *urb) diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h index f6636230be31..c020d61eccf2 100644 --- a/drivers/input/joystick/iforce/iforce.h +++ b/drivers/input/joystick/iforce/iforce.h @@ -98,6 +98,8 @@ struct iforce; struct iforce_xport_ops { void (*xmit)(struct iforce *iforce); int (*get_id)(struct iforce *iforce, u8* id); + int (*start_io)(struct iforce *iforce); + void (*stop_io)(struct iforce *iforce); }; struct iforce { From patchwork Tue Sep 18 00:47:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603617 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 ECB4215E8 for ; Tue, 18 Sep 2018 00:49:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC6F92A9D5 for ; Tue, 18 Sep 2018 00:49:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D092F2A9E7; Tue, 18 Sep 2018 00:49:09 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 6ECC82A9D5 for ; Tue, 18 Sep 2018 00:49:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729255AbeIRGRk (ORCPT ); Tue, 18 Sep 2018 02:17:40 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:35700 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729070AbeIRGRi (ORCPT ); Tue, 18 Sep 2018 02:17:38 -0400 Received: by mail-pl1-f194.google.com with SMTP id g2-v6so111909plo.2; Mon, 17 Sep 2018 17:47:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ptHpG94iG8JdtUK1/m7tAxhwZpuHN0rNhGhfBTFsAvc=; b=RKYzLolWwan4vuO4GKC1pQNY8McACKheEYxMbc0L+io2IckRAdzriZJgzg45kxn6pr v8a7lm8w4dj1AkE4NS9vphKa6qzYUB+u8yurYKIEz+pasSsaqK0+ztpQvAjF+UwDcHJe OjhSerr41DVlBz3/ePO/+rrRrnGz6e0rBB6sSeIGeS3BlVZ/KbdTJe+HAjL0JetKbJHm 7VBMkt/lGABgOoW2Y3/9yce0bEz+VvccydHKpgrW1JV7FB3HXSg7F+nhUVGu7xyY7be0 lkmJFJN9WSYItX97/MOclTecyUfQ8rOMSEEXpwL87rSXwbYS/DPDp3Cr2WzHNBQk97Ip g7iQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=ptHpG94iG8JdtUK1/m7tAxhwZpuHN0rNhGhfBTFsAvc=; b=XvEuTmi6Judfcyd7XYlF21rnxHCyyk6ITAH3AvqkrbinEpkUedYpA1NxmoEwXkvGlE 8SQ5l9ZX7RKiA79dqher/Dz9QW9XEZmVpj6VXdKNjywgA5fIwi74BFEB/jCw+8MOQVFc oTgBa7cKbBQ3l4kPhoGE8TLjyqDnEi77dwdzwWkoveAxfzkjiahVebbj4mZCPhmHj4ov D8sTfZ61j5A0IOapxs2fii6XSzfdy5d3mrYxhRjA4Hbi0q2YsR3L/kY+0IdzeIN8uKoo rP515G7JkY1thkK5LZLhY+dtZBLGS/LAqOsYOJoEWuRxHrrHqfzrGnTMxDfCKl3lExF0 cd8w== X-Gm-Message-State: APzg51A6ZxSAiQC09WcCSEULZ+dK2j/WoG7575zlhqHYtETuyxIRqToS Pqja/BllwQk0rDeQTarLg1TbqyBQ X-Google-Smtp-Source: ANB0VdbtAML6YP93rw61DspBR096C7IEhVrAorlv+W04DchUhXKzD9JPMfTIdgvDGqP5jcMrzLvT7A== X-Received: by 2002:a17:902:22e:: with SMTP id 43-v6mr27311411plc.118.1537231664425; Mon, 17 Sep 2018 17:47:44 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:42 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 06/20] Input: iforce - add bus type and parent arguments to iforce_init_device() Date: Mon, 17 Sep 2018 17:47:18 -0700 Message-Id: <20180918004732.9875-6-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 Note that the parent device for the USB-connected controllers is now USB interface instead of USB device. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-main.c | 19 ++++--------------- drivers/input/joystick/iforce/iforce-serio.c | 2 +- drivers/input/joystick/iforce/iforce-usb.c | 2 +- drivers/input/joystick/iforce/iforce.h | 3 ++- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c index 4401ca4a4c38..894769d03df3 100644 --- a/drivers/input/joystick/iforce/iforce-main.c +++ b/drivers/input/joystick/iforce/iforce-main.c @@ -221,7 +221,8 @@ static void iforce_close(struct input_dev *dev) iforce->xport_ops->stop_io(iforce); } -int iforce_init_device(struct iforce *iforce) +int iforce_init_device(struct device *parent, u16 bustype, + struct iforce *iforce) { struct input_dev *input_dev; struct ff_device *ff; @@ -243,20 +244,8 @@ int iforce_init_device(struct iforce *iforce) * Input device fields. */ - switch (iforce->bus) { -#ifdef CONFIG_JOYSTICK_IFORCE_USB - case IFORCE_USB: - input_dev->id.bustype = BUS_USB; - input_dev->dev.parent = &iforce->usbdev->dev; - break; -#endif -#ifdef CONFIG_JOYSTICK_IFORCE_232 - case IFORCE_232: - input_dev->id.bustype = BUS_RS232; - input_dev->dev.parent = &iforce->serio->dev; - break; -#endif - } + input_dev->id.bustype = bustype; + input_dev->dev.parent = parent; input_set_drvdata(input_dev, iforce); diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index afc7521b430d..b5dea273f98e 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -183,7 +183,7 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) if (err) goto fail1; - err = iforce_init_device(iforce); + err = iforce_init_device(&serio->dev, BUS_RS232, iforce); if (err) goto fail2; diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index 10b583b5fc82..824df4273774 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c @@ -229,7 +229,7 @@ static int iforce_usb_probe(struct usb_interface *intf, usb_fill_control_urb(iforce->ctrl, dev, usb_rcvctrlpipe(dev, 0), (void*) &iforce->cr, iforce->edata, 16, iforce_usb_ctrl, iforce); - err = iforce_init_device(iforce); + err = iforce_init_device(&intf->dev, BUS_USB, iforce); if (err) goto fail; diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h index c020d61eccf2..3ee9245a415b 100644 --- a/drivers/input/joystick/iforce/iforce.h +++ b/drivers/input/joystick/iforce/iforce.h @@ -156,7 +156,8 @@ static inline int iforce_get_id_packet(struct iforce *iforce, u8* id) /* Public functions */ /* iforce-main.c */ -int iforce_init_device(struct iforce *iforce); +int iforce_init_device(struct device *parent, u16 bustype, + struct iforce *iforce); /* iforce-packets.c */ int iforce_control_playback(struct iforce*, u16 id, unsigned int); From patchwork Tue Sep 18 00:47:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603615 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 2885415E8 for ; Tue, 18 Sep 2018 00:49:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17CB72A9D5 for ; Tue, 18 Sep 2018 00:49:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C0A92A9E7; Tue, 18 Sep 2018 00:49:09 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 071382A9D5 for ; Tue, 18 Sep 2018 00:49:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729070AbeIRGRk (ORCPT ); Tue, 18 Sep 2018 02:17:40 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:33139 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729265AbeIRGRk (ORCPT ); Tue, 18 Sep 2018 02:17:40 -0400 Received: by mail-pl1-f195.google.com with SMTP id b97-v6so114756plb.0; Mon, 17 Sep 2018 17:47:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FgPl4w9HaMfmh7DcHLhKWt4fytbo9xppMylF8EnTB4g=; b=iBMfc05cYiFtjmi6BKkq+GqRLEGJ07/ySa23o9iq2HAgsyOQS8MFolQwpGOy89SbZw 6f0sV2+WfbL2+LoFEMJJICNErqjcFuWundogy84LTkAMeL1ZEXHfM/wpzpujO4MlZ+BK WOqgyyEbjq7O2QDV0NOfg16w3fcwnrNe1e9j8D+R4OxA4+/xxEDLvmZK837ZK/0qnL8/ 2yXsPEU0r3NIXHNLUT2VlsNL+TNjuIWuEQ6IxykUTgpxRi6U+HOX80F74IUWKEYu7kJz go4VBQrazw0FMeQEPK0AUHqXf8FMNva1Y6UppB6I1po/HZ0ifeVWoOwnMhE/oBGlKuCA nHNg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=FgPl4w9HaMfmh7DcHLhKWt4fytbo9xppMylF8EnTB4g=; b=lr0YkiAzQNNHuaLnUFRgDXOe/J340i66IvCONkrHQ2330AryPVL6qUHnuF6tnjotbv AoD3Lp/7lnEW4u2zevuedXm4MGFHEolY0wG98l1kWSYW04+6iEX/Ag6+oJn5MxKskem0 IuAPlVXB61lZqFjk4oMjk+HvV5QL+43FwxOeCsb5S2sAPsnxX8xkDXvhHqTwVJFM2sW4 f6SutQcBDJWmu9GRXPaRn1q6b4IkGzYXi6iUZxB6X27KfcMeJjjDf3fEw3YwtSHJhODg A95HhvGtGB9lofY13XWDC7kdcN9WBgn1maftceI9+C7R7zXfxCVHE4bDW13TEbOzNXhX Qg/Q== X-Gm-Message-State: APzg51AhUpCeRgOgycMIT36KAy+tXvtKUvkyBzl9WvvDTnPAkvy3uO4h ejA17J4/ZL6gAX6QTJ809OM1nfxH X-Google-Smtp-Source: ANB0Vdbvns3DTEBwzkeQtbUIvdodPN7GBXBcgw9CLmvFDow9SN25YaAfVruO8dP9wmIL92oWtOsH9g== X-Received: by 2002:a17:902:3c5:: with SMTP id d63-v6mr26763447pld.145.1537231665987; Mon, 17 Sep 2018 17:47:45 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:44 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 07/20] Input: iforce - move transport data into transport modules Date: Mon, 17 Sep 2018 17:47:19 -0700 Message-Id: <20180918004732.9875-7-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 This moves transport-specific data from main iforce structure into transport modules. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-serio.c | 96 ++++++++----- drivers/input/joystick/iforce/iforce-usb.c | 138 +++++++++++-------- drivers/input/joystick/iforce/iforce.h | 14 +- 3 files changed, 144 insertions(+), 104 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index b5dea273f98e..6ff1bbeeb494 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -23,8 +23,20 @@ #include "iforce.h" +struct iforce_serio { + struct iforce iforce; + + struct serio *serio; + int idx, pkt, len, id; + u8 csum; + u8 expect_packet; +}; + static void iforce_serio_xmit(struct iforce *iforce) { + struct iforce_serio *iforce_serio = container_of(iforce, + struct iforce_serio, + iforce); unsigned char cs; int i; unsigned long flags; @@ -45,19 +57,20 @@ static void iforce_serio_xmit(struct iforce *iforce) cs = 0x2b; - serio_write(iforce->serio, 0x2b); + serio_write(iforce_serio->serio, 0x2b); - serio_write(iforce->serio, iforce->xmit.buf[iforce->xmit.tail]); + serio_write(iforce_serio->serio, iforce->xmit.buf[iforce->xmit.tail]); cs ^= iforce->xmit.buf[iforce->xmit.tail]; XMIT_INC(iforce->xmit.tail, 1); for (i=iforce->xmit.buf[iforce->xmit.tail]; i >= 0; --i) { - serio_write(iforce->serio, iforce->xmit.buf[iforce->xmit.tail]); + serio_write(iforce_serio->serio, + iforce->xmit.buf[iforce->xmit.tail]); cs ^= iforce->xmit.buf[iforce->xmit.tail]; XMIT_INC(iforce->xmit.tail, 1); } - serio_write(iforce->serio, cs); + serio_write(iforce_serio->serio, cs); if (test_and_clear_bit(IFORCE_XMIT_AGAIN, iforce->xmit_flags)) goto again; @@ -69,14 +82,18 @@ static void iforce_serio_xmit(struct iforce *iforce) static int iforce_serio_get_id(struct iforce *iforce, u8 *packet) { - iforce->expect_packet = FF_CMD_QUERY; + struct iforce_serio *iforce_serio = container_of(iforce, + struct iforce_serio, + iforce); + + iforce_serio->expect_packet = HI(FF_CMD_QUERY); iforce_send_packet(iforce, FF_CMD_QUERY, packet); wait_event_interruptible_timeout(iforce->wait, - !iforce->expect_packet, HZ); + !iforce_serio->expect_packet, HZ); - if (iforce->expect_packet) { - iforce->expect_packet = 0; + if (iforce_serio->expect_packet) { + iforce_serio->expect_packet = 0; return -EIO; } @@ -111,54 +128,56 @@ static void iforce_serio_write_wakeup(struct serio *serio) static irqreturn_t iforce_serio_irq(struct serio *serio, unsigned char data, unsigned int flags) { - struct iforce *iforce = serio_get_drvdata(serio); + struct iforce_serio *iforce_serio = serio_get_drvdata(serio); + struct iforce *iforce = &iforce_serio->iforce; - if (!iforce->pkt) { + if (!iforce_serio->pkt) { if (data == 0x2b) - iforce->pkt = 1; + iforce_serio->pkt = 1; goto out; } - if (!iforce->id) { + if (!iforce_serio->id) { if (data > 3 && data != 0xff) - iforce->pkt = 0; + iforce_serio->pkt = 0; else - iforce->id = data; + iforce_serio->id = data; goto out; } - if (!iforce->len) { + if (!iforce_serio->len) { if (data > IFORCE_MAX_LENGTH) { - iforce->pkt = 0; - iforce->id = 0; + iforce_serio->pkt = 0; + iforce_serio->id = 0; } else { - iforce->len = data; + iforce_serio->len = data; } goto out; } - if (iforce->idx < iforce->len) { - iforce->csum += iforce->data[iforce->idx++] = data; + if (iforce_serio->idx < iforce_serio->len) { + iforce->data[iforce_serio->idx++] = data; + iforce_serio->csum += data; goto out; } - if (iforce->idx == iforce->len) { - u16 cmd = (iforce->id << 8) | iforce->idx; + if (iforce_serio->idx == iforce_serio->len) { + u16 cmd = (iforce_serio->id << 8) | iforce_serio->idx; /* Handle command completion */ - if (HI(iforce->expect_packet) == HI(cmd)) { - iforce->expect_packet = 0; + if (iforce_serio->expect_packet == iforce_serio->id) { + iforce_serio->expect_packet = 0; iforce->ecmd = cmd; memcpy(iforce->edata, iforce->data, IFORCE_MAX_LENGTH); } iforce_process_packet(iforce, cmd, iforce->data); - iforce->pkt = 0; - iforce->id = 0; - iforce->len = 0; - iforce->idx = 0; - iforce->csum = 0; + iforce_serio->pkt = 0; + iforce_serio->id = 0; + iforce_serio->len = 0; + iforce_serio->idx = 0; + iforce_serio->csum = 0; } out: return IRQ_HANDLED; @@ -166,18 +185,21 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) { + struct iforce_serio *iforce_serio; struct iforce *iforce; int err; - iforce = kzalloc(sizeof(struct iforce), GFP_KERNEL); - if (!iforce) + iforce_serio = kzalloc(sizeof(*iforce_serio), GFP_KERNEL); + if (!iforce_serio) return -ENOMEM; + iforce = &iforce_serio->iforce; + iforce->xport_ops = &iforce_serio_xport_ops; iforce->bus = IFORCE_232; - iforce->serio = serio; - serio_set_drvdata(serio, iforce); + iforce_serio->serio = serio; + serio_set_drvdata(serio, iforce_serio); err = serio_open(serio, drv); if (err) @@ -191,18 +213,18 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) fail2: serio_close(serio); fail1: serio_set_drvdata(serio, NULL); - kfree(iforce); + kfree(iforce_serio); return err; } static void iforce_serio_disconnect(struct serio *serio) { - struct iforce *iforce = serio_get_drvdata(serio); + struct iforce_serio *iforce_serio = serio_get_drvdata(serio); - input_unregister_device(iforce->dev); + input_unregister_device(iforce_serio->iforce.dev); serio_close(serio); serio_set_drvdata(serio, NULL); - kfree(iforce); + kfree(iforce_serio); } static const struct serio_device_id iforce_serio_ids[] = { diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index 824df4273774..d4e7a24922cd 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c @@ -23,8 +23,19 @@ #include "iforce.h" +struct iforce_usb { + struct iforce iforce; + + struct usb_device *usbdev; + struct usb_interface *intf; + struct urb *irq, *out, *ctrl; + struct usb_ctrlrequest cr; +}; + static void __iforce_usb_xmit(struct iforce *iforce) { + struct iforce_usb *iforce_usb = container_of(iforce, struct iforce_usb, + iforce); int n, c; unsigned long flags; @@ -36,31 +47,32 @@ static void __iforce_usb_xmit(struct iforce *iforce) return; } - ((char *)iforce->out->transfer_buffer)[0] = iforce->xmit.buf[iforce->xmit.tail]; + ((char *)iforce_usb->out->transfer_buffer)[0] = iforce->xmit.buf[iforce->xmit.tail]; XMIT_INC(iforce->xmit.tail, 1); n = iforce->xmit.buf[iforce->xmit.tail]; XMIT_INC(iforce->xmit.tail, 1); - iforce->out->transfer_buffer_length = n + 1; - iforce->out->dev = iforce->usbdev; + iforce_usb->out->transfer_buffer_length = n + 1; + iforce_usb->out->dev = iforce_usb->usbdev; /* Copy rest of data then */ c = CIRC_CNT_TO_END(iforce->xmit.head, iforce->xmit.tail, XMIT_SIZE); if (n < c) c=n; - memcpy(iforce->out->transfer_buffer + 1, + memcpy(iforce_usb->out->transfer_buffer + 1, &iforce->xmit.buf[iforce->xmit.tail], c); if (n != c) { - memcpy(iforce->out->transfer_buffer + 1 + c, + memcpy(iforce_usb->out->transfer_buffer + 1 + c, &iforce->xmit.buf[0], n-c); } XMIT_INC(iforce->xmit.tail, n); - if ( (n=usb_submit_urb(iforce->out, GFP_ATOMIC)) ) { + if ( (n=usb_submit_urb(iforce_usb->out, GFP_ATOMIC)) ) { clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags); - dev_warn(&iforce->intf->dev, "usb_submit_urb failed %d\n", n); + dev_warn(&iforce_usb->intf->dev, + "usb_submit_urb failed %d\n", n); } /* The IFORCE_XMIT_RUNNING bit is not cleared here. That's intended. @@ -77,26 +89,28 @@ static void iforce_usb_xmit(struct iforce *iforce) static int iforce_usb_get_id(struct iforce *iforce, u8 *packet) { + struct iforce_usb *iforce_usb = container_of(iforce, struct iforce_usb, + iforce); int status; - iforce->cr.bRequest = packet[0]; - iforce->ctrl->dev = iforce->usbdev; + iforce_usb->cr.bRequest = packet[0]; + iforce_usb->ctrl->dev = iforce_usb->usbdev; - status = usb_submit_urb(iforce->ctrl, GFP_KERNEL); + status = usb_submit_urb(iforce_usb->ctrl, GFP_KERNEL); if (status) { - dev_err(&iforce->intf->dev, + dev_err(&iforce_usb->intf->dev, "usb_submit_urb failed %d\n", status); return -EIO; } wait_event_interruptible_timeout(iforce->wait, - iforce->ctrl->status != -EINPROGRESS, HZ); + iforce_usb->ctrl->status != -EINPROGRESS, HZ); - if (iforce->ctrl->status) { - dev_dbg(&iforce->intf->dev, + if (iforce_usb->ctrl->status) { + dev_dbg(&iforce_usb->intf->dev, "iforce->ctrl->status = %d\n", - iforce->ctrl->status); - usb_unlink_urb(iforce->ctrl); + iforce_usb->ctrl->status); + usb_unlink_urb(iforce_usb->ctrl); return -EIO; } @@ -105,7 +119,10 @@ static int iforce_usb_get_id(struct iforce *iforce, u8 *packet) static int iforce_usb_start_io(struct iforce *iforce) { - if (usb_submit_urb(iforce->irq, GFP_KERNEL)) + struct iforce_usb *iforce_usb = container_of(iforce, struct iforce_usb, + iforce); + + if (usb_submit_urb(iforce_usb->irq, GFP_KERNEL)) return -EIO; return 0; @@ -113,9 +130,12 @@ static int iforce_usb_start_io(struct iforce *iforce) static void iforce_usb_stop_io(struct iforce *iforce) { - usb_kill_urb(iforce->irq); - usb_kill_urb(iforce->out); - usb_kill_urb(iforce->ctrl); + struct iforce_usb *iforce_usb = container_of(iforce, struct iforce_usb, + iforce); + + usb_kill_urb(iforce_usb->irq); + usb_kill_urb(iforce_usb->out); + usb_kill_urb(iforce_usb->ctrl); } static const struct iforce_xport_ops iforce_usb_xport_ops = { @@ -127,8 +147,9 @@ static const struct iforce_xport_ops iforce_usb_xport_ops = { static void iforce_usb_irq(struct urb *urb) { - struct iforce *iforce = urb->context; - struct device *dev = &iforce->intf->dev; + struct iforce_usb *iforce_usb = urb->context; + struct iforce *iforce = &iforce_usb->iforce; + struct device *dev = &iforce_usb->intf->dev; int status; switch (urb->status) { @@ -152,7 +173,7 @@ static void iforce_usb_irq(struct urb *urb) (iforce->data[0] << 8) | (urb->actual_length - 1), iforce->data + 1); exit: - status = usb_submit_urb (urb, GFP_ATOMIC); + status = usb_submit_urb(urb, GFP_ATOMIC); if (status) dev_err(dev, "%s - usb_submit_urb failed with result %d\n", __func__, status); @@ -160,11 +181,12 @@ static void iforce_usb_irq(struct urb *urb) static void iforce_usb_out(struct urb *urb) { - struct iforce *iforce = urb->context; + struct iforce_usb *iforce_usb = urb->context; + struct iforce *iforce = &iforce_usb->iforce; if (urb->status) { clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags); - dev_dbg(&iforce->intf->dev, "urb->status %d, exiting\n", + dev_dbg(&iforce_usb->intf->dev, "urb->status %d, exiting\n", urb->status); return; } @@ -176,8 +198,12 @@ static void iforce_usb_out(struct urb *urb) static void iforce_usb_ctrl(struct urb *urb) { - struct iforce *iforce = urb->context; - if (urb->status) return; + struct iforce_usb *iforce_usb = urb->context; + struct iforce *iforce = &iforce_usb->iforce; + + if (urb->status) + return; + iforce->ecmd = 0xff00 | urb->actual_length; wake_up(&iforce->wait); } @@ -188,6 +214,7 @@ static int iforce_usb_probe(struct usb_interface *intf, struct usb_device *dev = interface_to_usbdev(intf); struct usb_host_interface *interface; struct usb_endpoint_descriptor *epirq, *epout; + struct iforce_usb *iforce_usb; struct iforce *iforce; int err = -ENOMEM; @@ -199,49 +226,52 @@ static int iforce_usb_probe(struct usb_interface *intf, epirq = &interface->endpoint[0].desc; epout = &interface->endpoint[1].desc; - if (!(iforce = kzalloc(sizeof(struct iforce) + 32, GFP_KERNEL))) + if (!(iforce_usb = kzalloc(sizeof(*iforce_usb) + 32, GFP_KERNEL))) goto fail; - if (!(iforce->irq = usb_alloc_urb(0, GFP_KERNEL))) + if (!(iforce_usb->irq = usb_alloc_urb(0, GFP_KERNEL))) goto fail; - if (!(iforce->out = usb_alloc_urb(0, GFP_KERNEL))) + if (!(iforce_usb->out = usb_alloc_urb(0, GFP_KERNEL))) goto fail; - if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL))) + if (!(iforce_usb->ctrl = usb_alloc_urb(0, GFP_KERNEL))) goto fail; + iforce = &iforce_usb->iforce; + iforce->xport_ops = &iforce_usb_xport_ops; iforce->bus = IFORCE_USB; - iforce->usbdev = dev; - iforce->intf = intf; - iforce->cr.bRequestType = USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_INTERFACE; - iforce->cr.wIndex = 0; - iforce->cr.wLength = cpu_to_le16(16); + iforce_usb->usbdev = dev; + iforce_usb->intf = intf; + + iforce_usb->cr.bRequestType = USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_INTERFACE; + iforce_usb->cr.wIndex = 0; + iforce_usb->cr.wLength = cpu_to_le16(16); - usb_fill_int_urb(iforce->irq, dev, usb_rcvintpipe(dev, epirq->bEndpointAddress), - iforce->data, 16, iforce_usb_irq, iforce, epirq->bInterval); + usb_fill_int_urb(iforce_usb->irq, dev, usb_rcvintpipe(dev, epirq->bEndpointAddress), + iforce->data, 16, iforce_usb_irq, iforce_usb, epirq->bInterval); - usb_fill_int_urb(iforce->out, dev, usb_sndintpipe(dev, epout->bEndpointAddress), - iforce + 1, 32, iforce_usb_out, iforce, epout->bInterval); + usb_fill_int_urb(iforce_usb->out, dev, usb_sndintpipe(dev, epout->bEndpointAddress), + iforce_usb + 1, 32, iforce_usb_out, iforce_usb, epout->bInterval); - usb_fill_control_urb(iforce->ctrl, dev, usb_rcvctrlpipe(dev, 0), - (void*) &iforce->cr, iforce->edata, 16, iforce_usb_ctrl, iforce); + usb_fill_control_urb(iforce_usb->ctrl, dev, usb_rcvctrlpipe(dev, 0), + (void*) &iforce_usb->cr, iforce->edata, 16, iforce_usb_ctrl, iforce_usb); err = iforce_init_device(&intf->dev, BUS_USB, iforce); if (err) goto fail; - usb_set_intfdata(intf, iforce); + usb_set_intfdata(intf, iforce_usb); return 0; fail: - if (iforce) { - usb_free_urb(iforce->irq); - usb_free_urb(iforce->out); - usb_free_urb(iforce->ctrl); - kfree(iforce); + if (iforce_usb) { + usb_free_urb(iforce_usb->irq); + usb_free_urb(iforce_usb->out); + usb_free_urb(iforce_usb->ctrl); + kfree(iforce_usb); } return err; @@ -249,17 +279,17 @@ static int iforce_usb_probe(struct usb_interface *intf, static void iforce_usb_disconnect(struct usb_interface *intf) { - struct iforce *iforce = usb_get_intfdata(intf); + struct iforce_usb *iforce_usb = usb_get_intfdata(intf); usb_set_intfdata(intf, NULL); - input_unregister_device(iforce->dev); + input_unregister_device(iforce_usb->iforce.dev); - usb_free_urb(iforce->irq); - usb_free_urb(iforce->out); - usb_free_urb(iforce->ctrl); + usb_free_urb(iforce_usb->irq); + usb_free_urb(iforce_usb->out); + usb_free_urb(iforce_usb->ctrl); - kfree(iforce); + kfree(iforce_usb); } static const struct usb_device_id iforce_usb_ids[] = { diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h index 3ee9245a415b..d9712c48ba74 100644 --- a/drivers/input/joystick/iforce/iforce.h +++ b/drivers/input/joystick/iforce/iforce.h @@ -111,19 +111,7 @@ struct iforce { unsigned char data[IFORCE_MAX_LENGTH]; unsigned char edata[IFORCE_MAX_LENGTH]; u16 ecmd; - u16 expect_packet; - -#ifdef CONFIG_JOYSTICK_IFORCE_232 - struct serio *serio; /* RS232 transfer */ - int idx, pkt, len, id; - unsigned char csum; -#endif -#ifdef CONFIG_JOYSTICK_IFORCE_USB - struct usb_device *usbdev; /* USB transfer */ - struct usb_interface *intf; - struct urb *irq, *out, *ctrl; - struct usb_ctrlrequest cr; -#endif + spinlock_t xmit_lock; /* Buffer used for asynchronous sending of bytes to the device */ struct circ_buf xmit; From patchwork Tue Sep 18 00:47:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603613 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 6AC9A157B for ; Tue, 18 Sep 2018 00:49:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AD582A9D5 for ; Tue, 18 Sep 2018 00:49:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EF3E2A9E7; Tue, 18 Sep 2018 00:49:05 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 9F9A02A9D5 for ; Tue, 18 Sep 2018 00:49:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729305AbeIRGRm (ORCPT ); Tue, 18 Sep 2018 02:17:42 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:41741 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729265AbeIRGRl (ORCPT ); Tue, 18 Sep 2018 02:17:41 -0400 Received: by mail-pg1-f193.google.com with SMTP id s15-v6so105545pgv.8; Mon, 17 Sep 2018 17:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uIsx+Lj2AOsNYnRJicwzzI3pQXrI3+GkDscgg4SjDng=; b=aJetEppu+LdT1fXncUO/hHryhQRy5cQ4bDPDl79s1EIO4b4MahV0XKDqBTt3vkdTpO m6wz6g0JSYDnlB1oua0H09pqMfHqCkDKGtTY9cW8t4BXtQnm5J6z7tiOxEKNs48mJIeZ Nfa6gJxD5TzmL7YTjzXEOc8x2JcIq1ggAtTUinM9Hc7l42qoi+yE6ieUWdyRUBnr3zUs CjSVdhKWGF++51eRTSpCriuvGCYKcs8YfaKjQpV+7Fz34UwtPLSM0NXeHzt7iEbOv6Br 5PKy1HnYSIAhYFWFybl7VFLxiSR3+QWk6vGKGZbu3HtQrL14fCTaH1BSrJzCXY7C16EF 4gqg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=uIsx+Lj2AOsNYnRJicwzzI3pQXrI3+GkDscgg4SjDng=; b=sIIOhOIDViUMiP5SNIzpLKjkeOsw5/jCgdSoKHtRh01ShO/V3MfgOMAlvqkX/8+wbX 2vjmyH3dfiDasbpAR8zFVtHzWJ3YtWkpLHQKMiAaFE2o1bdWxFfWEUWfHjmi02Yc/uA6 33aBY1IL3p/Z/OO3NxCmuCovieek5QZC8WKyex1QF735CO1PYL41DSYMpQISChxGTWuW 5XdQsC4yWtC3Jb4TnZZlv8LfnalsjI0Of4XNeFB+S3HBMJKQz2T4HYVCX+c2lFkyCvhq wXF1iynDdq+eJLXUbmTfo8t2ivX4MfdDmNozHqZdxRN29CO7szWzN4KEWYKwG8T2S8GV F9Nw== X-Gm-Message-State: APzg51BQMj3ZskYP9DEBoJpwK65FIJToxQTjHqmsxmpaSEG3f4GivD3f B2cIEIQbp56pETWiV2zRY70rqUp+ X-Google-Smtp-Source: ANB0Vdb9tywBVFUaGcvh+CNF+GMjKhNTUJ4XxvCx4GxxhlgWQOyNigRfkFBU0/3uMsIwY4ZLWBn12g== X-Received: by 2002:a62:6104:: with SMTP id v4-v6mr28497263pfb.122.1537231667408; Mon, 17 Sep 2018 17:47:47 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:46 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 08/20] Input: iforce - split into core and transport modules Date: Mon, 17 Sep 2018 17:47:20 -0700 Message-Id: <20180918004732.9875-8-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 Now that we have moved enough transport details into separate source files we can change them into transport modules so that they are only loaded when needed. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/Kconfig | 8 ++--- drivers/input/joystick/iforce/Makefile | 7 ++-- drivers/input/joystick/iforce/iforce-main.c | 35 ++----------------- .../input/joystick/iforce/iforce-packets.c | 2 ++ drivers/input/joystick/iforce/iforce-serio.c | 7 ++++ drivers/input/joystick/iforce/iforce-usb.c | 7 ++++ drivers/input/joystick/iforce/iforce.h | 2 -- 7 files changed, 25 insertions(+), 43 deletions(-) diff --git a/drivers/input/joystick/iforce/Kconfig b/drivers/input/joystick/iforce/Kconfig index ab4dbcbcbf50..55f6ae1da6b0 100644 --- a/drivers/input/joystick/iforce/Kconfig +++ b/drivers/input/joystick/iforce/Kconfig @@ -13,15 +13,15 @@ config JOYSTICK_IFORCE module will be called iforce. config JOYSTICK_IFORCE_USB - bool "I-Force USB joysticks and wheels" - depends on JOYSTICK_IFORCE && (JOYSTICK_IFORCE=m || USB=y) && USB + tristate "I-Force USB joysticks and wheels" + depends on JOYSTICK_IFORCE && USB help Say Y here if you have an I-Force joystick or steering wheel connected to your USB port. config JOYSTICK_IFORCE_232 - bool "I-Force Serial joysticks and wheels" - depends on JOYSTICK_IFORCE && (JOYSTICK_IFORCE=m || SERIO=y) && SERIO + tristate "I-Force Serial joysticks and wheels" + depends on JOYSTICK_IFORCE && SERIO help Say Y here if you have an I-Force joystick or steering wheel connected to your serial (COM) port. diff --git a/drivers/input/joystick/iforce/Makefile b/drivers/input/joystick/iforce/Makefile index bc5bda22f15e..414075019a4f 100644 --- a/drivers/input/joystick/iforce/Makefile +++ b/drivers/input/joystick/iforce/Makefile @@ -4,8 +4,7 @@ # By Johann Deneux # -obj-$(CONFIG_JOYSTICK_IFORCE) += iforce.o - +obj-$(CONFIG_JOYSTICK_IFORCE) += iforce.o iforce-y := iforce-ff.o iforce-main.o iforce-packets.o -iforce-$(CONFIG_JOYSTICK_IFORCE_232) += iforce-serio.o -iforce-$(CONFIG_JOYSTICK_IFORCE_USB) += iforce-usb.o +obj-$(CONFIG_JOYSTICK_IFORCE_232) += iforce-serio.o +obj-$(CONFIG_JOYSTICK_IFORCE_USB) += iforce-usb.o diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c index 894769d03df3..3a0698327c42 100644 --- a/drivers/input/joystick/iforce/iforce-main.c +++ b/drivers/input/joystick/iforce/iforce-main.c @@ -24,7 +24,7 @@ #include "iforce.h" MODULE_AUTHOR("Vojtech Pavlik , Johann Deneux "); -MODULE_DESCRIPTION("USB/RS232 I-Force joysticks and wheels driver"); +MODULE_DESCRIPTION("Core I-Force joysticks and wheels driver"); MODULE_LICENSE("GPL"); static signed short btn_joystick[] = @@ -411,35 +411,4 @@ int iforce_init_device(struct device *parent, u16 bustype, fail: input_free_device(input_dev); return error; } - -static int __init iforce_init(void) -{ - int err = 0; - -#ifdef CONFIG_JOYSTICK_IFORCE_USB - err = usb_register(&iforce_usb_driver); - if (err) - return err; -#endif -#ifdef CONFIG_JOYSTICK_IFORCE_232 - err = serio_register_driver(&iforce_serio_drv); -#ifdef CONFIG_JOYSTICK_IFORCE_USB - if (err) - usb_deregister(&iforce_usb_driver); -#endif -#endif - return err; -} - -static void __exit iforce_exit(void) -{ -#ifdef CONFIG_JOYSTICK_IFORCE_USB - usb_deregister(&iforce_usb_driver); -#endif -#ifdef CONFIG_JOYSTICK_IFORCE_232 - serio_unregister_driver(&iforce_serio_drv); -#endif -} - -module_init(iforce_init); -module_exit(iforce_exit); +EXPORT_SYMBOL(iforce_init_device); diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c index 8a9a152bb595..70db273e5045 100644 --- a/drivers/input/joystick/iforce/iforce-packets.c +++ b/drivers/input/joystick/iforce/iforce-packets.c @@ -96,6 +96,7 @@ int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data) return 0; } +EXPORT_SYMBOL(iforce_send_packet); /* Start or stop an effect */ int iforce_control_playback(struct iforce* iforce, u16 id, unsigned int value) @@ -203,3 +204,4 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) break; } } +EXPORT_SYMBOL(iforce_process_packet); diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index 6ff1bbeeb494..6c6411fbdc32 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -21,6 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include "iforce.h" struct iforce_serio { @@ -250,3 +251,9 @@ struct serio_driver iforce_serio_drv = { .connect = iforce_serio_connect, .disconnect = iforce_serio_disconnect, }; + +module_serio_driver(iforce_serio_drv); + +MODULE_AUTHOR("Vojtech Pavlik , Johann Deneux "); +MODULE_DESCRIPTION("RS232 I-Force joysticks and wheels driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index d4e7a24922cd..9d635f01cf19 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c @@ -21,6 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include "iforce.h" struct iforce_usb { @@ -316,3 +317,9 @@ struct usb_driver iforce_usb_driver = { .disconnect = iforce_usb_disconnect, .id_table = iforce_usb_ids, }; + +module_usb_driver(iforce_usb_driver); + +MODULE_AUTHOR("Vojtech Pavlik , Johann Deneux "); +MODULE_DESCRIPTION("USB I-Force joysticks and wheels driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h index d9712c48ba74..3e3df83b9d77 100644 --- a/drivers/input/joystick/iforce/iforce.h +++ b/drivers/input/joystick/iforce/iforce.h @@ -26,8 +26,6 @@ #include #include #include -#include -#include #include #include From patchwork Tue Sep 18 00:47:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603611 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 B380915E8 for ; Tue, 18 Sep 2018 00:49:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A45082A9D5 for ; Tue, 18 Sep 2018 00:49:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98E082A9E7; Tue, 18 Sep 2018 00:49:00 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 1FD492A9D5 for ; Tue, 18 Sep 2018 00:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729346AbeIRGRo (ORCPT ); Tue, 18 Sep 2018 02:17:44 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44622 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729317AbeIRGRo (ORCPT ); Tue, 18 Sep 2018 02:17:44 -0400 Received: by mail-pf1-f195.google.com with SMTP id k21-v6so98678pff.11; Mon, 17 Sep 2018 17:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h9fPmGeH09lvYWzOnYyXVlgxV08wm82k6fO9Keh58/Q=; b=W4KDFBzOokSQSjaoYFgqShO0Kntru5hAsbiQ2B1OcSqlGZ9h1y1PZMzqXhjoWx09VH 6d0w/crTslpL6mX/ER5TxAQLIWDyPdEXK7gezyfUWPhNKJlH4zMnHyA61T0mujWfcJ8q YYWXGRzkTdGyBBM4cUpzpqwTgLIAxSoBzE3NM+HgLxguY+JnbE8RYS8k3jiOkdcbxn6y 2ZL9XWhpXBUGU5Thbntt/lNVH5VTrsgua0ayKtc9iXVck1XdLqVvOlJbKZTeun+M3Gm2 97MPQeBqiGbovF9Lu3xBAnzIxu4mp893cOHoQ2HL6ugoXFziW6NoXkjodW/HFYel+tuC 69Yg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=h9fPmGeH09lvYWzOnYyXVlgxV08wm82k6fO9Keh58/Q=; b=AMMIx7nLMsdcyGFiuxw+poGRBgx8F95+eMFUX24iIQzCZaKg6hY1qBZ+riUlverNrt Sus4rLyRGPsv0vrIMdb5HPFQhdcFqapqNMt2tlxb7ywbeR9m13Glx2KRztRSU2O2Dl1g 4ozQx3wGPBGw/ac264mRylVMuy2ri5i8P6YCrrj3NgskteQSZQkIuP1jUcQi5OLvKvYB fiukEBfWq3fOiDX2Jv7Y+6aZgIEAnJ0PA/6fQ++5mXmChOTxjILhbN3L0jUS6t3qjyOf Q0NwlaQw4D3XVJrwHaDPJ9KPYH/jDVwZ0mIJ3PoiKxPYBpU+Yw3iocholGPzJErqjcDP wAtw== X-Gm-Message-State: APzg51BkaLd51kMIctnvc/B3qbOinCtOX/T9FRoVHEsnjEAIYMSf2mj0 sPB/Nl3Zm11A938WoeGequYO/fz/ X-Google-Smtp-Source: ANB0Vdb+Ij37vctV+QHpsCgNHPfh/VEDa2QYFWNpyRezqXYbA/s1VeXBip2PSQDLMIzjYkmGuV/J/g== X-Received: by 2002:a63:350f:: with SMTP id c15-v6mr10942237pga.206.1537231668796; Mon, 17 Sep 2018 17:47:48 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:47 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 09/20] Input: iforce - use DMA-safe buffer when getting IDs from USB Date: Mon, 17 Sep 2018 17:47:21 -0700 Message-Id: <20180918004732.9875-9-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 When working with USB devices we need to use DMA-safe buffers, and iforce->edata is not one. Let's rework the code to allocate temporary buffer (iforce_get_id() is called only during initialization so there is no reason to have permanent buffer) and use it. While at it, let's utilize usb_control_msg() API which simplifies code. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-usb.c | 68 +++++++--------------- 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index 9d635f01cf19..cefaa1c5abc7 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c @@ -29,8 +29,7 @@ struct iforce_usb { struct usb_device *usbdev; struct usb_interface *intf; - struct urb *irq, *out, *ctrl; - struct usb_ctrlrequest cr; + struct urb *irq, *out; }; static void __iforce_usb_xmit(struct iforce *iforce) @@ -92,30 +91,32 @@ static int iforce_usb_get_id(struct iforce *iforce, u8 *packet) { struct iforce_usb *iforce_usb = container_of(iforce, struct iforce_usb, iforce); + u8 *buf; int status; - iforce_usb->cr.bRequest = packet[0]; - iforce_usb->ctrl->dev = iforce_usb->usbdev; - - status = usb_submit_urb(iforce_usb->ctrl, GFP_KERNEL); - if (status) { + buf = kmalloc(IFORCE_MAX_LENGTH, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + status = usb_control_msg(iforce_usb->usbdev, + usb_rcvctrlpipe(iforce_usb->usbdev, 0), + packet[0], + USB_TYPE_VENDOR | USB_DIR_IN | + USB_RECIP_INTERFACE, + 0, 0, buf, IFORCE_MAX_LENGTH, HZ); + if (status < 0) { dev_err(&iforce_usb->intf->dev, - "usb_submit_urb failed %d\n", status); - return -EIO; - } - - wait_event_interruptible_timeout(iforce->wait, - iforce_usb->ctrl->status != -EINPROGRESS, HZ); - - if (iforce_usb->ctrl->status) { - dev_dbg(&iforce_usb->intf->dev, - "iforce->ctrl->status = %d\n", - iforce_usb->ctrl->status); - usb_unlink_urb(iforce_usb->ctrl); - return -EIO; + "usb_submit_urb failed: %d\n", status); + } else if (buf[0] != packet[0]) { + status = -EIO; + } else { + iforce->ecmd = 0xff00 | status; + memcpy(iforce->edata, buf, status); + status = 0; } - return -(iforce->edata[0] != packet[0]); + kfree(buf); + return status; } static int iforce_usb_start_io(struct iforce *iforce) @@ -136,7 +137,6 @@ static void iforce_usb_stop_io(struct iforce *iforce) usb_kill_urb(iforce_usb->irq); usb_kill_urb(iforce_usb->out); - usb_kill_urb(iforce_usb->ctrl); } static const struct iforce_xport_ops iforce_usb_xport_ops = { @@ -197,18 +197,6 @@ static void iforce_usb_out(struct urb *urb) wake_up(&iforce->wait); } -static void iforce_usb_ctrl(struct urb *urb) -{ - struct iforce_usb *iforce_usb = urb->context; - struct iforce *iforce = &iforce_usb->iforce; - - if (urb->status) - return; - - iforce->ecmd = 0xff00 | urb->actual_length; - wake_up(&iforce->wait); -} - static int iforce_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) { @@ -236,9 +224,6 @@ static int iforce_usb_probe(struct usb_interface *intf, if (!(iforce_usb->out = usb_alloc_urb(0, GFP_KERNEL))) goto fail; - if (!(iforce_usb->ctrl = usb_alloc_urb(0, GFP_KERNEL))) - goto fail; - iforce = &iforce_usb->iforce; iforce->xport_ops = &iforce_usb_xport_ops; @@ -247,19 +232,12 @@ static int iforce_usb_probe(struct usb_interface *intf, iforce_usb->usbdev = dev; iforce_usb->intf = intf; - iforce_usb->cr.bRequestType = USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_INTERFACE; - iforce_usb->cr.wIndex = 0; - iforce_usb->cr.wLength = cpu_to_le16(16); - usb_fill_int_urb(iforce_usb->irq, dev, usb_rcvintpipe(dev, epirq->bEndpointAddress), iforce->data, 16, iforce_usb_irq, iforce_usb, epirq->bInterval); usb_fill_int_urb(iforce_usb->out, dev, usb_sndintpipe(dev, epout->bEndpointAddress), iforce_usb + 1, 32, iforce_usb_out, iforce_usb, epout->bInterval); - usb_fill_control_urb(iforce_usb->ctrl, dev, usb_rcvctrlpipe(dev, 0), - (void*) &iforce_usb->cr, iforce->edata, 16, iforce_usb_ctrl, iforce_usb); - err = iforce_init_device(&intf->dev, BUS_USB, iforce); if (err) goto fail; @@ -271,7 +249,6 @@ static int iforce_usb_probe(struct usb_interface *intf, if (iforce_usb) { usb_free_urb(iforce_usb->irq); usb_free_urb(iforce_usb->out); - usb_free_urb(iforce_usb->ctrl); kfree(iforce_usb); } @@ -288,7 +265,6 @@ static void iforce_usb_disconnect(struct usb_interface *intf) usb_free_urb(iforce_usb->irq); usb_free_urb(iforce_usb->out); - usb_free_urb(iforce_usb->ctrl); kfree(iforce_usb); } From patchwork Tue Sep 18 00:47:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603609 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 B7E3815E8 for ; Tue, 18 Sep 2018 00:48:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6C472A9B7 for ; Tue, 18 Sep 2018 00:48:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AD522A9D5; Tue, 18 Sep 2018 00:48:57 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 E83252A9B7 for ; Tue, 18 Sep 2018 00:48:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729317AbeIRGRp (ORCPT ); Tue, 18 Sep 2018 02:17:45 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:33308 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729344AbeIRGRo (ORCPT ); Tue, 18 Sep 2018 02:17:44 -0400 Received: by mail-pf1-f194.google.com with SMTP id d4-v6so121541pfn.0; Mon, 17 Sep 2018 17:47:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q6MQQBXg5BnNlq8nEfytR1l6OiNQOXKjftVMweLbkvc=; b=Q46d73yBGTh78wTOuVGKyhfR94gX/gcwpSRfDfvKmaS0qreYgTgdDlArsiszaNZ0bE 3cJBiwrtoWtR1ZR/5b0ub2CZ/GrQ5+RbbKq2yVXW7zpeBFqoK5Zd5g7Vg6NnOtxyMYFv sDtZk/WC6ds114c3nIgnxPWOb5mZgk5EmZ4/M2YAWpCUmYGBzMpyg9xpRLcwqm/n7jVQ Qmaf0fAv2CJsVPIOrBfU51fRL1l52+71NMLYMjMqzshnBNISSoA8RBx7rHteRDt0ieie CqMOJGdZpQBCa3Bk2vvKpeWn9/x8yBk/k3GWxb2wfYPGgIbypXpRza2ebzvAeW6vSIxj ubkQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q6MQQBXg5BnNlq8nEfytR1l6OiNQOXKjftVMweLbkvc=; b=bCAuZuPPHVg4djUJKrBtOxGhdWH1LZKlJDrUuF+t+/kQfwxOHzy2DxoMz2aNPp/CCV fnN7mapd90/DgMHHPuCeFzWsXVOvI7DN+pR5ocbW2WbNHWssS/WpXy1WZqI84A+TYtnO Qm7Lp1k1sgIZKBePXGQ+7idKLEKwhiU4w3ust0jEj42oKQfdJFwDwWCXlavbLuwEz0iH RsGPKheHWSz+Vvjx86yxvBBIlPok8Xzqn9E46sz84KAYo4+gE7EHVRBJLOWaGhrd+q+6 84Np8RkyFM0RoAtKU7EiG4h+s9Wg4PnXaOHmuv9qrujC8DhoYzt1qOEzlRbh4/02icIv tvFQ== X-Gm-Message-State: APzg51Cv+d6hz2a3vRekUfz3SvLEa4DFmY5NR9X2SVyvxvjAXOttwjKH rLiHcC9tBfr9Xrq+zf/PbJhihvsw X-Google-Smtp-Source: ANB0VdZk2Y12NF7FM/VAX2wnHmvki/0cfmr/wd4RmKbnbEYC30Y4wOHSNDHanHn2Vj3UtxHps9SA5A== X-Received: by 2002:a63:df04:: with SMTP id u4-v6mr26033110pgg.434.1537231670246; Mon, 17 Sep 2018 17:47:50 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:49 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 10/20] Input: iforce - update formatting of switch statements Date: Mon, 17 Sep 2018 17:47:22 -0700 Message-Id: <20180918004732.9875-10-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 According to our coding style case labels in switch statements should be aligned with the switch keyword. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-ff.c | 18 +-- drivers/input/joystick/iforce/iforce-main.c | 70 +++++------ .../input/joystick/iforce/iforce-packets.c | 112 +++++++++--------- 3 files changed, 100 insertions(+), 100 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-ff.c b/drivers/input/joystick/iforce/iforce-ff.c index 3536d5f5ad18..56973dd97fd6 100644 --- a/drivers/input/joystick/iforce/iforce-ff.c +++ b/drivers/input/joystick/iforce/iforce-ff.c @@ -384,12 +384,12 @@ int iforce_upload_periodic(struct iforce *iforce, struct ff_effect *effect, stru } switch (effect->u.periodic.waveform) { - case FF_SQUARE: wave_code = 0x20; break; - case FF_TRIANGLE: wave_code = 0x21; break; - case FF_SINE: wave_code = 0x22; break; - case FF_SAW_UP: wave_code = 0x23; break; - case FF_SAW_DOWN: wave_code = 0x24; break; - default: wave_code = 0x20; break; + case FF_SQUARE: wave_code = 0x20; break; + case FF_TRIANGLE: wave_code = 0x21; break; + case FF_SINE: wave_code = 0x22; break; + case FF_SAW_UP: wave_code = 0x23; break; + case FF_SAW_DOWN: wave_code = 0x24; break; + default: wave_code = 0x20; break; } if (!old || need_core(old, effect)) { @@ -488,9 +488,9 @@ int iforce_upload_condition(struct iforce *iforce, struct ff_effect *effect, str int core_err = 0; switch (effect->type) { - case FF_SPRING: type = 0x40; break; - case FF_DAMPER: type = 0x41; break; - default: return -1; + case FF_SPRING: type = 0x40; break; + case FF_DAMPER: type = 0x41; break; + default: return -1; } if (!old || need_condition_modifier(iforce, old, effect)) { diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c index 3a0698327c42..9964aa8b3cdc 100644 --- a/drivers/input/joystick/iforce/iforce-main.c +++ b/drivers/input/joystick/iforce/iforce-main.c @@ -132,22 +132,21 @@ static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect, * Upload the effect */ switch (effect->type) { + case FF_PERIODIC: + ret = iforce_upload_periodic(iforce, effect, old); + break; - case FF_PERIODIC: - ret = iforce_upload_periodic(iforce, effect, old); - break; + case FF_CONSTANT: + ret = iforce_upload_constant(iforce, effect, old); + break; - case FF_CONSTANT: - ret = iforce_upload_constant(iforce, effect, old); - break; + case FF_SPRING: + case FF_DAMPER: + ret = iforce_upload_condition(iforce, effect, old); + break; - case FF_SPRING: - case FF_DAMPER: - ret = iforce_upload_condition(iforce, effect, old); - break; - - default: - return -EINVAL; + default: + return -EINVAL; } if (ret == 0) { @@ -351,34 +350,29 @@ int iforce_init_device(struct device *parent, u16 bustype, signed short t = iforce->type->abs[i]; switch (t) { + case ABS_X: + case ABS_Y: + case ABS_WHEEL: + input_set_abs_params(input_dev, t, -1920, 1920, 16, 128); + set_bit(t, input_dev->ffbit); + break; - case ABS_X: - case ABS_Y: - case ABS_WHEEL: - - input_set_abs_params(input_dev, t, -1920, 1920, 16, 128); - set_bit(t, input_dev->ffbit); - break; - - case ABS_THROTTLE: - case ABS_GAS: - case ABS_BRAKE: - - input_set_abs_params(input_dev, t, 0, 255, 0, 0); - break; - - case ABS_RUDDER: - - input_set_abs_params(input_dev, t, -128, 127, 0, 0); - break; + case ABS_THROTTLE: + case ABS_GAS: + case ABS_BRAKE: + input_set_abs_params(input_dev, t, 0, 255, 0, 0); + break; - case ABS_HAT0X: - case ABS_HAT0Y: - case ABS_HAT1X: - case ABS_HAT1Y: + case ABS_RUDDER: + input_set_abs_params(input_dev, t, -128, 127, 0, 0); + break; - input_set_abs_params(input_dev, t, -1, 1, 0, 0); - break; + case ABS_HAT0X: + case ABS_HAT0Y: + case ABS_HAT1X: + case ABS_HAT1Y: + input_set_abs_params(input_dev, t, -1, 1, 0, 0); + break; } } diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c index 70db273e5045..7aba2966454a 100644 --- a/drivers/input/joystick/iforce/iforce-packets.c +++ b/drivers/input/joystick/iforce/iforce-packets.c @@ -142,66 +142,72 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) switch (HI(cmd)) { - case 0x01: /* joystick position data */ - case 0x03: /* wheel position data */ - if (HI(cmd) == 1) { - input_report_abs(dev, ABS_X, (__s16) (((__s16)data[1] << 8) | data[0])); - input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[3] << 8) | data[2])); - input_report_abs(dev, ABS_THROTTLE, 255 - data[4]); - if (LO(cmd) >= 8 && test_bit(ABS_RUDDER ,dev->absbit)) - input_report_abs(dev, ABS_RUDDER, (__s8)data[7]); - } else { - input_report_abs(dev, ABS_WHEEL, (__s16) (((__s16)data[1] << 8) | data[0])); - input_report_abs(dev, ABS_GAS, 255 - data[2]); - input_report_abs(dev, ABS_BRAKE, 255 - data[3]); - } + case 0x01: /* joystick position data */ + case 0x03: /* wheel position data */ + if (HI(cmd) == 1) { + input_report_abs(dev, ABS_X, (__s16) (((__s16)data[1] << 8) | data[0])); + input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[3] << 8) | data[2])); + input_report_abs(dev, ABS_THROTTLE, 255 - data[4]); + if (LO(cmd) >= 8 && test_bit(ABS_RUDDER ,dev->absbit)) + input_report_abs(dev, ABS_RUDDER, (__s8)data[7]); + } else { + input_report_abs(dev, ABS_WHEEL, (__s16) (((__s16)data[1] << 8) | data[0])); + input_report_abs(dev, ABS_GAS, 255 - data[2]); + input_report_abs(dev, ABS_BRAKE, 255 - data[3]); + } - input_report_abs(dev, ABS_HAT0X, iforce_hat_to_axis[data[6] >> 4].x); - input_report_abs(dev, ABS_HAT0Y, iforce_hat_to_axis[data[6] >> 4].y); - - for (i = 0; iforce->type->btn[i] >= 0; i++) - input_report_key(dev, iforce->type->btn[i], data[(i >> 3) + 5] & (1 << (i & 7))); - - /* If there are untouched bits left, interpret them as the second hat */ - if (i <= 8) { - int btns = data[6]; - if (test_bit(ABS_HAT1X, dev->absbit)) { - if (btns & 8) input_report_abs(dev, ABS_HAT1X, -1); - else if (btns & 2) input_report_abs(dev, ABS_HAT1X, 1); - else input_report_abs(dev, ABS_HAT1X, 0); - } - if (test_bit(ABS_HAT1Y, dev->absbit)) { - if (btns & 1) input_report_abs(dev, ABS_HAT1Y, -1); - else if (btns & 4) input_report_abs(dev, ABS_HAT1Y, 1); - else input_report_abs(dev, ABS_HAT1Y, 0); - } + input_report_abs(dev, ABS_HAT0X, iforce_hat_to_axis[data[6] >> 4].x); + input_report_abs(dev, ABS_HAT0Y, iforce_hat_to_axis[data[6] >> 4].y); + + for (i = 0; iforce->type->btn[i] >= 0; i++) + input_report_key(dev, iforce->type->btn[i], data[(i >> 3) + 5] & (1 << (i & 7))); + + /* If there are untouched bits left, interpret them as the second hat */ + if (i <= 8) { + int btns = data[6]; + if (test_bit(ABS_HAT1X, dev->absbit)) { + if (btns & 8) + input_report_abs(dev, ABS_HAT1X, -1); + else if (btns & 2) + input_report_abs(dev, ABS_HAT1X, 1); + else + input_report_abs(dev, ABS_HAT1X, 0); } + if (test_bit(ABS_HAT1Y, dev->absbit)) { + if (btns & 1) + input_report_abs(dev, ABS_HAT1Y, -1); + else if (btns & 4) + input_report_abs(dev, ABS_HAT1Y, 1); + else + input_report_abs(dev, ABS_HAT1Y, 0); + } + } - input_sync(dev); + input_sync(dev); - break; + break; - case 0x02: /* status report */ - input_report_key(dev, BTN_DEAD, data[0] & 0x02); - input_sync(dev); + case 0x02: /* status report */ + input_report_key(dev, BTN_DEAD, data[0] & 0x02); + input_sync(dev); - /* Check if an effect was just started or stopped */ - i = data[1] & 0x7f; - if (data[1] & 0x80) { - if (!test_and_set_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) { - /* Report play event */ - input_report_ff_status(dev, i, FF_STATUS_PLAYING); - } - } else if (test_and_clear_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) { - /* Report stop event */ - input_report_ff_status(dev, i, FF_STATUS_STOPPED); + /* Check if an effect was just started or stopped */ + i = data[1] & 0x7f; + if (data[1] & 0x80) { + if (!test_and_set_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) { + /* Report play event */ + input_report_ff_status(dev, i, FF_STATUS_PLAYING); } - if (LO(cmd) > 3) { - int j; - for (j = 3; j < LO(cmd); j += 2) - mark_core_as_ready(iforce, data[j] | (data[j+1]<<8)); - } - break; + } else if (test_and_clear_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) { + /* Report stop event */ + input_report_ff_status(dev, i, FF_STATUS_STOPPED); + } + if (LO(cmd) > 3) { + int j; + for (j = 3; j < LO(cmd); j += 2) + mark_core_as_ready(iforce, data[j] | (data[j+1]<<8)); + } + break; } } EXPORT_SYMBOL(iforce_process_packet); From patchwork Tue Sep 18 00:47:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603607 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 0790A157B for ; Tue, 18 Sep 2018 00:48:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB5C62A9B7 for ; Tue, 18 Sep 2018 00:48:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF77D2A9D5; Tue, 18 Sep 2018 00:48:52 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 6668A2A9B7 for ; Tue, 18 Sep 2018 00:48:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728818AbeIRGRq (ORCPT ); Tue, 18 Sep 2018 02:17:46 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:41992 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729344AbeIRGRq (ORCPT ); Tue, 18 Sep 2018 02:17:46 -0400 Received: by mail-pg1-f196.google.com with SMTP id y4-v6so103499pgp.9; Mon, 17 Sep 2018 17:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0w+EbiE4L+ll0rh87wVXQ0LffiC/T5ki4PVoOHplc8U=; b=NfqnQWhfFhmM+QPrJQhqJMwlaTM+DwEBI8/OyQlUbNbV5GgT7O36hWW+j5Ve4cscz+ NC3EqHwhbwYpDbuq+kkJUfH7q/1vZJY7y0th82HNM6mV1JsZabsprvbV6R7K56u7/OkD HRP5+4nKijb8VNauNLA/cx4RbAJ3YGsIQVooF0Odns0Sk/gch5q2HvomXYLIlhWSqc5x hOrxsgqaYUi3fY98itDISZvwPKPb2W5leBPl1UkQ+srMhX47xIB+Dzf84fd5xTOmL6tB E8sF5dshYvmRgH9fK0BGnVXQm/NgMo9YR4kB9At5UdT1Wf+FuOoCfPl+O7l5IhUAqWPH ScBg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=0w+EbiE4L+ll0rh87wVXQ0LffiC/T5ki4PVoOHplc8U=; b=mlw8BDIfd5l+UFFRX0TU7/Q3AEhXs98ICtxTsWuqzpMyGAnV7Gi1EKStwS1qkOm1G4 mUF6JR59zH77sk6FKAqK7Ozo0g5zldLIoApt5XCSPvxoPU1/dMwwC9p8kMDRAdwvy3fg EoxzHSSmEelc1TcF3ruw2qUuYfchYSdeEAADxFO8Z74XG9x6xJAlLWzbVN2Gr9DoYRof B8y2gq/o69v9isesOMW3Uw1SaqYsgwsesnWp8U6BSXGsdcngnVehgUGFW6646A+jcYFQ ak4W5XV06yPjzO2V1KvDnhhfThxhX4BXLNwcvvGcvcm4BdM8IBGXwLe9AJcNH8n/0ZO4 a8vA== X-Gm-Message-State: APzg51BpovqHY/ttgWnaC3EUdC6YQYrH6LucBB/BMcd/cVV7GVXuMmG4 /OuRMA6pJCxl5rFtkj6CRDpeshuX X-Google-Smtp-Source: ANB0Vdbc44lKUcxxo46h98t6Jq87N8DkZf8f3dL1OIxBmeUbdvjIqRi3rYPFd1MUnD7EJYlhAPQYzg== X-Received: by 2002:a62:642:: with SMTP id 63-v6mr28386809pfg.42.1537231671646; Mon, 17 Sep 2018 17:47:51 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:50 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 11/20] Input: iforce - factor out hat handling when parsing packets Date: Mon, 17 Sep 2018 17:47:23 -0700 Message-Id: <20180918004732.9875-11-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 This makes code clearer a bit. Signed-off-by: Dmitry Torokhov --- .../input/joystick/iforce/iforce-packets.c | 101 ++++++++++-------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c index 7aba2966454a..ffd1dd65deb8 100644 --- a/drivers/input/joystick/iforce/iforce-packets.c +++ b/drivers/input/joystick/iforce/iforce-packets.c @@ -130,11 +130,47 @@ static int mark_core_as_ready(struct iforce *iforce, unsigned short addr) return -1; } -void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) +static void iforce_report_hats_buttons(struct iforce *iforce, u8 *data) { struct input_dev *dev = iforce->dev; int i; + input_report_abs(dev, ABS_HAT0X, iforce_hat_to_axis[data[6] >> 4].x); + input_report_abs(dev, ABS_HAT0Y, iforce_hat_to_axis[data[6] >> 4].y); + + for (i = 0; iforce->type->btn[i] >= 0; i++) + input_report_key(dev, iforce->type->btn[i], + data[(i >> 3) + 5] & (1 << (i & 7))); + + /* If there are untouched bits left, interpret them as the second hat */ + if (i <= 8) { + u8 btns = data[6]; + + if (test_bit(ABS_HAT1X, dev->absbit)) { + if (btns & BIT(3)) + input_report_abs(dev, ABS_HAT1X, -1); + else if (btns & BIT(1)) + input_report_abs(dev, ABS_HAT1X, 1); + else + input_report_abs(dev, ABS_HAT1X, 0); + } + + if (test_bit(ABS_HAT1Y, dev->absbit)) { + if (btns & BIT(0)) + input_report_abs(dev, ABS_HAT1Y, -1); + else if (btns & BIT(2)) + input_report_abs(dev, ABS_HAT1Y, 1); + else + input_report_abs(dev, ABS_HAT1Y, 0); + } + } +} + +void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) +{ + struct input_dev *dev = iforce->dev; + int i, j; + wake_up(&iforce->wait); if (!iforce->type) @@ -143,48 +179,26 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) switch (HI(cmd)) { case 0x01: /* joystick position data */ - case 0x03: /* wheel position data */ - if (HI(cmd) == 1) { - input_report_abs(dev, ABS_X, (__s16) (((__s16)data[1] << 8) | data[0])); - input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[3] << 8) | data[2])); - input_report_abs(dev, ABS_THROTTLE, 255 - data[4]); - if (LO(cmd) >= 8 && test_bit(ABS_RUDDER ,dev->absbit)) - input_report_abs(dev, ABS_RUDDER, (__s8)data[7]); - } else { - input_report_abs(dev, ABS_WHEEL, (__s16) (((__s16)data[1] << 8) | data[0])); - input_report_abs(dev, ABS_GAS, 255 - data[2]); - input_report_abs(dev, ABS_BRAKE, 255 - data[3]); - } + input_report_abs(dev, ABS_X, (__s16) (((__s16)data[1] << 8) | data[0])); + input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[3] << 8) | data[2])); + input_report_abs(dev, ABS_THROTTLE, 255 - data[4]); - input_report_abs(dev, ABS_HAT0X, iforce_hat_to_axis[data[6] >> 4].x); - input_report_abs(dev, ABS_HAT0Y, iforce_hat_to_axis[data[6] >> 4].y); - - for (i = 0; iforce->type->btn[i] >= 0; i++) - input_report_key(dev, iforce->type->btn[i], data[(i >> 3) + 5] & (1 << (i & 7))); - - /* If there are untouched bits left, interpret them as the second hat */ - if (i <= 8) { - int btns = data[6]; - if (test_bit(ABS_HAT1X, dev->absbit)) { - if (btns & 8) - input_report_abs(dev, ABS_HAT1X, -1); - else if (btns & 2) - input_report_abs(dev, ABS_HAT1X, 1); - else - input_report_abs(dev, ABS_HAT1X, 0); - } - if (test_bit(ABS_HAT1Y, dev->absbit)) { - if (btns & 1) - input_report_abs(dev, ABS_HAT1Y, -1); - else if (btns & 4) - input_report_abs(dev, ABS_HAT1Y, 1); - else - input_report_abs(dev, ABS_HAT1Y, 0); - } - } + if (LO(cmd) >= 8 && test_bit(ABS_RUDDER ,dev->absbit)) + input_report_abs(dev, ABS_RUDDER, (__s8)data[7]); + + iforce_report_hats_buttons(iforce, data); input_sync(dev); + break; + case 0x03: /* wheel position data */ + input_report_abs(dev, ABS_WHEEL, (__s16) (((__s16)data[1] << 8) | data[0])); + input_report_abs(dev, ABS_GAS, 255 - data[2]); + input_report_abs(dev, ABS_BRAKE, 255 - data[3]); + + iforce_report_hats_buttons(iforce, data); + + input_sync(dev); break; case 0x02: /* status report */ @@ -202,11 +216,10 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) /* Report stop event */ input_report_ff_status(dev, i, FF_STATUS_STOPPED); } - if (LO(cmd) > 3) { - int j; - for (j = 3; j < LO(cmd); j += 2) - mark_core_as_ready(iforce, data[j] | (data[j+1]<<8)); - } + + for (j = 3; j < LO(cmd); j += 2) + mark_core_as_ready(iforce, data[j] | (data[j + 1] << 8)); + break; } } From patchwork Tue Sep 18 00:47:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603603 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 D600215E8 for ; Tue, 18 Sep 2018 00:48:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C67D52A9B7 for ; Tue, 18 Sep 2018 00:48:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAA192A9D5; Tue, 18 Sep 2018 00:48:44 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 DCB7A2A9B7 for ; Tue, 18 Sep 2018 00:48:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729416AbeIRGRs (ORCPT ); Tue, 18 Sep 2018 02:17:48 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40972 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729407AbeIRGRr (ORCPT ); Tue, 18 Sep 2018 02:17:47 -0400 Received: by mail-pf1-f193.google.com with SMTP id h79-v6so105291pfk.8; Mon, 17 Sep 2018 17:47:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TJUB5Y8stsaj+NlXR7or8AWO9SD70GBJBp+fkS7Z/BE=; b=RraQOg4M6cKTWVCfIpuljXY3YVE61hnDxIvFLYatvHAVB7WhPgPivPl6XoNjZF0tvi T8UiGYlGPq1UbZy4TsvL0c0gLB4fB2K/UVmI7v2pXs6hrfceCt9xV3qyBW3mnNTlGZs5 YZa3zuEUFowKqPO+Z5B4D2lwgvW65SrcqX002vf7mi7QZHvuBSl49wwJ8BIcCyBX0aBG N+Bw0EPZHHTIkVoxSz+fpXrPE5Sll0XWHzE/wnt+H7FdcxGqwArapoBkazFTxV3dwMdc 3Bx+2aiBRZnRexaH+l0l+lEkYA3tZS8Yg/do0ZekUK8Ubu/ZuePdk3RJgHVqocGRMwuB fFpA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=TJUB5Y8stsaj+NlXR7or8AWO9SD70GBJBp+fkS7Z/BE=; b=SVFlzg+LZJMEnuL0h2c5aAVhyg6el8LX4FO9PBICN1/AVkrrLmhp74qVHSebqKoJBU AYaU/BCGnJ8RvzeiQNPGc3EF43ZeTsLS9jyMIHsOliBw0OT3+ObHPQghjc12Evo3aRJ3 a8a29WN8GSYbfsJzH949b8Oexxc+WsmyN/t+uw5VBfwrOxzkqa4dWik8ALv64F6ahXjG fk2Ug8HrtQWZubSPagU6Mu/dzCvX5PsRrl+Ot2DWIQVwDLoyuOmNKe/UTCUKt/phtmOo hu78IHQYWMRLEXm6HVZkLSzxulU4QewLYjrHJjzyqNlTC9RQpZl1mmV3BGBr9eqVri1q +cIw== X-Gm-Message-State: APzg51C2LnnEcjSCQImyVMqOatjx3CsCAzuYWoGwEAL6MjAdww6cQCR2 4l47Sk6Ff8X7z99F3vdGJbmmuboo X-Google-Smtp-Source: ANB0VdbDVxbZzmz8UwRTU74nZ/O97ERrf+Nv/3E1dcvPW1iU86x6yjAIJMpPdIpe3K+BNID58iNc1A== X-Received: by 2002:a62:8559:: with SMTP id u86-v6mr28340287pfd.32.1537231673018; Mon, 17 Sep 2018 17:47:53 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:52 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 12/20] Input: iforce - do not combine arguments for iforce_process_packet() Date: Mon, 17 Sep 2018 17:47:24 -0700 Message-Id: <20180918004732.9875-12-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 Current code combines packet type and data length into single argument to iforce_process_packet() and then has to untangle it. It is much clearer to simply use separate arguments. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-packets.c | 9 +++++---- drivers/input/joystick/iforce/iforce-serio.c | 8 ++++---- drivers/input/joystick/iforce/iforce-usb.c | 4 ++-- drivers/input/joystick/iforce/iforce.h | 3 ++- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c index ffd1dd65deb8..35b7a5206977 100644 --- a/drivers/input/joystick/iforce/iforce-packets.c +++ b/drivers/input/joystick/iforce/iforce-packets.c @@ -166,7 +166,8 @@ static void iforce_report_hats_buttons(struct iforce *iforce, u8 *data) } } -void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) +void iforce_process_packet(struct iforce *iforce, + u8 packet_id, u8 *data, size_t len) { struct input_dev *dev = iforce->dev; int i, j; @@ -176,14 +177,14 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) if (!iforce->type) return; - switch (HI(cmd)) { + switch (packet_id) { case 0x01: /* joystick position data */ input_report_abs(dev, ABS_X, (__s16) (((__s16)data[1] << 8) | data[0])); input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[3] << 8) | data[2])); input_report_abs(dev, ABS_THROTTLE, 255 - data[4]); - if (LO(cmd) >= 8 && test_bit(ABS_RUDDER ,dev->absbit)) + if (len >= 8 && test_bit(ABS_RUDDER ,dev->absbit)) input_report_abs(dev, ABS_RUDDER, (__s8)data[7]); iforce_report_hats_buttons(iforce, data); @@ -217,7 +218,7 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) input_report_ff_status(dev, i, FF_STATUS_STOPPED); } - for (j = 3; j < LO(cmd); j += 2) + for (j = 3; j < len; j += 2) mark_core_as_ready(iforce, data[j] | (data[j + 1] << 8)); break; diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index 6c6411fbdc32..f8bf7d2aa59f 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -163,16 +163,16 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, } if (iforce_serio->idx == iforce_serio->len) { - u16 cmd = (iforce_serio->id << 8) | iforce_serio->idx; - /* Handle command completion */ if (iforce_serio->expect_packet == iforce_serio->id) { iforce_serio->expect_packet = 0; - iforce->ecmd = cmd; + iforce->ecmd = (iforce_serio->id << 8) | + iforce_serio->idx; memcpy(iforce->edata, iforce->data, IFORCE_MAX_LENGTH); } - iforce_process_packet(iforce, cmd, iforce->data); + iforce_process_packet(iforce, iforce_serio->id, + iforce->data, iforce_serio->len); iforce_serio->pkt = 0; iforce_serio->id = 0; diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index cefaa1c5abc7..b3743fde2a3a 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c @@ -170,8 +170,8 @@ static void iforce_usb_irq(struct urb *urb) goto exit; } - iforce_process_packet(iforce, - (iforce->data[0] << 8) | (urb->actual_length - 1), iforce->data + 1); + iforce_process_packet(iforce, iforce->data[0], + iforce->data + 1, urb->actual_length - 1); exit: status = usb_submit_urb(urb, GFP_ATOMIC); diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h index 3e3df83b9d77..ce3c6aead8b6 100644 --- a/drivers/input/joystick/iforce/iforce.h +++ b/drivers/input/joystick/iforce/iforce.h @@ -147,7 +147,8 @@ int iforce_init_device(struct device *parent, u16 bustype, /* iforce-packets.c */ int iforce_control_playback(struct iforce*, u16 id, unsigned int); -void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data); +void iforce_process_packet(struct iforce *iforce, + u8 packet_id, u8 *data, size_t len); int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data); void iforce_dump_packet(struct iforce *iforce, char *msg, u16 cmd, unsigned char *data); From patchwork Tue Sep 18 00:47:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603605 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 5596815E8 for ; Tue, 18 Sep 2018 00:48:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 451B12A9B7 for ; Tue, 18 Sep 2018 00:48:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3949A2A9D5; Tue, 18 Sep 2018 00:48:49 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 DAAB42A9B7 for ; Tue, 18 Sep 2018 00:48:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728758AbeIRGSg (ORCPT ); Tue, 18 Sep 2018 02:18:36 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:46148 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729344AbeIRGRs (ORCPT ); Tue, 18 Sep 2018 02:17:48 -0400 Received: by mail-pl1-f194.google.com with SMTP id t19-v6so89953ply.13; Mon, 17 Sep 2018 17:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xA83sai601+9Drcvsji0za+nEGwEcKki265UlqOSVfo=; b=PiotIvNkWk6A7nqH4gZh7k3MELgk/IiFfbahoYFmWPDxTiPTNoXgTjyr89lSFuS8Hk wDjDd2G3InTa8hd1g3/h9m7cLRfIeFhdtX2p7qGiq/rr61QQhTXvE/OSOS1Ij2BOAddB BcZvABU+L+TndqCjDqVXj2brTVh7td0fzIPUWCxb9lppNZb+mt+qKnJYOau9Dl3H45ps sWbAs8H8gwXdm1fpqDNxcKD2cRhoCwHQHrkQ9r3luzHFmQ390I/tVzCPM0GMPqQvl4v2 ilRthD8Qqm9sZpj18WS2LvZvssC0/VVj49kKZdJF7TXeQTjDaONenAP+iiSu7xSi2JLk 24og== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=xA83sai601+9Drcvsji0za+nEGwEcKki265UlqOSVfo=; b=AvruGECsNe8kBUcmII2m/RPW5raAQb2nA6WKDQLqftNUshEjIbHpzzM91Cn6fLbHqZ qI28zZSyptpEfevtMo7OAFWrCWosv41GDH5o32jsBPXIyNuQXA3RsM3yH7T6vavEk9Q1 ZKbHuYvTOTd+3RIWGseFEWWSy9JuAX23aPAz8EI/k9NTTUKm6IaTPGETsJ0zfaLwMi5l CRAoHczIiiFI5JnqZQ8kAoT8o9CHu3NyX4YuIuu8r+fAgXB81LKyoJan+MA1Pb7i1iC9 ci9ETEOYQfBEo5DMmtx4SLr1vFij8m3n+FsfwbMVUmnoBKtfq/xgddMxN05C4S8+wSSr QIeQ== X-Gm-Message-State: APzg51Cl8oNvadjr4npmP5kuGYOH4pYK4TV9hBH0J70+ZNd0Ogc61tCz 5qetPJ0FoNvg47pWXzbEZ3qzaDe1 X-Google-Smtp-Source: ANB0Vdb9ByfNGZDjSXM1u7yQ/MdJQvCTny+Z5Te0jWm0JyRDY7quaq4vCdIaBdAX33KsjHUT0JdljQ== X-Received: by 2002:a17:902:163:: with SMTP id 90-v6mr26776449plb.322.1537231674351; Mon, 17 Sep 2018 17:47:54 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:53 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 13/20] Input: iforce - signal command completion from transport code Date: Mon, 17 Sep 2018 17:47:25 -0700 Message-Id: <20180918004732.9875-13-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 Signalling command completion from iforce_process_packet() does not make sense, as not all transport use the same data path for both commands and motion data form the device, that is why USB code already has to signal command completion iforce_usb_out(). Let's move signalling completion into individual transport modules. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-packets.c | 2 -- drivers/input/joystick/iforce/iforce-serio.c | 9 ++++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c index 35b7a5206977..c0a665961c23 100644 --- a/drivers/input/joystick/iforce/iforce-packets.c +++ b/drivers/input/joystick/iforce/iforce-packets.c @@ -172,8 +172,6 @@ void iforce_process_packet(struct iforce *iforce, struct input_dev *dev = iforce->dev; int i, j; - wake_up(&iforce->wait); - if (!iforce->type) return; diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index f8bf7d2aa59f..0dd95d145e85 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -169,10 +169,13 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, iforce->ecmd = (iforce_serio->id << 8) | iforce_serio->idx; memcpy(iforce->edata, iforce->data, IFORCE_MAX_LENGTH); - } - iforce_process_packet(iforce, iforce_serio->id, - iforce->data, iforce_serio->len); + /* Signal that command is done */ + wake_up(&iforce->wait); + } else { + iforce_process_packet(iforce, iforce_serio->id, + iforce->data, iforce_serio->len); + } iforce_serio->pkt = 0; iforce_serio->id = 0; From patchwork Tue Sep 18 00:47:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603601 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 04B03157B for ; Tue, 18 Sep 2018 00:48:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E873A2A9B7 for ; Tue, 18 Sep 2018 00:48:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAF7C2A9D5; Tue, 18 Sep 2018 00:48:38 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 895A42A9B7 for ; Tue, 18 Sep 2018 00:48:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729440AbeIRGRu (ORCPT ); Tue, 18 Sep 2018 02:17:50 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:45706 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729407AbeIRGRu (ORCPT ); Tue, 18 Sep 2018 02:17:50 -0400 Received: by mail-pl1-f195.google.com with SMTP id j8-v6so91694pll.12; Mon, 17 Sep 2018 17:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wHav3Nwh/EegPSO4dRJ04MDT2MQcX0l4gtMFSLuNA+A=; b=iqNoDaTmBQNWLkypPz5EZn50/CE5L4RY7rI+DPyF45MWAdQp7/ugILrHK5vuwXc9m6 j0xvPp5W+tufhdtGHk5HQd2GLisycyO2FzbXWvfe+yu15sX480q+fpAo8G99t9Ob0dVl WegIZSs78SIDEfXGIxEY8So5lwlgFyCm3/cq54gQ3+8VPIW0tB2A/mtOS1AOEyFwRThW GJwwi6BFRAUHzpTKjb9/0g4qzBfjUOByR5wqxvARJvagZ9yH9hZ0JRcTFSLeymZXq6qr htgwq+vdsJ/v26JnHd0HDM4uwcnD21wQq6dwCtoZGXKOOKaBuyAD9mHKabdS3D0yntdO eOqg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=wHav3Nwh/EegPSO4dRJ04MDT2MQcX0l4gtMFSLuNA+A=; b=Ta/M7wu7awUwxI1jkmRANCthHBH6Bsj4tPNWFwdvv99wOHmXG7KayhHHcyAUhChMU5 tGtPnisA1pdudw1N3wmNb/ne7AwYQNURXTP0Ef8Bd4JAsLnplAM29xuRSZ22IVaYhiYy KPKPlBEeIH3Cb4VQBoOIj0RDXlkE/qGQ90UmYafB6uLDnfsVkdTBdIrhnT1HnMudFO1F QL9/zM+8D8eMwoFd+L0J8BRTUZcf3XpxqXbr9xNg9p6CavTQgVZaYkDNwggKV3ieRFxn t42ePZcPG31mNaEw4PQIde5r8KuwYkeuVtKB5oA3US2q+HRfh/YAa9sVjWRT/V3KFsCF AZTQ== X-Gm-Message-State: APzg51DIJSOKGAXoiGFSkiokxgLx5cdUIukpnmXkxOWj3Pa2gUQLq22p NASSf0bxRRIe83mxpiMW68OEG1s/ X-Google-Smtp-Source: ANB0VdZEhWjytE0ILerWk8a3NCxKXt2Geah3EaaKPzossZakJRTbxLy8AwPYdCjumGnBsgHrWneVKA== X-Received: by 2002:a17:902:1ab:: with SMTP id b40-v6mr27663473plb.55.1537231675978; Mon, 17 Sep 2018 17:47:55 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:54 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 14/20] Input: iforce - only call iforce_process_packet() if initialized Date: Mon, 17 Sep 2018 17:47:26 -0700 Message-Id: <20180918004732.9875-14-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 It is excessive to check if device is fully initialized in iforce_process_packet(), as for USB-conected devices we do not start collecting reports until the device is fully initialized. Let's change serio transport code to not call iforce_process_packet() until device initialization is done. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-packets.c | 3 --- drivers/input/joystick/iforce/iforce-serio.c | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c index c0a665961c23..976ec1c7cf15 100644 --- a/drivers/input/joystick/iforce/iforce-packets.c +++ b/drivers/input/joystick/iforce/iforce-packets.c @@ -172,9 +172,6 @@ void iforce_process_packet(struct iforce *iforce, struct input_dev *dev = iforce->dev; int i, j; - if (!iforce->type) - return; - switch (packet_id) { case 0x01: /* joystick position data */ diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index 0dd95d145e85..8d7eba9c9f0e 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -172,7 +172,7 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, /* Signal that command is done */ wake_up(&iforce->wait); - } else { + } else if (likely(iforce->type)) { iforce_process_packet(iforce, iforce_serio->id, iforce->data, iforce_serio->len); } From patchwork Tue Sep 18 00:47:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603599 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 2103D157B for ; Tue, 18 Sep 2018 00:48:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FDE32A9B7 for ; Tue, 18 Sep 2018 00:48:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0448E2A9D5; Tue, 18 Sep 2018 00:48:35 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 574242A9B7 for ; Tue, 18 Sep 2018 00:48:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729463AbeIRGRx (ORCPT ); Tue, 18 Sep 2018 02:17:53 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:43436 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729407AbeIRGRw (ORCPT ); Tue, 18 Sep 2018 02:17:52 -0400 Received: by mail-pg1-f193.google.com with SMTP id v66-v6so100866pgb.10; Mon, 17 Sep 2018 17:47:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iSF41QL/4F8SAH9V7ryVUuaUkx8P5+uBNzviyJD1NWc=; b=keKfW7cj31um9Pc1Pib7/AanGNZv2U4tJ7CGewPB6IZ/HOjSd9soe81EZKGMVaXg9E Jp9hq51Wvgmy2b6koiCVgkgP2/M6MDp5ZivJlmdkRQhnmoO0mbTnyeFsTo9D1SIG8vfP j/gOsh+cKuWncAthaoMSy7rqXXKC+AKL8/Z0iqBjASQGRIqkBNYDJsBhB6s8g9wDQ+bH S+ZHu0q7gE/WFG2M+GlcFNWOog2+Fe+OdYQHG+OkhzWH9jwQ1gW6K85T3MkZyLZRYXpT RG5yjZAwUYN6Z+tJ/gpWz2F6Utd0Buf52kjjHV/WE02PijAp/9I7dVs4vdtTGSkv0e9L GwDw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=iSF41QL/4F8SAH9V7ryVUuaUkx8P5+uBNzviyJD1NWc=; b=C/ZZONNFYrZ5YQgpF3Mv2kI3zoy8HFk2QACrW1rDSCBqnB480bdP2DpEuGwAG7Mr2A EQ+CowZixMOrfhZrhmV5pXQCD9lQMQ+acBNCr0w1dOPo9k+fvfOzgVBr/YFMYV+Cb4eb saEHsiEKc2vNre5k+kqCk612VR6VjXT91Hdl10OJq9A1Srxe0451trkPV82AVTdkjH7n jyWovAgAnoYwOJzqIUGeEUuI1mJvkGk0zthVjw9X9zE19arfsXOoZn5uKFJc02YnpdMg fHy46+XXnEQ9kliL531K/qlHYjfyzk9uiydIwUSFe12WSSNuU/o/nNEeL+zSz3jXS50t HVEA== X-Gm-Message-State: APzg51Dt3j2HgLXecT3DCaHovD1H7P0RmQQmi/QXPmCU4oa7DGrAMShK Iik2bEzPGW6Q0vujtcTXe06li4x5 X-Google-Smtp-Source: ANB0VdaPUBcojgLODMuTantcRTXx6jLb8tbWmxHZELwXiRuZTU3C07XCZGnChsBKBq06LHe2NV2Stg== X-Received: by 2002:a63:ff1f:: with SMTP id k31-v6mr24813748pgi.20.1537231677747; Mon, 17 Sep 2018 17:47:57 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:56 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 15/20] Input: iforce - allow callers supply data buffer when fetching device IDs Date: Mon, 17 Sep 2018 17:47:27 -0700 Message-Id: <20180918004732.9875-15-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 We want to move buffer handling into transport layers as the properties of buffers (DMA-safety, alignment, etc) are different for different transports. To allow this, let's allow caller to specify their own buffers for the results of iforce_get_id_packet() and let transport drivers to figure what buffers they need to use for transfers. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-main.c | 27 ++++++++++--------- drivers/input/joystick/iforce/iforce-serio.c | 28 ++++++++++++++------ drivers/input/joystick/iforce/iforce-usb.c | 11 ++++---- drivers/input/joystick/iforce/iforce.h | 11 ++++---- 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c index 9964aa8b3cdc..5cb3e80f4e0d 100644 --- a/drivers/input/joystick/iforce/iforce-main.c +++ b/drivers/input/joystick/iforce/iforce-main.c @@ -225,7 +225,9 @@ int iforce_init_device(struct device *parent, u16 bustype, { struct input_dev *input_dev; struct ff_device *ff; - unsigned char c[] = "CEOV"; + u8 c[] = "CEOV"; + u8 buf[IFORCE_MAX_LENGTH]; + size_t len; int i, error; int ff_effects = 0; @@ -269,7 +271,7 @@ int iforce_init_device(struct device *parent, u16 bustype, */ for (i = 0; i < 20; i++) - if (!iforce_get_id_packet(iforce, "O")) + if (!iforce_get_id_packet(iforce, 'O', buf, &len)) break; if (i == 20) { /* 5 seconds */ @@ -283,23 +285,23 @@ int iforce_init_device(struct device *parent, u16 bustype, * Get device info. */ - if (!iforce_get_id_packet(iforce, "M")) - input_dev->id.vendor = (iforce->edata[2] << 8) | iforce->edata[1]; + if (!iforce_get_id_packet(iforce, 'M', buf, &len) || len < 3) + input_dev->id.vendor = (buf[2] << 8) | buf[1]; else dev_warn(&iforce->dev->dev, "Device does not respond to id packet M\n"); - if (!iforce_get_id_packet(iforce, "P")) - input_dev->id.product = (iforce->edata[2] << 8) | iforce->edata[1]; + if (!iforce_get_id_packet(iforce, 'P', buf, &len) || len < 3) + input_dev->id.product = (buf[2] << 8) | buf[1]; else dev_warn(&iforce->dev->dev, "Device does not respond to id packet P\n"); - if (!iforce_get_id_packet(iforce, "B")) - iforce->device_memory.end = (iforce->edata[2] << 8) | iforce->edata[1]; + if (!iforce_get_id_packet(iforce, 'B', buf, &len) || len < 3) + iforce->device_memory.end = (buf[2] << 8) | buf[1]; else dev_warn(&iforce->dev->dev, "Device does not respond to id packet B\n"); - if (!iforce_get_id_packet(iforce, "N")) - ff_effects = iforce->edata[1]; + if (!iforce_get_id_packet(iforce, 'N', buf, &len) || len < 2) + ff_effects = buf[1]; else dev_warn(&iforce->dev->dev, "Device does not respond to id packet N\n"); @@ -315,8 +317,9 @@ int iforce_init_device(struct device *parent, u16 bustype, */ for (i = 0; c[i]; i++) - if (!iforce_get_id_packet(iforce, c + i)) - iforce_dump_packet(iforce, "info", iforce->ecmd, iforce->edata); + if (!iforce_get_id_packet(iforce, c[i], buf, &len)) + iforce_dump_packet(iforce, "info", + (FF_CMD_QUERY & 0xff00) | len, buf); /* * Disable spring, enable force feedback. diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index 8d7eba9c9f0e..be44aed551f7 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -31,6 +31,8 @@ struct iforce_serio { int idx, pkt, len, id; u8 csum; u8 expect_packet; + u8 cmd_response[IFORCE_MAX_LENGTH]; + u8 cmd_response_len; }; static void iforce_serio_xmit(struct iforce *iforce) @@ -81,24 +83,34 @@ static void iforce_serio_xmit(struct iforce *iforce) spin_unlock_irqrestore(&iforce->xmit_lock, flags); } -static int iforce_serio_get_id(struct iforce *iforce, u8 *packet) +static int iforce_serio_get_id(struct iforce *iforce, u8 id, + u8 *response_data, size_t *response_len) { struct iforce_serio *iforce_serio = container_of(iforce, struct iforce_serio, iforce); iforce_serio->expect_packet = HI(FF_CMD_QUERY); - iforce_send_packet(iforce, FF_CMD_QUERY, packet); + iforce_serio->cmd_response_len = 0; + + iforce_send_packet(iforce, FF_CMD_QUERY, &id); wait_event_interruptible_timeout(iforce->wait, !iforce_serio->expect_packet, HZ); if (iforce_serio->expect_packet) { iforce_serio->expect_packet = 0; - return -EIO; + return -ETIMEDOUT; } - return -(iforce->edata[0] != packet[0]); + if (iforce_serio->cmd_response[0] != id) + return -EIO; + + memcpy(response_data, iforce_serio->cmd_response, + iforce_serio->cmd_response_len); + *response_len = iforce_serio->cmd_response_len; + + return 0; } static int iforce_serio_start_io(struct iforce *iforce) @@ -127,7 +139,7 @@ static void iforce_serio_write_wakeup(struct serio *serio) } static irqreturn_t iforce_serio_irq(struct serio *serio, - unsigned char data, unsigned int flags) + unsigned char data, unsigned int flags) { struct iforce_serio *iforce_serio = serio_get_drvdata(serio); struct iforce *iforce = &iforce_serio->iforce; @@ -166,9 +178,9 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, /* Handle command completion */ if (iforce_serio->expect_packet == iforce_serio->id) { iforce_serio->expect_packet = 0; - iforce->ecmd = (iforce_serio->id << 8) | - iforce_serio->idx; - memcpy(iforce->edata, iforce->data, IFORCE_MAX_LENGTH); + memcpy(iforce_serio->cmd_response, iforce->data, + IFORCE_MAX_LENGTH); + iforce_serio->cmd_response_len = iforce_serio->len; /* Signal that command is done */ wake_up(&iforce->wait); diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index b3743fde2a3a..68155c4de412 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c @@ -87,7 +87,8 @@ static void iforce_usb_xmit(struct iforce *iforce) __iforce_usb_xmit(iforce); } -static int iforce_usb_get_id(struct iforce *iforce, u8 *packet) +static int iforce_usb_get_id(struct iforce *iforce, u8 id, + u8 *response_data, size_t *response_len) { struct iforce_usb *iforce_usb = container_of(iforce, struct iforce_usb, iforce); @@ -100,18 +101,18 @@ static int iforce_usb_get_id(struct iforce *iforce, u8 *packet) status = usb_control_msg(iforce_usb->usbdev, usb_rcvctrlpipe(iforce_usb->usbdev, 0), - packet[0], + id, USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_INTERFACE, 0, 0, buf, IFORCE_MAX_LENGTH, HZ); if (status < 0) { dev_err(&iforce_usb->intf->dev, "usb_submit_urb failed: %d\n", status); - } else if (buf[0] != packet[0]) { + } else if (buf[0] != id) { status = -EIO; } else { - iforce->ecmd = 0xff00 | status; - memcpy(iforce->edata, buf, status); + memcpy(response_data, buf, status); + *response_len = status; status = 0; } diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h index ce3c6aead8b6..68558c594e54 100644 --- a/drivers/input/joystick/iforce/iforce.h +++ b/drivers/input/joystick/iforce/iforce.h @@ -95,7 +95,8 @@ struct iforce; struct iforce_xport_ops { void (*xmit)(struct iforce *iforce); - int (*get_id)(struct iforce *iforce, u8* id); + int (*get_id)(struct iforce *iforce, u8 id, + u8 *response_data, size_t *response_len); int (*start_io)(struct iforce *iforce); void (*stop_io)(struct iforce *iforce); }; @@ -107,8 +108,6 @@ struct iforce { int bus; unsigned char data[IFORCE_MAX_LENGTH]; - unsigned char edata[IFORCE_MAX_LENGTH]; - u16 ecmd; spinlock_t xmit_lock; /* Buffer used for asynchronous sending of bytes to the device */ @@ -135,9 +134,11 @@ struct iforce { /* Encode a time value */ #define TIME_SCALE(a) (a) -static inline int iforce_get_id_packet(struct iforce *iforce, u8* id) +static inline int iforce_get_id_packet(struct iforce *iforce, u8 id, + u8 *response_data, size_t *response_len) { - return iforce->xport_ops->get_id(iforce, id); + return iforce->xport_ops->get_id(iforce, id, + response_data, response_len); } /* Public functions */ From patchwork Tue Sep 18 00:47:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603597 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 43A59157B for ; Tue, 18 Sep 2018 00:48:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33C782A9B7 for ; Tue, 18 Sep 2018 00:48:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 283072A9D5; Tue, 18 Sep 2018 00:48:31 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 9FCA52A9B7 for ; Tue, 18 Sep 2018 00:48:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729482AbeIRGRz (ORCPT ); Tue, 18 Sep 2018 02:17:55 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:36429 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729469AbeIRGRy (ORCPT ); Tue, 18 Sep 2018 02:17:54 -0400 Received: by mail-pl1-f194.google.com with SMTP id p5-v6so108728plk.3; Mon, 17 Sep 2018 17:48:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HByUc57ld/iWST/cDFGHHb5LTFImKWNMLwbZ92Hy5EI=; b=k7JMFDVFgA3jpW8EHCiQs7+U7ex4LD9uG2hARVX9W84PDP1eYLEWmrEMwF3YWt0KJp i2B1kDvvybbRmkqBc20BzCQ1sEro/Ef1wBvc9eTjkMhT6MauNIcqiUoX3q4rlie0KkDZ k6yHRh98vHHaU2/pvjJuHzFAFUhfze75J+RCehjNkBVr8g3dNPJ8qhmtiP/oXQ8nkYNT 99oaABCgpvKwaFg0s88fuAt0uQJVJARmln1HFyYD5TuVoDgoAPAgxR1oeBDQ8qSLPvwK 9Uo+jYxPcnYl03n2gJGBQbvX1BJBPBW8nShtgu478FfYbgo6mgZf2pCO68Ix5ewmt7qp ZIlA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=HByUc57ld/iWST/cDFGHHb5LTFImKWNMLwbZ92Hy5EI=; b=pc7uAHEx3/xNDE76a0GhNPYoz5Zc3imgZkr3PiAOu1VCiOX0bGWZkyFavYJfqzW2iM pH3OM0terf66utJjcUE1IqilLYU3+kPGMSCk15TsLne419y7kkk6iWlHqNKRpGMJQ62X KZx5XTg2Q0YRvOfTPuFaT+ez7rd/bh5ThMuh33gzz7k2RErCn379vGQZroudBOg8vxkv in/d9FHIz8AB6KJMAjl2YuWeGcOOx+Iq5sfbOlK+wrRhqH487sGFUACICdXjIXdvLdU5 8STy52/utSNpzUoM2sew6H4aBCY3Dzf43gBCwGdBrxtfk1tR6/gqyyZl1ZrBHxA1Gwq9 tveQ== X-Gm-Message-State: APzg51ALl1wXbODqZZ2OlfR6yUwchvqluLWWpivheGpLdflxEECOPCzJ azesHROK7P73jfhMdKX+dnDAATOy X-Google-Smtp-Source: ANB0VdYfjbcmzOBC607GBea47gygW4K2rLES1Cs/GEPDgYoqAT7kOBdXLfYxGXTL7uF8vWudXJOT6g== X-Received: by 2002:a17:902:64c1:: with SMTP id y1-v6mr26436562pli.45.1537231679210; Mon, 17 Sep 2018 17:47:59 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:58 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 16/20] Input: iforce - use DMA-safe buffores for USB transfers Date: Mon, 17 Sep 2018 17:47:28 -0700 Message-Id: <20180918004732.9875-16-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 USB transport has to use cache line-aligned buffers for transfers to avoid DMA issues; serio doe snot have such restrictions. Let's move "data_in" buffer from main driver structure into transport modules and make sure USB requirements are respected. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-serio.c | 10 ++++--- drivers/input/joystick/iforce/iforce-usb.c | 28 +++++++++++++------- drivers/input/joystick/iforce/iforce.h | 2 -- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index be44aed551f7..c73d988cbc92 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -33,6 +33,7 @@ struct iforce_serio { u8 expect_packet; u8 cmd_response[IFORCE_MAX_LENGTH]; u8 cmd_response_len; + u8 data_in[IFORCE_MAX_LENGTH]; }; static void iforce_serio_xmit(struct iforce *iforce) @@ -169,7 +170,7 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, } if (iforce_serio->idx < iforce_serio->len) { - iforce->data[iforce_serio->idx++] = data; + iforce_serio->data_in[iforce_serio->idx++] = data; iforce_serio->csum += data; goto out; } @@ -178,15 +179,16 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, /* Handle command completion */ if (iforce_serio->expect_packet == iforce_serio->id) { iforce_serio->expect_packet = 0; - memcpy(iforce_serio->cmd_response, iforce->data, - IFORCE_MAX_LENGTH); + memcpy(iforce_serio->cmd_response, + iforce_serio->data_in, IFORCE_MAX_LENGTH); iforce_serio->cmd_response_len = iforce_serio->len; /* Signal that command is done */ wake_up(&iforce->wait); } else if (likely(iforce->type)) { iforce_process_packet(iforce, iforce_serio->id, - iforce->data, iforce_serio->len); + iforce_serio->data_in, + iforce_serio->len); } iforce_serio->pkt = 0; diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index 68155c4de412..d85258b50be2 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c @@ -30,6 +30,9 @@ struct iforce_usb { struct usb_device *usbdev; struct usb_interface *intf; struct urb *irq, *out; + + u8 data_in[IFORCE_MAX_LENGTH] ____cacheline_aligned; + u8 data_out[IFORCE_MAX_LENGTH] ____cacheline_aligned; }; static void __iforce_usb_xmit(struct iforce *iforce) @@ -171,8 +174,8 @@ static void iforce_usb_irq(struct urb *urb) goto exit; } - iforce_process_packet(iforce, iforce->data[0], - iforce->data + 1, urb->actual_length - 1); + iforce_process_packet(iforce, iforce_usb->data_in[0], + iforce_usb->data_in + 1, urb->actual_length - 1); exit: status = usb_submit_urb(urb, GFP_ATOMIC); @@ -216,13 +219,16 @@ static int iforce_usb_probe(struct usb_interface *intf, epirq = &interface->endpoint[0].desc; epout = &interface->endpoint[1].desc; - if (!(iforce_usb = kzalloc(sizeof(*iforce_usb) + 32, GFP_KERNEL))) + iforce_usb = kzalloc(sizeof(*iforce_usb), GFP_KERNEL); + if (!iforce_usb) goto fail; - if (!(iforce_usb->irq = usb_alloc_urb(0, GFP_KERNEL))) + iforce_usb->irq = usb_alloc_urb(0, GFP_KERNEL); + if (!iforce_usb->irq) goto fail; - if (!(iforce_usb->out = usb_alloc_urb(0, GFP_KERNEL))) + iforce_usb->out = usb_alloc_urb(0, GFP_KERNEL); + if (!iforce_usb->out) goto fail; iforce = &iforce_usb->iforce; @@ -233,11 +239,15 @@ static int iforce_usb_probe(struct usb_interface *intf, iforce_usb->usbdev = dev; iforce_usb->intf = intf; - usb_fill_int_urb(iforce_usb->irq, dev, usb_rcvintpipe(dev, epirq->bEndpointAddress), - iforce->data, 16, iforce_usb_irq, iforce_usb, epirq->bInterval); + usb_fill_int_urb(iforce_usb->irq, dev, + usb_rcvintpipe(dev, epirq->bEndpointAddress), + iforce_usb->data_in, sizeof(iforce_usb->data_in), + iforce_usb_irq, iforce_usb, epirq->bInterval); - usb_fill_int_urb(iforce_usb->out, dev, usb_sndintpipe(dev, epout->bEndpointAddress), - iforce_usb + 1, 32, iforce_usb_out, iforce_usb, epout->bInterval); + usb_fill_int_urb(iforce_usb->out, dev, + usb_sndintpipe(dev, epout->bEndpointAddress), + iforce_usb->data_out, sizeof(iforce_usb->data_out), + iforce_usb_out, iforce_usb, epout->bInterval); err = iforce_init_device(&intf->dev, BUS_USB, iforce); if (err) diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h index 68558c594e54..180de7a3f3a1 100644 --- a/drivers/input/joystick/iforce/iforce.h +++ b/drivers/input/joystick/iforce/iforce.h @@ -107,8 +107,6 @@ struct iforce { const struct iforce_xport_ops *xport_ops; int bus; - unsigned char data[IFORCE_MAX_LENGTH]; - spinlock_t xmit_lock; /* Buffer used for asynchronous sending of bytes to the device */ struct circ_buf xmit; From patchwork Tue Sep 18 00:47:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603593 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 151B615E8 for ; Tue, 18 Sep 2018 00:48:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0628E2A98B for ; Tue, 18 Sep 2018 00:48:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE5BC2A99D; Tue, 18 Sep 2018 00:48:23 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 9304F2A98B for ; Tue, 18 Sep 2018 00:48:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726987AbeIRGR6 (ORCPT ); Tue, 18 Sep 2018 02:17:58 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:34791 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729484AbeIRGRz (ORCPT ); Tue, 18 Sep 2018 02:17:55 -0400 Received: by mail-pf1-f196.google.com with SMTP id k19-v6so119740pfi.1; Mon, 17 Sep 2018 17:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tMA4CZejwy/bgOlPy0MmgAKcWO/jJ6UDYO2B4khfCIY=; b=OjhfHwhHHI1JEOwPQkXJdgBHaX78ef9iVrSNNbWtYGEck5nfIsbqXd7nkqcxnh+YLB qfX1aYCpp2hIiOfZz6unjWwZOu1BFof5Tozf7YrGFS8dWf3+W2/RwgjFXufccuRaXYGs mO7ZXsR6ptugY4xn2v/0eVvGOzd1GReeGGToelXYsHWrbVVzAZJw66ctiOkUn+cDWm1C zLF23h/MscKy8Wk9WwTawuq0tZqTV6u1cwT2+kT9MaCQgSbBFAippGHh0s+HL7LOLJGx qqjNGL+J71QarwIYVW8hiWapj8ZgjsJIEgAAZqFTpkavRphz+D80yHU2DEcU8vCCMbtT U0nw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=tMA4CZejwy/bgOlPy0MmgAKcWO/jJ6UDYO2B4khfCIY=; b=bGMWBP5sbOWoJDP/Lf8O5Fjz/zilM9nyX6ZDICdBwGtQf4jvjq9FQgxiduMkRV2jUt weqFe5U0iSJNUUgYWDQogDQTJMK5fcnJ72d0v/VmaRcB4az+XFZDkJHV3vdTF+6HHq7U ZtumRKpNhSr/7LOQNDJpH8qM2dPYjF/pdtCZWgzvH0hsPPdRGnpU/tJOvEGS2L8Acp8Y XjCgqSTVGux9cDwCKqnoAopAMIZFY9e5Uz57EVrc/5MjzLuFT9sh88lQH/05S6C7O+dB B+VkSN3yMgykB9LDsOAFVLMzsDh02mbrB5ZTYINI/d+rw6WlEWKhDQ6nn7FKnvfF22QG KAxw== X-Gm-Message-State: APzg51CZjQwqaKezX1ggjylahojN7b+BsbVPGo4vawG4sXwXlNZueCE4 f8gB8hHE/gz0AzxqpUYeIWi7oE4U X-Google-Smtp-Source: ANB0VdYpzVNRZHvQkJtl5f33enpFHLhcxHF6Wq6QX0Ksb8/OeA+hiakmNvh4vs0OkAF5ufhzwIF7zA== X-Received: by 2002:a63:a35f:: with SMTP id v31-v6mr25553394pgn.261.1537231681154; Mon, 17 Sep 2018 17:48:01 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.47.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:47:59 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 17/20] Input: only credit entropy when events are generated by a device Date: Mon, 17 Sep 2018 17:47:29 -0700 Message-Id: <20180918004732.9875-17-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 Currently we credit entropy (via add_input_randomness()) regardless of where an event comes form, a device itself, or an input handler, such as evdev (and thus from userspace). While access to event devices is supposed to be tightly controlled (one does not want random processes to be able to observe or inject keystrokes), developers may use evdev to inject events for testing purposes. Let's make sure that such events to not contribute to the entropy to keep the pool 'pure' and do not expose developer's boxes to not so random data. Signed-off-by: Dmitry Torokhov --- drivers/input/input.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/input/input.c b/drivers/input/input.c index 260f00ebe34d..0126b8bb6afa 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -368,12 +368,15 @@ static int input_get_disposition(struct input_dev *dev, } static void input_handle_event(struct input_dev *dev, - unsigned int type, unsigned int code, int value) + unsigned int type, unsigned int code, int value, + bool can_credit_entropy) { int disposition = input_get_disposition(dev, type, code, &value); - if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN) + if (can_credit_entropy && + disposition != INPUT_IGNORE_EVENT && type != EV_SYN) { add_input_randomness(type, code, value); + } if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) dev->event(dev, type, code, value); @@ -434,7 +437,7 @@ void input_event(struct input_dev *dev, if (is_event_supported(type, dev->evbit, EV_MAX)) { spin_lock_irqsave(&dev->event_lock, flags); - input_handle_event(dev, type, code, value); + input_handle_event(dev, type, code, value, true); spin_unlock_irqrestore(&dev->event_lock, flags); } } @@ -464,7 +467,7 @@ void input_inject_event(struct input_handle *handle, rcu_read_lock(); grab = rcu_dereference(dev->grab); if (!grab || grab == handle) - input_handle_event(dev, type, code, value); + input_handle_event(dev, type, code, value, false); rcu_read_unlock(); spin_unlock_irqrestore(&dev->event_lock, flags); From patchwork Tue Sep 18 00:47:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603595 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 2AC99157B for ; Tue, 18 Sep 2018 00:48:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B1DC2A9B7 for ; Tue, 18 Sep 2018 00:48:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F7032A9D5; Tue, 18 Sep 2018 00:48:30 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 F1A952A9B7 for ; Tue, 18 Sep 2018 00:48:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729500AbeIRGR6 (ORCPT ); Tue, 18 Sep 2018 02:17:58 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:47030 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726987AbeIRGR5 (ORCPT ); Tue, 18 Sep 2018 02:17:57 -0400 Received: by mail-pg1-f195.google.com with SMTP id b129-v6so94335pga.13; Mon, 17 Sep 2018 17:48:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RGr4r8GexPsIaQ1Kf4tDzDfD+BK7SJUhhOLQe4lCNHQ=; b=JrqAzBQXzqzRm8CAvx2CoJlW68eG/pfc9S84gG/1VU9EB8xswSmtIWVo3aLEC89ouJ zi8JjMixw09X1+Joy/A44Jm6XnEkqjWiq/o2tXSFJb7AbqWp8G7reRk73/7SepPafu3A 0CxSob0Wrept/M1+UO5oLQfNrD1qGtIdgyXKVNzBmf63nbRkOPi2EaTfm8UDhTHV98FF IgHFa4oH5jGUtgXJ0Sp4vw0W7PdDRuP974DMWquDl1I6U88f0Jzx+iYswKVJig7wjFWD bXn5A/quemrPLr/8M805/kFR0sfbVg8kgInJCCAGdbvN8sWT4RyGQrexgdLlNeEAhBzz aZxw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=RGr4r8GexPsIaQ1Kf4tDzDfD+BK7SJUhhOLQe4lCNHQ=; b=kd+jLS/sU8QCjmMhXjBea1yTv+o+Kuztp6bioCrnvQDuz6moB0VaU4d/PDdf4hTh7Q dpIaktQSrAXS6hd9UhZ9WuB4bOT9K4S7/A6YW3cTbQrnjsSqGez/0A95U6GeGyo6cneN EFMhxHuSC8zF/VNRBA4W9eGkrTcoZuUUmfEFKXCJy5lFng+Lsce/QuasRuduUkROyFl/ XxbZzdV1crsa1NNdj6UegWuCgWBII0dbSgRZNbfKIu9P1JmWKF2yNT/kdiTS6sgojdhL 7tUoly8Eitqjhj37VX/CvtiDeOMaB6tYWICLSKbY5BZ7XeDUVVT5R977SVdaZGON6B4/ rLBg== X-Gm-Message-State: APzg51B6RPBFxvlpZU3gLQzgxvsYWbz5D1AEyg//6Q01n5nyh+Buwh9X NmWO3G4enyLKAE6kJGPmj3/IhHCf X-Google-Smtp-Source: ANB0VdZ8ncM130KU6cbc0qtp46dPwEBlk+lBV8vC8EoObvpLh4G0NqK0TnsYz9uNUL5o4Niii9f60w== X-Received: by 2002:a63:d74f:: with SMTP id w15-v6mr25579512pgi.306.1537231683097; Mon, 17 Sep 2018 17:48:03 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.48.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:48:01 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 18/20] Input: iforce - drop bus type from iforce structure Date: Mon, 17 Sep 2018 17:47:30 -0700 Message-Id: <20180918004732.9875-18-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 It is not needed anymore as behavior is controlled by the transport operations set up for given device. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-serio.c | 1 - drivers/input/joystick/iforce/iforce-usb.c | 1 - drivers/input/joystick/iforce/iforce.h | 5 ----- 3 files changed, 7 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index c73d988cbc92..277522d0f324 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -214,7 +214,6 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) iforce = &iforce_serio->iforce; iforce->xport_ops = &iforce_serio_xport_ops; - iforce->bus = IFORCE_232; iforce_serio->serio = serio; serio_set_drvdata(serio, iforce_serio); diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index d85258b50be2..ae2dd5b5a416 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c @@ -234,7 +234,6 @@ static int iforce_usb_probe(struct usb_interface *intf, iforce = &iforce_usb->iforce; iforce->xport_ops = &iforce_usb_xport_ops; - iforce->bus = IFORCE_USB; iforce_usb->usbdev = dev; iforce_usb->intf = intf; diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h index 180de7a3f3a1..3e91cc381488 100644 --- a/drivers/input/joystick/iforce/iforce.h +++ b/drivers/input/joystick/iforce/iforce.h @@ -38,10 +38,6 @@ #define IFORCE_MAX_LENGTH 16 -/* iforce::bus */ -#define IFORCE_232 1 -#define IFORCE_USB 2 - #define IFORCE_EFFECTS_MAX 32 /* Each force feedback effect is made of one core effect, which can be @@ -105,7 +101,6 @@ struct iforce { struct input_dev *dev; /* Input device interface */ struct iforce_device *type; const struct iforce_xport_ops *xport_ops; - int bus; spinlock_t xmit_lock; /* Buffer used for asynchronous sending of bytes to the device */ From patchwork Tue Sep 18 00:47:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603591 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 51ED2157B for ; Tue, 18 Sep 2018 00:48:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4267A2A98B for ; Tue, 18 Sep 2018 00:48:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 365272A99D; Tue, 18 Sep 2018 00:48:18 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 CF1402A98B for ; Tue, 18 Sep 2018 00:48:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729543AbeIRGR7 (ORCPT ); Tue, 18 Sep 2018 02:17:59 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:47031 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729519AbeIRGR6 (ORCPT ); Tue, 18 Sep 2018 02:17:58 -0400 Received: by mail-pg1-f195.google.com with SMTP id b129-v6so94352pga.13; Mon, 17 Sep 2018 17:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CqGMjCUs/uvCGUwiT2aDuH2Habwf0XsqYCKkMi9e1Fg=; b=bwSXywbRDwDbIzMxWPzc/3CTV+SOiWfrH3g4cDrTA/xGXTo5ZJ+8nXRBN2C3r6V6N5 mWFvEim+4O4nmTwJL9TUze3ba9C8jZ/M6RYWwxA+89yuPdCHu7Yk6v5Fg4KobM0s3cMG h5cnjb4DstFGW6reczOzxETqossn5urlwIAGFKF0EiEWljdNqTrNA/pAgsLmC2l/VB5U /4xQA8C41k3eZoP3P9E0rjJDpLmCaXs4w8bo/uNeByNCZiF7/+wwFq+DJ5MSSnjTbOlM zDB+5Qyy0pUgscA1+QnRS7VhuaW4kIjlVFNXlS10KwY+LFme/at8rXsxxibN+PzSou1P G1Zw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=CqGMjCUs/uvCGUwiT2aDuH2Habwf0XsqYCKkMi9e1Fg=; b=LAau34VQOE6HmDOVcSgIIKB3kJnWwIufFhD8Y26eyFZNWxou1P8Nao+u5+flpB9BVb gWEX72wFNNnapiXlmpz43YDjXceWvQ4wzO/5qfRdDYlv9EMTqhnrf9k9NG6JP5pkPuNc Mhh0NI51PZq26QWYgiLaJ4u+0f94R/O8iQd97L61fXlgFT9GpJWRMF+aRuMwhRxWU85e UiOToSjR7nu/fmS0+D+WPDjAQ+jCu5zIKrXc1cSSgK+lT2iIjKsCtfP6GbDyUeJLdnFN Uc+G5aAYe0CiHqEhq7XmbDez42+M7eqyLnj+ZpnfWfXu3XuWzkwT9FDh35f52IS2HBny h+9w== X-Gm-Message-State: APzg51CEQp1Ts8nd+XWMFjdKeGoZavfNSUrIZ/ZjLzRMWzubvxBoLmyX hSBvJe2NKYpqcmG1y1Cj2Rd1tdnF X-Google-Smtp-Source: ANB0VdaEwjF6o+Tv3Umj6ZPXN1Xi/VDfVjYtseoiVDbEF880FSZv7k3ozFISxeaYbvNeJPZQlWJ9Vg== X-Received: by 2002:a63:2106:: with SMTP id h6-v6mr25155554pgh.161.1537231684502; Mon, 17 Sep 2018 17:48:04 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.48.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:48:03 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 19/20] Input: iforce - drop couple of temps from transport code Date: Mon, 17 Sep 2018 17:47:31 -0700 Message-Id: <20180918004732.9875-19-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 Transport initialization code now deals mostly with transport-specific data, so we can drop couple of temporary variables. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-serio.c | 7 ++----- drivers/input/joystick/iforce/iforce-usb.c | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c index 277522d0f324..e7692a38591e 100644 --- a/drivers/input/joystick/iforce/iforce-serio.c +++ b/drivers/input/joystick/iforce/iforce-serio.c @@ -204,16 +204,13 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) { struct iforce_serio *iforce_serio; - struct iforce *iforce; int err; iforce_serio = kzalloc(sizeof(*iforce_serio), GFP_KERNEL); if (!iforce_serio) return -ENOMEM; - iforce = &iforce_serio->iforce; - - iforce->xport_ops = &iforce_serio_xport_ops; + iforce_serio->iforce.xport_ops = &iforce_serio_xport_ops; iforce_serio->serio = serio; serio_set_drvdata(serio, iforce_serio); @@ -222,7 +219,7 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) if (err) goto fail1; - err = iforce_init_device(&serio->dev, BUS_RS232, iforce); + err = iforce_init_device(&serio->dev, BUS_RS232, &iforce_serio->iforce); if (err) goto fail2; diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index ae2dd5b5a416..a1e670781441 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c @@ -208,7 +208,6 @@ static int iforce_usb_probe(struct usb_interface *intf, struct usb_host_interface *interface; struct usb_endpoint_descriptor *epirq, *epout; struct iforce_usb *iforce_usb; - struct iforce *iforce; int err = -ENOMEM; interface = intf->cur_altsetting; @@ -231,9 +230,7 @@ static int iforce_usb_probe(struct usb_interface *intf, if (!iforce_usb->out) goto fail; - iforce = &iforce_usb->iforce; - - iforce->xport_ops = &iforce_usb_xport_ops; + iforce_usb->iforce.xport_ops = &iforce_usb_xport_ops; iforce_usb->usbdev = dev; iforce_usb->intf = intf; @@ -248,7 +245,7 @@ static int iforce_usb_probe(struct usb_interface *intf, iforce_usb->data_out, sizeof(iforce_usb->data_out), iforce_usb_out, iforce_usb, epout->bInterval); - err = iforce_init_device(&intf->dev, BUS_USB, iforce); + err = iforce_init_device(&intf->dev, BUS_USB, &iforce_usb->iforce); if (err) goto fail; From patchwork Tue Sep 18 00:47:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10603589 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 0B7C015E8 for ; Tue, 18 Sep 2018 00:48:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDB572A98B for ; Tue, 18 Sep 2018 00:48:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE84C2A99D; Tue, 18 Sep 2018 00:48:16 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 2CC932A98B for ; Tue, 18 Sep 2018 00:48:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729556AbeIRGSB (ORCPT ); Tue, 18 Sep 2018 02:18:01 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:47033 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729519AbeIRGSA (ORCPT ); Tue, 18 Sep 2018 02:18:00 -0400 Received: by mail-pg1-f196.google.com with SMTP id b129-v6so94380pga.13; Mon, 17 Sep 2018 17:48:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UXrwtXVoYP6FYwFbk7hnJYf0IXCoVIxfi4PArWLBiD4=; b=Z6NCvhRNigWiw13uGK69CU+GOsyJ6JRZEObwgss8AFL912Qf5U9/v8C2jA4e7aPPtp 5P4xAtQaemGRtzRWUTBKcfVbUdpMWvYwhXIAOpWSpc/WzqTB2eUFjIA9UbLXbnjnl3Z0 NUZEye9qAb37MpFso1uLpQuaOqfWiZZpCnRIjKbjrTrN5TTDf1vEf1MbdSsCt98ur0V+ zalJ5LPZU/A6PojKodG11NqIrZewX5DfyKce603eRgcTwx4u58HqoE1keFhJTty78BYf 4l2sp7QtQCSS4NE4H5X9aoEtyKI0NVoF+d2aNKXcgF0V5TVtmXUioUwuT1A3AHh5kj/X NQ+w== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=UXrwtXVoYP6FYwFbk7hnJYf0IXCoVIxfi4PArWLBiD4=; b=b1h/a3jK7bzPWObK2VDmszAkU4b0cv2EjTCK5ohJmqIiyHHK8Z1YX1Vfqmq/FS7JMv +OMlE3km2Wr/2LQXReEy46Mz6Qcb0qTKeCmAJ/K7A7lp+x7ExiwqrBMAZuJf145djf9P ovqpH/ssgHXzRNJKc0UoG6Xut78MjNMVCbVc1fpiqP5zTy6pvgK74O5W3l/9xSx+O6hl +TaMzXJ8DCzxQfQFVBHB5nuz6e52rca+4SHeak0r+X9ZRtetbiplBaUvR0/MsLkuxwtF Yc8oLDsgNpV+xqtz0rubyTr6LaVuDV/+ErRRihOfa3IojCzWJehHidvwhAT1bfZhYJpl MToA== X-Gm-Message-State: APzg51DCSe1UQxLJOUEYeIKaChVxpsDh7ok4jyzyytqqBKeMtzWCIvPu kTxF9gB6Xn/ovq9ysgN2XFW8KHlA X-Google-Smtp-Source: ANB0VdZ0DhUm0ch+CQpWjyWqnQiR8qONN4dC610U1HN47NYz1nvlUjPeE2e5pjxS33NECVdOnypqMA== X-Received: by 2002:a63:f902:: with SMTP id h2-v6mr25541742pgi.154.1537231685874; Mon, 17 Sep 2018 17:48:05 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id w69-v6sm26053316pgd.37.2018.09.17.17.48.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 17:48:04 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Tim Schumacher Cc: linux-kernel@vger.kernel.org Subject: [PATCH 20/20] Input: iforce - use unaligned accessors, where appropriate Date: Mon, 17 Sep 2018 17:47:32 -0700 Message-Id: <20180918004732.9875-20-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918004732.9875-1-dmitry.torokhov@gmail.com> References: <20180918004732.9875-1-dmitry.torokhov@gmail.com> 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 Instead of open-coding conversion from/to little-endian, let's use proper accessors. Signed-off-by: Dmitry Torokhov --- drivers/input/joystick/iforce/iforce-main.c | 7 ++++--- drivers/input/joystick/iforce/iforce-packets.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c index 5cb3e80f4e0d..d696b0b653b6 100644 --- a/drivers/input/joystick/iforce/iforce-main.c +++ b/drivers/input/joystick/iforce/iforce-main.c @@ -21,6 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include "iforce.h" MODULE_AUTHOR("Vojtech Pavlik , Johann Deneux "); @@ -286,17 +287,17 @@ int iforce_init_device(struct device *parent, u16 bustype, */ if (!iforce_get_id_packet(iforce, 'M', buf, &len) || len < 3) - input_dev->id.vendor = (buf[2] << 8) | buf[1]; + input_dev->id.vendor = get_unaligned_le16(buf + 1); else dev_warn(&iforce->dev->dev, "Device does not respond to id packet M\n"); if (!iforce_get_id_packet(iforce, 'P', buf, &len) || len < 3) - input_dev->id.product = (buf[2] << 8) | buf[1]; + input_dev->id.product = get_unaligned_le16(buf + 1); else dev_warn(&iforce->dev->dev, "Device does not respond to id packet P\n"); if (!iforce_get_id_packet(iforce, 'B', buf, &len) || len < 3) - iforce->device_memory.end = (buf[2] << 8) | buf[1]; + iforce->device_memory.end = get_unaligned_le16(buf + 1); else dev_warn(&iforce->dev->dev, "Device does not respond to id packet B\n"); diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c index 976ec1c7cf15..76c4475740ab 100644 --- a/drivers/input/joystick/iforce/iforce-packets.c +++ b/drivers/input/joystick/iforce/iforce-packets.c @@ -21,6 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include "iforce.h" static struct { @@ -175,8 +176,10 @@ void iforce_process_packet(struct iforce *iforce, switch (packet_id) { case 0x01: /* joystick position data */ - input_report_abs(dev, ABS_X, (__s16) (((__s16)data[1] << 8) | data[0])); - input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[3] << 8) | data[2])); + input_report_abs(dev, ABS_X, + (__s16) get_unaligned_le16(data)); + input_report_abs(dev, ABS_Y, + (__s16) get_unaligned_le16(data + 2)); input_report_abs(dev, ABS_THROTTLE, 255 - data[4]); if (len >= 8 && test_bit(ABS_RUDDER ,dev->absbit)) @@ -188,7 +191,8 @@ void iforce_process_packet(struct iforce *iforce, break; case 0x03: /* wheel position data */ - input_report_abs(dev, ABS_WHEEL, (__s16) (((__s16)data[1] << 8) | data[0])); + input_report_abs(dev, ABS_WHEEL, + (__s16) get_unaligned_le16(data)); input_report_abs(dev, ABS_GAS, 255 - data[2]); input_report_abs(dev, ABS_BRAKE, 255 - data[3]); @@ -214,7 +218,7 @@ void iforce_process_packet(struct iforce *iforce, } for (j = 3; j < len; j += 2) - mark_core_as_ready(iforce, data[j] | (data[j + 1] << 8)); + mark_core_as_ready(iforce, get_unaligned_le16(data + j)); break; }