Skip to content

Commit 6056f20

Browse files
Crescent CY Hsiehgregkh
authored andcommitted
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: Crescent CY Hsieh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 76ac8e2 commit 6056f20

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

drivers/tty/serial/serial_core.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,12 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4
13701370
return;
13711371
}
13721372

1373+
/* Clear other RS485 flags but SER_RS485_TERMINATE_BUS and return if enabling RS422 */
1374+
if (rs485->flags & SER_RS485_MODE_RS422) {
1375+
rs485->flags &= (SER_RS485_ENABLED | SER_RS485_MODE_RS422 | SER_RS485_TERMINATE_BUS);
1376+
return;
1377+
}
1378+
13731379
/* Pick sane settings if the user hasn't */
13741380
if ((supported_flags & (SER_RS485_RTS_ON_SEND|SER_RS485_RTS_AFTER_SEND)) &&
13751381
!(rs485->flags & SER_RS485_RTS_ON_SEND) ==

include/uapi/linux/serial.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ struct serial_icounter_struct {
138138
* * %SER_RS485_ADDRB - Enable RS485 addressing mode.
139139
* * %SER_RS485_ADDR_RECV - Receive address filter (enables @addr_recv). Requires %SER_RS485_ADDRB.
140140
* * %SER_RS485_ADDR_DEST - Destination address (enables @addr_dest). Requires %SER_RS485_ADDRB.
141+
* * %SER_RS485_MODE_RS422 - Enable RS422. Requires %SER_RS485_ENABLED.
141142
*/
142143
struct serial_rs485 {
143144
__u32 flags;
@@ -149,6 +150,7 @@ struct serial_rs485 {
149150
#define SER_RS485_ADDRB _BITUL(5)
150151
#define SER_RS485_ADDR_RECV _BITUL(6)
151152
#define SER_RS485_ADDR_DEST _BITUL(7)
153+
#define SER_RS485_MODE_RS422 _BITUL(8)
152154

153155
__u32 delay_rts_before_send;
154156
__u32 delay_rts_after_send;

0 commit comments

Comments
 (0)