diff options
author | Rhyland Klein <rklein@nvidia.com> | 2011-09-14 16:19:07 -0400 |
---|---|---|
committer | Anton Vorontsov <cbouatmailru@gmail.com> | 2011-11-24 13:39:17 -0500 |
commit | 6c75ea1e582d12120072cae742a0d63ea8ac8c65 (patch) | |
tree | e7d83460d58069ba6e3e664408a03a69db2ccaf9 /drivers/power/bq20z75.c | |
parent | 85b5fbf784810d80aa09646189848c9ebc8a4ba2 (diff) |
bq20z75: Devicetree init support
Adding support to generate platform data when kernel is configured
through device tree.
Also adding the binding for the TI bq20z75 fuel gadge and the
bq20z75 driver.
Signed-off-by: Rhyland Klein <rklein@nvidia.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Diffstat (limited to 'drivers/power/bq20z75.c')
-rw-r--r-- | drivers/power/bq20z75.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/drivers/power/bq20z75.c b/drivers/power/bq20z75.c index 9c5e5beda3a8..ce95ff791016 100644 --- a/drivers/power/bq20z75.c +++ b/drivers/power/bq20z75.c | |||
@@ -613,6 +613,80 @@ static void bq20z75_delayed_work(struct work_struct *work) | |||
613 | } | 613 | } |
614 | } | 614 | } |
615 | 615 | ||
616 | #if defined(CONFIG_OF) | ||
617 | |||
618 | #include <linux/of_device.h> | ||
619 | #include <linux/of_gpio.h> | ||
620 | |||
621 | static const struct of_device_id bq20z75_dt_ids[] = { | ||
622 | { .compatible = "ti,bq20z75" }, | ||
623 | { } | ||
624 | }; | ||
625 | MODULE_DEVICE_TABLE(i2c, bq20z75_dt_ids); | ||
626 | |||
627 | static struct bq20z75_platform_data *bq20z75_of_populate_pdata( | ||
628 | struct i2c_client *client) | ||
629 | { | ||
630 | struct device_node *of_node = client->dev.of_node; | ||
631 | struct bq20z75_platform_data *pdata = client->dev.platform_data; | ||
632 | enum of_gpio_flags gpio_flags; | ||
633 | int rc; | ||
634 | u32 prop; | ||
635 | |||
636 | /* verify this driver matches this device */ | ||
637 | if (!of_node) | ||
638 | return NULL; | ||
639 | |||
640 | /* if platform data is set, honor it */ | ||
641 | if (pdata) | ||
642 | return pdata; | ||
643 | |||
644 | /* first make sure at least one property is set, otherwise | ||
645 | * it won't change behavior from running without pdata. | ||
646 | */ | ||
647 | if (!of_get_property(of_node, "ti,i2c-retry-count", NULL) && | ||
648 | !of_get_property(of_node, "ti,poll-retry-count", NULL) && | ||
649 | !of_get_property(of_node, "ti,battery-detect-gpios", NULL)) | ||
650 | goto of_out; | ||
651 | |||
652 | pdata = devm_kzalloc(&client->dev, sizeof(struct bq20z75_platform_data), | ||
653 | GFP_KERNEL); | ||
654 | if (!pdata) | ||
655 | goto of_out; | ||
656 | |||
657 | rc = of_property_read_u32(of_node, "ti,i2c-retry-count", &prop); | ||
658 | if (!rc) | ||
659 | pdata->i2c_retry_count = prop; | ||
660 | |||
661 | rc = of_property_read_u32(of_node, "ti,poll-retry-count", &prop); | ||
662 | if (!rc) | ||
663 | pdata->poll_retry_count = prop; | ||
664 | |||
665 | if (!of_get_property(of_node, "ti,battery-detect-gpios", NULL)) { | ||
666 | pdata->battery_detect = -1; | ||
667 | goto of_out; | ||
668 | } | ||
669 | |||
670 | pdata->battery_detect = of_get_named_gpio_flags(of_node, | ||
671 | "ti,battery-detect-gpios", 0, &gpio_flags); | ||
672 | |||
673 | if (gpio_flags & OF_GPIO_ACTIVE_LOW) | ||
674 | pdata->battery_detect_present = 0; | ||
675 | else | ||
676 | pdata->battery_detect_present = 1; | ||
677 | |||
678 | of_out: | ||
679 | return pdata; | ||
680 | } | ||
681 | #else | ||
682 | #define bq20z75_dt_ids NULL | ||
683 | static struct bq20z75_platform_data *bq20z75_of_populate_pdata( | ||
684 | struct i2c_client *client) | ||
685 | { | ||
686 | return client->dev.platform_data; | ||
687 | } | ||
688 | #endif | ||
689 | |||
616 | static int __devinit bq20z75_probe(struct i2c_client *client, | 690 | static int __devinit bq20z75_probe(struct i2c_client *client, |
617 | const struct i2c_device_id *id) | 691 | const struct i2c_device_id *id) |
618 | { | 692 | { |
@@ -642,6 +716,8 @@ static int __devinit bq20z75_probe(struct i2c_client *client, | |||
642 | bq20z75_device->power_supply.external_power_changed = | 716 | bq20z75_device->power_supply.external_power_changed = |
643 | bq20z75_external_power_changed; | 717 | bq20z75_external_power_changed; |
644 | 718 | ||
719 | pdata = bq20z75_of_populate_pdata(client); | ||
720 | |||
645 | if (pdata) { | 721 | if (pdata) { |
646 | bq20z75_device->gpio_detect = | 722 | bq20z75_device->gpio_detect = |
647 | gpio_is_valid(pdata->battery_detect); | 723 | gpio_is_valid(pdata->battery_detect); |
@@ -775,6 +851,7 @@ static struct i2c_driver bq20z75_battery_driver = { | |||
775 | .id_table = bq20z75_id, | 851 | .id_table = bq20z75_id, |
776 | .driver = { | 852 | .driver = { |
777 | .name = "bq20z75-battery", | 853 | .name = "bq20z75-battery", |
854 | .of_match_table = bq20z75_dt_ids, | ||
778 | }, | 855 | }, |
779 | }; | 856 | }; |
780 | 857 | ||