public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] USB: serial: ftdi_sio: add ftdi serial to gpiochip label
@ 2023-10-03  0:11 Stan Bertrand
  2023-12-15 10:10 ` Johan Hovold
  0 siblings, 1 reply; 4+ messages in thread
From: Stan Bertrand @ 2023-10-03  0:11 UTC (permalink / raw)
  To: Johan Hovold, linux-usb
  Cc: Greg Kroah-Hartman, linux-kernel, Stanislas Bertrand

From: Stanislas Bertrand <stanislasbertrand@gmail.com>

Use ftdi serial number on gpiochip label.
Allows to interface with gpiod utils using the serial number:

$ gpiodetect
gpiochip5 [ftdi-cbus-FTRelay2] (4 lines)
gpiochip6 [ftdi-cbus] (4 lines)
gpiochip7 [ftdi-cbus-A106TPEC] (4 lines)

$ gpioget ftdi-cbus-FTRelay2 2
0

Signed-off-by: Stanislas Bertrand <stanislasbertrand@gmail.com>
---
 drivers/usb/serial/ftdi_sio.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 1bf23611be12..3e1b1c3194a2 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -2094,6 +2094,8 @@ static int ftdi_gpio_init(struct usb_serial_port *port)
 {
 	struct ftdi_private *priv = usb_get_serial_port_data(port);
 	struct usb_serial *serial = port->serial;
+	struct usb_device *udev = serial->dev;
+	const char *label;
 	int result;
 
 	switch (priv->chip_type) {
@@ -2116,6 +2118,15 @@ static int ftdi_gpio_init(struct usb_serial_port *port)
 	mutex_init(&priv->gpio_lock);
 
 	priv->gc.label = "ftdi-cbus";
+
+	if (udev->serial) {
+		label = devm_kasprintf(&udev->dev, GFP_KERNEL, "ftdi-cbus-%s",
+					udev->serial);
+		if (label) {
+			priv->gc.label = label;
+		}
+	}
+
 	priv->gc.request = ftdi_gpio_request;
 	priv->gc.get_direction = ftdi_gpio_direction_get;
 	priv->gc.direction_input = ftdi_gpio_direction_input;
-- 
2.34.1


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

end of thread, other threads:[~2024-01-02  8:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-03  0:11 [PATCH] USB: serial: ftdi_sio: add ftdi serial to gpiochip label Stan Bertrand
2023-12-15 10:10 ` Johan Hovold
2024-01-02  2:00   ` Stan Bertrand
2024-01-02  8:50     ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox