Show
Ignore:
Timestamp:
07/01/08 01:45:22 (5 months ago)
Author:
stepan
Message:

First attempt to clean up SPI probing and create a common
construct: the flash bus.

At some point the flash bus will be part of struct flashchip.

Pardon me for pushing this in, but I think it is important to beware of further
decay and it will improve things for other developers in the short run.

Carl-Daniel, I will consider your suggestions in another patch. I want to keep
things from getting too much for now. The patch includes Rudolf's VIA SPI
changes though.

Signed-off-by: Stefan Reinauer <stepan@…>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/util/flashrom/spi.c

    r3399 r3401  
    3535int spi_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr) 
    3636{ 
    37         if (it8716f_flashport) 
     37        switch (flashbus) { 
     38        case BUS_TYPE_IT87XX_SPI: 
    3839                return it8716f_spi_command(writecnt, readcnt, writearr, readarr); 
    39         else if ((ich7_detected) || (viaspi_detected)) 
    40                 return ich_spi_command(writecnt, readcnt, writearr, readarr); 
    41         else if (ich9_detected) 
    42                 return ich_spi_command(writecnt, readcnt, writearr, readarr); 
    43         printf_debug("%s called, but no SPI chipset detected\n", __FUNCTION__); 
     40        case BUS_TYPE_ICH7_SPI: 
     41        case BUS_TYPE_ICH9_SPI: 
     42        case BUS_TYPE_VIA_SPI: 
     43               return ich_spi_command(writecnt, readcnt, writearr, readarr); 
     44        default: 
     45                printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__); 
     46        } 
    4447        return 1; 
    4548} 
     
    136139 
    137140        /* only some SPI chipsets support 4 bytes commands */ 
    138         if (!((ich7_detected) || (ich9_detected) || (viaspi_detected))) 
    139                 return 0; 
    140         return probe_spi_rdid_generic(flash, 4); 
     141        switch (flashbus) { 
     142        case BUS_TYPE_ICH7_SPI: 
     143        case BUS_TYPE_ICH9_SPI: 
     144        case BUS_TYPE_VIA_SPI: 
     145                return probe_spi_rdid_generic(flash, 4); 
     146        default: 
     147                printf_debug("4b ID not supported on this SPI controller\n"); 
     148        } 
     149 
     150        return 0; 
    141151} 
    142152 
     
    317327void spi_page_program(int block, uint8_t *buf, uint8_t *bios) 
    318328{ 
    319         if (it8716f_flashport) { 
     329        switch (flashbus) { 
     330        case BUS_TYPE_IT87XX_SPI: 
    320331                it8716f_spi_page_program(block, buf, bios); 
    321                 return; 
    322         } 
    323         printf_debug("%s called, but no SPI chipset detected\n", __FUNCTION__); 
     332                break; 
     333        case BUS_TYPE_ICH7_SPI: 
     334        case BUS_TYPE_ICH9_SPI: 
     335                printf_debug("%s called, but not implemented for ICH\n", __FUNCTION__); 
     336                break; 
     337        default: 
     338                printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__); 
     339        } 
    324340} 
    325341 
     
    376392int spi_chip_read(struct flashchip *flash, uint8_t *buf) 
    377393{ 
    378         if (it8716f_flashport) 
     394 
     395        switch (flashbus) { 
     396        case BUS_TYPE_IT87XX_SPI: 
    379397                return it8716f_spi_chip_read(flash, buf); 
    380         else if ((ich7_detected) || (viaspi_detected)) 
     398        case BUS_TYPE_ICH7_SPI: 
     399        case BUS_TYPE_ICH9_SPI: 
     400        case BUS_TYPE_VIA_SPI: 
    381401                return ich_spi_read(flash, buf); 
    382         else if (ich9_detected) 
    383                 return ich_spi_read(flash, buf); 
    384         printf_debug("%s called, but no SPI chipset detected\n", __FUNCTION__); 
     402        default: 
     403                printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__); 
     404        } 
     405 
    385406        return 1; 
    386407} 
     
    388409int spi_chip_write(struct flashchip *flash, uint8_t *buf) 
    389410{ 
    390         if (it8716f_flashport) 
     411        switch (flashbus) { 
     412        case BUS_TYPE_IT87XX_SPI: 
    391413                return it8716f_spi_chip_write(flash, buf); 
    392         else if ((ich7_detected) || (viaspi_detected)) 
     414        case BUS_TYPE_ICH7_SPI: 
     415        case BUS_TYPE_ICH9_SPI: 
     416        case BUS_TYPE_VIA_SPI: 
    393417                return ich_spi_write(flash, buf); 
    394         else if (ich9_detected) 
    395                 return ich_spi_write(flash, buf); 
    396         printf_debug("%s called, but no SPI chipset detected\n", __FUNCTION__); 
     418        default: 
     419                printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__); 
     420        } 
     421 
    397422        return 1; 
    398423}