linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jianqun Xu <jay.xu@rock-chips.com>
To: heiko@sntech.de
Cc: linus.walleij@linaro.org, huangtao@rock-chips.com,
	kever.yang@rock-chips.com, linux-rockchip@lists.infradead.org,
	linux-gpio@vger.kernel.org, Jianqun Xu <jay.xu@rock-chips.com>
Subject: [PATCH 2/4] gpio: rockchip: get irq support for both dt and acpi
Date: Tue,  8 Mar 2022 14:19:33 +0800	[thread overview]
Message-ID: <20220308061935.2441447-3-jay.xu@rock-chips.com> (raw)
In-Reply-To: <20220308061935.2441447-1-jay.xu@rock-chips.com>

Get the irq of gpio controller with fwnode apis, support for both dt
node and acpi.

Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
---
 drivers/gpio/gpio-rockchip.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index b67038572285..3703c3d71809 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -5,7 +5,7 @@
  *
  * Copyright (c) 2021 Rockchip Electronics Co. Ltd.
  */
-
+#include <linux/acpi.h>
 #include <linux/bitops.h>
 #include <linux/clk.h>
 #include <linux/device.h>
@@ -639,10 +639,6 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 {
 	int id = 0;
 
-	bank->irq = irq_of_parse_and_map(bank->of_node, 0);
-	if (!bank->irq)
-		return -EINVAL;
-
 	bank->clk = of_clk_get(bank->of_node, 0);
 	if (IS_ERR(bank->clk))
 		return PTR_ERR(bank->clk);
@@ -668,6 +664,24 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 	return 0;
 }
 
+static int rockchip_gpio_get_irq(struct rockchip_pin_bank *bank)
+{
+	struct device *dev = bank->dev;
+	struct fwnode_handle *fwnode = dev_fwnode(dev);
+	struct device_node *np = NULL;
+	int irq = 0;
+
+	if (fwnode_property_read_bool(fwnode, "interrupt-controller"))
+		np = to_of_node(fwnode);
+
+	if (np)
+		irq = irq_of_parse_and_map(np, 0);
+	else if (has_acpi_companion(dev))
+		irq = platform_get_irq_optional(to_platform_device(dev), 0);
+
+	return irq;
+}
+
 static struct rockchip_pin_bank *
 rockchip_gpio_find_bank(struct pinctrl_dev *pctldev, int id)
 {
@@ -721,6 +735,10 @@ static int rockchip_gpio_probe(struct platform_device *pdev)
 	if (IS_ERR(bank->reg_base))
 		return PTR_ERR(bank->reg_base);
 
+	bank->irq = rockchip_gpio_get_irq(bank);
+	if (bank->irq < 0)
+		return bank->irq;
+
 	ret = rockchip_get_bank_data(bank);
 	if (ret)
 		return ret;
-- 
2.25.1


  parent reply	other threads:[~2022-03-08  6:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08  6:19 [PATCH RESEND 0/4] gpio-before-pinctrl Jianqun Xu
2022-03-08  6:19 ` [PATCH 1/4] gpio: rockchip: get regmap by devm_platform_ioremap_resource Jianqun Xu
2022-03-08  6:19 ` Jianqun Xu [this message]
2022-03-10 11:44   ` [PATCH 2/4] gpio: rockchip: get irq support for both dt and acpi Andy Shevchenko
2022-03-08  6:19 ` [PATCH 3/4] gpio: rockchip: support driver to work independs on pinctrl Jianqun Xu
2022-03-08  6:19 ` [PATCH 4/4] pinctrl: rockchip: register gpio driver before pinctrl driver Jianqun Xu
  -- strict thread matches above, loose matches on Subject: below --
2022-03-08  3:25 [PATCH 0/4] gpio-before-pinctrl Jianqun Xu
2022-03-08  3:25 ` [PATCH 2/4] gpio: rockchip: get irq support for both dt and acpi Jianqun Xu

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=20220308061935.2441447-3-jay.xu@rock-chips.com \
    --to=jay.xu@rock-chips.com \
    --cc=heiko@sntech.de \
    --cc=huangtao@rock-chips.com \
    --cc=kever.yang@rock-chips.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.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).