Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1501122pxb; Wed, 30 Mar 2022 05:08:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDMPnwWv2vSxPKopHqlPGmktatXDqwVZmtICYQJYe0H9+66EH94DvCJFuo3rx1uyncyNRL X-Received: by 2002:a17:906:a3d6:b0:6e1:1e61:f935 with SMTP id ca22-20020a170906a3d600b006e11e61f935mr14588806ejb.676.1648642091053; Wed, 30 Mar 2022 05:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648642090; cv=none; d=google.com; s=arc-20160816; b=eA4AA688+O5cxlYrr7c4Zo2eF5rALuiqtWC02JJtNRcwbfWrYD3jHXvRr8wyvK4ixt tu/QtSNHl8n+AmaBENvp8QHdpZ+UX8tZTYQ1Vg84IFYF/QIHQUe7FbxoxiAjUdk99bEI 3wzyzECZhbDrLu+ZlCPg5JAGb4WfTI5Bk74sH7HWxX+lSZnfs+PM25zE6eSxTgFcmz2X I5b6C58S9AnsFhksiNPM74Wl3MRLD5+cxHdHEl1MxSrNA9tXo82iTCbyxdhfkAYYn5nZ 6ahgVrdTPmWme8gdsbxOMnymEGQS5m6HPS2kGQU18PdcYjnLoUsNm63omdatmr7mqTiK IONA== 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:date:cc:to:from:subject :message-id:dkim-signature:dkim-signature; bh=8PpgMMBxggEaG/tZcyk/fCyr75Mh5Y67wwxxGHsATuM=; b=vvLM1kiELPRAoFMqmuVIdKTEToZNSgOhADRFXJOLzBTx6E8dMXl9p6SOofSnr8xYmK jwqnykkYmPOVl+MSW61aaCWTqXnGSBa7zGFusAhn07LuZH+Q+KJZsX4gWKb/JV65jXsk 2TYC5NSqzROYIqIQm9qMKBEKq6fHQFmX2N25/aEKsh1/imlT83cb41mRRYgvX2qFFvEn ipg4T8mHD4fUm+aSw6UVVBoYqZtFwePfeVePZ90otaHiMk7hEAwWbtlcQUObPSslIYNW /DtndWvGvK0A73PE58oUvtW6u7ZZWgdBRVs5W5/jv3Jy4f/1owYbFCAN5PGoiR5FRcWL SmkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=gI+Oiy9K; dkim=pass header.i=@tq-group.com header.s=key1 header.b=Mt9JQ15R; 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=NONE sp=NONE dis=NONE) header.from=tq-group.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id de45-20020a1709069bed00b006df7eafe421si19228207ejc.127.2022.03.30.05.07.44; Wed, 30 Mar 2022 05:08:10 -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=@tq-group.com header.s=key1 header.b=gI+Oiy9K; dkim=pass header.i=@tq-group.com header.s=key1 header.b=Mt9JQ15R; 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=NONE sp=NONE dis=NONE) header.from=tq-group.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235269AbiC2Kku (ORCPT + 99 others); Tue, 29 Mar 2022 06:40:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231955AbiC2Kks (ORCPT ); Tue, 29 Mar 2022 06:40:48 -0400 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB9699D059; Tue, 29 Mar 2022 03:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1648550345; x=1680086345; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=8PpgMMBxggEaG/tZcyk/fCyr75Mh5Y67wwxxGHsATuM=; b=gI+Oiy9KqNang2pAQPBGwJ1QR5kY5NEfCiFm1brTv0wnGzpp05KDYCSd 3NLAcufCmtrC+5ZETI/r9+8saRN77+mVokc9N0Uv/CEf5c50I8+kqhSVT XnoRtVN1fQqoEwe8qyzz8ut73QIPapQ9BS4C+BtCOvrR8um2baUhTBRho BHvZdTQoCfa4rHXx3m4olgI+RkxSMeS1dewEXtiOpy43AtwWGrI7i/Uis 2XvnoTa5PVuqtf5es/ixPSdc+lAnOw3nwCN+Mrvty5YYDYFqpEuiHis+2 ZAgtPScdrNsElfFH5dYhjZON23bENELXEtPWgekNUguq/8l0x95QADtkU w==; X-IronPort-AV: E=Sophos;i="5.90,220,1643670000"; d="scan'208";a="22957875" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 29 Mar 2022 12:39:02 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Tue, 29 Mar 2022 12:39:02 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Tue, 29 Mar 2022 12:39:02 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1648550342; x=1680086342; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=8PpgMMBxggEaG/tZcyk/fCyr75Mh5Y67wwxxGHsATuM=; b=Mt9JQ15RR+YeUMONNyCMv8bbVhfMrOBRoGgbj/a7OH9fLQmkXyQjfCrs Yd9yYXEvnjvDHaOdL1eXb8LI3prP/Th4wVMa4cfLdtg4KUcJYJ3bn6Mq7 pgO6QfhTaqH+fproUx0/8ZCaY40AqwrvPspwYWkdAX+em8JYb+Icu+vQd JEUvmY8izm5FFBLs1KsXV3zDDMrysYbTNbTlLhbfgHosRh2pORiL0S/Lm q0yhs/XDhATw6xsUID5ESg207xsI70KiME8h4rtRznC79RbWZ3m21Fvrc iV0/yDIyPnXwhTbMNMqWwLf2O479DuHwwKTsg3UOg/HNi/eqG0WmX1zDF g==; X-IronPort-AV: E=Sophos;i="5.90,220,1643670000"; d="scan'208";a="22957874" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 29 Mar 2022 12:39:02 +0200 Received: from schifferm-ubuntu (SCHIFFERM-M2.tq-net.de [10.121.201.138]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id 4A0C4280065; Tue, 29 Mar 2022 12:39:02 +0200 (CEST) Message-ID: Subject: Re: [PATCH] serial: Revert RS485 polarity change on UART open From: Matthias Schiffer To: Lukas Wunner Cc: Greg Kroah-Hartman , Jiri Slaby , Russell King , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Ilpo =?ISO-8859-1?Q?J=E4rvinen?= , Lino Sanfilippo Date: Tue, 29 Mar 2022 12:39:02 +0200 In-Reply-To: <20220329100328.GA2090@wunner.de> References: <20220329085050.311408-1-matthias.schiffer@ew.tq-group.com> <20220329100328.GA2090@wunner.de> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Tue, 2022-03-29 at 12:03 +0200, Lukas Wunner wrote: > [cc += Ilpo, Lino] > > On Tue, Mar 29, 2022 at 10:50:50AM +0200, Matthias Schiffer wrote: > > While the change of the RS485 polarity in > > commit d3b3404df318 ("serial: Fix incorrect rs485 polarity on uart > > open") > > might have made sense based on the original intention of the > > rs485-rts-active-low flag (*), this is not how it is implemented in > > various drivers: > [...] > > [(*) My understanding of the mentioned commit's description is that > > rs485-rts-active-low should have referred to the electical signal > > level > > of the RTS pin, rather than the logical RTS state as understood by > > the > > UART controller.] Hi Lukas, > > Since RTS is often just a GPIO on a pin controller that's configured > to function as RTS, my expectation would be that the same rules apply > to RTS polarity as those that apply to *any* GPIO. > > According to Documentation/devicetree/bindings/gpio/gpio.txt: > > "A gpio-specifier should contain a flag indicating the GPIO polarity; > active- > high or active-low. If it does, the following best practices should > be > followed: > The gpio-specifier's polarity flag should represent the physical > level at the > ^^^^^^^^^^^^ > ^^ > GPIO controller that achieves (or represents, for inputs) a > logically asserted > value at the device." Yes, that would make sense to me as well, but as described, this is not how the majority of drivers that I looked at works at the moment :( I'm not particularly attached to any of the interpretations, but it would be great to have some consistency here. And if the majority of drivers does it the "wrong" way, maybe we should accept that to keep the breakage as small as possible? > > > > At least the 8250 and the i.MX UART drivers interpret rs485-rts- > > active-low > > Which 8250 driver are you referring to specifically? When developing > d3b3404df318, I tested with 8250_bcm2835aux.c and amba-pl011.c. Both > worked exactly the way they should. I tested with 8250_omap.c, which does not implement the RS485 handling itself, but refers to the generic code in 8250_port.c. In fact, my first attempt to get the RS485 to work on my device was the following (which matches the originally intended interpretation of the polarity flag, but breaks existing users): --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1460,9 +1460,9 @@ void serial8250_em485_stop_tx(struct uart_8250_port *p) unsigned char mcr = serial8250_in_MCR(p); if (p->port.rs485.flags & SER_RS485_RTS_AFTER_SEND) - mcr |= UART_MCR_RTS; - else mcr &= ~UART_MCR_RTS; + else + mcr |= UART_MCR_RTS; serial8250_out_MCR(p, mcr); /* @@ -1611,9 +1611,9 @@ void serial8250_em485_start_tx(struct uart_8250_port *up) serial8250_stop_rx(&up->port); if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND) - mcr |= UART_MCR_RTS; - else mcr &= ~UART_MCR_RTS; + else + mcr |= UART_MCR_RTS; serial8250_out_MCR(up, mcr); } > > If imx.c and others have historically interpreted rs485-rts-active- > low > to mean that the physical level is "high" when active, then we could > just > amend imx_uart_probe() such that after calling uart_get_rs485_mode(), > the SER_RS485_RTS_ON_SEND and SER_RS485_RTS_AFTER_SEND bits are > flipped. Would that work for you? > I guess that would work. The fact that even the different variants of the 8250 are implemented inconsistently makes this especially ugly... It certainly puts a damper on the efforts to make the handling of RS485 in serial drivers more generic. > I'll go through the drivers to check which ones are affected. I'm > sorry > that you're seeing breakage, it's surprising to me that these > different > interpretations of rs485-rts-active-low exist. > > Thanks, > > Lukas Regards, Matthias