* [PATCH] USB: serial: ftdi_sio: Fix GPIO not working in autosuspend
@ 2019-01-14 12:30 ` Karoly Pados
0 siblings, 0 replies; 6+ messages in thread
From: Karoly Pados @ 2019-01-14 12:30 UTC (permalink / raw)
To: Johan Hovold, Greg Kroah-Hartman, linux-usb, linux-kernel, Loic Poulain
Cc: Karoly Pados
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 <pados@pados.hu>
---
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;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* USB: serial: ftdi_sio: Fix GPIO not working in autosuspend
@ 2019-01-14 12:30 ` Karoly Pados
0 siblings, 0 replies; 6+ messages in thread
From: Karoly Pados @ 2019-01-14 12:30 UTC (permalink / raw)
To: Johan Hovold, Greg Kroah-Hartman, linux-usb, linux-kernel, Loic Poulain
Cc: Karoly Pados
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 <pados@pados.hu>
---
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;
}
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] USB: serial: ftdi_sio: Fix GPIO not working in autosuspend
@ 2019-01-14 13:48 ` Johan Hovold
0 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2019-01-14 13:48 UTC (permalink / raw)
To: Karoly Pados
Cc: Johan Hovold, Greg Kroah-Hartman, linux-usb, linux-kernel, Loic Poulain
On Mon, Jan 14, 2019 at 01:30:03PM +0100, Karoly Pados wrote:
> 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 <pados@pados.hu>
> ---
> 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);
Both of the functions where you add autopm calls already have a local
variable for port->serial.
> + if (result) {
> + dev_err(&port->serial->interface->dev,
> + "Failed to wake device from autosuspend.\n");
And we tend not to log errors for these calls.
> + return result;
> + }
I replaced and port->serial with serial and dropped the dev_err:s before
applying for -rc3 with a Fixes and CC-stable tag.
Thanks,
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
* USB: serial: ftdi_sio: Fix GPIO not working in autosuspend
@ 2019-01-14 13:48 ` Johan Hovold
0 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2019-01-14 13:48 UTC (permalink / raw)
To: Karoly Pados
Cc: Johan Hovold, Greg Kroah-Hartman, linux-usb, linux-kernel, Loic Poulain
On Mon, Jan 14, 2019 at 01:30:03PM +0100, Karoly Pados wrote:
> 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 <pados@pados.hu>
> ---
> 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);
Both of the functions where you add autopm calls already have a local
variable for port->serial.
> + if (result) {
> + dev_err(&port->serial->interface->dev,
> + "Failed to wake device from autosuspend.\n");
And we tend not to log errors for these calls.
> + return result;
> + }
I replaced and port->serial with serial and dropped the dev_err:s before
applying for -rc3 with a Fixes and CC-stable tag.
Thanks,
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] USB: serial: ftdi_sio: Fix GPIO not working in autosuspend
@ 2019-01-14 15:13 ` Johan Hovold
0 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2019-01-14 15:13 UTC (permalink / raw)
To: Karoly Pados
Cc: Johan Hovold, Greg Kroah-Hartman, linux-usb, linux-kernel, Loic Poulain
On Mon, Jan 14, 2019 at 02:48:21PM +0100, Johan Hovold wrote:
> On Mon, Jan 14, 2019 at 01:30:03PM +0100, Karoly Pados wrote:
> > 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 <pados@pados.hu>
Do you intend to send a corresponding fix for cp210x as well?
Thanks,
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
* USB: serial: ftdi_sio: Fix GPIO not working in autosuspend
@ 2019-01-14 15:13 ` Johan Hovold
0 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2019-01-14 15:13 UTC (permalink / raw)
To: Karoly Pados
Cc: Johan Hovold, Greg Kroah-Hartman, linux-usb, linux-kernel, Loic Poulain
On Mon, Jan 14, 2019 at 02:48:21PM +0100, Johan Hovold wrote:
> On Mon, Jan 14, 2019 at 01:30:03PM +0100, Karoly Pados wrote:
> > 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 <pados@pados.hu>
Do you intend to send a corresponding fix for cp210x as well?
Thanks,
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-01-14 15:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-14 12:30 [PATCH] USB: serial: ftdi_sio: Fix GPIO not working in autosuspend Karoly Pados
2019-01-14 12:30 ` Karoly Pados
2019-01-14 13:48 ` [PATCH] " Johan Hovold
2019-01-14 13:48 ` Johan Hovold
2019-01-14 15:13 ` [PATCH] " Johan Hovold
2019-01-14 15:13 ` Johan Hovold
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.