From: Lino Sanfilippo <LinoSanfilippo@gmx.de> 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 <l.sanfilippo@kunbus.com> Subject: [PATCH v2 2/9] serial: core, 8250: set RS485 termination gpio in serial core Date: Sun, 3 Jul 2022 19:00:32 +0200 [thread overview] Message-ID: <20220703170039.2058202-3-LinoSanfilippo@gmx.de> (raw) In-Reply-To: <20220703170039.2058202-1-LinoSanfilippo@gmx.de> From: Lino Sanfilippo <l.sanfilippo@kunbus.com> 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 <l.sanfilippo@kunbus.com> --- 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); -- 2.25.1
WARNING: multiple messages have this Message-ID (diff)
From: Lino Sanfilippo <LinoSanfilippo@gmx.de> 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 <l.sanfilippo@kunbus.com> Subject: [PATCH v2 2/9] serial: core, 8250: set RS485 termination gpio in serial core Date: Sun, 3 Jul 2022 19:00:32 +0200 [thread overview] Message-ID: <20220703170039.2058202-3-LinoSanfilippo@gmx.de> (raw) In-Reply-To: <20220703170039.2058202-1-LinoSanfilippo@gmx.de> From: Lino Sanfilippo <l.sanfilippo@kunbus.com> 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 <l.sanfilippo@kunbus.com> --- 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); -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-07-03 17:02 UTC|newest] Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-07-03 17:00 [PATCH v2 0/9] Fixes and cleanup for RS485 Lino Sanfilippo 2022-07-03 17:00 ` Lino Sanfilippo 2022-07-03 17:00 ` [PATCH v2 1/9] serial: core: only get RS485 termination GPIO if supported Lino Sanfilippo 2022-07-03 17:00 ` Lino Sanfilippo 2022-07-03 18:27 ` Andy Shevchenko 2022-07-03 18:27 ` Andy Shevchenko 2022-07-04 9:01 ` Lino Sanfilippo 2022-07-04 9:01 ` Lino Sanfilippo 2022-07-04 9:55 ` Ilpo Järvinen 2022-07-04 9:55 ` Ilpo Järvinen 2022-07-04 15:07 ` Lino Sanfilippo 2022-07-04 15:07 ` Lino Sanfilippo 2022-07-03 17:00 ` Lino Sanfilippo [this message] 2022-07-03 17:00 ` [PATCH v2 2/9] serial: core, 8250: set RS485 termination gpio in serial core Lino Sanfilippo 2022-07-03 18:31 ` Andy Shevchenko 2022-07-03 18:31 ` Andy Shevchenko 2022-07-04 9:25 ` Lino Sanfilippo 2022-07-04 9:25 ` Lino Sanfilippo 2022-07-04 9:51 ` Ilpo Järvinen 2022-07-04 9:51 ` Ilpo Järvinen 2022-07-04 15:13 ` Lino Sanfilippo 2022-07-04 15:13 ` Lino Sanfilippo 2022-07-03 17:00 ` [PATCH v2 3/9] serial: core: move sanitizing of RS485 delays into own function Lino Sanfilippo 2022-07-03 17:00 ` Lino Sanfilippo 2022-07-03 17:00 ` [PATCH v2 4/9] serial: core: sanitize RS485 delays read from device tree Lino Sanfilippo 2022-07-03 17:00 ` Lino Sanfilippo 2022-07-03 18:34 ` Andy Shevchenko 2022-07-03 18:34 ` Andy Shevchenko 2022-07-04 9:08 ` Lino Sanfilippo 2022-07-04 9:08 ` Lino Sanfilippo 2022-07-03 17:00 ` [PATCH v2 5/9] dt_bindings: rs485: Correct delay values Lino Sanfilippo 2022-07-03 17:00 ` Lino Sanfilippo 2022-07-03 18:36 ` Andy Shevchenko 2022-07-03 18:36 ` Andy Shevchenko 2022-07-05 20:38 ` Rob Herring 2022-07-05 20:38 ` Rob Herring 2022-07-03 17:00 ` [PATCH v2 6/9] serial: 8250_dwlib: remove redundant sanity check for RS485 flags Lino Sanfilippo 2022-07-03 17:00 ` Lino Sanfilippo 2022-07-03 17:00 ` [PATCH v2 7/9] serial: ar933x: Fix check for RS485 support Lino Sanfilippo 2022-07-03 17:00 ` Lino Sanfilippo 2022-07-03 18:39 ` Andy Shevchenko 2022-07-03 18:39 ` Andy Shevchenko 2022-07-04 9:21 ` Lino Sanfilippo 2022-07-04 9:21 ` Lino Sanfilippo 2022-07-04 9:53 ` Ilpo Järvinen 2022-07-04 9:53 ` Ilpo Järvinen 2022-07-03 17:00 ` [PATCH v2 8/9] serial: ar933x: Remove redundant assignment in rs485_config Lino Sanfilippo 2022-07-03 17:00 ` Lino Sanfilippo 2022-07-03 17:00 ` [PATCH v2 9/9] serial: 8250: lpc18xx: Remove redundant sanity check for RS485 flags Lino Sanfilippo 2022-07-03 17:00 ` Lino Sanfilippo
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220703170039.2058202-3-LinoSanfilippo@gmx.de \ --to=linosanfilippo@gmx.de \ --cc=andriy.shevchenko@linux.intel.com \ --cc=devicetree@vger.kernel.org \ --cc=gregkh@linuxfoundation.org \ --cc=ilpo.jarvinen@linux.intel.com \ --cc=jirislaby@kernel.org \ --cc=krzysztof.kozlowski+dt@linaro.org \ --cc=l.sanfilippo@kunbus.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-serial@vger.kernel.org \ --cc=lukas@wunner.de \ --cc=p.rosenberger@kunbus.com \ --cc=robh+dt@kernel.org \ --cc=vz@mleia.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.