Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 243800c6 authored by Venkat Gopalakrishnan's avatar Venkat Gopalakrishnan
Browse files

mmc: mmc_ops: Add retry mechanism to mmc_switch



Some devices do not honor the max switch timeout exposed via
ext_csd, they take longer than that to complete the switch.
Hence add a retry mechanism to wait longer for the card to
get out of programming state before timing out.

Change-Id: Ica46e30df24b4f95f457271087e1e03823ed2959
Signed-off-by: default avatarVenkat Gopalakrishnan <venkatg@codeaurora.org>
parent 783bbd7d
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -478,6 +478,7 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
	unsigned long timeout;
	u32 status = 0;
	bool use_r1b_resp = use_busy_signal;
	int retries = 5;

	/*
	 * If the cmd timeout and the max_busy_timeout of the host are both
@@ -551,9 +552,15 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,

		/* Timeout if the device never leaves the program state. */
		if (time_after(jiffies, timeout)) {
			pr_err("%s: Card stuck in programming state! %s\n",
				mmc_hostname(host), __func__);
			pr_err("%s: Card stuck in programming state! %s, timeout:%ums, retries:%d\n",
				mmc_hostname(host), __func__,
				timeout_ms, retries);
			if (retries)
				timeout = jiffies +
						msecs_to_jiffies(timeout_ms);
			else
				return -ETIMEDOUT;
			retries--;
		}
	} while (R1_CURRENT_STATE(status) == R1_STATE_PRG);