diff options
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/i2c-core.c | 100 |
1 files changed, 41 insertions, 59 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index d48438908e1e..06c428b5822e 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -43,7 +43,7 @@ static DEFINE_IDR(i2c_adapter_idr); | |||
43 | 43 | ||
44 | #define is_newstyle_driver(d) ((d)->probe || (d)->remove || (d)->detect) | 44 | #define is_newstyle_driver(d) ((d)->probe || (d)->remove || (d)->detect) |
45 | 45 | ||
46 | static int i2c_attach_client(struct i2c_client *client); | 46 | static int i2c_check_addr(struct i2c_adapter *adapter, int addr); |
47 | static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); | 47 | static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); |
48 | 48 | ||
49 | /* ------------------------------------------------------------------------- */ | 49 | /* ------------------------------------------------------------------------- */ |
@@ -237,15 +237,17 @@ EXPORT_SYMBOL(i2c_verify_client); | |||
237 | 237 | ||
238 | 238 | ||
239 | /** | 239 | /** |
240 | * i2c_new_device - instantiate an i2c device for use with a new style driver | 240 | * i2c_new_device - instantiate an i2c device |
241 | * @adap: the adapter managing the device | 241 | * @adap: the adapter managing the device |
242 | * @info: describes one I2C device; bus_num is ignored | 242 | * @info: describes one I2C device; bus_num is ignored |
243 | * Context: can sleep | 243 | * Context: can sleep |
244 | * | 244 | * |
245 | * Create a device to work with a new style i2c driver, where binding is | 245 | * Create an i2c device. Binding is handled through driver model |
246 | * handled through driver model probe()/remove() methods. This call is not | 246 | * probe()/remove() methods. A driver may be bound to this device when we |
247 | * appropriate for use by mainboad initialization logic, which usually runs | 247 | * return from this function, or any later moment (e.g. maybe hotplugging will |
248 | * during an arch_initcall() long before any i2c_adapter could exist. | 248 | * load the driver module). This call is not appropriate for use by mainboard |
249 | * initialization logic, which usually runs during an arch_initcall() long | ||
250 | * before any i2c_adapter could exist. | ||
249 | * | 251 | * |
250 | * This returns the new i2c client, which may be saved for later use with | 252 | * This returns the new i2c client, which may be saved for later use with |
251 | * i2c_unregister_device(); or NULL to indicate an error. | 253 | * i2c_unregister_device(); or NULL to indicate an error. |
@@ -273,17 +275,40 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) | |||
273 | 275 | ||
274 | strlcpy(client->name, info->type, sizeof(client->name)); | 276 | strlcpy(client->name, info->type, sizeof(client->name)); |
275 | 277 | ||
276 | /* a new style driver may be bound to this device when we | 278 | /* Check for address business */ |
277 | * return from this function, or any later moment (e.g. maybe | 279 | status = i2c_check_addr(adap, client->addr); |
278 | * hotplugging will load the driver module). and the device | 280 | if (status) |
279 | * refcount model is the standard driver model one. | 281 | goto out_err; |
280 | */ | 282 | |
281 | status = i2c_attach_client(client); | 283 | client->dev.parent = &client->adapter->dev; |
282 | if (status < 0) { | 284 | client->dev.bus = &i2c_bus_type; |
283 | kfree(client); | 285 | |
284 | client = NULL; | 286 | if (client->driver && !is_newstyle_driver(client->driver)) { |
285 | } | 287 | client->dev.release = i2c_client_release; |
288 | dev_set_uevent_suppress(&client->dev, 1); | ||
289 | } else | ||
290 | client->dev.release = i2c_client_dev_release; | ||
291 | |||
292 | dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap), | ||
293 | client->addr); | ||
294 | status = device_register(&client->dev); | ||
295 | if (status) | ||
296 | goto out_err; | ||
297 | |||
298 | mutex_lock(&adap->clist_lock); | ||
299 | list_add_tail(&client->list, &adap->clients); | ||
300 | mutex_unlock(&adap->clist_lock); | ||
301 | |||
302 | dev_dbg(&adap->dev, "client [%s] registered with bus id %s\n", | ||
303 | client->name, dev_name(&client->dev)); | ||
304 | |||
286 | return client; | 305 | return client; |
306 | |||
307 | out_err: | ||
308 | dev_err(&adap->dev, "Failed to register i2c client %s at 0x%02x " | ||
309 | "(%d)\n", client->name, client->addr, status); | ||
310 | kfree(client); | ||
311 | return NULL; | ||
287 | } | 312 | } |
288 | EXPORT_SYMBOL_GPL(i2c_new_device); | 313 | EXPORT_SYMBOL_GPL(i2c_new_device); |
289 | 314 | ||
@@ -760,49 +785,6 @@ static int i2c_check_addr(struct i2c_adapter *adapter, int addr) | |||
760 | return device_for_each_child(&adapter->dev, &addr, __i2c_check_addr); | 785 | return device_for_each_child(&adapter->dev, &addr, __i2c_check_addr); |
761 | } | 786 | } |
762 | 787 | ||
763 | static int i2c_attach_client(struct i2c_client *client) | ||
764 | { | ||
765 | struct i2c_adapter *adapter = client->adapter; | ||
766 | int res; | ||
767 | |||
768 | /* Check for address business */ | ||
769 | res = i2c_check_addr(adapter, client->addr); | ||
770 | if (res) | ||
771 | return res; | ||
772 | |||
773 | client->dev.parent = &client->adapter->dev; | ||
774 | client->dev.bus = &i2c_bus_type; | ||
775 | |||
776 | if (client->driver) | ||
777 | client->dev.driver = &client->driver->driver; | ||
778 | |||
779 | if (client->driver && !is_newstyle_driver(client->driver)) { | ||
780 | client->dev.release = i2c_client_release; | ||
781 | dev_set_uevent_suppress(&client->dev, 1); | ||
782 | } else | ||
783 | client->dev.release = i2c_client_dev_release; | ||
784 | |||
785 | dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adapter), | ||
786 | client->addr); | ||
787 | res = device_register(&client->dev); | ||
788 | if (res) | ||
789 | goto out_err; | ||
790 | |||
791 | mutex_lock(&adapter->clist_lock); | ||
792 | list_add_tail(&client->list, &adapter->clients); | ||
793 | mutex_unlock(&adapter->clist_lock); | ||
794 | |||
795 | dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", | ||
796 | client->name, dev_name(&client->dev)); | ||
797 | |||
798 | return 0; | ||
799 | |||
800 | out_err: | ||
801 | dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x " | ||
802 | "(%d)\n", client->name, client->addr, res); | ||
803 | return res; | ||
804 | } | ||
805 | |||
806 | /** | 788 | /** |
807 | * i2c_use_client - increments the reference count of the i2c client structure | 789 | * i2c_use_client - increments the reference count of the i2c client structure |
808 | * @client: the client being referenced | 790 | * @client: the client being referenced |