Skip to content

Commit 901d16e

Browse files
jmentistorulf
authored andcommitted
mmc: sdhci_am654: Add retry tuning
Add retry tuning up to 10 times if we fail to find a failing region or no passing itapdly. This is necessary since some eMMC has been observed to never find a failing itapdly on the first couple of tuning iterations, but eventually does. Keep count of current tuning iteration using tuning_loop. It has been observed that the tuning algorithm does not need to loop more than 10 times before finding a failing itapdly. Signed-off-by: Judith Mendez <[email protected]> Acked-by: Adrian Hunter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent 7e85661 commit 901d16e

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

drivers/mmc/host/sdhci_am654.c

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686

8787
#define CLOCK_TOO_SLOW_HZ 50000000
8888
#define SDHCI_AM654_AUTOSUSPEND_DELAY -1
89+
#define RETRY_TUNING_MAX 10
8990

9091
/* Command Queue Host Controller Interface Base address */
9192
#define SDHCI_AM654_CQE_BASE_ADDR 0x200
@@ -151,6 +152,7 @@ struct sdhci_am654_data {
151152
u32 flags;
152153
u32 quirks;
153154
bool dll_enable;
155+
u32 tuning_loop;
154156

155157
#define SDHCI_AM654_QUIRK_FORCE_CDTEST BIT(0)
156158
};
@@ -443,22 +445,23 @@ static u32 sdhci_am654_cqhci_irq(struct sdhci_host *host, u32 intmask)
443445
#define ITAPDLY_LENGTH 32
444446
#define ITAPDLY_LAST_INDEX (ITAPDLY_LENGTH - 1)
445447

446-
static u32 sdhci_am654_calculate_itap(struct sdhci_host *host, struct window
448+
static int sdhci_am654_calculate_itap(struct sdhci_host *host, struct window
447449
*fail_window, u8 num_fails, bool circular_buffer)
448450
{
449451
u8 itap = 0, start_fail = 0, end_fail = 0, pass_length = 0;
450452
u8 first_fail_start = 0, last_fail_end = 0;
451-
struct device *dev = mmc_dev(host->mmc);
452453
struct window pass_window = {0, 0, 0};
453454
int prev_fail_end = -1;
454455
u8 i;
455456

456-
if (!num_fails)
457-
return ITAPDLY_LAST_INDEX >> 1;
457+
if (!num_fails) {
458+
/* Retry tuning */
459+
return -1;
460+
}
458461

459462
if (fail_window->length == ITAPDLY_LENGTH) {
460-
dev_err(dev, "No passing ITAPDLY, return 0\n");
461-
return 0;
463+
/* Retry tuning */
464+
return -1;
462465
}
463466

464467
first_fail_start = fail_window->start;
@@ -494,8 +497,8 @@ static u32 sdhci_am654_calculate_itap(struct sdhci_host *host, struct window
494497
return (itap > ITAPDLY_LAST_INDEX) ? ITAPDLY_LAST_INDEX >> 1 : itap;
495498
}
496499

497-
static int sdhci_am654_platform_execute_tuning(struct sdhci_host *host,
498-
u32 opcode)
500+
static int sdhci_am654_do_tuning(struct sdhci_host *host,
501+
u32 opcode)
499502
{
500503
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
501504
struct sdhci_am654_data *sdhci_am654 = sdhci_pltfm_priv(pltfm_host);
@@ -532,13 +535,30 @@ static int sdhci_am654_platform_execute_tuning(struct sdhci_host *host,
532535
if (fail_window[fail_index].length != 0)
533536
fail_index++;
534537

535-
itap = sdhci_am654_calculate_itap(host, fail_window, fail_index,
536-
sdhci_am654->dll_enable);
538+
return sdhci_am654_calculate_itap(host, fail_window, fail_index,
539+
sdhci_am654->dll_enable);
540+
}
537541

538-
sdhci_am654_write_itapdly(sdhci_am654, itap, sdhci_am654->itap_del_ena[timing]);
542+
static int sdhci_am654_platform_execute_tuning(struct sdhci_host *host,
543+
u32 opcode)
544+
{
545+
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
546+
struct sdhci_am654_data *sdhci_am654 = sdhci_pltfm_priv(pltfm_host);
547+
unsigned char timing = host->mmc->ios.timing;
548+
int itapdly;
539549

550+
do {
551+
itapdly = sdhci_am654_do_tuning(host, opcode);
552+
if (itapdly >= 0)
553+
break;
554+
} while (++sdhci_am654->tuning_loop < RETRY_TUNING_MAX);
555+
556+
if (itapdly < 0)
557+
return -1;
558+
559+
sdhci_am654_write_itapdly(sdhci_am654, itapdly, sdhci_am654->itap_del_ena[timing]);
540560
/* Save ITAPDLY */
541-
sdhci_am654->itap_del_sel[timing] = itap;
561+
sdhci_am654->itap_del_sel[timing] = itapdly;
542562

543563
return 0;
544564
}
@@ -742,6 +762,9 @@ static int sdhci_am654_init(struct sdhci_host *host)
742762
regmap_update_bits(sdhci_am654->base, CTL_CFG_3, TUNINGFORSDR50_MASK,
743763
TUNINGFORSDR50_MASK);
744764

765+
/* Use to re-execute tuning */
766+
sdhci_am654->tuning_loop = 0;
767+
745768
ret = sdhci_setup_host(host);
746769
if (ret)
747770
return ret;

0 commit comments

Comments
 (0)