summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorsyed rafiuddin <srafiuddin@nvidia.com>2011-05-12 12:36:23 +0530
committerVarun Colbert <vcolbert@nvidia.com>2011-05-18 11:46:03 -0700
commit0e88b6e178abfa50cbd594f48f972f390ce5a6bf (patch)
tree7862f63f5561ebe927bf926441e263c5438f5711 /drivers
parent342ec3b7714c672cbccaf72be8872cc555e28611 (diff)
power: battery: bq27x00: add "health" property
Addition of Health property which informs the health of the battery like good, dead and over charge. Bug 786669 Change-Id: I4ed3684ec4e777d110f3c5bd2a062ac5be22c6e2 Reviewed-on: http://git-master/r/30505 Reviewed-by: Varun Wadekar <vwadekar@nvidia.com> Reviewed-by: Mayuresh Kulkarni <mkulkarni@nvidia.com> Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com> Tested-by: Varun Colbert <vcolbert@nvidia.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/power/bq27x00_battery.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index 8f3d8cc0556a..00eaacb9466b 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -45,8 +45,10 @@
#define BQ27500_REG_SOC 0x2c
#define BQ27500_FLAG_DSC BIT(0)
+#define BQ27500_FLAG_SOCF BIT(1)
#define BQ27500_FLAG_BAT_DET BIT(3)
#define BQ27500_FLAG_FC BIT(9)
+#define BQ27500_FLAG_OTC BIT(15)
#define BQ27510_CNTL 0x00
#define BQ27510_ATRATE 0x02
@@ -103,6 +105,7 @@ static enum power_supply_property bq27x00_battery_props[] = {
POWER_SUPPLY_PROP_CYCLE_COUNT,
POWER_SUPPLY_PROP_TECHNOLOGY,
POWER_SUPPLY_PROP_SERIAL_NUMBER,
+ POWER_SUPPLY_PROP_HEALTH,
};
/*
@@ -115,6 +118,31 @@ static int bq27x00_read(u8 reg, int *rt_value, int b_single,
return di->bus->read(reg, rt_value, b_single, di);
}
+static int bq27510_battery_health(struct bq27x00_device_info *di,
+ int reg_offset)
+{
+ int ret;
+ int status;
+
+ if (di->chip == BQ27500 || di->chip == BQ27510) {
+ ret = i2c_smbus_read_word_data(di->client, reg_offset);
+ if (ret < 0) {
+ dev_err(di->dev, "read failure\n");
+ return ret;
+ }
+
+ if (ret & BQ27500_FLAG_SOCF)
+ status = POWER_SUPPLY_HEALTH_DEAD;
+ else if (ret & BQ27500_FLAG_OTC)
+ status = POWER_SUPPLY_HEALTH_OVERHEAT;
+ else
+ status = POWER_SUPPLY_HEALTH_GOOD;
+ return status;
+ }
+
+ return -1;
+}
+
/*
* Return the battery temperature in tenths of degree Celsius
* Or < 0 if something fails.
@@ -407,6 +435,9 @@ static int bq27x00_battery_get_property(struct power_supply *psy,
if (bq27510_get_battery_serial_number(di, val))
return -EINVAL;
break;
+ case POWER_SUPPLY_PROP_HEALTH:
+ val->intval = bq27510_battery_health(di, BQ27x00_REG_FLAGS);
+ break;
default:
return -EINVAL;
}