Skip to contentSkip to conversation

dw_dmac: cleanup for DT usage

PATCH In review Andy Shevchenko 5 participants 19 messages Mar 26, 2013 – Apr 1, 2013 dmaengine

lore
Share & tools
lore
#0 lore raw

v2 cover dw_dmac: cleanup for DT usage

It includes few cleanups when used with DT. Patch 4/4 is a modified version of the [1].

[1] http://www.spinics.net/lists/arm-kernel/msg225366.html

Since v1:
- address Arnd's comments
- apply Acks I got from Viresh

Andy Shevchenko (3):
dw_dmac: fix style of the comments
dw_dmac: rename DT related methods to reflect their belonging
dw_dmac: make wrapper on of_dma_controller_register()

Arnd Bergmann (1):
dmaengine: dw_dmac: simplify master selection

 drivers/dma/dw_dmac.c      | 145 +++++++++++++++++++++------------------------
 drivers/dma/dw_dmac_regs.h |   5 +-
 2 files changed, 71 insertions(+), 79 deletions(-)
Signature · 1 line
1.8.2.rc0.22.gb3600c3
#1 lore raw

PATCH v2 1/4 dw_dmac: fix style of the comments

Let's use capital letter as a first one in the comments. There is no functional changes.

---
 drivers/dma/dw_dmac.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/dma/dw_dmac.c +15 -15
index 43e2e89..d6dbb14 100644
@@ -173,7 +173,7 @@ static void dwc_initialize(struct dw_dma_chan *dwc)
 		return;
 
 	if (dws && dws->cfg_hi == ~0 && dws->cfg_lo == ~0) {
-		/* autoconfigure based on request line from DT */
+		/* Autoconfigure based on request line from DT */
 		if (dwc->direction == DMA_MEM_TO_DEV)
 			cfghi = DWC_CFGH_DST_PER(dwc->request_line);
 		else if (dwc->direction == DMA_DEV_TO_MEM)
@@ -473,16 +473,16 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc)
 			(unsigned long long)llp);
 
 	list_for_each_entry_safe(desc, _desc, &dwc->active_list, desc_node) {
-		/* initial residue value */
+		/* Initial residue value */
 		dwc->residue = desc->total_len;
 
-		/* check first descriptors addr */
+		/* Check first descriptors addr */
 		if (desc->txd.phys == llp) {
 			spin_unlock_irqrestore(&dwc->lock, flags);
 			return;
 		}
 
-		/* check first descriptors llp */
+		/* Check first descriptors llp */
 		if (desc->lli.llp == llp) {
 			/* This one is currently in progress */
 			dwc->residue -= dwc_get_sent(dwc);
@@ -588,7 +588,7 @@ inline dma_addr_t dw_dma_get_dst_addr(struct dma_chan *chan)
 }
 EXPORT_SYMBOL(dw_dma_get_dst_addr);
 
-/* called with dwc->lock held and all DMAC interrupts disabled */
+/* Called with dwc->lock held and all DMAC interrupts disabled */
 static void dwc_handle_cyclic(struct dw_dma *dw, struct dw_dma_chan *dwc,
 		u32 status_err, u32 status_xfer)
 {
@@ -626,7 +626,7 @@ static void dwc_handle_cyclic(struct dw_dma *dw, struct dw_dma_chan *dwc,
 
 		dwc_chan_disable(dw, dwc);
 
-		/* make sure DMA does not restart by loading a new list */
+		/* Make sure DMA does not restart by loading a new list */
 		channel_writel(dwc, LLP, 0);
 		channel_writel(dwc, CTL_LO, 0);
 		channel_writel(dwc, CTL_HI, 0);
@@ -1256,7 +1256,7 @@ static bool dw_dma_generic_filter(struct dma_chan *chan, void *param)
 	struct dw_dma_filter_args *fargs = param;
 	struct dw_dma_slave *dws = &dwc->slave;
 
-	/* ensure the device matches our channel */
+	/* Ensure the device matches our channel */
         if (chan->device != &fargs->dw->dma)
                 return false;
 
@@ -1323,7 +1323,7 @@ int dw_dma_cyclic_start(struct dma_chan *chan)
 
 	spin_lock_irqsave(&dwc->lock, flags);
 
-	/* assert channel is idle */
+	/* Assert channel is idle */
 	if (dma_readl(dw, CH_EN) & dwc->mask) {
 		dev_err(chan2dev(&dwc->chan),
 			"BUG: Attempted to start non-idle channel\n");
@@ -1335,7 +1335,7 @@ int dw_dma_cyclic_start(struct dma_chan *chan)
 	dma_writel(dw, CLEAR.ERROR, dwc->mask);
 	dma_writel(dw, CLEAR.XFER, dwc->mask);
 
-	/* setup DMAC channel registers */
+	/* Setup DMAC channel registers */
 	channel_writel(dwc, LLP, dwc->cdesc->desc[0]->txd.phys);
 	channel_writel(dwc, CTL_LO, DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN);
 	channel_writel(dwc, CTL_HI, 0);
@@ -1502,7 +1502,7 @@ struct dw_cyclic_desc *dw_dma_cyclic_prep(struct dma_chan *chan,
 		last = desc;
 	}
 
-	/* lets make a cyclic list */
+	/* Let's make a cyclic list */
 	last->lli.llp = cdesc->desc[0]->txd.phys;
 
 	dev_dbg(chan2dev(&dwc->chan), "cyclic prepared buf 0x%llx len %zu "
@@ -1707,7 +1707,7 @@ static int dw_probe(struct platform_device *pdev)
 
 	dw->regs = regs;
 
-	/* get hardware configuration parameters */
+	/* Get hardware configuration parameters */
 	if (autocfg) {
 		max_blk_size = dma_readl(dw, MAX_BLK_SIZE);
 
@@ -1729,10 +1729,10 @@ static int dw_probe(struct platform_device *pdev)
 	/* Calculate all channel mask before DMA setup */
 	dw->all_chan_mask = (1 << nr_channels) - 1;
 
-	/* force dma off, just in case */
+	/* Force dma off, just in case */
 	dw_dma_off(dw);
 
-	/* disable BLOCK interrupts as well */
+	/* Disable BLOCK interrupts as well */
 	channel_clear_bit(dw, MASK.BLOCK, dw->all_chan_mask);
 
 	err = devm_request_irq(&pdev->dev, irq, dw_dma_interrupt, 0,
@@ -1742,7 +1742,7 @@ static int dw_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, dw);
 
-	/* create a pool of consistent memory blocks for hardware descriptors */
+	/* Create a pool of consistent memory blocks for hardware descriptors */
 	dw->desc_pool = dmam_pool_create("dw_dmac_desc_pool", &pdev->dev,
 					 sizeof(struct dw_desc), 4, 0);
 	if (!dw->desc_pool) {
@@ -1783,7 +1783,7 @@ static int dw_probe(struct platform_device *pdev)
 
 		dwc->direction = DMA_TRANS_NONE;
 
-		/* hardware configuration */
+		/* Hardware configuration */
 		if (autocfg) {
 			unsigned int dwc_params;
 
Signature · 1 line
1.8.2.rc0.22.gb3600c3
#3 lore raw

PATCH v2 2/4 dw_dmac: rename DT related methods to reflect their belonging

In reply to Andy Shevchenko

Since we will have not only DT cases in future let's rename DT related methods to reflect their belonging.

The rename was done as follows:

	struct dw_dma_filter_args	-> struct dw_dma_of_filter_args
	dw_dma_generic_filter()		-> dw_dma_of_filter()
	dw_dma_xlate()			-> dw_dma_of_xlate()
	dw_dma_id_table			-> dw_dma_of_id_table

There is no functional change.

---
 drivers/dma/dw_dmac.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/dma/dw_dmac.c +13 -11
index d6dbb14..274fd7d 100644
@@ -1242,18 +1242,20 @@ static void dwc_free_chan_resources(struct dma_chan *chan)
 	dev_vdbg(chan2dev(chan), "%s: done\n", __func__);
 }
 
-struct dw_dma_filter_args {
+/*----------------------------------------------------------------------*/
+
+struct dw_dma_of_filter_args {
 	struct dw_dma *dw;
 	unsigned int req;
 	unsigned int src;
 	unsigned int dst;
 };
 
-static bool dw_dma_generic_filter(struct dma_chan *chan, void *param)
+static bool dw_dma_of_filter(struct dma_chan *chan, void *param)
 {
 	struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
 	struct dw_dma *dw = to_dw_dma(chan->device);
-	struct dw_dma_filter_args *fargs = param;
+	struct dw_dma_of_filter_args *fargs = param;
 	struct dw_dma_slave *dws = &dwc->slave;
 
 	/* Ensure the device matches our channel */
@@ -1273,11 +1275,11 @@ static bool dw_dma_generic_filter(struct dma_chan *chan, void *param)
 	return true;
 }
 
-static struct dma_chan *dw_dma_xlate(struct of_phandle_args *dma_spec,
-					 struct of_dma *ofdma)
+static struct dma_chan *dw_dma_of_xlate(struct of_phandle_args *dma_spec,
+					struct of_dma *ofdma)
 {
 	struct dw_dma *dw = ofdma->of_dma_data;
-	struct dw_dma_filter_args fargs = {
+	struct dw_dma_of_filter_args fargs = {
 		.dw = dw,
 	};
 	dma_cap_mask_t cap;
@@ -1298,7 +1300,7 @@ static struct dma_chan *dw_dma_xlate(struct of_phandle_args *dma_spec,
 	dma_cap_set(DMA_SLAVE, cap);
 
 	/* TODO: there should be a simpler way to do this */
-	return dma_request_channel(cap, dw_dma_generic_filter, &fargs);
+	return dma_request_channel(cap, dw_dma_of_filter, &fargs);
 }
 
 /* --------------------- Cyclic DMA API extensions -------------------- */
@@ -1843,7 +1845,7 @@ static int dw_probe(struct platform_device *pdev)
 
 	if (pdev->dev.of_node) {
 		err = of_dma_controller_register(pdev->dev.of_node,
-						 dw_dma_xlate, dw);
+						 dw_dma_of_xlate, dw);
 		if (err && err != -ENODEV)
 			dev_err(&pdev->dev,
 				"could not register of_dma_controller\n");
@@ -1913,11 +1915,11 @@ static const struct dev_pm_ops dw_dev_pm_ops = {
 };
 
 #ifdef CONFIG_OF
-static const struct of_device_id dw_dma_id_table[] = {
+static const struct of_device_id dw_dma_of_id_table[] = {
 	{ .compatible = "snps,dma-spear1340" },
 	{}
 };
-MODULE_DEVICE_TABLE(of, dw_dma_id_table);
+MODULE_DEVICE_TABLE(of, dw_dma_of_id_table);
 #endif
 
 static const struct platform_device_id dw_dma_ids[] = {
@@ -1933,7 +1935,7 @@ static struct platform_driver dw_driver = {
 	.driver = {
 		.name	= "dw_dmac",
 		.pm	= &dw_dev_pm_ops,
-		.of_match_table = of_match_ptr(dw_dma_id_table),
+		.of_match_table = of_match_ptr(dw_dma_of_id_table),
 	},
 	.id_table	= dw_dma_ids,
 };
Signature · 1 line
1.8.2.rc0.22.gb3600c3
Acked-by on v2 2/4
#4 lore raw

Re: [PATCH v2 2/4] dw_dmac: rename DT related methods to reflect their belonging

Quoted 9 lines · Andy Shevchenko

Since we will have not only DT cases in future let's rename DT related methods to reflect their belonging.

The rename was done as follows:

	struct dw_dma_filter_args	-> struct dw_dma_of_filter_args
	dw_dma_generic_filter()		-> dw_dma_of_filter()
	dw_dma_xlate()			-> dw_dma_of_xlate()
	dw_dma_id_table			-> dw_dma_of_id_table
Quoted 4 lines

There is no functional change.

#5 lore raw

PATCH v2 3/4 dw_dmac: make wrapper on of_dma_controller_register()

In reply to Andy Shevchenko

This patch introduces new method dw_dma_of_controller_register() and adds checks of the of_node presence together with CONFIG_OF before calling the wrapper. It helps to distinguish the real -ENODEV return code of fake one when of_dma_controller_register is not implemented.

---
 drivers/dma/dw_dmac.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/dma/dw_dmac.c +12 -7
index 274fd7d..c1f017b 100644
@@ -1303,6 +1303,16 @@ static struct dma_chan *dw_dma_of_xlate(struct of_phandle_args *dma_spec,
 	return dma_request_channel(cap, dw_dma_of_filter, &fargs);
 }
 
+static void dw_dma_of_controller_register(struct dw_dma *dw)
+{
+	struct device *dev = dw->dma.dev;
+	int err;
+
+	err = of_dma_controller_register(dev->of_node, dw_dma_of_xlate, dw);
+	if (err)
+		dev_err(dev, "could not register of_dma_controller\n");
+}
+
 /* --------------------- Cyclic DMA API extensions -------------------- */
 
 /**
@@ -1843,13 +1853,8 @@ static int dw_probe(struct platform_device *pdev)
 
 	dma_async_device_register(&dw->dma);
 
-	if (pdev->dev.of_node) {
-		err = of_dma_controller_register(pdev->dev.of_node,
-						 dw_dma_of_xlate, dw);
-		if (err && err != -ENODEV)
-			dev_err(&pdev->dev,
-				"could not register of_dma_controller\n");
-	}
+	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node)
+		dw_dma_of_controller_register(dw);
 
 	return 0;
 }
Signature · 1 line
1.8.2.rc0.22.gb3600c3
Acked-by on v2 3/4
#6 lore raw

Re: [PATCH v2 3/4] dw_dmac: make wrapper on of_dma_controller_register()

Quoted 6 lines · Andy Shevchenko

This patch introduces new method dw_dma_of_controller_register() and adds checks of the of_node presence together with CONFIG_OF before calling the wrapper. It helps to distinguish the real -ENODEV return code of fake one when of_dma_controller_register is not implemented.

Thanks for the update

#7 lore raw

Re: [PATCH v2 3/4] dw_dmac: make wrapper on of_dma_controller_register()

In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

This patch introduces new method dw_dma_of_controller_register() and adds checks of the of_node presence together with CONFIG_OF before calling the wrapper. It helps to distinguish the real -ENODEV return code of fake one when of_dma_controller_register is not implemented.

If CONFIG_OF is not set the of_node of the device will always be NULL. Which means of_dma_controller_register() will only be called if it is implemented. So you'll never get the -ENODEV from the of_dma_controller_register() stub.

- Lars

Quoted 43 lines
---
 drivers/dma/dw_dmac.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/dma/dw_dmac.c +12 -7
index 274fd7d..c1f017b 100644
@@ -1303,6 +1303,16 @@ static struct dma_chan *dw_dma_of_xlate(struct of_phandle_args *dma_spec,
 	return dma_request_channel(cap, dw_dma_of_filter, &fargs);
 }
 
+static void dw_dma_of_controller_register(struct dw_dma *dw)
+{
+	struct device *dev = dw->dma.dev;
+	int err;
+
+	err = of_dma_controller_register(dev->of_node, dw_dma_of_xlate, dw);
+	if (err)
+		dev_err(dev, "could not register of_dma_controller\n");
+}
+
 /* --------------------- Cyclic DMA API extensions -------------------- */
 
 /**
@@ -1843,13 +1853,8 @@ static int dw_probe(struct platform_device *pdev)
 
 	dma_async_device_register(&dw->dma);
 
-	if (pdev->dev.of_node) {
-		err = of_dma_controller_register(pdev->dev.of_node,
-						 dw_dma_of_xlate, dw);
-		if (err && err != -ENODEV)
-			dev_err(&pdev->dev,
-				"could not register of_dma_controller\n");
-	}
+	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node)
+		dw_dma_of_controller_register(dw);
 
 	return 0;
 }
#8 lore raw

Re: [PATCH v2 3/4] dw_dmac: make wrapper on of_dma_controller_register()

Quoted 9 lines · Lars-Peter Clausen
Quoted 4 lines · Andy Shevchenko

This patch introduces new method dw_dma_of_controller_register() and adds checks of the of_node presence together with CONFIG_OF before calling the wrapper. It helps to distinguish the real -ENODEV return code of fake one when of_dma_controller_register is not implemented.

If CONFIG_OF is not set the of_node of the device will always be NULL. Which means of_dma_controller_register() will only be called if it is implemented. So you'll never get the -ENODEV from the of_dma_controller_register() stub.

Thanks for clarification, I'll update the patch.

Quoted 47 lines

- Lars

Quoted 43 lines
---
 drivers/dma/dw_dmac.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/dma/dw_dmac.c +12 -7
index 274fd7d..c1f017b 100644
@@ -1303,6 +1303,16 @@ static struct dma_chan *dw_dma_of_xlate(struct of_phandle_args *dma_spec,
 	return dma_request_channel(cap, dw_dma_of_filter, &fargs);
 }
 
+static void dw_dma_of_controller_register(struct dw_dma *dw)
+{
+	struct device *dev = dw->dma.dev;
+	int err;
+
+	err = of_dma_controller_register(dev->of_node, dw_dma_of_xlate, dw);
+	if (err)
+		dev_err(dev, "could not register of_dma_controller\n");
+}
+
 /* --------------------- Cyclic DMA API extensions -------------------- */
 
 /**
@@ -1843,13 +1853,8 @@ static int dw_probe(struct platform_device *pdev)
 
 	dma_async_device_register(&dw->dma);
 
-	if (pdev->dev.of_node) {
-		err = of_dma_controller_register(pdev->dev.of_node,
-						 dw_dma_of_xlate, dw);
-		if (err && err != -ENODEV)
-			dev_err(&pdev->dev,
-				"could not register of_dma_controller\n");
-	}
+	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node)
+		dw_dma_of_controller_register(dw);
 
 	return 0;
 }
Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#9 lore raw

PATCH 1/1 dw_dmac: make wrapper on of_dma_controller_register()

In reply to Lars-Peter Clausen

This patch introduces new method dw_dma_of_controller_register(). The wrapper is called only when of_node is present.

---
 drivers/dma/dw_dmac.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/dma/dw_dmac.c +12 -7
index 274fd7d..12657d7 100644
@@ -1303,6 +1303,16 @@ static struct dma_chan *dw_dma_of_xlate(struct of_phandle_args *dma_spec,
 	return dma_request_channel(cap, dw_dma_of_filter, &fargs);
 }
 
+static void dw_dma_of_controller_register(struct dw_dma *dw)
+{
+	struct device *dev = dw->dma.dev;
+	int err;
+
+	err = of_dma_controller_register(dev->of_node, dw_dma_of_xlate, dw);
+	if (err)
+		dev_err(dev, "could not register of_dma_controller\n");
+}
+
 /* --------------------- Cyclic DMA API extensions -------------------- */
 
 /**
@@ -1843,13 +1853,8 @@ static int dw_probe(struct platform_device *pdev)
 
 	dma_async_device_register(&dw->dma);
 
-	if (pdev->dev.of_node) {
-		err = of_dma_controller_register(pdev->dev.of_node,
-						 dw_dma_of_xlate, dw);
-		if (err && err != -ENODEV)
-			dev_err(&pdev->dev,
-				"could not register of_dma_controller\n");
-	}
+	if (pdev->dev.of_node)
+		dw_dma_of_controller_register(dw);
 
 	return 0;
 }
Signature · 1 line
1.8.2.rc0.22.gb3600c3
#10 lore raw

Re: [PATCH v2.1] dw_dmac: make wrapper on of_dma_controller_register()

Quoted 33 lines · Andy Shevchenko

This patch introduces new method dw_dma_of_controller_register(). The wrapper is called only when of_node is present.

---
 drivers/dma/dw_dmac.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/dma/dw_dmac.c +10 -0
index 274fd7d..12657d7 100644
@@ -1303,6 +1303,16 @@ static struct dma_chan *dw_dma_of_xlate(struct of_phandle_args *dma_spec,
        return dma_request_channel(cap, dw_dma_of_filter, &fargs);
 }
 
+static void dw_dma_of_controller_register(struct dw_dma *dw)
+{
+       struct device *dev = dw->dma.dev;
+       int err;
+
+       err = of_dma_controller_register(dev->of_node, dw_dma_of_xlate, dw);
+       if (err)
+               dev_err(dev, "could not register of_dma_controller\n");
+}
+
 /* --------------------- Cyclic DMA API extensions -------------------- */
 
 /**
@@ -1843,13 +1853,8 @@ static int dw_probe(struct platform_device *pdev)
 
        dma_async_device_register(&dw->dma);

drivers/dma/dw_dmac.c static int dw_probe(struct platform_device *pdev) · line 1857

Quoted 10 lines
drivers/dma/dw_dmac.c +2 -7
 
-       if (pdev->dev.of_node) {
-               err = of_dma_controller_register(pdev->dev.of_node,
-                                                dw_dma_of_xlate, dw);
-               if (err && err != -ENODEV)
-                       dev_err(&pdev->dev,
-                               "could not register of_dma_controller\n");
-       }
+       if (pdev->dev.of_node)
+               dw_dma_of_controller_register(dw);

I forgot where we started from, but what's the need of this patch?

#11 lore raw

Re: [PATCH v2.1] dw_dmac: make wrapper on of_dma_controller_register()

Quoted 36 lines · Viresh Kumar
Quoted 34 lines · Andy Shevchenko

This patch introduces new method dw_dma_of_controller_register(). The wrapper is called only when of_node is present.

---
 drivers/dma/dw_dmac.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/dma/dw_dmac.c +10 -0
index 274fd7d..12657d7 100644
@@ -1303,6 +1303,16 @@ static struct dma_chan *dw_dma_of_xlate(struct of_phandle_args *dma_spec,
        return dma_request_channel(cap, dw_dma_of_filter, &fargs);
 }
 
+static void dw_dma_of_controller_register(struct dw_dma *dw)
+{
+       struct device *dev = dw->dma.dev;
+       int err;
+
+       err = of_dma_controller_register(dev->of_node, dw_dma_of_xlate, dw);
+       if (err)
+               dev_err(dev, "could not register of_dma_controller\n");
+}
+
 /* --------------------- Cyclic DMA API extensions -------------------- */
 
 /**
@@ -1843,13 +1853,8 @@ static int dw_probe(struct platform_device *pdev)
 
        dma_async_device_register(&dw->dma);
 
Quoted 11 lines

drivers/dma/dw_dmac.c static int dw_probe(struct platform_device *pdev) · line 1857

Quoted 9 lines
drivers/dma/dw_dmac.c +2 -7
-       if (pdev->dev.of_node) {
-               err = of_dma_controller_register(pdev->dev.of_node,
-                                                dw_dma_of_xlate, dw);
-               if (err && err != -ENODEV)
-                       dev_err(&pdev->dev,
-                               "could not register of_dma_controller\n");
-       }
+       if (pdev->dev.of_node)
+               dw_dma_of_controller_register(dw);

I forgot where we started from, but what's the need of this patch?

Nowadays, besides removal of the -ENODEV checking, it makes probe function looks tidier.

Think about upcoming stuff (e.g. ACPI), if we put everything inside probe it will look overloaded.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#12 lore raw

Re: [PATCH v2.1] dw_dmac: make wrapper on of_dma_controller_register()

Quoted 2 lines · Andy Shevchenko

Nowadays, besides removal of the -ENODEV checking, it makes probe function looks tidier.

Removal of -ENODEV is okay but am not sure if it makes code good :)

This is unnecessary abstraction for just calling a single routine. If that part was bigger, i would have agreed but to me this wrapper is just adding abstraction and nothing more.

--
viresh

#13 lore raw

PATCH 1/1 dw_dmac: remove unnecessary ENODEV check

If CONFIG_OF is not set the of_node of the device will always be NULL.

---
 drivers/dma/dw_dmac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dw_dmac.c +1 -1
index 274fd7d..736cffa 100644
@@ -1846,7 +1846,7 @@ static int dw_probe(struct platform_device *pdev)
 	if (pdev->dev.of_node) {
 		err = of_dma_controller_register(pdev->dev.of_node,
 						 dw_dma_of_xlate, dw);
-		if (err && err != -ENODEV)
+		if (err)
 			dev_err(&pdev->dev,
 				"could not register of_dma_controller\n");
 	}
Signature · 1 line
1.8.2.rc0.22.gb3600c3
Acked-by on v1 1/1
#14 lore raw

Re: [PATCH v2.2] dw_dmac: remove unnecessary ENODEV check

Quoted 12 lines · Andy Shevchenko

If CONFIG_OF is not set the of_node of the device will always be NULL.

---
 drivers/dma/dw_dmac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dw_dmac.c +0 -0
index 274fd7d..736cffa 100644

drivers/dma/dw_dmac.c static int dw_probe(struct platform_device *pdev) · line 1851

Quoted 7 lines
drivers/dma/dw_dmac.c +1 -1
@@ -1846,7 +1846,7 @@ static int dw_probe(struct platform_device *pdev)
        if (pdev->dev.of_node) {
                err = of_dma_controller_register(pdev->dev.of_node,
                                                 dw_dma_of_xlate, dw);
-               if (err && err != -ENODEV)
+               if (err)
                        dev_err(&pdev->dev,
                                "could not register of_dma_controller\n");
Acked-by
#15 lore raw

Re: [PATCH v2.2] dw_dmac: remove unnecessary ENODEV check

Quoted 10 lines · Viresh Kumar
Quoted 7 lines · Andy Shevchenko

If CONFIG_OF is not set the of_node of the device will always be NULL.

---
 drivers/dma/dw_dmac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

drivers/dma/dw_dmac.c static int dw_probe(struct platform_device *pdev) · line 1851

Quoted 12 lines
drivers/dma/dw_dmac.c +1 -1
index 274fd7d..736cffa 100644
@@ -1846,7 +1846,7 @@ static int dw_probe(struct platform_device *pdev)
        if (pdev->dev.of_node) {
                err = of_dma_controller_register(pdev->dev.of_node,
                                                 dw_dma_of_xlate, dw);
-               if (err && err != -ENODEV)
+               if (err)
                        dev_err(&pdev->dev,
                                "could not register of_dma_controller\n");
#16 lore raw

PATCH v2 4/4 dmaengine: dw_dmac: simplify master selection

In reply to Andy Shevchenko

From: Arnd Bergmann <[email protected]>

The patch to add the common DMA binding added a dummy dw_dma_slave structure into the dw_dma_chan structure in order to configure the masters correctly. It turns out that this can be simplified if we pick the DMA masters in the dwc_alloc_chan_resources function instead and save them in the dw_dma_chan structure directly.

This could be simplified further once all users that today use dw_dma_slave for configuration get converted to device tree based setup instead.

Cc linux-arm-kernel at lists.infradead.org
---
 drivers/dma/dw_dmac.c      | 76 ++++++++++++++++++----------------------------
 drivers/dma/dw_dmac_regs.h |  5 ++-
 2 files changed, 33 insertions(+), 48 deletions(-)
drivers/dma/dw_dmac.c +29 -47
index c1f017b..5c9fec6 100644
@@ -49,29 +49,22 @@ static inline unsigned int dwc_get_sms(struct dw_dma_slave *slave)
 	return slave ? slave->src_master : 1;
 }
 
-#define SRC_MASTER	0
-#define DST_MASTER	1
-
-static inline unsigned int dwc_get_master(struct dma_chan *chan, int master)
+static inline void dwc_set_masters(struct dw_dma_chan *dwc)
 {
-	struct dw_dma *dw = to_dw_dma(chan->device);
-	struct dw_dma_slave *dws = chan->private;
-	unsigned int m;
-
-	if (master == SRC_MASTER)
-		m = dwc_get_sms(dws);
-	else
-		m = dwc_get_dms(dws);
+	struct dw_dma *dw = to_dw_dma(dwc->chan.device);
+	struct dw_dma_slave *dws = dwc->chan.private;
+	unsigned char mmax = dw->nr_masters - 1;
 
-	return min_t(unsigned int, dw->nr_masters - 1, m);
+	if (dwc->request_line == ~0) {
+		dwc->src_master = min_t(unsigned char, mmax, dwc_get_sms(dws));
+		dwc->dst_master = min_t(unsigned char, mmax, dwc_get_dms(dws));
+	}
 }
 
 #define DWC_DEFAULT_CTLLO(_chan) ({				\
 		struct dw_dma_chan *_dwc = to_dw_dma_chan(_chan);	\
 		struct dma_slave_config	*_sconfig = &_dwc->dma_sconfig;	\
 		bool _is_slave = is_slave_direction(_dwc->direction);	\
-		int _dms = dwc_get_master(_chan, DST_MASTER);		\
-		int _sms = dwc_get_master(_chan, SRC_MASTER);		\
 		u8 _smsize = _is_slave ? _sconfig->src_maxburst :	\
 			DW_DMA_MSIZE_16;			\
 		u8 _dmsize = _is_slave ? _sconfig->dst_maxburst :	\
@@ -81,8 +74,8 @@ static inline unsigned int dwc_get_master(struct dma_chan *chan, int master)
 		 | DWC_CTLL_SRC_MSIZE(_smsize)			\
 		 | DWC_CTLL_LLP_D_EN				\
 		 | DWC_CTLL_LLP_S_EN				\
-		 | DWC_CTLL_DMS(_dms)				\
-		 | DWC_CTLL_SMS(_sms));				\
+		 | DWC_CTLL_DMS(_dwc->dst_master)		\
+		 | DWC_CTLL_SMS(_dwc->src_master));		\
 	})
 
 /*
@@ -92,13 +85,6 @@ static inline unsigned int dwc_get_master(struct dma_chan *chan, int master)
  */
 #define NR_DESCS_PER_CHANNEL	64
 
-static inline unsigned int dwc_get_data_width(struct dma_chan *chan, int master)
-{
-	struct dw_dma *dw = to_dw_dma(chan->device);
-
-	return dw->data_width[dwc_get_master(chan, master)];
-}
-
 /*----------------------------------------------------------------------*/
 
 static struct device *chan2dev(struct dma_chan *chan)
@@ -172,13 +158,7 @@ static void dwc_initialize(struct dw_dma_chan *dwc)
 	if (dwc->initialized == true)
 		return;
 
-	if (dws && dws->cfg_hi == ~0 && dws->cfg_lo == ~0) {
-		/* Autoconfigure based on request line from DT */
-		if (dwc->direction == DMA_MEM_TO_DEV)
-			cfghi = DWC_CFGH_DST_PER(dwc->request_line);
-		else if (dwc->direction == DMA_DEV_TO_MEM)
-			cfghi = DWC_CFGH_SRC_PER(dwc->request_line);
-	} else if (dws) {
+	if (dws) {
 		/*
 		 * We need controller-specific data to set up slave
 		 * transfers.
@@ -189,9 +169,9 @@ static void dwc_initialize(struct dw_dma_chan *dwc)
 		cfglo |= dws->cfg_lo & ~DWC_CFGL_CH_PRIOR_MASK;
 	} else {
 		if (dwc->direction == DMA_MEM_TO_DEV)
-			cfghi = DWC_CFGH_DST_PER(dwc->dma_sconfig.slave_id);
+			cfghi = DWC_CFGH_DST_PER(dwc->request_line);
 		else if (dwc->direction == DMA_DEV_TO_MEM)
-			cfghi = DWC_CFGH_SRC_PER(dwc->dma_sconfig.slave_id);
+			cfghi = DWC_CFGH_SRC_PER(dwc->request_line);
 	}
 
 	channel_writel(dwc, CFG_LO, cfglo);
@@ -745,6 +725,7 @@ dwc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
 		size_t len, unsigned long flags)
 {
 	struct dw_dma_chan	*dwc = to_dw_dma_chan(chan);
+	struct dw_dma		*dw = to_dw_dma(chan->device);
 	struct dw_desc		*desc;
 	struct dw_desc		*first;
 	struct dw_desc		*prev;
@@ -767,8 +748,8 @@ dwc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
 
 	dwc->direction = DMA_MEM_TO_MEM;
 
-	data_width = min_t(unsigned int, dwc_get_data_width(chan, SRC_MASTER),
-			   dwc_get_data_width(chan, DST_MASTER));
+	data_width = min_t(unsigned int, dw->data_width[dwc->src_master],
+			   dw->data_width[dwc->dst_master]);
 
 	src_width = dst_width = min_t(unsigned int, data_width,
 				      dwc_fast_fls(src | dest | len));
@@ -826,6 +807,7 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
 		unsigned long flags, void *context)
 {
 	struct dw_dma_chan	*dwc = to_dw_dma_chan(chan);
+	struct dw_dma		*dw = to_dw_dma(chan->device);
 	struct dma_slave_config	*sconfig = &dwc->dma_sconfig;
 	struct dw_desc		*prev;
 	struct dw_desc		*first;
@@ -859,7 +841,7 @@ dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
 		ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_M2P) :
 			DWC_CTLL_FC(DW_DMA_FC_D_M2P);
 
-		data_width = dwc_get_data_width(chan, SRC_MASTER);
+		data_width = dw->data_width[dwc->src_master];
 
 		for_each_sg(sgl, sg, sg_len, i) {
 			struct dw_desc	*desc;
@@ -919,7 +901,7 @@ slave_sg_todev_fill_desc:
 		ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_P2M) :
 			DWC_CTLL_FC(DW_DMA_FC_D_P2M);
 
-		data_width = dwc_get_data_width(chan, DST_MASTER);
+		data_width = dw->data_width[dwc->dst_master];
 
 		for_each_sg(sgl, sg, sg_len, i) {
 			struct dw_desc	*desc;
@@ -1020,6 +1002,10 @@ set_runtime_config(struct dma_chan *chan, struct dma_slave_config *sconfig)
 	memcpy(&dwc->dma_sconfig, sconfig, sizeof(*sconfig));
 	dwc->direction = sconfig->direction;
 
+	/* Take the request line from slave_id member */
+	if (dwc->request_line == ~0)
+		dwc->request_line = sconfig->slave_id;
+
 	convert_burst(&dwc->dma_sconfig.src_maxburst);
 	convert_burst(&dwc->dma_sconfig.dst_maxburst);
 	convert_slave_id(dwc);
@@ -1170,6 +1156,8 @@ static int dwc_alloc_chan_resources(struct dma_chan *chan)
 	 * doesn't mean what you think it means), and status writeback.
 	 */
 
+	dwc_set_masters(dwc);
+
 	spin_lock_irqsave(&dwc->lock, flags);
 	i = dwc->descs_allocated;
 	while (dwc->descs_allocated < NR_DESCS_PER_CHANNEL) {
@@ -1227,6 +1215,7 @@ static void dwc_free_chan_resources(struct dma_chan *chan)
 	list_splice_init(&dwc->free_list, &list);
 	dwc->descs_allocated = 0;
 	dwc->initialized = false;
+	dwc->request_line = ~0;
 
 	/* Disable interrupts */
 	channel_clear_bit(dw, MASK.XFER, dwc->mask);
@@ -1254,23 +1243,15 @@ struct dw_dma_of_filter_args {
 static bool dw_dma_of_filter(struct dma_chan *chan, void *param)
 {
 	struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
-	struct dw_dma *dw = to_dw_dma(chan->device);
 	struct dw_dma_of_filter_args *fargs = param;
-	struct dw_dma_slave *dws = &dwc->slave;
 
 	/* Ensure the device matches our channel */
         if (chan->device != &fargs->dw->dma)
                 return false;
 
-	dws->dma_dev	= dw->dma.dev;
-	dws->cfg_hi	= ~0;
-	dws->cfg_lo	= ~0;
-	dws->src_master	= fargs->src;
-	dws->dst_master	= fargs->dst;
-
 	dwc->request_line = fargs->req;
-
-	chan->private = dws;
+	dwc->src_master	= fargs->src;
+	dwc->dst_master	= fargs->dst;
 
 	return true;
 }
@@ -1794,6 +1775,7 @@ static int dw_probe(struct platform_device *pdev)
 		channel_clear_bit(dw, CH_EN, dwc->mask);
 
 		dwc->direction = DMA_TRANS_NONE;
+		dwc->request_line = ~0;
 
 		/* Hardware configuration */
 		if (autocfg) {
drivers/dma/dw_dmac_regs.h +4 -1
index 4d02c36..9b0e12e 100644
@@ -212,8 +212,11 @@ struct dw_dma_chan {
 	/* hardware configuration */
 	unsigned int		block_size;
 	bool			nollp;
+
+	/* custom slave configuration */
 	unsigned int		request_line;
-	struct dw_dma_slave	slave;
+	unsigned char		src_master;
+	unsigned char		dst_master;
 
 	/* configuration passed via DMA_SLAVE_CONFIG */
 	struct dma_slave_config dma_sconfig;
Signature · 1 line
1.8.2.rc0.22.gb3600c3
Acked-by on v2 4/4
#17 lore raw

Re: [PATCH v2 4/4] dmaengine: dw_dmac: simplify master selection

Quoted 9 lines · Andy Shevchenko

From: Arnd Bergmann <[email protected]>

The patch to add the common DMA binding added a dummy dw_dma_slave structure into the dw_dma_chan structure in order to configure the masters correctly. It turns out that this can be simplified if we pick the DMA masters in the dwc_alloc_chan_resources function instead and save them in the dw_dma_chan structure directly.

Quoted 8 lines

This could be simplified further once all users that today use dw_dma_slave for configuration get converted to device tree based setup instead.

Cc linux-arm-kernel at lists.infradead.org
#18 lore raw
In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

It includes few cleanups when used with DT. Patch 4/4 is a modified version of the [1].

Applied 1, 2, 4 & 2.2

Thanks
~Vinod

Quoted 22 lines

[1] http://www.spinics.net/lists/arm-kernel/msg225366.html

Since v1:
- address Arnd's comments
- apply Acks I got from Viresh

Andy Shevchenko (3):
dw_dmac: fix style of the comments
dw_dmac: rename DT related methods to reflect their belonging
dw_dmac: make wrapper on of_dma_controller_register()

Arnd Bergmann (1):
dmaengine: dw_dmac: simplify master selection

 drivers/dma/dw_dmac.c      | 145 +++++++++++++++++++++------------------------
 drivers/dma/dw_dmac_regs.h |   5 +-
 2 files changed, 71 insertions(+), 79 deletions(-)
Signature · 1 line
1.8.2.rc0.22.gb3600c3