From b210e6e41577b491cedfe108e215b8361a108f0b Mon Sep 17 00:00:00 2001 From: Diana Z Date: Tue, 19 Jul 2022 14:05:00 -0600 Subject: Zephyr: Add utilities for mux set and event clear Add utilities to allow tests to clear port events and set muxes using the TYPEC_CONTROL host command. BRANCH=None BUG=b:234839764 TEST=zmake testall Signed-off-by: Diana Z Change-Id: I28af3cbff7b045f41b7af4b282cdae1f03811524 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3774147 Reviewed-by: Abe Levkoy --- zephyr/test/drivers/include/test/drivers/utils.h | 20 ++++++++++++++++ zephyr/test/drivers/src/utils.c | 29 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'zephyr/test/drivers') diff --git a/zephyr/test/drivers/include/test/drivers/utils.h b/zephyr/test/drivers/include/test/drivers/utils.h index 3754979a14..b7fd6ebb86 100644 --- a/zephyr/test/drivers/include/test/drivers/utils.h +++ b/zephyr/test/drivers/include/test/drivers/utils.h @@ -385,6 +385,26 @@ void host_cmd_typec_control_enter_mode(int port, enum typec_mode mode); */ void host_cmd_typec_control_exit_modes(int port); +/** + * Run the host command to control PD port behavior, with the sub-command of + * TYPEC_CONTROL_COMMAND_USB_MUX_SET + * + * @param port The USB-C port number + * @param mux_set Mode and mux index to set + */ +void host_cmd_typec_control_usb_mux_set(int port, + struct typec_usb_mux_set mux_set); + +/** + * Run the host command to control PD port behavior, with the sub-command of + * TYPEC_CONTROL_COMMAND_CLEAR_EVENTS + * + * @param port The USB-C port number + * @param events Events to clear for the port (see PD_STATUS_EVENT_* + * definitions for options) + */ +void host_cmd_typec_control_clear_events(int port, uint32_t events); + #define GPIO_ACOK_OD_NODE DT_NODELABEL(gpio_acok_od) #define GPIO_ACOK_OD_PIN DT_GPIO_PIN(GPIO_ACOK_OD_NODE, gpios) diff --git a/zephyr/test/drivers/src/utils.c b/zephyr/test/drivers/src/utils.c index c88a4cde56..ba27eb7095 100644 --- a/zephyr/test/drivers/src/utils.c +++ b/zephyr/test/drivers/src/utils.c @@ -398,6 +398,35 @@ void host_cmd_typec_control_exit_modes(int port) "Failed to send Type-C control for port %d", port); } +void host_cmd_typec_control_usb_mux_set(int port, + struct typec_usb_mux_set mux_set) +{ + struct ec_params_typec_control params = { + .port = port, + .command = TYPEC_CONTROL_COMMAND_USB_MUX_SET, + .mux_params = mux_set, + }; + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_TYPEC_CONTROL, 0, params); + + zassume_ok(host_command_process(&args), + "Failed to send Type-C control for port %d", port); +} + +void host_cmd_typec_control_clear_events(int port, uint32_t events) +{ + struct ec_params_typec_control params = { + .port = port, + .command = TYPEC_CONTROL_COMMAND_CLEAR_EVENTS, + .clear_events_mask = events, + }; + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_TYPEC_CONTROL, 0, params); + + zassume_ok(host_command_process(&args), + "Failed to send Type-C control for port %d", port); +} + void host_cmd_usb_pd_get_amode( uint8_t port, uint16_t svid_idx, struct ec_params_usb_pd_get_mode_response *response, int *response_size) -- cgit v1.2.1