mtd/drivers/mtd/chips cfi_cmdset_0002.c,1.56,1.57
David Woodhouse
dwmw2 at infradead.org
Wed Aug 7 07:10:52 EDT 2002
Update of /home/cvs/mtd/drivers/mtd/chips
In directory phoenix.infradead.org:/tmp/cvs-serv29754
Modified Files:
cfi_cmdset_0002.c
Log Message:
Cosmetics and yield while waiting for write.
Index: cfi_cmdset_0002.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/chips/cfi_cmdset_0002.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- cfi_cmdset_0002.c 15 Jul 2002 15:13:25 -0000 1.56
+++ cfi_cmdset_0002.c 7 Aug 2002 11:10:49 -0000 1.57
@@ -340,8 +340,8 @@
static int do_write_oneword(struct map_info *map, struct flchip *chip, unsigned long adr, __u32 datum, int fast)
{
unsigned long timeo = jiffies + HZ;
- unsigned int oldstatus, status;
- unsigned int dq6, dq5;
+ unsigned int oldstatus, status;
+ unsigned int dq6, dq5;
unsigned long Count = 0;
struct cfi_private *cfi = map->fldrv_priv;
DECLARE_WAITQUEUE(wait, current);
@@ -350,7 +350,7 @@
retry:
cfi_spin_lock(chip->mutex);
- if (chip->state != FL_READY){
+ if (chip->state != FL_READY) {
#if 0
printk(KERN_DEBUG "Waiting for chip to write, status = %d\n", chip->state);
#endif
@@ -390,64 +390,63 @@
cfi_udelay(chip->word_write_time);
cfi_spin_lock(chip->mutex);
-
/* Polling toggle bits instead of reading back many times
- This ensures that write operation is really completed,
- or tells us why it failed. */
- dq6 = CMD(1<<6);
- dq5 = CMD(1<<5);
- timeo = jiffies + ( HZ / 1000 ); /* setting timeout to 1ms for now */
+ This ensures that write operation is really completed,
+ or tells us why it failed. */
+ dq6 = CMD(1<<6);
+ dq5 = CMD(1<<5);
+ timeo = jiffies + (HZ/1000); /* setting timeout to 1ms for now */
- oldstatus = cfi_read(map, adr);
- status = cfi_read(map, adr);
- while(
- ( (status & dq6) != (oldstatus & dq6) ) &&
- ( (status & dq5) != dq5 ) &&
- !time_after( jiffies, timeo )
- )
- {
- oldstatus = cfi_read( map, adr );
- status = cfi_read( map, adr );
- udelay(1);
+ oldstatus = cfi_read(map, adr);
+ status = cfi_read(map, adr);
+
+ while( (status & dq6) != (oldstatus & dq6) &&
+ (status & dq5) != dq5 &&
+ !time_after(jiffies, timeo) ) {
+
+ if (need_resched()) {
+ cfi_spin_unlock(chip->mutex);
+ yield();
+ cfi_spin_lock(chip->mutex);
+ } else
+ udelay(1);
+
+ oldstatus = cfi_read( map, adr );
+ status = cfi_read( map, adr );
}
- if( (status & dq6) != (oldstatus & dq6) )
- {
- /* The erasing didn't stop?? */
- if( ( status & dq5 ) == dq5 )
- {
- /* When DQ5 raises, we must check once again if DQ6 is toggling.
- If not, the erase has been completed OK. If not, reset chip. */
- oldstatus = cfi_read( map, adr );
- status = cfi_read( map, adr );
+ if( (status & dq6) != (oldstatus & dq6) ) {
+ /* The erasing didn't stop?? */
+ if( (status & dq5) == dq5 ) {
+ /* When DQ5 raises, we must check once again
+ if DQ6 is toggling. If not, the erase has been
+ completed OK. If not, reset chip. */
+ oldstatus = cfi_read(map, adr);
+ status = cfi_read(map, adr);
- if( ( oldstatus & 0x00FF ) == ( status & 0x00FF ) )
- {
- printk( "Warning: DQ5 raised while program operation was in progress, however operation completed OK\n" );
- }
- else
- {
- /* DQ5 is active so we can do a reset and stop the erase */
- cfi_write( map, CMD(0xF0), chip->start );
- printk( "Internal flash device timeout occured or write operation was performed while flash was programming.\n" );
- }
+ if ( (oldstatus & 0x00FF) == (status & 0x00FF) ) {
+ printk(KERN_WARNING "Warning: DQ5 raised while program operation was in progress, however operation completed OK\n" );
+ } else {
+ /* DQ5 is active so we can do a reset and stop the erase */
+ cfi_write(map, CMD(0xF0), chip->start);
+ printk(KERN_WARNING "Internal flash device timeout occurred or write operation was performed while flash was programming.\n" );
+ }
+ } else {
+ printk(KERN_WARNING "Waiting for write to complete timed out in do_write_oneword.");
+
+ chip->state = FL_READY;
+ wake_up(&chip->wq);
+ cfi_spin_unlock(chip->mutex);
+ DISABLE_VPP(map);
+ ret = -EIO;
}
- else
- {
- printk( "Waiting for write to complete timed out in do_write_oneword.");
-
- chip->state = FL_READY;
- wake_up(&chip->wq);
- cfi_spin_unlock(chip->mutex);
- DISABLE_VPP(map);
- ret = -EIO;
- }
}
+
DISABLE_VPP(map);
chip->state = FL_READY;
wake_up(&chip->wq);
cfi_spin_unlock(chip->mutex);
-
+
return ret;
}
@@ -567,6 +566,7 @@
cfi_send_gen_cmd(0x00, 0, chipstart, map, cfi, cfi->device_type, NULL);
}
+ /* Write the trailing bytes if any */
if (len & (CFIDEV_BUSWIDTH-1)) {
int i = 0, n = 0;
u_char tmp_buf[4];
@@ -718,8 +718,8 @@
chip->state = FL_READY;
wake_up(&chip->wq);
cfi_spin_unlock(chip->mutex);
+
return 0;
-
}
static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, unsigned long adr)
More information about the linux-mtd-cvs
mailing list