diff mbox series

spi: spi-geni-qcom: Set the clock properly at runtime resume

Message ID 20200708163922.1.I0b701fc23eca911a5bde4ae4fa7f97543d7f960e@changeid (mailing list archive)
State Superseded
Headers show
Series spi: spi-geni-qcom: Set the clock properly at runtime resume | expand

Commit Message

Doug Anderson July 8, 2020, 11:39 p.m. UTC
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(-)

Comments

Akash Asthana July 9, 2020, 7:30 a.m. UTC | #1
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)
Rajendra Nayak July 9, 2020, 8:55 a.m. UTC | #2
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)
>
Mark Brown July 9, 2020, 11:22 a.m. UTC | #3
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>
Doug Anderson July 9, 2020, 2:35 p.m. UTC | #4
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
Doug Anderson July 9, 2020, 2:44 p.m. UTC | #5
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
diff mbox series

Patch

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)