Skip to content

Commit 878c373

Browse files
notro0day robot
authored and
0day robot
committed
i2c: bcm2835: Fix hang for writing messages larger than 16 bytes
Writing messages larger than the FIFO size results in a hang, rendering the machine unusable. This is because the RXD status flag is set on the first interrupt which results in bcm2835_drain_rxfifo() stealing bytes from the buffer. The controller continues to trigger interrupts waiting for the missing bytes, but bcm2835_fill_txfifo() has none to give. In this situation wait_for_completion_timeout() apparently is unable to stop the madness. The BCM2835 ARM Peripherals datasheet has this to say about the flags: TXD: is set when the FIFO has space for at least one byte of data. RXD: is set when the FIFO contains at least one byte of data. TXW: is set during a write transfer and the FIFO is less than full. RXR: is set during a read transfer and the FIFO is or more full. Implementing the logic from the downstream i2c-bcm2708 driver solved the hang problem. Signed-off-by: Noralf Trønnes <[email protected]>
1 parent bc0195a commit 878c373

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

drivers/i2c/busses/i2c-bcm2835.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct bcm2835_i2c_dev {
6464
int irq;
6565
struct i2c_adapter adapter;
6666
struct completion completion;
67+
struct i2c_msg *curr_msg;
6768
u32 msg_err;
6869
u8 *msg_buf;
6970
size_t msg_buf_remaining;
@@ -126,26 +127,30 @@ static irqreturn_t bcm2835_i2c_isr(int this_irq, void *data)
126127
return IRQ_HANDLED;
127128
}
128129

129-
if (val & BCM2835_I2C_S_RXD) {
130-
bcm2835_drain_rxfifo(i2c_dev);
131-
if (!(val & BCM2835_I2C_S_DONE))
132-
return IRQ_HANDLED;
133-
}
134-
135130
if (val & BCM2835_I2C_S_DONE) {
136-
if (i2c_dev->msg_buf_remaining)
131+
if (i2c_dev->curr_msg->flags & I2C_M_RD) {
132+
bcm2835_drain_rxfifo(i2c_dev);
133+
val = bcm2835_i2c_readl(i2c_dev, BCM2835_I2C_S);
134+
}
135+
136+
if ((val & BCM2835_I2C_S_RXD) || i2c_dev->msg_buf_remaining)
137137
i2c_dev->msg_err = BCM2835_I2C_S_LEN;
138138
else
139139
i2c_dev->msg_err = 0;
140140
complete(&i2c_dev->completion);
141141
return IRQ_HANDLED;
142142
}
143143

144-
if (val & BCM2835_I2C_S_TXD) {
144+
if (val & BCM2835_I2C_S_TXW) {
145145
bcm2835_fill_txfifo(i2c_dev);
146146
return IRQ_HANDLED;
147147
}
148148

149+
if (val & BCM2835_I2C_S_RXR) {
150+
bcm2835_drain_rxfifo(i2c_dev);
151+
return IRQ_HANDLED;
152+
}
153+
149154
return IRQ_NONE;
150155
}
151156

@@ -155,6 +160,7 @@ static int bcm2835_i2c_xfer_msg(struct bcm2835_i2c_dev *i2c_dev,
155160
u32 c;
156161
unsigned long time_left;
157162

163+
i2c_dev->curr_msg = msg;
158164
i2c_dev->msg_buf = msg->buf;
159165
i2c_dev->msg_buf_remaining = msg->len;
160166
reinit_completion(&i2c_dev->completion);

0 commit comments

Comments
 (0)