diff options
author | Ting Shen <phoenixshen@google.com> | 2021-12-23 17:20:46 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-12-24 07:30:28 +0000 |
commit | 6989ff9053eba44365859249a1376585462734bc (patch) | |
tree | 18413edbc0b412ba014b54faf1ba4bf8029c3da0 | |
parent | f2bef959f0a733b8c7d30e285d10c480ae9fad11 (diff) | |
download | chrome-ec-6989ff9053eba44365859249a1376585462734bc.tar.gz |
zephyr: add ICM42607 sensor
Implement the dts binding and driver for ICM42607 sensor.
BUG=b:211845298
TEST=`accelread 1` on krabby
BRANCH=none
Signed-off-by: Ting Shen <phoenixshen@google.com>
Change-Id: I469b1d5b1f5063691ffd3155040490ef3f43c34e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3354657
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
Commit-Queue: Ting Shen <phoenixshen@chromium.org>
Tested-by: Ting Shen <phoenixshen@chromium.org>
-rw-r--r-- | driver/accelgyro_icm42607.c | 21 | ||||
-rw-r--r-- | zephyr/CMakeLists.txt | 2 | ||||
-rw-r--r-- | zephyr/dts/bindings/motionsense/driver/cros-ec,icm42607-accel.yaml | 13 | ||||
-rw-r--r-- | zephyr/dts/bindings/motionsense/driver/cros-ec,icm42607-gyro.yaml | 13 | ||||
-rw-r--r-- | zephyr/dts/bindings/motionsense/driver/icm42607.yaml | 17 | ||||
-rw-r--r-- | zephyr/shim/src/motionsense_driver/icm42607-drvinfo.inc | 57 | ||||
-rw-r--r-- | zephyr/shim/src/motionsense_driver/sensor_drv_list.inc | 3 |
7 files changed, 126 insertions, 0 deletions
diff --git a/driver/accelgyro_icm42607.c b/driver/accelgyro_icm42607.c index ae831c5918..2a2c68bc17 100644 --- a/driver/accelgyro_icm42607.c +++ b/driver/accelgyro_icm42607.c @@ -26,6 +26,27 @@ #define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args) #define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args) +#if defined(CONFIG_ZEPHYR) && defined(CONFIG_ACCEL_INTERRUPTS) + +/* Get the motion sensor ID of the ICM42607 sensor that generates the interrupt. + * The interrupt is converted to the event and transferred to motion sense task + * that actually handles the interrupt. + * + * Here we use an alias (icm42607_int) to get the motion sensor ID. This alias + * MUST be defined for this driver to work. + * aliases { + * icm42607-int = &base_accel; + * }; + */ +#if DT_NODE_EXISTS(DT_ALIAS(icm42607_int)) +#define CONFIG_ACCELGYRO_ICM42607_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(SENSOR_ID(DT_ALIAS(icm42607_int))) +#else +#error Missing aliases/icm42607-int in device tree +#endif + +#endif /* defined(CONFIG_ZEPHYR) && defined(CONFIG_ACCEL_INTERRUPTS) */ + STATIC_IF(CONFIG_ACCEL_FIFO) volatile uint32_t last_interrupt_timestamp; static int icm_switch_on_mclk(const struct motion_sensor_t *s) diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 60a30d7352..13e98feff7 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -142,6 +142,8 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ACCELGYRO_ICM "${PLATFORM_EC}/driver/accelgyro_icm_common.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ACCELGYRO_ICM426XX "${PLATFORM_EC}/driver/accelgyro_icm426xx.c") +zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ACCELGYRO_ICM42607 + "${PLATFORM_EC}/driver/accelgyro_icm42607.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ACCEL_FIFO "${PLATFORM_EC}/common/motion_sense_fifo.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ADC_CMD diff --git a/zephyr/dts/bindings/motionsense/driver/cros-ec,icm42607-accel.yaml b/zephyr/dts/bindings/motionsense/driver/cros-ec,icm42607-accel.yaml new file mode 100644 index 0000000000..ba7fbb3878 --- /dev/null +++ b/zephyr/dts/bindings/motionsense/driver/cros-ec,icm42607-accel.yaml @@ -0,0 +1,13 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +description: motion sense sensor node for ICM42607 accel + +compatible: "cros-ec,icm42607-accel" + +include: icm42607.yaml + +properties: + default-range: + default: 4 diff --git a/zephyr/dts/bindings/motionsense/driver/cros-ec,icm42607-gyro.yaml b/zephyr/dts/bindings/motionsense/driver/cros-ec,icm42607-gyro.yaml new file mode 100644 index 0000000000..4707f33d6d --- /dev/null +++ b/zephyr/dts/bindings/motionsense/driver/cros-ec,icm42607-gyro.yaml @@ -0,0 +1,13 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +description: motion sense sensor node for ICM42607 gyro + +compatible: "cros-ec,icm42607-gyro" + +include: icm42607.yaml + +properties: + default-range: + default: 1000 diff --git a/zephyr/dts/bindings/motionsense/driver/icm42607.yaml b/zephyr/dts/bindings/motionsense/driver/icm42607.yaml new file mode 100644 index 0000000000..f47e7a2f97 --- /dev/null +++ b/zephyr/dts/bindings/motionsense/driver/icm42607.yaml @@ -0,0 +1,17 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# common fields for both ICM426xx accel and gyro + +# every motionsense sensor node should include motionsense-sensor-base.yaml +include: motionsense-sensor-base.yaml + +properties: + i2c-spi-addr-flags: + type: string + description: i2c address or SPI peripheral logic GPIO + enum: + - "ICM42607_ADDR0_FLAGS" + - "ICM42607_ADDR1_FLAGS" + default: "ICM42607_ADDR0_FLAGS" diff --git a/zephyr/shim/src/motionsense_driver/icm42607-drvinfo.inc b/zephyr/shim/src/motionsense_driver/icm42607-drvinfo.inc new file mode 100644 index 0000000000..e8199eaacf --- /dev/null +++ b/zephyr/shim/src/motionsense_driver/icm42607-drvinfo.inc @@ -0,0 +1,57 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "driver/accelgyro_icm_common.h" +#include "driver/accelgyro_icm42607.h" + +/* + * CREATE_SENSOR_DATA which is defined in motionsense_sensors.c is + * the helper to create sensor driver specific data. + * + * CREATE_SENSOR_DATA gets two arguments. One is the compatible + * property value specified in device tree and the other one is the macro + * that actually creates sensor driver specific data. The macro gets + * node id and the name to be used for the sensor driver data. + */ + +/* + * Create driver data. It can be shared among the entries in + * motion_sensors array which are using the same icm42607 driver. + */ +#define CREATE_SENSOR_DATA_ICM42607(id, drvdata_name) \ + static struct icm_drv_data_t drvdata_name; + +/* + * Create driver data for each icm42607 drvinfo instance in device tree. + * (compatible = "cros-ec,drvdata-icm42607") + */ +CREATE_SENSOR_DATA(cros_ec_drvdata_icm42607, CREATE_SENSOR_DATA_ICM42607) +/* + * CREATE_MOTION_SENSOR which is defined in motionsense_sensors.c is + * the macro to create an entry in motion_sensors array. + * The macro gets value of compatible property of + * the sensor in device tree and sensor specific values like chip ID, + * type of sensor, name of driver, default min/max frequency. + * Then using the values, it creates the corresponding motion_sense_t entry + * in motion_sensors array. + */ + +/* + * Here, we call CREATE_MOTION_SENSOR to create a motion_sensor_t entry + * for each icm42607 accel instance(compatible = "cros-ec,icm42607-accel") + * in device tree. + */ +CREATE_MOTION_SENSOR(cros_ec_icm42607_accel, MOTIONSENSE_CHIP_ICM42607, \ + MOTIONSENSE_TYPE_ACCEL, icm42607_drv, \ + ICM42607_ACCEL_MIN_FREQ, ICM42607_ACCEL_MAX_FREQ) + +/* + * Here, we call CREATE_MOTION_SENSOR to create a motion_sensor_t entry + * for each icm42607 gyro instance (compatible = "cros-ec,icm42607-gyro") + * in device tree. + */ +CREATE_MOTION_SENSOR(cros_ec_icm42607_gyro, MOTIONSENSE_CHIP_ICM42607, \ + MOTIONSENSE_TYPE_GYRO, icm42607_drv, \ + ICM42607_GYRO_MIN_FREQ, ICM42607_GYRO_MAX_FREQ) diff --git a/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc b/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc index 0062dccccd..d8319ff193 100644 --- a/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc +++ b/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc @@ -40,3 +40,6 @@ #ifdef CONFIG_PLATFORM_EC_ACCELGYRO_ICM426XX #include "icm426xx-drvinfo.inc" #endif +#ifdef CONFIG_PLATFORM_EC_ACCELGYRO_ICM42607 +#include "icm42607-drvinfo.inc" +#endif |