From: Karoly Pados <pados@pados.hu>
To: "Johan Hovold" <johan@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
"Loic Poulain" <loic.poulain@linaro.org>
Cc: Karoly Pados <pados@pados.hu>
Subject: [PATCH v2] USB: serial: cp210x: Fix GPIO in autosuspend
Date: Sun, 17 Feb 2019 18:59:01 +0100 [thread overview]
Message-ID: <20190217175901.3986-1-pados@pados.hu> (raw)
Current GPIO code in cp210x fails to take USB autosuspend into account,
making it practically impossible to use GPIOs with autosuspend enabled
without user configuration. Fix this like for ftdi_sio in a previous patch.
Tested on a CP2102N.
Signed-off-by: Karoly Pados <pados@pados.hu>
---
Changelog:
- v2: Restrict new autopm calls to GPIO paths.
Always check result of usb_autopm_get.
Rebased to current usb_serial upstream.
drivers/usb/serial/cp210x.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index fac7a4547523..f7aaecad6e21 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -1370,8 +1370,13 @@ static int cp210x_gpio_get(struct gpio_chip *gc, unsigned int gpio)
if (priv->partnum == CP210X_PARTNUM_CP2105)
req_type = REQTYPE_INTERFACE_TO_HOST;
+ result = usb_autopm_get_interface(serial->interface);
+ if (result)
+ return result;
+
result = cp210x_read_vendor_block(serial, req_type,
CP210X_READ_LATCH, &buf, sizeof(buf));
+ usb_autopm_put_interface(serial->interface);
if (result < 0)
return result;
@@ -1392,6 +1397,10 @@ static void cp210x_gpio_set(struct gpio_chip *gc, unsigned int gpio, int value)
buf.mask = BIT(gpio);
+ result = usb_autopm_get_interface(serial->interface);
+ if (result)
+ goto out;
+
if (priv->partnum == CP210X_PARTNUM_CP2105) {
result = cp210x_write_vendor_block(serial,
REQTYPE_HOST_TO_INTERFACE,
@@ -1399,7 +1408,6 @@ static void cp210x_gpio_set(struct gpio_chip *gc, unsigned int gpio, int value)
sizeof(buf));
} else {
u16 wIndex = buf.state << 8 | buf.mask;
-
result = usb_control_msg(serial->dev,
usb_sndctrlpipe(serial->dev, 0),
CP210X_VENDOR_SPECIFIC,
@@ -1409,6 +1417,9 @@ static void cp210x_gpio_set(struct gpio_chip *gc, unsigned int gpio, int value)
NULL, 0, USB_CTRL_SET_TIMEOUT);
}
+ usb_autopm_put_interface(serial->interface);
+
+out:
if (result < 0) {
dev_err(&serial->interface->dev, "failed to set GPIO value: %d\n",
result);
--
2.20.1
next reply other threads:[~2019-02-17 17:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-17 17:59 Karoly Pados [this message]
2019-02-18 9:17 ` Oliver Neukum
2019-03-19 10:36 ` Johan Hovold
2019-03-19 11:15 ` Oliver Neukum
2019-03-19 13:14 ` Johan Hovold
2019-03-19 17:19 ` Karoly Pados
2019-03-20 9:11 ` Johan Hovold
2019-03-19 17:12 ` Karoly Pados
2019-02-20 9:23 ` Johan Hovold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190217175901.3986-1-pados@pados.hu \
--to=pados@pados.hu \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=loic.poulain@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®