diff options
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/busses/Kconfig | 40 | ||||
-rw-r--r-- | drivers/i2c/busses/Makefile | 6 | ||||
-rw-r--r-- | drivers/i2c/i2c-core.c | 179 | ||||
-rw-r--r-- | drivers/i2c/i2c-smbus.c | 1 |
4 files changed, 133 insertions, 93 deletions
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 87ab0568bb0e..bceafbfa7268 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig | |||
@@ -475,6 +475,26 @@ config I2C_PASEMI | |||
475 | help | 475 | help |
476 | Supports the PA Semi PWRficient on-chip SMBus interfaces. | 476 | Supports the PA Semi PWRficient on-chip SMBus interfaces. |
477 | 477 | ||
478 | config I2C_PCA_PLATFORM | ||
479 | tristate "PCA9564/PCA9665 as platform device" | ||
480 | select I2C_ALGOPCA | ||
481 | default n | ||
482 | help | ||
483 | This driver supports a memory mapped Philips PCA9564/PCA9665 | ||
484 | parallel bus to I2C bus controller. | ||
485 | |||
486 | This driver can also be built as a module. If so, the module | ||
487 | will be called i2c-pca-platform. | ||
488 | |||
489 | config I2C_PMCMSP | ||
490 | tristate "PMC MSP I2C TWI Controller" | ||
491 | depends on PMC_MSP | ||
492 | help | ||
493 | This driver supports the PMC TWI controller on MSP devices. | ||
494 | |||
495 | This driver can also be built as module. If so, the module | ||
496 | will be called i2c-pmcmsp. | ||
497 | |||
478 | config I2C_PNX | 498 | config I2C_PNX |
479 | tristate "I2C bus support for Philips PNX targets" | 499 | tristate "I2C bus support for Philips PNX targets" |
480 | depends on ARCH_PNX4008 | 500 | depends on ARCH_PNX4008 |
@@ -711,26 +731,6 @@ config I2C_PCA_ISA | |||
711 | delays when I2C/SMBus chip drivers are loaded (e.g. at boot | 731 | delays when I2C/SMBus chip drivers are loaded (e.g. at boot |
712 | time). If unsure, say N. | 732 | time). If unsure, say N. |
713 | 733 | ||
714 | config I2C_PCA_PLATFORM | ||
715 | tristate "PCA9564/PCA9665 as platform device" | ||
716 | select I2C_ALGOPCA | ||
717 | default n | ||
718 | help | ||
719 | This driver supports a memory mapped Philips PCA9564/PCA9665 | ||
720 | parallel bus to I2C bus controller. | ||
721 | |||
722 | This driver can also be built as a module. If so, the module | ||
723 | will be called i2c-pca-platform. | ||
724 | |||
725 | config I2C_PMCMSP | ||
726 | tristate "PMC MSP I2C TWI Controller" | ||
727 | depends on PMC_MSP | ||
728 | help | ||
729 | This driver supports the PMC TWI controller on MSP devices. | ||
730 | |||
731 | This driver can also be built as module. If so, the module | ||
732 | will be called i2c-pmcmsp. | ||
733 | |||
734 | config I2C_SIBYTE | 734 | config I2C_SIBYTE |
735 | tristate "SiByte SMBus interface" | 735 | tristate "SiByte SMBus interface" |
736 | depends on SIBYTE_SB1xxx_SOC | 736 | depends on SIBYTE_SB1xxx_SOC |
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 097236f631e8..936880bd1dc5 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile | |||
@@ -27,7 +27,7 @@ obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o | |||
27 | obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o | 27 | obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o |
28 | obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o | 28 | obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o |
29 | 29 | ||
30 | # Embebbed system I2C/SMBus host controller drivers | 30 | # Embedded system I2C/SMBus host controller drivers |
31 | obj-$(CONFIG_I2C_AT91) += i2c-at91.o | 31 | obj-$(CONFIG_I2C_AT91) += i2c-at91.o |
32 | obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o | 32 | obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o |
33 | obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o | 33 | obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o |
@@ -46,6 +46,8 @@ obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o | |||
46 | obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o | 46 | obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o |
47 | obj-$(CONFIG_I2C_OMAP) += i2c-omap.o | 47 | obj-$(CONFIG_I2C_OMAP) += i2c-omap.o |
48 | obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o | 48 | obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o |
49 | obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o | ||
50 | obj-$(CONFIG_I2C_PMCMSP) += i2c-pmcmsp.o | ||
49 | obj-$(CONFIG_I2C_PNX) += i2c-pnx.o | 51 | obj-$(CONFIG_I2C_PNX) += i2c-pnx.o |
50 | obj-$(CONFIG_I2C_PXA) += i2c-pxa.o | 52 | obj-$(CONFIG_I2C_PXA) += i2c-pxa.o |
51 | obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o | 53 | obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o |
@@ -68,8 +70,6 @@ obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o | |||
68 | obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o | 70 | obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o |
69 | obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o | 71 | obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o |
70 | obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o | 72 | obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o |
71 | obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o | ||
72 | obj-$(CONFIG_I2C_PMCMSP) += i2c-pmcmsp.o | ||
73 | obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o | 73 | obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o |
74 | obj-$(CONFIG_I2C_STUB) += i2c-stub.o | 74 | obj-$(CONFIG_I2C_STUB) += i2c-stub.o |
75 | obj-$(CONFIG_SCx200_ACB) += scx200_acb.o | 75 | obj-$(CONFIG_SCx200_ACB) += scx200_acb.o |
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index e0f833cca3f1..1cca2631e5b3 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -47,7 +47,6 @@ static DEFINE_MUTEX(core_lock); | |||
47 | static DEFINE_IDR(i2c_adapter_idr); | 47 | static DEFINE_IDR(i2c_adapter_idr); |
48 | 48 | ||
49 | static struct device_type i2c_client_type; | 49 | static struct device_type i2c_client_type; |
50 | static int i2c_check_addr(struct i2c_adapter *adapter, int addr); | ||
51 | static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); | 50 | static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver); |
52 | 51 | ||
53 | /* ------------------------------------------------------------------------- */ | 52 | /* ------------------------------------------------------------------------- */ |
@@ -371,6 +370,59 @@ struct i2c_client *i2c_verify_client(struct device *dev) | |||
371 | EXPORT_SYMBOL(i2c_verify_client); | 370 | EXPORT_SYMBOL(i2c_verify_client); |
372 | 371 | ||
373 | 372 | ||
373 | /* This is a permissive address validity check, I2C address map constraints | ||
374 | * are purposedly not enforced, except for the general call address. */ | ||
375 | static int i2c_check_client_addr_validity(const struct i2c_client *client) | ||
376 | { | ||
377 | if (client->flags & I2C_CLIENT_TEN) { | ||
378 | /* 10-bit address, all values are valid */ | ||
379 | if (client->addr > 0x3ff) | ||
380 | return -EINVAL; | ||
381 | } else { | ||
382 | /* 7-bit address, reject the general call address */ | ||
383 | if (client->addr == 0x00 || client->addr > 0x7f) | ||
384 | return -EINVAL; | ||
385 | } | ||
386 | return 0; | ||
387 | } | ||
388 | |||
389 | /* And this is a strict address validity check, used when probing. If a | ||
390 | * device uses a reserved address, then it shouldn't be probed. 7-bit | ||
391 | * addressing is assumed, 10-bit address devices are rare and should be | ||
392 | * explicitly enumerated. */ | ||
393 | static int i2c_check_addr_validity(unsigned short addr) | ||
394 | { | ||
395 | /* | ||
396 | * Reserved addresses per I2C specification: | ||
397 | * 0x00 General call address / START byte | ||
398 | * 0x01 CBUS address | ||
399 | * 0x02 Reserved for different bus format | ||
400 | * 0x03 Reserved for future purposes | ||
401 | * 0x04-0x07 Hs-mode master code | ||
402 | * 0x78-0x7b 10-bit slave addressing | ||
403 | * 0x7c-0x7f Reserved for future purposes | ||
404 | */ | ||
405 | if (addr < 0x08 || addr > 0x77) | ||
406 | return -EINVAL; | ||
407 | return 0; | ||
408 | } | ||
409 | |||
410 | static int __i2c_check_addr_busy(struct device *dev, void *addrp) | ||
411 | { | ||
412 | struct i2c_client *client = i2c_verify_client(dev); | ||
413 | int addr = *(int *)addrp; | ||
414 | |||
415 | if (client && client->addr == addr) | ||
416 | return -EBUSY; | ||
417 | return 0; | ||
418 | } | ||
419 | |||
420 | static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) | ||
421 | { | ||
422 | return device_for_each_child(&adapter->dev, &addr, | ||
423 | __i2c_check_addr_busy); | ||
424 | } | ||
425 | |||
374 | /** | 426 | /** |
375 | * i2c_new_device - instantiate an i2c device | 427 | * i2c_new_device - instantiate an i2c device |
376 | * @adap: the adapter managing the device | 428 | * @adap: the adapter managing the device |
@@ -410,8 +462,16 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) | |||
410 | 462 | ||
411 | strlcpy(client->name, info->type, sizeof(client->name)); | 463 | strlcpy(client->name, info->type, sizeof(client->name)); |
412 | 464 | ||
465 | /* Check for address validity */ | ||
466 | status = i2c_check_client_addr_validity(client); | ||
467 | if (status) { | ||
468 | dev_err(&adap->dev, "Invalid %d-bit I2C address 0x%02hx\n", | ||
469 | client->flags & I2C_CLIENT_TEN ? 10 : 7, client->addr); | ||
470 | goto out_err_silent; | ||
471 | } | ||
472 | |||
413 | /* Check for address business */ | 473 | /* Check for address business */ |
414 | status = i2c_check_addr(adap, client->addr); | 474 | status = i2c_check_addr_busy(adap, client->addr); |
415 | if (status) | 475 | if (status) |
416 | goto out_err; | 476 | goto out_err; |
417 | 477 | ||
@@ -436,6 +496,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) | |||
436 | out_err: | 496 | out_err: |
437 | dev_err(&adap->dev, "Failed to register i2c client %s at 0x%02x " | 497 | dev_err(&adap->dev, "Failed to register i2c client %s at 0x%02x " |
438 | "(%d)\n", client->name, client->addr, status); | 498 | "(%d)\n", client->name, client->addr, status); |
499 | out_err_silent: | ||
439 | kfree(client); | 500 | kfree(client); |
440 | return NULL; | 501 | return NULL; |
441 | } | 502 | } |
@@ -561,15 +622,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr, | |||
561 | return -EINVAL; | 622 | return -EINVAL; |
562 | } | 623 | } |
563 | 624 | ||
564 | if (info.addr < 0x03 || info.addr > 0x77) { | ||
565 | dev_err(dev, "%s: Invalid I2C address 0x%hx\n", "new_device", | ||
566 | info.addr); | ||
567 | return -EINVAL; | ||
568 | } | ||
569 | |||
570 | client = i2c_new_device(adap, &info); | 625 | client = i2c_new_device(adap, &info); |
571 | if (!client) | 626 | if (!client) |
572 | return -EEXIST; | 627 | return -EINVAL; |
573 | 628 | ||
574 | /* Keep track of the added device */ | 629 | /* Keep track of the added device */ |
575 | i2c_lock_adapter(adap); | 630 | i2c_lock_adapter(adap); |
@@ -1024,21 +1079,6 @@ EXPORT_SYMBOL(i2c_del_driver); | |||
1024 | 1079 | ||
1025 | /* ------------------------------------------------------------------------- */ | 1080 | /* ------------------------------------------------------------------------- */ |
1026 | 1081 | ||
1027 | static int __i2c_check_addr(struct device *dev, void *addrp) | ||
1028 | { | ||
1029 | struct i2c_client *client = i2c_verify_client(dev); | ||
1030 | int addr = *(int *)addrp; | ||
1031 | |||
1032 | if (client && client->addr == addr) | ||
1033 | return -EBUSY; | ||
1034 | return 0; | ||
1035 | } | ||
1036 | |||
1037 | static int i2c_check_addr(struct i2c_adapter *adapter, int addr) | ||
1038 | { | ||
1039 | return device_for_each_child(&adapter->dev, &addr, __i2c_check_addr); | ||
1040 | } | ||
1041 | |||
1042 | /** | 1082 | /** |
1043 | * i2c_use_client - increments the reference count of the i2c client structure | 1083 | * i2c_use_client - increments the reference count of the i2c client structure |
1044 | * @client: the client being referenced | 1084 | * @client: the client being referenced |
@@ -1277,6 +1317,41 @@ EXPORT_SYMBOL(i2c_master_recv); | |||
1277 | * ---------------------------------------------------- | 1317 | * ---------------------------------------------------- |
1278 | */ | 1318 | */ |
1279 | 1319 | ||
1320 | /* | ||
1321 | * Legacy default probe function, mostly relevant for SMBus. The default | ||
1322 | * probe method is a quick write, but it is known to corrupt the 24RF08 | ||
1323 | * EEPROMs due to a state machine bug, and could also irreversibly | ||
1324 | * write-protect some EEPROMs, so for address ranges 0x30-0x37 and 0x50-0x5f, | ||
1325 | * we use a short byte read instead. Also, some bus drivers don't implement | ||
1326 | * quick write, so we fallback to a byte read in that case too. | ||
1327 | * On x86, there is another special case for FSC hardware monitoring chips, | ||
1328 | * which want regular byte reads (address 0x73.) Fortunately, these are the | ||
1329 | * only known chips using this I2C address on PC hardware. | ||
1330 | * Returns 1 if probe succeeded, 0 if not. | ||
1331 | */ | ||
1332 | static int i2c_default_probe(struct i2c_adapter *adap, unsigned short addr) | ||
1333 | { | ||
1334 | int err; | ||
1335 | union i2c_smbus_data dummy; | ||
1336 | |||
1337 | #ifdef CONFIG_X86 | ||
1338 | if (addr == 0x73 && (adap->class & I2C_CLASS_HWMON) | ||
1339 | && i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE_DATA)) | ||
1340 | err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, | ||
1341 | I2C_SMBUS_BYTE_DATA, &dummy); | ||
1342 | else | ||
1343 | #endif | ||
1344 | if ((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50 | ||
1345 | || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) | ||
1346 | err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, | ||
1347 | I2C_SMBUS_BYTE, &dummy); | ||
1348 | else | ||
1349 | err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_WRITE, 0, | ||
1350 | I2C_SMBUS_QUICK, NULL); | ||
1351 | |||
1352 | return err >= 0; | ||
1353 | } | ||
1354 | |||
1280 | static int i2c_detect_address(struct i2c_client *temp_client, | 1355 | static int i2c_detect_address(struct i2c_client *temp_client, |
1281 | struct i2c_driver *driver) | 1356 | struct i2c_driver *driver) |
1282 | { | 1357 | { |
@@ -1286,34 +1361,20 @@ static int i2c_detect_address(struct i2c_client *temp_client, | |||
1286 | int err; | 1361 | int err; |
1287 | 1362 | ||
1288 | /* Make sure the address is valid */ | 1363 | /* Make sure the address is valid */ |
1289 | if (addr < 0x03 || addr > 0x77) { | 1364 | err = i2c_check_addr_validity(addr); |
1365 | if (err) { | ||
1290 | dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n", | 1366 | dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n", |
1291 | addr); | 1367 | addr); |
1292 | return -EINVAL; | 1368 | return err; |
1293 | } | 1369 | } |
1294 | 1370 | ||
1295 | /* Skip if already in use */ | 1371 | /* Skip if already in use */ |
1296 | if (i2c_check_addr(adapter, addr)) | 1372 | if (i2c_check_addr_busy(adapter, addr)) |
1297 | return 0; | 1373 | return 0; |
1298 | 1374 | ||
1299 | /* Make sure there is something at this address */ | 1375 | /* Make sure there is something at this address */ |
1300 | if (addr == 0x73 && (adapter->class & I2C_CLASS_HWMON)) { | 1376 | if (!i2c_default_probe(adapter, addr)) |
1301 | /* Special probe for FSC hwmon chips */ | 1377 | return 0; |
1302 | union i2c_smbus_data dummy; | ||
1303 | |||
1304 | if (i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_READ, 0, | ||
1305 | I2C_SMBUS_BYTE_DATA, &dummy) < 0) | ||
1306 | return 0; | ||
1307 | } else { | ||
1308 | if (i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_WRITE, 0, | ||
1309 | I2C_SMBUS_QUICK, NULL) < 0) | ||
1310 | return 0; | ||
1311 | |||
1312 | /* Prevent 24RF08 corruption */ | ||
1313 | if ((addr & ~0x0f) == 0x50) | ||
1314 | i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_WRITE, 0, | ||
1315 | I2C_SMBUS_QUICK, NULL); | ||
1316 | } | ||
1317 | 1378 | ||
1318 | /* Finally call the custom detection function */ | 1379 | /* Finally call the custom detection function */ |
1319 | memset(&info, 0, sizeof(struct i2c_board_info)); | 1380 | memset(&info, 0, sizeof(struct i2c_board_info)); |
@@ -1407,42 +1468,22 @@ i2c_new_probed_device(struct i2c_adapter *adap, | |||
1407 | 1468 | ||
1408 | for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { | 1469 | for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { |
1409 | /* Check address validity */ | 1470 | /* Check address validity */ |
1410 | if (addr_list[i] < 0x03 || addr_list[i] > 0x77) { | 1471 | if (i2c_check_addr_validity(addr_list[i]) < 0) { |
1411 | dev_warn(&adap->dev, "Invalid 7-bit address " | 1472 | dev_warn(&adap->dev, "Invalid 7-bit address " |
1412 | "0x%02x\n", addr_list[i]); | 1473 | "0x%02x\n", addr_list[i]); |
1413 | continue; | 1474 | continue; |
1414 | } | 1475 | } |
1415 | 1476 | ||
1416 | /* Check address availability */ | 1477 | /* Check address availability */ |
1417 | if (i2c_check_addr(adap, addr_list[i])) { | 1478 | if (i2c_check_addr_busy(adap, addr_list[i])) { |
1418 | dev_dbg(&adap->dev, "Address 0x%02x already in " | 1479 | dev_dbg(&adap->dev, "Address 0x%02x already in " |
1419 | "use, not probing\n", addr_list[i]); | 1480 | "use, not probing\n", addr_list[i]); |
1420 | continue; | 1481 | continue; |
1421 | } | 1482 | } |
1422 | 1483 | ||
1423 | /* Test address responsiveness | 1484 | /* Test address responsiveness */ |
1424 | The default probe method is a quick write, but it is known | 1485 | if (i2c_default_probe(adap, addr_list[i])) |
1425 | to corrupt the 24RF08 EEPROMs due to a state machine bug, | 1486 | break; |
1426 | and could also irreversibly write-protect some EEPROMs, so | ||
1427 | for address ranges 0x30-0x37 and 0x50-0x5f, we use a byte | ||
1428 | read instead. Also, some bus drivers don't implement | ||
1429 | quick write, so we fallback to a byte read it that case | ||
1430 | too. */ | ||
1431 | if ((addr_list[i] & ~0x07) == 0x30 | ||
1432 | || (addr_list[i] & ~0x0f) == 0x50 | ||
1433 | || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) { | ||
1434 | union i2c_smbus_data data; | ||
1435 | |||
1436 | if (i2c_smbus_xfer(adap, addr_list[i], 0, | ||
1437 | I2C_SMBUS_READ, 0, | ||
1438 | I2C_SMBUS_BYTE, &data) >= 0) | ||
1439 | break; | ||
1440 | } else { | ||
1441 | if (i2c_smbus_xfer(adap, addr_list[i], 0, | ||
1442 | I2C_SMBUS_WRITE, 0, | ||
1443 | I2C_SMBUS_QUICK, NULL) >= 0) | ||
1444 | break; | ||
1445 | } | ||
1446 | } | 1487 | } |
1447 | 1488 | ||
1448 | if (addr_list[i] == I2C_CLIENT_END) { | 1489 | if (addr_list[i] == I2C_CLIENT_END) { |
diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c index a24e0bfe9201..f61ccc1e5ea3 100644 --- a/drivers/i2c/i2c-smbus.c +++ b/drivers/i2c/i2c-smbus.c | |||
@@ -173,7 +173,6 @@ static int smbalert_remove(struct i2c_client *ara) | |||
173 | 173 | ||
174 | cancel_work_sync(&alert->alert); | 174 | cancel_work_sync(&alert->alert); |
175 | 175 | ||
176 | i2c_set_clientdata(ara, NULL); | ||
177 | kfree(alert); | 176 | kfree(alert); |
178 | return 0; | 177 | return 0; |
179 | } | 178 | } |