aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/ds2760_battery.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/ds2760_battery.c')
-rw-r--r--drivers/power/ds2760_battery.c64
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
307static 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
307static void ds2760_battery_work(struct work_struct *work) 329static 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
451static 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
475static 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
429static enum power_supply_property ds2760_battery_props[] = { 490static 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;