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: 644249 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rjrj76zhxz9sR8 for ; Tue, 5 Jul 2016 01:36:43 +1000 (AEST) 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-Spam-Score: -3.3 (---) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-3.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -1.4 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel@pengutronix.de 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 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); }