Skip to content

Commit 5eefcae

Browse files
Doug BergerLinus Walleij
authored andcommitted
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>
1 parent 30a464a commit 5eefcae

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

‎drivers/gpio/gpio-brcmstb.c‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,49 @@ static const struct dev_pm_ops brcmstb_gpio_pm_ops = {
603603
.resume_noirq = brcmstb_gpio_resume,
604604
};
605605

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+
606649
static int brcmstb_gpio_probe(struct platform_device *pdev)
607650
{
608651
struct device *dev = &pdev->dev;
@@ -726,6 +769,7 @@ static int brcmstb_gpio_probe(struct platform_device *pdev)
726769
need_wakeup_event |= !!__brcmstb_gpio_get_active_irqs(bank);
727770
gc->write_reg(reg_base + GIO_MASK(bank->id), 0);
728771

772+
brcmstb_gpio_set_names(dev, bank);
729773
err = gpiochip_add_data(gc, bank);
730774
if (err) {
731775
dev_err(dev, "Could not add gpiochip for bank %d\n",

0 commit comments

Comments
 (0)