aboutsummaryrefslogtreecommitdiff
path: root/module/clock/src/config_dt_clock.c
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 /module/clock/src/config_dt_clock.c
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>
Diffstat (limited to 'module/clock/src/config_dt_clock.c')
-rw-r--r--module/clock/src/config_dt_clock.c67
1 files changed, 67 insertions, 0 deletions
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