diff options
-rw-r--r-- | Documentation/i2c/instantiating-devices | 2 | ||||
-rw-r--r-- | drivers/i2c/Kconfig | 13 | ||||
-rw-r--r-- | drivers/i2c/Makefile | 3 | ||||
-rw-r--r-- | drivers/i2c/i2c-core.c | 158 | ||||
-rw-r--r-- | drivers/i2c/i2c-dev.c | 66 | ||||
-rw-r--r-- | drivers/i2c/i2c-mux.c | 165 | ||||
-rw-r--r-- | drivers/i2c/muxes/Kconfig | 18 | ||||
-rw-r--r-- | drivers/i2c/muxes/Makefile | 8 | ||||
-rw-r--r-- | drivers/i2c/muxes/pca954x.c | 301 | ||||
-rw-r--r-- | drivers/macintosh/therm_windtunnel.c | 4 | ||||
-rw-r--r-- | drivers/media/video/bt8xx/bttv-i2c.c | 2 | ||||
-rw-r--r-- | drivers/media/video/cx18/cx18-i2c.c | 3 | ||||
-rw-r--r-- | drivers/media/video/cx23885/cx23885-i2c.c | 15 | ||||
-rw-r--r-- | drivers/media/video/cx88/cx88-i2c.c | 19 | ||||
-rw-r--r-- | drivers/media/video/em28xx/em28xx-cards.c | 2 | ||||
-rw-r--r-- | drivers/media/video/ivtv/ivtv-i2c.c | 9 | ||||
-rw-r--r-- | drivers/media/video/v4l2-common.c | 3 | ||||
-rw-r--r-- | drivers/usb/host/ohci-pnx4008.c | 2 | ||||
-rw-r--r-- | drivers/video/matrox/i2c-matroxfb.c | 2 | ||||
-rw-r--r-- | include/linux/i2c-mux.h | 46 | ||||
-rw-r--r-- | include/linux/i2c.h | 33 | ||||
-rw-r--r-- | include/linux/i2c/pca954x.h | 47 |
22 files changed, 805 insertions, 116 deletions
diff --git a/Documentation/i2c/instantiating-devices b/Documentation/i2c/instantiating-devices index e89490270aba..87da405a8597 100644 --- a/Documentation/i2c/instantiating-devices +++ b/Documentation/i2c/instantiating-devices | |||
@@ -102,7 +102,7 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev) | |||
102 | memset(&i2c_info, 0, sizeof(struct i2c_board_info)); | 102 | memset(&i2c_info, 0, sizeof(struct i2c_board_info)); |
103 | strlcpy(i2c_info.name, "isp1301_pnx", I2C_NAME_SIZE); | 103 | strlcpy(i2c_info.name, "isp1301_pnx", I2C_NAME_SIZE); |
104 | isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, | 104 | isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, |
105 | normal_i2c); | 105 | normal_i2c, NULL); |
106 | i2c_put_adapter(i2c_adap); | 106 | i2c_put_adapter(i2c_adap); |
107 | (...) | 107 | (...) |
108 | } | 108 | } |
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig index d06083fdffbb..30f06e956bfb 100644 --- a/drivers/i2c/Kconfig +++ b/drivers/i2c/Kconfig | |||
@@ -47,6 +47,19 @@ config I2C_CHARDEV | |||
47 | This support is also available as a module. If so, the module | 47 | This support is also available as a module. If so, the module |
48 | will be called i2c-dev. | 48 | will be called i2c-dev. |
49 | 49 | ||
50 | config I2C_MUX | ||
51 | tristate "I2C bus multiplexing support" | ||
52 | depends on EXPERIMENTAL | ||
53 | help | ||
54 | Say Y here if you want the I2C core to support the ability to | ||
55 | handle multiplexed I2C bus topologies, by presenting each | ||
56 | multiplexed segment as a I2C adapter. | ||
57 | |||
58 | This support is also available as a module. If so, the module | ||
59 | will be called i2c-mux. | ||
60 | |||
61 | source drivers/i2c/muxes/Kconfig | ||
62 | |||
50 | config I2C_HELPER_AUTO | 63 | config I2C_HELPER_AUTO |
51 | bool "Autoselect pertinent helper modules" | 64 | bool "Autoselect pertinent helper modules" |
52 | default y | 65 | default y |
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile index a7d9b4be9bb3..c00fd66388f5 100644 --- a/drivers/i2c/Makefile +++ b/drivers/i2c/Makefile | |||
@@ -6,7 +6,8 @@ obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o | |||
6 | obj-$(CONFIG_I2C) += i2c-core.o | 6 | obj-$(CONFIG_I2C) += i2c-core.o |
7 | obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o | 7 | obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o |
8 | obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o | 8 | obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o |
9 | obj-y += algos/ busses/ | 9 | obj-$(CONFIG_I2C_MUX) += i2c-mux.o |
10 | obj-y += algos/ busses/ muxes/ | ||
10 | 11 | ||
11 | ifeq ($(CONFIG_I2C_DEBUG_CORE),y) | 12 | ifeq ($(CONFIG_I2C_DEBUG_CORE),y) |
12 | EXTRA_CFLAGS += -DDEBUG | 13 | EXTRA_CFLAGS += -DDEBUG |
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index df937df845eb..6649176de940 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -20,7 +20,9 @@ | |||
20 | /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>. | 20 | /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>. |
21 | All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> | 21 | All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> |
22 | SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and | 22 | SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and |
23 | Jean Delvare <khali@linux-fr.org> */ | 23 | Jean Delvare <khali@linux-fr.org> |
24 | Mux support by Rodolfo Giometti <giometti@enneenne.com> and | ||
25 | Michael Lawnick <michael.lawnick.ext@nsn.com> */ | ||
24 | 26 | ||
25 | #include <linux/module.h> | 27 | #include <linux/module.h> |
26 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
@@ -423,11 +425,87 @@ static int __i2c_check_addr_busy(struct device *dev, void *addrp) | |||
423 | return 0; | 425 | return 0; |
424 | } | 426 | } |
425 | 427 | ||
428 | /* walk up mux tree */ | ||
429 | static int i2c_check_mux_parents(struct i2c_adapter *adapter, int addr) | ||
430 | { | ||
431 | int result; | ||
432 | |||
433 | result = device_for_each_child(&adapter->dev, &addr, | ||
434 | __i2c_check_addr_busy); | ||
435 | |||
436 | if (!result && i2c_parent_is_i2c_adapter(adapter)) | ||
437 | result = i2c_check_mux_parents( | ||
438 | to_i2c_adapter(adapter->dev.parent), addr); | ||
439 | |||
440 | return result; | ||
441 | } | ||
442 | |||
443 | /* recurse down mux tree */ | ||
444 | static int i2c_check_mux_children(struct device *dev, void *addrp) | ||
445 | { | ||
446 | int result; | ||
447 | |||
448 | if (dev->type == &i2c_adapter_type) | ||
449 | result = device_for_each_child(dev, addrp, | ||
450 | i2c_check_mux_children); | ||
451 | else | ||
452 | result = __i2c_check_addr_busy(dev, addrp); | ||
453 | |||
454 | return result; | ||
455 | } | ||
456 | |||
426 | static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) | 457 | static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) |
427 | { | 458 | { |
428 | return device_for_each_child(&adapter->dev, &addr, | 459 | int result = 0; |
429 | __i2c_check_addr_busy); | 460 | |
461 | if (i2c_parent_is_i2c_adapter(adapter)) | ||
462 | result = i2c_check_mux_parents( | ||
463 | to_i2c_adapter(adapter->dev.parent), addr); | ||
464 | |||
465 | if (!result) | ||
466 | result = device_for_each_child(&adapter->dev, &addr, | ||
467 | i2c_check_mux_children); | ||
468 | |||
469 | return result; | ||
470 | } | ||
471 | |||
472 | /** | ||
473 | * i2c_lock_adapter - Get exclusive access to an I2C bus segment | ||
474 | * @adapter: Target I2C bus segment | ||
475 | */ | ||
476 | void i2c_lock_adapter(struct i2c_adapter *adapter) | ||
477 | { | ||
478 | if (i2c_parent_is_i2c_adapter(adapter)) | ||
479 | i2c_lock_adapter(to_i2c_adapter(adapter->dev.parent)); | ||
480 | else | ||
481 | rt_mutex_lock(&adapter->bus_lock); | ||
482 | } | ||
483 | EXPORT_SYMBOL_GPL(i2c_lock_adapter); | ||
484 | |||
485 | /** | ||
486 | * i2c_trylock_adapter - Try to get exclusive access to an I2C bus segment | ||
487 | * @adapter: Target I2C bus segment | ||
488 | */ | ||
489 | static int i2c_trylock_adapter(struct i2c_adapter *adapter) | ||
490 | { | ||
491 | if (i2c_parent_is_i2c_adapter(adapter)) | ||
492 | return i2c_trylock_adapter(to_i2c_adapter(adapter->dev.parent)); | ||
493 | else | ||
494 | return rt_mutex_trylock(&adapter->bus_lock); | ||
495 | } | ||
496 | |||
497 | /** | ||
498 | * i2c_unlock_adapter - Release exclusive access to an I2C bus segment | ||
499 | * @adapter: Target I2C bus segment | ||
500 | */ | ||
501 | void i2c_unlock_adapter(struct i2c_adapter *adapter) | ||
502 | { | ||
503 | if (i2c_parent_is_i2c_adapter(adapter)) | ||
504 | i2c_unlock_adapter(to_i2c_adapter(adapter->dev.parent)); | ||
505 | else | ||
506 | rt_mutex_unlock(&adapter->bus_lock); | ||
430 | } | 507 | } |
508 | EXPORT_SYMBOL_GPL(i2c_unlock_adapter); | ||
431 | 509 | ||
432 | /** | 510 | /** |
433 | * i2c_new_device - instantiate an i2c device | 511 | * i2c_new_device - instantiate an i2c device |
@@ -633,9 +711,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr, | |||
633 | return -EINVAL; | 711 | return -EINVAL; |
634 | 712 | ||
635 | /* Keep track of the added device */ | 713 | /* Keep track of the added device */ |
636 | i2c_lock_adapter(adap); | 714 | mutex_lock(&adap->userspace_clients_lock); |
637 | list_add_tail(&client->detected, &adap->userspace_clients); | 715 | list_add_tail(&client->detected, &adap->userspace_clients); |
638 | i2c_unlock_adapter(adap); | 716 | mutex_unlock(&adap->userspace_clients_lock); |
639 | dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", | 717 | dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", |
640 | info.type, info.addr); | 718 | info.type, info.addr); |
641 | 719 | ||
@@ -674,7 +752,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr, | |||
674 | 752 | ||
675 | /* Make sure the device was added through sysfs */ | 753 | /* Make sure the device was added through sysfs */ |
676 | res = -ENOENT; | 754 | res = -ENOENT; |
677 | i2c_lock_adapter(adap); | 755 | mutex_lock(&adap->userspace_clients_lock); |
678 | list_for_each_entry_safe(client, next, &adap->userspace_clients, | 756 | list_for_each_entry_safe(client, next, &adap->userspace_clients, |
679 | detected) { | 757 | detected) { |
680 | if (client->addr == addr) { | 758 | if (client->addr == addr) { |
@@ -687,7 +765,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr, | |||
687 | break; | 765 | break; |
688 | } | 766 | } |
689 | } | 767 | } |
690 | i2c_unlock_adapter(adap); | 768 | mutex_unlock(&adap->userspace_clients_lock); |
691 | 769 | ||
692 | if (res < 0) | 770 | if (res < 0) |
693 | dev_err(dev, "%s: Can't find device in list\n", | 771 | dev_err(dev, "%s: Can't find device in list\n", |
@@ -714,10 +792,11 @@ static const struct attribute_group *i2c_adapter_attr_groups[] = { | |||
714 | NULL | 792 | NULL |
715 | }; | 793 | }; |
716 | 794 | ||
717 | static struct device_type i2c_adapter_type = { | 795 | struct device_type i2c_adapter_type = { |
718 | .groups = i2c_adapter_attr_groups, | 796 | .groups = i2c_adapter_attr_groups, |
719 | .release = i2c_adapter_dev_release, | 797 | .release = i2c_adapter_dev_release, |
720 | }; | 798 | }; |
799 | EXPORT_SYMBOL_GPL(i2c_adapter_type); | ||
721 | 800 | ||
722 | #ifdef CONFIG_I2C_COMPAT | 801 | #ifdef CONFIG_I2C_COMPAT |
723 | static struct class_compat *i2c_adapter_compat_class; | 802 | static struct class_compat *i2c_adapter_compat_class; |
@@ -760,7 +839,7 @@ static int __process_new_adapter(struct device_driver *d, void *data) | |||
760 | 839 | ||
761 | static int i2c_register_adapter(struct i2c_adapter *adap) | 840 | static int i2c_register_adapter(struct i2c_adapter *adap) |
762 | { | 841 | { |
763 | int res = 0, dummy; | 842 | int res = 0; |
764 | 843 | ||
765 | /* Can't register until after driver model init */ | 844 | /* Can't register until after driver model init */ |
766 | if (unlikely(WARN_ON(!i2c_bus_type.p))) { | 845 | if (unlikely(WARN_ON(!i2c_bus_type.p))) { |
@@ -769,6 +848,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) | |||
769 | } | 848 | } |
770 | 849 | ||
771 | rt_mutex_init(&adap->bus_lock); | 850 | rt_mutex_init(&adap->bus_lock); |
851 | mutex_init(&adap->userspace_clients_lock); | ||
772 | INIT_LIST_HEAD(&adap->userspace_clients); | 852 | INIT_LIST_HEAD(&adap->userspace_clients); |
773 | 853 | ||
774 | /* Set default timeout to 1 second if not already set */ | 854 | /* Set default timeout to 1 second if not already set */ |
@@ -801,8 +881,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap) | |||
801 | 881 | ||
802 | /* Notify drivers */ | 882 | /* Notify drivers */ |
803 | mutex_lock(&core_lock); | 883 | mutex_lock(&core_lock); |
804 | dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap, | 884 | bus_for_each_drv(&i2c_bus_type, NULL, adap, __process_new_adapter); |
805 | __process_new_adapter); | ||
806 | mutex_unlock(&core_lock); | 885 | mutex_unlock(&core_lock); |
807 | 886 | ||
808 | return 0; | 887 | return 0; |
@@ -975,7 +1054,7 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
975 | return res; | 1054 | return res; |
976 | 1055 | ||
977 | /* Remove devices instantiated from sysfs */ | 1056 | /* Remove devices instantiated from sysfs */ |
978 | i2c_lock_adapter(adap); | 1057 | mutex_lock(&adap->userspace_clients_lock); |
979 | list_for_each_entry_safe(client, next, &adap->userspace_clients, | 1058 | list_for_each_entry_safe(client, next, &adap->userspace_clients, |
980 | detected) { | 1059 | detected) { |
981 | dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name, | 1060 | dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name, |
@@ -983,7 +1062,7 @@ int i2c_del_adapter(struct i2c_adapter *adap) | |||
983 | list_del(&client->detected); | 1062 | list_del(&client->detected); |
984 | i2c_unregister_device(client); | 1063 | i2c_unregister_device(client); |
985 | } | 1064 | } |
986 | i2c_unlock_adapter(adap); | 1065 | mutex_unlock(&adap->userspace_clients_lock); |
987 | 1066 | ||
988 | /* Detach any active clients. This can't fail, thus we do not | 1067 | /* Detach any active clients. This can't fail, thus we do not |
989 | checking the returned value. */ | 1068 | checking the returned value. */ |
@@ -1238,12 +1317,12 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
1238 | #endif | 1317 | #endif |
1239 | 1318 | ||
1240 | if (in_atomic() || irqs_disabled()) { | 1319 | if (in_atomic() || irqs_disabled()) { |
1241 | ret = rt_mutex_trylock(&adap->bus_lock); | 1320 | ret = i2c_trylock_adapter(adap); |
1242 | if (!ret) | 1321 | if (!ret) |
1243 | /* I2C activity is ongoing. */ | 1322 | /* I2C activity is ongoing. */ |
1244 | return -EAGAIN; | 1323 | return -EAGAIN; |
1245 | } else { | 1324 | } else { |
1246 | rt_mutex_lock(&adap->bus_lock); | 1325 | i2c_lock_adapter(adap); |
1247 | } | 1326 | } |
1248 | 1327 | ||
1249 | /* Retry automatically on arbitration loss */ | 1328 | /* Retry automatically on arbitration loss */ |
@@ -1255,7 +1334,7 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
1255 | if (time_after(jiffies, orig_jiffies + adap->timeout)) | 1334 | if (time_after(jiffies, orig_jiffies + adap->timeout)) |
1256 | break; | 1335 | break; |
1257 | } | 1336 | } |
1258 | rt_mutex_unlock(&adap->bus_lock); | 1337 | i2c_unlock_adapter(adap); |
1259 | 1338 | ||
1260 | return ret; | 1339 | return ret; |
1261 | } else { | 1340 | } else { |
@@ -1350,13 +1429,17 @@ static int i2c_default_probe(struct i2c_adapter *adap, unsigned short addr) | |||
1350 | I2C_SMBUS_BYTE_DATA, &dummy); | 1429 | I2C_SMBUS_BYTE_DATA, &dummy); |
1351 | else | 1430 | else |
1352 | #endif | 1431 | #endif |
1353 | if ((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50 | 1432 | if (!((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50) |
1354 | || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) | 1433 | && i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) |
1355 | err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, | ||
1356 | I2C_SMBUS_BYTE, &dummy); | ||
1357 | else | ||
1358 | err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_WRITE, 0, | 1434 | err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_WRITE, 0, |
1359 | I2C_SMBUS_QUICK, NULL); | 1435 | I2C_SMBUS_QUICK, NULL); |
1436 | else if (i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) | ||
1437 | err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, | ||
1438 | I2C_SMBUS_BYTE, &dummy); | ||
1439 | else { | ||
1440 | dev_warn(&adap->dev, "No suitable probing method supported\n"); | ||
1441 | err = -EOPNOTSUPP; | ||
1442 | } | ||
1360 | 1443 | ||
1361 | return err >= 0; | 1444 | return err >= 0; |
1362 | } | 1445 | } |
@@ -1437,16 +1520,6 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver) | |||
1437 | if (!(adapter->class & driver->class)) | 1520 | if (!(adapter->class & driver->class)) |
1438 | goto exit_free; | 1521 | goto exit_free; |
1439 | 1522 | ||
1440 | /* Stop here if the bus doesn't support probing */ | ||
1441 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE)) { | ||
1442 | if (address_list[0] == I2C_CLIENT_END) | ||
1443 | goto exit_free; | ||
1444 | |||
1445 | dev_warn(&adapter->dev, "Probing not supported\n"); | ||
1446 | err = -EOPNOTSUPP; | ||
1447 | goto exit_free; | ||
1448 | } | ||
1449 | |||
1450 | for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) { | 1523 | for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) { |
1451 | dev_dbg(&adapter->dev, "found normal entry for adapter %d, " | 1524 | dev_dbg(&adapter->dev, "found normal entry for adapter %d, " |
1452 | "addr 0x%02x\n", adap_id, address_list[i]); | 1525 | "addr 0x%02x\n", adap_id, address_list[i]); |
@@ -1461,18 +1534,23 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver) | |||
1461 | return err; | 1534 | return err; |
1462 | } | 1535 | } |
1463 | 1536 | ||
1537 | int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr) | ||
1538 | { | ||
1539 | return i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, | ||
1540 | I2C_SMBUS_QUICK, NULL) >= 0; | ||
1541 | } | ||
1542 | EXPORT_SYMBOL_GPL(i2c_probe_func_quick_read); | ||
1543 | |||
1464 | struct i2c_client * | 1544 | struct i2c_client * |
1465 | i2c_new_probed_device(struct i2c_adapter *adap, | 1545 | i2c_new_probed_device(struct i2c_adapter *adap, |
1466 | struct i2c_board_info *info, | 1546 | struct i2c_board_info *info, |
1467 | unsigned short const *addr_list) | 1547 | unsigned short const *addr_list, |
1548 | int (*probe)(struct i2c_adapter *, unsigned short addr)) | ||
1468 | { | 1549 | { |
1469 | int i; | 1550 | int i; |
1470 | 1551 | ||
1471 | /* Stop here if the bus doesn't support probing */ | 1552 | if (!probe) |
1472 | if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) { | 1553 | probe = i2c_default_probe; |
1473 | dev_err(&adap->dev, "Probing not supported\n"); | ||
1474 | return NULL; | ||
1475 | } | ||
1476 | 1554 | ||
1477 | for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { | 1555 | for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { |
1478 | /* Check address validity */ | 1556 | /* Check address validity */ |
@@ -1490,7 +1568,7 @@ i2c_new_probed_device(struct i2c_adapter *adap, | |||
1490 | } | 1568 | } |
1491 | 1569 | ||
1492 | /* Test address responsiveness */ | 1570 | /* Test address responsiveness */ |
1493 | if (i2c_default_probe(adap, addr_list[i])) | 1571 | if (probe(adap, addr_list[i])) |
1494 | break; | 1572 | break; |
1495 | } | 1573 | } |
1496 | 1574 | ||
@@ -2002,7 +2080,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, | |||
2002 | flags &= I2C_M_TEN | I2C_CLIENT_PEC; | 2080 | flags &= I2C_M_TEN | I2C_CLIENT_PEC; |
2003 | 2081 | ||
2004 | if (adapter->algo->smbus_xfer) { | 2082 | if (adapter->algo->smbus_xfer) { |
2005 | rt_mutex_lock(&adapter->bus_lock); | 2083 | i2c_lock_adapter(adapter); |
2006 | 2084 | ||
2007 | /* Retry automatically on arbitration loss */ | 2085 | /* Retry automatically on arbitration loss */ |
2008 | orig_jiffies = jiffies; | 2086 | orig_jiffies = jiffies; |
@@ -2016,7 +2094,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, | |||
2016 | orig_jiffies + adapter->timeout)) | 2094 | orig_jiffies + adapter->timeout)) |
2017 | break; | 2095 | break; |
2018 | } | 2096 | } |
2019 | rt_mutex_unlock(&adapter->bus_lock); | 2097 | i2c_unlock_adapter(adapter); |
2020 | } else | 2098 | } else |
2021 | res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, | 2099 | res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, |
2022 | command, protocol, data); | 2100 | command, protocol, data); |
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index e0694e4d86c7..5f3a52d517c3 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c | |||
@@ -167,13 +167,9 @@ static ssize_t i2cdev_write(struct file *file, const char __user *buf, | |||
167 | if (count > 8192) | 167 | if (count > 8192) |
168 | count = 8192; | 168 | count = 8192; |
169 | 169 | ||
170 | tmp = kmalloc(count, GFP_KERNEL); | 170 | tmp = memdup_user(buf, count); |
171 | if (tmp == NULL) | 171 | if (IS_ERR(tmp)) |
172 | return -ENOMEM; | 172 | return PTR_ERR(tmp); |
173 | if (copy_from_user(tmp, buf, count)) { | ||
174 | kfree(tmp); | ||
175 | return -EFAULT; | ||
176 | } | ||
177 | 173 | ||
178 | pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n", | 174 | pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n", |
179 | iminor(file->f_path.dentry->d_inode), count); | 175 | iminor(file->f_path.dentry->d_inode), count); |
@@ -193,12 +189,50 @@ static int i2cdev_check(struct device *dev, void *addrp) | |||
193 | return dev->driver ? -EBUSY : 0; | 189 | return dev->driver ? -EBUSY : 0; |
194 | } | 190 | } |
195 | 191 | ||
192 | /* walk up mux tree */ | ||
193 | static int i2cdev_check_mux_parents(struct i2c_adapter *adapter, int addr) | ||
194 | { | ||
195 | int result; | ||
196 | |||
197 | result = device_for_each_child(&adapter->dev, &addr, i2cdev_check); | ||
198 | |||
199 | if (!result && i2c_parent_is_i2c_adapter(adapter)) | ||
200 | result = i2cdev_check_mux_parents( | ||
201 | to_i2c_adapter(adapter->dev.parent), addr); | ||
202 | |||
203 | return result; | ||
204 | } | ||
205 | |||
206 | /* recurse down mux tree */ | ||
207 | static int i2cdev_check_mux_children(struct device *dev, void *addrp) | ||
208 | { | ||
209 | int result; | ||
210 | |||
211 | if (dev->type == &i2c_adapter_type) | ||
212 | result = device_for_each_child(dev, addrp, | ||
213 | i2cdev_check_mux_children); | ||
214 | else | ||
215 | result = i2cdev_check(dev, addrp); | ||
216 | |||
217 | return result; | ||
218 | } | ||
219 | |||
196 | /* This address checking function differs from the one in i2c-core | 220 | /* This address checking function differs from the one in i2c-core |
197 | in that it considers an address with a registered device, but no | 221 | in that it considers an address with a registered device, but no |
198 | driver bound to it, as NOT busy. */ | 222 | driver bound to it, as NOT busy. */ |
199 | static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr) | 223 | static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr) |
200 | { | 224 | { |
201 | return device_for_each_child(&adapter->dev, &addr, i2cdev_check); | 225 | int result = 0; |
226 | |||
227 | if (i2c_parent_is_i2c_adapter(adapter)) | ||
228 | result = i2cdev_check_mux_parents( | ||
229 | to_i2c_adapter(adapter->dev.parent), addr); | ||
230 | |||
231 | if (!result) | ||
232 | result = device_for_each_child(&adapter->dev, &addr, | ||
233 | i2cdev_check_mux_children); | ||
234 | |||
235 | return result; | ||
202 | } | 236 | } |
203 | 237 | ||
204 | static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client, | 238 | static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client, |
@@ -219,9 +253,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client, | |||
219 | if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) | 253 | if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) |
220 | return -EINVAL; | 254 | return -EINVAL; |
221 | 255 | ||
222 | rdwr_pa = (struct i2c_msg *) | 256 | rdwr_pa = kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), GFP_KERNEL); |
223 | kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), | ||
224 | GFP_KERNEL); | ||
225 | if (!rdwr_pa) | 257 | if (!rdwr_pa) |
226 | return -ENOMEM; | 258 | return -ENOMEM; |
227 | 259 | ||
@@ -247,15 +279,9 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client, | |||
247 | break; | 279 | break; |
248 | } | 280 | } |
249 | data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf; | 281 | data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf; |
250 | rdwr_pa[i].buf = kmalloc(rdwr_pa[i].len, GFP_KERNEL); | 282 | rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len); |
251 | if (rdwr_pa[i].buf == NULL) { | 283 | if (IS_ERR(rdwr_pa[i].buf)) { |
252 | res = -ENOMEM; | 284 | res = PTR_ERR(rdwr_pa[i].buf); |
253 | break; | ||
254 | } | ||
255 | if (copy_from_user(rdwr_pa[i].buf, data_ptrs[i], | ||
256 | rdwr_pa[i].len)) { | ||
257 | ++i; /* Needs to be kfreed too */ | ||
258 | res = -EFAULT; | ||
259 | break; | 285 | break; |
260 | } | 286 | } |
261 | } | 287 | } |
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c new file mode 100644 index 000000000000..d32a4843fc3a --- /dev/null +++ b/drivers/i2c/i2c-mux.c | |||
@@ -0,0 +1,165 @@ | |||
1 | /* | ||
2 | * Multiplexed I2C bus driver. | ||
3 | * | ||
4 | * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it> | ||
5 | * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it> | ||
6 | * Copyright (c) 2009-2010 NSN GmbH & Co KG <michael.lawnick.ext@nsn.com> | ||
7 | * | ||
8 | * Simplifies access to complex multiplexed I2C bus topologies, by presenting | ||
9 | * each multiplexed bus segment as an additional I2C adapter. | ||
10 | * Supports multi-level mux'ing (mux behind a mux). | ||
11 | * | ||
12 | * Based on: | ||
13 | * i2c-virt.c from Kumar Gala <galak@kernel.crashing.org> | ||
14 | * i2c-virtual.c from Ken Harrenstien, Copyright (c) 2004 Google, Inc. | ||
15 | * i2c-virtual.c from Brian Kuschak <bkuschak@yahoo.com> | ||
16 | * | ||
17 | * This file is licensed under the terms of the GNU General Public | ||
18 | * License version 2. This program is licensed "as is" without any | ||
19 | * warranty of any kind, whether express or implied. | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/slab.h> | ||
25 | #include <linux/i2c.h> | ||
26 | #include <linux/i2c-mux.h> | ||
27 | |||
28 | /* multiplexer per channel data */ | ||
29 | struct i2c_mux_priv { | ||
30 | struct i2c_adapter adap; | ||
31 | struct i2c_algorithm algo; | ||
32 | |||
33 | struct i2c_adapter *parent; | ||
34 | void *mux_dev; /* the mux chip/device */ | ||
35 | u32 chan_id; /* the channel id */ | ||
36 | |||
37 | int (*select)(struct i2c_adapter *, void *mux_dev, u32 chan_id); | ||
38 | int (*deselect)(struct i2c_adapter *, void *mux_dev, u32 chan_id); | ||
39 | }; | ||
40 | |||
41 | static int i2c_mux_master_xfer(struct i2c_adapter *adap, | ||
42 | struct i2c_msg msgs[], int num) | ||
43 | { | ||
44 | struct i2c_mux_priv *priv = adap->algo_data; | ||
45 | struct i2c_adapter *parent = priv->parent; | ||
46 | int ret; | ||
47 | |||
48 | /* Switch to the right mux port and perform the transfer. */ | ||
49 | |||
50 | ret = priv->select(parent, priv->mux_dev, priv->chan_id); | ||
51 | if (ret >= 0) | ||
52 | ret = parent->algo->master_xfer(parent, msgs, num); | ||
53 | if (priv->deselect) | ||
54 | priv->deselect(parent, priv->mux_dev, priv->chan_id); | ||
55 | |||
56 | return ret; | ||
57 | } | ||
58 | |||
59 | static int i2c_mux_smbus_xfer(struct i2c_adapter *adap, | ||
60 | u16 addr, unsigned short flags, | ||
61 | char read_write, u8 command, | ||
62 | int size, union i2c_smbus_data *data) | ||
63 | { | ||
64 | struct i2c_mux_priv *priv = adap->algo_data; | ||
65 | struct i2c_adapter *parent = priv->parent; | ||
66 | int ret; | ||
67 | |||
68 | /* Select the right mux port and perform the transfer. */ | ||
69 | |||
70 | ret = priv->select(parent, priv->mux_dev, priv->chan_id); | ||
71 | if (ret >= 0) | ||
72 | ret = parent->algo->smbus_xfer(parent, addr, flags, | ||
73 | read_write, command, size, data); | ||
74 | if (priv->deselect) | ||
75 | priv->deselect(parent, priv->mux_dev, priv->chan_id); | ||
76 | |||
77 | return ret; | ||
78 | } | ||
79 | |||
80 | /* Return the parent's functionality */ | ||
81 | static u32 i2c_mux_functionality(struct i2c_adapter *adap) | ||
82 | { | ||
83 | struct i2c_mux_priv *priv = adap->algo_data; | ||
84 | struct i2c_adapter *parent = priv->parent; | ||
85 | |||
86 | return parent->algo->functionality(parent); | ||
87 | } | ||
88 | |||
89 | struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent, | ||
90 | void *mux_dev, u32 force_nr, u32 chan_id, | ||
91 | int (*select) (struct i2c_adapter *, | ||
92 | void *, u32), | ||
93 | int (*deselect) (struct i2c_adapter *, | ||
94 | void *, u32)) | ||
95 | { | ||
96 | struct i2c_mux_priv *priv; | ||
97 | int ret; | ||
98 | |||
99 | priv = kzalloc(sizeof(struct i2c_mux_priv), GFP_KERNEL); | ||
100 | if (!priv) | ||
101 | return NULL; | ||
102 | |||
103 | /* Set up private adapter data */ | ||
104 | priv->parent = parent; | ||
105 | priv->mux_dev = mux_dev; | ||
106 | priv->chan_id = chan_id; | ||
107 | priv->select = select; | ||
108 | priv->deselect = deselect; | ||
109 | |||
110 | /* Need to do algo dynamically because we don't know ahead | ||
111 | * of time what sort of physical adapter we'll be dealing with. | ||
112 | */ | ||
113 | if (parent->algo->master_xfer) | ||
114 | priv->algo.master_xfer = i2c_mux_master_xfer; | ||
115 | if (parent->algo->smbus_xfer) | ||
116 | priv->algo.smbus_xfer = i2c_mux_smbus_xfer; | ||
117 | priv->algo.functionality = i2c_mux_functionality; | ||
118 | |||
119 | /* Now fill out new adapter structure */ | ||
120 | snprintf(priv->adap.name, sizeof(priv->adap.name), | ||
121 | "i2c-%d-mux (chan_id %d)", i2c_adapter_id(parent), chan_id); | ||
122 | priv->adap.owner = THIS_MODULE; | ||
123 | priv->adap.id = parent->id; | ||
124 | priv->adap.algo = &priv->algo; | ||
125 | priv->adap.algo_data = priv; | ||
126 | priv->adap.dev.parent = &parent->dev; | ||
127 | |||
128 | if (force_nr) { | ||
129 | priv->adap.nr = force_nr; | ||
130 | ret = i2c_add_numbered_adapter(&priv->adap); | ||
131 | } else { | ||
132 | ret = i2c_add_adapter(&priv->adap); | ||
133 | } | ||
134 | if (ret < 0) { | ||
135 | dev_err(&parent->dev, | ||
136 | "failed to add mux-adapter (error=%d)\n", | ||
137 | ret); | ||
138 | kfree(priv); | ||
139 | return NULL; | ||
140 | } | ||
141 | |||
142 | dev_info(&parent->dev, "Added multiplexed i2c bus %d\n", | ||
143 | i2c_adapter_id(&priv->adap)); | ||
144 | |||
145 | return &priv->adap; | ||
146 | } | ||
147 | EXPORT_SYMBOL_GPL(i2c_add_mux_adapter); | ||
148 | |||
149 | int i2c_del_mux_adapter(struct i2c_adapter *adap) | ||
150 | { | ||
151 | struct i2c_mux_priv *priv = adap->algo_data; | ||
152 | int ret; | ||
153 | |||
154 | ret = i2c_del_adapter(adap); | ||
155 | if (ret < 0) | ||
156 | return ret; | ||
157 | kfree(priv); | ||
158 | |||
159 | return 0; | ||
160 | } | ||
161 | EXPORT_SYMBOL_GPL(i2c_del_mux_adapter); | ||
162 | |||
163 | MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); | ||
164 | MODULE_DESCRIPTION("I2C driver for multiplexed I2C busses"); | ||
165 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig new file mode 100644 index 000000000000..4c9a99c4fcb0 --- /dev/null +++ b/drivers/i2c/muxes/Kconfig | |||
@@ -0,0 +1,18 @@ | |||
1 | # | ||
2 | # Multiplexer I2C chip drivers configuration | ||
3 | # | ||
4 | |||
5 | menu "Multiplexer I2C Chip support" | ||
6 | depends on I2C_MUX | ||
7 | |||
8 | config I2C_MUX_PCA954x | ||
9 | tristate "Philips PCA954x I2C Mux/switches" | ||
10 | depends on EXPERIMENTAL | ||
11 | help | ||
12 | If you say yes here you get support for the Philips PCA954x | ||
13 | I2C mux/switch devices. | ||
14 | |||
15 | This driver can also be built as a module. If so, the module | ||
16 | will be called pca954x. | ||
17 | |||
18 | endmenu | ||
diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile new file mode 100644 index 000000000000..bd83b5274815 --- /dev/null +++ b/drivers/i2c/muxes/Makefile | |||
@@ -0,0 +1,8 @@ | |||
1 | # | ||
2 | # Makefile for multiplexer I2C chip drivers. | ||
3 | |||
4 | obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o | ||
5 | |||
6 | ifeq ($(CONFIG_I2C_DEBUG_BUS),y) | ||
7 | EXTRA_CFLAGS += -DDEBUG | ||
8 | endif | ||
diff --git a/drivers/i2c/muxes/pca954x.c b/drivers/i2c/muxes/pca954x.c new file mode 100644 index 000000000000..6f9accf3189d --- /dev/null +++ b/drivers/i2c/muxes/pca954x.c | |||
@@ -0,0 +1,301 @@ | |||
1 | /* | ||
2 | * I2C multiplexer | ||
3 | * | ||
4 | * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it> | ||
5 | * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it> | ||
6 | * | ||
7 | * This module supports the PCA954x series of I2C multiplexer/switch chips | ||
8 | * made by Philips Semiconductors. | ||
9 | * This includes the: | ||
10 | * PCA9540, PCA9542, PCA9543, PCA9544, PCA9545, PCA9546, PCA9547 | ||
11 | * and PCA9548. | ||
12 | * | ||
13 | * These chips are all controlled via the I2C bus itself, and all have a | ||
14 | * single 8-bit register. The upstream "parent" bus fans out to two, | ||
15 | * four, or eight downstream busses or channels; which of these | ||
16 | * are selected is determined by the chip type and register contents. A | ||
17 | * mux can select only one sub-bus at a time; a switch can select any | ||
18 | * combination simultaneously. | ||
19 | * | ||
20 | * Based on: | ||
21 | * pca954x.c from Kumar Gala <galak@kernel.crashing.org> | ||
22 | * Copyright (C) 2006 | ||
23 | * | ||
24 | * Based on: | ||
25 | * pca954x.c from Ken Harrenstien | ||
26 | * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) | ||
27 | * | ||
28 | * Based on: | ||
29 | * i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com> | ||
30 | * and | ||
31 | * pca9540.c from Jean Delvare <khali@linux-fr.org>. | ||
32 | * | ||
33 | * This file is licensed under the terms of the GNU General Public | ||
34 | * License version 2. This program is licensed "as is" without any | ||
35 | * warranty of any kind, whether express or implied. | ||
36 | */ | ||
37 | |||
38 | #include <linux/module.h> | ||
39 | #include <linux/init.h> | ||
40 | #include <linux/slab.h> | ||
41 | #include <linux/device.h> | ||
42 | #include <linux/i2c.h> | ||
43 | #include <linux/i2c-mux.h> | ||
44 | |||
45 | #include <linux/i2c/pca954x.h> | ||
46 | |||
47 | #define PCA954X_MAX_NCHANS 8 | ||
48 | |||
49 | enum pca_type { | ||
50 | pca_9540, | ||
51 | pca_9542, | ||
52 | pca_9543, | ||
53 | pca_9544, | ||
54 | pca_9545, | ||
55 | pca_9546, | ||
56 | pca_9547, | ||
57 | pca_9548, | ||
58 | }; | ||
59 | |||
60 | struct pca954x { | ||
61 | enum pca_type type; | ||
62 | struct i2c_adapter *virt_adaps[PCA954X_MAX_NCHANS]; | ||
63 | |||
64 | u8 last_chan; /* last register value */ | ||
65 | }; | ||
66 | |||
67 | struct chip_desc { | ||
68 | u8 nchans; | ||
69 | u8 enable; /* used for muxes only */ | ||
70 | enum muxtype { | ||
71 | pca954x_ismux = 0, | ||
72 | pca954x_isswi | ||
73 | } muxtype; | ||
74 | }; | ||
75 | |||
76 | /* Provide specs for the PCA954x types we know about */ | ||
77 | static const struct chip_desc chips[] = { | ||
78 | [pca_9540] = { | ||
79 | .nchans = 2, | ||
80 | .enable = 0x4, | ||
81 | .muxtype = pca954x_ismux, | ||
82 | }, | ||
83 | [pca_9543] = { | ||
84 | .nchans = 2, | ||
85 | .muxtype = pca954x_isswi, | ||
86 | }, | ||
87 | [pca_9544] = { | ||
88 | .nchans = 4, | ||
89 | .enable = 0x4, | ||
90 | .muxtype = pca954x_ismux, | ||
91 | }, | ||
92 | [pca_9545] = { | ||
93 | .nchans = 4, | ||
94 | .muxtype = pca954x_isswi, | ||
95 | }, | ||
96 | [pca_9547] = { | ||
97 | .nchans = 8, | ||
98 | .enable = 0x8, | ||
99 | .muxtype = pca954x_ismux, | ||
100 | }, | ||
101 | [pca_9548] = { | ||
102 | .nchans = 8, | ||
103 | .muxtype = pca954x_isswi, | ||
104 | }, | ||
105 | }; | ||
106 | |||
107 | static const struct i2c_device_id pca954x_id[] = { | ||
108 | { "pca9540", pca_9540 }, | ||
109 | { "pca9542", pca_9540 }, | ||
110 | { "pca9543", pca_9543 }, | ||
111 | { "pca9544", pca_9544 }, | ||
112 | { "pca9545", pca_9545 }, | ||
113 | { "pca9546", pca_9545 }, | ||
114 | { "pca9547", pca_9547 }, | ||
115 | { "pca9548", pca_9548 }, | ||
116 | { } | ||
117 | }; | ||
118 | MODULE_DEVICE_TABLE(i2c, pca954x_id); | ||
119 | |||
120 | /* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer() | ||
121 | for this as they will try to lock adapter a second time */ | ||
122 | static int pca954x_reg_write(struct i2c_adapter *adap, | ||
123 | struct i2c_client *client, u8 val) | ||
124 | { | ||
125 | int ret = -ENODEV; | ||
126 | |||
127 | if (adap->algo->master_xfer) { | ||
128 | struct i2c_msg msg; | ||
129 | char buf[1]; | ||
130 | |||
131 | msg.addr = client->addr; | ||
132 | msg.flags = 0; | ||
133 | msg.len = 1; | ||
134 | buf[0] = val; | ||
135 | msg.buf = buf; | ||
136 | ret = adap->algo->master_xfer(adap, &msg, 1); | ||
137 | } else { | ||
138 | union i2c_smbus_data data; | ||
139 | ret = adap->algo->smbus_xfer(adap, client->addr, | ||
140 | client->flags, | ||
141 | I2C_SMBUS_WRITE, | ||
142 | val, I2C_SMBUS_BYTE, &data); | ||
143 | } | ||
144 | |||
145 | return ret; | ||
146 | } | ||
147 | |||
148 | static int pca954x_select_chan(struct i2c_adapter *adap, | ||
149 | void *client, u32 chan) | ||
150 | { | ||
151 | struct pca954x *data = i2c_get_clientdata(client); | ||
152 | const struct chip_desc *chip = &chips[data->type]; | ||
153 | u8 regval; | ||
154 | int ret = 0; | ||
155 | |||
156 | /* we make switches look like muxes, not sure how to be smarter */ | ||
157 | if (chip->muxtype == pca954x_ismux) | ||
158 | regval = chan | chip->enable; | ||
159 | else | ||
160 | regval = 1 << chan; | ||
161 | |||
162 | /* Only select the channel if its different from the last channel */ | ||
163 | if (data->last_chan != regval) { | ||
164 | ret = pca954x_reg_write(adap, client, regval); | ||
165 | data->last_chan = regval; | ||
166 | } | ||
167 | |||
168 | return ret; | ||
169 | } | ||
170 | |||
171 | static int pca954x_deselect_mux(struct i2c_adapter *adap, | ||
172 | void *client, u32 chan) | ||
173 | { | ||
174 | struct pca954x *data = i2c_get_clientdata(client); | ||
175 | |||
176 | /* Deselect active channel */ | ||
177 | data->last_chan = 0; | ||
178 | return pca954x_reg_write(adap, client, data->last_chan); | ||
179 | } | ||
180 | |||
181 | /* | ||
182 | * I2C init/probing/exit functions | ||
183 | */ | ||
184 | static int __devinit pca954x_probe(struct i2c_client *client, | ||
185 | const struct i2c_device_id *id) | ||
186 | { | ||
187 | struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); | ||
188 | struct pca954x_platform_data *pdata = client->dev.platform_data; | ||
189 | int num, force; | ||
190 | struct pca954x *data; | ||
191 | int ret = -ENODEV; | ||
192 | |||
193 | if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) | ||
194 | goto err; | ||
195 | |||
196 | data = kzalloc(sizeof(struct pca954x), GFP_KERNEL); | ||
197 | if (!data) { | ||
198 | ret = -ENOMEM; | ||
199 | goto err; | ||
200 | } | ||
201 | |||
202 | i2c_set_clientdata(client, data); | ||
203 | |||
204 | /* Read the mux register at addr to verify | ||
205 | * that the mux is in fact present. | ||
206 | */ | ||
207 | if (i2c_smbus_read_byte(client) < 0) { | ||
208 | dev_warn(&client->dev, "probe failed\n"); | ||
209 | goto exit_free; | ||
210 | } | ||
211 | |||
212 | data->type = id->driver_data; | ||
213 | data->last_chan = 0; /* force the first selection */ | ||
214 | |||
215 | /* Now create an adapter for each channel */ | ||
216 | for (num = 0; num < chips[data->type].nchans; num++) { | ||
217 | force = 0; /* dynamic adap number */ | ||
218 | if (pdata) { | ||
219 | if (num < pdata->num_modes) | ||
220 | /* force static number */ | ||
221 | force = pdata->modes[num].adap_id; | ||
222 | else | ||
223 | /* discard unconfigured channels */ | ||
224 | break; | ||
225 | } | ||
226 | |||
227 | data->virt_adaps[num] = | ||
228 | i2c_add_mux_adapter(adap, client, | ||
229 | force, num, pca954x_select_chan, | ||
230 | (pdata && pdata->modes[num].deselect_on_exit) | ||
231 | ? pca954x_deselect_mux : NULL); | ||
232 | |||
233 | if (data->virt_adaps[num] == NULL) { | ||
234 | ret = -ENODEV; | ||
235 | dev_err(&client->dev, | ||
236 | "failed to register multiplexed adapter" | ||
237 | " %d as bus %d\n", num, force); | ||
238 | goto virt_reg_failed; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | dev_info(&client->dev, | ||
243 | "registered %d multiplexed busses for I2C %s %s\n", | ||
244 | num, chips[data->type].muxtype == pca954x_ismux | ||
245 | ? "mux" : "switch", client->name); | ||
246 | |||
247 | return 0; | ||
248 | |||
249 | virt_reg_failed: | ||
250 | for (num--; num >= 0; num--) | ||
251 | i2c_del_mux_adapter(data->virt_adaps[num]); | ||
252 | exit_free: | ||
253 | kfree(data); | ||
254 | err: | ||
255 | return ret; | ||
256 | } | ||
257 | |||
258 | static int __devexit pca954x_remove(struct i2c_client *client) | ||
259 | { | ||
260 | struct pca954x *data = i2c_get_clientdata(client); | ||
261 | const struct chip_desc *chip = &chips[data->type]; | ||
262 | int i, err; | ||
263 | |||
264 | for (i = 0; i < chip->nchans; ++i) | ||
265 | if (data->virt_adaps[i]) { | ||
266 | err = i2c_del_mux_adapter(data->virt_adaps[i]); | ||
267 | if (err) | ||
268 | return err; | ||
269 | data->virt_adaps[i] = NULL; | ||
270 | } | ||
271 | |||
272 | kfree(data); | ||
273 | return 0; | ||
274 | } | ||
275 | |||
276 | static struct i2c_driver pca954x_driver = { | ||
277 | .driver = { | ||
278 | .name = "pca954x", | ||
279 | .owner = THIS_MODULE, | ||
280 | }, | ||
281 | .probe = pca954x_probe, | ||
282 | .remove = __devexit_p(pca954x_remove), | ||
283 | .id_table = pca954x_id, | ||
284 | }; | ||
285 | |||
286 | static int __init pca954x_init(void) | ||
287 | { | ||
288 | return i2c_add_driver(&pca954x_driver); | ||
289 | } | ||
290 | |||
291 | static void __exit pca954x_exit(void) | ||
292 | { | ||
293 | i2c_del_driver(&pca954x_driver); | ||
294 | } | ||
295 | |||
296 | module_init(pca954x_init); | ||
297 | module_exit(pca954x_exit); | ||
298 | |||
299 | MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); | ||
300 | MODULE_DESCRIPTION("PCA954x I2C mux/switch driver"); | ||
301 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c index 133f195de1fd..c89f396e4c53 100644 --- a/drivers/macintosh/therm_windtunnel.c +++ b/drivers/macintosh/therm_windtunnel.c | |||
@@ -322,10 +322,10 @@ do_attach( struct i2c_adapter *adapter ) | |||
322 | 322 | ||
323 | memset(&info, 0, sizeof(struct i2c_board_info)); | 323 | memset(&info, 0, sizeof(struct i2c_board_info)); |
324 | strlcpy(info.type, "therm_ds1775", I2C_NAME_SIZE); | 324 | strlcpy(info.type, "therm_ds1775", I2C_NAME_SIZE); |
325 | i2c_new_probed_device(adapter, &info, scan_ds1775); | 325 | i2c_new_probed_device(adapter, &info, scan_ds1775, NULL); |
326 | 326 | ||
327 | strlcpy(info.type, "therm_adm1030", I2C_NAME_SIZE); | 327 | strlcpy(info.type, "therm_adm1030", I2C_NAME_SIZE); |
328 | i2c_new_probed_device(adapter, &info, scan_adm1030); | 328 | i2c_new_probed_device(adapter, &info, scan_adm1030, NULL); |
329 | 329 | ||
330 | if( x.thermostat && x.fan ) { | 330 | if( x.thermostat && x.fan ) { |
331 | x.running = 1; | 331 | x.running = 1; |
diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c index 407fa61e4cda..685d6597ee79 100644 --- a/drivers/media/video/bt8xx/bttv-i2c.c +++ b/drivers/media/video/bt8xx/bttv-i2c.c | |||
@@ -411,7 +411,7 @@ void __devinit init_bttv_i2c_ir(struct bttv *btv) | |||
411 | 411 | ||
412 | memset(&info, 0, sizeof(struct i2c_board_info)); | 412 | memset(&info, 0, sizeof(struct i2c_board_info)); |
413 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); | 413 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); |
414 | i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list); | 414 | i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL); |
415 | } | 415 | } |
416 | } | 416 | } |
417 | 417 | ||
diff --git a/drivers/media/video/cx18/cx18-i2c.c b/drivers/media/video/cx18/cx18-i2c.c index 809f7d37129c..73ce90c2f577 100644 --- a/drivers/media/video/cx18/cx18-i2c.c +++ b/drivers/media/video/cx18/cx18-i2c.c | |||
@@ -117,7 +117,8 @@ static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw, | |||
117 | break; | 117 | break; |
118 | } | 118 | } |
119 | 119 | ||
120 | return i2c_new_probed_device(adap, &info, addr_list) == NULL ? -1 : 0; | 120 | return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ? |
121 | -1 : 0; | ||
121 | } | 122 | } |
122 | 123 | ||
123 | int cx18_i2c_register(struct cx18 *cx, unsigned idx) | 124 | int cx18_i2c_register(struct cx18 *cx, unsigned idx) |
diff --git a/drivers/media/video/cx23885/cx23885-i2c.c b/drivers/media/video/cx23885/cx23885-i2c.c index 1a391486e551..ed3d8f55029b 100644 --- a/drivers/media/video/cx23885/cx23885-i2c.c +++ b/drivers/media/video/cx23885/cx23885-i2c.c | |||
@@ -364,17 +364,10 @@ int cx23885_i2c_register(struct cx23885_i2c *bus) | |||
364 | 364 | ||
365 | memset(&info, 0, sizeof(struct i2c_board_info)); | 365 | memset(&info, 0, sizeof(struct i2c_board_info)); |
366 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); | 366 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); |
367 | /* | 367 | /* Use quick read command for probe, some IR chips don't |
368 | * We can't call i2c_new_probed_device() because it uses | 368 | * support writes */ |
369 | * quick writes for probing and the IR receiver device only | 369 | i2c_new_probed_device(&bus->i2c_adap, &info, addr_list, |
370 | * replies to reads. | 370 | i2c_probe_func_quick_read); |
371 | */ | ||
372 | if (i2c_smbus_xfer(&bus->i2c_adap, addr_list[0], 0, | ||
373 | I2C_SMBUS_READ, 0, I2C_SMBUS_QUICK, | ||
374 | NULL) >= 0) { | ||
375 | info.addr = addr_list[0]; | ||
376 | i2c_new_device(&bus->i2c_adap, &info); | ||
377 | } | ||
378 | } | 371 | } |
379 | 372 | ||
380 | return bus->i2c_rc; | 373 | return bus->i2c_rc; |
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c index 375ad53f7961..82db555b22dd 100644 --- a/drivers/media/video/cx88/cx88-i2c.c +++ b/drivers/media/video/cx88/cx88-i2c.c | |||
@@ -193,24 +193,13 @@ void cx88_i2c_init_ir(struct cx88_core *core) | |||
193 | 0x18, 0x6b, 0x71, | 193 | 0x18, 0x6b, 0x71, |
194 | I2C_CLIENT_END | 194 | I2C_CLIENT_END |
195 | }; | 195 | }; |
196 | const unsigned short *addrp; | ||
197 | 196 | ||
198 | memset(&info, 0, sizeof(struct i2c_board_info)); | 197 | memset(&info, 0, sizeof(struct i2c_board_info)); |
199 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); | 198 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); |
200 | /* | 199 | /* Use quick read command for probe, some IR chips don't |
201 | * We can't call i2c_new_probed_device() because it uses | 200 | * support writes */ |
202 | * quick writes for probing and at least some R receiver | 201 | i2c_new_probed_device(&core->i2c_adap, &info, addr_list, |
203 | * devices only reply to reads. | 202 | i2c_probe_func_quick_read); |
204 | */ | ||
205 | for (addrp = addr_list; *addrp != I2C_CLIENT_END; addrp++) { | ||
206 | if (i2c_smbus_xfer(&core->i2c_adap, *addrp, 0, | ||
207 | I2C_SMBUS_READ, 0, | ||
208 | I2C_SMBUS_QUICK, NULL) >= 0) { | ||
209 | info.addr = *addrp; | ||
210 | i2c_new_device(&core->i2c_adap, &info); | ||
211 | break; | ||
212 | } | ||
213 | } | ||
214 | } | 203 | } |
215 | } | 204 | } |
216 | 205 | ||
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c index ffbe544e30f4..e7efb4bffabd 100644 --- a/drivers/media/video/em28xx/em28xx-cards.c +++ b/drivers/media/video/em28xx/em28xx-cards.c | |||
@@ -2385,7 +2385,7 @@ void em28xx_register_i2c_ir(struct em28xx *dev) | |||
2385 | 2385 | ||
2386 | if (dev->init_data.name) | 2386 | if (dev->init_data.name) |
2387 | info.platform_data = &dev->init_data; | 2387 | info.platform_data = &dev->init_data; |
2388 | i2c_new_probed_device(&dev->i2c_adap, &info, addr_list); | 2388 | i2c_new_probed_device(&dev->i2c_adap, &info, addr_list, NULL); |
2389 | } | 2389 | } |
2390 | 2390 | ||
2391 | void em28xx_card_setup(struct em28xx *dev) | 2391 | void em28xx_card_setup(struct em28xx *dev) |
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c index d391bbdb0b8a..a74fa099c565 100644 --- a/drivers/media/video/ivtv/ivtv-i2c.c +++ b/drivers/media/video/ivtv/ivtv-i2c.c | |||
@@ -183,8 +183,8 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr) | |||
183 | return -1; | 183 | return -1; |
184 | memset(&info, 0, sizeof(struct i2c_board_info)); | 184 | memset(&info, 0, sizeof(struct i2c_board_info)); |
185 | strlcpy(info.type, type, I2C_NAME_SIZE); | 185 | strlcpy(info.type, type, I2C_NAME_SIZE); |
186 | return i2c_new_probed_device(adap, &info, addr_list) == NULL | 186 | return i2c_new_probed_device(adap, &info, addr_list, NULL) |
187 | ? -1 : 0; | 187 | == NULL ? -1 : 0; |
188 | } | 188 | } |
189 | 189 | ||
190 | /* Only allow one IR receiver to be registered per board */ | 190 | /* Only allow one IR receiver to be registered per board */ |
@@ -221,7 +221,8 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr) | |||
221 | info.platform_data = init_data; | 221 | info.platform_data = init_data; |
222 | strlcpy(info.type, type, I2C_NAME_SIZE); | 222 | strlcpy(info.type, type, I2C_NAME_SIZE); |
223 | 223 | ||
224 | return i2c_new_probed_device(adap, &info, addr_list) == NULL ? -1 : 0; | 224 | return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ? |
225 | -1 : 0; | ||
225 | } | 226 | } |
226 | 227 | ||
227 | /* Instantiate the IR receiver device using probing -- undesirable */ | 228 | /* Instantiate the IR receiver device using probing -- undesirable */ |
@@ -249,7 +250,7 @@ struct i2c_client *ivtv_i2c_new_ir_legacy(struct ivtv *itv) | |||
249 | 250 | ||
250 | memset(&info, 0, sizeof(struct i2c_board_info)); | 251 | memset(&info, 0, sizeof(struct i2c_board_info)); |
251 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); | 252 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); |
252 | return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list); | 253 | return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list, NULL); |
253 | } | 254 | } |
254 | 255 | ||
255 | int ivtv_i2c_register(struct ivtv *itv, unsigned idx) | 256 | int ivtv_i2c_register(struct ivtv *itv, unsigned idx) |
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c index 3ce7c64e5789..8ee1179be926 100644 --- a/drivers/media/video/v4l2-common.c +++ b/drivers/media/video/v4l2-common.c | |||
@@ -381,7 +381,8 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, | |||
381 | 381 | ||
382 | /* Create the i2c client */ | 382 | /* Create the i2c client */ |
383 | if (info->addr == 0 && probe_addrs) | 383 | if (info->addr == 0 && probe_addrs) |
384 | client = i2c_new_probed_device(adapter, info, probe_addrs); | 384 | client = i2c_new_probed_device(adapter, info, probe_addrs, |
385 | NULL); | ||
385 | else | 386 | else |
386 | client = i2c_new_device(adapter, info); | 387 | client = i2c_new_device(adapter, info); |
387 | 388 | ||
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c index cd74bbdd007c..653d6a60edb5 100644 --- a/drivers/usb/host/ohci-pnx4008.c +++ b/drivers/usb/host/ohci-pnx4008.c | |||
@@ -329,7 +329,7 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev) | |||
329 | memset(&i2c_info, 0, sizeof(struct i2c_board_info)); | 329 | memset(&i2c_info, 0, sizeof(struct i2c_board_info)); |
330 | strlcpy(i2c_info.type, "isp1301_pnx", I2C_NAME_SIZE); | 330 | strlcpy(i2c_info.type, "isp1301_pnx", I2C_NAME_SIZE); |
331 | isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, | 331 | isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, |
332 | normal_i2c); | 332 | normal_i2c, NULL); |
333 | i2c_put_adapter(i2c_adap); | 333 | i2c_put_adapter(i2c_adap); |
334 | if (!isp1301_i2c_client) { | 334 | if (!isp1301_i2c_client) { |
335 | err("failed to connect I2C to ISP1301 USB Transceiver"); | 335 | err("failed to connect I2C to ISP1301 USB Transceiver"); |
diff --git a/drivers/video/matrox/i2c-matroxfb.c b/drivers/video/matrox/i2c-matroxfb.c index 403b14445a78..0fb280ead3dc 100644 --- a/drivers/video/matrox/i2c-matroxfb.c +++ b/drivers/video/matrox/i2c-matroxfb.c | |||
@@ -191,7 +191,7 @@ static void* i2c_matroxfb_probe(struct matrox_fb_info* minfo) { | |||
191 | }; | 191 | }; |
192 | 192 | ||
193 | i2c_new_probed_device(&m2info->maven.adapter, | 193 | i2c_new_probed_device(&m2info->maven.adapter, |
194 | &maven_info, addr_list); | 194 | &maven_info, addr_list, NULL); |
195 | } | 195 | } |
196 | } | 196 | } |
197 | return m2info; | 197 | return m2info; |
diff --git a/include/linux/i2c-mux.h b/include/linux/i2c-mux.h new file mode 100644 index 000000000000..34536effd652 --- /dev/null +++ b/include/linux/i2c-mux.h | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | * | ||
3 | * i2c-mux.h - functions for the i2c-bus mux support | ||
4 | * | ||
5 | * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it> | ||
6 | * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it> | ||
7 | * Michael Lawnick <michael.lawnick.ext@nsn.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #ifndef _LINUX_I2C_MUX_H | ||
25 | #define _LINUX_I2C_MUX_H | ||
26 | |||
27 | #ifdef __KERNEL__ | ||
28 | |||
29 | /* | ||
30 | * Called to create a i2c bus on a multiplexed bus segment. | ||
31 | * The mux_dev and chan_id parameters are passed to the select | ||
32 | * and deselect callback functions to perform hardware-specific | ||
33 | * mux control. | ||
34 | */ | ||
35 | struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent, | ||
36 | void *mux_dev, u32 force_nr, u32 chan_id, | ||
37 | int (*select) (struct i2c_adapter *, | ||
38 | void *mux_dev, u32 chan_id), | ||
39 | int (*deselect) (struct i2c_adapter *, | ||
40 | void *mux_dev, u32 chan_id)); | ||
41 | |||
42 | int i2c_del_mux_adapter(struct i2c_adapter *adap); | ||
43 | |||
44 | #endif /* __KERNEL__ */ | ||
45 | |||
46 | #endif /* _LINUX_I2C_MUX_H */ | ||
diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 38dd4025aa4e..4bae0b72ed3c 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/of.h> /* for struct device_node */ | 37 | #include <linux/of.h> /* for struct device_node */ |
38 | 38 | ||
39 | extern struct bus_type i2c_bus_type; | 39 | extern struct bus_type i2c_bus_type; |
40 | extern struct device_type i2c_adapter_type; | ||
40 | 41 | ||
41 | /* --- General options ------------------------------------------------ */ | 42 | /* --- General options ------------------------------------------------ */ |
42 | 43 | ||
@@ -284,12 +285,18 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info); | |||
284 | 285 | ||
285 | /* If you don't know the exact address of an I2C device, use this variant | 286 | /* If you don't know the exact address of an I2C device, use this variant |
286 | * instead, which can probe for device presence in a list of possible | 287 | * instead, which can probe for device presence in a list of possible |
287 | * addresses. | 288 | * addresses. The "probe" callback function is optional. If it is provided, |
289 | * it must return 1 on successful probe, 0 otherwise. If it is not provided, | ||
290 | * a default probing method is used. | ||
288 | */ | 291 | */ |
289 | extern struct i2c_client * | 292 | extern struct i2c_client * |
290 | i2c_new_probed_device(struct i2c_adapter *adap, | 293 | i2c_new_probed_device(struct i2c_adapter *adap, |
291 | struct i2c_board_info *info, | 294 | struct i2c_board_info *info, |
292 | unsigned short const *addr_list); | 295 | unsigned short const *addr_list, |
296 | int (*probe)(struct i2c_adapter *, unsigned short addr)); | ||
297 | |||
298 | /* Common custom probe functions */ | ||
299 | extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr); | ||
293 | 300 | ||
294 | /* For devices that use several addresses, use i2c_new_dummy() to make | 301 | /* For devices that use several addresses, use i2c_new_dummy() to make |
295 | * client handles for the extra addresses. | 302 | * client handles for the extra addresses. |
@@ -362,6 +369,7 @@ struct i2c_adapter { | |||
362 | char name[48]; | 369 | char name[48]; |
363 | struct completion dev_released; | 370 | struct completion dev_released; |
364 | 371 | ||
372 | struct mutex userspace_clients_lock; | ||
365 | struct list_head userspace_clients; | 373 | struct list_head userspace_clients; |
366 | }; | 374 | }; |
367 | #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) | 375 | #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) |
@@ -376,23 +384,16 @@ static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data) | |||
376 | dev_set_drvdata(&dev->dev, data); | 384 | dev_set_drvdata(&dev->dev, data); |
377 | } | 385 | } |
378 | 386 | ||
379 | /** | 387 | static inline int i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter) |
380 | * i2c_lock_adapter - Prevent access to an I2C bus segment | ||
381 | * @adapter: Target I2C bus segment | ||
382 | */ | ||
383 | static inline void i2c_lock_adapter(struct i2c_adapter *adapter) | ||
384 | { | 388 | { |
385 | rt_mutex_lock(&adapter->bus_lock); | 389 | return adapter->dev.parent != NULL |
390 | && adapter->dev.parent->bus == &i2c_bus_type | ||
391 | && adapter->dev.parent->type == &i2c_adapter_type; | ||
386 | } | 392 | } |
387 | 393 | ||
388 | /** | 394 | /* Adapter locking functions, exported for shared pin cases */ |
389 | * i2c_unlock_adapter - Reauthorize access to an I2C bus segment | 395 | void i2c_lock_adapter(struct i2c_adapter *); |
390 | * @adapter: Target I2C bus segment | 396 | void i2c_unlock_adapter(struct i2c_adapter *); |
391 | */ | ||
392 | static inline void i2c_unlock_adapter(struct i2c_adapter *adapter) | ||
393 | { | ||
394 | rt_mutex_unlock(&adapter->bus_lock); | ||
395 | } | ||
396 | 397 | ||
397 | /*flags for the client struct: */ | 398 | /*flags for the client struct: */ |
398 | #define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ | 399 | #define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ |
diff --git a/include/linux/i2c/pca954x.h b/include/linux/i2c/pca954x.h new file mode 100644 index 000000000000..28f1f8d5ab1f --- /dev/null +++ b/include/linux/i2c/pca954x.h | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | * | ||
3 | * pca954x.h - I2C multiplexer/switch support | ||
4 | * | ||
5 | * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it> | ||
6 | * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it> | ||
7 | * Michael Lawnick <michael.lawnick.ext@nsn.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | |||
25 | #ifndef _LINUX_I2C_PCA954X_H | ||
26 | #define _LINUX_I2C_PCA954X_H | ||
27 | |||
28 | /* Platform data for the PCA954x I2C multiplexers */ | ||
29 | |||
30 | /* Per channel initialisation data: | ||
31 | * @adap_id: bus number for the adapter. 0 = don't care | ||
32 | * @deselect_on_exit: set this entry to 1, if your H/W needs deselection | ||
33 | * of this channel after transaction. | ||
34 | * | ||
35 | */ | ||
36 | struct pca954x_platform_mode { | ||
37 | int adap_id; | ||
38 | unsigned int deselect_on_exit:1; | ||
39 | }; | ||
40 | |||
41 | /* Per mux/switch data, used with i2c_register_board_info */ | ||
42 | struct pca954x_platform_data { | ||
43 | struct pca954x_platform_mode *modes; | ||
44 | int num_modes; | ||
45 | }; | ||
46 | |||
47 | #endif /* _LINUX_I2C_PCA954X_H */ | ||