Skip to contentSkip to conversation

serial: sc16is7xx: bunch of small fixes

PATCH In review Jakub Kicinski 3 participants 12 messages Mar 16, 2015 – Mar 26, 2015 7 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover serial: sc16is7xx: bunch of small fixes

From: Jakub Kicinski <[email protected]>

This series fixes three small problems with the sc16is7xx driver and adds an ability to configure from user space the RTS inversion for RS-485 mode.

None of the fixed issues is pressing so this seems like a -next material (based on tty.git/tty-next).

Jakub Kicinski (4):
sc16is7xx: remove ports on probe error path
sc16is7xx: don't wipe out port configuration on shutdown
sc16is7xx: expose RTS inversion in RS-485 mode
sc16is7xx: enable the clock

 drivers/tty/serial/sc16is7xx.c | 44 ++++++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 12 deletions(-)
Signature · 1 line
2.1.0
#2 lore raw

PATCH 1/4 sc16is7xx: remove ports on probe error path

In reply to a message not in the archive

From: Jakub Kicinski <[email protected]>

If ports are not explicitly removed on the error path the device will not get properly unregistered leaving /dev/ttySC* nodes in the filesystem.

---
 drivers/tty/serial/sc16is7xx.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/tty/serial/sc16is7xx.c +3 -0
index df9a384dfbda..11bb44039a57 100644
@@ -1120,6 +1120,9 @@ static int sc16is7xx_probe(struct device *dev,
 	if (!ret)
 		return 0;
 
+	for (i = 0; i < s->uart.nr; i++)
+		uart_remove_one_port(&s->uart, &s->p[i].port);
+
 	mutex_destroy(&s->mutex);
 
 #ifdef CONFIG_GPIOLIB
Signature · 1 line
2.1.0
#5 lore raw

PATCH 2/4 sc16is7xx: don't wipe out port configuration on shutdown

In reply to a message not in the archive

From: Jakub Kicinski <[email protected]>

EFCR register contains RS-485 configuration which should not be changed by shutdown. Instead of doing a write only update the appropriate bits.

---
 drivers/tty/serial/sc16is7xx.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/tty/serial/sc16is7xx.c +5 -3
index 11bb44039a57..e6b396e584f3 100644
@@ -903,9 +903,11 @@ static void sc16is7xx_shutdown(struct uart_port *port)
 	/* Disable all interrupts */
 	sc16is7xx_port_write(port, SC16IS7XX_IER_REG, 0);
 	/* Disable TX/RX */
-	sc16is7xx_port_write(port, SC16IS7XX_EFCR_REG,
-			     SC16IS7XX_EFCR_RXDISABLE_BIT |
-			     SC16IS7XX_EFCR_TXDISABLE_BIT);
+	sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG,
+			      SC16IS7XX_EFCR_RXDISABLE_BIT |
+			      SC16IS7XX_EFCR_TXDISABLE_BIT,
+			      SC16IS7XX_EFCR_RXDISABLE_BIT |
+			      SC16IS7XX_EFCR_TXDISABLE_BIT);
 
 	sc16is7xx_power(port, 0);
 }
Signature · 1 line
2.1.0
#8 lore raw

PATCH 3/4 sc16is7xx: expose RTS inversion in RS-485 mode

In reply to a message not in the archive

From: Jakub Kicinski <[email protected]>

Hardware is capable of inverting RTS signal when working in RS-485 mode. Expose this functionality to user space. Relay on a matching combination of standard flags (SER_RS485_RTS_ON_SEND and SER_RS485_RTS_AFTER_SEND) to detect when user space is requesting inverted RTS mode.

---
 drivers/tty/serial/sc16is7xx.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)
drivers/tty/serial/sc16is7xx.c +23 -9
index e6b396e584f3..24902d589b07 100644
@@ -829,16 +829,30 @@ static void sc16is7xx_set_termios(struct uart_port *port,
 }
 
 static int sc16is7xx_config_rs485(struct uart_port *port,
-				   struct serial_rs485 *rs485)
+				  struct serial_rs485 *rs485)
 {
-	if (port->rs485.flags & SER_RS485_ENABLED)
-		sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG,
-				      SC16IS7XX_EFCR_AUTO_RS485_BIT,
-				      SC16IS7XX_EFCR_AUTO_RS485_BIT);
-	else
-		sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG,
-				      SC16IS7XX_EFCR_AUTO_RS485_BIT,
-				      0);
+	const u32 mask = SC16IS7XX_EFCR_AUTO_RS485_BIT |
+			 SC16IS7XX_EFCR_RTS_INVERT_BIT;
+	u32 efcr = 0;
+
+	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;
+
+		efcr |= SC16IS7XX_EFCR_AUTO_RS485_BIT;
+
+		if (!rts_during_rx && rts_during_tx)
+			/* default */;
+		else if (rts_during_rx && !rts_during_tx)
+			efcr |= SC16IS7XX_EFCR_RTS_INVERT_BIT;
+		else
+			return -EINVAL;
+	}
+
+	sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, mask, efcr);
+
 	port->rs485 = *rs485;
 
 	return 0;
Signature · 1 line
2.1.0
#16 lore raw

PATCH 4/4 sc16is7xx: enable the clock

In reply to a message not in the archive

From: Jakub Kicinski <[email protected]>

Although clk_disable_unprepare() is called both on .remove() and in .probe() error path, the clock is never actually enabled.

---
 drivers/tty/serial/sc16is7xx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/tty/serial/sc16is7xx.c +1 -0
index 24902d589b07..20573d72715d 100644
@@ -1064,6 +1064,7 @@ static int sc16is7xx_probe(struct device *dev,
 		else
 			return PTR_ERR(s->clk);
 	} else {
+		clk_prepare_enable(s->clk);
 		freq = clk_get_rate(s->clk);
 	}
 
Signature · 1 line
2.1.0
#4 lore raw

Re: [PATCH 1/4] sc16is7xx: remove ports on probe error path

In reply to a message not in the archive
Quoted 7 lines · Jakub Kicinski

From: Jakub Kicinski <[email protected]>

If ports are not explicitly removed on the error path the device will not get properly unregistered leaving /dev/ttySC* nodes in the filesystem.

Quoted 22 lines
---
 drivers/tty/serial/sc16is7xx.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/tty/serial/sc16is7xx.c +3 -0
index df9a384dfbda..11bb44039a57 100644
@@ -1120,6 +1120,9 @@ static int sc16is7xx_probe(struct device *dev,
 	if (!ret)
 		return 0;
 
+	for (i = 0; i < s->uart.nr; i++)
+		uart_remove_one_port(&s->uart, &s->p[i].port);
+
 	mutex_destroy(&s->mutex);
 
 #ifdef CONFIG_GPIOLIB
Signature · 1 line
2.1.0
#7 lore raw

Re: [PATCH 2/4] sc16is7xx: don't wipe out port configuration on shutdown

In reply to a message not in the archive
Quoted 7 lines · Jakub Kicinski

From: Jakub Kicinski <[email protected]>

EFCR register contains RS-485 configuration which should not be changed by shutdown. Instead of doing a write only update the appropriate bits.

Quoted 27 lines
---
 drivers/tty/serial/sc16is7xx.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/tty/serial/sc16is7xx.c +5 -3
index 11bb44039a57..e6b396e584f3 100644
@@ -903,9 +903,11 @@ static void sc16is7xx_shutdown(struct uart_port *port)
 	/* Disable all interrupts */
 	sc16is7xx_port_write(port, SC16IS7XX_IER_REG, 0);
 	/* Disable TX/RX */
-	sc16is7xx_port_write(port, SC16IS7XX_EFCR_REG,
-			     SC16IS7XX_EFCR_RXDISABLE_BIT |
-			     SC16IS7XX_EFCR_TXDISABLE_BIT);
+	sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG,
+			      SC16IS7XX_EFCR_RXDISABLE_BIT |
+			      SC16IS7XX_EFCR_TXDISABLE_BIT,
+			      SC16IS7XX_EFCR_RXDISABLE_BIT |
+			      SC16IS7XX_EFCR_TXDISABLE_BIT);
 
 	sc16is7xx_power(port, 0);
 }
Signature · 1 line
2.1.0
#10 lore raw

Re: [PATCH 3/4] sc16is7xx: expose RTS inversion in RS-485 mode

In reply to a message not in the archive

This makes sense. I did have to fix up my user space app to set SER_RS485_RTS_ON_SEND after applying this patch.

Quoted 9 lines · Jakub Kicinski

From: Jakub Kicinski <[email protected]>

Hardware is capable of inverting RTS signal when working in RS-485 mode. Expose this functionality to user space. Relay on a matching combination of standard flags (SER_RS485_RTS_ON_SEND and SER_RS485_RTS_AFTER_SEND) to detect when user space is requesting inverted RTS mode.

Quoted 52 lines
---
 drivers/tty/serial/sc16is7xx.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)
drivers/tty/serial/sc16is7xx.c +23 -9
index e6b396e584f3..24902d589b07 100644
@@ -829,16 +829,30 @@ static void sc16is7xx_set_termios(struct uart_port *port,
 }
 
 static int sc16is7xx_config_rs485(struct uart_port *port,
-				   struct serial_rs485 *rs485)
+				  struct serial_rs485 *rs485)
 {
-	if (port->rs485.flags & SER_RS485_ENABLED)
-		sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG,
-				      SC16IS7XX_EFCR_AUTO_RS485_BIT,
-				      SC16IS7XX_EFCR_AUTO_RS485_BIT);
-	else
-		sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG,
-				      SC16IS7XX_EFCR_AUTO_RS485_BIT,
-				      0);
+	const u32 mask = SC16IS7XX_EFCR_AUTO_RS485_BIT |
+			 SC16IS7XX_EFCR_RTS_INVERT_BIT;
+	u32 efcr = 0;
+
+	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;
+
+		efcr |= SC16IS7XX_EFCR_AUTO_RS485_BIT;
+
+		if (!rts_during_rx && rts_during_tx)
+			/* default */;
+		else if (rts_during_rx && !rts_during_tx)
+			efcr |= SC16IS7XX_EFCR_RTS_INVERT_BIT;
+		else
+			return -EINVAL;
+	}
+
+	sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, mask, efcr);
+
 	port->rs485 = *rs485;
 
 	return 0;
Signature · 1 line
2.1.0
#18 lore raw

Re: [PATCH 4/4] sc16is7xx: enable the clock

In reply to a message not in the archive
Quoted 6 lines · Jakub Kicinski

From: Jakub Kicinski <[email protected]>

Although clk_disable_unprepare() is called both on .remove() and in .probe() error path, the clock is never actually enabled.

Quoted 20 lines
---
 drivers/tty/serial/sc16is7xx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/tty/serial/sc16is7xx.c +1 -0
index 24902d589b07..20573d72715d 100644
@@ -1064,6 +1064,7 @@ static int sc16is7xx_probe(struct device *dev,
 		else
 			return PTR_ERR(s->clk);
 	} else {
+		clk_prepare_enable(s->clk);
 		freq = clk_get_rate(s->clk);
 	}
 
Signature · 1 line
2.1.0
#12 lore raw

Re: [PATCH 3/4] sc16is7xx: expose RTS inversion in RS-485 mode

In reply to a message not in the archive
Quoted 2 lines · Jon Ringle

This makes sense. I did have to fix up my user space app to set SER_RS485_RTS_ON_SEND after applying this patch.

Yes, perhaps I should have mentioned that this makes the ioctl return -EINVAL when neither of SER_RS485_RTS_*_SEND flags is set. This definitely has potential to break people's apps. Let's see if anyone else has an opinion on this.

I am also very tempted to remove rs485.delay_rts_*_send mdelays from this driver and return -EINVAL in a similar fashion when there are set. Normally when the driver is responsible for wiggling the GPIO/RTS line mdelays can indeed impact when the lines change state but in sc16is7xx case transitions are controlled by HW and there is nothing the driver can do about the the relation between TX/RX mode switch and state of RTS lines... Do you agree?

#13 lore raw

Re: [PATCH 3/4] sc16is7xx: expose RTS inversion in RS-485 mode

Quoted 8 lines · Jakub Kiciński
Quoted 2 lines · Jon Ringle

This makes sense. I did have to fix up my user space app to set SER_RS485_RTS_ON_SEND after applying this patch.

Yes, perhaps I should have mentioned that this makes the ioctl return -EINVAL when neither of SER_RS485_RTS_*_SEND flags is set. This definitely has potential to break people's apps. Let's see if anyone else has an opinion on this.

Yes, don't break people's apps.

I can't take this, sorry.

greg k-h

#15 lore raw

Re: [PATCH 3/4] sc16is7xx: expose RTS inversion in RS-485 mode

In reply to a message not in the archive
Quoted 11 lines · Greg Kroah-Hartman
Quoted 8 lines · Jakub Kiciński
Quoted 2 lines · Jon Ringle

This makes sense. I did have to fix up my user space app to set SER_RS485_RTS_ON_SEND after applying this patch.

Yes, perhaps I should have mentioned that this makes the ioctl return -EINVAL when neither of SER_RS485_RTS_*_SEND flags is set. This definitely has potential to break people's apps. Let's see if anyone else has an opinion on this.

Yes, don't break people's apps.

Do you mean it would be OK if I ignore the incorrect combinations instead of returning -EINVAL or is any user-visible change in the behaviour of the driver unacceptable?