All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Abel Vesa <abel.vesa@nxp.com>
Cc: Mike Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	Sascha Hauer <kernel@pengutronix.de>,
	Lucas Stach <l.stach@pengutronix.de>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-clk@vger.kernel.org
Subject: Re: [RFC] clk: Mark HW enabled clocks as enabled in core
Date: Tue, 26 Jan 2021 12:51:05 +0100	[thread overview]
Message-ID: <20210126115105.GD28722@pengutronix.de> (raw)
In-Reply-To: <1611660096-12381-1-git-send-email-abel.vesa@nxp.com>

On Tue, Jan 26, 2021 at 01:21:36PM +0200, Abel Vesa wrote:
> Some clocks are already enabled in HW even before the kernel
> starts to boot. So, in order to make sure that these clocks do not
> get disabled when clk_disable_unused call is done or when
> reparenting clocks, we enable them in core on clock registration.
> Such a clock will have to be registered with CLK_IGNORE_UNUSED flag
> and also needs to have the is_enabled ops implemented.
> 
> Signed-off-by: Abel Vesa <abel.vesa@nxp.com>
> ---
>  drivers/clk/clk.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 3d751ae5bc70..26d55851cfa5 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -3416,6 +3416,7 @@ static int __clk_core_init(struct clk_core *core)
>  	int ret;
>  	struct clk_core *parent;
>  	unsigned long rate;
> +	bool is_hw_enabled = false;
>  	int phase;
>  
>  	if (!core)
> @@ -3558,12 +3559,20 @@ static int __clk_core_init(struct clk_core *core)
>  		rate = 0;
>  	core->rate = core->req_rate = rate;
>  
> +	/*
> +	 * If the clock has the CLK_IGNORE_UNUSED flag set and it is already
> +	 * enabled in HW, enable it in core too so it won't get accidentally
> +	 * disabled when walking the orphan tree and reparenting clocks
> +	 */
> +	if (core->flags & CLK_IGNORE_UNUSED && core->ops->is_enabled)
> +		is_hw_enabled = clk_core_is_enabled(core);
> +
>  	/*
>  	 * Enable CLK_IS_CRITICAL clocks so newly added critical clocks
>  	 * don't get accidentally disabled when walking the orphan tree and
>  	 * reparenting clocks
>  	 */
> -	if (core->flags & CLK_IS_CRITICAL) {
> +	if (core->flags & CLK_IS_CRITICAL || is_hw_enabled) {
>  		unsigned long flags;
>  
>  		ret = clk_core_prepare(core);

This means that a bootloader enabled clock with CLK_IGNORE_UNUSED flag
can effectively never be disabled because the prepare/enable count is 1
without any user. This is the behaviour we want to have with critical
clocks, but I don't think this is desired for clocks with the
CLK_IGNORE_UNUSED flag.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

  reply	other threads:[~2021-01-26 11:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26 11:21 [RFC] clk: Mark HW enabled clocks as enabled in core Abel Vesa
2021-01-26 11:51 ` Sascha Hauer [this message]
2021-01-26 13:12   ` Abel Vesa
2021-01-26 14:30     ` Sascha Hauer
2021-01-27 10:12       ` Abel Vesa
2021-01-27 10:47         ` Sascha Hauer
2021-01-27 11:16           ` Abel Vesa
     [not found]             ` <20210129081948.GF19583@pengutronix.de>
2021-02-02 11:37               ` Abel Vesa

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=20210126115105.GD28722@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=abel.vesa@nxp.com \
    --cc=kernel@pengutronix.de \
    --cc=l.stach@pengutronix.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.