Commit 20fd9830ccc685adce65ba89ffc3ca5426a2b064
Committed by
Anton Vorontsov
1 parent
b202a5e6c9
Exists in
master
and in
7 other branches
olpc_battery: Add support for CHARGE_NOW
CHARGE_NOW is needed by some user space software (read: UPower) for internal calculations. This patch violates the power supply class definition (as we already do for CAPACITY though it isn't as obvious there), but this is the best we can do without adding rather sophisticated algorithms to either the EC or UPower. Signed-off-by: Sascha Silbe <sascha-pgp@silbe.org> Signed-off-by: Paul Fox <pgf@laptop.org> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Showing 1 changed file with 24 additions and 0 deletions Side-by-side Diff
drivers/power/olpc_battery.c
... | ... | @@ -249,6 +249,24 @@ |
249 | 249 | return ret; |
250 | 250 | } |
251 | 251 | |
252 | +static int olpc_bat_get_charge_now(union power_supply_propval *val) | |
253 | +{ | |
254 | + uint8_t soc; | |
255 | + union power_supply_propval full; | |
256 | + int ret; | |
257 | + | |
258 | + ret = olpc_ec_cmd(EC_BAT_SOC, NULL, 0, &soc, 1); | |
259 | + if (ret) | |
260 | + return ret; | |
261 | + | |
262 | + ret = olpc_bat_get_charge_full_design(&full); | |
263 | + if (ret) | |
264 | + return ret; | |
265 | + | |
266 | + val->intval = soc * (full.intval / 100); | |
267 | + return 0; | |
268 | +} | |
269 | + | |
252 | 270 | /********************************************************************* |
253 | 271 | * Battery properties |
254 | 272 | *********************************************************************/ |
... | ... | @@ -347,6 +365,11 @@ |
347 | 365 | if (ret) |
348 | 366 | return ret; |
349 | 367 | break; |
368 | + case POWER_SUPPLY_PROP_CHARGE_NOW: | |
369 | + ret = olpc_bat_get_charge_now(val); | |
370 | + if (ret) | |
371 | + return ret; | |
372 | + break; | |
350 | 373 | case POWER_SUPPLY_PROP_TEMP: |
351 | 374 | ret = olpc_ec_cmd(EC_BAT_TEMP, NULL, 0, (void *)&ec_word, 2); |
352 | 375 | if (ret) |
... | ... | @@ -395,6 +418,7 @@ |
395 | 418 | POWER_SUPPLY_PROP_CAPACITY, |
396 | 419 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
397 | 420 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
421 | + POWER_SUPPLY_PROP_CHARGE_NOW, | |
398 | 422 | POWER_SUPPLY_PROP_TEMP, |
399 | 423 | POWER_SUPPLY_PROP_TEMP_AMBIENT, |
400 | 424 | POWER_SUPPLY_PROP_MANUFACTURER, |