Merge branch 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging
* 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging: i2c: Encourage move to dev_pm_ops by warning on use of legacy methods i2c: Factor out runtime suspend checks from PM operations i2c: Unregister dummy devices last on adapter removal
This commit is contained in:
commit
ad56cbf0fa
|
@ -196,88 +196,60 @@ static int i2c_device_pm_suspend(struct device *dev)
|
|||
{
|
||||
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
||||
|
||||
if (pm) {
|
||||
if (pm_runtime_suspended(dev))
|
||||
return 0;
|
||||
else
|
||||
return pm->suspend ? pm->suspend(dev) : 0;
|
||||
}
|
||||
|
||||
return i2c_legacy_suspend(dev, PMSG_SUSPEND);
|
||||
if (pm)
|
||||
return pm_generic_suspend(dev);
|
||||
else
|
||||
return i2c_legacy_suspend(dev, PMSG_SUSPEND);
|
||||
}
|
||||
|
||||
static int i2c_device_pm_resume(struct device *dev)
|
||||
{
|
||||
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
||||
int ret;
|
||||
|
||||
if (pm)
|
||||
ret = pm->resume ? pm->resume(dev) : 0;
|
||||
return pm_generic_resume(dev);
|
||||
else
|
||||
ret = i2c_legacy_resume(dev);
|
||||
|
||||
return ret;
|
||||
return i2c_legacy_resume(dev);
|
||||
}
|
||||
|
||||
static int i2c_device_pm_freeze(struct device *dev)
|
||||
{
|
||||
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
||||
|
||||
if (pm) {
|
||||
if (pm_runtime_suspended(dev))
|
||||
return 0;
|
||||
else
|
||||
return pm->freeze ? pm->freeze(dev) : 0;
|
||||
}
|
||||
|
||||
return i2c_legacy_suspend(dev, PMSG_FREEZE);
|
||||
if (pm)
|
||||
return pm_generic_freeze(dev);
|
||||
else
|
||||
return i2c_legacy_suspend(dev, PMSG_FREEZE);
|
||||
}
|
||||
|
||||
static int i2c_device_pm_thaw(struct device *dev)
|
||||
{
|
||||
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
||||
|
||||
if (pm) {
|
||||
if (pm_runtime_suspended(dev))
|
||||
return 0;
|
||||
else
|
||||
return pm->thaw ? pm->thaw(dev) : 0;
|
||||
}
|
||||
|
||||
return i2c_legacy_resume(dev);
|
||||
if (pm)
|
||||
return pm_generic_thaw(dev);
|
||||
else
|
||||
return i2c_legacy_resume(dev);
|
||||
}
|
||||
|
||||
static int i2c_device_pm_poweroff(struct device *dev)
|
||||
{
|
||||
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
||||
|
||||
if (pm) {
|
||||
if (pm_runtime_suspended(dev))
|
||||
return 0;
|
||||
else
|
||||
return pm->poweroff ? pm->poweroff(dev) : 0;
|
||||
}
|
||||
|
||||
return i2c_legacy_suspend(dev, PMSG_HIBERNATE);
|
||||
if (pm)
|
||||
return pm_generic_poweroff(dev);
|
||||
else
|
||||
return i2c_legacy_suspend(dev, PMSG_HIBERNATE);
|
||||
}
|
||||
|
||||
static int i2c_device_pm_restore(struct device *dev)
|
||||
{
|
||||
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
|
||||
int ret;
|
||||
|
||||
if (pm)
|
||||
ret = pm->restore ? pm->restore(dev) : 0;
|
||||
return pm_generic_restore(dev);
|
||||
else
|
||||
ret = i2c_legacy_resume(dev);
|
||||
|
||||
if (!ret) {
|
||||
pm_runtime_disable(dev);
|
||||
pm_runtime_set_active(dev);
|
||||
pm_runtime_enable(dev);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return i2c_legacy_resume(dev);
|
||||
}
|
||||
#else /* !CONFIG_PM_SLEEP */
|
||||
#define i2c_device_pm_suspend NULL
|
||||
|
@ -1019,6 +991,14 @@ static int i2c_do_del_adapter(struct i2c_driver *driver,
|
|||
}
|
||||
|
||||
static int __unregister_client(struct device *dev, void *dummy)
|
||||
{
|
||||
struct i2c_client *client = i2c_verify_client(dev);
|
||||
if (client && strcmp(client->name, "dummy"))
|
||||
i2c_unregister_device(client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __unregister_dummy(struct device *dev, void *dummy)
|
||||
{
|
||||
struct i2c_client *client = i2c_verify_client(dev);
|
||||
if (client)
|
||||
|
@ -1075,8 +1055,12 @@ int i2c_del_adapter(struct i2c_adapter *adap)
|
|||
mutex_unlock(&adap->userspace_clients_lock);
|
||||
|
||||
/* Detach any active clients. This can't fail, thus we do not
|
||||
checking the returned value. */
|
||||
* check the returned value. This is a two-pass process, because
|
||||
* we can't remove the dummy devices during the first pass: they
|
||||
* could have been instantiated by real devices wishing to clean
|
||||
* them up properly, so we give them a chance to do that first. */
|
||||
res = device_for_each_child(&adap->dev, NULL, __unregister_client);
|
||||
res = device_for_each_child(&adap->dev, NULL, __unregister_dummy);
|
||||
|
||||
#ifdef CONFIG_I2C_COMPAT
|
||||
class_compat_remove_link(i2c_adapter_compat_class, &adap->dev,
|
||||
|
@ -1140,6 +1124,14 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
|
|||
if (res)
|
||||
return res;
|
||||
|
||||
/* Drivers should switch to dev_pm_ops instead. */
|
||||
if (driver->suspend)
|
||||
pr_warn("i2c-core: driver [%s] using legacy suspend method\n",
|
||||
driver->driver.name);
|
||||
if (driver->resume)
|
||||
pr_warn("i2c-core: driver [%s] using legacy resume method\n",
|
||||
driver->driver.name);
|
||||
|
||||
pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
|
||||
|
||||
INIT_LIST_HEAD(&driver->clients);
|
||||
|
|
Loading…
Reference in New Issue