@@ -108,8 +108,9 @@ struct bcm2835_host {
108
108
u32 shadow ;
109
109
110
110
/*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 ;
113
114
struct dma_async_tx_descriptor * tx_desc ; /* descriptor */
114
115
115
116
bool have_dma ;
@@ -342,7 +343,7 @@ static void bcm2835_mmc_dma_complete(void *param)
342
343
343
344
if (host -> data && !(host -> data -> flags & MMC_DATA_WRITE )) {
344
345
/* otherwise handled in SDHCI IRQ */
345
- dma_chan = host -> dma_chan_rx ;
346
+ dma_chan = host -> dma_chan_rxtx ;
346
347
dir_data = DMA_FROM_DEVICE ;
347
348
348
349
dma_unmap_sg (dma_chan -> device -> dev ,
@@ -493,16 +494,21 @@ static void bcm2835_mmc_transfer_dma(struct bcm2835_host *host)
493
494
if (host -> blocks == 0 )
494
495
return ;
495
496
497
+ dma_chan = host -> dma_chan_rxtx ;
496
498
if (host -> data -> flags & MMC_DATA_READ ) {
497
- dma_chan = host -> dma_chan_rx ;
498
499
dir_data = DMA_FROM_DEVICE ;
499
500
dir_slave = DMA_DEV_TO_MEM ;
500
501
} else {
501
- dma_chan = host -> dma_chan_tx ;
502
502
dir_data = DMA_TO_DEVICE ;
503
503
dir_slave = DMA_MEM_TO_DEV ;
504
504
}
505
505
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
+
506
512
BUG_ON (!dma_chan -> device );
507
513
BUG_ON (!dma_chan -> device -> dev );
508
514
BUG_ON (!host -> data -> sg );
@@ -936,7 +942,7 @@ static void bcm2835_mmc_data_irq(struct bcm2835_host *host, u32 intmask)
936
942
if (host -> data -> flags & MMC_DATA_WRITE ) {
937
943
/* IRQ handled here */
938
944
939
- dma_chan = host -> dma_chan_tx ;
945
+ dma_chan = host -> dma_chan_rxtx ;
940
946
dir_data = DMA_TO_DEVICE ;
941
947
dma_unmap_sg (dma_chan -> device -> dev ,
942
948
host -> data -> sg , host -> data -> sg_len ,
@@ -1316,28 +1322,47 @@ static int bcm2835_mmc_add_host(struct bcm2835_host *host)
1316
1322
dev_info (dev , "Forcing PIO mode\n" );
1317
1323
host -> have_dma = false;
1318
1324
#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 )) {
1321
1326
dev_err (dev , "%s: Unable to initialise DMA channels. Falling back to PIO\n" ,
1322
1327
DRIVER_NAME );
1323
1328
host -> have_dma = false;
1324
1329
} else {
1325
1330
dev_info (dev , "DMA channels allocated" );
1326
- host -> have_dma = true;
1327
1331
1328
1332
cfg .src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES ;
1329
1333
cfg .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES ;
1330
1334
cfg .slave_id = 11 ; /* DREQ channel */
1331
1335
1336
+ /* Validate the slave configurations */
1337
+
1332
1338
cfg .direction = DMA_MEM_TO_DEV ;
1333
1339
cfg .src_addr = 0 ;
1334
1340
cfg .dst_addr = host -> bus_addr + SDHCI_BUFFER ;
1335
- ret = dmaengine_slave_config (host -> dma_chan_tx , & cfg );
1336
1341
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
+ }
1341
1366
}
1342
1367
#endif
1343
1368
mmc -> max_segs = 128 ;
@@ -1416,16 +1441,20 @@ static int bcm2835_mmc_probe(struct platform_device *pdev)
1416
1441
1417
1442
#ifndef FORCE_PIO
1418
1443
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" );
1421
1451
} else {
1422
1452
dma_cap_mask_t mask ;
1423
1453
1424
1454
dma_cap_zero (mask );
1425
1455
/* we don't care about the channel, any would work */
1426
1456
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 );
1429
1458
}
1430
1459
#endif
1431
1460
clk = devm_clk_get (dev , NULL );
0 commit comments