devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] clk: mediatek: mt8183: Fix GPU/MFG clock rate changing
@ 2022-05-20  9:43 Chen-Yu Tsai
  2022-05-20  9:43 ` [PATCH 1/4] arm64: dts: mt8183: Fix Mali GPU clock Chen-Yu Tsai
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Chen-Yu Tsai @ 2022-05-20  9:43 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Matthias Brugger
  Cc: Chen-Yu Tsai, Rob Herring, Krzysztof Kozlowski, Chun-Jie Chen,
	Miles Chen, AngeloGioacchino Del Regno, linux-clk, devicetree,
	linux-arm-kernel, linux-mediatek, linux-kernel

Hi everyone,

This series fixes the clock rate changing for the GPU. This work came
about as part of adding DVFS support for the Mali GPU on MT8183, to
support efforts in testing the SVS patches [1] on MT8183.

This series fixes a couple things:

1. Fix the clock reference for the GPU. The device tree incorrectly
   references the top level PLL, when in fact it is fed from the clock
   gate in the MFGCFG block. Fixed in patch 1.

2. Clock rate requests on the MFG clock gate aren't propagated up the
   tree. Fixed in patch 2 by adding CLK_SET_RATE_PARENT.

3. MFG clock needs to be temporarily muxed away from MFG PLL during PLL
   reconfiguration, to avoid glitches. This is done using a notifier.
   The framework is added in patch 3, and added to the driver in patch 4.

This is based on my "clk: mediatek: Move to struct clk_hw provider APIs"
series version 3 [2], which was just merged.

Please have a look.

The GPU DVFS stuff will be sent separately, as that part is a bit more
contentious, and the changes span more subsystems.


Regards
ChenYu

[1] https://lore.kernel.org/linux-mediatek/20220516004311.18358-1-roger.lu@mediatek.com/
[2] https://lore.kernel.org/linux-mediatek/20220519071610.423372-1-wenst@chromium.org/

Chen-Yu Tsai (4):
  arm64: dts: mt8183: Fix Mali GPU clock
  clk: mediatek: mt8183: mfgcfg: Propagate rate changes to parent
  clk: mediatek: mux: add clk notifier functions
  clk: mediatek: mt8183: Add clk mux notifier for MFG mux

 arch/arm64/boot/dts/mediatek/mt8183.dtsi |  2 +-
 drivers/clk/mediatek/clk-mt8183-mfgcfg.c |  6 ++--
 drivers/clk/mediatek/clk-mt8183.c        | 21 ++++++++++++
 drivers/clk/mediatek/clk-mux.c           | 42 ++++++++++++++++++++++++
 drivers/clk/mediatek/clk-mux.h           | 15 +++++++++
 5 files changed, 82 insertions(+), 4 deletions(-)

-- 
2.36.1.124.g0e6072fb45-goog


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

* [PATCH 1/4] arm64: dts: mt8183: Fix Mali GPU clock
  2022-05-20  9:43 [PATCH 0/4] clk: mediatek: mt8183: Fix GPU/MFG clock rate changing Chen-Yu Tsai
@ 2022-05-20  9:43 ` Chen-Yu Tsai
  2022-05-20  9:43 ` [PATCH 2/4] clk: mediatek: mt8183: mfgcfg: Propagate rate changes to parent Chen-Yu Tsai
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Chen-Yu Tsai @ 2022-05-20  9:43 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Matthias Brugger
  Cc: Chen-Yu Tsai, Rob Herring, Krzysztof Kozlowski, Chun-Jie Chen,
	Miles Chen, AngeloGioacchino Del Regno, linux-clk, devicetree,
	linux-arm-kernel, linux-mediatek, linux-kernel

The actual clock feeding into the Mali GPU on the MT8183 is from the
clock gate in the MFGCFG block, not CLK_TOP_MFGPLL_CK from the TOPCKGEN
block, which itself is simply a pass-through placeholder for the MFGPLL
in the APMIXEDSYS block.

Fix the hardware description with the correct clock reference.

Fixes: a8168cebf1bc ("arm64: dts: mt8183: Add node for the Mali GPU")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
 arch/arm64/boot/dts/mediatek/mt8183.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8183.dtsi b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
index 01e650251928..6ced76a60aab 100644
--- a/arch/arm64/boot/dts/mediatek/mt8183.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
@@ -1368,7 +1368,7 @@ gpu: gpu@13040000 {
 				<GIC_SPI 278 IRQ_TYPE_LEVEL_LOW>;
 			interrupt-names = "job", "mmu", "gpu";
 
-			clocks = <&topckgen CLK_TOP_MFGPLL_CK>;
+			clocks = <&mfgcfg CLK_MFG_BG3D>;
 
 			power-domains =
 				<&spm MT8183_POWER_DOMAIN_MFG_CORE0>,
-- 
2.36.1.124.g0e6072fb45-goog


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

* [PATCH 2/4] clk: mediatek: mt8183: mfgcfg: Propagate rate changes to parent
  2022-05-20  9:43 [PATCH 0/4] clk: mediatek: mt8183: Fix GPU/MFG clock rate changing Chen-Yu Tsai
  2022-05-20  9:43 ` [PATCH 1/4] arm64: dts: mt8183: Fix Mali GPU clock Chen-Yu Tsai
@ 2022-05-20  9:43 ` Chen-Yu Tsai
  2022-05-20  9:43 ` [PATCH 3/4] clk: mediatek: mux: add clk notifier functions Chen-Yu Tsai
  2022-05-20  9:43 ` [PATCH 4/4] clk: mediatek: mt8183: Add clk mux notifier for MFG mux Chen-Yu Tsai
  3 siblings, 0 replies; 6+ messages in thread
From: Chen-Yu Tsai @ 2022-05-20  9:43 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Matthias Brugger
  Cc: Chen-Yu Tsai, Rob Herring, Krzysztof Kozlowski, Chun-Jie Chen,
	Miles Chen, AngeloGioacchino Del Regno, linux-clk, devicetree,
	linux-arm-kernel, linux-mediatek, linux-kernel

The only clock in the MT8183 MFGCFG block feeds the GPU. Propagate its
rate change requests to its parent, so that DVFS for the GPU can work
properly.

Fixes: acddfc2c261b ("clk: mediatek: Add MT8183 clock support")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
 drivers/clk/mediatek/clk-mt8183-mfgcfg.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/mediatek/clk-mt8183-mfgcfg.c b/drivers/clk/mediatek/clk-mt8183-mfgcfg.c
index d774edaf760b..230299728859 100644
--- a/drivers/clk/mediatek/clk-mt8183-mfgcfg.c
+++ b/drivers/clk/mediatek/clk-mt8183-mfgcfg.c
@@ -18,9 +18,9 @@ static const struct mtk_gate_regs mfg_cg_regs = {
 	.sta_ofs = 0x0,
 };
 
-#define GATE_MFG(_id, _name, _parent, _shift)			\
-	GATE_MTK(_id, _name, _parent, &mfg_cg_regs, _shift,	\
-		&mtk_clk_gate_ops_setclr)
+#define GATE_MFG(_id, _name, _parent, _shift)				\
+	GATE_MTK_FLAGS(_id, _name, _parent, &mfg_cg_regs, _shift,	\
+		       &mtk_clk_gate_ops_setclr, CLK_SET_RATE_PARENT)
 
 static const struct mtk_gate mfg_clks[] = {
 	GATE_MFG(CLK_MFG_BG3D, "mfg_bg3d", "mfg_sel", 0)
-- 
2.36.1.124.g0e6072fb45-goog


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

* [PATCH 3/4] clk: mediatek: mux: add clk notifier functions
  2022-05-20  9:43 [PATCH 0/4] clk: mediatek: mt8183: Fix GPU/MFG clock rate changing Chen-Yu Tsai
  2022-05-20  9:43 ` [PATCH 1/4] arm64: dts: mt8183: Fix Mali GPU clock Chen-Yu Tsai
  2022-05-20  9:43 ` [PATCH 2/4] clk: mediatek: mt8183: mfgcfg: Propagate rate changes to parent Chen-Yu Tsai
@ 2022-05-20  9:43 ` Chen-Yu Tsai
  2022-05-20  9:43 ` [PATCH 4/4] clk: mediatek: mt8183: Add clk mux notifier for MFG mux Chen-Yu Tsai
  3 siblings, 0 replies; 6+ messages in thread
From: Chen-Yu Tsai @ 2022-05-20  9:43 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Matthias Brugger
  Cc: Chen-Yu Tsai, Rob Herring, Krzysztof Kozlowski, Chun-Jie Chen,
	Miles Chen, AngeloGioacchino Del Regno, linux-clk, devicetree,
	linux-arm-kernel, linux-mediatek, linux-kernel

With device frequency scaling, the mux clock that (indirectly) feeds the
device selects between a dedicated PLL, and some other stable clocks.

When a clk rate change is requested, the (normally) upstream PLL is
reconfigured. It's possible for the clock output of the PLL to become
unstable during this process.

To avoid causing the device to glitch, the mux should temporarily be
switched over to another "stable" clock during the PLL rate change.
This is done with clk notifiers.

This patch adds common functions for notifiers to temporarily and
transparently reparent mux clocks.

This was loosely based on commit 8adfb08605a9 ("clk: sunxi-ng: mux: Add
clk notifier functions").

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
 drivers/clk/mediatek/clk-mux.c | 42 ++++++++++++++++++++++++++++++++++
 drivers/clk/mediatek/clk-mux.h | 15 ++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/drivers/clk/mediatek/clk-mux.c b/drivers/clk/mediatek/clk-mux.c
index cd5f9fd8cb98..f84a5a753c09 100644
--- a/drivers/clk/mediatek/clk-mux.c
+++ b/drivers/clk/mediatek/clk-mux.c
@@ -4,6 +4,7 @@
  * Author: Owen Chen <owen.chen@mediatek.com>
  */
 
+#include <linux/clk.h>
 #include <linux/clk-provider.h>
 #include <linux/compiler_types.h>
 #include <linux/container_of.h>
@@ -259,4 +260,45 @@ void mtk_clk_unregister_muxes(const struct mtk_mux *muxes, int num,
 }
 EXPORT_SYMBOL_GPL(mtk_clk_unregister_muxes);
 
+/*
+ * This clock notifier is called when the frequency of the of the parent
+ * PLL clock is to be changed. The idea is to switch the parent to a
+ * stable clock, such as the main oscillator, while the PLL frequency
+ * stabilizes.
+ */
+static int mtk_clk_mux_notifier_cb(struct notifier_block *nb,
+				   unsigned long event, void *_data)
+{
+	struct clk_notifier_data *data = _data;
+	struct mtk_mux_nb *mux_nb = to_mtk_mux_nb(nb);
+	const struct mtk_mux *mux = mux_nb->mux;
+	struct clk_hw *hw;
+	int ret = 0;
+
+	hw = __clk_get_hw(data->clk);
+
+	switch (event) {
+	case PRE_RATE_CHANGE:
+		mux_nb->original_index = mux->ops->get_parent(hw);
+		ret = mux->ops->set_parent(hw, mux_nb->bypass_index);
+		break;
+
+	case POST_RATE_CHANGE:
+	case ABORT_RATE_CHANGE:
+		ret = mux->ops->set_parent(hw, mux_nb->original_index);
+		break;
+	}
+
+	return notifier_from_errno(ret);
+}
+
+int devm_mtk_clk_mux_notifier_register(struct device *dev, struct clk *clk,
+				       struct mtk_mux_nb *mux_nb)
+{
+	mux_nb->nb.notifier_call = mtk_clk_mux_notifier_cb;
+
+	return devm_clk_notifier_register(dev, clk, &mux_nb->nb);
+}
+EXPORT_SYMBOL_GPL(devm_mtk_clk_mux_notifier_register);
+
 MODULE_LICENSE("GPL");
diff --git a/drivers/clk/mediatek/clk-mux.h b/drivers/clk/mediatek/clk-mux.h
index 6539c58f5d7d..506e91125a3d 100644
--- a/drivers/clk/mediatek/clk-mux.h
+++ b/drivers/clk/mediatek/clk-mux.h
@@ -7,12 +7,14 @@
 #ifndef __DRV_CLK_MTK_MUX_H
 #define __DRV_CLK_MTK_MUX_H
 
+#include <linux/notifier.h>
 #include <linux/spinlock.h>
 #include <linux/types.h>
 
 struct clk;
 struct clk_hw_onecell_data;
 struct clk_ops;
+struct device;
 struct device_node;
 
 struct mtk_mux {
@@ -89,4 +91,17 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes,
 void mtk_clk_unregister_muxes(const struct mtk_mux *muxes, int num,
 			      struct clk_hw_onecell_data *clk_data);
 
+struct mtk_mux_nb {
+	struct notifier_block	nb;
+	const struct mtk_mux	*mux;
+
+	u8	bypass_index;	/* Which parent to temporarily use */
+	u8	original_index;	/* Set by notifier callback */
+};
+
+#define to_mtk_mux_nb(_nb)	container_of(_nb, struct mtk_mux_nb, nb)
+
+int devm_mtk_clk_mux_notifier_register(struct device *dev, struct clk *clk,
+				       struct mtk_mux_nb *mux_nb);
+
 #endif /* __DRV_CLK_MTK_MUX_H */
-- 
2.36.1.124.g0e6072fb45-goog


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

* [PATCH 4/4] clk: mediatek: mt8183: Add clk mux notifier for MFG mux
  2022-05-20  9:43 [PATCH 0/4] clk: mediatek: mt8183: Fix GPU/MFG clock rate changing Chen-Yu Tsai
                   ` (2 preceding siblings ...)
  2022-05-20  9:43 ` [PATCH 3/4] clk: mediatek: mux: add clk notifier functions Chen-Yu Tsai
@ 2022-05-20  9:43 ` Chen-Yu Tsai
  2022-05-21  4:27   ` Stephen Boyd
  3 siblings, 1 reply; 6+ messages in thread
From: Chen-Yu Tsai @ 2022-05-20  9:43 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Matthias Brugger
  Cc: Chen-Yu Tsai, Rob Herring, Krzysztof Kozlowski, Chun-Jie Chen,
	Miles Chen, AngeloGioacchino Del Regno, linux-clk, devicetree,
	linux-arm-kernel, linux-mediatek, linux-kernel

When the MFG PLL clock, which is upstream of the MFG clock, is changed,
the downstream clock and consumers need to be switched away from the PLL
over to a stable clock to avoid glitches.

This is done through the use of the newly added clk mux notifier. The
notifier is set on the mux itself instead of the upstream PLL, but in
practice this works, as the rate change notifitcations are propogated
throughout the sub-tree hanging off the PLL. Just before rate changes,
the MFG mux is temporarily and transparently switched to the 26 MHz
main crystal. After the rate change, the mux is switched back.

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
 drivers/clk/mediatek/clk-mt8183.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/clk/mediatek/clk-mt8183.c b/drivers/clk/mediatek/clk-mt8183.c
index 8a755fadebb5..afef3738396e 100644
--- a/drivers/clk/mediatek/clk-mt8183.c
+++ b/drivers/clk/mediatek/clk-mt8183.c
@@ -1192,6 +1192,8 @@ static int clk_mt8183_top_probe(struct platform_device *pdev)
 {
 	void __iomem *base;
 	struct device_node *node = pdev->dev.of_node;
+	struct mtk_mux_nb *mfg_mux_nb;
+	int i, ret;
 
 	base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(base))
@@ -1217,6 +1219,25 @@ static int clk_mt8183_top_probe(struct platform_device *pdev)
 	mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
 		top_clk_data);
 
+	/* Register mux notifier for MFG mux */
+	mfg_mux_nb = devm_kzalloc(&pdev->dev, sizeof(*mfg_mux_nb), GFP_KERNEL);
+	if (!mfg_mux_nb)
+		return -ENOMEM;
+
+	for (i = 0; i < ARRAY_SIZE(top_muxes); i++)
+		if (top_muxes[i].id == CLK_TOP_MUX_MFG)
+			break;
+	if (i == ARRAY_SIZE(top_muxes))
+		return -EINVAL;
+
+	mfg_mux_nb->mux = &top_muxes[i];
+	mfg_mux_nb->bypass_index = 0; // Bypass to 26M crystal
+	ret = devm_mtk_clk_mux_notifier_register(&pdev->dev,
+						 top_clk_data->hws[CLK_TOP_MUX_MFG]->clk,
+						 mfg_mux_nb);
+	if (ret)
+		return ret;
+
 	return of_clk_add_hw_provider(node, of_clk_hw_onecell_get,
 				      top_clk_data);
 }
-- 
2.36.1.124.g0e6072fb45-goog


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

* Re: [PATCH 4/4] clk: mediatek: mt8183: Add clk mux notifier for MFG mux
  2022-05-20  9:43 ` [PATCH 4/4] clk: mediatek: mt8183: Add clk mux notifier for MFG mux Chen-Yu Tsai
@ 2022-05-21  4:27   ` Stephen Boyd
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Boyd @ 2022-05-21  4:27 UTC (permalink / raw)
  To: Chen-Yu Tsai, Matthias Brugger, Michael Turquette
  Cc: Chen-Yu Tsai, Rob Herring, Krzysztof Kozlowski, Chun-Jie Chen,
	Miles Chen, AngeloGioacchino Del Regno, linux-clk, devicetree,
	linux-arm-kernel, linux-mediatek, linux-kernel

Quoting Chen-Yu Tsai (2022-05-20 02:43:23)
> diff --git a/drivers/clk/mediatek/clk-mt8183.c b/drivers/clk/mediatek/clk-mt8183.c
> index 8a755fadebb5..afef3738396e 100644
> --- a/drivers/clk/mediatek/clk-mt8183.c
> +++ b/drivers/clk/mediatek/clk-mt8183.c
> @@ -1217,6 +1219,25 @@ static int clk_mt8183_top_probe(struct platform_device *pdev)
>         mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
>                 top_clk_data);
>  
> +       /* Register mux notifier for MFG mux */

This comment sort of indicates it should be another function for this
block called "register mfg mux notifier".

> +       mfg_mux_nb = devm_kzalloc(&pdev->dev, sizeof(*mfg_mux_nb), GFP_KERNEL);
> +       if (!mfg_mux_nb)
> +               return -ENOMEM;
> +
> +       for (i = 0; i < ARRAY_SIZE(top_muxes); i++)
> +               if (top_muxes[i].id == CLK_TOP_MUX_MFG)
> +                       break;
> +       if (i == ARRAY_SIZE(top_muxes))
> +               return -EINVAL;
> +
> +       mfg_mux_nb->mux = &top_muxes[i];
> +       mfg_mux_nb->bypass_index = 0; // Bypass to 26M crystal

Use /* these types of comments */

> +       ret = devm_mtk_clk_mux_notifier_register(&pdev->dev,
> +                                                top_clk_data->hws[CLK_TOP_MUX_MFG]->clk,
> +                                                mfg_mux_nb);
> +       if (ret)
> +               return ret;
> +
>         return of_clk_add_hw_provider(node, of_clk_hw_onecell_get,

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

end of thread, other threads:[~2022-05-21  4:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-20  9:43 [PATCH 0/4] clk: mediatek: mt8183: Fix GPU/MFG clock rate changing Chen-Yu Tsai
2022-05-20  9:43 ` [PATCH 1/4] arm64: dts: mt8183: Fix Mali GPU clock Chen-Yu Tsai
2022-05-20  9:43 ` [PATCH 2/4] clk: mediatek: mt8183: mfgcfg: Propagate rate changes to parent Chen-Yu Tsai
2022-05-20  9:43 ` [PATCH 3/4] clk: mediatek: mux: add clk notifier functions Chen-Yu Tsai
2022-05-20  9:43 ` [PATCH 4/4] clk: mediatek: mt8183: Add clk mux notifier for MFG mux Chen-Yu Tsai
2022-05-21  4:27   ` 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).