From c36eaf24d3ab470a83c9a8f15499bab48e14cac3 Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Mon, 9 May 2022 16:29:07 -0600 Subject: test: Verify host command for motion_sense interrupt Check that enabling and disabling the motion_sense interrupt flag works. BRANCH=none BUG=b:224614211 TEST=zmake test test-drivers Signed-off-by: Yuval Peress Change-Id: I361feacbd71e2829f852b1d0565017e71680c609 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3636757 Reviewed-by: Jeremy Bettis --- zephyr/test/drivers/include/test/drivers/utils.h | 10 +++++++++ zephyr/test/drivers/src/host_cmd/motion_sense.c | 27 ++++++++++++++++++++++++ zephyr/test/drivers/src/utils.c | 15 +++++++++++++ 3 files changed, 52 insertions(+) diff --git a/zephyr/test/drivers/include/test/drivers/utils.h b/zephyr/test/drivers/include/test/drivers/utils.h index f0e8f6b7a2..d653d54938 100644 --- a/zephyr/test/drivers/include/test/drivers/utils.h +++ b/zephyr/test/drivers/include/test/drivers/utils.h @@ -392,6 +392,16 @@ int host_cmd_motion_sense_fifo_info(struct ec_response_motion_sense *response); int host_cmd_motion_sense_fifo_read(uint8_t buffer_length, struct ec_response_motion_sense *response); +/** + * @brief Call the int_enable motionsense host command + * + * @param enable 0 for disable, 1 for enable. All others are invalid + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_int_enable(int8_t enable, + struct ec_response_motion_sense *response); + /** * Run the host command to get the PD discovery responses. * diff --git a/zephyr/test/drivers/src/host_cmd/motion_sense.c b/zephyr/test/drivers/src/host_cmd/motion_sense.c index 1af5923bed..fbb22d4789 100644 --- a/zephyr/test/drivers/src/host_cmd/motion_sense.c +++ b/zephyr/test/drivers/src/host_cmd/motion_sense.c @@ -76,8 +76,10 @@ static void host_cmd_motion_sense_before(void *fixture) static void host_cmd_motion_sense_after(void *fixture) { struct host_cmd_motion_sense_fixture *this = fixture; + struct ec_response_motion_sense response; motion_sensors[0].drv = this->sensor_0_drv; + host_cmd_motion_sense_int_enable(0, &response); } ZTEST_SUITE(host_cmd_motion_sense, drivers_predicate_post_main, @@ -734,3 +736,28 @@ ZTEST(host_cmd_motion_sense, test_fifo_read) zassert_equal(4, response->fifo_read.data[1].data[1], NULL); zassert_equal(5, response->fifo_read.data[1].data[2], NULL); } + +ZTEST(host_cmd_motion_sense, test_int_enable) +{ + struct ec_response_motion_sense response; + + zassert_equal(EC_RES_INVALID_PARAM, + host_cmd_motion_sense_int_enable(2, &response), NULL); + + /* Make sure we start off disabled */ + zassume_ok(host_cmd_motion_sense_int_enable(0, &response), NULL); + + /* Test enable */ + zassert_ok(host_cmd_motion_sense_int_enable(1, &response), NULL); + zassert_ok(host_cmd_motion_sense_int_enable(EC_MOTION_SENSE_NO_VALUE, + &response), + NULL); + zassert_equal(1, response.fifo_int_enable.ret, NULL); + + /* Test disable */ + zassert_ok(host_cmd_motion_sense_int_enable(0, &response), NULL); + zassert_ok(host_cmd_motion_sense_int_enable(EC_MOTION_SENSE_NO_VALUE, + &response), + NULL); + zassert_equal(0, response.fifo_int_enable.ret, NULL); +} diff --git a/zephyr/test/drivers/src/utils.c b/zephyr/test/drivers/src/utils.c index a19d4531f5..c5e6b8148d 100644 --- a/zephyr/test/drivers/src/utils.c +++ b/zephyr/test/drivers/src/utils.c @@ -290,6 +290,21 @@ int host_cmd_motion_sense_fifo_read(uint8_t buffer_length, return host_command_process(&args); } +int host_cmd_motion_sense_int_enable(int8_t enable, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_FIFO_INT_ENABLE, + .fifo_int_enable = { + .enable = enable, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *response, params); + + return host_command_process(&args); +} + void host_cmd_typec_discovery(int port, enum typec_partner_type partner_type, void *response, size_t response_size) { -- cgit v1.2.1