From patchwork Tue Apr 4 06:00:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaewon Kim X-Patchwork-Id: 13199172 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C206C6FD1D for ; Tue, 4 Apr 2023 06:14:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233678AbjDDGOS (ORCPT ); Tue, 4 Apr 2023 02:14:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233668AbjDDGOR (ORCPT ); Tue, 4 Apr 2023 02:14:17 -0400 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E75821B8 for ; Mon, 3 Apr 2023 23:14:14 -0700 (PDT) Received: from epcas2p1.samsung.com (unknown [182.195.41.53]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20230404061411epoutp039009679d095927187d1ea09ec511e4cc~Spqfp5zuZ3076830768epoutp03E for ; Tue, 4 Apr 2023 06:14:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20230404061411epoutp039009679d095927187d1ea09ec511e4cc~Spqfp5zuZ3076830768epoutp03E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1680588851; bh=yxk3LInfyfp4SqA7cJhgXDlEraKJNgFGdKmVnOtMA/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FzeKSiSyaSV0fqX5IBCm+/O+Ch/FsjM2kRf2NTFZRTROpMjRIraUTBKzvfwvLvF5g Z5yMSor5P8SLgj6YVsCnoj/hFnFmFKtm0X2spg6hP5gJwXQrHjkxYElaTjXFoRqWQU waRfQZZ+kQkyZ3mFb1RBYVUOHBAnEUZV7/aJPb8Y= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p1.samsung.com (KnoxPortal) with ESMTP id 20230404061410epcas2p1ffd783739455327a78232e7a39fcc776~SpqfFMjrp1839918399epcas2p14; Tue, 4 Apr 2023 06:14:10 +0000 (GMT) Received: from epsmges2p1.samsung.com (unknown [182.195.36.70]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4PrHXL134Xz4x9QF; Tue, 4 Apr 2023 06:14:10 +0000 (GMT) Received: from epcas2p3.samsung.com ( [182.195.41.55]) by epsmges2p1.samsung.com (Symantec Messaging Gateway) with SMTP id C5.0D.61927.130CB246; Tue, 4 Apr 2023 15:14:10 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas2p2.samsung.com (KnoxPortal) with ESMTPA id 20230404061409epcas2p2b12a9cac014907e3930795cb67cb6040~SpqeEw5ss0906409064epcas2p2W; Tue, 4 Apr 2023 06:14:09 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230404061409epsmtrp1d9839c642188df34f77c6026fd90d8b7~SpqeEBRS_0601006010epsmtrp1K; Tue, 4 Apr 2023 06:14:09 +0000 (GMT) X-AuditID: b6c32a45-671ff7000001f1e7-d2-642bc03137ec Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id A0.CD.18071.130CB246; Tue, 4 Apr 2023 15:14:09 +0900 (KST) Received: from localhost.localdomain (unknown [10.229.9.51]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230404061409epsmtip13822c512614a3630e8784a3b1881b187~Spqd5kGE73056630566epsmtip1T; Tue, 4 Apr 2023 06:14:09 +0000 (GMT) From: Jaewon Kim To: Krzysztof Kozlowski , Andi Shyti , Alim Akhtar , Mark Brown , Rob Herring Cc: linux-spi@vger.kernel.org, linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Chanho Park , Jaewon Kim Subject: [PATCH 3/3] spi: s3c64xx: support interrupt based pio mode Date: Tue, 4 Apr 2023 15:00:11 +0900 Message-Id: <20230404060011.108561-4-jaewon02.kim@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230404060011.108561-1-jaewon02.kim@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJKsWRmVeSWpSXmKPExsWy7bCmua7RAe0Ug40PGS0ezNvGZrH4x3Mm i6kPn7BZXN6vbTH/yDlWix0NR1gt9r7eym6x6fE1VovLu+awWcw4v4/JovHjTXaL1r1H2B14 PK4v+cTssWlVJ5vHnWt72Dw2L6n36NuyitHj8ya5ALaobJuM1MSU1CKF1Lzk/JTMvHRbJe/g eOd4UzMDQ11DSwtzJYW8xNxUWyUXnwBdt8wcoBOVFMoSc0qBQgGJxcVK+nY2RfmlJakKGfnF JbZKqQUpOQXmBXrFibnFpXnpenmpJVaGBgZGpkCFCdkZLec6mQr2yVccuvGYsYHxi0QXIyeH hICJxOuDGxm7GLk4hAR2MEq83jcLyvnEKPH9y212COcbo8TJ55PYYVrmdnVAVe1llNj7Yi0z hPORUeLz8y9sIFVsAtoS39cvZgVJiAgcZZTYvvMtmMMMMmvh0TlgVcICzhITpm0Bs1kEVCVO d/cwgdi8AnYSO57fY4LYJy+xesMBZhCbU8Be4mv7DRaQQRICH9kllk09A3WUi8TVvllQtrDE q+NboGwpiZf9bVB2tkT79D+sEHaFxMUNs9kgbGOJWc/agR7iALpOU2L9Ln0QU0JAWeLILRaQ CmYBPomOw3/ZIcK8Eh1tQhCNahL3p56DGiIjMenISqiLPST+THwNdrGQwCRGiY/rTSYwys1C mL+AkXEVo1hqQXFuemqxUYEhPMqS83M3MYLToJbrDsbJb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A8W+OESgPN nrmFa/88KWE/nXXhxoyOiCYGPs8X5R16jUdeSk3iCfgfI1o1be6pewI32Fon8a5WdzHSYHn+ ff67J4e6HTx8thedUl5h4Myv7JD++upavxlu2UJvj0+59viCWPC73NjfKwQW/Fwnwlbh8z6Q 2z6z8oaDbZiOxAfV9tTdW02WHLnFcMrmyqtTYQX6r5IVU+Xvu2b35K5doifTxrdJ67c2X5SB /SdV4ZQ/0SJH7ui3dvX8lihknPBQLSZmz8J3EycZxzvbeK/R6zi6IEXUSGDPsh9//64+axj/ /8X/lWK+jWrlkvl3l63NL5/Pl/grTjcs0lzikmL3xhuPZJ/3hjFYXD6lxFKckWioxVxUnAgA i1UC1MgCAAA= X-CMS-MailID: 20230404061409epcas2p2b12a9cac014907e3930795cb67cb6040 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230404061409epcas2p2b12a9cac014907e3930795cb67cb6040 References: <20230404060011.108561-1-jaewon02.kim@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org This patch adds IRQ based PIO mode instead of cpu polling. By using the FIFO trigger level, interrupts are received. CPU consumption is reduced in PIO mode because registers are not constantly checked. Signed-off-by: Jaewon Kim --- drivers/spi/spi-s3c64xx.c | 54 ++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index bf1f3dcca202..f8986b05309e 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -59,6 +59,8 @@ #define S3C64XX_SPI_MODE_BUS_TSZ_HALFWORD (1<<17) #define S3C64XX_SPI_MODE_BUS_TSZ_WORD (2<<17) #define S3C64XX_SPI_MODE_BUS_TSZ_MASK (3<<17) +#define S3C64XX_SPI_MODE_RX_RDY_LVL GENMASK(16, 11) +#define S3C64XX_SPI_MODE_RX_RDY_LVL_SHIFT 11 #define S3C64XX_SPI_MODE_SELF_LOOPBACK (1<<3) #define S3C64XX_SPI_MODE_RXDMA_ON (1<<2) #define S3C64XX_SPI_MODE_TXDMA_ON (1<<1) @@ -567,6 +569,7 @@ static int s3c64xx_wait_for_pio(struct s3c64xx_spi_driver_data *sdd, { void __iomem *regs = sdd->regs; unsigned long val; + unsigned long time; u32 status; int loops; u32 cpy_len; @@ -577,6 +580,11 @@ static int s3c64xx_wait_for_pio(struct s3c64xx_spi_driver_data *sdd, ms = xfer->len * 8 * 1000 / sdd->cur_speed; ms += 10; /* some tolerance */ + val = msecs_to_jiffies(ms); + time = wait_for_completion_timeout(&sdd->xfer_completion, val); + if (!time) + return -EIO; + val = msecs_to_loops(ms); do { status = readl(regs + S3C64XX_SPI_STATUS); @@ -743,6 +751,8 @@ static int s3c64xx_spi_transfer_one(struct spi_master *master, u32 speed; u8 bpw; unsigned long flags; + u32 rdy_lv; + u32 val; reinit_completion(&sdd->xfer_completion); @@ -763,17 +773,41 @@ static int s3c64xx_spi_transfer_one(struct spi_master *master, sdd->rx_dma.ch && sdd->tx_dma.ch) { use_dma = 1; - } else if (xfer->len > fifo_len) { + } else if (xfer->len >= fifo_len) { tx_buf = xfer->tx_buf; rx_buf = xfer->rx_buf; origin_len = xfer->len; - target_len = xfer->len; - if (xfer->len > fifo_len) - xfer->len = fifo_len; + xfer->len = fifo_len - 1; } do { + if (!use_dma) { + reinit_completion(&sdd->xfer_completion); + + rdy_lv = xfer->len; + /* Setup RDY_FIFO trigger Level + * RDY_LVL = + * fifo_lvl upto 64 byte -> N bytes + * 128 byte -> RDY_LVL * 2 bytes + * 256 byte -> RDY_LVL * 4 bytes + */ + if (fifo_len == 128) + rdy_lv /= 2; + else if (fifo_len == 256) + rdy_lv /= 4; + + val = readl(sdd->regs + S3C64XX_SPI_MODE_CFG); + val &= ~S3C64XX_SPI_MODE_RX_RDY_LVL; + val |= (rdy_lv << S3C64XX_SPI_MODE_RX_RDY_LVL_SHIFT); + writel(val, sdd->regs + S3C64XX_SPI_MODE_CFG); + + /* Enable FIFO_RDY_EN IRQ */ + val = readl(sdd->regs + S3C64XX_SPI_INT_EN); + writel((val | S3C64XX_SPI_INT_RX_FIFORDY_EN), + sdd->regs + S3C64XX_SPI_INT_EN); + + } spin_lock_irqsave(&sdd->lock, flags); /* Pending only which is to be done */ @@ -834,8 +868,8 @@ static int s3c64xx_spi_transfer_one(struct spi_master *master, if (xfer->rx_buf) xfer->rx_buf += xfer->len; - if (target_len > fifo_len) - xfer->len = fifo_len; + if (target_len >= fifo_len) + xfer->len = fifo_len - 1; else xfer->len = target_len; } @@ -1005,6 +1039,14 @@ static irqreturn_t s3c64xx_spi_irq(int irq, void *data) dev_err(&spi->dev, "TX underrun\n"); } + if (val & S3C64XX_SPI_ST_RX_FIFORDY) { + complete(&sdd->xfer_completion); + /* No pending clear irq, turn-off INT_EN_RX_FIFO_RDY */ + val = readl(sdd->regs + S3C64XX_SPI_INT_EN); + writel((val & ~S3C64XX_SPI_INT_RX_FIFORDY_EN), + sdd->regs + S3C64XX_SPI_INT_EN); + } + /* Clear the pending irq by setting and then clearing it */ writel(clr, sdd->regs + S3C64XX_SPI_PENDING_CLR); writel(0, sdd->regs + S3C64XX_SPI_PENDING_CLR);