2006-10-09 15:00:53

by Timo Teras

[permalink] [raw]
Subject: [PATCH] MMC: Select only one voltage bit in OCR response

The card might go to inactive state (according to specification), if
there are unsupported bits set in the OCR.

Signed-off-by: Timo Teras <[email protected]>

---

drivers/mmc/mmc.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

8208e380f51ca772e84a0b83098d24aacfa3cc2b
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index acc5365..61bf3fc 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -475,7 +475,7 @@ static u32 mmc_select_voltage(struct mmc
if (bit) {
bit -= 1;

- ocr = 3 << bit;
+ ocr = 1 << bit;

host->ios.vdd = bit;
mmc_set_ios(host);
--
1.2.3.g90cc1


2006-10-09 16:53:25

by Russell King

[permalink] [raw]
Subject: Re: [PATCH] MMC: Select only one voltage bit in OCR response

On Mon, Oct 09, 2006 at 06:00:44PM +0300, Timo Teras wrote:
> The card might go to inactive state (according to specification), if
> there are unsupported bits set in the OCR.

NAK. This breaks some MMC cards.

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core

2006-10-09 17:24:01

by Timo Teras

[permalink] [raw]
Subject: Re: [PATCH] MMC: Select only one voltage bit in OCR response

On Mon, Oct 09, 2006 at 05:53:17PM +0100, Russell King wrote:
> On Mon, Oct 09, 2006 at 06:00:44PM +0300, Timo Teras wrote:
> > The card might go to inactive state (according to specification), if
> > there are unsupported bits set in the OCR.
>
> NAK. This breaks some MMC cards.

I see. But if we do send an OCR with an unsupported bit set, the card will
go to inactive state and is unusable. This problem is masked on controllers
with only 3.3V support, but I'm working with a controller supporting several
different voltages.

For example, I have a card giving an OCR reply of 0x0ff80080. The current
code will reply to this with 0x00000180 which is clearly incorrect.

Maybe something like "ocr &= 3 << bit;" would be more approriate?

Cheers,
Timo

2006-10-10 13:24:05

by Timo Teras

[permalink] [raw]
Subject: [PATCH] MMC: Do not set unsupported bits in OCR response

The card might go to inactive state (according to specification), if
there are unsupported bits set in the OCR.

Signed-off-by: Timo Teras <[email protected]>

---

drivers/mmc/mmc.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index ee8863c..c6f3077 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -475,7 +475,7 @@ static u32 mmc_select_voltage(struct mmc
if (bit) {
bit -= 1;

- ocr = 3 << bit;
+ ocr &= 3 << bit;

host->ios.vdd = bit;
mmc_set_ios(host);

2006-10-16 06:34:27

by Pierre Ossman

[permalink] [raw]
Subject: Re: [PATCH] MMC: Select only one voltage bit in OCR response

Timo Teras wrote:
> I see. But if we do send an OCR with an unsupported bit set, the card will
> go to inactive state and is unusable. This problem is masked on controllers
> with only 3.3V support, but I'm working with a controller supporting several
> different voltages.
>
> For example, I have a card giving an OCR reply of 0x0ff80080. The current
> code will reply to this with 0x00000180 which is clearly incorrect.
>
> Maybe something like "ocr &= 3 << bit;" would be more approriate?
>

Russell? Comments? Do you still have the offending card?

--
-- Pierre Ossman

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

2006-10-22 09:25:03

by Pierre Ossman

[permalink] [raw]
Subject: Re: [PATCH] MMC: Select only one voltage bit in OCR response

(In case you've missed it)

Pierre Ossman wrote:
> Timo Teras wrote:
>> I see. But if we do send an OCR with an unsupported bit set, the card will
>> go to inactive state and is unusable. This problem is masked on controllers
>> with only 3.3V support, but I'm working with a controller supporting several
>> different voltages.
>>
>> For example, I have a card giving an OCR reply of 0x0ff80080. The current
>> code will reply to this with 0x00000180 which is clearly incorrect.
>>
>> Maybe something like "ocr &= 3 << bit;" would be more approriate?
>>
>
> Russell? Comments? Do you still have the offending card?
>

--
-- Pierre Ossman

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

2006-10-31 10:05:12

by Russell King

[permalink] [raw]
Subject: Re: [PATCH] MMC: Select only one voltage bit in OCR response

On Mon, Oct 16, 2006 at 08:34:20AM +0200, Pierre Ossman wrote:
> Timo Teras wrote:
> > I see. But if we do send an OCR with an unsupported bit set, the card will
> > go to inactive state and is unusable. This problem is masked on controllers
> > with only 3.3V support, but I'm working with a controller supporting several
> > different voltages.
> >
> > For example, I have a card giving an OCR reply of 0x0ff80080. The current
> > code will reply to this with 0x00000180 which is clearly incorrect.
> >
> > Maybe something like "ocr &= 3 << bit;" would be more approriate?
> >
>
> Russell? Comments? Do you still have the offending card?

It wasn't my cards, but was reported by several other folk. I don't think
we can revert on this without breakage.

However, we should probably ensure that we don't end up setting voltage
bits which the cards don't support. So maybe masking the resulting OCR
value with the received combined OCR would be a good idea? Such as:

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index ee8863c..45e0598 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -467,23 +467,24 @@ static inline void mmc_delay(unsigned in
*/
static u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
{
+ u32 selected_ocr;
int bit;

- ocr &= host->ocr_avail;
+ selected_ocr = ocr & host->ocr_avail;

- bit = ffs(ocr);
+ bit = ffs(selected_ocr);
if (bit) {
bit -= 1;

- ocr = 3 << bit;
+ selected_ocr = 3 << bit;

host->ios.vdd = bit;
mmc_set_ios(host);
} else {
- ocr = 0;
+ selected_ocr = 0;
}

- return ocr;
+ return selected_ocr & ocr;
}

#define UNSTUFF_BITS(resp,start,size) \


--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core

2006-10-31 15:24:21

by Juha Yrjola

[permalink] [raw]
Subject: Re: [PATCH] MMC: Select only one voltage bit in OCR response

Russell King wrote:

>>> Maybe something like "ocr &= 3 << bit;" would be more approriate?
>>>
>> Russell? Comments? Do you still have the offending card?
>
> It wasn't my cards, but was reported by several other folk. I don't think
> we can revert on this without breakage.
>
> However, we should probably ensure that we don't end up setting voltage
> bits which the cards don't support. So maybe masking the resulting OCR
> value with the received combined OCR would be a good idea? Such as:

Isn't this exactly what Timo is proposing above?

Cheers,
Juha

> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index ee8863c..45e0598 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -467,23 +467,24 @@ static inline void mmc_delay(unsigned in
> */
> static u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
> {
> + u32 selected_ocr;
> int bit;
>
> - ocr &= host->ocr_avail;
> + selected_ocr = ocr & host->ocr_avail;
>
> - bit = ffs(ocr);
> + bit = ffs(selected_ocr);
> if (bit) {
> bit -= 1;
>
> - ocr = 3 << bit;
> + selected_ocr = 3 << bit;
>
> host->ios.vdd = bit;
> mmc_set_ios(host);
> } else {
> - ocr = 0;
> + selected_ocr = 0;
> }
>
> - return ocr;
> + return selected_ocr & ocr;
> }

2006-11-02 18:37:10

by Pierre Ossman

[permalink] [raw]
Subject: Re: [PATCH] MMC: Select only one voltage bit in OCR response

Juha Yrjola wrote:
>
> Isn't this exactly what Timo is proposing above?
>

I sure can't see the difference. Timo's patch queued up for -mm.

Rgds

--
-- Pierre Ossman

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