summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2019-07-15 14:10:11 -0600
committerCommit Bot <commit-bot@chromium.org>2019-09-03 20:36:04 +0000
commitdfbc632cd5b5a856086249253a98bc83d8942a29 (patch)
tree9f0359115a96ca0efe66905b5f6b1be644367430
parent083788ac19505f07bfe57a4d8b54a3b11b7554b3 (diff)
downloadchrome-ec-dfbc632cd5b5a856086249253a98bc83d8942a29.tar.gz
config: Refactor CONFIG_ACCEL_FIFO to enable use of IS_ENABLED
This change allows us to use the IS_ENABLED condition to replace the various ifdef guards around the CONFIG_ACCEL_FIFO BUG=b:137758297,chromium:981990 BRANCH=None TEST=buildall and CTS tests on Arcada Change-Id: I65d36bac19855e51c830a33e6f3812575e8d15d9 Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704164 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
-rw-r--r--baseboard/grunt/baseboard.h7
-rw-r--r--baseboard/hatch/baseboard.h6
-rw-r--r--baseboard/kukui/baseboard.h7
-rw-r--r--baseboard/octopus/baseboard.h6
-rw-r--r--baseboard/zork/baseboard.h7
-rw-r--r--board/arcada_ish/board.h8
-rw-r--r--board/atlas/board.h8
-rw-r--r--board/cheza/board.h8
-rw-r--r--board/coral/board.h7
-rw-r--r--board/eve/board.h7
-rw-r--r--board/flapjack/board.h11
-rw-r--r--board/nami/board.h7
-rw-r--r--board/nautilus/board.h7
-rw-r--r--board/nocturne/board.h7
-rw-r--r--board/poppy/board.h7
-rw-r--r--board/rainier/board.h7
-rw-r--r--board/rammus/board.h7
-rw-r--r--board/reef/board.h7
-rw-r--r--board/reef_mchp/board.h7
-rw-r--r--board/scarlet/board.h5
-rw-r--r--common/motion_sense.c151
-rw-r--r--common/motion_sense_fifo.c7
-rw-r--r--driver/accelgyro_bmi160.c84
-rw-r--r--driver/accelgyro_lsm6dsm.c90
-rw-r--r--driver/accelgyro_lsm6dso.c69
-rw-r--r--driver/als_si114x.c38
-rw-r--r--driver/als_tcs3400.c18
-rw-r--r--include/config.h13
-rw-r--r--include/motion_sense.h2
-rw-r--r--include/motion_sense_fifo.h7
30 files changed, 331 insertions, 291 deletions
diff --git a/baseboard/grunt/baseboard.h b/baseboard/grunt/baseboard.h
index 27d87091b2..e2fd994649 100644
--- a/baseboard/grunt/baseboard.h
+++ b/baseboard/grunt/baseboard.h
@@ -186,11 +186,12 @@
#define CONFIG_TEMP_SENSOR_SB_TSI
#ifndef VARIANT_GRUNT_NO_SENSORS
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is a power of 2. */
-#define CONFIG_ACCEL_FIFO 256
-
+#define CONFIG_ACCEL_FIFO_SIZE 256
/* Depends on how fast the AP boots and typical ODRs. */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#endif /* VARIANT_GRUNT_NO_SENSORS */
#define USB_PD_PORT_ANX74XX 0
diff --git a/baseboard/hatch/baseboard.h b/baseboard/hatch/baseboard.h
index dac40e9293..a7f352e736 100644
--- a/baseboard/hatch/baseboard.h
+++ b/baseboard/hatch/baseboard.h
@@ -72,10 +72,12 @@
/* I2C_PORT_ACCEL needs to be defined for i2c transactions */
#define I2C_PORT_ACCEL I2C_PORT_SENSOR
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 256
+#define CONFIG_ACCEL_FIFO_SIZE 256
/* Depends on how fast the AP boots and typical ODRs */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
/* Sensor console commands */
#define CONFIG_CMD_ACCELS
diff --git a/baseboard/kukui/baseboard.h b/baseboard/kukui/baseboard.h
index 317c51be51..b22b1cdf01 100644
--- a/baseboard/kukui/baseboard.h
+++ b/baseboard/kukui/baseboard.h
@@ -139,10 +139,11 @@
#define CONFIG_TABLET_MODE_SWITCH
#define GPIO_LID_OPEN GPIO_HALL_INT_L
-/* FIFO size is in power of 2. */
#ifndef VARIANT_KUKUI_NO_SENSORS
-#define CONFIG_ACCEL_FIFO 256
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO
+/* FIFO size is in power of 2. */
+#define CONFIG_ACCEL_FIFO_SIZE 256
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#endif /* VARIANT_KUKUI_NO_SENSORS */
/* USB PD config */
diff --git a/baseboard/octopus/baseboard.h b/baseboard/octopus/baseboard.h
index 32210a0ed1..a8e613b0e2 100644
--- a/baseboard/octopus/baseboard.h
+++ b/baseboard/octopus/baseboard.h
@@ -275,10 +275,12 @@
* and the lid sensor is polled real-time (in forced mode).
*/
#define CONFIG_ACCEL_INTERRUPTS
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* Power of 2 - Too large of a fifo causes too much timestamp jitter */
-#define CONFIG_ACCEL_FIFO 256
+#define CONFIG_ACCEL_FIFO_SIZE 256
/* Depends on how fast the AP boots and typical ODRs */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#endif /* VARIANT_OCTOPUS_NO_SENSORS */
/*
diff --git a/baseboard/zork/baseboard.h b/baseboard/zork/baseboard.h
index 362a8d2fc0..c7f706c2af 100644
--- a/baseboard/zork/baseboard.h
+++ b/baseboard/zork/baseboard.h
@@ -196,11 +196,12 @@
/* Thermal */
#define CONFIG_TEMP_SENSOR_SB_TSI
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is a power of 2. */
-#define CONFIG_ACCEL_FIFO 256
-
+#define CONFIG_ACCEL_FIFO_SIZE 256
/* Depends on how fast the AP boots and typical ODRs. */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#ifndef __ASSEMBLER__
diff --git a/board/arcada_ish/board.h b/board/arcada_ish/board.h
index 18bdf6258a..f036bfd301 100644
--- a/board/arcada_ish/board.h
+++ b/board/arcada_ish/board.h
@@ -34,8 +34,12 @@
#define CONFIG_MAG_CALIBRATE
#define CONFIG_ACCEL_INTERRUPTS
-#define CONFIG_ACCEL_FIFO 256
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
+/* FIFO size is a power of 2. */
+#define CONFIG_ACCEL_FIFO_SIZE 256
+/* Depends on how fast the AP boots and typical ODRs. */
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
/* Sensors without hardware FIFO are in forced mode */
#define CONFIG_ACCEL_FORCE_MODE_MASK (BIT(BASE_ACCEL) | BIT(LID_MAG))
diff --git a/board/atlas/board.h b/board/atlas/board.h
index 37d8c5afd1..2d35762b0f 100644
--- a/board/atlas/board.h
+++ b/board/atlas/board.h
@@ -114,8 +114,12 @@
#define CONFIG_ALS_OPT3001
#define ALS_COUNT 1
#define OPT3001_I2C_ADDR_FLAGS OPT3001_I2C_ADDR1_FLAGS
-#define CONFIG_ACCEL_FIFO 1024
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
+/* FIFO size is a power of 2. */
+#define CONFIG_ACCEL_FIFO_SIZE 1024
+/* Depends on how fast the AP boots and typical ODRs. */
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#define CONFIG_ACCEL_INTERRUPTS
/* USB */
diff --git a/board/cheza/board.h b/board/cheza/board.h
index 39adbcf500..b7c4131529 100644
--- a/board/cheza/board.h
+++ b/board/cheza/board.h
@@ -131,8 +131,12 @@
#define CONFIG_ACCEL_INTERRUPTS
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL)
-#define CONFIG_ACCEL_FIFO 512
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
+/* FIFO size is a power of 2. */
+#define CONFIG_ACCEL_FIFO_SIZE 256
+/* Depends on how fast the AP boots and typical ODRs. */
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#define CONFIG_CMD_ACCELS
#define CONFIG_CMD_ACCEL_INFO
#define CONFIG_ALS
diff --git a/board/coral/board.h b/board/coral/board.h
index 8a84cbb062..29afbd44ce 100644
--- a/board/coral/board.h
+++ b/board/coral/board.h
@@ -207,11 +207,12 @@
#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
#define CONFIG_DYNAMIC_MOTION_SENSOR_COUNT
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 512
-
+#define CONFIG_ACCEL_FIFO_SIZE 512
/* Depends on how fast the AP boots and typical ODRs */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#ifndef __ASSEMBLER__
diff --git a/board/eve/board.h b/board/eve/board.h
index 642db72eb3..ac4e80ce04 100644
--- a/board/eve/board.h
+++ b/board/eve/board.h
@@ -136,11 +136,12 @@
#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 512
-
+#define CONFIG_ACCEL_FIFO_SIZE 512
/* Depends on how fast the AP boots and typical ODRs */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
/* Enable double tap detection */
#define CONFIG_GESTURE_DETECTION
diff --git a/board/flapjack/board.h b/board/flapjack/board.h
index a7420a55eb..353f3a62b3 100644
--- a/board/flapjack/board.h
+++ b/board/flapjack/board.h
@@ -114,10 +114,17 @@
#define CONFIG_TABLET_MODE
#define CONFIG_TABLET_MODE_SWITCH
+/*
+ * Only include the sensor fifo in the RW section (since the motion task is only
+ * included there).
+ */
#ifdef SECTION_IS_RW
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 256
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_SIZE 256
+/* Depends on how fast the AP boots and typical ODRs. */
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#endif /* SECTION_IS_RW */
/* Wireless Power Charger Config */
diff --git a/board/nami/board.h b/board/nami/board.h
index 2a93975747..cfcc6b3d2e 100644
--- a/board/nami/board.h
+++ b/board/nami/board.h
@@ -148,11 +148,12 @@
/* KB backlight driver */
#define CONFIG_LED_DRIVER_LM3509
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 512
-
+#define CONFIG_ACCEL_FIFO_SIZE 512
/* Depends on how fast the AP boots and typical ODRs */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#define CONFIG_TABLET_MODE
#define CONFIG_TABLET_MODE_SWITCH
diff --git a/board/nautilus/board.h b/board/nautilus/board.h
index 30b21ef9f1..59f2b395ac 100644
--- a/board/nautilus/board.h
+++ b/board/nautilus/board.h
@@ -123,11 +123,12 @@
#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
#define CONFIG_LID_ANGLE_UPDATE
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 512
-
+#define CONFIG_ACCEL_FIFO_SIZE 512
/* Depends on how fast the AP boots and typical ODRs */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#undef CONFIG_UART_TX_BUF_SIZE
#define CONFIG_UART_TX_BUF_SIZE 2048
diff --git a/board/nocturne/board.h b/board/nocturne/board.h
index 3186090f20..f969a5f03d 100644
--- a/board/nocturne/board.h
+++ b/board/nocturne/board.h
@@ -94,9 +94,12 @@
#define ALS_COUNT 1
#define CONFIG_ALS_OPT3001
#define OPT3001_I2C_ADDR_FLAGS OPT3001_I2C_ADDR1_FLAGS
-#define CONFIG_ACCEL_FIFO 512 /* Must be a power of 2 */
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
+/* Must be a power of 2 */
+#define CONFIG_ACCEL_FIFO_SIZE 512
/* Depends on how fast the AP boots and typical ODRs */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#define CONFIG_ACCEL_INTERRUPTS
#define CONFIG_ACCELGYRO_BMI160
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
diff --git a/board/poppy/board.h b/board/poppy/board.h
index 36055bb1cc..104c77962a 100644
--- a/board/poppy/board.h
+++ b/board/poppy/board.h
@@ -133,11 +133,12 @@
/* Lower maximal ODR to 100Hz */
#define CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ 100000
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 512
-
+#define CONFIG_ACCEL_FIFO_SIZE 512
/* Depends on how fast the AP boots and typical ODRs */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#define CONFIG_TABLET_MODE
#define CONFIG_TABLET_MODE_SWITCH
diff --git a/board/rainier/board.h b/board/rainier/board.h
index 3827f97ea6..fe633e12b3 100644
--- a/board/rainier/board.h
+++ b/board/rainier/board.h
@@ -77,9 +77,12 @@
#define CONFIG_TABLET_MODE
#define CONFIG_TABLET_MODE_SWITCH
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 256
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_SIZE 256
+/* Depends on how fast the AP boots and typical ODRs. */
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
/* Sensors without hardware FIFO are in forced mode. */
#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_BARO)
diff --git a/board/rammus/board.h b/board/rammus/board.h
index da73f7acd4..1a8944e1ef 100644
--- a/board/rammus/board.h
+++ b/board/rammus/board.h
@@ -122,11 +122,12 @@
#undef CONFIG_SENSOR_TIGHT_TIMESTAMPS
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 512
-
+#define CONFIG_ACCEL_FIFO_SIZE 512
/* Depends on how fast the AP boots and typical ODRs */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#undef CONFIG_UART_TX_BUF_SIZE
#define CONFIG_UART_TX_BUF_SIZE 2048
diff --git a/board/reef/board.h b/board/reef/board.h
index d3493e347f..72f2818a23 100644
--- a/board/reef/board.h
+++ b/board/reef/board.h
@@ -206,11 +206,12 @@
#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 512
-
+#define CONFIG_ACCEL_FIFO_SIZE 512
/* Depends on how fast the AP boots and typical ODRs */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#ifndef __ASSEMBLER__
diff --git a/board/reef_mchp/board.h b/board/reef_mchp/board.h
index 3befb5bf05..348375e8da 100644
--- a/board/reef_mchp/board.h
+++ b/board/reef_mchp/board.h
@@ -213,11 +213,12 @@
#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 1024
-
+#define CONFIG_ACCEL_FIFO_SIZE 1024
/* Depends on how fast the AP boots and typical ODRs */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
#ifndef __ASSEMBLER__
diff --git a/board/scarlet/board.h b/board/scarlet/board.h
index 5187ac4eb8..901514f29f 100644
--- a/board/scarlet/board.h
+++ b/board/scarlet/board.h
@@ -99,8 +99,11 @@
#define CONFIG_TABLET_MODE
#define CONFIG_TABLET_MODE_SWITCH
+/* Enable sensor fifo, must also define the _SIZE and _THRES */
+#define CONFIG_ACCEL_FIFO
/* FIFO size is in power of 2. */
-#define CONFIG_ACCEL_FIFO 256
+#define CONFIG_ACCEL_FIFO_SIZE 256
+/* Depends on how fast the AP boots and typical ODRs. */
#define CONFIG_ACCEL_FIFO_THRES 10
/* USB PD config */
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 424da27011..650f2a7617 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -632,68 +632,68 @@ static int motion_sense_process(struct motion_sensor_t *sensor,
ret = sensor->drv->irq_handler(sensor, event);
}
#endif
-#ifdef CONFIG_ACCEL_FIFO
- if (motion_sensor_in_forced_mode(sensor)) {
- if (motion_sensor_time_to_read(ts, sensor)) {
- struct ec_response_motion_sensor_data vector;
- int *v = sensor->raw_xyz;
-
- ret = motion_sense_read(sensor);
- if (ret == EC_SUCCESS) {
- vector.flags = 0;
- vector.sensor_num = sensor - motion_sensors;
-#ifdef CONFIG_ACCEL_SPOOF_MODE
- if (sensor->flags &
- MOTIONSENSE_FLAG_IN_SPOOF_MODE)
- v = sensor->spoof_xyz;
-#endif /* defined(CONFIG_ACCEL_SPOOF_MODE) */
- vector.data[X] = v[X];
- vector.data[Y] = v[Y];
- vector.data[Z] = v[Z];
- motion_sense_fifo_stage_data(
- &vector, sensor, 3,
- __hw_clock_source_read());
- motion_sense_fifo_commit_data();
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ if (motion_sensor_in_forced_mode(sensor)) {
+ if (motion_sensor_time_to_read(ts, sensor)) {
+ struct ec_response_motion_sensor_data vector;
+ int *v = sensor->raw_xyz;
+
+ ret = motion_sense_read(sensor);
+ if (ret == EC_SUCCESS) {
+ vector.flags = 0;
+ vector.sensor_num = sensor -
+ motion_sensors;
+ if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE)
+ && sensor->flags &
+ MOTIONSENSE_FLAG_IN_SPOOF_MODE)
+ v = sensor->spoof_xyz;
+ vector.data[X] = v[X];
+ vector.data[Y] = v[Y];
+ vector.data[Z] = v[Z];
+ motion_sense_fifo_stage_data(
+ &vector, sensor, 3,
+ __hw_clock_source_read());
+ motion_sense_fifo_commit_data();
+ }
+ increment_sensor_collection(sensor, ts);
+ } else {
+ ret = EC_ERROR_BUSY;
}
- increment_sensor_collection(sensor, ts);
- } else {
- ret = EC_ERROR_BUSY;
}
- }
- if (*event & TASK_EVENT_MOTION_FLUSH_PENDING) {
- int flush_pending = atomic_read_clear(&sensor->flush_pending);
+ if (*event & TASK_EVENT_MOTION_FLUSH_PENDING) {
+ int flush_pending = atomic_read_clear(
+ &sensor->flush_pending);
- for (; flush_pending > 0; flush_pending--) {
- motion_sense_insert_async_event(sensor,
- ASYNC_EVENT_FLUSH);
- }
- }
-#else
- if (motion_sensor_in_forced_mode(sensor)) {
- if (motion_sensor_time_to_read(ts, sensor)) {
- /* Get latest data for local calculation */
- ret = motion_sense_read(sensor);
- increment_sensor_collection(sensor, ts);
- } else {
- ret = EC_ERROR_BUSY;
+ for (; flush_pending > 0; flush_pending--) {
+ motion_sense_insert_async_event(sensor,
+ ASYNC_EVENT_FLUSH);
+ }
}
- if (ret == EC_SUCCESS) {
- mutex_lock(&g_sensor_mutex);
- memcpy(sensor->xyz, sensor->raw_xyz,
- sizeof(sensor->xyz));
- mutex_unlock(&g_sensor_mutex);
+ } else {
+ if (motion_sensor_in_forced_mode(sensor)) {
+ if (motion_sensor_time_to_read(ts, sensor)) {
+ /* Get latest data for local calculation */
+ ret = motion_sense_read(sensor);
+ increment_sensor_collection(sensor, ts);
+ } else {
+ ret = EC_ERROR_BUSY;
+ }
+ if (ret == EC_SUCCESS) {
+ mutex_lock(&g_sensor_mutex);
+ memcpy(sensor->xyz, sensor->raw_xyz,
+ sizeof(sensor->xyz));
+ mutex_unlock(&g_sensor_mutex);
+ }
}
}
-#endif
/* ODR change was requested. */
if (is_odr_pending) {
motion_sense_set_data_rate(sensor);
motion_sense_set_motion_intervals();
-#ifdef CONFIG_ACCEL_FIFO
- motion_sense_insert_async_event(sensor,
- ASYNC_EVENT_ODR);
-#endif
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO))
+ motion_sense_insert_async_event(
+ sensor, ASYNC_EVENT_ODR);
}
return ret;
}
@@ -831,9 +831,7 @@ void motion_sense_task(void *u)
const uint16_t lid_angle_sensors = (BIT(CONFIG_LID_ANGLE_SENSOR_BASE)|
BIT(CONFIG_LID_ANGLE_SENSOR_LID));
#endif
-#ifdef CONFIG_ACCEL_FIFO
timestamp_t ts_last_int;
-#endif
#ifdef CONFIG_MOTION_FILL_LPC_SENSE_DATA
int sample_id = 0;
uint8_t *lpc_status;
@@ -842,9 +840,9 @@ void motion_sense_task(void *u)
set_present(lpc_status);
#endif
-#ifdef CONFIG_ACCEL_FIFO
- ts_last_int = get_time();
-#endif
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO))
+ ts_last_int = get_time();
+
while (1) {
ts_begin_task = get_time();
ready_status = 0;
@@ -897,20 +895,19 @@ void motion_sense_task(void *u)
update_sense_data(lpc_status, &sample_id);
#endif
-#ifdef CONFIG_ACCEL_FIFO
/*
* Ask the host to flush the queue if
* - a flush event has been queued.
* - the queue is almost full,
* - we haven't done it for a while.
*/
- if (wake_up_needed ||
- event & (TASK_EVENT_MOTION_ODR_CHANGE |
- TASK_EVENT_MOTION_FLUSH_PENDING) ||
- queue_space(&motion_sense_fifo) < CONFIG_ACCEL_FIFO_THRES ||
- (ap_event_interval > 0 &&
- time_after(ts_begin_task.le.lo,
- ts_last_int.le.lo + ap_event_interval))) {
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO) &&
+ (motion_sense_fifo_is_wake_up_needed() ||
+ event & (TASK_EVENT_MOTION_ODR_CHANGE |
+ TASK_EVENT_MOTION_FLUSH_PENDING) ||
+ (ap_event_interval > 0 &&
+ time_after(ts_begin_task.le.lo,
+ ts_last_int.le.lo + ap_event_interval)))) {
if ((event & TASK_EVENT_MOTION_FLUSH_PENDING) == 0) {
motion_sense_fifo_stage_timestamp(
__hw_clock_source_read());
@@ -937,9 +934,8 @@ void motion_sense_task(void *u)
mkbp_send_event(EC_MKBP_EVENT_SENSOR_FIFO);
wake_up_needed = 0;
}
-#endif
+#endif /* CONFIG_MKBP_EVENT */
}
-#endif
ts_end_task = get_time();
wait_us = -1;
@@ -1248,8 +1244,9 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
args->response_size = sizeof(out->perform_calib);
break;
-#ifdef CONFIG_ACCEL_FIFO
case MOTIONSENSE_CMD_FIFO_FLUSH:
+ if (!IS_ENABLED(CONFIG_ACCEL_FIFO))
+ return EC_RES_INVALID_PARAM;
sensor = host_sensor_id_to_real_sensor(
in->sensor_odr.sensor_num);
if (sensor == NULL)
@@ -1261,6 +1258,15 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
TASK_EVENT_MOTION_FLUSH_PENDING, 0);
/* pass-through */
case MOTIONSENSE_CMD_FIFO_INFO:
+ if (!IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ /*
+ * Only support the INFO command, to tell there is no
+ * FIFO.
+ */
+ memset(&out->fifo_info, 0, sizeof(out->fifo_info));
+ args->response_size = sizeof(out->fifo_info);
+ break;
+ }
motion_sense_get_fifo_info(&out->fifo_info);
for (i = 0; i < motion_sensor_count; i++) {
out->fifo_info.lost[i] = motion_sensors[i].lost;
@@ -1272,6 +1278,8 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
break;
case MOTIONSENSE_CMD_FIFO_READ:
+ if (!IS_ENABLED(CONFIG_ACCEL_FIFO))
+ return EC_RES_INVALID_PARAM;
mutex_lock(&g_sensor_mutex);
reported = MIN((args->response_max - sizeof(out->fifo_read)) /
motion_sense_fifo.unit_bytes,
@@ -1285,6 +1293,8 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
motion_sense_fifo.unit_bytes;
break;
case MOTIONSENSE_CMD_FIFO_INT_ENABLE:
+ if (!IS_ENABLED(CONFIG_ACCEL_FIFO))
+ return EC_RES_INVALID_PARAM;
switch (in->fifo_int_enable.enable) {
case 0:
case 1:
@@ -1298,13 +1308,6 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
return EC_RES_INVALID_PARAM;
}
break;
-#else
- case MOTIONSENSE_CMD_FIFO_INFO:
- /* Only support the INFO command, to tell there is no FIFO. */
- memset(&out->fifo_info, 0, sizeof(out->fifo_info));
- args->response_size = sizeof(out->fifo_info);
- break;
-#endif
#ifdef CONFIG_GESTURE_HOST_DETECTION
case MOTIONSENSE_CMD_LIST_ACTIVITIES: {
uint32_t enabled, disabled, mask, i;
diff --git a/common/motion_sense_fifo.c b/common/motion_sense_fifo.c
index 00c2f5a8cc..ec4c63b6de 100644
--- a/common/motion_sense_fifo.c
+++ b/common/motion_sense_fifo.c
@@ -26,7 +26,7 @@ int fifo_queue_count;
int fifo_int_enabled;
struct queue motion_sense_fifo = QUEUE_NULL(
- CONFIG_ACCEL_FIFO, struct ec_response_motion_sensor_data);
+ CONFIG_ACCEL_FIFO_SIZE, struct ec_response_motion_sensor_data);
int motion_sense_fifo_lost;
/**
@@ -401,3 +401,8 @@ static int motion_sense_get_next_event(uint8_t *out)
DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_SENSOR_FIFO, motion_sense_get_next_event);
+inline int motion_sense_fifo_is_wake_up_needed(void)
+{
+ return queue_space(&motion_sense_fifo) < CONFIG_ACCEL_FIFO_THRES ||
+ wake_up_needed;
+}
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c
index 6408bfcc79..aa4eaf13c7 100644
--- a/driver/accelgyro_bmi160.c
+++ b/driver/accelgyro_bmi160.c
@@ -27,9 +27,7 @@
#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args)
#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args)
-#ifdef CONFIG_ACCEL_FIFO
-static volatile uint32_t last_interrupt_timestamp;
-#endif
+STATIC_IF(CONFIG_ACCEL_FIFO) volatile uint32_t last_interrupt_timestamp;
/*
* Struct for pairing an engineering value with the register value for a
@@ -304,7 +302,6 @@ int bmi160_sec_raw_write8(const int port,
}
#endif
-#ifdef CONFIG_ACCEL_FIFO
static int enable_fifo(const struct motion_sensor_t *s, int enable)
{
struct bmi160_drv_data_t *data = BMI160_GET_DATA(s);
@@ -333,7 +330,6 @@ static int enable_fifo(const struct motion_sensor_t *s, int enable)
}
return ret;
}
-#endif
static int set_range(const struct motion_sensor_t *s,
int range,
@@ -386,10 +382,10 @@ static int set_data_rate(const struct motion_sensor_t *s,
#endif
if (rate == 0) {
-#ifdef CONFIG_ACCEL_FIFO
/* FIFO stop collecting events */
- enable_fifo(s, 0);
-#endif
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO))
+ enable_fifo(s, 0);
+
/* go to suspend mode */
ret = raw_write8(s->port, s->i2c_spi_addr_flags,
BMI160_CMD_REG,
@@ -473,13 +469,12 @@ static int set_data_rate(const struct motion_sensor_t *s,
}
#endif
-#ifdef CONFIG_ACCEL_FIFO
/*
* FIFO start collecting events.
* They will be discarded if AP does not want them.
*/
- enable_fifo(s, 1);
-#endif
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO))
+ enable_fifo(s, 1);
accel_cleanup:
mutex_unlock(s->mutex);
@@ -825,7 +820,6 @@ int list_activities(const struct motion_sensor_t *s,
#ifdef CONFIG_ACCEL_INTERRUPTS
-#ifdef CONFIG_ACCEL_FIFO
enum fifo_state {
FIFO_HEADER,
FIFO_DATA_SKIP,
@@ -873,10 +867,9 @@ static int bmi160_decode_header(struct motion_sensor_t *accel,
int *v = s->raw_xyz;
vector.flags = 0;
normalize(s, v, *bp);
-#ifdef CONFIG_ACCEL_SPOOF_MODE
- if (s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE)
+ if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) &&
+ s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE)
v = s->spoof_xyz;
-#endif /* defined(CONFIG_ACCEL_SPOOF_MODE) */
vector.data[X] = v[X];
vector.data[Y] = v[Y];
vector.data[Z] = v[Z];
@@ -1037,7 +1030,6 @@ static int load_fifo(struct motion_sensor_t *s, uint32_t last_ts)
motion_sense_fifo_commit_data();
return EC_SUCCESS;
}
-#endif /* CONFIG_ACCEL_FIFO */
/**
* bmi160_interrupt - called when the sensor activates the interrupt line.
@@ -1047,9 +1039,9 @@ static int load_fifo(struct motion_sensor_t *s, uint32_t last_ts)
*/
void bmi160_interrupt(enum gpio_signal signal)
{
-#ifdef CONFIG_ACCEL_FIFO
- last_interrupt_timestamp = __hw_clock_source_read();
-#endif
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO))
+ last_interrupt_timestamp = __hw_clock_source_read();
+
task_set_event(TASK_ID_MOTIONSENSE,
CONFIG_ACCELGYRO_BMI160_INT_EVENT, 0);
}
@@ -1119,34 +1111,37 @@ static int config_interrupt(const struct motion_sensor_t *s)
ret = raw_write8(s->port, s->i2c_spi_addr_flags,
BMI160_INT_MAP_REG(1), tmp);
-#ifdef CONFIG_ACCEL_FIFO
- /* map fifo water mark to int 1 */
- ret = raw_write8(s->port, s->i2c_spi_addr_flags,
- BMI160_INT_FIFO_MAP,
- BMI160_INT_MAP(1, FWM) |
- BMI160_INT_MAP(1, FFULL));
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ /* map fifo water mark to int 1 */
+ ret = raw_write8(s->port, s->i2c_spi_addr_flags,
+ BMI160_INT_FIFO_MAP,
+ BMI160_INT_MAP(1, FWM) |
+ BMI160_INT_MAP(1, FFULL));
- /* configure fifo watermark to int whenever there's any data in there */
- ret = raw_write8(s->port, s->i2c_spi_addr_flags,
- BMI160_FIFO_CONFIG_0, 1);
+ /*
+ * Configure fifo watermark to int whenever there's any data in
+ * there
+ */
+ ret = raw_write8(s->port, s->i2c_spi_addr_flags,
+ BMI160_FIFO_CONFIG_0, 1);
#ifdef CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT
- ret = raw_write8(s->port, s->i2c_spi_addr_flags,
- BMI160_FIFO_CONFIG_1,
- BMI160_FIFO_HEADER_EN);
+ ret = raw_write8(s->port, s->i2c_spi_addr_flags,
+ BMI160_FIFO_CONFIG_1,
+ BMI160_FIFO_HEADER_EN);
#else
- ret = raw_write8(s->port, s->i2c_spi_addr_flags,
- BMI160_FIFO_CONFIG_1,
- BMI160_FIFO_TAG_INT2_EN |
- BMI160_FIFO_HEADER_EN);
+ ret = raw_write8(s->port, s->i2c_spi_addr_flags,
+ BMI160_FIFO_CONFIG_1,
+ BMI160_FIFO_TAG_INT2_EN |
+ BMI160_FIFO_HEADER_EN);
#endif
- /* Set fifo*/
- ret = raw_read8(s->port, s->i2c_spi_addr_flags,
- BMI160_INT_EN_1, &tmp);
- tmp |= BMI160_INT_FWM_EN | BMI160_INT_FFUL_EN;
- ret = raw_write8(s->port, s->i2c_spi_addr_flags,
- BMI160_INT_EN_1, tmp);
-#endif
+ /* Set fifo*/
+ ret = raw_read8(s->port, s->i2c_spi_addr_flags,
+ BMI160_INT_EN_1, &tmp);
+ tmp |= BMI160_INT_FWM_EN | BMI160_INT_FFUL_EN;
+ ret = raw_write8(s->port, s->i2c_spi_addr_flags,
+ BMI160_INT_EN_1, tmp);
+ }
mutex_unlock(s->mutex);
return ret;
}
@@ -1222,10 +1217,9 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
*event |= TASK_EVENT_MOTION_ACTIVITY_INTERRUPT(
MOTIONSENSE_ACTIVITY_SIG_MOTION);
#endif
-#ifdef CONFIG_ACCEL_FIFO
- if (interrupt & (BMI160_FWM_INT | BMI160_FFULL_INT))
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO) &&
+ interrupt & (BMI160_FWM_INT | BMI160_FFULL_INT))
load_fifo(s, last_interrupt_timestamp);
-#endif
#ifdef CONFIG_BMI160_ORIENTATION_SENSOR
irq_set_orientation(s, interrupt);
#endif
diff --git a/driver/accelgyro_lsm6dsm.c b/driver/accelgyro_lsm6dsm.c
index 1a098f3b1e..4fc8591ee1 100644
--- a/driver/accelgyro_lsm6dsm.c
+++ b/driver/accelgyro_lsm6dsm.c
@@ -26,7 +26,6 @@
#define IS_FSTS_EMPTY(s) ((s).len & LSM6DSM_FIFO_EMPTY)
-#ifdef CONFIG_ACCEL_FIFO
static volatile uint32_t last_interrupt_timestamp;
/**
@@ -83,8 +82,6 @@ static inline uint8_t get_sensor_type(enum dev_fifo fifo_type)
return map[fifo_type];
}
-#endif
-
/**
* @return output base register for sensor
*/
@@ -112,23 +109,22 @@ static int config_interrupt(const struct motion_sensor_t *accel)
if (ret != EC_SUCCESS)
return ret;
-#ifdef CONFIG_ACCEL_FIFO
- /* As soon as one sample is ready, trigger an interrupt. */
- ret = st_raw_write8(accel->port, accel->i2c_spi_addr_flags,
- LSM6DSM_FIFO_CTRL1_ADDR,
- OUT_XYZ_SIZE / sizeof(uint16_t));
- if (ret != EC_SUCCESS)
- return ret;
- int1_ctrl_val |= LSM6DSM_INT_FIFO_TH | LSM6DSM_INT_FIFO_OVR |
- LSM6DSM_INT_FIFO_FULL;
-#endif /* CONFIG_ACCEL_FIFO */
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ /* As soon as one sample is ready, trigger an interrupt. */
+ ret = st_raw_write8(accel->port, accel->i2c_spi_addr_flags,
+ LSM6DSM_FIFO_CTRL1_ADDR,
+ OUT_XYZ_SIZE / sizeof(uint16_t));
+ if (ret != EC_SUCCESS)
+ return ret;
+ int1_ctrl_val |= LSM6DSM_INT_FIFO_TH | LSM6DSM_INT_FIFO_OVR |
+ LSM6DSM_INT_FIFO_FULL;
+ }
return st_raw_write8(accel->port, accel->i2c_spi_addr_flags,
LSM6DSM_INT1_CTRL, int1_ctrl_val);
}
-#ifdef CONFIG_ACCEL_FIFO
/**
* fifo_disable - set fifo mode
* @accel: Motion sensor pointer: must be MOTIONSENSE_TYPE_ACCEL.
@@ -437,14 +433,11 @@ static int is_fifo_empty(struct motion_sensor_t *s, struct fstatus *fsts)
return IS_FSTS_EMPTY(*fsts);
}
-#endif /* CONFIG_ACCEL_FIFO */
-
static void handle_interrupt_for_fifo(uint32_t ts)
{
-#ifdef CONFIG_ACCEL_FIFO
- if (time_after(ts, last_interrupt_timestamp))
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO) &&
+ time_after(ts, last_interrupt_timestamp))
last_interrupt_timestamp = ts;
-#endif
task_set_event(TASK_ID_MOTIONSENSE,
CONFIG_ACCEL_LSM6DSM_INT_EVENT, 0);
}
@@ -468,8 +461,7 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
(!(*event & CONFIG_ACCEL_LSM6DSM_INT_EVENT)))
return EC_ERROR_NOT_HANDLED;
-#ifdef CONFIG_ACCEL_FIFO
- {
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
struct fstatus fsts;
uint32_t last_fifo_read_ts;
uint32_t triggering_interrupt_timestamp =
@@ -498,7 +490,7 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
triggering_interrupt_timestamp == last_interrupt_timestamp)
handle_interrupt_for_fifo(last_fifo_read_ts);
}
-#endif
+
return ret;
}
#endif /* CONFIG_ACCEL_INTERRUPTS */
@@ -576,21 +568,22 @@ static int get_range(const struct motion_sensor_t *s)
int lsm6dsm_set_data_rate(const struct motion_sensor_t *s, int rate, int rnd)
{
struct stprivate_data *data = s->drv_data;
-#ifdef CONFIG_ACCEL_FIFO
- const struct motion_sensor_t *accel = LSM6DSM_MAIN_SENSOR(s);
- struct lsm6dsm_data *private = LSM6DSM_GET_DATA(accel);
-#endif
+ const struct motion_sensor_t *accel = IS_ENABLED(CONFIG_ACCEL_FIFO) ?
+ LSM6DSM_MAIN_SENSOR(s) : NULL;
+ struct lsm6dsm_data *private = IS_ENABLED(CONFIG_ACCEL_FIFO) ?
+ LSM6DSM_GET_DATA(accel) : NULL;
int ret = EC_SUCCESS, normalized_rate = 0;
uint8_t ctrl_reg, reg_val = 0;
-#ifdef CONFIG_ACCEL_FIFO
- /* FIFO must be disabled before setting any ODR values */
- ret = fifo_disable(accel);
- if (ret != EC_SUCCESS) {
- CPRINTS("Failed to disable FIFO. Error: %d", ret);
- return ret;
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ /* FIFO must be disabled before setting any ODR values */
+ ret = fifo_disable(accel);
+ if (ret != EC_SUCCESS) {
+ CPRINTS("Failed to disable FIFO. Error: %d", ret);
+ return ret;
+ }
}
-#endif
+
if (rate > 0) {
reg_val = LSM6DSM_ODR_TO_REG(rate);
normalized_rate = LSM6DSM_REG_TO_ODR(reg_val);
@@ -636,16 +629,17 @@ int lsm6dsm_set_data_rate(const struct motion_sensor_t *s, int rate, int rnd)
}
if (ret == EC_SUCCESS) {
data->base.odr = normalized_rate;
-#ifdef CONFIG_ACCEL_FIFO
- private->samples_to_discard[s->type] =
- LSM6DSM_DISCARD_SAMPLES;
- private->load_fifo_sensor_state[get_fifo_type(s)].sample_rate =
- normalized_rate == 0 ? 0 : SECOND * 1000 /
- normalized_rate;
- ret = fifo_enable(accel);
- if (ret != EC_SUCCESS)
- CPRINTS("Failed to enable FIFO. Error: %d", ret);
-#endif
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ private->samples_to_discard[s->type] =
+ LSM6DSM_DISCARD_SAMPLES;
+ private->load_fifo_sensor_state[get_fifo_type(s)]
+ .sample_rate = normalized_rate == 0
+ ? 0 : SECOND * 1000 / normalized_rate;
+ ret = fifo_enable(accel);
+ if (ret != EC_SUCCESS)
+ CPRINTS("Failed to enable FIFO. Error: %d",
+ ret);
+ }
}
mutex_unlock(s->mutex);
@@ -803,11 +797,11 @@ static int init(const struct motion_sensor_t *s)
if (ret != EC_SUCCESS)
goto err_unlock;
-#ifdef CONFIG_ACCEL_FIFO
- ret = fifo_disable(s);
- if (ret != EC_SUCCESS)
- goto err_unlock;
-#endif /* CONFIG_ACCEL_FIFO */
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ ret = fifo_disable(s);
+ if (ret != EC_SUCCESS)
+ goto err_unlock;
+ }
#ifdef CONFIG_ACCEL_INTERRUPTS
ret = config_interrupt(s);
diff --git a/driver/accelgyro_lsm6dso.c b/driver/accelgyro_lsm6dso.c
index c9ad09f740..617186872b 100644
--- a/driver/accelgyro_lsm6dso.c
+++ b/driver/accelgyro_lsm6dso.c
@@ -20,9 +20,7 @@
#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args)
-#ifdef CONFIG_ACCEL_FIFO
-static volatile uint32_t last_interrupt_timestamp;
-#endif /* CONFIG_ACCEL_FIFO */
+STATIC_IF(CONFIG_ACCEL_FIFO) volatile uint32_t last_interrupt_timestamp;
/*
* When ODR change, the sensor filters need settling time;
@@ -51,12 +49,13 @@ static inline int get_xyz_reg(enum motionsensor_type type)
static int config_interrupt(const struct motion_sensor_t *s)
{
int ret = EC_SUCCESS;
-
-#ifdef CONFIG_ACCEL_FIFO
int int1_ctrl_val;
- ret = st_raw_read8(s->port, s->i2c_spi_addr_flags,
- LSM6DSO_INT1_CTRL, &int1_ctrl_val);
+ if (!IS_ENABLED(CONFIG_ACCEL_FIFO))
+ return ret;
+
+ ret = st_raw_read8(s->port, s->i2c_spi_addr_flags, LSM6DSO_INT1_CTRL,
+ &int1_ctrl_val);
if (ret != EC_SUCCESS)
return ret;
@@ -64,8 +63,8 @@ static int config_interrupt(const struct motion_sensor_t *s)
* Configure FIFO threshold to 1 sample: interrupt on watermark
* will be generated every time a new data sample will be stored
* in FIFO. The interrupr on watermark is cleared only when the
- * number or samples still present in FIFO exceeds the configured
- * threshold.
+ * number or samples still present in FIFO exceeds the
+ * configured threshold.
*/
ret = st_raw_write8(s->port, s->i2c_spi_addr_flags,
LSM6DSO_FIFO_CTRL1_ADDR, 1);
@@ -75,14 +74,12 @@ static int config_interrupt(const struct motion_sensor_t *s)
int1_ctrl_val |= LSM6DSO_INT_FIFO_TH | LSM6DSO_INT_FIFO_OVR |
LSM6DSO_INT_FIFO_FULL;
- ret = st_raw_write8(s->port, s->i2c_spi_addr_flags,
- LSM6DSO_INT1_CTRL, int1_ctrl_val);
-#endif /* CONFIG_ACCEL_FIFO */
+ ret = st_raw_write8(s->port, s->i2c_spi_addr_flags, LSM6DSO_INT1_CTRL,
+ int1_ctrl_val);
return ret;
}
-#ifdef CONFIG_ACCEL_FIFO
/**
* fifo_disable - set fifo mode to LSM6DSO_FIFO_MODE_BYPASS_VAL
* @s: Motion sensor pointer: must be MOTIONSENSE_TYPE_ACCEL.
@@ -217,16 +214,14 @@ static int accelgyro_config_fifo(const struct motion_sensor_t *s)
return fifo_enable(s);
}
-#endif /* CONFIG_ACCEL_FIFO */
/**
* lsm6dso_interrupt - interrupt from int1 pin of sensor
*/
void lsm6dso_interrupt(enum gpio_signal signal)
{
-#ifdef CONFIG_ACCEL_FIFO
- last_interrupt_timestamp = __hw_clock_source_read();
-#endif /* CONFIG_ACCEL_FIFO */
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO))
+ last_interrupt_timestamp = __hw_clock_source_read();
task_set_event(TASK_ID_MOTIONSENSE,
CONFIG_ACCEL_LSM6DSO_INT_EVENT, 0);
@@ -245,21 +240,20 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
(!(*event & CONFIG_ACCEL_LSM6DSO_INT_EVENT)))
return EC_ERROR_NOT_HANDLED;
-#ifdef CONFIG_ACCEL_FIFO
- /* Read how many data patterns on FIFO to read. */
- ret = st_raw_read_n_noinc(s->port, s->i2c_spi_addr_flags,
- LSM6DSO_FIFO_STS1_ADDR,
- (uint8_t *)&fsts, sizeof(fsts));
- if (ret != EC_SUCCESS)
- return ret;
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ /* Read how many data patterns on FIFO to read. */
+ ret = st_raw_read_n_noinc(s->port, s->i2c_spi_addr_flags,
+ LSM6DSO_FIFO_STS1_ADDR,
+ (uint8_t *)&fsts, sizeof(fsts));
+ if (ret != EC_SUCCESS)
+ return ret;
- if (fsts.len & (LSM6DSO_FIFO_DATA_OVR | LSM6DSO_FIFO_FULL)) {
- CPRINTS("%s FIFO Overrun: %04x", s->name, fsts.len);
- }
+ if (fsts.len & (LSM6DSO_FIFO_DATA_OVR | LSM6DSO_FIFO_FULL))
+ CPRINTS("%s FIFO Overrun: %04x", s->name, fsts.len);
- if (fsts.len & LSM6DSO_FIFO_DIFF_MASK)
- ret = load_fifo(s, &fsts, last_interrupt_timestamp);
-#endif /* CONFIG_ACCEL_FIFO */
+ if (fsts.len & LSM6DSO_FIFO_DIFF_MASK)
+ ret = load_fifo(s, &fsts, last_interrupt_timestamp);
+ }
return ret;
}
@@ -355,9 +349,8 @@ static int set_data_rate(const struct motion_sensor_t *s, int rate, int rnd)
ret = st_write_data_with_mask(s, ctrl_reg, LSM6DSO_ODR_MASK, reg_val);
if (ret == EC_SUCCESS) {
data->base.odr = normalized_rate;
-#ifdef CONFIG_ACCEL_FIFO
- accelgyro_config_fifo(s);
-#endif /* CONFIG_ACCEL_FIFO */
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO))
+ accelgyro_config_fifo(s);
}
mutex_unlock(s->mutex);
@@ -465,11 +458,11 @@ static int init(const struct motion_sensor_t *s)
if (ret != EC_SUCCESS)
goto err_unlock;
-#ifdef CONFIG_ACCEL_FIFO
- ret = fifo_disable(s);
- if (ret != EC_SUCCESS)
- goto err_unlock;
-#endif /* CONFIG_ACCEL_FIFO */
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ ret = fifo_disable(s);
+ if (ret != EC_SUCCESS)
+ goto err_unlock;
+ }
#ifdef CONFIG_ACCEL_INTERRUPTS
ret = config_interrupt(s);
diff --git a/driver/als_si114x.c b/driver/als_si114x.c
index 4db3fcc9d7..35405bbea7 100644
--- a/driver/als_si114x.c
+++ b/driver/als_si114x.c
@@ -93,9 +93,6 @@ static int si114x_read_results(struct motion_sensor_t *s, int nb)
int i, ret, val;
struct si114x_drv_data_t *data = SI114X_GET_DATA(s);
struct si114x_typed_data_t *type_data = SI114X_GET_TYPED_DATA(s);
-#ifdef CONFIG_ACCEL_FIFO
- struct ec_response_motion_sensor_data vector;
-#endif
/* Read ALX result */
for (i = 0; i < nb; i++) {
@@ -147,23 +144,24 @@ static int si114x_read_results(struct motion_sensor_t *s, int nb)
if (i == nb)
return EC_ERROR_UNCHANGED;
-#ifdef CONFIG_ACCEL_FIFO
- vector.flags = 0;
- for (i = 0; i < nb; i++)
- vector.data[i] = s->raw_xyz[i];
- for (i = nb; i < 3; i++)
- vector.data[i] = 0;
- vector.sensor_num = s - motion_sensors;
- motion_sense_fifo_stage_data(&vector, s, nb,
- __hw_clock_source_read());
- motion_sense_fifo_commit_data();
- /*
- * TODO: get time at a more accurate spot.
- * Like in si114x_interrupt
- */
-#else
- /* We need to copy raw_xyz into xyz with mutex */
-#endif
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ struct ec_response_motion_sensor_data vector;
+
+ vector.flags = 0;
+ for (i = 0; i < nb; i++)
+ vector.data[i] = s->raw_xyz[i];
+ for (i = nb; i < 3; i++)
+ vector.data[i] = 0;
+ vector.sensor_num = s - motion_sensors;
+ motion_sense_fifo_stage_data(&vector, s, nb,
+ __hw_clock_source_read());
+ motion_sense_fifo_commit_data();
+ /*
+ * TODO: get time at a more accurate spot.
+ * Like in si114x_interrupt
+ */
+ }
+ /* Otherwise, we need to copy raw_xyz into xyz with mutex */
return EC_SUCCESS;
}
diff --git a/driver/als_tcs3400.c b/driver/als_tcs3400.c
index 774efd863c..7e867a606d 100644
--- a/driver/als_tcs3400.c
+++ b/driver/als_tcs3400.c
@@ -18,9 +18,7 @@
#define CPRINTS(fmt, args...) cprints(CC_ACCEL, "%s "fmt, __func__, ## args)
-#ifdef CONFIG_ACCEL_FIFO
-static volatile uint32_t last_interrupt_timestamp;
-#endif
+STATIC_IF(CONFIG_ACCEL_FIFO) volatile uint32_t last_interrupt_timestamp;
#ifdef CONFIG_TCS_USE_LUX_TABLE
/*
@@ -423,10 +421,10 @@ static int tcs3400_post_events(struct motion_sensor_t *s, uint32_t last_ts)
}
#endif /* CONFIG_ACCEL_SPOOF_MODE */
-#ifdef CONFIG_ACCEL_FIFO
- vector.sensor_num = s - motion_sensors;
- motion_sense_fifo_stage_data(&vector, s, 3, last_ts);
-#endif
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ vector.sensor_num = s - motion_sensors;
+ motion_sense_fifo_stage_data(&vector, s, 3, last_ts);
+ }
}
/*
@@ -476,9 +474,9 @@ static int tcs3400_post_events(struct motion_sensor_t *s, uint32_t last_ts)
void tcs3400_interrupt(enum gpio_signal signal)
{
-#ifdef CONFIG_ACCEL_FIFO
- last_interrupt_timestamp = __hw_clock_source_read();
-#endif
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO))
+ last_interrupt_timestamp = __hw_clock_source_read();
+
task_set_event(TASK_ID_MOTIONSENSE,
CONFIG_ALS_TCS3400_INT_EVENT, 0);
}
diff --git a/include/config.h b/include/config.h
index a31ba2ba81..ff91073ea5 100644
--- a/include/config.h
+++ b/include/config.h
@@ -44,12 +44,12 @@
* BOARD_*, CHIP_*, and CHIP_FAMILY_*.
*/
-/*
- * Add support for sensor FIFO:
- * define the size of the global fifo, must be a power of 2.
- */
+/* Add support for sensor FIFO */
#undef CONFIG_ACCEL_FIFO
+/* Define the size of the global fifo, must be a power of 2. */
+#undef CONFIG_ACCEL_FIFO_SIZE
+
/* The amount of free entries that trigger an interrupt to the AP. */
#undef CONFIG_ACCEL_FIFO_THRES
@@ -4880,5 +4880,10 @@
#endif
+#ifdef CONFIG_ACCEL_FIFO
+#if !defined(CONFIG_ACCEL_FIFO_SIZE) || !defined(CONFIG_ACCEL_FIFO_THRES)
+#error "Using CONFIG_ACCEL_FIFO, must define _SIZE and _THRES"
+#endif
+#endif /* CONFIG_ACCEL_FIFO */
#endif /* __CROS_EC_CONFIG_H */
diff --git a/include/motion_sense.h b/include/motion_sense.h
index b0e5244e3b..8e0ade7492 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -76,7 +76,7 @@ enum sensor_config {
#define BASE_RANGE(_range) ((_range) & ~ROUND_UP_FLAG)
#ifdef CONFIG_ACCEL_FIFO
-#define MAX_FIFO_EVENT_COUNT CONFIG_ACCEL_FIFO
+#define MAX_FIFO_EVENT_COUNT CONFIG_ACCEL_FIFO_SIZE
#else
#define MAX_FIFO_EVENT_COUNT 0
#endif
diff --git a/include/motion_sense_fifo.h b/include/motion_sense_fifo.h
index f0d5f853dd..6b306b5f29 100644
--- a/include/motion_sense_fifo.h
+++ b/include/motion_sense_fifo.h
@@ -67,4 +67,11 @@ void motion_sense_fifo_stage_timestamp(uint32_t timestamp);
void motion_sense_get_fifo_info(
struct ec_response_motion_sense_fifo_info *fifo_info);
+/**
+ * Checks if either the AP should be woken up due to the fifo.
+ *
+ * @return 1 if the AP should be woken up, 0 otherwise.
+ */
+int motion_sense_fifo_is_wake_up_needed(void);
+
#endif /* __CROS_EC_MOTION_SENSE_FIFO_H */