public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali.rohar@gmail.com>
To: linux-kernel@vger.kernel.org, Anton Vorontsov <cbou@mail.ru>,
	syed rafiuddin <rafiuddin.sayed@gmail.com>,
	Rodolfo Giometti <giometti@linux.it>,
	Lars-Peter Clausen <lars@metafoo.de>,
	David Woodhouse <dwmw2@infradead.org>
Cc: "Pali Rohár" <pali.rohar@gmail.com>
Subject: [PATCH 4/9] bq27x00: Cache energy property
Date: Tue,  1 Nov 2011 01:43:06 +0100	[thread overview]
Message-ID: <1320108191-6647-4-git-send-email-pali.rohar@gmail.com> (raw)
In-Reply-To: <1320108191-6647-1-git-send-email-pali.rohar@gmail.com>

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
---
 drivers/power/bq27x00_battery.c |   53 +++++++++++++++++++--------------------
 1 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index 6c8dfdb..e9aeb53 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -84,6 +84,7 @@ struct bq27x00_reg_cache {
 	int charge_full;
 	int cycle_count;
 	int capacity;
+	int energy;
 	int flags;
 };
 
@@ -225,6 +226,28 @@ static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di)
 }
 
 /*
+ * Return the battery Available energy in µWh
+ * Or < 0 if something fails.
+ */
+static int bq27x00_battery_read_energy(struct bq27x00_device_info *di)
+{
+	int ae;
+
+	ae = bq27x00_read(di, BQ27x00_REG_AE, false);
+	if (ae < 0) {
+		dev_err(di->dev, "error reading available energy\n");
+		return ae;
+	}
+
+	if (di->chip == BQ27500)
+		ae *= 1000;
+	else
+		ae = ae * 29200 / BQ27000_RS;
+
+	return ae;
+}
+
+/*
  * Return the battery Cycle count total
  * Or < 0 if something fails.
  */
@@ -268,12 +291,14 @@ static void bq27x00_update(struct bq27x00_device_info *di)
 	if (cache.flags >= 0) {
 		if (!is_bq27500 && (cache.flags & BQ27000_FLAG_CI)) {
 			cache.capacity = -ENODATA;
+			cache.energy = -ENODATA;
 			cache.time_to_empty = -ENODATA;
 			cache.time_to_empty_avg = -ENODATA;
 			cache.time_to_full = -ENODATA;
 			cache.charge_full = -ENODATA;
 		} else {
 			cache.capacity = bq27x00_battery_read_rsoc(di);
+			cache.energy = bq27x00_battery_read_energy(di);
 			cache.time_to_empty = bq27x00_battery_read_time(di, BQ27x00_REG_TTE);
 			cache.time_to_empty_avg = bq27x00_battery_read_time(di, BQ27x00_REG_TTECP);
 			cache.time_to_full = bq27x00_battery_read_time(di, BQ27x00_REG_TTF);
@@ -435,32 +460,6 @@ static int bq27x00_battery_voltage(struct bq27x00_device_info *di,
 	return 0;
 }
 
-/*
- * Return the battery Available energy in µWh
- * Or < 0 if something fails.
- */
-static int bq27x00_battery_energy(struct bq27x00_device_info *di,
-	union power_supply_propval *val)
-{
-	int ae;
-
-	ae = bq27x00_read(di, BQ27x00_REG_AE, false);
-	if (ae < 0) {
-		dev_err(di->dev, "error reading available energy\n");
-		return ae;
-	}
-
-	if (di->chip == BQ27500)
-		ae *= 1000;
-	else
-		ae = ae * 29200 / BQ27000_RS;
-
-	val->intval = ae;
-
-	return 0;
-}
-
-
 static int bq27x00_simple_value(int value,
 	union power_supply_propval *val)
 {
@@ -539,7 +538,7 @@ static int bq27x00_battery_get_property(struct power_supply *psy,
 		ret = bq27x00_simple_value(di->cache.cycle_count, val);
 		break;
 	case POWER_SUPPLY_PROP_ENERGY_NOW:
-		ret = bq27x00_battery_energy(di, val);
+		ret = bq27x00_simple_value(di->cache.energy, val);
 		break;
 	default:
 		return -EINVAL;
-- 
1.7.5.4


  parent reply	other threads:[~2011-11-01  0:47 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-20 15:18 [PATCH 1/7] bq27x00: Do not cache current_now value for bq27000 batery Pali Rohár
2011-09-20 15:18 ` [PATCH 2/7] bq27x00: Add support for property POWER_SUPPLY_PROP_CAPACITY_LEVEL Pali Rohár
2011-09-20 15:18 ` [PATCH 3/7] bq27x00: Report -ENODATA if bq27000 battery was not calibrated Pali Rohár
2011-09-20 15:18 ` [PATCH 4/7] bq27x00: Cache energy property Pali Rohár
2011-09-20 15:18 ` [PATCH 5/7] bq27x00: Cache temperature value in converted unit Pali Rohár
2011-09-20 15:18 ` [PATCH 6/7] bq27x00: Fix reporting status value for bq27500 battery Pali Rohár
2011-09-20 15:18 ` [PATCH 7/7] bq27x00: Fix reporting error messages Pali Rohár
2011-11-01  0:43 ` [PATCH 1/9] bq27x00: Do not cache current_now value for bq27000 batery Pali Rohár
2011-11-01  0:43   ` [PATCH 2/9] bq27x00: Add support for property POWER_SUPPLY_PROP_CAPACITY_LEVEL Pali Rohár
2011-11-01  0:43   ` [PATCH 3/9] bq27x00: Report -ENODATA if bq27000 battery was not calibrated Pali Rohár
2011-11-01  0:43   ` Pali Rohár [this message]
2011-11-01  0:43   ` [PATCH 5/9] bq27x00: Cache temperature value in converted unit Pali Rohár
2011-11-01  0:43   ` [PATCH 6/9] bq27x00: Fix reporting status value for bq27500 battery Pali Rohár
2011-11-01  0:43   ` [PATCH 7/9] bq27x00: Fix reporting error messages Pali Rohár
2011-11-01  0:43   ` [PATCH 8/9] bq27x00: Add miscdevice for each battery with ioctl for reading registers Pali Rohár
2011-11-01 12:09     ` Lars-Peter Clausen
2011-11-01 12:23       ` Pali Rohár
2011-11-01 12:46         ` Lars-Peter Clausen
2011-11-01 12:53           ` Pali Rohár
2011-11-25 20:10             ` Anton Vorontsov
2011-11-25 20:30               ` Pali Rohár
2011-11-25 20:46                 ` Anton Vorontsov
2011-11-25 20:54                   ` Pali Rohár
2011-11-25 22:04                     ` Anton Vorontsov
2011-11-25 22:48                       ` Pali Rohár
2011-11-27 11:54                       ` Mark Brown
2011-12-05 19:37                         ` Pali Rohár
2011-12-05 19:40                           ` Mark Brown
2011-11-01  0:43   ` [PATCH 9/9] bq27x00: Fix OOPS caused by unregistring bq27x00 driver Pali Rohár
2011-11-13 20:54     ` Pali Rohár
2011-11-25 22:53 ` [PATCH] rx51: add bq27200 i2c board info Pali Rohár
2011-11-25 23:03   ` Anton Vorontsov
2011-12-05 19:24     ` Felipe Contreras
2011-12-06 15:49     ` Pali Rohár
2011-12-07 20:25     ` Tony Lindgren
2011-12-17  9:55       ` Pali Rohár
2012-01-06  1:41       ` 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=1320108191-6647-4-git-send-email-pali.rohar@gmail.com \
    --to=pali.rohar@gmail.com \
    --cc=cbou@mail.ru \
    --cc=dwmw2@infradead.org \
    --cc=giometti@linux.it \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafiuddin.sayed@gmail.com \
    /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