summaryrefslogtreecommitdiff
path: root/zephyr/test/kingler
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2022-09-21 14:08:36 -0700
committerTom Hughes <tomhughes@chromium.org>2022-09-22 12:59:38 -0700
commitc453fd704268ef72de871b0c5ac7a989de662334 (patch)
treefcf6ce5810f9ff9e3c8cce434812dd75492269ed /zephyr/test/kingler
parent6c1587ca70f558b4f96b3f0b18ad8b027d3ba99d (diff)
parent28712dae9d7ed1e694f7622cc083afa71090d4d5 (diff)
downloadchrome-ec-firmware-fpmcu-dartmonkey-release.tar.gz
Merge remote-tracking branch cros/main into firmware-fpmcu-dartmonkey-releasefirmware-fpmcu-dartmonkey-release
Generated by: ./util/update_release_branch.py --board dartmonkey --relevant_paths_file ./util/fingerprint-relevant-paths.txt firmware-fpmcu-dartmonkey-release Relevant changes: git log --oneline 6c1587ca70..28712dae9d -- board/nocturne_fp board/dartmonkey common/fpsensor docs/fingerprint driver/fingerprint util/getversion.sh ded9307b79 util/getversion.sh: Fix version when not in a git repo 956055e692 board: change Google USB vendor info 71b2ef709d Update license boilerplate text in source code files 33e11afda0 Revert "fpsensor: Build fpsensor source file with C++" c8d0360723 fpsensor: Build fpsensor source file with C++ bc113abd53 fpsensor: Fix g++ compiler error 150a58a0dc fpsensor: Fix fp_set_sensor_mode return type b33b5ce85b fpsensor: Remove nested designators for C++ compatibility 2e864b2539 tree-wide: const-ify argv for console commands 56d8b360f9 test: Add test for get ikm failure when seed not set 3a3d6c3690 test: Add test for fpsensor trivial key failure 233e6bbd08 fpsensor_crypto: Abstract calls to hmac_SHA256 0a041b285b docs/fingerprint: Typo correction c03fab67e2 docs/fingerprint: Fix the path of fputils.py 0b5d4baf5a util/getversion.sh: Fix empty file list handling 6e128fe760 FPMCU dev board environment with Satlab 3eb29b6aa5 builtin: Move ssize_t to sys/types.h 345d62ebd1 docs/fingerprint: Update power numbers for latest dartmonkey release c25ffdb316 common: Conditionally support printf %l and %i modifiers 9a3c514b45 test: Add a test to check if the debugger is connected 54e603413f Move standard library tests to their own file 43fa6b4bf8 docs/fingerprint: Update power numbers for latest bloonchipper release 25536f9a84 driver/fingerprint/fpc/bep/fpc_sensor_spi.c: Format with clang-format 4face99efd driver/fingerprint/fpc/libfp/fpc_sensor_pal.h: Format with clang-format 738de2b575 trng: Rename rand to trng_rand 14b8270edd docs/fingerprint: Update dragonclaw power numbers 0b268f93d1 driver/fingerprint/fpc/libfp/fpc_private.c: Format with clang-format f80da163f2 driver/fingerprint/fpc/libfp/fpc_private.h: Format with clang-format a0751778f4 board/nocturne_fp/ro_workarounds.c: Format with clang-format 5e9c85c9b1 driver/fingerprint/fpc/libfp/fpc_sensor_pal.c: Format with clang-format c1f9dd3cf8 driver/fingerprint/fpc/libfp/fpc_bio_algorithm.h: Format with clang-format eb1e1bed8d driver/fingerprint/fpc/libfp/fpc1145_private.h: Format with clang-format 6e7b611821 driver/fingerprint/fpc/bep/fpc_bio_algorithm.h: Format with clang-format e0589cd5e2 driver/fingerprint/fpc/bep/fpc1035_private.h: Format with clang-format 58f0246dbe board/nocturne_fp/board_ro.c: Format with clang-format 7905e556a0 common/fpsensor/fpsensor_crypto.c: Format with clang-format 21289d170c driver/fingerprint/fpc/bep/fpc1025_private.h: Format with clang-format 98a20f937e common/fpsensor/fpsensor_state.c: Format with clang-format a2d255d8af common/fpsensor/fpsensor.c: Format with clang-format 84e53a65da board/nocturne_fp/board.h: Format with clang-format 73055eeb3f driver/fingerprint/fpc/bep/fpc_private.c: Format with clang-format 0f7b5cb509 common/fpsensor/fpsensor_private.h: Format with clang-format 1ceade6e65 driver/fingerprint/fpc/bep/fpc_private.h: Format with clang-format dca9d74321 Revert "trng: Rename rand to trng_rand" a6b0b3554f trng: Rename rand to trng_rand 28d0b75b70 third_party/boringssl: Remove unused header BRANCH=None BUG=b:244387210 b:242720240 b:215613183 b:242720910 b:236386294 BUG=b:234181908 b:244781166 b:234781655 b:234143158 b:234181908 BUG=b:237344361 b:236025198 b:234181908 b:180945056 chromium:1098010 BUG=b:246424843 b:234181908 b:131913998 TEST=`make -j buildall` TEST=./util/run_device_tests.py --board dartmonkey Test "aes": PASSED Test "cec": PASSED Test "cortexm_fpu": PASSED Test "crc": PASSED Test "flash_physical": PASSED Test "flash_write_protect": PASSED Test "fpsensor_hw": PASSED Test "fpsensor_spi_ro": PASSED Test "fpsensor_spi_rw": PASSED Test "fpsensor_uart_ro": PASSED Test "fpsensor_uart_rw": PASSED Test "mpu_ro": PASSED Test "mpu_rw": PASSED Test "mutex": PASSED Test "pingpong": PASSED Test "printf": PASSED Test "queue": PASSED Test "rollback_region0": PASSED Test "rollback_region1": PASSED Test "rollback_entropy": PASSED Test "rtc": PASSED Test "sha256": PASSED Test "sha256_unrolled": PASSED Test "static_if": PASSED Test "stdlib": PASSED Test "system_is_locked_wp_on": PASSED Test "system_is_locked_wp_off": PASSED Test "timer_dos": PASSED Test "utils": PASSED Test "utils_str": PASSED Test "panic_data_dartmonkey_v2.0.2887": PASSED Test "panic_data_nocturne_fp_v2.2.64": PASSED Test "panic_data_nami_fp_v2.2.144": PASSED Force-Relevant-Builds: all Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I2c312583a709fedae8fe11d92c22328c3b634bc7
Diffstat (limited to 'zephyr/test/kingler')
-rw-r--r--zephyr/test/kingler/CMakeLists.txt26
-rw-r--r--zephyr/test/kingler/Kconfig45
-rw-r--r--zephyr/test/kingler/README.md3
-rw-r--r--zephyr/test/kingler/common.dts155
-rw-r--r--zephyr/test/kingler/prj.conf31
-rw-r--r--zephyr/test/kingler/src/clamshell.c89
-rw-r--r--zephyr/test/kingler/src/db_detect_hdmi.c83
-rw-r--r--zephyr/test/kingler/src/db_detect_none.c79
-rw-r--r--zephyr/test/kingler/src/db_detect_typec.c85
-rw-r--r--zephyr/test/kingler/src/fakes.c29
-rw-r--r--zephyr/test/kingler/src/tablet.c91
-rw-r--r--zephyr/test/kingler/testcase.yaml32
12 files changed, 748 insertions, 0 deletions
diff --git a/zephyr/test/kingler/CMakeLists.txt b/zephyr/test/kingler/CMakeLists.txt
new file mode 100644
index 0000000000..b572e67fb5
--- /dev/null
+++ b/zephyr/test/kingler/CMakeLists.txt
@@ -0,0 +1,26 @@
+# 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(kingler)
+
+zephyr_include_directories("${PLATFORM_EC}/zephyr/projects/corsola/include")
+
+target_sources(app PRIVATE src/fakes.c)
+
+target_sources_ifdef(CONFIG_TEST_STEELIX_RUSTY
+app PRIVATE ${PLATFORM_EC}/zephyr/projects/corsola/src/kingler/board_steelix.c)
+target_sources_ifdef(CONFIG_TEST_FORM_FACTOR_CONVERTIBLE
+ app PRIVATE src/tablet.c)
+target_sources_ifdef(CONFIG_TEST_FORM_FACTOR_CLAMSHELL
+ app PRIVATE src/clamshell.c)
+target_sources_ifdef(CONFIG_VARIANT_CORSOLA_DB_DETECTION
+app PRIVATE ${PLATFORM_EC}/zephyr/projects/corsola/src/variant_db_detection.c)
+target_sources_ifdef(CONFIG_TEST_DB_DETECT_TYPEC
+ app PRIVATE src/db_detect_typec.c)
+target_sources_ifdef(CONFIG_TEST_DB_DETECT_HDMI
+ app PRIVATE src/db_detect_hdmi.c)
+target_sources_ifdef(CONFIG_TEST_DB_DETECT_NONE
+ app PRIVATE src/db_detect_none.c)
diff --git a/zephyr/test/kingler/Kconfig b/zephyr/test/kingler/Kconfig
new file mode 100644
index 0000000000..af52042cb6
--- /dev/null
+++ b/zephyr/test/kingler/Kconfig
@@ -0,0 +1,45 @@
+# 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 TEST_STEELIX_RUSTY
+ bool "Run the tests intended for steelix and rusty"
+ help
+ Include board_steelix.c into the binary to test the clamshell and
+ convertible.
+
+config TEST_FORM_FACTOR_CLAMSHELL
+ bool "Run the tests intended for clamshells"
+ help
+ Include clamshell tests into the binary.
+
+config TEST_FORM_FACTOR_CONVERTIBLE
+ bool "Run the tests intended for convertibles"
+ help
+ Include convertible tests into the binary.
+
+config VARIANT_CORSOLA_DB_DETECTION
+ bool "Run the tests intended for corsola DB detection"
+ help
+ Include variant_db_detection.c into the binary to test the type-c DB
+ tests, HDMI DB tests and none DB tests.
+
+config TEST_DB_DETECT_TYPEC
+ bool "Run the tests intended for type-c DB"
+ help
+ Include type-c DB tests into the binary.
+ test for DB GPIOs and interrupt.
+
+config TEST_DB_DETECT_HDMI
+ bool "Run the tests intended for HDMI DB"
+ help
+ Include HDMI DB tests into the binary.
+ test for DB GPIOs and interrupt.
+
+config TEST_DB_DETECT_NONE
+ bool "Run the tests intended for none DB"
+ help
+ Include none DB tests into the binary.
+ test for DB GPIOs and interrupt.
+
+source "Kconfig.zephyr"
diff --git a/zephyr/test/kingler/README.md b/zephyr/test/kingler/README.md
new file mode 100644
index 0000000000..bac3afced2
--- /dev/null
+++ b/zephyr/test/kingler/README.md
@@ -0,0 +1,3 @@
+Tests for board specific code under `zephyr/projects/corsola/src/kingler`.
+
+Run with ./twister -T zephyr/test/kingler
diff --git a/zephyr/test/kingler/common.dts b/zephyr/test/kingler/common.dts
new file mode 100644
index 0000000000..e065da896a
--- /dev/null
+++ b/zephyr/test/kingler/common.dts
@@ -0,0 +1,155 @@
+/* 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 <board-overlays/native_posix.dts>
+#include <npcx_emul.dts>
+
+/ {
+ /* These are temporary just to get the test to build.
+ * Should be replaced with the correct accel drivers,
+ * but we're not testing that code right now anyway.
+ */
+ motionsense-sensor-data {
+ bmi160_data: bmi160-drv-data {
+ compatible = "cros-ec,drvdata-bmi160";
+ status = "okay";
+ };
+ };
+ motionsense-sensor {
+ base_accel: ms-bmi160-accel {
+ compatible = "cros-ec,bmi160-accel";
+ status = "okay";
+
+ active-mask = "SENSOR_ACTIVE_S0_S3_S5";
+ location = "MOTIONSENSE_LOC_BASE";
+ drv-data = <&bmi160_data>;
+ default-range = <4>;
+ i2c-spi-addr-flags = "BMI160_ADDR0_FLAGS";
+ };
+ lid_accel: ms-bmi160-accel2 {
+ compatible = "cros-ec,bmi160-accel";
+ status = "okay";
+
+ active-mask = "SENSOR_ACTIVE_S0_S3_S5";
+ location = "MOTIONSENSE_LOC_BASE";
+ drv-data = <&bmi160_data>;
+ default-range = <4>;
+ i2c-spi-addr-flags = "BMI160_ADDR0_FLAGS";
+ };
+ };
+ motionsense-sensor-info {
+ compatible = "cros-ec,motionsense-sensor-info";
+
+ /*
+ * list of GPIO interrupts that have to
+ * be enabled at initial stage
+ */
+ sensor-irqs = <&int_base_imu>;
+ /* list of sensors in force mode */
+ accel-force-mode-sensors = <&lid_accel>;
+ };
+ named-i2c-ports {
+ compatible = "named-i2c-ports";
+ i2c_sensor: sensor {
+ i2c-port = <&i2c0_0>;
+ enum-names = "I2C_PORT_SENSOR";
+ };
+ i2c_eeprom: sensor {
+ i2c-port = <&i2c3_0>;
+ enum-names = "I2C_PORT_EEPROM";
+ };
+ };
+ /* TODO(jbettis): Move the i2c ports and pinctrls to npcx_emul.dts,
+ * and add all of them instead of just these.
+ */
+ soc-if {
+ i2c0_0: io_i2c_ctrl0_port0 {
+ compatible = "nuvoton,npcx-i2c-port";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ port = <0x00>;
+ controller = <&i2c_ctrl0>;
+ status = "disabled";
+ };
+ i2c3_0: io_i2c_ctrl3_port0 {
+ compatible = "nuvoton,npcx-i2c-port";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ port = <0x30>;
+ controller = <&i2c_ctrl3>;
+ status = "disabled";
+ };
+ };
+ pinctrl: pinctrl {
+ compatible = "nuvoton,npcx-pinctrl";
+ status = "okay";
+ /* I2C peripheral interfaces */
+ /omit-if-no-ref/ i2c0_0_sda_scl_gpb4_b5: periph-i2c0-0 {
+ pinmux = <&alt2_i2c0_0_sl>;
+ periph-pupd = <0x00 0>;
+ };
+ /omit-if-no-ref/ i2c3_0_sda_scl_gpd0_d1: periph-i2c3-0 {
+ pinmux = <&alt2_i2c3_0_sl>;
+ periph-pupd = <0x00 6>;
+ };
+ };
+ npcx-alts-map {
+ compatible = "nuvoton,npcx-pinctrl-conf";
+ /* SCFG DEVALT 2 */
+ alt2_i2c0_0_sl: alt20 {
+ alts = <&scfg 0x02 0x0 0>;
+ };
+ alt2_i2c3_0_sl: alt26 {
+ alts = <&scfg 0x02 0x6 0>;
+ };
+ };
+};
+
+&i2c0_0 {
+ status = "okay";
+ clock-frequency = <I2C_BITRATE_FAST>;
+ pinctrl-0 = <&i2c0_0_sda_scl_gpb4_b5>;
+ pinctrl-names = "default";
+};
+
+&i2c_ctrl0 {
+ status = "okay";
+};
+
+&i2c_ctrl2 {
+ status = "okay";
+};
+
+i2c_pwr_cbi: &i2c3_0 {
+ status = "okay";
+ clock-frequency = <I2C_BITRATE_FAST>;
+ pinctrl-0 = <&i2c3_0_sda_scl_gpd0_d1>;
+ pinctrl-names = "default";
+
+ charger: isl923x@9 {
+ compatible = "intersil,isl923x";
+ status = "okay";
+ reg = <0x9>;
+ };
+};
+
+&i2c_ctrl3 {
+ status = "okay";
+};
+
+&i2c_ctrl5 {
+ status = "okay";
+};
+
+&i2c_ctrl3 {
+ cbi_eeprom: eeprom@50 {
+ compatible = "atmel,at24";
+ reg = <0x50>;
+ size = <2048>;
+ pagesize = <16>;
+ address-width = <8>;
+ timeout = <5>;
+ };
+};
diff --git a/zephyr/test/kingler/prj.conf b/zephyr/test/kingler/prj.conf
new file mode 100644
index 0000000000..dfa1c68d4d
--- /dev/null
+++ b/zephyr/test/kingler/prj.conf
@@ -0,0 +1,31 @@
+# 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_EMUL=y
+CONFIG_PLATFORM_EC_HOOKS=y
+
+CONFIG_CROS_EC=y
+CONFIG_PLATFORM_EC=y
+CONFIG_SHIMMED_TASKS=y
+
+CONFIG_PLATFORM_EC_MOTIONSENSE=y
+CONFIG_PLATFORM_EC_DYNAMIC_MOTION_SENSOR_COUNT=y
+CONFIG_PLATFORM_EC_GMR_TABLET_MODE=y
+CONFIG_PLATFORM_EC_TABLET_MODE=y
+CONFIG_PLATFORM_EC_LID_ANGLE=y
+
+CONFIG_I2C=y
+CONFIG_I2C_NPCX=n
+
+CONFIG_PLATFORM_EC_CBI_EEPROM=y
+CONFIG_PLATFORM_EC_BOARD_VERSION_CBI=y
+CONFIG_EEPROM=y
+CONFIG_EEPROM_AT24=y
+CONFIG_EEPROM_SIMULATOR=n
+CONFIG_EMUL_EEPROM_AT2X=y
+CONFIG_EEPROM_SHELL=n
diff --git a/zephyr/test/kingler/src/clamshell.c b/zephyr/test/kingler/src/clamshell.c
new file mode 100644
index 0000000000..88595cc114
--- /dev/null
+++ b/zephyr/test/kingler/src/clamshell.c
@@ -0,0 +1,89 @@
+/* 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/kernel.h"
+#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/ztest.h>
+
+#include "cros_board_info.h"
+#include "cros_cbi.h"
+#include "gpio_signal.h"
+#include "hooks.h"
+#include "tablet_mode.h"
+
+static void *clamshell_setup(void)
+{
+ uint32_t val;
+ const struct device *wp_gpio =
+ DEVICE_DT_GET(DT_GPIO_CTLR(DT_ALIAS(gpio_wp), gpios));
+ const gpio_port_pins_t wp_pin = DT_GPIO_PIN(DT_ALIAS(gpio_wp), gpios);
+
+ /* Make sure that write protect is disabled */
+ zassert_ok(gpio_emul_input_set(wp_gpio, wp_pin, 1), NULL);
+ /* Set CBI form factor to CONVERTIBLE. */
+ zassert_ok(cbi_set_fw_config(CLAMSHELL << 13), NULL);
+ /* Run init hooks to initialize cbi. */
+ hook_notify(HOOK_INIT);
+
+ /* Check if CBI write worked. */
+ zassert_ok(cros_cbi_get_fw_config(FORM_FACTOR, &val), NULL);
+ zassert_equal(CLAMSHELL, val, "val=%d", val);
+
+ return NULL;
+}
+
+ZTEST_SUITE(steelix_clamshell, NULL, clamshell_setup, NULL, NULL, NULL);
+
+ZTEST(steelix_clamshell, test_gmr_tablet_switch_disabled)
+{
+ const struct device *tablet_mode_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_tablet_mode_l), gpios));
+ const gpio_port_pins_t tablet_mode_pin =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_tablet_mode_l), gpios);
+
+ /* Verify gmr_tablet_switch is disabled, by checking the side effects
+ * of calling tablet_set_mode, and setting gpio_tablet_mode_l.
+ */
+ zassert_ok(gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 0),
+ NULL);
+ k_sleep(K_MSEC(100));
+ tablet_set_mode(1, TABLET_TRIGGER_LID);
+ zassert_equal(0, tablet_get_mode(), NULL);
+ zassert_ok(gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 1),
+ NULL);
+ k_sleep(K_MSEC(100));
+ tablet_set_mode(0, TABLET_TRIGGER_LID);
+ zassert_equal(0, tablet_get_mode(), NULL);
+ zassert_ok(gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 0),
+ NULL);
+ k_sleep(K_MSEC(100));
+ tablet_set_mode(1, TABLET_TRIGGER_LID);
+ zassert_equal(0, tablet_get_mode(), NULL);
+}
+
+static int interrupt_count;
+
+void bmi3xx_interrupt(enum gpio_signal signal)
+{
+ interrupt_count++;
+}
+
+ZTEST(steelix_clamshell, test_base_imu_irq_disabled)
+{
+ const struct device *base_imu_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(base_imu_int_l), gpios));
+ const gpio_port_pins_t base_imu_pin =
+ DT_GPIO_PIN(DT_NODELABEL(base_imu_int_l), gpios);
+
+ /* Verify base_imu_irq is disabled. */
+ interrupt_count = 0;
+ zassert_ok(gpio_emul_input_set(base_imu_gpio, base_imu_pin, 1), NULL);
+ k_sleep(K_MSEC(100));
+ zassert_ok(gpio_emul_input_set(base_imu_gpio, base_imu_pin, 0), NULL);
+ k_sleep(K_MSEC(100));
+
+ zassert_equal(interrupt_count, 0, "interrupt_count=%d",
+ interrupt_count);
+}
diff --git a/zephyr/test/kingler/src/db_detect_hdmi.c b/zephyr/test/kingler/src/db_detect_hdmi.c
new file mode 100644
index 0000000000..35cf92ae5e
--- /dev/null
+++ b/zephyr/test/kingler/src/db_detect_hdmi.c
@@ -0,0 +1,83 @@
+/* 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/kernel.h"
+#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/ztest.h>
+
+#include "gpio_signal.h"
+#include "hooks.h"
+#include "variant_db_detection.h"
+
+static void *db_detection_setup(void)
+{
+ const struct device *hdmi_prsnt_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_hdmi_prsnt_odl), gpios));
+ const gpio_port_pins_t hdmi_prsnt_pin =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_hdmi_prsnt_odl), gpios);
+ /* Set the GPIO to low to indicate the DB is HDMI */
+ zassert_ok(gpio_emul_input_set(hdmi_prsnt_gpio, hdmi_prsnt_pin, 0),
+ NULL);
+
+ hook_notify(HOOK_INIT);
+
+ return NULL;
+}
+
+ZTEST_SUITE(db_detection, NULL, db_detection_setup, NULL, NULL, NULL);
+
+static int interrupt_count;
+void x_ec_interrupt(enum gpio_signal signal)
+{
+ interrupt_count++;
+}
+
+/* test hdmi db case */
+ZTEST(db_detection, test_db_detect_hdmi)
+{
+ const struct device *en_hdmi_gpio =
+ DEVICE_DT_GET(DT_GPIO_CTLR(DT_ALIAS(gpio_en_hdmi_pwr), gpios));
+ const gpio_port_pins_t en_hdmi_pin =
+ DT_GPIO_PIN(DT_ALIAS(gpio_en_hdmi_pwr), gpios);
+ const struct device *ps185_pwrdn_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_ALIAS(gpio_ps185_pwrdn_odl), gpios));
+ const gpio_port_pins_t ps185_pwrdn_pin =
+ DT_GPIO_PIN(DT_ALIAS(gpio_ps185_pwrdn_odl), gpios);
+ const struct device *int_x_ec_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_x_ec_gpio2), gpios));
+ const gpio_port_pins_t int_x_ec_pin =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_x_ec_gpio2), gpios);
+
+ /* Check the DB type is HDMI */
+ zassert_equal(CORSOLA_DB_HDMI, corsola_get_db_type(), NULL);
+
+ /* Verify we can enable or disable hdmi power */
+ zassert_ok(gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_en_hdmi_pwr), 1),
+ NULL);
+ zassert_equal(1, gpio_emul_output_get(en_hdmi_gpio, en_hdmi_pin), NULL);
+ zassert_ok(gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_en_hdmi_pwr), 0),
+ NULL);
+ zassert_equal(0, gpio_emul_output_get(en_hdmi_gpio, en_hdmi_pin), NULL);
+
+ /* Verify we can change the gpio_ps185_pwrdn_odl state */
+ zassert_ok(gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_ps185_pwrdn_odl), 1),
+ NULL);
+ zassert_equal(1,
+ gpio_emul_output_get(ps185_pwrdn_gpio, ps185_pwrdn_pin),
+ NULL);
+ zassert_ok(gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_ps185_pwrdn_odl), 0),
+ NULL);
+ zassert_equal(0,
+ gpio_emul_output_get(ps185_pwrdn_gpio, ps185_pwrdn_pin),
+ NULL);
+
+ /* Verify x_ec_interrupt is enabled */
+ interrupt_count = 0;
+ zassert_ok(gpio_emul_input_set(int_x_ec_gpio, int_x_ec_pin, 1), NULL);
+ k_sleep(K_MSEC(100));
+
+ zassert_equal(interrupt_count, 1, "interrupt_count=%d",
+ interrupt_count);
+}
diff --git a/zephyr/test/kingler/src/db_detect_none.c b/zephyr/test/kingler/src/db_detect_none.c
new file mode 100644
index 0000000000..9f37db04af
--- /dev/null
+++ b/zephyr/test/kingler/src/db_detect_none.c
@@ -0,0 +1,79 @@
+/* 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 <stdlib.h>
+#include <zephyr/kernel.h>
+#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/ztest.h>
+
+#include "cros_board_info.h"
+#include "cros_cbi.h"
+#include "gpio_signal.h"
+#include "hooks.h"
+#include "variant_db_detection.h"
+
+static void *db_detection_setup(void)
+{
+ const struct device *wp_gpio =
+ DEVICE_DT_GET(DT_GPIO_CTLR(DT_ALIAS(gpio_wp), gpios));
+ const gpio_port_pins_t wp_pin = DT_GPIO_PIN(DT_ALIAS(gpio_wp), gpios);
+
+ /* Make sure that write protect is disabled */
+ zassert_ok(gpio_emul_input_set(wp_gpio, wp_pin, 1), NULL);
+ /* Set CBI db_config to DB_NONE. */
+ zassert_ok(cbi_set_fw_config(DB_NONE << 0), NULL);
+ /* Run init hooks to initialize cbi. */
+ hook_notify(HOOK_INIT);
+ return NULL;
+}
+
+ZTEST_SUITE(db_detection, NULL, db_detection_setup, NULL, NULL, NULL);
+
+static int interrupt_count;
+void x_ec_interrupt(enum gpio_signal signal)
+{
+ interrupt_count++;
+}
+
+/* test none db case */
+ZTEST(db_detection, test_db_detect_none)
+{
+ gpio_flags_t *flags = (gpio_flags_t *)malloc(sizeof(gpio_flags_t));
+
+ const struct device *ec_x_gpio1 = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_ec_x_gpio1), gpios));
+ gpio_pin_t ec_x_pin1 =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_ec_x_gpio1), gpios);
+ const struct device *x_ec_gpio2 = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_x_ec_gpio2), gpios));
+ gpio_pin_t x_ec_pin2 =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_x_ec_gpio2), gpios);
+ const struct device *ec_x_gpio3 = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_ec_x_gpio3), gpios));
+ gpio_pin_t ec_x_pin3 =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_ec_x_gpio3), gpios);
+
+ /* Check the DB type is NONE */
+ zassert_equal(CORSOLA_DB_NONE, corsola_get_db_type(), NULL);
+
+ /* Verify the floating pins are input with PU to prevent leakage */
+ zassert_ok(gpio_emul_flags_get(ec_x_gpio1, ec_x_pin1, flags), NULL);
+ zassert_equal(*flags, (GPIO_INPUT | GPIO_PULL_UP), "flags=%d", *flags);
+ zassert_ok(gpio_emul_flags_get(x_ec_gpio2, x_ec_pin2, flags), NULL);
+ zassert_equal(*flags, (GPIO_INPUT | GPIO_PULL_UP), "flags=%d", *flags);
+ zassert_ok(gpio_emul_flags_get(ec_x_gpio3, ec_x_pin3, flags), NULL);
+ zassert_equal(*flags, (GPIO_INPUT | GPIO_PULL_UP), "flags=%d", *flags);
+ free(flags);
+
+ /* Verify x_ec_interrupt is disabled */
+ interrupt_count = 0;
+ zassert_ok(gpio_emul_input_set(x_ec_gpio2, x_ec_pin2, 0), NULL);
+ k_sleep(K_MSEC(100));
+ zassert_ok(gpio_emul_input_set(x_ec_gpio2, x_ec_pin2, 1), NULL);
+ k_sleep(K_MSEC(100));
+
+ zassert_equal(interrupt_count, 0, "interrupt_count=%d",
+ interrupt_count);
+}
diff --git a/zephyr/test/kingler/src/db_detect_typec.c b/zephyr/test/kingler/src/db_detect_typec.c
new file mode 100644
index 0000000000..53716fe552
--- /dev/null
+++ b/zephyr/test/kingler/src/db_detect_typec.c
@@ -0,0 +1,85 @@
+/* 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/kernel.h"
+#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/ztest.h>
+
+#include "gpio_signal.h"
+#include "hooks.h"
+#include "variant_db_detection.h"
+
+static void *db_detection_setup(void)
+{
+ const struct device *hdmi_prsnt_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_hdmi_prsnt_odl), gpios));
+ const gpio_port_pins_t hdmi_prsnt_pin =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_hdmi_prsnt_odl), gpios);
+ /* Set the GPIO to high to indicate the DB is type-c */
+ zassert_ok(gpio_emul_input_set(hdmi_prsnt_gpio, hdmi_prsnt_pin, 1),
+ NULL);
+
+ hook_notify(HOOK_INIT);
+
+ return NULL;
+}
+
+ZTEST_SUITE(db_detection, NULL, db_detection_setup, NULL, NULL, NULL);
+
+static int interrupt_count;
+void x_ec_interrupt(enum gpio_signal signal)
+{
+ interrupt_count++;
+}
+
+/* test typec db case */
+ZTEST(db_detection, test_db_detect_typec)
+{
+ const struct device *en_frs_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_ALIAS(gpio_usb_c1_frs_en), gpios));
+ const gpio_port_pins_t en_frs_pin =
+ DT_GPIO_PIN(DT_ALIAS(gpio_usb_c1_frs_en), gpios);
+ const struct device *c1_dp_in_hpd_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_ALIAS(gpio_usb_c1_dp_in_hpd), gpios));
+ const gpio_port_pins_t c1_dp_in_hpd_pin =
+ DT_GPIO_PIN(DT_ALIAS(gpio_usb_c1_dp_in_hpd), gpios);
+ const struct device *int_x_ec_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_x_ec_gpio2), gpios));
+ const gpio_port_pins_t int_x_ec_pin =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_x_ec_gpio2), gpios);
+
+ /* Check the DB type is type-c */
+ zassert_equal(CORSOLA_DB_TYPEC, corsola_get_db_type(), NULL);
+
+ /* Verify we can enable or disable FRS by setting gpio_usb_c1_frs_en */
+ zassert_ok(gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_frs_en), 1),
+ NULL);
+ zassert_equal(1, gpio_emul_output_get(en_frs_gpio, en_frs_pin), NULL);
+ zassert_ok(gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_frs_en), 0),
+ NULL);
+ zassert_equal(0, gpio_emul_output_get(en_frs_gpio, en_frs_pin), NULL);
+
+ /* Verify we can change the gpio_usb_c1_dp_in_hpd state */
+ zassert_ok(gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_dp_in_hpd),
+ 1),
+ NULL);
+ zassert_equal(1,
+ gpio_emul_output_get(c1_dp_in_hpd_gpio, c1_dp_in_hpd_pin),
+ NULL);
+ zassert_ok(gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_dp_in_hpd),
+ 0),
+ NULL);
+ zassert_equal(0,
+ gpio_emul_output_get(c1_dp_in_hpd_gpio, c1_dp_in_hpd_pin),
+ NULL);
+
+ /* Verify x_ec_interrupt is enabled */
+ interrupt_count = 0;
+ zassert_ok(gpio_emul_input_set(int_x_ec_gpio, int_x_ec_pin, 0), NULL);
+ k_sleep(K_MSEC(100));
+
+ zassert_equal(interrupt_count, 1, "interrupt_count=%d",
+ interrupt_count);
+}
diff --git a/zephyr/test/kingler/src/fakes.c b/zephyr/test/kingler/src/fakes.c
new file mode 100644
index 0000000000..cbf6c8d98c
--- /dev/null
+++ b/zephyr/test/kingler/src/fakes.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 <zephyr/fff.h>
+#include "gpio_signal.h"
+
+DEFINE_FFF_GLOBALS;
+FAKE_VOID_FUNC(power_button_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(button_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(lid_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(chipset_reset_request_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(power_signal_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(chipset_watchdog_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(extpower_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(usb_a0_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(switch_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(tcpc_alert_event, enum gpio_signal);
+FAKE_VOID_FUNC(ppc_interrupt, enum gpio_signal);
+FAKE_VOID_FUNC(bc12_interrupt, enum gpio_signal);
+
+#ifdef CONFIG_TEST_STEELIX_RUSTY
+FAKE_VOID_FUNC(x_ec_interrupt, enum gpio_signal);
+#endif
+
+#ifdef CONFIG_VARIANT_CORSOLA_DB_DETECTION
+FAKE_VOID_FUNC(bmi3xx_interrupt, enum gpio_signal);
+#endif
diff --git a/zephyr/test/kingler/src/tablet.c b/zephyr/test/kingler/src/tablet.c
new file mode 100644
index 0000000000..68be2b2b68
--- /dev/null
+++ b/zephyr/test/kingler/src/tablet.c
@@ -0,0 +1,91 @@
+/* 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/kernel.h"
+#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/ztest.h>
+
+#include "cros_board_info.h"
+#include "cros_cbi.h"
+#include "gpio_signal.h"
+#include "hooks.h"
+#include "tablet_mode.h"
+
+static void *tablet_setup(void)
+{
+ uint32_t val;
+ const struct device *wp_gpio =
+ DEVICE_DT_GET(DT_GPIO_CTLR(DT_ALIAS(gpio_wp), gpios));
+ const gpio_port_pins_t wp_pin = DT_GPIO_PIN(DT_ALIAS(gpio_wp), gpios);
+
+ /* Make sure that write protect is disabled */
+ zassert_ok(gpio_emul_input_set(wp_gpio, wp_pin, 1), NULL);
+ /* Set CBI form factor to CONVERTIBLE. */
+ zassert_ok(cbi_set_fw_config(CONVERTIBLE << 13), NULL);
+ /* Run init hooks to initialize cbi. */
+ hook_notify(HOOK_INIT);
+
+ /* Check if CBI write worked. */
+ zassert_ok(cros_cbi_get_fw_config(FORM_FACTOR, &val), NULL);
+ zassert_equal(CONVERTIBLE, val, "val=%d", val);
+
+ return NULL;
+}
+
+ZTEST_SUITE(steelix_tablet, NULL, tablet_setup, NULL, NULL, NULL);
+
+ZTEST(steelix_tablet, test_gmr_tablet_switch_enabled)
+{
+ const struct device *tablet_mode_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(gpio_tablet_mode_l), gpios));
+ const gpio_port_pins_t tablet_mode_pin =
+ DT_GPIO_PIN(DT_NODELABEL(gpio_tablet_mode_l), gpios);
+
+ /* Verify gmr_tablet_switch is enabled, by checking the side effects
+ * of calling tablet_set_mode, and setting gpio_tablet_mode_l.
+ */
+ zassert_ok(gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 0),
+ NULL);
+ k_sleep(K_MSEC(100));
+ tablet_set_mode(1, TABLET_TRIGGER_LID);
+ zassert_equal(1, tablet_get_mode(), NULL);
+ zassert_ok(gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 1),
+ NULL);
+ k_sleep(K_MSEC(100));
+ tablet_set_mode(0, TABLET_TRIGGER_LID);
+ zassert_equal(0, tablet_get_mode(), NULL);
+ zassert_ok(gpio_emul_input_set(tablet_mode_gpio, tablet_mode_pin, 0),
+ NULL);
+ k_sleep(K_MSEC(100));
+ tablet_set_mode(1, TABLET_TRIGGER_LID);
+ zassert_equal(1, tablet_get_mode(), NULL);
+}
+
+static int interrupt_count;
+
+void bmi3xx_interrupt(enum gpio_signal signal)
+{
+ interrupt_count++;
+}
+
+ZTEST(steelix_tablet, test_base_imu_irq_enabled)
+{
+ const struct device *base_imu_gpio = DEVICE_DT_GET(
+ DT_GPIO_CTLR(DT_NODELABEL(base_imu_int_l), gpios));
+ const gpio_port_pins_t base_imu_pin =
+ DT_GPIO_PIN(DT_NODELABEL(base_imu_int_l), gpios);
+
+ /* Verify base_imu_irq is enabled. Interrupt is configured
+ * GPIO_INT_EDGE_FALLING, so set high, then set low.
+ */
+ interrupt_count = 0;
+ zassert_ok(gpio_emul_input_set(base_imu_gpio, base_imu_pin, 1), NULL);
+ k_sleep(K_MSEC(100));
+ zassert_ok(gpio_emul_input_set(base_imu_gpio, base_imu_pin, 0), NULL);
+ k_sleep(K_MSEC(100));
+
+ zassert_equal(interrupt_count, 1, "interrupt_count=%d",
+ interrupt_count);
+}
diff --git a/zephyr/test/kingler/testcase.yaml b/zephyr/test/kingler/testcase.yaml
new file mode 100644
index 0000000000..1d6c1bd0a8
--- /dev/null
+++ b/zephyr/test/kingler/testcase.yaml
@@ -0,0 +1,32 @@
+# 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:
+ kingler.steelix:
+ extra_args: DTC_OVERLAY_FILE="./common.dts;../projects/corsola/interrupts_kingler.dts;../projects/corsola/cbi_steelix.dts;../projects/corsola/gpio_steelix.dts"
+ extra_configs:
+ - CONFIG_TEST_STEELIX_RUSTY=y
+ - CONFIG_TEST_FORM_FACTOR_CONVERTIBLE=y
+ kingler.rusty:
+ extra_args: DTC_OVERLAY_FILE="./common.dts;../projects/corsola/interrupts_kingler.dts;../projects/corsola/cbi_steelix.dts;../projects/corsola/gpio_steelix.dts"
+ extra_configs:
+ - CONFIG_TEST_STEELIX_RUSTY=y
+ - CONFIG_TEST_FORM_FACTOR_CLAMSHELL=y
+ kingler.db_detect_typec:
+ extra_args: DTC_OVERLAY_FILE="./common.dts;../projects/corsola/interrupts_kingler.dts;../projects/corsola/gpio_steelix.dts;"
+ extra_configs:
+ - CONFIG_TEST_DB_DETECT_TYPEC=y
+ - CONFIG_VARIANT_CORSOLA_DB_DETECTION=y
+ kingler.db_detect_hdmi:
+ extra_args: DTC_OVERLAY_FILE="./common.dts;../projects/corsola/interrupts_kingler.dts;../projects/corsola/gpio_steelix.dts"
+ extra_configs:
+ - CONFIG_TEST_DB_DETECT_HDMI=y
+ - CONFIG_VARIANT_CORSOLA_DB_DETECTION=y
+ kingler.db_detect_none:
+ extra_args: DTC_OVERLAY_FILE="./common.dts;../projects/corsola/interrupts_kingler.dts;../projects/corsola/cbi_steelix.dts;../projects/corsola/gpio_steelix.dts"
+ extra_configs:
+ - CONFIG_TEST_DB_DETECT_NONE=y
+ - CONFIG_VARIANT_CORSOLA_DB_DETECTION=y