mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-27 16:01:27 +00:00
ARMV7: OMAP: I2C driver: Restructure i2c_probe function
This patch removes the "magic number" delays and instead monitors state changes in the status register bits. Signed-off-by: Steve Sakoman <steve.sakoman@linaro.org> Tested-by: Heiko Schocher <hs@denx.de>
This commit is contained in:
parent
d480c46773
commit
fbad355562
1 changed files with 30 additions and 11 deletions
|
@ -310,6 +310,7 @@ static void flush_fifo(void)
|
||||||
|
|
||||||
int i2c_probe (uchar chip)
|
int i2c_probe (uchar chip)
|
||||||
{
|
{
|
||||||
|
u16 status;
|
||||||
int res = 1; /* default = fail */
|
int res = 1; /* default = fail */
|
||||||
|
|
||||||
if (chip == readw (&i2c_base->oa)) {
|
if (chip == readw (&i2c_base->oa)) {
|
||||||
|
@ -325,19 +326,37 @@ int i2c_probe (uchar chip)
|
||||||
writew (chip, &i2c_base->sa);
|
writew (chip, &i2c_base->sa);
|
||||||
/* stop bit needed here */
|
/* stop bit needed here */
|
||||||
writew (I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_STP, &i2c_base->con);
|
writew (I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_STP, &i2c_base->con);
|
||||||
/* enough delay for the NACK bit set */
|
|
||||||
udelay (50000);
|
|
||||||
|
|
||||||
if (!(readw (&i2c_base->stat) & I2C_STAT_NACK)) {
|
while (1) {
|
||||||
res = 0; /* success case */
|
status = wait_for_pin();
|
||||||
flush_fifo();
|
if (status == 0) {
|
||||||
writew(0xFFFF, &i2c_base->stat);
|
res = 1;
|
||||||
} else {
|
goto probe_exit;
|
||||||
writew(0xFFFF, &i2c_base->stat); /* failue, clear sources*/
|
}
|
||||||
writew (readw (&i2c_base->con) | I2C_CON_STP, &i2c_base->con); /* finish up xfer */
|
if (status & I2C_STAT_NACK) {
|
||||||
udelay(20000);
|
res = 1;
|
||||||
wait_for_bb ();
|
writew(0xff, &i2c_base->stat);
|
||||||
|
writew (readw (&i2c_base->con) | I2C_CON_STP, &i2c_base->con);
|
||||||
|
wait_for_bb ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (status & I2C_STAT_ARDY) {
|
||||||
|
writew(I2C_STAT_ARDY, &i2c_base->stat);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (status & I2C_STAT_RRDY) {
|
||||||
|
res = 0;
|
||||||
|
#if defined(CONFIG_OMAP243X) || defined(CONFIG_OMAP34XX) || \
|
||||||
|
defined(CONFIG_OMAP44XX)
|
||||||
|
readb(&i2c_base->data);
|
||||||
|
#else
|
||||||
|
readw(&i2c_base->data);
|
||||||
|
#endif
|
||||||
|
writew(I2C_STAT_RRDY, &i2c_base->stat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
probe_exit:
|
||||||
flush_fifo();
|
flush_fifo();
|
||||||
writew (0, &i2c_base->cnt); /* don't allow any more data in...we don't want it.*/
|
writew (0, &i2c_base->cnt); /* don't allow any more data in...we don't want it.*/
|
||||||
writew(0xFFFF, &i2c_base->stat);
|
writew(0xFFFF, &i2c_base->stat);
|
||||||
|
|
Loading…
Add table
Reference in a new issue