Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp726349rwe; Wed, 24 Aug 2022 08:06:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR6h+KxAe5zLUxUdKQjpgTPCaI8hcIYT5kT3pmPNYhH914MYq2h9OLvFvECdbeNoAiJT5smJ X-Received: by 2002:a62:cdc2:0:b0:536:5c11:c342 with SMTP id o185-20020a62cdc2000000b005365c11c342mr19181309pfg.42.1661353576512; Wed, 24 Aug 2022 08:06:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661353576; cv=none; d=google.com; s=arc-20160816; b=fgt7AQRIBmfz/VxKZBz9I3Xe/CdXr/tvTOv88bDA7sczUvNqxL19plnCMzuiY9bxQC ci2Rh4F3dBfgmTw3mAoNSAQnDzBzS5KFUuwPqExxz8RJNPOkZX3xSKUD+DLHvyOgTAsP JDsWhh20PZFgutfac1/fmsX4tZadgn0dp0XLy9PrGMCohbkuqXMsaksFE8jZNUNcVujd 3/H89Zt/szDoGt+U4XWagFzZs/fbDVFaSZqCN2uAHftoDSUYH0YyU4klxG2aLxtDnbGM 6fKO7ZzaPvQuVexw5CKfmm/DqbY8NHoB+cXxteBpzwqThp4PDTufSI5hrYYnkVYDkltf 0ceA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=C7k4/qzmbvcHbk1t4Y6psduPJGM7mWy0IEOqEdfux6A=; b=lU5Ctq4iuw3Vg5e12xWvcr0+qAezzjXGYxJ3NBQRwK97OJB8wxpRSKE4MeF1L/zAWi UvP4ElNv9I+oeaS4X1IJsz1elf8jr0d8zN9RMNFDHjGteLspBxwJSAkOpaDe2dQ9jnCT p3IyDA0DBCZXYL9wj8msIFu865H7IMrtHSAETJwNzfXmeXObr2vSi++a/xHLNuXnaR6v IzspKQS4i1WLnnshOri8+dX7FnRV6JNOPT+RvM7UATkyTO13i3R5yuxm88zax49Gp8JB Z6rPxoz7e5aEdPza/0V7tdxAbKxw8bxcAlqsHMqHFSBiqiXa5o7oG6CqeJiNw0LzjFbp uDJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=wqpAip+y; 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 o12-20020a170902d4cc00b0016d910ac9d1si15781400plg.119.2022.08.24.08.06.05; Wed, 24 Aug 2022 08:06:16 -0700 (PDT) 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=wqpAip+y; 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 S239205AbiHXO34 (ORCPT + 99 others); Wed, 24 Aug 2022 10:29:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239228AbiHXO3y (ORCPT ); Wed, 24 Aug 2022 10:29:54 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B451D10D0; Wed, 24 Aug 2022 07:29:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1661351388; x=1692887388; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=p+lH+5Wlft7OPjVPOMmWKBVBb/o4houeAm+ShSEsIt0=; b=wqpAip+yeFY2/53mvk97BPGaCDl8Ikjrtdx47aVJoIRdqqBfV+D5ds70 zD25NBY9SGBruptgFeBy/7upP5BCRb03tGG65eBRLXmoBw7kjplrY2s4H 9EhcqLbusfWqFhfchVDaFeK9SH5Ug6iVRWVuNgJJV/Go4b+stGg5+oro/ 6vdVSEv5EZFWqYyBEYHLExXkVD33UEBzI+4RukzZmy8z73mpUkN7e2CVh K0uWXFxr+2B3oKiQKZg1pc6e60K4EiAAUbUu8UTxbp3u2O7hkrenph28o MJMyyVtCx5Qa7q3BSVdPH+zFc7A2/1q9rm7tr7jqwIeCqQV9OEI4bspap w==; X-IronPort-AV: E=Sophos;i="5.93,260,1654585200"; d="scan'208";a="177706682" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 24 Aug 2022 07:29:48 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) 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 07:29:47 -0700 Received: from ROB-ULT-M68701.microchip.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Wed, 24 Aug 2022 07:29:44 -0700 From: Sergiu Moga To: , , , , , , , , , CC: , , , , Sergiu Moga Subject: [PATCH v2] tty: serial: atmel: Preserve previous USART mode if RS485 disabled Date: Wed, 24 Aug 2022 17:29:03 +0300 Message-ID: <20220824142902.502596-1-sergiu.moga@microchip.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit 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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 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 that were passed. Example of how this issue could reveal itself: When doing a serial communication with Hardware Flow Control through `linux-serial-test`, the tool would lead to the driver roughly doing the following: - set the corresponding bit to 1 (ATMEL_US_USMODE_HWHS bit in the ATMEL_US_MR register) through the atmel_set_termios() to enable Hardware Flow Control - disable RS485 through the atmel_config_rs485() method Thus, when the latter is called, the mode will be reset and the previously set bit is unset, leaving USART in normal mode instead of the expected Hardware Flow Control mode. This fix ensures that this reset is only done if the checking for RS485 succeeds and that the previous mode is preserved otherwise. Fixes: e8faff7330a35 ("ARM: 6092/1: atmel_serial: support for RS485 communications") Signed-off-by: Sergiu Moga Reviewed-by: Ilpo Järvinen --- v1 -> v2: - split commit message to slightly shorter bits such that it would be easier to read - add Reviewed-by tag 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