linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
To: Stephan Gerhold <stephan@gerhold.net>
Cc: Stephen Boyd <sboyd@kernel.org>, Andy Gross <agross@kernel.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Michael Turquette <mturquette@baylibre.com>,
	MSM <linux-arm-msm@vger.kernel.org>,
	linux-clk@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht,
	Georgi Djakov <georgi.djakov@linaro.org>
Subject: Re: [PATCH] clk: qcom: smd: Disable unused clocks
Date: Mon, 17 Aug 2020 08:52:46 -0600	[thread overview]
Message-ID: <CAOCk7Nq6CT5q_aXG2jZ2t5=3YKVKM4r=gSnJLJkVccpwyc3XnQ@mail.gmail.com> (raw)
In-Reply-To: <20200817140908.185976-1-stephan@gerhold.net>

On Mon, Aug 17, 2020 at 8:10 AM Stephan Gerhold <stephan@gerhold.net> wrote:
>
> At the moment, clk-smd-rpm forces all clocks on at probe time
> (for "handoff"). However, it does not make the clk core aware of that.
> This means that the clocks stay enabled forever if they are not used
> by anything.
>
> We can easily disable them again after bootup has been completed,
> by making the clk core aware of the state. This is implemented by
> returning the current state of the clock in is_prepared().
>
> Checking the SPMI clock registers reveals that this allows the RPM
> to disable unused BB/RF clocks. For example, on MSM8916 with all
> remote processors (except RPM) disabled, we get:
>
>  +--------------------------+------------+---------+--------+-------+
>  |                          | BOOTLOADER | HANDOFF | BEFORE | AFTER |
>  +--------------------------+------------+---------+--------+-------+
>  | BB_CLK1_STATUS1 (0x5108) |     ON*    |    ON   |   ON   |  ON*  |
>  | BB_CLK2_STATUS1 (0x5208) |     OFF    |    ON   |   ON   |  OFF  |
>  | RF_CLK1_STATUS1 (0x5408) |     OFF    |    ON   |   ON   |  OFF  |
>  | RF_CLK2_STATUS1 (0x5508) |     OFF    |    ON   |   ON   |  OFF  |
>  +--------------------------+------------+---------+--------+-------+
>   * BB_CLK1 seems to be always-on in RPM on MSM8916
>
> where:
>   - BOOTLOADER = clk-smd-rpm disabled entirely in device tree
>   - HANDOFF = temporarily after clk-smd-rpm was probed
>   - BEFORE/AFTER = after boot without/with the changes in this commit
>
> With this commit BB_CLK2/RF_CLK1/RF_CLK2 are disabled again when unused.
>
> Cc: Georgi Djakov <georgi.djakov@linaro.org>
> Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
> ---
> Originally I reported this here:
> https://lore.kernel.org/linux-arm-msm/20200523120810.GA166540@gerhold.net/
>
> Overall I'm not entirely sure why we need to force all these clocks
> on at all... But the downstream driver also seems to do it and the RPM
> interface is barely documented, so I didn't feel comfortable changing it...

So essentially, when the clk framework goes through late init, and
decides to turn off clocks that are not being used, it will also turn
off these clocks?

I think this is going to break other targets where other subsystems
happen to rely on these sorts of votes from Linux inorder to run/boot
(not saying it's a good thing, just that is how it is and since we
can't change the FW on those....).

I think this needs to be validated on every single qcom platform using
this driver.

Also, out of curiosity, how are you validating that BB_CLK2 is
actually off after this change?

> ---
>  drivers/clk/qcom/clk-smd-rpm.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/drivers/clk/qcom/clk-smd-rpm.c b/drivers/clk/qcom/clk-smd-rpm.c
> index 0e1dfa89489e..fa960cb794a8 100644
> --- a/drivers/clk/qcom/clk-smd-rpm.c
> +++ b/drivers/clk/qcom/clk-smd-rpm.c
> @@ -171,6 +171,9 @@ static int clk_smd_rpm_handoff(struct clk_smd_rpm *r)
>         if (ret)
>                 return ret;
>
> +       /* During handoff we force all clocks on */
> +       r->enabled = true;
> +
>         return 0;
>  }
>
> @@ -300,6 +303,13 @@ static void clk_smd_rpm_unprepare(struct clk_hw *hw)
>         mutex_unlock(&rpm_smd_clk_lock);
>  }
>
> +static int clk_smd_rpm_is_prepared(struct clk_hw *hw)
> +{
> +       struct clk_smd_rpm *r = to_clk_smd_rpm(hw);
> +
> +       return r->enabled;
> +}
> +
>  static int clk_smd_rpm_set_rate(struct clk_hw *hw, unsigned long rate,
>                                 unsigned long parent_rate)
>  {
> @@ -396,6 +406,7 @@ static int clk_smd_rpm_enable_scaling(struct qcom_smd_rpm *rpm)
>  static const struct clk_ops clk_smd_rpm_ops = {
>         .prepare        = clk_smd_rpm_prepare,
>         .unprepare      = clk_smd_rpm_unprepare,
> +       .is_prepared    = clk_smd_rpm_is_prepared,
>         .set_rate       = clk_smd_rpm_set_rate,
>         .round_rate     = clk_smd_rpm_round_rate,
>         .recalc_rate    = clk_smd_rpm_recalc_rate,
> @@ -404,6 +415,7 @@ static const struct clk_ops clk_smd_rpm_ops = {
>  static const struct clk_ops clk_smd_rpm_branch_ops = {
>         .prepare        = clk_smd_rpm_prepare,
>         .unprepare      = clk_smd_rpm_unprepare,
> +       .is_prepared    = clk_smd_rpm_is_prepared,
>  };
>
>  /* msm8916 */
> --
> 2.28.0
>

  reply	other threads:[~2020-08-17 14:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-17 14:09 [PATCH] clk: qcom: smd: Disable unused clocks Stephan Gerhold
2020-08-17 14:52 ` Jeffrey Hugo [this message]
2020-08-17 15:28   ` Stephan Gerhold
2020-08-17 15:46     ` Jeffrey Hugo
2020-08-17 16:13       ` Stephan Gerhold
2020-08-18  8:07   ` Stephan Gerhold
2020-08-20 23:27     ` Stephen Boyd
2020-08-21  6:48       ` Stephan Gerhold

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='CAOCk7Nq6CT5q_aXG2jZ2t5=3YKVKM4r=gSnJLJkVccpwyc3XnQ@mail.gmail.com' \
    --to=jeffrey.l.hugo@gmail.com \
    --cc=agross@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=georgi.djakov@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.org \
    --cc=stephan@gerhold.net \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /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;
as well as URLs for NNTP newsgroup(s).