linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] atmel_spi: Fix clock polarity
@ 2008-02-21  2:11 Atsushi Nemoto
       [not found] ` <20080221.111138.41629131.nemoto-IGagC74glE2asRnM1LW+pc8NsWr+9BEh@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Atsushi Nemoto @ 2008-02-21  2:11 UTC (permalink / raw)
  To: akpm; +Cc: David Brownell, Haavard Skinnemoen, spi-devel-general, linux-kernel

The atmel_spi driver does not initialize clock polarity correctly
(except for at91rm9200 CS0 channel) in some case.

The atmel_spi driver uses gpio-controlled chipselect.  OTOH spi clock
signal is controlled by CSRn.CPOL bit, but this register controls
clock signal correctly only in 'real transfer' duration.  At the time
of cs_activate() call, CSRn.CPOL will be initialized correctly, but
the controller do not know which channel is to be used next, so clock
signal will stay at the inactive state of last transfer.  If clock
polarity of new transfer and last transfer was differ, new transfer
will start with wrong clock signal state.

For example, if you started SPI MODE 2 or 3 transfer after SPI MODE 0
or 1 transfer, the clock signal state at the assertion of chipselect
will be low.  Of course this will violates SPI transfer.

This patch is short term solution for this problem.  It makes all
CSRn.CPOL match for the transfer before activating chipselect.  For
longer term, the best fix might be to let NPCS0 stay selected
permanently in MR and overwrite CSR0 with to the new slave's settings
before asserting CS.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Acked-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
---
This patch is already in mm tree as atmel_spi-fix-clock-polarity.patch.
I just rewrite description slightly and add my signed-off and acked-by
from Haavard Skinnemoen.

diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index 293b7ca..85687aa 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -87,6 +87,16 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
 	unsigned gpio = (unsigned) spi->controller_data;
 	unsigned active = spi->mode & SPI_CS_HIGH;
 	u32 mr;
+	int i;
+	u32 csr;
+	u32 cpol = (spi->mode & SPI_CPOL) ? SPI_BIT(CPOL) : 0;
+
+	/* Make sure clock polarity is correct */
+	for (i = 0; i < spi->master->num_chipselect; i++) {
+		csr = spi_readl(as, CSR0 + 4 * i);
+		if ((csr ^ cpol) & SPI_BIT(CPOL))
+			spi_writel(as, CSR0 + 4 * i, csr ^ SPI_BIT(CPOL));
+	}
 
 	mr = spi_readl(as, MR);
 	mr = SPI_BFINS(PCS, ~(1 << spi->chip_select), mr);

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

* Re: [PATCH] atmel_spi: Fix clock polarity
       [not found] ` <20080221.111138.41629131.nemoto-IGagC74glE2asRnM1LW+pc8NsWr+9BEh@public.gmane.org>
@ 2008-02-23  8:05   ` Andrew Morton
       [not found]     ` <20080223000507.3863d71f.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2008-02-23  8:05 UTC (permalink / raw)
  To: Atsushi Nemoto
  Cc: David Brownell,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Thu, 21 Feb 2008 11:11:38 +0900 (JST) Atsushi Nemoto <anemo-7JcRY8pycbNHfZP73Gtkiw@public.gmane.org> wrote:

> This patch is already in mm tree as atmel_spi-fix-clock-polarity.patch.
> I just rewrite description slightly and add my signed-off and acked-by
> from Haavard Skinnemoen.

I had it queued for 2.6.26 which I guess was wrong.  I'll bump it into
2.6.25.  Is it needed in 2.6.24.x?

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

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

* Re: [PATCH] atmel_spi: Fix clock polarity
       [not found]     ` <20080223000507.3863d71f.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
@ 2008-02-24  0:56       ` Haavard Skinnemoen
  0 siblings, 0 replies; 3+ messages in thread
From: Haavard Skinnemoen @ 2008-02-24  0:56 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Brownell,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	Atsushi Nemoto, linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Sat, 23 Feb 2008 00:05:07 -0800
Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org> wrote:

> I had it queued for 2.6.26 which I guess was wrong.  I'll bump it into
> 2.6.25.

Thanks!

> Is it needed in 2.6.24.x?

I think so. The last time that code was changed was before 2.6.23
AFAICT, so perhaps 2.6.23.x as well.

I'll have a closer look and pass it on to the stable team when it hits
mainline.

Haavard

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

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

end of thread, other threads:[~2008-02-24  0:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-21  2:11 [PATCH] atmel_spi: Fix clock polarity Atsushi Nemoto
     [not found] ` <20080221.111138.41629131.nemoto-IGagC74glE2asRnM1LW+pc8NsWr+9BEh@public.gmane.org>
2008-02-23  8:05   ` Andrew Morton
     [not found]     ` <20080223000507.3863d71f.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2008-02-24  0:56       ` Haavard Skinnemoen

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