mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mci: sdhci: arasan: fix probing eMMC without no-sd
@ 2023-01-03 22:03 Ahmad Fatoum
  2023-01-04 10:30 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2023-01-03 22:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum, Michael Graichen, Steffen Trumtrar, Yann Sionneau

Usual procedure when calling the detect callback of a MCI host driver is
to assume the connected card is a SD-Card and on timeout, treat it as
MMC instead. The Arasan driver failed to do this properly leading to the
need to specify no-sd to get eMMCs working. This is because the driver
only handled software timeouts gracefully: The MCI host itself may also
report timeout and it should not be treated as an error and instead
should be silently passed along as -ETIMEDOUT, so the MCI core can check
against it and fall back to eMMC after a failed probe for SD.

Reported-by: Michael Graichen <michael.graichen@hotmail.com>
Reported-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Cc: Yann Sionneau <ysionneau@kalray.eu>
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 drivers/mci/arasan-sdhci.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/mci/arasan-sdhci.c b/drivers/mci/arasan-sdhci.c
index 22389503becf..00a8ceed6836 100644
--- a/drivers/mci/arasan-sdhci.c
+++ b/drivers/mci/arasan-sdhci.c
@@ -136,16 +136,17 @@ static void arasan_sdhci_set_ios(struct mci_host *mci, struct mci_ios *ios)
 static int arasan_sdhci_wait_for_done(struct arasan_sdhci_host *host, u32 mask)
 {
 	u64 start = get_time_ns();
-	u16 stat;
-	u16 error;
+	u32 stat;
 
 	do {
-		stat = sdhci_read16(&host->sdhci, SDHCI_INT_NORMAL_STATUS);
+		stat = sdhci_read32(&host->sdhci, SDHCI_INT_STATUS);
+
+		if (stat & SDHCI_INT_TIMEOUT)
+			return -ETIMEDOUT;
+
 		if (stat & SDHCI_INT_ERROR) {
-			error = sdhci_read16(&host->sdhci,
-					     SDHCI_INT_ERROR_STATUS);
 			dev_err(host->mci.hw_dev, "SDHCI_INT_ERROR: 0x%08x\n",
-				error);
+				stat);
 			return -EPERM;
 		}
 
@@ -159,8 +160,11 @@ static int arasan_sdhci_wait_for_done(struct arasan_sdhci_host *host, u32 mask)
 	return 0;
 }
 
-static void print_error(struct arasan_sdhci_host *host, int cmdidx)
+static void print_error(struct arasan_sdhci_host *host, int cmdidx, int ret)
 {
+	if (ret == -ETIMEDOUT)
+		return;
+
 	dev_err(host->mci.hw_dev,
 		"error while transferring data for command %d\n", cmdidx);
 	dev_err(host->mci.hw_dev, "state = 0x%08x , interrupt = 0x%08x\n",
@@ -210,10 +214,8 @@ static int arasan_sdhci_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
 	sdhci_write16(&host->sdhci, SDHCI_COMMAND, command);
 
 	ret = arasan_sdhci_wait_for_done(host, mask);
-	if (ret == -EPERM)
+	if (ret)
 		goto error;
-	else if (ret)
-		return ret;
 
 	sdhci_read_response(&host->sdhci, cmd);
 	sdhci_write32(&host->sdhci, SDHCI_INT_STATUS, mask);
@@ -223,7 +225,7 @@ static int arasan_sdhci_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
 
 error:
 	if (ret) {
-		print_error(host, cmd->cmdidx);
+		print_error(host, cmd->cmdidx, ret);
 		arasan_sdhci_reset(host, BIT(1)); // SDHCI_RESET_CMD
 		arasan_sdhci_reset(host, BIT(2)); // SDHCI_RESET_DATA
 	}
-- 
2.38.1




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

* Re: [PATCH] mci: sdhci: arasan: fix probing eMMC without no-sd
  2023-01-03 22:03 [PATCH] mci: sdhci: arasan: fix probing eMMC without no-sd Ahmad Fatoum
@ 2023-01-04 10:30 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2023-01-04 10:30 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox, Michael Graichen, Steffen Trumtrar, Yann Sionneau

On Tue, Jan 03, 2023 at 11:03:17PM +0100, Ahmad Fatoum wrote:
> Usual procedure when calling the detect callback of a MCI host driver is
> to assume the connected card is a SD-Card and on timeout, treat it as
> MMC instead. The Arasan driver failed to do this properly leading to the
> need to specify no-sd to get eMMCs working. This is because the driver
> only handled software timeouts gracefully: The MCI host itself may also
> report timeout and it should not be treated as an error and instead
> should be silently passed along as -ETIMEDOUT, so the MCI core can check
> against it and fall back to eMMC after a failed probe for SD.
> 
> Reported-by: Michael Graichen <michael.graichen@hotmail.com>
> Reported-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> Cc: Yann Sionneau <ysionneau@kalray.eu>
> Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
> ---
>  drivers/mci/arasan-sdhci.c | 24 +++++++++++++-----------
>  1 file changed, 13 insertions(+), 11 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/mci/arasan-sdhci.c b/drivers/mci/arasan-sdhci.c
> index 22389503becf..00a8ceed6836 100644
> --- a/drivers/mci/arasan-sdhci.c
> +++ b/drivers/mci/arasan-sdhci.c
> @@ -136,16 +136,17 @@ static void arasan_sdhci_set_ios(struct mci_host *mci, struct mci_ios *ios)
>  static int arasan_sdhci_wait_for_done(struct arasan_sdhci_host *host, u32 mask)
>  {
>  	u64 start = get_time_ns();
> -	u16 stat;
> -	u16 error;
> +	u32 stat;
>  
>  	do {
> -		stat = sdhci_read16(&host->sdhci, SDHCI_INT_NORMAL_STATUS);
> +		stat = sdhci_read32(&host->sdhci, SDHCI_INT_STATUS);
> +
> +		if (stat & SDHCI_INT_TIMEOUT)
> +			return -ETIMEDOUT;
> +
>  		if (stat & SDHCI_INT_ERROR) {
> -			error = sdhci_read16(&host->sdhci,
> -					     SDHCI_INT_ERROR_STATUS);
>  			dev_err(host->mci.hw_dev, "SDHCI_INT_ERROR: 0x%08x\n",
> -				error);
> +				stat);
>  			return -EPERM;
>  		}
>  
> @@ -159,8 +160,11 @@ static int arasan_sdhci_wait_for_done(struct arasan_sdhci_host *host, u32 mask)
>  	return 0;
>  }
>  
> -static void print_error(struct arasan_sdhci_host *host, int cmdidx)
> +static void print_error(struct arasan_sdhci_host *host, int cmdidx, int ret)
>  {
> +	if (ret == -ETIMEDOUT)
> +		return;
> +
>  	dev_err(host->mci.hw_dev,
>  		"error while transferring data for command %d\n", cmdidx);
>  	dev_err(host->mci.hw_dev, "state = 0x%08x , interrupt = 0x%08x\n",
> @@ -210,10 +214,8 @@ static int arasan_sdhci_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
>  	sdhci_write16(&host->sdhci, SDHCI_COMMAND, command);
>  
>  	ret = arasan_sdhci_wait_for_done(host, mask);
> -	if (ret == -EPERM)
> +	if (ret)
>  		goto error;
> -	else if (ret)
> -		return ret;
>  
>  	sdhci_read_response(&host->sdhci, cmd);
>  	sdhci_write32(&host->sdhci, SDHCI_INT_STATUS, mask);
> @@ -223,7 +225,7 @@ static int arasan_sdhci_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
>  
>  error:
>  	if (ret) {
> -		print_error(host, cmd->cmdidx);
> +		print_error(host, cmd->cmdidx, ret);
>  		arasan_sdhci_reset(host, BIT(1)); // SDHCI_RESET_CMD
>  		arasan_sdhci_reset(host, BIT(2)); // SDHCI_RESET_DATA
>  	}
> -- 
> 2.38.1
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

end of thread, other threads:[~2023-01-04 10:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-03 22:03 [PATCH] mci: sdhci: arasan: fix probing eMMC without no-sd Ahmad Fatoum
2023-01-04 10:30 ` Sascha Hauer

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