diff mbox

[v3,4/4] mmc: atmel-mci: use probe deferring if dma controller is not ready yet

Message ID 1417183686-31481-5-git-send-email-ludovic.desroches@atmel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ludovic Desroches Nov. 28, 2014, 2:08 p.m. UTC
Return probe defer if requesting a dma channel without a dma controller
probed.

Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
---
 drivers/mmc/host/atmel-mci.c | 49 ++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 24 deletions(-)

Comments

Russell King - ARM Linux Nov. 28, 2014, 2:19 p.m. UTC | #1
Let's look at the resulting code:

On Fri, Nov 28, 2014 at 03:08:06PM +0100, Ludovic Desroches wrote:
> +static int atmci_configure_dma(struct atmel_mci *host)
>  {
> +	int ret = 0;
>  
> +	host->dma.chan = dma_request_slave_channel_reason(&host->pdev->dev, "rxtx");
> +	if (IS_ERR(host->dma.chan))
> +		return PTR_ERR(host->dma.chan);
> +
> +	dev_info(&host->pdev->dev, "using %s for DMA transfers\n",
> +		 dma_chan_name(host->dma.chan));
> +
> +	host->dma_conf.src_addr = host->mapbase + ATMCI_RDR;
> +	host->dma_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
> +	host->dma_conf.src_maxburst = 1;
> +	host->dma_conf.dst_addr = host->mapbase + ATMCI_TDR;
> +	host->dma_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
> +	host->dma_conf.dst_maxburst = 1;
> +	host->dma_conf.device_fc = false;
> +
> +	return ret;
>  }

I think you can clean this up a little further - what do you notice
about the value of "ret" here?
Ludovic Desroches Nov. 28, 2014, 2:35 p.m. UTC | #2
On Fri, Nov 28, 2014 at 02:19:03PM +0000, Russell King - ARM Linux wrote:
> Let's look at the resulting code:
> 
> On Fri, Nov 28, 2014 at 03:08:06PM +0100, Ludovic Desroches wrote:
> > +static int atmci_configure_dma(struct atmel_mci *host)
> >  {
> > +	int ret = 0;
> >  
> > +	host->dma.chan = dma_request_slave_channel_reason(&host->pdev->dev, "rxtx");
> > +	if (IS_ERR(host->dma.chan))
> > +		return PTR_ERR(host->dma.chan);
> > +
> > +	dev_info(&host->pdev->dev, "using %s for DMA transfers\n",
> > +		 dma_chan_name(host->dma.chan));
> > +
> > +	host->dma_conf.src_addr = host->mapbase + ATMCI_RDR;
> > +	host->dma_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
> > +	host->dma_conf.src_maxburst = 1;
> > +	host->dma_conf.dst_addr = host->mapbase + ATMCI_TDR;
> > +	host->dma_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
> > +	host->dma_conf.dst_maxburst = 1;
> > +	host->dma_conf.device_fc = false;
> > +
> > +	return ret;
> >  }
> 
> I think you can clean this up a little further - what do you notice
> about the value of "ret" here?

I think I see what you mean :) The fix I have merged for this patch
makes ret useless.

> 
> -- 
> FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up
> according to speedtest.net.
diff mbox

Patch

diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index 00f6088..0a96819 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -2272,29 +2272,26 @@  static void atmci_cleanup_slot(struct atmel_mci_slot *slot,
 	mmc_free_host(slot->mmc);
 }
 
-static bool atmci_configure_dma(struct atmel_mci *host)
+static int atmci_configure_dma(struct atmel_mci *host)
 {
-	if (host == NULL)
-		return false;
+	int ret = 0;
 
-	host->dma.chan = dma_request_slave_channel(&host->pdev->dev, "rxtx");
-	if (!host->dma.chan) {
-		dev_warn(&host->pdev->dev, "no DMA channel available\n");
-		return false;
-	} else {
-		dev_info(&host->pdev->dev,
-					"using %s for DMA transfers\n",
-					dma_chan_name(host->dma.chan));
-
-		host->dma_conf.src_addr = host->mapbase + ATMCI_RDR;
-		host->dma_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
-		host->dma_conf.src_maxburst = 1;
-		host->dma_conf.dst_addr = host->mapbase + ATMCI_TDR;
-		host->dma_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
-		host->dma_conf.dst_maxburst = 1;
-		host->dma_conf.device_fc = false;
-		return true;
-	}
+	host->dma.chan = dma_request_slave_channel_reason(&host->pdev->dev, "rxtx");
+	if (IS_ERR(host->dma.chan))
+		return PTR_ERR(host->dma.chan);
+
+	dev_info(&host->pdev->dev, "using %s for DMA transfers\n",
+		 dma_chan_name(host->dma.chan));
+
+	host->dma_conf.src_addr = host->mapbase + ATMCI_RDR;
+	host->dma_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+	host->dma_conf.src_maxburst = 1;
+	host->dma_conf.dst_addr = host->mapbase + ATMCI_TDR;
+	host->dma_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
+	host->dma_conf.dst_maxburst = 1;
+	host->dma_conf.device_fc = false;
+
+	return ret;
 }
 
 /*
@@ -2411,7 +2408,10 @@  static int atmci_probe(struct platform_device *pdev)
 
 	/* Get MCI capabilities and set operations according to it */
 	atmci_get_cap(host);
-	if (atmci_configure_dma(host)) {
+	ret = atmci_configure_dma(host);
+	if (ret == -EPROBE_DEFER)
+		goto err_dma_probe_defer;
+	if (ret == 0) {
 		host->prepare_data = &atmci_prepare_data_dma;
 		host->submit_data = &atmci_submit_data_dma;
 		host->stop_transfer = &atmci_stop_transfer_dma;
@@ -2496,8 +2496,9 @@  err_init_slot:
 	pm_runtime_put_noidle(&pdev->dev);
 
 	del_timer_sync(&host->timer);
-	if (host->dma.chan)
+	if (!IS_ERR(host->dma.chan))
 		dma_release_channel(host->dma.chan);
+err_dma_probe_defer:
 	free_irq(irq, host);
 	return ret;
 }
@@ -2523,7 +2524,7 @@  static int atmci_remove(struct platform_device *pdev)
 	atmci_readl(host, ATMCI_SR);
 
 	del_timer_sync(&host->timer);
-	if (host->dma.chan)
+	if (!IS_ERR(host->dma.chan))
 		dma_release_channel(host->dma.chan);
 
 	free_irq(platform_get_irq(pdev, 0), host);