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

Signed-off-by: Juergen Borleis <[email protected]>
---
 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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to