From patchwork Tue May 31 04:36:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mychaela N. Falconia" X-Patchwork-Id: 577720 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 3E3F7C433F5 for ; Tue, 31 May 2022 04:37:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243851AbiEaEh0 (ORCPT ); Tue, 31 May 2022 00:37:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243847AbiEaEhX (ORCPT ); Tue, 31 May 2022 00:37:23 -0400 Received: from freecalypso.org (freecalypso.org [195.154.163.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FD8F5E178; Mon, 30 May 2022 21:37:21 -0700 (PDT) Received: by freecalypso.org (Postfix, from userid 1001) id 25B0F37401A9; Tue, 31 May 2022 04:36:50 +0000 (UTC) From: "Mychaela N. Falconia" To: Johan Hovold , Greg Kroah-Hartman , Jiri Slaby Cc: linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, mychaela.falconia@gmail.com Subject: [PATCH v2 1/6] tty: add port flag to suppress ready signalling on open In-Reply-To: <20220531043356.8CAB637401A9@freecalypso.org> References: <20220531043356.8CAB637401A9@freecalypso.org> Message-Id: <20220531043650.25B0F37401A9@freecalypso.org> Date: Tue, 31 May 2022 04:36:49 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Johan Hovold Add a NORDY port flag to suppress raising the modem-control lines on open to signal DTE readiness. This can be used to implement a NORDY termios control flag to complement HUPCL, which controls lowering of the modem-control lines on final close. Initially drivers can export the flag through sysfs, which also allows control over the lines on first open. This can be used to prevent undesirable side-effects on open for applications where the DTR and RTS lines are used for non-standard purposes such as generating power-on and reset pulses. Signed-off-by: Johan Hovold [rebase: move from include/linux/tty.h to include/linux/tty_port.h] Signed-off-by: Mychaela N. Falconia --- drivers/tty/tty_port.c | 2 +- include/linux/tty_port.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c index 880608a65773..84831c1b6d10 100644 --- a/drivers/tty/tty_port.c +++ b/drivers/tty/tty_port.c @@ -441,7 +441,7 @@ EXPORT_SYMBOL(tty_port_carrier_raised); */ void tty_port_raise_dtr_rts(struct tty_port *port) { - if (port->ops->dtr_rts) + if (port->ops->dtr_rts && !tty_port_nordy(port)) port->ops->dtr_rts(port, 1); } EXPORT_SYMBOL(tty_port_raise_dtr_rts); diff --git a/include/linux/tty_port.h b/include/linux/tty_port.h index 58e9619116b7..0c1581cbfe2b 100644 --- a/include/linux/tty_port.h +++ b/include/linux/tty_port.h @@ -133,6 +133,7 @@ struct tty_port { #define TTY_PORT_CHECK_CD 4 /* carrier detect enabled */ #define TTY_PORT_KOPENED 5 /* device exclusively opened by kernel */ +#define TTY_PORT_NORDY 6 /* do not raise DTR/RTS on open */ void tty_port_init(struct tty_port *port); void tty_port_link_device(struct tty_port *port, struct tty_driver *driver, @@ -226,6 +227,16 @@ static inline void tty_port_set_kopened(struct tty_port *port, bool val) assign_bit(TTY_PORT_KOPENED, &port->iflags, val); } +static inline bool tty_port_nordy(const struct tty_port *port) +{ + return test_bit(TTY_PORT_NORDY, &port->iflags); +} + +static inline void tty_port_set_nordy(struct tty_port *port, bool val) +{ + assign_bit(TTY_PORT_NORDY, &port->iflags, val); +} + struct tty_struct *tty_port_tty_get(struct tty_port *port); void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty); int tty_port_carrier_raised(struct tty_port *port); From patchwork Tue May 31 04:37:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mychaela N. Falconia" X-Patchwork-Id: 577719 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 F247AC433EF for ; Tue, 31 May 2022 04:37:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243859AbiEaEhh (ORCPT ); Tue, 31 May 2022 00:37:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243858AbiEaEhe (ORCPT ); Tue, 31 May 2022 00:37:34 -0400 Received: from freecalypso.org (freecalypso.org [195.154.163.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC866939F0; Mon, 30 May 2022 21:37:32 -0700 (PDT) Received: by freecalypso.org (Postfix, from userid 1001) id 7AA40374023D; Tue, 31 May 2022 04:37:01 +0000 (UTC) From: "Mychaela N. Falconia" To: Johan Hovold , Greg Kroah-Hartman , Jiri Slaby Cc: linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, mychaela.falconia@gmail.com Subject: [PATCH v2 3/6] serial: core: fully suppress raising DTR & RTS on open if nordy is set In-Reply-To: <20220531043356.8CAB637401A9@freecalypso.org> References: <20220531043356.8CAB637401A9@freecalypso.org> Message-Id: <20220531043701.7AA40374023D@freecalypso.org> Date: Tue, 31 May 2022 04:37:01 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org When nordy sysfs attribute is written as 1, TTY_PORT_NORDY is set, and the call to raise DTR & RTS in tty_port_raise_dtr_rts() is suppressed. However, there is one other place where these signals are also raised on open: uart_port_startup() in drivers/tty/serial/serial_core.c - this other point of raising DTR & RTS also needs to be suppressed if TTY_PORT_NORDY is set. Signed-off-by: Mychaela N. Falconia --- drivers/tty/serial/serial_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index a17ac4efaceb..2a558813afa1 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -236,7 +236,7 @@ static int uart_port_startup(struct tty_struct *tty, struct uart_state *state, * Setup the RTS and DTR signals once the * port is open and ready to respond. */ - if (init_hw && C_BAUD(tty)) + if (init_hw && !tty_port_nordy(&state->port) && C_BAUD(tty)) uart_port_dtr_rts(uport, 1); } From patchwork Tue May 31 04:37:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mychaela N. Falconia" X-Patchwork-Id: 577721 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 2A8FBC433F5 for ; Tue, 31 May 2022 04:37:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243839AbiEaEhL (ORCPT ); Tue, 31 May 2022 00:37:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240933AbiEaEhJ (ORCPT ); Tue, 31 May 2022 00:37:09 -0400 Received: from freecalypso.org (freecalypso.org [195.154.163.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D2AB522FB; Mon, 30 May 2022 21:37:08 -0700 (PDT) Received: by freecalypso.org (Postfix, from userid 1001) id 13427374023E; Tue, 31 May 2022 04:37:07 +0000 (UTC) From: "Mychaela N. Falconia" To: Johan Hovold , Greg Kroah-Hartman , Jiri Slaby Cc: linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, mychaela.falconia@gmail.com Subject: [PATCH v2 4/6] USB: serial: add sysfs attribute to suppress ready signalling on open In-Reply-To: <20220531043356.8CAB637401A9@freecalypso.org> References: <20220531043356.8CAB637401A9@freecalypso.org> Message-Id: <20220531043707.13427374023E@freecalypso.org> Date: Tue, 31 May 2022 04:37:06 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Johan Hovold Add a nordy sysfs attribute to suppress raising the modem-control lines on open to signal DTE readiness. This can be used to prevent undesirable side-effects on open for applications where the DTR and RTS lines are used for non-standard purposes such as generating power-on and reset pulses. Signed-off-by: Johan Hovold Signed-off-by: Mychaela N. Falconia --- drivers/usb/serial/bus.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c index 9e38142acd38..25f8218b2bce 100644 --- a/drivers/usb/serial/bus.c +++ b/drivers/usb/serial/bus.c @@ -29,6 +29,37 @@ static int usb_serial_device_match(struct device *dev, return 0; } +static ssize_t nordy_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct usb_serial_port *port = dev_get_drvdata(dev); + + return sprintf(buf, "%d\n", tty_port_nordy(&port->port)); +} + +static ssize_t nordy_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct usb_serial_port *port = dev_get_drvdata(dev); + bool val; + int ret; + + ret = kstrtobool(buf, &val); + if (ret) + return ret; + + tty_port_set_nordy(&port->port, val); + + return count; +} +static DEVICE_ATTR_RW(nordy); + +static struct attribute *tty_attrs[] = { + &dev_attr_nordy.attr, + NULL +}; +ATTRIBUTE_GROUPS(tty); + static int usb_serial_device_probe(struct device *dev) { struct usb_serial_port *port = to_usb_serial_port(dev); @@ -50,8 +81,8 @@ static int usb_serial_device_probe(struct device *dev) } minor = port->minor; - tty_dev = tty_port_register_device(&port->port, usb_serial_tty_driver, - minor, dev); + tty_dev = tty_port_register_device_attr(&port->port, + usb_serial_tty_driver, minor, dev, port, tty_groups); if (IS_ERR(tty_dev)) { retval = PTR_ERR(tty_dev); goto err_port_remove;