diff mbox series

[v2,3/8] gpio: gpio-rockchip: parse gpio-ranges for bank id

Message ID 890be9a0-8e82-a8f4-bc15-d5d1597343c2@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/8] dt-bindings: gpio: rockchip,gpio-bank: add compatible string per SoC | expand

Commit Message

Johan Jonker Jan. 21, 2023, 11:08 a.m. UTC
Parse the gpio-ranges property in Rockchip gpio nodes to be
independent from aliases and probe order for our bank id.

Signed-off-by: Johan Jonker <jbx6244@gmail.com>
---
 drivers/gpio/gpio-rockchip.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

--
2.20.1

Comments

Linus Walleij Jan. 26, 2023, 1:47 p.m. UTC | #1
On Sat, Jan 21, 2023 at 12:08 PM Johan Jonker <jbx6244@gmail.com> wrote:

> Parse the gpio-ranges property in Rockchip gpio nodes to be
> independent from aliases and probe order for our bank id.
>
> Signed-off-by: Johan Jonker <jbx6244@gmail.com>

I guess there is no pretty way to do this.
Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij
Kever Yang March 2, 2023, 3:29 a.m. UTC | #2
Hi Johan,

On 2023/1/21 19:08, Johan Jonker wrote:
> Parse the gpio-ranges property in Rockchip gpio nodes to be
> independent from aliases and probe order for our bank id.
>
> Signed-off-by: Johan Jonker <jbx6244@gmail.com>

Looks good to me.

Reviewed-by: Kever Yang <kever.yang@rock-chips.com>


Thanks,
- Kever
> ---
>   drivers/gpio/gpio-rockchip.c | 24 ++++++++++++++++++------
>   1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
> index e5de15a2a..df74b71aa 100644
> --- a/drivers/gpio/gpio-rockchip.c
> +++ b/drivers/gpio/gpio-rockchip.c
> @@ -702,24 +702,36 @@ static int rockchip_gpio_probe(struct platform_device *pdev)
>   {
>   	struct device *dev = &pdev->dev;
>   	struct device_node *np = dev->of_node;
> -	struct device_node *pctlnp = of_get_parent(np);
> +	struct device_node *pctlnp;
>   	struct pinctrl_dev *pctldev = NULL;
>   	struct rockchip_pin_bank *bank = NULL;
>   	struct rockchip_pin_deferred *cfg;
> +	struct of_phandle_args args;
>   	static int gpio;
>   	int id, ret;
>
> -	if (!np || !pctlnp)
> +	if (!np)
> +		return -ENODEV;
> +
> +	ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &args);
> +	if (ret == 0) {
> +		pctlnp = args.np;
> +		id = args.args[1] / 32;
> +	} else {
> +		pctlnp = of_get_parent(np);
> +		id = of_alias_get_id(np, "gpio");
> +		if (id < 0)
> +			id = gpio++;
> +	}
> +
> +	if (!pctlnp)
>   		return -ENODEV;
>
>   	pctldev = of_pinctrl_get(pctlnp);
> +	of_node_put(pctlnp);
>   	if (!pctldev)
>   		return -EPROBE_DEFER;
>
> -	id = of_alias_get_id(np, "gpio");
> -	if (id < 0)
> -		id = gpio++;
> -
>   	bank = rockchip_gpio_find_bank(pctldev, id);
>   	if (!bank)
>   		return -EINVAL;
> --
> 2.20.1
>
>
> _______________________________________________
> Linux-rockchip mailing list
> Linux-rockchip@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-rockchip
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index e5de15a2a..df74b71aa 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -702,24 +702,36 @@  static int rockchip_gpio_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
-	struct device_node *pctlnp = of_get_parent(np);
+	struct device_node *pctlnp;
 	struct pinctrl_dev *pctldev = NULL;
 	struct rockchip_pin_bank *bank = NULL;
 	struct rockchip_pin_deferred *cfg;
+	struct of_phandle_args args;
 	static int gpio;
 	int id, ret;

-	if (!np || !pctlnp)
+	if (!np)
+		return -ENODEV;
+
+	ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &args);
+	if (ret == 0) {
+		pctlnp = args.np;
+		id = args.args[1] / 32;
+	} else {
+		pctlnp = of_get_parent(np);
+		id = of_alias_get_id(np, "gpio");
+		if (id < 0)
+			id = gpio++;
+	}
+
+	if (!pctlnp)
 		return -ENODEV;

 	pctldev = of_pinctrl_get(pctlnp);
+	of_node_put(pctlnp);
 	if (!pctldev)
 		return -EPROBE_DEFER;

-	id = of_alias_get_id(np, "gpio");
-	if (id < 0)
-		id = gpio++;
-
 	bank = rockchip_gpio_find_bank(pctldev, id);
 	if (!bank)
 		return -EINVAL;