* [PATCH 2/9] Documentation: serial-rs485: document SER_RS485_DELAY_IN_USEC flag
2019-02-20 15:27 [PATCH 1/9] serial: uapi: add SER_RS485_DELAY_IN_USEC flag to struct serial_rs485 Martin Kepplinger
@ 2019-02-20 15:27 ` Martin Kepplinger
2019-02-20 15:27 ` [PATCH 3/9] serial: core: add rs485-rts-delay-us devicetree property for RS485 Martin Kepplinger
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Martin Kepplinger @ 2019-02-20 15:27 UTC (permalink / raw)
To: gregkh, robh+dt, mark.rutland, jslaby, corbet, richard.genoud,
nicolas.ferre, alexandre.belloni, ludovic.desroches,
mcoquelin.stm32, alexandre.torgue, linux-serial, devicetree,
linux-arm-kernel, linux-stm32
Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 916 bytes --]
Document the new RS485 flag, SER_RS485_DELAY_IN_USEC that specifies that the
rts delay values stored in struct serial_rs485 hold values in microseconds
instead of milliseconds (the default).
Signed-off-by: Martin Kepplinger <martin.kepplinger@ginzinger.com>
---
Documentation/serial/serial-rs485.txt | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Documentation/serial/serial-rs485.txt b/Documentation/serial/serial-rs485.txt
index ce0c1a9b8aab..a1e15e9efc2e 100644
--- a/Documentation/serial/serial-rs485.txt
+++ b/Documentation/serial/serial-rs485.txt
@@ -75,6 +75,9 @@
/* Set rts delay after send, if needed: */
rs485conf.delay_rts_after_send = ...;
+ /* Specify the rts delay to be microseconds, not milliseconds */
+ rs485conf.flags |= SER_RS485_DELAY_IN_USEC;
+
/* Set this flag if you want to receive data even while sending data */
rs485conf.flags |= SER_RS485_RX_DURING_TX;
--
2.20.1
[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3616 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/9] serial: core: add rs485-rts-delay-us devicetree property for RS485
2019-02-20 15:27 [PATCH 1/9] serial: uapi: add SER_RS485_DELAY_IN_USEC flag to struct serial_rs485 Martin Kepplinger
2019-02-20 15:27 ` [PATCH 2/9] Documentation: serial-rs485: document SER_RS485_DELAY_IN_USEC flag Martin Kepplinger
@ 2019-02-20 15:27 ` Martin Kepplinger
2019-02-20 15:27 ` [PATCH 4/9] serial: 8250: add support for rs485 RTS delays in microseconds Martin Kepplinger
2019-02-20 15:27 ` [PATCH 5/9] serial: omap-serial: " Martin Kepplinger
3 siblings, 0 replies; 5+ messages in thread
From: Martin Kepplinger @ 2019-02-20 15:27 UTC (permalink / raw)
To: gregkh, robh+dt, mark.rutland, jslaby, corbet, richard.genoud,
nicolas.ferre, alexandre.belloni, ludovic.desroches,
mcoquelin.stm32, alexandre.torgue, linux-serial, devicetree,
linux-arm-kernel, linux-stm32
Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2141 bytes --]
struct serial_rs485 now optionally holds the rts delay values in
microseconds. Users can set these delays in their devicetree descriptions,
so this adds the microseconds-option with the "rs485-rts-delay-us" boolean
property.
Signed-off-by: Martin Kepplinger <martin.kepplinger@ginzinger.com>
---
Documentation/devicetree/bindings/serial/rs485.txt | 1 +
drivers/tty/serial/serial_core.c | 11 +++++++++++
2 files changed, 12 insertions(+)
diff --git a/Documentation/devicetree/bindings/serial/rs485.txt b/Documentation/devicetree/bindings/serial/rs485.txt
index b92592dff6dd..77396c62b383 100644
--- a/Documentation/devicetree/bindings/serial/rs485.txt
+++ b/Documentation/devicetree/bindings/serial/rs485.txt
@@ -12,6 +12,7 @@ Optional properties:
* b is the delay between end of data sent and rts signal in milliseconds
it corresponds to the delay after sending data and actual release of the line.
If this property is not specified, <0 0> is assumed.
+- rs485-rts-delay-us: the same as rs485-rts-delay, but in microseconds.
- rs485-rts-active-low: drive RTS low when sending (default is high).
- linux,rs485-enabled-at-boot-time: empty property telling to enable the rs485
feature at boot time. It can be disabled later with proper ioctl.
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 556f50aa1b58..4fb265b2c0fe 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3097,6 +3097,17 @@ void uart_get_rs485_mode(struct device *dev, struct serial_rs485 *rs485conf)
rs485conf->delay_rts_after_send = 0;
}
+ ret = device_property_read_u32_array(dev, "rs485-rts-delay-us",
+ rs485_delay, 2);
+ if (!ret) {
+ rs485conf->delay_rts_before_send = rs485_delay[0];
+ rs485conf->delay_rts_after_send = rs485_delay[1];
+ rs485conf->flags |= SER_RS485_DELAY_IN_USEC;
+ } else {
+ rs485conf->delay_rts_before_send = 0;
+ rs485conf->delay_rts_after_send = 0;
+ }
+
/*
* Clear full-duplex and enabled flags, set RTS polarity to active high
* to get to a defined state with the following properties:
--
2.20.1
[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3616 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/9] serial: 8250: add support for rs485 RTS delays in microseconds
2019-02-20 15:27 [PATCH 1/9] serial: uapi: add SER_RS485_DELAY_IN_USEC flag to struct serial_rs485 Martin Kepplinger
2019-02-20 15:27 ` [PATCH 2/9] Documentation: serial-rs485: document SER_RS485_DELAY_IN_USEC flag Martin Kepplinger
2019-02-20 15:27 ` [PATCH 3/9] serial: core: add rs485-rts-delay-us devicetree property for RS485 Martin Kepplinger
@ 2019-02-20 15:27 ` Martin Kepplinger
2019-02-20 15:27 ` [PATCH 5/9] serial: omap-serial: " Martin Kepplinger
3 siblings, 0 replies; 5+ messages in thread
From: Martin Kepplinger @ 2019-02-20 15:27 UTC (permalink / raw)
To: gregkh, robh+dt, mark.rutland, jslaby, corbet, richard.genoud,
nicolas.ferre, alexandre.belloni, ludovic.desroches,
mcoquelin.stm32, alexandre.torgue, linux-serial, devicetree,
linux-arm-kernel, linux-stm32
Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 3089 bytes --]
Read struct serial_rs485's flag SER_RS485_DELAY_IN_USEC and apply the delay
accordingly.
Signed-off-by: Martin Kepplinger <martin.kepplinger@ginzinger.com>
---
drivers/tty/serial/8250/8250_omap.c | 13 +++++++++++--
drivers/tty/serial/8250/8250_port.c | 25 +++++++++++++++++++++----
2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index 0a8316632d75..cbce43ac60b1 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -720,8 +720,17 @@ static int omap_8250_rs485_config(struct uart_port *port,
struct uart_8250_port *up = up_to_u8250p(port);
/* 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);
+ if (rs485->flags & SER_RS485_DELAY_IN_USEC) {
+ rs485->delay_rts_before_send = min(rs485->delay_rts_before_send,
+ 100000U);
+ rs485->delay_rts_after_send = min(rs485->delay_rts_after_send,
+ 100000U);
+ } else {
+ rs485->delay_rts_before_send = min(rs485->delay_rts_before_send,
+ 100U);
+ rs485->delay_rts_after_send = min(rs485->delay_rts_after_send,
+ 100U);
+ }
port->rs485 = *rs485;
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index d2f3310abe54..0cee4aa8323d 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -1483,6 +1483,15 @@ static void start_hrtimer_ms(struct hrtimer *hrt, unsigned long msec)
hrtimer_start(hrt, t, HRTIMER_MODE_REL);
}
+static void start_hrtimer_us(struct hrtimer *hrt, unsigned long usec)
+{
+ long sec = usec / 1000000;
+ long nsec = (usec % 1000000) * 1000000000;
+ ktime_t t = ktime_set(sec, nsec);
+
+ hrtimer_start(hrt, t, HRTIMER_MODE_REL);
+}
+
static void __stop_tx_rs485(struct uart_8250_port *p)
{
struct uart_8250_em485 *em485 = p->em485;
@@ -1493,8 +1502,12 @@ static void __stop_tx_rs485(struct uart_8250_port *p)
*/
if (p->port.rs485.delay_rts_after_send > 0) {
em485->active_timer = &em485->stop_tx_timer;
- start_hrtimer_ms(&em485->stop_tx_timer,
- p->port.rs485.delay_rts_after_send);
+ if (p->port.rs485.flags & SER_RS485_DELAY_IN_USEC)
+ start_hrtimer_us(&em485->stop_tx_timer,
+ p->port.rs485.delay_rts_after_send);
+ else
+ start_hrtimer_ms(&em485->stop_tx_timer,
+ p->port.rs485.delay_rts_after_send);
} else {
__do_stop_tx_rs485(p);
}
@@ -1600,8 +1613,12 @@ static inline void start_tx_rs485(struct uart_port *port)
if (up->port.rs485.delay_rts_before_send > 0) {
em485->active_timer = &em485->start_tx_timer;
- start_hrtimer_ms(&em485->start_tx_timer,
- up->port.rs485.delay_rts_before_send);
+ if (up->port.rs485.flags & SER_RS485_DELAY_IN_USEC)
+ start_hrtimer_us(&em485->start_tx_timer,
+ up->port.rs485.delay_rts_before_send);
+ else
+ start_hrtimer_ms(&em485->start_tx_timer,
+ up->port.rs485.delay_rts_before_send);
return;
}
}
--
2.20.1
[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3616 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 5/9] serial: omap-serial: add support for rs485 RTS delays in microseconds
2019-02-20 15:27 [PATCH 1/9] serial: uapi: add SER_RS485_DELAY_IN_USEC flag to struct serial_rs485 Martin Kepplinger
` (2 preceding siblings ...)
2019-02-20 15:27 ` [PATCH 4/9] serial: 8250: add support for rs485 RTS delays in microseconds Martin Kepplinger
@ 2019-02-20 15:27 ` Martin Kepplinger
3 siblings, 0 replies; 5+ messages in thread
From: Martin Kepplinger @ 2019-02-20 15:27 UTC (permalink / raw)
To: gregkh, robh+dt, mark.rutland, jslaby, corbet, richard.genoud,
nicolas.ferre, alexandre.belloni, ludovic.desroches,
mcoquelin.stm32, alexandre.torgue, linux-serial, devicetree,
linux-arm-kernel, linux-stm32
Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2402 bytes --]
Read struct serial_rs485's flag SER_RS485_DELAY_IN_USEC and apply the delay
accordingly.
Signed-off-by: Martin Kepplinger <martin.kepplinger@ginzinger.com>
---
drivers/tty/serial/omap-serial.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 6420ae581a80..adcd75ce5112 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -310,7 +310,11 @@ static void serial_omap_stop_tx(struct uart_port *port)
res = (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) ?
1 : 0;
if (gpio_get_value(up->rts_gpio) != res) {
- if (port->rs485.delay_rts_after_send > 0)
+ if (port->rs485.delay_rts_after_send > 0 &&
+ port->rs485.flags & SER_RS485_DELAY_IN_USEC)
+ udelay(
+ port->rs485.delay_rts_after_send);
+ else if (port->rs485.delay_rts_after_send > 0)
mdelay(
port->rs485.delay_rts_after_send);
gpio_set_value(up->rts_gpio, res);
@@ -420,7 +424,11 @@ static void serial_omap_start_tx(struct uart_port *port)
res = (port->rs485.flags & SER_RS485_RTS_ON_SEND) ? 1 : 0;
if (gpio_get_value(up->rts_gpio) != res) {
gpio_set_value(up->rts_gpio, res);
- if (port->rs485.delay_rts_before_send > 0)
+ if (port->rs485.delay_rts_before_send > 0 &&
+ port->rs485.flags & SER_RS485_DELAY_IN_USEC)
+ udelay(port->rs485.delay_rts_before_send);
+ else if (port->rs485.delay_rts_before_send > 0 &&
+ !(port->rs485.flags & SER_RS485_DELAY_IN_USEC)
mdelay(port->rs485.delay_rts_before_send);
}
}
@@ -1407,8 +1415,17 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
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);
+ if (port->rs485.flags & SER_RS485_DELAY_IN_USEC) {
+ rs485->delay_rts_before_send = min(rs485->delay_rts_before_send,
+ 100000U);
+ rs485->delay_rts_after_send = min(rs485->delay_rts_after_send,
+ 100000U);
+ } else {
+ rs485->delay_rts_before_send = min(rs485->delay_rts_before_send,
+ 100);
+ rs485->delay_rts_after_send = min(rs485->delay_rts_after_send,
+ 100U);
+ }
/* store new config */
port->rs485 = *rs485;
--
2.20.1
[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3616 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread