aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-mxs.c
diff options
context:
space:
mode:
authorShawn Guo <shawn.guo@linaro.org>2012-05-04 02:29:22 -0400
committerShawn Guo <shawn.guo@linaro.org>2012-05-12 01:32:19 -0400
commit4052d45e800ce33e1993fb70604941547ed73d26 (patch)
tree8cf84a968f897313a5db502239dbe9eaf45dd6aa /drivers/gpio/gpio-mxs.c
parent164387d2b4ae206f6275f5f6857aee74654918c4 (diff)
gpio/mxs: add device tree probe
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>
Diffstat (limited to 'drivers/gpio/gpio-mxs.c')
-rw-r--r--drivers/gpio/gpio-mxs.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c
index 38ae56f17916..429228b52acd 100644
--- a/drivers/gpio/gpio-mxs.c
+++ b/drivers/gpio/gpio-mxs.c
@@ -25,6 +25,9 @@
25#include <linux/io.h> 25#include <linux/io.h>
26#include <linux/irq.h> 26#include <linux/irq.h>
27#include <linux/gpio.h> 27#include <linux/gpio.h>
28#include <linux/of.h>
29#include <linux/of_address.h>
30#include <linux/of_device.h>
28#include <linux/platform_device.h> 31#include <linux/platform_device.h>
29#include <linux/slab.h> 32#include <linux/slab.h>
30#include <linux/basic_mmio_gpio.h> 33#include <linux/basic_mmio_gpio.h>
@@ -207,8 +210,19 @@ static struct platform_device_id mxs_gpio_ids[] = {
207}; 210};
208MODULE_DEVICE_TABLE(platform, mxs_gpio_ids); 211MODULE_DEVICE_TABLE(platform, mxs_gpio_ids);
209 212
213static const struct of_device_id mxs_gpio_dt_ids[] = {
214 { .compatible = "fsl,imx23-gpio", .data = (void *) IMX23_GPIO, },
215 { .compatible = "fsl,imx28-gpio", .data = (void *) IMX28_GPIO, },
216 { /* sentinel */ }
217};
218MODULE_DEVICE_TABLE(of, mxs_gpio_dt_ids);
219
210static int __devinit mxs_gpio_probe(struct platform_device *pdev) 220static int __devinit mxs_gpio_probe(struct platform_device *pdev)
211{ 221{
222 const struct of_device_id *of_id =
223 of_match_device(mxs_gpio_dt_ids, &pdev->dev);
224 struct device_node *np = pdev->dev.of_node;
225 struct device_node *parent;
212 static void __iomem *base; 226 static void __iomem *base;
213 struct mxs_gpio_port *port; 227 struct mxs_gpio_port *port;
214 struct resource *iores = NULL; 228 struct resource *iores = NULL;
@@ -218,8 +232,15 @@ static int __devinit mxs_gpio_probe(struct platform_device *pdev)
218 if (!port) 232 if (!port)
219 return -ENOMEM; 233 return -ENOMEM;
220 234
221 port->id = pdev->id; 235 if (np) {
222 port->devid = pdev->id_entry->driver_data; 236 port->id = of_alias_get_id(np, "gpio");
237 if (port->id < 0)
238 return port->id;
239 port->devid = (enum mxs_gpio_id) of_id->data;
240 } else {
241 port->id = pdev->id;
242 port->devid = pdev->id_entry->driver_data;
243 }
223 port->virtual_irq_start = MXS_GPIO_IRQ_START + port->id * 32; 244 port->virtual_irq_start = MXS_GPIO_IRQ_START + port->id * 32;
224 245
225 port->irq = platform_get_irq(pdev, 0); 246 port->irq = platform_get_irq(pdev, 0);
@@ -231,8 +252,14 @@ static int __devinit mxs_gpio_probe(struct platform_device *pdev)
231 * share the same one 252 * share the same one
232 */ 253 */
233 if (!base) { 254 if (!base) {
234 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 255 if (np) {
235 base = devm_request_and_ioremap(&pdev->dev, iores); 256 parent = of_get_parent(np);
257 base = of_iomap(parent, 0);
258 of_node_put(parent);
259 } else {
260 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
261 base = devm_request_and_ioremap(&pdev->dev, iores);
262 }
236 if (!base) 263 if (!base)
237 return -EADDRNOTAVAIL; 264 return -EADDRNOTAVAIL;
238 } 265 }
@@ -278,6 +305,7 @@ static struct platform_driver mxs_gpio_driver = {
278 .driver = { 305 .driver = {
279 .name = "gpio-mxs", 306 .name = "gpio-mxs",
280 .owner = THIS_MODULE, 307 .owner = THIS_MODULE,
308 .of_match_table = mxs_gpio_dt_ids,
281 }, 309 },
282 .probe = mxs_gpio_probe, 310 .probe = mxs_gpio_probe,
283 .id_table = mxs_gpio_ids, 311 .id_table = mxs_gpio_ids,