linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: atmel: fix handling of cs_change set on non-last xfer
@ 2016-01-18  1:25 Mans Rullgard
       [not found] ` <1453080351-29593-1-git-send-email-mans-2StjZFpD7GcAvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Mans Rullgard @ 2016-01-18  1:25 UTC (permalink / raw)
  To: Nicolas Ferre, Yang, Wenyou
  Cc: Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

The driver does the wrong thing when cs_change is set on a non-last
xfer in a message.  When cs_change is set, the driver deactivates the
CS and leaves it off until a later xfer again has cs_change set whereas
it should be briefly toggling CS off and on again.

This patch brings the behaviour of the driver back in line with the
documentation and common sense.  The delay of 10 us is the same as is
used by the default spi_transfer_one_message() function in spi.c.

Fixes: 8090d6d1a415 ("spi: atmel: Refactor spi-atmel to use SPI framework queue")
Signed-off-by: Mans Rullgard <mans-2StjZFpD7GcAvxtiuMwx3w@public.gmane.org>
---
 drivers/spi/spi-atmel.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index aebad36391c9..4b8ccf1f897e 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -315,7 +315,6 @@ struct atmel_spi {
 	struct atmel_spi_dma	dma;
 
 	bool			keep_cs;
-	bool			cs_active;
 
 	u32			fifo_size;
 };
@@ -1406,11 +1405,9 @@ static int atmel_spi_one_transfer(struct spi_master *master,
 				 &msg->transfers)) {
 			as->keep_cs = true;
 		} else {
-			as->cs_active = !as->cs_active;
-			if (as->cs_active)
-				cs_activate(as, msg->spi);
-			else
-				cs_deactivate(as, msg->spi);
+			cs_deactivate(as, msg->spi);
+			udelay(10);
+			cs_activate(as, msg->spi);
 		}
 	}
 
@@ -1433,7 +1430,6 @@ static int atmel_spi_transfer_one_message(struct spi_master *master,
 	atmel_spi_lock(as);
 	cs_activate(as, spi);
 
-	as->cs_active = true;
 	as->keep_cs = false;
 
 	msg->status = 0;
-- 
2.7.0

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] spi: atmel: fix handling of cs_change set on non-last xfer
       [not found] ` <1453080351-29593-1-git-send-email-mans-2StjZFpD7GcAvxtiuMwx3w@public.gmane.org>
@ 2016-01-26 17:01   ` Nicolas Ferre
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Ferre @ 2016-01-26 17:01 UTC (permalink / raw)
  To: Mans Rullgard, Yang, Wenyou, Mark Brown
  Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Le 18/01/2016 02:25, Mans Rullgard a écrit :
> The driver does the wrong thing when cs_change is set on a non-last
> xfer in a message.  When cs_change is set, the driver deactivates the
> CS and leaves it off until a later xfer again has cs_change set whereas
> it should be briefly toggling CS off and on again.
> 
> This patch brings the behaviour of the driver back in line with the
> documentation and common sense.  The delay of 10 us is the same as is
> used by the default spi_transfer_one_message() function in spi.c.
> 
> Fixes: 8090d6d1a415 ("spi: atmel: Refactor spi-atmel to use SPI framework queue")
> Signed-off-by: Mans Rullgard <mans-2StjZFpD7GcAvxtiuMwx3w@public.gmane.org>

Hi Mans,

Yes, it seems to be a sensible thing to do:
Acked-by: Nicolas Ferre <nicolas.ferre-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>

Thanks, best regards.

> ---
>  drivers/spi/spi-atmel.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
> index aebad36391c9..4b8ccf1f897e 100644
> --- a/drivers/spi/spi-atmel.c
> +++ b/drivers/spi/spi-atmel.c
> @@ -315,7 +315,6 @@ struct atmel_spi {
>  	struct atmel_spi_dma	dma;
>  
>  	bool			keep_cs;
> -	bool			cs_active;
>  
>  	u32			fifo_size;
>  };
> @@ -1406,11 +1405,9 @@ static int atmel_spi_one_transfer(struct spi_master *master,
>  				 &msg->transfers)) {
>  			as->keep_cs = true;
>  		} else {
> -			as->cs_active = !as->cs_active;
> -			if (as->cs_active)
> -				cs_activate(as, msg->spi);
> -			else
> -				cs_deactivate(as, msg->spi);
> +			cs_deactivate(as, msg->spi);
> +			udelay(10);
> +			cs_activate(as, msg->spi);
>  		}
>  	}
>  
> @@ -1433,7 +1430,6 @@ static int atmel_spi_transfer_one_message(struct spi_master *master,
>  	atmel_spi_lock(as);
>  	cs_activate(as, spi);
>  
> -	as->cs_active = true;
>  	as->keep_cs = false;
>  
>  	msg->status = 0;
> 


-- 
Nicolas Ferre
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH] spi: atmel: fix handling of cs_change set on non-last xfer
@ 2019-10-18 15:35 Gregory CLEMENT
  0 siblings, 0 replies; 3+ messages in thread
From: Gregory CLEMENT @ 2019-10-18 15:35 UTC (permalink / raw)
  To: Mark Brown, linux-spi, linux-kernel
  Cc: Nicolas Ferre, Alexandre Belloni, Ludovic Desroches,
	linux-arm-kernel, Thomas Petazzoni, Mans Rullgard, Nicolas Ferre,
	Gregory CLEMENT

From: Mans Rullgard <mans@mansr.com>

The driver does the wrong thing when cs_change is set on a non-last
xfer in a message.  When cs_change is set, the driver deactivates the
CS and leaves it off until a later xfer again has cs_change set whereas
it should be briefly toggling CS off and on again.

This patch brings the behaviour of the driver back in line with the
documentation and common sense.  The delay of 10 us is the same as is
used by the default spi_transfer_one_message() function in spi.c.
[gregory: rebased on for-5.5 from spi tree]
Fixes: 8090d6d1a415 ("spi: atmel: Refactor spi-atmel to use SPI framework queue")
Signed-off-by: Mans Rullgard <mans@mansr.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Gregory CLEMENT <gregory.clement@bootlin.com>
---
Hello,

This patch was first submitted 2 years[1] but was never applied while it
has received the acked-by from Nicolas, and I don't see any review
against it on the mailing list. So I resend it now.

Thanks,

Gregory

[1]: https://lkml.org/lkml/2016/1/17/31

 drivers/spi/spi-atmel.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index d88e2aa64839..9e84a93083bc 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -277,7 +277,6 @@ struct atmel_spi {
 	bool			use_pdc;
 
 	bool			keep_cs;
-	bool			cs_active;
 
 	u32			fifo_size;
 	u8			native_cs_free;
@@ -1416,11 +1415,9 @@ static int atmel_spi_one_transfer(struct spi_master *master,
 				 &msg->transfers)) {
 			as->keep_cs = true;
 		} else {
-			as->cs_active = !as->cs_active;
-			if (as->cs_active)
-				cs_activate(as, msg->spi);
-			else
-				cs_deactivate(as, msg->spi);
+			cs_deactivate(as, msg->spi);
+			udelay(10);
+			cs_activate(as, msg->spi);
 		}
 	}
 
@@ -1443,7 +1440,6 @@ static int atmel_spi_transfer_one_message(struct spi_master *master,
 	atmel_spi_lock(as);
 	cs_activate(as, spi);
 
-	as->cs_active = true;
 	as->keep_cs = false;
 
 	msg->status = 0;
-- 
2.23.0

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

end of thread, other threads:[~2019-10-18 15:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-18  1:25 [PATCH] spi: atmel: fix handling of cs_change set on non-last xfer Mans Rullgard
     [not found] ` <1453080351-29593-1-git-send-email-mans-2StjZFpD7GcAvxtiuMwx3w@public.gmane.org>
2016-01-26 17:01   ` Nicolas Ferre
  -- strict thread matches above, loose matches on Subject: below --
2019-10-18 15:35 Gregory CLEMENT

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