All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Abraham <thomas.abraham@linaro.org>
To: devicetree-discuss@lists.ozlabs.org
Cc: grant.likely@secretlab.ca, linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org, kgene.kim@samsung.com,
	vinod.koul@intel.com, patches@linaro.org,
	jassisinghbrar@gmail.com, boojin.kim@samsung.com
Subject: [PATCH 4/6] DMA: PL330: Add device tree support
Date: Fri, 26 Aug 2011 14:10:12 +0530	[thread overview]
Message-ID: <1314348014-2481-5-git-send-email-thomas.abraham@linaro.org> (raw)
In-Reply-To: <1314348014-2481-4-git-send-email-thomas.abraham@linaro.org>

For PL330 dma controllers instantiated from device tree, the channel
lookup is based on phandle of the dma controller and dma request id
specified by the client node. During probe, the private data of each
channel of the controller is set to point to the device node of the
dma controller. The 'chan_id' of the each channel is used as the
dma request id.

Client driver requesting dma channels specify the phandle of the
dma controller and the request id. The pl330 filter function
converts the phandle to the device node pointer and matches that
with channel's private data. If a match is found, the request id
from the client node and the 'chan_id' of the channel is matched.
A channel is found if both the values match.

Signed-off-by: Thomas Abraham <thomas.abraham@linaro.org>
---
 .../devicetree/bindings/dma/arm-pl330.txt          |   42 +++++++++++++
 drivers/dma/pl330.c                                |   63 +++++++++++++++++++-
 2 files changed, 103 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/dma/arm-pl330.txt

diff --git a/Documentation/devicetree/bindings/dma/arm-pl330.txt b/Documentation/devicetree/bindings/dma/arm-pl330.txt
new file mode 100644
index 0000000..46a8307
--- /dev/null
+++ b/Documentation/devicetree/bindings/dma/arm-pl330.txt
@@ -0,0 +1,42 @@
+* ARM PrimeCell PL330 DMA Controller
+
+The ARM PrimeCell PL330 DMA controller can move blocks of memory contents
+between memory and peripherals or memory to memory.
+
+Required properties:
+  - compatible: should one or more of the following
+    - arm,pl330-pdma - For controllers that support mem-to-dev and dev-to-mem
+      transfers.
+    - arm,pl330-mdma - For controllers that support mem-to-mem transfers only.
+    - arm,primecell - should be included for all pl330 dma controller nodes.
+
+  - reg: physical base address of the controller and length of memory mapped
+    region.
+
+  - interrupts: interrupt number to the cpu.
+
+  - arm,primecell-periphid: should be 0x00041330.
+
+  - arm,pl330-peri-reqs: number of actual peripheral requests connected to the
+    dma controller. Maximum value is 32.
+
+Example: (from Samsung's Exynos4 processor dtsi file)
+
+	pdma0: pdma@12680000 {
+		compatible = "arm,pl330-pdma", "arm,primecell";
+		reg = <0x12680000 0x1000>;
+		interrupts = <99>;
+		arm,primecell-periphid = <0x00041330>;
+		arm,pl330-peri-reqs = <30>;
+	};
+
+Client drivers (device nodes requiring dma transfers from dev-to-mem or
+mem-to-dev) should specify the DMA channel numbers using a two-value pair
+as shown below.
+
+  [property name]  = <[phandle of the dma controller] [dma request id]>;
+
+      where 'dma request id' is the dma request number which is connected
+      to the client controller.
+
+  Example:  tx-dma-channel = <&pdma0 12>;
diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 9732995..984dc18 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -19,6 +19,7 @@
 #include <linux/amba/pl330.h>
 #include <linux/pm_runtime.h>
 #include <linux/scatterlist.h>
+#include <linux/of.h>
 
 #define NR_DEFAULT_DESC	16
 
@@ -277,6 +278,20 @@ bool pl330_filter(struct dma_chan *chan, void *param)
 	if (chan->device->dev->driver != &pl330_driver.drv)
 		return false;
 
+#ifdef CONFIG_OF
+	if (chan->device->dev->of_node) {
+		const __be32 *prop_value;
+		phandle phandle;
+		struct device_node *node;
+
+		prop_value = ((struct property *)param)->value;
+		phandle = be32_to_cpup(prop_value++);
+		node = of_find_node_by_phandle(phandle);
+		return ((chan->private == node) &&
+				(chan->chan_id == be32_to_cpup(prop_value)));
+	}
+#endif
+
 	peri_id = chan->private;
 	return *peri_id == (unsigned)param;
 }
@@ -777,6 +792,40 @@ static irqreturn_t pl330_irq_handler(int irq, void *data)
 		return IRQ_NONE;
 }
 
+#ifdef CONFIG_OF
+static struct dma_pl330_platdata *pl330_parse_dt(struct device *dev)
+{
+	struct dma_pl330_platdata *pdat;
+	const void *value;
+
+	pdat = devm_kzalloc(dev, sizeof(*pdat), GFP_KERNEL);
+	if (!pdat)
+		return NULL;
+
+	value = of_get_property(dev->of_node, "arm,pl330-peri-reqs", NULL);
+	if (value)
+		pdat->nr_valid_peri = be32_to_cpup(value);
+
+	if (of_device_is_compatible(dev->of_node, "arm,pl330-pdma")) {
+		dma_cap_set(DMA_SLAVE, pdat->cap_mask);
+		dma_cap_set(DMA_CYCLIC, pdat->cap_mask);
+	} else if (of_device_is_compatible(dev->of_node, "arm,pl330-mdma")) {
+		dma_cap_set(DMA_MEMCPY, pdat->cap_mask);
+	} else if (of_device_is_compatible(dev->of_node, "arm,primecell")) {
+		dma_cap_set(DMA_SLAVE, pdat->cap_mask);
+		dma_cap_set(DMA_CYCLIC, pdat->cap_mask);
+		dma_cap_set(DMA_MEMCPY, pdat->cap_mask);
+	}
+
+	return pdat;
+}
+#else
+static struct dma_pl330_platdata *pl330_parse_dt(struct device *dev)
+{
+	return NULL;
+}
+#endif
+
 static int __devinit
 pl330_probe(struct amba_device *adev, const struct amba_id *id)
 {
@@ -789,7 +838,13 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 	int i, ret, irq;
 	int num_chan;
 
-	pdat = adev->dev.platform_data;
+	if (adev->dev.of_node) {
+		pdat = pl330_parse_dt(&adev->dev);
+		if (!pdat)
+			return -ENOMEM;
+	} else {
+		pdat = adev->dev.platform_data;
+	}
 
 	/* Allocate a new DMAC and its Channels */
 	pdmac = kzalloc(sizeof(*pdmac), GFP_KERNEL);
@@ -862,7 +917,11 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 
 	for (i = 0; i < num_chan; i++) {
 		pch = &pdmac->peripherals[i];
-		pch->chan.private = pdat ? &pdat->peri_id[i] : NULL;
+		if (!adev->dev.of_node)
+			pch->chan.private = pdat ? &pdat->peri_id[i] : NULL;
+		else
+			pch->chan.private = adev->dev.of_node;
+
 		INIT_LIST_HEAD(&pch->work_list);
 		spin_lock_init(&pch->lock);
 		pch->pl330_chid = NULL;
-- 
1.6.6.rc2

WARNING: multiple messages have this Message-ID (diff)
From: thomas.abraham@linaro.org (Thomas Abraham)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 4/6] DMA: PL330: Add device tree support
Date: Fri, 26 Aug 2011 14:10:12 +0530	[thread overview]
Message-ID: <1314348014-2481-5-git-send-email-thomas.abraham@linaro.org> (raw)
In-Reply-To: <1314348014-2481-4-git-send-email-thomas.abraham@linaro.org>

For PL330 dma controllers instantiated from device tree, the channel
lookup is based on phandle of the dma controller and dma request id
specified by the client node. During probe, the private data of each
channel of the controller is set to point to the device node of the
dma controller. The 'chan_id' of the each channel is used as the
dma request id.

Client driver requesting dma channels specify the phandle of the
dma controller and the request id. The pl330 filter function
converts the phandle to the device node pointer and matches that
with channel's private data. If a match is found, the request id
from the client node and the 'chan_id' of the channel is matched.
A channel is found if both the values match.

Signed-off-by: Thomas Abraham <thomas.abraham@linaro.org>
---
 .../devicetree/bindings/dma/arm-pl330.txt          |   42 +++++++++++++
 drivers/dma/pl330.c                                |   63 +++++++++++++++++++-
 2 files changed, 103 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/dma/arm-pl330.txt

diff --git a/Documentation/devicetree/bindings/dma/arm-pl330.txt b/Documentation/devicetree/bindings/dma/arm-pl330.txt
new file mode 100644
index 0000000..46a8307
--- /dev/null
+++ b/Documentation/devicetree/bindings/dma/arm-pl330.txt
@@ -0,0 +1,42 @@
+* ARM PrimeCell PL330 DMA Controller
+
+The ARM PrimeCell PL330 DMA controller can move blocks of memory contents
+between memory and peripherals or memory to memory.
+
+Required properties:
+  - compatible: should one or more of the following
+    - arm,pl330-pdma - For controllers that support mem-to-dev and dev-to-mem
+      transfers.
+    - arm,pl330-mdma - For controllers that support mem-to-mem transfers only.
+    - arm,primecell - should be included for all pl330 dma controller nodes.
+
+  - reg: physical base address of the controller and length of memory mapped
+    region.
+
+  - interrupts: interrupt number to the cpu.
+
+  - arm,primecell-periphid: should be 0x00041330.
+
+  - arm,pl330-peri-reqs: number of actual peripheral requests connected to the
+    dma controller. Maximum value is 32.
+
+Example: (from Samsung's Exynos4 processor dtsi file)
+
+	pdma0: pdma at 12680000 {
+		compatible = "arm,pl330-pdma", "arm,primecell";
+		reg = <0x12680000 0x1000>;
+		interrupts = <99>;
+		arm,primecell-periphid = <0x00041330>;
+		arm,pl330-peri-reqs = <30>;
+	};
+
+Client drivers (device nodes requiring dma transfers from dev-to-mem or
+mem-to-dev) should specify the DMA channel numbers using a two-value pair
+as shown below.
+
+  [property name]  = <[phandle of the dma controller] [dma request id]>;
+
+      where 'dma request id' is the dma request number which is connected
+      to the client controller.
+
+  Example:  tx-dma-channel = <&pdma0 12>;
diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 9732995..984dc18 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -19,6 +19,7 @@
 #include <linux/amba/pl330.h>
 #include <linux/pm_runtime.h>
 #include <linux/scatterlist.h>
+#include <linux/of.h>
 
 #define NR_DEFAULT_DESC	16
 
@@ -277,6 +278,20 @@ bool pl330_filter(struct dma_chan *chan, void *param)
 	if (chan->device->dev->driver != &pl330_driver.drv)
 		return false;
 
+#ifdef CONFIG_OF
+	if (chan->device->dev->of_node) {
+		const __be32 *prop_value;
+		phandle phandle;
+		struct device_node *node;
+
+		prop_value = ((struct property *)param)->value;
+		phandle = be32_to_cpup(prop_value++);
+		node = of_find_node_by_phandle(phandle);
+		return ((chan->private == node) &&
+				(chan->chan_id == be32_to_cpup(prop_value)));
+	}
+#endif
+
 	peri_id = chan->private;
 	return *peri_id == (unsigned)param;
 }
@@ -777,6 +792,40 @@ static irqreturn_t pl330_irq_handler(int irq, void *data)
 		return IRQ_NONE;
 }
 
+#ifdef CONFIG_OF
+static struct dma_pl330_platdata *pl330_parse_dt(struct device *dev)
+{
+	struct dma_pl330_platdata *pdat;
+	const void *value;
+
+	pdat = devm_kzalloc(dev, sizeof(*pdat), GFP_KERNEL);
+	if (!pdat)
+		return NULL;
+
+	value = of_get_property(dev->of_node, "arm,pl330-peri-reqs", NULL);
+	if (value)
+		pdat->nr_valid_peri = be32_to_cpup(value);
+
+	if (of_device_is_compatible(dev->of_node, "arm,pl330-pdma")) {
+		dma_cap_set(DMA_SLAVE, pdat->cap_mask);
+		dma_cap_set(DMA_CYCLIC, pdat->cap_mask);
+	} else if (of_device_is_compatible(dev->of_node, "arm,pl330-mdma")) {
+		dma_cap_set(DMA_MEMCPY, pdat->cap_mask);
+	} else if (of_device_is_compatible(dev->of_node, "arm,primecell")) {
+		dma_cap_set(DMA_SLAVE, pdat->cap_mask);
+		dma_cap_set(DMA_CYCLIC, pdat->cap_mask);
+		dma_cap_set(DMA_MEMCPY, pdat->cap_mask);
+	}
+
+	return pdat;
+}
+#else
+static struct dma_pl330_platdata *pl330_parse_dt(struct device *dev)
+{
+	return NULL;
+}
+#endif
+
 static int __devinit
 pl330_probe(struct amba_device *adev, const struct amba_id *id)
 {
@@ -789,7 +838,13 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 	int i, ret, irq;
 	int num_chan;
 
-	pdat = adev->dev.platform_data;
+	if (adev->dev.of_node) {
+		pdat = pl330_parse_dt(&adev->dev);
+		if (!pdat)
+			return -ENOMEM;
+	} else {
+		pdat = adev->dev.platform_data;
+	}
 
 	/* Allocate a new DMAC and its Channels */
 	pdmac = kzalloc(sizeof(*pdmac), GFP_KERNEL);
@@ -862,7 +917,11 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 
 	for (i = 0; i < num_chan; i++) {
 		pch = &pdmac->peripherals[i];
-		pch->chan.private = pdat ? &pdat->peri_id[i] : NULL;
+		if (!adev->dev.of_node)
+			pch->chan.private = pdat ? &pdat->peri_id[i] : NULL;
+		else
+			pch->chan.private = adev->dev.of_node;
+
 		INIT_LIST_HEAD(&pch->work_list);
 		spin_lock_init(&pch->lock);
 		pch->pl330_chid = NULL;
-- 
1.6.6.rc2

  reply	other threads:[~2011-08-26  8:40 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-26  8:40 [PATCH 0/6] Add device tree support for PL330 dma controller driver Thomas Abraham
2011-08-26  8:40 ` Thomas Abraham
2011-08-26  8:40 ` [PATCH 1/6] DMA: PL330: move filter function into driver Thomas Abraham
2011-08-26  8:40   ` Thomas Abraham
2011-08-26  8:40   ` [PATCH 2/6] DMA: PL330: Infer transfer direction from transfer request instead of platform data Thomas Abraham
2011-08-26  8:40     ` Thomas Abraham
2011-08-26  8:40     ` [PATCH 3/6] ARM: EXYNOS4: Modify platform data for pl330 driver Thomas Abraham
2011-08-26  8:40       ` Thomas Abraham
2011-08-26  8:40       ` Thomas Abraham [this message]
2011-08-26  8:40         ` [PATCH 4/6] DMA: PL330: Add device tree support Thomas Abraham
2011-08-26  8:40         ` [PATCH 5/6] ARM: SAMSUNG: Add device tree support for pl330 dma engine wrappers Thomas Abraham
2011-08-26  8:40           ` Thomas Abraham
2011-08-26  8:40           ` [PATCH 6/6] ARM: EXYNOS4: Limit usage of pl330 device instance to non-dt build Thomas Abraham
2011-08-26  8:40             ` Thomas Abraham
2011-08-26 13:16         ` [PATCH 4/6] DMA: PL330: Add device tree support Rob Herring
2011-08-26 13:16           ` Rob Herring
2011-08-26 14:23           ` Russell King - ARM Linux
2011-08-26 14:23             ` Russell King - ARM Linux
2011-08-30 12:21             ` Thomas Abraham
2011-08-30 12:21               ` Thomas Abraham
     [not found]           ` <4E579C9B.7030807-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-08-30 12:18             ` Thomas Abraham
2011-08-30 13:19               ` Rob Herring
2011-08-30 13:19                 ` Rob Herring
2011-08-31  6:46                 ` Thomas Abraham
2011-08-31  6:46                   ` Thomas Abraham
2011-08-31 12:51                   ` Rob Herring
2011-08-31 12:51                     ` Rob Herring
2011-08-31 15:46                     ` Thomas Abraham
2011-08-31 15:46                       ` Thomas Abraham
2011-08-31 16:04                       ` Rob Herring
2011-08-31 16:04                         ` Rob Herring
2011-09-01  9:03                         ` Thomas Abraham
2011-09-01  9:03                           ` Thomas Abraham
2011-08-30 13:09           ` Thomas Abraham
2011-08-30 13:09             ` Thomas Abraham
2011-08-29 17:29 ` [PATCH 0/6] Add device tree support for PL330 dma controller driver Vinod Koul
2011-08-29 17:29   ` Vinod Koul
2011-08-30 12:28   ` Thomas Abraham
2011-08-30 12:28     ` Thomas Abraham
2011-09-05 13:14     ` Vinod Koul
2011-09-05 13:14       ` Vinod Koul
2011-09-05  5:17   ` Kukjin Kim
2011-09-05  5:17     ` Kukjin Kim
2011-09-05 10:16     ` Thomas Abraham
2011-09-05 10:16       ` Thomas Abraham
2011-09-19  6:28 [PATCH v4 " Thomas Abraham
2011-09-19  6:28 ` [PATCH 1/6] DMA: PL330: move filter function into driver Thomas Abraham
2011-09-19  6:28   ` [PATCH 2/6] DMA: PL330: Infer transfer direction from transfer request instead of platform data Thomas Abraham
2011-09-19  6:28     ` [PATCH 3/6] ARM: EXYNOS4: Modify platform data for pl330 driver Thomas Abraham
2011-09-19  6:29       ` [PATCH 4/6] DMA: PL330: Add device tree support Thomas Abraham
2011-09-19  6:29         ` Thomas Abraham

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=1314348014-2481-5-git-send-email-thomas.abraham@linaro.org \
    --to=thomas.abraham@linaro.org \
    --cc=boojin.kim@samsung.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=jassisinghbrar@gmail.com \
    --cc=kgene.kim@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=patches@linaro.org \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.