Commit bb2a95c2 authored by Axel Lin's avatar Axel Lin Committed by Anton Vorontsov

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: default avatarAxel Lin <axel.lin@gmail.com>
Signed-off-by: default avatarAnton Vorontsov <anton.vorontsov@linaro.org>
parent 534f5306
...@@ -134,12 +134,11 @@ static int get_batt_uV(struct charger_manager *cm, int *uV) ...@@ -134,12 +134,11 @@ static int get_batt_uV(struct charger_manager *cm, int *uV)
union power_supply_propval val; union power_supply_propval val;
int ret; int ret;
if (cm->fuel_gauge) if (!cm->fuel_gauge)
ret = cm->fuel_gauge->get_property(cm->fuel_gauge,
POWER_SUPPLY_PROP_VOLTAGE_NOW, &val);
else
return -ENODEV; return -ENODEV;
ret = cm->fuel_gauge->get_property(cm->fuel_gauge,
POWER_SUPPLY_PROP_VOLTAGE_NOW, &val);
if (ret) if (ret)
return ret; return ret;
...@@ -245,9 +244,7 @@ static int try_charger_enable(struct charger_manager *cm, bool enable) ...@@ -245,9 +244,7 @@ static int try_charger_enable(struct charger_manager *cm, bool enable)
struct charger_desc *desc = cm->desc; struct charger_desc *desc = cm->desc;
/* Ignore if it's redundent command */ /* Ignore if it's redundent command */
if (enable && cm->charger_enabled) if (enable == cm->charger_enabled)
return 0;
if (!enable && !cm->charger_enabled)
return 0; return 0;
if (enable) { if (enable) {
...@@ -309,9 +306,7 @@ static void uevent_notify(struct charger_manager *cm, const char *event) ...@@ -309,9 +306,7 @@ static void uevent_notify(struct charger_manager *cm, const char *event)
if (!strncmp(env_str_save, event, UEVENT_BUF_SIZE)) if (!strncmp(env_str_save, event, UEVENT_BUF_SIZE))
return; /* Duplicated. */ return; /* Duplicated. */
else strncpy(env_str_save, event, UEVENT_BUF_SIZE);
strncpy(env_str_save, event, UEVENT_BUF_SIZE);
return; return;
} }
...@@ -387,8 +382,10 @@ static bool cm_monitor(void) ...@@ -387,8 +382,10 @@ static bool cm_monitor(void)
mutex_lock(&cm_list_mtx); mutex_lock(&cm_list_mtx);
list_for_each_entry(cm, &cm_list, entry) list_for_each_entry(cm, &cm_list, entry) {
stop = stop || _cm_monitor(cm); if (_cm_monitor(cm))
stop = true;
}
mutex_unlock(&cm_list_mtx); mutex_unlock(&cm_list_mtx);
...@@ -697,8 +694,10 @@ bool cm_suspend_again(void) ...@@ -697,8 +694,10 @@ bool cm_suspend_again(void)
mutex_lock(&cm_list_mtx); mutex_lock(&cm_list_mtx);
list_for_each_entry(cm, &cm_list, entry) { list_for_each_entry(cm, &cm_list, entry) {
if (cm->status_save_ext_pwr_inserted != is_ext_pwr_online(cm) || if (cm->status_save_ext_pwr_inserted != is_ext_pwr_online(cm) ||
cm->status_save_batt != is_batt_present(cm)) cm->status_save_batt != is_batt_present(cm)) {
ret = false; ret = false;
break;
}
} }
mutex_unlock(&cm_list_mtx); mutex_unlock(&cm_list_mtx);
...@@ -855,11 +854,10 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -855,11 +854,10 @@ static int charger_manager_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, cm); platform_set_drvdata(pdev, cm);
memcpy(&cm->charger_psy, &psy_default, memcpy(&cm->charger_psy, &psy_default, sizeof(psy_default));
sizeof(psy_default));
if (!desc->psy_name) { if (!desc->psy_name) {
strncpy(cm->psy_name_buf, psy_default.name, strncpy(cm->psy_name_buf, psy_default.name, PSY_NAME_MAX);
PSY_NAME_MAX);
} else { } else {
strncpy(cm->psy_name_buf, desc->psy_name, PSY_NAME_MAX); strncpy(cm->psy_name_buf, desc->psy_name, PSY_NAME_MAX);
} }
...@@ -894,15 +892,15 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -894,15 +892,15 @@ static int charger_manager_probe(struct platform_device *pdev)
POWER_SUPPLY_PROP_CURRENT_NOW; POWER_SUPPLY_PROP_CURRENT_NOW;
cm->charger_psy.num_properties++; cm->charger_psy.num_properties++;
} }
if (!desc->measure_battery_temp) {
cm->charger_psy.properties[cm->charger_psy.num_properties] =
POWER_SUPPLY_PROP_TEMP_AMBIENT;
cm->charger_psy.num_properties++;
}
if (desc->measure_battery_temp) { if (desc->measure_battery_temp) {
cm->charger_psy.properties[cm->charger_psy.num_properties] = cm->charger_psy.properties[cm->charger_psy.num_properties] =
POWER_SUPPLY_PROP_TEMP; POWER_SUPPLY_PROP_TEMP;
cm->charger_psy.num_properties++; cm->charger_psy.num_properties++;
} else {
cm->charger_psy.properties[cm->charger_psy.num_properties] =
POWER_SUPPLY_PROP_TEMP_AMBIENT;
cm->charger_psy.num_properties++;
} }
ret = power_supply_register(NULL, &cm->charger_psy); ret = power_supply_register(NULL, &cm->charger_psy);
...@@ -933,9 +931,8 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -933,9 +931,8 @@ static int charger_manager_probe(struct platform_device *pdev)
return 0; return 0;
err_chg_enable: err_chg_enable:
if (desc->charger_regulators) regulator_bulk_free(desc->num_charger_regulators,
regulator_bulk_free(desc->num_charger_regulators, desc->charger_regulators);
desc->charger_regulators);
err_bulk_get: err_bulk_get:
power_supply_unregister(&cm->charger_psy); power_supply_unregister(&cm->charger_psy);
err_register: err_register:
...@@ -961,10 +958,8 @@ static int __devexit charger_manager_remove(struct platform_device *pdev) ...@@ -961,10 +958,8 @@ static int __devexit charger_manager_remove(struct platform_device *pdev)
list_del(&cm->entry); list_del(&cm->entry);
mutex_unlock(&cm_list_mtx); mutex_unlock(&cm_list_mtx);
if (desc->charger_regulators) regulator_bulk_free(desc->num_charger_regulators,
regulator_bulk_free(desc->num_charger_regulators, desc->charger_regulators);
desc->charger_regulators);
power_supply_unregister(&cm->charger_psy); power_supply_unregister(&cm->charger_psy);
kfree(cm->charger_psy.properties); kfree(cm->charger_psy.properties);
kfree(cm->charger_stat); kfree(cm->charger_stat);
...@@ -982,9 +977,7 @@ MODULE_DEVICE_TABLE(platform, charger_manager_id); ...@@ -982,9 +977,7 @@ MODULE_DEVICE_TABLE(platform, charger_manager_id);
static int cm_suspend_prepare(struct device *dev) static int cm_suspend_prepare(struct device *dev)
{ {
struct platform_device *pdev = container_of(dev, struct platform_device, struct charger_manager *cm = dev_get_drvdata(dev);
dev);
struct charger_manager *cm = platform_get_drvdata(pdev);
if (!cm_suspended) { if (!cm_suspended) {
if (rtc_dev) { if (rtc_dev) {
...@@ -1020,9 +1013,7 @@ static int cm_suspend_prepare(struct device *dev) ...@@ -1020,9 +1013,7 @@ static int cm_suspend_prepare(struct device *dev)
static void cm_suspend_complete(struct device *dev) static void cm_suspend_complete(struct device *dev)
{ {
struct platform_device *pdev = container_of(dev, struct platform_device, struct charger_manager *cm = dev_get_drvdata(dev);
dev);
struct charger_manager *cm = platform_get_drvdata(pdev);
if (cm_suspended) { if (cm_suspended) {
if (rtc_dev) { if (rtc_dev) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment