blob: 85d6e8bd67fde433cc880b33795979e099a0a723 [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
5 * Copyright (C) 2005-2007 coresystems GmbH <stepan@coresystems.de>
6 * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de>
Ollie Lho184a4042005-11-26 21:55:36 +00007 *
Uwe Hermannd1107642007-08-29 17:52:32 +00008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
Ollie Lho184a4042005-11-26 21:55:36 +000011 *
Uwe Hermannd1107642007-08-29 17:52:32 +000012 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/*
23 * Contains the chipset specific flash enables.
Ollie Lho184a4042005-11-26 21:55:36 +000024 */
25
Lane Brooksd54958a2007-11-13 16:45:22 +000026#define _LARGEFILE64_SOURCE
27
Ollie Lhocbbf1252004-03-17 22:22:08 +000028#include <stdio.h>
29#include <pci/pci.h>
30#include <stdlib.h>
Lane Brooksd54958a2007-11-13 16:45:22 +000031#include <sys/types.h>
32#include <sys/stat.h>
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +000033#include <sys/mman.h>
Lane Brooksd54958a2007-11-13 16:45:22 +000034#include <fcntl.h>
35#include <unistd.h>
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000036#include "flash.h"
Stefan Reinauer86de2832006-03-31 11:26:55 +000037
Stefan Reinauer2cb94e12008-06-30 23:45:22 +000038/**
39 * flashrom defaults to LPC flash devices. If a known SPI controller is found
40 * and the SPI strappings are set, this will be overwritten by the probing code.
41 *
42 * Eventually, this will become an array when multiple flash support works.
43 */
44
45flashbus_t flashbus = BUS_TYPE_LPC;
46void *spibar = NULL;
47
Uwe Hermann372eeb52007-12-04 21:49:06 +000048static int enable_flash_ali_m1533(struct pci_dev *dev, const char *name)
Luc Verhaegen6b141752007-05-20 16:16:13 +000049{
50 uint8_t tmp;
51
Uwe Hermann372eeb52007-12-04 21:49:06 +000052 /*
53 * ROM Write enable, 0xFFFC0000-0xFFFDFFFF and
54 * 0xFFFE0000-0xFFFFFFFF ROM select enable.
55 */
Luc Verhaegen6b141752007-05-20 16:16:13 +000056 tmp = pci_read_byte(dev, 0x47);
57 tmp |= 0x46;
58 pci_write_byte(dev, 0x47, tmp);
59
60 return 0;
61}
62
Uwe Hermann372eeb52007-12-04 21:49:06 +000063static int enable_flash_sis630(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +000064{
Uwe Hermann372eeb52007-12-04 21:49:06 +000065 uint8_t b;
Ollie Lhocbbf1252004-03-17 22:22:08 +000066
Uwe Hermann372eeb52007-12-04 21:49:06 +000067 /* Enable 0xFFF8000~0xFFFF0000 decoding on SiS 540/630. */
Alex Beregszaszic9fb5d92007-09-11 15:58:18 +000068 b = pci_read_byte(dev, 0x40);
69 pci_write_byte(dev, 0x40, b | 0xb);
Uwe Hermann372eeb52007-12-04 21:49:06 +000070
71 /* Flash write enable on SiS 540/630. */
Alex Beregszaszic9fb5d92007-09-11 15:58:18 +000072 b = pci_read_byte(dev, 0x45);
73 pci_write_byte(dev, 0x45, b | 0x40);
Ollie Lhocbbf1252004-03-17 22:22:08 +000074
Uwe Hermann372eeb52007-12-04 21:49:06 +000075 /* The same thing on SiS 950 Super I/O side... */
76
77 /* First probe for Super I/O on config port 0x2e. */
Andriy Gapon65c1b862008-05-22 13:22:45 +000078 OUTB(0x87, 0x2e);
79 OUTB(0x01, 0x2e);
80 OUTB(0x55, 0x2e);
81 OUTB(0x55, 0x2e);
Ollie Lhocbbf1252004-03-17 22:22:08 +000082
Andriy Gapon65c1b862008-05-22 13:22:45 +000083 if (INB(0x2f) != 0x87) {
Uwe Hermann372eeb52007-12-04 21:49:06 +000084 /* If that failed, try config port 0x4e. */
Andriy Gapon65c1b862008-05-22 13:22:45 +000085 OUTB(0x87, 0x4e);
86 OUTB(0x01, 0x4e);
87 OUTB(0x55, 0x4e);
88 OUTB(0xaa, 0x4e);
89 if (INB(0x4f) != 0x87) {
Ollie Lhocbbf1252004-03-17 22:22:08 +000090 printf("Can not access SiS 950\n");
91 return -1;
92 }
Andriy Gapon65c1b862008-05-22 13:22:45 +000093 OUTB(0x24, 0x4e);
94 b = INB(0x4f) | 0xfc;
95 OUTB(0x24, 0x4e);
96 OUTB(b, 0x4f);
97 OUTB(0x02, 0x4e);
98 OUTB(0x02, 0x4f);
Ollie Lhocbbf1252004-03-17 22:22:08 +000099 }
100
Andriy Gapon65c1b862008-05-22 13:22:45 +0000101 OUTB(0x24, 0x2e);
102 printf("2f is %#x\n", INB(0x2f));
103 b = INB(0x2f) | 0xfc;
104 OUTB(0x24, 0x2e);
105 OUTB(b, 0x2f);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000106
Andriy Gapon65c1b862008-05-22 13:22:45 +0000107 OUTB(0x02, 0x2e);
108 OUTB(0x02, 0x2f);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000109
110 return 0;
111}
112
Uwe Hermann987942d2006-11-07 11:16:21 +0000113/* Datasheet:
114 * - Name: 82371AB PCI-TO-ISA / IDE XCELERATOR (PIIX4)
115 * - URL: http://www.intel.com/design/intarch/datashts/290562.htm
116 * - PDF: http://www.intel.com/design/intarch/datashts/29056201.pdf
117 * - Order Number: 290562-001
118 */
Uwe Hermann372eeb52007-12-04 21:49:06 +0000119static int enable_flash_piix4(struct pci_dev *dev, const char *name)
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000120{
121 uint16_t old, new;
Uwe Hermanna7e05482007-05-09 10:17:44 +0000122 uint16_t xbcs = 0x4e; /* X-Bus Chip Select register. */
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000123
124 old = pci_read_word(dev, xbcs);
125
126 /* Set bit 9: 1-Meg Extended BIOS Enable (PCI master accesses to
Uwe Hermanna7e05482007-05-09 10:17:44 +0000127 * FFF00000-FFF7FFFF are forwarded to ISA).
Uwe Hermann87203452008-10-26 18:40:42 +0000128 * Note: This bit is reserved on PIIX/PIIX3.
Uwe Hermanna7e05482007-05-09 10:17:44 +0000129 * Set bit 7: Extended BIOS Enable (PCI master accesses to
130 * FFF80000-FFFDFFFF are forwarded to ISA).
131 * Set bit 6: Lower BIOS Enable (PCI master, or ISA master accesses to
132 * the lower 64-Kbyte BIOS block (E0000-EFFFF) at the top
133 * of 1 Mbyte, or the aliases at the top of 4 Gbyte
134 * (FFFE0000-FFFEFFFF) result in the generation of BIOSCS#.
135 * Note: Accesses to FFFF0000-FFFFFFFF are always forwarded to ISA.
136 * Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable).
137 */
Uwe Hermann87203452008-10-26 18:40:42 +0000138 if (dev->device_id == 0x122e || dev->device_id == 0x7000)
139 new = old | 0x00c4; /* Bit 9 is reserved on PIIX/PIIX3. */
140 else
141 new = old | 0x02c4;
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000142
143 if (new == old)
144 return 0;
145
146 pci_write_word(dev, xbcs, new);
147
148 if (pci_read_word(dev, xbcs) != new) {
149 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name);
150 return -1;
151 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000152
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000153 return 0;
154}
155
Uwe Hermann372eeb52007-12-04 21:49:06 +0000156/*
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000157 * See ie. page 375 of "Intel I/O Controller Hub 7 (ICH7) Family Datasheet"
158 * http://download.intel.com/design/chipsets/datashts/30701303.pdf
Uwe Hermann372eeb52007-12-04 21:49:06 +0000159 */
160static int enable_flash_ich(struct pci_dev *dev, const char *name,
161 int bios_cntl)
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000162{
Ollie Lho184a4042005-11-26 21:55:36 +0000163 uint8_t old, new;
Stefan Reinauereb366472006-09-06 15:48:48 +0000164
Uwe Hermann372eeb52007-12-04 21:49:06 +0000165 /*
166 * Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, but
Uwe Hermanna7e05482007-05-09 10:17:44 +0000167 * just treating it as 8 bit wide seems to work fine in practice.
Stefan Reinauereb366472006-09-06 15:48:48 +0000168 */
Stefan Reinauer86de2832006-03-31 11:26:55 +0000169 old = pci_read_byte(dev, bios_cntl);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000170
Uwe Hermann793bdcd2008-05-22 22:47:04 +0000171 printf_debug("\nBIOS Lock Enable: %sabled, ",
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000172 (old & (1 << 1)) ? "en" : "dis");
173 printf_debug("BIOS Write Enable: %sabled, ",
174 (old & (1 << 0)) ? "en" : "dis");
175 printf_debug("BIOS_CNTL is 0x%x\n", old);
176
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000177 new = old | 1;
178
179 if (new == old)
180 return 0;
181
Stefan Reinauer86de2832006-03-31 11:26:55 +0000182 pci_write_byte(dev, bios_cntl, new);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000183
Stefan Reinauer86de2832006-03-31 11:26:55 +0000184 if (pci_read_byte(dev, bios_cntl) != new) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000185 printf("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 +0000186 return -1;
187 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000188
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000189 return 0;
190}
191
Uwe Hermann372eeb52007-12-04 21:49:06 +0000192static int enable_flash_ich_4e(struct pci_dev *dev, const char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000193{
Stefan Reinauereb366472006-09-06 15:48:48 +0000194 return enable_flash_ich(dev, name, 0x4e);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000195}
196
Uwe Hermann372eeb52007-12-04 21:49:06 +0000197static int enable_flash_ich_dc(struct pci_dev *dev, const char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000198{
Stefan Reinauereb366472006-09-06 15:48:48 +0000199 return enable_flash_ich(dev, name, 0xdc);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000200}
201
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000202#define ICH_STRAP_RSVD 0x00
203#define ICH_STRAP_SPI 0x01
204#define ICH_STRAP_PCI 0x02
205#define ICH_STRAP_LPC 0x03
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000206
Uwe Hermann394131e2008-10-18 21:14:13 +0000207static int enable_flash_vt8237s_spi(struct pci_dev *dev, const char *name)
208{
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000209 uint32_t mmio_base;
210
211 mmio_base = (pci_read_long(dev, 0xbc)) << 8;
212 printf_debug("MMIO base at = 0x%x\n", mmio_base);
Uwe Hermann394131e2008-10-18 21:14:13 +0000213 spibar = mmap(NULL, 0x70, PROT_READ | PROT_WRITE, MAP_SHARED,
214 fd_mem, mmio_base);
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000215
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000216 if (spibar == MAP_FAILED) {
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000217 perror("Can't mmap memory using " MEM_DEV);
218 exit(1);
219 }
220
Uwe Hermann394131e2008-10-18 21:14:13 +0000221 printf_debug("0x6c: 0x%04x (CLOCK/DEBUG)\n",
222 *(uint16_t *) (spibar + 0x6c));
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000223
224 flashbus = BUS_TYPE_VIA_SPI;
225
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000226 return 0;
227}
228
Uwe Hermann394131e2008-10-18 21:14:13 +0000229static int enable_flash_ich_dc_spi(struct pci_dev *dev, const char *name,
230 int ich_generation)
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000231{
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000232 int ret, i;
Stefan Reinauera9424d52008-06-27 16:28:34 +0000233 uint8_t old, new, bbs, buc;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000234 uint16_t spibar_offset;
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000235 uint32_t tmp, gcs;
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000236 void *rcrb;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000237 static const char *straps_names[] = { "reserved", "SPI", "PCI", "LPC" };
Uwe Hermann394131e2008-10-18 21:14:13 +0000238
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000239 /* Enable Flash Writes */
240 ret = enable_flash_ich_dc(dev, name);
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000241
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000242 /* Get physical address of Root Complex Register Block */
243 tmp = pci_read_long(dev, 0xf0) & 0xffffc000;
Stefan Reinauera9424d52008-06-27 16:28:34 +0000244 printf_debug("\nRoot Complex Register Block address = 0x%x\n", tmp);
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000245
246 /* Map RCBA to virtual memory */
Uwe Hermann394131e2008-10-18 21:14:13 +0000247 rcrb = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem,
248 (off_t) tmp);
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000249 if (rcrb == MAP_FAILED) {
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000250 perror("Can't mmap memory using " MEM_DEV);
251 exit(1);
252 }
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000253
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000254 gcs = *(volatile uint32_t *)(rcrb + 0x3410);
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000255 printf_debug("GCS = 0x%x: ", gcs);
256 printf_debug("BIOS Interface Lock-Down: %sabled, ",
257 (gcs & 0x1) ? "en" : "dis");
258 bbs = (gcs >> 10) & 0x3;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000259 printf_debug("BOOT BIOS Straps: 0x%x (%s)\n", bbs, straps_names[bbs]);
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000260
Stefan Reinauera9424d52008-06-27 16:28:34 +0000261 buc = *(volatile uint8_t *)(rcrb + 0x3414);
Uwe Hermann394131e2008-10-18 21:14:13 +0000262 printf_debug("Top Swap : %s\n",
263 (buc & 1) ? "enabled (A16 inverted)" : "not enabled");
Stefan Reinauera9424d52008-06-27 16:28:34 +0000264
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000265 /* It seems the ICH7 does not support SPI and LPC chips at the same
266 * time. At least not with our current code. So we prevent searching
267 * on ICH7 when the southbridge is strapped to LPC
268 */
269
270 if (ich_generation == 7 && bbs == ICH_STRAP_LPC) {
271 /* No further SPI initialization required */
272 return ret;
273 }
274
275 switch (ich_generation) {
276 case 7:
277 flashbus = BUS_TYPE_ICH7_SPI;
278 spibar_offset = 0x3020;
279 break;
280 case 8:
281 flashbus = BUS_TYPE_ICH9_SPI;
282 spibar_offset = 0x3020;
283 break;
284 case 9:
Carl-Daniel Hailfinger28ec74b2008-10-10 20:54:41 +0000285 case 10:
Uwe Hermann394131e2008-10-18 21:14:13 +0000286 default: /* Future version might behave the same */
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000287 flashbus = BUS_TYPE_ICH9_SPI;
288 spibar_offset = 0x3800;
289 break;
290 }
291
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000292 /* SPIBAR is at RCRB+0x3020 for ICH[78] and RCRB+0x3800 for ICH9. */
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000293 printf_debug("SPIBAR = 0x%x + 0x%04x\n", tmp, spibar_offset);
Stefan Reinauera9424d52008-06-27 16:28:34 +0000294
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000295 /* Assign Virtual Address */
Uwe Hermann394131e2008-10-18 21:14:13 +0000296 spibar = rcrb + spibar_offset;
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000297
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000298 switch (flashbus) {
299 case BUS_TYPE_ICH7_SPI:
Uwe Hermann394131e2008-10-18 21:14:13 +0000300 printf_debug("0x00: 0x%04x (SPIS)\n",
301 *(uint16_t *) (spibar + 0));
302 printf_debug("0x02: 0x%04x (SPIC)\n",
303 *(uint16_t *) (spibar + 2));
304 printf_debug("0x04: 0x%08x (SPIA)\n",
305 *(uint32_t *) (spibar + 4));
306 for (i = 0; i < 8; i++) {
Stefan Reinauera9424d52008-06-27 16:28:34 +0000307 int offs;
308 offs = 8 + (i * 8);
Uwe Hermann394131e2008-10-18 21:14:13 +0000309 printf_debug("0x%02x: 0x%08x (SPID%d)\n", offs,
310 *(uint32_t *) (spibar + offs), i);
311 printf_debug("0x%02x: 0x%08x (SPID%d+4)\n", offs + 4,
312 *(uint32_t *) (spibar + offs + 4), i);
Stefan Reinauera9424d52008-06-27 16:28:34 +0000313 }
Uwe Hermann394131e2008-10-18 21:14:13 +0000314 printf_debug("0x50: 0x%08x (BBAR)\n",
315 *(uint32_t *) (spibar + 0x50));
316 printf_debug("0x54: 0x%04x (PREOP)\n",
317 *(uint16_t *) (spibar + 0x54));
318 printf_debug("0x56: 0x%04x (OPTYPE)\n",
319 *(uint16_t *) (spibar + 0x56));
320 printf_debug("0x58: 0x%08x (OPMENU)\n",
321 *(uint32_t *) (spibar + 0x58));
322 printf_debug("0x5c: 0x%08x (OPMENU+4)\n",
323 *(uint32_t *) (spibar + 0x5c));
324 for (i = 0; i < 4; i++) {
Stefan Reinauera9424d52008-06-27 16:28:34 +0000325 int offs;
326 offs = 0x60 + (i * 4);
Uwe Hermann394131e2008-10-18 21:14:13 +0000327 printf_debug("0x%02x: 0x%08x (PBR%d)\n", offs,
328 *(uint32_t *) (spibar + offs), i);
Stefan Reinauera9424d52008-06-27 16:28:34 +0000329 }
330 printf_debug("\n");
Uwe Hermann394131e2008-10-18 21:14:13 +0000331 if ((*(uint16_t *) spibar) & (1 << 15)) {
Stefan Reinauera9424d52008-06-27 16:28:34 +0000332 printf("WARNING: SPI Configuration Lockdown activated.\n");
333 }
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000334 break;
335 case BUS_TYPE_ICH9_SPI:
336 /* TODO: Add dumping function for ICH8/ICH9, or drop the
337 * whole SPIBAR dumping from chipset_enable.c - There's
338 * inteltool for this task already.
339 */
340 break;
341 default:
342 /* Nothing */
343 break;
Stefan Reinauera9424d52008-06-27 16:28:34 +0000344 }
345
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000346 old = pci_read_byte(dev, 0xdc);
347 printf_debug("SPI Read Configuration: ");
348 new = (old >> 2) & 0x3;
349 switch (new) {
350 case 0:
351 case 1:
352 case 2:
353 printf_debug("prefetching %sabled, caching %sabled, ",
Uwe Hermann394131e2008-10-18 21:14:13 +0000354 (new & 0x2) ? "en" : "dis",
355 (new & 0x1) ? "dis" : "en");
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000356 break;
357 default:
358 printf_debug("invalid prefetching/caching settings, ");
359 break;
360 }
Carl-Daniel Hailfinger67f9ea32008-03-14 17:20:59 +0000361
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000362 return ret;
363}
Stefan Reinauera9424d52008-06-27 16:28:34 +0000364
Carl-Daniel Hailfinger1b18b3c2008-05-16 14:39:39 +0000365static int enable_flash_ich7(struct pci_dev *dev, const char *name)
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000366{
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000367 return enable_flash_ich_dc_spi(dev, name, 7);
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000368}
369
Carl-Daniel Hailfinger1b18b3c2008-05-16 14:39:39 +0000370static int enable_flash_ich8(struct pci_dev *dev, const char *name)
371{
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000372 return enable_flash_ich_dc_spi(dev, name, 8);
Carl-Daniel Hailfinger1b18b3c2008-05-16 14:39:39 +0000373}
374
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000375static int enable_flash_ich9(struct pci_dev *dev, const char *name)
376{
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000377 return enable_flash_ich_dc_spi(dev, name, 9);
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000378}
379
Carl-Daniel Hailfinger28ec74b2008-10-10 20:54:41 +0000380static int enable_flash_ich10(struct pci_dev *dev, const char *name)
381{
382 return enable_flash_ich_dc_spi(dev, name, 10);
383}
384
Uwe Hermann372eeb52007-12-04 21:49:06 +0000385static int enable_flash_vt823x(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000386{
Ollie Lho184a4042005-11-26 21:55:36 +0000387 uint8_t val;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000388
Uwe Hermann394131e2008-10-18 21:14:13 +0000389 /* enable ROM decode range (1MB) FFC00000 - FFFFFFFF */
Bari Ari9477c4e2008-04-29 13:46:38 +0000390 pci_write_byte(dev, 0x41, 0x7f);
391
Uwe Hermannffec5f32007-08-23 16:08:21 +0000392 /* ROM write enable */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000393 val = pci_read_byte(dev, 0x40);
394 val |= 0x10;
395 pci_write_byte(dev, 0x40, val);
396
397 if (pci_read_byte(dev, 0x40) != val) {
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000398 printf("\nWARNING: Failed to enable ROM Write on \"%s\"\n",
Uwe Hermanna7e05482007-05-09 10:17:44 +0000399 name);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000400 return -1;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000401 }
Luc Verhaegen6382b442007-03-02 22:16:38 +0000402
Uwe Hermanna7e05482007-05-09 10:17:44 +0000403 return 0;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000404}
405
Uwe Hermann372eeb52007-12-04 21:49:06 +0000406static int enable_flash_cs5530(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000407{
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000408 uint8_t reg8;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000409
Uwe Hermann394131e2008-10-18 21:14:13 +0000410#define DECODE_CONTROL_REG2 0x5b /* F0 index 0x5b */
411#define ROM_AT_LOGIC_CONTROL_REG 0x52 /* F0 index 0x52 */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000412
Uwe Hermann394131e2008-10-18 21:14:13 +0000413#define LOWER_ROM_ADDRESS_RANGE (1 << 0)
414#define ROM_WRITE_ENABLE (1 << 1)
415#define UPPER_ROM_ADDRESS_RANGE (1 << 2)
416#define BIOS_ROM_POSITIVE_DECODE (1 << 5)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000417
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000418 /* Decode 0x000E0000-0x000FFFFF (128 KB), not just 64 KB, and
419 * decode 0xFF000000-0xFFFFFFFF (16 MB), not just 256 KB.
420 * Make the configured ROM areas writable.
421 */
422 reg8 = pci_read_byte(dev, ROM_AT_LOGIC_CONTROL_REG);
423 reg8 |= LOWER_ROM_ADDRESS_RANGE;
424 reg8 |= UPPER_ROM_ADDRESS_RANGE;
425 reg8 |= ROM_WRITE_ENABLE;
426 pci_write_byte(dev, ROM_AT_LOGIC_CONTROL_REG, reg8);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000427
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000428 /* Set positive decode on ROM. */
429 reg8 = pci_read_byte(dev, DECODE_CONTROL_REG2);
430 reg8 |= BIOS_ROM_POSITIVE_DECODE;
431 pci_write_byte(dev, DECODE_CONTROL_REG2, reg8);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000432
Ollie Lhocbbf1252004-03-17 22:22:08 +0000433 return 0;
434}
435
Mart Raudseppe1344da2008-02-08 10:10:57 +0000436/**
437 * Geode systems write protect the BIOS via RCONFs (cache settings similar
438 * to MTRRs). To unlock, change MSR 0x1808 top byte to 0x22. Reading and
439 * writing to MSRs, however requires instructions rdmsr/wrmsr, which are
440 * ring0 privileged instructions so only the kernel can do the read/write.
441 * This function, therefore, requires that the msr kernel module be loaded
442 * to access these instructions from user space using device /dev/cpu/0/msr.
443 *
444 * This hard-coded location could have potential problems on SMP machines
445 * since it assumes cpu0, but it is safe on the Geode which is not SMP.
446 *
447 * Geode systems also write protect the NOR flash chip itself via MSR_NORF_CTL.
448 * To enable write to NOR Boot flash for the benefit of systems that have such
449 * a setup, raise MSR 0x51400018 WE_CS3 (write enable Boot Flash Chip Select).
450 *
451 * This is probably not portable beyond Linux.
452 */
Uwe Hermann372eeb52007-12-04 21:49:06 +0000453static int enable_flash_cs5536(struct pci_dev *dev, const char *name)
Lane Brooksd54958a2007-11-13 16:45:22 +0000454{
Uwe Hermann394131e2008-10-18 21:14:13 +0000455#define MSR_RCONF_DEFAULT 0x1808
456#define MSR_NORF_CTL 0x51400018
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000457
Lane Brooksd54958a2007-11-13 16:45:22 +0000458 int fd_msr;
459 unsigned char buf[8];
Lane Brooksd54958a2007-11-13 16:45:22 +0000460
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000461 fd_msr = open("/dev/cpu/0/msr", O_RDWR);
Lane Brooksd54958a2007-11-13 16:45:22 +0000462 if (!fd_msr) {
463 perror("open msr");
464 return -1;
465 }
Mart Raudseppe1344da2008-02-08 10:10:57 +0000466
467 if (lseek64(fd_msr, (off64_t) MSR_RCONF_DEFAULT, SEEK_SET) == -1) {
468 perror("lseek64");
Mart Raudsepp3697ac72008-02-11 14:32:45 +0000469 printf("Cannot operate on MSR. Did you run 'modprobe msr'?\n");
Mart Raudseppe1344da2008-02-08 10:10:57 +0000470 close(fd_msr);
471 return -1;
472 }
473
474 if (read(fd_msr, buf, 8) != 8) {
Mart Raudsepp3697ac72008-02-11 14:32:45 +0000475 perror("read msr");
Mart Raudseppe1344da2008-02-08 10:10:57 +0000476 close(fd_msr);
477 return -1;
478 }
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000479
Lane Brooksd54958a2007-11-13 16:45:22 +0000480 if (buf[7] != 0x22) {
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000481 buf[7] &= 0xfb;
Uwe Hermann394131e2008-10-18 21:14:13 +0000482 if (lseek64(fd_msr, (off64_t) MSR_RCONF_DEFAULT,
483 SEEK_SET) == -1) {
Mart Raudseppe1344da2008-02-08 10:10:57 +0000484 perror("lseek64");
485 close(fd_msr);
486 return -1;
487 }
488
Lane Brooksd54958a2007-11-13 16:45:22 +0000489 if (write(fd_msr, buf, 8) < 0) {
490 perror("msr write");
Mart Raudseppe1344da2008-02-08 10:10:57 +0000491 close(fd_msr);
Lane Brooksd54958a2007-11-13 16:45:22 +0000492 return -1;
493 }
Lane Brooksd54958a2007-11-13 16:45:22 +0000494 }
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000495
Mart Raudseppe1344da2008-02-08 10:10:57 +0000496 if (lseek64(fd_msr, (off64_t) MSR_NORF_CTL, SEEK_SET) == -1) {
497 perror("lseek64");
498 close(fd_msr);
499 return -1;
500 }
501
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000502 if (read(fd_msr, buf, 8) != 8) {
503 perror("read msr");
Mart Raudseppe1344da2008-02-08 10:10:57 +0000504 close(fd_msr);
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000505 return -1;
506 }
507
508 /* Raise WE_CS3 bit. */
509 buf[0] |= 0x08;
510
Mart Raudseppe1344da2008-02-08 10:10:57 +0000511 if (lseek64(fd_msr, (off64_t) MSR_NORF_CTL, SEEK_SET) == -1) {
512 perror("lseek64");
513 close(fd_msr);
514 return -1;
515 }
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000516 if (write(fd_msr, buf, 8) < 0) {
517 perror("msr write");
Mart Raudseppe1344da2008-02-08 10:10:57 +0000518 close(fd_msr);
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000519 return -1;
520 }
521
522 close(fd_msr);
523
Uwe Hermann394131e2008-10-18 21:14:13 +0000524#undef MSR_RCONF_DEFAULT
525#undef MSR_NORF_CTL
Lane Brooksd54958a2007-11-13 16:45:22 +0000526 return 0;
527}
528
Uwe Hermann372eeb52007-12-04 21:49:06 +0000529static int enable_flash_sc1100(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000530{
Ollie Lho184a4042005-11-26 21:55:36 +0000531 uint8_t new;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000532
Ollie Lhocbbf1252004-03-17 22:22:08 +0000533 pci_write_byte(dev, 0x52, 0xee);
534
535 new = pci_read_byte(dev, 0x52);
536
537 if (new != 0xee) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000538 printf("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 +0000539 return -1;
540 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000541
Ollie Lhocbbf1252004-03-17 22:22:08 +0000542 return 0;
543}
544
Uwe Hermann372eeb52007-12-04 21:49:06 +0000545static int enable_flash_sis5595(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000546{
Ollie Lho184a4042005-11-26 21:55:36 +0000547 uint8_t new, newer;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000548
Ollie Lhocbbf1252004-03-17 22:22:08 +0000549 new = pci_read_byte(dev, 0x45);
550
Uwe Hermann372eeb52007-12-04 21:49:06 +0000551 new &= (~0x20); /* Clear bit 5. */
552 new |= 0x4; /* Set bit 2. */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000553
554 pci_write_byte(dev, 0x45, new);
555
556 newer = pci_read_byte(dev, 0x45);
557 if (newer != new) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000558 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x45, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000559 printf("Stuck at 0x%x\n", newer);
560 return -1;
561 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000562
Urja Rannikkoa88daa72008-10-18 13:54:30 +0000563 /* Extended BIOS enable = 1, Lower BIOS Enable = 1 */
Uwe Hermann394131e2008-10-18 21:14:13 +0000564 new = pci_read_byte(dev, 0x40);
Urja Rannikkoa88daa72008-10-18 13:54:30 +0000565 new &= 0xFB;
566 new |= 0x3;
Uwe Hermann394131e2008-10-18 21:14:13 +0000567 pci_write_byte(dev, 0x40, new);
568 newer = pci_read_byte(dev, 0x40);
Urja Rannikkoa88daa72008-10-18 13:54:30 +0000569 if (newer != new) {
570 printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name);
571 printf("Stuck at 0x%x\n", newer);
572 return -1;
573 }
Ollie Lhocbbf1252004-03-17 22:22:08 +0000574 return 0;
575}
576
Uwe Hermann190f8492008-10-25 18:03:50 +0000577/* Works for AMD-8111, VIA VT82C586A/B, VIA VT82C686A/B. */
Uwe Hermann372eeb52007-12-04 21:49:06 +0000578static int enable_flash_amd8111(struct pci_dev *dev, const char *name)
Ollie Lho761bf1b2004-03-20 16:46:10 +0000579{
Ollie Lho184a4042005-11-26 21:55:36 +0000580 uint8_t old, new;
Uwe Hermanna7e05482007-05-09 10:17:44 +0000581
Uwe Hermann372eeb52007-12-04 21:49:06 +0000582 /* Enable decoding at 0xffb00000 to 0xffffffff. */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000583 old = pci_read_byte(dev, 0x43);
Ollie Lhod11f3612004-12-07 17:19:04 +0000584 new = old | 0xC0;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000585 if (new != old) {
586 pci_write_byte(dev, 0x43, new);
587 if (pci_read_byte(dev, 0x43) != new) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000588 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x43, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000589 }
590 }
591
Uwe Hermann190f8492008-10-25 18:03:50 +0000592 /* Enable 'ROM write' bit. */
Ollie Lho761bf1b2004-03-20 16:46:10 +0000593 old = pci_read_byte(dev, 0x40);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000594 new = old | 0x01;
595 if (new == old)
596 return 0;
597 pci_write_byte(dev, 0x40, new);
598
599 if (pci_read_byte(dev, 0x40) != new) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000600 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x40, new, name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000601 return -1;
602 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000603
Ollie Lhocbbf1252004-03-17 22:22:08 +0000604 return 0;
605}
606
Marc Jones3af487d2008-10-15 17:50:29 +0000607static int enable_flash_sb600(struct pci_dev *dev, const char *name)
608{
609 uint32_t old, new;
610 uint8_t reg;
611
612 /* Clear ROM Protect 0-3 */
Uwe Hermann394131e2008-10-18 21:14:13 +0000613 for (reg = 0x50; reg < 0x60; reg += 4) {
Marc Jones3af487d2008-10-15 17:50:29 +0000614 old = pci_read_long(dev, reg);
615 new = old & 0xFFFFFFFC;
616 if (new != old) {
617 pci_write_byte(dev, reg, new);
618 if (pci_read_long(dev, reg) != new) {
619 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x50, new, name);
620 }
621 }
622 }
623
624 return 0;
625}
626
Uwe Hermann372eeb52007-12-04 21:49:06 +0000627static int enable_flash_ck804(struct pci_dev *dev, const char *name)
Yinghai Lu952dfce2005-07-06 17:13:46 +0000628{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000629 uint8_t old, new;
Yinghai Lu952dfce2005-07-06 17:13:46 +0000630
Uwe Hermanna7e05482007-05-09 10:17:44 +0000631 old = pci_read_byte(dev, 0x88);
632 new = old | 0xc0;
633 if (new != old) {
634 pci_write_byte(dev, 0x88, new);
635 if (pci_read_byte(dev, 0x88) != new) {
636 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x88, new, name);
637 }
638 }
Yinghai Lu952dfce2005-07-06 17:13:46 +0000639
Uwe Hermanna7e05482007-05-09 10:17:44 +0000640 old = pci_read_byte(dev, 0x6d);
641 new = old | 0x01;
642 if (new == old)
643 return 0;
644 pci_write_byte(dev, 0x6d, new);
645
646 if (pci_read_byte(dev, 0x6d) != new) {
647 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name);
648 return -1;
649 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000650
Uwe Hermanna7e05482007-05-09 10:17:44 +0000651 return 0;
Yinghai Lu952dfce2005-07-06 17:13:46 +0000652}
653
Uwe Hermann372eeb52007-12-04 21:49:06 +0000654/* ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80) */
655static int enable_flash_sb400(struct pci_dev *dev, const char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000656{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000657 uint8_t tmp;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000658 struct pci_filter f;
659 struct pci_dev *smbusdev;
660
Uwe Hermann372eeb52007-12-04 21:49:06 +0000661 /* Look for the SMBus device. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000662 pci_filter_init((struct pci_access *)0, &f);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000663 f.vendor = 0x1002;
664 f.device = 0x4372;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000665
Stefan Reinauer86de2832006-03-31 11:26:55 +0000666 for (smbusdev = pacc->devices; smbusdev; smbusdev = smbusdev->next) {
Uwe Hermann394131e2008-10-18 21:14:13 +0000667 if (pci_filter_match(&f, smbusdev))
Stefan Reinauer86de2832006-03-31 11:26:55 +0000668 break;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000669 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000670
Uwe Hermanna7e05482007-05-09 10:17:44 +0000671 if (!smbusdev) {
Uwe Hermann372eeb52007-12-04 21:49:06 +0000672 fprintf(stderr, "ERROR: SMBus device not found. Aborting.\n");
Stefan Reinauer86de2832006-03-31 11:26:55 +0000673 exit(1);
674 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000675
Uwe Hermann372eeb52007-12-04 21:49:06 +0000676 /* Enable some SMBus stuff. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000677 tmp = pci_read_byte(smbusdev, 0x79);
678 tmp |= 0x01;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000679 pci_write_byte(smbusdev, 0x79, tmp);
680
Uwe Hermann372eeb52007-12-04 21:49:06 +0000681 /* Change southbridge. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000682 tmp = pci_read_byte(dev, 0x48);
683 tmp |= 0x21;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000684 pci_write_byte(dev, 0x48, tmp);
685
Uwe Hermann372eeb52007-12-04 21:49:06 +0000686 /* Now become a bit silly. */
Andriy Gapon65c1b862008-05-22 13:22:45 +0000687 tmp = INB(0xc6f);
688 OUTB(tmp, 0xeb);
689 OUTB(tmp, 0xeb);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000690 tmp |= 0x40;
Andriy Gapon65c1b862008-05-22 13:22:45 +0000691 OUTB(tmp, 0xc6f);
692 OUTB(tmp, 0xeb);
693 OUTB(tmp, 0xeb);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000694
695 return 0;
696}
697
Uwe Hermann372eeb52007-12-04 21:49:06 +0000698static int enable_flash_mcp55(struct pci_dev *dev, const char *name)
Yinghai Luca782972007-01-22 20:21:17 +0000699{
Uwe Hermann372eeb52007-12-04 21:49:06 +0000700 uint8_t old, new, byte;
701 uint16_t word;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000702
Uwe Hermann372eeb52007-12-04 21:49:06 +0000703 /* Set the 0-16 MB enable bits. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000704 byte = pci_read_byte(dev, 0x88);
705 byte |= 0xff; /* 256K */
706 pci_write_byte(dev, 0x88, byte);
707 byte = pci_read_byte(dev, 0x8c);
708 byte |= 0xff; /* 1M */
709 pci_write_byte(dev, 0x8c, byte);
710 word = pci_read_word(dev, 0x90);
Carl-Daniel Hailfingerdca0ab12007-10-17 22:30:07 +0000711 word |= 0x7fff; /* 16M */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000712 pci_write_word(dev, 0x90, word);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000713
Uwe Hermanna7e05482007-05-09 10:17:44 +0000714 old = pci_read_byte(dev, 0x6d);
715 new = old | 0x01;
716 if (new == old)
717 return 0;
718 pci_write_byte(dev, 0x6d, new);
Yinghai Luca782972007-01-22 20:21:17 +0000719
Uwe Hermanna7e05482007-05-09 10:17:44 +0000720 if (pci_read_byte(dev, 0x6d) != new) {
Uwe Hermann394131e2008-10-18 21:14:13 +0000721 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000722 return -1;
723 }
Yinghai Luca782972007-01-22 20:21:17 +0000724
725 return 0;
Yinghai Luca782972007-01-22 20:21:17 +0000726}
727
Uwe Hermann372eeb52007-12-04 21:49:06 +0000728static int enable_flash_ht1000(struct pci_dev *dev, const char *name)
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000729{
Uwe Hermanne823ee02007-06-05 15:02:18 +0000730 uint8_t byte;
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000731
Uwe Hermanne823ee02007-06-05 15:02:18 +0000732 /* Set the 4MB enable bit. */
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000733 byte = pci_read_byte(dev, 0x41);
734 byte |= 0x0e;
735 pci_write_byte(dev, 0x41, byte);
736
737 byte = pci_read_byte(dev, 0x43);
Uwe Hermannffec5f32007-08-23 16:08:21 +0000738 byte |= (1 << 4);
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000739 pci_write_byte(dev, 0x43, byte);
740
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000741 return 0;
742}
743
Ollie Lhocbbf1252004-03-17 22:22:08 +0000744typedef struct penable {
Uwe Hermann372eeb52007-12-04 21:49:06 +0000745 uint16_t vendor, device;
746 const char *name;
747 int (*doit) (struct pci_dev *dev, const char *name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000748} FLASH_ENABLE;
749
Uwe Hermann372eeb52007-12-04 21:49:06 +0000750static const FLASH_ENABLE enables[] = {
Uwe Hermanneac10162008-03-13 18:52:51 +0000751 {0x1039, 0x0630, "SiS630", enable_flash_sis630},
Uwe Hermann87203452008-10-26 18:40:42 +0000752 {0x8086, 0x122e, "Intel PIIX", enable_flash_piix4},
753 {0x8086, 0x7000, "Intel PIIX3", enable_flash_piix4},
Uwe Hermanneac10162008-03-13 18:52:51 +0000754 {0x8086, 0x7110, "Intel PIIX4/4E/4M", enable_flash_piix4},
755 {0x8086, 0x7198, "Intel 440MX", enable_flash_piix4},
756 {0x8086, 0x2410, "Intel ICH", enable_flash_ich_4e},
757 {0x8086, 0x2420, "Intel ICH0", enable_flash_ich_4e},
758 {0x8086, 0x2440, "Intel ICH2", enable_flash_ich_4e},
759 {0x8086, 0x244c, "Intel ICH2-M", enable_flash_ich_4e},
760 {0x8086, 0x2480, "Intel ICH3-S", enable_flash_ich_4e},
761 {0x8086, 0x248c, "Intel ICH3-M", enable_flash_ich_4e},
762 {0x8086, 0x24c0, "Intel ICH4/ICH4-L", enable_flash_ich_4e},
763 {0x8086, 0x24cc, "Intel ICH4-M", enable_flash_ich_4e},
764 {0x8086, 0x24d0, "Intel ICH5/ICH5R", enable_flash_ich_4e},
Claus Gindharta00e2a02008-05-14 12:22:38 +0000765 {0x8086, 0x25a1, "Intel 6300ESB", enable_flash_ich_4e},
Uwe Hermanneac10162008-03-13 18:52:51 +0000766 {0x8086, 0x2640, "Intel ICH6/ICH6R", enable_flash_ich_dc},
767 {0x8086, 0x2641, "Intel ICH6-M", enable_flash_ich_dc},
Ed Swierkcd2ed472008-08-20 20:31:41 +0000768 {0x8086, 0x5031, "Intel EP80579", enable_flash_ich_dc},
Carl-Daniel Hailfinger1b18b3c2008-05-16 14:39:39 +0000769 {0x8086, 0x27b0, "Intel ICH7DH", enable_flash_ich7},
770 {0x8086, 0x27b8, "Intel ICH7/ICH7R", enable_flash_ich7},
771 {0x8086, 0x27b9, "Intel ICH7M", enable_flash_ich7},
772 {0x8086, 0x27bd, "Intel ICH7MDH", enable_flash_ich7},
773 {0x8086, 0x2810, "Intel ICH8/ICH8R", enable_flash_ich8},
774 {0x8086, 0x2811, "Intel ICH8M-E", enable_flash_ich8},
775 {0x8086, 0x2812, "Intel ICH8DH", enable_flash_ich8},
776 {0x8086, 0x2814, "Intel ICH8DO", enable_flash_ich8},
777 {0x8086, 0x2815, "Intel ICH8M", enable_flash_ich8},
Carl-Daniel Hailfinger6dc1d3b2008-05-14 14:51:22 +0000778 {0x8086, 0x2912, "Intel ICH9DH", enable_flash_ich9},
779 {0x8086, 0x2914, "Intel ICH9DO", enable_flash_ich9},
780 {0x8086, 0x2916, "Intel ICH9R", enable_flash_ich9},
781 {0x8086, 0x2917, "Intel ICH9M-E", enable_flash_ich9},
782 {0x8086, 0x2918, "Intel ICH9", enable_flash_ich9},
783 {0x8086, 0x2919, "Intel ICH9M", enable_flash_ich9},
Carl-Daniel Hailfinger28ec74b2008-10-10 20:54:41 +0000784 {0x8086, 0x3a14, "Intel ICH10DO", enable_flash_ich10},
785 {0x8086, 0x3a16, "Intel ICH10R", enable_flash_ich10},
786 {0x8086, 0x3a18, "Intel ICH10", enable_flash_ich10},
787 {0x8086, 0x3a1a, "Intel ICH10D", enable_flash_ich10},
Uwe Hermanneac10162008-03-13 18:52:51 +0000788 {0x1106, 0x8231, "VIA VT8231", enable_flash_vt823x},
789 {0x1106, 0x3177, "VIA VT8235", enable_flash_vt823x},
790 {0x1106, 0x3227, "VIA VT8237", enable_flash_vt823x},
Rudolf Marek3fdbccf2008-06-30 21:38:30 +0000791 {0x1106, 0x3372, "VIA VT8237S", enable_flash_vt8237s_spi},
Uwe Hermanneac10162008-03-13 18:52:51 +0000792 {0x1106, 0x8324, "VIA CX700", enable_flash_vt823x},
Uwe Hermann190f8492008-10-25 18:03:50 +0000793 {0x1106, 0x0586, "VIA VT82C586A/B", enable_flash_amd8111},
794 {0x1106, 0x0686, "VIA VT82C686A/B", enable_flash_amd8111},
Uwe Hermanneac10162008-03-13 18:52:51 +0000795 {0x1078, 0x0100, "AMD CS5530(A)", enable_flash_cs5530},
796 {0x100b, 0x0510, "AMD SC1100", enable_flash_sc1100},
797 {0x1039, 0x0008, "SiS5595", enable_flash_sis5595},
798 {0x1022, 0x2080, "AMD CS5536", enable_flash_cs5536},
799 {0x1022, 0x7468, "AMD8111", enable_flash_amd8111},
Marc Jones3af487d2008-10-15 17:50:29 +0000800 {0x1002, 0x438D, "ATI(AMD) SB600", enable_flash_sb600},
Uwe Hermanneac10162008-03-13 18:52:51 +0000801 {0x10B9, 0x1533, "ALi M1533", enable_flash_ali_m1533},
802 {0x10de, 0x0050, "NVIDIA CK804", enable_flash_ck804}, /* LPC */
803 {0x10de, 0x0051, "NVIDIA CK804", enable_flash_ck804}, /* Pro */
804 /* Slave, should not be here, to fix known bug for A01. */
805 {0x10de, 0x00d3, "NVIDIA CK804", enable_flash_ck804},
806 {0x10de, 0x0260, "NVIDIA MCP51", enable_flash_ck804},
807 {0x10de, 0x0261, "NVIDIA MCP51", enable_flash_ck804},
808 {0x10de, 0x0262, "NVIDIA MCP51", enable_flash_ck804},
809 {0x10de, 0x0263, "NVIDIA MCP51", enable_flash_ck804},
810 {0x10de, 0x0360, "NVIDIA MCP55", enable_flash_mcp55}, /* M57SLI*/
811 {0x10de, 0x0361, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
812 {0x10de, 0x0362, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
813 {0x10de, 0x0363, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
814 {0x10de, 0x0364, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
815 {0x10de, 0x0365, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
816 {0x10de, 0x0366, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
817 {0x10de, 0x0367, "NVIDIA MCP55", enable_flash_mcp55}, /* Pro */
Stefan Reinauer7f274642008-07-05 09:48:30 +0000818 {0x10de, 0x0548, "NVIDIA MCP67", enable_flash_mcp55},
Uwe Hermanneac10162008-03-13 18:52:51 +0000819 {0x1002, 0x4377, "ATI SB400", enable_flash_sb400},
820 {0x1166, 0x0205, "Broadcom HT-1000", enable_flash_ht1000},
Ollie Lhocbbf1252004-03-17 22:22:08 +0000821};
Ollie Lho761bf1b2004-03-20 16:46:10 +0000822
Uwe Hermanne5ac1642008-03-12 11:54:51 +0000823void print_supported_chipsets(void)
824{
825 int i;
826
827 printf("\nSupported chipsets:\n\n");
828
829 for (i = 0; i < ARRAY_SIZE(enables); i++)
830 printf("%s (%04x:%04x)\n", enables[i].name,
831 enables[i].vendor, enables[i].device);
832}
833
Uwe Hermanna7e05482007-05-09 10:17:44 +0000834int chipset_flash_enable(void)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000835{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000836 struct pci_dev *dev = 0;
Uwe Hermann372eeb52007-12-04 21:49:06 +0000837 int ret = -2; /* Nothing! */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000838 int i;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000839
Uwe Hermann372eeb52007-12-04 21:49:06 +0000840 /* Now let's try to find the chipset we have... */
Uwe Hermanne5ac1642008-03-12 11:54:51 +0000841 for (i = 0; i < ARRAY_SIZE(enables); i++) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000842 dev = pci_dev_find(enables[i].vendor, enables[i].device);
843 if (dev)
844 break;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000845 }
846
Uwe Hermanna7e05482007-05-09 10:17:44 +0000847 if (dev) {
Uwe Hermanna502dce2007-10-17 23:55:15 +0000848 printf("Found chipset \"%s\", enabling flash write... ",
Uwe Hermanna7e05482007-05-09 10:17:44 +0000849 enables[i].name);
850
851 ret = enables[i].doit(dev, enables[i].name);
852 if (ret)
Uwe Hermanna502dce2007-10-17 23:55:15 +0000853 printf("FAILED!\n");
Uwe Hermanna7e05482007-05-09 10:17:44 +0000854 else
Uwe Hermannac309342007-10-10 17:42:20 +0000855 printf("OK.\n");
Uwe Hermanna7e05482007-05-09 10:17:44 +0000856 }
857
858 return ret;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000859}