blob: 0e72c2c01a26c82dc4512499cf1d371ffd809f3a [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 Hailfingere1514992007-10-02 15:49:25 +000033#define ITE_SUPERIO_PORT1 0x2e
34#define ITE_SUPERIO_PORT2 0x4e
35
36#define JEDEC_RDID {0x9f}
37#define JEDEC_RDID_OUTSIZE 0x01
38#define JEDEC_RDID_INSIZE 0x03
39
40static uint16_t it8716f_flashport = 0;
41
Carl-Daniel Hailfinger92242622007-09-27 14:29:57 +000042/* Generic Super I/O helper functions */
43uint8_t regval(uint16_t port, uint8_t reg)
44{
45 outb(reg, port);
46 return inb(port + 1);
47}
48
49void regwrite(uint16_t port, uint8_t reg, uint8_t val)
50{
51 outb(reg, port);
52 outb(val, port + 1);
53}
54
55/* Helper functions for most recent ITE IT87xx Super I/O chips */
56#define CHIP_ID_BYTE1_REG 0x20
57#define CHIP_ID_BYTE2_REG 0x21
58static void enter_conf_mode_ite(uint16_t port)
59{
60 outb(0x87, port);
61 outb(0x01, port);
62 outb(0x55, port);
Carl-Daniel Hailfingere1514992007-10-02 15:49:25 +000063 if (port == ITE_SUPERIO_PORT1)
Carl-Daniel Hailfinger92242622007-09-27 14:29:57 +000064 outb(0x55, port);
65 else
66 outb(0xaa, port);
67}
68
69static void exit_conf_mode_ite(uint16_t port)
70{
71 regwrite(port, 0x02, 0x02);
72}
73
74static uint16_t find_ite_serial_flash_port(uint16_t port)
75{
76 uint8_t tmp = 0;
77 uint16_t id, flashport = 0;
78
79 enter_conf_mode_ite(port);
80
81 id = regval(port, CHIP_ID_BYTE1_REG) << 8;
82 id |= regval(port, CHIP_ID_BYTE2_REG);
83
84 /* TODO: Handle more IT87xx if they support flash translation */
85 if (id == 0x8716) {
86 /* NOLDN, reg 0x24, mask out lowest bit (suspend) */
87 tmp = regval(port, 0x24) & 0xFE;
88 printf("Serial flash segment 0x%08x-0x%08x %sabled\n",
89 0xFFFE0000, 0xFFFFFFFF, (tmp & 1 << 1) ? "en" : "dis");
90 printf("Serial flash segment 0x%08x-0x%08x %sabled\n",
91 0x000E0000, 0x000FFFFF, (tmp & 1 << 1) ? "en" : "dis");
92 printf("Serial flash segment 0x%08x-0x%08x %sabled\n",
93 0xFFEE0000, 0xFFEFFFFF, (tmp & 1 << 2) ? "en" : "dis");
94 printf("Serial flash segment 0x%08x-0x%08x %sabled\n",
95 0xFFF80000, 0xFFFEFFFF, (tmp & 1 << 3) ? "en" : "dis");
96 printf("LPC write to serial flash %sabled\n",
97 (tmp & 1 << 4) ? "en" : "dis");
98 printf("serial flash pin %i\n", (tmp & 1 << 5) ? 87 : 29);
99 /* LDN 0x7, reg 0x64/0x65 */
100 regwrite(port, 0x07, 0x7);
101 flashport = regval(port, 0x64) << 8;
102 flashport |= regval(port, 0x65);
103 }
104 exit_conf_mode_ite(port);
105 return flashport;
106}
107
Carl-Daniel Hailfingere1514992007-10-02 15:49:25 +0000108/* The IT8716F only supports commands with length 1,2,4,5 bytes including
109 command byte and can not read more than 3 bytes from the device.
110 This function expects writearr[0] to be the first byte sent to the device,
111 whereas the IT8716F splits commands internally into address and non-address
112 commands with the address in inverse wire order. That's why the register
113 ordering in case 4 and 5 may seem strange. */
114static int it8716f_spi_command(uint16_t port, unsigned char writecnt, unsigned char readcnt, const unsigned char *writearr, unsigned char *readarr)
Carl-Daniel Hailfinger92242622007-09-27 14:29:57 +0000115{
Carl-Daniel Hailfingere1514992007-10-02 15:49:25 +0000116 uint8_t busy, writeenc;
Carl-Daniel Hailfinger92242622007-09-27 14:29:57 +0000117 do {
118 busy = inb(port) & 0x80;
119 } while (busy);
Carl-Daniel Hailfingere1514992007-10-02 15:49:25 +0000120 if (readcnt > 3) {
121 printf("%s called with unsupported readcnt %i\n",
122 __FUNCTION__, readcnt);
123 return 1;
124 }
125 switch (writecnt) {
126 case 1:
127 outb(writearr[0], port + 1);
128 writeenc = 0x0;
129 break;
130 case 2:
131 outb(writearr[0], port + 1);
132 outb(writearr[1], port + 7);
133 writeenc = 0x1;
134 break;
135 case 4:
136 outb(writearr[0], port + 1);
137 outb(writearr[1], port + 4);
138 outb(writearr[2], port + 3);
139 outb(writearr[3], port + 2);
140 writeenc = 0x2;
141 break;
142 case 5:
143 outb(writearr[0], port + 1);
144 outb(writearr[1], port + 4);
145 outb(writearr[2], port + 3);
146 outb(writearr[3], port + 2);
147 outb(writearr[4], port + 7);
148 writeenc = 0x3;
149 break;
150 default:
151 printf("%s called with unsupported writecnt %i\n",
152 __FUNCTION__, writecnt);
153 return 1;
154 }
155 /* Start IO, 33MHz, readcnt input bytes, writecnt output bytes. Note:
156 We can't use writecnt directly, but have to use a strange encoding */
157 outb((0x5 << 4) | ((readcnt & 0x3) << 2) | (writeenc), port);
Carl-Daniel Hailfinger92242622007-09-27 14:29:57 +0000158 do {
159 busy = inb(port) & 0x80;
160 } while (busy);
Carl-Daniel Hailfingere1514992007-10-02 15:49:25 +0000161 readarr[0] = inb(port + 5);
162 readarr[1] = inb(port + 6);
163 readarr[2] = inb(port + 7);
164 return 0;
165}
166
167static int it8716f_serial_rdid(uint16_t port, unsigned char *readarr)
168{
169 const unsigned char cmd[] = JEDEC_RDID;
170
171 if (it8716f_spi_command(port, JEDEC_RDID_OUTSIZE, JEDEC_RDID_INSIZE, cmd, readarr))
172 return 1;
173 printf("RDID returned %02x %02x %02x\n", readarr[0], readarr[1], readarr[2]);
174 return 0;
Carl-Daniel Hailfinger92242622007-09-27 14:29:57 +0000175}
176
177static int it87xx_probe_serial_flash(const char *name)
178{
Carl-Daniel Hailfingere1514992007-10-02 15:49:25 +0000179 it8716f_flashport = find_ite_serial_flash_port(ITE_SUPERIO_PORT1);
180 if (!it8716f_flashport)
181 it8716f_flashport = find_ite_serial_flash_port(ITE_SUPERIO_PORT2);
182 return (!it8716f_flashport);
183}
184
185int probe_spi(struct flashchip *flash)
186{
187 unsigned char readarr[3];
188 uint8_t manuf_id;
189 uint16_t model_id;
190 if (it8716f_flashport) {
191 it8716f_serial_rdid(it8716f_flashport, readarr);
192 manuf_id = readarr[0];
193 model_id = (readarr[1] << 8) | readarr[2];
194 printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, manuf_id, model_id);
195 if (manuf_id == flash->manufacture_id && model_id == flash->model_id)
196 return 1;
197 }
198
Carl-Daniel Hailfinger92242622007-09-27 14:29:57 +0000199 return 0;
200}
201
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000202/*
Uwe Hermannffec5f32007-08-23 16:08:21 +0000203 * Helper functions for many Winbond Super I/Os of the W836xx range.
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000204 */
205#define W836_INDEX 0x2E
206#define W836_DATA 0x2F
207
208/* Enter extended functions */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000209static void w836xx_ext_enter(void)
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000210{
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000211 outb(0x87, W836_INDEX);
212 outb(0x87, W836_INDEX);
213}
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000214
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000215/* Leave extended functions */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000216static void w836xx_ext_leave(void)
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000217{
218 outb(0xAA, W836_INDEX);
219}
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000220
Uwe Hermannffec5f32007-08-23 16:08:21 +0000221/* General functions for reading/writing Winbond Super I/Os. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000222static unsigned char wbsio_read(unsigned char index)
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000223{
224 outb(index, W836_INDEX);
225 return inb(W836_DATA);
226}
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000227
Uwe Hermanna7e05482007-05-09 10:17:44 +0000228static void wbsio_write(unsigned char index, unsigned char data)
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000229{
230 outb(index, W836_INDEX);
231 outb(data, W836_DATA);
232}
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000233
Uwe Hermannffec5f32007-08-23 16:08:21 +0000234static void wbsio_mask(unsigned char index, unsigned char data,
235 unsigned char mask)
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000236{
237 unsigned char tmp;
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000238
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000239 outb(index, W836_INDEX);
240 tmp = inb(W836_DATA) & ~mask;
241 outb(tmp | (data & mask), W836_DATA);
Mondrian Nuessleaef1c7c2007-05-03 10:09:23 +0000242}
243
Uwe Hermannffec5f32007-08-23 16:08:21 +0000244/**
245 * Winbond W83627HF: Raise GPIO24.
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000246 *
247 * Suited for:
Uwe Hermannffec5f32007-08-23 16:08:21 +0000248 * - Agami Aruma
249 * - IWILL DK8-HTX
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000250 */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000251static int w83627hf_gpio24_raise(const char *name)
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000252{
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000253 w836xx_ext_enter();
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000254
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000255 /* Is this the w83627hf? */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000256 if (wbsio_read(0x20) != 0x52) { /* SIO device ID register */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000257 fprintf(stderr, "\nERROR: %s: W83627HF: Wrong ID: 0x%02X.\n",
258 name, wbsio_read(0x20));
259 w836xx_ext_leave();
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000260 return -1;
261 }
262
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000263 /* PIN89S: WDTO/GP24 multiplex -> GPIO24 */
264 wbsio_mask(0x2B, 0x10, 0x10);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000265
Uwe Hermanna7e05482007-05-09 10:17:44 +0000266 wbsio_write(0x07, 0x08); /* Select logical device 8: GPIO port 2 */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000267
Uwe Hermanna7e05482007-05-09 10:17:44 +0000268 wbsio_mask(0x30, 0x01, 0x01); /* Activate logical device. */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000269
Uwe Hermanna7e05482007-05-09 10:17:44 +0000270 wbsio_mask(0xF0, 0x00, 0x10); /* GPIO24 -> output */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000271
Uwe Hermanna7e05482007-05-09 10:17:44 +0000272 wbsio_mask(0xF2, 0x00, 0x10); /* Clear GPIO24 inversion */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000273
Uwe Hermanna7e05482007-05-09 10:17:44 +0000274 wbsio_mask(0xF1, 0x10, 0x10); /* Raise GPIO24 */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000275
276 w836xx_ext_leave();
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000277
278 return 0;
279}
280
Uwe Hermannffec5f32007-08-23 16:08:21 +0000281/**
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000282 * Suited for VIAs EPIA M and MII, and maybe other CLE266 based EPIAs.
283 *
Uwe Hermannffec5f32007-08-23 16:08:21 +0000284 * We don't need to do this when using LinuxBIOS, GPIO15 is never lowered there.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000285 */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000286static int board_via_epia_m(const char *name)
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000287{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000288 struct pci_dev *dev;
289 unsigned int base;
290 uint8_t val;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000291
Uwe Hermanna7e05482007-05-09 10:17:44 +0000292 dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */
293 if (!dev) {
294 fprintf(stderr, "\nERROR: VT8235 ISA Bridge not found.\n");
295 return -1;
296 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000297
Uwe Hermanna7e05482007-05-09 10:17:44 +0000298 /* GPIO12-15 -> output */
299 val = pci_read_byte(dev, 0xE4);
300 val |= 0x10;
301 pci_write_byte(dev, 0xE4, val);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000302
Uwe Hermanna7e05482007-05-09 10:17:44 +0000303 /* Get Power Management IO address. */
304 base = pci_read_word(dev, 0x88) & 0xFF80;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000305
Uwe Hermanna7e05482007-05-09 10:17:44 +0000306 /* enable GPIO15 which is connected to write protect. */
307 val = inb(base + 0x4D);
308 val |= 0x80;
309 outb(val, base + 0x4D);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000310
Uwe Hermanna7e05482007-05-09 10:17:44 +0000311 return 0;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000312}
313
Uwe Hermannffec5f32007-08-23 16:08:21 +0000314/**
Luc Verhaegen32707542007-07-04 17:51:49 +0000315 * Suited for:
Uwe Hermannffec5f32007-08-23 16:08:21 +0000316 * - ASUS A7V8X-MX SE and A7V400-MX: AMD K7 + VIA KM400A + VT8235
317 * - Tyan Tomcat K7M: AMD Geode NX + VIA KM400 + VT8237.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000318 */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000319static int board_asus_a7v8x_mx(const char *name)
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000320{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000321 struct pci_dev *dev;
322 uint8_t val;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000323
Uwe Hermanna7e05482007-05-09 10:17:44 +0000324 dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */
Luc Verhaegen32707542007-07-04 17:51:49 +0000325 if (!dev)
326 dev = pci_dev_find(0x1106, 0x3227); /* VT8237 ISA bridge */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000327 if (!dev) {
Luc Verhaegen32707542007-07-04 17:51:49 +0000328 fprintf(stderr, "\nERROR: VT823x ISA bridge not found.\n");
Uwe Hermanna7e05482007-05-09 10:17:44 +0000329 return -1;
330 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000331
Uwe Hermanna7e05482007-05-09 10:17:44 +0000332 /* This bit is marked reserved actually */
333 val = pci_read_byte(dev, 0x59);
334 val &= 0x7F;
335 pci_write_byte(dev, 0x59, val);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000336
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000337 /* Raise ROM MEMW# line on Winbond w83697 SuperIO */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000338 w836xx_ext_enter();
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000339
Uwe Hermanna7e05482007-05-09 10:17:44 +0000340 if (!(wbsio_read(0x24) & 0x02)) /* flash rom enabled? */
341 wbsio_mask(0x24, 0x08, 0x08); /* enable MEMW# */
Luc Verhaegen7977f4e2007-05-04 04:47:04 +0000342
343 w836xx_ext_leave();
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000344
Uwe Hermanna7e05482007-05-09 10:17:44 +0000345 return 0;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000346}
347
Uwe Hermannffec5f32007-08-23 16:08:21 +0000348/**
Luc Verhaegen6b141752007-05-20 16:16:13 +0000349 * Suited for ASUS P5A.
350 *
351 * This is rather nasty code, but there's no way to do this cleanly.
352 * We're basically talking to some unknown device on SMBus, my guess
353 * is that it is the Winbond W83781D that lives near the DIP BIOS.
354 */
Luc Verhaegen6b141752007-05-20 16:16:13 +0000355static int board_asus_p5a(const char *name)
356{
357 uint8_t tmp;
358 int i;
359
360#define ASUSP5A_LOOP 5000
361
362 outb(0x00, 0xE807);
363 outb(0xEF, 0xE803);
364
365 outb(0xFF, 0xE800);
366
367 for (i = 0; i < ASUSP5A_LOOP; i++) {
368 outb(0xE1, 0xFF);
369 if (inb(0xE800) & 0x04)
370 break;
371 }
372
373 if (i == ASUSP5A_LOOP) {
374 printf("%s: Unable to contact device.\n", name);
375 return -1;
376 }
377
378 outb(0x20, 0xE801);
379 outb(0x20, 0xE1);
380
381 outb(0xFF, 0xE802);
382
383 for (i = 0; i < ASUSP5A_LOOP; i++) {
384 tmp = inb(0xE800);
385 if (tmp & 0x70)
386 break;
387 }
388
389 if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) {
390 printf("%s: failed to read device.\n", name);
391 return -1;
392 }
393
394 tmp = inb(0xE804);
395 tmp &= ~0x02;
396
397 outb(0x00, 0xE807);
398 outb(0xEE, 0xE803);
399
400 outb(tmp, 0xE804);
401
402 outb(0xFF, 0xE800);
403 outb(0xE1, 0xFF);
404
405 outb(0x20, 0xE801);
406 outb(0x20, 0xE1);
407
408 outb(0xFF, 0xE802);
409
410 for (i = 0; i < ASUSP5A_LOOP; i++) {
411 tmp = inb(0xE800);
412 if (tmp & 0x70)
413 break;
414 }
415
416 if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) {
417 printf("%s: failed to write to device.\n", name);
418 return -1;
419 }
420
421 return 0;
422}
423
Stefan Reinauer1c283f42007-06-05 12:51:52 +0000424static int board_ibm_x3455(const char *name)
425{
426 uint8_t byte;
427
Uwe Hermanne823ee02007-06-05 15:02:18 +0000428 /* Set GPIO lines in the Broadcom HT-1000 southbridge. */
Stefan Reinauer1c283f42007-06-05 12:51:52 +0000429 outb(0x45, 0xcd6);
430 byte = inb(0xcd7);
Uwe Hermanne823ee02007-06-05 15:02:18 +0000431 outb(byte | 0x20, 0xcd7);
Stefan Reinauer1c283f42007-06-05 12:51:52 +0000432
433 return 0;
434}
435
Luc Verhaegenfdd0c582007-08-11 16:59:11 +0000436/**
437 * Suited for EPoX EP-BX3, and maybe some other Intel 440BX based boards.
438 */
439static int board_epox_ep_bx3(const char *name)
440{
441 uint8_t tmp;
442
443 /* Raise GPIO22. */
444 tmp = inb(0x4036);
445 outb(tmp, 0xEB);
446
447 tmp |= 0x40;
448
449 outb(tmp, 0x4036);
450 outb(tmp, 0xEB);
451
452 return 0;
453}
454
Uwe Hermannffec5f32007-08-23 16:08:21 +0000455/**
456 * We use 2 sets of IDs here, you're free to choose which is which. This
457 * is to provide a very high degree of certainty when matching a board on
458 * the basis of subsystem/card IDs. As not every vendor handles
459 * subsystem/card IDs in a sane manner.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000460 *
Uwe Hermannffec5f32007-08-23 16:08:21 +0000461 * Keep the second set NULLed if it should be ignored.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000462 */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000463struct board_pciid_enable {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000464 /* Any device, but make it sensible, like the isa bridge. */
465 uint16_t first_vendor;
466 uint16_t first_device;
467 uint16_t first_card_vendor;
468 uint16_t first_card_device;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000469
Uwe Hermanna7e05482007-05-09 10:17:44 +0000470 /* Any device, but make it sensible, like
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000471 * the host bridge. May be NULL
472 */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000473 uint16_t second_vendor;
474 uint16_t second_device;
475 uint16_t second_card_vendor;
476 uint16_t second_card_device;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000477
Uwe Hermanna7e05482007-05-09 10:17:44 +0000478 /* From linuxbios table */
479 char *lb_vendor;
480 char *lb_part;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000481
Uwe Hermanna7e05482007-05-09 10:17:44 +0000482 char *name;
483 int (*enable) (const char *name);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000484};
485
486struct board_pciid_enable board_pciid_enables[] = {
Carl-Daniel Hailfinger92242622007-09-27 14:29:57 +0000487 {0x10de, 0x0360, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
488 "gigabyte", "m57sli", "GIGABYTE GA-M57SLI", it87xx_probe_serial_flash},
Uwe Hermanna7e05482007-05-09 10:17:44 +0000489 {0x1022, 0x7468, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
490 "iwill", "dk8_htx", "IWILL DK8-HTX", w83627hf_gpio24_raise},
491 {0x1022, 0x746B, 0x1022, 0x36C0, 0x0000, 0x0000, 0x0000, 0x0000,
492 "AGAMI", "ARUMA", "agami Aruma", w83627hf_gpio24_raise},
493 {0x1106, 0x3177, 0x1106, 0xAA01, 0x1106, 0x3123, 0x1106, 0xAA01,
494 NULL, NULL, "VIA EPIA M/MII/...", board_via_epia_m},
495 {0x1106, 0x3177, 0x1043, 0x80A1, 0x1106, 0x3205, 0x1043, 0x8118,
496 NULL, NULL, "ASUS A7V8-MX SE", board_asus_a7v8x_mx},
Luc Verhaegen32707542007-07-04 17:51:49 +0000497 {0x8086, 0x1076, 0x8086, 0x1176, 0x1106, 0x3059, 0x10f1, 0x2498,
498 NULL, NULL, "Tyan Tomcat K7M", board_asus_a7v8x_mx},
Luc Verhaegen6b141752007-05-20 16:16:13 +0000499 {0x10B9, 0x1541, 0x0000, 0x0000, 0x10B9, 0x1533, 0x0000, 0x0000,
500 "asus", "p5a", "ASUS P5A", board_asus_p5a},
Stefan Reinauer1c283f42007-06-05 12:51:52 +0000501 {0x1166, 0x0205, 0x1014, 0x0347, 0x0000, 0x0000, 0x0000, 0x0000,
502 "ibm", "x3455", "IBM x3455", board_ibm_x3455},
Luc Verhaegenfdd0c582007-08-11 16:59:11 +0000503 {0x8086, 0x7110, 0x0000, 0x0000, 0x8086, 0x7190, 0x0000, 0x0000,
504 "epox", "ep-bx3", "EPoX EP-BX3", board_epox_ep_bx3},
Uwe Hermanna7e05482007-05-09 10:17:44 +0000505 {0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL} /* Keep this */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000506};
507
Uwe Hermannffec5f32007-08-23 16:08:21 +0000508/**
509 * Match boards on LinuxBIOS table gathered vendor and part name.
510 * Require main PCI IDs to match too as extra safety.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000511 */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000512static struct board_pciid_enable *board_match_linuxbios_name(char *vendor,
513 char *part)
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000514{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000515 struct board_pciid_enable *board = board_pciid_enables;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000516
Uwe Hermanna7e05482007-05-09 10:17:44 +0000517 for (; board->name; board++) {
518 if (!board->lb_vendor || strcmp(board->lb_vendor, vendor))
519 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000520
Uwe Hermanna7e05482007-05-09 10:17:44 +0000521 if (!board->lb_part || strcmp(board->lb_part, part))
522 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000523
Uwe Hermanna7e05482007-05-09 10:17:44 +0000524 if (!pci_dev_find(board->first_vendor, board->first_device))
525 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000526
Uwe Hermanna7e05482007-05-09 10:17:44 +0000527 if (board->second_vendor &&
528 !pci_dev_find(board->second_vendor, board->second_device))
529 continue;
530 return board;
531 }
532 return NULL;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000533}
534
Uwe Hermannffec5f32007-08-23 16:08:21 +0000535/**
536 * Match boards on PCI IDs and subsystem IDs.
537 * Second set of IDs can be main only or missing completely.
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000538 */
539static struct board_pciid_enable *board_match_pci_card_ids(void)
540{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000541 struct board_pciid_enable *board = board_pciid_enables;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000542
Uwe Hermanna7e05482007-05-09 10:17:44 +0000543 for (; board->name; board++) {
544 if (!board->first_card_vendor || !board->first_card_device)
545 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000546
Uwe Hermanna7e05482007-05-09 10:17:44 +0000547 if (!pci_card_find(board->first_vendor, board->first_device,
548 board->first_card_vendor,
549 board->first_card_device))
550 continue;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000551
Uwe Hermanna7e05482007-05-09 10:17:44 +0000552 if (board->second_vendor) {
553 if (board->second_card_vendor) {
554 if (!pci_card_find(board->second_vendor,
555 board->second_device,
556 board->second_card_vendor,
557 board->second_card_device))
558 continue;
559 } else {
560 if (!pci_dev_find(board->second_vendor,
561 board->second_device))
562 continue;
563 }
564 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000565
Uwe Hermanna7e05482007-05-09 10:17:44 +0000566 return board;
567 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000568
Uwe Hermanna7e05482007-05-09 10:17:44 +0000569 return NULL;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000570}
571
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000572int board_flash_enable(char *vendor, char *part)
573{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000574 struct board_pciid_enable *board = NULL;
575 int ret = 0;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000576
Uwe Hermanna7e05482007-05-09 10:17:44 +0000577 if (vendor && part)
578 board = board_match_linuxbios_name(vendor, part);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000579
Uwe Hermanna7e05482007-05-09 10:17:44 +0000580 if (!board)
581 board = board_match_pci_card_ids();
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000582
Uwe Hermanna7e05482007-05-09 10:17:44 +0000583 if (board) {
584 printf("Found board \"%s\": Enabling flash write... ",
585 board->name);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000586
Uwe Hermanna7e05482007-05-09 10:17:44 +0000587 ret = board->enable(board->name);
588 if (ret)
589 printf("Failed!\n");
590 else
591 printf("OK.\n");
592 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000593
Uwe Hermanna7e05482007-05-09 10:17:44 +0000594 return ret;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000595}