aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Leach <mike.leach@linaro.org>2023-03-16 21:15:06 +0000
committerMike Leach <mike.leach@linaro.org>2023-07-14 11:12:37 +0100
commit7a8adef18322e52680b23fa97a83616ea935dca5 (patch)
tree08505287fee695bc798f882669cb6b16b16d6cf9
parent2feae45b94a7e294acd4775f0879bb0ff6da7d58 (diff)
module: clock: Add dt configuration support
Update clock SCP module to support device tree configuration. Signed-off-by: Mike Leach <mike.leach@linaro.org>
-rw-r--r--dts/bindings/scp/arm,scp-clk-dev.yaml20
-rw-r--r--module/clock/CMakeLists.txt9
-rw-r--r--module/clock/src/config_dt_clock.c67
3 files changed, 96 insertions, 0 deletions
diff --git a/dts/bindings/scp/arm,scp-clk-dev.yaml b/dts/bindings/scp/arm,scp-clk-dev.yaml
new file mode 100644
index 000000000000..8c44428a2589
--- /dev/null
+++ b/dts/bindings/scp/arm,scp-clk-dev.yaml
@@ -0,0 +1,20 @@
+# SCP firmware clock device software configuration
+
+description: Driver and API indexes for SCP clock software module configuration.
+
+compatible: "arm,scp-clk-dev"
+
+include: base.yaml
+
+properties:
+ name:
+ type: string
+ required: true
+
+ scp-ids:
+ description: Array of framework element IDs in order - driver ID, api-id and optional pd-source-id
+ required: true
+ type: phandle-array
+
+
+ \ No newline at end of file
diff --git a/module/clock/CMakeLists.txt b/module/clock/CMakeLists.txt
index 2de363db8d8c..9747469f7e63 100644
--- a/module/clock/CMakeLists.txt
+++ b/module/clock/CMakeLists.txt
@@ -16,3 +16,12 @@ target_sources(
"${CMAKE_CURRENT_SOURCE_DIR}/src/clock_tree_management.c")
target_link_libraries(${SCP_MODULE_TARGET} PRIVATE module-power-domain)
+
+if(SCP_MODULE IN_LIST SCP_DT_CONFIG_MODULES_ALL)
+ target_sources(${SCP_MODULE_TARGET}
+ PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/config_dt_clock.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_clock.h")
+ set(SCP_DT_BIND_H_GEN_FROM_INCL "${SCP_DT_BIND_H_GEN_FROM_INCL}" PARENT_SCOPE)
+endif()
diff --git a/module/clock/src/config_dt_clock.c b/module/clock/src/config_dt_clock.c
new file mode 100644
index 000000000000..aab9b27d1067
--- /dev/null
+++ b/module/clock/src/config_dt_clock.c
@@ -0,0 +1,67 @@
+/*
+ * Arm SCP/MCP Software
+ * Copyright (c) 2019-2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <mod_clock.h>
+#include <mod_power_domain.h>
+
+#include <fwk_element.h>
+#include <fwk_id.h>
+#include <fwk_module.h>
+#include <fwk_module_idx.h>
+#include <fwk_devicetree.h>
+#include <fwk_dt_config_common.h>
+
+#define CLK_DEV_COMPAT arm_scp_clk_dev
+
+/*
+ * driver id and api id are required, pd source id is optional
+ * DT array order must match this.
+ */
+#define CFG_CLK_DEV_ELEM_DATA_PH(n) \
+ .driver_id = FWK_DT_PH_IDX_SCP_ID_ELEM(CLK_DEV_COMPAT, n, 0), \
+ .api_id = FWK_DT_PH_IDX_SCP_ID_ELEM(CLK_DEV_COMPAT, n, 1), \
+ .pd_source_id = FWK_DT_PH_OPT_IDX_SCP_ID_ELEM(CLK_DEV_COMPAT, n, 2),
+
+#define CFG_CLK_DEV_ELEM_INIT(n) \
+ [n] = { \
+ .name = FWK_DT_INST_PROP(CLK_DEV_COMPAT, n, name), \
+ .data = &((struct mod_clock_dev_config) { \
+ CFG_CLK_DEV_ELEM_DATA_PH(n) \
+ }), \
+ },
+
+/* build tables if at least one instance in device tree */
+#if DT_HAS_COMPAT_STATUS_OKAY(CLK_DEV_COMPAT)
+
+/* data table */
+static struct fwk_element clock_element_table[] = {
+ // Macro for array elements
+ DT_FOREACH_OKAY_INST_arm_scp_clk_dev(CFG_CLK_DEV_ELEM_INIT)
+ // last null element
+ [DT_N_INST_arm_scp_clk_dev_NUM_OKAY] = { 0 },
+};
+
+/* access data table from dynamic element callback */
+#ifdef FWK_MODULE_GEN_DYNAMIC_CLOCK
+const struct fwk_element *_static_get_element_table_clock() {
+ return clock_element_table;
+}
+#endif
+
+/* config structure */
+struct fwk_module_config config_dt_clock = {
+ #ifdef FWK_MODULE_GEN_DYNAMIC_CLOCK
+ .elements = FWK_MODULE_DYNAMIC_ELEMENTS(dyn_get_element_table_clock),
+ #else
+ .elements = FWK_MODULE_STATIC_ELEMENTS_PTR(clock_element_table),
+ #endif
+};
+
+#else
+/* no DT references - set up NULL object */
+struct fwk_module_config config_dt_clock = { 0 };
+#endif