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

i2c: Document reserved I2C addresses

Move strict I2C address validity check to a single function, and
document the reserved I2C addresses there.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Hans Verkuil <hverkuil@xs4all.nl>

+25 -3
+25 -3
drivers/i2c/i2c-core.c
··· 387 387 return 0; 388 388 } 389 389 390 + /* And this is a strict address validity check, used when probing. If a 391 + * device uses a reserved address, then it shouldn't be probed. 7-bit 392 + * addressing is assumed, 10-bit address devices are rare and should be 393 + * explicitly enumerated. */ 394 + static int i2c_check_addr_validity(unsigned short addr) 395 + { 396 + /* 397 + * Reserved addresses per I2C specification: 398 + * 0x00 General call address / START byte 399 + * 0x01 CBUS address 400 + * 0x02 Reserved for different bus format 401 + * 0x03 Reserved for future purposes 402 + * 0x04-0x07 Hs-mode master code 403 + * 0x78-0x7b 10-bit slave addressing 404 + * 0x7c-0x7f Reserved for future purposes 405 + */ 406 + if (addr < 0x08 || addr > 0x77) 407 + return -EINVAL; 408 + return 0; 409 + } 410 + 390 411 /** 391 412 * i2c_new_device - instantiate an i2c device 392 413 * @adap: the adapter managing the device ··· 1361 1340 int err; 1362 1341 1363 1342 /* Make sure the address is valid */ 1364 - if (addr < 0x03 || addr > 0x77) { 1343 + err = i2c_check_addr_validity(addr); 1344 + if (err) { 1365 1345 dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n", 1366 1346 addr); 1367 - return -EINVAL; 1347 + return err; 1368 1348 } 1369 1349 1370 1350 /* Skip if already in use */ ··· 1468 1446 1469 1447 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { 1470 1448 /* Check address validity */ 1471 - if (addr_list[i] < 0x03 || addr_list[i] > 0x77) { 1449 + if (i2c_check_addr_validity(addr_list[i]) < 0) { 1472 1450 dev_warn(&adap->dev, "Invalid 7-bit address " 1473 1451 "0x%02x\n", addr_list[i]); 1474 1452 continue;