diff mbox

[v3] thermal: tango: add resume support

Message ID 578CC9C9.3050806@free.fr (mailing list archive)
State New, archived
Headers show

Commit Message

Mason July 18, 2016, 12:21 p.m. UTC
From: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>

When this platform is suspended, firmware powers the entire SoC down,
except a few hardware blocks waiting for wakeup events. And there is
no context to save for this particular block.

Therefore, there is nothing useful for the driver to do on suspend;
so we define a NULL suspend hook. On resume, the driver initializes
the block exactly as is done in the probe callback.

Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
---
Changes in v3
Drop the DEV_PM_OPS macro, which caused some confusion.
Note: tango_thermal_pm struct only exists when CONFIG_PM_SLEEP is defined
@Kevin, can I add your Reviewed-by tag back?
---
 drivers/thermal/tango_thermal.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

Comments

Thierry Reding July 20, 2016, 10:50 a.m. UTC | #1
On Mon, Jul 18, 2016 at 02:21:29PM +0200, Mason wrote:
> From: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
> 
> When this platform is suspended, firmware powers the entire SoC down,
> except a few hardware blocks waiting for wakeup events. And there is
> no context to save for this particular block.
> 
> Therefore, there is nothing useful for the driver to do on suspend;
> so we define a NULL suspend hook. On resume, the driver initializes
> the block exactly as is done in the probe callback.
> 
> Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
> ---
> Changes in v3
> Drop the DEV_PM_OPS macro, which caused some confusion.
> Note: tango_thermal_pm struct only exists when CONFIG_PM_SLEEP is defined
> @Kevin, can I add your Reviewed-by tag back?
> ---
>  drivers/thermal/tango_thermal.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)

Reviewed-by: Thierry Reding <treding@nvidia.com>
Kevin Hilman July 22, 2016, 10 p.m. UTC | #2
Mason <slash.tmp@free.fr> writes:

> From: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
>
> When this platform is suspended, firmware powers the entire SoC down,
> except a few hardware blocks waiting for wakeup events. And there is
> no context to save for this particular block.
>
> Therefore, there is nothing useful for the driver to do on suspend;
> so we define a NULL suspend hook. On resume, the driver initializes
> the block exactly as is done in the probe callback.
>
> Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
> ---
> Changes in v3
> Drop the DEV_PM_OPS macro, which caused some confusion.
> Note: tango_thermal_pm struct only exists when CONFIG_PM_SLEEP is defined
> @Kevin, can I add your Reviewed-by tag back?
> ---
>  drivers/thermal/tango_thermal.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/tango_thermal.c b/drivers/thermal/tango_thermal.c
> index 70e0d9f406e9..957f8937e126 100644
> --- a/drivers/thermal/tango_thermal.c
> +++ b/drivers/thermal/tango_thermal.c
> @@ -64,6 +64,12 @@ static const struct thermal_zone_of_device_ops ops = {
>  	.get_temp	= tango_get_temp,
>  };
>  
> +static void tango_thermal_init(struct tango_thermal_priv *priv)
> +{
> +	writel(0, priv->base + TEMPSI_CFG);
> +	writel(CMD_ON, priv->base + TEMPSI_CMD);
> +}
> +
>  static int tango_thermal_probe(struct platform_device *pdev)
>  {
>  	struct resource *res;
> @@ -79,14 +85,24 @@ static int tango_thermal_probe(struct platform_device *pdev)
>  	if (IS_ERR(priv->base))
>  		return PTR_ERR(priv->base);
>  
> +	platform_set_drvdata(pdev, priv);
>  	priv->thresh_idx = IDX_MIN;
> -	writel(0, priv->base + TEMPSI_CFG);
> -	writel(CMD_ON, priv->base + TEMPSI_CMD);
> +	tango_thermal_init(priv);
>  
>  	tzdev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, priv, &ops);
>  	return PTR_ERR_OR_ZERO(tzdev);
>  }
>  
> +#ifdef CONFIG_PM_SLEEP
> +static int tango_thermal_resume(struct device *dev)
> +{
> +	tango_thermal_init(dev_get_drvdata(dev));
> +	return 0;
> +}
> +
> +static SIMPLE_DEV_PM_OPS(tango_thermal_pm, NULL, tango_thermal_resume);
> +#endif

#else
#define tango_thermal_resume NULL
#endif

And then move the SIMPLE_DEV_PM_OPS here...

> +
>  static const struct of_device_id tango_sensor_ids[] = {
>  	{
>  		.compatible = "sigma,smp8758-thermal",
> @@ -99,6 +115,9 @@ static struct platform_driver tango_thermal_driver = {
>  	.driver	= {
>  		.name		= "tango-thermal",
>  		.of_match_table	= tango_sensor_ids,
> +#ifdef CONFIG_PM_SLEEP
> +		.pm		= &tango_thermal_pm,
> +#endif

... which allows you to get rid of the ugly ifdef here.
(c.f. CodingStyle, Chapter 20,)

Kevin
Mason July 25, 2016, 8:18 a.m. UTC | #3
On 23/07/2016 00:00, Kevin Hilman wrote:

> Mason wrote:
> 
>> +#ifdef CONFIG_PM_SLEEP
>> +static int tango_thermal_resume(struct device *dev)
>> +{
>> +	tango_thermal_init(dev_get_drvdata(dev));
>> +	return 0;
>> +}
>> +
>> +static SIMPLE_DEV_PM_OPS(tango_thermal_pm, NULL, tango_thermal_resume);
>> +#endif
> 
> #else
> #define tango_thermal_resume NULL
> #endif
> 
> And then move the SIMPLE_DEV_PM_OPS here...

Moving the SIMPLE_DEV_PM_OPS macro outside the CONFIG_PM_SLEEP guard
would unconditionally define a struct dev_pm_ops, which just wastes
space when CONFIG_PM_SLEEP is undefined (if I'm not mistaken).

That's why I put SIMPLE_DEV_PM_OPS inside the CONFIG_PM_SLEEP guard.

>> +
>>  static const struct of_device_id tango_sensor_ids[] = {
>>  	{
>>  		.compatible = "sigma,smp8758-thermal",
>> @@ -99,6 +115,9 @@ static struct platform_driver tango_thermal_driver = {
>>  	.driver	= {
>>  		.name		= "tango-thermal",
>>  		.of_match_table	= tango_sensor_ids,
>> +#ifdef CONFIG_PM_SLEEP
>> +		.pm		= &tango_thermal_pm,
>> +#endif
> 
> ... which allows you to get rid of the ugly ifdef here.
> (c.f. CodingStyle, Chapter 20,)

The previous solution (v2) avoided duplicating the ifdef block,
but Arnd and Thierry objected to the code. Later, they agreed
that it should work; but if they didn't catch the code's intent
at a glance, maybe there is a problem with it anyway.

What do you think?

I copied the DEV_PM_OPS "trick" from drivers/thermal/ti-soc-thermal/ti-bandgap.c
(which was done by Eduardo, a thermal maintainer, so maybe he
prefers that solution after all? commit 8feaf0ce1a043)

Regards.
Arnd Bergmann July 25, 2016, 8:52 a.m. UTC | #4
On Monday, July 25, 2016 10:18:22 AM CEST Mason wrote:
> On 23/07/2016 00:00, Kevin Hilman wrote:
> 
> > Mason wrote:
> > 
> >> +#ifdef CONFIG_PM_SLEEP
> >> +static int tango_thermal_resume(struct device *dev)
> >> +{
> >> +    tango_thermal_init(dev_get_drvdata(dev));
> >> +    return 0;
> >> +}
> >> +
> >> +static SIMPLE_DEV_PM_OPS(tango_thermal_pm, NULL, tango_thermal_resume);
> >> +#endif
> > 
> > #else
> > #define tango_thermal_resume NULL
> > #endif

That's what SIMPLE_DEV_PM_OPS does internally already.

> > And then move the SIMPLE_DEV_PM_OPS here...
> 
> Moving the SIMPLE_DEV_PM_OPS macro outside the CONFIG_PM_SLEEP guard
> would unconditionally define a struct dev_pm_ops, which just wastes
> space when CONFIG_PM_SLEEP is undefined (if I'm not mistaken).
> 
> That's why I put SIMPLE_DEV_PM_OPS inside the CONFIG_PM_SLEEP guard.

If you want to avoid the extra few bytes, just use the trick I
suggested:

	.pm = IS_ENABLED(CONFIG_PM_SLEEP) ? &tango_thermal_pm : NULL,

> >> +
> >>  static const struct of_device_id tango_sensor_ids[] = {
> >>      {
> >>              .compatible = "sigma,smp8758-thermal",
> >> @@ -99,6 +115,9 @@ static struct platform_driver tango_thermal_driver = {
> >>      .driver = {
> >>              .name           = "tango-thermal",
> >>              .of_match_table = tango_sensor_ids,
> >> +#ifdef CONFIG_PM_SLEEP
> >> +            .pm             = &tango_thermal_pm,
> >> +#endif
> > 
> > ... which allows you to get rid of the ugly ifdef here.
> > (c.f. CodingStyle, Chapter 20,)
> 
> The previous solution (v2) avoided duplicating the ifdef block,
> but Arnd and Thierry objected to the code. Later, they agreed
> that it should work; but if they didn't catch the code's intent
> at a glance, maybe there is a problem with it anyway.
> 
> What do you think?
> 
> I copied the DEV_PM_OPS "trick" from drivers/thermal/ti-soc-thermal/ti-bandgap.c
> (which was done by Eduardo, a thermal maintainer, so maybe he
> prefers that solution after all? commit 8feaf0ce1a043)

You should basically never have that #ifdef inside of the
platform_driver definition. The normal way to do it is to have
__maybe_unused markers for the functions so gcc can silently drop
them when they are unused, or to have (slightly uglier and easier
to get wrong) #ifdef around the function, but not around the
references, but nowhere else.

The SIMPLE_DEV_PM_OPS macro is suboptimal because it requires the
__maybe_unused tags and because it leaves more data around than
necessary. Feel free to suggest improvements for those macros
(others have tried before and failed because of the hundreds or
thousands of users that exist), just don't try to be extra clever
in your one driver, it would only make it harder for readers to
understand.

	Arnd
Mason July 25, 2016, 9:48 a.m. UTC | #5
On 25/07/2016 10:52, Arnd Bergmann wrote:

> On Monday, July 25, 2016 10:18:22 AM CEST Mason wrote:
> 
>> Moving the SIMPLE_DEV_PM_OPS macro outside the CONFIG_PM_SLEEP guard
>> would unconditionally define a struct dev_pm_ops, which just wastes
>> space when CONFIG_PM_SLEEP is undefined (if I'm not mistaken).
>>
>> That's why I put SIMPLE_DEV_PM_OPS inside the CONFIG_PM_SLEEP guard.
> 
> If you want to avoid the extra few bytes, just use the trick I
> suggested:
> 
> 	.pm = IS_ENABLED(CONFIG_PM_SLEEP) ? &tango_thermal_pm : NULL,

This would achieve the same result as the solution I proposed
in my v2 patch, right?

So you're saying you prefer the IS_ENABLED macro over using
#ifdef ... #else define stuff as NULL #endif

Did I get that right?

Eduardo, Zhang, what do thermal maintainers prefer?

> You should basically never have that #ifdef inside of the
> platform_driver definition.

Except when the fields don't exist, like the bug I introduced
in struct smp_operations (which you fixed).

Regards.
Arnd Bergmann July 26, 2016, 12:13 p.m. UTC | #6
On Monday, July 25, 2016 11:48:47 AM CEST Mason wrote:
> On 25/07/2016 10:52, Arnd Bergmann wrote:
> 
> > On Monday, July 25, 2016 10:18:22 AM CEST Mason wrote:
> > 
> >> Moving the SIMPLE_DEV_PM_OPS macro outside the CONFIG_PM_SLEEP guard
> >> would unconditionally define a struct dev_pm_ops, which just wastes
> >> space when CONFIG_PM_SLEEP is undefined (if I'm not mistaken).
> >>
> >> That's why I put SIMPLE_DEV_PM_OPS inside the CONFIG_PM_SLEEP guard.
> > 
> > If you want to avoid the extra few bytes, just use the trick I
> > suggested:
> > 
> >       .pm = IS_ENABLED(CONFIG_PM_SLEEP) ? &tango_thermal_pm : NULL,
> 
> This would achieve the same result as the solution I proposed
> in my v2 patch, right?
> 
> So you're saying you prefer the IS_ENABLED macro over using
> #ifdef ... #else define stuff as NULL #endif
> 
> Did I get that right?

Yes, but I'd also prefer not to hide the operations structure
at all and just rely on the __maybe_unused (ideally) or
#ifdef (not as good, but commonly used) to leave out the
functions.

> Eduardo, Zhang, what do thermal maintainers prefer?
> 
> > You should basically never have that #ifdef inside of the
> > platform_driver definition.
> 
> Except when the fields don't exist, like the bug I introduced
> in struct smp_operations (which you fixed).

Right.

	Arnd
Zhang, Rui Aug. 19, 2016, 11:29 a.m. UTC | #7
On 二, 2016-07-26 at 14:13 +0200, Arnd Bergmann wrote:
> On Monday, July 25, 2016 11:48:47 AM CEST Mason wrote:
> > 
> > On 25/07/2016 10:52, Arnd Bergmann wrote:
> > 
> > > 
> > > On Monday, July 25, 2016 10:18:22 AM CEST Mason wrote:
> > > 
> > > > 
> > > > Moving the SIMPLE_DEV_PM_OPS macro outside the CONFIG_PM_SLEEP
> > > > guard
> > > > would unconditionally define a struct dev_pm_ops, which just
> > > > wastes
> > > > space when CONFIG_PM_SLEEP is undefined (if I'm not mistaken).
> > > > 
> > > > That's why I put SIMPLE_DEV_PM_OPS inside the CONFIG_PM_SLEEP
> > > > guard.
> > > If you want to avoid the extra few bytes, just use the trick I
> > > suggested:
> > > 
> > >       .pm = IS_ENABLED(CONFIG_PM_SLEEP) ? &tango_thermal_pm :
> > > NULL,
> > This would achieve the same result as the solution I proposed
> > in my v2 patch, right?
> > 
> > So you're saying you prefer the IS_ENABLED macro over using
> > #ifdef ... #else define stuff as NULL #endif
> > 
> > Did I get that right?
> Yes, but I'd also prefer not to hide the operations structure
> at all and just rely on the __maybe_unused (ideally) or
> #ifdef (not as good, but commonly used) to leave out the
> functions.
> 
IMO, the typical way is to use #ifdef for the pm callbacks, and leave
SIMPLE_DEV_PM_OPS outside the #ifdef.
For example, drivers/ata/ahci_imx.c.

thanks,
rui
> > 
> > Eduardo, Zhang, what do thermal maintainers prefer?
> > 
> > > 
> > > You should basically never have that #ifdef inside of the
> > > platform_driver definition.
> > Except when the fields don't exist, like the bug I introduced
> > in struct smp_operations (which you fixed).
> Right.
> 
> 	Arnd
Arnd Bergmann Aug. 22, 2016, 9 p.m. UTC | #8
On Friday, August 19, 2016 7:29:56 PM CEST Zhang Rui wrote:
> On 二, 2016-07-26 at 14:13 +0200, Arnd Bergmann wrote:
> > On Monday, July 25, 2016 11:48:47 AM CEST Mason wrote:
> > > 
> > > On 25/07/2016 10:52, Arnd Bergmann wrote:
> > > 
> > > > 
> > > > On Monday, July 25, 2016 10:18:22 AM CEST Mason wrote:
> > > > 
> > > > > 
> > > > > Moving the SIMPLE_DEV_PM_OPS macro outside the CONFIG_PM_SLEEP
> > > > > guard
> > > > > would unconditionally define a struct dev_pm_ops, which just
> > > > > wastes
> > > > > space when CONFIG_PM_SLEEP is undefined (if I'm not mistaken).
> > > > > 
> > > > > That's why I put SIMPLE_DEV_PM_OPS inside the CONFIG_PM_SLEEP
> > > > > guard.
> > > > If you want to avoid the extra few bytes, just use the trick I
> > > > suggested:
> > > > 
> > > >       .pm = IS_ENABLED(CONFIG_PM_SLEEP) ? &tango_thermal_pm :
> > > > NULL,
> > > This would achieve the same result as the solution I proposed
> > > in my v2 patch, right?
> > > 
> > > So you're saying you prefer the IS_ENABLED macro over using
> > > #ifdef ... #else define stuff as NULL #endif
> > > 
> > > Did I get that right?
> > Yes, but I'd also prefer not to hide the operations structure
> > at all and just rely on the __maybe_unused (ideally) or
> > #ifdef (not as good, but commonly used) to leave out the
> > functions.
> > 
> IMO, the typical way is to use #ifdef for the pm callbacks, and leave
> SIMPLE_DEV_PM_OPS outside the #ifdef.
> For example, drivers/ata/ahci_imx.c.
> 

Lots of drivers do it like that, the main downside I see is that a
lot of them also get it wrong and use incorrect #ifdef guards,
either checking the wrong Kconfig symbol, or hiding the wrong
subset of functions.

	Arnd
Zhang, Rui Aug. 24, 2016, 8:25 a.m. UTC | #9
On 一, 2016-08-22 at 23:00 +0200, Arnd Bergmann wrote:
> On Friday, August 19, 2016 7:29:56 PM CEST Zhang Rui wrote:
> > 
> > On 二, 2016-07-26 at 14:13 +0200, Arnd Bergmann wrote:
> > > 
> > > On Monday, July 25, 2016 11:48:47 AM CEST Mason wrote:
> > > > 
> > > > 
> > > > On 25/07/2016 10:52, Arnd Bergmann wrote:
> > > > 
> > > > > 
> > > > > 
> > > > > On Monday, July 25, 2016 10:18:22 AM CEST Mason wrote:
> > > > > 
> > > > > > 
> > > > > > 
> > > > > > Moving the SIMPLE_DEV_PM_OPS macro outside the
> > > > > > CONFIG_PM_SLEEP
> > > > > > guard
> > > > > > would unconditionally define a struct dev_pm_ops, which
> > > > > > just
> > > > > > wastes
> > > > > > space when CONFIG_PM_SLEEP is undefined (if I'm not
> > > > > > mistaken).
> > > > > > 
> > > > > > That's why I put SIMPLE_DEV_PM_OPS inside the
> > > > > > CONFIG_PM_SLEEP
> > > > > > guard.
> > > > > If you want to avoid the extra few bytes, just use the trick
> > > > > I
> > > > > suggested:
> > > > > 
> > > > >       .pm = IS_ENABLED(CONFIG_PM_SLEEP) ? &tango_thermal_pm :
> > > > > NULL,
> > > > This would achieve the same result as the solution I proposed
> > > > in my v2 patch, right?
> > > > 
> > > > So you're saying you prefer the IS_ENABLED macro over using
> > > > #ifdef ... #else define stuff as NULL #endif
> > > > 
> > > > Did I get that right?
> > > Yes, but I'd also prefer not to hide the operations structure
> > > at all and just rely on the __maybe_unused (ideally) or
> > > #ifdef (not as good, but commonly used) to leave out the
> > > functions.
> > > 
> > IMO, the typical way is to use #ifdef for the pm callbacks, and
> > leave
> > SIMPLE_DEV_PM_OPS outside the #ifdef.
> > For example, drivers/ata/ahci_imx.c.
> > 
> Lots of drivers do it like that, the main downside I see is that a
> lot of them also get it wrong and use incorrect #ifdef guards,
> either checking the wrong Kconfig symbol,

This also happens when IS_ENABLED macro is used.

>  or hiding the wrong
> subset of functions.
> 
This also sounds a driver bug to me, and the driver should get fixed.
For us, it's not a problem if we do it right here, right? :)

thanks,
rui
Arnd Bergmann Aug. 24, 2016, 8:32 a.m. UTC | #10
On Wednesday, August 24, 2016 4:25:40 PM CEST Zhang Rui wrote:
> On 一, 2016-08-22 at 23:00 +0200, Arnd Bergmann wrote:
> > On Friday, August 19, 2016 7:29:56 PM CEST Zhang Rui wrote:
> > > 
> > > On 二, 2016-07-26 at 14:13 +0200, Arnd Bergmann wrote:
> > > > 
> > > > On Monday, July 25, 2016 11:48:47 AM CEST Mason wrote:
> > > > > 
> > > > > 
> > > > > On 25/07/2016 10:52, Arnd Bergmann wrote:
> > > > > 
> > > > > > 
> > > > > > 
> > > > > > On Monday, July 25, 2016 10:18:22 AM CEST Mason wrote:
> > > > > > 
> > > > > > > 
> > > > > > > 
> > > > > > > Moving the SIMPLE_DEV_PM_OPS macro outside the
> > > > > > > CONFIG_PM_SLEEP
> > > > > > > guard
> > > > > > > would unconditionally define a struct dev_pm_ops, which
> > > > > > > just
> > > > > > > wastes
> > > > > > > space when CONFIG_PM_SLEEP is undefined (if I'm not
> > > > > > > mistaken).
> > > > > > > 
> > > > > > > That's why I put SIMPLE_DEV_PM_OPS inside the
> > > > > > > CONFIG_PM_SLEEP
> > > > > > > guard.
> > > > > > If you want to avoid the extra few bytes, just use the trick
> > > > > > I
> > > > > > suggested:
> > > > > > 
> > > > > >       .pm = IS_ENABLED(CONFIG_PM_SLEEP) ? &tango_thermal_pm :
> > > > > > NULL,
> > > > > This would achieve the same result as the solution I proposed
> > > > > in my v2 patch, right?
> > > > > 
> > > > > So you're saying you prefer the IS_ENABLED macro over using
> > > > > #ifdef ... #else define stuff as NULL #endif
> > > > > 
> > > > > Did I get that right?
> > > > Yes, but I'd also prefer not to hide the operations structure
> > > > at all and just rely on the __maybe_unused (ideally) or
> > > > #ifdef (not as good, but commonly used) to leave out the
> > > > functions.
> > > > 
> > > IMO, the typical way is to use #ifdef for the pm callbacks, and
> > > leave
> > > SIMPLE_DEV_PM_OPS outside the #ifdef.
> > > For example, drivers/ata/ahci_imx.c.
> > > 
> > Lots of drivers do it like that, the main downside I see is that a
> > lot of them also get it wrong and use incorrect #ifdef guards,
> > either checking the wrong Kconfig symbol,
> 
> This also happens when IS_ENABLED macro is used.

Right, but not with the __maybe_unused annotations.

> >  or hiding the wrong
> > subset of functions.
> > 
> This also sounds a driver bug to me, and the driver should get fixed.
> For us, it's not a problem if we do it right here, right? :)

I think the ideal is to have only one set of conditionals in each
driver, so at least you don't get a mismatch between them.

SIMPLE_DEV_PM_OPS uses conditional evaluation (but does not
show the reference to the compiler). Annotating the functions as
__maybe_unused lets the compiler decide for itself if they should
be dropped or not, which means we use only the conditional inside
of SIMPLE_DEV_PM_OPS.

Ideally, SIMPLE_DEV_PM_OPS itself should have used an IS_ENABLED()
check instead of the #ifdef, that would have made it possible to
just leave the function always defined with no __maybe_unused, but
still have it dropped from the object code without a warning
when there is no runtime reference.

	Arnd
Mason Aug. 24, 2016, 3:12 p.m. UTC | #11
On 24/08/2016 10:32, Arnd Bergmann wrote:

> I think the ideal is to have only one set of conditionals in each
> driver, so at least you don't get a mismatch between them.
> 
> SIMPLE_DEV_PM_OPS uses conditional evaluation (but does not
> show the reference to the compiler). Annotating the functions as
> __maybe_unused lets the compiler decide for itself if they should
> be dropped or not, which means we use only the conditional inside
> of SIMPLE_DEV_PM_OPS.
> 
> Ideally, SIMPLE_DEV_PM_OPS itself should have used an IS_ENABLED()
> check instead of the #ifdef, that would have made it possible to
> just leave the function always defined with no __maybe_unused, but
> still have it dropped from the object code without a warning
> when there is no runtime reference.

I'm not sure my trivial issue deserves this much discussion. I just
want the patch to be upstream in some form.

I'll submit one more patch, with SIMPLE_DEV_PM_OPS used unconditionally,
and annotate the resume function with __maybe_unused.

This will waste the space of the struct on systems where S3 is disabled,
but it seems to be the preferred solution, IIUC.

Regards.
diff mbox

Patch

diff --git a/drivers/thermal/tango_thermal.c b/drivers/thermal/tango_thermal.c
index 70e0d9f406e9..957f8937e126 100644
--- a/drivers/thermal/tango_thermal.c
+++ b/drivers/thermal/tango_thermal.c
@@ -64,6 +64,12 @@  static const struct thermal_zone_of_device_ops ops = {
 	.get_temp	= tango_get_temp,
 };
 
+static void tango_thermal_init(struct tango_thermal_priv *priv)
+{
+	writel(0, priv->base + TEMPSI_CFG);
+	writel(CMD_ON, priv->base + TEMPSI_CMD);
+}
+
 static int tango_thermal_probe(struct platform_device *pdev)
 {
 	struct resource *res;
@@ -79,14 +85,24 @@  static int tango_thermal_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->base))
 		return PTR_ERR(priv->base);
 
+	platform_set_drvdata(pdev, priv);
 	priv->thresh_idx = IDX_MIN;
-	writel(0, priv->base + TEMPSI_CFG);
-	writel(CMD_ON, priv->base + TEMPSI_CMD);
+	tango_thermal_init(priv);
 
 	tzdev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, priv, &ops);
 	return PTR_ERR_OR_ZERO(tzdev);
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int tango_thermal_resume(struct device *dev)
+{
+	tango_thermal_init(dev_get_drvdata(dev));
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(tango_thermal_pm, NULL, tango_thermal_resume);
+#endif
+
 static const struct of_device_id tango_sensor_ids[] = {
 	{
 		.compatible = "sigma,smp8758-thermal",
@@ -99,6 +115,9 @@  static struct platform_driver tango_thermal_driver = {
 	.driver	= {
 		.name		= "tango-thermal",
 		.of_match_table	= tango_sensor_ids,
+#ifdef CONFIG_PM_SLEEP
+		.pm		= &tango_thermal_pm,
+#endif
 	},
 };