summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@google.com>2021-06-07 09:48:00 -0600
committerCommit Bot <commit-bot@chromium.org>2021-06-07 18:15:22 +0000
commit4df10f7b2b0e67d1c36bb69285436ec0d5e3fdfd (patch)
tree4276acbab14b79df5066770362347e14b0d6380d
parent43fffb5b0292ee1c48015b04ea55793a140d8177 (diff)
downloadchrome-ec-4df10f7b2b0e67d1c36bb69285436ec0d5e3fdfd.tar.gz
zephyr: driver: add ST accel_lis2dw12
BUG=b:180980668,b:189857004 BRANCH=none TEST=make buildall TEST=zmake configure -b $PROJ_HAYATO Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Ib743f0dbcc4a9731ccb575344413f161cd0dbba2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2944617 Tested-by: Denis Brockus <dbrockus@chromium.org> Auto-Submit: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Yuval Peress <peress@chromium.org> Commit-Queue: Yuval Peress <peress@chromium.org>
-rw-r--r--driver/accel_lis2dw12.c19
-rw-r--r--driver/accel_lis2dw12.h26
-rw-r--r--include/driver/accel_lis2dw12_public.h34
-rw-r--r--zephyr/CMakeLists.txt4
-rw-r--r--zephyr/Kconfig.sensor_devices20
-rw-r--r--zephyr/dts/bindings/motionsense/driver/cros-ec,lis2dw12.yaml10
-rw-r--r--zephyr/dts/bindings/motionsense/drvdata/cros-ec,drvdata-lis2dw12.yaml18
-rw-r--r--zephyr/shim/include/config_chip.h10
-rw-r--r--zephyr/shim/src/motionsense_driver/lis2dw12-drvinfo.inc44
-rw-r--r--zephyr/shim/src/motionsense_driver/sensor_drv_list.inc3
10 files changed, 163 insertions, 25 deletions
diff --git a/driver/accel_lis2dw12.c b/driver/accel_lis2dw12.c
index 270c2d0eed..2658217d5c 100644
--- a/driver/accel_lis2dw12.c
+++ b/driver/accel_lis2dw12.c
@@ -10,7 +10,7 @@
#include "accelgyro.h"
#include "common.h"
#include "console.h"
-#include "driver/accel_lis2dw12.h"
+#include "accel_lis2dw12.h"
#include "hooks.h"
#include "hwtimer.h"
#include "math_util.h"
@@ -28,6 +28,23 @@
#define LIS2DW12_ENABLE_FIFO
#endif
+#if defined(CONFIG_ZEPHYR) && defined(CONFIG_ACCEL_INTERRUPTS)
+/* Get the motion sensor ID of the LIS2DW12 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 (lis2dw12_int) to get the motion sensor ID. This alias
+ * MUST be defined for this driver to work.
+ * aliases {
+ * lis2dw12-int = &lid_accel;
+ * };
+ */
+#if DT_NODE_EXISTS(DT_ALIAS(lis2dw12_int))
+#define CONFIG_ACCEL_LIS2DW12_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(SENSOR_ID(DT_ALIAS(lis2dw12_int)))
+#endif
+#endif
+
STATIC_IF(LIS2DW12_ENABLE_FIFO) volatile uint32_t last_interrupt_timestamp;
/**
diff --git a/driver/accel_lis2dw12.h b/driver/accel_lis2dw12.h
index c1f70bc513..8e1c97464c 100644
--- a/driver/accel_lis2dw12.h
+++ b/driver/accel_lis2dw12.h
@@ -11,20 +11,8 @@
#ifndef __CROS_EC_ACCEL_LIS2DW12_H
#define __CROS_EC_ACCEL_LIS2DW12_H
-#include "driver/stm_mems_common.h"
-
-/*
- * 7-bit address is 011000Xb. Where 'X' is determined
- * by the voltage on the ADDR pin.
- */
-#define LIS2DW12_ADDR0 0x18
-#define LIS2DW12_ADDR1 0x19
-
-#define LIS2DWL_ADDR0_FLAGS 0x18
-#define LIS2DWL_ADDR1_FLAGS 0x19
-
-#define LIS2DW12_EN_BIT 0x01
-#define LIS2DW12_DIS_BIT 0x00
+#include "driver/accel_lis2dw12_public.h"
+#include "stm_mems_common.h"
/* Who am I. */
#define LIS2DW12_WHO_AM_I_REG 0x0f
@@ -174,12 +162,6 @@ enum lis2dw12_odr {
LIS2DW12_ODR_LIST_NUM
};
-/* Absolute Acc rate. */
-#define LIS2DW12_ODR_MIN_VAL 12500
-#define LIS2DW12_ODR_MAX_VAL \
- MOTION_MAX_SENSOR_FREQUENCY(1600000, LIS2DW12_ODR_MIN_VAL)
-
-
/* Full scale range registers. */
#define LIS2DW12_FS_ADDR LIS2DW12_CTRL6_ADDR
#define LIS2DW12_FS_MASK 0x30
@@ -224,8 +206,4 @@ enum lis2dw12_fs {
*/
#define LIS2DW12_RESOLUTION 14
-extern const struct accelgyro_drv lis2dw12_drv;
-
-void lis2dw12_interrupt(enum gpio_signal signal);
-
#endif /* __CROS_EC_ACCEL_LIS2DW12_H */
diff --git a/include/driver/accel_lis2dw12_public.h b/include/driver/accel_lis2dw12_public.h
new file mode 100644
index 0000000000..ba9fd80809
--- /dev/null
+++ b/include/driver/accel_lis2dw12_public.h
@@ -0,0 +1,34 @@
+/* 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.
+ */
+
+/* LIS2DW12 gsensor module for Chrome EC */
+
+#ifndef __CROS_EC_DRIVER_ACCEL_LIS2DW12_PUBLIC_H
+#define __CROS_EC_DRIVER_ACCEL_LIS2DW12_PUBLIC_H
+
+extern const struct accelgyro_drv lis2dw12_drv;
+
+/* I2C ADDRESS DEFINITIONS
+ *
+ * 7-bit address is 011000Xb. Where 'X' is determined
+ * by the voltage on the ADDR pin.
+ */
+#define LIS2DW12_ADDR0 0x18
+#define LIS2DW12_ADDR1 0x19
+
+#define LIS2DWL_ADDR0_FLAGS 0x18
+#define LIS2DWL_ADDR1_FLAGS 0x19
+
+#define LIS2DW12_EN_BIT 0x01
+#define LIS2DW12_DIS_BIT 0x00
+
+/* Absolute Acc rate. */
+#define LIS2DW12_ODR_MIN_VAL 12500
+#define LIS2DW12_ODR_MAX_VAL \
+ MOTION_MAX_SENSOR_FREQUENCY(1600000, LIS2DW12_ODR_MIN_VAL)
+
+void lis2dw12_interrupt(enum gpio_signal signal);
+
+#endif /* __CROS_EC_DRIVER_ACCEL_LIS2DW12_PUBLIC_H */
diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt
index 9e9af412d8..78f33d1f4f 100644
--- a/zephyr/CMakeLists.txt
+++ b/zephyr/CMakeLists.txt
@@ -133,6 +133,8 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ACCEL_BMA255
"${PLATFORM_EC}/common/math_util.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ACCEL_KX022
"${PLATFORM_EC}/driver/accel_kionix.c")
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ACCEL_LIS2DW12
+ "${PLATFORM_EC}/driver/accel_lis2dw12.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ACCELGYRO_BMI
"${PLATFORM_EC}/driver/accelgyro_bmi_common.c"
"${PLATFORM_EC}/common/math_util.c")
@@ -281,6 +283,8 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_SWITCHCAP_LN9310
"${PLATFORM_EC}/driver/ln9310.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_SPI_FLASH_REGS
"${PLATFORM_EC}/common/spi_flash_reg.c")
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_STM_MEMS_COMMON
+ "${PLATFORM_EC}/driver/stm_mems_common.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_TABLET_MODE
"${PLATFORM_EC}/common/tablet_mode.c")
diff --git a/zephyr/Kconfig.sensor_devices b/zephyr/Kconfig.sensor_devices
index d4415af9b4..0dc3eb40d4 100644
--- a/zephyr/Kconfig.sensor_devices
+++ b/zephyr/Kconfig.sensor_devices
@@ -32,6 +32,21 @@ config PLATFORM_EC_ACCEL_KX022
The driver supports Kionix's KX022 triaxial low-g acceleration sensor.
It allows measurements of acceleration in three perpendicular axes.
+config PLATFORM_EC_ACCEL_LIS2DW12
+ bool "LIS2DW12 Accelerometer Driver"
+ imply PLATFORM_EC_STM_MEMS_COMMON
+ help
+ The driver supports ST's LIS2DW12 3D digital accelerometer sensor.
+ It allows measurements of acceleration in three perpendicular axes.
+
+config PLATFORM_EC_ACCEL_LIS2DW12_AS_BASE
+ bool "LIS2DW12 Interrupt force mode"
+ depends on PLATFORM_EC_ACCEL_LIS2DW12
+ help
+ The LIS2DW driver supports fifo and interrupt, but letting lid accel
+ sensor work at polling mode is a common selection in current usage
+ model. This option will select interrupt (foced mode).
+
config PLATFORM_EC_ACCELGYRO_BMI160
bool "BMI160 Accelgyrometer Driver"
select PLATFORM_EC_ACCELGYRO_BMI
@@ -61,6 +76,11 @@ config PLATFORM_EC_ACCELGYRO_ICM426XX
The driver supports ICM425XX which provides both accelerometer and
gyroscope readings.
+config PLATFORM_EC_STM_MEMS_COMMON
+ bool "STM MEMS Common Driver"
+ help
+ The driver supports common STM MEMS devices
+
rsource "Kconfig.accelgyro_bmi"
rsource "Kconfig.accelgyro_icm"
diff --git a/zephyr/dts/bindings/motionsense/driver/cros-ec,lis2dw12.yaml b/zephyr/dts/bindings/motionsense/driver/cros-ec,lis2dw12.yaml
new file mode 100644
index 0000000000..5f7b0b40e0
--- /dev/null
+++ b/zephyr/dts/bindings/motionsense/driver/cros-ec,lis2dw12.yaml
@@ -0,0 +1,10 @@
+# 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: motionsense sensor node for LIS2DW12 Accelerometer
+
+compatible: "cros-ec,lis2dw12"
+
+# every motionsense sensor node should include motionsense-sensor-base.yaml
+include: motionsense-sensor-base.yaml
diff --git a/zephyr/dts/bindings/motionsense/drvdata/cros-ec,drvdata-lis2dw12.yaml b/zephyr/dts/bindings/motionsense/drvdata/cros-ec,drvdata-lis2dw12.yaml
new file mode 100644
index 0000000000..ecb182a4fd
--- /dev/null
+++ b/zephyr/dts/bindings/motionsense/drvdata/cros-ec,drvdata-lis2dw12.yaml
@@ -0,0 +1,18 @@
+# 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: LIS2DW12 driver data node
+
+compatible: "cros-ec,drvdata-lis2dw12"
+
+include: drvdata-base.yaml
+
+#
+# examples:
+#
+# lis2dw12_data: lis2dw12-drv-data {
+# compatible = "cros-ec,drvdata-lis2dw12";
+# status = "okay";
+# };
+#
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index 204f3732c9..cc500cd748 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -1572,4 +1572,14 @@
#define CONFIG_CCD_USBC_PORT_NUMBER CONFIG_PLATFORM_EC_CCD_USBC_PORT_NUMBER
#endif
+#undef CONFIG_ACCEL_LIS2DW12
+#ifdef CONFIG_PLATFORM_EC_ACCEL_LIS2DW12
+#define CONFIG_ACCEL_LIS2DW12
+#endif
+
+#undef CONFIG_ACCEL_LIS2DW_AS_BASE
+#ifdef CONFIG_PLATFORM_EC_ACCEL_LIS2DW12_AS_BASE
+#define CONFIG_ACCEL_LIS2DW_AS_BASE
+#endif
+
#endif /* __CROS_EC_CONFIG_CHIP_H */
diff --git a/zephyr/shim/src/motionsense_driver/lis2dw12-drvinfo.inc b/zephyr/shim/src/motionsense_driver/lis2dw12-drvinfo.inc
new file mode 100644
index 0000000000..433a9d4192
--- /dev/null
+++ b/zephyr/shim/src/motionsense_driver/lis2dw12-drvinfo.inc
@@ -0,0 +1,44 @@
+/* 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 "accel_lis2dw12_public.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 for each Kionix drvinfo instance in device tree.
+ * (compatible = "cros-ec,drvdata-lis2dw12")
+ */
+/* Declare LIS2DW12 driver data */
+#define CREATE_SENSOR_DATA_LIS2DW12(id, drvdata_name) \
+ static struct motion_sensor_t drvdata_name;
+
+CREATE_SENSOR_DATA(cros_ec_drvdata_lis2dw12, CREATE_SENSOR_DATA_LIS2DW12)
+
+/*
+ * 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.
+ */
+
+/*
+ * Create a motion_sensor_t entry for each LIS2DW12
+ * instance(compatible = "cros-ec,lis2dw12") in device tree.
+ */
+CREATE_MOTION_SENSOR(cros_ec_lis2dw12, MOTIONSENSE_CHIP_LIS2DW12, \
+ MOTIONSENSE_TYPE_ACCEL, lis2dw12_drv, \
+ LIS2DW12_ODR_MIN_VAL, LIS2DW12_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 b9b3a189ad..f8fa4b7e53 100644
--- a/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc
+++ b/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc
@@ -25,6 +25,9 @@
#ifdef CONFIG_PLATFORM_EC_ACCEL_KX022
#include "kx022-drvinfo.inc"
#endif
+#ifdef CONFIG_PLATFORM_EC_ACCEL_LIS2DW12
+#include "lis2dw12-drvinfo.inc"
+#endif
#ifdef CONFIG_PLATFORM_EC_ACCELGYRO_BMI160
#include "bmi160-drvinfo.inc"
#endif