aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2011-03-20 09:50:52 -0400
committerJean Delvare <khali@endymion.delvare>2011-03-20 09:50:52 -0400
commit7ae31482a8376fb0df3a0c5ff0677a92820c06b7 (patch)
tree4c5c6b7de9c2f3775d41378e380f49918c3a9230 /drivers/i2c
parent0c31f8e5720e1191b4cf46a9b5374fe6b857c53c (diff)
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>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/i2c-core.c20
1 files changed, 14 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);
1091 1091
1092/* ------------------------------------------------------------------------- */ 1092/* ------------------------------------------------------------------------- */
1093 1093
1094int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *))
1095{
1096 int res;
1097
1098 mutex_lock(&core_lock);
1099 res = bus_for_each_dev(&i2c_bus_type, NULL, data, fn);
1100 mutex_unlock(&core_lock);
1101
1102 return res;
1103}
1104EXPORT_SYMBOL_GPL(i2c_for_each_dev);
1105
1094static int __process_new_driver(struct device *dev, void *data) 1106static int __process_new_driver(struct device *dev, void *data)
1095{ 1107{
1096 if (dev->type != &i2c_adapter_type) 1108 if (dev->type != &i2c_adapter_type)
@@ -1134,9 +1146,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
1134 1146
1135 INIT_LIST_HEAD(&driver->clients); 1147 INIT_LIST_HEAD(&driver->clients);
1136 /* Walk the adapters that are already present */ 1148 /* Walk the adapters that are already present */
1137 mutex_lock(&core_lock); 1149 i2c_for_each_dev(driver, __process_new_driver);
1138 bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_new_driver);
1139 mutex_unlock(&core_lock);
1140 1150
1141 return 0; 1151 return 0;
1142} 1152}
@@ -1156,9 +1166,7 @@ static int __process_removed_driver(struct device *dev, void *data)
1156 */ 1166 */
1157void i2c_del_driver(struct i2c_driver *driver) 1167void i2c_del_driver(struct i2c_driver *driver)
1158{ 1168{
1159 mutex_lock(&core_lock); 1169 i2c_for_each_dev(driver, __process_removed_driver);
1160 bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_removed_driver);
1161 mutex_unlock(&core_lock);
1162 1170
1163 driver_unregister(&driver->driver); 1171 driver_unregister(&driver->driver);
1164 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); 1172 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);