From patchwork Wed Feb 27 00:44:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou Yang X-Patchwork-Id: 2190381 Return-Path: X-Original-To: patchwork-spi-devel-general@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by patchwork2.kernel.org (Postfix) with ESMTP id 5BC1DDF215 for ; Wed, 27 Feb 2013 00:48:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1UAVC3-0005IB-Kq; Wed, 27 Feb 2013 00:48:23 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1UAVC2-0005HP-Dz for spi-devel-general@lists.sourceforge.net; Wed, 27 Feb 2013 00:48:22 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of atmel.com designates 192.199.1.245 as permitted sender) client-ip=192.199.1.245; envelope-from=wenyou.yang@atmel.com; helo=DVREDG01.corp.atmel.com; Received: from nasmtp01.atmel.com ([192.199.1.245] helo=DVREDG01.corp.atmel.com) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1UAVC1-0007Xh-7R for spi-devel-general@lists.sourceforge.net; Wed, 27 Feb 2013 00:48:22 +0000 Received: from apsmtp01.atmel.com (10.168.254.31) by DVREDG01.corp.atmel.com (10.42.103.30) with Microsoft SMTP Server (TLS) id 14.2.318.1; Tue, 26 Feb 2013 17:47:29 -0700 Received: from shaarm01.corp.atmel.com (10.168.254.13) by apsmtp01.atmel.com (10.168.254.31) with Microsoft SMTP Server id 14.2.318.1; Wed, 27 Feb 2013 08:55:03 +0800 From: Wenyou Yang To: Subject: [PATCH Resend v5 09/16] spi/spi-atmel: fix spi-atmel driver to adapt to slave_config changes Date: Wed, 27 Feb 2013 08:44:55 +0800 Message-ID: <1361925895-12375-1-git-send-email-wenyou.yang@atmel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1361925297-11854-1-git-send-email-wenyou.yang@atmel.com> References: <1361925297-11854-1-git-send-email-wenyou.yang@atmel.com> MIME-Version: 1.0 X-Spam-Score: -2.2 (--) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1UAVC1-0007Xh-7R Cc: richard.genoud@gmail.com, JM.Lin@atmel.com, nicolas.ferre@atmel.com, linux-kernel@vger.kernel.org, wenyou.yang@atmel.com, spi-devel-general@lists.sourceforge.net, plagnioj@jcrosoft.com X-BeenThere: spi-devel-general@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux SPI core/device drivers discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: spi-devel-general-bounces@lists.sourceforge.net From: Richard Genoud This is the following of the patch e2b35f3dbfc080f15b72834d08f04f0269dbe9be Signed-off-by: Richard Genoud [wenyou.yang@atmel.com: BUG: dmaengine mode when enable both spi0 and spi1, spi0 doesn't work] [wenyou.yang@atmel.com: submit the patch] Signed-off-by: Wenyou Yang Cc: spi-devel-general@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org --- drivers/spi/spi-atmel.c | 61 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index d77dd53..d8af7d0 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -388,6 +388,37 @@ static inline int atmel_spi_xfer_can_be_chained(struct spi_transfer *xfer) return xfer->delay_usecs == 0 && !xfer->cs_change; } +static int atmel_spi_dma_slave_config(struct atmel_spi *as, + struct dma_slave_config *slave_config) +{ + int err = 0; + + slave_config->dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; + slave_config->src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; + + slave_config->dst_addr = (dma_addr_t)as->phybase + SPI_TDR; + slave_config->src_addr = (dma_addr_t)as->phybase + SPI_RDR; + slave_config->src_maxburst = 1; + slave_config->dst_maxburst = 1; + slave_config->device_fc = false; + + slave_config->direction = DMA_MEM_TO_DEV; + if (dmaengine_slave_config(as->dma.chan_tx, slave_config)) { + dev_err(&as->pdev->dev, + "failed to configure tx dma channel\n"); + err = -EINVAL; + } + + slave_config->direction = DMA_DEV_TO_MEM; + if (dmaengine_slave_config(as->dma.chan_rx, slave_config)) { + dev_err(&as->pdev->dev, + "failed to configure rx dma channel\n"); + err = -EINVAL; + } + + return err; +} + static bool filter(struct dma_chan *chan, void *slave) { struct at_dma_slave *sl = slave; @@ -403,14 +434,12 @@ static bool filter(struct dma_chan *chan, void *slave) static int atmel_spi_configure_dma(struct atmel_spi *as) { struct at_dma_slave *sdata = &as->dma.dma_slave; + struct dma_slave_config slave_config; + int err; if (sdata && sdata->dma_dev) { dma_cap_mask_t mask; - /* setup DMA addresses */ - sdata->rx_reg = (dma_addr_t)as->phybase + SPI_RDR; - sdata->tx_reg = (dma_addr_t)as->phybase + SPI_TDR; - /* Try to grab two DMA channels */ dma_cap_zero(mask); dma_cap_set(DMA_SLAVE, mask); @@ -420,21 +449,27 @@ static int atmel_spi_configure_dma(struct atmel_spi *as) dma_request_channel(mask, filter, sdata); } if (!as->dma.chan_rx || !as->dma.chan_tx) { - if (as->dma.chan_rx) - dma_release_channel(as->dma.chan_rx); - if (as->dma.chan_tx) - dma_release_channel(as->dma.chan_tx); dev_err(&as->pdev->dev, "DMA channel not available, unable to use SPI\n"); - return -EBUSY; + err = -EBUSY; + goto error; } + err = atmel_spi_dma_slave_config(as, &slave_config); + if (err) + goto error; + dev_info(&as->pdev->dev, "Using %s (tx) and %s (rx) for DMA transfers\n", dma_chan_name(as->dma.chan_tx), dma_chan_name(as->dma.chan_rx)); - return 0; +error: + if (as->dma.chan_rx) + dma_release_channel(as->dma.chan_rx); + if (as->dma.chan_tx) + dma_release_channel(as->dma.chan_tx); + return err; } static void atmel_spi_stop_dma(struct atmel_spi *as) @@ -511,6 +546,7 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, struct dma_chan *txchan = as->dma.chan_tx; struct dma_async_tx_descriptor *rxdesc; struct dma_async_tx_descriptor *txdesc; + struct dma_slave_config slave_config; dma_cookie_t cookie; u32 len = *plen; @@ -549,6 +585,10 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, *plen = len; + if (atmel_spi_dma_slave_config(as, &slave_config)) + goto err_exit; + + /* Send both scatterlists */ rxdesc = rxchan->device->device_prep_slave_sg(rxchan, &as->dma.sgrx, @@ -597,6 +637,7 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, err_dma: spi_writel(as, IDR, SPI_BIT(OVRES)); atmel_spi_stop_dma(as); +err_exit: atmel_spi_lock(as); return -ENOMEM; }