blob: 1387874b9f7854ce2a962e48e2a8138f3f8716fe [file] [log] [blame]
Ollie Lho184a4042005-11-26 21:55:36 +00001/*
Uwe Hermannd1107642007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
Ollie Lho184a4042005-11-26 21:55:36 +00003 *
Uwe Hermannd1107642007-08-29 17:52:32 +00004 * Copyright (C) 2000 Silicon Integrated System Corporation
Stefan Reinauer8fa64812009-08-12 09:27:45 +00005 * Copyright (C) 2005-2009 coresystems GmbH
Uwe Hermannd1107642007-08-29 17:52:32 +00006 * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de>
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +00007 * Copyright (C) 2007,2008,2009 Carl-Daniel Hailfinger
Adam Jurkowskie4984102009-12-21 15:30:46 +00008 * Copyright (C) 2009 Kontron Modular Computers GmbH
Ollie Lho184a4042005-11-26 21:55:36 +00009 *
Uwe Hermannd1107642007-08-29 17:52:32 +000010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License.
Ollie Lho184a4042005-11-26 21:55:36 +000013 *
Uwe Hermannd1107642007-08-29 17:52:32 +000014 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24/*
25 * Contains the chipset specific flash enables.
Ollie Lho184a4042005-11-26 21:55:36 +000026 */
27
Lane Brooksd54958a2007-11-13 16:45:22 +000028#define _LARGEFILE64_SOURCE
29
Ollie Lhocbbf1252004-03-17 22:22:08 +000030#include <stdlib.h>
Uwe Hermanne8ba5382009-05-22 11:37:27 +000031#include <string.h>
Lane Brooksd54958a2007-11-13 16:45:22 +000032#include <sys/types.h>
Carl-Daniel Hailfingerdcef67e2010-06-21 23:20:15 +000033#include <unistd.h>
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000034#include "flash.h"
Stefan Reinauer86de2832006-03-31 11:26:55 +000035
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +000036#if defined(__i386__) || defined(__x86_64__)
37
Michael Karcher89bed6d2010-06-13 10:16:12 +000038#define NOT_DONE_YET 1
39
Uwe Hermann372eeb52007-12-04 21:49:06 +000040static int enable_flash_ali_m1533(struct pci_dev *dev, const char *name)
Luc Verhaegen6b141752007-05-20 16:16:13 +000041{
42 uint8_t tmp;
43
Uwe Hermann372eeb52007-12-04 21:49:06 +000044 /*
45 * ROM Write enable, 0xFFFC0000-0xFFFDFFFF and
46 * 0xFFFE0000-0xFFFFFFFF ROM select enable.
47 */
Luc Verhaegen6b141752007-05-20 16:16:13 +000048 tmp = pci_read_byte(dev, 0x47);
49 tmp |= 0x46;
50 pci_write_byte(dev, 0x47, tmp);
51
52 return 0;
53}
54
Carl-Daniel Hailfinger9f46cfc2009-11-15 17:13:29 +000055static int enable_flash_sis85c496(struct pci_dev *dev, const char *name)
56{
57 uint8_t tmp;
58
59 tmp = pci_read_byte(dev, 0xd0);
60 tmp |= 0xf8;
61 pci_write_byte(dev, 0xd0, tmp);
62
63 return 0;
64}
65
66static int enable_flash_sis_mapping(struct pci_dev *dev, const char *name)
67{
68 uint8_t new, newer;
69
70 /* Extended BIOS enable = 1, Lower BIOS Enable = 1 */
71 /* This is 0xFFF8000~0xFFFF0000 decoding on SiS 540/630. */
72 new = pci_read_byte(dev, 0x40);
73 new &= (~0x04); /* No idea why we clear bit 2. */
74 new |= 0xb; /* 0x3 for some chipsets, bit 7 seems to be don't care. */
75 pci_write_byte(dev, 0x40, new);
76 newer = pci_read_byte(dev, 0x40);
77 if (newer != new) {
Sean Nelson316a29f2010-05-07 20:09:04 +000078 msg_pinfo("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name);
79 msg_pinfo("Stuck at 0x%x\n", newer);
Carl-Daniel Hailfinger9f46cfc2009-11-15 17:13:29 +000080 return -1;
81 }
82 return 0;
83}
84
85static struct pci_dev *find_southbridge(uint16_t vendor, const char *name)
86{
87 struct pci_dev *sbdev;
88
89 sbdev = pci_dev_find_vendorclass(vendor, 0x0601);
90 if (!sbdev)
91 sbdev = pci_dev_find_vendorclass(vendor, 0x0680);
92 if (!sbdev)
93 sbdev = pci_dev_find_vendorclass(vendor, 0x0000);
94 if (!sbdev)
Sean Nelson316a29f2010-05-07 20:09:04 +000095 msg_perr("No southbridge found for %s!\n", name);
Carl-Daniel Hailfinger9f46cfc2009-11-15 17:13:29 +000096 if (sbdev)
Sean Nelson316a29f2010-05-07 20:09:04 +000097 msg_pdbg("Found southbridge %04x:%04x at %02x:%02x:%01x\n",
Carl-Daniel Hailfinger9f46cfc2009-11-15 17:13:29 +000098 sbdev->vendor_id, sbdev->device_id,
99 sbdev->bus, sbdev->dev, sbdev->func);
100 return sbdev;
101}
102
103static int enable_flash_sis501(struct pci_dev *dev, const char *name)
104{
105 uint8_t tmp;
106 int ret = 0;
107 struct pci_dev *sbdev;
108
109 sbdev = find_southbridge(dev->vendor_id, name);
110 if (!sbdev)
111 return -1;
112
113 ret = enable_flash_sis_mapping(sbdev, name);
114
115 tmp = sio_read(0x22, 0x80);
116 tmp &= (~0x20);
117 tmp |= 0x4;
118 sio_write(0x22, 0x80, tmp);
119
120 tmp = sio_read(0x22, 0x70);
121 tmp &= (~0x20);
122 tmp |= 0x4;
123 sio_write(0x22, 0x70, tmp);
124
125 return ret;
126}
127
128static int enable_flash_sis5511(struct pci_dev *dev, const char *name)
129{
130 uint8_t tmp;
131 int ret = 0;
132 struct pci_dev *sbdev;
133
134 sbdev = find_southbridge(dev->vendor_id, name);
135 if (!sbdev)
136 return -1;
137
138 ret = enable_flash_sis_mapping(sbdev, name);
139
140 tmp = sio_read(0x22, 0x50);
141 tmp &= (~0x20);
142 tmp |= 0x4;
143 sio_write(0x22, 0x50, tmp);
144
145 return ret;
146}
147
Carl-Daniel Hailfinger9f46cfc2009-11-15 17:13:29 +0000148static int enable_flash_sis530(struct pci_dev *dev, const char *name)
149{
150 uint8_t new, newer;
151 int ret = 0;
152 struct pci_dev *sbdev;
153
154 sbdev = find_southbridge(dev->vendor_id, name);
155 if (!sbdev)
156 return -1;
157
158 ret = enable_flash_sis_mapping(sbdev, name);
159
160 new = pci_read_byte(sbdev, 0x45);
161 new &= (~0x20);
162 new |= 0x4;
163 pci_write_byte(sbdev, 0x45, new);
Luc Verhaegen9cce2f52010-01-10 15:01:08 +0000164 newer = pci_read_byte(sbdev, 0x45);
Carl-Daniel Hailfinger9f46cfc2009-11-15 17:13:29 +0000165 if (newer != new) {
Sean Nelson316a29f2010-05-07 20:09:04 +0000166 msg_pinfo("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name);
167 msg_pinfo("Stuck at 0x%x\n", newer);
Carl-Daniel Hailfinger9f46cfc2009-11-15 17:13:29 +0000168 ret = -1;
169 }
170
171 return ret;
172}
173
174static int enable_flash_sis540(struct pci_dev *dev, const char *name)
175{
176 uint8_t new, newer;
177 int ret = 0;
178 struct pci_dev *sbdev;
179
180 sbdev = find_southbridge(dev->vendor_id, name);
181 if (!sbdev)
182 return -1;
183
184 ret = enable_flash_sis_mapping(sbdev, name);
185
186 new = pci_read_byte(sbdev, 0x45);
187 new &= (~0x80);
188 new |= 0x40;
189 pci_write_byte(sbdev, 0x45, new);
Luc Verhaegen9cce2f52010-01-10 15:01:08 +0000190 newer = pci_read_byte(sbdev, 0x45);
Carl-Daniel Hailfinger9f46cfc2009-11-15 17:13:29 +0000191 if (newer != new) {
Sean Nelson316a29f2010-05-07 20:09:04 +0000192 msg_pinfo("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name);
193 msg_pinfo("Stuck at 0x%x\n", newer);
Carl-Daniel Hailfinger9f46cfc2009-11-15 17:13:29 +0000194 ret = -1;
195 }
196
197 return ret;
198}
199
Uwe Hermann987942d2006-11-07 11:16:21 +0000200/* Datasheet:
201 * - Name: 82371AB PCI-TO-ISA / IDE XCELERATOR (PIIX4)
202 * - URL: http://www.intel.com/design/intarch/datashts/290562.htm
203 * - PDF: http://www.intel.com/design/intarch/datashts/29056201.pdf
204 * - Order Number: 290562-001
205 */
Uwe Hermann372eeb52007-12-04 21:49:06 +0000206static int enable_flash_piix4(struct pci_dev *dev, const char *name)
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000207{
208 uint16_t old, new;
Uwe Hermanna7e05482007-05-09 10:17:44 +0000209 uint16_t xbcs = 0x4e; /* X-Bus Chip Select register. */
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000210
Maciej Pijankaa661e152009-12-08 17:26:24 +0000211 buses_supported = CHIP_BUSTYPE_PARALLEL;
212
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000213 old = pci_read_word(dev, xbcs);
214
215 /* Set bit 9: 1-Meg Extended BIOS Enable (PCI master accesses to
Uwe Hermanna7e05482007-05-09 10:17:44 +0000216 * FFF00000-FFF7FFFF are forwarded to ISA).
Uwe Hermannc556d322008-10-28 11:50:05 +0000217 * Note: This bit is reserved on PIIX/PIIX3/MPIIX.
Uwe Hermanna7e05482007-05-09 10:17:44 +0000218 * Set bit 7: Extended BIOS Enable (PCI master accesses to
219 * FFF80000-FFFDFFFF are forwarded to ISA).
220 * Set bit 6: Lower BIOS Enable (PCI master, or ISA master accesses to
221 * the lower 64-Kbyte BIOS block (E0000-EFFFF) at the top
222 * of 1 Mbyte, or the aliases at the top of 4 Gbyte
223 * (FFFE0000-FFFEFFFF) result in the generation of BIOSCS#.
224 * Note: Accesses to FFFF0000-FFFFFFFF are always forwarded to ISA.
225 * Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable).
226 */
Uwe Hermannc556d322008-10-28 11:50:05 +0000227 if (dev->device_id == 0x122e || dev->device_id == 0x7000
228 || dev->device_id == 0x1234)
229 new = old | 0x00c4; /* PIIX/PIIX3/MPIIX: Bit 9 is reserved. */
Uwe Hermann87203452008-10-26 18:40:42 +0000230 else
231 new = old | 0x02c4;
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000232
233 if (new == old)
234 return 0;
235
236 pci_write_word(dev, xbcs, new);
237
238 if (pci_read_word(dev, xbcs) != new) {
Sean Nelson316a29f2010-05-07 20:09:04 +0000239 msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name);
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000240 return -1;
241 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000242
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000243 return 0;
244}
245
Uwe Hermann372eeb52007-12-04 21:49:06 +0000246/*
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000247 * See ie. page 375 of "Intel I/O Controller Hub 7 (ICH7) Family Datasheet"
248 * http://download.intel.com/design/chipsets/datashts/30701303.pdf
Uwe Hermann372eeb52007-12-04 21:49:06 +0000249 */
250static int enable_flash_ich(struct pci_dev *dev, const char *name,
251 int bios_cntl)
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000252{
Ollie Lho184a4042005-11-26 21:55:36 +0000253 uint8_t old, new;
Stefan Reinauereb366472006-09-06 15:48:48 +0000254
Uwe Hermann372eeb52007-12-04 21:49:06 +0000255 /*
256 * Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, but
Uwe Hermanna7e05482007-05-09 10:17:44 +0000257 * just treating it as 8 bit wide seems to work fine in practice.
Stefan Reinauereb366472006-09-06 15:48:48 +0000258 */
Stefan Reinauer86de2832006-03-31 11:26:55 +0000259 old = pci_read_byte(dev, bios_cntl);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000260
Sean Nelson316a29f2010-05-07 20:09:04 +0000261 msg_pdbg("\nBIOS Lock Enable: %sabled, ",
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000262 (old & (1 << 1)) ? "en" : "dis");
Sean Nelson316a29f2010-05-07 20:09:04 +0000263 msg_pdbg("BIOS Write Enable: %sabled, ",
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000264 (old & (1 << 0)) ? "en" : "dis");
Sean Nelson316a29f2010-05-07 20:09:04 +0000265 msg_pdbg("BIOS_CNTL is 0x%x\n", old);
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000266
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000267 new = old | 1;
268
269 if (new == old)
270 return 0;
271
Stefan Reinauer86de2832006-03-31 11:26:55 +0000272 pci_write_byte(dev, bios_cntl, new);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000273
Stefan Reinauer86de2832006-03-31 11:26:55 +0000274 if (pci_read_byte(dev, bios_cntl) != new) {
Sean Nelson316a29f2010-05-07 20:09:04 +0000275 msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", bios_cntl, new, name);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000276 return -1;
277 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000278
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000279 return 0;
280}
281
Uwe Hermann372eeb52007-12-04 21:49:06 +0000282static int enable_flash_ich_4e(struct pci_dev *dev, const char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000283{
Carl-Daniel Hailfinger4c7ea382009-08-10 23:30:45 +0000284 /*
285 * Note: ICH5 has registers similar to FWH_SEL1, FWH_SEL2 and
286 * FWH_DEC_EN1, but they are called FB_SEL1, FB_SEL2, FB_DEC_EN1 and
287 * FB_DEC_EN2.
288 */
Carl-Daniel Hailfinger7f9922d2010-06-20 11:04:26 +0000289 buses_supported = CHIP_BUSTYPE_FWH;
Stefan Reinauereb366472006-09-06 15:48:48 +0000290 return enable_flash_ich(dev, name, 0x4e);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000291}
292
Uwe Hermann372eeb52007-12-04 21:49:06 +0000293static int enable_flash_ich_dc(struct pci_dev *dev, const char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000294{
Carl-Daniel Hailfinger4c7ea382009-08-10 23:30:45 +0000295 uint32_t fwh_conf;
296 int i;
Carl-Daniel Hailfinger44498682009-08-13 23:23:37 +0000297 char *idsel = NULL;
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000298 int tmp;
299 int max_decode_fwh_idsel = 0;
300 int max_decode_fwh_decode = 0;
301 int contiguous = 1;
Carl-Daniel Hailfinger4c7ea382009-08-10 23:30:45 +0000302
Carl-Daniel Hailfinger44498682009-08-13 23:23:37 +0000303 if (programmer_param)
304 idsel = strstr(programmer_param, "fwh_idsel=");
305
306 if (idsel) {
307 idsel += strlen("fwh_idsel=");
308 fwh_conf = (uint32_t)strtoul(idsel, NULL, 0);
309
310 /* FIXME: Need to undo this on shutdown. */
Sean Nelson316a29f2010-05-07 20:09:04 +0000311 msg_pinfo("\nSetting IDSEL=0x%x for top 16 MB", fwh_conf);
Carl-Daniel Hailfinger44498682009-08-13 23:23:37 +0000312 pci_write_long(dev, 0xd0, fwh_conf);
313 pci_write_word(dev, 0xd4, fwh_conf);
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000314 /* FIXME: Decode settings are not changed. */
Carl-Daniel Hailfinger44498682009-08-13 23:23:37 +0000315 }
316
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000317 /* Ignore all legacy ranges below 1 MB.
318 * We currently only support flashing the chip which responds to
319 * IDSEL=0. To support IDSEL!=0, flashbase and decode size calculations
320 * have to be adjusted.
321 */
322 /* FWH_SEL1 */
323 fwh_conf = pci_read_long(dev, 0xd0);
324 for (i = 7; i >= 0; i--) {
325 tmp = (fwh_conf >> (i * 4)) & 0xf;
Sean Nelson316a29f2010-05-07 20:09:04 +0000326 msg_pdbg("\n0x%08x/0x%08x FWH IDSEL: 0x%x",
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000327 (0x1ff8 + i) * 0x80000,
328 (0x1ff0 + i) * 0x80000,
329 tmp);
330 if ((tmp == 0) && contiguous) {
331 max_decode_fwh_idsel = (8 - i) * 0x80000;
332 } else {
333 contiguous = 0;
334 }
335 }
336 /* FWH_SEL2 */
337 fwh_conf = pci_read_word(dev, 0xd4);
338 for (i = 3; i >= 0; i--) {
339 tmp = (fwh_conf >> (i * 4)) & 0xf;
Sean Nelson316a29f2010-05-07 20:09:04 +0000340 msg_pdbg("\n0x%08x/0x%08x FWH IDSEL: 0x%x",
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000341 (0xff4 + i) * 0x100000,
342 (0xff0 + i) * 0x100000,
343 tmp);
344 if ((tmp == 0) && contiguous) {
345 max_decode_fwh_idsel = (8 - i) * 0x100000;
346 } else {
347 contiguous = 0;
348 }
349 }
350 contiguous = 1;
351 /* FWH_DEC_EN1 */
352 fwh_conf = pci_read_word(dev, 0xd8);
353 for (i = 7; i >= 0; i--) {
354 tmp = (fwh_conf >> (i + 0x8)) & 0x1;
Sean Nelson316a29f2010-05-07 20:09:04 +0000355 msg_pdbg("\n0x%08x/0x%08x FWH decode %sabled",
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000356 (0x1ff8 + i) * 0x80000,
357 (0x1ff0 + i) * 0x80000,
358 tmp ? "en" : "dis");
Michael Karcher96785392010-01-03 15:09:17 +0000359 if ((tmp == 1) && contiguous) {
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000360 max_decode_fwh_decode = (8 - i) * 0x80000;
361 } else {
362 contiguous = 0;
363 }
364 }
365 for (i = 3; i >= 0; i--) {
366 tmp = (fwh_conf >> i) & 0x1;
Sean Nelson316a29f2010-05-07 20:09:04 +0000367 msg_pdbg("\n0x%08x/0x%08x FWH decode %sabled",
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000368 (0xff4 + i) * 0x100000,
369 (0xff0 + i) * 0x100000,
370 tmp ? "en" : "dis");
Michael Karcher96785392010-01-03 15:09:17 +0000371 if ((tmp == 1) && contiguous) {
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000372 max_decode_fwh_decode = (8 - i) * 0x100000;
373 } else {
374 contiguous = 0;
375 }
376 }
377 max_rom_decode.fwh = min(max_decode_fwh_idsel, max_decode_fwh_decode);
Sean Nelson316a29f2010-05-07 20:09:04 +0000378 msg_pdbg("\nMaximum FWH chip size: 0x%x bytes", max_rom_decode.fwh);
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000379
380 /* If we're called by enable_flash_ich_dc_spi, it will override
381 * buses_supported anyway.
382 */
383 buses_supported = CHIP_BUSTYPE_FWH;
Stefan Reinauereb366472006-09-06 15:48:48 +0000384 return enable_flash_ich(dev, name, 0xdc);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000385}
386
Adam Jurkowskie4984102009-12-21 15:30:46 +0000387static int enable_flash_poulsbo(struct pci_dev *dev, const char *name)
388{
389 uint16_t old, new;
390 int err;
391
392 if ((err = enable_flash_ich(dev, name, 0xd8)) != 0)
393 return err;
394
395 old = pci_read_byte(dev, 0xd9);
Sean Nelson316a29f2010-05-07 20:09:04 +0000396 msg_pdbg("BIOS Prefetch Enable: %sabled, ",
Adam Jurkowskie4984102009-12-21 15:30:46 +0000397 (old & 1) ? "en" : "dis");
398 new = old & ~1;
399
400 if (new != old)
401 pci_write_byte(dev, 0xd9, new);
402
Carl-Daniel Hailfinger7f9922d2010-06-20 11:04:26 +0000403 buses_supported = CHIP_BUSTYPE_FWH;
Adam Jurkowskie4984102009-12-21 15:30:46 +0000404 return 0;
405}
406
407
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000408#define ICH_STRAP_RSVD 0x00
409#define ICH_STRAP_SPI 0x01
410#define ICH_STRAP_PCI 0x02
411#define ICH_STRAP_LPC 0x03
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000412
Uwe Hermann394131e2008-10-18 21:14:13 +0000413static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name)
414{
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000415 uint32_t mmio_base;
416
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000417 /* Do we really need no write enable? */
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000418 mmio_base = (pci_read_long(dev, 0xbc)) << 8;
Sean Nelson316a29f2010-05-07 20:09:04 +0000419 msg_pdbg("MMIO base at = 0x%x\n", mmio_base);
Stefan Reinauer0593f212009-01-26 01:10:48 +0000420 spibar = physmap("VT8237S MMIO registers", mmio_base, 0x70);
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000421
Sean Nelson316a29f2010-05-07 20:09:04 +0000422 msg_pdbg("0x6c: 0x%04x (CLOCK/DEBUG)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000423 mmio_readw(spibar + 0x6c));
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000424
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000425 /* Not sure if it speaks all these bus protocols. */
426 buses_supported = CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000427 spi_controller = SPI_CONTROLLER_VIA;
Rudolf Marek0c2029f2009-02-01 18:40:50 +0000428 ich_init_opcodes();
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000429
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000430 return 0;
431}
432
Joshua Roysf93b36a2010-07-01 17:45:54 +0000433#define ICH_BMWAG(x) ((x >> 24) & 0xff)
434#define ICH_BMRAG(x) ((x >> 16) & 0xff)
435#define ICH_BRWA(x) ((x >> 8) & 0xff)
436#define ICH_BRRA(x) ((x >> 0) & 0xff)
437
438#define ICH_FREG_BASE(x) ((x >> 0) & 0x1fff)
439#define ICH_FREG_LIMIT(x) ((x >> 16) & 0x1fff)
440
441static void do_ich9_spi_frap(uint32_t frap, int i)
442{
443 const char *access_names[4] = {
444 "locked", "read-only", "write-only", "read-write"
445 };
446 const char *region_names[5] = {
447 "Flash Descriptor", "BIOS", "Management Engine",
448 "Gigabit Ethernet", "Platform Data"
449 };
450 int rwperms = ((ICH_BRWA(frap) & (1 << i)) << 1) |
451 ((ICH_BRRA(frap) & (1 << i)) << 0);
452 int offset = 0x54 + i * 4;
453 uint32_t freg = mmio_readl(spibar + offset), base, limit;
454
455 msg_pdbg("0x%02X: 0x%08x (FREG%i: %s)\n",
456 offset, freg, i, region_names[i]);
457
458 base = ICH_FREG_BASE(freg);
459 limit = ICH_FREG_LIMIT(freg);
460 if (base == 0x1fff && limit == 0) {
461 /* this FREG is disabled */
462 msg_pdbg("%s region is unused.\n", region_names[i]);
463 return;
464 }
465
466 msg_pdbg("0x%08x-0x%08x is %s\n",
467 (base << 12), (limit << 12) | 0x0fff,
468 access_names[rwperms]);
469}
470
Uwe Hermann394131e2008-10-18 21:14:13 +0000471static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name,
472 int ich_generation)
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000473{
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000474 int ret, i;
Stefan Reinauera9424d52008-06-27 16:28:34 +0000475 uint8_t old, new, bbs, buc;
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000476 uint16_t spibar_offset, tmp2;
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000477 uint32_t tmp, gcs;
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000478 void *rcrb;
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000479 //TODO: These names are incorrect for EP80579. For that, the solution would look like the commented line
480 //static const char *straps_names[] = {"SPI", "reserved", "reserved", "LPC" };
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000481 static const char *straps_names[] = { "reserved", "SPI", "PCI", "LPC" };
Uwe Hermann394131e2008-10-18 21:14:13 +0000482
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000483 /* Enable Flash Writes */
484 ret = enable_flash_ich_dc(dev, name);
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000485
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000486 /* Get physical address of Root Complex Register Block */
487 tmp = pci_read_long(dev, 0xf0) & 0xffffc000;
Sean Nelson316a29f2010-05-07 20:09:04 +0000488 msg_pdbg("\nRoot Complex Register Block address = 0x%x\n", tmp);
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000489
490 /* Map RCBA to virtual memory */
Stefan Reinauer0593f212009-01-26 01:10:48 +0000491 rcrb = physmap("ICH RCRB", tmp, 0x4000);
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000492
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000493 gcs = mmio_readl(rcrb + 0x3410);
Sean Nelson316a29f2010-05-07 20:09:04 +0000494 msg_pdbg("GCS = 0x%x: ", gcs);
495 msg_pdbg("BIOS Interface Lock-Down: %sabled, ",
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000496 (gcs & 0x1) ? "en" : "dis");
497 bbs = (gcs >> 10) & 0x3;
Sean Nelson316a29f2010-05-07 20:09:04 +0000498 msg_pdbg("BOOT BIOS Straps: 0x%x (%s)\n", bbs, straps_names[bbs]);
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000499
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000500 buc = mmio_readb(rcrb + 0x3414);
Sean Nelson316a29f2010-05-07 20:09:04 +0000501 msg_pdbg("Top Swap : %s\n",
Uwe Hermann394131e2008-10-18 21:14:13 +0000502 (buc & 1) ? "enabled (A16 inverted)" : "not enabled");
Stefan Reinauera9424d52008-06-27 16:28:34 +0000503
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000504 /* It seems the ICH7 does not support SPI and LPC chips at the same
505 * time. At least not with our current code. So we prevent searching
506 * on ICH7 when the southbridge is strapped to LPC
507 */
508
509 if (ich_generation == 7 && bbs == ICH_STRAP_LPC) {
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000510 buses_supported = CHIP_BUSTYPE_FWH;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000511 /* No further SPI initialization required */
512 return ret;
513 }
514
515 switch (ich_generation) {
516 case 7:
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000517 buses_supported = CHIP_BUSTYPE_SPI;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000518 spi_controller = SPI_CONTROLLER_ICH7;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000519 spibar_offset = 0x3020;
520 break;
521 case 8:
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000522 buses_supported = CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000523 spi_controller = SPI_CONTROLLER_ICH9;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000524 spibar_offset = 0x3020;
525 break;
526 case 9:
Carl-Daniel Hailfinger28ec74b2008-10-10 20:54:41 +0000527 case 10:
Uwe Hermann394131e2008-10-18 21:14:13 +0000528 default: /* Future version might behave the same */
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000529 buses_supported = CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000530 spi_controller = SPI_CONTROLLER_ICH9;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000531 spibar_offset = 0x3800;
532 break;
533 }
534
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000535 /* SPIBAR is at RCRB+0x3020 for ICH[78] and RCRB+0x3800 for ICH9. */
Sean Nelson316a29f2010-05-07 20:09:04 +0000536 msg_pdbg("SPIBAR = 0x%x + 0x%04x\n", tmp, spibar_offset);
Stefan Reinauera9424d52008-06-27 16:28:34 +0000537
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000538 /* Assign Virtual Address */
Uwe Hermann394131e2008-10-18 21:14:13 +0000539 spibar = rcrb + spibar_offset;
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000540
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000541 switch (spi_controller) {
542 case SPI_CONTROLLER_ICH7:
Sean Nelson316a29f2010-05-07 20:09:04 +0000543 msg_pdbg("0x00: 0x%04x (SPIS)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000544 mmio_readw(spibar + 0));
Sean Nelson316a29f2010-05-07 20:09:04 +0000545 msg_pdbg("0x02: 0x%04x (SPIC)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000546 mmio_readw(spibar + 2));
Sean Nelson316a29f2010-05-07 20:09:04 +0000547 msg_pdbg("0x04: 0x%08x (SPIA)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000548 mmio_readl(spibar + 4));
Uwe Hermann394131e2008-10-18 21:14:13 +0000549 for (i = 0; i < 8; i++) {
Stefan Reinauera9424d52008-06-27 16:28:34 +0000550 int offs;
551 offs = 8 + (i * 8);
Sean Nelson316a29f2010-05-07 20:09:04 +0000552 msg_pdbg("0x%02x: 0x%08x (SPID%d)\n", offs,
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000553 mmio_readl(spibar + offs), i);
Sean Nelson316a29f2010-05-07 20:09:04 +0000554 msg_pdbg("0x%02x: 0x%08x (SPID%d+4)\n", offs + 4,
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000555 mmio_readl(spibar + offs + 4), i);
Stefan Reinauera9424d52008-06-27 16:28:34 +0000556 }
Carl-Daniel Hailfinger80f3d052010-05-28 15:53:08 +0000557 ichspi_bbar = mmio_readl(spibar + 0x50);
Sean Nelson316a29f2010-05-07 20:09:04 +0000558 msg_pdbg("0x50: 0x%08x (BBAR)\n",
Carl-Daniel Hailfinger80f3d052010-05-28 15:53:08 +0000559 ichspi_bbar);
Sean Nelson316a29f2010-05-07 20:09:04 +0000560 msg_pdbg("0x54: 0x%04x (PREOP)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000561 mmio_readw(spibar + 0x54));
Sean Nelson316a29f2010-05-07 20:09:04 +0000562 msg_pdbg("0x56: 0x%04x (OPTYPE)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000563 mmio_readw(spibar + 0x56));
Sean Nelson316a29f2010-05-07 20:09:04 +0000564 msg_pdbg("0x58: 0x%08x (OPMENU)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000565 mmio_readl(spibar + 0x58));
Sean Nelson316a29f2010-05-07 20:09:04 +0000566 msg_pdbg("0x5c: 0x%08x (OPMENU+4)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000567 mmio_readl(spibar + 0x5c));
Uwe Hermann394131e2008-10-18 21:14:13 +0000568 for (i = 0; i < 4; i++) {
Stefan Reinauera9424d52008-06-27 16:28:34 +0000569 int offs;
570 offs = 0x60 + (i * 4);
Sean Nelson316a29f2010-05-07 20:09:04 +0000571 msg_pdbg("0x%02x: 0x%08x (PBR%d)\n", offs,
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000572 mmio_readl(spibar + offs), i);
Stefan Reinauera9424d52008-06-27 16:28:34 +0000573 }
Sean Nelson316a29f2010-05-07 20:09:04 +0000574 msg_pdbg("\n");
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000575 if (mmio_readw(spibar) & (1 << 15)) {
Sean Nelson316a29f2010-05-07 20:09:04 +0000576 msg_pinfo("WARNING: SPI Configuration Lockdown activated.\n");
FENG yu ningc05a2952008-12-08 18:16:58 +0000577 ichspi_lock = 1;
Stefan Reinauera9424d52008-06-27 16:28:34 +0000578 }
FENG yu ningf041e9b2008-12-15 02:32:11 +0000579 ich_init_opcodes();
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000580 break;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000581 case SPI_CONTROLLER_ICH9:
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000582 tmp2 = mmio_readw(spibar + 4);
Sean Nelson316a29f2010-05-07 20:09:04 +0000583 msg_pdbg("0x04: 0x%04x (HSFS)\n", tmp2);
584 msg_pdbg("FLOCKDN %i, ", (tmp2 >> 15 & 1));
585 msg_pdbg("FDV %i, ", (tmp2 >> 14) & 1);
586 msg_pdbg("FDOPSS %i, ", (tmp2 >> 13) & 1);
587 msg_pdbg("SCIP %i, ", (tmp2 >> 5) & 1);
588 msg_pdbg("BERASE %i, ", (tmp2 >> 3) & 3);
589 msg_pdbg("AEL %i, ", (tmp2 >> 2) & 1);
590 msg_pdbg("FCERR %i, ", (tmp2 >> 1) & 1);
591 msg_pdbg("FDONE %i\n", (tmp2 >> 0) & 1);
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000592
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000593 tmp = mmio_readl(spibar + 0x50);
Sean Nelson316a29f2010-05-07 20:09:04 +0000594 msg_pdbg("0x50: 0x%08x (FRAP)\n", tmp);
Joshua Roysf93b36a2010-07-01 17:45:54 +0000595 msg_pdbg("BMWAG 0x%02x, ", ICH_BMWAG(tmp));
596 msg_pdbg("BMRAG 0x%02x, ", ICH_BMRAG(tmp));
597 msg_pdbg("BRWA 0x%02x, ", ICH_BRWA(tmp));
598 msg_pdbg("BRRA 0x%02x\n", ICH_BRRA(tmp));
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000599
Joshua Roysf93b36a2010-07-01 17:45:54 +0000600 /* print out the FREGx registers along with FRAP access bits */
601 for(i = 0; i < 5; i++)
602 do_ich9_spi_frap(tmp, i);
603
Sean Nelson316a29f2010-05-07 20:09:04 +0000604 msg_pdbg("0x74: 0x%08x (PR0)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000605 mmio_readl(spibar + 0x74));
Sean Nelson316a29f2010-05-07 20:09:04 +0000606 msg_pdbg("0x78: 0x%08x (PR1)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000607 mmio_readl(spibar + 0x78));
Sean Nelson316a29f2010-05-07 20:09:04 +0000608 msg_pdbg("0x7C: 0x%08x (PR2)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000609 mmio_readl(spibar + 0x7C));
Sean Nelson316a29f2010-05-07 20:09:04 +0000610 msg_pdbg("0x80: 0x%08x (PR3)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000611 mmio_readl(spibar + 0x80));
Sean Nelson316a29f2010-05-07 20:09:04 +0000612 msg_pdbg("0x84: 0x%08x (PR4)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000613 mmio_readl(spibar + 0x84));
Sean Nelson316a29f2010-05-07 20:09:04 +0000614 msg_pdbg("0x90: 0x%08x (SSFS, SSFC)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000615 mmio_readl(spibar + 0x90));
Sean Nelson316a29f2010-05-07 20:09:04 +0000616 msg_pdbg("0x94: 0x%04x (PREOP)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000617 mmio_readw(spibar + 0x94));
Sean Nelson316a29f2010-05-07 20:09:04 +0000618 msg_pdbg("0x96: 0x%04x (OPTYPE)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000619 mmio_readw(spibar + 0x96));
Sean Nelson316a29f2010-05-07 20:09:04 +0000620 msg_pdbg("0x98: 0x%08x (OPMENU)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000621 mmio_readl(spibar + 0x98));
Sean Nelson316a29f2010-05-07 20:09:04 +0000622 msg_pdbg("0x9C: 0x%08x (OPMENU+4)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000623 mmio_readl(spibar + 0x9C));
Carl-Daniel Hailfinger80f3d052010-05-28 15:53:08 +0000624 ichspi_bbar = mmio_readl(spibar + 0xA0);
Sean Nelson316a29f2010-05-07 20:09:04 +0000625 msg_pdbg("0xA0: 0x%08x (BBAR)\n",
Carl-Daniel Hailfinger80f3d052010-05-28 15:53:08 +0000626 ichspi_bbar);
Sean Nelson316a29f2010-05-07 20:09:04 +0000627 msg_pdbg("0xB0: 0x%08x (FDOC)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000628 mmio_readl(spibar + 0xB0));
FENG yu ning37179b82009-01-18 06:39:32 +0000629 if (tmp2 & (1 << 15)) {
Sean Nelson316a29f2010-05-07 20:09:04 +0000630 msg_pinfo("WARNING: SPI Configuration Lockdown activated.\n");
FENG yu ning37179b82009-01-18 06:39:32 +0000631 ichspi_lock = 1;
632 }
Peter Stugee8a3e4c2008-12-22 14:12:08 +0000633 ich_init_opcodes();
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000634 break;
635 default:
636 /* Nothing */
637 break;
Stefan Reinauera9424d52008-06-27 16:28:34 +0000638 }
639
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000640 old = pci_read_byte(dev, 0xdc);
Sean Nelson316a29f2010-05-07 20:09:04 +0000641 msg_pdbg("SPI Read Configuration: ");
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000642 new = (old >> 2) & 0x3;
643 switch (new) {
644 case 0:
645 case 1:
646 case 2:
Sean Nelson316a29f2010-05-07 20:09:04 +0000647 msg_pdbg("prefetching %sabled, caching %sabled, ",
Uwe Hermann394131e2008-10-18 21:14:13 +0000648 (new & 0x2) ? "en" : "dis",
649 (new & 0x1) ? "dis" : "en");
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000650 break;
651 default:
Sean Nelson316a29f2010-05-07 20:09:04 +0000652 msg_pdbg("invalid prefetching/caching settings, ");
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000653 break;
654 }
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000655
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000656 return ret;
657}
Stefan Reinauera9424d52008-06-27 16:28:34 +0000658
Carl-Daniel Hailfinger1b18b3c2008-05-16 14:39:39 +0000659static int enable_flash_ich7(struct pci_dev *dev, const char *name)
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000660{
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000661 return enable_flash_ich_dc_spi(dev, name, 7);
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000662}
663
Carl-Daniel Hailfinger1b18b3c2008-05-16 14:39:39 +0000664static int enable_flash_ich8(struct pci_dev *dev, const char *name)
665{
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000666 return enable_flash_ich_dc_spi(dev, name, 8);
Carl-Daniel Hailfinger1b18b3c2008-05-16 14:39:39 +0000667}
668
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000669static int enable_flash_ich9(struct pci_dev *dev, const char *name)
670{
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000671 return enable_flash_ich_dc_spi(dev, name, 9);
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000672}
673
Carl-Daniel Hailfinger28ec74b2008-10-10 20:54:41 +0000674static int enable_flash_ich10(struct pci_dev *dev, const char *name)
675{
676 return enable_flash_ich_dc_spi(dev, name, 10);
677}
678
Michael Karcher89bed6d2010-06-13 10:16:12 +0000679static void via_do_byte_merge(void * arg)
680{
681 struct pci_dev * dev = arg;
682 uint8_t val;
683
684 msg_pdbg("Re-enabling byte merging\n");
685 val = pci_read_byte(dev, 0x71);
686 val |= 0x40;
687 pci_write_byte(dev, 0x71, val);
688}
689
690static int via_no_byte_merge(struct pci_dev *dev, const char *name)
691{
692 uint8_t val;
693
694 val = pci_read_byte(dev, 0x71);
695 if (val & 0x40)
696 {
697 msg_pdbg("Disabling byte merging\n");
698 val &= ~0x40;
699 pci_write_byte(dev, 0x71, val);
700 register_shutdown(via_do_byte_merge, dev);
701 }
702 return NOT_DONE_YET; /* need to find south bridge, too */
703}
704
Uwe Hermann372eeb52007-12-04 21:49:06 +0000705static int enable_flash_vt823x(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000706{
Ollie Lho184a4042005-11-26 21:55:36 +0000707 uint8_t val;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000708
Uwe Hermann394131e2008-10-18 21:14:13 +0000709 /* enable ROM decode range (1MB) FFC00000 - FFFFFFFF */
Bari Ari9477c4e2008-04-29 13:46:38 +0000710 pci_write_byte(dev, 0x41, 0x7f);
711
Uwe Hermannffec5f32007-08-23 16:08:21 +0000712 /* ROM write enable */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000713 val = pci_read_byte(dev, 0x40);
714 val |= 0x10;
715 pci_write_byte(dev, 0x40, val);
716
717 if (pci_read_byte(dev, 0x40) != val) {
Sean Nelson316a29f2010-05-07 20:09:04 +0000718 msg_pinfo("\nWARNING: Failed to enable flash write on \"%s\"\n",
Uwe Hermanna7e05482007-05-09 10:17:44 +0000719 name);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000720 return -1;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000721 }
Luc Verhaegen6382b442007-03-02 22:16:38 +0000722
Luc Verhaegen73d21192009-12-23 00:54:26 +0000723 if (dev->device_id == 0x3227) { /* VT8237R */
724 /* All memory cycles, not just ROM ones, go to LPC. */
725 val = pci_read_byte(dev, 0x59);
726 val &= ~0x80;
727 pci_write_byte(dev, 0x59, val);
728 }
729
Uwe Hermanna7e05482007-05-09 10:17:44 +0000730 return 0;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000731}
732
Uwe Hermann372eeb52007-12-04 21:49:06 +0000733static int enable_flash_cs5530(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000734{
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000735 uint8_t reg8;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000736
Uwe Hermann394131e2008-10-18 21:14:13 +0000737#define DECODE_CONTROL_REG2 0x5b /* F0 index 0x5b */
738#define ROM_AT_LOGIC_CONTROL_REG 0x52 /* F0 index 0x52 */
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000739#define CS5530_RESET_CONTROL_REG 0x44 /* F0 index 0x44 */
740#define CS5530_USB_SHADOW_REG 0x43 /* F0 index 0x43 */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000741
Uwe Hermann394131e2008-10-18 21:14:13 +0000742#define LOWER_ROM_ADDRESS_RANGE (1 << 0)
743#define ROM_WRITE_ENABLE (1 << 1)
744#define UPPER_ROM_ADDRESS_RANGE (1 << 2)
745#define BIOS_ROM_POSITIVE_DECODE (1 << 5)
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000746#define CS5530_ISA_MASTER (1 << 7)
747#define CS5530_ENABLE_SA2320 (1 << 2)
748#define CS5530_ENABLE_SA20 (1 << 6)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000749
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000750 buses_supported = CHIP_BUSTYPE_PARALLEL;
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000751 /* Decode 0x000E0000-0x000FFFFF (128 KB), not just 64 KB, and
752 * decode 0xFF000000-0xFFFFFFFF (16 MB), not just 256 KB.
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000753 * FIXME: Should we really touch the low mapping below 1 MB? Flashrom
754 * ignores that region completely.
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000755 * Make the configured ROM areas writable.
756 */
757 reg8 = pci_read_byte(dev, ROM_AT_LOGIC_CONTROL_REG);
758 reg8 |= LOWER_ROM_ADDRESS_RANGE;
759 reg8 |= UPPER_ROM_ADDRESS_RANGE;
760 reg8 |= ROM_WRITE_ENABLE;
761 pci_write_byte(dev, ROM_AT_LOGIC_CONTROL_REG, reg8);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000762
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000763 /* Set positive decode on ROM. */
764 reg8 = pci_read_byte(dev, DECODE_CONTROL_REG2);
765 reg8 |= BIOS_ROM_POSITIVE_DECODE;
766 pci_write_byte(dev, DECODE_CONTROL_REG2, reg8);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000767
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000768 reg8 = pci_read_byte(dev, CS5530_RESET_CONTROL_REG);
769 if (reg8 & CS5530_ISA_MASTER) {
770 /* We have A0-A23 available. */
771 max_rom_decode.parallel = 16 * 1024 * 1024;
772 } else {
773 reg8 = pci_read_byte(dev, CS5530_USB_SHADOW_REG);
774 if (reg8 & CS5530_ENABLE_SA2320) {
775 /* We have A0-19, A20-A23 available. */
776 max_rom_decode.parallel = 16 * 1024 * 1024;
777 } else if (reg8 & CS5530_ENABLE_SA20) {
778 /* We have A0-19, A20 available. */
779 max_rom_decode.parallel = 2 * 1024 * 1024;
780 } else {
781 /* A20 and above are not active. */
782 max_rom_decode.parallel = 1024 * 1024;
783 }
784 }
785
Ollie Lhocbbf1252004-03-17 22:22:08 +0000786 return 0;
787}
788
Mart Raudseppe1344da2008-02-08 10:10:57 +0000789/**
790 * Geode systems write protect the BIOS via RCONFs (cache settings similar
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000791 * to MTRRs). To unlock, change MSR 0x1808 top byte to 0x22.
Mart Raudseppe1344da2008-02-08 10:10:57 +0000792 *
793 * Geode systems also write protect the NOR flash chip itself via MSR_NORF_CTL.
794 * To enable write to NOR Boot flash for the benefit of systems that have such
795 * a setup, raise MSR 0x51400018 WE_CS3 (write enable Boot Flash Chip Select).
Mart Raudseppe1344da2008-02-08 10:10:57 +0000796 */
Uwe Hermann372eeb52007-12-04 21:49:06 +0000797static int enable_flash_cs5536(struct pci_dev *dev, const char *name)
Lane Brooksd54958a2007-11-13 16:45:22 +0000798{
Uwe Hermann394131e2008-10-18 21:14:13 +0000799#define MSR_RCONF_DEFAULT 0x1808
800#define MSR_NORF_CTL 0x51400018
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000801
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000802 msr_t msr;
Lane Brooksd54958a2007-11-13 16:45:22 +0000803
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000804 /* Geode only has a single core */
805 if (setup_cpu_msr(0))
Lane Brooksd54958a2007-11-13 16:45:22 +0000806 return -1;
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000807
808 msr = rdmsr(MSR_RCONF_DEFAULT);
809 if ((msr.hi >> 24) != 0x22) {
810 msr.hi &= 0xfbffffff;
811 wrmsr(MSR_RCONF_DEFAULT, msr);
Lane Brooksd54958a2007-11-13 16:45:22 +0000812 }
Mart Raudseppe1344da2008-02-08 10:10:57 +0000813
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000814 msr = rdmsr(MSR_NORF_CTL);
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000815 /* Raise WE_CS3 bit. */
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000816 msr.lo |= 0x08;
817 wrmsr(MSR_NORF_CTL, msr);
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000818
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000819 cleanup_cpu_msr();
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000820
Uwe Hermann394131e2008-10-18 21:14:13 +0000821#undef MSR_RCONF_DEFAULT
822#undef MSR_NORF_CTL
Lane Brooksd54958a2007-11-13 16:45:22 +0000823 return 0;
824}
825
Uwe Hermann372eeb52007-12-04 21:49:06 +0000826static int enable_flash_sc1100(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000827{
Ollie Lho184a4042005-11-26 21:55:36 +0000828 uint8_t new;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000829
Ollie Lhocbbf1252004-03-17 22:22:08 +0000830 pci_write_byte(dev, 0x52, 0xee);
831
832 new = pci_read_byte(dev, 0x52);
833
834 if (new != 0xee) {
Sean Nelson316a29f2010-05-07 20:09:04 +0000835 msg_pinfo("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x52, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000836 return -1;
837 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000838
Ollie Lhocbbf1252004-03-17 22:22:08 +0000839 return 0;
840}
841
Uwe Hermann190f8492008-10-25 18:03:50 +0000842/* Works for AMD-8111, VIA VT82C586A/B, VIA VT82C686A/B. */
Uwe Hermann372eeb52007-12-04 21:49:06 +0000843static int enable_flash_amd8111(struct pci_dev *dev, const char *name)
Ollie Lho761bf1b2004-03-20 16:46:10 +0000844{
Ollie Lho184a4042005-11-26 21:55:36 +0000845 uint8_t old, new;
Uwe Hermanna7e05482007-05-09 10:17:44 +0000846
Uwe Hermann372eeb52007-12-04 21:49:06 +0000847 /* Enable decoding at 0xffb00000 to 0xffffffff. */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000848 old = pci_read_byte(dev, 0x43);
Ollie Lhod11f3612004-12-07 17:19:04 +0000849 new = old | 0xC0;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000850 if (new != old) {
851 pci_write_byte(dev, 0x43, new);
852 if (pci_read_byte(dev, 0x43) != new) {
Sean Nelson316a29f2010-05-07 20:09:04 +0000853 msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x43, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000854 }
855 }
856
Uwe Hermann190f8492008-10-25 18:03:50 +0000857 /* Enable 'ROM write' bit. */
Ollie Lho761bf1b2004-03-20 16:46:10 +0000858 old = pci_read_byte(dev, 0x40);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000859 new = old | 0x01;
860 if (new == old)
861 return 0;
862 pci_write_byte(dev, 0x40, new);
863
864 if (pci_read_byte(dev, 0x40) != new) {
Sean Nelson316a29f2010-05-07 20:09:04 +0000865 msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000866 return -1;
867 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000868
Ollie Lhocbbf1252004-03-17 22:22:08 +0000869 return 0;
870}
871
Marc Jones3af487d2008-10-15 17:50:29 +0000872static int enable_flash_sb600(struct pci_dev *dev, const char *name)
873{
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000874 uint32_t tmp, prot;
Marc Jones3af487d2008-10-15 17:50:29 +0000875 uint8_t reg;
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000876 struct pci_dev *smbus_dev;
877 int has_spi = 1;
Marc Jones3af487d2008-10-15 17:50:29 +0000878
Jason Wanga3f04be2008-11-28 21:36:51 +0000879 /* Clear ROM protect 0-3. */
880 for (reg = 0x50; reg < 0x60; reg += 4) {
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000881 prot = pci_read_long(dev, reg);
882 /* No protection flags for this region?*/
883 if ((prot & 0x3) == 0)
884 continue;
Sean Nelson316a29f2010-05-07 20:09:04 +0000885 msg_pinfo("SB600 %s%sprotected from %u to %u\n",
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000886 (prot & 0x1) ? "write " : "",
887 (prot & 0x2) ? "read " : "",
888 (prot & 0xfffffc00),
889 (prot & 0xfffffc00) + ((prot & 0x3ff) << 8));
890 prot &= 0xfffffffc;
891 pci_write_byte(dev, reg, prot);
892 prot = pci_read_long(dev, reg);
Carl-Daniel Hailfinger9bb88ac2009-05-06 13:51:44 +0000893 if (prot & 0x3)
Sean Nelson316a29f2010-05-07 20:09:04 +0000894 msg_perr("SB600 %s%sunprotect failed from %u to %u\n",
Carl-Daniel Hailfinger9bb88ac2009-05-06 13:51:44 +0000895 (prot & 0x1) ? "write " : "",
896 (prot & 0x2) ? "read " : "",
897 (prot & 0xfffffc00),
898 (prot & 0xfffffc00) + ((prot & 0x3ff) << 8));
Jason Wanga3f04be2008-11-28 21:36:51 +0000899 }
900
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000901 /* Read SPI_BaseAddr */
902 tmp = pci_read_long(dev, 0xa0);
Carl-Daniel Hailfingerf8555e22009-07-23 01:36:08 +0000903 tmp &= 0xffffffe0; /* remove bits 4-0 (reserved) */
Sean Nelson316a29f2010-05-07 20:09:04 +0000904 msg_pdbg("SPI base address is at 0x%x\n", tmp);
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000905
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000906 /* If the BAR has address 0, it is unlikely SPI is used. */
907 if (!tmp)
908 has_spi = 0;
909
Carl-Daniel Hailfingerf8555e22009-07-23 01:36:08 +0000910 if (has_spi) {
911 /* Physical memory has to be mapped at page (4k) boundaries. */
912 sb600_spibar = physmap("SB600 SPI registers", tmp & 0xfffff000,
913 0x1000);
914 /* The low bits of the SPI base address are used as offset into
915 * the mapped page.
916 */
917 sb600_spibar += tmp & 0xfff;
918
919 tmp = pci_read_long(dev, 0xa0);
Sean Nelson316a29f2010-05-07 20:09:04 +0000920 msg_pdbg("AltSpiCSEnable=%i, SpiRomEnable=%i, "
Carl-Daniel Hailfingerf8555e22009-07-23 01:36:08 +0000921 "AbortEnable=%i\n", tmp & 0x1, (tmp & 0x2) >> 1,
922 (tmp & 0x4) >> 2);
923 tmp = (pci_read_byte(dev, 0xba) & 0x4) >> 2;
Sean Nelson316a29f2010-05-07 20:09:04 +0000924 msg_pdbg("PrefetchEnSPIFromIMC=%i, ", tmp);
Carl-Daniel Hailfingerf8555e22009-07-23 01:36:08 +0000925
926 tmp = pci_read_byte(dev, 0xbb);
Sean Nelson316a29f2010-05-07 20:09:04 +0000927 msg_pdbg("PrefetchEnSPIFromHost=%i, SpiOpEnInLpcMode=%i\n",
Carl-Daniel Hailfingerf8555e22009-07-23 01:36:08 +0000928 tmp & 0x1, (tmp & 0x20) >> 5);
929 tmp = mmio_readl(sb600_spibar);
Sean Nelson316a29f2010-05-07 20:09:04 +0000930 msg_pdbg("SpiArbEnable=%i, SpiAccessMacRomEn=%i, "
Carl-Daniel Hailfingerf8555e22009-07-23 01:36:08 +0000931 "SpiHostAccessRomEn=%i, ArbWaitCount=%i, "
932 "SpiBridgeDisable=%i, DropOneClkOnRd=%i\n",
933 (tmp >> 19) & 0x1, (tmp >> 22) & 0x1,
934 (tmp >> 23) & 0x1, (tmp >> 24) & 0x7,
935 (tmp >> 27) & 0x1, (tmp >> 28) & 0x1);
936 }
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000937
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000938 /* Look for the SMBus device. */
939 smbus_dev = pci_dev_find(0x1002, 0x4385);
940
Carl-Daniel Hailfingerf8555e22009-07-23 01:36:08 +0000941 if (has_spi && !smbus_dev) {
Sean Nelson316a29f2010-05-07 20:09:04 +0000942 msg_perr("ERROR: SMBus device not found. Not enabling SPI.\n");
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000943 has_spi = 0;
Carl-Daniel Hailfingerf8555e22009-07-23 01:36:08 +0000944 }
945 if (has_spi) {
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000946 /* Note about the bit tests below: If a bit is zero, the GPIO is SPI. */
947 /* GPIO11/SPI_DO and GPIO12/SPI_DI status */
948 reg = pci_read_byte(smbus_dev, 0xAB);
949 reg &= 0xC0;
Sean Nelson316a29f2010-05-07 20:09:04 +0000950 msg_pdbg("GPIO11 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_DO");
951 msg_pdbg("GPIO12 used for %s\n", (reg & (1 << 7)) ? "GPIO" : "SPI_DI");
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000952 if (reg != 0x00)
953 has_spi = 0;
954 /* GPIO31/SPI_HOLD and GPIO32/SPI_CS status */
955 reg = pci_read_byte(smbus_dev, 0x83);
956 reg &= 0xC0;
Sean Nelson316a29f2010-05-07 20:09:04 +0000957 msg_pdbg("GPIO31 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_HOLD");
958 msg_pdbg("GPIO32 used for %s\n", (reg & (1 << 7)) ? "GPIO" : "SPI_CS");
Carl-Daniel Hailfinger98622512009-05-15 23:36:23 +0000959 /* SPI_HOLD is not used on all boards, filter it out. */
960 if ((reg & 0x80) != 0x00)
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000961 has_spi = 0;
962 /* GPIO47/SPI_CLK status */
963 reg = pci_read_byte(smbus_dev, 0xA7);
964 reg &= 0x40;
Sean Nelson316a29f2010-05-07 20:09:04 +0000965 msg_pdbg("GPIO47 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_CLK");
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000966 if (reg != 0x00)
967 has_spi = 0;
968 }
969
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000970 buses_supported = CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH;
971 if (has_spi) {
972 buses_supported |= CHIP_BUSTYPE_SPI;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000973 spi_controller = SPI_CONTROLLER_SB600;
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000974 }
Jason Wanga3f04be2008-11-28 21:36:51 +0000975
Carl-Daniel Hailfinger98622512009-05-15 23:36:23 +0000976 /* Read ROM strap override register. */
977 OUTB(0x8f, 0xcd6);
978 reg = INB(0xcd7);
979 reg &= 0x0e;
Sean Nelson316a29f2010-05-07 20:09:04 +0000980 msg_pdbg("ROM strap override is %sactive", (reg & 0x02) ? "" : "not ");
Carl-Daniel Hailfinger98622512009-05-15 23:36:23 +0000981 if (reg & 0x02) {
982 switch ((reg & 0x0c) >> 2) {
983 case 0x00:
Sean Nelson316a29f2010-05-07 20:09:04 +0000984 msg_pdbg(": LPC");
Carl-Daniel Hailfinger98622512009-05-15 23:36:23 +0000985 break;
986 case 0x01:
Sean Nelson316a29f2010-05-07 20:09:04 +0000987 msg_pdbg(": PCI");
Carl-Daniel Hailfinger98622512009-05-15 23:36:23 +0000988 break;
989 case 0x02:
Sean Nelson316a29f2010-05-07 20:09:04 +0000990 msg_pdbg(": FWH");
Carl-Daniel Hailfinger98622512009-05-15 23:36:23 +0000991 break;
992 case 0x03:
Sean Nelson316a29f2010-05-07 20:09:04 +0000993 msg_pdbg(": SPI");
Carl-Daniel Hailfinger98622512009-05-15 23:36:23 +0000994 break;
995 }
996 }
Sean Nelson316a29f2010-05-07 20:09:04 +0000997 msg_pdbg("\n");
Carl-Daniel Hailfinger98622512009-05-15 23:36:23 +0000998
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000999 /* Force enable SPI ROM in SB600 PM register.
1000 * If we enable SPI ROM here, we have to disable it after we leave.
Zheng Bao284a6002009-05-04 22:33:50 +00001001 * But how can we know which ROM we are going to handle? So we have
1002 * to trade off. We only access LPC ROM if we boot via LPC ROM. And
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +00001003 * only SPI ROM if we boot via SPI ROM. If you want to access SPI on
1004 * boards with LPC straps, you have to use the code below.
Zheng Bao284a6002009-05-04 22:33:50 +00001005 */
1006 /*
Jason Wanga3f04be2008-11-28 21:36:51 +00001007 OUTB(0x8f, 0xcd6);
1008 OUTB(0x0e, 0xcd7);
Zheng Bao284a6002009-05-04 22:33:50 +00001009 */
Marc Jones3af487d2008-10-15 17:50:29 +00001010
1011 return 0;
1012}
1013
Luc Verhaegen90e8e612009-05-26 09:48:28 +00001014static int enable_flash_nvidia_nforce2(struct pci_dev *dev, const char *name)
1015{
Uwe Hermanne9d04d42009-06-02 19:54:22 +00001016 uint8_t tmp;
Luc Verhaegen90e8e612009-05-26 09:48:28 +00001017
Uwe Hermanne9d04d42009-06-02 19:54:22 +00001018 pci_write_byte(dev, 0x92, 0);
Luc Verhaegen90e8e612009-05-26 09:48:28 +00001019
Uwe Hermanne9d04d42009-06-02 19:54:22 +00001020 tmp = pci_read_byte(dev, 0x6d);
1021 tmp |= 0x01;
1022 pci_write_byte(dev, 0x6d, tmp);
Luc Verhaegen90e8e612009-05-26 09:48:28 +00001023
Uwe Hermanne9d04d42009-06-02 19:54:22 +00001024 return 0;
Luc Verhaegen90e8e612009-05-26 09:48:28 +00001025}
1026
Uwe Hermann372eeb52007-12-04 21:49:06 +00001027static int enable_flash_ck804(struct pci_dev *dev, const char *name)
Yinghai Lu952dfce2005-07-06 17:13:46 +00001028{
Uwe Hermanna7e05482007-05-09 10:17:44 +00001029 uint8_t old, new;
Yinghai Lu952dfce2005-07-06 17:13:46 +00001030
Uwe Hermanna7e05482007-05-09 10:17:44 +00001031 old = pci_read_byte(dev, 0x88);
1032 new = old | 0xc0;
1033 if (new != old) {
1034 pci_write_byte(dev, 0x88, new);
1035 if (pci_read_byte(dev, 0x88) != new) {
Sean Nelson316a29f2010-05-07 20:09:04 +00001036 msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x88, new, name);
Uwe Hermanna7e05482007-05-09 10:17:44 +00001037 }
1038 }
Yinghai Lu952dfce2005-07-06 17:13:46 +00001039
Uwe Hermanna7e05482007-05-09 10:17:44 +00001040 old = pci_read_byte(dev, 0x6d);
1041 new = old | 0x01;
1042 if (new == old)
1043 return 0;
1044 pci_write_byte(dev, 0x6d, new);
1045
1046 if (pci_read_byte(dev, 0x6d) != new) {
Sean Nelson316a29f2010-05-07 20:09:04 +00001047 msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name);
Uwe Hermanna7e05482007-05-09 10:17:44 +00001048 return -1;
1049 }
Uwe Hermannffec5f32007-08-23 16:08:21 +00001050
Uwe Hermanna7e05482007-05-09 10:17:44 +00001051 return 0;
Yinghai Lu952dfce2005-07-06 17:13:46 +00001052}
1053
Uwe Hermann372eeb52007-12-04 21:49:06 +00001054/* ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80) */
1055static int enable_flash_sb400(struct pci_dev *dev, const char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +00001056{
Uwe Hermanna7e05482007-05-09 10:17:44 +00001057 uint8_t tmp;
Stefan Reinauer86de2832006-03-31 11:26:55 +00001058 struct pci_dev *smbusdev;
1059
Uwe Hermann372eeb52007-12-04 21:49:06 +00001060 /* Look for the SMBus device. */
Carl-Daniel Hailfingerf6e3efb2009-05-06 00:35:31 +00001061 smbusdev = pci_dev_find(0x1002, 0x4372);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +00001062
Uwe Hermanna7e05482007-05-09 10:17:44 +00001063 if (!smbusdev) {
Sean Nelson316a29f2010-05-07 20:09:04 +00001064 msg_perr("ERROR: SMBus device not found. Aborting.\n");
Stefan Reinauer86de2832006-03-31 11:26:55 +00001065 exit(1);
1066 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +00001067
Uwe Hermann372eeb52007-12-04 21:49:06 +00001068 /* Enable some SMBus stuff. */
Uwe Hermanna7e05482007-05-09 10:17:44 +00001069 tmp = pci_read_byte(smbusdev, 0x79);
1070 tmp |= 0x01;
Stefan Reinauer86de2832006-03-31 11:26:55 +00001071 pci_write_byte(smbusdev, 0x79, tmp);
1072
Uwe Hermann372eeb52007-12-04 21:49:06 +00001073 /* Change southbridge. */
Uwe Hermanna7e05482007-05-09 10:17:44 +00001074 tmp = pci_read_byte(dev, 0x48);
1075 tmp |= 0x21;
Stefan Reinauer86de2832006-03-31 11:26:55 +00001076 pci_write_byte(dev, 0x48, tmp);
1077
Uwe Hermann372eeb52007-12-04 21:49:06 +00001078 /* Now become a bit silly. */
Andriy Gapon65c1b862008-05-22 13:22:45 +00001079 tmp = INB(0xc6f);
1080 OUTB(tmp, 0xeb);
1081 OUTB(tmp, 0xeb);
Uwe Hermanna7e05482007-05-09 10:17:44 +00001082 tmp |= 0x40;
Andriy Gapon65c1b862008-05-22 13:22:45 +00001083 OUTB(tmp, 0xc6f);
1084 OUTB(tmp, 0xeb);
1085 OUTB(tmp, 0xeb);
Stefan Reinauer86de2832006-03-31 11:26:55 +00001086
1087 return 0;
1088}
1089
Uwe Hermann372eeb52007-12-04 21:49:06 +00001090static int enable_flash_mcp55(struct pci_dev *dev, const char *name)
Yinghai Luca782972007-01-22 20:21:17 +00001091{
Michael Karcher4e2fb0e2010-01-12 23:29:26 +00001092 uint8_t old, new, val;
1093 uint16_t wordval;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +00001094
Uwe Hermann372eeb52007-12-04 21:49:06 +00001095 /* Set the 0-16 MB enable bits. */
Michael Karcher4e2fb0e2010-01-12 23:29:26 +00001096 val = pci_read_byte(dev, 0x88);
1097 val |= 0xff; /* 256K */
1098 pci_write_byte(dev, 0x88, val);
1099 val = pci_read_byte(dev, 0x8c);
1100 val |= 0xff; /* 1M */
1101 pci_write_byte(dev, 0x8c, val);
1102 wordval = pci_read_word(dev, 0x90);
1103 wordval |= 0x7fff; /* 16M */
1104 pci_write_word(dev, 0x90, wordval);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +00001105
Uwe Hermanna7e05482007-05-09 10:17:44 +00001106 old = pci_read_byte(dev, 0x6d);
1107 new = old | 0x01;
1108 if (new == old)
1109 return 0;
1110 pci_write_byte(dev, 0x6d, new);
Yinghai Luca782972007-01-22 20:21:17 +00001111
Uwe Hermanna7e05482007-05-09 10:17:44 +00001112 if (pci_read_byte(dev, 0x6d) != new) {
Sean Nelson316a29f2010-05-07 20:09:04 +00001113 msg_pinfo("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name);
Uwe Hermanna7e05482007-05-09 10:17:44 +00001114 return -1;
1115 }
Yinghai Luca782972007-01-22 20:21:17 +00001116
1117 return 0;
Yinghai Luca782972007-01-22 20:21:17 +00001118}
1119
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001120/* This is a shot in the dark. Even if the code is totally bogus for some
1121 * chipsets, users will at least start to send in reports.
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001122 */
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001123static int enable_flash_mcp6x_7x_common(struct pci_dev *dev, const char *name)
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001124{
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001125 int ret = 0;
Michael Karchercfa674f2010-02-25 11:38:23 +00001126 uint8_t val;
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001127 uint16_t status;
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001128 char *busname;
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001129 uint32_t mcp_spibaraddr;
1130 void *mcp_spibar;
1131 struct pci_dev *smbusdev;
1132
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001133 msg_pinfo("This chipset is not really supported yet. Guesswork...\n");
1134
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001135 /* dev is the ISA bridge. No idea what the stuff below does. */
Michael Karchercfa674f2010-02-25 11:38:23 +00001136 val = pci_read_byte(dev, 0x8a);
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001137 msg_pdbg("ISA/LPC bridge reg 0x8a contents: 0x%02x, bit 6 is %i, bit 5 "
Michael Karchercfa674f2010-02-25 11:38:23 +00001138 "is %i\n", val, (val >> 6) & 0x1, (val >> 5) & 0x1);
1139 switch ((val >> 5) & 0x3) {
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001140 case 0x0:
1141 buses_supported = CHIP_BUSTYPE_LPC;
1142 break;
1143 case 0x2:
1144 buses_supported = CHIP_BUSTYPE_SPI;
1145 break;
1146 default:
1147 buses_supported = CHIP_BUSTYPE_UNKNOWN;
1148 break;
1149 }
1150 busname = flashbuses_to_text(buses_supported);
1151 msg_pdbg("Guessed flash bus type is %s\n", busname);
1152 free(busname);
1153
1154 /* Force enable SPI and disable LPC? Not a good idea. */
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001155#if 0
Michael Karchercfa674f2010-02-25 11:38:23 +00001156 val |= (1 << 6);
1157 val &= ~(1 << 5);
1158 pci_write_byte(dev, 0x8a, val);
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001159#endif
1160
1161 /* Look for the SMBus device (SMBus PCI class) */
1162 smbusdev = pci_dev_find_vendorclass(0x10de, 0x0c05);
1163 if (!smbusdev) {
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001164 if (buses_supported & CHIP_BUSTYPE_SPI) {
1165 msg_perr("ERROR: SMBus device not found. Not enabling "
1166 "SPI.\n");
1167 buses_supported &= ~CHIP_BUSTYPE_SPI;
1168 ret = 1;
1169 } else {
1170 msg_pinfo("Odd. SMBus device not found.\n");
1171 }
1172 goto out_msg;
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001173 }
1174 msg_pdbg("Found SMBus device %04x:%04x at %02x:%02x:%01x\n",
1175 smbusdev->vendor_id, smbusdev->device_id,
1176 smbusdev->bus, smbusdev->dev, smbusdev->func);
1177
1178 /* Locate the BAR where the SPI interface lives. */
1179 mcp_spibaraddr = pci_read_long(smbusdev, 0x74);
1180 msg_pdbg("SPI BAR is at 0x%08x, ", mcp_spibaraddr);
1181 /* We hope this has native alignment. We know the SPI interface (well,
1182 * a set of GPIOs that is connected to SPI flash) is at offset 0x530,
1183 * so we expect a size of at least 0x800. Clear the lower bits.
1184 * It is entirely possible that the BAR is 64k big and the low bits are
1185 * reserved for an entirely different purpose.
1186 */
1187 mcp_spibaraddr &= ~0x7ff;
1188 msg_pdbg("after clearing low bits BAR is at 0x%08x\n", mcp_spibaraddr);
1189
1190 /* Accessing a NULL pointer BAR is evil. Don't do it. */
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001191 if (mcp_spibaraddr && (buses_supported == CHIP_BUSTYPE_SPI)) {
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001192 /* Map the BAR. Bytewise/wordwise access at 0x530 and 0x540. */
1193 mcp_spibar = physmap("MCP67 SPI", mcp_spibaraddr, 0x544);
1194
1195/* Guessed. If this is correct, migrate to a separate MCP67 SPI driver. */
1196#define MCP67_SPI_CS (1 << 1)
1197#define MCP67_SPI_SCK (1 << 2)
1198#define MCP67_SPI_MOSI (1 << 3)
1199#define MCP67_SPI_MISO (1 << 4)
1200#define MCP67_SPI_ENABLE (1 << 0)
1201#define MCP67_SPI_IDLE (1 << 8)
1202
1203 status = mmio_readw(mcp_spibar + 0x530);
1204 msg_pdbg("SPI control is 0x%04x, enable=%i, idle=%i\n",
1205 status, status & 0x1, (status >> 8) & 0x1);
1206 /* FIXME: Remove the physunmap once the SPI driver exists. */
1207 physunmap(mcp_spibar, 0x544);
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001208 } else if (!mcp_spibaraddr && (buses_supported & CHIP_BUSTYPE_SPI)) {
1209 msg_pdbg("Strange. MCP SPI BAR is invalid.\n");
1210 buses_supported &= ~CHIP_BUSTYPE_SPI;
1211 ret = 1;
1212 } else if (mcp_spibaraddr && !(buses_supported & CHIP_BUSTYPE_SPI)) {
1213 msg_pdbg("Strange. MCP SPI BAR is valid, but chipset apparently"
1214 " doesn't have SPI enabled.\n");
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001215 } else {
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001216 msg_pdbg("MCP SPI is not used.\n");
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001217 }
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001218out_msg:
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001219 msg_pinfo("Please send the output of \"flashrom -V\" to "
1220 "flashrom@flashrom.org to help us finish support for your "
1221 "chipset. Thanks.\n");
1222
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001223 return ret;
1224}
1225
1226/**
1227 * The MCP61/MCP67 code is guesswork based on cleanroom reverse engineering.
1228 * Due to that, it only reads info and doesn't change any settings.
1229 * It is assumed that LPC chips need the MCP55 code and SPI chips need the
1230 * code provided in enable_flash_mcp6x_7x_common. Until we know for sure, call
1231 * enable_flash_mcp55 from this function only if enable_flash_mcp6x_7x_common
1232 * indicates the flash chip is LPC. Warning: enable_flash_mcp55
1233 * might make SPI flash inaccessible. The same caveat applies to SPI init
1234 * for LPC flash.
1235 */
1236static int enable_flash_mcp67(struct pci_dev *dev, const char *name)
1237{
1238 int result = 0;
1239
1240 result = enable_flash_mcp6x_7x_common(dev, name);
1241 if (result)
1242 return result;
1243
1244 /* Not sure if this is correct. No docs as usual. */
1245 switch (buses_supported) {
1246 case CHIP_BUSTYPE_LPC:
1247 result = enable_flash_mcp55(dev, name);
1248 break;
1249 case CHIP_BUSTYPE_SPI:
1250 msg_pinfo("SPI on this chipset is not supported yet.\n");
1251 buses_supported = CHIP_BUSTYPE_NONE;
1252 break;
1253 default:
1254 msg_pinfo("Something went wrong with bus type detection.\n");
1255 buses_supported = CHIP_BUSTYPE_NONE;
1256 break;
1257 }
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001258
1259 return result;
1260}
1261
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001262static int enable_flash_mcp7x(struct pci_dev *dev, const char *name)
1263{
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001264 int result = 0;
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001265
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001266 result = enable_flash_mcp6x_7x_common(dev, name);
1267 if (result)
1268 return result;
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001269
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001270 /* Not sure if this is correct. No docs as usual. */
1271 switch (buses_supported) {
1272 case CHIP_BUSTYPE_LPC:
1273 msg_pinfo("LPC on this chipset is not supported yet.\n");
1274 break;
1275 case CHIP_BUSTYPE_SPI:
1276 msg_pinfo("SPI on this chipset is not supported yet.\n");
1277 buses_supported = CHIP_BUSTYPE_NONE;
1278 break;
1279 default:
1280 msg_pinfo("Something went wrong with bus type detection.\n");
1281 buses_supported = CHIP_BUSTYPE_NONE;
1282 break;
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001283 }
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001284
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001285 return result;
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001286}
1287
Uwe Hermann372eeb52007-12-04 21:49:06 +00001288static int enable_flash_ht1000(struct pci_dev *dev, const char *name)
Stefan Reinauerc868b9e2007-06-05 10:28:39 +00001289{
Michael Karchercfa674f2010-02-25 11:38:23 +00001290 uint8_t val;
Stefan Reinauerc868b9e2007-06-05 10:28:39 +00001291
Uwe Hermanne823ee02007-06-05 15:02:18 +00001292 /* Set the 4MB enable bit. */
Michael Karchercfa674f2010-02-25 11:38:23 +00001293 val = pci_read_byte(dev, 0x41);
1294 val |= 0x0e;
1295 pci_write_byte(dev, 0x41, val);
Stefan Reinauerc868b9e2007-06-05 10:28:39 +00001296
Michael Karchercfa674f2010-02-25 11:38:23 +00001297 val = pci_read_byte(dev, 0x43);
1298 val |= (1 << 4);
1299 pci_write_byte(dev, 0x43, val);
Stefan Reinauerc868b9e2007-06-05 10:28:39 +00001300
Stefan Reinauerc868b9e2007-06-05 10:28:39 +00001301 return 0;
1302}
1303
Stefan Reinauer9a6d1762008-12-03 21:24:40 +00001304/**
1305 * Usually on the x86 architectures (and on other PC-like platforms like some
1306 * Alphas or Itanium) the system flash is mapped right below 4G. On the AMD
1307 * Elan SC520 only a small piece of the system flash is mapped there, but the
1308 * complete flash is mapped somewhere below 1G. The position can be determined
1309 * by the BOOTCS PAR register.
1310 */
1311static int get_flashbase_sc520(struct pci_dev *dev, const char *name)
1312{
1313 int i, bootcs_found = 0;
1314 uint32_t parx = 0;
1315 void *mmcr;
1316
1317 /* 1. Map MMCR */
Stefan Reinauer0593f212009-01-26 01:10:48 +00001318 mmcr = physmap("Elan SC520 MMCR", 0xfffef000, getpagesize());
Stefan Reinauer9a6d1762008-12-03 21:24:40 +00001319
1320 /* 2. Scan PAR0 (0x88) - PAR15 (0xc4) for
1321 * BOOTCS region (PARx[31:29] = 100b)e
1322 */
1323 for (i = 0x88; i <= 0xc4; i += 4) {
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +00001324 parx = mmio_readl(mmcr + i);
Stefan Reinauer9a6d1762008-12-03 21:24:40 +00001325 if ((parx >> 29) == 4) {
1326 bootcs_found = 1;
1327 break; /* BOOTCS found */
1328 }
1329 }
1330
1331 /* 3. PARx[25] = 1b --> flashbase[29:16] = PARx[13:0]
1332 * PARx[25] = 0b --> flashbase[29:12] = PARx[17:0]
1333 */
1334 if (bootcs_found) {
1335 if (parx & (1 << 25)) {
1336 parx &= (1 << 14) - 1; /* Mask [13:0] */
1337 flashbase = parx << 16;
1338 } else {
1339 parx &= (1 << 18) - 1; /* Mask [17:0] */
1340 flashbase = parx << 12;
1341 }
1342 } else {
Sean Nelson316a29f2010-05-07 20:09:04 +00001343 msg_pinfo("AMD Elan SC520 detected, but no BOOTCS. Assuming flash at 4G\n");
Stefan Reinauer9a6d1762008-12-03 21:24:40 +00001344 }
1345
1346 /* 4. Clean up */
Carl-Daniel Hailfingerbe726812009-08-09 12:44:08 +00001347 physunmap(mmcr, getpagesize());
Stefan Reinauer9a6d1762008-12-03 21:24:40 +00001348 return 0;
1349}
1350
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +00001351#endif
1352
Uwe Hermann4179d292009-05-08 17:50:51 +00001353/* Please keep this list alphabetically sorted by vendor/device. */
Uwe Hermann05fab752009-05-16 23:42:17 +00001354const struct penable chipset_enables[] = {
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +00001355#if defined(__i386__) || defined(__x86_64__)
Uwe Hermann4179d292009-05-08 17:50:51 +00001356 {0x10B9, 0x1533, OK, "ALi", "M1533", enable_flash_ali_m1533},
1357 {0x1022, 0x7440, OK, "AMD", "AMD-768", enable_flash_amd8111},
1358 {0x1022, 0x7468, OK, "AMD", "AMD8111", enable_flash_amd8111},
1359 {0x1078, 0x0100, OK, "AMD", "CS5530(A)", enable_flash_cs5530},
1360 {0x1022, 0x2080, OK, "AMD", "CS5536", enable_flash_cs5536},
Nils Jacobse715c7b2009-09-23 02:09:23 +00001361 {0x1022, 0x2090, OK, "AMD", "CS5536", enable_flash_cs5536},
Uwe Hermann4179d292009-05-08 17:50:51 +00001362 {0x1022, 0x3000, OK, "AMD", "Elan SC520", get_flashbase_sc520},
1363 {0x1002, 0x438D, OK, "AMD", "SB600", enable_flash_sb600},
Carl-Daniel Hailfinger174962d2009-09-01 22:13:42 +00001364 {0x1002, 0x439d, OK, "AMD", "SB700/SB710/SB750", enable_flash_sb600},
Uwe Hermann4179d292009-05-08 17:50:51 +00001365 {0x100b, 0x0510, NT, "AMD", "SC1100", enable_flash_sc1100},
1366 {0x1002, 0x4377, OK, "ATI", "SB400", enable_flash_sb400},
1367 {0x1166, 0x0205, OK, "Broadcom", "HT-1000", enable_flash_ht1000},
Carl-Daniel Hailfinger797a8342009-11-26 16:51:39 +00001368 {0x8086, 0x3b00, NT, "Intel", "3400 Desktop", enable_flash_ich10},
1369 {0x8086, 0x3b01, NT, "Intel", "3400 Mobile", enable_flash_ich10},
1370 {0x8086, 0x3b0d, NT, "Intel", "3400 Mobile SFF", enable_flash_ich10},
Uwe Hermannb0039912009-05-07 13:24:49 +00001371 {0x8086, 0x7198, OK, "Intel", "440MX", enable_flash_piix4},
Uwe Hermann4179d292009-05-08 17:50:51 +00001372 {0x8086, 0x25a1, OK, "Intel", "6300ESB", enable_flash_ich_4e},
1373 {0x8086, 0x2670, OK, "Intel", "631xESB/632xESB/3100", enable_flash_ich_dc},
1374 {0x8086, 0x5031, OK, "Intel", "EP80579", enable_flash_ich7},
Uwe Hermannb0039912009-05-07 13:24:49 +00001375 {0x8086, 0x2420, OK, "Intel", "ICH0", enable_flash_ich_4e},
Uwe Hermann4179d292009-05-08 17:50:51 +00001376 {0x8086, 0x3a18, OK, "Intel", "ICH10", enable_flash_ich10},
1377 {0x8086, 0x3a1a, OK, "Intel", "ICH10D", enable_flash_ich10},
1378 {0x8086, 0x3a14, OK, "Intel", "ICH10DO", enable_flash_ich10},
1379 {0x8086, 0x3a16, OK, "Intel", "ICH10R", enable_flash_ich10},
Uwe Hermannb0039912009-05-07 13:24:49 +00001380 {0x8086, 0x2440, OK, "Intel", "ICH2", enable_flash_ich_4e},
1381 {0x8086, 0x244c, OK, "Intel", "ICH2-M", enable_flash_ich_4e},
Uwe Hermannb0039912009-05-07 13:24:49 +00001382 {0x8086, 0x248c, OK, "Intel", "ICH3-M", enable_flash_ich_4e},
Uwe Hermann4179d292009-05-08 17:50:51 +00001383 {0x8086, 0x2480, OK, "Intel", "ICH3-S", enable_flash_ich_4e},
Uwe Hermannb0039912009-05-07 13:24:49 +00001384 {0x8086, 0x24c0, OK, "Intel", "ICH4/ICH4-L", enable_flash_ich_4e},
1385 {0x8086, 0x24cc, OK, "Intel", "ICH4-M", enable_flash_ich_4e},
1386 {0x8086, 0x24d0, OK, "Intel", "ICH5/ICH5R", enable_flash_ich_4e},
Uwe Hermannb0039912009-05-07 13:24:49 +00001387 {0x8086, 0x2640, OK, "Intel", "ICH6/ICH6R", enable_flash_ich_dc},
1388 {0x8086, 0x2641, OK, "Intel", "ICH6-M", enable_flash_ich_dc},
Uwe Hermannb0039912009-05-07 13:24:49 +00001389 {0x8086, 0x27b0, OK, "Intel", "ICH7DH", enable_flash_ich7},
1390 {0x8086, 0x27b8, OK, "Intel", "ICH7/ICH7R", enable_flash_ich7},
1391 {0x8086, 0x27b9, OK, "Intel", "ICH7M", enable_flash_ich7},
1392 {0x8086, 0x27bd, OK, "Intel", "ICH7MDH", enable_flash_ich7},
David Hendricksdb7c1532010-01-19 02:19:27 +00001393 {0x8086, 0x27bc, OK, "Intel", "NM10", enable_flash_ich7},
Uwe Hermann4179d292009-05-08 17:50:51 +00001394 {0x8086, 0x2410, OK, "Intel", "ICH", enable_flash_ich_4e},
Uwe Hermannb0039912009-05-07 13:24:49 +00001395 {0x8086, 0x2812, OK, "Intel", "ICH8DH", enable_flash_ich8},
1396 {0x8086, 0x2814, OK, "Intel", "ICH8DO", enable_flash_ich8},
Uwe Hermann4179d292009-05-08 17:50:51 +00001397 {0x8086, 0x2810, OK, "Intel", "ICH8/ICH8R", enable_flash_ich8},
Uwe Hermannb0039912009-05-07 13:24:49 +00001398 {0x8086, 0x2815, OK, "Intel", "ICH8M", enable_flash_ich8},
Uwe Hermann4179d292009-05-08 17:50:51 +00001399 {0x8086, 0x2811, OK, "Intel", "ICH8M-E", enable_flash_ich8},
1400 {0x8086, 0x2918, OK, "Intel", "ICH9", enable_flash_ich9},
Uwe Hermannb0039912009-05-07 13:24:49 +00001401 {0x8086, 0x2912, OK, "Intel", "ICH9DH", enable_flash_ich9},
1402 {0x8086, 0x2914, OK, "Intel", "ICH9DO", enable_flash_ich9},
Uwe Hermannb0039912009-05-07 13:24:49 +00001403 {0x8086, 0x2919, OK, "Intel", "ICH9M", enable_flash_ich9},
Uwe Hermann4179d292009-05-08 17:50:51 +00001404 {0x8086, 0x2917, OK, "Intel", "ICH9M-E", enable_flash_ich9},
1405 {0x8086, 0x2916, OK, "Intel", "ICH9R", enable_flash_ich9},
Carl-Daniel Hailfinger95baaad2009-08-21 17:26:13 +00001406 {0x8086, 0x2910, OK, "Intel", "ICH9 Engineering Sample", enable_flash_ich9},
Uwe Hermann4179d292009-05-08 17:50:51 +00001407 {0x8086, 0x1234, NT, "Intel", "MPIIX", enable_flash_piix4},
1408 {0x8086, 0x7000, OK, "Intel", "PIIX3", enable_flash_piix4},
1409 {0x8086, 0x7110, OK, "Intel", "PIIX4/4E/4M", enable_flash_piix4},
1410 {0x8086, 0x122e, OK, "Intel", "PIIX", enable_flash_piix4},
Adam Jurkowskie4984102009-12-21 15:30:46 +00001411 {0x8086, 0x8119, OK, "Intel", "Poulsbo", enable_flash_poulsbo},
Luc Verhaegenaad7e672009-10-06 11:32:21 +00001412 {0x10de, 0x0030, OK, "NVIDIA", "nForce4/MCP4", enable_flash_nvidia_nforce2},
Uwe Hermannb0039912009-05-07 13:24:49 +00001413 {0x10de, 0x0050, OK, "NVIDIA", "CK804", enable_flash_ck804}, /* LPC */
1414 {0x10de, 0x0051, OK, "NVIDIA", "CK804", enable_flash_ck804}, /* Pro */
Luc Verhaegen90e8e612009-05-26 09:48:28 +00001415 {0x10de, 0x0060, OK, "NVIDIA", "NForce2", enable_flash_nvidia_nforce2},
Michael Karcher5f31ebe2010-06-12 23:07:26 +00001416 {0x10de, 0x00e0, OK, "NVIDIA", "NForce3", enable_flash_nvidia_nforce2},
Uwe Hermanneac10162008-03-13 18:52:51 +00001417 /* Slave, should not be here, to fix known bug for A01. */
Uwe Hermannb0039912009-05-07 13:24:49 +00001418 {0x10de, 0x00d3, OK, "NVIDIA", "CK804", enable_flash_ck804},
1419 {0x10de, 0x0260, NT, "NVIDIA", "MCP51", enable_flash_ck804},
1420 {0x10de, 0x0261, NT, "NVIDIA", "MCP51", enable_flash_ck804},
1421 {0x10de, 0x0262, NT, "NVIDIA", "MCP51", enable_flash_ck804},
1422 {0x10de, 0x0263, NT, "NVIDIA", "MCP51", enable_flash_ck804},
1423 {0x10de, 0x0360, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* M57SLI*/
Carl-Daniel Hailfinger33d7b6a2010-05-22 07:27:16 +00001424 /* 10de:0361 is present in Tyan S2915 OEM systems, but not connected to
1425 * the flash chip. Instead, 10de:0364 is connected to the flash chip.
1426 * Until we have PCI device class matching or some fallback mechanism,
1427 * this is needed to get flashrom working on Tyan S2915 and maybe other
1428 * dual-MCP55 boards.
1429 */
1430#if 0
1431 {0x10de, 0x0361, NT, "NVIDIA", "MCP55", enable_flash_mcp55}, /* LPC */
1432#endif
Uwe Hermannb0039912009-05-07 13:24:49 +00001433 {0x10de, 0x0362, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* LPC */
1434 {0x10de, 0x0363, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* LPC */
1435 {0x10de, 0x0364, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* LPC */
1436 {0x10de, 0x0365, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* LPC */
1437 {0x10de, 0x0366, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* LPC */
1438 {0x10de, 0x0367, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* Pro */
Carl-Daniel Hailfingerce5fad02010-02-18 12:24:38 +00001439 {0x10de, 0x03e0, NT, "NVIDIA", "MCP61", enable_flash_mcp67},
1440 {0x10de, 0x03e1, NT, "NVIDIA", "MCP61", enable_flash_mcp67},
1441 {0x10de, 0x03e2, NT, "NVIDIA", "MCP61", enable_flash_mcp67},
1442 {0x10de, 0x03e3, NT, "NVIDIA", "MCP61", enable_flash_mcp67},
Carl-Daniel Hailfingerea3b1b42010-02-13 23:41:01 +00001443 {0x10de, 0x0440, NT, "NVIDIA", "MCP65", enable_flash_mcp7x},
1444 {0x10de, 0x0441, NT, "NVIDIA", "MCP65", enable_flash_mcp7x},
1445 {0x10de, 0x0442, NT, "NVIDIA", "MCP65", enable_flash_mcp7x},
1446 {0x10de, 0x0443, NT, "NVIDIA", "MCP65", enable_flash_mcp7x},
1447 {0x10de, 0x0548, OK, "NVIDIA", "MCP67", enable_flash_mcp67},
1448 {0x10de, 0x075c, NT, "NVIDIA", "MCP78S", enable_flash_mcp7x},
1449 {0x10de, 0x075d, NT, "NVIDIA", "MCP78S", enable_flash_mcp7x},
1450 {0x10de, 0x07d7, NT, "NVIDIA", "MCP73", enable_flash_mcp7x},
1451 {0x10de, 0x0aac, NT, "NVIDIA", "MCP79", enable_flash_mcp7x},
1452 {0x10de, 0x0aad, NT, "NVIDIA", "MCP79", enable_flash_mcp7x},
1453 {0x10de, 0x0aae, NT, "NVIDIA", "MCP79", enable_flash_mcp7x},
1454 {0x10de, 0x0aaf, NT, "NVIDIA", "MCP79", enable_flash_mcp7x},
Carl-Daniel Hailfinger6a0269e2009-11-15 17:20:21 +00001455 {0x1039, 0x0496, NT, "SiS", "85C496+497", enable_flash_sis85c496},
1456 {0x1039, 0x0406, NT, "SiS", "501/5101/5501", enable_flash_sis501},
1457 {0x1039, 0x5511, NT, "SiS", "5511", enable_flash_sis5511},
Luc Verhaegen9cce2f52010-01-10 15:01:08 +00001458 {0x1039, 0x5596, NT, "SiS", "5596", enable_flash_sis5511},
Carl-Daniel Hailfinger6a0269e2009-11-15 17:20:21 +00001459 {0x1039, 0x5571, NT, "SiS", "5571", enable_flash_sis530},
1460 {0x1039, 0x5591, NT, "SiS", "5591/5592", enable_flash_sis530},
1461 {0x1039, 0x5597, NT, "SiS", "5597/5598/5581/5120", enable_flash_sis530},
1462 {0x1039, 0x0530, NT, "SiS", "530", enable_flash_sis530},
1463 {0x1039, 0x5600, NT, "SiS", "600", enable_flash_sis530},
1464 {0x1039, 0x0620, NT, "SiS", "620", enable_flash_sis530},
1465 {0x1039, 0x0540, NT, "SiS", "540", enable_flash_sis540},
Luc Verhaegen9892ca62009-12-09 07:43:13 +00001466 {0x1039, 0x0630, NT, "SiS", "630", enable_flash_sis540},
1467 {0x1039, 0x0635, NT, "SiS", "635", enable_flash_sis540},
1468 {0x1039, 0x0640, NT, "SiS", "640", enable_flash_sis540},
1469 {0x1039, 0x0645, NT, "SiS", "645", enable_flash_sis540},
1470 {0x1039, 0x0646, NT, "SiS", "645DX", enable_flash_sis540},
1471 {0x1039, 0x0648, NT, "SiS", "648", enable_flash_sis540},
1472 {0x1039, 0x0650, NT, "SiS", "650", enable_flash_sis540},
1473 {0x1039, 0x0651, NT, "SiS", "651", enable_flash_sis540},
1474 {0x1039, 0x0655, NT, "SiS", "655", enable_flash_sis540},
1475 {0x1039, 0x0730, NT, "SiS", "730", enable_flash_sis540},
1476 {0x1039, 0x0733, NT, "SiS", "733", enable_flash_sis540},
1477 {0x1039, 0x0735, OK, "SiS", "735", enable_flash_sis540},
1478 {0x1039, 0x0740, NT, "SiS", "740", enable_flash_sis540},
1479 {0x1039, 0x0745, NT, "SiS", "745", enable_flash_sis540},
1480 {0x1039, 0x0746, NT, "SiS", "746", enable_flash_sis540},
1481 {0x1039, 0x0748, NT, "SiS", "748", enable_flash_sis540},
1482 {0x1039, 0x0755, NT, "SiS", "755", enable_flash_sis540},
Michael Karcher89bed6d2010-06-13 10:16:12 +00001483 /* VIA northbridges */
1484 {0x1106, 0x0585, NT, "VIA", "VT82C585VPX", via_no_byte_merge},
1485 {0x1106, 0x0595, NT, "VIA", "VT82C595", via_no_byte_merge},
1486 {0x1106, 0x0597, NT, "VIA", "VT82C597", via_no_byte_merge},
1487 {0x1106, 0x0691, NT, "VIA", "VT82C69x", via_no_byte_merge}, /* 691, 693a, 694t, 694x checked */
1488 {0x1106, 0x0601, NT, "VIA", "VT8601/VT8601A", via_no_byte_merge},
1489 {0x1106, 0x8601, NT, "VIA", "VT8601T", via_no_byte_merge},
1490 /* VIA southbridges */
Uwe Hermann4179d292009-05-08 17:50:51 +00001491 {0x1106, 0x8324, OK, "VIA", "CX700", enable_flash_vt823x},
1492 {0x1106, 0x8231, NT, "VIA", "VT8231", enable_flash_vt823x},
Mateusz Murawskie6abef02009-06-18 12:42:46 +00001493 {0x1106, 0x3074, NT, "VIA", "VT8233", enable_flash_vt823x},
Raúl Sorianocd8404d2009-12-23 21:29:18 +00001494 {0x1106, 0x3147, OK, "VIA", "VT8233A", enable_flash_vt823x},
Uwe Hermann4179d292009-05-08 17:50:51 +00001495 {0x1106, 0x3177, OK, "VIA", "VT8235", enable_flash_vt823x},
1496 {0x1106, 0x3227, OK, "VIA", "VT8237", enable_flash_vt823x},
1497 {0x1106, 0x3337, OK, "VIA", "VT8237A", enable_flash_vt823x},
1498 {0x1106, 0x3372, OK, "VIA", "VT8237S", enable_flash_vt8237s_spi},
Arjan Koers8dfea832009-06-15 00:03:37 +00001499 {0x1106, 0x8353, OK, "VIA", "VX800", enable_flash_vt8237s_spi},
Uwe Hermann3e0774d2009-09-25 01:05:06 +00001500 {0x1106, 0x0596, OK, "VIA", "VT82C596", enable_flash_amd8111},
Uwe Hermann4179d292009-05-08 17:50:51 +00001501 {0x1106, 0x0586, OK, "VIA", "VT82C586A/B", enable_flash_amd8111},
1502 {0x1106, 0x0686, NT, "VIA", "VT82C686A/B", enable_flash_amd8111},
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +00001503#endif
Uwe Hermann05fab752009-05-16 23:42:17 +00001504 {},
Ollie Lhocbbf1252004-03-17 22:22:08 +00001505};
Ollie Lho761bf1b2004-03-20 16:46:10 +00001506
Uwe Hermanna7e05482007-05-09 10:17:44 +00001507int chipset_flash_enable(void)
Ollie Lhocbbf1252004-03-17 22:22:08 +00001508{
Uwe Hermanna7e05482007-05-09 10:17:44 +00001509 struct pci_dev *dev = 0;
Uwe Hermann372eeb52007-12-04 21:49:06 +00001510 int ret = -2; /* Nothing! */
Uwe Hermanna7e05482007-05-09 10:17:44 +00001511 int i;
Ollie Lhocbbf1252004-03-17 22:22:08 +00001512
Uwe Hermann372eeb52007-12-04 21:49:06 +00001513 /* Now let's try to find the chipset we have... */
Uwe Hermann05fab752009-05-16 23:42:17 +00001514 for (i = 0; chipset_enables[i].vendor_name != NULL; i++) {
1515 dev = pci_dev_find(chipset_enables[i].vendor_id,
1516 chipset_enables[i].device_id);
Michael Karcher89bed6d2010-06-13 10:16:12 +00001517 if (!dev)
1518 continue;
1519 if (ret != -2) {
1520 msg_pinfo("WARNING: unexpected second chipset match: "
1521 "\"%s %s\"\nignoring, please report lspci and "
1522 "board URL to flashrom@flashrom.org!\n",
1523 chipset_enables[i].vendor_name,
1524 chipset_enables[i].device_name);
1525 continue;
1526 }
Sean Nelson316a29f2010-05-07 20:09:04 +00001527 msg_pinfo("Found chipset \"%s %s\", enabling flash write... ",
Uwe Hermann05fab752009-05-16 23:42:17 +00001528 chipset_enables[i].vendor_name,
1529 chipset_enables[i].device_name);
Carl-Daniel Hailfingerf469c272010-05-22 07:31:50 +00001530 msg_pdbg("chipset PCI ID is %04x:%04x, ",
1531 chipset_enables[i].vendor_id,
1532 chipset_enables[i].device_id);
Uwe Hermanna7e05482007-05-09 10:17:44 +00001533
Uwe Hermann05fab752009-05-16 23:42:17 +00001534 ret = chipset_enables[i].doit(dev,
1535 chipset_enables[i].device_name);
Michael Karcher89bed6d2010-06-13 10:16:12 +00001536 if (ret == NOT_DONE_YET) {
1537 ret = -2;
1538 msg_pinfo("OK - searching further chips.\n");
1539 } else if (ret < 0)
Sean Nelson316a29f2010-05-07 20:09:04 +00001540 msg_pinfo("FAILED!\n");
Michael Karcher89bed6d2010-06-13 10:16:12 +00001541 else if(ret == 0)
Sean Nelson316a29f2010-05-07 20:09:04 +00001542 msg_pinfo("OK.\n");
Uwe Hermanna7e05482007-05-09 10:17:44 +00001543 }
Michael Karcher89bed6d2010-06-13 10:16:12 +00001544
Sean Nelson316a29f2010-05-07 20:09:04 +00001545 msg_pinfo("This chipset supports the following protocols: %s.\n",
Uwe Hermann9899cad2009-06-28 21:47:57 +00001546 flashbuses_to_text(buses_supported));
Uwe Hermanna7e05482007-05-09 10:17:44 +00001547
1548 return ret;
Ollie Lhocbbf1252004-03-17 22:22:08 +00001549}