2008-03-18 10:59:51

by Wappler Marcel

[permalink] [raw]
Subject: MMC: Card detection through pin CD/DAT3 issue

Hi Pierre, hi MMC developers,

I am at porting the generic PCI controller driver mmc/host/sdhci.c to a special non PCI direct memory mapped host. The hardware
vendor decided to implement the card detection not through the mechanical card present switch but through detecting the card
internal pull up at pin 1 (CD/DAT3).

With this detection scheme I have some dificulties togehter with the internal working of the current MMC stack:

The controller cannot detect a newly inserted card if the card power is switched of. This is due to the fact that the SD card
applies the internal card detection pull up after it powered up. If there is no power -> no powering up -> no pull up. (besides the
fact that a pull up needs power to for doing its work :-) )

My questions are:

1. knows anyone a host controller which uses the same card detection mechanism?

2. How could the driver manage the problem that the MMC stack switches off the card power if removed and therefor no state change on
line CD/DAT3 occurs at re-insertion of that card?

3. In a short look through some MMC card specs I did not find any description of some card detection mechanism. So I suppose the
mechanical switch is the only possible solution to detect a newly inserted card. Am I right or is there nevertheless a chance to
detect a inserted MMC together with this host?

Please CC me personaly and thanks a lot,
Marcel
--
Marcel Wappler
Bridgeco AG
CH-8600 D?bendorf
Switzerland


2008-03-18 11:21:32

by Pierre Ossman

[permalink] [raw]
Subject: Re: MMC: Card detection through pin CD/DAT3 issue

On Tue, 18 Mar 2008 11:59:25 +0100
"Wappler Marcel" <[email protected]> wrote:

> Hi Pierre, hi MMC developers,
>
> I am at porting the generic PCI controller driver mmc/host/sdhci.c to a special non PCI direct memory mapped host. The hardware
> vendor decided to implement the card detection not through the mechanical card present switch but through detecting the card
> internal pull up at pin 1 (CD/DAT3).
>

The SDHCI spec doesn't specify how to detect the card, so this is a valid behaviour. That said, it's a very stupid way to detect cards as it is very unreliable. There's a reason extremely few use this technique.

> With this detection scheme I have some dificulties togehter with the internal working of the current MMC stack:
>
> The controller cannot detect a newly inserted card if the card power is switched of. This is due to the fact that the SD card
> applies the internal card detection pull up after it powered up. If there is no power -> no powering up -> no pull up. (besides the
> fact that a pull up needs power to for doing its work :-) )
>

Then you have broken hardware. The specs clearly state that the controller must be able to detect cards without powering up the cards. Also, the cards must implement the pull-up in a way that behaves like a resistor. So there should be no requirement for full power there either.

> My questions are:
>
> 1. knows anyone a host controller which uses the same card detection mechanism?
>

Yes, some wbsd controllers at least.

> 2. How could the driver manage the problem that the MMC stack switches off the card power if removed and therefor no state change on
> line CD/DAT3 occurs at re-insertion of that card?
>

Provided your hardware is in fact so broken that it cannot be properly handled, you could add a quirk that forces the sdhci driver to keep power on constantly.

> 3. In a short look through some MMC card specs I did not find any description of some card detection mechanism. So I suppose the
> mechanical switch is the only possible solution to detect a newly inserted card. Am I right or is there nevertheless a chance to
> detect a inserted MMC together with this host?
>

I have a faint memory of a pull-up being added to the MMC 4 spec (the ones with lots of pads). Still, it's a crappy detection mechanism as it doesn't play well with data transfers, and the pull-up can usually be disabled in the cards.

Rgds
--
-- Pierre Ossman

Linux kernel, MMC maintainer http://www.kernel.org
PulseAudio, core developer http://pulseaudio.org
rdesktop, core developer http://www.rdesktop.org

2008-03-18 12:24:48

by Wappler Marcel

[permalink] [raw]
Subject: RE: MMC: Card detection through pin CD/DAT3 issue

Hi Pierre,

>> With this detection scheme I have some dificulties togehter
>> with the internal working of the current MMC stack:
>> The controller cannot detect a newly inserted card if the card power
>> is switched of. This is due to the fact that the SD card applies the
>> internal card detection pull up after it powered up. If there is no
>> power -> no powering up -> no pull up. (besides the fact that a pull
>> up needs power to for doing its work :-) )
>>

> Then you have broken hardware. The specs clearly state that the
> controller must be able to detect cards without powering up the
> cards. Also, the cards must implement the pull-up in a way that
> behaves like a resistor. So there should be no requirement for
> full power there either.

I have found this requirement in the SD host controller spec:
"The card detect is active regardless of the SD Bus Power."

I wonder how the card should be able to pull up the CD/DAT3 Pad to VCC
if its only VCC pad is not connected to VCC due to the fact that the host
controller has switched off the cards power - any idea how this could be
managed?

There is a SD card spec section somewhere which statet that:
"If one of the supply pins (VDD or VSS) is not connected properly, then
the current is drawn through a data line to supply the card."

Maybe this is the key in understanding ho the pull up without VCC connected
works?

Thanks,
marcel

2008-03-18 12:48:57

by Pierre Ossman

[permalink] [raw]
Subject: Re: MMC: Card detection through pin CD/DAT3 issue

On Tue, 18 Mar 2008 13:24:33 +0100
"Wappler Marcel" <[email protected]> wrote:

>
> I have found this requirement in the SD host controller spec:
> "The card detect is active regardless of the SD Bus Power."
>
> I wonder how the card should be able to pull up the CD/DAT3 Pad to VCC
> if its only VCC pad is not connected to VCC due to the fact that the host
> controller has switched off the cards power - any idea how this could be
> managed?

It could provide a very low voltage and current, just enough to probe the resistor but not enough to actually power anything on the card.

>
> There is a SD card spec section somewhere which statet that:
> "If one of the supply pins (VDD or VSS) is not connected properly, then
> the current is drawn through a data line to supply the card."
>
> Maybe this is the key in understanding ho the pull up without VCC connected
> works?
>

I think that's just a warning that the supply pins need to be grounded when power is disabled. I have a controller where they are left floating, and some cards do indeed power up using power from the data line pull-ups. The end results is a heavily malfunctioning card due to insufficient power supply.

Most of this card detection using DAT3 business is unknown to me. The spec that describes how it is supposed to work is not publicly available, so I can only speculate.

Rgds
--
-- Pierre Ossman

Linux kernel, MMC maintainer http://www.kernel.org
PulseAudio, core developer http://pulseaudio.org
rdesktop, core developer http://www.rdesktop.org

2008-03-19 20:51:46

by Wappler Marcel

[permalink] [raw]
Subject: RE: MMC: Card detection through pin CD/DAT3 issue

Thank you, Pierre,

this special host controller is more an SDHCI _inspired_ than a
_compliant_ one. Not only powering off the card bus led to the not
working card detection but also the RESET_ALL function. Both
tasks are reqired by the SDHCI standard after removing the card.
But Pierre has prepared the sdhci.c very well: there is a quirk
called "SSM_QUIRK_NO_CARD_NO_RESET". In combination with disabling
power off after a card removal now it works.

Bodo Eggert wrote:
>> I have found this requirement in the SD host controller spec:
>> "The card detect is active regardless of the SD Bus Power."
>>
>> I wonder how the card should be able to pull up the CD/DAT3 Pad to
>> VCC if its only VCC pad is not connected to VCC due to the fact that
>> the host controller has switched off the cards power - any idea how
>> this could be managed?

> If the VCC pin is connected to 0 V, the "pullup" will pull
> down to 0V.
> If the controller reverses it's logic while VCC=0, it might work.

I am concerned that in this case there would be neither a pull
up nor a pull down at this signal. Due to floating gates that input
could lead to millions of "card detection" events a second, if
no card is inserted?


Regards,
Marcel

Marcel Wappler
Bridgeco AG
CH-8600 D?bendorf
Switzerland

2008-03-19 21:50:33

by Bodo Eggert

[permalink] [raw]
Subject: RE: MMC: Card detection through pin CD/DAT3 issue

Wappler Marcel <[email protected]> wrote:

> I have found this requirement in the SD host controller spec:
> "The card detect is active regardless of the SD Bus Power."
>
> I wonder how the card should be able to pull up the CD/DAT3 Pad to VCC
> if its only VCC pad is not connected to VCC due to the fact that the host
> controller has switched off the cards power - any idea how this could be
> managed?

If the VCC pin is connected to 0 V, the "pullup" will pull down to 0 V.
If the controller reverses it's logic while VCC=0, it might work.

The controller might alternatively switch all pins (except the pullup) to
VCC, which would look to the card like switching all pins to 0V, but
detection by pullup would still work.

2008-03-20 07:27:37

by Bodo Eggert

[permalink] [raw]
Subject: RE: MMC: Card detection through pin CD/DAT3 issue

On Wed, 19 Mar 2008, Wappler Marcel wrote:
> Bodo Eggert wrote:

> >> I have found this requirement in the SD host controller spec:
> >> "The card detect is active regardless of the SD Bus Power."
> >>
> >> I wonder how the card should be able to pull up the CD/DAT3 Pad to
> >> VCC if its only VCC pad is not connected to VCC due to the fact that
> >> the host controller has switched off the cards power - any idea how
> >> this could be managed?
>
> > If the VCC pin is connected to 0 V, the "pullup" will pull
> > down to 0V.
> > If the controller reverses it's logic while VCC=0, it might work.
>
> I am concerned that in this case there would be neither a pull
> up nor a pull down at this signal. Due to floating gates that input
> could lead to millions of "card detection" events a second, if

As long as no card is inserted, the pin on the controller would be floating
and generating the same amount of interrupts, unless there is a (weak)
internal pulldown. You can do the same for the reversed logic, using
an internal pullup and abusing the card's pullup as a pulldown.

--
Never forget that your weapon is made by the lowest bidder.