feat(nxp-clk): add oscillator clock objects
The oscillator clock objects will be used to describe the FIRC, FXOSC,
and SIRC clocks, all of which are oscillators on S32CC SoCs.
Change-Id: Icf235cc9b8f1d95d2c0051ce9a7655fd120289b8
Signed-off-by: Ghennadi Procopciuc <ghennadi.procopciuc@nxp.com>
diff --git a/drivers/nxp/clk/s32cc/s32cc_clk.mk b/drivers/nxp/clk/s32cc/s32cc_clk.mk
index ef6ad33..3f704c6 100644
--- a/drivers/nxp/clk/s32cc/s32cc_clk.mk
+++ b/drivers/nxp/clk/s32cc/s32cc_clk.mk
@@ -9,6 +9,8 @@
CLK_SOURCES := \
${PLAT_DRIVERS_PATH}/clk/s32cc/s32cc_clk_drv.c \
+ ${PLAT_DRIVERS_PATH}/clk/s32cc/s32cc_clk_modules.c \
+ ${PLAT_DRIVERS_PATH}/clk/s32cc/s32cc_clk_utils.c \
ifeq (${BL_COMM_CLK_NEEDED},yes)
BL2_SOURCES += ${CLK_SOURCES}
diff --git a/drivers/nxp/clk/s32cc/s32cc_clk_modules.c b/drivers/nxp/clk/s32cc/s32cc_clk_modules.c
new file mode 100644
index 0000000..f8fc52f
--- /dev/null
+++ b/drivers/nxp/clk/s32cc/s32cc_clk_modules.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2020-2024 NXP
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+#include <s32cc-clk-ids.h>
+#include <s32cc-clk-modules.h>
+#include <s32cc-clk-utils.h>
+
+/* Oscillators */
+static struct s32cc_osc fxosc =
+ S32CC_OSC_INIT(S32CC_FXOSC);
+static struct s32cc_clk fxosc_clk =
+ S32CC_MODULE_CLK(fxosc);
+
+static struct s32cc_osc firc =
+ S32CC_OSC_INIT(S32CC_FIRC);
+static struct s32cc_clk firc_clk =
+ S32CC_MODULE_CLK(firc);
+
+static struct s32cc_osc sirc =
+ S32CC_OSC_INIT(S32CC_SIRC);
+static struct s32cc_clk sirc_clk =
+ S32CC_MODULE_CLK(sirc);
+
+static struct s32cc_clk *s32cc_hw_clk_list[3] = {
+ /* Oscillators */
+ [S32CC_CLK_ID(S32CC_CLK_FIRC)] = &firc_clk,
+ [S32CC_CLK_ID(S32CC_CLK_SIRC)] = &sirc_clk,
+ [S32CC_CLK_ID(S32CC_CLK_FXOSC)] = &fxosc_clk,
+};
+
+static struct s32cc_clk_array s32cc_hw_clocks = {
+ .type_mask = S32CC_CLK_TYPE(S32CC_CLK_FIRC),
+ .clks = &s32cc_hw_clk_list[0],
+ .n_clks = ARRAY_SIZE(s32cc_hw_clk_list),
+};
+
+struct s32cc_clk *s32cc_get_arch_clk(unsigned long id)
+{
+ static const struct s32cc_clk_array *clk_table[1] = {
+ &s32cc_hw_clocks,
+ };
+
+ return s32cc_get_clk_from_table(clk_table, ARRAY_SIZE(clk_table), id);
+}
diff --git a/drivers/nxp/clk/s32cc/s32cc_clk_utils.c b/drivers/nxp/clk/s32cc/s32cc_clk_utils.c
new file mode 100644
index 0000000..14ab674
--- /dev/null
+++ b/drivers/nxp/clk/s32cc/s32cc_clk_utils.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2024 NXP
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+#include <s32cc-clk-ids.h>
+#include <s32cc-clk-utils.h>
+
+static struct s32cc_clk *s32cc_clk_get_from_array(const struct s32cc_clk_array *arr,
+ unsigned long clk_id)
+{
+ unsigned long type, id;
+
+ type = S32CC_CLK_TYPE(clk_id);
+
+ if (type != arr->type_mask) {
+ return NULL;
+ }
+
+ id = S32CC_CLK_ID(clk_id);
+
+ if (id >= arr->n_clks) {
+ return NULL;
+ }
+
+ return arr->clks[id];
+}
+
+struct s32cc_clk *s32cc_get_clk_from_table(const struct s32cc_clk_array *const *clk_arr,
+ size_t size,
+ unsigned long clk_id)
+{
+ struct s32cc_clk *clk;
+ size_t i;
+
+ for (i = 0; i < size; i++) {
+ clk = s32cc_clk_get_from_array(clk_arr[i], clk_id);
+ if (clk != NULL) {
+ return clk;
+ }
+ }
+
+ return NULL;
+}