From patchwork Tue Apr 17 14:29:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sylwester Nawrocki/Kernel \\(PLT\\) /SRPOL/Staff Engineer/Samsung Electronics" X-Patchwork-Id: 10345267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E1C8B60542 for ; Tue, 17 Apr 2018 14:31:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C362E283F2 for ; Tue, 17 Apr 2018 14:31:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE02E2857F; Tue, 17 Apr 2018 14:31:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29D94285C7 for ; Tue, 17 Apr 2018 14:31:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752120AbeDQObF (ORCPT ); Tue, 17 Apr 2018 10:31:05 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:14002 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752710AbeDQObC (ORCPT ); Tue, 17 Apr 2018 10:31:02 -0400 Received: from epcas2p1.samsung.com (unknown [182.195.41.53]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20180417143101epoutp044df95cb01fb138f1d2ae49dd66748150~mP5uL5mcq3244832448epoutp04c; Tue, 17 Apr 2018 14:31:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20180417143101epoutp044df95cb01fb138f1d2ae49dd66748150~mP5uL5mcq3244832448epoutp04c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1523975461; bh=58MYVs6EQtcx4V/Eo+APZJzDFTNpr3PXKp09crxuEEE=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=Zrvlc9/u8mjXrmx3+4qVJjS14KjIeP1r+1IYCm/PsjehH+6vvgRzqGIwRne+DkgSY jFz6X3Wl+AGDhlmuiZPqxrGhDYISN28EKGX4osW6RxM4aWMi9+4/ZdXoPKam03Ofuv nOk6hq0w9EVL36/U45XRD1k38pUb1Nn4gnH+spCM= Received: from epsmges2p3.samsung.com (unknown [182.195.42.71]) by epcas2p3.samsung.com (KnoxPortal) with ESMTP id 20180417143100epcas2p3352dec095dda0610afe00e1a9970f4a2~mP5tkxa5x1318213182epcas2p3K; Tue, 17 Apr 2018 14:31:00 +0000 (GMT) Received: from epcas2p1.samsung.com ( [182.195.41.53]) by epsmges2p3.samsung.com (Symantec Messaging Gateway) with SMTP id 62.16.04072.42506DA5; Tue, 17 Apr 2018 23:31:00 +0900 (KST) Received: from epsmgms2p2new.samsung.com (unknown [182.195.42.143]) by epcas2p2.samsung.com (KnoxPortal) with ESMTP id 20180417143100epcas2p228d05e4de4ce06621635a523241d9824~mP5tRoe1m1177811778epcas2p22; Tue, 17 Apr 2018 14:31:00 +0000 (GMT) X-AuditID: b6c32a47-0fbff70000000fe8-3e-5ad60524ba1e Received: from epmmp1.local.host ( [203.254.227.16]) by epsmgms2p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 9A.5E.03827.42506DA5; Tue, 17 Apr 2018 23:31:00 +0900 (KST) Received: from AMDC3061.digital.local ([106.116.147.40]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P7C0012A2Y8EI10@mmp1.samsung.com>; Tue, 17 Apr 2018 23:31:00 +0900 (KST) From: Sylwester Nawrocki To: broonie@kernel.org Cc: andi@etezian.org, krzk@kernel.org, kgene@kernel.org, linux-spi@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, m.szyprowski@samsung.com, b.zolnierkie@samsung.com, Sylwester Nawrocki Subject: [PATCH v2 8/8] spi: spi-s3c64xx: Allow higher transfer lengths in polling IO mode Date: Tue, 17 Apr 2018 16:29:54 +0200 Message-id: <20180417142954.5507-8-s.nawrocki@samsung.com> X-Mailer: git-send-email 2.14.2 In-reply-to: <20180417142954.5507-1-s.nawrocki@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrAIsWRmVeSWpSXmKPExsWy7bCmqa4K67Uog659chaLfzxnstg4Yz2r xdSHT9gs+h+/ZrY4f34Du8Wmx9dYLWac38dk0fjxJrvF2iN32S0Ov2lndeDyuL7kE7PHplWd bB6bl9R79G1ZxejxeZNcAGsUl01Kak5mWWqRvl0CV8aDRbsZCzYrVKze9oitgXGzZBcjJ4eE gInE/tVXmEBsIYEdjBLL9/N1MXIB2d+B7HUv2LoYOcCKHrQZQdTsZpQ4tccTouYXo8TFFevY QRJsAoYSvUf7GEFsEQExidtzOplBipgFmpgkWh+sYwVJCAvESEzvugfWwCKgKnFywy8WEJtX wEriY8cqFoiL5CXeL7jPCLKYU8BaYn+nCMgcCYElbBLXt/9jhqhxkfjwajobhC0s8er4FnYI W1ri2aqNjBB2tURnWxc7RHMLo8SfaZegGqwlDh+/CHYQswCfRMfhv+wQX/JKdLQJQZR4SHz9 shhqjqPE3aUP2SA+7mOUODTzI8sERqkFjAyrGMVSC4pz01OLjQqM9YoTc4tL89L1kvNzNzGC 41XLfQfjtnM+hxgFOBiVeHgldlyJEmJNLCuuzD3EKMHBrCTCu/MxUIg3JbGyKrUoP76oNCe1 +BCjNAeLkjhvg++ZKCGB9MSS1OzU1ILUIpgsEwenVANjzvnKVbFWV4sXd3z6e9zpys7ErkbZ tbU7Zzdw1BycYS8utvhAU+Q0RkemvFmaOdE3m/f4igW1KPNeLMl0NijnFy9IuLWEfUe0ptoC 8fxFv/8EFx/ObTziPdtw4aW4CQxPxTXy0ydZR6/2DolT9pNkP9WiFb8gVO3Gv5yAw6rHH3qU nsqYfEiJpTgj0VCLuag4EQDy7Py/0wIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOLMWRmVeSWpSXmKPExsVy+t9jAV0V1mtRBicfclgs/vGcyWLjjPWs FlMfPmGz6H/8mtni/PkN7BabHl9jtZhxfh+TRePHm+wWa4/cZbc4/Kad1YHL4/qST8wem1Z1 snlsXlLv0bdlFaPH501yAaxRXDYpqTmZZalF+nYJXBkPFu1mLNisULF62yO2BsbNkl2MHBwS AiYSD9qMuhg5OYQEdjJKTPuo0sXIBWT/YpSYu+MDC0iCTcBQovdoHyOILSIgJnF7TiczSBGz QBOTxPvPn5lBEsICMRLTu+6xg9gsAqoSJzf8AmvmFbCS+NixCsyWEJCXeL/gPiPIYk4Ba4n9 nSIgphBQybJ/ghMYeRYwMqxilEwtKM5Nzy02KjDKSy3XK07MLS7NS9dLzs/dxAgMrm2Htfp3 MD5eEn+IUYCDUYmHV2LHlSgh1sSy4srcQ4wSHMxKIrw7HwOFeFMSK6tSi/Lji0pzUosPMUpz sCiJ8/LnH4sUEkhPLEnNTk0tSC2CyTJxcEo1MDZ8ncr7IMhn16G6YOl7G1w6/z33O3Kz/n1A iI/qqoceP7o/HPRK2LuyqEoghHkCj4/Zs7srN+5bFhbTGfiQ7Zj+r4VyzD/mTv57z2uOn+0V 148MhlITojmMT27NisrpZy3xr5P9miSQYdVQPJF5+S+JqTLnP77advuvo+aZo3p3A6WrH1RU KyixFGckGmoxFxUnAgDjcVNjKgIAAA== X-CMS-MailID: 20180417143100epcas2p228d05e4de4ce06621635a523241d9824 X-Msg-Generator: CA CMS-TYPE: 102P X-CMS-RootMailID: 20180417143100epcas2p228d05e4de4ce06621635a523241d9824 X-RootMTR: 20180417143100epcas2p228d05e4de4ce06621635a523241d9824 References: <20180417142954.5507-1-s.nawrocki@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some variants of the SPI controller have no DMA support, in such case SPI transfers longer than the FIFO length are not currently properly handled by the driver. Fix it by doing multiple transfers in the s3c64xx_spi_transfer_one() function if the SPI transfer length exceeds the FIFO size. Signed-off-by: Sylwester Nawrocki Reviewed-by: Andi Shyti --- drivers/spi/spi-s3c64xx.c | 99 +++++++++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 33 deletions(-) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 27cd8c59eabf..755ab2dc6969 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -635,11 +635,14 @@ static int s3c64xx_spi_transfer_one(struct spi_master *master, { struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); const unsigned int fifo_len = (FIFO_LVL_MASK(sdd) >> 1) + 1; + const void *tx_buf = NULL; + void *rx_buf = NULL; + int target_len = 0, origin_len = 0; + int use_dma = 0; int status; u32 speed; u8 bpw; unsigned long flags; - int use_dma; reinit_completion(&sdd->xfer_completion); @@ -654,47 +657,77 @@ static int s3c64xx_spi_transfer_one(struct spi_master *master, s3c64xx_spi_config(sdd); } - /* Polling method for xfers not bigger than FIFO capacity */ - use_dma = 0; if (!is_polling(sdd) && (xfer->len > fifo_len) && - sdd->rx_dma.ch && sdd->tx_dma.ch) + sdd->rx_dma.ch && sdd->tx_dma.ch) { use_dma = 1; - spin_lock_irqsave(&sdd->lock, flags); + } else if (is_polling(sdd) && xfer->len > fifo_len) { + tx_buf = xfer->tx_buf; + rx_buf = xfer->rx_buf; + origin_len = xfer->len; - /* Pending only which is to be done */ - sdd->state &= ~RXBUSY; - sdd->state &= ~TXBUSY; + target_len = xfer->len; + if (xfer->len > fifo_len) + xfer->len = fifo_len; + } + + do { + spin_lock_irqsave(&sdd->lock, flags); - s3c64xx_enable_datapath(sdd, xfer, use_dma); + /* Pending only which is to be done */ + sdd->state &= ~RXBUSY; + sdd->state &= ~TXBUSY; - /* Start the signals */ - s3c64xx_spi_set_cs(spi, true); + s3c64xx_enable_datapath(sdd, xfer, use_dma); - spin_unlock_irqrestore(&sdd->lock, flags); + /* Start the signals */ + s3c64xx_spi_set_cs(spi, true); - if (use_dma) - status = s3c64xx_wait_for_dma(sdd, xfer); - else - status = s3c64xx_wait_for_pio(sdd, xfer); - - if (status) { - dev_err(&spi->dev, "I/O Error: rx-%d tx-%d res:rx-%c tx-%c len-%d\n", - xfer->rx_buf ? 1 : 0, xfer->tx_buf ? 1 : 0, - (sdd->state & RXBUSY) ? 'f' : 'p', - (sdd->state & TXBUSY) ? 'f' : 'p', - xfer->len); - - if (use_dma) { - if (xfer->tx_buf != NULL - && (sdd->state & TXBUSY)) - dmaengine_terminate_all(sdd->tx_dma.ch); - if (xfer->rx_buf != NULL - && (sdd->state & RXBUSY)) - dmaengine_terminate_all(sdd->rx_dma.ch); + spin_unlock_irqrestore(&sdd->lock, flags); + + if (use_dma) + status = s3c64xx_wait_for_dma(sdd, xfer); + else + status = s3c64xx_wait_for_pio(sdd, xfer); + + if (status) { + dev_err(&spi->dev, + "I/O Error: rx-%d tx-%d res:rx-%c tx-%c len-%d\n", + xfer->rx_buf ? 1 : 0, xfer->tx_buf ? 1 : 0, + (sdd->state & RXBUSY) ? 'f' : 'p', + (sdd->state & TXBUSY) ? 'f' : 'p', + xfer->len); + + if (use_dma) { + if (xfer->tx_buf && (sdd->state & TXBUSY)) + dmaengine_terminate_all(sdd->tx_dma.ch); + if (xfer->rx_buf && (sdd->state & RXBUSY)) + dmaengine_terminate_all(sdd->rx_dma.ch); + } + } else { + s3c64xx_flush_fifo(sdd); } - } else { - s3c64xx_flush_fifo(sdd); + if (target_len > 0) { + target_len -= xfer->len; + + if (xfer->tx_buf) + xfer->tx_buf += xfer->len; + + if (xfer->rx_buf) + xfer->rx_buf += xfer->len; + + if (target_len > fifo_len) + xfer->len = fifo_len; + else + xfer->len = target_len; + } + } while (target_len > 0); + + if (origin_len) { + /* Restore original xfer buffers and length */ + xfer->tx_buf = tx_buf; + xfer->rx_buf = rx_buf; + xfer->len = origin_len; } return status;