[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20250822135816.739582-2-marcos@orca.pet>
Date: Fri, 22 Aug 2025 15:58:11 +0200
From: Marcos Del Sol Vives <marcos@...a.pet>
To: linux-kernel@...r.kernel.org
Cc: Marcos Del Sol Vives <marcos@...a.pet>,
Linus Walleij <linus.walleij@...aro.org>,
Bartosz Golaszewski <brgl@...ev.pl>,
Michael Walle <mwalle@...nel.org>,
Lee Jones <lee@...nel.org>,
Bjorn Helgaas <bhelgaas@...gle.com>,
linux-gpio@...r.kernel.org,
linux-pci@...r.kernel.org
Subject: [PATCH v4 1/3] gpio: gpio-regmap: add flag to set direction before value
When configuring a pin as an output, by default the gpio-regmap driver
writes first the value 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.
Also, added a missing error check in gpio_regmap_direction_output().
Signed-off-by: Marcos Del Sol Vives <marcos@...a.pet>
---
drivers/gpio/gpio-regmap.c | 17 ++++++++++++++++-
include/linux/gpio/regmap.h | 18 ++++++++++++++++++
2 files changed, 34 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..a2257a1288a8 100644
--- a/include/linux/gpio/regmap.h
+++ b/include/linux/gpio/regmap.h
@@ -3,6 +3,8 @@
#ifndef _LINUX_GPIO_REGMAP_H
#define _LINUX_GPIO_REGMAP_H
+#include <linux/bits.h>
+
struct device;
struct fwnode_handle;
struct gpio_regmap;
@@ -12,6 +14,19 @@ 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 +38,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 +85,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
Powered by blists - more mailing lists