aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorAdamski, Krzysztof (Nokia - PL/Wroclaw) <krzysztof.adamski@nokia.com>2018-11-16 08:24:41 -0500
committerWolfram Sang <wsa@the-dreams.de>2018-12-06 17:14:53 -0500
commit6c7f25cae54b840302e4f1b371dbf318fbf09ab2 (patch)
tree134a73858cd1cfd44a4f54ca5d62ac39e7b786be /drivers/i2c
parent0b57436f15bf40e432487086c4f2d01fd3529393 (diff)
i2c: axxia: properly handle master timeout
According to Intel (R) Axxia TM Lionfish Communication Processor Peripheral Subsystem Hardware Reference Manual, the AXXIA I2C module have a programmable Master Wait Timer, which among others, checks the time between commands send in manual mode. When a timeout (25ms) passes, TSS bit is set in Master Interrupt Status register and a Stop command is issued by the hardware. The axxia_i2c_xfer(), does not properly handle this situation, however. For each message a separate axxia_i2c_xfer_msg() is called and this function incorrectly assumes that any interrupt might happen only when waiting for completion. This is mostly correct but there is one exception - a master timeout can trigger if enough time has passed between individual transfers. It will, by definition, happen between transfers when the interrupts are disabled by the code. If that happens, the hardware issues Stop command. The interrupt indicating timeout will not be triggered as soon as we enable them since the Master Interrupt Status is cleared when master mode is entered again (which happens before enabling irqs) meaning this error is lost and the transfer is continued even though the Stop was issued on the bus. The subsequent operations completes without error but a bogus value (0xFF in case of read) is read as the client device is confused because aborted transfer. No error is returned from master_xfer() making caller believe that a valid value was read. To fix the problem, the TSS bit (indicating timeout) in Master Interrupt Status register is checked before each transfer. If it is set, there was a timeout before this transfer and (as described above) the hardware already issued Stop command so the transaction should be aborted thus -ETIMEOUT is returned from the master_xfer() callback. In order to be sure no timeout was issued we can't just read the status just before starting new transaction as there will always be a small window of time (few CPU cycles at best) where this might still happen. For this reason we have to temporally disable the timer before checking for TSS bit. Disabling it will, however, clear the TSS bit so in order to preserve that information, we have to read it in ISR so we have to ensure that the TSS interrupt is not masked between transfers of one transaction. There is no need to call bus recovery or controller reinitialization if that happens so it's skipped. Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com> Reviewed-by: Alexander Sverdlin <alexander.sverdlin@nokia.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-axxia.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/drivers/i2c/busses/i2c-axxia.c b/drivers/i2c/busses/i2c-axxia.c
index 8e60048a33f8..51d34959709b 100644
--- a/drivers/i2c/busses/i2c-axxia.c
+++ b/drivers/i2c/busses/i2c-axxia.c
@@ -74,8 +74,7 @@
74 MST_STATUS_ND) 74 MST_STATUS_ND)
75#define MST_STATUS_ERR (MST_STATUS_NAK | \ 75#define MST_STATUS_ERR (MST_STATUS_NAK | \
76 MST_STATUS_AL | \ 76 MST_STATUS_AL | \
77 MST_STATUS_IP | \ 77 MST_STATUS_IP)
78 MST_STATUS_TSS)
79#define MST_TX_BYTES_XFRD 0x50 78#define MST_TX_BYTES_XFRD 0x50
80#define MST_RX_BYTES_XFRD 0x54 79#define MST_RX_BYTES_XFRD 0x54
81#define SCL_HIGH_PERIOD 0x80 80#define SCL_HIGH_PERIOD 0x80
@@ -241,7 +240,7 @@ static int axxia_i2c_empty_rx_fifo(struct axxia_i2c_dev *idev)
241 */ 240 */
242 if (c <= 0 || c > I2C_SMBUS_BLOCK_MAX) { 241 if (c <= 0 || c > I2C_SMBUS_BLOCK_MAX) {
243 idev->msg_err = -EPROTO; 242 idev->msg_err = -EPROTO;
244 i2c_int_disable(idev, ~0); 243 i2c_int_disable(idev, ~MST_STATUS_TSS);
245 complete(&idev->msg_complete); 244 complete(&idev->msg_complete);
246 break; 245 break;
247 } 246 }
@@ -299,14 +298,19 @@ static irqreturn_t axxia_i2c_isr(int irq, void *_dev)
299 298
300 if (status & MST_STATUS_SCC) { 299 if (status & MST_STATUS_SCC) {
301 /* Stop completed */ 300 /* Stop completed */
302 i2c_int_disable(idev, ~0); 301 i2c_int_disable(idev, ~MST_STATUS_TSS);
303 complete(&idev->msg_complete); 302 complete(&idev->msg_complete);
304 } else if (status & MST_STATUS_SNS) { 303 } else if (status & MST_STATUS_SNS) {
305 /* Transfer done */ 304 /* Transfer done */
306 i2c_int_disable(idev, ~0); 305 i2c_int_disable(idev, ~MST_STATUS_TSS);
307 if (i2c_m_rd(idev->msg) && idev->msg_xfrd < idev->msg->len) 306 if (i2c_m_rd(idev->msg) && idev->msg_xfrd < idev->msg->len)
308 axxia_i2c_empty_rx_fifo(idev); 307 axxia_i2c_empty_rx_fifo(idev);
309 complete(&idev->msg_complete); 308 complete(&idev->msg_complete);
309 } else if (status & MST_STATUS_TSS) {
310 /* Transfer timeout */
311 idev->msg_err = -ETIMEDOUT;
312 i2c_int_disable(idev, ~MST_STATUS_TSS);
313 complete(&idev->msg_complete);
310 } else if (unlikely(status & MST_STATUS_ERR)) { 314 } else if (unlikely(status & MST_STATUS_ERR)) {
311 /* Transfer error */ 315 /* Transfer error */
312 i2c_int_disable(idev, ~0); 316 i2c_int_disable(idev, ~0);
@@ -339,10 +343,10 @@ static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
339 u32 rx_xfer, tx_xfer; 343 u32 rx_xfer, tx_xfer;
340 u32 addr_1, addr_2; 344 u32 addr_1, addr_2;
341 unsigned long time_left; 345 unsigned long time_left;
346 unsigned int wt_value;
342 347
343 idev->msg = msg; 348 idev->msg = msg;
344 idev->msg_xfrd = 0; 349 idev->msg_xfrd = 0;
345 idev->msg_err = 0;
346 reinit_completion(&idev->msg_complete); 350 reinit_completion(&idev->msg_complete);
347 351
348 if (i2c_m_ten(msg)) { 352 if (i2c_m_ten(msg)) {
@@ -383,9 +387,18 @@ static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
383 else if (axxia_i2c_fill_tx_fifo(idev) != 0) 387 else if (axxia_i2c_fill_tx_fifo(idev) != 0)
384 int_mask |= MST_STATUS_TFL; 388 int_mask |= MST_STATUS_TFL;
385 389
390 wt_value = WT_VALUE(readl(idev->base + WAIT_TIMER_CONTROL));
391 /* Disable wait timer temporarly */
392 writel(wt_value, idev->base + WAIT_TIMER_CONTROL);
393 /* Check if timeout error happened */
394 if (idev->msg_err)
395 goto out;
396
386 /* Start manual mode */ 397 /* Start manual mode */
387 writel(CMD_MANUAL, idev->base + MST_COMMAND); 398 writel(CMD_MANUAL, idev->base + MST_COMMAND);
388 399
400 writel(WT_EN | wt_value, idev->base + WAIT_TIMER_CONTROL);
401
389 i2c_int_enable(idev, int_mask); 402 i2c_int_enable(idev, int_mask);
390 403
391 time_left = wait_for_completion_timeout(&idev->msg_complete, 404 time_left = wait_for_completion_timeout(&idev->msg_complete,
@@ -396,13 +409,15 @@ static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
396 if (readl(idev->base + MST_COMMAND) & CMD_BUSY) 409 if (readl(idev->base + MST_COMMAND) & CMD_BUSY)
397 dev_warn(idev->dev, "busy after xfer\n"); 410 dev_warn(idev->dev, "busy after xfer\n");
398 411
399 if (time_left == 0) 412 if (time_left == 0) {
400 idev->msg_err = -ETIMEDOUT; 413 idev->msg_err = -ETIMEDOUT;
401
402 if (idev->msg_err == -ETIMEDOUT)
403 i2c_recover_bus(&idev->adapter); 414 i2c_recover_bus(&idev->adapter);
415 axxia_i2c_init(idev);
416 }
404 417
405 if (unlikely(idev->msg_err) && idev->msg_err != -ENXIO) 418out:
419 if (unlikely(idev->msg_err) && idev->msg_err != -ENXIO &&
420 idev->msg_err != -ETIMEDOUT)
406 axxia_i2c_init(idev); 421 axxia_i2c_init(idev);
407 422
408 return idev->msg_err; 423 return idev->msg_err;
@@ -410,7 +425,7 @@ static int axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
410 425
411static int axxia_i2c_stop(struct axxia_i2c_dev *idev) 426static int axxia_i2c_stop(struct axxia_i2c_dev *idev)
412{ 427{
413 u32 int_mask = MST_STATUS_ERR | MST_STATUS_SCC; 428 u32 int_mask = MST_STATUS_ERR | MST_STATUS_SCC | MST_STATUS_TSS;
414 unsigned long time_left; 429 unsigned long time_left;
415 430
416 reinit_completion(&idev->msg_complete); 431 reinit_completion(&idev->msg_complete);
@@ -437,6 +452,9 @@ axxia_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
437 int i; 452 int i;
438 int ret = 0; 453 int ret = 0;
439 454
455 idev->msg_err = 0;
456 i2c_int_enable(idev, MST_STATUS_TSS);
457
440 for (i = 0; ret == 0 && i < num; ++i) 458 for (i = 0; ret == 0 && i < num; ++i)
441 ret = axxia_i2c_xfer_msg(idev, &msgs[i]); 459 ret = axxia_i2c_xfer_msg(idev, &msgs[i]);
442 460