diff options
author | Tomasz Michalec <tm@semihalf.com> | 2021-09-02 17:01:44 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-09-03 15:35:33 +0000 |
commit | cab1ac319919cd816b70d844fc6d8e479e989e61 (patch) | |
tree | ea9de9dd38283b02c07c0e130ec15da74db5ea1c /zephyr/test/drivers/src | |
parent | cde2d8998daf2530079e8395ce79f20b1beda70e (diff) | |
download | chrome-ec-cab1ac319919cd816b70d844fc6d8e479e989e61.tar.gz |
zephyr: drivers: add BB retimer init test
bb_retimier init function is tested with I2C communication errors and
wrong values of BB retimer vendor/device ID.
Init function checks state of AP, so CONFIG_PLATFORM_EC_POWERSEQ is
enabled. CONFIG_PLATFORM_EC_POWERSEQ_INTEL and
CONFIG_PLATFORM_EC_POWERSEQ_PP5000_CONTROL are disabled to reduce code
that needs to be mocked.
BUG=b:184856919
BRANCH=none
TEST=make configure --test zephyr/test/drivers
Signed-off-by: Tomasz Michalec <tm@semihalf.com>
Change-Id: Ibaed931f54a797d70fa86297b3eb0181ab2a689d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3140205
Commit-Queue: Jeremy Bettis <jbettis@chromium.org>
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'zephyr/test/drivers/src')
-rw-r--r-- | zephyr/test/drivers/src/bb_retimer.c | 98 | ||||
-rw-r--r-- | zephyr/test/drivers/src/stubs.c | 30 |
2 files changed, 127 insertions, 1 deletions
diff --git a/zephyr/test/drivers/src/bb_retimer.c b/zephyr/test/drivers/src/bb_retimer.c index c7e5fb7789..38111ce4e5 100644 --- a/zephyr/test/drivers/src/bb_retimer.c +++ b/zephyr/test/drivers/src/bb_retimer.c @@ -5,6 +5,8 @@ #include <zephyr.h> #include <ztest.h> +#include <drivers/gpio.h> +#include <drivers/gpio/gpio_emul.h> #include "common.h" #include "ec_tasks.h" @@ -18,6 +20,11 @@ #include "driver/retimer/bb_retimer.h" +#define GPIO_USB_C1_LS_EN_PATH DT_PATH(named_gpios, usb_c1_ls_en) +#define GPIO_USB_C1_LS_EN_PORT DT_GPIO_PIN(GPIO_USB_C1_LS_EN_PATH, gpios) +#define GPIO_USB_C1_RT_RST_ODL_PATH DT_PATH(named_gpios, usb_c1_rt_rst_odl) +#define GPIO_USB_C1_RT_RST_ODL_PORT \ + DT_GPIO_PIN(GPIO_USB_C1_RT_RST_ODL_PATH, gpios) #define EMUL_LABEL DT_NODELABEL(usb_c1_bb_retimer_emul) #define BB_RETIMER_ORD DT_DEP_ORD(EMUL_LABEL) @@ -418,11 +425,100 @@ static void test_bb_set_dfp_state(void) exp_conn, conn); } +/** Test BB retimer init */ +static void test_bb_init(void) +{ + const struct device *gpio_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_USB_C1_LS_EN_PATH, gpios)); + struct i2c_emul *emul; + + zassert_not_null(gpio_dev, "Cannot get GPIO device"); + + emul = bb_emul_get(BB_RETIMER_ORD); + + /* Set AP to normal state and wait for chipset task */ + set_mock_power_state(POWER_S0); + k_msleep(1); + + /* Setup emulator fail on read */ + i2c_common_emul_set_read_fail_reg(emul, BB_RETIMER_REG_VENDOR_ID); + /* Test fail on vendor ID read */ + zassert_equal(-EIO, bb_usb_retimer.init(&usb_muxes[USBC_PORT_C1]), + NULL); + /* Enable pins should be set always after init, when AP is on */ + zassert_equal(1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT), + NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, + GPIO_USB_C1_RT_RST_ODL_PORT), + NULL); + + /* Setup wrong vendor ID */ + i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + bb_emul_set_reg(emul, BB_RETIMER_REG_VENDOR_ID, 0x12144678); + /* Test fail on wrong vendor ID */ + zassert_equal(EC_ERROR_INVAL, + bb_usb_retimer.init(&usb_muxes[USBC_PORT_C1]), NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT), + NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, + GPIO_USB_C1_RT_RST_ODL_PORT), + NULL); + + /* Setup emulator fail on device ID read */ + i2c_common_emul_set_read_fail_reg(emul, BB_RETIMER_REG_DEVICE_ID); + bb_emul_set_reg(emul, BB_RETIMER_REG_VENDOR_ID, BB_RETIMER_VENDOR_ID_1); + /* Test fail on device ID read */ + zassert_equal(-EIO, bb_usb_retimer.init(&usb_muxes[USBC_PORT_C1]), + NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT), + NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, + GPIO_USB_C1_RT_RST_ODL_PORT), + NULL); + + /* Setup wrong device ID */ + i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + bb_emul_set_reg(emul, BB_RETIMER_REG_DEVICE_ID, 0x12144678); + /* Test fail on wrong device ID */ + zassert_equal(EC_ERROR_INVAL, + bb_usb_retimer.init(&usb_muxes[USBC_PORT_C1]), NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT), + NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, + GPIO_USB_C1_RT_RST_ODL_PORT), + NULL); + + /* Test successful init */ + bb_emul_set_reg(emul, BB_RETIMER_REG_DEVICE_ID, BB_RETIMER_DEVICE_ID); + zassert_equal(EC_SUCCESS, bb_usb_retimer.init(&usb_muxes[USBC_PORT_C1]), + NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT), + NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, + GPIO_USB_C1_RT_RST_ODL_PORT), + NULL); + + /* Set AP to off state and wait for chipset task */ + set_mock_power_state(POWER_G3); + k_msleep(1); + + /* With AP off, init should fail and pins should be unset */ + zassert_equal(EC_ERROR_NOT_POWERED, + bb_usb_retimer.init(&usb_muxes[USBC_PORT_C1]), NULL); + zassert_equal(0, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT), + NULL); + zassert_equal(0, gpio_emul_output_get(gpio_dev, + GPIO_USB_C1_RT_RST_ODL_PORT), + NULL); +} + + void test_suite_bb_retimer(void) { ztest_test_suite(bb_retimer, ztest_user_unit_test(test_bb_is_fw_update_capable), ztest_user_unit_test(test_bb_set_state), - ztest_user_unit_test(test_bb_set_dfp_state)); + ztest_user_unit_test(test_bb_set_dfp_state), + ztest_user_unit_test(test_bb_init)); ztest_run_test_suite(bb_retimer); } diff --git a/zephyr/test/drivers/src/stubs.c b/zephyr/test/drivers/src/stubs.c index 62d037d718..8a339679a8 100644 --- a/zephyr/test/drivers/src/stubs.c +++ b/zephyr/test/drivers/src/stubs.c @@ -11,6 +11,7 @@ #include "charger/isl9241_public.h" #include "config.h" #include "i2c/i2c.h" +#include "power.h" #include "ppc/sn5s330_public.h" #include "ppc/syv682x_public.h" #include "retimer/bb_retimer_public.h" @@ -200,3 +201,32 @@ uint16_t tcpc_get_alert_status(void) { return 0; } + +enum power_state power_chipset_init(void) +{ + return POWER_G3; +} + +enum power_state mock_state = POWER_G3; + +void set_mock_power_state(enum power_state state) +{ + mock_state = state; + task_wake(TASK_ID_CHIPSET); +} + +enum power_state power_handle_state(enum power_state state) +{ + return mock_state; +} + +void chipset_reset(enum chipset_reset_reason reason) +{ +} + +void chipset_force_shutdown(enum chipset_shutdown_reason reason) +{ +} + +/* Power signals list. Must match order of enum power_signal. */ +const struct power_signal_info power_signal_list[] = {}; |