diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2016-10-06 11:25:49 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2017-05-01 21:20:27 +0000 |
commit | d7ceef057cfdc28e7d272d608113d8ef331ee7b4 (patch) | |
tree | f299bae4ac9583fde32a1e99499fbed60bbfb42c | |
parent | aba96a42512b65e6560c1c94d3241cdb421eed36 (diff) | |
download | chrome-ec-d7ceef057cfdc28e7d272d608113d8ef331ee7b4.tar.gz |
UPSTREAM: 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, ultima
BUG=none, b:36973851
TEST=After putting a KX022 accel as first in the list, it would not
initialize properly. After adding the loop, it initializes properly.
Reviewed-on: https://chromium-review.googlesource.com/394750
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
(cherry picked from commit 09f90a3b8f0f48d11b3653ad2af1d61c29691a48)
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/409507
(cherry picked from commit 7b52b9dc1e21ad87fa759a02cff820c6b4960f4f)
Change-Id: I3194a5d1deb0c2eb2a04a459aab3b4269e479af3
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/489780
-rw-r--r-- | driver/accel_kionix.c | 23 | ||||
-rw-r--r-- | driver/accel_kionix.h | 6 |
2 files changed, 28 insertions, 1 deletions
diff --git a/driver/accel_kionix.c b/driver/accel_kionix.c index 7600f452ee..a57f2060f1 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); diff --git a/driver/accel_kionix.h b/driver/accel_kionix.h index 6c71cb7918..012ee8ec2b 100644 --- a/driver/accel_kionix.h +++ b/driver/accel_kionix.h @@ -69,4 +69,10 @@ extern const struct accelgyro_drv kionix_accel_drv; #define KIONIX_XOUT_L(v) (KX022_XOUT_L + \ (v) * (KXCJ9_XOUT_L - KX022_XOUT_L)) +#define KIONIX_WHO_AM_I(v) (KX022_WHOAMI + \ + (v) * (KXCJ9_WHOAMI - KX022_WHOAMI)) + +#define KIONIX_WHO_AM_I_VAL(v) (KX022_WHO_AM_I_VAL + \ + (v) * (KXCJ9_WHO_AM_I_VAL - KX022_WHO_AM_I_VAL)) + #endif /* __CROS_EC_ACCEL_KIONIX_H */ |