linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] clk: Introduce CLK_ASSUME_ENABLED_WHEN_UNUSED
@ 2021-12-03  3:54 Bjorn Andersson
  2021-12-03  3:54 ` [PATCH 2/2] clk: qcom: sm8250-dispcc: Flag shared RCGs as assumed enable Bjorn Andersson
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Bjorn Andersson @ 2021-12-03  3:54 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Bjorn Andersson, dmitry.baryshkov
  Cc: linux-clk, linux-kernel, linux-arm-msm

Some clock implementations doesn't provide means of implementing
is_enabled(), but still requires to be explicitly disabled when found
unused as part of clk_disable_unused().

One such set of clocks are Qualcomm's display RCGs. These can be enabled
and disabled automatically by the hardware, so it's not possible to
reliably query their configuration. Further more, these clocks need to
be disabled when unused, to allow them to be "parked" onto a safe
parent. Failure to disable the RCG results in the hardware locking up as
clk_disable_unused() traverses up the tree and turns off its source
clocks.

Add a new flag, CLK_ASSUME_ENABLED_BOOT, which clock drivers can use to
signal that these clocks should be disabled even if they don't implement
the is_enabled() ops.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---
 drivers/clk/clk.c            | 2 +-
 include/linux/clk-provider.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index f467d63bbf1e..e0bb53cbd4c8 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1265,7 +1265,7 @@ static void __init clk_disable_unused_subtree(struct clk_core *core)
 	 * sequence.  call .disable_unused if available, otherwise fall
 	 * back to .disable
 	 */
-	if (clk_core_is_enabled(core)) {
+	if (clk_core_is_enabled(core) || core->flags & CLK_ASSUME_ENABLED_WHEN_UNUSED) {
 		trace_clk_disable(core);
 		if (core->ops->disable_unused)
 			core->ops->disable_unused(core->hw);
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index f59c875271a0..7661cce31fa1 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -32,6 +32,8 @@
 #define CLK_OPS_PARENT_ENABLE	BIT(12)
 /* duty cycle call may be forwarded to the parent clock */
 #define CLK_DUTY_CYCLE_PARENT	BIT(13)
+/* assume clock is enabled if found unused in late init */
+#define CLK_ASSUME_ENABLED_WHEN_UNUSED	BIT(14)
 
 struct clk;
 struct clk_hw;
-- 
2.33.1


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

* [PATCH 2/2] clk: qcom: sm8250-dispcc: Flag shared RCGs as assumed enable
  2021-12-03  3:54 [PATCH 1/2] clk: Introduce CLK_ASSUME_ENABLED_WHEN_UNUSED Bjorn Andersson
@ 2021-12-03  3:54 ` Bjorn Andersson
  2021-12-07  5:05   ` Vinod Koul
  2021-12-07  5:04 ` [PATCH 1/2] clk: Introduce CLK_ASSUME_ENABLED_WHEN_UNUSED Vinod Koul
  2021-12-09  8:56 ` Stephen Boyd
  2 siblings, 1 reply; 5+ messages in thread
From: Bjorn Andersson @ 2021-12-03  3:54 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Bjorn Andersson, dmitry.baryshkov
  Cc: linux-clk, linux-kernel, linux-arm-msm

The state of the shared RCGs found in the SM8250 dispcc can't reliably
be queried and hence doesn't implement the is_enabled() callback.

Mark the shared RCGs as CLK_ASSUME_ENABLED_WHEN_UNUSED, to ensure that
clk_disable_unused() will issue a disable and park the RCGs before it
turns off the parent PLLs - which will lock up these RCGs in any system
with continuous splash enabled.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---
 drivers/clk/qcom/dispcc-sm8250.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/qcom/dispcc-sm8250.c b/drivers/clk/qcom/dispcc-sm8250.c
index 2842e2b6f4a4..f7c7c829553e 100644
--- a/drivers/clk/qcom/dispcc-sm8250.c
+++ b/drivers/clk/qcom/dispcc-sm8250.c
@@ -218,7 +218,7 @@ static struct clk_rcg2 disp_cc_mdss_ahb_clk_src = {
 		.name = "disp_cc_mdss_ahb_clk_src",
 		.parent_data = disp_cc_parent_data_3,
 		.num_parents = ARRAY_SIZE(disp_cc_parent_data_3),
-		.flags = CLK_SET_RATE_PARENT,
+		.flags = CLK_SET_RATE_PARENT | CLK_ASSUME_ENABLED_WHEN_UNUSED,
 		.ops = &clk_rcg2_shared_ops,
 	},
 };
@@ -550,7 +550,7 @@ static struct clk_rcg2 disp_cc_mdss_mdp_clk_src = {
 		.name = "disp_cc_mdss_mdp_clk_src",
 		.parent_data = disp_cc_parent_data_5,
 		.num_parents = ARRAY_SIZE(disp_cc_parent_data_5),
-		.flags = CLK_SET_RATE_PARENT,
+		.flags = CLK_SET_RATE_PARENT | CLK_ASSUME_ENABLED_WHEN_UNUSED,
 		.ops = &clk_rcg2_shared_ops,
 	},
 };
@@ -602,7 +602,7 @@ static struct clk_rcg2 disp_cc_mdss_rot_clk_src = {
 		.name = "disp_cc_mdss_rot_clk_src",
 		.parent_data = disp_cc_parent_data_5,
 		.num_parents = ARRAY_SIZE(disp_cc_parent_data_5),
-		.flags = CLK_SET_RATE_PARENT,
+		.flags = CLK_SET_RATE_PARENT | CLK_ASSUME_ENABLED_WHEN_UNUSED,
 		.ops = &clk_rcg2_shared_ops,
 	},
 };
-- 
2.33.1


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

* Re: [PATCH 1/2] clk: Introduce CLK_ASSUME_ENABLED_WHEN_UNUSED
  2021-12-03  3:54 [PATCH 1/2] clk: Introduce CLK_ASSUME_ENABLED_WHEN_UNUSED Bjorn Andersson
  2021-12-03  3:54 ` [PATCH 2/2] clk: qcom: sm8250-dispcc: Flag shared RCGs as assumed enable Bjorn Andersson
@ 2021-12-07  5:04 ` Vinod Koul
  2021-12-09  8:56 ` Stephen Boyd
  2 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2021-12-07  5:04 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Michael Turquette, Stephen Boyd, dmitry.baryshkov, linux-clk,
	linux-kernel, linux-arm-msm

On 02-12-21, 19:54, Bjorn Andersson wrote:
> Some clock implementations doesn't provide means of implementing
> is_enabled(), but still requires to be explicitly disabled when found
> unused as part of clk_disable_unused().
> 
> One such set of clocks are Qualcomm's display RCGs. These can be enabled
> and disabled automatically by the hardware, so it's not possible to
> reliably query their configuration. Further more, these clocks need to
> be disabled when unused, to allow them to be "parked" onto a safe
> parent. Failure to disable the RCG results in the hardware locking up as
> clk_disable_unused() traverses up the tree and turns off its source
> clocks.
> 
> Add a new flag, CLK_ASSUME_ENABLED_BOOT, which clock drivers can use to
> signal that these clocks should be disabled even if they don't implement
> the is_enabled() ops.

I think the name is bit long, but can't think of anything better. Btw
the explanation in log is _very_ good. I think we need to capture this
in the header file below as well.

Reviewed-by: Vinod Koul <vkoul@kernel.org>

> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---
>  drivers/clk/clk.c            | 2 +-
>  include/linux/clk-provider.h | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index f467d63bbf1e..e0bb53cbd4c8 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -1265,7 +1265,7 @@ static void __init clk_disable_unused_subtree(struct clk_core *core)
>  	 * sequence.  call .disable_unused if available, otherwise fall
>  	 * back to .disable
>  	 */
> -	if (clk_core_is_enabled(core)) {
> +	if (clk_core_is_enabled(core) || core->flags & CLK_ASSUME_ENABLED_WHEN_UNUSED) {
>  		trace_clk_disable(core);
>  		if (core->ops->disable_unused)
>  			core->ops->disable_unused(core->hw);
> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
> index f59c875271a0..7661cce31fa1 100644
> --- a/include/linux/clk-provider.h
> +++ b/include/linux/clk-provider.h
> @@ -32,6 +32,8 @@
>  #define CLK_OPS_PARENT_ENABLE	BIT(12)
>  /* duty cycle call may be forwarded to the parent clock */
>  #define CLK_DUTY_CYCLE_PARENT	BIT(13)
> +/* assume clock is enabled if found unused in late init */
> +#define CLK_ASSUME_ENABLED_WHEN_UNUSED	BIT(14)
>  
>  struct clk;
>  struct clk_hw;
> -- 
> 2.33.1

-- 
~Vinod

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

* Re: [PATCH 2/2] clk: qcom: sm8250-dispcc: Flag shared RCGs as assumed enable
  2021-12-03  3:54 ` [PATCH 2/2] clk: qcom: sm8250-dispcc: Flag shared RCGs as assumed enable Bjorn Andersson
@ 2021-12-07  5:05   ` Vinod Koul
  0 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2021-12-07  5:05 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Michael Turquette, Stephen Boyd, dmitry.baryshkov, linux-clk,
	linux-kernel, linux-arm-msm

On 02-12-21, 19:54, Bjorn Andersson wrote:
> The state of the shared RCGs found in the SM8250 dispcc can't reliably
> be queried and hence doesn't implement the is_enabled() callback.
> 
> Mark the shared RCGs as CLK_ASSUME_ENABLED_WHEN_UNUSED, to ensure that
> clk_disable_unused() will issue a disable and park the RCGs before it
> turns off the parent PLLs - which will lock up these RCGs in any system
> with continuous splash enabled.

Reviewed-by: Vinod Koul <vkoul@kernel.org>

-- 
~Vinod

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

* Re: [PATCH 1/2] clk: Introduce CLK_ASSUME_ENABLED_WHEN_UNUSED
  2021-12-03  3:54 [PATCH 1/2] clk: Introduce CLK_ASSUME_ENABLED_WHEN_UNUSED Bjorn Andersson
  2021-12-03  3:54 ` [PATCH 2/2] clk: qcom: sm8250-dispcc: Flag shared RCGs as assumed enable Bjorn Andersson
  2021-12-07  5:04 ` [PATCH 1/2] clk: Introduce CLK_ASSUME_ENABLED_WHEN_UNUSED Vinod Koul
@ 2021-12-09  8:56 ` Stephen Boyd
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2021-12-09  8:56 UTC (permalink / raw)
  To: Bjorn Andersson, Michael Turquette, dmitry.baryshkov
  Cc: linux-clk, linux-kernel, linux-arm-msm

Quoting Bjorn Andersson (2021-12-02 19:54:35)
> Some clock implementations doesn't provide means of implementing
> is_enabled(), but still requires to be explicitly disabled when found
> unused as part of clk_disable_unused().
> 
> One such set of clocks are Qualcomm's display RCGs. These can be enabled
> and disabled automatically by the hardware, so it's not possible to
> reliably query their configuration. Further more, these clocks need to
> be disabled when unused, to allow them to be "parked" onto a safe
> parent. Failure to disable the RCG results in the hardware locking up as
> clk_disable_unused() traverses up the tree and turns off its source
> clocks.
> 
> Add a new flag, CLK_ASSUME_ENABLED_BOOT, which clock drivers can use to
> signal that these clocks should be disabled even if they don't implement
> the is_enabled() ops.
> 
> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---

I'm inclined to remove the disable unused logic. It is the main cause of
problems in the clk framework and with android pushing everyone to use
modules it's become a more broken design in need of an actual fix.  The
best approach is probably to just rip it out and start over, kicking off
the process for someone to fix the power regression of any clks that are
left enabled at boot. Or we can take the regulator approach and delay
disabling for 30 seconds and keep it around.

I'd prefer we take the approach of parking clks at init instead as
Dmitry proposed. It will break continuous splash screen but I don't
think that's being used anyway?

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

end of thread, other threads:[~2021-12-09  8:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-03  3:54 [PATCH 1/2] clk: Introduce CLK_ASSUME_ENABLED_WHEN_UNUSED Bjorn Andersson
2021-12-03  3:54 ` [PATCH 2/2] clk: qcom: sm8250-dispcc: Flag shared RCGs as assumed enable Bjorn Andersson
2021-12-07  5:05   ` Vinod Koul
2021-12-07  5:04 ` [PATCH 1/2] clk: Introduce CLK_ASSUME_ENABLED_WHEN_UNUSED Vinod Koul
2021-12-09  8:56 ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).