From patchwork Sun Jul 3 17:00:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12904417 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 60C84C43334 for ; Sun, 3 Jul 2022 17:03:49 +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=Vt/xzYp3fZGm463ujYvNaZ6WFNwOLVO2tua8Pla0n4M=; b=kU2mmmY57Z7J9u H24mXfmYr8eemr9ImplyUy6eKtUB5xq+FQqax/QLvg/5ofr5R03dm8rF/MGZBnazN9Vz0trGN8Kl9 sVorFRoy4DZjiz0yiFPZ8sEspG9ADZLYf3qZ8JbTHsX8RPvaNxu3gea04QIJGtpfjP6udLQje80xv d00iqZw1uPConar3NKWkxZ8cFWy8xkPAsTDQ3LqAzbXzFgbf80lTtTl997Jsj2wnwI9PmO+IXd0zu kckjowxCx2PO4GRJWpmTBmIgI4Qe4+s9mnHgb4Cj80yRE9+AyB3/8h6cDr24kCiKlOrDBlnZDMId0 hSRePMS9V21SqvK+PArw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o82zd-00HMza-7y; Sun, 03 Jul 2022 17:02:45 +0000 Received: from mout.gmx.net ([212.227.15.19]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o82yf-00HMR0-Oe for linux-arm-kernel@lists.infradead.org; Sun, 03 Jul 2022 17:01:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656867690; bh=4T+L3fj2rIaDf0LyMh9vktfUXwU/37+/jmdujXAyxz0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=FEuqHqg0WG5nVktHv6xCd3W1Ld6jtB5zAnlm/hfeHGjRN6Yvx+WK7KZ0ix1XOe/KH Xz2o8FO+6xxwOB7ztgX+NX3bVE6WtFKxUf6wsoQHWizke8Wf4wPpYI5FKUGIAYl1RT z0BrGsQRBedJMDB5HbP8B4dl8XpeKYnXsLUIHS2c= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.210]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N1wq3-1nRnF52VdB-012Kq0; Sun, 03 Jul 2022 19:01:30 +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 v2 2/9] serial: core, 8250: set RS485 termination gpio in serial core Date: Sun, 3 Jul 2022 19:00:32 +0200 Message-Id: <20220703170039.2058202-3-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220703170039.2058202-1-LinoSanfilippo@gmx.de> References: <20220703170039.2058202-1-Lino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ml0B3YDINDsMKTxAFQSE3fnUWV8j+8BKiJIzG0iW3mkiMUi76M5eB/ AKrMnc6y2FDwGHcR/crZaU++34um5YhKei4KDIcxW2j+uJPzuPMfzFgawUh0OH5koJh36JpaZ 9S1pabv9aVkZBL6iAngcJK73Qw8pVAcbfcw9A1zf2azLRypkN5qGnq8XzED2UtQAch/WacOv/ bXJUkQn41u4O9BDyOqkJTNtBgJtFDE2PEzA+CmVKOUzaXeTsBFrqxTF4BzUyxoyX4iNZ5Yv3k v7jtFg4PdlSIOzm+5S70okhmX/J8BNd2TUPCeO2fL+cU15TaDlG7TDSel0eds6ysiClwqiR7G 9GgOI6ZkBqiabwN3VsqOED5hyBNiPpS8ulfrW1YenrA/d21STfPn1kAgg== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220703_100146_112324_96628C02 X-CRM114-Status: GOOD ( 14.05 ) 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 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 3768663dfa4d..9c29d031b404 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 (!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, 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);