From patchwork Sun Jul 3 17:00:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 587079 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 D3007C43334 for ; Sun, 3 Jul 2022 17:01:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231179AbiGCRBy (ORCPT ); Sun, 3 Jul 2022 13:01:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229730AbiGCRBy (ORCPT ); Sun, 3 Jul 2022 13:01:54 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BFD7615B; Sun, 3 Jul 2022 10:01:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656867690; bh=C3f07IvyTVhB+y3Q1h44bhbt9vRcIn4vLfeS+jIHjl4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=UWg1iEGo6CeHvfMMIMMD9CoHT0jbVNvQN+at0B7mf3usRzdY1V7YQN10p7whaduf4 Td0bpGFkBiZCRpROiY5W9x73UZkSpbeA/t5AzYKFhrP1WuM814C9xzxTtXsZBNGIlP dB6pbCgMy25/R0iizdNEA/ic2poIFkzPTjOdMz2Y= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([46.223.3.210]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MxlzI-1nPIwu0lH4-00zFlf; Sun, 03 Jul 2022 19:01:30 +0200 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: ilpo.jarvinen@linux.intel.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, andriy.shevchenko@linux.intel.com, vz@mleia.com, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, lukas@wunner.de, p.rosenberger@kunbus.com, Lino Sanfilippo Subject: [PATCH v2 1/9] serial: core: only get RS485 termination GPIO if supported Date: Sun, 3 Jul 2022 19:00:31 +0200 Message-Id: <20220703170039.2058202-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220703170039.2058202-1-LinoSanfilippo@gmx.de> References: <20220703170039.2058202-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:BNqEbx/9a7Pb1HYT5WcqGew1ocBgpWVPz7NMEroLwpfbbZWgiNG 7ZgXhoo1Tbtpsx0c8O/Tr7rLINJO3+WiwvgZ5cKUVeGOXXxz6vLlB91Yvab8Z6dDulISFZ6 RfJC5I4LfCOMl/2DuNx+yaeO7/pq2+uU/u0zO8R+liIAANAkdguZPE15z1YR4h8rGHuzPXC wR8nYf3FTb9S5SFa1lbdQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:oOHxaRj80UE=:FXzyBpuwcy/JGOnS5aO/lW Okq6c/8RULC3/s31QGDvwKmhxXuCI+RpcZwuJvTwctvF0AkUGt2H/sUiUM2lzAiJsvsHlkxft VbGjpoU77eMPiC9WXsHYImHUVXkXc7qPNDoCUvrt0Nc95/GHz/AczY1apx29If1P6fxQtdC2x GKJDPf2Wiui5VVaXfQj7v1OUpc/U2buXnJjUwrrgh6aL2ClzrH0RGPVYcNs99WXjLGcTo6lM1 ehuJ0jBbEQ6RRBQUOH3DbEMn1C9HNBDyAURLhjIydo6YhemOIm/ejEiQyryXB5dTikblqLSEb KQmjaOk1g4EXtdi4g9bp7o7lKjWB1TQTXBoNKbDpDhMjb0LxBLWhxNJpQ8RXKqJy84DiXUiJ8 7kJbXw00qPN5v5V9C11hRDi5Ayw6rZkVB87DVS+35ydmMm6LA+eGpasU5BSeuSQvvNQs/tRh2 x2nSNm3i4z+O1QpSYoJjrm4Wkdh2H93IyMzORhYGWnFR/aVea8+pBfdTVe6nQ6WKor86v9R+Z u+zsH6NKK/4U9e8660hA9kUhXOy/8R8iDxhObv2TUgTWR686vcqc3YqCr8xRM7OqHPtYeMLKJ bnzR9/dm5vl3pvisfYe3YBGdT4dmgxCa+t/9JilOIdjkiOI5d7WDw1ebIaamCIZ8+grGUfGM1 ivFitghN1blZXsYJncEElXX+YxMn630Tun5QABH1RsklORACj5tJWEKQaBgCZVMC9ZmKsDnBh Ht7Ux5vWBssGUHiiFbvIXtIjXANGBuKKR3JQThK4EKpyEHyvBXHmYHbBQ4QFmrWFx/HB+hWf9 VooZW9sgqranC7d3CHKIJ6IBt9HA+ydMKIq3+u0mPzFYpkTdvhKJqih3OaIZkZANrEYjs3Xr2 zd7aPMjN3lQs7ttcS+cemVL5/cx9y/LJP5E/g/9CVfMM8AhBdJP4CLr+PxKss/ytWIlCqii5E EDNU0mxEcx5tReyg3e4RgSrdRGbbaa5HXY63IXXyVxSzzist7x5o7vBAo6+lj2HWffuBFWOwB fFo9DUBgMHR2hBERTyicsUi/ugli6rcL9njTgY6kT+7WAY6X5l5nhNYoKyG7cTe6R2et0jLTK txuTm8H+E62W532aldkf+I/PVpgRHLb3mFLe5nGofHYGJQXaamKq3z1DQ== Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Lino Sanfilippo In uart_get_rs485_mode() only try to get a termination GPIO if RS485 bus termination is supported by the driver. This prevents from allocating and holding a GPIO descriptor for the drivers lifetimg that will never be used. Signed-off-by: Lino Sanfilippo --- NOTE: This patch follows the design decision that "rs485_supported" is set by the driver at initialization and cannot be modified afterwards. However the better approach would be to let the serial core modify the termination GPIO support setting based on the existence of a termination GPIO. If "rs485_supported" is not a read-only value any more in future the logic implemented in this patch should be adjusted accordingly. drivers/tty/serial/serial_core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 85ef7ef00b82..3768663dfa4d 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -3404,6 +3404,16 @@ int uart_get_rs485_mode(struct uart_port *port) */ port->rs485_term_gpio = devm_gpiod_get_optional(dev, "rs485-term", GPIOD_OUT_LOW); + + if (port->rs485_term_gpio && + !(port->rs485_supported->flags & SER_RS485_TERMINATE_BUS)) { + dev_warn(port->dev, + "%s (%d): RS485 termination gpio not supported by driver\n", + port->name, port->line); + devm_gpiod_put(dev, port->rs485_term_gpio); + port->rs485_term_gpio = NULL; + } + if (IS_ERR(port->rs485_term_gpio)) { ret = PTR_ERR(port->rs485_term_gpio); port->rs485_term_gpio = NULL;