Skip to contentSkip to conversation

To use DMA generic APIs for Samsung DMA

PATCH Superseded Kukjin Kim 6 participants 23 messages Jul 13, 2011 – Jul 16, 2011

Subsystems (8)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Kukjin Kim

author
#0 lore raw

v2 cover To use DMA generic APIs for Samsung DMA

Following is diagram of this changes

+---------------------------------------------------------------------+
| Each drivers which uses DMA                                         |
+---------------------------------------------------------------------+
| S3C DMA API (such as s3c2410_dma_xxxx)                              |
+-------------------------------+-------------------------------------+
| DMA driver for S3C24XX        | S3C PL330 DMA API driver            |
| PL080 DMA driver for S3C64XX  | (arch/arm/plat-samsung/s3c-pl330.c) |
|                               +-------------------------------------+
| (arch/arm/plat-s3c24xx/dma.c) | Common DMA core driver              |
| (arch/arm/mach-s3c64xx/dma.c) | (arch/arm/common/pl330.c)           |
+-------------------------------+-------------------------------------+
                               ||
                (removing S3C DMA API for PL330)
                               ||
                               \/
+---------------------------------------------------------------------+
| Each drivers which uses DMA                                         |
+-------------------------------+-------------------------------------+
| S3C DMA API(s3c2410_dma_xxx)  | DMA generic API for PL330           |
+-------------------------------+-------------------------------------+
| DMA driver for S3C24XX        | PL330 DMA API driver                |
| PL080 DMA driver for S3C64XX  | (drivers/dma/pl330.c)               |
|                               +-------------------------------------+
| (arch/arm/plat-s3c24xx/dma.c) | Common DMA core driver              |
| (arch/arm/mach-s3c64xx/dma.c) | (arch/arm/common/pl330.c)           |
+-------------------------------+-------------------------------------+

Changes since V1:
- removed s3c-pl330 dma driver
- to support multiple platform
- to support this dma on s5p64x0, s5pc100 and s5pv210 as well as exynos4
- addressed comments from Russell King, Grant Likely, Jassi Brar, Mark Brown and many developrs...Thanks all.

[PATCH V2 01/12] DMA: PL330: Add support runtime PM for PL330 DMAC [PATCH V2 02/12] DMA: PL330: Update PL330 DMA API driver [PATCH V2 03/12] DMA: PL330: Add DMA capabilities [PATCH V2 04/12] ARM: SAMSUNG: Update to use PL330-DMA driver [PATCH V2 05/12] ARM: SAMSUNG: Add common DMA operations [PATCH V2 06/12] ARM: EXYNOS4: Use generic DMA PL330 driver [PATCH V2 07/12] ARM: S5PV210: Use generic DMA PL330 driver [PATCH V2 08/12] ARM: S5PC100: Use generic DMA PL330 driver [PATCH V2 09/12] ARM: S5P64X0: Use generic DMA PL330 driver [PATCH V2 10/12] ARM: SAMSUNG: Remove S3C-PL330-DMA driver [PATCH V2 11/12] spi/s3c64xx: Add support DMA engine API [PATCH V2 12/12] ASoC: Samsung: Update DMA interface

author
#1 lore raw

PATCH v2 1/12 DMA: PL330: Add support runtime PM for PL330 DMAC

From: Boojin Kim <[email protected]>

---
 drivers/dma/pl330.c |   78 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 75 insertions(+), 3 deletions(-)
drivers/dma/pl330.c +75 -3
index 6abe1ec..39e9ffd 100644
@@ -17,6 +17,7 @@
 #include <linux/interrupt.h>
 #include <linux/amba/bus.h>
 #include <linux/amba/pl330.h>
+#include <linux/pm_runtime.h>
 
 #define NR_DEFAULT_DESC	16
 
@@ -83,6 +84,8 @@ struct dma_pl330_dmac {
 
 	/* Peripheral channels connected to this DMAC */
 	struct dma_pl330_chan peripherals[0]; /* keep at end */
+
+	struct clk *clk;
 };
 
 struct dma_pl330_desc {
@@ -688,7 +691,8 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 	pi->mcbufsz = pdat->mcbuf_sz;
 
 	res = &adev->res;
-	request_mem_region(res->start, resource_size(res), "dma-pl330");
+	request_mem_region(res->start,
+		resource_size(res), dev_name(&adev->dev));
 
 	pi->base = ioremap(res->start, resource_size(res));
 	if (!pi->base) {
@@ -696,6 +700,30 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 		goto probe_err1;
 	}
 
+	pdmac->clk = clk_get(&adev->dev, "dma");
+	if (IS_ERR(pdmac->clk)) {
+		dev_err(&adev->dev, "Cannot get operation clock.\n");
+		ret = -EINVAL;
+		goto probe_err1;
+	}
+
+	amba_set_drvdata(adev, pdmac);
+
+#ifdef CONFIG_PM_RUNTIME
+	/* to use the runtime PM helper functions */
+	pm_runtime_enable(&adev->dev);
+
+	/* enable the power domain */
+	if (pm_runtime_get_sync(&adev->dev)) {
+		dev_err(&adev->dev, "failed to get runtime pm\n");
+		ret = -ENODEV;
+		goto probe_err1;
+	}
+#else
+	/* enable dma clk */
+	clk_enable(pdmac->clk);
+#endif
+
 	irq = adev->irq[0];
 	ret = request_irq(irq, pl330_irq_handler, 0,
 			dev_name(&adev->dev), pi);
@@ -763,8 +791,6 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 		goto probe_err4;
 	}
 
-	amba_set_drvdata(adev, pdmac);
-
 	dev_info(&adev->dev,
 		"Loaded driver for PL330 DMAC-%d\n", adev->periphid);
 	dev_info(&adev->dev,
@@ -825,6 +851,13 @@ static int __devexit pl330_remove(struct amba_device *adev)
 	res = &adev->res;
 	release_mem_region(res->start, resource_size(res));
 
+#ifdef CONFIG_PM_RUNTIME
+	pm_runtime_put(&adev->dev);
+	pm_runtime_disable(&adev->dev);
+#else
+	clk_disable(pdmac->clk);
+#endif
+
 	kfree(pdmac);
 
 	return 0;
@@ -838,10 +871,49 @@ static struct amba_id pl330_ids[] = {
 	{ 0, 0 },
 };
 
+#ifdef CONFIG_PM_RUNTIME
+static int pl330_runtime_suspend(struct device *dev)
+{
+	struct dma_pl330_dmac *pdmac = dev_get_drvdata(dev);
+
+	if (!pdmac) {
+		dev_err(dev, "failed to get dmac\n");
+		return -ENODEV;
+	}
+
+	clk_disable(pdmac->clk);
+
+	return 0;
+}
+
+static int pl330_runtime_resume(struct device *dev)
+{
+	struct dma_pl330_dmac *pdmac = dev_get_drvdata(dev);
+
+	if (!pdmac) {
+		dev_err(dev, "failed to get dmac\n");
+		return -ENODEV;
+	}
+
+	clk_enable(pdmac->clk);
+
+	return 0;
+}
+#else
+#define pl330_runtime_suspend	NULL
+#define pl330_runtime_resume	NULL
+#endif /* CONFIG_PM_RUNTIME */
+
+static const struct dev_pm_ops pl330_pm_ops = {
+	.runtime_suspend = pl330_runtime_suspend,
+	.runtime_resume = pl330_runtime_resume,
+};
+
 static struct amba_driver pl330_driver = {
 	.drv = {
 		.owner = THIS_MODULE,
 		.name = "dma-pl330",
+		.pm = &pl330_pm_ops,
 	},
 	.id_table = pl330_ids,
 	.probe = pl330_probe,
Signature · 1 line
1.7.1
#2 lore raw

PATCH v2 1/12 DMA: PL330: Add support runtime PM for PL330 DMAC

drivers/dma/pl330.c pl330_probe(struct amba_device *adev, const struct amba_id *id) · line 695

Quoted 7 lines · Kukjin Kim
drivers/dma/pl330.c +2 -1
@@ -688,7 +691,8 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 	pi->mcbufsz = pdat->mcbuf_sz;
 
 	res = &adev->res;
-	request_mem_region(res->start, resource_size(res), "dma-pl330");
+	request_mem_region(res->start,
+		resource_size(res), dev_name(&adev->dev));

The convention that we've been using is:

10004000-10004fff : mb:aaci
10004000-10004fff : aaci-pl041
10005000-10005fff : mb:mmci
10005000-10005fff : mmci-pl18x
10006000-10006fff : mb:kmi0
10006000-10006fff : kmi-pl050
10007000-10007fff : mb:kmi1
10007000-10007fff : kmi-pl050
10009000-10009fff : mb:uart0
10009000-10009fff : uart-pl011
1000a000-1000afff : mb:uart1
1000a000-1000afff : uart-pl011
1000b000-1000bfff : mb:uart2
1000b000-1000bfff : uart-pl011
1000c000-1000cfff : mb:uart3
1000c000-1000cfff : uart-pl011

The parent resource uses the device name. The child resource is the driver name. That (a) avoids useless duplication of data in /proc/iomem and (b) is more informative when you look at /proc/iomem about what's where.

author
#3 lore raw

PATCH v2 2/12 DMA: PL330: Update PL330 DMA API driver

In reply to Kukjin Kim

From: Boojin Kim <[email protected]>

This patch updates following 3 items.
1. Removes unneccessary code.
2. Add AMBA, PL330 configuration
3. Change the meaning of 'peri_id' variable from PL330 event number to specific dma id by user.

---
 drivers/dma/Kconfig        |    3 ++-
 drivers/dma/pl330.c        |   31 ++++++++++++++++---------------
 include/linux/amba/pl330.h |    2 +-
 3 files changed, 19 insertions(+), 17 deletions(-)
drivers/dma/Kconfig +2 -1
index 25cf327..569cb14 100644
@@ -193,7 +193,8 @@ config ARCH_HAS_ASYNC_TX_FIND_CHANNEL
 config PL330_DMA
 	tristate "DMA API Driver for PL330"
 	select DMA_ENGINE
-	depends on PL330
+	depends on ARM_AMBA
+	select PL330
 	help
 	  Select if your platform has one or more PL330 DMACs.
 	  You need to provide platform specific settings via
drivers/dma/pl330.c +16 -15
index 39e9ffd..9bdda7b 100644
@@ -455,7 +455,7 @@ static struct dma_pl330_desc *pl330_get_desc(struct dma_pl330_chan *pch)
 	async_tx_ack(&desc->txd);
 
 	desc->req.rqtype = peri->rqtype;
-	desc->req.peri = peri->peri_id;
+	desc->req.peri = pch->chan.chan_id;
 
 	dma_async_tx_descriptor_init(&desc->txd, &pch->chan);
 
@@ -577,7 +577,7 @@ pl330_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
 	struct dma_pl330_peri *peri = chan->private;
 	struct scatterlist *sg;
 	unsigned long flags;
-	int i, burst_size;
+	int i;
 	dma_addr_t addr;
 
 	if (unlikely(!pch || !sgl || !sg_len))
@@ -594,7 +594,6 @@ pl330_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
 	}
 
 	addr = peri->fifo_addr;
-	burst_size = peri->burst_sz;
 
 	first = NULL;
 
@@ -642,7 +641,7 @@ pl330_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
 				sg_dma_address(sg), addr, sg_dma_len(sg));
 		}
 
-		desc->rqcfg.brst_size = burst_size;
+		desc->rqcfg.brst_size = peri->burst_sz;
 		desc->rqcfg.brst_len = 1;
 	}
 
@@ -749,17 +748,19 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 		struct dma_pl330_peri *peri = &pdat->peri[i];
 		pch = &pdmac->peripherals[i];
 
-		switch (peri->rqtype) {
-		case MEMTOMEM:
-			dma_cap_set(DMA_MEMCPY, pd->cap_mask);
-			break;
-		case MEMTODEV:
-		case DEVTOMEM:
-			dma_cap_set(DMA_SLAVE, pd->cap_mask);
-			break;
-		default:
-			dev_err(&adev->dev, "DEVTODEV Not Supported\n");
-			continue;
+		if (peri) {
+			switch (peri->rqtype) {
+			case MEMTOMEM:
+				dma_cap_set(DMA_MEMCPY, pd->cap_mask);
+				break;
+			case MEMTODEV:
+			case DEVTOMEM:
+				dma_cap_set(DMA_SLAVE, pd->cap_mask);
+				break;
+			default:
+				dev_err(&adev->dev, "DEVTODEV Not Supported\n");
+				continue;
+			}
 		}
 
 		INIT_LIST_HEAD(&pch->work_list);
include/linux/amba/pl330.h +1 -1
index cbee7de..17b0ada 100644
@@ -19,7 +19,7 @@ struct dma_pl330_peri {
 	 * Peri_Req i/f of the DMAC that is
 	 * peripheral could be reached from.
 	 */
-	u8 peri_id; /* {0, 31} */
+	u8 peri_id; /* specific dma id */
 	enum pl330_reqtype rqtype;
 
 	/* For M->D and D->M Channels */
Signature · 1 line
1.7.1
author
#4 lore raw

PATCH v2 3/12 DMA: PL330: Add DMA capabilities

In reply to Kukjin Kim

From: Boojin Kim <[email protected]>

This patch adds DMA_CYCLIC capability that is used for audio driver and SLAVE_CONFIG capability for transmit between device and memory.

---
 drivers/dma/pl330.c |  187 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 173 insertions(+), 14 deletions(-)
drivers/dma/pl330.c +173 -14
index 9bdda7b..2162ac5 100644
@@ -69,6 +69,9 @@ struct dma_pl330_chan {
 	 * NULL if the channel is available to be acquired.
 	 */
 	void *pl330_chid;
+
+	/* taks for cyclic capability */
+	struct tasklet_struct *cyclic_task;
 };
 
 struct dma_pl330_dmac {
@@ -105,6 +108,7 @@ struct dma_pl330_desc {
 
 	/* The channel which currently holds this desc */
 	struct dma_pl330_chan *pchan;
+	bool cyclic;
 };
 
 static inline struct dma_pl330_chan *
@@ -184,6 +188,60 @@ static inline void fill_queue(struct dma_pl330_chan *pch)
 	}
 }
 
+static void pl330_tasklet_cyclic(unsigned long data)
+{
+	struct dma_pl330_chan *pch = (struct dma_pl330_chan *)data;
+	struct dma_pl330_desc *desc, *_dt;
+	unsigned long flags;
+	LIST_HEAD(list);
+
+	spin_lock_irqsave(&pch->lock, flags);
+
+	/* Pick up ripe tomatoes */
+	list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
+		if ((desc->status == DONE) && desc->cyclic) {
+			dma_async_tx_callback callback;
+
+			list_move_tail(&desc->node, &pch->work_list);
+			pch->completed = desc->txd.cookie;
+
+			desc->status = PREP;
+
+			/* Try to submit a req imm.
+			next to the last completed cookie */
+			fill_queue(pch);
+
+			/* Make sure the PL330 Channel thread is active */
+			pl330_chan_ctrl(pch->pl330_chid, PL330_OP_START);
+
+			callback = desc->txd.callback;
+			if (callback)
+				callback(desc->txd.callback_param);
+
+		}
+
+	spin_unlock_irqrestore(&pch->lock, flags);
+}
+
+static void pl330_cyclic_free(struct dma_pl330_chan *pch)
+{
+	struct dma_pl330_dmac *pdmac = pch->dmac;
+	struct dma_pl330_desc *desc, *_dt;
+	unsigned long flags;
+	LIST_HEAD(list);
+
+	spin_lock_irqsave(&pdmac->pool_lock, flags);
+
+	list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
+	if (desc->cyclic)
+		list_move_tail(&desc->node, &list);
+
+	list_splice_tail_init(&list, &pdmac->desc_pool);
+
+	spin_unlock_irqrestore(&pdmac->pool_lock, flags);
+	pch->cyclic_task = NULL;
+}
+
 static void pl330_tasklet(unsigned long data)
 {
 	struct dma_pl330_chan *pch = (struct dma_pl330_chan *)data;
@@ -227,6 +285,9 @@ static void dma_pl330_rqcb(void *token, enum pl330_op_err err)
 
 	spin_unlock_irqrestore(&pch->lock, flags);
 
+	if (pch->cyclic_task)
+		tasklet_schedule(pch->cyclic_task);
+	else
 	tasklet_schedule(&pch->task);
 }
 
@@ -256,25 +317,58 @@ static int pl330_alloc_chan_resources(struct dma_chan *chan)
 static int pl330_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, unsigned long arg)
 {
 	struct dma_pl330_chan *pch = to_pchan(chan);
-	struct dma_pl330_desc *desc;
+	struct dma_pl330_desc *desc, *_dt;
 	unsigned long flags;
+	struct dma_pl330_dmac *pdmac = pch->dmac;
+	struct dma_slave_config *slave_config;
+	struct dma_pl330_peri *peri;
+	int i;
+	LIST_HEAD(list);
 
-	/* Only supports DMA_TERMINATE_ALL */
-	if (cmd != DMA_TERMINATE_ALL)
-		return -ENXIO;
-
-	spin_lock_irqsave(&pch->lock, flags);
-
-	/* FLUSH the PL330 Channel thread */
-	pl330_chan_ctrl(pch->pl330_chid, PL330_OP_FLUSH);
+	switch (cmd) {
+	case DMA_TERMINATE_ALL:
+		spin_lock_irqsave(&pch->lock, flags);
 
-	/* Mark all desc done */
-	list_for_each_entry(desc, &pch->work_list, node)
-		desc->status = DONE;
+		/* FLUSH the PL330 Channel thread */
+		pl330_chan_ctrl(pch->pl330_chid, PL330_OP_FLUSH);
 
-	spin_unlock_irqrestore(&pch->lock, flags);
+		/* Mark all desc done */
+		list_for_each_entry_safe(desc, _dt, &pch->work_list , node) {
+			desc->status = DONE;
+			pch->completed = desc->txd.cookie;
+			list_move_tail(&desc->node, &list);
+		}
 
-	pl330_tasklet((unsigned long) pch);
+		list_splice_tail_init(&list, &pdmac->desc_pool);
+		spin_unlock_irqrestore(&pch->lock, flags);
+		break;
+	case DMA_SLAVE_CONFIG:
+		slave_config = (struct dma_slave_config *)arg;
+		peri = pch->chan.private;
+
+		if (slave_config->direction == DMA_TO_DEVICE) {
+			if (slave_config->dst_addr)
+				peri->fifo_addr = slave_config->dst_addr;
+			if (slave_config->dst_addr_width) {
+				i = 0;
+				while (slave_config->dst_addr_width != (1 << i))
+					i++;
+				peri->burst_sz = i;
+			}
+		} else if (slave_config->direction == DMA_FROM_DEVICE) {
+			if (slave_config->src_addr)
+				peri->fifo_addr = slave_config->src_addr;
+			if (slave_config->src_addr_width) {
+				i = 0;
+				while (slave_config->src_addr_width != (1 << i))
+					i++;
+				peri->burst_sz = i;
+			}
+		}
+		break;
+	default:
+		return -ENXIO;
+	}
 
 	return 0;
 }
@@ -291,6 +385,9 @@ static void pl330_free_chan_resources(struct dma_chan *chan)
 	pl330_release_channel(pch->pl330_chid);
 	pch->pl330_chid = NULL;
 
+	if (pch->cyclic_task)
+		pl330_cyclic_free(pch);
+
 	spin_unlock_irqrestore(&pch->lock, flags);
 }
 
@@ -522,6 +619,66 @@ static inline int get_burst_len(struct dma_pl330_desc *desc, size_t len)
 	return burst_len;
 }
 
+static struct dma_async_tx_descriptor *pl330_prep_dma_cyclic(
+		struct dma_chan *chan, dma_addr_t dma_addr, size_t len,
+		size_t period_len, enum dma_data_direction direction)
+{
+	struct dma_pl330_desc *desc;
+	struct dma_pl330_chan *pch = to_pchan(chan);
+	struct dma_pl330_peri *peri = chan->private;
+	dma_addr_t dst;
+	dma_addr_t src;
+
+	pch = to_pchan(chan);
+	if (!pch) {
+		dev_err(pch->dmac->pif.dev, "%s:%d Unable to fetch desc\n",
+			__func__, __LINE__);
+		return NULL;
+	}
+
+	desc = pl330_get_desc(pch);
+	if (!desc) {
+		dev_err(pch->dmac->pif.dev, "%s:%d Unable to fetch desc\n",
+			__func__, __LINE__);
+		return NULL;
+	}
+
+	switch (direction) {
+	case DMA_TO_DEVICE:
+		desc->rqcfg.src_inc = 1;
+		desc->rqcfg.dst_inc = 0;
+		src = dma_addr;
+		dst = peri->fifo_addr;
+		break;
+	case DMA_FROM_DEVICE:
+		desc->rqcfg.src_inc = 0;
+		desc->rqcfg.dst_inc = 1;
+		src = peri->fifo_addr;
+		dst = dma_addr;
+		break;
+	default:
+		dev_err(pch->dmac->pif.dev, "%s:%d Invalid dma direction\n",
+		__func__, __LINE__);
+		return NULL;
+	}
+
+	desc->rqcfg.brst_size = peri->burst_sz;
+	desc->rqcfg.brst_len = 1;
+
+	if (!pch->cyclic_task) {
+		pch->cyclic_task =
+			kmalloc(sizeof(struct tasklet_struct), GFP_KERNEL);
+		tasklet_init(pch->cyclic_task,
+			pl330_tasklet_cyclic, (unsigned int)pch);
+	}
+
+	desc->cyclic = true;
+
+	fill_px(&desc->px, dst, src, period_len);
+
+	return &desc->txd;
+}
+
 static struct dma_async_tx_descriptor *
 pl330_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst,
 		dma_addr_t src, size_t len, unsigned long flags)
@@ -756,6 +913,7 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 			case MEMTODEV:
 			case DEVTOMEM:
 				dma_cap_set(DMA_SLAVE, pd->cap_mask);
+				dma_cap_set(DMA_CYCLIC, pd->cap_mask);
 				break;
 			default:
 				dev_err(&adev->dev, "DEVTODEV Not Supported\n");
@@ -781,6 +939,7 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 	pd->device_alloc_chan_resources = pl330_alloc_chan_resources;
 	pd->device_free_chan_resources = pl330_free_chan_resources;
 	pd->device_prep_dma_memcpy = pl330_prep_dma_memcpy;
+	pd->device_prep_dma_cyclic = pl330_prep_dma_cyclic;
 	pd->device_tx_status = pl330_tx_status;
 	pd->device_prep_slave_sg = pl330_prep_slave_sg;
 	pd->device_control = pl330_control;
Signature · 1 line
1.7.1
#5 lore raw

PATCH v2 3/12 DMA: PL330: Add DMA capabilities

Quoted 19 lines · Kukjin Kim
drivers/dma/pl330.c +19 -0
+static void pl330_tasklet_cyclic(unsigned long data)
+{
+	struct dma_pl330_chan *pch = (struct dma_pl330_chan *)data;
+	struct dma_pl330_desc *desc, *_dt;
+	unsigned long flags;
+	LIST_HEAD(list);
+
+	spin_lock_irqsave(&pch->lock, flags);
+
+	/* Pick up ripe tomatoes */
+	list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
+		if ((desc->status == DONE) && desc->cyclic) {
+			dma_async_tx_callback callback;
+
+			list_move_tail(&desc->node, &pch->work_list);
+			pch->completed = desc->txd.cookie;
+
+			desc->status = PREP;
+

drivers/dma/pl330.c static inline void fill_queue(struct dma_pl330_chan *pch) · line 219

Quoted 10 lines
drivers/dma/pl330.c +10 -0
+			/* Try to submit a req imm.
+			next to the last completed cookie */
+			fill_queue(pch);
+
+			/* Make sure the PL330 Channel thread is active */
+			pl330_chan_ctrl(pch->pl330_chid, PL330_OP_START);
+
+			callback = desc->txd.callback;
+			if (callback)
+				callback(desc->txd.callback_param);

How does this work when callbacks are allowed to queue new requests? Aren't you going to deadlock on the spinlock?

I don't see 'list' being used in this function either.

Quoted 10 lines
drivers/dma/pl330.c +10 -0
+
+		}
+
+	spin_unlock_irqrestore(&pch->lock, flags);
+}
+
+static void pl330_cyclic_free(struct dma_pl330_chan *pch)
+{
+	struct dma_pl330_dmac *pdmac = pch->dmac;
+	struct dma_pl330_desc *desc, *_dt;

drivers/dma/pl330.c static inline void fill_queue(struct dma_pl330_chan *pch) · line 239

Quoted 10 lines
drivers/dma/pl330.c +10 -0
+	unsigned long flags;
+	LIST_HEAD(list);
+
+	spin_lock_irqsave(&pdmac->pool_lock, flags);
+
+	list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
+	if (desc->cyclic)
+		list_move_tail(&desc->node, &list);
+
+	list_splice_tail_init(&list, &pdmac->desc_pool);

As you're not using 'list' after this point, would 'list_splice_tail' do here?

Quoted 9 lines
drivers/dma/pl330.c +5 -0
+
+	spin_unlock_irqrestore(&pdmac->pool_lock, flags);
+	pch->cyclic_task = NULL;
+}
+
 static void pl330_tasklet(unsigned long data)
 {
 	struct dma_pl330_chan *pch = (struct dma_pl330_chan *)data;

drivers/dma/pl330.c static void dma_pl330_rqcb(void *token, enum pl330_op_err err) · line 291

Quoted 7 lines
drivers/dma/pl330.c +3 -0
@@ -227,6 +285,9 @@ static void dma_pl330_rqcb(void *token, enum pl330_op_err err)
 
 	spin_unlock_irqrestore(&pch->lock, flags);
 
+	if (pch->cyclic_task)
+		tasklet_schedule(pch->cyclic_task);
+	else
 	tasklet_schedule(&pch->task);

This 'tasklet_schedule' wants to be indented.

Quoted 33 lines
drivers/dma/pl330.c +11 -12
 }
 
@@ -256,25 +317,58 @@ static int pl330_alloc_chan_resources(struct dma_chan *chan)
 static int pl330_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, unsigned long arg)
 {
 	struct dma_pl330_chan *pch = to_pchan(chan);
-	struct dma_pl330_desc *desc;
+	struct dma_pl330_desc *desc, *_dt;
 	unsigned long flags;
+	struct dma_pl330_dmac *pdmac = pch->dmac;
+	struct dma_slave_config *slave_config;
+	struct dma_pl330_peri *peri;
+	int i;
+	LIST_HEAD(list);
 
-	/* Only supports DMA_TERMINATE_ALL */
-	if (cmd != DMA_TERMINATE_ALL)
-		return -ENXIO;
-
-	spin_lock_irqsave(&pch->lock, flags);
-
-	/* FLUSH the PL330 Channel thread */
-	pl330_chan_ctrl(pch->pl330_chid, PL330_OP_FLUSH);
+	switch (cmd) {
+	case DMA_TERMINATE_ALL:
+		spin_lock_irqsave(&pch->lock, flags);
 
-	/* Mark all desc done */
-	list_for_each_entry(desc, &pch->work_list, node)
-		desc->status = DONE;
+		/* FLUSH the PL330 Channel thread */
+		pl330_chan_ctrl(pch->pl330_chid, PL330_OP_FLUSH);
 

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct dma_chan *chan) · line 342

Quoted 10 lines
drivers/dma/pl330.c +7 -2
-	spin_unlock_irqrestore(&pch->lock, flags);
+		/* Mark all desc done */
+		list_for_each_entry_safe(desc, _dt, &pch->work_list , node) {
+			desc->status = DONE;
+			pch->completed = desc->txd.cookie;
+			list_move_tail(&desc->node, &list);
+		}
 
-	pl330_tasklet((unsigned long) pch);
+		list_splice_tail_init(&list, &pdmac->desc_pool);

Again, would list_splice_tail() do here?

Quoted 15 lines
drivers/dma/pl330.c +15 -0
+		spin_unlock_irqrestore(&pch->lock, flags);
+		break;
+	case DMA_SLAVE_CONFIG:
+		slave_config = (struct dma_slave_config *)arg;
+		peri = pch->chan.private;
+
+		if (slave_config->direction == DMA_TO_DEVICE) {
+			if (slave_config->dst_addr)
+				peri->fifo_addr = slave_config->dst_addr;
+			if (slave_config->dst_addr_width) {
+				i = 0;
+				while (slave_config->dst_addr_width != (1 << i))
+					i++;
+				peri->burst_sz = i;
+			}

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct dma_chan *chan) · line 367

Quoted 10 lines
drivers/dma/pl330.c +10 -0
+		} else if (slave_config->direction == DMA_FROM_DEVICE) {
+			if (slave_config->src_addr)
+				peri->fifo_addr = slave_config->src_addr;
+			if (slave_config->src_addr_width) {
+				i = 0;
+				while (slave_config->src_addr_width != (1 << i))
+					i++;
+				peri->burst_sz = i;
+			}
+		}

It would make more sense to store the M2P and P2M address/width/burst size separately, so you don't have to make DMA_SLAVE_CONFIG calls before every transfer.

#6 lore raw

PATCH v2 3/12 DMA: PL330: Add DMA capabilities

This patch adds DMA cyclic capability and Slave configuration. DMA cyclic capability is only used for audio circular buffer.

Quoted 34 lines · Russell king
Quoted 19 lines · Kukjin Kim
drivers/dma/pl330.c +19 -0
+static void pl330_tasklet_cyclic(unsigned long data)
+{
+	struct dma_pl330_chan *pch = (struct dma_pl330_chan *)data;
+	struct dma_pl330_desc *desc, *_dt;
+	unsigned long flags;
+	LIST_HEAD(list);
+
+	spin_lock_irqsave(&pch->lock, flags);
+
+	/* Pick up ripe tomatoes */
+	list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
+		if ((desc->status == DONE) && desc->cyclic) {
+			dma_async_tx_callback callback;
+
+			list_move_tail(&desc->node, &pch->work_list);
+			pch->completed = desc->txd.cookie;
+
+			desc->status = PREP;
+

drivers/dma/pl330.c static inline void fill_queue(struct dma_pl330_chan *pch) · line 219

Quoted 10 lines
drivers/dma/pl330.c +10 -0
+			/* Try to submit a req imm.
+			next to the last completed cookie */
+			fill_queue(pch);
+
+			/* Make sure the PL330 Channel thread is active */
+			pl330_chan_ctrl(pch->pl330_chid, PL330_OP_START);
+
+			callback = desc->txd.callback;
+			if (callback)
+				callback(desc->txd.callback_param);

How does this work when callbacks are allowed to queue new requests? Aren't you going to deadlock on the spinlock?

Quoted 3 lines

I don't see 'list' being used in this function either.

Cyclic capability re-uses the requests that were submitted through tx_submit().
It's possible because Cyclic capability uses same DMA configuration. This pl330_tasklet_cyclic() makes the status of the done request into 'PREP'.
And, re-submit it to PL330.
There are no deadlock because callback function just gathers transmit position.
And Cyclic capability doesn't use 'list' for queue new requests.

Quoted 15 lines
Quoted 15 lines
drivers/dma/pl330.c +15 -0
+
+		}
+
+	spin_unlock_irqrestore(&pch->lock, flags);
+}
+
+static void pl330_cyclic_free(struct dma_pl330_chan *pch)
+{
+	struct dma_pl330_dmac *pdmac = pch->dmac;
+	struct dma_pl330_desc *desc, *_dt;
+	unsigned long flags;
+	LIST_HEAD(list);
+
+	spin_lock_irqsave(&pdmac->pool_lock, flags);
+
Quoted 8 lines

drivers/dma/pl330.c static inline void fill_queue(struct dma_pl330_chan *pch) · line 239

Quoted 5 lines
drivers/dma/pl330.c +5 -0
+	list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
+	if (desc->cyclic)
+		list_move_tail(&desc->node, &list);
+
+	list_splice_tail_init(&list, &pdmac->desc_pool);

As you're not using 'list' after this point, would 'list_splice_tail' do here?

Yes, You're right. the 'list' isn't used after device_free_chan_resources(). So, I release it to desc_pool by using 'list_splice_tail'

Quoted 12 lines

drivers/dma/pl330.c static void dma_pl330_rqcb(void *token, enum

Quoted 10 lines
drivers/dma/pl330.c +5 -0
+
+	spin_unlock_irqrestore(&pdmac->pool_lock, flags);
+	pch->cyclic_task = NULL;
+}
+
 static void pl330_tasklet(unsigned long data)
 {
 	struct dma_pl330_chan *pch = (struct dma_pl330_chan *)data;
@@ -227,6 +285,9 @@ static void dma_pl330_rqcb(void *token, enum

pl330_op_err err)

Quoted 1 line
Quoted 8 lines

drivers/dma/pl330.c static void dma_pl330_rqcb(void *token, enum pl330_op_err err) · line 291

Quoted 6 lines
drivers/dma/pl330.c +3 -0
 	spin_unlock_irqrestore(&pch->lock, flags);
 
+	if (pch->cyclic_task)
+		tasklet_schedule(pch->cyclic_task);
+	else
 	tasklet_schedule(&pch->task);

This 'tasklet_schedule' wants to be indented.

I will address your guide. Thanks

Quoted 45 lines

Review static int pl330_alloc_chan_resources(struct

Quoted 4 lines

}

(quoted diff) +0 -0
@@ -256,25 +317,58 @@ static int pl330_alloc_chan_resources(struct

dma_chan *chan)

Review static int pl330_alloc_chan_resources(struct · line 317

Quoted 1 line
(quoted diff) +0 -0
 static int pl330_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,

unsigned long arg)

Quoted 22 lines
drivers/dma/pl330.c +9 -9
 {
 	struct dma_pl330_chan *pch = to_pchan(chan);
-	struct dma_pl330_desc *desc;
+	struct dma_pl330_desc *desc, *_dt;
 	unsigned long flags;
+	struct dma_pl330_dmac *pdmac = pch->dmac;
+	struct dma_slave_config *slave_config;
+	struct dma_pl330_peri *peri;
+	int i;
+	LIST_HEAD(list);
 
-	/* Only supports DMA_TERMINATE_ALL */
-	if (cmd != DMA_TERMINATE_ALL)
-		return -ENXIO;
-
-	spin_lock_irqsave(&pch->lock, flags);
-
-	/* FLUSH the PL330 Channel thread */
-	pl330_chan_ctrl(pch->pl330_chid, PL330_OP_FLUSH);
+	switch (cmd) {
+	case DMA_TERMINATE_ALL:
+		spin_lock_irqsave(&pch->lock, flags);

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct dma_chan *chan)

Quoted 10 lines
drivers/dma/pl330.c +4 -4
 
-	/* Mark all desc done */
-	list_for_each_entry(desc, &pch->work_list, node)
-		desc->status = DONE;
+		/* FLUSH the PL330 Channel thread */
+		pl330_chan_ctrl(pch->pl330_chid, PL330_OP_FLUSH);
 
-	spin_unlock_irqrestore(&pch->lock, flags);
+		/* Mark all desc done */
+		list_for_each_entry_safe(desc, _dt, &pch->work_list , node)

{

Quoted 5 lines
drivers/dma/pl330.c +4 -0
+			desc->status = DONE;
+			pch->completed = desc->txd.cookie;
+			list_move_tail(&desc->node, &list);
+		}
 
Quoted 4 lines

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct dma_chan *chan) · line 342

Quoted 2 lines
drivers/dma/pl330.c +1 -1
-	pl330_tasklet((unsigned long) pch);
+		list_splice_tail_init(&list, &pdmac->desc_pool);

Again, would list_splice_tail() do here?

This code is for 'flush' operation that releases all of the pre-loaded requests.
I uses 'list_splice_tail_init' for it instead of 'pl330_tasklet' that also calls 'list_splice_tail_init'.

Quoted 13 lines

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct dma_chan *chan)

Quoted 13 lines
drivers/dma/pl330.c +12 -0
+		spin_unlock_irqrestore(&pch->lock, flags);
+		break;
+	case DMA_SLAVE_CONFIG:
+		slave_config = (struct dma_slave_config *)arg;
+		peri = pch->chan.private;
+
+		if (slave_config->direction == DMA_TO_DEVICE) {
+			if (slave_config->dst_addr)
+				peri->fifo_addr = slave_config->dst_addr;
+			if (slave_config->dst_addr_width) {
+				i = 0;
+				while (slave_config->dst_addr_width != (1 <<

i))

Quoted 9 lines

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct dma_chan *chan)

Quoted 9 lines
drivers/dma/pl330.c +9 -0
+					i++;
+				peri->burst_sz = i;
+			}
+		} else if (slave_config->direction == DMA_FROM_DEVICE) {
+			if (slave_config->src_addr)
+				peri->fifo_addr = slave_config->src_addr;
+			if (slave_config->src_addr_width) {
+				i = 0;
+				while (slave_config->src_addr_width != (1 <<

i))

Quoted 8 lines

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct dma_chan *chan) · line 366

Quoted 4 lines
drivers/dma/pl330.c +4 -0
+					i++;
+				peri->burst_sz = i;
+			}
+		}

It would make more sense to store the M2P and P2M address/width/burst size separately, so you don't have to make DMA_SLAVE_CONFIG calls before every transfer.

DMA_SLAVE_CONFIG is called the first time that DMA client driver requests DMA channel.

#7 lore raw

PATCH v2 3/12 DMA: PL330: Add DMA capabilities

In reply to Kukjin Kim

Hello,

2011/7/13 Kukjin Kim <[email protected]>:

Quoted 76 lines

From: Boojin Kim <[email protected]>

This patch adds DMA_CYCLIC capability that is used for audio driver and SLAVE_CONFIG capability for transmit between device and memory.

---
?drivers/dma/pl330.c | ?187 +++++++++++++++++++++++++++++++++++++++++++++++---- ?1 files changed, 173 insertions(+), 14 deletions(-)

drivers/dma/pl330.c +0 -0
index 9bdda7b..2162ac5 100644
@@ -69,6 +69,9 @@ struct dma_pl330_chan {

? ? ? ? * NULL if the channel is available to be acquired. ? ? ? ? */
? ? ? ?void *pl330_chid;
+
+ ? ? ? /* taks for cyclic capability */
+ ? ? ? struct tasklet_struct *cyclic_task;
?};

?struct dma_pl330_dmac {

drivers/dma/pl330.c +0 -0
@@ -105,6 +108,7 @@ struct dma_pl330_desc {
 

? ? ? ?/* The channel which currently holds this desc */ ? ? ? ?struct dma_pl330_chan *pchan;
+ ? ? ? bool cyclic;
?};

?static inline struct dma_pl330_chan *

drivers/dma/pl330.c +37 -0
@@ -184,6 +188,60 @@ static inline void fill_queue(struct dma_pl330_chan *pch)
 ? ? ? ?}
 ?}
 
+static void pl330_tasklet_cyclic(unsigned long data)
+{
+ ? ? ? struct dma_pl330_chan *pch = (struct dma_pl330_chan *)data;
+ ? ? ? struct dma_pl330_desc *desc, *_dt;
+ ? ? ? unsigned long flags;
+ ? ? ? LIST_HEAD(list);
+
+ ? ? ? spin_lock_irqsave(&pch->lock, flags);
+
+ ? ? ? /* Pick up ripe tomatoes */
+ ? ? ? list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
+ ? ? ? ? ? ? ? if ((desc->status == DONE) && desc->cyclic) {
+ ? ? ? ? ? ? ? ? ? ? ? dma_async_tx_callback callback;
+
+ ? ? ? ? ? ? ? ? ? ? ? list_move_tail(&desc->node, &pch->work_list);
+ ? ? ? ? ? ? ? ? ? ? ? pch->completed = desc->txd.cookie;
+
+ ? ? ? ? ? ? ? ? ? ? ? desc->status = PREP;
+
+ ? ? ? ? ? ? ? ? ? ? ? /* Try to submit a req imm.
+ ? ? ? ? ? ? ? ? ? ? ? next to the last completed cookie */
+ ? ? ? ? ? ? ? ? ? ? ? fill_queue(pch);
+
+ ? ? ? ? ? ? ? ? ? ? ? /* Make sure the PL330 Channel thread is active */
+ ? ? ? ? ? ? ? ? ? ? ? pl330_chan_ctrl(pch->pl330_chid, PL330_OP_START);
+
+ ? ? ? ? ? ? ? ? ? ? ? callback = desc->txd.callback;
+ ? ? ? ? ? ? ? ? ? ? ? if (callback)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? callback(desc->txd.callback_param);
+
+ ? ? ? ? ? ? ? }
+
+ ? ? ? spin_unlock_irqrestore(&pch->lock, flags);
+}
+
+static void pl330_cyclic_free(struct dma_pl330_chan *pch)
+{

drivers/dma/pl330.c static inline void fill_queue(struct dma_pl330_chan *pch) · line 237

Quoted 10 lines
drivers/dma/pl330.c +10 -0
+ ? ? ? struct dma_pl330_dmac *pdmac = pch->dmac;
+ ? ? ? struct dma_pl330_desc *desc, *_dt;
+ ? ? ? unsigned long flags;
+ ? ? ? LIST_HEAD(list);
+
+ ? ? ? spin_lock_irqsave(&pdmac->pool_lock, flags);
+
+ ? ? ? list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
+ ? ? ? if (desc->cyclic)
+ ? ? ? ? ? ? ? list_move_tail(&desc->node, &list);

nitpick: indentation will be required after for_each

Quoted 79 lines
drivers/dma/pl330.c +46 -14
+
+ ? ? ? list_splice_tail_init(&list, &pdmac->desc_pool);
+
+ ? ? ? spin_unlock_irqrestore(&pdmac->pool_lock, flags);
+ ? ? ? pch->cyclic_task = NULL;
+}
+
 ?static void pl330_tasklet(unsigned long data)
 ?{
 ? ? ? ?struct dma_pl330_chan *pch = (struct dma_pl330_chan *)data;
@@ -227,6 +285,9 @@ static void dma_pl330_rqcb(void *token, enum pl330_op_err err)
 
 ? ? ? ?spin_unlock_irqrestore(&pch->lock, flags);
 
+ ? ? ? if (pch->cyclic_task)
+ ? ? ? ? ? ? ? tasklet_schedule(pch->cyclic_task);
+ ? ? ? else
 ? ? ? ?tasklet_schedule(&pch->task);
 ?}
 
@@ -256,25 +317,58 @@ static int pl330_alloc_chan_resources(struct dma_chan *chan)
 ?static int pl330_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, unsigned long arg)
 ?{
 ? ? ? ?struct dma_pl330_chan *pch = to_pchan(chan);
- ? ? ? struct dma_pl330_desc *desc;
+ ? ? ? struct dma_pl330_desc *desc, *_dt;
 ? ? ? ?unsigned long flags;
+ ? ? ? struct dma_pl330_dmac *pdmac = pch->dmac;
+ ? ? ? struct dma_slave_config *slave_config;
+ ? ? ? struct dma_pl330_peri *peri;
+ ? ? ? int i;
+ ? ? ? LIST_HEAD(list);
 
- ? ? ? /* Only supports DMA_TERMINATE_ALL */
- ? ? ? if (cmd != DMA_TERMINATE_ALL)
- ? ? ? ? ? ? ? return -ENXIO;
-
- ? ? ? spin_lock_irqsave(&pch->lock, flags);
-
- ? ? ? /* FLUSH the PL330 Channel thread */
- ? ? ? pl330_chan_ctrl(pch->pl330_chid, PL330_OP_FLUSH);
+ ? ? ? switch (cmd) {
+ ? ? ? case DMA_TERMINATE_ALL:
+ ? ? ? ? ? ? ? spin_lock_irqsave(&pch->lock, flags);
 
- ? ? ? /* Mark all desc done */
- ? ? ? list_for_each_entry(desc, &pch->work_list, node)
- ? ? ? ? ? ? ? desc->status = DONE;
+ ? ? ? ? ? ? ? /* FLUSH the PL330 Channel thread */
+ ? ? ? ? ? ? ? pl330_chan_ctrl(pch->pl330_chid, PL330_OP_FLUSH);
 
- ? ? ? spin_unlock_irqrestore(&pch->lock, flags);
+ ? ? ? ? ? ? ? /* Mark all desc done */
+ ? ? ? ? ? ? ? list_for_each_entry_safe(desc, _dt, &pch->work_list , node) {
+ ? ? ? ? ? ? ? ? ? ? ? desc->status = DONE;
+ ? ? ? ? ? ? ? ? ? ? ? pch->completed = desc->txd.cookie;
+ ? ? ? ? ? ? ? ? ? ? ? list_move_tail(&desc->node, &list);
+ ? ? ? ? ? ? ? }
 
- ? ? ? pl330_tasklet((unsigned long) pch);
+ ? ? ? ? ? ? ? list_splice_tail_init(&list, &pdmac->desc_pool);
+ ? ? ? ? ? ? ? spin_unlock_irqrestore(&pch->lock, flags);
+ ? ? ? ? ? ? ? break;
+ ? ? ? case DMA_SLAVE_CONFIG:
+ ? ? ? ? ? ? ? slave_config = (struct dma_slave_config *)arg;
+ ? ? ? ? ? ? ? peri = pch->chan.private;
+
+ ? ? ? ? ? ? ? if (slave_config->direction == DMA_TO_DEVICE) {
+ ? ? ? ? ? ? ? ? ? ? ? if (slave_config->dst_addr)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? peri->fifo_addr = slave_config->dst_addr;
+ ? ? ? ? ? ? ? ? ? ? ? if (slave_config->dst_addr_width) {
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i = 0;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? while (slave_config->dst_addr_width != (1 << i))
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i++;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? peri->burst_sz = i;
+ ? ? ? ? ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? } else if (slave_config->direction == DMA_FROM_DEVICE) {
+ ? ? ? ? ? ? ? ? ? ? ? if (slave_config->src_addr)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? peri->fifo_addr = slave_config->src_addr;

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct dma_chan *chan) · line 370

Quoted 10 lines
drivers/dma/pl330.c +10 -0
+ ? ? ? ? ? ? ? ? ? ? ? if (slave_config->src_addr_width) {
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i = 0;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? while (slave_config->src_addr_width != (1 << i))
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i++;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? peri->burst_sz = i;
+ ? ? ? ? ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? break;
+ ? ? ? default:
+ ? ? ? ? ? ? ? return -ENXIO;

To print error message in the default case will be better.

Quoted 24 lines
drivers/dma/pl330.c +10 -0
+ ? ? ? }
 
 ? ? ? ?return 0;
 ?}
@@ -291,6 +385,9 @@ static void pl330_free_chan_resources(struct dma_chan *chan)
 ? ? ? ?pl330_release_channel(pch->pl330_chid);
 ? ? ? ?pch->pl330_chid = NULL;
 
+ ? ? ? if (pch->cyclic_task)
+ ? ? ? ? ? ? ? pl330_cyclic_free(pch);
+
 ? ? ? ?spin_unlock_irqrestore(&pch->lock, flags);
 ?}
 
@@ -522,6 +619,66 @@ static inline int get_burst_len(struct dma_pl330_desc *desc, size_t len)
 ? ? ? ?return burst_len;
 ?}
 
+static struct dma_async_tx_descriptor *pl330_prep_dma_cyclic(
+ ? ? ? ? ? ? ? struct dma_chan *chan, dma_addr_t dma_addr, size_t len,
+ ? ? ? ? ? ? ? size_t period_len, enum dma_data_direction direction)
+{
+ ? ? ? struct dma_pl330_desc *desc;
+ ? ? ? struct dma_pl330_chan *pch = to_pchan(chan);

drivers/dma/pl330.c static inline int get_burst_len(struct dma_pl330_desc *desc, size_t len) · line 637

Quoted 10 lines
drivers/dma/pl330.c +10 -0
+ ? ? ? struct dma_pl330_peri *peri = chan->private;
+ ? ? ? dma_addr_t dst;
+ ? ? ? dma_addr_t src;
+
+ ? ? ? pch = to_pchan(chan);
+ ? ? ? if (!pch) {
+ ? ? ? ? ? ? ? dev_err(pch->dmac->pif.dev, "%s:%d Unable to fetch desc\n",
+ ? ? ? ? ? ? ? ? ? ? ? __func__, __LINE__);
+ ? ? ? ? ? ? ? return NULL;
+ ? ? ? }

'pch' is already acquired when defined. It's duplicated. dev_err has a incorrect parameter because pch is NULL. Accessing pch->dmac will be failed.

Quoted 71 lines
drivers/dma/pl330.c +44 -0
+
+ ? ? ? desc = pl330_get_desc(pch);
+ ? ? ? if (!desc) {
+ ? ? ? ? ? ? ? dev_err(pch->dmac->pif.dev, "%s:%d Unable to fetch desc\n",
+ ? ? ? ? ? ? ? ? ? ? ? __func__, __LINE__);
+ ? ? ? ? ? ? ? return NULL;
+ ? ? ? }
+
+ ? ? ? switch (direction) {
+ ? ? ? case DMA_TO_DEVICE:
+ ? ? ? ? ? ? ? desc->rqcfg.src_inc = 1;
+ ? ? ? ? ? ? ? desc->rqcfg.dst_inc = 0;
+ ? ? ? ? ? ? ? src = dma_addr;
+ ? ? ? ? ? ? ? dst = peri->fifo_addr;
+ ? ? ? ? ? ? ? break;
+ ? ? ? case DMA_FROM_DEVICE:
+ ? ? ? ? ? ? ? desc->rqcfg.src_inc = 0;
+ ? ? ? ? ? ? ? desc->rqcfg.dst_inc = 1;
+ ? ? ? ? ? ? ? src = peri->fifo_addr;
+ ? ? ? ? ? ? ? dst = dma_addr;
+ ? ? ? ? ? ? ? break;
+ ? ? ? default:
+ ? ? ? ? ? ? ? dev_err(pch->dmac->pif.dev, "%s:%d Invalid dma direction\n",
+ ? ? ? ? ? ? ? __func__, __LINE__);
+ ? ? ? ? ? ? ? return NULL;
+ ? ? ? }
+
+ ? ? ? desc->rqcfg.brst_size = peri->burst_sz;
+ ? ? ? desc->rqcfg.brst_len = 1;
+
+ ? ? ? if (!pch->cyclic_task) {
+ ? ? ? ? ? ? ? pch->cyclic_task =
+ ? ? ? ? ? ? ? ? ? ? ? kmalloc(sizeof(struct tasklet_struct), GFP_KERNEL);
+ ? ? ? ? ? ? ? tasklet_init(pch->cyclic_task,
+ ? ? ? ? ? ? ? ? ? ? ? pl330_tasklet_cyclic, (unsigned int)pch);
+ ? ? ? }
+
+ ? ? ? desc->cyclic = true;
+
+ ? ? ? fill_px(&desc->px, dst, src, period_len);
+
+ ? ? ? return &desc->txd;
+}
+

?static struct dma_async_tx_descriptor * ?pl330_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst, ? ? ? ? ? ? ? ?dma_addr_t src, size_t len, unsigned long flags)

drivers/dma/pl330.c +0 -0
@@ -756,6 +913,7 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)

? ? ? ? ? ? ? ? ? ? ? ?case MEMTODEV:
? ? ? ? ? ? ? ? ? ? ? ?case DEVTOMEM:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?dma_cap_set(DMA_SLAVE, pd->cap_mask);
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dma_cap_set(DMA_CYCLIC, pd->cap_mask); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ? ? ?default:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?dev_err(&adev->dev, "DEVTODEV Not Supported\n");

drivers/dma/pl330.c +1 -1
@@ -781,6 +939,7 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 ? ? ? ?pd->device_alloc_chan_resources = pl330_alloc_chan_resources;
 ? ? ? ?pd->device_free_chan_resources = pl330_free_chan_resources;
 ? ? ? ?pd->device_prep_dma_memcpy = pl330_prep_dma_memcpy;
+ ? ? ? pd->device_prep_dma_cyclic = pl330_prep_dma_cyclic;
 ? ? ? ?pd->device_tx_status = pl330_tx_status;
 ? ? ? ?pd->device_prep_slave_sg = pl330_prep_slave_sg;
 ? ? ? ?pd->device_control = pl330_control;
--

1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to majordomo at vger.kernel.org
More majordomo info at ?http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Best Regards,
Chanho Park
#8 lore raw

PATCH v2 3/12 DMA: PL330: Add DMA capabilities

Quoted 58 lines · Chanho Park

2011/7/13 Kukjin Kim <[email protected]>:

Quoted 11 lines

From: Boojin Kim <[email protected]>

This patch adds DMA_CYCLIC capability that is used for audio driver and SLAVE_CONFIG capability for transmit between device and memory.

---
?drivers/dma/pl330.c | ?187

+++++++++++++++++++++++++++++++++++++++++++++++----

drivers/dma/pl330.c static inline void fill_queue(struct dma_pl330_chan

Quoted 25 lines

?1 files changed, 173 insertions(+), 14 deletions(-)

drivers/dma/pl330.c +0 -0
index 9bdda7b..2162ac5 100644
@@ -69,6 +69,9 @@ struct dma_pl330_chan {

? ? ? ? * NULL if the channel is available to be acquired. ? ? ? ? */
? ? ? ?void *pl330_chid;
+
+ ? ? ? /* taks for cyclic capability */
+ ? ? ? struct tasklet_struct *cyclic_task;
?};

?struct dma_pl330_dmac {

drivers/dma/pl330.c +0 -0
@@ -105,6 +108,7 @@ struct dma_pl330_desc {
 

? ? ? ?/* The channel which currently holds this desc */ ? ? ? ?struct dma_pl330_chan *pchan;
+ ? ? ? bool cyclic;
?};

?static inline struct dma_pl330_chan *

drivers/dma/pl330.c +0 -0
@@ -184,6 +188,60 @@ static inline void fill_queue(struct dma_pl330_chan

*pch)

Quoted 19 lines
drivers/dma/pl330.c +16 -0
 ? ? ? ?}
 ?}
 
+static void pl330_tasklet_cyclic(unsigned long data)
+{
+ ? ? ? struct dma_pl330_chan *pch = (struct dma_pl330_chan *)data;
+ ? ? ? struct dma_pl330_desc *desc, *_dt;
+ ? ? ? unsigned long flags;
+ ? ? ? LIST_HEAD(list);
+
+ ? ? ? spin_lock_irqsave(&pch->lock, flags);
+
+ ? ? ? /* Pick up ripe tomatoes */
+ ? ? ? list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
+ ? ? ? ? ? ? ? if ((desc->status == DONE) && desc->cyclic) {
+ ? ? ? ? ? ? ? ? ? ? ? dma_async_tx_callback callback;
+
+ ? ? ? ? ? ? ? ? ? ? ? list_move_tail(&desc->node, &pch->work_list);
+ ? ? ? ? ? ? ? ? ? ? ? pch->completed = desc->txd.cookie;
Quoted 8 lines

drivers/dma/pl330.c static inline void fill_queue(struct dma_pl330_chan · line 214

Quoted 8 lines
drivers/dma/pl330.c +8 -0
+
+ ? ? ? ? ? ? ? ? ? ? ? desc->status = PREP;
+
+ ? ? ? ? ? ? ? ? ? ? ? /* Try to submit a req imm.
+ ? ? ? ? ? ? ? ? ? ? ? next to the last completed cookie */
+ ? ? ? ? ? ? ? ? ? ? ? fill_queue(pch);
+
+ ? ? ? ? ? ? ? ? ? ? ? /* Make sure the PL330 Channel thread is active

*/

Quoted 1 line

drivers/dma/pl330.c static inline void fill_queue(struct dma_pl330_chan · line 215

Quoted 1 line
drivers/dma/pl330.c +1 -0
+ ? ? ? ? ? ? ? ? ? ? ? pl330_chan_ctrl(pch->pl330_chid,

PL330_OP_START);

Quoted 16 lines
Quoted 16 lines
drivers/dma/pl330.c +16 -0
+
+ ? ? ? ? ? ? ? ? ? ? ? callback = desc->txd.callback;
+ ? ? ? ? ? ? ? ? ? ? ? if (callback)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? callback(desc->txd.callback_param);
+
+ ? ? ? ? ? ? ? }
+
+ ? ? ? spin_unlock_irqrestore(&pch->lock, flags);
+}
+
+static void pl330_cyclic_free(struct dma_pl330_chan *pch)
+{
+ ? ? ? struct dma_pl330_dmac *pdmac = pch->dmac;
+ ? ? ? struct dma_pl330_desc *desc, *_dt;
+ ? ? ? unsigned long flags;
+ ? ? ? LIST_HEAD(list);
Quoted 9 lines

drivers/dma/pl330.c static inline void fill_queue(struct dma_pl330_chan · line 237

Quoted 6 lines
drivers/dma/pl330.c +6 -0
+
+ ? ? ? spin_lock_irqsave(&pdmac->pool_lock, flags);
+
+ ? ? ? list_for_each_entry_safe(desc, _dt, &pch->work_list, node)
+ ? ? ? if (desc->cyclic)
+ ? ? ? ? ? ? ? list_move_tail(&desc->node, &list);

nitpick: indentation will be required after for_each

I will address your comment.

Quoted 54 lines

drivers/dma/pl330.c static void dma_pl330_rqcb(void *token, enum

Quoted 11 lines
drivers/dma/pl330.c +7 -0
+
+ ? ? ? list_splice_tail_init(&list, &pdmac->desc_pool);
+
+ ? ? ? spin_unlock_irqrestore(&pdmac->pool_lock, flags);
+ ? ? ? pch->cyclic_task = NULL;
+}
+
 ?static void pl330_tasklet(unsigned long data)
 ?{
 ? ? ? ?struct dma_pl330_chan *pch = (struct dma_pl330_chan *)data;
@@ -227,6 +285,9 @@ static void dma_pl330_rqcb(void *token, enum

pl330_op_err err)

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct

Quoted 10 lines
drivers/dma/pl330.c +3 -0
 ? ? ? ?spin_unlock_irqrestore(&pch->lock, flags);
 
+ ? ? ? if (pch->cyclic_task)
+ ? ? ? ? ? ? ? tasklet_schedule(pch->cyclic_task);
+ ? ? ? else
 ? ? ? ?tasklet_schedule(&pch->task);
 ?}
 
@@ -256,25 +317,58 @@ static int pl330_alloc_chan_resources(struct

dma_chan *chan)

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct · line 317

Quoted 1 line
drivers/dma/pl330.c +0 -0
 ?static int pl330_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,

unsigned long arg)

Quoted 29 lines
drivers/dma/pl330.c +11 -12
 ?{
 ? ? ? ?struct dma_pl330_chan *pch = to_pchan(chan);
- ? ? ? struct dma_pl330_desc *desc;
+ ? ? ? struct dma_pl330_desc *desc, *_dt;
 ? ? ? ?unsigned long flags;
+ ? ? ? struct dma_pl330_dmac *pdmac = pch->dmac;
+ ? ? ? struct dma_slave_config *slave_config;
+ ? ? ? struct dma_pl330_peri *peri;
+ ? ? ? int i;
+ ? ? ? LIST_HEAD(list);
 
- ? ? ? /* Only supports DMA_TERMINATE_ALL */
- ? ? ? if (cmd != DMA_TERMINATE_ALL)
- ? ? ? ? ? ? ? return -ENXIO;
-
- ? ? ? spin_lock_irqsave(&pch->lock, flags);
-
- ? ? ? /* FLUSH the PL330 Channel thread */
- ? ? ? pl330_chan_ctrl(pch->pl330_chid, PL330_OP_FLUSH);
+ ? ? ? switch (cmd) {
+ ? ? ? case DMA_TERMINATE_ALL:
+ ? ? ? ? ? ? ? spin_lock_irqsave(&pch->lock, flags);
 
- ? ? ? /* Mark all desc done */
- ? ? ? list_for_each_entry(desc, &pch->work_list, node)
- ? ? ? ? ? ? ? desc->status = DONE;
+ ? ? ? ? ? ? ? /* FLUSH the PL330 Channel thread */
+ ? ? ? ? ? ? ? pl330_chan_ctrl(pch->pl330_chid, PL330_OP_FLUSH);
 
Quoted 3 lines

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct · line 336

Quoted 3 lines
drivers/dma/pl330.c +2 -1
- ? ? ? spin_unlock_irqrestore(&pch->lock, flags);
+ ? ? ? ? ? ? ? /* Mark all desc done */
+ ? ? ? ? ? ? ? list_for_each_entry_safe(desc, _dt, &pch->work_list ,

node)

Quoted 17 lines

{

Quoted 16 lines
drivers/dma/pl330.c +14 -1
+ ? ? ? ? ? ? ? ? ? ? ? desc->status = DONE;
+ ? ? ? ? ? ? ? ? ? ? ? pch->completed = desc->txd.cookie;
+ ? ? ? ? ? ? ? ? ? ? ? list_move_tail(&desc->node, &list);
+ ? ? ? ? ? ? ? }
 
- ? ? ? pl330_tasklet((unsigned long) pch);
+ ? ? ? ? ? ? ? list_splice_tail_init(&list, &pdmac->desc_pool);
+ ? ? ? ? ? ? ? spin_unlock_irqrestore(&pch->lock, flags);
+ ? ? ? ? ? ? ? break;
+ ? ? ? case DMA_SLAVE_CONFIG:
+ ? ? ? ? ? ? ? slave_config = (struct dma_slave_config *)arg;
+ ? ? ? ? ? ? ? peri = pch->chan.private;
+
+ ? ? ? ? ? ? ? if (slave_config->direction == DMA_TO_DEVICE) {
+ ? ? ? ? ? ? ? ? ? ? ? if (slave_config->dst_addr)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? peri->fifo_addr =

slave_config->dst_addr;

Quoted 3 lines

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct · line 354

Quoted 3 lines
drivers/dma/pl330.c +3 -0
+ ? ? ? ? ? ? ? ? ? ? ? if (slave_config->dst_addr_width) {
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i = 0;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? while (slave_config->dst_addr_width !=

(1 <<

Quoted 7 lines

i))

Quoted 6 lines
drivers/dma/pl330.c +6 -0
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i++;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? peri->burst_sz = i;
+ ? ? ? ? ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? } else if (slave_config->direction == DMA_FROM_DEVICE) {
+ ? ? ? ? ? ? ? ? ? ? ? if (slave_config->src_addr)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? peri->fifo_addr =

slave_config->src_addr;

Quoted 3 lines

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct · line 363

Quoted 3 lines
drivers/dma/pl330.c +3 -0
+ ? ? ? ? ? ? ? ? ? ? ? if (slave_config->src_addr_width) {
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i = 0;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? while (slave_config->src_addr_width !=

(1 <<

Quoted 11 lines

i))

drivers/dma/pl330.c static int pl330_alloc_chan_resources(struct · line 370

Quoted 7 lines
drivers/dma/pl330.c +7 -0
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i++;
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? peri->burst_sz = i;
+ ? ? ? ? ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? break;
+ ? ? ? default:
+ ? ? ? ? ? ? ? return -ENXIO;

To print error message in the default case will be better.

I will address your comment.

Quoted 20 lines

drivers/dma/pl330.c static void pl330_free_chan_resources(struct

Quoted 5 lines
drivers/dma/pl330.c +1 -0
+ ? ? ? }
 
 ? ? ? ?return 0;
 ?}
@@ -291,6 +385,9 @@ static void pl330_free_chan_resources(struct

dma_chan *chan)

drivers/dma/pl330.c static inline int get_burst_len(struct

Quoted 10 lines
drivers/dma/pl330.c +3 -0
 ? ? ? ?pl330_release_channel(pch->pl330_chid);
 ? ? ? ?pch->pl330_chid = NULL;
 
+ ? ? ? if (pch->cyclic_task)
+ ? ? ? ? ? ? ? pl330_cyclic_free(pch);
+
 ? ? ? ?spin_unlock_irqrestore(&pch->lock, flags);
 ?}
 
@@ -522,6 +619,66 @@ static inline int get_burst_len(struct

dma_pl330_desc *desc, size_t len)

Quoted 3 lines
drivers/dma/pl330.c +0 -0
 ? ? ? ?return burst_len;
 ?}
 
Quoted 13 lines

drivers/dma/pl330.c static inline int get_burst_len(struct · line 634

Quoted 13 lines
drivers/dma/pl330.c +13 -0
+static struct dma_async_tx_descriptor *pl330_prep_dma_cyclic(
+ ? ? ? ? ? ? ? struct dma_chan *chan, dma_addr_t dma_addr, size_t len,
+ ? ? ? ? ? ? ? size_t period_len, enum dma_data_direction direction)
+{
+ ? ? ? struct dma_pl330_desc *desc;
+ ? ? ? struct dma_pl330_chan *pch = to_pchan(chan);
+ ? ? ? struct dma_pl330_peri *peri = chan->private;
+ ? ? ? dma_addr_t dst;
+ ? ? ? dma_addr_t src;
+
+ ? ? ? pch = to_pchan(chan);
+ ? ? ? if (!pch) {
+ ? ? ? ? ? ? ? dev_err(pch->dmac->pif.dev, "%s:%d Unable to fetch

desc\n",

Quoted 7 lines

drivers/dma/pl330.c static inline int get_burst_len(struct · line 637

Quoted 3 lines
drivers/dma/pl330.c +3 -0
+ ? ? ? ? ? ? ? ? ? ? ? __func__, __LINE__);
+ ? ? ? ? ? ? ? return NULL;
+ ? ? ? }

'pch' is already acquired when defined. It's duplicated. dev_err has a incorrect parameter because pch is NULL. Accessing pch->dmac will be failed.

I will address your comment.

Quoted 5 lines

drivers/dma/pl330.c static inline int get_burst_len(struct · line 641

Quoted 5 lines
drivers/dma/pl330.c +4 -0
+
+ ? ? ? desc = pl330_get_desc(pch);
+ ? ? ? if (!desc) {
+ ? ? ? ? ? ? ? dev_err(pch->dmac->pif.dev, "%s:%d Unable to fetch

desc\n",

Quoted 20 lines
Quoted 9 lines
drivers/dma/pl330.c +9 -0
+ ? ? ? ? ? ? ? ? ? ? ? __func__, __LINE__);
+ ? ? ? ? ? ? ? return NULL;
+ ? ? ? }
+
+ ? ? ? switch (direction) {
+ ? ? ? case DMA_TO_DEVICE:
+ ? ? ? ? ? ? ? desc->rqcfg.src_inc = 1;
+ ? ? ? ? ? ? ? desc->rqcfg.dst_inc = 0;
+ ? ? ? ? ? ? ? src = dma_addr;

drivers/dma/pl330.c static inline int get_burst_len(struct · line 660

Quoted 10 lines
drivers/dma/pl330.c +10 -0
+ ? ? ? ? ? ? ? dst = peri->fifo_addr;
+ ? ? ? ? ? ? ? break;
+ ? ? ? case DMA_FROM_DEVICE:
+ ? ? ? ? ? ? ? desc->rqcfg.src_inc = 0;
+ ? ? ? ? ? ? ? desc->rqcfg.dst_inc = 1;
+ ? ? ? ? ? ? ? src = peri->fifo_addr;
+ ? ? ? ? ? ? ? dst = dma_addr;
+ ? ? ? ? ? ? ? break;
+ ? ? ? default:
+ ? ? ? ? ? ? ? dev_err(pch->dmac->pif.dev, "%s:%d Invalid dma

direction\n",

Quoted 10 lines

drivers/dma/pl330.c static inline int get_burst_len(struct · line 670

Quoted 10 lines
drivers/dma/pl330.c +10 -0
+ ? ? ? ? ? ? ? __func__, __LINE__);
+ ? ? ? ? ? ? ? return NULL;
+ ? ? ? }
+
+ ? ? ? desc->rqcfg.brst_size = peri->burst_sz;
+ ? ? ? desc->rqcfg.brst_len = 1;
+
+ ? ? ? if (!pch->cyclic_task) {
+ ? ? ? ? ? ? ? pch->cyclic_task =
+ ? ? ? ? ? ? ? ? ? ? ? kmalloc(sizeof(struct tasklet_struct),

GFP_KERNEL);

Quoted 48 lines

drivers/dma/pl330.c pl330_probe(struct amba_device *adev, const struct

Quoted 15 lines
drivers/dma/pl330.c +11 -0
+ ? ? ? ? ? ? ? tasklet_init(pch->cyclic_task,
+ ? ? ? ? ? ? ? ? ? ? ? pl330_tasklet_cyclic, (unsigned int)pch);
+ ? ? ? }
+
+ ? ? ? desc->cyclic = true;
+
+ ? ? ? fill_px(&desc->px, dst, src, period_len);
+
+ ? ? ? return &desc->txd;
+}
+

?static struct dma_async_tx_descriptor * ?pl330_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst, ? ? ? ? ? ? ? ?dma_addr_t src, size_t len, unsigned long flags)

drivers/dma/pl330.c +0 -0
@@ -756,6 +913,7 @@ pl330_probe(struct amba_device *adev, const struct

amba_id *id)

Quoted 7 lines

? ? ? ? ? ? ? ? ? ? ? ?case MEMTODEV:
? ? ? ? ? ? ? ? ? ? ? ?case DEVTOMEM:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?dma_cap_set(DMA_SLAVE, pd->cap_mask);
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dma_cap_set(DMA_CYCLIC, pd->cap_mask); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ? ? ?default:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?dev_err(&adev->dev, "DEVTODEV Not

Supported\n");

drivers/dma/pl330.c pl330_probe(struct amba_device *adev, const struct

Quoted 1 line
drivers/dma/pl330.c +0 -0
@@ -781,6 +939,7 @@ pl330_probe(struct amba_device *adev, const struct

amba_id *id)

Quoted 10 lines
drivers/dma/pl330.c +1 -1
 ? ? ? ?pd->device_alloc_chan_resources = pl330_alloc_chan_resources;
 ? ? ? ?pd->device_free_chan_resources = pl330_free_chan_resources;
 ? ? ? ?pd->device_prep_dma_memcpy = pl330_prep_dma_memcpy;
+ ? ? ? pd->device_prep_dma_cyclic = pl330_prep_dma_cyclic;
 ? ? ? ?pd->device_tx_status = pl330_tx_status;
 ? ? ? ?pd->device_prep_slave_sg = pl330_prep_slave_sg;
 ? ? ? ?pd->device_control = pl330_control;
--

1.7.1

Quoted 2 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-

soc" in

Quoted 3 lines

the body of a message to majordomo at vger.kernel.org More majordomo info at ?http://vger.kernel.org/majordomo-info.html

--
Best Regards,
Chanho Park

author
#9 lore raw

PATCH v2 4/12 ARM: SAMSUNG: Update to use PL330-DMA driver

In reply to Kukjin Kim

From: Boojin Kim <[email protected]>

This patch adds to support PL330-DMA driver on DMADEVICE for S5P SoCs.

---
 arch/arm/mach-exynos4/include/mach/dma.h           |    4 +-
 arch/arm/mach-s5p64x0/include/mach/dma.h           |    2 +-
 arch/arm/mach-s5pc100/include/mach/dma.h           |    2 +-
 arch/arm/mach-s5pv210/include/mach/dma.h           |    2 +-
 arch/arm/plat-samsung/Kconfig                      |    8 +++++++
 .../include/plat/{s3c-dma-pl330.h => dma-pl330.h}  |   21 +++++++++++++------
 .../plat-samsung/include/plat/s3c-pl330-pdata.h    |    2 +-
 7 files changed, 28 insertions(+), 13 deletions(-)
 rename arch/arm/plat-samsung/include/plat/{s3c-dma-pl330.h => dma-pl330.h} (84%)
arch/arm/mach-exynos4/include/mach/dma.h +2 -2
index 81209eb..201842a 100644
@@ -20,7 +20,7 @@
 #ifndef __MACH_DMA_H
 #define __MACH_DMA_H
 
-/* This platform uses the common S3C DMA API driver for PL330 */
-#include <plat/s3c-dma-pl330.h>
+/* This platform uses the common DMA API driver for PL330 */
+#include <plat/dma-pl330.h>
 
 #endif /* __MACH_DMA_H */
arch/arm/mach-s5p64x0/include/mach/dma.h +1 -1
index 81209eb..1beae2c 100644
@@ -21,6 +21,6 @@
 #define __MACH_DMA_H
 
 /* This platform uses the common S3C DMA API driver for PL330 */
-#include <plat/s3c-dma-pl330.h>
+#include <plat/dma-pl330.h>
 
 #endif /* __MACH_DMA_H */
arch/arm/mach-s5pc100/include/mach/dma.h +1 -1
index 81209eb..1beae2c 100644
@@ -21,6 +21,6 @@
 #define __MACH_DMA_H
 
 /* This platform uses the common S3C DMA API driver for PL330 */
-#include <plat/s3c-dma-pl330.h>
+#include <plat/dma-pl330.h>
 
 #endif /* __MACH_DMA_H */
arch/arm/mach-s5pv210/include/mach/dma.h +1 -1
index 81209eb..1beae2c 100644
@@ -21,6 +21,6 @@
 #define __MACH_DMA_H
 
 /* This platform uses the common S3C DMA API driver for PL330 */
-#include <plat/s3c-dma-pl330.h>
+#include <plat/dma-pl330.h>
 
 #endif /* __MACH_DMA_H */
arch/arm/plat-samsung/Kconfig +8 -0
index 4d79519..cb170a6 100644
@@ -300,6 +300,14 @@ config S3C_PL330_DMA
 	help
 	  S3C DMA API Driver for PL330 DMAC.
 
+config DMADEV_PL330
+	bool
+	select DMADEVICES
+	select PL330_DMA
+	select ARM_AMBA
+	help
+	  Use DMA device engine for PL330 DMAC.
+
 comment "Power management"
 
 config SAMSUNG_PM_DEBUG
arch/arm/plat-samsung/include/plat/dma-pl330.h renamed from arch/arm/plat-samsung/include/plat/s3c-dma-pl330.h +14 -7
similarity index 84%
rename from arch/arm/plat-samsung/include/plat/s3c-dma-pl330.h
rename to arch/arm/plat-samsung/include/plat/dma-pl330.h
index 8107442..c402719 100644
@@ -8,19 +8,18 @@
  * (at your option) any later version.
  */
 
-#ifndef	__S3C_DMA_PL330_H_
-#define	__S3C_DMA_PL330_H_
-
-#define S3C2410_DMAF_AUTOSTART		(1 << 0)
-#define S3C2410_DMAF_CIRCULAR		(1 << 1)
+#ifndef __DMA_PL330_H_
+#define __DMA_PL330_H_ __FILE__
 
+#define S3C2410_DMAF_AUTOSTART	(1 << 0)
+#define S3C2410_DMAF_CIRCULAR	(1 << 1)
 /*
  * PL330 can assign any channel to communicate with
  * any of the peripherals attched to the DMAC.
  * For the sake of consistency across client drivers,
  * We keep the channel names unchanged and only add
  * missing peripherals are added.
- * Order is not important since S3C PL330 API driver
+ * Order is not important since DMA PL330 API driver
  * use these just as IDs.
  */
 enum dma_ch {
@@ -84,6 +83,14 @@ enum dma_ch {
 	DMACH_SLIMBUS4_TX,
 	DMACH_SLIMBUS5_RX,
 	DMACH_SLIMBUS5_TX,
+	DMACH_MTOM_0,
+	DMACH_MTOM_1,
+	DMACH_MTOM_2,
+	DMACH_MTOM_3,
+	DMACH_MTOM_4,
+	DMACH_MTOM_5,
+	DMACH_MTOM_6,
+	DMACH_MTOM_7,
 	/* END Marker, also used to denote a reserved channel */
 	DMACH_MAX,
 };
@@ -95,4 +102,4 @@ static inline bool s3c_dma_has_circular(void)
 
 #include <plat/dma.h>
 
-#endif	/* __S3C_DMA_PL330_H_ */
+#endif	/* __DMA_PL330_H_ */
arch/arm/plat-samsung/include/plat/s3c-pl330-pdata.h +1 -1
index bf5e2a9..64fdf66 100644
@@ -12,7 +12,7 @@
 #ifndef __S3C_PL330_PDATA_H
 #define __S3C_PL330_PDATA_H
 
-#include <plat/s3c-dma-pl330.h>
+#include <plat/dma-pl330.h>
 
 /*
  * Every PL330 DMAC has max 32 peripheral interfaces,
Signature · 1 line
1.7.1
author
#10 lore raw

PATCH v2 5/12 ARM: SAMSUNG: Add common DMA operations

In reply to Kukjin Kim

From: Boojin Kim <[email protected]>

This patch adds common DMA operations which are used for Samsung DMA drivers. Currently there are two types of DMA driver for Samsung SoCs. The one is S3C-DMA for S3C SoCs and the other is PL330-DMA for S5P SoCs. This patch provides funcion pointers for common DMA operations to DMA client driver like SPI and Audio. It makes DMA client drivers support multi-platform.
In addition, this common DMA operations implement the shared actions that are needed for DMA client driver. For example shared actions are filter() function for dma_request_channel() and parameter passing for device_prep_slave_sg().

---
 arch/arm/mach-s3c2410/include/mach/dma.h       |    3 +-
 arch/arm/plat-samsung/Makefile                 |    6 +-
 arch/arm/plat-samsung/dma-ops.c                |  131 +++++++++++++++++++++++
 arch/arm/plat-samsung/include/plat/dma-ops.h   |   47 +++++++++
 arch/arm/plat-samsung/include/plat/dma-pl330.h |    3 +
 arch/arm/plat-samsung/include/plat/dma.h       |    2 +-
 arch/arm/plat-samsung/s3c-dma-ops.c            |  132 ++++++++++++++++++++++++
 7 files changed, 320 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/plat-samsung/dma-ops.c
 create mode 100644 arch/arm/plat-samsung/include/plat/dma-ops.h
 create mode 100644 arch/arm/plat-samsung/s3c-dma-ops.c
arch/arm/mach-s3c2410/include/mach/dma.h +2 -1
index b2b2a5b..71a662d 100644
@@ -13,7 +13,6 @@
 #ifndef __ASM_ARCH_DMA_H
 #define __ASM_ARCH_DMA_H __FILE__
 
-#include <plat/dma.h>
 #include <linux/sysdev.h>
 
 #define MAX_DMA_TRANSFER_SIZE   0x100000 /* Data Unit is half word  */
@@ -51,6 +50,8 @@ enum dma_ch {
 	DMACH_MAX,		/* the end entry */
 };
 
+#include <plat/dma.h>
+
 #define DMACH_LOW_LEVEL	(1<<28)	/* use this to specifiy hardware ch no */
 
 /* we have 4 dma channels */
arch/arm/plat-samsung/Makefile +4 -2
index 53eb15b..9ecf2aa 100644
@@ -62,9 +62,11 @@ obj-$(CONFIG_SAMSUNG_DEV_PWM)	+= dev-pwm.o
 
 # DMA support
 
-obj-$(CONFIG_S3C_DMA)		+= dma.o
+obj-$(CONFIG_S3C_DMA)		+= dma.o s3c-dma-ops.o
 
-obj-$(CONFIG_S3C_PL330_DMA)	+= s3c-pl330.o
+obj-$(CONFIG_DMADEV_PL330)	+= dma-ops.o
+
+obj-$(CONFIG_S3C_PL330_DMA)	+= s3c-pl330.o s3c-dma-ops.o
 
 # PM support
 
arch/arm/plat-samsung/dma-ops.c new file +131 -0

131 lines not on this page · raw message

arch/arm/plat-samsung/include/plat/dma-ops.h new file +47 -0

47 lines not on this page · raw message

arch/arm/plat-samsung/include/plat/dma-pl330.h +3 -0
index c402719..be84bec 100644
@@ -1,4 +1,7 @@
 /*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com
+ *
  * Copyright (C) 2010 Samsung Electronics Co. Ltd.
  *	Jaswinder Singh <[email protected]>
  *
arch/arm/plat-samsung/include/plat/dma.h +1 -1
index 2e8f8c6..90da162 100644
@@ -124,4 +124,4 @@ extern int s3c2410_dma_getposition(unsigned int channel,
 extern int s3c2410_dma_set_opfn(unsigned int, s3c2410_dma_opfn_t rtn);
 extern int s3c2410_dma_set_buffdone_fn(unsigned int, s3c2410_dma_cbfn_t rtn);
 
-
+#include <plat/dma-ops.h>
arch/arm/plat-samsung/s3c-dma-ops.c new file +132 -0

132 lines not on this page · raw message

Signature · 1 line
1.7.1
#11 lore raw

PATCH v2 5/12 ARM: SAMSUNG: Add common DMA operations

Quoted 85 lines · Kukjin Kim

From: Boojin Kim <[email protected]>

This patch adds common DMA operations which are used for Samsung DMA drivers. Currently there are two types of DMA driver for Samsung SoCs. The one is S3C-DMA for S3C SoCs and the other is PL330-DMA for S5P SoCs. This patch provides funcion pointers for common DMA operations to DMA client driver like SPI and Audio. It makes DMA client drivers support multi-platform.
In addition, this common DMA operations implement the shared actions that are needed for DMA client driver. For example shared actions are filter() function for dma_request_channel() and parameter passing for device_prep_slave_sg().

---
 arch/arm/mach-s3c2410/include/mach/dma.h       |    3 +-
 arch/arm/plat-samsung/Makefile                 |    6 +-
 arch/arm/plat-samsung/dma-ops.c                |  131 +++++++++++++++++++++++
 arch/arm/plat-samsung/include/plat/dma-ops.h   |   47 +++++++++
 arch/arm/plat-samsung/include/plat/dma-pl330.h |    3 +
 arch/arm/plat-samsung/include/plat/dma.h       |    2 +-
 arch/arm/plat-samsung/s3c-dma-ops.c            |  132 ++++++++++++++++++++++++
 7 files changed, 320 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/plat-samsung/dma-ops.c
 create mode 100644 arch/arm/plat-samsung/include/plat/dma-ops.h
 create mode 100644 arch/arm/plat-samsung/s3c-dma-ops.c
arch/arm/mach-s3c2410/include/mach/dma.h +2 -1
index b2b2a5b..71a662d 100644
@@ -13,7 +13,6 @@
 #ifndef __ASM_ARCH_DMA_H
 #define __ASM_ARCH_DMA_H __FILE__
 
-#include <plat/dma.h>
 #include <linux/sysdev.h>
 
 #define MAX_DMA_TRANSFER_SIZE   0x100000 /* Data Unit is half word  */
@@ -51,6 +50,8 @@ enum dma_ch {
 	DMACH_MAX,		/* the end entry */
 };
 
+#include <plat/dma.h>
+
 #define DMACH_LOW_LEVEL	(1<<28)	/* use this to specifiy hardware ch no */
 
 /* we have 4 dma channels */
arch/arm/plat-samsung/Makefile +4 -2
index 53eb15b..9ecf2aa 100644
@@ -62,9 +62,11 @@ obj-$(CONFIG_SAMSUNG_DEV_PWM)	+= dev-pwm.o
 
 # DMA support
 
-obj-$(CONFIG_S3C_DMA)		+= dma.o
+obj-$(CONFIG_S3C_DMA)		+= dma.o s3c-dma-ops.o
 
-obj-$(CONFIG_S3C_PL330_DMA)	+= s3c-pl330.o
+obj-$(CONFIG_DMADEV_PL330)	+= dma-ops.o
+
+obj-$(CONFIG_S3C_PL330_DMA)	+= s3c-pl330.o s3c-dma-ops.o
 
 # PM support
 
arch/arm/plat-samsung/dma-ops.c new file +12 -0
new file mode 100644
index 0000000..94a9d33
@@ -0,0 +1,131 @@
+/* linux/arch/arm/plat-samsung/dma-ops.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com
+ *
+ * Samsung DMA Operations
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+

arch/arm/plat-samsung/dma-ops.c line 22

Quoted 10 lines
arch/arm/plat-samsung/dma-ops.c new file +10 -0
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/dmaengine.h>
+#include <linux/amba/pl330.h>
+
+#include <mach/dma.h>
+
+static bool filter(struct dma_chan *chan, void *param)
+{
+	struct dma_pl330_peri *peri = (struct dma_pl330_peri *)chan->private;

Is this code pl330 specific? If so, 'pl330' should probably be referenced in the function name.

Quoted 93 lines
arch/arm/plat-samsung/dma-ops.c new file +93 -0
+	unsigned dma_ch = (unsigned)param;
+
+	if (peri->peri_id != dma_ch)
+		return false;
+
+	return true;
+}
+
+static unsigned dma_request(enum dma_ch dma_ch, struct samsung_dma_info *info)
+{
+	struct dma_chan *chan;
+	dma_cap_mask_t mask;
+	struct dma_slave_config slave_config;
+
+	dma_cap_zero(mask);
+	dma_cap_set(info->cap, mask);
+
+	chan = dma_request_channel(mask, filter, (void *)dma_ch);
+
+	if (info->direction == DMA_FROM_DEVICE) {
+		memset(&slave_config, 0, sizeof(struct dma_slave_config));
+		slave_config.direction = info->direction;
+		slave_config.src_addr = info->fifo;
+		slave_config.src_addr_width = info->width;
+		dmaengine_slave_config(chan, &slave_config);
+	} else if (info->direction == DMA_TO_DEVICE) {
+		memset(&slave_config, 0, sizeof(struct dma_slave_config));
+		slave_config.direction = info->direction;
+		slave_config.dst_addr = info->fifo;
+		slave_config.dst_addr_width = info->width;
+		dmaengine_slave_config(chan, &slave_config);
+	}
+
+	return (unsigned)chan;
+}
+
+static int dma_release(unsigned ch, struct s3c2410_dma_client *client)
+{
+	dma_release_channel((struct dma_chan *)ch);
+
+	return 0;
+}
+
+static int dma_prepare(unsigned ch, struct samsung_dma_prep_info *info)
+{
+	struct scatterlist sg;
+	struct dma_chan *chan = (struct dma_chan *)ch;
+	struct dma_async_tx_descriptor *desc;
+
+	switch (info->cap) {
+	case DMA_SLAVE:
+		sg_init_table(&sg, 1);
+		sg_dma_len(&sg) = info->len;
+		sg_set_page(&sg, pfn_to_page(PFN_DOWN(info->buf)),
+			    info->len, offset_in_page(info->buf));
+		sg_dma_address(&sg) = info->buf;
+
+		desc = chan->device->device_prep_slave_sg(chan,
+			&sg, 1, info->direction, DMA_PREP_INTERRUPT);
+		break;
+	case DMA_CYCLIC:
+		desc = chan->device->device_prep_dma_cyclic(chan,
+			info->buf, info->len, info->period, info->direction);
+		break;
+	default:
+		dev_err(&chan->dev->device, "unsupported format\n");
+		return -EFAULT;
+	}
+
+	if (!desc) {
+		dev_err(&chan->dev->device, "cannot prepare cyclic dma\n");
+		return -EFAULT;
+	}
+
+	desc->callback = info->fp;
+	desc->callback_param = info->fp_param;
+
+	dmaengine_submit((struct dma_async_tx_descriptor *)desc);
+
+	return 0;
+}
+
+static inline int dma_trigger(unsigned ch)
+{
+	dma_async_issue_pending((struct dma_chan *)ch);
+
+	return 0;
+}
+
+static inline int dma_flush(unsigned ch)
+{
+	return dmaengine_terminate_all((struct dma_chan *)ch);
+}

arch/arm/plat-samsung/dma-ops.c line 125

Quoted 10 lines
arch/arm/plat-samsung/dma-ops.c new file +10 -0
+
+static struct samsung_dma_ops dmaeng_ops = {
+	.request	= dma_request,
+	.release	= dma_release,
+	.prepare	= dma_prepare,
+	.trigger	= dma_trigger,
+	.started	= NULL,
+	.flush		= dma_flush,
+	.stop		= dma_flush,
+};

Even though these function are all local statics, you should use a samsung prefix to avoid namespace collisions. So, they should be named something like: samsung_dmaeng_ops, samsung_dmaeng_request(), samsung_dmaeng_release(), etc. The ops structure and the functions should have the same prefix.

arch/arm/plat-samsung/dma-ops.c line 131

Quoted 6 lines
arch/arm/plat-samsung/dma-ops.c new file +6 -0
+
+void *samsung_dma_get_ops(void)
+{
+	return (void *)&dmaeng_ops;
+}
+EXPORT_SYMBOL(samsung_dma_get_ops);

If all that is needed is a reference to the dma ops, then you could simply export samsung_dmaeng_ops() without a separate function.

Quoted 58 lines
arch/arm/plat-samsung/include/plat/dma-ops.h new file +47 -0
new file mode 100644
index 0000000..eea4130
@@ -0,0 +1,47 @@
+/* arch/arm/plat-samsung/include/plat/dma-ops.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com
+ *
+ * Samsung DMA support
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/dmaengine.h>
+
+struct samsung_dma_prep_info {
+	enum dma_transaction_type cap;
+	enum dma_data_direction direction;
+	unsigned buf;
+	unsigned long period;
+	unsigned long len;
+	void (*fp)(void *data);
+	void *fp_param;
+};
+
+struct samsung_dma_info {
+	enum dma_transaction_type cap;
+	enum dma_data_direction direction;
+	enum dma_slave_buswidth width;
+	unsigned fifo;
+	struct s3c2410_dma_client *client;
+};
+
+struct samsung_dma_ops {
+	unsigned (*request)(enum dma_ch ch, struct samsung_dma_info *info);
+	int (*release)(unsigned ch, struct s3c2410_dma_client *client);
+	int (*prepare)(unsigned ch, struct samsung_dma_prep_info *info);
+	int (*trigger)(unsigned ch);
+	int (*started)(unsigned ch);
+	int (*flush)(unsigned ch);
+	int (*stop)(unsigned ch);
+};
+
+/*
+ * samsung_dma_get_ops
+ * get the set of dma operations
+ */
+extern void *samsung_dma_get_ops(void);
arch/arm/plat-samsung/include/plat/dma-pl330.h +0 -0
index c402719..be84bec 100644

arch/arm/plat-samsung/include/plat/dma-pl330.h line 7

Quoted 7 lines
arch/arm/plat-samsung/include/plat/dma-pl330.h +3 -0
@@ -1,4 +1,7 @@
 /*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com
+ *
  * Copyright (C) 2010 Samsung Electronics Co. Ltd.
  *	Jaswinder Singh <[email protected]>
  *

Heh, this patch doesn't make any changes to this file, and samsung already has a copyright notice on it anyway. You should probably drop this hunk.

arch/arm/plat-samsung/include/plat/dma.h extern int s3c2410_dma_getposition(unsigned int channel, · line 127

Quoted 9 lines
arch/arm/plat-samsung/include/plat/dma.h +0 -1
index 2e8f8c6..90da162 100644
@@ -124,4 +124,4 @@ extern int s3c2410_dma_getposition(unsigned int channel,
 extern int s3c2410_dma_set_opfn(unsigned int, s3c2410_dma_opfn_t rtn);
 extern int s3c2410_dma_set_buffdone_fn(unsigned int, s3c2410_dma_cbfn_t rtn);
 
-

nitpick: Unrelated whitespace change. One blank line of whitespace is sufficient anyway.

Quoted 17 lines
arch/arm/plat-samsung/include/plat/dma.h +1 -0
+#include <plat/dma-ops.h>
arch/arm/plat-samsung/s3c-dma-ops.c new file +10 -0
new file mode 100644
index 0000000..17b1be0
@@ -0,0 +1,132 @@
+/* linux/arch/arm/plat-samsung/s3c-dma-ops.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com
+ *
+ * Samsung S3C-DMA Operations
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

arch/arm/plat-samsung/s3c-dma-ops.c line 20

Quoted 10 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +10 -0
+*/
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+
+#include <mach/dma.h>
+
+struct cb_data {

struct s3c2410_cb_data {

arch/arm/plat-samsung/s3c-dma-ops.c line 32

Quoted 12 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +12 -0
+	void (*fp) (void *);
+	void *fp_param;
+	unsigned ch;
+	struct list_head node;
+};
+
+static LIST_HEAD(dma_list);
+
+static void dma_cb(struct s3c2410_dma_chan *channel,
+		   void *param, int size, enum s3c2410_dma_buffresult res)
+{
+	struct cb_data *data = (struct cb_data *)param;

param is a void*. The (struct cb_data*) cast is not needed.

arch/arm/plat-samsung/s3c-dma-ops.c line 37

Quoted 5 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +5 -0
+
+	data->fp(data->fp_param);
+}
+
+static unsigned dma_request(enum dma_ch dma_ch, struct samsung_dma_info *info)

These functions should *definitely* be named differently from the dma_* ops in the other file so that you can differentiate between them, and to make them grep-friendly. This goes for *all* file-scope symbols.

arch/arm/plat-samsung/s3c-dma-ops.c line 46

Quoted 9 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +9 -0
+{
+	struct cb_data *data;
+
+	if (s3c2410_dma_request(dma_ch, info->client, NULL) < 0) {
+		s3c2410_dma_free(dma_ch, info->client);
+		return 0;
+	}
+
+	data = kmalloc(sizeof(struct cb_data), GFP_KERNEL);

kzalloc()

arch/arm/plat-samsung/s3c-dma-ops.c line 47

Quoted 1 line
arch/arm/plat-samsung/s3c-dma-ops.c new file +1 -0
+	data->fp = NULL;

Drop this line after converting to kzalloc()

arch/arm/plat-samsung/s3c-dma-ops.c line 48

Quoted 1 line
arch/arm/plat-samsung/s3c-dma-ops.c new file +1 -0
+	data->ch = (unsigned)dma_ch;

Is the cast necessary?

Quoted 6 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +6 -0
+	list_add_tail(&data->node, &dma_list);
+
+	if (info->direction == DMA_FROM_DEVICE)
+		s3c2410_dma_devconfig(dma_ch, S3C2410_DMASRC_HW, info->fifo);
+	else
+		s3c2410_dma_devconfig(dma_ch, S3C2410_DMASRC_MEM, info->fifo);
#12 lore raw

PATCH v2 5/12 ARM: SAMSUNG: Add common DMA operations

Quoted 98 lines · Grant Likely
Quoted 13 lines · Kukjin Kim

From: Boojin Kim <[email protected]>

This patch adds common DMA operations which are used for Samsung DMA drivers. Currently there are two types of DMA driver for Samsung SoCs. The one is S3C-DMA for S3C SoCs and the other is PL330-DMA for S5P SoCs. This patch provides funcion pointers for common DMA operations to DMA client driver like SPI and Audio. It makes DMA client drivers support multi-platform.
In addition, this common DMA operations implement the shared actions that are needed for DMA client driver. For example shared actions are filter() function for dma_request_channel() and parameter passing for device_prep_slave_sg().

Quoted 6 lines
---
 arch/arm/mach-s3c2410/include/mach/dma.h       |    3 +-
 arch/arm/plat-samsung/Makefile                 |    6 +-
 arch/arm/plat-samsung/dma-ops.c                |  131

+++++++++++++++++++++++

Quoted 4 lines
 arch/arm/plat-samsung/include/plat/dma-ops.h   |   47 +++++++++
 arch/arm/plat-samsung/include/plat/dma-pl330.h |    3 +
 arch/arm/plat-samsung/include/plat/dma.h       |    2 +-
 arch/arm/plat-samsung/s3c-dma-ops.c            |  132

++++++++++++++++++++++++

arch/arm/mach-

Quoted 6 lines
 7 files changed, 320 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/plat-samsung/dma-ops.c
 create mode 100644 arch/arm/plat-samsung/include/plat/dma-ops.h
 create mode 100644 arch/arm/plat-samsung/s3c-dma-ops.c
arch/arm/mach- renamed from arch/arm/mach-s3c2410/include/mach/dma.h +0 -0

s3c2410/include/mach/dma.h

Quoted 12 lines

index b2b2a5b..71a662d 100644

arch/arm/mach-s3c2410/include/mach/dma.h +0 -1
@@ -13,7 +13,6 @@
 #ifndef __ASM_ARCH_DMA_H
 #define __ASM_ARCH_DMA_H __FILE__
 
-#include <plat/dma.h>
 #include <linux/sysdev.h>
 
 #define MAX_DMA_TRANSFER_SIZE   0x100000 /* Data Unit is half word  */

arch/arm/mach-s3c2410/include/mach/dma.h enum dma_ch { · line 55

Quoted 6 lines
arch/arm/mach-s3c2410/include/mach/dma.h +2 -0
@@ -51,6 +50,8 @@ enum dma_ch {
 	DMACH_MAX,		/* the end entry */
 };
 
+#include <plat/dma.h>
+
 #define DMACH_LOW_LEVEL	(1<<28)	/* use this to specifiy hardware

ch no */

arch/arm/plat-

Quoted 3 lines
arch/arm/mach-s3c2410/include/mach/dma.h +0 -0
 /* we have 4 dma channels */
arch/arm/plat- renamed from arch/arm/plat-samsung/Makefile +0 -0

samsung/Makefile

arch/arm/plat-

Quoted 18 lines

index 53eb15b..9ecf2aa 100644

arch/arm/plat-samsung/Makefile +4 -2
@@ -62,9 +62,11 @@ obj-$(CONFIG_SAMSUNG_DEV_PWM)	+= dev-pwm.o
 
 # DMA support
 
-obj-$(CONFIG_S3C_DMA)		+= dma.o
+obj-$(CONFIG_S3C_DMA)		+= dma.o s3c-dma-ops.o
 
-obj-$(CONFIG_S3C_PL330_DMA)	+= s3c-pl330.o
+obj-$(CONFIG_DMADEV_PL330)	+= dma-ops.o
+
+obj-$(CONFIG_S3C_PL330_DMA)	+= s3c-pl330.o s3c-dma-ops.o
 
 # PM support
 
arch/arm/plat- renamed from arch/arm/plat-samsung/dma-ops.c +0 -0

samsung/dma-ops.c

Quoted 23 lines

new file mode 100644
index 0000000..94a9d33

arch/arm/plat-samsung/dma-ops.c new file +18 -0
@@ -0,0 +1,131 @@
+/* linux/arch/arm/plat-samsung/dma-ops.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com
+ *
+ * Samsung DMA Operations
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/dmaengine.h>
+#include <linux/amba/pl330.h>
+
+#include <mach/dma.h>
Quoted 8 lines
Quoted 5 lines
arch/arm/plat-samsung/dma-ops.c new file +4 -0
+
+static bool filter(struct dma_chan *chan, void *param)
+{
+	struct dma_pl330_peri *peri = (struct dma_pl330_peri *)chan-

private;

Is this code pl330 specific? If so, 'pl330' should probably be referenced in the function name.

I will address your comment.

Quoted 57 lines

arch/arm/plat-samsung/dma-ops.c

Quoted 10 lines
arch/arm/plat-samsung/dma-ops.c new file +9 -0
+	unsigned dma_ch = (unsigned)param;
+
+	if (peri->peri_id != dma_ch)
+		return false;
+
+	return true;
+}
+
+static unsigned dma_request(enum dma_ch dma_ch, struct samsung_dma_info

*info)

Quoted 46 lines
arch/arm/plat-samsung/dma-ops.c new file +46 -0
+{
+	struct dma_chan *chan;
+	dma_cap_mask_t mask;
+	struct dma_slave_config slave_config;
+
+	dma_cap_zero(mask);
+	dma_cap_set(info->cap, mask);
+
+	chan = dma_request_channel(mask, filter, (void *)dma_ch);
+
+	if (info->direction == DMA_FROM_DEVICE) {
+		memset(&slave_config, 0, sizeof(struct dma_slave_config));
+		slave_config.direction = info->direction;
+		slave_config.src_addr = info->fifo;
+		slave_config.src_addr_width = info->width;
+		dmaengine_slave_config(chan, &slave_config);
+	} else if (info->direction == DMA_TO_DEVICE) {
+		memset(&slave_config, 0, sizeof(struct dma_slave_config));
+		slave_config.direction = info->direction;
+		slave_config.dst_addr = info->fifo;
+		slave_config.dst_addr_width = info->width;
+		dmaengine_slave_config(chan, &slave_config);
+	}
+
+	return (unsigned)chan;
+}
+
+static int dma_release(unsigned ch, struct s3c2410_dma_client *client)
+{
+	dma_release_channel((struct dma_chan *)ch);
+
+	return 0;
+}
+
+static int dma_prepare(unsigned ch, struct samsung_dma_prep_info *info)
+{
+	struct scatterlist sg;
+	struct dma_chan *chan = (struct dma_chan *)ch;
+	struct dma_async_tx_descriptor *desc;
+
+	switch (info->cap) {
+	case DMA_SLAVE:
+		sg_init_table(&sg, 1);
+		sg_dma_len(&sg) = info->len;
+		sg_set_page(&sg, pfn_to_page(PFN_DOWN(info->buf)),
+			    info->len, offset_in_page(info->buf));
Quoted 8 lines

arch/arm/plat-samsung/dma-ops.c

Quoted 8 lines
arch/arm/plat-samsung/dma-ops.c new file +8 -0
+		sg_dma_address(&sg) = info->buf;
+
+		desc = chan->device->device_prep_slave_sg(chan,
+			&sg, 1, info->direction, DMA_PREP_INTERRUPT);
+		break;
+	case DMA_CYCLIC:
+		desc = chan->device->device_prep_dma_cyclic(chan,
+			info->buf, info->len, info->period,

info->direction);

Quoted 38 lines
Quoted 38 lines
arch/arm/plat-samsung/dma-ops.c new file +38 -0
+		break;
+	default:
+		dev_err(&chan->dev->device, "unsupported format\n");
+		return -EFAULT;
+	}
+
+	if (!desc) {
+		dev_err(&chan->dev->device, "cannot prepare cyclic dma\n");
+		return -EFAULT;
+	}
+
+	desc->callback = info->fp;
+	desc->callback_param = info->fp_param;
+
+	dmaengine_submit((struct dma_async_tx_descriptor *)desc);
+
+	return 0;
+}
+
+static inline int dma_trigger(unsigned ch)
+{
+	dma_async_issue_pending((struct dma_chan *)ch);
+
+	return 0;
+}
+
+static inline int dma_flush(unsigned ch)
+{
+	return dmaengine_terminate_all((struct dma_chan *)ch);
+}
+
+static struct samsung_dma_ops dmaeng_ops = {
+	.request	= dma_request,
+	.release	= dma_release,
+	.prepare	= dma_prepare,
+	.trigger	= dma_trigger,
+	.started	= NULL,
+	.flush		= dma_flush,
Quoted 8 lines

arch/arm/plat-samsung/dma-ops.c line 125

Quoted 2 lines
arch/arm/plat-samsung/dma-ops.c new file +2 -0
+	.stop		= dma_flush,
+};

Even though these function are all local statics, you should use a samsung prefix to avoid namespace collisions. So, they should be named something like: samsung_dmaeng_ops, samsung_dmaeng_request(), samsung_dmaeng_release(), etc. The ops structure and the functions should have the same prefix.

I will address your comment.

Quoted 10 lines

arch/arm/plat-samsung/dma-ops.c line 131

Quoted 7 lines
arch/arm/plat-samsung/dma-ops.c new file +6 -0
+
+void *samsung_dma_get_ops(void)
+{
+	return (void *)&dmaeng_ops;
+}
+EXPORT_SYMBOL(samsung_dma_get_ops);

If all that is needed is a reference to the dma ops, then you could simply export samsung_dmaeng_ops() without a separate function.

Grant, Thanks for your comments. I can't understand this comment well. Do you mean to change function name from 'samsung_dma_get_ops()' to 'samsung_dmaeng_ops()' ?
Or export 'dmaeng_ops' variable instead of making this 'samsung_dma_get_ops()' function

Quoted 57 lines

Review

Quoted 2 lines
(quoted diff) +0 -0

b/arch/arm/plat-samsung/include/plat/dma-ops.h

Review

Quoted 53 lines

new file mode 100644
index 0000000..eea4130

arch/arm/plat-samsung/include/plat/dma-ops.h new file +47 -0
@@ -0,0 +1,47 @@
+/* arch/arm/plat-samsung/include/plat/dma-ops.h
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com
+ *
+ * Samsung DMA support
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/dmaengine.h>
+
+struct samsung_dma_prep_info {
+	enum dma_transaction_type cap;
+	enum dma_data_direction direction;
+	unsigned buf;
+	unsigned long period;
+	unsigned long len;
+	void (*fp)(void *data);
+	void *fp_param;
+};
+
+struct samsung_dma_info {
+	enum dma_transaction_type cap;
+	enum dma_data_direction direction;
+	enum dma_slave_buswidth width;
+	unsigned fifo;
+	struct s3c2410_dma_client *client;
+};
+
+struct samsung_dma_ops {
+	unsigned (*request)(enum dma_ch ch, struct samsung_dma_info *info);
+	int (*release)(unsigned ch, struct s3c2410_dma_client *client);
+	int (*prepare)(unsigned ch, struct samsung_dma_prep_info *info);
+	int (*trigger)(unsigned ch);
+	int (*started)(unsigned ch);
+	int (*flush)(unsigned ch);
+	int (*stop)(unsigned ch);
+};
+
+/*
+ * samsung_dma_get_ops
+ * get the set of dma operations
+ */
+extern void *samsung_dma_get_ops(void);
(quoted diff) +0 -0

b/arch/arm/plat-samsung/include/plat/dma-pl330.h

Quoted 16 lines

arch/arm/plat-samsung/include/plat/dma-pl330.h line 7

Quoted 11 lines

index c402719..be84bec 100644

arch/arm/plat-samsung/include/plat/dma-pl330.h +3 -0
@@ -1,4 +1,7 @@
 /*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com
+ *
  * Copyright (C) 2010 Samsung Electronics Co. Ltd.
  *	Jaswinder Singh <[email protected]>
  *

Heh, this patch doesn't make any changes to this file, and samsung already has a copyright notice on it anyway. You should probably drop this hunk.

I will address your comment.

Quoted 8 lines

arch/arm/plat-

Quoted 2 lines
arch/arm/plat- renamed from arch/arm/plat-samsung/include/plat/dma.h +0 -0

samsung/include/plat/dma.h

arch/arm/plat-samsung/include/plat/dma.h extern int s3c2410_dma_getposition(unsigned int

Quoted 4 lines

index 2e8f8c6..90da162 100644

arch/arm/plat-samsung/include/plat/dma.h +0 -0
@@ -124,4 +124,4 @@ extern int s3c2410_dma_getposition(unsigned int

channel,

Quoted 8 lines

arch/arm/plat-samsung/include/plat/dma.h extern int s3c2410_dma_getposition(unsigned int · line 125

Quoted 2 lines
arch/arm/plat-samsung/include/plat/dma.h +0 -0
 extern int s3c2410_dma_set_opfn(unsigned int, s3c2410_dma_opfn_t rtn);
 extern int s3c2410_dma_set_buffdone_fn(unsigned int, s3c2410_dma_cbfn_t

rtn);

arch/arm/plat-samsung/include/plat/dma.h extern int s3c2410_dma_getposition(unsigned int channel, · line 127

Quoted 2 lines
arch/arm/plat-samsung/include/plat/dma.h +0 -1
-

nitpick: Unrelated whitespace change. One blank line of whitespace is sufficient anyway.

I will address your comment.

Quoted 53 lines

arch/arm/plat-

Quoted 2 lines
arch/arm/plat-samsung/include/plat/dma.h +1 -0
+#include <plat/dma-ops.h>
arch/arm/plat- renamed from arch/arm/plat-samsung/s3c-dma-ops.c +0 -0

samsung/s3c-dma-ops.c

Quoted 15 lines

new file mode 100644
index 0000000..17b1be0

arch/arm/plat-samsung/s3c-dma-ops.c new file +10 -0
@@ -0,0 +1,132 @@
+/* linux/arch/arm/plat-samsung/s3c-dma-ops.c
+ *
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com
+ *
+ * Samsung S3C-DMA Operations
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

arch/arm/plat-samsung/s3c-dma-ops.c line 20

Quoted 10 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +10 -0
+*/
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+
+#include <mach/dma.h>
+
+struct cb_data {

struct s3c2410_cb_data {

arch/arm/plat-samsung/s3c-dma-ops.c line 32

Quoted 12 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +12 -0
+	void (*fp) (void *);
+	void *fp_param;
+	unsigned ch;
+	struct list_head node;
+};
+
+static LIST_HEAD(dma_list);
+
+static void dma_cb(struct s3c2410_dma_chan *channel,
+		   void *param, int size, enum s3c2410_dma_buffresult res)
+{
+	struct cb_data *data = (struct cb_data *)param;

param is a void*. The (struct cb_data*) cast is not needed.

arch/arm/plat-samsung/s3c-dma-ops.c

Quoted 5 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +5 -0
+
+	data->fp(data->fp_param);
+}
+
+static unsigned dma_request(enum dma_ch dma_ch, struct samsung_dma_info

*info)

Quoted 4 lines

These functions should *definitely* be named differently from the dma_* ops in the other file so that you can differentiate between them, and to make them grep-friendly. This goes for *all* file-scope symbols.

I will address your comment.

Quoted 13 lines

arch/arm/plat-samsung/s3c-dma-ops.c line 46

Quoted 10 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +9 -0
+{
+	struct cb_data *data;
+
+	if (s3c2410_dma_request(dma_ch, info->client, NULL) < 0) {
+		s3c2410_dma_free(dma_ch, info->client);
+		return 0;
+	}
+
+	data = kmalloc(sizeof(struct cb_data), GFP_KERNEL);

kzalloc()

Quoted 3 lines

arch/arm/plat-samsung/s3c-dma-ops.c line 47

Quoted 1 line
arch/arm/plat-samsung/s3c-dma-ops.c new file +1 -0
+	data->fp = NULL;

Drop this line after converting to kzalloc()

I will address your comment.

Quoted 9 lines

arch/arm/plat-samsung/s3c-dma-ops.c line 48

Quoted 2 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +1 -0
+	data->ch = (unsigned)dma_ch;

Is the cast necessary?

arch/arm/plat-samsung/s3c-dma-ops.c

Quoted 4 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +4 -0
+	list_add_tail(&data->node, &dma_list);
+
+	if (info->direction == DMA_FROM_DEVICE)
+		s3c2410_dma_devconfig(dma_ch, S3C2410_DMASRC_HW,

info->fifo);

Quoted 18 lines
Quoted 3 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +2 -0
+	else
+		s3c2410_dma_devconfig(dma_ch, S3C2410_DMASRC_MEM, info-

fifo);

From arch/arm/plat-samsung/include/plat/dma.h:

	enum s3c2410_dmasrc {
		S3C2410_DMASRC_HW,	/* source is memory */
		S3C2410_DMASRC_MEM	/* source is hardware */
	};

from dma-mapping.h:

	enum dma_data_direction {
		DMA_BIDIRECTIONAL = 0,
		DMA_TO_DEVICE = 1,
		DMA_FROM_DEVICE = 2,
		DMA_NONE = 3,
	};
Quoted 4 lines

/me thinks it would all look nicer if s3c2410 dma just replaced s3c2410_dmasrc to dma_data_direction, and from what I can tell it would just be a simple search and replace. :-)

I will address your comment.

Quoted 13 lines

arch/arm/plat-samsung/s3c-dma-ops.c line 64

Quoted 10 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +10 -0
+
+	if (info->cap == DMA_CYCLIC)
+		s3c2410_dma_setflags(dma_ch, S3C2410_DMAF_CIRCULAR);
+
+	s3c2410_dma_config(dma_ch, info->width);
+
+	return (unsigned)dma_ch;
+}
+
+static int dma_release(unsigned ch, struct s3c2410_dma_client *client)

unsigned int

Quoted 11 lines

arch/arm/plat-samsung/s3c-dma-ops.c line 70

Quoted 6 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +6 -0
+{
+	struct cb_data *data;
+
+	list_for_each_entry(data, &dma_list, node)
+	    if (data->ch == ch)
+		break;

nit: incorrect indentation. Use tab characters instead of spaces. I've got "set list" and "set listchars=tab:\|-,trail:-" in my ~/.vimrc so I can see the difference between tabs and spaces.

I will address your comment.

Quoted 5 lines

arch/arm/plat-samsung/s3c-dma-ops.c line 71

Quoted 1 line
arch/arm/plat-samsung/s3c-dma-ops.c new file +1 -0
+	list_del(&data->node);

What happens if the channel isn't found in the list? Can that situation happen?

Quoted 8 lines

What happens if two drivers call dma_release simultaneously? It looks like a mutex is needed to protext the dma_list.

arch/arm/plat-samsung/s3c-dma-ops.c

Quoted 2 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +2 -0
+
+	s3c2410_dma_free((enum dma_ch)ch, client);

All the casting in this patch makes me nervous. When a lot of casting is required, I wonder if the API needs to be changed.

I will remove casting to "enum dma_ch"

Quoted 58 lines
Quoted 58 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +57 -0
+	kfree(data);
+
+	return 0;
+}
+
+static int dma_prepare(unsigned ch, struct samsung_dma_prep_info *info)
+{
+	struct cb_data *data;
+
+	list_for_each_entry(data, &dma_list, node)
+	    if (data->ch == ch)
+		break;
+
+	if (!data->fp) {
+		s3c2410_dma_set_buffdone_fn((enum dma_ch)ch, dma_cb);
+		data->fp = info->fp;
+		data->fp_param = info->fp_param;
+	}
+	s3c2410_dma_enqueue((enum dma_ch)ch, (void *)data, info->buf,
+			    info->period);
+
+	return 0;
+}
+
+static inline int dma_trigger(unsigned ch)
+{
+	return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_START);
+}
+
+static inline int dma_started(unsigned ch)
+{
+	return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STARTED);
+}
+
+static inline int dma_flush(unsigned ch)
+{
+	return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_FLUSH);
+}
+
+static inline int dma_stop(unsigned ch)
+{
+	return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STOP);
+}
+
+static struct samsung_dma_ops s3c_dma_ops = {
+	.request	= dma_request,
+	.release	= dma_release,
+	.prepare	= dma_prepare,
+	.trigger	= dma_trigger,
+	.started	= dma_started,
+	.flush		= dma_flush,
+	.stop		= dma_stop,
+};
+
+void *samsung_dma_get_ops(void)
+{
+	return (void *)&s3c_dma_ops;
Quoted 9 lines

arch/arm/plat-samsung/s3c-dma-ops.c

Quoted 2 lines
arch/arm/plat-samsung/s3c-dma-ops.c new file +2 -0
+}
+EXPORT_SYMBOL(samsung_dma_get_ops);

This is a problem. This patch adds two implementations of samsung_dma_get_ops(). New code needs to be multiplatform friendly. That means that the code nees to handle both dma-ops.c and s3c-dma-ops.c compiled into the kernel at the same time and select the correct one at runtime.

I will address your comment.

Quoted 5 lines

g.

Quoted 3 lines

--
1.7.1

#13 lore raw

PATCH v2 5/12 ARM: SAMSUNG: Add common DMA operations

Quoted 10 lines · Boojin Kim
Quoted 8 lines · Grant Likely

arch/arm/plat-samsung/dma-ops.c line 131

Quoted 5 lines
arch/arm/plat-samsung/dma-ops.c new file +5 -0
+void *samsung_dma_get_ops(void)
+{
+	return (void *)&dmaeng_ops;
+}
+EXPORT_SYMBOL(samsung_dma_get_ops);

If all that is needed is a reference to the dma ops, then you could simply export samsung_dmaeng_ops() without a separate function.

Quoted 5 lines

Grant, Thanks for your comments. I can't understand this comment well. Do you mean to change function name from 'samsung_dma_get_ops()' to 'samsung_dmaeng_ops()' ?
Or export 'dmaeng_ops' variable instead of making this 'samsung_dma_get_ops()' function

I mean export dmaeng_ops instead of using a function. You also get some type checking by not casting it into a (void*).

author
#14 lore raw

PATCH v2 6/12 ARM: EXYNOS4: Use generic DMA PL330 driver

In reply to Kukjin Kim

From: Boojin Kim <[email protected]>

This patch makes Samsung EXYNOS4 to use DMA PL330 driver on DMADEVICE. The EXYNOS4 uses DMA generic APIs instead of SAMSUNG specific S3C-PL330 APIs.

---
 arch/arm/mach-exynos4/Kconfig |    2 +-
 arch/arm/mach-exynos4/clock.c |   16 +-
 arch/arm/mach-exynos4/dma.c   |  323 +++++++++++++++++++++++++++--------------
 3 files changed, 221 insertions(+), 120 deletions(-)
arch/arm/mach-exynos4/Kconfig +1 -1
index 1435fc3..5cc9b7a 100644
@@ -11,7 +11,7 @@ if ARCH_EXYNOS4
 
 config CPU_EXYNOS4210
 	bool
-	select S3C_PL330_DMA
+	select DMADEV_PL330
 	help
 	  Enable EXYNOS4210 CPU support
 
arch/arm/mach-exynos4/clock.c +9 -7
index 871f9d5..1b2e78c 100644
@@ -47,6 +47,11 @@ static struct clk clk_sclk_usbphy1 = {
 	.id		= -1,
 };
 
+static struct clk dummy_apb_pclk = {
+	.name		= "apb_pclk",
+	.id		= -1,
+};
+
 static int exynos4_clksrc_mask_top_ctrl(struct clk *clk, int enable)
 {
 	return s5p_gatectrl(S5P_CLKSRC_MASK_TOP, clk, enable);
@@ -485,16 +490,11 @@ static struct clk init_clocks_off[] = {
 		.enable		= exynos4_clk_ip_fsys_ctrl,
 		.ctrlbit	= (1 << 10),
 	}, {
-		.name		= "pdma",
-		.id		= 0,
+		.name		= "dma",
+		.id		= -1,
 		.enable		= exynos4_clk_ip_fsys_ctrl,
 		.ctrlbit	= (1 << 0),
 	}, {
-		.name		= "pdma",
-		.id		= 1,
-		.enable		= exynos4_clk_ip_fsys_ctrl,
-		.ctrlbit	= (1 << 1),
-	}, {
 		.name		= "adc",
 		.id		= -1,
 		.enable		= exynos4_clk_ip_peril_ctrl,
@@ -1212,5 +1212,7 @@ void __init exynos4_register_clocks(void)
 	s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
 	s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
 
+	s3c24xx_register_clock(&dummy_apb_pclk);
+
 	s3c_pwmclk_init();
 }
arch/arm/mach-exynos4/dma.c +211 -112

362 lines not on this page · raw message

Signature · 1 line
1.7.1
author
#15 lore raw

PATCH v2 7/12 ARM: S5PV210: Use generic DMA PL330 driver

In reply to Kukjin Kim

From: Boojin Kim <[email protected]>

This patch makes Samsung S5PV210 to use DMA PL330 driver on DMADEVICE. The S5PV210 uses DMA generic APIs instead of SAMSUNG specific S3C-PL330 APIs.

---
 arch/arm/mach-s5pv210/Kconfig |    2 +-
 arch/arm/mach-s5pv210/clock.c |   16 ++--
 arch/arm/mach-s5pv210/dma.c   |  232 +++++++++++++++++++----------------------
 3 files changed, 118 insertions(+), 132 deletions(-)
arch/arm/mach-s5pv210/Kconfig +1 -1
index 37b5a97..fb11e38 100644
@@ -11,7 +11,7 @@ if ARCH_S5PV210
 
 config CPU_S5PV210
 	bool
-	select S3C_PL330_DMA
+	select DMADEV_PL330
 	select S5P_EXT_INT
 	select S5P_HRT
 	select S5PV210_PM if PM
arch/arm/mach-s5pv210/clock.c +8 -8
index 2d59949..dbe7285 100644
@@ -221,6 +221,11 @@ static struct clk clk_pcmcdclk2 = {
 	.id		= -1,
 };
 
+static struct clk dummy_apb_pclk = {
+	.name		= "apb_pclk",
+	.id		= -1,
+};
+
 static struct clk *clkset_vpllsrc_list[] = {
 	[0] = &clk_fin_vpll,
 	[1] = &clk_sclk_hdmi27m,
@@ -311,18 +316,12 @@ static struct clk_ops clk_fout_apll_ops = {
 
 static struct clk init_clocks_off[] = {
 	{
-		.name		= "pdma",
-		.id		= 0,
+		.name		= "dma",
+		.id		= -1,
 		.parent		= &clk_hclk_psys.clk,
 		.enable		= s5pv210_clk_ip0_ctrl,
 		.ctrlbit	= (1 << 3),
 	}, {
-		.name		= "pdma",
-		.id		= 1,
-		.parent		= &clk_hclk_psys.clk,
-		.enable		= s5pv210_clk_ip0_ctrl,
-		.ctrlbit	= (1 << 4),
-	}, {
 		.name		= "rot",
 		.id		= -1,
 		.parent		= &clk_hclk_dsys.clk,
@@ -1239,5 +1238,6 @@ void __init s5pv210_register_clocks(void)
 	s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
 	s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
 
+	s3c24xx_register_clock(&dummy_apb_pclk);
 	s3c_pwmclk_init();
 }
arch/arm/mach-s5pv210/dma.c +109 -123

264 lines not on this page · raw message

Signature · 1 line
1.7.1
author
#16 lore raw

PATCH v2 8/12 ARM: S5PC100: Use generic DMA PL330 driver

In reply to Kukjin Kim

From: Boojin Kim <[email protected]>

This patch makes Samsung S5PC100 to use DMA PL330 driver on DMADEVICE. The S5PC100 uses DMA generic APIs instead of SAMSUNG specific S3C-PL330 APIs.

---
 arch/arm/mach-s5pc100/Kconfig |    2 +-
 arch/arm/mach-s5pc100/clock.c |   23 ++---
 arch/arm/mach-s5pc100/dma.c   |  249 +++++++++++++++++++++--------------------
 3 files changed, 136 insertions(+), 138 deletions(-)
arch/arm/mach-s5pc100/Kconfig +1 -1
index 608722f..379fadc 100644
@@ -10,7 +10,7 @@ if ARCH_S5PC100
 config CPU_S5PC100
 	bool
 	select S5P_EXT_INT
-	select S3C_PL330_DMA
+	select DMADEV_PL330
 	help
 	  Enable S5PC100 CPU support
 
arch/arm/mach-s5pc100/clock.c +9 -14
index 0305e9b..891acfe 100644
@@ -34,6 +34,11 @@ static struct clk s5p_clk_otgphy = {
 	.id		= -1,
 };
 
+static struct clk dummy_apb_pclk = {
+	.name		= "apb_pclk",
+	.id		= -1,
+};
+
 static struct clk *clk_src_mout_href_list[] = {
 	[0] = &s5p_clk_27m,
 	[1] = &clk_fin_hpll,
@@ -416,12 +421,6 @@ static struct clk init_clocks_off[] = {
 		.enable		= s5pc100_d0_0_ctrl,
 		.ctrlbit	= (1 << 4),
 	}, {
-		.name		= "mdma",
-		.id		= -1,
-		.parent		= &clk_div_d0_bus.clk,
-		.enable		= s5pc100_d0_0_ctrl,
-		.ctrlbit	= (1 << 3),
-	}, {
 		.name		= "cfcon",
 		.id		= -1,
 		.parent		= &clk_div_d0_bus.clk,
@@ -488,14 +487,8 @@ static struct clk init_clocks_off[] = {
 		.enable		= s5pc100_d1_0_ctrl,
 		.ctrlbit	= (1 << 2),
 	}, {
-		.name		= "pdma",
-		.id		= 1,
-		.parent		= &clk_div_d1_bus.clk,
-		.enable		= s5pc100_d1_0_ctrl,
-		.ctrlbit	= (1 << 1),
-	}, {
-		.name		= "pdma",
-		.id		= 0,
+		.name		= "dma",
+		.id		= -1,
 		.parent		= &clk_div_d1_bus.clk,
 		.enable		= s5pc100_d1_0_ctrl,
 		.ctrlbit	= (1 << 0),
@@ -1394,5 +1387,7 @@ void __init s5pc100_register_clocks(void)
 	s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
 	s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
 
+	s3c24xx_register_clock(&dummy_apb_pclk);
+
 	s3c_pwmclk_init();
 }
arch/arm/mach-s5pc100/dma.c +126 -123

280 lines not on this page · raw message

Signature · 1 line
1.7.1
author
#17 lore raw

PATCH v2 9/12 ARM: S5P64X0: Use generic DMA PL330 driver

In reply to Kukjin Kim

From: Boojin Kim <[email protected]>

This patch makes Samsung S5P64X0 to use DMA PL330 driver on DMADEVICE. The S5P64X0 uses DMA generic APIs instead of SAMSUNG specific S3C-PL330 APIs.

---
 arch/arm/mach-s5p64x0/Kconfig         |    4 +-
 arch/arm/mach-s5p64x0/clock-s5p6440.c |    9 +-
 arch/arm/mach-s5p64x0/clock-s5p6450.c |    9 +-
 arch/arm/mach-s5p64x0/dma.c           |  303 +++++++++++++++++++++++----------
 4 files changed, 228 insertions(+), 97 deletions(-)
arch/arm/mach-s5p64x0/Kconfig +2 -2
index 017af4c..7108e7e 100644
@@ -9,14 +9,14 @@ if ARCH_S5P64X0
 
 config CPU_S5P6440
 	bool
-	select S3C_PL330_DMA
+	select DMADEV_PL330
 	select S5P_HRT
 	help
 	  Enable S5P6440 CPU support
 
 config CPU_S5P6450
 	bool
-	select S3C_PL330_DMA
+	select DMADEV_PL330
 	select S5P_HRT
 	help
 	  Enable S5P6450 CPU support
arch/arm/mach-s5p64x0/clock-s5p6440.c +8 -1
index 9f12c2e..5f7ad9e 100644
@@ -153,7 +153,7 @@ static struct clk init_clocks_off[] = {
 		.enable		= s5p64x0_hclk0_ctrl,
 		.ctrlbit	= (1 << 8),
 	}, {
-		.name		= "pdma",
+		.name		= "dma",
 		.id		= -1,
 		.parent		= &clk_hclk_low.clk,
 		.enable		= s5p64x0_hclk0_ctrl,
@@ -533,6 +533,11 @@ static struct clksrc_clk *sysclks[] = {
 	&clk_pclk_low,
 };
 
+static struct clk dummy_apb_pclk = {
+	.name		= "apb_pclk",
+	.id		= -1,
+};
+
 void __init_or_cpufreq s5p6440_setup_clocks(void)
 {
 	struct clk *xtal_clk;
@@ -615,5 +620,7 @@ void __init s5p6440_register_clocks(void)
 	s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
 	s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
 
+	s3c24xx_register_clock(&dummy_apb_pclk);
+
 	s3c_pwmclk_init();
 }
arch/arm/mach-s5p64x0/clock-s5p6450.c +8 -1
index 4eec457..62d4707 100644
@@ -189,7 +189,7 @@ static struct clk init_clocks_off[] = {
 		.enable		= s5p64x0_hclk0_ctrl,
 		.ctrlbit	= (1 << 3),
 	}, {
-		.name		= "pdma",
+		.name		= "dma",
 		.id		= -1,
 		.parent		= &clk_hclk_low.clk,
 		.enable		= s5p64x0_hclk0_ctrl,
@@ -583,6 +583,11 @@ static struct clksrc_clk *sysclks[] = {
 	&clk_sclk_audio0,
 };
 
+static struct clk dummy_apb_pclk = {
+	.name		= "apb_pclk",
+	.id		= -1,
+};
+
 void __init_or_cpufreq s5p6450_setup_clocks(void)
 {
 	struct clk *xtal_clk;
@@ -662,5 +667,7 @@ void __init s5p6450_register_clocks(void)
 	s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
 	s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
 
+	s3c24xx_register_clock(&dummy_apb_pclk);
+
 	s3c_pwmclk_init();
 }
arch/arm/mach-s5p64x0/dma.c +210 -93

340 lines not on this page · raw message

Signature · 1 line
1.7.1
author
#18 lore raw

PATCH v2 10/12 ARM: SAMSUNG: Remove S3C-PL330-DMA driver

In reply to Kukjin Kim

From: Boojin Kim <[email protected]>

Since DMA generic APIs can be used for Samsung DMA now so that the s3c-pl330 which includes Samsung specific DMA APIs can be removed.

---
 arch/arm/plat-samsung/Kconfig                      |    6 -
 arch/arm/plat-samsung/Makefile                     |    2 -
 arch/arm/plat-samsung/include/plat/dma-pl330.h     |    8 +-
 .../plat-samsung/include/plat/s3c-pl330-pdata.h    |   32 -
 arch/arm/plat-samsung/s3c-pl330.c                  | 1244 --------------------
 5 files changed, 5 insertions(+), 1287 deletions(-)
 delete mode 100644 arch/arm/plat-samsung/include/plat/s3c-pl330-pdata.h
 delete mode 100644 arch/arm/plat-samsung/s3c-pl330.c
arch/arm/plat-samsung/Kconfig +0 -6
index cb170a6..db789d7 100644
@@ -294,12 +294,6 @@ config S3C_DMA
 	help
 	  Internal configuration for S3C DMA core
 
-config S3C_PL330_DMA
-	bool
-	select PL330
-	help
-	  S3C DMA API Driver for PL330 DMAC.
-
 config DMADEV_PL330
 	bool
 	select DMADEVICES
arch/arm/plat-samsung/Makefile +0 -2
index 9ecf2aa..ea98621 100644
@@ -66,8 +66,6 @@ obj-$(CONFIG_S3C_DMA)		+= dma.o s3c-dma-ops.o
 
 obj-$(CONFIG_DMADEV_PL330)	+= dma-ops.o
 
-obj-$(CONFIG_S3C_PL330_DMA)	+= s3c-pl330.o s3c-dma-ops.o
-
 # PM support
 
 obj-$(CONFIG_PM)		+= pm.o
arch/arm/plat-samsung/include/plat/dma-pl330.h +5 -3
index be84bec..dbc1288 100644
@@ -14,8 +14,6 @@
 #ifndef __DMA_PL330_H_
 #define __DMA_PL330_H_ __FILE__
 
-#define S3C2410_DMAF_AUTOSTART	(1 << 0)
-#define S3C2410_DMAF_CIRCULAR	(1 << 1)
 /*
  * PL330 can assign any channel to communicate with
  * any of the peripherals attched to the DMAC.
@@ -98,11 +96,15 @@ enum dma_ch {
 	DMACH_MAX,
 };
 
+struct s3c2410_dma_client {
+	char	*name;
+};
+
 static inline bool s3c_dma_has_circular(void)
 {
 	return true;
 }
 
-#include <plat/dma.h>
+#include <plat/dma-ops.h>
 
 #endif	/* __DMA_PL330_H_ */
arch/arm/plat-samsung/include/plat/s3c-pl330-pdata.h deleted +0 -32
deleted file mode 100644
index 64fdf66..0000000
@@ -1,32 +0,0 @@
-/* linux/arch/arm/plat-samsung/include/plat/s3c-pl330-pdata.h
- *
- * Copyright (C) 2010 Samsung Electronics Co. Ltd.
- *	Jaswinder Singh <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#ifndef __S3C_PL330_PDATA_H
-#define __S3C_PL330_PDATA_H
-
-#include <plat/dma-pl330.h>
-
-/*
- * Every PL330 DMAC has max 32 peripheral interfaces,
- * of which some may be not be really used in your
- * DMAC's configuration.
- * Populate this array of 32 peri i/fs with relevant
- * channel IDs for used peri i/f and DMACH_MAX for
- * those unused.
- *
- * The platforms just need to provide this info
- * to the S3C DMA API driver for PL330.
- */
-struct s3c_pl330_platdata {
-	enum dma_ch peri[32];
-};
-
-#endif /* __S3C_PL330_PDATA_H */
arch/arm/plat-samsung/s3c-pl330.c deleted +0 -1244

1,244 lines not on this page · raw message

Signature · 1 line
1.7.1
author
#19 lore raw

PATCH v2 11/12 spi/s3c64xx: Add support DMA engine API

In reply to Kukjin Kim

From: Boojin Kim <[email protected]>

This patch adds to support DMA generic API to transfer raw SPI data. Basiclly the spi driver uses DMA generic API if architecture supports it. Otherwise, uses Samsung specific S3C-PL330 APIs.

---
 drivers/spi/spi_s3c64xx.c |  141 ++++++++++++++++++++++-----------------------
 1 files changed, 69 insertions(+), 72 deletions(-)
drivers/spi/spi_s3c64xx.c +69 -72
index 8945e20..a4cf76a 100644
@@ -172,6 +172,9 @@ struct s3c64xx_spi_driver_data {
 	unsigned                        state;
 	unsigned                        cur_mode, cur_bpw;
 	unsigned                        cur_speed;
+	unsigned			rx_ch;
+	unsigned			tx_ch;
+	struct samsung_dma_ops		*ops;
 };
 
 static struct s3c2410_dma_client s3c64xx_spi_dma_client = {
@@ -227,6 +230,38 @@ static void flush_fifo(struct s3c64xx_spi_driver_data *sdd)
 	writel(val, regs + S3C64XX_SPI_CH_CFG);
 }
 
+static void s3c64xx_spi_dma_rxcb(void *data)
+{
+	struct s3c64xx_spi_driver_data *sdd
+		= (struct s3c64xx_spi_driver_data *)data;
+	unsigned long flags;
+
+	spin_lock_irqsave(&sdd->lock, flags);
+
+	sdd->state &= ~RXBUSY;
+	/* If the other done */
+	if (!(sdd->state & TXBUSY))
+		complete(&sdd->xfer_completion);
+
+	spin_unlock_irqrestore(&sdd->lock, flags);
+}
+
+static void s3c64xx_spi_dma_txcb(void *data)
+{
+	struct s3c64xx_spi_driver_data *sdd
+		= (struct s3c64xx_spi_driver_data *)data;
+	unsigned long flags;
+
+	spin_lock_irqsave(&sdd->lock, flags);
+
+	sdd->state &= ~TXBUSY;
+	/* If the other done */
+	if (!(sdd->state & RXBUSY))
+		complete(&sdd->xfer_completion);
+
+	spin_unlock_irqrestore(&sdd->lock, flags);
+}
+
 static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
 				struct spi_device *spi,
 				struct spi_transfer *xfer, int dma_mode)
@@ -234,6 +269,7 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
 	struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
 	void __iomem *regs = sdd->regs;
 	u32 modecfg, chcfg;
+	struct samsung_dma_prep_info info;
 
 	modecfg = readl(regs + S3C64XX_SPI_MODE_CFG);
 	modecfg &= ~(S3C64XX_SPI_MODE_TXDMA_ON | S3C64XX_SPI_MODE_RXDMA_ON);
@@ -259,10 +295,14 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
 		chcfg |= S3C64XX_SPI_CH_TXCH_ON;
 		if (dma_mode) {
 			modecfg |= S3C64XX_SPI_MODE_TXDMA_ON;
-			s3c2410_dma_config(sdd->tx_dmach, sdd->cur_bpw / 8);
-			s3c2410_dma_enqueue(sdd->tx_dmach, (void *)sdd,
-						xfer->tx_dma, xfer->len);
-			s3c2410_dma_ctrl(sdd->tx_dmach, S3C2410_DMAOP_START);
+			info.cap = DMA_SLAVE;
+			info.direction = DMA_TO_DEVICE;
+			info.buf = xfer->tx_dma;
+			info.len = xfer->len;
+			info.fp = s3c64xx_spi_dma_txcb;
+			info.fp_param = sdd;
+			sdd->ops->prepare(sdd->tx_ch, &info);
+			sdd->ops->trigger(sdd->tx_ch);
 		} else {
 			switch (sdd->cur_bpw) {
 			case 32:
@@ -294,10 +334,14 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
 			writel(((xfer->len * 8 / sdd->cur_bpw) & 0xffff)
 					| S3C64XX_SPI_PACKET_CNT_EN,
 					regs + S3C64XX_SPI_PACKET_CNT);
-			s3c2410_dma_config(sdd->rx_dmach, sdd->cur_bpw / 8);
-			s3c2410_dma_enqueue(sdd->rx_dmach, (void *)sdd,
-						xfer->rx_dma, xfer->len);
-			s3c2410_dma_ctrl(sdd->rx_dmach, S3C2410_DMAOP_START);
+			info.cap = DMA_SLAVE;
+			info.direction = DMA_FROM_DEVICE;
+			info.buf = xfer->rx_dma;
+			info.len = xfer->len;
+			info.fp = s3c64xx_spi_dma_rxcb;
+			info.fp_param = sdd;
+			sdd->ops->prepare(sdd->rx_ch, &info);
+			sdd->ops->trigger(sdd->rx_ch);
 		}
 	}
 
@@ -483,46 +527,6 @@ static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd)
 	}
 }
 
-static void s3c64xx_spi_dma_rxcb(struct s3c2410_dma_chan *chan, void *buf_id,
-				 int size, enum s3c2410_dma_buffresult res)
-{
-	struct s3c64xx_spi_driver_data *sdd = buf_id;
-	unsigned long flags;
-
-	spin_lock_irqsave(&sdd->lock, flags);
-
-	if (res == S3C2410_RES_OK)
-		sdd->state &= ~RXBUSY;
-	else
-		dev_err(&sdd->pdev->dev, "DmaAbrtRx-%d\n", size);
-
-	/* If the other done */
-	if (!(sdd->state & TXBUSY))
-		complete(&sdd->xfer_completion);
-
-	spin_unlock_irqrestore(&sdd->lock, flags);
-}
-
-static void s3c64xx_spi_dma_txcb(struct s3c2410_dma_chan *chan, void *buf_id,
-				 int size, enum s3c2410_dma_buffresult res)
-{
-	struct s3c64xx_spi_driver_data *sdd = buf_id;
-	unsigned long flags;
-
-	spin_lock_irqsave(&sdd->lock, flags);
-
-	if (res == S3C2410_RES_OK)
-		sdd->state &= ~TXBUSY;
-	else
-		dev_err(&sdd->pdev->dev, "DmaAbrtTx-%d \n", size);
-
-	/* If the other done */
-	if (!(sdd->state & RXBUSY))
-		complete(&sdd->xfer_completion);
-
-	spin_unlock_irqrestore(&sdd->lock, flags);
-}
-
 #define XFER_DMAADDR_INVALID DMA_BIT_MASK(32)
 
 static int s3c64xx_spi_map_mssg(struct s3c64xx_spi_driver_data *sdd,
@@ -697,12 +701,10 @@ static void handle_msg(struct s3c64xx_spi_driver_data *sdd,
 			if (use_dma) {
 				if (xfer->tx_buf != NULL
 						&& (sdd->state & TXBUSY))
-					s3c2410_dma_ctrl(sdd->tx_dmach,
-							S3C2410_DMAOP_FLUSH);
+					sdd->ops->stop(sdd->tx_ch);
 				if (xfer->rx_buf != NULL
 						&& (sdd->state & RXBUSY))
-					s3c2410_dma_ctrl(sdd->rx_dmach,
-							S3C2410_DMAOP_FLUSH);
+					sdd->ops->stop(sdd->rx_ch);
 			}
 
 			goto out;
@@ -742,24 +744,19 @@ out:
 
 static int acquire_dma(struct s3c64xx_spi_driver_data *sdd)
 {
-	if (s3c2410_dma_request(sdd->rx_dmach,
-					&s3c64xx_spi_dma_client, NULL) < 0) {
-		dev_err(&sdd->pdev->dev, "cannot get RxDMA\n");
-		return 0;
-	}
-	s3c2410_dma_set_buffdone_fn(sdd->rx_dmach, s3c64xx_spi_dma_rxcb);
-	s3c2410_dma_devconfig(sdd->rx_dmach, S3C2410_DMASRC_HW,
-					sdd->sfr_start + S3C64XX_SPI_RX_DATA);
-
-	if (s3c2410_dma_request(sdd->tx_dmach,
-					&s3c64xx_spi_dma_client, NULL) < 0) {
-		dev_err(&sdd->pdev->dev, "cannot get TxDMA\n");
-		s3c2410_dma_free(sdd->rx_dmach, &s3c64xx_spi_dma_client);
-		return 0;
-	}
-	s3c2410_dma_set_buffdone_fn(sdd->tx_dmach, s3c64xx_spi_dma_txcb);
-	s3c2410_dma_devconfig(sdd->tx_dmach, S3C2410_DMASRC_MEM,
-					sdd->sfr_start + S3C64XX_SPI_TX_DATA);
+
+	struct samsung_dma_info info;
+	sdd->ops = samsung_dma_get_ops();
+
+	info.cap = DMA_SLAVE;
+	info.client = &s3c64xx_spi_dma_client;
+	info.direction = DMA_FROM_DEVICE;
+	info.fifo = sdd->sfr_start + S3C64XX_SPI_RX_DATA;
+	info.width = sdd->cur_bpw / 8;
+	sdd->rx_ch = sdd->ops->request(sdd->rx_dmach, &info);
+	info.direction = DMA_TO_DEVICE;
+	info.fifo = sdd->sfr_start + S3C64XX_SPI_TX_DATA;
+	sdd->tx_ch = sdd->ops->request(sdd->tx_dmach, &info);
 
 	return 1;
 }
@@ -800,8 +797,8 @@ static void s3c64xx_spi_work(struct work_struct *work)
 	spin_unlock_irqrestore(&sdd->lock, flags);
 
 	/* Free DMA channels */
-	s3c2410_dma_free(sdd->tx_dmach, &s3c64xx_spi_dma_client);
-	s3c2410_dma_free(sdd->rx_dmach, &s3c64xx_spi_dma_client);
+	sdd->ops->release(sdd->rx_ch, &s3c64xx_spi_dma_client);
+	sdd->ops->release(sdd->tx_ch, &s3c64xx_spi_dma_client);
 }
 
 static int s3c64xx_spi_transfer(struct spi_device *spi,
Signature · 1 line
1.7.1
author
#20 lore raw

PATCH v2 12/12 ASoC: Samsung: Update DMA interface

In reply to Kukjin Kim

From: Boojin Kim <[email protected]>

This patch adds to support the DMA PL330 driver that uses DMA generic API. Samsung sound driver uses DMA generic API if architecture supports it. Otherwise, use samsung specific S3C-PL330 API driver to transfer PCM data.

Cc Jassi Brar <[email protected]>
Cc Liam Girdwood <[email protected]>
Cc Mark Brown <[email protected]>
---
 arch/arm/mach-s3c2410/include/mach/dma.h       |    2 +-
 arch/arm/mach-s3c64xx/include/mach/dma.h       |    2 +-
 arch/arm/plat-samsung/include/plat/dma-pl330.h |    2 +-
 sound/soc/samsung/ac97.c                       |    8 +-
 sound/soc/samsung/dma.c                        |  158 ++++++++++--------------
 sound/soc/samsung/dma.h                        |    4 +-
 6 files changed, 79 insertions(+), 97 deletions(-)
arch/arm/mach-s3c2410/include/mach/dma.h +1 -1
index 71a662d..c69d60a 100644
@@ -197,7 +197,7 @@ struct s3c2410_dma_chan {
 
 typedef unsigned long dma_device_t;
 
-static inline bool s3c_dma_has_circular(void)
+static inline bool dma_has_circular(void)
 {
 	return false;
 }
arch/arm/mach-s3c64xx/include/mach/dma.h +1 -1
index 0a5d926..d752e27 100644
@@ -58,7 +58,7 @@ enum dma_ch {
 	DMACH_MAX		/* the end */
 };
 
-static __inline__ bool s3c_dma_has_circular(void)
+static inline bool dma_has_circular(void)
 {
 	return true;
 }
arch/arm/plat-samsung/include/plat/dma-pl330.h +1 -1
index dbc1288..4bd0e49 100644
@@ -100,7 +100,7 @@ struct s3c2410_dma_client {
 	char	*name;
 };
 
-static inline bool s3c_dma_has_circular(void)
+static inline bool dma_has_circular(void)
 {
 	return true;
 }
sound/soc/samsung/ac97.c +6 -2
index f97110e..e09cb9d 100644
@@ -271,7 +271,9 @@ static int s3c_ac97_trigger(struct snd_pcm_substream *substream, int cmd,
 
 	writel(ac_glbctrl, s3c_ac97.regs + S3C_AC97_GLBCTRL);
 
-	s3c2410_dma_ctrl(dma_data->channel, S3C2410_DMAOP_STARTED);
+	if (!dma_data->ops)
+		dma_data->ops = samsung_dma_get_ops();
+	dma_data->ops->started(dma_data->channel);
 
 	return 0;
 }
@@ -317,7 +319,9 @@ static int s3c_ac97_mic_trigger(struct snd_pcm_substream *substream,
 
 	writel(ac_glbctrl, s3c_ac97.regs + S3C_AC97_GLBCTRL);
 
-	s3c2410_dma_ctrl(dma_data->channel, S3C2410_DMAOP_STARTED);
+	if (!dma_data->ops)
+		dma_data->ops = samsung_dma_get_ops();
+	dma_data->ops->started(dma_data->channel);
 
 	return 0;
 }
sound/soc/samsung/dma.c +67 -91

255 lines not on this page · raw message

sound/soc/samsung/dma.h +3 -1
index c506592..7d1ead7 100644
@@ -6,7 +6,7 @@
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
  *
- *  ALSA PCM interface for the Samsung S3C24xx CPU
+ *  ALSA PCM interface for the Samsung SoC
  */
 
 #ifndef _S3C_AUDIO_H
@@ -17,6 +17,8 @@ struct s3c_dma_params {
 	int channel;				/* Channel ID */
 	dma_addr_t dma_addr;
 	int dma_size;			/* Size of the DMA transfer */
+	unsigned ch;
+	struct samsung_dma_ops *ops;
 };
 
 #endif
Signature · 1 line
1.7.1
#21 lore raw

PATCH v2 12/12 ASoC: Samsung: Update DMA interface

arch/arm/mach-s3c2410/include/mach/dma.h struct s3c2410_dma_chan { · line 203

Quoted 5 lines · Kukjin Kim
arch/arm/mach-s3c2410/include/mach/dma.h +1 -1
-static inline bool s3c_dma_has_circular(void)
+static inline bool dma_has_circular(void)
 {
 	return false;
 }

The namespacing here doesn't look great, this is still a Samsung specific internal API.

Otherwise this looks good.

author
#22 lore raw

PATCH v2 12/12 ASoC: Samsung: Update DMA interface

Quoted 12 lines · Mark Brown

arch/arm/mach-s3c2410/include/mach/dma.h struct s3c2410_dma_chan { · line 203

Quoted 5 lines · Kukjin Kim
arch/arm/mach-s3c2410/include/mach/dma.h +1 -1
-static inline bool s3c_dma_has_circular(void)
+static inline bool dma_has_circular(void)
 {
 	return false;
 }

The namespacing here doesn't look great, this is still a Samsung specific internal API.

OK, will keep it.

Quoted 1 line

Otherwise this looks good.

Thanks.

Best regards,
Kgene.
--
Kukjin Kim <[email protected]>, Senior Engineer, SW Solution Development Team, Samsung Electronics Co., Ltd.