From patchwork Mon Jun 13 09:27:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Lin X-Patchwork-Id: 12879241 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44C66C433EF for ; Mon, 13 Jun 2022 09:29:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date:Subject:Cc:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=eXbQSqsn1iyAN1aoE0BWSvEb6zznCDs7TiHAznbctpM=; b=mtnT/Lro0e1Tv/ JQZPc0XqQjmO5ShYtfq12zsOomosSFmCQ6hAXvyyLg3mYHpFsHPPUva8z6e9jHogS2xNHmKotvQZl QMVCO5CdekXitlnLLSPab/OAkkNuH7OsXFeVvP931mszvmRU5/WH8XnNNy4uNyk3JA3QTgoxoTELK G/7xgTiIUlRFpI/oepImhn3OqC6491X5D7NLbtTSh3G/IB1PNJFnbhe+7Lj5Fi3IQYY4KZC4wkgVL P+N9jWdAmpdmXYqOFe475ma5MLkrnnc5ZwKbjHIOd1auaZmtoB5VoLp7IyS0iiJAe6IuY9F5p3ZnV AeHIWfhM6kGzWXZh6Lew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0gMX-002Xrf-OE; Mon, 13 Jun 2022 09:27:57 +0000 Received: from mail-m121144.qiye.163.com ([115.236.121.144]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0gMT-002Xpd-OP; Mon, 13 Jun 2022 09:27:55 +0000 Received: from localhost.localdomain (unknown [58.22.7.114]) by mail-m121144.qiye.163.com (Hmail) with ESMTPA id 0A824AC04CF; Mon, 13 Jun 2022 17:27:48 +0800 (CST) From: Jon Lin To: broonie@kernel.org Cc: heiko@sntech.de, linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Jon Lin Subject: [PATCH] spi: rockchip: Disable local irq when pio write out of interrupt service Date: Mon, 13 Jun 2022 17:27:44 +0800 Message-Id: <20220613092744.9726-1-jon.lin@rock-chips.com> X-Mailer: git-send-email 2.17.1 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgPGg8OCBgUHx5ZQUlOS1dZCBgUCR5ZQVlLVUtZV1 kWDxoPAgseWUFZKDYvK1lXWShZQUlKS0tKN1dZLVlBSVdZDwkaFQgSH1lBWUNLSBlWGEtJSktLHU saGh1DVRMBExYaEhckFA4PWVdZFhoPEhUdFFlBWU9LSFVKSktISkNVS1kG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6PCo6CRw4KT09IQ0QPUkXDygS HUoKFANVSlVKTU5OSkpJT01DTUlLVTMWGhIXVREUFVUXEhU7CRQYEFYYExILCFUYFBZFWVdZEgtZ QVlOQ1VJSVVMVUpKT1lXWQgBWUFJTENLNwY+ X-HM-Tid: 0a815c640702b039kuuu0a824ac04cf X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220613_022753_956316_0A0BB973 X-CRM114-Status: GOOD ( 10.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Avoid interrupt come and interrupt the pio_writer. Signed-off-by: Jon Lin Signed-off-by: Jon --- drivers/spi/spi-rockchip.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c index a08215eb9e14..2184de146928 100644 --- a/drivers/spi/spi-rockchip.c +++ b/drivers/spi/spi-rockchip.c @@ -199,6 +199,7 @@ struct rockchip_spi { bool cs_high_supported; /* native CS supports active-high polarity */ struct spi_transfer *xfer; /* Store xfer temporarily */ + spinlock_t lock; /* prevent I/O concurrent access */ }; static inline void spi_enable_chip(struct rockchip_spi *rs, bool enable) @@ -293,9 +294,13 @@ static void rockchip_spi_handle_err(struct spi_controller *ctlr, static void rockchip_spi_pio_writer(struct rockchip_spi *rs) { - u32 tx_free = rs->fifo_len - readl_relaxed(rs->regs + ROCKCHIP_SPI_TXFLR); - u32 words = min(rs->tx_left, tx_free); + u32 tx_free; + u32 words; + unsigned long flags; + spin_lock_irqsave(&rs->lock, flags); + tx_free = rs->fifo_len - readl_relaxed(rs->regs + ROCKCHIP_SPI_TXFLR); + words = min(rs->tx_left, tx_free); rs->tx_left -= words; for (; words; words--) { u32 txw; @@ -308,6 +313,7 @@ static void rockchip_spi_pio_writer(struct rockchip_spi *rs) writel_relaxed(txw, rs->regs + ROCKCHIP_SPI_TXDR); rs->tx += rs->n_bytes; } + spin_unlock_irqrestore(&rs->lock, flags); } static void rockchip_spi_pio_reader(struct rockchip_spi *rs) @@ -779,6 +785,8 @@ static int rockchip_spi_probe(struct platform_device *pdev) goto err_put_ctlr; } + spin_lock_init(&rs->lock); + rs->apb_pclk = devm_clk_get(&pdev->dev, "apb_pclk"); if (IS_ERR(rs->apb_pclk)) { dev_err(&pdev->dev, "Failed to get apb_pclk\n");