summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoramber.chen <amber.chen@lcfc.corp-partner.google.com>2022-08-31 17:57:32 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-19 03:36:10 +0000
commitb434bfc2dbaf86d5bf4c922da800b5ea9fb3a6b5 (patch)
tree4a900f1f5844f9c5bbe001635e3bf6b55155b284
parent447b7da4a27bd54c3bc36819ac60018e4c18f829 (diff)
downloadchrome-ec-b434bfc2dbaf86d5bf4c922da800b5ea9fb3a6b5.tar.gz
zephyr: add initial shim for lsm6dsm sensor
Add initial shim for the lsm6dsm accel/gryo sensor BUG=none BRANCH=none TEST=zmake build pujjo Signed-off-by: amber.chen <amber.chen@lcfc.corp-partner.google.com> Change-Id: Ib1ab863bedd2575dfafcbfc1c49c54afe46a7c2c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3865215 Reviewed-by: Andrew McRae <amcrae@google.com> Commit-Queue: Andrew McRae <amcrae@google.com> Code-Coverage: Andrew McRae <amcrae@google.com> Tested-by: Andrew McRae <amcrae@google.com> Reviewed-by: Peter Marheine <pmarheine@chromium.org>
-rw-r--r--driver/accelgyro_lsm6dsm.h17
-rw-r--r--util/config_allowed.txt1
-rw-r--r--zephyr/CMakeLists.txt2
-rw-r--r--zephyr/Kconfig.sensor_devices7
-rw-r--r--zephyr/dts/bindings/motionsense/driver/cros-ec,lsm6dsm-accel.yaml13
-rw-r--r--zephyr/dts/bindings/motionsense/driver/cros-ec,lsm6dsm-gyro.yaml13
-rw-r--r--zephyr/dts/bindings/motionsense/driver/lsm6dsm.yaml19
-rw-r--r--zephyr/dts/bindings/motionsense/drvdata/cros-ec,drvdata-lsm6dsm.yaml21
-rw-r--r--zephyr/shim/include/config_chip.h5
-rw-r--r--zephyr/shim/src/motionsense_driver/lsm6dsm-drvinfo.inc57
-rw-r--r--zephyr/shim/src/motionsense_driver/sensor_drv_list.inc3
11 files changed, 157 insertions, 1 deletions
diff --git a/driver/accelgyro_lsm6dsm.h b/driver/accelgyro_lsm6dsm.h
index a1d591bcc0..51da2a42fb 100644
--- a/driver/accelgyro_lsm6dsm.h
+++ b/driver/accelgyro_lsm6dsm.h
@@ -386,4 +386,21 @@ struct lsm6dsm_data {
int lsm6dsm_set_data_rate(const struct motion_sensor_t *s, int rate, int rnd);
+#if defined(CONFIG_ZEPHYR)
+/* Get the motion sensor ID of the LSM6DSM 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 (lsm6dsm_int) to get the motion sensor ID. This alias
+ * MUST be defined for this driver to work.
+ * aliases {
+ * lsm6dsm-int = &lid_accel;
+ * };
+ */
+#if DT_NODE_EXISTS(DT_ALIAS(lsm6dsm_int))
+#define CONFIG_ACCEL_LSM6DSM_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(SENSOR_ID(DT_ALIAS(lsm6dsm_int)))
+#endif
+#endif
+
#endif /* __CROS_EC_ACCELGYRO_LSM6DSM_H */
diff --git a/util/config_allowed.txt b/util/config_allowed.txt
index 53bed47dcc..7a8e3ffbba 100644
--- a/util/config_allowed.txt
+++ b/util/config_allowed.txt
@@ -10,7 +10,6 @@ CONFIG_ACCELGYRO_ICM42607_INT_EVENT
CONFIG_ACCELGYRO_ICM426XX_INT_EVENT
CONFIG_ACCELGYRO_ICM_I2C
CONFIG_ACCELGYRO_LSM6DS0
-CONFIG_ACCELGYRO_LSM6DSM
CONFIG_ACCELGYRO_SEC_ADDR_FLAGS
CONFIG_ACCEL_CAL_KASA_RADIUS_THRES
CONFIG_ACCEL_CAL_MAX_TEMP
diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt
index 0aabe7d4f2..83a94c3b41 100644
--- a/zephyr/CMakeLists.txt
+++ b/zephyr/CMakeLists.txt
@@ -192,6 +192,8 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ACCELGYRO_ICM42607
"${PLATFORM_EC}/driver/accelgyro_icm42607.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ACCELGYRO_LSM6DSO
"${PLATFORM_EC}/driver/accelgyro_lsm6dso.c")
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ACCELGYRO_LSM6DSM
+ "${PLATFORM_EC}/driver/accelgyro_lsm6dsm.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ACCEL_FIFO
"${PLATFORM_EC}/common/motion_sense_fifo.c")
zephyr_library_sources_ifdef(CONFIG_ADC
diff --git a/zephyr/Kconfig.sensor_devices b/zephyr/Kconfig.sensor_devices
index 21851f1a5c..12f5951ff5 100644
--- a/zephyr/Kconfig.sensor_devices
+++ b/zephyr/Kconfig.sensor_devices
@@ -113,6 +113,13 @@ config PLATFORM_EC_ACCELGYRO_LSM6DSO
The driver supports ST's LSM6DSO 3D digital accelerometer sensor.
It allows measurements of acceleration in three perpendicular axes.
+config PLATFORM_EC_ACCELGYRO_LSM6DSM
+ bool "LSM6DSM Accelgyro Driver"
+ select PLATFORM_EC_STM_MEMS_COMMON
+ help
+ The driver supports ST's LSM6DSM 3D digital accelerometer sensor.
+ It allows measurements of acceleration in three perpendicular axes.
+
config PLATFORM_EC_STM_MEMS_COMMON
bool
help
diff --git a/zephyr/dts/bindings/motionsense/driver/cros-ec,lsm6dsm-accel.yaml b/zephyr/dts/bindings/motionsense/driver/cros-ec,lsm6dsm-accel.yaml
new file mode 100644
index 0000000000..25bd059906
--- /dev/null
+++ b/zephyr/dts/bindings/motionsense/driver/cros-ec,lsm6dsm-accel.yaml
@@ -0,0 +1,13 @@
+# Copyright 2022 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: motionsense sensor node for LSM6DSM Accelerometer
+
+compatible: "cros-ec,lsm6dsm-accel"
+
+include: lsm6dsm.yaml
+
+properties:
+ default-range:
+ default: 4
diff --git a/zephyr/dts/bindings/motionsense/driver/cros-ec,lsm6dsm-gyro.yaml b/zephyr/dts/bindings/motionsense/driver/cros-ec,lsm6dsm-gyro.yaml
new file mode 100644
index 0000000000..737f3a5105
--- /dev/null
+++ b/zephyr/dts/bindings/motionsense/driver/cros-ec,lsm6dsm-gyro.yaml
@@ -0,0 +1,13 @@
+# Copyright 2022 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: motionsense sensor node for LSM6DSM Gyro
+
+compatible: "cros-ec,lsm6dsm-gyro"
+
+include: lsm6dsm.yaml
+
+properties:
+ default-range:
+ default: 1000
diff --git a/zephyr/dts/bindings/motionsense/driver/lsm6dsm.yaml b/zephyr/dts/bindings/motionsense/driver/lsm6dsm.yaml
new file mode 100644
index 0000000000..efd71fe181
--- /dev/null
+++ b/zephyr/dts/bindings/motionsense/driver/lsm6dsm.yaml
@@ -0,0 +1,19 @@
+# Copyright 2022 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 LSM6DSM 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
+ # Address is b'0110101x' where x is determined by the
+ # logic level on SA0
+ enum:
+ - "LSM6DSM_ADDR0_FLAGS"
+ - "LSM6DSM_ADDR1_FLAGS"
+ default: "LSM6DSM_ADDR0_FLAGS"
diff --git a/zephyr/dts/bindings/motionsense/drvdata/cros-ec,drvdata-lsm6dsm.yaml b/zephyr/dts/bindings/motionsense/drvdata/cros-ec,drvdata-lsm6dsm.yaml
new file mode 100644
index 0000000000..66e6f32f60
--- /dev/null
+++ b/zephyr/dts/bindings/motionsense/drvdata/cros-ec,drvdata-lsm6dsm.yaml
@@ -0,0 +1,21 @@
+# Copyright 2022 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: LSM6DSM driver data node. Note this has to be
+ a separate instance for each sensor instance for this device
+ e.g if the device is used for both accel and gyro, then
+ separate instances of this driver data node must be used for each.
+
+compatible: "cros-ec,drvdata-lsm6dsm"
+
+include: drvdata-base.yaml
+
+#
+# examples:
+#
+# lsm6dsm_data: lsm6dsm-drv-data {
+# compatible = "cros-ec,drvdata-lsm6dsm";
+# status = "okay";
+# };
+#
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index 45715a5ae3..38bf127379 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -2014,6 +2014,11 @@ extern char mock_jump_data[sizeof(struct jump_data) + 256];
#define CONFIG_ACCELGYRO_LSM6DSO
#endif
+#undef CONFIG_ACCELGYRO_LSM6DSM
+#ifdef CONFIG_PLATFORM_EC_ACCELGYRO_LSM6DSM
+#define CONFIG_ACCELGYRO_LSM6DSM
+#endif
+
#endif /* CONFIG_PLATFORM_EC_MOTIONSENSE */
#undef CONFIG_MATH_UTIL
diff --git a/zephyr/shim/src/motionsense_driver/lsm6dsm-drvinfo.inc b/zephyr/shim/src/motionsense_driver/lsm6dsm-drvinfo.inc
new file mode 100644
index 0000000000..32faaa087f
--- /dev/null
+++ b/zephyr/shim/src/motionsense_driver/lsm6dsm-drvinfo.inc
@@ -0,0 +1,57 @@
+/* Copyright 2022 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_lsm6dsm.h"
+#include "driver/stm_mems_common.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. This must be a separate instance for
+ * each entry of the lsm6dsm device in the motion_sensors array.
+ */
+#define CREATE_SENSOR_DATA_LSM6DSM(id, drvdata_name) \
+ static struct lsm6dsm_data drvdata_name = LSM6DSM_DATA;
+
+/*
+ * Create driver data for each lsm6dsm drvinfo instance in device tree.
+ * (compatible = "cros-ec,drvdata-lsm6dsm")
+ */
+CREATE_SENSOR_DATA(cros_ec_drvdata_lsm6dsm, CREATE_SENSOR_DATA_LSM6DSM)
+/*
+ * 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 lsm6dsm accel instance(compatible = "cros-ec,lsm6dsm-accel")
+ * in device tree.
+ */
+CREATE_MOTION_SENSOR(cros_ec_lsm6dsm_accel, MOTIONSENSE_CHIP_LSM6DSM, \
+ MOTIONSENSE_TYPE_ACCEL, lsm6dsm_drv, \
+ LSM6DSM_ODR_MIN_VAL, LSM6DSM_ODR_MAX_VAL)
+
+/*
+ * Here, we call CREATE_MOTION_SENSOR to create a motion_sensor_t entry
+ * for each lsm6dsm gyro instance (compatible = "cros-ec,lsm6dsm-gyro")
+ * in device tree.
+ */
+CREATE_MOTION_SENSOR(cros_ec_lsm6dsm_gyro, MOTIONSENSE_CHIP_LSM6DSM, \
+ MOTIONSENSE_TYPE_GYRO, lsm6dsm_drv, \
+ LSM6DSM_ODR_MIN_VAL, LSM6DSM_ODR_MAX_VAL)
diff --git a/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc b/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc
index cecc3a9ced..1ea1ba2a2d 100644
--- a/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc
+++ b/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc
@@ -52,3 +52,6 @@
#ifdef CONFIG_PLATFORM_EC_ACCELGYRO_LSM6DSO
#include "lsm6dso-drvinfo.inc"
#endif
+#ifdef CONFIG_PLATFORM_EC_ACCELGYRO_LSM6DSM
+#include "lsm6dsm-drvinfo.inc"
+#endif