linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Niedermaier <cniedermaier@dh-electronics.com>
To: <linux-serial@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>
Cc: <krzysztof.kozlowski+dt@linaro.org>, <marex@denx.de>,
	<jirislaby@kernel.org>,
	Christoph Niedermaier <cniedermaier@dh-electronics.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Linux Team <linux-imx@nxp.com>
Subject: [PATCH 2/4] serial: core: Add option to control rs485 RX_DURING_TX by a GPIO
Date: Wed, 26 Oct 2022 18:50:47 +0200	[thread overview]
Message-ID: <20221026165049.9541-3-cniedermaier@dh-electronics.com> (raw)
In-Reply-To: <20221026165049.9541-1-cniedermaier@dh-electronics.com>

This patch provides a generic GPIO variable for the use of the rs485
feature RX_DURING_TX controlled by a GPIO. The GPIO is defined by the
devicetree property "rs485-rx-during-tx-gpios". To use it in a low
level serial driver, the evaluation of this variable must be
implemented there accordingly.

Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jirislaby@kernel.org>
Cc: Marek Vasut <marex@denx.de>
Cc: Linux Team <linux-imx@nxp.com>
To: linux-serial@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
---
 drivers/tty/serial/serial_core.c | 12 ++++++++++++
 include/linux/serial_core.h      |  1 +
 2 files changed, 13 insertions(+)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 179ee199df34..63150d922aa1 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3410,6 +3410,7 @@ int uart_get_rs485_mode(struct uart_port *port)
 	struct device *dev = port->dev;
 	u32 rs485_delay[2];
 	int ret;
+	int rx_during_tx_gpio_flag;
 
 	ret = device_property_read_u32_array(dev, "rs485-rts-delay",
 					     rs485_delay, 2);
@@ -3458,6 +3459,17 @@ int uart_get_rs485_mode(struct uart_port *port)
 	if (port->rs485_term_gpio)
 		port->rs485_supported.flags |= SER_RS485_TERMINATE_BUS;
 
+	rx_during_tx_gpio_flag = (rs485conf->flags & SER_RS485_RX_DURING_TX) ?
+				 GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
+	port->rs485_rx_during_tx_gpio = devm_gpiod_get_optional(dev,
+								"rs485-rx-during-tx",
+								rx_during_tx_gpio_flag);
+	if (IS_ERR(port->rs485_rx_during_tx_gpio)) {
+		ret = PTR_ERR(port->rs485_rx_during_tx_gpio);
+		port->rs485_rx_during_tx_gpio = NULL;
+		return dev_err_probe(dev, ret, "Cannot get rs485-rx-during-tx-gpios\n");
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(uart_get_rs485_mode);
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index d657f2a42a7b..b4cdeb6e952a 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -579,6 +579,7 @@ struct uart_port {
 	struct serial_rs485     rs485;
 	struct serial_rs485	rs485_supported;	/* Supported mask for serial_rs485 */
 	struct gpio_desc	*rs485_term_gpio;	/* enable RS485 bus termination */
+	struct gpio_desc	*rs485_rx_during_tx_gpio; /* Controls RS485 Rx enable during Tx */
 	struct serial_iso7816   iso7816;
 	void			*private_data;		/* generic platform data pointer */
 };
-- 
2.11.0


  parent reply	other threads:[~2022-10-26 17:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26 16:50 [PATCH 0/4] tty: serial: Add ability to control rs485 RX_DURING_TX via a GPIO Christoph Niedermaier
2022-10-26 16:50 ` [PATCH 1/4] dt_bindings: rs485: Add binding for GPIO that controls Rx enable during Tx Christoph Niedermaier
2022-10-26 20:59   ` Rob Herring
2022-10-27 12:06     ` Christoph Niedermaier
2022-10-28  6:20       ` Alexander Dahl
2022-10-28  8:27         ` Christoph Niedermaier
2022-10-26 16:50 ` Christoph Niedermaier [this message]
2022-10-26 16:50 ` [PATCH 3/4] serial: imx: Add support for rs485 RX_DURING_TX GPIO Christoph Niedermaier
2022-10-26 16:50 ` [PATCH 4/4] serial: stm32: " Christoph Niedermaier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221026165049.9541-3-cniedermaier@dh-electronics.com \
    --to=cniedermaier@dh-electronics.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-serial@vger.kernel.org \
    --cc=marex@denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).