From d5bdb37fd02b420cc6a682bf9e51e7e50658c85b Mon Sep 17 00:00:00 2001 From: "GL.iNet-Hongjian.Zhang" Date: Sat, 18 Sep 2021 14:44:13 +0800 Subject: [PATCH 4/8] add RS485 support --- .../821-fix-glinet-rs485-auto-txrx.patch | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 target/linux/ath79/patches-5.4/821-fix-glinet-rs485-auto-txrx.patch diff --git a/target/linux/ath79/patches-5.4/821-fix-glinet-rs485-auto-txrx.patch b/target/linux/ath79/patches-5.4/821-fix-glinet-rs485-auto-txrx.patch new file mode 100644 index 0000000000..2030cad53d --- /dev/null +++ b/target/linux/ath79/patches-5.4/821-fix-glinet-rs485-auto-txrx.patch @@ -0,0 +1,83 @@ +Index: b/drivers/tty/serial/8250/8250.h +=================================================================== +--- a/drivers/tty/serial/8250/8250.h 2021-08-26 20:55:22.000000000 +0800 ++++ b/drivers/tty/serial/8250/8250.h 2021-09-18 14:30:46.200708724 +0800 +@@ -13,6 +13,8 @@ + + #include "../serial_mctrl_gpio.h" + ++extern unsigned int rs485txen_gpio; ++ + struct uart_8250_dma { + int (*tx_dma)(struct uart_8250_port *p); + int (*rx_dma)(struct uart_8250_port *p); +Index: b/drivers/tty/serial/8250/8250_of.c +=================================================================== +--- a/drivers/tty/serial/8250/8250_of.c 2021-08-26 20:55:22.000000000 +0800 ++++ b/drivers/tty/serial/8250/8250_of.c 2021-09-18 14:41:02.964067786 +0800 +@@ -205,6 +205,7 @@ err_pmruntime: + /* + * Try to register a serial port + */ ++unsigned int rs485txen_gpio = 0xff; + static int of_platform_serial_probe(struct platform_device *ofdev) + { + struct of_serial_info *info; +@@ -246,6 +247,10 @@ static int of_platform_serial_probe(stru + &port8250.overrun_backoff_time_ms) != 0) + port8250.overrun_backoff_time_ms = 0; + ++ if(!of_property_read_u32(ofdev->dev.of_node,"rs485_pin",&rs485txen_gpio)){ ++ pr_info("Serial port to 485 enable,rs485txen_gpio = gpio%d \n",rs485txen_gpio); ++ } ++ + ret = serial8250_register_8250_port(&port8250); + if (ret < 0) + goto err_dispose; +Index: b/drivers/tty/serial/8250/8250_port.c +=================================================================== +--- a/drivers/tty/serial/8250/8250_port.c 2021-08-26 20:55:22.000000000 +0800 ++++ b/drivers/tty/serial/8250/8250_port.c 2021-09-18 14:36:49.548608917 +0800 +@@ -34,6 +34,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -1463,10 +1464,22 @@ static void __stop_tx_rs485(struct uart_ + } + } + ++static unsigned int serial8250_tx_empty(struct uart_port *port); + static inline void __do_stop_tx(struct uart_8250_port *p) + { +- if (serial8250_clear_THRI(p)) ++ if (serial8250_clear_THRI(p)){ ++ + serial8250_rpm_put_tx(p); ++ ++ if(0xff != rs485txen_gpio){ ++ ++ while(!serial8250_tx_empty(&(p->port))){ ++ ++ ; ++ } ++ gpiod_set_value(gpio_to_desc(rs485txen_gpio),0); ++ } ++ } + } + + static inline void __stop_tx(struct uart_8250_port *p) +@@ -1510,6 +1523,10 @@ static void serial8250_stop_tx(struct ua + + static inline void __start_tx(struct uart_port *port) + { ++ if(0xff != rs485txen_gpio){ ++ gpiod_set_value(gpio_to_desc(rs485txen_gpio),1); ++ } ++ + struct uart_8250_port *up = up_to_u8250p(port); + + if (up->dma && !up->dma->tx_dma(up)) -- 2.17.1