From patchwork Wed Jun 22 15:46:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 584137 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28414CCA486 for ; Wed, 22 Jun 2022 15:47:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359573AbiFVPr5 (ORCPT ); Wed, 22 Jun 2022 11:47:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359503AbiFVPrq (ORCPT ); Wed, 22 Jun 2022 11:47:46 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91E933C4AE; Wed, 22 Jun 2022 08:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1655912840; bh=ng3CY5sBLo9HzL9eQ6cr+vyMggjXbLYmrX0EBHYnCIE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=hxE6QMAWXz8YpSwjcicr3QOu28G1YDOM0vvGeIpeGDRQ3TkpGCJZxqvrLmOX8oIEU DIzVsoSlu+uP/XDoIeMqVIcm0kWq31QAngdg8EPZPRSOgSE4mVE6pPjVgWHeFTAbvP +pWdS4EK36cll96Ze7Z3lbTmVJBDmYN5NcCU44Us= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.22]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MpDJd-1nKCVr0uzP-00qlEB; Wed, 22 Jun 2022 17:47:20 +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 2/8] serial: core, 8250: set RS485 termination gpio in serial core Date: Wed, 22 Jun 2022 17:46:53 +0200 Message-Id: <20220622154659.8710-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220622154659.8710-1-LinoSanfilippo@gmx.de> References: <20220622154659.8710-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:cmEZCvLPWTj25EBlWIAqA2P+RVwRJduESTOZ6QXNayL1PnA2PFD 0AYCcgcDpyZyU1uKG7YhQ++CwAbtQV9walYKTr0oUVIw1H6X+yxQ+klCIsAfKRbGDmJwiy7 PM71d0xXn5O472U+OsJHEVvVqwUapk9CxxdVgZHJ/me28HSLuCrmcg6R3RJPEUbMRbPF/3o vPQXt2ygjo0IVkr3v+bvg== X-UI-Out-Filterresults: notjunk:1;V03:K0:5DQqlhHqeBQ=:NL07DEelmlp2U6m+kzaU9M tPEfKRnlZrnoQk3PwrBtsZwwCP2O2E4mG9RB/PI5VFjpbOxwo4wEuOo47ORqcJGS+QwMpevKw X7ah1Xc6qakmoFb9kaPpXO81Ko1adePtnz/o+8uOJfiH4dlTrWgLh/q+U/AAYZDHQhjeqv4X2 Jh22L5o1iBU5zEbt1wlFL2Hse1wxsi3Fqg7WacHlaWE8J9d6sVezzedskcI88qOzdieEwAnIZ X+V0mA3ECAvTf+qt9OKxAyaHcs0I5l6r25kvzkabyAuJ2gFbOmf8AfdjqNJVAT2EpPITBUI0v ZfAoLaHKOZpRzPduNFWT/e7iubchvJVXItYBjPbq9J76YYgo/YLLCzWQsVMXHnD9E5GTd8lEl cXxQTJl8w3Q5ikjH+a44gJg79bB7Mx4QV7ndMn3PwD+hItrV1vCyOfpiygjAaMtBl9Uf+Iew6 7DTAQGRoL9xWoTqyGUEZtSp2amz63/RL6fw+EEGiH3wqFBv3Pcw2vZqI9i2iioIJNY+pNR9kn zBOKuwrbDQosOrs3T70/FmfifARVva+iL0kEhFXUBYQgYaxRgnir8Ybm0BmaL+tfLGTHq5/SL l6Cwj0vAoX7VlpRazahpf+u9z3QVYkH5WS014EArFY77HrvgGcbB8tcFovfmbcynWwNhS/NW+ jY8GF5rq+5r/AKssxNRrggscwa2k8f0GsRzEEoLLKxHjK5IGPYP1mwRh7gQBE02toKYG6Rrc7 ho3vnCgJNtkJqWUPeXBA9uKQQqzvewym1favEUzIhRoghqogGZGZLpUpTJ5vFPYhCvoe8mDkS ooRxFwqhOUlcGVuAen+l8Vxf+dt9BTUvikMEm52fpxPyjLvlPiYyMV0AtRCxAbYfZkMTO41pr QwG7SpQ3aB4TuPnajfNAiluvHQSn8Gvea3gb+MYgqbpfSItXl3bFMJvXt5iuV9G5nob05an5P pi/OYt3fBIAKl1CTkqUBI+xh47Gz6upzAlhCHmnQyCh7+Lq6L3D7GuGd5rHpXJ6UpRZM8cTnN QhGlg2jQiU8AYRSzPf2xoaqiy+InRAJIdzszOlVDqwy7JLH1nM9AIXGtxiZzzmM0U4q1EU8Vr IQIF1RMxzhxtMkXToM02bxagV3Gu3G3Gv3G5He+4oisrrCu3MpUTSEmVA== Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.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. This 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 3e3d784aa628..5245c179cc51 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -675,9 +675,6 @@ int serial8250_em485_config(struct uart_port *port, struct serial_rs485 *rs485) 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 015f4e1da647..b387376e6fa2 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1352,12 +1352,23 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4 memset(rs485->padding, 0, sizeof(rs485->padding)); } +static void uart_set_rs485_termination(struct uart_port *port, + const struct serial_rs485 *rs485) +{ + if (!port->rs485_term_gpio || !(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, rs485); if (ret) @@ -1400,6 +1411,7 @@ static int uart_set_rs485_config(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, &rs485);