mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alban Bedel <albeu@free.fr>
To: linux-mips@linux-mips.org
Cc: Rob Herring <robh+dt@kernel.org>, Pawel Moll <pawel.moll@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Ian Campbell <ijc+devicetree@hellion.org.uk>,
	Kumar Gala <galak@codeaurora.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Jason Cooper <jason@lakedaemon.net>,
	Ralf Baechle <ralf@linux-mips.org>, Alban Bedel <albeu@free.fr>,
	Andrew Bresticker <abrestic@chromium.org>,
	Qais Yousef <qais.yousef@imgtec.com>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 11/14] MIPS: ath79: Add OF support to the GPIO driver
Date: Fri, 17 Apr 2015 16:24:26 +0200	[thread overview]
Message-ID: <1429280669-2986-12-git-send-email-albeu@free.fr> (raw)
In-Reply-To: <1429280669-2986-1-git-send-email-albeu@free.fr>

Replace the simple GPIO chip registration by a platform driver
and make ath79_gpio_init() just register the device.

Signed-off-by: Alban Bedel <albeu@free.fr>
---
 arch/mips/ath79/dev-common.c | 13 ++++++++
 arch/mips/ath79/gpio.c       | 73 +++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 81 insertions(+), 5 deletions(-)

diff --git a/arch/mips/ath79/dev-common.c b/arch/mips/ath79/dev-common.c
index 516225d..4f397cb 100644
--- a/arch/mips/ath79/dev-common.c
+++ b/arch/mips/ath79/dev-common.c
@@ -106,3 +106,16 @@ void __init ath79_register_wdt(void)
 
 	platform_device_register_simple("ath79-wdt", -1, &res, 1);
 }
+
+void __init ath79_gpio_init(void)
+{
+	struct resource res;
+
+	memset(&res, 0, sizeof(res));
+
+	res.flags = IORESOURCE_MEM;
+	res.start = AR71XX_GPIO_BASE;
+	res.end = res.start + AR71XX_GPIO_SIZE - 1;
+
+	platform_device_register_simple("ath79-gpio", -1, &res, 1);
+}
diff --git a/arch/mips/ath79/gpio.c b/arch/mips/ath79/gpio.c
index 8d025b0..ce1a61d 100644
--- a/arch/mips/ath79/gpio.c
+++ b/arch/mips/ath79/gpio.c
@@ -20,6 +20,7 @@
 #include <linux/io.h>
 #include <linux/ioport.h>
 #include <linux/gpio.h>
+#include <linux/of_device.h>
 
 #include <asm/mach-ath79/ar71xx_regs.h>
 #include <asm/mach-ath79/ath79.h>
@@ -178,11 +179,52 @@ void ath79_gpio_function_disable(u32 mask)
 	ath79_gpio_function_setup(0, mask);
 }
 
-void __init ath79_gpio_init(void)
+static const struct of_device_id ath79_gpio_of_match[] = {
+	{
+		.compatible = "qca,ar7100-gpio",
+		.data = (void *)AR71XX_GPIO_COUNT,
+	},
+	{
+		.compatible = "qca,ar7240-gpio",
+		.data = (void *)AR7240_GPIO_COUNT,
+	},
+	{
+		.compatible = "qca,ar7241-gpio",
+		.data = (void *)AR7241_GPIO_COUNT,
+	},
+	{
+		.compatible = "qca,ar9130-gpio",
+		.data = (void *)AR913X_GPIO_COUNT,
+	},
+	{
+		.compatible = "qca,ar9330-gpio",
+		.data = (void *)AR933X_GPIO_COUNT,
+	},
+	{
+		.compatible = "qca,ar9340-gpio",
+		.data = (void *)AR934X_GPIO_COUNT,
+	},
+	{
+		.compatible = "qca,qca9550-gpio",
+		.data = (void *)QCA955X_GPIO_COUNT,
+	},
+	{},
+};
+
+static int ath79_gpio_probe(struct platform_device *pdev)
 {
+	struct resource *res;
 	int err;
 
-	if (soc_is_ar71xx())
+	if (pdev->dev.of_node) {
+		const struct of_device_id *of_id =
+			of_match_device(ath79_gpio_of_match, &pdev->dev);
+		if (!of_id) {
+			dev_err(&pdev->dev, "Error: No device match found\n");
+			return -ENODEV;
+		}
+		ath79_gpio_count = (unsigned long)of_id->data;
+	} else if (soc_is_ar71xx())
 		ath79_gpio_count = AR71XX_GPIO_COUNT;
 	else if (soc_is_ar7240())
 		ath79_gpio_count = AR7240_GPIO_COUNT;
@@ -199,7 +241,13 @@ void __init ath79_gpio_init(void)
 	else
 		BUG();
 
-	ath79_gpio_base = ioremap_nocache(AR71XX_GPIO_BASE, AR71XX_GPIO_SIZE);
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	ath79_gpio_base = devm_ioremap_nocache(
+		&pdev->dev, res->start, resource_size(res));
+	if (!ath79_gpio_base)
+		return -ENOMEM;
+
+	ath79_gpio_chip.dev = &pdev->dev;
 	ath79_gpio_chip.ngpio = ath79_gpio_count;
 	if (soc_is_ar934x() || soc_is_qca955x()) {
 		ath79_gpio_chip.direction_input = ar934x_gpio_direction_input;
@@ -207,10 +255,25 @@ void __init ath79_gpio_init(void)
 	}
 
 	err = gpiochip_add(&ath79_gpio_chip);
-	if (err)
-		panic("cannot add AR71xx GPIO chip, error=%d", err);
+	if (err) {
+		dev_err(&pdev->dev,
+			"cannot add AR71xx GPIO chip, error=%d", err);
+		return err;
+	}
+
+	return 0;
 }
 
+static struct platform_driver ath79_gpio_driver = {
+	.driver = {
+		.name = "ath79-gpio",
+		.of_match_table	= ath79_gpio_of_match,
+	},
+	.probe = ath79_gpio_probe,
+};
+
+module_platform_driver(ath79_gpio_driver);
+
 int gpio_get_value(unsigned gpio)
 {
 	if (gpio < ath79_gpio_count)
-- 
2.0.0


  parent reply	other threads:[~2015-04-17 14:27 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-17 14:24 [PATH] MIPS: ath79: Add OF support and DTS for TL-WR1043ND Alban Bedel
2015-04-17 14:24 ` [PATCH 01/14] devicetree: Add bindings for the SoC of the ATH79 familly Alban Bedel
2015-04-17 14:24 ` [PATCH 02/14] MIPS: ath79: Add basic device tree support Alban Bedel
2015-04-18  7:05   ` Paul Bolle
2015-04-18 16:31     ` Alban
2015-04-20  9:50       ` Paul Bolle
2015-04-24  9:39         ` Alban
2015-04-17 14:24 ` [PATCH 03/14] devicetree: Add bindings for the ATH79 DDR controllers Alban Bedel
2015-04-17 14:24 ` [PATCH 04/14] devicetree: Add bindings for the ATH79 interrupt controllers Alban Bedel
2015-04-17 16:17   ` Sergei Shtylyov
2015-04-17 14:24 ` [PATCH 05/14] devicetree: Add bindings for the ATH79 MISC " Alban Bedel
2015-04-17 14:24 ` [PATCH 06/14] MIPS: ath79: Add OF support to the IRQ controllers Alban Bedel
2015-04-17 14:24 ` [PATCH 07/14] devicetree: Add bindings for the ATH79 PLL controllers Alban Bedel
2015-04-17 16:20   ` Sergei Shtylyov
2015-04-17 14:24 ` [PATCH 08/14] MIPS: ath79: Use the common clk API Alban Bedel
2015-04-17 14:24 ` [PATCH 09/14] MIPS: ath79: Add OF support to the clocks Alban Bedel
2015-04-17 14:24 ` [PATCH 10/14] devicetree: Add bindings for the ATH79 GPIO controllers Alban Bedel
2015-04-17 14:24 ` Alban Bedel [this message]
2015-04-17 14:53   ` [PATCH 11/14] MIPS: ath79: Add OF support to the GPIO driver Arnd Bergmann
2015-04-18 16:57     ` Alban
2015-04-18 16:13 ` [PATCH 12/14] MIPS: Add a basic dtsi for the AR9132 Alban Bedel
2015-04-18 16:13   ` [PATCH 13/14] of: Add vendor prefix for TP-Link Technologies Co. Ltd Alban Bedel
2015-04-21 14:26     ` Rob Herring
2015-04-18 16:13   ` [PATCH 14/14] MIPS: Add basic support for the TL-WR1043ND version 1 Alban Bedel
2015-04-18 20:33 ` [PATH] MIPS: ath79: Add OF support and DTS for TL-WR1043ND Florian Fainelli
2015-04-19 11:50   ` Alban

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=1429280669-2986-12-git-send-email-albeu@free.fr \
    --to=albeu@free.fr \
    --cc=abrestic@chromium.org \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=jason@lakedaemon.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=qais.yousef@imgtec.com \
    --cc=ralf@linux-mips.org \
    --cc=robh+dt@kernel.org \
    --cc=tglx@linutronix.de \
    /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®