From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Biju Das <biju.das.jz@bp.renesas.com>
Cc: Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Russell King <linux@armlinux.org.uk>,
linux-clk@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>,
Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>,
Biju Das <biju.das.au@gmail.com>,
linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH RFC 1/3] clk: Add clk_disable_unprepare_sync()
Date: Wed, 7 Feb 2024 00:58:50 +0200 [thread overview]
Message-ID: <20240206225850.GA23702@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20240131160947.96171-2-biju.das.jz@bp.renesas.com>
Hi Biju,
Thank you for the patch.
On Wed, Jan 31, 2024 at 04:09:45PM +0000, Biju Das wrote:
> Currently clk_disable() is not synchronous. Consumers just
> gate the clock, but it doesn't check actually the clock is
> gated. Introduce clk_disable_unprepare_sync() to synchronize
> the clock gate operation.
I think this needs to be designed a bit more.
First of all, you state that clk_disable() is not synchronous, but
that's not documented anywhere. This should be addressed as a first
patch, with clarifications to the documentation of the clock API
functions (clk_disable(), clk_unprepare() and clk_disable_unprepare())
and the corresponding clock provider operations (clk_ops). You should
also explain in that patch why that's the desired behaviour, compared to
making those operations synchronous.
Then, instead of adding a new synchronous clock disable operation, I
wonder if it wouldn't be better to add a public function that
synchronizes a previous disable call by using the exising
infrastructure, and in particular the .is_enabled() operation. This
would provide the feature you're looking for without needing to modify
all clock provider drivers.
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> drivers/clk/clk.c | 36 +++++++++++++++++++++++++++---------
> include/linux/clk-provider.h | 4 ++++
> include/linux/clk.h | 25 +++++++++++++++++++++++++
> 3 files changed, 56 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 2253c154a824..958d6677b3a6 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -1080,7 +1080,7 @@ int clk_prepare(struct clk *clk)
> }
> EXPORT_SYMBOL_GPL(clk_prepare);
>
> -static void clk_core_disable(struct clk_core *core)
> +static void clk_core_disable(struct clk_core *core, bool sync)
> {
> lockdep_assert_held(&enable_lock);
>
> @@ -1102,17 +1102,20 @@ static void clk_core_disable(struct clk_core *core)
> if (core->ops->disable)
> core->ops->disable(core->hw);
>
> + if (sync && core->ops->disable_sync)
> + core->ops->disable_sync(core->hw);
> +
> trace_clk_disable_complete(core);
>
> - clk_core_disable(core->parent);
> + clk_core_disable(core->parent, false);
> }
>
> -static void clk_core_disable_lock(struct clk_core *core)
> +static void clk_core_disable_lock(struct clk_core *core, bool sync)
> {
> unsigned long flags;
>
> flags = clk_enable_lock();
> - clk_core_disable(core);
> + clk_core_disable(core, sync);
> clk_enable_unlock(flags);
> }
>
> @@ -1133,10 +1136,25 @@ void clk_disable(struct clk *clk)
> if (IS_ERR_OR_NULL(clk))
> return;
>
> - clk_core_disable_lock(clk->core);
> + clk_core_disable_lock(clk->core, false);
> }
> EXPORT_SYMBOL_GPL(clk_disable);
>
> +/**
> + * clk_disable_sync - gate a clock synchronously
> + * @clk: the clk being gated
> + *
> + * It is similar to clk_disable, but guarantees that clk is gated synchronously.
> + */
> +void clk_disable_sync(struct clk *clk)
> +{
> + if (IS_ERR_OR_NULL(clk))
> + return;
> +
> + clk_core_disable_lock(clk->core, true);
> +}
> +EXPORT_SYMBOL_GPL(clk_disable_sync);
> +
> static int clk_core_enable(struct clk_core *core)
> {
> int ret = 0;
> @@ -1164,7 +1182,7 @@ static int clk_core_enable(struct clk_core *core)
> trace_clk_enable_complete(core);
>
> if (ret) {
> - clk_core_disable(core->parent);
> + clk_core_disable(core->parent, false);
> return ret;
> }
> }
> @@ -1340,7 +1358,7 @@ static int clk_core_prepare_enable(struct clk_core *core)
>
> static void clk_core_disable_unprepare(struct clk_core *core)
> {
> - clk_core_disable_lock(core);
> + clk_core_disable_lock(core, false);
> clk_core_unprepare_lock(core);
> }
>
> @@ -2058,7 +2076,7 @@ static void __clk_set_parent_after(struct clk_core *core,
> * for preventing a race with clk_enable().
> */
> if (core->prepare_count) {
> - clk_core_disable_lock(core);
> + clk_core_disable_lock(core, false);
> clk_core_disable_unprepare(old_parent);
> }
>
> @@ -2352,7 +2370,7 @@ static void clk_change_rate(struct clk_core *core)
> core->rate = clk_recalc(core, best_parent_rate);
>
> if (core->flags & CLK_SET_RATE_UNGATE) {
> - clk_core_disable_lock(core);
> + clk_core_disable_lock(core, false);
> clk_core_unprepare(core);
> }
>
> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
> index 1293c38ddb7f..604cc9338465 100644
> --- a/include/linux/clk-provider.h
> +++ b/include/linux/clk-provider.h
> @@ -115,6 +115,9 @@ struct clk_duty {
> * @disable: Disable the clock atomically. Called with enable_lock held.
> * This function must not sleep.
> *
> + * @disable_sync: Disable and sync the clockatomically. Called with enable_lock
> + * held.This function must not sleep.
> + *
> * @is_enabled: Queries the hardware to determine if the clock is enabled.
> * This function must not sleep. Optional, if this op is not
> * set then the enable count will be used.
> @@ -238,6 +241,7 @@ struct clk_ops {
> void (*unprepare_unused)(struct clk_hw *hw);
> int (*enable)(struct clk_hw *hw);
> void (*disable)(struct clk_hw *hw);
> + void (*disable_sync)(struct clk_hw *hw);
> int (*is_enabled)(struct clk_hw *hw);
> void (*disable_unused)(struct clk_hw *hw);
> int (*save_context)(struct clk_hw *hw);
> diff --git a/include/linux/clk.h b/include/linux/clk.h
> index 06f1b292f8a0..f472756310c7 100644
> --- a/include/linux/clk.h
> +++ b/include/linux/clk.h
> @@ -664,6 +664,23 @@ int __must_check clk_bulk_enable(int num_clks,
> */
> void clk_disable(struct clk *clk);
>
> +/**
> + * clk_disable_sync - inform the system when the clock source is no longer
> + * required.
> + * @clk: clock source
> + *
> + * Inform the system that a clock source is no longer required by
> + * a driver and is in shut down.
> + *
> + * May be called from atomic contexts.
> + *
> + * Implementation detail: if the clock source is shared between
> + * multiple drivers, clk_enable() calls must be balanced by the
> + * same number of clk_disable_sync() calls for the clock source to be
> + * disabled.
> + */
> +void clk_disable_sync(struct clk *clk);
> +
> /**
> * clk_bulk_disable - inform the system when the set of clks is no
> * longer required.
> @@ -995,6 +1012,8 @@ static inline int __must_check clk_bulk_enable(int num_clks,
>
> static inline void clk_disable(struct clk *clk) {}
>
> +static inline void clk_disable_sync(struct clk *clk) {}
> +
>
> static inline void clk_bulk_disable(int num_clks,
> const struct clk_bulk_data *clks) {}
> @@ -1086,6 +1105,12 @@ static inline void clk_disable_unprepare(struct clk *clk)
> clk_unprepare(clk);
> }
>
> +static inline void clk_disable_unprepare_sync(struct clk *clk)
> +{
> + clk_disable_sync(clk);
> + clk_unprepare(clk);
> +}
> +
> static inline int __must_check
> clk_bulk_prepare_enable(int num_clks, const struct clk_bulk_data *clks)
> {
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2024-02-06 22:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-31 16:09 [PATCH RFC 0/3] Add clk_disable_unprepare_sync() Biju Das
2024-01-31 16:09 ` [PATCH RFC 1/3] clk: " Biju Das
2024-02-06 22:58 ` Laurent Pinchart [this message]
2024-02-11 16:17 ` Biju Das
2024-01-31 16:09 ` [PATCH RFC 2/3] clk: renesas: rzg2l: Add disable_sync() callback Biju Das
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=20240206225850.GA23702@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=biju.das.au@gmail.com \
--cc=biju.das.jz@bp.renesas.com \
--cc=geert+renesas@glider.be \
--cc=linux-clk@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mturquette@baylibre.com \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=sakari.ailus@linux.intel.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