@@ -802,21 +802,25 @@ static struct mtd_info *cfi_amdstd_setup(struct mtd_info *mtd)
802802}
803803
804804/*
805- * Return true if the chip is ready.
805+ * Return true if the chip is ready and has the correct value .
806806 *
807807 * Ready is one of: read mode, query mode, erase-suspend-read mode (in any
808808 * non-suspended sector) and is indicated by no toggle bits toggling.
809809 *
810+ * Error are indicated by toggling bits or bits held with the wrong value,
811+ * or with bits toggling.
812+ *
810813 * Note that anything more complicated than checking if no bits are toggling
811814 * (including checking DQ5 for an error status) is tricky to get working
812815 * correctly and is therefore not done (particularly with interleaved chips
813816 * as each chip must be checked independently of the others).
814817 */
815818static int __xipram chip_ready (struct map_info * map , struct flchip * chip ,
816- unsigned long addr )
819+ unsigned long addr , map_word * expected )
817820{
818821 struct cfi_private * cfi = map -> fldrv_priv ;
819822 map_word d , t ;
823+ int ret ;
820824
821825 if (cfi_use_status_reg (cfi )) {
822826 map_word ready = CMD (CFI_SR_DRB );
@@ -826,57 +830,20 @@ static int __xipram chip_ready(struct map_info *map, struct flchip *chip,
826830 */
827831 cfi_send_gen_cmd (0x70 , cfi -> addr_unlock1 , chip -> start , map , cfi ,
828832 cfi -> device_type , NULL );
829- d = map_read (map , addr );
833+ t = map_read (map , addr );
830834
831- return map_word_andequal (map , d , ready , ready );
835+ return map_word_andequal (map , t , ready , ready );
832836 }
833837
834838 d = map_read (map , addr );
835839 t = map_read (map , addr );
836840
837- return map_word_equal (map , d , t );
838- }
839-
840- /*
841- * Return true if the chip is ready and has the correct value.
842- *
843- * Ready is one of: read mode, query mode, erase-suspend-read mode (in any
844- * non-suspended sector) and it is indicated by no bits toggling.
845- *
846- * Error are indicated by toggling bits or bits held with the wrong value,
847- * or with bits toggling.
848- *
849- * Note that anything more complicated than checking if no bits are toggling
850- * (including checking DQ5 for an error status) is tricky to get working
851- * correctly and is therefore not done (particularly with interleaved chips
852- * as each chip must be checked independently of the others).
853- *
854- */
855- static int __xipram chip_good (struct map_info * map , struct flchip * chip ,
856- unsigned long addr , map_word expected )
857- {
858- struct cfi_private * cfi = map -> fldrv_priv ;
859- map_word oldd , curd ;
860-
861- if (cfi_use_status_reg (cfi )) {
862- map_word ready = CMD (CFI_SR_DRB );
863-
864- /*
865- * For chips that support status register, check device
866- * ready bit
867- */
868- cfi_send_gen_cmd (0x70 , cfi -> addr_unlock1 , chip -> start , map , cfi ,
869- cfi -> device_type , NULL );
870- curd = map_read (map , addr );
871-
872- return map_word_andequal (map , curd , ready , ready );
873- }
841+ ret = map_word_equal (map , d , t );
874842
875- oldd = map_read ( map , addr );
876- curd = map_read ( map , addr ) ;
843+ if (! ret || ! expected )
844+ return ret ;
877845
878- return map_word_equal (map , oldd , curd ) &&
879- map_word_equal (map , curd , expected );
846+ return map_word_equal (map , t , * expected );
880847}
881848
882849static int get_chip (struct map_info * map , struct flchip * chip , unsigned long adr , int mode )
@@ -893,7 +860,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
893860
894861 case FL_STATUS :
895862 for (;;) {
896- if (chip_ready (map , chip , adr ))
863+ if (chip_ready (map , chip , adr , NULL ))
897864 break ;
898865
899866 if (time_after (jiffies , timeo )) {
@@ -932,7 +899,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
932899 chip -> state = FL_ERASE_SUSPENDING ;
933900 chip -> erase_suspended = 1 ;
934901 for (;;) {
935- if (chip_ready (map , chip , adr ))
902+ if (chip_ready (map , chip , adr , NULL ))
936903 break ;
937904
938905 if (time_after (jiffies , timeo )) {
@@ -1463,7 +1430,7 @@ static int do_otp_lock(struct map_info *map, struct flchip *chip, loff_t adr,
14631430 /* wait for chip to become ready */
14641431 timeo = jiffies + msecs_to_jiffies (2 );
14651432 for (;;) {
1466- if (chip_ready (map , chip , adr ))
1433+ if (chip_ready (map , chip , adr , NULL ))
14671434 break ;
14681435
14691436 if (time_after (jiffies , timeo )) {
@@ -1695,19 +1662,19 @@ static int __xipram do_write_oneword_once(struct map_info *map,
16951662 }
16961663
16971664 /*
1698- * We check "time_after" and "!chip_good " before checking
1699- * "chip_good " to avoid the failure due to scheduling.
1665+ * We check "time_after" and "!chip_ready " before checking
1666+ * "chip_ready " to avoid the failure due to scheduling.
17001667 */
17011668 if (time_after (jiffies , timeo ) &&
1702- !chip_good (map , chip , adr , datum )) {
1669+ !chip_ready (map , chip , adr , & datum )) {
17031670 xip_enable (map , chip , adr );
17041671 printk (KERN_WARNING "MTD %s(): software timeout\n" , __func__ );
17051672 xip_disable (map , chip , adr );
17061673 ret = - EIO ;
17071674 break ;
17081675 }
17091676
1710- if (chip_good (map , chip , adr , datum )) {
1677+ if (chip_ready (map , chip , adr , & datum )) {
17111678 if (cfi_check_err_status (map , chip , adr ))
17121679 ret = - EIO ;
17131680 break ;
@@ -1975,18 +1942,18 @@ static int __xipram do_write_buffer_wait(struct map_info *map,
19751942 }
19761943
19771944 /*
1978- * We check "time_after" and "!chip_good " before checking
1979- * "chip_good " to avoid the failure due to scheduling.
1945+ * We check "time_after" and "!chip_ready " before checking
1946+ * "chip_ready " to avoid the failure due to scheduling.
19801947 */
19811948 if (time_after (jiffies , timeo ) &&
1982- !chip_good (map , chip , adr , datum )) {
1949+ !chip_ready (map , chip , adr , & datum )) {
19831950 pr_err ("MTD %s(): software timeout, address:0x%.8lx.\n" ,
19841951 __func__ , adr );
19851952 ret = - EIO ;
19861953 break ;
19871954 }
19881955
1989- if (chip_good (map , chip , adr , datum )) {
1956+ if (chip_ready (map , chip , adr , & datum )) {
19901957 if (cfi_check_err_status (map , chip , adr ))
19911958 ret = - EIO ;
19921959 break ;
@@ -2195,7 +2162,7 @@ static int cfi_amdstd_panic_wait(struct map_info *map, struct flchip *chip,
21952162 * If the driver thinks the chip is idle, and no toggle bits
21962163 * are changing, then the chip is actually idle for sure.
21972164 */
2198- if (chip -> state == FL_READY && chip_ready (map , chip , adr ))
2165+ if (chip -> state == FL_READY && chip_ready (map , chip , adr , NULL ))
21992166 return 0 ;
22002167
22012168 /*
@@ -2212,7 +2179,7 @@ static int cfi_amdstd_panic_wait(struct map_info *map, struct flchip *chip,
22122179
22132180 /* wait for the chip to become ready */
22142181 for (i = 0 ; i < jiffies_to_usecs (timeo ); i ++ ) {
2215- if (chip_ready (map , chip , adr ))
2182+ if (chip_ready (map , chip , adr , NULL ))
22162183 return 0 ;
22172184
22182185 udelay (1 );
@@ -2276,13 +2243,13 @@ static int do_panic_write_oneword(struct map_info *map, struct flchip *chip,
22762243 map_write (map , datum , adr );
22772244
22782245 for (i = 0 ; i < jiffies_to_usecs (uWriteTimeout ); i ++ ) {
2279- if (chip_ready (map , chip , adr ))
2246+ if (chip_ready (map , chip , adr , NULL ))
22802247 break ;
22812248
22822249 udelay (1 );
22832250 }
22842251
2285- if (!chip_good (map , chip , adr , datum ) ||
2252+ if (!chip_ready (map , chip , adr , & datum ) ||
22862253 cfi_check_err_status (map , chip , adr )) {
22872254 /* reset on all failures. */
22882255 map_write (map , CMD (0xF0 ), chip -> start );
@@ -2424,6 +2391,7 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip)
24242391 DECLARE_WAITQUEUE (wait , current );
24252392 int ret ;
24262393 int retry_cnt = 0 ;
2394+ map_word datum = map_word_ff (map );
24272395
24282396 adr = cfi -> addr_unlock1 ;
24292397
@@ -2478,7 +2446,7 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip)
24782446 chip -> erase_suspended = 0 ;
24792447 }
24802448
2481- if (chip_good (map , chip , adr , map_word_ff ( map ) )) {
2449+ if (chip_ready (map , chip , adr , & datum )) {
24822450 if (cfi_check_err_status (map , chip , adr ))
24832451 ret = - EIO ;
24842452 break ;
@@ -2523,6 +2491,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
25232491 DECLARE_WAITQUEUE (wait , current );
25242492 int ret ;
25252493 int retry_cnt = 0 ;
2494+ map_word datum = map_word_ff (map );
25262495
25272496 adr += chip -> start ;
25282497
@@ -2577,7 +2546,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
25772546 chip -> erase_suspended = 0 ;
25782547 }
25792548
2580- if (chip_good (map , chip , adr , map_word_ff ( map ) )) {
2549+ if (chip_ready (map , chip , adr , & datum )) {
25812550 if (cfi_check_err_status (map , chip , adr ))
25822551 ret = - EIO ;
25832552 break ;
@@ -2771,7 +2740,7 @@ static int __maybe_unused do_ppb_xxlock(struct map_info *map,
27712740 */
27722741 timeo = jiffies + msecs_to_jiffies (2000 ); /* 2s max (un)locking */
27732742 for (;;) {
2774- if (chip_ready (map , chip , adr ))
2743+ if (chip_ready (map , chip , adr , NULL ))
27752744 break ;
27762745
27772746 if (time_after (jiffies , timeo )) {
0 commit comments