diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-19 20:45:51 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-19 20:45:51 -0400 |
commit | 5c6fb0059cec9a3c0f6d88a0ddf3d62ad323cd57 (patch) | |
tree | 49b4ceaeb5686fca4546315155d04633adf25b3c | |
parent | 31583d6acf940d2951bc8716557b06d9de5a0c4b (diff) | |
parent | c70366732f67dbdb32f7fe9c6aa59299b76feca6 (diff) |
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: New macro to initialize i2c address lists on the fly
i2c: Don't advertise i2c functions when not available
i2c: Use rwsem instead of mutex for board info
i2c: Add a sysfs interface to instantiate devices
i2c: Limit core locking to the necessary sections
i2c: Kill the redundant client list
i2c: Kill is_newstyle_driver
i2c: Merge i2c_attach_client into i2c_new_device
i2c: Drop i2c_probe function
i2c: Get rid of the legacy binding model
i2c: Kill client_register and client_unregister methods
-rw-r--r-- | Documentation/feature-removal-schedule.txt | 10 | ||||
-rw-r--r-- | Documentation/i2c/instantiating-devices | 44 | ||||
-rw-r--r-- | Documentation/i2c/writing-clients | 16 | ||||
-rw-r--r-- | drivers/i2c/i2c-boardinfo.c | 7 | ||||
-rw-r--r-- | drivers/i2c/i2c-core.c | 557 | ||||
-rw-r--r-- | drivers/i2c/i2c-core.h | 4 | ||||
-rw-r--r-- | include/linux/i2c.h | 72 |
7 files changed, 275 insertions, 435 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt index 8d07ed31207e..f8cd450be9aa 100644 --- a/Documentation/feature-removal-schedule.txt +++ b/Documentation/feature-removal-schedule.txt | |||
@@ -368,16 +368,6 @@ Who: Krzysztof Piotr Oledzki <ole@ans.pl> | |||
368 | 368 | ||
369 | --------------------------- | 369 | --------------------------- |
370 | 370 | ||
371 | What: i2c_attach_client(), i2c_detach_client(), i2c_driver->detach_client(), | ||
372 | i2c_adapter->client_register(), i2c_adapter->client_unregister | ||
373 | When: 2.6.30 | ||
374 | Check: i2c_attach_client i2c_detach_client | ||
375 | Why: Deprecated by the new (standard) device driver binding model. Use | ||
376 | i2c_driver->probe() and ->remove() instead. | ||
377 | Who: Jean Delvare <khali@linux-fr.org> | ||
378 | |||
379 | --------------------------- | ||
380 | |||
381 | What: fscher and fscpos drivers | 371 | What: fscher and fscpos drivers |
382 | When: June 2009 | 372 | When: June 2009 |
383 | Why: Deprecated by the new fschmd driver. | 373 | Why: Deprecated by the new fschmd driver. |
diff --git a/Documentation/i2c/instantiating-devices b/Documentation/i2c/instantiating-devices index b55ce57a84db..c740b7b41088 100644 --- a/Documentation/i2c/instantiating-devices +++ b/Documentation/i2c/instantiating-devices | |||
@@ -165,3 +165,47 @@ was done there. Two significant differences are: | |||
165 | Once again, method 3 should be avoided wherever possible. Explicit device | 165 | Once again, method 3 should be avoided wherever possible. Explicit device |
166 | instantiation (methods 1 and 2) is much preferred for it is safer and | 166 | instantiation (methods 1 and 2) is much preferred for it is safer and |
167 | faster. | 167 | faster. |
168 | |||
169 | |||
170 | Method 4: Instantiate from user-space | ||
171 | ------------------------------------- | ||
172 | |||
173 | In general, the kernel should know which I2C devices are connected and | ||
174 | what addresses they live at. However, in certain cases, it does not, so a | ||
175 | sysfs interface was added to let the user provide the information. This | ||
176 | interface is made of 2 attribute files which are created in every I2C bus | ||
177 | directory: new_device and delete_device. Both files are write only and you | ||
178 | must write the right parameters to them in order to properly instantiate, | ||
179 | respectively delete, an I2C device. | ||
180 | |||
181 | File new_device takes 2 parameters: the name of the I2C device (a string) | ||
182 | and the address of the I2C device (a number, typically expressed in | ||
183 | hexadecimal starting with 0x, but can also be expressed in decimal.) | ||
184 | |||
185 | File delete_device takes a single parameter: the address of the I2C | ||
186 | device. As no two devices can live at the same address on a given I2C | ||
187 | segment, the address is sufficient to uniquely identify the device to be | ||
188 | deleted. | ||
189 | |||
190 | Example: | ||
191 | # echo eeprom 0x50 > /sys/class/i2c-adapter/i2c-3/new_device | ||
192 | |||
193 | While this interface should only be used when in-kernel device declaration | ||
194 | can't be done, there is a variety of cases where it can be helpful: | ||
195 | * The I2C driver usually detects devices (method 3 above) but the bus | ||
196 | segment your device lives on doesn't have the proper class bit set and | ||
197 | thus detection doesn't trigger. | ||
198 | * The I2C driver usually detects devices, but your device lives at an | ||
199 | unexpected address. | ||
200 | * The I2C driver usually detects devices, but your device is not detected, | ||
201 | either because the detection routine is too strict, or because your | ||
202 | device is not officially supported yet but you know it is compatible. | ||
203 | * You are developing a driver on a test board, where you soldered the I2C | ||
204 | device yourself. | ||
205 | |||
206 | This interface is a replacement for the force_* module parameters some I2C | ||
207 | drivers implement. Being implemented in i2c-core rather than in each | ||
208 | device driver individually, it is much more efficient, and also has the | ||
209 | advantage that you do not have to reload the driver to change a setting. | ||
210 | You can also instantiate the device before the driver is loaded or even | ||
211 | available, and you don't need to know what driver the device needs. | ||
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients index c1a06f989cf7..7860aafb483d 100644 --- a/Documentation/i2c/writing-clients +++ b/Documentation/i2c/writing-clients | |||
@@ -126,19 +126,9 @@ different) configuration information, as do drivers handling chip variants | |||
126 | that can't be distinguished by protocol probing, or which need some board | 126 | that can't be distinguished by protocol probing, or which need some board |
127 | specific information to operate correctly. | 127 | specific information to operate correctly. |
128 | 128 | ||
129 | Accordingly, the I2C stack now has two models for associating I2C devices | ||
130 | with their drivers: the original "legacy" model, and a newer one that's | ||
131 | fully compatible with the Linux 2.6 driver model. These models do not mix, | ||
132 | since the "legacy" model requires drivers to create "i2c_client" device | ||
133 | objects after SMBus style probing, while the Linux driver model expects | ||
134 | drivers to be given such device objects in their probe() routines. | ||
135 | 129 | ||
136 | The legacy model is deprecated now and will soon be removed, so we no | 130 | Device/Driver Binding |
137 | longer document it here. | 131 | --------------------- |
138 | |||
139 | |||
140 | Standard Driver Model Binding ("New Style") | ||
141 | ------------------------------------------- | ||
142 | 132 | ||
143 | System infrastructure, typically board-specific initialization code or | 133 | System infrastructure, typically board-specific initialization code or |
144 | boot firmware, reports what I2C devices exist. For example, there may be | 134 | boot firmware, reports what I2C devices exist. For example, there may be |
@@ -201,7 +191,7 @@ a given I2C bus. This is for example the case of hardware monitoring | |||
201 | devices on a PC's SMBus. In that case, you may want to let your driver | 191 | devices on a PC's SMBus. In that case, you may want to let your driver |
202 | detect supported devices automatically. This is how the legacy model | 192 | detect supported devices automatically. This is how the legacy model |
203 | was working, and is now available as an extension to the standard | 193 | was working, and is now available as an extension to the standard |
204 | driver model (so that we can finally get rid of the legacy model.) | 194 | driver model. |
205 | 195 | ||
206 | You simply have to define a detect callback which will attempt to | 196 | You simply have to define a detect callback which will attempt to |
207 | identify supported devices (returning 0 for supported ones and -ENODEV | 197 | identify supported devices (returning 0 for supported ones and -ENODEV |
diff --git a/drivers/i2c/i2c-boardinfo.c b/drivers/i2c/i2c-boardinfo.c index ffb35f09df03..a26a34a06641 100644 --- a/drivers/i2c/i2c-boardinfo.c +++ b/drivers/i2c/i2c-boardinfo.c | |||
@@ -18,6 +18,7 @@ | |||
18 | 18 | ||
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/i2c.h> | 20 | #include <linux/i2c.h> |
21 | #include <linux/rwsem.h> | ||
21 | 22 | ||
22 | #include "i2c-core.h" | 23 | #include "i2c-core.h" |
23 | 24 | ||
@@ -25,7 +26,7 @@ | |||
25 | /* These symbols are exported ONLY FOR the i2c core. | 26 | /* These symbols are exported ONLY FOR the i2c core. |
26 | * No other users will be supported. | 27 | * No other users will be supported. |
27 | */ | 28 | */ |
28 | DEFINE_MUTEX(__i2c_board_lock); | 29 | DECLARE_RWSEM(__i2c_board_lock); |
29 | EXPORT_SYMBOL_GPL(__i2c_board_lock); | 30 | EXPORT_SYMBOL_GPL(__i2c_board_lock); |
30 | 31 | ||
31 | LIST_HEAD(__i2c_board_list); | 32 | LIST_HEAD(__i2c_board_list); |
@@ -63,7 +64,7 @@ i2c_register_board_info(int busnum, | |||
63 | { | 64 | { |
64 | int status; | 65 | int status; |
65 | 66 | ||
66 | mutex_lock(&__i2c_board_lock); | 67 | down_write(&__i2c_board_lock); |
67 | 68 | ||
68 | /* dynamic bus numbers will be assigned after the last static one */ | 69 | /* dynamic bus numbers will be assigned after the last static one */ |
69 | if (busnum >= __i2c_first_dynamic_bus_num) | 70 | if (busnum >= __i2c_first_dynamic_bus_num) |
@@ -84,7 +85,7 @@ i2c_register_board_info(int busnum, | |||
84 | list_add_tail(&devinfo->list, &__i2c_board_list); | 85 | list_add_tail(&devinfo->list, &__i2c_board_list); |
85 | } | 86 | } |
86 | 87 | ||
87 | mutex_unlock(&__i2c_board_lock); | 88 | up_write(&__i2c_board_lock); |
88 | 89 | ||
89 | return status; | 90 | return status; |
90 | } | 91 | } |
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 5ed622ee65c3..0e45c296d3d2 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -33,16 +33,20 @@ | |||
33 | #include <linux/completion.h> | 33 | #include <linux/completion.h> |
34 | #include <linux/hardirq.h> | 34 | #include <linux/hardirq.h> |
35 | #include <linux/irqflags.h> | 35 | #include <linux/irqflags.h> |
36 | #include <linux/rwsem.h> | ||
36 | #include <asm/uaccess.h> | 37 | #include <asm/uaccess.h> |
37 | 38 | ||
38 | #include "i2c-core.h" | 39 | #include "i2c-core.h" |
39 | 40 | ||
40 | 41 | ||
42 | /* core_lock protects i2c_adapter_idr, userspace_devices, and guarantees | ||
43 | that device detection, deletion of detected devices, and attach_adapter | ||
44 | and detach_adapter calls are serialized */ | ||
41 | static DEFINE_MUTEX(core_lock); | 45 | static DEFINE_MUTEX(core_lock); |
42 | static DEFINE_IDR(i2c_adapter_idr); | 46 | static DEFINE_IDR(i2c_adapter_idr); |
47 | static LIST_HEAD(userspace_devices); | ||
43 | 48 | ||
44 | #define is_newstyle_driver(d) ((d)->probe || (d)->remove || (d)->detect) | 49 | static int i2c_check_addr(struct i2c_adapter *adapter, int addr); |
45 | |||
46 | static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); | 50 | static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); |
47 | 51 | ||
48 | /* ------------------------------------------------------------------------- */ | 52 | /* ------------------------------------------------------------------------- */ |
@@ -63,12 +67,6 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv) | |||
63 | struct i2c_client *client = to_i2c_client(dev); | 67 | struct i2c_client *client = to_i2c_client(dev); |
64 | struct i2c_driver *driver = to_i2c_driver(drv); | 68 | struct i2c_driver *driver = to_i2c_driver(drv); |
65 | 69 | ||
66 | /* make legacy i2c drivers bypass driver model probing entirely; | ||
67 | * such drivers scan each i2c adapter/bus themselves. | ||
68 | */ | ||
69 | if (!is_newstyle_driver(driver)) | ||
70 | return 0; | ||
71 | |||
72 | /* match on an id table if there is one */ | 70 | /* match on an id table if there is one */ |
73 | if (driver->id_table) | 71 | if (driver->id_table) |
74 | return i2c_match_id(driver->id_table, client) != NULL; | 72 | return i2c_match_id(driver->id_table, client) != NULL; |
@@ -83,10 +81,6 @@ static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
83 | { | 81 | { |
84 | struct i2c_client *client = to_i2c_client(dev); | 82 | struct i2c_client *client = to_i2c_client(dev); |
85 | 83 | ||
86 | /* by definition, legacy drivers can't hotplug */ | ||
87 | if (dev->driver) | ||
88 | return 0; | ||
89 | |||
90 | if (add_uevent_var(env, "MODALIAS=%s%s", | 84 | if (add_uevent_var(env, "MODALIAS=%s%s", |
91 | I2C_MODULE_PREFIX, client->name)) | 85 | I2C_MODULE_PREFIX, client->name)) |
92 | return -ENOMEM; | 86 | return -ENOMEM; |
@@ -175,12 +169,6 @@ static int i2c_device_resume(struct device *dev) | |||
175 | return driver->resume(to_i2c_client(dev)); | 169 | return driver->resume(to_i2c_client(dev)); |
176 | } | 170 | } |
177 | 171 | ||
178 | static void i2c_client_release(struct device *dev) | ||
179 | { | ||
180 | struct i2c_client *client = to_i2c_client(dev); | ||
181 | complete(&client->released); | ||
182 | } | ||
183 | |||
184 | static void i2c_client_dev_release(struct device *dev) | 172 | static void i2c_client_dev_release(struct device *dev) |
185 | { | 173 | { |
186 | kfree(to_i2c_client(dev)); | 174 | kfree(to_i2c_client(dev)); |
@@ -240,15 +228,17 @@ EXPORT_SYMBOL(i2c_verify_client); | |||
240 | 228 | ||
241 | 229 | ||
242 | /** | 230 | /** |
243 | * i2c_new_device - instantiate an i2c device for use with a new style driver | 231 | * i2c_new_device - instantiate an i2c device |
244 | * @adap: the adapter managing the device | 232 | * @adap: the adapter managing the device |
245 | * @info: describes one I2C device; bus_num is ignored | 233 | * @info: describes one I2C device; bus_num is ignored |
246 | * Context: can sleep | 234 | * Context: can sleep |
247 | * | 235 | * |
248 | * Create a device to work with a new style i2c driver, where binding is | 236 | * Create an i2c device. Binding is handled through driver model |
249 | * handled through driver model probe()/remove() methods. This call is not | 237 | * probe()/remove() methods. A driver may be bound to this device when we |
250 | * appropriate for use by mainboad initialization logic, which usually runs | 238 | * return from this function, or any later moment (e.g. maybe hotplugging will |
251 | * during an arch_initcall() long before any i2c_adapter could exist. | 239 | * load the driver module). This call is not appropriate for use by mainboard |
240 | * initialization logic, which usually runs during an arch_initcall() long | ||
241 | * before any i2c_adapter could exist. | ||
252 | * | 242 | * |
253 | * This returns the new i2c client, which may be saved for later use with | 243 | * This returns the new i2c client, which may be saved for later use with |
254 | * i2c_unregister_device(); or NULL to indicate an error. | 244 | * i2c_unregister_device(); or NULL to indicate an error. |
@@ -276,17 +266,31 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) | |||
276 | 266 | ||
277 | strlcpy(client->name, info->type, sizeof(client->name)); | 267 | strlcpy(client->name, info->type, sizeof(client->name)); |
278 | 268 | ||
279 | /* a new style driver may be bound to this device when we | 269 | /* Check for address business */ |
280 | * return from this function, or any later moment (e.g. maybe | 270 | status = i2c_check_addr(adap, client->addr); |
281 | * hotplugging will load the driver module). and the device | 271 | if (status) |
282 | * refcount model is the standard driver model one. | 272 | goto out_err; |
283 | */ | 273 | |
284 | status = i2c_attach_client(client); | 274 | client->dev.parent = &client->adapter->dev; |
285 | if (status < 0) { | 275 | client->dev.bus = &i2c_bus_type; |
286 | kfree(client); | 276 | client->dev.release = i2c_client_dev_release; |
287 | client = NULL; | 277 | |
288 | } | 278 | dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap), |
279 | client->addr); | ||
280 | status = device_register(&client->dev); | ||
281 | if (status) | ||
282 | goto out_err; | ||
283 | |||
284 | dev_dbg(&adap->dev, "client [%s] registered with bus id %s\n", | ||
285 | client->name, dev_name(&client->dev)); | ||
286 | |||
289 | return client; | 287 | return client; |
288 | |||
289 | out_err: | ||
290 | dev_err(&adap->dev, "Failed to register i2c client %s at 0x%02x " | ||
291 | "(%d)\n", client->name, client->addr, status); | ||
292 | kfree(client); | ||
293 | return NULL; | ||
290 | } | 294 | } |
291 | EXPORT_SYMBOL_GPL(i2c_new_device); | 295 | EXPORT_SYMBOL_GPL(i2c_new_device); |
292 | 296 | ||
@@ -298,28 +302,6 @@ EXPORT_SYMBOL_GPL(i2c_new_device); | |||
298 | */ | 302 | */ |
299 | void i2c_unregister_device(struct i2c_client *client) | 303 | void i2c_unregister_device(struct i2c_client *client) |
300 | { | 304 | { |
301 | struct i2c_adapter *adapter = client->adapter; | ||
302 | struct i2c_driver *driver = client->driver; | ||
303 | |||
304 | if (driver && !is_newstyle_driver(driver)) { | ||
305 | dev_err(&client->dev, "can't unregister devices " | ||
306 | "with legacy drivers\n"); | ||
307 | WARN_ON(1); | ||
308 | return; | ||
309 | } | ||
310 | |||
311 | if (adapter->client_unregister) { | ||
312 | if (adapter->client_unregister(client)) { | ||
313 | dev_warn(&client->dev, | ||
314 | "client_unregister [%s] failed\n", | ||
315 | client->name); | ||
316 | } | ||
317 | } | ||
318 | |||
319 | mutex_lock(&adapter->clist_lock); | ||
320 | list_del(&client->list); | ||
321 | mutex_unlock(&adapter->clist_lock); | ||
322 | |||
323 | device_unregister(&client->dev); | 305 | device_unregister(&client->dev); |
324 | } | 306 | } |
325 | EXPORT_SYMBOL_GPL(i2c_unregister_device); | 307 | EXPORT_SYMBOL_GPL(i2c_unregister_device); |
@@ -393,8 +375,128 @@ show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) | |||
393 | return sprintf(buf, "%s\n", adap->name); | 375 | return sprintf(buf, "%s\n", adap->name); |
394 | } | 376 | } |
395 | 377 | ||
378 | /* | ||
379 | * Let users instantiate I2C devices through sysfs. This can be used when | ||
380 | * platform initialization code doesn't contain the proper data for | ||
381 | * whatever reason. Also useful for drivers that do device detection and | ||
382 | * detection fails, either because the device uses an unexpected address, | ||
383 | * or this is a compatible device with different ID register values. | ||
384 | * | ||
385 | * Parameter checking may look overzealous, but we really don't want | ||
386 | * the user to provide incorrect parameters. | ||
387 | */ | ||
388 | static ssize_t | ||
389 | i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr, | ||
390 | const char *buf, size_t count) | ||
391 | { | ||
392 | struct i2c_adapter *adap = to_i2c_adapter(dev); | ||
393 | struct i2c_board_info info; | ||
394 | struct i2c_client *client; | ||
395 | char *blank, end; | ||
396 | int res; | ||
397 | |||
398 | dev_warn(dev, "The new_device interface is still experimental " | ||
399 | "and may change in a near future\n"); | ||
400 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
401 | |||
402 | blank = strchr(buf, ' '); | ||
403 | if (!blank) { | ||
404 | dev_err(dev, "%s: Missing parameters\n", "new_device"); | ||
405 | return -EINVAL; | ||
406 | } | ||
407 | if (blank - buf > I2C_NAME_SIZE - 1) { | ||
408 | dev_err(dev, "%s: Invalid device name\n", "new_device"); | ||
409 | return -EINVAL; | ||
410 | } | ||
411 | memcpy(info.type, buf, blank - buf); | ||
412 | |||
413 | /* Parse remaining parameters, reject extra parameters */ | ||
414 | res = sscanf(++blank, "%hi%c", &info.addr, &end); | ||
415 | if (res < 1) { | ||
416 | dev_err(dev, "%s: Can't parse I2C address\n", "new_device"); | ||
417 | return -EINVAL; | ||
418 | } | ||
419 | if (res > 1 && end != '\n') { | ||
420 | dev_err(dev, "%s: Extra parameters\n", "new_device"); | ||
421 | return -EINVAL; | ||
422 | } | ||
423 | |||
424 | if (info.addr < 0x03 || info.addr > 0x77) { | ||
425 | dev_err(dev, "%s: Invalid I2C address 0x%hx\n", "new_device", | ||
426 | info.addr); | ||
427 | return -EINVAL; | ||
428 | } | ||
429 | |||
430 | client = i2c_new_device(adap, &info); | ||
431 | if (!client) | ||
432 | return -EEXIST; | ||
433 | |||
434 | /* Keep track of the added device */ | ||
435 | mutex_lock(&core_lock); | ||
436 | list_add_tail(&client->detected, &userspace_devices); | ||
437 | mutex_unlock(&core_lock); | ||
438 | dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", | ||
439 | info.type, info.addr); | ||
440 | |||
441 | return count; | ||
442 | } | ||
443 | |||
444 | /* | ||
445 | * And of course let the users delete the devices they instantiated, if | ||
446 | * they got it wrong. This interface can only be used to delete devices | ||
447 | * instantiated by i2c_sysfs_new_device above. This guarantees that we | ||
448 | * don't delete devices to which some kernel code still has references. | ||
449 | * | ||
450 | * Parameter checking may look overzealous, but we really don't want | ||
451 | * the user to delete the wrong device. | ||
452 | */ | ||
453 | static ssize_t | ||
454 | i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr, | ||
455 | const char *buf, size_t count) | ||
456 | { | ||
457 | struct i2c_adapter *adap = to_i2c_adapter(dev); | ||
458 | struct i2c_client *client, *next; | ||
459 | unsigned short addr; | ||
460 | char end; | ||
461 | int res; | ||
462 | |||
463 | /* Parse parameters, reject extra parameters */ | ||
464 | res = sscanf(buf, "%hi%c", &addr, &end); | ||
465 | if (res < 1) { | ||
466 | dev_err(dev, "%s: Can't parse I2C address\n", "delete_device"); | ||
467 | return -EINVAL; | ||
468 | } | ||
469 | if (res > 1 && end != '\n') { | ||
470 | dev_err(dev, "%s: Extra parameters\n", "delete_device"); | ||
471 | return -EINVAL; | ||
472 | } | ||
473 | |||
474 | /* Make sure the device was added through sysfs */ | ||
475 | res = -ENOENT; | ||
476 | mutex_lock(&core_lock); | ||
477 | list_for_each_entry_safe(client, next, &userspace_devices, detected) { | ||
478 | if (client->addr == addr && client->adapter == adap) { | ||
479 | dev_info(dev, "%s: Deleting device %s at 0x%02hx\n", | ||
480 | "delete_device", client->name, client->addr); | ||
481 | |||
482 | list_del(&client->detected); | ||
483 | i2c_unregister_device(client); | ||
484 | res = count; | ||
485 | break; | ||
486 | } | ||
487 | } | ||
488 | mutex_unlock(&core_lock); | ||
489 | |||
490 | if (res < 0) | ||
491 | dev_err(dev, "%s: Can't find device in list\n", | ||
492 | "delete_device"); | ||
493 | return res; | ||
494 | } | ||
495 | |||
396 | static struct device_attribute i2c_adapter_attrs[] = { | 496 | static struct device_attribute i2c_adapter_attrs[] = { |
397 | __ATTR(name, S_IRUGO, show_adapter_name, NULL), | 497 | __ATTR(name, S_IRUGO, show_adapter_name, NULL), |
498 | __ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device), | ||
499 | __ATTR(delete_device, S_IWUSR, NULL, i2c_sysfs_delete_device), | ||
398 | { }, | 500 | { }, |
399 | }; | 501 | }; |
400 | 502 | ||
@@ -408,7 +510,7 @@ static void i2c_scan_static_board_info(struct i2c_adapter *adapter) | |||
408 | { | 510 | { |
409 | struct i2c_devinfo *devinfo; | 511 | struct i2c_devinfo *devinfo; |
410 | 512 | ||
411 | mutex_lock(&__i2c_board_lock); | 513 | down_read(&__i2c_board_lock); |
412 | list_for_each_entry(devinfo, &__i2c_board_list, list) { | 514 | list_for_each_entry(devinfo, &__i2c_board_list, list) { |
413 | if (devinfo->busnum == adapter->nr | 515 | if (devinfo->busnum == adapter->nr |
414 | && !i2c_new_device(adapter, | 516 | && !i2c_new_device(adapter, |
@@ -417,7 +519,7 @@ static void i2c_scan_static_board_info(struct i2c_adapter *adapter) | |||
417 | "Can't create device at 0x%02x\n", | 519 | "Can't create device at 0x%02x\n", |
418 | devinfo->board_info.addr); | 520 | devinfo->board_info.addr); |
419 | } | 521 | } |
420 | mutex_unlock(&__i2c_board_lock); | 522 | up_read(&__i2c_board_lock); |
421 | } | 523 | } |
422 | 524 | ||
423 | static int i2c_do_add_adapter(struct device_driver *d, void *data) | 525 | static int i2c_do_add_adapter(struct device_driver *d, void *data) |
@@ -441,14 +543,12 @@ static int i2c_register_adapter(struct i2c_adapter *adap) | |||
441 | int res = 0, dummy; | 543 | int res = 0, dummy; |
442 | 544 | ||
443 | /* Can't register until after driver model init */ | 545 | /* Can't register until after driver model init */ |
444 | if (unlikely(WARN_ON(!i2c_bus_type.p))) | 546 | if (unlikely(WARN_ON(!i2c_bus_type.p))) { |
445 | return -EAGAIN; | 547 | res = -EAGAIN; |
548 | goto out_list; | ||
549 | } | ||
446 | 550 | ||
447 | mutex_init(&adap->bus_lock); | 551 | mutex_init(&adap->bus_lock); |
448 | mutex_init(&adap->clist_lock); | ||
449 | INIT_LIST_HEAD(&adap->clients); | ||
450 | |||
451 | mutex_lock(&core_lock); | ||
452 | 552 | ||
453 | /* Set default timeout to 1 second if not already set */ | 553 | /* Set default timeout to 1 second if not already set */ |
454 | if (adap->timeout == 0) | 554 | if (adap->timeout == 0) |
@@ -463,21 +563,23 @@ static int i2c_register_adapter(struct i2c_adapter *adap) | |||
463 | 563 | ||
464 | dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); | 564 | dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); |
465 | 565 | ||
466 | /* create pre-declared device nodes for new-style drivers */ | 566 | /* create pre-declared device nodes */ |
467 | if (adap->nr < __i2c_first_dynamic_bus_num) | 567 | if (adap->nr < __i2c_first_dynamic_bus_num) |
468 | i2c_scan_static_board_info(adap); | 568 | i2c_scan_static_board_info(adap); |
469 | 569 | ||
470 | /* Notify drivers */ | 570 | /* Notify drivers */ |
571 | mutex_lock(&core_lock); | ||
471 | dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap, | 572 | dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap, |
472 | i2c_do_add_adapter); | 573 | i2c_do_add_adapter); |
473 | |||
474 | out_unlock: | ||
475 | mutex_unlock(&core_lock); | 574 | mutex_unlock(&core_lock); |
476 | return res; | 575 | |
576 | return 0; | ||
477 | 577 | ||
478 | out_list: | 578 | out_list: |
579 | mutex_lock(&core_lock); | ||
479 | idr_remove(&i2c_adapter_idr, adap->nr); | 580 | idr_remove(&i2c_adapter_idr, adap->nr); |
480 | goto out_unlock; | 581 | mutex_unlock(&core_lock); |
582 | return res; | ||
481 | } | 583 | } |
482 | 584 | ||
483 | /** | 585 | /** |
@@ -596,6 +698,14 @@ static int i2c_do_del_adapter(struct device_driver *d, void *data) | |||
596 | return res; | 698 | return res; |
597 | } | 699 | } |
598 | 700 | ||
701 | static int __unregister_client(struct device *dev, void *dummy) | ||
702 | { | ||
703 | struct i2c_client *client = i2c_verify_client(dev); | ||
704 | if (client) | ||
705 | i2c_unregister_device(client); | ||
706 | return 0; | ||
707 | } | ||
708 | |||
599 | /** | 709 | /** |
600 | * i2c_del_adapter - unregister I2C adapter | 710 | * i2c_del_adapter - unregister I2C adapter |
601 | * @adap: the adapter being unregistered | 711 | * @adap: the adapter being unregistered |
@@ -606,46 +716,30 @@ static int i2c_do_del_adapter(struct device_driver *d, void *data) | |||
606 | */ | 716 | */ |
607 | int i2c_del_adapter(struct i2c_adapter *adap) | 717 | int i2c_del_adapter(struct i2c_adapter *adap) |
608 | { | 718 | { |
609 | struct i2c_client *client, *_n; | ||
610 | int res = 0; | 719 | int res = 0; |
611 | 720 | struct i2c_adapter *found; | |
612 | mutex_lock(&core_lock); | ||
613 | 721 | ||
614 | /* First make sure that this adapter was ever added */ | 722 | /* First make sure that this adapter was ever added */ |
615 | if (idr_find(&i2c_adapter_idr, adap->nr) != adap) { | 723 | mutex_lock(&core_lock); |
724 | found = idr_find(&i2c_adapter_idr, adap->nr); | ||
725 | mutex_unlock(&core_lock); | ||
726 | if (found != adap) { | ||
616 | pr_debug("i2c-core: attempting to delete unregistered " | 727 | pr_debug("i2c-core: attempting to delete unregistered " |
617 | "adapter [%s]\n", adap->name); | 728 | "adapter [%s]\n", adap->name); |
618 | res = -EINVAL; | 729 | return -EINVAL; |
619 | goto out_unlock; | ||
620 | } | 730 | } |
621 | 731 | ||
622 | /* Tell drivers about this removal */ | 732 | /* Tell drivers about this removal */ |
733 | mutex_lock(&core_lock); | ||
623 | res = bus_for_each_drv(&i2c_bus_type, NULL, adap, | 734 | res = bus_for_each_drv(&i2c_bus_type, NULL, adap, |
624 | i2c_do_del_adapter); | 735 | i2c_do_del_adapter); |
736 | mutex_unlock(&core_lock); | ||
625 | if (res) | 737 | if (res) |
626 | goto out_unlock; | 738 | return res; |
627 | |||
628 | /* detach any active clients. This must be done first, because | ||
629 | * it can fail; in which case we give up. */ | ||
630 | list_for_each_entry_safe_reverse(client, _n, &adap->clients, list) { | ||
631 | struct i2c_driver *driver; | ||
632 | |||
633 | driver = client->driver; | ||
634 | |||
635 | /* new style, follow standard driver model */ | ||
636 | if (!driver || is_newstyle_driver(driver)) { | ||
637 | i2c_unregister_device(client); | ||
638 | continue; | ||
639 | } | ||
640 | 739 | ||
641 | /* legacy drivers create and remove clients themselves */ | 740 | /* Detach any active clients. This can't fail, thus we do not |
642 | if ((res = driver->detach_client(client))) { | 741 | checking the returned value. */ |
643 | dev_err(&adap->dev, "detach_client failed for client " | 742 | res = device_for_each_child(&adap->dev, NULL, __unregister_client); |
644 | "[%s] at address 0x%02x\n", client->name, | ||
645 | client->addr); | ||
646 | goto out_unlock; | ||
647 | } | ||
648 | } | ||
649 | 743 | ||
650 | /* clean up the sysfs representation */ | 744 | /* clean up the sysfs representation */ |
651 | init_completion(&adap->dev_released); | 745 | init_completion(&adap->dev_released); |
@@ -655,7 +749,9 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
655 | wait_for_completion(&adap->dev_released); | 749 | wait_for_completion(&adap->dev_released); |
656 | 750 | ||
657 | /* free bus id */ | 751 | /* free bus id */ |
752 | mutex_lock(&core_lock); | ||
658 | idr_remove(&i2c_adapter_idr, adap->nr); | 753 | idr_remove(&i2c_adapter_idr, adap->nr); |
754 | mutex_unlock(&core_lock); | ||
659 | 755 | ||
660 | dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); | 756 | dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); |
661 | 757 | ||
@@ -663,9 +759,7 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
663 | added again */ | 759 | added again */ |
664 | memset(&adap->dev, 0, sizeof(adap->dev)); | 760 | memset(&adap->dev, 0, sizeof(adap->dev)); |
665 | 761 | ||
666 | out_unlock: | 762 | return 0; |
667 | mutex_unlock(&core_lock); | ||
668 | return res; | ||
669 | } | 763 | } |
670 | EXPORT_SYMBOL(i2c_del_adapter); | 764 | EXPORT_SYMBOL(i2c_del_adapter); |
671 | 765 | ||
@@ -688,11 +782,7 @@ static int __attach_adapter(struct device *dev, void *data) | |||
688 | 782 | ||
689 | /* | 783 | /* |
690 | * An i2c_driver is used with one or more i2c_client (device) nodes to access | 784 | * An i2c_driver is used with one or more i2c_client (device) nodes to access |
691 | * i2c slave chips, on a bus instance associated with some i2c_adapter. There | 785 | * i2c slave chips, on a bus instance associated with some i2c_adapter. |
692 | * are two models for binding the driver to its device: "new style" drivers | ||
693 | * follow the standard Linux driver model and just respond to probe() calls | ||
694 | * issued if the driver core sees they match(); "legacy" drivers create device | ||
695 | * nodes themselves. | ||
696 | */ | 786 | */ |
697 | 787 | ||
698 | int i2c_register_driver(struct module *owner, struct i2c_driver *driver) | 788 | int i2c_register_driver(struct module *owner, struct i2c_driver *driver) |
@@ -703,37 +793,26 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) | |||
703 | if (unlikely(WARN_ON(!i2c_bus_type.p))) | 793 | if (unlikely(WARN_ON(!i2c_bus_type.p))) |
704 | return -EAGAIN; | 794 | return -EAGAIN; |
705 | 795 | ||
706 | /* new style driver methods can't mix with legacy ones */ | ||
707 | if (is_newstyle_driver(driver)) { | ||
708 | if (driver->detach_adapter || driver->detach_client) { | ||
709 | printk(KERN_WARNING | ||
710 | "i2c-core: driver [%s] is confused\n", | ||
711 | driver->driver.name); | ||
712 | return -EINVAL; | ||
713 | } | ||
714 | } | ||
715 | |||
716 | /* add the driver to the list of i2c drivers in the driver core */ | 796 | /* add the driver to the list of i2c drivers in the driver core */ |
717 | driver->driver.owner = owner; | 797 | driver->driver.owner = owner; |
718 | driver->driver.bus = &i2c_bus_type; | 798 | driver->driver.bus = &i2c_bus_type; |
719 | 799 | ||
720 | /* for new style drivers, when registration returns the driver core | 800 | /* When registration returns, the driver core |
721 | * will have called probe() for all matching-but-unbound devices. | 801 | * will have called probe() for all matching-but-unbound devices. |
722 | */ | 802 | */ |
723 | res = driver_register(&driver->driver); | 803 | res = driver_register(&driver->driver); |
724 | if (res) | 804 | if (res) |
725 | return res; | 805 | return res; |
726 | 806 | ||
727 | mutex_lock(&core_lock); | ||
728 | |||
729 | pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name); | 807 | pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name); |
730 | 808 | ||
731 | INIT_LIST_HEAD(&driver->clients); | 809 | INIT_LIST_HEAD(&driver->clients); |
732 | /* Walk the adapters that are already present */ | 810 | /* Walk the adapters that are already present */ |
811 | mutex_lock(&core_lock); | ||
733 | class_for_each_device(&i2c_adapter_class, NULL, driver, | 812 | class_for_each_device(&i2c_adapter_class, NULL, driver, |
734 | __attach_adapter); | 813 | __attach_adapter); |
735 | |||
736 | mutex_unlock(&core_lock); | 814 | mutex_unlock(&core_lock); |
815 | |||
737 | return 0; | 816 | return 0; |
738 | } | 817 | } |
739 | EXPORT_SYMBOL(i2c_register_driver); | 818 | EXPORT_SYMBOL(i2c_register_driver); |
@@ -753,32 +832,11 @@ static int __detach_adapter(struct device *dev, void *data) | |||
753 | i2c_unregister_device(client); | 832 | i2c_unregister_device(client); |
754 | } | 833 | } |
755 | 834 | ||
756 | if (is_newstyle_driver(driver)) | ||
757 | return 0; | ||
758 | |||
759 | /* Have a look at each adapter, if clients of this driver are still | ||
760 | * attached. If so, detach them to be able to kill the driver | ||
761 | * afterwards. | ||
762 | */ | ||
763 | if (driver->detach_adapter) { | 835 | if (driver->detach_adapter) { |
764 | if (driver->detach_adapter(adapter)) | 836 | if (driver->detach_adapter(adapter)) |
765 | dev_err(&adapter->dev, | 837 | dev_err(&adapter->dev, |
766 | "detach_adapter failed for driver [%s]\n", | 838 | "detach_adapter failed for driver [%s]\n", |
767 | driver->driver.name); | 839 | driver->driver.name); |
768 | } else { | ||
769 | struct i2c_client *client, *_n; | ||
770 | |||
771 | list_for_each_entry_safe(client, _n, &adapter->clients, list) { | ||
772 | if (client->driver != driver) | ||
773 | continue; | ||
774 | dev_dbg(&adapter->dev, | ||
775 | "detaching client [%s] at 0x%02x\n", | ||
776 | client->name, client->addr); | ||
777 | if (driver->detach_client(client)) | ||
778 | dev_err(&adapter->dev, "detach_client " | ||
779 | "failed for client [%s] at 0x%02x\n", | ||
780 | client->name, client->addr); | ||
781 | } | ||
782 | } | 840 | } |
783 | 841 | ||
784 | return 0; | 842 | return 0; |
@@ -792,14 +850,12 @@ static int __detach_adapter(struct device *dev, void *data) | |||
792 | void i2c_del_driver(struct i2c_driver *driver) | 850 | void i2c_del_driver(struct i2c_driver *driver) |
793 | { | 851 | { |
794 | mutex_lock(&core_lock); | 852 | mutex_lock(&core_lock); |
795 | |||
796 | class_for_each_device(&i2c_adapter_class, NULL, driver, | 853 | class_for_each_device(&i2c_adapter_class, NULL, driver, |
797 | __detach_adapter); | 854 | __detach_adapter); |
855 | mutex_unlock(&core_lock); | ||
798 | 856 | ||
799 | driver_unregister(&driver->driver); | 857 | driver_unregister(&driver->driver); |
800 | pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); | 858 | pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); |
801 | |||
802 | mutex_unlock(&core_lock); | ||
803 | } | 859 | } |
804 | EXPORT_SYMBOL(i2c_del_driver); | 860 | EXPORT_SYMBOL(i2c_del_driver); |
805 | 861 | ||
@@ -820,86 +876,6 @@ static int i2c_check_addr(struct i2c_adapter *adapter, int addr) | |||
820 | return device_for_each_child(&adapter->dev, &addr, __i2c_check_addr); | 876 | return device_for_each_child(&adapter->dev, &addr, __i2c_check_addr); |
821 | } | 877 | } |
822 | 878 | ||
823 | int i2c_attach_client(struct i2c_client *client) | ||
824 | { | ||
825 | struct i2c_adapter *adapter = client->adapter; | ||
826 | int res; | ||
827 | |||
828 | /* Check for address business */ | ||
829 | res = i2c_check_addr(adapter, client->addr); | ||
830 | if (res) | ||
831 | return res; | ||
832 | |||
833 | client->dev.parent = &client->adapter->dev; | ||
834 | client->dev.bus = &i2c_bus_type; | ||
835 | |||
836 | if (client->driver) | ||
837 | client->dev.driver = &client->driver->driver; | ||
838 | |||
839 | if (client->driver && !is_newstyle_driver(client->driver)) { | ||
840 | client->dev.release = i2c_client_release; | ||
841 | dev_set_uevent_suppress(&client->dev, 1); | ||
842 | } else | ||
843 | client->dev.release = i2c_client_dev_release; | ||
844 | |||
845 | dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adapter), | ||
846 | client->addr); | ||
847 | res = device_register(&client->dev); | ||
848 | if (res) | ||
849 | goto out_err; | ||
850 | |||
851 | mutex_lock(&adapter->clist_lock); | ||
852 | list_add_tail(&client->list, &adapter->clients); | ||
853 | mutex_unlock(&adapter->clist_lock); | ||
854 | |||
855 | dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", | ||
856 | client->name, dev_name(&client->dev)); | ||
857 | |||
858 | if (adapter->client_register) { | ||
859 | if (adapter->client_register(client)) { | ||
860 | dev_dbg(&adapter->dev, "client_register " | ||
861 | "failed for client [%s] at 0x%02x\n", | ||
862 | client->name, client->addr); | ||
863 | } | ||
864 | } | ||
865 | |||
866 | return 0; | ||
867 | |||
868 | out_err: | ||
869 | dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x " | ||
870 | "(%d)\n", client->name, client->addr, res); | ||
871 | return res; | ||
872 | } | ||
873 | EXPORT_SYMBOL(i2c_attach_client); | ||
874 | |||
875 | int i2c_detach_client(struct i2c_client *client) | ||
876 | { | ||
877 | struct i2c_adapter *adapter = client->adapter; | ||
878 | int res = 0; | ||
879 | |||
880 | if (adapter->client_unregister) { | ||
881 | res = adapter->client_unregister(client); | ||
882 | if (res) { | ||
883 | dev_err(&client->dev, | ||
884 | "client_unregister [%s] failed, " | ||
885 | "client not detached\n", client->name); | ||
886 | goto out; | ||
887 | } | ||
888 | } | ||
889 | |||
890 | mutex_lock(&adapter->clist_lock); | ||
891 | list_del(&client->list); | ||
892 | mutex_unlock(&adapter->clist_lock); | ||
893 | |||
894 | init_completion(&client->released); | ||
895 | device_unregister(&client->dev); | ||
896 | wait_for_completion(&client->released); | ||
897 | |||
898 | out: | ||
899 | return res; | ||
900 | } | ||
901 | EXPORT_SYMBOL(i2c_detach_client); | ||
902 | |||
903 | /** | 879 | /** |
904 | * i2c_use_client - increments the reference count of the i2c client structure | 880 | * i2c_use_client - increments the reference count of the i2c client structure |
905 | * @client: the client being referenced | 881 | * @client: the client being referenced |
@@ -1129,144 +1105,7 @@ EXPORT_SYMBOL(i2c_master_recv); | |||
1129 | * Will not work for 10-bit addresses! | 1105 | * Will not work for 10-bit addresses! |
1130 | * ---------------------------------------------------- | 1106 | * ---------------------------------------------------- |
1131 | */ | 1107 | */ |
1132 | static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind, | ||
1133 | int (*found_proc) (struct i2c_adapter *, int, int)) | ||
1134 | { | ||
1135 | int err; | ||
1136 | |||
1137 | /* Make sure the address is valid */ | ||
1138 | if (addr < 0x03 || addr > 0x77) { | ||
1139 | dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n", | ||
1140 | addr); | ||
1141 | return -EINVAL; | ||
1142 | } | ||
1143 | |||
1144 | /* Skip if already in use */ | ||
1145 | if (i2c_check_addr(adapter, addr)) | ||
1146 | return 0; | ||
1147 | |||
1148 | /* Make sure there is something at this address, unless forced */ | ||
1149 | if (kind < 0) { | ||
1150 | if (i2c_smbus_xfer(adapter, addr, 0, 0, 0, | ||
1151 | I2C_SMBUS_QUICK, NULL) < 0) | ||
1152 | return 0; | ||
1153 | |||
1154 | /* prevent 24RF08 corruption */ | ||
1155 | if ((addr & ~0x0f) == 0x50) | ||
1156 | i2c_smbus_xfer(adapter, addr, 0, 0, 0, | ||
1157 | I2C_SMBUS_QUICK, NULL); | ||
1158 | } | ||
1159 | |||
1160 | /* Finally call the custom detection function */ | ||
1161 | err = found_proc(adapter, addr, kind); | ||
1162 | /* -ENODEV can be returned if there is a chip at the given address | ||
1163 | but it isn't supported by this chip driver. We catch it here as | ||
1164 | this isn't an error. */ | ||
1165 | if (err == -ENODEV) | ||
1166 | err = 0; | ||
1167 | |||
1168 | if (err) | ||
1169 | dev_warn(&adapter->dev, "Client creation failed at 0x%x (%d)\n", | ||
1170 | addr, err); | ||
1171 | return err; | ||
1172 | } | ||
1173 | |||
1174 | int i2c_probe(struct i2c_adapter *adapter, | ||
1175 | const struct i2c_client_address_data *address_data, | ||
1176 | int (*found_proc) (struct i2c_adapter *, int, int)) | ||
1177 | { | ||
1178 | int i, err; | ||
1179 | int adap_id = i2c_adapter_id(adapter); | ||
1180 | |||
1181 | /* Force entries are done first, and are not affected by ignore | ||
1182 | entries */ | ||
1183 | if (address_data->forces) { | ||
1184 | const unsigned short * const *forces = address_data->forces; | ||
1185 | int kind; | ||
1186 | |||
1187 | for (kind = 0; forces[kind]; kind++) { | ||
1188 | for (i = 0; forces[kind][i] != I2C_CLIENT_END; | ||
1189 | i += 2) { | ||
1190 | if (forces[kind][i] == adap_id | ||
1191 | || forces[kind][i] == ANY_I2C_BUS) { | ||
1192 | dev_dbg(&adapter->dev, "found force " | ||
1193 | "parameter for adapter %d, " | ||
1194 | "addr 0x%02x, kind %d\n", | ||
1195 | adap_id, forces[kind][i + 1], | ||
1196 | kind); | ||
1197 | err = i2c_probe_address(adapter, | ||
1198 | forces[kind][i + 1], | ||
1199 | kind, found_proc); | ||
1200 | if (err) | ||
1201 | return err; | ||
1202 | } | ||
1203 | } | ||
1204 | } | ||
1205 | } | ||
1206 | |||
1207 | /* Stop here if we can't use SMBUS_QUICK */ | ||
1208 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) { | ||
1209 | if (address_data->probe[0] == I2C_CLIENT_END | ||
1210 | && address_data->normal_i2c[0] == I2C_CLIENT_END) | ||
1211 | return 0; | ||
1212 | |||
1213 | dev_dbg(&adapter->dev, "SMBus Quick command not supported, " | ||
1214 | "can't probe for chips\n"); | ||
1215 | return -EOPNOTSUPP; | ||
1216 | } | ||
1217 | |||
1218 | /* Probe entries are done second, and are not affected by ignore | ||
1219 | entries either */ | ||
1220 | for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) { | ||
1221 | if (address_data->probe[i] == adap_id | ||
1222 | || address_data->probe[i] == ANY_I2C_BUS) { | ||
1223 | dev_dbg(&adapter->dev, "found probe parameter for " | ||
1224 | "adapter %d, addr 0x%02x\n", adap_id, | ||
1225 | address_data->probe[i + 1]); | ||
1226 | err = i2c_probe_address(adapter, | ||
1227 | address_data->probe[i + 1], | ||
1228 | -1, found_proc); | ||
1229 | if (err) | ||
1230 | return err; | ||
1231 | } | ||
1232 | } | ||
1233 | |||
1234 | /* Normal entries are done last, unless shadowed by an ignore entry */ | ||
1235 | for (i = 0; address_data->normal_i2c[i] != I2C_CLIENT_END; i += 1) { | ||
1236 | int j, ignore; | ||
1237 | |||
1238 | ignore = 0; | ||
1239 | for (j = 0; address_data->ignore[j] != I2C_CLIENT_END; | ||
1240 | j += 2) { | ||
1241 | if ((address_data->ignore[j] == adap_id || | ||
1242 | address_data->ignore[j] == ANY_I2C_BUS) | ||
1243 | && address_data->ignore[j + 1] | ||
1244 | == address_data->normal_i2c[i]) { | ||
1245 | dev_dbg(&adapter->dev, "found ignore " | ||
1246 | "parameter for adapter %d, " | ||
1247 | "addr 0x%02x\n", adap_id, | ||
1248 | address_data->ignore[j + 1]); | ||
1249 | ignore = 1; | ||
1250 | break; | ||
1251 | } | ||
1252 | } | ||
1253 | if (ignore) | ||
1254 | continue; | ||
1255 | |||
1256 | dev_dbg(&adapter->dev, "found normal entry for adapter %d, " | ||
1257 | "addr 0x%02x\n", adap_id, | ||
1258 | address_data->normal_i2c[i]); | ||
1259 | err = i2c_probe_address(adapter, address_data->normal_i2c[i], | ||
1260 | -1, found_proc); | ||
1261 | if (err) | ||
1262 | return err; | ||
1263 | } | ||
1264 | |||
1265 | return 0; | ||
1266 | } | ||
1267 | EXPORT_SYMBOL(i2c_probe); | ||
1268 | 1108 | ||
1269 | /* Separate detection function for new-style drivers */ | ||
1270 | static int i2c_detect_address(struct i2c_client *temp_client, int kind, | 1109 | static int i2c_detect_address(struct i2c_client *temp_client, int kind, |
1271 | struct i2c_driver *driver) | 1110 | struct i2c_driver *driver) |
1272 | { | 1111 | { |
diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h index cd5bff874855..9f9c57ff6708 100644 --- a/drivers/i2c/i2c-core.h +++ b/drivers/i2c/i2c-core.h | |||
@@ -16,6 +16,8 @@ | |||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include <linux/rwsem.h> | ||
20 | |||
19 | struct i2c_devinfo { | 21 | struct i2c_devinfo { |
20 | struct list_head list; | 22 | struct list_head list; |
21 | int busnum; | 23 | int busnum; |
@@ -25,7 +27,7 @@ struct i2c_devinfo { | |||
25 | /* board_lock protects board_list and first_dynamic_bus_num. | 27 | /* board_lock protects board_list and first_dynamic_bus_num. |
26 | * only i2c core components are allowed to use these symbols. | 28 | * only i2c core components are allowed to use these symbols. |
27 | */ | 29 | */ |
28 | extern struct mutex __i2c_board_lock; | 30 | extern struct rw_semaphore __i2c_board_lock; |
29 | extern struct list_head __i2c_board_list; | 31 | extern struct list_head __i2c_board_list; |
30 | extern int __i2c_first_dynamic_bus_num; | 32 | extern int __i2c_first_dynamic_bus_num; |
31 | 33 | ||
diff --git a/include/linux/i2c.h b/include/linux/i2c.h index ad2580596033..f4784c0fe975 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h | |||
@@ -47,6 +47,7 @@ struct i2c_driver; | |||
47 | union i2c_smbus_data; | 47 | union i2c_smbus_data; |
48 | struct i2c_board_info; | 48 | struct i2c_board_info; |
49 | 49 | ||
50 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
50 | /* | 51 | /* |
51 | * The master routines are the ones normally used to transmit data to devices | 52 | * The master routines are the ones normally used to transmit data to devices |
52 | * on a bus (or read from them). Apart from two basic transfer functions to | 53 | * on a bus (or read from them). Apart from two basic transfer functions to |
@@ -93,6 +94,7 @@ extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, | |||
93 | extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, | 94 | extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, |
94 | u8 command, u8 length, | 95 | u8 command, u8 length, |
95 | const u8 *values); | 96 | const u8 *values); |
97 | #endif /* I2C */ | ||
96 | 98 | ||
97 | /** | 99 | /** |
98 | * struct i2c_driver - represent an I2C device driver | 100 | * struct i2c_driver - represent an I2C device driver |
@@ -100,9 +102,8 @@ extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, | |||
100 | * @class: What kind of i2c device we instantiate (for detect) | 102 | * @class: What kind of i2c device we instantiate (for detect) |
101 | * @attach_adapter: Callback for bus addition (for legacy drivers) | 103 | * @attach_adapter: Callback for bus addition (for legacy drivers) |
102 | * @detach_adapter: Callback for bus removal (for legacy drivers) | 104 | * @detach_adapter: Callback for bus removal (for legacy drivers) |
103 | * @detach_client: Callback for device removal (for legacy drivers) | 105 | * @probe: Callback for device binding |
104 | * @probe: Callback for device binding (new-style drivers) | 106 | * @remove: Callback for device unbinding |
105 | * @remove: Callback for device unbinding (new-style drivers) | ||
106 | * @shutdown: Callback for device shutdown | 107 | * @shutdown: Callback for device shutdown |
107 | * @suspend: Callback for device suspend | 108 | * @suspend: Callback for device suspend |
108 | * @resume: Callback for device resume | 109 | * @resume: Callback for device resume |
@@ -137,26 +138,14 @@ struct i2c_driver { | |||
137 | int id; | 138 | int id; |
138 | unsigned int class; | 139 | unsigned int class; |
139 | 140 | ||
140 | /* Notifies the driver that a new bus has appeared. This routine | 141 | /* Notifies the driver that a new bus has appeared or is about to be |
141 | * can be used by the driver to test if the bus meets its conditions | 142 | * removed. You should avoid using this if you can, it will probably |
142 | * & seek for the presence of the chip(s) it supports. If found, it | 143 | * be removed in a near future. |
143 | * registers the client(s) that are on the bus to the i2c admin. via | ||
144 | * i2c_attach_client. (LEGACY I2C DRIVERS ONLY) | ||
145 | */ | 144 | */ |
146 | int (*attach_adapter)(struct i2c_adapter *); | 145 | int (*attach_adapter)(struct i2c_adapter *); |
147 | int (*detach_adapter)(struct i2c_adapter *); | 146 | int (*detach_adapter)(struct i2c_adapter *); |
148 | 147 | ||
149 | /* tells the driver that a client is about to be deleted & gives it | 148 | /* Standard driver model interfaces */ |
150 | * the chance to remove its private data. Also, if the client struct | ||
151 | * has been dynamically allocated by the driver in the function above, | ||
152 | * it must be freed here. (LEGACY I2C DRIVERS ONLY) | ||
153 | */ | ||
154 | int (*detach_client)(struct i2c_client *) __deprecated; | ||
155 | |||
156 | /* Standard driver model interfaces, for "new style" i2c drivers. | ||
157 | * With the driver model, device enumeration is NEVER done by drivers; | ||
158 | * it's done by infrastructure. (NEW STYLE DRIVERS ONLY) | ||
159 | */ | ||
160 | int (*probe)(struct i2c_client *, const struct i2c_device_id *); | 149 | int (*probe)(struct i2c_client *, const struct i2c_device_id *); |
161 | int (*remove)(struct i2c_client *); | 150 | int (*remove)(struct i2c_client *); |
162 | 151 | ||
@@ -191,9 +180,8 @@ struct i2c_driver { | |||
191 | * @driver: device's driver, hence pointer to access routines | 180 | * @driver: device's driver, hence pointer to access routines |
192 | * @dev: Driver model device node for the slave. | 181 | * @dev: Driver model device node for the slave. |
193 | * @irq: indicates the IRQ generated by this device (if any) | 182 | * @irq: indicates the IRQ generated by this device (if any) |
194 | * @list: list of active/busy clients (DEPRECATED) | 183 | * @detected: member of an i2c_driver.clients list or i2c-core's |
195 | * @detected: member of an i2c_driver.clients list | 184 | * userspace_devices list |
196 | * @released: used to synchronize client releases & detaches and references | ||
197 | * | 185 | * |
198 | * An i2c_client identifies a single device (i.e. chip) connected to an | 186 | * An i2c_client identifies a single device (i.e. chip) connected to an |
199 | * i2c bus. The behaviour exposed to Linux is defined by the driver | 187 | * i2c bus. The behaviour exposed to Linux is defined by the driver |
@@ -209,9 +197,7 @@ struct i2c_client { | |||
209 | struct i2c_driver *driver; /* and our access routines */ | 197 | struct i2c_driver *driver; /* and our access routines */ |
210 | struct device dev; /* the device structure */ | 198 | struct device dev; /* the device structure */ |
211 | int irq; /* irq issued by device */ | 199 | int irq; /* irq issued by device */ |
212 | struct list_head list; /* DEPRECATED */ | ||
213 | struct list_head detected; | 200 | struct list_head detected; |
214 | struct completion released; | ||
215 | }; | 201 | }; |
216 | #define to_i2c_client(d) container_of(d, struct i2c_client, dev) | 202 | #define to_i2c_client(d) container_of(d, struct i2c_client, dev) |
217 | 203 | ||
@@ -248,11 +234,10 @@ static inline void i2c_set_clientdata(struct i2c_client *dev, void *data) | |||
248 | * that, such as chip type, configuration, associated IRQ, and so on. | 234 | * that, such as chip type, configuration, associated IRQ, and so on. |
249 | * | 235 | * |
250 | * i2c_board_info is used to build tables of information listing I2C devices | 236 | * i2c_board_info is used to build tables of information listing I2C devices |
251 | * that are present. This information is used to grow the driver model tree | 237 | * that are present. This information is used to grow the driver model tree. |
252 | * for "new style" I2C drivers. For mainboards this is done statically using | 238 | * For mainboards this is done statically using i2c_register_board_info(); |
253 | * i2c_register_board_info(); bus numbers identify adapters that aren't | 239 | * bus numbers identify adapters that aren't yet available. For add-on boards, |
254 | * yet available. For add-on boards, i2c_new_device() does this dynamically | 240 | * i2c_new_device() does this dynamically with the adapter already known. |
255 | * with the adapter already known. | ||
256 | */ | 241 | */ |
257 | struct i2c_board_info { | 242 | struct i2c_board_info { |
258 | char type[I2C_NAME_SIZE]; | 243 | char type[I2C_NAME_SIZE]; |
@@ -277,6 +262,7 @@ struct i2c_board_info { | |||
277 | .type = dev_type, .addr = (dev_addr) | 262 | .type = dev_type, .addr = (dev_addr) |
278 | 263 | ||
279 | 264 | ||
265 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
280 | /* Add-on boards should register/unregister their devices; e.g. a board | 266 | /* Add-on boards should register/unregister their devices; e.g. a board |
281 | * with integrated I2C, a config eeprom, sensors, and a codec that's | 267 | * with integrated I2C, a config eeprom, sensors, and a codec that's |
282 | * used in conjunction with the primary hardware. | 268 | * used in conjunction with the primary hardware. |
@@ -300,6 +286,7 @@ extern struct i2c_client * | |||
300 | i2c_new_dummy(struct i2c_adapter *adap, u16 address); | 286 | i2c_new_dummy(struct i2c_adapter *adap, u16 address); |
301 | 287 | ||
302 | extern void i2c_unregister_device(struct i2c_client *); | 288 | extern void i2c_unregister_device(struct i2c_client *); |
289 | #endif /* I2C */ | ||
303 | 290 | ||
304 | /* Mainboard arch_initcall() code should register all its I2C devices. | 291 | /* Mainboard arch_initcall() code should register all its I2C devices. |
305 | * This is done at arch_initcall time, before declaring any i2c adapters. | 292 | * This is done at arch_initcall time, before declaring any i2c adapters. |
@@ -316,7 +303,7 @@ i2c_register_board_info(int busnum, struct i2c_board_info const *info, | |||
316 | { | 303 | { |
317 | return 0; | 304 | return 0; |
318 | } | 305 | } |
319 | #endif | 306 | #endif /* I2C_BOARDINFO */ |
320 | 307 | ||
321 | /* | 308 | /* |
322 | * The following structs are for those who like to implement new bus drivers: | 309 | * The following structs are for those who like to implement new bus drivers: |
@@ -352,21 +339,15 @@ struct i2c_adapter { | |||
352 | const struct i2c_algorithm *algo; /* the algorithm to access the bus */ | 339 | const struct i2c_algorithm *algo; /* the algorithm to access the bus */ |
353 | void *algo_data; | 340 | void *algo_data; |
354 | 341 | ||
355 | /* --- administration stuff. */ | ||
356 | int (*client_register)(struct i2c_client *) __deprecated; | ||
357 | int (*client_unregister)(struct i2c_client *) __deprecated; | ||
358 | |||
359 | /* data fields that are valid for all devices */ | 342 | /* data fields that are valid for all devices */ |
360 | u8 level; /* nesting level for lockdep */ | 343 | u8 level; /* nesting level for lockdep */ |
361 | struct mutex bus_lock; | 344 | struct mutex bus_lock; |
362 | struct mutex clist_lock; | ||
363 | 345 | ||
364 | int timeout; /* in jiffies */ | 346 | int timeout; /* in jiffies */ |
365 | int retries; | 347 | int retries; |
366 | struct device dev; /* the adapter device */ | 348 | struct device dev; /* the adapter device */ |
367 | 349 | ||
368 | int nr; | 350 | int nr; |
369 | struct list_head clients; /* DEPRECATED */ | ||
370 | char name[48]; | 351 | char name[48]; |
371 | struct completion dev_released; | 352 | struct completion dev_released; |
372 | }; | 353 | }; |
@@ -412,11 +393,16 @@ struct i2c_client_address_data { | |||
412 | /* The numbers to use to set I2C bus address */ | 393 | /* The numbers to use to set I2C bus address */ |
413 | #define ANY_I2C_BUS 0xffff | 394 | #define ANY_I2C_BUS 0xffff |
414 | 395 | ||
396 | /* Construct an I2C_CLIENT_END-terminated array of i2c addresses */ | ||
397 | #define I2C_ADDRS(addr, addrs...) \ | ||
398 | ((const unsigned short []){ addr, ## addrs, I2C_CLIENT_END }) | ||
399 | |||
415 | 400 | ||
416 | /* ----- functions exported by i2c.o */ | 401 | /* ----- functions exported by i2c.o */ |
417 | 402 | ||
418 | /* administration... | 403 | /* administration... |
419 | */ | 404 | */ |
405 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | ||
420 | extern int i2c_add_adapter(struct i2c_adapter *); | 406 | extern int i2c_add_adapter(struct i2c_adapter *); |
421 | extern int i2c_del_adapter(struct i2c_adapter *); | 407 | extern int i2c_del_adapter(struct i2c_adapter *); |
422 | extern int i2c_add_numbered_adapter(struct i2c_adapter *); | 408 | extern int i2c_add_numbered_adapter(struct i2c_adapter *); |
@@ -429,11 +415,6 @@ static inline int i2c_add_driver(struct i2c_driver *driver) | |||
429 | return i2c_register_driver(THIS_MODULE, driver); | 415 | return i2c_register_driver(THIS_MODULE, driver); |
430 | } | 416 | } |
431 | 417 | ||
432 | /* These are deprecated, your driver should use the standard .probe() | ||
433 | * and .remove() methods instead. */ | ||
434 | extern int __deprecated i2c_attach_client(struct i2c_client *); | ||
435 | extern int __deprecated i2c_detach_client(struct i2c_client *); | ||
436 | |||
437 | extern struct i2c_client *i2c_use_client(struct i2c_client *client); | 418 | extern struct i2c_client *i2c_use_client(struct i2c_client *client); |
438 | extern void i2c_release_client(struct i2c_client *client); | 419 | extern void i2c_release_client(struct i2c_client *client); |
439 | 420 | ||
@@ -442,14 +423,6 @@ extern void i2c_release_client(struct i2c_client *client); | |||
442 | extern void i2c_clients_command(struct i2c_adapter *adap, | 423 | extern void i2c_clients_command(struct i2c_adapter *adap, |
443 | unsigned int cmd, void *arg); | 424 | unsigned int cmd, void *arg); |
444 | 425 | ||
445 | /* Detect function. It iterates over all possible addresses itself. | ||
446 | * It will only call found_proc if some client is connected at the | ||
447 | * specific address (unless a 'force' matched); | ||
448 | */ | ||
449 | extern int i2c_probe(struct i2c_adapter *adapter, | ||
450 | const struct i2c_client_address_data *address_data, | ||
451 | int (*found_proc) (struct i2c_adapter *, int, int)); | ||
452 | |||
453 | extern struct i2c_adapter *i2c_get_adapter(int id); | 426 | extern struct i2c_adapter *i2c_get_adapter(int id); |
454 | extern void i2c_put_adapter(struct i2c_adapter *adap); | 427 | extern void i2c_put_adapter(struct i2c_adapter *adap); |
455 | 428 | ||
@@ -471,6 +444,7 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap) | |||
471 | { | 444 | { |
472 | return adap->nr; | 445 | return adap->nr; |
473 | } | 446 | } |
447 | #endif /* I2C */ | ||
474 | #endif /* __KERNEL__ */ | 448 | #endif /* __KERNEL__ */ |
475 | 449 | ||
476 | /** | 450 | /** |