gpio: nomadik: handle variadic GPIO count
authorThéo Lebrun <theo.lebrun@bootlin.com>
Wed, 28 Feb 2024 11:28:21 +0000 (12:28 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Thu, 29 Feb 2024 09:36:20 +0000 (10:36 +0100)
Read the "ngpios" property to determine the number of GPIOs for a bank.
If not available, fallback to NMK_GPIO_PER_CHIP ie 32 ie the current
behavior.

The IP block always supports 32 GPIOs, but platforms can expose a lesser
amount. The Mobileye EyeQ5 is in this case; one bank is 29 GPIOs and
the other is 23.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240228-mbly-gpio-v2-23-3ba757474006@bootlin.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpio-nomadik.c

index ca5c28965224bc856cf66394f0c8e262f7fdfac4..19394dc7e34a09cea5fc31c8d8bcea9b200ebc75 100644 (file)
@@ -488,7 +488,7 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct device_node *np,
        struct gpio_chip *chip;
        struct clk *clk;
        void __iomem *base;
-       u32 id;
+       u32 id, ngpio;
 
        gpio_dev = bus_find_device_by_of_node(&platform_bus_type, np);
        if (!gpio_dev) {
@@ -518,10 +518,15 @@ struct nmk_gpio_chip *nmk_gpio_populate_chip(struct device_node *np,
                return ERR_PTR(-ENOMEM);
        }
 
+       if (device_property_read_u32(gpio_dev, "ngpios", &ngpio)) {
+               ngpio = NMK_GPIO_PER_CHIP;
+               dev_dbg(&pdev->dev, "populate: using default ngpio (%d)\n", ngpio);
+       }
+
        nmk_chip->bank = id;
        chip = &nmk_chip->chip;
        chip->base = -1;
-       chip->ngpio = NMK_GPIO_PER_CHIP;
+       chip->ngpio = ngpio;
        chip->label = dev_name(gpio_dev);
        chip->parent = gpio_dev;