[Letux-kernel] Fwd: [PATCH 4/7] clk: ingenic: tcu: Embed syscore_ops in TCU context

H. Nikolaus Schaller hns at goldelico.com
Mon Feb 17 17:55:30 CET 2025


Hi Paul,
this is likely something we should have a look at.

(Note that there is also a PATCH 1/7] syscore: Pass context data to callbacks needed)

BR,
Nikolaus

> Anfang der weitergeleiteten Nachricht:
> 
> Von: Thierry Reding <thierry.reding at gmail.com>
> Betreff: [PATCH 4/7] clk: ingenic: tcu: Embed syscore_ops in TCU context
> Datum: 17. Februar 2025 um 17:37:10 MEZ
> An: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
> Kopie: x86 at kernel.org, linux-arm-kernel at lists.infradead.org, linux-riscv at lists.infradead.org, linux-mips at vger.kernel.org, loongarch at lists.linux.dev, linuxppc-dev at lists.ozlabs.org, linux-sh at vger.kernel.org, linux-pci at vger.kernel.org, linux-acpi at vger.kernel.org, linux-kernel at vger.kernel.org
> 
> From: Thierry Reding <treding at nvidia.com>
> 
> This enables the syscore callbacks to obtain the TCU context without
> relying on a separate global variable.
> 
> Signed-off-by: Thierry Reding <treding at nvidia.com>
> ---
> drivers/clk/ingenic/tcu.c | 54 ++++++++++++++++++---------------------
> 1 file changed, 25 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/clk/ingenic/tcu.c b/drivers/clk/ingenic/tcu.c
> index 85bd4bc73c1b..503a58d08224 100644
> --- a/drivers/clk/ingenic/tcu.c
> +++ b/drivers/clk/ingenic/tcu.c
> @@ -53,9 +53,9 @@ struct ingenic_tcu {
> struct clk *clk;
> 
> struct clk_hw_onecell_data *clocks;
> -};
> 
> -static struct ingenic_tcu *ingenic_tcu;
> + struct syscore_ops syscore;
> +};
> 
> static inline struct ingenic_tcu_clk *to_tcu_clk(struct clk_hw *hw)
> {
> @@ -332,6 +332,24 @@ static const struct of_device_id __maybe_unused ingenic_tcu_of_match[] __initcon
> { /* sentinel */ }
> };
> 
> +static int __maybe_unused tcu_pm_suspend(struct syscore_ops *ops)
> +{
> + struct ingenic_tcu *tcu = container_of(ops, typeof(*tcu), syscore);
> +
> + if (tcu->clk)
> + clk_disable(tcu->clk);
> +
> + return 0;
> +}
> +
> +static void __maybe_unused tcu_pm_resume(struct syscore_ops *ops)
> +{
> + struct ingenic_tcu *tcu = container_of(ops, typeof(*tcu), syscore);
> +
> + if (tcu->clk)
> + clk_enable(tcu->clk);
> +}
> +
> static int __init ingenic_tcu_probe(struct device_node *np)
> {
> const struct of_device_id *id = of_match_node(ingenic_tcu_of_match, np);
> @@ -430,7 +448,11 @@ static int __init ingenic_tcu_probe(struct device_node *np)
> goto err_unregister_ost_clock;
> }
> 
> - ingenic_tcu = tcu;
> + if (IS_ENABLED(CONFIG_PM_SLEEP)) {
> + tcu->syscore.suspend = tcu_pm_suspend;
> + tcu->syscore.resume = tcu_pm_resume;
> + register_syscore_ops(&tcu->syscore);
> + }
> 
> return 0;
> 
> @@ -455,38 +477,12 @@ static int __init ingenic_tcu_probe(struct device_node *np)
> return ret;
> }
> 
> -static int __maybe_unused tcu_pm_suspend(struct syscore_ops *ops)
> -{
> - struct ingenic_tcu *tcu = ingenic_tcu;
> -
> - if (tcu->clk)
> - clk_disable(tcu->clk);
> -
> - return 0;
> -}
> -
> -static void __maybe_unused tcu_pm_resume(struct syscore_ops *ops)
> -{
> - struct ingenic_tcu *tcu = ingenic_tcu;
> -
> - if (tcu->clk)
> - clk_enable(tcu->clk);
> -}
> -
> -static struct syscore_ops __maybe_unused tcu_pm_ops = {
> - .suspend = tcu_pm_suspend,
> - .resume = tcu_pm_resume,
> -};
> -
> static void __init ingenic_tcu_init(struct device_node *np)
> {
> int ret = ingenic_tcu_probe(np);
> 
> if (ret)
> pr_crit("Failed to initialize TCU clocks: %d\n", ret);
> -
> - if (IS_ENABLED(CONFIG_PM_SLEEP))
> - register_syscore_ops(&tcu_pm_ops);
> }
> 
> CLK_OF_DECLARE_DRIVER(jz4740_cgu, "ingenic,jz4740-tcu", ingenic_tcu_init);
> -- 
> 2.48.1
> 
> 



More information about the Letux-kernel mailing list