From: Bjorn Andersson <andersson@kernel.org>
To: Abel Vesa <abel.vesa@linaro.org>
Cc: Mike Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>, Andy Gross <agross@kernel.org>,
Konrad Dybcio <konrad.dybcio@linaro.org>,
Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
linux-clk@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH v3 1/2] clk: Add generic sync_state callback for disabling unused clocks
Date: Fri, 6 Jan 2023 11:22:42 -0600 [thread overview]
Message-ID: <20230106172242.bvuwzysjlh2cp7pw@builder.lan> (raw)
In-Reply-To: <20221227204528.1899863-1-abel.vesa@linaro.org>
On Tue, Dec 27, 2022 at 10:45:27PM +0200, Abel Vesa wrote:
> There are unused clocks that need to remain untouched by clk_disable_unused,
> and most likely could be disabled later on sync_state. So provide a generic
> sync_state callback for the clock providers that register such clocks.
> Then, use the same mechanism as clk_disable_unused from that generic
> callback, but pass the device to make sure only the clocks belonging to
> the current clock provider get disabled, if unused. Also, during the
> default clk_disable_unused, if the driver that registered the clock has
> the generic clk_sync_state_disable_unused callback set for sync_state,
> skip disabling its clocks.
>
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
Reviewed-by: Bjorn Andersson <andersson@kernel.org>
Regards,
Bjorn
> ---
>
> Changes since v2:
> * dropped the check for sync_state callback (clk_sync_state_disable_unused),
> like Dmitry suggested
>
> drivers/clk/clk.c | 57 +++++++++++++++++++++++++++++-------
> include/linux/clk-provider.h | 1 +
> 2 files changed, 47 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index e62552a75f08..ac7182903d88 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -1302,14 +1302,26 @@ static void clk_core_disable_unprepare(struct clk_core *core)
> clk_core_unprepare_lock(core);
> }
>
> -static void __init clk_unprepare_unused_subtree(struct clk_core *core)
> +static void clk_unprepare_unused_subtree(struct clk_core *core,
> + struct device *dev)
> {
> + bool from_sync_state = !!dev;
> struct clk_core *child;
>
> lockdep_assert_held(&prepare_lock);
>
> hlist_for_each_entry(child, &core->children, child_node)
> - clk_unprepare_unused_subtree(child);
> + clk_unprepare_unused_subtree(child, dev);
> +
> + if (from_sync_state && core->dev != dev)
> + return;
> +
> + /*
> + * clock will be unprepared on sync_state,
> + * so leave as is for now
> + */
> + if (!from_sync_state && dev_has_sync_state(core->dev))
> + return;
>
> if (core->prepare_count)
> return;
> @@ -1332,15 +1344,27 @@ static void __init clk_unprepare_unused_subtree(struct clk_core *core)
> clk_pm_runtime_put(core);
> }
>
> -static void __init clk_disable_unused_subtree(struct clk_core *core)
> +static void clk_disable_unused_subtree(struct clk_core *core,
> + struct device *dev)
> {
> + bool from_sync_state = !!dev;
> struct clk_core *child;
> unsigned long flags;
>
> lockdep_assert_held(&prepare_lock);
>
> hlist_for_each_entry(child, &core->children, child_node)
> - clk_disable_unused_subtree(child);
> + clk_disable_unused_subtree(child, dev);
> +
> + if (from_sync_state && core->dev != dev)
> + return;
> +
> + /*
> + * clock will be disabled on sync_state,
> + * so leave as is for now
> + */
> + if (!from_sync_state && dev_has_sync_state(core->dev))
> + return;
>
> if (core->flags & CLK_OPS_PARENT_ENABLE)
> clk_core_prepare_enable(core->parent);
> @@ -1378,7 +1402,7 @@ static void __init clk_disable_unused_subtree(struct clk_core *core)
> clk_core_disable_unprepare(core->parent);
> }
>
> -static bool clk_ignore_unused __initdata;
> +static bool clk_ignore_unused;
> static int __init clk_ignore_unused_setup(char *__unused)
> {
> clk_ignore_unused = true;
> @@ -1386,35 +1410,46 @@ static int __init clk_ignore_unused_setup(char *__unused)
> }
> __setup("clk_ignore_unused", clk_ignore_unused_setup);
>
> -static int __init clk_disable_unused(void)
> +static void __clk_disable_unused(struct device *dev)
> {
> struct clk_core *core;
>
> if (clk_ignore_unused) {
> pr_warn("clk: Not disabling unused clocks\n");
> - return 0;
> + return;
> }
>
> clk_prepare_lock();
>
> hlist_for_each_entry(core, &clk_root_list, child_node)
> - clk_disable_unused_subtree(core);
> + clk_disable_unused_subtree(core, dev);
>
> hlist_for_each_entry(core, &clk_orphan_list, child_node)
> - clk_disable_unused_subtree(core);
> + clk_disable_unused_subtree(core, dev);
>
> hlist_for_each_entry(core, &clk_root_list, child_node)
> - clk_unprepare_unused_subtree(core);
> + clk_unprepare_unused_subtree(core, dev);
>
> hlist_for_each_entry(core, &clk_orphan_list, child_node)
> - clk_unprepare_unused_subtree(core);
> + clk_unprepare_unused_subtree(core, dev);
>
> clk_prepare_unlock();
> +}
> +
> +static int __init clk_disable_unused(void)
> +{
> + __clk_disable_unused(NULL);
>
> return 0;
> }
> late_initcall_sync(clk_disable_unused);
>
> +void clk_sync_state_disable_unused(struct device *dev)
> +{
> + __clk_disable_unused(dev);
> +}
> +EXPORT_SYMBOL_GPL(clk_sync_state_disable_unused);
> +
> static int clk_core_determine_round_nolock(struct clk_core *core,
> struct clk_rate_request *req)
> {
> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
> index 842e72a5348f..cf1adfeaf257 100644
> --- a/include/linux/clk-provider.h
> +++ b/include/linux/clk-provider.h
> @@ -720,6 +720,7 @@ struct clk *clk_register_divider_table(struct device *dev, const char *name,
> void __iomem *reg, u8 shift, u8 width,
> u8 clk_divider_flags, const struct clk_div_table *table,
> spinlock_t *lock);
> +void clk_sync_state_disable_unused(struct device *dev);
> /**
> * clk_register_divider - register a divider clock with the clock framework
> * @dev: device registering this clock
> --
> 2.34.1
>
next prev parent reply other threads:[~2023-01-06 17:23 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-27 20:45 [PATCH v3 1/2] clk: Add generic sync_state callback for disabling unused clocks Abel Vesa
2022-12-27 20:45 ` [PATCH v3 2/2] clk: qcom: sdm845: Use generic clk_sync_state_disable_unused callback Abel Vesa
2023-01-05 14:03 ` Dmitry Baryshkov
2023-01-05 14:03 ` [PATCH v3 1/2] clk: Add generic sync_state callback for disabling unused clocks Dmitry Baryshkov
2023-01-06 17:22 ` Bjorn Andersson [this message]
2023-01-10 17:17 ` (subset) " Bjorn Andersson
2023-02-18 5:38 ` Stephen Boyd
2023-02-20 15:46 ` Abel Vesa
2023-02-20 16:27 ` Abel Vesa
2023-02-20 17:51 ` Saravana Kannan
2023-02-20 18:47 ` Abel Vesa
2023-02-21 19:58 ` Saravana Kannan
2023-02-22 7:57 ` Abel Vesa
2023-05-11 12:58 ` Abel Vesa
2023-05-12 0:46 ` Saravana Kannan
2023-05-12 10:30 ` Abel Vesa
2023-05-27 0:13 ` Saravana Kannan
2023-02-20 16:33 ` Bjorn Andersson
2023-02-21 18:44 ` Stephen Boyd
2023-02-20 16:21 ` Bjorn Andersson
2023-02-21 19:24 ` Stephen Boyd
2023-02-22 15:34 ` Bjorn Andersson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230106172242.bvuwzysjlh2cp7pw@builder.lan \
--to=andersson@kernel.org \
--cc=abel.vesa@linaro.org \
--cc=agross@kernel.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=konrad.dybcio@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=sboyd@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox