All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: Fix handling of cs_change in core implementation
@ 2014-03-30  0:27 Mark Brown
       [not found] ` <1396139265-28900-1-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2014-03-30  0:27 UTC (permalink / raw)
  To: Gerhard Sittig
  Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linaro-kernel-cunTk1MwBs8s++Sfvej+rw, Mark Brown

From: Mark Brown <broonie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

The core implementation of cs_change didn't follow the documentation
which says that cs_change in the middle of the transfer means to briefly
deassert chip select, instead it followed buggy drivers which change the
polarity of chip select.  Use a delay of 10us between deassert and
reassert simply from pulling numbers out of a hat.

Reported-by: Gerhard Sittig <gsi-ynQEQJNshbs@public.gmane.org>
Signed-off-by: Mark Brown <broonie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
---

Compile tested only.

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

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 121c43b..4eb9bf0 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -754,7 +754,6 @@ static int spi_transfer_one_message(struct spi_master *master,
 				    struct spi_message *msg)
 {
 	struct spi_transfer *xfer;
-	bool cur_cs = true;
 	bool keep_cs = false;
 	int ret = 0;
 	int ms = 1;
@@ -800,8 +799,9 @@ static int spi_transfer_one_message(struct spi_master *master,
 					 &msg->transfers)) {
 				keep_cs = true;
 			} else {
-				cur_cs = !cur_cs;
-				spi_set_cs(msg->spi, cur_cs);
+				spi_set_cs(msg->spi, false);
+				udelay(10);
+				spi_set_cs(msg->spi, true);
 			}
 		}
 
-- 
1.9.1

--
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: Fix handling of cs_change in core implementation
       [not found] ` <1396139265-28900-1-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2014-03-31  7:45   ` Gerhard Sittig
       [not found]     ` <20140331074529.GE2775-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Gerhard Sittig @ 2014-03-31  7:45 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linaro-kernel-cunTk1MwBs8s++Sfvej+rw, Mark Brown

On Sun, 2014-03-30 at 00:27 +0000, Mark Brown wrote:
> 
> From: Mark Brown <broonie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> 
> The core implementation of cs_change didn't follow the documentation
> which says that cs_change in the middle of the transfer means to briefly
> deassert chip select, instead it followed buggy drivers which change the
> polarity of chip select.  Use a delay of 10us between deassert and
> reassert simply from pulling numbers out of a hat.
> 
> Reported-by: Gerhard Sittig <gsi-ynQEQJNshbs@public.gmane.org>
> Signed-off-by: Mark Brown <broonie-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>

The change looks good to me.  The resulting behaviour now is what
the documentation suggests (brief deassertion of the CS signal).
The previous inversion was unexpected.

The delay between deassertion and re-assertion looks good, too.
It allows for propagation of the change through the hardware.
Those who need longer pauses still can construct individual
messages.  There's probably no need to change the boolean
"cs_change" into a numerical "deassertion pause length" spec.


virtually yours
Gerhard Sittig
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr. 5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office-ynQEQJNshbs@public.gmane.org
--
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

* Re: [PATCH] spi: Fix handling of cs_change in core implementation
       [not found]     ` <20140331074529.GE2775-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
@ 2014-03-31 17:17       ` Mark Brown
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Brown @ 2014-03-31 17:17 UTC (permalink / raw)
  To: Gerhard Sittig
  Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA, linaro-kernel-cunTk1MwBs8s++Sfvej+rw

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

On Mon, Mar 31, 2014 at 09:45:29AM +0200, Gerhard Sittig wrote:

> The delay between deassertion and re-assertion looks good, too.
> It allows for propagation of the change through the hardware.
> Those who need longer pauses still can construct individual
> messages.  There's probably no need to change the boolean
> "cs_change" into a numerical "deassertion pause length" spec.

I'm more worried about board specific requirements to increase the delay
there than I am about devices, or about devices that wish to lower the
delay.  But I do think it's likely to be OK in practice, someone who
actually runs into problems can worry about enhancements.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2014-03-31 17:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-30  0:27 [PATCH] spi: Fix handling of cs_change in core implementation Mark Brown
     [not found] ` <1396139265-28900-1-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2014-03-31  7:45   ` Gerhard Sittig
     [not found]     ` <20140331074529.GE2775-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org>
2014-03-31 17:17       ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.