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);