blob: 187b61d88ea6e985757a4dd9299d6c9362fadfc0 [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 Hermannea2c66d2006-11-05 18:26:08 +000080/* Datasheet: http://www.intel.com/design/intarch/datashts/290562.htm */
81static int enable_flash_piix4(struct pci_dev *dev, char *name)
82{
83 uint16_t old, new;
84 uint16_t xbcs = 0x4e; /* X-Bus Chip Select register. */
85
86 old = pci_read_word(dev, xbcs);
87
88 /* Set bit 9: 1-Meg Extended BIOS Enable (PCI master accesses to
89 FFF00000-FFF7FFFF are forwarded to ISA).
90 Set bit 7: Extended BIOS Enable (PCI master accesses to
91 FFF80000-FFFDFFFF are forwarded to ISA).
92 Set bit 6: Lower BIOS Enable (PCI master, or ISA master accesses to
93 the lower 64-Kbyte BIOS block (E00000­EFFFF) at the top
94 of 1 Mbyte, or the aliases at the top of 4 Gbyte
95 (FFFE0000-FFFEFFF) result in the generation of BIOSCS#.
96 Set bit 2: BIOSCS# Write Protect Enable (1=enable, 0=disable). */
97 new = old | 0x2c4;
98
99 if (new == old)
100 return 0;
101
102 pci_write_word(dev, xbcs, new);
103
104 if (pci_read_word(dev, xbcs) != new) {
105 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name);
106 return -1;
107 }
108 return 0;
109}
110
Stefan Reinauer86de2832006-03-31 11:26:55 +0000111static int enable_flash_ich(struct pci_dev *dev, char *name, int bios_cntl)
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000112{
113 /* register 4e.b gets or'ed with one */
Ollie Lho184a4042005-11-26 21:55:36 +0000114 uint8_t old, new;
Stefan Reinauereb366472006-09-06 15:48:48 +0000115
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000116 /* if it fails, it fails. There are so many variations of broken mobos
117 * that it is hard to argue that we should quit at this point.
118 */
119
Stefan Reinauereb366472006-09-06 15:48:48 +0000120 /* Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, but
121 * just treating it as 8 bit wide seems to work fine in practice.
122 */
123
124 /* see ie. page 375 of "Intel ICH7 External Design Specification"
125 * http://download.intel.com/design/chipsets/datashts/30701302.pdf
126 */
127
Stefan Reinauer86de2832006-03-31 11:26:55 +0000128 old = pci_read_byte(dev, bios_cntl);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000129
130 new = old | 1;
131
132 if (new == old)
133 return 0;
134
Stefan Reinauer86de2832006-03-31 11:26:55 +0000135 pci_write_byte(dev, bios_cntl, new);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000136
Stefan Reinauer86de2832006-03-31 11:26:55 +0000137 if (pci_read_byte(dev, bios_cntl) != new) {
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000138 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
Stefan Reinauer86de2832006-03-31 11:26:55 +0000139 bios_cntl, new, name);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000140 return -1;
141 }
142 return 0;
143}
144
Stefan Reinauereb366472006-09-06 15:48:48 +0000145static int enable_flash_ich_4e(struct pci_dev *dev, char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000146{
Stefan Reinauereb366472006-09-06 15:48:48 +0000147 return enable_flash_ich(dev, name, 0x4e);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000148}
149
Stefan Reinauereb366472006-09-06 15:48:48 +0000150static int enable_flash_ich_dc(struct pci_dev *dev, char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000151{
Stefan Reinauereb366472006-09-06 15:48:48 +0000152 return enable_flash_ich(dev, name, 0xdc);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000153}
154
Ollie Lhocbbf1252004-03-17 22:22:08 +0000155static int enable_flash_vt8235(struct pci_dev *dev, char *name)
156{
Ollie Lho184a4042005-11-26 21:55:36 +0000157 uint8_t old, new, val;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000158 unsigned int base;
159 int ok;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000160
Ollie Lhocbbf1252004-03-17 22:22:08 +0000161 /* get io privilege access PCI configuration space */
162 if (iopl(3) != 0) {
163 perror("Can not set io priviliage");
164 exit(1);
165 }
166
167 old = pci_read_byte(dev, 0x40);
168
169 new = old | 0x10;
170
171 if (new == old)
172 return 0;
173
174 ok = pci_write_byte(dev, 0x40, new);
175 if (ok != 0) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000176 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
177 old, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000178 }
179
180 /* enable GPIO15 which is connected to write protect. */
Ollie Lho8b8897a2004-03-27 00:18:15 +0000181 base = ((pci_read_byte(dev, 0x88) & 0x80) | pci_read_byte(dev, 0x89) << 8);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000182 val = inb(base + 0x4d);
183 val |= 0x80;
184 outb(val, base + 0x4d);
185
186 if (ok != 0) {
187 return -1;
188 } else {
189 return 0;
190 }
191}
192
193static int enable_flash_vt8231(struct pci_dev *dev, char *name)
194{
Ollie Lho184a4042005-11-26 21:55:36 +0000195 uint8_t val;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000196
Ollie Lhocbbf1252004-03-17 22:22:08 +0000197 val = pci_read_byte(dev, 0x40);
198 val |= 0x10;
199 pci_write_byte(dev, 0x40, val);
200
201 if (pci_read_byte(dev, 0x40) != val) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000202 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
203 0x40, val, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000204 return -1;
205 }
206 return 0;
207}
208
209static int enable_flash_cs5530(struct pci_dev *dev, char *name)
210{
Ollie Lho184a4042005-11-26 21:55:36 +0000211 uint8_t new;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000212
Ollie Lhocbbf1252004-03-17 22:22:08 +0000213 pci_write_byte(dev, 0x52, 0xee);
214
215 new = pci_read_byte(dev, 0x52);
216
217 if (new != 0xee) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000218 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
219 0x52, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000220 return -1;
221 }
Ollie Lho184a4042005-11-26 21:55:36 +0000222
223 new = pci_read_byte(dev, 0x5b) | 0x20;
224 pci_write_byte(dev, 0x5b, new);
225
Ollie Lhocbbf1252004-03-17 22:22:08 +0000226 return 0;
227}
228
Ollie Lho184a4042005-11-26 21:55:36 +0000229
Ollie Lhocbbf1252004-03-17 22:22:08 +0000230static int enable_flash_sc1100(struct pci_dev *dev, char *name)
231{
Ollie Lho184a4042005-11-26 21:55:36 +0000232 uint8_t new;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000233
Ollie Lhocbbf1252004-03-17 22:22:08 +0000234 pci_write_byte(dev, 0x52, 0xee);
235
236 new = pci_read_byte(dev, 0x52);
237
238 if (new != 0xee) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000239 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
240 0x52, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000241 return -1;
242 }
243 return 0;
244}
245
246static int enable_flash_sis5595(struct pci_dev *dev, char *name)
247{
Ollie Lho184a4042005-11-26 21:55:36 +0000248 uint8_t new, newer;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000249
Ollie Lhocbbf1252004-03-17 22:22:08 +0000250 new = pci_read_byte(dev, 0x45);
251
252 /* clear bit 5 */
Ollie Lho761bf1b2004-03-20 16:46:10 +0000253 new &= (~0x20);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000254 /* set bit 2 */
255 new |= 0x4;
256
257 pci_write_byte(dev, 0x45, new);
258
259 newer = pci_read_byte(dev, 0x45);
260 if (newer != new) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000261 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
262 0x45, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000263 printf("Stuck at 0x%x\n", newer);
264 return -1;
265 }
266 return 0;
267}
268
Ollie Lho761bf1b2004-03-20 16:46:10 +0000269static int enable_flash_amd8111(struct pci_dev *dev, char *name)
270{
Ollie Lhocbbf1252004-03-17 22:22:08 +0000271 /* register 4e.b gets or'ed with one */
Ollie Lho184a4042005-11-26 21:55:36 +0000272 uint8_t old, new;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000273 /* if it fails, it fails. There are so many variations of broken mobos
274 * that it is hard to argue that we should quit at this point.
275 */
276
Ollie Lhod11f3612004-12-07 17:19:04 +0000277 /* enable decoding at 0xffb00000 to 0xffffffff */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000278 old = pci_read_byte(dev, 0x43);
Ollie Lhod11f3612004-12-07 17:19:04 +0000279 new = old | 0xC0;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000280 if (new != old) {
281 pci_write_byte(dev, 0x43, new);
282 if (pci_read_byte(dev, 0x43) != new) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000283 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
284 0x43, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000285 }
286 }
287
Ollie Lho761bf1b2004-03-20 16:46:10 +0000288 old = pci_read_byte(dev, 0x40);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000289 new = old | 0x01;
290 if (new == old)
291 return 0;
292 pci_write_byte(dev, 0x40, new);
293
294 if (pci_read_byte(dev, 0x40) != new) {
Ollie Lho8b8897a2004-03-27 00:18:15 +0000295 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
296 0x40, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000297 return -1;
298 }
299 return 0;
300}
301
Yinghai Lu952dfce2005-07-06 17:13:46 +0000302//By yhlu
303static int enable_flash_ck804(struct pci_dev *dev, char *name)
304{
305 /* register 4e.b gets or'ed with one */
Ollie Lho184a4042005-11-26 21:55:36 +0000306 uint8_t old, new;
Yinghai Lu952dfce2005-07-06 17:13:46 +0000307 /* if it fails, it fails. There are so many variations of broken mobos
308 * that it is hard to argue that we should quit at this point.
309 */
310
311 //dump_pci_device(dev);
312
313 old = pci_read_byte(dev, 0x88);
314 new = old | 0xc0;
315 if (new != old) {
316 pci_write_byte(dev, 0x88, new);
317 if (pci_read_byte(dev, 0x88) != new) {
318 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
319 0x88, new, name);
320 }
321 }
322
323 old = pci_read_byte(dev, 0x6d);
324 new = old | 0x01;
325 if (new == old)
326 return 0;
327 pci_write_byte(dev, 0x6d, new);
328
329 if (pci_read_byte(dev, 0x6d) != new) {
330 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
331 0x6d, new, name);
332 return -1;
333 }
334 return 0;
335}
336
Stefan Reinauer86de2832006-03-31 11:26:55 +0000337static int enable_flash_sb400(struct pci_dev *dev, char *name)
338{
339 uint8_t tmp;
340
341 struct pci_filter f;
342 struct pci_dev *smbusdev;
343
344 /* get io privilege access */
345 if (iopl(3) != 0) {
346 perror("Can not set io priviliage");
347 exit(1);
348 }
349
350 /* then look for the smbus device */
351 pci_filter_init((struct pci_access *) 0, &f);
352 f.vendor = 0x1002;
353 f.device = 0x4372;
354
355 for (smbusdev = pacc->devices; smbusdev; smbusdev = smbusdev->next) {
356 if (pci_filter_match(&f, smbusdev)) {
357 break;
358 }
359 }
360
361 if(!smbusdev) {
362 perror("smbus device not found. aborting\n");
363 exit(1);
364 }
365
366 // enable some smbus stuff
367 tmp=pci_read_byte(smbusdev, 0x79);
368 tmp|=0x01;
369 pci_write_byte(smbusdev, 0x79, tmp);
370
371 // change southbridge
372 tmp=pci_read_byte(dev, 0x48);
373 tmp|=0x21;
374 pci_write_byte(dev, 0x48, tmp);
375
376 // now become a bit silly.
377 tmp=inb(0xc6f);
378 outb(tmp,0xeb);
379 outb(tmp, 0xeb);
380 tmp|=0x40;
381 outb(tmp, 0xc6f);
382 outb(tmp, 0xeb);
383 outb(tmp, 0xeb);
384
385 return 0;
386}
387
Ollie Lhocbbf1252004-03-17 22:22:08 +0000388typedef struct penable {
Ollie Lho761bf1b2004-03-20 16:46:10 +0000389 unsigned short vendor, device;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000390 char *name;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000391 int (*doit) (struct pci_dev * dev, char *name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000392} FLASH_ENABLE;
393
394static FLASH_ENABLE enables[] = {
Stefan Reinauereb366472006-09-06 15:48:48 +0000395 {0x1039, 0x0630, "SIS630", enable_flash_sis630},
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000396 {0x8086, 0x7110, "PIIX4/PIIX4E/PIIX4M", enable_flash_piix4},
Stefan Reinauereb366472006-09-06 15:48:48 +0000397 {0x8086, 0x2410, "ICH", enable_flash_ich_4e},
398 {0x8086, 0x2420, "ICH0", enable_flash_ich_4e},
399 {0x8086, 0x2440, "ICH2", enable_flash_ich_4e},
400 {0x8086, 0x244c, "ICH2-M", enable_flash_ich_4e},
401 {0x8086, 0x2480, "ICH3-S", enable_flash_ich_4e},
402 {0x8086, 0x248c, "ICH3-M", enable_flash_ich_4e},
403 {0x8086, 0x24c0, "ICH4/ICH4-L", enable_flash_ich_4e},
404 {0x8086, 0x24cc, "ICH4-M", enable_flash_ich_4e},
405 {0x8086, 0x24d0, "ICH5/ICH5R", enable_flash_ich_4e},
406 {0x8086, 0x2640, "ICH6/ICH6R", enable_flash_ich_dc},
407 {0x8086, 0x2641, "ICH6-M", enable_flash_ich_dc},
408 {0x8086, 0x27b8, "ICH7/ICH7R", enable_flash_ich_dc},
409 {0x8086, 0x27b9, "ICH7M", enable_flash_ich_dc},
410 {0x8086, 0x27bd, "ICH7MDH", enable_flash_ich_dc},
411 {0x8086, 0x2810, "ICH8/ICH8R", enable_flash_ich_dc},
412 {0x8086, 0x2812, "ICH8DH", enable_flash_ich_dc},
413 {0x8086, 0x2814, "ICH8DO", enable_flash_ich_dc},
Ollie Lho761bf1b2004-03-20 16:46:10 +0000414 {0x1106, 0x8231, "VT8231", enable_flash_vt8231},
415 {0x1106, 0x3177, "VT8235", enable_flash_vt8235},
Stefan Reinauer219b61e2006-10-14 21:04:49 +0000416 {0x1106, 0x3227, "VT8237", enable_flash_vt8231},
Ollie Lho761bf1b2004-03-20 16:46:10 +0000417 {0x1078, 0x0100, "CS5530", enable_flash_cs5530},
418 {0x100b, 0x0510, "SC1100", enable_flash_sc1100},
Ollie Lhocbbf1252004-03-17 22:22:08 +0000419 {0x1039, 0x0008, "SIS5595", enable_flash_sis5595},
420 {0x1022, 0x7468, "AMD8111", enable_flash_amd8111},
Stefan Reinauer86de2832006-03-31 11:26:55 +0000421 // this fallthrough looks broken.
Yinghai Lu952dfce2005-07-06 17:13:46 +0000422 {0x10de, 0x0050, "NVIDIA CK804", enable_flash_ck804}, // LPC
423 {0x10de, 0x0051, "NVIDIA CK804", enable_flash_ck804}, // Pro
424 {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 +0000425
426 {0x10de, 0x0260, "NVidia MCP51", enable_flash_ck804},
427 {0x10de, 0x0261, "NVidia MCP51", enable_flash_ck804},
428 {0x10de, 0x0262, "NVidia MCP51", enable_flash_ck804},
429 {0x10de, 0x0263, "NVidia MCP51", enable_flash_ck804},
430
Stefan Reinauer86de2832006-03-31 11:26:55 +0000431 {0x1002, 0x4377, "ATI SB400", enable_flash_sb400}, // ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000432};
Ollie Lho761bf1b2004-03-20 16:46:10 +0000433
Ollie Lho184a4042005-11-26 21:55:36 +0000434static int mbenable_island_aruma(void)
435{
Stefan Reinauer86de2832006-03-31 11:26:55 +0000436#define EFIR 0x2e /* Extended function index register, either 0x2e or 0x4e */
437#define EFDR EFIR + 1 /* Extended function data register, one plus the index reg. */
Ollie Lho184a4042005-11-26 21:55:36 +0000438 char b;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000439
440/* Disable the flash write protect. The flash write protect is
441 * connected to the WinBond w83627hf GPIO 24.
442 */
Ollie Lho184a4042005-11-26 21:55:36 +0000443
444 /* get io privilege access winbond config space */
445 if (iopl(3) != 0) {
446 perror("Can not set io priviliage");
447 exit(1);
448 }
449
450 printf("Disabling mainboard flash write protection.\n");
451
452 outb(0x87, EFIR); // sequence to unlock extended functions
453 outb(0x87, EFIR);
454
455 outb(0x20, EFIR); // SIO device ID register
456 b = inb(EFDR);
457 printf_debug("W83627HF device ID = 0x%x\n",b);
458
459 if (b != 0x52) {
460 perror("Incorrect device ID, aborting write protect disable\n");
461 exit(1);
462 }
463
464 outb(0x2b, EFIR); // GPIO multiplexed pin reg.
465 b = inb(EFDR) | 0x10;
466 outb(0x2b, EFIR);
467 outb(b, EFDR); // select GPIO 24 instead of WDTO
468
469 outb(0x7, EFIR); // logical device select
470 outb(0x8, EFDR); // point to device 8, GPIO port 2
471
472 outb(0x30, EFIR); // logic device activation control
473 outb(0x1, EFDR); // activate
474
475 outb(0xf0, EFIR); // GPIO 20-27 I/O selection register
476 b = inb(EFDR) & ~0x10;
477 outb(0xf0, EFIR);
478 outb(b, EFDR); // set GPIO 24 as an output
479
480 outb(0xf1, EFIR); // GPIO 20-27 data register
481 b = inb(EFDR) | 0x10;
482 outb(0xf1, EFIR);
483 outb(b, EFDR); // set GPIO 24
484
485 outb(0xaa, EFIR); // command to exit extended functions
486
487 return 0;
488}
489
490typedef struct mbenable {
491 char *vendor, *part;
492 int (*doit)(void);
493} MAINBOARD_ENABLE;
494
495static MAINBOARD_ENABLE mbenables[] = {
496 { "ISLAND", "ARUMA", mbenable_island_aruma },
497};
498
Ollie Lhocbbf1252004-03-17 22:22:08 +0000499int enable_flash_write()
500{
501 int i;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000502 struct pci_dev *dev = 0;
503 FLASH_ENABLE *enable = 0;
504
Ollie Lho761bf1b2004-03-20 16:46:10 +0000505 pacc = pci_alloc(); /* Get the pci_access structure */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000506 /* Set all options you want -- here we stick with the defaults */
Ollie Lho761bf1b2004-03-20 16:46:10 +0000507 pci_init(pacc); /* Initialize the PCI library */
508 pci_scan_bus(pacc); /* We want to get the list of devices */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000509
Ollie Lho184a4042005-11-26 21:55:36 +0000510
511 /* First look whether we have to do something for this
512 * motherboard.
513 */
514 for (i = 0; i < sizeof(mbenables) / sizeof(mbenables[0]); i++) {
515 if(lb_vendor && !strcmp(mbenables[i].vendor, lb_vendor) &&
516 lb_part && !strcmp(mbenables[i].part, lb_part)) {
517 mbenables[i].doit();
518 break;
519 }
520 }
521
Ollie Lhocbbf1252004-03-17 22:22:08 +0000522 /* now let's try to find the chipset we have ... */
Ollie Lho761bf1b2004-03-20 16:46:10 +0000523 for (i = 0; i < sizeof(enables) / sizeof(enables[0]) && (!dev);
524 i++) {
Ollie Lhocbbf1252004-03-17 22:22:08 +0000525 struct pci_filter f;
526 struct pci_dev *z;
527 /* the first param is unused. */
528 pci_filter_init((struct pci_access *) 0, &f);
529 f.vendor = enables[i].vendor;
530 f.device = enables[i].device;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000531 for (z = pacc->devices; z; z = z->next)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000532 if (pci_filter_match(&f, z)) {
533 enable = &enables[i];
534 dev = z;
535 }
536 }
537
Stefan Reinauercbc55d02006-08-25 19:21:42 +0000538 if (!enable) {
539 printf("Warning: Unknown system. Flash detection "
540 "will most likely fail.\n");
541 return 1;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000542 }
Stefan Reinauercbc55d02006-08-25 19:21:42 +0000543
544 /* now do the deed. */
545 printf("Enabling flash write on %s...", enable->name);
546 if (enable->doit(dev, enable->name) == 0)
547 printf("OK\n");
Ollie Lhocbbf1252004-03-17 22:22:08 +0000548 return 0;
549}