clk: check for disabled clock-provider in of_clk_get_hw_from_clkspec
PATCH 1/1 clk: check for disabled clock-provider in of_clk_get_hw_from_clkspec
of_clk_get_hw_from_clkspec checks all available clock-providers by compairing their of-nodes to the one from the clkspec. If no matching clock-provider is found, the function returns EPROBE_DEFER to cause a re-check at a later date.
If a matching clock-provider is found, a authoritative answer can be retrieved from it whether the clock exists or not.
This does not take into account that the clock-provider may never appear, because it's node is disabled. This can happen for example when a clock is optional, provided by a separate block which just never gets enabled.
One example of this happening is the rk3588's VOP, which has optional additional display-clock-supplies coming from PLLs inside the hdmiphy blocks. These can be used for better rates, but the system will also work without them.
The problem around that is described in the followups to:
https://lore.kernel.org/dri-devel/[email protected]/
As we already know the of-node of the presumed clock-provider, just add a check via of_device_is_available whether this is a "valid" device node. This prevents ethernal defer-loops.
--- drivers/clk/clk.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/clk/clk.c +4 -0
@@ -5258,6 +5258,10 @@ of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec)if (!clkspec)return ERR_PTR (-EINVAL ); +/* Check if node in clkspec is in disabled/fail state */ +if (!of_device_is_available (clkspec->np)) +return ERR_PTR (-ENOENT ); +mutex_lock (&of_clk_mutex);list_for_each_entry (provider, &of_clk_providers, link) {if (provider->node == clkspec->np) {
Signature · 1 line
2.47.2
Hi,
Quoted 17 lines · Heiko Stuebner
of_clk_get_hw_from_clkspecchecks all available clock-providers by compairing their of-nodes to the one from the clkspec. If no matching clock-provider is found, the function returnsEPROBE_DEFERto cause a re-check at a later date.If a matching clock-provider is found, a authoritative answer can be retrieved from it whether the clock exists or not.
This does not take into account that the clock-provider may never appear, because it's node is disabled. This can happen for example when a clock is optional, provided by a separate block which just never gets enabled.
One example of this happening is the rk3588's VOP, which has optional additional display-clock-supplies coming from PLLs inside the hdmiphy blocks. These can be used for better rates, but the system will also work without them.
Quoted 6 lines
The problem around that is described in the followups to:
https://lore.kernel.org/dri-devel/[email protected]/As we already know the of-node of the presumed clock-provider, just add a check via
of_device_is_availablewhether this is a "valid" device node. This prevents ethernal defer-loops.
if there is a respin:
s/ethernal/eternal
Quoted 2 lines
Signed-off-by Heiko Stuebner <[email protected]>---
Also seems useful for having a quick final error if a referenced clock node has not been enabled by accident during board bringup.
Thanks,
-- Sebastian
Quoted 21 lines
drivers/clk/clk.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/clk/clk.c +4
-0@@ -5258,6 +5258,10 @@ of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec)if (!clkspec)return ERR_PTR (-EINVAL ); +/* Check if node in clkspec is in disabled/fail state */ +if (!of_device_is_available (clkspec->np)) +return ERR_PTR (-ENOENT ); +mutex_lock (&of_clk_mutex);list_for_each_entry (provider, &of_clk_providers, link) {if (provider->node == clkspec->np) {Signature · 1 line
2.47.2
Hi,
Quoted 6 lines · Heiko Stuebner
of_clk_get_hw_from_clkspecchecks all available clock-providers by compairing their of-nodes to the one from the clkspec. If no matching clock-provider is found, the function returnsEPROBE_DEFERto cause a re-check at a later date.If a matching clock-provider is found, a authoritative answer can be
Nit: s/a authoritative/an authoritative/
Quoted 28 lines
retrieved from it whether the clock exists or not.
This does not take into account that the clock-provider may never appear, because it's node is disabled. This can happen for example when a clock is optional, provided by a separate block which just never gets enabled.
One example of this happening is the rk3588's VOP, which has optional additional display-clock-supplies coming from PLLs inside the hdmiphy blocks. These can be used for better rates, but the system will also work without them.
The problem around that is described in the followups to:
https://lore.kernel.org/dri-devel/[email protected]/As we already know the of-node of the presumed clock-provider, just add a check via
of_device_is_availablewhether this is a "valid" device node. This prevents ethernal defer-loops.Signed-off-by Heiko Stuebner <[email protected]>--- drivers/clk/clk.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/clk/clk.c +0
-0
drivers/clk/clk.c of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec) · line 5267
Quoted 10 lines
drivers/clk/clk.c +4
-0@@ -5258,6 +5258,10 @@ of_clk_get_hw_from_clkspec(struct of_phandle_args *clkspec)if (!clkspec)return ERR_PTR (-EINVAL ); +/* Check if node in clkspec is in disabled/fail state */ +if (!of_device_is_available (clkspec->np)) +return ERR_PTR (-ENOENT ); +mutex_lock (&of_clk_mutex);list_for_each_entry (provider, &of_clk_providers, link) {if (provider->node == clkspec->np) {
Without this patch applied, when disabling hdmi0 and hdptxphy0 nodes on Rock5B, rockchip-drm module fails to probe and hdmi1 output cannot be used anymore:
rockchip-drm display-subsystem: [drm] *ERROR* failed to get pll_hdmiphy0
After applying the patch, I confirm the error is gone and hdmi1 is functional again. Hence,
Thanks,
Cristian