lkml.org 
[lkml]   [2011]   [Feb]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 3/4] power: bq20z75: add support for POWER_NOW
Date
From: Rhyland Klein <rklein@nvidia.com>

Adding support for POWER_NOW property. Returns the product of current and
voltage in terms of uW.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
drivers/power/bq20z75.c | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/drivers/power/bq20z75.c b/drivers/power/bq20z75.c
index e82d10e..7558d51 100644
--- a/drivers/power/bq20z75.c
+++ b/drivers/power/bq20z75.c
@@ -142,6 +142,7 @@ static enum power_supply_property bq20z75_properties[] = {
POWER_SUPPLY_PROP_CHARGE_NOW,
POWER_SUPPLY_PROP_CHARGE_FULL,
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
+ POWER_SUPPLY_PROP_POWER_NOW,
};

struct bq20z75_info {
@@ -411,6 +412,32 @@ static int bq20z75_get_battery_capacity(struct i2c_client *client,
return 0;
}

+static int bq20z75_get_power_now(struct i2c_client *client,
+ union power_supply_propval *val)
+{
+ int voltage_now = 0;
+ int current_now = 0;
+
+ voltage_now = bq20z75_read_word_data(client,
+ bq20z75_data[REG_VOLTAGE].addr);
+ if (voltage_now < 0)
+ return voltage_now;
+
+ current_now = bq20z75_read_word_data(client,
+ bq20z75_data[REG_CURRENT].addr);
+ if (current_now < 0)
+ return current_now;
+
+ /* returned values are 16 bit */
+ current_now = (s16)current_now;
+ /* need to ensure it is positive */
+ current_now = abs(current_now);
+
+ val->intval = voltage_now * current_now;
+
+ return 0;
+}
+
static char bq20z75_serial[5];
static int bq20z75_get_battery_serial_number(struct i2c_client *client,
union power_supply_propval *val)
@@ -475,6 +502,10 @@ static int bq20z75_get_property(struct power_supply *psy,
ret = bq20z75_get_battery_capacity(client, ret, psp, val);
break;

+ case POWER_SUPPLY_PROP_POWER_NOW:
+ ret = bq20z75_get_power_now(client, val);
+ break;
+
case POWER_SUPPLY_PROP_SERIAL_NUMBER:
ret = bq20z75_get_battery_serial_number(client, val);
break;
--
1.7.0.4


\
 
 \ /
  Last update: 2011-03-01 01:59    [W:0.129 / U:0.336 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site