summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2018-06-13 13:16:25 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-06-17 02:40:44 -0700
commitee5d8b8a627381e906369f6c108dab7be2ac7518 (patch)
treedbe28641ba108a9feec991e8bfb8036a64a9e85f
parentfc1496d1bb84f74d539bc11a205d90926dc79740 (diff)
downloadchrome-ec-ee5d8b8a627381e906369f6c108dab7be2ac7518.tar.gz
driver: bmi160: Rename secondary i2c access functions
Make it more generic to support sensor other than BMI159. BUG=b:110143516 BRANCH=none TEST=compile Change-Id: I954df2e9301e05968930add396cd724ca0dfa262 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1101550 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--driver/accelgyro_bmi160.c15
-rw-r--r--driver/accelgyro_bmi160.h11
-rw-r--r--driver/mag_bmm150.c12
-rw-r--r--include/config.h5
4 files changed, 28 insertions, 15 deletions
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c
index b7bd6f5cbb..0e765e5d5e 100644
--- a/driver/accelgyro_bmi160.c
+++ b/driver/accelgyro_bmi160.c
@@ -241,14 +241,14 @@ static int raw_read_n(const int port, const int addr, const uint8_t reg,
return rv;
}
-#ifdef CONFIG_MAG_BMI160_BMM150
+#ifdef CONFIG_BMI160_SEC_I2C
/**
* Control access to the compass on the secondary i2c interface:
* enable values are:
* 1: manual access, we can issue i2c to the compass
* 0: data access: BMI160 gather data periodically from the compass.
*/
-static int bmm150_mag_access_ctrl(const int port, const int addr,
+static int bmi160_sec_access_ctrl(const int port, const int addr,
const int enable)
{
int mag_if_ctrl;
@@ -269,7 +269,7 @@ static int bmm150_mag_access_ctrl(const int port, const int addr,
* Read register from compass.
* Assuming we are in manual access mode, read compass i2c register.
*/
-int raw_mag_read8(const int port, const int addr, const uint8_t reg,
+int bmi160_sec_raw_read8(const int port, const int addr, const uint8_t reg,
int *data_ptr)
{
/* Only read 1 bytes */
@@ -281,7 +281,8 @@ int raw_mag_read8(const int port, const int addr, const uint8_t reg,
* Write register from compass.
* Assuming we are in manual access mode, write to compass i2c register.
*/
-int raw_mag_write8(const int port, const int addr, const uint8_t reg, int data)
+int bmi160_sec_raw_write8(const int port, const int addr, const uint8_t reg,
+ int data)
{
raw_write8(port, addr, BMI160_MAG_I2C_WRITE_DATA, data);
return raw_write8(port, addr, BMI160_MAG_I2C_WRITE_ADDR, reg);
@@ -1200,7 +1201,7 @@ static int init(const struct motion_sensor_t *s)
raw_write8(s->port, s->addr, BMI160_PMU_TRIGGER, 0);
}
-#ifdef CONFIG_MAG_BMI160_BMM150
+#ifdef CONFIG_BMI160_SEC_I2C
if (s->type == MOTIONSENSE_TYPE_MAG) {
struct bmi160_drv_data_t *data = BMI160_GET_DATA(s);
@@ -1263,7 +1264,7 @@ static int init(const struct motion_sensor_t *s)
}
- bmm150_mag_access_ctrl(s->port, s->addr, 1);
+ bmi160_sec_access_ctrl(s->port, s->addr, 1);
ret = bmm150_init(s);
if (ret)
@@ -1277,7 +1278,7 @@ static int init(const struct motion_sensor_t *s)
* Put back the secondary interface in normal mode.
* BMI160 will poll based on the configure ODR.
*/
- bmm150_mag_access_ctrl(s->port, s->addr, 0);
+ bmi160_sec_access_ctrl(s->port, s->addr, 0);
}
#endif
diff --git a/driver/accelgyro_bmi160.h b/driver/accelgyro_bmi160.h
index 9d756ae9c2..fa72649e01 100644
--- a/driver/accelgyro_bmi160.h
+++ b/driver/accelgyro_bmi160.h
@@ -493,11 +493,12 @@ struct bmi160_drv_data_t {
void bmi160_interrupt(enum gpio_signal signal);
-#ifdef CONFIG_MAG_BMI160_BMM150
-/* Functions to access the compass through the accel/gyro. */
-int raw_mag_read8(const int port, const int addr, const uint8_t reg,
- int *data_ptr);
-int raw_mag_write8(const int port, const int addr, const uint8_t reg, int data);
+#ifdef CONFIG_BMI160_SEC_I2C
+/* Functions to access the secondary device through the accel/gyro. */
+int bmi160_sec_raw_read8(const int port, const int addr, const uint8_t reg,
+ int *data_ptr);
+int bmi160_sec_raw_write8(const int port, const int addr, const uint8_t reg,
+ int data);
#endif
#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL
diff --git a/driver/mag_bmm150.c b/driver/mag_bmm150.c
index c546dec1ce..014909b365 100644
--- a/driver/mag_bmm150.c
+++ b/driver/mag_bmm150.c
@@ -10,7 +10,6 @@
#include "accelgyro.h"
#include "common.h"
#include "console.h"
-#include "driver/accelgyro_bmi160.h"
#include "driver/mag_bmm150.h"
#include "hooks.h"
#include "i2c.h"
@@ -18,6 +17,15 @@
#include "timer.h"
#include "util.h"
+#ifdef CONFIG_MAG_BMI160_BMM150
+#include "driver/accelgyro_bmi160.h"
+#define raw_mag_read8 bmi160_sec_raw_read8
+#define raw_mag_write8 bmi160_sec_raw_write8
+#else
+#error "Not implemented"
+#endif
+
+
#define CPUTS(outstr) cputs(CC_ACCEL, outstr)
#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args)
#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args)
@@ -63,8 +71,6 @@
* patent rights of the copyright holder.
*/
-#include "mag_bmm150.h"
-
#define BMI150_READ_16BIT_COM_REG(store_, addr_) do { \
int val; \
raw_mag_read8(s->port, s->addr, (addr_), &val); \
diff --git a/include/config.h b/include/config.h
index 423496b5af..248f8ce1c1 100644
--- a/include/config.h
+++ b/include/config.h
@@ -3779,4 +3779,9 @@
#define CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ \
CONFIG_EC_MAX_SENSOR_FREQ_DEFAULT_MILLIHZ
#endif
+
+/* Enable BMI160 secondary port if needed. */
+#ifdef CONFIG_MAG_BMI160_BMM150
+#define CONFIG_BMI160_SEC_I2C
+#endif
#endif /* __CROS_EC_CONFIG_H */