gpio: provide for_each_hwgpio()
PATCH v2 1/2 gpio: provide for_each_hwgpio()
From: Bartosz Golaszewski <[email protected]>
We only provide iterators for requested GPIOs to provider drivers. In order to allow them to display debug information about all GPIOs, let's provide a variant for iterating over all GPIOs.
---
v1 -> v2:
- rename the iterator to for_each_hwgpio()
include/linux/gpio/driver.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
include/linux/gpio/driver.h +15 -0
@@ -551,6 +551,21 @@ DEFINE_CLASS(_gpiochip_for_each_data, }), const char **label, int *i) +/** +* for_each_hwgpio - Iterates over all GPIOs for given chip. +* @_chip: Chip to iterate over. +* @_i: Loop counter. +* @_label: Place to store the address of the label if the GPIO is requested. +* Set to NULL for unused GPIOs. +*/ +#define for_each_hwgpio (_chip, _i, _label) \ + for (CLASS(_gpiochip_for_each_data, _data)(&_label, &_i); \ + *_data.i < _chip->ngpio; \ + (*_data.i)++, kfree(*(_data.label)), *_data.label = NULL) \ + if (IS_ERR(*_data.label = \ + gpiochip_dup_line_label(_chip, *_data.i))) {} \ + else +/** * for_each_requested_gpio_in_range - iterates over requested GPIOs in a given range * @_chip: the chip to query
Signature · 1 line
2.40.1
PATCH v2 2/2 gpio: sim: use for_each_hwgpio()
From: Bartosz Golaszewski <[email protected]>
Display debugfs information about all simulated GPIOs, not only the requested ones.
--- drivers/gpio/gpio-sim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpio-sim.c +2 -2
@@ -234,10 +234,10 @@ static void gpio_sim_dbg_show(struct seq_file *seq, struct gpio_chip *gc)guard (mutex)(&chip->lock); -for_each_requested_gpio (gc, i, label) +for_each_hwgpio (gc, i, label) seq_printf(seq, " gpio-%-3d (%s) %s,%s\n", gc->base + i, - label, + label ?: "<unused>", test_bit(i, chip->direction_map) ? "input" : test_bit(i, chip->value_map) ? "output-high" : "output-low",
Signature · 1 line
2.40.1
Re: [PATCH v2 2/2] gpio: sim: use for_each_hwgpio()
Quoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Display debugfs information about all simulated GPIOs, not only the requested ones.
Signed-off-by Bartosz Golaszewski <[email protected]>
Yours,
Linus Walleij
Re: [PATCH v2 2/2] gpio: sim: use for_each_hwgpio()
In reply to Bartosz GolaszewskiQuoted 29 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Display debugfs information about all simulated GPIOs, not only the requested ones.
Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/gpio/gpio-sim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpio/gpio-sim.c +2
-3@@ -234,10 +234,10 @@ static void gpio_sim_dbg_show(struct seq_file *seq, struct gpio_chip *gc)guard (mutex)(&chip->lock); -for_each_requested_gpio (gc, i, label) +for_each_hwgpio (gc, i, label) seq_printf(seq, " gpio-%-3d (%s) %s,%s\n", gc->base + i, - label, + label ?: "<unused>", test_bit(i, chip->direction_map) ? "input" : test_bit(i, chip->value_map) ? "output-high" : "output-low", --
Quoted 2 lines
2.40.1
Patch applied.
Bart
Quoted 10 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We only provide iterators for requested GPIOs to provider drivers. In order to allow them to display debug information about all GPIOs, let's provide a variant for iterating over all GPIOs.
Signed-off-by Bartosz Golaszewski <[email protected]>---
v1 -> v2:
- rename the iterator tofor_each_hwgpio()
Yours,
Linus Walleij
Quoted 42 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We only provide iterators for requested GPIOs to provider drivers. In order to allow them to display debug information about all GPIOs, let's provide a variant for iterating over all GPIOs.
Signed-off-by Bartosz Golaszewski <[email protected]>---
v1 -> v2:
- rename the iterator tofor_each_hwgpio()include/linux/gpio/driver.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)include/linux/gpio/driver.h +15
-1@@ -551,6 +551,21 @@ DEFINE_CLASS(_gpiochip_for_each_data, }), const char **label, int *i) +/** +* for_each_hwgpio - Iterates over all GPIOs for given chip. +* @_chip: Chip to iterate over. +* @_i: Loop counter. +* @_label: Place to store the address of the label if the GPIO is requested. +* Set to NULL for unused GPIOs. +*/ +#define for_each_hwgpio (_chip, _i, _label) \ + for (CLASS(_gpiochip_for_each_data, _data)(&_label, &_i); \ + *_data.i < _chip->ngpio; \ + (*_data.i)++, kfree(*(_data.label)), *_data.label = NULL) \ + if (IS_ERR(*_data.label = \ + gpiochip_dup_line_label(_chip, *_data.i))) {} \ + else +/** * for_each_requested_gpio_in_range - iterates over requested GPIOs in a given range * @_chip: the chip to query --
Quoted 2 lines
2.40.1
Patch applied.
Bart