diff options
author | Mike Leach <mike.leach@linaro.org> | 2024-01-18 17:19:02 +0000 |
---|---|---|
committer | Mike Leach <mike.leach@linaro.org> | 2024-02-02 17:41:50 +0000 |
commit | 9e135a63a5c3fd2412199c8b3449866753813f51 (patch) | |
tree | fe8e3dd14d95a99f56373797bec6cc4af4a0c6dd | |
parent | b8f872b9aeab24bd9602569529df6c28bd3b6bcf (diff) |
module: mock_psu: Add DT configuration support
Update mock_psu SCP module to support device tree configuration.
Signed-off-by: Mike Leach <mike.leach@linaro.org>
-rw-r--r-- | module/mock_psu/CMakeLists.txt | 9 | ||||
-rw-r--r-- | module/mock_psu/src/config_dt_mock_psu.c | 62 |
2 files changed, 71 insertions, 0 deletions
diff --git a/module/mock_psu/CMakeLists.txt b/module/mock_psu/CMakeLists.txt index b0e2d57989bf..6da90a78a15f 100644 --- a/module/mock_psu/CMakeLists.txt +++ b/module/mock_psu/CMakeLists.txt @@ -13,4 +13,13 @@ target_include_directories(${SCP_MODULE_TARGET} target_sources(${SCP_MODULE_TARGET} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/mod_mock_psu.c") +if(SCP_MODULE IN_LIST SCP_DT_CONFIG_MODULES_ALL) + target_sources(${SCP_MODULE_TARGET} + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/config_dt_mock_psu.c") + + # add header file to list used to generate defines for dt include + list(APPEND SCP_DT_BIND_H_GEN_FROM_INCL "${CMAKE_CURRENT_SOURCE_DIR}/include/mod_mock_psu.h") + set(SCP_DT_BIND_H_GEN_FROM_INCL "${SCP_DT_BIND_H_GEN_FROM_INCL}" PARENT_SCOPE) +endif() + target_link_libraries(${SCP_MODULE_TARGET} PRIVATE module-psu module-timer) diff --git a/module/mock_psu/src/config_dt_mock_psu.c b/module/mock_psu/src/config_dt_mock_psu.c new file mode 100644 index 000000000000..22c738aa9ba3 --- /dev/null +++ b/module/mock_psu/src/config_dt_mock_psu.c @@ -0,0 +1,62 @@ +/* + * Arm SCP/MCP Software + * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#include <mod_mock_psu.h> + +#include <fwk_macros.h> +#include <fwk_module.h> + +#include <fwk_dt_config_common.h> + +#define PSU_COMPAT scp_mock_psu +#define PSU_PROP(n, prop) FWK_DT_INST_PROP(PSU_COMPAT, n ,prop) + +/* single element .data structure */ +#define PSU_ELEM_DATA(n) \ + .async_alarm_id = FWK_DT_PH_OPT_IDX_SCP_ID_ELEM(PSU_COMPAT, n, 0), \ + .default_enabled = PSU_PROP(n, default_enabled), \ + .default_voltage = PSU_PROP(n, default_voltage), + +/* single element table entry */ +#define PSU_ELEM_INIT(n) \ + [PSU_PROP(n, elem_idx)] = { \ + .name = PSU_PROP(n, label), \ + .data = &(struct mod_mock_psu_element_cfg) { \ + PSU_ELEM_DATA(n) \ + }, \ + }, + +/* table generator */ +static struct fwk_element element_table[] = { + /* Macro for array elements */ + DT_FOREACH_OKAY_INST_scp_mock_psu(PSU_ELEM_INIT) + /* last null element */ + [DT_N_INST_scp_mock_psu_NUM_OKAY] = { 0 }, +}; + +/* access data table using function */ +const struct fwk_element *_static_get_element_table_mock_psu() { + /* + * using elem_idx property to bind table array elements to + * framework indexes. Check these result in a properly formed table + * which is not too small for the largest index. + * This will cause a build error if table is incorrect. + */ + FWK_DT_BUILD_BUG_ON(!FWK_DT_TABLE_CHECK(element_table, DT_N_INST_scp_mock_psu_NUM_OKAY + 1)); + + return element_table; +} + +/* config structure */ +struct fwk_module_config config_dt_mock_psu = { +#ifdef FWK_MODULE_GEN_DYNAMIC_MOCK_PSU + /* use custom external element callback to allow runtime modification */ + .elements = FWK_MODULE_DYNAMIC_ELEMENTS(dyn_get_element_table_mock_psu), +#else + /* use local access function */ + .elements = FWK_MODULE_DYNAMIC_ELEMENTS(_static_get_element_table_mock_psu), +#endif +}; |