]> git.baikalelectronics.ru Git - uboot.git/commitdiff
gpio: gpio-rockchip: parse gpio-ranges for bank id
authorChris Morgan <macromorgan@hotmail.com>
Mon, 13 Feb 2023 22:27:34 +0000 (16:27 -0600)
committerKever Yang <kever.yang@rock-chips.com>
Tue, 28 Feb 2023 10:07:27 +0000 (18:07 +0800)
Use the new devicetree property of gpio-ranges to determine the GPIO
bank ID. Preserve the "old" way of doing things too, so that boards
can be migrated and tested gradually (I only have a 3566 and 3326 to
test).

Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
drivers/gpio/rk_gpio.c

index 68f30157a9a6de64b162445dff1e21c3650e2d5c..f7ad4d68b4529879bc0330e30eef22ed8aaa283b 100644 (file)
@@ -142,6 +142,7 @@ static int rockchip_gpio_probe(struct udevice *dev)
 {
        struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
        struct rockchip_gpio_priv *priv = dev_get_priv(dev);
+       struct ofnode_phandle_args args;
        char *end;
        int ret;
 
@@ -150,9 +151,22 @@ static int rockchip_gpio_probe(struct udevice *dev)
        if (ret)
                return ret;
 
-       uc_priv->gpio_count = ROCKCHIP_GPIOS_PER_BANK;
-       end = strrchr(dev->name, '@');
-       priv->bank = trailing_strtoln(dev->name, end);
+       /*
+        * If "gpio-ranges" is present in the devicetree use it to parse
+        * the GPIO bank ID, otherwise use the legacy method.
+        */
+       ret = ofnode_parse_phandle_with_args(dev_ofnode(dev),
+                                            "gpio-ranges", NULL, 3,
+                                            0, &args);
+       if (!ret || ret != -ENOENT) {
+               uc_priv->gpio_count = args.args[2];
+               priv->bank = args.args[1] / args.args[2];
+       } else {
+               uc_priv->gpio_count = ROCKCHIP_GPIOS_PER_BANK;
+               end = strrchr(dev->name, '@');
+               priv->bank = trailing_strtoln(dev->name, end);
+       }
+
        priv->name[0] = 'A' + priv->bank;
        uc_priv->bank_name = priv->name;