mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-22 00:40:03 +00:00
spi: sh-msiof: Make sure all DMA operations have completed
In case of a bi-directional transfer, receive DMA may complete in the rcar-dmac driver before transmit DMA, due to scheduling latencies. As the MSIOF driver waits for completion of the receive DMA only, it may submit the next transmit DMA request before the previous one has completed. Make the driver more robust by waiting for the completion of both receive and transmit DMA, when applicable. Based on a patch in the BSP by Ryo Kataoka. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
16c10b3bf8
commit
08ba7ae35b
1 changed files with 29 additions and 24 deletions
|
@ -49,6 +49,7 @@ struct sh_msiof_spi_priv {
|
||||||
struct platform_device *pdev;
|
struct platform_device *pdev;
|
||||||
struct sh_msiof_spi_info *info;
|
struct sh_msiof_spi_info *info;
|
||||||
struct completion done;
|
struct completion done;
|
||||||
|
struct completion done_txdma;
|
||||||
unsigned int tx_fifo_size;
|
unsigned int tx_fifo_size;
|
||||||
unsigned int rx_fifo_size;
|
unsigned int rx_fifo_size;
|
||||||
unsigned int min_div_pow;
|
unsigned int min_div_pow;
|
||||||
|
@ -649,19 +650,21 @@ static int sh_msiof_slave_abort(struct spi_master *master)
|
||||||
|
|
||||||
p->slave_aborted = true;
|
p->slave_aborted = true;
|
||||||
complete(&p->done);
|
complete(&p->done);
|
||||||
|
complete(&p->done_txdma);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sh_msiof_wait_for_completion(struct sh_msiof_spi_priv *p)
|
static int sh_msiof_wait_for_completion(struct sh_msiof_spi_priv *p,
|
||||||
|
struct completion *x)
|
||||||
{
|
{
|
||||||
if (spi_controller_is_slave(p->master)) {
|
if (spi_controller_is_slave(p->master)) {
|
||||||
if (wait_for_completion_interruptible(&p->done) ||
|
if (wait_for_completion_interruptible(x) ||
|
||||||
p->slave_aborted) {
|
p->slave_aborted) {
|
||||||
dev_dbg(&p->pdev->dev, "interrupted\n");
|
dev_dbg(&p->pdev->dev, "interrupted\n");
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!wait_for_completion_timeout(&p->done, HZ)) {
|
if (!wait_for_completion_timeout(x, HZ)) {
|
||||||
dev_err(&p->pdev->dev, "timeout\n");
|
dev_err(&p->pdev->dev, "timeout\n");
|
||||||
return -ETIMEDOUT;
|
return -ETIMEDOUT;
|
||||||
}
|
}
|
||||||
|
@ -711,7 +714,7 @@ static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wait for tx fifo to be emptied / rx fifo to be filled */
|
/* wait for tx fifo to be emptied / rx fifo to be filled */
|
||||||
ret = sh_msiof_wait_for_completion(p);
|
ret = sh_msiof_wait_for_completion(p, &p->done);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto stop_reset;
|
goto stop_reset;
|
||||||
|
|
||||||
|
@ -740,10 +743,7 @@ static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p,
|
||||||
|
|
||||||
static void sh_msiof_dma_complete(void *arg)
|
static void sh_msiof_dma_complete(void *arg)
|
||||||
{
|
{
|
||||||
struct sh_msiof_spi_priv *p = arg;
|
complete(arg);
|
||||||
|
|
||||||
sh_msiof_write(p, IER, 0);
|
|
||||||
complete(&p->done);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
|
static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
|
||||||
|
@ -764,7 +764,7 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
|
|
||||||
desc_rx->callback = sh_msiof_dma_complete;
|
desc_rx->callback = sh_msiof_dma_complete;
|
||||||
desc_rx->callback_param = p;
|
desc_rx->callback_param = &p->done;
|
||||||
cookie = dmaengine_submit(desc_rx);
|
cookie = dmaengine_submit(desc_rx);
|
||||||
if (dma_submit_error(cookie))
|
if (dma_submit_error(cookie))
|
||||||
return cookie;
|
return cookie;
|
||||||
|
@ -782,13 +782,8 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
|
||||||
goto no_dma_tx;
|
goto no_dma_tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rx) {
|
desc_tx->callback = sh_msiof_dma_complete;
|
||||||
/* No callback */
|
desc_tx->callback_param = &p->done_txdma;
|
||||||
desc_tx->callback = NULL;
|
|
||||||
} else {
|
|
||||||
desc_tx->callback = sh_msiof_dma_complete;
|
|
||||||
desc_tx->callback_param = p;
|
|
||||||
}
|
|
||||||
cookie = dmaengine_submit(desc_tx);
|
cookie = dmaengine_submit(desc_tx);
|
||||||
if (dma_submit_error(cookie)) {
|
if (dma_submit_error(cookie)) {
|
||||||
ret = cookie;
|
ret = cookie;
|
||||||
|
@ -805,6 +800,8 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
|
||||||
sh_msiof_write(p, IER, ier_bits);
|
sh_msiof_write(p, IER, ier_bits);
|
||||||
|
|
||||||
reinit_completion(&p->done);
|
reinit_completion(&p->done);
|
||||||
|
if (tx)
|
||||||
|
reinit_completion(&p->done_txdma);
|
||||||
p->slave_aborted = false;
|
p->slave_aborted = false;
|
||||||
|
|
||||||
/* Now start DMA */
|
/* Now start DMA */
|
||||||
|
@ -819,17 +816,24 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
|
||||||
goto stop_dma;
|
goto stop_dma;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wait for tx/rx DMA completion */
|
if (tx) {
|
||||||
ret = sh_msiof_wait_for_completion(p);
|
/* wait for tx DMA completion */
|
||||||
if (ret)
|
ret = sh_msiof_wait_for_completion(p, &p->done_txdma);
|
||||||
goto stop_reset;
|
if (ret)
|
||||||
|
goto stop_reset;
|
||||||
|
}
|
||||||
|
|
||||||
if (!rx) {
|
if (rx) {
|
||||||
reinit_completion(&p->done);
|
/* wait for rx DMA completion */
|
||||||
sh_msiof_write(p, IER, IER_TEOFE);
|
ret = sh_msiof_wait_for_completion(p, &p->done);
|
||||||
|
if (ret)
|
||||||
|
goto stop_reset;
|
||||||
|
|
||||||
|
sh_msiof_write(p, IER, 0);
|
||||||
|
} else {
|
||||||
/* wait for tx fifo to be emptied */
|
/* wait for tx fifo to be emptied */
|
||||||
ret = sh_msiof_wait_for_completion(p);
|
sh_msiof_write(p, IER, IER_TEOFE);
|
||||||
|
ret = sh_msiof_wait_for_completion(p, &p->done);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto stop_reset;
|
goto stop_reset;
|
||||||
}
|
}
|
||||||
|
@ -1327,6 +1331,7 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
|
||||||
p->min_div_pow = chipdata->min_div_pow;
|
p->min_div_pow = chipdata->min_div_pow;
|
||||||
|
|
||||||
init_completion(&p->done);
|
init_completion(&p->done);
|
||||||
|
init_completion(&p->done_txdma);
|
||||||
|
|
||||||
p->clk = devm_clk_get(&pdev->dev, NULL);
|
p->clk = devm_clk_get(&pdev->dev, NULL);
|
||||||
if (IS_ERR(p->clk)) {
|
if (IS_ERR(p->clk)) {
|
||||||
|
|
Loading…
Reference in a new issue