blob: 43ca02c37cf0d4dea9820e0b36609bbdb873c9ed [file] [log] [blame]
Luc Verhaegen8e3a6002007-04-04 22:45:58 +00001/*
Uwe Hermannd1107642007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +00003 *
Uwe Hermannd1107642007-08-29 17:52:32 +00004 * Copyright (C) 2005-2007 coresystems GmbH <stepan@coresystems.de>
5 * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de>
6 * Copyright (C) 2007 Luc Verhaegen <libv@skynet.be>
Carl-Daniel Hailfinger92242622007-09-27 14:29:57 +00007 * Copyright (C) 2007 Carl-Daniel Hailfinger
Luc Verhaegen8e3a6002007-04-04 22:45:58 +00008 *
Uwe Hermannd1107642007-08-29 17:52:32 +00009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000012 *
Uwe Hermannd1107642007-08-29 17:52:32 +000013 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000021 */
22
23/*
24 * Contains the board specific flash enables.
25 */
26
27#include <stdio.h>
28#include <pci/pci.h>
29#include <stdint.h>
30#include <string.h>
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000031#include "flash.h"
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000032
Carl-Daniel Hailfinger92242622007-09-27 14:29:57 +000033/* Generic Super I/O helper functions */
34uint8_t regval(uint16_t port, uint8_t reg)
35{
36 outb(reg, port);
37 return inb(port + 1);
38}
39
40void regwrite(uint16_t port, uint8_t reg, uint8_t val)
41{
42 outb(reg, port);
43 outb(val, port + 1);
44}
45
46/* Helper functions for most recent ITE IT87xx Super I/O chips */
47#define CHIP_ID_BYTE1_REG 0x20
48#define CHIP_ID_BYTE2_REG 0x21
49static void enter_conf_mode_ite(uint16_t port)
50{
51 outb(0x87, port);
52 outb(0x01, port);
53 outb(0x55, port);
54 if (port == 0x2e)
55 outb(0x55, port);
56 else
57 outb(0xaa, port);
58}
59
60static void exit_conf_mode_ite(uint16_t port)
61{
62 regwrite(port, 0x02, 0x02);
63}
64
65static uint16_t find_ite_serial_flash_port(uint16_t port)
66{
67 uint8_t tmp = 0;
68 uint16_t id, flashport = 0;
69
70 enter_conf_mode_ite(port);
71
72 id = regval(port, CHIP_ID_BYTE1_REG) << 8;
73 id |= regval(port, CHIP_ID_BYTE2_REG);
74
75 /* TODO: Handle more IT87xx if they support flash translation */
76 if (id == 0x8716) {
77 /* NOLDN, reg 0x24, mask out lowest bit (suspend) */
78 tmp = regval(port, 0x24) & 0xFE;
79 printf("Serial flash segment 0x%08x-0x%08x %sabled\n",
80 0xFFFE0000, 0xFFFFFFFF, (tmp & 1 << 1) ? "en" : "dis");
81 printf("Serial flash segment 0x%08x-0x%08x %sabled\n",
82 0x000E0000, 0x000FFFFF, (tmp & 1 << 1) ? "en" : "dis");
83 printf("Serial flash segment 0x%08x-0x%08x %sabled\n",
84 0xFFEE0000, 0xFFEFFFFF, (tmp & 1 << 2) ? "en" : "dis");
85 printf("Serial flash segment 0x%08x-0x%08x %sabled\n",
86 0xFFF80000, 0xFFFEFFFF, (tmp & 1 << 3) ? "en" : "dis");
87 printf("LPC write to serial flash %sabled\n",
88 (tmp & 1 << 4) ? "en" : "dis");
89 printf("serial flash pin %i\n", (tmp & 1 << 5) ? 87 : 29);
90 /* LDN 0x7, reg 0x64/0x65 */
91 regwrite(port, 0x07, 0x7);
92 flashport = regval(port, 0x64) << 8;
93 flashport |= regval(port, 0x65);
94 }
95 exit_conf_mode_ite(port);
96 return flashport;
97}
98
99static void it8716_serial_rdid(uint16_t port)
100{
101 uint8_t busy, data0, data1, data2;
102 do {
103 busy = inb(port) & 0x80;
104 } while (busy);
105 /* RDID */
106 outb(0x9f, port + 1);
107 /* Start IO, 33MHz, 3 input bytes, 0 output bytes*/
108 outb((0x5<<4)|(0x3<<2)|(0x0), port);
109 do {
110 busy = inb(port) & 0x80;
111 } while (busy);
112 data0 = inb(port + 5);
113 data1 = inb(port + 6);
114 data2 = inb(port + 7);
115 printf("RDID returned %02x %02x %02x\n", data0, data1, data2);
116 return;
117}
118
119static int it87xx_probe_serial_flash(const char *name)
120{
121 uint16_t flashport;
122 flashport = find_ite_serial_flash_port(0x2e);
123 if (flashport)
124 it8716_serial_rdid(flashport);
125 flashport = find_ite_serial_flash_port(0x4e);
126 if (flashport)
127 it8716_serial_rdid(flashport);
128 return 0;
129}
130
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000131/*
Uwe Hermannffec5f32007-08-23 16:08:21 +0000132 * Helper functions for many Winbond Super I/Os of the W836xx range.
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000133 */
134#define W836_INDEX 0x2E
135#define W836_DATA 0x2F
136
137/* Enter extended functions */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000138static void w836xx_ext_enter(void)
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000139{
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000140 outb(0x87, W836_INDEX);
141 outb(0x87, W836_INDEX);
142}
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000143
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000144/* Leave extended functions */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000145static void w836xx_ext_leave(void)
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000146{
147 outb(0xAA, W836_INDEX);
148}
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000149
Uwe Hermannffec5f32007-08-23 16:08:21 +0000150/* General functions for reading/writing Winbond Super I/Os. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000151static unsigned char wbsio_read(unsigned char index)
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000152{
153 outb(index, W836_INDEX);
154 return inb(W836_DATA);
155}
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000156
Uwe Hermanna7e05482007-05-09 10:17:44 +0000157static void wbsio_write(unsigned char index, unsigned char data)
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000158{
159 outb(index, W836_INDEX);
160 outb(data, W836_DATA);
161}
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000162
Uwe Hermannffec5f32007-08-23 16:08:21 +0000163static void wbsio_mask(unsigned char index, unsigned char data,
164 unsigned char mask)
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000165{
166 unsigned char tmp;
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000167
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000168 outb(index, W836_INDEX);
169 tmp = inb(W836_DATA) & ~mask;
170 outb(tmp | (data & mask), W836_DATA);
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000171}
172
Uwe Hermannffec5f32007-08-23 16:08:21 +0000173/**
174 * Winbond W83627HF: Raise GPIO24.
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000175 *
176 * Suited for:
Uwe Hermannffec5f32007-08-23 16:08:21 +0000177 * - Agami Aruma
178 * - IWILL DK8-HTX
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000179 */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000180static int w83627hf_gpio24_raise(const char *name)
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000181{
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000182 w836xx_ext_enter();
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000183
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000184 /* Is this the w83627hf? */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000185 if (wbsio_read(0x20) != 0x52) { /* SIO device ID register */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000186 fprintf(stderr, "\nERROR: %s: W83627HF: Wrong ID: 0x%02X.\n",
187 name, wbsio_read(0x20));
188 w836xx_ext_leave();
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000189 return -1;
190 }
191
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000192 /* PIN89S: WDTO/GP24 multiplex -> GPIO24 */
193 wbsio_mask(0x2B, 0x10, 0x10);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000194
Uwe Hermanna7e05482007-05-09 10:17:44 +0000195 wbsio_write(0x07, 0x08); /* Select logical device 8: GPIO port 2 */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000196
Uwe Hermanna7e05482007-05-09 10:17:44 +0000197 wbsio_mask(0x30, 0x01, 0x01); /* Activate logical device. */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000198
Uwe Hermanna7e05482007-05-09 10:17:44 +0000199 wbsio_mask(0xF0, 0x00, 0x10); /* GPIO24 -> output */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000200
Uwe Hermanna7e05482007-05-09 10:17:44 +0000201 wbsio_mask(0xF2, 0x00, 0x10); /* Clear GPIO24 inversion */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000202
Uwe Hermanna7e05482007-05-09 10:17:44 +0000203 wbsio_mask(0xF1, 0x10, 0x10); /* Raise GPIO24 */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000204
205 w836xx_ext_leave();
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000206
207 return 0;
208}
209
Uwe Hermannffec5f32007-08-23 16:08:21 +0000210/**
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000211 * Suited for VIAs EPIA M and MII, and maybe other CLE266 based EPIAs.
212 *
Uwe Hermannffec5f32007-08-23 16:08:21 +0000213 * We don't need to do this when using LinuxBIOS, GPIO15 is never lowered there.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000214 */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000215static int board_via_epia_m(const char *name)
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000216{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000217 struct pci_dev *dev;
218 unsigned int base;
219 uint8_t val;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000220
Uwe Hermanna7e05482007-05-09 10:17:44 +0000221 dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */
222 if (!dev) {
223 fprintf(stderr, "\nERROR: VT8235 ISA Bridge not found.\n");
224 return -1;
225 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000226
Uwe Hermanna7e05482007-05-09 10:17:44 +0000227 /* GPIO12-15 -> output */
228 val = pci_read_byte(dev, 0xE4);
229 val |= 0x10;
230 pci_write_byte(dev, 0xE4, val);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000231
Uwe Hermanna7e05482007-05-09 10:17:44 +0000232 /* Get Power Management IO address. */
233 base = pci_read_word(dev, 0x88) & 0xFF80;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000234
Uwe Hermanna7e05482007-05-09 10:17:44 +0000235 /* enable GPIO15 which is connected to write protect. */
236 val = inb(base + 0x4D);
237 val |= 0x80;
238 outb(val, base + 0x4D);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000239
Uwe Hermanna7e05482007-05-09 10:17:44 +0000240 return 0;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000241}
242
Uwe Hermannffec5f32007-08-23 16:08:21 +0000243/**
Luc Verhaegen32707542007-07-04 17:51:49 +0000244 * Suited for:
Uwe Hermannffec5f32007-08-23 16:08:21 +0000245 * - ASUS A7V8X-MX SE and A7V400-MX: AMD K7 + VIA KM400A + VT8235
246 * - Tyan Tomcat K7M: AMD Geode NX + VIA KM400 + VT8237.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000247 */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000248static int board_asus_a7v8x_mx(const char *name)
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000249{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000250 struct pci_dev *dev;
251 uint8_t val;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000252
Uwe Hermanna7e05482007-05-09 10:17:44 +0000253 dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */
Luc Verhaegen32707542007-07-04 17:51:49 +0000254 if (!dev)
255 dev = pci_dev_find(0x1106, 0x3227); /* VT8237 ISA bridge */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000256 if (!dev) {
Luc Verhaegen32707542007-07-04 17:51:49 +0000257 fprintf(stderr, "\nERROR: VT823x ISA bridge not found.\n");
Uwe Hermanna7e05482007-05-09 10:17:44 +0000258 return -1;
259 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000260
Uwe Hermanna7e05482007-05-09 10:17:44 +0000261 /* This bit is marked reserved actually */
262 val = pci_read_byte(dev, 0x59);
263 val &= 0x7F;
264 pci_write_byte(dev, 0x59, val);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000265
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000266 /* Raise ROM MEMW# line on Winbond w83697 SuperIO */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000267 w836xx_ext_enter();
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000268
Uwe Hermanna7e05482007-05-09 10:17:44 +0000269 if (!(wbsio_read(0x24) & 0x02)) /* flash rom enabled? */
270 wbsio_mask(0x24, 0x08, 0x08); /* enable MEMW# */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000271
272 w836xx_ext_leave();
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000273
Uwe Hermanna7e05482007-05-09 10:17:44 +0000274 return 0;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000275}
276
Uwe Hermannffec5f32007-08-23 16:08:21 +0000277/**
Luc Verhaegen6b141752007-05-20 16:16:13 +0000278 * Suited for ASUS P5A.
279 *
280 * This is rather nasty code, but there's no way to do this cleanly.
281 * We're basically talking to some unknown device on SMBus, my guess
282 * is that it is the Winbond W83781D that lives near the DIP BIOS.
283 */
Luc Verhaegen6b141752007-05-20 16:16:13 +0000284static int board_asus_p5a(const char *name)
285{
286 uint8_t tmp;
287 int i;
288
289#define ASUSP5A_LOOP 5000
290
291 outb(0x00, 0xE807);
292 outb(0xEF, 0xE803);
293
294 outb(0xFF, 0xE800);
295
296 for (i = 0; i < ASUSP5A_LOOP; i++) {
297 outb(0xE1, 0xFF);
298 if (inb(0xE800) & 0x04)
299 break;
300 }
301
302 if (i == ASUSP5A_LOOP) {
303 printf("%s: Unable to contact device.\n", name);
304 return -1;
305 }
306
307 outb(0x20, 0xE801);
308 outb(0x20, 0xE1);
309
310 outb(0xFF, 0xE802);
311
312 for (i = 0; i < ASUSP5A_LOOP; i++) {
313 tmp = inb(0xE800);
314 if (tmp & 0x70)
315 break;
316 }
317
318 if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) {
319 printf("%s: failed to read device.\n", name);
320 return -1;
321 }
322
323 tmp = inb(0xE804);
324 tmp &= ~0x02;
325
326 outb(0x00, 0xE807);
327 outb(0xEE, 0xE803);
328
329 outb(tmp, 0xE804);
330
331 outb(0xFF, 0xE800);
332 outb(0xE1, 0xFF);
333
334 outb(0x20, 0xE801);
335 outb(0x20, 0xE1);
336
337 outb(0xFF, 0xE802);
338
339 for (i = 0; i < ASUSP5A_LOOP; i++) {
340 tmp = inb(0xE800);
341 if (tmp & 0x70)
342 break;
343 }
344
345 if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) {
346 printf("%s: failed to write to device.\n", name);
347 return -1;
348 }
349
350 return 0;
351}
352
Stefan Reinauer1c283f42007-06-05 12:51:52 +0000353static int board_ibm_x3455(const char *name)
354{
355 uint8_t byte;
356
Uwe Hermanne823ee02007-06-05 15:02:18 +0000357 /* Set GPIO lines in the Broadcom HT-1000 southbridge. */
Stefan Reinauer1c283f42007-06-05 12:51:52 +0000358 outb(0x45, 0xcd6);
359 byte = inb(0xcd7);
Uwe Hermanne823ee02007-06-05 15:02:18 +0000360 outb(byte | 0x20, 0xcd7);
Stefan Reinauer1c283f42007-06-05 12:51:52 +0000361
362 return 0;
363}
364
Luc Verhaegenfdd0c582007-08-11 16:59:11 +0000365/**
366 * Suited for EPoX EP-BX3, and maybe some other Intel 440BX based boards.
367 */
368static int board_epox_ep_bx3(const char *name)
369{
370 uint8_t tmp;
371
372 /* Raise GPIO22. */
373 tmp = inb(0x4036);
374 outb(tmp, 0xEB);
375
376 tmp |= 0x40;
377
378 outb(tmp, 0x4036);
379 outb(tmp, 0xEB);
380
381 return 0;
382}
383
Uwe Hermannffec5f32007-08-23 16:08:21 +0000384/**
385 * We use 2 sets of IDs here, you're free to choose which is which. This
386 * is to provide a very high degree of certainty when matching a board on
387 * the basis of subsystem/card IDs. As not every vendor handles
388 * subsystem/card IDs in a sane manner.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000389 *
Uwe Hermannffec5f32007-08-23 16:08:21 +0000390 * Keep the second set NULLed if it should be ignored.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000391 */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000392struct board_pciid_enable {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000393 /* Any device, but make it sensible, like the isa bridge. */
394 uint16_t first_vendor;
395 uint16_t first_device;
396 uint16_t first_card_vendor;
397 uint16_t first_card_device;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000398
Uwe Hermanna7e05482007-05-09 10:17:44 +0000399 /* Any device, but make it sensible, like
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000400 * the host bridge. May be NULL
401 */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000402 uint16_t second_vendor;
403 uint16_t second_device;
404 uint16_t second_card_vendor;
405 uint16_t second_card_device;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000406
Uwe Hermanna7e05482007-05-09 10:17:44 +0000407 /* From linuxbios table */
408 char *lb_vendor;
409 char *lb_part;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000410
Uwe Hermanna7e05482007-05-09 10:17:44 +0000411 char *name;
412 int (*enable) (const char *name);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000413};
414
415struct board_pciid_enable board_pciid_enables[] = {
Carl-Daniel Hailfinger92242622007-09-27 14:29:57 +0000416 {0x10de, 0x0360, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
417 "gigabyte", "m57sli", "GIGABYTE GA-M57SLI", it87xx_probe_serial_flash},
Uwe Hermanna7e05482007-05-09 10:17:44 +0000418 {0x1022, 0x7468, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
419 "iwill", "dk8_htx", "IWILL DK8-HTX", w83627hf_gpio24_raise},
420 {0x1022, 0x746B, 0x1022, 0x36C0, 0x0000, 0x0000, 0x0000, 0x0000,
421 "AGAMI", "ARUMA", "agami Aruma", w83627hf_gpio24_raise},
422 {0x1106, 0x3177, 0x1106, 0xAA01, 0x1106, 0x3123, 0x1106, 0xAA01,
423 NULL, NULL, "VIA EPIA M/MII/...", board_via_epia_m},
424 {0x1106, 0x3177, 0x1043, 0x80A1, 0x1106, 0x3205, 0x1043, 0x8118,
425 NULL, NULL, "ASUS A7V8-MX SE", board_asus_a7v8x_mx},
Luc Verhaegen32707542007-07-04 17:51:49 +0000426 {0x8086, 0x1076, 0x8086, 0x1176, 0x1106, 0x3059, 0x10f1, 0x2498,
427 NULL, NULL, "Tyan Tomcat K7M", board_asus_a7v8x_mx},
Luc Verhaegen6b141752007-05-20 16:16:13 +0000428 {0x10B9, 0x1541, 0x0000, 0x0000, 0x10B9, 0x1533, 0x0000, 0x0000,
429 "asus", "p5a", "ASUS P5A", board_asus_p5a},
Stefan Reinauer1c283f42007-06-05 12:51:52 +0000430 {0x1166, 0x0205, 0x1014, 0x0347, 0x0000, 0x0000, 0x0000, 0x0000,
431 "ibm", "x3455", "IBM x3455", board_ibm_x3455},
Luc Verhaegenfdd0c582007-08-11 16:59:11 +0000432 {0x8086, 0x7110, 0x0000, 0x0000, 0x8086, 0x7190, 0x0000, 0x0000,
433 "epox", "ep-bx3", "EPoX EP-BX3", board_epox_ep_bx3},
Uwe Hermanna7e05482007-05-09 10:17:44 +0000434 {0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL} /* Keep this */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000435};
436
Uwe Hermannffec5f32007-08-23 16:08:21 +0000437/**
438 * Match boards on LinuxBIOS table gathered vendor and part name.
439 * Require main PCI IDs to match too as extra safety.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000440 */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000441static struct board_pciid_enable *board_match_linuxbios_name(char *vendor,
442 char *part)
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000443{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000444 struct board_pciid_enable *board = board_pciid_enables;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000445
Uwe Hermanna7e05482007-05-09 10:17:44 +0000446 for (; board->name; board++) {
447 if (!board->lb_vendor || strcmp(board->lb_vendor, vendor))
448 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000449
Uwe Hermanna7e05482007-05-09 10:17:44 +0000450 if (!board->lb_part || strcmp(board->lb_part, part))
451 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000452
Uwe Hermanna7e05482007-05-09 10:17:44 +0000453 if (!pci_dev_find(board->first_vendor, board->first_device))
454 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000455
Uwe Hermanna7e05482007-05-09 10:17:44 +0000456 if (board->second_vendor &&
457 !pci_dev_find(board->second_vendor, board->second_device))
458 continue;
459 return board;
460 }
461 return NULL;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000462}
463
Uwe Hermannffec5f32007-08-23 16:08:21 +0000464/**
465 * Match boards on PCI IDs and subsystem IDs.
466 * Second set of IDs can be main only or missing completely.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000467 */
468static struct board_pciid_enable *board_match_pci_card_ids(void)
469{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000470 struct board_pciid_enable *board = board_pciid_enables;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000471
Uwe Hermanna7e05482007-05-09 10:17:44 +0000472 for (; board->name; board++) {
473 if (!board->first_card_vendor || !board->first_card_device)
474 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000475
Uwe Hermanna7e05482007-05-09 10:17:44 +0000476 if (!pci_card_find(board->first_vendor, board->first_device,
477 board->first_card_vendor,
478 board->first_card_device))
479 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000480
Uwe Hermanna7e05482007-05-09 10:17:44 +0000481 if (board->second_vendor) {
482 if (board->second_card_vendor) {
483 if (!pci_card_find(board->second_vendor,
484 board->second_device,
485 board->second_card_vendor,
486 board->second_card_device))
487 continue;
488 } else {
489 if (!pci_dev_find(board->second_vendor,
490 board->second_device))
491 continue;
492 }
493 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000494
Uwe Hermanna7e05482007-05-09 10:17:44 +0000495 return board;
496 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000497
Uwe Hermanna7e05482007-05-09 10:17:44 +0000498 return NULL;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000499}
500
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000501int board_flash_enable(char *vendor, char *part)
502{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000503 struct board_pciid_enable *board = NULL;
504 int ret = 0;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000505
Uwe Hermanna7e05482007-05-09 10:17:44 +0000506 if (vendor && part)
507 board = board_match_linuxbios_name(vendor, part);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000508
Uwe Hermanna7e05482007-05-09 10:17:44 +0000509 if (!board)
510 board = board_match_pci_card_ids();
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000511
Uwe Hermanna7e05482007-05-09 10:17:44 +0000512 if (board) {
513 printf("Found board \"%s\": Enabling flash write... ",
514 board->name);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000515
Uwe Hermanna7e05482007-05-09 10:17:44 +0000516 ret = board->enable(board->name);
517 if (ret)
518 printf("Failed!\n");
519 else
520 printf("OK.\n");
521 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000522
Uwe Hermanna7e05482007-05-09 10:17:44 +0000523 return ret;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000524}