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