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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6CE3C433FE for ; Tue, 8 Mar 2022 14:50:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347629AbiCHOvn (ORCPT ); Tue, 8 Mar 2022 09:51:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234154AbiCHOvk (ORCPT ); Tue, 8 Mar 2022 09:51:40 -0500 Received: from bmailout1.hostsharing.net (bmailout1.hostsharing.net [IPv6:2a01:37:1000::53df:5f64:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74E2A3C733; Tue, 8 Mar 2022 06:50:43 -0800 (PST) Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "RapidSSL TLS DV RSA Mixed SHA256 2020 CA-1" (verified OK)) by bmailout1.hostsharing.net (Postfix) with ESMTPS id 1E8B730057E8D; Tue, 8 Mar 2022 15:50:42 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 11FC547A006; Tue, 8 Mar 2022 15:50:42 +0100 (CET) Date: Tue, 8 Mar 2022 15:50:42 +0100 From: Lukas Wunner To: Ilpo =?iso-8859-1?Q?J=E4rvinen?= Cc: Andy Shevchenko , "open list:SERIAL DRIVERS" , Jiri Slaby , Greg Kroah-Hartman , Linux Kernel Mailing List , Johan Hovold , Heikki Krogerus , Raymond Tan , Heiko Stuebner Subject: Re: [PATCH 1/7] serial: 8250_dwlib: RS485 HW half duplex support Message-ID: <20220308145042.GA20520@wunner.de> References: <20220302095606.14818-1-ilpo.jarvinen@linux.intel.com> <20220302095606.14818-2-ilpo.jarvinen@linux.intel.com> <20220306184857.GA19394@wunner.de> <20220307191854.GA27748@wunner.de> <6931d6ad-7520-b585-a8ba-35349e730bb@linux.intel.com> <20220308122220.GA24694@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 08, 2022 at 02:59:59PM +0200, Ilpo Järvinen wrote: > On Tue, 8 Mar 2022, Lukas Wunner wrote: > > On Tue, Mar 08, 2022 at 02:16:56PM +0200, Ilpo Järvinen wrote: > > > The SoC also has a pin to select between RS485 and RS232. With a combo > > > transceiver, TCR-based heuristic just runs into the same problems as the > > > version-based one did. > > > > I thought this was about detecting whether hardware-assisted DE assertion > > may be used (versus software-controlled), not about whether to enable > > RS-485 mode. Right? > > HW DE assertion only works when RS485 mode is enabled so I don't see how > these questions could be easily decoupled like that. That's assuming with > "software-controlled" you mean RTS(RS232)+em485? Right, that's what I meant. Enabling RS-485 mode is only supposed to happen upon a TIOCSRS485 ioctl or if the "linux,rs485-enabled-at-boot-time" property is present. We don't need to second-guess the user's decision to enable RS-485 mode. If that's what they've asked for, then we can and should assume that an RS-485 transceiver is attached. Of course, if hardware-assisted DE assertion requires a particular pinmux state, we could double-check whether that pinmux state is set. If the RTS/DE pin is not muxed as a DE pin but rather as an RTS pin, one option would be to fall back to software-controlled RTS assertion. A warning message may be warranted in that case. Whether hardware-assisted DE assertion is supported by the chip can not only be detected by checking for the POR 0x6 value in the TCR register: You can alternatively write a non-zero value to any of the RS-485 registers, then check if reading the register back returns a non-zero value (RE_EN is probably a good candidate). That approach is more robust than relying on the POR value 0x6 in TCR because you never know if boot firmware fiddled with the registers before passing control to the kernel. Thanks, Lukas