{"id":2224164,"url":"http://patchwork.ozlabs.org/api/patches/2224164/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/20260417022104.3973576-4-ycliang@andestech.com/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260417022104.3973576-4-ycliang@andestech.com>","list_archive_url":null,"date":"2026-04-17T02:20:59","name":"[3/8] spi: atcspi200: Use proper timeout handling for busy-wait loops","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"65227529cdc207555d13cd4f66469ed7dc9daed2","submitter":{"id":79234,"url":"http://patchwork.ozlabs.org/api/people/79234/?format=json","name":"Leo Yu-Chi Liang","email":"ycliang@andestech.com"},"delegate":{"id":17739,"url":"http://patchwork.ozlabs.org/api/users/17739/?format=json","username":"jagan","first_name":"Jagannadha Sutradharudu","last_name":"Teki","email":"jagannadh.teki@gmail.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20260417022104.3973576-4-ycliang@andestech.com/mbox/","series":[{"id":500221,"url":"http://patchwork.ozlabs.org/api/series/500221/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=500221","date":"2026-04-17T02:20:56","name":"spi: atcspi200: Modernize driver and add spi-mem + data merge support","version":1,"mbox":"http://patchwork.ozlabs.org/series/500221/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2224164/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2224164/checks/","tags":{},"related":[],"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org)","phobos.denx.de;\n dmarc=fail (p=reject dis=none) header.from=andestech.com","phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de","phobos.denx.de; dmarc=fail (p=reject dis=none)\n header.from=andestech.com","phobos.denx.de;\n spf=pass smtp.mailfrom=ycliang@andestech.com"],"Received":["from phobos.denx.de (phobos.denx.de\n [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fxdtg2hzkz1yGt\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 12:22:03 +1000 (AEST)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 23EB48423F;\n\tFri, 17 Apr 2026 04:21:40 +0200 (CEST)","by phobos.denx.de (Postfix, from userid 109)\n id EBD9983EEF; Fri, 17 Apr 2026 04:21:38 +0200 (CEST)","from Atcsqr.andestech.com (unknown [60.248.187.195])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id 19334841C8\n for <u-boot@lists.denx.de>; Fri, 17 Apr 2026 04:21:35 +0200 (CEST)","from mail.andestech.com (ATCPCS34.andestech.com [10.0.1.134])\n by Atcsqr.andestech.com with ESMTP id 63H2LABm015785;\n Fri, 17 Apr 2026 10:21:10 +0800 (+08)\n (envelope-from ycliang@andestech.com)","from swlinux02.andestech.com (10.0.15.183) by ATCPCS34.andestech.com\n (10.0.1.134) with Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 17 Apr\n 2026 10:21:10 +0800"],"X-Spam-Checker-Version":"SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-1.1 required=5.0 tests=BAYES_00,\n RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,\n RCVD_IN_VALIDITY_RPBL_BLOCKED,RDNS_NONE,SPF_HELO_NONE,SPF_PASS\n autolearn=no autolearn_force=no version=3.4.2","From":"Leo Yu-Chi Liang <ycliang@andestech.com>","To":"<u-boot@lists.denx.de>","CC":"Tom Rini <trini@konsulko.com>, Vignesh R <vigneshr@ti.com>, \"Takahiro\n Kuwano\" <takahiro.kuwano@infineon.com>, Jagan Teki\n <jagan@amarulasolutions.com>, <ycliang@andestech.com>","Subject":"[PATCH 3/8] spi: atcspi200: Use proper timeout handling for busy-wait\n loops","Date":"Fri, 17 Apr 2026 10:20:59 +0800","Message-ID":"<20260417022104.3973576-4-ycliang@andestech.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20260417022104.3973576-1-ycliang@andestech.com>","References":"<20260417022104.3973576-1-ycliang@andestech.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Content-Type":"text/plain","X-Originating-IP":"[10.0.15.183]","X-ClientProxiedBy":"ATCPCS33.andestech.com (10.0.1.100) To\n ATCPCS34.andestech.com (10.0.1.134)","X-DKIM-Results":"atcpcs34.andestech.com; dkim=none;","X-DNSRBL":"","X-MAIL":"Atcsqr.andestech.com 63H2LABm015785","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.39","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<https://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=subscribe>","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>","X-Virus-Scanned":"clamav-milter 0.103.8 at phobos.denx.de","X-Virus-Status":"Clean"},"content":"Replace manual busy-wait counters with standard U-Boot timeout APIs:\n\n- Use wait_for_bit_le32() for FIFO reset wait in claim_bus and SPI\n  busy wait in stop, providing time-based timeouts with watchdog\n  support\n- Use get_timer() for the transfer polling loop where TX/RX work\n  is done inside the loop\n- Remove the 'to' field from private data (no longer needed)\n- Replace iteration-count SPI_TIMEOUT with time-based SPI_TIMEOUT_MS\n\nSigned-off-by: Leo Yu-Chi Liang <ycliang@andestech.com>\n---\n drivers/spi/atcspi200_spi.c | 41 ++++++++++++++++++-------------------\n 1 file changed, 20 insertions(+), 21 deletions(-)","diff":"diff --git a/drivers/spi/atcspi200_spi.c b/drivers/spi/atcspi200_spi.c\nindex 33cf7583581..38345a88260 100644\n--- a/drivers/spi/atcspi200_spi.c\n+++ b/drivers/spi/atcspi200_spi.c\n@@ -11,13 +11,15 @@\n #include <dm/device_compat.h>\n #include <log.h>\n #include <spi.h>\n+#include <time.h>\n+#include <wait_bit.h>\n #include <asm/io.h>\n #include <linux/bitfield.h>\n #include <linux/bitops.h>\n \n #define MAX_TRANSFER_LEN\t512\n #define CHUNK_SIZE\t\t1\n-#define SPI_TIMEOUT\t\t0x100000\n+#define SPI_TIMEOUT_MS\t\t1000\n #define SPI_DEF_SRC_CLK\t\t100000000\n #define SPI_DEF_MAX_CLK\t\t40000000\n \n@@ -68,7 +70,6 @@\n \n struct atcspi200_priv {\n \tvoid\t\t*regs;\n-\tint\t\tto;\n \tunsigned int\tfreq;\n \tunsigned int\tsrc_clk;\n \tunsigned int\tmax_clk;\n@@ -126,14 +127,16 @@ static int atcspi200_hw_set_speed(struct atcspi200_priv *priv)\n static int atcspi200_hw_claim_bus(struct atcspi200_priv *priv)\n {\n \tunsigned int format;\n+\tint ret;\n \n \tatcspi200_write(priv, ATCSPI200_REG_CTRL,\n \t\t\tatcspi200_read(priv, ATCSPI200_REG_CTRL) |\n \t\t\tTXFRST | RXFRST | SPIRST);\n-\twhile ((atcspi200_read(priv, ATCSPI200_REG_CTRL) &\n-\t\t(TXFRST | RXFRST | SPIRST)) && priv->to--)\n-\t\tif (!priv->to)\n-\t\t\treturn -EINVAL;\n+\tret = wait_for_bit_le32(priv->regs + ATCSPI200_REG_CTRL,\n+\t\t\t\tTXFRST | RXFRST | SPIRST,\n+\t\t\t\tfalse, SPI_TIMEOUT_MS, false);\n+\tif (ret)\n+\t\treturn ret;\n \n \tpriv->cmd_len = 0;\n \tformat = priv->mode | FIELD_PREP(DATA_LEN_MASK, 8 - 1);\n@@ -176,12 +179,8 @@ static int atcspi200_hw_start(struct atcspi200_priv *priv)\n \n static int atcspi200_hw_stop(struct atcspi200_priv *priv)\n {\n-\twhile ((atcspi200_read(priv, ATCSPI200_REG_STATUS) & SPIBSY) &&\n-\t       priv->to--)\n-\t\tif (!priv->to)\n-\t\t\treturn -EINVAL;\n-\n-\treturn 0;\n+\treturn wait_for_bit_le32(priv->regs + ATCSPI200_REG_STATUS,\n+\t\t\t\t SPIBSY, false, SPI_TIMEOUT_MS, false);\n }\n \n static void atcspi200_tx_byte(struct atcspi200_priv *priv, const void *dout)\n@@ -209,7 +208,8 @@ static int atcspi200_hw_xfer(struct atcspi200_priv *priv,\n \tsize_t cmd_len = priv->cmd_len;\n \tunsigned long data_len = bitlen / 8;\n \tint rf_cnt;\n-\tint ret = 0, timeout = 0;\n+\tint ret = 0;\n+\tunsigned long start;\n \n \tmax_tran_len = priv->max_transfer_length;\n \tswitch (flags) {\n@@ -252,12 +252,17 @@ static int atcspi200_hw_xfer(struct atcspi200_priv *priv,\n \t\tpriv->tran_len = tran_len;\n \t\tnum_blks = DIV_ROUND_UP(tran_len, CHUNK_SIZE);\n \t\tnum_bytes = tran_len % CHUNK_SIZE;\n-\t\ttimeout = SPI_TIMEOUT;\n \t\tif (num_bytes == 0)\n \t\t\tnum_bytes = CHUNK_SIZE;\n+\t\tstart = get_timer(0);\n \t\tatcspi200_hw_start(priv);\n \n-\t\twhile (num_blks && timeout--) {\n+\t\twhile (num_blks) {\n+\t\t\tif (get_timer(start) > SPI_TIMEOUT_MS) {\n+\t\t\t\tdebug(\"spi_xfer: %s() timeout\\n\", __func__);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n \t\t\tevent = atcspi200_read(priv, ATCSPI200_REG_STATUS);\n \n \t\t\tif ((event & TXEPTY) && data_out) {\n@@ -282,11 +287,6 @@ static int atcspi200_hw_xfer(struct atcspi200_priv *priv,\n \t\t\t\t\tdin = (unsigned char *)din + rx_bytes;\n \t\t\t\t}\n \t\t\t}\n-\n-\t\t\tif (!timeout) {\n-\t\t\t\tdebug(\"spi_xfer: %s() timeout\\n\", __func__);\n-\t\t\t\tbreak;\n-\t\t\t}\n \t\t}\n \n \t\tdata_len -= tran_len;\n@@ -385,7 +385,6 @@ static int atcspi200_spi_probe(struct udevice *bus)\n {\n \tstruct atcspi200_priv *priv = dev_get_priv(bus);\n \n-\tpriv->to = SPI_TIMEOUT;\n \tpriv->max_transfer_length = MAX_TRANSFER_LEN;\n \tatcspi200_spi_get_clk(bus);\n \n","prefixes":["3/8"]}