Skip to content

Commit e34b46d

Browse files
committed
linux-raspberrypi: Control RTS pins for Seeed'd RS-485 implementation
This patch is taken from Seeed: Seeed-Studio@f3864ba It is needed because of the RS-485 implementation Seeed uses on reComputer-r100x. We add this patch on the raspberrypicm4-ioboard OS image because that is what we advise users to select for the Seeed reComputer-r100x hardware. Changelog-entry: Add RTS control for Seeed's RS-485 implementation Signed-off-by: Florin Sarbu <[email protected]>
1 parent 6e8b9a3 commit e34b46d

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
From ec4e5cc6a5e68eb93b4775eb28626cddd0ff7a89 Mon Sep 17 00:00:00 2001
2+
From: qian <[email protected]>
3+
Date: Fri, 16 Aug 2024 06:03:06 +0000
4+
Subject: [PATCH] Add serial RTS control gpio
5+
6+
---
7+
drivers/tty/serial/serial_core.c | 16 ++++++++++++++++
8+
include/linux/serial_core.h | 1 +
9+
2 files changed, 17 insertions(+)
10+
11+
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
12+
index 45b721abaa2f..8fa249678f52 100644
13+
--- a/drivers/tty/serial/serial_core.c
14+
+++ b/drivers/tty/serial/serial_core.c
15+
@@ -567,6 +567,10 @@ static int uart_write(struct tty_struct *tty,
16+
}
17+
18+
port = uart_port_lock(state, flags);
19+
+ if(port->rts_gpio)
20+
+ {
21+
+ gpiod_set_value(port->rts_gpio, 1);
22+
+ }
23+
circ = &state->xmit;
24+
if (!circ->buf) {
25+
uart_port_unlock(port, flags);
26+
@@ -587,6 +591,11 @@ static int uart_write(struct tty_struct *tty,
27+
}
28+
29+
__uart_start(tty);
30+
+
31+
+ if(port->rts_gpio)
32+
+ {
33+
+ gpiod_set_value(port->rts_gpio, 0);
34+
+ }
35+
uart_port_unlock(port, flags);
36+
return ret;
37+
}
38+
@@ -2991,6 +3000,13 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
39+
*/
40+
uport->flags &= ~UPF_DEAD;
41+
42+
+ uport->rts_gpio = devm_gpiod_get_optional(uport->dev, "rts",
43+
+ GPIOD_OUT_LOW);
44+
+ if (IS_ERR(uport->rts_gpio)) {
45+
+ ret = PTR_ERR(uport->rts_gpio);
46+
+ uport->rts_gpio = NULL;
47+
+ return dev_err_probe(uport->dev, ret, "Cannot get rts-gpios\n");
48+
+ }
49+
out:
50+
mutex_unlock(&port->mutex);
51+
mutex_unlock(&port_mutex);
52+
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
53+
index d5b6b1550d59..3ba7bf798bff 100644
54+
--- a/include/linux/serial_core.h
55+
+++ b/include/linux/serial_core.h
56+
@@ -256,6 +256,7 @@ struct uart_port {
57+
struct serial_rs485 rs485;
58+
const struct serial_rs485 *rs485_supported; /* Supported mask for serial_rs485 */
59+
struct gpio_desc *rs485_term_gpio; /* enable RS485 bus termination */
60+
+ struct gpio_desc *rts_gpio; /* enable RS485 RTS */
61+
struct serial_iso7816 iso7816;
62+
void *private_data; /* generic platform data pointer */
63+
};
64+
--
65+
2.25.1
66+

layers/meta-balena-raspberrypi/recipes-kernel/linux/linux-raspberrypi_5.15.bbappend

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ SRC_URI:append:raspberrypi3-unipi-neuron = " \
3838
file://0001-pi3neuron-disable-gccplugins.patch \
3939
"
4040

41+
SRC_URI:append:raspberrypicm4-ioboard = " \
42+
file://0001-Add-serial-RTS-control-gpio.patch \
43+
"
44+
4145
BALENA_CONFIGS:append = " fbtft"
4246
BALENA_CONFIGS[fbtft] = " \
4347
CONFIG_STAGING=y \

0 commit comments

Comments
 (0)