public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/2] Fix some corner cases in bus width setting
@ 2014-12-25 16:22 Andrew Gabbasov
  2014-12-25 16:22 ` [U-Boot] [PATCH 1/2] mmc: Avoid redundant switching to 1-bit bus width for MMC cards Andrew Gabbasov
  2014-12-25 16:22 ` [U-Boot] [PATCH 2/2] mmc: Skip changing bus width for MMC cards earlier than version 4.0 Andrew Gabbasov
  0 siblings, 2 replies; 6+ messages in thread
From: Andrew Gabbasov @ 2014-12-25 16:22 UTC (permalink / raw)
  To: u-boot

Among other fixes, the commit 786e8f818c25265d12d5d06e257fe2b1ba516134
"mmc: Fix handling of bus widths and DDR card capabilities" changed
bus width setting code so that if the attempt to switch to last 1-bit
width item fails, the whole initialization fails. This seems to be more
correct than earlier ignoring of such error, but this makes sense
if the bus width was actually switched. But if all the switching
commands fail (e.g. because the card does not support bus width
switching at all), then we could just skip last switching to default
bus width and treat it as a success.

Also, MMC cards of earlier versions than MMC standard version 4.0
do not support wider bus widths, so it doesn't make sense to even try
to switch the bus width for such cards.

Andrew Gabbasov (2):
  mmc: Avoid redundant switching to 1-bit bus width for MMC cards
  mmc: Skip changing bus width for MMC cards earlier than version 4.0

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

-- 
2.1.0

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

* [U-Boot] [PATCH 1/2] mmc: Avoid redundant switching to 1-bit bus width for MMC cards
  2014-12-25 16:22 [U-Boot] [PATCH 0/2] Fix some corner cases in bus width setting Andrew Gabbasov
@ 2014-12-25 16:22 ` Andrew Gabbasov
  2015-01-19 14:42   ` Pantelis Antoniou
  2014-12-25 16:22 ` [U-Boot] [PATCH 2/2] mmc: Skip changing bus width for MMC cards earlier than version 4.0 Andrew Gabbasov
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Gabbasov @ 2014-12-25 16:22 UTC (permalink / raw)
  To: u-boot

If all the commands switching an MMC card to 4- or 8-bit bus width fail,
and the bus width for the controller and the driver is still set
to default 1 bit, there is no need to send one more command to switch
the card to 1-bit bus width. Also, if the card or host controller do not
support wider bus widths, there is no need to send a switch command at all.

However, if one of switch commands succeeds, but the subsequent ext_csd
fields comparison fails, the card should be switched to some other bus width
(next in the list for the loop), or to default 1-bit bus width as a last
resort. That's why it would be incorrect to just remove the 1-bit bus width
case from the list, it should still be processed in some cases.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
Tested-by: Alexey Brodkin <abrodkin@synopsys.com>
---
 drivers/mmc/mmc.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 1eb9c27..c0cf318 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -1139,6 +1139,18 @@ static int mmc_startup(struct mmc *mmc)
 			unsigned int caps = ext_to_hostcaps[extw];
 
 			/*
+			 * If the bus width is still not changed,
+			 * don't try to set the default again.
+			 * Otherwise, recover from switch attempts
+			 * by switching to 1-bit bus width.
+			 */
+			if ((extw == EXT_CSD_BUS_WIDTH_1) &&
+			    (mmc->bus_width == 1)) {
+				err = 0;
+				break;
+			}
+
+			/*
 			 * Check to make sure the card and controller support
 			 * these capabilities
 			 */
-- 
2.1.0

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

* [U-Boot] [PATCH 2/2] mmc: Skip changing bus width for MMC cards earlier than version 4.0
  2014-12-25 16:22 [U-Boot] [PATCH 0/2] Fix some corner cases in bus width setting Andrew Gabbasov
  2014-12-25 16:22 ` [U-Boot] [PATCH 1/2] mmc: Avoid redundant switching to 1-bit bus width for MMC cards Andrew Gabbasov
@ 2014-12-25 16:22 ` Andrew Gabbasov
  2015-01-13 10:22   ` Alexey Brodkin
  2015-01-19 14:45   ` Pantelis Antoniou
  1 sibling, 2 replies; 6+ messages in thread
From: Andrew Gabbasov @ 2014-12-25 16:22 UTC (permalink / raw)
  To: u-boot

Wider bus widths (larger than default 1 bit) appeared in MMC standard
version 4.0. So, for MMC cards of any earlier version trying to change
the bus width (including ext_csd comparison) does not make any sense.
It may work incorrectly and at least cause unnecessary timeouts.
So, just skip the entire bus width related activity for earlier versions.

Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
Tested-by: Alexey Brodkin <abrodkin@synopsys.com>
---
 drivers/mmc/mmc.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index c0cf318..14d6a13 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -486,7 +486,7 @@ static int mmc_change_freq(struct mmc *mmc)
 	char cardtype;
 	int err;
 
-	mmc->card_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
+	mmc->card_caps = 0;
 
 	if (mmc_host_is_spi(mmc))
 		return 0;
@@ -495,6 +495,8 @@ static int mmc_change_freq(struct mmc *mmc)
 	if (mmc->version < MMC_VERSION_4)
 		return 0;
 
+	mmc->card_caps |= MMC_MODE_4BIT | MMC_MODE_8BIT;
+
 	err = mmc_send_ext_csd(mmc, ext_csd);
 
 	if (err)
@@ -1107,7 +1109,8 @@ static int mmc_startup(struct mmc *mmc)
 			mmc->tran_speed = 50000000;
 		else
 			mmc->tran_speed = 25000000;
-	} else {
+	} else if (mmc->version >= MMC_VERSION_4) {
+		/* Only version 4 of MMC supports wider bus widths */
 		int idx;
 
 		/* An array of possible bus widths in order of preference */
-- 
2.1.0

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

* [U-Boot] [PATCH 2/2] mmc: Skip changing bus width for MMC cards earlier than version 4.0
  2014-12-25 16:22 ` [U-Boot] [PATCH 2/2] mmc: Skip changing bus width for MMC cards earlier than version 4.0 Andrew Gabbasov
@ 2015-01-13 10:22   ` Alexey Brodkin
  2015-01-19 14:45   ` Pantelis Antoniou
  1 sibling, 0 replies; 6+ messages in thread
From: Alexey Brodkin @ 2015-01-13 10:22 UTC (permalink / raw)
  To: u-boot

Hi Pantelis,

On Thu, 2014-12-25 at 10:22 -0600, Andrew Gabbasov wrote:
> Wider bus widths (larger than default 1 bit) appeared in MMC standard
> version 4.0. So, for MMC cards of any earlier version trying to change
> the bus width (including ext_csd comparison) does not make any sense.
> It may work incorrectly and at least cause unnecessary timeouts.
> So, just skip the entire bus width related activity for earlier versions.
> 
> Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
> Tested-by: Alexey Brodkin <abrodkin@synopsys.com>

This change fixes regression introduced in
https://patchwork.ozlabs.org/patch/416442/ for MMC cards.

Please consider applying if you don't have any objections.

Regards,
Alexey

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

* [U-Boot] [PATCH 1/2] mmc: Avoid redundant switching to 1-bit bus width for MMC cards
  2014-12-25 16:22 ` [U-Boot] [PATCH 1/2] mmc: Avoid redundant switching to 1-bit bus width for MMC cards Andrew Gabbasov
@ 2015-01-19 14:42   ` Pantelis Antoniou
  0 siblings, 0 replies; 6+ messages in thread
From: Pantelis Antoniou @ 2015-01-19 14:42 UTC (permalink / raw)
  To: u-boot

Hi Andrew,

> On Dec 25, 2014, at 18:22 , Andrew Gabbasov <andrew_gabbasov@mentor.com> wrote:
> 
> If all the commands switching an MMC card to 4- or 8-bit bus width fail,
> and the bus width for the controller and the driver is still set
> to default 1 bit, there is no need to send one more command to switch
> the card to 1-bit bus width. Also, if the card or host controller do not
> support wider bus widths, there is no need to send a switch command at all.
> 
> However, if one of switch commands succeeds, but the subsequent ext_csd
> fields comparison fails, the card should be switched to some other bus width
> (next in the list for the loop), or to default 1-bit bus width as a last
> resort. That's why it would be incorrect to just remove the 1-bit bus width
> case from the list, it should still be processed in some cases.
> 
> Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
> Tested-by: Alexey Brodkin <abrodkin@synopsys.com>
> ---
> drivers/mmc/mmc.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index 1eb9c27..c0cf318 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -1139,6 +1139,18 @@ static int mmc_startup(struct mmc *mmc)
> 			unsigned int caps = ext_to_hostcaps[extw];
> 
> 			/*
> +			 * If the bus width is still not changed,
> +			 * don't try to set the default again.
> +			 * Otherwise, recover from switch attempts
> +			 * by switching to 1-bit bus width.
> +			 */
> +			if ((extw == EXT_CSD_BUS_WIDTH_1) &&
> +			    (mmc->bus_width == 1)) {
> +				err = 0;
> +				break;
> +			}
> +
> +			/*
> 			 * Check to make sure the card and controller support
> 			 * these capabilities
> 			 */
> -- 
> 2.1.0
> 

Patch looks fine; taken the liberty to remove the superfluous parentheses at the
if statement.

Regards

? Pantelis

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

* [U-Boot] [PATCH 2/2] mmc: Skip changing bus width for MMC cards earlier than version 4.0
  2014-12-25 16:22 ` [U-Boot] [PATCH 2/2] mmc: Skip changing bus width for MMC cards earlier than version 4.0 Andrew Gabbasov
  2015-01-13 10:22   ` Alexey Brodkin
@ 2015-01-19 14:45   ` Pantelis Antoniou
  1 sibling, 0 replies; 6+ messages in thread
From: Pantelis Antoniou @ 2015-01-19 14:45 UTC (permalink / raw)
  To: u-boot

Hi Andrew,

> On Dec 25, 2014, at 18:22 , Andrew Gabbasov <andrew_gabbasov@mentor.com> wrote:
> 
> Wider bus widths (larger than default 1 bit) appeared in MMC standard
> version 4.0. So, for MMC cards of any earlier version trying to change
> the bus width (including ext_csd comparison) does not make any sense.
> It may work incorrectly and at least cause unnecessary timeouts.
> So, just skip the entire bus width related activity for earlier versions.
> 
> Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
> Tested-by: Alexey Brodkin <abrodkin@synopsys.com>
> ---
> drivers/mmc/mmc.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index c0cf318..14d6a13 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -486,7 +486,7 @@ static int mmc_change_freq(struct mmc *mmc)
> 	char cardtype;
> 	int err;
> 
> -	mmc->card_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
> +	mmc->card_caps = 0;
> 
> 	if (mmc_host_is_spi(mmc))
> 		return 0;
> @@ -495,6 +495,8 @@ static int mmc_change_freq(struct mmc *mmc)
> 	if (mmc->version < MMC_VERSION_4)
> 		return 0;
> 
> +	mmc->card_caps |= MMC_MODE_4BIT | MMC_MODE_8BIT;
> +
> 	err = mmc_send_ext_csd(mmc, ext_csd);
> 
> 	if (err)
> @@ -1107,7 +1109,8 @@ static int mmc_startup(struct mmc *mmc)
> 			mmc->tran_speed = 50000000;
> 		else
> 			mmc->tran_speed = 25000000;
> -	} else {
> +	} else if (mmc->version >= MMC_VERSION_4) {
> +		/* Only version 4 of MMC supports wider bus widths */
> 		int idx;
> 
> 		/* An array of possible bus widths in order of preference */
> -- 
> 2.1.0

Applied, thanks.

? Pantelis

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

end of thread, other threads:[~2015-01-19 14:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-25 16:22 [U-Boot] [PATCH 0/2] Fix some corner cases in bus width setting Andrew Gabbasov
2014-12-25 16:22 ` [U-Boot] [PATCH 1/2] mmc: Avoid redundant switching to 1-bit bus width for MMC cards Andrew Gabbasov
2015-01-19 14:42   ` Pantelis Antoniou
2014-12-25 16:22 ` [U-Boot] [PATCH 2/2] mmc: Skip changing bus width for MMC cards earlier than version 4.0 Andrew Gabbasov
2015-01-13 10:22   ` Alexey Brodkin
2015-01-19 14:45   ` Pantelis Antoniou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox