summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Gasnier <fabrice.gasnier@st.com>2019-10-01 04:51:09 -0400
committerWolfram Sang <wsa@the-dreams.de>2019-10-24 14:52:17 -0400
commit6d6b0d0d5afc8c4c84b08261260ba11dfa5206f2 (patch)
tree83718c6f89b3dce44c0357ef3025e46a6aa04c19
parent02e64276c6dbcc4c5f39844f33d18180832a58f3 (diff)
i2c: stm32f7: fix a race in slave mode with arbitration loss irq
When in slave mode, an arbitration loss (ARLO) may be detected before the slave had a chance to detect the stop condition (STOPF in ISR). This is seen when two master + slave adapters switch their roles. It provokes the i2c bus to be stuck, busy as SCL line is stretched. - the I2C_SLAVE_STOP event is never generated due to STOPF flag is set but don't generate an irq (race with ARLO irq, STOPIE is masked). STOPF flag remains set until next master xfer (e.g. when STOPIE irq get unmasked). In this case, completion is generated too early: immediately upon new transfer request (then it doesn't send all data). - Some data get stuck in TXDR register. As a consequence, the controller stretches the SCL line: the bus gets busy until a future master transfer triggers the bus busy / recovery mechanism (this can take time... and may never happen at all) So choice is to let the STOPF being detected by the slave isr handler, to properly handle this stop condition. E.g. don't mask IRQs in error handler, when the slave is running. Fixes: 60d609f30de2 ("i2c: i2c-stm32f7: Add slave support") Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Reviewed-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r--drivers/i2c/busses/i2c-stm32f7.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index c8ce6c8dd404..073bf57a9821 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -1503,7 +1503,7 @@ static irqreturn_t stm32f7_i2c_isr_error(int irq, void *data)
1503 void __iomem *base = i2c_dev->base; 1503 void __iomem *base = i2c_dev->base;
1504 struct device *dev = i2c_dev->dev; 1504 struct device *dev = i2c_dev->dev;
1505 struct stm32_i2c_dma *dma = i2c_dev->dma; 1505 struct stm32_i2c_dma *dma = i2c_dev->dma;
1506 u32 mask, status; 1506 u32 status;
1507 1507
1508 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR); 1508 status = readl_relaxed(i2c_dev->base + STM32F7_I2C_ISR);
1509 1509
@@ -1528,12 +1528,15 @@ static irqreturn_t stm32f7_i2c_isr_error(int irq, void *data)
1528 f7_msg->result = -EINVAL; 1528 f7_msg->result = -EINVAL;
1529 } 1529 }
1530 1530
1531 /* Disable interrupts */ 1531 if (!i2c_dev->slave_running) {
1532 if (stm32f7_i2c_is_slave_registered(i2c_dev)) 1532 u32 mask;
1533 mask = STM32F7_I2C_XFER_IRQ_MASK; 1533 /* Disable interrupts */
1534 else 1534 if (stm32f7_i2c_is_slave_registered(i2c_dev))
1535 mask = STM32F7_I2C_ALL_IRQ_MASK; 1535 mask = STM32F7_I2C_XFER_IRQ_MASK;
1536 stm32f7_i2c_disable_irq(i2c_dev, mask); 1536 else
1537 mask = STM32F7_I2C_ALL_IRQ_MASK;
1538 stm32f7_i2c_disable_irq(i2c_dev, mask);
1539 }
1537 1540
1538 /* Disable dma */ 1541 /* Disable dma */
1539 if (i2c_dev->use_dma) { 1542 if (i2c_dev->use_dma) {