mmc: retry CMD1 in mmc_send_op_cond() until the eMMC is ready
PATCH 1/1 mmc: retry CMD1 in mmc_send_op_cond() until the eMMC is ready
From: Haibo Chen <[email protected]>
According to eMMC specification v5.1 section 6.4.3, we should issue CMD1 repeatedly in the idle state until the eMMC is ready even if mmc_send_op_cond() send CMD1 with argument = 0. Otherwise some eMMC devices seems to enter the inactive mode after mmc_complete_op_cond() issued CMD0 when the eMMC device is busy. This patch also align with Linux 5.7.
--- drivers/mmc/mmc.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-)
drivers/mmc/mmc.c +33 -8
@@ -664,21 +664,46 @@ static int mmc_send_op_cond_iter(struct mmc *mmc, int use_arg)static int mmc_send_op_cond (struct mmc *mmc) { +struct mmc_cmd cmd;int err, i; +int timeout =1000 ; +ulong start;/* Some cards seem to need this */ mmc_go_idle (mmc); -/* Asking to the card its capabilities */ -for (i =0 ; i <2 ; i++) { - err =mmc_send_op_cond_iter (mmc, i !=0 ); + cmd.cmdidx =MMC_CMD_SEND_OP_COND ; + cmd.resp_type =MMC_RSP_R3 ; + cmd.cmdarg =0 ; + + start =get_timer (0 ); +/* +* According to eMMC specification v5.1 section 6.4.3, we +* should issue CMD1 repeatedly in the idle state until +* the eMMC is ready. Otherwise some eMMC devices seem to enter +* the inactive mode after mmc_complete_op_cond() issued CMD0 when +* the eMMC device is busy. +*/ +while (1 ) { + err =mmc_send_cmd (mmc, &cmd,NULL );if (err)return err; - -/* exit if not busy (flag seems to be inverted) */ -if (mmc->ocr &OCR_BUSY ) -break ; +if (mmc_host_is_spi (mmc)) { +if (!(cmd.response[0 ] & (1 <<0 ))) +break ; + }else { + mmc->ocr = cmd.response[0 ]; +/* exit if not busy (flag seems to be inverted) */ +if (mmc->ocr &OCR_BUSY ) +break ; + } +if (get_timer (start) > timeout) +return -EOPNOTSUPP ; +udelay (100 ); +if (!mmc_host_is_spi (mmc)) + cmd.cmdarg = cmd.response[0 ] | (1 <<30 ); } + mmc->op_cond_pending =1 ;return 0 ; }
@@ -691,7 +716,7 @@ static int mmc_complete_op_cond(struct mmc *mmc)int err; mmc->op_cond_pending =0 ; -if (!(mmc->ocr &OCR_BUSY )) { +if (mmc->ocr &OCR_BUSY ) {/* Some cards seem to need this */ mmc_go_idle (mmc);
Signature · 1 line
2.17.1
PATCH 1/1 mmc: retry CMD1 in mmc_send_op_cond() until the eMMC is ready
Quoted 47 lines
Subject: [PATCH] mmc: retry CMD1 in
mmc_send_op_cond()until the eMMC is readyFrom: Haibo Chen <[email protected]>
According to eMMC specification v5.1 section 6.4.3, we should issue CMD1 repeatedly in the idle state until the eMMC is ready even if
mmc_send_op_cond()send CMD1 with argument = 0. Otherwise some eMMC devices seems to enter the inactive mode aftermmc_complete_op_cond()issued CMD0 when the eMMC device is busy. This patch also align with Linux 5.7.Signed-off-by Haibo Chen <[email protected]>--- drivers/mmc/mmc.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-)drivers/mmc/mmc.c index renamed from drivers/mmc/mmc.c +0
-0
523c055967..509549756b100644drivers/mmc/mmc.c +13
-3@@ -664,21 +664,46 @@ static int mmc_send_op_cond_iter(struct mmc *mmc, int use_arg)static int mmc_send_op_cond (struct mmc *mmc) { +struct mmc_cmd cmd;int err, i; +int timeout =1000 ; +ulong start;/* Some cards seem to need this */ mmc_go_idle (mmc); -/* Asking to the card its capabilities */ -for (i =0 ; i <2 ; i++) { - err =mmc_send_op_cond_iter (mmc, i !=0 ); + cmd.cmdidx =MMC_CMD_SEND_OP_COND ; + cmd.resp_type =MMC_RSP_R3 ; + cmd.cmdarg =0 ; + + start =get_timer (0 ); +/* +* According to eMMC specification v5.1 section 6.4.3, we +* should issue CMD1 repeatedly in the idle state until +* the eMMC is ready. Otherwise some eMMC devices seem to enter +* the inactive mode after mmc_complete_op_cond() issued CMD0 when
drivers/mmc/mmc.c
Quoted 2 lines
drivers/mmc/mmc.c +2
-0+* the eMMC device is busy. +*/
Could we just extend the previous for loop to fix the issue? Your piece code duplicate much of the code and changed the original behavior.
Quoted 9 lines
drivers/mmc/mmc.c +3
-4+while (1 ) { + err =mmc_send_cmd (mmc, &cmd,NULL );if (err)return err; - -/* exit if not busy (flag seems to be inverted) */ -if (mmc->ocr &OCR_BUSY ) -break ; +if (mmc_host_is_spi (mmc)) {
drivers/mmc/mmc.c
Quoted 10 lines
drivers/mmc/mmc.c +10
-0+if (!(cmd.response[0 ] & (1 <<0 ))) +break ; + }else { + mmc->ocr = cmd.response[0 ]; +/* exit if not busy (flag seems to be inverted) */ +if (mmc->ocr &OCR_BUSY ) +break ; + } +if (get_timer (start) > timeout) +return -EOPNOTSUPP ;
TIMEOUT, please.
drivers/mmc/mmc.c
Quoted 1 line
drivers/mmc/mmc.c +1
-0+udelay (100 );
This will change the original behavior by adding a delay.
drivers/mmc/mmc.c
Quoted 2 lines
drivers/mmc/mmc.c +2
-0+if (!mmc_host_is_spi (mmc)) + cmd.cmdarg = cmd.response[0 ] | (1 <<30 );
Do we need "1 << 30" ?
drivers/mmc/mmc.c static int mmc_complete_op_cond(struct mmc · line 720
Quoted 12 lines
drivers/mmc/mmc.c +2
-1} + mmc->op_cond_pending =1 ;return 0 ; }@@ -691,7 +716,7 @@ static int mmc_complete_op_cond(struct mmc *mmc)int err; mmc->op_cond_pending =0 ; -if (!(mmc->ocr &OCR_BUSY )) { +if (mmc->ocr &OCR_BUSY ) {
When card not go out busy, it means card not
finish power up seq. Why drop !?
drivers/mmc/mmc.c static int mmc_complete_op_cond(struct mmc
Quoted 4 lines
drivers/mmc/mmc.c +0
-1/* Some cards seem to need this */ mmc_go_idle (mmc); --
Would the following patch help?
drivers/mmc/mmc.c +7 -1
@@ -665,12 +665,15 @@ static int mmc_send_op_cond_iter(struct mmc *mmc, int use_arg)static int mmc_send_op_cond (struct mmc *mmc) {int err, i; +int timeout =1000 ; +ulong start;/* Some cards seem to need this */ mmc_go_idle (mmc); + start =get_timer (0 );/* Asking to the card its capabilities */ -for (i =0 ; i <2 ; i++) { +for (i =0 ; ; i++) { err =mmc_send_op_cond_iter (mmc, i !=0 );if (err)return err;
@@ -678,6 +681,9 @@ static int mmc_send_op_cond(struct mmc *mmc)/* exit if not busy (flag seems to be inverted) */ if (mmc->ocr &OCR_BUSY )break ; + +if (get_timer (start) > timeout) +return -ETIMEDOUT ; } mmc->op_cond_pending =1 ;return 0 ;
Thanks,
Peng.
Quoted 1 line
2.17.1
PATCH 1/1 mmc: retry CMD1 in mmc_send_op_cond() until the eMMC is ready
Quoted 11 lines · Peng Fan
Quoted 11 lines
Subject: [PATCH] mmc: retry CMD1 in
mmc_send_op_cond()until the eMMC is readyFrom: Haibo Chen <[email protected]>
According to eMMC specification v5.1 section 6.4.3, we should issue CMD1 repeatedly in the idle state until the eMMC is ready even if
mmc_send_op_cond()send CMD1 with argument = 0. Otherwise some eMMC devices seems to enter the inactive mode aftermmc_complete_op_cond()issued CMD0 when the eMMC device is busy. This patch also align with Linux 5.7.
Well, i think that it can't compare to linux driver. is your issue fixed with this patch?
As i know, this sequence is not follow correct spec. To enhance boot, it was skipping the polling time. If there is a problem, could you explain in more detail? Then I will also check on my targets.
Quoted 83 lines
Quoted 36 lines
Signed-off-by Haibo Chen <[email protected]>--- drivers/mmc/mmc.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-)drivers/mmc/mmc.c index renamed from drivers/mmc/mmc.c +0
-0
523c055967..509549756b100644drivers/mmc/mmc.c +13
-3@@ -664,21 +664,46 @@ static int mmc_send_op_cond_iter(struct mmc *mmc, int use_arg)static int mmc_send_op_cond (struct mmc *mmc) { +struct mmc_cmd cmd;int err, i; +int timeout =1000 ; +ulong start;/* Some cards seem to need this */ mmc_go_idle (mmc); -/* Asking to the card its capabilities */ -for (i =0 ; i <2 ; i++) { - err =mmc_send_op_cond_iter (mmc, i !=0 ); + cmd.cmdidx =MMC_CMD_SEND_OP_COND ; + cmd.resp_type =MMC_RSP_R3 ; + cmd.cmdarg =0 ; + + start =get_timer (0 ); +/* +* According to eMMC specification v5.1 section 6.4.3, we +* should issue CMD1 repeatedly in the idle state until +* the eMMC is ready. Otherwise some eMMC devices seem to enter +* the inactive mode after mmc_complete_op_cond() issued CMD0 when
drivers/mmc/mmc.c
Quoted 2 lines
drivers/mmc/mmc.c +2
-0+* the eMMC device is busy. +*/ Could we just extend the previous for loop to fix the issue? Your piece code duplicate much of the code and changed the original behavior.
Quoted 9 lines
drivers/mmc/mmc.c +3
-4+while (1 ) { + err =mmc_send_cmd (mmc, &cmd,NULL );if (err)return err; - -/* exit if not busy (flag seems to be inverted) */ -if (mmc->ocr &OCR_BUSY ) -break ; +if (mmc_host_is_spi (mmc)) {drivers/mmc/mmc.c
Quoted 10 lines
drivers/mmc/mmc.c +10
-0+if (!(cmd.response[0 ] & (1 <<0 ))) +break ; + }else { + mmc->ocr = cmd.response[0 ]; +/* exit if not busy (flag seems to be inverted) */ +if (mmc->ocr &OCR_BUSY ) +break ; + } +if (get_timer (start) > timeout) +return -EOPNOTSUPP ;TIMEOUT, please.
drivers/mmc/mmc.c
Quoted 1 line
drivers/mmc/mmc.c +1
-0+udelay (100 );This will change the original behavior by adding a delay.
drivers/mmc/mmc.c
Quoted 2 lines
drivers/mmc/mmc.c +2
-0+if (!mmc_host_is_spi (mmc)) + cmd.cmdarg = cmd.response[0 ] | (1 <<30 );Do we need "1 << 30" ?
Quoted 9 lines
drivers/mmc/mmc.c +1
-0} + mmc->op_cond_pending =1 ;return 0 ; }@@ -691,7 +716,7 @@ static int mmc_complete_op_cond(struct mmc *mmc)int err;
Quoted 6 lines
drivers/mmc/mmc.c static int mmc_complete_op_cond(struct mmc · line 720
Quoted 3 lines
drivers/mmc/mmc.c +1
-1mmc->op_cond_pending =0 ; -if (!(mmc->ocr &OCR_BUSY )) { +if (mmc->ocr &OCR_BUSY ) {When card not go out busy, it means card not
finish power up seq. Why drop !?
Right. It doesn't finish power-ups seq.
If it's working with this patch, it seems something wrong.
Quoted 7 lines
drivers/mmc/mmc.c static int mmc_send_op_cond_iter(struct mmc *mmc, int use_arg)
Quoted 5 lines
drivers/mmc/mmc.c +0
-1/* Some cards seem to need this */ mmc_go_idle (mmc); --Would the following patch help?
yes. it's more better.
If need to increase polling time, i think it's correct place in mmc_complete_op_cond().
Best Regards,
Jaehoon Chung
Quoted 38 lines
drivers/mmc/mmc.c +7
-1@@ -665,12 +665,15 @@ static int mmc_send_op_cond_iter(struct mmc *mmc, int use_arg)static int mmc_send_op_cond (struct mmc *mmc) {int err, i; +int timeout =1000 ; +ulong start;/* Some cards seem to need this */ mmc_go_idle (mmc); + start =get_timer (0 );/* Asking to the card its capabilities */ -for (i =0 ; i <2 ; i++) { +for (i =0 ; ; i++) { err =mmc_send_op_cond_iter (mmc, i !=0 );if (err)return err;@@ -678,6 +681,9 @@ static int mmc_send_op_cond(struct mmc *mmc)/* exit if not busy (flag seems to be inverted) */ if (mmc->ocr &OCR_BUSY )break ; + +if (get_timer (start) > timeout) +return -ETIMEDOUT ; } mmc->op_cond_pending =1 ;return 0 ;Thanks,
Peng.Quoted 1 line
2.17.1
PATCH 1/1 mmc: retry CMD1 in mmc_send_op_cond() until the eMMC is ready
In reply to Peng FanQuoted 108 lines
-----Original Message-----
From: Peng Fan <[email protected]>
Sent: 2020?5?19? 11:38
To: BOUGH CHEN <[email protected]>; u-boot at lists.denx.de
Cc: dl-uboot-imx <[email protected]>
Subject: RE: [PATCH] mmc: retry CMD1 inmmc_send_op_cond()until the eMMC is readyQuoted 8 lines
Subject: [PATCH] mmc: retry CMD1 in
mmc_send_op_cond()until the eMMC is readyFrom: Haibo Chen <[email protected]>
According to eMMC specification v5.1 section 6.4.3, we should issue CMD1 repeatedly in the idle state until the eMMC is ready even if
mmc_send_op_cond()send CMD1 with argument = 0. Otherwise someeMMC
Quoted 39 lines
devices seems to enter the inactive mode after
mmc_complete_op_cond()issued CMD0 when the eMMC device is busy. This patch also align with Linux 5.7.Signed-off-by Haibo Chen <[email protected]>--- drivers/mmc/mmc.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-)drivers/mmc/mmc.c index renamed from drivers/mmc/mmc.c +0
-0
523c055967..509549756b100644drivers/mmc/mmc.c +13
-3@@ -664,21 +664,46 @@ static int mmc_send_op_cond_iter(struct mmc *mmc, int use_arg)static int mmc_send_op_cond (struct mmc *mmc) { +struct mmc_cmd cmd;int err, i; +int timeout =1000 ; +ulong start;/* Some cards seem to need this */ mmc_go_idle (mmc); -/* Asking to the card its capabilities */ -for (i =0 ; i <2 ; i++) { - err =mmc_send_op_cond_iter (mmc, i !=0 ); + cmd.cmdidx =MMC_CMD_SEND_OP_COND ; + cmd.resp_type =MMC_RSP_R3 ; + cmd.cmdarg =0 ; + + start =get_timer (0 ); +/* +* According to eMMC specification v5.1 section 6.4.3, we +* should issue CMD1 repeatedly in the idle state until +* the eMMC is ready. Otherwise some eMMC devices seem to enter +* the inactive mode after mmc_complete_op_cond() issued CMD0 when
drivers/mmc/mmc.c
Quoted 2 lines
drivers/mmc/mmc.c +2
-0+* the eMMC device is busy. +*/ Could we just extend the previous for loop to fix the issue?
Your piece code duplicate much of the code and changed the original behavior.Quoted 9 lines
drivers/mmc/mmc.c +3
-4+while (1 ) { + err =mmc_send_cmd (mmc, &cmd,NULL );if (err)return err; - -/* exit if not busy (flag seems to be inverted) */ -if (mmc->ocr &OCR_BUSY ) -break ; +if (mmc_host_is_spi (mmc)) {drivers/mmc/mmc.c
Quoted 10 lines
drivers/mmc/mmc.c +10
-0+if (!(cmd.response[0 ] & (1 <<0 ))) +break ; + }else { + mmc->ocr = cmd.response[0 ]; +/* exit if not busy (flag seems to be inverted) */ +if (mmc->ocr &OCR_BUSY ) +break ; + } +if (get_timer (start) > timeout) +return -EOPNOTSUPP ;TIMEOUT, please.
drivers/mmc/mmc.c
Quoted 1 line
drivers/mmc/mmc.c +1
-0+udelay (100 );This will change the original behavior by adding a delay.
drivers/mmc/mmc.c
Quoted 2 lines
drivers/mmc/mmc.c +2
-0+if (!mmc_host_is_spi (mmc)) + cmd.cmdarg = cmd.response[0 ] | (1 <<30 );Do we need "1 << 30" ?
drivers/mmc/mmc.c static int mmc_complete_op_cond(struct mmc · line 720
Quoted 12 lines
drivers/mmc/mmc.c +2
-1} + mmc->op_cond_pending =1 ;return 0 ; }@@ -691,7 +716,7 @@ static int mmc_complete_op_cond(struct mmc *mmc)int err; mmc->op_cond_pending =0 ; -if (!(mmc->ocr &OCR_BUSY )) { +if (mmc->ocr &OCR_BUSY ) {When card not go out busy, it means card not finish power up seq. Why drop !?
Quoted 7 lines
drivers/mmc/mmc.c static int mmc_send_op_cond_iter(struct mmc *mmc, int use_arg)
Quoted 4 lines
drivers/mmc/mmc.c +0
-1/* Some cards seem to need this */ mmc_go_idle (mmc); --Would the following patch help?
Hi Peng,
Thanks for your carefully review and suggestion, most eMMC chip can work normal on the original code, only some Toshiba eMMC need more time to get out of busy after cmd1. The patch I send out just refer to the Linux driver code, and pass on the customer side.
Currently I'm not sure whether the bit 30 of the argument for cmd1 is necessary for this eMMC, I will get the reworked board which soldered this Toshiba eMMC in a few days, then I can test on my hand. Will test this then and give you response.
Best Regards
Haibo Chen
Quoted 34 lines
drivers/mmc/mmc.c index renamed from drivers/mmc/mmc.c +0
-0
523c055967..d3a0538cdb100644drivers/mmc/mmc.c +7
-1@@ -665,12 +665,15 @@ static int mmc_send_op_cond_iter(struct mmc *mmc, int use_arg) static int mmc_send_op_cond(struct mmc *mmc) {int err, i; +int timeout =1000 ; +ulong start;/* Some cards seem to need this */ mmc_go_idle (mmc); + start =get_timer (0 );/* Asking to the card its capabilities */ -for (i =0 ; i <2 ; i++) { +for (i =0 ; ; i++) { err =mmc_send_op_cond_iter (mmc, i !=0 );if (err)return err;@@ -678,6 +681,9 @@ static int mmc_send_op_cond(struct mmc *mmc)/* exit if not busy (flag seems to be inverted) */ if (mmc->ocr &OCR_BUSY )break ; + +if (get_timer (start) > timeout) +return -ETIMEDOUT ; } mmc->op_cond_pending =1 ;return 0 ;Thanks,
Peng.Quoted 1 line
2.17.1