From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/4] mci: sdhci: reduce duplication in sdhci_wait_idle[_data]
Date: Wed, 2 Jul 2025 13:01:39 +0200 [thread overview]
Message-ID: <20250702110139.2235318-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250702110139.2235318-1-a.fatoum@pengutronix.de>
Now that the two functions look nearly identical, let's factor out the
common parts into a helper function and keep only the differences.
In future, we may export only a single function once the implications
are better understood, but even now, it's already a win for readability.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/mci/sdhci.c | 42 ++++++++++++++----------------------------
1 file changed, 14 insertions(+), 28 deletions(-)
diff --git a/drivers/mci/sdhci.c b/drivers/mci/sdhci.c
index f0c95f2dbfa8..2d32a8b31188 100644
--- a/drivers/mci/sdhci.c
+++ b/drivers/mci/sdhci.c
@@ -821,17 +821,12 @@ void sdhci_enable_clk(struct sdhci *host, u16 clk)
sdhci_write16(host, SDHCI_CLOCK_CONTROL, clk);
}
-int sdhci_wait_idle(struct sdhci *host, struct mci_cmd *cmd, struct mci_data *data)
+static int __sdhci_wait_idle(struct sdhci *host, struct mci_cmd *cmd,
+ struct mci_data *data, u32 mask)
{
- u32 mask;
ktime_t timeout_ns;
int ret;
- mask = SDHCI_CMD_INHIBIT_CMD;
-
- if (data || (cmd && (cmd->resp_type & MMC_RSP_BUSY)))
- mask |= SDHCI_CMD_INHIBIT_DATA;
-
if (cmd && (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION ||
mmc_op_tuning(cmd->cmdidx)))
mask &= ~SDHCI_CMD_INHIBIT_DATA;
@@ -849,30 +844,21 @@ int sdhci_wait_idle(struct sdhci *host, struct mci_cmd *cmd, struct mci_data *da
return 0;
}
+int sdhci_wait_idle(struct sdhci *host, struct mci_cmd *cmd, struct mci_data *data)
+{
+ u32 mask = SDHCI_CMD_INHIBIT_CMD;
+
+ if (data || (cmd && (cmd->resp_type & MMC_RSP_BUSY)))
+ mask |= SDHCI_CMD_INHIBIT_DATA;
+
+ return __sdhci_wait_idle(host, cmd, data, mask);
+}
+
int sdhci_wait_idle_data(struct sdhci *host, struct mci_cmd *cmd)
{
- u32 mask;
- ktime_t timeout_ns;
- int ret;
+ u32 mask = SDHCI_CMD_INHIBIT_CMD | SDHCI_CMD_INHIBIT_DATA;
- mask = SDHCI_CMD_INHIBIT_CMD | SDHCI_CMD_INHIBIT_DATA;
-
- if (cmd && (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION ||
- mmc_op_tuning(cmd->cmdidx)))
- mask &= ~SDHCI_CMD_INHIBIT_DATA;
-
- timeout_ns = sdhci_compute_timeout(cmd, NULL);
-
- ret = wait_on_timeout(timeout_ns,
- !(sdhci_read32(host, SDHCI_PRESENT_STATE) & mask));
-
- if (ret) {
- dev_err(sdhci_dev(host),
- "SDHCI timeout while waiting for idle\n");
- return -EBUSY;
- }
-
- return 0;
+ return __sdhci_wait_idle(host, cmd, NULL, mask);
}
void sdhci_set_clock(struct sdhci *host, unsigned int clock, unsigned int input_clock)
--
2.39.5
prev parent reply other threads:[~2025-07-02 12:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-02 11:01 [PATCH 0/4] mci: clean up MCI idle delay handling a bit Ahmad Fatoum
2025-07-02 11:01 ` [PATCH 1/4] include: linux/iopoll.h: evaluate timeout_us argument only once Ahmad Fatoum
2025-07-02 11:01 ` [PATCH 2/4] mci: bcm2835: allow core to request timeouts longer than 100ms Ahmad Fatoum
2025-07-02 11:01 ` [PATCH 3/4] mci: sdhci: use sdhci_compute_timeout in sdhci_wait_idle[_data] Ahmad Fatoum
2025-07-02 11:01 ` Ahmad Fatoum [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250702110139.2235318-5-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox