linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pierre Yves MORDRET <pierre-yves.mordret@foss.st.com>
To: Alain Volmat <alain.volmat@foss.st.com>, <wsa@kernel.org>
Cc: <alexandre.torgue@foss.st.com>, <linux-i2c@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <fabrice.gasnier@foss.st.com>,
	<amelie.delaunay@foss.st.com>
Subject: Re: [PATCH 4/4] i2c: stm32f7: use proper DMAENGINE API for termination
Date: Thu, 23 Sep 2021 10:38:09 +0200	[thread overview]
Message-ID: <1b717a3f-8e2f-2e78-4509-63b04648659b@foss.st.com> (raw)
In-Reply-To: <1632151292-18503-5-git-send-email-alain.volmat@foss.st.com>

Hi Alain

Look good to me

Reviewed-by: Pierre-Yves MORDRET <pierre-yves.mordret@foss.st.com>

Regards

On 9/20/21 5:21 PM, Alain Volmat wrote:
> dmaengine_terminate_all() is deprecated in favor of explicitly saying if
> it should be sync or async.  Here, we use dmaengine_terminate_sync in
> i2c_xfer and i2c_smbus_xfer handlers and rely on
> dmaengine_terminate_async within interrupt handlers
> (transmission error cases).
> dmaengine_synchronize is added within i2c_xfer and i2c_smbus_xfer handler
> to finalize terminate started in interrupt handlers.
> 
> Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
> ---
>  drivers/i2c/busses/i2c-stm32f7.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
> index 50d5ae81d227..66145d2b9b55 100644
> --- a/drivers/i2c/busses/i2c-stm32f7.c
> +++ b/drivers/i2c/busses/i2c-stm32f7.c
> @@ -1521,7 +1521,7 @@ static irqreturn_t stm32f7_i2c_isr_event(int irq, void *data)
>  		writel_relaxed(STM32F7_I2C_ICR_NACKCF, base + STM32F7_I2C_ICR);
>  		if (i2c_dev->use_dma) {
>  			stm32f7_i2c_disable_dma_req(i2c_dev);
> -			dmaengine_terminate_all(dma->chan_using);
> +			dmaengine_terminate_async(dma->chan_using);
>  		}
>  		f7_msg->result = -ENXIO;
>  	}
> @@ -1588,7 +1588,7 @@ static irqreturn_t stm32f7_i2c_isr_event_thread(int irq, void *data)
>  	if (!ret) {
>  		dev_dbg(i2c_dev->dev, "<%s>: Timed out\n", __func__);
>  		stm32f7_i2c_disable_dma_req(i2c_dev);
> -		dmaengine_terminate_all(dma->chan_using);
> +		dmaengine_terminate_async(dma->chan_using);
>  		f7_msg->result = -ETIMEDOUT;
>  	}
>  
> @@ -1665,7 +1665,7 @@ static irqreturn_t stm32f7_i2c_isr_error(int irq, void *data)
>  	/* Disable dma */
>  	if (i2c_dev->use_dma) {
>  		stm32f7_i2c_disable_dma_req(i2c_dev);
> -		dmaengine_terminate_all(dma->chan_using);
> +		dmaengine_terminate_async(dma->chan_using);
>  	}
>  
>  	i2c_dev->master_mode = false;
> @@ -1702,6 +1702,9 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap,
>  						i2c_dev->adap.timeout);
>  	ret = f7_msg->result;
>  	if (ret) {
> +		if (i2c_dev->use_dma)
> +			dmaengine_synchronize(dma->chan_using);
> +
>  		/*
>  		 * It is possible that some unsent data have already been
>  		 * written into TXDR. To avoid sending old data in a
> @@ -1716,7 +1719,7 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap,
>  		dev_dbg(i2c_dev->dev, "Access to slave 0x%x timed out\n",
>  			i2c_dev->msg->addr);
>  		if (i2c_dev->use_dma)
> -			dmaengine_terminate_all(dma->chan_using);
> +			dmaengine_terminate_sync(dma->chan_using);
>  		stm32f7_i2c_wait_free_bus(i2c_dev);
>  		ret = -ETIMEDOUT;
>  	}
> @@ -1761,6 +1764,9 @@ static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
>  					      i2c_dev->adap.timeout);
>  	ret = f7_msg->result;
>  	if (ret) {
> +		if (i2c_dev->use_dma)
> +			dmaengine_synchronize(dma->chan_using);
> +
>  		/*
>  		 * It is possible that some unsent data have already been
>  		 * written into TXDR. To avoid sending old data in a
> @@ -1774,7 +1780,7 @@ static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
>  	if (!timeout) {
>  		dev_dbg(dev, "Access to slave 0x%x timed out\n", f7_msg->addr);
>  		if (i2c_dev->use_dma)
> -			dmaengine_terminate_all(dma->chan_using);
> +			dmaengine_terminate_sync(dma->chan_using);
>  		stm32f7_i2c_wait_free_bus(i2c_dev);
>  		ret = -ETIMEDOUT;
>  		goto pm_free;
> 

-- 
--
~ Py MORDRET
--

  reply	other threads:[~2021-09-23  8:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20 15:21 [PATCH 0/4] i2c: stm32: various fixes & dmaengine updates Alain Volmat
2021-09-20 15:21 ` [PATCH 1/4] i2c: stm32f7: flush TX FIFO upon transfer errors Alain Volmat
2021-09-23  8:35   ` Pierre Yves MORDRET
2021-11-29 12:12   ` Wolfram Sang
2021-09-20 15:21 ` [PATCH 2/4] i2c: stm32f7: recover the bus on access timeout Alain Volmat
2021-09-23  8:37   ` Pierre Yves MORDRET
2021-11-29 12:17   ` Wolfram Sang
2021-11-29 12:33     ` Alain Volmat
2021-11-29 12:52       ` Wolfram Sang
2021-11-30  8:56         ` Alain Volmat
2021-11-30  9:27           ` Wolfram Sang
2021-11-30  9:27   ` Wolfram Sang
2021-09-20 15:21 ` [PATCH 3/4] i2c: stm32f7: stop dma transfer in case of NACK Alain Volmat
2021-09-23  8:37   ` Pierre Yves MORDRET
2021-11-30  9:27   ` Wolfram Sang
2021-09-20 15:21 ` [PATCH 4/4] i2c: stm32f7: use proper DMAENGINE API for termination Alain Volmat
2021-09-23  8:38   ` Pierre Yves MORDRET [this message]
2021-11-30  9:28   ` Wolfram Sang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1b717a3f-8e2f-2e78-4509-63b04648659b@foss.st.com \
    --to=pierre-yves.mordret@foss.st.com \
    --cc=alain.volmat@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=amelie.delaunay@foss.st.com \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).