mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-02 23:27:06 +00:00
serial: omap: Disallow RS-485 if rts-gpio is not specified
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 <linus.walleij@linaro.org> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Lukas Wunner <lukas@wunner.de> Link: https://lore.kernel.org/r/f191dcca0d8ea03598c463fc0d3fba8941ff2275.1662888075.git.lukas@wunner.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
ed9f4bb396
commit
e2752ae3cf
1 changed files with 13 additions and 14 deletions
|
@ -300,8 +300,7 @@ static void serial_omap_stop_tx(struct uart_port *port)
|
||||||
serial_out(up, UART_OMAP_SCR, up->scr);
|
serial_out(up, UART_OMAP_SCR, up->scr);
|
||||||
res = (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) ?
|
res = (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) ?
|
||||||
1 : 0;
|
1 : 0;
|
||||||
if (up->rts_gpiod &&
|
if (gpiod_get_value(up->rts_gpiod) != res) {
|
||||||
gpiod_get_value(up->rts_gpiod) != res) {
|
|
||||||
if (port->rs485.delay_rts_after_send > 0)
|
if (port->rs485.delay_rts_after_send > 0)
|
||||||
mdelay(
|
mdelay(
|
||||||
port->rs485.delay_rts_after_send);
|
port->rs485.delay_rts_after_send);
|
||||||
|
@ -397,7 +396,7 @@ static void serial_omap_start_tx(struct uart_port *port)
|
||||||
|
|
||||||
/* if rts not already enabled */
|
/* if rts not already enabled */
|
||||||
res = (port->rs485.flags & SER_RS485_RTS_ON_SEND) ? 1 : 0;
|
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);
|
gpiod_set_value(up->rts_gpiod, res);
|
||||||
if (port->rs485.delay_rts_before_send > 0)
|
if (port->rs485.delay_rts_before_send > 0)
|
||||||
mdelay(port->rs485.delay_rts_before_send);
|
mdelay(port->rs485.delay_rts_before_send);
|
||||||
|
@ -1336,13 +1335,11 @@ serial_omap_config_rs485(struct uart_port *port, struct ktermios *termios,
|
||||||
up->ier = 0;
|
up->ier = 0;
|
||||||
serial_out(up, UART_IER, 0);
|
serial_out(up, UART_IER, 0);
|
||||||
|
|
||||||
if (up->rts_gpiod) {
|
/* enable / disable rts */
|
||||||
/* enable / disable rts */
|
val = (rs485->flags & SER_RS485_ENABLED) ?
|
||||||
val = (rs485->flags & SER_RS485_ENABLED) ?
|
SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND;
|
||||||
SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND;
|
val = (rs485->flags & val) ? 1 : 0;
|
||||||
val = (rs485->flags & val) ? 1 : 0;
|
gpiod_set_value(up->rts_gpiod, val);
|
||||||
gpiod_set_value(up->rts_gpiod, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enable interrupts */
|
/* Enable interrupts */
|
||||||
up->ier = mode;
|
up->ier = mode;
|
||||||
|
@ -1547,11 +1544,13 @@ static int serial_omap_probe_rs485(struct uart_omap_port *up,
|
||||||
ret = PTR_ERR(up->rts_gpiod);
|
ret = PTR_ERR(up->rts_gpiod);
|
||||||
if (ret == -EPROBE_DEFER)
|
if (ret == -EPROBE_DEFER)
|
||||||
return ret;
|
return ret;
|
||||||
/*
|
|
||||||
* FIXME: the code historically ignored any other error than
|
|
||||||
* -EPROBE_DEFER and just went on without GPIO.
|
|
||||||
*/
|
|
||||||
up->rts_gpiod = NULL;
|
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 {
|
} else {
|
||||||
gpiod_set_consumer_name(up->rts_gpiod, "omap-serial");
|
gpiod_set_consumer_name(up->rts_gpiod, "omap-serial");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue