diff options
author | Yuval Peress <peress@google.com> | 2021-09-29 22:15:43 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-01 17:45:39 +0000 |
commit | 5b2987bbcbd55f4c6ba28e075a82183a5bdd8b31 (patch) | |
tree | e8c698698e3182bcc00af4367b95151246f125e5 | |
parent | 7d2f528aafc357481e01dfcb00dd1968520b38aa (diff) | |
download | chrome-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>
-rw-r--r-- | zephyr/dts/bindings/emul/cros,isl923x_emul.yaml | 12 | ||||
-rw-r--r-- | zephyr/emul/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/emul/Kconfig | 1 | ||||
-rw-r--r-- | zephyr/emul/Kconfig.isl923x | 22 | ||||
-rw-r--r-- | zephyr/emul/emul_isl923x.c | 64 | ||||
-rw-r--r-- | zephyr/include/emul/emul_isl923x.h | 9 | ||||
-rw-r--r-- | zephyr/test/drivers/overlay.dts | 7 |
7 files changed, 116 insertions, 0 deletions
diff --git a/zephyr/dts/bindings/emul/cros,isl923x_emul.yaml b/zephyr/dts/bindings/emul/cros,isl923x_emul.yaml new file mode 100644 index 0000000000..be8b1183a2 --- /dev/null +++ b/zephyr/dts/bindings/emul/cros,isl923x_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: ISL923X Charger emulator + +compatible: "cros,isl923x_emul" + +include: base.yaml +properties: + reg: + required: true diff --git a/zephyr/emul/CMakeLists.txt b/zephyr/emul/CMakeLists.txt index 02b176b942..8bf15666ab 100644 --- a/zephyr/emul/CMakeLists.txt +++ b/zephyr/emul/CMakeLists.txt @@ -15,3 +15,4 @@ 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) zephyr_library_sources_ifdef(CONFIG_I2C_MOCK i2c_mock.c) +zephyr_library_sources_ifdef(CONFIG_EMUL_ISL923X emul_isl923x.c) diff --git a/zephyr/emul/Kconfig b/zephyr/emul/Kconfig index 8d9c8e42ea..e47232bdd1 100644 --- a/zephyr/emul/Kconfig +++ b/zephyr/emul/Kconfig @@ -70,3 +70,4 @@ config EMUL_BB_RETIMER rsource "Kconfig.ln9310" rsource "Kconfig.lis2dw12" rsource "Kconfig.i2c_mock" +rsource "Kconfig.isl923x" diff --git a/zephyr/emul/Kconfig.isl923x b/zephyr/emul/Kconfig.isl923x new file mode 100644 index 0000000000..bf124ec0a9 --- /dev/null +++ b/zephyr/emul/Kconfig.isl923x @@ -0,0 +1,22 @@ +# 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_ISL923X_EMUL := cros,isl923x-emul + +menuconfig EMUL_ISL923X + bool "ISL923X switchcap emulator" + default $(dt_compat_enabled,$(DT_COMPAT_ISL923X_EMUL)) + depends on I2C_EMUL + help + Enable the ISL923X emulator. This driver uses the emulated I2C bus. It + is used to test the isl923x driver. Emulator API is available in + zephyr/include/emul/emul_isl923x.h + +if EMUL_ISL923X + +module = ISL923X_EMUL +module-str = isl923x_emul +source "subsys/logging/Kconfig.template.log_config" + +endif # EMUL_ISL923X 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) diff --git a/zephyr/include/emul/emul_isl923x.h b/zephyr/include/emul/emul_isl923x.h new file mode 100644 index 0000000000..659b87d59e --- /dev/null +++ b/zephyr/include/emul/emul_isl923x.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_ISL923X_H_ +#define ZEPHYR_INCLUDE_EMUL_EMUL_ISL923X_H_ + +#endif /* ZEPHYR_INCLUDE_EMUL_EMUL_ISL923X_H_ */ diff --git a/zephyr/test/drivers/overlay.dts b/zephyr/test/drivers/overlay.dts index b211d77caa..782345a7be 100644 --- a/zephyr/test/drivers/overlay.dts +++ b/zephyr/test/drivers/overlay.dts @@ -541,6 +541,13 @@ reg = <0x84>; label = "I2C_MOCK"; }; + + isl923x_emul: isl923x@9 { + compatible = "cros,isl923x-emul"; + status = "okay"; + reg = <0x9>; + label = "ISL923X_EMUL"; + }; }; /* Enable all thermistors for testing */ |