Skip to content

Commit 6e860b0

Browse files
committed
mmc: Merge branch fixes into next
Merge the mmc fixes for v6.8-rc[n] into the next branch, to allow them to get tested together with the new mmc changes that are targeted for v6.9. Signed-off-by: Ulf Hansson <[email protected]>
2 parents a119357 + 09e2382 commit 6e860b0

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

drivers/mmc/host/sdhci-xenon-phy.c

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/slab.h>
1212
#include <linux/delay.h>
1313
#include <linux/ktime.h>
14+
#include <linux/iopoll.h>
1415
#include <linux/of_address.h>
1516

1617
#include "sdhci-pltfm.h"
@@ -109,6 +110,8 @@
109110
#define XENON_EMMC_PHY_LOGIC_TIMING_ADJUST (XENON_EMMC_PHY_REG_BASE + 0x18)
110111
#define XENON_LOGIC_TIMING_VALUE 0x00AA8977
111112

113+
#define XENON_MAX_PHY_TIMEOUT_LOOPS 100
114+
112115
/*
113116
* List offset of PHY registers and some special register values
114117
* in eMMC PHY 5.0 or eMMC PHY 5.1
@@ -216,6 +219,19 @@ static int xenon_alloc_emmc_phy(struct sdhci_host *host)
216219
return 0;
217220
}
218221

222+
static int xenon_check_stability_internal_clk(struct sdhci_host *host)
223+
{
224+
u32 reg;
225+
int err;
226+
227+
err = read_poll_timeout(sdhci_readw, reg, reg & SDHCI_CLOCK_INT_STABLE,
228+
1100, 20000, false, host, SDHCI_CLOCK_CONTROL);
229+
if (err)
230+
dev_err(mmc_dev(host->mmc), "phy_init: Internal clock never stabilized.\n");
231+
232+
return err;
233+
}
234+
219235
/*
220236
* eMMC 5.0/5.1 PHY init/re-init.
221237
* eMMC PHY init should be executed after:
@@ -232,6 +248,11 @@ static int xenon_emmc_phy_init(struct sdhci_host *host)
232248
struct xenon_priv *priv = sdhci_pltfm_priv(pltfm_host);
233249
struct xenon_emmc_phy_regs *phy_regs = priv->emmc_phy_regs;
234250

251+
int ret = xenon_check_stability_internal_clk(host);
252+
253+
if (ret)
254+
return ret;
255+
235256
reg = sdhci_readl(host, phy_regs->timing_adj);
236257
reg |= XENON_PHY_INITIALIZAION;
237258
sdhci_writel(host, reg, phy_regs->timing_adj);
@@ -259,18 +280,27 @@ static int xenon_emmc_phy_init(struct sdhci_host *host)
259280
/* get the wait time */
260281
wait /= clock;
261282
wait++;
262-
/* wait for host eMMC PHY init completes */
263-
udelay(wait);
264283

265-
reg = sdhci_readl(host, phy_regs->timing_adj);
266-
reg &= XENON_PHY_INITIALIZAION;
267-
if (reg) {
284+
/*
285+
* AC5X spec says bit must be polled until zero.
286+
* We see cases in which timeout can take longer
287+
* than the standard calculation on AC5X, which is
288+
* expected following the spec comment above.
289+
* According to the spec, we must wait as long as
290+
* it takes for that bit to toggle on AC5X.
291+
* Cap that with 100 delay loops so we won't get
292+
* stuck here forever:
293+
*/
294+
295+
ret = read_poll_timeout(sdhci_readl, reg,
296+
!(reg & XENON_PHY_INITIALIZAION),
297+
wait, XENON_MAX_PHY_TIMEOUT_LOOPS * wait,
298+
false, host, phy_regs->timing_adj);
299+
if (ret)
268300
dev_err(mmc_dev(host->mmc), "eMMC PHY init cannot complete after %d us\n",
269-
wait);
270-
return -ETIMEDOUT;
271-
}
301+
wait * XENON_MAX_PHY_TIMEOUT_LOOPS);
272302

273-
return 0;
303+
return ret;
274304
}
275305

276306
#define ARMADA_3700_SOC_PAD_1_8V 0x1

0 commit comments

Comments
 (0)