USB: ftdio_sio: GPIO validity fixes
Subsystems (4)
cover USB: ftdio_sio: GPIO validity fixes
Having recently tried to use the CBUS GPIOs that come thanks to the ftdio_sio driver, it occurred to me that the driver has a couple of usability issues:
- it advertises potential GPIOs that are reserved to other uses (LED control, or something else)
- it returns an odd error (-ENODEV), instead of the expected -EINVAL when a line is unavailable, leading to a difficult diagnostic
We address the issues in a number of ways:
- Stop reporting invalid GPIO lines as valid to userspace. It definitely seems odd to do so. Instead, report the line as being used, making the userspace interface a bit more consistent.
- Implement the init_valid_mask() callback in the ftdi_sio driver, allowing it to report which lines are actually valid.
- As suggested by Linus, give an indication to the user of why some of the GPIO lines are unavailable, and point them to a useful tool (once per boot). It is a bit sad that there next to no documentation on how to use these CBUS pins.
- Drop the error reporting code, which has become useless at this point.
Tested with a couple of FTDI devices (FT230X and FT231X) and various CBUS configurations.
Marc Zyngier (4):
gpiolib: cdev: Flag invalid GPIOs as used
USB: serial: ftdi_sio: Report the valid GPIO lines to gpiolib
USB: serial: ftdi_sio: Log the CBUS GPIO validity
USB: serial: ftdi_sio: Drop GPIO line checking dead code
drivers/gpio/gpiolib-cdev.c | 1 + drivers/usb/serial/ftdi_sio.c | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-)
Signature · 1 line
2.28.0
PATCH 1/4 gpiolib: cdev: Flag invalid GPIOs as used
When reporting the state of a GPIO to userspace, we never check for the actual validity of the line, meaning we report invalid lines as being usable. A subsequent request will fail though, which is an inconsistent behaviour from a userspace perspective.
Instead, let's check for the validity of the line and report it as used if it is invalid. This allows a tool such as gpioinfo to report something sensible:
gpiochip3 - 4 lines:
line 0: unnamed unused input active-high line 1: unnamed kernel input active-high [used] line 2: unnamed kernel input active-high [used] line 3: unnamed unused input active-high
In this example, lines 1 and 2 are invalid, and cannot be used by userspace.
--- drivers/gpio/gpiolib-cdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpio/gpiolib-cdev.c +1 -0
@@ -1910,6 +1910,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,test_bit (FLAG_USED_AS_IRQ , &desc->flags) ||test_bit (FLAG_EXPORT , &desc->flags) ||test_bit (FLAG_SYSFS , &desc->flags) || + !gpiochip_line_is_valid (gc, info->offset) || !ok_for_pinctrl) info->flags |= GPIO_V2_LINE_FLAG_USED;
Signature · 1 line
2.28.0
Johan Hovold
maintainerRe: [PATCH 1/4] gpiolib: cdev: Flag invalid GPIOs as used
Quoted 28 lines · Marc Zyngier
When reporting the state of a GPIO to userspace, we never check for the actual validity of the line, meaning we report invalid lines as being usable. A subsequent request will fail though, which is an inconsistent behaviour from a userspace perspective.
Instead, let's check for the validity of the line and report it as used if it is invalid. This allows a tool such as gpioinfo to report something sensible:
gpiochip3 - 4 lines:
line 0: unnamed unused input active-high line 1: unnamed kernel input active-high [used] line 2: unnamed kernel input active-high [used] line 3: unnamed unused input active-highIn this example, lines 1 and 2 are invalid, and cannot be used by userspace.
Signed-off-by Marc Zyngier <[email protected]>--- drivers/gpio/gpiolib-cdev.c | 1 + 1 file changed, 1 insertion(+)drivers/gpio/gpiolib-cdev.c +0
-0
drivers/gpio/gpiolib-cdev.c static void gpio_desc_to_lineinfo(struct gpio_desc *desc, · line 1915
Quoted 6 lines
drivers/gpio/gpiolib-cdev.c +1
-0@@ -1910,6 +1910,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,test_bit (FLAG_USED_AS_IRQ , &desc->flags) ||test_bit (FLAG_EXPORT , &desc->flags) ||test_bit (FLAG_SYSFS , &desc->flags) || + !gpiochip_line_is_valid (gc, info->offset) || !ok_for_pinctrl) info->flags |= GPIO_V2_LINE_FLAG_USED;
So this is somewhat separate from the rest of the series in case it applies also to gpio chips with reserved ranges (e.g. "gpio-reserved-ranges" devicetree property). Are they currently reported as available?
Looks like this will work well also for USB gpio controllers with static muxing configured in EEPROM, especially as that is how we already report pins reported as unavailable by pinctrl (i.e. ok_for_pinctrl).
Johan
Re: [PATCH 1/4] gpiolib: cdev: Flag invalid GPIOs as used
Quoted 33 lines · Johan Hovold
Quoted 32 lines · Marc Zyngier
When reporting the state of a GPIO to userspace, we never check for the actual validity of the line, meaning we report invalid lines as being usable. A subsequent request will fail though, which is an inconsistent behaviour from a userspace perspective.
Instead, let's check for the validity of the line and report it as used if it is invalid. This allows a tool such as gpioinfo to report something sensible:
gpiochip3 - 4 lines:
line 0: unnamed unused input active-high line 1: unnamed kernel input active-high [used] line 2: unnamed kernel input active-high [used] line 3: unnamed unused input active-highIn this example, lines 1 and 2 are invalid, and cannot be used by userspace.
Signed-off-by Marc Zyngier <[email protected]>--- drivers/gpio/gpiolib-cdev.c | 1 + 1 file changed, 1 insertion(+)drivers/gpio/gpiolib-cdev.c +0
-0@@ -1910,6 +1910,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,test_bit (FLAG_USED_AS_IRQ , &desc->flags) ||test_bit (FLAG_EXPORT , &desc->flags) || test_bit(FLAG_SYSFS, &desc->flags) ||
Quoted 8 lines
drivers/gpio/gpiolib-cdev.c static void gpio_desc_to_lineinfo(struct gpio_desc *desc, · line 1915
Quoted 3 lines
drivers/gpio/gpiolib-cdev.c +1
-0+ !gpiochip_line_is_valid (gc, info->offset) || !ok_for_pinctrl) info->flags |= GPIO_V2_LINE_FLAG_USED;So this is somewhat separate from the rest of the series in case it applies also to gpio chips with reserved ranges (e.g. "gpio-reserved-ranges" devicetree property). Are they currently reported as available?
I don't have any HW that uses this, but gpiolib-of.c makes use of it to expose the valid GPIO range. I expect these systems suffer from the same issue.
Quoted 3 lines
Looks like this will work well also for USB gpio controllers with static muxing configured in EEPROM, especially as that is how we already report pins reported as unavailable by pinctrl (i.e.
ok_for_pinctrl).
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH 1/4] gpiolib: cdev: Flag invalid GPIOs as used
In reply to Marc ZyngierQuoted 15 lines · Marc Zyngier
When reporting the state of a GPIO to userspace, we never check for the actual validity of the line, meaning we report invalid lines as being usable. A subsequent request will fail though, which is an inconsistent behaviour from a userspace perspective.
Instead, let's check for the validity of the line and report it as used if it is invalid. This allows a tool such as gpioinfo to report something sensible:
gpiochip3 - 4 lines:
line 0: unnamed unused input active-high line 1: unnamed kernel input active-high [used] line 2: unnamed kernel input active-high [used] line 3: unnamed unused input active-high
Quoted 4 lines
In this example, lines 1 and 2 are invalid, and cannot be used by userspace.
Signed-off-by Marc Zyngier <[email protected]>
This makes sense, so patch applied (unless Bartosz tells me otherwise, then I'll pull it out again).
Yours,
Linus Walleij
PATCH 2/4 USB: serial: ftdi_sio: Report the valid GPIO lines to gpiolib
In reply to Marc ZyngierSince it is pretty common for only some of the CBUS lines to be valid as GPIO lines, let's report such validity to the rest of the kernel.
--- drivers/usb/serial/ftdi_sio.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/usb/serial/ftdi_sio.c +14 -0
@@ -2002,6 +2002,19 @@ static int ftdi_gpio_direction_output(struct gpio_chip *gc, unsigned int gpio,return result; } +static int ftdi_gpio_init_valid_mask (struct gpio_chip *gc, +unsigned long *valid_mask, +unsigned int ngpios) +{ +struct usb_serial_port *port =gpiochip_get_data (gc); +struct ftdi_private *priv =usb_get_serial_port_data (port); +unsigned long map = priv->gpio_altfunc; + +bitmap_complement (valid_mask, &map, ngpios); + +return 0 ; +} +static int ftdi_read_eeprom (struct usb_serial *serial,void *dst,u16 addr,u16 nbytes) {
@@ -2173,6 +2186,7 @@ static int ftdi_gpio_init(struct usb_serial_port *port) priv->gc.get_direction = ftdi_gpio_direction_get; priv->gc.direction_input = ftdi_gpio_direction_input; priv->gc.direction_output = ftdi_gpio_direction_output; + priv->gc.init_valid_mask = ftdi_gpio_init_valid_mask; priv->gc.get = ftdi_gpio_get; priv->gc.set = ftdi_gpio_set; priv->gc.get_multiple = ftdi_gpio_get_multiple;
Signature · 1 line
2.28.0
Re: [PATCH 2/4] USB: serial: ftdi_sio: Report the valid GPIO lines to gpiolib
Quoted 5 lines · Marc Zyngier
Since it is pretty common for only some of the CBUS lines to be valid as GPIO lines, let's report such validity to the rest of the kernel.
Signed-off-by Marc Zyngier <[email protected]>
Yours,
Linus Walleij
PATCH 3/4 USB: serial: ftdi_sio: Log the CBUS GPIO validity
In reply to Marc ZyngierThe validity of the ftdi CBUS GPIO is pretty hidden so far, and finding out *why* some GPIOs don't work is sometimes hard to identify. So let's help the user by displaying the map of the CBUS pins that are valid for a GPIO.
Also, tell the user about the magic ftx-prog tool that can make GPIOs appear: https://github.com/richardeoin/ftx-prog
--- drivers/usb/serial/ftdi_sio.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/usb/serial/ftdi_sio.c +9 -0
@@ -2012,6 +2012,15 @@ static int ftdi_gpio_init_valid_mask(struct gpio_chip *gc,bitmap_complement (valid_mask, &map, ngpios); +if (bitmap_empty (valid_mask, ngpios)) +dev_warn (&port->dev,"No usable GPIO\n" ); +else +dev_info (&port->dev,"Enabling CBUS%*pbl for GPIO\n" , + ngpios, valid_mask); + +if (!bitmap_full (valid_mask, ngpios)) +dev_warn_once (&port->dev,"Consider using a tool such as ftx-prog to enable GPIOs if required\n" ); +return 0 ; }
Signature · 1 line
2.28.0
Johan Hovold
maintainerRe: [PATCH 3/4] USB: serial: ftdi_sio: Log the CBUS GPIO validity
Quoted 19 lines · Marc Zyngier
The validity of the ftdi CBUS GPIO is pretty hidden so far, and finding out *why* some GPIOs don't work is sometimes hard to identify. So let's help the user by displaying the map of the CBUS pins that are valid for a GPIO.
Also, tell the user about the magic ftx-prog tool that can make GPIOs appear: https://github.com/richardeoin/ftx-prog
Suggested-by Linus Walleij <[email protected]>Signed-off-by Marc Zyngier <[email protected]>--- drivers/usb/serial/ftdi_sio.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/usb/serial/ftdi_sio.c +0
-0
drivers/usb/serial/ftdi_sio.c static int ftdi_gpio_init_valid_mask(struct gpio_chip *gc, · line 2016
Quoted 5 lines
drivers/usb/serial/ftdi_sio.c +2
-0@@ -2012,6 +2012,15 @@ static int ftdi_gpio_init_valid_mask(struct gpio_chip *gc,bitmap_complement (valid_mask, &map, ngpios); +if (bitmap_empty (valid_mask, ngpios)) +dev_warn (&port->dev,"No usable GPIO\n" );
This isn't an error of any kind, and certainly not something that deserves a warning in the system log on every probe. Not everyone cares about the GPIO interface.
drivers/usb/serial/ftdi_sio.c static int ftdi_gpio_init_valid_mask(struct gpio_chip *gc, · line 2019
Quoted 3 lines
drivers/usb/serial/ftdi_sio.c +3
-0+else +dev_info (&port->dev,"Enabling CBUS%*pbl for GPIO\n" , + ngpios, valid_mask);
And while printing this mask has some worth I'm still reluctant to be spamming the logs with it. Just like gpolib has a dev_dbg() for registering chips, this should probably be demoted to KERN_DEBUG as well.
drivers/usb/serial/ftdi_sio.c static int ftdi_gpio_init_valid_mask(struct gpio_chip *gc, · line 2023
Quoted 4 lines
drivers/usb/serial/ftdi_sio.c +4
-0+ +if (!bitmap_full (valid_mask, ngpios)) +dev_warn_once (&port->dev,"Consider using a tool such as ftx-prog to enable GPIOs if required\n" ); +
And again, this is not something that belongs in the logs of just about every system with an attached ftdi device.
While not possible to combine with the valid_mask approach, this is something which we could otherwise add to the request() callback for the first request that fails due to the mux configuration.
drivers/usb/serial/ftdi_sio.c static int ftdi_gpio_init_valid_mask(struct gpio_chip *gc, · line 2025
Quoted 2 lines
drivers/usb/serial/ftdi_sio.c +0
-0return 0 ; }
Johan
Re: [PATCH 3/4] USB: serial: ftdi_sio: Log the CBUS GPIO validity
Quoted 40 lines · Johan Hovold
Quoted 19 lines · Marc Zyngier
The validity of the ftdi CBUS GPIO is pretty hidden so far, and finding out *why* some GPIOs don't work is sometimes hard to identify. So let's help the user by displaying the map of the CBUS pins that are valid for a GPIO.
Also, tell the user about the magic ftx-prog tool that can make GPIOs appear: https://github.com/richardeoin/ftx-prog
Suggested-by Linus Walleij <[email protected]>Signed-off-by Marc Zyngier <[email protected]>--- drivers/usb/serial/ftdi_sio.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/usb/serial/ftdi_sio.c +0
-0drivers/usb/serial/ftdi_sio.c static int ftdi_gpio_init_valid_mask(struct · line 2017
Quoted 6 lines
drivers/usb/serial/ftdi_sio.c +2
-0@@ -2012,6 +2012,15 @@ static int ftdi_gpio_init_valid_mask(struct gpio_chip *gc,bitmap_complement (valid_mask, &map, ngpios); +if (bitmap_empty (valid_mask, ngpios)) +dev_warn (&port->dev,"No usable GPIO\n" );This isn't an error of any kind, and certainly not something that deserves a warning in the system log on every probe. Not everyone cares about the GPIO interface.
drivers/usb/serial/ftdi_sio.c static int ftdi_gpio_init_valid_mask(struct gpio_chip *gc, · line 2019
Quoted 3 lines
drivers/usb/serial/ftdi_sio.c +3
-0+else +dev_info (&port->dev,"Enabling CBUS%*pbl for GPIO\n" , + ngpios, valid_mask);And while printing this mask has some worth I'm still reluctant to be spamming the logs with it. Just like gpolib has a
dev_dbg()for registering chips, this should probably be demoted toKERN_DEBUGas well.
Quoted 8 lines
drivers/usb/serial/ftdi_sio.c static int ftdi_gpio_init_valid_mask(struct gpio_chip *gc, · line 2023
Quoted 5 lines
drivers/usb/serial/ftdi_sio.c +4
-0+ +if (!bitmap_full (valid_mask, ngpios)) + dev_warn_once(&port->dev, "Consider using a tool such as ftx-prog to enable GPIOs if required\n"); +And again, this is not something that belongs in the logs of just about every system with an attached ftdi device.
Fine by me, this patch can be dropped without issue. After all, I now know how to deal with these chips.
Quoted 3 lines
While not possible to combine with the
valid_maskapproach, this is something which we could otherwise add to therequest()callback for the first request that fails due to the mux configuration.
That was Linus' initial suggestion. But I think a consistent user API is more important than free advise in the kernel log.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Johan Hovold
maintainerRe: [PATCH 3/4] USB: serial: ftdi_sio: Log the CBUS GPIO validity
Quoted 14 lines · Marc Zyngier
Quoted 9 lines · Johan Hovold
Quoted 4 lines · Marc Zyngier
(quoted diff) +2
-0+ if (!bitmap_full(valid_mask, ngpios)) + dev_warn_once(&port->dev, "Consider using a tool such as ftx-progto enable GPIOs if required\n");
+And again, this is not something that belongs in the logs of just about every system with an attached ftdi device.
Fine by me, this patch can be dropped without issue. After all, I now know how to deal with these chips.
Quoted 7 lines
Quoted 4 lines
While not possible to combine with the
valid_maskapproach, this is something which we could otherwise add to therequest()callback for the
first request that fails due to the mux configuration.That was Linus' initial suggestion. But I think a consistent user API is more important than free advise in the kernel log.
I tend to agree. So since your valid-mask approach clearly has some merit in that it marks the lines in use when using the new cdev interface, perhaps we should stick with that.
Johan
Re: [PATCH 3/4] USB: serial: ftdi_sio: Log the CBUS GPIO validity
Quoted 20 lines · Johan Hovold
Quoted 19 lines · Marc Zyngier
Quoted 9 lines · Johan Hovold
Quoted 4 lines · Marc Zyngier
(quoted diff) +2
-0+ if (!bitmap_full(valid_mask, ngpios)) + dev_warn_once(&port->dev, "Consider using a tool such as ftx-progto enable GPIOs if required\n");
+And again, this is not something that belongs in the logs of just about every system with an attached ftdi device.
Fine by me, this patch can be dropped without issue. After all, I now know how to deal with these chips.
Quoted 4 lines
While not possible to combine with the
valid_maskapproach, this is something which we could otherwise add to therequest()callback for the
first request that fails due to the mux configuration.
Quoted 6 lines
Quoted 2 lines
That was Linus' initial suggestion. But I think a consistent user API is more important than free advise in the kernel log.
I tend to agree. So since your valid-mask approach clearly has some merit in that it marks the lines in use when using the new cdev interface, perhaps we should stick with that.
It sounds like we agree that this patch sans prints is acceptable.
It makes things better so let's go with that.
The problem for the user is that the line looks to be "used by the kernel" (true in some sense) but they have no idea what to do about it and that the ftx-prog will solve their hacking problem.
It's a matter of taste admittedly, I have noticed that some subsystem maintainers are "dmesg minimalists" and want as little as possible in dmesg while some are "dmesg maximalists" and want as much messages and help as possible for users in dmesg. I tend toward the latter but it's not like I don't see the beauty and feeling of control that comes with a clean dmesg.
My usual argument is that different loglevels exist for a reason and those who don't want advice can just filter out anything but errors or worse. But it seems they don't really wanna hear that because on their pet systems KERN_INFO it is on by default so it bothers them.
Yours,
Linus Walleij
Johan Hovold
maintainerRe: [PATCH 3/4] USB: serial: ftdi_sio: Log the CBUS GPIO validity
Quoted 24 lines · Linus Walleij
Quoted 23 lines · Johan Hovold
Quoted 21 lines · Marc Zyngier
Quoted 9 lines · Johan Hovold
Quoted 4 lines · Marc Zyngier
(quoted diff) +2
-0+ if (!bitmap_full(valid_mask, ngpios)) + dev_warn_once(&port->dev, "Consider using a tool such as ftx-progto enable GPIOs if required\n");
+And again, this is not something that belongs in the logs of just about every system with an attached ftdi device.
Fine by me, this patch can be dropped without issue. After all, I now know how to deal with these chips.
Quoted 4 lines
While not possible to combine with the
valid_maskapproach, this is something which we could otherwise add to therequest()callback for the
first request that fails due to the mux configuration.That was Linus' initial suggestion. But I think a consistent user API is more important than free advise in the kernel log.
Quoted 7 lines
Quoted 3 lines
I tend to agree. So since your valid-mask approach clearly has some merit in that it marks the lines in use when using the new cdev interface, perhaps we should stick with that.
It sounds like we agree that this patch sans prints is acceptable.
It makes things better so let's go with that.
Sounds good.
I'm about to apply patches 2, 3 and 4 with some smaller changes like demoting the printk messages to KERN_DEBUG and dropping the ftx-progs warning.
Quoted 4 lines
The problem for the user is that the line looks to be "used by the kernel" (true in some sense) but they have no idea what to do about it and that the ftx-prog will solve their hacking problem.
Right, it's not ideal, but the datasheets for these devices clearly states that the configuration of the CBUS pins is done in EEPROM and the vendor provides some tool to do that. Then there's a bunch of open source implementations for the same including ftx-progs (which can only be used for a subset of these devices).
I'd be fine with a dev_err() on the first request that fails saying that the CBUS pin is not configured for GPIO use (perhaps even on every request if its not something that a non-root user can trigger). But we cannot have both that and have the line marked in-use through the chardev interface currently.
I'm admittedly a bit torn on which is preferable.
Johan
Johan Hovold
maintainerRe: [PATCH 3/4] USB: serial: ftdi_sio: Log the CBUS GPIO validity
Quoted 23 lines · Johan Hovold
Quoted 3 lines · Linus Walleij
It sounds like we agree that this patch sans prints is acceptable.
It makes things better so let's go with that.
Sounds good.
I'm about to apply patches 2, 3 and 4 with some smaller changes like demoting the printk messages to
KERN_DEBUGand dropping the ftx-progs warning.Quoted 4 lines
The problem for the user is that the line looks to be "used by the kernel" (true in some sense) but they have no idea what to do about it and that the ftx-prog will solve their hacking problem.
Right, it's not ideal, but the datasheets for these devices clearly states that the configuration of the CBUS pins is done in EEPROM and the vendor provides some tool to do that. Then there's a bunch of open source implementations for the same including ftx-progs (which can only be used for a subset of these devices).
Quoted 7 lines
I'd be fine with a
dev_err()on the first request that fails saying that the CBUS pin is not configured for GPIO use (perhaps even on every request if its not something that a non-root user can trigger). But we cannot have both that and have the line marked in-use through the chardev interface currently.I'm admittedly a bit torn on which is preferable.
I've applied the patches now. Having this reported through the chardev interface must be better than having to match up a failed request with something in the system log.
Johan
PATCH 4/4 USB: serial: ftdi_sio: Drop GPIO line checking dead code
In reply to Marc ZyngierNow that the code code can track the validity of GPIO pins, there is no need to check whether the line is valid.
--- drivers/usb/serial/ftdi_sio.c | 3 --- 1 file changed, 3 deletions(-)
drivers/usb/serial/ftdi_sio.c +0 -3
@@ -1841,9 +1841,6 @@ static int ftdi_gpio_request(struct gpio_chip *gc, unsigned int offset)struct ftdi_private *priv =usb_get_serial_port_data (port);int result; -if (priv->gpio_altfunc &BIT (offset)) -return -ENODEV ; -mutex_lock (&priv->gpio_lock);if (!priv->gpio_used) {/* Set default pin states, as we cannot get them from device */
Signature · 1 line
2.28.0
Quoted 25 lines · Marc Zyngier
Having recently tried to use the CBUS GPIOs that come thanks to the
ftdio_siodriver, it occurred to me that the driver has a couple of usability issues:- it advertises potential GPIOs that are reserved to other uses (LED control, or something else)
- it returns an odd error (
-ENODEV), instead of the expected-EINVALwhen a line is unavailable, leading to a difficult diagnosticWe address the issues in a number of ways:
- Stop reporting invalid GPIO lines as valid to userspace. It definitely seems odd to do so. Instead, report the line as being used, making the userspace interface a bit more consistent.
- Implement the
init_valid_mask()callback in theftdi_siodriver, allowing it to report which lines are actually valid.- As suggested by Linus, give an indication to the user of why some of the GPIO lines are unavailable, and point them to a useful tool (once per boot). It is a bit sad that there next to no documentation on how to use these CBUS pins.
Quoted 5 lines
- Drop the error reporting code, which has become useless at this point.
Tested with a couple of FTDI devices (FT230X and FT231X) and various CBUS configurations.
Series looks pretty good to me, FWIW,
Quoted 13 lines
Marc Zyngier (4):
gpiolib: cdev: Flag invalid GPIOs as used
USB: serial:ftdi_sio: Report the valid GPIO lines to gpiolib
USB: serial:ftdi_sio: Log the CBUS GPIO validity
USB: serial:ftdi_sio: Drop GPIO line checking dead codedrivers/gpio/gpiolib-cdev.c | 1 + drivers/usb/serial/ftdi_sio.c | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-)--
2.28.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Johan Hovold
maintainerQuoted 6 lines · Marc Zyngier
Having recently tried to use the CBUS GPIOs that come thanks to the
ftdio_siodriver, it occurred to me that the driver has a couple of usability issues:- it advertises potential GPIOs that are reserved to other uses (LED control, or something else)
Consider the alternative, that the gpio offsets (for CBUS0, CBUS1, CBUS2 or CBUS4) varies depending on how the pins have been muxed. Hardly very user friendly.
Quoted 2 lines
- it returns an odd error (
-ENODEV), instead of the expected-EINVALwhen a line is unavailable, leading to a difficult diagnostic
Hmm, maybe. Several gpio driver return -ENODEV when trying to request reserved pins. Even gpiolib returns -ENODEV when a pins is not yet available due to probe deferal.
-EBUSY could also be an alternative, but that's used to indicate that a line is already in use as a gpio.
Quoted 6 lines
We address the issues in a number of ways:
- Stop reporting invalid GPIO lines as valid to userspace. It definitely seems odd to do so. Instead, report the line as being used, making the userspace interface a bit more consistent.
Quoted 7 lines
- Implement the
init_valid_mask()callback in theftdi_siodriver, allowing it to report which lines are actually valid.- As suggested by Linus, give an indication to the user of why some of the GPIO lines are unavailable, and point them to a useful tool (once per boot). It is a bit sad that there next to no documentation on how to use these CBUS pins.
Don't be sad, Marc; write some documentation. ;)
Johan
Quoted 11 lines · Johan Hovold
Quoted 6 lines · Marc Zyngier
Having recently tried to use the CBUS GPIOs that come thanks to the
ftdio_siodriver, it occurred to me that the driver has a couple of usability issues:- it advertises potential GPIOs that are reserved to other uses (LED control, or something else)
Consider the alternative, that the gpio offsets (for CBUS0, CBUS1, CBUS2 or CBUS4) varies depending on how the pins have been muxed. Hardly very user friendly.
That's not what I suggest. If you want fixed GPIO offsets, fine by me. But telling the user "these are GPIOs you can use", and then "on second though, you can't" is not exactly consistent.
Quoted 6 lines
Quoted 2 lines
- it returns an odd error (
-ENODEV), instead of the expected-EINVALwhen a line is unavailable, leading to a difficult diagnosticHmm, maybe. Several gpio driver return
-ENODEVwhen trying to request reserved pins. Even gpiolib returns-ENODEVwhen a pins is not yet available due to probe deferal.
-ENODEV really means "no GPIOchip" in this context. The fact that other drivers return -ENODEV for reserved pins looks like a bug to me.
Quoted 2 lines
-EBUSYcould also be an alternative, but that's used to indicate that a line is already in use as a gpio.
Or something else. Which is exactly the case, as it's been allocated to another function.
Quoted 9 lines
Quoted 9 lines
We address the issues in a number of ways:
- Stop reporting invalid GPIO lines as valid to userspace. It definitely seems odd to do so. Instead, report the line as being used, making the userspace interface a bit more consistent.
- Implement the
init_valid_mask()callback in theftdi_siodriver, allowing it to report which lines are actually valid.
Quoted 6 lines
Quoted 4 lines
- As suggested by Linus, give an indication to the user of why some of the GPIO lines are unavailable, and point them to a useful tool (once per boot). It is a bit sad that there next to no documentation on how to use these CBUS pins.
Don't be sad, Marc; write some documentation. ;)
I sure will, right after I have fixed the rest of the kernel bugs I have introduced. With a bit of luck, that's right after I finally kick the bucket.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Johan Hovold
maintainerQuoted 9 lines · Marc Zyngier
Quoted 8 lines · Johan Hovold
Quoted 6 lines · Marc Zyngier
Having recently tried to use the CBUS GPIOs that come thanks to the
ftdio_siodriver, it occurred to me that the driver has a couple of usability issues:- it advertises potential GPIOs that are reserved to other uses (LED control, or something else)
Quoted 8 lines
Quoted 4 lines
Consider the alternative, that the gpio offsets (for CBUS0, CBUS1, CBUS2
or CBUS4) varies depending on how the pins have been muxed. Hardly very user friendly.That's not what I suggest. If you want fixed GPIO offsets, fine by me. But telling the user "these are GPIOs you can use", and then "on second though, you can't" is not exactly consistent.
It's really no different from any other gpio chip which registers all its lines, including those which may have been muxed for other purposes.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
- it returns an odd error (
-ENODEV), instead of the expected-EINVALwhen a line is unavailable, leading to a difficult diagnosticHmm, maybe. Several gpio driver return
-ENODEVwhen trying to request reserved pins. Even gpiolib returns-ENODEVwhen a pins is not yet available due to probe deferal.
-ENODEVreally means "no GPIOchip" in this context. The fact that other drivers return-ENODEVfor reserved pins looks like a bug to me.
No, the chip is there. The -ENODEV is what you get when requesting the line, because the line isn't available.
Quoted 5 lines
Quoted 2 lines
-EBUSYcould also be an alternative, but that's used to indicate that a line is already in use as a gpio.Or something else. Which is exactly the case, as it's been allocated to another function.
Right, there are invalid requests (e.g. requesting line five of a four line chip), lines that are already in use, and lines not available due to muxing.
And then there's the question of whether to use the same or distinct errnos for these. I believe using distinct errnos provides more feedback, but we can certainly pick another errno for this if it's really that confusing.
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
We address the issues in a number of ways:
- Stop reporting invalid GPIO lines as valid to userspace. It definitely seems odd to do so. Instead, report the line as being used, making the userspace interface a bit more consistent.
- Implement the
init_valid_mask()callback in theftdi_siodriver, allowing it to report which lines are actually valid.- As suggested by Linus, give an indication to the user of why some of the GPIO lines are unavailable, and point them to a useful tool (once per boot). It is a bit sad that there next to no documentation on how to use these CBUS pins.
Quoted 5 lines
Quoted 1 line
Don't be sad, Marc; write some documentation. ;)
I sure will, right after I have fixed the rest of the kernel bugs I have introduced. With a bit of luck, that's right after I finally kick the bucket.
Hear, hear.
Johan
Quoted 15 lines · Johan Hovold
Quoted 14 lines · Marc Zyngier
Quoted 12 lines · Johan Hovold
Quoted 6 lines · Marc Zyngier
Having recently tried to use the CBUS GPIOs that come thanks to the
ftdio_siodriver, it occurred to me that the driver has a couple of usability issues:- it advertises potential GPIOs that are reserved to other uses (LED control, or something else)
Consider the alternative, that the gpio offsets (for CBUS0, CBUS1, CBUS2
or CBUS4) varies depending on how the pins have been muxed. Hardly very user friendly.
Quoted 6 lines
Quoted 3 lines
That's not what I suggest. If you want fixed GPIO offsets, fine by me. But telling the user "these are GPIOs you can use", and then "on second though, you can't" is not exactly consistent.
It's really no different from any other gpio chip which registers all its lines, including those which may have been muxed for other purposes.
If they claim that their lines are available, and then refuse to let the user play with it, that's just a bug willing to be fixed.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
- it returns an odd error (
-ENODEV), instead of the expected-EINVALwhen a line is unavailable, leading to a difficult diagnosticHmm, maybe. Several gpio driver return
-ENODEVwhen trying to request reserved pins. Even gpiolib returns-ENODEVwhen a pins is not yet available due to probe deferal.
Quoted 5 lines
Quoted 2 lines
-ENODEVreally means "no GPIOchip" in this context. The fact that other drivers return-ENODEVfor reserved pins looks like a bug to me.No, the chip is there. The
-ENODEVis what you get when requesting the line, because the line isn't available.
I still believe that ENODEV is the wrong error. The device is there, but the request is invalid because the line is used by something else. EINVAL, EBUSY, ENXIO would all be (sort of) OK.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
-EBUSYcould also be an alternative, but that's used to indicate that a line is already in use as a gpio.Or something else. Which is exactly the case, as it's been allocated to another function.
Quoted 8 lines
Right, there are invalid requests (e.g. requesting line five of a four line chip), lines that are already in use, and lines not available due to muxing.
And then there's the question of whether to use the same or distinct errnos for these. I believe using distinct errnos provides more feedback, but we can certainly pick another errno for this if it's really that confusing.
Fundamentally, I don't think the backend driver should be in charge of the error reporting. That should be the char device's job. Leaving it to the individual drivers is a sure way to have an inconsistent API.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Johan Hovold
maintainerQuoted 20 lines · Marc Zyngier
Quoted 19 lines · Johan Hovold
Quoted 17 lines · Marc Zyngier
Quoted 5 lines · Johan Hovold
Quoted 4 lines · Marc Zyngier
Having recently tried to use the CBUS GPIOs that come thanks to the
ftdio_siodriver, it occurred to me that the driver has a couple of usability issues:Quoted 7 lines
Quoted 2 lines
- it advertises potential GPIOs that are reserved to other uses (LED control, or something else)
Consider the alternative, that the gpio offsets (for CBUS0, CBUS1, CBUS2
or CBUS4) varies depending on how the pins have been muxed. Hardly very user friendly.That's not what I suggest. If you want fixed GPIO offsets, fine by me. But telling the user "these are GPIOs you can use", and then "on second though, you can't" is not exactly consistent.
Quoted 6 lines
Quoted 3 lines
It's really no different from any other gpio chip which registers all its lines, including those which may have been muxed for other purposes.
If they claim that their lines are available, and then refuse to let the user play with it, that's just a bug willing to be fixed.
My point was that this is how *all* gpio drivers work, and that muxing is somewhat orthogonal to the gpio controller implementation.
Not sure how you would even "fix" that since muxing can often be changed at runtime while the number of lines is typically a hardware feature (which we report to the user). The resource is still there but it may not be available for use.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
- it returns an odd error (
-ENODEV), instead of the expected-EINVALwhen a line is unavailable, leading to a difficult diagnosticHmm, maybe. Several gpio driver return
-ENODEVwhen trying to request reserved pins. Even gpiolib returns-ENODEVwhen a pins is not yet available due to probe deferal.
-ENODEVreally means "no GPIOchip" in this context. The fact that other drivers return-ENODEVfor reserved pins looks like a bug to me.
Quoted 6 lines
Quoted 2 lines
No, the chip is there. The
-ENODEVis what you get when requesting the line, because the line isn't available.I still believe that ENODEV is the wrong error. The device is there, but the request is invalid because the line is used by something else. EINVAL, EBUSY, ENXIO would all be (sort of) OK.
Fair enough.
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
-EBUSYcould also be an alternative, but that's used to indicate that a line is already in use as a gpio.Or something else. Which is exactly the case, as it's been allocated to another function.
Right, there are invalid requests (e.g. requesting line five of a four line chip), lines that are already in use, and lines not available due to muxing.
Quoted 8 lines
Quoted 4 lines
And then there's the question of whether to use the same or distinct errnos for these. I believe using distinct errnos provides more feedback, but we can certainly pick another errno for this if it's really that confusing.
Fundamentally, I don't think the backend driver should be in charge of the error reporting. That should be the char device's job. Leaving it to the individual drivers is a sure way to have an inconsistent API.
I agree, and your valid-mask approach takes care of the static mux- configuration case nicely.
Johan
Quoted 7 lines · Johan Hovold
Quoted 2 lines · Marc Zyngier
If they claim that their lines are available, and then refuse to let the user play with it, that's just a bug willing to be fixed.
My point was that this is how *all* gpio drivers work, and that muxing is somewhat orthogonal to the gpio controller implementation.
This is true. It's because it is orthogonal that the separate subsystem for pin control including pin muxing exists.
Should I be really overly picky, the drivers that can mux lines like this should be implementing the pin control mux driver side as well just to make Linux aware of this. But if the muxing cannot be changed by the kernel (albeit with special tools) then it would be pretty overengineered for this case. Things would be much easier if this wasn't some flashing configuration but more of a runtime thing (which is kind of the implicit assumption in pin control land).
We don't really have many drivers that are "muxable by (intrusive) flashing" as opposed to "muxable by setting some bits" so in that way these FTDI drivers and siblings are special.
So this needs some special considerations to become user friendly I think.
Yours,
Linus Walleij
Johan Hovold
maintainerQuoted 12 lines · Linus Walleij
Quoted 7 lines · Johan Hovold
Quoted 2 lines · Marc Zyngier
If they claim that their lines are available, and then refuse to let the user play with it, that's just a bug willing to be fixed.
My point was that this is how *all* gpio drivers work, and that muxing is somewhat orthogonal to the gpio controller implementation.
This is true. It's because it is orthogonal that the separate subsystem for pin control including pin muxing exists.
Quoted 8 lines
Should I be really overly picky, the drivers that can mux lines like this should be implementing the pin control mux driver side as well just to make Linux aware of this. But if the muxing cannot be changed by the kernel (albeit with special tools) then it would be pretty overengineered for this case. Things would be much easier if this wasn't some flashing configuration but more of a runtime thing (which is kind of the implicit assumption in pin control land).
We'd still have problem of how to configure these hot-pluggable devices at runtime, so it's not necessarily easier.
If I remember correctly the xr_serial driver under review is doing something like muxing at runtime, but by simply having whichever interface (tty or gpio) that claims the resource first implicitly set the mux configuration. I have to revisit that.
Quoted 3 lines
We don't really have many drivers that are "muxable by (intrusive) flashing" as opposed to "muxable by setting some bits" so in that way these FTDI drivers and siblings are special.
Yeah, but the gpio-reserved-range (valid-mask) feature which Marc used comes close here.
Johan