Skip to contentSkip to conversation

mmc: mxs-mmc driver, correct timeout calculation

PATCH New Elie De Brauwer 1 participant 1 message Feb 9, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: mxs-mmc driver, correct timeout calculation

All,

I bumped into an issue with the mxs_ns_to_ssp_ticks() function used in the mxs-mmc.c host. I found out during some testing that when I requested a timeout of 10 msecs, I actually ended up with a 10 second-long timeout.

If you look at the mxs_ns_to_ssp_ticks function, you see that they take the following steps:
- store the number of clock ticks in a milliseconds
- converts the timeout in nssec to a timeout in msec
- multiplying these two together gives the total number of ticks
- divide this by 4096 (*)

This flow makes sense, but in order to convert the timeout in ns to a timeout in seconds, one should divide by 1000000 not by 1000 (which gives the timeout in usecs). Which also explains the offset by a thousand observed in my tests.

(*) 4096 is specified in o.a. the i.MX283 reference manual page 1339, the register stores the value in the multiples of 4096 clockticks.

Below you can find trivial patch to correct this.

my 2 cents
E.

(ps, please cc me, since I'm not on the list).

---
 drivers/mmc/host/mxs-mmc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/mxs-mmc.c +1 -1
index 206fe49..f25f7fe 100644
@@ -339,7 +339,7 @@ static unsigned short mxs_ns_to_ssp_ticks(unsigned clock_rate, unsigned ns)
 	 * and might overflow
 	 */
 	const unsigned int clock_per_ms = clock_rate / 1000;
-	const unsigned int ms = ns / 1000;
+	const unsigned int ms = ns / 1000000;
 	const unsigned int ticks = ms * clock_per_ms;
 	const unsigned int ssp_ticks = ticks / ssp_timeout_mul;
 
Signature · 1 line
1.7.10.4