3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
11 * For verifying the I2C bus, a full I2C bus scanning is performed.
13 * #ifdef CONFIG_SYS_POST_I2C_ADDRS
14 * The test is considered as passed if all the devices and only the devices
15 * in the list are found.
16 * #ifdef CONFIG_SYS_POST_I2C_IGNORES
17 * Ignore devices listed in CONFIG_SYS_POST_I2C_IGNORES. These devices
18 * are optional or not vital to board functionality.
20 * #else [ ! CONFIG_SYS_POST_I2C_ADDRS ]
21 * The test is considered as passed if any I2C device is found.
29 #if CONFIG_POST & CONFIG_SYS_POST_I2C
31 static int i2c_ignore_device(unsigned int chip)
33 #ifdef CONFIG_SYS_POST_I2C_IGNORES
34 const unsigned char i2c_ignore_list[] = CONFIG_SYS_POST_I2C_IGNORES;
37 for (i = 0; i < sizeof(i2c_ignore_list); i++)
38 if (i2c_ignore_list[i] == chip)
45 int i2c_post_test (int flags)
48 #ifndef CONFIG_SYS_POST_I2C_ADDRS
49 /* Start at address 1, address 0 is the general call address */
50 for (i = 1; i < 128; i++) {
51 if (i2c_ignore_device(i))
53 if (i2c_probe (i) == 0)
57 /* No devices found */
62 unsigned char i2c_addr_list[] = CONFIG_SYS_POST_I2C_ADDRS;
64 /* Start at address 1, address 0 is the general call address */
65 for (i = 1; i < 128; i++) {
66 if (i2c_ignore_device(i))
68 if (i2c_probe(i) != 0)
71 for (j = 0; j < sizeof(i2c_addr_list); ++j) {
72 if (i == i2c_addr_list[j]) {
73 i2c_addr_list[j] = 0xff;
78 if (j == sizeof(i2c_addr_list)) {
80 post_log("I2C: addr %02x not expected\n", i);
84 for (i = 0; i < sizeof(i2c_addr_list); ++i) {
85 if (i2c_addr_list[i] == 0xff)
87 if (i2c_ignore_device(i2c_addr_list[i]))
89 post_log("I2C: addr %02x did not respond\n", i2c_addr_list[i]);
97 #endif /* CONFIG_POST & CONFIG_SYS_POST_I2C */