Skip to content

Commit cef437e

Browse files
Daniel Mackenomsg
authored andcommitted
w1: ds2760_battery: add support for sleep mode feature
This adds support for ds2760's sleep mode feature. With this feature enabled, the chip enters a deep sleep mode and disconnects from the battery when the w1 line is held down for more than 2 seconds. This new behaviour can be switched on and off using a new module parameter. Signed-off-by: Daniel Mack <[email protected]> Cc: Szabolcs Gyurko <[email protected]> Acked-by: Matt Reimer <[email protected]> Acked-by: Evgeniy Polyakov <[email protected]> Signed-off-by: Anton Vorontsov <[email protected]>
1 parent 0b47b57 commit cef437e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

drivers/power/ds2760_battery.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ static unsigned int cache_time = 1000;
6262
module_param(cache_time, uint, 0644);
6363
MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
6464

65+
static unsigned int pmod_enabled;
66+
module_param(pmod_enabled, bool, 0644);
67+
MODULE_PARM_DESC(pmod_enabled, "PMOD enable bit");
68+
6569
/* Some batteries have their rated capacity stored a N * 10 mAh, while
6670
* others use an index into this table. */
6771
static int rated_capacities[] = {
@@ -259,6 +263,17 @@ static void ds2760_battery_update_status(struct ds2760_device_info *di)
259263
power_supply_changed(&di->bat);
260264
}
261265

266+
static void ds2760_battery_write_status(struct ds2760_device_info *di,
267+
char status)
268+
{
269+
if (status == di->raw[DS2760_STATUS_REG])
270+
return;
271+
272+
w1_ds2760_write(di->w1_dev, &status, DS2760_STATUS_WRITE_REG, 1);
273+
w1_ds2760_store_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
274+
w1_ds2760_recall_eeprom(di->w1_dev, DS2760_EEPROM_BLOCK1);
275+
}
276+
262277
static void ds2760_battery_work(struct work_struct *work)
263278
{
264279
struct ds2760_device_info *di = container_of(work,
@@ -342,6 +357,7 @@ static enum power_supply_property ds2760_battery_props[] = {
342357

343358
static int ds2760_battery_probe(struct platform_device *pdev)
344359
{
360+
char status;
345361
int retval = 0;
346362
struct ds2760_device_info *di;
347363

@@ -371,6 +387,16 @@ static int ds2760_battery_probe(struct platform_device *pdev)
371387
goto batt_failed;
372388
}
373389

390+
/* enable sleep mode feature */
391+
ds2760_battery_read_status(di);
392+
status = di->raw[DS2760_STATUS_REG];
393+
if (pmod_enabled)
394+
status |= DS2760_STATUS_PMOD;
395+
else
396+
status &= ~DS2760_STATUS_PMOD;
397+
398+
ds2760_battery_write_status(di, status);
399+
374400
INIT_DELAYED_WORK(&di->monitor_work, ds2760_battery_work);
375401
di->monitor_wqueue = create_singlethread_workqueue(dev_name(&pdev->dev));
376402
if (!di->monitor_wqueue) {

drivers/w1/slaves/w1_ds2760.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
#define DS2760_PROTECTION_REG 0x00
2727
#define DS2760_STATUS_REG 0x01
28+
#define DS2760_STATUS_IE (1 << 2)
29+
#define DS2760_STATUS_SWEN (1 << 3)
30+
#define DS2760_STATUS_RNAOP (1 << 4)
31+
#define DS2760_STATUS_PMOD (1 << 5)
2832
#define DS2760_EEPROM_REG 0x07
2933
#define DS2760_SPECIAL_FEATURE_REG 0x08
3034
#define DS2760_VOLTAGE_MSB 0x0c
@@ -38,6 +42,7 @@
3842
#define DS2760_EEPROM_BLOCK0 0x20
3943
#define DS2760_ACTIVE_FULL 0x20
4044
#define DS2760_EEPROM_BLOCK1 0x30
45+
#define DS2760_STATUS_WRITE_REG 0x31
4146
#define DS2760_RATED_CAPACITY 0x32
4247
#define DS2760_CURRENT_OFFSET_BIAS 0x33
4348
#define DS2760_ACTIVE_EMPTY 0x3b

0 commit comments

Comments
 (0)