@@ -269,7 +269,7 @@ static void fix_single_param(int flag, int *cached, int *curr)
269269 * cached = * curr ;
270270}
271271
272- #define CACHE_INVALIDATION_TIME_US (5 * SECOND)
272+ #define CACHE_INVALIDATION_TIME_US (3 * SECOND)
273273
274274/*
275275 * f any value in batt_params is bad, replace it with a cached
@@ -282,14 +282,42 @@ __override void board_battery_compensate_params(struct batt_params *batt)
282282 static timestamp_t deadline ;
283283
284284 /*
285- * If battery keeps failing for 5 seconds, stop hiding the error and
285+ * If battery keeps failing for 3 seconds, stop hiding the error and
286286 * report back to host.
287287 */
288- if (batt -> flags & BATT_FLAG_BAD_ANY ) {
289- if (timestamp_expired (deadline , NULL ))
288+ if (batt -> flags & BATT_FLAG_RESPONSIVE ) {
289+ if (batt -> flags & BATT_FLAG_BAD_ANY ) {
290+ if (timestamp_expired (deadline , NULL ))
291+ return ;
292+ } else
293+ deadline .val = get_time ().val + CACHE_INVALIDATION_TIME_US ;
294+ } else if (!(batt -> flags & BATT_FLAG_RESPONSIVE )) {
295+ /**
296+ * There are 4 situations for battery is not repsonsed
297+ * 1. Darin battery (first time)
298+ * 2. Dead battery (first time)
299+ * 3. No battery (is preset)
300+ * 4. Others
301+ */
302+ /* we don't need to cache the value when battery is not present */
303+ if (!batt -> is_present ) {
304+ batt_cache .flags &= ~BATT_FLAG_RESPONSIVE ;
305+ return ;
306+ }
307+
308+ /* we don't need to cache the value when we read the battery first time*/
309+ if (!(batt_cache .flags & BATT_FLAG_RESPONSIVE ))
290310 return ;
291- } else {
292- deadline .val = get_time ().val + CACHE_INVALIDATION_TIME_US ;
311+
312+ /**
313+ * If battery keeps no responsing for 3 seconds, stop hiding the error and
314+ * back to host.
315+ */
316+ if (timestamp_expired (deadline , NULL )) {
317+ batt_cache .flags &= ~BATT_FLAG_RESPONSIVE ;
318+ return ;
319+ }
320+
293321 }
294322
295323 /* return cached values for at most CACHE_INVALIDATION_TIME_US */
@@ -330,6 +358,8 @@ __override void board_battery_compensate_params(struct batt_params *batt)
330358
331359 /* remove bad flags after applying cached values */
332360 batt -> flags &= ~BATT_FLAG_BAD_ANY ;
361+ batt -> flags |= BATT_FLAG_RESPONSIVE ;
362+ batt_cache .flags |= BATT_FLAG_RESPONSIVE ;
333363}
334364
335365/*****************************************************************************/
0 commit comments