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