diff options
-rw-r--r-- | Documentation/devicetree/bindings/power_supply/max17042_battery.txt | 18 | ||||
-rw-r--r-- | drivers/power/max17042_battery.c | 50 |
2 files changed, 67 insertions, 1 deletions
diff --git a/Documentation/devicetree/bindings/power_supply/max17042_battery.txt b/Documentation/devicetree/bindings/power_supply/max17042_battery.txt new file mode 100644 index 000000000000..5bc9b685cf8a --- /dev/null +++ b/Documentation/devicetree/bindings/power_supply/max17042_battery.txt | |||
@@ -0,0 +1,18 @@ | |||
1 | max17042_battery | ||
2 | ~~~~~~~~~~~~~~~~ | ||
3 | |||
4 | Required properties : | ||
5 | - compatible : "maxim,max17042" | ||
6 | |||
7 | Optional properties : | ||
8 | - maxim,rsns-microohm : Resistance of rsns resistor in micro Ohms | ||
9 | (datasheet-recommended value is 10000). | ||
10 | Defining this property enables current-sense functionality. | ||
11 | |||
12 | Example: | ||
13 | |||
14 | battery-charger@36 { | ||
15 | compatible = "maxim,max17042"; | ||
16 | reg = <0x36>; | ||
17 | maxim,rsns-microohm = <10000>; | ||
18 | }; | ||
diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c index 872e9b4a5ade..e36763a4f0f0 100644 --- a/drivers/power/max17042_battery.c +++ b/drivers/power/max17042_battery.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/mod_devicetable.h> | 31 | #include <linux/mod_devicetable.h> |
32 | #include <linux/power_supply.h> | 32 | #include <linux/power_supply.h> |
33 | #include <linux/power/max17042_battery.h> | 33 | #include <linux/power/max17042_battery.h> |
34 | #include <linux/of.h> | ||
34 | 35 | ||
35 | /* Status register bits */ | 36 | /* Status register bits */ |
36 | #define STATUS_POR_BIT (1 << 1) | 37 | #define STATUS_POR_BIT (1 << 1) |
@@ -608,6 +609,40 @@ static void max17042_init_worker(struct work_struct *work) | |||
608 | chip->init_complete = 1; | 609 | chip->init_complete = 1; |
609 | } | 610 | } |
610 | 611 | ||
612 | #ifdef CONFIG_OF | ||
613 | static struct max17042_platform_data * | ||
614 | max17042_get_pdata(struct device *dev) | ||
615 | { | ||
616 | struct device_node *np = dev->of_node; | ||
617 | u32 prop; | ||
618 | struct max17042_platform_data *pdata; | ||
619 | |||
620 | if (!np) | ||
621 | return dev->platform_data; | ||
622 | |||
623 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
624 | if (!pdata) | ||
625 | return NULL; | ||
626 | |||
627 | /* | ||
628 | * Require current sense resistor value to be specified for | ||
629 | * current-sense functionality to be enabled at all. | ||
630 | */ | ||
631 | if (of_property_read_u32(np, "maxim,rsns-microohm", &prop) == 0) { | ||
632 | pdata->r_sns = prop; | ||
633 | pdata->enable_current_sense = true; | ||
634 | } | ||
635 | |||
636 | return pdata; | ||
637 | } | ||
638 | #else | ||
639 | static struct max17042_platform_data * | ||
640 | max17042_get_pdata(struct device *dev) | ||
641 | { | ||
642 | return dev->platform_data; | ||
643 | } | ||
644 | #endif | ||
645 | |||
611 | static int __devinit max17042_probe(struct i2c_client *client, | 646 | static int __devinit max17042_probe(struct i2c_client *client, |
612 | const struct i2c_device_id *id) | 647 | const struct i2c_device_id *id) |
613 | { | 648 | { |
@@ -624,7 +659,11 @@ static int __devinit max17042_probe(struct i2c_client *client, | |||
624 | return -ENOMEM; | 659 | return -ENOMEM; |
625 | 660 | ||
626 | chip->client = client; | 661 | chip->client = client; |
627 | chip->pdata = client->dev.platform_data; | 662 | chip->pdata = max17042_get_pdata(&client->dev); |
663 | if (!chip->pdata) { | ||
664 | dev_err(&client->dev, "no platform data provided\n"); | ||
665 | return -EINVAL; | ||
666 | } | ||
628 | 667 | ||
629 | i2c_set_clientdata(client, chip); | 668 | i2c_set_clientdata(client, chip); |
630 | 669 | ||
@@ -689,6 +728,14 @@ static int __devexit max17042_remove(struct i2c_client *client) | |||
689 | return 0; | 728 | return 0; |
690 | } | 729 | } |
691 | 730 | ||
731 | #ifdef CONFIG_OF | ||
732 | static const struct of_device_id max17042_dt_match[] = { | ||
733 | { .compatible = "maxim,max17042" }, | ||
734 | { }, | ||
735 | }; | ||
736 | MODULE_DEVICE_TABLE(of, max17042_dt_match); | ||
737 | #endif | ||
738 | |||
692 | static const struct i2c_device_id max17042_id[] = { | 739 | static const struct i2c_device_id max17042_id[] = { |
693 | { "max17042", 0 }, | 740 | { "max17042", 0 }, |
694 | { } | 741 | { } |
@@ -698,6 +745,7 @@ MODULE_DEVICE_TABLE(i2c, max17042_id); | |||
698 | static struct i2c_driver max17042_i2c_driver = { | 745 | static struct i2c_driver max17042_i2c_driver = { |
699 | .driver = { | 746 | .driver = { |
700 | .name = "max17042", | 747 | .name = "max17042", |
748 | .of_match_table = of_match_ptr(max17042_dt_match), | ||
701 | }, | 749 | }, |
702 | .probe = max17042_probe, | 750 | .probe = max17042_probe, |
703 | .remove = __devexit_p(max17042_remove), | 751 | .remove = __devexit_p(max17042_remove), |