summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2019-11-19 11:07:02 -0700
committerCommit Bot <commit-bot@chromium.org>2019-11-21 19:44:12 +0000
commit55dc3bb5577f2db697c2b0322d8d98f87aa47e38 (patch)
treed31e4a3394ebca5955703e208927e490225c6335
parentb2f6e2cbfad15bbf07c78be11f9fe6376acfb745 (diff)
downloadchrome-ec-55dc3bb5577f2db697c2b0322d8d98f87aa47e38.tar.gz
driver: lsm6dsm: Allow building without CONFIG_ACCEL_FIFO
This change refactors the lsm6dsm to allow building without the use of the FIFO or sensor interrupts. BUG=None BRANCH=None TEST=make buildall Change-Id: I5b338d81061f25fd1c8209b4555f63ea4d8b2dbc Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1916679 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Auto-Submit: Leifu Zhao <leifu.zhao@intel.corp-partner.google.com> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r--board/akemi/board.c2
-rw-r--r--board/arcada_ish/board.c2
-rw-r--r--board/bloog/board.c2
-rw-r--r--board/drallion_ish/board.c2
-rw-r--r--board/fleex/board.c2
-rw-r--r--board/kodama/board.c2
-rw-r--r--board/meep/board.c2
-rw-r--r--board/phaser/board.c2
-rw-r--r--board/tglrvp_ish/board.c2
-rw-r--r--board/treeya/board.c2
-rw-r--r--board/yorp/board.c2
-rw-r--r--driver/accelgyro_lsm6dsm.c66
-rw-r--r--driver/accelgyro_lsm6dsm.h39
13 files changed, 79 insertions, 48 deletions
diff --git a/board/akemi/board.c b/board/akemi/board.c
index ff3385679f..5ec34712f9 100644
--- a/board/akemi/board.c
+++ b/board/akemi/board.c
@@ -172,7 +172,7 @@ static struct mutex g_lid_mutex;
/* Lid accel private data */
static struct stprivate_data g_lis2dwl_data;
/* Base accel private data */
-static struct lsm6dsm_data lsm6dsm_data;
+static struct lsm6dsm_data lsm6dsm_data = LSM6DSM_DATA;
/* Matrix to rotate accelrator into standard reference frame */
static const mat33_fp_t base_standard_ref = {
diff --git a/board/arcada_ish/board.c b/board/arcada_ish/board.c
index 8c96067be5..ea8118642e 100644
--- a/board/arcada_ish/board.c
+++ b/board/arcada_ish/board.c
@@ -37,7 +37,7 @@ static struct mutex g_lid_mag_mutex;
static struct mutex g_base_mutex;
/* sensor private data */
-static struct lsm6dsm_data lsm6dsm_a_data;
+static struct lsm6dsm_data lsm6dsm_a_data = LSM6DSM_DATA;
static struct stprivate_data g_lis2dh_data;
static struct lis2mdl_private_data lis2mdl_a_data;
diff --git a/board/bloog/board.c b/board/bloog/board.c
index 42049d0ef7..9387938d78 100644
--- a/board/bloog/board.c
+++ b/board/bloog/board.c
@@ -124,7 +124,7 @@ const mat33_fp_t base_standard_ref = {
/* sensor private data */
static struct kionix_accel_data kx022_data;
-static struct lsm6dsm_data lsm6dsm_data;
+static struct lsm6dsm_data lsm6dsm_data = LSM6DSM_DATA;
/* Drivers */
struct motion_sensor_t motion_sensors[] = {
diff --git a/board/drallion_ish/board.c b/board/drallion_ish/board.c
index cc46d37b5a..933f3d26d5 100644
--- a/board/drallion_ish/board.c
+++ b/board/drallion_ish/board.c
@@ -38,7 +38,7 @@ static struct mutex g_lid_mag_mutex;
static struct mutex g_base_mutex;
/* sensor private data */
-static struct lsm6dsm_data lsm6dsm_a_data;
+static struct lsm6dsm_data lsm6dsm_a_data = LSM6DSM_DATA;
static struct stprivate_data g_lis2dh_data;
static struct lis2mdl_private_data lis2mdl_a_data;
diff --git a/board/fleex/board.c b/board/fleex/board.c
index 7ee6495b86..564b346c18 100644
--- a/board/fleex/board.c
+++ b/board/fleex/board.c
@@ -119,7 +119,7 @@ const mat33_fp_t lid_standard_ref = {
/* sensor private data */
static struct stprivate_data g_lis2dh_data;
-static struct lsm6dsm_data lsm6dsm_data;
+static struct lsm6dsm_data lsm6dsm_data = LSM6DSM_DATA;
/* Drivers */
struct motion_sensor_t motion_sensors[] = {
diff --git a/board/kodama/board.c b/board/kodama/board.c
index 968f5e5749..953c3e7831 100644
--- a/board/kodama/board.c
+++ b/board/kodama/board.c
@@ -241,7 +241,7 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
#ifdef SECTION_IS_RW
static struct mutex g_lid_mutex;
-static struct lsm6dsm_data lsm6dsm_data;
+static struct lsm6dsm_data lsm6dsm_data = LSM6DSM_DATA;
/* Matrix to rotate accelerometer into standard reference frame */
static const mat33_fp_t lid_standard_ref = {
diff --git a/board/meep/board.c b/board/meep/board.c
index 200909dca0..ed781e7f81 100644
--- a/board/meep/board.c
+++ b/board/meep/board.c
@@ -124,7 +124,7 @@ const mat33_fp_t base_standard_ref = {
/* sensor private data */
static struct kionix_accel_data kx022_data;
-static struct lsm6dsm_data lsm6dsm_data;
+static struct lsm6dsm_data lsm6dsm_data = LSM6DSM_DATA;
/* Drivers */
struct motion_sensor_t motion_sensors[] = {
diff --git a/board/phaser/board.c b/board/phaser/board.c
index 009bbfb25a..7889b102dc 100644
--- a/board/phaser/board.c
+++ b/board/phaser/board.c
@@ -106,7 +106,7 @@ const mat33_fp_t standard_rot_ref = {
/* sensor private data */
static struct stprivate_data g_lis2dh_data;
-static struct lsm6dsm_data lsm6dsm_data;
+static struct lsm6dsm_data lsm6dsm_data = LSM6DSM_DATA;
/* Drivers */
struct motion_sensor_t motion_sensors[] = {
diff --git a/board/tglrvp_ish/board.c b/board/tglrvp_ish/board.c
index 313f7ced8a..3c8fd36cb6 100644
--- a/board/tglrvp_ish/board.c
+++ b/board/tglrvp_ish/board.c
@@ -30,7 +30,7 @@ const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* Sensor config */
static struct mutex g_base_mutex;
/* sensor private data */
-static struct lsm6dsm_data lsm6dsm_a_data;
+static struct lsm6dsm_data lsm6dsm_a_data = LSM6DSM_DATA;
/* Drivers */
struct motion_sensor_t motion_sensors[] = {
diff --git a/board/treeya/board.c b/board/treeya/board.c
index eb6985b7e0..fbcbb8aa35 100644
--- a/board/treeya/board.c
+++ b/board/treeya/board.c
@@ -49,7 +49,7 @@ static struct mutex g_base_mutex_1;
/* Lid accel private data */
static struct stprivate_data g_lis2dwl_data;
/* Base accel private data */
-static struct lsm6dsm_data g_lsm6dsm_data;
+static struct lsm6dsm_data g_lsm6dsm_data = LSM6DSM_DATA;
/* Matrix to rotate accelrator into standard reference frame */
diff --git a/board/yorp/board.c b/board/yorp/board.c
index 89dee7fb41..89a5b20c1a 100644
--- a/board/yorp/board.c
+++ b/board/yorp/board.c
@@ -105,7 +105,7 @@ const mat33_fp_t base_standard_ref = {
/* sensor private data */
static struct kionix_accel_data g_kx022_data;
-static struct lsm6dsm_data lsm6dsm_data;
+static struct lsm6dsm_data lsm6dsm_data = LSM6DSM_DATA;
/* Drivers */
struct motion_sensor_t motion_sensors[] = {
diff --git a/driver/accelgyro_lsm6dsm.c b/driver/accelgyro_lsm6dsm.c
index 4c6e90b13e..3d0c717a9b 100644
--- a/driver/accelgyro_lsm6dsm.c
+++ b/driver/accelgyro_lsm6dsm.c
@@ -26,6 +26,14 @@
#define IS_FSTS_EMPTY(s) ((s).len & LSM6DSM_FIFO_EMPTY)
+#ifndef FIFO_READ_LEN
+#define FIFO_READ_LEN 0
+#endif
+
+#ifndef CONFIG_ACCEL_LSM6DSM_INT_EVENT
+#define CONFIG_ACCEL_LSM6DSM_INT_EVENT 0
+#endif
+
static volatile uint32_t last_interrupt_timestamp;
/**
@@ -35,14 +43,16 @@ static volatile uint32_t last_interrupt_timestamp;
* @param s Pointer to the first sensor in the lsm6dsm (accelerometer).
* @param ts The timestamp to use for the interrupt timestamp.
*/
-static void reset_load_fifo_sensor_state(struct motion_sensor_t *s, uint32_t ts)
+__maybe_unused static void reset_load_fifo_sensor_state(
+ struct motion_sensor_t *s, uint32_t ts)
{
int i;
- struct lsm6dsm_data *data = LSM6DSM_GET_DATA(s);
+ struct lsm6dsm_accel_fifo_state *fifo_state =
+ LSM6DSM_GET_DATA(s)->accel_fifo_state;
for (i = 0; i < FIFO_DEV_NUM; i++) {
- data->load_fifo_sensor_state[i].int_timestamp = ts;
- data->load_fifo_sensor_state[i].sample_count = 0;
+ fifo_state->load_fifo_sensor_state[i].int_timestamp = ts;
+ fifo_state->load_fifo_sensor_state[i].sample_count = 0;
}
}
@@ -91,7 +101,6 @@ static inline int get_xyz_reg(enum motionsensor_type type)
(LSM6DSM_ACCEL_OUT_X_L_ADDR - LSM6DSM_GYRO_OUT_X_L_ADDR) * type;
}
-#ifdef CONFIG_ACCEL_INTERRUPTS
/**
* Configure interrupt int 1 to fire handler for:
*
@@ -99,7 +108,7 @@ static inline int get_xyz_reg(enum motionsensor_type type)
*
* @accel: Motion sensor pointer to accelerometer.
*/
-static int config_interrupt(const struct motion_sensor_t *accel)
+__maybe_unused static int config_interrupt(const struct motion_sensor_t *accel)
{
int ret = EC_SUCCESS;
int int1_ctrl_val;
@@ -142,9 +151,10 @@ static int fifo_disable(const struct motion_sensor_t *accel)
static void fifo_reset_pattern(struct lsm6dsm_data *private)
{
/* The fifo is ready to run. */
- memcpy(&private->current, &private->config,
+ memcpy(&private->accel_fifo_state->current,
+ &private->accel_fifo_state->config,
sizeof(struct lsm6dsm_fifo_data));
- private->next_in_patten = FIFO_DEV_INVALID;
+ private->accel_fifo_state->next_in_pattern = FIFO_DEV_INVALID;
}
/**
@@ -164,6 +174,7 @@ static int fifo_enable(const struct motion_sensor_t *accel)
unsigned int max_odr = 0;
uint8_t odr_reg_val;
struct lsm6dsm_data *private = LSM6DSM_GET_DATA(accel);
+ struct lsm6dsm_accel_fifo_state *fifo_state = private->accel_fifo_state;
/* In FIFO sensors are mapped in a different way. */
uint8_t agm_maps[] = {
MOTIONSENSE_TYPE_GYRO,
@@ -196,18 +207,18 @@ static int fifo_enable(const struct motion_sensor_t *accel)
LSM6DSM_FIFO_CTRL5_ADDR, odr_reg_val);
/* Scan all sensors configuration to calculate FIFO decimator. */
- private->config.total_samples_in_pattern = 0;
+ fifo_state->config.total_samples_in_pattern = 0;
for (i = FIFO_DEV_GYRO; i < FIFO_DEV_NUM; i++) {
if (odrs[i] > 0) {
- private->config.samples_in_pattern[i] =
+ fifo_state->config.samples_in_pattern[i] =
odrs[i] / min_odr;
decimators[i] =
LSM6DSM_FIFO_DECIMATOR(max_odr / odrs[i]);
- private->config.total_samples_in_pattern +=
- private->config.samples_in_pattern[i];
+ fifo_state->config.total_samples_in_pattern +=
+ fifo_state->config.samples_in_pattern[i];
} else {
/* Not in FIFO if sensor disabled. */
- private->config.samples_in_pattern[i] = 0;
+ fifo_state->config.samples_in_pattern[i] = 0;
}
}
st_raw_write8(accel->port, accel->i2c_spi_addr_flags,
@@ -276,11 +287,12 @@ static int fifo_enable(const struct motion_sensor_t *accel)
static int fifo_next(struct lsm6dsm_data *private)
{
int next_id;
+ struct lsm6dsm_accel_fifo_state *fifo_state = private->accel_fifo_state;
- if (private->current.total_samples_in_pattern == 0)
+ if (fifo_state->current.total_samples_in_pattern == 0)
fifo_reset_pattern(private);
- if (private->current.total_samples_in_pattern == 0) {
+ if (fifo_state->current.total_samples_in_pattern == 0) {
/*
* Not expected we are supposed to be called to process FIFO
* data.
@@ -289,13 +301,13 @@ static int fifo_next(struct lsm6dsm_data *private)
return FIFO_DEV_INVALID;
}
- for (next_id = private->next_in_patten + 1; 1; next_id++) {
+ for (next_id = fifo_state->next_in_pattern + 1; 1; next_id++) {
if (next_id == FIFO_DEV_NUM)
next_id = FIFO_DEV_GYRO;
- if (private->current.samples_in_pattern[next_id] != 0) {
- private->current.samples_in_pattern[next_id]--;
- private->current.total_samples_in_pattern--;
- private->next_in_patten = next_id;
+ if (fifo_state->current.samples_in_pattern[next_id] != 0) {
+ fifo_state->current.samples_in_pattern[next_id]--;
+ fifo_state->current.total_samples_in_pattern--;
+ fifo_state->next_in_pattern = next_id;
return next_id;
}
}
@@ -328,8 +340,8 @@ static void push_fifo_data(struct motion_sensor_t *accel, uint8_t *fifo,
}
id = get_sensor_type(next_fifo);
- if (private->samples_to_discard[id] > 0) {
- private->samples_to_discard[id]--;
+ if (private->accel_fifo_state->samples_to_discard[id] > 0) {
+ private->accel_fifo_state->samples_to_discard[id]--;
} else {
s = accel + id;
axis = s->raw_xyz;
@@ -453,7 +465,8 @@ void lsm6dsm_interrupt(enum gpio_signal signal)
/**
* irq_handler - bottom half of the interrupt stack
*/
-static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
+__maybe_unused static int irq_handler(
+ struct motion_sensor_t *s, uint32_t *event)
{
int ret = EC_SUCCESS;
@@ -493,7 +506,6 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
return ret;
}
-#endif /* CONFIG_ACCEL_INTERRUPTS */
/**
* set_range - set full scale range
@@ -630,9 +642,11 @@ int lsm6dsm_set_data_rate(const struct motion_sensor_t *s, int rate, int rnd)
if (ret == EC_SUCCESS) {
data->base.odr = normalized_rate;
if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
- private->samples_to_discard[s->type] =
+ struct lsm6dsm_accel_fifo_state *fifo_state =
+ private->accel_fifo_state;
+ fifo_state->samples_to_discard[s->type] =
LSM6DSM_DISCARD_SAMPLES;
- private->load_fifo_sensor_state[get_fifo_type(s)]
+ fifo_state->load_fifo_sensor_state[get_fifo_type(s)]
.sample_rate = normalized_rate == 0
? 0 : SECOND * 1000 / normalized_rate;
ret = fifo_enable(accel);
diff --git a/driver/accelgyro_lsm6dsm.h b/driver/accelgyro_lsm6dsm.h
index 3c4ba5d8bb..f63f6af4a0 100644
--- a/driver/accelgyro_lsm6dsm.h
+++ b/driver/accelgyro_lsm6dsm.h
@@ -299,6 +299,22 @@ struct load_fifo_sensor_state_t {
int sample_rate;
};
+/**
+ * Structure used to hold fifo state. This struct should only be used if
+ * CONFIG_ACCEL_FIFO is defined.
+ */
+struct lsm6dsm_accel_fifo_state {
+ struct lsm6dsm_fifo_data config;
+ struct lsm6dsm_fifo_data current;
+ int next_in_pattern;
+ /*
+ * After an ODR change, the sensor filters need settling time; discard
+ * initial samples with incorrect values
+ */
+ unsigned int samples_to_discard[FIFO_DEV_NUM];
+ struct load_fifo_sensor_state_t load_fifo_sensor_state[FIFO_DEV_NUM];
+};
+
/*
* lsm6dsm_data is used for accel gyro and the sensor connect to a LSM6DSM.
*
@@ -334,17 +350,7 @@ struct lsm6dsm_data {
/* BMM150 doesn't use st_mems_common; no stprivate_data */
struct stprivate_data st_data[2];
#endif
-#ifdef CONFIG_ACCEL_FIFO
- struct lsm6dsm_fifo_data config;
- struct lsm6dsm_fifo_data current;
- int next_in_patten;
- /*
- * After an ODR change, the sensor filters need settling time; discard
- * initial samples with incorrect values
- */
- unsigned int samples_to_discard[FIFO_DEV_NUM];
- struct load_fifo_sensor_state_t load_fifo_sensor_state[FIFO_DEV_NUM];
-#endif /* CONFIG_ACCEL_FIFO */
+ struct lsm6dsm_accel_fifo_state *accel_fifo_state;
#if defined(CONFIG_LSM6DSM_SEC_I2C) && defined(CONFIG_MAG_CALIBRATE)
union {
#ifdef CONFIG_MAG_LSM6DSM_BMM150
@@ -358,6 +364,17 @@ struct lsm6dsm_data {
#endif /* CONFIG_MAG_CALIBRATE */
};
+#ifdef CONFIG_ACCEL_FIFO
+#define LSM6DSM_ACCEL_FIFO_STATE (&((struct lsm6dsm_accel_fifo_state) {}))
+#else
+#define LSM6DSM_ACCEL_FIFO_STATE NULL
+#endif
+
+#define LSM6DSM_DATA \
+ ((struct lsm6dsm_data) { \
+ .accel_fifo_state = LSM6DSM_ACCEL_FIFO_STATE, \
+ })
+
/*
* Note: The specific number of samples to discard depends on the filters
* configured for the chip, as well as the ODR being set. For most of our