Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2277080imm; Sun, 9 Sep 2018 20:56:19 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaDpFPz7UKdD9p9+j5mN8cqAd/OMZ9At/yyn6eJjcjEmcJPBSIOVO5WExcTxtIFWKXl98LS X-Received: by 2002:a63:ce43:: with SMTP id r3-v6mr20866862pgi.439.1536551779386; Sun, 09 Sep 2018 20:56:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536551779; cv=none; d=google.com; s=arc-20160816; b=m0pOQfAs961FYcCdfFX25xWuQ+QdaKUP+k9UmePxnfs4lqwCE8ntkpV5W+G/ykvrPN 2JAS5hUVgBWOk/evJ+gsUfG4pQcN3Dk8n93n+Jux2PYN4wbn85w8iQ8KIVc6zpYmRW+W K8ETcpK2qP8riga9GnlEMaXlXxGbaFAo3p1cAmau3K7jiyi3kBFksiNZ9atpb6p7eGc4 /Iya1xEhvrZJozqdalB8K+o+yaC1hzkGd5j0ox+MuVMXo17D/o/Z0hA7A4m8IbpJ93FH XFOsk2blSumGdQYWVCtTiDy86yTlm01rtEjEJAumr4x4Zmxu1lV7x6kCFSipHxpuVcG9 W14g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=SG8sWWsUdQ+QzU3DR1/zmYzm4TBejOsatzqsOC1dbUU=; b=JkdLu7mzPKcdK+hDCHZH9kEFjkIjtm81W/PXegX+3r8uYla5VHyDygt9HN712RHck+ 2f8R6o1YWsEDmysNcNBnru39IdLhbN1qGd1/yh1mJRW06RDck1cIcjSA+aVV19QsFgiI tNoCcgpM03uP40fnGV5Oy7KYpG955V7LOjaZC6kFNzWmt3PTVJD7YVJL0PNYOh75IhsW +WY5eRrjp5AyIicxyc6ZkI2dkQ0x02jJClvHwhjzWY6Eo53ZUB4zdBDl/LgfWP99w8jF DV+DpC/1d0yo/pOJpBXgDLAr7ycQ+ENw4c/+q37f4HLqLNTH+R5UxQPMhQV6fLQ1fWNk PcJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=MO6yuRou; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w26-v6si16879371pgl.340.2018.09.09.20.56.03; Sun, 09 Sep 2018 20:56:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=MO6yuRou; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726665AbeIJIqZ (ORCPT + 99 others); Mon, 10 Sep 2018 04:46:25 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36743 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726185AbeIJIqY (ORCPT ); Mon, 10 Sep 2018 04:46:24 -0400 Received: by mail-pg1-f195.google.com with SMTP id d1-v6so9742527pgo.3 for ; Sun, 09 Sep 2018 20:54:26 -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=Y1ry6SkZRzpjAx4cLMJ+OoTY4T0Aiu8xOAPAcCGOyQ/xUAKWHh8rfWxgm+UrcZ/Txk Zv6rXSZus5UyY8Qy09WleG8s5+ls+dshOaF3pADq+llQhqD2Rnhr4S3F3MOYA31LezR0 Ccm3GFpOf6SBKN+n8rvEvveJlEqgO2Ju/U2lh5REooOiPRoxUg16gJSgdZg+yeFnWoQO vPqiIpvIQW7s3SDJHvM5O3PuP8ne54KKPxlMRe+uq7mvpJ8TrIdlMJ/XFJWNmKTUSUnl 8JA5mYWprJzI540Iq/rXShrD86o6qN8Bi9S2SNLYBTDJliBQLiDgtJJ2/fkbbhKh0rco iTUg== X-Gm-Message-State: APzg51D40G7eBedcRQiJB4uf12QW1VuGIFt+gt98lGaNoCxOkMa5cpbT x0ojepUVnR9/X1z9KKKeToHAkA== 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 Cc: pihsun@chromium.org, Mark Brown , Matthias Brugger , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org 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 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); } -- 2.19.0.rc2.392.g5ba43deb5a-goog