Commit c045105c authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Greg Kroah-Hartman

mmc: sh_mmcif: rework dma channel handling

commit 27cbd7e8 upstream.

When compiling the sh_mmcif driver for ARM64, we currently
get a harmless build warning:

../drivers/mmc/host/sh_mmcif.c: In function 'sh_mmcif_request_dma_one':
../drivers/mmc/host/sh_mmcif.c:417:4: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
    (void *)pdata->slave_id_tx :
    ^
../drivers/mmc/host/sh_mmcif.c:418:4: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
    (void *)pdata->slave_id_rx;

This could be worked around by adding another cast to uintptr_t, but
I decided to simplify the code a little more to avoid that. This
splits out the platform data using code into a separate function
and builds that only for CONFIG_SUPERH. This part still has a typecast
but does not need a second one. The SH platform code could be further
modified to pass a pointer directly as we do on other architectures
when we have a filter function.

The normal case is simplified further and now just calls
dma_request_slave_channel() directly without going through the
compat handling.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e08f9a7c
...@@ -397,38 +397,26 @@ static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host) ...@@ -397,38 +397,26 @@ static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host)
} }
static struct dma_chan * static struct dma_chan *
sh_mmcif_request_dma_one(struct sh_mmcif_host *host, sh_mmcif_request_dma_pdata(struct sh_mmcif_host *host, uintptr_t slave_id)
struct sh_mmcif_plat_data *pdata,
enum dma_transfer_direction direction)
{ {
struct dma_slave_config cfg = { 0, };
struct dma_chan *chan;
void *slave_data = NULL;
struct resource *res;
struct device *dev = sh_mmcif_host_to_dev(host);
dma_cap_mask_t mask; dma_cap_mask_t mask;
int ret;
dma_cap_zero(mask); dma_cap_zero(mask);
dma_cap_set(DMA_SLAVE, mask); dma_cap_set(DMA_SLAVE, mask);
if (slave_id <= 0)
return NULL;
if (pdata) return dma_request_channel(mask, shdma_chan_filter, (void *)slave_id);
slave_data = direction == DMA_MEM_TO_DEV ? }
(void *)pdata->slave_id_tx :
(void *)pdata->slave_id_rx;
chan = dma_request_slave_channel_compat(mask, shdma_chan_filter,
slave_data, dev,
direction == DMA_MEM_TO_DEV ? "tx" : "rx");
dev_dbg(dev, "%s: %s: got channel %p\n", __func__,
direction == DMA_MEM_TO_DEV ? "TX" : "RX", chan);
if (!chan) static int sh_mmcif_dma_slave_config(struct sh_mmcif_host *host,
return NULL; struct dma_chan *chan,
enum dma_transfer_direction direction)
{
struct resource *res;
struct dma_slave_config cfg = { 0, };
res = platform_get_resource(host->pd, IORESOURCE_MEM, 0); res = platform_get_resource(host->pd, IORESOURCE_MEM, 0);
cfg.direction = direction; cfg.direction = direction;
if (direction == DMA_DEV_TO_MEM) { if (direction == DMA_DEV_TO_MEM) {
...@@ -439,38 +427,42 @@ sh_mmcif_request_dma_one(struct sh_mmcif_host *host, ...@@ -439,38 +427,42 @@ sh_mmcif_request_dma_one(struct sh_mmcif_host *host,
cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
} }
ret = dmaengine_slave_config(chan, &cfg); return dmaengine_slave_config(chan, &cfg);
if (ret < 0) {
dma_release_channel(chan);
return NULL;
}
return chan;
} }
static void sh_mmcif_request_dma(struct sh_mmcif_host *host, static void sh_mmcif_request_dma(struct sh_mmcif_host *host)
struct sh_mmcif_plat_data *pdata)
{ {
struct device *dev = sh_mmcif_host_to_dev(host); struct device *dev = sh_mmcif_host_to_dev(host);
host->dma_active = false; host->dma_active = false;
if (pdata) { /* We can only either use DMA for both Tx and Rx or not use it at all */
if (pdata->slave_id_tx <= 0 || pdata->slave_id_rx <= 0) if (IS_ENABLED(CONFIG_SUPERH) && dev->platform_data) {
return; struct sh_mmcif_plat_data *pdata = dev->platform_data;
} else if (!dev->of_node) {
return; host->chan_tx = sh_mmcif_request_dma_pdata(host,
pdata->slave_id_tx);
host->chan_rx = sh_mmcif_request_dma_pdata(host,
pdata->slave_id_rx);
} else {
host->chan_tx = dma_request_slave_channel(dev, "tx");
host->chan_tx = dma_request_slave_channel(dev, "rx");
} }
dev_dbg(dev, "%s: got channel TX %p RX %p\n", __func__, host->chan_tx,
host->chan_rx);
/* We can only either use DMA for both Tx and Rx or not use it at all */ if (!host->chan_tx || !host->chan_rx ||
host->chan_tx = sh_mmcif_request_dma_one(host, pdata, DMA_MEM_TO_DEV); sh_mmcif_dma_slave_config(host, host->chan_tx, DMA_MEM_TO_DEV) ||
if (!host->chan_tx) sh_mmcif_dma_slave_config(host, host->chan_rx, DMA_DEV_TO_MEM))
return; goto error;
host->chan_rx = sh_mmcif_request_dma_one(host, pdata, DMA_DEV_TO_MEM); return;
if (!host->chan_rx) {
error:
if (host->chan_tx)
dma_release_channel(host->chan_tx); dma_release_channel(host->chan_tx);
host->chan_tx = NULL; if (host->chan_rx)
} dma_release_channel(host->chan_rx);
host->chan_tx = host->chan_rx = NULL;
} }
static void sh_mmcif_release_dma(struct sh_mmcif_host *host) static void sh_mmcif_release_dma(struct sh_mmcif_host *host)
...@@ -1102,7 +1094,7 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) ...@@ -1102,7 +1094,7 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
if (ios->power_mode == MMC_POWER_UP) { if (ios->power_mode == MMC_POWER_UP) {
if (!host->card_present) { if (!host->card_present) {
/* See if we also get DMA */ /* See if we also get DMA */
sh_mmcif_request_dma(host, dev->platform_data); sh_mmcif_request_dma(host);
host->card_present = true; host->card_present = true;
} }
sh_mmcif_set_power(host, ios); sh_mmcif_set_power(host, ios);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment