All of lore.kernel.org
 help / color / mirror / Atom feed
* Move RS485 implementation from drivers to serial core (v4 RESEND)
@ 2022-04-10 10:46 ` Lino Sanfilippo
  0 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux, richard.genoud, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, shawnguo, s.hauer, kernel, festevam, linux-imx,
	mcoquelin.stm32, alexandre.torgue, linux-serial, linux-kernel,
	linux-arm-kernel, linux-stm32, lukas, p.rosenberger

This patch series is an attempt to simplify rs485 implementation in drivers
by moving the following tasks out of the drivers into the serial core:

- ensure sane RTS settings: in case of an invalid configuration (both RTS
  after send and RTS on send set or both unset) enable RTS on send and
  disable RTS after send

- nullify the padding field of the serial_rs485 struct before it is
  returned to userspace

- copy the configuration stored in the serial_rs485 struct to the port
  configuration if setting the configuration in the driver was successfull

- limit the RTS delay to 100ms


Redundant code has been removed from the following drivers for now:

- atmel
- fsl_lpuart
- amba
- imx
- max310x
- omap-serial
- sc16is7xx
- stm32-usart

The code has been tested with the amba pl011 driver. This series applies
against Gregs tty-testing branch.

Changes in v2:
- use a makro for max RTS delays and comment it (as requested by Jiri)
- add a comment concerning the memset of a structures padding field - correct
  typos in the commit message (found by Uwe) 
- rephrase all commit messages to make more clear that function
  uart_set_rs485_config() has been extended by checks and other functionalities
  (as requested by Uwe)

Changes in v3:
- add warning messages if the serial core corrects RS485 values (as requested by
  Lukas Wunner)
- dont expose the macro for max RTS delays to userspace (as requested by Greg)

Changes in v4:
- use ratelimit warning messages and also print device, uart port name and line
  (as requested by Jiri)




^ permalink raw reply	[flat|nested] 23+ messages in thread

* Move RS485 implementation from drivers to serial core (v4 RESEND)
@ 2022-04-10 10:46 ` Lino Sanfilippo
  0 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux-arm-kernel, alexandre.belloni, mcoquelin.stm32,
	richard.genoud, festevam, s.hauer, linux, alexandre.torgue,
	ludovic.desroches, lukas, linux-imx, kernel, linux-serial,
	shawnguo, linux-stm32, linux-kernel, p.rosenberger

This patch series is an attempt to simplify rs485 implementation in drivers
by moving the following tasks out of the drivers into the serial core:

- ensure sane RTS settings: in case of an invalid configuration (both RTS
  after send and RTS on send set or both unset) enable RTS on send and
  disable RTS after send

- nullify the padding field of the serial_rs485 struct before it is
  returned to userspace

- copy the configuration stored in the serial_rs485 struct to the port
  configuration if setting the configuration in the driver was successfull

- limit the RTS delay to 100ms


Redundant code has been removed from the following drivers for now:

- atmel
- fsl_lpuart
- amba
- imx
- max310x
- omap-serial
- sc16is7xx
- stm32-usart

The code has been tested with the amba pl011 driver. This series applies
against Gregs tty-testing branch.

Changes in v2:
- use a makro for max RTS delays and comment it (as requested by Jiri)
- add a comment concerning the memset of a structures padding field - correct
  typos in the commit message (found by Uwe) 
- rephrase all commit messages to make more clear that function
  uart_set_rs485_config() has been extended by checks and other functionalities
  (as requested by Uwe)

Changes in v3:
- add warning messages if the serial core corrects RS485 values (as requested by
  Lukas Wunner)
- dont expose the macro for max RTS delays to userspace (as requested by Greg)

Changes in v4:
- use ratelimit warning messages and also print device, uart port name and line
  (as requested by Jiri)



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 1/9] serial: core: move RS485 configuration tasks from drivers into core
  2022-04-10 10:46 ` Lino Sanfilippo
@ 2022-04-10 10:46   ` Lino Sanfilippo
  -1 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux, richard.genoud, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, shawnguo, s.hauer, kernel, festevam, linux-imx,
	mcoquelin.stm32, alexandre.torgue, linux-serial, linux-kernel,
	linux-arm-kernel, linux-stm32, lukas, p.rosenberger,
	Lino Sanfilippo

Several drivers that support setting the RS485 configuration via userspace
implement one or more of the following tasks:

- in case of an invalid RTS configuration (both RTS after send and RTS on
  send set or both unset) fall back to enable RTS on send and disable RTS
  after send

- nullify the padding field of the returned serial_rs485 struct

- copy the configuration into the uart port struct

- limit RTS delays to 100 ms

Move these tasks into the serial core to make them generic and to provide
a consistent behaviour among all drivers.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/serial_core.c | 33 ++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 6a8963caf954..108b389e6e12 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -42,6 +42,11 @@ static struct lock_class_key port_lock_key;
 
 #define HIGH_BITS_OFFSET	((sizeof(long)-sizeof(int))*8)
 
+/*
+ * Max time with active RTS before/after data is sent.
+ */
+#define RS485_MAX_RTS_DELAY	100 /* msecs */
+
 static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
 					struct ktermios *old_termios);
 static void uart_wait_until_sent(struct tty_struct *tty, int timeout);
@@ -1296,8 +1301,36 @@ static int uart_set_rs485_config(struct uart_port *port,
 	if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user)))
 		return -EFAULT;
 
+	/* pick sane settings if the user hasn't */
+	if (!(rs485.flags & SER_RS485_RTS_ON_SEND) ==
+	    !(rs485.flags & SER_RS485_RTS_AFTER_SEND)) {
+		dev_warn_ratelimited(port->dev,
+			"%s (%d): invalid RTS setting, using RTS_ON_SEND instead\n",
+			port->name, port->line);
+		rs485.flags |= SER_RS485_RTS_ON_SEND;
+		rs485.flags &= ~SER_RS485_RTS_AFTER_SEND;
+	}
+
+	if (rs485.delay_rts_before_send > RS485_MAX_RTS_DELAY) {
+		rs485.delay_rts_before_send = RS485_MAX_RTS_DELAY;
+		dev_warn_ratelimited(port->dev,
+			"%s (%d): RTS delay before sending clamped to %u ms\n",
+			port->name, port->line, rs485.delay_rts_before_send);
+	}
+
+	if (rs485.delay_rts_after_send > RS485_MAX_RTS_DELAY) {
+		rs485.delay_rts_after_send = RS485_MAX_RTS_DELAY;
+		dev_warn_ratelimited(port->dev,
+			"%s (%d): RTS delay after sending clamped to %u ms\n",
+			port->name, port->line, rs485.delay_rts_after_send);
+	}
+	/* Return clean padding area to userspace */
+	memset(rs485.padding, 0, sizeof(rs485.padding));
+
 	spin_lock_irqsave(&port->lock, flags);
 	ret = port->rs485_config(port, &rs485);
+	if (!ret)
+		port->rs485 = rs485;
 	spin_unlock_irqrestore(&port->lock, flags);
 	if (ret)
 		return ret;

base-commit: 3123109284176b1532874591f7c81f3837bbdc17
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 1/9] serial: core: move RS485 configuration tasks from drivers into core
@ 2022-04-10 10:46   ` Lino Sanfilippo
  0 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux-arm-kernel, alexandre.belloni, mcoquelin.stm32,
	Lino Sanfilippo, richard.genoud, festevam, s.hauer, linux,
	alexandre.torgue, ludovic.desroches, lukas, linux-imx, kernel,
	linux-serial, shawnguo, linux-stm32, linux-kernel, p.rosenberger

Several drivers that support setting the RS485 configuration via userspace
implement one or more of the following tasks:

- in case of an invalid RTS configuration (both RTS after send and RTS on
  send set or both unset) fall back to enable RTS on send and disable RTS
  after send

- nullify the padding field of the returned serial_rs485 struct

- copy the configuration into the uart port struct

- limit RTS delays to 100 ms

Move these tasks into the serial core to make them generic and to provide
a consistent behaviour among all drivers.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/serial_core.c | 33 ++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 6a8963caf954..108b389e6e12 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -42,6 +42,11 @@ static struct lock_class_key port_lock_key;
 
 #define HIGH_BITS_OFFSET	((sizeof(long)-sizeof(int))*8)
 
+/*
+ * Max time with active RTS before/after data is sent.
+ */
+#define RS485_MAX_RTS_DELAY	100 /* msecs */
+
 static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
 					struct ktermios *old_termios);
 static void uart_wait_until_sent(struct tty_struct *tty, int timeout);
@@ -1296,8 +1301,36 @@ static int uart_set_rs485_config(struct uart_port *port,
 	if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user)))
 		return -EFAULT;
 
+	/* pick sane settings if the user hasn't */
+	if (!(rs485.flags & SER_RS485_RTS_ON_SEND) ==
+	    !(rs485.flags & SER_RS485_RTS_AFTER_SEND)) {
+		dev_warn_ratelimited(port->dev,
+			"%s (%d): invalid RTS setting, using RTS_ON_SEND instead\n",
+			port->name, port->line);
+		rs485.flags |= SER_RS485_RTS_ON_SEND;
+		rs485.flags &= ~SER_RS485_RTS_AFTER_SEND;
+	}
+
+	if (rs485.delay_rts_before_send > RS485_MAX_RTS_DELAY) {
+		rs485.delay_rts_before_send = RS485_MAX_RTS_DELAY;
+		dev_warn_ratelimited(port->dev,
+			"%s (%d): RTS delay before sending clamped to %u ms\n",
+			port->name, port->line, rs485.delay_rts_before_send);
+	}
+
+	if (rs485.delay_rts_after_send > RS485_MAX_RTS_DELAY) {
+		rs485.delay_rts_after_send = RS485_MAX_RTS_DELAY;
+		dev_warn_ratelimited(port->dev,
+			"%s (%d): RTS delay after sending clamped to %u ms\n",
+			port->name, port->line, rs485.delay_rts_after_send);
+	}
+	/* Return clean padding area to userspace */
+	memset(rs485.padding, 0, sizeof(rs485.padding));
+
 	spin_lock_irqsave(&port->lock, flags);
 	ret = port->rs485_config(port, &rs485);
+	if (!ret)
+		port->rs485 = rs485;
 	spin_unlock_irqrestore(&port->lock, flags);
 	if (ret)
 		return ret;

base-commit: 3123109284176b1532874591f7c81f3837bbdc17
-- 
2.35.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 2/9] serial: amba-pl011: remove redundant code in rs485_config
  2022-04-10 10:46 ` Lino Sanfilippo
@ 2022-04-10 10:46   ` Lino Sanfilippo
  -1 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux, richard.genoud, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, shawnguo, s.hauer, kernel, festevam, linux-imx,
	mcoquelin.stm32, alexandre.torgue, linux-serial, linux-kernel,
	linux-arm-kernel, linux-stm32, lukas, p.rosenberger,
	Lino Sanfilippo

In uart_set_rs485_config() the serial core already

- ensures that only one of both options RTS on send or RTS after send is
  set

- nullifies the padding field of the passed serial_rs485 struct

- clamps the RTS delays

- assigns the passed serial_rs485 struct to the uart port

So remove these tasks from the code of the drivers rs485_config() function
to avoid redundancy.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/amba-pl011.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 51ecb050ae40..de2c4dc6257e 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -2170,25 +2170,11 @@ static int pl011_rs485_config(struct uart_port *port,
 	struct uart_amba_port *uap =
 		container_of(port, struct uart_amba_port, port);
 
-	/* pick sane settings if the user hasn't */
-	if (!(rs485->flags & SER_RS485_RTS_ON_SEND) ==
-	    !(rs485->flags & SER_RS485_RTS_AFTER_SEND)) {
-		rs485->flags |= SER_RS485_RTS_ON_SEND;
-		rs485->flags &= ~SER_RS485_RTS_AFTER_SEND;
-	}
-	/* clamp the delays to [0, 100ms] */
-	rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U);
-	rs485->delay_rts_after_send = min(rs485->delay_rts_after_send, 100U);
-	memset(rs485->padding, 0, sizeof(rs485->padding));
-
 	if (port->rs485.flags & SER_RS485_ENABLED)
 		pl011_rs485_tx_stop(uap);
 
-	/* Set new configuration */
-	port->rs485 = *rs485;
-
 	/* Make sure auto RTS is disabled */
-	if (port->rs485.flags & SER_RS485_ENABLED) {
+	if (rs485->flags & SER_RS485_ENABLED) {
 		u32 cr = pl011_read(uap, REG_CR);
 
 		cr &= ~UART011_CR_RTSEN;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 2/9] serial: amba-pl011: remove redundant code in rs485_config
@ 2022-04-10 10:46   ` Lino Sanfilippo
  0 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux-arm-kernel, alexandre.belloni, mcoquelin.stm32,
	Lino Sanfilippo, richard.genoud, festevam, s.hauer, linux,
	alexandre.torgue, ludovic.desroches, lukas, linux-imx, kernel,
	linux-serial, shawnguo, linux-stm32, linux-kernel, p.rosenberger

In uart_set_rs485_config() the serial core already

- ensures that only one of both options RTS on send or RTS after send is
  set

- nullifies the padding field of the passed serial_rs485 struct

- clamps the RTS delays

- assigns the passed serial_rs485 struct to the uart port

So remove these tasks from the code of the drivers rs485_config() function
to avoid redundancy.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/amba-pl011.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 51ecb050ae40..de2c4dc6257e 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -2170,25 +2170,11 @@ static int pl011_rs485_config(struct uart_port *port,
 	struct uart_amba_port *uap =
 		container_of(port, struct uart_amba_port, port);
 
-	/* pick sane settings if the user hasn't */
-	if (!(rs485->flags & SER_RS485_RTS_ON_SEND) ==
-	    !(rs485->flags & SER_RS485_RTS_AFTER_SEND)) {
-		rs485->flags |= SER_RS485_RTS_ON_SEND;
-		rs485->flags &= ~SER_RS485_RTS_AFTER_SEND;
-	}
-	/* clamp the delays to [0, 100ms] */
-	rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U);
-	rs485->delay_rts_after_send = min(rs485->delay_rts_after_send, 100U);
-	memset(rs485->padding, 0, sizeof(rs485->padding));
-
 	if (port->rs485.flags & SER_RS485_ENABLED)
 		pl011_rs485_tx_stop(uap);
 
-	/* Set new configuration */
-	port->rs485 = *rs485;
-
 	/* Make sure auto RTS is disabled */
-	if (port->rs485.flags & SER_RS485_ENABLED) {
+	if (rs485->flags & SER_RS485_ENABLED) {
 		u32 cr = pl011_read(uap, REG_CR);
 
 		cr &= ~UART011_CR_RTSEN;
-- 
2.35.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 3/9] serial: stm32: remove redundant code in rs485_config
  2022-04-10 10:46 ` Lino Sanfilippo
@ 2022-04-10 10:46   ` Lino Sanfilippo
  -1 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux, richard.genoud, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, shawnguo, s.hauer, kernel, festevam, linux-imx,
	mcoquelin.stm32, alexandre.torgue, linux-serial, linux-kernel,
	linux-arm-kernel, linux-stm32, lukas, p.rosenberger,
	Lino Sanfilippo

In uart_set_rs485_config() the serial core already ensures that only one of
both options RTS on send or RTS after send is set. It also assigns the
passed serial_rs485 struct to the uart port.

So remove the check and the assignment from the drivers rs485_config()
function to avoid redundancy.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/stm32-usart.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index 87b5cd4c9743..f886976daef6 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -107,8 +107,6 @@ static int stm32_usart_config_rs485(struct uart_port *port,
 
 	stm32_usart_clr_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit));
 
-	port->rs485 = *rs485conf;
-
 	rs485conf->flags |= SER_RS485_RX_DURING_TX;
 
 	if (rs485conf->flags & SER_RS485_ENABLED) {
@@ -128,13 +126,10 @@ static int stm32_usart_config_rs485(struct uart_port *port,
 					     rs485conf->delay_rts_after_send,
 					     baud);
 
-		if (rs485conf->flags & SER_RS485_RTS_ON_SEND) {
+		if (rs485conf->flags & SER_RS485_RTS_ON_SEND)
 			cr3 &= ~USART_CR3_DEP;
-			rs485conf->flags &= ~SER_RS485_RTS_AFTER_SEND;
-		} else {
+		else
 			cr3 |= USART_CR3_DEP;
-			rs485conf->flags |= SER_RS485_RTS_AFTER_SEND;
-		}
 
 		writel_relaxed(cr3, port->membase + ofs->cr3);
 		writel_relaxed(cr1, port->membase + ofs->cr1);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 3/9] serial: stm32: remove redundant code in rs485_config
@ 2022-04-10 10:46   ` Lino Sanfilippo
  0 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux-arm-kernel, alexandre.belloni, mcoquelin.stm32,
	Lino Sanfilippo, richard.genoud, festevam, s.hauer, linux,
	alexandre.torgue, ludovic.desroches, lukas, linux-imx, kernel,
	linux-serial, shawnguo, linux-stm32, linux-kernel, p.rosenberger

In uart_set_rs485_config() the serial core already ensures that only one of
both options RTS on send or RTS after send is set. It also assigns the
passed serial_rs485 struct to the uart port.

So remove the check and the assignment from the drivers rs485_config()
function to avoid redundancy.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/stm32-usart.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index 87b5cd4c9743..f886976daef6 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -107,8 +107,6 @@ static int stm32_usart_config_rs485(struct uart_port *port,
 
 	stm32_usart_clr_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit));
 
-	port->rs485 = *rs485conf;
-
 	rs485conf->flags |= SER_RS485_RX_DURING_TX;
 
 	if (rs485conf->flags & SER_RS485_ENABLED) {
@@ -128,13 +126,10 @@ static int stm32_usart_config_rs485(struct uart_port *port,
 					     rs485conf->delay_rts_after_send,
 					     baud);
 
-		if (rs485conf->flags & SER_RS485_RTS_ON_SEND) {
+		if (rs485conf->flags & SER_RS485_RTS_ON_SEND)
 			cr3 &= ~USART_CR3_DEP;
-			rs485conf->flags &= ~SER_RS485_RTS_AFTER_SEND;
-		} else {
+		else
 			cr3 |= USART_CR3_DEP;
-			rs485conf->flags |= SER_RS485_RTS_AFTER_SEND;
-		}
 
 		writel_relaxed(cr3, port->membase + ofs->cr3);
 		writel_relaxed(cr1, port->membase + ofs->cr1);
-- 
2.35.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 4/9] serial: sc16is7xx: remove redundant check in rs485_config
  2022-04-10 10:46 ` Lino Sanfilippo
@ 2022-04-10 10:46   ` Lino Sanfilippo
  -1 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux, richard.genoud, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, shawnguo, s.hauer, kernel, festevam, linux-imx,
	mcoquelin.stm32, alexandre.torgue, linux-serial, linux-kernel,
	linux-arm-kernel, linux-stm32, lukas, p.rosenberger,
	Lino Sanfilippo

In uart_set_rs485_config() the serial core already ensures that only one of
both options RTS on send or RTS after send is set.

So remove this check from the drivers rs485_config() function to avoid
redundancy.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/sc16is7xx.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
index e857fb61efbf..bb939d2877db 100644
--- a/drivers/tty/serial/sc16is7xx.c
+++ b/drivers/tty/serial/sc16is7xx.c
@@ -1134,16 +1134,6 @@ static int sc16is7xx_config_rs485(struct uart_port *port,
 	struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
 
 	if (rs485->flags & SER_RS485_ENABLED) {
-		bool rts_during_rx, rts_during_tx;
-
-		rts_during_rx = rs485->flags & SER_RS485_RTS_AFTER_SEND;
-		rts_during_tx = rs485->flags & SER_RS485_RTS_ON_SEND;
-
-		if (rts_during_rx == rts_during_tx)
-			dev_err(port->dev,
-				"unsupported RTS signalling on_send:%d after_send:%d - exactly one of RS485 RTS flags should be set\n",
-				rts_during_tx, rts_during_rx);
-
 		/*
 		 * RTS signal is handled by HW, it's timing can't be influenced.
 		 * However, it's sometimes useful to delay TX even without RTS
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 4/9] serial: sc16is7xx: remove redundant check in rs485_config
@ 2022-04-10 10:46   ` Lino Sanfilippo
  0 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux-arm-kernel, alexandre.belloni, mcoquelin.stm32,
	Lino Sanfilippo, richard.genoud, festevam, s.hauer, linux,
	alexandre.torgue, ludovic.desroches, lukas, linux-imx, kernel,
	linux-serial, shawnguo, linux-stm32, linux-kernel, p.rosenberger

In uart_set_rs485_config() the serial core already ensures that only one of
both options RTS on send or RTS after send is set.

So remove this check from the drivers rs485_config() function to avoid
redundancy.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/sc16is7xx.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
index e857fb61efbf..bb939d2877db 100644
--- a/drivers/tty/serial/sc16is7xx.c
+++ b/drivers/tty/serial/sc16is7xx.c
@@ -1134,16 +1134,6 @@ static int sc16is7xx_config_rs485(struct uart_port *port,
 	struct sc16is7xx_one *one = to_sc16is7xx_one(port, port);
 
 	if (rs485->flags & SER_RS485_ENABLED) {
-		bool rts_during_rx, rts_during_tx;
-
-		rts_during_rx = rs485->flags & SER_RS485_RTS_AFTER_SEND;
-		rts_during_tx = rs485->flags & SER_RS485_RTS_ON_SEND;
-
-		if (rts_during_rx == rts_during_tx)
-			dev_err(port->dev,
-				"unsupported RTS signalling on_send:%d after_send:%d - exactly one of RS485 RTS flags should be set\n",
-				rts_during_tx, rts_during_rx);
-
 		/*
 		 * RTS signal is handled by HW, it's timing can't be influenced.
 		 * However, it's sometimes useful to delay TX even without RTS
-- 
2.35.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 5/9] serial: omap: remove redundant code in rs485_config
  2022-04-10 10:46 ` Lino Sanfilippo
@ 2022-04-10 10:46   ` Lino Sanfilippo
  -1 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux, richard.genoud, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, shawnguo, s.hauer, kernel, festevam, linux-imx,
	mcoquelin.stm32, alexandre.torgue, linux-serial, linux-kernel,
	linux-arm-kernel, linux-stm32, lukas, p.rosenberger,
	Lino Sanfilippo

In uart_set_rs485_config() the serial core already clamps the RTS delays.
It also assigns the passed serial_rs485 struct to the uart port.

So remove these tasks from the drivers rs485_config() function to avoid
redundancy.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/omap-serial.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 8d5ffa196097..46f4d4cacb6e 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -1336,18 +1336,11 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
 	up->ier = 0;
 	serial_out(up, UART_IER, 0);
 
-	/* Clamp the delays to [0, 100ms] */
-	rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U);
-	rs485->delay_rts_after_send  = min(rs485->delay_rts_after_send, 100U);
-
-	/* store new config */
-	port->rs485 = *rs485;
-
 	if (up->rts_gpiod) {
 		/* enable / disable rts */
-		val = (port->rs485.flags & SER_RS485_ENABLED) ?
+		val = (rs485->flags & SER_RS485_ENABLED) ?
 			SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND;
-		val = (port->rs485.flags & val) ? 1 : 0;
+		val = (rs485->flags & val) ? 1 : 0;
 		gpiod_set_value(up->rts_gpiod, val);
 	}
 
@@ -1358,7 +1351,7 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
 	/* If RS-485 is disabled, make sure the THR interrupt is fired when
 	 * TX FIFO is below the trigger level.
 	 */
-	if (!(port->rs485.flags & SER_RS485_ENABLED) &&
+	if (!(rs485->flags & SER_RS485_ENABLED) &&
 	    (up->scr & OMAP_UART_SCR_TX_EMPTY)) {
 		up->scr &= ~OMAP_UART_SCR_TX_EMPTY;
 		serial_out(up, UART_OMAP_SCR, up->scr);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 5/9] serial: omap: remove redundant code in rs485_config
@ 2022-04-10 10:46   ` Lino Sanfilippo
  0 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux-arm-kernel, alexandre.belloni, mcoquelin.stm32,
	Lino Sanfilippo, richard.genoud, festevam, s.hauer, linux,
	alexandre.torgue, ludovic.desroches, lukas, linux-imx, kernel,
	linux-serial, shawnguo, linux-stm32, linux-kernel, p.rosenberger

In uart_set_rs485_config() the serial core already clamps the RTS delays.
It also assigns the passed serial_rs485 struct to the uart port.

So remove these tasks from the drivers rs485_config() function to avoid
redundancy.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/omap-serial.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 8d5ffa196097..46f4d4cacb6e 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -1336,18 +1336,11 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
 	up->ier = 0;
 	serial_out(up, UART_IER, 0);
 
-	/* Clamp the delays to [0, 100ms] */
-	rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U);
-	rs485->delay_rts_after_send  = min(rs485->delay_rts_after_send, 100U);
-
-	/* store new config */
-	port->rs485 = *rs485;
-
 	if (up->rts_gpiod) {
 		/* enable / disable rts */
-		val = (port->rs485.flags & SER_RS485_ENABLED) ?
+		val = (rs485->flags & SER_RS485_ENABLED) ?
 			SER_RS485_RTS_AFTER_SEND : SER_RS485_RTS_ON_SEND;
-		val = (port->rs485.flags & val) ? 1 : 0;
+		val = (rs485->flags & val) ? 1 : 0;
 		gpiod_set_value(up->rts_gpiod, val);
 	}
 
@@ -1358,7 +1351,7 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
 	/* If RS-485 is disabled, make sure the THR interrupt is fired when
 	 * TX FIFO is below the trigger level.
 	 */
-	if (!(port->rs485.flags & SER_RS485_ENABLED) &&
+	if (!(rs485->flags & SER_RS485_ENABLED) &&
 	    (up->scr & OMAP_UART_SCR_TX_EMPTY)) {
 		up->scr &= ~OMAP_UART_SCR_TX_EMPTY;
 		serial_out(up, UART_OMAP_SCR, up->scr);
-- 
2.35.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 6/9] serial: max310: remove redundant memset in rs485_config
  2022-04-10 10:46 ` Lino Sanfilippo
@ 2022-04-10 10:46   ` Lino Sanfilippo
  -1 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux, richard.genoud, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, shawnguo, s.hauer, kernel, festevam, linux-imx,
	mcoquelin.stm32, alexandre.torgue, linux-serial, linux-kernel,
	linux-arm-kernel, linux-stm32, lukas, p.rosenberger,
	Lino Sanfilippo

In uart_set_rs485_config() the serial core already nullifies the padding
field of the passed serial_rs485 struct before returning it to userspace.

Doing the same in the drivers rs485_config() function is redundant, so
remove the concerning memset in this function.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/max310x.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 3112b4a05448..a0b6ea52d133 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -1037,7 +1037,6 @@ static int max310x_rs485_config(struct uart_port *port,
 
 	rs485->flags &= SER_RS485_RTS_ON_SEND | SER_RS485_RX_DURING_TX |
 			SER_RS485_ENABLED;
-	memset(rs485->padding, 0, sizeof(rs485->padding));
 	port->rs485 = *rs485;
 
 	schedule_work(&one->rs_work);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 6/9] serial: max310: remove redundant memset in rs485_config
@ 2022-04-10 10:46   ` Lino Sanfilippo
  0 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux-arm-kernel, alexandre.belloni, mcoquelin.stm32,
	Lino Sanfilippo, richard.genoud, festevam, s.hauer, linux,
	alexandre.torgue, ludovic.desroches, lukas, linux-imx, kernel,
	linux-serial, shawnguo, linux-stm32, linux-kernel, p.rosenberger

In uart_set_rs485_config() the serial core already nullifies the padding
field of the passed serial_rs485 struct before returning it to userspace.

Doing the same in the drivers rs485_config() function is redundant, so
remove the concerning memset in this function.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/max310x.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
index 3112b4a05448..a0b6ea52d133 100644
--- a/drivers/tty/serial/max310x.c
+++ b/drivers/tty/serial/max310x.c
@@ -1037,7 +1037,6 @@ static int max310x_rs485_config(struct uart_port *port,
 
 	rs485->flags &= SER_RS485_RTS_ON_SEND | SER_RS485_RX_DURING_TX |
 			SER_RS485_ENABLED;
-	memset(rs485->padding, 0, sizeof(rs485->padding));
 	port->rs485 = *rs485;
 
 	schedule_work(&one->rs_work);
-- 
2.35.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 7/9] serial: imx: remove redundant assignment in rs485_config
  2022-04-10 10:46 ` Lino Sanfilippo
@ 2022-04-10 10:46   ` Lino Sanfilippo
  -1 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux, richard.genoud, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, shawnguo, s.hauer, kernel, festevam, linux-imx,
	mcoquelin.stm32, alexandre.torgue, linux-serial, linux-kernel,
	linux-arm-kernel, linux-stm32, lukas, p.rosenberger,
	Lino Sanfilippo

In uart_set_rs485_config() the serial core already assigns the passed
serial_rs485 struct to the uart port.

So remove the assignment in the drivers rs485_config() function to avoid
reduncancy.

Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/imx.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index fd38e6ed4fda..e934880febe8 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -1937,8 +1937,6 @@ static int imx_uart_rs485_config(struct uart_port *port,
 	    rs485conf->flags & SER_RS485_RX_DURING_TX)
 		imx_uart_start_rx(port);
 
-	port->rs485 = *rs485conf;
-
 	return 0;
 }
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 7/9] serial: imx: remove redundant assignment in rs485_config
@ 2022-04-10 10:46   ` Lino Sanfilippo
  0 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux-arm-kernel, alexandre.belloni, mcoquelin.stm32,
	Lino Sanfilippo, richard.genoud, festevam, s.hauer, linux,
	alexandre.torgue, ludovic.desroches, lukas, linux-imx, kernel,
	linux-serial, shawnguo, linux-stm32, linux-kernel, p.rosenberger

In uart_set_rs485_config() the serial core already assigns the passed
serial_rs485 struct to the uart port.

So remove the assignment in the drivers rs485_config() function to avoid
reduncancy.

Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/imx.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index fd38e6ed4fda..e934880febe8 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -1937,8 +1937,6 @@ static int imx_uart_rs485_config(struct uart_port *port,
 	    rs485conf->flags & SER_RS485_RX_DURING_TX)
 		imx_uart_start_rx(port);
 
-	port->rs485 = *rs485conf;
-
 	return 0;
 }
 
-- 
2.35.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 8/9] serial: fsl_lpuart: remove redundant code in rs485_config functions
  2022-04-10 10:46 ` Lino Sanfilippo
@ 2022-04-10 10:46   ` Lino Sanfilippo
  -1 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux, richard.genoud, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, shawnguo, s.hauer, kernel, festevam, linux-imx,
	mcoquelin.stm32, alexandre.torgue, linux-serial, linux-kernel,
	linux-arm-kernel, linux-stm32, lukas, p.rosenberger,
	Lino Sanfilippo

In uart_set_rs485_config() the serial core already ensures that only one of
both options RTS on send or RTS after send is set. It also assigns the
passed serial_rs485 struct to the uart port.

So remove the check and the assignment from the drivers rs485_config()
function to avoid redundancy.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/fsl_lpuart.c | 32 --------------------------------
 1 file changed, 32 deletions(-)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 87789872f400..8fea7fd915d2 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -1377,19 +1377,6 @@ static int lpuart_config_rs485(struct uart_port *port,
 		/* Enable auto RS-485 RTS mode */
 		modem |= UARTMODEM_TXRTSE;
 
-		/*
-		 * RTS needs to be logic HIGH either during transfer _or_ after
-		 * transfer, other variants are not supported by the hardware.
-		 */
-
-		if (!(rs485->flags & (SER_RS485_RTS_ON_SEND |
-				SER_RS485_RTS_AFTER_SEND)))
-			rs485->flags |= SER_RS485_RTS_ON_SEND;
-
-		if (rs485->flags & SER_RS485_RTS_ON_SEND &&
-				rs485->flags & SER_RS485_RTS_AFTER_SEND)
-			rs485->flags &= ~SER_RS485_RTS_AFTER_SEND;
-
 		/*
 		 * The hardware defaults to RTS logic HIGH while transfer.
 		 * Switch polarity in case RTS shall be logic HIGH
@@ -1402,9 +1389,6 @@ static int lpuart_config_rs485(struct uart_port *port,
 			modem |= UARTMODEM_TXRTSPOL;
 	}
 
-	/* Store the new configuration */
-	sport->port.rs485 = *rs485;
-
 	writeb(modem, sport->port.membase + UARTMODEM);
 	return 0;
 }
@@ -1428,19 +1412,6 @@ static int lpuart32_config_rs485(struct uart_port *port,
 		/* Enable auto RS-485 RTS mode */
 		modem |= UARTMODEM_TXRTSE;
 
-		/*
-		 * RTS needs to be logic HIGH either during transfer _or_ after
-		 * transfer, other variants are not supported by the hardware.
-		 */
-
-		if (!(rs485->flags & (SER_RS485_RTS_ON_SEND |
-				SER_RS485_RTS_AFTER_SEND)))
-			rs485->flags |= SER_RS485_RTS_ON_SEND;
-
-		if (rs485->flags & SER_RS485_RTS_ON_SEND &&
-				rs485->flags & SER_RS485_RTS_AFTER_SEND)
-			rs485->flags &= ~SER_RS485_RTS_AFTER_SEND;
-
 		/*
 		 * The hardware defaults to RTS logic HIGH while transfer.
 		 * Switch polarity in case RTS shall be logic HIGH
@@ -1453,9 +1424,6 @@ static int lpuart32_config_rs485(struct uart_port *port,
 			modem |= UARTMODEM_TXRTSPOL;
 	}
 
-	/* Store the new configuration */
-	sport->port.rs485 = *rs485;
-
 	lpuart32_write(&sport->port, modem, UARTMODIR);
 	return 0;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 8/9] serial: fsl_lpuart: remove redundant code in rs485_config functions
@ 2022-04-10 10:46   ` Lino Sanfilippo
  0 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux-arm-kernel, alexandre.belloni, mcoquelin.stm32,
	Lino Sanfilippo, richard.genoud, festevam, s.hauer, linux,
	alexandre.torgue, ludovic.desroches, lukas, linux-imx, kernel,
	linux-serial, shawnguo, linux-stm32, linux-kernel, p.rosenberger

In uart_set_rs485_config() the serial core already ensures that only one of
both options RTS on send or RTS after send is set. It also assigns the
passed serial_rs485 struct to the uart port.

So remove the check and the assignment from the drivers rs485_config()
function to avoid redundancy.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/fsl_lpuart.c | 32 --------------------------------
 1 file changed, 32 deletions(-)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 87789872f400..8fea7fd915d2 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -1377,19 +1377,6 @@ static int lpuart_config_rs485(struct uart_port *port,
 		/* Enable auto RS-485 RTS mode */
 		modem |= UARTMODEM_TXRTSE;
 
-		/*
-		 * RTS needs to be logic HIGH either during transfer _or_ after
-		 * transfer, other variants are not supported by the hardware.
-		 */
-
-		if (!(rs485->flags & (SER_RS485_RTS_ON_SEND |
-				SER_RS485_RTS_AFTER_SEND)))
-			rs485->flags |= SER_RS485_RTS_ON_SEND;
-
-		if (rs485->flags & SER_RS485_RTS_ON_SEND &&
-				rs485->flags & SER_RS485_RTS_AFTER_SEND)
-			rs485->flags &= ~SER_RS485_RTS_AFTER_SEND;
-
 		/*
 		 * The hardware defaults to RTS logic HIGH while transfer.
 		 * Switch polarity in case RTS shall be logic HIGH
@@ -1402,9 +1389,6 @@ static int lpuart_config_rs485(struct uart_port *port,
 			modem |= UARTMODEM_TXRTSPOL;
 	}
 
-	/* Store the new configuration */
-	sport->port.rs485 = *rs485;
-
 	writeb(modem, sport->port.membase + UARTMODEM);
 	return 0;
 }
@@ -1428,19 +1412,6 @@ static int lpuart32_config_rs485(struct uart_port *port,
 		/* Enable auto RS-485 RTS mode */
 		modem |= UARTMODEM_TXRTSE;
 
-		/*
-		 * RTS needs to be logic HIGH either during transfer _or_ after
-		 * transfer, other variants are not supported by the hardware.
-		 */
-
-		if (!(rs485->flags & (SER_RS485_RTS_ON_SEND |
-				SER_RS485_RTS_AFTER_SEND)))
-			rs485->flags |= SER_RS485_RTS_ON_SEND;
-
-		if (rs485->flags & SER_RS485_RTS_ON_SEND &&
-				rs485->flags & SER_RS485_RTS_AFTER_SEND)
-			rs485->flags &= ~SER_RS485_RTS_AFTER_SEND;
-
 		/*
 		 * The hardware defaults to RTS logic HIGH while transfer.
 		 * Switch polarity in case RTS shall be logic HIGH
@@ -1453,9 +1424,6 @@ static int lpuart32_config_rs485(struct uart_port *port,
 			modem |= UARTMODEM_TXRTSPOL;
 	}
 
-	/* Store the new configuration */
-	sport->port.rs485 = *rs485;
-
 	lpuart32_write(&sport->port, modem, UARTMODIR);
 	return 0;
 }
-- 
2.35.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 9/9] serial: atmel: remove redundant assignment in rs485_config
  2022-04-10 10:46 ` Lino Sanfilippo
@ 2022-04-10 10:46   ` Lino Sanfilippo
  -1 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux, richard.genoud, nicolas.ferre, alexandre.belloni,
	ludovic.desroches, shawnguo, s.hauer, kernel, festevam, linux-imx,
	mcoquelin.stm32, alexandre.torgue, linux-serial, linux-kernel,
	linux-arm-kernel, linux-stm32, lukas, p.rosenberger,
	Lino Sanfilippo

In uart_set_rs485_config() the serial core already assigns the passed
serial_rs485 struct to the uart port.

So remove the assignment from the drivers rs485_config() function to avoid
redundancy.

Acked-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/atmel_serial.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index 3a45e4fc7993..dd1c7e4bd1c9 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -299,11 +299,9 @@ static int atmel_config_rs485(struct uart_port *port,
 	/* Resetting serial mode to RS232 (0x0) */
 	mode &= ~ATMEL_US_USMODE;
 
-	port->rs485 = *rs485conf;
-
 	if (rs485conf->flags & SER_RS485_ENABLED) {
 		dev_dbg(port->dev, "Setting UART to RS485\n");
-		if (port->rs485.flags & SER_RS485_RX_DURING_TX)
+		if (rs485conf->flags & SER_RS485_RX_DURING_TX)
 			atmel_port->tx_done_mask = ATMEL_US_TXRDY;
 		else
 			atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v4 RESEND 9/9] serial: atmel: remove redundant assignment in rs485_config
@ 2022-04-10 10:46   ` Lino Sanfilippo
  0 siblings, 0 replies; 23+ messages in thread
From: Lino Sanfilippo @ 2022-04-10 10:46 UTC (permalink / raw)
  To: gregkh, jirislaby, u.kleine-koenig
  Cc: linux-arm-kernel, alexandre.belloni, mcoquelin.stm32,
	Lino Sanfilippo, richard.genoud, festevam, s.hauer, linux,
	alexandre.torgue, ludovic.desroches, lukas, linux-imx, kernel,
	linux-serial, shawnguo, linux-stm32, linux-kernel, p.rosenberger

In uart_set_rs485_config() the serial core already assigns the passed
serial_rs485 struct to the uart port.

So remove the assignment from the drivers rs485_config() function to avoid
redundancy.

Acked-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/tty/serial/atmel_serial.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index 3a45e4fc7993..dd1c7e4bd1c9 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -299,11 +299,9 @@ static int atmel_config_rs485(struct uart_port *port,
 	/* Resetting serial mode to RS232 (0x0) */
 	mode &= ~ATMEL_US_USMODE;
 
-	port->rs485 = *rs485conf;
-
 	if (rs485conf->flags & SER_RS485_ENABLED) {
 		dev_dbg(port->dev, "Setting UART to RS485\n");
-		if (port->rs485.flags & SER_RS485_RX_DURING_TX)
+		if (rs485conf->flags & SER_RS485_RX_DURING_TX)
 			atmel_port->tx_done_mask = ATMEL_US_TXRDY;
 		else
 			atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
-- 
2.35.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH v4 RESEND 9/9] serial: atmel: remove redundant assignment in rs485_config
  2022-04-10 10:46   ` Lino Sanfilippo
@ 2022-04-11  8:27     ` Claudiu.Beznea
  -1 siblings, 0 replies; 23+ messages in thread
From: Claudiu.Beznea @ 2022-04-11  8:27 UTC (permalink / raw)
  To: LinoSanfilippo, gregkh, jirislaby, u.kleine-koenig
  Cc: linux-arm-kernel, alexandre.belloni, mcoquelin.stm32,
	richard.genoud, festevam, s.hauer, linux, alexandre.torgue,
	Ludovic.Desroches, lukas, linux-imx, kernel, linux-serial,
	shawnguo, linux-stm32, linux-kernel, p.rosenberger

On 10.04.2022 13:46, Lino Sanfilippo wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> In uart_set_rs485_config() the serial core already assigns the passed
> serial_rs485 struct to the uart port.
> 
> So remove the assignment from the drivers rs485_config() function to avoid
> redundancy.
> 
> Acked-by: Richard Genoud <richard.genoud@gmail.com>
> Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>

Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>


> ---
>  drivers/tty/serial/atmel_serial.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index 3a45e4fc7993..dd1c7e4bd1c9 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -299,11 +299,9 @@ static int atmel_config_rs485(struct uart_port *port,
>         /* Resetting serial mode to RS232 (0x0) */
>         mode &= ~ATMEL_US_USMODE;
> 
> -       port->rs485 = *rs485conf;
> -
>         if (rs485conf->flags & SER_RS485_ENABLED) {
>                 dev_dbg(port->dev, "Setting UART to RS485\n");
> -               if (port->rs485.flags & SER_RS485_RX_DURING_TX)
> +               if (rs485conf->flags & SER_RS485_RX_DURING_TX)
>                         atmel_port->tx_done_mask = ATMEL_US_TXRDY;
>                 else
>                         atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
> --
> 2.35.1
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v4 RESEND 9/9] serial: atmel: remove redundant assignment in rs485_config
@ 2022-04-11  8:27     ` Claudiu.Beznea
  0 siblings, 0 replies; 23+ messages in thread
From: Claudiu.Beznea @ 2022-04-11  8:27 UTC (permalink / raw)
  To: LinoSanfilippo, gregkh, jirislaby, u.kleine-koenig
  Cc: linux-arm-kernel, alexandre.belloni, mcoquelin.stm32,
	richard.genoud, festevam, s.hauer, linux, alexandre.torgue,
	Ludovic.Desroches, lukas, linux-imx, kernel, linux-serial,
	shawnguo, linux-stm32, linux-kernel, p.rosenberger

On 10.04.2022 13:46, Lino Sanfilippo wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> In uart_set_rs485_config() the serial core already assigns the passed
> serial_rs485 struct to the uart port.
> 
> So remove the assignment from the drivers rs485_config() function to avoid
> redundancy.
> 
> Acked-by: Richard Genoud <richard.genoud@gmail.com>
> Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>

Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>


> ---
>  drivers/tty/serial/atmel_serial.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index 3a45e4fc7993..dd1c7e4bd1c9 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -299,11 +299,9 @@ static int atmel_config_rs485(struct uart_port *port,
>         /* Resetting serial mode to RS232 (0x0) */
>         mode &= ~ATMEL_US_USMODE;
> 
> -       port->rs485 = *rs485conf;
> -
>         if (rs485conf->flags & SER_RS485_ENABLED) {
>                 dev_dbg(port->dev, "Setting UART to RS485\n");
> -               if (port->rs485.flags & SER_RS485_RX_DURING_TX)
> +               if (rs485conf->flags & SER_RS485_RX_DURING_TX)
>                         atmel_port->tx_done_mask = ATMEL_US_TXRDY;
>                 else
>                         atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
> --
> 2.35.1
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Move RS485 implementation from drivers to serial core (v4 RESEND)
  2022-04-10 10:46 ` Lino Sanfilippo
                   ` (9 preceding siblings ...)
  (?)
@ 2022-09-20 11:43 ` Lukas Wunner
  -1 siblings, 0 replies; 23+ messages in thread
From: Lukas Wunner @ 2022-09-20 11:43 UTC (permalink / raw)
  To: Lino Sanfilippo
  Cc: gregkh, jirislaby, u.kleine-koenig, linux, richard.genoud,
	nicolas.ferre, alexandre.belloni, ludovic.desroches, shawnguo,
	s.hauer, kernel, festevam, linux-imx, mcoquelin.stm32,
	alexandre.torgue, linux-serial, linux-kernel, linux-arm-kernel,
	linux-stm32, p.rosenberger

On Sun, Apr 10, 2022 at 12:46:33PM +0200, Lino Sanfilippo wrote:
> This patch series is an attempt to simplify rs485 implementation in drivers
> by moving the following tasks out of the drivers into the serial core:
> 
> - ensure sane RTS settings: in case of an invalid configuration (both RTS
>   after send and RTS on send set or both unset) enable RTS on send and
>   disable RTS after send
[...]
> Redundant code has been removed from the following drivers for now:
> 
> - atmel
> - fsl_lpuart
> - amba
> - imx
> - max310x
> - omap-serial
> - sc16is7xx
> - stm32-usart

It looks like there's more of this cruft left at least in
serial8250_em485_config()...

Thanks,

Lukas

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2022-09-20 11:44 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-10 10:46 Move RS485 implementation from drivers to serial core (v4 RESEND) Lino Sanfilippo
2022-04-10 10:46 ` Lino Sanfilippo
2022-04-10 10:46 ` [PATCH v4 RESEND 1/9] serial: core: move RS485 configuration tasks from drivers into core Lino Sanfilippo
2022-04-10 10:46   ` Lino Sanfilippo
2022-04-10 10:46 ` [PATCH v4 RESEND 2/9] serial: amba-pl011: remove redundant code in rs485_config Lino Sanfilippo
2022-04-10 10:46   ` Lino Sanfilippo
2022-04-10 10:46 ` [PATCH v4 RESEND 3/9] serial: stm32: " Lino Sanfilippo
2022-04-10 10:46   ` Lino Sanfilippo
2022-04-10 10:46 ` [PATCH v4 RESEND 4/9] serial: sc16is7xx: remove redundant check " Lino Sanfilippo
2022-04-10 10:46   ` Lino Sanfilippo
2022-04-10 10:46 ` [PATCH v4 RESEND 5/9] serial: omap: remove redundant code " Lino Sanfilippo
2022-04-10 10:46   ` Lino Sanfilippo
2022-04-10 10:46 ` [PATCH v4 RESEND 6/9] serial: max310: remove redundant memset " Lino Sanfilippo
2022-04-10 10:46   ` Lino Sanfilippo
2022-04-10 10:46 ` [PATCH v4 RESEND 7/9] serial: imx: remove redundant assignment " Lino Sanfilippo
2022-04-10 10:46   ` Lino Sanfilippo
2022-04-10 10:46 ` [PATCH v4 RESEND 8/9] serial: fsl_lpuart: remove redundant code in rs485_config functions Lino Sanfilippo
2022-04-10 10:46   ` Lino Sanfilippo
2022-04-10 10:46 ` [PATCH v4 RESEND 9/9] serial: atmel: remove redundant assignment in rs485_config Lino Sanfilippo
2022-04-10 10:46   ` Lino Sanfilippo
2022-04-11  8:27   ` Claudiu.Beznea
2022-04-11  8:27     ` Claudiu.Beznea
2022-09-20 11:43 ` Move RS485 implementation from drivers to serial core (v4 RESEND) Lukas Wunner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.