@@ -304,6 +304,28 @@ static void ds2760_battery_write_rated_capacity(struct ds2760_device_info *di,
304
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
329
static void ds2760_battery_work (struct work_struct * work )
308
330
{
309
331
struct ds2760_device_info * di = container_of (work ,
@@ -426,6 +448,45 @@ static int ds2760_battery_get_property(struct power_supply *psy,
426
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
490
static enum power_supply_property ds2760_battery_props [] = {
430
491
POWER_SUPPLY_PROP_STATUS ,
431
492
POWER_SUPPLY_PROP_VOLTAGE_NOW ,
@@ -460,6 +521,9 @@ static int ds2760_battery_probe(struct platform_device *pdev)
460
521
di -> bat .properties = ds2760_battery_props ;
461
522
di -> bat .num_properties = ARRAY_SIZE (ds2760_battery_props );
462
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
527
di -> bat .set_charged = ds2760_battery_set_charged ;
464
528
di -> bat .external_power_changed =
465
529
ds2760_battery_external_power_changed ;
0 commit comments