Skip to content

Commit

Permalink
serial: omap: Disallow RS-485 if rts-gpio is not specified
Browse files Browse the repository at this point in the history
The serial-omap driver requires an rts-gpio for RS-485 to work.
Historically it has allowed enabling RS-485 even if no rts-gpio was
specified in the device tree.

That doesn't make any sense, so disable RS-485 on probe if rts-gpio is
missing and disallow user space from enabling it.

Three NULL pointer checks for up->rts_gpiod can be dropped as a result,
simplifying the driver slightly.

Cc: Linus Walleij <[email protected]>
Reviewed-by: Ilpo Järvinen <[email protected]>
Acked-by: Linus Walleij <[email protected]>
Signed-off-by: Lukas Wunner <[email protected]>
Link: https://lore.kernel.org/r/f191dcca0d8ea03598c463fc0d3fba8941ff2275.1662888075.git.lukas@wunner.de
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
l1k authored and gregkh committed Sep 22, 2022
1 parent ed9f4bb commit e2752ae
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions drivers/tty/serial/omap-serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ static void serial_omap_stop_tx(struct uart_port *port)
serial_out(up, UART_OMAP_SCR, up->scr);
res = (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) ?
1 : 0;
if (up->rts_gpiod &&
gpiod_get_value(up->rts_gpiod) != res) {
if (gpiod_get_value(up->rts_gpiod) != res) {
if (port->rs485.delay_rts_after_send > 0)
mdelay(
port->rs485.delay_rts_after_send);
Expand Down Expand Up @@ -397,7 +396,7 @@ static void serial_omap_start_tx(struct uart_port *port)

/* if rts not already enabled */
res = (port->rs485.flags & SER_RS485_RTS_ON_SEND) ? 1 : 0;
if (up->rts_gpiod && gpiod_get_value(up->rts_gpiod) != res) {
if (gpiod_get_value(up->rts_gpiod) != res) {
gpiod_set_value(up->rts_gpiod, res);
if (port->rs485.delay_rts_before_send > 0)
mdelay(port->rs485.delay_rts_before_send);
Expand Down Expand Up @@ -1336,13 +1335,11 @@ serial_omap_config_rs485(struct uart_port *port, struct ktermios *termios,
up->ier = 0;
serial_out(up, UART_IER, 0);

if (up->rts_gpiod) {
/* enable / disable rts */
val = (rs485->flags & SER_RS485_ENABLED) ?
SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND;
val = (rs485->flags & val) ? 1 : 0;
gpiod_set_value(up->rts_gpiod, val);
}
/* enable / disable rts */
val = (rs485->flags & SER_RS485_ENABLED) ?
SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND;
val = (rs485->flags & val) ? 1 : 0;
gpiod_set_value(up->rts_gpiod, val);

/* Enable interrupts */
up->ier = mode;
Expand Down Expand Up @@ -1547,11 +1544,13 @@ static int serial_omap_probe_rs485(struct uart_omap_port *up,
ret = PTR_ERR(up->rts_gpiod);
if (ret == -EPROBE_DEFER)
return ret;
/*
* FIXME: the code historically ignored any other error than
* -EPROBE_DEFER and just went on without GPIO.
*/

up->rts_gpiod = NULL;
up->port.rs485_supported = (const struct serial_rs485) { };
if (rs485conf->flags & SER_RS485_ENABLED) {
dev_err(dev, "disabling RS-485 (rts-gpio missing in device tree)\n");
memset(rs485conf, 0, sizeof(*rs485conf));
}
} else {
gpiod_set_consumer_name(up->rts_gpiod, "omap-serial");
}
Expand Down

0 comments on commit e2752ae

Please sign in to comment.