linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion
@ 2022-04-14 19:02 ` Andy Shevchenko
  2022-04-14 19:02   ` [PATCH v5 1/6] gpiolib: Introduce a helper to get first GPIO controller node Andy Shevchenko
                     ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Andy Shevchenko @ 2022-04-14 19:02 UTC (permalink / raw)
  To: Andy Shevchenko, Neil Armstrong, linux-gpio, linux-arm-kernel,
	linux-amlogic, linux-kernel
  Cc: Linus Walleij, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Bartosz Golaszewski, Marek Szyprowski

This is a spin-off (*) of the previous work of switching GPIO library
to use fwnode instead of of_node. Here we introduce a couple of
a new macro helpers, which allows to switch some of the drivers
to use fwnode and partially fwnode APIs. As a result of this cleanup
a few drivers switched to use GPIO fwnode instead of of_node.

*) it's subset of it with a new (patch 1) helper.

Marek, Martin, can you give this a try?
This requires at least two patches for GPIO library to be applied.

Bart, Linus, I can take it thru my tree with an immutable branch if
it's the way you prefer, otherwise please suggest on how to proceed.

Changelog v5:
- dropped tested patches (this series based on them, though)
- introduced a new helper (thanks Marek and Martin for reporting an issue)
- redone Armada and Meson code using newly introduced helper

Changelog v4:
- fixed compilation of the Samsung pin control drivers (LKP)
- explained in the commit message why namespacing is good for meson defs
- added tag to one of meson patches (Neil)

Changelog v3:
- moved count initialization to the definition in patch 2 (Geert)
- replaced of_args by args, used %pfwP in patch 7 (Geert)
- fixed kernel doc warning in patch 7
- added tags to patches 1, 2, 6, and 7 (Geert)
- added tag to patch 4 (Fabien)
- renamed MREG to MESON_REG in patch 9 (Neil)
- added tag to patch 10 (Neil)
- used --base for cover-letter

Changelog v2:
- properly based, so kbuild bot may test it (LKP)
- fixed typo in the macro (Geert)
- split to two macro helpers and rename the gpiochip_count()
- tagged one of stm32 and one of meson patches (Fabien, Neil)
- unified previously standalone armada patch
- due to above rewrote the armada patch from v1 completely (Sergey)
- added a lot of a new patches
- compile tested all of them on x86

Andy Shevchenko (6):
  gpiolib: Introduce a helper to get first GPIO controller node
  pinctrl: armada-37xx: Switch to use fwnode instead of of_node
  pinctrl: armada-37xx: Reuse GPIO fwnode in
    armada_37xx_irqchip_register()
  pinctrl: meson: Rename REG_* to MESON_REG_*
  pinctrl: meson: Enable COMPILE_TEST
  pinctrl: meson: Replace custom code by gpiochip_node_count() call

 drivers/pinctrl/meson/Kconfig               |  2 +-
 drivers/pinctrl/meson/pinctrl-meson.c       | 52 ++++++++++-----------
 drivers/pinctrl/meson/pinctrl-meson.h       | 28 +++++------
 drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 34 ++++----------
 include/linux/gpio/driver.h                 | 10 ++++
 5 files changed, 59 insertions(+), 67 deletions(-)

-- 
2.35.1


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

* [PATCH v5 1/6] gpiolib: Introduce a helper to get first GPIO controller node
  2022-04-14 19:02 ` [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion Andy Shevchenko
@ 2022-04-14 19:02   ` Andy Shevchenko
  2022-04-25 18:52     ` Bartosz Golaszewski
  2022-04-14 19:02   ` [PATCH v5 2/6] pinctrl: armada-37xx: Switch to use fwnode instead of of_node Andy Shevchenko
                     ` (6 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2022-04-14 19:02 UTC (permalink / raw)
  To: Andy Shevchenko, Neil Armstrong, linux-gpio, linux-arm-kernel,
	linux-amlogic, linux-kernel
  Cc: Linus Walleij, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Bartosz Golaszewski, Marek Szyprowski

Introduce a helper to get first GPIO controller node which drivers
may want to use.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/gpio/driver.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 12de0b22b4ef..83e2d72e51bb 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -766,4 +766,14 @@ static inline unsigned int gpiochip_node_count(struct device *dev)
 	return count;
 }
 
+static inline struct fwnode_handle *gpiochip_node_get_first(struct device *dev)
+{
+	struct fwnode_handle *fwnode;
+
+	for_each_gpiochip_node(dev, fwnode)
+		return fwnode;
+
+	return NULL;
+}
+
 #endif /* __LINUX_GPIO_DRIVER_H */
-- 
2.35.1


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

* [PATCH v5 2/6] pinctrl: armada-37xx: Switch to use fwnode instead of of_node
  2022-04-14 19:02 ` [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion Andy Shevchenko
  2022-04-14 19:02   ` [PATCH v5 1/6] gpiolib: Introduce a helper to get first GPIO controller node Andy Shevchenko
@ 2022-04-14 19:02   ` Andy Shevchenko
  2022-04-14 19:02   ` [PATCH v5 3/6] pinctrl: armada-37xx: Reuse GPIO fwnode in armada_37xx_irqchip_register() Andy Shevchenko
                     ` (5 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2022-04-14 19:02 UTC (permalink / raw)
  To: Andy Shevchenko, Neil Armstrong, linux-gpio, linux-arm-kernel,
	linux-amlogic, linux-kernel
  Cc: Linus Walleij, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Bartosz Golaszewski, Marek Szyprowski

GPIO library now accepts fwnode as a firmware node,
so switch the driver to use it.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
index 08cad14042e2..110f70bce3fe 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
@@ -21,6 +21,7 @@
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinmux.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 #include <linux/string_helpers.h>
@@ -787,18 +788,13 @@ static int armada_37xx_gpiochip_register(struct platform_device *pdev,
 					struct armada_37xx_pinctrl *info)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *np;
+	struct fwnode_handle *fwnode;
 	struct gpio_chip *gc;
-	int ret = -ENODEV;
+	int ret;
 
-	for_each_child_of_node(dev->of_node, np) {
-		if (of_find_property(np, "gpio-controller", NULL)) {
-			ret = 0;
-			break;
-		}
-	}
-	if (ret)
-		return ret;
+	fwnode = gpiochip_node_get_first(dev);
+	if (!fwnode)
+		return -ENODEV;
 
 	info->gpio_chip = armada_37xx_gpiolib_chip;
 
@@ -806,7 +802,7 @@ static int armada_37xx_gpiochip_register(struct platform_device *pdev,
 	gc->ngpio = info->data->nr_pins;
 	gc->parent = dev;
 	gc->base = -1;
-	gc->of_node = np;
+	gc->fwnode = fwnode;
 	gc->label = info->data->name;
 
 	ret = armada_37xx_irqchip_register(pdev, info);
-- 
2.35.1


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

* [PATCH v5 3/6] pinctrl: armada-37xx: Reuse GPIO fwnode in armada_37xx_irqchip_register()
  2022-04-14 19:02 ` [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion Andy Shevchenko
  2022-04-14 19:02   ` [PATCH v5 1/6] gpiolib: Introduce a helper to get first GPIO controller node Andy Shevchenko
  2022-04-14 19:02   ` [PATCH v5 2/6] pinctrl: armada-37xx: Switch to use fwnode instead of of_node Andy Shevchenko
@ 2022-04-14 19:02   ` Andy Shevchenko
  2022-04-14 19:02   ` [PATCH v5 4/6] pinctrl: meson: Rename REG_* to MESON_REG_* Andy Shevchenko
                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2022-04-14 19:02 UTC (permalink / raw)
  To: Andy Shevchenko, Neil Armstrong, linux-gpio, linux-arm-kernel,
	linux-amlogic, linux-kernel
  Cc: Linus Walleij, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Bartosz Golaszewski, Marek Szyprowski

Since we have fwnode of the first found GPIO controller assigned to the
struct gpio_chip, we may reuse it in the armada_37xx_irqchip_register().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
index 110f70bce3fe..ef4118e49f16 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
@@ -727,23 +727,13 @@ static int armada_37xx_irqchip_register(struct platform_device *pdev,
 	struct gpio_chip *gc = &info->gpio_chip;
 	struct irq_chip *irqchip = &info->irq_chip;
 	struct gpio_irq_chip *girq = &gc->irq;
+	struct device_node *np = to_of_node(gc->fwnode);
 	struct device *dev = &pdev->dev;
-	struct device_node *np;
-	int ret = -ENODEV, i, nr_irq_parent;
-
-	/* Check if we have at least one gpio-controller child node */
-	for_each_child_of_node(dev->of_node, np) {
-		if (of_property_read_bool(np, "gpio-controller")) {
-			ret = 0;
-			break;
-		}
-	}
-	if (ret)
-		return dev_err_probe(dev, ret, "no gpio-controller child node\n");
+	unsigned int i, nr_irq_parent;
 
-	nr_irq_parent = of_irq_count(np);
 	spin_lock_init(&info->irq_lock);
 
+	nr_irq_parent = of_irq_count(np);
 	if (!nr_irq_parent) {
 		dev_err(dev, "invalid or no IRQ\n");
 		return 0;
-- 
2.35.1


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

* [PATCH v5 4/6] pinctrl: meson: Rename REG_* to MESON_REG_*
  2022-04-14 19:02 ` [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion Andy Shevchenko
                     ` (2 preceding siblings ...)
  2022-04-14 19:02   ` [PATCH v5 3/6] pinctrl: armada-37xx: Reuse GPIO fwnode in armada_37xx_irqchip_register() Andy Shevchenko
@ 2022-04-14 19:02   ` Andy Shevchenko
  2022-04-14 19:02   ` [PATCH v5 5/6] pinctrl: meson: Enable COMPILE_TEST Andy Shevchenko
                     ` (3 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2022-04-14 19:02 UTC (permalink / raw)
  To: Andy Shevchenko, Neil Armstrong, linux-gpio, linux-arm-kernel,
	linux-amlogic, linux-kernel
  Cc: Linus Walleij, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Bartosz Golaszewski, Marek Szyprowski

Currently compilation test fails on x86 due to name collision. The usual
way to fix that is to move both conflicting parts to their own namespaces.

Rename REG_* to MESON_REG_* as a prerequisite for enabling COMPILE_TEST.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
---
 drivers/pinctrl/meson/pinctrl-meson.c | 24 +++++++++++------------
 drivers/pinctrl/meson/pinctrl-meson.h | 28 +++++++++++++--------------
 2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/pinctrl/meson/pinctrl-meson.c b/drivers/pinctrl/meson/pinctrl-meson.c
index 49851444a6e3..5b46a0979db7 100644
--- a/drivers/pinctrl/meson/pinctrl-meson.c
+++ b/drivers/pinctrl/meson/pinctrl-meson.c
@@ -218,13 +218,13 @@ static int meson_pinconf_set_output(struct meson_pinctrl *pc,
 				    unsigned int pin,
 				    bool out)
 {
-	return meson_pinconf_set_gpio_bit(pc, pin, REG_DIR, !out);
+	return meson_pinconf_set_gpio_bit(pc, pin, MESON_REG_DIR, !out);
 }
 
 static int meson_pinconf_get_output(struct meson_pinctrl *pc,
 				    unsigned int pin)
 {
-	int ret = meson_pinconf_get_gpio_bit(pc, pin, REG_DIR);
+	int ret = meson_pinconf_get_gpio_bit(pc, pin, MESON_REG_DIR);
 
 	if (ret < 0)
 		return ret;
@@ -236,13 +236,13 @@ static int meson_pinconf_set_drive(struct meson_pinctrl *pc,
 				   unsigned int pin,
 				   bool high)
 {
-	return meson_pinconf_set_gpio_bit(pc, pin, REG_OUT, high);
+	return meson_pinconf_set_gpio_bit(pc, pin, MESON_REG_OUT, high);
 }
 
 static int meson_pinconf_get_drive(struct meson_pinctrl *pc,
 				   unsigned int pin)
 {
-	return meson_pinconf_get_gpio_bit(pc, pin, REG_OUT);
+	return meson_pinconf_get_gpio_bit(pc, pin, MESON_REG_OUT);
 }
 
 static int meson_pinconf_set_output_drive(struct meson_pinctrl *pc,
@@ -269,7 +269,7 @@ static int meson_pinconf_disable_bias(struct meson_pinctrl *pc,
 	if (ret)
 		return ret;
 
-	meson_calc_reg_and_bit(bank, pin, REG_PULLEN, &reg, &bit);
+	meson_calc_reg_and_bit(bank, pin, MESON_REG_PULLEN, &reg, &bit);
 	ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), 0);
 	if (ret)
 		return ret;
@@ -288,7 +288,7 @@ static int meson_pinconf_enable_bias(struct meson_pinctrl *pc, unsigned int pin,
 	if (ret)
 		return ret;
 
-	meson_calc_reg_and_bit(bank, pin, REG_PULL, &reg, &bit);
+	meson_calc_reg_and_bit(bank, pin, MESON_REG_PULL, &reg, &bit);
 	if (pull_up)
 		val = BIT(bit);
 
@@ -296,7 +296,7 @@ static int meson_pinconf_enable_bias(struct meson_pinctrl *pc, unsigned int pin,
 	if (ret)
 		return ret;
 
-	meson_calc_reg_and_bit(bank, pin, REG_PULLEN, &reg, &bit);
+	meson_calc_reg_and_bit(bank, pin, MESON_REG_PULLEN, &reg, &bit);
 	ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit),	BIT(bit));
 	if (ret)
 		return ret;
@@ -321,7 +321,7 @@ static int meson_pinconf_set_drive_strength(struct meson_pinctrl *pc,
 	if (ret)
 		return ret;
 
-	meson_calc_reg_and_bit(bank, pin, REG_DS, &reg, &bit);
+	meson_calc_reg_and_bit(bank, pin, MESON_REG_DS, &reg, &bit);
 
 	if (drive_strength_ua <= 500) {
 		ds_val = MESON_PINCONF_DRV_500UA;
@@ -407,7 +407,7 @@ static int meson_pinconf_get_pull(struct meson_pinctrl *pc, unsigned int pin)
 	if (ret)
 		return ret;
 
-	meson_calc_reg_and_bit(bank, pin, REG_PULLEN, &reg, &bit);
+	meson_calc_reg_and_bit(bank, pin, MESON_REG_PULLEN, &reg, &bit);
 
 	ret = regmap_read(pc->reg_pullen, reg, &val);
 	if (ret)
@@ -416,7 +416,7 @@ static int meson_pinconf_get_pull(struct meson_pinctrl *pc, unsigned int pin)
 	if (!(val & BIT(bit))) {
 		conf = PIN_CONFIG_BIAS_DISABLE;
 	} else {
-		meson_calc_reg_and_bit(bank, pin, REG_PULL, &reg, &bit);
+		meson_calc_reg_and_bit(bank, pin, MESON_REG_PULL, &reg, &bit);
 
 		ret = regmap_read(pc->reg_pull, reg, &val);
 		if (ret)
@@ -447,7 +447,7 @@ static int meson_pinconf_get_drive_strength(struct meson_pinctrl *pc,
 	if (ret)
 		return ret;
 
-	meson_calc_reg_and_bit(bank, pin, REG_DS, &reg, &bit);
+	meson_calc_reg_and_bit(bank, pin, MESON_REG_DS, &reg, &bit);
 
 	ret = regmap_read(pc->reg_ds, reg, &val);
 	if (ret)
@@ -595,7 +595,7 @@ static int meson_gpio_get(struct gpio_chip *chip, unsigned gpio)
 	if (ret)
 		return ret;
 
-	meson_calc_reg_and_bit(bank, gpio, REG_IN, &reg, &bit);
+	meson_calc_reg_and_bit(bank, gpio, MESON_REG_IN, &reg, &bit);
 	regmap_read(pc->reg_gpio, reg, &val);
 
 	return !!(val & BIT(bit));
diff --git a/drivers/pinctrl/meson/pinctrl-meson.h b/drivers/pinctrl/meson/pinctrl-meson.h
index ff5372e0a475..b197827027bd 100644
--- a/drivers/pinctrl/meson/pinctrl-meson.h
+++ b/drivers/pinctrl/meson/pinctrl-meson.h
@@ -63,13 +63,13 @@ struct meson_reg_desc {
  * enum meson_reg_type - type of registers encoded in @meson_reg_desc
  */
 enum meson_reg_type {
-	REG_PULLEN,
-	REG_PULL,
-	REG_DIR,
-	REG_OUT,
-	REG_IN,
-	REG_DS,
-	NUM_REG,
+	MESON_REG_PULLEN,
+	MESON_REG_PULL,
+	MESON_REG_DIR,
+	MESON_REG_OUT,
+	MESON_REG_IN,
+	MESON_REG_DS,
+	MESON_NUM_REG,
 };
 
 /**
@@ -102,7 +102,7 @@ struct meson_bank {
 	unsigned int last;
 	int irq_first;
 	int irq_last;
-	struct meson_reg_desc regs[NUM_REG];
+	struct meson_reg_desc regs[MESON_NUM_REG];
 };
 
 struct meson_pinctrl_data {
@@ -150,12 +150,12 @@ struct meson_pinctrl {
 		.irq_first	= fi,					\
 		.irq_last	= li,					\
 		.regs = {						\
-			[REG_PULLEN]	= { per, peb },			\
-			[REG_PULL]	= { pr, pb },			\
-			[REG_DIR]	= { dr, db },			\
-			[REG_OUT]	= { or, ob },			\
-			[REG_IN]	= { ir, ib },			\
-			[REG_DS]	= { dsr, dsb },			\
+			[MESON_REG_PULLEN]	= { per, peb },		\
+			[MESON_REG_PULL]	= { pr, pb },		\
+			[MESON_REG_DIR]		= { dr, db },		\
+			[MESON_REG_OUT]		= { or, ob },		\
+			[MESON_REG_IN]		= { ir, ib },		\
+			[MESON_REG_DS]		= { dsr, dsb },		\
 		},							\
 	 }
 
-- 
2.35.1


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

* [PATCH v5 5/6] pinctrl: meson: Enable COMPILE_TEST
  2022-04-14 19:02 ` [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion Andy Shevchenko
                     ` (3 preceding siblings ...)
  2022-04-14 19:02   ` [PATCH v5 4/6] pinctrl: meson: Rename REG_* to MESON_REG_* Andy Shevchenko
@ 2022-04-14 19:02   ` Andy Shevchenko
  2022-04-14 19:02   ` [PATCH v5 6/6] pinctrl: meson: Replace custom code by gpiochip_node_count() call Andy Shevchenko
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2022-04-14 19:02 UTC (permalink / raw)
  To: Andy Shevchenko, Neil Armstrong, linux-gpio, linux-arm-kernel,
	linux-amlogic, linux-kernel
  Cc: Linus Walleij, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Bartosz Golaszewski, Marek Szyprowski

Enable COMPILE_TEST for a better test coverage.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
---
 drivers/pinctrl/meson/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/meson/Kconfig b/drivers/pinctrl/meson/Kconfig
index d1955c65b4b6..64fb9e074ac6 100644
--- a/drivers/pinctrl/meson/Kconfig
+++ b/drivers/pinctrl/meson/Kconfig
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 menuconfig PINCTRL_MESON
 	tristate "Amlogic SoC pinctrl drivers"
-	depends on ARCH_MESON
+	depends on ARCH_MESON || COMPILE_TEST
 	depends on OF
 	default y
 	select PINMUX
-- 
2.35.1


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

* [PATCH v5 6/6] pinctrl: meson: Replace custom code by gpiochip_node_count() call
  2022-04-14 19:02 ` [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion Andy Shevchenko
                     ` (4 preceding siblings ...)
  2022-04-14 19:02   ` [PATCH v5 5/6] pinctrl: meson: Enable COMPILE_TEST Andy Shevchenko
@ 2022-04-14 19:02   ` Andy Shevchenko
  2022-04-14 20:28   ` [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion Marek Szyprowski
  2022-04-19 21:51   ` Linus Walleij
  7 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2022-04-14 19:02 UTC (permalink / raw)
  To: Andy Shevchenko, Neil Armstrong, linux-gpio, linux-arm-kernel,
	linux-amlogic, linux-kernel
  Cc: Linus Walleij, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Bartosz Golaszewski, Marek Szyprowski

Since we have generic function to count GPIO controller nodes
under a given device, there is no need to open code it. Replace
custom code by gpiochip_node_count() call.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
---
 drivers/pinctrl/meson/pinctrl-meson.c | 28 ++++++++++++---------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/pinctrl/meson/pinctrl-meson.c b/drivers/pinctrl/meson/pinctrl-meson.c
index 5b46a0979db7..cc2cd73ff8f9 100644
--- a/drivers/pinctrl/meson/pinctrl-meson.c
+++ b/drivers/pinctrl/meson/pinctrl-meson.c
@@ -49,6 +49,7 @@
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinmux.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/seq_file.h>
 
@@ -662,27 +663,22 @@ static struct regmap *meson_map_resource(struct meson_pinctrl *pc,
 	return devm_regmap_init_mmio(pc->dev, base, &meson_regmap_config);
 }
 
-static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc,
-				  struct device_node *node)
+static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc)
 {
-	struct device_node *np, *gpio_np = NULL;
+	struct device_node *gpio_np;
+	unsigned int chips;
 
-	for_each_child_of_node(node, np) {
-		if (!of_find_property(np, "gpio-controller", NULL))
-			continue;
-		if (gpio_np) {
-			dev_err(pc->dev, "multiple gpio nodes\n");
-			of_node_put(np);
-			return -EINVAL;
-		}
-		gpio_np = np;
-	}
-
-	if (!gpio_np) {
+	chips = gpiochip_node_count(pc->dev);
+	if (!chips) {
 		dev_err(pc->dev, "no gpio node found\n");
 		return -EINVAL;
 	}
+	if (chips > 1) {
+		dev_err(pc->dev, "multiple gpio nodes\n");
+		return -EINVAL;
+	}
 
+	gpio_np = to_of_node(gpiochip_node_get_first(pc->dev));
 	pc->of_node = gpio_np;
 
 	pc->reg_mux = meson_map_resource(pc, gpio_np, "mux");
@@ -751,7 +747,7 @@ int meson_pinctrl_probe(struct platform_device *pdev)
 	pc->dev = dev;
 	pc->data = (struct meson_pinctrl_data *) of_device_get_match_data(dev);
 
-	ret = meson_pinctrl_parse_dt(pc, dev->of_node);
+	ret = meson_pinctrl_parse_dt(pc);
 	if (ret)
 		return ret;
 
-- 
2.35.1


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

* Re: [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion
  2022-04-14 19:02 ` [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion Andy Shevchenko
                     ` (5 preceding siblings ...)
  2022-04-14 19:02   ` [PATCH v5 6/6] pinctrl: meson: Replace custom code by gpiochip_node_count() call Andy Shevchenko
@ 2022-04-14 20:28   ` Marek Szyprowski
  2022-04-19 21:51   ` Linus Walleij
  7 siblings, 0 replies; 13+ messages in thread
From: Marek Szyprowski @ 2022-04-14 20:28 UTC (permalink / raw)
  To: Andy Shevchenko, Neil Armstrong, linux-gpio, linux-arm-kernel,
	linux-amlogic, linux-kernel
  Cc: Linus Walleij, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Bartosz Golaszewski

Hi Andy,

On 14.04.2022 21:02, Andy Shevchenko wrote:
> This is a spin-off (*) of the previous work of switching GPIO library
> to use fwnode instead of of_node. Here we introduce a couple of
> a new macro helpers, which allows to switch some of the drivers
> to use fwnode and partially fwnode APIs. As a result of this cleanup
> a few drivers switched to use GPIO fwnode instead of of_node.
>
> *) it's subset of it with a new (patch 1) helper.
>
> Marek, Martin, can you give this a try?
> This requires at least two patches for GPIO library to be applied.

I've applied patch #1 and #6 on top of linux next-20220413 with commit 
88834c75cae5 ("pinctrl: meson: Replace custom code by 
gpiochip_node_count() call") reverted. All my Meson-based test boards 
(Odroid C4, N2, Khadas VIM3/3l) work fine now. Thanks! Feel free to add:

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

> Bart, Linus, I can take it thru my tree with an immutable branch if
> it's the way you prefer, otherwise please suggest on how to proceed.
>
> Changelog v5:
> - dropped tested patches (this series based on them, though)
> - introduced a new helper (thanks Marek and Martin for reporting an issue)
> - redone Armada and Meson code using newly introduced helper
>
> Changelog v4:
> - fixed compilation of the Samsung pin control drivers (LKP)
> - explained in the commit message why namespacing is good for meson defs
> - added tag to one of meson patches (Neil)
>
> Changelog v3:
> - moved count initialization to the definition in patch 2 (Geert)
> - replaced of_args by args, used %pfwP in patch 7 (Geert)
> - fixed kernel doc warning in patch 7
> - added tags to patches 1, 2, 6, and 7 (Geert)
> - added tag to patch 4 (Fabien)
> - renamed MREG to MESON_REG in patch 9 (Neil)
> - added tag to patch 10 (Neil)
> - used --base for cover-letter
>
> Changelog v2:
> - properly based, so kbuild bot may test it (LKP)
> - fixed typo in the macro (Geert)
> - split to two macro helpers and rename the gpiochip_count()
> - tagged one of stm32 and one of meson patches (Fabien, Neil)
> - unified previously standalone armada patch
> - due to above rewrote the armada patch from v1 completely (Sergey)
> - added a lot of a new patches
> - compile tested all of them on x86
>
> Andy Shevchenko (6):
>    gpiolib: Introduce a helper to get first GPIO controller node
>    pinctrl: armada-37xx: Switch to use fwnode instead of of_node
>    pinctrl: armada-37xx: Reuse GPIO fwnode in
>      armada_37xx_irqchip_register()
>    pinctrl: meson: Rename REG_* to MESON_REG_*
>    pinctrl: meson: Enable COMPILE_TEST
>    pinctrl: meson: Replace custom code by gpiochip_node_count() call
>
>   drivers/pinctrl/meson/Kconfig               |  2 +-
>   drivers/pinctrl/meson/pinctrl-meson.c       | 52 ++++++++++-----------
>   drivers/pinctrl/meson/pinctrl-meson.h       | 28 +++++------
>   drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 34 ++++----------
>   include/linux/gpio/driver.h                 | 10 ++++
>   5 files changed, 59 insertions(+), 67 deletions(-)
>
Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


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

* Re: [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion
  2022-04-14 19:02 ` [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion Andy Shevchenko
                     ` (6 preceding siblings ...)
  2022-04-14 20:28   ` [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion Marek Szyprowski
@ 2022-04-19 21:51   ` Linus Walleij
  7 siblings, 0 replies; 13+ messages in thread
From: Linus Walleij @ 2022-04-19 21:51 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Neil Armstrong, linux-gpio, linux-arm-kernel, linux-amlogic,
	linux-kernel, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Bartosz Golaszewski, Marek Szyprowski

On Thu, Apr 14, 2022 at 9:02 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> This is a spin-off (*) of the previous work of switching GPIO library
> to use fwnode instead of of_node. Here we introduce a couple of
> a new macro helpers, which allows to switch some of the drivers
> to use fwnode and partially fwnode APIs. As a result of this cleanup
> a few drivers switched to use GPIO fwnode instead of of_node.
>
> *) it's subset of it with a new (patch 1) helper.
>
> Marek, Martin, can you give this a try?
> This requires at least two patches for GPIO library to be applied.
>
> Bart, Linus, I can take it thru my tree with an immutable branch if
> it's the way you prefer, otherwise please suggest on how to proceed.

Hmmm that sounds best, patch 1 does not apply to the pinctrl
tree so I suppose there are already dependencies in the GPIO
tree?

FWIW, the series:
Acked-by: Linus Walleij <linus.walleij@linaro.org>

I'm of course a fan of this nice refactoring series.

Yours,
Linus Walleij

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

* Re: [PATCH v5 1/6] gpiolib: Introduce a helper to get first GPIO controller node
  2022-04-14 19:02   ` [PATCH v5 1/6] gpiolib: Introduce a helper to get first GPIO controller node Andy Shevchenko
@ 2022-04-25 18:52     ` Bartosz Golaszewski
  2022-04-26 10:29       ` Andy Shevchenko
  0 siblings, 1 reply; 13+ messages in thread
From: Bartosz Golaszewski @ 2022-04-25 18:52 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Neil Armstrong, open list:GPIO SUBSYSTEM, Linux ARM,
	linux-amlogic, Linux Kernel Mailing List, Linus Walleij,
	Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Andrew Lunn,
	Gregory Clement, Sebastian Hesselbarth, Marek Szyprowski

On Thu, Apr 14, 2022 at 9:02 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Introduce a helper to get first GPIO controller node which drivers
> may want to use.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  include/linux/gpio/driver.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
> index 12de0b22b4ef..83e2d72e51bb 100644
> --- a/include/linux/gpio/driver.h
> +++ b/include/linux/gpio/driver.h
> @@ -766,4 +766,14 @@ static inline unsigned int gpiochip_node_count(struct device *dev)
>         return count;
>  }
>
> +static inline struct fwnode_handle *gpiochip_node_get_first(struct device *dev)
> +{
> +       struct fwnode_handle *fwnode;
> +
> +       for_each_gpiochip_node(dev, fwnode)
> +               return fwnode;
> +
> +       return NULL;
> +}
> +
>  #endif /* __LINUX_GPIO_DRIVER_H */
> --
> 2.35.1
>

Any chance you could name it get_first_gpiochip_node()? It's static so
we don't have to worry about the prefix and it would make the purpose
more clear.

Bart

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

* Re: [PATCH v5 1/6] gpiolib: Introduce a helper to get first GPIO controller node
  2022-04-25 18:52     ` Bartosz Golaszewski
@ 2022-04-26 10:29       ` Andy Shevchenko
  2022-05-05 13:05         ` Bartosz Golaszewski
  0 siblings, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2022-04-26 10:29 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Andy Shevchenko, Neil Armstrong, open list:GPIO SUBSYSTEM,
	Linux ARM, linux-amlogic, Linux Kernel Mailing List,
	Linus Walleij, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Marek Szyprowski

On Tue, Apr 26, 2022 at 12:27 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> On Thu, Apr 14, 2022 at 9:02 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > Introduce a helper to get first GPIO controller node which drivers
> > may want to use.

> > +static inline struct fwnode_handle *gpiochip_node_get_first(struct device *dev)
> > +{
> > +       struct fwnode_handle *fwnode;
> > +
> > +       for_each_gpiochip_node(dev, fwnode)
> > +               return fwnode;
> > +
> > +       return NULL;
> > +}
> > +
> >  #endif /* __LINUX_GPIO_DRIVER_H */
> > --
> > 2.35.1
> >
>
> Any chance you could name it get_first_gpiochip_node()? It's static so
> we don't have to worry about the prefix and it would make the purpose
> more clear.

There are two things why I prefer it as is:
1) it's static inline, so it's part of (internal) but still exported API;
2) it's already in my for-next branch which I would like not to
rebase, until it's a really serious issue.

That said, if you still insist I can rename it.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v5 1/6] gpiolib: Introduce a helper to get first GPIO controller node
  2022-04-26 10:29       ` Andy Shevchenko
@ 2022-05-05 13:05         ` Bartosz Golaszewski
  2022-05-05 13:17           ` Andy Shevchenko
  0 siblings, 1 reply; 13+ messages in thread
From: Bartosz Golaszewski @ 2022-05-05 13:05 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Andy Shevchenko, Neil Armstrong, open list:GPIO SUBSYSTEM,
	Linux ARM, linux-amlogic, Linux Kernel Mailing List,
	Linus Walleij, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Marek Szyprowski

On Tue, Apr 26, 2022 at 12:29 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Tue, Apr 26, 2022 at 12:27 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> >
> > On Thu, Apr 14, 2022 at 9:02 PM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > Introduce a helper to get first GPIO controller node which drivers
> > > may want to use.
>
> > > +static inline struct fwnode_handle *gpiochip_node_get_first(struct device *dev)
> > > +{
> > > +       struct fwnode_handle *fwnode;
> > > +
> > > +       for_each_gpiochip_node(dev, fwnode)
> > > +               return fwnode;
> > > +
> > > +       return NULL;
> > > +}
> > > +
> > >  #endif /* __LINUX_GPIO_DRIVER_H */
> > > --
> > > 2.35.1
> > >
> >
> > Any chance you could name it get_first_gpiochip_node()? It's static so
> > we don't have to worry about the prefix and it would make the purpose
> > more clear.
>
> There are two things why I prefer it as is:
> 1) it's static inline, so it's part of (internal) but still exported API;
> 2) it's already in my for-next branch which I would like not to
> rebase, until it's a really serious issue.
>
> That said, if you still insist I can rename it.

No that's fine and I also pulled that into my tree.

Bart

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

* Re: [PATCH v5 1/6] gpiolib: Introduce a helper to get first GPIO controller node
  2022-05-05 13:05         ` Bartosz Golaszewski
@ 2022-05-05 13:17           ` Andy Shevchenko
  0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2022-05-05 13:17 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Neil Armstrong, open list:GPIO SUBSYSTEM, Linux ARM,
	linux-amlogic, Linux Kernel Mailing List, Linus Walleij,
	Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Andrew Lunn,
	Gregory Clement, Sebastian Hesselbarth, Marek Szyprowski

On Thu, May 05, 2022 at 03:05:52PM +0200, Bartosz Golaszewski wrote:
> On Tue, Apr 26, 2022 at 12:29 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Tue, Apr 26, 2022 at 12:27 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> > > On Thu, Apr 14, 2022 at 9:02 PM Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com> wrote:

...

> > > Any chance you could name it get_first_gpiochip_node()? It's static so
> > > we don't have to worry about the prefix and it would make the purpose
> > > more clear.
> >
> > There are two things why I prefer it as is:
> > 1) it's static inline, so it's part of (internal) but still exported API;
> > 2) it's already in my for-next branch which I would like not to
> > rebase, until it's a really serious issue.
> >
> > That said, if you still insist I can rename it.
> 
> No that's fine and I also pulled that into my tree.

Thank you!

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2022-05-05 13:17 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20220414190251eucas1p1ef520fa995057550fa533eb34a02ae63@eucas1p1.samsung.com>
2022-04-14 19:02 ` [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion Andy Shevchenko
2022-04-14 19:02   ` [PATCH v5 1/6] gpiolib: Introduce a helper to get first GPIO controller node Andy Shevchenko
2022-04-25 18:52     ` Bartosz Golaszewski
2022-04-26 10:29       ` Andy Shevchenko
2022-05-05 13:05         ` Bartosz Golaszewski
2022-05-05 13:17           ` Andy Shevchenko
2022-04-14 19:02   ` [PATCH v5 2/6] pinctrl: armada-37xx: Switch to use fwnode instead of of_node Andy Shevchenko
2022-04-14 19:02   ` [PATCH v5 3/6] pinctrl: armada-37xx: Reuse GPIO fwnode in armada_37xx_irqchip_register() Andy Shevchenko
2022-04-14 19:02   ` [PATCH v5 4/6] pinctrl: meson: Rename REG_* to MESON_REG_* Andy Shevchenko
2022-04-14 19:02   ` [PATCH v5 5/6] pinctrl: meson: Enable COMPILE_TEST Andy Shevchenko
2022-04-14 19:02   ` [PATCH v5 6/6] pinctrl: meson: Replace custom code by gpiochip_node_count() call Andy Shevchenko
2022-04-14 20:28   ` [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion Marek Szyprowski
2022-04-19 21:51   ` 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).