From patchwork Mon Apr 30 09:03:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Engraf X-Patchwork-Id: 10371157 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0601F60234 for ; Mon, 30 Apr 2018 09:10:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBF32289A6 for ; Mon, 30 Apr 2018 09:10:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E07EC289AD; Mon, 30 Apr 2018 09:10:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A395289AB for ; Mon, 30 Apr 2018 09:10:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752389AbeD3JKq (ORCPT ); Mon, 30 Apr 2018 05:10:46 -0400 Received: from mail.sysgo.com ([176.9.12.79]:36464 "EHLO mail.sysgo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752099AbeD3JKq (ORCPT ); Mon, 30 Apr 2018 05:10:46 -0400 X-Greylist: delayed 406 seconds by postgrey-1.27 at vger.kernel.org; Mon, 30 Apr 2018 05:10:46 EDT From: David Engraf To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, David Engraf Subject: [PATCH] Input: serio - add writing multiple bytes at once Date: Mon, 30 Apr 2018 11:03:24 +0200 Message-Id: <20180430090324.30845-1-david.engraf@sysgo.com> X-Mailer: git-send-email 2.14.1 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 current version only supports forwarding a single byte to the tty layer. This patch adds serio_write_length() to allow a serport driver writing multiple bytes at once. The patch also includes a fallback to serio_write_length() when a driver did not register a single byte function. Signed-off-by: David Engraf --- drivers/input/serio/serport.c | 7 ++++--- include/linux/serio.h | 13 ++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c index f8ead9f9c77e..209343f636a3 100644 --- a/drivers/input/serio/serport.c +++ b/drivers/input/serio/serport.c @@ -45,10 +45,11 @@ struct serport { * Callback functions from the serio code. */ -static int serport_serio_write(struct serio *serio, unsigned char data) +static int serport_serio_write_length(struct serio *serio, + const unsigned char *data, int count) { struct serport *serport = serio->port_data; - return -(serport->tty->ops->write(serport->tty, &data, 1) != 1); + return -(serport->tty->ops->write(serport->tty, data, count) != count); } static int serport_serio_open(struct serio *serio) @@ -176,7 +177,7 @@ static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file, u snprintf(serio->phys, sizeof(serio->phys), "%s/serio0", tty_name(tty)); serio->id = serport->id; serio->id.type = SERIO_RS232; - serio->write = serport_serio_write; + serio->write_length = serport_serio_write_length; serio->open = serport_serio_open; serio->close = serport_serio_close; serio->port_data = serport; diff --git a/include/linux/serio.h b/include/linux/serio.h index 138a5efe863a..6f5cb92d0f22 100644 --- a/include/linux/serio.h +++ b/include/linux/serio.h @@ -35,6 +35,8 @@ struct serio { spinlock_t lock; int (*write)(struct serio *, unsigned char); + int (*write_length)(struct serio *serio, const unsigned char *data, + int count); int (*open)(struct serio *); void (*close)(struct serio *); int (*start)(struct serio *); @@ -122,12 +124,21 @@ void serio_unregister_driver(struct serio_driver *drv); module_driver(__serio_driver, serio_register_driver, \ serio_unregister_driver) +static inline int serio_write_length(struct serio *serio, + const unsigned char *data, int count) +{ + if (serio->write_length) + return serio->write_length(serio, data, count); + else + return -1; +} + static inline int serio_write(struct serio *serio, unsigned char data) { if (serio->write) return serio->write(serio, data); else - return -1; + return serio_write_length(serio, &data, 1); } static inline void serio_drv_write_wakeup(struct serio *serio)