diff mbox series

[v4,09/39] gpio: qcom_pmic: 1-based GPIOs

Message ID 20240215-b4-qcom-common-target-v4-9-ed06355c634a@linaro.org
State Superseded
Headers show
Series Qualcomm generic board support | expand

Commit Message

Caleb Connolly Feb. 15, 2024, 8:52 p.m. UTC
Qualcomm PMICs number their GPIOs starting from 1, implement a custom
.xlate method to handle this.

Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
 drivers/gpio/qcom_pmic_gpio.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

Sumit Garg Feb. 20, 2024, 5:47 a.m. UTC | #1
On Fri, 16 Feb 2024 at 02:22, Caleb Connolly <caleb.connolly@linaro.org> wrote:
>
> Qualcomm PMICs number their GPIOs starting from 1, implement a custom
> .xlate method to handle this.
>
> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
>  drivers/gpio/qcom_pmic_gpio.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>

Reviewed-by: Sumit Garg <sumit.garg@linaro.org>

-Sumit

> diff --git a/drivers/gpio/qcom_pmic_gpio.c b/drivers/gpio/qcom_pmic_gpio.c
> index 6167c8411678..2a4fef8d28cb 100644
> --- a/drivers/gpio/qcom_pmic_gpio.c
> +++ b/drivers/gpio/qcom_pmic_gpio.c
> @@ -209,12 +209,34 @@ static int qcom_gpio_set_value(struct udevice *dev, unsigned offset,
>                                        REG_CTL_OUTPUT_MASK, !!value);
>  }
>
> +static int qcom_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
> +                          struct ofnode_phandle_args *args)
> +{
> +       struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
> +
> +       if (args->args_count < 1)
> +               return -EINVAL;
> +
> +       /* GPIOs in DT are 1-based */
> +       desc->offset = args->args[0] - 1;
> +       if (desc->offset >= uc_priv->gpio_count)
> +               return -EINVAL;
> +
> +       if (args->args_count < 2)
> +               return 0;
> +
> +       desc->flags = gpio_flags_xlate(args->args[1]);
> +
> +       return 0;
> +}
> +
>  static const struct dm_gpio_ops qcom_gpio_ops = {
>         .direction_input        = qcom_gpio_direction_input,
>         .direction_output       = qcom_gpio_direction_output,
>         .get_value              = qcom_gpio_get_value,
>         .set_value              = qcom_gpio_set_value,
>         .get_function           = qcom_gpio_get_function,
> +       .xlate                  = qcom_gpio_xlate,
>  };
>
>  static int qcom_gpio_probe(struct udevice *dev)
>
> --
> 2.43.1
>
diff mbox series

Patch

diff --git a/drivers/gpio/qcom_pmic_gpio.c b/drivers/gpio/qcom_pmic_gpio.c
index 6167c8411678..2a4fef8d28cb 100644
--- a/drivers/gpio/qcom_pmic_gpio.c
+++ b/drivers/gpio/qcom_pmic_gpio.c
@@ -209,12 +209,34 @@  static int qcom_gpio_set_value(struct udevice *dev, unsigned offset,
 				       REG_CTL_OUTPUT_MASK, !!value);
 }
 
+static int qcom_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
+			   struct ofnode_phandle_args *args)
+{
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+
+	if (args->args_count < 1)
+		return -EINVAL;
+
+	/* GPIOs in DT are 1-based */
+	desc->offset = args->args[0] - 1;
+	if (desc->offset >= uc_priv->gpio_count)
+		return -EINVAL;
+
+	if (args->args_count < 2)
+		return 0;
+
+	desc->flags = gpio_flags_xlate(args->args[1]);
+
+	return 0;
+}
+
 static const struct dm_gpio_ops qcom_gpio_ops = {
 	.direction_input	= qcom_gpio_direction_input,
 	.direction_output	= qcom_gpio_direction_output,
 	.get_value		= qcom_gpio_get_value,
 	.set_value		= qcom_gpio_set_value,
 	.get_function		= qcom_gpio_get_function,
+	.xlate			= qcom_gpio_xlate,
 };
 
 static int qcom_gpio_probe(struct udevice *dev)