Skip to contentSkip to conversation

mtd/SMI: Add support for ST SMI controller

PATCH New Amit Virdi 2 participants 21 messages Feb 24, 2012 – Apr 20, 2012

Subsystems (2)
lore
Share & tools
lore

Amit Virdi

author
#0 lore raw

cover mtd/SMI: Add support for ST SMI controller

In the current u-boot, a driver exists for ST's SMI controller. However, the driver is SPEAr specific. This patchset makes the driver more generic so that it can be used across multiple platforms.

In the first commit, the driver is renamed to st_smi. In subsequent patches, changes are introduced so as to make the driver generic.

Amit Virdi (4):
st_smi: Remove compilation warning
st_smi: Return error in case TFF is not set
st_smi: Change SMI timeout values
st_smi: Enhance the error handling

Armando Visconti (3):
st_smi: Removed no needed dependency on ST_M25Pxx_ID
st_smi: Change the flash probing method
st_smi: Fix bug in flash_print_info()

Shiraz Hashim (1):
st_smi: Move status register read before modifying ctrl register

Vipin KUMAR (2):
st_smi: Add support for SPEAr SMI driver
st_smi: Read status until timeout happens

Vipin Kumar (1):
st_smi: Fix smi read status

 drivers/mtd/Makefile                               |    2 +-
 drivers/mtd/{spr_smi.c => st_smi.c}                |  223 ++++++++++++--------
 include/configs/spear-common.h                     |    6 +-
 .../spr_smi.h => include/linux/mtd/st_smi.h        |   10 +-
 4 files changed, 140 insertions(+), 101 deletions(-)
 rename drivers/mtd/{spr_smi.c => st_smi.c} (66%)
 rename arch/arm/include/asm/arch-spear/spr_smi.h => include/linux/mtd/st_smi.h (95%)
Signature · 1 line
1.7.2.2
author
#1 lore raw

PATCH 1/11 st_smi: Add support for SPEAr SMI driver

From: Vipin KUMAR <[email protected]>

SMI is the serial memory interface controller provided by ST.

Earlier, a driver exists in the u-boot source code for the SMI IP. However, it was specific to spear platforms. This commit converts the same driver to a more generic driver. As a result, the driver files are renamed to st_smi.c and st_smi.h and moved into drivers/mtd folder for reusability by other platforms using smi controller peripheral.

---
 drivers/mtd/Makefile                               |    2 +-
 drivers/mtd/{spr_smi.c => st_smi.c}                |    5 +++--
 include/configs/spear-common.h                     |    6 +++---
 .../spr_smi.h => include/linux/mtd/st_smi.h        |    6 ++++--
 4 files changed, 11 insertions(+), 8 deletions(-)
 rename drivers/mtd/{spr_smi.c => st_smi.c} (99%)
 rename arch/arm/include/asm/arch-spear/spr_smi.h => include/linux/mtd/st_smi.h (98%)
drivers/mtd/Makefile +1 -1
index 5a5ecdf..543c845 100644
@@ -35,7 +35,7 @@ COBJS-$(CONFIG_HAS_DATAFLASH) += dataflash.o
 COBJS-$(CONFIG_FTSMC020) += ftsmc020.o
 COBJS-$(CONFIG_FLASH_CFI_LEGACY) += jedec_flash.o
 COBJS-$(CONFIG_MW_EEPROM) += mw_eeprom.o
-COBJS-$(CONFIG_SPEARSMI) += spr_smi.o
+COBJS-$(CONFIG_ST_SMI) += st_smi.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
drivers/mtd/st_smi.c renamed from drivers/mtd/spr_smi.c +3 -2
similarity index 99%
rename from drivers/mtd/spr_smi.c
rename to drivers/mtd/st_smi.c
index 9a70a19..b514046 100644
@@ -24,10 +24,10 @@
 #include <common.h>
 #include <flash.h>
 #include <linux/err.h>
+#include <linux/mtd/st_smi.h>
 
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
-#include <asm/arch/spr_smi.h>
 
 #if !defined(CONFIG_SYS_NO_FLASH)
 
@@ -82,6 +82,7 @@ static unsigned int smi_read_id(flash_info_t *info, int banknum)
 	writel(READ_ID, &smicntl->smi_tr);
 	writel((banknum << BANKSEL_SHIFT) | SEND | TX_LEN_1 | RX_LEN_3,
 	       &smicntl->smi_cr2);
+
 	smi_wait_xfer_finish(XFER_FINISH_TOUT);
 
 	value = (readl(&smicntl->smi_rr) & 0x00FFFFFF);
@@ -232,7 +233,7 @@ static int smi_write_enable(int bank)
  *
  * SMI initialization routine. Sets SMI control register1.
  */
-static void smi_init(void)
+void smi_init(void)
 {
 	/* Setting the fast mode values. SMI working at 166/4 = 41.5 MHz */
 	writel(HOLD1 | FAST_MODE | BANK_EN | DSEL_TIME | PRESCAL4,
include/configs/spear-common.h +3 -3
index 3947fd5..5a582e8 100644
@@ -55,10 +55,10 @@
 #if defined(CONFIG_FLASH_PNOR)
 #define CONFIG_SPEAR_EMI
 #else
-#define CONFIG_SPEARSMI
+#define CONFIG_ST_SMI
 #endif
 
-#if defined(CONFIG_SPEARSMI)
+#if defined(CONFIG_ST_SMI)
 
 #define CONFIG_SYS_MAX_FLASH_BANKS		2
 #define CONFIG_SYS_FLASH_BASE			0xF8000000
@@ -124,7 +124,7 @@
  * U-Boot Environment placing definitions.
  */
 #if defined(CONFIG_ENV_IS_IN_FLASH)
-#ifdef CONFIG_SPEARSMI
+#ifdef CONFIG_ST_SMI
 /*
  * Environment is in serial NOR flash
  */
include/linux/mtd/st_smi.h renamed from arch/arm/include/asm/arch-spear/spr_smi.h +4 -2
similarity index 98%
rename from arch/arm/include/asm/arch-spear/spr_smi.h
rename to include/linux/mtd/st_smi.h
index 06df745..b7a78ac 100644
@@ -21,8 +21,8 @@
  * MA 02111-1307 USA
  */
 
-#ifndef SPR_SMI_H
-#define SPR_SMI_H
+#ifndef ST_SMI_H
+#define ST_SMI_H
 
 /* 0xF800.0000 . 0xFBFF.FFFF	64MB	SMI (Serial Flash Mem) */
 /* 0xFC00.0000 . 0xFC1F.FFFF	2MB	SMI (Serial Flash Reg.) */
@@ -112,4 +112,6 @@ struct flash_dev {
 #define XFER_FINISH_TOUT	2	/* xfer finish timeout */
 #define WMODE_TOUT		2	/* write enable timeout */
 
+extern void smi_init(void);
+
 #endif
Signature · 1 line
1.7.2.2
#2 lore raw

PATCH 1/11 st_smi: Add support for SPEAr SMI driver

Hi Amit,

Quoted 9 lines · On Friday 24 February 2012 13:23:04 Amit Virdi wrote:

From: Vipin KUMAR <[email protected]>

SMI is the serial memory interface controller provided by ST.

Earlier, a driver exists in the u-boot source code for the SMI IP. However, it was specific to spear platforms. This commit converts the same driver to a more generic driver. As a result, the driver files are renamed to st_smi.c and st_smi.h and moved into drivers/mtd folder for reusability by other platforms using smi controller peripheral.

Since u-boot/next is now available, I wanted to apply some SPEAr patches. Mainly the "st_smi" patch series:

[PATCH 01/11] st_smi: Add support for SPEAr SMI driver
...

and the SPEAr platform rework:

[PATCH V2 00/24] SPEAr: Update platform support for SPEAr3xx/6xx
...

Unfortunately the first patch series doesn't apply any more to "next":

[stefan at kubuntu u-boot-staging (sr at denx.de)]$ git am -s bundle-2819.mbox
Applying: st_smi: Add support for SPEAr SMI driver
error: patch failed: include/configs/spear-common.h:55
error: include/configs/spear-common.h: patch does not apply
Patch failed at 0001 st_smi: Add support for SPEAr SMI driver

Could you please rebase your patch series on "next"? And make sure that all SPEAr based boards still compile clean?

Thanks,
Stefan

author
#3 lore raw

PATCH 2/11 st_smi: Remove compilation warning

In reply to Amit Virdi
---
 drivers/mtd/st_smi.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
drivers/mtd/st_smi.c +0 -5
index b514046..82f1fe1 100644
@@ -323,24 +323,19 @@ static int smi_write(unsigned int *src_addr, unsigned int *dst_addr,
 		     unsigned int length, ulong bank_addr)
 {
 	int banknum;
-	unsigned int WM;
 
 	switch (bank_addr) {
 	case SMIBANK0_BASE:
 		banknum = BANK0;
-		WM = WM0;
 		break;
 	case SMIBANK1_BASE:
 		banknum = BANK1;
-		WM = WM1;
 		break;
 	case SMIBANK2_BASE:
 		banknum = BANK2;
-		WM = WM2;
 		break;
 	case SMIBANK3_BASE:
 		banknum = BANK3;
-		WM = WM3;
 		break;
 	default:
 		return -1;
Signature · 1 line
1.7.2.2
author
#4 lore raw

PATCH 3/11 st_smi: Return error in case TFF is not set

In reply to Amit Virdi

Curently the code makes wrong assumption that the Transfer finished flag shall be set within the stipulated time. However, there may occur a scenario in which the TFF flag is not set. Return error in that case.

---
 drivers/mtd/st_smi.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
drivers/mtd/st_smi.c +14 -8
index 82f1fe1..ec19b0d 100644
@@ -58,13 +58,15 @@ static struct flash_dev flash_ids[] = {
  *
  * Wait until TFF is set in status register
  */
-static void smi_wait_xfer_finish(int timeout)
+static int smi_wait_xfer_finish(int timeout)
 {
-	while (timeout--) {
+	do {
 		if (readl(&smicntl->smi_sr) & TFF)
-			break;
+			return 0;
 		udelay(1000);
-	}
+	} while (timeout--);
+
+	return -1;
 }
 
 /*
@@ -83,7 +85,8 @@ static unsigned int smi_read_id(flash_info_t *info, int banknum)
 	writel((banknum << BANKSEL_SHIFT) | SEND | TX_LEN_1 | RX_LEN_3,
 	       &smicntl->smi_cr2);
 
-	smi_wait_xfer_finish(XFER_FINISH_TOUT);
+	if (smi_wait_xfer_finish(XFER_FINISH_TOUT))
+		return -EIO;
 
 	value = (readl(&smicntl->smi_rr) & 0x00FFFFFF);
 
@@ -151,7 +154,8 @@ static unsigned int smi_read_sr(int bank)
 	/* Performing a RSR instruction in HW mode */
 	writel((bank << BANKSEL_SHIFT) | RD_STATUS_REG, &smicntl->smi_cr2);
 
-	smi_wait_xfer_finish(XFER_FINISH_TOUT);
+	if (smi_wait_xfer_finish(XFER_FINISH_TOUT))
+		return -1;
 
 	/* Restore the CTRL REG1 state */
 	writel(ctrlreg1, &smicntl->smi_cr1);
@@ -211,7 +215,8 @@ static int smi_write_enable(int bank)
 	/* Give the Flash, Write Enable command */
 	writel((bank << BANKSEL_SHIFT) | WE, &smicntl->smi_cr2);
 
-	smi_wait_xfer_finish(XFER_FINISH_TOUT);
+	if (smi_wait_xfer_finish(XFER_FINISH_TOUT))
+		return -1;
 
 	/* Restore the CTRL REG1 state */
 	writel(ctrlreg1, &smicntl->smi_cr1);
@@ -292,7 +297,8 @@ static int smi_sector_erase(flash_info_t *info, unsigned int sector)
 		writel(instruction, &smicntl->smi_tr);
 		writel((bank << BANKSEL_SHIFT) | SEND | TX_LEN_4,
 		       &smicntl->smi_cr2);
-		smi_wait_xfer_finish(XFER_FINISH_TOUT);
+		if (smi_wait_xfer_finish(XFER_FINISH_TOUT))
+			return -EIO;
 
 		if (smi_wait_till_ready(bank, CONFIG_SYS_FLASH_ERASE_TOUT))
 			return -EBUSY;
Signature · 1 line
1.7.2.2
#5 lore raw

PATCH 3/11 st_smi: Return error in case TFF is not set

Quoted 21 lines · On Friday 24 February 2012 13:23:06 Amit Virdi wrote:

Curently the code makes wrong assumption that the Transfer finished flag shall be set within the stipulated time. However, there may occur a scenario in which the TFF flag is not set. Return error in that case.

---
 drivers/mtd/st_smi.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
drivers/mtd/st_smi.c +1 -1
index 82f1fe1..ec19b0d 100644
@@ -58,13 +58,15 @@ static struct flash_dev flash_ids[] = {
  *
  * Wait until TFF is set in status register
  */
-static void smi_wait_xfer_finish(int timeout)
+static int smi_wait_xfer_finish(int timeout)
 {

drivers/mtd/st_smi.c static struct flash_dev flash_ids[] = { · line 69

Quoted 10 lines
drivers/mtd/st_smi.c +5 -3
-	while (timeout--) {
+	do {
 		if (readl(&smicntl->smi_sr) & TFF)
-			break;
+			return 0;
 		udelay(1000);
-	}
+	} while (timeout--);
+
+	return -1;

Somewhat unrelated to the patch topic, but I don't really like this kind of timeout loops. Since it always adds at least 1ms delay after initial failing test. Better use something like this:

static int smi_wait_xfer_finish(int timeout)

{
	ulong start = get_timer(0);

	while (get_timer(start) < timeout) {
		if (readl(&smicntl->smi_sr) & TFF)
			return 0;

		/* Try again after 100usec */
		udelay(100);
	}

	return -1;
}

You could tune this udelay(100) down more or even remove it completely.

But such a change could be done in a addon cleanup patch, changing all timeout loops this way. I suggest you take a look at my version, here these loops are changes. In the designware networking driver as well, iirc.

Thanks,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de

author
#6 lore raw

PATCH 3/11 st_smi: Return error in case TFF is not set

Hello Stefan,

Quoted 52 lines · Stefan Roese
Quoted 21 lines · On Friday 24 February 2012 13:23:06 Amit Virdi wrote:

Curently the code makes wrong assumption that the Transfer finished flag shall be set within the stipulated time. However, there may occur a scenario in which the TFF flag is not set. Return error in that case.

---
  drivers/mtd/st_smi.c |   22 ++++++++++++++--------
  1 files changed, 14 insertions(+), 8 deletions(-)
drivers/mtd/st_smi.c +1 -1
index 82f1fe1..ec19b0d 100644
@@ -58,13 +58,15 @@ static struct flash_dev flash_ids[] = {
   *
   * Wait until TFF is set in status register
   */
-static void smi_wait_xfer_finish(int timeout)
+static int smi_wait_xfer_finish(int timeout)
  {

drivers/mtd/st_smi.c static struct flash_dev flash_ids[] = { · line 69

Quoted 10 lines
drivers/mtd/st_smi.c +5 -3
-	while (timeout--) {
+	do {
  		if (readl(&smicntl->smi_sr)&  TFF)
-			break;
+			return 0;
  		udelay(1000);
-	}
+	} while (timeout--);
+
+	return -1;

Somewhat unrelated to the patch topic, but I don't really like this kind of timeout loops. Since it always adds at least 1ms delay after initial failing test. Better use something like this:

static int smi_wait_xfer_finish(int timeout)

{
	ulong start = get_timer(0);

	while (get_timer(start)<  timeout) {
		if (readl(&smicntl->smi_sr)&  TFF)
			return 0;

		/* Try again after 100usec */
		udelay(100);
	}

	return -1;
}
Quoted 6 lines

You could tune this udelay(100) down more or even remove it completely.

But such a change could be done in a addon cleanup patch, changing all timeout loops this way. I suggest you take a look at my version, here these loops are changes. In the designware networking driver as well, iirc.

Thanks for pointing out. In a separate cleanup patch, I shall be changing all the timeout loops for smi driver. I'll check other ST drivers too and change the timer implementation there too.

Regards
Amit Virdi

#7 lore raw

PATCH 3/11 st_smi: Return error in case TFF is not set

Hi Amit,

Quoted 10 lines · On Wednesday 29 February 2012 10:10:20 Amit Virdi wrote:
Quoted 6 lines

You could tune this udelay(100) down more or even remove it completely.

But such a change could be done in a addon cleanup patch, changing all timeout loops this way. I suggest you take a look at my version, here these loops are changes. In the designware networking driver as well, iirc.

Thanks for pointing out. In a separate cleanup patch, I shall be changing all the timeout loops for smi driver. I'll check other ST drivers too and change the timer implementation there too.

Good.

Thanks,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de

author
#8 lore raw

PATCH 4/11 st_smi: Change SMI timeout values

In reply to Amit Virdi
---
 include/linux/mtd/st_smi.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
include/linux/mtd/st_smi.h +2 -2
index b7a78ac..04f81ea 100644
@@ -109,8 +109,8 @@ struct flash_dev {
 };
 
 #define SFLASH_PAGE_SIZE	0x100	/* flash page size */
-#define XFER_FINISH_TOUT	2	/* xfer finish timeout */
-#define WMODE_TOUT		2	/* write enable timeout */
+#define XFER_FINISH_TOUT	15	/* xfer finish timeout(in ms) */
+#define WMODE_TOUT		15	/* write enable timeout(in ms) */
 
 extern void smi_init(void);
 
Signature · 1 line
1.7.2.2
author
#9 lore raw

PATCH 5/11 st_smi: Enhance the error handling

In reply to Amit Virdi

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

---
 drivers/mtd/st_smi.c |   34 +++++++++++++++++++++-------------
 1 files changed, 21 insertions(+), 13 deletions(-)
drivers/mtd/st_smi.c +21 -13
index ec19b0d..ce50fc1 100644
@@ -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;
 }
Signature · 1 line
1.7.2.2
author
#10 lore raw

PATCH 6/11 st_smi: Read status until timeout happens

In reply to Amit Virdi

From: Vipin KUMAR <[email protected]>

SMI driver read status fails because the control register could not be overwritten. Instead, the read status should be tried until timeout.

---
 drivers/mtd/st_smi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/mtd/st_smi.c +1 -1
index ce50fc1..7b4c6f3 100644
@@ -187,7 +187,7 @@ static int smi_wait_till_ready(int bank, int timeout)
 	do {
 		sr = smi_read_sr(bank);
 		if (sr < 0)
-			break;
+			continue;	/* try until timeout */
 		else if (!(sr & WIP_BIT))
 			return 0;
 
Signature · 1 line
1.7.2.2
author
#11 lore raw

PATCH 7/11 st_smi: Move status register read before modifying ctrl register

In reply to Amit Virdi

From: Shiraz Hashim <[email protected]>

---
 drivers/mtd/st_smi.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/mtd/st_smi.c +4 -2
index 7b4c6f3..eb902b2 100644
@@ -148,7 +148,7 @@ static ulong flash_get_size(ulong base, int banknum)
  */
 static int smi_read_sr(int bank)
 {
-	u32 ctrlreg1;
+	u32 ctrlreg1, val;
 
 	/* store the CTRL REG1 state */
 	ctrlreg1 = readl(&smicntl->smi_cr1);
@@ -163,10 +163,12 @@ static int smi_read_sr(int bank)
 	if (smi_wait_xfer_finish(XFER_FINISH_TOUT))
 		return -1;
 
+	val = readl(&smicntl->smi_sr);
+
 	/* Restore the CTRL REG1 state */
 	writel(ctrlreg1, &smicntl->smi_cr1);
 
-	return readl(&smicntl->smi_sr);
+	return val;
 }
 
 /*
Signature · 1 line
1.7.2.2
author
#12 lore raw

PATCH 8/11 st_smi: Fix smi read status

In reply to Amit Virdi

From: Vipin Kumar <[email protected]>

smi_read_sr fails sometimes because of TFF not getting set within assumed time. This condition may arise because of, for example, smi memory being in a erase mode.

This fix is to enable reading the status register until timeout.

---
 drivers/mtd/st_smi.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
drivers/mtd/st_smi.c +2 -6
index eb902b2..e5c803b 100644
@@ -188,9 +188,7 @@ static int smi_wait_till_ready(int bank, int timeout)
 	   but potentially three seconds (!) after page erase. */
 	do {
 		sr = smi_read_sr(bank);
-		if (sr < 0)
-			continue;	/* try until timeout */
-		else if (!(sr & WIP_BIT))
+		if ((sr >= 0) && (!(sr & WIP_BIT)))
 			return 0;
 
 		/* Try again after 1m-sec */
@@ -231,9 +229,7 @@ static int smi_write_enable(int bank)
 
 	do {
 		sr = smi_read_sr(bank);
-		if (sr < 0)
-			break;
-		else if (sr & (1 << (bank + WM_SHIFT)))
+		if ((sr >= 0) && (sr & (1 << (bank + WM_SHIFT))))
 			return 0;
 
 		/* Try again after 1m-sec */
Signature · 1 line
1.7.2.2
author
#13 lore raw

PATCH 9/11 st_smi: Removed no needed dependency on ST_M25Pxx_ID

In reply to Amit Virdi

From: Armando Visconti <[email protected]>

Since the smi erase code is very generic and works for any kind of flash, there is no need to test for ST_M25Pxx_ID flash types like m25p40 flashes).

---
 drivers/mtd/st_smi.c |   50 ++++++++++++++++++--------------------------------
 1 files changed, 18 insertions(+), 32 deletions(-)
drivers/mtd/st_smi.c +18 -32
index e5c803b..43eb2ab 100644
@@ -37,8 +37,6 @@ static ulong bank_base[CONFIG_SYS_MAX_FLASH_BANKS] =
     CONFIG_SYS_FLASH_ADDR_BASE;
 flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
 
-#define ST_M25Pxx_ID		0x00002020
-
 static struct flash_dev flash_ids[] = {
 	{0x10, 0x10000, 2},	/* 64K Byte */
 	{0x11, 0x20000, 4},	/* 128K Byte */
@@ -287,39 +285,32 @@ static int smi_sector_erase(flash_info_t *info, unsigned int sector)
 
 	writel(readl(&smicntl->smi_sr) & ~(ERF1 | ERF2), &smicntl->smi_sr);
 
-	if (info->flash_id == ST_M25Pxx_ID) {
-		/* Wait until finished previous write command. */
-		if (smi_wait_till_ready(bank, CONFIG_SYS_FLASH_ERASE_TOUT))
-			return -EBUSY;
+	/* Wait until finished previous write command. */
+	if (smi_wait_till_ready(bank, CONFIG_SYS_FLASH_ERASE_TOUT))
+		return -EBUSY;
 
-		/* Send write enable, before erase commands. */
-		if (smi_write_enable(bank))
-			return -EIO;
+	/* Send write enable, before erase commands. */
+	if (smi_write_enable(bank))
+		return -EIO;
 
-		/* Put SMI in SW mode */
-		writel(readl(&smicntl->smi_cr1) | SW_MODE, &smicntl->smi_cr1);
+	/* Put SMI in SW mode */
+	writel(readl(&smicntl->smi_cr1) | SW_MODE, &smicntl->smi_cr1);
 
-		/* Send Sector Erase command in SW Mode */
-		writel(instruction, &smicntl->smi_tr);
-		writel((bank << BANKSEL_SHIFT) | SEND | TX_LEN_4,
+	/* Send Sector Erase command in SW Mode */
+	writel(instruction, &smicntl->smi_tr);
+	writel((bank << BANKSEL_SHIFT) | SEND | TX_LEN_4,
 		       &smicntl->smi_cr2);
-		if (smi_wait_xfer_finish(XFER_FINISH_TOUT))
-			return -EIO;
+	if (smi_wait_xfer_finish(XFER_FINISH_TOUT))
+		return -EIO;
 
-		if (smi_wait_till_ready(bank, CONFIG_SYS_FLASH_ERASE_TOUT))
-			return -EBUSY;
+	if (smi_wait_till_ready(bank, CONFIG_SYS_FLASH_ERASE_TOUT))
+		return -EBUSY;
 
-		/* Put SMI in HW mode */
-		writel(readl(&smicntl->smi_cr1) & ~SW_MODE,
+	/* Put SMI in HW mode */
+	writel(readl(&smicntl->smi_cr1) & ~SW_MODE,
 		       &smicntl->smi_cr1);
 
-		return 0;
-	} else {
-		/* Put SMI in HW mode */
-		writel(readl(&smicntl->smi_cr1) & ~SW_MODE,
-		       &smicntl->smi_cr1);
-		return -EINVAL;
-	}
+	return 0;
 }
 
 /*
@@ -496,11 +487,6 @@ int flash_erase(flash_info_t *info, int s_first, int s_last)
 	int prot = 0;
 	flash_sect_t sect;
 
-	if (info->flash_id != ST_M25Pxx_ID) {
-		puts("Can't erase unknown flash type - aborted\n");
-		return 1;
-	}
-
 	if ((s_first < 0) || (s_first > s_last)) {
 		puts("- no sectors to erase\n");
 		return 1;
Signature · 1 line
1.7.2.2
author
#14 lore raw

PATCH 10/11 st_smi: Change the flash probing method

In reply to Amit Virdi

From: Armando Visconti <[email protected]>

THis patch introduces a new methodology for flash probing in which flash_devices[] table, looked-up thru the dev_id, is used to locate the flash geometry and information.

---
 drivers/mtd/st_smi.c |   92 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 65 insertions(+), 27 deletions(-)
drivers/mtd/st_smi.c +65 -27
index 43eb2ab..a308399 100644
@@ -37,17 +37,61 @@ static ulong bank_base[CONFIG_SYS_MAX_FLASH_BANKS] =
     CONFIG_SYS_FLASH_ADDR_BASE;
 flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
 
-static struct flash_dev flash_ids[] = {
-	{0x10, 0x10000, 2},	/* 64K Byte */
-	{0x11, 0x20000, 4},	/* 128K Byte */
-	{0x12, 0x40000, 4},	/* 256K Byte */
-	{0x13, 0x80000, 8},	/* 512K Byte */
-	{0x14, 0x100000, 16},	/* 1M Byte */
-	{0x15, 0x200000, 32},	/* 2M Byte */
-	{0x16, 0x400000, 64},	/* 4M Byte */
-	{0x17, 0x800000, 128},	/* 8M Byte */
-	{0x18, 0x1000000, 64},	/* 16M Byte */
-	{0x00,}
+/* data structure to maintain flash ids from different vendors */
+struct flash_device {
+	char *name;
+	u8 erase_cmd;
+	u32 device_id;
+	u32 pagesize;
+	unsigned long sectorsize;
+	unsigned long size_in_bytes;
+};
+
+#define FLASH_ID(n, es, id, psize, ssize, size)	\
+{				\
+	.name = n,		\
+	.erase_cmd = es,	\
+	.device_id = id,	\
+	.pagesize = psize,	\
+	.sectorsize = ssize,	\
+	.size_in_bytes = size	\
+}
+
+/*
+ * List of supported flash devices.
+ * Currently the erase_cmd field is not used in this driver.
+ */
+static struct flash_device flash_devices[] = {
+	FLASH_ID("st m25p16"     , 0xd8, 0x00152020, 0x100, 0x10000, 0x200000),
+	FLASH_ID("st m25p32"     , 0xd8, 0x00162020, 0x100, 0x10000, 0x400000),
+	FLASH_ID("st m25p64"     , 0xd8, 0x00172020, 0x100, 0x10000, 0x800000),
+	FLASH_ID("st m25p128"    , 0xd8, 0x00182020, 0x100, 0x40000, 0x1000000),
+	FLASH_ID("st m25p05"     , 0xd8, 0x00102020, 0x80 , 0x8000 , 0x10000),
+	FLASH_ID("st m25p10"     , 0xd8, 0x00112020, 0x80 , 0x8000 , 0x20000),
+	FLASH_ID("st m25p20"     , 0xd8, 0x00122020, 0x100, 0x10000, 0x40000),
+	FLASH_ID("st m25p40"     , 0xd8, 0x00132020, 0x100, 0x10000, 0x80000),
+	FLASH_ID("st m25p80"     , 0xd8, 0x00142020, 0x100, 0x10000, 0x100000),
+	FLASH_ID("st m45pe10"    , 0xd8, 0x00114020, 0x100, 0x10000, 0x20000),
+	FLASH_ID("st m45pe20"    , 0xd8, 0x00124020, 0x100, 0x10000, 0x40000),
+	FLASH_ID("st m45pe40"    , 0xd8, 0x00134020, 0x100, 0x10000, 0x80000),
+	FLASH_ID("st m45pe80"    , 0xd8, 0x00144020, 0x100, 0x10000, 0x100000),
+	FLASH_ID("sp s25fl004"   , 0xd8, 0x00120201, 0x100, 0x10000, 0x80000),
+	FLASH_ID("sp s25fl008"   , 0xd8, 0x00130201, 0x100, 0x10000, 0x100000),
+	FLASH_ID("sp s25fl016"   , 0xd8, 0x00140201, 0x100, 0x10000, 0x200000),
+	FLASH_ID("sp s25fl032"   , 0xd8, 0x00150201, 0x100, 0x10000, 0x400000),
+	FLASH_ID("sp s25fl064"   , 0xd8, 0x00160201, 0x100, 0x10000, 0x800000),
+	FLASH_ID("mac 25l512"    , 0xd8, 0x001020C2, 0x010, 0x10000, 0x10000),
+	FLASH_ID("mac 25l1005"   , 0xd8, 0x001120C2, 0x010, 0x10000, 0x20000),
+	FLASH_ID("mac 25l2005"   , 0xd8, 0x001220C2, 0x010, 0x10000, 0x40000),
+	FLASH_ID("mac 25l4005"   , 0xd8, 0x001320C2, 0x010, 0x10000, 0x80000),
+	FLASH_ID("mac 25l4005a"  , 0xd8, 0x001320C2, 0x010, 0x10000, 0x80000),
+	FLASH_ID("mac 25l8005"   , 0xd8, 0x001420C2, 0x010, 0x10000, 0x100000),
+	FLASH_ID("mac 25l1605"   , 0xd8, 0x001520C2, 0x100, 0x10000, 0x200000),
+	FLASH_ID("mac 25l1605a"  , 0xd8, 0x001520C2, 0x010, 0x10000, 0x200000),
+	FLASH_ID("mac 25l3205"   , 0xd8, 0x001620C2, 0x100, 0x10000, 0x400000),
+	FLASH_ID("mac 25l3205a"  , 0xd8, 0x001620C2, 0x100, 0x10000, 0x400000),
+	FLASH_ID("mac 25l6405"   , 0xd8, 0x001720C2, 0x100, 0x10000, 0x800000),
+	FLASH_ID("wbd w25q128" , 0xd8, 0x001840EF, 0x1000, 0x10000, 0x1000000),
 };
 
 /*
@@ -105,9 +149,7 @@ static unsigned int smi_read_id(flash_info_t *info, int banknum)
 static ulong flash_get_size(ulong base, int banknum)
 {
 	flash_info_t *info = &flash_info[banknum];
-	struct flash_dev *dev;
 	int value;
-	unsigned int density;
 	int i;
 
 	value = smi_read_id(info, banknum);
@@ -117,24 +159,20 @@ static ulong flash_get_size(ulong base, int banknum)
 		return 0;
 	}
 
-	density = (value >> 16) & 0xff;
+	/* Matches chip-id to entire list of 'serial-nor flash' ids */
+	for (i = 0; i < ARRAY_SIZE(flash_devices); i++) {
+		if (flash_devices[i].device_id == value) {
+			info->size = flash_devices[i].size_in_bytes;
+			info->flash_id = value;
+			info->start[0] = base;
+			info->sector_count =
+					info->size/flash_devices[i].sectorsize;
 
-	for (i = 0, dev = &flash_ids[0]; dev->density != 0x0;
-	     i++, dev = &flash_ids[i]) {
-		if (dev->density == density) {
-			info->size = dev->size;
-			info->sector_count = dev->sector_count;
-			break;
+			return info->size;
 		}
 	}
 
-	if (dev->density == 0x0)
-		return 0;
-
-	info->flash_id = value & 0xffff;
-	info->start[0] = base;
-
-	return info->size;
+	return 0;
 }
 
 /*
Signature · 1 line
1.7.2.2
author
#15 lore raw

PATCH 11/11 st_smi: Fix bug in flash_print_info()

In reply to Amit Virdi

From: Armando Visconti <[email protected]>

If the flash size was smaller than 1MB then flash_print_info() was erroneously reporting 0 MB.

---
 drivers/mtd/st_smi.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
drivers/mtd/st_smi.c +7 -2
index a308399..6d4edba 100644
@@ -471,8 +471,13 @@ void flash_print_info(flash_info_t *info)
 		puts("missing or unknown FLASH type\n");
 		return;
 	}
-	printf("  Size: %ld MB in %d Sectors\n",
-	       info->size >> 20, info->sector_count);
+
+	if (info->size >= 0x100000)
+		printf("  Size: %ld MB in %d Sectors\n",
+		       info->size >> 20, info->sector_count);
+	else
+		printf("  Size: %ld KB in %d Sectors\n",
+		       info->size >> 10, info->sector_count);
 
 	puts("  Sector Start Addresses:");
 	for (i = 0; i < info->sector_count; ++i) {
Signature · 1 line
1.7.2.2
author
#16 lore raw

cover mtd/SMI: Add support for ST SMI controller

In reply to Amit Virdi

Hello Stefan,

Quoted 28 lines · Amit VIRDI

In the current u-boot, a driver exists for ST's SMI controller. However, the driver is SPEAr specific. This patchset makes the driver more generic so that it can be used across multiple platforms.

In the first commit, the driver is renamed to st_smi. In subsequent patches, changes are introduced so as to make the driver generic.

Amit Virdi (4):
st_smi: Remove compilation warning
st_smi: Return error in case TFF is not set
st_smi: Change SMI timeout values
st_smi: Enhance the error handling

Armando Visconti (3):
st_smi: Removed no needed dependency on ST_M25Pxx_ID
st_smi: Change the flash probing method
st_smi: Fix bug in flash_print_info()

Shiraz Hashim (1):
st_smi: Move status register read before modifying ctrl register

Vipin KUMAR (2):
st_smi: Add support for SPEAr SMI driver
st_smi: Read status until timeout happens

Vipin Kumar (1):
st_smi: Fix smi read status

Quoted 8 lines
  drivers/mtd/Makefile                               |    2 +-
  drivers/mtd/{spr_smi.c =>  st_smi.c}                |  223 ++++++++++++--------
  include/configs/spear-common.h                     |    6 +-
  .../spr_smi.h =>  include/linux/mtd/st_smi.h        |   10 +-
  4 files changed, 140 insertions(+), 101 deletions(-)

rename drivers/mtd/{spr_smi.c => st_smi.c} (66%)
rename arch/arm/include/asm/arch-spear/spr_smi.h => include/linux/mtd/st_smi.h (95%)

I'm not sure about the status of this patchset. Can you please tell me who's the custodian for SNOR flash devices?

Thanks
Amit Virdi

#17 lore raw

cover mtd/SMI: Add support for ST SMI controller

Hi Amit,

Quoted 38 lines · On Wednesday 07 March 2012 11:02:04 Amit Virdi wrote:
Quoted 34 lines

In the current u-boot, a driver exists for ST's SMI controller. However, the driver is SPEAr specific. This patchset makes the driver more generic so that it can be used across multiple platforms.

In the first commit, the driver is renamed to st_smi. In subsequent patches, changes are introduced so as to make the driver generic.

Amit Virdi (4):
st_smi: Remove compilation warning
st_smi: Return error in case TFF is not set
st_smi: Change SMI timeout values
st_smi: Enhance the error handling

Armando Visconti (3):
st_smi: Removed no needed dependency on ST_M25Pxx_ID
st_smi: Change the flash probing method
st_smi: Fix bug in flash_print_info()

Shiraz Hashim (1):
st_smi: Move status register read before modifying ctrl register

Vipin KUMAR (2):
st_smi: Add support for SPEAr SMI driver
st_smi: Read status until timeout happens

Vipin Kumar (1):
st_smi: Fix smi read status

  drivers/mtd/Makefile                               |    2 +-
  drivers/mtd/{spr_smi.c =>  st_smi.c}                |  223
  ++++++++++++-------- include/configs/spear-common.h                   
   |    6 +-
  .../spr_smi.h =>  include/linux/mtd/st_smi.h        |   10 +-
  4 files changed, 140 insertions(+), 101 deletions(-)
Quoted 3 lines

rename drivers/mtd/{spr_smi.c => st_smi.c} (66%) rename arch/arm/include/asm/arch-spear/spr_smi.h => include/linux/mtd/st_smi.h (95%)

Quoted 2 lines

I'm not sure about the status of this patchset. Can you please tell me who's the custodian for SNOR flash devices?

Usually I handle those kind of patches, as I'm the CFI flash custodian. I have assigned those patches to me. Since its not really bug fixes, I'll add them to the next branch, once it opens. So they will get pushed after the upcoming release.

Thanks,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de

author
#18 lore raw

cover mtd/SMI: Add support for ST SMI controller

Dear Stefan,

Quoted 9 lines
Quoted 3 lines

I'm not sure about the status of this patchset. Can you please tell me who's the custodian for SNOR flash devices?

Usually I handle those kind of patches, as I'm the CFI flash custodian. I have assigned those patches to me. Since its not really bug fixes, I'll add them to the next branch, once it opens. So they will get pushed after the upcoming release.

Thanks for the information. I have added another patch as a cleanup for the timeout loops. Will you prefer V2 for this patchset with that commit added or you're fine with that as a separate commit?

Thanks
Amit Virdi

#19 lore raw

cover mtd/SMI: Add support for ST SMI controller

Hi Amit,

Quoted 11 lines · On Wednesday 07 March 2012 12:46:43 Amit Virdi wrote:
Quoted 7 lines
Quoted 2 lines

I'm not sure about the status of this patchset. Can you please tell me who's the custodian for SNOR flash devices?

Usually I handle those kind of patches, as I'm the CFI flash custodian. I have assigned those patches to me. Since its not really bug fixes, I'll add them to the next branch, once it opens. So they will get pushed after the upcoming release.

Thanks for the information. I have added another patch as a cleanup for the timeout loops. Will you prefer V2 for this patchset with that commit added or you're fine with that as a separate commit?

Separate patch is fine with me.

Thanks,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de

author
#20 lore raw

PATCH 1/1 st_smi: Fixed page size for Winbond W25Q128FV flash

In reply to Amit Virdi

From: Armando Visconti <[email protected]>

---
 drivers/mtd/st_smi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/mtd/st_smi.c +1 -1
index bd5602b..3f689e7 100644
@@ -91,7 +91,7 @@ static struct flash_device flash_devices[] = {
 	FLASH_ID("mac 25l3205"   , 0xd8, 0x001620C2, 0x100, 0x10000, 0x400000),
 	FLASH_ID("mac 25l3205a"  , 0xd8, 0x001620C2, 0x100, 0x10000, 0x400000),
 	FLASH_ID("mac 25l6405"   , 0xd8, 0x001720C2, 0x100, 0x10000, 0x800000),
-	FLASH_ID("wbd w25q128" , 0xd8, 0x001840EF, 0x1000, 0x10000, 0x1000000),
+	FLASH_ID("wbd w25q128" , 0xd8, 0x001840EF, 0x100, 0x10000, 0x1000000),
 };
 
 /*
Signature · 1 line
1.7.2.2