aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/atmel_spi.c
diff options
context:
space:
mode:
authorGerard Kam <gerardk5@verizon.net>2008-08-04 16:41:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-08-04 19:58:45 -0400
commitdc329442b9fd365bec95718013586c07ff600c34 (patch)
treef965829f4421afd65932ad0782502b9583037b39 /drivers/spi/atmel_spi.c
parent5aa6cf302c2758702348aab7457e516d3a5121b9 (diff)
atmel_spi: fix hang due to missed interrupt
For some time my at91sam9260 board with JFFS2 on serial flash (m25p80) would hang when accessing the serial flash and SPI bus. Slowing the SPI clock down to 9 MHz reduced the occurrence of the hang from "always" during boot to a nuisance level that allowed other SW development to continue. Finally had to address this issue when an application stresses the I/O to always cause a hang. Hang seems to be caused by a missed SPI interrupt, so that the task ends up waiting forever after calling spi_sync(). The fix has 2 parts. First is to halt the DMA engine before the "current" PDC registers are loaded. This ensures that the "next" registers are loaded before the DMA operation takes off. The second part of the fix is a kludge that adds a "completion" interrupt in case the ENDRX interrupt for the last segment of the DMA chaining operation was missed. The patch allows the SPI clock for the serial flash to be increased from 9 MHz to 15 MHz (or more?). No hangs or SPI overruns were encountered. Haavard: while this patch does indeed improve things, I still see overruns and CRC errors on my NGW100 board when running the DataFlash at 10 MHz. However, I think some improvement is better than nothing, so I'm passing this on for inclusion in 2.6.27. Signed-off-by: Gerard Kam <gerardk5@verizon.net> Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/spi/atmel_spi.c')
-rw-r--r--drivers/spi/atmel_spi.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index 0c7165660853..95190c619c10 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -184,7 +184,8 @@ static void atmel_spi_next_xfer(struct spi_master *master,
184{ 184{
185 struct atmel_spi *as = spi_master_get_devdata(master); 185 struct atmel_spi *as = spi_master_get_devdata(master);
186 struct spi_transfer *xfer; 186 struct spi_transfer *xfer;
187 u32 len, remaining, total; 187 u32 len, remaining;
188 u32 ieval;
188 dma_addr_t tx_dma, rx_dma; 189 dma_addr_t tx_dma, rx_dma;
189 190
190 if (!as->current_transfer) 191 if (!as->current_transfer)
@@ -197,6 +198,8 @@ static void atmel_spi_next_xfer(struct spi_master *master,
197 xfer = NULL; 198 xfer = NULL;
198 199
199 if (xfer) { 200 if (xfer) {
201 spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
202
200 len = xfer->len; 203 len = xfer->len;
201 atmel_spi_next_xfer_data(master, xfer, &tx_dma, &rx_dma, &len); 204 atmel_spi_next_xfer_data(master, xfer, &tx_dma, &rx_dma, &len);
202 remaining = xfer->len - len; 205 remaining = xfer->len - len;
@@ -234,6 +237,8 @@ static void atmel_spi_next_xfer(struct spi_master *master,
234 as->next_transfer = xfer; 237 as->next_transfer = xfer;
235 238
236 if (xfer) { 239 if (xfer) {
240 u32 total;
241
237 total = len; 242 total = len;
238 atmel_spi_next_xfer_data(master, xfer, &tx_dma, &rx_dma, &len); 243 atmel_spi_next_xfer_data(master, xfer, &tx_dma, &rx_dma, &len);
239 as->next_remaining_bytes = total - len; 244 as->next_remaining_bytes = total - len;
@@ -250,9 +255,11 @@ static void atmel_spi_next_xfer(struct spi_master *master,
250 " next xfer %p: len %u tx %p/%08x rx %p/%08x\n", 255 " next xfer %p: len %u tx %p/%08x rx %p/%08x\n",
251 xfer, xfer->len, xfer->tx_buf, xfer->tx_dma, 256 xfer, xfer->len, xfer->tx_buf, xfer->tx_dma,
252 xfer->rx_buf, xfer->rx_dma); 257 xfer->rx_buf, xfer->rx_dma);
258 ieval = SPI_BIT(ENDRX) | SPI_BIT(OVRES);
253 } else { 259 } else {
254 spi_writel(as, RNCR, 0); 260 spi_writel(as, RNCR, 0);
255 spi_writel(as, TNCR, 0); 261 spi_writel(as, TNCR, 0);
262 ieval = SPI_BIT(RXBUFF) | SPI_BIT(ENDRX) | SPI_BIT(OVRES);
256 } 263 }
257 264
258 /* REVISIT: We're waiting for ENDRX before we start the next 265 /* REVISIT: We're waiting for ENDRX before we start the next
@@ -265,7 +272,7 @@ static void atmel_spi_next_xfer(struct spi_master *master,
265 * 272 *
266 * It should be doable, though. Just not now... 273 * It should be doable, though. Just not now...
267 */ 274 */
268 spi_writel(as, IER, SPI_BIT(ENDRX) | SPI_BIT(OVRES)); 275 spi_writel(as, IER, ieval);
269 spi_writel(as, PTCR, SPI_BIT(TXTEN) | SPI_BIT(RXTEN)); 276 spi_writel(as, PTCR, SPI_BIT(TXTEN) | SPI_BIT(RXTEN));
270} 277}
271 278
@@ -396,7 +403,7 @@ atmel_spi_interrupt(int irq, void *dev_id)
396 403
397 ret = IRQ_HANDLED; 404 ret = IRQ_HANDLED;
398 405
399 spi_writel(as, IDR, (SPI_BIT(ENDTX) | SPI_BIT(ENDRX) 406 spi_writel(as, IDR, (SPI_BIT(RXBUFF) | SPI_BIT(ENDRX)
400 | SPI_BIT(OVRES))); 407 | SPI_BIT(OVRES)));
401 408
402 /* 409 /*
@@ -418,7 +425,7 @@ atmel_spi_interrupt(int irq, void *dev_id)
418 if (xfer->delay_usecs) 425 if (xfer->delay_usecs)
419 udelay(xfer->delay_usecs); 426 udelay(xfer->delay_usecs);
420 427
421 dev_warn(master->dev.parent, "fifo overrun (%u/%u remaining)\n", 428 dev_warn(master->dev.parent, "overrun (%u/%u remaining)\n",
422 spi_readl(as, TCR), spi_readl(as, RCR)); 429 spi_readl(as, TCR), spi_readl(as, RCR));
423 430
424 /* 431 /*
@@ -442,7 +449,7 @@ atmel_spi_interrupt(int irq, void *dev_id)
442 spi_readl(as, SR); 449 spi_readl(as, SR);
443 450
444 atmel_spi_msg_done(master, as, msg, -EIO, 0); 451 atmel_spi_msg_done(master, as, msg, -EIO, 0);
445 } else if (pending & SPI_BIT(ENDRX)) { 452 } else if (pending & (SPI_BIT(RXBUFF) | SPI_BIT(ENDRX))) {
446 ret = IRQ_HANDLED; 453 ret = IRQ_HANDLED;
447 454
448 spi_writel(as, IDR, pending); 455 spi_writel(as, IDR, pending);