Skip to content

Commit

Permalink
serial: 8250_fintek: Return -EINVAL on invalid configuration
Browse files Browse the repository at this point in the history
Hardware does not support having the same RTS level during RX and TX
when RS485 mode is on (URA in Fintek terminology).

The manufacturer has also confirmed that the delays are not enabled if
the RS485 mode is not enabled.

Therefore we should return -EINVAL if the user wants to have the same
value for RTS_ON_SEND and RTS_AFTER_SEND.

Cc: "Ji-Ze Hong (Peter Hong)" <[email protected]>
Cc: Lukas Wunner <[email protected]>
Signed-off-by: Ricardo Ribalda Delgado <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
ribalda authored and gregkh committed Nov 8, 2017
1 parent e5656d4 commit 7ecc770
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions drivers/tty/serial/8250/8250_fintek.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,17 @@ static int fintek_8250_rs485_config(struct uart_port *port,
if (!pdata)
return -EINVAL;

if (rs485->flags & SER_RS485_ENABLED)
/* Hardware do not support same RTS level on send and receive */
if (!(rs485->flags & SER_RS485_RTS_ON_SEND) ==
!(rs485->flags & SER_RS485_RTS_AFTER_SEND))
return -EINVAL;

if (rs485->flags & SER_RS485_ENABLED) {
memset(rs485->padding, 0, sizeof(rs485->padding));
else
config |= RS485_URA;
} else {
memset(rs485, 0, sizeof(*rs485));
}

rs485->flags &= SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND |
SER_RS485_RTS_AFTER_SEND;
Expand All @@ -215,12 +222,6 @@ static int fintek_8250_rs485_config(struct uart_port *port,
config |= RXW4C_IRA;
}

if ((!!(rs485->flags & SER_RS485_RTS_ON_SEND)) ==
(!!(rs485->flags & SER_RS485_RTS_AFTER_SEND)))
rs485->flags &= ~SER_RS485_ENABLED;
else
config |= RS485_URA;

if (rs485->flags & SER_RS485_RTS_ON_SEND)
config |= RTS_INVERT;

Expand Down

0 comments on commit 7ecc770

Please sign in to comment.