From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7DCFEC00140 for ; Wed, 24 Aug 2022 11:49:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=4/pTnQN0s1DEIS3ux4wFNHARPQlaUAEwo2BGS4zkqJA=; b=Wi8stz2CNOkNGh vDvSs43ATApHDfinm8nBXlseOVp0amnziSbVKjM7i8fEDHlUN6EkcxzMfblnoVAdXMTSj/1p8WcPp 17UIq2hEu4THaLJGlO9RXDYGIE6/HqugQaYR4gxJ+DqA23Y7H22By7smeR4k9doMOSJFEPJFpSyCq x0rlGAOTd/vtzwM9CX7haJml08p7QAWkAfGZitfKmRt8TGUsZJouFTMdWid1XRY/H82SsQg/Hlxy7 +kGLCYEie/4fEqiuRaFPeKhlRM41klz9cR1FxaHlax/8+5Uc5GBOplWq4fUF1M71+lk8Xfg+ieo3u FIge05/pjS/CW58C/4Vw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQos0-00CZfH-St; Wed, 24 Aug 2022 11:48:28 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQorx-00CZcl-57 for linux-arm-kernel@lists.infradead.org; Wed, 24 Aug 2022 11:48:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1661341706; x=1692877706; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=MZDAJgikHNjzvh5Y3euMJ9onTXF+3A93fahuugd7kik=; b=jYcGM8281RQIdnpU3aibmOYB9o+Vm7f/pSpww8Fr6b9utvExrJXbjiUt arw8NPd102bQbQRL1mHehYpaat0l99HhpeqPgM0So5gGVBMSBg5XhteB+ R6jW+VjPVUbH/MBI74MwF168ILOU4+iH3Oo/HDU/2vI2gdmBqyOR33uo6 9RZtNvNxv0qVrB8XwA2jh7Ei4ReYjqf2MHNS0jrSD9jm8xy3xeoFzQBb5 ZOZ9b8LeSQ4x3XGoRFzj7aIn0q/d81KlF7vRU8RlS6pyPRAH0cr/nRLtJ viqsqLPUWTEir+uqUheDB6YB8RWm5mrmM8oQxFnaVMyiTrqskf/PM/uLz Q==; X-IronPort-AV: E=Sophos;i="5.93,260,1654585200"; d="scan'208";a="170713015" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 24 Aug 2022 04:48:21 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) 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; Wed, 24 Aug 2022 04:48:20 -0700 Received: from ROB-ULT-M68701.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Wed, 24 Aug 2022 04:48:17 -0700 From: Sergiu Moga To: , , , , , , , , , , CC: , , , Sergiu Moga Subject: [PATCH] tty: serial: atmel: Preserve previous USART mode if RS485 disabled Date: Wed, 24 Aug 2022 14:42:57 +0300 Message-ID: <20220824114255.444655-1-sergiu.moga@microchip.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220824_044825_301218_CDF86D23 X-CRM114-Status: GOOD ( 15.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Whenever the atmel_rs485_config driver method would be called, the USART mode is reset to normal mode before even checking if RS485 flag is set, thus resulting in losing the previous USART mode in the case where the checking fails. Some tools, such as `linux-serial-test`, lead to the driver calling this method when doing the setup of the serial port: after setting the port mode (Hardware Flow Control, Normal Mode, RS485 Mode, etc.), `linux-serial-test` tries to enable/disable RS485 depending on the commandline arguments passed. If we were to, for example, enable Hardware Flow Control through `linux-serial-test`, the tool would make the driver set the corresponding bit to 1 (ATMEL_US_USMODE_HWHS bit in the ATMEL_US_MR register) through the atmel_set_termios method and then proceed to disabling RS485. This, in turn, causes the ATMEL_US_USMODE_HWHS bit of the ATMEL_US_MR mode register to be unset and, if the checking for RS485 fails, leads to having the mode set back to the ATMEL_US_USMODE_NORMAL normal mode. Since in hardware flow control mode the meanings of the ATMEL_US_RTSDIS and ATMEL_US_RTSEN bits are swapped, this leads to our endpoint leaving the RTS line to high when wanting to receive, which is the opposite of what the other endpoint is expecting in order to start transmitting. This fix ensures that this reset is done only if the checking for RS485 succeeds. Fixes: e8faff7330a35 ("ARM: 6092/1: atmel_serial: support for RS485 communications") Signed-off-by: Sergiu Moga --- drivers/tty/serial/atmel_serial.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 0a0b46ee0955..c29b1fb48694 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -298,9 +298,6 @@ static int atmel_config_rs485(struct uart_port *port, struct ktermios *termios, mode = atmel_uart_readl(port, ATMEL_US_MR); - /* Resetting serial mode to RS232 (0x0) */ - mode &= ~ATMEL_US_USMODE; - if (rs485conf->flags & SER_RS485_ENABLED) { dev_dbg(port->dev, "Setting UART to RS485\n"); if (rs485conf->flags & SER_RS485_RX_DURING_TX) @@ -310,6 +307,7 @@ static int atmel_config_rs485(struct uart_port *port, struct ktermios *termios, atmel_uart_writel(port, ATMEL_US_TTGR, rs485conf->delay_rts_after_send); + mode &= ~ATMEL_US_USMODE; mode |= ATMEL_US_USMODE_RS485; } else { dev_dbg(port->dev, "Setting UART to RS232\n"); -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel