Changeset 727


Ignore:
Timestamp:
09/18/09 17:50:56 (3 years ago)
Author:
hailfinger
Message:

The current ICH SPI preop handling is a hack which spews lots of
warnings, but still yields correct results.
With the multicommand infrastructure I introduced in r645, it became
possible to integrate ICH SPI preopcodes cleanly into the flashrom
design.

The new code checks for every opcode in a multicommand array if it is a
preopcode. If yes, it checks if the next opcode is associated with that
preopcode and in that case it simply runs the opcode because the correct
preopcode will be run automatically before the opcode.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>
Acked-by: FENG Yu Ning <fengyuning1984@…>

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/flash.h

    r724 r727  
    499499        int (*command)(unsigned int writecnt, unsigned int readcnt, 
    500500                   const unsigned char *writearr, unsigned char *readarr); 
    501         int (*multicommand)(struct spi_command *spicommands); 
     501        int (*multicommand)(struct spi_command *cmds); 
    502502 
    503503        /* Optimized functions for this programmer */ 
     
    515515int spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    516516                const unsigned char *writearr, unsigned char *readarr); 
    517 int spi_send_multicommand(struct spi_command *spicommands); 
     517int spi_send_multicommand(struct spi_command *cmds); 
    518518int spi_write_enable(void); 
    519519int spi_write_disable(void); 
     
    540540int default_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    541541                             const unsigned char *writearr, unsigned char *readarr); 
    542 int default_spi_send_multicommand(struct spi_command *spicommands); 
     542int default_spi_send_multicommand(struct spi_command *cmds); 
    543543 
    544544/* 82802ab.c */ 
     
    566566int ich_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len); 
    567567int ich_spi_write_256(struct flashchip *flash, uint8_t * buf); 
    568 int ich_spi_send_multicommand(struct spi_command *spicommands); 
     568int ich_spi_send_multicommand(struct spi_command *cmds); 
    569569 
    570570/* it87spi.c */ 
  • trunk/ichspi.c

    r711 r727  
    743743} 
    744744 
    745 int ich_spi_send_multicommand(struct spi_command *spicommands) 
     745int ich_spi_send_multicommand(struct spi_command *cmds) 
    746746{ 
    747747        int ret = 0; 
    748         while ((spicommands->writecnt || spicommands->readcnt) && !ret) { 
    749                 ret = ich_spi_send_command(spicommands->writecnt, spicommands->readcnt, 
    750                                            spicommands->writearr, spicommands->readarr); 
    751                 /* This awful hack needs to be smarter. 
    752                  */ 
    753                 if ((ret == SPI_INVALID_OPCODE) && 
    754                     ((spicommands->writearr[0] == JEDEC_WREN) || 
    755                      (spicommands->writearr[0] == JEDEC_EWSR))) { 
    756                         printf_debug(" due to SPI master limitation, ignoring" 
    757                                      " and hoping it will be run as PREOP\n"); 
    758                         ret = 0; 
    759                 } 
    760                 spicommands++; 
     748        int oppos, preoppos; 
     749        for (; (cmds->writecnt || cmds->readcnt) && !ret; cmds++) { 
     750                /* Is the next command valid or a terminator? */ 
     751                if ((cmds + 1)->writecnt || (cmds + 1)->readcnt) { 
     752                        preoppos = find_preop(curopcodes, cmds->writearr[0]); 
     753                        oppos = find_opcode(curopcodes, (cmds + 1)->writearr[0]); 
     754                        /* Is the opcode of the current command listed in the 
     755                         * ICH struct OPCODES as associated preopcode for the 
     756                         * opcode of the next command? 
     757                         */ 
     758                        if ((oppos != -1) && (preoppos != -1) && 
     759                            (curopcodes->opcode[oppos].atomic - 1 == preoppos)) { 
     760                                printf_debug("opcode 0x%02x will be run as PREOP\n", 
     761                                             cmds->writearr[0]); 
     762                                continue; 
     763                        } 
     764                }        
     765                         
     766                ret = ich_spi_send_command(cmds->writecnt, cmds->readcnt, 
     767                                           cmds->writearr, cmds->readarr); 
    761768        } 
    762769        return ret; 
  • trunk/spi.c

    r724 r727  
    119119} 
    120120 
    121 int spi_send_multicommand(struct spi_command *spicommands) 
     121int spi_send_multicommand(struct spi_command *cmds) 
    122122{ 
    123123        if (!spi_programmer[spi_controller].multicommand) { 
     
    127127        } 
    128128 
    129         return spi_programmer[spi_controller].multicommand(spicommands); 
     129        return spi_programmer[spi_controller].multicommand(cmds); 
    130130} 
    131131 
     
    149149} 
    150150 
    151 int default_spi_send_multicommand(struct spi_command *spicommands) 
     151int default_spi_send_multicommand(struct spi_command *cmds) 
    152152{ 
    153153        int result = 0; 
    154         while ((spicommands->writecnt || spicommands->readcnt) && !result) { 
    155                 result = spi_send_command(spicommands->writecnt, spicommands->readcnt, 
    156                                           spicommands->writearr, spicommands->readarr); 
    157                 spicommands++; 
     154        for (; (cmds->writecnt || cmds->readcnt) && !result; cmds++) { 
     155                result = spi_send_command(cmds->writecnt, cmds->readcnt, 
     156                                          cmds->writearr, cmds->readarr); 
    158157        } 
    159158        return result; 
     
    495494{ 
    496495        int result; 
    497         struct spi_command spicommands[] = { 
     496        struct spi_command cmds[] = { 
    498497        { 
    499498                .writecnt       = JEDEC_WREN_OUTSIZE, 
     
    519518        } 
    520519         
    521         result = spi_send_multicommand(spicommands); 
     520        result = spi_send_multicommand(cmds); 
    522521        if (result) { 
    523522                fprintf(stderr, "%s failed during command execution\n", 
     
    541540{ 
    542541        int result; 
    543         struct spi_command spicommands[] = { 
     542        struct spi_command cmds[] = { 
    544543        { 
    545544                .writecnt       = JEDEC_WREN_OUTSIZE, 
     
    565564        } 
    566565 
    567         result = spi_send_multicommand(spicommands); 
     566        result = spi_send_multicommand(cmds); 
    568567        if (result) { 
    569568                fprintf(stderr, "%s failed during command execution\n", __func__); 
     
    597596{ 
    598597        int result; 
    599         struct spi_command spicommands[] = { 
     598        struct spi_command cmds[] = { 
    600599        { 
    601600                .writecnt       = JEDEC_WREN_OUTSIZE, 
     
    615614        }}; 
    616615 
    617         result = spi_send_multicommand(spicommands); 
     616        result = spi_send_multicommand(cmds); 
    618617        if (result) { 
    619618                fprintf(stderr, "%s failed during command execution\n", 
     
    641640{ 
    642641        int result; 
    643         struct spi_command spicommands[] = { 
     642        struct spi_command cmds[] = { 
    644643        { 
    645644                .writecnt       = JEDEC_WREN_OUTSIZE, 
     
    659658        }}; 
    660659 
    661         result = spi_send_multicommand(spicommands); 
     660        result = spi_send_multicommand(cmds); 
    662661        if (result) { 
    663662                fprintf(stderr, "%s failed during command execution\n", __func__); 
     
    703702{ 
    704703        int result; 
    705         struct spi_command spicommands[] = { 
     704        struct spi_command cmds[] = { 
    706705        { 
    707706                .writecnt       = JEDEC_WREN_OUTSIZE, 
     
    721720        }}; 
    722721 
    723         result = spi_send_multicommand(spicommands); 
     722        result = spi_send_multicommand(cmds); 
    724723        if (result) { 
    725724                fprintf(stderr, "%s failed during command execution\n", 
     
    780779{ 
    781780        int result; 
    782         struct spi_command spicommands[] = { 
     781        struct spi_command cmds[] = { 
    783782        { 
    784783                .writecnt       = JEDEC_EWSR_OUTSIZE, 
     
    798797        }}; 
    799798 
    800         result = spi_send_multicommand(spicommands); 
     799        result = spi_send_multicommand(cmds); 
    801800        if (result) { 
    802801                fprintf(stderr, "%s failed during command execution\n", 
     
    809808{ 
    810809        int result; 
    811         struct spi_command spicommands[] = { 
     810        struct spi_command cmds[] = { 
    812811        { 
    813812                .writecnt       = JEDEC_WREN_OUTSIZE, 
     
    827826        }}; 
    828827 
    829         result = spi_send_multicommand(spicommands); 
     828        result = spi_send_multicommand(cmds); 
    830829        if (result) { 
    831830                fprintf(stderr, "%s failed during command execution\n", 
     
    845844                (address >> 0) & 0xff, 
    846845        }; 
    847         struct spi_command spicommands[] = { 
     846        struct spi_command cmds[] = { 
    848847        { 
    849848                .writecnt       = JEDEC_WREN_OUTSIZE, 
     
    874873        memcpy(&cmd[4], bytes, len); 
    875874 
    876         result = spi_send_multicommand(spicommands); 
     875        result = spi_send_multicommand(cmds); 
    877876        if (result) { 
    878877                fprintf(stderr, "%s failed during command execution\n", 
Note: See TracChangeset for help on using the changeset viewer.