linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kumaravel Thiagarajan <kumaravel.thiagarajan@microchip.com>
To: <linux-kernel@vger.kernel.org>, <linux-serial@vger.kernel.org>
Cc: <gregkh@linuxfoundation.org>, <jirislaby@kernel.org>,
	<andriy.shevchenko@linux.intel.com>,
	<ilpo.jarvinen@linux.intel.com>, <macro@orcam.me.uk>,
	<jay.dolan@accesio.com>, <cang1@live.co.uk>,
	<u.kleine-koenig@pengutronix.de>, <wander@redhat.com>,
	<etremblay@distech-controls.com>, <jk@ozlabs.org>,
	<biju.das.jz@bp.renesas.com>, <geert+renesas@glider.be>,
	<phil.edworthy@renesas.com>, <lukas@wunner.de>,
	<UNGLinuxDriver@microchip.com>, <colin.i.king@gmail.com>,
	Tharun Kumar P <tharunkumar.pasumarthi@microchip.com>
Subject: [PATCH v5 tty-next 3/4] 8250: microchip: pci1xxxx: Add RS485 support to quad-uart driver
Date: Thu, 17 Nov 2022 10:31:25 +0530	[thread overview]
Message-ID: <20221117050126.2966714-4-kumaravel.thiagarajan@microchip.com> (raw)
In-Reply-To: <20221117050126.2966714-1-kumaravel.thiagarajan@microchip.com>

pci1xxxx uart supports RS485 mode of operation in the hardware with
auto-direction control with configurable delay for releasing RTS after
the transmission. This patch adds support for the RS485 mode.

Co-developed-by: Tharun Kumar P <tharunkumar.pasumarthi@microchip.com>
Signed-off-by: Tharun Kumar P <tharunkumar.pasumarthi@microchip.com>
Signed-off-by: Kumaravel Thiagarajan <kumaravel.thiagarajan@microchip.com>
---
Changes in v5:
- Removed unnecessary assignments
- Corrected styling issues in comments

Changes in v4:
- No Change

Changes in v3:
- Remove flags sanitization in driver which is taken care in core

Changes in v2:
- move pci1xxxx_rs485_config to a separate patch with
  pci1xxxx_rs485_supported.
---
 drivers/tty/serial/8250/8250_pci1xxxx.c | 50 +++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_pci1xxxx.c b/drivers/tty/serial/8250/8250_pci1xxxx.c
index 02b9c6959dcc..bead9fd4019e 100644
--- a/drivers/tty/serial/8250/8250_pci1xxxx.c
+++ b/drivers/tty/serial/8250/8250_pci1xxxx.c
@@ -139,6 +139,54 @@ static void pci1xxxx_set_divisor(struct uart_port *port, unsigned int baud,
 	       port->membase + UART_BAUD_CLK_DIVISOR_REG);
 }
 
+static int pci1xxxx_rs485_config(struct uart_port *port,
+				 struct ktermios *termios,
+				 struct serial_rs485 *rs485)
+{
+	u32 clock_div = readl(port->membase + UART_BAUD_CLK_DIVISOR_REG);
+	u8 delay_in_baud_periods;
+	u32 baud_period_in_ns;
+	u32 data = 0;
+
+	/*
+	 * pci1xxxx's uart hardware supports only RTS delay after
+	 * Tx and in units of bit times to a maximum of 15
+	 */
+	if (rs485->flags & SER_RS485_ENABLED) {
+		data = ADCL_CFG_EN | ADCL_CFG_PIN_SEL;
+
+		if (!(rs485->flags & SER_RS485_RTS_ON_SEND))
+			data |= ADCL_CFG_POL_SEL;
+
+		if (rs485->delay_rts_after_send) {
+			baud_period_in_ns =
+				FIELD_GET(BAUD_CLOCK_DIV_INT_MSK, clock_div) *
+				UART_BIT_SAMPLE_CNT;
+			delay_in_baud_periods =
+				(rs485->delay_rts_after_send * NSEC_PER_MSEC) /
+				baud_period_in_ns;
+			delay_in_baud_periods =
+				min_t(u8, delay_in_baud_periods,
+				      FIELD_MAX(ADCL_CFG_RTS_DELAY_MASK));
+			data |= FIELD_PREP(ADCL_CFG_RTS_DELAY_MASK,
+					   delay_in_baud_periods);
+			rs485->delay_rts_after_send =
+				(baud_period_in_ns * delay_in_baud_periods) /
+				NSEC_PER_MSEC;
+			rs485->delay_rts_before_send = 0;
+		}
+	}
+	writel(data, port->membase + ADCL_CFG_REG);
+	return 0;
+}
+
+static const struct serial_rs485 pci1xxxx_rs485_supported = {
+	.flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND |
+		 SER_RS485_RTS_AFTER_SEND,
+	.delay_rts_after_send = 1,
+	/* Delay RTS before send is not supported */
+};
+
 static int pci1xxxx_setup(struct pci1xxxx_8250 *priv,
 			  struct uart_8250_port *port, int idx)
 {
@@ -193,6 +241,8 @@ static int pci1xxxx_setup(struct pci1xxxx_8250 *priv,
 	port->port.set_termios = serial8250_do_set_termios;
 	port->port.get_divisor = pci1xxxx_get_divisor;
 	port->port.set_divisor = pci1xxxx_set_divisor;
+	port->port.rs485_config = pci1xxxx_rs485_config;
+	port->port.rs485_supported = pci1xxxx_rs485_supported;
 	ret = serial8250_pci_setup_port(priv->dev, port, 0, offset, 0);
 	if (ret < 0)
 		return ret;
-- 
2.25.1


  parent reply	other threads:[~2022-11-17  5:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-17  5:01 [PATCH v5 tty-next 0/4] 8250: microchip: pci1xxxx: Add driver for the pci1xxxx's quad-uart function Kumaravel Thiagarajan
2022-11-17  5:01 ` [PATCH v5 tty-next 1/4] 8250: microchip: pci1xxxx: Add driver for quad-uart support Kumaravel Thiagarajan
2022-11-17  8:25   ` Andy Shevchenko
2022-11-18  9:37     ` Tharunkumar.Pasumarthi
2022-11-18 10:42       ` Andy Shevchenko
2022-11-25 15:45     ` Tharunkumar.Pasumarthi
2022-11-25 18:03       ` Andy Shevchenko
2022-11-17  5:01 ` [PATCH v5 tty-next 2/4] 8250: microchip: pci1xxxx: Add serial8250_pci_setup_port definition in 8250_pcilib.c Kumaravel Thiagarajan
2022-11-17  6:55   ` Andy Shevchenko
2022-11-18  9:40     ` Tharunkumar.Pasumarthi
2022-11-18 10:43       ` Andy Shevchenko
2022-11-19  3:50         ` Tharunkumar.Pasumarthi
2022-11-19 12:05           ` Andy Shevchenko
2022-11-17 12:26   ` Ilpo Järvinen
2022-11-17  5:01 ` Kumaravel Thiagarajan [this message]
2022-11-17 12:24   ` [PATCH v5 tty-next 3/4] 8250: microchip: pci1xxxx: Add RS485 support to quad-uart driver Ilpo Järvinen
2022-11-17  5:01 ` [PATCH v5 tty-next 4/4] 8250: microchip: pci1xxxx: Add power management functions " Kumaravel Thiagarajan

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=20221117050126.2966714-4-kumaravel.thiagarajan@microchip.com \
    --to=kumaravel.thiagarajan@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=cang1@live.co.uk \
    --cc=colin.i.king@gmail.com \
    --cc=etremblay@distech-controls.com \
    --cc=geert+renesas@glider.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jay.dolan@accesio.com \
    --cc=jirislaby@kernel.org \
    --cc=jk@ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=macro@orcam.me.uk \
    --cc=phil.edworthy@renesas.com \
    --cc=tharunkumar.pasumarthi@microchip.com \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=wander@redhat.com \
    /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).