aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-em.c
diff options
context:
space:
mode:
authorMagnus Damm <damm@opensource.se>2013-02-26 08:26:23 -0500
committerGrant Likely <grant.likely@secretlab.ca>2013-03-05 20:12:26 -0500
commit753c5983ddd38022a680a36f5d66b23b185c9b62 (patch)
tree3caf63dd7f8579a0eda026edd1d4cbb5e57d6aa0 /drivers/gpio/gpio-em.c
parent8d4c277e185c31359cf70573d8b0351fb7dd0dfe (diff)
gpio/em: Add Device Tree support
Update the Emma Mobile GPIO driver to add DT support. The patch simply adds a two-cell xlate function and updates the probe code to allow configuration via DT using the "ngpios" property plus OF id in the same style as gpio-mvebu.c. The code is also adjusted to use postcore_initcall() to force early setup. Signed-off-by: Magnus Damm <damm@opensource.se> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/gpio/gpio-em.c')
-rw-r--r--drivers/gpio/gpio-em.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
index deca78f99316..d05369735857 100644
--- a/drivers/gpio/gpio-em.c
+++ b/drivers/gpio/gpio-em.c
@@ -231,10 +231,12 @@ static int em_gio_irq_domain_map(struct irq_domain *h, unsigned int virq,
231 231
232static struct irq_domain_ops em_gio_irq_domain_ops = { 232static struct irq_domain_ops em_gio_irq_domain_ops = {
233 .map = em_gio_irq_domain_map, 233 .map = em_gio_irq_domain_map,
234 .xlate = irq_domain_xlate_twocell,
234}; 235};
235 236
236static int em_gio_probe(struct platform_device *pdev) 237static int em_gio_probe(struct platform_device *pdev)
237{ 238{
239 struct gpio_em_config pdata_dt;
238 struct gpio_em_config *pdata = pdev->dev.platform_data; 240 struct gpio_em_config *pdata = pdev->dev.platform_data;
239 struct em_gio_priv *p; 241 struct em_gio_priv *p;
240 struct resource *io[2], *irq[2]; 242 struct resource *io[2], *irq[2];
@@ -259,8 +261,8 @@ static int em_gio_probe(struct platform_device *pdev)
259 irq[0] = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 261 irq[0] = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
260 irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1); 262 irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
261 263
262 if (!io[0] || !io[1] || !irq[0] || !irq[1] || !pdata) { 264 if (!io[0] || !io[1] || !irq[0] || !irq[1]) {
263 dev_err(&pdev->dev, "missing IRQ, IOMEM or configuration\n"); 265 dev_err(&pdev->dev, "missing IRQ or IOMEM\n");
264 ret = -EINVAL; 266 ret = -EINVAL;
265 goto err1; 267 goto err1;
266 } 268 }
@@ -279,6 +281,25 @@ static int em_gio_probe(struct platform_device *pdev)
279 goto err2; 281 goto err2;
280 } 282 }
281 283
284 if (!pdata) {
285 memset(&pdata_dt, 0, sizeof(pdata_dt));
286 pdata = &pdata_dt;
287
288 if (of_property_read_u32(pdev->dev.of_node, "ngpios",
289 &pdata->number_of_pins)) {
290 dev_err(&pdev->dev, "Missing ngpios OF property\n");
291 ret = -EINVAL;
292 goto err3;
293 }
294
295 ret = of_alias_get_id(pdev->dev.of_node, "gpio");
296 if (ret < 0) {
297 dev_err(&pdev->dev, "Couldn't get OF id\n");
298 goto err3;
299 }
300 pdata->gpio_base = ret * 32; /* 32 GPIOs per instance */
301 }
302
282 gpio_chip = &p->gpio_chip; 303 gpio_chip = &p->gpio_chip;
283 gpio_chip->direction_input = em_gio_direction_input; 304 gpio_chip->direction_input = em_gio_direction_input;
284 gpio_chip->get = em_gio_get; 305 gpio_chip->get = em_gio_get;
@@ -366,15 +387,33 @@ static int em_gio_remove(struct platform_device *pdev)
366 return 0; 387 return 0;
367} 388}
368 389
390static const struct of_device_id em_gio_dt_ids[] = {
391 { .compatible = "renesas,em-gio", },
392 {},
393};
394MODULE_DEVICE_TABLE(of, em_gio_dt_ids);
395
369static struct platform_driver em_gio_device_driver = { 396static struct platform_driver em_gio_device_driver = {
370 .probe = em_gio_probe, 397 .probe = em_gio_probe,
371 .remove = em_gio_remove, 398 .remove = em_gio_remove,
372 .driver = { 399 .driver = {
373 .name = "em_gio", 400 .name = "em_gio",
401 .of_match_table = em_gio_dt_ids,
402 .owner = THIS_MODULE,
374 } 403 }
375}; 404};
376 405
377module_platform_driver(em_gio_device_driver); 406static int __init em_gio_init(void)
407{
408 return platform_driver_register(&em_gio_device_driver);
409}
410postcore_initcall(em_gio_init);
411
412static void __exit em_gio_exit(void)
413{
414 platform_driver_unregister(&em_gio_device_driver);
415}
416module_exit(em_gio_exit);
378 417
379MODULE_AUTHOR("Magnus Damm"); 418MODULE_AUTHOR("Magnus Damm");
380MODULE_DESCRIPTION("Renesas Emma Mobile GIO Driver"); 419MODULE_DESCRIPTION("Renesas Emma Mobile GIO Driver");