Skip to contentSkip to conversation

SD card experts wanted

DISCUSSION Juergen Beisert 3 participants 6 messages Aug 29, 2012 – Aug 30, 2012

lore
Share & tools
lore
#0 lore raw

Hi there,

any SD/MMC card experts here? I have trouble with the current SD/MMC detection code in Barebox.
The function sd_change_freq() in the file 'drivers/mci/mci-core.c' tries to detect the max. transfer frequency the attached card can handle. Nothing special here, but the following line in this routine fails on my system:

if ((__be32_to_cpu(switch_status[4]) & 0x0f000000) == 0x01000000)

It checks the clock speed capabilities returned from the card. As far as I understand the "simplified SD card spec" the "0x01000000" means SDR25 speed, which means still "single transfer per clock at 25 MHz clock rate". But the sd_change_freq() routine sets the MMC_MODE_HS bit for this case in the card's capabilities variable. The remaining routines in 'drivers/mci/mci-core.c' then use 50 MHz for the transfer speed.

This behaviour became an issue here, as my SDHC supports 50 MHz, but the attached card only up to 25 MHz. After switching to 50 MHz, the card wasn't able to respond anymore.
For SDHCs which supports only up to 25 MHz this misinterpretation is no issue, as the routines still use the 25 MHz, and the SD card can still respond.

"simplified SD card spec" talks about the bit's meaning: seems the regular speed was SDR12 which means 12.5 MHz. Then SDR25 cards appear, which are also called "high speed card". Could the MMC_MODE_HS just mean this "high speed" and using it at 50 MHz is just some kind of typo? Or do MMCs act differently and the code mixes SD and MMC features?

Any pointers would help.

jbe

Signature · 7 lines
Pengutronix e.K.                              | Juergen Beisert             |
Linux Solutions for Science and Industry      | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw
Quoted 23 lines · Juergen Beisert

Hi there,

any SD/MMC card experts here? I have trouble with the current SD/MMC detection code in Barebox.
The function sd_change_freq() in the file 'drivers/mci/mci-core.c' tries to detect the max. transfer frequency the attached card can handle. Nothing special here, but the following line in this routine fails on my system:

if ((__be32_to_cpu(switch_status[4]) & 0x0f000000) == 0x01000000)

It checks the clock speed capabilities returned from the card. As far as I understand the "simplified SD card spec" the "0x01000000" means SDR25 speed, which means still "single transfer per clock at 25 MHz clock rate". But the sd_change_freq() routine sets the MMC_MODE_HS bit for this case in the card's capabilities variable. The remaining routines in 'drivers/mci/mci-core.c' then use 50 MHz for the transfer speed.

This behaviour became an issue here, as my SDHC supports 50 MHz, but the attached card only up to 25 MHz. After switching to 50 MHz, the card wasn't able to respond anymore.
For SDHCs which supports only up to 25 MHz this misinterpretation is no issue, as the routines still use the 25 MHz, and the SD card can still respond.

Quoted 5 lines

"simplified SD card spec" talks about the bit's meaning: seems the regular speed was SDR12 which means 12.5 MHz. Then SDR25 cards appear, which are also called "high speed card". Could the MMC_MODE_HS just mean this "high speed" and using it at 50 MHz is just some kind of typo? Or do MMCs act differently and the code mixes SD and MMC features?

I saw it too this isssue

the mmc and sd feature are different with different spec so we need different code to interpret it

see in the kernel

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#2 lore raw
In reply to Juergen Beisert

Hi,

Quoted 10 lines · Juergen Beisert

any SD/MMC card experts here? I have trouble with the current SD/MMC detection code in Barebox.
The function sd_change_freq() in the file 'drivers/mci/mci-core.c' tries to detect the max. transfer frequency the attached card can handle. Nothing special here, but the following line in this routine fails on my system:

if ((__be32_to_cpu(switch_status[4]) & 0x0f000000) == 0x01000000)

It checks the clock speed capabilities returned from the card. As far as I understand the "simplified SD card spec" the "0x01000000" means SDR25 speed,

I think your analysis is correct.

Quoted 4 lines

which means still "single transfer per clock at 25 MHz clock rate". But the sd_change_freq() routine sets the MMC_MODE_HS bit for this case in the card's capabilities variable. The remaining routines in 'drivers/mci/mci-core.c' then use 50 MHz for the transfer speed.

IMHO mci_startup_sd() is buggy.

Quoted 6 lines

This behaviour became an issue here, as my SDHC supports 50 MHz, but the attached card only up to 25 MHz. After switching to 50 MHz, the card wasn't able to respond anymore.
For SDHCs which supports only up to 25 MHz this misinterpretation is no issue, as the routines still use the 25 MHz, and the SD card can still respond.

Quoted 7 lines

"simplified SD card spec" talks about the bit's meaning: seems the regular speed was SDR12 which means 12.5 MHz. Then SDR25 cards appear, which are also called "high speed card". Could the MMC_MODE_HS just mean this "high speed" and using it at 50 MHz is just some kind of typo? Or do MMCs act differently and the code mixes SD and MMC features?

Any pointers would help.

MMC has the following speed modes:

- legacy 0-26MHz
- high speed SDR 0-52MHz
- high speed DDR 0-52MHz
- HS200 SDR 0-200MHz

while SD has:

- SDR12
- SDR25
- SDR50
- SDR104
- DDR50

So my guess is that MMC_MODE_HS maps to SDR25 for SD-only, and MMC_MODE_HS_52MHz maps to SDR50 for SD and MMC.

(Apparently mmc_change_freq always sets MMC_MODE_HS, it is meaningless for MMC.)

Thus, mci_startup_sd() should do:

	if (mci->card_caps & MMC_MODE_HS)
		mci_set_clock(mci, 25000000);
	else
		mci_set_clock(mci, 12500000);

Johannes

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw

Hi Johannes,

Quoted 8 lines · Johannes Stezenbach
Quoted 7 lines · Juergen Beisert

any SD/MMC card experts here? I have trouble with the current SD/MMC detection code in Barebox.
The function sd_change_freq() in the file 'drivers/mci/mci-core.c' tries to detect the max. transfer frequency the attached card can handle. Nothing special here, but the following line in this routine fails on my system:

Quoted 7 lines
Quoted 5 lines

if ((__be32_to_cpu(switch_status[4]) & 0x0f000000) == 0x01000000)

It checks the clock speed capabilities returned from the card. As far as I understand the "simplified SD card spec" the "0x01000000" means SDR25 speed,

I think your analysis is correct.

Thanks.

Quoted 6 lines
Quoted 4 lines

which means still "single transfer per clock at 25 MHz clock rate". But the sd_change_freq() routine sets the MMC_MODE_HS bit for this case in the card's capabilities variable. The remaining routines in 'drivers/mci/mci-core.c' then use 50 MHz for the transfer speed.

IMHO mci_startup_sd() is buggy.

Ack.

Quoted 13 lines
Quoted 13 lines

This behaviour became an issue here, as my SDHC supports 50 MHz, but the attached card only up to 25 MHz. After switching to 50 MHz, the card wasn't able to respond anymore.
For SDHCs which supports only up to 25 MHz this misinterpretation is no issue, as the routines still use the 25 MHz, and the SD card can still respond.

"simplified SD card spec" talks about the bit's meaning: seems the regular speed was SDR12 which means 12.5 MHz. Then SDR25 cards appear, which are also called "high speed card". Could the MMC_MODE_HS just mean this "high speed" and using it at 50 MHz is just some kind of typo? Or do MMCs act differently and the code mixes SD and MMC features?

Quoted 8 lines
Quoted 1 line

Any pointers would help.

MMC has the following speed modes:

- legacy 0-26MHz
- high speed SDR 0-52MHz
- high speed DDR 0-52MHz
- HS200 SDR 0-200MHz

Ahh, here come the curious 26 MHz and 52 MHz into the game. Its related to MMC only.

Quoted 11 lines

while SD has:

- SDR12
- SDR25
- SDR50
- SDR104
- DDR50

So my guess is that MMC_MODE_HS maps to SDR25 for SD-only, and MMC_MODE_HS_52MHz maps to SDR50 for SD and MMC.

Quoted 8 lines

(Apparently mmc_change_freq always sets MMC_MODE_HS, it is meaningless for MMC.)

Thus, mci_startup_sd() should do:

	if (mci->card_caps & MMC_MODE_HS)
		mci_set_clock(mci, 25000000);
	else
		mci_set_clock(mci, 12500000);

As far as I understand the spec, there is a max. speed field in the CSD which tells us the regular max. speed of this card. And the fields from the CSR can overwrite the CSD settings. So, a card which reports 25 MHz in the CSD can still enable 50 MHz (SDR50) in the CSR and the SDHC then can use 50 MHz for the clock. But maybe I'm wrong here.

On the other hand: why switching the clock speed inside the SD card? The spec defines, the SDHC can switch the clock speed at any time, at least it must be below or equal to the max. clock speed the card supports.

When the specification is called "simplified", how complicated must be the "non-simplified" version of this document... ;)

jbe

Signature · 7 lines
Pengutronix e.K.                              | Juergen Beisert             |
Linux Solutions for Science and Industry      | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Hi,

Quoted 32 lines · Juergen Beisert
Quoted 7 lines · Johannes Stezenbach

MMC has the following speed modes:

- legacy 0-26MHz
- high speed SDR 0-52MHz
- high speed DDR 0-52MHz
- HS200 SDR 0-200MHz

Ahh, here come the curious 26 MHz and 52 MHz into the game. Its related to MMC only.

Quoted 11 lines

while SD has:

- SDR12
- SDR25
- SDR50
- SDR104
- DDR50

So my guess is that MMC_MODE_HS maps to SDR25 for SD-only, and MMC_MODE_HS_52MHz maps to SDR50 for SD and MMC.

Quoted 8 lines

(Apparently mmc_change_freq always sets MMC_MODE_HS, it is meaningless for MMC.)

Thus, mci_startup_sd() should do:

	if (mci->card_caps & MMC_MODE_HS)
		mci_set_clock(mci, 25000000);
	else
		mci_set_clock(mci, 12500000);
Quoted 5 lines

As far as I understand the spec, there is a max. speed field in the CSD which tells us the regular max. speed of this card. And the fields from the CSR can overwrite the CSD settings. So, a card which reports 25 MHz in the CSD can still enable 50 MHz (SDR50) in the CSR and the SDHC then can use 50 MHz for the clock. But maybe I'm wrong here.

What I wrote is not even correct ;-/

SD has legacy Default Mode and legacy High Speed mode,
and "Ultra High Speed" modes. SDR12, SDR25, SDR50, SDR104 and DDR50 are all UHS modes. And Default Mode and SDR12 support up to 12.5MB/s, but the bus clock is up to 25MHz (4 bit parallel).
So the code in mci_startup_sd() is correct as is.

See table in 3.9.6 Summary of Bus Speed Mode.

Regarding CSD, my understanding is that TRAN_SPEED only applies to legacy Default Mode. If the card supports HS mode or UHS modes then it must be able to use 50MHz clock.
(This is stated below Table 5-6: Maximum Data Transfer Rate Definition)

Quoted 3 lines

On the other hand: why switching the clock speed inside the SD card? The spec defines, the SDHC can switch the clock speed at any time, at least it must be below or equal to the max. clock speed the card supports.

I suppose the card's controller needs to know how to program internal clock dividers.

Best Regards
Johannes

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#5 lore raw

Hi Johannes,

Quoted 38 lines · Johannes Stezenbach
Quoted 31 lines · Juergen Beisert
Quoted 6 lines · Johannes Stezenbach

MMC has the following speed modes:

- legacy 0-26MHz
- high speed SDR 0-52MHz
- high speed DDR 0-52MHz
- HS200 SDR 0-200MHz

Ahh, here come the curious 26 MHz and 52 MHz into the game. Its related to MMC only.

Quoted 11 lines

while SD has:

- SDR12
- SDR25
- SDR50
- SDR104
- DDR50

So my guess is that MMC_MODE_HS maps to SDR25 for SD-only, and MMC_MODE_HS_52MHz maps to SDR50 for SD and MMC.

Quoted 8 lines

(Apparently mmc_change_freq always sets MMC_MODE_HS, it is meaningless for MMC.)

Thus, mci_startup_sd() should do:

	if (mci->card_caps & MMC_MODE_HS)
		mci_set_clock(mci, 25000000);
	else
		mci_set_clock(mci, 12500000);
Quoted 5 lines

As far as I understand the spec, there is a max. speed field in the CSD which tells us the regular max. speed of this card. And the fields from the CSR can overwrite the CSD settings. So, a card which reports 25 MHz in the CSD can still enable 50 MHz (SDR50) in the CSR and the SDHC then can use 50 MHz for the clock. But maybe I'm wrong here.

Quoted 7 lines

What I wrote is not even correct ;-/

SD has legacy Default Mode and legacy High Speed mode,
and "Ultra High Speed" modes. SDR12, SDR25, SDR50, SDR104 and DDR50 are all UHS modes. And Default Mode and SDR12 support up to 12.5MB/s, but the bus clock is up to 25MHz (4 bit parallel).
So the code in mci_startup_sd() is correct as is.

Now I found the Abbreviations in the spec:

UHS    Ultra High Speed
SDR12  One of UHS modes with single data rate. Up to 12.5MB/sec at 25MHz
SDR25  One of UHS modes with single data rate. Up to 25MB/sec at 50MHz
SDR50  One of UHS modes with single data rate. Up to 50MB/sec at 100MHz

SDR104 One of UHS modes with single data rate. Up to 104MB/sec at 208MHz

So they mean the transfer capacity in "bytes per second" and not the clock speed with their SDR<number>. Thanks for this hint.

Reading further discovers:

* all these UHS modes are _not_ valid for SDSC type of SD cards (up to 2 GiB capacity)

This information should help to get the code right.

Quoted 3 lines

Regarding CSD, my understanding is that TRAN_SPEED only applies to legacy Default Mode. If the card supports HS mode or UHS modes then it must be able to use 50MHz clock.

Ack.

Regards,
Juergen

Signature · 7 lines
Pengutronix e.K.                              | Juergen Beisert             |
Linux Solutions for Science and Industry      | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox