From: rklein@nvidia.com
To: Anton Vorontsov <cbouatmailru@gmail.com>
Cc: olof@lixom.net, linux-kernel@vger.kernel.org,
Rhyland Klein <rklein@nvidia.com>
Subject: [PATCH 3/4] power: bq20z75: add support for POWER_NOW
Date: Mon, 28 Feb 2011 16:55:30 -0800 [thread overview]
Message-ID: <1298940931-17552-4-git-send-email-rklein@nvidia.com> (raw)
In-Reply-To: <1298940931-17552-1-git-send-email-rklein@nvidia.com>
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
next prev parent reply other threads:[~2011-03-01 0:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-01 0:55 [PATCH 0/4] power: bq20z75: update support rklein
2011-03-01 0:55 ` [PATCH 1/4] power: bq20z75: add optional battery detect gpio rklein
2011-03-01 0:55 ` [PATCH 2/4] power: bq20z75: add i2c retry mechanism rklein
2011-03-01 0:55 ` rklein [this message]
2011-03-01 19:39 ` [PATCH 3/4] power: bq20z75: add support for POWER_NOW Anton Vorontsov
2011-03-01 0:55 ` [PATCH 4/4] power_supply: update power_supply_is_watt_property rklein
2011-03-01 19:41 ` [PATCH 0/4] power: bq20z75: update support Anton Vorontsov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1298940931-17552-4-git-send-email-rklein@nvidia.com \
--to=rklein@nvidia.com \
--cc=cbouatmailru@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=olof@lixom.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox