From patchwork Sun Feb 13 22:27:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12744711 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 87320C433EF for ; Sun, 13 Feb 2022 22:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TMcMgWNbtGQZFR5deS5wTNF5f4PaaZYVzwivLdBo1cc=; b=I9t8+Xj0pJm5D3 8jnTsixqhHMGyzq/1DbbJKz3OGmHk9kvvLxaS2rvKuL0oqE7yM7MGRDDJsSPjZI2PcRJ1y1Et9iAX /7yk9A7cKw7mjuZ579Gmk9PMEgjYYlJv+qZ8gVtDqD78mJB0hvUc3KAImQg3Gci6TwM5zEA5g2N7n DVQGtUI++9nXtddNvpjeywSOJ1gyhcQSbtH5KnJ0vT44gy8QbTGgb+9K4bCYa5xn1CRr1NHjvasA2 ZBZHgbYJD+mlRGQlA9UPZGnNj8tEeUX+zhmyVMBIYmxU6BGwUWwpCKPLZLHuJ/lk2eK11K/ySAsRn Ib8UFhkFTpPFL5x7Rdxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJNMq-00Ccow-3f; Sun, 13 Feb 2022 22:29:16 +0000 Received: from mout.gmx.net ([212.227.17.21]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nJNLy-00Cca3-57 for linux-arm-kernel@lists.infradead.org; Sun, 13 Feb 2022 22:28:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1644791285; bh=bZh7fD3BxcL0U4ga7XTlAYTEC0EPT7y619IUOjTzv7Y=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=RG8BL/3hnOqCkN8Y2FE9lEVGlXBqqK/fncb4/LOQmAFJUicXB1gEOXVvp4NT8gLkw ZKZhqJGA0wx6NMgIpMIvMGfy8E74XlHo0TjNXC2zu6tyilA0CPugWs2HLCLIphHWTm bg7uEUU9SyC2jP86Jd6+SEL7cVg7eBWBRiMeFgdQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([149.172.237.68]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N9Mtg-1oORt22z8W-015L7F; Sun, 13 Feb 2022 23:28:05 +0100 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org Subject: [PATCH 1/9] serial: core: move RS485 configuration tasks from drivers into core Date: Sun, 13 Feb 2022 23:27:29 +0100 Message-Id: <20220213222737.15709-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220213222737.15709-1-LinoSanfilippo@gmx.de> References: <20220213222737.15709-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:a70uNS3aT4SFE/6OuZPcmU57hS9z6lw3Arpt/2q+1Rn1DqngY4I cqop7d/eCjPhLHz9sZAYXp8ibRRdjqeKMEGk6i8ckZI+xCeYiAixStK8vfEAdAWCt5bZW84 pGb79r9pJC9KWg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pWvxsZEUcdOJem7jWUn3MV tPOvmCzy1o7b7Y+HClYbxJFlSej0xOuLabHMF1D7qen911i/aL06ILU2l4ujGsiU/79Q4oQW+ y5GQAwDhb0/l2UVr+pApKj32Jxuc/FCWJT3VAxG0vPlaFiodRfoj21sV6OvD5mhkQJnQ+sMu0 sw1NHPFrvIt81k= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220213_142822_533522_57EC166C X-CRM114-Status: GOOD ( 11.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, alexandre.belloni@bootlin.com, mcoquelin.stm32@gmail.com, Lino Sanfilippo , richard.genoud@gmail.com, festevam@gmail.com, s.hauer@pengutronix.de, linux@armlinux.org.uk, alexandre.torgue@foss.st.com, ludovic.desroches@microchip.com, lukas@wunner.de, linux-imx@nxp.com, kernel@pengutronix.de, linux-serial@vger.kernel.org, shawnguo@kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Several drivers that support setting the RS485 configuration via userspace implement on or more of the following tasks: - in case of an invalid RTS configuration (both RTS after send and RTS on send set or both unset) fall back to enable RTS on send and disable RTS after send - nullify the padding field of the returned serial_rs485 struct - copy the configuration into the uart port struct - limit RTS delays to 100 ms Move these tasks into the serial core to make them generic and to provide a consistent beheviour among all drivers. Signed-off-by: Lino Sanfilippo --- drivers/tty/serial/serial_core.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) base-commit: ad30d108a5135af584ff47f5ff81be971b6c26f1 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 846192a7b4bf..3fab4070359c 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1282,8 +1282,21 @@ static int uart_set_rs485_config(struct uart_port *port, if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user))) return -EFAULT; + /* pick sane settings if the user hasn't */ + if (!(rs485.flags & SER_RS485_RTS_ON_SEND) == + !(rs485.flags & SER_RS485_RTS_AFTER_SEND)) { + rs485.flags |= SER_RS485_RTS_ON_SEND; + rs485.flags &= ~SER_RS485_RTS_AFTER_SEND; + } + /* clamp the delays to [0, 100ms] */ + rs485.delay_rts_before_send = min(rs485.delay_rts_before_send, 100U); + rs485.delay_rts_after_send = min(rs485.delay_rts_after_send, 100U); + memset(rs485.padding, 0, sizeof(rs485.padding)); + spin_lock_irqsave(&port->lock, flags); ret = port->rs485_config(port, &rs485); + if (!ret) + port->rs485 = rs485; spin_unlock_irqrestore(&port->lock, flags); if (ret) return ret;