build/patch/kernel/archive/sunxi-5.15/patches.megous/clk-sunxi-ng-add-support-for-rate-resetting-notifier.patch

81 lines
2.7 KiB
Diff

From 0f44af555e03079b9b8d8ed9833fa0fda67cd4a1 Mon Sep 17 00:00:00 2001
From: Icenowy Zheng <icenowy@aosc.io>
Date: Wed, 17 Jun 2020 08:39:18 +0800
Subject: [PATCH 306/478] clk: sunxi-ng: add support for rate resetting
notifier
In some situaitons, we will want a clock rate be kept while its parent
can change, for example, to make dual-head work on A64, TCON0 clock
needs to be kept for LCD display and its parent (or grandparent)
PLL-Video0 need to be changed for HDMI display. (There's a quirk on A64
that HDMI PHY can only use PLL-Video0, not PLL-Video1).
Add a notifier helper to create such kind of rate keeping notifier by
reset the rate after the parent changed.
Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
---
drivers/clk/sunxi-ng/ccu_common.c | 22 ++++++++++++++++++++++
drivers/clk/sunxi-ng/ccu_common.h | 12 ++++++++++++
2 files changed, 34 insertions(+)
diff --git a/drivers/clk/sunxi-ng/ccu_common.c b/drivers/clk/sunxi-ng/ccu_common.c
index 88cb569e5..5627b6a13 100644
--- a/drivers/clk/sunxi-ng/ccu_common.c
+++ b/drivers/clk/sunxi-ng/ccu_common.c
@@ -194,6 +194,28 @@ int devm_sunxi_ccu_probe(struct device *dev, void __iomem *reg,
return 0;
}
+static int ccu_rate_reset_notifier_cb(struct notifier_block *nb,
+ unsigned long event, void *data)
+{
+ struct ccu_rate_reset_nb *rate_reset = to_ccu_rate_reset_nb(nb);
+
+ if (event == PRE_RATE_CHANGE) {
+ rate_reset->saved_rate = clk_get_rate(rate_reset->target_clk);
+ } else if (event == POST_RATE_CHANGE) {
+ clk_set_rate(rate_reset->target_clk, rate_reset->saved_rate);
+ }
+
+ return NOTIFY_DONE;
+}
+
+int ccu_rate_reset_notifier_register(struct ccu_rate_reset_nb *rate_reset_nb)
+{
+ rate_reset_nb->clk_nb.notifier_call = ccu_rate_reset_notifier_cb;
+
+ return clk_notifier_register(rate_reset_nb->common->hw.clk,
+ &rate_reset_nb->clk_nb);
+}
+
void of_sunxi_ccu_probe(struct device_node *node, void __iomem *reg,
const struct sunxi_ccu_desc *desc)
{
diff --git a/drivers/clk/sunxi-ng/ccu_common.h b/drivers/clk/sunxi-ng/ccu_common.h
index 98a1834b5..4faee6619 100644
--- a/drivers/clk/sunxi-ng/ccu_common.h
+++ b/drivers/clk/sunxi-ng/ccu_common.h
@@ -63,6 +63,18 @@ struct ccu_pll_nb {
int ccu_pll_notifier_register(struct ccu_pll_nb *pll_nb);
+struct ccu_rate_reset_nb {
+ struct notifier_block clk_nb;
+ struct ccu_common *common;
+
+ struct clk *target_clk;
+ unsigned long saved_rate;
+};
+
+#define to_ccu_rate_reset_nb(_nb) container_of(_nb, struct ccu_rate_reset_nb, clk_nb)
+
+int ccu_rate_reset_notifier_register(struct ccu_rate_reset_nb *rate_reset_nb);
+
int devm_sunxi_ccu_probe(struct device *dev, void __iomem *reg,
const struct sunxi_ccu_desc *desc);
void of_sunxi_ccu_probe(struct device_node *node, void __iomem *reg,
--
2.35.3