Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2949299pxp; Tue, 8 Mar 2022 05:13:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyiVrjHMdsBwRsyvN+IY+l3GT643d3iZOgLL36C0pI7+v5CvJjw4WL+eMgnEeCPcKbjIqnX X-Received: by 2002:a05:6402:51cb:b0:409:e99f:bc1c with SMTP id r11-20020a05640251cb00b00409e99fbc1cmr16306247edd.68.1646745236326; Tue, 08 Mar 2022 05:13:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646745236; cv=none; d=google.com; s=arc-20160816; b=L+PA6a+QtUtU2WoKcCbD7hakhU8sJFaw/iZD3uBInfWHRgomvstQRGnk5vRmd4R94x 5Md4rZfDfAct0V31n5n0nwhds8kURKcNHgHs5DJRgNspov+8Y0OtTZM4lCxfueyD6ej0 Nhq2zlWmBdPggr8mZOthmKe0BOvXBRLdPMgR4LU4TuTrYO6Iyp0I3v8vlOl8L6F3eHfD OPtabG9WnC6tbmFnCkq7lWd6A3gCBXE0xjPqMw+CO+31O2MiR30HUJ49/q2HAmPQSyHb G17IUSb4eK7AQis3NUWtPDkHfLdFB4/XU2vLObj7Y585/V8aUDTobG/XGo9QynCC11KN cSUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=h8//XmONRAISsxHxCygXdrHcMT5DefL1meLeOJZCtJ0=; b=Aq2jdodvORRpL+dgCNFYwcTPiY8XZWTcg01kDPlcXE7wUZsf7bg4n2iFzPhb1em3UI Iz4i/mdYBn3x3L7NIsbUcioanvFdJ6W0F/vdMypohgKY7QZCBrDrqqbPern8jg9ap/zS e6xgtgMfyca/2oI0KtGQXOxmfRRZRyE2273nnJJaCKPP5jR7pP6FEcMuHsm3tAuFjmJu jkoprS1t2SCcZgiQTLxBVW1P8GiNTtSmkrOf9v4eju2A9L1UPykvMB+41Is+xDdTpnp4 kGfjoIa+EscWgZhDqqALX9+1ad81DHCQAZQe4+qBXIIgq+sTHjEkjvO80KEr55/8cloW uUKQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e21-20020a170906505500b006d5ace63574si9380454ejk.396.2022.03.08.05.13.32; Tue, 08 Mar 2022 05:13:56 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245036AbiCGTT5 (ORCPT + 99 others); Mon, 7 Mar 2022 14:19:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237059AbiCGTTz (ORCPT ); Mon, 7 Mar 2022 14:19:55 -0500 Received: from bmailout3.hostsharing.net (bmailout3.hostsharing.net [IPv6:2a01:4f8:150:2161:1:b009:f23e:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05DAA193EB; Mon, 7 Mar 2022 11:18:58 -0800 (PST) Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (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 bmailout3.hostsharing.net (Postfix) with ESMTPS id A9FD9101C0527; Mon, 7 Mar 2022 20:18:54 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 87D06449B49; Mon, 7 Mar 2022 20:18:54 +0100 (CET) Date: Mon, 7 Mar 2022 20:18:54 +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 , Andy Shevchenko , Heikki Krogerus , Raymond Tan , Heiko Stuebner Subject: Re: [PATCH 1/7] serial: 8250_dwlib: RS485 HW half duplex support Message-ID: <20220307191854.GA27748@wunner.de> References: <20220302095606.14818-1-ilpo.jarvinen@linux.intel.com> <20220302095606.14818-2-ilpo.jarvinen@linux.intel.com> <20220306184857.GA19394@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) X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, 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 Mon, Mar 07, 2022 at 11:19:59AM +0200, Ilpo J?rvinen wrote: > On Mon, 7 Mar 2022, Andy Shevchenko wrote: > > On Mon, Mar 7, 2022 at 12:00 AM Lukas Wunner wrote: > > > On Wed, Mar 02, 2022 at 11:56:00AM +0200, Ilpo J?rvinen wrote: > > > > + d->hw_rs485_support = device_property_read_bool(p->dev, "snps,rs485-interface-en"); > > > > + if (d->hw_rs485_support) > > > > + p->rs485_config = dw8250_rs485_config; > > > > + > > > > > > You wrote in the commit message that rs485 support is present from > > > version 4.0 onward. Can't we just check the IP version and enable > > > rs485 support for >= 4.0? That would seem more appropriate instead > > > of introducing yet another new property. > > > > AFAIU this is dependent on the IP syntheses. I.o.w. version 4.0+ is a > > prerequisite, but doesn't automatically mean that there is a support. > > Unfortunately there is no way to tell this clearly in the IP > > configuration register. > > And the IP synthesis only part of the picture, in general case, it'd > also matter that there's something connected to that RE (i.e., > an RS485 transceiver). If an RS-485 transceiver is *soldered* to the UART, the devicetree is supposed to contain the property "linux,rs485-enabled-at-boot-time" under the UART's of_node. In that case the UART driver can (and should) enable rs485 mode already on ->probe. Of course there's also the possibility to enable RS-485 after ->open with the TIOCSRS485 ioctl. That can be used if the transceiver is attached at runtime (which is likely a rare use case) or as a legacy enablement method if the driver lacks linux,rs485-enabled-at-boot-time support. That's for DT platforms, but I suppose you've got ACPI. Not sure how it's handled there, the ACPI 6.4 spec contains a "UART Serial Bus Connection Resource Descriptor" but nothing on RS-485, so I guess the only option is to use regular DT properties in a _DSD object? > I initially had additional version check here while developing this > patch series but it seemed to not provide any added value due those > other factors that need to be considered. Here's another idea: Read TCR register on ->probe. It's POR value is 0x6 if RS-485 is supported by the chip, else 0x0. (Page 220 of the 4.01a spec says UCV register does not exist if additional features are not implemented and reading from this register address returns 0, I suppose the same applies to TCR if RS-485 is not implemented.) Since the driver may change the polarity in the TCR register, be sure to write 0x6 to it on ->remove so that you can still correctly detect presence of the RS-485 feature after unbind/rebind of the driver. Thanks, Lukas