summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorPaul Ma <magf@bitland.corp-partner.google.com>2019-08-06 16:59:49 +0800
committerCommit Bot <commit-bot@chromium.org>2019-08-21 05:46:30 +0000
commita29f68a815b8e0ddb472c2cc812d6b18ac4b8c74 (patch)
tree9b20c9be82c45c8a0d1b52372bb523bf74320187 /driver
parent74f268374972bdc8bd6c2a5c412d31edafa812b1 (diff)
downloadchrome-ec-a29f68a815b8e0ddb472c2cc812d6b18ac4b8c74.tar.gz
driver: lis2dwl: add driver support
lis2dwl has almost the same register interface as lis2dw12. lis2dwl only has one low power mode and when in low power mode, it has only 12 bit resolution. In order to get 14 bit resolution, we only use its high performance mode. Add MOTIONSENSE_FLAG_INT_ACTIVE_HIGH flag to support both active high and active low interrupt. BUG=b:138768226, b:138978278 BRANCH=none TEST=use Akemi board, add lis2dwl as accel sensor, boot the board and make sure sensor x/y/z get correct value by 'accelinfo on' Cq-Depend: chromium:515302 Change-Id: I37fcc0f43af3c8055079e09db00757b665813ba8 Signed-off-by: Paul Ma <magf@bitland.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1739026 Tested-by: Martin Roth <martinroth@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Martin Roth <martinroth@chromium.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: mario tesi <mario.tesi@st.com> Commit-Queue: Martin Roth <martinroth@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/accel_lis2dw12.c24
-rw-r--r--driver/accel_lis2dw12.h3
-rw-r--r--driver/build.mk2
3 files changed, 27 insertions, 2 deletions
diff --git a/driver/accel_lis2dw12.c b/driver/accel_lis2dw12.c
index 7faed478c2..13359575de 100644
--- a/driver/accel_lis2dw12.c
+++ b/driver/accel_lis2dw12.c
@@ -109,7 +109,8 @@ static int fifo_data_avail(struct motion_sensor_t *s)
int ret, nsamples;
if (s->flags & MOTIONSENSE_FLAG_INT_SIGNAL)
- return gpio_get_level(s->int_signal);
+ return gpio_get_level(s->int_signal) ==
+ !!(MOTIONSENSE_FLAG_INT_ACTIVE_HIGH & s->flags);
ret = lis2dw12_get_fifo_samples(s, &nsamples);
/* If we failed to read the FIFO size assume empty. */
@@ -387,11 +388,18 @@ static int set_data_rate(const struct motion_sensor_t *s, int rate, int rnd)
reg_val = LIS2DW12_ODR_12HZ_VAL;
normalized_rate = LIS2DW12_ODR_MIN_VAL;
}
+
+ /* lis2dwl supports 14 bit resolution only at high performance mode,
+ * and it will always stay at high performance mode from initialization.
+ * But lis2dw12 needs switch low power mode according to odr value.
+ */
+#ifndef CONFIG_ACCEL_LIS2DWL
if (reg_val > LIS2DW12_ODR_200HZ_VAL)
ret = set_power_mode(s, LIS2DW12_HIGH_PERF, 0);
else
ret = set_power_mode(s, LIS2DW12_LOW_POWER,
LIS2DW12_LOW_POWER_MODE_2);
+#endif
ret = st_write_data_with_mask(s, LIS2DW12_ACC_ODR_ADDR,
LIS2DW12_ACC_ODR_MASK, reg_val);
@@ -508,8 +516,22 @@ static int init(const struct motion_sensor_t *s)
if (ret != EC_SUCCESS)
goto err_unlock;
+ /* Interrupt trigger level of power-on-reset is HIGH */
+ if (!(MOTIONSENSE_FLAG_INT_ACTIVE_HIGH & s->flags)) {
+ ret = st_write_data_with_mask(s, LIS2DW12_H_ACTIVE_ADDR,
+ LIS2DW12_H_ACTIVE_MASK,
+ LIS2DW12_EN_BIT);
+ if (ret != EC_SUCCESS)
+ goto err_unlock;
+ }
+
+#ifdef CONFIG_ACCEL_LIS2DWL
+ /* lis2dwl supports 14 bit resolution only at high perfomance mode */
+ ret = set_power_mode(s, LIS2DW12_HIGH_PERF, 0);
+#else
/* Set default Mode and Low Power Mode. */
ret = set_power_mode(s, LIS2DW12_LOW_POWER, LIS2DW12_LOW_POWER_MODE_2);
+#endif
if (ret != EC_SUCCESS)
goto err_unlock;
diff --git a/driver/accel_lis2dw12.h b/driver/accel_lis2dw12.h
index de547cb3ad..a4d183de78 100644
--- a/driver/accel_lis2dw12.h
+++ b/driver/accel_lis2dw12.h
@@ -20,6 +20,9 @@
#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
diff --git a/driver/build.mk b/driver/build.mk
index 0770734496..e110e41667 100644
--- a/driver/build.mk
+++ b/driver/build.mk
@@ -19,7 +19,7 @@ driver-$(CONFIG_ACCEL_LIS2D_COMMON)+=accel_lis2dh.o stm_mems_common.o
driver-$(CONFIG_MAG_LIS2MDL)+=mag_lis2mdl.o
driver-$(CONFIG_SENSORHUB_LSM6DSM)+=sensorhub_lsm6dsm.o
driver-$(CONFIG_SYNC)+=sync.o
-driver-$(CONFIG_ACCEL_LIS2DW12)+=accel_lis2dw12.o stm_mems_common.o
+driver-$(CONFIG_ACCEL_LIS2DW_COMMON)+=accel_lis2dw12.o stm_mems_common.o
# BC1.2 Charger Detection Devices
driver-$(CONFIG_BC12_DETECT_MAX14637)+=bc12/max14637.o