mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH] bq27x00: Addition of POWER_SUPPLY_PROP_HEALTH property
       [not found] <CAF5reFh7-eroTCfN5MBKjmH4W7S_K-Z3MXoKU93sdtsNo0hxCA@mail.gmail.com>
@ 2011-08-24 13:12 ` Anton Vorontsov
  2011-09-20 15:00 ` Pali Rohár
  1 sibling, 0 replies; 2+ messages in thread
From: Anton Vorontsov @ 2011-08-24 13:12 UTC (permalink / raw)
  To: syed rafiuddin; +Cc: linux-kernel, Pali Rohár, vimal.newwork

On Wed, Aug 24, 2011 at 12:51:38PM +0530, 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@gmail.com>
> Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
> Reviewed-by: vimal singh <vimal.newwork@gmail.com>

The patch is whitespace damaged. :-(

Otherwise it looks good.

Thanks,

-- 
Anton Vorontsov
Email: cbouatmailru@gmail.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] bq27x00: Addition of POWER_SUPPLY_PROP_HEALTH property
       [not found] <CAF5reFh7-eroTCfN5MBKjmH4W7S_K-Z3MXoKU93sdtsNo0hxCA@mail.gmail.com>
  2011-08-24 13:12 ` [PATCH] bq27x00: Addition of POWER_SUPPLY_PROP_HEALTH property Anton Vorontsov
@ 2011-09-20 15:00 ` Pali Rohár
  1 sibling, 0 replies; 2+ messages in thread
From: Pali Rohár @ 2011-09-20 15:00 UTC (permalink / raw)
  To: syed rafiuddin; +Cc: linux-kernel, Anton Vorontsov, vimal.newwork

[-- Attachment #1: Type: text/plain, Size: 3620 bytes --]

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@gmail.com>
> Reviewed-by: Pali Rohár <pali.rohar@gmail.com>
> Reviewed-by: vimal singh <vimal.newwork@gmail.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@gmail.com

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-09-20 15:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAF5reFh7-eroTCfN5MBKjmH4W7S_K-Z3MXoKU93sdtsNo0hxCA@mail.gmail.com>
2011-08-24 13:12 ` [PATCH] bq27x00: Addition of POWER_SUPPLY_PROP_HEALTH property Anton Vorontsov
2011-09-20 15:00 ` Pali Rohár

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®