summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2016-10-06 11:25:49 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2016-11-17 07:27:41 +0000
commit17f02252ecbefc2ba1734dcda852f9aadce7a3b6 (patch)
treea3bcba73d1b81690f299f957b4e6b9bb477c44ed
parent56c7c192f1e3ddeb7ca8baa8cb73a3644457ed91 (diff)
downloadchrome-ec-17f02252ecbefc2ba1734dcda852f9aadce7a3b6.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. Reviewed-on: https://chromium-review.googlesource.com/394750 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit 09f90a3b8f0f48d11b3653ad2af1d61c29691a48) Change-Id: I3194a5d1deb0c2eb2a04a459aab3b4269e479af3 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/412031
-rw-r--r--driver/accel_kionix.c23
-rw-r--r--driver/accel_kionix.h6
2 files changed, 28 insertions, 1 deletions
diff --git a/driver/accel_kionix.c b/driver/accel_kionix.c
index 826380f880..75d5b72998 100644
--- a/driver/accel_kionix.c
+++ b/driver/accel_kionix.c
@@ -457,11 +457,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 */