summaryrefslogtreecommitdiff
path: root/zephyr
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-09-16 22:31:49 -0600
committerCommit Bot <commit-bot@chromium.org>2021-09-17 21:00:11 +0000
commit256b26922dc7446260a4ec22538fc5574e8503f3 (patch)
tree9e69a2283e0f241e2bc7210ecf878365cb3e5d86 /zephyr
parent1613037faf34f98a6683bc5563c513ff5b55b299 (diff)
downloadchrome-ec-256b26922dc7446260a4ec22538fc5574e8503f3.tar.gz
zephyr: emul: lis2dw12: Add stubs for LIS2DW12 emulator
BRANCH=none BUG=b:200046770 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: If425d9760b8db9024478fb9a664ffa71e7c25eb7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3168034 Tested-by: Yuval Peress <peress@google.com> Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Yuval Peress <peress@google.com>
Diffstat (limited to 'zephyr')
-rw-r--r--zephyr/dts/bindings/emul/cros,lis2dw12-emul.yaml12
-rw-r--r--zephyr/emul/CMakeLists.txt1
-rw-r--r--zephyr/emul/Kconfig1
-rw-r--r--zephyr/emul/Kconfig.lis2dw1223
-rw-r--r--zephyr/emul/emul_lis2dw12.c69
-rw-r--r--zephyr/emul/emul_ln9310.c1
-rw-r--r--zephyr/include/emul/emul_lis2dw12.h9
-rw-r--r--zephyr/test/drivers/overlay.dts30
8 files changed, 146 insertions, 0 deletions
diff --git a/zephyr/dts/bindings/emul/cros,lis2dw12-emul.yaml b/zephyr/dts/bindings/emul/cros,lis2dw12-emul.yaml
new file mode 100644
index 0000000000..44c29fbe56
--- /dev/null
+++ b/zephyr/dts/bindings/emul/cros,lis2dw12-emul.yaml
@@ -0,0 +1,12 @@
+# 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: CROS implementation of the LIS2DW12 emulator
+
+compatible: "cros,lis2dw12-emul"
+
+include: base.yaml
+properties:
+ reg:
+ required: true
diff --git a/zephyr/emul/CMakeLists.txt b/zephyr/emul/CMakeLists.txt
index 5c5a69eb35..b46c51c8b6 100644
--- a/zephyr/emul/CMakeLists.txt
+++ b/zephyr/emul/CMakeLists.txt
@@ -13,3 +13,4 @@ zephyr_library_sources_ifdef(CONFIG_EMUL_BMI emul_bmi260.c)
zephyr_library_sources_ifdef(CONFIG_EMUL_TCS3400 emul_tcs3400.c)
zephyr_library_sources_ifdef(CONFIG_EMUL_BB_RETIMER emul_bb_retimer.c)
zephyr_library_sources_ifdef(CONFIG_EMUL_LN9310 emul_ln9310.c)
+zephyr_library_sources_ifdef(CONFIG_EMUL_LIS2DW12 emul_lis2dw12.c)
diff --git a/zephyr/emul/Kconfig b/zephyr/emul/Kconfig
index f52c27349b..c108caea4b 100644
--- a/zephyr/emul/Kconfig
+++ b/zephyr/emul/Kconfig
@@ -68,3 +68,4 @@ config EMUL_BB_RETIMER
available in zephyr/include/emul/emul_bb_retimer.h
rsource "Kconfig.ln9310"
+rsource "Kconfig.lis2dw12"
diff --git a/zephyr/emul/Kconfig.lis2dw12 b/zephyr/emul/Kconfig.lis2dw12
new file mode 100644
index 0000000000..2263255418
--- /dev/null
+++ b/zephyr/emul/Kconfig.lis2dw12
@@ -0,0 +1,23 @@
+# 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.
+
+DT_COMPAT_LIS2DW12_EMUL := cros,lis2dw12-emul
+
+menuconfig EMUL_LIS2DW12
+ bool "LIS2DW12 accelerometer emulator"
+ default $(dt_compat_enabled,$(DT_COMPAT_LIS2DW12_EMUL))
+ depends on I2C_EMUL
+ select PLATFORM_EC_ACCEL_LIS2DW12
+ help
+ Enable the LIS2DW12 emulator. This driver uses the emulated I2C bus.
+ It is used to test the lis2dw12 driver. Emulator API is available in
+ zephyr/include/emul/emul_lis2dw12.h
+
+if EMUL_LIS2DW12
+
+module = LIS2DW12_EMUL
+module-str = lis2dw12_emul
+source "subsys/logging/Kconfig.template.log_config"
+
+endif # EMUL_LIS2DW12
diff --git a/zephyr/emul/emul_lis2dw12.c b/zephyr/emul/emul_lis2dw12.c
new file mode 100644
index 0000000000..e775bdbb20
--- /dev/null
+++ b/zephyr/emul/emul_lis2dw12.c
@@ -0,0 +1,69 @@
+/* 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.
+ */
+
+#define DT_DRV_COMPAT cros_lis2dw12_emul
+
+#include <device.h>
+#include <drivers/i2c.h>
+#include <drivers/i2c_emul.h>
+#include <emul.h>
+#include <errno.h>
+#include <sys/__assert.h>
+
+#include "driver/accel_lis2dw12.h"
+#include "emul/emul_common_i2c.h"
+#include "emul/emul_lis2dw12.h"
+#include "i2c.h"
+
+#include <logging/log.h>
+LOG_MODULE_REGISTER(lis2dw12_emul, CONFIG_LIS2DW12_EMUL_LOG_LEVEL);
+
+struct lis2dw12_emul_data {
+ /** Common I2C data */
+ struct i2c_common_emul_data common;
+};
+
+struct lis2dw12_emul_cfg {
+ /** Common I2C config */
+ struct i2c_common_emul_cfg common;
+};
+
+static struct i2c_emul_api lis2dw12_emul_api_i2c = {
+ .transfer = i2c_common_emul_transfer,
+};
+
+static int emul_lis2dw12_init(const struct emul *emul,
+ const struct device *parent)
+{
+ const struct lis2dw12_emul_cfg *lis2dw12_cfg = emul->cfg;
+ const struct i2c_common_emul_cfg *cfg = &(lis2dw12_cfg->common);
+ struct lis2dw12_emul_data *data = emul->data;
+
+ data->common.emul.api = &lis2dw12_emul_api_i2c;
+ data->common.emul.addr = cfg->addr;
+ data->common.emul.parent = emul;
+ data->common.i2c = parent;
+ data->common.cfg = cfg;
+ i2c_common_emul_init(&data->common);
+
+ return i2c_emul_register(parent, emul->dev_label, &data->common.emul);
+}
+
+#define INIT_LIS2DW12(n) \
+ static struct lis2dw12_emul_data lis2dw12_emul_data_##n = { \
+ .common = { \
+ }, \
+ }; \
+ static const struct lis2dw12_emul_cfg lis2dw12_emul_cfg_##n = { \
+ .common = { \
+ .i2c_label = DT_INST_BUS_LABEL(n), \
+ .dev_label = DT_INST_LABEL(n), \
+ .addr = DT_INST_REG_ADDR(n), \
+ }, \
+ }; \
+ EMUL_DEFINE(emul_lis2dw12_init, DT_DRV_INST(n), \
+ &lis2dw12_emul_cfg_##n, &lis2dw12_emul_data_##n)
+
+DT_INST_FOREACH_STATUS_OKAY(INIT_LIS2DW12)
diff --git a/zephyr/emul/emul_ln9310.c b/zephyr/emul/emul_ln9310.c
index 19e3fc7276..9298767d67 100644
--- a/zephyr/emul/emul_ln9310.c
+++ b/zephyr/emul/emul_ln9310.c
@@ -14,6 +14,7 @@
#include "driver/ln9310.h"
#include "emul/emul_common_i2c.h"
+#include "emul/emul_ln9310.h"
#include "i2c.h"
#include <logging/log.h>
diff --git a/zephyr/include/emul/emul_lis2dw12.h b/zephyr/include/emul/emul_lis2dw12.h
new file mode 100644
index 0000000000..ce34887da8
--- /dev/null
+++ b/zephyr/include/emul/emul_lis2dw12.h
@@ -0,0 +1,9 @@
+/* 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.
+ */
+
+#ifndef ZEPHYR_INCLUDE_EMUL_EMUL_LIS2DW12_H_
+#define ZEPHYR_INCLUDE_EMUL_EMUL_LIS2DW12_H_
+
+#endif /* ZEPHYR_INCLUDE_EMUL_EMUL_LIS2DW12_H_ */
diff --git a/zephyr/test/drivers/overlay.dts b/zephyr/test/drivers/overlay.dts
index 56027a7138..adf90fbc6c 100644
--- a/zephyr/test/drivers/overlay.dts
+++ b/zephyr/test/drivers/overlay.dts
@@ -9,6 +9,7 @@
aliases {
bmi260-int = &ms_bmi260_accel;
bmi160-int = &ms_bmi160_accel;
+ lis2dw12-int = &ms_lis2dw12_accel;
tcs3400-int = &tcs3400_clear;
};
named-gpios {
@@ -207,6 +208,10 @@
mutex_bmi160: bmi160-mutex {
label = "BMI160_MUTEX";
};
+
+ mutex_lis2dw12: lis2dw12-mutex {
+ label = "LIS2DW12_MUTEX";
+ };
};
/*
@@ -224,6 +229,11 @@
status = "okay";
};
+ lis2dw12_data: lis2dw12-drv-data {
+ compatible = "cros-ec,drvdata-lis2dw12";
+ status = "okay";
+ };
+
tcs_clear_data: tcs3400-clear-drv-data {
compatible = "cros-ec,drvdata-tcs3400-clear";
status = "okay";
@@ -347,6 +357,19 @@
i2c-spi-addr-flags = "BMI160_ADDR0_FLAGS";
};
+ ms_lis2dw12_accel: ms-lis2dw12-accel {
+ compatible = "cros-ec,lis2dw12";
+ status = "okay";
+
+ label = "LIS2DW12";
+ location = "MOTIONSENSE_LOC_BASE";
+ mutex = <&mutex_lis2dw12>;
+ port = <&i2c_accel>;
+ drv-data = <&lis2dw12_data>;
+ default-range = <2>;
+ i2c-spi-addr-flags = "LIS2DWL_ADDR1_FLAGS";
+ };
+
tcs3400_clear: tcs3400-clear {
compatible = "cros-ec,tcs3400-clear";
status = "okay";
@@ -495,4 +518,11 @@
reg = <0x80>;
label = "LN9310";
};
+
+ lis2dw12_emul: lis2dw12@19 {
+ compatible = "cros,lis2dw12-emul";
+ status = "okay";
+ reg = <0x19>;
+ label = "LIS2DW12_EMUL";
+ };
};