Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: I2C bus multiplexer driver pca954x
i2c: Multiplexed I2C bus core support
i2c: Use a separate mutex for userspace client lists
i2c: Make i2c_default_probe self-sufficient
i2c: Drop dummy variable
i2c: Move adapter locking helpers to i2c-core
V4L/DVB: Use custom I2C probing function mechanism
i2c: Add support for custom probe function
i2c-dev: Use memdup_user
i2c-dev: Remove unnecessary kmalloc casts

+805 -116
+1 -1
Documentation/i2c/instantiating-devices
··· 102 102 memset(&i2c_info, 0, sizeof(struct i2c_board_info)); 103 103 strlcpy(i2c_info.name, "isp1301_pnx", I2C_NAME_SIZE); 104 104 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, 105 - normal_i2c); 105 + normal_i2c, NULL); 106 106 i2c_put_adapter(i2c_adap); 107 107 (...) 108 108 }
+13
drivers/i2c/Kconfig
··· 47 47 This support is also available as a module. If so, the module 48 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 63 config I2C_HELPER_AUTO 51 64 bool "Autoselect pertinent helper modules" 52 65 default y
+2 -1
drivers/i2c/Makefile
··· 6 6 obj-$(CONFIG_I2C) += i2c-core.o 7 7 obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o 8 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 12 ifeq ($(CONFIG_I2C_DEBUG_CORE),y) 12 13 EXTRA_CFLAGS += -DDEBUG
+118 -40
drivers/i2c/i2c-core.c
··· 20 20 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>. 21 21 All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> 22 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 27 #include <linux/module.h> 26 28 #include <linux/kernel.h> ··· 425 423 return 0; 426 424 } 427 425 426 + /* walk up mux tree */ 427 + static int i2c_check_mux_parents(struct i2c_adapter *adapter, int addr) 428 + { 429 + int result; 430 + 431 + result = device_for_each_child(&adapter->dev, &addr, 432 + __i2c_check_addr_busy); 433 + 434 + if (!result && i2c_parent_is_i2c_adapter(adapter)) 435 + result = i2c_check_mux_parents( 436 + to_i2c_adapter(adapter->dev.parent), addr); 437 + 438 + return result; 439 + } 440 + 441 + /* recurse down mux tree */ 442 + static int i2c_check_mux_children(struct device *dev, void *addrp) 443 + { 444 + int result; 445 + 446 + if (dev->type == &i2c_adapter_type) 447 + result = device_for_each_child(dev, addrp, 448 + i2c_check_mux_children); 449 + else 450 + result = __i2c_check_addr_busy(dev, addrp); 451 + 452 + return result; 453 + } 454 + 428 455 static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) 429 456 { 430 - return device_for_each_child(&adapter->dev, &addr, 431 - __i2c_check_addr_busy); 457 + int result = 0; 458 + 459 + if (i2c_parent_is_i2c_adapter(adapter)) 460 + result = i2c_check_mux_parents( 461 + to_i2c_adapter(adapter->dev.parent), addr); 462 + 463 + if (!result) 464 + result = device_for_each_child(&adapter->dev, &addr, 465 + i2c_check_mux_children); 466 + 467 + return result; 432 468 } 469 + 470 + /** 471 + * i2c_lock_adapter - Get exclusive access to an I2C bus segment 472 + * @adapter: Target I2C bus segment 473 + */ 474 + void i2c_lock_adapter(struct i2c_adapter *adapter) 475 + { 476 + if (i2c_parent_is_i2c_adapter(adapter)) 477 + i2c_lock_adapter(to_i2c_adapter(adapter->dev.parent)); 478 + else 479 + rt_mutex_lock(&adapter->bus_lock); 480 + } 481 + EXPORT_SYMBOL_GPL(i2c_lock_adapter); 482 + 483 + /** 484 + * i2c_trylock_adapter - Try to get exclusive access to an I2C bus segment 485 + * @adapter: Target I2C bus segment 486 + */ 487 + static int i2c_trylock_adapter(struct i2c_adapter *adapter) 488 + { 489 + if (i2c_parent_is_i2c_adapter(adapter)) 490 + return i2c_trylock_adapter(to_i2c_adapter(adapter->dev.parent)); 491 + else 492 + return rt_mutex_trylock(&adapter->bus_lock); 493 + } 494 + 495 + /** 496 + * i2c_unlock_adapter - Release exclusive access to an I2C bus segment 497 + * @adapter: Target I2C bus segment 498 + */ 499 + void i2c_unlock_adapter(struct i2c_adapter *adapter) 500 + { 501 + if (i2c_parent_is_i2c_adapter(adapter)) 502 + i2c_unlock_adapter(to_i2c_adapter(adapter->dev.parent)); 503 + else 504 + rt_mutex_unlock(&adapter->bus_lock); 505 + } 506 + EXPORT_SYMBOL_GPL(i2c_unlock_adapter); 433 507 434 508 /** 435 509 * i2c_new_device - instantiate an i2c device ··· 711 633 return -EINVAL; 712 634 713 635 /* Keep track of the added device */ 714 - i2c_lock_adapter(adap); 636 + mutex_lock(&adap->userspace_clients_lock); 715 637 list_add_tail(&client->detected, &adap->userspace_clients); 716 - i2c_unlock_adapter(adap); 638 + mutex_unlock(&adap->userspace_clients_lock); 717 639 dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", 718 640 info.type, info.addr); 719 641 ··· 752 674 753 675 /* Make sure the device was added through sysfs */ 754 676 res = -ENOENT; 755 - i2c_lock_adapter(adap); 677 + mutex_lock(&adap->userspace_clients_lock); 756 678 list_for_each_entry_safe(client, next, &adap->userspace_clients, 757 679 detected) { 758 680 if (client->addr == addr) { ··· 765 687 break; 766 688 } 767 689 } 768 - i2c_unlock_adapter(adap); 690 + mutex_unlock(&adap->userspace_clients_lock); 769 691 770 692 if (res < 0) 771 693 dev_err(dev, "%s: Can't find device in list\n", ··· 792 714 NULL 793 715 }; 794 716 795 - static struct device_type i2c_adapter_type = { 717 + struct device_type i2c_adapter_type = { 796 718 .groups = i2c_adapter_attr_groups, 797 719 .release = i2c_adapter_dev_release, 798 720 }; 721 + EXPORT_SYMBOL_GPL(i2c_adapter_type); 799 722 800 723 #ifdef CONFIG_I2C_COMPAT 801 724 static struct class_compat *i2c_adapter_compat_class; ··· 839 760 840 761 static int i2c_register_adapter(struct i2c_adapter *adap) 841 762 { 842 - int res = 0, dummy; 763 + int res = 0; 843 764 844 765 /* Can't register until after driver model init */ 845 766 if (unlikely(WARN_ON(!i2c_bus_type.p))) { ··· 848 769 } 849 770 850 771 rt_mutex_init(&adap->bus_lock); 772 + mutex_init(&adap->userspace_clients_lock); 851 773 INIT_LIST_HEAD(&adap->userspace_clients); 852 774 853 775 /* Set default timeout to 1 second if not already set */ ··· 881 801 882 802 /* Notify drivers */ 883 803 mutex_lock(&core_lock); 884 - dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap, 885 - __process_new_adapter); 804 + bus_for_each_drv(&i2c_bus_type, NULL, adap, __process_new_adapter); 886 805 mutex_unlock(&core_lock); 887 806 888 807 return 0; ··· 1054 975 return res; 1055 976 1056 977 /* Remove devices instantiated from sysfs */ 1057 - i2c_lock_adapter(adap); 978 + mutex_lock(&adap->userspace_clients_lock); 1058 979 list_for_each_entry_safe(client, next, &adap->userspace_clients, 1059 980 detected) { 1060 981 dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name, ··· 1062 983 list_del(&client->detected); 1063 984 i2c_unregister_device(client); 1064 985 } 1065 - i2c_unlock_adapter(adap); 986 + mutex_unlock(&adap->userspace_clients_lock); 1066 987 1067 988 /* Detach any active clients. This can't fail, thus we do not 1068 989 checking the returned value. */ ··· 1317 1238 #endif 1318 1239 1319 1240 if (in_atomic() || irqs_disabled()) { 1320 - ret = rt_mutex_trylock(&adap->bus_lock); 1241 + ret = i2c_trylock_adapter(adap); 1321 1242 if (!ret) 1322 1243 /* I2C activity is ongoing. */ 1323 1244 return -EAGAIN; 1324 1245 } else { 1325 - rt_mutex_lock(&adap->bus_lock); 1246 + i2c_lock_adapter(adap); 1326 1247 } 1327 1248 1328 1249 /* Retry automatically on arbitration loss */ ··· 1334 1255 if (time_after(jiffies, orig_jiffies + adap->timeout)) 1335 1256 break; 1336 1257 } 1337 - rt_mutex_unlock(&adap->bus_lock); 1258 + i2c_unlock_adapter(adap); 1338 1259 1339 1260 return ret; 1340 1261 } else { ··· 1429 1350 I2C_SMBUS_BYTE_DATA, &dummy); 1430 1351 else 1431 1352 #endif 1432 - if ((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50 1433 - || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) 1434 - err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, 1435 - I2C_SMBUS_BYTE, &dummy); 1436 - else 1353 + if (!((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50) 1354 + && i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) 1437 1355 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_WRITE, 0, 1438 1356 I2C_SMBUS_QUICK, NULL); 1357 + else if (i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) 1358 + err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, 1359 + I2C_SMBUS_BYTE, &dummy); 1360 + else { 1361 + dev_warn(&adap->dev, "No suitable probing method supported\n"); 1362 + err = -EOPNOTSUPP; 1363 + } 1439 1364 1440 1365 return err >= 0; 1441 1366 } ··· 1520 1437 if (!(adapter->class & driver->class)) 1521 1438 goto exit_free; 1522 1439 1523 - /* Stop here if the bus doesn't support probing */ 1524 - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE)) { 1525 - if (address_list[0] == I2C_CLIENT_END) 1526 - goto exit_free; 1527 - 1528 - dev_warn(&adapter->dev, "Probing not supported\n"); 1529 - err = -EOPNOTSUPP; 1530 - goto exit_free; 1531 - } 1532 - 1533 1440 for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) { 1534 1441 dev_dbg(&adapter->dev, "found normal entry for adapter %d, " 1535 1442 "addr 0x%02x\n", adap_id, address_list[i]); ··· 1534 1461 return err; 1535 1462 } 1536 1463 1464 + int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr) 1465 + { 1466 + return i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, 1467 + I2C_SMBUS_QUICK, NULL) >= 0; 1468 + } 1469 + EXPORT_SYMBOL_GPL(i2c_probe_func_quick_read); 1470 + 1537 1471 struct i2c_client * 1538 1472 i2c_new_probed_device(struct i2c_adapter *adap, 1539 1473 struct i2c_board_info *info, 1540 - unsigned short const *addr_list) 1474 + unsigned short const *addr_list, 1475 + int (*probe)(struct i2c_adapter *, unsigned short addr)) 1541 1476 { 1542 1477 int i; 1543 1478 1544 - /* Stop here if the bus doesn't support probing */ 1545 - if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) { 1546 - dev_err(&adap->dev, "Probing not supported\n"); 1547 - return NULL; 1548 - } 1479 + if (!probe) 1480 + probe = i2c_default_probe; 1549 1481 1550 1482 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { 1551 1483 /* Check address validity */ ··· 1568 1490 } 1569 1491 1570 1492 /* Test address responsiveness */ 1571 - if (i2c_default_probe(adap, addr_list[i])) 1493 + if (probe(adap, addr_list[i])) 1572 1494 break; 1573 1495 } 1574 1496 ··· 2080 2002 flags &= I2C_M_TEN | I2C_CLIENT_PEC; 2081 2003 2082 2004 if (adapter->algo->smbus_xfer) { 2083 - rt_mutex_lock(&adapter->bus_lock); 2005 + i2c_lock_adapter(adapter); 2084 2006 2085 2007 /* Retry automatically on arbitration loss */ 2086 2008 orig_jiffies = jiffies; ··· 2094 2016 orig_jiffies + adapter->timeout)) 2095 2017 break; 2096 2018 } 2097 - rt_mutex_unlock(&adapter->bus_lock); 2019 + i2c_unlock_adapter(adapter); 2098 2020 } else 2099 2021 res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, 2100 2022 command, protocol, data);
+46 -20
drivers/i2c/i2c-dev.c
··· 167 167 if (count > 8192) 168 168 count = 8192; 169 169 170 - tmp = kmalloc(count, GFP_KERNEL); 171 - if (tmp == NULL) 172 - return -ENOMEM; 173 - if (copy_from_user(tmp, buf, count)) { 174 - kfree(tmp); 175 - return -EFAULT; 176 - } 170 + tmp = memdup_user(buf, count); 171 + if (IS_ERR(tmp)) 172 + return PTR_ERR(tmp); 177 173 178 174 pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n", 179 175 iminor(file->f_path.dentry->d_inode), count); ··· 189 193 return dev->driver ? -EBUSY : 0; 190 194 } 191 195 196 + /* walk up mux tree */ 197 + static int i2cdev_check_mux_parents(struct i2c_adapter *adapter, int addr) 198 + { 199 + int result; 200 + 201 + result = device_for_each_child(&adapter->dev, &addr, i2cdev_check); 202 + 203 + if (!result && i2c_parent_is_i2c_adapter(adapter)) 204 + result = i2cdev_check_mux_parents( 205 + to_i2c_adapter(adapter->dev.parent), addr); 206 + 207 + return result; 208 + } 209 + 210 + /* recurse down mux tree */ 211 + static int i2cdev_check_mux_children(struct device *dev, void *addrp) 212 + { 213 + int result; 214 + 215 + if (dev->type == &i2c_adapter_type) 216 + result = device_for_each_child(dev, addrp, 217 + i2cdev_check_mux_children); 218 + else 219 + result = i2cdev_check(dev, addrp); 220 + 221 + return result; 222 + } 223 + 192 224 /* This address checking function differs from the one in i2c-core 193 225 in that it considers an address with a registered device, but no 194 226 driver bound to it, as NOT busy. */ 195 227 static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr) 196 228 { 197 - return device_for_each_child(&adapter->dev, &addr, i2cdev_check); 229 + int result = 0; 230 + 231 + if (i2c_parent_is_i2c_adapter(adapter)) 232 + result = i2cdev_check_mux_parents( 233 + to_i2c_adapter(adapter->dev.parent), addr); 234 + 235 + if (!result) 236 + result = device_for_each_child(&adapter->dev, &addr, 237 + i2cdev_check_mux_children); 238 + 239 + return result; 198 240 } 199 241 200 242 static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client, ··· 253 219 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) 254 220 return -EINVAL; 255 221 256 - rdwr_pa = (struct i2c_msg *) 257 - kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), 258 - GFP_KERNEL); 222 + rdwr_pa = kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), GFP_KERNEL); 259 223 if (!rdwr_pa) 260 224 return -ENOMEM; 261 225 ··· 279 247 break; 280 248 } 281 249 data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf; 282 - rdwr_pa[i].buf = kmalloc(rdwr_pa[i].len, GFP_KERNEL); 283 - if (rdwr_pa[i].buf == NULL) { 284 - res = -ENOMEM; 285 - break; 286 - } 287 - if (copy_from_user(rdwr_pa[i].buf, data_ptrs[i], 288 - rdwr_pa[i].len)) { 289 - ++i; /* Needs to be kfreed too */ 290 - res = -EFAULT; 250 + rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len); 251 + if (IS_ERR(rdwr_pa[i].buf)) { 252 + res = PTR_ERR(rdwr_pa[i].buf); 291 253 break; 292 254 } 293 255 }
+165
drivers/i2c/i2c-mux.c
··· 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");
+18
drivers/i2c/muxes/Kconfig
··· 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
+8
drivers/i2c/muxes/Makefile
··· 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
+301
drivers/i2c/muxes/pca954x.c
··· 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");
+2 -2
drivers/macintosh/therm_windtunnel.c
··· 322 322 323 323 memset(&info, 0, sizeof(struct i2c_board_info)); 324 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 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 330 if( x.thermostat && x.fan ) { 331 331 x.running = 1;
+1 -1
drivers/media/video/bt8xx/bttv-i2c.c
··· 411 411 412 412 memset(&info, 0, sizeof(struct i2c_board_info)); 413 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
+2 -1
drivers/media/video/cx18/cx18-i2c.c
··· 117 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 124 int cx18_i2c_register(struct cx18 *cx, unsigned idx)
+4 -11
drivers/media/video/cx23885/cx23885-i2c.c
··· 364 364 365 365 memset(&info, 0, sizeof(struct i2c_board_info)); 366 366 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 367 - /* 368 - * We can't call i2c_new_probed_device() because it uses 369 - * quick writes for probing and the IR receiver device only 370 - * replies to reads. 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 - } 367 + /* Use quick read command for probe, some IR chips don't 368 + * support writes */ 369 + i2c_new_probed_device(&bus->i2c_adap, &info, addr_list, 370 + i2c_probe_func_quick_read); 378 371 } 379 372 380 373 return bus->i2c_rc;
+4 -15
drivers/media/video/cx88/cx88-i2c.c
··· 193 193 0x18, 0x6b, 0x71, 194 194 I2C_CLIENT_END 195 195 }; 196 - const unsigned short *addrp; 197 196 198 197 memset(&info, 0, sizeof(struct i2c_board_info)); 199 198 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 200 - /* 201 - * We can't call i2c_new_probed_device() because it uses 202 - * quick writes for probing and at least some R receiver 203 - * devices only reply to reads. 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 - } 199 + /* Use quick read command for probe, some IR chips don't 200 + * support writes */ 201 + i2c_new_probed_device(&core->i2c_adap, &info, addr_list, 202 + i2c_probe_func_quick_read); 214 203 } 215 204 } 216 205
+1 -1
drivers/media/video/em28xx/em28xx-cards.c
··· 2385 2385 2386 2386 if (dev->init_data.name) 2387 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 2391 void em28xx_card_setup(struct em28xx *dev)
+5 -4
drivers/media/video/ivtv/ivtv-i2c.c
··· 183 183 return -1; 184 184 memset(&info, 0, sizeof(struct i2c_board_info)); 185 185 strlcpy(info.type, type, I2C_NAME_SIZE); 186 - return i2c_new_probed_device(adap, &info, addr_list) == NULL 187 - ? -1 : 0; 186 + return i2c_new_probed_device(adap, &info, addr_list, NULL) 187 + == NULL ? -1 : 0; 188 188 } 189 189 190 190 /* Only allow one IR receiver to be registered per board */ ··· 221 221 info.platform_data = init_data; 222 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 228 /* Instantiate the IR receiver device using probing -- undesirable */ ··· 250 249 251 250 memset(&info, 0, sizeof(struct i2c_board_info)); 252 251 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 253 - return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list); 252 + return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list, NULL); 254 253 } 255 254 256 255 int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
+2 -1
drivers/media/video/v4l2-common.c
··· 381 381 382 382 /* Create the i2c client */ 383 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 386 else 386 387 client = i2c_new_device(adapter, info); 387 388
+1 -1
drivers/usb/host/ohci-pnx4008.c
··· 329 329 memset(&i2c_info, 0, sizeof(struct i2c_board_info)); 330 330 strlcpy(i2c_info.type, "isp1301_pnx", I2C_NAME_SIZE); 331 331 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, 332 - normal_i2c); 332 + normal_i2c, NULL); 333 333 i2c_put_adapter(i2c_adap); 334 334 if (!isp1301_i2c_client) { 335 335 err("failed to connect I2C to ISP1301 USB Transceiver");
+1 -1
drivers/video/matrox/i2c-matroxfb.c
··· 191 191 }; 192 192 193 193 i2c_new_probed_device(&m2info->maven.adapter, 194 - &maven_info, addr_list); 194 + &maven_info, addr_list, NULL); 195 195 } 196 196 } 197 197 return m2info;
+46
include/linux/i2c-mux.h
··· 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 */
+17 -16
include/linux/i2c.h
··· 37 37 #include <linux/of.h> /* for struct device_node */ 38 38 39 39 extern struct bus_type i2c_bus_type; 40 + extern struct device_type i2c_adapter_type; 40 41 41 42 /* --- General options ------------------------------------------------ */ 42 43 ··· 285 284 286 285 /* If you don't know the exact address of an I2C device, use this variant 287 286 * instead, which can probe for device presence in a list of possible 288 - * addresses. 287 + * addresses. The "probe" callback function is optional. If it is provided, 288 + * it must return 1 on successful probe, 0 otherwise. If it is not provided, 289 + * a default probing method is used. 289 290 */ 290 291 extern struct i2c_client * 291 292 i2c_new_probed_device(struct i2c_adapter *adap, 292 293 struct i2c_board_info *info, 293 - unsigned short const *addr_list); 294 + unsigned short const *addr_list, 295 + int (*probe)(struct i2c_adapter *, unsigned short addr)); 296 + 297 + /* Common custom probe functions */ 298 + extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr); 294 299 295 300 /* For devices that use several addresses, use i2c_new_dummy() to make 296 301 * client handles for the extra addresses. ··· 369 362 char name[48]; 370 363 struct completion dev_released; 371 364 365 + struct mutex userspace_clients_lock; 372 366 struct list_head userspace_clients; 373 367 }; 374 368 #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) ··· 384 376 dev_set_drvdata(&dev->dev, data); 385 377 } 386 378 387 - /** 388 - * i2c_lock_adapter - Prevent access to an I2C bus segment 389 - * @adapter: Target I2C bus segment 390 - */ 391 - static inline void i2c_lock_adapter(struct i2c_adapter *adapter) 379 + static inline int i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter) 392 380 { 393 - rt_mutex_lock(&adapter->bus_lock); 381 + return adapter->dev.parent != NULL 382 + && adapter->dev.parent->bus == &i2c_bus_type 383 + && adapter->dev.parent->type == &i2c_adapter_type; 394 384 } 395 385 396 - /** 397 - * i2c_unlock_adapter - Reauthorize access to an I2C bus segment 398 - * @adapter: Target I2C bus segment 399 - */ 400 - static inline void i2c_unlock_adapter(struct i2c_adapter *adapter) 401 - { 402 - rt_mutex_unlock(&adapter->bus_lock); 403 - } 386 + /* Adapter locking functions, exported for shared pin cases */ 387 + void i2c_lock_adapter(struct i2c_adapter *); 388 + void i2c_unlock_adapter(struct i2c_adapter *); 404 389 405 390 /*flags for the client struct: */ 406 391 #define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
+47
include/linux/i2c/pca954x.h
··· 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 */