Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp4985562img; Tue, 26 Mar 2019 23:00:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqyz6cBoJjtQh6aZe0xoBKEL8MUtuvDiZLRCJF9gHyimEhPbM0O9zlTtUQCu6BBtg7VMc8ju X-Received: by 2002:a62:6c43:: with SMTP id h64mr33659500pfc.123.1553666439452; Tue, 26 Mar 2019 23:00:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553666439; cv=none; d=google.com; s=arc-20160816; b=W1xEsQ0NJ1LB0V/CCKiHB+FOVFhTTeeNB4gvfGtNRg6OnN2DdpEjBEC9QTXvZNUMzI A0etRh1Ydp22D6b0MbJNpBJQj0ls4JLd/1w5EW/usgCdkpUrHJ94ygH5bP656SGpR4d8 Lfy/Z862h2PAuhOfdTwTLfqanCEUd0EvtAk+WvKxZJCS6DYOpFjsStqhUKvnH2BOtp9t X+18sGbFDXd+8QXvF6gw+cb05xu79SxfMnrSN3pRrsd/YM4VQL4Q01I/p4/SNUV+/X/4 D0Uf9Y4iD4WxVAAd6JP8rrKNjq8O4Aeah5WBK0SDMxqU+0R/Air3UkL89BKBB0o+VR1I Nbgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=KT+g1+XtGBOoIwtSTct5X3UtWlKCsnsfrJ1PHIdXCrM=; b=V+mOanHnU5vZ/eFpevo8rxYlIuQVNlX2ftaQUQCP/uq85oubZLRrTI+6F3fPkesuRt L8VBgPJMsP1hllcXQhUwUIO5mgN4XgL7CPNfRumMqwndQ0yR21ub3FdVfcddqUbGhVTN ysr3VbAEkEOZjD3j6unjLikYC3GQWgq2fYXogb5GmWxUrF/V8WpglNZYGvI/9cx13j78 FHM8SLhmadHOCYSnDFSsP1T4jTaGCqdBwq0rRAeGBpw2MAxlhY+fd2H+umN36usprrjf 5J/PUTjnawKtxRMVawJc4hT2bRzMcX5hUcj4WChgOFUGvQB2b0TpJ7AAb9DDXsC902Rb lvfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=ikKF5eIm; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n66si17864049pfb.62.2019.03.26.23.00.24; Tue, 26 Mar 2019 23:00:39 -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=pass header.i=@nvidia.com header.s=n1 header.b=ikKF5eIm; 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=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733100AbfC0F5Y (ORCPT + 99 others); Wed, 27 Mar 2019 01:57:24 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:6212 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732949AbfC0F5P (ORCPT ); Wed, 27 Mar 2019 01:57:15 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 26 Mar 2019 22:57:11 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 26 Mar 2019 22:57:13 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 26 Mar 2019 22:57:13 -0700 Received: from HQMAIL104.nvidia.com (172.18.146.11) by HQMAIL106.nvidia.com (172.18.146.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 27 Mar 2019 05:57:12 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL104.nvidia.com (172.18.146.11) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 27 Mar 2019 05:57:13 +0000 Received: from skomatineni-linux.nvidia.com (Not Verified[10.2.161.83]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Tue, 26 Mar 2019 22:57:12 -0700 From: Sowjanya Komatineni To: , , , , , , , CC: , , , , Subject: [PATCH V1 07/26] spi: tegra114: flush fifos Date: Tue, 26 Mar 2019 22:56:28 -0700 Message-ID: <1553666207-11414-7-git-send-email-skomatineni@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1553666207-11414-1-git-send-email-skomatineni@nvidia.com> References: <1553666207-11414-1-git-send-email-skomatineni@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1553666231; bh=KT+g1+XtGBOoIwtSTct5X3UtWlKCsnsfrJ1PHIdXCrM=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=ikKF5eImpkqRykDrH5TVc8VAhGcQErnQee0t85zBjzJKM8N1GmPB7aU9Y4V8xvp1R c963/47ieYxUP2RlIsCSBCH85mTc1FWkZVb1FJrk7zdCDPl5oIExChIeyhBRRz+GlD KQyJovyeWaoLFmLbk+TMHLfpIWfpwhn2nTnK22MIYMkdX4dVYKKZjCHFhYENTImkrF E0hoMapl2nKMS6XI5NzsTlocXgnFQ/5fetnv752kYSSb0dm8llgdj0PFixyKmhIQTr glDf7tT1x2Q1PE8c8tKXT+aeopVYTc8De9RVHISMIz0KCGecQQUXIrMtwFUl4I8Ti8 +SxtQXWXm9DDQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fixes: Flush TX and RX FIFOs before start of new transfer and on FIFO overflow or underrun errors. Signed-off-by: Sowjanya Komatineni --- drivers/spi/spi-tegra114.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi-tegra114.c b/drivers/spi/spi-tegra114.c index 0d20fc489134..477828051aba 100644 --- a/drivers/spi/spi-tegra114.c +++ b/drivers/spi/spi-tegra114.c @@ -500,22 +500,37 @@ static int tegra_spi_start_rx_dma(struct tegra_spi_data *tspi, int len) return 0; } -static int tegra_spi_start_dma_based_transfer( - struct tegra_spi_data *tspi, struct spi_transfer *t) +static int tegra_spi_flush_fifos(struct tegra_spi_data *tspi) { - u32 val; - unsigned int len; - int ret = 0; + unsigned long timeout = jiffies + HZ; u32 status; - /* Make sure that Rx and Tx fifo are empty */ status = tegra_spi_readl(tspi, SPI_FIFO_STATUS); if ((status & SPI_FIFO_EMPTY) != SPI_FIFO_EMPTY) { - dev_err(tspi->dev, "Rx/Tx fifo are not empty status 0x%08x\n", - (unsigned)status); - return -EIO; + status |= SPI_RX_FIFO_FLUSH | SPI_TX_FIFO_FLUSH; + tegra_spi_writel(tspi, status, SPI_FIFO_STATUS); + while ((status & SPI_FIFO_EMPTY) != SPI_FIFO_EMPTY) { + status = tegra_spi_readl(tspi, SPI_FIFO_STATUS); + if (time_after(jiffies, timeout)) { + dev_err(tspi->dev, + "timeout waiting for fifo flush\n"); + return -EIO; + } + + udelay(1); + } } + return 0; +} + +static int tegra_spi_start_dma_based_transfer( + struct tegra_spi_data *tspi, struct spi_transfer *t) +{ + u32 val; + unsigned int len; + int ret = 0; + val = SPI_DMA_BLK_SET(tspi->curr_dma_words - 1); tegra_spi_writel(tspi, val, SPI_DMA_BLK); @@ -781,6 +796,9 @@ static int tegra_spi_start_transfer_one(struct spi_device *spi, dev_dbg(tspi->dev, "The def 0x%x and written 0x%x\n", tspi->def_command1_reg, (unsigned)command1); + ret = tegra_spi_flush_fifos(tspi); + if (ret < 0) + return ret; if (total_fifo_words > SPI_FIFO_DEPTH) ret = tegra_spi_start_dma_based_transfer(tspi, t); else @@ -878,6 +896,7 @@ static int tegra_spi_transfer_one_message(struct spi_master *master, (tspi->cur_direction & DATA_DIR_RX)) dmaengine_terminate_all(tspi->rx_dma_chan); ret = -EIO; + tegra_spi_flush_fifos(tspi); reset_control_assert(tspi->rst); udelay(2); reset_control_deassert(tspi->rst); @@ -931,6 +950,7 @@ static irqreturn_t handle_cpu_based_xfer(struct tegra_spi_data *tspi) tspi->status_reg); dev_err(tspi->dev, "CpuXfer 0x%08x:0x%08x\n", tspi->command1_reg, tspi->dma_control_reg); + tegra_spi_flush_fifos(tspi); reset_control_assert(tspi->rst); udelay(2); reset_control_deassert(tspi->rst); @@ -1003,6 +1023,7 @@ static irqreturn_t handle_dma_based_xfer(struct tegra_spi_data *tspi) tspi->status_reg); dev_err(tspi->dev, "DmaXfer 0x%08x:0x%08x\n", tspi->command1_reg, tspi->dma_control_reg); + tegra_spi_flush_fifos(tspi); reset_control_assert(tspi->rst); udelay(2); reset_control_deassert(tspi->rst); -- 2.7.4