Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 2 | * This file is part of the flashrom project. |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 3 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 4 | * Copyright (C) 2000 Silicon Integrated System Corporation |
| 5 | * Copyright (C) 2005-2007 coresystems GmbH <stepan@coresystems.de> |
| 6 | * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de> |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 7 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 11 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * Contains the chipset specific flash enables. |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #include <pci/pci.h> |
| 28 | #include <stdlib.h> |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 29 | #include "flash.h" |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 30 | |
Luc Verhaegen | 6b14175 | 2007-05-20 16:16:13 +0000 | [diff] [blame] | 31 | static int enable_flash_ali_m1533(struct pci_dev *dev, char *name) |
| 32 | { |
| 33 | uint8_t tmp; |
| 34 | |
| 35 | /* ROM Write enable, 0xFFFC0000-0xFFFDFFFF and |
| 36 | 0xFFFE0000-0xFFFFFFFF ROM select enable. */ |
| 37 | tmp = pci_read_byte(dev, 0x47); |
| 38 | tmp |= 0x46; |
| 39 | pci_write_byte(dev, 0x47, tmp); |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 44 | static int enable_flash_sis630(struct pci_dev *dev, char *name) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 45 | { |
| 46 | char b; |
| 47 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 48 | /* Enable 0xFFF8000~0xFFFF0000 decoding on SiS 540/630 */ |
| 49 | outl(0x80000840, 0x0cf8); |
| 50 | b = inb(0x0cfc) | 0x0b; |
| 51 | outb(b, 0xcfc); |
| 52 | /* Flash write enable on SiS 540/630 */ |
| 53 | outl(0x80000845, 0x0cf8); |
| 54 | b = inb(0x0cfd) | 0x40; |
| 55 | outb(b, 0xcfd); |
| 56 | |
| 57 | /* The same thing on SiS 950 SuperIO side */ |
| 58 | outb(0x87, 0x2e); |
| 59 | outb(0x01, 0x2e); |
| 60 | outb(0x55, 0x2e); |
| 61 | outb(0x55, 0x2e); |
| 62 | |
| 63 | if (inb(0x2f) != 0x87) { |
| 64 | outb(0x87, 0x4e); |
| 65 | outb(0x01, 0x4e); |
| 66 | outb(0x55, 0x4e); |
| 67 | outb(0xaa, 0x4e); |
| 68 | if (inb(0x4f) != 0x87) { |
| 69 | printf("Can not access SiS 950\n"); |
| 70 | return -1; |
| 71 | } |
| 72 | outb(0x24, 0x4e); |
| 73 | b = inb(0x4f) | 0xfc; |
| 74 | outb(0x24, 0x4e); |
| 75 | outb(b, 0x4f); |
| 76 | outb(0x02, 0x4e); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 77 | outb(0x02, 0x4f); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | outb(0x24, 0x2e); |
| 81 | printf("2f is %#x\n", inb(0x2f)); |
| 82 | b = inb(0x2f) | 0xfc; |
| 83 | outb(0x24, 0x2e); |
| 84 | outb(b, 0x2f); |
| 85 | |
| 86 | outb(0x02, 0x2e); |
| 87 | outb(0x02, 0x2f); |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
Uwe Hermann | 987942d | 2006-11-07 11:16:21 +0000 | [diff] [blame] | 92 | /* Datasheet: |
| 93 | * - Name: 82371AB PCI-TO-ISA / IDE XCELERATOR (PIIX4) |
| 94 | * - URL: http://www.intel.com/design/intarch/datashts/290562.htm |
| 95 | * - PDF: http://www.intel.com/design/intarch/datashts/29056201.pdf |
| 96 | * - Order Number: 290562-001 |
| 97 | */ |
Uwe Hermann | ea2c66d | 2006-11-05 18:26:08 +0000 | [diff] [blame] | 98 | static int enable_flash_piix4(struct pci_dev *dev, char *name) |
| 99 | { |
| 100 | uint16_t old, new; |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 101 | uint16_t xbcs = 0x4e; /* X-Bus Chip Select register. */ |
Uwe Hermann | ea2c66d | 2006-11-05 18:26:08 +0000 | [diff] [blame] | 102 | |
| 103 | old = pci_read_word(dev, xbcs); |
| 104 | |
| 105 | /* Set bit 9: 1-Meg Extended BIOS Enable (PCI master accesses to |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 106 | * FFF00000-FFF7FFFF are forwarded to ISA). |
| 107 | * Set bit 7: Extended BIOS Enable (PCI master accesses to |
| 108 | * FFF80000-FFFDFFFF are forwarded to ISA). |
| 109 | * Set bit 6: Lower BIOS Enable (PCI master, or ISA master accesses to |
| 110 | * the lower 64-Kbyte BIOS block (E0000-EFFFF) at the top |
| 111 | * of 1 Mbyte, or the aliases at the top of 4 Gbyte |
| 112 | * (FFFE0000-FFFEFFFF) result in the generation of BIOSCS#. |
| 113 | * Note: Accesses to FFFF0000-FFFFFFFF are always forwarded to ISA. |
| 114 | * Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable). |
| 115 | */ |
Uwe Hermann | ea2c66d | 2006-11-05 18:26:08 +0000 | [diff] [blame] | 116 | new = old | 0x2c4; |
| 117 | |
| 118 | if (new == old) |
| 119 | return 0; |
| 120 | |
| 121 | pci_write_word(dev, xbcs, new); |
| 122 | |
| 123 | if (pci_read_word(dev, xbcs) != new) { |
| 124 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name); |
| 125 | return -1; |
| 126 | } |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 127 | |
Uwe Hermann | ea2c66d | 2006-11-05 18:26:08 +0000 | [diff] [blame] | 128 | return 0; |
| 129 | } |
| 130 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 131 | static int enable_flash_ich(struct pci_dev *dev, char *name, int bios_cntl) |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 132 | { |
| 133 | /* register 4e.b gets or'ed with one */ |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 134 | uint8_t old, new; |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 135 | |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 136 | /* if it fails, it fails. There are so many variations of broken mobos |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 137 | * that it is hard to argue that we should quit at this point. |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 138 | */ |
| 139 | |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 140 | /* Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, but |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 141 | * just treating it as 8 bit wide seems to work fine in practice. |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 142 | */ |
| 143 | |
| 144 | /* see ie. page 375 of "Intel ICH7 External Design Specification" |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 145 | * http://download.intel.com/design/chipsets/datashts/30701302.pdf |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 146 | */ |
| 147 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 148 | old = pci_read_byte(dev, bios_cntl); |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 149 | |
| 150 | new = old | 1; |
| 151 | |
| 152 | if (new == old) |
| 153 | return 0; |
| 154 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 155 | pci_write_byte(dev, bios_cntl, new); |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 156 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 157 | if (pci_read_byte(dev, bios_cntl) != new) { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 158 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", bios_cntl, new, name); |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 159 | return -1; |
| 160 | } |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 161 | |
Ronald G. Minnich | 6a96741 | 2004-09-28 20:09:06 +0000 | [diff] [blame] | 162 | return 0; |
| 163 | } |
| 164 | |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 165 | static int enable_flash_ich_4e(struct pci_dev *dev, char *name) |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 166 | { |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 167 | return enable_flash_ich(dev, name, 0x4e); |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 170 | static int enable_flash_ich_dc(struct pci_dev *dev, char *name) |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 171 | { |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 172 | return enable_flash_ich(dev, name, 0xdc); |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 175 | static int enable_flash_vt823x(struct pci_dev *dev, char *name) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 176 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 177 | uint8_t val; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 178 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 179 | /* ROM write enable */ |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 180 | val = pci_read_byte(dev, 0x40); |
| 181 | val |= 0x10; |
| 182 | pci_write_byte(dev, 0x40, val); |
| 183 | |
| 184 | if (pci_read_byte(dev, 0x40) != val) { |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 185 | printf("\nWARNING: Failed to enable ROM Write on \"%s\"\n", |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 186 | name); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 187 | return -1; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 188 | } |
Luc Verhaegen | 6382b44 | 2007-03-02 22:16:38 +0000 | [diff] [blame] | 189 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 190 | return 0; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static int enable_flash_cs5530(struct pci_dev *dev, char *name) |
| 194 | { |
Uwe Hermann | f4a673b | 2007-06-06 21:35:45 +0000 | [diff] [blame] | 195 | uint8_t reg8; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 196 | |
Uwe Hermann | f4a673b | 2007-06-06 21:35:45 +0000 | [diff] [blame] | 197 | #define DECODE_CONTROL_REG2 0x5b /* F0 index 0x5b */ |
| 198 | #define ROM_AT_LOGIC_CONTROL_REG 0x52 /* F0 index 0x52 */ |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 199 | |
Uwe Hermann | f4a673b | 2007-06-06 21:35:45 +0000 | [diff] [blame] | 200 | #define LOWER_ROM_ADDRESS_RANGE (1 << 0) |
| 201 | #define ROM_WRITE_ENABLE (1 << 1) |
| 202 | #define UPPER_ROM_ADDRESS_RANGE (1 << 2) |
| 203 | #define BIOS_ROM_POSITIVE_DECODE (1 << 5) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 204 | |
Uwe Hermann | f4a673b | 2007-06-06 21:35:45 +0000 | [diff] [blame] | 205 | /* Decode 0x000E0000-0x000FFFFF (128 KB), not just 64 KB, and |
| 206 | * decode 0xFF000000-0xFFFFFFFF (16 MB), not just 256 KB. |
| 207 | * Make the configured ROM areas writable. |
| 208 | */ |
| 209 | reg8 = pci_read_byte(dev, ROM_AT_LOGIC_CONTROL_REG); |
| 210 | reg8 |= LOWER_ROM_ADDRESS_RANGE; |
| 211 | reg8 |= UPPER_ROM_ADDRESS_RANGE; |
| 212 | reg8 |= ROM_WRITE_ENABLE; |
| 213 | pci_write_byte(dev, ROM_AT_LOGIC_CONTROL_REG, reg8); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 214 | |
Uwe Hermann | f4a673b | 2007-06-06 21:35:45 +0000 | [diff] [blame] | 215 | /* Set positive decode on ROM. */ |
| 216 | reg8 = pci_read_byte(dev, DECODE_CONTROL_REG2); |
| 217 | reg8 |= BIOS_ROM_POSITIVE_DECODE; |
| 218 | pci_write_byte(dev, DECODE_CONTROL_REG2, reg8); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 219 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | static int enable_flash_sc1100(struct pci_dev *dev, char *name) |
| 224 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 225 | uint8_t new; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 226 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 227 | pci_write_byte(dev, 0x52, 0xee); |
| 228 | |
| 229 | new = pci_read_byte(dev, 0x52); |
| 230 | |
| 231 | if (new != 0xee) { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 232 | printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x52, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 233 | return -1; |
| 234 | } |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 235 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | static int enable_flash_sis5595(struct pci_dev *dev, char *name) |
| 240 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 241 | uint8_t new, newer; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 242 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 243 | new = pci_read_byte(dev, 0x45); |
| 244 | |
| 245 | /* clear bit 5 */ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 246 | new &= (~0x20); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 247 | /* set bit 2 */ |
| 248 | new |= 0x4; |
| 249 | |
| 250 | pci_write_byte(dev, 0x45, new); |
| 251 | |
| 252 | newer = pci_read_byte(dev, 0x45); |
| 253 | if (newer != new) { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 254 | printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 255 | printf("Stuck at 0x%x\n", newer); |
| 256 | return -1; |
| 257 | } |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 258 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 259 | return 0; |
| 260 | } |
| 261 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 262 | static int enable_flash_amd8111(struct pci_dev *dev, char *name) |
| 263 | { |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 264 | /* register 4e.b gets or'ed with one */ |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 265 | uint8_t old, new; |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 266 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 267 | /* if it fails, it fails. There are so many variations of broken mobos |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 268 | * that it is hard to argue that we should quit at this point. |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 269 | */ |
| 270 | |
Ollie Lho | d11f361 | 2004-12-07 17:19:04 +0000 | [diff] [blame] | 271 | /* enable decoding at 0xffb00000 to 0xffffffff */ |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 272 | old = pci_read_byte(dev, 0x43); |
Ollie Lho | d11f361 | 2004-12-07 17:19:04 +0000 | [diff] [blame] | 273 | new = old | 0xC0; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 274 | if (new != old) { |
| 275 | pci_write_byte(dev, 0x43, new); |
| 276 | if (pci_read_byte(dev, 0x43) != new) { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 277 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x43, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 281 | old = pci_read_byte(dev, 0x40); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 282 | new = old | 0x01; |
| 283 | if (new == old) |
| 284 | return 0; |
| 285 | pci_write_byte(dev, 0x40, new); |
| 286 | |
| 287 | if (pci_read_byte(dev, 0x40) != new) { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 288 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 289 | return -1; |
| 290 | } |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 291 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 292 | return 0; |
| 293 | } |
| 294 | |
Yinghai Lu | 952dfce | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 295 | static int enable_flash_ck804(struct pci_dev *dev, char *name) |
| 296 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 297 | /* register 4e.b gets or'ed with one */ |
| 298 | uint8_t old, new; |
Yinghai Lu | 952dfce | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 299 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 300 | /* if it fails, it fails. There are so many variations of broken mobos |
| 301 | * that it is hard to argue that we should quit at this point. |
| 302 | */ |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 303 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 304 | /* dump_pci_device(dev); */ |
Yinghai Lu | 952dfce | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 305 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 306 | old = pci_read_byte(dev, 0x88); |
| 307 | new = old | 0xc0; |
| 308 | if (new != old) { |
| 309 | pci_write_byte(dev, 0x88, new); |
| 310 | if (pci_read_byte(dev, 0x88) != new) { |
| 311 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x88, new, name); |
| 312 | } |
| 313 | } |
Yinghai Lu | 952dfce | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 314 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 315 | old = pci_read_byte(dev, 0x6d); |
| 316 | new = old | 0x01; |
| 317 | if (new == old) |
| 318 | return 0; |
| 319 | pci_write_byte(dev, 0x6d, new); |
| 320 | |
| 321 | if (pci_read_byte(dev, 0x6d) != new) { |
| 322 | printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name); |
| 323 | return -1; |
| 324 | } |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 325 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 326 | return 0; |
Yinghai Lu | 952dfce | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 329 | static int enable_flash_sb400(struct pci_dev *dev, char *name) |
| 330 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 331 | uint8_t tmp; |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 332 | |
| 333 | struct pci_filter f; |
| 334 | struct pci_dev *smbusdev; |
| 335 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 336 | /* then look for the smbus device */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 337 | pci_filter_init((struct pci_access *)0, &f); |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 338 | f.vendor = 0x1002; |
| 339 | f.device = 0x4372; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 340 | |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 341 | for (smbusdev = pacc->devices; smbusdev; smbusdev = smbusdev->next) { |
| 342 | if (pci_filter_match(&f, smbusdev)) { |
| 343 | break; |
| 344 | } |
| 345 | } |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 346 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 347 | if (!smbusdev) { |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 348 | fprintf(stderr, "ERROR: SMBus device not found. aborting\n"); |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 349 | exit(1); |
| 350 | } |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 351 | |
| 352 | /* enable some smbus stuff */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 353 | tmp = pci_read_byte(smbusdev, 0x79); |
| 354 | tmp |= 0x01; |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 355 | pci_write_byte(smbusdev, 0x79, tmp); |
| 356 | |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 357 | /* change southbridge */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 358 | tmp = pci_read_byte(dev, 0x48); |
| 359 | tmp |= 0x21; |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 360 | pci_write_byte(dev, 0x48, tmp); |
| 361 | |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 362 | /* now become a bit silly. */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 363 | tmp = inb(0xc6f); |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 364 | outb(tmp, 0xeb); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 365 | outb(tmp, 0xeb); |
| 366 | tmp |= 0x40; |
Stefan Reinauer | 86de283 | 2006-03-31 11:26:55 +0000 | [diff] [blame] | 367 | outb(tmp, 0xc6f); |
| 368 | outb(tmp, 0xeb); |
| 369 | outb(tmp, 0xeb); |
| 370 | |
| 371 | return 0; |
| 372 | } |
| 373 | |
Yinghai Lu | ca78297 | 2007-01-22 20:21:17 +0000 | [diff] [blame] | 374 | static int enable_flash_mcp55(struct pci_dev *dev, char *name) |
| 375 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 376 | /* register 4e.b gets or'ed with one */ |
| 377 | unsigned char old, new, byte; |
| 378 | unsigned short word; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 379 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 380 | /* if it fails, it fails. There are so many variations of broken mobos |
| 381 | * that it is hard to argue that we should quit at this point. |
| 382 | */ |
Yinghai Lu | ca78297 | 2007-01-22 20:21:17 +0000 | [diff] [blame] | 383 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 384 | /* dump_pci_device(dev); */ |
Yinghai Lu | ca78297 | 2007-01-22 20:21:17 +0000 | [diff] [blame] | 385 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 386 | /* Set the 4MB enable bit bit */ |
| 387 | byte = pci_read_byte(dev, 0x88); |
| 388 | byte |= 0xff; /* 256K */ |
| 389 | pci_write_byte(dev, 0x88, byte); |
| 390 | byte = pci_read_byte(dev, 0x8c); |
| 391 | byte |= 0xff; /* 1M */ |
| 392 | pci_write_byte(dev, 0x8c, byte); |
| 393 | word = pci_read_word(dev, 0x90); |
| 394 | word |= 0x7fff; /* 15M */ |
| 395 | pci_write_word(dev, 0x90, word); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 396 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 397 | old = pci_read_byte(dev, 0x6d); |
| 398 | new = old | 0x01; |
| 399 | if (new == old) |
| 400 | return 0; |
| 401 | pci_write_byte(dev, 0x6d, new); |
Yinghai Lu | ca78297 | 2007-01-22 20:21:17 +0000 | [diff] [blame] | 402 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 403 | if (pci_read_byte(dev, 0x6d) != new) { |
| 404 | printf |
| 405 | ("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", |
| 406 | 0x6d, new, name); |
| 407 | return -1; |
| 408 | } |
Yinghai Lu | ca78297 | 2007-01-22 20:21:17 +0000 | [diff] [blame] | 409 | |
| 410 | return 0; |
Yinghai Lu | ca78297 | 2007-01-22 20:21:17 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Stefan Reinauer | c868b9e | 2007-06-05 10:28:39 +0000 | [diff] [blame] | 413 | static int enable_flash_ht1000(struct pci_dev *dev, char *name) |
| 414 | { |
Uwe Hermann | e823ee0 | 2007-06-05 15:02:18 +0000 | [diff] [blame] | 415 | uint8_t byte; |
Stefan Reinauer | c868b9e | 2007-06-05 10:28:39 +0000 | [diff] [blame] | 416 | |
Uwe Hermann | e823ee0 | 2007-06-05 15:02:18 +0000 | [diff] [blame] | 417 | /* Set the 4MB enable bit. */ |
Stefan Reinauer | c868b9e | 2007-06-05 10:28:39 +0000 | [diff] [blame] | 418 | byte = pci_read_byte(dev, 0x41); |
| 419 | byte |= 0x0e; |
| 420 | pci_write_byte(dev, 0x41, byte); |
| 421 | |
| 422 | byte = pci_read_byte(dev, 0x43); |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 423 | byte |= (1 << 4); |
Stefan Reinauer | c868b9e | 2007-06-05 10:28:39 +0000 | [diff] [blame] | 424 | pci_write_byte(dev, 0x43, byte); |
| 425 | |
Stefan Reinauer | c868b9e | 2007-06-05 10:28:39 +0000 | [diff] [blame] | 426 | return 0; |
| 427 | } |
| 428 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 429 | typedef struct penable { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 430 | unsigned short vendor, device; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 431 | char *name; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 432 | int (*doit) (struct pci_dev * dev, char *name); |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 433 | } FLASH_ENABLE; |
| 434 | |
| 435 | static FLASH_ENABLE enables[] = { |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 436 | {0x1039, 0x0630, "SIS630", enable_flash_sis630}, |
Uwe Hermann | ea2c66d | 2006-11-05 18:26:08 +0000 | [diff] [blame] | 437 | {0x8086, 0x7110, "PIIX4/PIIX4E/PIIX4M", enable_flash_piix4}, |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 438 | {0x8086, 0x2410, "ICH", enable_flash_ich_4e}, |
| 439 | {0x8086, 0x2420, "ICH0", enable_flash_ich_4e}, |
| 440 | {0x8086, 0x2440, "ICH2", enable_flash_ich_4e}, |
| 441 | {0x8086, 0x244c, "ICH2-M", enable_flash_ich_4e}, |
| 442 | {0x8086, 0x2480, "ICH3-S", enable_flash_ich_4e}, |
| 443 | {0x8086, 0x248c, "ICH3-M", enable_flash_ich_4e}, |
| 444 | {0x8086, 0x24c0, "ICH4/ICH4-L", enable_flash_ich_4e}, |
| 445 | {0x8086, 0x24cc, "ICH4-M", enable_flash_ich_4e}, |
| 446 | {0x8086, 0x24d0, "ICH5/ICH5R", enable_flash_ich_4e}, |
| 447 | {0x8086, 0x2640, "ICH6/ICH6R", enable_flash_ich_dc}, |
| 448 | {0x8086, 0x2641, "ICH6-M", enable_flash_ich_dc}, |
Uwe Hermann | 3ad2518 | 2007-03-31 19:48:38 +0000 | [diff] [blame] | 449 | {0x8086, 0x27b0, "ICH7DH", enable_flash_ich_dc}, |
Stefan Reinauer | eb36647 | 2006-09-06 15:48:48 +0000 | [diff] [blame] | 450 | {0x8086, 0x27b8, "ICH7/ICH7R", enable_flash_ich_dc}, |
| 451 | {0x8086, 0x27b9, "ICH7M", enable_flash_ich_dc}, |
| 452 | {0x8086, 0x27bd, "ICH7MDH", enable_flash_ich_dc}, |
| 453 | {0x8086, 0x2810, "ICH8/ICH8R", enable_flash_ich_dc}, |
| 454 | {0x8086, 0x2812, "ICH8DH", enable_flash_ich_dc}, |
| 455 | {0x8086, 0x2814, "ICH8DO", enable_flash_ich_dc}, |
Luc Verhaegen | 6382b44 | 2007-03-02 22:16:38 +0000 | [diff] [blame] | 456 | {0x1106, 0x8231, "VT8231", enable_flash_vt823x}, |
| 457 | {0x1106, 0x3177, "VT8235", enable_flash_vt823x}, |
| 458 | {0x1106, 0x3227, "VT8237", enable_flash_vt823x}, |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 459 | {0x1106, 0x8324, "CX700", enable_flash_vt823x}, |
Stefan Reinauer | c6b5f49 | 2006-11-07 10:22:20 +0000 | [diff] [blame] | 460 | {0x1106, 0x0686, "VT82C686", enable_flash_amd8111}, |
Uwe Hermann | f4a673b | 2007-06-06 21:35:45 +0000 | [diff] [blame] | 461 | {0x1078, 0x0100, "CS5530/CS5530A", enable_flash_cs5530}, |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 462 | {0x100b, 0x0510, "SC1100", enable_flash_sc1100}, |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 463 | {0x1039, 0x0008, "SIS5595", enable_flash_sis5595}, |
| 464 | {0x1022, 0x7468, "AMD8111", enable_flash_amd8111}, |
Luc Verhaegen | 6b14175 | 2007-05-20 16:16:13 +0000 | [diff] [blame] | 465 | {0x10B9, 0x1533, "ALi M1533", enable_flash_ali_m1533}, |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 466 | /* this fallthrough looks broken. */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 467 | {0x10de, 0x0050, "NVIDIA CK804", enable_flash_ck804}, /* LPC */ |
| 468 | {0x10de, 0x0051, "NVIDIA CK804", enable_flash_ck804}, /* Pro */ |
| 469 | {0x10de, 0x00d3, "NVIDIA CK804", enable_flash_ck804}, /* Slave, should not be here, to fix known bug for A01. */ |
Stefan Reinauer | 219b61e | 2006-10-14 21:04:49 +0000 | [diff] [blame] | 470 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 471 | {0x10de, 0x0260, "NVidia MCP51", enable_flash_ck804}, |
| 472 | {0x10de, 0x0261, "NVidia MCP51", enable_flash_ck804}, |
| 473 | {0x10de, 0x0262, "NVidia MCP51", enable_flash_ck804}, |
| 474 | {0x10de, 0x0263, "NVidia MCP51", enable_flash_ck804}, |
Stefan Reinauer | 219b61e | 2006-10-14 21:04:49 +0000 | [diff] [blame] | 475 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 476 | {0x10de, 0x0360, "NVIDIA MCP55", enable_flash_mcp55}, /* Gigabyte m57sli-s4 */ |
| 477 | {0x10de, 0x0361, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */ |
| 478 | {0x10de, 0x0362, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */ |
| 479 | {0x10de, 0x0363, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */ |
| 480 | {0x10de, 0x0364, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */ |
| 481 | {0x10de, 0x0365, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */ |
| 482 | {0x10de, 0x0366, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */ |
| 483 | {0x10de, 0x0367, "NVIDIA MCP55", enable_flash_mcp55}, /* Pro */ |
Yinghai Lu | ca78297 | 2007-01-22 20:21:17 +0000 | [diff] [blame] | 484 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 485 | {0x1002, 0x4377, "ATI SB400", enable_flash_sb400}, /* ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80) */ |
Stefan Reinauer | c868b9e | 2007-06-05 10:28:39 +0000 | [diff] [blame] | 486 | |
Uwe Hermann | e823ee0 | 2007-06-05 15:02:18 +0000 | [diff] [blame] | 487 | {0x1166, 0x0205, "Broadcom HT-1000", enable_flash_ht1000}, |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 488 | }; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 489 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 490 | int chipset_flash_enable(void) |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 491 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 492 | struct pci_dev *dev = 0; |
| 493 | int ret = -2; /* nothing! */ |
| 494 | int i; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 495 | |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 496 | /* now let's try to find the chipset we have ... */ |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 497 | for (i = 0; i < sizeof(enables) / sizeof(enables[0]); i++) { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 498 | dev = pci_dev_find(enables[i].vendor, enables[i].device); |
| 499 | if (dev) |
| 500 | break; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 503 | if (dev) { |
| 504 | printf("Found chipset \"%s\": Enabling flash write... ", |
| 505 | enables[i].name); |
| 506 | |
| 507 | ret = enables[i].doit(dev, enables[i].name); |
| 508 | if (ret) |
| 509 | printf("Failed!\n"); |
| 510 | else |
| 511 | printf("OK.\n"); |
| 512 | } |
| 513 | |
| 514 | return ret; |
Ollie Lho | cbbf125 | 2004-03-17 22:22:08 +0000 | [diff] [blame] | 515 | } |