linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] USB: serial: cp210x: Fix alternate function for CP2102N QFN20
@ 2021-05-28 20:39 Stefan Agner
  2021-06-10  7:53 ` Johan Hovold
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Agner @ 2021-05-28 20:39 UTC (permalink / raw)
  To: johan; +Cc: gregkh, linux-usb, linux-kernel, stefan

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 <stefan@agner.ch>
---
Tested on a custom PCB with a CP2102N QFP20 device. I noticed the bug after
configuring GPIO.2/3 to be TX/RX LED.

--
Stefan

 drivers/usb/serial/cp210x.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index ee595d1bea0a..c9f8ebd34122 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -537,6 +537,12 @@ struct cp210x_single_port_config {
 #define CP210X_2NCONFIG_GPIO_RSTLATCH_IDX	587
 #define CP210X_2NCONFIG_GPIO_CONTROL_IDX	600
 
+/* CP2102N QFN20 port configuration values */
+#define CP2102N_QFN20_GPIO2_TXLED_MODE		BIT(2)
+#define CP2102N_QFN20_GPIO3_RXLED_MODE		BIT(3)
+#define CP2102N_QFN20_GPIO1_RS485_MODE		BIT(4)
+#define CP2102N_QFN20_GPIO0_CLK_MODE		BIT(6)
+
 /* CP210X_VENDOR_SPECIFIC, CP210X_WRITE_LATCH call writes these 0x2 bytes. */
 struct cp210x_gpio_write {
 	u8	mask;
@@ -1733,7 +1739,19 @@ static int cp2102n_gpioconf_init(struct usb_serial *serial)
 	priv->gpio_pushpull = (gpio_pushpull >> 3) & 0x0f;
 
 	/* 0 indicates GPIO mode, 1 is alternate function */
-	priv->gpio_altfunc = (gpio_ctrl >> 2) & 0x0f;
+	if (priv->partnum == CP210X_PARTNUM_CP2102N_QFN20) {
+		/* QFN20 is special... */
+		if (gpio_ctrl & CP2102N_QFN20_GPIO0_CLK_MODE)   /* GPIO 0 */
+			priv->gpio_altfunc |= BIT(0);
+		if (gpio_ctrl & CP2102N_QFN20_GPIO1_RS485_MODE) /* GPIO 1 */
+			priv->gpio_altfunc |= BIT(1);
+		if (gpio_ctrl & CP2102N_QFN20_GPIO2_TXLED_MODE) /* GPIO 2 */
+			priv->gpio_altfunc |= BIT(2);
+		if (gpio_ctrl & CP2102N_QFN20_GPIO3_RXLED_MODE) /* GPIO 3 */
+			priv->gpio_altfunc |= BIT(3);
+	} else {
+		priv->gpio_altfunc = (gpio_ctrl >> 2) & 0x0f;
+	}
 
 	if (priv->partnum == CP210X_PARTNUM_CP2102N_QFN28) {
 		/*
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] USB: serial: cp210x: Fix alternate function for CP2102N QFN20
  2021-05-28 20:39 [PATCH] USB: serial: cp210x: Fix alternate function for CP2102N QFN20 Stefan Agner
@ 2021-06-10  7:53 ` Johan Hovold
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hovold @ 2021-06-10  7:53 UTC (permalink / raw)
  To: Stefan Agner; +Cc: gregkh, linux-usb, linux-kernel

On Fri, May 28, 2021 at 10:39:31PM +0200, Stefan Agner wrote:
> 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 <stefan@agner.ch>
> ---
> Tested on a custom PCB with a CP2102N QFP20 device. I noticed the bug after
> configuring GPIO.2/3 to be TX/RX LED.

Thanks for fixing this, Stefan.

Nice and clean and patch, and your findings match the datasheet ("Table
4.2. GPIO Pin Alternate Functions").

Now applied for 5.13 with a stable tag.

Johan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-10  7:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-28 20:39 [PATCH] USB: serial: cp210x: Fix alternate function for CP2102N QFN20 Stefan Agner
2021-06-10  7:53 ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).