From patchwork Sun Jul 3 08:16:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 940762 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6387CrF022285 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 3 Jul 2011 08:07:33 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QdHhd-0000vp-Dc; Sun, 03 Jul 2011 08:06:55 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QdHhX-0000zp-VO; Sun, 03 Jul 2011 08:06:47 +0000 Received: from mail-iy0-f177.google.com ([209.85.210.177]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QdHhL-0000vo-Lh for linux-arm-kernel@lists.infradead.org; Sun, 03 Jul 2011 08:06:36 +0000 Received: by mail-iy0-f177.google.com with SMTP id 15so4665225iyn.36 for ; Sun, 03 Jul 2011 01:06:35 -0700 (PDT) Received: by 10.42.243.9 with SMTP id lk9mr5449735icb.207.1309680395248; Sun, 03 Jul 2011 01:06:35 -0700 (PDT) Received: from localhost.localdomain ([114.218.201.201]) by mx.google.com with ESMTPS id vn4sm5177441icb.7.2011.07.03.01.06.22 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 03 Jul 2011 01:06:34 -0700 (PDT) From: Shawn Guo To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/2] gpio/mxc: add device tree probe support Date: Sun, 3 Jul 2011 16:16:57 +0800 Message-Id: <1309681017-22970-3-git-send-email-shawn.guo@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1309681017-22970-1-git-send-email-shawn.guo@linaro.org> References: <1309681017-22970-1-git-send-email-shawn.guo@linaro.org> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110703_040635_866953_ED025811 X-CRM114-Status: GOOD ( 19.70 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.210.177 listed in list.dnswl.org] Cc: Grant Likely , devicetree-discuss@lists.ozlabs.org, Shawn Guo , patches@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sun, 03 Jul 2011 08:07:33 +0000 (UTC) The patch adds device tree probe support for gpio-mxc driver. Signed-off-by: Shawn Guo Cc: Grant Likely --- .../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,-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 #include #include +#include +#include #include 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,