Commit fb823981c550f873270666ce0f6117dbb956c214

Authored by Andrew Gabbasov
Committed by Pantelis Antoniou
1 parent 33ace362fd

mmc: fsl_esdhc: fix calculation of timeout for data transactions

Calculation of the timeout value should be based on actual clock value,
written to controller registers. Since mmc->tran_speed is either the
maximum allowed speed, or the preliminary value, that is be not yet
set to registers, the actual timeout, taken by the controller, based
on its clock settings, may be much longer than expected, based on
mmc->tran_speed value. In particular it happens at early initialization
stage, when typical value of mmc->tran_speed is 20MHz or 26MHz, while
actual clock setting, configured in the controller, is 400kHz.
It's more correct to use mmc->clock value for timeout calculation instead.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>

Showing 1 changed file with 6 additions and 6 deletions Side-by-side Diff

drivers/mmc/fsl_esdhc.c
... ... @@ -221,16 +221,16 @@
221 221 * 2)Timeout period should be minimum 0.250sec as per SD Card spec
222 222 * So, Number of SD Clock cycles for 0.25sec should be minimum
223 223 * (SD Clock/sec * 0.25 sec) SD Clock cycles
224   - * = (mmc->tran_speed * 1/4) SD Clock cycles
  224 + * = (mmc->clock * 1/4) SD Clock cycles
225 225 * As 1) >= 2)
226   - * => (2^(timeout+13)) >= mmc->tran_speed * 1/4
  226 + * => (2^(timeout+13)) >= mmc->clock * 1/4
227 227 * Taking log2 both the sides
228   - * => timeout + 13 >= log2(mmc->tran_speed/4)
  228 + * => timeout + 13 >= log2(mmc->clock/4)
229 229 * Rounding up to next power of 2
230   - * => timeout + 13 = log2(mmc->tran_speed/4) + 1
231   - * => timeout + 13 = fls(mmc->tran_speed/4)
  230 + * => timeout + 13 = log2(mmc->clock/4) + 1
  231 + * => timeout + 13 = fls(mmc->clock/4)
232 232 */
233   - timeout = fls(mmc->tran_speed/4);
  233 + timeout = fls(mmc->clock/4);
234 234 timeout -= 13;
235 235  
236 236 if (timeout > 14)