@@ -278,7 +278,7 @@ static void fix_single_param(int flag, int *cached, int *curr)
278278 * cached = * curr ;
279279}
280280
281- #define CACHE_INVALIDATION_TIME_US (5 * SECOND)
281+ #define CACHE_INVALIDATION_TIME_US (3 * SECOND)
282282
283283/*
284284 * f any value in batt_params is bad, replace it with a cached
@@ -291,14 +291,43 @@ __override void board_battery_compensate_params(struct batt_params *batt)
291291 static timestamp_t deadline ;
292292
293293 /*
294- * If battery keeps failing for 5 seconds, stop hiding the error and
294+ * If battery keeps failing for 3 seconds, stop hiding the error and
295295 * report back to host.
296296 */
297- if (batt -> flags & BATT_FLAG_BAD_ANY ) {
298- if (timestamp_expired (deadline , NULL ))
297+
298+ if (batt -> flags & BATT_FLAG_RESPONSIVE ) {
299+ if (batt -> flags & BATT_FLAG_BAD_ANY ) {
300+ if (timestamp_expired (deadline , NULL ))
301+ return ;
302+ } else
303+ deadline .val = get_time ().val + CACHE_INVALIDATION_TIME_US ;
304+ } else if (!(batt -> flags & BATT_FLAG_RESPONSIVE )) {
305+ /**
306+ * There are 4 situations for battery is not repsonsed
307+ * 1. Darin battery (first time)
308+ * 2. Dead battery (first time)
309+ * 3. No battery (is preset)
310+ * 4. Others
311+ */
312+ /* we don't need to cache the value when battery is not present */
313+ if (!batt -> is_present ) {
314+ batt_cache .flags &= ~BATT_FLAG_RESPONSIVE ;
315+ return ;
316+ }
317+
318+ /* we don't need to cache the value when we read the battery first time*/
319+ if (!(batt_cache .flags & BATT_FLAG_RESPONSIVE ))
299320 return ;
300- } else {
301- deadline .val = get_time ().val + CACHE_INVALIDATION_TIME_US ;
321+
322+ /**
323+ * If battery keeps no responsing for 3 seconds, stop hiding the error and
324+ * back to host.
325+ */
326+ if (timestamp_expired (deadline , NULL )) {
327+ batt_cache .flags &= ~BATT_FLAG_RESPONSIVE ;
328+ return ;
329+ }
330+
302331 }
303332
304333 /* return cached values for at most CACHE_INVALIDATION_TIME_US */
@@ -339,6 +368,8 @@ __override void board_battery_compensate_params(struct batt_params *batt)
339368
340369 /* remove bad flags after applying cached values */
341370 batt -> flags &= ~BATT_FLAG_BAD_ANY ;
371+ batt -> flags |= BATT_FLAG_RESPONSIVE ;
372+ batt_cache .flags |= BATT_FLAG_RESPONSIVE ;
342373}
343374
344375/*****************************************************************************/
0 commit comments