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.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/drivers/power/ds2760_battery.c b/drivers/power/ds2760_battery.c
index a52d4a11652d..520b5c49ff30 100644
--- a/drivers/power/ds2760_battery.c
+++ b/drivers/power/ds2760_battery.c
@@ -62,6 +62,10 @@ static unsigned int cache_time = 1000;
62module_param(cache_time, uint, 0644); 62module_param(cache_time, uint, 0644);
63MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); 63MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
64 64
65static unsigned int pmod_enabled;
66module_param(pmod_enabled, bool, 0644);
67MODULE_PARM_DESC(pmod_enabled, "PMOD enable bit");
68
65/* Some batteries have their rated capacity stored a N * 10 mAh, while 69/* Some batteries have their rated capacity stored a N * 10 mAh, while
66 * others use an index into this table. */ 70 * others use an index into this table. */
67static int rated_capacities[] = { 71static int rated_capacities[] = {
@@ -259,6 +263,17 @@ static void ds2760_battery_update_status(struct ds2760_device_info *di)
259 power_supply_changed(&di->bat); 263 power_supply_changed(&di->bat);
260} 264}
261 265
266static 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
262static void ds2760_battery_work(struct work_struct *work) 277static void ds2760_battery_work(struct work_struct *work)
263{ 278{
264 struct ds2760_device_info *di = container_of(work, 279 struct ds2760_device_info *di = container_of(work,
@@ -342,9 +357,9 @@ static enum power_supply_property ds2760_battery_props[] = {
342 357
343static int ds2760_battery_probe(struct platform_device *pdev) 358static int ds2760_battery_probe(struct platform_device *pdev)
344{ 359{
360 char status;
345 int retval = 0; 361 int retval = 0;
346 struct ds2760_device_info *di; 362 struct ds2760_device_info *di;
347 struct ds2760_platform_data *pdata;
348 363
349 di = kzalloc(sizeof(*di), GFP_KERNEL); 364 di = kzalloc(sizeof(*di), GFP_KERNEL);
350 if (!di) { 365 if (!di) {
@@ -354,14 +369,13 @@ static int ds2760_battery_probe(struct platform_device *pdev)
354 369
355 platform_set_drvdata(pdev, di); 370 platform_set_drvdata(pdev, di);
356 371
357 pdata = pdev->dev.platform_data; 372 di->dev = &pdev->dev;
358 di->dev = &pdev->dev; 373 di->w1_dev = pdev->dev.parent;
359 di->w1_dev = pdev->dev.parent; 374 di->bat.name = dev_name(&pdev->dev);
360 di->bat.name = dev_name(&pdev->dev); 375 di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
361 di->bat.type = POWER_SUPPLY_TYPE_BATTERY; 376 di->bat.properties = ds2760_battery_props;
362 di->bat.properties = ds2760_battery_props; 377 di->bat.num_properties = ARRAY_SIZE(ds2760_battery_props);
363 di->bat.num_properties = ARRAY_SIZE(ds2760_battery_props); 378 di->bat.get_property = ds2760_battery_get_property;
364 di->bat.get_property = ds2760_battery_get_property;
365 di->bat.external_power_changed = 379 di->bat.external_power_changed =
366 ds2760_battery_external_power_changed; 380 ds2760_battery_external_power_changed;
367 381
@@ -373,6 +387,16 @@ static int ds2760_battery_probe(struct platform_device *pdev)
373 goto batt_failed; 387 goto batt_failed;
374 } 388 }
375 389
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
376 INIT_DELAYED_WORK(&di->monitor_work, ds2760_battery_work); 400 INIT_DELAYED_WORK(&di->monitor_work, ds2760_battery_work);
377 di->monitor_wqueue = create_singlethread_workqueue(dev_name(&pdev->dev)); 401 di->monitor_wqueue = create_singlethread_workqueue(dev_name(&pdev->dev));
378 if (!di->monitor_wqueue) { 402 if (!di->monitor_wqueue) {