diff mbox

[U-Boot,v4,3/4] mmc: fsl_esdhc: Implement card-detect hook.

Message ID 1325502939-6556-4-git-send-email-thierry.reding@avionic-design.de
State Accepted, archived
Delegated to: Andy Fleming
Headers show

Commit Message

Thierry Reding Jan. 2, 2012, 11:15 a.m. UTC
This card-detect hook probably doesn't work. Perhaps somebody with more
knowledge about the hardware can comment on this. I think that perhaps
even the complete code from esdhc_init() could go into the getcd()
function instead or mmc_getcd() needs to be called at some later time
after mmc_init(), which, however, would require many other drivers to
change.

In addition to implementing the hook, this patch also removes the call
to the board_mmc_getcd() function which is now called from the MMC
framework and is no longer required here.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
---
 drivers/mmc/fsl_esdhc.c |   29 ++++++++++++-----------------
 1 files changed, 12 insertions(+), 17 deletions(-)

Comments

Jason Liu Jan. 4, 2012, 5:19 a.m. UTC | #1
2012/1/2 Thierry Reding <thierry.reding@avionic-design.de>:
> This card-detect hook probably doesn't work. Perhaps somebody with more
> knowledge about the hardware can comment on this. I think that perhaps
> even the complete code from esdhc_init() could go into the getcd()
> function instead or mmc_getcd() needs to be called at some later time
> after mmc_init(), which, however, would require many other drivers to
> change.

yes, the hook in the patch does not work for the fsl i.mx sdhc controller due to
silicon issues and we need always use gpio to read the card detection status.

>
> In addition to implementing the hook, this patch also removes the call
> to the board_mmc_getcd() function which is now called from the MMC
> framework and is no longer required here.
>
> Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
> ---

Tested ok on i.mx51evk board,

Tested-by: Jason Liu <jason.hui@linaro.org>

>  drivers/mmc/fsl_esdhc.c |   29 ++++++++++++-----------------
>  1 files changed, 12 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
> index f038acc..1ed5355 100644
> --- a/drivers/mmc/fsl_esdhc.c
> +++ b/drivers/mmc/fsl_esdhc.c
> @@ -418,7 +418,6 @@ static int esdhc_init(struct mmc *mmc)
>        struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
>        struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
>        int timeout = 1000;
> -       int ret = 0;
>
>        /* Reset the entire host controller */
>        esdhc_write32(&regs->sysctl, SYSCTL_RSTA);
> @@ -445,24 +444,19 @@ static int esdhc_init(struct mmc *mmc)
>        /* Set timout to the maximum value */
>        esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
>
> -       /* Check if there is a callback for detecting the card */
> -       ret = board_mmc_getcd(mmc);
> -       if (ret < 0) {
> -               timeout = 1000;
> -               while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_CINS) &&
> -                               --timeout)
> -                       udelay(1000);
> +       return 0;
> +}
>
> -               if (timeout <= 0)
> -                       ret = NO_CARD_ERR;
> -       } else {
> -               if (ret == 0)
> -                       ret = NO_CARD_ERR;
> -               else
> -                       ret = 0;
> -       }
> +static int esdhc_getcd(struct mmc *mmc)
> +{
> +       struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
> +       struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
> +       int timeout = 1000;
> +
> +       while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
> +               udelay(1000);
>
> -       return ret;
> +       return timeout > 0;
>  }
>
>  static void esdhc_reset(struct fsl_esdhc *regs)
> @@ -500,6 +494,7 @@ int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
>        mmc->send_cmd = esdhc_send_cmd;
>        mmc->set_ios = esdhc_set_ios;
>        mmc->init = esdhc_init;
> +       mmc->getcd = esdhc_getcd;
>
>        voltage_caps = 0;
>        caps = regs->hostcapblt;
> --
> 1.7.8.1
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
diff mbox

Patch

diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
index f038acc..1ed5355 100644
--- a/drivers/mmc/fsl_esdhc.c
+++ b/drivers/mmc/fsl_esdhc.c
@@ -418,7 +418,6 @@  static int esdhc_init(struct mmc *mmc)
 	struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
 	struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
 	int timeout = 1000;
-	int ret = 0;
 
 	/* Reset the entire host controller */
 	esdhc_write32(&regs->sysctl, SYSCTL_RSTA);
@@ -445,24 +444,19 @@  static int esdhc_init(struct mmc *mmc)
 	/* Set timout to the maximum value */
 	esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
 
-	/* Check if there is a callback for detecting the card */
-	ret = board_mmc_getcd(mmc);
-	if (ret < 0) {
-		timeout = 1000;
-		while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_CINS) &&
-				--timeout)
-			udelay(1000);
+	return 0;
+}
 
-		if (timeout <= 0)
-			ret = NO_CARD_ERR;
-	} else {
-		if (ret == 0)
-			ret = NO_CARD_ERR;
-		else
-			ret = 0;
-	}
+static int esdhc_getcd(struct mmc *mmc)
+{
+	struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
+	struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
+	int timeout = 1000;
+
+	while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
+		udelay(1000);
 
-	return ret;
+	return timeout > 0;
 }
 
 static void esdhc_reset(struct fsl_esdhc *regs)
@@ -500,6 +494,7 @@  int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
 	mmc->send_cmd = esdhc_send_cmd;
 	mmc->set_ios = esdhc_set_ios;
 	mmc->init = esdhc_init;
+	mmc->getcd = esdhc_getcd;
 
 	voltage_caps = 0;
 	caps = regs->hostcapblt;