devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC RESEND] GPIO: gpio-generic: Add DT support
@ 2013-07-30 11:18 Alexander Shiyan
  2013-07-30 16:22 ` Olof Johansson
  0 siblings, 1 reply; 14+ messages in thread
From: Alexander Shiyan @ 2013-07-30 11:18 UTC (permalink / raw)
  To: linux-gpio
  Cc: Linus Walleij, devicetree, Rob Herring, Pawel Moll, Mark Rutland,
	Stephen Warren, Ian Campbell, Grant Likely, Alexander Shiyan

This patch adds DT support for generic (MMIO) GPIO driver.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 .../devicetree/bindings/gpio/gpio-generic.txt      | 25 ++++++++++++++
 drivers/gpio/gpio-generic.c                        | 40 +++++++++++++++-------
 2 files changed, 53 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-generic.txt

diff --git a/Documentation/devicetree/bindings/gpio/gpio-generic.txt b/Documentation/devicetree/bindings/gpio/gpio-generic.txt
new file mode 100644
index 0000000..a9417ac
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/gpio-generic.txt
@@ -0,0 +1,25 @@
+Generic memory-mapped GPIO controller
+
+Required properties:
+- compatible: Should be "basic-mmio-gpio" or "basic-mmio-gpio-be".
+- reg: Physical base GPIO controller registers location and length.
+- reg-names: Should be the names of reg resources. Each register uses
+  its own reg name, so there should be as many reg names as referenced
+  registers:
+  "dat"		: Input/output register (Required),
+  "set"		: Register for set output bits (Optional),
+  "clr"		: Register for clear output bits (Optional),
+  "dirout"	: Register for setup direction as output (Optional),
+  "dirin"	: Register for setup direction as input (Optional).
+- gpio-controller: Marks the device node as a gpio controller.
+- #gpio-cells: Should be two.
+
+Example (Simple 8-bit memory cell):
+
+bgpio: gpio@20000000 {
+	compatible = "basic-mmio-gpio";
+	reg = <0x20000000 0x1>;
+	reg-names = "dat";
+	gpio-controller;
+	#gpio-cells = <2>;
+};
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
index d2196bf..055c7f5 100644
--- a/drivers/gpio/gpio-generic.c
+++ b/drivers/gpio/gpio-generic.c
@@ -57,6 +57,7 @@ o        `                     ~~~~\___/~~~~    ` controller in FPGA is ,.`
 #include <linux/ioport.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
+#include <linux/of_device.h>
 #include <linux/slab.h>
 #include <linux/platform_device.h>
 #include <linux/mod_devicetable.h>
@@ -440,6 +441,26 @@ EXPORT_SYMBOL_GPL(bgpio_init);
 
 #ifdef CONFIG_GPIO_GENERIC_PLATFORM
 
+static const struct platform_device_id bgpio_id_table[] = {
+	{ .name = "basic-mmio-gpio",	.driver_data = 0, },
+	{ .name = "basic-mmio-gpio-be",	.driver_data = BGPIOF_BIG_ENDIAN, },
+	{ }
+};
+MODULE_DEVICE_TABLE(platform, bgpio_id_table);
+
+static const struct of_device_id bgpio_id_dt_table[] = {
+	{
+		.compatible	= "basic-mmio-gpio",
+		.data		= (const void *)0,
+	},
+	{
+		.compatible	= "basic-mmio-gpio-be",
+		.data		= (const void *)BGPIOF_BIG_ENDIAN,
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(of, bgpio_id_dt_table);
+
 static void __iomem *bgpio_map(struct platform_device *pdev,
 			       const char *name,
 			       resource_size_t sane_sz,
@@ -487,11 +508,12 @@ static int bgpio_pdev_probe(struct platform_device *pdev)
 	void __iomem *clr;
 	void __iomem *dirout;
 	void __iomem *dirin;
-	unsigned long sz;
-	unsigned long flags = 0;
+	unsigned long sz, flags;
 	int err;
 	struct bgpio_chip *bgc;
 	struct bgpio_pdata *pdata = dev_get_platdata(dev);
+	const struct of_device_id *of_id =
+		of_match_device(bgpio_id_dt_table, &pdev->dev);
 
 	r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
 	if (!r)
@@ -519,8 +541,7 @@ static int bgpio_pdev_probe(struct platform_device *pdev)
 	if (err)
 		return err;
 
-	if (!strcmp(platform_get_device_id(pdev)->name, "basic-mmio-gpio-be"))
-		flags |= BGPIOF_BIG_ENDIAN;
+	flags = of_id ? (ulong)of_id->data : pdev->id_entry->driver_data;
 
 	bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL);
 	if (!bgc)
@@ -548,16 +569,11 @@ static int bgpio_pdev_remove(struct platform_device *pdev)
 	return bgpio_remove(bgc);
 }
 
-static const struct platform_device_id bgpio_id_table[] = {
-	{ "basic-mmio-gpio", },
-	{ "basic-mmio-gpio-be", },
-	{},
-};
-MODULE_DEVICE_TABLE(platform, bgpio_id_table);
-
 static struct platform_driver bgpio_driver = {
 	.driver = {
-		.name = "basic-mmio-gpio",
+		.name		= "basic-mmio-gpio",
+		.owner		= THIS_MODULE,
+		.of_match_table	= bgpio_id_dt_table,
 	},
 	.id_table = bgpio_id_table,
 	.probe = bgpio_pdev_probe,
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-08-10 21:59 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-30 11:18 [RFC RESEND] GPIO: gpio-generic: Add DT support Alexander Shiyan
2013-07-30 16:22 ` Olof Johansson
2013-07-30 17:59   ` Stephen Warren
2013-07-31 15:56     ` Mark Rutland
2013-08-05 15:35       ` Alexander Shiyan
2013-08-06 11:00       ` Pawel Moll
2013-08-07 14:07         ` Mark Rutland
2013-08-07 16:12           ` Stephen Warren
2013-08-08  9:11             ` Mark Rutland
2013-08-08 18:34               ` Stephen Warren
2013-08-09  3:21                 ` Grant Likely
2013-08-09  9:09                 ` Mark Rutland
2013-08-09 16:31                   ` Stephen Warren
2013-08-09 16:44                     ` Alexander Shiyan

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