summaryrefslogtreecommitdiff
path: root/driver/accel_kionix.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2016-10-06 11:25:49 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-10-08 18:34:36 -0700
commit09f90a3b8f0f48d11b3653ad2af1d61c29691a48 (patch)
tree642d36b89d3886822cbc78d2288d31778e6b7e36 /driver/accel_kionix.c
parentacc1a842e483b391f25ea5cd300317949301915a (diff)
downloadchrome-ec-09f90a3b8f0f48d11b3653ad2af1d61c29691a48.tar.gz
kionix: Add reading whoami to be sure device has booted.
From the specs, "KX022-1020 Specifications Rev4.0", the power up time can be as long as 10ms. Add a loop to be sure the device is responsive before initalizing it. BRANCH=reef,glados,oak,veyron,cyan BUG=none TEST=After putting a KX022 accel as first in the list, it would not initialize properly. After adding the loop, it initializes properly. Change-Id: I3194a5d1deb0c2eb2a04a459aab3b4269e479af3 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/394750 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/accel_kionix.c')
-rw-r--r--driver/accel_kionix.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/driver/accel_kionix.c b/driver/accel_kionix.c
index 2a9149d9a7..785fca44f6 100644
--- a/driver/accel_kionix.c
+++ b/driver/accel_kionix.c
@@ -450,11 +450,32 @@ static int init(const struct motion_sensor_t *s)
int ret, val, reg, reset_field;
uint8_t timeout;
+ /* The chip can take up to 10ms to boot */
+ mutex_lock(s->mutex);
+ reg = KIONIX_WHO_AM_I(V(s));
+ timeout = 0;
+ do {
+ msleep(1);
+ /* Read WHO_AM_I to be sure the device has booted */
+ ret = raw_read8(s->port, s->addr, reg, &val);
+ if (ret == EC_SUCCESS)
+ break;
+
+ /* Check for timeout. */
+ if (timeout++ > 20) {
+ ret = EC_ERROR_TIMEOUT;
+ break;
+ }
+ } while (1);
+ if (ret != EC_SUCCESS) {
+ mutex_unlock(s->mutex);
+ return ret;
+ }
+
reg = KIONIX_CTRL2_REG(V(s));
reset_field = KIONIX_RESET_FIELD(V(s));
/* Issue a software reset. */
- mutex_lock(s->mutex);
/* Place the sensor in standby mode to make changes. */
ret = disable_sensor(s, &val);
@@ -533,8 +554,8 @@ const struct accelgyro_drv kionix_accel_drv = {
#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL
struct i2c_stress_test_dev kionix_i2c_stress_test_dev = {
.reg_info = {
- .read_reg = KX022_WHOAMI,
- .read_val = KIONIX_WHO_AM_I_VAL,
+ .read_reg = KIONIX_WHO_AM_I(V(s)),
+ .read_val = KIONIX_WHO_AM_I_VAL(V(s)),
.write_reg = KIONIX_ODR_REG(V(s)),
},
.i2c_read = &raw_read8,