Skip to content

Commit b8589e2

Browse files
Benoit CoussonSamuel Ortiz
authored andcommitted
gpio/twl: Add DT support to gpio-twl4030 driver
Add the DT support for the I2C GPIO expander inside the twl4030. Note: The pdata parameters still have to be properly adapted using dedicated bindings. Signed-off-by: Benoit Cousson <b-cousson@ti.com> Acked-by: Felipe Balbi <balbi@ti.com> Acked-by: Grant Likely <grant.likely@secretlab.ca> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 2d9dd99 commit b8589e2

2 files changed

Lines changed: 73 additions & 29 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
twl4030 GPIO controller bindings
2+
3+
Required properties:
4+
- compatible:
5+
- "ti,twl4030-gpio" for twl4030 GPIO controller
6+
- #gpio-cells : Should be two.
7+
- first cell is the pin number
8+
- second cell is used to specify optional parameters (unused)
9+
- gpio-controller : Marks the device node as a GPIO controller.
10+
- #interrupt-cells : Should be 2.
11+
- interrupt-controller: Mark the device node as an interrupt controller
12+
The first cell is the GPIO number.
13+
The second cell is not used.
14+
15+
Example:
16+
17+
twl_gpio: gpio {
18+
compatible = "ti,twl4030-gpio";
19+
#gpio-cells = <2>;
20+
gpio-controller;
21+
#interrupt-cells = <2>;
22+
interrupt-controller;
23+
};

‎drivers/gpio/gpio-twl4030.c‎

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <linux/irq.h>
3333
#include <linux/gpio.h>
3434
#include <linux/platform_device.h>
35+
#include <linux/of.h>
36+
#include <linux/irqdomain.h>
3537

3638
#include <linux/i2c/twl.h>
3739

@@ -256,7 +258,8 @@ static int twl_request(struct gpio_chip *chip, unsigned offset)
256258
* and vMMC2 power supplies based on card presence.
257259
*/
258260
pdata = chip->dev->platform_data;
259-
value |= pdata->mmc_cd & 0x03;
261+
if (pdata)
262+
value |= pdata->mmc_cd & 0x03;
260263

261264
status = gpio_twl4030_write(REG_GPIO_CTRL, value);
262265
}
@@ -395,6 +398,7 @@ static int gpio_twl4030_remove(struct platform_device *pdev);
395398
static int __devinit gpio_twl4030_probe(struct platform_device *pdev)
396399
{
397400
struct twl4030_gpio_platform_data *pdata = pdev->dev.platform_data;
401+
struct device_node *node = pdev->dev.of_node;
398402
int ret, irq_base;
399403

400404
/* maybe setup IRQs */
@@ -409,47 +413,55 @@ static int __devinit gpio_twl4030_probe(struct platform_device *pdev)
409413
return irq_base;
410414
}
411415

416+
irq_domain_add_legacy(node, TWL4030_GPIO_MAX, irq_base, 0,
417+
&irq_domain_simple_ops, NULL);
418+
412419
ret = twl4030_sih_setup(&pdev->dev, TWL4030_MODULE_GPIO, irq_base);
413420
if (ret < 0)
414421
return ret;
415422

416423
twl4030_gpio_irq_base = irq_base;
417424

418425
no_irqs:
419-
/*
420-
* NOTE: boards may waste power if they don't set pullups
421-
* and pulldowns correctly ... default for non-ULPI pins is
422-
* pulldown, and some other pins may have external pullups
423-
* or pulldowns. Careful!
424-
*/
425-
ret = gpio_twl4030_pulls(pdata->pullups, pdata->pulldowns);
426-
if (ret)
427-
dev_dbg(&pdev->dev, "pullups %.05x %.05x --> %d\n",
428-
pdata->pullups, pdata->pulldowns,
429-
ret);
430-
431-
ret = gpio_twl4030_debounce(pdata->debounce, pdata->mmc_cd);
432-
if (ret)
433-
dev_dbg(&pdev->dev, "debounce %.03x %.01x --> %d\n",
434-
pdata->debounce, pdata->mmc_cd,
435-
ret);
436-
437-
twl_gpiochip.base = pdata->gpio_base;
426+
twl_gpiochip.base = -1;
438427
twl_gpiochip.ngpio = TWL4030_GPIO_MAX;
439428
twl_gpiochip.dev = &pdev->dev;
440429

441-
/* NOTE: we assume VIBRA_CTL.VIBRA_EN, in MODULE_AUDIO_VOICE,
442-
* is (still) clear if use_leds is set.
443-
*/
444-
if (pdata->use_leds)
445-
twl_gpiochip.ngpio += 2;
430+
if (pdata) {
431+
twl_gpiochip.base = pdata->gpio_base;
432+
433+
/*
434+
* NOTE: boards may waste power if they don't set pullups
435+
* and pulldowns correctly ... default for non-ULPI pins is
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+
}
446458

447459
ret = gpiochip_add(&twl_gpiochip);
448460
if (ret < 0) {
449461
dev_err(&pdev->dev, "could not register gpiochip, %d\n", ret);
450462
twl_gpiochip.ngpio = 0;
451463
gpio_twl4030_remove(pdev);
452-
} else if (pdata->setup) {
464+
} else if (pdata && pdata->setup) {
453465
int status;
454466

455467
status = pdata->setup(&pdev->dev,
@@ -467,7 +479,7 @@ static int gpio_twl4030_remove(struct platform_device *pdev)
467479
struct twl4030_gpio_platform_data *pdata = pdev->dev.platform_data;
468480
int status;
469481

470-
if (pdata->teardown) {
482+
if (pdata && pdata->teardown) {
471483
status = pdata->teardown(&pdev->dev,
472484
pdata->gpio_base, TWL4030_GPIO_MAX);
473485
if (status) {
@@ -488,12 +500,21 @@ static int gpio_twl4030_remove(struct platform_device *pdev)
488500
return -EIO;
489501
}
490502

503+
static const struct of_device_id twl_gpio_match[] = {
504+
{ .compatible = "ti,twl4030-gpio", },
505+
{ },
506+
};
507+
MODULE_DEVICE_TABLE(of, twl_gpio_match);
508+
491509
/* Note: this hardware lives inside an I2C-based multi-function device. */
492510
MODULE_ALIAS("platform:twl4030_gpio");
493511

494512
static struct platform_driver gpio_twl4030_driver = {
495-
.driver.name = "twl4030_gpio",
496-
.driver.owner = THIS_MODULE,
513+
.driver = {
514+
.name = "twl4030_gpio",
515+
.owner = THIS_MODULE,
516+
.of_match_table = of_match_ptr(twl_gpio_match),
517+
},
497518
.probe = gpio_twl4030_probe,
498519
.remove = gpio_twl4030_remove,
499520
};

0 commit comments

Comments
 (0)