diff options
author | Florian Vaussard <florian.vaussard@epfl.ch> | 2012-09-05 03:46:25 -0400 |
---|---|---|
committer | Benoit Cousson <b-cousson@ti.com> | 2012-09-07 13:22:27 -0400 |
commit | f74ce8fb849e9f9c54a494cff5fc30d53ca4e963 (patch) | |
tree | 4136e8fc03d9aff1155a316c839f69f05f63d25a /drivers | |
parent | 5635121edb18cda14a60e4702f3ae53add5df894 (diff) |
gpio/twl4030: get platform data from device tree
Adds a number of missing device tree properties for
twl4030/gpio, and update bindings:
- "ti,use-leds" -> .use_leds
- "ti,debounce" -> .debounce
- "ti,mmc-cd" -> .mmc_cd
- "ti,pullups" -> .pullups
- "ti,pulldowns" -> .pulldowns
Signed-off-by: Florian Vaussard <florian.vaussard@epfl.ch>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Vaibhav Hiremath <hvaibhav@ti.com>
[b-cousson@ti.com: Fix some checkpatch CHECK issues]
Signed-off-by: Benoit Cousson <b-cousson@ti.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gpio/gpio-twl4030.c | 82 |
1 files changed, 55 insertions, 27 deletions
diff --git a/drivers/gpio/gpio-twl4030.c b/drivers/gpio/gpio-twl4030.c index 94256fe7bf36..f923252da839 100644 --- a/drivers/gpio/gpio-twl4030.c +++ b/drivers/gpio/gpio-twl4030.c | |||
@@ -395,6 +395,31 @@ static int __devinit gpio_twl4030_debounce(u32 debounce, u8 mmc_cd) | |||
395 | 395 | ||
396 | static int gpio_twl4030_remove(struct platform_device *pdev); | 396 | static int gpio_twl4030_remove(struct platform_device *pdev); |
397 | 397 | ||
398 | static struct twl4030_gpio_platform_data *of_gpio_twl4030(struct device *dev) | ||
399 | { | ||
400 | struct twl4030_gpio_platform_data *omap_twl_info; | ||
401 | |||
402 | omap_twl_info = devm_kzalloc(dev, sizeof(*omap_twl_info), GFP_KERNEL); | ||
403 | if (!omap_twl_info) | ||
404 | return NULL; | ||
405 | |||
406 | omap_twl_info->gpio_base = -1; | ||
407 | |||
408 | omap_twl_info->use_leds = of_property_read_bool(dev->of_node, | ||
409 | "ti,use-leds"); | ||
410 | |||
411 | of_property_read_u32(dev->of_node, "ti,debounce", | ||
412 | &omap_twl_info->debounce); | ||
413 | of_property_read_u32(dev->of_node, "ti,mmc-cd", | ||
414 | (u32 *)&omap_twl_info->mmc_cd); | ||
415 | of_property_read_u32(dev->of_node, "ti,pullups", | ||
416 | &omap_twl_info->pullups); | ||
417 | of_property_read_u32(dev->of_node, "ti,pulldowns", | ||
418 | &omap_twl_info->pulldowns); | ||
419 | |||
420 | return omap_twl_info; | ||
421 | } | ||
422 | |||
398 | static int __devinit gpio_twl4030_probe(struct platform_device *pdev) | 423 | static int __devinit gpio_twl4030_probe(struct platform_device *pdev) |
399 | { | 424 | { |
400 | struct twl4030_gpio_platform_data *pdata = pdev->dev.platform_data; | 425 | struct twl4030_gpio_platform_data *pdata = pdev->dev.platform_data; |
@@ -423,39 +448,42 @@ static int __devinit gpio_twl4030_probe(struct platform_device *pdev) | |||
423 | twl4030_gpio_irq_base = irq_base; | 448 | twl4030_gpio_irq_base = irq_base; |
424 | 449 | ||
425 | no_irqs: | 450 | no_irqs: |
426 | twl_gpiochip.base = -1; | ||
427 | twl_gpiochip.ngpio = TWL4030_GPIO_MAX; | 451 | twl_gpiochip.ngpio = TWL4030_GPIO_MAX; |
428 | twl_gpiochip.dev = &pdev->dev; | 452 | twl_gpiochip.dev = &pdev->dev; |
429 | 453 | ||
430 | if (pdata) { | 454 | if (node) |
431 | twl_gpiochip.base = pdata->gpio_base; | 455 | pdata = of_gpio_twl4030(&pdev->dev); |
432 | 456 | ||
433 | /* | 457 | if (pdata == NULL) { |
434 | * NOTE: boards may waste power if they don't set pullups | 458 | dev_err(&pdev->dev, "Platform data is missing\n"); |
435 | * and pulldowns correctly ... default for non-ULPI pins is | 459 | return -ENXIO; |
436 | * pulldown, and some other pins may have external pullups | ||
437 | * or pulldowns. Careful! | ||
438 | */ | ||
439 | ret = gpio_twl4030_pulls(pdata->pullups, pdata->pulldowns); | ||
440 | if (ret) | ||
441 | dev_dbg(&pdev->dev, "pullups %.05x %.05x --> %d\n", | ||
442 | pdata->pullups, pdata->pulldowns, | ||
443 | ret); | ||
444 | |||
445 | ret = gpio_twl4030_debounce(pdata->debounce, pdata->mmc_cd); | ||
446 | if (ret) | ||
447 | dev_dbg(&pdev->dev, "debounce %.03x %.01x --> %d\n", | ||
448 | pdata->debounce, pdata->mmc_cd, | ||
449 | ret); | ||
450 | |||
451 | /* | ||
452 | * NOTE: we assume VIBRA_CTL.VIBRA_EN, in MODULE_AUDIO_VOICE, | ||
453 | * is (still) clear if use_leds is set. | ||
454 | */ | ||
455 | if (pdata->use_leds) | ||
456 | twl_gpiochip.ngpio += 2; | ||
457 | } | 460 | } |
458 | 461 | ||
462 | twl_gpiochip.base = pdata->gpio_base; | ||
463 | |||
464 | /* | ||
465 | * NOTE: boards may waste power if they don't set pullups | ||
466 | * and pulldowns correctly ... default for non-ULPI pins is | ||
467 | * pulldown, and some other pins may have external pullups | ||
468 | * or pulldowns. Careful! | ||
469 | */ | ||
470 | ret = gpio_twl4030_pulls(pdata->pullups, pdata->pulldowns); | ||
471 | if (ret) | ||
472 | dev_dbg(&pdev->dev, "pullups %.05x %.05x --> %d\n", | ||
473 | pdata->pullups, pdata->pulldowns, ret); | ||
474 | |||
475 | ret = gpio_twl4030_debounce(pdata->debounce, pdata->mmc_cd); | ||
476 | if (ret) | ||
477 | dev_dbg(&pdev->dev, "debounce %.03x %.01x --> %d\n", | ||
478 | pdata->debounce, pdata->mmc_cd, ret); | ||
479 | |||
480 | /* | ||
481 | * NOTE: we assume VIBRA_CTL.VIBRA_EN, in MODULE_AUDIO_VOICE, | ||
482 | * is (still) clear if use_leds is set. | ||
483 | */ | ||
484 | if (pdata->use_leds) | ||
485 | twl_gpiochip.ngpio += 2; | ||
486 | |||
459 | ret = gpiochip_add(&twl_gpiochip); | 487 | ret = gpiochip_add(&twl_gpiochip); |
460 | if (ret < 0) { | 488 | if (ret < 0) { |
461 | dev_err(&pdev->dev, "could not register gpiochip, %d\n", ret); | 489 | dev_err(&pdev->dev, "could not register gpiochip, %d\n", ret); |