Linux-SPI Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] spi: fix cs_change for last transfer
@ 2020-03-15 17:08 Michał Mirosław
  2020-03-16 12:17 ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Michał Mirosław @ 2020-03-15 17:08 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA

Generic spi_transfer_one_message() implementation introduced in
commit b158935f70b9 has a bug in cs_change handling: it keeps CS
asserted when cs_change is set. Fix it.

Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Fixes: b158935f70b9 ("spi: Provide common spi_message processing loop")
Signed-off-by: Michał Mirosław <mirq-linux-CoA6ZxLDdyEEUmgCuDUIdw@public.gmane.org>
---
 drivers/spi/spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 8994545367a2..5012eabde468 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1206,7 +1206,7 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
 				    struct spi_message *msg)
 {
 	struct spi_transfer *xfer;
-	bool keep_cs = false;
+	bool keep_cs = true;
 	int ret = 0;
 	struct spi_statistics *statm = &ctlr->statistics;
 	struct spi_statistics *stats = &msg->spi->statistics;
@@ -1268,7 +1268,7 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
 		if (xfer->cs_change) {
 			if (list_is_last(&xfer->transfer_list,
 					 &msg->transfers)) {
-				keep_cs = true;
+				keep_cs = false;
 			} else {
 				spi_set_cs(msg->spi, false);
 				_spi_transfer_cs_change_delay(msg, xfer);
-- 
2.20.1

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

* Re: [PATCH] spi: fix cs_change for last transfer
  2020-03-15 17:08 [PATCH] spi: fix cs_change for last transfer Michał Mirosław
@ 2020-03-16 12:17 ` Mark Brown
  2020-03-16 14:34   ` Michał Mirosław
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2020-03-16 12:17 UTC (permalink / raw)
  To: Michał Mirosław; +Cc: linux-spi, linux-kernel

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

On Sun, Mar 15, 2020 at 06:08:53PM +0100, Michał Mirosław wrote:

> Generic spi_transfer_one_message() implementation introduced in
> commit b158935f70b9 has a bug in cs_change handling: it keeps CS
> asserted when cs_change is set. Fix it.

>  	struct spi_transfer *xfer;
> -	bool keep_cs = false;
> +	bool keep_cs = true;
>  	int ret = 0;
>  	struct spi_statistics *statm = &ctlr->statistics;
>  	struct spi_statistics *stats = &msg->spi->statistics;
> @@ -1268,7 +1268,7 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
>  		if (xfer->cs_change) {
>  			if (list_is_last(&xfer->transfer_list,
>  					 &msg->transfers)) {
> -				keep_cs = true;
> +				keep_cs = false;
>  			} else {

This is the opposite of the intended behaviour - we want to deassert
chip select at the end of the message unless cs_change is set on the
last transfer.  If this were broken I would expect to see widespread
problems being reported.

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

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

* Re: [PATCH] spi: fix cs_change for last transfer
  2020-03-16 12:17 ` Mark Brown
@ 2020-03-16 14:34   ` Michał Mirosław
       [not found]     ` <20200316143455.GA19141-cHozx32mtrEEUmgCuDUIdw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Michał Mirosław @ 2020-03-16 14:34 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel

On Mon, Mar 16, 2020 at 12:17:50PM +0000, Mark Brown wrote:
> On Sun, Mar 15, 2020 at 06:08:53PM +0100, Michał Mirosław wrote:
> > Generic spi_transfer_one_message() implementation introduced in
> > commit b158935f70b9 has a bug in cs_change handling: it keeps CS
> > asserted when cs_change is set. Fix it.
> 
> >  	struct spi_transfer *xfer;
> > -	bool keep_cs = false;
> > +	bool keep_cs = true;
> >  	int ret = 0;
> >  	struct spi_statistics *statm = &ctlr->statistics;
> >  	struct spi_statistics *stats = &msg->spi->statistics;
> > @@ -1268,7 +1268,7 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
> >  		if (xfer->cs_change) {
> >  			if (list_is_last(&xfer->transfer_list,
> >  					 &msg->transfers)) {
> > -				keep_cs = true;
> > +				keep_cs = false;
> >  			} else {
> 
> This is the opposite of the intended behaviour - we want to deassert
> chip select at the end of the message unless cs_change is set on the
> last transfer.  If this were broken I would expect to see widespread
> problems being reported.

This is unfortunate naming I suppose. I reread the spi.h comments
a few more times and it seems indeed, that .cs_change == 1 on last
transfer means to a driver: "you may leave CS unchanged" - quite the
reverse compared to non-last transfers.

Please drop this patch then.

Best Regards
Michał Mirosław

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

* Re: [PATCH] spi: fix cs_change for last transfer
       [not found]     ` <20200316143455.GA19141-cHozx32mtrEEUmgCuDUIdw@public.gmane.org>
@ 2020-03-16 15:13       ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2020-03-16 15:13 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA

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

On Mon, Mar 16, 2020 at 03:34:55PM +0100, Michał Mirosław wrote:
> On Mon, Mar 16, 2020 at 12:17:50PM +0000, Mark Brown wrote:

> > This is the opposite of the intended behaviour - we want to deassert
> > chip select at the end of the message unless cs_change is set on the
> > last transfer.  If this were broken I would expect to see widespread
> > problems being reported.

> This is unfortunate naming I suppose. I reread the spi.h comments
> a few more times and it seems indeed, that .cs_change == 1 on last
> transfer means to a driver: "you may leave CS unchanged" - quite the
> reverse compared to non-last transfers.

cs_change also means that we should add an extra chip select transition
on transfers other than the last.

> Please drop this patch then.

OK.

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

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-15 17:08 [PATCH] spi: fix cs_change for last transfer Michał Mirosław
2020-03-16 12:17 ` Mark Brown
2020-03-16 14:34   ` Michał Mirosław
     [not found]     ` <20200316143455.GA19141-cHozx32mtrEEUmgCuDUIdw@public.gmane.org>
2020-03-16 15:13       ` Mark Brown

Linux-SPI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-spi/0 linux-spi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-spi linux-spi/ https://lore.kernel.org/linux-spi \
		linux-spi@vger.kernel.org
	public-inbox-index linux-spi

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-spi


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git