From: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
patches-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org
Subject: [PATCH 2/2] gpio/mxc: add device tree probe support
Date: Sun, 3 Jul 2011 16:16:57 +0800 [thread overview]
Message-ID: <1309681017-22970-3-git-send-email-shawn.guo@linaro.org> (raw)
In-Reply-To: <1309681017-22970-1-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
The patch adds device tree probe support for gpio-mxc driver.
Signed-off-by: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
---
.../devicetree/bindings/gpio/fsl-imx-gpio.txt | 22 ++++++++++
drivers/gpio/gpio-mxc.c | 42 +++++++++++++++++++-
2 files changed, 63 insertions(+), 1 deletions(-)
create mode 100644 Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt
diff --git a/Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt b/Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt
new file mode 100644
index 0000000..4363ae4
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/fsl-imx-gpio.txt
@@ -0,0 +1,22 @@
+* Freescale i.MX/MXC GPIO controller
+
+Required properties:
+- compatible : Should be "fsl,<soc>-gpio"
+- reg : Address and length of the register set for the device
+- interrupts : Should be the port interrupt shared by all 32 pins, if
+ one number. If two numbers, the first one is the interrupt shared
+ by low 16 pins and the second one is for high 16 pins.
+- gpio-controller : Marks the device node as a gpio controller.
+- #gpio-cells : Should be two. The first cell is the pin number and
+ the second cell is used to specify optional parameters (currently
+ unused).
+
+Example:
+
+gpio0: gpio@73f84000 {
+ compatible = "fsl,imx51-gpio", "fsl,imx31-gpio";
+ reg = <0x73f84000 0x4000>;
+ interrupts = <50 51>;
+ gpio-controller;
+ #gpio-cells = <2>;
+};
diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index 7ae71d6..b42204f 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -27,6 +27,8 @@
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/basic_mmio_gpio.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
#include <asm-generic/bug.h>
enum mxc_gpio_type {
@@ -141,6 +143,13 @@ static struct platform_device_id mxc_gpio_devtype[] = {
}
};
+static const struct of_device_id mxc_gpio_dt_ids[] = {
+ { .compatible = "fsl,imx1-gpio", .data = &mxc_gpio_devdata[IMX1_GPIO], },
+ { .compatible = "fsl,imx2-gpio", .data = &mxc_gpio_devdata[IMX2_GPIO], },
+ { .compatible = "fsl,imx31-gpio", .data = &mxc_gpio_devdata[IMX_GPIO], },
+ { /* sentinel */ },
+};
+
/*
* MX2 has one interrupt *for all* gpio ports. The list is used
* to save the references to all ports, so that mx2_gpio_irq_handler
@@ -321,6 +330,33 @@ static void __init mxc_gpio_init_gc(struct mxc_gpio_port *port)
IRQ_NOREQUEST, 0);
}
+#ifdef CONFIG_OF
+static int mxc_gpio_probe_dt(struct mxc_gpio_port *port,
+ struct platform_device *pdev)
+{
+ struct device_node *np = pdev->dev.of_node;
+ const struct of_device_id *of_id =
+ of_match_device(mxc_gpio_dt_ids, &pdev->dev);
+
+ if (!np)
+ return -ENODEV;
+
+ pdev->id = of_alias_get_id(np, "gpio");
+ if (pdev->id < 0)
+ return -ENODEV;
+
+ port->devdata = of_id->data;
+
+ return 0;
+}
+#else
+static inline int mxc_gpio_probe_dt(struct mxc_gpio_port *port,
+ struct platform_device *pdev)
+{
+ return -ENODEV;
+}
+#endif
+
static int __devinit mxc_gpio_probe(struct platform_device *pdev)
{
struct mxc_gpio_port *port;
@@ -331,7 +367,10 @@ static int __devinit mxc_gpio_probe(struct platform_device *pdev)
if (!port)
return -ENOMEM;
- port->devdata = &mxc_gpio_devdata[pdev->id_entry->driver_data];
+ err = mxc_gpio_probe_dt(port, pdev);
+ if (err == -ENODEV)
+ port->devdata = &mxc_gpio_devdata[pdev->id_entry->driver_data];
+
port->virtual_irq_start = MXC_GPIO_IRQ_START + pdev->id * 32;
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -416,6 +455,7 @@ static struct platform_driver mxc_gpio_driver = {
.driver = {
.name = "gpio-mxc",
.owner = THIS_MODULE,
+ .of_match_table = mxc_gpio_dt_ids,
},
.probe = mxc_gpio_probe,
.id_table = mxc_gpio_devtype,
--
1.7.4.1
next prev parent reply other threads:[~2011-07-03 8:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-03 8:16 [PATCH 0/2] Add device tree probe for imx/mxc gpio Shawn Guo
[not found] ` <1309681017-22970-1-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2011-07-03 8:16 ` [PATCH 1/2] gpio/mxc: get rid of the uses of cpu_is_mx() Shawn Guo
[not found] ` <1309681017-22970-2-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2011-07-04 6:10 ` Grant Likely
2011-07-04 6:11 ` Grant Likely
[not found] ` <20110704061028.GE15152-e0URQFbLeQY2iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2011-07-04 16:56 ` Shawn Guo
[not found] ` <20110704165627.GA10594-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-07-04 16:59 ` Grant Likely
2011-07-04 6:46 ` Sascha Hauer
[not found] ` <20110704064603.GW6069-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2011-07-04 9:28 ` Shawn Guo
2011-07-04 9:49 ` Sascha Hauer
[not found] ` <20110704094921.GG6069-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2011-07-04 10:20 ` Shawn Guo
[not found] ` <20110704102008.GH10245-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-07-04 16:44 ` Sascha Hauer
[not found] ` <20110704164457.GJ6069-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2011-07-05 3:01 ` Shawn Guo
[not found] ` <20110705030121.GB10594-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-07-05 3:04 ` Grant Likely
[not found] ` <CACxGe6vHF-k+xCXAYwuQnuRXceD9eJC4ZpSbNXey8cnkX1J2-Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-07-05 3:32 ` Shawn Guo
[not found] ` <20110705033227.GC10594-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-07-05 16:42 ` Sascha Hauer
2011-07-06 5:21 ` Shawn Guo
[not found] ` <20110704092800.GG10245-+NayF8gZjK2ctlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2011-07-04 15:23 ` Grant Likely
2011-07-03 8:16 ` Shawn Guo [this message]
[not found] ` <1309681017-22970-3-git-send-email-shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2011-07-04 6:19 ` [PATCH 2/2] gpio/mxc: add device tree probe support Grant Likely
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=1309681017-22970-3-git-send-email-shawn.guo@linaro.org \
--to=shawn.guo-qsej5fyqhm4dnm+yrofe0a@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=patches-QSEj5FYQhm4dnm+yROfE0A@public.gmane.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).