All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amit Virdi <amit.virdi@st.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 05/11] st_smi: Enhance the error handling
Date: Fri, 24 Feb 2012 17:53:08 +0530	[thread overview]
Message-ID: <1330086194-21762-6-git-send-email-amit.virdi@st.com> (raw)
In-Reply-To: <1330086194-21762-1-git-send-email-amit.virdi@st.com>

This commit does the following:
 - Reports error if SNOR flash is not found on the board
 - Changes smi_read_sr to return error using which a retry mechanism is
   implemented for reading flash status

Signed-off-by: Vipin Kumar <vipin.kumar@st.com>
Signed-off-by: Amit Virdi <amit.virdi@st.com>
---
 drivers/mtd/st_smi.c |   34 +++++++++++++++++++++-------------
 1 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/drivers/mtd/st_smi.c b/drivers/mtd/st_smi.c
index ec19b0d..ce50fc1 100644
--- a/drivers/mtd/st_smi.c
+++ b/drivers/mtd/st_smi.c
@@ -108,11 +108,17 @@ static ulong flash_get_size(ulong base, int banknum)
 {
 	flash_info_t *info = &flash_info[banknum];
 	struct flash_dev *dev;
-	unsigned int value;
+	int value;
 	unsigned int density;
 	int i;
 
 	value = smi_read_id(info, banknum);
+
+	if (value < 0) {
+		printf("Flash id could not be read\n");
+		return 0;
+	}
+
 	density = (value >> 16) & 0xff;
 
 	for (i = 0, dev = &flash_ids[0]; dev->density != 0x0;
@@ -140,7 +146,7 @@ static ulong flash_get_size(ulong base, int banknum)
  * This routine will get the status register of the flash chip present at the
  * given bank
  */
-static unsigned int smi_read_sr(int bank)
+static int smi_read_sr(int bank)
 {
 	u32 ctrlreg1;
 
@@ -174,13 +180,11 @@ static unsigned int smi_read_sr(int bank)
  */
 static int smi_wait_till_ready(int bank, int timeout)
 {
-	int count;
-	unsigned int sr;
+	int sr;
 
 	/* One chip guarantees max 5 msec wait here after page writes,
 	   but potentially three seconds (!) after page erase. */
-	for (count = 0; count < timeout; count++) {
-
+	do {
 		sr = smi_read_sr(bank);
 		if (sr < 0)
 			break;
@@ -189,7 +193,8 @@ static int smi_wait_till_ready(int bank, int timeout)
 
 		/* Try again after 1m-sec */
 		udelay(1000);
-	}
+	} while (timeout--);
+
 	printf("SMI controller is still in wait, timeout=%d\n", timeout);
 	return -EIO;
 }
@@ -205,6 +210,7 @@ static int smi_write_enable(int bank)
 {
 	u32 ctrlreg1;
 	int timeout = WMODE_TOUT;
+	int sr;
 
 	/* Store the CTRL REG1 state */
 	ctrlreg1 = readl(&smicntl->smi_cr1);
@@ -221,14 +227,16 @@ static int smi_write_enable(int bank)
 	/* Restore the CTRL REG1 state */
 	writel(ctrlreg1, &smicntl->smi_cr1);
 
-	while (timeout--) {
-		if (smi_read_sr(bank) & (1 << (bank + WM_SHIFT)))
+	do {
+		sr = smi_read_sr(bank);
+		if (sr < 0)
 			break;
-		udelay(1000);
-	}
+		else if (sr & (1 << (bank + WM_SHIFT)))
+			return 0;
 
-	if (timeout)
-		return 0;
+		/* Try again after 1m-sec */
+		udelay(1000);
+	} while (timeout--);
 
 	return -1;
 }
-- 
1.7.2.2

  parent reply	other threads:[~2012-02-24 12:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-24 12:23 [U-Boot] [PATCH 00/11] mtd/SMI: Add support for ST SMI controller Amit Virdi
2012-02-24 12:23 ` [U-Boot] [PATCH 01/11] st_smi: Add support for SPEAr SMI driver Amit Virdi
2012-04-20  7:47   ` Stefan Roese
2012-02-24 12:23 ` [U-Boot] [PATCH 02/11] st_smi: Remove compilation warning Amit Virdi
2012-02-24 12:23 ` [U-Boot] [PATCH 03/11] st_smi: Return error in case TFF is not set Amit Virdi
2012-02-27 10:26   ` Stefan Roese
2012-02-29  9:10     ` Amit Virdi
2012-03-02 13:32       ` Stefan Roese
2012-02-24 12:23 ` [U-Boot] [PATCH 04/11] st_smi: Change SMI timeout values Amit Virdi
2012-02-24 12:23 ` Amit Virdi [this message]
2012-02-24 12:23 ` [U-Boot] [PATCH 06/11] st_smi: Read status until timeout happens Amit Virdi
2012-02-24 12:23 ` [U-Boot] [PATCH 07/11] st_smi: Move status register read before modifying ctrl register Amit Virdi
2012-02-24 12:23 ` [U-Boot] [PATCH 08/11] st_smi: Fix smi read status Amit Virdi
2012-02-24 12:23 ` [U-Boot] [PATCH 09/11] st_smi: Removed no needed dependency on ST_M25Pxx_ID Amit Virdi
2012-02-24 12:23 ` [U-Boot] [PATCH 10/11] st_smi: Change the flash probing method Amit Virdi
2012-02-24 12:23 ` [U-Boot] [PATCH 11/11] st_smi: Fix bug in flash_print_info() Amit Virdi
2012-03-07 10:02 ` [U-Boot] [PATCH 00/11] mtd/SMI: Add support for ST SMI controller Amit Virdi
2012-03-07 11:27   ` Stefan Roese
2012-03-07 11:46     ` Amit Virdi
2012-03-07 11:49       ` Stefan Roese
2012-03-30  6:12 ` [U-Boot] [PATCH] st_smi: Fixed page size for Winbond W25Q128FV flash Amit Virdi

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=1330086194-21762-6-git-send-email-amit.virdi@st.com \
    --to=amit.virdi@st.com \
    --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.