On 30/11/2023 21:22, Caleb Connolly wrote:
Upstream uses the gpio-ranges property to define the number of GPIOs,
support for parsing this when gpio-count is unspecified

Additionally, drop the bank-name property as it isn't used in upstream,
and we can just hardcode the bank name instead.

Signed-off-by: Caleb Connolly <caleb.conno...@linaro.org>
---
  drivers/gpio/qcom_pmic_gpio.c | 39 ++++++++++++++++++++++++++++++++-------
  1 file changed, 32 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/qcom_pmic_gpio.c b/drivers/gpio/qcom_pmic_gpio.c
index 7b83c67fa464..54f4dbd2b84e 100644
--- a/drivers/gpio/qcom_pmic_gpio.c
+++ b/drivers/gpio/qcom_pmic_gpio.c
@@ -245,23 +245,48 @@ static int qcom_gpio_probe(struct udevice *dev)
        return 0;
  }
+/*
+ * Parse basic GPIO count specified via the gpio-ranges property
+ * as specified in Linux devicetrees
+ * Returns < 0 on error, otherwise gpio count
+ */
+static int qcom_gpio_of_parse_ranges(struct udevice *dev)
+{
+       int ret;
+       struct ofnode_phandle_args args;
+
+       ret = ofnode_parse_phandle_with_args(dev_ofnode(dev), "gpio-ranges",
+                                            NULL, 3, 0, &args);
+       if (ret)
+               return log_msg_ret("gpio-ranges", ret);
+
+       return args.args[2];
+}
+
  static int qcom_gpio_of_to_plat(struct udevice *dev)
  {
        struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+       int ret;
uc_priv->gpio_count = dev_read_u32_default(dev, "gpio-count", 0);
-       uc_priv->bank_name = dev_read_string(dev, "gpio-bank-name");
-       if (uc_priv->bank_name == NULL)
-               uc_priv->bank_name = "qcom_pmic";
+       if (!uc_priv->gpio_count) {
+               ret = qcom_gpio_of_parse_ranges(dev);
+               if (ret > 0)
+                       uc_priv->gpio_count = ret;
+               else
+                       return ret;
+       }
+
+       uc_priv->bank_name = "pmic";
return 0;
  }
static const struct udevice_id qcom_gpio_ids[] = {
-       { .compatible = "qcom,pm8916-gpio" },
-       { .compatible = "qcom,pm8994-gpio" }, /* 22 GPIO's */
-       { .compatible = "qcom,pm8998-gpio" },
-       { .compatible = "qcom,pms405-gpio" },
+       { .compatible = "qcom,pm8916-gpio", },
+       { .compatible = "qcom,pm8994-gpio", },
+       { .compatible = "qcom,pm8998-gpio", },
+       { .compatible = "qcom,pms405-gpio", },

This seems to be a spurious change

        { }
  };

Reply via email to