[PATCH 3/4] mci: sdhci: use the busy_timeout value in the sdhci_wait_idle functions
Sebastien Bourdelin
sebastien.bourdelin at gmail.com
Thu Oct 31 02:27:20 PDT 2024
From: Sebastien Bourdelin <sebastien.bourdelin at rtone.fr>
The busy_timeout value is used by the sdhci_wait_idle and
sdhci_wait_idle_data functions to define the timeout to wait on when
send a command to the controller.
The default value remains unchanged and is set to 10ms.
Signed-off-by: Sebastien Bourdelin <sebastien.bourdelin at rtone.fr>
---
drivers/mci/sdhci.c | 14 ++++++++++++--
drivers/mci/sdhci.h | 2 ++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/mci/sdhci.c b/drivers/mci/sdhci.c
index fe033583ad..1425c72ef5 100644
--- a/drivers/mci/sdhci.c
+++ b/drivers/mci/sdhci.c
@@ -796,9 +796,11 @@ void sdhci_enable_clk(struct sdhci *host, u16 clk)
int sdhci_wait_idle(struct sdhci *host, struct mci_cmd *cmd, struct mci_data *data)
{
u32 mask;
+ unsigned timeout_ms;
int ret;
mask = SDHCI_CMD_INHIBIT_CMD;
+ timeout_ms = SDHCI_CMD_DEFAULT_BUSY_TIMEOUT;
if (data || (cmd && (cmd->resp_type & MMC_RSP_BUSY)))
mask |= SDHCI_CMD_INHIBIT_DATA;
@@ -806,7 +808,10 @@ int sdhci_wait_idle(struct sdhci *host, struct mci_cmd *cmd, struct mci_data *da
if (cmd && cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
mask &= ~SDHCI_CMD_INHIBIT_DATA;
- ret = wait_on_timeout(10 * MSECOND,
+ if (cmd && cmd->busy_timeout != 0)
+ timeout_ms = cmd->busy_timeout;
+
+ ret = wait_on_timeout(timeout_ms * MSECOND,
!(sdhci_read32(host, SDHCI_PRESENT_STATE) & mask));
if (ret) {
@@ -821,14 +826,19 @@ int sdhci_wait_idle(struct sdhci *host, struct mci_cmd *cmd, struct mci_data *da
int sdhci_wait_idle_data(struct sdhci *host, struct mci_cmd *cmd)
{
u32 mask;
+ unsigned timeout_ms;
int ret;
mask = SDHCI_CMD_INHIBIT_CMD | SDHCI_CMD_INHIBIT_DATA;
+ timeout_ms = SDHCI_CMD_DEFAULT_BUSY_TIMEOUT;
if (cmd && cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
mask &= ~SDHCI_CMD_INHIBIT_DATA;
- ret = wait_on_timeout(10 * MSECOND,
+ if (cmd && cmd->busy_timeout != 0)
+ timeout_ms = cmd->busy_timeout;
+
+ ret = wait_on_timeout(timeout_ms * MSECOND,
!(sdhci_read32(host, SDHCI_PRESENT_STATE) & mask));
if (ret) {
diff --git a/drivers/mci/sdhci.h b/drivers/mci/sdhci.h
index 5de85239b1..757840acc7 100644
--- a/drivers/mci/sdhci.h
+++ b/drivers/mci/sdhci.h
@@ -200,6 +200,8 @@
#define SDHCI_MAX_DIV_SPEC_200 256
#define SDHCI_MAX_DIV_SPEC_300 2046
+#define SDHCI_CMD_DEFAULT_BUSY_TIMEOUT 10
+
struct sdhci {
u32 (*read32)(struct sdhci *host, int reg);
u16 (*read16)(struct sdhci *host, int reg);
--
2.46.2
More information about the barebox
mailing list