From patchwork Mon Nov 12 08:52:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou Yang X-Patchwork-Id: 1727041 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 24C783FCF7 for ; Mon, 12 Nov 2012 09:01:47 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TXprS-00055N-4C; Mon, 12 Nov 2012 08:59:19 +0000 Received: from newsmtp5.atmel.com ([204.2.163.5] helo=sjogate2.atmel.com) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TXpok-0003dc-Bd for linux-arm-kernel@lists.infradead.org; Mon, 12 Nov 2012 08:56:32 +0000 Received: from penbh01.corp.atmel.com ([10.168.5.31]) by sjogate2.atmel.com (8.13.6/8.13.6) with ESMTP id qAC8ooNg029499; Mon, 12 Nov 2012 00:51:19 -0800 (PST) Received: from penmb01.corp.atmel.com ([10.168.5.33]) by penbh01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 12 Nov 2012 16:56:23 +0800 Received: from shaarm01.corp.atmel.com ([10.217.6.34]) by penmb01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 12 Nov 2012 16:56:22 +0800 From: Wenyou Yang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 10/17] spi/atmel_spi: correct 16 bits transfer with DMA Date: Mon, 12 Nov 2012 16:52:30 +0800 Message-Id: <1352710357-3265-11-git-send-email-wenyou.yang@atmel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1352710357-3265-1-git-send-email-wenyou.yang@atmel.com> References: <1352710357-3265-1-git-send-email-wenyou.yang@atmel.com> X-OriginalArrivalTime: 12 Nov 2012 08:56:23.0066 (UTC) FILETIME=[971EA7A0:01CDC0B3] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121112_035630_660401_79DCC100 X-CRM114-Status: GOOD ( 13.52 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.7 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: Richard Genoud , JM.Lin@atmel.com, nicolas.ferre@atmel.com, wenyou.yang@atmel.com, grant.likely@secretlab.ca, spi-devel-general@lists.sourceforge.net 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 From: Richard Genoud Signed-off-by: Richard Genoud Cc: grant.likely@secretlab.ca Cc: spi-devel-general@lists.sourceforge.net --- drivers/spi/spi-atmel.c | 53 +++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index 0007a53..7a3613d 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -249,6 +249,8 @@ struct atmel_spi_device { #define BUFFER_SIZE PAGE_SIZE #define INVALID_DMA_ADDRESS 0xffffffff +static struct dma_slave_config slave_config; + /* * Version 2 of the SPI controller has * - CR.LASTXFER @@ -406,17 +408,41 @@ static bool filter(struct dma_chan *chan, void *slave) } } +static int atmel_spi_set_dma_xfer_width(struct atmel_spi *as, u8 bits_per_word) +{ + int err = 0; + + if (bits_per_word > 8) { + slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; + slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; + } else { + slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; + slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; + } + + slave_config.direction = DMA_TO_DEVICE; + 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_FROM_DEVICE; + 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 int __devinit atmel_spi_configure_dma(struct atmel_spi *as) { struct at_dma_slave *sdata = (struct at_dma_slave *)&as->data.dma_slave; - struct dma_slave_config slave_config; int err; - memset(&slave_config, 0, sizeof(slave_config)); slave_config.dst_addr = (dma_addr_t)as->phybase + SPI_TDR; slave_config.src_addr = (dma_addr_t)as->phybase + SPI_RDR; - slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; - slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; slave_config.src_maxburst = 1; slave_config.dst_maxburst = 1; slave_config.device_fc = false; @@ -439,21 +465,9 @@ static int __devinit atmel_spi_configure_dma(struct atmel_spi *as) goto error; } - slave_config.direction = DMA_TO_DEVICE; - if (dmaengine_slave_config(as->dma.chan_tx, &slave_config)) { - dev_err(&as->pdev->dev, - "failed to configure tx dma channel\n"); - err = -EINVAL; + err = atmel_spi_set_dma_xfer_width(as, 8); + if (err) goto error; - } - - slave_config.direction = DMA_FROM_DEVICE; - if (dmaengine_slave_config(as->dma.chan_rx, &slave_config)) { - dev_err(&as->pdev->dev, - "failed to configure rx dma channel\n"); - err = -EINVAL; - goto error; - } dev_info(&as->pdev->dev, "Using %s (tx) and " \ " %s (rx) for DMA transfers\n", @@ -575,6 +589,9 @@ static int atmel_spi_next_xfer_dma(struct spi_master *master, memset(as->buffer, 0, xfer->len); } + if (atmel_spi_set_dma_xfer_width(as, xfer->bits_per_word)) + goto err_dma; + /* Send both scatterlists */ rxdesc = rxchan->device->device_prep_slave_sg(rxchan, &as->dma.sgrx,