Changeset 906 for trunk/chipset_enable.c


Ignore:
Timestamp:
Feb 18, 2010 1:24:38 PM (3 years ago)
Author:
hailfinger
Message:

Refactor MCP SPI detection:

  • Set supported buses based on ISA bridge reg 0x8a
  • Use MCP55 chipset enable only if LPC is detected
  • Allow LPC on MCP61
  • Eliminate duplicated code where possible

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/chipset_enable.c

    r902 r906  
    10551055} 
    10561056 
    1057 /** 
    1058  * The MCP67 code is guesswork based on cleanroom reverse engineering. 
    1059  * Due to that, it only reads info and doesn't change any settings. 
    1060  * It is assumed that LPC chips need the MCP55 code and SPI chips need the 
    1061  * code provided in this function. Until we know for sure, call 
    1062  * enable_flash_mcp55 from this function. Warning: enable_flash_mcp55 
    1063  * might make SPI flash inaccessible. The same caveat applies to SPI init 
    1064  * for LPC flash. 
     1057/* This is a shot in the dark. Even if the code is totally bogus for some 
     1058 * chipsets, users will at least start to send in reports. 
    10651059 */ 
    1066 static int enable_flash_mcp67(struct pci_dev *dev, const char *name) 
    1067 { 
    1068         int result = 0; 
     1060static int enable_flash_mcp6x_7x_common(struct pci_dev *dev, const char *name) 
     1061{ 
     1062        int ret = 0; 
    10691063        uint8_t byte; 
    10701064        uint16_t status; 
     1065        char *busname; 
    10711066        uint32_t mcp_spibaraddr; 
    10721067        void *mcp_spibar; 
    10731068        struct pci_dev *smbusdev; 
    10741069 
     1070        msg_pinfo("This chipset is not really supported yet. Guesswork...\n"); 
     1071 
    10751072        /* dev is the ISA bridge. No idea what the stuff below does. */ 
    10761073        byte = pci_read_byte(dev, 0x8a); 
    1077         msg_pdbg("ISA bridge reg 0x8a contents: 0x%02x, bit 6 is %i, bit 5 is " 
    1078                  "%i\n", byte, (byte >> 6) & 0x1, (byte >> 5) & 0x1); 
    1079         msg_pdbg("Guessed flash bus type is %s\n", ((byte >> 5) & 0x3) == 0x2 ? 
    1080                  "SPI" : "unknown, probably LPC"); 
    1081         /* Disable the write code for now until we have more info. */ 
     1074        msg_pdbg("ISA/LPC bridge reg 0x8a contents: 0x%02x, bit 6 is %i, bit 5 " 
     1075                 "is %i\n", byte, (byte >> 6) & 0x1, (byte >> 5) & 0x1); 
     1076        switch ((byte >> 5) & 0x3) { 
     1077        case 0x0: 
     1078                buses_supported = CHIP_BUSTYPE_LPC; 
     1079                break; 
     1080        case 0x2: 
     1081                buses_supported = CHIP_BUSTYPE_SPI; 
     1082                break; 
     1083        default: 
     1084                buses_supported = CHIP_BUSTYPE_UNKNOWN; 
     1085                break; 
     1086        } 
     1087        busname = flashbuses_to_text(buses_supported); 
     1088        msg_pdbg("Guessed flash bus type is %s\n", busname); 
     1089        free(busname); 
     1090 
     1091        /* Force enable SPI and disable LPC? Not a good idea. */ 
    10821092#if 0 
    10831093        byte |= (1 << 6); 
     
    10891099        smbusdev = pci_dev_find_vendorclass(0x10de, 0x0c05); 
    10901100        if (!smbusdev) { 
    1091                 msg_perr("ERROR: SMBus device not found. Aborting.\n"); 
    1092                 exit(1); 
     1101                if (buses_supported & CHIP_BUSTYPE_SPI) { 
     1102                        msg_perr("ERROR: SMBus device not found. Not enabling " 
     1103                                 "SPI.\n"); 
     1104                        buses_supported &= ~CHIP_BUSTYPE_SPI; 
     1105                        ret = 1; 
     1106                } else { 
     1107                        msg_pinfo("Odd. SMBus device not found.\n"); 
     1108                } 
     1109                goto out_msg; 
    10931110        } 
    10941111        msg_pdbg("Found SMBus device %04x:%04x at %02x:%02x:%01x\n", 
     
    11091126 
    11101127        /* Accessing a NULL pointer BAR is evil. Don't do it. */ 
    1111         if (mcp_spibaraddr) { 
     1128        if (mcp_spibaraddr && (buses_supported == CHIP_BUSTYPE_SPI)) { 
    11121129                /* Map the BAR. Bytewise/wordwise access at 0x530 and 0x540. */ 
    11131130                mcp_spibar = physmap("MCP67 SPI", mcp_spibaraddr, 0x544); 
     
    11261143                /* FIXME: Remove the physunmap once the SPI driver exists. */ 
    11271144                physunmap(mcp_spibar, 0x544); 
     1145        } else if (!mcp_spibaraddr && (buses_supported & CHIP_BUSTYPE_SPI)) { 
     1146                msg_pdbg("Strange. MCP SPI BAR is invalid.\n"); 
     1147                buses_supported &= ~CHIP_BUSTYPE_SPI; 
     1148                ret = 1; 
     1149        } else if (mcp_spibaraddr && !(buses_supported & CHIP_BUSTYPE_SPI)) { 
     1150                msg_pdbg("Strange. MCP SPI BAR is valid, but chipset apparently" 
     1151                         " doesn't have SPI enabled.\n"); 
    11281152        } else { 
    1129                 msg_pdbg("Strange. MCP67 SPI BAR is invalid.\n"); 
    1130         } 
     1153                msg_pdbg("MCP SPI is not used.\n"); 
     1154        } 
     1155out_msg: 
    11311156        msg_pinfo("Please send the output of \"flashrom -V\" to " 
    11321157                  "flashrom@flashrom.org to help us finish support for your " 
    11331158                  "chipset. Thanks.\n"); 
    11341159 
    1135         /* Not sure if this is still correct. No docs as usual. */ 
    1136         result = enable_flash_mcp55(dev, name); 
     1160        return ret; 
     1161} 
     1162 
     1163/** 
     1164 * The MCP61/MCP67 code is guesswork based on cleanroom reverse engineering. 
     1165 * Due to that, it only reads info and doesn't change any settings. 
     1166 * It is assumed that LPC chips need the MCP55 code and SPI chips need the 
     1167 * code provided in enable_flash_mcp6x_7x_common. Until we know for sure, call 
     1168 * enable_flash_mcp55 from this function only if enable_flash_mcp6x_7x_common 
     1169 * indicates the flash chip is LPC. Warning: enable_flash_mcp55 
     1170 * might make SPI flash inaccessible. The same caveat applies to SPI init 
     1171 * for LPC flash. 
     1172 */ 
     1173static int enable_flash_mcp67(struct pci_dev *dev, const char *name) 
     1174{ 
     1175        int result = 0; 
     1176 
     1177        result = enable_flash_mcp6x_7x_common(dev, name); 
     1178        if (result) 
     1179                return result; 
     1180 
     1181        /* Not sure if this is correct. No docs as usual. */ 
     1182        switch (buses_supported) { 
     1183        case CHIP_BUSTYPE_LPC: 
     1184                result = enable_flash_mcp55(dev, name); 
     1185                break; 
     1186        case CHIP_BUSTYPE_SPI: 
     1187                msg_pinfo("SPI on this chipset is not supported yet.\n"); 
     1188                buses_supported = CHIP_BUSTYPE_NONE; 
     1189                break; 
     1190        default: 
     1191                msg_pinfo("Something went wrong with bus type detection.\n"); 
     1192                buses_supported = CHIP_BUSTYPE_NONE; 
     1193                break; 
     1194        } 
    11371195 
    11381196        return result; 
    11391197} 
    11401198 
    1141 /* This is a shot in the dark. Even if the code is totally bogus for some 
    1142  * chipsets, users will at least start to send in reports. 
    1143  */ 
    11441199static int enable_flash_mcp7x(struct pci_dev *dev, const char *name) 
    11451200{ 
    1146         uint8_t byte; 
    1147         uint32_t mcp_spibaraddr; 
    1148         struct pci_dev *smbusdev; 
    1149  
    1150         msg_pinfo("This chipset is not really supported yet. Guesswork...\n"); 
    1151  
    1152         /* dev is the ISA bridge. No idea what the stuff below does. */ 
    1153         byte = pci_read_byte(dev, 0x8a); 
    1154         msg_pdbg("ISA/LPC bridge reg 0x8a contents: 0x%02x, bit 6 is %i, bit 5 " 
    1155                  "is %i\n", byte, (byte >> 6) & 0x1, (byte >> 5) & 0x1); 
    1156  
    1157         /* Look for the SMBus device (SMBus PCI class) */ 
    1158         smbusdev = pci_dev_find_vendorclass(0x10de, 0x0c05); 
    1159         if (!smbusdev) { 
    1160                 msg_perr("ERROR: SMBus device not found. Aborting.\n"); 
    1161                 exit(1); 
    1162         } 
    1163         msg_pdbg("Found SMBus device %04x:%04x at %02x:%02x:%01x\n", 
    1164                 smbusdev->vendor_id, smbusdev->device_id, 
    1165                 smbusdev->bus, smbusdev->dev, smbusdev->func); 
    1166  
    1167         /* Locate the BAR where the SPI interface lives. */ 
    1168         mcp_spibaraddr = pci_read_long(smbusdev, 0x74); 
    1169         msg_pdbg("SPI BAR is at 0x%08x, ", mcp_spibaraddr); 
    1170  
    1171         msg_pinfo("Please send the output of \"flashrom -V\" to " 
    1172                   "flashrom@flashrom.org to help us finish support for your " 
    1173                   "chipset. Thanks.\n"); 
    1174  
    1175         return 0; 
     1201        int result = 0; 
     1202 
     1203        result = enable_flash_mcp6x_7x_common(dev, name); 
     1204        if (result) 
     1205                return result; 
     1206 
     1207        /* Not sure if this is correct. No docs as usual. */ 
     1208        switch (buses_supported) { 
     1209        case CHIP_BUSTYPE_LPC: 
     1210                msg_pinfo("LPC on this chipset is not supported yet.\n"); 
     1211                break; 
     1212        case CHIP_BUSTYPE_SPI: 
     1213                msg_pinfo("SPI on this chipset is not supported yet.\n"); 
     1214                buses_supported = CHIP_BUSTYPE_NONE; 
     1215                break; 
     1216        default: 
     1217                msg_pinfo("Something went wrong with bus type detection.\n"); 
     1218                buses_supported = CHIP_BUSTYPE_NONE; 
     1219                break; 
     1220        } 
     1221 
     1222        return result; 
    11761223} 
    11771224 
     
    13151362        {0x10de, 0x0366, OK, "NVIDIA", "MCP55",         enable_flash_mcp55}, /* LPC */ 
    13161363        {0x10de, 0x0367, OK, "NVIDIA", "MCP55",         enable_flash_mcp55}, /* Pro */ 
    1317         {0x10de, 0x03e0, NT, "NVIDIA", "MCP61",         enable_flash_mcp7x}, 
    1318         {0x10de, 0x03e1, NT, "NVIDIA", "MCP61",         enable_flash_mcp7x}, 
    1319         {0x10de, 0x03e2, NT, "NVIDIA", "MCP61",         enable_flash_mcp7x}, 
    1320         {0x10de, 0x03e3, NT, "NVIDIA", "MCP61",         enable_flash_mcp7x}, 
     1364        {0x10de, 0x03e0, NT, "NVIDIA", "MCP61",         enable_flash_mcp67}, 
     1365        {0x10de, 0x03e1, NT, "NVIDIA", "MCP61",         enable_flash_mcp67}, 
     1366        {0x10de, 0x03e2, NT, "NVIDIA", "MCP61",         enable_flash_mcp67}, 
     1367        {0x10de, 0x03e3, NT, "NVIDIA", "MCP61",         enable_flash_mcp67}, 
    13211368        {0x10de, 0x0440, NT, "NVIDIA", "MCP65",         enable_flash_mcp7x}, 
    13221369        {0x10de, 0x0441, NT, "NVIDIA", "MCP65",         enable_flash_mcp7x}, 
Note: See TracChangeset for help on using the changeset viewer.