aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-max732x.c
diff options
context:
space:
mode:
authorSemen Protsenko <semen.protsenko@globallogic.com>2015-01-13 08:41:42 -0500
committerLinus Walleij <linus.walleij@linaro.org>2015-01-15 11:49:25 -0500
commit43c4bcf9425ef596f9651bd0c647065dc5e9ad50 (patch)
tree9b93b8da2de7e75b1e9683f1b060de6ba512e5c8 /drivers/gpio/gpio-max732x.c
parentf28f8eff9148eb2a3a568cc378167ba28dd2f225 (diff)
gpio: max732x: Add device tree support
Signed-off-by: Semen Protsenko <semen.protsenko@globallogic.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-max732x.c')
-rw-r--r--drivers/gpio/gpio-max732x.c62
1 files changed, 51 insertions, 11 deletions
diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c
index 6c676225b886..a642f780901d 100644
--- a/drivers/gpio/gpio-max732x.c
+++ b/drivers/gpio/gpio-max732x.c
@@ -21,6 +21,7 @@
21#include <linux/irq.h> 21#include <linux/irq.h>
22#include <linux/i2c.h> 22#include <linux/i2c.h>
23#include <linux/i2c/max732x.h> 23#include <linux/i2c/max732x.h>
24#include <linux/of.h>
24 25
25 26
26/* 27/*
@@ -116,6 +117,22 @@ static const struct i2c_device_id max732x_id[] = {
116}; 117};
117MODULE_DEVICE_TABLE(i2c, max732x_id); 118MODULE_DEVICE_TABLE(i2c, max732x_id);
118 119
120#ifdef CONFIG_OF
121static const struct of_device_id max732x_of_table[] = {
122 { .compatible = "maxim,max7319" },
123 { .compatible = "maxim,max7320" },
124 { .compatible = "maxim,max7321" },
125 { .compatible = "maxim,max7322" },
126 { .compatible = "maxim,max7323" },
127 { .compatible = "maxim,max7324" },
128 { .compatible = "maxim,max7325" },
129 { .compatible = "maxim,max7326" },
130 { .compatible = "maxim,max7327" },
131 { }
132};
133MODULE_DEVICE_TABLE(of, max732x_of_table);
134#endif
135
119struct max732x_chip { 136struct max732x_chip {
120 struct gpio_chip gpio_chip; 137 struct gpio_chip gpio_chip;
121 138
@@ -457,10 +474,12 @@ static int max732x_irq_setup(struct max732x_chip *chip,
457 int has_irq = max732x_features[id->driver_data] >> 32; 474 int has_irq = max732x_features[id->driver_data] >> 32;
458 int ret; 475 int ret;
459 476
460 if (pdata->irq_base && has_irq != INT_NONE) { 477 if (((pdata && pdata->irq_base) || client->irq)
478 && has_irq != INT_NONE) {
461 int lvl; 479 int lvl;
462 480
463 chip->irq_base = pdata->irq_base; 481 if (pdata)
482 chip->irq_base = pdata->irq_base;
464 chip->irq_features = has_irq; 483 chip->irq_features = has_irq;
465 mutex_init(&chip->irq_lock); 484 mutex_init(&chip->irq_lock);
466 485
@@ -515,7 +534,7 @@ static int max732x_irq_setup(struct max732x_chip *chip,
515 struct max732x_platform_data *pdata = dev_get_platdata(&client->dev); 534 struct max732x_platform_data *pdata = dev_get_platdata(&client->dev);
516 int has_irq = max732x_features[id->driver_data] >> 32; 535 int has_irq = max732x_features[id->driver_data] >> 32;
517 536
518 if (pdata->irq_base && has_irq != INT_NONE) 537 if (((pdata && pdata->irq_base) || client->irq) && has_irq != INT_NONE)
519 dev_warn(&client->dev, "interrupt support not compiled in\n"); 538 dev_warn(&client->dev, "interrupt support not compiled in\n");
520 539
521 return 0; 540 return 0;
@@ -574,28 +593,47 @@ static int max732x_setup_gpio(struct max732x_chip *chip,
574 return port; 593 return port;
575} 594}
576 595
596static struct max732x_platform_data *of_gpio_max732x(struct device *dev)
597{
598 struct max732x_platform_data *pdata;
599
600 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
601 if (!pdata)
602 return NULL;
603
604 pdata->gpio_base = -1;
605
606 return pdata;
607}
608
577static int max732x_probe(struct i2c_client *client, 609static int max732x_probe(struct i2c_client *client,
578 const struct i2c_device_id *id) 610 const struct i2c_device_id *id)
579{ 611{
580 struct max732x_platform_data *pdata; 612 struct max732x_platform_data *pdata;
613 struct device_node *node;
581 struct max732x_chip *chip; 614 struct max732x_chip *chip;
582 struct i2c_client *c; 615 struct i2c_client *c;
583 uint16_t addr_a, addr_b; 616 uint16_t addr_a, addr_b;
584 int ret, nr_port; 617 int ret, nr_port;
585 618
586 pdata = dev_get_platdata(&client->dev); 619 pdata = dev_get_platdata(&client->dev);
587 if (pdata == NULL) { 620 node = client->dev.of_node;
621
622 if (!pdata && node)
623 pdata = of_gpio_max732x(&client->dev);
624
625 if (!pdata) {
588 dev_dbg(&client->dev, "no platform data\n"); 626 dev_dbg(&client->dev, "no platform data\n");
589 return -EINVAL; 627 return -EINVAL;
590 } 628 }
591 629
592 chip = devm_kzalloc(&client->dev, sizeof(struct max732x_chip), 630 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
593 GFP_KERNEL);
594 if (chip == NULL) 631 if (chip == NULL)
595 return -ENOMEM; 632 return -ENOMEM;
596 chip->client = client; 633 chip->client = client;
597 634
598 nr_port = max732x_setup_gpio(chip, id, pdata->gpio_base); 635 nr_port = max732x_setup_gpio(chip, id, pdata->gpio_base);
636 chip->gpio_chip.dev = &client->dev;
599 637
600 addr_a = (client->addr & 0x0f) | 0x60; 638 addr_a = (client->addr & 0x0f) | 0x60;
601 addr_b = (client->addr & 0x0f) | 0x50; 639 addr_b = (client->addr & 0x0f) | 0x50;
@@ -643,7 +681,7 @@ static int max732x_probe(struct i2c_client *client,
643 if (ret) 681 if (ret)
644 goto out_failed; 682 goto out_failed;
645 683
646 if (pdata->setup) { 684 if (pdata && pdata->setup) {
647 ret = pdata->setup(client, chip->gpio_chip.base, 685 ret = pdata->setup(client, chip->gpio_chip.base,
648 chip->gpio_chip.ngpio, pdata->context); 686 chip->gpio_chip.ngpio, pdata->context);
649 if (ret < 0) 687 if (ret < 0)
@@ -664,9 +702,10 @@ static int max732x_remove(struct i2c_client *client)
664{ 702{
665 struct max732x_platform_data *pdata = dev_get_platdata(&client->dev); 703 struct max732x_platform_data *pdata = dev_get_platdata(&client->dev);
666 struct max732x_chip *chip = i2c_get_clientdata(client); 704 struct max732x_chip *chip = i2c_get_clientdata(client);
667 int ret;
668 705
669 if (pdata->teardown) { 706 if (pdata && pdata->teardown) {
707 int ret;
708
670 ret = pdata->teardown(client, chip->gpio_chip.base, 709 ret = pdata->teardown(client, chip->gpio_chip.base,
671 chip->gpio_chip.ngpio, pdata->context); 710 chip->gpio_chip.ngpio, pdata->context);
672 if (ret < 0) { 711 if (ret < 0) {
@@ -689,8 +728,9 @@ static int max732x_remove(struct i2c_client *client)
689 728
690static struct i2c_driver max732x_driver = { 729static struct i2c_driver max732x_driver = {
691 .driver = { 730 .driver = {
692 .name = "max732x", 731 .name = "max732x",
693 .owner = THIS_MODULE, 732 .owner = THIS_MODULE,
733 .of_match_table = of_match_ptr(max732x_of_table),
694 }, 734 },
695 .probe = max732x_probe, 735 .probe = max732x_probe,
696 .remove = max732x_remove, 736 .remove = max732x_remove,