From patchwork Wed Feb 26 16:19:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 3725951 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B3E8ABF13A for ; Wed, 26 Feb 2014 16:24:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A6ABA201BA for ; Wed, 26 Feb 2014 16:24:23 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 97B7E2018E for ; Wed, 26 Feb 2014 16:24:22 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WIhFn-0001kD-72; Wed, 26 Feb 2014 16:22:41 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WIhFK-0005eA-K7; Wed, 26 Feb 2014 16:22:10 +0000 Received: from mail-we0-x22e.google.com ([2a00:1450:400c:c03::22e]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WIhEQ-0005X2-9V for linux-arm-kernel@lists.infradead.org; Wed, 26 Feb 2014 16:21:16 +0000 Received: by mail-we0-f174.google.com with SMTP id t60so449717wes.19 for ; Wed, 26 Feb 2014 08:20:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=S/a49AWNsHkLHCin4IzQHxIgXtuPN1GFQBN3rolFSo8=; b=Iby9I4NgrBHLKqGSypK6JIbVva675a5jrNUTG1ZCQGOU/0Bk/NwOLswJNDMsJ6i+kM dJZ0YX4PdcRiz53/jD6vfugv6MNLiE6PpeRh4hsB35gMb4yK6XpBA7lOSG79Tb6vAzKb FZDKT/88kpysQwL8ley6qOhWjUJugRQCSC52I0gaPDKiMaZAwjcKcuk9gBh6eZp1zPxg IxZR6y0ai/xBqBnSu5Ifiy1AYyO2VAsGfltIPbobiEgHNUHohlFPbS2H9I8vTmsQ1tzv Vwqw8nRHYcTfQBkSdC+c13UGMRBwZIeDIOOWF0JZmSyFmKJt7bShOvrvecQbXYJ1qD80 Wlzw== X-Received: by 10.180.149.206 with SMTP id uc14mr8788997wib.10.1393431651419; Wed, 26 Feb 2014 08:20:51 -0800 (PST) Received: from lnx-rg.pr (lyon.paratronic.fr. [213.41.177.106]) by mx.google.com with ESMTPSA id xt1sm3724941wjb.17.2014.02.26.08.20.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Feb 2014 08:20:50 -0800 (PST) From: Richard Genoud To: Greg Kroah-Hartman Subject: [PATCH v4 5/5] tty/serial: at91: add interrupts for modem control lines Date: Wed, 26 Feb 2014 17:19:48 +0100 Message-Id: <1393431588-25977-6-git-send-email-richard.genoud@gmail.com> X-Mailer: git-send-email 1.8.5 In-Reply-To: <1393431588-25977-1-git-send-email-richard.genoud@gmail.com> References: <1393431588-25977-1-git-send-email-richard.genoud@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140226_112114_589771_8F288F76 X-CRM114-Status: GOOD ( 17.57 ) X-Spam-Score: -2.0 (--) Cc: Alexander Shiyan , Richard Genoud , Linus Walleij , Nicolas Ferre , linux-serial@vger.kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Handle CTS/DSR/RI/DCD GPIO interrupts in atmel_serial. Signed-off-by: Richard Genoud --- drivers/tty/serial/atmel_serial.c | 129 +++++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index d7d873c1a1d0..779501db72ff 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -167,7 +168,9 @@ struct atmel_uart_port { struct serial_rs485 rs485; /* rs485 settings */ struct mctrl_gpios *gpios; + int gpio_irq[UART_GPIO_MAX]; unsigned int tx_done_mask; + bool ms_irq_enabled; bool is_usart; /* usart or uart */ struct timer_list uart_timer; /* uart timer */ int (*prepare_rx)(struct uart_port *port); @@ -489,8 +492,38 @@ static void atmel_stop_rx(struct uart_port *port) */ static void atmel_enable_ms(struct uart_port *port) { - UART_PUT_IER(port, ATMEL_US_RIIC | ATMEL_US_DSRIC - | ATMEL_US_DCDIC | ATMEL_US_CTSIC); + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); + uint32_t ier = 0; + + /* + * Interrupt should not be enabled twice + */ + if (atmel_port->ms_irq_enabled) + return; + + atmel_port->ms_irq_enabled = true; + + if (atmel_port->gpio_irq[UART_GPIO_CTS] >= 0) + enable_irq(atmel_port->gpio_irq[UART_GPIO_CTS]); + else + ier |= ATMEL_US_CTSIC; + + if (atmel_port->gpio_irq[UART_GPIO_DSR] >= 0) + enable_irq(atmel_port->gpio_irq[UART_GPIO_DSR]); + else + ier |= ATMEL_US_DSRIC; + + if (atmel_port->gpio_irq[UART_GPIO_RI] >= 0) + enable_irq(atmel_port->gpio_irq[UART_GPIO_RI]); + else + ier |= ATMEL_US_RIIC; + + if (atmel_port->gpio_irq[UART_GPIO_DCD] >= 0) + enable_irq(atmel_port->gpio_irq[UART_GPIO_DCD]); + else + ier |= ATMEL_US_DCDIC; + + UART_PUT_IER(port, ier); } /* @@ -1079,11 +1112,35 @@ atmel_handle_status(struct uart_port *port, unsigned int pending, static irqreturn_t atmel_interrupt(int irq, void *dev_id) { struct uart_port *port = dev_id; + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); unsigned int status, pending, pass_counter = 0; + bool gpio_handled = false; do { status = atmel_get_lines_status(port); pending = status & UART_GET_IMR(port); + if (!gpio_handled) { + /* + * Dealing with GPIO interrupt + */ + if ((irq >= 0) && + (irq == atmel_port->gpio_irq[UART_GPIO_CTS])) + pending |= ATMEL_US_CTSIC; + + if ((irq >= 0) && + (irq == atmel_port->gpio_irq[UART_GPIO_DSR])) + pending |= ATMEL_US_DSRIC; + + if ((irq >= 0) && + (irq == atmel_port->gpio_irq[UART_GPIO_RI])) + pending |= ATMEL_US_RIIC; + + if ((irq >= 0) && + (irq == atmel_port->gpio_irq[UART_GPIO_DCD])) + pending |= ATMEL_US_DCDIC; + + gpio_handled = true; + } if (!pending) break; @@ -1563,6 +1620,45 @@ static void atmel_get_ip_name(struct uart_port *port) } } +static void atmel_free_gpio_irq(struct uart_port *port) +{ + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); + enum mctrl_gpio_idx i; + + for (i = 0; i < UART_GPIO_MAX; i++) + if (atmel_port->gpio_irq[i] >= 0) + free_irq(atmel_port->gpio_irq[i], port); +} + +static int atmel_request_gpio_irq(struct uart_port *port) +{ + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); + int *irq = atmel_port->gpio_irq; + enum mctrl_gpio_idx i; + int err = 0; + + for (i = 0; (i < UART_GPIO_MAX) && !err; i++) { + if (irq[i] < 0) + continue; + + irq_set_status_flags(irq[i], IRQ_NOAUTOEN); + err = request_irq(irq[i], atmel_interrupt, IRQ_TYPE_EDGE_BOTH, + "atmel_serial", port); + if (err) + dev_err(port->dev, "atmel_startup - Can't get %d irq\n", + irq[i]); + } + + /* + * If something went wrong, rollback. + */ + while (err && --i) + if (irq[i] >= 0) + free_irq(irq[i], port); + + return err; +} + /* * Perform initialization and enable port for reception */ @@ -1579,6 +1675,7 @@ static int atmel_startup(struct uart_port *port) * handle an unexpected interrupt */ UART_PUT_IDR(port, -1); + atmel_port->ms_irq_enabled = false; /* * Allocate the IRQ @@ -1591,6 +1688,13 @@ static int atmel_startup(struct uart_port *port) } /* + * Get the GPIO lines IRQ + */ + retval = atmel_request_gpio_irq(port); + if (retval) + goto free_irq; + + /* * Initialize DMA (if necessary) */ atmel_init_property(atmel_port, pdev); @@ -1654,6 +1758,11 @@ static int atmel_startup(struct uart_port *port) } return 0; + +free_irq: + free_irq(port->irq, port); + + return retval; } /* @@ -1701,9 +1810,12 @@ static void atmel_shutdown(struct uart_port *port) atmel_port->rx_ring.tail = 0; /* - * Free the interrupt + * Free the interrupts */ free_irq(port->irq, port); + atmel_free_gpio_irq(port); + + atmel_port->ms_irq_enabled = false; } /* @@ -2366,12 +2478,23 @@ static int atmel_serial_resume(struct platform_device *pdev) static int atmel_init_gpios(struct atmel_uart_port *p, struct device *dev) { + enum mctrl_gpio_idx i; + struct gpio_desc *gpiod; int err = 0; p->gpios = mctrl_gpio_init(dev, 0); if (IS_ERR_OR_NULL(p->gpios)) err = PTR_ERR(p->gpios); + for (i = 0; i < UART_GPIO_MAX; i++) { + gpiod = mctrl_gpio_to_gpiod(p->gpios, i); + if (!IS_ERR_OR_NULL(gpiod) && + (gpiod_get_direction(gpiod) == GPIOF_DIR_IN)) + p->gpio_irq[i] = gpiod_to_irq(gpiod); + else + p->gpio_irq[i] = -EINVAL; + } + return err; }