aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/bq27x00_battery.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2011-10-31 20:43:04 -0400
committerAnton Vorontsov <cbouatmailru@gmail.com>2011-11-25 14:57:48 -0500
commitd66bab3f3a5119084ac0ed010a7eae0000af4f16 (patch)
treea4a82bcd3912fc54dbf1a3ff3975325e0b67ebe0 /drivers/power/bq27x00_battery.c
parentb68f6216c5f53698379603209d3168766449fdab (diff)
bq27x00_battery: Add support for property POWER_SUPPLY_PROP_CAPACITY_LEVEL
Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
Diffstat (limited to 'drivers/power/bq27x00_battery.c')
-rw-r--r--drivers/power/bq27x00_battery.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index d238144d1e81..a5311225b964 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -54,12 +54,16 @@
54 54
55#define BQ27000_REG_RSOC 0x0B /* Relative State-of-Charge */ 55#define BQ27000_REG_RSOC 0x0B /* Relative State-of-Charge */
56#define BQ27000_REG_ILMD 0x76 /* Initial last measured discharge */ 56#define BQ27000_REG_ILMD 0x76 /* Initial last measured discharge */
57#define BQ27000_FLAG_CHGS BIT(7) 57#define BQ27000_FLAG_EDVF BIT(0) /* Final End-of-Discharge-Voltage flag */
58#define BQ27000_FLAG_EDV1 BIT(1) /* First End-of-Discharge-Voltage flag */
58#define BQ27000_FLAG_FC BIT(5) 59#define BQ27000_FLAG_FC BIT(5)
60#define BQ27000_FLAG_CHGS BIT(7) /* Charge state flag */
59 61
60#define BQ27500_REG_SOC 0x2C 62#define BQ27500_REG_SOC 0x2C
61#define BQ27500_REG_DCAP 0x3C /* Design capacity */ 63#define BQ27500_REG_DCAP 0x3C /* Design capacity */
62#define BQ27500_FLAG_DSC BIT(0) 64#define BQ27500_FLAG_DSC BIT(0)
65#define BQ27500_FLAG_SOCF BIT(1) /* State-of-Charge threshold final */
66#define BQ27500_FLAG_SOC1 BIT(2) /* State-of-Charge threshold 1 */
63#define BQ27500_FLAG_FC BIT(9) 67#define BQ27500_FLAG_FC BIT(9)
64 68
65#define BQ27000_RS 20 /* Resistor sense */ 69#define BQ27000_RS 20 /* Resistor sense */
@@ -106,6 +110,7 @@ static enum power_supply_property bq27x00_battery_props[] = {
106 POWER_SUPPLY_PROP_VOLTAGE_NOW, 110 POWER_SUPPLY_PROP_VOLTAGE_NOW,
107 POWER_SUPPLY_PROP_CURRENT_NOW, 111 POWER_SUPPLY_PROP_CURRENT_NOW,
108 POWER_SUPPLY_PROP_CAPACITY, 112 POWER_SUPPLY_PROP_CAPACITY,
113 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
109 POWER_SUPPLY_PROP_TEMP, 114 POWER_SUPPLY_PROP_TEMP,
110 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, 115 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
111 POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, 116 POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
@@ -373,6 +378,36 @@ static int bq27x00_battery_status(struct bq27x00_device_info *di,
373 return 0; 378 return 0;
374} 379}
375 380
381static int bq27x00_battery_capacity_level(struct bq27x00_device_info *di,
382 union power_supply_propval *val)
383{
384 int level;
385
386 if (di->chip == BQ27500) {
387 if (di->cache.flags & BQ27500_FLAG_FC)
388 level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
389 else if (di->cache.flags & BQ27500_FLAG_SOC1)
390 level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
391 else if (di->cache.flags & BQ27500_FLAG_SOCF)
392 level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
393 else
394 level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
395 } else {
396 if (di->cache.flags & BQ27000_FLAG_FC)
397 level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
398 else if (di->cache.flags & BQ27000_FLAG_EDV1)
399 level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
400 else if (di->cache.flags & BQ27000_FLAG_EDVF)
401 level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
402 else
403 level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
404 }
405
406 val->intval = level;
407
408 return 0;
409}
410
376/* 411/*
377 * Return the battery Voltage in milivolts 412 * Return the battery Voltage in milivolts
378 * Or < 0 if something fails. 413 * Or < 0 if something fails.
@@ -464,6 +499,9 @@ static int bq27x00_battery_get_property(struct power_supply *psy,
464 case POWER_SUPPLY_PROP_CAPACITY: 499 case POWER_SUPPLY_PROP_CAPACITY:
465 ret = bq27x00_simple_value(di->cache.capacity, val); 500 ret = bq27x00_simple_value(di->cache.capacity, val);
466 break; 501 break;
502 case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
503 ret = bq27x00_battery_capacity_level(di, val);
504 break;
467 case POWER_SUPPLY_PROP_TEMP: 505 case POWER_SUPPLY_PROP_TEMP:
468 ret = bq27x00_battery_temperature(di, val); 506 ret = bq27x00_battery_temperature(di, val);
469 break; 507 break;