From patchwork Wed Mar 21 01:58:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 10298293 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 2C92F60385 for ; Wed, 21 Mar 2018 01:58:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CE572975C for ; Wed, 21 Mar 2018 01:58:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11AF329760; Wed, 21 Mar 2018 01:58:51 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 9AD972975C for ; Wed, 21 Mar 2018 01:58:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751728AbeCUB6f (ORCPT ); Tue, 20 Mar 2018 21:58:35 -0400 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:34918 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751671AbeCUB6b (ORCPT ); Tue, 20 Mar 2018 21:58:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Date:Message-Id:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner: List-Archive; bh=eJgWfqqopDMB8VlVXu6ze7qJntB+kgi6g42XlNSuzf4=; b=NscgJpfP/vFf GmvhTu+XlziOwwunguk+uXZ9U+nQYGgx1GLEy0uPgMBvnmJlxChgESMcVy3ycFQ/i+3pYyj0sZT1C OSJ98vMhUn0i4W5kH79sHIe0AZEI0Ob8KB5F9vDlWW6Q0xLGRo3OWSfxmsg3WSJXX8UfaVrwTLtnY U7XfY=; Received: from [218.255.99.6] (helo=finisterre.ee.mobilebroadband) by heliosphere.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1eyT1I-00007w-N7; Wed, 21 Mar 2018 01:58:29 +0000 Received: by finisterre.ee.mobilebroadband (Postfix, from userid 1000) id 26A3E44007A; Wed, 21 Mar 2018 01:58:26 +0000 (GMT) From: Mark Brown To: Baolin Wang Cc: Mark Brown , broonie@kernel.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, erick.chen@spreadtrum.com, baolin.wang@linaro.org, linux-spi@vger.kernel.org Subject: Applied "spi: sprd: Simplify the transfer function" to the spi tree In-Reply-To: Message-Id: <20180321015826.26A3E44007A@finisterre.ee.mobilebroadband> Date: Wed, 21 Mar 2018 01:58:26 +0000 (GMT) Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The patch spi: sprd: Simplify the transfer function has been applied to the spi tree at https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From a61aa683655f3182aca6e38404ae9aac03e771ae Mon Sep 17 00:00:00 2001 From: Baolin Wang Date: Tue, 20 Mar 2018 10:42:13 +0800 Subject: [PATCH] spi: sprd: Simplify the transfer function We can move the hardware spinlock protection into the ADI read/write functions to simplify the sprd_adi_transfer_one() function. Moreover this optimization can also help to access PMIC without considering the hardware spinlock using sprd_adi_read/write() functions. Signed-off-by: Baolin Wang Signed-off-by: Mark Brown --- drivers/spi/spi-sprd-adi.c | 64 +++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/drivers/spi/spi-sprd-adi.c b/drivers/spi/spi-sprd-adi.c index 5993bdbf79e4..74bbd045aac0 100644 --- a/drivers/spi/spi-sprd-adi.c +++ b/drivers/spi/spi-sprd-adi.c @@ -123,7 +123,17 @@ static int sprd_adi_fifo_is_full(struct sprd_adi *sadi) static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val) { int read_timeout = ADI_READ_TIMEOUT; + unsigned long flags; u32 val, rd_addr; + int ret; + + ret = hwspin_lock_timeout_irqsave(sadi->hwlock, + ADI_HWSPINLOCK_TIMEOUT, + &flags); + if (ret) { + dev_err(sadi->dev, "get the hw lock failed\n"); + return ret; + } /* * Set the physical register address need to read into RD_CMD register, @@ -147,7 +157,8 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val) if (read_timeout == 0) { dev_err(sadi->dev, "ADI read timeout\n"); - return -EBUSY; + ret = -EBUSY; + goto out; } /* @@ -161,21 +172,35 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val) if (rd_addr != (reg_paddr & REG_ADDR_LOW_MASK)) { dev_err(sadi->dev, "read error, reg addr = 0x%x, val = 0x%x\n", reg_paddr, val); - return -EIO; + ret = -EIO; + goto out; } *read_val = val & RD_VALUE_MASK; - return 0; + +out: + hwspin_unlock_irqrestore(sadi->hwlock, &flags); + return ret; } -static int sprd_adi_write(struct sprd_adi *sadi, unsigned long reg, u32 val) +static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val) { + unsigned long reg = sprd_adi_to_vaddr(sadi, reg_paddr); u32 timeout = ADI_FIFO_DRAIN_TIMEOUT; + unsigned long flags; int ret; + ret = hwspin_lock_timeout_irqsave(sadi->hwlock, + ADI_HWSPINLOCK_TIMEOUT, + &flags); + if (ret) { + dev_err(sadi->dev, "get the hw lock failed\n"); + return ret; + } + ret = sprd_adi_drain_fifo(sadi); if (ret < 0) - return ret; + goto out; /* * we should wait for write fifo is empty before writing data to PMIC @@ -192,10 +217,12 @@ static int sprd_adi_write(struct sprd_adi *sadi, unsigned long reg, u32 val) if (timeout == 0) { dev_err(sadi->dev, "write fifo is full\n"); - return -EBUSY; + ret = -EBUSY; } - return 0; +out: + hwspin_unlock_irqrestore(sadi->hwlock, &flags); + return ret; } static int sprd_adi_transfer_one(struct spi_controller *ctlr, @@ -203,7 +230,6 @@ static int sprd_adi_transfer_one(struct spi_controller *ctlr, struct spi_transfer *t) { struct sprd_adi *sadi = spi_controller_get_devdata(ctlr); - unsigned long flags, virt_reg; u32 phy_reg, val; int ret; @@ -214,16 +240,7 @@ static int sprd_adi_transfer_one(struct spi_controller *ctlr, if (ret) return ret; - ret = hwspin_lock_timeout_irqsave(sadi->hwlock, - ADI_HWSPINLOCK_TIMEOUT, - &flags); - if (ret) { - dev_err(sadi->dev, "get the hw lock failed\n"); - return ret; - } - ret = sprd_adi_read(sadi, phy_reg, &val); - hwspin_unlock_irqrestore(sadi->hwlock, &flags); if (ret) return ret; @@ -241,19 +258,8 @@ static int sprd_adi_transfer_one(struct spi_controller *ctlr, if (ret) return ret; - virt_reg = sprd_adi_to_vaddr(sadi, phy_reg); val = *p; - - ret = hwspin_lock_timeout_irqsave(sadi->hwlock, - ADI_HWSPINLOCK_TIMEOUT, - &flags); - if (ret) { - dev_err(sadi->dev, "get the hw lock failed\n"); - return ret; - } - - ret = sprd_adi_write(sadi, virt_reg, val); - hwspin_unlock_irqrestore(sadi->hwlock, &flags); + ret = sprd_adi_write(sadi, phy_reg, val); if (ret) return ret; } else {