From patchwork Sun Apr 10 10:46:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12808119 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 83188C433F5 for ; Sun, 10 Apr 2022 10:49:20 +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=00sUBzMhEnyTj+ycBZ3xnZcrY6P8d88mB13X6MolFRw=; b=ig0xme33RS9wBS UdIlL87Z0U6RLmXmB4GB9ghtVpqgNVssJXqqZzvySCb6Wiqxgyr+lhBxCLQTGYtdLTXoTE+grLhC+ Ws5J1I22ZHw8Hi3RDvYC+WJp74/brCXvsefOBUUyowTx0hyv5v7rM2Xfdi9uflYNpniRFwGhpgGIt 9wmE8OTtVb4tnvdoMy4ZbKdigzgh1WPnfBcGNApb9Rdss9Ml01IxjyZ3IcFxqHJNRlm09C1MjfA6b yeZ9aA9RvDKP6L8TBHFmVbNuijD04cMVYR5ULSOIS7bVFgiMQeSAOMKSirn7JQHt/KnBjveR2cQzw 2mB15aAg/IEIKp9eCjrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndV72-004fza-Fk; Sun, 10 Apr 2022 10:48:08 +0000 Received: from mout.gmx.net ([212.227.15.18]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndV6Q-004foJ-9r for linux-arm-kernel@lists.infradead.org; Sun, 10 Apr 2022 10:47:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1649587635; bh=bcuHE5LYV9+TYYYh0ydrJw7GifQW+gzYXpAJjFrVMQk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=lMxvV4i1Ks1xzYR/VWUoE2+ZOsd6jl0EDnc6VmK6Y8SGiscZalFKsnaKaeUwa4NOZ CtaP1VasZJFVM1r9u8kdYAK97CboQr5vQhSnHAt54MfkgmgqE4xGeh/PyW0/GIGHng Re6o7NEhpJiEnUjuj4kX85JcpB+dIyfWSWHjN2w0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.230]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N7QxL-1o2xMU2AST-017q8t; Sun, 10 Apr 2022 12:47:15 +0200 From: Lino Sanfilippo To: gregkh@linuxfoundation.org, jirislaby@kernel.org, u.kleine-koenig@pengutronix.de Subject: [PATCH v4 RESEND 1/9] serial: core: move RS485 configuration tasks from drivers into core Date: Sun, 10 Apr 2022 12:46:34 +0200 Message-Id: <20220410104642.32195-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220410104642.32195-1-LinoSanfilippo@gmx.de> References: <20220410104642.32195-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Cbf0m5TvH0ivlHwoDqjuX1YEpNeDKfr+7WrIDoXnHJHL5oc9rwR RR0tSPb0vgFgGpPm+NbS5IewZHnWiWlo3WHhYEGogSv1pHWCU+XP7+YOQsda4ZD3VeG2b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eWdAi3jqtoJqJKN+LcG3ayi9GJzLNCPEWW1yrtkUkP 9NMm85Xr1uMQvIYGRO2otn6PQfEaBT/5szjjfS5ZzAEMpaQMc8aH3tDgVj+DR5ghhEQW0YkFa YVHkVFeq5axL29QilBQRMFo0YII5dPxgyqoHWWLPjMYi0uvXezu/AdrT4GKEwfsXKmpBh7R2u dlX7syztAov0lU= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_034730_676198_7296C59C X-CRM114-Status: GOOD ( 14.05 ) 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, p.rosenberger@kunbus.com 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 one 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 behaviour among all drivers. Signed-off-by: Lino Sanfilippo --- drivers/tty/serial/serial_core.c | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) base-commit: 3123109284176b1532874591f7c81f3837bbdc17 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 6a8963caf954..108b389e6e12 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -42,6 +42,11 @@ static struct lock_class_key port_lock_key; #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8) +/* + * Max time with active RTS before/after data is sent. + */ +#define RS485_MAX_RTS_DELAY 100 /* msecs */ + static void uart_change_speed(struct tty_struct *tty, struct uart_state *state, struct ktermios *old_termios); static void uart_wait_until_sent(struct tty_struct *tty, int timeout); @@ -1296,8 +1301,36 @@ 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)) { + dev_warn_ratelimited(port->dev, + "%s (%d): invalid RTS setting, using RTS_ON_SEND instead\n", + port->name, port->line); + rs485.flags |= SER_RS485_RTS_ON_SEND; + rs485.flags &= ~SER_RS485_RTS_AFTER_SEND; + } + + if (rs485.delay_rts_before_send > RS485_MAX_RTS_DELAY) { + rs485.delay_rts_before_send = RS485_MAX_RTS_DELAY; + dev_warn_ratelimited(port->dev, + "%s (%d): RTS delay before sending clamped to %u ms\n", + port->name, port->line, rs485.delay_rts_before_send); + } + + if (rs485.delay_rts_after_send > RS485_MAX_RTS_DELAY) { + rs485.delay_rts_after_send = RS485_MAX_RTS_DELAY; + dev_warn_ratelimited(port->dev, + "%s (%d): RTS delay after sending clamped to %u ms\n", + port->name, port->line, rs485.delay_rts_after_send); + } + /* Return clean padding area to userspace */ + 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;