Changeset 3398

Show
Ignore:
Timestamp:
06/30/08 23:38:30 (3 months ago)
Author:
ruik
Message:

This patch adds support for VIA SPI controller on VT8237S. It is similar with
few documented exceptions to ICH7 SPI controller.

Signed-off-by: Rudolf Marek <r.marek@…>
Acked-by: Peter Stuge <peter@…>

Location:
trunk/util/flashrom
Files:
4 modified

Legend:

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

    r3395 r3398  
    188188void *ich_spibar = NULL; 
    189189 
     190static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name) { 
     191        uint32_t mmio_base; 
     192 
     193        mmio_base = (pci_read_long(dev, 0xbc)) << 8; 
     194        printf_debug("MMIO base at = 0x%x\n", mmio_base); 
     195        ich_spibar =  mmap(NULL, 0x70, PROT_READ | PROT_WRITE, MAP_SHARED, 
     196                                fd_mem, mmio_base); 
     197 
     198        if (ich_spibar == MAP_FAILED) { 
     199                perror("Can't mmap memory using " MEM_DEV); 
     200                exit(1); 
     201        } 
     202 
     203        printf_debug("0x6c: 0x%04x     (CLOCK/DEBUG)\n", *(uint16_t *)(ich_spibar + 0x6c)); 
     204        viaspi_detected = 1; 
     205        return 0; 
     206} 
     207 
    190208static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, unsigned long spibar) 
    191209{ 
     
    271289/* Flag for ICH7 SPI register block */ 
    272290int ich7_detected = 0; 
     291int viaspi_detected = 0; 
    273292 
    274293static int enable_flash_ich7(struct pci_dev *dev, const char *name) 
     
    661680        {0x1106, 0x3177, "VIA VT8235",          enable_flash_vt823x}, 
    662681        {0x1106, 0x3227, "VIA VT8237",          enable_flash_vt823x}, 
     682        {0x1106, 0x3372, "VIA VT8237S",         enable_flash_vt8237s_spi}, 
    663683        {0x1106, 0x8324, "VIA CX700",           enable_flash_vt823x}, 
    664684        {0x1106, 0x0686, "VIA VT82C686",        enable_flash_amd8111}, 
  • trunk/util/flashrom/flash.h

    r3393 r3398  
    372372void print_supported_chipsets(void); 
    373373extern int ich7_detected; 
     374extern int viaspi_detected; 
    374375extern int ich9_detected; 
    375376extern void *ich_spibar; 
  • trunk/util/flashrom/ichspi.c

    r3397 r3398  
    4242#include "spi.h" 
    4343 
    44 #define MAXDATABYTES 0x40 
    45  
    4644/* ICH9 controller register definition */ 
    4745#define ICH9_REG_FADDR         0x08     /* 32 Bits */ 
     
    8280#define SPIS_FCERR             0x00000008 
    8381 
     82/* VIA SPI is compatible with ICH7, but maxdata 
     83   to transfer is 16 bytes. 
     84 
     85   DATA byte count on ICH7 is 8:13, on VIA 8:11 
     86 
     87   bit 12 is port select CS0 CS1 
     88   bit 13 is FAST READ enable 
     89   bit 7  is used with fast read and one shot controls CS de-assert? 
     90*/ 
     91 
    8492#define ICH7_REG_SPIC          0x02     /* 16 Bits */ 
    8593#define SPIC_SCGO              0x0002 
    8694#define SPIC_ACS               0x0004 
    8795#define SPIC_SPOP              0x0008 
    88 #define SPIC_DS                        0x4000 
     96#define SPIC_DS                0x4000 
    8997 
    9098#define ICH7_REG_SPIA          0x04     /* 32 Bits */ 
     
    144152                      uint8_t datalength, uint8_t * data); 
    145153static int ich_spi_read_page(struct flashchip *flash, uint8_t * buf, 
    146                              int offset); 
     154                             int offset, int maxdata); 
    147155static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes, 
    148                               int offset); 
     156                              int offset, int maxdata); 
    149157static int ich_spi_erase_block(struct flashchip *flash, int offset); 
    150158 
     
    177185        /* 8:16 Prefix Opcode 2 */ 
    178186        temp16 |= ((uint16_t) op->preop[1]) << 8; 
    179         if (ich7_detected) { 
     187        if ((ich7_detected) || (viaspi_detected)) { 
    180188                REGWRITE16(ICH7_REG_PREOP, temp16); 
    181189        } else if (ich9_detected) { 
     
    189197        } 
    190198 
    191         if (ich7_detected) { 
     199        if ((ich7_detected) || (viaspi_detected)) { 
    192200                REGWRITE16(ICH7_REG_OPTYPE, temp16); 
    193201        } else if (ich9_detected) { 
     
    202210        } 
    203211 
    204         if (ich7_detected) { 
     212        if ((ich7_detected) || (viaspi_detected)) { 
    205213                REGWRITE32(ICH7_REG_OPMENU, temp32); 
    206214        } else if (ich9_detected) { 
     
    216224        } 
    217225 
    218         if (ich7_detected) { 
     226        if ((ich7_detected) || (viaspi_detected)) { 
    219227                REGWRITE32(ICH7_REG_OPMENU + 4, temp32); 
    220228        } else if (ich9_detected) { 
     
    226234 
    227235static int ich7_run_opcode(uint8_t nr, OPCODE op, uint32_t offset, 
    228                            uint8_t datalength, uint8_t * data) 
     236                           uint8_t datalength, uint8_t * data, int maxdata) 
    229237{ 
    230238        int write_cmd = 0; 
     
    276284        if (datalength != 0) { 
    277285                temp16 |= SPIC_DS; 
    278                 temp16 |= ((uint16_t) ((datalength - 1) & 0x3f)) << 8; 
     286                temp16 |= ((uint32_t) ((datalength - 1) & (maxdata - 1))) << 8; 
    279287        } 
    280288 
     
    432440{ 
    433441        if (ich7_detected) 
    434                 return ich7_run_opcode(nr, op, offset, datalength, data); 
    435         else if (ich9_detected) { 
     442                return ich7_run_opcode(nr, op, offset, datalength, data, 64); 
     443        else if (viaspi_detected) 
     444                return ich7_run_opcode(nr, op, offset, datalength, data, 16); 
     445        else if (ich9_detected) 
    436446                return ich9_run_opcode(nr, op, offset, datalength, data); 
    437         } 
    438447 
    439448        /* If we ever get here, something really weird happened */ 
     
    456465} 
    457466 
    458 static int ich_spi_read_page(struct flashchip *flash, uint8_t * buf, int offset) 
     467static int ich_spi_read_page(struct flashchip *flash, uint8_t * buf, int offset, int maxdata) 
    459468{ 
    460469        int page_size = flash->page_size; 
     
    465474                     offset, page_size, buf); 
    466475 
    467         for (a = 0; a < page_size; a += MAXDATABYTES) { 
    468                 if (remaining < MAXDATABYTES) { 
     476        for (a = 0; a < page_size; a += maxdata) { 
     477                if (remaining < maxdata) { 
    469478 
    470479                        if (run_opcode 
     
    479488                        if (run_opcode 
    480489                            (1, curopcodes->opcode[1], 
    481                              offset + (page_size - remaining), MAXDATABYTES, 
     490                             offset + (page_size - remaining), maxdata, 
    482491                             &buf[page_size - remaining]) != 0) { 
    483492                                printf_debug("Error reading"); 
    484493                                return 1; 
    485494                        } 
    486                         remaining -= MAXDATABYTES; 
     495                        remaining -= maxdata; 
    487496                } 
    488497        } 
     
    492501 
    493502static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes, 
    494                               int offset) 
     503                              int offset, int maxdata) 
    495504{ 
    496505        int page_size = flash->page_size; 
     
    501510                     offset, page_size, bytes); 
    502511 
    503         for (a = 0; a < page_size; a += MAXDATABYTES) { 
    504                 if (remaining < MAXDATABYTES) { 
     512        for (a = 0; a < page_size; a += maxdata) { 
     513                if (remaining < maxdata) { 
    505514                        if (run_opcode 
    506515                            (0, curopcodes->opcode[0], 
     
    514523                        if (run_opcode 
    515524                            (0, curopcodes->opcode[0], 
    516                              offset + (page_size - remaining), MAXDATABYTES, 
     525                             offset + (page_size - remaining), maxdata, 
    517526                             &bytes[page_size - remaining]) != 0) { 
    518527                                printf_debug("Error writing"); 
    519528                                return 1; 
    520529                        } 
    521                         remaining -= MAXDATABYTES; 
     530                        remaining -= maxdata; 
    522531                } 
    523532        } 
     
    531540        int total_size = flash->total_size * 1024; 
    532541        int page_size = flash->page_size; 
     542        int maxdata = 64; 
     543 
     544        if (viaspi_detected) { 
     545                maxdata = 16; 
     546        } 
    533547 
    534548        for (i = 0; (i < total_size / page_size) && (rc == 0); i++) { 
    535549                rc = ich_spi_read_page(flash, (void *)(buf + i * page_size), 
    536                                        i * page_size); 
     550                                       i * page_size, maxdata); 
    537551        } 
    538552 
     
    546560        int page_size = flash->page_size; 
    547561        int erase_size = 64 * 1024; 
     562        int maxdata = 64; 
    548563 
    549564        spi_disable_blockprotect(); 
     
    558573                } 
    559574 
     575        if (viaspi_detected) { 
     576                maxdata = 16; 
     577        } 
    560578                for (j = 0; j < erase_size / page_size; j++) { 
    561579                        ich_spi_write_page(flash, (void *)(buf + (i * erase_size) + (j * page_size)), 
    562                                            (i * erase_size) + (j * page_size)); 
     580                                           (i * erase_size) + (j * page_size), maxdata); 
    563581                } 
    564582        } 
  • trunk/util/flashrom/spi.c

    r3393 r3398  
    3737        if (it8716f_flashport) 
    3838                return it8716f_spi_command(writecnt, readcnt, writearr, readarr); 
    39        else if (ich7_detected) 
    40                return ich_spi_command(writecnt, readcnt, writearr, readarr); 
     39        else if ((ich7_detected) || (viaspi_detected)) 
     40                return ich_spi_command(writecnt, readcnt, writearr, readarr); 
    4141        else if (ich9_detected) 
    4242                return ich_spi_command(writecnt, readcnt, writearr, readarr); 
     
    361361        if (it8716f_flashport) 
    362362                return it8716f_spi_chip_read(flash, buf); 
    363        else if (ich7_detected) 
    364                return ich_spi_read(flash, buf); 
     363        else if ((ich7_detected) || (viaspi_detected)) 
     364                return ich_spi_read(flash, buf); 
    365365        else if (ich9_detected) 
    366366                return ich_spi_read(flash, buf); 
     
    373373        if (it8716f_flashport) 
    374374                return it8716f_spi_chip_write(flash, buf); 
    375        else if (ich7_detected) 
    376                return ich_spi_write(flash, buf); 
     375        else if ((ich7_detected) || (viaspi_detected)) 
     376                return ich_spi_write(flash, buf); 
    377377        else if (ich9_detected) 
    378378                return ich_spi_write(flash, buf);