mtd/SMI: Add support for ST SMI controller
Subsystems (2)
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.
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%)Signature · 1 line
1.7.2.2
PATCH RESEND 1/12 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
@@ -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
@@ -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
@@ -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 */
include/linux/mtd/st_smi.h renamed from arch/arm/include/asm/arch-spear/spr_smi.h +4 -2
@@ -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
PATCH RESEND 2/12 st_smi: Return error in case TFF is not set
In reply to Amit VirdiCurently 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
@@ -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
PATCH RESEND 3/12 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
@@ -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
PATCH RESEND 4/12 st_smi: Enhance the error handling
In reply to Amit VirdiThis 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
@@ -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
PATCH RESEND 5/12 st_smi: Read status until timeout happens
In reply to Amit VirdiFrom: 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
@@ -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
PATCH RESEND 6/12 st_smi: Move status register read before modifying ctrl register
In reply to Amit VirdiFrom: Shiraz Hashim <[email protected]>
--- drivers/mtd/st_smi.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/mtd/st_smi.c +4 -2
@@ -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
PATCH RESEND 7/12 st_smi: Fix smi read status
In reply to Amit VirdiFrom: 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
@@ -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
PATCH RESEND 8/12 st_smi: Removed no needed dependency on ST_M25Pxx_ID
In reply to Amit VirdiFrom: 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
@@ -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
PATCH RESEND 9/12 st_smi: Change the flash probing method
In reply to Amit VirdiFrom: 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
@@ -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
PATCH RESEND 10/12 st_smi: Fix bug in flash_print_info()
In reply to Amit VirdiFrom: 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
@@ -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
PATCH RESEND 11/12 st_smi: Change timeout loop implementation
In reply to Amit VirdiThere 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.
--- drivers/mtd/st_smi.c | 27 +++++++++++++++++---------- 1 files changed, 17 insertions(+), 10 deletions(-)
drivers/mtd/st_smi.c +17 -10
@@ -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 ; }
Signature · 1 line
1.7.2.2
PATCH RESEND 12/12 st_smi: Fixed page size for Winbond W25Q128FV flash
In reply to Amit VirdiFrom: Armando Visconti <[email protected]>
--- drivers/mtd/st_smi.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/mtd/st_smi.c +1 -1
@@ -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