Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp9180rdb; Thu, 25 Jan 2024 06:55:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQ2qESPSD4irRjTgGGbjPPO8h6FeTfFc7pD1JbFCqwgBkjZbieXOzH+Ny47FJTnxcxp8rm X-Received: by 2002:a05:622a:130f:b0:42a:3983:59bf with SMTP id v15-20020a05622a130f00b0042a398359bfmr1144204qtk.63.1706194539452; Thu, 25 Jan 2024 06:55:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706194539; cv=pass; d=google.com; s=arc-20160816; b=vcMQEbAPWWYAqqecqVIGRHfQQfl+apYBRNUdngE1/xMSafSJAcrk+fsQt1HC4DmoxM 5niNsAjEFkh7VETyaPaU+Z91LnYvV1MU7MY0vDiKaid/Anfcv+n2flJCFuAN+wgM0idK UIMqed9VFi6dvkMXddyOltuEhSzP1HSnG6nvnQw+DL/yb+LnUya15ChsnGvV834RkcC3 ZoXa3zLxSSoyiolUhmD6vL9hepLdGjHgx6xVWIzTAal/LDX7Em1bTQntxE8trItYeCta g48ZHO74V9u5vp1J1mzhgV7bYPYvn8ecNnewu2GWCyFz6l+iS+R2jUT++Zo7kBwrDBex uxRw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ZysQ9KAcWXka70FvugQOSV9RayYcqOy7xI0fMhicphA=; fh=neYYEYDDBiloBUX0offulAnrRZM+Gy1+1fqKS4b9oG8=; b=TRgJNr6IKb1J9Ii5UE+RL0S4i9ZaYwzSe3+2Q5c6CHsxNPe8m8iNemZrw5G635KTWn zgcR/nQDHde+5jEfRkFpLQA/QT4xtF+mkIonHWF5kJvhdgIPgfBXIQdV0gsM0ENumbKH mLSurNhUOAWiK99wzykVDNvFkYE9CCYJ3twgCP60NBGswrBC2f5AkdOXeC5a7qhU9rtM yJC6dVGRY67EaZuK9x82/X062+pYd95diyxomAqtnjI7NWoXB5ZFWyWbNsFcuVqhuERX If8Glk3I3XX/tvD/2A7mbdK8jTpvbsDw9PZXKBbAli94Ni3OVBwlkiEt3IyVCa4o++cp Tvzg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WGMK5KOf; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-38765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s10-20020a05622a178a00b0042a1f274b03si13218308qtk.490.2024.01.25.06.55.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 06:55:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WGMK5KOf; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-38765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 59A9E1C24DA4 for ; Thu, 25 Jan 2024 14:55:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7291412839B; Thu, 25 Jan 2024 14:50:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="WGMK5KOf" Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1A8582D6E for ; Thu, 25 Jan 2024 14:50:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706194229; cv=none; b=I7fVa1XB3H+qkf7fq7mT13Y3rSHQIq38mdOc8NS5Wei9ZlI6/oQwXm0h/m8kpDXgL69J8RsAyT7APjH/09ApbEnYtzScvnH5zg4JWwApAgkgwYuagJqKmv1BujnrVwMPM+mt3m95bJv1klzkpv3coNGC5g0B8BiIVZt3l+CRNDw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706194229; c=relaxed/simple; bh=PQ0DdMw7t2JvUMcjVibwWPTT4g6T5s8jNboS4tHNMMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KE2AXiXqzx+aKHKZEt1vS2Ijhv06k+CoZnvSoKMBGAl9ljs/bx22ah5hESZJg58YXIVYLIltc8qf6m/rjhWjy+48L/OnPe1VZRTtPm4yjlvvRw7lSuXCq9D45FArO3UE/clZCMeuKBRqSVa+I/Mog0OPXbxOylAoWQRGYwTZ7iQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=WGMK5KOf; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-40eb033c192so5238475e9.0 for ; Thu, 25 Jan 2024 06:50:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706194224; x=1706799024; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZysQ9KAcWXka70FvugQOSV9RayYcqOy7xI0fMhicphA=; b=WGMK5KOfHP15eG+RGbqD6t0+Mz7XdSnAgBymAX512FbnV6Xg9XfRvOBHaxMtCRI7CR NJFTRzH/TLtQ3ZWFVNebuM296oh70FQVvp+nxNTYR3UOXsZiG5ZyAAVDpGzUd4Fiw/EM BEZ96vqKaghZauQR5jIcmSf8K2kNXlvlANlLGG6RhlNQY5HHLERL9rC5J+fCO73M7b4+ amJdVNxv5PrBp7+NF1aufGlRiVGWNeC6yYw9yI+YhBm5bCVoVQ2aDK3GYVPqwARkeZxV PLhR6COGYrQtJCxep2sQ0zZMyKrcAbXhT1aTxBx287YKHRrJPNLFKsXEuV+PYR72R4ZF QaQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706194224; x=1706799024; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZysQ9KAcWXka70FvugQOSV9RayYcqOy7xI0fMhicphA=; b=EPDckN8V4kRj71k01PUhkFvdRFzw95GvR8NjO1B1kQnoBCLSM/elDs/bGxXeJKnKmI Ikor0c40Nb6Fgr25ghTuLBi9cHQC8vy2lqz7VN6xvZLegd1h4en3r0QV7BPQZN3gj3Fd IUVmiFwJL3n4g7t4lu1IP9ggdmvUQ55dj8VqfCuY/CXdUloPGS/vv6/rya965Z0YAK55 P5uP+fyV51fy6PH9/+DWzHZgq3r3S19Dcdr3t80NlHeZBRHpxSPWwcgKz6LSy0typXGy Scdz/X1yTSDKCn+JH9S4rgovYlXxsjPvIPkUbZZmyLA1OzRlQDdRAFk+4fphOP6rqM8r CE2A== X-Gm-Message-State: AOJu0Yy08cAkx6T4QFaIIHJmwWdfpauGLJA/6AQGbPqB9+q8M4v55Udz mUssfOi0/nMw+4gXgrgTg8Zx0iZxmDYryYHfBbtHD2FGjp1398AVhvjKOGbgbq8= X-Received: by 2002:a05:600c:3003:b0:40e:474f:94d8 with SMTP id j3-20020a05600c300300b0040e474f94d8mr577969wmh.177.1706194224662; Thu, 25 Jan 2024 06:50:24 -0800 (PST) Received: from ta2.c.googlers.com.com (88.140.78.34.bc.googleusercontent.com. [34.78.140.88]) by smtp.gmail.com with ESMTPSA id v17-20020a05600c471100b0040d91fa270fsm2875875wmo.36.2024.01.25.06.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 06:50:24 -0800 (PST) From: Tudor Ambarus To: broonie@kernel.org, andi.shyti@kernel.org, arnd@arndb.de Cc: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, alim.akhtar@samsung.com, linux-spi@vger.kernel.org, linux-samsung-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, andre.draszik@linaro.org, peter.griffin@linaro.org, semen.protsenko@linaro.org, kernel-team@android.com, willmcvicker@google.com, Tudor Ambarus Subject: [PATCH v2 16/28] spi: s3c64xx: simplify s3c64xx_wait_for_pio() Date: Thu, 25 Jan 2024 14:49:54 +0000 Message-ID: <20240125145007.748295-17-tudor.ambarus@linaro.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240125145007.748295-1-tudor.ambarus@linaro.org> References: <20240125145007.748295-1-tudor.ambarus@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit s3c64xx_spi_transfer_one() makes sure that for PIO the xfer->len is always smaller than the fifo size. Since we can't receive more that the FIFO size, droop the loop handling, the code becomes less misleading. Signed-off-by: Tudor Ambarus --- drivers/spi/spi-s3c64xx.c | 75 +++++++++------------------------------ 1 file changed, 17 insertions(+), 58 deletions(-) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index d2dd28ff00c6..00a0878aeb80 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -485,26 +485,6 @@ static int s3c64xx_enable_datapath(struct s3c64xx_spi_driver_data *sdd, return 0; } -static u32 s3c64xx_spi_wait_for_timeout(struct s3c64xx_spi_driver_data *sdd, - int timeout_ms) -{ - void __iomem *regs = sdd->regs; - unsigned long val = 1; - u32 status; - u32 max_fifo = FIFO_DEPTH(sdd); - - if (timeout_ms) - val = msecs_to_loops(timeout_ms); - - do { - status = readl(regs + S3C64XX_SPI_STATUS); - } while (FIELD_GET(S3C64XX_SPI_ST_RX_FIFO_LVL, status) < max_fifo && - --val); - - /* return the actual received data length */ - return FIELD_GET(S3C64XX_SPI_ST_RX_FIFO_LVL, status); -} - static int s3c64xx_wait_for_dma(struct s3c64xx_spi_driver_data *sdd, struct spi_transfer *xfer) { @@ -553,13 +533,11 @@ static int s3c64xx_wait_for_pio(struct s3c64xx_spi_driver_data *sdd, struct spi_transfer *xfer, bool use_irq) { void __iomem *regs = sdd->regs; + u8 *buf = xfer->rx_buf; + unsigned long time_us; unsigned long val; - u32 status; - int loops; - u32 cpy_len; - u8 *buf; + u32 status, len; int ms; - unsigned long time_us; /* microsecs to xfer 'len' bytes @ 'cur_speed' */ time_us = (xfer->len * 8 * 1000 * 1000) / sdd->cur_speed; @@ -582,48 +560,29 @@ static int s3c64xx_wait_for_pio(struct s3c64xx_spi_driver_data *sdd, status = readl(regs + S3C64XX_SPI_STATUS); } while (FIELD_GET(S3C64XX_SPI_ST_RX_FIFO_LVL, status) < xfer->len && --val); - if (!val) return -EIO; /* If it was only Tx */ - if (!xfer->rx_buf) { + if (!buf) { sdd->state &= ~TXBUSY; return 0; } - /* - * If the receive length is bigger than the controller fifo - * size, calculate the loops and read the fifo as many times. - * loops = length / max fifo size (calculated by using the - * fifo mask). - * For any size less than the fifo size the below code is - * executed atleast once. - */ - loops = xfer->len / FIFO_DEPTH(sdd); - buf = xfer->rx_buf; - do { - /* wait for data to be received in the fifo */ - cpy_len = s3c64xx_spi_wait_for_timeout(sdd, - (loops ? ms : 0)); - - switch (sdd->cur_bpw) { - case 32: - ioread32_rep(regs + S3C64XX_SPI_RX_DATA, - buf, cpy_len / 4); - break; - case 16: - ioread16_rep(regs + S3C64XX_SPI_RX_DATA, - buf, cpy_len / 2); - break; - default: - ioread8_rep(regs + S3C64XX_SPI_RX_DATA, - buf, cpy_len); - break; - } + len = FIELD_GET(S3C64XX_SPI_ST_RX_FIFO_LVL, status); + + switch (sdd->cur_bpw) { + case 32: + ioread32_rep(regs + S3C64XX_SPI_RX_DATA, buf, len / 4); + break; + case 16: + ioread16_rep(regs + S3C64XX_SPI_RX_DATA, buf, len / 2); + break; + default: + ioread8_rep(regs + S3C64XX_SPI_RX_DATA, buf, len); + break; + } - buf = buf + cpy_len; - } while (loops--); sdd->state &= ~RXBUSY; return 0; -- 2.43.0.429.g432eaa2c6b-goog