linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: designware: Prevent runtime suspend during adapter registration
@ 2016-02-11 14:36 Jarkko Nikula
  2016-02-11 14:47 ` Mika Westerberg
  2016-02-12 19:04 ` Wolfram Sang
  0 siblings, 2 replies; 3+ messages in thread
From: Jarkko Nikula @ 2016-02-11 14:36 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Andy Shevchenko, Mika Westerberg, linux-i2c, linux-pm,
	Jarkko Nikula

There can be unnecessary runtime suspend-resume cycle during
i2c-designware-platdrv probe when it registers the I2C adapter device. This
happens because i2c-designware-platdrv is set to initially active platform
device in its probe function and is a parent of I2C adapter.

In that case power.usage_count of i2c-designware device is zero and
pm_runtime_get()/pm_runtime_put() cycle during probe could put it into
runtime suspend. This happens when the i2c_register_adapter() calls the
device_register():

i2c_register_adapter
  device_register
    device_add
      bus_probe_device
        device_initial_probe
          __device_attach
            if (dev->parent) pm_runtime_get_sync(dev->parent)
            ...
            if (dev->parent) pm_runtime_put(dev->parent)

After that the i2c_register_adapter() continues registering I2C slave
devices. In case slave device probe does I2C transfers the parent will
resume again and thus get a needless runtime suspend/resume cycle during
adapter registration.

Prevent this while retaining the runtime PM status of i2c-designware by
only incrementing/decrementing device power usage count during I2C
adapter registration. That makes sure there won't be spurious runtime PM
status changes and lets the driver core to idle the device after probe
finishes.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
I sent earlier an RFC doing the same in i2c-core because it looked a few
other I2C bus drivers might benefit too. However, as Alan pointed, it's
bad form to do PM on your parent:
http://www.spinics.net/lists/linux-i2c/msg22587.html

After hacking a bit with PM in i2c-designware-pcidrv.c I can say this is
only for i2c-designware-platdrv case. Runtime PM settings are a little
different between platform and PCI devices. For instance runtime PM is
enabled by default for PCI devices but forbidded and there seems be no
reason to move runtime PM calls in i2c_dw_pci_probe().

Anyway, I decided to put PM usage count increment/decrement calls to
i2c-designware-core.c: i2c_dw_probe() because change lines are more
clear there, are more future proof and don't harm PCI case.
---
 drivers/i2c/busses/i2c-designware-core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index 10fbd6d841e0..dfe35087b40d 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -883,9 +883,17 @@ int i2c_dw_probe(struct dw_i2c_dev *dev)
 		return r;
 	}
 
+	/*
+	 * Increment PM usage count during adapter registration in order to
+	 * avoid possible spurious runtime suspend when adapter device is
+	 * registered to the device core and immediate resume in case bus has
+	 * registered I2C slaves that do I2C transfers in their probe.
+	 */
+	pm_runtime_get_noresume(dev->dev);
 	r = i2c_add_numbered_adapter(adap);
 	if (r)
 		dev_err(dev->dev, "failure adding adapter: %d\n", r);
+	pm_runtime_put_noidle(dev->dev);
 
 	return r;
 }
-- 
2.7.0

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

* Re: [PATCH] i2c: designware: Prevent runtime suspend during adapter registration
  2016-02-11 14:36 [PATCH] i2c: designware: Prevent runtime suspend during adapter registration Jarkko Nikula
@ 2016-02-11 14:47 ` Mika Westerberg
  2016-02-12 19:04 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Mika Westerberg @ 2016-02-11 14:47 UTC (permalink / raw)
  To: Jarkko Nikula; +Cc: Wolfram Sang, Andy Shevchenko, linux-i2c, linux-pm

On Thu, Feb 11, 2016 at 04:36:03PM +0200, Jarkko Nikula wrote:
> There can be unnecessary runtime suspend-resume cycle during
> i2c-designware-platdrv probe when it registers the I2C adapter device. This
> happens because i2c-designware-platdrv is set to initially active platform
> device in its probe function and is a parent of I2C adapter.
> 
> In that case power.usage_count of i2c-designware device is zero and
> pm_runtime_get()/pm_runtime_put() cycle during probe could put it into
> runtime suspend. This happens when the i2c_register_adapter() calls the
> device_register():
> 
> i2c_register_adapter
>   device_register
>     device_add
>       bus_probe_device
>         device_initial_probe
>           __device_attach
>             if (dev->parent) pm_runtime_get_sync(dev->parent)
>             ...
>             if (dev->parent) pm_runtime_put(dev->parent)
> 
> After that the i2c_register_adapter() continues registering I2C slave
> devices. In case slave device probe does I2C transfers the parent will
> resume again and thus get a needless runtime suspend/resume cycle during
> adapter registration.
> 
> Prevent this while retaining the runtime PM status of i2c-designware by
> only incrementing/decrementing device power usage count during I2C
> adapter registration. That makes sure there won't be spurious runtime PM
> status changes and lets the driver core to idle the device after probe
> finishes.
> 
> Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

I don't know any better way to fix this,

Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

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

* Re: [PATCH] i2c: designware: Prevent runtime suspend during adapter registration
  2016-02-11 14:36 [PATCH] i2c: designware: Prevent runtime suspend during adapter registration Jarkko Nikula
  2016-02-11 14:47 ` Mika Westerberg
@ 2016-02-12 19:04 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2016-02-12 19:04 UTC (permalink / raw)
  To: Jarkko Nikula; +Cc: Andy Shevchenko, Mika Westerberg, linux-i2c, linux-pm

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

On Thu, Feb 11, 2016 at 04:36:03PM +0200, Jarkko Nikula wrote:
> There can be unnecessary runtime suspend-resume cycle during
> i2c-designware-platdrv probe when it registers the I2C adapter device. This
> happens because i2c-designware-platdrv is set to initially active platform
> device in its probe function and is a parent of I2C adapter.
> 
> In that case power.usage_count of i2c-designware device is zero and
> pm_runtime_get()/pm_runtime_put() cycle during probe could put it into
> runtime suspend. This happens when the i2c_register_adapter() calls the
> device_register():
> 
> i2c_register_adapter
>   device_register
>     device_add
>       bus_probe_device
>         device_initial_probe
>           __device_attach
>             if (dev->parent) pm_runtime_get_sync(dev->parent)
>             ...
>             if (dev->parent) pm_runtime_put(dev->parent)
> 
> After that the i2c_register_adapter() continues registering I2C slave
> devices. In case slave device probe does I2C transfers the parent will
> resume again and thus get a needless runtime suspend/resume cycle during
> adapter registration.
> 
> Prevent this while retaining the runtime PM status of i2c-designware by
> only incrementing/decrementing device power usage count during I2C
> adapter registration. That makes sure there won't be spurious runtime PM
> status changes and lets the driver core to idle the device after probe
> finishes.
> 
> Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

Applied to for-next, thanks!


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2016-02-12 19:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-11 14:36 [PATCH] i2c: designware: Prevent runtime suspend during adapter registration Jarkko Nikula
2016-02-11 14:47 ` Mika Westerberg
2016-02-12 19:04 ` Wolfram Sang

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