mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wenhua Lin <Wenhua.Lin@unisoc.com>
To: Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andy@kernel.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Orson Zhai <orsonzhai@gmail.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	<linux-gpio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	wenhua lin <wenhua.lin1994@gmail.com>,
	Wenhua Lin <Wenhua.Lin@unisoc.com>,
	Xiongpeng Wu <xiongpeng.wu@unisoc.com>
Subject: [PATCH V3 3/4] gpio: eic-sprd: Modify the calculation method of eic number
Date: Thu, 4 Jan 2024 10:42:43 +0800	[thread overview]
Message-ID: <20240104024244.12163-4-Wenhua.Lin@unisoc.com> (raw)
In-Reply-To: <20240104024244.12163-1-Wenhua.Lin@unisoc.com>

When the soc changes, the corresponding gpio-eic-sprd.c
code needs to be modified, and the corresponding
Document must also be modified, which is quite troublesome.
To avoid modifying the driver file, the number of eics
is automatically calculated by matching dts nodes.

Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
---
 drivers/gpio/gpio-eic-sprd.c | 45 ++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/drivers/gpio/gpio-eic-sprd.c b/drivers/gpio/gpio-eic-sprd.c
index e492157e5154..1ca3c444957c 100644
--- a/drivers/gpio/gpio-eic-sprd.c
+++ b/drivers/gpio/gpio-eic-sprd.c
@@ -109,34 +109,32 @@ static struct sprd_eic *to_sprd_eic(struct notifier_block *nb)
 
 struct sprd_eic_variant_data {
 	enum sprd_eic_type type;
-	u32 num_eics;
 };
 
+#define SPRD_EIC_VAR_DATA(soc_name)						\
+static const struct sprd_eic_variant_data soc_name##_eic_dbnc_data = {		\
+	.type = SPRD_EIC_DEBOUNCE,						\
+};										\
+										\
+static const struct sprd_eic_variant_data soc_name##_eic_latch_data = {	\
+	.type = SPRD_EIC_LATCH,							\
+};										\
+										\
+static const struct sprd_eic_variant_data soc_name##_eic_async_data = {	\
+	.type = SPRD_EIC_ASYNC,							\
+};										\
+										\
+static const struct sprd_eic_variant_data soc_name##_eic_sync_data = {		\
+	.type = SPRD_EIC_SYNC,							\
+}
+
+SPRD_EIC_VAR_DATA(sc9860);
+
 static const char *sprd_eic_label_name[SPRD_EIC_MAX] = {
 	"eic-debounce", "eic-latch", "eic-async",
 	"eic-sync",
 };
 
-static const struct sprd_eic_variant_data sc9860_eic_dbnc_data = {
-	.type = SPRD_EIC_DEBOUNCE,
-	.num_eics = 8,
-};
-
-static const struct sprd_eic_variant_data sc9860_eic_latch_data = {
-	.type = SPRD_EIC_LATCH,
-	.num_eics = 8,
-};
-
-static const struct sprd_eic_variant_data sc9860_eic_async_data = {
-	.type = SPRD_EIC_ASYNC,
-	.num_eics = 8,
-};
-
-static const struct sprd_eic_variant_data sc9860_eic_sync_data = {
-	.type = SPRD_EIC_SYNC,
-	.num_eics = 8,
-};
-
 static inline void __iomem *sprd_eic_offset_base(struct sprd_eic *sprd_eic,
 						 unsigned int bank)
 {
@@ -607,6 +605,7 @@ static int sprd_eic_probe(struct platform_device *pdev)
 	struct gpio_irq_chip *irq;
 	struct sprd_eic *sprd_eic;
 	struct resource *res;
+	u16 num_banks = 0;
 	int ret, i;
 
 	pdata = of_device_get_match_data(dev);
@@ -640,10 +639,12 @@ static int sprd_eic_probe(struct platform_device *pdev)
 		sprd_eic->base[i] = devm_ioremap_resource(dev, res);
 		if (IS_ERR(sprd_eic->base[i]))
 			return PTR_ERR(sprd_eic->base[i]);
+
+		num_banks++;
 	}
 
 	sprd_eic->chip.label = sprd_eic_label_name[sprd_eic->type];
-	sprd_eic->chip.ngpio = pdata->num_eics;
+	sprd_eic->chip.ngpio = num_banks * SPRD_EIC_PER_BANK_NR;
 	sprd_eic->chip.base = -1;
 	sprd_eic->chip.parent = dev;
 	sprd_eic->chip.direction_input = sprd_eic_direction_input;
-- 
2.17.1


  parent reply	other threads:[~2024-01-04  2:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-04  2:42 [PATCH V3 0/4] gpio: eic-sprd: Modification of UNISOC Platform EIC Driver Wenhua Lin
2024-01-04  2:42 ` [PATCH V3 1/4] gpio: eic-sprd: Keep the clock rtc_1k on Wenhua Lin
2024-01-04 12:59   ` Andy Shevchenko
2024-01-05  2:11     ` wenhua lin
2024-01-05  2:17       ` Chunyan Zhang
2024-01-05  2:28         ` wenhua lin
2024-01-05  3:25   ` Chunyan Zhang
2024-01-08  7:36     ` wenhua lin
2024-01-04  2:42 ` [PATCH V3 2/4] gpio: eic-sprd: Clear interrupt after set the interrupt type Wenhua Lin
2024-01-04  2:42 ` Wenhua Lin [this message]
2024-01-04 13:01   ` [PATCH V3 3/4] gpio: eic-sprd: Modify the calculation method of eic number Andy Shevchenko
2024-01-05  2:13     ` wenhua lin
2024-01-04  2:42 ` [PATCH V3 4/4] gpio: eic-sprd: Support 8 banks EIC controller Wenhua Lin
2024-01-08  8:55   ` Chunyan Zhang
2024-01-09  7:58     ` wenhua lin

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=20240104024244.12163-4-Wenhua.Lin@unisoc.com \
    --to=wenhua.lin@unisoc.com \
    --cc=andy@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=orsonzhai@gmail.com \
    --cc=wenhua.lin1994@gmail.com \
    --cc=xiongpeng.wu@unisoc.com \
    --cc=zhang.lyra@gmail.com \
    /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

all inboxes | Powered by JetHome®