@@ -764,28 +764,12 @@ static int charger_get_property(struct power_supply *psy,
val->intval = 0;
break;
case POWER_SUPPLY_PROP_CHARGE_FULL:
- if (is_full_charged(cm))
- val->intval = 1;
- else
- val->intval = 0;
- ret = 0;
+ ret = cm->fuel_gauge->get_property(cm->fuel_gauge,
+ POWER_SUPPLY_PROP_CHARGE_FULL, val);
break;
case POWER_SUPPLY_PROP_CHARGE_NOW:
- if (is_charging(cm)) {
- ret = cm->fuel_gauge->get_property(cm->fuel_gauge,
- POWER_SUPPLY_PROP_CHARGE_NOW,
- val);
- if (ret) {
- val->intval = 1;
- ret = 0;
- } else {
- /* If CHARGE_NOW is supplied, use it */
- val->intval = (val->intval > 0) ?
- val->intval : 1;
- }
- } else {
- val->intval = 0;
- }
+ ret = cm->fuel_gauge->get_property(cm->fuel_gauge,
+ POWER_SUPPLY_PROP_CHARGE_NOW, val);
break;
default:
return -EINVAL;
@@ -793,8 +777,7 @@ static int charger_get_property(struct power_supply *psy,
return ret;
}
-#define NUM_CHARGER_PSY_OPTIONAL (4)
-static enum power_supply_property default_charger_props[] = {
+static enum power_supply_property cm_default_props[] = {
/* Guaranteed to provide */
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_HEALTH,
@@ -802,20 +785,21 @@ static enum power_supply_property default_charger_props[] = {
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_ONLINE,
- POWER_SUPPLY_PROP_CHARGE_FULL,
POWER_SUPPLY_PROP_TEMP,
- /*
- * Optional properties are:
- * POWER_SUPPLY_PROP_CHARGE_NOW,
- * POWER_SUPPLY_PROP_CURRENT_NOW,
- */
};
+static enum power_supply_property cm_optional_props[] = {
+ POWER_SUPPLY_PROP_CHARGE_FULL,
+ POWER_SUPPLY_PROP_CHARGE_NOW,
+ POWER_SUPPLY_PROP_CURRENT_NOW,
+};
+
+#define CM_NUM_OF_PROPS \
+ (ARRAY_SIZE(cm_default_props) + ARRAY_SIZE(cm_optional_props))
+
static struct power_supply psy_default = {
.name = "battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
- .properties = default_charger_props,
- .num_properties = ARRAY_SIZE(default_charger_props),
.get_property = charger_get_property,
};
@@ -1328,6 +1312,18 @@ static inline struct charger_desc *cm_get_drv_data(struct platform_device *pdev)
return (struct charger_desc *)dev_get_platdata(&pdev->dev);
}
+static void cm_test_and_add_property(struct charger_manager *cm,
+ enum power_supply_property psp)
+{
+ union power_supply_propval val;
+
+ if (cm->fuel_gauge->get_property(cm->fuel_gauge, psp, &val))
+ return;
+
+ cm->charger_psy.properties[cm->charger_psy.num_properties] = psp;
+ cm->charger_psy.num_properties++;
+}
+
static enum alarmtimer_restart cm_timer_func(struct alarm *alarm, ktime_t now)
{
cm_timer_set = false;
@@ -1340,7 +1336,6 @@ static int charger_manager_probe(struct platform_device *pdev)
struct charger_manager *cm;
int ret = 0, i = 0;
int j = 0;
- union power_supply_propval val;
if (!desc) {
dev_err(&pdev->dev, "No platform data (desc) found\n");
@@ -1442,30 +1437,17 @@ static int charger_manager_probe(struct platform_device *pdev)
/* Allocate for psy properties because they may vary */
cm->charger_psy.properties = devm_kzalloc(&pdev->dev,
sizeof(enum power_supply_property)
- * (ARRAY_SIZE(default_charger_props) +
- NUM_CHARGER_PSY_OPTIONAL), GFP_KERNEL);
+ * CM_NUM_OF_PROPS, GFP_KERNEL);
if (!cm->charger_psy.properties)
return -ENOMEM;
- memcpy(cm->charger_psy.properties, default_charger_props,
- sizeof(enum power_supply_property) *
- ARRAY_SIZE(default_charger_props));
- cm->charger_psy.num_properties = psy_default.num_properties;
-
- /* Find which optional psy-properties are available */
- if (!cm->fuel_gauge->get_property(cm->fuel_gauge,
- POWER_SUPPLY_PROP_CHARGE_NOW, &val)) {
- cm->charger_psy.properties[cm->charger_psy.num_properties] =
- POWER_SUPPLY_PROP_CHARGE_NOW;
- cm->charger_psy.num_properties++;
- }
- if (!cm->fuel_gauge->get_property(cm->fuel_gauge,
- POWER_SUPPLY_PROP_CURRENT_NOW,
- &val)) {
- cm->charger_psy.properties[cm->charger_psy.num_properties] =
- POWER_SUPPLY_PROP_CURRENT_NOW;
- cm->charger_psy.num_properties++;
- }
+ memcpy(cm->charger_psy.properties, cm_default_props,
+ sizeof(enum power_supply_property) *
+ ARRAY_SIZE(cm_default_props));
+ cm->charger_psy.num_properties = ARRAY_SIZE(cm_default_props);
+
+ for (i = 0; i < ARRAY_SIZE(cm_optional_props); i++)
+ cm_test_and_add_property(cm, cm_optional_props[i]);
if (desc->thermal_zone)
cm->tzd_batt =
The POWER_SUPPLY_CHARGE_NOW/FULL property reflects battery's charges in uAh unit, but charger-manager has been used it wrongly. This patch makes it to use those propeties correctly and change to be optional. Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com> --- drivers/power/charger-manager.c | 86 ++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 52 deletions(-)