linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH v2] thermal: tango: add resume support
@ 2016-06-28 11:37 Mason
  2016-07-18  9:33 ` Thierry Reding
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Mason @ 2016-06-28 11:37 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Reviewed-by: Kevin Hilman <khilman@baylibre.com>
Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
---
Add Kevin's Reviewed-by tag.
Eduardo/Zhang, can you pick this patch up for 4.8?
---
 drivers/thermal/tango_thermal.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/tango_thermal.c b/drivers/thermal/tango_thermal.c
index 70e0d9f406e9..d571ce2f546d 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,30 @@ 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)
+{
+	struct tango_thermal_priv *priv = dev_get_drvdata(dev);
+	tango_thermal_init(priv);
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(tango_thermal_pm, NULL, tango_thermal_resume);
+
+#define DEV_PM_OPS	&tango_thermal_pm
+#else
+#define DEV_PM_OPS	NULL
+#endif
+
 static const struct of_device_id tango_sensor_ids[] = {
 	{
 		.compatible = "sigma,smp8758-thermal",
@@ -99,6 +121,7 @@ static struct platform_driver tango_thermal_driver = {
 	.driver	= {
 		.name		= "tango-thermal",
 		.of_match_table	= tango_sensor_ids,
+		.pm		= DEV_PM_OPS,
 	},
 };
 
-- 
2.8.2

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

* [RESEND PATCH v2] thermal: tango: add resume support
  2016-06-28 11:37 [RESEND PATCH v2] thermal: tango: add resume support Mason
@ 2016-07-18  9:33 ` Thierry Reding
  2016-07-18 10:09   ` Arnd Bergmann
  2016-07-18 12:21 ` [PATCH v3] " Mason
  2016-09-02 13:17 ` [PATCH v4] " Marc Gonzalez
  2 siblings, 1 reply; 20+ messages in thread
From: Thierry Reding @ 2016-07-18  9:33 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Jun 28, 2016 at 01:37:58PM +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.
> 
> Reviewed-by: Kevin Hilman <khilman@baylibre.com>
> Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
> ---
> Add Kevin's Reviewed-by tag.
> Eduardo/Zhang, can you pick this patch up for 4.8?
> ---
>  drivers/thermal/tango_thermal.c | 27 +++++++++++++++++++++++++--
>  1 file changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/thermal/tango_thermal.c b/drivers/thermal/tango_thermal.c
> index 70e0d9f406e9..d571ce2f546d 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,30 @@ 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)
> +{
> +	struct tango_thermal_priv *priv = dev_get_drvdata(dev);
> +	tango_thermal_init(priv);

checkpatch will warn about this. You're supposed to separate the local
variable declarations and code by a single blank line.

> +
> +	return 0;
> +}
> +
> +static SIMPLE_DEV_PM_OPS(tango_thermal_pm, NULL, tango_thermal_resume);
> +
> +#define DEV_PM_OPS	&tango_thermal_pm
> +#else
> +#define DEV_PM_OPS	NULL
> +#endif

In my experience it's often not useful to #ifdef the struct pm_ops.
These days you almost certainly want PM enabled, and the conditional
doesn't save you all that much in the first place, because it's not
unlikely for this to fit into some of the space that would be padded
out anyway.

As a side-note, I've noticed that this driver has the following
dependencies:

	depends on ARCH_TANGO || COMPILE_TEST

which, last I checked, is probably going to fail on some architectures
because you need at least another one on HAS_IOMEM (for readl() and
writel()). That's a pre-existing problem, of course, so should be fixed
in a separate patch.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160718/b630d14e/attachment.sig>

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

* [RESEND PATCH v2] thermal: tango: add resume support
  2016-07-18  9:33 ` Thierry Reding
@ 2016-07-18 10:09   ` Arnd Bergmann
  2016-07-18 10:13     ` Thierry Reding
  0 siblings, 1 reply; 20+ messages in thread
From: Arnd Bergmann @ 2016-07-18 10:09 UTC (permalink / raw)
  To: linux-arm-kernel

On Monday, July 18, 2016 11:33:28 AM CEST Thierry Reding wrote:

> > +
> > +     return 0;
> > +}
> > +
> > +static SIMPLE_DEV_PM_OPS(tango_thermal_pm, NULL, tango_thermal_resume);
> > +
> > +#define DEV_PM_OPS   &tango_thermal_pm
> > +#else
> > +#define DEV_PM_OPS   NULL
> > +#endif
> 
> In my experience it's often not useful to #ifdef the struct pm_ops.
> These days you almost certainly want PM enabled, and the conditional
> doesn't save you all that much in the first place, because it's not
> unlikely for this to fit into some of the space that would be padded
> out anyway.

This will also generate a warning when CONFIG_PM_SLEEP is not set.
Better write this as

#define DEV_PM_OPS (IS_ENABLED(CONFIG_PM_SLEEP) ? &tango_thermal_pm : NULL)

so the compiler can drop the variable definition when it's not
needed.

> As a side-note, I've noticed that this driver has the following
> dependencies:
> 
>         depends on ARCH_TANGO || COMPILE_TEST
> 
> which, last I checked, is probably going to fail on some architectures
> because you need at least another one on HAS_IOMEM (for readl() and
> writel()). That's a pre-existing problem, of course, so should be fixed
> in a separate patch.

No need, we just merged a patch to no longer allow COMPILE_TEST on
arch/um/, so we can safely rely on MMIO to be available for COMPILE_TEST.

	Arnd

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

* [RESEND PATCH v2] thermal: tango: add resume support
  2016-07-18 10:09   ` Arnd Bergmann
@ 2016-07-18 10:13     ` Thierry Reding
  2016-07-18 11:10       ` Arnd Bergmann
  0 siblings, 1 reply; 20+ messages in thread
From: Thierry Reding @ 2016-07-18 10:13 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jul 18, 2016 at 12:09:39PM +0200, Arnd Bergmann wrote:
> On Monday, July 18, 2016 11:33:28 AM CEST Thierry Reding wrote:
> 
> > > +
> > > +     return 0;
> > > +}
> > > +
> > > +static SIMPLE_DEV_PM_OPS(tango_thermal_pm, NULL, tango_thermal_resume);
> > > +
> > > +#define DEV_PM_OPS   &tango_thermal_pm
> > > +#else
> > > +#define DEV_PM_OPS   NULL
> > > +#endif
> > 
> > In my experience it's often not useful to #ifdef the struct pm_ops.
> > These days you almost certainly want PM enabled, and the conditional
> > doesn't save you all that much in the first place, because it's not
> > unlikely for this to fit into some of the space that would be padded
> > out anyway.
> 
> This will also generate a warning when CONFIG_PM_SLEEP is not set.
> Better write this as
> 
> #define DEV_PM_OPS (IS_ENABLED(CONFIG_PM_SLEEP) ? &tango_thermal_pm : NULL)
> 
> so the compiler can drop the variable definition when it's not
> needed.

My suggestion was to define tango_thermal_pm unconditionally to avoid
any of these tricks. For any real use-case in which the 92 bytes for the
struct dev_pm_ops would matter you most likely want PM_SLEEP anyway, so
I don't really see why we would even want to make it optional.

> > As a side-note, I've noticed that this driver has the following
> > dependencies:
> > 
> >         depends on ARCH_TANGO || COMPILE_TEST
> > 
> > which, last I checked, is probably going to fail on some architectures
> > because you need at least another one on HAS_IOMEM (for readl() and
> > writel()). That's a pre-existing problem, of course, so should be fixed
> > in a separate patch.
> 
> No need, we just merged a patch to no longer allow COMPILE_TEST on
> arch/um/, so we can safely rely on MMIO to be available for COMPILE_TEST.

I thought at least S390 didn't have readl() and writel() either, at
least when PCI wasn't enabled, or some such.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160718/dca40322/attachment.sig>

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

* [RESEND PATCH v2] thermal: tango: add resume support
  2016-07-18 10:13     ` Thierry Reding
@ 2016-07-18 11:10       ` Arnd Bergmann
  2016-07-18 11:28         ` Thierry Reding
  0 siblings, 1 reply; 20+ messages in thread
From: Arnd Bergmann @ 2016-07-18 11:10 UTC (permalink / raw)
  To: linux-arm-kernel

On Monday, July 18, 2016 12:13:38 PM CEST Thierry Reding wrote:
> On Mon, Jul 18, 2016 at 12:09:39PM +0200, Arnd Bergmann wrote:
> > On Monday, July 18, 2016 11:33:28 AM CEST Thierry Reding wrote:
> > 
> > > > +
> > > > +     return 0;
> > > > +}
> > > > +
> > > > +static SIMPLE_DEV_PM_OPS(tango_thermal_pm, NULL, tango_thermal_resume);
> > > > +
> > > > +#define DEV_PM_OPS   &tango_thermal_pm
> > > > +#else
> > > > +#define DEV_PM_OPS   NULL
> > > > +#endif
> > > 
> > > In my experience it's often not useful to #ifdef the struct pm_ops.
> > > These days you almost certainly want PM enabled, and the conditional
> > > doesn't save you all that much in the first place, because it's not
> > > unlikely for this to fit into some of the space that would be padded
> > > out anyway.
> > 
> > This will also generate a warning when CONFIG_PM_SLEEP is not set.
> > Better write this as
> > 
> > #define DEV_PM_OPS (IS_ENABLED(CONFIG_PM_SLEEP) ? &tango_thermal_pm : NULL)
> > 
> > so the compiler can drop the variable definition when it's not
> > needed.
> 
> My suggestion was to define tango_thermal_pm unconditionally to avoid
> any of these tricks. For any real use-case in which the 92 bytes for the
> struct dev_pm_ops would matter you most likely want PM_SLEEP anyway, so
> I don't really see why we would even want to make it optional.

Sure, leaving it unconditional works too. 

> > > As a side-note, I've noticed that this driver has the following
> > > dependencies:
> > > 
> > >         depends on ARCH_TANGO || COMPILE_TEST
> > > 
> > > which, last I checked, is probably going to fail on some architectures
> > > because you need at least another one on HAS_IOMEM (for readl() and
> > > writel()). That's a pre-existing problem, of course, so should be fixed
> > > in a separate patch.
> > 
> > No need, we just merged a patch to no longer allow COMPILE_TEST on
> > arch/um/, so we can safely rely on MMIO to be available for COMPILE_TEST.
> 
> I thought at least S390 didn't have readl() and writel() either, at
> least when PCI wasn't enabled, or some such.

Yes, but they've never complained about COMPILE_TEST breakage because
of that. Tile is in the same boat too in some configurations.

	Arnd

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

* [RESEND PATCH v2] thermal: tango: add resume support
  2016-07-18 11:10       ` Arnd Bergmann
@ 2016-07-18 11:28         ` Thierry Reding
  0 siblings, 0 replies; 20+ messages in thread
From: Thierry Reding @ 2016-07-18 11:28 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jul 18, 2016 at 01:10:07PM +0200, Arnd Bergmann wrote:
> On Monday, July 18, 2016 12:13:38 PM CEST Thierry Reding wrote:
> > On Mon, Jul 18, 2016 at 12:09:39PM +0200, Arnd Bergmann wrote:
> > > On Monday, July 18, 2016 11:33:28 AM CEST Thierry Reding wrote:
> > > 
> > > > > +
> > > > > +     return 0;
> > > > > +}
> > > > > +
> > > > > +static SIMPLE_DEV_PM_OPS(tango_thermal_pm, NULL, tango_thermal_resume);
> > > > > +
> > > > > +#define DEV_PM_OPS   &tango_thermal_pm
> > > > > +#else
> > > > > +#define DEV_PM_OPS   NULL
> > > > > +#endif
> > > > 
> > > > In my experience it's often not useful to #ifdef the struct pm_ops.
> > > > These days you almost certainly want PM enabled, and the conditional
> > > > doesn't save you all that much in the first place, because it's not
> > > > unlikely for this to fit into some of the space that would be padded
> > > > out anyway.
> > > 
> > > This will also generate a warning when CONFIG_PM_SLEEP is not set.
> > > Better write this as
> > > 
> > > #define DEV_PM_OPS (IS_ENABLED(CONFIG_PM_SLEEP) ? &tango_thermal_pm : NULL)
> > > 
> > > so the compiler can drop the variable definition when it's not
> > > needed.
> > 
> > My suggestion was to define tango_thermal_pm unconditionally to avoid
> > any of these tricks. For any real use-case in which the 92 bytes for the
> > struct dev_pm_ops would matter you most likely want PM_SLEEP anyway, so
> > I don't really see why we would even want to make it optional.
> 
> Sure, leaving it unconditional works too. 
> 
> > > > As a side-note, I've noticed that this driver has the following
> > > > dependencies:
> > > > 
> > > >         depends on ARCH_TANGO || COMPILE_TEST
> > > > 
> > > > which, last I checked, is probably going to fail on some architectures
> > > > because you need at least another one on HAS_IOMEM (for readl() and
> > > > writel()). That's a pre-existing problem, of course, so should be fixed
> > > > in a separate patch.
> > > 
> > > No need, we just merged a patch to no longer allow COMPILE_TEST on
> > > arch/um/, so we can safely rely on MMIO to be available for COMPILE_TEST.
> > 
> > I thought at least S390 didn't have readl() and writel() either, at
> > least when PCI wasn't enabled, or some such.
> 
> Yes, but they've never complained about COMPILE_TEST breakage because
> of that. Tile is in the same boat too in some configurations.

Ah, okay. I remember running into this occasionally when doing
randconfig builds on S390. That was many moons ago, so perhaps it's not
an issue anymore, and maybe I've become overly cautious about the
COMPILE_TEST dependency.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160718/a8f6b2c4/attachment.sig>

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

* [PATCH v3] thermal: tango: add resume support
  2016-06-28 11:37 [RESEND PATCH v2] thermal: tango: add resume support Mason
  2016-07-18  9:33 ` Thierry Reding
@ 2016-07-18 12:21 ` Mason
  2016-07-20 10:50   ` Thierry Reding
  2016-07-22 22:00   ` Kevin Hilman
  2016-09-02 13:17 ` [PATCH v4] " Marc Gonzalez
  2 siblings, 2 replies; 20+ messages in thread
From: Mason @ 2016-07-18 12:21 UTC (permalink / raw)
  To: linux-arm-kernel

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
+
 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
 	},
 };
 
-- 
2.9.0

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

* [PATCH v3] thermal: tango: add resume support
  2016-07-18 12:21 ` [PATCH v3] " Mason
@ 2016-07-20 10:50   ` Thierry Reding
  2016-07-22 22:00   ` Kevin Hilman
  1 sibling, 0 replies; 20+ messages in thread
From: Thierry Reding @ 2016-07-20 10:50 UTC (permalink / raw)
  To: linux-arm-kernel

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>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160720/37477eea/attachment.sig>

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

* [PATCH v3] thermal: tango: add resume support
  2016-07-18 12:21 ` [PATCH v3] " Mason
  2016-07-20 10:50   ` Thierry Reding
@ 2016-07-22 22:00   ` Kevin Hilman
  2016-07-25  8:18     ` Mason
  1 sibling, 1 reply; 20+ messages in thread
From: Kevin Hilman @ 2016-07-22 22:00 UTC (permalink / raw)
  To: linux-arm-kernel

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

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

* [PATCH v3] thermal: tango: add resume support
  2016-07-22 22:00   ` Kevin Hilman
@ 2016-07-25  8:18     ` Mason
  2016-07-25  8:52       ` Arnd Bergmann
  0 siblings, 1 reply; 20+ messages in thread
From: Mason @ 2016-07-25  8:18 UTC (permalink / raw)
  To: linux-arm-kernel

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.

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

* [PATCH v3] thermal: tango: add resume support
  2016-07-25  8:18     ` Mason
@ 2016-07-25  8:52       ` Arnd Bergmann
  2016-07-25  9:48         ` Mason
  0 siblings, 1 reply; 20+ messages in thread
From: Arnd Bergmann @ 2016-07-25  8:52 UTC (permalink / raw)
  To: linux-arm-kernel

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

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

* [PATCH v3] thermal: tango: add resume support
  2016-07-25  8:52       ` Arnd Bergmann
@ 2016-07-25  9:48         ` Mason
  2016-07-26 12:13           ` Arnd Bergmann
  0 siblings, 1 reply; 20+ messages in thread
From: Mason @ 2016-07-25  9:48 UTC (permalink / raw)
  To: linux-arm-kernel

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.

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

* [PATCH v3] thermal: tango: add resume support
  2016-07-25  9:48         ` Mason
@ 2016-07-26 12:13           ` Arnd Bergmann
  2016-08-19 11:29             ` Zhang Rui
  0 siblings, 1 reply; 20+ messages in thread
From: Arnd Bergmann @ 2016-07-26 12:13 UTC (permalink / raw)
  To: linux-arm-kernel

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

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

* [PATCH v3] thermal: tango: add resume support
  2016-07-26 12:13           ` Arnd Bergmann
@ 2016-08-19 11:29             ` Zhang Rui
  2016-08-22 21:00               ` Arnd Bergmann
  0 siblings, 1 reply; 20+ messages in thread
From: Zhang Rui @ 2016-08-19 11:29 UTC (permalink / raw)
  To: linux-arm-kernel

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

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

* [PATCH v3] thermal: tango: add resume support
  2016-08-19 11:29             ` Zhang Rui
@ 2016-08-22 21:00               ` Arnd Bergmann
  2016-08-24  8:25                 ` Zhang Rui
  0 siblings, 1 reply; 20+ messages in thread
From: Arnd Bergmann @ 2016-08-22 21:00 UTC (permalink / raw)
  To: linux-arm-kernel

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

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

* [PATCH v3] thermal: tango: add resume support
  2016-08-22 21:00               ` Arnd Bergmann
@ 2016-08-24  8:25                 ` Zhang Rui
  2016-08-24  8:32                   ` Arnd Bergmann
  0 siblings, 1 reply; 20+ messages in thread
From: Zhang Rui @ 2016-08-24  8:25 UTC (permalink / raw)
  To: linux-arm-kernel

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

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

* [PATCH v3] thermal: tango: add resume support
  2016-08-24  8:25                 ` Zhang Rui
@ 2016-08-24  8:32                   ` Arnd Bergmann
  2016-08-24 15:12                     ` Mason
  0 siblings, 1 reply; 20+ messages in thread
From: Arnd Bergmann @ 2016-08-24  8:32 UTC (permalink / raw)
  To: linux-arm-kernel

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

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

* [PATCH v3] thermal: tango: add resume support
  2016-08-24  8:32                   ` Arnd Bergmann
@ 2016-08-24 15:12                     ` Mason
  0 siblings, 0 replies; 20+ messages in thread
From: Mason @ 2016-08-24 15:12 UTC (permalink / raw)
  To: linux-arm-kernel

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.

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

* [PATCH v4] thermal: tango: add resume support
  2016-06-28 11:37 [RESEND PATCH v2] thermal: tango: add resume support Mason
  2016-07-18  9:33 ` Thierry Reding
  2016-07-18 12:21 ` [PATCH v3] " Mason
@ 2016-09-02 13:17 ` Marc Gonzalez
  2016-09-02 20:54   ` Kevin Hilman
  2 siblings, 1 reply; 20+ messages in thread
From: Marc Gonzalez @ 2016-09-02 13:17 UTC (permalink / raw)
  To: linux-arm-kernel

When this platform is suspended, firmware powers the entire SoC down,
except a few hardware blocks waiting for wakeup events. 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>
---
Earlier versions of this patch were reviewed by Kevin and Thierry.
The current form is preferred by Arnd.
---
 drivers/thermal/tango_thermal.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/tango_thermal.c b/drivers/thermal/tango_thermal.c
index 70e0d9f406e9..201304aeafeb 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,22 @@ 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);
 }
 
+static int __maybe_unused 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);
+
 static const struct of_device_id tango_sensor_ids[] = {
 	{
 		.compatible = "sigma,smp8758-thermal",
@@ -99,6 +113,7 @@ static struct platform_driver tango_thermal_driver = {
 	.driver	= {
 		.name		= "tango-thermal",
 		.of_match_table	= tango_sensor_ids,
+		.pm		= &tango_thermal_pm,
 	},
 };
 
-- 
2.9.0

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

* [PATCH v4] thermal: tango: add resume support
  2016-09-02 13:17 ` [PATCH v4] " Marc Gonzalez
@ 2016-09-02 20:54   ` Kevin Hilman
  0 siblings, 0 replies; 20+ messages in thread
From: Kevin Hilman @ 2016-09-02 20:54 UTC (permalink / raw)
  To: linux-arm-kernel

Marc Gonzalez <marc_gonzalez@sigmadesigns.com> writes:

> When this platform is suspended, firmware powers the entire SoC down,
> except a few hardware blocks waiting for wakeup events. 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>

Reviewed-by: Kevin Hilman <khilman@baylibre.com>

> ---
> Earlier versions of this patch were reviewed by Kevin and Thierry.
> The current form is preferred by Arnd.
> ---
>  drivers/thermal/tango_thermal.c | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/tango_thermal.c b/drivers/thermal/tango_thermal.c
> index 70e0d9f406e9..201304aeafeb 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,22 @@ 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);
>  }
>  
> +static int __maybe_unused 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);
> +
>  static const struct of_device_id tango_sensor_ids[] = {
>  	{
>  		.compatible = "sigma,smp8758-thermal",
> @@ -99,6 +113,7 @@ static struct platform_driver tango_thermal_driver = {
>  	.driver	= {
>  		.name		= "tango-thermal",
>  		.of_match_table	= tango_sensor_ids,
> +		.pm		= &tango_thermal_pm,
>  	},
>  };

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

end of thread, other threads:[~2016-09-02 20:54 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-28 11:37 [RESEND PATCH v2] thermal: tango: add resume support Mason
2016-07-18  9:33 ` Thierry Reding
2016-07-18 10:09   ` Arnd Bergmann
2016-07-18 10:13     ` Thierry Reding
2016-07-18 11:10       ` Arnd Bergmann
2016-07-18 11:28         ` Thierry Reding
2016-07-18 12:21 ` [PATCH v3] " Mason
2016-07-20 10:50   ` Thierry Reding
2016-07-22 22:00   ` Kevin Hilman
2016-07-25  8:18     ` Mason
2016-07-25  8:52       ` Arnd Bergmann
2016-07-25  9:48         ` Mason
2016-07-26 12:13           ` Arnd Bergmann
2016-08-19 11:29             ` Zhang Rui
2016-08-22 21:00               ` Arnd Bergmann
2016-08-24  8:25                 ` Zhang Rui
2016-08-24  8:32                   ` Arnd Bergmann
2016-08-24 15:12                     ` Mason
2016-09-02 13:17 ` [PATCH v4] " Marc Gonzalez
2016-09-02 20:54   ` Kevin Hilman

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