Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3597190pxb; Mon, 24 Jan 2022 13:09:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwdIBIp545vNVjVcVXO+HVrUbytiUj+e8P0/h3o1XrdRAL5Xy3OxD64mgJ6LPTjmrtJLShX X-Received: by 2002:a05:6a00:174c:b0:4c9:e7ee:87b8 with SMTP id j12-20020a056a00174c00b004c9e7ee87b8mr4131242pfc.28.1643058541408; Mon, 24 Jan 2022 13:09:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643058541; cv=none; d=google.com; s=arc-20160816; b=SoeSZ596o1iRDOtIlFREmgAjJSkXamf6hdSXfiI1SGyWUqVTY4BPoHQ8dxAT4C39/9 LiLfQFNdQq+s0LnEQ5uOQg+QpRwiIL1OMlSv1CfDFoJmoPccvzc8+gyOr6etUefEyhYT xjVoWvwSq5723honHzbBO9KG8eMRaREGcORaqUMlGVXiXB93VGQXZRSgk1s4LiAfcFje 4ojGmVJ/sL8LtbO0g8sPMurag5nfcsOBYOsLnPMDFCyl6L9W3DSm08E2SZGNp2X43lhM tsC2pN2UKx580MjgYQgj4tGcqkiEbBAhCli5hK4z0tvYRnEW+9OLLtSNm14X5TUEv8XQ ZJ2w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=URawb1dYDN+7Fon7W+qU56TSojx95Y4Sx0ho8IaY4Cw=; b=Gp/rH7UAohNd3zFHh9viQlGJ1hX4i6pSGVbKMIY/Z7ROvG0/QcnwfhEmI670RKi+Dl SkagvpFITPiODf41/AsOsZPpmaZY2lq4HezMVv9Djx40/25GY/kNSpjbxeeRgWL7ZF6U eQI6qbvk4umCuA7wwT0bdLqr3sJbpo6WWyUIzDQ5vhbHtXAi5sMpAfIy7v83oThG+P80 mwZMwL/ttxDta8Xjg/6z5IHRJj3vSZfZF/KdEpySrv6imDirtrPV6zIjCiRSuFosEhTM QOkAsHQ3A2gfsNRheoQFrqI9/cVuGN7HiB6OxLMdViyigDN0BdGnbPzf5reY5W4aMTq0 Gz+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uaMph8oN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d185si3098752pgc.646.2022.01.24.13.08.49; Mon, 24 Jan 2022 13:09:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uaMph8oN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385821AbiAXUej (ORCPT + 99 others); Mon, 24 Jan 2022 15:34:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355459AbiAXUNl (ORCPT ); Mon, 24 Jan 2022 15:13:41 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D013AC0604D1; Mon, 24 Jan 2022 11:37:02 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6E11F614FC; Mon, 24 Jan 2022 19:37:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49DAFC340E5; Mon, 24 Jan 2022 19:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643053021; bh=QR8yZAhBM7iYkAK09ew+ffn9nmVg2lFDcim+AuhC6z0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uaMph8oNPNHKHUdVllV9XuoCJCC1k2saptmg2JZ5XO/DJVM7hR06mMKxM3mkRZLK+ kG6bK7MFXdQaktSytk6gIgTrJ4pOJLNKSWkZi9WfJCcujhUzu0Y4tKlH61TM/yCjA7 6DXfihI26P8vaMbszc8dUSkh/2Bk3JAvNbxXv3G0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rafael Gago Castano , Jan Kiszka , Su Bao Cheng , Lukas Wunner Subject: [PATCH 5.4 251/320] serial: Fix incorrect rs485 polarity on uart open Date: Mon, 24 Jan 2022 19:43:55 +0100 Message-Id: <20220124184002.524758989@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukas Wunner commit d3b3404df318504ec084213ab1065b73f49b0f1d upstream. Commit a6845e1e1b78 ("serial: core: Consider rs485 settings to drive RTS") sought to deassert RTS when opening an rs485-enabled uart port. That way, the transceiver does not occupy the bus until it transmits data. Unfortunately, the commit mixed up the logic and *asserted* RTS instead of *deasserting* it: The commit amended uart_port_dtr_rts(), which raises DTR and RTS when opening an rs232 port. "Raising" actually means lowering the signal that's coming out of the uart, because an rs232 transceiver not only changes a signal's voltage level, it also *inverts* the signal. See the simplified schematic in the MAX232 datasheet for an example: https://www.ti.com/lit/ds/symlink/max232.pdf So, to raise RTS on an rs232 port, TIOCM_RTS is *set* in port->mctrl and that results in the signal being driven low. In contrast to rs232, the signal level for rs485 Transmit Enable is the identity, not the inversion: If the transceiver expects a "high" RTS signal for Transmit Enable, the signal coming out of the uart must also be high, so TIOCM_RTS must be *cleared* in port->mctrl. The commit did the exact opposite, but it's easy to see why given the confusing semantics of rs232 and rs485. Fix it. Fixes: a6845e1e1b78 ("serial: core: Consider rs485 settings to drive RTS") Cc: stable@vger.kernel.org # v4.14+ Cc: Rafael Gago Castano Cc: Jan Kiszka Cc: Su Bao Cheng Signed-off-by: Lukas Wunner Link: https://lore.kernel.org/r/9395767847833f2f3193c49cde38501eeb3b5669.1639821059.git.lukas@wunner.de Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/serial_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -160,7 +160,7 @@ static void uart_port_dtr_rts(struct uar int RTS_after_send = !!(uport->rs485.flags & SER_RS485_RTS_AFTER_SEND); if (raise) { - if (rs485_on && !RTS_after_send) { + if (rs485_on && RTS_after_send) { uart_set_mctrl(uport, TIOCM_DTR); uart_clear_mctrl(uport, TIOCM_RTS); } else { @@ -169,7 +169,7 @@ static void uart_port_dtr_rts(struct uar } else { unsigned int clear = TIOCM_DTR; - clear |= (!rs485_on || !RTS_after_send) ? TIOCM_RTS : 0; + clear |= (!rs485_on || RTS_after_send) ? TIOCM_RTS : 0; uart_clear_mctrl(uport, clear); } }