2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2007-03-06 17:08:43 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I2C test
|
|
|
|
*
|
|
|
|
* For verifying the I2C bus, a full I2C bus scanning is performed.
|
|
|
|
*
|
2022-12-04 15:14:17 +00:00
|
|
|
* #ifdef CFG_SYS_POST_I2C_ADDRS
|
2010-10-22 05:20:31 +00:00
|
|
|
* The test is considered as passed if all the devices and only the devices
|
|
|
|
* in the list are found.
|
2022-12-04 15:14:17 +00:00
|
|
|
* #ifdef CFG_SYS_POST_I2C_IGNORES
|
|
|
|
* Ignore devices listed in CFG_SYS_POST_I2C_IGNORES. These devices
|
2010-10-22 05:20:31 +00:00
|
|
|
* are optional or not vital to board functionality.
|
|
|
|
* #endif
|
2022-12-04 15:14:17 +00:00
|
|
|
* #else [ ! CFG_SYS_POST_I2C_ADDRS ]
|
2007-03-06 17:08:43 +00:00
|
|
|
* The test is considered as passed if any I2C device is found.
|
|
|
|
* #endif
|
|
|
|
*/
|
|
|
|
|
2010-10-22 05:20:27 +00:00
|
|
|
#include <common.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2007-03-06 17:08:43 +00:00
|
|
|
#include <post.h>
|
|
|
|
#include <i2c.h>
|
|
|
|
|
2022-12-04 15:14:17 +00:00
|
|
|
#if CFG_POST & CFG_SYS_POST_I2C
|
2007-03-06 17:08:43 +00:00
|
|
|
|
2010-10-22 05:20:31 +00:00
|
|
|
static int i2c_ignore_device(unsigned int chip)
|
|
|
|
{
|
2022-12-04 15:14:17 +00:00
|
|
|
#ifdef CFG_SYS_POST_I2C_IGNORES
|
|
|
|
const unsigned char i2c_ignore_list[] = CFG_SYS_POST_I2C_IGNORES;
|
2010-10-22 05:20:31 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(i2c_ignore_list); i++)
|
|
|
|
if (i2c_ignore_list[i] == chip)
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-06 17:08:43 +00:00
|
|
|
int i2c_post_test (int flags)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2022-12-04 15:14:17 +00:00
|
|
|
#ifndef CFG_SYS_POST_I2C_ADDRS
|
2010-10-22 05:20:29 +00:00
|
|
|
/* Start at address 1, address 0 is the general call address */
|
2010-11-15 07:20:39 +00:00
|
|
|
for (i = 1; i < 128; i++) {
|
2010-10-22 05:20:31 +00:00
|
|
|
if (i2c_ignore_device(i))
|
|
|
|
continue;
|
2010-10-22 05:20:27 +00:00
|
|
|
if (i2c_probe (i) == 0)
|
|
|
|
return 0;
|
2010-11-15 07:20:39 +00:00
|
|
|
}
|
2010-10-22 05:20:27 +00:00
|
|
|
|
|
|
|
/* No devices found */
|
|
|
|
return -1;
|
|
|
|
#else
|
2010-10-22 05:20:28 +00:00
|
|
|
unsigned int ret = 0;
|
2007-03-06 17:08:43 +00:00
|
|
|
int j;
|
2022-12-04 15:14:17 +00:00
|
|
|
unsigned char i2c_addr_list[] = CFG_SYS_POST_I2C_ADDRS;
|
2007-03-06 17:08:43 +00:00
|
|
|
|
2010-10-22 05:20:29 +00:00
|
|
|
/* Start at address 1, address 0 is the general call address */
|
|
|
|
for (i = 1; i < 128; i++) {
|
2010-10-22 05:20:31 +00:00
|
|
|
if (i2c_ignore_device(i))
|
|
|
|
continue;
|
2010-10-22 05:20:27 +00:00
|
|
|
if (i2c_probe(i) != 0)
|
|
|
|
continue;
|
2010-10-22 05:20:28 +00:00
|
|
|
|
2010-10-22 05:20:27 +00:00
|
|
|
for (j = 0; j < sizeof(i2c_addr_list); ++j) {
|
|
|
|
if (i == i2c_addr_list[j]) {
|
2010-10-22 05:20:28 +00:00
|
|
|
i2c_addr_list[j] = 0xff;
|
2010-10-22 05:20:27 +00:00
|
|
|
break;
|
2007-03-06 17:08:43 +00:00
|
|
|
}
|
2010-10-22 05:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (j == sizeof(i2c_addr_list)) {
|
2010-10-22 05:20:28 +00:00
|
|
|
ret = -1;
|
|
|
|
post_log("I2C: addr %02x not expected\n", i);
|
2007-03-06 17:08:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-22 05:20:28 +00:00
|
|
|
for (i = 0; i < sizeof(i2c_addr_list); ++i) {
|
|
|
|
if (i2c_addr_list[i] == 0xff)
|
|
|
|
continue;
|
2013-04-15 04:01:07 +00:00
|
|
|
if (i2c_ignore_device(i2c_addr_list[i]))
|
|
|
|
continue;
|
2010-10-22 05:20:28 +00:00
|
|
|
post_log("I2C: addr %02x did not respond\n", i2c_addr_list[i]);
|
|
|
|
ret = -1;
|
2007-03-06 17:08:43 +00:00
|
|
|
}
|
2010-10-22 05:20:28 +00:00
|
|
|
|
|
|
|
return ret;
|
2007-03-06 17:08:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:14:17 +00:00
|
|
|
#endif /* CFG_POST & CFG_SYS_POST_I2C */
|