diff options
-rw-r--r-- | Documentation/devicetree/bindings/power_supply/ti_bq20z75.txt | 23 | ||||
-rw-r--r-- | drivers/power/bq20z75.c | 77 |
2 files changed, 100 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/power_supply/ti_bq20z75.txt b/Documentation/devicetree/bindings/power_supply/ti_bq20z75.txt new file mode 100644 index 000000000000..7571294f4110 --- /dev/null +++ b/Documentation/devicetree/bindings/power_supply/ti_bq20z75.txt | |||
@@ -0,0 +1,23 @@ | |||
1 | TI bq20z75 | ||
2 | ~~~~~~~~~~ | ||
3 | |||
4 | Required properties : | ||
5 | - compatible : "ti,bq20z75" | ||
6 | |||
7 | Optional properties : | ||
8 | - ti,i2c-retry-count : The number of times to retry i2c transactions on i2c | ||
9 | IO failure. | ||
10 | - ti,poll-retry-count : The number of times to try looking for new status | ||
11 | after an external change notification. | ||
12 | - ti,battery-detect-gpios : The gpio which signals battery detection and | ||
13 | a flag specifying its polarity. | ||
14 | |||
15 | Example: | ||
16 | |||
17 | bq20z75@b { | ||
18 | compatible = "ti,bq20z75"; | ||
19 | reg = < 0xb >; | ||
20 | ti,i2c-retry-count = <2>; | ||
21 | ti,poll-retry-count = <10>; | ||
22 | ti,battery-detect-gpios = <&gpio-controller 122 1>; | ||
23 | } | ||
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 | ||