Commit d529de29 authored by Mark Brown's avatar Mark Brown Committed by Jean Delvare

i2c: Factor out runtime suspend checks from PM operations

When devices use dev_pm_ops the I2C API is implementing standard functionality
for integration with runtime PM and for checking for the presence of a per
device op. The PM core provides pm_generic_ functions implementing this
behaviour - use them to reduce coupling with future PM updates.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent 5219bf88
...@@ -196,40 +196,29 @@ static int i2c_device_pm_suspend(struct device *dev) ...@@ -196,40 +196,29 @@ static int i2c_device_pm_suspend(struct device *dev)
{ {
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
if (pm) { if (pm)
if (pm_runtime_suspended(dev)) return pm_generic_suspend(dev);
return 0;
else else
return pm->suspend ? pm->suspend(dev) : 0;
}
return i2c_legacy_suspend(dev, PMSG_SUSPEND); return i2c_legacy_suspend(dev, PMSG_SUSPEND);
} }
static int i2c_device_pm_resume(struct device *dev) static int i2c_device_pm_resume(struct device *dev)
{ {
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
int ret;
if (pm) if (pm)
ret = pm->resume ? pm->resume(dev) : 0; return pm_generic_resume(dev);
else else
ret = i2c_legacy_resume(dev); return i2c_legacy_resume(dev);
return ret;
} }
static int i2c_device_pm_freeze(struct device *dev) static int i2c_device_pm_freeze(struct device *dev)
{ {
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
if (pm) { if (pm)
if (pm_runtime_suspended(dev)) return pm_generic_freeze(dev);
return 0;
else else
return pm->freeze ? pm->freeze(dev) : 0;
}
return i2c_legacy_suspend(dev, PMSG_FREEZE); return i2c_legacy_suspend(dev, PMSG_FREEZE);
} }
...@@ -237,13 +226,9 @@ static int i2c_device_pm_thaw(struct device *dev) ...@@ -237,13 +226,9 @@ static int i2c_device_pm_thaw(struct device *dev)
{ {
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
if (pm) { if (pm)
if (pm_runtime_suspended(dev)) return pm_generic_thaw(dev);
return 0;
else else
return pm->thaw ? pm->thaw(dev) : 0;
}
return i2c_legacy_resume(dev); return i2c_legacy_resume(dev);
} }
...@@ -251,33 +236,20 @@ static int i2c_device_pm_poweroff(struct device *dev) ...@@ -251,33 +236,20 @@ static int i2c_device_pm_poweroff(struct device *dev)
{ {
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
if (pm) { if (pm)
if (pm_runtime_suspended(dev)) return pm_generic_poweroff(dev);
return 0;
else else
return pm->poweroff ? pm->poweroff(dev) : 0;
}
return i2c_legacy_suspend(dev, PMSG_HIBERNATE); return i2c_legacy_suspend(dev, PMSG_HIBERNATE);
} }
static int i2c_device_pm_restore(struct device *dev) static int i2c_device_pm_restore(struct device *dev)
{ {
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
int ret;
if (pm) if (pm)
ret = pm->restore ? pm->restore(dev) : 0; return pm_generic_restore(dev);
else else
ret = i2c_legacy_resume(dev); return i2c_legacy_resume(dev);
if (!ret) {
pm_runtime_disable(dev);
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
}
return ret;
} }
#else /* !CONFIG_PM_SLEEP */ #else /* !CONFIG_PM_SLEEP */
#define i2c_device_pm_suspend NULL #define i2c_device_pm_suspend NULL
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment