From patchwork Thu May 3 20:19:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 908264 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ka3vlZ4L"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40cRNM0pMqz9s2t for ; Fri, 4 May 2018 06:20:35 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sJZxCeLej9mpDT1kC6Z9yOdTYZgmzC1pmArdwuCr44g=; b=ka3vlZ4Leh+Q3C UFgO76AkD4m9WyjiprfVzIzv1/+6DZ07V4dDSe4gXoz5uixzOQsBfWXrWb5YyJqJxDhtgqv85Ylrl CjMPkucXt65PzL/Jj7liPW8L1miqs+xjaqCvm4nmGEQ9THCBPUK7B5d8pDQoYfKaXZrilf6HP5XtC mOwUSJzAffTdhkjmuseocgI2aMJd2xMHzH7I7MuH59Kb9/aA/yqfTAIjVRs6JzPUG4vbBRoPiqPhu E1YcjfWEizuQaEzCd4Eneej3CCeU7oPweJ3JX5ckDuAOOesy//qHQsnx4orXhRoZtTMWKmG+5gItj CaDgbT6uFTJva+xacUVw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fEKiN-0007qw-BX; Thu, 03 May 2018 20:20:31 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fEKiF-0007JA-BF for linux-arm-kernel@lists.infradead.org; Thu, 03 May 2018 20:20:25 +0000 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fEKhz-0006kK-SO; Thu, 03 May 2018 22:20:07 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1fEKhu-00019w-F9; Thu, 03 May 2018 22:20:02 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: linux-serial@vger.kernel.org Subject: [PATCH v2] tty: implement led triggers Date: Thu, 3 May 2018 22:19:52 +0200 Message-Id: <20180503201952.16592-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <0c1bb915-bd92-4433-61ec-78fdba453396@arm.com> References: <0c1bb915-bd92-4433-61ec-78fdba453396@arm.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180503_132023_586724_E8DD7EAB X-CRM114-Status: GOOD ( 19.23 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2001:67c:670:201:290:27ff:fe1d:cc33 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: One Thousand Gnomes , Florian Fainelli , kernel@pengutronix.de, Mathieu Poirier , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Pavel Machek , Robin Murphy , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org The rx trigger fires when data is pushed to the ldisc. This is a bit later than the actual receiving of data but has the nice benefit that it doesn't need adaption for each driver and isn't in the hot path. Similarily the tx trigger fires when data taken from the ldisc. Signed-off-by: Uwe Kleine-König --- Changes since v1, sent with Message-Id: 20180503100448.1350-1-u.kleine-koenig@pengutronix.de: - implement tx trigger; - introduce Kconfig symbol for conditional compilation; - set trigger to NULL if allocating the name failed to not free random pointers in case the port struct wasn't zeroed; - use if/else instead of goto drivers/tty/Kconfig | 7 +++++++ drivers/tty/tty_buffer.c | 4 ++++ drivers/tty/tty_io.c | 6 ++++++ drivers/tty/tty_port.c | 32 ++++++++++++++++++++++++++++++++ include/linux/tty.h | 7 +++++++ 5 files changed, 56 insertions(+) diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig index 0840d27381ea..07a2fb05439f 100644 --- a/drivers/tty/Kconfig +++ b/drivers/tty/Kconfig @@ -41,6 +41,13 @@ config VT If unsure, say Y, or else you won't be able to do much with your new shiny Linux system :-) +config TTY_LEDS_TRIGGER + bool "Enable support for TTY actions making LEDs blink" + depends on LEDS_TRIGGERS + ---help--- + This enable support for tty triggers. It provides two LED triggers + (rx and tx) for each TTY. + config CONSOLE_TRANSLATIONS depends on VT default y diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c index c996b6859c5e..4d364b77b1a7 100644 --- a/drivers/tty/tty_buffer.c +++ b/drivers/tty/tty_buffer.c @@ -17,6 +17,7 @@ #include #include #include +#include #define MIN_TTYB_SIZE 256 @@ -499,6 +500,7 @@ static void flush_to_ldisc(struct work_struct *work) struct tty_buffer *head = buf->head; struct tty_buffer *next; int count; + unsigned long delay = 50 /* ms */; /* Ldisc or user is trying to gain exclusive access */ if (atomic_read(&buf->priority)) @@ -521,6 +523,8 @@ static void flush_to_ldisc(struct work_struct *work) continue; } + led_trigger_blink_oneshot(port->led_trigger_rx, &delay, &delay, 0); + count = receive_buf(port, head, count); if (!count) break; diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 7c838b90a31d..2c840f1e1e82 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -83,6 +83,7 @@ #include #include #include +#include #include #include #include @@ -950,11 +951,16 @@ static inline ssize_t do_tty_write( /* Do the write .. */ for (;;) { size_t size = count; + unsigned long delay = 50 /* ms */; + if (size > chunk) size = chunk; ret = -EFAULT; if (copy_from_user(tty->write_buf, buf, size)) break; + + led_trigger_blink_oneshot(tty->port->led_trigger_tx, &delay, &delay, 0); + ret = write(tty, file, tty->write_buf, size); if (ret <= 0) break; diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c index 25d736880013..f042879a597c 100644 --- a/drivers/tty/tty_port.c +++ b/drivers/tty/tty_port.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -157,6 +158,30 @@ struct device *tty_port_register_device_attr_serdev(struct tty_port *port, tty_port_link_device(port, driver, index); +#ifdef CONFIG_TTY_LEDS_TRIGGER + port->led_trigger_rx_name = kasprintf(GFP_KERNEL, "%s%d-rx", + driver->name, index); + if (port->led_trigger_rx_name) { + led_trigger_register_simple(port->led_trigger_rx_name, + &port->led_trigger_rx); + } else { + port->led_trigger_rx = NULL; + pr_err("Failed to allocate trigger name for %s%d\n", + driver->name, index); + } + + port->led_trigger_tx_name = kasprintf(GFP_KERNEL, "%s%d-tx", + driver->name, index); + if (port->led_trigger_tx_name) { + led_trigger_register_simple(port->led_trigger_tx_name, + &port->led_trigger_tx); + } else { + port->led_trigger_tx = NULL; + pr_err("Failed to allocate trigger name for %s%d\n", + driver->name, index); + } +#endif + dev = serdev_tty_port_register(port, device, driver, index); if (PTR_ERR(dev) != -ENODEV) { /* Skip creating cdev if we registered a serdev device */ @@ -206,6 +231,13 @@ void tty_port_unregister_device(struct tty_port *port, if (ret == 0) return; +#ifdef CONFIG_TTY_LEDS_TRIGGER + led_trigger_unregister_simple(port->led_trigger_rx); + kfree(port->led_trigger_rx_name); + led_trigger_unregister_simple(port->led_trigger_tx); + kfree(port->led_trigger_tx_name); +#endif + tty_unregister_device(driver, index); } EXPORT_SYMBOL_GPL(tty_port_unregister_device); diff --git a/include/linux/tty.h b/include/linux/tty.h index 1dd587ba6d88..b7dc957365b6 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -249,6 +249,13 @@ struct tty_port { set to size of fifo */ struct kref kref; /* Ref counter */ void *client_data; + +#ifdef CONFIG_TTY_LEDS_TRIGGER + struct led_trigger *led_trigger_rx; + char *led_trigger_rx_name; + struct led_trigger *led_trigger_tx; + char *led_trigger_tx_name; +#endif }; /* tty_port::iflags bits -- use atomic bit ops */