diff options
Diffstat (limited to 'drivers/power/88pm860x_battery.c')
-rw-r--r-- | drivers/power/88pm860x_battery.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/drivers/power/88pm860x_battery.c b/drivers/power/88pm860x_battery.c index a99d7f2829a7..d49579b227ec 100644 --- a/drivers/power/88pm860x_battery.c +++ b/drivers/power/88pm860x_battery.c | |||
@@ -98,7 +98,7 @@ struct pm860x_battery_info { | |||
98 | struct i2c_client *i2c; | 98 | struct i2c_client *i2c; |
99 | struct device *dev; | 99 | struct device *dev; |
100 | 100 | ||
101 | struct power_supply battery; | 101 | struct power_supply *battery; |
102 | struct mutex lock; | 102 | struct mutex lock; |
103 | int status; | 103 | int status; |
104 | int irq_cc; | 104 | int irq_cc; |
@@ -798,9 +798,8 @@ out: | |||
798 | 798 | ||
799 | static void pm860x_external_power_changed(struct power_supply *psy) | 799 | static void pm860x_external_power_changed(struct power_supply *psy) |
800 | { | 800 | { |
801 | struct pm860x_battery_info *info; | 801 | struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent); |
802 | 802 | ||
803 | info = container_of(psy, struct pm860x_battery_info, battery); | ||
804 | calc_resistor(info); | 803 | calc_resistor(info); |
805 | } | 804 | } |
806 | 805 | ||
@@ -808,7 +807,7 @@ static int pm860x_batt_get_prop(struct power_supply *psy, | |||
808 | enum power_supply_property psp, | 807 | enum power_supply_property psp, |
809 | union power_supply_propval *val) | 808 | union power_supply_propval *val) |
810 | { | 809 | { |
811 | struct pm860x_battery_info *info = dev_get_drvdata(psy->dev->parent); | 810 | struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent); |
812 | int data; | 811 | int data; |
813 | int ret; | 812 | int ret; |
814 | 813 | ||
@@ -874,7 +873,7 @@ static int pm860x_batt_set_prop(struct power_supply *psy, | |||
874 | enum power_supply_property psp, | 873 | enum power_supply_property psp, |
875 | const union power_supply_propval *val) | 874 | const union power_supply_propval *val) |
876 | { | 875 | { |
877 | struct pm860x_battery_info *info = dev_get_drvdata(psy->dev->parent); | 876 | struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent); |
878 | 877 | ||
879 | switch (psp) { | 878 | switch (psp) { |
880 | case POWER_SUPPLY_PROP_CHARGE_FULL: | 879 | case POWER_SUPPLY_PROP_CHARGE_FULL: |
@@ -901,6 +900,16 @@ static enum power_supply_property pm860x_batt_props[] = { | |||
901 | POWER_SUPPLY_PROP_TEMP, | 900 | POWER_SUPPLY_PROP_TEMP, |
902 | }; | 901 | }; |
903 | 902 | ||
903 | static const struct power_supply_desc pm860x_battery_desc = { | ||
904 | .name = "battery-monitor", | ||
905 | .type = POWER_SUPPLY_TYPE_BATTERY, | ||
906 | .properties = pm860x_batt_props, | ||
907 | .num_properties = ARRAY_SIZE(pm860x_batt_props), | ||
908 | .get_property = pm860x_batt_get_prop, | ||
909 | .set_property = pm860x_batt_set_prop, | ||
910 | .external_power_changed = pm860x_external_power_changed, | ||
911 | }; | ||
912 | |||
904 | static int pm860x_battery_probe(struct platform_device *pdev) | 913 | static int pm860x_battery_probe(struct platform_device *pdev) |
905 | { | 914 | { |
906 | struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); | 915 | struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); |
@@ -936,14 +945,6 @@ static int pm860x_battery_probe(struct platform_device *pdev) | |||
936 | 945 | ||
937 | pm860x_init_battery(info); | 946 | pm860x_init_battery(info); |
938 | 947 | ||
939 | info->battery.name = "battery-monitor"; | ||
940 | info->battery.type = POWER_SUPPLY_TYPE_BATTERY; | ||
941 | info->battery.properties = pm860x_batt_props; | ||
942 | info->battery.num_properties = ARRAY_SIZE(pm860x_batt_props); | ||
943 | info->battery.get_property = pm860x_batt_get_prop; | ||
944 | info->battery.set_property = pm860x_batt_set_prop; | ||
945 | info->battery.external_power_changed = pm860x_external_power_changed; | ||
946 | |||
947 | if (pdata && pdata->max_capacity) | 948 | if (pdata && pdata->max_capacity) |
948 | info->max_capacity = pdata->max_capacity; | 949 | info->max_capacity = pdata->max_capacity; |
949 | else | 950 | else |
@@ -953,10 +954,11 @@ static int pm860x_battery_probe(struct platform_device *pdev) | |||
953 | else | 954 | else |
954 | info->resistor = 300; /* set default internal resistor */ | 955 | info->resistor = 300; /* set default internal resistor */ |
955 | 956 | ||
956 | ret = power_supply_register(&pdev->dev, &info->battery, NULL); | 957 | info->battery = power_supply_register(&pdev->dev, &pm860x_battery_desc, |
957 | if (ret) | 958 | NULL); |
958 | return ret; | 959 | if (IS_ERR(info->battery)) |
959 | info->battery.dev->parent = &pdev->dev; | 960 | return PTR_ERR(info->battery); |
961 | info->battery->dev.parent = &pdev->dev; | ||
960 | 962 | ||
961 | ret = request_threaded_irq(info->irq_cc, NULL, | 963 | ret = request_threaded_irq(info->irq_cc, NULL, |
962 | pm860x_coulomb_handler, IRQF_ONESHOT, | 964 | pm860x_coulomb_handler, IRQF_ONESHOT, |
@@ -981,7 +983,7 @@ static int pm860x_battery_probe(struct platform_device *pdev) | |||
981 | out_coulomb: | 983 | out_coulomb: |
982 | free_irq(info->irq_cc, info); | 984 | free_irq(info->irq_cc, info); |
983 | out_reg: | 985 | out_reg: |
984 | power_supply_unregister(&info->battery); | 986 | power_supply_unregister(info->battery); |
985 | return ret; | 987 | return ret; |
986 | } | 988 | } |
987 | 989 | ||
@@ -991,7 +993,7 @@ static int pm860x_battery_remove(struct platform_device *pdev) | |||
991 | 993 | ||
992 | free_irq(info->irq_batt, info); | 994 | free_irq(info->irq_batt, info); |
993 | free_irq(info->irq_cc, info); | 995 | free_irq(info->irq_cc, info); |
994 | power_supply_unregister(&info->battery); | 996 | power_supply_unregister(info->battery); |
995 | return 0; | 997 | return 0; |
996 | } | 998 | } |
997 | 999 | ||