@@ -1497,17 +1497,11 @@ static irqreturn_t stm32f7_i2c_slave_isr_event(struct stm32f7_i2c_dev *i2c_dev)
1497
1497
static irqreturn_t stm32f7_i2c_isr_event (int irq , void * data )
1498
1498
{
1499
1499
struct stm32f7_i2c_dev * i2c_dev = data ;
1500
- struct stm32f7_i2c_msg * f7_msg = & i2c_dev -> f7_msg ;
1501
- struct stm32_i2c_dma * dma = i2c_dev -> dma ;
1502
- void __iomem * base = i2c_dev -> base ;
1503
- u32 status , mask ;
1504
- int ret = IRQ_HANDLED ;
1500
+ u32 status ;
1505
1501
1506
- /* Check if the interrupt if for a slave device */
1507
- if (!i2c_dev -> master_mode ) {
1508
- ret = stm32f7_i2c_slave_isr_event (i2c_dev );
1509
- return ret ;
1510
- }
1502
+ /* Check if the interrupt is for a slave device */
1503
+ if (!i2c_dev -> master_mode )
1504
+ return IRQ_WAKE_THREAD ;
1511
1505
1512
1506
status = readl_relaxed (i2c_dev -> base + STM32F7_I2C_ISR );
1513
1507
@@ -1519,6 +1513,29 @@ static irqreturn_t stm32f7_i2c_isr_event(int irq, void *data)
1519
1513
if (status & STM32F7_I2C_ISR_RXNE )
1520
1514
stm32f7_i2c_read_rx_data (i2c_dev );
1521
1515
1516
+ /* Wake up the thread if other flags are raised */
1517
+ if (status &
1518
+ (STM32F7_I2C_ISR_NACKF | STM32F7_I2C_ISR_STOPF |
1519
+ STM32F7_I2C_ISR_TC | STM32F7_I2C_ISR_TCR ))
1520
+ return IRQ_WAKE_THREAD ;
1521
+
1522
+ return IRQ_HANDLED ;
1523
+ }
1524
+
1525
+ static irqreturn_t stm32f7_i2c_isr_event_thread (int irq , void * data )
1526
+ {
1527
+ struct stm32f7_i2c_dev * i2c_dev = data ;
1528
+ struct stm32f7_i2c_msg * f7_msg = & i2c_dev -> f7_msg ;
1529
+ struct stm32_i2c_dma * dma = i2c_dev -> dma ;
1530
+ void __iomem * base = i2c_dev -> base ;
1531
+ u32 status , mask ;
1532
+ int ret ;
1533
+
1534
+ if (!i2c_dev -> master_mode )
1535
+ return stm32f7_i2c_slave_isr_event (i2c_dev );
1536
+
1537
+ status = readl_relaxed (i2c_dev -> base + STM32F7_I2C_ISR );
1538
+
1522
1539
/* NACK received */
1523
1540
if (status & STM32F7_I2C_ISR_NACKF ) {
1524
1541
dev_dbg (i2c_dev -> dev , "<%s>: Receive NACK (addr %x)\n" ,
@@ -1531,33 +1548,28 @@ static irqreturn_t stm32f7_i2c_isr_event(int irq, void *data)
1531
1548
f7_msg -> result = - ENXIO ;
1532
1549
}
1533
1550
1534
- /* STOP detection flag */
1535
- if (status & STM32F7_I2C_ISR_STOPF ) {
1536
- /* Disable interrupts */
1537
- if (stm32f7_i2c_is_slave_registered (i2c_dev ))
1538
- mask = STM32F7_I2C_XFER_IRQ_MASK ;
1551
+ if (status & STM32F7_I2C_ISR_TCR ) {
1552
+ if (f7_msg -> smbus )
1553
+ stm32f7_i2c_smbus_reload (i2c_dev );
1539
1554
else
1540
- mask = STM32F7_I2C_ALL_IRQ_MASK ;
1541
- stm32f7_i2c_disable_irq (i2c_dev , mask );
1542
-
1543
- /* Clear STOP flag */
1544
- writel_relaxed (STM32F7_I2C_ICR_STOPCF , base + STM32F7_I2C_ICR );
1545
-
1546
- if (i2c_dev -> use_dma && !f7_msg -> result ) {
1547
- ret = IRQ_WAKE_THREAD ;
1548
- } else {
1549
- i2c_dev -> master_mode = false;
1550
- complete (& i2c_dev -> complete );
1551
- }
1555
+ stm32f7_i2c_reload (i2c_dev );
1552
1556
}
1553
1557
1554
1558
/* Transfer complete */
1555
1559
if (status & STM32F7_I2C_ISR_TC ) {
1560
+ /* Wait for dma transfer completion before sending next message */
1561
+ if (i2c_dev -> use_dma && !f7_msg -> result ) {
1562
+ ret = wait_for_completion_timeout (& i2c_dev -> dma -> dma_complete , HZ );
1563
+ if (!ret ) {
1564
+ dev_dbg (i2c_dev -> dev , "<%s>: Timed out\n" , __func__ );
1565
+ stm32f7_i2c_disable_dma_req (i2c_dev );
1566
+ dmaengine_terminate_async (dma -> chan_using );
1567
+ f7_msg -> result = - ETIMEDOUT ;
1568
+ }
1569
+ }
1556
1570
if (f7_msg -> stop ) {
1557
1571
mask = STM32F7_I2C_CR2_STOP ;
1558
1572
stm32f7_i2c_set_bits (base + STM32F7_I2C_CR2 , mask );
1559
- } else if (i2c_dev -> use_dma && !f7_msg -> result ) {
1560
- ret = IRQ_WAKE_THREAD ;
1561
1573
} else if (f7_msg -> smbus ) {
1562
1574
stm32f7_i2c_smbus_rep_start (i2c_dev );
1563
1575
} else {
@@ -1567,55 +1579,26 @@ static irqreturn_t stm32f7_i2c_isr_event(int irq, void *data)
1567
1579
}
1568
1580
}
1569
1581
1570
- if (status & STM32F7_I2C_ISR_TCR ) {
1571
- if (f7_msg -> smbus )
1572
- stm32f7_i2c_smbus_reload (i2c_dev );
1582
+ /* STOP detection flag */
1583
+ if (status & STM32F7_I2C_ISR_STOPF ) {
1584
+ /* Disable interrupts */
1585
+ if (stm32f7_i2c_is_slave_registered (i2c_dev ))
1586
+ mask = STM32F7_I2C_XFER_IRQ_MASK ;
1573
1587
else
1574
- stm32f7_i2c_reload (i2c_dev );
1575
- }
1576
-
1577
- return ret ;
1578
- }
1579
-
1580
- static irqreturn_t stm32f7_i2c_isr_event_thread (int irq , void * data )
1581
- {
1582
- struct stm32f7_i2c_dev * i2c_dev = data ;
1583
- struct stm32f7_i2c_msg * f7_msg = & i2c_dev -> f7_msg ;
1584
- struct stm32_i2c_dma * dma = i2c_dev -> dma ;
1585
- u32 status ;
1586
- int ret ;
1587
-
1588
- /*
1589
- * Wait for dma transfer completion before sending next message or
1590
- * notity the end of xfer to the client
1591
- */
1592
- ret = wait_for_completion_timeout (& i2c_dev -> dma -> dma_complete , HZ );
1593
- if (!ret ) {
1594
- dev_dbg (i2c_dev -> dev , "<%s>: Timed out\n" , __func__ );
1595
- stm32f7_i2c_disable_dma_req (i2c_dev );
1596
- dmaengine_terminate_async (dma -> chan_using );
1597
- f7_msg -> result = - ETIMEDOUT ;
1598
- }
1588
+ mask = STM32F7_I2C_ALL_IRQ_MASK ;
1589
+ stm32f7_i2c_disable_irq (i2c_dev , mask );
1599
1590
1600
- status = readl_relaxed (i2c_dev -> base + STM32F7_I2C_ISR );
1591
+ /* Clear STOP flag */
1592
+ writel_relaxed (STM32F7_I2C_ICR_STOPCF , base + STM32F7_I2C_ICR );
1601
1593
1602
- if (status & STM32F7_I2C_ISR_TC ) {
1603
- if (f7_msg -> smbus ) {
1604
- stm32f7_i2c_smbus_rep_start (i2c_dev );
1605
- } else {
1606
- i2c_dev -> msg_id ++ ;
1607
- i2c_dev -> msg ++ ;
1608
- stm32f7_i2c_xfer_msg (i2c_dev , i2c_dev -> msg );
1609
- }
1610
- } else {
1611
1594
i2c_dev -> master_mode = false;
1612
1595
complete (& i2c_dev -> complete );
1613
1596
}
1614
1597
1615
1598
return IRQ_HANDLED ;
1616
1599
}
1617
1600
1618
- static irqreturn_t stm32f7_i2c_isr_error (int irq , void * data )
1601
+ static irqreturn_t stm32f7_i2c_isr_error_thread (int irq , void * data )
1619
1602
{
1620
1603
struct stm32f7_i2c_dev * i2c_dev = data ;
1621
1604
struct stm32f7_i2c_msg * f7_msg = & i2c_dev -> f7_msg ;
@@ -2202,8 +2185,11 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
2202
2185
if (ret )
2203
2186
return dev_err_probe (& pdev -> dev , ret , "Failed to request irq event\n" );
2204
2187
2205
- ret = devm_request_irq (& pdev -> dev , irq_error , stm32f7_i2c_isr_error , 0 ,
2206
- pdev -> name , i2c_dev );
2188
+ ret = devm_request_threaded_irq (& pdev -> dev , irq_error ,
2189
+ NULL ,
2190
+ stm32f7_i2c_isr_error_thread ,
2191
+ IRQF_ONESHOT ,
2192
+ pdev -> name , i2c_dev );
2207
2193
if (ret )
2208
2194
return dev_err_probe (& pdev -> dev , ret , "Failed to request irq error\n" );
2209
2195
0 commit comments