* [PATCH v2 0/6] gpiolib: unify gpio-hog code
@ 2026-03-09 12:42 Bartosz Golaszewski
2026-03-09 12:42 ` [PATCH v2 1/6] gpio: of: clear OF_POPULATED on hog nodes in remove path Bartosz Golaszewski
` (6 more replies)
0 siblings, 7 replies; 12+ messages in thread
From: Bartosz Golaszewski @ 2026-03-09 12:42 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Geert Uytterhoeven,
Frank Rowand, Mika Westerberg, Andy Shevchenko, Aaro Koskinen,
Janusz Krzysztofik, Tony Lindgren, Russell King, Jonathan Corbet,
Shuah Khan
Cc: linux-gpio, linux-kernel, linux-acpi, linux-arm-kernel,
linux-omap, linux-doc, brgl, Bartosz Golaszewski, stable,
Mika Westerberg, Kevin Hilman
GPIO hogs are handled separately in three places: for OF, ACPI and
machine lookup. In addition hogs cannot be set up using software nodes.
A lot of that code is actually redundant and - except for some special
handling of OF nodes - can be unified in one place.
This series moves hogging into GPIO core and bases it on fwnode API
(with a single helper from OF to translate devicetree properties into
lookup flags), converts the two remaining users of machine hogs to using
software node approach and removes machine hog support entirely. In
addition, there's a patch extending the configurability of gpio-sim now
that it uses software nodes for hogs.
For merging: I think this should go through the GPIO tree with an Ack
from OMAP1 maintainers.
Even with the new feature for gpio-sim, this series still removes twice
the number of lines, it adds.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
Changes in v2:
- reduce the leakage of OF APIs into GPIO core by replacing
of_phandle_args with fwnode_reference_args
- fix return value check in patch 2/6
- shrink code in patch 2/6
- don't allow #gpio-cells to be 0
- extend commit message of patch 6/6 to explain the need for this new
feature
- Link to v1: https://patch.msgid.link/20260305-gpio-hog-fwnode-v1-0-97d7df6bbd17@oss.qualcomm.com
---
Bartosz Golaszewski (6):
gpio: of: clear OF_POPULATED on hog nodes in remove path
gpio: move hogs into GPIO core
gpio: sim: use fwnode-based GPIO hogs
ARM: omap1: ams-delta: convert GPIO hogs to using firmware nodes
gpio: remove machine hogs
gpio: sim: allow to define the active-low setting of a simulated hog
Documentation/driver-api/gpio/board.rst | 16 ---
arch/arm/mach-omap1/board-ams-delta.c | 32 ++++-
drivers/gpio/gpio-sim.c | 200 +++++++++++++++-----------------
drivers/gpio/gpiolib-acpi-core.c | 70 -----------
drivers/gpio/gpiolib-of.c | 152 ++++--------------------
drivers/gpio/gpiolib-of.h | 10 ++
drivers/gpio/gpiolib.c | 137 +++++++++++++---------
drivers/gpio/gpiolib.h | 3 +
include/linux/gpio/machine.h | 33 ------
9 files changed, 238 insertions(+), 415 deletions(-)
---
base-commit: a0ae2a256046c0c5d3778d1a194ff2e171f16e5f
change-id: 20260224-gpio-hog-fwnode-b46a53196253
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 1/6] gpio: of: clear OF_POPULATED on hog nodes in remove path
2026-03-09 12:42 [PATCH v2 0/6] gpiolib: unify gpio-hog code Bartosz Golaszewski
@ 2026-03-09 12:42 ` Bartosz Golaszewski
2026-03-09 12:42 ` [PATCH v2 2/6] gpio: move hogs into GPIO core Bartosz Golaszewski
` (5 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Bartosz Golaszewski @ 2026-03-09 12:42 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Geert Uytterhoeven,
Frank Rowand, Mika Westerberg, Andy Shevchenko, Aaro Koskinen,
Janusz Krzysztofik, Tony Lindgren, Russell King, Jonathan Corbet,
Shuah Khan
Cc: linux-gpio, linux-kernel, linux-acpi, linux-arm-kernel,
linux-omap, linux-doc, brgl, Bartosz Golaszewski, stable
The previously set OF_POPULATED flag should be cleared on the hog nodes
when removing the chip.
Cc: stable@vger.kernel.org
Fixes: 63636d956c455 ("gpio: of: Add DT overlay support for GPIO hogs")
Acked-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/gpio/gpiolib-of.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index ef1ac68b94b78f09e768cc740e893632b8817505..08b7b662512b825086cd70440be98b59befc3ffe 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -1210,7 +1210,14 @@ int of_gpiochip_add(struct gpio_chip *chip)
void of_gpiochip_remove(struct gpio_chip *chip)
{
- of_node_put(dev_of_node(&chip->gpiodev->dev));
+ struct device_node *np = dev_of_node(&chip->gpiodev->dev);
+
+ for_each_child_of_node_scoped(np, child) {
+ if (of_property_present(child, "gpio-hog"))
+ of_node_clear_flag(child, OF_POPULATED);
+ }
+
+ of_node_put(np);
}
bool of_gpiochip_instance_match(struct gpio_chip *gc, unsigned int index)
--
2.47.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 2/6] gpio: move hogs into GPIO core
2026-03-09 12:42 [PATCH v2 0/6] gpiolib: unify gpio-hog code Bartosz Golaszewski
2026-03-09 12:42 ` [PATCH v2 1/6] gpio: of: clear OF_POPULATED on hog nodes in remove path Bartosz Golaszewski
@ 2026-03-09 12:42 ` Bartosz Golaszewski
2026-03-24 16:16 ` Geert Uytterhoeven
2026-03-09 12:42 ` [PATCH v2 3/6] gpio: sim: use fwnode-based GPIO hogs Bartosz Golaszewski
` (4 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Bartosz Golaszewski @ 2026-03-09 12:42 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Geert Uytterhoeven,
Frank Rowand, Mika Westerberg, Andy Shevchenko, Aaro Koskinen,
Janusz Krzysztofik, Tony Lindgren, Russell King, Jonathan Corbet,
Shuah Khan
Cc: linux-gpio, linux-kernel, linux-acpi, linux-arm-kernel,
linux-omap, linux-doc, brgl, Bartosz Golaszewski, Mika Westerberg
Refactor line hogging code by moving the parts duplicated in
gpiolib-acpi-core.c and gpiolib-of.c into gpiolib.c, leaving just the
OF-specific bits in the latter.
This makes fwnode the primary API for setting up hogs and allows to use
software nodes in addition to ACPI and OF nodes.
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/gpio/gpiolib-acpi-core.c | 70 -------------------
drivers/gpio/gpiolib-of.c | 143 +++++----------------------------------
drivers/gpio/gpiolib-of.h | 10 +++
drivers/gpio/gpiolib.c | 98 ++++++++++++++++++++++++++-
drivers/gpio/gpiolib.h | 3 +
5 files changed, 125 insertions(+), 199 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi-core.c b/drivers/gpio/gpiolib-acpi-core.c
index ced6375d1badf9e113e708ce4bc9f83071f9acca..09f860200a059b1d17c652b9aa66a49abea3cb4f 100644
--- a/drivers/gpio/gpiolib-acpi-core.c
+++ b/drivers/gpio/gpiolib-acpi-core.c
@@ -1220,75 +1220,6 @@ static void acpi_gpiochip_free_regions(struct acpi_gpio_chip *achip)
}
}
-static struct gpio_desc *
-acpi_gpiochip_parse_own_gpio(struct acpi_gpio_chip *achip,
- struct fwnode_handle *fwnode,
- const char **name,
- unsigned long *lflags,
- enum gpiod_flags *dflags)
-{
- struct gpio_chip *chip = achip->chip;
- struct gpio_desc *desc;
- u32 gpios[2];
- int ret;
-
- *lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
- *dflags = GPIOD_ASIS;
- *name = NULL;
-
- ret = fwnode_property_read_u32_array(fwnode, "gpios", gpios,
- ARRAY_SIZE(gpios));
- if (ret < 0)
- return ERR_PTR(ret);
-
- desc = gpiochip_get_desc(chip, gpios[0]);
- if (IS_ERR(desc))
- return desc;
-
- if (gpios[1])
- *lflags |= GPIO_ACTIVE_LOW;
-
- if (fwnode_property_present(fwnode, "input"))
- *dflags |= GPIOD_IN;
- else if (fwnode_property_present(fwnode, "output-low"))
- *dflags |= GPIOD_OUT_LOW;
- else if (fwnode_property_present(fwnode, "output-high"))
- *dflags |= GPIOD_OUT_HIGH;
- else
- return ERR_PTR(-EINVAL);
-
- fwnode_property_read_string(fwnode, "line-name", name);
-
- return desc;
-}
-
-static void acpi_gpiochip_scan_gpios(struct acpi_gpio_chip *achip)
-{
- struct gpio_chip *chip = achip->chip;
-
- device_for_each_child_node_scoped(chip->parent, fwnode) {
- unsigned long lflags;
- enum gpiod_flags dflags;
- struct gpio_desc *desc;
- const char *name;
- int ret;
-
- if (!fwnode_property_present(fwnode, "gpio-hog"))
- continue;
-
- desc = acpi_gpiochip_parse_own_gpio(achip, fwnode, &name,
- &lflags, &dflags);
- if (IS_ERR(desc))
- continue;
-
- ret = gpiod_hog(desc, name, lflags, dflags);
- if (ret) {
- dev_err(chip->parent, "Failed to hog GPIO\n");
- return;
- }
- }
-}
-
void acpi_gpiochip_add(struct gpio_chip *chip)
{
struct acpi_gpio_chip *acpi_gpio;
@@ -1321,7 +1252,6 @@ void acpi_gpiochip_add(struct gpio_chip *chip)
}
acpi_gpiochip_request_regions(acpi_gpio);
- acpi_gpiochip_scan_gpios(acpi_gpio);
acpi_dev_clear_dependencies(adev);
}
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 08b7b662512b825086cd70440be98b59befc3ffe..bc56003025258eba29c0897c43b29101fd490b17 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -10,6 +10,7 @@
#include <linux/device.h>
#include <linux/err.h>
#include <linux/errno.h>
+#include <linux/fwnode.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of.h>
@@ -735,139 +736,26 @@ struct gpio_desc *of_find_gpio(struct device_node *np, const char *con_id,
return desc;
}
-/**
- * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
- * @np: device node to get GPIO from
- * @chip: GPIO chip whose hog is parsed
- * @idx: Index of the GPIO to parse
- * @name: GPIO line name
- * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
- * of_find_gpio() or of_parse_own_gpio()
- * @dflags: gpiod_flags - optional GPIO initialization flags
- *
- * Returns:
- * GPIO descriptor to use with Linux GPIO API, or one of the errno
- * value on the error condition.
- */
-static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
- struct gpio_chip *chip,
- unsigned int idx, const char **name,
- unsigned long *lflags,
- enum gpiod_flags *dflags)
+int of_gpiochip_get_lflags(struct gpio_chip *chip,
+ struct fwnode_reference_args *gpiospec,
+ unsigned long *lflags)
{
- struct device_node *chip_np;
enum of_gpio_flags xlate_flags;
- struct of_phandle_args gpiospec;
+ struct of_phandle_args args;
struct gpio_desc *desc;
- unsigned int i;
- u32 tmp;
- int ret;
-
- chip_np = dev_of_node(&chip->gpiodev->dev);
- if (!chip_np)
- return ERR_PTR(-EINVAL);
-
- xlate_flags = 0;
- *lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
- *dflags = GPIOD_ASIS;
- ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp);
- if (ret)
- return ERR_PTR(ret);
+ args.np = to_of_node(gpiospec->fwnode);
+ args.args_count = gpiospec->nargs;
- gpiospec.np = chip_np;
- gpiospec.args_count = tmp;
+ for (int i = 0; i < args.args_count; i++)
+ args.args[i] = gpiospec->args[i];
- for (i = 0; i < tmp; i++) {
- ret = of_property_read_u32_index(np, "gpios", idx * tmp + i,
- &gpiospec.args[i]);
- if (ret)
- return ERR_PTR(ret);
- }
-
- desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags);
+ desc = of_xlate_and_get_gpiod_flags(chip, &args, &xlate_flags);
if (IS_ERR(desc))
- return desc;
+ return PTR_ERR(desc);
*lflags = of_convert_gpio_flags(xlate_flags);
- if (of_property_read_bool(np, "input"))
- *dflags |= GPIOD_IN;
- else if (of_property_read_bool(np, "output-low"))
- *dflags |= GPIOD_OUT_LOW;
- else if (of_property_read_bool(np, "output-high"))
- *dflags |= GPIOD_OUT_HIGH;
- else {
- pr_warn("GPIO line %d (%pOFn): no hogging state specified, bailing out\n",
- desc_to_gpio(desc), np);
- return ERR_PTR(-EINVAL);
- }
-
- if (name && of_property_read_string(np, "line-name", name))
- *name = np->name;
-
- return desc;
-}
-
-/**
- * of_gpiochip_add_hog - Add all hogs in a hog device node
- * @chip: gpio chip to act on
- * @hog: device node describing the hogs
- *
- * Returns:
- * 0 on success, or negative errno on failure.
- */
-static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog)
-{
- enum gpiod_flags dflags;
- struct gpio_desc *desc;
- unsigned long lflags;
- const char *name;
- unsigned int i;
- int ret;
-
- for (i = 0;; i++) {
- desc = of_parse_own_gpio(hog, chip, i, &name, &lflags, &dflags);
- if (IS_ERR(desc))
- break;
-
- ret = gpiod_hog(desc, name, lflags, dflags);
- if (ret < 0)
- return ret;
-
-#ifdef CONFIG_OF_DYNAMIC
- WRITE_ONCE(desc->hog, hog);
-#endif
- }
-
- return 0;
-}
-
-/**
- * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions
- * @chip: gpio chip to act on
- *
- * This is only used by of_gpiochip_add to request/set GPIO initial
- * configuration.
- *
- * Returns:
- * 0 on success, or negative errno on failure.
- */
-static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
-{
- int ret;
-
- for_each_available_child_of_node_scoped(dev_of_node(&chip->gpiodev->dev), np) {
- if (!of_property_read_bool(np, "gpio-hog"))
- continue;
-
- ret = of_gpiochip_add_hog(chip, np);
- if (ret < 0)
- return ret;
-
- of_node_set_flag(np, OF_POPULATED);
- }
-
return 0;
}
@@ -922,7 +810,7 @@ static int of_gpio_notify(struct notifier_block *nb, unsigned long action,
if (!gdev)
return NOTIFY_DONE; /* not for us */
- ret = of_gpiochip_add_hog(gpio_device_get_chip(gdev), rd->dn);
+ ret = gpiochip_add_hog(gpio_device_get_chip(gdev), of_fwnode_handle(rd->dn));
if (ret < 0) {
pr_err("%s: failed to add hogs for %pOF\n", __func__,
rd->dn);
@@ -1201,9 +1089,10 @@ int of_gpiochip_add(struct gpio_chip *chip)
of_node_get(np);
- ret = of_gpiochip_scan_gpios(chip);
- if (ret)
- of_node_put(np);
+ for_each_available_child_of_node_scoped(np, child) {
+ if (of_property_read_bool(child, "gpio-hog"))
+ of_node_set_flag(child, OF_POPULATED);
+ }
return ret;
}
diff --git a/drivers/gpio/gpiolib-of.h b/drivers/gpio/gpiolib-of.h
index 2257f7a498a10d69980f0c8afd48d5b661632d87..218cfe5bc4ac31a7c48306a08b4feafc06c0ad55 100644
--- a/drivers/gpio/gpiolib-of.h
+++ b/drivers/gpio/gpiolib-of.h
@@ -10,6 +10,7 @@
struct device_node;
struct fwnode_handle;
+struct fwnode_reference_args;
struct gpio_chip;
struct gpio_desc;
@@ -24,6 +25,9 @@ int of_gpiochip_add(struct gpio_chip *gc);
void of_gpiochip_remove(struct gpio_chip *gc);
bool of_gpiochip_instance_match(struct gpio_chip *gc, unsigned int index);
int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id);
+int of_gpiochip_get_lflags(struct gpio_chip *chip,
+ struct fwnode_reference_args *gpiospec,
+ unsigned long *lflags);
#else
static inline struct gpio_desc *of_find_gpio(struct device_node *np,
const char *con_id,
@@ -44,6 +48,12 @@ static inline int of_gpio_count(const struct fwnode_handle *fwnode,
{
return 0;
}
+static inline int of_gpiochip_get_lflags(struct gpio_chip *chip,
+ struct fwnode_reference_args *gpiospec,
+ unsigned long *lflags)
+{
+ return -ENOENT;
+}
#endif /* CONFIG_OF_GPIO */
extern struct notifier_block gpio_of_notifier;
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 581d00c128b608c30f45c12e968c15628e205870..b993cdae79e6dc389ca42ed079b3e39d1f9fed5a 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -948,7 +948,7 @@ static void gpiochip_machine_hog(struct gpio_chip *gc, struct gpiod_hog *hog)
__func__, gc->label, hog->chip_hwnum, rv);
}
-static void machine_gpiochip_add(struct gpio_chip *gc)
+static void gpiochip_machine_hog_lines(struct gpio_chip *gc)
{
struct gpiod_hog *hog;
@@ -960,6 +960,98 @@ static void machine_gpiochip_add(struct gpio_chip *gc)
}
}
+int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
+{
+ struct fwnode_handle *gc_node = dev_fwnode(&gc->gpiodev->dev);
+ struct fwnode_reference_args gpiospec;
+ enum gpiod_flags dflags;
+ struct gpio_desc *desc;
+ unsigned long lflags;
+ const char *name;
+ int ret, argc;
+ u32 gpios[3]; /* We support up to three-cell bindings. */
+ u32 cells;
+
+ lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
+ dflags = GPIOD_ASIS;
+ name = NULL;
+
+ argc = fwnode_property_count_u32(fwnode, "gpios");
+ if (argc < 0)
+ return argc;
+ if (argc > 3)
+ return -EINVAL;
+
+ ret = fwnode_property_read_u32_array(fwnode, "gpios", gpios, argc);
+ if (ret < 0)
+ return ret;
+
+ if (is_of_node(fwnode)) {
+ /*
+ * OF-nodes need some additional special handling for
+ * translating of devicetree flags.
+ */
+ ret = fwnode_property_read_u32(gc_node, "#gpio-cells", &cells);
+ if (ret)
+ return ret;
+ if (!ret && argc != cells)
+ return -EINVAL;
+
+ memset(&gpiospec, 0, sizeof(gpiospec));
+ gpiospec.fwnode = fwnode;
+ gpiospec.nargs = argc;
+
+ for (int i = 0; i < argc; i++)
+ gpiospec.args[i] = gpios[i];
+
+ ret = of_gpiochip_get_lflags(gc, &gpiospec, &lflags);
+ if (ret)
+ return ret;
+ } else {
+ /*
+ * GPIO_ACTIVE_LOW is currently the only lookup flag
+ * supported for non-OF firmware nodes.
+ */
+ if (gpios[1])
+ lflags |= GPIO_ACTIVE_LOW;
+ }
+
+ if (fwnode_property_present(fwnode, "input"))
+ dflags |= GPIOD_IN;
+ else if (fwnode_property_present(fwnode, "output-low"))
+ dflags |= GPIOD_OUT_LOW;
+ else if (fwnode_property_present(fwnode, "output-high"))
+ dflags |= GPIOD_OUT_HIGH;
+ else
+ return -EINVAL;
+
+ fwnode_property_read_string(fwnode, "line-name", &name);
+
+ desc = gpiochip_get_desc(gc, gpios[0]);
+ if (IS_ERR(desc))
+ return PTR_ERR(desc);
+
+ return gpiod_hog(desc, name, lflags, dflags);
+}
+
+static int gpiochip_hog_lines(struct gpio_chip *gc)
+{
+ int ret;
+
+ device_for_each_child_node_scoped(&gc->gpiodev->dev, fwnode) {
+ if (!fwnode_property_present(fwnode, "gpio-hog"))
+ continue;
+
+ ret = gpiochip_add_hog(gc, fwnode);
+ if (ret)
+ return ret;
+ }
+
+ gpiochip_machine_hog_lines(gc);
+
+ return 0;
+}
+
static void gpiochip_setup_devs(void)
{
struct gpio_device *gdev;
@@ -1209,7 +1301,9 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
acpi_gpiochip_add(gc);
- machine_gpiochip_add(gc);
+ ret = gpiochip_hog_lines(gc);
+ if (ret)
+ goto err_remove_of_chip;
ret = gpiochip_irqchip_init_valid_mask(gc);
if (ret)
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 8d1a762f9d11bfc29c9102be02d7b640aa7daad3..dc4cb61a93187659d943f4ce3622bc1755e9fd42 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -23,6 +23,8 @@
#define GPIOCHIP_NAME "gpiochip"
+struct fwnode_handle;
+
/**
* struct gpio_device - internal state container for GPIO devices
* @dev: the GPIO device struct
@@ -274,6 +276,7 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce);
int gpiod_hog(struct gpio_desc *desc, const char *name,
unsigned long lflags, enum gpiod_flags dflags);
+int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode);
int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev);
struct gpio_desc *gpiochip_get_desc(struct gpio_chip *gc, unsigned int hwnum);
const char *gpiod_get_label(struct gpio_desc *desc);
--
2.47.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 3/6] gpio: sim: use fwnode-based GPIO hogs
2026-03-09 12:42 [PATCH v2 0/6] gpiolib: unify gpio-hog code Bartosz Golaszewski
2026-03-09 12:42 ` [PATCH v2 1/6] gpio: of: clear OF_POPULATED on hog nodes in remove path Bartosz Golaszewski
2026-03-09 12:42 ` [PATCH v2 2/6] gpio: move hogs into GPIO core Bartosz Golaszewski
@ 2026-03-09 12:42 ` Bartosz Golaszewski
2026-03-09 12:42 ` [PATCH v2 4/6] ARM: omap1: ams-delta: convert GPIO hogs to using firmware nodes Bartosz Golaszewski
` (3 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Bartosz Golaszewski @ 2026-03-09 12:42 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Geert Uytterhoeven,
Frank Rowand, Mika Westerberg, Andy Shevchenko, Aaro Koskinen,
Janusz Krzysztofik, Tony Lindgren, Russell King, Jonathan Corbet,
Shuah Khan
Cc: linux-gpio, linux-kernel, linux-acpi, linux-arm-kernel,
linux-omap, linux-doc, brgl, Bartosz Golaszewski
Convert gpio-sim to using software nodes for setting up simulated hogs
instead of legacy machine hogs.
Reviewed-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/gpio/gpio-sim.c | 162 +++++++++++++++++-------------------------------
1 file changed, 56 insertions(+), 106 deletions(-)
diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 13b87c8e6d0caf62ce311dad409a9b4d3f091caa..51bcbdd91b4b027b7a340971a11cce5280ca1295 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -40,6 +40,7 @@
#define GPIO_SIM_NGPIO_MAX 1024
#define GPIO_SIM_PROP_MAX 5 /* Max 4 properties + sentinel. */
+#define GPIO_SIM_HOG_PROP_MAX 5
#define GPIO_SIM_NUM_ATTRS 3 /* value, pull and sentinel */
static DEFINE_IDA(gpio_sim_ida);
@@ -561,8 +562,6 @@ struct gpio_sim_device {
*/
struct mutex lock;
- struct gpiod_hog *hogs;
-
struct list_head bank_list;
};
@@ -774,102 +773,6 @@ static void gpio_sim_set_reserved_ranges(struct gpio_sim_bank *bank,
}
}
-static void gpio_sim_remove_hogs(struct gpio_sim_device *dev)
-{
- struct gpiod_hog *hog;
-
- if (!dev->hogs)
- return;
-
- gpiod_remove_hogs(dev->hogs);
-
- for (hog = dev->hogs; hog->chip_label; hog++) {
- kfree(hog->chip_label);
- kfree(hog->line_name);
- }
-
- kfree(dev->hogs);
- dev->hogs = NULL;
-}
-
-static int gpio_sim_add_hogs(struct gpio_sim_device *dev)
-{
- unsigned int num_hogs = 0, idx = 0;
- struct gpio_sim_bank *bank;
- struct gpio_sim_line *line;
- struct gpiod_hog *hog;
-
- list_for_each_entry(bank, &dev->bank_list, siblings) {
- list_for_each_entry(line, &bank->line_list, siblings) {
- if (line->offset >= bank->num_lines)
- continue;
-
- if (line->hog)
- num_hogs++;
- }
- }
-
- if (!num_hogs)
- return 0;
-
- /* Allocate one more for the sentinel. */
- dev->hogs = kzalloc_objs(*dev->hogs, num_hogs + 1);
- if (!dev->hogs)
- return -ENOMEM;
-
- list_for_each_entry(bank, &dev->bank_list, siblings) {
- list_for_each_entry(line, &bank->line_list, siblings) {
- if (line->offset >= bank->num_lines)
- continue;
-
- if (!line->hog)
- continue;
-
- hog = &dev->hogs[idx++];
-
- /*
- * We need to make this string manually because at this
- * point the device doesn't exist yet and so dev_name()
- * is not available.
- */
- if (gpio_sim_bank_has_label(bank))
- hog->chip_label = kstrdup(bank->label,
- GFP_KERNEL);
- else
- hog->chip_label = kasprintf(GFP_KERNEL,
- "gpio-sim.%u:%pfwP",
- dev->id,
- bank->swnode);
- if (!hog->chip_label) {
- gpio_sim_remove_hogs(dev);
- return -ENOMEM;
- }
-
- /*
- * We need to duplicate this because the hog config
- * item can be removed at any time (and we can't block
- * it) and gpiolib doesn't make a deep copy of the hog
- * data.
- */
- if (line->hog->name) {
- hog->line_name = kstrdup(line->hog->name,
- GFP_KERNEL);
- if (!hog->line_name) {
- gpio_sim_remove_hogs(dev);
- return -ENOMEM;
- }
- }
-
- hog->chip_hwnum = line->offset;
- hog->dflags = line->hog->dir;
- }
- }
-
- gpiod_add_hogs(dev->hogs);
-
- return 0;
-}
-
static struct fwnode_handle *
gpio_sim_make_bank_swnode(struct gpio_sim_bank *bank,
struct fwnode_handle *parent)
@@ -917,12 +820,61 @@ gpio_sim_make_bank_swnode(struct gpio_sim_bank *bank,
return fwnode_create_software_node(properties, parent);
}
+static int gpio_sim_bank_add_hogs(struct gpio_sim_bank *bank)
+{
+ struct property_entry properties[GPIO_SIM_HOG_PROP_MAX];
+ struct fwnode_handle *swnode;
+ struct gpio_sim_line *line;
+ struct gpio_sim_hog *hog;
+ unsigned int idx;
+ u32 gpios[2];
+
+ list_for_each_entry(line, &bank->line_list, siblings) {
+ if (!line->hog)
+ continue;
+
+ hog = line->hog;
+
+ gpios[0] = line->offset;
+ gpios[1] = 0;
+
+ memset(properties, 0, sizeof(properties));
+
+ idx = 0;
+ properties[idx++] = PROPERTY_ENTRY_BOOL("gpio-hog");
+ properties[idx++] = PROPERTY_ENTRY_U32_ARRAY("gpios", gpios);
+ properties[idx++] = PROPERTY_ENTRY_STRING("line-name", hog->name);
+
+ switch (hog->dir) {
+ case GPIOD_IN:
+ properties[idx++] = PROPERTY_ENTRY_BOOL("input");
+ break;
+ case GPIOD_OUT_HIGH:
+ properties[idx++] = PROPERTY_ENTRY_BOOL("output-high");
+ break;
+ case GPIOD_OUT_LOW:
+ properties[idx++] = PROPERTY_ENTRY_BOOL("output-low");
+ break;
+ default:
+ /* Would have been validated at configfs store. */
+ WARN(1, "Unexpected hog direction value: %d", hog->dir);
+ return -EINVAL;
+ }
+
+ swnode = fwnode_create_software_node(properties, bank->swnode);
+ if (IS_ERR(swnode))
+ return PTR_ERR(swnode);
+ }
+
+ return 0;
+}
+
static void gpio_sim_remove_swnode_recursive(struct fwnode_handle *swnode)
{
struct fwnode_handle *child;
fwnode_for_each_child_node(swnode, child)
- fwnode_remove_software_node(child);
+ gpio_sim_remove_swnode_recursive(child);
fwnode_remove_software_node(swnode);
}
@@ -977,12 +929,12 @@ static int gpio_sim_device_activate(struct gpio_sim_device *dev)
gpio_sim_remove_swnode_recursive(swnode);
return ret;
}
- }
- ret = gpio_sim_add_hogs(dev);
- if (ret) {
- gpio_sim_remove_swnode_recursive(swnode);
- return ret;
+ ret = gpio_sim_bank_add_hogs(bank);
+ if (ret) {
+ gpio_sim_remove_swnode_recursive(swnode);
+ return ret;
+ }
}
pdevinfo.name = "gpio-sim";
@@ -991,7 +943,6 @@ static int gpio_sim_device_activate(struct gpio_sim_device *dev)
ret = dev_sync_probe_register(&dev->probe_data, &pdevinfo);
if (ret) {
- gpio_sim_remove_hogs(dev);
gpio_sim_remove_swnode_recursive(swnode);
return ret;
}
@@ -1007,7 +958,6 @@ static void gpio_sim_device_deactivate(struct gpio_sim_device *dev)
swnode = dev_fwnode(&dev->probe_data.pdev->dev);
dev_sync_probe_unregister(&dev->probe_data);
- gpio_sim_remove_hogs(dev);
gpio_sim_remove_swnode_recursive(swnode);
}
--
2.47.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 4/6] ARM: omap1: ams-delta: convert GPIO hogs to using firmware nodes
2026-03-09 12:42 [PATCH v2 0/6] gpiolib: unify gpio-hog code Bartosz Golaszewski
` (2 preceding siblings ...)
2026-03-09 12:42 ` [PATCH v2 3/6] gpio: sim: use fwnode-based GPIO hogs Bartosz Golaszewski
@ 2026-03-09 12:42 ` Bartosz Golaszewski
2026-03-09 12:42 ` [PATCH v2 5/6] gpio: remove machine hogs Bartosz Golaszewski
` (2 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Bartosz Golaszewski @ 2026-03-09 12:42 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Geert Uytterhoeven,
Frank Rowand, Mika Westerberg, Andy Shevchenko, Aaro Koskinen,
Janusz Krzysztofik, Tony Lindgren, Russell King, Jonathan Corbet,
Shuah Khan
Cc: linux-gpio, linux-kernel, linux-acpi, linux-arm-kernel,
linux-omap, linux-doc, brgl, Bartosz Golaszewski, Kevin Hilman
Setup a software node hierarchy for the latch2 GPIO controller defining
the required hog and stop using legacy machine hog API.
Acked-by: Kevin Hilman <khilman@baylibre.com>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
arch/arm/mach-omap1/board-ams-delta.c | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/arch/arm/mach-omap1/board-ams-delta.c b/arch/arm/mach-omap1/board-ams-delta.c
index 16392720296cd224732450c85419c35bbab506f6..1bec4fa0bd5e8bfc58103d1f24b22176707fd26f 100644
--- a/arch/arm/mach-omap1/board-ams-delta.c
+++ b/arch/arm/mach-omap1/board-ams-delta.c
@@ -556,10 +556,30 @@ static struct gpiod_lookup_table *ams_delta_gpio_tables[] __initdata = {
&ams_delta_nand_gpio_table,
};
-static struct gpiod_hog ams_delta_gpio_hogs[] = {
- GPIO_HOG(LATCH2_LABEL, LATCH2_PIN_KEYBRD_DATAOUT, "keybrd_dataout",
- GPIO_ACTIVE_HIGH, GPIOD_OUT_LOW),
- {},
+static const struct software_node latch2_gpio_swnode = {
+ .name = LATCH2_LABEL,
+};
+
+static const u32 latch2_hog_gpios[] = { LATCH2_PIN_KEYBRD_DATAOUT, 0 };
+
+static const struct property_entry latch2_gpio_hog_props[] = {
+ PROPERTY_ENTRY_BOOL("gpio-hog"),
+ PROPERTY_ENTRY_U32_ARRAY("gpios", latch2_hog_gpios),
+ PROPERTY_ENTRY_STRING("line-name", "keybrd_dataout"),
+ PROPERTY_ENTRY_BOOL("output-low"),
+ { }
+};
+
+static const struct software_node latch2_gpio_hog_swnode = {
+ .parent = &latch2_gpio_swnode,
+ .name = "latch2-hog",
+ .properties = latch2_gpio_hog_props,
+};
+
+static const struct software_node *const latch2_gpio_swnodes[] = {
+ &latch2_gpio_swnode,
+ &latch2_gpio_hog_swnode,
+ NULL
};
static struct plat_serial8250_port ams_delta_modem_ports[];
@@ -684,7 +704,6 @@ static void __init ams_delta_init(void)
omap_gpio_deps_init();
ams_delta_latch2_init();
- gpiod_add_hogs(ams_delta_gpio_hogs);
omap_serial_init();
omap_register_i2c_bus(1, 100, NULL, 0);
@@ -693,6 +712,9 @@ static void __init ams_delta_init(void)
platform_add_devices(ams_delta_devices, ARRAY_SIZE(ams_delta_devices));
platform_device_register_full(&latch1_gpio_devinfo);
+
+ software_node_register_node_group(latch2_gpio_swnodes);
+ latch2_gpio_devinfo.fwnode = software_node_fwnode(&latch2_gpio_swnode);
platform_device_register_full(&latch2_gpio_devinfo);
/*
--
2.47.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 5/6] gpio: remove machine hogs
2026-03-09 12:42 [PATCH v2 0/6] gpiolib: unify gpio-hog code Bartosz Golaszewski
` (3 preceding siblings ...)
2026-03-09 12:42 ` [PATCH v2 4/6] ARM: omap1: ams-delta: convert GPIO hogs to using firmware nodes Bartosz Golaszewski
@ 2026-03-09 12:42 ` Bartosz Golaszewski
2026-05-20 0:46 ` Dmitry Torokhov
2026-03-09 12:42 ` [PATCH v2 6/6] gpio: sim: allow to define the active-low setting of a simulated hog Bartosz Golaszewski
2026-03-16 9:11 ` [PATCH v2 0/6] gpiolib: unify gpio-hog code Bartosz Golaszewski
6 siblings, 1 reply; 12+ messages in thread
From: Bartosz Golaszewski @ 2026-03-09 12:42 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Geert Uytterhoeven,
Frank Rowand, Mika Westerberg, Andy Shevchenko, Aaro Koskinen,
Janusz Krzysztofik, Tony Lindgren, Russell King, Jonathan Corbet,
Shuah Khan
Cc: linux-gpio, linux-kernel, linux-acpi, linux-arm-kernel,
linux-omap, linux-doc, brgl, Bartosz Golaszewski
With no more users, remove legacy machine hog API from the kernel.
Reviewed-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
Documentation/driver-api/gpio/board.rst | 16 --------
drivers/gpio/gpiolib.c | 71 ---------------------------------
include/linux/gpio/machine.h | 33 ---------------
3 files changed, 120 deletions(-)
diff --git a/Documentation/driver-api/gpio/board.rst b/Documentation/driver-api/gpio/board.rst
index 069b54d8591bdeb975a6c650d643db4f7eb98ab7..0993cac891fb5e4887a1aee6deae273197c6aae1 100644
--- a/Documentation/driver-api/gpio/board.rst
+++ b/Documentation/driver-api/gpio/board.rst
@@ -239,22 +239,6 @@ mapping and is thus transparent to GPIO consumers.
A set of functions such as gpiod_set_value() is available to work with
the new descriptor-oriented interface.
-Boards using platform data can also hog GPIO lines by defining GPIO hog tables.
-
-.. code-block:: c
-
- struct gpiod_hog gpio_hog_table[] = {
- GPIO_HOG("gpio.0", 10, "foo", GPIO_ACTIVE_LOW, GPIOD_OUT_HIGH),
- { }
- };
-
-And the table can be added to the board code as follows::
-
- gpiod_add_hogs(gpio_hog_table);
-
-The line will be hogged as soon as the gpiochip is created or - in case the
-chip was created earlier - when the hog table is registered.
-
Arrays of pins
--------------
In addition to requesting pins belonging to a function one by one, a device may
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index b993cdae79e6dc389ca42ed079b3e39d1f9fed5a..829774322f3595d191e13e89ef83001507f6fdea 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -103,9 +103,6 @@ static DEFINE_MUTEX(gpio_devices_lock);
/* Ensures coherence during read-only accesses to the list of GPIO devices. */
DEFINE_STATIC_SRCU(gpio_devices_srcu);
-static DEFINE_MUTEX(gpio_machine_hogs_mutex);
-static LIST_HEAD(gpio_machine_hogs);
-
const char *const gpio_suffixes[] = { "gpios", "gpio", NULL };
static void gpiochip_free_hogs(struct gpio_chip *gc);
@@ -930,36 +927,6 @@ static int gpiochip_setup_dev(struct gpio_chip *gc)
return ret;
}
-static void gpiochip_machine_hog(struct gpio_chip *gc, struct gpiod_hog *hog)
-{
- struct gpio_desc *desc;
- int rv;
-
- desc = gpiochip_get_desc(gc, hog->chip_hwnum);
- if (IS_ERR(desc)) {
- gpiochip_err(gc, "%s: unable to get GPIO desc: %ld\n",
- __func__, PTR_ERR(desc));
- return;
- }
-
- rv = gpiod_hog(desc, hog->line_name, hog->lflags, hog->dflags);
- if (rv)
- gpiod_err(desc, "%s: unable to hog GPIO line (%s:%u): %d\n",
- __func__, gc->label, hog->chip_hwnum, rv);
-}
-
-static void gpiochip_machine_hog_lines(struct gpio_chip *gc)
-{
- struct gpiod_hog *hog;
-
- guard(mutex)(&gpio_machine_hogs_mutex);
-
- list_for_each_entry(hog, &gpio_machine_hogs, list) {
- if (!strcmp(gc->label, hog->chip_label))
- gpiochip_machine_hog(gc, hog);
- }
-}
-
int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
{
struct fwnode_handle *gc_node = dev_fwnode(&gc->gpiodev->dev);
@@ -1047,8 +1014,6 @@ static int gpiochip_hog_lines(struct gpio_chip *gc)
return ret;
}
- gpiochip_machine_hog_lines(gc);
-
return 0;
}
@@ -4582,42 +4547,6 @@ void gpiod_remove_lookup_table(struct gpiod_lookup_table *table)
}
EXPORT_SYMBOL_GPL(gpiod_remove_lookup_table);
-/**
- * gpiod_add_hogs() - register a set of GPIO hogs from machine code
- * @hogs: table of gpio hog entries with a zeroed sentinel at the end
- */
-void gpiod_add_hogs(struct gpiod_hog *hogs)
-{
- struct gpiod_hog *hog;
-
- guard(mutex)(&gpio_machine_hogs_mutex);
-
- for (hog = &hogs[0]; hog->chip_label; hog++) {
- list_add_tail(&hog->list, &gpio_machine_hogs);
-
- /*
- * The chip may have been registered earlier, so check if it
- * exists and, if so, try to hog the line now.
- */
- struct gpio_device *gdev __free(gpio_device_put) =
- gpio_device_find_by_label(hog->chip_label);
- if (gdev)
- gpiochip_machine_hog(gpio_device_get_chip(gdev), hog);
- }
-}
-EXPORT_SYMBOL_GPL(gpiod_add_hogs);
-
-void gpiod_remove_hogs(struct gpiod_hog *hogs)
-{
- struct gpiod_hog *hog;
-
- guard(mutex)(&gpio_machine_hogs_mutex);
-
- for (hog = &hogs[0]; hog->chip_label; hog++)
- list_del(&hog->list);
-}
-EXPORT_SYMBOL_GPL(gpiod_remove_hogs);
-
static bool gpiod_match_lookup_table(struct device *dev,
const struct gpiod_lookup_table *table)
{
diff --git a/include/linux/gpio/machine.h b/include/linux/gpio/machine.h
index 44e5f162973eb6f6e85188f56ec34e1e3e2beab6..5eb88f5d0630f83b6a3a0e6727103c319e139b27 100644
--- a/include/linux/gpio/machine.h
+++ b/include/linux/gpio/machine.h
@@ -46,23 +46,6 @@ struct gpiod_lookup_table {
struct gpiod_lookup table[];
};
-/**
- * struct gpiod_hog - GPIO line hog table
- * @chip_label: name of the chip the GPIO belongs to
- * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
- * @line_name: consumer name for the hogged line
- * @lflags: bitmask of gpio_lookup_flags GPIO_* values
- * @dflags: GPIO flags used to specify the direction and value
- */
-struct gpiod_hog {
- struct list_head list;
- const char *chip_label;
- u16 chip_hwnum;
- const char *line_name;
- unsigned long lflags;
- int dflags;
-};
-
/*
* Helper for lookup tables with just one single lookup for a device.
*/
@@ -95,24 +78,10 @@ static struct gpiod_lookup_table _name = { \
.flags = _flags, \
}
-/*
- * Simple definition of a single GPIO hog in an array.
- */
-#define GPIO_HOG(_chip_label, _chip_hwnum, _line_name, _lflags, _dflags) \
-(struct gpiod_hog) { \
- .chip_label = _chip_label, \
- .chip_hwnum = _chip_hwnum, \
- .line_name = _line_name, \
- .lflags = _lflags, \
- .dflags = _dflags, \
-}
-
#ifdef CONFIG_GPIOLIB
void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n);
void gpiod_remove_lookup_table(struct gpiod_lookup_table *table);
-void gpiod_add_hogs(struct gpiod_hog *hogs);
-void gpiod_remove_hogs(struct gpiod_hog *hogs);
#else /* ! CONFIG_GPIOLIB */
static inline
void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {}
@@ -120,8 +89,6 @@ static inline
void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}
static inline
void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {}
-static inline void gpiod_add_hogs(struct gpiod_hog *hogs) {}
-static inline void gpiod_remove_hogs(struct gpiod_hog *hogs) {}
#endif /* CONFIG_GPIOLIB */
#endif /* __LINUX_GPIO_MACHINE_H */
--
2.47.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 6/6] gpio: sim: allow to define the active-low setting of a simulated hog
2026-03-09 12:42 [PATCH v2 0/6] gpiolib: unify gpio-hog code Bartosz Golaszewski
` (4 preceding siblings ...)
2026-03-09 12:42 ` [PATCH v2 5/6] gpio: remove machine hogs Bartosz Golaszewski
@ 2026-03-09 12:42 ` Bartosz Golaszewski
2026-03-16 9:11 ` [PATCH v2 0/6] gpiolib: unify gpio-hog code Bartosz Golaszewski
6 siblings, 0 replies; 12+ messages in thread
From: Bartosz Golaszewski @ 2026-03-09 12:42 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Geert Uytterhoeven,
Frank Rowand, Mika Westerberg, Andy Shevchenko, Aaro Koskinen,
Janusz Krzysztofik, Tony Lindgren, Russell King, Jonathan Corbet,
Shuah Khan
Cc: linux-gpio, linux-kernel, linux-acpi, linux-arm-kernel,
linux-omap, linux-doc, brgl, Bartosz Golaszewski
Add a new configfs attribute to the hog group allowing to configure the
active-low lookup flag for hogged lines. This will allow us to extend
tests to also cover the line config of hogs set up using software nodes.
Reviewed-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/gpio/gpio-sim.c | 40 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 51bcbdd91b4b027b7a340971a11cce5280ca1295..f32674230237eb08bbf8dd1337a79b5d0aa13259 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -654,6 +654,7 @@ struct gpio_sim_hog {
char *name;
int dir;
+ bool active_low;
};
static struct gpio_sim_hog *to_gpio_sim_hog(struct config_item *item)
@@ -836,7 +837,7 @@ static int gpio_sim_bank_add_hogs(struct gpio_sim_bank *bank)
hog = line->hog;
gpios[0] = line->offset;
- gpios[1] = 0;
+ gpios[1] = hog->active_low ? 1 : 0;
memset(properties, 0, sizeof(properties));
@@ -1315,9 +1316,46 @@ gpio_sim_hog_config_direction_store(struct config_item *item,
CONFIGFS_ATTR(gpio_sim_hog_config_, direction);
+static ssize_t gpio_sim_hog_config_active_low_show(struct config_item *item,
+ char *page)
+{
+ struct gpio_sim_hog *hog = to_gpio_sim_hog(item);
+ struct gpio_sim_device *dev = gpio_sim_hog_get_device(hog);
+
+ guard(mutex)(&dev->lock);
+
+ return sprintf(page, "%c\n", hog->active_low ? '1' : '0');
+}
+
+static ssize_t
+gpio_sim_hog_config_active_low_store(struct config_item *item,
+ const char *page, size_t count)
+{
+ struct gpio_sim_hog *hog = to_gpio_sim_hog(item);
+ struct gpio_sim_device *dev = gpio_sim_hog_get_device(hog);
+ bool active_low;
+ int ret;
+
+ guard(mutex)(&dev->lock);
+
+ if (gpio_sim_device_is_live(dev))
+ return -EBUSY;
+
+ ret = kstrtobool(page, &active_low);
+ if (ret)
+ return ret;
+
+ hog->active_low = active_low;
+
+ return count;
+}
+
+CONFIGFS_ATTR(gpio_sim_hog_config_, active_low);
+
static struct configfs_attribute *gpio_sim_hog_config_attrs[] = {
&gpio_sim_hog_config_attr_name,
&gpio_sim_hog_config_attr_direction,
+ &gpio_sim_hog_config_attr_active_low,
NULL
};
--
2.47.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 0/6] gpiolib: unify gpio-hog code
2026-03-09 12:42 [PATCH v2 0/6] gpiolib: unify gpio-hog code Bartosz Golaszewski
` (5 preceding siblings ...)
2026-03-09 12:42 ` [PATCH v2 6/6] gpio: sim: allow to define the active-low setting of a simulated hog Bartosz Golaszewski
@ 2026-03-16 9:11 ` Bartosz Golaszewski
6 siblings, 0 replies; 12+ messages in thread
From: Bartosz Golaszewski @ 2026-03-16 9:11 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Geert Uytterhoeven,
Frank Rowand, Mika Westerberg, Andy Shevchenko, Aaro Koskinen,
Janusz Krzysztofik, Tony Lindgren, Russell King, Jonathan Corbet,
Shuah Khan, Bartosz Golaszewski
Cc: linux-gpio, linux-kernel, linux-acpi, linux-arm-kernel,
linux-omap, linux-doc, stable, Mika Westerberg, Kevin Hilman
On Mon, 09 Mar 2026 13:42:36 +0100, Bartosz Golaszewski wrote:
> GPIO hogs are handled separately in three places: for OF, ACPI and
> machine lookup. In addition hogs cannot be set up using software nodes.
> A lot of that code is actually redundant and - except for some special
> handling of OF nodes - can be unified in one place.
>
> This series moves hogging into GPIO core and bases it on fwnode API
> (with a single helper from OF to translate devicetree properties into
> lookup flags), converts the two remaining users of machine hogs to using
> software node approach and removes machine hog support entirely. In
> addition, there's a patch extending the configurability of gpio-sim now
> that it uses software nodes for hogs.
>
> [...]
Applied, thanks!
[1/6] gpio: of: clear OF_POPULATED on hog nodes in remove path
https://git.kernel.org/brgl/c/bbee90e750262bfb406d66dc65c46d616d2b6673
[2/6] gpio: move hogs into GPIO core
https://git.kernel.org/brgl/c/d1d564ec4992945db853303dc2978256bce8c0b4
[3/6] gpio: sim: use fwnode-based GPIO hogs
https://git.kernel.org/brgl/c/5cfbd0eb784f19436b5d5a9a7e0dca862619739a
[4/6] ARM: omap1: ams-delta: convert GPIO hogs to using firmware nodes
https://git.kernel.org/brgl/c/e627fc9fad93d59765dd16adac1b2a9bf68d7523
[5/6] gpio: remove machine hogs
https://git.kernel.org/brgl/c/dea046e7f46f2357124a465e058c92cac3e351c5
[6/6] gpio: sim: allow to define the active-low setting of a simulated hog
https://git.kernel.org/brgl/c/696e9ba9a3da3d919d08a1abf05c9288311858f1
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 2/6] gpio: move hogs into GPIO core
2026-03-09 12:42 ` [PATCH v2 2/6] gpio: move hogs into GPIO core Bartosz Golaszewski
@ 2026-03-24 16:16 ` Geert Uytterhoeven
0 siblings, 0 replies; 12+ messages in thread
From: Geert Uytterhoeven @ 2026-03-24 16:16 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Bartosz Golaszewski, Frank Rowand, Mika Westerberg,
Andy Shevchenko, Aaro Koskinen, Janusz Krzysztofik, Tony Lindgren,
Russell King, Jonathan Corbet, Shuah Khan, linux-gpio,
linux-kernel, linux-acpi, linux-arm-kernel, linux-omap, linux-doc,
Mika Westerberg
Hi Bartosz,
On Mon, 9 Mar 2026 at 13:43, Bartosz Golaszewski
<bartosz.golaszewski@oss.qualcomm.com> wrote:
> Refactor line hogging code by moving the parts duplicated in
> gpiolib-acpi-core.c and gpiolib-of.c into gpiolib.c, leaving just the
> OF-specific bits in the latter.
>
> This makes fwnode the primary API for setting up hogs and allows to use
> software nodes in addition to ACPI and OF nodes.
>
> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> Reviewed-by: Linus Walleij <linusw@kernel.org>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Thanks for your patch, which is now commit d1d564ec4992945d ("gpio:
move hogs into GPIO core") in gpio/gpio/for-next.
This breaks GPIO on the Renesas Marzen (R-Car H1) board:
-gpio_rcar ffc40000.gpio: driving 32 GPIOs
+gpiochip_add_data_with_key: GPIOs 512..543 (ffc40000.gpio) failed
to register, -22
+gpio_rcar ffc40000.gpio: failed to add GPIO controller
+gpio_rcar ffc40000.gpio: probe with driver gpio_rcar failed with error -22
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -960,6 +960,98 @@ static void machine_gpiochip_add(struct gpio_chip *gc)
> }
> }
>
> +int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
> +{
> + struct fwnode_handle *gc_node = dev_fwnode(&gc->gpiodev->dev);
> + struct fwnode_reference_args gpiospec;
> + enum gpiod_flags dflags;
> + struct gpio_desc *desc;
> + unsigned long lflags;
> + const char *name;
> + int ret, argc;
> + u32 gpios[3]; /* We support up to three-cell bindings. */
> + u32 cells;
> +
> + lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
> + dflags = GPIOD_ASIS;
> + name = NULL;
> +
> + argc = fwnode_property_count_u32(fwnode, "gpios");
> + if (argc < 0)
> + return argc;
> + if (argc > 3)
> + return -EINVAL;
The GPIO hog at [1] has a gpios property with two entries:
gpios = <17 GPIO_ACTIVE_LOW>, <18 GPIO_ACTIVE_LOW>;
hence argc = 4, which is considered invalid.
The check should take into account the actual value of #gpio-cells,
and handle the presence of multiple GPIOs.
"git grep -Ww gpio-hog -- arch/*/boot/dts/ | grep 'gpios\s*=.*>,'" finds
several other places where multiple GPIOs are specified.
> +
> + ret = fwnode_property_read_u32_array(fwnode, "gpios", gpios, argc);
> + if (ret < 0)
> + return ret;
> +
> + if (is_of_node(fwnode)) {
> + /*
> + * OF-nodes need some additional special handling for
> + * translating of devicetree flags.
> + */
> + ret = fwnode_property_read_u32(gc_node, "#gpio-cells", &cells);
> + if (ret)
> + return ret;
> + if (!ret && argc != cells)
> + return -EINVAL;
> +
> + memset(&gpiospec, 0, sizeof(gpiospec));
> + gpiospec.fwnode = fwnode;
> + gpiospec.nargs = argc;
> +
> + for (int i = 0; i < argc; i++)
> + gpiospec.args[i] = gpios[i];
> +
> + ret = of_gpiochip_get_lflags(gc, &gpiospec, &lflags);
> + if (ret)
> + return ret;
> + } else {
> + /*
> + * GPIO_ACTIVE_LOW is currently the only lookup flag
> + * supported for non-OF firmware nodes.
> + */
> + if (gpios[1])
> + lflags |= GPIO_ACTIVE_LOW;
> + }
> +
> + if (fwnode_property_present(fwnode, "input"))
> + dflags |= GPIOD_IN;
> + else if (fwnode_property_present(fwnode, "output-low"))
> + dflags |= GPIOD_OUT_LOW;
> + else if (fwnode_property_present(fwnode, "output-high"))
> + dflags |= GPIOD_OUT_HIGH;
> + else
> + return -EINVAL;
> +
> + fwnode_property_read_string(fwnode, "line-name", &name);
> +
> + desc = gpiochip_get_desc(gc, gpios[0]);
> + if (IS_ERR(desc))
> + return PTR_ERR(desc);
> +
> + return gpiod_hog(desc, name, lflags, dflags);
> +}
[1] https://elixir.bootlin.com/linux/v6.19.9/source/arch/arm/boot/dts/renesas/r8a7779-marzen.dts#L196
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 5/6] gpio: remove machine hogs
2026-03-09 12:42 ` [PATCH v2 5/6] gpio: remove machine hogs Bartosz Golaszewski
@ 2026-05-20 0:46 ` Dmitry Torokhov
2026-05-20 5:27 ` Dmitry Torokhov
0 siblings, 1 reply; 12+ messages in thread
From: Dmitry Torokhov @ 2026-05-20 0:46 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Bartosz Golaszewski, Geert Uytterhoeven,
Frank Rowand, Mika Westerberg, Andy Shevchenko, Aaro Koskinen,
Janusz Krzysztofik, Tony Lindgren, Russell King, Jonathan Corbet,
Shuah Khan, linux-gpio, linux-kernel, linux-acpi,
linux-arm-kernel, linux-omap, linux-doc
On Mon, Mar 09, 2026 at 01:42:41PM +0100, Bartosz Golaszewski wrote:
> With no more users, remove legacy machine hog API from the kernel.
>
> Reviewed-by: Linus Walleij <linusw@kernel.org>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Argh! What is the replacement for this? I have patches for rsk7203 to
use them to get rid of legacy gpio use, like this:
diff --git a/arch/sh/boards/mach-rsk/devices-rsk7203.c b/arch/sh/boards/mach-rsk/devices-rsk7203.c
index f8760a91e2f1..5bbd3b31cffb 100644
--- a/arch/sh/boards/mach-rsk/devices-rsk7203.c
+++ b/arch/sh/boards/mach-rsk/devices-rsk7203.c
@@ -12,7 +12,7 @@
#include <linux/smsc911x.h>
#include <linux/input.h>
#include <linux/io.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
#include <linux/gpio/machine.h>
#include <linux/gpio/property.h>
#include <asm/machvec.h>
@@ -165,6 +165,19 @@ static const struct platform_device_info rsk7203_devices[] __initconst = {
},
};
+/* The base of the function GPIOs in the flat enum */
+#define SH7203_FN_BASE GPIO_FN_PINT7_PB
+
+static struct gpiod_hog rsk7203_gpio_hogs[] = {
+ GPIO_HOG("sh7203_pfc-fn", GPIO_FN_TXD0 - SH7203_FN_BASE,
+ "TXD0", GPIO_ACTIVE_HIGH, GPIOD_ASIS),
+ GPIO_HOG("sh7203_pfc-fn", GPIO_FN_RXD0 - SH7203_FN_BASE,
+ "RXD0", GPIO_ACTIVE_HIGH, GPIOD_ASIS),
+ GPIO_HOG("sh7203_pfc-fn", GPIO_FN_IRQ0_PB - SH7203_FN_BASE,
+ "IRQ0_PB", GPIO_ACTIVE_HIGH, GPIOD_ASIS),
+ { }
+};
+
static int __init rsk7203_devices_setup(void)
{
struct platform_device *pd;
@@ -172,12 +185,10 @@ static int __init rsk7203_devices_setup(void)
int i;
/* Select pins for SCIF0 */
- gpio_request(GPIO_FN_TXD0, NULL);
- gpio_request(GPIO_FN_RXD0, NULL);
+ gpiod_add_hogs(rsk7203_gpio_hogs);
/* Setup LAN9118: CS1 in 16-bit Big Endian Mode, IRQ0 at Port B */
__raw_writel(0x36db0400, 0xfffc0008); /* CS1BCR */
- gpio_request(GPIO_FN_IRQ0_PB, NULL);
error = software_node_register_node_group(rsk7203_swnodes);
if (error) {
If there is no replacement maybe we can resurrect this? Or shoudl we
have add swnode support for hogs?
Thanks.
--
Dmitry
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 5/6] gpio: remove machine hogs
2026-05-20 0:46 ` Dmitry Torokhov
@ 2026-05-20 5:27 ` Dmitry Torokhov
2026-05-20 6:55 ` Bartosz Golaszewski
0 siblings, 1 reply; 12+ messages in thread
From: Dmitry Torokhov @ 2026-05-20 5:27 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Bartosz Golaszewski, Geert Uytterhoeven,
Frank Rowand, Mika Westerberg, Andy Shevchenko, Aaro Koskinen,
Janusz Krzysztofik, Tony Lindgren, Russell King, Jonathan Corbet,
Shuah Khan, linux-gpio, linux-kernel, linux-acpi,
linux-arm-kernel, linux-omap, linux-doc
On Tue, May 19, 2026 at 05:46:50PM -0700, Dmitry Torokhov wrote:
> On Mon, Mar 09, 2026 at 01:42:41PM +0100, Bartosz Golaszewski wrote:
> > With no more users, remove legacy machine hog API from the kernel.
> >
> > Reviewed-by: Linus Walleij <linusw@kernel.org>
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
>
> Argh! What is the replacement for this? I have patches for rsk7203 to
> use them to get rid of legacy gpio use, like this:
>
> diff --git a/arch/sh/boards/mach-rsk/devices-rsk7203.c b/arch/sh/boards/mach-rsk/devices-rsk7203.c
> index f8760a91e2f1..5bbd3b31cffb 100644
> --- a/arch/sh/boards/mach-rsk/devices-rsk7203.c
> +++ b/arch/sh/boards/mach-rsk/devices-rsk7203.c
> @@ -12,7 +12,7 @@
> #include <linux/smsc911x.h>
> #include <linux/input.h>
> #include <linux/io.h>
> -#include <linux/gpio.h>
> +#include <linux/gpio/consumer.h>
> #include <linux/gpio/machine.h>
> #include <linux/gpio/property.h>
> #include <asm/machvec.h>
> @@ -165,6 +165,19 @@ static const struct platform_device_info rsk7203_devices[] __initconst = {
> },
> };
>
> +/* The base of the function GPIOs in the flat enum */
> +#define SH7203_FN_BASE GPIO_FN_PINT7_PB
> +
> +static struct gpiod_hog rsk7203_gpio_hogs[] = {
> + GPIO_HOG("sh7203_pfc-fn", GPIO_FN_TXD0 - SH7203_FN_BASE,
> + "TXD0", GPIO_ACTIVE_HIGH, GPIOD_ASIS),
> + GPIO_HOG("sh7203_pfc-fn", GPIO_FN_RXD0 - SH7203_FN_BASE,
> + "RXD0", GPIO_ACTIVE_HIGH, GPIOD_ASIS),
> + GPIO_HOG("sh7203_pfc-fn", GPIO_FN_IRQ0_PB - SH7203_FN_BASE,
> + "IRQ0_PB", GPIO_ACTIVE_HIGH, GPIOD_ASIS),
> + { }
> +};
> +
> static int __init rsk7203_devices_setup(void)
> {
> struct platform_device *pd;
> @@ -172,12 +185,10 @@ static int __init rsk7203_devices_setup(void)
> int i;
>
> /* Select pins for SCIF0 */
> - gpio_request(GPIO_FN_TXD0, NULL);
> - gpio_request(GPIO_FN_RXD0, NULL);
> + gpiod_add_hogs(rsk7203_gpio_hogs);
>
> /* Setup LAN9118: CS1 in 16-bit Big Endian Mode, IRQ0 at Port B */
> __raw_writel(0x36db0400, 0xfffc0008); /* CS1BCR */
> - gpio_request(GPIO_FN_IRQ0_PB, NULL);
>
> error = software_node_register_node_group(rsk7203_swnodes);
> if (error) {
>
>
> If there is no replacement maybe we can resurrect this? Or shoudl we
> have add swnode support for hogs?
Hmm, I guess it is already there so I should simply switch. Sorry about
the noise.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 5/6] gpio: remove machine hogs
2026-05-20 5:27 ` Dmitry Torokhov
@ 2026-05-20 6:55 ` Bartosz Golaszewski
0 siblings, 0 replies; 12+ messages in thread
From: Bartosz Golaszewski @ 2026-05-20 6:55 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Bartosz Golaszewski, Linus Walleij, Geert Uytterhoeven,
Frank Rowand, Mika Westerberg, Andy Shevchenko, Aaro Koskinen,
Janusz Krzysztofik, Tony Lindgren, Russell King, Jonathan Corbet,
Shuah Khan, linux-gpio, linux-kernel, linux-acpi,
linux-arm-kernel, linux-omap, linux-doc
On Wed, May 20, 2026 at 7:27 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> >
> > If there is no replacement maybe we can resurrect this? Or shoudl we
> > have add swnode support for hogs?
>
> Hmm, I guess it is already there so I should simply switch. Sorry about
> the noise.
>
Earlier in this series you have examples of using software node based
hogging, I hope you can use it?
Bart
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-05-20 6:55 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-09 12:42 [PATCH v2 0/6] gpiolib: unify gpio-hog code Bartosz Golaszewski
2026-03-09 12:42 ` [PATCH v2 1/6] gpio: of: clear OF_POPULATED on hog nodes in remove path Bartosz Golaszewski
2026-03-09 12:42 ` [PATCH v2 2/6] gpio: move hogs into GPIO core Bartosz Golaszewski
2026-03-24 16:16 ` Geert Uytterhoeven
2026-03-09 12:42 ` [PATCH v2 3/6] gpio: sim: use fwnode-based GPIO hogs Bartosz Golaszewski
2026-03-09 12:42 ` [PATCH v2 4/6] ARM: omap1: ams-delta: convert GPIO hogs to using firmware nodes Bartosz Golaszewski
2026-03-09 12:42 ` [PATCH v2 5/6] gpio: remove machine hogs Bartosz Golaszewski
2026-05-20 0:46 ` Dmitry Torokhov
2026-05-20 5:27 ` Dmitry Torokhov
2026-05-20 6:55 ` Bartosz Golaszewski
2026-03-09 12:42 ` [PATCH v2 6/6] gpio: sim: allow to define the active-low setting of a simulated hog Bartosz Golaszewski
2026-03-16 9:11 ` [PATCH v2 0/6] gpiolib: unify gpio-hog code Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox