Ignore:
Timestamp:
Jul 22, 2010 8:04:15 PM (3 years ago)
Author:
mkarcher
Message:

Move Intel SPI initialisation to ichspi.c

Smarter version could decide whether SPI is vital or not depending on
straps. Straps are currently implemented for ICH7. EP80579 is in the comment,
PCH of 5 Series/3400 Series has "LPC, reserved, PCI, SPI".

Signed-off-by: Michael Karcher <flashrom@…>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/chipset_enable.c

    r1076 r1098  
    418418static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name) 
    419419{ 
    420         uint32_t mmio_base; 
    421  
    422420        /* Do we really need no write enable? */ 
    423         mmio_base = (pci_read_long(dev, 0xbc)) << 8; 
    424         msg_pdbg("MMIO base at = 0x%x\n", mmio_base); 
    425         ich_spibar = physmap("VT8237S MMIO registers", mmio_base, 0x70); 
    426  
    427         msg_pdbg("0x6c: 0x%04x     (CLOCK/DEBUG)\n", 
    428                      mmio_readw(ich_spibar + 0x6c)); 
    429  
    430         /* Not sure if it speaks all these bus protocols. */ 
    431         buses_supported = CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI; 
    432         spi_controller = SPI_CONTROLLER_VIA; 
    433         ich_init_opcodes(); 
    434  
    435         return 0; 
    436 } 
    437  
    438 #define ICH_BMWAG(x) ((x >> 24) & 0xff) 
    439 #define ICH_BMRAG(x) ((x >> 16) & 0xff) 
    440 #define ICH_BRWA(x)  ((x >>  8) & 0xff) 
    441 #define ICH_BRRA(x)  ((x >>  0) & 0xff) 
    442  
    443 #define ICH_FREG_BASE(x)  ((x >>  0) & 0x1fff) 
    444 #define ICH_FREG_LIMIT(x) ((x >> 16) & 0x1fff) 
    445  
    446 static void do_ich9_spi_frap(uint32_t frap, int i) 
    447 { 
    448         const char *access_names[4] = { 
    449                 "locked", "read-only", "write-only", "read-write" 
    450         }; 
    451         const char *region_names[5] = { 
    452                 "Flash Descriptor", "BIOS", "Management Engine", 
    453                 "Gigabit Ethernet", "Platform Data" 
    454         }; 
    455         uint32_t base, limit; 
    456         int rwperms = (((ICH_BRWA(frap) >> i) & 1) << 1) | 
    457                       (((ICH_BRRA(frap) >> i) & 1) << 0); 
    458         int offset = 0x54 + i * 4; 
    459         uint32_t freg = mmio_readl(ich_spibar + offset); 
    460  
    461         msg_pdbg("0x%02X: 0x%08x (FREG%i: %s)\n", 
    462                      offset, freg, i, region_names[i]); 
    463  
    464         base  = ICH_FREG_BASE(freg); 
    465         limit = ICH_FREG_LIMIT(freg); 
    466         if (base == 0x1fff && limit == 0) { 
    467                 /* this FREG is disabled */ 
    468                 msg_pdbg("%s region is unused.\n", region_names[i]); 
    469                 return; 
    470         } 
    471  
    472         msg_pdbg("0x%08x-0x%08x is %s\n", 
    473                     (base << 12), (limit << 12) | 0x0fff, 
    474                     access_names[rwperms]); 
     421        return via_init_spi(dev); 
    475422} 
    476423 
     
    478425                                   int ich_generation) 
    479426{ 
    480         int ret, i; 
    481         uint8_t old, new, bbs, buc; 
    482         uint16_t spibar_offset, tmp2; 
     427        int ret; 
     428        uint8_t bbs, buc; 
    483429        uint32_t tmp, gcs; 
    484430        void *rcrb; 
     
    513459         */ 
    514460 
    515         if (ich_generation == 7 && bbs == ICH_STRAP_LPC) { 
    516                 buses_supported = CHIP_BUSTYPE_FWH; 
    517                 /* No further SPI initialization required */ 
    518                 return ret; 
    519         } 
    520  
    521         switch (ich_generation) { 
    522         case 7: 
    523                 buses_supported = CHIP_BUSTYPE_SPI; 
    524                 spi_controller = SPI_CONTROLLER_ICH7; 
    525                 spibar_offset = 0x3020; 
    526                 break; 
    527         case 8: 
    528                 buses_supported = CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI; 
    529                 spi_controller = SPI_CONTROLLER_ICH9; 
    530                 spibar_offset = 0x3020; 
    531                 break; 
    532         case 9: 
    533         case 10: 
    534         default:                /* Future version might behave the same */ 
    535                 buses_supported = CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI; 
    536                 spi_controller = SPI_CONTROLLER_ICH9; 
    537                 spibar_offset = 0x3800; 
    538                 break; 
    539         } 
    540  
    541         /* SPIBAR is at RCRB+0x3020 for ICH[78] and RCRB+0x3800 for ICH9. */ 
    542         msg_pdbg("SPIBAR = 0x%x + 0x%04x\n", tmp, spibar_offset); 
    543  
    544         /* Assign Virtual Address */ 
    545         ich_spibar = rcrb + spibar_offset; 
    546  
    547         switch (spi_controller) { 
    548         case SPI_CONTROLLER_ICH7: 
    549                 msg_pdbg("0x00: 0x%04x     (SPIS)\n", 
    550                              mmio_readw(ich_spibar + 0)); 
    551                 msg_pdbg("0x02: 0x%04x     (SPIC)\n", 
    552                              mmio_readw(ich_spibar + 2)); 
    553                 msg_pdbg("0x04: 0x%08x (SPIA)\n", 
    554                              mmio_readl(ich_spibar + 4)); 
    555                 for (i = 0; i < 8; i++) { 
    556                         int offs; 
    557                         offs = 8 + (i * 8); 
    558                         msg_pdbg("0x%02x: 0x%08x (SPID%d)\n", offs, 
    559                                      mmio_readl(ich_spibar + offs), i); 
    560                         msg_pdbg("0x%02x: 0x%08x (SPID%d+4)\n", offs + 4, 
    561                                      mmio_readl(ich_spibar + offs + 4), i); 
     461        buses_supported = CHIP_BUSTYPE_FWH; 
     462        if (ich_generation == 7) { 
     463                if(bbs == ICH_STRAP_LPC) { 
     464                        /* No further SPI initialization required */ 
     465                        return ret; 
    562466                } 
    563                 ichspi_bbar = mmio_readl(ich_spibar + 0x50); 
    564                 msg_pdbg("0x50: 0x%08x (BBAR)\n", 
    565                              ichspi_bbar); 
    566                 msg_pdbg("0x54: 0x%04x     (PREOP)\n", 
    567                              mmio_readw(ich_spibar + 0x54)); 
    568                 msg_pdbg("0x56: 0x%04x     (OPTYPE)\n", 
    569                              mmio_readw(ich_spibar + 0x56)); 
    570                 msg_pdbg("0x58: 0x%08x (OPMENU)\n", 
    571                              mmio_readl(ich_spibar + 0x58)); 
    572                 msg_pdbg("0x5c: 0x%08x (OPMENU+4)\n", 
    573                              mmio_readl(ich_spibar + 0x5c)); 
    574                 for (i = 0; i < 4; i++) { 
    575                         int offs; 
    576                         offs = 0x60 + (i * 4); 
    577                         msg_pdbg("0x%02x: 0x%08x (PBR%d)\n", offs, 
    578                                      mmio_readl(ich_spibar + offs), i); 
    579                 } 
    580                 msg_pdbg("\n"); 
    581                 if (mmio_readw(ich_spibar) & (1 << 15)) { 
    582                         msg_pinfo("WARNING: SPI Configuration Lockdown activated.\n"); 
    583                         ichspi_lock = 1; 
    584                 } 
    585                 ich_init_opcodes(); 
    586                 break; 
    587         case SPI_CONTROLLER_ICH9: 
    588                 tmp2 = mmio_readw(ich_spibar + 4); 
    589                 msg_pdbg("0x04: 0x%04x (HSFS)\n", tmp2); 
    590                 msg_pdbg("FLOCKDN %i, ", (tmp2 >> 15 & 1)); 
    591                 msg_pdbg("FDV %i, ", (tmp2 >> 14) & 1); 
    592                 msg_pdbg("FDOPSS %i, ", (tmp2 >> 13) & 1); 
    593                 msg_pdbg("SCIP %i, ", (tmp2 >> 5) & 1); 
    594                 msg_pdbg("BERASE %i, ", (tmp2 >> 3) & 3); 
    595                 msg_pdbg("AEL %i, ", (tmp2 >> 2) & 1); 
    596                 msg_pdbg("FCERR %i, ", (tmp2 >> 1) & 1); 
    597                 msg_pdbg("FDONE %i\n", (tmp2 >> 0) & 1); 
    598  
    599                 tmp = mmio_readl(ich_spibar + 0x50); 
    600                 msg_pdbg("0x50: 0x%08x (FRAP)\n", tmp); 
    601                 msg_pdbg("BMWAG 0x%02x, ", ICH_BMWAG(tmp)); 
    602                 msg_pdbg("BMRAG 0x%02x, ", ICH_BMRAG(tmp)); 
    603                 msg_pdbg("BRWA 0x%02x, ", ICH_BRWA(tmp)); 
    604                 msg_pdbg("BRRA 0x%02x\n", ICH_BRRA(tmp)); 
    605  
    606                 /* print out the FREGx registers along with FRAP access bits */ 
    607                 for(i = 0; i < 5; i++) 
    608                         do_ich9_spi_frap(tmp, i); 
    609  
    610                 msg_pdbg("0x74: 0x%08x (PR0)\n", 
    611                              mmio_readl(ich_spibar + 0x74)); 
    612                 msg_pdbg("0x78: 0x%08x (PR1)\n", 
    613                              mmio_readl(ich_spibar + 0x78)); 
    614                 msg_pdbg("0x7C: 0x%08x (PR2)\n", 
    615                              mmio_readl(ich_spibar + 0x7C)); 
    616                 msg_pdbg("0x80: 0x%08x (PR3)\n", 
    617                              mmio_readl(ich_spibar + 0x80)); 
    618                 msg_pdbg("0x84: 0x%08x (PR4)\n", 
    619                              mmio_readl(ich_spibar + 0x84)); 
    620                 msg_pdbg("0x90: 0x%08x (SSFS, SSFC)\n", 
    621                              mmio_readl(ich_spibar + 0x90)); 
    622                 msg_pdbg("0x94: 0x%04x     (PREOP)\n", 
    623                              mmio_readw(ich_spibar + 0x94)); 
    624                 msg_pdbg("0x96: 0x%04x     (OPTYPE)\n", 
    625                              mmio_readw(ich_spibar + 0x96)); 
    626                 msg_pdbg("0x98: 0x%08x (OPMENU)\n", 
    627                              mmio_readl(ich_spibar + 0x98)); 
    628                 msg_pdbg("0x9C: 0x%08x (OPMENU+4)\n", 
    629                              mmio_readl(ich_spibar + 0x9C)); 
    630                 ichspi_bbar = mmio_readl(ich_spibar + 0xA0); 
    631                 msg_pdbg("0xA0: 0x%08x (BBAR)\n", 
    632                              ichspi_bbar); 
    633                 msg_pdbg("0xB0: 0x%08x (FDOC)\n", 
    634                              mmio_readl(ich_spibar + 0xB0)); 
    635                 if (tmp2 & (1 << 15)) { 
    636                         msg_pinfo("WARNING: SPI Configuration Lockdown activated.\n"); 
    637                         ichspi_lock = 1; 
    638                 } 
    639                 ich_init_opcodes(); 
    640                 break; 
    641         default: 
    642                 /* Nothing */ 
    643                 break; 
    644         } 
    645  
    646         old = pci_read_byte(dev, 0xdc); 
    647         msg_pdbg("SPI Read Configuration: "); 
    648         new = (old >> 2) & 0x3; 
    649         switch (new) { 
    650         case 0: 
    651         case 1: 
    652         case 2: 
    653                 msg_pdbg("prefetching %sabled, caching %sabled, ", 
    654                              (new & 0x2) ? "en" : "dis", 
    655                              (new & 0x1) ? "dis" : "en"); 
    656                 break; 
    657         default: 
    658                 msg_pdbg("invalid prefetching/caching settings, "); 
    659                 break; 
    660         } 
     467                else 
     468                        /* Disable LPC/FWH if strapped to PCI or SPI */ 
     469                        buses_supported = 0; 
     470        } 
     471 
     472        /* this adds CHIP_BUSTYPE_SPI */ 
     473        if (ich_init_spi(dev, tmp, rcrb, ich_generation) != 0) { 
     474                if (!ret) 
     475                        ret = ERROR_NONFATAL; 
     476        } 
    661477 
    662478        return ret; 
     
    15471363                else if(ret == 0) 
    15481364                        msg_pinfo("OK.\n"); 
     1365                else if(ret == ERROR_NONFATAL) 
     1366                        msg_pinfo("PROBLEMS, continuing anyway\n"); 
    15491367        } 
    15501368 
Note: See TracChangeset for help on using the changeset viewer.