summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2022-04-26 09:15:27 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-05-23 16:44:43 +0000
commit85b9afeb4d572adf9aae9db42b450582de1fd50d (patch)
treec95f8a0ea9882efa478a59d4638ce08820cf245d /driver
parent23a15646ceb5c00ce3279565f33ee80af049a608 (diff)
downloadchrome-ec-85b9afeb4d572adf9aae9db42b450582de1fd50d.tar.gz
bmix60: Use CONFIG_<driver>_INT_ENABLE
Use CONFIG_<driver>_INT_ENABLE to not include interrupt() and irq_handler() when hardware interrupt are not used. Disable call to motion_sense_fifo() with IS_ENABLED(CONFIG_ACCEL_FIFO). Other use of CONFIG_ACCEL_FIFO are removed: only when a hardware interrupt is configured we enable the sensor FIFO. Otherwise we directly read into the sensor data registers. BUG=b:230401133 BRANCH=asurada,dedede,brya TEST=Build all. Check Zephyr with herobrine. Check on bugzzy. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Change-Id: Ie33ad8dd34b5723ce9da4029effdae0755d81c03 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3609354 Reviewed-by: Yuval Peress <peress@google.com>
Diffstat (limited to 'driver')
-rw-r--r--driver/accelgyro_bmi160.c27
-rw-r--r--driver/accelgyro_bmi260.c111
-rw-r--r--driver/accelgyro_bmi_common.c22
3 files changed, 85 insertions, 75 deletions
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c
index 08bd7a0445..184e20c9f5 100644
--- a/driver/accelgyro_bmi160.c
+++ b/driver/accelgyro_bmi160.c
@@ -28,11 +28,16 @@
#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args)
#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args)
+#ifdef CONFIG_ACCELGYRO_BMI160_INT_EVENT
+#define ACCELGYRO_BMI160_INT_ENABLE
+#endif
+
STATIC_IF(CONFIG_BMI_ORIENTATION_SENSOR) void irq_set_orientation(
struct motion_sensor_t *s,
int interrupt);
-STATIC_IF(CONFIG_ACCEL_FIFO) volatile uint32_t last_interrupt_timestamp;
+STATIC_IF(ACCELGYRO_BMI160_INT_ENABLE)
+ volatile uint32_t last_interrupt_timestamp;
static int wakeup_time[] = {
[MOTIONSENSE_TYPE_ACCEL] = 4,
@@ -106,7 +111,7 @@ static int set_data_rate(const struct motion_sensor_t *s,
if (rate == 0) {
/* FIFO stop collecting events */
- if (IS_ENABLED(CONFIG_ACCEL_FIFO))
+ if (IS_ENABLED(ACCELGYRO_BMI160_INT_ENABLE))
bmi_enable_fifo(s, 0);
/* go to suspend mode */
@@ -170,7 +175,7 @@ static int set_data_rate(const struct motion_sensor_t *s,
* FIFO start collecting events.
* They will be discarded if AP does not want them.
*/
- if (IS_ENABLED(CONFIG_ACCEL_FIFO))
+ if (IS_ENABLED(ACCELGYRO_BMI160_INT_ENABLE))
bmi_enable_fifo(s, 1);
accel_cleanup:
@@ -437,7 +442,7 @@ config_accel_interrupt(const struct motion_sensor_t *s)
ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
BMI160_INT_MAP_REG(1), tmp);
- if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ if (IS_ENABLED(ACCELGYRO_BMI160_INT_ENABLE)) {
/* map fifo water mark to int 1 */
ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
BMI160_INT_FIFO_MAP,
@@ -468,7 +473,7 @@ config_accel_interrupt(const struct motion_sensor_t *s)
return ret;
}
-#ifdef CONFIG_ACCEL_INTERRUPTS
+#ifdef ACCELGYRO_BMI160_INT_ENABLE
#ifdef CONFIG_BMI_ORIENTATION_SENSOR
static void irq_set_orientation(struct motion_sensor_t *s,
int interrupt)
@@ -514,8 +519,7 @@ static void irq_set_orientation(struct motion_sensor_t *s,
*/
void bmi160_interrupt(enum gpio_signal signal)
{
- if (IS_ENABLED(CONFIG_ACCEL_FIFO))
- last_interrupt_timestamp = __hw_clock_source_read();
+ last_interrupt_timestamp = __hw_clock_source_read();
task_set_event(TASK_ID_MOTIONSENSE, CONFIG_ACCELGYRO_BMI160_INT_EVENT);
}
@@ -555,8 +559,7 @@ static int irq_handler(struct motion_sensor_t *s,
(interrupt & BMI160_SIGMOT_INT))
*event |= TASK_EVENT_MOTION_ACTIVITY_INTERRUPT(
MOTIONSENSE_ACTIVITY_SIG_MOTION);
- if (IS_ENABLED(CONFIG_ACCEL_FIFO) &&
- (interrupt & (BMI160_FWM_INT | BMI160_FFULL_INT))) {
+ if (interrupt & (BMI160_FWM_INT | BMI160_FFULL_INT)) {
bmi_load_fifo(s, last_interrupt_timestamp);
has_read_fifo = 1;
}
@@ -569,7 +572,7 @@ static int irq_handler(struct motion_sensor_t *s,
return EC_SUCCESS;
}
-#endif /* CONFIG_ACCEL_INTERRUPTS */
+#endif /* ACCELGYRO_BMI160_INT_ENABLE */
static int init(struct motion_sensor_t *s)
{
@@ -715,7 +718,7 @@ static int init(struct motion_sensor_t *s)
*/
saved_data->odr = 0;
- if (IS_ENABLED(CONFIG_ACCEL_INTERRUPTS) &&
+ if (IS_ENABLED(ACCELGYRO_BMI160_INT_ENABLE) &&
(s->type == MOTIONSENSE_TYPE_ACCEL))
ret = config_accel_interrupt(s);
@@ -735,7 +738,7 @@ const struct accelgyro_drv bmi160_drv = {
.get_offset = bmi_get_offset,
.perform_calib = perform_calib,
.read_temp = bmi_read_temp,
-#ifdef CONFIG_ACCEL_INTERRUPTS
+#ifdef ACCELGYRO_BMI160_INT_ENABLE
.irq_handler = irq_handler,
#endif
#ifdef CONFIG_GESTURE_HOST_DETECTION
diff --git a/driver/accelgyro_bmi260.c b/driver/accelgyro_bmi260.c
index daddf9fac5..cf2b019cb2 100644
--- a/driver/accelgyro_bmi260.c
+++ b/driver/accelgyro_bmi260.c
@@ -23,6 +23,11 @@
#include "util.h"
#include "watchdog.h"
+
+#ifdef CONFIG_ACCELGYRO_BMI260_INT_EVENT
+#define ACCELGYRO_BMI260_INT_ENABLE
+#endif
+
/* BMI220/BMI260 firmware binary */
#if defined(CONFIG_ACCELGYRO_BMI220)
#include "bmi220/accelgyro_bmi220_config_tbin.h"
@@ -37,7 +42,8 @@
#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args)
#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args)
-STATIC_IF(CONFIG_ACCEL_FIFO) volatile uint32_t last_interrupt_timestamp;
+STATIC_IF(ACCELGYRO_BMI260_INT_ENABLE)
+ volatile uint32_t last_interrupt_timestamp;
/*
* The gyro start-up time is 45ms in normal mode
@@ -84,7 +90,7 @@ static int set_data_rate(const struct motion_sensor_t *s,
if (rate == 0) {
/* FIFO stop collecting events */
- if (IS_ENABLED(CONFIG_ACCEL_FIFO))
+ if (IS_ENABLED(ACCELGYRO_BMI260_INT_ENABLE))
bmi_enable_fifo(s, 0);
/* disable sensor */
ret = enable_sensor(s, 0);
@@ -123,7 +129,7 @@ static int set_data_rate(const struct motion_sensor_t *s,
* FIFO start collecting events.
* They will be discarded if AP does not want them.
*/
- if (IS_ENABLED(CONFIG_ACCEL_FIFO))
+ if (IS_ENABLED(ACCELGYRO_BMI260_INT_ENABLE))
bmi_enable_fifo(s, 1);
accel_cleanup:
mutex_unlock(s->mutex);
@@ -279,29 +285,13 @@ end_perform_calib:
return ret;
}
-#ifdef CONFIG_ACCEL_INTERRUPTS
-
-/**
- * bmi260_interrupt - called when the sensor activates the interrupt line.
- *
- * This is a "top half" interrupt handler, it just asks motion sense ask
- * to schedule the "bottom half", ->irq_handler().
- */
-void bmi260_interrupt(enum gpio_signal signal)
-{
- if (IS_ENABLED(CONFIG_ACCEL_FIFO))
- last_interrupt_timestamp = __hw_clock_source_read();
-
- task_set_event(TASK_ID_MOTIONSENSE, CONFIG_ACCELGYRO_BMI260_INT_EVENT);
-}
-
/**
* config_interrupt - sets up the interrupt request output pin on the BMI260
*
* Note: this function only supports motion_sensor_t structs of type
* MOTIONSENSE_TYPE_ACCEL and expects the caller to verify this.
*/
-static int config_interrupt(const struct motion_sensor_t *s)
+static __maybe_unused int config_interrupt(const struct motion_sensor_t *s)
{
int ret;
@@ -317,47 +307,59 @@ static int config_interrupt(const struct motion_sensor_t *s)
/* TODO(chingkang): Test it if we want int2 as an interrupt */
/* configure int2 as an interrupt */
ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
- BMI260_INT2_IO_CTRL,
- BMI260_INT2_OUTPUT_EN);
+ BMI260_INT2_IO_CTRL,
+ BMI260_INT2_OUTPUT_EN);
else
/* configure int2 as an external input. */
ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
- BMI260_INT2_IO_CTRL,
- BMI260_INT2_INPUT_EN);
+ BMI260_INT2_IO_CTRL,
+ BMI260_INT2_INPUT_EN);
- if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
- /* map fifo water mark to int 1 */
- ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
- BMI260_INT_MAP_DATA,
- BMI260_INT_MAP_DATA_REG(1, FWM) |
- BMI260_INT_MAP_DATA_REG(1, FFULL));
+ /* map fifo water mark to int 1 */
+ ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
+ BMI260_INT_MAP_DATA,
+ BMI260_INT_MAP_DATA_REG(1, FWM) |
+ BMI260_INT_MAP_DATA_REG(1, FFULL));
- /*
- * Configure fifo watermark to int whenever there's any data in
- * there
- */
- ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
- BMI260_FIFO_WTM_0, 1);
+ /*
+ * Configure fifo watermark to int whenever there's any data in
+ * there
+ */
+ ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
+ BMI260_FIFO_WTM_0, 1);
+ ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
+ BMI260_FIFO_WTM_1, 0);
+ if (IS_ENABLED(CONFIG_ACCELGYRO_BMI260_INT2_OUTPUT))
ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
- BMI260_FIFO_WTM_1, 0);
- if (IS_ENABLED(CONFIG_ACCELGYRO_BMI260_INT2_OUTPUT))
- ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
- BMI260_FIFO_CONFIG_1,
- BMI260_FIFO_HEADER_EN);
- else
- ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
- BMI260_FIFO_CONFIG_1,
- (BMI260_FIFO_TAG_INT_LEVEL <<
- BMI260_FIFO_TAG_INT2_EN_OFFSET) |
- BMI260_FIFO_HEADER_EN);
- /* disable FIFO sensortime frame */
+ BMI260_FIFO_CONFIG_1,
+ BMI260_FIFO_HEADER_EN);
+ else
ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
- BMI260_FIFO_CONFIG_0, 0);
- }
+ BMI260_FIFO_CONFIG_1,
+ (BMI260_FIFO_TAG_INT_LEVEL <<
+ BMI260_FIFO_TAG_INT2_EN_OFFSET) |
+ BMI260_FIFO_HEADER_EN);
+ /* disable FIFO sensortime frame */
+ ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
+ BMI260_FIFO_CONFIG_0, 0);
mutex_unlock(s->mutex);
return ret;
}
+#ifdef ACCELGYRO_BMI260_INT_ENABLE
+/**
+ * bmi260_interrupt - called when the sensor activates the interrupt line.
+ *
+ * This is a "top half" interrupt handler, it just asks motion sense ask
+ * to schedule the "bottom half", ->irq_handler().
+ */
+void bmi260_interrupt(enum gpio_signal signal)
+{
+ last_interrupt_timestamp = __hw_clock_source_read();
+
+ task_set_event(TASK_ID_MOTIONSENSE, CONFIG_ACCELGYRO_BMI260_INT_EVENT);
+}
+
/**
* irq_handler - bottom half of the interrupt stack.
* Ran from the motion_sense task, finds the events that raised the interrupt.
@@ -385,8 +387,7 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
if (rv)
return rv;
- if (IS_ENABLED(CONFIG_ACCEL_FIFO) &&
- interrupt & (BMI260_FWM_INT | BMI260_FFULL_INT)) {
+ if (interrupt & (BMI260_FWM_INT | BMI260_FFULL_INT)) {
bmi_load_fifo(s, last_interrupt_timestamp);
has_read_fifo = 1;
}
@@ -397,7 +398,7 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
return EC_SUCCESS;
}
-#endif /* CONFIG_ACCEL_INTERRUPTS */
+#endif /* ACCELGYRO_BMI260_INT_ENABLE */
/*
* If the .init_rom section is not memory mapped, we need a static
@@ -590,7 +591,7 @@ static int init(struct motion_sensor_t *s)
*/
saved_data->odr = 0;
- if (IS_ENABLED(CONFIG_ACCEL_INTERRUPTS) &&
+ if (IS_ENABLED(ACCELGYRO_BMI260_INT_ENABLE) &&
(s->type == MOTIONSENSE_TYPE_ACCEL))
ret = config_interrupt(s);
@@ -610,7 +611,7 @@ const struct accelgyro_drv bmi260_drv = {
.get_offset = bmi_get_offset,
.perform_calib = perform_calib,
.read_temp = bmi_read_temp,
-#ifdef CONFIG_ACCEL_INTERRUPTS
+#ifdef ACCELGYRO_BMI260_INT_ENABLE
.irq_handler = irq_handler,
#endif
#ifdef CONFIG_GESTURE_HOST_DETECTION
diff --git a/driver/accelgyro_bmi_common.c b/driver/accelgyro_bmi_common.c
index 4086e3ba2a..210cfd37ce 100644
--- a/driver/accelgyro_bmi_common.c
+++ b/driver/accelgyro_bmi_common.c
@@ -374,20 +374,26 @@ int bmi_decode_header(struct motion_sensor_t *accel, enum fifo_header hdr,
struct motion_sensor_t *s = accel + i;
if (hdr & (1 << (i + BMI_FH_PARM_OFFSET))) {
- struct ec_response_motion_sensor_data vector;
int *v = s->raw_xyz;
- vector.flags = 0;
bmi_normalize(s, v, *bp);
if (IS_ENABLED(CONFIG_ACCEL_SPOOF_MODE) &&
s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE)
v = s->spoof_xyz;
- vector.data[X] = v[X];
- vector.data[Y] = v[Y];
- vector.data[Z] = v[Z];
- vector.sensor_num = s - motion_sensors;
- motion_sense_fifo_stage_data(&vector, s, 3,
- last_ts);
+ if (IS_ENABLED(CONFIG_ACCEL_FIFO)) {
+ struct ec_response_motion_sensor_data vector;
+
+ vector.flags = 0;
+ vector.data[X] = v[X];
+ vector.data[Y] = v[Y];
+ vector.data[Z] = v[Z];
+ vector.sensor_num = s - motion_sensors;
+ motion_sense_fifo_stage_data(&vector, s,
+ 3,
+ last_ts);
+ } else {
+ motion_sense_push_raw_xyz(s);
+ }
*bp += (i == MOTIONSENSE_TYPE_MAG ? 8 : 6);
}
}