2020-07-08 23:40:35

by Doug Anderson

[permalink] [raw]
Subject: [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume

In the patch ("spi: spi-geni-qcom: Avoid clock setting if not needed")
we avoid a whole pile of clock code. As part of that, we should have
restored the clock at runtime resume. Do that.

It turns out that, at least with today's configurations, this doesn't
actually matter. That's because none of the current device trees have
an OPP table for geni SPI yet. That makes dev_pm_opp_set_rate(dev, 0)
a no-op. This is why it wasn't noticed in the testing of the original
patch. It's still a good idea to fix, though.

Signed-off-by: Douglas Anderson <[email protected]>
---
Sending this as a separate patch even though I think the patch it's
fixing [1] hasn't landed yet. I'd be happy if this was squashed into
that patch when landing if that suits everyone, but it could land on
its own too.

Like the patch it's fixing, this needs to target the Qualcomm tree in
order to avoid merge conflicts.

[1] https://lore.kernel.org/r/20200701174506.1.Icfdcee14649fc0a6c38e87477b28523d4e60bab3@changeid

drivers/spi/spi-geni-qcom.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c
index 97fac5ea6afd..e5ece1bcc4ad 100644
--- a/drivers/spi/spi-geni-qcom.c
+++ b/drivers/spi/spi-geni-qcom.c
@@ -79,6 +79,7 @@ struct spi_geni_master {
u32 tx_wm;
u32 last_mode;
unsigned long cur_speed_hz;
+ unsigned long cur_sclk_hz;
unsigned int cur_bits_per_word;
unsigned int tx_rem_bytes;
unsigned int rx_rem_bytes;
@@ -116,6 +117,9 @@ static int get_spi_clk_cfg(unsigned int speed_hz,
ret = dev_pm_opp_set_rate(mas->dev, sclk_freq);
if (ret)
dev_err(mas->dev, "dev_pm_opp_set_rate failed %d\n", ret);
+ else
+ mas->cur_sclk_hz = sclk_freq;
+
return ret;
}

@@ -670,7 +674,13 @@ static int __maybe_unused spi_geni_runtime_resume(struct device *dev)
if (ret)
return ret;

- return geni_se_resources_on(&mas->se);
+ ret = geni_se_resources_on(&mas->se);
+ if (ret)
+ return ret;
+
+ dev_pm_opp_set_rate(mas->dev, mas->cur_sclk_hz);
+
+ return 0;
}

static int __maybe_unused spi_geni_suspend(struct device *dev)
--
2.27.0.383.g050319c2ae-goog


2020-07-09 07:33:43

by Akash Asthana

[permalink] [raw]
Subject: Re: [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume

Hi Doug,

>
> @@ -670,7 +674,13 @@ static int __maybe_unused spi_geni_runtime_resume(struct device *dev)
> if (ret)
> return ret;
>
> - return geni_se_resources_on(&mas->se);
> + ret = geni_se_resources_on(&mas->se);
> + if (ret)
> + return ret;
> +
> + dev_pm_opp_set_rate(mas->dev, mas->cur_sclk_hz);
> +
> + return 0;
> }

Should we fail to resume if error is returned from 'opp_set_rate'?

'spi_geni_prepare_message' use to fail for any error from
'opp_set_rate'  before patch series "Avoid clock setting if not needed".

But now it's possible that 'prepare_message' can return success even
when opp are not at desired state(from previous resume call).

Regards,

Akash

>
> static int __maybe_unused spi_geni_suspend(struct device *dev)

--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project

2020-07-09 08:58:45

by Rajendra Nayak

[permalink] [raw]
Subject: Re: [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume


On 7/9/2020 5:09 AM, Douglas Anderson wrote:
> In the patch ("spi: spi-geni-qcom: Avoid clock setting if not needed")
> we avoid a whole pile of clock code. As part of that, we should have
> restored the clock at runtime resume. Do that.
>
> It turns out that, at least with today's configurations, this doesn't
> actually matter. That's because none of the current device trees have
> an OPP table for geni SPI yet. That makes dev_pm_opp_set_rate(dev, 0)
> a no-op. This is why it wasn't noticed in the testing of the original
> patch. It's still a good idea to fix, though.

good catch, without this (and with OPP tables added) we would end up removing
the performance vote on suspend and never put it back unless the rate changes.
Perhaps a similar change would be needed for spi-qcom-qspi too?

>
> Signed-off-by: Douglas Anderson <[email protected]>
> ---
> Sending this as a separate patch even though I think the patch it's
> fixing [1] hasn't landed yet. I'd be happy if this was squashed into
> that patch when landing if that suits everyone, but it could land on
> its own too.
>
> Like the patch it's fixing, this needs to target the Qualcomm tree in
> order to avoid merge conflicts.
>
> [1] https://lore.kernel.org/r/20200701174506.1.Icfdcee14649fc0a6c38e87477b28523d4e60bab3@changeid
>
> drivers/spi/spi-geni-qcom.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c
> index 97fac5ea6afd..e5ece1bcc4ad 100644
> --- a/drivers/spi/spi-geni-qcom.c
> +++ b/drivers/spi/spi-geni-qcom.c
> @@ -79,6 +79,7 @@ struct spi_geni_master {
> u32 tx_wm;
> u32 last_mode;
> unsigned long cur_speed_hz;
> + unsigned long cur_sclk_hz;
> unsigned int cur_bits_per_word;
> unsigned int tx_rem_bytes;
> unsigned int rx_rem_bytes;
> @@ -116,6 +117,9 @@ static int get_spi_clk_cfg(unsigned int speed_hz,
> ret = dev_pm_opp_set_rate(mas->dev, sclk_freq);
> if (ret)
> dev_err(mas->dev, "dev_pm_opp_set_rate failed %d\n", ret);
> + else
> + mas->cur_sclk_hz = sclk_freq;
> +
> return ret;
> }
>
> @@ -670,7 +674,13 @@ static int __maybe_unused spi_geni_runtime_resume(struct device *dev)
> if (ret)
> return ret;
>
> - return geni_se_resources_on(&mas->se);
> + ret = geni_se_resources_on(&mas->se);
> + if (ret)
> + return ret;
> +
> + dev_pm_opp_set_rate(mas->dev, mas->cur_sclk_hz);
> +
> + return 0;
> }
>
> static int __maybe_unused spi_geni_suspend(struct device *dev)
>

--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation

2020-07-09 11:24:11

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume

On Wed, Jul 08, 2020 at 04:39:39PM -0700, Douglas Anderson wrote:
> In the patch ("spi: spi-geni-qcom: Avoid clock setting if not needed")
> we avoid a whole pile of clock code. As part of that, we should have
> restored the clock at runtime resume. Do that.

Acked-by: Mark Brown <[email protected]>


Attachments:
(No filename) (310.00 B)
signature.asc (499.00 B)
Download all attachments

2020-07-09 14:36:57

by Doug Anderson

[permalink] [raw]
Subject: Re: [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume

Hi,

On Thu, Jul 9, 2020 at 12:30 AM Akash Asthana <[email protected]> wrote:
>
> Hi Doug,
>
> >
> > @@ -670,7 +674,13 @@ static int __maybe_unused spi_geni_runtime_resume(struct device *dev)
> > if (ret)
> > return ret;
> >
> > - return geni_se_resources_on(&mas->se);
> > + ret = geni_se_resources_on(&mas->se);
> > + if (ret)
> > + return ret;
> > +
> > + dev_pm_opp_set_rate(mas->dev, mas->cur_sclk_hz);
> > +
> > + return 0;
> > }
>
> Should we fail to resume if error is returned from 'opp_set_rate'?
>
> 'spi_geni_prepare_message' use to fail for any error from
> 'opp_set_rate' before patch series "Avoid clock setting if not needed".
>
> But now it's possible that 'prepare_message' can return success even
> when opp are not at desired state(from previous resume call).

I can. I was following the spi_geni_runtime_suspend() example and
just calling it, but I suppose it makes sense that setting the clock
to 0 failing isn't as important as setting it to something non-zero.

I'll post a v2 real quick and keep Acks / Reviews.

-Doug

2020-07-09 14:51:56

by Doug Anderson

[permalink] [raw]
Subject: Re: [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume

Hi,

On Thu, Jul 9, 2020 at 1:55 AM Rajendra Nayak <[email protected]> wrote:
>
>
> On 7/9/2020 5:09 AM, Douglas Anderson wrote:
> > In the patch ("spi: spi-geni-qcom: Avoid clock setting if not needed")
> > we avoid a whole pile of clock code. As part of that, we should have
> > restored the clock at runtime resume. Do that.
> >
> > It turns out that, at least with today's configurations, this doesn't
> > actually matter. That's because none of the current device trees have
> > an OPP table for geni SPI yet. That makes dev_pm_opp_set_rate(dev, 0)
> > a no-op. This is why it wasn't noticed in the testing of the original
> > patch. It's still a good idea to fix, though.
>
> good catch, without this (and with OPP tables added) we would end up removing
> the performance vote on suspend and never put it back unless the rate changes.
> Perhaps a similar change would be needed for spi-qcom-qspi too?

The quad spi already patch had this fix and it actually mattered
there. That's what made me go look back and realize that I needed the
fix in the geni SPI. See:

https://lore.kernel.org/r/20200707131607.1.Ia7cb4f41ce93d37d0a764b47c8a453ce9e9c70ef@changeid

I'll send a v2 of that with Akash's suggestion of checking the return
value, though.

-Doug