summaryrefslogtreecommitdiff
path: root/driver/accel_kionix.c
diff options
context:
space:
mode:
authorNick Vaccaro <nvaccaro@chromium.org>2017-05-26 12:29:14 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-08-08 17:34:11 -0700
commite656b970e204309c1a665f154a5972ed85305911 (patch)
tree58ed84ec4144caf71a4953bae780ec60dd62037e /driver/accel_kionix.c
parent8bfde69fdd9b5feb4c47c8c714416c17afe00f78 (diff)
downloadchrome-ec-e656b970e204309c1a665f154a5972ed85305911.tar.gz
sensors: add bmi160 & kionix orientation driver
BRANCH=none BUG=chromium:718919 TEST=make buildall -j works, orientation works when enabled on gru and scarlet. Change-Id: I16dcfa5d9dea39c082d98190fa1bb6e496168b17 Signed-off-by: Nick Vaccaro <nvaccaro@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/540124 Tested-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Diffstat (limited to 'driver/accel_kionix.c')
-rw-r--r--driver/accel_kionix.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/driver/accel_kionix.c b/driver/accel_kionix.c
index 7323abf6f0..8697a17d66 100644
--- a/driver/accel_kionix.c
+++ b/driver/accel_kionix.c
@@ -253,6 +253,12 @@ static int enable_sensor(const struct motion_sensor_t *s, int reg_val)
if (ret != EC_SUCCESS)
continue;
+#ifdef CONFIG_KX022_ORIENTATION_SENSOR
+ /* Enable tilt orientation mode if lid sensor */
+ if ((s->location == MOTIONSENSE_LOC_LID) && (V(s) == 0))
+ reg_val |= KX022_CNTL1_TPE;
+#endif
+
/* Enable accelerometer based on reg_val value. */
ret = raw_write8(s->port, s->addr, reg,
reg_val | pc1_field);
@@ -394,6 +400,55 @@ static int get_offset(const struct motion_sensor_t *s, int16_t *offset,
return EC_SUCCESS;
}
+#ifdef CONFIG_KX022_ORIENTATION_SENSOR
+static enum motionsensor_orientation kx022_convert_orientation(
+ const struct motion_sensor_t *s,
+ int orientation)
+{
+ enum motionsensor_orientation res = MOTIONSENSE_ORIENTATION_UNKNOWN;
+
+ switch (orientation) {
+ case KX022_ORIENT_PORTRAIT:
+ res = MOTIONSENSE_ORIENTATION_PORTRAIT;
+ break;
+ case KX022_ORIENT_INVERT_PORTRAIT:
+ res = MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT;
+ break;
+ case KX022_ORIENT_LANDSCAPE:
+ res = MOTIONSENSE_ORIENTATION_LANDSCAPE;
+ break;
+ case KX022_ORIENT_INVERT_LANDSCAPE:
+ res = MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE;
+ break;
+ default:
+ break;
+ }
+ res = motion_sense_remap_orientation(s, res);
+ return res;
+}
+
+static int check_orientation_locked(const struct motion_sensor_t *s)
+{
+ struct kionix_accel_data *data = s->drv_data;
+ int orientation, raw_orientation;
+ int ret;
+
+ ret = raw_read8(s->port, s->addr,
+ KX022_TSCP, &raw_orientation);
+ if (ret != EC_SUCCESS)
+ return ret;
+
+ /* mask off up and down events, we don't care about those */
+ raw_orientation &= KX022_ORIENT_MASK;
+ if (raw_orientation && (raw_orientation != data->raw_orientation)) {
+ data->raw_orientation = raw_orientation;
+ orientation = kx022_convert_orientation(s, raw_orientation);
+ SET_ORIENTATION(s, orientation);
+ }
+ return ret;
+}
+#endif
+
static int read(const struct motion_sensor_t *s, vector_3_t v)
{
uint8_t acc[6];
@@ -405,6 +460,11 @@ static int read(const struct motion_sensor_t *s, vector_3_t v)
reg = KIONIX_XOUT_L(V(s));
mutex_lock(s->mutex);
ret = raw_read_multi(s->port, s->addr, reg, acc, 6);
+#ifdef CONFIG_KX022_ORIENTATION_SENSOR
+ if ((s->location == MOTIONSENSE_LOC_LID) && (V(s) == 0) &&
+ (ret == EC_SUCCESS))
+ ret = check_orientation_locked(s);
+#endif
mutex_unlock(s->mutex);
if (ret != EC_SUCCESS)