Skip to content

Commit 6f7ec77

Browse files
agnersjhovold
authored andcommitted
USB: serial: cp210x: fix alternate function for CP2102N QFN20
The QFN20 part has a different GPIO/port function assignment. The configuration struct bit field ordered as TX/RX/RS485/WAKEUP/CLK which exactly matches GPIO0-3 for QFN24/28. However, QFN20 has a different GPIO to primary function assignment. Special case QFN20 to follow to properly detect which GPIOs are available. Signed-off-by: Stefan Agner <[email protected]> Link: https://lore.kernel.org/r/51830b2b24118eb0f77c5c9ac64ffb2f519dbb1d.1622218300.git.stefan@agner.ch Fixes: c8acfe0 ("USB: serial: cp210x: implement GPIO support for CP2102N") Cc: [email protected] # 4.19 Signed-off-by: Johan Hovold <[email protected]>
1 parent bc96c72 commit 6f7ec77

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

drivers/usb/serial/cp210x.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,12 @@ struct cp210x_single_port_config {
537537
#define CP210X_2NCONFIG_GPIO_RSTLATCH_IDX 587
538538
#define CP210X_2NCONFIG_GPIO_CONTROL_IDX 600
539539

540+
/* CP2102N QFN20 port configuration values */
541+
#define CP2102N_QFN20_GPIO2_TXLED_MODE BIT(2)
542+
#define CP2102N_QFN20_GPIO3_RXLED_MODE BIT(3)
543+
#define CP2102N_QFN20_GPIO1_RS485_MODE BIT(4)
544+
#define CP2102N_QFN20_GPIO0_CLK_MODE BIT(6)
545+
540546
/* CP210X_VENDOR_SPECIFIC, CP210X_WRITE_LATCH call writes these 0x2 bytes. */
541547
struct cp210x_gpio_write {
542548
u8 mask;
@@ -1733,7 +1739,19 @@ static int cp2102n_gpioconf_init(struct usb_serial *serial)
17331739
priv->gpio_pushpull = (gpio_pushpull >> 3) & 0x0f;
17341740

17351741
/* 0 indicates GPIO mode, 1 is alternate function */
1736-
priv->gpio_altfunc = (gpio_ctrl >> 2) & 0x0f;
1742+
if (priv->partnum == CP210X_PARTNUM_CP2102N_QFN20) {
1743+
/* QFN20 is special... */
1744+
if (gpio_ctrl & CP2102N_QFN20_GPIO0_CLK_MODE) /* GPIO 0 */
1745+
priv->gpio_altfunc |= BIT(0);
1746+
if (gpio_ctrl & CP2102N_QFN20_GPIO1_RS485_MODE) /* GPIO 1 */
1747+
priv->gpio_altfunc |= BIT(1);
1748+
if (gpio_ctrl & CP2102N_QFN20_GPIO2_TXLED_MODE) /* GPIO 2 */
1749+
priv->gpio_altfunc |= BIT(2);
1750+
if (gpio_ctrl & CP2102N_QFN20_GPIO3_RXLED_MODE) /* GPIO 3 */
1751+
priv->gpio_altfunc |= BIT(3);
1752+
} else {
1753+
priv->gpio_altfunc = (gpio_ctrl >> 2) & 0x0f;
1754+
}
17371755

17381756
if (priv->partnum == CP210X_PARTNUM_CP2102N_QFN28) {
17391757
/*

0 commit comments

Comments
 (0)