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