335
340
dir = DMA_FROM_DEVICE;
338
dma_unmap_sg(chan->device->dev, data->sg, data->sg_len, dir);
343
if (!data->host_cookie)
344
dma_unmap_sg(chan->device->dev, data->sg, data->sg_len, dir);
341
347
* Use of DMA with scatter-gather is impossible.
353
359
dmaengine_terminate_all(host->dma_current);
356
static int mmci_dma_start_data(struct mmci_host *host, unsigned int datactrl)
362
static int mmci_dma_prep_data(struct mmci_host *host, struct mmc_data *data,
363
struct mmci_host_next *next)
358
365
struct variant_data *variant = host->variant;
359
366
struct dma_slave_config conf = {
364
371
.src_maxburst = variant->fifohalfsize >> 2, /* # of words */
365
372
.dst_maxburst = variant->fifohalfsize >> 2, /* # of words */
367
struct mmc_data *data = host->data;
368
374
struct dma_chan *chan;
369
375
struct dma_device *device;
370
376
struct dma_async_tx_descriptor *desc;
373
host->dma_current = NULL;
379
/* Check if next job is already prepared */
380
if (data->host_cookie && !next &&
381
host->dma_current && host->dma_desc_current)
385
host->dma_current = NULL;
386
host->dma_desc_current = NULL;
375
389
if (data->flags & MMC_DATA_READ) {
376
390
conf.direction = DMA_FROM_DEVICE;
417
next->dma_chan = chan;
418
next->dma_desc = desc;
420
host->dma_current = chan;
421
host->dma_desc_current = desc;
428
dmaengine_terminate_all(chan);
429
dma_unmap_sg(device->dev, data->sg, data->sg_len, conf.direction);
433
static int mmci_dma_start_data(struct mmci_host *host, unsigned int datactrl)
436
struct mmc_data *data = host->data;
438
ret = mmci_dma_prep_data(host, host->data, NULL);
402
442
/* Okay, go for it. */
403
host->dma_current = chan;
405
443
dev_vdbg(mmc_dev(host->mmc),
406
444
"Submit MMCI DMA job, sglen %d blksz %04x blks %04x flags %08x\n",
407
445
data->sg_len, data->blksz, data->blocks, data->flags);
408
dmaengine_submit(desc);
409
dma_async_issue_pending(chan);
446
dmaengine_submit(host->dma_desc_current);
447
dma_async_issue_pending(host->dma_current);
411
449
datactrl |= MCI_DPSM_DMAENABLE;
421
459
writel(readl(host->base + MMCIMASK0) | MCI_DATAENDMASK,
422
460
host->base + MMCIMASK0);
426
dmaengine_terminate_all(chan);
427
dma_unmap_sg(device->dev, data->sg, data->sg_len, conf.direction);
464
static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
466
struct mmci_host_next *next = &host->next_data;
468
if (data->host_cookie && data->host_cookie != next->cookie) {
469
pr_warning("[%s] invalid cookie: data->host_cookie %d"
470
" host->next_data.cookie %d\n",
471
__func__, data->host_cookie, host->next_data.cookie);
472
data->host_cookie = 0;
475
if (!data->host_cookie)
478
host->dma_desc_current = next->dma_desc;
479
host->dma_current = next->dma_chan;
481
next->dma_desc = NULL;
482
next->dma_chan = NULL;
485
static void mmci_pre_request(struct mmc_host *mmc, struct mmc_request *mrq,
488
struct mmci_host *host = mmc_priv(mmc);
489
struct mmc_data *data = mrq->data;
490
struct mmci_host_next *nd = &host->next_data;
495
if (data->host_cookie) {
496
data->host_cookie = 0;
500
/* if config for dma */
501
if (((data->flags & MMC_DATA_WRITE) && host->dma_tx_channel) ||
502
((data->flags & MMC_DATA_READ) && host->dma_rx_channel)) {
503
if (mmci_dma_prep_data(host, data, nd))
504
data->host_cookie = 0;
506
data->host_cookie = ++nd->cookie < 0 ? 1 : nd->cookie;
510
static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq,
513
struct mmci_host *host = mmc_priv(mmc);
514
struct mmc_data *data = mrq->data;
515
struct dma_chan *chan;
516
enum dma_data_direction dir;
521
if (data->flags & MMC_DATA_READ) {
522
dir = DMA_FROM_DEVICE;
523
chan = host->dma_rx_channel;
526
chan = host->dma_tx_channel;
530
/* if config for dma */
533
dmaengine_terminate_all(chan);
534
if (data->host_cookie)
535
dma_unmap_sg(mmc_dev(host->mmc), data->sg,
537
mrq->data->host_cookie = 0;
431
542
/* Blank functions if the DMA engine is not available */
543
static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
432
546
static inline void mmci_dma_setup(struct mmci_host *host)
995
pm_runtime_get_sync(mmc_dev(mmc));
877
997
spin_lock_irqsave(&host->lock, flags);
1002
mmci_get_next_data(host, mrq->data);
881
1004
if (mrq->data && mrq->data->flags & MMC_DATA_READ)
882
1005
mmci_start_data(host, mrq->data);
1071
1200
mmc->ops = &mmci_ops;
1072
mmc->f_min = (host->mclk + 511) / 512;
1202
* The ARM and ST versions of the block have slightly different
1203
* clock divider equations which means that the minimum divider
1206
if (variant->st_clkdiv)
1207
mmc->f_min = DIV_ROUND_UP(host->mclk, 257);
1209
mmc->f_min = DIV_ROUND_UP(host->mclk, 512);
1074
1211
* If the platform data supplies a maximum operating
1075
1212
* frequency, this takes precedence. Else, we fall back
1242
1383
struct mmci_host *host = mmc_priv(mmc);
1386
* Undo pm_runtime_put() in probe. We use the _sync
1387
* version here so that we can access the primecell.
1389
pm_runtime_get_sync(&dev->dev);
1244
1391
mmc_remove_host(mmc);
1246
1393
writel(0, host->base + MMCIMASK0);