blob: 3b8014937d54e8974d163b3357e4c8ef152c5efe [file] [log] [blame]
Ollie Lho184a4042005-11-26 21:55:36 +00001/*
2 * flash rom utility: enable flash writes
3 *
Luc Verhaegen8e3a6002007-04-04 22:45:58 +00004 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2005-2007 coresystems GmbH <stepan@coresystems.de>
Stefan Reinauereb366472006-09-06 15:48:48 +00006 * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de>
Ollie Lho184a4042005-11-26 21:55:36 +00007 *
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 Lhocbbf1252004-03-17 22:22:08 +000014#include <stdio.h>
15#include <pci/pci.h>
16#include <stdlib.h>
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000017#include "flash.h"
Stefan Reinauer86de2832006-03-31 11:26:55 +000018
Luc Verhaegen6b141752007-05-20 16:16:13 +000019static int enable_flash_ali_m1533(struct pci_dev *dev, char *name)
20{
21 uint8_t tmp;
22
23 /* ROM Write enable, 0xFFFC0000-0xFFFDFFFF and
24 0xFFFE0000-0xFFFFFFFF ROM select enable. */
25 tmp = pci_read_byte(dev, 0x47);
26 tmp |= 0x46;
27 pci_write_byte(dev, 0x47, tmp);
28
29 return 0;
30}
31
Ollie Lho761bf1b2004-03-20 16:46:10 +000032static int enable_flash_sis630(struct pci_dev *dev, char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +000033{
34 char b;
35
Ollie Lhocbbf1252004-03-17 22:22:08 +000036 /* Enable 0xFFF8000~0xFFFF0000 decoding on SiS 540/630 */
37 outl(0x80000840, 0x0cf8);
38 b = inb(0x0cfc) | 0x0b;
39 outb(b, 0xcfc);
40 /* Flash write enable on SiS 540/630 */
41 outl(0x80000845, 0x0cf8);
42 b = inb(0x0cfd) | 0x40;
43 outb(b, 0xcfd);
44
45 /* The same thing on SiS 950 SuperIO side */
46 outb(0x87, 0x2e);
47 outb(0x01, 0x2e);
48 outb(0x55, 0x2e);
49 outb(0x55, 0x2e);
50
51 if (inb(0x2f) != 0x87) {
52 outb(0x87, 0x4e);
53 outb(0x01, 0x4e);
54 outb(0x55, 0x4e);
55 outb(0xaa, 0x4e);
56 if (inb(0x4f) != 0x87) {
57 printf("Can not access SiS 950\n");
58 return -1;
59 }
60 outb(0x24, 0x4e);
61 b = inb(0x4f) | 0xfc;
62 outb(0x24, 0x4e);
63 outb(b, 0x4f);
64 outb(0x02, 0x4e);
Ollie Lho761bf1b2004-03-20 16:46:10 +000065 outb(0x02, 0x4f);
Ollie Lhocbbf1252004-03-17 22:22:08 +000066 }
67
68 outb(0x24, 0x2e);
69 printf("2f is %#x\n", inb(0x2f));
70 b = inb(0x2f) | 0xfc;
71 outb(0x24, 0x2e);
72 outb(b, 0x2f);
73
74 outb(0x02, 0x2e);
75 outb(0x02, 0x2f);
76
77 return 0;
78}
79
Uwe Hermann987942d2006-11-07 11:16:21 +000080/* Datasheet:
81 * - Name: 82371AB PCI-TO-ISA / IDE XCELERATOR (PIIX4)
82 * - URL: http://www.intel.com/design/intarch/datashts/290562.htm
83 * - PDF: http://www.intel.com/design/intarch/datashts/29056201.pdf
84 * - Order Number: 290562-001
85 */
Uwe Hermannea2c66d2006-11-05 18:26:08 +000086static int enable_flash_piix4(struct pci_dev *dev, char *name)
87{
88 uint16_t old, new;
Uwe Hermanna7e05482007-05-09 10:17:44 +000089 uint16_t xbcs = 0x4e; /* X-Bus Chip Select register. */
Uwe Hermannea2c66d2006-11-05 18:26:08 +000090
91 old = pci_read_word(dev, xbcs);
92
93 /* Set bit 9: 1-Meg Extended BIOS Enable (PCI master accesses to
Uwe Hermanna7e05482007-05-09 10:17:44 +000094 * FFF00000-FFF7FFFF are forwarded to ISA).
95 * Set bit 7: Extended BIOS Enable (PCI master accesses to
96 * FFF80000-FFFDFFFF are forwarded to ISA).
97 * Set bit 6: Lower BIOS Enable (PCI master, or ISA master accesses to
98 * the lower 64-Kbyte BIOS block (E0000-EFFFF) at the top
99 * of 1 Mbyte, or the aliases at the top of 4 Gbyte
100 * (FFFE0000-FFFEFFFF) result in the generation of BIOSCS#.
101 * Note: Accesses to FFFF0000-FFFFFFFF are always forwarded to ISA.
102 * Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable).
103 */
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000104 new = old | 0x2c4;
105
106 if (new == old)
107 return 0;
108
109 pci_write_word(dev, xbcs, new);
110
111 if (pci_read_word(dev, xbcs) != new) {
112 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name);
113 return -1;
114 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000115
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000116 return 0;
117}
118
Stefan Reinauer86de2832006-03-31 11:26:55 +0000119static int enable_flash_ich(struct pci_dev *dev, char *name, int bios_cntl)
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000120{
121 /* register 4e.b gets or'ed with one */
Ollie Lho184a4042005-11-26 21:55:36 +0000122 uint8_t old, new;
Stefan Reinauereb366472006-09-06 15:48:48 +0000123
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000124 /* if it fails, it fails. There are so many variations of broken mobos
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000125 * that it is hard to argue that we should quit at this point.
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000126 */
127
Stefan Reinauereb366472006-09-06 15:48:48 +0000128 /* Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, but
Uwe Hermanna7e05482007-05-09 10:17:44 +0000129 * just treating it as 8 bit wide seems to work fine in practice.
Stefan Reinauereb366472006-09-06 15:48:48 +0000130 */
131
132 /* see ie. page 375 of "Intel ICH7 External Design Specification"
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000133 * http://download.intel.com/design/chipsets/datashts/30701302.pdf
Stefan Reinauereb366472006-09-06 15:48:48 +0000134 */
135
Stefan Reinauer86de2832006-03-31 11:26:55 +0000136 old = pci_read_byte(dev, bios_cntl);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000137
138 new = old | 1;
139
140 if (new == old)
141 return 0;
142
Stefan Reinauer86de2832006-03-31 11:26:55 +0000143 pci_write_byte(dev, bios_cntl, new);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000144
Stefan Reinauer86de2832006-03-31 11:26:55 +0000145 if (pci_read_byte(dev, bios_cntl) != new) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000146 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", bios_cntl, new, name);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000147 return -1;
148 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000149
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000150 return 0;
151}
152
Stefan Reinauereb366472006-09-06 15:48:48 +0000153static int enable_flash_ich_4e(struct pci_dev *dev, char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000154{
Stefan Reinauereb366472006-09-06 15:48:48 +0000155 return enable_flash_ich(dev, name, 0x4e);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000156}
157
Stefan Reinauereb366472006-09-06 15:48:48 +0000158static int enable_flash_ich_dc(struct pci_dev *dev, char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000159{
Stefan Reinauereb366472006-09-06 15:48:48 +0000160 return enable_flash_ich(dev, name, 0xdc);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000161}
162
Uwe Hermanna7e05482007-05-09 10:17:44 +0000163static int enable_flash_vt823x(struct pci_dev *dev, char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000164{
Ollie Lho184a4042005-11-26 21:55:36 +0000165 uint8_t val;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000166
Uwe Hermannffec5f32007-08-23 16:08:21 +0000167 /* ROM write enable */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000168 val = pci_read_byte(dev, 0x40);
169 val |= 0x10;
170 pci_write_byte(dev, 0x40, val);
171
172 if (pci_read_byte(dev, 0x40) != val) {
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000173 printf("\nWARNING: Failed to enable ROM Write on \"%s\"\n",
Uwe Hermanna7e05482007-05-09 10:17:44 +0000174 name);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000175 return -1;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000176 }
Luc Verhaegen6382b442007-03-02 22:16:38 +0000177
Uwe Hermanna7e05482007-05-09 10:17:44 +0000178 return 0;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000179}
180
181static int enable_flash_cs5530(struct pci_dev *dev, char *name)
182{
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000183 uint8_t reg8;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000184
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000185 #define DECODE_CONTROL_REG2 0x5b /* F0 index 0x5b */
186 #define ROM_AT_LOGIC_CONTROL_REG 0x52 /* F0 index 0x52 */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000187
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000188 #define LOWER_ROM_ADDRESS_RANGE (1 << 0)
189 #define ROM_WRITE_ENABLE (1 << 1)
190 #define UPPER_ROM_ADDRESS_RANGE (1 << 2)
191 #define BIOS_ROM_POSITIVE_DECODE (1 << 5)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000192
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000193 /* Decode 0x000E0000-0x000FFFFF (128 KB), not just 64 KB, and
194 * decode 0xFF000000-0xFFFFFFFF (16 MB), not just 256 KB.
195 * Make the configured ROM areas writable.
196 */
197 reg8 = pci_read_byte(dev, ROM_AT_LOGIC_CONTROL_REG);
198 reg8 |= LOWER_ROM_ADDRESS_RANGE;
199 reg8 |= UPPER_ROM_ADDRESS_RANGE;
200 reg8 |= ROM_WRITE_ENABLE;
201 pci_write_byte(dev, ROM_AT_LOGIC_CONTROL_REG, reg8);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000202
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000203 /* Set positive decode on ROM. */
204 reg8 = pci_read_byte(dev, DECODE_CONTROL_REG2);
205 reg8 |= BIOS_ROM_POSITIVE_DECODE;
206 pci_write_byte(dev, DECODE_CONTROL_REG2, reg8);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000207
Ollie Lhocbbf1252004-03-17 22:22:08 +0000208 return 0;
209}
210
211static int enable_flash_sc1100(struct pci_dev *dev, char *name)
212{
Ollie Lho184a4042005-11-26 21:55:36 +0000213 uint8_t new;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000214
Ollie Lhocbbf1252004-03-17 22:22:08 +0000215 pci_write_byte(dev, 0x52, 0xee);
216
217 new = pci_read_byte(dev, 0x52);
218
219 if (new != 0xee) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000220 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x52, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000221 return -1;
222 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000223
Ollie Lhocbbf1252004-03-17 22:22:08 +0000224 return 0;
225}
226
227static int enable_flash_sis5595(struct pci_dev *dev, char *name)
228{
Ollie Lho184a4042005-11-26 21:55:36 +0000229 uint8_t new, newer;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000230
Ollie Lhocbbf1252004-03-17 22:22:08 +0000231 new = pci_read_byte(dev, 0x45);
232
233 /* clear bit 5 */
Ollie Lho761bf1b2004-03-20 16:46:10 +0000234 new &= (~0x20);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000235 /* set bit 2 */
236 new |= 0x4;
237
238 pci_write_byte(dev, 0x45, new);
239
240 newer = pci_read_byte(dev, 0x45);
241 if (newer != new) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000242 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000243 printf("Stuck at 0x%x\n", newer);
244 return -1;
245 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000246
Ollie Lhocbbf1252004-03-17 22:22:08 +0000247 return 0;
248}
249
Ollie Lho761bf1b2004-03-20 16:46:10 +0000250static int enable_flash_amd8111(struct pci_dev *dev, char *name)
251{
Ollie Lhocbbf1252004-03-17 22:22:08 +0000252 /* register 4e.b gets or'ed with one */
Ollie Lho184a4042005-11-26 21:55:36 +0000253 uint8_t old, new;
Uwe Hermanna7e05482007-05-09 10:17:44 +0000254
Ollie Lhocbbf1252004-03-17 22:22:08 +0000255 /* if it fails, it fails. There are so many variations of broken mobos
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000256 * that it is hard to argue that we should quit at this point.
Ollie Lhocbbf1252004-03-17 22:22:08 +0000257 */
258
Ollie Lhod11f3612004-12-07 17:19:04 +0000259 /* enable decoding at 0xffb00000 to 0xffffffff */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000260 old = pci_read_byte(dev, 0x43);
Ollie Lhod11f3612004-12-07 17:19:04 +0000261 new = old | 0xC0;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000262 if (new != old) {
263 pci_write_byte(dev, 0x43, new);
264 if (pci_read_byte(dev, 0x43) != new) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000265 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x43, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000266 }
267 }
268
Ollie Lho761bf1b2004-03-20 16:46:10 +0000269 old = pci_read_byte(dev, 0x40);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000270 new = old | 0x01;
271 if (new == old)
272 return 0;
273 pci_write_byte(dev, 0x40, new);
274
275 if (pci_read_byte(dev, 0x40) != new) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000276 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000277 return -1;
278 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000279
Ollie Lhocbbf1252004-03-17 22:22:08 +0000280 return 0;
281}
282
Yinghai Lu952dfce2005-07-06 17:13:46 +0000283static int enable_flash_ck804(struct pci_dev *dev, char *name)
284{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000285 /* register 4e.b gets or'ed with one */
286 uint8_t old, new;
Yinghai Lu952dfce2005-07-06 17:13:46 +0000287
Uwe Hermanna7e05482007-05-09 10:17:44 +0000288 /* if it fails, it fails. There are so many variations of broken mobos
289 * that it is hard to argue that we should quit at this point.
290 */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000291
Uwe Hermanna7e05482007-05-09 10:17:44 +0000292 /* dump_pci_device(dev); */
Yinghai Lu952dfce2005-07-06 17:13:46 +0000293
Uwe Hermanna7e05482007-05-09 10:17:44 +0000294 old = pci_read_byte(dev, 0x88);
295 new = old | 0xc0;
296 if (new != old) {
297 pci_write_byte(dev, 0x88, new);
298 if (pci_read_byte(dev, 0x88) != new) {
299 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x88, new, name);
300 }
301 }
Yinghai Lu952dfce2005-07-06 17:13:46 +0000302
Uwe Hermanna7e05482007-05-09 10:17:44 +0000303 old = pci_read_byte(dev, 0x6d);
304 new = old | 0x01;
305 if (new == old)
306 return 0;
307 pci_write_byte(dev, 0x6d, new);
308
309 if (pci_read_byte(dev, 0x6d) != new) {
310 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name);
311 return -1;
312 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000313
Uwe Hermanna7e05482007-05-09 10:17:44 +0000314 return 0;
Yinghai Lu952dfce2005-07-06 17:13:46 +0000315}
316
Stefan Reinauer86de2832006-03-31 11:26:55 +0000317static int enable_flash_sb400(struct pci_dev *dev, char *name)
318{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000319 uint8_t tmp;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000320
321 struct pci_filter f;
322 struct pci_dev *smbusdev;
323
Stefan Reinauer86de2832006-03-31 11:26:55 +0000324 /* then look for the smbus device */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000325 pci_filter_init((struct pci_access *)0, &f);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000326 f.vendor = 0x1002;
327 f.device = 0x4372;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000328
Stefan Reinauer86de2832006-03-31 11:26:55 +0000329 for (smbusdev = pacc->devices; smbusdev; smbusdev = smbusdev->next) {
330 if (pci_filter_match(&f, smbusdev)) {
331 break;
332 }
333 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000334
Uwe Hermanna7e05482007-05-09 10:17:44 +0000335 if (!smbusdev) {
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000336 fprintf(stderr, "ERROR: SMBus device not found. aborting\n");
Stefan Reinauer86de2832006-03-31 11:26:55 +0000337 exit(1);
338 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000339
340 /* enable some smbus stuff */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000341 tmp = pci_read_byte(smbusdev, 0x79);
342 tmp |= 0x01;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000343 pci_write_byte(smbusdev, 0x79, tmp);
344
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000345 /* change southbridge */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000346 tmp = pci_read_byte(dev, 0x48);
347 tmp |= 0x21;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000348 pci_write_byte(dev, 0x48, tmp);
349
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000350 /* now become a bit silly. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000351 tmp = inb(0xc6f);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000352 outb(tmp, 0xeb);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000353 outb(tmp, 0xeb);
354 tmp |= 0x40;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000355 outb(tmp, 0xc6f);
356 outb(tmp, 0xeb);
357 outb(tmp, 0xeb);
358
359 return 0;
360}
361
Yinghai Luca782972007-01-22 20:21:17 +0000362static int enable_flash_mcp55(struct pci_dev *dev, char *name)
363{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000364 /* register 4e.b gets or'ed with one */
365 unsigned char old, new, byte;
366 unsigned short word;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000367
Uwe Hermanna7e05482007-05-09 10:17:44 +0000368 /* if it fails, it fails. There are so many variations of broken mobos
369 * that it is hard to argue that we should quit at this point.
370 */
Yinghai Luca782972007-01-22 20:21:17 +0000371
Uwe Hermanna7e05482007-05-09 10:17:44 +0000372 /* dump_pci_device(dev); */
Yinghai Luca782972007-01-22 20:21:17 +0000373
Uwe Hermanna7e05482007-05-09 10:17:44 +0000374 /* Set the 4MB enable bit bit */
375 byte = pci_read_byte(dev, 0x88);
376 byte |= 0xff; /* 256K */
377 pci_write_byte(dev, 0x88, byte);
378 byte = pci_read_byte(dev, 0x8c);
379 byte |= 0xff; /* 1M */
380 pci_write_byte(dev, 0x8c, byte);
381 word = pci_read_word(dev, 0x90);
382 word |= 0x7fff; /* 15M */
383 pci_write_word(dev, 0x90, word);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000384
Uwe Hermanna7e05482007-05-09 10:17:44 +0000385 old = pci_read_byte(dev, 0x6d);
386 new = old | 0x01;
387 if (new == old)
388 return 0;
389 pci_write_byte(dev, 0x6d, new);
Yinghai Luca782972007-01-22 20:21:17 +0000390
Uwe Hermanna7e05482007-05-09 10:17:44 +0000391 if (pci_read_byte(dev, 0x6d) != new) {
392 printf
393 ("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
394 0x6d, new, name);
395 return -1;
396 }
Yinghai Luca782972007-01-22 20:21:17 +0000397
398 return 0;
Yinghai Luca782972007-01-22 20:21:17 +0000399}
400
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000401static int enable_flash_ht1000(struct pci_dev *dev, char *name)
402{
Uwe Hermanne823ee02007-06-05 15:02:18 +0000403 uint8_t byte;
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000404
Uwe Hermanne823ee02007-06-05 15:02:18 +0000405 /* Set the 4MB enable bit. */
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000406 byte = pci_read_byte(dev, 0x41);
407 byte |= 0x0e;
408 pci_write_byte(dev, 0x41, byte);
409
410 byte = pci_read_byte(dev, 0x43);
Uwe Hermannffec5f32007-08-23 16:08:21 +0000411 byte |= (1 << 4);
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000412 pci_write_byte(dev, 0x43, byte);
413
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000414 return 0;
415}
416
Ollie Lhocbbf1252004-03-17 22:22:08 +0000417typedef struct penable {
Ollie Lho761bf1b2004-03-20 16:46:10 +0000418 unsigned short vendor, device;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000419 char *name;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000420 int (*doit) (struct pci_dev * dev, char *name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000421} FLASH_ENABLE;
422
423static FLASH_ENABLE enables[] = {
Stefan Reinauereb366472006-09-06 15:48:48 +0000424 {0x1039, 0x0630, "SIS630", enable_flash_sis630},
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000425 {0x8086, 0x7110, "PIIX4/PIIX4E/PIIX4M", enable_flash_piix4},
Stefan Reinauereb366472006-09-06 15:48:48 +0000426 {0x8086, 0x2410, "ICH", enable_flash_ich_4e},
427 {0x8086, 0x2420, "ICH0", enable_flash_ich_4e},
428 {0x8086, 0x2440, "ICH2", enable_flash_ich_4e},
429 {0x8086, 0x244c, "ICH2-M", enable_flash_ich_4e},
430 {0x8086, 0x2480, "ICH3-S", enable_flash_ich_4e},
431 {0x8086, 0x248c, "ICH3-M", enable_flash_ich_4e},
432 {0x8086, 0x24c0, "ICH4/ICH4-L", enable_flash_ich_4e},
433 {0x8086, 0x24cc, "ICH4-M", enable_flash_ich_4e},
434 {0x8086, 0x24d0, "ICH5/ICH5R", enable_flash_ich_4e},
435 {0x8086, 0x2640, "ICH6/ICH6R", enable_flash_ich_dc},
436 {0x8086, 0x2641, "ICH6-M", enable_flash_ich_dc},
Uwe Hermann3ad25182007-03-31 19:48:38 +0000437 {0x8086, 0x27b0, "ICH7DH", enable_flash_ich_dc},
Stefan Reinauereb366472006-09-06 15:48:48 +0000438 {0x8086, 0x27b8, "ICH7/ICH7R", enable_flash_ich_dc},
439 {0x8086, 0x27b9, "ICH7M", enable_flash_ich_dc},
440 {0x8086, 0x27bd, "ICH7MDH", enable_flash_ich_dc},
441 {0x8086, 0x2810, "ICH8/ICH8R", enable_flash_ich_dc},
442 {0x8086, 0x2812, "ICH8DH", enable_flash_ich_dc},
443 {0x8086, 0x2814, "ICH8DO", enable_flash_ich_dc},
Luc Verhaegen6382b442007-03-02 22:16:38 +0000444 {0x1106, 0x8231, "VT8231", enable_flash_vt823x},
445 {0x1106, 0x3177, "VT8235", enable_flash_vt823x},
446 {0x1106, 0x3227, "VT8237", enable_flash_vt823x},
Uwe Hermanna7e05482007-05-09 10:17:44 +0000447 {0x1106, 0x8324, "CX700", enable_flash_vt823x},
Stefan Reinauerc6b5f492006-11-07 10:22:20 +0000448 {0x1106, 0x0686, "VT82C686", enable_flash_amd8111},
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000449 {0x1078, 0x0100, "CS5530/CS5530A", enable_flash_cs5530},
Ollie Lho761bf1b2004-03-20 16:46:10 +0000450 {0x100b, 0x0510, "SC1100", enable_flash_sc1100},
Ollie Lhocbbf1252004-03-17 22:22:08 +0000451 {0x1039, 0x0008, "SIS5595", enable_flash_sis5595},
452 {0x1022, 0x7468, "AMD8111", enable_flash_amd8111},
Luc Verhaegen6b141752007-05-20 16:16:13 +0000453 {0x10B9, 0x1533, "ALi M1533", enable_flash_ali_m1533},
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000454 /* this fallthrough looks broken. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000455 {0x10de, 0x0050, "NVIDIA CK804", enable_flash_ck804}, /* LPC */
456 {0x10de, 0x0051, "NVIDIA CK804", enable_flash_ck804}, /* Pro */
457 {0x10de, 0x00d3, "NVIDIA CK804", enable_flash_ck804}, /* Slave, should not be here, to fix known bug for A01. */
Stefan Reinauer219b61e2006-10-14 21:04:49 +0000458
Uwe Hermanna7e05482007-05-09 10:17:44 +0000459 {0x10de, 0x0260, "NVidia MCP51", enable_flash_ck804},
460 {0x10de, 0x0261, "NVidia MCP51", enable_flash_ck804},
461 {0x10de, 0x0262, "NVidia MCP51", enable_flash_ck804},
462 {0x10de, 0x0263, "NVidia MCP51", enable_flash_ck804},
Stefan Reinauer219b61e2006-10-14 21:04:49 +0000463
Uwe Hermanna7e05482007-05-09 10:17:44 +0000464 {0x10de, 0x0360, "NVIDIA MCP55", enable_flash_mcp55}, /* Gigabyte m57sli-s4 */
465 {0x10de, 0x0361, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
466 {0x10de, 0x0362, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
467 {0x10de, 0x0363, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
468 {0x10de, 0x0364, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
469 {0x10de, 0x0365, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
470 {0x10de, 0x0366, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
471 {0x10de, 0x0367, "NVIDIA MCP55", enable_flash_mcp55}, /* Pro */
Yinghai Luca782972007-01-22 20:21:17 +0000472
Uwe Hermanna7e05482007-05-09 10:17:44 +0000473 {0x1002, 0x4377, "ATI SB400", enable_flash_sb400}, /* ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80) */
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000474
Uwe Hermanne823ee02007-06-05 15:02:18 +0000475 {0x1166, 0x0205, "Broadcom HT-1000", enable_flash_ht1000},
Ollie Lhocbbf1252004-03-17 22:22:08 +0000476};
Ollie Lho761bf1b2004-03-20 16:46:10 +0000477
Uwe Hermanna7e05482007-05-09 10:17:44 +0000478int chipset_flash_enable(void)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000479{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000480 struct pci_dev *dev = 0;
481 int ret = -2; /* nothing! */
482 int i;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000483
Ollie Lhocbbf1252004-03-17 22:22:08 +0000484 /* now let's try to find the chipset we have ... */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000485 for (i = 0; i < sizeof(enables) / sizeof(enables[0]); i++) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000486 dev = pci_dev_find(enables[i].vendor, enables[i].device);
487 if (dev)
488 break;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000489 }
490
Uwe Hermanna7e05482007-05-09 10:17:44 +0000491 if (dev) {
492 printf("Found chipset \"%s\": Enabling flash write... ",
493 enables[i].name);
494
495 ret = enables[i].doit(dev, enables[i].name);
496 if (ret)
497 printf("Failed!\n");
498 else
499 printf("OK.\n");
500 }
501
502 return ret;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000503}