gpio: gpio-pci-idio-16 regression after LTS upgrade
From: Mark Cave-Ayland
Date: Mon Oct 06 2025 - 04:37:42 EST
Hi all,
As part of our internal vfio testing here at Nutanix we make use of an emulated gpio-pci-idio-16 device. Recently we've upgraded our LTS kernel and found that the device stops working which I've bisected down to this commit:
$ git bisect bad
73d8f3efc5c2b757ab06685741df01eaed8090c4 is the first bad commit
commit 73d8f3efc5c2b757ab06685741df01eaed8090c4
Author: William Breathitt Gray <william.gray@xxxxxxxxxx>
Date: Thu Aug 10 18:00:40 2023 -0400
gpio: pci-idio-16: Migrate to the regmap API
The regmap API supports IO port accessors so we can take advantage of
regmap abstractions rather than handling access to the device registers
directly in the driver. Migrate the pci-idio-16 module to the new
idio-16 library interface leveraging the gpio-regmap API.
Suggested-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Link: https://lore.kernel.org/r/5ba5405c64aca984d5cf3bdbdffa04c325e5a147.1680618405.git.william.gray@xxxxxxxxxx/
Signed-off-by: William Breathitt Gray <william.gray@xxxxxxxxxx>
Reviewed-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
drivers/gpio/Kconfig | 2 +-
drivers/gpio/gpio-pci-idio-16.c | 294 +++++++++-------------------------------
2 files changed, 62 insertions(+), 234 deletions(-)
With this commit when the gpio-pci-idio16 module fails upon load as below:
[ 0.266606] pci-idio-16 0000:00:03.0: error -EINVAL: Unable to initialize register map
[ 0.266867] pci-idio-16: probe of 0000:00:03.0 failed with error -22
After some more debugging I was able to determine that the failure was due to the regmap cache failing initialisation in drivers/base/regmap/regcache-flat.c::regcache_flat_init() because max_register wasn't set on the regmap. I was able to fix that fairly easily with this:
diff --git a/drivers/gpio/gpio-pci-idio-16.c b/drivers/gpio/gpio-pci-idio-16.c
index 44c0a21b1d1d..55be571b5cca 100644
--- a/drivers/gpio/gpio-pci-idio-16.c
+++ b/drivers/gpio/gpio-pci-idio-16.c
@@ -41,6 +41,7 @@ static const struct regmap_config idio_16_regmap_config = {
.reg_stride = 1,
.val_bits = 8,
.io_port = true,
+ .max_register = 0x7,
.wr_table = &idio_16_wr_table,
.rd_table = &idio_16_rd_table,
.volatile_table = &idio_16_rd_table,
Okay so the module now loads, but all of my gpios are now inputs!
root@debian12:~# gpioinfo
gpiochip0 - 32 lines:
line 0: "OUT0" unused input active-high
line 1: "OUT1" unused input active-high
line 2: "OUT2" unused input active-high
line 3: "OUT3" unused input active-high
line 4: "OUT4" unused input active-high
line 5: "OUT5" unused input active-high
line 6: "OUT6" unused input active-high
line 7: "OUT7" unused input active-high
line 8: "OUT8" unused input active-high
line 9: "OUT9" unused input active-high
line 10: "OUT10" unused input active-high
line 11: "OUT11" unused input active-high
line 12: "OUT12" unused input active-high
line 13: "OUT13" unused input active-high
line 14: "OUT14" unused input active-high
line 15: "OUT15" unused input active-high
line 16: "IIN0" unused input active-high
line 17: "IIN1" unused input active-high
line 18: "IIN2" unused input active-high
line 19: "IIN3" unused input active-high
line 20: "IIN4" unused input active-high
line 21: "IIN5" unused input active-high
line 22: "IIN6" unused input active-high
line 23: "IIN7" unused input active-high
line 24: "IIN8" unused input active-high
line 25: "IIN9" unused input active-high
line 26: "IIN10" unused input active-high
line 27: "IIN11" unused input active-high
line 28: "IIN12" unused input active-high
line 29: "IIN13" unused input active-high
line 30: "IIN14" unused input active-high
line 31: "IIN15" unused input active-high
root@debian12:~# gpioget 0 0
gpioget: error reading GPIO values: Input/output error
which also output:
[ 329.529321] gpio-512 (gpioget): gpiod_direction_input: missing direction_input() operation and line is output
My guess is that this is because drivers/gpio/gpio-regmap.c::gpio_regmap_get_direction() isn't able to can't handle the situation where lines 0-15 are outputs and lines 16-31 are inputs, compared with the old idio_16_gpio_get_direction() function it replaced.
What would be the best way forward? Possibly add the .get_direction callback to the gpio_regmap_config? Or is there another way to have mixed inputs and outputs with the gpio_regmap API?
Many thanks,
Mark.