[PATCH 16/20] gpio/rockchip: try to get gpio id from uid when ACPI enabled
From: Jianqun Xu
Date: Tue Sep 20 2022 - 06:32:32 EST
When the ACPI is enabled, the GPIO index should be get from the uid,
otherwise get it from the dt alias or a static count to the legency dt
files.
Signed-off-by: Jianqun Xu <jay.xu@xxxxxxxxxxxxxx>
---
drivers/gpio/gpio-rockchip.c | 40 ++++++++++++++++++++++++++++--------
1 file changed, 31 insertions(+), 9 deletions(-)
diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index 09ed5c880dde..11586d93549b 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -6,6 +6,7 @@
* Copyright (c) 2021 Rockchip Electronics Co. Ltd.
*/
+#include <linux/acpi.h>
#include <linux/bitops.h>
#include <linux/clk.h>
#include <linux/device.h>
@@ -710,6 +711,29 @@ rockchip_gpio_find_bank(struct pinctrl_dev *pctldev, int id)
return found ? bank : NULL;
}
+static int rockchip_gpio_get_bank_id(struct device *dev)
+{
+ struct fwnode_handle *fwnode = dev_fwnode(dev);
+ int bank_id = -EINVAL;
+ u64 uid;
+ int ret;
+ static int gpio;
+
+ if (is_acpi_node(fwnode)) {
+ ret = acpi_dev_uid_to_integer(ACPI_COMPANION(dev), &uid);
+ if (ret < 0)
+ return ret;
+
+ bank_id = uid;
+ } else {
+ bank_id = of_alias_get_id(to_of_node(fwnode), "gpio");
+ if (bank_id < 0)
+ bank_id = gpio++;
+ }
+
+ return bank_id;
+}
+
static int rockchip_gpio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -717,8 +741,7 @@ static int rockchip_gpio_probe(struct platform_device *pdev)
struct device_node *pctlnp = of_get_parent(np);
struct pinctrl_dev *pctldev = NULL;
struct rockchip_pin_bank *bank = NULL;
- static int gpio;
- int id, ret;
+ int ret;
if (!np || !pctlnp)
return -ENODEV;
@@ -727,13 +750,11 @@ static int rockchip_gpio_probe(struct platform_device *pdev)
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;
+ ret = rockchip_gpio_get_bank_id(dev);
+ if (ret >= 0)
+ bank->bank_num = ret;
+ else
+ goto err;
bank->dev = dev;
bank->of_node = np;
@@ -759,6 +780,7 @@ static int rockchip_gpio_probe(struct platform_device *pdev)
clk_put(bank->db_clk);
clk_disable_unprepare(bank->clk);
clk_disable_unprepare(bank->db_clk);
+err:
return ret;
}
--
2.25.1