From patchwork Sun Jul 10 16:44:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12912579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 897A0C43334 for ; Sun, 10 Jul 2022 16:47:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UUOViPMMkmYXywm0dhbkpdc0sPz2y+Z+APlydG/+k4s=; b=VAWJvlzxEFm86I gu+dLUvXRWgtOHC5MPhJtJ0Ve3BQ2DYkCK8e35LhX3tOqrvV3w4kdj4zWPJLDEndPo5TIBUFxXNMD U9I4ARIY2bVyajhQueKxkcKddqSxyHnmQ1PUy2qKhkpai7+CM9shMIJQvqI7j/2RE0ig5EKSuOM68 QvFIMRLtDXP7T/r2h+3NP7QliFgcRUaJtSL5SEUNmyhVmq4RIouES3RS42vJGNwBxtYzHNtBOrGxx 8wA+3OEkkQbIYdEU5oXeTjrXG2tu8b+r647I2HDmsZA0cxVJsW2C6qHDX9Jf/67oVEpKKH9tUYDI5 8DZQUyNsrvP3ESGLhRlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAa4o-00CXwf-5m; Sun, 10 Jul 2022 16:46:34 +0000 Received: from mout.gmx.net ([212.227.17.20]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAa3P-00CXCT-FW for linux-arm-kernel@lists.infradead.org; Sun, 10 Jul 2022 16:45:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1657471496; bh=r9kQ+eb8XdjZm2Ia2YL2lmH1Q4foW6xhwQY0wLK1kO0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Q+2VyhytvwOF/Ho43AS3sCGevrGN3OZMunGLb3xBpMl48zX/xQiNocBP1h11IBHbr YMO0M2doffF0EYPv5dn5oyXeWdmwpLpmNthrkyUlP6J0cEetzyz2xQZ97rpOMd6LAU d2n/dFbopqmN093Ux//1k2vRYZlLKtCm8NtjNvGo= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.243]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MHoNC-1oONqA1uYY-00Eu3u; Sun, 10 Jul 2022 18:44:56 +0200 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: ilpo.jarvinen@linux.intel.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, vz@mleia.com, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, lukas@wunner.de, p.rosenberger@kunbus.com, Lino Sanfilippo Subject: [PATCH v4 3/8] serial: core, 8250: set RS485 termination GPIO in serial core Date: Sun, 10 Jul 2022 18:44:37 +0200 Message-Id: <20220710164442.2958979-4-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220710164442.2958979-1-LinoSanfilippo@gmx.de> References: <20220710164442.2958979-1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l8GZItODXlI9+6RrzKccLDwAqkw3Vq9v3o3CEytAtkT2xe6+j Ni1HrE8dbHrrA7ts7whPh0AbK8i9uwu6zgpnYhM2OJKqMPUSZ8xbp4GWV0SeDTcRhOIziOiuY dnH8PgTurz8tyI4TeyXgHDWiB2pMerIKmiZpLVeyIYhVBCesXCO7XjeD0LOeyvlsYzcQW78gc JUVUsyQQmO6BZiUtlbkabCvyoR5i1rUaC8oVhcIkOyJJnuAPAyneU9zzaYZboGtpZDHCWlemM hhKY6RO4OJ2ez5iwS6GvqQ9wiylSkfSgfYz/f3dU9NzTZKy1ICjqWm3HZHYh3gvl1wqoD35Ba 9LJM8Xiv1CXhoO2Ls8FDpMyvX+A7wDcNfDRy23pWQO0rIcaBrQYEItUdA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220710_094508_230016_E3EA4EB1 X-CRM114-Status: GOOD ( 14.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Lino Sanfilippo In serial8250_em485_config() the termination GPIO is set with the uart_port spinlock held. This is an issue if setting the GPIO line can sleep (e.g. since the concerning GPIO expander is connected via SPI or I2C). Fix this by setting the termination line outside of the uart_port spinlock in the serial core and using gpiod_set_value_cansleep() which instead of gpiod_set_value() allows it to sleep. Beside fixing the termination GPIO line setting for the 8250 driver this change also makes setting the termination GPIO generic for all UART drivers. Signed-off-by: Lino Sanfilippo --- drivers/tty/serial/8250/8250_port.c | 3 --- drivers/tty/serial/serial_core.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index ed2a606f2da7..72252d956f17 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -676,9 +676,6 @@ int serial8250_em485_config(struct uart_port *port, struct ktermios *termios, rs485->flags &= ~SER_RS485_RTS_AFTER_SEND; } - gpiod_set_value(port->rs485_term_gpio, - rs485->flags & SER_RS485_TERMINATE_BUS); - /* * Both serial8250_em485_init() and serial8250_em485_destroy() * are idempotent. diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 1db44cde76f6..047ec51dbd41 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1358,12 +1358,23 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4 memset(rs485->padding1, 0, sizeof(rs485->padding1)); } +static void uart_set_rs485_termination(struct uart_port *port, + const struct serial_rs485 *rs485) +{ + if (!(rs485->flags & SER_RS485_ENABLED)) + return; + + gpiod_set_value_cansleep(port->rs485_term_gpio, + !!(rs485->flags & SER_RS485_TERMINATE_BUS)); +} + int uart_rs485_config(struct uart_port *port) { struct serial_rs485 *rs485 = &port->rs485; int ret; uart_sanitize_serial_rs485(port, rs485); + uart_set_rs485_termination(port, rs485); ret = port->rs485_config(port, NULL, rs485); if (ret) @@ -1406,6 +1417,7 @@ static int uart_set_rs485_config(struct tty_struct *tty, struct uart_port *port, if (ret) return ret; uart_sanitize_serial_rs485(port, &rs485); + uart_set_rs485_termination(port, &rs485); spin_lock_irqsave(&port->lock, flags); ret = port->rs485_config(port, &tty->termios, &rs485);