Commit 6056f20f authored by Crescent CY Hsieh's avatar Crescent CY Hsieh Committed by Greg Kroah-Hartman

tty: serial: Add RS422 flag to struct serial_rs485

Add "SER_RS485_MODE_RS422" flag to struct serial_rs485, so that serial
port can switch interface into RS422 if supported by using ioctl command
"TIOCSRS485".

By treating RS422 as a mode of RS485, which means while enabling RS422
there are two flags need to be set (SER_RS485_ENABLED and
SER_RS485_MODE_RS422), it would make things much easier. For example
some places that checks for "SER_RS485_ENABLED" won't need to be rewritten.
Signed-off-by: default avatarCrescent CY Hsieh <crescentcy.hsieh@moxa.com>
Link: https://lore.kernel.org/r/20231201071554.258607-3-crescentcy.hsieh@moxa.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 76ac8e29
...@@ -1370,6 +1370,12 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4 ...@@ -1370,6 +1370,12 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4
return; return;
} }
/* Clear other RS485 flags but SER_RS485_TERMINATE_BUS and return if enabling RS422 */
if (rs485->flags & SER_RS485_MODE_RS422) {
rs485->flags &= (SER_RS485_ENABLED | SER_RS485_MODE_RS422 | SER_RS485_TERMINATE_BUS);
return;
}
/* Pick sane settings if the user hasn't */ /* Pick sane settings if the user hasn't */
if ((supported_flags & (SER_RS485_RTS_ON_SEND|SER_RS485_RTS_AFTER_SEND)) && if ((supported_flags & (SER_RS485_RTS_ON_SEND|SER_RS485_RTS_AFTER_SEND)) &&
!(rs485->flags & SER_RS485_RTS_ON_SEND) == !(rs485->flags & SER_RS485_RTS_ON_SEND) ==
......
...@@ -138,6 +138,7 @@ struct serial_icounter_struct { ...@@ -138,6 +138,7 @@ struct serial_icounter_struct {
* * %SER_RS485_ADDRB - Enable RS485 addressing mode. * * %SER_RS485_ADDRB - Enable RS485 addressing mode.
* * %SER_RS485_ADDR_RECV - Receive address filter (enables @addr_recv). Requires %SER_RS485_ADDRB. * * %SER_RS485_ADDR_RECV - Receive address filter (enables @addr_recv). Requires %SER_RS485_ADDRB.
* * %SER_RS485_ADDR_DEST - Destination address (enables @addr_dest). Requires %SER_RS485_ADDRB. * * %SER_RS485_ADDR_DEST - Destination address (enables @addr_dest). Requires %SER_RS485_ADDRB.
* * %SER_RS485_MODE_RS422 - Enable RS422. Requires %SER_RS485_ENABLED.
*/ */
struct serial_rs485 { struct serial_rs485 {
__u32 flags; __u32 flags;
...@@ -149,6 +150,7 @@ struct serial_rs485 { ...@@ -149,6 +150,7 @@ struct serial_rs485 {
#define SER_RS485_ADDRB _BITUL(5) #define SER_RS485_ADDRB _BITUL(5)
#define SER_RS485_ADDR_RECV _BITUL(6) #define SER_RS485_ADDR_RECV _BITUL(6)
#define SER_RS485_ADDR_DEST _BITUL(7) #define SER_RS485_ADDR_DEST _BITUL(7)
#define SER_RS485_MODE_RS422 _BITUL(8)
__u32 delay_rts_before_send; __u32 delay_rts_before_send;
__u32 delay_rts_after_send; __u32 delay_rts_after_send;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment