diff options
author | Axel Lin <axel.lin@gmail.com> | 2012-01-11 23:56:35 -0500 |
---|---|---|
committer | Anton Vorontsov <anton.vorontsov@linaro.org> | 2012-03-26 12:41:19 -0400 |
commit | bb2a95c2d2450be1ac942adf6815375f620b7015 (patch) | |
tree | de8fdf6b7fc59f931de42468f32d1f9fc9c3ce57 /drivers/power/charger-manager.c | |
parent | 534f5306d701e2717b039898888bfbb8584186bd (diff) |
charger-manager: Clean up for better readability
This patch includes below changes:
* Some code change for better readability.
* Current code in probe already ensures desc->charger_regulators
is not NULL. No need to check if it is NULL or not before calling
regulator_bulk_free().
* Use dev_get_drvdata() in cm_suspend_prepare() and cm_suspend_complete()
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Diffstat (limited to 'drivers/power/charger-manager.c')
-rw-r--r-- | drivers/power/charger-manager.c | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c index 88fd9710bda2..e610e6b46b5b 100644 --- a/drivers/power/charger-manager.c +++ b/drivers/power/charger-manager.c | |||
@@ -134,12 +134,11 @@ static int get_batt_uV(struct charger_manager *cm, int *uV) | |||
134 | union power_supply_propval val; | 134 | union power_supply_propval val; |
135 | int ret; | 135 | int ret; |
136 | 136 | ||
137 | if (cm->fuel_gauge) | 137 | if (!cm->fuel_gauge) |
138 | ret = cm->fuel_gauge->get_property(cm->fuel_gauge, | ||
139 | POWER_SUPPLY_PROP_VOLTAGE_NOW, &val); | ||
140 | else | ||
141 | return -ENODEV; | 138 | return -ENODEV; |
142 | 139 | ||
140 | ret = cm->fuel_gauge->get_property(cm->fuel_gauge, | ||
141 | POWER_SUPPLY_PROP_VOLTAGE_NOW, &val); | ||
143 | if (ret) | 142 | if (ret) |
144 | return ret; | 143 | return ret; |
145 | 144 | ||
@@ -245,9 +244,7 @@ static int try_charger_enable(struct charger_manager *cm, bool enable) | |||
245 | struct charger_desc *desc = cm->desc; | 244 | struct charger_desc *desc = cm->desc; |
246 | 245 | ||
247 | /* Ignore if it's redundent command */ | 246 | /* Ignore if it's redundent command */ |
248 | if (enable && cm->charger_enabled) | 247 | if (enable == cm->charger_enabled) |
249 | return 0; | ||
250 | if (!enable && !cm->charger_enabled) | ||
251 | return 0; | 248 | return 0; |
252 | 249 | ||
253 | if (enable) { | 250 | if (enable) { |
@@ -309,9 +306,7 @@ static void uevent_notify(struct charger_manager *cm, const char *event) | |||
309 | 306 | ||
310 | if (!strncmp(env_str_save, event, UEVENT_BUF_SIZE)) | 307 | if (!strncmp(env_str_save, event, UEVENT_BUF_SIZE)) |
311 | return; /* Duplicated. */ | 308 | return; /* Duplicated. */ |
312 | else | 309 | strncpy(env_str_save, event, UEVENT_BUF_SIZE); |
313 | strncpy(env_str_save, event, UEVENT_BUF_SIZE); | ||
314 | |||
315 | return; | 310 | return; |
316 | } | 311 | } |
317 | 312 | ||
@@ -387,8 +382,10 @@ static bool cm_monitor(void) | |||
387 | 382 | ||
388 | mutex_lock(&cm_list_mtx); | 383 | mutex_lock(&cm_list_mtx); |
389 | 384 | ||
390 | list_for_each_entry(cm, &cm_list, entry) | 385 | list_for_each_entry(cm, &cm_list, entry) { |
391 | stop = stop || _cm_monitor(cm); | 386 | if (_cm_monitor(cm)) |
387 | stop = true; | ||
388 | } | ||
392 | 389 | ||
393 | mutex_unlock(&cm_list_mtx); | 390 | mutex_unlock(&cm_list_mtx); |
394 | 391 | ||
@@ -697,8 +694,10 @@ bool cm_suspend_again(void) | |||
697 | mutex_lock(&cm_list_mtx); | 694 | mutex_lock(&cm_list_mtx); |
698 | list_for_each_entry(cm, &cm_list, entry) { | 695 | list_for_each_entry(cm, &cm_list, entry) { |
699 | if (cm->status_save_ext_pwr_inserted != is_ext_pwr_online(cm) || | 696 | if (cm->status_save_ext_pwr_inserted != is_ext_pwr_online(cm) || |
700 | cm->status_save_batt != is_batt_present(cm)) | 697 | cm->status_save_batt != is_batt_present(cm)) { |
701 | ret = false; | 698 | ret = false; |
699 | break; | ||
700 | } | ||
702 | } | 701 | } |
703 | mutex_unlock(&cm_list_mtx); | 702 | mutex_unlock(&cm_list_mtx); |
704 | 703 | ||
@@ -855,11 +854,10 @@ static int charger_manager_probe(struct platform_device *pdev) | |||
855 | 854 | ||
856 | platform_set_drvdata(pdev, cm); | 855 | platform_set_drvdata(pdev, cm); |
857 | 856 | ||
858 | memcpy(&cm->charger_psy, &psy_default, | 857 | memcpy(&cm->charger_psy, &psy_default, sizeof(psy_default)); |
859 | sizeof(psy_default)); | 858 | |
860 | if (!desc->psy_name) { | 859 | if (!desc->psy_name) { |
861 | strncpy(cm->psy_name_buf, psy_default.name, | 860 | strncpy(cm->psy_name_buf, psy_default.name, PSY_NAME_MAX); |
862 | PSY_NAME_MAX); | ||
863 | } else { | 861 | } else { |
864 | strncpy(cm->psy_name_buf, desc->psy_name, PSY_NAME_MAX); | 862 | strncpy(cm->psy_name_buf, desc->psy_name, PSY_NAME_MAX); |
865 | } | 863 | } |
@@ -894,15 +892,15 @@ static int charger_manager_probe(struct platform_device *pdev) | |||
894 | POWER_SUPPLY_PROP_CURRENT_NOW; | 892 | POWER_SUPPLY_PROP_CURRENT_NOW; |
895 | cm->charger_psy.num_properties++; | 893 | cm->charger_psy.num_properties++; |
896 | } | 894 | } |
897 | if (!desc->measure_battery_temp) { | 895 | |
898 | cm->charger_psy.properties[cm->charger_psy.num_properties] = | ||
899 | POWER_SUPPLY_PROP_TEMP_AMBIENT; | ||
900 | cm->charger_psy.num_properties++; | ||
901 | } | ||
902 | if (desc->measure_battery_temp) { | 896 | if (desc->measure_battery_temp) { |
903 | cm->charger_psy.properties[cm->charger_psy.num_properties] = | 897 | cm->charger_psy.properties[cm->charger_psy.num_properties] = |
904 | POWER_SUPPLY_PROP_TEMP; | 898 | POWER_SUPPLY_PROP_TEMP; |
905 | cm->charger_psy.num_properties++; | 899 | cm->charger_psy.num_properties++; |
900 | } else { | ||
901 | cm->charger_psy.properties[cm->charger_psy.num_properties] = | ||
902 | POWER_SUPPLY_PROP_TEMP_AMBIENT; | ||
903 | cm->charger_psy.num_properties++; | ||
906 | } | 904 | } |
907 | 905 | ||
908 | ret = power_supply_register(NULL, &cm->charger_psy); | 906 | ret = power_supply_register(NULL, &cm->charger_psy); |
@@ -933,9 +931,8 @@ static int charger_manager_probe(struct platform_device *pdev) | |||
933 | return 0; | 931 | return 0; |
934 | 932 | ||
935 | err_chg_enable: | 933 | err_chg_enable: |
936 | if (desc->charger_regulators) | 934 | regulator_bulk_free(desc->num_charger_regulators, |
937 | regulator_bulk_free(desc->num_charger_regulators, | 935 | desc->charger_regulators); |
938 | desc->charger_regulators); | ||
939 | err_bulk_get: | 936 | err_bulk_get: |
940 | power_supply_unregister(&cm->charger_psy); | 937 | power_supply_unregister(&cm->charger_psy); |
941 | err_register: | 938 | err_register: |
@@ -961,10 +958,8 @@ static int __devexit charger_manager_remove(struct platform_device *pdev) | |||
961 | list_del(&cm->entry); | 958 | list_del(&cm->entry); |
962 | mutex_unlock(&cm_list_mtx); | 959 | mutex_unlock(&cm_list_mtx); |
963 | 960 | ||
964 | if (desc->charger_regulators) | 961 | regulator_bulk_free(desc->num_charger_regulators, |
965 | regulator_bulk_free(desc->num_charger_regulators, | 962 | desc->charger_regulators); |
966 | desc->charger_regulators); | ||
967 | |||
968 | power_supply_unregister(&cm->charger_psy); | 963 | power_supply_unregister(&cm->charger_psy); |
969 | kfree(cm->charger_psy.properties); | 964 | kfree(cm->charger_psy.properties); |
970 | kfree(cm->charger_stat); | 965 | kfree(cm->charger_stat); |
@@ -982,9 +977,7 @@ MODULE_DEVICE_TABLE(platform, charger_manager_id); | |||
982 | 977 | ||
983 | static int cm_suspend_prepare(struct device *dev) | 978 | static int cm_suspend_prepare(struct device *dev) |
984 | { | 979 | { |
985 | struct platform_device *pdev = container_of(dev, struct platform_device, | 980 | struct charger_manager *cm = dev_get_drvdata(dev); |
986 | dev); | ||
987 | struct charger_manager *cm = platform_get_drvdata(pdev); | ||
988 | 981 | ||
989 | if (!cm_suspended) { | 982 | if (!cm_suspended) { |
990 | if (rtc_dev) { | 983 | if (rtc_dev) { |
@@ -1020,9 +1013,7 @@ static int cm_suspend_prepare(struct device *dev) | |||
1020 | 1013 | ||
1021 | static void cm_suspend_complete(struct device *dev) | 1014 | static void cm_suspend_complete(struct device *dev) |
1022 | { | 1015 | { |
1023 | struct platform_device *pdev = container_of(dev, struct platform_device, | 1016 | struct charger_manager *cm = dev_get_drvdata(dev); |
1024 | dev); | ||
1025 | struct charger_manager *cm = platform_get_drvdata(pdev); | ||
1026 | 1017 | ||
1027 | if (cm_suspended) { | 1018 | if (cm_suspended) { |
1028 | if (rtc_dev) { | 1019 | if (rtc_dev) { |