linux-rockchip.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Johan Jonker <jbx6244@gmail.com>
To: linus.walleij@linaro.org, brgl@bgdev.pl
Cc: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
	heiko@sntech.de, linux-gpio@vger.kernel.org,
	devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
	kever.yang@rock-chips.com, sjg@chromium.org,
	philipp.tomsich@vrull.eu, john@metanate.com,
	quentin.schulz@theobroma-systems.com
Subject: [PATCH v2 3/8] gpio: gpio-rockchip: parse gpio-ranges for bank id
Date: Sat, 21 Jan 2023 12:08:38 +0100	[thread overview]
Message-ID: <890be9a0-8e82-a8f4-bc15-d5d1597343c2@gmail.com> (raw)
In-Reply-To: <03627216-54b5-5d9b-f91d-adcd637819e3@gmail.com>

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(-)

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

  parent reply	other threads:[~2023-01-21 11:09 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-21 11:06 [PATCH v2 1/8] dt-bindings: gpio: rockchip,gpio-bank: add compatible string per SoC Johan Jonker
2023-01-21 11:08 ` [PATCH v2 2/8] dt-bindings: pinctrl: rockchip,pinctrl: mark gpio sub nodes of pinctrl as deprecated Johan Jonker
2023-01-22 13:53   ` Krzysztof Kozlowski
2023-01-26 13:45   ` Linus Walleij
2023-02-05 17:20     ` Johan Jonker
2023-02-06 11:26   ` Linus Walleij
2023-01-21 11:08 ` Johan Jonker [this message]
2023-01-26 13:47   ` [PATCH v2 3/8] gpio: gpio-rockchip: parse gpio-ranges for bank id Linus Walleij
2023-03-02  3:29   ` Kever Yang
2023-01-21 11:08 ` [PATCH v2 4/8] ARM: dts: rockchip: add gpio-ranges property to gpio nodes Johan Jonker
2023-03-02  6:37   ` Kever Yang
2023-01-21 11:09 ` [PATCH v2 5/8] arm64: " Johan Jonker
2023-03-02  6:38   ` Kever Yang
2023-01-21 11:09 ` [PATCH v2 6/8] ARM: dts: rockchip: replace compatible " Johan Jonker
2023-01-21 11:09 ` [PATCH v2 7/8] arm64: " Johan Jonker
2023-01-21 11:10 ` [PATCH v2 8/8] ARM: dts: rockchip: rk3066a: move gpio nodes to root Johan Jonker
2023-01-22 13:52 ` [PATCH v2 1/8] dt-bindings: gpio: rockchip,gpio-bank: add compatible string per SoC Krzysztof Kozlowski
2023-01-26 13:44 ` Linus Walleij
2023-02-08 11:08 ` Linus Walleij
2023-02-10 20:03   ` Bartosz Golaszewski
2023-02-12 16:14     ` Krzysztof Kozlowski
2023-02-15 15:02       ` Bartosz Golaszewski
2023-02-15 16:14         ` Johan Jonker
2023-02-15 20:15           ` Krzysztof Kozlowski
2023-02-15 21:01 ` [PATCH v3] " Johan Jonker
2023-02-16 10:41   ` Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=890be9a0-8e82-a8f4-bc15-d5d1597343c2@gmail.com \
    --to=jbx6244@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=devicetree@vger.kernel.org \
    --cc=heiko@sntech.de \
    --cc=john@metanate.com \
    --cc=kever.yang@rock-chips.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=philipp.tomsich@vrull.eu \
    --cc=quentin.schulz@theobroma-systems.com \
    --cc=robh+dt@kernel.org \
    --cc=sjg@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).