summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/amenia/board.c4
-rw-r--r--board/elm/board.c5
-rw-r--r--board/glados/board.c4
-rw-r--r--board/kevin/board.c4
-rw-r--r--board/oak/board.c4
-rw-r--r--board/reef/board.c4
-rw-r--r--board/samus/board.c4
-rw-r--r--board/strago/board.c5
-rw-r--r--board/wheatley/board.c4
-rw-r--r--driver/accel_kionix.c71
-rw-r--r--driver/accel_kionix.h8
11 files changed, 47 insertions, 70 deletions
diff --git a/board/amenia/board.c b/board/amenia/board.c
index 82bfb238b2..d6e13b0264 100644
--- a/board/amenia/board.c
+++ b/board/amenia/board.c
@@ -484,9 +484,7 @@ const matrix_3x3_t base_standard_ref = {
};
/* KX022 private data */
-struct kionix_accel_data g_kx022_data = {
- .variant = KX022,
-};
+struct kionix_accel_data g_kx022_data;
struct motion_sensor_t motion_sensors[] = {
/*
diff --git a/board/elm/board.c b/board/elm/board.c
index a7562d9bb1..ce9a0154bc 100644
--- a/board/elm/board.c
+++ b/board/elm/board.c
@@ -496,10 +496,7 @@ const matrix_3x3_t lid_standard_ref = {
};
/* KX022 private data */
-struct kionix_accel_data g_kx022_data[2] = {
- {.variant = KX022},
- {.variant = KX022},
-};
+struct kionix_accel_data g_kx022_data[2];
struct motion_sensor_t motion_sensors[] = {
{.name = "Base Accel",
diff --git a/board/glados/board.c b/board/glados/board.c
index a6bfb36e15..83e5520535 100644
--- a/board/glados/board.c
+++ b/board/glados/board.c
@@ -473,9 +473,7 @@ static struct mutex g_lid_mutex;
static struct mutex g_base_mutex;
/* KX022 private data */
-struct kionix_accel_data g_kx022_data = {
- .variant = KX022,
-};
+struct kionix_accel_data g_kx022_data;
struct motion_sensor_t motion_sensors[] = {
/*
diff --git a/board/kevin/board.c b/board/kevin/board.c
index 628fcde0f4..b566f199b0 100644
--- a/board/kevin/board.c
+++ b/board/kevin/board.c
@@ -469,9 +469,7 @@ const matrix_3x3_t lid_standard_ref = {
};
/* KX022 private data */
-struct kionix_accel_data g_kx022_data = {
- .variant = KX022,
-};
+struct kionix_accel_data g_kx022_data;
#endif /* BOARD_KEVIN */
struct motion_sensor_t motion_sensors[] = {
diff --git a/board/oak/board.c b/board/oak/board.c
index 1c12dafe6e..bdacb78567 100644
--- a/board/oak/board.c
+++ b/board/oak/board.c
@@ -648,9 +648,7 @@ const matrix_3x3_t base_standard_ref = {
#endif
/* KX022 private data */
-struct kionix_accel_data g_kx022_data = {
- .variant = KX022,
-};
+struct kionix_accel_data g_kx022_data;
struct motion_sensor_t motion_sensors[] = {
#ifdef CONFIG_ACCELGYRO_BMI160
diff --git a/board/reef/board.c b/board/reef/board.c
index d7343e9ffe..c58520d8e1 100644
--- a/board/reef/board.c
+++ b/board/reef/board.c
@@ -722,9 +722,7 @@ const matrix_3x3_t base_standard_ref = {
};
/* KX022 private data */
-struct kionix_accel_data g_kx022_data = {
- .variant = KX022,
-};
+struct kionix_accel_data g_kx022_data;
/* FIXME(dhendrix): Copied from Amenia, probably need to tweak for Reef */
struct motion_sensor_t motion_sensors[] = {
diff --git a/board/samus/board.c b/board/samus/board.c
index 5257899ecc..b5d0a9830b 100644
--- a/board/samus/board.c
+++ b/board/samus/board.c
@@ -274,9 +274,7 @@ static struct mutex g_base_mutex;
static struct mutex g_lid_mutex;
/* kxcj9 local/private data */
-struct kionix_accel_data g_kxcj9_data = {
- .variant = KXCJ9,
-};
+struct kionix_accel_data g_kxcj9_data;
/* lsm6ds0 local sensor data (per-sensor) */
struct lsm6ds0_data g_saved_data[2];
diff --git a/board/strago/board.c b/board/strago/board.c
index 58759de1f3..ecef093e41 100644
--- a/board/strago/board.c
+++ b/board/strago/board.c
@@ -183,10 +183,7 @@ void board_reset_pd_mcu(void)
/* Four Motion sensors */
/* kxcj9 mutex and local/private data*/
static struct mutex g_kxcj9_mutex[2];
-struct kionix_accel_data g_kxcj9_data[2] = {
- {.variant = KXCJ9},
- {.variant = KXCJ9},
-};
+struct kionix_accel_data g_kxcj9_data[2];
/* Matrix to rotate accelrator into standard reference frame */
const matrix_3x3_t base_standard_ref = {
diff --git a/board/wheatley/board.c b/board/wheatley/board.c
index 5ae6caf1a2..fa39533de5 100644
--- a/board/wheatley/board.c
+++ b/board/wheatley/board.c
@@ -453,9 +453,7 @@ static struct mutex g_lid_mutex;
static struct mutex g_base_mutex;
/* KX022 private data */
-struct kionix_accel_data g_kx022_data = {
- .variant = KX022,
-};
+struct kionix_accel_data g_kx022_data;
struct motion_sensor_t motion_sensors[] = {
/*
diff --git a/driver/accel_kionix.c b/driver/accel_kionix.c
index ecd96c3119..750c8cd808 100644
--- a/driver/accel_kionix.c
+++ b/driver/accel_kionix.c
@@ -27,11 +27,18 @@
/* Number of times to attempt to enable sensor before giving up. */
#define SENSOR_ENABLE_ATTEMPTS 3
+#if defined(CONFIG_ACCEL_KXCJ9) && !defined(CONFIG_ACCEL_KX022)
+#define V(s_) 1
+#elif defined(CONFIG_ACCEL_KX022) && !defined(CONFIG_ACCEL_KXCJ9)
+#define V(s_) 0
+#else
+#define V(s_) ((s_)->chip == MOTIONSENSE_CHIP_KXCJ9)
+#endif
/* Index for which table to use. */
#if !defined(CONFIG_ACCEL_KXCJ9) || !defined(CONFIG_ACCEL_KX022)
-#define T 0
+#define T(s_) 0
#else
-#define T (data->variant)
+#define T(s_) V(s_)
#endif /* !defined(CONFIG_ACCEL_KXCJ9) || !defined(CONFIG_ACCEL_KX022) */
/* List of range values in +/-G's and their associated register values. */
@@ -202,10 +209,9 @@ static int raw_read_multi(const int port, int addr, uint8_t reg,
static int disable_sensor(const struct motion_sensor_t *s, int *reg_val)
{
int i, ret, reg, pc1_field;
- struct kionix_accel_data *data = s->drv_data;
- reg = KIONIX_CTRL1_REG(data->variant);
- pc1_field = KIONIX_PC1_FIELD(data->variant);
+ reg = KIONIX_CTRL1_REG(V(s));
+ pc1_field = KIONIX_PC1_FIELD(V(s));
/*
* Read the current state of the control register
@@ -238,10 +244,9 @@ static int disable_sensor(const struct motion_sensor_t *s, int *reg_val)
static int enable_sensor(const struct motion_sensor_t *s, int reg_val)
{
int i, ret, reg, pc1_field;
- struct kionix_accel_data *data = s->drv_data;
- reg = KIONIX_CTRL1_REG(data->variant);
- pc1_field = KIONIX_PC1_FIELD(data->variant);
+ reg = KIONIX_CTRL1_REG(V(s));
+ pc1_field = KIONIX_PC1_FIELD(V(s));
for (i = 0; i < SENSOR_ENABLE_ATTEMPTS; i++) {
ret = raw_read8(s->port, s->addr, reg, &reg_val);
@@ -265,10 +270,11 @@ static int set_range(const struct motion_sensor_t *s, int range, int rnd)
struct kionix_accel_data *data = s->drv_data;
/* Find index for interface pair matching the specified range. */
- index = find_param_index(range, rnd, ranges[T], ARRAY_SIZE(ranges[T]));
- range_field = KIONIX_RANGE_FIELD(data->variant);
- reg = KIONIX_CTRL1_REG(data->variant);
- range_val = ranges[T][index].reg;
+ index = find_param_index(range, rnd, ranges[T(s)],
+ ARRAY_SIZE(ranges[T(s)]));
+ range_field = KIONIX_RANGE_FIELD(V(s));
+ reg = KIONIX_CTRL1_REG(V(s));
+ range_val = ranges[T(s)][index].reg;
/* Disable the sensor to allow for changing of critical parameters. */
mutex_lock(s->mutex);
@@ -299,7 +305,7 @@ static int set_range(const struct motion_sensor_t *s, int range, int rnd)
static int get_range(const struct motion_sensor_t *s)
{
struct kionix_accel_data *data = s->drv_data;
- return ranges[T][data->sensor_range].val;
+ return ranges[T(s)][data->sensor_range].val;
}
static int set_resolution(const struct motion_sensor_t *s, int res, int rnd)
@@ -308,11 +314,11 @@ static int set_resolution(const struct motion_sensor_t *s, int res, int rnd)
struct kionix_accel_data *data = s->drv_data;
/* Find index for interface pair matching the specified resolution. */
- index = find_param_index(res, rnd, resolutions[T],
- ARRAY_SIZE(resolutions[T]));
- res_val = resolutions[T][index].reg;
- res_field = KIONIX_RES_FIELD(data->variant);
- reg = KIONIX_CTRL1_REG(data->variant);
+ index = find_param_index(res, rnd, resolutions[T(s)],
+ ARRAY_SIZE(resolutions[T(s)]));
+ res_val = resolutions[T(s)][index].reg;
+ res_field = KIONIX_RES_FIELD(V(s));
+ reg = KIONIX_CTRL1_REG(V(s));
/* Disable the sensor to allow for changing of critical parameters. */
mutex_lock(s->mutex);
@@ -343,7 +349,7 @@ static int set_resolution(const struct motion_sensor_t *s, int res, int rnd)
static int get_resolution(const struct motion_sensor_t *s)
{
struct kionix_accel_data *data = s->drv_data;
- return resolutions[T][data->sensor_resolution].val;
+ return resolutions[T(s)][data->sensor_resolution].val;
}
static int set_data_rate(const struct motion_sensor_t *s, int rate, int rnd)
@@ -353,11 +359,11 @@ static int set_data_rate(const struct motion_sensor_t *s, int rate, int rnd)
struct kionix_accel_data *data = s->drv_data;
/* Find index for interface pair matching the specified rate. */
- index = find_param_index(rate, rnd, datarates[T],
- ARRAY_SIZE(datarates[T]));
- odr_val = datarates[T][index].reg;
- reg = KIONIX_ODR_REG(data->variant);
- odr_field = KIONIX_ODR_FIELD(data->variant);
+ index = find_param_index(rate, rnd, datarates[T(s)],
+ ARRAY_SIZE(datarates[T(s)]));
+ odr_val = datarates[T(s)][index].reg;
+ reg = KIONIX_ODR_REG(V(s));
+ odr_field = KIONIX_ODR_FIELD(V(s));
/* Disable the sensor to allow for changing of critical parameters. */
mutex_lock(s->mutex);
@@ -392,7 +398,7 @@ static int set_data_rate(const struct motion_sensor_t *s, int rate, int rnd)
static int get_data_rate(const struct motion_sensor_t *s)
{
struct kionix_accel_data *data = s->drv_data;
- return datarates[T][data->sensor_datarate].val;
+ return datarates[T(s)][data->sensor_datarate].val;
}
static int set_offset(const struct motion_sensor_t *s, const int16_t *offset,
@@ -425,7 +431,7 @@ static int read(const struct motion_sensor_t *s, vector_3_t v)
struct kionix_accel_data *data = s->drv_data;
/* Read 6 bytes starting at XOUT_L. */
- reg = KIONIX_XOUT_L(data->variant);
+ reg = KIONIX_XOUT_L(V(s));
mutex_lock(s->mutex);
ret = raw_read_multi(s->port, s->addr, reg, acc, 6);
mutex_unlock(s->mutex);
@@ -448,11 +454,11 @@ static int read(const struct motion_sensor_t *s, vector_3_t v)
*/
resolution = get_resolution(s);
for (i = X; i <= Z; i++) {
- if (KXCJ9 == data->variant) {
+ if (V(s)) {
v[i] = (((int8_t)acc[i * 2 + 1]) << 4) |
(acc[i * 2] >> 4);
v[i] <<= 16 - resolution;
- } else if (KX022 == data->variant) {
+ } else {
if (resolution == 8)
acc[i * 2] = 0;
v[i] = (((int8_t)acc[i * 2 + 1]) << 8) | acc[i * 2];
@@ -472,10 +478,9 @@ static int init(const struct motion_sensor_t *s)
{
int ret, val, reg, reset_field;
uint8_t timeout;
- struct kionix_accel_data *data = s->drv_data;
- reg = KIONIX_CTRL2_REG(data->variant);
- reset_field = KIONIX_RESET_FIELD(data->variant);
+ reg = KIONIX_CTRL2_REG(V(s));
+ reset_field = KIONIX_RESET_FIELD(V(s));
/* Issue a software reset. */
mutex_lock(s->mutex);
@@ -527,9 +532,9 @@ static int init(const struct motion_sensor_t *s)
if (ret != EC_SUCCESS)
return ret;
- if (KXCJ9 == data->variant)
+ if (V(s))
ret = set_resolution(s, 12, 1);
- else if (KX022 == data->variant)
+ else
ret = set_resolution(s, 16, 1);
if (ret != EC_SUCCESS)
return ret;
diff --git a/driver/accel_kionix.h b/driver/accel_kionix.h
index 3dc7f314a4..6c71cb7918 100644
--- a/driver/accel_kionix.h
+++ b/driver/accel_kionix.h
@@ -12,12 +12,6 @@
#include "driver/accel_kx022.h"
#include "driver/accel_kxcj9.h"
-enum kionix_accel {
- KX022,
- KXCJ9,
- SUPPORTED_KIONIX_ACCELS,
-};
-
/*
* Struct for pairing an engineering value with the register value for a
* parameter.
@@ -28,8 +22,6 @@ struct accel_param_pair {
};
struct kionix_accel_data {
- /* Variant of Kionix Accelerometer. */
- uint8_t variant;
/* Note, the following are indicies into their respective tables. */
/* Current range of accelerometer. */
int sensor_range;