4949#define SST49LF008A 0x005a
5050#define AT49BV6416 0x00d6
5151
52+ /*
53+ * Status Register bit description. Used by flash devices that don't
54+ * support DQ polling (e.g. HyperFlash)
55+ */
56+ #define CFI_SR_DRB BIT(7)
57+ #define CFI_SR_ESB BIT(5)
58+ #define CFI_SR_PSB BIT(4)
59+ #define CFI_SR_WBASB BIT(3)
60+ #define CFI_SR_SLSB BIT(1)
61+
5262static int cfi_amdstd_read (struct mtd_info * , loff_t , size_t , size_t * , u_char * );
5363static int cfi_amdstd_write_words (struct mtd_info * , loff_t , size_t , size_t * , const u_char * );
5464static int cfi_amdstd_write_buffers (struct mtd_info * , loff_t , size_t , size_t * , const u_char * );
@@ -97,6 +107,50 @@ static struct mtd_chip_driver cfi_amdstd_chipdrv = {
97107 .module = THIS_MODULE
98108};
99109
110+ /*
111+ * Use status register to poll for Erase/write completion when DQ is not
112+ * supported. This is indicated by Bit[1:0] of SoftwareFeatures field in
113+ * CFI Primary Vendor-Specific Extended Query table 1.5
114+ */
115+ static int cfi_use_status_reg (struct cfi_private * cfi )
116+ {
117+ struct cfi_pri_amdstd * extp = cfi -> cmdset_priv ;
118+ u8 poll_mask = CFI_POLL_STATUS_REG | CFI_POLL_DQ ;
119+
120+ return extp -> MinorVersion >= '5' &&
121+ (extp -> SoftwareFeatures & poll_mask ) == CFI_POLL_STATUS_REG ;
122+ }
123+
124+ static void cfi_check_err_status (struct map_info * map , struct flchip * chip ,
125+ unsigned long adr )
126+ {
127+ struct cfi_private * cfi = map -> fldrv_priv ;
128+ map_word status ;
129+
130+ if (!cfi_use_status_reg (cfi ))
131+ return ;
132+
133+ cfi_send_gen_cmd (0x70 , cfi -> addr_unlock1 , chip -> start , map , cfi ,
134+ cfi -> device_type , NULL );
135+ status = map_read (map , adr );
136+
137+ if (map_word_bitsset (map , status , CMD (0x3a ))) {
138+ unsigned long chipstatus = MERGESTATUS (status );
139+
140+ if (chipstatus & CFI_SR_ESB )
141+ pr_err ("%s erase operation failed, status %lx\n" ,
142+ map -> name , chipstatus );
143+ if (chipstatus & CFI_SR_PSB )
144+ pr_err ("%s program operation failed, status %lx\n" ,
145+ map -> name , chipstatus );
146+ if (chipstatus & CFI_SR_WBASB )
147+ pr_err ("%s buffer program command aborted, status %lx\n" ,
148+ map -> name , chipstatus );
149+ if (chipstatus & CFI_SR_SLSB )
150+ pr_err ("%s sector write protected, status %lx\n" ,
151+ map -> name , chipstatus );
152+ }
153+ }
100154
101155/* #define DEBUG_CFI_FEATURES */
102156
@@ -742,10 +796,25 @@ static struct mtd_info *cfi_amdstd_setup(struct mtd_info *mtd)
742796 * correctly and is therefore not done (particularly with interleaved chips
743797 * as each chip must be checked independently of the others).
744798 */
745- static int __xipram chip_ready (struct map_info * map , unsigned long addr )
799+ static int __xipram chip_ready (struct map_info * map , struct flchip * chip ,
800+ unsigned long addr )
746801{
802+ struct cfi_private * cfi = map -> fldrv_priv ;
747803 map_word d , t ;
748804
805+ if (cfi_use_status_reg (cfi )) {
806+ map_word ready = CMD (CFI_SR_DRB );
807+ /*
808+ * For chips that support status register, check device
809+ * ready bit
810+ */
811+ cfi_send_gen_cmd (0x70 , cfi -> addr_unlock1 , chip -> start , map , cfi ,
812+ cfi -> device_type , NULL );
813+ d = map_read (map , addr );
814+
815+ return map_word_andequal (map , d , ready , ready );
816+ }
817+
749818 d = map_read (map , addr );
750819 t = map_read (map , addr );
751820
@@ -767,10 +836,30 @@ static int __xipram chip_ready(struct map_info *map, unsigned long addr)
767836 * as each chip must be checked independently of the others).
768837 *
769838 */
770- static int __xipram chip_good (struct map_info * map , unsigned long addr , map_word expected )
839+ static int __xipram chip_good (struct map_info * map , struct flchip * chip ,
840+ unsigned long addr , map_word expected )
771841{
842+ struct cfi_private * cfi = map -> fldrv_priv ;
772843 map_word oldd , curd ;
773844
845+ if (cfi_use_status_reg (cfi )) {
846+ map_word ready = CMD (CFI_SR_DRB );
847+ map_word err = CMD (CFI_SR_PSB | CFI_SR_ESB );
848+ /*
849+ * For chips that support status register, check device
850+ * ready bit and Erase/Program status bit to know if
851+ * operation succeeded.
852+ */
853+ cfi_send_gen_cmd (0x70 , cfi -> addr_unlock1 , chip -> start , map , cfi ,
854+ cfi -> device_type , NULL );
855+ curd = map_read (map , addr );
856+
857+ if (map_word_andequal (map , curd , ready , ready ))
858+ return !map_word_bitsset (map , curd , err );
859+
860+ return 0 ;
861+ }
862+
774863 oldd = map_read (map , addr );
775864 curd = map_read (map , addr );
776865
@@ -792,7 +881,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
792881
793882 case FL_STATUS :
794883 for (;;) {
795- if (chip_ready (map , adr ))
884+ if (chip_ready (map , chip , adr ))
796885 break ;
797886
798887 if (time_after (jiffies , timeo )) {
@@ -830,7 +919,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
830919 chip -> state = FL_ERASE_SUSPENDING ;
831920 chip -> erase_suspended = 1 ;
832921 for (;;) {
833- if (chip_ready (map , adr ))
922+ if (chip_ready (map , chip , adr ))
834923 break ;
835924
836925 if (time_after (jiffies , timeo )) {
@@ -1362,7 +1451,7 @@ static int do_otp_lock(struct map_info *map, struct flchip *chip, loff_t adr,
13621451 /* wait for chip to become ready */
13631452 timeo = jiffies + msecs_to_jiffies (2 );
13641453 for (;;) {
1365- if (chip_ready (map , adr ))
1454+ if (chip_ready (map , chip , adr ))
13661455 break ;
13671456
13681457 if (time_after (jiffies , timeo )) {
@@ -1628,22 +1717,24 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
16281717 continue ;
16291718 }
16301719
1631- if (time_after (jiffies , timeo ) && !chip_ready (map , adr )){
1720+ if (time_after (jiffies , timeo ) &&
1721+ !chip_ready (map , chip , adr )) {
16321722 xip_enable (map , chip , adr );
16331723 printk (KERN_WARNING "MTD %s(): software timeout\n" , __func__ );
16341724 xip_disable (map , chip , adr );
16351725 break ;
16361726 }
16371727
1638- if (chip_ready (map , adr ))
1728+ if (chip_ready (map , chip , adr ))
16391729 break ;
16401730
16411731 /* Latency issues. Drop the lock, wait a while and retry */
16421732 UDELAY (map , chip , adr , 1 );
16431733 }
16441734 /* Did we succeed? */
1645- if (!chip_good (map , adr , datum )) {
1735+ if (!chip_good (map , chip , adr , datum )) {
16461736 /* reset on all failures. */
1737+ cfi_check_err_status (map , chip , adr );
16471738 map_write (map , CMD (0xF0 ), chip -> start );
16481739 /* FIXME - should have reset delay before continuing */
16491740
@@ -1881,10 +1972,11 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
18811972 * We check "time_after" and "!chip_good" before checking "chip_good" to avoid
18821973 * the failure due to scheduling.
18831974 */
1884- if (time_after (jiffies , timeo ) && !chip_good (map , adr , datum ))
1975+ if (time_after (jiffies , timeo ) &&
1976+ !chip_good (map , chip , adr , datum ))
18851977 break ;
18861978
1887- if (chip_good (map , adr , datum )) {
1979+ if (chip_good (map , chip , adr , datum )) {
18881980 xip_enable (map , chip , adr );
18891981 goto op_done ;
18901982 }
@@ -1901,6 +1993,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
19011993 * See e.g.
19021994 * http://www.spansion.com/Support/Application%20Notes/MirrorBit_Write_Buffer_Prog_Page_Buffer_Read_AN.pdf
19031995 */
1996+ cfi_check_err_status (map , chip , adr );
19041997 cfi_send_gen_cmd (0xAA , cfi -> addr_unlock1 , chip -> start , map , cfi ,
19051998 cfi -> device_type , NULL );
19061999 cfi_send_gen_cmd (0x55 , cfi -> addr_unlock2 , chip -> start , map , cfi ,
@@ -2018,7 +2111,7 @@ static int cfi_amdstd_panic_wait(struct map_info *map, struct flchip *chip,
20182111 * If the driver thinks the chip is idle, and no toggle bits
20192112 * are changing, then the chip is actually idle for sure.
20202113 */
2021- if (chip -> state == FL_READY && chip_ready (map , adr ))
2114+ if (chip -> state == FL_READY && chip_ready (map , chip , adr ))
20222115 return 0 ;
20232116
20242117 /*
@@ -2035,7 +2128,7 @@ static int cfi_amdstd_panic_wait(struct map_info *map, struct flchip *chip,
20352128
20362129 /* wait for the chip to become ready */
20372130 for (i = 0 ; i < jiffies_to_usecs (timeo ); i ++ ) {
2038- if (chip_ready (map , adr ))
2131+ if (chip_ready (map , chip , adr ))
20392132 return 0 ;
20402133
20412134 udelay (1 );
@@ -2099,14 +2192,15 @@ static int do_panic_write_oneword(struct map_info *map, struct flchip *chip,
20992192 map_write (map , datum , adr );
21002193
21012194 for (i = 0 ; i < jiffies_to_usecs (uWriteTimeout ); i ++ ) {
2102- if (chip_ready (map , adr ))
2195+ if (chip_ready (map , chip , adr ))
21032196 break ;
21042197
21052198 udelay (1 );
21062199 }
21072200
2108- if (!chip_good (map , adr , datum )) {
2201+ if (!chip_good (map , chip , adr , datum )) {
21092202 /* reset on all failures. */
2203+ cfi_check_err_status (map , chip , adr );
21102204 map_write (map , CMD (0xF0 ), chip -> start );
21112205 /* FIXME - should have reset delay before continuing */
21122206
@@ -2300,7 +2394,7 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip)
23002394 chip -> erase_suspended = 0 ;
23012395 }
23022396
2303- if (chip_good (map , adr , map_word_ff (map )))
2397+ if (chip_good (map , chip , adr , map_word_ff (map )))
23042398 break ;
23052399
23062400 if (time_after (jiffies , timeo )) {
@@ -2316,6 +2410,7 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip)
23162410 /* Did we succeed? */
23172411 if (ret ) {
23182412 /* reset on all failures. */
2413+ cfi_check_err_status (map , chip , adr );
23192414 map_write (map , CMD (0xF0 ), chip -> start );
23202415 /* FIXME - should have reset delay before continuing */
23212416
@@ -2396,7 +2491,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
23962491 chip -> erase_suspended = 0 ;
23972492 }
23982493
2399- if (chip_good (map , adr , map_word_ff (map )))
2494+ if (chip_good (map , chip , adr , map_word_ff (map )))
24002495 break ;
24012496
24022497 if (time_after (jiffies , timeo )) {
@@ -2412,6 +2507,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
24122507 /* Did we succeed? */
24132508 if (ret ) {
24142509 /* reset on all failures. */
2510+ cfi_check_err_status (map , chip , adr );
24152511 map_write (map , CMD (0xF0 ), chip -> start );
24162512 /* FIXME - should have reset delay before continuing */
24172513
@@ -2587,7 +2683,7 @@ static int __maybe_unused do_ppb_xxlock(struct map_info *map,
25872683 */
25882684 timeo = jiffies + msecs_to_jiffies (2000 ); /* 2s max (un)locking */
25892685 for (;;) {
2590- if (chip_ready (map , adr ))
2686+ if (chip_ready (map , chip , adr ))
25912687 break ;
25922688
25932689 if (time_after (jiffies , timeo )) {
0 commit comments