diff options
-rw-r--r-- | zephyr/test/drivers/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/Kconfig | 3 | ||||
-rw-r--r-- | zephyr/test/drivers/boards/native_posix.overlay | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/testcase.yaml | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/usb_port_power_dumb/CMakeLists.txt | 7 | ||||
-rw-r--r-- | zephyr/test/drivers/usb_port_power_dumb/src/usb_port_power_dumb.c | 101 | ||||
-rw-r--r-- | zephyr/test/drivers/usb_port_power_dumb/usba.dts | 14 |
7 files changed, 137 insertions, 1 deletions
diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt index 9e51295d4d..b4dbfdae78 100644 --- a/zephyr/test/drivers/CMakeLists.txt +++ b/zephyr/test/drivers/CMakeLists.txt @@ -52,6 +52,7 @@ add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_LED_DRIVER led_driver) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_MKBP mkbp) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USB_MALFUNCTION_SINK usb_malfunction_sink) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USB_PD_DPS dps) +add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USB_PORT_POWER_DUMB usb_port_power_dumb) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USB_RETIMER_FW_UPDATE usb_retimer_fw_update) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USBC_ALT_MODE usbc_alt_mode) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_USBC_TBT_MODE usbc_tbt_mode) diff --git a/zephyr/test/drivers/Kconfig b/zephyr/test/drivers/Kconfig index cf877607ce..b208654dba 100644 --- a/zephyr/test/drivers/Kconfig +++ b/zephyr/test/drivers/Kconfig @@ -26,6 +26,9 @@ config LINK_TEST_SUITE_MKBP config LINK_TEST_SUITE_USB_MALFUNCTION_SINK bool "Link and test the usb_malfunction_sink tests" +config LINK_TEST_SUITE_USB_PORT_POWER_DUMB + bool "Link and test the usb_port_power_dumb tests" + config LINK_TEST_SUITE_USB_PD_DPS bool "Link and test the dps tests" diff --git a/zephyr/test/drivers/boards/native_posix.overlay b/zephyr/test/drivers/boards/native_posix.overlay index 03b59c8ac7..468ef299f2 100644 --- a/zephyr/test/drivers/boards/native_posix.overlay +++ b/zephyr/test/drivers/boards/native_posix.overlay @@ -204,6 +204,10 @@ gpio_ec_pg_pin_temp: ec_pg_pin_temp { gpios = <&gpio0 4 GPIO_INPUT>; }; + gpio_en_pp5000_usba_r: en_pp5000_usba_r { + gpios = <&gpio1 5 GPIO_OUTPUT_LOW>; + enum-name = "GPIO_EN_PP5000_USBA_R"; + }; }; gpio1: gpio@101 { @@ -216,7 +220,7 @@ low-level; gpio-controller; #gpio-cells = <2>; - ngpios = <5>; + ngpios = <6>; }; gpio-interrupts { diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml index 3708529ed3..de0b1ac3bd 100644 --- a/zephyr/test/drivers/testcase.yaml +++ b/zephyr/test/drivers/testcase.yaml @@ -61,6 +61,12 @@ tests: - CONFIG_PLATFORM_EC_MKBP_INPUT_DEVICES=y - CONFIG_PLATFORM_EC_MKBP_EVENT=y - CONFIG_PLATFORM_EC_MKBP_USE_GPIO=y + drivers.usb_port_power_dumb: + extra_args: DTC_OVERLAY_FILE="./boards/native_posix.overlay;./usb_port_power_dumb/usba.dts" + extra_configs: + - CONFIG_LINK_TEST_SUITE_USB_PORT_POWER_DUMB=y + - CONFIG_PLATFORM_EC_USBA=y + - CONFIG_PLATFORM_EC_USB_PORT_POWER_DUMB=y drivers.usb_retimer_fw_update: extra_args: CONF_FILE="prj.conf;usb_retimer_fw_update/prj.conf" extra_configs: diff --git a/zephyr/test/drivers/usb_port_power_dumb/CMakeLists.txt b/zephyr/test/drivers/usb_port_power_dumb/CMakeLists.txt new file mode 100644 index 0000000000..902a5b4a2d --- /dev/null +++ b/zephyr/test/drivers/usb_port_power_dumb/CMakeLists.txt @@ -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. + +target_sources(app PRIVATE + src/usb_port_power_dumb.c +) diff --git a/zephyr/test/drivers/usb_port_power_dumb/src/usb_port_power_dumb.c b/zephyr/test/drivers/usb_port_power_dumb/src/usb_port_power_dumb.c new file mode 100644 index 0000000000..5485854e88 --- /dev/null +++ b/zephyr/test/drivers/usb_port_power_dumb/src/usb_port_power_dumb.c @@ -0,0 +1,101 @@ +/* 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 <stdint.h> +#include <string.h> +#include <zephyr/kernel.h> +#include <zephyr/shell/shell_dummy.h> +#include <zephyr/ztest_assert.h> +#include <zephyr/ztest.h> + +#include "console.h" +#include "gpio.h" +#include "host_command.h" +#include "test/drivers/test_state.h" +#include "usb_charge.h" + +/* Expecting at least one port */ +BUILD_ASSERT(ARRAY_SIZE(usb_port_enable) >= 1); +BUILD_ASSERT(USB_PORT_COUNT >= 1); + +/* Index of the USB-A port under test */ +#define PORT_ID 0 + +static int check_gpio_status_for_port(int port_id) +{ + /* Ensure we don't make any invalid inquiries. These should only trip in + * the case of developer error. + */ + zassert_true(port_id < ARRAY_SIZE(usb_port_enable), + "Out of bounds port_id"); + zassert_true(usb_port_enable[port_id] >= 0, + "No valid pin number for this port"); + + return gpio_get_level(usb_port_enable[port_id]); +} + +ZTEST(usb_port_power_dumb, console_command__noargs) +{ + const char *outbuffer; + size_t buffer_size; + + /* With no args, print current state */ + shell_backend_dummy_clear_output(get_ec_shell()); + zassert_ok(shell_execute_cmd(get_ec_shell(), "usbchargemode"), NULL); + outbuffer = + shell_backend_dummy_get_output(get_ec_shell(), &buffer_size); + + zassert_ok(!strstr(outbuffer, "Port " STRINGIFY(PORT_ID) ": off"), + "Actual: '%s'", outbuffer); + + zassert_false(check_gpio_status_for_port(PORT_ID), NULL); +} + +ZTEST(usb_port_power_dumb, console_command__modify_port_status) +{ + const char *outbuffer; + size_t buffer_size; + + /* Change the port status to on */ + shell_backend_dummy_clear_output(get_ec_shell()); + zassert_ok(shell_execute_cmd(get_ec_shell(), + "usbchargemode " STRINGIFY(PORT_ID) " on"), + NULL); + outbuffer = + shell_backend_dummy_get_output(get_ec_shell(), &buffer_size); + + zassert_ok(!strstr(outbuffer, "Port " STRINGIFY(PORT_ID) ": on"), + "Actual: '%s'", outbuffer); + + zassert_true(check_gpio_status_for_port(PORT_ID), NULL); +} + +ZTEST(usb_port_power_dumb, console_command__invalid) +{ + /* Various bad input */ + zassert_ok(!shell_execute_cmd(get_ec_shell(), "usbchargemode NaN"), + NULL); + zassert_ok(!shell_execute_cmd(get_ec_shell(), "usbchargemode -1"), + NULL); + zassert_ok(!shell_execute_cmd(get_ec_shell(), "usbchargemode 10000"), + NULL); + zassert_ok( + !shell_execute_cmd(get_ec_shell(), + "usbchargemode " STRINGIFY(PORT_ID) " abc"), + NULL); +} + +static void reset(void *data) +{ + ARG_UNUSED(data); + + /* Turn the port off */ + zassume_ok(usb_charge_set_mode(PORT_ID, USB_CHARGE_MODE_DISABLED, + USB_DISALLOW_SUSPEND_CHARGE), + NULL); +} + +ZTEST_SUITE(usb_port_power_dumb, drivers_predicate_post_main, NULL, reset, + reset, NULL); diff --git a/zephyr/test/drivers/usb_port_power_dumb/usba.dts b/zephyr/test/drivers/usb_port_power_dumb/usba.dts new file mode 100644 index 0000000000..ff700d03fc --- /dev/null +++ b/zephyr/test/drivers/usb_port_power_dumb/usba.dts @@ -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. + */ + +/ { + /* Add a USB-A port to the board. Uses a GPIO pin defined in + * zephyr/test/drivers/boards/native_posix.overlay + */ + usba-port-enable-list { + compatible = "cros-ec,usba-port-enable-pins"; + enable-pins = <&gpio_en_pp5000_usba_r>; + }; +}; |