[PATCH 2/5] mci i.MX esdhc: use timeout loops
Sascha Hauer
s.hauer at pengutronix.de
Thu Feb 9 08:39:55 EST 2012
Too often I have waited to get a reaction from this driver
when something goes wrong. Use timeout loops instead of
inifinite polling loops.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
drivers/mci/imx-esdhc.c | 27 ++++++++++++++++++++-------
1 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index 2123a8b..d36d211 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -238,6 +238,7 @@ esdhc_send_cmd(struct mci_host *mci, struct mci_cmd *cmd, struct mci_data *data)
u32 irqstat;
struct fsl_esdhc_host *host = to_fsl_esdhc(mci);
struct fsl_esdhc *regs = host->regs;
+ int ret;
esdhc_write32(®s->irqstat, -1);
@@ -268,8 +269,12 @@ esdhc_send_cmd(struct mci_host *mci, struct mci_cmd *cmd, struct mci_data *data)
esdhc_write32(®s->xfertyp, xfertyp);
/* Wait for the command to complete */
- while (!(esdhc_read32(®s->irqstat) & IRQSTAT_CC))
- ;
+ ret = wait_on_timeout(100 * MSECOND,
+ esdhc_read32(®s->irqstat) & IRQSTAT_CC);
+ if (ret) {
+ dev_err(host->dev, "timeout 1\n");
+ return -ETIMEDOUT;
+ }
irqstat = esdhc_read32(®s->irqstat);
esdhc_write32(®s->irqstat, irqstat);
@@ -321,12 +326,20 @@ esdhc_send_cmd(struct mci_host *mci, struct mci_cmd *cmd, struct mci_data *data)
esdhc_write32(®s->irqstat, -1);
/* Wait for the bus to be idle */
- while ((esdhc_read32(®s->prsstat) & PRSSTAT_CICHB) ||
- (esdhc_read32(®s->prsstat) & PRSSTAT_CIDHB))
- ;
+ ret = wait_on_timeout(100 * MSECOND,
+ !(esdhc_read32(®s->prsstat) &
+ (PRSSTAT_CICHB | PRSSTAT_CIDHB)));
+ if (ret) {
+ dev_err(host->dev, "timeout 2\n");
+ return -ETIMEDOUT;
+ }
- while (esdhc_read32(®s->prsstat) & PRSSTAT_DLA)
- ;
+ ret = wait_on_timeout(100 * MSECOND,
+ !(esdhc_read32(®s->prsstat) & PRSSTAT_DLA));
+ if (ret) {
+ dev_err(host->dev, "timeout 3\n");
+ return -ETIMEDOUT;
+ }
return 0;
}
--
1.7.9
More information about the barebox
mailing list