lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Tue, 20 Sep 2011 17:00:18 +0200
From:	Pali Rohár <pali.rohar@...il.com>
To:	syed rafiuddin <rafiuddin.sayed@...il.com>
Cc:	linux-kernel@...r.kernel.org, Anton Vorontsov <cbou@...l.ru>,
	vimal.newwork@...il.com
Subject: Re: [PATCH] bq27x00: Addition of POWER_SUPPLY_PROP_HEALTH property

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@...il.com>
> Reviewed-by: Pali Rohár <pali.rohar@...il.com>
> Reviewed-by: vimal singh <vimal.newwork@...il.com>
> ---
>  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@...il.com
Download attachment "signature.asc" of type "application/pgp-signature" (199 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ