diff options
| author | Daniel Mack <daniel@caiaq.de> | 2010-05-18 15:49:53 -0400 |
|---|---|---|
| committer | Anton Vorontsov <cbouatmailru@gmail.com> | 2010-05-19 04:14:42 -0400 |
| commit | bd52ca555ef36bf5b790178cfe8b7d42b5c16ca6 (patch) | |
| tree | f414ebcfa52a2014c7698e66614af25ee8452fbe | |
| parent | 0011d2d4a5f7bb5666dcfb9f9b3dbdb084ab98f1 (diff) | |
ds2760_battery: Make charge_now and charge_full writeable
For userspace tools and daemons, it might be necessary to adjust
the charge_now and charge_full properties of the ds2760 battery monitor,
for example for unavoidable corrections due to aging batteries.
Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Matt Reimer <mreimer@vpop.net>
Cc: Evgeniy Polyakov <zbr@ioremap.net>
Cc: Tejun Heo <tj@kernel.org>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Alexey Starikovskiy <astarikovskiy@suse.de>
Cc: Len Brown <len.brown@intel.com>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
| -rw-r--r-- | drivers/power/ds2760_battery.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/drivers/power/ds2760_battery.c b/drivers/power/ds2760_battery.c index 3bf8d1f622e3..4d3b27228a2e 100644 --- a/drivers/power/ds2760_battery.c +++ b/drivers/power/ds2760_battery.c | |||
| @@ -304,6 +304,28 @@ static void ds2760_battery_write_rated_capacity(struct ds2760_device_info *di, | |||
| 304 | w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1); | 304 | w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1); |
| 305 | } | 305 | } |
| 306 | 306 | ||
| 307 | static void ds2760_battery_write_active_full(struct ds2760_device_info *di, | ||
| 308 | int active_full) | ||
| 309 | { | ||
| 310 | unsigned char tmp[2] = { | ||
| 311 | active_full >> 8, | ||
| 312 | active_full & 0xff | ||
| 313 | }; | ||
| 314 | |||
| 315 | if (tmp[0] == di->raw[DS2760_ACTIVE_FULL] && | ||
| 316 | tmp[1] == di->raw[DS2760_ACTIVE_FULL + 1]) | ||
| 317 | return; | ||
| 318 | |||
| 319 | w1_ds2760_write(di->w1_dev, tmp, DS2760_ACTIVE_FULL, sizeof(tmp)); | ||
| 320 | w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK0); | ||
| 321 | w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK0); | ||
| 322 | |||
| 323 | /* Write to the di->raw[] buffer directly - the DS2760_ACTIVE_FULL | ||
| 324 | * values won't be read back by ds2760_battery_read_status() */ | ||
| 325 | di->raw[DS2760_ACTIVE_FULL] = tmp[0]; | ||
| 326 | di->raw[DS2760_ACTIVE_FULL + 1] = tmp[1]; | ||
| 327 | } | ||
| 328 | |||
| 307 | static void ds2760_battery_work(struct work_struct *work) | 329 | static void ds2760_battery_work(struct work_struct *work) |
| 308 | { | 330 | { |
| 309 | struct ds2760_device_info *di = container_of(work, | 331 | struct ds2760_device_info *di = container_of(work, |
| @@ -426,6 +448,45 @@ static int ds2760_battery_get_property(struct power_supply *psy, | |||
| 426 | return 0; | 448 | return 0; |
| 427 | } | 449 | } |
| 428 | 450 | ||
| 451 | static int ds2760_battery_set_property(struct power_supply *psy, | ||
| 452 | enum power_supply_property psp, | ||
| 453 | const union power_supply_propval *val) | ||
| 454 | { | ||
| 455 | struct ds2760_device_info *di = to_ds2760_device_info(psy); | ||
| 456 | |||
| 457 | switch (psp) { | ||
| 458 | case POWER_SUPPLY_PROP_CHARGE_FULL: | ||
| 459 | /* the interface counts in uAh, convert the value */ | ||
| 460 | ds2760_battery_write_active_full(di, val->intval / 1000L); | ||
| 461 | break; | ||
| 462 | |||
| 463 | case POWER_SUPPLY_PROP_CHARGE_NOW: | ||
| 464 | /* ds2760_battery_set_current_accum() does the conversion */ | ||
| 465 | ds2760_battery_set_current_accum(di, val->intval); | ||
| 466 | break; | ||
| 467 | |||
| 468 | default: | ||
| 469 | return -EPERM; | ||
| 470 | } | ||
| 471 | |||
| 472 | return 0; | ||
| 473 | } | ||
| 474 | |||
| 475 | static int ds2760_battery_property_is_writeable(struct power_supply *psy, | ||
| 476 | enum power_supply_property psp) | ||
| 477 | { | ||
| 478 | switch (psp) { | ||
| 479 | case POWER_SUPPLY_PROP_CHARGE_FULL: | ||
| 480 | case POWER_SUPPLY_PROP_CHARGE_NOW: | ||
| 481 | return 1; | ||
| 482 | |||
| 483 | default: | ||
| 484 | break; | ||
| 485 | } | ||
| 486 | |||
| 487 | return 0; | ||
| 488 | } | ||
| 489 | |||
| 429 | static enum power_supply_property ds2760_battery_props[] = { | 490 | static enum power_supply_property ds2760_battery_props[] = { |
| 430 | POWER_SUPPLY_PROP_STATUS, | 491 | POWER_SUPPLY_PROP_STATUS, |
| 431 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | 492 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| @@ -460,6 +521,9 @@ static int ds2760_battery_probe(struct platform_device *pdev) | |||
| 460 | di->bat.properties = ds2760_battery_props; | 521 | di->bat.properties = ds2760_battery_props; |
| 461 | di->bat.num_properties = ARRAY_SIZE(ds2760_battery_props); | 522 | di->bat.num_properties = ARRAY_SIZE(ds2760_battery_props); |
| 462 | di->bat.get_property = ds2760_battery_get_property; | 523 | di->bat.get_property = ds2760_battery_get_property; |
| 524 | di->bat.set_property = ds2760_battery_set_property; | ||
| 525 | di->bat.property_is_writeable = | ||
| 526 | ds2760_battery_property_is_writeable; | ||
| 463 | di->bat.set_charged = ds2760_battery_set_charged; | 527 | di->bat.set_charged = ds2760_battery_set_charged; |
| 464 | di->bat.external_power_changed = | 528 | di->bat.external_power_changed = |
| 465 | ds2760_battery_external_power_changed; | 529 | ds2760_battery_external_power_changed; |
