U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] clk: fixed-rate: Use "clock-output-names" to name fixed clocks
@ 2025-04-17 17:11 Fabio Estevam
  2025-04-18 14:51 ` Marek Vasut
  0 siblings, 1 reply; 20+ messages in thread
From: Fabio Estevam @ 2025-04-17 17:11 UTC (permalink / raw)
  To: trini
  Cc: lukma, seanga2, marex, francesco.dolcini, aford173, u-boot,
	Fabio Estevam

From: Fabio Estevam <festevam@denx.de>

Currently, fixed-rate clocks in U-Boot are named based on their devicetree
node names. For example, given the following node:

osc_24m: clock-osc-24m {
	compatible = "fixed-clock";
	#clock-cells = <0>;
	clock-frequency = <24000000>;
	clock-output-names = "osc_24m";
};

U-Boot registers the clock as "clock-osc-24m", derived from the node name,
ignoring the clock-output-names property.

This differs from Linux, which uses the clock-output-names property when
assigning clock names. As a result, clock consumers expecting names
like "osc_24m" (as defined in the property) may fail to resolve clocks
correctly in U-Boot.

Update the fixed-rate clock driver to check for the clock-output-names
property and use it as the clock name if present. If not, the fallback
remains the node name. This makes U-Boot behavior consistent with Linux.

One concrete impact is on i.MX8MP, where USB clock lookup failed following
commit b4734c9c333b ("clk: imx: Convert clock-osc-* back to osc_*").

With this change applied, fixed-clocks are correctly registered with their
expected names:

u-boot=> clk dump
 Rate               Usecnt      Name
------------------------------------------
 32768                0        |-- osc_32k
 24000000             5        |-- osc_24m

This change restores i.MX8MP USB functionality by ensuring the proper clock
names are used.

Fixes: b4734c9c333b ("clk: imx: Convert clock-osc-* back to osc_*")
Reported-by: Francesco Dolcini <francesco.dolcini@toradex.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>
Tested-by: Adam Ford <aford173@gmail.com> #imx8mp-beacon
---
Changes since v1:
- Included <dm/read.h> that defines dev_read_string_index() instead
of relying on indirect inclusion via <dm.h>.
- Removed superflous parenthesis around dev_read_string_index().
- Added Adam's Reviewed-by tag.

 drivers/clk/clk_fixed_rate.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/clk/clk_fixed_rate.c b/drivers/clk/clk_fixed_rate.c
index d1da05cc18a5..648e31b4fe14 100644
--- a/drivers/clk/clk_fixed_rate.c
+++ b/drivers/clk/clk_fixed_rate.c
@@ -9,6 +9,7 @@
 #include <dm.h>
 #include <log.h>
 #include <dm/device-internal.h>
+#include <dm/read.h>
 #include <linux/clk-provider.h>
 
 #define UBOOT_DM_CLK_FIXED_RATE "fixed_rate_clock"
@@ -35,6 +36,8 @@ void clk_fixed_rate_ofdata_to_plat_(struct udevice *dev,
 				    struct clk_fixed_rate *plat)
 {
 	struct clk *clk = &plat->clk;
+	const char *clk_name;
+
 	if (CONFIG_IS_ENABLED(OF_REAL))
 		plat->fixed_rate = dev_read_u32_default(dev, "clock-frequency",
 							0);
@@ -45,6 +48,16 @@ void clk_fixed_rate_ofdata_to_plat_(struct udevice *dev,
 
 	clk->dev = dev;
 	clk->enable_count = 0;
+
+	/*
+	 * If the "clock-output-names" property is present, use it
+	 * as the clock name, like it is done in Linux.
+	 * Otherwise, the original behavior will be preserved: the fixed clock
+	 * name will be its node name.
+	 *
+	 */
+	if (!dev_read_string_index(dev, "clock-output-names", 0, &clk_name))
+		dev->name = clk_name;
 }
 
 static ulong clk_fixed_rate_raw_get_rate(struct clk *clk)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2025-04-25 17:17 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-17 17:11 [PATCH v2] clk: fixed-rate: Use "clock-output-names" to name fixed clocks Fabio Estevam
2025-04-18 14:51 ` Marek Vasut
2025-04-19 12:59   ` Adam Ford
2025-04-19 22:51     ` Marek Vasut
2025-04-19 19:11   ` Fabio Estevam
2025-04-19 20:40     ` Adam Ford
2025-04-20  0:47       ` Marek Vasut
2025-04-20  1:07         ` Fabio Estevam
2025-04-20 19:20           ` Marek Vasut
2025-04-21 23:29             ` Adam Ford
2025-04-25  2:02             ` Fabio Estevam
2025-04-25  2:20               ` Marek Vasut
2025-04-25  2:35                 ` Fabio Estevam
2025-04-25  2:37                   ` Adam Ford
2025-04-25  2:59                     ` Adam Ford
2025-04-25 12:55                   ` Fabio Estevam
2025-04-25 13:55                     ` Fabio Estevam
2025-04-25 17:14                       ` Marek Vasut
2025-04-25 17:13                     ` Marek Vasut
2025-04-19 22:52     ` Marek Vasut

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox