From nobody Thu Apr 9 15:01:23 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2876CC4332F for ; Mon, 7 Nov 2022 12:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232338AbiKGMpt (ORCPT ); Mon, 7 Nov 2022 07:45:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232356AbiKGMpb (ORCPT ); Mon, 7 Nov 2022 07:45:31 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 380A31BEAA; Mon, 7 Nov 2022 04:45:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1667825131; x=1699361131; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1g3ZoLeTzd5buYYEiRhNgZ+0cPrzHWqcCAwXMPpYlQQ=; b=uAsQ8QHZ7miCXKeDd1th2+CcJJ+nXzT041tA4YNLD8BcGF6YITlDFYMG hrwNrGxgFJxzG0nkyEiJKclmdy64+dkQJyInE5OvbDLOsalt2izHddgj7 2irL+dpoVhborzxm7uN1lNxFpGGO1K5VrtRGTBuKHVM4gONBrj3mE57XF 0NSNiM1noircE6DzJGHJoYdO6ZKcg2khpFFW0fu4R4qAKxk3VgVjrzQG8 20NOkXrzcGjTjtwhg48cU9WJUveA3+lVM8mntXoQKWHw+0bhQij9kfNBg q8Yzrd/ro2qitRy9LQ1tjwXxpzOauYz5/KGXXrZIO3nuD3MUGp4kz5dpF w==; X-IronPort-AV: E=Sophos;i="5.96,143,1665471600"; d="scan'208";a="182255428" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 07 Nov 2022 05:45:30 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Mon, 7 Nov 2022 05:45:29 -0700 Received: from CHE-LT-UNGSOFTWARE.microchip.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Mon, 7 Nov 2022 05:45:23 -0700 From: Kumaravel Thiagarajan To: , CC: , , , , , , , , , , , , , , , Subject: [PATCH v3 tty-next 2/3] 8250: microchip: pci1xxxx: Add rs485 support to quad-uart driver Date: Mon, 7 Nov 2022 18:15:16 +0530 Message-ID: <20221107124517.1364484-3-kumaravel.thiagarajan@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221107124517.1364484-1-kumaravel.thiagarajan@microchip.com> References: <20221107124517.1364484-1-kumaravel.thiagarajan@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Kumaravel Thiagarajan Signed-off-by: Tharun Kumar P --- 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 | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/tty/serial/8250/8250_pci1xxxx.c b/drivers/tty/serial/8= 250/8250_pci1xxxx.c index e74e8d63daee..ed3418feb262 100644 --- a/drivers/tty/serial/8250/8250_pci1xxxx.c +++ b/drivers/tty/serial/8250/8250_pci1xxxx.c @@ -137,6 +137,53 @@ static void pci1xxxx_set_divisor(struct uart_port *por= t, unsigned int baud, port->membase + UART_BAUD_CLK_DIVISOR_REG); } =20 +static int pci1xxxx_rs485_config(struct uart_port *port, + struct ktermios *termios, + struct serial_rs485 *rs485) +{ + u32 clock_div =3D readl(port->membase + UART_BAUD_CLK_DIVISOR_REG); + u8 delay_in_baud_periods =3D 0; + u32 baud_period_in_ns =3D 0; + u32 data =3D 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 =3D ADCL_CFG_EN | ADCL_CFG_PIN_SEL; + + if (!(rs485->flags & SER_RS485_RTS_ON_SEND)) + data |=3D ADCL_CFG_POL_SEL; + + if (rs485->delay_rts_after_send) { + baud_period_in_ns =3D + FIELD_GET(BAUD_CLOCK_DIV_INT_MSK, clock_div) * + UART_BIT_SAMPLE_CNT; + delay_in_baud_periods =3D + (rs485->delay_rts_after_send * NSEC_PER_MSEC) / + baud_period_in_ns; + delay_in_baud_periods =3D + min_t(u8, delay_in_baud_periods, + FIELD_MAX(ADCL_CFG_RTS_DELAY_MASK)); + data |=3D FIELD_PREP(ADCL_CFG_RTS_DELAY_MASK, + delay_in_baud_periods); + rs485->delay_rts_after_send =3D + (baud_period_in_ns * delay_in_baud_periods) / + NSEC_PER_MSEC; + rs485->delay_rts_before_send =3D 0; + } + } + writel(data, port->membase + ADCL_CFG_REG); + return 0; +} + +static const struct serial_rs485 pci1xxxx_rs485_supported =3D { + .flags =3D SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | + SER_RS485_RTS_AFTER_SEND, + .delay_rts_after_send =3D 1, + /* Delay RTS before send is not supported */ +}; + static int pci1xxxx_setup(struct pci1xxxx_8250 *priv, struct uart_8250_port *port, int idx) { @@ -186,6 +233,8 @@ static int pci1xxxx_setup(struct pci1xxxx_8250 *priv, port->port.set_termios =3D serial8250_do_set_termios; port->port.get_divisor =3D pci1xxxx_get_divisor; port->port.set_divisor =3D pci1xxxx_set_divisor; + port->port.rs485_config =3D pci1xxxx_rs485_config; + port->port.rs485_supported =3D pci1xxxx_rs485_supported; ret =3D pci_setup_port(priv->dev, port, 0, offset, 0); if (ret < 0) return ret; --=20 2.25.1