clk: fixed-rate: Use "clock-output-names" to name fixed clocks
PATCH 1/1 clk: fixed-rate: Use "clock-output-names" to name fixed clocks
From: Fabio Estevam <[email protected]>
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.
--- drivers/clk/clk_fixed_rate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/clk/clk_fixed_rate.c +12 -0
@@ -35,6 +35,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 +47,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)
Signature · 1 line
2.34.1
Quoted 13 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
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"; };
Quoted 7 lines
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.
You read my mind! I just sent out an e-mail to the other thread with this very suggestion.
Quoted 4 lines
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.
Agreed.
Quoted 7 lines
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:
Quoted 8 lines
u-boot=> clk dump
Rate Usecnt Name
------------------------------------------32768 0 |-- osc_32k 24000000 5 |-- osc_24mThis change restores i.MX8MP USB functionality by ensuring the proper clock names are used.
Quoted 41 lines
Fixes b4734c9c333b ("clk: imx: Convert clock-osc-* back to osc_*")Reported-by Francesco Dolcini <[email protected]>Signed-off-by Fabio Estevam <[email protected]>--- drivers/clk/clk_fixed_rate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/clk/clk_fixed_rate.c +12
-1@@ -35,6 +35,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 +47,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
Hi Fabio,
Quoted 63 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
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_24mThis 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 <[email protected]>Signed-off-by Fabio Estevam <[email protected]>--- drivers/clk/clk_fixed_rate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/clk/clk_fixed_rate.c +2
-0@@ -35,6 +35,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 +47,16 @@ void clk_fixed_rate_ofdata_to_plat_(struct udevice *dev, clk->dev = dev; clk->enable_count =0 ;
drivers/clk/clk_fixed_rate.c void clk_fixed_rate_ofdata_to_plat_(struct udevice *dev, · line 59
Quoted 10 lines
drivers/clk/clk_fixed_rate.c +10
-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;
What about
dev_read_string_index(dev, "clock-output-names", 0, &dev->name);
so you don't need to store the return value in a temporary variable?
Cheers,
Quentin