aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-rockchip.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi/spi-rockchip.c')
-rw-r--r--drivers/spi/spi-rockchip.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
index c0743604b906..f96ea8a38d64 100644
--- a/drivers/spi/spi-rockchip.c
+++ b/drivers/spi/spi-rockchip.c
@@ -220,7 +220,7 @@ static inline void wait_for_idle(struct rockchip_spi *rs)
220 do { 220 do {
221 if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY)) 221 if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY))
222 return; 222 return;
223 } while (time_before(jiffies, timeout)); 223 } while (!time_after(jiffies, timeout));
224 224
225 dev_warn(rs->dev, "spi controller is in busy state!\n"); 225 dev_warn(rs->dev, "spi controller is in busy state!\n");
226} 226}
@@ -415,7 +415,7 @@ static void rockchip_spi_dma_txcb(void *data)
415 spin_unlock_irqrestore(&rs->lock, flags); 415 spin_unlock_irqrestore(&rs->lock, flags);
416} 416}
417 417
418static int rockchip_spi_dma_transfer(struct rockchip_spi *rs) 418static void rockchip_spi_prepare_dma(struct rockchip_spi *rs)
419{ 419{
420 unsigned long flags; 420 unsigned long flags;
421 struct dma_slave_config rxconf, txconf; 421 struct dma_slave_config rxconf, txconf;
@@ -474,8 +474,6 @@ static int rockchip_spi_dma_transfer(struct rockchip_spi *rs)
474 dmaengine_submit(txdesc); 474 dmaengine_submit(txdesc);
475 dma_async_issue_pending(rs->dma_tx.ch); 475 dma_async_issue_pending(rs->dma_tx.ch);
476 } 476 }
477
478 return 1;
479} 477}
480 478
481static void rockchip_spi_config(struct rockchip_spi *rs) 479static void rockchip_spi_config(struct rockchip_spi *rs)
@@ -499,7 +497,7 @@ static void rockchip_spi_config(struct rockchip_spi *rs)
499 } 497 }
500 498
501 /* div doesn't support odd number */ 499 /* div doesn't support odd number */
502 div = rs->max_freq / rs->speed; 500 div = max_t(u32, rs->max_freq / rs->speed, 1);
503 div = (div + 1) & 0xfffe; 501 div = (div + 1) & 0xfffe;
504 502
505 spi_enable_chip(rs, 0); 503 spi_enable_chip(rs, 0);
@@ -529,7 +527,8 @@ static int rockchip_spi_transfer_one(
529 int ret = 0; 527 int ret = 0;
530 struct rockchip_spi *rs = spi_master_get_devdata(master); 528 struct rockchip_spi *rs = spi_master_get_devdata(master);
531 529
532 WARN_ON((readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY)); 530 WARN_ON(readl_relaxed(rs->regs + ROCKCHIP_SPI_SSIENR) &&
531 (readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY));
533 532
534 if (!xfer->tx_buf && !xfer->rx_buf) { 533 if (!xfer->tx_buf && !xfer->rx_buf) {
535 dev_err(rs->dev, "No buffer for transfer\n"); 534 dev_err(rs->dev, "No buffer for transfer\n");
@@ -556,16 +555,17 @@ static int rockchip_spi_transfer_one(
556 else if (rs->rx) 555 else if (rs->rx)
557 rs->tmode = CR0_XFM_RO; 556 rs->tmode = CR0_XFM_RO;
558 557
559 if (master->can_dma && master->can_dma(master, spi, xfer)) 558 /* we need prepare dma before spi was enabled */
559 if (master->can_dma && master->can_dma(master, spi, xfer)) {
560 rs->use_dma = 1; 560 rs->use_dma = 1;
561 else 561 rockchip_spi_prepare_dma(rs);
562 } else {
562 rs->use_dma = 0; 563 rs->use_dma = 0;
564 }
563 565
564 rockchip_spi_config(rs); 566 rockchip_spi_config(rs);
565 567
566 if (rs->use_dma) 568 if (!rs->use_dma)
567 ret = rockchip_spi_dma_transfer(rs);
568 else
569 ret = rockchip_spi_pio_transfer(rs); 569 ret = rockchip_spi_pio_transfer(rs);
570 570
571 return ret; 571 return ret;
@@ -678,7 +678,7 @@ static int rockchip_spi_probe(struct platform_device *pdev)
678 rs->dma_tx.addr = (dma_addr_t)(mem->start + ROCKCHIP_SPI_TXDR); 678 rs->dma_tx.addr = (dma_addr_t)(mem->start + ROCKCHIP_SPI_TXDR);
679 rs->dma_rx.addr = (dma_addr_t)(mem->start + ROCKCHIP_SPI_RXDR); 679 rs->dma_rx.addr = (dma_addr_t)(mem->start + ROCKCHIP_SPI_RXDR);
680 rs->dma_tx.direction = DMA_MEM_TO_DEV; 680 rs->dma_tx.direction = DMA_MEM_TO_DEV;
681 rs->dma_tx.direction = DMA_DEV_TO_MEM; 681 rs->dma_rx.direction = DMA_DEV_TO_MEM;
682 682
683 master->can_dma = rockchip_spi_can_dma; 683 master->can_dma = rockchip_spi_can_dma;
684 master->dma_tx = rs->dma_tx.ch; 684 master->dma_tx = rs->dma_tx.ch;