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 296 return 0; 297 297 } 298 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 + 299 312 static unsigned 300 313 omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) 301 314 { ··· 322 309 u32 l; 323 310 u8 * rx; 324 311 const u8 * tx; 312 + void __iomem *chstat_reg; 325 313 326 314 mcspi = spi_master_get_devdata(spi->master); 327 315 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 328 316 l = mcspi_cached_chconf0(spi); 317 + 318 + chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0; 329 319 330 320 count = xfer->len; 331 321 c = count; ··· 398 382 if (tx != NULL) { 399 383 wait_for_completion(&mcspi_dma->dma_tx_completion); 400 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 + } 401 395 } 402 396 403 397 if (rx != NULL) { ··· 459 433 omap2_mcspi_set_enable(spi, 1); 460 434 } 461 435 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 436 } 476 437 477 438 static unsigned