From patchwork Mon Nov 30 15:37:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11940903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1857C83012 for ; Mon, 30 Nov 2020 15:38:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 713C120725 for ; Mon, 30 Nov 2020 15:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728337AbgK3Pih (ORCPT ); Mon, 30 Nov 2020 10:38:37 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:44194 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726928AbgK3Pig (ORCPT ); Mon, 30 Nov 2020 10:38:36 -0500 Received: by mail-lf1-f67.google.com with SMTP id d20so22404584lfe.11; Mon, 30 Nov 2020 07:38:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+aLtio6V1+D5pI+gfBa6W9Kw54KOG0u5ylBdBluGMXY=; b=NVsWMmwKOMOtHCSGfbUU6ETtlwnj0vE0ZtyqNkZoPF6SKylswybsq390UbD5eqKZh+ fprl7nCh14ZKchOUnQhPubJJ7ZEBc2CS4S4E+UwP0G3D3jRBTZTmB2+amsx4z/Cz8Wd6 aTK3Aib5Jca6f2aUWm6FLYA9Zklevqh5JQ7s4OT9FyVG3igScEbEf8hFWdhEBmrkKN8U kC+lrtrE2LqdfJ4q97CduVymDvMZeMnEaHUQ/FvfUkLq62C/lSxpCwmbFQEzNkG3Z8N0 U/3wHY2suki9K/uKd1kSZhsS78Pq82SZLPPkGJUQr8EEr/3CnJVcKm4+JnIuObfrCXBq m8Pw== X-Gm-Message-State: AOAM532b8Vi1bmGKt2aIbcYBlMq+wB33w/Nn6Xatqn3GDLBf5C9lqule bh/3odCkzBLL8nI+3/6BFpd0uodSU9afBA== X-Google-Smtp-Source: ABdhPJyK//aBOsqAM2W2TFUh6Gj+kw5QM+xj4FI9UtZblb9pLbYEAsTUAl2xtclS10ebD23bLMN34A== X-Received: by 2002:a19:711:: with SMTP id 17mr9667668lfh.131.1606750674171; Mon, 30 Nov 2020 07:37:54 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id t6sm2498672lfk.207.2020.11.30.07.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 07:37:52 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kjlFu-0002Oh-Lm; Mon, 30 Nov 2020 16:38:22 +0100 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , "Mychaela N . Falconia" , linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 1/5] tty: add port flag to suppress ready signalling on open Date: Mon, 30 Nov 2020 16:37:38 +0100 Message-Id: <20201130153742.9163-2-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201130153742.9163-1-johan@kernel.org> References: <20201130153742.9163-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 use 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 Reviewed-by: Mychaela N. Falconia --- drivers/tty/tty_port.c | 2 +- include/linux/tty.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c index ea80bf872f54..2613debc1d06 100644 --- a/drivers/tty/tty_port.c +++ b/drivers/tty/tty_port.c @@ -415,7 +415,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.h b/include/linux/tty.h index a99e9b8e4e31..31414efd8661 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -267,6 +267,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 */ /* * Where all of the state associated with a tty is kept while the tty @@ -683,6 +684,19 @@ static inline void tty_port_set_kopened(struct tty_port *port, bool val) clear_bit(TTY_PORT_KOPENED, &port->iflags); } +static inline bool tty_port_nordy(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) +{ + if (val) + set_bit(TTY_PORT_NORDY, &port->iflags); + else + clear_bit(TTY_PORT_NORDY, &port->iflags); +} + extern struct tty_struct *tty_port_tty_get(struct tty_port *port); extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty); extern int tty_port_carrier_raised(struct tty_port *port); From patchwork Mon Nov 30 15:37:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11940907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B7D5C63777 for ; Mon, 30 Nov 2020 15:39:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BAFC206C0 for ; Mon, 30 Nov 2020 15:39:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728392AbgK3Pim (ORCPT ); Mon, 30 Nov 2020 10:38:42 -0500 Received: from mail-lf1-f45.google.com ([209.85.167.45]:41724 "EHLO mail-lf1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728321AbgK3Pih (ORCPT ); Mon, 30 Nov 2020 10:38:37 -0500 Received: by mail-lf1-f45.google.com with SMTP id r24so22430174lfm.8; Mon, 30 Nov 2020 07:38:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vS6wFzkkLhX1TVsecDayO/AB9FKfg+OLWHQOURPFz3E=; b=KzT3A2a0J/CwmqpJisiZQ0+SYcqGDb/Vg3v8pIancuxMUMCL/DfRNTy3MXNALt03+9 8jZ9TfJM6NwlBfCHUfEy+4e3bMuzamDxLqNsXV+TMNl8FLMuiLKwl/s8AFGNI74cyuIJ kk36c65X4jK/jUw7/GAEGhBW5LtuxVtqiCjE6x2DSuSL2f1v9egPgqvVuxB+MqQ6aUnX pYFMcY0bDIHgDFpGGKya9FhITlhqL2U0FCrghieC+OPytoq4mBx0t87g5bgJYHeKoFML +O85nuEojoH6CdW6KGXhxuWr0WLoYZZ/5LhB37zIgUBDM+R7KqXEqHERc3o0ymHpHaOA LTmw== X-Gm-Message-State: AOAM532tYPCAdecwGvYhA86G+tVoZxd0EtY6TgcPri9ZS4fFCRGT5S0X qRxuOe6bzLP1o/bMzKJHejs= X-Google-Smtp-Source: ABdhPJyepEmOBOqOlRQr+/nG28rnh9kHVvQL/4zx7facwSuG+BUHciKJV+0kqUzfLRBaOMx0PDdEKQ== X-Received: by 2002:a19:fc0f:: with SMTP id a15mr9469592lfi.248.1606750674784; Mon, 30 Nov 2020 07:37:54 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id q16sm2950131ljj.32.2020.11.30.07.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 07:37:52 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kjlFu-0002Ol-Ob; Mon, 30 Nov 2020 16:38:22 +0100 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , "Mychaela N . Falconia" , linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 2/5] serial: core: add sysfs attribute to suppress ready signalling on open Date: Mon, 30 Nov 2020 16:37:39 +0100 Message-Id: <20201130153742.9163-3-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201130153742.9163-1-johan@kernel.org> References: <20201130153742.9163-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add a nordy sysfs attribute to suppress raising the modem-control lines on open to signal DTE readiness. This can be use 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 --- Documentation/ABI/testing/sysfs-tty | 7 +++++++ drivers/tty/serial/serial_core.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-tty b/Documentation/ABI/testing/sysfs-tty index e157130a6792..2634b4bf9c7f 100644 --- a/Documentation/ABI/testing/sysfs-tty +++ b/Documentation/ABI/testing/sysfs-tty @@ -161,3 +161,10 @@ Contact: Andy Shevchenko Description: Allows user to detach or attach back the given device as kernel console. It shows and accepts a boolean variable. + +What: /sys/class/tty/ttyS0/nordy +Date: November 2020 +Contact: Johan Hovold +Description: + Show and store the port NORDY flag which suppresses raising + the modem-control lines on open to signal DTE readiness. diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index f41cba10b86b..063a617182ce 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2805,6 +2805,33 @@ static ssize_t console_store(struct device *dev, return ret < 0 ? ret : count; } +static ssize_t nordy_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct tty_port *port = dev_get_drvdata(dev); + + return sprintf(buf, "%d\n", tty_port_nordy(port)); +} + +static ssize_t nordy_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct tty_port *port = dev_get_drvdata(dev); + unsigned int val; + int ret; + + ret = kstrtouint(buf, 0, &val); + if (ret) + return ret; + + if (val > 1) + return -EINVAL; + + tty_port_set_nordy(port, val); + + return count; +} + static DEVICE_ATTR_RO(uartclk); static DEVICE_ATTR_RO(type); static DEVICE_ATTR_RO(line); @@ -2819,6 +2846,7 @@ static DEVICE_ATTR_RO(io_type); static DEVICE_ATTR_RO(iomem_base); static DEVICE_ATTR_RO(iomem_reg_shift); static DEVICE_ATTR_RW(console); +static DEVICE_ATTR_RW(nordy); static struct attribute *tty_dev_attrs[] = { &dev_attr_uartclk.attr, @@ -2835,6 +2863,7 @@ static struct attribute *tty_dev_attrs[] = { &dev_attr_iomem_base.attr, &dev_attr_iomem_reg_shift.attr, &dev_attr_console.attr, + &dev_attr_nordy.attr, NULL }; From patchwork Mon Nov 30 15:37:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11940905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 343FAC83016 for ; Mon, 30 Nov 2020 15:38:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC785206C0 for ; Mon, 30 Nov 2020 15:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728350AbgK3Pii (ORCPT ); Mon, 30 Nov 2020 10:38:38 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:46096 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727556AbgK3Pii (ORCPT ); Mon, 30 Nov 2020 10:38:38 -0500 Received: by mail-lf1-f66.google.com with SMTP id t6so22414180lfl.13; Mon, 30 Nov 2020 07:38:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wX/I1sXDrWB17nXmZ4/VUTNk1RGewCzBNozxf+IPcvs=; b=Lg6IdV5x2TAYVPD8+hlZ8Ggtc1TbruqJbN0tqzfcE37zwDguLpBdnxDC9zNyot9nVS AAR/IpD64zEt11Tr3LZbgD4Mx/oGbv20xbt/IKMXAIPu3IbMkxxGvXndXkxIGR9Ps95I JkvDdbiopj2pkM67JSljTRVkM5LZaWnpHG2Mv+KVJRE4WJmfmC0WU9FOaGQ6k5Ka5naQ 86JlKKO+sQX3aMmoOcUnRR7Dm8KPFBGD5Nfca7F2uCoJnfSg/frA1yYlKFBmdFfczPto dXslRNK7HLsFIZhrEKSR/XqVr3UZykWked94NdWl3g+AVOMkRBLiN08wJIANFbl2gxV5 dLnA== X-Gm-Message-State: AOAM532SntCEQe39izRNbFoGQfRIOWBw7dH77is7i3YC22+Pjz5e/DGz 8Ak17YwM/MwvPGSNGyMl6YE= X-Google-Smtp-Source: ABdhPJxvScOcMYD7Tt8YWHK2qbhuamWyLHg0NrITzgg3eak3+wQeEhys0HE0qxd5qn8dNo2FOY6fGg== X-Received: by 2002:ac2:53bc:: with SMTP id j28mr9680680lfh.39.1606750675410; Mon, 30 Nov 2020 07:37:55 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id 84sm2491995lfa.39.2020.11.30.07.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 07:37:52 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kjlFu-0002Oq-RT; Mon, 30 Nov 2020 16:38:22 +0100 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , "Mychaela N . Falconia" , linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 3/5] USB: serial: add sysfs attribute to suppress ready signalling on open Date: Mon, 30 Nov 2020 16:37:40 +0100 Message-Id: <20201130153742.9163-4-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201130153742.9163-1-johan@kernel.org> References: <20201130153742.9163-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add a nordy sysfs attribute to suppress raising the modem-control lines on open to signal DTE readiness. This can be use 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 --- drivers/usb/serial/bus.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c index eb0195cf37dd..37bbeab6666e 100644 --- a/drivers/usb/serial/bus.c +++ b/drivers/usb/serial/bus.c @@ -35,6 +35,40 @@ 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); + unsigned int val; + int ret; + + ret = kstrtouint(buf, 0, &val); + if (ret) + return ret; + + if (val > 1) + return -EINVAL; + + 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_driver *driver; @@ -60,8 +94,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; From patchwork Mon Nov 30 15:37:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11940909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63CE4C64E7B for ; Mon, 30 Nov 2020 15:39:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 288CE20725 for ; Mon, 30 Nov 2020 15:39:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728377AbgK3Pim (ORCPT ); Mon, 30 Nov 2020 10:38:42 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:33486 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727289AbgK3Pii (ORCPT ); Mon, 30 Nov 2020 10:38:38 -0500 Received: by mail-lj1-f196.google.com with SMTP id t22so18610508ljk.0; Mon, 30 Nov 2020 07:38:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eioTLuh9qMD02dGo7kd70kPRax33tNEMYOnayXuoEQw=; b=MZRcP0uFRJPXYR+eOx0ZLiNY+2EjfHoTpTtUkWs8NmEPlgiGVKTiQlqTyWfLONnjhx OwMd/tU66zPHsjvLKKKIWZadNCGhXFOd8YHi/nWeT84TlqZ+tT973EZfOpZGD6o/r4mB RgwUm48twv/qs4t5+Iz8veLCjXXhlQ97LpEzE+lFG3u72jNYm872h2Hr+uhT5jlCvrEb 8sRTdpXbyRqfuGTtWxXcJUz6o4WVGbKNrCvdCWzfl+OGiTX6kjYKXoEg+HA6HbNSTbQs QHaNUnEfoNfLQVIl3n60ceL+gKtb7sNRupHgoAzjLNAF/4c7lTCQw8fNgHPSxBS6Vs6P jJiw== X-Gm-Message-State: AOAM530/REe5Oyzqe+3GRz6z9kaRvoaUXB2ZHpO68Q9kF1N1iDzcQe3z IDokmj6s2CjuZPyrJp0dzqh3ei823MhIlg== X-Google-Smtp-Source: ABdhPJycWz4pakWbnNhMZrR15429/k3C2l+f+SL+NfM0k55ybkoyPv1lvJESnpb6LIozLrCrb/Th/g== X-Received: by 2002:a2e:5750:: with SMTP id r16mr10156744ljd.61.1606750676106; Mon, 30 Nov 2020 07:37:56 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id r8sm2467749lff.238.2020.11.30.07.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 07:37:54 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kjlFu-0002Ow-UO; Mon, 30 Nov 2020 16:38:22 +0100 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , "Mychaela N . Falconia" , linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 4/5] USB: serial: ftdi_sio: pass port to quirk port_probe functions Date: Mon, 30 Nov 2020 16:37:41 +0100 Message-Id: <20201130153742.9163-5-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201130153742.9163-1-johan@kernel.org> References: <20201130153742.9163-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: "Mychaela N. Falconia" The original code passed only the pointer to the ftdi_private struct to quirk port_probe functions. However, some quirks may need to be applied conditionally only to some channels of a multichannel FT2232x or FT4232H device, and if a given quirk's port_probe function needs to figure out which channel of a multichannel device is currently being considered, it needs access to the port pointer passed to the ftdi_sio_port_probe() function, so it can traverse USB data structures from there. Signed-off-by: Mychaela N. Falconia Signed-off-by: Johan Hovold --- drivers/usb/serial/ftdi_sio.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index e0f4c3d9649c..b69032c9ec2b 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -88,15 +88,15 @@ struct ftdi_private { struct ftdi_sio_quirk { int (*probe)(struct usb_serial *); /* Special settings for probed ports. */ - void (*port_probe)(struct ftdi_private *); + void (*port_probe)(struct usb_serial_port *); }; static int ftdi_jtag_probe(struct usb_serial *serial); static int ftdi_NDI_device_setup(struct usb_serial *serial); static int ftdi_stmclite_probe(struct usb_serial *serial); static int ftdi_8u2232c_probe(struct usb_serial *serial); -static void ftdi_USB_UIRT_setup(struct ftdi_private *priv); -static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv); +static void ftdi_USB_UIRT_setup(struct usb_serial_port *port); +static void ftdi_HE_TIRA1_setup(struct usb_serial_port *port); static const struct ftdi_sio_quirk ftdi_jtag_quirk = { .probe = ftdi_jtag_probe, @@ -2252,11 +2252,11 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port) mutex_init(&priv->cfg_lock); - if (quirk && quirk->port_probe) - quirk->port_probe(priv); - usb_set_serial_port_data(port, priv); + if (quirk && quirk->port_probe) + quirk->port_probe(port); + ftdi_determine_type(port); ftdi_set_max_packet_size(port); if (read_latency_timer(port) < 0) @@ -2277,8 +2277,10 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port) /* Setup for the USB-UIRT device, which requires hardwired * baudrate (38400 gets mapped to 312500) */ /* Called from usbserial:serial_probe */ -static void ftdi_USB_UIRT_setup(struct ftdi_private *priv) +static void ftdi_USB_UIRT_setup(struct usb_serial_port *port) { + struct ftdi_private *priv = usb_get_serial_port_data(port); + priv->flags |= ASYNC_SPD_CUST; priv->custom_divisor = 77; priv->force_baud = 38400; @@ -2287,8 +2289,10 @@ static void ftdi_USB_UIRT_setup(struct ftdi_private *priv) /* Setup for the HE-TIRA1 device, which requires hardwired * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */ -static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv) +static void ftdi_HE_TIRA1_setup(struct usb_serial_port *port) { + struct ftdi_private *priv = usb_get_serial_port_data(port); + priv->flags |= ASYNC_SPD_CUST; priv->custom_divisor = 240; priv->force_baud = 38400; From patchwork Mon Nov 30 15:37:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11940913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1855C71156 for ; Mon, 30 Nov 2020 15:39:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 792F2206C0 for ; Mon, 30 Nov 2020 15:39:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728439AbgK3Piq (ORCPT ); Mon, 30 Nov 2020 10:38:46 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:40222 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728407AbgK3Pip (ORCPT ); Mon, 30 Nov 2020 10:38:45 -0500 Received: by mail-lf1-f68.google.com with SMTP id u19so22465389lfr.7; Mon, 30 Nov 2020 07:38:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4xtaGbTTemD9c+E+gQC/qoKbsCwyc5X5pTFIoVTRIcY=; b=XeGGeWo2IbayVLWJuk0LH9PvIkj4JGWuM01gBEL53/k5+vLiZn/gCm2XU/lPj1uORu NrwtoaT+kwUs3N3IGOFePyh1GxVFTWrkR+0JQY1ud80deSm1mc4Lal/Q5M4iXgWy19hS CpPrwGCSO+OCNr84kBAQhw8NHIXy/naU9z0nJaVNRkyEXsykCcTF6MmVrD16F1M9WNOk O7m4VLelVPmX4jotxLeyO5oUBonsQTDo7Qe3bG6rc5xGd1bzJaNgJcOyS2NLXSAYOHW0 wiI0RhYpuSfXjo7MkRRi6yfOqxVv/ae8zROOK6vYVgs8EReQJIfC55WQj8oHZoBqVpT+ mYBw== X-Gm-Message-State: AOAM530d+ek4kvrQPxjdyLp55mV/kFDEczvMoWHRc0PzUFjabZVg4sKH 18RcygCRMBnwoqU1FC3gqiU= X-Google-Smtp-Source: ABdhPJyoAIGrX3t/GwCwwxX5FF3BTTdVclkBAmNcvhBtaeIKUyVCuYC3+kJHlq1YimU+WkvJIEYSxw== X-Received: by 2002:ac2:50c8:: with SMTP id h8mr9258203lfm.556.1606750676607; Mon, 30 Nov 2020 07:37:56 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id v1sm2487959lfg.252.2020.11.30.07.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 07:37:55 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kjlFv-0002P1-1k; Mon, 30 Nov 2020 16:38:23 +0100 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , "Mychaela N . Falconia" , linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 5/5] USB: serial: ftdi_sio: add support for FreeCalypso DUART28C adapter Date: Mon, 30 Nov 2020 16:37:42 +0100 Message-Id: <20201130153742.9163-6-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201130153742.9163-1-johan@kernel.org> References: <20201130153742.9163-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: "Mychaela N. Falconia" FreeCalypso DUART28C is an FT2232D-based USB to dual UART adapter with a special quirk: Channel B RTS and DTR outputs (BDBUS2 and BDBUS4 on the chip) have been repurposed to drive PWON and RESET controls on Calypso targets. The circuit is wired such that BDBUS[24] high (RTS/DTR inactive) is the normal state with Iota VRPC controls NOT activated, whereas BDBUS[24] low (RTS or DTR active) turn ON the corresponding open drain control signal drivers. A special ftdi_sio driver quirk is needed in order to suppress automatic assertion of DTR & RTS on device open: this device's special PWON and RESET control drivers MUST NOT be activated when the port is ordinarily opened for plain serial communication, instead they must only be activated when a special userspace application explicitly requests such activation with a TIOCMBIS ioctl. These special userspace applications are responsible for making the needed pulse with a TIOCMBIS, delay, TIOCMBIC sequence. The special quirk is conditionalized on the DUART28C adapter's custom USB ID, and is further limited to FT2232D Channel B only: Channel A is wired normally, with the chip's ADBUS2 and ADBUS4 outputs actually being RTS and DTR rather than something else. Signed-off-by: Mychaela N. Falconia [johan: reimplement using new NORDY flag, trim quirk comment] Signed-off-by: Johan Hovold --- drivers/usb/serial/ftdi_sio.c | 22 ++++++++++++++++++++++ drivers/usb/serial/ftdi_sio_ids.h | 1 + 2 files changed, 23 insertions(+) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index b69032c9ec2b..b555bbc1b0a9 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -97,6 +97,7 @@ static int ftdi_stmclite_probe(struct usb_serial *serial); static int ftdi_8u2232c_probe(struct usb_serial *serial); static void ftdi_USB_UIRT_setup(struct usb_serial_port *port); static void ftdi_HE_TIRA1_setup(struct usb_serial_port *port); +static void ftdi_duart28c_setup(struct usb_serial_port *port); static const struct ftdi_sio_quirk ftdi_jtag_quirk = { .probe = ftdi_jtag_probe, @@ -122,6 +123,10 @@ static const struct ftdi_sio_quirk ftdi_8u2232c_quirk = { .probe = ftdi_8u2232c_probe, }; +static const struct ftdi_sio_quirk ftdi_duart28c_quirk = { + .port_probe = ftdi_duart28c_setup, +}; + /* * The 8U232AM has the same API as the sio except for: * - it can support MUCH higher baudrates; up to: @@ -1042,6 +1047,8 @@ static const struct usb_device_id id_table_combined[] = { .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, { USB_DEVICE(FTDI_VID, FTDI_FALCONIA_JTAG_UNBUF_PID), .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, + { USB_DEVICE(FTDI_VID, FTDI_FALCONIA_DUART28C_PID), + .driver_info = (kernel_ulong_t)&ftdi_duart28c_quirk }, { } /* Terminating entry */ }; @@ -2386,6 +2393,21 @@ static int ftdi_stmclite_probe(struct usb_serial *serial) return 0; } +/* + * FreeCalypso DUART28C is an FT2232D-based USB to dual UART adapter + * with a special quirk: Channel B RTS and DTR outputs (BDBUS2 and BDBUS4 + * on the chip) have been repurposed to drive PWON and RESET controls. + */ +static void ftdi_duart28c_setup(struct usb_serial_port *port) +{ + struct usb_serial *serial = port->serial; + struct usb_interface *intf = serial->interface; + int ifnum = intf->cur_altsetting->desc.bInterfaceNumber; + + if (ifnum == 1) + tty_port_set_nordy(&port->port, 1); +} + static int ftdi_sio_port_remove(struct usb_serial_port *port) { struct ftdi_private *priv = usb_get_serial_port_data(port); diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h index 3d47c6d72256..3081b8916a0a 100644 --- a/drivers/usb/serial/ftdi_sio_ids.h +++ b/drivers/usb/serial/ftdi_sio_ids.h @@ -45,6 +45,7 @@ */ #define FTDI_FALCONIA_JTAG_BUF_PID 0x7150 #define FTDI_FALCONIA_JTAG_UNBUF_PID 0x7151 +#define FTDI_FALCONIA_DUART28C_PID 0x7152 /* Sienna Serial Interface by Secyourit GmbH */ #define FTDI_SIENNA_PID 0x8348