From patchwork Sat Feb 9 13:14:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1039179 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="Zzrn2pZW"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43xXcC05TQz9sMl for ; Sun, 10 Feb 2019 00:15:54 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id B154CC21F20; Sat, 9 Feb 2019 13:15:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id B781CC21F69; Sat, 9 Feb 2019 13:15:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 55811C21FB5; Sat, 9 Feb 2019 13:15:14 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id E4259C21E29 for ; Sat, 9 Feb 2019 13:15:12 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id y1so2795324pgk.11 for ; Sat, 09 Feb 2019 05:15:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EQXeuwozr969vjAh+N+j1PArUOa9K4EhQObqOKooYK0=; b=Zzrn2pZWj6jifWbw0DKYAcxOEAgipeaoz/yekj63NWU+kWvIYedRWzrE0BVrI3XtOc 0Onnrse1TbPNTKKNW0SwrfEI8sBTN7kSi6eGw/pF8c0v5YVmQizIoPWISvqlMaTDgWiT gdjcfPEc+EsOVbpqjiVV1tLvbgr/zBg0GT2Uk= 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=EQXeuwozr969vjAh+N+j1PArUOa9K4EhQObqOKooYK0=; b=e3Y59MMZv++tk+LetfvxbKmamNEpDsa2qEmFtqpoGX4jFKJWSfAvQaQwx9uRuUc84o uvORSttb5iMh7exl5IWg+4bLiOU6nPZfQRlPwQZ+VdnT6X67X9i31U0swsvtEDjQ2vAR opjuIVwyZ83JFNJfrTkHTHrJs3v7zPaZCwwgGP9CURJF+gKql2TXXf43rtWEkW7fSCaQ JV4IdjykRABj4tjj/9ZGjaPvRhO9HAOWJXOLLERARXSIJRvHyAY/PIahrci5WgX+6Pyp Amm7cp21gxodQqJaum9j1h7wINUwL91sxqdzG+1U5XS4NV7x2fGBUk1B58SVOSkbJ4OE iZ6A== X-Gm-Message-State: AHQUAua2yjDO10sD8QQH2fgbfy5Airnz/kWILkRM8y9ysaUoAqa6RptI BIftGOZXx2bQtGk1DVddqa0ciA== X-Google-Smtp-Source: AHgI3IaEEODKVXhaCkrscA67vc3jc4K6ZmICf358b5ja6xdJaT9JNWLH+oLxjsG9bjKSEnpXFP1H/w== X-Received: by 2002:a65:44ca:: with SMTP id g10mr22307606pgs.180.1549718111279; Sat, 09 Feb 2019 05:15:11 -0800 (PST) Received: from localhost.localdomain ([115.97.184.151]) by smtp.gmail.com with ESMTPSA id z8sm6267013pgg.62.2019.02.09.05.15.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Feb 2019 05:15:10 -0800 (PST) From: Jagan Teki To: Maxime Ripard Date: Sat, 9 Feb 2019 18:44:51 +0530 Message-Id: <20190209131500.29954-2-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20190209131500.29954-1-jagan@amarulasolutions.com> References: <20190209131500.29954-1-jagan@amarulasolutions.com> MIME-Version: 1.0 Cc: u-boot@lists.denx.de, Stefan Mavrodiev Subject: [U-Boot] [PATCH 01/10] spi: sun4i: Poll for rxfifo empty X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" To drain rx fifo the fifo need to poll till the fifo count become empty. The current code is using wait_for_bit logic on control register with exchange burst mode mask, which is not a proper way of waiting for draining fifo. So, add code for polling fifo status register till rxfifo count become empty. Signed-off-by: Jagan Teki --- drivers/spi/sun4i_spi.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/spi/sun4i_spi.c b/drivers/spi/sun4i_spi.c index 38cc743c61..87b396a96e 100644 --- a/drivers/spi/sun4i_spi.c +++ b/drivers/spi/sun4i_spi.c @@ -31,6 +31,8 @@ #include +#include + #define SUN4I_FIFO_DEPTH 64 #define SUN4I_RXDATA_REG 0x00 @@ -46,7 +48,6 @@ #define SUN4I_CTL_LMTF BIT(6) #define SUN4I_CTL_TF_RST BIT(8) #define SUN4I_CTL_RF_RST BIT(9) -#define SUN4I_CTL_XCH_MASK 0x0400 #define SUN4I_CTL_XCH BIT(10) #define SUN4I_CTL_CS_MASK 0x3000 #define SUN4I_CTL_CS(cs) (((cs) << 12) & SUN4I_CTL_CS_MASK) @@ -308,7 +309,7 @@ static int sun4i_spi_xfer(struct udevice *dev, unsigned int bitlen, struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev); u32 len = bitlen / 8; - u32 reg; + u32 reg, rx_fifocnt; u8 nbytes; int ret; @@ -343,10 +344,12 @@ static int sun4i_spi_xfer(struct udevice *dev, unsigned int bitlen, reg = readl(&priv->regs->ctl); writel(reg | SUN4I_CTL_XCH, &priv->regs->ctl); - /* Wait transfer to complete */ - ret = wait_for_bit_le32(&priv->regs->ctl, SUN4I_CTL_XCH_MASK, - false, SUN4I_SPI_TIMEOUT_US, false); - if (ret) { + /* Wait till RX FIFO to be empty */ + ret = readl_poll_timeout(&priv->regs->ctl, rx_fifocnt, + !(((rx_fifocnt & SUN4I_FIFO_STA_RF_CNT_MASK) >> + SUN4I_FIFO_STA_RF_CNT_BITS) < nbytes), + SUN4I_SPI_TIMEOUT_US); + if (ret < 0) { printf("ERROR: sun4i_spi: Timeout transferring data\n"); sun4i_spi_set_cs(bus, slave_plat->cs, false); return ret;