From patchwork Tue Aug 24 07:02:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Zhang X-Patchwork-Id: 12454065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AF1DC4338F for ; Tue, 24 Aug 2021 07:02:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E019D6135F for ; Tue, 24 Aug 2021 07:02:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231483AbhHXHDG (ORCPT ); Tue, 24 Aug 2021 03:03:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231332AbhHXHDG (ORCPT ); Tue, 24 Aug 2021 03:03:06 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92EE5C061575; Tue, 24 Aug 2021 00:02:22 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id n12so237317plk.10; Tue, 24 Aug 2021 00:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0TshSGoZRkdJp806oI7mCmz4O2DIOv+2W+79PoduCNA=; b=sXHUhklvqPLVsCc4CKRzsHjdDt76ZShlNR45Krlo3j8cDrU1FQTn0WHmEdyjvRQifh fDIPGmxg9UNELHJiuZjMG+2p9Ajq6HJ3ZHYDsPxrnlwn/7FgkU+oU8JSMxzPUtt+YlgJ lfJk/845kZ+dW4UXPPcaYN5rLnAJUkQx7AyymGD/mFkq91BsVt/5EjQXjR5W+NQLcNo2 gdPa0r2ice6CGRdP9IBaUPJfRhcxe1ZmeYk+ynqA3WrgWWRLaDzzlDWTauSN31CcpujV 9miBpWSe4ECMvRmpBzzyDSuqgWldqej8mWJcu60zPWDfATM23ZCIfzXiHoz+9vOn0n17 Jmkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0TshSGoZRkdJp806oI7mCmz4O2DIOv+2W+79PoduCNA=; b=HmdNwo+aDkTAthvhcv/hUdCjKbRMNdxsjqIsNUIh36dF6MOzoSQHIhBLgnTs2Mi4cS iWm2dJsO5a/rCI9NPIBJ0nNhAJZfwvN6jY8txlq34vzdZh4L21qdBQ8t6Y9qZRRQ+U92 WdN86gBrZbwyysAnv9T+P1DERdGnJM1r5k4hwj2u8n6p1aQBxI3EhvUQ8eeeun5vF6TH FI/JUXYmqCv3HjjY9HirnSxJSj5QTZeVkfhjIJL8zYqF1cIh0RzSzUVrpaFAkUy0D9mf XgnYUt0mXG9uq0fwZ468vDzEVVPX4LLDNaewC8Tw7dgv2+GPrEmI/7pGrNdgV/m+/LJ9 rnVw== X-Gm-Message-State: AOAM5302njZ82VwOuFX0AcRtB4kxs6t5xSiJuvB75jmZgeTXdIG3NvIM 1rOyZTHJeuk14ipbgxYa6xLGfuc0koM= X-Google-Smtp-Source: ABdhPJx7qh+mfymAzQBG25lRx9QE5vU6BPHyUUPgWEEM5pL746lJaJh6WH29vwMxgEGrEQbLK0EAQQ== X-Received: by 2002:a17:90b:f8d:: with SMTP id ft13mr2840811pjb.228.1629788542127; Tue, 24 Aug 2021 00:02:22 -0700 (PDT) Received: from ubt.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id b17sm20365340pgl.61.2021.08.24.00.02.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 00:02:21 -0700 (PDT) From: Chunyan Zhang To: Mark Brown Cc: linux-spi@vger.kernel.org, Baolin Wang , Orson Zhai , Chunyan Zhang , Chunyan Zhang , Luting Guo , LKML Subject: [PATCH 1/3] spi: sprd: Pass offset instead of physical address to adi_read/_write() Date: Tue, 24 Aug 2021 15:02:10 +0800 Message-Id: <20210824070212.2089255-1-zhang.lyra@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: Chunyan Zhang The register offset would be added a physical address base and then pass to the function sprd_adt_read()/_write() each time before calling them. So we can do that within these two functions instead, that would make the code more clear. Signed-off-by: Chunyan Zhang --- drivers/spi/spi-sprd-adi.c | 105 ++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 61 deletions(-) diff --git a/drivers/spi/spi-sprd-adi.c b/drivers/spi/spi-sprd-adi.c index ab19068be867..abdad1ea7b38 100644 --- a/drivers/spi/spi-sprd-adi.c +++ b/drivers/spi/spi-sprd-adi.c @@ -117,24 +117,18 @@ struct sprd_adi { struct notifier_block restart_handler; }; -static int sprd_adi_check_paddr(struct sprd_adi *sadi, u32 paddr) +static int sprd_adi_check_addr(struct sprd_adi *sadi, u32 reg) { - if (paddr < sadi->slave_pbase || paddr > - (sadi->slave_pbase + ADI_SLAVE_ADDR_SIZE)) { + if (reg > ADI_SLAVE_ADDR_SIZE) { dev_err(sadi->dev, - "slave physical address is incorrect, addr = 0x%x\n", - paddr); + "slave address offset is incorrect, reg = 0x%x\n", + reg); return -EINVAL; } return 0; } -static unsigned long sprd_adi_to_vaddr(struct sprd_adi *sadi, u32 paddr) -{ - return (paddr - sadi->slave_pbase + sadi->slave_vbase); -} - static int sprd_adi_drain_fifo(struct sprd_adi *sadi) { u32 timeout = ADI_FIFO_DRAIN_TIMEOUT; @@ -161,11 +155,11 @@ static int sprd_adi_fifo_is_full(struct sprd_adi *sadi) return readl_relaxed(sadi->base + REG_ADI_ARM_FIFO_STS) & BIT_FIFO_FULL; } -static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val) +static int sprd_adi_read(struct sprd_adi *sadi, u32 reg, u32 *read_val) { int read_timeout = ADI_READ_TIMEOUT; unsigned long flags; - u32 val, rd_addr; + u32 val, rd_addr, paddr; int ret = 0; if (sadi->hwlock) { @@ -178,11 +172,16 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val) } } + ret = sprd_adi_check_addr(sadi, reg); + if (ret) + goto out; + /* * Set the physical register address need to read into RD_CMD register, * then ADI controller will start to transfer automatically. */ - writel_relaxed(reg_paddr, sadi->base + REG_ADI_RD_CMD); + paddr = sadi->slave_pbase + reg; + writel_relaxed(paddr, sadi->base + REG_ADI_RD_CMD); /* * Wait read operation complete, the BIT_RD_CMD_BUSY will be set @@ -212,9 +211,9 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val) */ rd_addr = (val & RD_ADDR_MASK) >> RD_ADDR_SHIFT; - if (rd_addr != (reg_paddr & REG_ADDR_LOW_MASK)) { + if (rd_addr != (paddr & REG_ADDR_LOW_MASK)) { dev_err(sadi->dev, "read error, reg addr = 0x%x, val = 0x%x\n", - reg_paddr, val); + paddr, val); ret = -EIO; goto out; } @@ -227,9 +226,8 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val) return ret; } -static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val) +static int sprd_adi_write(struct sprd_adi *sadi, u32 reg, u32 val) { - unsigned long reg = sprd_adi_to_vaddr(sadi, reg_paddr); u32 timeout = ADI_FIFO_DRAIN_TIMEOUT; unsigned long flags; int ret; @@ -244,6 +242,10 @@ static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val) } } + ret = sprd_adi_check_addr(sadi, reg); + if (ret) + goto out; + ret = sprd_adi_drain_fifo(sadi); if (ret < 0) goto out; @@ -254,7 +256,8 @@ static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val) */ do { if (!sprd_adi_fifo_is_full(sadi)) { - writel_relaxed(val, (void __iomem *)reg); + /* we need virtual register address to write. */ + writel_relaxed(val, (void __iomem *)(sadi->slave_vbase + reg)); break; } @@ -277,44 +280,24 @@ static int sprd_adi_transfer_one(struct spi_controller *ctlr, struct spi_transfer *t) { struct sprd_adi *sadi = spi_controller_get_devdata(ctlr); - u32 phy_reg, val; + u32 reg, val; int ret; if (t->rx_buf) { - phy_reg = *(u32 *)t->rx_buf + sadi->slave_pbase; - - ret = sprd_adi_check_paddr(sadi, phy_reg); - if (ret) - return ret; - - ret = sprd_adi_read(sadi, phy_reg, &val); - if (ret) - return ret; - + reg = *(u32 *)t->rx_buf; + ret = sprd_adi_read(sadi, reg, &val); *(u32 *)t->rx_buf = val; } else if (t->tx_buf) { u32 *p = (u32 *)t->tx_buf; - - /* - * Get the physical register address need to write and convert - * the physical address to virtual address. Since we need - * virtual register address to write. - */ - phy_reg = *p++ + sadi->slave_pbase; - ret = sprd_adi_check_paddr(sadi, phy_reg); - if (ret) - return ret; - + reg = *p++; val = *p; - ret = sprd_adi_write(sadi, phy_reg, val); - if (ret) - return ret; + ret = sprd_adi_write(sadi, reg, val); } else { dev_err(sadi->dev, "no buffer for transfer\n"); - return -EINVAL; + ret = -EINVAL; } - return 0; + return ret; } static void sprd_adi_set_wdt_rst_mode(struct sprd_adi *sadi) @@ -323,9 +306,9 @@ static void sprd_adi_set_wdt_rst_mode(struct sprd_adi *sadi) u32 val; /* Set default watchdog reboot mode */ - sprd_adi_read(sadi, sadi->slave_pbase + PMIC_RST_STATUS, &val); + sprd_adi_read(sadi, PMIC_RST_STATUS, &val); val |= HWRST_STATUS_WATCHDOG; - sprd_adi_write(sadi, sadi->slave_pbase + PMIC_RST_STATUS, val); + sprd_adi_write(sadi, PMIC_RST_STATUS, val); #endif } @@ -366,40 +349,40 @@ static int sprd_adi_restart_handler(struct notifier_block *this, reboot_mode = HWRST_STATUS_NORMAL; /* Record the reboot mode */ - sprd_adi_read(sadi, sadi->slave_pbase + PMIC_RST_STATUS, &val); + sprd_adi_read(sadi, PMIC_RST_STATUS, &val); val &= ~HWRST_STATUS_WATCHDOG; val |= reboot_mode; - sprd_adi_write(sadi, sadi->slave_pbase + PMIC_RST_STATUS, val); + sprd_adi_write(sadi, PMIC_RST_STATUS, val); /* Enable the interface clock of the watchdog */ - sprd_adi_read(sadi, sadi->slave_pbase + PMIC_MODULE_EN, &val); + sprd_adi_read(sadi, PMIC_MODULE_EN, &val); val |= BIT_WDG_EN; - sprd_adi_write(sadi, sadi->slave_pbase + PMIC_MODULE_EN, val); + sprd_adi_write(sadi, PMIC_MODULE_EN, val); /* Enable the work clock of the watchdog */ - sprd_adi_read(sadi, sadi->slave_pbase + PMIC_CLK_EN, &val); + sprd_adi_read(sadi, PMIC_CLK_EN, &val); val |= BIT_WDG_EN; - sprd_adi_write(sadi, sadi->slave_pbase + PMIC_CLK_EN, val); + sprd_adi_write(sadi, PMIC_CLK_EN, val); /* Unlock the watchdog */ - sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_LOCK, WDG_UNLOCK_KEY); + sprd_adi_write(sadi, REG_WDG_LOCK, WDG_UNLOCK_KEY); - sprd_adi_read(sadi, sadi->slave_pbase + REG_WDG_CTRL, &val); + sprd_adi_read(sadi, REG_WDG_CTRL, &val); val |= BIT_WDG_NEW; - sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_CTRL, val); + sprd_adi_write(sadi, REG_WDG_CTRL, val); /* Load the watchdog timeout value, 50ms is always enough. */ - sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_LOAD_HIGH, 0); - sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_LOAD_LOW, + sprd_adi_write(sadi, REG_WDG_LOAD_HIGH, 0); + sprd_adi_write(sadi, REG_WDG_LOAD_LOW, WDG_LOAD_VAL & WDG_LOAD_MASK); /* Start the watchdog to reset system */ - sprd_adi_read(sadi, sadi->slave_pbase + REG_WDG_CTRL, &val); + sprd_adi_read(sadi, REG_WDG_CTRL, &val); val |= BIT_WDG_RUN | BIT_WDG_RST; - sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_CTRL, val); + sprd_adi_write(sadi, REG_WDG_CTRL, val); /* Lock the watchdog */ - sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_LOCK, ~WDG_UNLOCK_KEY); + sprd_adi_write(sadi, REG_WDG_LOCK, ~WDG_UNLOCK_KEY); mdelay(1000); From patchwork Tue Aug 24 07:02:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Zhang X-Patchwork-Id: 12454067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3ACCC4338F for ; Tue, 24 Aug 2021 07:02:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4AF661181 for ; Tue, 24 Aug 2021 07:02:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231332AbhHXHDP (ORCPT ); Tue, 24 Aug 2021 03:03:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234633AbhHXHDK (ORCPT ); Tue, 24 Aug 2021 03:03:10 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0202AC06175F; Tue, 24 Aug 2021 00:02:27 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id c4so11657901plh.7; Tue, 24 Aug 2021 00:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pAVLriOKMyhaOJWbZj70EKxm3Jc9VNASO2rIE5jIqK0=; b=Ovpxm5p1tZOzii+C82+4S/b4ersXONHVVAvszzU0r7KEDcV0xv3wBjXI3aLjODkVIo YYpPenN6KD2MdOesfoom+EIoDZMRD4hzLX2qqh0FAZNNbeBRzQ2p8EP1mHFDqMpjCBRL qDzcSHnDvlEHFZLhqvBwJ5oSxKWbd+FbLrOugySgwGW4DT+YdmgOBNFHzw37c6Tqhg6M uS8+sR1W54yxhHRwu1thgiTP/fGWtipLgNU5B1vWYKvgdeBEiWlqIo4/NGo/CVFpIzpk HgWNHZduH15b6719qx6k/9kEzk2H63yTZz6GGLH2oKIpKi6dFZrB/rD0+1KjRJlZezAJ iDtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pAVLriOKMyhaOJWbZj70EKxm3Jc9VNASO2rIE5jIqK0=; b=k4nDxhogxErQIkKK3nBcTaDIpdo8j5Y+lKBq3zMa1wZVI/6dDztqM+NjYJPU+Ga8mX zctfVzaVUWjHX+PkkJt9muyQ+zEmCh3FmIrEt4l9tW0UJJmDLAD/OmACIR/vm7KxontO kSki0kmT8tj5UcU3mRmuKvR1ijc+qibDhiIBwVFwR43wiYXzdTBCfAYO5tksHh0j4MKx 5cpWRethXU8w9iMu9yvEvakoN0jzanvNqZFB3g/vKpCdSnUTZLR7zkRUD4pNE617xsF+ cnuK20RknD3vxuv+WooDf12O3zJblgvLeOUYNm5jwroT8pxr5Awg0HqqpKpv//ZkdYjV SCNg== X-Gm-Message-State: AOAM531mO8kkQ4EUOajec7U5E35rZSLbM3sNU3zSPbnPBioz3M9MFn8k EAJeHQfIYATA2o12Hm1yqtI= X-Google-Smtp-Source: ABdhPJwvhYZ9OXJgmIjktoUAeG4hP/upTvabgf9DqDZ6PndwnvE7chDSvWwEF9AcGrC6+jTIS1S2Fw== X-Received: by 2002:a17:902:bcc6:b0:12d:bd30:bc4d with SMTP id o6-20020a170902bcc600b0012dbd30bc4dmr31891845pls.18.1629788546570; Tue, 24 Aug 2021 00:02:26 -0700 (PDT) Received: from ubt.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id b17sm20365340pgl.61.2021.08.24.00.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 00:02:26 -0700 (PDT) From: Chunyan Zhang To: Mark Brown Cc: linux-spi@vger.kernel.org, Baolin Wang , Orson Zhai , Chunyan Zhang , Chunyan Zhang , Luting Guo , LKML Subject: [PATCH 2/3] spi: sprd: Make sure offset not equal to slave address size Date: Tue, 24 Aug 2021 15:02:11 +0800 Message-Id: <20210824070212.2089255-2-zhang.lyra@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824070212.2089255-1-zhang.lyra@gmail.com> References: <20210824070212.2089255-1-zhang.lyra@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: Chunyan Zhang The slave register offset shouldn't equal to the max slave address which ADI can support to access. Signed-off-by: Chunyan Zhang --- drivers/spi/spi-sprd-adi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-sprd-adi.c b/drivers/spi/spi-sprd-adi.c index abdad1ea7b38..06af519c0b21 100644 --- a/drivers/spi/spi-sprd-adi.c +++ b/drivers/spi/spi-sprd-adi.c @@ -119,7 +119,7 @@ struct sprd_adi { static int sprd_adi_check_addr(struct sprd_adi *sadi, u32 reg) { - if (reg > ADI_SLAVE_ADDR_SIZE) { + if (reg >= ADI_SLAVE_ADDR_SIZE) { dev_err(sadi->dev, "slave address offset is incorrect, reg = 0x%x\n", reg); From patchwork Tue Aug 24 07:02:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Zhang X-Patchwork-Id: 12454069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B65FC4320A for ; Tue, 24 Aug 2021 07:02:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 36FD461356 for ; Tue, 24 Aug 2021 07:02:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234634AbhHXHDQ (ORCPT ); Tue, 24 Aug 2021 03:03:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234664AbhHXHDP (ORCPT ); Tue, 24 Aug 2021 03:03:15 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34837C061760; Tue, 24 Aug 2021 00:02:31 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id fz10so2199917pjb.0; Tue, 24 Aug 2021 00:02:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oBX4YIAIW1Lbo+DKwuinsj3XFa4b7I197fWtFrroOkw=; b=Iz1l+BKZmk6rvR1qvQTI85Ev1PiVlrZf1SE+mkwOi1sUT8BNYOib3RU2srJLPcwBdn 14+j4oKjZB09b6avirzYaM9tnM2QgDj3vBgry2ie9GVFkxLpOplcXXbplnkb0AUvGOvk N1RR8+rfdTHnoGBMjcwiVGyGxPKfuRTUZRQ2gfHfeD9R9FcjWH+ozhWF14b8yaZimM/n omSRz6CJFSaBs0XHj6t1Z6gCDuS5kjS9Osg1jNUCm+CskQFCydCofbhySdOvAPP4Rf4j aOGum/iDWCLy5zxfqPc0GPf6LVcN1UE6ZVXsxRv9OBNWPRmn32Zt4xnF0p8o0wcqkOFu 8T8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oBX4YIAIW1Lbo+DKwuinsj3XFa4b7I197fWtFrroOkw=; b=htj97ijesXGiK8z/hz/JR6dq5hBiW5er5Quvb34hu0fmVoYdB8SyHYlEqvmWdmrF6o bEzK0FYhzzbFEaxHTAcEJoQzFhgYCbPDICcBqhGD09lnh2t043i7i04GkFZFMcxj4pCV 0sorE4RM9Jk+bNbXiN6YvSDkkpxY0WIleJJ6c4BqeDN5bNWCdG4UfW2WOEB3tUG5WqxA ZpoNIBG+Irr0LhIJnXmSTDkNz1p7DpVAg/r7a1IHqfEuo2ooGIterD0O2nO42UGDW4IF 74uUzrep8JE9E6AyFLNi/8oIqrXXBJNkLQxmZYJPP1sfaSXngE3seeRwL3oyoFfVaKEe pnwA== X-Gm-Message-State: AOAM531cT5f+mC+Vo8w8WBV259eypqH4LktBpltUeNFPkcPDGD3bC5YQ V/dJ3VTq24jIYvY5nZn2dU8= X-Google-Smtp-Source: ABdhPJwjl2rOeOrASOTBv/k9TzyFpyQfE0/4jDUWDQXS1mVDn1bFA8mRNVVhpWP8U2vixbNKhL+R+g== X-Received: by 2002:a17:90b:3608:: with SMTP id ml8mr2921425pjb.22.1629788550803; Tue, 24 Aug 2021 00:02:30 -0700 (PDT) Received: from ubt.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id b17sm20365340pgl.61.2021.08.24.00.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 00:02:30 -0700 (PDT) From: Chunyan Zhang To: Mark Brown Cc: linux-spi@vger.kernel.org, Baolin Wang , Orson Zhai , Chunyan Zhang , Chunyan Zhang , Luting Guo , LKML Subject: [PATCH 3/3] spi: sprd: fill offset only to RD_CMD register for reading from slave device Date: Tue, 24 Aug 2021 15:02:12 +0800 Message-Id: <20210824070212.2089255-3-zhang.lyra@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210824070212.2089255-1-zhang.lyra@gmail.com> References: <20210824070212.2089255-1-zhang.lyra@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: Chunyan Zhang RD_CMD can accept slave address offset only, higher bits are reserved. Writing the whole slave address including slave base seems unnecessary. Signed-off-by: Chunyan Zhang --- drivers/spi/spi-sprd-adi.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-sprd-adi.c b/drivers/spi/spi-sprd-adi.c index 06af519c0b21..07f11b17bf20 100644 --- a/drivers/spi/spi-sprd-adi.c +++ b/drivers/spi/spi-sprd-adi.c @@ -159,7 +159,7 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg, u32 *read_val) { int read_timeout = ADI_READ_TIMEOUT; unsigned long flags; - u32 val, rd_addr, paddr; + u32 val, rd_addr; int ret = 0; if (sadi->hwlock) { @@ -177,11 +177,10 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg, u32 *read_val) goto out; /* - * Set the physical register address need to read into RD_CMD register, + * Set the slave address offset need to read into RD_CMD register, * then ADI controller will start to transfer automatically. */ - paddr = sadi->slave_pbase + reg; - writel_relaxed(paddr, sadi->base + REG_ADI_RD_CMD); + writel_relaxed(reg, sadi->base + REG_ADI_RD_CMD); /* * Wait read operation complete, the BIT_RD_CMD_BUSY will be set @@ -211,9 +210,9 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg, u32 *read_val) */ rd_addr = (val & RD_ADDR_MASK) >> RD_ADDR_SHIFT; - if (rd_addr != (paddr & REG_ADDR_LOW_MASK)) { + if (rd_addr != (reg & REG_ADDR_LOW_MASK)) { dev_err(sadi->dev, "read error, reg addr = 0x%x, val = 0x%x\n", - paddr, val); + reg, val); ret = -EIO; goto out; }