blob: 652fbcd82026de7972233b505589060427e95a57 [file] [log] [blame]
Ollie Lho184a4042005-11-26 21:55:36 +00001/*
2 * flash rom utility: enable flash writes
3 *
4 * Copyright (C) 2000-2004 ???
5 * Copyright (C) 2005 coresystems GmbH <stepan@openbios.org>
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 <sys/io.h>
15#include <stdio.h>
16#include <pci/pci.h>
17#include <stdlib.h>
Ollie Lho184a4042005-11-26 21:55:36 +000018#include <stdint.h>
19#include <string.h>
20#include "lbtable.h"
21#include "debug.h"
Ollie Lhocbbf1252004-03-17 22:22:08 +000022
Stefan Reinauer86de2832006-03-31 11:26:55 +000023// We keep this for the others.
24static struct pci_access *pacc;
25
Ollie Lho761bf1b2004-03-20 16:46:10 +000026static int enable_flash_sis630(struct pci_dev *dev, char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +000027{
28 char b;
29
30 /* get io privilege access PCI configuration space */
31 if (iopl(3) != 0) {
32 perror("Can not set io priviliage");
33 exit(1);
34 }
35
36 /* 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;
89 uint16_t xbcs = 0x4e; /* X-Bus Chip Select register. */
90
91 old = pci_read_word(dev, xbcs);
92
93 /* Set bit 9: 1-Meg Extended BIOS Enable (PCI master accesses to
94 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
Uwe Hermann987942d2006-11-07 11:16:21 +000098 the lower 64-Kbyte BIOS block (E0000-EFFFF) at the top
Uwe Hermannea2c66d2006-11-05 18:26:08 +000099 of 1 Mbyte, or the aliases at the top of 4 Gbyte
Uwe Hermann987942d2006-11-07 11:16:21 +0000100 (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). */
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000103 new = old | 0x2c4;
104
105 if (new == old)
106 return 0;
107
108 pci_write_word(dev, xbcs, new);
109
110 if (pci_read_word(dev, xbcs) != new) {
111 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name);
112 return -1;
113 }
114 return 0;
115}
116
Stefan Reinauer86de2832006-03-31 11:26:55 +0000117static int enable_flash_ich(struct pci_dev *dev, char *name, int bios_cntl)
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000118{
119 /* register 4e.b gets or'ed with one */
Ollie Lho184a4042005-11-26 21:55:36 +0000120 uint8_t old, new;
Stefan Reinauereb366472006-09-06 15:48:48 +0000121
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000122 /* if it fails, it fails. There are so many variations of broken mobos
123 * that it is hard to argue that we should quit at this point.
124 */
125
Stefan Reinauereb366472006-09-06 15:48:48 +0000126 /* Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, but
127 * just treating it as 8 bit wide seems to work fine in practice.
128 */
129
130 /* see ie. page 375 of "Intel ICH7 External Design Specification"
131 * http://download.intel.com/design/chipsets/datashts/30701302.pdf
132 */
133
Stefan Reinauer86de2832006-03-31 11:26:55 +0000134 old = pci_read_byte(dev, bios_cntl);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000135
136 new = old | 1;
137
138 if (new == old)
139 return 0;
140
Stefan Reinauer86de2832006-03-31 11:26:55 +0000141 pci_write_byte(dev, bios_cntl, new);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000142
Stefan Reinauer86de2832006-03-31 11:26:55 +0000143 if (pci_read_byte(dev, bios_cntl) != new) {
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000144 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
Stefan Reinauer86de2832006-03-31 11:26:55 +0000145 bios_cntl, new, name);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000146 return -1;
147 }
148 return 0;
149}
150
Stefan Reinauereb366472006-09-06 15:48:48 +0000151static int enable_flash_ich_4e(struct pci_dev *dev, char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000152{
Stefan Reinauereb366472006-09-06 15:48:48 +0000153 return enable_flash_ich(dev, name, 0x4e);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000154}
155
Stefan Reinauereb366472006-09-06 15:48:48 +0000156static int enable_flash_ich_dc(struct pci_dev *dev, char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000157{
Stefan Reinauereb366472006-09-06 15:48:48 +0000158 return enable_flash_ich(dev, name, 0xdc);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000159}
160
Ollie Lhocbbf1252004-03-17 22:22:08 +0000161static int enable_flash_vt8235(struct pci_dev *dev, char *name)
162{
Ollie Lho184a4042005-11-26 21:55:36 +0000163 uint8_t old, new, val;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000164 unsigned int base;
165 int ok;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000166
Ollie Lhocbbf1252004-03-17 22:22:08 +0000167 /* get io privilege access PCI configuration space */
168 if (iopl(3) != 0) {
169 perror("Can not set io priviliage");
170 exit(1);
171 }
172
173 old = pci_read_byte(dev, 0x40);
174
175 new = old | 0x10;
176
177 if (new == old)
178 return 0;
179
180 ok = pci_write_byte(dev, 0x40, new);
181 if (ok != 0) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000182 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
183 old, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000184 }
185
186 /* enable GPIO15 which is connected to write protect. */
Ollie Lho8b8897a2004-03-27 00:18:15 +0000187 base = ((pci_read_byte(dev, 0x88) & 0x80) | pci_read_byte(dev, 0x89) << 8);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000188 val = inb(base + 0x4d);
189 val |= 0x80;
190 outb(val, base + 0x4d);
191
192 if (ok != 0) {
193 return -1;
194 } else {
195 return 0;
196 }
197}
198
199static int enable_flash_vt8231(struct pci_dev *dev, char *name)
200{
Ollie Lho184a4042005-11-26 21:55:36 +0000201 uint8_t val;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000202
Ollie Lhocbbf1252004-03-17 22:22:08 +0000203 val = pci_read_byte(dev, 0x40);
204 val |= 0x10;
205 pci_write_byte(dev, 0x40, val);
206
207 if (pci_read_byte(dev, 0x40) != val) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000208 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
209 0x40, val, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000210 return -1;
211 }
212 return 0;
213}
214
215static int enable_flash_cs5530(struct pci_dev *dev, char *name)
216{
Ollie Lho184a4042005-11-26 21:55:36 +0000217 uint8_t new;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000218
Ollie Lhocbbf1252004-03-17 22:22:08 +0000219 pci_write_byte(dev, 0x52, 0xee);
220
221 new = pci_read_byte(dev, 0x52);
222
223 if (new != 0xee) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000224 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
225 0x52, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000226 return -1;
227 }
Ollie Lho184a4042005-11-26 21:55:36 +0000228
229 new = pci_read_byte(dev, 0x5b) | 0x20;
230 pci_write_byte(dev, 0x5b, new);
231
Ollie Lhocbbf1252004-03-17 22:22:08 +0000232 return 0;
233}
234
Ollie Lho184a4042005-11-26 21:55:36 +0000235
Ollie Lhocbbf1252004-03-17 22:22:08 +0000236static int enable_flash_sc1100(struct pci_dev *dev, char *name)
237{
Ollie Lho184a4042005-11-26 21:55:36 +0000238 uint8_t new;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000239
Ollie Lhocbbf1252004-03-17 22:22:08 +0000240 pci_write_byte(dev, 0x52, 0xee);
241
242 new = pci_read_byte(dev, 0x52);
243
244 if (new != 0xee) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000245 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
246 0x52, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000247 return -1;
248 }
249 return 0;
250}
251
252static int enable_flash_sis5595(struct pci_dev *dev, char *name)
253{
Ollie Lho184a4042005-11-26 21:55:36 +0000254 uint8_t new, newer;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000255
Ollie Lhocbbf1252004-03-17 22:22:08 +0000256 new = pci_read_byte(dev, 0x45);
257
258 /* clear bit 5 */
Ollie Lho761bf1b2004-03-20 16:46:10 +0000259 new &= (~0x20);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000260 /* set bit 2 */
261 new |= 0x4;
262
263 pci_write_byte(dev, 0x45, new);
264
265 newer = pci_read_byte(dev, 0x45);
266 if (newer != new) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000267 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
268 0x45, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000269 printf("Stuck at 0x%x\n", newer);
270 return -1;
271 }
272 return 0;
273}
274
Ollie Lho761bf1b2004-03-20 16:46:10 +0000275static int enable_flash_amd8111(struct pci_dev *dev, char *name)
276{
Ollie Lhocbbf1252004-03-17 22:22:08 +0000277 /* register 4e.b gets or'ed with one */
Ollie Lho184a4042005-11-26 21:55:36 +0000278 uint8_t old, new;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000279 /* if it fails, it fails. There are so many variations of broken mobos
280 * that it is hard to argue that we should quit at this point.
281 */
282
Ollie Lhod11f3612004-12-07 17:19:04 +0000283 /* enable decoding at 0xffb00000 to 0xffffffff */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000284 old = pci_read_byte(dev, 0x43);
Ollie Lhod11f3612004-12-07 17:19:04 +0000285 new = old | 0xC0;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000286 if (new != old) {
287 pci_write_byte(dev, 0x43, new);
288 if (pci_read_byte(dev, 0x43) != new) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000289 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
290 0x43, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000291 }
292 }
293
Ollie Lho761bf1b2004-03-20 16:46:10 +0000294 old = pci_read_byte(dev, 0x40);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000295 new = old | 0x01;
296 if (new == old)
297 return 0;
298 pci_write_byte(dev, 0x40, new);
299
300 if (pci_read_byte(dev, 0x40) != new) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000301 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
302 0x40, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000303 return -1;
304 }
305 return 0;
306}
307
Yinghai Lu952dfce2005-07-06 17:13:46 +0000308//By yhlu
309static int enable_flash_ck804(struct pci_dev *dev, char *name)
310{
311 /* register 4e.b gets or'ed with one */
Ollie Lho184a4042005-11-26 21:55:36 +0000312 uint8_t old, new;
Yinghai Lu952dfce2005-07-06 17:13:46 +0000313 /* if it fails, it fails. There are so many variations of broken mobos
314 * that it is hard to argue that we should quit at this point.
315 */
316
317 //dump_pci_device(dev);
318
319 old = pci_read_byte(dev, 0x88);
320 new = old | 0xc0;
321 if (new != old) {
322 pci_write_byte(dev, 0x88, new);
323 if (pci_read_byte(dev, 0x88) != new) {
324 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
325 0x88, new, name);
326 }
327 }
328
329 old = pci_read_byte(dev, 0x6d);
330 new = old | 0x01;
331 if (new == old)
332 return 0;
333 pci_write_byte(dev, 0x6d, new);
334
335 if (pci_read_byte(dev, 0x6d) != new) {
336 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
337 0x6d, new, name);
338 return -1;
339 }
340 return 0;
341}
342
Stefan Reinauer86de2832006-03-31 11:26:55 +0000343static int enable_flash_sb400(struct pci_dev *dev, char *name)
344{
345 uint8_t tmp;
346
347 struct pci_filter f;
348 struct pci_dev *smbusdev;
349
350 /* get io privilege access */
351 if (iopl(3) != 0) {
352 perror("Can not set io priviliage");
353 exit(1);
354 }
355
356 /* then look for the smbus device */
357 pci_filter_init((struct pci_access *) 0, &f);
358 f.vendor = 0x1002;
359 f.device = 0x4372;
360
361 for (smbusdev = pacc->devices; smbusdev; smbusdev = smbusdev->next) {
362 if (pci_filter_match(&f, smbusdev)) {
363 break;
364 }
365 }
366
367 if(!smbusdev) {
368 perror("smbus device not found. aborting\n");
369 exit(1);
370 }
371
372 // enable some smbus stuff
373 tmp=pci_read_byte(smbusdev, 0x79);
374 tmp|=0x01;
375 pci_write_byte(smbusdev, 0x79, tmp);
376
377 // change southbridge
378 tmp=pci_read_byte(dev, 0x48);
379 tmp|=0x21;
380 pci_write_byte(dev, 0x48, tmp);
381
382 // now become a bit silly.
383 tmp=inb(0xc6f);
384 outb(tmp,0xeb);
385 outb(tmp, 0xeb);
386 tmp|=0x40;
387 outb(tmp, 0xc6f);
388 outb(tmp, 0xeb);
389 outb(tmp, 0xeb);
390
391 return 0;
392}
393
Yinghai Luca782972007-01-22 20:21:17 +0000394//By yhlu
395static int enable_flash_mcp55(struct pci_dev *dev, char *name)
396{
397 /* register 4e.b gets or'ed with one */
398 unsigned char old, new, byte;
399 unsigned short word;
400
401 /* if it fails, it fails. There are so many variations of broken mobos
402 * that it is hard to argue that we should quit at this point.
403 */
404
405 //dump_pci_device(dev);
406
407 /* Set the 4MB enable bit bit */
408 byte = pci_read_byte(dev, 0x88);
409 byte |= 0xff; //256K
410 pci_write_byte(dev, 0x88, byte);
411 byte = pci_read_byte(dev, 0x8c);
412 byte |= 0xff; //1M
413 pci_write_byte(dev, 0x8c, byte);
414 word = pci_read_word(dev, 0x90);
415 word |= 0x7fff; //15M
416 pci_write_word(dev, 0x90, word);
417
418 old = pci_read_byte(dev, 0x6d);
419 new = old | 0x01;
420 if (new == old)
421 return 0;
422 pci_write_byte(dev, 0x6d, new);
423
424 if (pci_read_byte(dev, 0x6d) != new) {
425 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
426 0x6d, new, name);
427 return -1;
428 }
429
430 return 0;
431
432}
433
Ollie Lhocbbf1252004-03-17 22:22:08 +0000434typedef struct penable {
Ollie Lho761bf1b2004-03-20 16:46:10 +0000435 unsigned short vendor, device;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000436 char *name;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000437 int (*doit) (struct pci_dev * dev, char *name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000438} FLASH_ENABLE;
439
440static FLASH_ENABLE enables[] = {
Stefan Reinauereb366472006-09-06 15:48:48 +0000441 {0x1039, 0x0630, "SIS630", enable_flash_sis630},
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000442 {0x8086, 0x7110, "PIIX4/PIIX4E/PIIX4M", enable_flash_piix4},
Stefan Reinauereb366472006-09-06 15:48:48 +0000443 {0x8086, 0x2410, "ICH", enable_flash_ich_4e},
444 {0x8086, 0x2420, "ICH0", enable_flash_ich_4e},
445 {0x8086, 0x2440, "ICH2", enable_flash_ich_4e},
446 {0x8086, 0x244c, "ICH2-M", enable_flash_ich_4e},
447 {0x8086, 0x2480, "ICH3-S", enable_flash_ich_4e},
448 {0x8086, 0x248c, "ICH3-M", enable_flash_ich_4e},
449 {0x8086, 0x24c0, "ICH4/ICH4-L", enable_flash_ich_4e},
450 {0x8086, 0x24cc, "ICH4-M", enable_flash_ich_4e},
451 {0x8086, 0x24d0, "ICH5/ICH5R", enable_flash_ich_4e},
452 {0x8086, 0x2640, "ICH6/ICH6R", enable_flash_ich_dc},
453 {0x8086, 0x2641, "ICH6-M", enable_flash_ich_dc},
454 {0x8086, 0x27b8, "ICH7/ICH7R", enable_flash_ich_dc},
455 {0x8086, 0x27b9, "ICH7M", enable_flash_ich_dc},
456 {0x8086, 0x27bd, "ICH7MDH", enable_flash_ich_dc},
457 {0x8086, 0x2810, "ICH8/ICH8R", enable_flash_ich_dc},
458 {0x8086, 0x2812, "ICH8DH", enable_flash_ich_dc},
459 {0x8086, 0x2814, "ICH8DO", enable_flash_ich_dc},
Ollie Lho761bf1b2004-03-20 16:46:10 +0000460 {0x1106, 0x8231, "VT8231", enable_flash_vt8231},
461 {0x1106, 0x3177, "VT8235", enable_flash_vt8235},
Stefan Reinauer219b61e2006-10-14 21:04:49 +0000462 {0x1106, 0x3227, "VT8237", enable_flash_vt8231},
Stefan Reinauerc6b5f492006-11-07 10:22:20 +0000463 {0x1106, 0x0686, "VT82C686", enable_flash_amd8111},
Ollie Lho761bf1b2004-03-20 16:46:10 +0000464 {0x1078, 0x0100, "CS5530", enable_flash_cs5530},
465 {0x100b, 0x0510, "SC1100", enable_flash_sc1100},
Ollie Lhocbbf1252004-03-17 22:22:08 +0000466 {0x1039, 0x0008, "SIS5595", enable_flash_sis5595},
467 {0x1022, 0x7468, "AMD8111", enable_flash_amd8111},
Stefan Reinauer86de2832006-03-31 11:26:55 +0000468 // this fallthrough looks broken.
Yinghai Lu952dfce2005-07-06 17:13:46 +0000469 {0x10de, 0x0050, "NVIDIA CK804", enable_flash_ck804}, // LPC
470 {0x10de, 0x0051, "NVIDIA CK804", enable_flash_ck804}, // Pro
471 {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 +0000472
473 {0x10de, 0x0260, "NVidia MCP51", enable_flash_ck804},
474 {0x10de, 0x0261, "NVidia MCP51", enable_flash_ck804},
Yinghai Luca782972007-01-22 20:21:17 +0000475 // {0x10de, 0x0261, "NVIDIA C51", enable_flash_ck804}, // YHLU
Stefan Reinauer219b61e2006-10-14 21:04:49 +0000476 {0x10de, 0x0262, "NVidia MCP51", enable_flash_ck804},
477 {0x10de, 0x0263, "NVidia MCP51", enable_flash_ck804},
478
Yinghai Luca782972007-01-22 20:21:17 +0000479 {0x10de, 0x0364, "NVIDIA MCP55", enable_flash_mcp55}, // LPC
480 {0x10de, 0x0367, "NVIDIA MCP55", enable_flash_mcp55}, // Pro
481
Stefan Reinauer86de2832006-03-31 11:26:55 +0000482 {0x1002, 0x4377, "ATI SB400", enable_flash_sb400}, // ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000483};
Ollie Lho761bf1b2004-03-20 16:46:10 +0000484
Ollie Lho184a4042005-11-26 21:55:36 +0000485static int mbenable_island_aruma(void)
486{
Stefan Reinauer86de2832006-03-31 11:26:55 +0000487#define EFIR 0x2e /* Extended function index register, either 0x2e or 0x4e */
488#define EFDR EFIR + 1 /* Extended function data register, one plus the index reg. */
Ollie Lho184a4042005-11-26 21:55:36 +0000489 char b;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000490
491/* Disable the flash write protect. The flash write protect is
492 * connected to the WinBond w83627hf GPIO 24.
493 */
Ollie Lho184a4042005-11-26 21:55:36 +0000494
495 /* get io privilege access winbond config space */
496 if (iopl(3) != 0) {
497 perror("Can not set io priviliage");
498 exit(1);
499 }
500
501 printf("Disabling mainboard flash write protection.\n");
502
503 outb(0x87, EFIR); // sequence to unlock extended functions
504 outb(0x87, EFIR);
505
506 outb(0x20, EFIR); // SIO device ID register
507 b = inb(EFDR);
508 printf_debug("W83627HF device ID = 0x%x\n",b);
509
510 if (b != 0x52) {
511 perror("Incorrect device ID, aborting write protect disable\n");
512 exit(1);
513 }
514
515 outb(0x2b, EFIR); // GPIO multiplexed pin reg.
516 b = inb(EFDR) | 0x10;
517 outb(0x2b, EFIR);
518 outb(b, EFDR); // select GPIO 24 instead of WDTO
519
520 outb(0x7, EFIR); // logical device select
521 outb(0x8, EFDR); // point to device 8, GPIO port 2
522
523 outb(0x30, EFIR); // logic device activation control
524 outb(0x1, EFDR); // activate
525
526 outb(0xf0, EFIR); // GPIO 20-27 I/O selection register
527 b = inb(EFDR) & ~0x10;
528 outb(0xf0, EFIR);
529 outb(b, EFDR); // set GPIO 24 as an output
530
531 outb(0xf1, EFIR); // GPIO 20-27 data register
532 b = inb(EFDR) | 0x10;
533 outb(0xf1, EFIR);
534 outb(b, EFDR); // set GPIO 24
535
536 outb(0xaa, EFIR); // command to exit extended functions
537
538 return 0;
539}
540
541typedef struct mbenable {
542 char *vendor, *part;
543 int (*doit)(void);
544} MAINBOARD_ENABLE;
545
546static MAINBOARD_ENABLE mbenables[] = {
547 { "ISLAND", "ARUMA", mbenable_island_aruma },
548};
549
Ollie Lhocbbf1252004-03-17 22:22:08 +0000550int enable_flash_write()
551{
552 int i;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000553 struct pci_dev *dev = 0;
554 FLASH_ENABLE *enable = 0;
555
Ollie Lho761bf1b2004-03-20 16:46:10 +0000556 pacc = pci_alloc(); /* Get the pci_access structure */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000557 /* Set all options you want -- here we stick with the defaults */
Ollie Lho761bf1b2004-03-20 16:46:10 +0000558 pci_init(pacc); /* Initialize the PCI library */
559 pci_scan_bus(pacc); /* We want to get the list of devices */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000560
Ollie Lho184a4042005-11-26 21:55:36 +0000561
562 /* First look whether we have to do something for this
563 * motherboard.
564 */
565 for (i = 0; i < sizeof(mbenables) / sizeof(mbenables[0]); i++) {
566 if(lb_vendor && !strcmp(mbenables[i].vendor, lb_vendor) &&
567 lb_part && !strcmp(mbenables[i].part, lb_part)) {
568 mbenables[i].doit();
569 break;
570 }
571 }
572
Ollie Lhocbbf1252004-03-17 22:22:08 +0000573 /* now let's try to find the chipset we have ... */
Ollie Lho761bf1b2004-03-20 16:46:10 +0000574 for (i = 0; i < sizeof(enables) / sizeof(enables[0]) && (!dev);
575 i++) {
Ollie Lhocbbf1252004-03-17 22:22:08 +0000576 struct pci_filter f;
577 struct pci_dev *z;
578 /* the first param is unused. */
579 pci_filter_init((struct pci_access *) 0, &f);
580 f.vendor = enables[i].vendor;
581 f.device = enables[i].device;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000582 for (z = pacc->devices; z; z = z->next)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000583 if (pci_filter_match(&f, z)) {
584 enable = &enables[i];
585 dev = z;
586 }
587 }
588
Stefan Reinauercbc55d02006-08-25 19:21:42 +0000589 if (!enable) {
590 printf("Warning: Unknown system. Flash detection "
591 "will most likely fail.\n");
592 return 1;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000593 }
Stefan Reinauercbc55d02006-08-25 19:21:42 +0000594
595 /* now do the deed. */
596 printf("Enabling flash write on %s...", enable->name);
597 if (enable->doit(dev, enable->name) == 0)
598 printf("OK\n");
Ollie Lhocbbf1252004-03-17 22:22:08 +0000599 return 0;
600}