aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-dw.c
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2015-03-09 10:48:49 -0400
committerMark Brown <broonie@kernel.org>2015-03-09 14:11:13 -0400
commitf89a6d8f43ebe9508bb5492c846ad997ad50eafe (patch)
tree9efc2db1c5c20e114e65638bedf7f0eb880ec595 /drivers/spi/spi-dw.c
parent4d5ac1edfdd79aea31983333cb53dd5db29559f9 (diff)
spi: dw-mid: move to use core SPI DMA mappings
SPI core has a comprehensive function set to map and unmap a message when it's needed. This patch converts driver to use that advantage. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi/spi-dw.c')
-rw-r--r--drivers/spi/spi-dw.c40
1 files changed, 7 insertions, 33 deletions
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index d53cffe7ff22..2437bfcbf2f8 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -217,32 +217,6 @@ static void dw_reader(struct dw_spi *dws)
217 } 217 }
218} 218}
219 219
220/*
221 * Note: first step is the protocol driver prepares
222 * a dma-capable memory, and this func just need translate
223 * the virt addr to physical
224 */
225static int map_dma_buffers(struct spi_master *master,
226 struct spi_device *spi, struct spi_transfer *transfer)
227{
228 struct dw_spi *dws = spi_master_get_devdata(master);
229 struct chip_data *chip = spi_get_ctldata(spi);
230
231 if (!master->cur_msg->is_dma_mapped
232 || !dws->dma_inited
233 || !chip->enable_dma
234 || !dws->dma_ops)
235 return 0;
236
237 if (transfer->tx_dma)
238 dws->tx_dma = transfer->tx_dma;
239
240 if (transfer->rx_dma)
241 dws->rx_dma = transfer->rx_dma;
242
243 return 1;
244}
245
246static void int_error_stop(struct dw_spi *dws, const char *msg) 220static void int_error_stop(struct dw_spi *dws, const char *msg)
247{ 221{
248 spi_reset_chip(dws); 222 spi_reset_chip(dws);
@@ -322,11 +296,10 @@ static int dw_spi_transfer_one(struct spi_master *master,
322 u32 cr0 = 0; 296 u32 cr0 = 0;
323 int ret; 297 int ret;
324 298
299 dws->dma_mapped = 0;
325 dws->n_bytes = chip->n_bytes; 300 dws->n_bytes = chip->n_bytes;
326 dws->dma_width = chip->dma_width; 301 dws->dma_width = chip->dma_width;
327 302
328 dws->rx_dma = transfer->rx_dma;
329 dws->tx_dma = transfer->tx_dma;
330 dws->tx = (void *)transfer->tx_buf; 303 dws->tx = (void *)transfer->tx_buf;
331 dws->tx_end = dws->tx + transfer->len; 304 dws->tx_end = dws->tx + transfer->len;
332 dws->rx = transfer->rx_buf; 305 dws->rx = transfer->rx_buf;
@@ -386,7 +359,8 @@ static int dw_spi_transfer_one(struct spi_master *master,
386 dw_writew(dws, DW_SPI_CTRL0, cr0); 359 dw_writew(dws, DW_SPI_CTRL0, cr0);
387 360
388 /* Check if current transfer is a DMA transaction */ 361 /* Check if current transfer is a DMA transaction */
389 dws->dma_mapped = map_dma_buffers(master, spi, transfer); 362 if (master->can_dma && master->can_dma(master, spi, transfer))
363 dws->dma_mapped = master->cur_msg_mapped;
390 364
391 /* For poll mode just disable all interrupts */ 365 /* For poll mode just disable all interrupts */
392 spi_mask_intr(dws, 0xff); 366 spi_mask_intr(dws, 0xff);
@@ -396,7 +370,7 @@ static int dw_spi_transfer_one(struct spi_master *master,
396 * we only need set the TXEI IRQ, as TX/RX always happen syncronizely 370 * we only need set the TXEI IRQ, as TX/RX always happen syncronizely
397 */ 371 */
398 if (dws->dma_mapped) { 372 if (dws->dma_mapped) {
399 ret = dws->dma_ops->dma_setup(dws); 373 ret = dws->dma_ops->dma_setup(dws, transfer);
400 if (ret < 0) { 374 if (ret < 0) {
401 spi_enable_chip(dws, 1); 375 spi_enable_chip(dws, 1);
402 return ret; 376 return ret;
@@ -416,7 +390,7 @@ static int dw_spi_transfer_one(struct spi_master *master,
416 spi_enable_chip(dws, 1); 390 spi_enable_chip(dws, 1);
417 391
418 if (dws->dma_mapped) { 392 if (dws->dma_mapped) {
419 ret = dws->dma_ops->dma_transfer(dws); 393 ret = dws->dma_ops->dma_transfer(dws, transfer);
420 if (ret < 0) 394 if (ret < 0)
421 return ret; 395 return ret;
422 } 396 }
@@ -470,8 +444,6 @@ static int dw_spi_setup(struct spi_device *spi)
470 444
471 chip->rx_threshold = 0; 445 chip->rx_threshold = 0;
472 chip->tx_threshold = 0; 446 chip->tx_threshold = 0;
473
474 chip->enable_dma = chip_info->enable_dma;
475 } 447 }
476 448
477 if (spi->bits_per_word == 8) { 449 if (spi->bits_per_word == 8) {
@@ -584,6 +556,8 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
584 if (ret) { 556 if (ret) {
585 dev_warn(dev, "DMA init failed\n"); 557 dev_warn(dev, "DMA init failed\n");
586 dws->dma_inited = 0; 558 dws->dma_inited = 0;
559 } else {
560 master->can_dma = dws->dma_ops->can_dma;
587 } 561 }
588 } 562 }
589 563