i2c: stm32f7: unmap DMA mapped buffer

Before each I2C transfer using DMA, the I2C buffer is DMA'pped to make
sure the memory buffer is DMA'able. This is handle in the function
`stm32_i2c_prep_dma_xfer()`.
If the transfer fails for any reason the I2C buffer must be unmap.
Use the dma_callback to factorize the code and fix this issue.

Note that the `stm32f7_i2c_dma_callback()` is now called in case of DMA
transfer success and error and that the `complete()` on the dma_complete
completion structure is done inconditionnally in case of transfer
success or error as well as the `dmaengine_terminate_async()`.
This is allowed as a `complete()` in case transfer error has no effect
as well as a `dmaengine_terminate_async()` on a transfer success.

Also fix the unneeded cast and remove not more needed variables.

Fixes: 7ecc8cfde553 ("i2c: i2c-stm32f7: Add DMA support")
Signed-off-by: Clément Le Goffic <clement.legoffic@foss.st.com>
Cc: <stable@vger.kernel.org> # v4.18+
Acked-by: Alain Volmat <alain.volmat@foss.st.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Link: https://lore.kernel.org/r/20250704-i2c-upstream-v4-2-84a095a2c728@foss.st.com

authored by Clément Le Goffic and committed by Andi Shyti 6aae87fe c870cbbd

Changed files
+7 -13
drivers
i2c
busses
+7 -13
drivers/i2c/busses/i2c-stm32f7.c
··· 739 739 740 740 static void stm32f7_i2c_dma_callback(void *arg) 741 741 { 742 - struct stm32f7_i2c_dev *i2c_dev = (struct stm32f7_i2c_dev *)arg; 742 + struct stm32f7_i2c_dev *i2c_dev = arg; 743 743 struct stm32_i2c_dma *dma = i2c_dev->dma; 744 744 745 745 stm32f7_i2c_disable_dma_req(i2c_dev); 746 + dmaengine_terminate_async(dma->chan_using); 746 747 dma_unmap_single(i2c_dev->dev, dma->dma_buf, dma->dma_len, 747 748 dma->dma_data_dir); 748 749 complete(&dma->dma_complete); ··· 1511 1510 u16 addr = f7_msg->addr; 1512 1511 void __iomem *base = i2c_dev->base; 1513 1512 struct device *dev = i2c_dev->dev; 1514 - struct stm32_i2c_dma *dma = i2c_dev->dma; 1515 1513 1516 1514 /* Bus error */ 1517 1515 if (status & STM32F7_I2C_ISR_BERR) { ··· 1551 1551 } 1552 1552 1553 1553 /* Disable dma */ 1554 - if (i2c_dev->use_dma) { 1555 - stm32f7_i2c_disable_dma_req(i2c_dev); 1556 - dmaengine_terminate_async(dma->chan_using); 1557 - } 1554 + if (i2c_dev->use_dma) 1555 + stm32f7_i2c_dma_callback(i2c_dev); 1558 1556 1559 1557 i2c_dev->master_mode = false; 1560 1558 complete(&i2c_dev->complete); ··· 1598 1600 { 1599 1601 struct stm32f7_i2c_dev *i2c_dev = data; 1600 1602 struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg; 1601 - struct stm32_i2c_dma *dma = i2c_dev->dma; 1602 1603 void __iomem *base = i2c_dev->base; 1603 1604 u32 status, mask; 1604 1605 int ret; ··· 1616 1619 dev_dbg(i2c_dev->dev, "<%s>: Receive NACK (addr %x)\n", 1617 1620 __func__, f7_msg->addr); 1618 1621 writel_relaxed(STM32F7_I2C_ICR_NACKCF, base + STM32F7_I2C_ICR); 1619 - if (i2c_dev->use_dma) { 1620 - stm32f7_i2c_disable_dma_req(i2c_dev); 1621 - dmaengine_terminate_async(dma->chan_using); 1622 - } 1622 + if (i2c_dev->use_dma) 1623 + stm32f7_i2c_dma_callback(i2c_dev); 1623 1624 f7_msg->result = -ENXIO; 1624 1625 } 1625 1626 ··· 1635 1640 ret = wait_for_completion_timeout(&i2c_dev->dma->dma_complete, HZ); 1636 1641 if (!ret) { 1637 1642 dev_dbg(i2c_dev->dev, "<%s>: Timed out\n", __func__); 1638 - stm32f7_i2c_disable_dma_req(i2c_dev); 1639 - dmaengine_terminate_async(dma->chan_using); 1643 + stm32f7_i2c_dma_callback(i2c_dev); 1640 1644 f7_msg->result = -ETIMEDOUT; 1641 1645 } 1642 1646 }