From 2fb25509b800726342955194a0c6ac24299fb08e Mon Sep 17 00:00:00 2001 From: Ghennadi Procopciuc Date: Mon, 13 Jan 2025 09:50:51 +0200 Subject: [PATCH] feat(nxp-clk): add get_rate for s32cc_dfs Add the option to obtain the rate of an s32cc_dfs object. The DFS rate depends on the module to which it's connected. Therefore, it will always return the rate of its parent. Change-Id: Ie3becd36721f541d0fab11b2fb57aacd66d48220 Signed-off-by: Ghennadi Procopciuc --- drivers/nxp/clk/s32cc/s32cc_clk_drv.c | 42 ++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/drivers/nxp/clk/s32cc/s32cc_clk_drv.c b/drivers/nxp/clk/s32cc/s32cc_clk_drv.c index 95298435d..3b945dd4b 100644 --- a/drivers/nxp/clk/s32cc/s32cc_clk_drv.c +++ b/drivers/nxp/clk/s32cc/s32cc_clk_drv.c @@ -33,6 +33,14 @@ struct s32cc_clk_drv { uintptr_t rdc; }; +static int set_module_rate(const struct s32cc_clk_obj *module, + unsigned long rate, unsigned long *orate, + unsigned int *depth); +static int get_module_rate(const struct s32cc_clk_obj *module, + const struct s32cc_clk_drv *drv, + unsigned long *rate, + unsigned int depth); + static int update_stack_depth(unsigned int *depth) { if (*depth == 0U) { @@ -651,6 +659,29 @@ static int enable_dfs(struct s32cc_clk_obj *module, return 0; } +static int get_dfs_freq(const struct s32cc_clk_obj *module, + const struct s32cc_clk_drv *drv, + unsigned long *rate, unsigned int depth) +{ + const struct s32cc_dfs *dfs = s32cc_obj2dfs(module); + unsigned int ldepth = depth; + uintptr_t dfs_addr; + int ret; + + ret = update_stack_depth(&ldepth); + if (ret != 0) { + return ret; + } + + ret = get_base_addr(dfs->instance, drv, &dfs_addr); + if (ret != 0) { + ERROR("Failed to detect the DFS instance\n"); + return ret; + } + + return get_module_rate(dfs->parent, drv, rate, ldepth); +} + static struct s32cc_dfs *get_div_dfs(const struct s32cc_dfs_div *dfs_div) { const struct s32cc_clk_obj *parent = dfs_div->parent; @@ -1059,14 +1090,6 @@ static bool s32cc_clk_is_enabled(unsigned long id) return false; } -static int set_module_rate(const struct s32cc_clk_obj *module, - unsigned long rate, unsigned long *orate, - unsigned int *depth); -static int get_module_rate(const struct s32cc_clk_obj *module, - const struct s32cc_clk_drv *drv, - unsigned long *rate, - unsigned int depth); - static int set_osc_freq(const struct s32cc_clk_obj *module, unsigned long rate, unsigned long *orate, unsigned int *depth) { @@ -1470,6 +1493,9 @@ static int get_module_rate(const struct s32cc_clk_obj *module, case s32cc_pll_t: ret = get_pll_freq(module, drv, rate, ldepth); break; + case s32cc_dfs_t: + ret = get_dfs_freq(module, drv, rate, ldepth); + break; default: ret = -EINVAL; break;