From 46de0b9c992fd4da90075b39ccff0a849a976301 Mon Sep 17 00:00:00 2001 From: Ghennadi Procopciuc Date: Fri, 10 Jan 2025 16:33:36 +0200 Subject: [PATCH] feat(nxp-clk): add get_rate for s32cc_clk Add the option to obtain the rate of an s32cc_clk object. s32cc_clk are usually links to either another s32cc_clk or a different clock module. Therefore, this function routes the request. Change-Id: I0c1174cb861d2062882319e46cb6ca97bad70aab Signed-off-by: Ghennadi Procopciuc --- drivers/nxp/clk/s32cc/s32cc_clk_drv.c | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/nxp/clk/s32cc/s32cc_clk_drv.c b/drivers/nxp/clk/s32cc/s32cc_clk_drv.c index 810162b0b..ffbc3ac0e 100644 --- a/drivers/nxp/clk/s32cc/s32cc_clk_drv.c +++ b/drivers/nxp/clk/s32cc/s32cc_clk_drv.c @@ -1062,6 +1062,10 @@ static bool s32cc_clk_is_enabled(unsigned long id) 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) @@ -1138,6 +1142,36 @@ static int set_clk_freq(const struct s32cc_clk_obj *module, unsigned long rate, return -EINVAL; } +static int get_clk_freq(const struct s32cc_clk_obj *module, + const struct s32cc_clk_drv *drv, unsigned long *rate, + unsigned int depth) +{ + const struct s32cc_clk *clk = s32cc_obj2clk(module); + unsigned int ldepth = depth; + int ret; + + ret = update_stack_depth(&ldepth); + if (ret != 0) { + return ret; + } + + if (clk == NULL) { + ERROR("Invalid clock\n"); + return -EINVAL; + } + + if (clk->module != NULL) { + return get_module_rate(clk->module, drv, rate, ldepth); + } + + if (clk->pclock == NULL) { + ERROR("Invalid clock parent\n"); + return -EINVAL; + } + + return get_clk_freq(&clk->pclock->desc, drv, rate, ldepth); +} + static int set_pll_freq(const struct s32cc_clk_obj *module, unsigned long rate, unsigned long *orate, unsigned int *depth) { @@ -1354,6 +1388,9 @@ static int get_module_rate(const struct s32cc_clk_obj *module, case s32cc_osc_t: ret = get_osc_freq(module, drv, rate, ldepth); break; + case s32cc_clk_t: + ret = get_clk_freq(module, drv, rate, ldepth); + break; default: ret = -EINVAL; break;