* [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller
@ 2012-05-07 7:30 Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 01/12] st_smi: Add support for SPEAr SMI driver Amit Virdi
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
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.
This patchset is rebased on "next".
Amit Virdi (4):
st_smi: Return error in case TFF is not set
st_smi: Change SMI timeout values
st_smi: Enhance the error handling
st_smi: Change timeout loop implementation
Armando Visconti (4):
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()
st_smi: Fixed page size for Winbond W25Q128FV flash
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} | 231 ++++++++++++--------
include/configs/spear-common.h | 6 +-
.../spr_smi.h => include/linux/mtd/st_smi.h | 10 +-
4 files changed, 150 insertions(+), 99 deletions(-)
rename drivers/mtd/{spr_smi.c => st_smi.c} (65%)
rename arch/arm/include/asm/arch-spear/spr_smi.h => include/linux/mtd/st_smi.h (95%)
--
1.7.2.2
^ permalink raw reply [flat|nested] 13+ messages in thread
* [U-Boot] [PATCH V1 RESEND 01/12] st_smi: Add support for SPEAr SMI driver
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
@ 2012-05-07 7:30 ` Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 02/12] st_smi: Return error in case TFF is not set Amit Virdi
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
From: Vipin KUMAR <vipin.kumar@st.com>
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.
Signed-off-by: Vipin Kumar <vipin.kumar@st.com>
Signed-off-by: Amit Virdi <amit.virdi@st.com>
---
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%)
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index 5a5ecdf..543c845 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -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)
diff --git a/drivers/mtd/spr_smi.c b/drivers/mtd/st_smi.c
similarity index 99%
rename from drivers/mtd/spr_smi.c
rename to drivers/mtd/st_smi.c
index 6d4257a..82f1fe1 100644
--- a/drivers/mtd/spr_smi.c
+++ b/drivers/mtd/st_smi.c
@@ -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,
diff --git a/include/configs/spear-common.h b/include/configs/spear-common.h
index 5fef8cc..e0fd618 100644
--- a/include/configs/spear-common.h
+++ b/include/configs/spear-common.h
@@ -55,10 +55,10 @@
#if defined(CONFIG_FLASH_PNOR)
#define CONFIG_SPEAR_EMI 1
#else
-#define CONFIG_SPEARSMI 1
+#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
*/
diff --git a/arch/arm/include/asm/arch-spear/spr_smi.h b/include/linux/mtd/st_smi.h
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
--- a/arch/arm/include/asm/arch-spear/spr_smi.h
+++ b/include/linux/mtd/st_smi.h
@@ -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
--
1.7.2.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [U-Boot] [PATCH V1 RESEND 02/12] st_smi: Return error in case TFF is not set
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 01/12] st_smi: Add support for SPEAr SMI driver Amit Virdi
@ 2012-05-07 7:30 ` Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 03/12] st_smi: Change SMI timeout values Amit Virdi
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Vipin Kumar <vipin.kumar@st.com>
Signed-off-by: Amit Virdi <amit.virdi@st.com>
---
drivers/mtd/st_smi.c | 22 ++++++++++++++--------
1 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/mtd/st_smi.c b/drivers/mtd/st_smi.c
index 82f1fe1..ec19b0d 100644
--- a/drivers/mtd/st_smi.c
+++ b/drivers/mtd/st_smi.c
@@ -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;
--
1.7.2.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [U-Boot] [PATCH V1 RESEND 03/12] st_smi: Change SMI timeout values
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 01/12] st_smi: Add support for SPEAr SMI driver Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 02/12] st_smi: Return error in case TFF is not set Amit Virdi
@ 2012-05-07 7:30 ` Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 04/12] st_smi: Enhance the error handling Amit Virdi
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
Signed-off-by: Amit Virdi <amit.virdi@st.com>
---
include/linux/mtd/st_smi.h | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/mtd/st_smi.h b/include/linux/mtd/st_smi.h
index b7a78ac..04f81ea 100644
--- a/include/linux/mtd/st_smi.h
+++ b/include/linux/mtd/st_smi.h
@@ -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);
--
1.7.2.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [U-Boot] [PATCH V1 RESEND 04/12] st_smi: Enhance the error handling
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
` (2 preceding siblings ...)
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 03/12] st_smi: Change SMI timeout values Amit Virdi
@ 2012-05-07 7:30 ` Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 05/12] st_smi: Read status until timeout happens Amit Virdi
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
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
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [U-Boot] [PATCH V1 RESEND 05/12] st_smi: Read status until timeout happens
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
` (3 preceding siblings ...)
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 04/12] st_smi: Enhance the error handling Amit Virdi
@ 2012-05-07 7:30 ` Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 06/12] st_smi: Move status register read before modifying ctrl register Amit Virdi
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
From: Vipin KUMAR <vipin.kumar@st.com>
SMI driver read status fails because the control register could not be
overwritten. Instead, the read status should be tried until timeout.
Signed-off-by: Vipin Kumar <vipin.kumar@st.com>
Signed-off-by: Amit Virdi <amit.virdi@st.com>
---
drivers/mtd/st_smi.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/mtd/st_smi.c b/drivers/mtd/st_smi.c
index ce50fc1..7b4c6f3 100644
--- a/drivers/mtd/st_smi.c
+++ b/drivers/mtd/st_smi.c
@@ -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;
--
1.7.2.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [U-Boot] [PATCH V1 RESEND 06/12] st_smi: Move status register read before modifying ctrl register
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
` (4 preceding siblings ...)
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 05/12] st_smi: Read status until timeout happens Amit Virdi
@ 2012-05-07 7:30 ` Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 07/12] st_smi: Fix smi read status Amit Virdi
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
From: Shiraz Hashim <shiraz.hashim@st.com>
Signed-off-by: Shiraz Hashim <shiraz.hashim@st.com>
Signed-off-by: Amit Virdi <amit.virdi@st.com>
---
drivers/mtd/st_smi.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/st_smi.c b/drivers/mtd/st_smi.c
index 7b4c6f3..eb902b2 100644
--- a/drivers/mtd/st_smi.c
+++ b/drivers/mtd/st_smi.c
@@ -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;
}
/*
--
1.7.2.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [U-Boot] [PATCH V1 RESEND 07/12] st_smi: Fix smi read status
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
` (5 preceding siblings ...)
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 06/12] st_smi: Move status register read before modifying ctrl register Amit Virdi
@ 2012-05-07 7:30 ` Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 08/12] st_smi: Removed no needed dependency on ST_M25Pxx_ID Amit Virdi
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
From: Vipin Kumar <vipin.kumar@st.com>
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.
Signed-off-by: Vipin Kumar <vipin.kumar@st.com>
Signed-off-by: Amit Virdi <amit.virdi@st.com>
---
drivers/mtd/st_smi.c | 8 ++------
1 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/mtd/st_smi.c b/drivers/mtd/st_smi.c
index eb902b2..e5c803b 100644
--- a/drivers/mtd/st_smi.c
+++ b/drivers/mtd/st_smi.c
@@ -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 */
--
1.7.2.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [U-Boot] [PATCH V1 RESEND 08/12] st_smi: Removed no needed dependency on ST_M25Pxx_ID
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
` (6 preceding siblings ...)
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 07/12] st_smi: Fix smi read status Amit Virdi
@ 2012-05-07 7:30 ` Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 09/12] st_smi: Change the flash probing method Amit Virdi
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
From: Armando Visconti <armando.visconti@st.com>
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).
Signed-off-by: Armando Visconti <armando.visconti@st.com>
Signed-off-by: Amit Virdi <amit.virdi@st.com>
---
drivers/mtd/st_smi.c | 50 ++++++++++++++++++--------------------------------
1 files changed, 18 insertions(+), 32 deletions(-)
diff --git a/drivers/mtd/st_smi.c b/drivers/mtd/st_smi.c
index e5c803b..43eb2ab 100644
--- a/drivers/mtd/st_smi.c
+++ b/drivers/mtd/st_smi.c
@@ -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;
--
1.7.2.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [U-Boot] [PATCH V1 RESEND 09/12] st_smi: Change the flash probing method
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
` (7 preceding siblings ...)
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 08/12] st_smi: Removed no needed dependency on ST_M25Pxx_ID Amit Virdi
@ 2012-05-07 7:30 ` Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 10/12] st_smi: Fix bug in flash_print_info() Amit Virdi
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
From: Armando Visconti <armando.visconti@st.com>
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.
Signed-off-by: Armando Visconti <armando.visconti@st.com>
Signed-off-by: Amit Virdi <amit.virdi@st.com>
---
drivers/mtd/st_smi.c | 92 +++++++++++++++++++++++++++++++++++---------------
1 files changed, 65 insertions(+), 27 deletions(-)
diff --git a/drivers/mtd/st_smi.c b/drivers/mtd/st_smi.c
index 43eb2ab..a308399 100644
--- a/drivers/mtd/st_smi.c
+++ b/drivers/mtd/st_smi.c
@@ -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;
}
/*
--
1.7.2.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [U-Boot] [PATCH V1 RESEND 10/12] st_smi: Fix bug in flash_print_info()
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
` (8 preceding siblings ...)
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 09/12] st_smi: Change the flash probing method Amit Virdi
@ 2012-05-07 7:30 ` Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 11/12] st_smi: Change timeout loop implementation Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 12/12] st_smi: Fixed page size for Winbond W25Q128FV flash Amit Virdi
11 siblings, 0 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
From: Armando Visconti <armando.visconti@st.com>
If the flash size was smaller than 1MB then flash_print_info()
was erroneously reporting 0 MB.
Signed-off-by: Armando Visconti <armando.visconti@st.com>
Signed-off-by: Amit Virdi <amit.virdi@st.com>
---
drivers/mtd/st_smi.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/st_smi.c b/drivers/mtd/st_smi.c
index a308399..6d4edba 100644
--- a/drivers/mtd/st_smi.c
+++ b/drivers/mtd/st_smi.c
@@ -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) {
--
1.7.2.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [U-Boot] [PATCH V1 RESEND 11/12] st_smi: Change timeout loop implementation
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
` (9 preceding siblings ...)
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 10/12] st_smi: Fix bug in flash_print_info() Amit Virdi
@ 2012-05-07 7:30 ` Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 12/12] st_smi: Fixed page size for Winbond W25Q128FV flash Amit Virdi
11 siblings, 0 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
There are two problems in the current timeout loop implementation:
1. In case initial test failing, there will always be a delay of 1 ms
2. The delay duration is not tunable
The new implementation addresses both these limitations.
Signed-off-by: Amit Virdi <amit.virdi@st.com>
---
drivers/mtd/st_smi.c | 27 +++++++++++++++++----------
1 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/st_smi.c b/drivers/mtd/st_smi.c
index 6d4edba..bd5602b 100644
--- a/drivers/mtd/st_smi.c
+++ b/drivers/mtd/st_smi.c
@@ -102,11 +102,15 @@ static struct flash_device flash_devices[] = {
*/
static int smi_wait_xfer_finish(int timeout)
{
- do {
+ ulong start = get_timer(0);
+
+ while (get_timer(start) < timeout) {
if (readl(&smicntl->smi_sr) & TFF)
return 0;
- udelay(1000);
- } while (timeout--);
+
+ /* Try after 10 ms */
+ udelay(10);
+ };
return -1;
}
@@ -219,16 +223,17 @@ static int smi_read_sr(int bank)
static int smi_wait_till_ready(int bank, int timeout)
{
int sr;
+ ulong start = get_timer(0);
/* One chip guarantees max 5 msec wait here after page writes,
but potentially three seconds (!) after page erase. */
- do {
+ while (get_timer(start) < timeout) {
sr = smi_read_sr(bank);
if ((sr >= 0) && (!(sr & WIP_BIT)))
return 0;
- /* Try again after 1m-sec */
- udelay(1000);
+ /* Try again after 10 usec */
+ udelay(10);
} while (timeout--);
printf("SMI controller is still in wait, timeout=%d\n", timeout);
@@ -245,6 +250,7 @@ static int smi_wait_till_ready(int bank, int timeout)
static int smi_write_enable(int bank)
{
u32 ctrlreg1;
+ u32 start;
int timeout = WMODE_TOUT;
int sr;
@@ -263,14 +269,15 @@ static int smi_write_enable(int bank)
/* Restore the CTRL REG1 state */
writel(ctrlreg1, &smicntl->smi_cr1);
- do {
+ start = get_timer(0);
+ while (get_timer(start) < timeout) {
sr = smi_read_sr(bank);
if ((sr >= 0) && (sr & (1 << (bank + WM_SHIFT))))
return 0;
- /* Try again after 1m-sec */
- udelay(1000);
- } while (timeout--);
+ /* Try again after 10 usec */
+ udelay(10);
+ };
return -1;
}
--
1.7.2.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [U-Boot] [PATCH V1 RESEND 12/12] st_smi: Fixed page size for Winbond W25Q128FV flash
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
` (10 preceding siblings ...)
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 11/12] st_smi: Change timeout loop implementation Amit Virdi
@ 2012-05-07 7:30 ` Amit Virdi
11 siblings, 0 replies; 13+ messages in thread
From: Amit Virdi @ 2012-05-07 7:30 UTC (permalink / raw)
To: u-boot
From: Armando Visconti <armando.visconti@st.com>
Signed-off-by: Armando Visconti <armando.visconti@st.com>
Signed-off-by: Amit Virdi <amit.virdi@st.com>
---
drivers/mtd/st_smi.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/mtd/st_smi.c b/drivers/mtd/st_smi.c
index bd5602b..3f689e7 100644
--- a/drivers/mtd/st_smi.c
+++ b/drivers/mtd/st_smi.c
@@ -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),
};
/*
--
1.7.2.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
end of thread, other threads:[~2012-05-07 7:30 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-07 7:30 [U-Boot] [PATCH V1 RESEND 00/12] mtd/SMI: Add support for ST SMI controller Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 01/12] st_smi: Add support for SPEAr SMI driver Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 02/12] st_smi: Return error in case TFF is not set Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 03/12] st_smi: Change SMI timeout values Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 04/12] st_smi: Enhance the error handling Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 05/12] st_smi: Read status until timeout happens Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 06/12] st_smi: Move status register read before modifying ctrl register Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 07/12] st_smi: Fix smi read status Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 08/12] st_smi: Removed no needed dependency on ST_M25Pxx_ID Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 09/12] st_smi: Change the flash probing method Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 10/12] st_smi: Fix bug in flash_print_info() Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 11/12] st_smi: Change timeout loop implementation Amit Virdi
2012-05-07 7:30 ` [U-Boot] [PATCH V1 RESEND 12/12] st_smi: Fixed page size for Winbond W25Q128FV flash Amit Virdi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox