From patchwork Thu Sep 1 09:04:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: thomas.abraham@linaro.org X-Patchwork-Id: 3825 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id CF21623F22 for ; Thu, 1 Sep 2011 09:05:04 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id C45D7A18587 for ; Thu, 1 Sep 2011 09:05:04 +0000 (UTC) Received: by mail-fx0-f52.google.com with SMTP id 18so721928fxd.11 for ; Thu, 01 Sep 2011 02:05:04 -0700 (PDT) Received: by 10.223.4.133 with SMTP id 5mr1405717far.81.1314867904683; Thu, 01 Sep 2011 02:05:04 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.11.8 with SMTP id m8cs44981lab; Thu, 1 Sep 2011 02:05:04 -0700 (PDT) Received: by 10.236.77.131 with SMTP id d3mr7494111yhe.63.1314867903083; Thu, 01 Sep 2011 02:05:03 -0700 (PDT) Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by mx.google.com with ESMTP id u46si1133230yhm.52.2011.09.01.02.05.02; Thu, 01 Sep 2011 02:05:03 -0700 (PDT) Received-SPF: neutral (google.com: 203.254.224.24 is neither permitted nor denied by best guess record for domain of thomas.abraham@linaro.org) client-ip=203.254.224.24; Authentication-Results: mx.google.com; spf=neutral (google.com: 203.254.224.24 is neither permitted nor denied by best guess record for domain of thomas.abraham@linaro.org) smtp.mail=thomas.abraham@linaro.org Received: from epcpsbgm2.samsung.com (mailout1.samsung.com [203.254.224.24]) by mailout1.samsung.com (Oracle Communications Messaging Exchange Server 7u4-19.01 64bit (built Sep 7 2010)) with ESMTP id <0LQU005YU6K9UO50@mailout1.samsung.com> for patches@linaro.org; Thu, 01 Sep 2011 18:05:02 +0900 (KST) X-AuditID: cbfee61b-b7b7fae000005864-fc-4e5f4abec83b Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (MMPCPMTA) with SMTP id 25.1B.22628.EBA4F5E4; Thu, 01 Sep 2011 18:05:02 +0900 (KST) Received: from localhost.localdomain ([107.108.73.37]) by mmp2.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0LQU001MY6JYD0@mmp2.samsung.com> for patches@linaro.org; Thu, 01 Sep 2011 18:05:02 +0900 (KST) Date: Thu, 01 Sep 2011 14:34:40 +0530 From: Thomas Abraham Subject: [PATCH v2 4/6] DMA: PL330: Add device tree support In-reply-to: <1314867882-11755-4-git-send-email-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, robherring2@gmail.com, vinod.koul@intel.com, patches@linaro.org, jassisinghbrar@gmail.com, boojin.kim@samsung.com Message-id: <1314867882-11755-5-git-send-email-thomas.abraham@linaro.org> X-Mailer: git-send-email 1.6.6.rc2 Content-transfer-encoding: 7BIT References: <1314867882-11755-1-git-send-email-thomas.abraham@linaro.org> <1314867882-11755-2-git-send-email-thomas.abraham@linaro.org> <1314867882-11755-3-git-send-email-thomas.abraham@linaro.org> <1314867882-11755-4-git-send-email-thomas.abraham@linaro.org> X-Brightmail-Tracker: AAAAAA== 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. Cc: Jassi Brar Cc: Boojin Kim Signed-off-by: Thomas Abraham Reviewed-by: Rob Herring --- .../devicetree/bindings/dma/arm-pl330.txt | 29 ++++++++++++++++ drivers/dma/pl330.c | 35 +++++++++++++++++--- 2 files changed, 59 insertions(+), 5 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..69e6c02 --- /dev/null +++ b/Documentation/devicetree/bindings/dma/arm-pl330.txt @@ -0,0 +1,29 @@ +* 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 include both "arm,pl330" and "arm,primecell". + - reg: physical base address of the controller and length of memory mapped + region. + - interrupts: interrupt number to the cpu. + +Example: (from Samsung's Exynos4 processor dtsi file) + + pdma0: pdma@12680000 { + compatible = "arm,pl330", "arm,primecell"; + reg = <0x12680000 0x1000>; + interrupts = <99>; + }; + +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..0c55de4 100644 --- a/drivers/dma/pl330.c +++ b/drivers/dma/pl330.c @@ -19,6 +19,7 @@ #include #include #include +#include #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; } @@ -857,12 +872,17 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id) INIT_LIST_HEAD(&pd->channels); /* Initialize channel parameters */ - num_chan = max(pdat ? pdat->nr_valid_peri : 0, (u8)pi->pcfg.num_chan); + num_chan = max(pdat ? pdat->nr_valid_peri : (u8)pi->pcfg.num_peri, + (u8)pi->pcfg.num_chan); pdmac->peripherals = kzalloc(num_chan * sizeof(*pch), GFP_KERNEL); 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; @@ -876,11 +896,16 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id) } pd->dev = &adev->dev; - if (pdat) + if (pdat) { pd->cap_mask = pdat->cap_mask; - else + } else { dma_cap_set(DMA_MEMCPY, pd->cap_mask); - + if (pi->pcfg.num_peri) { + dma_cap_set(DMA_SLAVE, pd->cap_mask); + dma_cap_set(DMA_CYCLIC, pd->cap_mask); + } + } + 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;