@@ -674,12 +674,15 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)
return POWER_SUPPLY_HEALTH_GOOD;
}
-void bq27xxx_battery_update(struct bq27xxx_device_info *di)
+static void __bq27xxx_battery_update(struct bq27xxx_device_info *di,
+ struct power_supply *psy)
{
struct bq27xxx_reg_cache cache = {0, };
bool has_ci_flag = di->chip == BQ27000 || di->chip == BQ27010;
bool has_singe_flag = di->chip == BQ27000 || di->chip == BQ27010;
+ WARN_ON(!psy);
+
cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag);
if ((cache.flags & 0xff) == 0xff)
cache.flags = -1; /* read error */
@@ -717,13 +720,25 @@ void bq27xxx_battery_update(struct bq27xxx_device_info *di)
di->charge_design_full = bq27xxx_battery_read_dcap(di);
}
- if (di->cache.capacity != cache.capacity)
- power_supply_changed(di->bat);
+ if (psy && di->cache.capacity != cache.capacity)
+ power_supply_changed(psy);
if (memcmp(&di->cache, &cache, sizeof(cache)) != 0)
di->cache = cache;
di->last_update = jiffies;
+
+ if (poll_interval > 0) {
+ /* The timer does not have to be accurate. */
+ set_timer_slack(&di->work.timer, poll_interval * HZ / 4);
+ schedule_delayed_work(&di->work, poll_interval * HZ);
+ }
+}
+
+void bq27xxx_battery_update(struct bq27xxx_device_info *di)
+{
+ cancel_delayed_work_sync(&di->work);
+ __bq27xxx_battery_update(di, di->bat);
}
EXPORT_SYMBOL_GPL(bq27xxx_battery_update);
@@ -733,13 +748,7 @@ static void bq27xxx_battery_poll(struct work_struct *work)
container_of(work, struct bq27xxx_device_info,
work.work);
- bq27xxx_battery_update(di);
-
- if (poll_interval > 0) {
- /* The timer does not have to be accurate. */
- set_timer_slack(&di->work.timer, poll_interval * HZ / 4);
- schedule_delayed_work(&di->work, poll_interval * HZ);
- }
+ __bq27xxx_battery_update(di, di->bat);
}
/*
@@ -874,7 +883,7 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
mutex_lock(&di->lock);
if (time_is_before_jiffies(di->last_update + 5 * HZ)) {
cancel_delayed_work_sync(&di->work);
- bq27xxx_battery_poll(&di->work.work);
+ __bq27xxx_battery_update(di, psy);
}
mutex_unlock(&di->lock);