From 0939fffdebee1e8326d2b2c898433ab28db1ded1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 13 Jul 2012 10:03:08 +0200 Subject: [PATCH] charger: Add delay in tasker task to avoid lockup The charger task relies on calc_next_state() performing a delay before returning. My reading of the code suggests that this doesn't happen always. For example: When pre-charging: if (battery_temperature(&batt_temp) == EC_SUCCESS) return ST_CHARGING; When discharging and capacity is low: /* Check remaining charge % */ if (battery_state_of_charge(&capacity) == 0 && capacity < 10) return notify_battery_low(); I would like to suggest that the code be refactored to more like: int next_checkms = 5000; /* next time to check battery */ while (1) { int action = ACTION_NONE; err = get_state(&state); if (!err) { action = calculate_action(&state); err = perform_action(action, &next_check_ms); } usleep(next_check_ms * 1000); } so that the delays are really clear, the state is all read at once, there is no reliance on earlier state, and we always delay even on error. In the meantime, this CL inserts a mandatory 5 second delay in the loop, which should prevent the charger task lockup. BUG=chrome-os-partner:11285 TEST=manual (please do this test before committing) 1. boot to kernel, see that battery can be seen 2. suspend and resume device 3. see that the charger loop does not cause an EC watchdog reset and AP power off/reset. There should be no watchdog warning message on the EC console. Change-Id: I141e374933c4dc0ec60bcdccf96443f57067c585 Signed-off-by: Simon Glass Reviewed-on: https://gerrit.chromium.org/gerrit/27353 Reviewed-by: Rong Chang Tested-by: Rong Chang Reviewed-by: Che-Liang Chiou Tested-by: Katie Roberts-Hoffman Commit-Ready: Katie Roberts-Hoffman --- common/pmu_tps65090_charger.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c index b4b1c05fbc..4aacf99155 100644 --- a/common/pmu_tps65090_charger.c +++ b/common/pmu_tps65090_charger.c @@ -296,5 +296,8 @@ void pmu_charger_task(void) state_list[next_state]); state = next_state; } + + /* TODO(sjg@chromium.org): root cause crosbug.com/p/11285 */ + usleep(5000 * 1000); } }