Re: [PATCH v2 2/9] serial: core, 8250: set RS485 termination gpio in serial core

From: Andy Shevchenko
Date: Sun Jul 03 2022 - 14:32:57 EST


On Sun, Jul 3, 2022 at 7:02 PM Lino Sanfilippo <LinoSanfilippo@xxxxxx> wrote:
>
> From: Lino Sanfilippo <l.sanfilippo@xxxxxxxxxx>
>
> 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.

allows it to

> Beside fixing the termination GPIO line setting for the 8250 driver this
> change also makes setting the termination GPIO generic for all UART
> drivers.

...

> +static void uart_set_rs485_termination(struct uart_port *port,
> + const struct serial_rs485 *rs485)
> +{

> + if (!port->rs485_term_gpio

This duplicates the check the GPIO library does. Drop it.

> || !(rs485->flags & SER_RS485_ENABLED))
> + return;
> +
> + gpiod_set_value_cansleep(port->rs485_term_gpio,
> + !!(rs485->flags & SER_RS485_TERMINATE_BUS));
> +}

--
With Best Regards,
Andy Shevchenko