summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2011-03-20 16:50:52 +0300
committerJean Delvare <khali@endymion.delvare>2011-03-20 16:50:52 +0300
commit7ae31482a8376fb0df3a0c5ff0677a92820c06b7 (patch)
tree4c5c6b7de9c2f3775d41378e380f49918c3a9230
parent0c31f8e5720e1191b4cf46a9b5374fe6b857c53c (diff)
downloadlinux-7ae31482a8376fb0df3a0c5ff0677a92820c06b7.tar.xz
i2c: Export i2c_for_each_dev
Introduce i2c_for_each_dev(), an i2c device iterator with proper locking for use by i2c-dev. This is needed so that we can get rid of the attach_adapter and detach_adapter legacy callback functions. Signed-off-by: Jean Delvare <khali@linux-fr.org>
-rw-r--r--drivers/i2c/i2c-core.c20
-rw-r--r--include/linux/i2c.h2
2 files changed, 16 insertions, 6 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index f7620cada782..b9fa1d0320b4 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1091,6 +1091,18 @@ EXPORT_SYMBOL(i2c_del_adapter);
/* ------------------------------------------------------------------------- */
+int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *))
+{
+ int res;
+
+ mutex_lock(&core_lock);
+ res = bus_for_each_dev(&i2c_bus_type, NULL, data, fn);
+ mutex_unlock(&core_lock);
+
+ return res;
+}
+EXPORT_SYMBOL_GPL(i2c_for_each_dev);
+
static int __process_new_driver(struct device *dev, void *data)
{
if (dev->type != &i2c_adapter_type)
@@ -1134,9 +1146,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
INIT_LIST_HEAD(&driver->clients);
/* Walk the adapters that are already present */
- mutex_lock(&core_lock);
- bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_new_driver);
- mutex_unlock(&core_lock);
+ i2c_for_each_dev(driver, __process_new_driver);
return 0;
}
@@ -1156,9 +1166,7 @@ static int __process_removed_driver(struct device *dev, void *data)
*/
void i2c_del_driver(struct i2c_driver *driver)
{
- mutex_lock(&core_lock);
- bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_removed_driver);
- mutex_unlock(&core_lock);
+ i2c_for_each_dev(driver, __process_removed_driver);
driver_unregister(&driver->driver);
pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 3963a5567472..4df12c7e69d7 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -395,6 +395,8 @@ i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter)
return NULL;
}
+int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *));
+
/* Adapter locking functions, exported for shared pin cases */
void i2c_lock_adapter(struct i2c_adapter *);
void i2c_unlock_adapter(struct i2c_adapter *);