[PATCH] USB: serial: ftdi_sio: add ftdi serial to gpiochip label

Stan Bertrand
2023-10-03T00:12:21Z

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