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: 542476 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 B54A0C433FE for ; Sun, 13 Feb 2022 22:34:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238716AbiBMWeJ (ORCPT ); Sun, 13 Feb 2022 17:34:09 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238652AbiBMWd6 (ORCPT ); Sun, 13 Feb 2022 17:33:58 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 192705468F; Sun, 13 Feb 2022 14:33:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1644791630; bh=bZh7fD3BxcL0U4ga7XTlAYTEC0EPT7y619IUOjTzv7Y=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=fJ2J1ZE0XlMRdlW52TUFV8Rls4Wt+oe23eSYWj7DXJWajS3kefqY7OCtnrdOilFc7 +T37tZ8LTjRw72zk+aSv3KVno7C/iOCRieNKqGQ84DjZPXdaPjR6KYIBReP1lx6OSn BVRc9RvsMGN77rACYFoIg6aiL+c+u2qWoXGV4770= 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 Cc: linux@armlinux.org.uk, richard.genoud@gmail.com, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, ludovic.desroches@microchip.com, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, lukas@wunner.de, Lino Sanfilippo 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 pGb79r9pJC9KWgmT7d2YGAKs5egMFgBpJUZOpsIxXRwVf4VSjo2bXW3br64Ayb/nGyae5pI kWJYGVzKhf3TfZQ3c5gGQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:WISNCh6R/yA=:sVlZs0DWuHUGARQn/S3+aK zd59Brdk98FRPHtjNCIj67dB3yZj9E5b+LYZhLTpVVm0twqHHmcruORuTyLEZEEIRRfPbSSbW ZgqggRyclent0AWivDhkySKXNprFXcyH3sjtEBrcigV1Lmz26t8gT4qcdZSc0lZcJcMuaTqgQ TCjjF2z/7nkqoIG36h5kCM1pVZD46mRahcDLQemzyQT3r9ReH6XAk6YuFmz/kGZ7aDIkBgnlK HS6Ojs9BRDudMNxxIxF/yDHaqrRndvwVaqULS5tRHNbdlfG9SbXd8tHGevNhezmL4Jtq+22x+ Dtdb8txG5ry5CPfofYwKG+LGlN1R6/KiJ6EgeMDhhswThOVX6F7+LhOmUFSDJedLpU7IaxpJH HdLqydKblOr5ZACttW1UnusNsgc5Gnr80DtWXT49puMknGy6iCRksJZEWyqyhAnYX5wAPYSq4 RyacO4M4BMjQXvYBBRDajYH7U7nd7VAlSYqlsl80iKFwAiaf+s1VFA0sfawi9xQPMeFvkCAti kt4UvBK7tM1t8MlR+9OZtik7l40ThCct043pcnXvAq2WpN+og438rjTrUYrmqGtq8VGLLcR8H Qg4HjdVwTdEgwiZVzITuneRLiNaVPRcEKDXu54DVxBi3SxZsXrtb2e79Lo1KXQdnIZ4UT/x8p BhuYIgllQmuBRgcIGcCbvZiwyjEiDaSZT3IiavF8R6RDxfvHUrfihiO4I8jDCSc/JU1f+XFXf 6Fnhy6JJTGgVL1v6FMMAHDvUAJTBJAm8weKDLboi2GFitZa1Zyc/X/fCwrIyJJvkFBJ+iB+4e nbfKOvPuyXTLdoP+9NouO4eysr9Y4gNIOU97iYqsLA7rna1Y+m+0/yTgQ8KIPclkVBVB6fdUN aLSDn/P0xP9X/g/kE3ach3bLknEpqGm37qAba4/7DADSUErhSDtOLAjjLehqaNiOASPsDGBl4 Q+TOG+WUz7dVNdm1BbOtuwtVyZSDxdk6IgLfFhoEL3cjlMaH59anz4lqxik39gcDMlDvoJl3l f/meXFdtKSzjdPzHC5rM8JVDEwdSoM6/LQicSYaQu3oNCJEvL6ph5lP0xusLD6BBW09KGKxTo jUS2wR4UmLz2wo= Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.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;