blob: 78749634ae222e9fa81178e4d72c629cf496f5c8 [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
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000033/*
Uwe Hermannffec5f32007-08-23 16:08:21 +000034 * Helper functions for many Winbond Super I/Os of the W836xx range.
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000035 */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000036/* Enter extended functions */
Ronald G. Minnichfa496922007-10-12 21:22:40 +000037static void w836xx_ext_enter(uint16_t port)
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +000038{
Ronald G. Minnichfa496922007-10-12 21:22:40 +000039 outb(0x87, port);
40 outb(0x87, port);
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000041}
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +000042
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000043/* Leave extended functions */
Ronald G. Minnichfa496922007-10-12 21:22:40 +000044static void w836xx_ext_leave(uint16_t port)
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000045{
Ronald G. Minnichfa496922007-10-12 21:22:40 +000046 outb(0xAA, port);
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000047}
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +000048
Uwe Hermannffec5f32007-08-23 16:08:21 +000049/* General functions for reading/writing Winbond Super I/Os. */
Ronald G. Minnichfa496922007-10-12 21:22:40 +000050static unsigned char wbsio_read(uint16_t index, uint8_t reg)
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000051{
Ronald G. Minnichfa496922007-10-12 21:22:40 +000052 outb(reg, index);
53 return inb(index+1);
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000054}
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +000055
Ronald G. Minnichfa496922007-10-12 21:22:40 +000056static void wbsio_write(uint16_t index, uint8_t reg, uint8_t data)
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000057{
Ronald G. Minnichfa496922007-10-12 21:22:40 +000058 outb(reg, index);
59 outb(data, index+1);
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000060}
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +000061
Ronald G. Minnichfa496922007-10-12 21:22:40 +000062static void wbsio_mask(uint16_t index, uint8_t reg, uint8_t data, uint8_t mask)
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000063{
Ronald G. Minnichfa496922007-10-12 21:22:40 +000064 uint8_t tmp;
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +000065
Ronald G. Minnichfa496922007-10-12 21:22:40 +000066 outb(reg, index);
67 tmp = inb(index+1) & ~mask;
68 outb(tmp | (data & mask), index+1);
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +000069}
70
Uwe Hermannffec5f32007-08-23 16:08:21 +000071/**
72 * Winbond W83627HF: Raise GPIO24.
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000073 *
74 * Suited for:
Uwe Hermannffec5f32007-08-23 16:08:21 +000075 * - Agami Aruma
76 * - IWILL DK8-HTX
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000077 */
Ronald G. Minnichfa496922007-10-12 21:22:40 +000078static int w83627hf_gpio24_raise(uint16_t index, const char *name)
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000079{
Ronald G. Minnichfa496922007-10-12 21:22:40 +000080 w836xx_ext_enter(index);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000081
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000082 /* Is this the w83627hf? */
Ronald G. Minnichfa496922007-10-12 21:22:40 +000083 if (wbsio_read(index, 0x20) != 0x52) { /* Super I/O device ID register */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000084 fprintf(stderr, "\nERROR: %s: W83627HF: Wrong ID: 0x%02X.\n",
Ronald G. Minnichfa496922007-10-12 21:22:40 +000085 name, wbsio_read(index, 0x20));
86 w836xx_ext_leave(index);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000087 return -1;
88 }
89
Luc Verhaegen7977f4e2007-05-04 04:47:04 +000090 /* PIN89S: WDTO/GP24 multiplex -> GPIO24 */
Ronald G. Minnichfa496922007-10-12 21:22:40 +000091 wbsio_mask(index, 0x2B, 0x10, 0x10);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000092
Ronald G. Minnichfa496922007-10-12 21:22:40 +000093 wbsio_write(index, 0x07, 0x08); /* Select logical device 8: GPIO port 2 */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000094
Ronald G. Minnichfa496922007-10-12 21:22:40 +000095 wbsio_mask(index, 0x30, 0x01, 0x01); /* Activate logical device. */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000096
Ronald G. Minnichfa496922007-10-12 21:22:40 +000097 wbsio_mask(index, 0xF0, 0x00, 0x10); /* GPIO24 -> output */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000098
Ronald G. Minnichfa496922007-10-12 21:22:40 +000099 wbsio_mask(index, 0xF2, 0x00, 0x10); /* Clear GPIO24 inversion */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000100
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000101 wbsio_mask(index, 0xF1, 0x10, 0x10); /* Raise GPIO24 */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000102
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000103 w836xx_ext_leave(index);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000104
105 return 0;
106}
107
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000108static int w83627hf_gpio24_raise_2e(const char *name)
109{
110 return w83627hf_gpio24_raise(0x2d, name);
111}
112
113/**
114 * Winbond W83627THF: GPIO 4, bit 4
115 *
116 * Suited for:
117 * - MSI K8N-NEO3
118 */
119static int w83627thf_gpio4_4_raise(uint16_t index, const char *name)
120{
121 w836xx_ext_enter(index);
122 /* Is this the w83627thf? */
123 if (wbsio_read(index, 0x20) != 0x82) { /* Super I/O device ID register */
124 fprintf(stderr, "\nERROR: %s: W83627THF: Wrong ID: 0x%02X.\n",
125 name, wbsio_read(index, 0x20));
126 w836xx_ext_leave(index);
127 return -1;
128 }
129
130 /* PINxxxxS: GPIO4/bit 4 multiplex -> GPIOXXX */
131
132 wbsio_write(index, 0x07, 0x09); /* Select logical device 9: GPIO port 4 */
133
134 wbsio_mask(index, 0x30, 0x02, 0x02); /* Activate logical device. */
135
136 wbsio_mask(index, 0xF4, 0x00, 0x10); /* GPIO4 bit 4 -> output */
137
138 wbsio_mask(index, 0xF6, 0x00, 0x10); /* Clear GPIO4 bit 4 inversion */
139
140 wbsio_mask(index, 0xF5, 0x10, 0x10); /* Raise GPIO4 bit 4 */
141
142 w836xx_ext_leave(index);
143
144 return 0;
145}
146
147static int w83627thf_gpio4_4_raise_4e(const char *name)
148{
149 return w83627thf_gpio4_4_raise(0x4E, name);
150}
Uwe Hermannffec5f32007-08-23 16:08:21 +0000151/**
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000152 * Suited for VIAs EPIA M and MII, and maybe other CLE266 based EPIAs.
153 *
Uwe Hermannffec5f32007-08-23 16:08:21 +0000154 * We don't need to do this when using LinuxBIOS, GPIO15 is never lowered there.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000155 */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000156static int board_via_epia_m(const char *name)
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000157{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000158 struct pci_dev *dev;
159 unsigned int base;
160 uint8_t val;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000161
Uwe Hermanna7e05482007-05-09 10:17:44 +0000162 dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */
163 if (!dev) {
Uwe Hermanna502dce2007-10-17 23:55:15 +0000164 fprintf(stderr, "\nERROR: VT8235 ISA bridge not found.\n");
Uwe Hermanna7e05482007-05-09 10:17:44 +0000165 return -1;
166 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000167
Uwe Hermanna7e05482007-05-09 10:17:44 +0000168 /* GPIO12-15 -> output */
169 val = pci_read_byte(dev, 0xE4);
170 val |= 0x10;
171 pci_write_byte(dev, 0xE4, val);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000172
Uwe Hermanna7e05482007-05-09 10:17:44 +0000173 /* Get Power Management IO address. */
174 base = pci_read_word(dev, 0x88) & 0xFF80;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000175
Uwe Hermanna7e05482007-05-09 10:17:44 +0000176 /* enable GPIO15 which is connected to write protect. */
177 val = inb(base + 0x4D);
178 val |= 0x80;
179 outb(val, base + 0x4D);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000180
Uwe Hermanna7e05482007-05-09 10:17:44 +0000181 return 0;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000182}
183
Uwe Hermannffec5f32007-08-23 16:08:21 +0000184/**
Luc Verhaegen32707542007-07-04 17:51:49 +0000185 * Suited for:
Uwe Hermannffec5f32007-08-23 16:08:21 +0000186 * - ASUS A7V8X-MX SE and A7V400-MX: AMD K7 + VIA KM400A + VT8235
187 * - Tyan Tomcat K7M: AMD Geode NX + VIA KM400 + VT8237.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000188 */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000189static int board_asus_a7v8x_mx(const char *name)
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000190{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000191 struct pci_dev *dev;
192 uint8_t val;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000193
Uwe Hermanna7e05482007-05-09 10:17:44 +0000194 dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */
Luc Verhaegen32707542007-07-04 17:51:49 +0000195 if (!dev)
196 dev = pci_dev_find(0x1106, 0x3227); /* VT8237 ISA bridge */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000197 if (!dev) {
Luc Verhaegen32707542007-07-04 17:51:49 +0000198 fprintf(stderr, "\nERROR: VT823x ISA bridge not found.\n");
Uwe Hermanna7e05482007-05-09 10:17:44 +0000199 return -1;
200 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000201
Uwe Hermanna7e05482007-05-09 10:17:44 +0000202 /* This bit is marked reserved actually */
203 val = pci_read_byte(dev, 0x59);
204 val &= 0x7F;
205 pci_write_byte(dev, 0x59, val);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000206
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000207 /* Raise ROM MEMW# line on Winbond w83697 SuperIO */
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000208 w836xx_ext_enter(0x2E);
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000209
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000210 if (!(wbsio_read(0x2E, 0x24) & 0x02)) /* flash rom enabled? */
211 wbsio_mask(0x2E, 0x24, 0x08, 0x08); /* enable MEMW# */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000212
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000213 w836xx_ext_leave(0x2E);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000214
Uwe Hermanna7e05482007-05-09 10:17:44 +0000215 return 0;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000216}
217
Uwe Hermannffec5f32007-08-23 16:08:21 +0000218/**
Luc Verhaegen6b141752007-05-20 16:16:13 +0000219 * Suited for ASUS P5A.
220 *
221 * This is rather nasty code, but there's no way to do this cleanly.
222 * We're basically talking to some unknown device on SMBus, my guess
223 * is that it is the Winbond W83781D that lives near the DIP BIOS.
224 */
Luc Verhaegen6b141752007-05-20 16:16:13 +0000225static int board_asus_p5a(const char *name)
226{
227 uint8_t tmp;
228 int i;
229
230#define ASUSP5A_LOOP 5000
231
232 outb(0x00, 0xE807);
233 outb(0xEF, 0xE803);
234
235 outb(0xFF, 0xE800);
236
237 for (i = 0; i < ASUSP5A_LOOP; i++) {
238 outb(0xE1, 0xFF);
239 if (inb(0xE800) & 0x04)
240 break;
241 }
242
243 if (i == ASUSP5A_LOOP) {
244 printf("%s: Unable to contact device.\n", name);
245 return -1;
246 }
247
248 outb(0x20, 0xE801);
249 outb(0x20, 0xE1);
250
251 outb(0xFF, 0xE802);
252
253 for (i = 0; i < ASUSP5A_LOOP; i++) {
254 tmp = inb(0xE800);
255 if (tmp & 0x70)
256 break;
257 }
258
259 if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) {
260 printf("%s: failed to read device.\n", name);
261 return -1;
262 }
263
264 tmp = inb(0xE804);
265 tmp &= ~0x02;
266
267 outb(0x00, 0xE807);
268 outb(0xEE, 0xE803);
269
270 outb(tmp, 0xE804);
271
272 outb(0xFF, 0xE800);
273 outb(0xE1, 0xFF);
274
275 outb(0x20, 0xE801);
276 outb(0x20, 0xE1);
277
278 outb(0xFF, 0xE802);
279
280 for (i = 0; i < ASUSP5A_LOOP; i++) {
281 tmp = inb(0xE800);
282 if (tmp & 0x70)
283 break;
284 }
285
286 if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) {
287 printf("%s: failed to write to device.\n", name);
288 return -1;
289 }
290
291 return 0;
292}
293
Stefan Reinauer1c283f42007-06-05 12:51:52 +0000294static int board_ibm_x3455(const char *name)
295{
296 uint8_t byte;
297
Uwe Hermanne823ee02007-06-05 15:02:18 +0000298 /* Set GPIO lines in the Broadcom HT-1000 southbridge. */
Stefan Reinauer1c283f42007-06-05 12:51:52 +0000299 outb(0x45, 0xcd6);
300 byte = inb(0xcd7);
Uwe Hermanne823ee02007-06-05 15:02:18 +0000301 outb(byte | 0x20, 0xcd7);
Stefan Reinauer1c283f42007-06-05 12:51:52 +0000302
303 return 0;
304}
305
Luc Verhaegenfdd0c582007-08-11 16:59:11 +0000306/**
307 * Suited for EPoX EP-BX3, and maybe some other Intel 440BX based boards.
308 */
309static int board_epox_ep_bx3(const char *name)
310{
311 uint8_t tmp;
312
313 /* Raise GPIO22. */
314 tmp = inb(0x4036);
315 outb(tmp, 0xEB);
316
317 tmp |= 0x40;
318
319 outb(tmp, 0x4036);
320 outb(tmp, 0xEB);
321
322 return 0;
323}
324
Uwe Hermannffec5f32007-08-23 16:08:21 +0000325/**
326 * We use 2 sets of IDs here, you're free to choose which is which. This
327 * is to provide a very high degree of certainty when matching a board on
328 * the basis of subsystem/card IDs. As not every vendor handles
329 * subsystem/card IDs in a sane manner.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000330 *
Uwe Hermannffec5f32007-08-23 16:08:21 +0000331 * Keep the second set NULLed if it should be ignored.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000332 */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000333struct board_pciid_enable {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000334 /* Any device, but make it sensible, like the isa bridge. */
335 uint16_t first_vendor;
336 uint16_t first_device;
337 uint16_t first_card_vendor;
338 uint16_t first_card_device;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000339
Uwe Hermanna7e05482007-05-09 10:17:44 +0000340 /* Any device, but make it sensible, like
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000341 * the host bridge. May be NULL
342 */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000343 uint16_t second_vendor;
344 uint16_t second_device;
345 uint16_t second_card_vendor;
346 uint16_t second_card_device;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000347
Uwe Hermanna7e05482007-05-09 10:17:44 +0000348 /* From linuxbios table */
349 char *lb_vendor;
350 char *lb_part;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000351
Uwe Hermanna7e05482007-05-09 10:17:44 +0000352 char *name;
353 int (*enable) (const char *name);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000354};
355
356struct board_pciid_enable board_pciid_enables[] = {
Carl-Daniel Hailfinger92242622007-09-27 14:29:57 +0000357 {0x10de, 0x0360, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Uwe Hermanna502dce2007-10-17 23:55:15 +0000358 "gigabyte", "m57sli", "GIGABYTE GA-M57SLI-S4", it87xx_probe_spi_flash},
Michael van der Kolff3385cb82007-10-16 21:18:43 +0000359 {0x10de, 0x03e0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Uwe Hermanna502dce2007-10-17 23:55:15 +0000360 "gigabyte", "m61p", "GIGABYTE GA-M61P-S3", it87xx_probe_spi_flash},
Uwe Hermanna7e05482007-05-09 10:17:44 +0000361 {0x1022, 0x7468, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000362 "iwill", "dk8_htx", "IWILL DK8-HTX", w83627hf_gpio24_raise_2e},
363 {0x10de, 0x005e, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
364 "msi", "k8n-neo3", "MSI K8N Neo3", w83627thf_gpio4_4_raise_4e},
Uwe Hermanna7e05482007-05-09 10:17:44 +0000365 {0x1022, 0x746B, 0x1022, 0x36C0, 0x0000, 0x0000, 0x0000, 0x0000,
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000366 "AGAMI", "ARUMA", "agami Aruma", w83627hf_gpio24_raise_2e},
Uwe Hermanna7e05482007-05-09 10:17:44 +0000367 {0x1106, 0x3177, 0x1106, 0xAA01, 0x1106, 0x3123, 0x1106, 0xAA01,
368 NULL, NULL, "VIA EPIA M/MII/...", board_via_epia_m},
369 {0x1106, 0x3177, 0x1043, 0x80A1, 0x1106, 0x3205, 0x1043, 0x8118,
370 NULL, NULL, "ASUS A7V8-MX SE", board_asus_a7v8x_mx},
Luc Verhaegen32707542007-07-04 17:51:49 +0000371 {0x8086, 0x1076, 0x8086, 0x1176, 0x1106, 0x3059, 0x10f1, 0x2498,
372 NULL, NULL, "Tyan Tomcat K7M", board_asus_a7v8x_mx},
Luc Verhaegen6b141752007-05-20 16:16:13 +0000373 {0x10B9, 0x1541, 0x0000, 0x0000, 0x10B9, 0x1533, 0x0000, 0x0000,
374 "asus", "p5a", "ASUS P5A", board_asus_p5a},
Stefan Reinauer1c283f42007-06-05 12:51:52 +0000375 {0x1166, 0x0205, 0x1014, 0x0347, 0x0000, 0x0000, 0x0000, 0x0000,
376 "ibm", "x3455", "IBM x3455", board_ibm_x3455},
Luc Verhaegenfdd0c582007-08-11 16:59:11 +0000377 {0x8086, 0x7110, 0x0000, 0x0000, 0x8086, 0x7190, 0x0000, 0x0000,
378 "epox", "ep-bx3", "EPoX EP-BX3", board_epox_ep_bx3},
Uwe Hermanna7e05482007-05-09 10:17:44 +0000379 {0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL} /* Keep this */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000380};
381
Uwe Hermannffec5f32007-08-23 16:08:21 +0000382/**
383 * Match boards on LinuxBIOS table gathered vendor and part name.
384 * Require main PCI IDs to match too as extra safety.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000385 */
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000386static struct board_pciid_enable *board_match_linuxbios_name(char *vendor,
387 char *part)
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000388{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000389 struct board_pciid_enable *board = board_pciid_enables;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000390
Uwe Hermanna7e05482007-05-09 10:17:44 +0000391 for (; board->name; board++) {
392 if (!board->lb_vendor || strcmp(board->lb_vendor, vendor))
393 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000394
Uwe Hermanna7e05482007-05-09 10:17:44 +0000395 if (!board->lb_part || strcmp(board->lb_part, part))
396 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000397
Uwe Hermanna7e05482007-05-09 10:17:44 +0000398 if (!pci_dev_find(board->first_vendor, board->first_device))
399 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000400
Uwe Hermanna7e05482007-05-09 10:17:44 +0000401 if (board->second_vendor &&
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000402 !pci_dev_find(board->second_vendor, board->second_device))
Uwe Hermanna7e05482007-05-09 10:17:44 +0000403 continue;
404 return board;
405 }
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000406 printf("NOT FOUND %s:%s\n", vendor, part);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000407 return NULL;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000408}
409
Uwe Hermannffec5f32007-08-23 16:08:21 +0000410/**
411 * Match boards on PCI IDs and subsystem IDs.
412 * Second set of IDs can be main only or missing completely.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000413 */
414static struct board_pciid_enable *board_match_pci_card_ids(void)
415{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000416 struct board_pciid_enable *board = board_pciid_enables;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000417
Uwe Hermanna7e05482007-05-09 10:17:44 +0000418 for (; board->name; board++) {
419 if (!board->first_card_vendor || !board->first_card_device)
420 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000421
Uwe Hermanna7e05482007-05-09 10:17:44 +0000422 if (!pci_card_find(board->first_vendor, board->first_device,
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000423 board->first_card_vendor,
424 board->first_card_device))
Uwe Hermanna7e05482007-05-09 10:17:44 +0000425 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000426
Uwe Hermanna7e05482007-05-09 10:17:44 +0000427 if (board->second_vendor) {
428 if (board->second_card_vendor) {
429 if (!pci_card_find(board->second_vendor,
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000430 board->second_device,
431 board->second_card_vendor,
432 board->second_card_device))
Uwe Hermanna7e05482007-05-09 10:17:44 +0000433 continue;
434 } else {
435 if (!pci_dev_find(board->second_vendor,
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000436 board->second_device))
Uwe Hermanna7e05482007-05-09 10:17:44 +0000437 continue;
438 }
439 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000440
Uwe Hermanna7e05482007-05-09 10:17:44 +0000441 return board;
442 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000443
Uwe Hermanna7e05482007-05-09 10:17:44 +0000444 return NULL;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000445}
446
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000447int board_flash_enable(char *vendor, char *part)
448{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000449 struct board_pciid_enable *board = NULL;
450 int ret = 0;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000451
Uwe Hermanna7e05482007-05-09 10:17:44 +0000452 if (vendor && part)
453 board = board_match_linuxbios_name(vendor, part);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000454
Uwe Hermanna7e05482007-05-09 10:17:44 +0000455 if (!board)
456 board = board_match_pci_card_ids();
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000457
Uwe Hermanna7e05482007-05-09 10:17:44 +0000458 if (board) {
Uwe Hermanna502dce2007-10-17 23:55:15 +0000459 printf("Found board \"%s\": enabling flash write... ",
Ronald G. Minnichfa496922007-10-12 21:22:40 +0000460 board->name);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000461
Uwe Hermanna7e05482007-05-09 10:17:44 +0000462 ret = board->enable(board->name);
463 if (ret)
Uwe Hermanna502dce2007-10-17 23:55:15 +0000464 printf("FAILED!\n");
Uwe Hermanna7e05482007-05-09 10:17:44 +0000465 else
466 printf("OK.\n");
467 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000468
Uwe Hermanna7e05482007-05-09 10:17:44 +0000469 return ret;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000470}