Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'ib-for-each-requested' into devel

+24 -23
+2 -6
arch/arm/plat-orion/gpio.c
··· 442 442 443 443 struct orion_gpio_chip *ochip = gpiochip_get_data(chip); 444 444 u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk; 445 + const char *label; 445 446 int i; 446 447 447 448 out = readl_relaxed(GPIO_OUT(ochip)); ··· 454 453 edg_msk = readl_relaxed(GPIO_EDGE_MASK(ochip)); 455 454 lvl_msk = readl_relaxed(GPIO_LEVEL_MASK(ochip)); 456 455 457 - for (i = 0; i < chip->ngpio; i++) { 458 - const char *label; 456 + for_each_requested_gpio(chip, i, label) { 459 457 u32 msk; 460 458 bool is_out; 461 - 462 - label = gpiochip_is_requested(chip, i); 463 - if (!label) 464 - continue; 465 459 466 460 msk = 1 << i; 467 461 is_out = !(io_conf & msk);
+2 -6
drivers/gpio/gpio-mvebu.c
··· 846 846 { 847 847 struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip); 848 848 u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk; 849 + const char *label; 849 850 int i; 850 851 851 852 regmap_read(mvchip->regs, GPIO_OUT_OFF + mvchip->offset, &out); ··· 858 857 edg_msk = mvebu_gpio_read_edge_mask(mvchip); 859 858 lvl_msk = mvebu_gpio_read_level_mask(mvchip); 860 859 861 - for (i = 0; i < chip->ngpio; i++) { 862 - const char *label; 860 + for_each_requested_gpio(chip, i, label) { 863 861 u32 msk; 864 862 bool is_out; 865 - 866 - label = gpiochip_is_requested(chip, i); 867 - if (!label) 868 - continue; 869 863 870 864 msk = BIT(i); 871 865 is_out = !(io_conf & msk);
+2 -6
drivers/gpio/gpio-xra1403.c
··· 121 121 struct xra1403 *xra = gpiochip_get_data(chip); 122 122 int value[XRA_LAST]; 123 123 int i; 124 + const char *label; 124 125 unsigned int gcr; 125 126 unsigned int gsr; 126 127 ··· 137 136 138 137 gcr = value[XRA_GCR + 1] << 8 | value[XRA_GCR]; 139 138 gsr = value[XRA_GSR + 1] << 8 | value[XRA_GSR]; 140 - for (i = 0; i < chip->ngpio; i++) { 141 - const char *label = gpiochip_is_requested(chip, i); 142 - 143 - if (!label) 144 - continue; 145 - 139 + for_each_requested_gpio(chip, i, label) { 146 140 seq_printf(s, " gpio-%-3d (%-12s) %s %s\n", 147 141 chip->base + i, label, 148 142 (gcr & BIT(i)) ? "in" : "out",
+2 -5
drivers/pinctrl/pinctrl-at91.c
··· 1486 1486 int i; 1487 1487 struct at91_gpio_chip *at91_gpio = gpiochip_get_data(chip); 1488 1488 void __iomem *pio = at91_gpio->regbase; 1489 + const char *gpio_label; 1489 1490 1490 - for (i = 0; i < chip->ngpio; i++) { 1491 + for_each_requested_gpio(chip, i, gpio_label) { 1491 1492 unsigned mask = pin_to_mask(i); 1492 - const char *gpio_label; 1493 1493 1494 - gpio_label = gpiochip_is_requested(chip, i); 1495 - if (!gpio_label) 1496 - continue; 1497 1494 mode = at91_gpio->ops->get_periph(pio, mask); 1498 1495 seq_printf(s, "[%s] GPIO%s%d: ", 1499 1496 gpio_label, chip->label, i);
+16
include/linux/gpio/driver.h
··· 474 474 extern const char *gpiochip_is_requested(struct gpio_chip *gc, 475 475 unsigned int offset); 476 476 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 + 477 493 /* add/remove chips */ 478 494 extern int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, 479 495 struct lock_class_key *lock_key,