Skip to content

Commit 3d8bb3d

Browse files
author
Bartosz Golaszewski
committed
gpio: provide for_each_hwgpio()
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]> Reviewed-by: Linus Walleij <[email protected]>
1 parent 5d60c1e commit 3d8bb3d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

include/linux/gpio/driver.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,21 @@ DEFINE_CLASS(_gpiochip_for_each_data,
551551
}),
552552
const char **label, int *i)
553553

554+
/**
555+
* for_each_hwgpio - Iterates over all GPIOs for given chip.
556+
* @_chip: Chip to iterate over.
557+
* @_i: Loop counter.
558+
* @_label: Place to store the address of the label if the GPIO is requested.
559+
* Set to NULL for unused GPIOs.
560+
*/
561+
#define for_each_hwgpio(_chip, _i, _label) \
562+
for (CLASS(_gpiochip_for_each_data, _data)(&_label, &_i); \
563+
*_data.i < _chip->ngpio; \
564+
(*_data.i)++, kfree(*(_data.label)), *_data.label = NULL) \
565+
if (IS_ERR(*_data.label = \
566+
gpiochip_dup_line_label(_chip, *_data.i))) {} \
567+
else
568+
554569
/**
555570
* for_each_requested_gpio_in_range - iterates over requested GPIOs in a given range
556571
* @_chip: the chip to query

0 commit comments

Comments
 (0)