Skip to content

Commit a395acf

Browse files
committed
mmc: mmc_spi: Allow the driver to be built when CONFIG_HAS_DMA is unset
The commit cd57d07 ("sh: don't allow non-coherent DMA for NOMMU") made CONFIG_NO_DMA to be set for some platforms, for good reasons. Consequentially, CONFIG_HAS_DMA doesn't get set, which makes the DMA mapping interface to be built as stub functions, but also prevent the mmc_spi driver from being built as it depends on CONFIG_HAS_DMA. It turns out that for some odd cases, the driver still relied on the DMA mapping interface, even if the DMA was not actively being used. To fixup the behaviour, let's drop the build dependency for CONFIG_HAS_DMA. Moreover, as to allow the driver to succeed probing, let's move the DMA initializations behind "#ifdef CONFIG_HAS_DMA". Fixes: cd57d07 ("sh: don't allow non-coherent DMA for NOMMU") Reported-by: Rich Felker <[email protected]> Signed-off-by: Ulf Hansson <[email protected]> Tested-by: Rich Felker <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9d5dcef commit a395acf

File tree

2 files changed

+53
-35
lines changed

2 files changed

+53
-35
lines changed

drivers/mmc/host/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ config MMC_GOLDFISH
602602

603603
config MMC_SPI
604604
tristate "MMC/SD/SDIO over SPI"
605-
depends on SPI_MASTER && HAS_DMA
605+
depends on SPI_MASTER
606606
select CRC7
607607
select CRC_ITU_T
608608
help

drivers/mmc/host/mmc_spi.c

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,52 @@ mmc_spi_detect_irq(int irq, void *mmc)
12781278
return IRQ_HANDLED;
12791279
}
12801280

1281+
#ifdef CONFIG_HAS_DMA
1282+
static int mmc_spi_dma_alloc(struct mmc_spi_host *host)
1283+
{
1284+
struct spi_device *spi = host->spi;
1285+
struct device *dev;
1286+
1287+
if (!spi->master->dev.parent->dma_mask)
1288+
return 0;
1289+
1290+
dev = spi->master->dev.parent;
1291+
1292+
host->ones_dma = dma_map_single(dev, host->ones, MMC_SPI_BLOCKSIZE,
1293+
DMA_TO_DEVICE);
1294+
if (dma_mapping_error(dev, host->ones_dma))
1295+
return -ENOMEM;
1296+
1297+
host->data_dma = dma_map_single(dev, host->data, sizeof(*host->data),
1298+
DMA_BIDIRECTIONAL);
1299+
if (dma_mapping_error(dev, host->data_dma)) {
1300+
dma_unmap_single(dev, host->ones_dma, MMC_SPI_BLOCKSIZE,
1301+
DMA_TO_DEVICE);
1302+
return -ENOMEM;
1303+
}
1304+
1305+
dma_sync_single_for_cpu(dev, host->data_dma, sizeof(*host->data),
1306+
DMA_BIDIRECTIONAL);
1307+
1308+
host->dma_dev = dev;
1309+
return 0;
1310+
}
1311+
1312+
static void mmc_spi_dma_free(struct mmc_spi_host *host)
1313+
{
1314+
if (!host->dma_dev)
1315+
return;
1316+
1317+
dma_unmap_single(host->dma_dev, host->ones_dma, MMC_SPI_BLOCKSIZE,
1318+
DMA_TO_DEVICE);
1319+
dma_unmap_single(host->dma_dev, host->data_dma, sizeof(*host->data),
1320+
DMA_BIDIRECTIONAL);
1321+
}
1322+
#else
1323+
static inline mmc_spi_dma_alloc(struct mmc_spi_host *host) { return 0; }
1324+
static inline void mmc_spi_dma_free(struct mmc_spi_host *host) {}
1325+
#endif
1326+
12811327
static int mmc_spi_probe(struct spi_device *spi)
12821328
{
12831329
void *ones;
@@ -1374,23 +1420,9 @@ static int mmc_spi_probe(struct spi_device *spi)
13741420
if (!host->data)
13751421
goto fail_nobuf1;
13761422

1377-
if (spi->master->dev.parent->dma_mask) {
1378-
struct device *dev = spi->master->dev.parent;
1379-
1380-
host->dma_dev = dev;
1381-
host->ones_dma = dma_map_single(dev, ones,
1382-
MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
1383-
if (dma_mapping_error(dev, host->ones_dma))
1384-
goto fail_ones_dma;
1385-
host->data_dma = dma_map_single(dev, host->data,
1386-
sizeof(*host->data), DMA_BIDIRECTIONAL);
1387-
if (dma_mapping_error(dev, host->data_dma))
1388-
goto fail_data_dma;
1389-
1390-
dma_sync_single_for_cpu(host->dma_dev,
1391-
host->data_dma, sizeof(*host->data),
1392-
DMA_BIDIRECTIONAL);
1393-
}
1423+
status = mmc_spi_dma_alloc(host);
1424+
if (status)
1425+
goto fail_dma;
13941426

13951427
/* setup message for status/busy readback */
13961428
spi_message_init(&host->readback);
@@ -1458,20 +1490,12 @@ static int mmc_spi_probe(struct spi_device *spi)
14581490
fail_add_host:
14591491
mmc_remove_host(mmc);
14601492
fail_glue_init:
1461-
if (host->dma_dev)
1462-
dma_unmap_single(host->dma_dev, host->data_dma,
1463-
sizeof(*host->data), DMA_BIDIRECTIONAL);
1464-
fail_data_dma:
1465-
if (host->dma_dev)
1466-
dma_unmap_single(host->dma_dev, host->ones_dma,
1467-
MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
1468-
fail_ones_dma:
1493+
mmc_spi_dma_free(host);
1494+
fail_dma:
14691495
kfree(host->data);
1470-
14711496
fail_nobuf1:
14721497
mmc_free_host(mmc);
14731498
mmc_spi_put_pdata(spi);
1474-
14751499
nomem:
14761500
kfree(ones);
14771501
return status;
@@ -1489,13 +1513,7 @@ static int mmc_spi_remove(struct spi_device *spi)
14891513

14901514
mmc_remove_host(mmc);
14911515

1492-
if (host->dma_dev) {
1493-
dma_unmap_single(host->dma_dev, host->ones_dma,
1494-
MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
1495-
dma_unmap_single(host->dma_dev, host->data_dma,
1496-
sizeof(*host->data), DMA_BIDIRECTIONAL);
1497-
}
1498-
1516+
mmc_spi_dma_free(host);
14991517
kfree(host->data);
15001518
kfree(host->ones);
15011519

0 commit comments

Comments
 (0)