From patchwork Mon Jan 14 12:30:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karoly Pados X-Patchwork-Id: 10762313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C1B713B5 for ; Mon, 14 Jan 2019 12:30:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EECED287F3 for ; Mon, 14 Jan 2019 12:30:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E19A92881A; Mon, 14 Jan 2019 12:30:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CDD7287F3 for ; Mon, 14 Jan 2019 12:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726534AbfANMaL (ORCPT ); Mon, 14 Jan 2019 07:30:11 -0500 Received: from erza.pados.hu ([176.9.136.194]:38152 "EHLO erza.pados.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726449AbfANMaL (ORCPT ); Mon, 14 Jan 2019 07:30:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=pados.hu; s=february2016; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=rXbiEf79sJoWrz/kAiUQbcyFCnrDzGwpuOg3buNZrsE=; b=usYSW0gfDdcgT53AYroiC1TlVf 06mJhCAQtxkj42lyu7IABEAzxTtbQTjuSZeswVNfw0rTMDR4LSnESny/O6r0UrShHvuGAIrYnzRDI NjkFQR2Q30eFTIPMM11iTkORfaCDxuqsULPzIQaFuSZRBFXRANEFqAQ+g63jXtJi/+SJdSSNFs2Cq SvXUaJUujP2yxbKPKPwC5alM/H9FhcOIiGrhRYGa6kXs2d7TOVkZeu5L146kP1jA56rWQDmIu5zRZ vmMj98r5B1PG5kJdbzpYYchZ7xave8UVHz4mrlzCcSq9nftvdxwGrx1N0CC/T+zRRJLkz9eHn+fDf jtjkwVDA==; Received: from 188-143-5-0.pool.digikabel.hu ([188.143.5.0] helo=localhost) by erza with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gj1NX-00045P-WF; Mon, 14 Jan 2019 13:30:08 +0100 From: Karoly Pados To: "Johan Hovold" , "Greg Kroah-Hartman" , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Loic Poulain" Cc: Karoly Pados Subject: [PATCH] USB: serial: ftdi_sio: Fix GPIO not working in autosuspend Date: Mon, 14 Jan 2019 13:30:03 +0100 Message-Id: <20190114123003.8228-1-pados@pados.hu> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Spam_score: -2.9 X-Spam_report: Spam detection software, running on the system "erza", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: There is a bug in the current GPIO code for ftdi_sio: it failed to take USB autosuspend into account. If the device is in autosuspend, calls to usb_control_msg() fail with -EHOSTUNREACH. Because the s [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: pados.hu] -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 TVD_RCVD_IP Message was received from an IP address Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is a bug in the current GPIO code for ftdi_sio: it failed to take USB autosuspend into account. If the device is in autosuspend, calls to usb_control_msg() fail with -EHOSTUNREACH. Because the standard value for autosuspend timeout is usually 2-5 seconds, this made it almost impossible to use the GPIOs on machines that have USB autosuspend enabled. This patch fixes the issue by acquiring a PM lock on the device for the duration of the USB transfers. Tested on an FT231X device. Signed-off-by: Karoly Pados --- Please consider backporting to 4.20.x, otherwise the GPIO driver is not really usable for anybody with USB autosuspend enabled (eg. many laptops), at least not without manual configuration. drivers/usb/serial/ftdi_sio.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 1ab2a6191013..01813dce37f2 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -1783,6 +1783,13 @@ static int ftdi_set_bitmode(struct usb_serial_port *port, u8 mode) int result; u16 val; + result = usb_autopm_get_interface(port->serial->interface); + if (result) { + dev_err(&port->serial->interface->dev, + "Failed to wake device from autosuspend.\n"); + return result; + } + val = (mode << 8) | (priv->gpio_output << 4) | priv->gpio_value; result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), @@ -1795,6 +1802,8 @@ static int ftdi_set_bitmode(struct usb_serial_port *port, u8 mode) val, result); } + usb_autopm_put_interface(port->serial->interface); + return result; } @@ -1846,9 +1855,18 @@ static int ftdi_read_cbus_pins(struct usb_serial_port *port) unsigned char *buf; int result; + result = usb_autopm_get_interface(port->serial->interface); + if (result) { + dev_err(&port->serial->interface->dev, + "Failed to wake device from autosuspend.\n"); + return result; + } + buf = kmalloc(1, GFP_KERNEL); - if (!buf) + if (!buf) { + usb_autopm_put_interface(port->serial->interface); return -ENOMEM; + } result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), @@ -1863,6 +1881,7 @@ static int ftdi_read_cbus_pins(struct usb_serial_port *port) } kfree(buf); + usb_autopm_put_interface(port->serial->interface); return result; }