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: 10345327 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 894DE601D7 for ; Tue, 17 Apr 2018 14:35:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A25E209CE for ; Tue, 17 Apr 2018 14:35:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CB3321FAD; Tue, 17 Apr 2018 14:35:59 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 916B3209CE for ; Tue, 17 Apr 2018 14:35:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-reply-to:Message-id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3Hy6cmvnQRwD5tm4eXsiCxp0WKcRjJUAqs6X1q+ZZH4=; b=tAXKh/47JOhpdOJGoAWZ7Zh2e6 gb9/ykGCaw27RA9pPuXu3UiG0SWZWCsLcxXpaMcUQr15uNBWoItvDyr4cvLqzUqUlxjcGhdypY4wX nrnp+6t8lNg3xZeRcixmxtmgCSRXjy9NcmKjZ5ERcGRU4r4/UelFVFEucN+X6Lc8nsDZVSLoYuBOI qXwEPVDxaRQZTntuicLBpMjqDcVfyD1yQnRue+IrzuK5tIvcORkVzlqPbV2Kq0lWthG4X+hYYPSmx if2XNwmIJiUTWg+ucjWrOUJDI/gy3GlnpEB5EPSwhquO9MTeZQrZAwFxOlwplBV2YANOBbECN60ip kt0W0suA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f8Ri4-0004bX-DK; Tue, 17 Apr 2018 14:35:52 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f8RdZ-0000Vh-Fo for linux-arm-kernel@lists.infradead.org; Tue, 17 Apr 2018 14:31:19 +0000 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 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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IBWT/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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180417_073114_160340_DFF960FB X-CRM114-Status: GOOD ( 18.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-samsung-soc@vger.kernel.org, Sylwester Nawrocki , b.zolnierkie@samsung.com, krzk@kernel.org, linux-spi@vger.kernel.org, kgene@kernel.org, andi@etezian.org, linux-arm-kernel@lists.infradead.org, m.szyprowski@samsung.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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;