power:qpnp-bms: use jiffies in bms_resume interface
Bms_resume interface uses monotonic boottime. When watch is resumed by rtc_alarm(60s)
and the soc calculated period(20s) has arrived, it will set wake_lock(qpnp_soc_wake)
and triger bms module to recalculate soc. However, beacuse of the wake_lock, watch cost
at most 1.2s at one mins update and consumes more power.
When use jiffies, will reduce the soc calculated times, and reduce one mins update to 350ms.
Reduce the average power consumption of ambient mode about 0.3 ~ 0.6 mA.
Change-Id: I4dddb890c8c2d474c089885898cafc87b203c1cf
Signed-off-by: libing <l00228880@notesmail.huawei.com>
diff --git a/drivers/power/qpnp-bms.c b/drivers/power/qpnp-bms.c
index 7450df8..6c7262d 100644
--- a/drivers/power/qpnp-bms.c
+++ b/drivers/power/qpnp-bms.c
@@ -349,6 +349,7 @@
int warm_reset_shutdown_soc_valid_limit;
int estimate_new_ocv_flag;
const char *battery_type;
+ unsigned long last_recalc_time_by_jiffies;
#endif
};
@@ -3088,6 +3089,9 @@
}
get_current_time(&chip->last_recalc_time);
+#ifdef CONFIG_HUAWEI_BATTERY_SETTING
+ chip->last_recalc_time_by_jiffies = (unsigned long)div_u64(get_jiffies_64(),HZ);
+#endif
chip->first_time_calc_soc = 0;
chip->first_time_calc_uuc = 0;
return chip->calculated_soc;
@@ -5352,7 +5356,7 @@
static int bms_resume(struct device *dev)
{
- int rc;
+ int rc = 0;
int soc_calc_period;
int time_until_next_recalc = 0;
unsigned long time_since_last_recalc;
@@ -5362,13 +5366,21 @@
int sleep_duration;
uint16_t ocv_raw;
+#ifdef CONFIG_HUAWEI_BATTERY_SETTING
+ tm_now_sec = (unsigned long)div_u64(get_jiffies_64(),HZ);
+#else
rc = get_current_time(&tm_now_sec);
+#endif
if (rc) {
pr_err("Could not read current time: %d\n", rc);
tm_now_sec = 0;
} else {
soc_calc_period = get_calculation_delay_ms(chip);
+#ifdef CONFIG_HUAWEI_BATTERY_SETTING
+ time_since_last_recalc = tm_now_sec - chip->last_recalc_time_by_jiffies;
+#else
time_since_last_recalc = tm_now_sec - chip->last_recalc_time;
+#endif
pr_debug("Time since last recalc: %lu\n",
time_since_last_recalc);
time_until_next_recalc = max(0, soc_calc_period