Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp357713imm; Tue, 18 Sep 2018 23:30:43 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYK3xQ8R0RqKrQBVm8398MMmLDXVqdTPIFCb9mQHywO4ePy5syXgA1y0d4VAC2LjPpPRkBn X-Received: by 2002:a63:6604:: with SMTP id a4-v6mr30948673pgc.404.1537338642939; Tue, 18 Sep 2018 23:30:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537338642; cv=none; d=google.com; s=arc-20160816; b=1EoSc8G2+oK1Zn09EXXnGvHsF2K8NyWiLPOujeQB3PlbT1pgacUxkvcAqYFt0abuPA IfBJWs5GmdOI/QIN9VJLEZ69ODuzFDMmE082wW2GtaATwmTgC24bR25jLZ73UYvWVuCi XbYhowmRKM8wymQRDVKb7S5QNUnymkdfrwEdnGA/992M0xDXvI3ue9Pn/f8dy1LVaT9V jcj7hGloKXGljaXjPBuabpZ6rTRPGQ4UCXlO7k4Nh+iuQ3hY0x0COiAqPtZigeci+NeY JD9Dw6wZ2EE84OyUJVHbEBCFQo8nq2cAM2OeEUmDBB4ZN9sNF+2pUvMd7MmCyvUHastz ChfQ== 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=4UxYp9Fd6cQxttmxSAWHS+kOvGw5onYHLG7nB8EqH7I=; b=JipLu1GeUKWmMdRnDaTjZhbp7Ge/uSew1atcAH8NQ9Iz2KBw+4VgFZlUFeBb7hfCyE QSJImImHrFukfYQHkU5G9vlMrimvFIyfDIAxDmGY8maek8YL7pmxO5DDQuFHaA6IBW1O +OAyWODJbAvsOIxEWjYaokDr0FpoV3Mv658XVzyIZ594uhMvwhSxVFkOvIJYrU6orfwf yLKddrPxYaiAqmLSiHiIIk6fJ3XnaQ+QVWH4mHafYDkKsq/spcgop2AMWEnG1sXxtL0q JDrtqsseT9gUDRwN2NP+wrxMkxz2O8oWgf3JQhBMgGU39vPToMDd23fTwUSlXFZVGTAn hjiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=iPxpUv9Y; 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 y64-v6si2511402pgb.219.2018.09.18.23.30.25; Tue, 18 Sep 2018 23:30:42 -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=iPxpUv9Y; 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 S1730908AbeISMGq (ORCPT + 99 others); Wed, 19 Sep 2018 08:06:46 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:37339 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728297AbeISMGq (ORCPT ); Wed, 19 Sep 2018 08:06:46 -0400 Received: by mail-pf1-f195.google.com with SMTP id h69-v6so2206864pfd.4 for ; Tue, 18 Sep 2018 23:30:20 -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=4UxYp9Fd6cQxttmxSAWHS+kOvGw5onYHLG7nB8EqH7I=; b=iPxpUv9YM2oQncReLzlo1rl/sWHUju78qzBVX/OAYcoi1eagyg98xgBQ3+5oJL3iaW GWV96pP18tXwXLAhmmMo4E2ljmlQ9GOywT5iMouqVC5TGpl/3qsrfYiTABeNpK36dz/x Z+1kO/OV3kNgeoxtFE7+vsr9OWrxJo1PzJT2I= 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=4UxYp9Fd6cQxttmxSAWHS+kOvGw5onYHLG7nB8EqH7I=; b=jTPaUseCch6kIcnw1QhXxN03amXlI9oRu4YeYT3kZbjZHkJft/BZbEVZCAZKz8ZqvN f7+m+TwTcs4kQgk1P4F43gSjaPvgXLutWBdLRQtdqkzS+HmpPn7ivIiVISVf668lW4AS riWmWlw7+ubFdTWphMzFnfSzhGK4i396mWQxHl8SJ4j2g/nl1a9zQHE1mEoNgcIa8sEA WCvV/hjL/q76jaOGWbsDSXucEE5wK5r+pSZTIYbQMyAZoxPuOTs5thG62qPQV5nIF61p xCijhdWTPW0hc7ubGJM+oyz8p+JEe7t2jCIjllEIZq8xHLY54qhh33s7I7uwKNogAKe3 BuCw== X-Gm-Message-State: APzg51D8qnqVrgmmwu0qjtPTHprQqi4SJZsCiwtQxfhXjqQ3lfoooJHr ia5hwkAFXXCrhXKIdo2DLx3Y2g== X-Received: by 2002:a63:e54b:: with SMTP id z11-v6mr30498558pgj.328.1537338620266; Tue, 18 Sep 2018 23:30:20 -0700 (PDT) Received: from pihsun-z840.tpe.corp.google.com ([2401:fa00:1:10:1039:d81d:d174:8fe9]) by smtp.googlemail.com with ESMTPSA id y7-v6sm37188874pff.181.2018.09.18.23.30.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Sep 2018 23:30:19 -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 v3] spi: mediatek: Don't modify spi_transfer when transfer. Date: Wed, 19 Sep 2018 14:29:27 +0800 Message-Id: <20180919062928.238917-1-pihsun@chromium.org> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog In-Reply-To: <20180918161504.GM2471@sirena.org.uk> References: <20180918161504.GM2471@sirena.org.uk> 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 --- 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