Changeset 1546


Ignore:
Timestamp:
Jun 19, 2012 2:06:53 PM (11 months ago)
Author:
hailfinger
Message:

Add native SPI AAI write support to the Dediprog SF100 driver

To tell the programmer how to handle the data on the spi bus, a flag in
the fourth byte sent with the usb command is used. The second word was
mistaken for the size of the chunks sent over usb earlier. The third
byte (first of the second word) is now set to zero. This also adds some
checks for the size of data chunks sent over usb.

Signed-off-by: Nico Huber <nico.huber@…>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dediprog.c

    r1544 r1546  
    3232static int dediprog_endpoint; 
    3333 
     34#define DEDI_SPI_CMD_PAGEWRITE  0x1 
     35#define DEDI_SPI_CMD_AAIWRITE   0x4 
     36 
    3437#if 0 
    3538/* Might be useful for other pieces of code as well. */ 
     
    308311} 
    309312 
    310 /* Bulk write interface, will write multiple page_size byte chunks aligned to page_size bytes. 
    311  * @start       start address 
    312  * @len         length 
    313  * @return      0 on success, 1 on failure 
    314  */ 
    315 static int dediprog_spi_bulk_write(struct flashctx *flash, uint8_t *buf, 
    316                                    unsigned int start, unsigned int len) 
     313/* Bulk write interface, will write multiple chunksize byte chunks aligned to chunksize bytes. 
     314 * @chunksize       length of data chunks, only 256 supported by now 
     315 * @start           start address 
     316 * @len             length 
     317 * @dedi_spi_cmd    dediprog specific write command for spi bus 
     318 * @return          0 on success, 1 on failure 
     319 */ 
     320static int dediprog_spi_bulk_write(struct flashctx *flash, uint8_t *buf, unsigned int chunksize, 
     321                                   unsigned int start, unsigned int len, uint8_t dedi_spi_cmd) 
    317322{ 
    318323        int ret; 
     
    322327         * space in a USB bulk transfer must be filled with 0xff padding. 
    323328         */ 
    324         const unsigned int chunksize = flash->page_size; 
    325329        const unsigned int count = len / chunksize; 
    326         const char count_and_chunk[] = {count & 0xff, 
    327                                         (count >> 8) & 0xff, 
    328                                         chunksize & 0xff, 
    329                                         (chunksize >> 8) & 0xff}; 
     330        const char count_and_cmd[] = {count & 0xff, (count >> 8) & 0xff, 0x00, dedi_spi_cmd}; 
    330331        char usbbuf[512]; 
     332 
     333        /* 
     334         * We should change this check to 
     335         *   chunksize > 512 
     336         * once we know how to handle different chunk sizes. 
     337         */ 
     338        if (chunksize != 256) { 
     339                msg_perr("%s: Chunk sizes other than 256 bytes are unsupported, chunksize=%u!\n" 
     340                         "Please report a bug at flashrom@flashrom.org\n", __func__, chunksize); 
     341                return 1; 
     342        } 
    331343 
    332344        if ((start % chunksize) || (len % chunksize)) { 
     
    342354         * SPI side. 
    343355         */ 
    344         ret = usb_control_msg(dediprog_handle, 0x42, 0x30, start % 0x10000, 
    345                               start / 0x10000, (char *)count_and_chunk, 
    346                               sizeof(count_and_chunk), DEFAULT_TIMEOUT); 
    347         if (ret != sizeof(count_and_chunk)) { 
     356        ret = usb_control_msg(dediprog_handle, 0x42, 0x30, start % 0x10000, start / 0x10000, 
     357                              (char *)count_and_cmd, sizeof(count_and_cmd), DEFAULT_TIMEOUT); 
     358        if (ret != sizeof(count_and_cmd)) { 
    348359                msg_perr("Command Write SPI Bulk failed, %i %s!\n", ret, 
    349360                         usb_strerror()); 
     
    367378} 
    368379 
    369 static int dediprog_spi_write_256(struct flashctx *flash, uint8_t *buf, 
    370                                   unsigned int start, unsigned int len) 
     380static int dediprog_spi_write(struct flashctx *flash, uint8_t *buf, 
     381                              unsigned int start, unsigned int len, uint8_t dedi_spi_cmd) 
    371382{ 
    372383        int ret; 
     
    376387 
    377388        dediprog_set_leds(PASS_OFF|BUSY_ON|ERROR_OFF); 
     389 
     390        if (chunksize != 256) { 
     391                msg_pdbg("Page sizes other than 256 bytes are unsupported as " 
     392                         "we don't know how dediprog\nhandles them.\n"); 
     393                /* Write everything like it was residue. */ 
     394                residue = len; 
     395        } 
    378396 
    379397        if (residue) { 
     
    390408        /* Round down. */ 
    391409        bulklen = (len - residue) / chunksize * chunksize; 
    392         ret = dediprog_spi_bulk_write(flash, buf + residue, start + residue, 
    393                                      bulklen); 
     410        ret = dediprog_spi_bulk_write(flash, buf + residue, chunksize, start + residue, bulklen, dedi_spi_cmd); 
    394411        if (ret) { 
    395412                dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); 
     
    411428        dediprog_set_leds(PASS_ON|BUSY_OFF|ERROR_OFF); 
    412429        return 0; 
     430} 
     431 
     432static int dediprog_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) 
     433{ 
     434        return dediprog_spi_write(flash, buf, start, len, DEDI_SPI_CMD_PAGEWRITE); 
     435} 
     436 
     437static int dediprog_spi_write_aai(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) 
     438{ 
     439        return dediprog_spi_write(flash, buf, start, len, DEDI_SPI_CMD_AAIWRITE); 
    413440} 
    414441 
     
    718745        .read           = dediprog_spi_read, 
    719746        .write_256      = dediprog_spi_write_256, 
    720         .write_aai      = default_spi_write_aai, 
     747        .write_aai      = dediprog_spi_write_aai, 
    721748}; 
    722749 
Note: See TracChangeset for help on using the changeset viewer.