public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND v2 1/2] clk: mediatek: mt8173-infracfg: Handle unallocated infracfg when module
@ 2024-06-12 20:11 Alper Nebi Yasak
  2024-06-12 20:11 ` [PATCH RESEND v2 2/2] arm64: dts: mediatek: mt8173: Fix timer 13 MHz clock description Alper Nebi Yasak
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alper Nebi Yasak @ 2024-06-12 20:11 UTC (permalink / raw)
  To: AngeloGioacchino Del Regno, linux-mediatek
  Cc: linux-kernel, Stephen Boyd, Rob Herring, devicetree,
	Michael Turquette, Uwe Kleine-König, Conor Dooley,
	linux-arm-kernel, Chen-Yu Tsai, Krzysztof Kozlowski,
	Matthias Brugger, linux-clk, Alper Nebi Yasak

The MT8173 infracfg clock driver does initialization in two steps, via a
CLK_OF_DECLARE_DRIVER declaration. However its early init function
doesn't get to run when it's built as a module, presumably since it's
not loaded by the time it would have been called by of_clk_init(). This
causes its second-step probe() to return -ENOMEM when trying to register
clocks, as the necessary clock_data struct isn't initialized by the
first step.

MT2701 and MT6797 clock drivers also use this mechanism, but they try to
allocate the necessary clock_data structure if missing in the second
step. Mimic that for the MT8173 infracfg clock as well to make it work
as a module.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
---

Changes in v2:
- Rewrite patch subject for consistency

v1: https://lore.kernel.org/lkml/20231108213734.140707-1-alpernebiyasak@gmail.com/

 drivers/clk/mediatek/clk-mt8173-infracfg.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/mediatek/clk-mt8173-infracfg.c b/drivers/clk/mediatek/clk-mt8173-infracfg.c
index 2f2f074e231a..ecc8b0063ea5 100644
--- a/drivers/clk/mediatek/clk-mt8173-infracfg.c
+++ b/drivers/clk/mediatek/clk-mt8173-infracfg.c
@@ -98,7 +98,17 @@ CLK_OF_DECLARE_DRIVER(mtk_infrasys, "mediatek,mt8173-infracfg",
 static int clk_mt8173_infracfg_probe(struct platform_device *pdev)
 {
 	struct device_node *node = pdev->dev.of_node;
-	int r;
+	int r, i;
+
+	if (!infra_clk_data) {
+		infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
+		if (!infra_clk_data)
+			return -ENOMEM;
+	} else {
+		for (i = 0; i < CLK_INFRA_NR_CLK; i++)
+			if (infra_clk_data->hws[i] == ERR_PTR(-EPROBE_DEFER))
+				infra_clk_data->hws[i] = ERR_PTR(-ENOENT);
+	}
 
 	r = mtk_clk_register_gates(&pdev->dev, node, infra_gates,
 				   ARRAY_SIZE(infra_gates), infra_clk_data);

base-commit: 03d44168cbd7fc57d5de56a3730427db758fc7f6
-- 
2.45.1


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

* [PATCH RESEND v2 2/2] arm64: dts: mediatek: mt8173: Fix timer 13 MHz clock description
  2024-06-12 20:11 [PATCH RESEND v2 1/2] clk: mediatek: mt8173-infracfg: Handle unallocated infracfg when module Alper Nebi Yasak
@ 2024-06-12 20:11 ` Alper Nebi Yasak
  2024-06-13  7:06 ` [PATCH RESEND v2 1/2] clk: mediatek: mt8173-infracfg: Handle unallocated infracfg when module AngeloGioacchino Del Regno
  2024-07-08 19:05 ` Stephen Boyd
  2 siblings, 0 replies; 4+ messages in thread
From: Alper Nebi Yasak @ 2024-06-12 20:11 UTC (permalink / raw)
  To: AngeloGioacchino Del Regno, linux-mediatek
  Cc: linux-kernel, Stephen Boyd, Rob Herring, devicetree,
	Michael Turquette, Uwe Kleine-König, Conor Dooley,
	linux-arm-kernel, Chen-Yu Tsai, Krzysztof Kozlowski,
	Matthias Brugger, linux-clk, Alper Nebi Yasak

A previous patch fixes an issue with the mt8173-infracfg clock driver
when working as a module, but has the side effect of skipping set up of
CLK_INFRA_CLK_13M in that case. This clock is used by the timer device.

Similar to the MT8183, MT8192, MT8195 and MT8186 cases [1], change the
input clock of the timer block a fixed factor divide-by-2 clock that
takes the 26 MHz oscillator as its input.

Also remove the RTC clock from the timer node while we're here. According
to commit 59311b19d7f63 ("clocksource/drivers/timer-mediatek: Add system
timer bindings") it is no longer used.

[1] https://lore.kernel.org/all/20221201084229.3464449-1-wenst@chromium.org/

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
---
Tested on a MT8173 Chromebook. But I'm not sure I understand all of
this, so review with a pinch of salt.

Changes in v2:
- Add this patch

 arch/arm64/boot/dts/mediatek/mt8173.dtsi | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8173.dtsi b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
index 3458be7f7f61..809b379b6818 100644
--- a/arch/arm64/boot/dts/mediatek/mt8173.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8173.dtsi
@@ -244,6 +244,15 @@ psci {
 		cpu_on	 = <0x84000003>;
 	};
 
+	clk13m: fixed-factor-clock-13m {
+		compatible = "fixed-factor-clock";
+		#clock-cells = <0>;
+		clocks = <&clk26m>;
+		clock-div = <2>;
+		clock-mult = <1>;
+		clock-output-names = "clk13m";
+	};
+
 	clk26m: oscillator0 {
 		compatible = "fixed-clock";
 		#clock-cells = <0>;
@@ -530,8 +539,7 @@ timer: timer@10008000 {
 				     "mediatek,mt6577-timer";
 			reg = <0 0x10008000 0 0x1000>;
 			interrupts = <GIC_SPI 144 IRQ_TYPE_LEVEL_LOW>;
-			clocks = <&infracfg CLK_INFRA_CLK_13M>,
-				 <&topckgen CLK_TOP_RTC_SEL>;
+			clocks = <&clk13m>;
 		};
 
 		pwrap: pwrap@1000d000 {
-- 
2.45.1


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

* Re: [PATCH RESEND v2 1/2] clk: mediatek: mt8173-infracfg: Handle unallocated infracfg when module
  2024-06-12 20:11 [PATCH RESEND v2 1/2] clk: mediatek: mt8173-infracfg: Handle unallocated infracfg when module Alper Nebi Yasak
  2024-06-12 20:11 ` [PATCH RESEND v2 2/2] arm64: dts: mediatek: mt8173: Fix timer 13 MHz clock description Alper Nebi Yasak
@ 2024-06-13  7:06 ` AngeloGioacchino Del Regno
  2024-07-08 19:05 ` Stephen Boyd
  2 siblings, 0 replies; 4+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-06-13  7:06 UTC (permalink / raw)
  To: Alper Nebi Yasak, linux-mediatek
  Cc: linux-kernel, Stephen Boyd, Rob Herring, devicetree,
	Michael Turquette, Uwe Kleine-König, Conor Dooley,
	linux-arm-kernel, Chen-Yu Tsai, Krzysztof Kozlowski,
	Matthias Brugger, linux-clk

Il 12/06/24 22:11, Alper Nebi Yasak ha scritto:
> The MT8173 infracfg clock driver does initialization in two steps, via a
> CLK_OF_DECLARE_DRIVER declaration. However its early init function
> doesn't get to run when it's built as a module, presumably since it's
> not loaded by the time it would have been called by of_clk_init(). This
> causes its second-step probe() to return -ENOMEM when trying to register
> clocks, as the necessary clock_data struct isn't initialized by the
> first step.
> 
> MT2701 and MT6797 clock drivers also use this mechanism, but they try to
> allocate the necessary clock_data structure if missing in the second
> step. Mimic that for the MT8173 infracfg clock as well to make it work
> as a module.
> 
> Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

> ---
> 
> Changes in v2:
> - Rewrite patch subject for consistency
> 
> v1: https://lore.kernel.org/lkml/20231108213734.140707-1-alpernebiyasak@gmail.com/
> 
>   drivers/clk/mediatek/clk-mt8173-infracfg.c | 12 +++++++++++-
>   1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/mediatek/clk-mt8173-infracfg.c b/drivers/clk/mediatek/clk-mt8173-infracfg.c
> index 2f2f074e231a..ecc8b0063ea5 100644
> --- a/drivers/clk/mediatek/clk-mt8173-infracfg.c
> +++ b/drivers/clk/mediatek/clk-mt8173-infracfg.c
> @@ -98,7 +98,17 @@ CLK_OF_DECLARE_DRIVER(mtk_infrasys, "mediatek,mt8173-infracfg",
>   static int clk_mt8173_infracfg_probe(struct platform_device *pdev)
>   {
>   	struct device_node *node = pdev->dev.of_node;
> -	int r;
> +	int r, i;
> +
> +	if (!infra_clk_data) {
> +		infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
> +		if (!infra_clk_data)
> +			return -ENOMEM;
> +	} else {
> +		for (i = 0; i < CLK_INFRA_NR_CLK; i++)
> +			if (infra_clk_data->hws[i] == ERR_PTR(-EPROBE_DEFER))
> +				infra_clk_data->hws[i] = ERR_PTR(-ENOENT);
> +	}
>   
>   	r = mtk_clk_register_gates(&pdev->dev, node, infra_gates,
>   				   ARRAY_SIZE(infra_gates), infra_clk_data);
> 
> base-commit: 03d44168cbd7fc57d5de56a3730427db758fc7f6


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

* Re: [PATCH RESEND v2 1/2] clk: mediatek: mt8173-infracfg: Handle unallocated infracfg when module
  2024-06-12 20:11 [PATCH RESEND v2 1/2] clk: mediatek: mt8173-infracfg: Handle unallocated infracfg when module Alper Nebi Yasak
  2024-06-12 20:11 ` [PATCH RESEND v2 2/2] arm64: dts: mediatek: mt8173: Fix timer 13 MHz clock description Alper Nebi Yasak
  2024-06-13  7:06 ` [PATCH RESEND v2 1/2] clk: mediatek: mt8173-infracfg: Handle unallocated infracfg when module AngeloGioacchino Del Regno
@ 2024-07-08 19:05 ` Stephen Boyd
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2024-07-08 19:05 UTC (permalink / raw)
  To: Alper Nebi Yasak, AngeloGioacchino Del Regno, linux-mediatek
  Cc: linux-kernel, Rob Herring, devicetree, Michael Turquette,
	Uwe Kleine-König, Conor Dooley, linux-arm-kernel,
	Chen-Yu Tsai, Krzysztof Kozlowski, Matthias Brugger, linux-clk,
	Alper Nebi Yasak

Quoting Alper Nebi Yasak (2024-06-12 13:11:00)
> The MT8173 infracfg clock driver does initialization in two steps, via a
> CLK_OF_DECLARE_DRIVER declaration. However its early init function
> doesn't get to run when it's built as a module, presumably since it's
> not loaded by the time it would have been called by of_clk_init(). This
> causes its second-step probe() to return -ENOMEM when trying to register
> clocks, as the necessary clock_data struct isn't initialized by the
> first step.
> 
> MT2701 and MT6797 clock drivers also use this mechanism, but they try to
> allocate the necessary clock_data structure if missing in the second
> step. Mimic that for the MT8173 infracfg clock as well to make it work
> as a module.
> 
> Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
> ---

Applied to clk-next

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

end of thread, other threads:[~2024-07-08 19:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-12 20:11 [PATCH RESEND v2 1/2] clk: mediatek: mt8173-infracfg: Handle unallocated infracfg when module Alper Nebi Yasak
2024-06-12 20:11 ` [PATCH RESEND v2 2/2] arm64: dts: mediatek: mt8173: Fix timer 13 MHz clock description Alper Nebi Yasak
2024-06-13  7:06 ` [PATCH RESEND v2 1/2] clk: mediatek: mt8173-infracfg: Handle unallocated infracfg when module AngeloGioacchino Del Regno
2024-07-08 19:05 ` Stephen Boyd

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