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

gpio: brcmstb: support gpio-line-names property

The default handling of the gpio-line-names property by the
gpiolib-of implementation does not work with the multiple
gpiochip banks per device structure used by the gpio-brcmstb
driver.

This commit adds driver level support for the device tree
property so that GPIO lines can be assigned friendly names.

Signed-off-by: Doug Berger <opendmb@gmail.com>
Link: https://lore.kernel.org/r/1583780521-45702-1-git-send-email-opendmb@gmail.com
Acked-by: Gregory Fong <gregory.0xf0@gmail.com>
Acked-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Doug Berger and committed by
Linus Walleij
5eefcaed 30a464a8

+44
+44
drivers/gpio/gpio-brcmstb.c
··· 603 603 .resume_noirq = brcmstb_gpio_resume, 604 604 }; 605 605 606 + static void brcmstb_gpio_set_names(struct device *dev, 607 + struct brcmstb_gpio_bank *bank) 608 + { 609 + struct device_node *np = dev->of_node; 610 + const char **names; 611 + int nstrings, base; 612 + unsigned int i; 613 + 614 + base = bank->id * MAX_GPIO_PER_BANK; 615 + 616 + nstrings = of_property_count_strings(np, "gpio-line-names"); 617 + if (nstrings <= base) 618 + /* Line names not present */ 619 + return; 620 + 621 + names = devm_kcalloc(dev, MAX_GPIO_PER_BANK, sizeof(*names), 622 + GFP_KERNEL); 623 + if (!names) 624 + return; 625 + 626 + /* 627 + * Make sure to not index beyond the end of the number of descriptors 628 + * of the GPIO device. 629 + */ 630 + for (i = 0; i < bank->width; i++) { 631 + const char *name; 632 + int ret; 633 + 634 + ret = of_property_read_string_index(np, "gpio-line-names", 635 + base + i, &name); 636 + if (ret) { 637 + if (ret != -ENODATA) 638 + dev_err(dev, "unable to name line %d: %d\n", 639 + base + i, ret); 640 + break; 641 + } 642 + if (*name) 643 + names[i] = name; 644 + } 645 + 646 + bank->gc.names = names; 647 + } 648 + 606 649 static int brcmstb_gpio_probe(struct platform_device *pdev) 607 650 { 608 651 struct device *dev = &pdev->dev; ··· 769 726 need_wakeup_event |= !!__brcmstb_gpio_get_active_irqs(bank); 770 727 gc->write_reg(reg_base + GIO_MASK(bank->id), 0); 771 728 729 + brcmstb_gpio_set_names(dev, bank); 772 730 err = gpiochip_add_data(gc, bank); 773 731 if (err) { 774 732 dev_err(dev, "Could not add gpiochip for bank %d\n",