linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back
@ 2022-08-07 14:04 Robin Reckmann
  2022-08-07 15:31 ` Caleb Connolly
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Robin Reckmann @ 2022-08-07 14:04 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Sumit Semwal,
	Christian König
  Cc: Robin Reckmann, linux-arm-msm, linux-i2c, linux-kernel,
	linux-media, dri-devel, linaro-mm-sig

Fix i2c transfers using GPI DMA mode for all message types that do not set
the I2C_M_DMA_SAFE flag (e.g. SMBus "read byte").

In this case a bounce buffer is returned by i2c_get_dma_safe_msg_buf(),
and it has to synced back to the message after the transfer is done.

Add missing assignment of dma buffer in geni_i2c_gpi().

Set xferred in i2c_put_dma_safe_msg_buf() to true in case of no error to
ensure the sync-back of this dma buffer to the message.

Signed-off-by: Robin Reckmann <robin.reckmann@gmail.com>
---
 drivers/i2c/busses/i2c-qcom-geni.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
index 6ac402ea58fb..d3541e94794e 100644
--- a/drivers/i2c/busses/i2c-qcom-geni.c
+++ b/drivers/i2c/busses/i2c-qcom-geni.c
@@ -484,12 +484,12 @@ static void geni_i2c_gpi_unmap(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
 {
 	if (tx_buf) {
 		dma_unmap_single(gi2c->se.dev->parent, tx_addr, msg->len, DMA_TO_DEVICE);
-		i2c_put_dma_safe_msg_buf(tx_buf, msg, false);
+		i2c_put_dma_safe_msg_buf(tx_buf, msg, !gi2c->err);
 	}
 
 	if (rx_buf) {
 		dma_unmap_single(gi2c->se.dev->parent, rx_addr, msg->len, DMA_FROM_DEVICE);
-		i2c_put_dma_safe_msg_buf(rx_buf, msg, false);
+		i2c_put_dma_safe_msg_buf(rx_buf, msg, !gi2c->err);
 	}
 }
 
@@ -553,6 +553,7 @@ static int geni_i2c_gpi(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
 	desc->callback_param = gi2c;
 
 	dmaengine_submit(desc);
+	*buf = dma_buf;
 	*dma_addr_p = addr;
 
 	return 0;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back
  2022-08-07 14:04 [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back Robin Reckmann
@ 2022-08-07 15:31 ` Caleb Connolly
  2022-08-08  5:54 ` Wolfram Sang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Caleb Connolly @ 2022-08-07 15:31 UTC (permalink / raw)
  To: Robin Reckmann, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Sumit Semwal, Christian König
  Cc: Robin Reckmann, linux-arm-msm, linux-i2c, linux-kernel,
	linux-media, dri-devel, linaro-mm-sig



On 07/08/2022 15:04, Robin Reckmann wrote:
> Fix i2c transfers using GPI DMA mode for all message types that do not set
> the I2C_M_DMA_SAFE flag (e.g. SMBus "read byte").
>
> In this case a bounce buffer is returned by i2c_get_dma_safe_msg_buf(),
> and it has to synced back to the message after the transfer is done.
>
> Add missing assignment of dma buffer in geni_i2c_gpi().
>
> Set xferred in i2c_put_dma_safe_msg_buf() to true in case of no error to
> ensure the sync-back of this dma buffer to the message.
Thanks for sending this, it fixes GPI DMA on the PocoPhone F1 and Pixel 3!
>
> Signed-off-by: Robin Reckmann <robin.reckmann@gmail.com>Reviewed-by: Caleb Connolly <caleb@connolly.tech>
> ---
>   drivers/i2c/busses/i2c-qcom-geni.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
> index 6ac402ea58fb..d3541e94794e 100644
> --- a/drivers/i2c/busses/i2c-qcom-geni.c
> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
> @@ -484,12 +484,12 @@ static void geni_i2c_gpi_unmap(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
>   {
>   	if (tx_buf) {
>   		dma_unmap_single(gi2c->se.dev->parent, tx_addr, msg->len, DMA_TO_DEVICE);
> -		i2c_put_dma_safe_msg_buf(tx_buf, msg, false);
> +		i2c_put_dma_safe_msg_buf(tx_buf, msg, !gi2c->err);
>   	}
>
>   	if (rx_buf) {
>   		dma_unmap_single(gi2c->se.dev->parent, rx_addr, msg->len, DMA_FROM_DEVICE);
> -		i2c_put_dma_safe_msg_buf(rx_buf, msg, false);
> +		i2c_put_dma_safe_msg_buf(rx_buf, msg, !gi2c->err);
>   	}
>   }
>
> @@ -553,6 +553,7 @@ static int geni_i2c_gpi(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
>   	desc->callback_param = gi2c;
>
>   	dmaengine_submit(desc);
> +	*buf = dma_buf;
>   	*dma_addr_p = addr;
>
>   	return 0;
> --
> 2.25.1
>

--
Kind Regards,
Caleb


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back
  2022-08-07 14:04 [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back Robin Reckmann
  2022-08-07 15:31 ` Caleb Connolly
@ 2022-08-08  5:54 ` Wolfram Sang
  2022-08-08 13:38   ` Robin Reckmann
  2022-08-08  6:59 ` Luca Weiss
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Wolfram Sang @ 2022-08-08  5:54 UTC (permalink / raw)
  To: Robin Reckmann
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Sumit Semwal,
	Christian König, Robin Reckmann, linux-arm-msm, linux-i2c,
	linux-kernel, linux-media, dri-devel, linaro-mm-sig

[-- Attachment #1: Type: text/plain, Size: 665 bytes --]

On Sun, Aug 07, 2022 at 11:04:54PM +0900, Robin Reckmann wrote:
> Fix i2c transfers using GPI DMA mode for all message types that do not set
> the I2C_M_DMA_SAFE flag (e.g. SMBus "read byte").
> 
> In this case a bounce buffer is returned by i2c_get_dma_safe_msg_buf(),
> and it has to synced back to the message after the transfer is done.
> 
> Add missing assignment of dma buffer in geni_i2c_gpi().
> 
> Set xferred in i2c_put_dma_safe_msg_buf() to true in case of no error to
> ensure the sync-back of this dma buffer to the message.
> 
> Signed-off-by: Robin Reckmann <robin.reckmann@gmail.com>

Thank you! What would be a Fixes tag for this?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back
  2022-08-07 14:04 [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back Robin Reckmann
  2022-08-07 15:31 ` Caleb Connolly
  2022-08-08  5:54 ` Wolfram Sang
@ 2022-08-08  6:59 ` Luca Weiss
  2022-08-08 11:46 ` Konrad Dybcio
  2022-08-11 12:14 ` Wolfram Sang
  4 siblings, 0 replies; 7+ messages in thread
From: Luca Weiss @ 2022-08-08  6:59 UTC (permalink / raw)
  To: Robin Reckmann, Andy Gross, Bjorn Andersson, Konrad Dybcio,
	Sumit Semwal, Christian König
  Cc: Robin Reckmann, linux-arm-msm, linux-i2c, linux-kernel,
	linux-media, dri-devel, linaro-mm-sig

Hi Robin,

On Sun Aug 7, 2022 at 4:04 PM CEST, Robin Reckmann wrote:
> Fix i2c transfers using GPI DMA mode for all message types that do not set
> the I2C_M_DMA_SAFE flag (e.g. SMBus "read byte").
>
> In this case a bounce buffer is returned by i2c_get_dma_safe_msg_buf(),
> and it has to synced back to the message after the transfer is done.
>
> Add missing assignment of dma buffer in geni_i2c_gpi().
>
> Set xferred in i2c_put_dma_safe_msg_buf() to true in case of no error to
> ensure the sync-back of this dma buffer to the message.
>
> Signed-off-by: Robin Reckmann <robin.reckmann@gmail.com>

This makes I2C with GPI DMA work on sm6350/sm7725 fairphone-fp4!
Thanks for fixing this!

Tested-by: Luca Weiss <luca.weiss@fairphone.com>

Regards
Luca

> ---
>  drivers/i2c/busses/i2c-qcom-geni.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
> index 6ac402ea58fb..d3541e94794e 100644
> --- a/drivers/i2c/busses/i2c-qcom-geni.c
> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
> @@ -484,12 +484,12 @@ static void geni_i2c_gpi_unmap(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
>  {
>  	if (tx_buf) {
>  		dma_unmap_single(gi2c->se.dev->parent, tx_addr, msg->len, DMA_TO_DEVICE);
> -		i2c_put_dma_safe_msg_buf(tx_buf, msg, false);
> +		i2c_put_dma_safe_msg_buf(tx_buf, msg, !gi2c->err);
>  	}
>  
>  	if (rx_buf) {
>  		dma_unmap_single(gi2c->se.dev->parent, rx_addr, msg->len, DMA_FROM_DEVICE);
> -		i2c_put_dma_safe_msg_buf(rx_buf, msg, false);
> +		i2c_put_dma_safe_msg_buf(rx_buf, msg, !gi2c->err);
>  	}
>  }
>  
> @@ -553,6 +553,7 @@ static int geni_i2c_gpi(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
>  	desc->callback_param = gi2c;
>  
>  	dmaengine_submit(desc);
> +	*buf = dma_buf;
>  	*dma_addr_p = addr;
>  
>  	return 0;
> -- 
> 2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back
  2022-08-07 14:04 [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back Robin Reckmann
                   ` (2 preceding siblings ...)
  2022-08-08  6:59 ` Luca Weiss
@ 2022-08-08 11:46 ` Konrad Dybcio
  2022-08-11 12:14 ` Wolfram Sang
  4 siblings, 0 replies; 7+ messages in thread
From: Konrad Dybcio @ 2022-08-08 11:46 UTC (permalink / raw)
  To: Robin Reckmann, Andy Gross, Bjorn Andersson, Sumit Semwal,
	Christian König
  Cc: Robin Reckmann, linux-arm-msm, linux-i2c, linux-kernel,
	linux-media, dri-devel, linaro-mm-sig



On 7.08.2022 16:04, Robin Reckmann wrote:
> Fix i2c transfers using GPI DMA mode for all message types that do not set
> the I2C_M_DMA_SAFE flag (e.g. SMBus "read byte").
> 
> In this case a bounce buffer is returned by i2c_get_dma_safe_msg_buf(),
> and it has to synced back to the message after the transfer is done.
> 
> Add missing assignment of dma buffer in geni_i2c_gpi().
> 
> Set xferred in i2c_put_dma_safe_msg_buf() to true in case of no error to
> ensure the sync-back of this dma buffer to the message.
> 
> Signed-off-by: Robin Reckmann <robin.reckmann@gmail.com>
> ---
Makes SM8450 Xperia 1 IV boot with the touchscreen but enabled (previously
it would simply crash), but the touchscreen itself does not work yet (not
yet sure if something is still missing on my part wrt hw setup):

[    1.838819] gpi 900000.dma-controller: Error in Transaction
[    1.838944] geni_i2c 990000.i2c: DMA txn failed:3
[    1.839166] geni_i2c 990000.i2c: GPI transfer failed: -5


Still, this is a very nice improvement.

Reviewed-by: Konrad Dybcio <konrad.dybcio@somainline.org>

Konrad
>  drivers/i2c/busses/i2c-qcom-geni.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
> index 6ac402ea58fb..d3541e94794e 100644
> --- a/drivers/i2c/busses/i2c-qcom-geni.c
> +++ b/drivers/i2c/busses/i2c-qcom-geni.c
> @@ -484,12 +484,12 @@ static void geni_i2c_gpi_unmap(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
>  {
>  	if (tx_buf) {
>  		dma_unmap_single(gi2c->se.dev->parent, tx_addr, msg->len, DMA_TO_DEVICE);
> -		i2c_put_dma_safe_msg_buf(tx_buf, msg, false);
> +		i2c_put_dma_safe_msg_buf(tx_buf, msg, !gi2c->err);
>  	}
>  
>  	if (rx_buf) {
>  		dma_unmap_single(gi2c->se.dev->parent, rx_addr, msg->len, DMA_FROM_DEVICE);
> -		i2c_put_dma_safe_msg_buf(rx_buf, msg, false);
> +		i2c_put_dma_safe_msg_buf(rx_buf, msg, !gi2c->err);
>  	}
>  }
>  
> @@ -553,6 +553,7 @@ static int geni_i2c_gpi(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
>  	desc->callback_param = gi2c;
>  
>  	dmaengine_submit(desc);
> +	*buf = dma_buf;
>  	*dma_addr_p = addr;
>  
>  	return 0;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back
  2022-08-08  5:54 ` Wolfram Sang
@ 2022-08-08 13:38   ` Robin Reckmann
  0 siblings, 0 replies; 7+ messages in thread
From: Robin Reckmann @ 2022-08-08 13:38 UTC (permalink / raw)
  To: Wolfram Sang, Robin Reckmann, Andy Gross, Bjorn Andersson,
	Konrad Dybcio, Sumit Semwal, Christian König,
	Robin Reckmann, linux-arm-msm, linux-i2c, linux-kernel,
	linux-media, dri-devel, linaro-mm-sig



On Mon, 8 Aug 2022, Wolfram Sang wrote:

> On Sun, Aug 07, 2022 at 11:04:54PM +0900, Robin Reckmann wrote:
>> Fix i2c transfers using GPI DMA mode for all message types that do not set
>> the I2C_M_DMA_SAFE flag (e.g. SMBus "read byte").
>>
>> In this case a bounce buffer is returned by i2c_get_dma_safe_msg_buf(),
>> and it has to synced back to the message after the transfer is done.
>>
>> Add missing assignment of dma buffer in geni_i2c_gpi().
>>
>> Set xferred in i2c_put_dma_safe_msg_buf() to true in case of no error to
>> ensure the sync-back of this dma buffer to the message.
>>
>> Signed-off-by: Robin Reckmann <robin.reckmann@gmail.com>
>
> Thank you! What would be a Fixes tag for this?
>
>
Thanks for having a look!

Fixes: d8703554f4de ("i2c: qcom-geni: Add support for GPI DMA")

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back
  2022-08-07 14:04 [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back Robin Reckmann
                   ` (3 preceding siblings ...)
  2022-08-08 11:46 ` Konrad Dybcio
@ 2022-08-11 12:14 ` Wolfram Sang
  4 siblings, 0 replies; 7+ messages in thread
From: Wolfram Sang @ 2022-08-11 12:14 UTC (permalink / raw)
  To: Robin Reckmann
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Sumit Semwal,
	Christian König, Robin Reckmann, linux-arm-msm, linux-i2c,
	linux-kernel, linux-media, dri-devel, linaro-mm-sig

[-- Attachment #1: Type: text/plain, Size: 650 bytes --]

On Sun, Aug 07, 2022 at 11:04:54PM +0900, Robin Reckmann wrote:
> Fix i2c transfers using GPI DMA mode for all message types that do not set
> the I2C_M_DMA_SAFE flag (e.g. SMBus "read byte").
> 
> In this case a bounce buffer is returned by i2c_get_dma_safe_msg_buf(),
> and it has to synced back to the message after the transfer is done.
> 
> Add missing assignment of dma buffer in geni_i2c_gpi().
> 
> Set xferred in i2c_put_dma_safe_msg_buf() to true in case of no error to
> ensure the sync-back of this dma buffer to the message.
> 
> Signed-off-by: Robin Reckmann <robin.reckmann@gmail.com>

Applied to for-current, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-08-11 12:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-07 14:04 [PATCH] i2c: qcom-geni: Fix GPI DMA buffer sync-back Robin Reckmann
2022-08-07 15:31 ` Caleb Connolly
2022-08-08  5:54 ` Wolfram Sang
2022-08-08 13:38   ` Robin Reckmann
2022-08-08  6:59 ` Luca Weiss
2022-08-08 11:46 ` Konrad Dybcio
2022-08-11 12:14 ` Wolfram Sang

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).