Changeset 1201


Ignore:
Timestamp:
Oct 8, 2010 2:37:55 AM (3 years ago)
Author:
hailfinger
Message:

SPI write status register (WRSR) may take longer than 100 ms, and it
makes sense to poll for completion in 10 ms steps until 5 s are over.
This patch complements r1115.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>
Acked-by: Joshua Roys <roysjosh@…>

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/flash.h

    r1199 r1201  
    3535 
    3636#define ERROR_PTR ((void*)-1) 
     37 
     38/* Error codes */ 
     39#define TIMEOUT_ERROR   -101 
    3740 
    3841typedef unsigned long chipaddr; 
  • trunk/spi25.c

    r1194 r1201  
    857857{ 
    858858        int result; 
     859        int i = 0; 
    859860        struct spi_command cmds[] = { 
    860861        { 
     
    880881                msg_cerr("%s failed during command execution\n", 
    881882                        __func__); 
    882         } 
    883         /* WRSR performs a self-timed erase before the changes take effect. */ 
     883                /* No point in waiting for the command to complete if execution 
     884                 * failed. 
     885                 */ 
     886                return result; 
     887        } 
     888        /* WRSR performs a self-timed erase before the changes take effect. 
     889         * This may take 50-85 ms in most cases, and some chips apparently 
     890         * allow running RDSR only once. Therefore pick an initial delay of 
     891         * 100 ms, then wait in 10 ms steps until a total of 5 s have elapsed. 
     892         */ 
    884893        programmer_delay(100 * 1000); 
    885         return result; 
     894        while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) { 
     895                if (++i > 490) { 
     896                        msg_cerr("Error: WIP bit after WRSR never cleared\n"); 
     897                        return TIMEOUT_ERROR; 
     898                } 
     899                programmer_delay(10 * 1000); 
     900        } 
     901        return 0; 
    886902} 
    887903 
     
    889905{ 
    890906        int result; 
     907        int i = 0; 
    891908        struct spi_command cmds[] = { 
    892909        { 
     
    912929                msg_cerr("%s failed during command execution\n", 
    913930                        __func__); 
    914         } 
    915         /* WRSR performs a self-timed erase before the changes take effect. */ 
     931                /* No point in waiting for the command to complete if execution 
     932                 * failed. 
     933                 */ 
     934                return result; 
     935        } 
     936        /* WRSR performs a self-timed erase before the changes take effect. 
     937         * This may take 50-85 ms in most cases, and some chips apparently 
     938         * allow running RDSR only once. Therefore pick an initial delay of 
     939         * 100 ms, then wait in 10 ms steps until a total of 5 s have elapsed. 
     940         */ 
    916941        programmer_delay(100 * 1000); 
    917         return result; 
     942        while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) { 
     943                if (++i > 490) { 
     944                        msg_cerr("Error: WIP bit after WRSR never cleared\n"); 
     945                        return TIMEOUT_ERROR; 
     946                } 
     947                programmer_delay(10 * 1000); 
     948        } 
     949        return 0; 
    918950} 
    919951 
Note: See TracChangeset for help on using the changeset viewer.