All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 04/37] Blackfin: bfin_sdh: clean up send_cmd
Date: Sat,  2 Oct 2010 16:05:30 -0400	[thread overview]
Message-ID: <1286049958-4125-3-git-send-email-vapier@gentoo.org> (raw)
In-Reply-To: <1286049958-4125-1-git-send-email-vapier@gentoo.org>

Simplify the command setup and status checking steps, and add a proper
timeout to the status polling code to avoid possible infinite hangs.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/mmc/bfin_sdh.c |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/mmc/bfin_sdh.c b/drivers/mmc/bfin_sdh.c
index 4a77779..27d9bf6 100644
--- a/drivers/mmc/bfin_sdh.c
+++ b/drivers/mmc/bfin_sdh.c
@@ -58,27 +58,29 @@
 static int
 sdh_send_cmd(struct mmc *mmc, struct mmc_cmd *mmc_cmd)
 {
-	unsigned int sdh_cmd;
-	unsigned int status;
+	unsigned int status, timeout;
 	int cmd = mmc_cmd->cmdidx;
 	int flags = mmc_cmd->resp_type;
 	int arg = mmc_cmd->cmdarg;
-	int ret = 0;
-	sdh_cmd = 0;
-
-	sdh_cmd |= cmd;
+	int ret;
+	u16 sdh_cmd;
 
+	sdh_cmd = cmd | CMD_E;
 	if (flags & MMC_RSP_PRESENT)
 		sdh_cmd |= CMD_RSP;
-
 	if (flags & MMC_RSP_136)
 		sdh_cmd |= CMD_L_RSP;
 
 	bfin_write_SDH_ARGUMENT(arg);
-	bfin_write_SDH_COMMAND(sdh_cmd | CMD_E);
+	bfin_write_SDH_COMMAND(sdh_cmd);
 
 	/* wait for a while */
+	timeout = 0;
 	do {
+		if (++timeout > 1000000) {
+			status = CMD_TIME_OUT;
+			break;
+		}
 		udelay(1);
 		status = bfin_read_SDH_STATUS();
 	} while (!(status & (CMD_SENT | CMD_RESP_END | CMD_TIME_OUT |
@@ -94,12 +96,15 @@ sdh_send_cmd(struct mmc *mmc, struct mmc_cmd *mmc_cmd)
 	}
 
 	if (status & CMD_TIME_OUT)
-		ret |= TIMEOUT;
+		ret = TIMEOUT;
 	else if (status & CMD_CRC_FAIL && flags & MMC_RSP_CRC)
-		ret |= COMM_ERR;
+		ret = COMM_ERR;
+	else
+		ret = 0;
 
 	bfin_write_SDH_STATUS_CLR(CMD_SENT_STAT | CMD_RESP_END_STAT |
 				CMD_TIMEOUT_STAT | CMD_CRC_FAIL_STAT);
+
 	return ret;
 }
 
-- 
1.7.3.1

  parent reply	other threads:[~2010-10-02 20:05 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-02 20:05 [U-Boot] [PATCH 00/37] Blackfin updates for v2010.12-rc1 Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 03/37] Blackfin: bfin_spi: add optional DMA support Mike Frysinger
2010-10-02 20:05 ` Mike Frysinger [this message]
2010-10-02 20:05 ` [U-Boot] [PATCH 05/37] Blackfin: unify gpio cfi implementations Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 06/37] Blackfin: punt headers for non-existent BF541 Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 07/37] Blackfin: bfin_mac: convert from old style MMR macros Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 08/37] Blackfin: bf537-stamp: post: update old MMR style macros Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 09/37] Blackfin: bf527-ezkit: video: convert from old style MMR macros Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 10/37] Blackfin: bf548-ezkit: " Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 11/37] Blackfin: cm-bf548: " Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 12/37] Blackfin: bf527-ad7160-eval: " Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 14/37] Blackfin: bf537: unify arch header duplication Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 19/37] Blackfin: move CONFIG_BFIN_CPU to board config.mk Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 20/37] Blackfin: cmd_gpio: document/extend input sub-option Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 21/37] Blackfin: support a 3rd gpio cfi pin Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 22/37] Blackfin: adi config: add an "all spi flashes" option to unify board lists Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 23/37] Blackfin: adi config: add a hook for boards to append the env Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 24/37] Blackfin: bf527-sdp: new board port Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 25/37] Blackfin: cmd_gpio: return gpio value to caller Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 26/37] Blackfin: adi config: allow boards to tweak a little more Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 27/37] Blackfin: bct-brettl2: new board port Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 28/37] Blackfin: adi config: enable nand lock/unlock support Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 29/37] Blackfin: bf526-ezbrd: enable BootROM-OOB layout when booting from NAND Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 30/37] Blackfin: cmd_gpio: accept upper case pin names Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 31/37] Blackfin: propagate target cpu defines when building embedded env Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 32/37] Blackfin: blackvme: new board port Mike Frysinger
2010-10-03  1:52   ` Wojtek Skulski
2010-10-02 20:05 ` [U-Boot] [PATCH 33/37] Blackfin: fix MMC init output alignment Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 34/37] Blackfin: bf548-ezkit: bump SPI flash size up Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 35/37] Blackfin: bf527-ad7160-eval: fix GPIO CS define Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 36/37] Blackfin: bf537-pnav: increase monitor len Mike Frysinger
2010-10-02 20:05 ` [U-Boot] [PATCH 37/37] Blackfin: otp: fix build after constification of args[] Mike Frysinger
2010-10-04 17:33 ` [U-Boot] Pull request u-boot-blackfin.git Mike Frysinger
2010-10-05 12:43   ` Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1286049958-4125-3-git-send-email-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.