Commit 5481d075 authored by Sonic Zhang's avatar Sonic Zhang Committed by Ben Dooks

i2c-bfin-twi: fix lost interrupts at high speeds

i2c event of next read/write byte may trigger before current int state
is cleared in the interrupt handler. So, this should be done at the
beginning of interrupt handler to avoid losing new i2c events.
Signed-off-by: default avatarSonic Zhang <sonic.zhang@analog.com>
Signed-off-by: default avatarMike Frysinger <vapier@gentoo.org>
Signed-off-by: default avatarBen Dooks <ben-linux@fluff.org>
parent 5cfafc18
...@@ -81,14 +81,15 @@ static const u16 pin_req[2][3] = { ...@@ -81,14 +81,15 @@ static const u16 pin_req[2][3] = {
{P_TWI1_SCL, P_TWI1_SDA, 0}, {P_TWI1_SCL, P_TWI1_SDA, 0},
}; };
static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
unsigned short twi_int_status)
{ {
unsigned short twi_int_status = read_INT_STAT(iface);
unsigned short mast_stat = read_MASTER_STAT(iface); unsigned short mast_stat = read_MASTER_STAT(iface);
if (twi_int_status & XMTSERV) { if (twi_int_status & XMTSERV) {
/* Transmit next data */ /* Transmit next data */
if (iface->writeNum > 0) { if (iface->writeNum > 0) {
SSYNC();
write_XMT_DATA8(iface, *(iface->transPtr++)); write_XMT_DATA8(iface, *(iface->transPtr++));
iface->writeNum--; iface->writeNum--;
} }
...@@ -110,10 +111,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) ...@@ -110,10 +111,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
write_MASTER_CTL(iface, write_MASTER_CTL(iface,
(read_MASTER_CTL(iface) | RSTART) & ~MDIR); (read_MASTER_CTL(iface) | RSTART) & ~MDIR);
} }
SSYNC();
/* Clear status */
write_INT_STAT(iface, XMTSERV);
SSYNC();
} }
if (twi_int_status & RCVSERV) { if (twi_int_status & RCVSERV) {
if (iface->readNum > 0) { if (iface->readNum > 0) {
...@@ -135,7 +132,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) ...@@ -135,7 +132,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
} else if (iface->manual_stop) { } else if (iface->manual_stop) {
write_MASTER_CTL(iface, write_MASTER_CTL(iface,
read_MASTER_CTL(iface) | STOP); read_MASTER_CTL(iface) | STOP);
SSYNC();
} else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
iface->cur_msg + 1 < iface->msg_num) { iface->cur_msg + 1 < iface->msg_num) {
if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD) if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD)
...@@ -144,18 +140,12 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) ...@@ -144,18 +140,12 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
else else
write_MASTER_CTL(iface, write_MASTER_CTL(iface,
(read_MASTER_CTL(iface) | RSTART) & ~MDIR); (read_MASTER_CTL(iface) | RSTART) & ~MDIR);
SSYNC();
} }
/* Clear interrupt source */
write_INT_STAT(iface, RCVSERV);
SSYNC();
} }
if (twi_int_status & MERR) { if (twi_int_status & MERR) {
write_INT_STAT(iface, MERR);
write_INT_MASK(iface, 0); write_INT_MASK(iface, 0);
write_MASTER_STAT(iface, 0x3e); write_MASTER_STAT(iface, 0x3e);
write_MASTER_CTL(iface, 0); write_MASTER_CTL(iface, 0);
SSYNC();
iface->result = -EIO; iface->result = -EIO;
if (mast_stat & LOSTARB) if (mast_stat & LOSTARB)
...@@ -173,10 +163,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) ...@@ -173,10 +163,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
* results. * results.
*/ */
if (twi_int_status & MCOMP) { if (twi_int_status & MCOMP) {
write_INT_STAT(iface, MCOMP);
write_INT_MASK(iface, 0);
write_MASTER_CTL(iface, 0);
SSYNC();
/* If it is a quick transfer, only address without data, /* If it is a quick transfer, only address without data,
* not an err, return 1. * not an err, return 1.
* If address is acknowledged return 1. * If address is acknowledged return 1.
...@@ -189,8 +175,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) ...@@ -189,8 +175,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
return; return;
} }
if (twi_int_status & MCOMP) { if (twi_int_status & MCOMP) {
write_INT_STAT(iface, MCOMP);
SSYNC();
if (iface->cur_mode == TWI_I2C_MODE_COMBINED) { if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
if (iface->readNum == 0) { if (iface->readNum == 0) {
/* set the read number to 1 and ask for manual /* set the read number to 1 and ask for manual
...@@ -212,7 +196,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) ...@@ -212,7 +196,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
/* remove restart bit and enable master receive */ /* remove restart bit and enable master receive */
write_MASTER_CTL(iface, write_MASTER_CTL(iface,
read_MASTER_CTL(iface) & ~RSTART); read_MASTER_CTL(iface) & ~RSTART);
SSYNC();
} else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
iface->cur_msg+1 < iface->msg_num) { iface->cur_msg+1 < iface->msg_num) {
iface->cur_msg++; iface->cur_msg++;
...@@ -231,7 +214,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) ...@@ -231,7 +214,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
write_XMT_DATA8(iface, write_XMT_DATA8(iface,
*(iface->transPtr++)); *(iface->transPtr++));
iface->writeNum--; iface->writeNum--;
SSYNC();
} }
} }
...@@ -249,12 +231,10 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface) ...@@ -249,12 +231,10 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
/* remove restart bit and enable master receive */ /* remove restart bit and enable master receive */
write_MASTER_CTL(iface, write_MASTER_CTL(iface,
read_MASTER_CTL(iface) & ~RSTART); read_MASTER_CTL(iface) & ~RSTART);
SSYNC();
} else { } else {
iface->result = 1; iface->result = 1;
write_INT_MASK(iface, 0); write_INT_MASK(iface, 0);
write_MASTER_CTL(iface, 0); write_MASTER_CTL(iface, 0);
SSYNC();
} }
} }
complete(&iface->complete); complete(&iface->complete);
...@@ -265,9 +245,18 @@ static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id) ...@@ -265,9 +245,18 @@ static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id)
{ {
struct bfin_twi_iface *iface = dev_id; struct bfin_twi_iface *iface = dev_id;
unsigned long flags; unsigned long flags;
unsigned short twi_int_status;
spin_lock_irqsave(&iface->lock, flags); spin_lock_irqsave(&iface->lock, flags);
bfin_twi_handle_interrupt(iface); while (1) {
twi_int_status = read_INT_STAT(iface);
if (!twi_int_status)
break;
/* Clear interrupt status */
write_INT_STAT(iface, twi_int_status);
bfin_twi_handle_interrupt(iface, twi_int_status);
SSYNC();
}
spin_unlock_irqrestore(&iface->lock, flags); spin_unlock_irqrestore(&iface->lock, flags);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment