aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMarcus Cooper <marcus.xm.cooper@stericsson.com>2013-01-11 08:12:54 -0500
committerAnton Vorontsov <anton@enomsg.org>2013-01-15 20:43:46 -0500
commitea4024017831d61874351defe8f8c58ae73f8009 (patch)
tree0411f756d15ee826c05a603e1218125a0410fcc0 /drivers
parenta864c5a869dcdb40617fc15166385e0ffa609592 (diff)
ab8500_bm: Recharge condition not optimal for battery
Today the battery recharge is determined with a voltage threshold. This voltage threshold is only valid when the battery is relaxed. In charging algorithm the voltage read is the loaded battery voltage and no compensation is done to get the relaxed voltage. When maintenance charging is not selected, this makes the recharging condition to almost immediately activate when there is a discharge present on the battery. Depending on which vendor the battery comes from this behavior can wear out the battery much faster than normal. The fuelgauge driver is responsible to monitor the actual battery capacity and is able to estimate the remaining capacity. It is better to use the remaining capacity as a limit to determine when battery should be recharged. Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Marcus Cooper <marcus.xm.cooper@stericsson.com> Reviewed-by: Hakan BERG <hakan.berg@stericsson.com> Reviewed-by: Jonas ABERG <jonas.aberg@stericsson.com> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/power/ab8500_bmdata.c19
-rw-r--r--drivers/power/ab8500_fg.c146
-rw-r--r--drivers/power/abx500_chargalg.c30
3 files changed, 162 insertions, 33 deletions
diff --git a/drivers/power/ab8500_bmdata.c b/drivers/power/ab8500_bmdata.c
index 0bf52369d6a5..20c157b4fe99 100644
--- a/drivers/power/ab8500_bmdata.c
+++ b/drivers/power/ab8500_bmdata.c
@@ -192,7 +192,7 @@ static struct abx500_battery_type bat_type_thermistor[] = {
192 .nominal_voltage = 3700, 192 .nominal_voltage = 3700,
193 .termination_vol = 4050, 193 .termination_vol = 4050,
194 .termination_curr = 200, 194 .termination_curr = 200,
195 .recharge_vol = 3990, 195 .recharge_cap = 95,
196 .normal_cur_lvl = 400, 196 .normal_cur_lvl = 400,
197 .normal_vol_lvl = 4100, 197 .normal_vol_lvl = 4100,
198 .maint_a_cur_lvl = 400, 198 .maint_a_cur_lvl = 400,
@@ -219,7 +219,7 @@ static struct abx500_battery_type bat_type_thermistor[] = {
219 .nominal_voltage = 3600, 219 .nominal_voltage = 3600,
220 .termination_vol = 4150, 220 .termination_vol = 4150,
221 .termination_curr = 80, 221 .termination_curr = 80,
222 .recharge_vol = 4130, 222 .recharge_cap = 95,
223 .normal_cur_lvl = 700, 223 .normal_cur_lvl = 700,
224 .normal_vol_lvl = 4200, 224 .normal_vol_lvl = 4200,
225 .maint_a_cur_lvl = 600, 225 .maint_a_cur_lvl = 600,
@@ -247,7 +247,7 @@ static struct abx500_battery_type bat_type_thermistor[] = {
247 .nominal_voltage = 3600, 247 .nominal_voltage = 3600,
248 .termination_vol = 4150, 248 .termination_vol = 4150,
249 .termination_curr = 80, 249 .termination_curr = 80,
250 .recharge_vol = 4130, 250 .recharge_cap = 95,
251 .normal_cur_lvl = 700, 251 .normal_cur_lvl = 700,
252 .normal_vol_lvl = 4200, 252 .normal_vol_lvl = 4200,
253 .maint_a_cur_lvl = 600, 253 .maint_a_cur_lvl = 600,
@@ -278,7 +278,7 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = {
278 .nominal_voltage = 3700, 278 .nominal_voltage = 3700,
279 .termination_vol = 4050, 279 .termination_vol = 4050,
280 .termination_curr = 200, 280 .termination_curr = 200,
281 .recharge_vol = 3990, 281 .recharge_cap = 95,
282 .normal_cur_lvl = 400, 282 .normal_cur_lvl = 400,
283 .normal_vol_lvl = 4100, 283 .normal_vol_lvl = 4100,
284 .maint_a_cur_lvl = 400, 284 .maint_a_cur_lvl = 400,
@@ -310,7 +310,7 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = {
310 .nominal_voltage = 3700, 310 .nominal_voltage = 3700,
311 .termination_vol = 4150, 311 .termination_vol = 4150,
312 .termination_curr = 100, 312 .termination_curr = 100,
313 .recharge_vol = 4130, 313 .recharge_cap = 95,
314 .normal_cur_lvl = 700, 314 .normal_cur_lvl = 700,
315 .normal_vol_lvl = 4200, 315 .normal_vol_lvl = 4200,
316 .maint_a_cur_lvl = 600, 316 .maint_a_cur_lvl = 600,
@@ -337,7 +337,7 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = {
337 .nominal_voltage = 3700, 337 .nominal_voltage = 3700,
338 .termination_vol = 4150, 338 .termination_vol = 4150,
339 .termination_curr = 100, 339 .termination_curr = 100,
340 .recharge_vol = 4130, 340 .recharge_cap = 95,
341 .normal_cur_lvl = 700, 341 .normal_cur_lvl = 700,
342 .normal_vol_lvl = 4200, 342 .normal_vol_lvl = 4200,
343 .maint_a_cur_lvl = 600, 343 .maint_a_cur_lvl = 600,
@@ -364,7 +364,7 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = {
364 .nominal_voltage = 3700, 364 .nominal_voltage = 3700,
365 .termination_vol = 4150, 365 .termination_vol = 4150,
366 .termination_curr = 100, 366 .termination_curr = 100,
367 .recharge_vol = 4130, 367 .recharge_cap = 95,
368 .normal_cur_lvl = 700, 368 .normal_cur_lvl = 700,
369 .normal_vol_lvl = 4200, 369 .normal_vol_lvl = 4200,
370 .maint_a_cur_lvl = 600, 370 .maint_a_cur_lvl = 600,
@@ -405,8 +405,8 @@ static const struct abx500_fg_parameters fg = {
405 .lowbat_threshold = 3100, 405 .lowbat_threshold = 3100,
406 .battok_falling_th_sel0 = 2860, 406 .battok_falling_th_sel0 = 2860,
407 .battok_raising_th_sel1 = 2860, 407 .battok_raising_th_sel1 = 2860,
408 .maint_thres = 95,
408 .user_cap_limit = 15, 409 .user_cap_limit = 15,
409 .maint_thres = 97,
410}; 410};
411 411
412static const struct abx500_maxim_parameters maxi_params = { 412static const struct abx500_maxim_parameters maxi_params = {
@@ -435,6 +435,7 @@ struct abx500_bm_data ab8500_bm_data = {
435 .bkup_bat_v = BUP_VCH_SEL_2P6V, 435 .bkup_bat_v = BUP_VCH_SEL_2P6V,
436 .bkup_bat_i = BUP_ICH_SEL_150UA, 436 .bkup_bat_i = BUP_ICH_SEL_150UA,
437 .no_maintenance = false, 437 .no_maintenance = false,
438 .capacity_scaling = false,
438 .adc_therm = ABx500_ADC_THERM_BATCTRL, 439 .adc_therm = ABx500_ADC_THERM_BATCTRL,
439 .chg_unknown_bat = false, 440 .chg_unknown_bat = false,
440 .enable_overshoot = false, 441 .enable_overshoot = false,
@@ -479,7 +480,7 @@ int __devinit ab8500_bm_of_probe(struct device *dev,
479 bm->chg_unknown_bat = true; 480 bm->chg_unknown_bat = true;
480 bm->bat_type[BATTERY_UNKNOWN].charge_full_design = 2600; 481 bm->bat_type[BATTERY_UNKNOWN].charge_full_design = 2600;
481 bm->bat_type[BATTERY_UNKNOWN].termination_vol = 4150; 482 bm->bat_type[BATTERY_UNKNOWN].termination_vol = 4150;
482 bm->bat_type[BATTERY_UNKNOWN].recharge_vol = 4130; 483 bm->bat_type[BATTERY_UNKNOWN].recharge_cap = 95;
483 bm->bat_type[BATTERY_UNKNOWN].normal_cur_lvl = 520; 484 bm->bat_type[BATTERY_UNKNOWN].normal_cur_lvl = 520;
484 bm->bat_type[BATTERY_UNKNOWN].normal_vol_lvl = 4200; 485 bm->bat_type[BATTERY_UNKNOWN].normal_vol_lvl = 4200;
485 } 486 }
diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c
index f3dbba8b3925..76fab6b5c541 100644
--- a/drivers/power/ab8500_fg.c
+++ b/drivers/power/ab8500_fg.c
@@ -113,6 +113,13 @@ struct ab8500_fg_avg_cap {
113 int sum; 113 int sum;
114}; 114};
115 115
116struct ab8500_fg_cap_scaling {
117 bool enable;
118 int cap_to_scale[2];
119 int disable_cap_level;
120 int scaled_cap;
121};
122
116struct ab8500_fg_battery_capacity { 123struct ab8500_fg_battery_capacity {
117 int max_mah_design; 124 int max_mah_design;
118 int max_mah; 125 int max_mah;
@@ -123,6 +130,7 @@ struct ab8500_fg_battery_capacity {
123 int prev_percent; 130 int prev_percent;
124 int prev_level; 131 int prev_level;
125 int user_mah; 132 int user_mah;
133 struct ab8500_fg_cap_scaling cap_scale;
126}; 134};
127 135
128struct ab8500_fg_flags { 136struct ab8500_fg_flags {
@@ -1167,6 +1175,99 @@ static int ab8500_fg_capacity_level(struct ab8500_fg *di)
1167} 1175}
1168 1176
1169/** 1177/**
1178 * ab8500_fg_calculate_scaled_capacity() - Capacity scaling
1179 * @di: pointer to the ab8500_fg structure
1180 *
1181 * Calculates the capacity to be shown to upper layers. Scales the capacity
1182 * to have 100% as a reference from the actual capacity upon removal of charger
1183 * when charging is in maintenance mode.
1184 */
1185static int ab8500_fg_calculate_scaled_capacity(struct ab8500_fg *di)
1186{
1187 struct ab8500_fg_cap_scaling *cs = &di->bat_cap.cap_scale;
1188 int capacity = di->bat_cap.prev_percent;
1189
1190 if (!cs->enable)
1191 return capacity;
1192
1193 /*
1194 * As long as we are in fully charge mode scale the capacity
1195 * to show 100%.
1196 */
1197 if (di->flags.fully_charged) {
1198 cs->cap_to_scale[0] = 100;
1199 cs->cap_to_scale[1] =
1200 max(capacity, di->bm->fg_params->maint_thres);
1201 dev_dbg(di->dev, "Scale cap with %d/%d\n",
1202 cs->cap_to_scale[0], cs->cap_to_scale[1]);
1203 }
1204
1205 /* Calculates the scaled capacity. */
1206 if ((cs->cap_to_scale[0] != cs->cap_to_scale[1])
1207 && (cs->cap_to_scale[1] > 0))
1208 capacity = min(100,
1209 DIV_ROUND_CLOSEST(di->bat_cap.prev_percent *
1210 cs->cap_to_scale[0],
1211 cs->cap_to_scale[1]));
1212
1213 if (di->flags.charging) {
1214 if (capacity < cs->disable_cap_level) {
1215 cs->disable_cap_level = capacity;
1216 dev_dbg(di->dev, "Cap to stop scale lowered %d%%\n",
1217 cs->disable_cap_level);
1218 } else if (!di->flags.fully_charged) {
1219 if (di->bat_cap.prev_percent >=
1220 cs->disable_cap_level) {
1221 dev_dbg(di->dev, "Disabling scaled capacity\n");
1222 cs->enable = false;
1223 capacity = di->bat_cap.prev_percent;
1224 } else {
1225 dev_dbg(di->dev,
1226 "Waiting in cap to level %d%%\n",
1227 cs->disable_cap_level);
1228 capacity = cs->disable_cap_level;
1229 }
1230 }
1231 }
1232
1233 return capacity;
1234}
1235
1236/**
1237 * ab8500_fg_update_cap_scalers() - Capacity scaling
1238 * @di: pointer to the ab8500_fg structure
1239 *
1240 * To be called when state change from charge<->discharge to update
1241 * the capacity scalers.
1242 */
1243static void ab8500_fg_update_cap_scalers(struct ab8500_fg *di)
1244{
1245 struct ab8500_fg_cap_scaling *cs = &di->bat_cap.cap_scale;
1246
1247 if (!cs->enable)
1248 return;
1249 if (di->flags.charging) {
1250 di->bat_cap.cap_scale.disable_cap_level =
1251 di->bat_cap.cap_scale.scaled_cap;
1252 dev_dbg(di->dev, "Cap to stop scale at charge %d%%\n",
1253 di->bat_cap.cap_scale.disable_cap_level);
1254 } else {
1255 if (cs->scaled_cap != 100) {
1256 cs->cap_to_scale[0] = cs->scaled_cap;
1257 cs->cap_to_scale[1] = di->bat_cap.prev_percent;
1258 } else {
1259 cs->cap_to_scale[0] = 100;
1260 cs->cap_to_scale[1] =
1261 max(di->bat_cap.prev_percent,
1262 di->bm->fg_params->maint_thres);
1263 }
1264
1265 dev_dbg(di->dev, "Cap to scale at discharge %d/%d\n",
1266 cs->cap_to_scale[0], cs->cap_to_scale[1]);
1267 }
1268}
1269
1270/**
1170 * ab8500_fg_check_capacity_limits() - Check if capacity has changed 1271 * ab8500_fg_check_capacity_limits() - Check if capacity has changed
1171 * @di: pointer to the ab8500_fg structure 1272 * @di: pointer to the ab8500_fg structure
1172 * @init: capacity is allowed to go up in init mode 1273 * @init: capacity is allowed to go up in init mode
@@ -1214,16 +1315,24 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)
1214 } else if (di->flags.fully_charged) { 1315 } else if (di->flags.fully_charged) {
1215 /* 1316 /*
1216 * We report 100% if algorithm reported fully charged 1317 * We report 100% if algorithm reported fully charged
1217 * unless capacity drops too much 1318 * and show 100% during maintenance charging (scaling).
1218 */ 1319 */
1219 if (di->flags.force_full) { 1320 if (di->flags.force_full) {
1220 di->bat_cap.prev_percent = di->bat_cap.permille / 10; 1321 di->bat_cap.prev_percent = di->bat_cap.permille / 10;
1221 di->bat_cap.prev_mah = di->bat_cap.mah; 1322 di->bat_cap.prev_mah = di->bat_cap.mah;
1222 } else if (!di->flags.force_full && 1323
1223 di->bat_cap.prev_percent != 1324 changed = true;
1224 (di->bat_cap.permille) / 10 && 1325
1225 (di->bat_cap.permille / 10) < 1326 if (!di->bat_cap.cap_scale.enable &&
1226 di->bm->fg_params->maint_thres) { 1327 di->bm->capacity_scaling) {
1328 di->bat_cap.cap_scale.enable = true;
1329 di->bat_cap.cap_scale.cap_to_scale[0] = 100;
1330 di->bat_cap.cap_scale.cap_to_scale[1] =
1331 di->bat_cap.prev_percent;
1332 di->bat_cap.cap_scale.disable_cap_level = 100;
1333 }
1334 } else if ( di->bat_cap.prev_percent !=
1335 (di->bat_cap.permille) / 10) {
1227 dev_dbg(di->dev, 1336 dev_dbg(di->dev,
1228 "battery reported full " 1337 "battery reported full "
1229 "but capacity dropping: %d\n", 1338 "but capacity dropping: %d\n",
@@ -1272,6 +1381,14 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)
1272 } 1381 }
1273 1382
1274 if (changed) { 1383 if (changed) {
1384 if (di->bm->capacity_scaling) {
1385 di->bat_cap.cap_scale.scaled_cap =
1386 ab8500_fg_calculate_scaled_capacity(di);
1387
1388 dev_info(di->dev, "capacity=%d (%d)\n",
1389 di->bat_cap.prev_percent,
1390 di->bat_cap.cap_scale.scaled_cap);
1391 }
1275 power_supply_changed(&di->fg_psy); 1392 power_supply_changed(&di->fg_psy);
1276 if (di->flags.fully_charged && di->flags.force_full) { 1393 if (di->flags.fully_charged && di->flags.force_full) {
1277 dev_dbg(di->dev, "Battery full, notifying.\n"); 1394 dev_dbg(di->dev, "Battery full, notifying.\n");
@@ -1337,7 +1454,7 @@ static void ab8500_fg_algorithm_charging(struct ab8500_fg *di)
1337 * Read the FG and calculate the new capacity 1454 * Read the FG and calculate the new capacity
1338 */ 1455 */
1339 mutex_lock(&di->cc_lock); 1456 mutex_lock(&di->cc_lock);
1340 if (!di->flags.conv_done) { 1457 if (!di->flags.conv_done && !di->flags.force_full) {
1341 /* Wasn't the CC IRQ that got us here */ 1458 /* Wasn't the CC IRQ that got us here */
1342 mutex_unlock(&di->cc_lock); 1459 mutex_unlock(&di->cc_lock);
1343 dev_dbg(di->dev, "%s CC conv not done\n", 1460 dev_dbg(di->dev, "%s CC conv not done\n",
@@ -2027,7 +2144,9 @@ static int ab8500_fg_get_property(struct power_supply *psy,
2027 val->intval = di->bat_cap.prev_mah; 2144 val->intval = di->bat_cap.prev_mah;
2028 break; 2145 break;
2029 case POWER_SUPPLY_PROP_CAPACITY: 2146 case POWER_SUPPLY_PROP_CAPACITY:
2030 if (di->flags.batt_unknown && !di->bm->chg_unknown_bat && 2147 if (di->bm->capacity_scaling)
2148 val->intval = di->bat_cap.cap_scale.scaled_cap;
2149 else if (di->flags.batt_unknown && !di->bm->chg_unknown_bat &&
2031 di->flags.batt_id_received) 2150 di->flags.batt_id_received)
2032 val->intval = 100; 2151 val->intval = 100;
2033 else 2152 else
@@ -2091,6 +2210,8 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
2091 break; 2210 break;
2092 di->flags.charging = false; 2211 di->flags.charging = false;
2093 di->flags.fully_charged = false; 2212 di->flags.fully_charged = false;
2213 if (di->bm->capacity_scaling)
2214 ab8500_fg_update_cap_scalers(di);
2094 queue_work(di->fg_wq, &di->fg_work); 2215 queue_work(di->fg_wq, &di->fg_work);
2095 break; 2216 break;
2096 case POWER_SUPPLY_STATUS_FULL: 2217 case POWER_SUPPLY_STATUS_FULL:
@@ -2103,10 +2224,13 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
2103 queue_work(di->fg_wq, &di->fg_work); 2224 queue_work(di->fg_wq, &di->fg_work);
2104 break; 2225 break;
2105 case POWER_SUPPLY_STATUS_CHARGING: 2226 case POWER_SUPPLY_STATUS_CHARGING:
2106 if (di->flags.charging) 2227 if (di->flags.charging &&
2228 !di->flags.fully_charged)
2107 break; 2229 break;
2108 di->flags.charging = true; 2230 di->flags.charging = true;
2109 di->flags.fully_charged = false; 2231 di->flags.fully_charged = false;
2232 if (di->bm->capacity_scaling)
2233 ab8500_fg_update_cap_scalers(di);
2110 queue_work(di->fg_wq, &di->fg_work); 2234 queue_work(di->fg_wq, &di->fg_work);
2111 break; 2235 break;
2112 }; 2236 };
@@ -2146,8 +2270,8 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
2146 case POWER_SUPPLY_PROP_TEMP: 2270 case POWER_SUPPLY_PROP_TEMP:
2147 switch (ext->type) { 2271 switch (ext->type) {
2148 case POWER_SUPPLY_TYPE_BATTERY: 2272 case POWER_SUPPLY_TYPE_BATTERY:
2149 if (di->flags.batt_id_received) 2273 if (di->flags.batt_id_received)
2150 di->bat_temp = ret.intval; 2274 di->bat_temp = ret.intval;
2151 break; 2275 break;
2152 default: 2276 default:
2153 break; 2277 break;
diff --git a/drivers/power/abx500_chargalg.c b/drivers/power/abx500_chargalg.c
index 8b69da0ae5af..78b623572b52 100644
--- a/drivers/power/abx500_chargalg.c
+++ b/drivers/power/abx500_chargalg.c
@@ -33,9 +33,6 @@
33/* End-of-charge criteria counter */ 33/* End-of-charge criteria counter */
34#define EOC_COND_CNT 10 34#define EOC_COND_CNT 10
35 35
36/* Recharge criteria counter */
37#define RCH_COND_CNT 3
38
39#define to_abx500_chargalg_device_info(x) container_of((x), \ 36#define to_abx500_chargalg_device_info(x) container_of((x), \
40 struct abx500_chargalg, chargalg_psy); 37 struct abx500_chargalg, chargalg_psy);
41 38
@@ -196,7 +193,6 @@ enum maxim_ret {
196 * @dev: pointer to the structure device 193 * @dev: pointer to the structure device
197 * @charge_status: battery operating status 194 * @charge_status: battery operating status
198 * @eoc_cnt: counter used to determine end-of_charge 195 * @eoc_cnt: counter used to determine end-of_charge
199 * @rch_cnt: counter used to determine start of recharge
200 * @maintenance_chg: indicate if maintenance charge is active 196 * @maintenance_chg: indicate if maintenance charge is active
201 * @t_hyst_norm temperature hysteresis when the temperature has been 197 * @t_hyst_norm temperature hysteresis when the temperature has been
202 * over or under normal limits 198 * over or under normal limits
@@ -223,7 +219,6 @@ struct abx500_chargalg {
223 struct device *dev; 219 struct device *dev;
224 int charge_status; 220 int charge_status;
225 int eoc_cnt; 221 int eoc_cnt;
226 int rch_cnt;
227 bool maintenance_chg; 222 bool maintenance_chg;
228 int t_hyst_norm; 223 int t_hyst_norm;
229 int t_hyst_lowhigh; 224 int t_hyst_lowhigh;
@@ -858,6 +853,7 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
858 union power_supply_propval ret; 853 union power_supply_propval ret;
859 int i, j; 854 int i, j;
860 bool psy_found = false; 855 bool psy_found = false;
856 bool capacity_updated = false;
861 857
862 psy = (struct power_supply *)data; 858 psy = (struct power_supply *)data;
863 ext = dev_get_drvdata(dev); 859 ext = dev_get_drvdata(dev);
@@ -870,6 +866,16 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
870 if (!psy_found) 866 if (!psy_found)
871 return 0; 867 return 0;
872 868
869 /*
870 * If external is not registering 'POWER_SUPPLY_PROP_CAPACITY' to its
871 * property because of handling that sysfs entry on its own, this is
872 * the place to get the battery capacity.
873 */
874 if (!ext->get_property(ext, POWER_SUPPLY_PROP_CAPACITY, &ret)) {
875 di->batt_data.percent = ret.intval;
876 capacity_updated = true;
877 }
878
873 /* Go through all properties for the psy */ 879 /* Go through all properties for the psy */
874 for (j = 0; j < ext->num_properties; j++) { 880 for (j = 0; j < ext->num_properties; j++) {
875 enum power_supply_property prop; 881 enum power_supply_property prop;
@@ -1154,7 +1160,8 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)
1154 } 1160 }
1155 break; 1161 break;
1156 case POWER_SUPPLY_PROP_CAPACITY: 1162 case POWER_SUPPLY_PROP_CAPACITY:
1157 di->batt_data.percent = ret.intval; 1163 if (!capacity_updated)
1164 di->batt_data.percent = ret.intval;
1158 break; 1165 break;
1159 default: 1166 default:
1160 break; 1167 break;
@@ -1424,16 +1431,13 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
1424 case STATE_WAIT_FOR_RECHARGE_INIT: 1431 case STATE_WAIT_FOR_RECHARGE_INIT:
1425 abx500_chargalg_hold_charging(di); 1432 abx500_chargalg_hold_charging(di);
1426 abx500_chargalg_state_to(di, STATE_WAIT_FOR_RECHARGE); 1433 abx500_chargalg_state_to(di, STATE_WAIT_FOR_RECHARGE);
1427 di->rch_cnt = RCH_COND_CNT;
1428 /* Intentional fallthrough */ 1434 /* Intentional fallthrough */
1429 1435
1430 case STATE_WAIT_FOR_RECHARGE: 1436 case STATE_WAIT_FOR_RECHARGE:
1431 if (di->batt_data.volt <= 1437 if (di->batt_data.percent <=
1432 di->bm->bat_type[di->bm->batt_id].recharge_vol) { 1438 di->bm->bat_type[di->bm->batt_id].
1433 if (di->rch_cnt-- == 0) 1439 recharge_cap)
1434 abx500_chargalg_state_to(di, STATE_NORMAL_INIT); 1440 abx500_chargalg_state_to(di, STATE_NORMAL_INIT);
1435 } else
1436 di->rch_cnt = RCH_COND_CNT;
1437 break; 1441 break;
1438 1442
1439 case STATE_MAINTENANCE_A_INIT: 1443 case STATE_MAINTENANCE_A_INIT: