Re: [PATCH] bq27x00: Addition of POWER_SUPPLY_PROP_HEALTH property

From: Pali Rohár
Date: Tue Sep 20 2011 - 11:00:41 EST


On Wednesday 24 August 2011 12:51:38 syed rafiuddin wrote:
> This patch adds POWER_SUPPLY_PROP_HEALTH property which reports
> the battery state as good or dead.
>
> Signed-off-by: syed rafiuddin <rafiudidn.29@xxxxxxxxx>
> Reviewed-by: Pali Rohár <pali.rohar@xxxxxxxxx>
> Reviewed-by: vimal singh <vimal.newwork@xxxxxxxxx>
> ---
> drivers/power/bq27x00_battery.c | 37
> +++++++++++++++++++++++++++++++++++++
> 1 files changed, 37 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/power/bq27x00_battery.c
> b/drivers/power/bq27x00_battery.c
> index bb16f5b..2aeb1c2 100644
> --- a/drivers/power/bq27x00_battery.c
> +++ b/drivers/power/bq27x00_battery.c
> @@ -54,13 +54,16 @@
>
> #define BQ27000_REG_RSOC 0x0B /* Relative State-of-Charge */
> #define BQ27000_REG_ILMD 0x76 /* Initial last measured discharge */
> +#define BQ27000_FLAG_EDVF BIT(0)
> #define BQ27000_FLAG_CHGS BIT(7)
> #define BQ27000_FLAG_FC BIT(5)
>
> #define BQ27500_REG_SOC 0x2C
> #define BQ27500_REG_DCAP 0x3C /* Design capacity */
> #define BQ27500_FLAG_DSC BIT(0)
> +#define BQ27500_FLAG_SOCF BIT(1)
> #define BQ27500_FLAG_FC BIT(9)
> +#define BQ27500_FLAG_OTC BIT(15)
>
> #define BQ27000_RS 20 /* Resistor sense */
>
> @@ -118,6 +121,7 @@ static enum power_supply_property
> bq27x00_battery_props[] = {
> POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
> POWER_SUPPLY_PROP_CYCLE_COUNT,
> POWER_SUPPLY_PROP_ENERGY_NOW,
> + POWER_SUPPLY_PROP_HEALTH,
> };
>
> static unsigned int poll_interval = 360;
> @@ -437,6 +441,36 @@ static int bq27x00_simple_value(int value,
> return 0;
> }
>
> +static int bq27x00_battery_health(struct bq27x00_device_info *di,
> + union power_supply_propval *val)
> +{
> + int ret;
> + int status;
> +
> + ret = bq27x00_read(di, BQ27x00_REG_FLAGS, false);
> + if (ret < 0)
> + return ret;
> +
> + if (di->chip == BQ27500) {
> + 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;
> +
> + val->intval = status;
> + } else {
> + if (ret & BQ27000_FLAG_EDVF)
> + status = POWER_SUPPLY_HEALTH_DEAD;
> + else
> + status = POWER_SUPPLY_HEALTH_GOOD;
> +
> + val->intval = status;
> + }
> + return 0;
> +}
> +
> #define to_bq27x00_device_info(x) container_of((x), \
> struct bq27x00_device_info, bat);
>
> @@ -503,6 +537,9 @@ static int bq27x00_battery_get_property(struct
> power_supply *psy,
> case POWER_SUPPLY_PROP_ENERGY_NOW:
> ret = bq27x00_battery_energy(di, val);
> break;
> + case POWER_SUPPLY_PROP_HEALTH:
> + ret = bq27x00_battery_health(di, val);
> + break;
> default:
> return -EINVAL;
> }

Hello,

sorry for late comment, but

I looked into datasheet properly again and this patch does not do what is in
head message.

For bq27000/27200 battery:
BQ27000_FLAG_EDVF bit is set when battery is discharged to empty capacity
treshold. So I think that BQ27000_FLAG_EDVF can be used in power_supply for
POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL flag.

For bq27500 battery:
BQ27500_FLAG_SOCF bit indicate final discharge capacity warning. So it is
similar as EDVF bit for bq27000 battery.

BQ27500_FLAG_OTC bit is set when detected overtemperature in charging mode. So
I think only this flag can be used for POWER_SUPPLY_HEALTH property. Also in
datasheet is bit OTD which is set when detedted overtemperature in discharging
mode. So it could be set to POWER_SUPPLY_HEALTH_OVERHEAT too.

--
Pali Rohár
pali.rohar@xxxxxxxxx

Attachment: signature.asc
Description: This is a digitally signed message part.