linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume
@ 2020-07-08 23:39 Douglas Anderson
  2020-07-09  7:30 ` Akash Asthana
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Douglas Anderson @ 2020-07-08 23:39 UTC (permalink / raw)
  To: Mark Brown, Andy Gross, Bjorn Andersson
  Cc: linux-arm-msm, akashast, Rajendra Nayak, georgi.djakov, swboyd,
	mkshah, ctheegal, mka, Douglas Anderson, linux-kernel, linux-spi

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 <dianders@chromium.org>
---
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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume
  2020-07-08 23:39 [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume Douglas Anderson
@ 2020-07-09  7:30 ` Akash Asthana
  2020-07-09 14:35   ` Doug Anderson
  2020-07-09  8:55 ` Rajendra Nayak
  2020-07-09 11:22 ` Mark Brown
  2 siblings, 1 reply; 6+ messages in thread
From: Akash Asthana @ 2020-07-09  7:30 UTC (permalink / raw)
  To: Douglas Anderson, Mark Brown, Andy Gross, Bjorn Andersson
  Cc: linux-arm-msm, Rajendra Nayak, georgi.djakov, swboyd, mkshah,
	ctheegal, mka, linux-kernel, linux-spi

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume
  2020-07-08 23:39 [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume Douglas Anderson
  2020-07-09  7:30 ` Akash Asthana
@ 2020-07-09  8:55 ` Rajendra Nayak
  2020-07-09 14:44   ` Doug Anderson
  2020-07-09 11:22 ` Mark Brown
  2 siblings, 1 reply; 6+ messages in thread
From: Rajendra Nayak @ 2020-07-09  8:55 UTC (permalink / raw)
  To: Douglas Anderson, Mark Brown, Andy Gross, Bjorn Andersson
  Cc: linux-arm-msm, akashast, georgi.djakov, swboyd, mkshah, ctheegal,
	mka, linux-kernel, linux-spi


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 <dianders@chromium.org>
> ---
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume
  2020-07-08 23:39 [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume Douglas Anderson
  2020-07-09  7:30 ` Akash Asthana
  2020-07-09  8:55 ` Rajendra Nayak
@ 2020-07-09 11:22 ` Mark Brown
  2 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2020-07-09 11:22 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: Andy Gross, Bjorn Andersson, linux-arm-msm, akashast,
	Rajendra Nayak, georgi.djakov, swboyd, mkshah, ctheegal, mka,
	linux-kernel, linux-spi

[-- Attachment #1: Type: text/plain, Size: 304 bytes --]

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 <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume
  2020-07-09  7:30 ` Akash Asthana
@ 2020-07-09 14:35   ` Doug Anderson
  0 siblings, 0 replies; 6+ messages in thread
From: Doug Anderson @ 2020-07-09 14:35 UTC (permalink / raw)
  To: Akash Asthana
  Cc: Mark Brown, Andy Gross, Bjorn Andersson, linux-arm-msm,
	Rajendra Nayak, Georgi Djakov, Stephen Boyd, Maulik Shah,
	ctheegal, Matthias Kaehlcke, LKML, linux-spi

Hi,

On Thu, Jul 9, 2020 at 12:30 AM Akash Asthana <akashast@codeaurora.org> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume
  2020-07-09  8:55 ` Rajendra Nayak
@ 2020-07-09 14:44   ` Doug Anderson
  0 siblings, 0 replies; 6+ messages in thread
From: Doug Anderson @ 2020-07-09 14:44 UTC (permalink / raw)
  To: Rajendra Nayak
  Cc: Mark Brown, Andy Gross, Bjorn Andersson, linux-arm-msm,
	Akash Asthana, Georgi Djakov, Stephen Boyd, Maulik Shah,
	ctheegal, Matthias Kaehlcke, LKML, linux-spi

Hi,

On Thu, Jul 9, 2020 at 1:55 AM Rajendra Nayak <rnayak@codeaurora.org> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-07-09 14:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-08 23:39 [PATCH] spi: spi-geni-qcom: Set the clock properly at runtime resume Douglas Anderson
2020-07-09  7:30 ` Akash Asthana
2020-07-09 14:35   ` Doug Anderson
2020-07-09  8:55 ` Rajendra Nayak
2020-07-09 14:44   ` Doug Anderson
2020-07-09 11:22 ` Mark Brown

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).