summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Olivier Huard <pierre-olivier.huard@rtone.fr>2024-02-06 16:22:39 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-02-08 08:15:29 +0100
commit6530d4bad33dbc23fb48e2673600e50e510de41a (patch)
tree821811335c18aecf3d20da02e221da0888cd6c9e
parent8ce3f15f21254e82aab3bc7698db55b54b980eef (diff)
downloadbarebox-6530d4bad33d.tar.gz
barebox-6530d4bad33d.tar.xz
serial: ns16550: add support for half duplex rs485
Some RS485 serial interfaces does not use correctly RTS as Receiver Enable and Data Enable, the internal receiver of the ns16550 must be disabled during transmit to avoid loopback. By default the option is enabled (when the property 'linux,rs485-enabled-at-boot-time' is present), and can be disabled with the property 'rs485-rx-during-tx'. Signed-off-by: Pierre-Olivier Huard <pierre-olivier.huard@rtone.fr> Link: https://lore.barebox.org/20240206152239.341460-3-pierre-olivier.huard@rtone.fr Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/serial/serial_ns16550.c9
-rw-r--r--drivers/serial/serial_ns16550.h4
2 files changed, 13 insertions, 0 deletions
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index 73d8365dac..1b1692658f 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -43,6 +43,7 @@ struct ns16550_priv {
bool rs485_mode;
bool rs485_rts_active_low;
+ bool rs485_rx_during_tx;
};
struct ns16550_drvdata {
@@ -279,6 +280,9 @@ static void ns16550_putc(struct console_device *cdev, char c)
ns16550_write(cdev, MCR_RTS, mcr);
else
ns16550_write(cdev, 0, mcr);
+
+ if (!priv->rs485_rx_during_tx)
+ ns16550_write(cdev, CNTL_TXEN, cntl);
}
ns16550_write(cdev, c, thr);
@@ -292,6 +296,9 @@ static void ns16550_putc(struct console_device *cdev, char c)
ns16550_write(cdev, 0, mcr);
else
ns16550_write(cdev, MCR_RTS, mcr);
+
+ if (!priv->rs485_rx_during_tx)
+ ns16550_write(cdev, CNTL_TXEN | CNTL_RXEN, cntl);
}
}
@@ -350,6 +357,8 @@ static void ns16550_probe_dt(struct device *dev, struct ns16550_priv *priv)
of_property_read_bool(np, "rs485-rts-active-low");
priv->rs485_mode =
of_property_read_bool(np, "linux,rs485-enabled-at-boot-time");
+ priv->rs485_rx_during_tx =
+ of_property_read_bool(np, "rs485-rx-during-tx");
switch (width) {
case 1:
diff --git a/drivers/serial/serial_ns16550.h b/drivers/serial/serial_ns16550.h
index 1c5d9d551a..2d941cb8d1 100644
--- a/drivers/serial/serial_ns16550.h
+++ b/drivers/serial/serial_ns16550.h
@@ -36,6 +36,7 @@
#define lsr 5
#define msr 6
#define scr 7
+#define cntl 8
#define thr rbr
#define iir fcr
@@ -76,6 +77,9 @@
/* Transmitter FIFO completely empty */
#define LSR_EMPTY (LSR_THRE | LSR_TEMT)
+#define CNTL_RXEN 0x01
+#define CNTL_TXEN 0x02
+
/* useful defaults for LCR */
#define LCR_8N1 0x03