linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] gpio: of: Add DT overlay support for GPIO hogs
@ 2020-02-20 13:01 Geert Uytterhoeven
  2020-02-20 13:01 ` [PATCH v2 1/2] gpio: of: Extract of_gpiochip_add_hog() Geert Uytterhoeven
  2020-02-20 13:01 ` [PATCH v2 2/2] gpio: of: Add DT overlay support for GPIO hogs Geert Uytterhoeven
  0 siblings, 2 replies; 11+ messages in thread
From: Geert Uytterhoeven @ 2020-02-20 13:01 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Pantelis Antoniou,
	Frank Rowand, Rob Herring, Mark Rutland
  Cc: Peter Ujfalusi, Chris Brandt, linux-gpio, devicetree,
	linux-renesas-soc, linux-kernel, Geert Uytterhoeven

	Hi all,

As GPIO hogs are configured at GPIO controller initialization time,
adding/removing GPIO hogs in Device Tree overlays currently does not
work.  Hence this patch series adds support for that, by registering an
of_reconfig notifier, as is already done for platform, i2c, and SPI
devices.

Changes compared to v1[1]:
  - Drop RFC state,
  - Document that modifying existing gpio-hog nodes is not supported.

After I posted v1, Frank created a unittest[2] to demonstrate the
problem, and to verify to my series fixes it (thanks a lot!).

Thanks!

[1] "[PATCH/RFC 0/2] gpio: of: Add DT overlay support for GPIO hogs"
    https://lore.kernel.org/r/20191230133852.5890-1-geert+renesas@glider.be/
[2] "[RFC PATCH 0/2] of: unittest: add overlay gpio test to catch gpio hog
     problem"
    https://lore.kernel.org/r/1579070828-18221-1-git-send-email-frowand.list@gmail.com/

Geert Uytterhoeven (2):
  gpio: of: Extract of_gpiochip_add_hog()
  gpio: of: Add DT overlay support for GPIO hogs

 drivers/gpio/gpiolib-of.c | 139 +++++++++++++++++++++++++++++++++-----
 drivers/gpio/gpiolib-of.h |   2 +
 drivers/gpio/gpiolib.c    |  14 +++-
 drivers/gpio/gpiolib.h    |   3 +
 4 files changed, 139 insertions(+), 19 deletions(-)

-- 
2.17.1

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] 11+ messages in thread

* [PATCH v2 1/2] gpio: of: Extract of_gpiochip_add_hog()
  2020-02-20 13:01 [PATCH v2 0/2] gpio: of: Add DT overlay support for GPIO hogs Geert Uytterhoeven
@ 2020-02-20 13:01 ` Geert Uytterhoeven
  2020-02-20 18:50   ` Frank Rowand
  2020-02-21 16:08   ` Linus Walleij
  2020-02-20 13:01 ` [PATCH v2 2/2] gpio: of: Add DT overlay support for GPIO hogs Geert Uytterhoeven
  1 sibling, 2 replies; 11+ messages in thread
From: Geert Uytterhoeven @ 2020-02-20 13:01 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Pantelis Antoniou,
	Frank Rowand, Rob Herring, Mark Rutland
  Cc: Peter Ujfalusi, Chris Brandt, linux-gpio, devicetree,
	linux-renesas-soc, linux-kernel, Geert Uytterhoeven

Extract the code to add all GPIO hogs of a gpio-hog node into its own
function, so it can be reused.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/gpio/gpiolib-of.c | 49 ++++++++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 16 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index c6d30f73df078e0b..2b47f93886075294 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -604,6 +604,35 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
 	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 error if it fails otherwise 0 on success.
+ */
+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;
+	}
+
+	return 0;
+}
+
 /**
  * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions
  * @chip:	gpio chip to act on
@@ -614,29 +643,17 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
  */
 static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
 {
-	struct gpio_desc *desc = NULL;
 	struct device_node *np;
-	const char *name;
-	unsigned long lflags;
-	enum gpiod_flags dflags;
-	unsigned int i;
 	int ret;
 
 	for_each_available_child_of_node(chip->of_node, np) {
 		if (!of_property_read_bool(np, "gpio-hog"))
 			continue;
 
-		for (i = 0;; i++) {
-			desc = of_parse_own_gpio(np, chip, i, &name, &lflags,
-						 &dflags);
-			if (IS_ERR(desc))
-				break;
-
-			ret = gpiod_hog(desc, name, lflags, dflags);
-			if (ret < 0) {
-				of_node_put(np);
-				return ret;
-			}
+		ret = of_gpiochip_add_hog(chip, np);
+		if (ret < 0) {
+			of_node_put(np);
+			return ret;
 		}
 	}
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/2] gpio: of: Add DT overlay support for GPIO hogs
  2020-02-20 13:01 [PATCH v2 0/2] gpio: of: Add DT overlay support for GPIO hogs Geert Uytterhoeven
  2020-02-20 13:01 ` [PATCH v2 1/2] gpio: of: Extract of_gpiochip_add_hog() Geert Uytterhoeven
@ 2020-02-20 13:01 ` Geert Uytterhoeven
  2020-02-20 18:51   ` Frank Rowand
  2020-02-21 16:10   ` Linus Walleij
  1 sibling, 2 replies; 11+ messages in thread
From: Geert Uytterhoeven @ 2020-02-20 13:01 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Pantelis Antoniou,
	Frank Rowand, Rob Herring, Mark Rutland
  Cc: Peter Ujfalusi, Chris Brandt, linux-gpio, devicetree,
	linux-renesas-soc, linux-kernel, Geert Uytterhoeven

As GPIO hogs are configured at GPIO controller initialization time,
adding/removing GPIO hogs in DT overlays does not work.

Add support for GPIO hogs described in DT overlays by registering an OF
reconfiguration notifier, to handle the addition and removal of GPIO hog
subnodes to/from a GPIO controller device node.

Note that when a GPIO hog device node is being removed, its "gpios"
properties is no longer available, so we have to keep track of which
node a hog belongs to, which is done by adding a pointer to the hog's
device node to struct gpio_desc.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - Drop RFC state,
  - Document that modifying existing gpio-hog nodes is not supported.
---
 drivers/gpio/gpiolib-of.c | 90 +++++++++++++++++++++++++++++++++++++++
 drivers/gpio/gpiolib-of.h |  2 +
 drivers/gpio/gpiolib.c    | 14 ++++--
 drivers/gpio/gpiolib.h    |  3 ++
 4 files changed, 106 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 2b47f93886075294..ccc449df3792ae97 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -628,6 +628,10 @@ static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog)
 		ret = gpiod_hog(desc, name, lflags, dflags);
 		if (ret < 0)
 			return ret;
+
+#ifdef CONFIG_OF_DYNAMIC
+		desc->hog = hog;
+#endif
 	}
 
 	return 0;
@@ -655,11 +659,97 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
 			of_node_put(np);
 			return ret;
 		}
+
+		of_node_set_flag(np, OF_POPULATED);
 	}
 
 	return 0;
 }
 
+#ifdef CONFIG_OF_DYNAMIC
+/**
+ * of_gpiochip_remove_hog - Remove all hogs in a hog device node
+ * @chip:	gpio chip to act on
+ * @hog:	device node describing the hogs
+ */
+static void of_gpiochip_remove_hog(struct gpio_chip *chip,
+				   struct device_node *hog)
+{
+	struct gpio_desc *descs = chip->gpiodev->descs;
+	unsigned int i;
+
+	for (i = 0; i < chip->ngpio; i++) {
+		if (test_bit(FLAG_IS_HOGGED, &descs[i].flags) &&
+		    descs[i].hog == hog)
+			gpiochip_free_own_desc(&descs[i]);
+	}
+}
+
+static int of_gpiochip_match_node(struct gpio_chip *chip, void *data)
+{
+	return chip->gpiodev->dev.of_node == data;
+}
+
+static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np)
+{
+	return gpiochip_find(np, of_gpiochip_match_node);
+}
+
+static int of_gpio_notify(struct notifier_block *nb, unsigned long action,
+			  void *arg)
+{
+	struct of_reconfig_data *rd = arg;
+	struct gpio_chip *chip;
+	int ret;
+
+	/*
+	 * This only supports adding and removing complete gpio-hog nodes.
+	 * Modifying an existing gpio-hog node is not supported (except for
+	 * changing its "status" property, which is treated the same as
+	 * addition/removal).
+	 */
+	switch (of_reconfig_get_state_change(action, arg)) {
+	case OF_RECONFIG_CHANGE_ADD:
+		if (!of_property_read_bool(rd->dn, "gpio-hog"))
+			return NOTIFY_OK;	/* not for us */
+
+		if (of_node_test_and_set_flag(rd->dn, OF_POPULATED))
+			return NOTIFY_OK;
+
+		chip = of_find_gpiochip_by_node(rd->dn->parent);
+		if (chip == NULL)
+			return NOTIFY_OK;	/* not for us */
+
+		ret = of_gpiochip_add_hog(chip, rd->dn);
+		if (ret < 0) {
+			pr_err("%s: failed to add hogs for %pOF\n", __func__,
+			       rd->dn);
+			of_node_clear_flag(rd->dn, OF_POPULATED);
+			return notifier_from_errno(ret);
+		}
+		break;
+
+	case OF_RECONFIG_CHANGE_REMOVE:
+		if (!of_node_check_flag(rd->dn, OF_POPULATED))
+			return NOTIFY_OK;	/* already depopulated */
+
+		chip = of_find_gpiochip_by_node(rd->dn->parent);
+		if (chip == NULL)
+			return NOTIFY_OK;	/* not for us */
+
+		of_gpiochip_remove_hog(chip, rd->dn);
+		of_node_clear_flag(rd->dn, OF_POPULATED);
+		break;
+	}
+
+	return NOTIFY_OK;
+}
+
+struct notifier_block gpio_of_notifier = {
+	.notifier_call = of_gpio_notify,
+};
+#endif /* CONFIG_OF_DYNAMIC */
+
 /**
  * of_gpio_simple_xlate - translate gpiospec to the GPIO number and flags
  * @gc:		pointer to the gpio_chip structure
diff --git a/drivers/gpio/gpiolib-of.h b/drivers/gpio/gpiolib-of.h
index 9768831b1fe2f25b..ed26664f153782fc 100644
--- a/drivers/gpio/gpiolib-of.h
+++ b/drivers/gpio/gpiolib-of.h
@@ -35,4 +35,6 @@ static inline bool of_gpio_need_valid_mask(const struct gpio_chip *gc)
 }
 #endif /* CONFIG_OF_GPIO */
 
+extern struct notifier_block gpio_of_notifier;
+
 #endif /* GPIOLIB_OF_H */
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 56de871060ea211e..6f312220fe80acaf 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2925,6 +2925,9 @@ static bool gpiod_free_commit(struct gpio_desc *desc)
 		clear_bit(FLAG_PULL_DOWN, &desc->flags);
 		clear_bit(FLAG_BIAS_DISABLE, &desc->flags);
 		clear_bit(FLAG_IS_HOGGED, &desc->flags);
+#ifdef CONFIG_OF_DYNAMIC
+		desc->hog = NULL;
+#endif
 		ret = true;
 	}
 
@@ -5126,10 +5129,15 @@ static int __init gpiolib_dev_init(void)
 	if (ret < 0) {
 		pr_err("gpiolib: failed to allocate char dev region\n");
 		bus_unregister(&gpio_bus_type);
-	} else {
-		gpiolib_initialized = true;
-		gpiochip_setup_devs();
+		return ret;
 	}
+
+	gpiolib_initialized = true;
+	gpiochip_setup_devs();
+
+	if (IS_ENABLED(CONFIG_OF_DYNAMIC))
+		WARN_ON(of_reconfig_notifier_register(&gpio_of_notifier));
+
 	return ret;
 }
 core_initcall(gpiolib_dev_init);
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 3e0aab2945d82974..18c75e83fd7679ec 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -119,6 +119,9 @@ struct gpio_desc {
 	const char		*label;
 	/* Name of the GPIO */
 	const char		*name;
+#ifdef CONFIG_OF_DYNAMIC
+	struct device_node	*hog;
+#endif
 };
 
 int gpiod_request(struct gpio_desc *desc, const char *label);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/2] gpio: of: Extract of_gpiochip_add_hog()
  2020-02-20 13:01 ` [PATCH v2 1/2] gpio: of: Extract of_gpiochip_add_hog() Geert Uytterhoeven
@ 2020-02-20 18:50   ` Frank Rowand
  2020-02-21 16:08   ` Linus Walleij
  1 sibling, 0 replies; 11+ messages in thread
From: Frank Rowand @ 2020-02-20 18:50 UTC (permalink / raw)
  To: Geert Uytterhoeven, Linus Walleij, Bartosz Golaszewski,
	Pantelis Antoniou, Rob Herring, Mark Rutland
  Cc: Peter Ujfalusi, Chris Brandt, linux-gpio, devicetree,
	linux-renesas-soc, linux-kernel

On 2/20/20 7:01 AM, Geert Uytterhoeven wrote:
> Extract the code to add all GPIO hogs of a gpio-hog node into its own
> function, so it can be reused.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> v2:
>   - No changes.
> ---
>  drivers/gpio/gpiolib-of.c | 49 ++++++++++++++++++++++++++-------------
>  1 file changed, 33 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index c6d30f73df078e0b..2b47f93886075294 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -604,6 +604,35 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
>  	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 error if it fails otherwise 0 on success.
> + */
> +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;
> +	}
> +
> +	return 0;
> +}
> +
>  /**
>   * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions
>   * @chip:	gpio chip to act on
> @@ -614,29 +643,17 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
>   */
>  static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
>  {
> -	struct gpio_desc *desc = NULL;
>  	struct device_node *np;
> -	const char *name;
> -	unsigned long lflags;
> -	enum gpiod_flags dflags;
> -	unsigned int i;
>  	int ret;
>  
>  	for_each_available_child_of_node(chip->of_node, np) {
>  		if (!of_property_read_bool(np, "gpio-hog"))
>  			continue;
>  
> -		for (i = 0;; i++) {
> -			desc = of_parse_own_gpio(np, chip, i, &name, &lflags,
> -						 &dflags);
> -			if (IS_ERR(desc))
> -				break;
> -
> -			ret = gpiod_hog(desc, name, lflags, dflags);
> -			if (ret < 0) {
> -				of_node_put(np);
> -				return ret;
> -			}
> +		ret = of_gpiochip_add_hog(chip, np);
> +		if (ret < 0) {
> +			of_node_put(np);
> +			return ret;
>  		}
>  	}
>  
> 

Reviewed-by: Frank Rowand <frank.rowand@sony.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/2] gpio: of: Add DT overlay support for GPIO hogs
  2020-02-20 13:01 ` [PATCH v2 2/2] gpio: of: Add DT overlay support for GPIO hogs Geert Uytterhoeven
@ 2020-02-20 18:51   ` Frank Rowand
  2020-02-21 16:10   ` Linus Walleij
  1 sibling, 0 replies; 11+ messages in thread
From: Frank Rowand @ 2020-02-20 18:51 UTC (permalink / raw)
  To: Geert Uytterhoeven, Linus Walleij, Bartosz Golaszewski,
	Pantelis Antoniou, Rob Herring, Mark Rutland
  Cc: Peter Ujfalusi, Chris Brandt, linux-gpio, devicetree,
	linux-renesas-soc, linux-kernel, Frank Rowand

On 2/20/20 7:01 AM, Geert Uytterhoeven wrote:
> As GPIO hogs are configured at GPIO controller initialization time,
> adding/removing GPIO hogs in DT overlays does not work.
> 
> Add support for GPIO hogs described in DT overlays by registering an OF
> reconfiguration notifier, to handle the addition and removal of GPIO hog
> subnodes to/from a GPIO controller device node.
> 
> Note that when a GPIO hog device node is being removed, its "gpios"
> properties is no longer available, so we have to keep track of which
> node a hog belongs to, which is done by adding a pointer to the hog's
> device node to struct gpio_desc.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> v2:
>   - Drop RFC state,
>   - Document that modifying existing gpio-hog nodes is not supported.
> ---
>  drivers/gpio/gpiolib-of.c | 90 +++++++++++++++++++++++++++++++++++++++
>  drivers/gpio/gpiolib-of.h |  2 +
>  drivers/gpio/gpiolib.c    | 14 ++++--
>  drivers/gpio/gpiolib.h    |  3 ++
>  4 files changed, 106 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index 2b47f93886075294..ccc449df3792ae97 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -628,6 +628,10 @@ static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog)
>  		ret = gpiod_hog(desc, name, lflags, dflags);
>  		if (ret < 0)
>  			return ret;
> +
> +#ifdef CONFIG_OF_DYNAMIC
> +		desc->hog = hog;
> +#endif
>  	}
>  
>  	return 0;
> @@ -655,11 +659,97 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
>  			of_node_put(np);
>  			return ret;
>  		}
> +
> +		of_node_set_flag(np, OF_POPULATED);
>  	}
>  
>  	return 0;
>  }
>  
> +#ifdef CONFIG_OF_DYNAMIC
> +/**
> + * of_gpiochip_remove_hog - Remove all hogs in a hog device node
> + * @chip:	gpio chip to act on
> + * @hog:	device node describing the hogs
> + */
> +static void of_gpiochip_remove_hog(struct gpio_chip *chip,
> +				   struct device_node *hog)
> +{
> +	struct gpio_desc *descs = chip->gpiodev->descs;
> +	unsigned int i;
> +
> +	for (i = 0; i < chip->ngpio; i++) {
> +		if (test_bit(FLAG_IS_HOGGED, &descs[i].flags) &&
> +		    descs[i].hog == hog)
> +			gpiochip_free_own_desc(&descs[i]);
> +	}
> +}
> +
> +static int of_gpiochip_match_node(struct gpio_chip *chip, void *data)
> +{
> +	return chip->gpiodev->dev.of_node == data;
> +}
> +
> +static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np)
> +{
> +	return gpiochip_find(np, of_gpiochip_match_node);
> +}
> +
> +static int of_gpio_notify(struct notifier_block *nb, unsigned long action,
> +			  void *arg)
> +{
> +	struct of_reconfig_data *rd = arg;
> +	struct gpio_chip *chip;
> +	int ret;
> +
> +	/*
> +	 * This only supports adding and removing complete gpio-hog nodes.
> +	 * Modifying an existing gpio-hog node is not supported (except for
> +	 * changing its "status" property, which is treated the same as
> +	 * addition/removal).
> +	 */
> +	switch (of_reconfig_get_state_change(action, arg)) {
> +	case OF_RECONFIG_CHANGE_ADD:
> +		if (!of_property_read_bool(rd->dn, "gpio-hog"))
> +			return NOTIFY_OK;	/* not for us */
> +
> +		if (of_node_test_and_set_flag(rd->dn, OF_POPULATED))
> +			return NOTIFY_OK;
> +
> +		chip = of_find_gpiochip_by_node(rd->dn->parent);
> +		if (chip == NULL)
> +			return NOTIFY_OK;	/* not for us */
> +
> +		ret = of_gpiochip_add_hog(chip, rd->dn);
> +		if (ret < 0) {
> +			pr_err("%s: failed to add hogs for %pOF\n", __func__,
> +			       rd->dn);
> +			of_node_clear_flag(rd->dn, OF_POPULATED);
> +			return notifier_from_errno(ret);
> +		}
> +		break;
> +
> +	case OF_RECONFIG_CHANGE_REMOVE:
> +		if (!of_node_check_flag(rd->dn, OF_POPULATED))
> +			return NOTIFY_OK;	/* already depopulated */
> +
> +		chip = of_find_gpiochip_by_node(rd->dn->parent);
> +		if (chip == NULL)
> +			return NOTIFY_OK;	/* not for us */
> +
> +		of_gpiochip_remove_hog(chip, rd->dn);
> +		of_node_clear_flag(rd->dn, OF_POPULATED);
> +		break;
> +	}
> +
> +	return NOTIFY_OK;
> +}
> +
> +struct notifier_block gpio_of_notifier = {
> +	.notifier_call = of_gpio_notify,
> +};
> +#endif /* CONFIG_OF_DYNAMIC */
> +
>  /**
>   * of_gpio_simple_xlate - translate gpiospec to the GPIO number and flags
>   * @gc:		pointer to the gpio_chip structure
> diff --git a/drivers/gpio/gpiolib-of.h b/drivers/gpio/gpiolib-of.h
> index 9768831b1fe2f25b..ed26664f153782fc 100644
> --- a/drivers/gpio/gpiolib-of.h
> +++ b/drivers/gpio/gpiolib-of.h
> @@ -35,4 +35,6 @@ static inline bool of_gpio_need_valid_mask(const struct gpio_chip *gc)
>  }
>  #endif /* CONFIG_OF_GPIO */
>  
> +extern struct notifier_block gpio_of_notifier;
> +
>  #endif /* GPIOLIB_OF_H */
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 56de871060ea211e..6f312220fe80acaf 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -2925,6 +2925,9 @@ static bool gpiod_free_commit(struct gpio_desc *desc)
>  		clear_bit(FLAG_PULL_DOWN, &desc->flags);
>  		clear_bit(FLAG_BIAS_DISABLE, &desc->flags);
>  		clear_bit(FLAG_IS_HOGGED, &desc->flags);
> +#ifdef CONFIG_OF_DYNAMIC
> +		desc->hog = NULL;
> +#endif
>  		ret = true;
>  	}
>  
> @@ -5126,10 +5129,15 @@ static int __init gpiolib_dev_init(void)
>  	if (ret < 0) {
>  		pr_err("gpiolib: failed to allocate char dev region\n");
>  		bus_unregister(&gpio_bus_type);
> -	} else {
> -		gpiolib_initialized = true;
> -		gpiochip_setup_devs();
> +		return ret;
>  	}
> +
> +	gpiolib_initialized = true;
> +	gpiochip_setup_devs();
> +
> +	if (IS_ENABLED(CONFIG_OF_DYNAMIC))
> +		WARN_ON(of_reconfig_notifier_register(&gpio_of_notifier));
> +
>  	return ret;
>  }
>  core_initcall(gpiolib_dev_init);
> diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
> index 3e0aab2945d82974..18c75e83fd7679ec 100644
> --- a/drivers/gpio/gpiolib.h
> +++ b/drivers/gpio/gpiolib.h
> @@ -119,6 +119,9 @@ struct gpio_desc {
>  	const char		*label;
>  	/* Name of the GPIO */
>  	const char		*name;
> +#ifdef CONFIG_OF_DYNAMIC
> +	struct device_node	*hog;
> +#endif
>  };
>  
>  int gpiod_request(struct gpio_desc *desc, const char *label);
> 

Reviewed-by: Frank Rowand <frank.rowand@sony.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/2] gpio: of: Extract of_gpiochip_add_hog()
  2020-02-20 13:01 ` [PATCH v2 1/2] gpio: of: Extract of_gpiochip_add_hog() Geert Uytterhoeven
  2020-02-20 18:50   ` Frank Rowand
@ 2020-02-21 16:08   ` Linus Walleij
  2020-02-21 17:18     ` Frank Rowand
  1 sibling, 1 reply; 11+ messages in thread
From: Linus Walleij @ 2020-02-21 16:08 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Bartosz Golaszewski, Pantelis Antoniou, Frank Rowand,
	Rob Herring, Mark Rutland, Peter Ujfalusi, Chris Brandt,
	open list:GPIO SUBSYSTEM,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Linux-Renesas, linux-kernel

On Thu, Feb 20, 2020 at 2:01 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:

> Extract the code to add all GPIO hogs of a gpio-hog node into its own
> function, so it can be reused.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> v2:
>   - No changes.

Patch applied with Frank's Review tag.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/2] gpio: of: Add DT overlay support for GPIO hogs
  2020-02-20 13:01 ` [PATCH v2 2/2] gpio: of: Add DT overlay support for GPIO hogs Geert Uytterhoeven
  2020-02-20 18:51   ` Frank Rowand
@ 2020-02-21 16:10   ` Linus Walleij
  1 sibling, 0 replies; 11+ messages in thread
From: Linus Walleij @ 2020-02-21 16:10 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Bartosz Golaszewski, Pantelis Antoniou, Frank Rowand,
	Rob Herring, Mark Rutland, Peter Ujfalusi, Chris Brandt,
	open list:GPIO SUBSYSTEM,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Linux-Renesas, linux-kernel

On Thu, Feb 20, 2020 at 2:01 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:

> As GPIO hogs are configured at GPIO controller initialization time,
> adding/removing GPIO hogs in DT overlays does not work.
>
> Add support for GPIO hogs described in DT overlays by registering an OF
> reconfiguration notifier, to handle the addition and removal of GPIO hog
> subnodes to/from a GPIO controller device node.
>
> Note that when a GPIO hog device node is being removed, its "gpios"
> properties is no longer available, so we have to keep track of which
> node a hog belongs to, which is done by adding a pointer to the hog's
> device node to struct gpio_desc.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> v2:
>   - Drop RFC state,
>   - Document that modifying existing gpio-hog nodes is not supported.

Clean and well separated code, patch applied
with Frank's review tag!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/2] gpio: of: Extract of_gpiochip_add_hog()
  2020-02-21 16:08   ` Linus Walleij
@ 2020-02-21 17:18     ` Frank Rowand
  2020-02-21 17:20       ` Frank Rowand
  2020-02-28 22:43       ` Linus Walleij
  0 siblings, 2 replies; 11+ messages in thread
From: Frank Rowand @ 2020-02-21 17:18 UTC (permalink / raw)
  To: Linus Walleij, Geert Uytterhoeven, Rob Herring
  Cc: Bartosz Golaszewski, Pantelis Antoniou, Mark Rutland,
	Peter Ujfalusi, Chris Brandt, open list:GPIO SUBSYSTEM,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Linux-Renesas, linux-kernel

Hi Linus, Rob,

On 2/21/20 10:08 AM, Linus Walleij wrote:
> On Thu, Feb 20, 2020 at 2:01 PM Geert Uytterhoeven
> <geert+renesas@glider.be> wrote:
> 
>> Extract the code to add all GPIO hogs of a gpio-hog node into its own
>> function, so it can be reused.
>>
>> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
>> ---
>> v2:
>>   - No changes.
> 
> Patch applied with Frank's Review tag.

I created a devicetree unittest to show the problem that Geert's patches
fix.

I would prefer to have my unittest patch series applied somewhere,
immediately followed by Geert's patch series.  This way, after
applying my series, a test fail is reported, then after Geert's
series is applied, the test fail becomes a test pass.

Can you coordinate with Rob to accept both series either via
your tree or Rob's tree?

-Frank

> 
> Yours,
> Linus Walleij
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/2] gpio: of: Extract of_gpiochip_add_hog()
  2020-02-21 17:18     ` Frank Rowand
@ 2020-02-21 17:20       ` Frank Rowand
  2020-02-28 22:43       ` Linus Walleij
  1 sibling, 0 replies; 11+ messages in thread
From: Frank Rowand @ 2020-02-21 17:20 UTC (permalink / raw)
  To: Linus Walleij, Geert Uytterhoeven, Rob Herring
  Cc: Bartosz Golaszewski, Pantelis Antoniou, Mark Rutland,
	Peter Ujfalusi, Chris Brandt, open list:GPIO SUBSYSTEM,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Linux-Renesas, linux-kernel

On 2/21/20 11:18 AM, Frank Rowand wrote:
> Hi Linus, Rob,
> 
> On 2/21/20 10:08 AM, Linus Walleij wrote:
>> On Thu, Feb 20, 2020 at 2:01 PM Geert Uytterhoeven
>> <geert+renesas@glider.be> wrote:
>>
>>> Extract the code to add all GPIO hogs of a gpio-hog node into its own
>>> function, so it can be reused.
>>>
>>> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
>>> ---
>>> v2:
>>>   - No changes.
>>
>> Patch applied with Frank's Review tag.
> 
> I created a devicetree unittest to show the problem that Geert's patches
> fix.

I left out the link to my patch series:

   https://lore.kernel.org/linux-devicetree/1582224021-12827-1-git-send-email-frowand.list@gmail.com/

   [PATCH v2 0/2] of: unittest: add overlay gpio test to catch gpio hog problem

-Frank

> 
> I would prefer to have my unittest patch series applied somewhere,
> immediately followed by Geert's patch series.  This way, after
> applying my series, a test fail is reported, then after Geert's
> series is applied, the test fail becomes a test pass.
> 
> Can you coordinate with Rob to accept both series either via
> your tree or Rob's tree?
> 
> -Frank
> 
>>
>> Yours,
>> Linus Walleij
>>
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/2] gpio: of: Extract of_gpiochip_add_hog()
  2020-02-21 17:18     ` Frank Rowand
  2020-02-21 17:20       ` Frank Rowand
@ 2020-02-28 22:43       ` Linus Walleij
  2020-03-02 19:57         ` Frank Rowand
  1 sibling, 1 reply; 11+ messages in thread
From: Linus Walleij @ 2020-02-28 22:43 UTC (permalink / raw)
  To: Frank Rowand
  Cc: Geert Uytterhoeven, Rob Herring, Bartosz Golaszewski,
	Pantelis Antoniou, Mark Rutland, Peter Ujfalusi, Chris Brandt,
	open list:GPIO SUBSYSTEM,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Linux-Renesas, linux-kernel

On Fri, Feb 21, 2020 at 6:18 PM Frank Rowand <frowand.list@gmail.com> wrote:
> On 2/21/20 10:08 AM, Linus Walleij wrote:

> > Patch applied with Frank's Review tag.
>
> I created a devicetree unittest to show the problem that Geert's patches
> fix.
>
> I would prefer to have my unittest patch series applied somewhere,
> immediately followed by Geert's patch series.  This way, after
> applying my series, a test fail is reported, then after Geert's
> series is applied, the test fail becomes a test pass.
>
> Can you coordinate with Rob to accept both series either via
> your tree or Rob's tree?

I see Rob already applied the test.

I do not personally bother much about which order problems
get solved but I guess if Rob can back out the patch I can apply
it to my tree instead, before these patches. for some time,
before I start pulling stuff on top.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/2] gpio: of: Extract of_gpiochip_add_hog()
  2020-02-28 22:43       ` Linus Walleij
@ 2020-03-02 19:57         ` Frank Rowand
  0 siblings, 0 replies; 11+ messages in thread
From: Frank Rowand @ 2020-03-02 19:57 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Geert Uytterhoeven, Rob Herring, Bartosz Golaszewski,
	Pantelis Antoniou, Mark Rutland, Peter Ujfalusi, Chris Brandt,
	open list:GPIO SUBSYSTEM,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Linux-Renesas, linux-kernel

On 2/28/20 4:43 PM, Linus Walleij wrote:
> On Fri, Feb 21, 2020 at 6:18 PM Frank Rowand <frowand.list@gmail.com> wrote:
>> On 2/21/20 10:08 AM, Linus Walleij wrote:
> 
>>> Patch applied with Frank's Review tag.
>>
>> I created a devicetree unittest to show the problem that Geert's patches
>> fix.
>>
>> I would prefer to have my unittest patch series applied somewhere,
>> immediately followed by Geert's patch series.  This way, after
>> applying my series, a test fail is reported, then after Geert's
>> series is applied, the test fail becomes a test pass.
>>
>> Can you coordinate with Rob to accept both series either via
>> your tree or Rob's tree?
> 
> I see Rob already applied the test.
> 
> I do not personally bother much about which order problems
> get solved but I guess if Rob can back out the patch I can apply
> it to my tree instead, before these patches. for some time,
> before I start pulling stuff on top.
> 
> Yours,
> Linus Walleij
> 

At this point, if it is a lot of trouble or confusion, I would not
bother undoing the commits that have been done.  I'll leave it up
to you and Rob to coordinate if you do decide to undo.

-Frank

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-03-02 19:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-20 13:01 [PATCH v2 0/2] gpio: of: Add DT overlay support for GPIO hogs Geert Uytterhoeven
2020-02-20 13:01 ` [PATCH v2 1/2] gpio: of: Extract of_gpiochip_add_hog() Geert Uytterhoeven
2020-02-20 18:50   ` Frank Rowand
2020-02-21 16:08   ` Linus Walleij
2020-02-21 17:18     ` Frank Rowand
2020-02-21 17:20       ` Frank Rowand
2020-02-28 22:43       ` Linus Walleij
2020-03-02 19:57         ` Frank Rowand
2020-02-20 13:01 ` [PATCH v2 2/2] gpio: of: Add DT overlay support for GPIO hogs Geert Uytterhoeven
2020-02-20 18:51   ` Frank Rowand
2020-02-21 16:10   ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).