linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/5] gpio, pinctrl, introduce for_each_requested_gpio() helper
@ 2020-06-15 15:05 Andy Shevchenko
  2020-06-15 15:05 ` [PATCH v1 1/5] gpiolib: Introduce for_each_requested_gpio_in_range() macro Andy Shevchenko
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-06-15 15:05 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, linux-gpio; +Cc: Andy Shevchenko

While cleaning up Intel pin control drivers I have noticed that one helper
macro can be used widely in GPIO and pin control subsystems. Here we are.

Intel stuff is deliberately excluded, so, this can be applied to the GPIO
subsystem into immutable branch that will be propagated to pin control
subsystem and TWIMC parties, such as Intel pin control drivers.

Andy Shevchenko (5):
  gpiolib: Introduce for_each_requested_gpio_in_range() macro
  ARM/orion/gpio: Make use of for_each_requested_gpio()
  gpio: mvebu: Make use of for_each_requested_gpio()
  gpio: xra1403: Make use of for_each_requested_gpio()
  pinctrl: at91: Make use of for_each_requested_gpio()

 arch/arm/plat-orion/gpio.c     |  8 ++------
 drivers/gpio/gpio-mvebu.c      |  8 ++------
 drivers/gpio/gpio-xra1403.c    |  8 ++------
 drivers/pinctrl/pinctrl-at91.c |  7 ++-----
 include/linux/gpio/driver.h    | 16 ++++++++++++++++
 5 files changed, 24 insertions(+), 23 deletions(-)

-- 
2.27.0.rc2


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

* [PATCH v1 1/5] gpiolib: Introduce for_each_requested_gpio_in_range() macro
  2020-06-15 15:05 [PATCH v1 0/5] gpio, pinctrl, introduce for_each_requested_gpio() helper Andy Shevchenko
@ 2020-06-15 15:05 ` Andy Shevchenko
  2020-06-15 15:05 ` [PATCH v1 2/5] ARM/orion/gpio: Make use of for_each_requested_gpio() Andy Shevchenko
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-06-15 15:05 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, linux-gpio; +Cc: Andy Shevchenko

Introduce for_each_requested_gpio_in_range() macro which helps
to iterate over requested GPIO in a range. There are already
potential users of it, which are going to be converted
by the following patches.

For most of them for_each_requested_gpio() shortcut has been added.

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

diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 4d949e82fd19..b0402f884999 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -474,6 +474,22 @@ struct gpio_chip {
 extern const char *gpiochip_is_requested(struct gpio_chip *gc,
 			unsigned int offset);
 
+/**
+ * for_each_requested_gpio_in_range - iterates over requested GPIOs in a given range
+ * @chip:	the chip to query
+ * @i:		loop variable
+ * @base:	first GPIO in the range
+ * @size:	amount of GPIOs to check starting from @base
+ * @label:	label of current GPIO
+ */
+#define for_each_requested_gpio_in_range(chip, i, base, size, label)			\
+	for (i = 0; i < size; i++)							\
+		if ((label = gpiochip_is_requested(chip, base + i)) == NULL) {} else
+
+/* Iterates over all requested GPIO of the given @chip */
+#define for_each_requested_gpio(chip, i, label)						\
+	for_each_requested_gpio_in_range(chip, i, 0, chip->ngpio, label)
+
 /* add/remove chips */
 extern int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 				      struct lock_class_key *lock_key,
-- 
2.27.0.rc2


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

* [PATCH v1 2/5] ARM/orion/gpio: Make use of for_each_requested_gpio()
  2020-06-15 15:05 [PATCH v1 0/5] gpio, pinctrl, introduce for_each_requested_gpio() helper Andy Shevchenko
  2020-06-15 15:05 ` [PATCH v1 1/5] gpiolib: Introduce for_each_requested_gpio_in_range() macro Andy Shevchenko
@ 2020-06-15 15:05 ` Andy Shevchenko
  2020-06-16 20:43   ` Andrew Lunn
  2020-07-18 20:52   ` Gregory CLEMENT
  2020-06-15 15:05 ` [PATCH v1 3/5] gpio: mvebu: " Andy Shevchenko
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-06-15 15:05 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, linux-gpio
  Cc: Andy Shevchenko, Jason Cooper, Andrew Lunn,
	Sebastian Hesselbarth, Gregory Clement

Make use of for_each_requested_gpio() instead of home grown analogue.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jason Cooper <jason@lakedaemon.net>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: Gregory Clement <gregory.clement@bootlin.com>
---
 arch/arm/plat-orion/gpio.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/arm/plat-orion/gpio.c b/arch/arm/plat-orion/gpio.c
index 26a531ebb6e9..734f0be4f14a 100644
--- a/arch/arm/plat-orion/gpio.c
+++ b/arch/arm/plat-orion/gpio.c
@@ -442,6 +442,7 @@ static void orion_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 
 	struct orion_gpio_chip *ochip = gpiochip_get_data(chip);
 	u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk;
+	const char *label;
 	int i;
 
 	out	= readl_relaxed(GPIO_OUT(ochip));
@@ -453,15 +454,10 @@ static void orion_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 	edg_msk	= readl_relaxed(GPIO_EDGE_MASK(ochip));
 	lvl_msk	= readl_relaxed(GPIO_LEVEL_MASK(ochip));
 
-	for (i = 0; i < chip->ngpio; i++) {
-		const char *label;
+	for_each_requested_gpio(chip, i, label) {
 		u32 msk;
 		bool is_out;
 
-		label = gpiochip_is_requested(chip, i);
-		if (!label)
-			continue;
-
 		msk = 1 << i;
 		is_out = !(io_conf & msk);
 
-- 
2.27.0.rc2


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

* [PATCH v1 3/5] gpio: mvebu: Make use of for_each_requested_gpio()
  2020-06-15 15:05 [PATCH v1 0/5] gpio, pinctrl, introduce for_each_requested_gpio() helper Andy Shevchenko
  2020-06-15 15:05 ` [PATCH v1 1/5] gpiolib: Introduce for_each_requested_gpio_in_range() macro Andy Shevchenko
  2020-06-15 15:05 ` [PATCH v1 2/5] ARM/orion/gpio: Make use of for_each_requested_gpio() Andy Shevchenko
@ 2020-06-15 15:05 ` Andy Shevchenko
  2020-06-15 15:05 ` [PATCH v1 4/5] gpio: xra1403: " Andy Shevchenko
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-06-15 15:05 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, linux-gpio
  Cc: Andy Shevchenko, Thierry Reding, Uwe Kleine-König, Lee Jones

Make use of for_each_requested_gpio() instead of home grown analogue.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Lee Jones <lee.jones@linaro.org>
---
 drivers/gpio/gpio-mvebu.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index bd65114eb170..433e2c3f3fd5 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -846,6 +846,7 @@ static void mvebu_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 {
 	struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip);
 	u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk;
+	const char *label;
 	int i;
 
 	regmap_read(mvchip->regs, GPIO_OUT_OFF + mvchip->offset, &out);
@@ -857,15 +858,10 @@ static void mvebu_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 	edg_msk	= mvebu_gpio_read_edge_mask(mvchip);
 	lvl_msk	= mvebu_gpio_read_level_mask(mvchip);
 
-	for (i = 0; i < chip->ngpio; i++) {
-		const char *label;
+	for_each_requested_gpio(chip, i, label) {
 		u32 msk;
 		bool is_out;
 
-		label = gpiochip_is_requested(chip, i);
-		if (!label)
-			continue;
-
 		msk = BIT(i);
 		is_out = !(io_conf & msk);
 
-- 
2.27.0.rc2


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

* [PATCH v1 4/5] gpio: xra1403: Make use of for_each_requested_gpio()
  2020-06-15 15:05 [PATCH v1 0/5] gpio, pinctrl, introduce for_each_requested_gpio() helper Andy Shevchenko
                   ` (2 preceding siblings ...)
  2020-06-15 15:05 ` [PATCH v1 3/5] gpio: mvebu: " Andy Shevchenko
@ 2020-06-15 15:05 ` Andy Shevchenko
  2020-06-15 15:05 ` [PATCH v1 5/5] pinctrl: at91: " Andy Shevchenko
  2020-06-20 21:16 ` [PATCH v1 0/5] gpio, pinctrl, introduce for_each_requested_gpio() helper Linus Walleij
  5 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-06-15 15:05 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, linux-gpio
  Cc: Andy Shevchenko, Nandor Han, Semi Malinen

Make use of for_each_requested_gpio() instead of home grown analogue.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Nandor Han <nandor.han@ge.com>
Cc: Semi Malinen <semi.malinen@ge.com>
---
 drivers/gpio/gpio-xra1403.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpio-xra1403.c b/drivers/gpio/gpio-xra1403.c
index 31b5072b2df0..e2cac12092af 100644
--- a/drivers/gpio/gpio-xra1403.c
+++ b/drivers/gpio/gpio-xra1403.c
@@ -121,6 +121,7 @@ static void xra1403_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 	struct xra1403 *xra = gpiochip_get_data(chip);
 	int value[XRA_LAST];
 	int i;
+	const char *label;
 	unsigned int gcr;
 	unsigned int gsr;
 
@@ -136,12 +137,7 @@ static void xra1403_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 
 	gcr = value[XRA_GCR + 1] << 8 | value[XRA_GCR];
 	gsr = value[XRA_GSR + 1] << 8 | value[XRA_GSR];
-	for (i = 0; i < chip->ngpio; i++) {
-		const char *label = gpiochip_is_requested(chip, i);
-
-		if (!label)
-			continue;
-
+	for_each_requested_gpio(chip, i, label) {
 		seq_printf(s, " gpio-%-3d (%-12s) %s %s\n",
 			   chip->base + i, label,
 			   (gcr & BIT(i)) ? "in" : "out",
-- 
2.27.0.rc2


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

* [PATCH v1 5/5] pinctrl: at91: Make use of for_each_requested_gpio()
  2020-06-15 15:05 [PATCH v1 0/5] gpio, pinctrl, introduce for_each_requested_gpio() helper Andy Shevchenko
                   ` (3 preceding siblings ...)
  2020-06-15 15:05 ` [PATCH v1 4/5] gpio: xra1403: " Andy Shevchenko
@ 2020-06-15 15:05 ` Andy Shevchenko
  2020-06-20 21:16 ` [PATCH v1 0/5] gpio, pinctrl, introduce for_each_requested_gpio() helper Linus Walleij
  5 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-06-15 15:05 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, linux-gpio
  Cc: Andy Shevchenko, Ludovic Desroches, Nicolas Ferre, Alexandre Belloni

Make use of for_each_requested_gpio() instead of home grown analogue.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Ludovic Desroches <ludovic.desroches@microchip.com>
Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/pinctrl/pinctrl-at91.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index 52386ad29f28..9c5213087659 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -1486,14 +1486,11 @@ static void at91_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 	int i;
 	struct at91_gpio_chip *at91_gpio = gpiochip_get_data(chip);
 	void __iomem *pio = at91_gpio->regbase;
+	const char *gpio_label;
 
-	for (i = 0; i < chip->ngpio; i++) {
+	for_each_requested_gpio(chip, i, gpio_label) {
 		unsigned mask = pin_to_mask(i);
-		const char *gpio_label;
 
-		gpio_label = gpiochip_is_requested(chip, i);
-		if (!gpio_label)
-			continue;
 		mode = at91_gpio->ops->get_periph(pio, mask);
 		seq_printf(s, "[%s] GPIO%s%d: ",
 			   gpio_label, chip->label, i);
-- 
2.27.0.rc2


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

* Re: [PATCH v1 2/5] ARM/orion/gpio: Make use of for_each_requested_gpio()
  2020-06-15 15:05 ` [PATCH v1 2/5] ARM/orion/gpio: Make use of for_each_requested_gpio() Andy Shevchenko
@ 2020-06-16 20:43   ` Andrew Lunn
  2020-07-18 20:52   ` Gregory CLEMENT
  1 sibling, 0 replies; 10+ messages in thread
From: Andrew Lunn @ 2020-06-16 20:43 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, Jason Cooper,
	Sebastian Hesselbarth, Gregory Clement

On Mon, Jun 15, 2020 at 06:05:42PM +0300, Andy Shevchenko wrote:
> Make use of for_each_requested_gpio() instead of home grown analogue.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [PATCH v1 0/5] gpio, pinctrl, introduce for_each_requested_gpio() helper
  2020-06-15 15:05 [PATCH v1 0/5] gpio, pinctrl, introduce for_each_requested_gpio() helper Andy Shevchenko
                   ` (4 preceding siblings ...)
  2020-06-15 15:05 ` [PATCH v1 5/5] pinctrl: at91: " Andy Shevchenko
@ 2020-06-20 21:16 ` Linus Walleij
  5 siblings, 0 replies; 10+ messages in thread
From: Linus Walleij @ 2020-06-20 21:16 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Bartosz Golaszewski, open list:GPIO SUBSYSTEM

On Mon, Jun 15, 2020 at 5:05 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> While cleaning up Intel pin control drivers I have noticed that one helper
> macro can be used widely in GPIO and pin control subsystems. Here we are.
>
> Intel stuff is deliberately excluded, so, this can be applied to the GPIO
> subsystem into immutable branch that will be propagated to pin control
> subsystem and TWIMC parties, such as Intel pin control drivers.

Oh, nice! There it is :)

I applied this to the branch ib-for-each-requested in the GPIO tree and
merged into the GPIO devel branch, then I also pulled that into the
pinctrl "devel" branch.

Yours,
Linus Walleij

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

* Re: [PATCH v1 2/5] ARM/orion/gpio: Make use of for_each_requested_gpio()
  2020-06-15 15:05 ` [PATCH v1 2/5] ARM/orion/gpio: Make use of for_each_requested_gpio() Andy Shevchenko
  2020-06-16 20:43   ` Andrew Lunn
@ 2020-07-18 20:52   ` Gregory CLEMENT
  2020-07-18 21:31     ` Andy Shevchenko
  1 sibling, 1 reply; 10+ messages in thread
From: Gregory CLEMENT @ 2020-07-18 20:52 UTC (permalink / raw)
  To: Andy Shevchenko, Linus Walleij, Bartosz Golaszewski, linux-gpio
  Cc: Andy Shevchenko, Jason Cooper, Andrew Lunn, Sebastian Hesselbarth

Andy Shevchenko <andriy.shevchenko@linux.intel.com> writes:

> Make use of for_each_requested_gpio() instead of home grown analogue.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Jason Cooper <jason@lakedaemon.net>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
> Cc: Gregory Clement <gregory.clement@bootlin.com>

Applied on mvebu/arm

Thanks,

Gregory
> ---
>  arch/arm/plat-orion/gpio.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/arch/arm/plat-orion/gpio.c b/arch/arm/plat-orion/gpio.c
> index 26a531ebb6e9..734f0be4f14a 100644
> --- a/arch/arm/plat-orion/gpio.c
> +++ b/arch/arm/plat-orion/gpio.c
> @@ -442,6 +442,7 @@ static void orion_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
>  
>  	struct orion_gpio_chip *ochip = gpiochip_get_data(chip);
>  	u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk;
> +	const char *label;
>  	int i;
>  
>  	out	= readl_relaxed(GPIO_OUT(ochip));
> @@ -453,15 +454,10 @@ static void orion_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
>  	edg_msk	= readl_relaxed(GPIO_EDGE_MASK(ochip));
>  	lvl_msk	= readl_relaxed(GPIO_LEVEL_MASK(ochip));
>  
> -	for (i = 0; i < chip->ngpio; i++) {
> -		const char *label;
> +	for_each_requested_gpio(chip, i, label) {
>  		u32 msk;
>  		bool is_out;
>  
> -		label = gpiochip_is_requested(chip, i);
> -		if (!label)
> -			continue;
> -
>  		msk = 1 << i;
>  		is_out = !(io_conf & msk);
>  
> -- 
> 2.27.0.rc2
>

-- 
Gregory Clement, Bootlin
Embedded Linux and Kernel engineering
http://bootlin.com

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

* Re: [PATCH v1 2/5] ARM/orion/gpio: Make use of for_each_requested_gpio()
  2020-07-18 20:52   ` Gregory CLEMENT
@ 2020-07-18 21:31     ` Andy Shevchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-07-18 21:31 UTC (permalink / raw)
  To: Gregory CLEMENT
  Cc: Andy Shevchenko, Linus Walleij, Bartosz Golaszewski,
	open list:GPIO SUBSYSTEM, Jason Cooper, Andrew Lunn,
	Sebastian Hesselbarth

On Sat, Jul 18, 2020 at 11:53 PM Gregory CLEMENT
<gregory.clement@bootlin.com> wrote:
>
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> writes:
>
> > Make use of for_each_requested_gpio() instead of home grown analogue.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Cc: Jason Cooper <jason@lakedaemon.net>
> > Cc: Andrew Lunn <andrew@lunn.ch>
> > Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
> > Cc: Gregory Clement <gregory.clement@bootlin.com>
>
> Applied on mvebu/arm

I guess you need to merge an immutable branch from Linus. Does above imply this?



-- 
With Best Regards,
Andy Shevchenko

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

end of thread, other threads:[~2020-07-18 21:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 15:05 [PATCH v1 0/5] gpio, pinctrl, introduce for_each_requested_gpio() helper Andy Shevchenko
2020-06-15 15:05 ` [PATCH v1 1/5] gpiolib: Introduce for_each_requested_gpio_in_range() macro Andy Shevchenko
2020-06-15 15:05 ` [PATCH v1 2/5] ARM/orion/gpio: Make use of for_each_requested_gpio() Andy Shevchenko
2020-06-16 20:43   ` Andrew Lunn
2020-07-18 20:52   ` Gregory CLEMENT
2020-07-18 21:31     ` Andy Shevchenko
2020-06-15 15:05 ` [PATCH v1 3/5] gpio: mvebu: " Andy Shevchenko
2020-06-15 15:05 ` [PATCH v1 4/5] gpio: xra1403: " Andy Shevchenko
2020-06-15 15:05 ` [PATCH v1 5/5] pinctrl: at91: " Andy Shevchenko
2020-06-20 21:16 ` [PATCH v1 0/5] gpio, pinctrl, introduce for_each_requested_gpio() helper 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).