Changeset 1460


Ignore:
Timestamp:
11/07/11 00:51:09 (7 months ago)
Author:
stefanct
Message:

ichspi: use a variable to distinguish ich generations instead of spi_programmer->type

The type member is enough most of the time to derive the wanted
information, but

  • not always (e.g. ich_set_bbar),
  • only available after registration, which we want to delay till the end of init, and
  • we really want to distinguish between chipset version-grained attributes which are not reflected by the registered programmer.

Hence this patch introduces a new static variable which is set up
early by the init functions and allows us to get rid of all "switch
(spi_programmer->type)" in ichspi.c. We reuse the enum introduced
for descriptor mode for the type of the new variable.

Previously magic numbers were passed by chipset_enable wrappers. Now
they use the enumeration items too. To get this working the enum
definition had to be moved to programmer.h.

Another noteworthy detail: previously we have checked for a valid
programmer/ich generation all over the place. I have removed those
checks and added one single check in the init method. Calling any
function of a programmer without executing the init method first, is
undefined behavior.

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

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/chipset_enable.c

    r1454 r1460  
    490490 
    491491static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name, 
    492                                    int ich_generation) 
     492                                   enum ich_chipset ich_generation) 
    493493{ 
    494494        int ret; 
     
    505505 
    506506        switch (ich_generation) { 
    507         case 7: 
     507        case CHIPSET_ICH7: 
    508508                /* EP80579 may need further changes, but this is the least 
    509509                 * intrusive way to get correct BOOT Strap printing without 
     
    514514                        straps_names = straps_names_ich7_nm10; 
    515515                break; 
    516         case 8: 
    517         case 9: 
    518         case 10: 
     516        case CHIPSET_ICH8: 
     517        case CHIPSET_ICH9: 
     518        case CHIPSET_ICH10: 
    519519                straps_names = straps_names_ich8910; 
    520520                break; 
    521         case 11: 
    522         case 12: 
     521        case CHIPSET_5_SERIES_IBEX_PEAK: 
     522        case CHIPSET_6_SERIES_COUGAR_POINT: 
    523523                straps_names = straps_names_pch56; 
    524524                break; 
     
    558558         */ 
    559559        buses_supported = BUS_FWH; 
    560         if (ich_generation == 7) { 
     560        if (ich_generation == CHIPSET_ICH7) { 
    561561                if (bbs == 0x03) { 
    562562                        /* If strapped to LPC, no further SPI initialization is 
     
    580580static int enable_flash_ich7(struct pci_dev *dev, const char *name) 
    581581{ 
    582         return enable_flash_ich_dc_spi(dev, name, 7); 
     582        return enable_flash_ich_dc_spi(dev, name, CHIPSET_ICH7); 
    583583} 
    584584 
    585585static int enable_flash_ich8(struct pci_dev *dev, const char *name) 
    586586{ 
    587         return enable_flash_ich_dc_spi(dev, name, 8); 
     587        return enable_flash_ich_dc_spi(dev, name, CHIPSET_ICH8); 
    588588} 
    589589 
    590590static int enable_flash_ich9(struct pci_dev *dev, const char *name) 
    591591{ 
    592         return enable_flash_ich_dc_spi(dev, name, 9); 
     592        return enable_flash_ich_dc_spi(dev, name, CHIPSET_ICH9); 
    593593} 
    594594 
    595595static int enable_flash_ich10(struct pci_dev *dev, const char *name) 
    596596{ 
    597         return enable_flash_ich_dc_spi(dev, name, 10); 
     597        return enable_flash_ich_dc_spi(dev, name, CHIPSET_ICH10); 
    598598} 
    599599 
     
    601601static int enable_flash_pch5(struct pci_dev *dev, const char *name) 
    602602{ 
    603         return enable_flash_ich_dc_spi(dev, name, 11); 
     603        return enable_flash_ich_dc_spi(dev, name, CHIPSET_5_SERIES_IBEX_PEAK); 
    604604} 
    605605 
     
    607607static int enable_flash_pch6(struct pci_dev *dev, const char *name) 
    608608{ 
    609         return enable_flash_ich_dc_spi(dev, name, 12); 
     609        return enable_flash_ich_dc_spi(dev, name, CHIPSET_6_SERIES_COUGAR_POINT); 
    610610} 
    611611 
  • trunk/ich_descriptors.h

    r1452 r1460  
    2525 
    2626#include <stdint.h> 
     27#include "programmer.h" /* for enum ich_chipset */ 
    2728 
    2829/* FIXME: Replace with generic return codes */ 
     
    6465#define ICH_FREG_LIMIT(flreg) (((flreg) >>  4) & 0x01fff000) 
    6566 
    66 /* Used to select the right descriptor printing function. 
    67  * Currently only ICH8 and Ibex Peak are supported. 
    68  */ 
    69 enum ich_chipset { 
    70         CHIPSET_ICH_UNKNOWN, 
    71         CHIPSET_ICH7 = 7, 
    72         CHIPSET_ICH8, 
    73         CHIPSET_ICH9, 
    74         CHIPSET_ICH10, 
    75         CHIPSET_5_SERIES_IBEX_PEAK, 
    76         CHIPSET_6_SERIES_COUGAR_POINT, 
    77         CHIPSET_7_SERIES_PANTHER_POINT 
    78 }; 
    79  
    8067void prettyprint_ich_reg_vscc(uint32_t reg_val, int verbosity); 
    8168 
  • trunk/ichspi.c

    r1452 r1460  
    173173static int ichspi_lock = 0; 
    174174 
     175static enum ich_chipset ich_generation = CHIPSET_ICH_UNKNOWN; 
    175176uint32_t ichspi_bbar = 0; 
    176177 
     
    455456        } 
    456457 
    457         switch (spi_programmer->type) { 
    458         case SPI_CONTROLLER_ICH7: 
    459         case SPI_CONTROLLER_VIA: 
     458        switch (ich_generation) { 
     459        case CHIPSET_ICH7: 
    460460                preop = REGREAD16(ICH7_REG_PREOP); 
    461461                optype = REGREAD16(ICH7_REG_OPTYPE); 
     
    463463                opmenu[1] = REGREAD32(ICH7_REG_OPMENU + 4); 
    464464                break; 
    465         case SPI_CONTROLLER_ICH9: 
     465        case CHIPSET_ICH8: 
     466        default:                /* Future version might behave the same */ 
    466467                preop = REGREAD16(ICH9_REG_PREOP); 
    467468                optype = REGREAD16(ICH9_REG_OPTYPE); 
     
    469470                opmenu[1] = REGREAD32(ICH9_REG_OPMENU + 4); 
    470471                break; 
    471         default: 
    472                 msg_perr("%s: unsupported chipset\n", __func__); 
    473                 return -1; 
    474472        } 
    475473 
     
    530528 
    531529        msg_pdbg("\n%s: preop=%04x optype=%04x opmenu=%08x%08x\n", __func__, preop, optype, opmenu[0], opmenu[1]); 
    532         switch (spi_programmer->type) { 
    533         case SPI_CONTROLLER_ICH7: 
    534         case SPI_CONTROLLER_VIA: 
     530        switch (ich_generation) { 
     531        case CHIPSET_ICH7: 
    535532                /* Register undo only for enable_undo=1, i.e. first call. */ 
    536533                if (enable_undo) { 
     
    545542                mmio_writel(opmenu[1], ich_spibar + ICH7_REG_OPMENU + 4); 
    546543                break; 
    547         case SPI_CONTROLLER_ICH9: 
     544        case CHIPSET_ICH8: 
     545        default:                /* Future version might behave the same */ 
    548546                /* Register undo only for enable_undo=1, i.e. first call. */ 
    549547                if (enable_undo) { 
     
    558556                mmio_writel(opmenu[1], ich_spibar + ICH9_REG_OPMENU + 4); 
    559557                break; 
    560         default: 
    561                 msg_perr("%s: unsupported chipset\n", __func__); 
    562                 return -1; 
    563558        } 
    564559 
     
    570565 * it didn't stick. 
    571566 */ 
    572 static void ich_set_bbar(int ich_generation, uint32_t min_addr) 
     567static void ich_set_bbar(uint32_t min_addr) 
    573568{ 
    574569        int bbar_off; 
    575570        switch (ich_generation) { 
    576         case 7: 
     571        case CHIPSET_ICH7: 
    577572                bbar_off = 0x50; 
    578573                break; 
    579         case 8: 
     574        case CHIPSET_ICH8: 
    580575                msg_perr("BBAR offset is unknown on ICH8!\n"); 
    581576                return; 
     577        case CHIPSET_ICH9: 
    582578        default:                /* Future version might behave the same */ 
    583579                bbar_off = ICH9_REG_BBAR; 
     
    944940        } 
    945941 
    946         switch (spi_programmer->type) { 
    947         case SPI_CONTROLLER_VIA: 
    948         case SPI_CONTROLLER_ICH7: 
     942        switch (ich_generation) { 
     943        case CHIPSET_ICH7: 
    949944                return ich7_run_opcode(op, offset, datalength, data, maxlength); 
    950         case SPI_CONTROLLER_ICH9: 
     945        case CHIPSET_ICH8: 
     946        default:                /* Future version might behave the same */ 
    951947                return ich9_run_opcode(op, offset, datalength, data); 
    952         default: 
    953                 /* If we ever get here, something really weird happened */ 
    954                 return -1; 
    955948        } 
    956949} 
     
    10231016                addr = (writearr[1] << 16) | 
    10241017                    (writearr[2] << 8) | (writearr[3] << 0); 
    1025                 switch (spi_programmer->type) { 
    1026                 case SPI_CONTROLLER_ICH7: 
    1027                 case SPI_CONTROLLER_VIA: 
    1028                 case SPI_CONTROLLER_ICH9: 
    1029                         if (addr < ichspi_bbar) { 
    1030                                 msg_perr("%s: Address 0x%06x below allowed " 
    1031                                          "range 0x%06x-0xffffff\n", __func__, 
    1032                                          addr, ichspi_bbar); 
    1033                                 return SPI_INVALID_ADDRESS; 
    1034                         } 
    1035                         break; 
    1036                 default: 
    1037                         break; 
     1018                if (addr < ichspi_bbar) { 
     1019                        msg_perr("%s: Address 0x%06x below allowed " 
     1020                                 "range 0x%06x-0xffffff\n", __func__, 
     1021                                 addr, ichspi_bbar); 
     1022                        return SPI_INVALID_ADDRESS; 
    10381023                } 
    10391024        } 
     
    13171302 
    13181303int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb, 
    1319                         int ich_generation) 
     1304                 enum ich_chipset ich_gen) 
    13201305{ 
    13211306        int i; 
     
    13251310        int desc_valid = 0; 
    13261311 
     1312        ich_generation = ich_gen; 
     1313 
    13271314        switch (ich_generation) { 
    1328         case 7: 
     1315        case CHIPSET_ICH_UNKNOWN: 
     1316                return -1; 
     1317        case CHIPSET_ICH7: 
     1318        case CHIPSET_ICH8: 
    13291319                spibar_offset = 0x3020; 
    13301320                break; 
    1331         case 8: 
    1332                 spibar_offset = 0x3020; 
    1333                 break; 
    1334         case 9: 
    1335         case 10: 
     1321        case CHIPSET_ICH9: 
    13361322        default:                /* Future version might behave the same */ 
    13371323                spibar_offset = 0x3800; 
     
    13461332 
    13471333        switch (ich_generation) { 
    1348         case 7: 
     1334        case CHIPSET_ICH7: 
    13491335                msg_pdbg("0x00: 0x%04x     (SPIS)\n", 
    13501336                             mmio_readw(ich_spibar + 0)); 
     
    13821368                        ichspi_lock = 1; 
    13831369                } 
    1384                 ich_set_bbar(ich_generation, 0); 
     1370                ich_set_bbar(0); 
    13851371                register_spi_programmer(&spi_programmer_ich7); 
    13861372                ich_init_opcodes(); 
    13871373                break; 
    1388         case 8: 
    1389         case 9: 
    1390         case 10: 
     1374        case CHIPSET_ICH8: 
    13911375        default:                /* Future version might behave the same */ 
    13921376                tmp2 = mmio_readw(ich_spibar + ICH9_REG_HSFS); 
     
    14481432                msg_pdbg("0x9C: 0x%08x (OPMENU+4)\n", 
    14491433                             mmio_readl(ich_spibar + ICH9_REG_OPMENU + 4)); 
    1450                 if (ich_generation == 8) { 
     1434                if (ich_generation == CHIPSET_ICH8) { 
    14511435                        tmp = mmio_readl(ich_spibar + ICH8_REG_VSCC); 
    14521436                        msg_pdbg("0xC1: 0x%08x (VSCC)\n", tmp); 
     
    14701454                        tmp = mmio_readl(ich_spibar + ICH9_REG_FPB); 
    14711455                        msg_pdbg("0xD0: 0x%08x (FPB)\n", tmp); 
    1472                         ich_set_bbar(ich_generation, 0); 
     1456                        ich_set_bbar(0); 
    14731457                } 
    14741458 
     
    15251509        /* Not sure if it speaks all these bus protocols. */ 
    15261510        buses_supported = BUS_LPC | BUS_FWH; 
     1511        ich_generation = CHIPSET_ICH7; 
    15271512        register_spi_programmer(&spi_programmer_via); 
    15281513 
     
    15571542        } 
    15581543 
    1559         ich_set_bbar(7, 0); 
     1544        ich_set_bbar(0); 
    15601545        ich_init_opcodes(); 
    15611546 
  • trunk/programmer.h

    r1459 r1460  
    580580/* ichspi.c */ 
    581581#if CONFIG_INTERNAL == 1 
     582enum ich_chipset { 
     583        CHIPSET_ICH_UNKNOWN, 
     584        CHIPSET_ICH7 = 7, 
     585        CHIPSET_ICH8, 
     586        CHIPSET_ICH9, 
     587        CHIPSET_ICH10, 
     588        CHIPSET_5_SERIES_IBEX_PEAK, 
     589        CHIPSET_6_SERIES_COUGAR_POINT, 
     590        CHIPSET_7_SERIES_PANTHER_POINT 
     591}; 
     592 
    582593extern uint32_t ichspi_bbar; 
    583594int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb, 
    584                     int ich_generation); 
     595                 enum ich_chipset ich_generation); 
    585596int via_init_spi(struct pci_dev *dev); 
    586597 
Note: See TracChangeset for help on using the changeset viewer.