mirror of
https://github.com/Stichting-MINIX-Research-Foundation/u-boot.git
synced 2025-09-09 03:58:18 -04:00
Blackfin: TWI/I2C: add timeout to transfer
The current transfer code relies on ctrlc() to abort transfers, but this requires user interactivity. Naturalize the process with a timeout. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
This commit is contained in:
parent
f2b4bc04d6
commit
3814ea4f00
@ -60,6 +60,9 @@ struct i2c_msg {
|
|||||||
u8 *abuf; /* addr buffer */
|
u8 *abuf; /* addr buffer */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Allow msec timeout per ~byte transfer */
|
||||||
|
#define I2C_TIMEOUT 10
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wait_for_completion - manage the actual i2c transfer
|
* wait_for_completion - manage the actual i2c transfer
|
||||||
* @msg: the i2c msg
|
* @msg: the i2c msg
|
||||||
@ -67,8 +70,9 @@ struct i2c_msg {
|
|||||||
static int wait_for_completion(struct i2c_msg *msg)
|
static int wait_for_completion(struct i2c_msg *msg)
|
||||||
{
|
{
|
||||||
uint16_t int_stat;
|
uint16_t int_stat;
|
||||||
|
ulong timebase = get_timer(0);
|
||||||
|
|
||||||
while (!ctrlc()) {
|
do {
|
||||||
int_stat = bfin_read_TWI_INT_STAT();
|
int_stat = bfin_read_TWI_INT_STAT();
|
||||||
|
|
||||||
if (int_stat & XMTSERV) {
|
if (int_stat & XMTSERV) {
|
||||||
@ -103,7 +107,7 @@ static int wait_for_completion(struct i2c_msg *msg)
|
|||||||
debugi("processing MERR");
|
debugi("processing MERR");
|
||||||
bfin_write_TWI_INT_STAT(MERR);
|
bfin_write_TWI_INT_STAT(MERR);
|
||||||
SSYNC();
|
SSYNC();
|
||||||
break;
|
return msg->len;
|
||||||
}
|
}
|
||||||
if (int_stat & MCOMP) {
|
if (int_stat & MCOMP) {
|
||||||
debugi("processing MCOMP");
|
debugi("processing MCOMP");
|
||||||
@ -116,7 +120,12 @@ static int wait_for_completion(struct i2c_msg *msg)
|
|||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/* If we were able to do something, reset timeout */
|
||||||
|
if (int_stat)
|
||||||
|
timebase = get_timer(0);
|
||||||
|
|
||||||
|
} while (get_timer(timebase) < I2C_TIMEOUT);
|
||||||
|
|
||||||
return msg->len;
|
return msg->len;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user