Skip to content

Commit d0859e1

Browse files
author
Josh Tsai
committed
Fixed battery return unavailable value when battery no response one time
Sometimes, battery does not response for a little time. When battery does not response, EC will try to wake it up and read the battery static information But the dynamic information will be cleared when read the static information If system read the value in memory mapping, it will get the 0 percentage and do the hibernate Signed-off-by: Josh Tsai <josh_tsai@compal.corp-partner.google.com>
1 parent 85fdf34 commit d0859e1

1 file changed

Lines changed: 37 additions & 6 deletions

File tree

board/hx30/battery.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)