From 4124e115de82797f604808aaa5caad4512a9a1ed Mon Sep 17 00:00:00 2001 From: Icenowy Zheng Date: Mon, 14 Aug 2023 07:28:08 +0200 Subject: [PATCH 209/464] 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 --- 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 8d28a7a079d0..434fa46ad460 100644 --- a/drivers/clk/sunxi-ng/ccu_common.c +++ b/drivers/clk/sunxi-ng/ccu_common.c @@ -87,6 +87,28 @@ int ccu_pll_notifier_register(struct ccu_pll_nb *pll_nb) } EXPORT_SYMBOL_NS_GPL(ccu_pll_notifier_register, SUNXI_CCU); +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); +} + static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev, 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 fbf16c6b896d..6b0b05fae123 100644 --- a/drivers/clk/sunxi-ng/ccu_common.h +++ b/drivers/clk/sunxi-ng/ccu_common.h @@ -69,4 +69,16 @@ int devm_sunxi_ccu_probe(struct device *dev, void __iomem *reg, void of_sunxi_ccu_probe(struct device_node *node, void __iomem *reg, const struct sunxi_ccu_desc *desc); +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); + #endif /* _COMMON_H_ */ -- 2.34.1