From patchwork Thu May 3 10:04:48 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: 907947 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="CauuaxHD"; 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 40c9kv69HNz9s37 for ; Thu, 3 May 2018 20:05:43 +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: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:In-Reply-To:References: List-Owner; bh=PE0Y2a9dCGd6ctz3eKBZzfSxb8IuHIJIBuUNm/TUIz8=; b=CauuaxHDHnSa2u 2SENzdWYZjXpKI+gCGKe3ly59R5Wl71mT5x7sVaad0G30Tv4Fr58/+Pbuo0kTJg1w+v3vFQ9RYZk/ t1S8Ih58xCMBzN+W03HdF0ju6GTKPaUKlPo2ZyYker/rbqEtMYIfvaSVYEXMxioNlE7ItfWgSyPDy in1OW77AldTTfyL3KvsYaPB6Mi/hzpZMGAi2IwJko58/bbyCBd5r2cCpZwcZC33M6EjS/RF3iVCpr hWoYJyp/sjjMFbf5vS6lsseAR3xzamxx/UWtqyklh+c9isn6LoIHDPBTbOLYmb3L6Qo8YzA4EgAd5 qpMhfC1vJ3ERQwN6+5Hg==; 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 1fEB7J-0000S9-Hr; Thu, 03 May 2018 10:05:37 +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 1fEB72-0007qL-Px for linux-arm-kernel@lists.infradead.org; Thu, 03 May 2018 10:05:23 +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 1fEB6m-0003Rw-7J; Thu, 03 May 2018 12:05:04 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1fEB6k-0007zV-LC; Thu, 03 May 2018 12:05:02 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: linux-serial@vger.kernel.org Subject: [PATCH] tty: implement a rx led trigger Date: Thu, 3 May 2018 12:04:48 +0200 Message-Id: <20180503100448.1350-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.17.0 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_030521_104075_CF455343 X-CRM114-Status: GOOD ( 18.37 ) 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 , Pavel Machek , Mathieu Poirier , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, kernel@pengutronix.de, 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 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. Signed-off-by: Uwe Kleine-König --- Hello, this is actually v2 of the series "serial: Add LED trigger support" that Sascha sent in November 2016. For now this is only the RX part however that I'd like to use as a base to get feedback. Once we got to an acceptable change the TX part should be easy (once the right place to place the trigger is clear). Other than that the trigger moved from a dedicated function in serial_core that each driver is supposed to call on reception of data to flush_to_ldisc(). Best regards Uwe drivers/tty/tty_buffer.c | 4 ++++ drivers/tty/tty_port.c | 16 ++++++++++++++++ include/linux/tty.h | 3 +++ 3 files changed, 23 insertions(+) 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_port.c b/drivers/tty/tty_port.c index 25d736880013..51b78a585417 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,18 @@ struct device *tty_port_register_device_attr_serdev(struct tty_port *port, tty_port_link_device(port, driver, index); + port->led_trigger_rx_name = kasprintf(GFP_KERNEL, "%s%d-rx", + driver->name, index); + if (!port->led_trigger_rx_name) { + pr_err("Failed to allocate trigger name for %s%d\n", + driver->name, index); + goto skip_trigger; + } + + led_trigger_register_simple(port->led_trigger_rx_name, + &port->led_trigger_rx); + +skip_trigger: 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 +219,9 @@ void tty_port_unregister_device(struct tty_port *port, if (ret == 0) return; + led_trigger_unregister_simple(port->led_trigger_rx); + kfree(port->led_trigger_rx_name); + 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..7e36ee1d2056 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -249,6 +249,9 @@ struct tty_port { set to size of fifo */ struct kref kref; /* Ref counter */ void *client_data; + + struct led_trigger *led_trigger_rx; + char *led_trigger_rx_name; }; /* tty_port::iflags bits -- use atomic bit ops */