Commit ad56cbf0 authored by Linus Torvalds's avatar Linus Torvalds

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
parents ab0724ff f4e8db31
...@@ -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
...@@ -1019,6 +991,14 @@ static int i2c_do_del_adapter(struct i2c_driver *driver, ...@@ -1019,6 +991,14 @@ static int i2c_do_del_adapter(struct i2c_driver *driver,
} }
static int __unregister_client(struct device *dev, void *dummy) 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); struct i2c_client *client = i2c_verify_client(dev);
if (client) if (client)
...@@ -1075,8 +1055,12 @@ int i2c_del_adapter(struct i2c_adapter *adap) ...@@ -1075,8 +1055,12 @@ int i2c_del_adapter(struct i2c_adapter *adap)
mutex_unlock(&adap->userspace_clients_lock); mutex_unlock(&adap->userspace_clients_lock);
/* Detach any active clients. This can't fail, thus we do not /* 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_client);
res = device_for_each_child(&adap->dev, NULL, __unregister_dummy);
#ifdef CONFIG_I2C_COMPAT #ifdef CONFIG_I2C_COMPAT
class_compat_remove_link(i2c_adapter_compat_class, &adap->dev, 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) ...@@ -1140,6 +1124,14 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
if (res) if (res)
return 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); pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
INIT_LIST_HEAD(&driver->clients); INIT_LIST_HEAD(&driver->clients);
......
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