diff options
-rw-r--r-- | zephyr/program/rex/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/program/rex/Kconfig | 4 | ||||
-rw-r--r-- | zephyr/program/rex/cbi.dtsi | 35 | ||||
-rw-r--r-- | zephyr/program/rex/rex/project.overlay | 1 | ||||
-rw-r--r-- | zephyr/program/rex/src/fan.c | 37 | ||||
-rw-r--r-- | zephyr/shim/src/cbi/cros_cbi_fw_config.c | 4 | ||||
-rw-r--r-- | zephyr/test/rex/CMakeLists.txt | 3 | ||||
-rw-r--r-- | zephyr/test/rex/Kconfig | 20 | ||||
-rw-r--r-- | zephyr/test/rex/fan.dtsi | 35 | ||||
-rw-r--r-- | zephyr/test/rex/prj.conf | 5 | ||||
-rw-r--r-- | zephyr/test/rex/src/fan.c | 88 | ||||
-rw-r--r-- | zephyr/test/rex/testcase.yaml | 2 |
12 files changed, 227 insertions, 8 deletions
diff --git a/zephyr/program/rex/CMakeLists.txt b/zephyr/program/rex/CMakeLists.txt index 27d7dff068..18e95c75b3 100644 --- a/zephyr/program/rex/CMakeLists.txt +++ b/zephyr/program/rex/CMakeLists.txt @@ -8,5 +8,6 @@ project(rex) zephyr_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include") zephyr_library_sources_ifdef(CONFIG_AP_PWRSEQ "src/board_power.c") +zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_FAN "src/fan.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC "src/usbc_config.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC "src/usb_pd_policy.c") diff --git a/zephyr/program/rex/Kconfig b/zephyr/program/rex/Kconfig index 7d17c27815..f61e27ad7d 100644 --- a/zephyr/program/rex/Kconfig +++ b/zephyr/program/rex/Kconfig @@ -8,4 +8,8 @@ config BOARD_REX Build Google Rex reference board. The board uses Nuvoton NPCX9 chip as the EC. +module = REX +module-str = Rex board-specific code +source "subsys/logging/Kconfig.template.log_config" + source "Kconfig.zephyr" diff --git a/zephyr/program/rex/cbi.dtsi b/zephyr/program/rex/cbi.dtsi new file mode 100644 index 0000000000..59e56d9ebd --- /dev/null +++ b/zephyr/program/rex/cbi.dtsi @@ -0,0 +1,35 @@ +/* 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. + */ + +/ { + rex-fw-config { + compatible = "cros-ec,cbi-fw-config"; + + /* + * FW_CONFIG field to enable fan or not. + */ + fan { + enum-name = "FW_FAN"; + start = <0>; + size = <1>; + + no-fan { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_FAN_NOT_PRESENT"; + value = <0>; + }; + fan-present { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_FAN_PRESENT"; + value = <1>; + /* + * Set as default so that unprovisioned + * configs will run the fan regardless. + */ + default; + }; + }; + }; +}; diff --git a/zephyr/program/rex/rex/project.overlay b/zephyr/program/rex/rex/project.overlay index 7a5d68fa30..b8d5f5ac94 100644 --- a/zephyr/program/rex/rex/project.overlay +++ b/zephyr/program/rex/rex/project.overlay @@ -5,6 +5,7 @@ /* Rex program common DTSI includes */ #include "../battery.dtsi" +#include "../cbi.dtsi" #include "../fan.dtsi" #include "../generated.dtsi" #include "../interrupts.dtsi" diff --git a/zephyr/program/rex/src/fan.c b/zephyr/program/rex/src/fan.c new file mode 100644 index 0000000000..6d50df50fe --- /dev/null +++ b/zephyr/program/rex/src/fan.c @@ -0,0 +1,37 @@ +/* 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 "cros_cbi.h" +#include "fan.h" +#include "gpio/gpio.h" +#include "hooks.h" + +#include <zephyr/devicetree.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/logging/log.h> + +LOG_MODULE_DECLARE(rex, CONFIG_REX_LOG_LEVEL); + +/* + * Rex fan support + */ +static void fan_init(void) +{ + int ret; + uint32_t val; + /* + * Retrieve the fan config. + */ + ret = cros_cbi_get_fw_config(FW_FAN, &val); + if (ret != 0) { + LOG_ERR("Error retrieving CBI FW_CONFIG field %d", FW_FAN); + return; + } + + if (val == FW_FAN_NOT_PRESENT) { + fan_set_count(0); + } +} +DECLARE_HOOK(HOOK_INIT, fan_init, HOOK_PRIO_POST_FIRST); diff --git a/zephyr/shim/src/cbi/cros_cbi_fw_config.c b/zephyr/shim/src/cbi/cros_cbi_fw_config.c index 8f6086eb58..b4ea79d7fb 100644 --- a/zephyr/shim/src/cbi/cros_cbi_fw_config.c +++ b/zephyr/shim/src/cbi/cros_cbi_fw_config.c @@ -189,8 +189,8 @@ static int cros_cbi_fw_config_get_field(uint32_t cached_fw_config, return 0; } -int cros_cbi_get_fw_config(enum cbi_fw_config_field_id field_id, - uint32_t *value) +test_mockable int cros_cbi_get_fw_config(enum cbi_fw_config_field_id field_id, + uint32_t *value) { int rc; diff --git a/zephyr/test/rex/CMakeLists.txt b/zephyr/test/rex/CMakeLists.txt index ddee5d0120..a594a6b9dc 100644 --- a/zephyr/test/rex/CMakeLists.txt +++ b/zephyr/test/rex/CMakeLists.txt @@ -12,3 +12,6 @@ add_subdirectory(${PLATFORM_EC}/zephyr/test/test_utils test_utils) target_sources_ifdef(CONFIG_TEST_USB_PD_POLICY app PRIVATE src/usb_pd_policy.c) target_sources_ifdef(CONFIG_TEST_USB_PD_POLICY app PRIVATE ${PLATFORM_EC_PROGRAM_DIR}/rex/src/usb_pd_policy.c) + +target_sources_ifdef(CONFIG_TEST_FAN app PRIVATE src/fan.c) +target_sources_ifdef(CONFIG_TEST_FAN app PRIVATE ${PLATFORM_EC_PROGRAM_DIR}/rex/src/fan.c) diff --git a/zephyr/test/rex/Kconfig b/zephyr/test/rex/Kconfig index 11709b9b92..dde1b0fc4a 100644 --- a/zephyr/test/rex/Kconfig +++ b/zephyr/test/rex/Kconfig @@ -5,19 +5,27 @@ config TEST_USB_PD_POLICY bool "Run the tests intended for usb_pd_policy" help - Include usb_pd_policy.c into the binary and test - their functions. + Include usb_pd_policy.c into the binary and test their functions. config TEST_ENABLE_USB_PD_DISCHARGE bool "Enable CONFIG_USB_PD_DISCHARGE" help - This is used to define CONFIG_USB_PD_DISCHARGE - for testing purposes directly + This is used to define CONFIG_USB_PD_DISCHARGE for testing purposes + directly. config TEST_ENABLE_USB_PD_HOST_CMD bool "Enable CONFIG_USB_PD_HOST_CMD" help - This is used to define CONFIG_USB_PD_HOST_CMD - for testing purposes directly + This is used to define CONFIG_USB_PD_HOST_CMD for testing purposes + directly. + +config TEST_FAN + bool "Run the tests intended for fan" + help + Include fan.c into the binary and test their functions. + +module = REX +module-str = Rex board-specific code +source "subsys/logging/Kconfig.template.log_config" source "Kconfig.zephyr" diff --git a/zephyr/test/rex/fan.dtsi b/zephyr/test/rex/fan.dtsi new file mode 100644 index 0000000000..59e56d9ebd --- /dev/null +++ b/zephyr/test/rex/fan.dtsi @@ -0,0 +1,35 @@ +/* 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. + */ + +/ { + rex-fw-config { + compatible = "cros-ec,cbi-fw-config"; + + /* + * FW_CONFIG field to enable fan or not. + */ + fan { + enum-name = "FW_FAN"; + start = <0>; + size = <1>; + + no-fan { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_FAN_NOT_PRESENT"; + value = <0>; + }; + fan-present { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_FAN_PRESENT"; + value = <1>; + /* + * Set as default so that unprovisioned + * configs will run the fan regardless. + */ + default; + }; + }; + }; +}; diff --git a/zephyr/test/rex/prj.conf b/zephyr/test/rex/prj.conf index 89165e36a8..980186b31d 100644 --- a/zephyr/test/rex/prj.conf +++ b/zephyr/test/rex/prj.conf @@ -9,3 +9,8 @@ CONFIG_ASSERT=y CONFIG_CROS_EC=y CONFIG_PLATFORM_EC=y + +CONFIG_LOG=y +CONFIG_LOG_MODE_MINIMAL=y + +CONFIG_GPIO_GET_CONFIG=y diff --git a/zephyr/test/rex/src/fan.c b/zephyr/test/rex/src/fan.c new file mode 100644 index 0000000000..eb918a4369 --- /dev/null +++ b/zephyr/test/rex/src/fan.c @@ -0,0 +1,88 @@ +/* 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 "cros_cbi.h" +#include "fan.h" +#include "hooks.h" + +#include <zephyr/fff.h> +#include <zephyr/ztest.h> + +DECLARE_FAKE_VALUE_FUNC(int, cros_cbi_get_fw_config, + enum cbi_fw_config_field_id, uint32_t *); +DEFINE_FAKE_VALUE_FUNC(int, cros_cbi_get_fw_config, enum cbi_fw_config_field_id, + uint32_t *); +DECLARE_FAKE_VOID_FUNC(fan_set_count, int); +DEFINE_FAKE_VOID_FUNC(fan_set_count, int); + +int cros_cbi_get_fw_config_mock(enum cbi_fw_config_field_id field_id, + uint32_t *value) +{ + *value = FW_FAN_PRESENT; + return 0; +} + +int cros_cbi_get_fw_config_mock_no_fan(enum cbi_fw_config_field_id field_id, + uint32_t *value) +{ + *value = FW_FAN_NOT_PRESENT; + return 0; +} + +int cros_cbi_get_fw_config_mock_error(enum cbi_fw_config_field_id field_id, + uint32_t *value) +{ + return -1; +} + +void fan_set_count_mock(int count) +{ + zassert_equal(0, count); +} + +static void fan_before(void *fixture) +{ + ARG_UNUSED(fixture); + + RESET_FAKE(cros_cbi_get_fw_config); + RESET_FAKE(fan_set_count); +} + +ZTEST_USER(fan, test_fan_init) +{ + cros_cbi_get_fw_config_fake.custom_fake = cros_cbi_get_fw_config_mock; + fan_set_count_fake.custom_fake = fan_set_count_mock; + + hook_notify(HOOK_INIT); + + zassert_equal(1, cros_cbi_get_fw_config_fake.call_count); + zassert_equal(0, fan_set_count_fake.call_count); +} + +ZTEST_USER(fan, test_fan_init_no_fan) +{ + cros_cbi_get_fw_config_fake.custom_fake = + cros_cbi_get_fw_config_mock_no_fan; + fan_set_count_fake.custom_fake = fan_set_count_mock; + + hook_notify(HOOK_INIT); + + zassert_equal(1, cros_cbi_get_fw_config_fake.call_count); + zassert_equal(1, fan_set_count_fake.call_count); +} + +ZTEST_USER(fan, test_fan_init_error_reading_cbi) +{ + cros_cbi_get_fw_config_fake.custom_fake = + cros_cbi_get_fw_config_mock_error; + fan_set_count_fake.custom_fake = fan_set_count_mock; + + hook_notify(HOOK_INIT); + + zassert_equal(1, cros_cbi_get_fw_config_fake.call_count); + zassert_equal(0, fan_set_count_fake.call_count); +} + +ZTEST_SUITE(fan, NULL, NULL, fan_before, NULL, NULL); diff --git a/zephyr/test/rex/testcase.yaml b/zephyr/test/rex/testcase.yaml index 54e6f6cb55..00f38df167 100644 --- a/zephyr/test/rex/testcase.yaml +++ b/zephyr/test/rex/testcase.yaml @@ -6,7 +6,9 @@ common: platform_allow: native_posix tests: rex.default: + extra_args: DTC_OVERLAY_FILE="./boards/native_posix.overlay;./fan.dtsi;" extra_configs: - CONFIG_TEST_USB_PD_POLICY=y - CONFIG_TEST_ENABLE_USB_PD_DISCHARGE=y - CONFIG_TEST_ENABLE_USB_PD_HOST_CMD=y + - CONFIG_TEST_FAN=y |