Changeset 3401

Show
Ignore:
Timestamp:
07/01/08 01:45:22 (3 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@…>

Location:
trunk/util/flashrom
Files:
5 modified

Legend:

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

    r3398 r3401  
    3636#include "flash.h" 
    3737 
     38/** 
     39 * flashrom defaults to LPC flash devices. If a known SPI controller is found 
     40 * and the SPI strappings are set, this will be overwritten by the probing code. 
     41 * 
     42 * Eventually, this will become an array when multiple flash support works. 
     43 */ 
     44 
     45flashbus_t flashbus = BUS_TYPE_LPC; 
     46void *spibar = NULL; 
     47 
     48 
    3849static int enable_flash_ali_m1533(struct pci_dev *dev, const char *name) 
    3950{ 
     
    125136         * Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable). 
    126137         */ 
    127         new = old | 0x2c4; 
     138        new = old | 0x02c4; 
    128139 
    129140        if (new == old) 
     
    186197} 
    187198 
    188 void *ich_spibar = NULL; 
     199#define ICH_STRAP_RSVD 0x00 
     200#define ICH_STRAP_SPI  0x01 
     201#define ICH_STRAP_PCI  0x02 
     202#define ICH_STRAP_LPC  0x03 
    189203 
    190204static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name) { 
     
    193207        mmio_base = (pci_read_long(dev, 0xbc)) << 8; 
    194208        printf_debug("MMIO base at = 0x%x\n", mmio_base); 
    195         ich_spibar =  mmap(NULL, 0x70, PROT_READ | PROT_WRITE, MAP_SHARED, 
     209        spibar =  mmap(NULL, 0x70, PROT_READ | PROT_WRITE, MAP_SHARED, 
    196210                                fd_mem, mmio_base); 
    197211 
    198         if (ich_spibar == MAP_FAILED) { 
     212        if (spibar == MAP_FAILED) { 
    199213                perror("Can't mmap memory using " MEM_DEV); 
    200214                exit(1); 
    201215        } 
    202216 
    203         printf_debug("0x6c: 0x%04x     (CLOCK/DEBUG)\n", *(uint16_t *)(ich_spibar + 0x6c)); 
    204         viaspi_detected = 1; 
    205         return 0; 
    206 } 
    207  
    208 static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, unsigned long spibar) 
    209 { 
     217        printf_debug("0x6c: 0x%04x     (CLOCK/DEBUG)\n", *(uint16_t *)(spibar + 0x6c)); 
     218 
     219        flashbus = BUS_TYPE_VIA_SPI; 
     220 
     221        return 0; 
     222} 
     223 
     224static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, int ich_generation) 
     225{ 
     226        int ret, i; 
    210227        uint8_t old, new, bbs, buc; 
     228        uint16_t spibar_offset; 
    211229        uint32_t tmp, gcs; 
    212230        void *rcrb; 
    213  
    214         /* Read the Root Complex Base Address Register (RCBA) */ 
    215         tmp = pci_read_long(dev, 0xf0); 
    216  
    217         /* Calculate the Root Complex Register Block address */ 
    218         tmp &= 0xffffc000; 
     231        static const char *straps_names[] = { "reserved", "SPI", "PCI", "LPC" }; 
     232         
     233        /* Enable Flash Writes */ 
     234        ret = enable_flash_ich_dc(dev, name); 
     235 
     236        /* Get physical address of Root Complex Register Block */ 
     237        tmp = pci_read_long(dev, 0xf0) & 0xffffc000; 
    219238        printf_debug("\nRoot Complex Register Block address = 0x%x\n", tmp); 
     239 
     240        /* Map RCBA to virtual memory */ 
    220241        rcrb = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, (off_t)tmp); 
    221242        if (rcrb == MAP_FAILED) { 
     
    223244                exit(1); 
    224245        } 
    225         printf_debug("GCS address = 0x%x\n", tmp + 0x3410); 
     246 
    226247        gcs = *(volatile uint32_t *)(rcrb + 0x3410); 
    227248        printf_debug("GCS = 0x%x: ", gcs); 
     
    229250                     (gcs & 0x1) ? "en" : "dis"); 
    230251        bbs = (gcs >> 10) & 0x3; 
    231         printf_debug("BOOT BIOS Straps: 0x%x (%s)\n",   bbs, 
    232                      (bbs == 0x3) ? "LPC" : ((bbs == 0x2) ? "PCI" : "SPI")); 
    233         if (bbs >= 2) 
    234                 ich7_detected = 0; 
     252        printf_debug("BOOT BIOS Straps: 0x%x (%s)\n", bbs, straps_names[bbs]); 
    235253 
    236254        buc = *(volatile uint8_t *)(rcrb + 0x3414); 
    237255        printf_debug("Top Swap : %s\n", (buc & 1)?"enabled (A16 inverted)":"not enabled"); 
    238256 
     257        /* It seems the ICH7 does not support SPI and LPC chips at the same 
     258         * time. At least not with our current code. So we prevent searching 
     259         * on ICH7 when the southbridge is strapped to LPC 
     260         */ 
     261 
     262        if (ich_generation == 7 && bbs == ICH_STRAP_LPC) { 
     263                /* No further SPI initialization required */ 
     264                return ret; 
     265        } 
     266 
     267        switch (ich_generation) { 
     268        case 7: 
     269                flashbus = BUS_TYPE_ICH7_SPI; 
     270                spibar_offset = 0x3020; 
     271                break; 
     272        case 8: 
     273                flashbus = BUS_TYPE_ICH9_SPI; 
     274                spibar_offset = 0x3020; 
     275                break; 
     276        case 9: 
     277        default: /* Future version might behave the same */ 
     278                flashbus = BUS_TYPE_ICH9_SPI; 
     279                spibar_offset = 0x3800; 
     280                break; 
     281        } 
     282 
    239283        /* SPIBAR is at RCRB+0x3020 for ICH[78] and RCRB+0x3800 for ICH9. */ 
    240         printf_debug("SPIBAR = 0x%x + 0x%04x\n", tmp, (uint16_t)spibar); 
    241  
    242         // Assign Virtual Address 
    243         ich_spibar =  rcrb + spibar; 
    244  
    245         if (ich7_detected) { 
    246                 int i; 
    247                 printf_debug("0x00: 0x%04x     (SPIS)\n", *(uint16_t *)(ich_spibar + 0)); 
    248                 printf_debug("0x02: 0x%04x     (SPIC)\n", *(uint16_t *)(ich_spibar + 2)); 
    249                 printf_debug("0x04: 0x%08x (SPIA)\n", *(uint32_t *)(ich_spibar + 4)); 
     284        printf_debug("SPIBAR = 0x%x + 0x%04x\n", tmp, spibar_offset); 
     285 
     286        /* Assign Virtual Address */ 
     287        spibar =  rcrb + spibar_offset; 
     288 
     289        switch (flashbus) { 
     290        case BUS_TYPE_ICH7_SPI: 
     291                printf_debug("0x00: 0x%04x     (SPIS)\n", *(uint16_t *)(spibar + 0)); 
     292                printf_debug("0x02: 0x%04x     (SPIC)\n", *(uint16_t *)(spibar + 2)); 
     293                printf_debug("0x04: 0x%08x (SPIA)\n", *(uint32_t *)(spibar + 4)); 
    250294                for (i=0; i < 8; i++) { 
    251295                        int offs; 
    252296                        offs = 8 + (i * 8); 
    253                         printf_debug("0x%02x: 0x%08x (SPID%d)\n", offs, *(uint32_t *)(ich_spibar + offs), i); 
    254                         printf_debug("0x%02x: 0x%08x (SPID%d+4)\n", offs+4, *(uint32_t *)(ich_spibar + offs +4), i); 
    255                 } 
    256                 printf_debug("0x50: 0x%08x (BBAR)\n", *(uint32_t *)(ich_spibar + 0x50)); 
    257                 printf_debug("0x54: 0x%04x     (PREOP)\n", *(uint16_t *)(ich_spibar + 0x54)); 
    258                 printf_debug("0x56: 0x%04x     (OPTYPE)\n", *(uint16_t *)(ich_spibar + 0x56)); 
    259                 printf_debug("0x58: 0x%08x (OPMENU)\n", *(uint32_t *)(ich_spibar + 0x58)); 
    260                 printf_debug("0x5c: 0x%08x (OPMENU+4)\n", *(uint32_t *)(ich_spibar + 0x5c)); 
     297                        printf_debug("0x%02x: 0x%08x (SPID%d)\n", offs, *(uint32_t *)(spibar + offs), i); 
     298                        printf_debug("0x%02x: 0x%08x (SPID%d+4)\n", offs+4, *(uint32_t *)(spibar + offs +4), i); 
     299                } 
     300                printf_debug("0x50: 0x%08x (BBAR)\n", *(uint32_t *)(spibar + 0x50)); 
     301                printf_debug("0x54: 0x%04x     (PREOP)\n", *(uint16_t *)(spibar + 0x54)); 
     302                printf_debug("0x56: 0x%04x     (OPTYPE)\n", *(uint16_t *)(spibar + 0x56)); 
     303                printf_debug("0x58: 0x%08x (OPMENU)\n", *(uint32_t *)(spibar + 0x58)); 
     304                printf_debug("0x5c: 0x%08x (OPMENU+4)\n", *(uint32_t *)(spibar + 0x5c)); 
    261305                for (i=0; i < 4; i++) { 
    262306                        int offs; 
    263307                        offs = 0x60 + (i * 4); 
    264                         printf_debug("0x%02x: 0x%08x (PBR%d)\n", offs, *(uint32_t *)(ich_spibar + offs), i); 
     308                        printf_debug("0x%02x: 0x%08x (PBR%d)\n", offs, *(uint32_t *)(spibar + offs), i); 
    265309                } 
    266310                printf_debug("\n"); 
    267                 if ( (*(uint16_t *)ich_spibar) & (1 << 15)) { 
     311                if ( (*(uint16_t *)spibar) & (1 << 15)) { 
    268312                        printf("WARNING: SPI Configuration Lockdown activated.\n"); 
    269313                } 
     314                break; 
     315        case BUS_TYPE_ICH9_SPI: 
     316                /* TODO: Add dumping function for ICH8/ICH9, or drop the  
     317                 * whole SPIBAR dumping from chipset_enable.c - There's  
     318                 * inteltool for this task already. 
     319                 */ 
     320                break; 
     321        default: 
     322                /* Nothing */ 
     323                break; 
    270324        } 
    271325 
     
    278332        case 2: 
    279333                printf_debug("prefetching %sabled, caching %sabled, ", 
    280                         (new & 0x2) ? "en" : "dis", (new & 0x1) ? "dis" : "en"); 
     334                        (new & 0x2) ? "en" : "dis",  
     335                        (new & 0x1) ? "dis" : "en"); 
    281336                break; 
    282337        default: 
     
    284339                break; 
    285340        } 
    286         return enable_flash_ich_dc(dev, name); 
    287 } 
    288  
    289 /* Flag for ICH7 SPI register block */ 
    290 int ich7_detected = 0; 
    291 int viaspi_detected = 0; 
     341 
     342        return ret; 
     343} 
    292344 
    293345static int enable_flash_ich7(struct pci_dev *dev, const char *name) 
    294346{ 
    295        ich7_detected = 1; 
    296         return enable_flash_ich_dc_spi(dev, name, 0x3020); 
    297 } 
    298  
    299 /* Flag for ICH8/ICH9 SPI register block */ 
    300 int ich9_detected = 0; 
     347        return enable_flash_ich_dc_spi(dev, name, 7); 
     348} 
    301349 
    302350static int enable_flash_ich8(struct pci_dev *dev, const char *name) 
    303351{ 
    304         ich9_detected = 1; 
    305         return enable_flash_ich_dc_spi(dev, name, 0x3020); 
     352        return enable_flash_ich_dc_spi(dev, name, 8); 
    306353} 
    307354 
    308355static int enable_flash_ich9(struct pci_dev *dev, const char *name) 
    309356{ 
    310         ich9_detected = 1; 
    311         return enable_flash_ich_dc_spi(dev, name, 0x3800); 
     357        return enable_flash_ich_dc_spi(dev, name, 9); 
    312358} 
    313359 
  • trunk/util/flashrom/flash.h

    r3399 r3401  
    371371int chipset_flash_enable(void); 
    372372void print_supported_chipsets(void); 
    373 extern int ich7_detected; 
    374 extern int viaspi_detected; 
    375 extern int ich9_detected; 
    376 extern void *ich_spibar; 
     373 
     374typedef enum { 
     375        BUS_TYPE_LPC, 
     376        BUS_TYPE_ICH7_SPI, 
     377        BUS_TYPE_ICH9_SPI, 
     378        BUS_TYPE_IT87XX_SPI, 
     379        BUS_TYPE_VIA_SPI 
     380} flashbus_t; 
     381 
     382extern flashbus_t flashbus; 
     383extern void *spibar; 
    377384 
    378385/* Physical memory mapping device */ 
  • trunk/util/flashrom/ichspi.c

    r3398 r3401  
    132132{ 
    133133        volatile uint32_t regval; 
    134         regval = *(volatile uint32_t *) ((uint8_t *) ich_spibar + X); 
     134        regval = *(volatile uint32_t *) ((uint8_t *) spibar + X); 
    135135        return regval; 
    136136} 
     
    139139{ 
    140140        volatile uint16_t regval; 
    141         regval = *(volatile uint16_t *) ((uint8_t *) ich_spibar + X); 
     141        regval = *(volatile uint16_t *) ((uint8_t *) spibar + X); 
    142142        return regval; 
    143143} 
    144144 
    145 #define REGWRITE32(X,Y) (*(uint32_t *)((uint8_t *)ich_spibar+X)=Y) 
    146 #define REGWRITE16(X,Y) (*(uint16_t *)((uint8_t *)ich_spibar+X)=Y) 
    147 #define REGWRITE8(X,Y)  (*(uint8_t *)((uint8_t *)ich_spibar+X)=Y) 
     145#define REGWRITE32(X,Y) (*(uint32_t *)((uint8_t *)spibar+X)=Y) 
     146#define REGWRITE16(X,Y) (*(uint16_t *)((uint8_t *)spibar+X)=Y) 
     147#define REGWRITE8(X,Y)  (*(uint8_t *)((uint8_t *)spibar+X)=Y) 
    148148 
    149149/* Common SPI functions */ 
     
    176176{ 
    177177        uint8_t a; 
    178         uint16_t temp16; 
    179         uint32_t temp32; 
     178        uint16_t preop, optype; 
     179        uint32_t opmenu[2]; 
    180180 
    181181        /* Program Prefix Opcodes */ 
    182         temp16 = 0; 
     182        preop = 0; 
    183183        /* 0:7 Prefix Opcode 1 */ 
    184         temp16 = (op->preop[0]); 
     184        preop = (op->preop[0]); 
    185185        /* 8:16 Prefix Opcode 2 */ 
    186         temp16 |= ((uint16_t) op->preop[1]) << 8; 
    187         if ((ich7_detected) || (viaspi_detected)) { 
    188                 REGWRITE16(ICH7_REG_PREOP, temp16); 
    189         } else if (ich9_detected) { 
    190                 REGWRITE16(ICH9_REG_PREOP, temp16); 
    191         } 
    192  
     186        preop |= ((uint16_t) op->preop[1]) << 8; 
     187         
    193188        /* Program Opcode Types 0 - 7 */ 
    194         temp16 = 0; 
     189        optype = 0; 
    195190        for (a = 0; a < 8; a++) { 
    196                 temp16 |= ((uint16_t) op->opcode[a].spi_type) << (a * 2); 
    197         } 
    198  
    199         if ((ich7_detected) || (viaspi_detected)) { 
    200                 REGWRITE16(ICH7_REG_OPTYPE, temp16); 
    201         } else if (ich9_detected) { 
    202                 REGWRITE16(ICH9_REG_OPTYPE, temp16); 
    203         } 
    204  
    205  
     191                optype |= ((uint16_t) op->opcode[a].spi_type) << (a * 2); 
     192        } 
     193         
    206194        /* Program Allowable Opcodes 0 - 3 */ 
    207         temp32 = 0; 
     195        opmenu[0] = 0; 
    208196        for (a = 0; a < 4; a++) { 
    209                 temp32 |= ((uint32_t) op->opcode[a].opcode) << (a * 8); 
    210         } 
    211  
    212         if ((ich7_detected) || (viaspi_detected)) { 
    213                 REGWRITE32(ICH7_REG_OPMENU, temp32); 
    214         } else if (ich9_detected) { 
    215                 REGWRITE32(ICH9_REG_OPMENU, temp32); 
    216         } 
    217  
     197                opmenu[0] |= ((uint32_t) op->opcode[a].opcode) << (a * 8); 
     198        } 
    218199 
    219200        /*Program Allowable Opcodes 4 - 7 */ 
    220         temp32 = 0; 
     201        opmenu[1] = 0; 
    221202        for (a = 4; a < 8; a++) { 
    222                 temp32 |= 
    223                     ((uint32_t) op->opcode[a].opcode) << ((a - 4) * 8); 
    224         } 
    225  
    226         if ((ich7_detected) || (viaspi_detected)) { 
    227                 REGWRITE32(ICH7_REG_OPMENU + 4, temp32); 
    228         } else if (ich9_detected) { 
    229                 REGWRITE32(ICH9_REG_OPMENU + 4, temp32); 
     203                opmenu[1] |= ((uint32_t) op->opcode[a].opcode) << ((a - 4) * 8); 
     204        } 
     205 
     206        switch (flashbus) { 
     207        case BUS_TYPE_ICH7_SPI:  
     208        case BUS_TYPE_VIA_SPI:  
     209                REGWRITE16(ICH7_REG_PREOP, preop); 
     210                REGWRITE16(ICH7_REG_OPTYPE, optype); 
     211                REGWRITE32(ICH7_REG_OPMENU, opmenu[0]); 
     212                REGWRITE32(ICH7_REG_OPMENU + 4, opmenu[1]); 
     213                break; 
     214        case BUS_TYPE_ICH9_SPI: 
     215                REGWRITE16(ICH9_REG_PREOP, preop); 
     216                REGWRITE16(ICH9_REG_OPTYPE, optype); 
     217                REGWRITE32(ICH9_REG_OPMENU, opmenu[0]); 
     218                REGWRITE32(ICH9_REG_OPMENU + 4, opmenu[1]); 
     219                break; 
     220        default: 
     221                printf_debug("%s: unsupported chipset\n", __FUNCTION__); 
     222                return -1; 
    230223        } 
    231224 
     
    341334{ 
    342335        int write_cmd = 0; 
     336        int timeout; 
    343337        uint32_t temp32; 
    344338        uint32_t a; 
     
    411405 
    412406        /*wait for cycle complete */ 
    413         while ((REGREAD32(ICH9_REG_SSFS) & SSFS_CDS) == 0) { 
    414                 /*TODO; Do something that this can't lead into an endless loop. but some 
    415                  * commands may cause this to be last more than 30 seconds */ 
     407        timeout = 1000 * 60;    // 60s is a looong timeout. 
     408        while (((REGREAD32(ICH9_REG_SSFS) & SSFS_CDS) == 0) && --timeout) { 
     409                myusec_delay(1000); 
     410        } 
     411        if (!timeout) { 
     412                printf_debug("timeout\n"); 
    416413        } 
    417414 
     
    439436                      uint8_t datalength, uint8_t * data) 
    440437{ 
    441         if (ich7_detected) 
     438        switch (flashbus) { 
     439        case BUS_TYPE_VIA_SPI: 
     440                return ich7_run_opcode(nr, op, offset, datalength, data, 16); 
     441        case BUS_TYPE_ICH7_SPI: 
    442442                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) 
     443        case BUS_TYPE_ICH9_SPI: 
    446444                return ich9_run_opcode(nr, op, offset, datalength, data); 
     445        default: 
     446                printf_debug("%s: unsupported chipset\n", __FUNCTION__); 
     447        } 
    447448 
    448449        /* If we ever get here, something really weird happened */ 
     
    542543        int maxdata = 64; 
    543544 
    544         if (viaspi_detected) { 
     545        if (flashbus == BUS_TYPE_VIA_SPI) { 
    545546                maxdata = 16; 
    546547        } 
     
    573574                } 
    574575 
    575         if (viaspi_detected) { 
     576        if (flashbus == BUS_TYPE_VIA_SPI) { 
    576577                maxdata = 16; 
    577578        } 
  • trunk/util/flashrom/it87spi.c

    r3344 r3401  
    44 * Copyright (C) 2007, 2008 Carl-Daniel Hailfinger 
    55 * Copyright (C) 2008 Ronald Hoogenboom <ronald@zonnet.nl> 
     6 * Copyright (C) 2008 coresystems GmbH 
    67 * 
    78 * This program is free software; you can redistribute it and/or modify 
     
    113114{ 
    114115        it8716f_flashport = find_ite_spi_flash_port(ITE_SUPERIO_PORT1); 
     116 
    115117        if (!it8716f_flashport) 
    116118                it8716f_flashport = find_ite_spi_flash_port(ITE_SUPERIO_PORT2); 
     119 
     120        if (it8716f_flashport) 
     121                flashbus = BUS_TYPE_IT87XX_SPI; 
     122 
    117123        return (!it8716f_flashport); 
    118124} 
  • 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}