From patchwork Mon Jul 4 15:34:12 2016 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: 9212885 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 CD89660572 for ; Mon, 4 Jul 2016 15:36:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF0E42873C for ; Mon, 4 Jul 2016 15:36:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3CC928741; Mon, 4 Jul 2016 15:36: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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 324B82873C for ; Mon, 4 Jul 2016 15:36:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bK5tS-0003dk-Gj; Mon, 04 Jul 2016 15:34:42 +0000 Received: from arcturus.kleine-koenig.org ([78.47.169.190]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bK5tP-0003S6-Bh for linux-arm-kernel@lists.infradead.org; Mon, 04 Jul 2016 15:34:40 +0000 Received: by arcturus.kleine-koenig.org (Postfix, from userid 1000) id A6115AF835; Mon, 4 Jul 2016 17:34:14 +0200 (CEST) From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org Subject: [PATCH] serial: imx: add rx and tx led trigger Date: Mon, 4 Jul 2016 17:34:12 +0200 Message-Id: <1467646452-21243-1-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160704_083439_717458_FE075ACF X-CRM114-Status: GOOD ( 11.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel@pengutronix.de Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for two led triggers per UART instance that blink on transmission and reception of data respectively. Signed-off-by: Uwe Kleine-König --- drivers/tty/serial/imx.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 621e488cbb12..2b6ba3b8bdd5 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -227,6 +228,8 @@ struct imx_port { wait_queue_head_t dma_wait; unsigned int saved_reg[10]; bool context_saved; + struct led_trigger led_trigger_rx; + struct led_trigger led_trigger_tx; }; struct imx_port_ucrs { @@ -293,6 +296,10 @@ static inline int is_imx6q_uart(struct imx_port *sport) { return sport->devdata->devtype == IMX6Q_UART; } + +static unsigned long led_delay = 50; +module_param(led_delay, ulong, 0644); + /* * Save and restore functions for UCR1, UCR2 and UCR3 registers */ @@ -426,6 +433,9 @@ static inline void imx_transmit_buffer(struct imx_port *sport) return; } + led_trigger_blink_oneshot(&sport->led_trigger_tx, + &led_delay, &led_delay, 1); + if (sport->dma_is_enabled) { /* * We've just sent a X-char Ensure the TX DMA is enabled @@ -635,6 +645,9 @@ static irqreturn_t imx_rxint(int irq, void *dev_id) struct tty_port *port = &sport->port.state->port; unsigned long flags, temp; + led_trigger_blink_oneshot(&sport->led_trigger_rx, + &led_delay, &led_delay, 1); + spin_lock_irqsave(&sport->port.lock, flags); while (readl(sport->port.membase + USR2) & USR2_RDR) { @@ -708,6 +721,9 @@ static void imx_dma_rxint(struct imx_port *sport) unsigned long temp; unsigned long flags; + led_trigger_blink_oneshot(&sport->led_trigger_rx, + &led_delay, &led_delay, 1); + spin_lock_irqsave(&sport->port.lock, flags); temp = readl(sport->port.membase + USR2); @@ -2002,6 +2018,42 @@ static void serial_imx_probe_pdata(struct imx_port *sport, sport->have_rtscts = 1; } +static void imx_register_led_trigger(struct device *dev, struct imx_port *sport) +{ +#ifdef CONFIG_LEDS_TRIGGERS + int ret; + char *name; + + name = devm_kasprintf(dev, GFP_KERNEL, "ttymxc%d-rx|ttymxc%d-tx", + sport->port.line, sport->port.line); + if (!name) { + dev_warn(dev, "failed to allocate led trigger name\n"); + return; + } + + sport->led_trigger_rx.name = name; + + name = strchr(name, '|'); + *name = '\0'; + + sport->led_trigger_tx.name = name + 1; + + ret = led_trigger_register(&sport->led_trigger_rx); + if (ret) { + dev_warn(dev, "failed to register rx led trigger\n"); + goto err_register_rx; + } + + ret = led_trigger_register(&sport->led_trigger_tx); + if (ret) { + dev_warn(dev, "failed to register tx led trigger\n"); + led_trigger_unregister(&sport->led_trigger_rx); +err_register_rx: + devm_kfree(dev, name); + } +#endif +} + static int serial_imx_probe(struct platform_device *pdev) { struct imx_port *sport; @@ -2065,6 +2117,8 @@ static int serial_imx_probe(struct platform_device *pdev) sport->port.uartclk = clk_get_rate(sport->clk_per); + imx_register_led_trigger(&pdev->dev, sport); + /* For register access, we only need to enable the ipg clock. */ ret = clk_prepare_enable(sport->clk_ipg); if (ret) @@ -2110,6 +2164,9 @@ static int serial_imx_remove(struct platform_device *pdev) { struct imx_port *sport = platform_get_drvdata(pdev); +#ifdef CONFIG_LEDS_TRIGGERS + led_trigger_unregister(&sport->led_trigger_rx); +#endif return uart_remove_one_port(&imx_reg, &sport->port); }