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 <ghennadi.procopciuc@nxp.com>
diff --git a/drivers/nxp/clk/s32cc/s32cc_clk_drv.c b/drivers/nxp/clk/s32cc/s32cc_clk_drv.c
index 810162b..ffbc3ac 100644
--- a/drivers/nxp/clk/s32cc/s32cc_clk_drv.c
+++ b/drivers/nxp/clk/s32cc/s32cc_clk_drv.c
@@ -1062,6 +1062,10 @@
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 @@
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 @@
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;