blob: 6a0fc4ff56244ee9f13f9c4204004a5235787434 [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>
33#include <sys/stat.h>
34#include <fcntl.h>
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000035#include "flash.h"
Stefan Reinauer86de2832006-03-31 11:26:55 +000036
FENG yu ningc05a2952008-12-08 18:16:58 +000037extern int ichspi_lock;
38
Uwe Hermann372eeb52007-12-04 21:49:06 +000039static int enable_flash_ali_m1533(struct pci_dev *dev, const char *name)
Luc Verhaegen6b141752007-05-20 16:16:13 +000040{
41 uint8_t tmp;
42
Uwe Hermann372eeb52007-12-04 21:49:06 +000043 /*
44 * ROM Write enable, 0xFFFC0000-0xFFFDFFFF and
45 * 0xFFFE0000-0xFFFFFFFF ROM select enable.
46 */
Luc Verhaegen6b141752007-05-20 16:16:13 +000047 tmp = pci_read_byte(dev, 0x47);
48 tmp |= 0x46;
49 pci_write_byte(dev, 0x47, tmp);
50
51 return 0;
52}
53
Carl-Daniel Hailfinger9f46cfc2009-11-15 17:13:29 +000054static int enable_flash_sis85c496(struct pci_dev *dev, const char *name)
55{
56 uint8_t tmp;
57
58 tmp = pci_read_byte(dev, 0xd0);
59 tmp |= 0xf8;
60 pci_write_byte(dev, 0xd0, tmp);
61
62 return 0;
63}
64
65static int enable_flash_sis_mapping(struct pci_dev *dev, const char *name)
66{
67 uint8_t new, newer;
68
69 /* Extended BIOS enable = 1, Lower BIOS Enable = 1 */
70 /* This is 0xFFF8000~0xFFFF0000 decoding on SiS 540/630. */
71 new = pci_read_byte(dev, 0x40);
72 new &= (~0x04); /* No idea why we clear bit 2. */
73 new |= 0xb; /* 0x3 for some chipsets, bit 7 seems to be don't care. */
74 pci_write_byte(dev, 0x40, new);
75 newer = pci_read_byte(dev, 0x40);
76 if (newer != new) {
77 printf_debug("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name);
78 printf_debug("Stuck at 0x%x\n", newer);
79 return -1;
80 }
81 return 0;
82}
83
84static struct pci_dev *find_southbridge(uint16_t vendor, const char *name)
85{
86 struct pci_dev *sbdev;
87
88 sbdev = pci_dev_find_vendorclass(vendor, 0x0601);
89 if (!sbdev)
90 sbdev = pci_dev_find_vendorclass(vendor, 0x0680);
91 if (!sbdev)
92 sbdev = pci_dev_find_vendorclass(vendor, 0x0000);
93 if (!sbdev)
94 fprintf(stderr, "No southbridge found for %s!\n", name);
95 if (sbdev)
96 printf_debug("Found southbridge %04x:%04x at %02x:%02x:%01x\n",
97 sbdev->vendor_id, sbdev->device_id,
98 sbdev->bus, sbdev->dev, sbdev->func);
99 return sbdev;
100}
101
102static int enable_flash_sis501(struct pci_dev *dev, const char *name)
103{
104 uint8_t tmp;
105 int ret = 0;
106 struct pci_dev *sbdev;
107
108 sbdev = find_southbridge(dev->vendor_id, name);
109 if (!sbdev)
110 return -1;
111
112 ret = enable_flash_sis_mapping(sbdev, name);
113
114 tmp = sio_read(0x22, 0x80);
115 tmp &= (~0x20);
116 tmp |= 0x4;
117 sio_write(0x22, 0x80, tmp);
118
119 tmp = sio_read(0x22, 0x70);
120 tmp &= (~0x20);
121 tmp |= 0x4;
122 sio_write(0x22, 0x70, tmp);
123
124 return ret;
125}
126
127static int enable_flash_sis5511(struct pci_dev *dev, const char *name)
128{
129 uint8_t tmp;
130 int ret = 0;
131 struct pci_dev *sbdev;
132
133 sbdev = find_southbridge(dev->vendor_id, name);
134 if (!sbdev)
135 return -1;
136
137 ret = enable_flash_sis_mapping(sbdev, name);
138
139 tmp = sio_read(0x22, 0x50);
140 tmp &= (~0x20);
141 tmp |= 0x4;
142 sio_write(0x22, 0x50, tmp);
143
144 return ret;
145}
146
147static int enable_flash_sis5596(struct pci_dev *dev, const char *name)
148{
149 int ret;
150
151 ret = enable_flash_sis5511(dev, name);
152
153 /* FIXME: Needs same superio handling as enable_flash_sis630 */
154 return ret;
155}
156
157static int enable_flash_sis530(struct pci_dev *dev, const char *name)
158{
159 uint8_t new, newer;
160 int ret = 0;
161 struct pci_dev *sbdev;
162
163 sbdev = find_southbridge(dev->vendor_id, name);
164 if (!sbdev)
165 return -1;
166
167 ret = enable_flash_sis_mapping(sbdev, name);
168
169 new = pci_read_byte(sbdev, 0x45);
170 new &= (~0x20);
171 new |= 0x4;
172 pci_write_byte(sbdev, 0x45, new);
173 newer = pci_read_byte(dev, 0x45);
174 if (newer != new) {
175 printf_debug("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name);
176 printf_debug("Stuck at 0x%x\n", newer);
177 ret = -1;
178 }
179
180 return ret;
181}
182
183static int enable_flash_sis540(struct pci_dev *dev, const char *name)
184{
185 uint8_t new, newer;
186 int ret = 0;
187 struct pci_dev *sbdev;
188
189 sbdev = find_southbridge(dev->vendor_id, name);
190 if (!sbdev)
191 return -1;
192
193 ret = enable_flash_sis_mapping(sbdev, name);
194
195 new = pci_read_byte(sbdev, 0x45);
196 new &= (~0x80);
197 new |= 0x40;
198 pci_write_byte(sbdev, 0x45, new);
199 newer = pci_read_byte(dev, 0x45);
200 if (newer != new) {
201 printf_debug("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name);
202 printf_debug("Stuck at 0x%x\n", newer);
203 ret = -1;
204 }
205
206 return ret;
207}
208
Uwe Hermann987942d2006-11-07 11:16:21 +0000209/* Datasheet:
210 * - Name: 82371AB PCI-TO-ISA / IDE XCELERATOR (PIIX4)
211 * - URL: http://www.intel.com/design/intarch/datashts/290562.htm
212 * - PDF: http://www.intel.com/design/intarch/datashts/29056201.pdf
213 * - Order Number: 290562-001
214 */
Uwe Hermann372eeb52007-12-04 21:49:06 +0000215static int enable_flash_piix4(struct pci_dev *dev, const char *name)
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000216{
217 uint16_t old, new;
Uwe Hermanna7e05482007-05-09 10:17:44 +0000218 uint16_t xbcs = 0x4e; /* X-Bus Chip Select register. */
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000219
Maciej Pijankaa661e152009-12-08 17:26:24 +0000220 buses_supported = CHIP_BUSTYPE_PARALLEL;
221
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000222 old = pci_read_word(dev, xbcs);
223
224 /* Set bit 9: 1-Meg Extended BIOS Enable (PCI master accesses to
Uwe Hermanna7e05482007-05-09 10:17:44 +0000225 * FFF00000-FFF7FFFF are forwarded to ISA).
Uwe Hermannc556d322008-10-28 11:50:05 +0000226 * Note: This bit is reserved on PIIX/PIIX3/MPIIX.
Uwe Hermanna7e05482007-05-09 10:17:44 +0000227 * Set bit 7: Extended BIOS Enable (PCI master accesses to
228 * FFF80000-FFFDFFFF are forwarded to ISA).
229 * Set bit 6: Lower BIOS Enable (PCI master, or ISA master accesses to
230 * the lower 64-Kbyte BIOS block (E0000-EFFFF) at the top
231 * of 1 Mbyte, or the aliases at the top of 4 Gbyte
232 * (FFFE0000-FFFEFFFF) result in the generation of BIOSCS#.
233 * Note: Accesses to FFFF0000-FFFFFFFF are always forwarded to ISA.
234 * Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable).
235 */
Uwe Hermannc556d322008-10-28 11:50:05 +0000236 if (dev->device_id == 0x122e || dev->device_id == 0x7000
237 || dev->device_id == 0x1234)
238 new = old | 0x00c4; /* PIIX/PIIX3/MPIIX: Bit 9 is reserved. */
Uwe Hermann87203452008-10-26 18:40:42 +0000239 else
240 new = old | 0x02c4;
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000241
242 if (new == old)
243 return 0;
244
245 pci_write_word(dev, xbcs, new);
246
247 if (pci_read_word(dev, xbcs) != new) {
Stefan Reinauer630c79d2009-08-11 12:15:39 +0000248 printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name);
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000249 return -1;
250 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000251
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000252 return 0;
253}
254
Uwe Hermann372eeb52007-12-04 21:49:06 +0000255/*
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000256 * See ie. page 375 of "Intel I/O Controller Hub 7 (ICH7) Family Datasheet"
257 * http://download.intel.com/design/chipsets/datashts/30701303.pdf
Uwe Hermann372eeb52007-12-04 21:49:06 +0000258 */
259static int enable_flash_ich(struct pci_dev *dev, const char *name,
260 int bios_cntl)
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000261{
Ollie Lho184a4042005-11-26 21:55:36 +0000262 uint8_t old, new;
Stefan Reinauereb366472006-09-06 15:48:48 +0000263
Uwe Hermann372eeb52007-12-04 21:49:06 +0000264 /*
265 * Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, but
Uwe Hermanna7e05482007-05-09 10:17:44 +0000266 * just treating it as 8 bit wide seems to work fine in practice.
Stefan Reinauereb366472006-09-06 15:48:48 +0000267 */
Stefan Reinauer86de2832006-03-31 11:26:55 +0000268 old = pci_read_byte(dev, bios_cntl);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000269
Uwe Hermann793bdcd2008-05-22 22:47:04 +0000270 printf_debug("\nBIOS Lock Enable: %sabled, ",
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000271 (old & (1 << 1)) ? "en" : "dis");
272 printf_debug("BIOS Write Enable: %sabled, ",
273 (old & (1 << 0)) ? "en" : "dis");
274 printf_debug("BIOS_CNTL is 0x%x\n", old);
275
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000276 new = old | 1;
277
278 if (new == old)
279 return 0;
280
Stefan Reinauer86de2832006-03-31 11:26:55 +0000281 pci_write_byte(dev, bios_cntl, new);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000282
Stefan Reinauer86de2832006-03-31 11:26:55 +0000283 if (pci_read_byte(dev, bios_cntl) != new) {
Stefan Reinauer630c79d2009-08-11 12:15:39 +0000284 printf_debug("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 +0000285 return -1;
286 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000287
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000288 return 0;
289}
290
Uwe Hermann372eeb52007-12-04 21:49:06 +0000291static int enable_flash_ich_4e(struct pci_dev *dev, const char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000292{
Carl-Daniel Hailfinger4c7ea382009-08-10 23:30:45 +0000293 /*
294 * Note: ICH5 has registers similar to FWH_SEL1, FWH_SEL2 and
295 * FWH_DEC_EN1, but they are called FB_SEL1, FB_SEL2, FB_DEC_EN1 and
296 * FB_DEC_EN2.
297 */
Stefan Reinauereb366472006-09-06 15:48:48 +0000298 return enable_flash_ich(dev, name, 0x4e);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000299}
300
Uwe Hermann372eeb52007-12-04 21:49:06 +0000301static int enable_flash_ich_dc(struct pci_dev *dev, const char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000302{
Carl-Daniel Hailfinger4c7ea382009-08-10 23:30:45 +0000303 uint32_t fwh_conf;
304 int i;
Carl-Daniel Hailfinger44498682009-08-13 23:23:37 +0000305 char *idsel = NULL;
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000306 int tmp;
307 int max_decode_fwh_idsel = 0;
308 int max_decode_fwh_decode = 0;
309 int contiguous = 1;
Carl-Daniel Hailfinger4c7ea382009-08-10 23:30:45 +0000310
Carl-Daniel Hailfinger44498682009-08-13 23:23:37 +0000311 if (programmer_param)
312 idsel = strstr(programmer_param, "fwh_idsel=");
313
314 if (idsel) {
315 idsel += strlen("fwh_idsel=");
316 fwh_conf = (uint32_t)strtoul(idsel, NULL, 0);
317
318 /* FIXME: Need to undo this on shutdown. */
319 printf("\nSetting IDSEL=0x%x for top 16 MB", fwh_conf);
320 pci_write_long(dev, 0xd0, fwh_conf);
321 pci_write_word(dev, 0xd4, fwh_conf);
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000322 /* FIXME: Decode settings are not changed. */
Carl-Daniel Hailfinger44498682009-08-13 23:23:37 +0000323 }
324
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000325 /* Ignore all legacy ranges below 1 MB.
326 * We currently only support flashing the chip which responds to
327 * IDSEL=0. To support IDSEL!=0, flashbase and decode size calculations
328 * have to be adjusted.
329 */
330 /* FWH_SEL1 */
331 fwh_conf = pci_read_long(dev, 0xd0);
332 for (i = 7; i >= 0; i--) {
333 tmp = (fwh_conf >> (i * 4)) & 0xf;
334 printf_debug("\n0x%08x/0x%08x FWH IDSEL: 0x%x",
335 (0x1ff8 + i) * 0x80000,
336 (0x1ff0 + i) * 0x80000,
337 tmp);
338 if ((tmp == 0) && contiguous) {
339 max_decode_fwh_idsel = (8 - i) * 0x80000;
340 } else {
341 contiguous = 0;
342 }
343 }
344 /* FWH_SEL2 */
345 fwh_conf = pci_read_word(dev, 0xd4);
346 for (i = 3; i >= 0; i--) {
347 tmp = (fwh_conf >> (i * 4)) & 0xf;
348 printf_debug("\n0x%08x/0x%08x FWH IDSEL: 0x%x",
349 (0xff4 + i) * 0x100000,
350 (0xff0 + i) * 0x100000,
351 tmp);
352 if ((tmp == 0) && contiguous) {
353 max_decode_fwh_idsel = (8 - i) * 0x100000;
354 } else {
355 contiguous = 0;
356 }
357 }
358 contiguous = 1;
359 /* FWH_DEC_EN1 */
360 fwh_conf = pci_read_word(dev, 0xd8);
361 for (i = 7; i >= 0; i--) {
362 tmp = (fwh_conf >> (i + 0x8)) & 0x1;
363 printf_debug("\n0x%08x/0x%08x FWH decode %sabled",
364 (0x1ff8 + i) * 0x80000,
365 (0x1ff0 + i) * 0x80000,
366 tmp ? "en" : "dis");
Michael Karcher96785392010-01-03 15:09:17 +0000367 if ((tmp == 1) && contiguous) {
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000368 max_decode_fwh_decode = (8 - i) * 0x80000;
369 } else {
370 contiguous = 0;
371 }
372 }
373 for (i = 3; i >= 0; i--) {
374 tmp = (fwh_conf >> i) & 0x1;
375 printf_debug("\n0x%08x/0x%08x FWH decode %sabled",
376 (0xff4 + i) * 0x100000,
377 (0xff0 + i) * 0x100000,
378 tmp ? "en" : "dis");
Michael Karcher96785392010-01-03 15:09:17 +0000379 if ((tmp == 1) && contiguous) {
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000380 max_decode_fwh_decode = (8 - i) * 0x100000;
381 } else {
382 contiguous = 0;
383 }
384 }
385 max_rom_decode.fwh = min(max_decode_fwh_idsel, max_decode_fwh_decode);
386 printf_debug("\nMaximum FWH chip size: 0x%x bytes", max_rom_decode.fwh);
387
388 /* If we're called by enable_flash_ich_dc_spi, it will override
389 * buses_supported anyway.
390 */
391 buses_supported = CHIP_BUSTYPE_FWH;
Stefan Reinauereb366472006-09-06 15:48:48 +0000392 return enable_flash_ich(dev, name, 0xdc);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000393}
394
Adam Jurkowskie4984102009-12-21 15:30:46 +0000395static int enable_flash_poulsbo(struct pci_dev *dev, const char *name)
396{
397 uint16_t old, new;
398 int err;
399
400 if ((err = enable_flash_ich(dev, name, 0xd8)) != 0)
401 return err;
402
403 old = pci_read_byte(dev, 0xd9);
404 printf_debug("BIOS Prefetch Enable: %sabled, ",
405 (old & 1) ? "en" : "dis");
406 new = old & ~1;
407
408 if (new != old)
409 pci_write_byte(dev, 0xd9, new);
410
411 return 0;
412}
413
414
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000415#define ICH_STRAP_RSVD 0x00
416#define ICH_STRAP_SPI 0x01
417#define ICH_STRAP_PCI 0x02
418#define ICH_STRAP_LPC 0x03
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000419
Uwe Hermann394131e2008-10-18 21:14:13 +0000420static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name)
421{
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000422 uint32_t mmio_base;
423
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000424 /* Do we really need no write enable? */
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000425 mmio_base = (pci_read_long(dev, 0xbc)) << 8;
426 printf_debug("MMIO base at = 0x%x\n", mmio_base);
Stefan Reinauer0593f212009-01-26 01:10:48 +0000427 spibar = physmap("VT8237S MMIO registers", mmio_base, 0x70);
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000428
Uwe Hermann394131e2008-10-18 21:14:13 +0000429 printf_debug("0x6c: 0x%04x (CLOCK/DEBUG)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000430 mmio_readw(spibar + 0x6c));
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000431
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000432 /* Not sure if it speaks all these bus protocols. */
433 buses_supported = CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000434 spi_controller = SPI_CONTROLLER_VIA;
Rudolf Marek0c2029f2009-02-01 18:40:50 +0000435 ich_init_opcodes();
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000436
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000437 return 0;
438}
439
Uwe Hermann394131e2008-10-18 21:14:13 +0000440static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name,
441 int ich_generation)
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000442{
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000443 int ret, i;
Stefan Reinauera9424d52008-06-27 16:28:34 +0000444 uint8_t old, new, bbs, buc;
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000445 uint16_t spibar_offset, tmp2;
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000446 uint32_t tmp, gcs;
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000447 void *rcrb;
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000448 //TODO: These names are incorrect for EP80579. For that, the solution would look like the commented line
449 //static const char *straps_names[] = {"SPI", "reserved", "reserved", "LPC" };
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000450 static const char *straps_names[] = { "reserved", "SPI", "PCI", "LPC" };
Uwe Hermann394131e2008-10-18 21:14:13 +0000451
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000452 /* Enable Flash Writes */
453 ret = enable_flash_ich_dc(dev, name);
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000454
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000455 /* Get physical address of Root Complex Register Block */
456 tmp = pci_read_long(dev, 0xf0) & 0xffffc000;
Stefan Reinauera9424d52008-06-27 16:28:34 +0000457 printf_debug("\nRoot Complex Register Block address = 0x%x\n", tmp);
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000458
459 /* Map RCBA to virtual memory */
Stefan Reinauer0593f212009-01-26 01:10:48 +0000460 rcrb = physmap("ICH RCRB", tmp, 0x4000);
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000461
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000462 gcs = mmio_readl(rcrb + 0x3410);
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000463 printf_debug("GCS = 0x%x: ", gcs);
464 printf_debug("BIOS Interface Lock-Down: %sabled, ",
465 (gcs & 0x1) ? "en" : "dis");
466 bbs = (gcs >> 10) & 0x3;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000467 printf_debug("BOOT BIOS Straps: 0x%x (%s)\n", bbs, straps_names[bbs]);
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000468
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000469 buc = mmio_readb(rcrb + 0x3414);
Uwe Hermann394131e2008-10-18 21:14:13 +0000470 printf_debug("Top Swap : %s\n",
471 (buc & 1) ? "enabled (A16 inverted)" : "not enabled");
Stefan Reinauera9424d52008-06-27 16:28:34 +0000472
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000473 /* It seems the ICH7 does not support SPI and LPC chips at the same
474 * time. At least not with our current code. So we prevent searching
475 * on ICH7 when the southbridge is strapped to LPC
476 */
477
478 if (ich_generation == 7 && bbs == ICH_STRAP_LPC) {
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000479 buses_supported = CHIP_BUSTYPE_FWH;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000480 /* No further SPI initialization required */
481 return ret;
482 }
483
484 switch (ich_generation) {
485 case 7:
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000486 buses_supported = CHIP_BUSTYPE_SPI;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000487 spi_controller = SPI_CONTROLLER_ICH7;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000488 spibar_offset = 0x3020;
489 break;
490 case 8:
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000491 buses_supported = CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000492 spi_controller = SPI_CONTROLLER_ICH9;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000493 spibar_offset = 0x3020;
494 break;
495 case 9:
Carl-Daniel Hailfinger28ec74b2008-10-10 20:54:41 +0000496 case 10:
Uwe Hermann394131e2008-10-18 21:14:13 +0000497 default: /* Future version might behave the same */
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000498 buses_supported = CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000499 spi_controller = SPI_CONTROLLER_ICH9;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000500 spibar_offset = 0x3800;
501 break;
502 }
503
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000504 /* SPIBAR is at RCRB+0x3020 for ICH[78] and RCRB+0x3800 for ICH9. */
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000505 printf_debug("SPIBAR = 0x%x + 0x%04x\n", tmp, spibar_offset);
Stefan Reinauera9424d52008-06-27 16:28:34 +0000506
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000507 /* Assign Virtual Address */
Uwe Hermann394131e2008-10-18 21:14:13 +0000508 spibar = rcrb + spibar_offset;
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000509
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000510 switch (spi_controller) {
511 case SPI_CONTROLLER_ICH7:
Uwe Hermann394131e2008-10-18 21:14:13 +0000512 printf_debug("0x00: 0x%04x (SPIS)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000513 mmio_readw(spibar + 0));
Uwe Hermann394131e2008-10-18 21:14:13 +0000514 printf_debug("0x02: 0x%04x (SPIC)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000515 mmio_readw(spibar + 2));
Uwe Hermann394131e2008-10-18 21:14:13 +0000516 printf_debug("0x04: 0x%08x (SPIA)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000517 mmio_readl(spibar + 4));
Uwe Hermann394131e2008-10-18 21:14:13 +0000518 for (i = 0; i < 8; i++) {
Stefan Reinauera9424d52008-06-27 16:28:34 +0000519 int offs;
520 offs = 8 + (i * 8);
Uwe Hermann394131e2008-10-18 21:14:13 +0000521 printf_debug("0x%02x: 0x%08x (SPID%d)\n", offs,
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000522 mmio_readl(spibar + offs), i);
Uwe Hermann394131e2008-10-18 21:14:13 +0000523 printf_debug("0x%02x: 0x%08x (SPID%d+4)\n", offs + 4,
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000524 mmio_readl(spibar + offs + 4), i);
Stefan Reinauera9424d52008-06-27 16:28:34 +0000525 }
Uwe Hermann394131e2008-10-18 21:14:13 +0000526 printf_debug("0x50: 0x%08x (BBAR)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000527 mmio_readl(spibar + 0x50));
Uwe Hermann394131e2008-10-18 21:14:13 +0000528 printf_debug("0x54: 0x%04x (PREOP)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000529 mmio_readw(spibar + 0x54));
Uwe Hermann394131e2008-10-18 21:14:13 +0000530 printf_debug("0x56: 0x%04x (OPTYPE)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000531 mmio_readw(spibar + 0x56));
Uwe Hermann394131e2008-10-18 21:14:13 +0000532 printf_debug("0x58: 0x%08x (OPMENU)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000533 mmio_readl(spibar + 0x58));
Uwe Hermann394131e2008-10-18 21:14:13 +0000534 printf_debug("0x5c: 0x%08x (OPMENU+4)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000535 mmio_readl(spibar + 0x5c));
Uwe Hermann394131e2008-10-18 21:14:13 +0000536 for (i = 0; i < 4; i++) {
Stefan Reinauera9424d52008-06-27 16:28:34 +0000537 int offs;
538 offs = 0x60 + (i * 4);
Uwe Hermann394131e2008-10-18 21:14:13 +0000539 printf_debug("0x%02x: 0x%08x (PBR%d)\n", offs,
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000540 mmio_readl(spibar + offs), i);
Stefan Reinauera9424d52008-06-27 16:28:34 +0000541 }
542 printf_debug("\n");
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000543 if (mmio_readw(spibar) & (1 << 15)) {
Stefan Reinauera9424d52008-06-27 16:28:34 +0000544 printf("WARNING: SPI Configuration Lockdown activated.\n");
FENG yu ningc05a2952008-12-08 18:16:58 +0000545 ichspi_lock = 1;
Stefan Reinauera9424d52008-06-27 16:28:34 +0000546 }
FENG yu ningf041e9b2008-12-15 02:32:11 +0000547 ich_init_opcodes();
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000548 break;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000549 case SPI_CONTROLLER_ICH9:
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000550 tmp2 = mmio_readw(spibar + 4);
FENG yu ning37179b82009-01-18 06:39:32 +0000551 printf_debug("0x04: 0x%04x (HSFS)\n", tmp2);
552 printf_debug("FLOCKDN %i, ", (tmp2 >> 15 & 1));
553 printf_debug("FDV %i, ", (tmp2 >> 14) & 1);
554 printf_debug("FDOPSS %i, ", (tmp2 >> 13) & 1);
555 printf_debug("SCIP %i, ", (tmp2 >> 5) & 1);
556 printf_debug("BERASE %i, ", (tmp2 >> 3) & 3);
557 printf_debug("AEL %i, ", (tmp2 >> 2) & 1);
558 printf_debug("FCERR %i, ", (tmp2 >> 1) & 1);
559 printf_debug("FDONE %i\n", (tmp2 >> 0) & 1);
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000560
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000561 tmp = mmio_readl(spibar + 0x50);
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000562 printf_debug("0x50: 0x%08x (FRAP)\n", tmp);
563 printf_debug("BMWAG %i, ", (tmp >> 24) & 0xff);
564 printf_debug("BMRAG %i, ", (tmp >> 16) & 0xff);
565 printf_debug("BRWA %i, ", (tmp >> 8) & 0xff);
566 printf_debug("BRRA %i\n", (tmp >> 0) & 0xff);
567
568 printf_debug("0x54: 0x%08x (FREG0)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000569 mmio_readl(spibar + 0x54));
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000570 printf_debug("0x58: 0x%08x (FREG1)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000571 mmio_readl(spibar + 0x58));
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000572 printf_debug("0x5C: 0x%08x (FREG2)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000573 mmio_readl(spibar + 0x5C));
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000574 printf_debug("0x60: 0x%08x (FREG3)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000575 mmio_readl(spibar + 0x60));
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000576 printf_debug("0x64: 0x%08x (FREG4)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000577 mmio_readl(spibar + 0x64));
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000578 printf_debug("0x74: 0x%08x (PR0)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000579 mmio_readl(spibar + 0x74));
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000580 printf_debug("0x78: 0x%08x (PR1)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000581 mmio_readl(spibar + 0x78));
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000582 printf_debug("0x7C: 0x%08x (PR2)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000583 mmio_readl(spibar + 0x7C));
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000584 printf_debug("0x80: 0x%08x (PR3)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000585 mmio_readl(spibar + 0x80));
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000586 printf_debug("0x84: 0x%08x (PR4)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000587 mmio_readl(spibar + 0x84));
FENG yu ning37179b82009-01-18 06:39:32 +0000588 printf_debug("0x90: 0x%08x (SSFS, SSFC)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000589 mmio_readl(spibar + 0x90));
FENG yu ning37179b82009-01-18 06:39:32 +0000590 printf_debug("0x94: 0x%04x (PREOP)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000591 mmio_readw(spibar + 0x94));
FENG yu ning37179b82009-01-18 06:39:32 +0000592 printf_debug("0x96: 0x%04x (OPTYPE)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000593 mmio_readw(spibar + 0x96));
FENG yu ning37179b82009-01-18 06:39:32 +0000594 printf_debug("0x98: 0x%08x (OPMENU)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000595 mmio_readl(spibar + 0x98));
FENG yu ning37179b82009-01-18 06:39:32 +0000596 printf_debug("0x9C: 0x%08x (OPMENU+4)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000597 mmio_readl(spibar + 0x9C));
FENG yu ning37179b82009-01-18 06:39:32 +0000598 printf_debug("0xA0: 0x%08x (BBAR)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000599 mmio_readl(spibar + 0xA0));
Carl-Daniel Hailfingerd3b0e392008-11-03 00:20:22 +0000600 printf_debug("0xB0: 0x%08x (FDOC)\n",
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000601 mmio_readl(spibar + 0xB0));
FENG yu ning37179b82009-01-18 06:39:32 +0000602 if (tmp2 & (1 << 15)) {
603 printf("WARNING: SPI Configuration Lockdown activated.\n");
604 ichspi_lock = 1;
605 }
Peter Stugee8a3e4c2008-12-22 14:12:08 +0000606 ich_init_opcodes();
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000607 break;
608 default:
609 /* Nothing */
610 break;
Stefan Reinauera9424d52008-06-27 16:28:34 +0000611 }
612
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000613 old = pci_read_byte(dev, 0xdc);
614 printf_debug("SPI Read Configuration: ");
615 new = (old >> 2) & 0x3;
616 switch (new) {
617 case 0:
618 case 1:
619 case 2:
620 printf_debug("prefetching %sabled, caching %sabled, ",
Uwe Hermann394131e2008-10-18 21:14:13 +0000621 (new & 0x2) ? "en" : "dis",
622 (new & 0x1) ? "dis" : "en");
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000623 break;
624 default:
625 printf_debug("invalid prefetching/caching settings, ");
626 break;
627 }
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000628
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000629 return ret;
630}
Stefan Reinauera9424d52008-06-27 16:28:34 +0000631
Carl-Daniel Hailfinger1b18b3c2008-05-16 14:39:39 +0000632static int enable_flash_ich7(struct pci_dev *dev, const char *name)
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000633{
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000634 return enable_flash_ich_dc_spi(dev, name, 7);
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000635}
636
Carl-Daniel Hailfinger1b18b3c2008-05-16 14:39:39 +0000637static int enable_flash_ich8(struct pci_dev *dev, const char *name)
638{
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000639 return enable_flash_ich_dc_spi(dev, name, 8);
Carl-Daniel Hailfinger1b18b3c2008-05-16 14:39:39 +0000640}
641
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000642static int enable_flash_ich9(struct pci_dev *dev, const char *name)
643{
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000644 return enable_flash_ich_dc_spi(dev, name, 9);
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000645}
646
Carl-Daniel Hailfinger28ec74b2008-10-10 20:54:41 +0000647static int enable_flash_ich10(struct pci_dev *dev, const char *name)
648{
649 return enable_flash_ich_dc_spi(dev, name, 10);
650}
651
Uwe Hermann372eeb52007-12-04 21:49:06 +0000652static int enable_flash_vt823x(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000653{
Ollie Lho184a4042005-11-26 21:55:36 +0000654 uint8_t val;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000655
Uwe Hermann394131e2008-10-18 21:14:13 +0000656 /* enable ROM decode range (1MB) FFC00000 - FFFFFFFF */
Bari Ari9477c4e2008-04-29 13:46:38 +0000657 pci_write_byte(dev, 0x41, 0x7f);
658
Uwe Hermannffec5f32007-08-23 16:08:21 +0000659 /* ROM write enable */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000660 val = pci_read_byte(dev, 0x40);
661 val |= 0x10;
662 pci_write_byte(dev, 0x40, val);
663
664 if (pci_read_byte(dev, 0x40) != val) {
Stefan Reinauer630c79d2009-08-11 12:15:39 +0000665 printf("\nWARNING: Failed to enable flash write on \"%s\"\n",
Uwe Hermanna7e05482007-05-09 10:17:44 +0000666 name);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000667 return -1;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000668 }
Luc Verhaegen6382b442007-03-02 22:16:38 +0000669
Luc Verhaegen73d21192009-12-23 00:54:26 +0000670 if (dev->device_id == 0x3227) { /* VT8237R */
671 /* All memory cycles, not just ROM ones, go to LPC. */
672 val = pci_read_byte(dev, 0x59);
673 val &= ~0x80;
674 pci_write_byte(dev, 0x59, val);
675 }
676
Uwe Hermanna7e05482007-05-09 10:17:44 +0000677 return 0;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000678}
679
Uwe Hermann372eeb52007-12-04 21:49:06 +0000680static int enable_flash_cs5530(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000681{
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000682 uint8_t reg8;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000683
Uwe Hermann394131e2008-10-18 21:14:13 +0000684#define DECODE_CONTROL_REG2 0x5b /* F0 index 0x5b */
685#define ROM_AT_LOGIC_CONTROL_REG 0x52 /* F0 index 0x52 */
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000686#define CS5530_RESET_CONTROL_REG 0x44 /* F0 index 0x44 */
687#define CS5530_USB_SHADOW_REG 0x43 /* F0 index 0x43 */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000688
Uwe Hermann394131e2008-10-18 21:14:13 +0000689#define LOWER_ROM_ADDRESS_RANGE (1 << 0)
690#define ROM_WRITE_ENABLE (1 << 1)
691#define UPPER_ROM_ADDRESS_RANGE (1 << 2)
692#define BIOS_ROM_POSITIVE_DECODE (1 << 5)
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000693#define CS5530_ISA_MASTER (1 << 7)
694#define CS5530_ENABLE_SA2320 (1 << 2)
695#define CS5530_ENABLE_SA20 (1 << 6)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000696
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000697 buses_supported = CHIP_BUSTYPE_PARALLEL;
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000698 /* Decode 0x000E0000-0x000FFFFF (128 KB), not just 64 KB, and
699 * decode 0xFF000000-0xFFFFFFFF (16 MB), not just 256 KB.
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000700 * FIXME: Should we really touch the low mapping below 1 MB? Flashrom
701 * ignores that region completely.
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000702 * Make the configured ROM areas writable.
703 */
704 reg8 = pci_read_byte(dev, ROM_AT_LOGIC_CONTROL_REG);
705 reg8 |= LOWER_ROM_ADDRESS_RANGE;
706 reg8 |= UPPER_ROM_ADDRESS_RANGE;
707 reg8 |= ROM_WRITE_ENABLE;
708 pci_write_byte(dev, ROM_AT_LOGIC_CONTROL_REG, reg8);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000709
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000710 /* Set positive decode on ROM. */
711 reg8 = pci_read_byte(dev, DECODE_CONTROL_REG2);
712 reg8 |= BIOS_ROM_POSITIVE_DECODE;
713 pci_write_byte(dev, DECODE_CONTROL_REG2, reg8);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000714
Carl-Daniel Hailfinger2a9e2452009-12-17 15:20:01 +0000715 reg8 = pci_read_byte(dev, CS5530_RESET_CONTROL_REG);
716 if (reg8 & CS5530_ISA_MASTER) {
717 /* We have A0-A23 available. */
718 max_rom_decode.parallel = 16 * 1024 * 1024;
719 } else {
720 reg8 = pci_read_byte(dev, CS5530_USB_SHADOW_REG);
721 if (reg8 & CS5530_ENABLE_SA2320) {
722 /* We have A0-19, A20-A23 available. */
723 max_rom_decode.parallel = 16 * 1024 * 1024;
724 } else if (reg8 & CS5530_ENABLE_SA20) {
725 /* We have A0-19, A20 available. */
726 max_rom_decode.parallel = 2 * 1024 * 1024;
727 } else {
728 /* A20 and above are not active. */
729 max_rom_decode.parallel = 1024 * 1024;
730 }
731 }
732
Ollie Lhocbbf1252004-03-17 22:22:08 +0000733 return 0;
734}
735
Mart Raudseppe1344da2008-02-08 10:10:57 +0000736/**
737 * Geode systems write protect the BIOS via RCONFs (cache settings similar
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000738 * to MTRRs). To unlock, change MSR 0x1808 top byte to 0x22.
Mart Raudseppe1344da2008-02-08 10:10:57 +0000739 *
740 * Geode systems also write protect the NOR flash chip itself via MSR_NORF_CTL.
741 * To enable write to NOR Boot flash for the benefit of systems that have such
742 * a setup, raise MSR 0x51400018 WE_CS3 (write enable Boot Flash Chip Select).
Mart Raudseppe1344da2008-02-08 10:10:57 +0000743 */
Uwe Hermann372eeb52007-12-04 21:49:06 +0000744static int enable_flash_cs5536(struct pci_dev *dev, const char *name)
Lane Brooksd54958a2007-11-13 16:45:22 +0000745{
Uwe Hermann394131e2008-10-18 21:14:13 +0000746#define MSR_RCONF_DEFAULT 0x1808
747#define MSR_NORF_CTL 0x51400018
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000748
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000749 msr_t msr;
Lane Brooksd54958a2007-11-13 16:45:22 +0000750
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000751 /* Geode only has a single core */
752 if (setup_cpu_msr(0))
Lane Brooksd54958a2007-11-13 16:45:22 +0000753 return -1;
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000754
755 msr = rdmsr(MSR_RCONF_DEFAULT);
756 if ((msr.hi >> 24) != 0x22) {
757 msr.hi &= 0xfbffffff;
758 wrmsr(MSR_RCONF_DEFAULT, msr);
Lane Brooksd54958a2007-11-13 16:45:22 +0000759 }
Mart Raudseppe1344da2008-02-08 10:10:57 +0000760
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000761 msr = rdmsr(MSR_NORF_CTL);
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000762 /* Raise WE_CS3 bit. */
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000763 msr.lo |= 0x08;
764 wrmsr(MSR_NORF_CTL, msr);
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000765
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000766 cleanup_cpu_msr();
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000767
Uwe Hermann394131e2008-10-18 21:14:13 +0000768#undef MSR_RCONF_DEFAULT
769#undef MSR_NORF_CTL
Lane Brooksd54958a2007-11-13 16:45:22 +0000770 return 0;
771}
772
Uwe Hermann372eeb52007-12-04 21:49:06 +0000773static int enable_flash_sc1100(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000774{
Ollie Lho184a4042005-11-26 21:55:36 +0000775 uint8_t new;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000776
Ollie Lhocbbf1252004-03-17 22:22:08 +0000777 pci_write_byte(dev, 0x52, 0xee);
778
779 new = pci_read_byte(dev, 0x52);
780
781 if (new != 0xee) {
Stefan Reinauer630c79d2009-08-11 12:15:39 +0000782 printf_debug("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 +0000783 return -1;
784 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000785
Ollie Lhocbbf1252004-03-17 22:22:08 +0000786 return 0;
787}
788
Uwe Hermann190f8492008-10-25 18:03:50 +0000789/* Works for AMD-8111, VIA VT82C586A/B, VIA VT82C686A/B. */
Uwe Hermann372eeb52007-12-04 21:49:06 +0000790static int enable_flash_amd8111(struct pci_dev *dev, const char *name)
Ollie Lho761bf1b2004-03-20 16:46:10 +0000791{
Ollie Lho184a4042005-11-26 21:55:36 +0000792 uint8_t old, new;
Uwe Hermanna7e05482007-05-09 10:17:44 +0000793
Uwe Hermann372eeb52007-12-04 21:49:06 +0000794 /* Enable decoding at 0xffb00000 to 0xffffffff. */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000795 old = pci_read_byte(dev, 0x43);
Ollie Lhod11f3612004-12-07 17:19:04 +0000796 new = old | 0xC0;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000797 if (new != old) {
798 pci_write_byte(dev, 0x43, new);
799 if (pci_read_byte(dev, 0x43) != new) {
Stefan Reinauer630c79d2009-08-11 12:15:39 +0000800 printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x43, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000801 }
802 }
803
Uwe Hermann190f8492008-10-25 18:03:50 +0000804 /* Enable 'ROM write' bit. */
Ollie Lho761bf1b2004-03-20 16:46:10 +0000805 old = pci_read_byte(dev, 0x40);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000806 new = old | 0x01;
807 if (new == old)
808 return 0;
809 pci_write_byte(dev, 0x40, new);
810
811 if (pci_read_byte(dev, 0x40) != new) {
Stefan Reinauer630c79d2009-08-11 12:15:39 +0000812 printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000813 return -1;
814 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000815
Ollie Lhocbbf1252004-03-17 22:22:08 +0000816 return 0;
817}
818
Marc Jones3af487d2008-10-15 17:50:29 +0000819static int enable_flash_sb600(struct pci_dev *dev, const char *name)
820{
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000821 uint32_t tmp, prot;
Marc Jones3af487d2008-10-15 17:50:29 +0000822 uint8_t reg;
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000823 struct pci_dev *smbus_dev;
824 int has_spi = 1;
Marc Jones3af487d2008-10-15 17:50:29 +0000825
Jason Wanga3f04be2008-11-28 21:36:51 +0000826 /* Clear ROM protect 0-3. */
827 for (reg = 0x50; reg < 0x60; reg += 4) {
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000828 prot = pci_read_long(dev, reg);
829 /* No protection flags for this region?*/
830 if ((prot & 0x3) == 0)
831 continue;
832 printf_debug("SB600 %s%sprotected from %u to %u\n",
833 (prot & 0x1) ? "write " : "",
834 (prot & 0x2) ? "read " : "",
835 (prot & 0xfffffc00),
836 (prot & 0xfffffc00) + ((prot & 0x3ff) << 8));
837 prot &= 0xfffffffc;
838 pci_write_byte(dev, reg, prot);
839 prot = pci_read_long(dev, reg);
Carl-Daniel Hailfinger9bb88ac2009-05-06 13:51:44 +0000840 if (prot & 0x3)
Peter Stuge19997ae2009-05-06 15:05:39 +0000841 printf("SB600 %s%sunprotect failed from %u to %u\n",
Carl-Daniel Hailfinger9bb88ac2009-05-06 13:51:44 +0000842 (prot & 0x1) ? "write " : "",
843 (prot & 0x2) ? "read " : "",
844 (prot & 0xfffffc00),
845 (prot & 0xfffffc00) + ((prot & 0x3ff) << 8));
Jason Wanga3f04be2008-11-28 21:36:51 +0000846 }
847
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000848 /* Read SPI_BaseAddr */
849 tmp = pci_read_long(dev, 0xa0);
Carl-Daniel Hailfingerf8555e22009-07-23 01:36:08 +0000850 tmp &= 0xffffffe0; /* remove bits 4-0 (reserved) */
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000851 printf_debug("SPI base address is at 0x%x\n", tmp);
852
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000853 /* If the BAR has address 0, it is unlikely SPI is used. */
854 if (!tmp)
855 has_spi = 0;
856
Carl-Daniel Hailfingerf8555e22009-07-23 01:36:08 +0000857 if (has_spi) {
858 /* Physical memory has to be mapped at page (4k) boundaries. */
859 sb600_spibar = physmap("SB600 SPI registers", tmp & 0xfffff000,
860 0x1000);
861 /* The low bits of the SPI base address are used as offset into
862 * the mapped page.
863 */
864 sb600_spibar += tmp & 0xfff;
865
866 tmp = pci_read_long(dev, 0xa0);
867 printf_debug("AltSpiCSEnable=%i, SpiRomEnable=%i, "
868 "AbortEnable=%i\n", tmp & 0x1, (tmp & 0x2) >> 1,
869 (tmp & 0x4) >> 2);
870 tmp = (pci_read_byte(dev, 0xba) & 0x4) >> 2;
871 printf_debug("PrefetchEnSPIFromIMC=%i, ", tmp);
872
873 tmp = pci_read_byte(dev, 0xbb);
874 printf_debug("PrefetchEnSPIFromHost=%i, SpiOpEnInLpcMode=%i\n",
875 tmp & 0x1, (tmp & 0x20) >> 5);
876 tmp = mmio_readl(sb600_spibar);
877 printf_debug("SpiArbEnable=%i, SpiAccessMacRomEn=%i, "
878 "SpiHostAccessRomEn=%i, ArbWaitCount=%i, "
879 "SpiBridgeDisable=%i, DropOneClkOnRd=%i\n",
880 (tmp >> 19) & 0x1, (tmp >> 22) & 0x1,
881 (tmp >> 23) & 0x1, (tmp >> 24) & 0x7,
882 (tmp >> 27) & 0x1, (tmp >> 28) & 0x1);
883 }
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000884
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000885 /* Look for the SMBus device. */
886 smbus_dev = pci_dev_find(0x1002, 0x4385);
887
Carl-Daniel Hailfingerf8555e22009-07-23 01:36:08 +0000888 if (has_spi && !smbus_dev) {
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000889 fprintf(stderr, "ERROR: SMBus device not found. Not enabling SPI.\n");
890 has_spi = 0;
Carl-Daniel Hailfingerf8555e22009-07-23 01:36:08 +0000891 }
892 if (has_spi) {
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000893 /* Note about the bit tests below: If a bit is zero, the GPIO is SPI. */
894 /* GPIO11/SPI_DO and GPIO12/SPI_DI status */
895 reg = pci_read_byte(smbus_dev, 0xAB);
896 reg &= 0xC0;
897 printf_debug("GPIO11 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_DO");
898 printf_debug("GPIO12 used for %s\n", (reg & (1 << 7)) ? "GPIO" : "SPI_DI");
899 if (reg != 0x00)
900 has_spi = 0;
901 /* GPIO31/SPI_HOLD and GPIO32/SPI_CS status */
902 reg = pci_read_byte(smbus_dev, 0x83);
903 reg &= 0xC0;
904 printf_debug("GPIO31 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_HOLD");
905 printf_debug("GPIO32 used for %s\n", (reg & (1 << 7)) ? "GPIO" : "SPI_CS");
Carl-Daniel Hailfinger98622512009-05-15 23:36:23 +0000906 /* SPI_HOLD is not used on all boards, filter it out. */
907 if ((reg & 0x80) != 0x00)
Carl-Daniel Hailfingerdbfa0292009-05-10 14:11:07 +0000908 has_spi = 0;
909 /* GPIO47/SPI_CLK status */
910 reg = pci_read_byte(smbus_dev, 0xA7);
911 reg &= 0x40;
912 printf_debug("GPIO47 used for %s\n", (reg & (1 << 6)) ? "GPIO" : "SPI_CLK");
913 if (reg != 0x00)
914 has_spi = 0;
915 }
916
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000917 buses_supported = CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH;
918 if (has_spi) {
919 buses_supported |= CHIP_BUSTYPE_SPI;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000920 spi_controller = SPI_CONTROLLER_SB600;
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000921 }
Jason Wanga3f04be2008-11-28 21:36:51 +0000922
Carl-Daniel Hailfinger98622512009-05-15 23:36:23 +0000923 /* Read ROM strap override register. */
924 OUTB(0x8f, 0xcd6);
925 reg = INB(0xcd7);
926 reg &= 0x0e;
927 printf_debug("ROM strap override is %sactive", (reg & 0x02) ? "" : "not ");
928 if (reg & 0x02) {
929 switch ((reg & 0x0c) >> 2) {
930 case 0x00:
931 printf_debug(": LPC");
932 break;
933 case 0x01:
934 printf_debug(": PCI");
935 break;
936 case 0x02:
937 printf_debug(": FWH");
938 break;
939 case 0x03:
940 printf_debug(": SPI");
941 break;
942 }
943 }
944 printf_debug("\n");
945
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000946 /* Force enable SPI ROM in SB600 PM register.
947 * If we enable SPI ROM here, we have to disable it after we leave.
Zheng Bao284a6002009-05-04 22:33:50 +0000948 * But how can we know which ROM we are going to handle? So we have
949 * to trade off. We only access LPC ROM if we boot via LPC ROM. And
Carl-Daniel Hailfinger41d6bd92009-05-05 22:50:07 +0000950 * only SPI ROM if we boot via SPI ROM. If you want to access SPI on
951 * boards with LPC straps, you have to use the code below.
Zheng Bao284a6002009-05-04 22:33:50 +0000952 */
953 /*
Jason Wanga3f04be2008-11-28 21:36:51 +0000954 OUTB(0x8f, 0xcd6);
955 OUTB(0x0e, 0xcd7);
Zheng Bao284a6002009-05-04 22:33:50 +0000956 */
Marc Jones3af487d2008-10-15 17:50:29 +0000957
958 return 0;
959}
960
Luc Verhaegen90e8e612009-05-26 09:48:28 +0000961static int enable_flash_nvidia_nforce2(struct pci_dev *dev, const char *name)
962{
Uwe Hermanne9d04d42009-06-02 19:54:22 +0000963 uint8_t tmp;
Luc Verhaegen90e8e612009-05-26 09:48:28 +0000964
Uwe Hermanne9d04d42009-06-02 19:54:22 +0000965 pci_write_byte(dev, 0x92, 0);
Luc Verhaegen90e8e612009-05-26 09:48:28 +0000966
Uwe Hermanne9d04d42009-06-02 19:54:22 +0000967 tmp = pci_read_byte(dev, 0x6d);
968 tmp |= 0x01;
969 pci_write_byte(dev, 0x6d, tmp);
Luc Verhaegen90e8e612009-05-26 09:48:28 +0000970
Uwe Hermanne9d04d42009-06-02 19:54:22 +0000971 return 0;
Luc Verhaegen90e8e612009-05-26 09:48:28 +0000972}
973
Uwe Hermann372eeb52007-12-04 21:49:06 +0000974static int enable_flash_ck804(struct pci_dev *dev, const char *name)
Yinghai Lu952dfce2005-07-06 17:13:46 +0000975{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000976 uint8_t old, new;
Yinghai Lu952dfce2005-07-06 17:13:46 +0000977
Uwe Hermanna7e05482007-05-09 10:17:44 +0000978 old = pci_read_byte(dev, 0x88);
979 new = old | 0xc0;
980 if (new != old) {
981 pci_write_byte(dev, 0x88, new);
982 if (pci_read_byte(dev, 0x88) != new) {
Stefan Reinauer630c79d2009-08-11 12:15:39 +0000983 printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x88, new, name);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000984 }
985 }
Yinghai Lu952dfce2005-07-06 17:13:46 +0000986
Uwe Hermanna7e05482007-05-09 10:17:44 +0000987 old = pci_read_byte(dev, 0x6d);
988 new = old | 0x01;
989 if (new == old)
990 return 0;
991 pci_write_byte(dev, 0x6d, new);
992
993 if (pci_read_byte(dev, 0x6d) != new) {
Stefan Reinauer630c79d2009-08-11 12:15:39 +0000994 printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000995 return -1;
996 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000997
Uwe Hermanna7e05482007-05-09 10:17:44 +0000998 return 0;
Yinghai Lu952dfce2005-07-06 17:13:46 +0000999}
1000
Uwe Hermann372eeb52007-12-04 21:49:06 +00001001/* ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80) */
1002static int enable_flash_sb400(struct pci_dev *dev, const char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +00001003{
Uwe Hermanna7e05482007-05-09 10:17:44 +00001004 uint8_t tmp;
Stefan Reinauer86de2832006-03-31 11:26:55 +00001005 struct pci_dev *smbusdev;
1006
Uwe Hermann372eeb52007-12-04 21:49:06 +00001007 /* Look for the SMBus device. */
Carl-Daniel Hailfingerf6e3efb2009-05-06 00:35:31 +00001008 smbusdev = pci_dev_find(0x1002, 0x4372);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +00001009
Uwe Hermanna7e05482007-05-09 10:17:44 +00001010 if (!smbusdev) {
Uwe Hermann372eeb52007-12-04 21:49:06 +00001011 fprintf(stderr, "ERROR: SMBus device not found. Aborting.\n");
Stefan Reinauer86de2832006-03-31 11:26:55 +00001012 exit(1);
1013 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +00001014
Uwe Hermann372eeb52007-12-04 21:49:06 +00001015 /* Enable some SMBus stuff. */
Uwe Hermanna7e05482007-05-09 10:17:44 +00001016 tmp = pci_read_byte(smbusdev, 0x79);
1017 tmp |= 0x01;
Stefan Reinauer86de2832006-03-31 11:26:55 +00001018 pci_write_byte(smbusdev, 0x79, tmp);
1019
Uwe Hermann372eeb52007-12-04 21:49:06 +00001020 /* Change southbridge. */
Uwe Hermanna7e05482007-05-09 10:17:44 +00001021 tmp = pci_read_byte(dev, 0x48);
1022 tmp |= 0x21;
Stefan Reinauer86de2832006-03-31 11:26:55 +00001023 pci_write_byte(dev, 0x48, tmp);
1024
Uwe Hermann372eeb52007-12-04 21:49:06 +00001025 /* Now become a bit silly. */
Andriy Gapon65c1b862008-05-22 13:22:45 +00001026 tmp = INB(0xc6f);
1027 OUTB(tmp, 0xeb);
1028 OUTB(tmp, 0xeb);
Uwe Hermanna7e05482007-05-09 10:17:44 +00001029 tmp |= 0x40;
Andriy Gapon65c1b862008-05-22 13:22:45 +00001030 OUTB(tmp, 0xc6f);
1031 OUTB(tmp, 0xeb);
1032 OUTB(tmp, 0xeb);
Stefan Reinauer86de2832006-03-31 11:26:55 +00001033
1034 return 0;
1035}
1036
Uwe Hermann372eeb52007-12-04 21:49:06 +00001037static int enable_flash_mcp55(struct pci_dev *dev, const char *name)
Yinghai Luca782972007-01-22 20:21:17 +00001038{
Uwe Hermann372eeb52007-12-04 21:49:06 +00001039 uint8_t old, new, byte;
1040 uint16_t word;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +00001041
Uwe Hermann372eeb52007-12-04 21:49:06 +00001042 /* Set the 0-16 MB enable bits. */
Uwe Hermanna7e05482007-05-09 10:17:44 +00001043 byte = pci_read_byte(dev, 0x88);
1044 byte |= 0xff; /* 256K */
1045 pci_write_byte(dev, 0x88, byte);
1046 byte = pci_read_byte(dev, 0x8c);
1047 byte |= 0xff; /* 1M */
1048 pci_write_byte(dev, 0x8c, byte);
1049 word = pci_read_word(dev, 0x90);
Carl-Daniel Hailfingerdca0ab12007-10-17 22:30:07 +00001050 word |= 0x7fff; /* 16M */
Uwe Hermanna7e05482007-05-09 10:17:44 +00001051 pci_write_word(dev, 0x90, word);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +00001052
Uwe Hermanna7e05482007-05-09 10:17:44 +00001053 old = pci_read_byte(dev, 0x6d);
1054 new = old | 0x01;
1055 if (new == old)
1056 return 0;
1057 pci_write_byte(dev, 0x6d, new);
Yinghai Luca782972007-01-22 20:21:17 +00001058
Uwe Hermanna7e05482007-05-09 10:17:44 +00001059 if (pci_read_byte(dev, 0x6d) != new) {
Stefan Reinauer630c79d2009-08-11 12:15:39 +00001060 printf_debug("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name);
Uwe Hermanna7e05482007-05-09 10:17:44 +00001061 return -1;
1062 }
Yinghai Luca782972007-01-22 20:21:17 +00001063
1064 return 0;
Yinghai Luca782972007-01-22 20:21:17 +00001065}
1066
Uwe Hermann372eeb52007-12-04 21:49:06 +00001067static int enable_flash_ht1000(struct pci_dev *dev, const char *name)
Stefan Reinauerc868b9e2007-06-05 10:28:39 +00001068{
Uwe Hermanne823ee02007-06-05 15:02:18 +00001069 uint8_t byte;
Stefan Reinauerc868b9e2007-06-05 10:28:39 +00001070
Uwe Hermanne823ee02007-06-05 15:02:18 +00001071 /* Set the 4MB enable bit. */
Stefan Reinauerc868b9e2007-06-05 10:28:39 +00001072 byte = pci_read_byte(dev, 0x41);
1073 byte |= 0x0e;
1074 pci_write_byte(dev, 0x41, byte);
1075
1076 byte = pci_read_byte(dev, 0x43);
Uwe Hermannffec5f32007-08-23 16:08:21 +00001077 byte |= (1 << 4);
Stefan Reinauerc868b9e2007-06-05 10:28:39 +00001078 pci_write_byte(dev, 0x43, byte);
1079
Stefan Reinauerc868b9e2007-06-05 10:28:39 +00001080 return 0;
1081}
1082
Stefan Reinauer9a6d1762008-12-03 21:24:40 +00001083/**
1084 * Usually on the x86 architectures (and on other PC-like platforms like some
1085 * Alphas or Itanium) the system flash is mapped right below 4G. On the AMD
1086 * Elan SC520 only a small piece of the system flash is mapped there, but the
1087 * complete flash is mapped somewhere below 1G. The position can be determined
1088 * by the BOOTCS PAR register.
1089 */
1090static int get_flashbase_sc520(struct pci_dev *dev, const char *name)
1091{
1092 int i, bootcs_found = 0;
1093 uint32_t parx = 0;
1094 void *mmcr;
1095
1096 /* 1. Map MMCR */
Stefan Reinauer0593f212009-01-26 01:10:48 +00001097 mmcr = physmap("Elan SC520 MMCR", 0xfffef000, getpagesize());
Stefan Reinauer9a6d1762008-12-03 21:24:40 +00001098
1099 /* 2. Scan PAR0 (0x88) - PAR15 (0xc4) for
1100 * BOOTCS region (PARx[31:29] = 100b)e
1101 */
1102 for (i = 0x88; i <= 0xc4; i += 4) {
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +00001103 parx = mmio_readl(mmcr + i);
Stefan Reinauer9a6d1762008-12-03 21:24:40 +00001104 if ((parx >> 29) == 4) {
1105 bootcs_found = 1;
1106 break; /* BOOTCS found */
1107 }
1108 }
1109
1110 /* 3. PARx[25] = 1b --> flashbase[29:16] = PARx[13:0]
1111 * PARx[25] = 0b --> flashbase[29:12] = PARx[17:0]
1112 */
1113 if (bootcs_found) {
1114 if (parx & (1 << 25)) {
1115 parx &= (1 << 14) - 1; /* Mask [13:0] */
1116 flashbase = parx << 16;
1117 } else {
1118 parx &= (1 << 18) - 1; /* Mask [17:0] */
1119 flashbase = parx << 12;
1120 }
1121 } else {
1122 printf("AMD Elan SC520 detected, but no BOOTCS. Assuming flash at 4G\n");
1123 }
1124
1125 /* 4. Clean up */
Carl-Daniel Hailfingerbe726812009-08-09 12:44:08 +00001126 physunmap(mmcr, getpagesize());
Stefan Reinauer9a6d1762008-12-03 21:24:40 +00001127 return 0;
1128}
1129
Uwe Hermann4179d292009-05-08 17:50:51 +00001130/* Please keep this list alphabetically sorted by vendor/device. */
Uwe Hermann05fab752009-05-16 23:42:17 +00001131const struct penable chipset_enables[] = {
Uwe Hermann4179d292009-05-08 17:50:51 +00001132 {0x10B9, 0x1533, OK, "ALi", "M1533", enable_flash_ali_m1533},
1133 {0x1022, 0x7440, OK, "AMD", "AMD-768", enable_flash_amd8111},
1134 {0x1022, 0x7468, OK, "AMD", "AMD8111", enable_flash_amd8111},
1135 {0x1078, 0x0100, OK, "AMD", "CS5530(A)", enable_flash_cs5530},
1136 {0x1022, 0x2080, OK, "AMD", "CS5536", enable_flash_cs5536},
Nils Jacobse715c7b2009-09-23 02:09:23 +00001137 {0x1022, 0x2090, OK, "AMD", "CS5536", enable_flash_cs5536},
Uwe Hermann4179d292009-05-08 17:50:51 +00001138 {0x1022, 0x3000, OK, "AMD", "Elan SC520", get_flashbase_sc520},
1139 {0x1002, 0x438D, OK, "AMD", "SB600", enable_flash_sb600},
Carl-Daniel Hailfinger174962d2009-09-01 22:13:42 +00001140 {0x1002, 0x439d, OK, "AMD", "SB700/SB710/SB750", enable_flash_sb600},
Uwe Hermann4179d292009-05-08 17:50:51 +00001141 {0x100b, 0x0510, NT, "AMD", "SC1100", enable_flash_sc1100},
1142 {0x1002, 0x4377, OK, "ATI", "SB400", enable_flash_sb400},
1143 {0x1166, 0x0205, OK, "Broadcom", "HT-1000", enable_flash_ht1000},
Carl-Daniel Hailfinger797a8342009-11-26 16:51:39 +00001144 {0x8086, 0x3b00, NT, "Intel", "3400 Desktop", enable_flash_ich10},
1145 {0x8086, 0x3b01, NT, "Intel", "3400 Mobile", enable_flash_ich10},
1146 {0x8086, 0x3b0d, NT, "Intel", "3400 Mobile SFF", enable_flash_ich10},
Uwe Hermannb0039912009-05-07 13:24:49 +00001147 {0x8086, 0x7198, OK, "Intel", "440MX", enable_flash_piix4},
Uwe Hermann4179d292009-05-08 17:50:51 +00001148 {0x8086, 0x25a1, OK, "Intel", "6300ESB", enable_flash_ich_4e},
1149 {0x8086, 0x2670, OK, "Intel", "631xESB/632xESB/3100", enable_flash_ich_dc},
1150 {0x8086, 0x5031, OK, "Intel", "EP80579", enable_flash_ich7},
Uwe Hermannb0039912009-05-07 13:24:49 +00001151 {0x8086, 0x2420, OK, "Intel", "ICH0", enable_flash_ich_4e},
Uwe Hermann4179d292009-05-08 17:50:51 +00001152 {0x8086, 0x3a18, OK, "Intel", "ICH10", enable_flash_ich10},
1153 {0x8086, 0x3a1a, OK, "Intel", "ICH10D", enable_flash_ich10},
1154 {0x8086, 0x3a14, OK, "Intel", "ICH10DO", enable_flash_ich10},
1155 {0x8086, 0x3a16, OK, "Intel", "ICH10R", enable_flash_ich10},
Uwe Hermannb0039912009-05-07 13:24:49 +00001156 {0x8086, 0x2440, OK, "Intel", "ICH2", enable_flash_ich_4e},
1157 {0x8086, 0x244c, OK, "Intel", "ICH2-M", enable_flash_ich_4e},
Uwe Hermannb0039912009-05-07 13:24:49 +00001158 {0x8086, 0x248c, OK, "Intel", "ICH3-M", enable_flash_ich_4e},
Uwe Hermann4179d292009-05-08 17:50:51 +00001159 {0x8086, 0x2480, OK, "Intel", "ICH3-S", enable_flash_ich_4e},
Uwe Hermannb0039912009-05-07 13:24:49 +00001160 {0x8086, 0x24c0, OK, "Intel", "ICH4/ICH4-L", enable_flash_ich_4e},
1161 {0x8086, 0x24cc, OK, "Intel", "ICH4-M", enable_flash_ich_4e},
1162 {0x8086, 0x24d0, OK, "Intel", "ICH5/ICH5R", enable_flash_ich_4e},
Uwe Hermannb0039912009-05-07 13:24:49 +00001163 {0x8086, 0x2640, OK, "Intel", "ICH6/ICH6R", enable_flash_ich_dc},
1164 {0x8086, 0x2641, OK, "Intel", "ICH6-M", enable_flash_ich_dc},
Uwe Hermannb0039912009-05-07 13:24:49 +00001165 {0x8086, 0x27b0, OK, "Intel", "ICH7DH", enable_flash_ich7},
1166 {0x8086, 0x27b8, OK, "Intel", "ICH7/ICH7R", enable_flash_ich7},
1167 {0x8086, 0x27b9, OK, "Intel", "ICH7M", enable_flash_ich7},
1168 {0x8086, 0x27bd, OK, "Intel", "ICH7MDH", enable_flash_ich7},
Uwe Hermann4179d292009-05-08 17:50:51 +00001169 {0x8086, 0x2410, OK, "Intel", "ICH", enable_flash_ich_4e},
Uwe Hermannb0039912009-05-07 13:24:49 +00001170 {0x8086, 0x2812, OK, "Intel", "ICH8DH", enable_flash_ich8},
1171 {0x8086, 0x2814, OK, "Intel", "ICH8DO", enable_flash_ich8},
Uwe Hermann4179d292009-05-08 17:50:51 +00001172 {0x8086, 0x2810, OK, "Intel", "ICH8/ICH8R", enable_flash_ich8},
Uwe Hermannb0039912009-05-07 13:24:49 +00001173 {0x8086, 0x2815, OK, "Intel", "ICH8M", enable_flash_ich8},
Uwe Hermann4179d292009-05-08 17:50:51 +00001174 {0x8086, 0x2811, OK, "Intel", "ICH8M-E", enable_flash_ich8},
1175 {0x8086, 0x2918, OK, "Intel", "ICH9", enable_flash_ich9},
Uwe Hermannb0039912009-05-07 13:24:49 +00001176 {0x8086, 0x2912, OK, "Intel", "ICH9DH", enable_flash_ich9},
1177 {0x8086, 0x2914, OK, "Intel", "ICH9DO", enable_flash_ich9},
Uwe Hermannb0039912009-05-07 13:24:49 +00001178 {0x8086, 0x2919, OK, "Intel", "ICH9M", enable_flash_ich9},
Uwe Hermann4179d292009-05-08 17:50:51 +00001179 {0x8086, 0x2917, OK, "Intel", "ICH9M-E", enable_flash_ich9},
1180 {0x8086, 0x2916, OK, "Intel", "ICH9R", enable_flash_ich9},
Carl-Daniel Hailfinger95baaad2009-08-21 17:26:13 +00001181 {0x8086, 0x2910, OK, "Intel", "ICH9 Engineering Sample", enable_flash_ich9},
Uwe Hermann4179d292009-05-08 17:50:51 +00001182 {0x8086, 0x1234, NT, "Intel", "MPIIX", enable_flash_piix4},
1183 {0x8086, 0x7000, OK, "Intel", "PIIX3", enable_flash_piix4},
1184 {0x8086, 0x7110, OK, "Intel", "PIIX4/4E/4M", enable_flash_piix4},
1185 {0x8086, 0x122e, OK, "Intel", "PIIX", enable_flash_piix4},
Adam Jurkowskie4984102009-12-21 15:30:46 +00001186 {0x8086, 0x8119, OK, "Intel", "Poulsbo", enable_flash_poulsbo},
Luc Verhaegenaad7e672009-10-06 11:32:21 +00001187 {0x10de, 0x0030, OK, "NVIDIA", "nForce4/MCP4", enable_flash_nvidia_nforce2},
Uwe Hermannb0039912009-05-07 13:24:49 +00001188 {0x10de, 0x0050, OK, "NVIDIA", "CK804", enable_flash_ck804}, /* LPC */
1189 {0x10de, 0x0051, OK, "NVIDIA", "CK804", enable_flash_ck804}, /* Pro */
Luc Verhaegen90e8e612009-05-26 09:48:28 +00001190 {0x10de, 0x0060, OK, "NVIDIA", "NForce2", enable_flash_nvidia_nforce2},
Uwe Hermanneac10162008-03-13 18:52:51 +00001191 /* Slave, should not be here, to fix known bug for A01. */
Uwe Hermannb0039912009-05-07 13:24:49 +00001192 {0x10de, 0x00d3, OK, "NVIDIA", "CK804", enable_flash_ck804},
1193 {0x10de, 0x0260, NT, "NVIDIA", "MCP51", enable_flash_ck804},
1194 {0x10de, 0x0261, NT, "NVIDIA", "MCP51", enable_flash_ck804},
1195 {0x10de, 0x0262, NT, "NVIDIA", "MCP51", enable_flash_ck804},
1196 {0x10de, 0x0263, NT, "NVIDIA", "MCP51", enable_flash_ck804},
1197 {0x10de, 0x0360, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* M57SLI*/
1198 {0x10de, 0x0361, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* LPC */
1199 {0x10de, 0x0362, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* LPC */
1200 {0x10de, 0x0363, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* LPC */
1201 {0x10de, 0x0364, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* LPC */
1202 {0x10de, 0x0365, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* LPC */
1203 {0x10de, 0x0366, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* LPC */
1204 {0x10de, 0x0367, OK, "NVIDIA", "MCP55", enable_flash_mcp55}, /* Pro */
1205 {0x10de, 0x0548, OK, "NVIDIA", "MCP67", enable_flash_mcp55},
Carl-Daniel Hailfinger6a0269e2009-11-15 17:20:21 +00001206 {0x1039, 0x0496, NT, "SiS", "85C496+497", enable_flash_sis85c496},
1207 {0x1039, 0x0406, NT, "SiS", "501/5101/5501", enable_flash_sis501},
1208 {0x1039, 0x5511, NT, "SiS", "5511", enable_flash_sis5511},
1209 {0x1039, 0x5596, NT, "SiS", "5596", enable_flash_sis5596},
1210 {0x1039, 0x5571, NT, "SiS", "5571", enable_flash_sis530},
1211 {0x1039, 0x5591, NT, "SiS", "5591/5592", enable_flash_sis530},
1212 {0x1039, 0x5597, NT, "SiS", "5597/5598/5581/5120", enable_flash_sis530},
1213 {0x1039, 0x0530, NT, "SiS", "530", enable_flash_sis530},
1214 {0x1039, 0x5600, NT, "SiS", "600", enable_flash_sis530},
1215 {0x1039, 0x0620, NT, "SiS", "620", enable_flash_sis530},
1216 {0x1039, 0x0540, NT, "SiS", "540", enable_flash_sis540},
Luc Verhaegen9892ca62009-12-09 07:43:13 +00001217 {0x1039, 0x0630, NT, "SiS", "630", enable_flash_sis540},
1218 {0x1039, 0x0635, NT, "SiS", "635", enable_flash_sis540},
1219 {0x1039, 0x0640, NT, "SiS", "640", enable_flash_sis540},
1220 {0x1039, 0x0645, NT, "SiS", "645", enable_flash_sis540},
1221 {0x1039, 0x0646, NT, "SiS", "645DX", enable_flash_sis540},
1222 {0x1039, 0x0648, NT, "SiS", "648", enable_flash_sis540},
1223 {0x1039, 0x0650, NT, "SiS", "650", enable_flash_sis540},
1224 {0x1039, 0x0651, NT, "SiS", "651", enable_flash_sis540},
1225 {0x1039, 0x0655, NT, "SiS", "655", enable_flash_sis540},
1226 {0x1039, 0x0730, NT, "SiS", "730", enable_flash_sis540},
1227 {0x1039, 0x0733, NT, "SiS", "733", enable_flash_sis540},
1228 {0x1039, 0x0735, OK, "SiS", "735", enable_flash_sis540},
1229 {0x1039, 0x0740, NT, "SiS", "740", enable_flash_sis540},
1230 {0x1039, 0x0745, NT, "SiS", "745", enable_flash_sis540},
1231 {0x1039, 0x0746, NT, "SiS", "746", enable_flash_sis540},
1232 {0x1039, 0x0748, NT, "SiS", "748", enable_flash_sis540},
1233 {0x1039, 0x0755, NT, "SiS", "755", enable_flash_sis540},
Uwe Hermann4179d292009-05-08 17:50:51 +00001234 {0x1106, 0x8324, OK, "VIA", "CX700", enable_flash_vt823x},
1235 {0x1106, 0x8231, NT, "VIA", "VT8231", enable_flash_vt823x},
Mateusz Murawskie6abef02009-06-18 12:42:46 +00001236 {0x1106, 0x3074, NT, "VIA", "VT8233", enable_flash_vt823x},
Raúl Sorianocd8404d2009-12-23 21:29:18 +00001237 {0x1106, 0x3147, OK, "VIA", "VT8233A", enable_flash_vt823x},
Uwe Hermann4179d292009-05-08 17:50:51 +00001238 {0x1106, 0x3177, OK, "VIA", "VT8235", enable_flash_vt823x},
1239 {0x1106, 0x3227, OK, "VIA", "VT8237", enable_flash_vt823x},
1240 {0x1106, 0x3337, OK, "VIA", "VT8237A", enable_flash_vt823x},
1241 {0x1106, 0x3372, OK, "VIA", "VT8237S", enable_flash_vt8237s_spi},
Arjan Koers8dfea832009-06-15 00:03:37 +00001242 {0x1106, 0x8353, OK, "VIA", "VX800", enable_flash_vt8237s_spi},
Uwe Hermann3e0774d2009-09-25 01:05:06 +00001243 {0x1106, 0x0596, OK, "VIA", "VT82C596", enable_flash_amd8111},
Uwe Hermann4179d292009-05-08 17:50:51 +00001244 {0x1106, 0x0586, OK, "VIA", "VT82C586A/B", enable_flash_amd8111},
1245 {0x1106, 0x0686, NT, "VIA", "VT82C686A/B", enable_flash_amd8111},
Uwe Hermann05fab752009-05-16 23:42:17 +00001246
1247 {},
Ollie Lhocbbf1252004-03-17 22:22:08 +00001248};
Ollie Lho761bf1b2004-03-20 16:46:10 +00001249
Uwe Hermanna7e05482007-05-09 10:17:44 +00001250int chipset_flash_enable(void)
Ollie Lhocbbf1252004-03-17 22:22:08 +00001251{
Uwe Hermanna7e05482007-05-09 10:17:44 +00001252 struct pci_dev *dev = 0;
Uwe Hermann372eeb52007-12-04 21:49:06 +00001253 int ret = -2; /* Nothing! */
Uwe Hermanna7e05482007-05-09 10:17:44 +00001254 int i;
Ollie Lhocbbf1252004-03-17 22:22:08 +00001255
Uwe Hermann372eeb52007-12-04 21:49:06 +00001256 /* Now let's try to find the chipset we have... */
Uwe Hermann05fab752009-05-16 23:42:17 +00001257 for (i = 0; chipset_enables[i].vendor_name != NULL; i++) {
1258 dev = pci_dev_find(chipset_enables[i].vendor_id,
1259 chipset_enables[i].device_id);
Uwe Hermanna7e05482007-05-09 10:17:44 +00001260 if (dev)
1261 break;
Ollie Lhocbbf1252004-03-17 22:22:08 +00001262 }
1263
Uwe Hermanna7e05482007-05-09 10:17:44 +00001264 if (dev) {
Uwe Hermannb0039912009-05-07 13:24:49 +00001265 printf("Found chipset \"%s %s\", enabling flash write... ",
Uwe Hermann05fab752009-05-16 23:42:17 +00001266 chipset_enables[i].vendor_name,
1267 chipset_enables[i].device_name);
Uwe Hermanna7e05482007-05-09 10:17:44 +00001268
Uwe Hermann05fab752009-05-16 23:42:17 +00001269 ret = chipset_enables[i].doit(dev,
1270 chipset_enables[i].device_name);
Uwe Hermanna7e05482007-05-09 10:17:44 +00001271 if (ret)
Uwe Hermanna502dce2007-10-17 23:55:15 +00001272 printf("FAILED!\n");
Uwe Hermanna7e05482007-05-09 10:17:44 +00001273 else
Uwe Hermannac309342007-10-10 17:42:20 +00001274 printf("OK.\n");
Uwe Hermanna7e05482007-05-09 10:17:44 +00001275 }
Uwe Hermann1432a602009-06-28 23:26:37 +00001276 printf("This chipset supports the following protocols: %s.\n",
Uwe Hermann9899cad2009-06-28 21:47:57 +00001277 flashbuses_to_text(buses_supported));
Uwe Hermanna7e05482007-05-09 10:17:44 +00001278
1279 return ret;
Ollie Lhocbbf1252004-03-17 22:22:08 +00001280}