summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-03-07 10:24:01 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-05-12 23:35:56 +0000
commit8d04e95a49b0f9e63bba99e1911ff80616738064 (patch)
treed9f763c4c2d3b6973587c4599de4da616cb5046c
parenta9a9ae1abc4ddb6a89ee0d29b88fbdd1d2ef67b1 (diff)
downloadchrome-ec-8d04e95a49b0f9e63bba99e1911ff80616738064.tar.gz
driver: Add BMI160 basic driver support
Basic initialization of BMI160. Fit into the existing accel/gyro framework. BUG=chrome-os-partner:36018 BRANCH=none TEST=Ability to read samples with accelinfo. Change-Id: I5c86d4c3964eb6f876dd4042e5019195ffcca4ed Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/270454 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--driver/accelgyro_bmi160.c392
-rw-r--r--driver/accelgyro_bmi160.h254
-rw-r--r--driver/build.mk1
-rw-r--r--include/ec_commands.h2
4 files changed, 649 insertions, 0 deletions
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c
new file mode 100644
index 0000000000..469950f07d
--- /dev/null
+++ b/driver/accelgyro_bmi160.c
@@ -0,0 +1,392 @@
+/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * BMI160/BMC50 accelerometer and gyro module for Chrome EC
+ * 3D digital accelerometer & 3D digital gyroscope
+ */
+
+#include "accelgyro.h"
+#include "common.h"
+#include "console.h"
+#include "driver/accelgyro_bmi160.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "task.h"
+#include "timer.h"
+#include "util.h"
+
+#define CPUTS(outstr) cputs(CC_ACCEL, outstr)
+#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args)
+
+/*
+ * Struct for pairing an engineering value with the register value for a
+ * parameter.
+ */
+struct accel_param_pair {
+ int val; /* Value in engineering units. */
+ int reg_val; /* Corresponding register value. */
+};
+
+/* List of range values in +/-G's and their associated register values. */
+static const struct accel_param_pair g_ranges[] = {
+ {2, BMI160_GSEL_2G},
+ {4, BMI160_GSEL_4G},
+ {8, BMI160_GSEL_8G},
+ {16, BMI160_GSEL_16G}
+};
+
+/*
+ * List of angular rate range values in +/-dps's
+ * and their associated register values.
+ */
+const struct accel_param_pair dps_ranges[] = {
+ {125, BMI160_DPS_SEL_125},
+ {250, BMI160_DPS_SEL_250},
+ {500, BMI160_DPS_SEL_500},
+ {1000, BMI160_DPS_SEL_1000},
+ {2000, BMI160_DPS_SEL_2000}
+};
+
+static inline const struct accel_param_pair *get_range_table(
+ enum motionsensor_type type, int *psize)
+{
+ if (MOTIONSENSE_TYPE_ACCEL == type) {
+ if (psize)
+ *psize = ARRAY_SIZE(g_ranges);
+ return g_ranges;
+ } else {
+ if (psize)
+ *psize = ARRAY_SIZE(dps_ranges);
+ return dps_ranges;
+ }
+}
+
+static inline int get_xyz_reg(enum motionsensor_type type)
+{
+ switch (type) {
+ case MOTIONSENSE_TYPE_ACCEL:
+ return BMI160_ACC_X_L_G;
+ case MOTIONSENSE_TYPE_GYRO:
+ return BMI160_GYR_X_L_G;
+ case MOTIONSENSE_TYPE_MAG:
+ return BMI160_MAG_X_L_G;
+ default:
+ return -1;
+ }
+}
+
+/**
+ * @return reg value that matches the given engineering value passed in.
+ * The round_up flag is used to specify whether to round up or down.
+ * Note, this function always returns a valid reg value. If the request is
+ * outside the range of values, it returns the closest valid reg value.
+ */
+static int get_reg_val(const int eng_val, const int round_up,
+ const struct accel_param_pair *pairs, const int size)
+{
+ int i;
+ for (i = 0; i < size - 1; i++) {
+ if (eng_val <= pairs[i].val)
+ break;
+
+ if (eng_val < pairs[i+1].val) {
+ if (round_up)
+ i += 1;
+ break;
+ }
+ }
+ return pairs[i].reg_val;
+}
+
+/**
+ * @return engineering value that matches the given reg val
+ */
+static int get_engineering_val(const int reg_val,
+ const struct accel_param_pair *pairs, const int size)
+{
+ int i;
+ for (i = 0; i < size; i++) {
+ if (reg_val == pairs[i].reg_val)
+ break;
+ }
+ return pairs[i].val;
+}
+
+/**
+ * Read register from accelerometer.
+ */
+static inline int raw_read8(const int addr, const int reg, int *data_ptr)
+{
+ return i2c_read8(I2C_PORT_ACCEL, addr, reg, data_ptr);
+}
+
+/**
+ * Write register from accelerometer.
+ */
+static inline int raw_write8(const int addr, const int reg, int data)
+{
+ return i2c_write8(I2C_PORT_ACCEL, addr, reg, data);
+}
+
+static int set_range(const struct motion_sensor_t *s,
+ int range,
+ int rnd)
+{
+ int ret, range_tbl_size;
+ uint8_t reg_val, ctrl_reg;
+ const struct accel_param_pair *ranges;
+ struct motion_data_t *data = (struct motion_data_t *)s->drv_data;
+
+ ctrl_reg = BMI160_RANGE_REG(s->type);
+ ranges = get_range_table(s->type, &range_tbl_size);
+ reg_val = get_reg_val(range, rnd, ranges, range_tbl_size);
+
+ ret = raw_write8(s->i2c_addr, ctrl_reg, reg_val);
+ /* Now that we have set the range, update the driver's value. */
+ if (ret == EC_SUCCESS)
+ data->range = get_engineering_val(reg_val, ranges,
+ range_tbl_size);
+ return ret;
+}
+
+static int get_range(const struct motion_sensor_t *s,
+ int *range)
+{
+ struct motion_data_t *data = (struct motion_data_t *)s->drv_data;
+
+ *range = data->range;
+ return EC_SUCCESS;
+}
+
+static int set_resolution(const struct motion_sensor_t *s,
+ int res,
+ int rnd)
+{
+ /* Only one resolution, BMI160_RESOLUTION, so nothing to do. */
+ return EC_SUCCESS;
+}
+
+static int get_resolution(const struct motion_sensor_t *s,
+ int *res)
+{
+ *res = BMI160_RESOLUTION;
+ return EC_SUCCESS;
+}
+
+static int set_data_rate(const struct motion_sensor_t *s,
+ int rate,
+ int rnd)
+{
+ int ret, val, normalized_rate;
+ uint8_t ctrl_reg, reg_val;
+ struct motion_data_t *data = s->drv_data;
+
+ if (rate == 0) {
+ /* suspend */
+ ret = raw_write8(s->i2c_addr, BMI160_CMD_REG,
+ BMI150_CMD_MODE_SUSPEND(s->type));
+ msleep(30);
+ return ret;
+ }
+ ctrl_reg = BMI160_CONF_REG(s->type);
+ reg_val = BMI160_ODR_TO_REG(rate);
+ normalized_rate = BMI160_REG_TO_ODR(reg_val);
+ if (rnd && (normalized_rate < rate)) {
+ reg_val++;
+ normalized_rate *= 2;
+ }
+
+ switch (s->type) {
+ case MOTIONSENSE_TYPE_ACCEL:
+ if (reg_val > BMI160_ODR_1600HZ) {
+ reg_val = BMI160_ODR_1600HZ;
+ normalized_rate = 1600000;
+ } else if (reg_val < BMI160_ODR_0_78HZ) {
+ reg_val = BMI160_ODR_0_78HZ;
+ normalized_rate = 780;
+ }
+ break;
+ case MOTIONSENSE_TYPE_GYRO:
+ if (reg_val > BMI160_ODR_3200HZ) {
+ reg_val = BMI160_ODR_3200HZ;
+ normalized_rate = 3200000;
+ } else if (reg_val < BMI160_ODR_25HZ) {
+ reg_val = BMI160_ODR_25HZ;
+ normalized_rate = 25000;
+ }
+ break;
+ default:
+ return -1;
+ }
+
+ /*
+ * Lock accel resource to prevent another task from attempting
+ * to write accel parameters until we are done.
+ */
+ mutex_lock(s->mutex);
+
+ ret = raw_read8(s->i2c_addr, ctrl_reg, &val);
+ if (ret != EC_SUCCESS)
+ goto accel_cleanup;
+
+ val = (val & ~BMI160_ODR_MASK) | reg_val;
+ ret = raw_write8(s->i2c_addr, ctrl_reg, val);
+
+ /* Now that we have set the odr, update the driver's value. */
+ if (ret == EC_SUCCESS)
+ data->odr = normalized_rate;
+
+accel_cleanup:
+ mutex_unlock(s->mutex);
+ return ret;
+}
+
+static int get_data_rate(const struct motion_sensor_t *s,
+ int *rate)
+{
+ struct motion_data_t *data = s->drv_data;
+
+ *rate = data->odr;
+ return EC_SUCCESS;
+}
+
+#ifdef CONFIG_ACCEL_INTERRUPTS
+static int set_interrupt(const struct motion_sensor_t *s,
+ unsigned int threshold)
+{
+ /* Currently unsupported. */
+ return EC_ERROR_UNKNOWN;
+}
+#endif
+
+static int is_data_ready(const struct motion_sensor_t *s, int *ready)
+{
+ int ret, tmp;
+
+ ret = raw_read8(s->i2c_addr, BMI160_STATUS, &tmp);
+
+ if (ret != EC_SUCCESS) {
+ CPRINTF("[%T %s type:0x%X RS Error]", s->name, s->type);
+ return ret;
+ }
+
+ *ready = tmp & BMI160_DRDY_MASK(s->type);
+ return EC_SUCCESS;
+}
+
+static int read(const struct motion_sensor_t *s, vector_3_t v)
+{
+ uint8_t data[6];
+ uint8_t xyz_reg;
+ int ret, tmp = 0, range = 0;
+
+ ret = is_data_ready(s, &tmp);
+ if (ret != EC_SUCCESS)
+ return ret;
+
+ /*
+ * If sensor data is not ready, return the previous read data.
+ * Note: return success so that motion senor task can read again
+ * to get the latest updated sensor data quickly.
+ */
+ if (!tmp) {
+ v[0] = s->raw_xyz[0];
+ v[1] = s->raw_xyz[1];
+ v[2] = s->raw_xyz[2];
+ return EC_SUCCESS;
+ }
+
+ xyz_reg = get_xyz_reg(s->type);
+
+ /* Read 6 bytes starting at xyz_reg */
+ i2c_lock(I2C_PORT_ACCEL, 1);
+ ret = i2c_xfer(I2C_PORT_ACCEL, s->i2c_addr,
+ &xyz_reg, 1, data, 6, I2C_XFER_SINGLE);
+ i2c_lock(I2C_PORT_ACCEL, 0);
+
+ if (ret != EC_SUCCESS) {
+ CPRINTF("[%T %s type:0x%X RD XYZ Error %d]",
+ s->name, s->type, ret);
+ return ret;
+ }
+
+ v[0] = ((int16_t)((data[1] << 8) | data[0]));
+ v[1] = ((int16_t)((data[3] << 8) | data[2]));
+ v[2] = ((int16_t)((data[5] << 8) | data[4]));
+
+ ret = get_range(s, &range);
+ if (ret)
+ return EC_ERROR_UNKNOWN;
+
+ v[0] *= range;
+ v[1] *= range;
+ v[2] *= range;
+
+ /* normalize the accel scale: 1G = 1024 */
+ if (MOTIONSENSE_TYPE_ACCEL == s->type) {
+ v[0] >>= 5;
+ v[1] >>= 5;
+ v[2] >>= 5;
+ } else {
+ v[0] >>= 8;
+ v[1] >>= 8;
+ v[2] >>= 8;
+ }
+
+ return EC_SUCCESS;
+}
+
+static int init(const struct motion_sensor_t *s)
+{
+ int ret = 0, tmp;
+
+ ret = raw_read8(s->i2c_addr, BMI160_CHIP_ID, &tmp);
+ if (ret)
+ return EC_ERROR_UNKNOWN;
+
+ if (tmp != BMI160_CHIP_ID_MAJOR)
+ return EC_ERROR_ACCESS_DENIED;
+
+
+ if (s->type == MOTIONSENSE_TYPE_ACCEL) {
+ raw_write8(s->i2c_addr, BMI160_CMD_REG,
+ BMI160_CMD_SOFT_RESET);
+ msleep(30);
+ /* To avoid gyro wakeup */
+ raw_write8(s->i2c_addr, BMI160_PMU_TRIGGER, 0);
+ }
+
+ raw_write8(s->i2c_addr, BMI160_CMD_REG,
+ BMI150_CMD_MODE_NORMAL(s->type));
+ msleep(30);
+
+ set_range(s, s->runtime_config.range, 0);
+ msleep(30);
+
+ set_data_rate(s, s->runtime_config.odr, 0);
+ msleep(30);
+
+
+ /* Fifo setup is done elsewhere */
+ CPRINTF("[%T %s: MS Done Init type:0x%X range:%d odr:%d]\n",
+ s->name, s->type, s->runtime_config.range,
+ s->runtime_config.odr);
+ return ret;
+}
+
+const struct accelgyro_drv bmi160_drv = {
+ .init = init,
+ .read = read,
+ .set_range = set_range,
+ .get_range = get_range,
+ .set_resolution = set_resolution,
+ .get_resolution = get_resolution,
+ .set_data_rate = set_data_rate,
+ .get_data_rate = get_data_rate,
+#ifdef CONFIG_ACCEL_INTERRUPTS
+ .set_interrupt = set_interrupt,
+#endif
+};
diff --git a/driver/accelgyro_bmi160.h b/driver/accelgyro_bmi160.h
new file mode 100644
index 0000000000..7ea98a034f
--- /dev/null
+++ b/driver/accelgyro_bmi160.h
@@ -0,0 +1,254 @@
+/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* BMI160 accelerometer and gyro and BMM150 compass module for Chrome EC */
+
+#ifndef __CROS_EC_ACCEL_BMI160_H
+#define __CROS_EC_ACCEL_BMI160_H
+
+#include "accelgyro.h"
+
+#define BMI160_ADDR0 0xd0
+#define BMI160_ADDR1 0xd2
+
+#define BMI160_CHIP_ID 0x00
+#define BMI160_CHIP_ID_MAJOR 0xd1
+
+#define BMI160_SPEC_ACC_STARTUP_TIME_MS 10
+#define BMI160_SPEC_GYR_STARTUP_TIME_MS 80
+#define BMI160_SPEC_MAG_STARTUP_TIME_MS 60
+
+
+#define BMI160_ERR_REG 0x02
+#define BMI160_PMU_STATUS 0x03
+#define BMI160_MAG_X_L_G 0x04
+#define BMI160_MAG_X_H_G 0x05
+#define BMI160_MAG_Y_L_G 0x06
+#define BMI160_MAG_Y_H_G 0x07
+#define BMI160_MAG_Z_L_G 0x08
+#define BMI160_MAG_Z_H_G 0x09
+#define BMI160_RHALL_L_G 0x0a
+#define BMI160_RHALL_H_G 0x0b
+#define BMI160_GYR_X_L_G 0x0c
+#define BMI160_GYR_X_H_G 0x0d
+#define BMI160_GYR_Y_L_G 0x0e
+#define BMI160_GYR_Y_H_G 0x0f
+#define BMI160_GYR_Z_L_G 0x10
+#define BMI160_GYR_Z_H_G 0x11
+#define BMI160_ACC_X_L_G 0x12
+#define BMI160_ACC_X_H_G 0x13
+#define BMI160_ACC_Y_L_G 0x14
+#define BMI160_ACC_Y_H_G 0x15
+#define BMI160_ACC_Z_L_G 0x16
+#define BMI160_ACC_Z_H_G 0x17
+
+#define BMI160_SENSORTIME_0 0x18
+#define BMI160_SENSORTIME_1 0x19
+#define BMI160_SENSORTIME_2 0x1a
+
+#define BMI160_STATUS 0x1b
+#define BMI160_DRDY_ACC 0x80
+#define BMI160_DRDY_GYR 0x40
+#define BMI160_DRDY_MAG 0x20
+#define BMI160_DRDY_OFF(_sensor) (7 - (_sensor))
+#define BMI160_DRDY_MASK(_sensor) (1 << BMI160_DRDY_OFF(_sensor))
+#define BMI160_NVM_RDY 0x10
+#define BMI160_FOC_RDY 0x08
+#define BMI160_MAG_MAN_OP 0x04
+#define BMI160_GYR_SLF_TST 0x02
+#define BMI160_POR_DETECTED 0x01
+
+
+#define BMI160_INT_STATUS_0 0x1c
+#define BMI160_INT_STATUS_1 0x1d
+#define BMI160_INT_STATUS_2 0x1e
+#define BMI160_INT_STATUS_3 0x1f
+
+#define BMI160_TEMPERATURE_0 0x20
+#define BMI160_TEMPERATURE_1 0x21
+
+#define BMI160_FIFO_LENGTH_0 0x22
+#define BMI160_FIFO_LENGTH_1 0x23
+#define BMI160_FIFO_DATA 0x24
+
+#define BMI160_ACC_CONF 0x40
+#define BMI160_GSEL_2G 0X03
+#define BMI160_GSEL_4G 0X05
+#define BMI160_GSEL_8G 0X08
+#define BMI160_GSEL_16G 0X0C
+
+#define BMI160_ODR_MASK 0x0F
+
+#define BMI160_ACC_BW_OFFSET 4
+#define BMI160_ACC_BW_MASK (0x7 << BMI160_ACC_BW_OFFSET)
+#define BMI160_ACC_RANGE 0x41
+
+#define BMI160_DPS_SEL_2000 0x00
+#define BMI160_DPS_SEL_1000 0x01
+#define BMI160_DPS_SEL_500 0x02
+#define BMI160_DPS_SEL_250 0x03
+#define BMI160_DPS_SEL_125 0x04
+
+#define BMI160_GYR_CONF 0x42
+
+#define BMI160_GYR_BW_OFFSET 4
+#define BMI160_GYR_BW_MASK (0x3 << BMI160_GYR_BW_OFFSET)
+#define BMI160_GYR_RANGE 0x43
+
+#define BMI160_MAG_CONF 0x44
+
+/* odr = 100 / (1 << (8 - reg)) ,within limit */
+#define BMI160_ODR_0_78HZ 0x01
+#define BMI160_ODR_25HZ 0x06
+#define BMI160_ODR_1600HZ 0x0C
+#define BMI160_ODR_3200HZ 0x0D
+
+#define BMI160_REG_TO_ODR(_regval) (100000 / (1 << (8 - (_regval))))
+#define BMI160_ODR_TO_REG(_odr) (__builtin_clz(100000 / (_odr)) - 23)
+
+#define BMI160_CONF_REG(_sensor) (0x40 + 2 * (_sensor))
+#define BMI160_RANGE_REG(_sensor) (0x41 + 2 * (_sensor))
+
+#define BMI160_FIFO_DOWNS 0x45
+#define BMI160_FIFO_CONFIG_0 0x46
+#define BMI160_FIFO_CONFIG_1 0x47
+
+#define BMI160_MAG_IF_0 0x4b
+#define BMI160_MAG_IF_1 0x4c
+#define BMI160_MAG_IF_2 0x4d
+#define BMI160_MAG_IF_3 0x4e
+#define BMI160_MAG_IF_4 0x4f
+
+#define BMI160_INT_EN_0 0x50
+#define BMI160_INT_EN_1 0x51
+#define BMI160_INT_EN_2 0x52
+
+#define BMI160_INT_OUT_CTRL 0x53
+#define BMI160_INT_LATCH 0x54
+
+#define BMI160_INT_MAP_0 0x55
+#define BMI160_INT_MAP_1 0x56
+#define BMI160_INT_MAP_2 0x57
+
+#define BMI160_INT_DATA_0 0x58
+#define BMI160_INT_DATA_1 0x59
+
+#define BMI160_INT_MOTION_0 0x5f
+#define BMI160_INT_MOTION_1 0x60
+#define BMI160_INT_MOTION_2 0x61
+#define BMI160_INT_MOTION_3 0x62
+
+#define BMI160_INT_TAP_0 0x63
+#define BMI160_INT_TAP_1 0x64
+
+#define BMI160_INT_ORIENT_0 0x65
+#define BMI160_INT_ORIENT_1 0x66
+
+#define BMI160_INT_FLAT_0 0x67
+#define BMI160_INT_FLAT_1 0x68
+
+#define BMI160_FOC_CONF 0x69
+#define BMI160_CONF 0x6a
+#define BMI160_IF_CONF 0x6b
+
+#define BMI160_PMU_TRIGGER 0x6c
+#define BMI160_SELF_TEST 0x6d
+
+#define BMI160_CMD_REG 0x7e
+#define BMI160_CMD_SOFT_RESET 0xb6
+#define BMI160_CMD_NOOP 0x00
+#define BMI160_CMD_ACC_MODE_SUSP 0x10
+#define BMI160_CMD_ACC_MODE_NORMAL 0x11
+#define BMI160_CMD_ACC_MODE_LOWPOWER 0x12
+#define BMI160_CMD_GYR_MODE_SUSP 0x14
+#define BMI160_CMD_GYR_MODE_NORMAL 0x15
+#define BMI160_CMD_GYR_MODE_FAST_STARTUP 0x17
+#define BMI160_CMD_MAG_MODE_SUSP 0x18
+#define BMI160_CMD_MAG_MODE_NORMAL 0x19
+#define BMI160_CMD_MAG_MODE_LOWPOWER 0x1a
+#define BMI150_CMD_MODE_NORMAL(_sensor) (0x11 + 4 * (_sensor))
+#define BMI150_CMD_MODE_SUSPEND(_sensor) (0x10 + 4 * (_sensor))
+
+#define BMI160_CMD_FIFO_FLUSH 0xb0
+#define BMI160_CMD_INT_RESET 0xb1
+#define BMI160_CMD_SOFT_RESET 0xb6
+#define BMI160_CMD_EXT_MODE_EN_B0 0x37
+#define BMI160_CMD_EXT_MODE_EN_B1 0x9a
+#define BMI160_CMD_EXT_MODE_EN_B2 0xc0
+
+#define BMI160_CMD_TGT_PAGE 0
+#define BMI160_CMD_TGT_PAGE_COM 1
+#define BMI160_CMD_TGT_PAGE_ACC 2
+#define BMI160_CMD_TGT_PAGE_GYR 3
+
+#define BMI160_FF_FRAME_LEN_TS 4
+#define BMI160_FF_DATA_LEN_ACC 6
+#define BMI160_FF_DATA_LEN_GYR 6
+#define BMI160_FF_DATA_LEN_MAG 8
+
+#if 0
+#define BMI160_DPS_SEL_245 (0 << 3)
+#define BMI160_DPS_SEL_500 (1 << 3)
+#define BMI160_DPS_SEL_1000 (2 << 3)
+#define BMI160_DPS_SEL_2000 (3 << 3)
+#define BMI160_GSEL_2G (0 << 3)
+#define BMI160_GSEL_4G (2 << 3)
+#define BMI160_GSEL_8G (3 << 3)
+
+#define BMI160_RANGE_MASK (3 << 3)
+
+#define BMI160_ODR_PD (0 << 5)
+#define BMI160_ODR_10HZ (1 << 5)
+#define BMI160_ODR_15HZ (1 << 5)
+#define BMI160_ODR_50HZ (2 << 5)
+#define BMI160_ODR_59HZ (2 << 5)
+#define BMI160_ODR_119HZ (3 << 5)
+#define BMI160_ODR_238HZ (4 << 5)
+#define BMI160_ODR_476HZ (5 << 5)
+#define BMI160_ODR_952HZ (6 << 5)
+
+#define BMI160_ODR_MASK (7 << 5)
+
+/*
+ * Register : STATUS_REG
+ * Address : 0X27
+ */
+enum bmi160_status {
+ BMI160_STS_DOWN = 0x00,
+ BMI160_STS_XLDA_UP = 0x01,
+ BMI160_STS_GDA_UP = 0x02,
+};
+#define BMI160_STS_XLDA_MASK 0x01
+#define BMI160_STS_GDA_MASK 0x02
+
+/*
+ * Register : CTRL_REG8
+ * Address : 0X22
+ * Bit Group Name: BDU
+ */
+enum bmi160_bdu {
+ BMI160_BDU_DISABLE = 0x00,
+ BMI160_BDU_ENABLE = 0x40,
+};
+#endif
+
+/* Sensor resolution in number of bits. This sensor has fixed resolution. */
+#define BMI160_RESOLUTION 16
+
+extern const struct accelgyro_drv bmi160_drv;
+
+enum bmi160_running_mode {
+ STANDARD_UI_9DOF_FIFO = 0,
+ STANDARD_UI_IMU_FIFO = 1,
+ STANDARD_UI_IMU = 2,
+ STANDARD_UI_ADVANCEPOWERSAVE = 3,
+ ACCEL_PEDOMETER = 4,
+ APPLICATION_HEAD_TRACKING = 5,
+ APPLICATION_NAVIGATION = 6,
+ APPLICATION_REMOTE_CONTROL = 7,
+ APPLICATION_INDOOR_NAVIGATION = 8,
+};
+
+#endif /* __CROS_EC_ACCEL_BMI160_H */
diff --git a/driver/build.mk b/driver/build.mk
index 545b4cc934..f45b293dc7 100644
--- a/driver/build.mk
+++ b/driver/build.mk
@@ -9,6 +9,7 @@
# Accelerometers
driver-$(CONFIG_ACCEL_KXCJ9)+=accel_kxcj9.o
driver-$(CONFIG_ACCELGYRO_LSM6DS0)+=accelgyro_lsm6ds0.o
+driver-$(CONFIG_ACCELGYRO_BMI160)+=accelgyro_bmi160.o
# ALS drivers
driver-$(CONFIG_ALS_ISL29035)+=als_isl29035.o
diff --git a/include/ec_commands.h b/include/ec_commands.h
index ad3056e3e8..8a05d0ab5b 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1659,6 +1659,7 @@ enum motionsense_command {
enum motionsensor_type {
MOTIONSENSE_TYPE_ACCEL = 0,
MOTIONSENSE_TYPE_GYRO = 1,
+ MOTIONSENSE_TYPE_MAG = 2,
};
/* List of motion sensor locations. */
@@ -1671,6 +1672,7 @@ enum motionsensor_location {
enum motionsensor_chip {
MOTIONSENSE_CHIP_KXCJ9 = 0,
MOTIONSENSE_CHIP_LSM6DS0 = 1,
+ MOTIONSENSE_CHIP_BMI160 = 2,
};
/* Module flag masks used for the dump sub-command. */