Skip to content

Commit 3525e0a

Browse files
mitabroonie
authored andcommitted
spi: omap2-mcspi: fix dma transfer for vmalloced buffer
Currently omap2-mcspi cannot handle dma transfer for vmalloced buffer. I hit this problem when using mtdblock on spi-nor. This lets the SPI core handle the page mapping for dma transfer buffer. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent c508709 commit 3525e0a

File tree

1 file changed

+17
-45
lines changed

1 file changed

+17
-45
lines changed

drivers/spi/spi-omap2-mcspi.c

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -423,16 +423,12 @@ static void omap2_mcspi_tx_dma(struct spi_device *spi,
423423

424424
if (mcspi_dma->dma_tx) {
425425
struct dma_async_tx_descriptor *tx;
426-
struct scatterlist sg;
427426

428427
dmaengine_slave_config(mcspi_dma->dma_tx, &cfg);
429428

430-
sg_init_table(&sg, 1);
431-
sg_dma_address(&sg) = xfer->tx_dma;
432-
sg_dma_len(&sg) = xfer->len;
433-
434-
tx = dmaengine_prep_slave_sg(mcspi_dma->dma_tx, &sg, 1,
435-
DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
429+
tx = dmaengine_prep_slave_sg(mcspi_dma->dma_tx, xfer->tx_sg.sgl,
430+
xfer->tx_sg.nents, DMA_MEM_TO_DEV,
431+
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
436432
if (tx) {
437433
tx->callback = omap2_mcspi_tx_callback;
438434
tx->callback_param = spi;
@@ -478,20 +474,15 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,
478474

479475
if (mcspi_dma->dma_rx) {
480476
struct dma_async_tx_descriptor *tx;
481-
struct scatterlist sg;
482477

483478
dmaengine_slave_config(mcspi_dma->dma_rx, &cfg);
484479

485480
if ((l & OMAP2_MCSPI_CHCONF_TURBO) && mcspi->fifo_depth == 0)
486481
dma_count -= es;
487482

488-
sg_init_table(&sg, 1);
489-
sg_dma_address(&sg) = xfer->rx_dma;
490-
sg_dma_len(&sg) = dma_count;
491-
492-
tx = dmaengine_prep_slave_sg(mcspi_dma->dma_rx, &sg, 1,
493-
DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT |
494-
DMA_CTRL_ACK);
483+
tx = dmaengine_prep_slave_sg(mcspi_dma->dma_rx, xfer->rx_sg.sgl,
484+
xfer->rx_sg.nents, DMA_DEV_TO_MEM,
485+
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
495486
if (tx) {
496487
tx->callback = omap2_mcspi_rx_callback;
497488
tx->callback_param = spi;
@@ -505,8 +496,6 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,
505496
omap2_mcspi_set_dma_req(spi, 1, 1);
506497

507498
wait_for_completion(&mcspi_dma->dma_rx_completion);
508-
dma_unmap_single(mcspi->dev, xfer->rx_dma, count,
509-
DMA_FROM_DEVICE);
510499

511500
if (mcspi->fifo_depth > 0)
512501
return count;
@@ -619,8 +608,6 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
619608

620609
if (tx != NULL) {
621610
wait_for_completion(&mcspi_dma->dma_tx_completion);
622-
dma_unmap_single(mcspi->dev, xfer->tx_dma, xfer->len,
623-
DMA_TO_DEVICE);
624611

625612
if (mcspi->fifo_depth > 0) {
626613
irqstat_reg = mcspi->base + OMAP2_MCSPI_IRQSTATUS;
@@ -1087,6 +1074,16 @@ static void omap2_mcspi_cleanup(struct spi_device *spi)
10871074
gpio_free(spi->cs_gpio);
10881075
}
10891076

1077+
static bool omap2_mcspi_can_dma(struct spi_master *master,
1078+
struct spi_device *spi,
1079+
struct spi_transfer *xfer)
1080+
{
1081+
if (xfer->len < DMA_MIN_BYTES)
1082+
return false;
1083+
1084+
return true;
1085+
}
1086+
10901087
static int omap2_mcspi_work_one(struct omap2_mcspi *mcspi,
10911088
struct spi_device *spi, struct spi_transfer *t)
10921089
{
@@ -1268,32 +1265,6 @@ static int omap2_mcspi_transfer_one(struct spi_master *master,
12681265
return -EINVAL;
12691266
}
12701267

1271-
if (len < DMA_MIN_BYTES)
1272-
goto skip_dma_map;
1273-
1274-
if (mcspi_dma->dma_tx && tx_buf != NULL) {
1275-
t->tx_dma = dma_map_single(mcspi->dev, (void *) tx_buf,
1276-
len, DMA_TO_DEVICE);
1277-
if (dma_mapping_error(mcspi->dev, t->tx_dma)) {
1278-
dev_dbg(mcspi->dev, "dma %cX %d bytes error\n",
1279-
'T', len);
1280-
return -EINVAL;
1281-
}
1282-
}
1283-
if (mcspi_dma->dma_rx && rx_buf != NULL) {
1284-
t->rx_dma = dma_map_single(mcspi->dev, rx_buf, t->len,
1285-
DMA_FROM_DEVICE);
1286-
if (dma_mapping_error(mcspi->dev, t->rx_dma)) {
1287-
dev_dbg(mcspi->dev, "dma %cX %d bytes error\n",
1288-
'R', len);
1289-
if (tx_buf != NULL)
1290-
dma_unmap_single(mcspi->dev, t->tx_dma,
1291-
len, DMA_TO_DEVICE);
1292-
return -EINVAL;
1293-
}
1294-
}
1295-
1296-
skip_dma_map:
12971268
return omap2_mcspi_work_one(mcspi, spi, t);
12981269
}
12991270

@@ -1377,6 +1348,7 @@ static int omap2_mcspi_probe(struct platform_device *pdev)
13771348
master->transfer_one = omap2_mcspi_transfer_one;
13781349
master->set_cs = omap2_mcspi_set_cs;
13791350
master->cleanup = omap2_mcspi_cleanup;
1351+
master->can_dma = omap2_mcspi_can_dma;
13801352
master->dev.of_node = node;
13811353
master->max_speed_hz = OMAP2_MCSPI_MAX_FREQ;
13821354
master->min_speed_hz = OMAP2_MCSPI_MAX_FREQ >> 15;

0 commit comments

Comments
 (0)