diff options
author | Diana Z <dzigterman@chromium.org> | 2023-04-05 15:48:03 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-04-07 20:18:38 +0000 |
commit | f12e495e6e72d45254847346feba1f9abb7b205f (patch) | |
tree | 9d7be476354036f454db53bec669f0492eda7405 | |
parent | a421b3380fb85c7e6dc990d7c668899bebb4b5d1 (diff) | |
download | chrome-ec-f12e495e6e72d45254847346feba1f9abb7b205f.tar.gz |
Zephyr Test: Create test for NX20P3481 PPC
Create test cases and emulor behavior to cover the slightly-different
portions of the NX20P348X code related to Vbus sourcig and sinking.
BRANCH=None
BUG=b:276468569
TEST=./twister -T ./zephyr/test
Change-Id: Ieb30b3dbe3ad52448359ef253085058efe5b1d39
Signed-off-by: Diana Z <dzigterman@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4404285
Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | zephyr/emul/emul_nx20p348x.c | 22 | ||||
-rw-r--r-- | zephyr/test/drivers/nx20p348x/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/nx20p348x/src/nx20p3481.c | 49 | ||||
-rw-r--r-- | zephyr/test/drivers/testcase.yaml | 8 |
4 files changed, 80 insertions, 0 deletions
diff --git a/zephyr/emul/emul_nx20p348x.c b/zephyr/emul/emul_nx20p348x.c index c6704c2278..e7b45531d6 100644 --- a/zephyr/emul/emul_nx20p348x.c +++ b/zephyr/emul/emul_nx20p348x.c @@ -132,6 +132,28 @@ static int nx20p348x_emul_write(const struct emul *emul, int reg, uint8_t val, data->regs[reg] = val; + if (IS_ENABLED(CONFIG_PLATFORM_EC_USBC_PPC_NX20P3481) && + reg == NX20P348X_SWITCH_CONTROL_REG) { + bool enabled = val & NX20P3481_SWITCH_CONTROL_HVSNK; + + /* Update our status as if we turned on/off Vbus sinking */ + if (enabled) + data->regs[NX20P348X_SWITCH_STATUS_REG] |= + NX20P348X_SWITCH_STATUS_HVSNK; + else + data->regs[NX20P348X_SWITCH_STATUS_REG] &= + ~NX20P348X_SWITCH_STATUS_HVSNK; + + /* Do the same for sourcing */ + enabled = val & NX20P3481_SWITCH_CONTROL_5VSRC; + if (enabled) + data->regs[NX20P348X_SWITCH_STATUS_REG] |= + NX20P348X_SWITCH_STATUS_5VSRC; + else + data->regs[NX20P348X_SWITCH_STATUS_REG] &= + ~NX20P348X_SWITCH_STATUS_5VSRC; + } + return 0; } diff --git a/zephyr/test/drivers/nx20p348x/CMakeLists.txt b/zephyr/test/drivers/nx20p348x/CMakeLists.txt index 14f27739a1..b2c202bd5b 100644 --- a/zephyr/test/drivers/nx20p348x/CMakeLists.txt +++ b/zephyr/test/drivers/nx20p348x/CMakeLists.txt @@ -5,4 +5,5 @@ target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) target_sources(app PRIVATE src/nx20p348x.c) +target_sources_ifdef(CONFIG_PLATFORM_EC_USBC_PPC_NX20P3481 app PRIVATE src/nx20p3481.c) target_sources_ifdef(CONFIG_PLATFORM_EC_USBC_PPC_NX20P3483 app PRIVATE src/nx20p3483.c) diff --git a/zephyr/test/drivers/nx20p348x/src/nx20p3481.c b/zephyr/test/drivers/nx20p348x/src/nx20p3481.c new file mode 100644 index 0000000000..0897c3e8d1 --- /dev/null +++ b/zephyr/test/drivers/nx20p348x/src/nx20p3481.c @@ -0,0 +1,49 @@ +/* Copyright 2023 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "driver/ppc/nx20p348x.h" +#include "nx20p348x_test_shared.h" +#include "test/drivers/stubs.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" +#include "usbc_ppc.h" + +#include <zephyr/shell/shell.h> +#include <zephyr/shell/shell_dummy.h> +#include <zephyr/ztest.h> + +ZTEST_F(nx20p348x_driver, test_sink_enable) +{ + uint8_t reg; + + zassert_ok(ppc_vbus_sink_enable(TEST_PORT, true)); + reg = nx20p348x_emul_peek(fixture->nx20p348x_emul, + NX20P348X_SWITCH_CONTROL_REG); + zassert_equal(reg & NX20P3481_SWITCH_CONTROL_HVSNK, + NX20P3481_SWITCH_CONTROL_HVSNK); + + zassert_ok(ppc_vbus_sink_enable(TEST_PORT, false)); + reg = nx20p348x_emul_peek(fixture->nx20p348x_emul, + NX20P348X_SWITCH_CONTROL_REG); + zassert_not_equal(reg & NX20P3481_SWITCH_CONTROL_HVSNK, + NX20P3481_SWITCH_CONTROL_HVSNK); +} + +ZTEST_F(nx20p348x_driver, test_source_enable) +{ + uint8_t reg; + + zassert_ok(ppc_vbus_source_enable(TEST_PORT, true)); + reg = nx20p348x_emul_peek(fixture->nx20p348x_emul, + NX20P348X_SWITCH_CONTROL_REG); + zassert_equal(reg & NX20P3481_SWITCH_CONTROL_5VSRC, + NX20P3481_SWITCH_CONTROL_5VSRC); + + zassert_ok(ppc_vbus_source_enable(TEST_PORT, false)); + reg = nx20p348x_emul_peek(fixture->nx20p348x_emul, + NX20P348X_SWITCH_CONTROL_REG); + zassert_not_equal(reg & NX20P3481_SWITCH_CONTROL_5VSRC, + NX20P3481_SWITCH_CONTROL_5VSRC); +} diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml index 4c709e1147..d4c6fc7e75 100644 --- a/zephyr/test/drivers/testcase.yaml +++ b/zephyr/test/drivers/testcase.yaml @@ -257,6 +257,14 @@ tests: - CONFIG_PLATFORM_EC_MKBP_USE_GPIO=y - CONFIG_PLATFORM_EC_KEYBOARD_KEYPAD=y tags: common mkbp + drivers.nx20p3481: + extra_dtc_overlay_files: + - ./boards/native_posix.overlay + - ./nx20p348x/usbc.dts + extra_configs: + - CONFIG_LINK_TEST_SUITE_NX20P348X=y + - CONFIG_PLATFORM_EC_USBC_PPC_NX20P3481=y + - CONFIG_PLATFORM_EC_USBC_PPC_NX20P3483=n drivers.nx20p3483: extra_dtc_overlay_files: - ./boards/native_posix.overlay |