Patchwork [1/1] power: bq27541_battery - Provide energy measurement

login
register
mail settings
Submitter Alex Hornung
Date Jan. 29, 2013, 6:57 p.m.
Message ID <51081B7F.40709@alexhornung.com>
Download mbox | patch
Permalink /patch/216628/
State New
Headers show

Comments

Alex Hornung - Jan. 29, 2013, 6:57 p.m.
Hi,

this patch addresses bug report 1109183[1].

It's a straight-forward patch adding support for energy measurements
from the fuel gauge chip. The 10mWh unit is straight from the datasheet
- everything else is straight forward, in line with other values the
chip provides.

Cheers,
Alex



[1]: https://bugs.launchpad.net/ubuntu-nexus7/+bug/1109183
Andy Whitcroft - Jan. 29, 2013, 7:48 p.m.
On Tue, Jan 29, 2013 at 06:57:03PM +0000, Alex Hornung wrote:
> Hi,
> 
> this patch addresses bug report 1109183[1].
> 
> It's a straight-forward patch adding support for energy measurements
> from the fuel gauge chip. The 10mWh unit is straight from the datasheet
> - everything else is straight forward, in line with other values the
> chip provides.
> 
> Cheers,
> Alex
> 
> 
> 
> [1]: https://bugs.launchpad.net/ubuntu-nexus7/+bug/1109183

> From 715aaf72d40a5a68cca29a4a4e3dd242ee4fb38c Mon Sep 17 00:00:00 2001
> From: Alex Hornung <alex@alexhornung.com>
> Date: Mon, 28 Jan 2013 18:47:48 +0000
> Subject: [PATCH 1/1] power: bq27541_battery - Provide energy measurement
> 
>  * Since the fuel gauge chip provides energy estimates, expose
>    those as well.
> 
> Signed-off-by: Alex Hornung <alex@alexhornung.com>
> ---
>  drivers/power/bq27541_battery.c |    9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/power/bq27541_battery.c b/drivers/power/bq27541_battery.c
> index 9ce5c2d..c433043 100755
> --- a/drivers/power/bq27541_battery.c
> +++ b/drivers/power/bq27541_battery.c
> @@ -111,6 +111,7 @@ enum {
>  	REG_CAPACITY,
>  	REG_SERIAL_NUMBER,
>  	REG_CHARGE_NOW,
> +	REG_ENERGY,
>  	REG_POWER,
>  	REG_CYCLE,
>  
> @@ -142,6 +143,7 @@ static struct bq27541_device_data {
>  	[REG_CAPACITY]				= BQ27541_DATA(CAPACITY, 0x2c, 0, 100),
>  
>  	[REG_CHARGE_NOW]			= BQ27541_DATA(CHARGE_NOW, 0x10, 0, 65535),
> +	[REG_ENERGY]				= BQ27541_DATA(ENERGY_NOW, 0x22, 0, 65535),
>  	[REG_POWER]				= BQ27541_DATA(POWER_AVG, 0x24, 0, 65535),
>  	[REG_CYCLE]				= BQ27541_DATA(CYCLE_COUNT, 0x2a, 0, 65535),
>  
> @@ -156,6 +158,7 @@ static enum power_supply_property bq27541_properties[] = {
>  	POWER_SUPPLY_PROP_CAPACITY,
>  	POWER_SUPPLY_PROP_TEMP,
>  	POWER_SUPPLY_PROP_CHARGE_NOW,
> +	POWER_SUPPLY_PROP_ENERGY_NOW,
>  	POWER_SUPPLY_PROP_CYCLE_COUNT
>  };
>  
> @@ -505,6 +508,11 @@ static int bq27541_get_psp(int reg_offset, enum power_supply_property psp,
>  		val->intval = rt_value * 1000;
>  		BAT_NOTICE("charge_now = %u uA\n", val->intval);
>  	}
> +	if (psp == POWER_SUPPLY_PROP_ENERGY_NOW) {
> +		/* energy is reported in 10 mWh */
> +		val->intval = rt_value * 10000;
> +		BAT_NOTICE("energy_now = %u uWh\n", val->intval);
> +	}
>  	if (psp == POWER_SUPPLY_PROP_CYCLE_COUNT) {
>  		val->intval = rt_value;
>  		BAT_NOTICE("cycle count = %u\n", val->intval);
> @@ -714,6 +722,7 @@ static int bq27541_get_property(struct power_supply *psy,
>  		case POWER_SUPPLY_PROP_TEMP:
>  		case POWER_SUPPLY_PROP_SERIAL_NUMBER:
>  		case POWER_SUPPLY_PROP_CHARGE_NOW:
> +		case POWER_SUPPLY_PROP_ENERGY_NOW:
>  		case POWER_SUPPLY_PROP_CYCLE_COUNT:
>  			for (count = 0; count < REG_MAX; count++) {
>  				if (psp == bq27541_data[count].psp)
> -- 
> 1.7.10.4

Taking the units on faith, this seems to add a resonable additional
measurement.

Alex, I am assuming you are upstreaming this in paralllel, do keep us
in the loop if there are any changes.

Otherwise it looks a useful addition, not too invasive.

Acked-by: Andy Whitcroft <apw@canonical.com>

We'll want to get some testing on this once it hits.

-apw
Leann Ogasawara - Jan. 29, 2013, 7:56 p.m.
Acked-by: Leann Ogasawara <leann.ogasawara@canonical.com>

On 01/29/2013 10:57 AM, Alex Hornung wrote:
> Hi,
>
> this patch addresses bug report 1109183[1].
>
> It's a straight-forward patch adding support for energy measurements
> from the fuel gauge chip. The 10mWh unit is straight from the datasheet
> - everything else is straight forward, in line with other values the
> chip provides.
>
> Cheers,
> Alex
>
>
>
> [1]: https://bugs.launchpad.net/ubuntu-nexus7/+bug/1109183
>
>
Andy Whitcroft - Jan. 29, 2013, 8:25 p.m.
Applied to ubuntu-nexus7.

-apw
Alex Hornung - Jan. 29, 2013, 9:31 p.m.
On 29/01/13 19:48, Andy Whitcroft wrote:
> Alex, I am assuming you are upstreaming this in paralllel, do keep us
> in the loop if there are any changes.

It's submitted upstream here:

https://android-review.googlesource.com/#/c/50732/


Cheers,
Alex

Patch

From 715aaf72d40a5a68cca29a4a4e3dd242ee4fb38c Mon Sep 17 00:00:00 2001
From: Alex Hornung <alex@alexhornung.com>
Date: Mon, 28 Jan 2013 18:47:48 +0000
Subject: [PATCH 1/1] power: bq27541_battery - Provide energy measurement

 * Since the fuel gauge chip provides energy estimates, expose
   those as well.

Signed-off-by: Alex Hornung <alex@alexhornung.com>
---
 drivers/power/bq27541_battery.c |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/power/bq27541_battery.c b/drivers/power/bq27541_battery.c
index 9ce5c2d..c433043 100755
--- a/drivers/power/bq27541_battery.c
+++ b/drivers/power/bq27541_battery.c
@@ -111,6 +111,7 @@  enum {
 	REG_CAPACITY,
 	REG_SERIAL_NUMBER,
 	REG_CHARGE_NOW,
+	REG_ENERGY,
 	REG_POWER,
 	REG_CYCLE,
 
@@ -142,6 +143,7 @@  static struct bq27541_device_data {
 	[REG_CAPACITY]				= BQ27541_DATA(CAPACITY, 0x2c, 0, 100),
 
 	[REG_CHARGE_NOW]			= BQ27541_DATA(CHARGE_NOW, 0x10, 0, 65535),
+	[REG_ENERGY]				= BQ27541_DATA(ENERGY_NOW, 0x22, 0, 65535),
 	[REG_POWER]				= BQ27541_DATA(POWER_AVG, 0x24, 0, 65535),
 	[REG_CYCLE]				= BQ27541_DATA(CYCLE_COUNT, 0x2a, 0, 65535),
 
@@ -156,6 +158,7 @@  static enum power_supply_property bq27541_properties[] = {
 	POWER_SUPPLY_PROP_CAPACITY,
 	POWER_SUPPLY_PROP_TEMP,
 	POWER_SUPPLY_PROP_CHARGE_NOW,
+	POWER_SUPPLY_PROP_ENERGY_NOW,
 	POWER_SUPPLY_PROP_CYCLE_COUNT
 };
 
@@ -505,6 +508,11 @@  static int bq27541_get_psp(int reg_offset, enum power_supply_property psp,
 		val->intval = rt_value * 1000;
 		BAT_NOTICE("charge_now = %u uA\n", val->intval);
 	}
+	if (psp == POWER_SUPPLY_PROP_ENERGY_NOW) {
+		/* energy is reported in 10 mWh */
+		val->intval = rt_value * 10000;
+		BAT_NOTICE("energy_now = %u uWh\n", val->intval);
+	}
 	if (psp == POWER_SUPPLY_PROP_CYCLE_COUNT) {
 		val->intval = rt_value;
 		BAT_NOTICE("cycle count = %u\n", val->intval);
@@ -714,6 +722,7 @@  static int bq27541_get_property(struct power_supply *psy,
 		case POWER_SUPPLY_PROP_TEMP:
 		case POWER_SUPPLY_PROP_SERIAL_NUMBER:
 		case POWER_SUPPLY_PROP_CHARGE_NOW:
+		case POWER_SUPPLY_PROP_ENERGY_NOW:
 		case POWER_SUPPLY_PROP_CYCLE_COUNT:
 			for (count = 0; count < REG_MAX; count++) {
 				if (psp == bq27541_data[count].psp)
-- 
1.7.10.4