Skip to content

Commit b3337eb

Browse files
andy-shevlinusw
authored andcommitted
gpiolib: Introduce for_each_requested_gpio_in_range() macro
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent b3a9e3b commit b3337eb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

include/linux/gpio/driver.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,22 @@ struct gpio_chip {
474474
extern const char *gpiochip_is_requested(struct gpio_chip *gc,
475475
unsigned int offset);
476476

477+
/**
478+
* for_each_requested_gpio_in_range - iterates over requested GPIOs in a given range
479+
* @chip: the chip to query
480+
* @i: loop variable
481+
* @base: first GPIO in the range
482+
* @size: amount of GPIOs to check starting from @base
483+
* @label: label of current GPIO
484+
*/
485+
#define for_each_requested_gpio_in_range(chip, i, base, size, label) \
486+
for (i = 0; i < size; i++) \
487+
if ((label = gpiochip_is_requested(chip, base + i)) == NULL) {} else
488+
489+
/* Iterates over all requested GPIO of the given @chip */
490+
#define for_each_requested_gpio(chip, i, label) \
491+
for_each_requested_gpio_in_range(chip, i, 0, chip->ngpio, label)
492+
477493
/* add/remove chips */
478494
extern int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
479495
struct lock_class_key *lock_key,

0 commit comments

Comments
 (0)