summaryrefslogtreecommitdiff
path: root/zephyr
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2022-09-06 18:08:42 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-12 09:57:07 +0000
commit09cfcbbf5f93753f689e7cf1b47b63f17c3e9f36 (patch)
treec3fcff1e6cf310aabf8ec3ee68d31c1dfbc5d85c /zephyr
parent234a3fd7dd115f1ea06d37b9d8cff7bc83ee7871 (diff)
downloadchrome-ec-09cfcbbf5f93753f689e7cf1b47b63f17c3e9f36.tar.gz
zephyr/test: add krabby board test
This CL adds the basic framework code for implementing krabby tests, and also a new test for corsola/src/krabby/charger_workaround.c. BUG=b:243841599 TEST=twister -T zephyr/test/krabby BRANCH=none Signed-off-by: Ting Shen <phoenixshen@google.com> Change-Id: I8703d444b1fedc6b4a7a0c5aefe28a4e09716806 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3873241 Commit-Queue: Ting Shen <phoenixshen@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Tested-by: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'zephyr')
-rw-r--r--zephyr/dts/it8xxx2_emul.dts177
-rw-r--r--zephyr/projects/corsola/src/krabby/charger_workaround.c2
-rw-r--r--zephyr/shim/include/charger/chg_rt9490.h1
-rw-r--r--zephyr/shim/src/charger.c1
-rw-r--r--zephyr/test/krabby/CMakeLists.txt14
-rw-r--r--zephyr/test/krabby/README.md3
-rw-r--r--zephyr/test/krabby/common.dts70
-rw-r--r--zephyr/test/krabby/pinctrl.dts7
-rw-r--r--zephyr/test/krabby/prj.conf36
-rw-r--r--zephyr/test/krabby/src/charger_workaround.c98
-rw-r--r--zephyr/test/krabby/src/stubs.c29
-rw-r--r--zephyr/test/krabby/testcase.yaml9
12 files changed, 446 insertions, 1 deletions
diff --git a/zephyr/dts/it8xxx2_emul.dts b/zephyr/dts/it8xxx2_emul.dts
new file mode 100644
index 0000000000..7165dbb63e
--- /dev/null
+++ b/zephyr/dts/it8xxx2_emul.dts
@@ -0,0 +1,177 @@
+/* Copyright 2022 The ChromiumOS Authors.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Contains emulators for devices normally found on IT8xxx2 chips.
+ * To use, include this file, then the board's gpio definitions.
+ */
+
+#include <dt-bindings/gpio_defines.h>
+
+/ {
+ gpioa: gpio@f01601 {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf01601 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+ gpiob: gpio@f01602 {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf01602 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+ gpioc: gpio@f01603 {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf01603 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+ gpiod: gpio@f01604 {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf01604 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+ gpioe: gpio@f01605 {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf01605 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+ gpiof: gpio@f01606 {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf01606 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+ gpiog: gpio@f01607 {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf01607 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+ gpioh: gpio@f01608 {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf01608 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+ gpioi: gpio@f01609 {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf01609 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+ gpioj: gpio@f0160a {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf0160a 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+ gpiok: gpio@f0160b {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf0160b 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+ gpiol: gpio@f0160c {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf0160c 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+ gpiom: gpio@f0160d {
+ status = "okay";
+ compatible = "zephyr,gpio-emul";
+ reg = <0xf0160d 0x4>;
+ rising-edge;
+ falling-edge;
+ high-level;
+ low-level;
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <8>;
+ };
+
+ i2c_ctrl0: i2c@f01c40 {
+ compatible = "zephyr,i2c-emul-controller";
+ clock-frequency = <I2C_BITRATE_STANDARD>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+ reg = <0xf01c40 0x1000>;
+ };
+};
diff --git a/zephyr/projects/corsola/src/krabby/charger_workaround.c b/zephyr/projects/corsola/src/krabby/charger_workaround.c
index 07a4379737..d44e26eb67 100644
--- a/zephyr/projects/corsola/src/krabby/charger_workaround.c
+++ b/zephyr/projects/corsola/src/krabby/charger_workaround.c
@@ -17,7 +17,7 @@
* Newer project should have all of these fixed.
*/
BUILD_ASSERT(IS_ENABLED(CONFIG_BOARD_KRABBY) ||
- IS_ENABLED(CONFIG_BOARD_TENTACRUEL));
+ IS_ENABLED(CONFIG_BOARD_TENTACRUEL) || IS_ENABLED(CONFIG_TEST));
static void enter_hidden_mode(void)
{
diff --git a/zephyr/shim/include/charger/chg_rt9490.h b/zephyr/shim/include/charger/chg_rt9490.h
index a8424e4db5..f7d57690fd 100644
--- a/zephyr/shim/include/charger/chg_rt9490.h
+++ b/zephyr/shim/include/charger/chg_rt9490.h
@@ -7,6 +7,7 @@
#include "driver/charger/rt9490.h"
#define RT9490_CHG_COMPAT richtek_rt9490
+#define RT9490_EMUL_COMPAT zephyr_rt9490_emul
#define CHG_CONFIG_RT9490(id) \
{ \
diff --git a/zephyr/shim/src/charger.c b/zephyr/shim/src/charger.c
index be8c7615f6..e9677db07c 100644
--- a/zephyr/shim/src/charger.c
+++ b/zephyr/shim/src/charger.c
@@ -25,6 +25,7 @@
CHECK_COMPAT(ISL923X_EMUL_COMPAT, usbc_id, chg_id, CHG_CONFIG_ISL923X) \
CHECK_COMPAT(ISL9241_CHG_COMPAT, usbc_id, chg_id, CHG_CONFIG_ISL9241) \
CHECK_COMPAT(RT9490_CHG_COMPAT, usbc_id, chg_id, CHG_CONFIG_RT9490) \
+ CHECK_COMPAT(RT9490_EMUL_COMPAT, usbc_id, chg_id, CHG_CONFIG_RT9490) \
CHECK_COMPAT(SM5803_CHG_COMPAT, usbc_id, chg_id, CHG_CONFIG_SM5803)
#define CHG_CHIP(usbc_id) \
diff --git a/zephyr/test/krabby/CMakeLists.txt b/zephyr/test/krabby/CMakeLists.txt
new file mode 100644
index 0000000000..6c70116d9f
--- /dev/null
+++ b/zephyr/test/krabby/CMakeLists.txt
@@ -0,0 +1,14 @@
+# Copyright 2022 The ChromiumOS Authors.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+cmake_minimum_required(VERSION 3.13.1)
+find_package(Zephyr REQUIRED HINTS "${ZEPHYR_BASE}")
+project(krabby)
+
+zephyr_include_directories("${PLATFORM_EC}/zephyr/projects/corsola/include")
+
+target_sources(app PRIVATE
+ src/charger_workaround.c
+ src/stubs.c
+ ${PLATFORM_EC}/zephyr/projects/corsola/src/krabby/charger_workaround.c)
diff --git a/zephyr/test/krabby/README.md b/zephyr/test/krabby/README.md
new file mode 100644
index 0000000000..8262d85fcc
--- /dev/null
+++ b/zephyr/test/krabby/README.md
@@ -0,0 +1,3 @@
+Tests for board specific code under `zephyr/projects/corsola/src/krabby`.
+
+Run with ./twister -T zephyr/test/krabby
diff --git a/zephyr/test/krabby/common.dts b/zephyr/test/krabby/common.dts
new file mode 100644
index 0000000000..b5971b75e1
--- /dev/null
+++ b/zephyr/test/krabby/common.dts
@@ -0,0 +1,70 @@
+/* Copyright 2022 The ChromiumOS Authors.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <it8xxx2_emul.dts>
+
+/ {
+ pinctrl: pinctrl {
+ compatible = "ite,it8xxx2-pinctrl";
+ status = "disabled";
+ };
+
+ named-i2c-ports {
+ compatible = "named-i2c-ports";
+
+ i2c_charger: charger {
+ i2c-port = <&i2c_ctrl0>;
+ enum-names = "I2C_PORT_CHARGER",
+ "I2C_PORT_BATTERY";
+ };
+ };
+
+ usbc {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ port0@0 {
+ compatible = "named-usbc-port";
+ status = "okay";
+ reg = <0>;
+ chg = <&charger>;
+ tcpc = <&tcpci_emul>;
+ };
+ };
+
+ batteries {
+ default_battery: lgc_ac17a8m {
+ compatible = "lgc,ac17a8m", "battery-smart";
+ };
+ };
+};
+
+&i2c_ctrl0 {
+ status="okay";
+
+ charger: rt9490@53 {
+ compatible = "zephyr,rt9490-emul";
+ status = "okay";
+ reg = <0x53>;
+ };
+
+ battery: sb@b {
+ compatible = "zephyr,smart-battery";
+ reg = <0xb>;
+ cycle-count = <99>;
+ version = "BATTERY_SPEC_VER_1_1_WITH_PEC";
+ /* Real battery voltages are multiples of 4.4V. */
+ desired-charg-volt = <5000>;
+ desired-charg-cur = <1000>;
+ mf-name = "LGC";
+ dev-name = "AC17A8M";
+ };
+
+ tcpci_emul: tcpci_emul@82 {
+ compatible = "cros,tcpci-generic-emul";
+ status = "okay";
+ reg = <0x82>;
+ };
+};
diff --git a/zephyr/test/krabby/pinctrl.dts b/zephyr/test/krabby/pinctrl.dts
new file mode 100644
index 0000000000..295b652351
--- /dev/null
+++ b/zephyr/test/krabby/pinctrl.dts
@@ -0,0 +1,7 @@
+/* Copyright 2022 The ChromiumOS Authors.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* remove pinctrl to avoid pull in too many unwanted dependency */
+/delete-node/ &pinctrl;
diff --git a/zephyr/test/krabby/prj.conf b/zephyr/test/krabby/prj.conf
new file mode 100644
index 0000000000..02e10421bc
--- /dev/null
+++ b/zephyr/test/krabby/prj.conf
@@ -0,0 +1,36 @@
+# Copyright 2022 The ChromiumOS Authors.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+CONFIG_ZTEST=y
+CONFIG_ZTEST_ASSERT_VERBOSE=1
+CONFIG_ZTEST_NEW_API=y
+
+CONFIG_ASSERT=y
+CONFIG_CROS_EC=y
+CONFIG_EMUL=y
+CONFIG_EMUL_RT9490=y
+CONFIG_EMUL_SMART_BATTERY=y
+CONFIG_EMUL_TCPCI=y
+CONFIG_I2C=y
+CONFIG_I2C_EMUL=y
+CONFIG_SHIMMED_TASKS=y
+
+CONFIG_PLATFORM_EC=y
+CONFIG_PLATFORM_EC_BACKLIGHT_LID=n
+CONFIG_PLATFORM_EC_BATTERY=y
+CONFIG_PLATFORM_EC_BATTERY_FUEL_GAUGE=y
+CONFIG_PLATFORM_EC_BATTERY_PRESENT_GPIO=y
+CONFIG_PLATFORM_EC_CHARGER=y
+CONFIG_PLATFORM_EC_CHARGER_RT9490=y
+CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR=10
+CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR_AC=20
+CONFIG_PLATFORM_EC_CHARGE_MANAGER=n
+CONFIG_PLATFORM_EC_HOOKS=y
+CONFIG_PLATFORM_EC_HOSTCMD=y
+CONFIG_PLATFORM_EC_LID_SWITCH=n
+CONFIG_PLATFORM_EC_SWITCH=n
+CONFIG_PLATFORM_EC_USBC=n
+CONFIG_PLATFORM_EC_USB_CHARGER=n
+CONFIG_PLATFORM_EC_USB_POWER_DELIVERY=n
+CONFIG_PLATFORM_EC_VBOOT_HASH=n
diff --git a/zephyr/test/krabby/src/charger_workaround.c b/zephyr/test/krabby/src/charger_workaround.c
new file mode 100644
index 0000000000..da53374b8f
--- /dev/null
+++ b/zephyr/test/krabby/src/charger_workaround.c
@@ -0,0 +1,98 @@
+/* Copyright 2022 The ChromiumOS Authors.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <zephyr/devicetree.h>
+#include <zephyr/drivers/emul.h>
+#include <zephyr/fff.h>
+#include <zephyr/ztest.h>
+
+#include "charger.h"
+#include "driver/charger/rt9490.h"
+#include "emul/emul_rt9490.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "system.h"
+
+DEFINE_FFF_GLOBALS;
+
+FAKE_VALUE_FUNC(int, board_get_version);
+
+const struct emul *emul = EMUL_DT_GET(DT_NODELABEL(charger));
+
+static bool ibus_adc_workaround_called(void)
+{
+ return rt9490_emul_peek_reg(emul, 0x52) == 0xC4;
+}
+
+static bool i2c_speed_workaround_called(void)
+{
+ return rt9490_emul_peek_reg(emul, 0x71) == 0x22;
+}
+
+static bool eoc_deglitch_workaround_called(void)
+{
+ return !(rt9490_emul_peek_reg(emul, RT9490_REG_ADD_CTRL0) &
+ RT9490_TD_EOC);
+}
+
+static bool disable_safety_timer_called(void)
+{
+ return rt9490_emul_peek_reg(emul, RT9490_REG_SAFETY_TMR_CTRL) ==
+ (RT9490_EN_TRICHG_TMR | RT9490_EN_PRECHG_TMR |
+ RT9490_EN_FASTCHG_TMR);
+}
+
+ZTEST(charger_workaround, test_board_version_0)
+{
+ board_get_version_fake.return_val = 0;
+
+ hook_notify(HOOK_INIT);
+ zassert_true(ibus_adc_workaround_called(), NULL);
+ zassert_true(i2c_speed_workaround_called(), NULL);
+ zassert_false(eoc_deglitch_workaround_called(), NULL);
+ zassert_true(disable_safety_timer_called(), NULL);
+}
+
+ZTEST(charger_workaround, test_board_version_1)
+{
+ board_get_version_fake.return_val = 1;
+
+ hook_notify(HOOK_INIT);
+ zassert_false(ibus_adc_workaround_called(), NULL);
+ zassert_true(i2c_speed_workaround_called(), NULL);
+ zassert_true(eoc_deglitch_workaround_called(), NULL);
+ zassert_true(disable_safety_timer_called(), NULL);
+}
+
+ZTEST(charger_workaround, test_board_version_2)
+{
+ board_get_version_fake.return_val = 2;
+
+ hook_notify(HOOK_INIT);
+ zassert_false(ibus_adc_workaround_called(), NULL);
+ zassert_true(i2c_speed_workaround_called(), NULL);
+ zassert_false(eoc_deglitch_workaround_called(), NULL);
+ zassert_false(disable_safety_timer_called(), NULL);
+}
+
+ZTEST(charger_workaround, test_board_version_3)
+{
+ board_get_version_fake.return_val = 3;
+
+ hook_notify(HOOK_INIT);
+ zassert_false(ibus_adc_workaround_called(), NULL);
+ zassert_false(i2c_speed_workaround_called(), NULL);
+ zassert_false(eoc_deglitch_workaround_called(), NULL);
+ zassert_false(disable_safety_timer_called(), NULL);
+}
+
+static void charge_workaround_before(void *fixture)
+{
+ RESET_FAKE(board_get_version);
+ rt9490_emul_reset_regs(emul);
+}
+
+ZTEST_SUITE(charger_workaround, NULL, NULL, charge_workaround_before, NULL,
+ NULL);
diff --git a/zephyr/test/krabby/src/stubs.c b/zephyr/test/krabby/src/stubs.c
new file mode 100644
index 0000000000..233b4d8bee
--- /dev/null
+++ b/zephyr/test/krabby/src/stubs.c
@@ -0,0 +1,29 @@
+/* Copyright 2022 The ChromiumOS Authors.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "charge_ramp.h"
+#include "charge_state.h"
+
+int board_set_active_charge_port(int port)
+{
+ return 0;
+}
+
+int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state)
+{
+ return 0;
+}
+
+void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
+ int charge_mv)
+{
+}
+
+const struct batt_params *charger_current_battery_params(void)
+{
+ static const struct batt_params params = {};
+
+ return &params;
+}
diff --git a/zephyr/test/krabby/testcase.yaml b/zephyr/test/krabby/testcase.yaml
new file mode 100644
index 0000000000..4ec2ae13a2
--- /dev/null
+++ b/zephyr/test/krabby/testcase.yaml
@@ -0,0 +1,9 @@
+# Copyright 2022 The ChromiumOS Authors.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+common:
+ platform_allow: native_posix
+tests:
+ krabby.default:
+ extra_args: DTC_OVERLAY_FILE="common.dts;../projects/corsola/interrupts_krabby.dts;../projects/corsola/gpio_krabby.dts;pinctrl.dts"