The clock names are retrived via SCMI_CLOCK_ATTRIBUTES, called for each
clock ID. This may take a lot of time to complete and is not strictly
necessary. Register each clock as "scmi-%zu" instead, and let the first
call of SCMI_CLOCK_ATTRIBUTES fill in the actual clock name.

This has a side effect, which can be considered both an upside and also
a downside. Unused clock are never renamed and retain their placeholder
"scmi-%zu" name, which avoids empty clock names for nameless SCMI clock,
and avoids the name resolution and improves boot time. But for those
SCMI clock which do have name, that name is not listed until the clock
are used.

This is a preparatory patch for deferred issue of SCMI_CLOCK_ATTRIBUTES.

Reviewed-by: Peng Fan <[email protected]>
Signed-off-by: Marek Vasut <[email protected]>
---
Cc: Alice Guo <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Sean Anderson <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Valentin Caron <[email protected]>
Cc: Vinh Nguyen <[email protected]>
Cc: [email protected]
---
V2: Add RB from Peng
V3: No change
---
 drivers/clk/clk_scmi.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c
index 1a6a6ae464c..9bb41eddbba 100644
--- a/drivers/clk/clk_scmi.c
+++ b/drivers/clk/clk_scmi.c
@@ -17,6 +17,7 @@
 
 struct clk_scmi {
        struct clk clk;
+       char name[SCMI_CLOCK_NAME_LENGTH_MAX];
        u32 ctrl_flags;
 };
 
@@ -325,25 +326,21 @@ static int scmi_clk_probe(struct udevice *dev)
                return -ENOMEM;
 
        for (i = 0; i < num_clocks; i++) {
-               char *clock_name;
+               clk_scmi = clk_scmi_bulk + i;
+               char *clock_name = clk_scmi->name;
                u32 attributes;
 
-               if (!scmi_clk_get_attibute(dev, i, &clock_name, &attributes)) {
-                       clk_scmi = clk_scmi_bulk + i;
-                       if (!clock_name)
-                               ret = -ENOMEM;
-                       else
-                               ret = clk_register(&clk_scmi->clk, 
dev->driver->name,
-                                                  clock_name, dev->name);
-
-                       if (ret) {
-                               free(clock_name);
-                               return ret;
-                       }
+               snprintf(clock_name, SCMI_CLOCK_NAME_LENGTH_MAX, "scmi-%zu", i);
+
+               ret = clk_register(&clk_scmi->clk, dev->driver->name,
+                                  clock_name, dev->name);
+               if (ret)
+                       return ret;
 
-                       dev_clk_dm(dev, i, &clk_scmi->clk);
-                       dev_set_parent_priv(clk_scmi->clk.dev, priv);
+               dev_clk_dm(dev, i, &clk_scmi->clk);
+               dev_set_parent_priv(clk_scmi->clk.dev, priv);
 
+               if (!scmi_clk_get_attibute(dev, i, &clock_name, &attributes)) {
                        if (CLK_HAS_RESTRICTIONS(attributes)) {
                                u32 perm;
 
-- 
2.51.0

Reply via email to