Re: [rfc/patch 12/15] power: bq27200: add power property

From: Felipe Balbi
Date: Sun Jul 12 2009 - 16:12:00 EST


Hi,

On Sun, Jul 12, 2009 at 09:09:34PM +0300, Felipe Balbi wrote:
> @@ -190,6 +205,8 @@ static int bq27200_get_property(struct power_supply *psy,
> case POWER_SUPPLY_PROP_TEMP:
> val->intval = bq27200_temperature(bq);
> break;
> + case POWER_SUPPLY_PROP_POWER_AVG:
> + val->intval = bq27200_power(bq);

missing break here. Updated patch attached.

--
balbi
From c28459cbfa2dcdbb0c3f6ea7f662fb4f9a582ede Mon Sep 17 00:00:00 2001
From: Felipe Balbi <me@xxxxxxxxxxxxxxx>
Date: Wed, 8 Jul 2009 13:33:38 +0300
Subject: [PATCH 12/15] power: bq27200: add power property

report power average to userland.

Signed-off-by: Felipe Balbi <me@xxxxxxxxxxxxxxx>
---
drivers/power/bq27200_battery.c | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/drivers/power/bq27200_battery.c b/drivers/power/bq27200_battery.c
index 658c2c5..1b08f39 100644
--- a/drivers/power/bq27200_battery.c
+++ b/drivers/power/bq27200_battery.c
@@ -54,6 +54,7 @@

#define BQ27200_SENSING_RESISTOR (20) /* 20 mOhms */
#define BQ27200_CURRENT_CONSTANT (256 * 3570 / 1000) /* 256 * 3.57 uV */
+#define BQ27200_POWER_CONSTANT (256 * 29200 / 1000) /* 256 * 29.2 uVVh */

struct bq27200 {
struct power_supply bat;
@@ -73,6 +74,7 @@ static enum power_supply_property bq27200_props[] = {
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_TEMP,
+ POWER_SUPPLY_PROP_POWER_AVG,
};

/*
@@ -166,6 +168,19 @@ static int bq27200_rsoc(struct bq27200 *bq)
return ret >> 8;
}

+static int bq27200_power(struct bq27200 *bq)
+{
+ int ret;
+
+ ret = bq27200_readw(bq, BQ27200_REG_AP);
+ if (ret < 0) {
+ dev_err(&bq->client->dev, "error reading average power\n");
+ return ret;
+ }
+
+ return (ret * BQ27200_POWER_CONSTANT) / BQ27200_SENSING_RESISTOR;
+}
+
static int bq27200_get_property(struct power_supply *psy,
enum power_supply_property psp, union power_supply_propval *val)
{
@@ -190,6 +205,9 @@ static int bq27200_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_TEMP:
val->intval = bq27200_temperature(bq);
break;
+ case POWER_SUPPLY_PROP_POWER_AVG:
+ val->intval = bq27200_power(bq);
+ break;
default:
return -EINVAL;
}
--
1.6.4.rc0.17.gd9eb0