mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Juergen Borleis <jbe@pengutronix.de>
To: linux-kernel@vger.kernel.org
Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>,
	kernel@pengutronix.de
Subject: [PATCH 6/7] bq27xxx: init the cache first
Date: Tue, 10 Jun 2014 11:44:52 +0200	[thread overview]
Message-ID: <1402393493-3559-7-git-send-email-jbe@pengutronix.de> (raw)
In-Reply-To: <1402393493-3559-1-git-send-email-jbe@pengutronix.de>

While registering the power supply the framework starts to query immediately.
This change ensures providing consistent information.

Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
---
 drivers/power/bq27x00_battery.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index 3f3169e..0a02d86 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -124,6 +124,8 @@ struct bq27x00_device_info {
 	struct bq27x00_access_methods bus;
 
 	struct mutex lock;
+
+	bool dev_accessible; /* true when the device is accessible */
 };
 
 static enum power_supply_property bq27x00_battery_props[] = {
@@ -178,6 +180,19 @@ static inline int bq27x00_read(struct bq27x00_device_info *di, u8 reg,
 	return di->bus.read(di, reg, single);
 }
 
+static void bq27245_init_cache(struct bq27x00_reg_cache *cache)
+{
+	cache->temperature = cache->time_to_empty = cache->time_to_empty_avg =
+		cache->time_to_full = cache->charge_full = cache->cycle_count =
+		cache->capacity = cache->energy = cache->flags =
+		cache->power_avg = cache->health = -ENODATA;
+}
+
+static void bq27xxx_is_awake(struct bq27x00_device_info *di)
+{
+	di->dev_accessible = true;
+}
+
 /*
  * Higher versions of the chip like BQ27425 and BQ27500
  * differ from BQ27000 and BQ27200 in calculation of certain
@@ -748,17 +763,20 @@ static int bq27x00_powersupply_init(struct bq27x00_device_info *di)
 	INIT_DELAYED_WORK(&di->work, bq27x00_battery_poll);
 	mutex_init(&di->lock);
 
+	dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION);
+
+	/* expect the chip is accessible for now */
+	bq27xxx_is_awake(di);
+	/* we get queried immediately, so init our cache first */
+	bq27245_init_cache(&di->cache);
+
 	ret = power_supply_register(di->dev, &di->bat);
-	if (ret) {
+	if (ret)
 		dev_err(di->dev, "failed to register battery: %d\n", ret);
-		return ret;
-	}
-
-	dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION);
 
 	bq27x00_update(di);
 
-	return 0;
+	return ret;
 }
 
 static void bq27x00_powersupply_unregister(struct bq27x00_device_info *di)
-- 
2.0.0.rc2


  parent reply	other threads:[~2014-06-10  9:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-10  9:44 Power/battery/BQ27xxx: some fixes and hot-plug support Juergen Borleis
2014-06-10  9:44 ` [PATCH 1/7] bq27425: fix register offset for SOC on bq27425 Juergen Borleis
2014-06-10  9:44 ` [PATCH 2/7] bq27425: add support to read the control registers Juergen Borleis
2014-06-10  9:44 ` [PATCH 3/7] bq27425: add support for different firmware chip types Juergen Borleis
2014-06-10  9:44 ` [PATCH 4/7] bq27425: the DesignCapacity register is at a different offset Juergen Borleis
2014-06-10  9:44 ` [PATCH 5/7] bq27xxx: suppress error messages Juergen Borleis
2014-06-10  9:44 ` Juergen Borleis [this message]
2014-06-10  9:44 ` [PATCH 7/7] bq27xxx: enable hot-plug support Juergen Borleis
2014-07-08  8:28 ` Power/battery/BQ27xxx: some fixes and " Steffen Trumtrar

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=1402393493-3559-7-git-send-email-jbe@pengutronix.de \
    --to=jbe@pengutronix.de \
    --cc=dbaryshkov@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®