Skip to content

Commit 4990be3

Browse files
author
Phil Elwell
committed
bcm2835-mmc: Only claim one DMA channel
With both MMC controllers enabled there are few DMA channels left. The bcm2835-mmc driver only uses DMA in one direction at a time, so it doesn't need to claim two channels. See: #1327 Signed-off-by: Phil Elwell <[email protected]>
1 parent 06c1699 commit 4990be3

File tree

2 files changed

+49
-21
lines changed

2 files changed

+49
-21
lines changed

arch/arm/boot/dts/bcm2708_common.dtsi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,8 @@
232232
reg = <0x7e300000 0x100>;
233233
interrupts = <2 30>;
234234
clocks = <&clk_mmc>;
235-
dmas = <&dma 11>,
236-
<&dma 11>;
237-
dma-names = "tx", "rx";
235+
dmas = <&dma 11>;
236+
dma-names = "rx-tx";
238237
brcm,overclock-50 = <0>;
239238
status = "disabled";
240239
};

drivers/mmc/host/bcm2835-mmc.c

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ struct bcm2835_host {
108108
u32 shadow;
109109

110110
/*DMA part*/
111-
struct dma_chan *dma_chan_rx; /* DMA channel for reads */
112-
struct dma_chan *dma_chan_tx; /* DMA channel for writes */
111+
struct dma_chan *dma_chan_rxtx; /* DMA channel for reads and writes */
112+
struct dma_slave_config dma_cfg_rx;
113+
struct dma_slave_config dma_cfg_tx;
113114
struct dma_async_tx_descriptor *tx_desc; /* descriptor */
114115

115116
bool have_dma;
@@ -342,7 +343,7 @@ static void bcm2835_mmc_dma_complete(void *param)
342343

343344
if (host->data && !(host->data->flags & MMC_DATA_WRITE)) {
344345
/* otherwise handled in SDHCI IRQ */
345-
dma_chan = host->dma_chan_rx;
346+
dma_chan = host->dma_chan_rxtx;
346347
dir_data = DMA_FROM_DEVICE;
347348

348349
dma_unmap_sg(dma_chan->device->dev,
@@ -493,16 +494,21 @@ static void bcm2835_mmc_transfer_dma(struct bcm2835_host *host)
493494
if (host->blocks == 0)
494495
return;
495496

497+
dma_chan = host->dma_chan_rxtx;
496498
if (host->data->flags & MMC_DATA_READ) {
497-
dma_chan = host->dma_chan_rx;
498499
dir_data = DMA_FROM_DEVICE;
499500
dir_slave = DMA_DEV_TO_MEM;
500501
} else {
501-
dma_chan = host->dma_chan_tx;
502502
dir_data = DMA_TO_DEVICE;
503503
dir_slave = DMA_MEM_TO_DEV;
504504
}
505505

506+
/* The parameters have already been validated, so this will not fail */
507+
(void)dmaengine_slave_config(dma_chan,
508+
(dir_data == DMA_FROM_DEVICE) ?
509+
&host->dma_cfg_rx :
510+
&host->dma_cfg_tx);
511+
506512
BUG_ON(!dma_chan->device);
507513
BUG_ON(!dma_chan->device->dev);
508514
BUG_ON(!host->data->sg);
@@ -936,7 +942,7 @@ static void bcm2835_mmc_data_irq(struct bcm2835_host *host, u32 intmask)
936942
if (host->data->flags & MMC_DATA_WRITE) {
937943
/* IRQ handled here */
938944

939-
dma_chan = host->dma_chan_tx;
945+
dma_chan = host->dma_chan_rxtx;
940946
dir_data = DMA_TO_DEVICE;
941947
dma_unmap_sg(dma_chan->device->dev,
942948
host->data->sg, host->data->sg_len,
@@ -1316,28 +1322,47 @@ static int bcm2835_mmc_add_host(struct bcm2835_host *host)
13161322
dev_info(dev, "Forcing PIO mode\n");
13171323
host->have_dma = false;
13181324
#else
1319-
if (IS_ERR_OR_NULL(host->dma_chan_tx) ||
1320-
IS_ERR_OR_NULL(host->dma_chan_rx)) {
1325+
if (IS_ERR_OR_NULL(host->dma_chan_rxtx)) {
13211326
dev_err(dev, "%s: Unable to initialise DMA channels. Falling back to PIO\n",
13221327
DRIVER_NAME);
13231328
host->have_dma = false;
13241329
} else {
13251330
dev_info(dev, "DMA channels allocated");
1326-
host->have_dma = true;
13271331

13281332
cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
13291333
cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
13301334
cfg.slave_id = 11; /* DREQ channel */
13311335

1336+
/* Validate the slave configurations */
1337+
13321338
cfg.direction = DMA_MEM_TO_DEV;
13331339
cfg.src_addr = 0;
13341340
cfg.dst_addr = host->bus_addr + SDHCI_BUFFER;
1335-
ret = dmaengine_slave_config(host->dma_chan_tx, &cfg);
13361341

1337-
cfg.direction = DMA_DEV_TO_MEM;
1338-
cfg.src_addr = host->bus_addr + SDHCI_BUFFER;
1339-
cfg.dst_addr = 0;
1340-
ret = dmaengine_slave_config(host->dma_chan_rx, &cfg);
1342+
ret = dmaengine_slave_config(host->dma_chan_rxtx, &cfg);
1343+
1344+
if (ret == 0) {
1345+
host->dma_cfg_tx = cfg;
1346+
1347+
cfg.direction = DMA_DEV_TO_MEM;
1348+
cfg.src_addr = host->bus_addr + SDHCI_BUFFER;
1349+
cfg.dst_addr = 0;
1350+
1351+
ret = dmaengine_slave_config(host->dma_chan_rxtx, &cfg);
1352+
}
1353+
1354+
if (ret == 0) {
1355+
host->dma_cfg_rx = cfg;
1356+
1357+
host->use_dma = true;
1358+
} else {
1359+
pr_err("%s: unable to configure DMA channel. "
1360+
"Faling back to PIO\n",
1361+
mmc_hostname(mmc));
1362+
dma_release_channel(host->dma_chan_rxtx);
1363+
host->dma_chan_rxtx = NULL;
1364+
host->use_dma = false;
1365+
}
13411366
}
13421367
#endif
13431368
mmc->max_segs = 128;
@@ -1416,16 +1441,20 @@ static int bcm2835_mmc_probe(struct platform_device *pdev)
14161441

14171442
#ifndef FORCE_PIO
14181443
if (node) {
1419-
host->dma_chan_tx = dma_request_slave_channel(dev, "tx");
1420-
host->dma_chan_rx = dma_request_slave_channel(dev, "rx");
1444+
host->dma_chan_rxtx = dma_request_slave_channel(dev, "rx-tx");
1445+
if (!host->dma_chan_rxtx)
1446+
host->dma_chan_rxtx =
1447+
dma_request_slave_channel(dev, "tx");
1448+
if (!host->dma_chan_rxtx)
1449+
host->dma_chan_rxtx =
1450+
dma_request_slave_channel(dev, "rx");
14211451
} else {
14221452
dma_cap_mask_t mask;
14231453

14241454
dma_cap_zero(mask);
14251455
/* we don't care about the channel, any would work */
14261456
dma_cap_set(DMA_SLAVE, mask);
1427-
host->dma_chan_tx = dma_request_channel(mask, NULL, NULL);
1428-
host->dma_chan_rx = dma_request_channel(mask, NULL, NULL);
1457+
host->dma_chan_rxtx = dma_request_channel(mask, NULL, NULL);
14291458
}
14301459
#endif
14311460
clk = devm_clk_get(dev, NULL);

0 commit comments

Comments
 (0)