[PATCH 2/4] clk: scmi: Factor out clock control flags resolution
Marek Vasut
marek.vasut+renesas at mailbox.org
Tue Oct 28 04:41:04 CET 2025
Pull clock control flags resolution into dedicated function and
call it from each site that does access clock control flags. No
functional change.
This is a preparatory patch for deferred issue of SCMI_CLOCK_ATTRIBUTES.
Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
---
Cc: Alice Guo <alice.guo at nxp.com>
Cc: Patrice Chotard <patrice.chotard at foss.st.com>
Cc: Patrick Delaunay <patrick.delaunay at foss.st.com>
Cc: Peng Fan <peng.fan at nxp.com>
Cc: Sean Anderson <seanga2 at gmail.com>
Cc: Tom Rini <trini at konsulko.com>
Cc: Valentin Caron <valentin.caron at foss.st.com>
Cc: Vinh Nguyen <vinh.nguyen.xz at renesas.com>
Cc: u-boot at lists.denx.de
---
drivers/clk/clk_scmi.c | 51 +++++++++++++++++++++++-------------------
1 file changed, 28 insertions(+), 23 deletions(-)
diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c
index 0b64c73a61d..3ee2df0ca9b 100644
--- a/drivers/clk/clk_scmi.c
+++ b/drivers/clk/clk_scmi.c
@@ -163,22 +163,36 @@ static int scmi_clk_gate(struct clk *clk, int enable)
return scmi_to_linux_errno(out.status);
}
-static int scmi_clk_enable(struct clk *clk)
+static int scmi_clk_get_ctrl_flags(struct clk *clk, u32 *ctrl_flags)
{
struct clk_scmi *clkscmi;
struct clk *c;
int ret;
- if (!CONFIG_IS_ENABLED(CLK_CCF))
- return scmi_clk_gate(clk, 1);
-
ret = clk_get_by_id(clk->id, &c);
if (ret)
return ret;
clkscmi = container_of(c, struct clk_scmi, clk);
- if (clkscmi->ctrl_flags & SUPPORT_CLK_STAT_CONTROL)
+ *ctrl_flags = clkscmi->ctrl_flags;
+
+ return 0;
+}
+
+static int scmi_clk_enable(struct clk *clk)
+{
+ u32 ctrl_flags;
+ int ret;
+
+ if (!CONFIG_IS_ENABLED(CLK_CCF))
+ return scmi_clk_gate(clk, 1);
+
+ ret = scmi_clk_get_ctrl_flags(clk, &ctrl_flags);
+ if (ret)
+ return ret;
+
+ if (ctrl_flags & SUPPORT_CLK_STAT_CONTROL)
return scmi_clk_gate(clk, 1);
/* Following Linux drivers/clk/clk-scmi.c, directly return 0 if agent has no permission. */
@@ -188,20 +202,17 @@ static int scmi_clk_enable(struct clk *clk)
static int scmi_clk_disable(struct clk *clk)
{
- struct clk_scmi *clkscmi;
- struct clk *c;
+ u32 ctrl_flags;
int ret;
if (!CONFIG_IS_ENABLED(CLK_CCF))
return scmi_clk_gate(clk, 0);
- ret = clk_get_by_id(clk->id, &c);
+ ret = scmi_clk_get_ctrl_flags(clk, &ctrl_flags);
if (ret)
return ret;
- clkscmi = container_of(c, struct clk_scmi, clk);
-
- if (clkscmi->ctrl_flags & SUPPORT_CLK_STAT_CONTROL)
+ if (ctrl_flags & SUPPORT_CLK_STAT_CONTROL)
return scmi_clk_gate(clk, 0);
/* Following Linux drivers/clk/clk-scmi.c, directly return 0 if agent has no permission. */
@@ -259,20 +270,17 @@ static ulong __scmi_clk_set_rate(struct clk *clk, ulong rate)
static ulong scmi_clk_set_rate(struct clk *clk, ulong rate)
{
- struct clk_scmi *clkscmi;
- struct clk *c;
+ u32 ctrl_flags;
int ret;
if (!CONFIG_IS_ENABLED(CLK_CCF))
return __scmi_clk_set_rate(clk, rate);
- ret = clk_get_by_id(clk->id, &c);
+ ret = scmi_clk_get_ctrl_flags(clk, &ctrl_flags);
if (ret)
return ret;
- clkscmi = container_of(c, struct clk_scmi, clk);
-
- if (clkscmi->ctrl_flags & SUPPORT_CLK_RATE_CONTROL)
+ if (ctrl_flags & SUPPORT_CLK_RATE_CONTROL)
return __scmi_clk_set_rate(clk, rate);
/* Following Linux drivers/clk/clk-scmi.c, directly return 0 if agent has no permission. */
@@ -374,20 +382,17 @@ static int __scmi_clk_set_parent(struct clk *clk, struct clk *parent)
static int scmi_clk_set_parent(struct clk *clk, struct clk *parent)
{
- struct clk_scmi *clkscmi;
- struct clk *c;
+ u32 ctrl_flags;
int ret;
if (!CONFIG_IS_ENABLED(CLK_CCF))
return -ENOTSUPP;
- ret = clk_get_by_id(clk->id, &c);
+ ret = scmi_clk_get_ctrl_flags(clk, &ctrl_flags);
if (ret)
return ret;
- clkscmi = container_of(c, struct clk_scmi, clk);
-
- if (clkscmi->ctrl_flags & SUPPORT_CLK_PARENT_CONTROL)
+ if (ctrl_flags & SUPPORT_CLK_PARENT_CONTROL)
return __scmi_clk_set_parent(clk, parent);
/* Following Linux drivers/clk/clk-scmi.c, directly return 0 if agent has no permission. */
--
2.51.0
More information about the U-Boot
mailing list