aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r--drivers/i2c/i2c-core.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index f0bd5bcdf563..9a58994ff7ea 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -348,7 +348,7 @@ EXPORT_SYMBOL(i2c_verify_client);
348 348
349 349
350/* This is a permissive address validity check, I2C address map constraints 350/* This is a permissive address validity check, I2C address map constraints
351 * are purposedly not enforced, except for the general call address. */ 351 * are purposely not enforced, except for the general call address. */
352static int i2c_check_client_addr_validity(const struct i2c_client *client) 352static int i2c_check_client_addr_validity(const struct i2c_client *client)
353{ 353{
354 if (client->flags & I2C_CLIENT_TEN) { 354 if (client->flags & I2C_CLIENT_TEN) {
@@ -537,9 +537,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
537 client->dev.parent = &client->adapter->dev; 537 client->dev.parent = &client->adapter->dev;
538 client->dev.bus = &i2c_bus_type; 538 client->dev.bus = &i2c_bus_type;
539 client->dev.type = &i2c_client_type; 539 client->dev.type = &i2c_client_type;
540#ifdef CONFIG_OF
541 client->dev.of_node = info->of_node; 540 client->dev.of_node = info->of_node;
542#endif
543 541
544 dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap), 542 dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
545 client->addr); 543 client->addr);
@@ -799,6 +797,10 @@ static int i2c_do_add_adapter(struct i2c_driver *driver,
799 797
800 /* Let legacy drivers scan this bus for matching devices */ 798 /* Let legacy drivers scan this bus for matching devices */
801 if (driver->attach_adapter) { 799 if (driver->attach_adapter) {
800 dev_warn(&adap->dev, "%s: attach_adapter method is deprecated\n",
801 driver->driver.name);
802 dev_warn(&adap->dev, "Please use another way to instantiate "
803 "your i2c_client\n");
802 /* We ignore the return code; if it fails, too bad */ 804 /* We ignore the return code; if it fails, too bad */
803 driver->attach_adapter(adap); 805 driver->attach_adapter(adap);
804 } 806 }
@@ -983,6 +985,8 @@ static int i2c_do_del_adapter(struct i2c_driver *driver,
983 985
984 if (!driver->detach_adapter) 986 if (!driver->detach_adapter)
985 return 0; 987 return 0;
988 dev_warn(&adapter->dev, "%s: detach_adapter method is deprecated\n",
989 driver->driver.name);
986 res = driver->detach_adapter(adapter); 990 res = driver->detach_adapter(adapter);
987 if (res) 991 if (res)
988 dev_err(&adapter->dev, "detach_adapter failed (%d) " 992 dev_err(&adapter->dev, "detach_adapter failed (%d) "
@@ -1093,6 +1097,18 @@ EXPORT_SYMBOL(i2c_del_adapter);
1093 1097
1094/* ------------------------------------------------------------------------- */ 1098/* ------------------------------------------------------------------------- */
1095 1099
1100int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *))
1101{
1102 int res;
1103
1104 mutex_lock(&core_lock);
1105 res = bus_for_each_dev(&i2c_bus_type, NULL, data, fn);
1106 mutex_unlock(&core_lock);
1107
1108 return res;
1109}
1110EXPORT_SYMBOL_GPL(i2c_for_each_dev);
1111
1096static int __process_new_driver(struct device *dev, void *data) 1112static int __process_new_driver(struct device *dev, void *data)
1097{ 1113{
1098 if (dev->type != &i2c_adapter_type) 1114 if (dev->type != &i2c_adapter_type)
@@ -1136,9 +1152,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
1136 1152
1137 INIT_LIST_HEAD(&driver->clients); 1153 INIT_LIST_HEAD(&driver->clients);
1138 /* Walk the adapters that are already present */ 1154 /* Walk the adapters that are already present */
1139 mutex_lock(&core_lock); 1155 i2c_for_each_dev(driver, __process_new_driver);
1140 bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_new_driver);
1141 mutex_unlock(&core_lock);
1142 1156
1143 return 0; 1157 return 0;
1144} 1158}
@@ -1158,9 +1172,7 @@ static int __process_removed_driver(struct device *dev, void *data)
1158 */ 1172 */
1159void i2c_del_driver(struct i2c_driver *driver) 1173void i2c_del_driver(struct i2c_driver *driver)
1160{ 1174{
1161 mutex_lock(&core_lock); 1175 i2c_for_each_dev(driver, __process_removed_driver);
1162 bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_removed_driver);
1163 mutex_unlock(&core_lock);
1164 1176
1165 driver_unregister(&driver->driver); 1177 driver_unregister(&driver->driver);
1166 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); 1178 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
@@ -1583,12 +1595,12 @@ i2c_new_probed_device(struct i2c_adapter *adap,
1583} 1595}
1584EXPORT_SYMBOL_GPL(i2c_new_probed_device); 1596EXPORT_SYMBOL_GPL(i2c_new_probed_device);
1585 1597
1586struct i2c_adapter *i2c_get_adapter(int id) 1598struct i2c_adapter *i2c_get_adapter(int nr)
1587{ 1599{
1588 struct i2c_adapter *adapter; 1600 struct i2c_adapter *adapter;
1589 1601
1590 mutex_lock(&core_lock); 1602 mutex_lock(&core_lock);
1591 adapter = idr_find(&i2c_adapter_idr, id); 1603 adapter = idr_find(&i2c_adapter_idr, nr);
1592 if (adapter && !try_module_get(adapter->owner)) 1604 if (adapter && !try_module_get(adapter->owner))
1593 adapter = NULL; 1605 adapter = NULL;
1594 1606