From patchwork Mon Sep 10 03:54:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pi-Hsun Shih X-Patchwork-Id: 10593555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 23FDA920 for ; Mon, 10 Sep 2018 03:55:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FA8828E5C for ; Mon, 10 Sep 2018 03:55:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0128428F98; Mon, 10 Sep 2018 03:55:14 +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,RCVD_IN_DNSWL_NONE 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 77B1628E5C for ; Mon, 10 Sep 2018 03:55:14 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=CAQinAAelTfNYh8xd9Bua6RVC+8TplOWrD4qQJz8yTI=; b=JvRuQmkzZnCv4W cEMbAA/4vNekT1lASO+MTOgorDAhAX01eQ5J414O3rKNpBPw0fx4UWXT48rdEELzIEKP131Ci72W/ 9FZyI0PY4VISvC1S6ntirCmhohoEzUQObynwiPV0GWqqI1UOM1ah/Isyyu2ZQWtOk7YNLsDvp4j7h TBzuJyNX7/Az5aNCj2ofSAcW4NzJm5GCLZglPGH84dZxonCVZr+NOGyOk5JK3CrzZxnVcMUIq2Qjg 5RUT1fQxuklY5EQcYzmCre4n5PjV/8TkQCrjshk2vb5Q2gs2w/AUvt1iVeSg18snLxmIR7JHmuMTJ qfJw/m1tV4BqDM8AzFSw==; 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 1fzDI2-0004Jg-E5 for patchwork-linux-mediatek@patchwork.kernel.org; Mon, 10 Sep 2018 03:55:06 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fzDHa-000418-Iv for linux-mediatek@lists.infradead.org; Mon, 10 Sep 2018 03:54:40 +0000 Received: by mail-pg1-x541.google.com with SMTP id l63-v6so9733469pga.7 for ; Sun, 09 Sep 2018 20:54:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SG8sWWsUdQ+QzU3DR1/zmYzm4TBejOsatzqsOC1dbUU=; b=MO6yuRoub75Fge2FUR3Cs2ems7spAWXzGd9SaUiZBClGnvR49R6YJ9Brtp2SDVgMPW CiUuNdukgcHa760+BJ9ijW+451d70oXLmmRC6Pzn+QKuEa3pgr1JQQ8Lf4JB/NUhRVY2 4yopA2nD1m1eXShM3un2QoWBiHZviKyGDzVVo= 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=SG8sWWsUdQ+QzU3DR1/zmYzm4TBejOsatzqsOC1dbUU=; b=jQM5Rb9c9deYXl3ztAl2filP+98IS9ro9BAXR0+q7vO9YAoizCFjLkrxydneIff3Qc Ojyq8DgydGXDHmmho4mndMwnrxuNC4Bswwc0z26N6PFTEM7HgDtV1e2HshjEy0TFA+Iy 26ZWihr3wwLvPrOh11d0k06ab5sAH3yMuR7HeIZNBzd8Z8a+aJyOPLbjioNrXcmK0AHM tQjUni7/EbnR93y/9GmHoKR1FA84KDLAIfKd8H8ICyFlNjfFpXfWTkeTKTSB8J6Yw9fW uz2E3xTQuR3sXAX0o8nKCFbI4R7+Sd2xbqNHdZ3S3LIaeLUK1c0mlLCJzwDblZ8FM7jG FR0w== X-Gm-Message-State: APzg51BONqge0tQqs5ry9/Pul7FwUVZZlfNc/IylOHr3eEvmHEeaTgbL H1bY/zBJXTjtpWbrPKxdjiQq9g== X-Google-Smtp-Source: ANB0Vdahp8iBOTB20SkX/l621r8+oWce7o4T17Syo965DCVzreBhpQTFFHxMSeTEldc+fcdYja+JCg== X-Received: by 2002:a63:d150:: with SMTP id c16-v6mr20549007pgj.188.1536551666605; Sun, 09 Sep 2018 20:54:26 -0700 (PDT) Received: from pihsun-z840.tpe.corp.google.com ([2401:fa00:1:10:7889:7a43:f899:134c]) by smtp.googlemail.com with ESMTPSA id m21-v6sm20223932pgd.6.2018.09.09.20.54.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Sep 2018 20:54:25 -0700 (PDT) From: Peter Shih To: Subject: [PATCH v2] spi: mediatek: Don't modify spi_transfer when transfer. Date: Mon, 10 Sep 2018 11:54:21 +0800 Message-Id: <20180910035421.101505-1-pihsun@chromium.org> X-Mailer: git-send-email 2.19.0.rc2.392.g5ba43deb5a-goog In-Reply-To: <20180910035047.98496-1-pihsun@chromium.org> References: <20180910035047.98496-1-pihsun@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180909_205438_661431_28C71E3F X-CRM114-Status: GOOD ( 14.04 ) X-BeenThere: linux-mediatek@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-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Mark Brown , linux-mediatek@lists.infradead.org, pihsun@chromium.org, Matthias Brugger , linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Mediatek SPI driver modifies some fields (tx_buf, rx_buf, len, tx_dma, rx_dma) of the spi_transfer* passed in when doing transfer_one and in interrupt handler. This is somewhat unexpected, and there are some caller (e.g. Cr50 spi driver) that reuse the spi_transfer for multiple messages. Add a field to record how many bytes have been transferred, and calculate the right len / buffer based on it instead. Signed-off-by: Pi-Hsun Shih Change-Id: I23e218cd964f16c0b2b26127d4a5ca6529867673 --- drivers/spi/spi-mt65xx.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c index 86bf45667a040..3dc31627c6558 100644 --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c @@ -98,6 +98,7 @@ struct mtk_spi { struct clk *parent_clk, *sel_clk, *spi_clk; struct spi_transfer *cur_transfer; u32 xfer_len; + u32 num_xfered; struct scatterlist *tx_sgl, *rx_sgl; u32 tx_sgl_len, rx_sgl_len; const struct mtk_spi_compatible *dev_comp; @@ -385,6 +386,7 @@ static int mtk_spi_fifo_transfer(struct spi_master *master, mdata->cur_transfer = xfer; mdata->xfer_len = min(MTK_SPI_MAX_FIFO_SIZE, xfer->len); + mdata->num_xfered = 0; mtk_spi_prepare_transfer(master, xfer); mtk_spi_setup_packet(master); @@ -415,6 +417,7 @@ static int mtk_spi_dma_transfer(struct spi_master *master, mdata->tx_sgl_len = 0; mdata->rx_sgl_len = 0; mdata->cur_transfer = xfer; + mdata->num_xfered = 0; mtk_spi_prepare_transfer(master, xfer); @@ -482,7 +485,7 @@ static int mtk_spi_setup(struct spi_device *spi) static irqreturn_t mtk_spi_interrupt(int irq, void *dev_id) { - u32 cmd, reg_val, cnt, remainder; + u32 cmd, reg_val, cnt, remainder, len; struct spi_master *master = dev_id; struct mtk_spi *mdata = spi_master_get_devdata(master); struct spi_transfer *trans = mdata->cur_transfer; @@ -497,36 +500,38 @@ static irqreturn_t mtk_spi_interrupt(int irq, void *dev_id) if (trans->rx_buf) { cnt = mdata->xfer_len / 4; ioread32_rep(mdata->base + SPI_RX_DATA_REG, - trans->rx_buf, cnt); + trans->rx_buf + mdata->num_xfered, cnt); remainder = mdata->xfer_len % 4; if (remainder > 0) { reg_val = readl(mdata->base + SPI_RX_DATA_REG); - memcpy(trans->rx_buf + (cnt * 4), - ®_val, remainder); + memcpy(trans->rx_buf + + mdata->num_xfered + + (cnt * 4), + ®_val, + remainder); } } - trans->len -= mdata->xfer_len; - if (!trans->len) { + mdata->num_xfered += mdata->xfer_len; + if (mdata->num_xfered == trans->len) { spi_finalize_current_transfer(master); return IRQ_HANDLED; } - if (trans->tx_buf) - trans->tx_buf += mdata->xfer_len; - if (trans->rx_buf) - trans->rx_buf += mdata->xfer_len; - - mdata->xfer_len = min(MTK_SPI_MAX_FIFO_SIZE, trans->len); + len = trans->len - mdata->num_xfered; + mdata->xfer_len = min(MTK_SPI_MAX_FIFO_SIZE, len); mtk_spi_setup_packet(master); - cnt = trans->len / 4; - iowrite32_rep(mdata->base + SPI_TX_DATA_REG, trans->tx_buf, cnt); + cnt = len / 4; + iowrite32_rep(mdata->base + SPI_TX_DATA_REG, + trans->tx_buf + mdata->num_xfered, cnt); - remainder = trans->len % 4; + remainder = len % 4; if (remainder > 0) { reg_val = 0; - memcpy(®_val, trans->tx_buf + (cnt * 4), remainder); + memcpy(®_val, + trans->tx_buf + (cnt * 4) + mdata->num_xfered, + remainder); writel(reg_val, mdata->base + SPI_TX_DATA_REG); }