From patchwork Wed May 22 23:31:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 798186 Delivered-To: patch@linaro.org Received: by 2002:ab3:6414:0:b0:267:d849:ee76 with SMTP id j20csp917645lte; Wed, 22 May 2024 16:33:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU83WQTEpImdlpeg5yMvNWx97k09oh0h6mldLKNr+Ffv35E4R8nkDPhx+bOGdkTUSEbJNqCPcsIZVV/Pe1lUx40 X-Google-Smtp-Source: AGHT+IFNSg0uC0nGWgkAZlCMjChUJfevb154t/mz09mQAM9dzVlGSW9WL4fZCRD0ccXw/jBdAMnS X-Received: by 2002:a05:651c:c6:b0:2d8:3e60:b9c9 with SMTP id 38308e7fff4ca-2e949540f51mr20525381fa.33.1716420784161; Wed, 22 May 2024 16:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716420784; cv=none; d=google.com; s=arc-20160816; b=alL7WqRULd+WXGApgndvLAHGYaFLJZmd5o3SYfGPl+2yUvxdhIasZNULN1Cmjg42P/ FfMeTrC4I6WZcLDUrWB5o/WEPPc4SDhB2PUVLdX6Sk/D3vprIvVzEAFUTYMBlB5Je5HL BxfQ8ZQaIcU4+Y8ynABlF/a3d7xCcg5Z2r9BgIewgzlWpDg1PKS7Dn6sB5kh3oo0+r/t qarnYyNLSr+3RTCnO0J4xIBo2+l/Q/wxuexABKaWUrpeFqvH2PEieAw+dg4OmnbaGiIe qtUhD5F5Q6JxRj1zot9KK/3ydIqkZLifYBpHbv9bE0GJRjGLiiyTcSoYIf/sOUezpi2y K1lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=up20KcUHKaWbwVwB7lK+qX3BMiB3ScqRXF1dCSdqfWg=; fh=FHCgR61fMhvjGtSHlaRcX5S3FVMvzA3QxQVg+EJj5bw=; b=STLx0D203scTFmZ/9+LvX3hC8VXEcdzdnYW0ilqxxwMrhn3jTO5+Qc2XEpDWOSPOJK /oOyw4doZ803yqU1r6e367XI7MlT1k1Vv6xJd02+1wZfOVsZxAp2GIFNj6K3Z1Zlhanc cfpWbUvYPGxnhQqpRdLbH2aEMzrWQzGwUJ13WoOcdGuyAq0FwTSTg0RdEoMJ7pcW7VQi 7zCfLoxDZ6PFYk8sk8TYFLCI8b0xW5K0BzkBGcMbDMalgSaw9fQx3ilWk+LVyzC4czBr Hv5sWcFhE0k11gDf6hKrRtK38QDu5KQJaXCBkbahzh9QaNBMbawR2WzmJNr13QnLqVg5 ZX+w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="NQwVI/yY"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57814bc9800si3288172a12.43.2024.05.22.16.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 16:33:04 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="NQwVI/yY"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B9C7288542; Thu, 23 May 2024 01:31:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="NQwVI/yY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B7191884F9; Thu, 23 May 2024 01:31: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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 69D51884EE for ; Thu, 23 May 2024 01:31:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=semen.protsenko@linaro.org Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6f1016f41e2so2689034a34.1 for ; Wed, 22 May 2024 16:31:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716420702; x=1717025502; darn=lists.denx.de; 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=up20KcUHKaWbwVwB7lK+qX3BMiB3ScqRXF1dCSdqfWg=; b=NQwVI/yYlkaV4gDmM/tI/L5k9BuLv93k7CTnDD9fZmkPBV4jFiTxr9hoIhkEgAMwZo LHP8IqvprpnPk+vzMJA38Ow07HkiVErSvboC5RS7nsC1Cm2KUtqCNdFqA3dWbobpHWy9 tKA3eTONRSbdQI5E3U3ErK5i+uo3xqPNSd9jkJYYRDdBDMAtcduAgLVzFRrdoz0OEJaw Aid5IC3ShEe3wDt/UKs9t3uGbvlooXsmt4//TqvVeuzXQALjImjIU61y2b2F99lsxMVE xGM1aL9oSFc1jErxCUnRaBhyZM+KuIMTB+Ac7P4cQ+Rt9mBjCRrXfU6E3nwEsDo45jCa Fl5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716420702; x=1717025502; 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=up20KcUHKaWbwVwB7lK+qX3BMiB3ScqRXF1dCSdqfWg=; b=K6CZWsFB31B7VuxzZjHHpx9SlJw8oHIvzlijtQcDHtDevmMLazAIfut2rItWDvyX3X wjRf0S2mQiwKcGbuzemRTJ3uUzuwE4RqDNa1Mk1fH00VtsoYEA4RKgew+o0vMdRhgV27 kTp2MfKH4lp0VzZP6J5S/krA4gRSo++FxCUKZ90BGT8EZ3a2UBpHvU6082YhnMa2wkv2 q+hhE7MoS32KS7kC12tZFeizi83UoE6T6hZ8mCy6kUMfgE3CzXarkyW/pl7SLRPwMaxm B42F+TCPLWR0VqWV/qh81rWDzNCfdx2EhmKm9tbk/DTXUuRbVQ52z8K7gY7KlIB1PF5+ AQQw== X-Forwarded-Encrypted: i=1; AJvYcCUL5pEdHGq4oWB/qVgP26jf4wf+0q6zDbekSm6zly0vELXM9qBgVlrFwgUmdPb6elwUMYo2Pxrk2KKEWQETQoc1z4mqFw== X-Gm-Message-State: AOJu0YyYIgMJszXNGQSLUZkpYkNJo9q7nO7yqcurvx7wuyG9x6ZkQMao iItWweAv/oHXo7854xvZOIbkNbm36sv0U9prK5x/wbgMoplgGZZYn18nWLiu2sE= X-Received: by 2002:a9d:740e:0:b0:6ef:9dcd:56ad with SMTP id 46e09a7af769-6f66a59e8f1mr3230956a34.38.1716420701745; Wed, 22 May 2024 16:31:41 -0700 (PDT) Received: from localhost ([136.62.192.75]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-6f0e7471924sm4963127a34.17.2024.05.22.16.31.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 16:31:41 -0700 (PDT) From: Sam Protsenko To: Tom Rini , Minkyu Kang , Peng Fan , Jaehoon Chung , Simon Glass Cc: Philipp Tomsich , Kever Yang , Eugeniy Paltsev , Peter Robinson , Jonas Karlman , Yang Xiwen , Ferass El Hafidi , Sean Anderson , u-boot@lists.denx.de, uboot-snps-arc@synopsys.com Subject: [PATCH 07/42] mmc: dw_mmc: Extract FIFO data transfer into a separate routine Date: Wed, 22 May 2024 18:31:00 -0500 Message-Id: <20240522233135.26835-8-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240522233135.26835-1-semen.protsenko@linaro.org> References: <20240522233135.26835-1-semen.protsenko@linaro.org> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean FIFO data transfer is implemented as quite a massive chunk of code. Extract it into a dedicated function to make dwmci_data_transfer() easier to read and reduce the indentation level of the code. No functional change. Signed-off-by: Sam Protsenko --- drivers/mmc/dw_mmc.c | 107 +++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c index 40b9b034f793..144f29f09240 100644 --- a/drivers/mmc/dw_mmc.c +++ b/drivers/mmc/dw_mmc.c @@ -140,25 +140,67 @@ static unsigned int dwmci_get_timeout(struct mmc *mmc, const unsigned int size) return timeout; } -static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data) +static int dwmci_data_transfer_fifo(struct dwmci_host *host, + struct mmc_data *data, u32 mask) { - struct mmc *mmc = host->mmc; + const u32 fifo_depth = (((host->fifoth_val & RX_WMARK_MASK) >> + RX_WMARK_SHIFT) + 1) * 2; + const u32 int_rx = mask & (DWMCI_INTMSK_RXDR | DWMCI_INTMSK_DTO); + const u32 int_tx = mask & DWMCI_INTMSK_TXDR; int ret = 0; - u32 timeout, mask, size, i, len = 0; - u32 *buf = NULL; - ulong start = get_timer(0); - u32 fifo_depth = (((host->fifoth_val & RX_WMARK_MASK) >> - RX_WMARK_SHIFT) + 1) * 2; + u32 len = 0, size, i; + u32 *buf; + + size = (data->blocksize * data->blocks) / 4; + if (!host->fifo_mode || !size) + return 0; - size = data->blocksize * data->blocks; if (data->flags == MMC_DATA_READ) buf = (unsigned int *)data->dest; else buf = (unsigned int *)data->src; - timeout = dwmci_get_timeout(mmc, size); + if (data->flags == MMC_DATA_READ && int_rx) { + dwmci_writel(host, DWMCI_RINTSTS, int_rx); + while (size) { + ret = dwmci_fifo_ready(host, DWMCI_FIFO_EMPTY, &len); + if (ret < 0) + break; + + len = (len >> DWMCI_FIFO_SHIFT) & DWMCI_FIFO_MASK; + len = min(size, len); + for (i = 0; i < len; i++) + *buf++ = dwmci_readl(host, DWMCI_DATA); + size = size > len ? (size - len) : 0; + } + } else if (data->flags == MMC_DATA_WRITE && int_tx) { + while (size) { + ret = dwmci_fifo_ready(host, DWMCI_FIFO_FULL, &len); + if (ret < 0) + break; + + len = fifo_depth - ((len >> DWMCI_FIFO_SHIFT) & + DWMCI_FIFO_MASK); + len = min(size, len); + for (i = 0; i < len; i++) + dwmci_writel(host, DWMCI_DATA, *buf++); + size = size > len ? (size - len) : 0; + } + dwmci_writel(host, DWMCI_RINTSTS, DWMCI_INTMSK_TXDR); + } - size /= 4; + return ret; +} + +static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data) +{ + struct mmc *mmc = host->mmc; + int ret = 0; + u32 timeout, mask, size; + ulong start = get_timer(0); + + size = data->blocksize * data->blocks; + timeout = dwmci_get_timeout(mmc, size); for (;;) { mask = dwmci_readl(host, DWMCI_RINTSTS); @@ -169,50 +211,7 @@ static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data) break; } - if (host->fifo_mode && size) { - len = 0; - if (data->flags == MMC_DATA_READ && - (mask & (DWMCI_INTMSK_RXDR | DWMCI_INTMSK_DTO))) { - dwmci_writel(host, DWMCI_RINTSTS, - mask & (DWMCI_INTMSK_RXDR | - DWMCI_INTMSK_DTO)); - while (size) { - ret = dwmci_fifo_ready(host, - DWMCI_FIFO_EMPTY, - &len); - if (ret < 0) - break; - - len = (len >> DWMCI_FIFO_SHIFT) & - DWMCI_FIFO_MASK; - len = min(size, len); - for (i = 0; i < len; i++) - *buf++ = - dwmci_readl(host, DWMCI_DATA); - size = size > len ? (size - len) : 0; - } - } else if (data->flags == MMC_DATA_WRITE && - (mask & DWMCI_INTMSK_TXDR)) { - while (size) { - ret = dwmci_fifo_ready(host, - DWMCI_FIFO_FULL, - &len); - if (ret < 0) - break; - - len = fifo_depth - ((len >> - DWMCI_FIFO_SHIFT) & - DWMCI_FIFO_MASK); - len = min(size, len); - for (i = 0; i < len; i++) - dwmci_writel(host, DWMCI_DATA, - *buf++); - size = size > len ? (size - len) : 0; - } - dwmci_writel(host, DWMCI_RINTSTS, - DWMCI_INTMSK_TXDR); - } - } + ret = dwmci_data_transfer_fifo(host, data, mask); /* Data arrived correctly. */ if (mask & DWMCI_INTMSK_DTO) {