Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual
Page 48

KTD-S0057-I
Page 44 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
static inline __s32 i2c_smbus_read_byte (int file)
{
union i2c_smbus_data data;
if (i2c_smbus_access (file, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data))
return
-1;
else
return 0x0FF & data.byte;
}
static int scan_i2c_bus (int file, int mode, int first, int last)
{
int i, j;
printf (" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n");
for (i = 0; i < 128; i += 16)
{
printf ("%02x: ", i);
for (j = 0; j < 16; j++)
{
fflush
(stdout);
/* Skip unwanted addresses */
if (i+j < first || i+j > last)
{
printf (" "); continue;
}
/* Set slave address */
if (ioctl (file, I2C_SLAVE, i+j) < 0)
{
if (errno == EBUSY)
{
printf ("UU "); continue;
}
else
{
/* ERROR: Could not set address */
printf ("** "); continue;
}
}
/* Probe this address */
/* This is known to lock SMBus on various write-only chips (mainly clock chips) */
if (i2c_smbus_read_byte (file) < 0)
printf
("--
");
else
printf ("%02x ", i+j);
}
printf
("\n");
}
return
0;
}