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