[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1298940931-17552-4-git-send-email-rklein@nvidia.com>
Date: Mon, 28 Feb 2011 16:55:30 -0800
From: rklein@...dia.com
To: Anton Vorontsov <cbouatmailru@...il.com>
Cc: olof@...om.net, linux-kernel@...r.kernel.org,
Rhyland Klein <rklein@...dia.com>
Subject: [PATCH 3/4] power: bq20z75: add support for POWER_NOW
From: Rhyland Klein <rklein@...dia.com>
Adding support for POWER_NOW property. Returns the product of current and
voltage in terms of uW.
Signed-off-by: Rhyland Klein <rklein@...dia.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists