i2cdetect: don't die on addresses already in use by drivers
We can't use i2c_set_slave_addr() in i2cdetect, as we have to check for EBUSY after calling ioctl(I2C_SLAVE) and print 'UU' on busy addresses instead of bailing-out. While we're at it: reorder definitions of local vars in i2cdetect_main(). function old new delta i2cdetect_main 703 744 +41 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 41/0) Total: 41 bytes text data bss dec hex filename 826097 4164 9584 839845 cd0a5 busybox_old 826145 4164 9584 839893 cd0d5 busybox_unstripped Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
d291c2fdd5
commit
314742747d
@ -355,6 +355,13 @@ static void i2c_set_pec(int fd, int pec)
|
|||||||
itoptr(pec ? 1 : 0),
|
itoptr(pec ? 1 : 0),
|
||||||
"can't set PEC");
|
"can't set PEC");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void i2c_set_slave_addr(int fd, int addr, int force)
|
||||||
|
{
|
||||||
|
ioctl_or_perror_and_die(fd, force ? I2C_SLAVE_FORCE : I2C_SLAVE,
|
||||||
|
itoptr(addr),
|
||||||
|
"can't set address to 0x%02x", addr);
|
||||||
|
}
|
||||||
#endif /* ENABLE_I2CGET || ENABLE_I2CSET || ENABLE_I2CDUMP */
|
#endif /* ENABLE_I2CGET || ENABLE_I2CSET || ENABLE_I2CDUMP */
|
||||||
|
|
||||||
#if ENABLE_I2CGET || ENABLE_I2CSET
|
#if ENABLE_I2CGET || ENABLE_I2CSET
|
||||||
@ -390,13 +397,6 @@ static int i2c_dev_open(int i2cbus)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void i2c_set_slave_addr(int fd, int addr, int force)
|
|
||||||
{
|
|
||||||
ioctl_or_perror_and_die(fd, force ? I2C_SLAVE_FORCE : I2C_SLAVE,
|
|
||||||
itoptr(addr),
|
|
||||||
"can't set address to 0x%02x", addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Size reducing helpers for xxx_check_funcs(). */
|
/* Size reducing helpers for xxx_check_funcs(). */
|
||||||
static void get_funcs_matrix(int fd, unsigned long *funcs)
|
static void get_funcs_matrix(int fd, unsigned long *funcs)
|
||||||
{
|
{
|
||||||
@ -1281,11 +1281,9 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
opt_F = (1 << 4), opt_l = (1 << 5);
|
opt_F = (1 << 4), opt_l = (1 << 5);
|
||||||
const char *const optstr = "yaqrFl";
|
const char *const optstr = "yaqrFl";
|
||||||
|
|
||||||
int fd, bus_num, i, j, mode = DETECT_MODE_AUTO;
|
int fd, bus_num, i, j, mode = DETECT_MODE_AUTO, status;
|
||||||
int status;
|
unsigned first = 0x00, last = 0x77, opts;
|
||||||
unsigned first = 0x00, last = 0x77;
|
|
||||||
unsigned long funcs;
|
unsigned long funcs;
|
||||||
unsigned opts;
|
|
||||||
|
|
||||||
opt_complementary = "q--r:r--q:" /* mutually exclusive */
|
opt_complementary = "q--r:r--q:" /* mutually exclusive */
|
||||||
"?3"; /* up to 3 args */
|
"?3"; /* up to 3 args */
|
||||||
@ -1370,7 +1368,16 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_set_slave_addr(fd, i + j, 0);
|
status = ioctl(fd, I2C_SLAVE, itoptr(i + j));
|
||||||
|
if (status < 0) {
|
||||||
|
if (errno == EBUSY) {
|
||||||
|
printf("UU ");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bb_perror_msg_and_die(
|
||||||
|
"can't set address to 0x%02x", i + j);
|
||||||
|
}
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case DETECT_MODE_READ:
|
case DETECT_MODE_READ:
|
||||||
|
Loading…
Reference in New Issue
Block a user