Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1562520rwb; Wed, 16 Nov 2022 21:04:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf4EoT8XLji5nSiK6tFId5Tio4doziYX+y/Tr2GP87tCssodCc2VZzWod1BqQE8/uQdXKUBf X-Received: by 2002:a63:e411:0:b0:45f:b2a7:2659 with SMTP id a17-20020a63e411000000b0045fb2a72659mr657045pgi.132.1668661457774; Wed, 16 Nov 2022 21:04:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668661457; cv=none; d=google.com; s=arc-20160816; b=wMb3TQVWn2mir+JaeNtTEPmLAlt8bgKmlO66AOGgNrfVe75XFjNqpgO2CUgLJrwk3M j7WTqeuHycKPaRXnk92sVFvkqs193DTXGQS2W7waMtCtK1aLhE83I9+hlgohpFGyHvSt a65lUIpZHR8kSCnO+RhSHabIw/JVr6FPWyVmrCSf2DBkj6ZH8Yg4NAJUfDrWxgfgZt+V vnMVKvHUdX74C6AnNmGZMPGKsh1eeFDKrrB7KjLgVAgXWvAE3FwmqD0BVT28G+yB3s2v 9IeWofigQRslfT2twnwvA3w8pSPcS2Uo+SnGFy2Nt6IjaQsg+faRkcLE73BcE3BjUfPb HHaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UH0uo3qvfT0N8FgInW/HXfCMnUVmG+wYXW7ts8IIhMc=; b=sg0MU3MWh0Qfxtbje5KGJGyiv1hsnMQVpU/zdLvV3PJjZKUdyx1ow8Joga8V0LKVDZ LkegrCi4gnU/+vQ0pTocjllAdIbhYFEaptCRE4SSK9zw/zZKC+BiE4WNkiYCBLf3I+1a igQHeoPdg2+evMrYvGNT3CSO4yA1j9vRR9TTUl+qY5+ULd/u34Nk+kLn++TFEnOScqA9 kPSrRverX8MlWnzEuYs20JmzdvoIVozYjHNb+beaIXLzAUEZrdMmLs6CMXb0TwtohTDa OjuyLTJIZSGJlh3YsjzoK5KwFqVotn1WXPxZOJAh+FQXBBSjeKjrXkAd1GluNM8xl80Z w0EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=hnWPIQBa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a656388000000b0046fd9ddc689si39484pgv.571.2022.11.16.21.04.05; Wed, 16 Nov 2022 21:04:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=hnWPIQBa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238829AbiKQFBo (ORCPT + 91 others); Thu, 17 Nov 2022 00:01:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234681AbiKQFBb (ORCPT ); Thu, 17 Nov 2022 00:01:31 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9CAE654E4; Wed, 16 Nov 2022 21:01:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1668661279; x=1700197279; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KtXZOYbD4plLDa2Ad1WCAaIg5uR0r+ACgPobtXvRYeU=; b=hnWPIQBaJEGKYFGXoeJGNXpiLaWr64RQ4bDJEjv4Y9j9kZCPKU6ZV5In QrzzObErA0/+EKbsmrkbhbCifiwAuws1DYtRxJcIOk2Mz4+5glTPcVrHK HUcqVY+XLu4SiNdYhUN4YJPxDPp1OAFCn4DUwb440zwJhm1V1Qy4hOU1R xF8X0UdjtSkusVBcNF8FNMhZUgdWJjsJ2y9zu5kWSxCtRPpo68JAr66qI zK+ortNYNbIvmHkI03CNTRNeT9vijQezFCgkxRUbnSMdmLbNC5kcQDxpN 2HQ1Vd9VLKPT1Z1YHgXT/7Y3SC99JShz69zOPKEgLMm26F8PBSC9UJXHC A==; X-IronPort-AV: E=Sophos;i="5.96,169,1665471600"; d="scan'208";a="187387079" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 16 Nov 2022 22:01:18 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Wed, 16 Nov 2022 22:01:18 -0700 Received: from CHE-LT-UNGSOFTWARE.microchip.com (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Wed, 16 Nov 2022 22:01:12 -0700 From: Kumaravel Thiagarajan To: , CC: , , , , , , , , , , , , , , , , , Tharun Kumar P 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 Message-ID: <20221117050126.2966714-4-kumaravel.thiagarajan@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221117050126.2966714-1-kumaravel.thiagarajan@microchip.com> References: <20221117050126.2966714-1-kumaravel.thiagarajan@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Tharun Kumar P Signed-off-by: Kumaravel Thiagarajan --- 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