* [PATCH v3] tty: serial: Add RS422 flag to struct serial_rs485
@ 2023-11-08 6:07 Crescent CY Hsieh
2023-11-09 13:35 ` Ilpo Järvinen
0 siblings, 1 reply; 3+ messages in thread
From: Crescent CY Hsieh @ 2023-11-08 6:07 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: linux-kernel, linux-serial, Crescent CY Hsieh
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.
There are only two things need to be noticed:
- While enabling RS422, other RS485 flags should not be set.
- RS422 doesn't need to deal with termination, so while disabling RS485
or enabling RS422, uart_set_rs485_termination() shall return.
Signed-off-by: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
---
Changes from v2 to v3:
- Remove "SER_RS422_ENABLED" flag from legacy flags.
- Revise "SER_RS422_ENABLED" into "SER_RS485_MODE_RS422".
- Remove the code which checks the conflicts between SER_RS485_ENABLED
and SER_RS422_ENABLED.
- Add return check in uart_set_rs485_termination().
Changes from v1 to v2:
- Revise the logic that checks whether RS422/RS485 are enabled
simultaneously.
v2: https://lore.kernel.org/all/20231101064404.45711-1-crescentcy.hsieh@moxa.com/
v1: https://lore.kernel.org/all/20231030053632.5109-1-crescentcy.hsieh@moxa.com/
---
drivers/tty/serial/serial_core.c | 11 ++++++++++-
include/uapi/linux/serial.h | 18 ++++++++++--------
2 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 831d03361..777f091a4 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1376,6 +1376,13 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4
return;
}
+ /* Clear other RS485 flags and return if enabling RS422 */
+ if (rs485->flags & SER_RS485_MODE_RS422) {
+ memset(rs485, 0, sizeof(*rs485));
+ rs485->flags |= (SER_RS485_ENABLED | SER_RS485_MODE_RS422);
+ return;
+ }
+
/* Pick sane settings if the user hasn't */
if ((supported_flags & (SER_RS485_RTS_ON_SEND|SER_RS485_RTS_AFTER_SEND)) &&
!(rs485->flags & SER_RS485_RTS_ON_SEND) ==
@@ -1400,7 +1407,9 @@ static void uart_sanitize_serial_rs485(struct uart_port *port, struct serial_rs4
static void uart_set_rs485_termination(struct uart_port *port,
const struct serial_rs485 *rs485)
{
- if (!(rs485->flags & SER_RS485_ENABLED))
+ /* Return while disabling RS485 or enabling RS422 */
+ if (!(rs485->flags & SER_RS485_ENABLED) ||
+ (rs485->flags & SER_RS485_ENABLED && rs485->flags & SER_RS485_MODE_RS422))
return;
gpiod_set_value_cansleep(port->rs485_term_gpio,
diff --git a/include/uapi/linux/serial.h b/include/uapi/linux/serial.h
index 53bc1af67..c9c4d3b00 100644
--- a/include/uapi/linux/serial.h
+++ b/include/uapi/linux/serial.h
@@ -137,17 +137,19 @@ struct serial_icounter_struct {
* * %SER_RS485_ADDRB - Enable RS485 addressing mode.
* * %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_MODE_RS422 - Enable RS422. Requires %SER_RS485_ENABLED.
*/
struct serial_rs485 {
__u32 flags;
-#define SER_RS485_ENABLED (1 << 0)
-#define SER_RS485_RTS_ON_SEND (1 << 1)
-#define SER_RS485_RTS_AFTER_SEND (1 << 2)
-#define SER_RS485_RX_DURING_TX (1 << 4)
-#define SER_RS485_TERMINATE_BUS (1 << 5)
-#define SER_RS485_ADDRB (1 << 6)
-#define SER_RS485_ADDR_RECV (1 << 7)
-#define SER_RS485_ADDR_DEST (1 << 8)
+#define SER_RS485_ENABLED BIT(0)
+#define SER_RS485_RTS_ON_SEND BIT(1)
+#define SER_RS485_RTS_AFTER_SEND BIT(2)
+#define SER_RS485_RX_DURING_TX BIT(3)
+#define SER_RS485_TERMINATE_BUS BIT(4)
+#define SER_RS485_ADDRB BIT(5)
+#define SER_RS485_ADDR_RECV BIT(6)
+#define SER_RS485_ADDR_DEST BIT(7)
+#define SER_RS485_MODE_RS422 BIT(8)
__u32 delay_rts_before_send;
__u32 delay_rts_after_send;
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] tty: serial: Add RS422 flag to struct serial_rs485
2023-11-08 6:07 [PATCH v3] tty: serial: Add RS422 flag to struct serial_rs485 Crescent CY Hsieh
@ 2023-11-09 13:35 ` Ilpo Järvinen
2023-11-09 14:16 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Ilpo Järvinen @ 2023-11-09 13:35 UTC (permalink / raw)
To: Crescent CY Hsieh; +Cc: Greg Kroah-Hartman, Jiri Slaby, LKML, linux-serial
On Wed, 8 Nov 2023, Crescent CY Hsieh wrote:
> 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.
>
> There are only two things need to be noticed:
>
> - While enabling RS422, other RS485 flags should not be set.
> - RS422 doesn't need to deal with termination, so while disabling RS485
> or enabling RS422, uart_set_rs485_termination() shall return.
>
> Signed-off-by: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
>
> ---
> Changes from v2 to v3:
> - Remove "SER_RS422_ENABLED" flag from legacy flags.
> - Revise "SER_RS422_ENABLED" into "SER_RS485_MODE_RS422".
> - Remove the code which checks the conflicts between SER_RS485_ENABLED
> and SER_RS422_ENABLED.
> - Add return check in uart_set_rs485_termination().
>
> Changes from v1 to v2:
> - Revise the logic that checks whether RS422/RS485 are enabled
> simultaneously.
>
> v2: https://lore.kernel.org/all/20231101064404.45711-1-crescentcy.hsieh@moxa.com/
> v1: https://lore.kernel.org/all/20231030053632.5109-1-crescentcy.hsieh@moxa.com/
>
> ---
> --- a/include/uapi/linux/serial.h
> +++ b/include/uapi/linux/serial.h
> @@ -137,17 +137,19 @@ struct serial_icounter_struct {
> * * %SER_RS485_ADDRB - Enable RS485 addressing mode.
> * * %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_MODE_RS422 - Enable RS422. Requires %SER_RS485_ENABLED.
> */
> struct serial_rs485 {
> __u32 flags;
> -#define SER_RS485_ENABLED (1 << 0)
> -#define SER_RS485_RTS_ON_SEND (1 << 1)
> -#define SER_RS485_RTS_AFTER_SEND (1 << 2)
> -#define SER_RS485_RX_DURING_TX (1 << 4)
> -#define SER_RS485_TERMINATE_BUS (1 << 5)
> -#define SER_RS485_ADDRB (1 << 6)
> -#define SER_RS485_ADDR_RECV (1 << 7)
> -#define SER_RS485_ADDR_DEST (1 << 8)
> +#define SER_RS485_ENABLED BIT(0)
> +#define SER_RS485_RTS_ON_SEND BIT(1)
> +#define SER_RS485_RTS_AFTER_SEND BIT(2)
> +#define SER_RS485_RX_DURING_TX BIT(3)
> +#define SER_RS485_TERMINATE_BUS BIT(4)
> +#define SER_RS485_ADDRB BIT(5)
> +#define SER_RS485_ADDR_RECV BIT(6)
> +#define SER_RS485_ADDR_DEST BIT(7)
> +#define SER_RS485_MODE_RS422 BIT(8)
Is BIT() allowed in uapi headers these days?
--
i.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] tty: serial: Add RS422 flag to struct serial_rs485
2023-11-09 13:35 ` Ilpo Järvinen
@ 2023-11-09 14:16 ` Greg Kroah-Hartman
0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2023-11-09 14:16 UTC (permalink / raw)
To: Ilpo Järvinen; +Cc: Crescent CY Hsieh, Jiri Slaby, LKML, linux-serial
On Thu, Nov 09, 2023 at 03:35:50PM +0200, Ilpo Järvinen wrote:
> On Wed, 8 Nov 2023, Crescent CY Hsieh wrote:
>
> > 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.
> >
> > There are only two things need to be noticed:
> >
> > - While enabling RS422, other RS485 flags should not be set.
> > - RS422 doesn't need to deal with termination, so while disabling RS485
> > or enabling RS422, uart_set_rs485_termination() shall return.
> >
> > Signed-off-by: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
> >
> > ---
> > Changes from v2 to v3:
> > - Remove "SER_RS422_ENABLED" flag from legacy flags.
> > - Revise "SER_RS422_ENABLED" into "SER_RS485_MODE_RS422".
> > - Remove the code which checks the conflicts between SER_RS485_ENABLED
> > and SER_RS422_ENABLED.
> > - Add return check in uart_set_rs485_termination().
> >
> > Changes from v1 to v2:
> > - Revise the logic that checks whether RS422/RS485 are enabled
> > simultaneously.
> >
> > v2: https://lore.kernel.org/all/20231101064404.45711-1-crescentcy.hsieh@moxa.com/
> > v1: https://lore.kernel.org/all/20231030053632.5109-1-crescentcy.hsieh@moxa.com/
> >
> > ---
>
> > --- a/include/uapi/linux/serial.h
> > +++ b/include/uapi/linux/serial.h
> > @@ -137,17 +137,19 @@ struct serial_icounter_struct {
> > * * %SER_RS485_ADDRB - Enable RS485 addressing mode.
> > * * %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_MODE_RS422 - Enable RS422. Requires %SER_RS485_ENABLED.
> > */
> > struct serial_rs485 {
> > __u32 flags;
> > -#define SER_RS485_ENABLED (1 << 0)
> > -#define SER_RS485_RTS_ON_SEND (1 << 1)
> > -#define SER_RS485_RTS_AFTER_SEND (1 << 2)
> > -#define SER_RS485_RX_DURING_TX (1 << 4)
> > -#define SER_RS485_TERMINATE_BUS (1 << 5)
> > -#define SER_RS485_ADDRB (1 << 6)
> > -#define SER_RS485_ADDR_RECV (1 << 7)
> > -#define SER_RS485_ADDR_DEST (1 << 8)
> > +#define SER_RS485_ENABLED BIT(0)
> > +#define SER_RS485_RTS_ON_SEND BIT(1)
> > +#define SER_RS485_RTS_AFTER_SEND BIT(2)
> > +#define SER_RS485_RX_DURING_TX BIT(3)
> > +#define SER_RS485_TERMINATE_BUS BIT(4)
> > +#define SER_RS485_ADDRB BIT(5)
> > +#define SER_RS485_ADDR_RECV BIT(6)
> > +#define SER_RS485_ADDR_DEST BIT(7)
> > +#define SER_RS485_MODE_RS422 BIT(8)
>
> Is BIT() allowed in uapi headers these days?
No, but there is something else that is, can't find it at the moment...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-09 14:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-08 6:07 [PATCH v3] tty: serial: Add RS422 flag to struct serial_rs485 Crescent CY Hsieh
2023-11-09 13:35 ` Ilpo Järvinen
2023-11-09 14:16 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).