Skip to content

Commit

Permalink
USB: serial: ftdi_sio: fix GPIO not working in autosuspend
Browse files Browse the repository at this point in the history
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>
[ johan: simplify code somewhat ]
Fixes: ba93cc7 ("USB: serial: ftdi_sio: implement GPIO support for FT-X devices")
Cc: stable <stable@vger.kernel.org>	# 4.20
Signed-off-by: Johan Hovold <johan@kernel.org>
  • Loading branch information
Karoly Pados authored and Johan Hovold committed Jan 14, 2019
1 parent b81c2c3 commit a8eda9f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion drivers/usb/serial/ftdi_sio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,10 @@ static int ftdi_set_bitmode(struct usb_serial_port *port, u8 mode)
int result;
u16 val;

result = usb_autopm_get_interface(serial->interface);
if (result)
return result;

val = (mode << 8) | (priv->gpio_output << 4) | priv->gpio_value;
result = usb_control_msg(serial->dev,
usb_sndctrlpipe(serial->dev, 0),
Expand All @@ -1795,6 +1799,8 @@ static int ftdi_set_bitmode(struct usb_serial_port *port, u8 mode)
val, result);
}

usb_autopm_put_interface(serial->interface);

return result;
}

Expand Down Expand Up @@ -1846,9 +1852,15 @@ static int ftdi_read_cbus_pins(struct usb_serial_port *port)
unsigned char *buf;
int result;

result = usb_autopm_get_interface(serial->interface);
if (result)
return result;

buf = kmalloc(1, GFP_KERNEL);
if (!buf)
if (!buf) {
usb_autopm_put_interface(serial->interface);
return -ENOMEM;
}

result = usb_control_msg(serial->dev,
usb_rcvctrlpipe(serial->dev, 0),
Expand All @@ -1863,6 +1875,7 @@ static int ftdi_read_cbus_pins(struct usb_serial_port *port)
}

kfree(buf);
usb_autopm_put_interface(serial->interface);

return result;
}
Expand Down

0 comments on commit a8eda9f

Please sign in to comment.