spi/omap2_mcspi: Verify TX reg is empty after TX only xfer with DMA

In case of TX only with DMA, the driver assumes that the data
has been transferred once DMA callback in invoked. However,
SPI's shift register may still contain data. Thus, the driver
is supposed to verify that the register is empty and the end of
the SPI transfer has been reached.

Signed-off-by: Ilkka Koskinen <ilkka.koskinen@nokia.com>
Tested-by: Tuomas Katila <ext-tuomas.2.katila@nokia.com>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by Ilkka Koskinen and committed by Grant Likely 2764c500 e1993ed6

+26 -13
+26 -13
drivers/spi/omap2_mcspi.c
··· 296 return 0; 297 } 298 299 static unsigned 300 omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) 301 { ··· 322 u32 l; 323 u8 * rx; 324 const u8 * tx; 325 326 mcspi = spi_master_get_devdata(spi->master); 327 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 328 l = mcspi_cached_chconf0(spi); 329 330 count = xfer->len; 331 c = count; ··· 398 if (tx != NULL) { 399 wait_for_completion(&mcspi_dma->dma_tx_completion); 400 dma_unmap_single(NULL, xfer->tx_dma, count, DMA_TO_DEVICE); 401 } 402 403 if (rx != NULL) { ··· 459 omap2_mcspi_set_enable(spi, 1); 460 } 461 return count; 462 - } 463 - 464 - static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit) 465 - { 466 - unsigned long timeout; 467 - 468 - timeout = jiffies + msecs_to_jiffies(1000); 469 - while (!(__raw_readl(reg) & bit)) { 470 - if (time_after(jiffies, timeout)) 471 - return -1; 472 - cpu_relax(); 473 - } 474 - return 0; 475 } 476 477 static unsigned
··· 296 return 0; 297 } 298 299 + static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit) 300 + { 301 + unsigned long timeout; 302 + 303 + timeout = jiffies + msecs_to_jiffies(1000); 304 + while (!(__raw_readl(reg) & bit)) { 305 + if (time_after(jiffies, timeout)) 306 + return -1; 307 + cpu_relax(); 308 + } 309 + return 0; 310 + } 311 + 312 static unsigned 313 omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) 314 { ··· 309 u32 l; 310 u8 * rx; 311 const u8 * tx; 312 + void __iomem *chstat_reg; 313 314 mcspi = spi_master_get_devdata(spi->master); 315 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 316 l = mcspi_cached_chconf0(spi); 317 + 318 + chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0; 319 320 count = xfer->len; 321 c = count; ··· 382 if (tx != NULL) { 383 wait_for_completion(&mcspi_dma->dma_tx_completion); 384 dma_unmap_single(NULL, xfer->tx_dma, count, DMA_TO_DEVICE); 385 + 386 + /* for TX_ONLY mode, be sure all words have shifted out */ 387 + if (rx == NULL) { 388 + if (mcspi_wait_for_reg_bit(chstat_reg, 389 + OMAP2_MCSPI_CHSTAT_TXS) < 0) 390 + dev_err(&spi->dev, "TXS timed out\n"); 391 + else if (mcspi_wait_for_reg_bit(chstat_reg, 392 + OMAP2_MCSPI_CHSTAT_EOT) < 0) 393 + dev_err(&spi->dev, "EOT timed out\n"); 394 + } 395 } 396 397 if (rx != NULL) { ··· 433 omap2_mcspi_set_enable(spi, 1); 434 } 435 return count; 436 } 437 438 static unsigned