The Vortex86 family of SoCs need the direction set before the value, else
writes to the DATA ports are ignored.
This commit adds a new "flags" field plus a flag to change the default
behaviour, which is to set first the direction and then the value.
Signed-off-by: Marcos Del Sol Vives <marcos@orca.pet>
---
drivers/gpio/gpio-regmap.c | 17 ++++++++++++++++-
include/linux/gpio/regmap.h | 17 +++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
index e8a32dfebdcb..24cefbd57637 100644
--- a/drivers/gpio/gpio-regmap.c
+++ b/drivers/gpio/gpio-regmap.c
@@ -31,6 +31,7 @@ struct gpio_regmap {
unsigned int reg_clr_base;
unsigned int reg_dir_in_base;
unsigned int reg_dir_out_base;
+ unsigned int flags;
int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
unsigned int offset, unsigned int *reg,
@@ -196,7 +197,20 @@ static int gpio_regmap_direction_input(struct gpio_chip *chip,
static int gpio_regmap_direction_output(struct gpio_chip *chip,
unsigned int offset, int value)
{
- gpio_regmap_set(chip, offset, value);
+ struct gpio_regmap *gpio = gpiochip_get_data(chip);
+ int ret;
+
+ if (gpio->flags & GPIO_REGMAP_DIR_BEFORE_SET) {
+ ret = gpio_regmap_set_direction(chip, offset, true);
+ if (ret)
+ return ret;
+
+ return gpio_regmap_set(chip, offset, value);
+ }
+
+ ret = gpio_regmap_set(chip, offset, value);
+ if (ret)
+ return ret;
return gpio_regmap_set_direction(chip, offset, true);
}
@@ -247,6 +261,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
gpio->reg_clr_base = config->reg_clr_base;
gpio->reg_dir_in_base = config->reg_dir_in_base;
gpio->reg_dir_out_base = config->reg_dir_out_base;
+ gpio->flags = config->flags;
chip = &gpio->gpio_chip;
chip->parent = config->parent;
diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h
index c722c67668c6..aea107e71fec 100644
--- a/include/linux/gpio/regmap.h
+++ b/include/linux/gpio/regmap.h
@@ -12,6 +12,20 @@ struct regmap;
#define GPIO_REGMAP_ADDR_ZERO ((unsigned int)(-1))
#define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO)
+
+/**
+ * enum gpio_regmap_flags - flags to control GPIO operation
+ */
+enum gpio_regmap_flags {
+ /**
+ * @GPIO_REGMAP_DIR_BEFORE_SET: when setting a pin as an output, set
+ * its direction before the value. The output value will be undefined
+ * for a short time which may have unwanted side effects, but some
+ * hardware requires this.
+ */
+ GPIO_REGMAP_DIR_BEFORE_SET = BIT(0),
+};
+
/**
* struct gpio_regmap_config - Description of a generic regmap gpio_chip.
* @parent: The parent device
@@ -23,6 +37,8 @@ struct regmap;
* If not given, the name of the device is used.
* @ngpio: (Optional) Number of GPIOs
* @names: (Optional) Array of names for gpios
+ * @flags: (Optional) A bitmask of flags from
+ * &enum gpio_regmap_flags
* @reg_dat_base: (Optional) (in) register base address
* @reg_set_base: (Optional) set register base address
* @reg_clr_base: (Optional) clear register base address
@@ -68,6 +84,7 @@ struct gpio_regmap_config {
const char *label;
int ngpio;
const char *const *names;
+ unsigned int flags;
unsigned int reg_dat_base;
unsigned int reg_set_base;
--
2.34.1
Hi Marcos, kernel test robot noticed the following build errors: [auto build test ERROR on brgl/gpio/for-next] [also build test ERROR on lee-mfd/for-mfd-next lee-mfd/for-mfd-fixes pci/next pci/for-linus linus/master v6.17-rc2 next-20250821] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Marcos-Del-Sol-Vives/gpio-gpio-regmap-add-flags-to-control-some-behaviour/20250821-182416 base: https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next patch link: https://lore.kernel.org/r/20250821101902.626329-2-marcos%40orca.pet patch subject: [PATCH v3 1/3] gpio: gpio-regmap: add flags to control some behaviour config: x86_64-buildonly-randconfig-001-20250822 (https://download.01.org/0day-ci/archive/20250822/202508221142.ETxcEpjA-lkp@intel.com/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250822/202508221142.ETxcEpjA-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202508221142.ETxcEpjA-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from drivers/gpio/gpio-fxl6408.c:11: >> include/linux/gpio/regmap.h:26:31: error: call to undeclared function 'BIT'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 26 | GPIO_REGMAP_DIR_BEFORE_SET = BIT(0), | ^ >> include/linux/gpio/regmap.h:26:31: error: expression is not an integer constant expression 26 | GPIO_REGMAP_DIR_BEFORE_SET = BIT(0), | ^~~~~~ In file included from drivers/gpio/gpio-fxl6408.c:12: In file included from include/linux/i2c.h:13: In file included from include/linux/acpi.h:14: In file included from include/linux/device.h:32: In file included from include/linux/device/driver.h:21: In file included from include/linux/module.h:20: In file included from include/linux/elf.h:6: In file included from arch/x86/include/asm/elf.h:10: In file included from arch/x86/include/asm/ia32.h:7: In file included from include/linux/compat.h:17: In file included from include/linux/fs.h:34: In file included from include/linux/percpu-rwsem.h:7: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:98:11: warning: array index 3 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 98 | return (set->sig[3] | set->sig[2] | | ^ ~ arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here 24 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from drivers/gpio/gpio-fxl6408.c:12: In file included from include/linux/i2c.h:13: In file included from include/linux/acpi.h:14: In file included from include/linux/device.h:32: In file included from include/linux/device/driver.h:21: In file included from include/linux/module.h:20: In file included from include/linux/elf.h:6: In file included from arch/x86/include/asm/elf.h:10: In file included from arch/x86/include/asm/ia32.h:7: In file included from include/linux/compat.h:17: In file included from include/linux/fs.h:34: In file included from include/linux/percpu-rwsem.h:7: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:98:25: warning: array index 2 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 98 | return (set->sig[3] | set->sig[2] | | ^ ~ arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here 24 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from drivers/gpio/gpio-fxl6408.c:12: In file included from include/linux/i2c.h:13: In file included from include/linux/acpi.h:14: In file included from include/linux/device.h:32: In file included from include/linux/device/driver.h:21: In file included from include/linux/module.h:20: In file included from include/linux/elf.h:6: In file included from arch/x86/include/asm/elf.h:10: In file included from arch/x86/include/asm/ia32.h:7: In file included from include/linux/compat.h:17: In file included from include/linux/fs.h:34: In file included from include/linux/percpu-rwsem.h:7: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:99:4: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 99 | set->sig[1] | set->sig[0]) == 0; | ^ ~ arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here 24 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from drivers/gpio/gpio-fxl6408.c:12: In file included from include/linux/i2c.h:13: In file included from include/linux/acpi.h:14: In file included from include/linux/device.h:32: In file included from include/linux/device/driver.h:21: In file included from include/linux/module.h:20: In file included from include/linux/elf.h:6: In file included from arch/x86/include/asm/elf.h:10: In file included from arch/x86/include/asm/ia32.h:7: In file included from include/linux/compat.h:17: In file included from include/linux/fs.h:34: In file included from include/linux/percpu-rwsem.h:7: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:101:11: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] 101 | return (set->sig[1] | set->sig[0]) == 0; | ^ ~ arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here 24 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from drivers/gpio/gpio-fxl6408.c:12: In file included from include/linux/i2c.h:13: In file included from include/linux/acpi.h:14: In file included from include/linux/device.h:32: In file included from include/linux/device/driver.h:21: In file included from include/linux/module.h:20: In file included from include/linux/elf.h:6: In file included from arch/x86/include/asm/elf.h:10: In file included from arch/x86/include/asm/ia32.h:7: In file included from include/linux/compat.h:17: In file included from include/linux/fs.h:34: In file included from include/linux/percpu-rwsem.h:7: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:114:11: warning: array index 3 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds] 114 | return (set1->sig[3] == set2->sig[3]) && | ^ ~ arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here vim +/BIT +26 include/linux/gpio/regmap.h 14 15 16 /** 17 * enum gpio_regmap_flags - flags to control GPIO operation 18 */ 19 enum gpio_regmap_flags { 20 /** 21 * @GPIO_REGMAP_DIR_BEFORE_SET: when setting a pin as an output, set 22 * its direction before the value. The output value will be undefined 23 * for a short time which may have unwanted side effects, but some 24 * hardware requires this. 25 */ > 26 GPIO_REGMAP_DIR_BEFORE_SET = BIT(0), 27 }; 28 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
El 22/08/2025 a las 5:27, kernel test robot escribió: > Hi Marcos, > > kernel test robot noticed the following build errors: > > [auto build test ERROR on brgl/gpio/for-next] > [also build test ERROR on lee-mfd/for-mfd-next lee-mfd/for-mfd-fixes pci/next pci/for-linus linus/master v6.17-rc2 next-20250821] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch#_base_tree_information] > > url: https://github.com/intel-lab-lkp/linux/commits/Marcos-Del-Sol-Vives/gpio-gpio-regmap-add-flags-to-control-some-behaviour/20250821-182416 > base: https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next > patch link: https://lore.kernel.org/r/20250821101902.626329-2-marcos%40orca.pet > patch subject: [PATCH v3 1/3] gpio: gpio-regmap: add flags to control some behaviour > config: x86_64-buildonly-randconfig-001-20250822 (https://download.01.org/0day-ci/archive/20250822/202508221142.ETxcEpjA-lkp@intel.com/config) > compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250822/202508221142.ETxcEpjA-lkp@intel.com/reproduce) > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > the same patch/commit), kindly add following tags > | Reported-by: kernel test robot <lkp@intel.com> > | Closes: https://lore.kernel.org/oe-kbuild-all/202508221142.ETxcEpjA-lkp@intel.com/ > > All errors (new ones prefixed by >>): > > In file included from drivers/gpio/gpio-fxl6408.c:11: >>> include/linux/gpio/regmap.h:26:31: error: call to undeclared function 'BIT'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] > 26 | GPIO_REGMAP_DIR_BEFORE_SET = BIT(0), > | ^ >>> include/linux/gpio/regmap.h:26:31: error: expression is not an integer constant expression > 26 | GPIO_REGMAP_DIR_BEFORE_SET = BIT(0), > | ^~~~~~ > In file included from drivers/gpio/gpio-fxl6408.c:12: > In file included from include/linux/i2c.h:13: > In file included from include/linux/acpi.h:14: > In file included from include/linux/device.h:32: > In file included from include/linux/device/driver.h:21: > In file included from include/linux/module.h:20: > In file included from include/linux/elf.h:6: > In file included from arch/x86/include/asm/elf.h:10: > In file included from arch/x86/include/asm/ia32.h:7: > In file included from include/linux/compat.h:17: > In file included from include/linux/fs.h:34: > In file included from include/linux/percpu-rwsem.h:7: > In file included from include/linux/rcuwait.h:6: > In file included from include/linux/sched/signal.h:6: > include/linux/signal.h:98:11: warning: array index 3 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds] This is correct, thanks. I added a missing "#include <linux/bits.h>" to fix it. Will be in a v4 of the patch set.
On Thu, Aug 21, 2025 at 12:19 PM Marcos Del Sol Vives <marcos@orca.pet> wrote: > static int gpio_regmap_direction_output(struct gpio_chip *chip, > unsigned int offset, int value) > { > - gpio_regmap_set(chip, offset, value); > + struct gpio_regmap *gpio = gpiochip_get_data(chip); > + int ret; > + > + if (gpio->flags & GPIO_REGMAP_DIR_BEFORE_SET) { > + ret = gpio_regmap_set_direction(chip, offset, true); > + if (ret) > + return ret; > + > + return gpio_regmap_set(chip, offset, value); > + } > + > + ret = gpio_regmap_set(chip, offset, value); > + if (ret) > + return ret; > > return gpio_regmap_set_direction(chip, offset, true); I guess this looks like this because it is just copied from gpio-mmio.c: static int bgpio_simple_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) { gc->set(gc, gpio, val); return bgpio_dir_return(gc, gpio, true); } It's hard to know which semantic to employ here, it's one way or the other. I like the new flag. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> You can merge this with the rest of the series. Yours, Linus Walleij
Hi, On Thu Aug 21, 2025 at 6:40 PM CEST, Linus Walleij wrote: > On Thu, Aug 21, 2025 at 12:19 PM Marcos Del Sol Vives <marcos@orca.pet> wrote: > > > static int gpio_regmap_direction_output(struct gpio_chip *chip, > > unsigned int offset, int value) > > { > > - gpio_regmap_set(chip, offset, value); > > + struct gpio_regmap *gpio = gpiochip_get_data(chip); > > + int ret; > > + > > + if (gpio->flags & GPIO_REGMAP_DIR_BEFORE_SET) { > > + ret = gpio_regmap_set_direction(chip, offset, true); > > + if (ret) > > + return ret; > > + > > + return gpio_regmap_set(chip, offset, value); > > + } > > + > > + ret = gpio_regmap_set(chip, offset, value); > > + if (ret) > > + return ret; Could you add a short paragraph to the commit message that you've added error checking? Something like: While at it, add the missing error check in gpio_regmap_direction_output(). > > > > return gpio_regmap_set_direction(chip, offset, true); > > I guess this looks like this because it is just copied from > gpio-mmio.c: Yeah probably :) With that above fixed: Reviewed-by: Michael Walle <mwalle@kernel.org>
El 22/08/2025 a las 9:07, Michael Walle escribió: >>> + ret = gpio_regmap_set(chip, offset, value); >>> + if (ret) >>> + return ret; > > Could you add a short paragraph to the commit message that you've > added error checking? Something like: > > While at it, add the missing error check in > gpio_regmap_direction_output(). > Added! Thanks for the feedback!
Not my area, but consider making the subject more specific, e.g., "add flag to set direction before value" On Thu, Aug 21, 2025 at 12:18:57PM +0200, Marcos Del Sol Vives wrote: > The Vortex86 family of SoCs need the direction set before the value, else > writes to the DATA ports are ignored. > > This commit adds a new "flags" field plus a flag to change the default > behaviour, which is to set first the direction and then the value. This sounds like the default behavior is to set direction, then value. But from the patch, it looks like: - default: set value, then direction - with GPIO_REGMAP_DIR_BEFORE_SET: set direction, then value > Signed-off-by: Marcos Del Sol Vives <marcos@orca.pet> > --- > drivers/gpio/gpio-regmap.c | 17 ++++++++++++++++- > include/linux/gpio/regmap.h | 17 +++++++++++++++++ > 2 files changed, 33 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c > index e8a32dfebdcb..24cefbd57637 100644 > --- a/drivers/gpio/gpio-regmap.c > +++ b/drivers/gpio/gpio-regmap.c > @@ -31,6 +31,7 @@ struct gpio_regmap { > unsigned int reg_clr_base; > unsigned int reg_dir_in_base; > unsigned int reg_dir_out_base; > + unsigned int flags; > > int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base, > unsigned int offset, unsigned int *reg, > @@ -196,7 +197,20 @@ static int gpio_regmap_direction_input(struct gpio_chip *chip, > static int gpio_regmap_direction_output(struct gpio_chip *chip, > unsigned int offset, int value) > { > - gpio_regmap_set(chip, offset, value); > + struct gpio_regmap *gpio = gpiochip_get_data(chip); > + int ret; > + > + if (gpio->flags & GPIO_REGMAP_DIR_BEFORE_SET) { > + ret = gpio_regmap_set_direction(chip, offset, true); > + if (ret) > + return ret; > + > + return gpio_regmap_set(chip, offset, value); > + } > + > + ret = gpio_regmap_set(chip, offset, value); > + if (ret) > + return ret; > > return gpio_regmap_set_direction(chip, offset, true); > } > @@ -247,6 +261,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config > gpio->reg_clr_base = config->reg_clr_base; > gpio->reg_dir_in_base = config->reg_dir_in_base; > gpio->reg_dir_out_base = config->reg_dir_out_base; > + gpio->flags = config->flags; > > chip = &gpio->gpio_chip; > chip->parent = config->parent; > diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h > index c722c67668c6..aea107e71fec 100644 > --- a/include/linux/gpio/regmap.h > +++ b/include/linux/gpio/regmap.h > @@ -12,6 +12,20 @@ struct regmap; > #define GPIO_REGMAP_ADDR_ZERO ((unsigned int)(-1)) > #define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO) > > + > +/** > + * enum gpio_regmap_flags - flags to control GPIO operation > + */ > +enum gpio_regmap_flags { > + /** > + * @GPIO_REGMAP_DIR_BEFORE_SET: when setting a pin as an output, set > + * its direction before the value. The output value will be undefined > + * for a short time which may have unwanted side effects, but some > + * hardware requires this. > + */ > + GPIO_REGMAP_DIR_BEFORE_SET = BIT(0), > +}; > + > /** > * struct gpio_regmap_config - Description of a generic regmap gpio_chip. > * @parent: The parent device > @@ -23,6 +37,8 @@ struct regmap; > * If not given, the name of the device is used. > * @ngpio: (Optional) Number of GPIOs > * @names: (Optional) Array of names for gpios > + * @flags: (Optional) A bitmask of flags from > + * &enum gpio_regmap_flags > * @reg_dat_base: (Optional) (in) register base address > * @reg_set_base: (Optional) set register base address > * @reg_clr_base: (Optional) clear register base address > @@ -68,6 +84,7 @@ struct gpio_regmap_config { > const char *label; > int ngpio; > const char *const *names; > + unsigned int flags; > > unsigned int reg_dat_base; > unsigned int reg_set_base; > -- > 2.34.1 >
El 21/08/2025 a las 16:32, Bjorn Helgaas escribió: > Not my area, but consider making the subject more specific, e.g., > "add flag to set direction before value" > > On Thu, Aug 21, 2025 at 12:18:57PM +0200, Marcos Del Sol Vives wrote: >> The Vortex86 family of SoCs need the direction set before the value, else >> writes to the DATA ports are ignored. >> >> This commit adds a new "flags" field plus a flag to change the default >> behaviour, which is to set first the direction and then the value. > > This sounds like the default behavior is to set direction, then value. > But from the patch, it looks like: > > - default: set value, then direction > > - with GPIO_REGMAP_DIR_BEFORE_SET: set direction, then value > Noted, thanks for the feedback! I've amended the commit and now it reads: > gpio: gpio-regmap: add flag to set direction before value > > When configuring a pin as an output, the gpio-regmap driver by default > writes first to the the value register, and then configures the direction. > > The Vortex86 family of SoCs, however, need the direction set before the > value, else writes to the data ports are ignored. > > This commit adds a new "flags" field plus a flag to reverse that order, > allowing the direction to be set before the value. Hope that looks more clear! Thanks, Marcos
© 2016 - 2025 Red Hat, Inc.