Skip to contentSkip to conversation

fsl_esdhc: Correcting esdhc timeout counter calculation

PATCH New Kumar Gala 6 participants 10 messages Feb 24, 2011 – Feb 25, 2011 MMC, SD and SDIO

lore
Share & tools
lore

Kumar Gala

author
#0 lore raw

PATCH 1/1 fsl_esdhc: Correcting esdhc timeout counter calculation

From: Priyanka Jain <[email protected]>

- Timeout counter value is set as DTOCV bits in SYSCTL register For counter value set as x,
Timeout period = (2^(13+x))/SD_CLOCK

- As per 4.6.2.2 section of SD Card specification v2.00, host should cofigure timeout period value to minimum 250 msec.

- SD_CLOCK = mmc->trans_speed

- Calculating x based on
250 msec = (2^(13+x))/mmc->trans_speed

---
 drivers/mmc/fsl_esdhc.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/mmc/fsl_esdhc.c +4 -1
index c6de751..6f8a09d 100644
@@ -210,7 +210,10 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
 	esdhc_write32(&regs->blkattr, data->blocks << 16 | data->blocksize);
 
 	/* Calculate the timeout period for data transactions */
-	timeout = fls(mmc->tran_speed/10) - 1;
+	/* Timeout period = (2^(13+timeout))/mmc->trans_speed
+	 * Timeout period should be minimum 250msec as per SD Card spec
+	 */
+	timeout = fls(mmc->tran_speed/4);
 	timeout -= 13;
 
 	if (timeout > 14)
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 1/1 fsl_esdhc: Correcting esdhc timeout counter calculation

Dear Kumar Gala,

Quoted 5 lines · In message <[email protected]> you…

- Timeout counter value is set as DTOCV bits in SYSCTL register For counter value set as x,
Timeout period = (2^(13+x))/SD_CLOCK

Quoted 7 lines

- As per 4.6.2.2 section of SD Card specification v2.00, host should cofigure timeout period value to minimum 250 msec.

- SD_CLOCK = mmc->trans_speed

- Calculating x based on
250 msec = (2^(13+x))/mmc->trans_speed

OK, here the theory is given...

drivers/mmc/fsl_esdhc.c static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data) · line 217

Quoted 5 lines
drivers/mmc/fsl_esdhc.c +4 -0
+	/* Timeout period = (2^(13+timeout))/mmc->trans_speed
+	 * Timeout period should be minimum 250msec as per SD Card spec
+	 */
+	timeout = fls(mmc->tran_speed/4);
 	timeout -= 13;

But how does this translate intothis formula? I think there must be missing something.

Also, should there not be some checking for valid input data ranges?

Nitpick: incorrect multi-line comment style.

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"There's always been Tower of Babel sort of  bickering  inside  Unix,
but  this  is the most extreme form ever. This means at least several
years of confusion." - Bill Gates, founder and chairman of Microsoft,
about the Open Systems Foundation
#2 lore raw

PATCH 1/1 fsl_esdhc: Correcting esdhc timeout counter calculation

Quoted 18 lines · Wolfgang Denk

Dear Kumar Gala,

Quoted 5 lines · In message <[email protected]> you…

- Timeout counter value is set as DTOCV bits in SYSCTL register ? For counter value set as x,
? Timeout period = (2^(13+x))/SD_CLOCK

Quoted 7 lines

- As per 4.6.2.2 section of SD Card specification v2.00, host should ? cofigure timeout period value to minimum 250 msec.

- SD_CLOCK = mmc->trans_speed

- Calculating x based on
? 250 msec = (2^(13+x))/mmc->trans_speed

OK, here the theory is given...

Quoted 8 lines
Quoted 5 lines

+ ? ? /* Timeout period = (2^(13+timeout))/mmc->trans_speed
+ ? ? ?* Timeout period should be minimum 250msec as per SD Card spec
+ ? ? ?*/
+ ? ? timeout = fls(mmc->tran_speed/4);
? ? ? timeout -= 13;

But how does this translate intothis formula? ?I think there must be missing something.

Yeah, that took me a while, too. Maybe we should update it to make clear:

1) The formula ends up being (2^(13 + timeout))/mmc->trans_speed = (1/4) seconds --> 2^(13 + timeout) = mmc->trans_speed/4
--> 13 + timeout = log2(mmc->trans_speed/4)
...etc

2) We are effectively rounding up to the next highest power of 2 to make sure the timeout is *at least* 250ms

Andy

#3 lore raw

PATCH 1/1 fsl_esdhc: Correcting esdhc timeout counter calculation

Dear Andy Fleming,

Quoted 7 lines · In message <[email protected]> you…

Yeah, that took me a while, too. Maybe we should update it to make clear:

1) The formula ends up being (2^(13 + timeout))/mmc->trans_speed = (1/4) seconds --> 2^(13 + timeout) = mmc->trans_speed/4
--> 13 + timeout = log2(mmc->trans_speed/4)
...etc

Does this not depend on the units used for speed, and thus in the end on CONFIC_SYS_HZ ?

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The use of COBOL cripples the mind; its teaching  should,  therefore,
be regarded as a criminal offence.
          -- Edsger W. Dijkstra, SIGPLAN Notices, Volume 17, Number 5
#4 lore raw

PATCH 1/1 fsl_esdhc: Correcting esdhc timeout counter calculation

Dear Wolgang Denk

Quoted 17 lines

-----Original Message-----
From: Wolfgang Denk [mailto:wd at denx.de]
Sent: Friday, February 25, 2011 11:06 AM
To: Andy Fleming
Cc: Kumar Gala; u-boot at lists.denx.de; Fleming Andy-AFLEMING; Jain Priyanka-B32167
Subject: Re: [U-Boot] [PATCH] fsl_esdhc: Correcting esdhc timeout counter calculation

Dear Andy Fleming,

In message <[email protected]>

Quoted 2 lines · you

Yeah, that took me a while, too. Maybe we should update it to make

clear:

Quoted 1 line
Quoted 9 lines
Quoted 5 lines

1) The formula ends up being (2^(13 + timeout))/mmc->trans_speed = (1/4) seconds
--> 2^(13 + timeout) = mmc->trans_speed/4
--> 13 + timeout = log2(mmc->trans_speed/4)
...etc

Does this not depend on the units used for speed, and thus in the end on CONFIC_SYS_HZ ?

We are using absolute figures. So this code is independent of units of speed. For standard speed cards, mmc->tran_speed is 25000000.
Code snippet(mmc.c) of setting tran_speed is:

        /* divide frequency by 10, since the mults are 10x bigger */
        freq = fbase[(cmd.response[0] & 0x7)];
        mult = multipliers[((cmd.response[0] >> 3) & 0xf)];
        mmc->tran_speed = freq * mult;
Quoted 11 lines

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence.
-- Edsger W. Dijkstra, SIGPLAN Notices, Volume 17, Number 5

#5 lore raw

PATCH 1/1 fsl_esdhc: Correcting esdhc timeout counter calculation

Dear Jain Priyanka-B32167,

Quoted 11 lines · In message <470DB7CE2CD0944E9436E7ADEFC02FE3138B4C@039-SN1MPN1-003.039d.mgd.msf…
Quoted 10 lines
Quoted 6 lines

1) The formula ends up being (2^(13 + timeout))/mmc->trans_speed =3D (1/4) seconds
--> 2^(13 + timeout) = mmc->trans_speed/4
--> 13 + timeout = log2(mmc->trans_speed/4)
...etc

Does this not depend on the units used for speed, and thus in the end on CONFIC_SYS_HZ ?

We are using absolute figures. So this code is independent of units of speed.

Funny you should say that.

Quoted 1 line

For standard speed cards, mmc->tran_speed is 25000000.

"Speed" is always some unit per time. Your 'absolute" number 25000000 here makes no sense if you cannot tell what it means. Is it bits per millisecond? Bytes per week? Nibbles per year?

Quoted 4 lines
        /* divide frequency by 10, since the mults are 10x bigger */
        freq = fbase[(cmd.response[0] & 0x7)];
        mult = multipliers[((cmd.response[0] >> 3) & 0xf)];
        mmc->tran_speed = freq * mult;

You don't have any "absolute figures" here. A frequency is defined to measure events per time, so it is important to give the unit used. Is frequency in Hz, or in kHz, or in MHz, or what?

It is impossible for the reader to verify the correctness of the code if you don't provide such information, so please document your code in a way that makes it possible to check it.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"I haven't lost my mind - it's backed up on tape somewhere."
#6 lore raw

PATCH 1/1 fsl_esdhc: Correcting esdhc timeout counter calculation

In reply to Wolfgang Denk
Quoted 6 lines · Wolfgang Denk

Dear Andy Fleming,

Quoted 3 lines · In message <[email protected]> you…

Yeah, that took me a while, too. Maybe we should update it to make clear:

Quoted 7 lines
Quoted 4 lines

1) The formula ends up being (2^(13 + timeout))/mmc->trans_speed = (1/4) seconds --> 2^(13 + timeout) = mmc->trans_speed/4
--> 13 + timeout = log2(mmc->trans_speed/4)
...etc

Does this not depend on the units used for speed, and thus in the end on CONFIC_SYS_HZ ?

No, but that wasn't apparent because I didn't mention the units of 2^(13+timeout). It is in units of sd clocks.

So: num sd clocks = (sd clocks per sec) * 0.25 sec = mmc->tran_speed/4 = 2^(13+regval).

Now, it is true that the actual speed of the sd clock is going to depend on CONFIG_SYS_HZ, in that a tran_speed of 25MHz may not be perfectly achievable with available dividers, but this code is not taking that into account, and the fact that it's rounding up to the next power of two should take care of that.

Andy

#7 lore raw

PATCH 1/1 fsl_esdhc: Correcting esdhc timeout counter calculation

Dear Fleming Andy-AFLEMING,

Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 3 lines

Does this not depend on the units used for speed, and thus in the end on CONFIC_SYS_HZ ?

No, but that wasn't apparent because I didn't mention the units of 2^(13+timeout). It is in units of sd clocks.

Quoted 8 lines

So: num sd clocks = (sd clocks per sec) * 0.25 sec = mmc->tran_speed/4 = 2^(13+regval).

Now, it is true that the actual speed of the sd clock is going to depend on CONFIG_SYS_HZ, in that a tran_speed of 25MHz may not be perfectly achievable with available dividers, but this code is not taking that into account, and the fact that it's rounding up to the next power of two should take care of that.

Fine. Can we please add such explanation to the code?

Thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The use of COBOL cripples the mind; its teaching  should,  therefore,
be regarded as a criminal offence.
          -- Edsger W. Dijkstra, SIGPLAN Notices, Volume 17, Number 5
author
#8 lore raw

PATCH 1/1 fsl_esdhc: Correcting esdhc timeout counter calculation

In reply to Kumar Gala
Quoted 14 lines · Kumar Gala

From: Priyanka Jain <[email protected]>

- Timeout counter value is set as DTOCV bits in SYSCTL register For counter value set as x,
Timeout period = (2^(13+x))/SD_CLOCK

- As per 4.6.2.2 section of SD Card specification v2.00, host should cofigure timeout period value to minimum 250 msec.

- SD_CLOCK = mmc->trans_speed

- Calculating x based on
250 msec = (2^(13+x))/mmc->trans_speed

Quoted 6 lines

---
drivers/mmc/fsl_esdhc.c | 5 ++++-

1 files changed, 4 insertions(+), 1 deletions(-)

Stefano,

Can you test this on iMX to make sure we didnt break anything there.

Quoted 24 lines
drivers/mmc/fsl_esdhc.c +4 -1
index c6de751..6f8a09d 100644
@@ -210,7 +210,10 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
 	esdhc_write32(&regs->blkattr, data->blocks << 16 | data->blocksize);
 
 	/* Calculate the timeout period for data transactions */
-	timeout = fls(mmc->tran_speed/10) - 1;
+	/* Timeout period = (2^(13+timeout))/mmc->trans_speed
+	 * Timeout period should be minimum 250msec as per SD Card spec
+	 */
+	timeout = fls(mmc->tran_speed/4);
 	timeout -= 13;
 
 	if (timeout > 14)
Signature · 6 lines
1.7.2.3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
#9 lore raw

PATCH 1/1 fsl_esdhc: Correcting esdhc timeout counter calculation

Quoted 24 lines · Kumar Gala
Quoted 14 lines · Kumar Gala

From: Priyanka Jain <[email protected]>

- Timeout counter value is set as DTOCV bits in SYSCTL register For counter value set as x,
Timeout period = (2^(13+x))/SD_CLOCK

- As per 4.6.2.2 section of SD Card specification v2.00, host should cofigure timeout period value to minimum 250 msec.

- SD_CLOCK = mmc->trans_speed

- Calculating x based on
250 msec = (2^(13+x))/mmc->trans_speed

Quoted 6 lines

---
drivers/mmc/fsl_esdhc.c | 5 ++++-

1 files changed, 4 insertions(+), 1 deletions(-)
Quoted 3 lines

Stefano,

Can you test this on iMX to make sure we didnt break anything there.

Yes, I will test it and I will send my tested-by if everything is ok.

Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================