From patchwork Wed Sep 26 06:51:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou Yang X-Patchwork-Id: 1507891 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 3BB263FDAE for ; Wed, 26 Sep 2012 06:56:49 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TGlWK-0000QU-Ne; Wed, 26 Sep 2012 06:54:56 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TGlVM-0008UX-8p for linux-arm-kernel@merlin.infradead.org; Wed, 26 Sep 2012 06:53:56 +0000 Received: from newsmtp5.atmel.com ([204.2.163.5] helo=sjogate2.atmel.com) by casper.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TGlVJ-00043g-So for linux-arm-kernel@lists.infradead.org; Wed, 26 Sep 2012 06:53:55 +0000 Received: from penbh01.corp.atmel.com ([10.168.5.31]) by sjogate2.atmel.com (8.13.6/8.13.6) with ESMTP id q8Q6meNi011239 for ; Tue, 25 Sep 2012 23:48:55 -0700 (PDT) Received: from penmb01.corp.atmel.com ([10.168.5.33]) by penbh01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 26 Sep 2012 14:52:27 +0800 Received: from shaarm01.corp.atmel.com ([10.217.6.34]) by penmb01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 26 Sep 2012 14:52:26 +0800 From: Wenyou Yang To: nicolas.ferre@atmel.com Subject: [PATCH 6/6] spi: atmel: add dt property for DMA configuration for sam9x5 and sam9n12 Date: Wed, 26 Sep 2012 14:51:01 +0800 Message-Id: <1348642261-27554-7-git-send-email-wenyou.yang@atmel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1348642261-27554-1-git-send-email-wenyou.yang@atmel.com> References: <1348642261-27554-1-git-send-email-wenyou.yang@atmel.com> X-OriginalArrivalTime: 26 Sep 2012 06:52:27.0450 (UTC) FILETIME=[7DBB71A0:01CD9BB3] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20120926_075354_321877_E11BB09F X-CRM114-Status: GOOD ( 12.85 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on casper.infradead.org summary: Content analysis details: (-2.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.8 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-arm-kernel@lists.infradead.org, Wenyou Yang X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Signed-off-by: Wenyou Yang --- arch/arm/boot/dts/at91sam9n12.dtsi | 2 ++ arch/arm/boot/dts/at91sam9x5.dtsi | 4 +++ drivers/spi/spi-atmel.c | 55 +++++++++++++++++++++++++++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/arch/arm/boot/dts/at91sam9n12.dtsi b/arch/arm/boot/dts/at91sam9n12.dtsi index c6868a2..b51f94d 100644 --- a/arch/arm/boot/dts/at91sam9n12.dtsi +++ b/arch/arm/boot/dts/at91sam9n12.dtsi @@ -98,6 +98,7 @@ compatible = "atmel,at91sam9g45-dma"; reg = <0xffffec00 0x200>; interrupts = <20 4 0>; + #dma-cells = <1>; }; pioA: gpio@fffff400 { @@ -197,6 +198,7 @@ has_dma_support = <1>; has_pdc_support = <0>; is_ver2 = <1>; + dma = <&dma 0x10002212>; status = "disabled"; }; diff --git a/arch/arm/boot/dts/at91sam9x5.dtsi b/arch/arm/boot/dts/at91sam9x5.dtsi index f124473..ee46cb7 100644 --- a/arch/arm/boot/dts/at91sam9x5.dtsi +++ b/arch/arm/boot/dts/at91sam9x5.dtsi @@ -100,12 +100,14 @@ compatible = "atmel,at91sam9g45-dma"; reg = <0xffffec00 0x200>; interrupts = <20 4 0>; + #dma-cells = <1>; }; dma1: dma-controller@ffffee00 { compatible = "atmel,at91sam9g45-dma"; reg = <0xffffee00 0x200>; interrupts = <21 4 0>; + #dma-cells = <1>; }; pioA: gpio@fffff400 { @@ -248,6 +250,7 @@ has_dma_support = <1>; has_pdc_support = <0>; is_ver2 = <1>; + dma = <&dma0 0x10002212>; status = "disabled"; }; @@ -265,6 +268,7 @@ has_dma_support = <1>; has_pdc_support = <0>; is_ver2 = <1>; + dma = <&dma1 0x10002212>; status = "disabled"; }; }; diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index 9930438..ad19423 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -1436,6 +1436,57 @@ static void atmel_spi_cleanup(struct spi_device *spi) kfree(asd); } +static int at91_spi_of_init(struct device_node *np, + struct at_dma_slave *atslave) +{ + struct of_phandle_args dma_spec; + struct device_node *dmac_np; + struct platform_device *dmac_pdev; + const __be32 *nbcells; + int ret; + + ret = of_parse_phandle_with_args(np, "dma", "#dma-cells", 0, &dma_spec); + if (ret || !dma_spec.np) { + pr_err("%s: can't parse dma property (%d)\n", + np->full_name, ret); + goto err0; + } + dmac_np = dma_spec.np; + + /* check property format */ + nbcells = of_get_property(dmac_np, "#dma-cells", NULL); + if (!nbcells) { + pr_err("%s: #dma-cells property is required\n", np->full_name); + ret = -EINVAL; + goto err1; + } + + if (dma_spec.args_count != be32_to_cpup(nbcells) + || dma_spec.args_count != 1) { + pr_err("%s: wrong #dma-cells for %s\n", + np->full_name, dmac_np->full_name); + ret = -EINVAL; + goto err1; + } + + dmac_pdev = of_find_device_by_node(dmac_np); + if (!dmac_pdev) { + pr_err("%s: unable to find pdev from DMA controller\n", + dmac_np->full_name); + ret = -EINVAL; + goto err1; + } + + atslave->dma_dev = &dmac_pdev->dev; + atslave->cfg = dma_spec.args[0]; + +err1: + of_node_put(dma_spec.np); +err0: + pr_debug("%s exited with status %d\n", __func__, ret); + return ret; +} + static int of_get_atmel_spi_data(struct device_node *np, struct atmel_spi *as) { const __be32 *val; @@ -1540,7 +1591,9 @@ static int __devinit atmel_spi_probe(struct platform_device *pdev) goto out_unmap_regs; if (as->data.has_dma_support) { - if (atmel_spi_configure_dma(as) == 0) + if ((at91_spi_of_init(pdev->dev.of_node, + &as->data.dma_slave) == 0) + && (atmel_spi_configure_dma(as) == 0)) as->use_dma = true; } else if (as->data.has_pdc_support) as->use_pdc = true;