• Al Cooper's avatar
    mmc: sdhci: SD tuning is broken for some controllers · 7ce45e95
    Al Cooper authored
    The SD Host Controller spec states that the SD Host Controller can
    request that the driver send up to 40 CMD19's while doing tuning
    and that the total time the card spends responding must be < 150ms.
    The sdhci_execute_tuning() function in sdhci.c that loops through
    sending the CMD19's has multiple bugs. First it sets a "timeout"
    variable to 150 and a loop counter variable to 40. It then decrements
    both variables by 1 at the end of each loop. It tries to handle
    violations of the count and time by doing a break when BOTH variables
    are equal to zero, which can never happen because they we set to
    different values and decremented by 1 at the same time. The timeout
    variable is not based on time at all and is totally useless.
    The routine also considers a loop counter of zero to be an error
    which means that any controller that requests the max of 40 CMD19s
    will cause tuning to fail and be disabled.
    
    I've fixed these issues by allowing up to 40 CMD19's and I've removed
    any attempt to handle the 150ms time limit. Removing timeout checking
    seems safe here because each CMD19 is timeout protected and the max
    loop counters insures we don't loop forever. Adding timeout checking
    would not be as simple as snapping the time at the loop start and
    checking for 150ms to pass because the loop queues the CMD19's and
    uses events to wait for completion so the time would include
    all the normal scheduler latencies.
    Signed-off-by: default avatarAl Cooper <alcooperx@gmail.com>
    Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
    Signed-off-by: default avatarChris Ball <chris@printf.net>
    7ce45e95
sdhci.c 86.7 KB