diff options
-rw-r--r-- | include/host_command.h | 16 | ||||
-rw-r--r-- | zephyr/shim/src/espi.c | 10 | ||||
-rw-r--r-- | zephyr/shim/src/ztest_system.c | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/overlay.dts | 16 | ||||
-rw-r--r-- | zephyr/test/drivers/prj.conf | 8 | ||||
-rw-r--r-- | zephyr/test/drivers/src/espi.c | 35 | ||||
-rw-r--r-- | zephyr/test/drivers/src/main.c | 2 |
7 files changed, 87 insertions, 6 deletions
diff --git a/include/host_command.h b/include/host_command.h index 15cca98d96..ccf86214aa 100644 --- a/include/host_command.h +++ b/include/host_command.h @@ -349,4 +349,20 @@ void host_send_sysrq(uint8_t key); uint32_t get_feature_flags0(void); uint32_t get_feature_flags1(void); +#ifdef CONFIG_ZTEST +static inline void +stub_send_response_callback(struct host_cmd_handler_args *args) +{ + ARG_UNUSED(args); +} + +#define BUILD_HOST_COMMAND(CMD, VERSION, RESPONSE) \ + { \ + .command = (CMD), .version = (VERSION), \ + .send_response = stub_send_response_callback, \ + .response = &(RESPONSE), .response_max = sizeof(RESPONSE), \ + .response_size = sizeof(RESPONSE) \ + } +#endif /* CONFIG_ZTEST */ + #endif /* __CROS_EC_HOST_COMMAND_H */ diff --git a/zephyr/shim/src/espi.c b/zephyr/shim/src/espi.c index e8ca1fcd0d..c064bd6157 100644 --- a/zephyr/shim/src/espi.c +++ b/zephyr/shim/src/espi.c @@ -196,11 +196,11 @@ int espi_vw_disable_wire_int(enum espi_vw_signal signal) uint8_t *lpc_get_memmap_range(void) { uint32_t lpc_memmap = 0; + int result = espi_read_lpc_request(espi_dev, EACPI_GET_SHARED_MEMORY, + &lpc_memmap); - if (espi_read_lpc_request(espi_dev, EACPI_GET_SHARED_MEMORY, - &lpc_memmap) != 0) { - LOG_ERR("Get lpc_memmap failed!\n"); - } + if (result != EC_SUCCESS) + LOG_ERR("Get lpc_memmap failed (%d)!\n", result); return (uint8_t *)lpc_memmap; } @@ -413,7 +413,7 @@ static enum ec_status lpc_get_protocol_info(struct host_cmd_handler_args *args) args->response_size = sizeof(*r); - return EC_SUCCESS; + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO, lpc_get_protocol_info, EC_VER_MASK(0)); diff --git a/zephyr/shim/src/ztest_system.c b/zephyr/shim/src/ztest_system.c index 4b30270692..14796b5bd5 100644 --- a/zephyr/shim/src/ztest_system.c +++ b/zephyr/shim/src/ztest_system.c @@ -61,3 +61,9 @@ struct jump_data *get_jump_data(void) { return NULL; } + +__attribute__((weak)) +void system_reset(int flags) +{ + __builtin_unreachable(); +} diff --git a/zephyr/test/drivers/overlay.dts b/zephyr/test/drivers/overlay.dts index f0413746d3..4d650551fa 100644 --- a/zephyr/test/drivers/overlay.dts +++ b/zephyr/test/drivers/overlay.dts @@ -39,6 +39,11 @@ enum-name = "GPIO_PG_EC_DSW_PWROK"; label = "PG_EC_DSW_PWROK"; }; + ec_pch_wake_odl { + gpios = <&gpio0 5 GPIO_OUT_HIGH>; + enum-name = "GPIO_EC_PCH_WAKE_ODL"; + label = "EC_PCH_WAKE_ODL"; + }; }; named-i2c-ports { compatible = "named-i2c-ports"; @@ -392,8 +397,17 @@ }; }; +&espi0 { + espi-host@0 { + status = "okay"; + compatible = "zephyr,espi-emul-espi-host"; + reg = <0x0>; + label = "ESPI_HOST"; + }; +}; + &gpio0 { - ngpios = <5>; + ngpios = <6>; }; &i2c0 { diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf index 3fd3636946..4ba0efc2a0 100644 --- a/zephyr/test/drivers/prj.conf +++ b/zephyr/test/drivers/prj.conf @@ -61,6 +61,14 @@ CONFIG_PLATFORM_EC_ACCEL_FIFO=y CONFIG_PLATFORM_EC_SENSOR_TIGHT_TIMESTAMPS=y CONFIG_PLATFORM_EC_ALS_TCS3400=y +CONFIG_ESPI=y +CONFIG_ESPI_EMUL=y +CONFIG_EMUL_ESPI_HOST=y +CONFIG_PLATFORM_EC_ESPI=y +CONFIG_ESPI_PERIPHERAL_ACPI_SHM_REGION=y +CONFIG_ESPI_PERIPHERAL_CUSTOM_OPCODE=y +CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD=y + # Things that default to on, but aren't working yet CONFIG_PLATFORM_EC_BACKLIGHT_LID=n CONFIG_PLATFORM_EC_SWITCH=n diff --git a/zephyr/test/drivers/src/espi.c b/zephyr/test/drivers/src/espi.c new file mode 100644 index 0000000000..c852f1b771 --- /dev/null +++ b/zephyr/test/drivers/src/espi.c @@ -0,0 +1,35 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr.h> +#include <ztest.h> + +#include "ec_commands.h" +#include "host_command.h" + +static void test_host_command_get_protocol_info(void) +{ + struct ec_response_get_protocol_info response; + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO, 0, response); + + zassert_ok(host_command_process(&args), NULL); + zassert_ok(args.result, NULL); + zassert_equal(args.response_size, sizeof(response), NULL); + zassert_equal(response.protocol_versions, BIT(3), NULL); + zassert_equal(response.max_request_packet_size, EC_LPC_HOST_PACKET_SIZE, + NULL); + zassert_equal(response.max_response_packet_size, + EC_LPC_HOST_PACKET_SIZE, NULL); + zassert_equal(response.flags, 0, NULL); +} + +void test_suite_espi(void) +{ + ztest_test_suite(espi, + ztest_user_unit_test( + test_host_command_get_protocol_info)); + ztest_run_test_suite(espi); +} diff --git a/zephyr/test/drivers/src/main.c b/zephyr/test/drivers/src/main.c index ca573b98fd..46fd462283 100644 --- a/zephyr/test/drivers/src/main.c +++ b/zephyr/test/drivers/src/main.c @@ -18,6 +18,7 @@ extern void test_suite_ppc(void); extern void test_suite_bmi260(void); extern void test_suite_bmi160(void); extern void test_suite_tcs3400(void); +extern void test_suite_espi(void); void test_main(void) { @@ -37,4 +38,5 @@ void test_main(void) test_suite_bmi260(); test_suite_bmi160(); test_suite_tcs3400(); + test_suite_espi(); } |