linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Apelete Seketeli <apelete@seketeli.net>, linux-mmc@vger.kernel.org
Cc: Chris Ball <chris@printf.net>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	H Hartley Sweeten <hsweeten@visionengravers.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Wei Yongjun <yongjun_wei@trendmicro.com.cn>,
	Alex Smith <alex.smith@imgtec.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] mmc: jz4740: add dma infrastructure for data transfers
Date: Fri, 11 Jul 2014 02:03:27 +0200	[thread overview]
Message-ID: <26025372.ALyVZ87vgl@avalon> (raw)
In-Reply-To: <1405031246-16365-2-git-send-email-apelete@seketeli.net>

Hi Apelete,

Thank you for the patch.

On Friday 11 July 2014 00:27:26 Apelete Seketeli wrote:
> Until now the MMC driver for JZ4740 SoC was relying on PIO mode only
> for data transfers.
> This patch allows the use of DMA for data trasnfers in addition to PIO
> mode by relying on DMA Engine.
> 
> DMA tranfers performance might be further improved by taking advantage
> of the asynchronous request capability of the MMC framework.
> 
> Signed-off-by: Apelete Seketeli <apelete@seketeli.net>
> ---
> drivers/mmc/host/jz4740_mmc.c |  172 +++++++++++++++++++++++++++++++++++++--
> 1 file changed, 164
> insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
> index 537d6c7..2897b49 100644
> --- a/drivers/mmc/host/jz4740_mmc.c
> +++ b/drivers/mmc/host/jz4740_mmc.c

[snip]

> +static void jz4740_dma_unmap(struct jz4740_mmc_host *host,
> +			     struct mmc_data *data)
> +{
> +	enum dma_data_direction dir = jz4740_get_dma_dir(data);
> +
> +	dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, dir);
> +}
> +
> +static int jz4740_start_dma_transfer(struct jz4740_mmc_host *host,
> +				     struct mmc_data *data)
> +{
> +	struct dma_chan *chan;
> +	struct dma_async_tx_descriptor *desc;
> +	struct dma_slave_config conf = {
> +		.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
> +		.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
> +		.src_maxburst = JZ4740_MMC_FIFO_HALF_SIZE,
> +		.dst_maxburst = JZ4740_MMC_FIFO_HALF_SIZE,
> +	};
> +	enum dma_data_direction dir = jz4740_get_dma_dir(data);
> +
> +	host->sg_len = dma_map_sg(mmc_dev(host->mmc),

You should use the DMA engine device here, not the MMC device, as the memory 
transfers will be performed by the DMA engine. Same for the dma_unmap_sg() 
call above.

> +				  data->sg,
> +				  data->sg_len,
> +				  dir);
> +
> +	if (host->sg_len < 0) {
> +		dev_err(mmc_dev(host->mmc),
> +			 "Failed to map scatterlist for DMA operation\n");
> +		return -EINVAL;
> +	}
> +
> +	if (dir == DMA_TO_DEVICE) {
> +		conf.direction = DMA_MEM_TO_DEV;
> +		conf.dst_addr = host->mem_res->start + JZ_REG_MMC_TXFIFO;
> +		conf.slave_id = JZ4740_DMA_TYPE_MMC_TRANSMIT;
> +		chan = host->dma_tx;
> +	} else {
> +		conf.direction = DMA_DEV_TO_MEM;
> +		conf.src_addr = host->mem_res->start + JZ_REG_MMC_RXFIFO;
> +		conf.slave_id = JZ4740_DMA_TYPE_MMC_RECEIVE;
> +		chan = host->dma_rx;
> +	}
> +
> +	dmaengine_slave_config(chan, &conf);
> +	desc = dmaengine_prep_slave_sg(chan,
> +				       data->sg,
> +				       host->sg_len,
> +				       conf.direction,
> +				       DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
> +	if (!desc) {
> +		dev_err(mmc_dev(host->mmc),
> +			 "Failed to allocate DMA %s descriptor",
> +			 conf.direction == DMA_MEM_TO_DEV ? "TX" : "RX");
> +		goto dma_unmap;
> +	}
> +
> +	dmaengine_submit(desc);
> +	dma_async_issue_pending(chan);
> +
> +	return 0;
> +
> +dma_unmap:
> +	jz4740_dma_unmap(host, data);
> +	return -ENOMEM;
> +}
> +
> +/*-------------------------------------------------------------------------
> ---*/ +
>  static void jz4740_mmc_set_irq_enabled(struct jz4740_mmc_host *host,
>  	unsigned int irq, bool enabled)
>  {

[snip]

> @@ -784,10 +922,17 @@ static int jz4740_mmc_probe(struct platform_device*
> pdev) goto err_free_host;
>  	}
> 
> -	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	host->base = devm_ioremap_resource(&pdev->dev, res);
> +	host->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!host->mem_res) {
> +		ret = -EBUSY;
> +		dev_err(&pdev->dev, "Failed to request memory region\n");
> +		goto err_free_host;

The devm_ioremap_resource() call below will handle the mem_res == NULL case 
and print a message, so you could remove this check.

> +	}
> +
> +	host->base = devm_ioremap_resource(&pdev->dev, host->mem_res);
>  	if (IS_ERR(host->base)) {
>  		ret = PTR_ERR(host->base);
> +		dev_err(&pdev->dev, "Failed to ioremap base memory\n");
>  		goto err_free_host;
>  	}
> 

[snip]

-- 
Regards,

Laurent Pinchart


      reply	other threads:[~2014-07-11  0:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-10 22:27 [PATCH v3] Use DMA for data transfers in JZ4740 MMC driver Apelete Seketeli
2014-07-10 22:27 ` [PATCH v3] mmc: jz4740: add dma infrastructure for data transfers Apelete Seketeli
2014-07-11  0:03   ` Laurent Pinchart [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=26025372.ALyVZ87vgl@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=alex.smith@imgtec.com \
    --cc=apelete@seketeli.net \
    --cc=chris@printf.net \
    --cc=hsweeten@visionengravers.com \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    --cc=yongjun_wei@trendmicro.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).