2017-11-06 10:50:33

by Ricardo Ribalda Delgado

[permalink] [raw]
Subject: [PATCH 1/2] serial: 8250_fintek: Return -EINVAL on invalid configuration

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]>
---
drivers/tty/serial/8250/8250_fintek.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_fintek.c b/drivers/tty/serial/8250/8250_fintek.c
index c41cbb52f1fe..ca7e96f9f080 100644
--- a/drivers/tty/serial/8250/8250_fintek.c
+++ b/drivers/tty/serial/8250/8250_fintek.c
@@ -201,10 +201,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;
@@ -219,12 +226,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;

--
2.14.2


From 1584969453875204067@xxx Fri Nov 24 17:31:00 +0000 2017
X-GM-THRID: 1584969453875204067
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread


2017-11-06 10:50:18

by Ricardo Ribalda Delgado

[permalink] [raw]
Subject: [PATCH 2/2] serial: 8250_fintek: Disable delays for ports != 0

According to the datasheet, only the first port supports delay before
send and delay after send.

Reported-by: "Ji-Ze Hong (Peter Hong)" <[email protected]>
Signed-off-by: Ricardo Ribalda Delgado <[email protected]>
---
drivers/tty/serial/8250/8250_fintek.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_fintek.c b/drivers/tty/serial/8250/8250_fintek.c
index ca7e96f9f080..61745d4bea31 100644
--- a/drivers/tty/serial/8250/8250_fintek.c
+++ b/drivers/tty/serial/8250/8250_fintek.c
@@ -216,6 +216,12 @@ static int fintek_8250_rs485_config(struct uart_port *port,
rs485->flags &= SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND |
SER_RS485_RTS_AFTER_SEND;

+ /* Only the first port supports delays */
+ if (pdata->index) {
+ rs485->delay_rts_before_send = 0;
+ rs485->delay_rts_after_send = 0;
+ }
+
if (rs485->delay_rts_before_send) {
rs485->delay_rts_before_send = 1;
config |= TXW4C_IRA;
--
2.14.2


From 1582952359948878949@xxx Thu Nov 02 11:10:09 +0000 2017
X-GM-THRID: 1582952359948878949
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread