From 229094b2455e093c95d07251a0021f3b637e813c Mon Sep 17 00:00:00 2001 From: Vijay Hiremath Date: Wed, 23 Sep 2015 12:30:14 -0700 Subject: ALS: Disable the ALS task if all the ALS inits fail BUG=none TEST=Manually tested on Kunimitsu & Strago. Removed the ALS sensor from DUT, using "taskinfo" console command observed that the ALS task is not running. BRANCH=none Change-Id: I96cb720bd8d70033d433cdc2cd9cea9b56a3b389 Signed-off-by: Vijay Hiremath Reviewed-on: https://chromium-review.googlesource.com/301753 Commit-Ready: Vijay P Hiremath Tested-by: Vijay P Hiremath Reviewed-by: Shawn N --- common/als.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'common/als.c') diff --git a/common/als.c b/common/als.c index 17bff66961..06bd734ef0 100644 --- a/common/als.c +++ b/common/als.c @@ -48,7 +48,27 @@ void als_task(void) static void als_task_enable(void) { - task_timeout = ALS_POLL_PERIOD; + int fail_count = 0; + int err; + int i; + + for (i = 0; i < EC_ALS_ENTRIES && i < ALS_COUNT; i++) { + err = als[i].init(); + if (err) { + fail_count++; + ccprintf("%s ALS sensor failed to initialize, err=%d\n", + als[i].name, err); + } + } + + /* + * If all the ALS filed to initialize, disable the ALS task. + */ + if (fail_count == ALS_COUNT) + task_timeout = -1; + else + task_timeout = ALS_POLL_PERIOD; + task_wake(TASK_ID_ALS); } @@ -57,7 +77,7 @@ static void als_task_disable(void) task_timeout = -1; } -DECLARE_HOOK(HOOK_CHIPSET_RESUME, als_task_enable, HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_CHIPSET_RESUME, als_task_enable, HOOK_PRIO_ALS_INIT); DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, als_task_disable, HOOK_PRIO_DEFAULT); /*****************************************************************************/ -- cgit v1.2.1