gl-infra-builder-FUjr/patches-22.03.4/2008-rs485-auto-txrx.patch
Jianhui Zhao 6205851d07 /patches-22.03.4: clean
Signed-off-by: Jianhui Zhao <jianhui.zhao@gl-inet.com>
2023-06-09 16:29:11 +08:00

98 lines
3.3 KiB
Diff

From 8420e17cbd3a8030da71da0b990047e2983cb7a4 Mon Sep 17 00:00:00 2001
From: Hongjian Zhang <hongjian.zhang@gl-inet.com>
Date: Thu, 8 Jun 2023 16:39:42 +0800
Subject: [PATCH] fix glinet rs485 auto txrx
---
.../821-fix-glinet-rs485-auto-txrx.patch | 78 +++++++++++++++++++
1 file changed, 78 insertions(+)
create mode 100644 target/linux/generic/hack-5.10/821-fix-glinet-rs485-auto-txrx.patch
diff --git a/target/linux/generic/hack-5.10/821-fix-glinet-rs485-auto-txrx.patch b/target/linux/generic/hack-5.10/821-fix-glinet-rs485-auto-txrx.patch
new file mode 100644
index 0000000000..ffbc50138e
--- /dev/null
+++ b/target/linux/generic/hack-5.10/821-fix-glinet-rs485-auto-txrx.patch
@@ -0,0 +1,78 @@
+Index: b/drivers/tty/serial/8250/8250.h
+===================================================================
+--- a/drivers/tty/serial/8250/8250.h 2022-11-11 15:32:57.058347175 +0800
++++ b/drivers/tty/serial/8250/8250.h 2022-11-11 15:32:57.054347212 +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 2022-11-11 15:32:57.058347175 +0800
++++ b/drivers/tty/serial/8250/8250_of.c 2022-11-11 15:32:57.054347212 +0800
+@@ -193,6 +193,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;
+@@ -233,6 +234,9 @@ static int of_platform_serial_probe(stru
+ "overrun-throttle-ms",
+ &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)
+Index: b/drivers/tty/serial/8250/8250_port.c
+===================================================================
+--- a/drivers/tty/serial/8250/8250_port.c 2022-11-11 15:32:57.058347175 +0800
++++ b/drivers/tty/serial/8250/8250_port.c 2022-11-11 15:34:05.781713932 +0800
+@@ -31,6 +31,7 @@
+ #include <linux/uaccess.h>
+ #include <linux/pm_runtime.h>
+ #include <linux/ktime.h>
++#include <linux/gpio/consumer.h>
+
+ #include <asm/io.h>
+ #include <asm/irq.h>
+@@ -1499,10 +1500,18 @@ 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)
+@@ -1548,6 +1557,10 @@ static inline void __start_tx(struct uar
+ {
+ struct uart_8250_port *up = up_to_u8250p(port);
+
++ if(0xff != rs485txen_gpio){
++ gpiod_set_value(gpio_to_desc(rs485txen_gpio),1);
++ }
++
+ if (up->dma && !up->dma->tx_dma(up))
+ return;
+
--
2.17.1