All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] mmc: correct the HS400 initialization process
@ 2019-03-18  8:23 BOUGH CHEN
  2019-03-18 11:53 ` Marek Vasut
  0 siblings, 1 reply; 6+ messages in thread
From: BOUGH CHEN @ 2019-03-18  8:23 UTC (permalink / raw)
  To: u-boot

After the commit b9a2a0e2e9c0 ("mmc: Add support for downgrading
HS200/HS400 to HS mode"), it add a parameter in mmc_set_card_speed()
which indicates that the HS200/HS400 to HS downgrade is happening.

During the HS400 initialization, first select to HS200, and config
the related clock rate, then downgrade to HS mode. So here also need
to config the downgrade value to be true, make sure in the function
mmc_set_card_speed(), after switch to HS mode, first config the
clock rate, then read the EXT_CSD. Otherwise read EXT_CSD in HS mode
at wrong clock rate, e.g. 200MHz, may lead to uncertain result.

Test on i.MX8QM MEK board, some Micron eMMC will stuck in transfer
mode in this case, and USDHC will never get data transfer complete
status, cause the uboot hang.

Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
---
 drivers/mmc/mmc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 1c1527cc74..55d3560b30 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -1892,8 +1892,7 @@ static int mmc_select_hs400(struct mmc *mmc)
 	}
 
 	/* Set back to HS */
-	mmc_set_card_speed(mmc, MMC_HS, false);
-	mmc_set_clock(mmc, mmc_mode2freq(mmc, MMC_HS), false);
+	mmc_set_card_speed(mmc, MMC_HS, true);
 
 	err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH,
 			 EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_FLAG);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH] mmc: correct the HS400 initialization process
  2019-03-18  8:23 [U-Boot] [PATCH] mmc: correct the HS400 initialization process BOUGH CHEN
@ 2019-03-18 11:53 ` Marek Vasut
  2019-03-25 10:24   ` BOUGH CHEN
  0 siblings, 1 reply; 6+ messages in thread
From: Marek Vasut @ 2019-03-18 11:53 UTC (permalink / raw)
  To: u-boot

On 3/18/19 9:23 AM, BOUGH CHEN wrote:
> After the commit b9a2a0e2e9c0 ("mmc: Add support for downgrading
> HS200/HS400 to HS mode"), it add a parameter in mmc_set_card_speed()
> which indicates that the HS200/HS400 to HS downgrade is happening.
> 
> During the HS400 initialization, first select to HS200, and config
> the related clock rate, then downgrade to HS mode. So here also need
> to config the downgrade value to be true, make sure in the function
> mmc_set_card_speed(), after switch to HS mode, first config the
> clock rate, then read the EXT_CSD. Otherwise read EXT_CSD in HS mode
> at wrong clock rate, e.g. 200MHz, may lead to uncertain result.

I think the fix is right, but the reasoning for it is not.

If you call mmc_set_card_speed() with hsdowngrade=true, it will result
in calling __mmc_switch() with send_status=false , which in turn means
that after issuing the MMC_CMD_SWITCH command, the code won't poll the
card using MMC_CMD_SEND_STATUS, but just wait a bit and then switch the
bus properties. This is indeed required when switching bus properties.
And that's what I think was making your card unstable.

Is that the case ?

> Test on i.MX8QM MEK board, some Micron eMMC will stuck in transfer
> mode in this case, and USDHC will never get data transfer complete
> status, cause the uboot hang.
> 
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
> ---
>  drivers/mmc/mmc.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index 1c1527cc74..55d3560b30 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -1892,8 +1892,7 @@ static int mmc_select_hs400(struct mmc *mmc)
>  	}
>  
>  	/* Set back to HS */
> -	mmc_set_card_speed(mmc, MMC_HS, false);
> -	mmc_set_clock(mmc, mmc_mode2freq(mmc, MMC_HS), false);
> +	mmc_set_card_speed(mmc, MMC_HS, true);
>  
>  	err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH,
>  			 EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_FLAG);
> 


-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH] mmc: correct the HS400 initialization process
  2019-03-18 11:53 ` Marek Vasut
@ 2019-03-25 10:24   ` BOUGH CHEN
  2019-03-25 11:16     ` Marek Vasut
  0 siblings, 1 reply; 6+ messages in thread
From: BOUGH CHEN @ 2019-03-25 10:24 UTC (permalink / raw)
  To: u-boot


> -----Original Message-----
> From: Marek Vasut [mailto:marek.vasut at gmail.com]
> Sent: 2019年3月18日 19:53
> To: BOUGH CHEN <haibo.chen@nxp.com>; jh80.chung at samsung.com;
> trini at konsulko.com
> Cc: marek.vasut+renesas at gmail.com; Ye Li <ye.li@nxp.com>; dl-uboot-imx
> <uboot-imx@nxp.com>; u-boot at lists.denx.de
> Subject: Re: [PATCH] mmc: correct the HS400 initialization process
> 
> On 3/18/19 9:23 AM, BOUGH CHEN wrote:
> > After the commit b9a2a0e2e9c0 ("mmc: Add support for downgrading
> > HS200/HS400 to HS mode"), it add a parameter in mmc_set_card_speed()
> > which indicates that the HS200/HS400 to HS downgrade is happening.
> >
> > During the HS400 initialization, first select to HS200, and config the
> > related clock rate, then downgrade to HS mode. So here also need to
> > config the downgrade value to be true, make sure in the function
> > mmc_set_card_speed(), after switch to HS mode, first config the clock
> > rate, then read the EXT_CSD. Otherwise read EXT_CSD in HS mode at
> > wrong clock rate, e.g. 200MHz, may lead to uncertain result.
> 
> I think the fix is right, but the reasoning for it is not.
> 
> If you call mmc_set_card_speed() with hsdowngrade=true, it will result in
> calling __mmc_switch() with send_status=false , which in turn means that
> after issuing the MMC_CMD_SWITCH command, the code won't poll the card
> using MMC_CMD_SEND_STATUS, but just wait a bit and then switch the bus
> properties. This is indeed required when switching bus properties.
> And that's what I think was making your card unstable.
> 
> Is that the case ?

Sorry for the tardy reply, I miss the email last week.
No, if without this patch, even I add the dealy after the switch command, eMMC still stuck after the CMD8.
The main issue is that, in mmc_set_card_speed, if the bus mode the HS mode, it will send CMD8 to get the EXT_CSD, but the clock is still 200MHz at that time.
It is wrong that EMMC output data in HS mode at 200MHz. 

Best Regards
Haibo Chen

> 
> > Test on i.MX8QM MEK board, some Micron eMMC will stuck in transfer
> > mode in this case, and USDHC will never get data transfer complete
> > status, cause the uboot hang.
> >
> > Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
> > ---
> >  drivers/mmc/mmc.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index
> > 1c1527cc74..55d3560b30 100644
> > --- a/drivers/mmc/mmc.c
> > +++ b/drivers/mmc/mmc.c
> > @@ -1892,8 +1892,7 @@ static int mmc_select_hs400(struct mmc *mmc)
> >  	}
> >
> >  	/* Set back to HS */
> > -	mmc_set_card_speed(mmc, MMC_HS, false);
> > -	mmc_set_clock(mmc, mmc_mode2freq(mmc, MMC_HS), false);
> > +	mmc_set_card_speed(mmc, MMC_HS, true);
> >
> >  	err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
> EXT_CSD_BUS_WIDTH,
> >  			 EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_FLAG);
> >
> 
> 
> --
> Best regards,
> Marek Vasut

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH] mmc: correct the HS400 initialization process
  2019-03-25 10:24   ` BOUGH CHEN
@ 2019-03-25 11:16     ` Marek Vasut
  2019-03-25 12:10       ` Tom Rini
  0 siblings, 1 reply; 6+ messages in thread
From: Marek Vasut @ 2019-03-25 11:16 UTC (permalink / raw)
  To: u-boot

On 3/25/19 11:24 AM, BOUGH CHEN wrote:
> 
>> -----Original Message-----
>> From: Marek Vasut [mailto:marek.vasut at gmail.com]
>> Sent: 2019年3月18日 19:53
>> To: BOUGH CHEN <haibo.chen@nxp.com>; jh80.chung at samsung.com;
>> trini at konsulko.com
>> Cc: marek.vasut+renesas at gmail.com; Ye Li <ye.li@nxp.com>; dl-uboot-imx
>> <uboot-imx@nxp.com>; u-boot at lists.denx.de
>> Subject: Re: [PATCH] mmc: correct the HS400 initialization process
>>
>> On 3/18/19 9:23 AM, BOUGH CHEN wrote:
>>> After the commit b9a2a0e2e9c0 ("mmc: Add support for downgrading
>>> HS200/HS400 to HS mode"), it add a parameter in mmc_set_card_speed()
>>> which indicates that the HS200/HS400 to HS downgrade is happening.
>>>
>>> During the HS400 initialization, first select to HS200, and config the
>>> related clock rate, then downgrade to HS mode. So here also need to
>>> config the downgrade value to be true, make sure in the function
>>> mmc_set_card_speed(), after switch to HS mode, first config the clock
>>> rate, then read the EXT_CSD. Otherwise read EXT_CSD in HS mode at
>>> wrong clock rate, e.g. 200MHz, may lead to uncertain result.
>>
>> I think the fix is right, but the reasoning for it is not.
>>
>> If you call mmc_set_card_speed() with hsdowngrade=true, it will result in
>> calling __mmc_switch() with send_status=false , which in turn means that
>> after issuing the MMC_CMD_SWITCH command, the code won't poll the card
>> using MMC_CMD_SEND_STATUS, but just wait a bit and then switch the bus
>> properties. This is indeed required when switching bus properties.
>> And that's what I think was making your card unstable.
>>
>> Is that the case ?
> 
> Sorry for the tardy reply, I miss the email last week.
> No, if without this patch, even I add the dealy after the switch command, eMMC still stuck after the CMD8.
> The main issue is that, in mmc_set_card_speed, if the bus mode the HS mode, it will send CMD8 to get the EXT_CSD, but the clock is still 200MHz at that time.
> It is wrong that EMMC output data in HS mode at 200MHz. 

OK, that makes sense.

-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH] mmc: correct the HS400 initialization process
  2019-03-25 11:16     ` Marek Vasut
@ 2019-03-25 12:10       ` Tom Rini
  2019-03-25 12:28         ` Marek Vasut
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Rini @ 2019-03-25 12:10 UTC (permalink / raw)
  To: u-boot

On Mon, Mar 25, 2019 at 12:16:53PM +0100, Marek Vasut wrote:
> On 3/25/19 11:24 AM, BOUGH CHEN wrote:
> > 
> >> -----Original Message-----
> >> From: Marek Vasut [mailto:marek.vasut at gmail.com]
> >> Sent: 2019年3月18日 19:53
> >> To: BOUGH CHEN <haibo.chen@nxp.com>; jh80.chung at samsung.com;
> >> trini at konsulko.com
> >> Cc: marek.vasut+renesas at gmail.com; Ye Li <ye.li@nxp.com>; dl-uboot-imx
> >> <uboot-imx@nxp.com>; u-boot at lists.denx.de
> >> Subject: Re: [PATCH] mmc: correct the HS400 initialization process
> >>
> >> On 3/18/19 9:23 AM, BOUGH CHEN wrote:
> >>> After the commit b9a2a0e2e9c0 ("mmc: Add support for downgrading
> >>> HS200/HS400 to HS mode"), it add a parameter in mmc_set_card_speed()
> >>> which indicates that the HS200/HS400 to HS downgrade is happening.
> >>>
> >>> During the HS400 initialization, first select to HS200, and config the
> >>> related clock rate, then downgrade to HS mode. So here also need to
> >>> config the downgrade value to be true, make sure in the function
> >>> mmc_set_card_speed(), after switch to HS mode, first config the clock
> >>> rate, then read the EXT_CSD. Otherwise read EXT_CSD in HS mode at
> >>> wrong clock rate, e.g. 200MHz, may lead to uncertain result.
> >>
> >> I think the fix is right, but the reasoning for it is not.
> >>
> >> If you call mmc_set_card_speed() with hsdowngrade=true, it will result in
> >> calling __mmc_switch() with send_status=false , which in turn means that
> >> after issuing the MMC_CMD_SWITCH command, the code won't poll the card
> >> using MMC_CMD_SEND_STATUS, but just wait a bit and then switch the bus
> >> properties. This is indeed required when switching bus properties.
> >> And that's what I think was making your card unstable.
> >>
> >> Is that the case ?
> > 
> > Sorry for the tardy reply, I miss the email last week.
> > No, if without this patch, even I add the dealy after the switch command, eMMC still stuck after the CMD8.
> > The main issue is that, in mmc_set_card_speed, if the bus mode the HS mode, it will send CMD8 to get the EXT_CSD, but the clock is still 200MHz at that time.
> > It is wrong that EMMC output data in HS mode at 200MHz. 
> 
> OK, that makes sense.

Do we need a re-worded commit message then or no?  Thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190325/4dc32caa/attachment.sig>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] [PATCH] mmc: correct the HS400 initialization process
  2019-03-25 12:10       ` Tom Rini
@ 2019-03-25 12:28         ` Marek Vasut
  0 siblings, 0 replies; 6+ messages in thread
From: Marek Vasut @ 2019-03-25 12:28 UTC (permalink / raw)
  To: u-boot

On 3/25/19 1:10 PM, Tom Rini wrote:
> On Mon, Mar 25, 2019 at 12:16:53PM +0100, Marek Vasut wrote:
>> On 3/25/19 11:24 AM, BOUGH CHEN wrote:
>>>
>>>> -----Original Message-----
>>>> From: Marek Vasut [mailto:marek.vasut at gmail.com]
>>>> Sent: 2019年3月18日 19:53
>>>> To: BOUGH CHEN <haibo.chen@nxp.com>; jh80.chung at samsung.com;
>>>> trini at konsulko.com
>>>> Cc: marek.vasut+renesas at gmail.com; Ye Li <ye.li@nxp.com>; dl-uboot-imx
>>>> <uboot-imx@nxp.com>; u-boot at lists.denx.de
>>>> Subject: Re: [PATCH] mmc: correct the HS400 initialization process
>>>>
>>>> On 3/18/19 9:23 AM, BOUGH CHEN wrote:
>>>>> After the commit b9a2a0e2e9c0 ("mmc: Add support for downgrading
>>>>> HS200/HS400 to HS mode"), it add a parameter in mmc_set_card_speed()
>>>>> which indicates that the HS200/HS400 to HS downgrade is happening.
>>>>>
>>>>> During the HS400 initialization, first select to HS200, and config the
>>>>> related clock rate, then downgrade to HS mode. So here also need to
>>>>> config the downgrade value to be true, make sure in the function
>>>>> mmc_set_card_speed(), after switch to HS mode, first config the clock
>>>>> rate, then read the EXT_CSD. Otherwise read EXT_CSD in HS mode at
>>>>> wrong clock rate, e.g. 200MHz, may lead to uncertain result.
>>>>
>>>> I think the fix is right, but the reasoning for it is not.
>>>>
>>>> If you call mmc_set_card_speed() with hsdowngrade=true, it will result in
>>>> calling __mmc_switch() with send_status=false , which in turn means that
>>>> after issuing the MMC_CMD_SWITCH command, the code won't poll the card
>>>> using MMC_CMD_SEND_STATUS, but just wait a bit and then switch the bus
>>>> properties. This is indeed required when switching bus properties.
>>>> And that's what I think was making your card unstable.
>>>>
>>>> Is that the case ?
>>>
>>> Sorry for the tardy reply, I miss the email last week.
>>> No, if without this patch, even I add the dealy after the switch command, eMMC still stuck after the CMD8.
>>> The main issue is that, in mmc_set_card_speed, if the bus mode the HS mode, it will send CMD8 to get the EXT_CSD, but the clock is still 200MHz at that time.
>>> It is wrong that EMMC output data in HS mode at 200MHz. 
>>
>> OK, that makes sense.
> 
> Do we need a re-worded commit message then or no?  Thanks!

A bit wouldn't hurt, to clarify things.

-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-03-25 12:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-18  8:23 [U-Boot] [PATCH] mmc: correct the HS400 initialization process BOUGH CHEN
2019-03-18 11:53 ` Marek Vasut
2019-03-25 10:24   ` BOUGH CHEN
2019-03-25 11:16     ` Marek Vasut
2019-03-25 12:10       ` Tom Rini
2019-03-25 12:28         ` Marek Vasut

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.