From patchwork Tue Jun 28 06:49:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Icenowy Zheng X-Patchwork-Id: 1649513 X-Patchwork-Delegate: andre.przywara@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=icenowy.me header.i=uwu@icenowy.me header.a=rsa-sha256 header.s=zmail header.b=FQZuYPvJ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LXQNJ66Lhz9sGJ for ; Tue, 28 Jun 2022 23:26:24 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3611D83BFE; Tue, 28 Jun 2022 15:26:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=icenowy.me Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=icenowy.me header.i=uwu@icenowy.me header.b="FQZuYPvJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4346A84410; Tue, 28 Jun 2022 08:49:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from sender4-op-o18.zoho.com (sender4-op-o18.zoho.com [136.143.188.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E550184424 for ; Tue, 28 Jun 2022 08:49:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=icenowy.me Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=uwu@icenowy.me ARC-Seal: i=1; a=rsa-sha256; t=1656398978; cv=none; d=zohomail.com; s=zohoarc; b=k6BBQkeq9rYwd1C0nc0IiO39VKva3n7UGqyJvcnN2XcleK01h0CowROSO7/ScWjF3mKGEiPPyITa1RDNSFectkr/UcS1a5TVD+jfb1BwMy/SRnBRmEVgeliDuI79X+uvNVaoTg/uOWDaSr3aGTZj8EWI4G0iGWEDGsw50t6vKuo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656398978; h=Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=u9UC5xbs2nn9qgdQ588HgW+KPxQuLWldA2Isd6UNW1s=; b=J3xihGEH0ACT10MDWSpIxRHj3aG0gvYMV9zAfqSRMdWGtR8Hv2KKHfq/Y7W2Un33hFLQm08E0ETTCgVFiPTcusyhymPT8uvcEC5SVKenaGrD+M6nN/Pg9+l59aWDkDZbhUJXt57FCM2O+f69pCRuGeNR7KqPMA9rlEcLQqvCPuM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=icenowy.me; spf=pass smtp.mailfrom=uwu@icenowy.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1656398978; s=zmail; d=icenowy.me; i=uwu@icenowy.me; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=u9UC5xbs2nn9qgdQ588HgW+KPxQuLWldA2Isd6UNW1s=; b=FQZuYPvJ0ZB8mUbMtZkYbDlXtIkXdcd7tAqf3ayuh0WPVFIS5EZrF+8PoizqrahX effosUE8avLumqlqAClvcPAwo65Pkf/OECN709rzZq3ZelxE7ke1Dcz6KoagilwwG2g g0cF3Hfk/uScldySfTmIXnTG8N6/jnJFydoTT7kU= Received: from edelgard.icenowy.me (59.41.163.137 [59.41.163.137]) by mx.zohomail.com with SMTPS id 16563989756881006.4906135058854; Mon, 27 Jun 2022 23:49:35 -0700 (PDT) From: Icenowy Zheng To: Jagan Teki , Andre Przywara , Jesse Taube Cc: u-boot@lists.denx.de, Icenowy Zheng Subject: [PATCH sunxi/next] spi: sunxi: use XCH status to detect in-progress transfer Date: Tue, 28 Jun 2022 14:49:24 +0800 Message-Id: <20220628064924.390103-1-uwu@icenowy.me> X-Mailer: git-send-email 2.36.0 MIME-Version: 1.0 X-ZohoMailClient: External X-Mailman-Approved-At: Tue, 28 Jun 2022 15:25:58 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The current detection of RX FIFO depth seems to be not reliable, and XCH will self-clear when a transfer is done. Check XCH bit when polling for transfer finish. Signed-off-by: Icenowy Zheng Reviewed-by: Andre Przywara --- drivers/spi/spi-sunxi.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi-sunxi.c b/drivers/spi/spi-sunxi.c index 2f33337725..a424c6a98e 100644 --- a/drivers/spi/spi-sunxi.c +++ b/drivers/spi/spi-sunxi.c @@ -83,7 +83,7 @@ DECLARE_GLOBAL_DATA_PTR; #endif #define SUN4I_SPI_MIN_RATE 3000 #define SUN4I_SPI_DEFAULT_RATE 1000000 -#define SUN4I_SPI_TIMEOUT_US 1000000 +#define SUN4I_SPI_TIMEOUT_MS 1000 #define SPI_REG(priv, reg) ((priv)->base + \ (priv)->variant->regs[reg]) @@ -326,7 +326,6 @@ static int sun4i_spi_xfer(struct udevice *dev, unsigned int bitlen, struct dm_spi_slave_plat *slave_plat = dev_get_parent_plat(dev); u32 len = bitlen / 8; - u32 rx_fifocnt; u8 nbytes; int ret; @@ -364,13 +363,10 @@ static int sun4i_spi_xfer(struct udevice *dev, unsigned int bitlen, setbits_le32(SPI_REG(priv, SPI_TCR), SPI_BIT(priv, SPI_TCR_XCH)); - /* Wait till RX FIFO to be empty */ - ret = readl_poll_timeout(SPI_REG(priv, SPI_FSR), - rx_fifocnt, - (((rx_fifocnt & - SPI_BIT(priv, SPI_FSR_RF_CNT_MASK)) >> - SUN4I_FIFO_STA_RF_CNT_BITS) >= nbytes), - SUN4I_SPI_TIMEOUT_US); + /* Wait for the transfer to be done */ + ret = wait_for_bit_le32((const void *)SPI_REG(priv, SPI_TCR), + SPI_BIT(priv, SPI_TCR_XCH), + false, SUN4I_SPI_TIMEOUT_MS, false); if (ret < 0) { printf("ERROR: sun4i_spi: Timeout transferring data\n"); sun4i_spi_set_cs(bus, slave_plat->cs, false);