lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 10 Jun 2014 11:44:52 +0200
From:	Juergen Borleis <jbe@...gutronix.de>
To:	linux-kernel@...r.kernel.org
Cc:	Dmitry Eremin-Solenikov <dbaryshkov@...il.com>,
	David Woodhouse <dwmw2@...radead.org>, kernel@...gutronix.de
Subject: [PATCH 6/7] bq27xxx: init the cache first

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

Signed-off-by: Juergen Borleis <jbe@...gutronix.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

--
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

Powered by Openwall GNU/*/Linux Powered by OpenVZ