]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
gpio/mxs: add device tree probe
authorShawn Guo <shawn.guo@linaro.org>
Fri, 4 May 2012 06:29:22 +0000 (14:29 +0800)
committerShawn Guo <shawn.guo@linaro.org>
Sat, 12 May 2012 05:32:19 +0000 (13:32 +0800)
It adds device tree probe for gpio-mxs driver.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Documentation/devicetree/bindings/gpio/gpio-mxs.txt [new file with mode: 0644]
drivers/gpio/gpio-mxs.c

diff --git a/Documentation/devicetree/bindings/gpio/gpio-mxs.txt b/Documentation/devicetree/bindings/gpio/gpio-mxs.txt
new file mode 100644 (file)
index 0000000..0c35673
--- /dev/null
@@ -0,0 +1,87 @@
+* Freescale MXS GPIO controller
+
+The Freescale MXS GPIO controller is part of MXS PIN controller.  The
+GPIOs are organized in port/bank.  Each port consists of 32 GPIOs.
+
+As the GPIO controller is embedded in the PIN controller and all the
+GPIO ports share the same IO space with PIN controller, the GPIO node
+will be represented as sub-nodes of MXS pinctrl node.
+
+Required properties for GPIO node:
+- compatible : Should be "fsl,<soc>-gpio".  The supported SoCs include
+  imx23 and imx28.
+- interrupts : Should be the port interrupt shared by all 32 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).
+- interrupt-controller: Marks the device node as an interrupt controller.
+- #interrupt-cells : Should be 2.  The first cell is the GPIO number.
+  The second cell bits[3:0] is used to specify trigger type and level flags:
+      1 = low-to-high edge triggered.
+      2 = high-to-low edge triggered.
+      4 = active high level-sensitive.
+      8 = active low level-sensitive.
+
+Note: Each GPIO port should have an alias correctly numbered in "aliases"
+node.
+
+Examples:
+
+aliases {
+       gpio0 = &gpio0;
+       gpio1 = &gpio1;
+       gpio2 = &gpio2;
+       gpio3 = &gpio3;
+       gpio4 = &gpio4;
+};
+
+pinctrl@80018000 {
+       compatible = "fsl,imx28-pinctrl", "simple-bus";
+       reg = <0x80018000 2000>;
+
+       gpio0: gpio@0 {
+               compatible = "fsl,imx28-gpio";
+               interrupts = <127>;
+               gpio-controller;
+               #gpio-cells = <2>;
+               interrupt-controller;
+               #interrupt-cells = <2>;
+       };
+
+       gpio1: gpio@1 {
+               compatible = "fsl,imx28-gpio";
+               interrupts = <126>;
+               gpio-controller;
+               #gpio-cells = <2>;
+               interrupt-controller;
+               #interrupt-cells = <2>;
+       };
+
+       gpio2: gpio@2 {
+               compatible = "fsl,imx28-gpio";
+               interrupts = <125>;
+               gpio-controller;
+               #gpio-cells = <2>;
+               interrupt-controller;
+               #interrupt-cells = <2>;
+       };
+
+       gpio3: gpio@3 {
+               compatible = "fsl,imx28-gpio";
+               interrupts = <124>;
+               gpio-controller;
+               #gpio-cells = <2>;
+               interrupt-controller;
+               #interrupt-cells = <2>;
+       };
+
+       gpio4: gpio@4 {
+               compatible = "fsl,imx28-gpio";
+               interrupts = <123>;
+               gpio-controller;
+               #gpio-cells = <2>;
+               interrupt-controller;
+               #interrupt-cells = <2>;
+       };
+};
index 38ae56f17916b69ad6a530796eccadd1f7f10492..429228b52acd3757fd13c3462fd391637ddc54a8 100644 (file)
@@ -25,6 +25,9 @@
 #include <linux/io.h>
 #include <linux/irq.h>
 #include <linux/gpio.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/basic_mmio_gpio.h>
@@ -207,8 +210,19 @@ static struct platform_device_id mxs_gpio_ids[] = {
 };
 MODULE_DEVICE_TABLE(platform, mxs_gpio_ids);
 
+static const struct of_device_id mxs_gpio_dt_ids[] = {
+       { .compatible = "fsl,imx23-gpio", .data = (void *) IMX23_GPIO, },
+       { .compatible = "fsl,imx28-gpio", .data = (void *) IMX28_GPIO, },
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, mxs_gpio_dt_ids);
+
 static int __devinit mxs_gpio_probe(struct platform_device *pdev)
 {
+       const struct of_device_id *of_id =
+                       of_match_device(mxs_gpio_dt_ids, &pdev->dev);
+       struct device_node *np = pdev->dev.of_node;
+       struct device_node *parent;
        static void __iomem *base;
        struct mxs_gpio_port *port;
        struct resource *iores = NULL;
@@ -218,8 +232,15 @@ static int __devinit mxs_gpio_probe(struct platform_device *pdev)
        if (!port)
                return -ENOMEM;
 
-       port->id = pdev->id;
-       port->devid = pdev->id_entry->driver_data;
+       if (np) {
+               port->id = of_alias_get_id(np, "gpio");
+               if (port->id < 0)
+                       return port->id;
+               port->devid = (enum mxs_gpio_id) of_id->data;
+       } else {
+               port->id = pdev->id;
+               port->devid = pdev->id_entry->driver_data;
+       }
        port->virtual_irq_start = MXS_GPIO_IRQ_START + port->id * 32;
 
        port->irq = platform_get_irq(pdev, 0);
@@ -231,8 +252,14 @@ static int __devinit mxs_gpio_probe(struct platform_device *pdev)
         * share the same one
         */
        if (!base) {
-               iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-               base = devm_request_and_ioremap(&pdev->dev, iores);
+               if (np) {
+                       parent = of_get_parent(np);
+                       base = of_iomap(parent, 0);
+                       of_node_put(parent);
+               } else {
+                       iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+                       base = devm_request_and_ioremap(&pdev->dev, iores);
+               }
                if (!base)
                        return -EADDRNOTAVAIL;
        }
@@ -278,6 +305,7 @@ static struct platform_driver mxs_gpio_driver = {
        .driver         = {
                .name   = "gpio-mxs",
                .owner  = THIS_MODULE,
+               .of_match_table = mxs_gpio_dt_ids,
        },
        .probe          = mxs_gpio_probe,
        .id_table       = mxs_gpio_ids,