diff options
author | Vijay Hiremath <vijay.p.hiremath@intel.com> | 2015-09-23 12:30:14 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-10-02 12:55:51 -0700 |
commit | 229094b2455e093c95d07251a0021f3b637e813c (patch) | |
tree | 9f9000c571d4c4dca79737902d14fe4a6a84643f | |
parent | 2aebfda07f3fe4d3ee058022f088283b35f4f976 (diff) | |
download | chrome-ec-229094b2455e093c95d07251a0021f3b637e813c.tar.gz |
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 <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/301753
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r-- | board/glados/board.c | 2 | ||||
-rw-r--r-- | board/kunimitsu/board.c | 2 | ||||
-rw-r--r-- | board/samus/board.c | 2 | ||||
-rw-r--r-- | board/strago/board.c | 2 | ||||
-rw-r--r-- | board/wheatley/board.c | 2 | ||||
-rw-r--r-- | common/als.c | 24 | ||||
-rw-r--r-- | driver/als_isl29035.c | 8 | ||||
-rw-r--r-- | driver/als_isl29035.h | 1 | ||||
-rw-r--r-- | driver/als_opt3001.c | 29 | ||||
-rw-r--r-- | driver/als_opt3001.h | 1 | ||||
-rw-r--r-- | include/als.h | 4 |
11 files changed, 42 insertions, 35 deletions
diff --git a/board/glados/board.c b/board/glados/board.c index 5fa6217eb7..80b1f35105 100644 --- a/board/glados/board.c +++ b/board/glados/board.c @@ -209,7 +209,7 @@ BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT); /* ALS instances. Must be in same order as enum als_id. */ struct als_t als[] = { - {"TI", opt3001_read_lux, 5}, + {"TI", opt3001_init, opt3001_read_lux, 5}, }; BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); diff --git a/board/kunimitsu/board.c b/board/kunimitsu/board.c index a173409c0d..580c5b13a8 100644 --- a/board/kunimitsu/board.c +++ b/board/kunimitsu/board.c @@ -295,7 +295,7 @@ BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT); /* ALS instances. Must be in same order as enum als_id. */ struct als_t als[] = { - {"TI", opt3001_read_lux, 5}, + {"TI", opt3001_init, opt3001_read_lux, 5}, }; BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); diff --git a/board/samus/board.c b/board/samus/board.c index 4d5a2e9132..83b9b58309 100644 --- a/board/samus/board.c +++ b/board/samus/board.c @@ -170,7 +170,7 @@ BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); /* ALS instances. Must be in same order as enum als_id. */ struct als_t als[] = { - {"ISL", isl29035_read_lux, 5}, + {"ISL", isl29035_init, isl29035_read_lux, 5}, }; BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); diff --git a/board/strago/board.c b/board/strago/board.c index b80d8cc3f7..79e99b83ee 100644 --- a/board/strago/board.c +++ b/board/strago/board.c @@ -157,7 +157,7 @@ BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); /* ALS instances. Must be in same order as enum als_id. */ struct als_t als[] = { - {"ISL", isl29035_read_lux, 5}, + {"ISL", isl29035_init, isl29035_read_lux, 5}, }; BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); diff --git a/board/wheatley/board.c b/board/wheatley/board.c index 49a11049a3..85ebedb53c 100644 --- a/board/wheatley/board.c +++ b/board/wheatley/board.c @@ -196,7 +196,7 @@ BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT); /* ALS instances. Must be in same order as enum als_id. */ struct als_t als[] = { - {"TI", opt3001_read_lux, 5}, + {"TI", opt3001_init, opt3001_read_lux, 5}, }; BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); 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); /*****************************************************************************/ diff --git a/driver/als_isl29035.c b/driver/als_isl29035.c index f908e443bd..357cc99089 100644 --- a/driver/als_isl29035.c +++ b/driver/als_isl29035.c @@ -6,10 +6,7 @@ */ #include "driver/als_isl29035.h" -#include "common.h" -#include "hooks.h" #include "i2c.h" -#include "timer.h" /* I2C interface */ #define ILS29035_I2C_ADDR 0x88 @@ -23,17 +20,16 @@ #define ILS29035_REG_INT_HT_MSB 7 #define ILS29035_REG_ID 15 -static void isl29035_init(void) +int isl29035_init(void) { /* * Tell it to read continually. This uses 70uA, as opposed to nearly * zero, but it makes the hook/update code cleaner (we don't want to * wait 90ms to read on demand while processing hook callbacks). */ - (void)i2c_write8(I2C_PORT_ALS, ILS29035_I2C_ADDR, + return i2c_write8(I2C_PORT_ALS, ILS29035_I2C_ADDR, ILS29035_REG_COMMAND_I, 0xa0); } -DECLARE_HOOK(HOOK_CHIPSET_RESUME, isl29035_init, HOOK_PRIO_DEFAULT); int isl29035_read_lux(int *lux, int af) { diff --git a/driver/als_isl29035.h b/driver/als_isl29035.h index 0546ceb2d2..0a2f18f72c 100644 --- a/driver/als_isl29035.h +++ b/driver/als_isl29035.h @@ -8,6 +8,7 @@ #ifndef __CROS_EC_ALS_ISL29035_H #define __CROS_EC_ALS_ISL29035_H +int isl29035_init(void); int isl29035_read_lux(int *lux, int af); #endif /* __CROS_EC_ALS_ISL29035_H */ diff --git a/driver/als_opt3001.c b/driver/als_opt3001.c index 712b70a00d..4c5fa5d9f9 100644 --- a/driver/als_opt3001.c +++ b/driver/als_opt3001.c @@ -6,13 +6,7 @@ */ #include "driver/als_opt3001.h" -#include "common.h" -#include "console.h" -#include "hooks.h" #include "i2c.h" -#include "timer.h" - -#define CPRINTF(format, args...) cprintf(CC_I2C, format, ## args) /** * Read register from OPT3001 light sensor. @@ -45,22 +39,18 @@ static int opt3001_i2c_write(const int reg, int data) /** * Initialise OPT3001 light sensor. */ -static void opt3001_init(void) +int opt3001_init(void) { int data; int ret; ret = opt3001_i2c_read(OPT3001_REG_MAN_ID, &data); - if (ret || data != OPT3001_MANUFACTURER_ID) { - CPRINTF("ALS init failed: ret=%d, data=0x%x\n", ret, data); - return; - } + if (ret || data != OPT3001_MANUFACTURER_ID) + return ret; ret = opt3001_i2c_read(OPT3001_REG_DEV_ID, &data); - if (ret || data != OPT3001_DEVICE_ID) { - CPRINTF("ALS init failed: ret=%d, data=0x%x\n", ret, data); - return; - } + if (ret || data != OPT3001_DEVICE_ID) + return ret; /* * [15:12]: 0101b Automatic full scale (1310.40lux, 0.32lux/lsb) @@ -68,11 +58,8 @@ static void opt3001_init(void) * [10:9] : 10b Continuous Mode of conversion operation * [4] : 1b Latched window-style comparison operation */ - ret = opt3001_i2c_write(OPT3001_REG_CONFIGURE, 0x5C10); - if (ret) - CPRINTF("ALS configure failed: ret=%d\n", ret); + return opt3001_i2c_write(OPT3001_REG_CONFIGURE, 0x5C10); } -DECLARE_HOOK(HOOK_CHIPSET_RESUME, opt3001_init, HOOK_PRIO_DEFAULT + 1); /** * Read OPT3001 light sensor data. @@ -83,10 +70,8 @@ int opt3001_read_lux(int *lux, int af) int data; ret = opt3001_i2c_read(OPT3001_REG_RESULT, &data); - if (ret) { - CPRINTF("ALS read failed: ret=%d\n", ret); + if (ret) return ret; - } /* * The default power-on values will give 12 bits of precision: diff --git a/driver/als_opt3001.h b/driver/als_opt3001.h index b9c7714c0b..3e21ba7db8 100644 --- a/driver/als_opt3001.h +++ b/driver/als_opt3001.h @@ -26,6 +26,7 @@ #define OPT3001_MANUFACTURER_ID 0x5449 #define OPT3001_DEVICE_ID 0x3001 +int opt3001_init(void); int opt3001_read_lux(int *lux, int af); #endif /* __CROS_EC_ALS_OPT3001_H */ diff --git a/include/als.h b/include/als.h index c2a4e3a01e..89d1e06628 100644 --- a/include/als.h +++ b/include/als.h @@ -8,12 +8,16 @@ #include "common.h" +/* Priority for ALS HOOK int */ +#define HOOK_PRIO_ALS_INIT (HOOK_PRIO_DEFAULT + 1) + /* Defined in board.h */ enum als_id; /* Initialized in board.c */ struct als_t { const char const *name; + int (*init)(void); int (*read)(int *lux, int af); int attenuation_factor; }; |