summaryrefslogtreecommitdiff
path: root/zephyr/emul/emul_isl923x.c
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2021-09-29 22:15:43 -0600
committerCommit Bot <commit-bot@chromium.org>2021-10-01 17:45:39 +0000
commit5b2987bbcbd55f4c6ba28e075a82183a5bdd8b31 (patch)
treee8c698698e3182bcc00af4367b95151246f125e5 /zephyr/emul/emul_isl923x.c
parent7d2f528aafc357481e01dfcb00dd1968520b38aa (diff)
downloadchrome-ec-5b2987bbcbd55f4c6ba28e075a82183a5bdd8b31.tar.gz
zephyr: test: Add stub isl923x emulator
Add the skeleton code needed to emulate the isl923x charger. BRANCH=none BUG=b:201602829 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Yuval Peress <peress@google.com> Change-Id: Ic9af555ccd7ff6a0be2e7a0818b5e566816a0c13 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3195202 Reviewed-by: Aaron Massey <aaronmassey@google.com> Reviewed-by: Wai-Hong Tam <waihong@google.com>
Diffstat (limited to 'zephyr/emul/emul_isl923x.c')
-rw-r--r--zephyr/emul/emul_isl923x.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/zephyr/emul/emul_isl923x.c b/zephyr/emul/emul_isl923x.c
new file mode 100644
index 0000000000..2a76c08d74
--- /dev/null
+++ b/zephyr/emul/emul_isl923x.c
@@ -0,0 +1,64 @@
+/* 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_isl923x_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/charger/isl923x.h"
+#include "driver/charger/isl923x_public.h"
+#include "emul/emul_common_i2c.h"
+#include "emul/emul_isl923x.h"
+#include "i2c.h"
+
+#include <logging/log.h>
+LOG_MODULE_REGISTER(isl923x_emul, CONFIG_ISL923X_EMUL_LOG_LEVEL);
+
+struct isl923x_emul_data {
+ /** Common I2C data */
+ struct i2c_common_emul_data common;
+};
+
+struct isl923x_emul_cfg {
+ /** Common I2C config */
+ const struct i2c_common_emul_cfg common;
+};
+
+static int emul_isl923x_init(const struct emul *emul,
+ const struct device *parent)
+{
+ const struct isl923x_emul_cfg *cfg = emul->cfg;
+ struct isl923x_emul_data *data = emul->data;
+
+ data->common.emul.api = &i2c_common_emul_api;
+ data->common.emul.addr = cfg->common.addr;
+ data->common.emul.parent = emul;
+ data->common.i2c = parent;
+ data->common.cfg = &cfg->common;
+ i2c_common_emul_init(&data->common);
+
+ return i2c_emul_register(parent, emul->dev_label, &data->common.emul);
+}
+
+#define INIT_ISL923X(n) \
+ static struct isl923x_emul_data isl923x_emul_data_##n = { \
+ .common = {}, \
+ }; \
+ static struct isl923x_emul_cfg isl923x_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_isl923x_init, DT_DRV_INST(n), &isl923x_emul_cfg_##n, \
+ &isl923x_emul_data_##n)
+
+DT_INST_FOREACH_STATUS_OKAY(INIT_ISL923X)