Skip to content

Commit 83b6704

Browse files
committed
USB: serial: cp210x: fix CP2105 GPIO registration
When generalising GPIO support and adding support for CP2102N, the GPIO registration for some CP2105 devices accidentally broke. Specifically, when all the pins of a port are in "modem" mode, and thus unavailable for GPIO use, the GPIO chip would now be registered without having initialised the number of GPIO lines. This would in turn be rejected by gpiolib and some errors messages would be printed (but importantly probe would still succeed). Fix this by initialising the number of GPIO lines before registering the GPIO chip. Note that as for the other device types, and as when all CP2105 pins are muxed for LED function, the GPIO chip is registered also when no pins are available for GPIO use. Reported-by: Maarten Brock <[email protected]> Link: https://lore.kernel.org/r/[email protected] Fixes: c8acfe0 ("USB: serial: cp210x: implement GPIO support for CP2102N") Cc: [email protected] # 4.19 Cc: Karoly Pados <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Greg Kroah-Hartman <[email protected]> Tested-by: Maarten Brock <[email protected]> Signed-off-by: Johan Hovold <[email protected]>
1 parent 2585cf9 commit 83b6704

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/usb/serial/cp210x.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,8 @@ static int cp2105_gpioconf_init(struct usb_serial *serial)
16351635

16361636
/* 2 banks of GPIO - One for the pins taken from each serial port */
16371637
if (intf_num == 0) {
1638+
priv->gc.ngpio = 2;
1639+
16381640
if (mode.eci == CP210X_PIN_MODE_MODEM) {
16391641
/* mark all GPIOs of this interface as reserved */
16401642
priv->gpio_altfunc = 0xff;
@@ -1645,8 +1647,9 @@ static int cp2105_gpioconf_init(struct usb_serial *serial)
16451647
priv->gpio_pushpull = (u8)((le16_to_cpu(config.gpio_mode) &
16461648
CP210X_ECI_GPIO_MODE_MASK) >>
16471649
CP210X_ECI_GPIO_MODE_OFFSET);
1648-
priv->gc.ngpio = 2;
16491650
} else if (intf_num == 1) {
1651+
priv->gc.ngpio = 3;
1652+
16501653
if (mode.sci == CP210X_PIN_MODE_MODEM) {
16511654
/* mark all GPIOs of this interface as reserved */
16521655
priv->gpio_altfunc = 0xff;
@@ -1657,7 +1660,6 @@ static int cp2105_gpioconf_init(struct usb_serial *serial)
16571660
priv->gpio_pushpull = (u8)((le16_to_cpu(config.gpio_mode) &
16581661
CP210X_SCI_GPIO_MODE_MASK) >>
16591662
CP210X_SCI_GPIO_MODE_OFFSET);
1660-
priv->gc.ngpio = 3;
16611663
} else {
16621664
return -ENODEV;
16631665
}

0 commit comments

Comments
 (0)