1 // SPDX-License-Identifier: GPL-2.0+
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
10 * For verifying the I2C bus, a full I2C bus scanning is performed.
12 * #ifdef CONFIG_SYS_POST_I2C_ADDRS
13 * The test is considered as passed if all the devices and only the devices
14 * in the list are found.
15 * #ifdef CONFIG_SYS_POST_I2C_IGNORES
16 * Ignore devices listed in CONFIG_SYS_POST_I2C_IGNORES. These devices
17 * are optional or not vital to board functionality.
19 * #else [ ! CONFIG_SYS_POST_I2C_ADDRS ]
20 * The test is considered as passed if any I2C device is found.
28 #if CONFIG_POST & CONFIG_SYS_POST_I2C
30 static int i2c_ignore_device(unsigned int chip)
32 #ifdef CONFIG_SYS_POST_I2C_IGNORES
33 const unsigned char i2c_ignore_list[] = CONFIG_SYS_POST_I2C_IGNORES;
36 for (i = 0; i < sizeof(i2c_ignore_list); i++)
37 if (i2c_ignore_list[i] == chip)
44 int i2c_post_test (int flags)
47 #ifndef CONFIG_SYS_POST_I2C_ADDRS
48 /* Start at address 1, address 0 is the general call address */
49 for (i = 1; i < 128; i++) {
50 if (i2c_ignore_device(i))
52 if (i2c_probe (i) == 0)
56 /* No devices found */
61 unsigned char i2c_addr_list[] = CONFIG_SYS_POST_I2C_ADDRS;
63 /* Start at address 1, address 0 is the general call address */
64 for (i = 1; i < 128; i++) {
65 if (i2c_ignore_device(i))
67 if (i2c_probe(i) != 0)
70 for (j = 0; j < sizeof(i2c_addr_list); ++j) {
71 if (i == i2c_addr_list[j]) {
72 i2c_addr_list[j] = 0xff;
77 if (j == sizeof(i2c_addr_list)) {
79 post_log("I2C: addr %02x not expected\n", i);
83 for (i = 0; i < sizeof(i2c_addr_list); ++i) {
84 if (i2c_addr_list[i] == 0xff)
86 if (i2c_ignore_device(i2c_addr_list[i]))
88 post_log("I2C: addr %02x did not respond\n", i2c_addr_list[i]);
96 #endif /* CONFIG_POST & CONFIG_SYS_POST_I2C */