blob: 2ec4c7dcc761d4f1868d08ee94683b8d408ff709 [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>
33#include <fcntl.h>
34#include <unistd.h>
Luc Verhaegen8e3a6002007-04-04 22:45:58 +000035#include "flash.h"
Stefan Reinauer86de2832006-03-31 11:26:55 +000036
Uwe Hermann372eeb52007-12-04 21:49:06 +000037static int enable_flash_ali_m1533(struct pci_dev *dev, const char *name)
Luc Verhaegen6b141752007-05-20 16:16:13 +000038{
39 uint8_t tmp;
40
Uwe Hermann372eeb52007-12-04 21:49:06 +000041 /*
42 * ROM Write enable, 0xFFFC0000-0xFFFDFFFF and
43 * 0xFFFE0000-0xFFFFFFFF ROM select enable.
44 */
Luc Verhaegen6b141752007-05-20 16:16:13 +000045 tmp = pci_read_byte(dev, 0x47);
46 tmp |= 0x46;
47 pci_write_byte(dev, 0x47, tmp);
48
49 return 0;
50}
51
Uwe Hermann372eeb52007-12-04 21:49:06 +000052static int enable_flash_sis630(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +000053{
Uwe Hermann372eeb52007-12-04 21:49:06 +000054 uint8_t b;
Ollie Lhocbbf1252004-03-17 22:22:08 +000055
Uwe Hermann372eeb52007-12-04 21:49:06 +000056 /* Enable 0xFFF8000~0xFFFF0000 decoding on SiS 540/630. */
Alex Beregszaszic9fb5d92007-09-11 15:58:18 +000057 b = pci_read_byte(dev, 0x40);
58 pci_write_byte(dev, 0x40, b | 0xb);
Uwe Hermann372eeb52007-12-04 21:49:06 +000059
60 /* Flash write enable on SiS 540/630. */
Alex Beregszaszic9fb5d92007-09-11 15:58:18 +000061 b = pci_read_byte(dev, 0x45);
62 pci_write_byte(dev, 0x45, b | 0x40);
Ollie Lhocbbf1252004-03-17 22:22:08 +000063
Uwe Hermann372eeb52007-12-04 21:49:06 +000064 /* The same thing on SiS 950 Super I/O side... */
65
66 /* First probe for Super I/O on config port 0x2e. */
Ollie Lhocbbf1252004-03-17 22:22:08 +000067 outb(0x87, 0x2e);
68 outb(0x01, 0x2e);
69 outb(0x55, 0x2e);
70 outb(0x55, 0x2e);
71
72 if (inb(0x2f) != 0x87) {
Uwe Hermann372eeb52007-12-04 21:49:06 +000073 /* If that failed, try config port 0x4e. */
Ollie Lhocbbf1252004-03-17 22:22:08 +000074 outb(0x87, 0x4e);
75 outb(0x01, 0x4e);
76 outb(0x55, 0x4e);
77 outb(0xaa, 0x4e);
78 if (inb(0x4f) != 0x87) {
79 printf("Can not access SiS 950\n");
80 return -1;
81 }
82 outb(0x24, 0x4e);
83 b = inb(0x4f) | 0xfc;
84 outb(0x24, 0x4e);
85 outb(b, 0x4f);
86 outb(0x02, 0x4e);
Ollie Lho761bf1b2004-03-20 16:46:10 +000087 outb(0x02, 0x4f);
Ollie Lhocbbf1252004-03-17 22:22:08 +000088 }
89
90 outb(0x24, 0x2e);
91 printf("2f is %#x\n", inb(0x2f));
92 b = inb(0x2f) | 0xfc;
93 outb(0x24, 0x2e);
94 outb(b, 0x2f);
95
96 outb(0x02, 0x2e);
97 outb(0x02, 0x2f);
98
99 return 0;
100}
101
Uwe Hermann987942d2006-11-07 11:16:21 +0000102/* Datasheet:
103 * - Name: 82371AB PCI-TO-ISA / IDE XCELERATOR (PIIX4)
104 * - URL: http://www.intel.com/design/intarch/datashts/290562.htm
105 * - PDF: http://www.intel.com/design/intarch/datashts/29056201.pdf
106 * - Order Number: 290562-001
107 */
Uwe Hermann372eeb52007-12-04 21:49:06 +0000108static int enable_flash_piix4(struct pci_dev *dev, const char *name)
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000109{
110 uint16_t old, new;
Uwe Hermanna7e05482007-05-09 10:17:44 +0000111 uint16_t xbcs = 0x4e; /* X-Bus Chip Select register. */
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000112
113 old = pci_read_word(dev, xbcs);
114
115 /* Set bit 9: 1-Meg Extended BIOS Enable (PCI master accesses to
Uwe Hermanna7e05482007-05-09 10:17:44 +0000116 * FFF00000-FFF7FFFF are forwarded to ISA).
117 * Set bit 7: Extended BIOS Enable (PCI master accesses to
118 * FFF80000-FFFDFFFF are forwarded to ISA).
119 * Set bit 6: Lower BIOS Enable (PCI master, or ISA master accesses to
120 * the lower 64-Kbyte BIOS block (E0000-EFFFF) at the top
121 * of 1 Mbyte, or the aliases at the top of 4 Gbyte
122 * (FFFE0000-FFFEFFFF) result in the generation of BIOSCS#.
123 * Note: Accesses to FFFF0000-FFFFFFFF are always forwarded to ISA.
124 * Set bit 2: BIOSCS# Write Enable (1=enable, 0=disable).
125 */
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000126 new = old | 0x2c4;
127
128 if (new == old)
129 return 0;
130
131 pci_write_word(dev, xbcs, new);
132
133 if (pci_read_word(dev, xbcs) != new) {
134 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", xbcs, new, name);
135 return -1;
136 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000137
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000138 return 0;
139}
140
Uwe Hermann372eeb52007-12-04 21:49:06 +0000141/*
142 * See ie. page 375 of "Intel ICH7 External Design Specification"
143 * http://download.intel.com/design/chipsets/datashts/30701302.pdf
144 */
145static int enable_flash_ich(struct pci_dev *dev, const char *name,
146 int bios_cntl)
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000147{
Ollie Lho184a4042005-11-26 21:55:36 +0000148 uint8_t old, new;
Stefan Reinauereb366472006-09-06 15:48:48 +0000149
Uwe Hermann372eeb52007-12-04 21:49:06 +0000150 /*
151 * Note: the ICH0-ICH5 BIOS_CNTL register is actually 16 bit wide, but
Uwe Hermanna7e05482007-05-09 10:17:44 +0000152 * just treating it as 8 bit wide seems to work fine in practice.
Stefan Reinauereb366472006-09-06 15:48:48 +0000153 */
Stefan Reinauer86de2832006-03-31 11:26:55 +0000154 old = pci_read_byte(dev, bios_cntl);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000155
156 new = old | 1;
157
158 if (new == old)
159 return 0;
160
Stefan Reinauer86de2832006-03-31 11:26:55 +0000161 pci_write_byte(dev, bios_cntl, new);
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000162
Stefan Reinauer86de2832006-03-31 11:26:55 +0000163 if (pci_read_byte(dev, bios_cntl) != new) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000164 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 +0000165 return -1;
166 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000167
Ronald G. Minnich6a967412004-09-28 20:09:06 +0000168 return 0;
169}
170
Uwe Hermann372eeb52007-12-04 21:49:06 +0000171static int enable_flash_ich_4e(struct pci_dev *dev, const char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000172{
Stefan Reinauereb366472006-09-06 15:48:48 +0000173 return enable_flash_ich(dev, name, 0x4e);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000174}
175
Uwe Hermann372eeb52007-12-04 21:49:06 +0000176static int enable_flash_ich_dc(struct pci_dev *dev, const char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000177{
Stefan Reinauereb366472006-09-06 15:48:48 +0000178 return enable_flash_ich(dev, name, 0xdc);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000179}
180
Uwe Hermann372eeb52007-12-04 21:49:06 +0000181static int enable_flash_vt823x(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000182{
Ollie Lho184a4042005-11-26 21:55:36 +0000183 uint8_t val;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000184
Uwe Hermannffec5f32007-08-23 16:08:21 +0000185 /* ROM write enable */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000186 val = pci_read_byte(dev, 0x40);
187 val |= 0x10;
188 pci_write_byte(dev, 0x40, val);
189
190 if (pci_read_byte(dev, 0x40) != val) {
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000191 printf("\nWARNING: Failed to enable ROM Write on \"%s\"\n",
Uwe Hermanna7e05482007-05-09 10:17:44 +0000192 name);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000193 return -1;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000194 }
Luc Verhaegen6382b442007-03-02 22:16:38 +0000195
Uwe Hermanna7e05482007-05-09 10:17:44 +0000196 return 0;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000197}
198
Uwe Hermann372eeb52007-12-04 21:49:06 +0000199static int enable_flash_cs5530(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000200{
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000201 uint8_t reg8;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000202
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000203 #define DECODE_CONTROL_REG2 0x5b /* F0 index 0x5b */
204 #define ROM_AT_LOGIC_CONTROL_REG 0x52 /* F0 index 0x52 */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000205
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000206 #define LOWER_ROM_ADDRESS_RANGE (1 << 0)
207 #define ROM_WRITE_ENABLE (1 << 1)
208 #define UPPER_ROM_ADDRESS_RANGE (1 << 2)
209 #define BIOS_ROM_POSITIVE_DECODE (1 << 5)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000210
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000211 /* Decode 0x000E0000-0x000FFFFF (128 KB), not just 64 KB, and
212 * decode 0xFF000000-0xFFFFFFFF (16 MB), not just 256 KB.
213 * Make the configured ROM areas writable.
214 */
215 reg8 = pci_read_byte(dev, ROM_AT_LOGIC_CONTROL_REG);
216 reg8 |= LOWER_ROM_ADDRESS_RANGE;
217 reg8 |= UPPER_ROM_ADDRESS_RANGE;
218 reg8 |= ROM_WRITE_ENABLE;
219 pci_write_byte(dev, ROM_AT_LOGIC_CONTROL_REG, reg8);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000220
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000221 /* Set positive decode on ROM. */
222 reg8 = pci_read_byte(dev, DECODE_CONTROL_REG2);
223 reg8 |= BIOS_ROM_POSITIVE_DECODE;
224 pci_write_byte(dev, DECODE_CONTROL_REG2, reg8);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000225
Ollie Lhocbbf1252004-03-17 22:22:08 +0000226 return 0;
227}
228
Uwe Hermann372eeb52007-12-04 21:49:06 +0000229static int enable_flash_cs5536(struct pci_dev *dev, const char *name)
Lane Brooksd54958a2007-11-13 16:45:22 +0000230{
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000231 #define MSR_NORF_CTL 0x51400018
232
Lane Brooksd54958a2007-11-13 16:45:22 +0000233 int fd_msr;
234 unsigned char buf[8];
235 unsigned int addr = 0x1808;
236
237 /* Geode systems write protect the BIOS via RCONFs (cache
238 * settings similar to MTRRs). To unlock, change MSR 0x1808
239 * top byte to 0x22. Reading and writing to msr, however
Uwe Hermann372eeb52007-12-04 21:49:06 +0000240 * requires instructions rdmsr/wrmsr, which are ring0 privileged
Lane Brooksd54958a2007-11-13 16:45:22 +0000241 * instructions so only the kernel can do the read/write. This
242 * function, therefore, requires that the msr kernel module be
243 * loaded to access these instructions from user space using
244 * device /dev/cpu/0/msr. This hard-coded driver location
245 * could have potential problems on SMP machines since it
Uwe Hermann372eeb52007-12-04 21:49:06 +0000246 * assumes cpu0, but it is safe on the Geode which is not SMP.
Lane Brooksd54958a2007-11-13 16:45:22 +0000247 *
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000248 * Geode systems also write protect the NOR flash chip itself
249 * via MSR_NORF_CTL. To enable write to NOR Boot flash for the
250 * benefit of systems that have such a setup, raise
251 * MSR 0x51400018 WE_CS3 (write enable Boot Flash Chip Select).
252 *
Uwe Hermann372eeb52007-12-04 21:49:06 +0000253 * This is probably not portable beyond Linux.
Lane Brooksd54958a2007-11-13 16:45:22 +0000254 */
255
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000256 fd_msr = open("/dev/cpu/0/msr", O_RDWR);
Lane Brooksd54958a2007-11-13 16:45:22 +0000257 if (!fd_msr) {
258 perror("open msr");
259 return -1;
260 }
261 lseek64(fd_msr, (off64_t) addr, SEEK_SET);
262 read(fd_msr, buf, 8);
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000263
264 printf("Enabling Geode MSR to write to flash.\n");
265
Lane Brooksd54958a2007-11-13 16:45:22 +0000266 if (buf[7] != 0x22) {
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000267 buf[7] &= 0xfb;
Lane Brooksd54958a2007-11-13 16:45:22 +0000268 lseek64(fd_msr, (off64_t) addr, SEEK_SET);
269 if (write(fd_msr, buf, 8) < 0) {
270 perror("msr write");
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000271 printf("Cannot write to MSR. Did you run 'modprobe msr'?\n");
Lane Brooksd54958a2007-11-13 16:45:22 +0000272 return -1;
273 }
Lane Brooksd54958a2007-11-13 16:45:22 +0000274 }
Mart Raudsepp0514a5f2008-02-08 09:59:58 +0000275
276 lseek64(fd_msr, (off64_t) MSR_NORF_CTL, SEEK_SET);
277 if (read(fd_msr, buf, 8) != 8) {
278 perror("read msr");
279 return -1;
280 }
281
282 /* Raise WE_CS3 bit. */
283 buf[0] |= 0x08;
284
285 lseek64(fd_msr, (off64_t) MSR_NORF_CTL, SEEK_SET);
286 if (write(fd_msr, buf, 8) < 0) {
287 perror("msr write");
288 printf("Cannot write to MSR. Did you run 'modprobe msr'?\n");
289 return -1;
290 }
291
292 close(fd_msr);
293
294 #undef MSR_NORF_CTL
Lane Brooksd54958a2007-11-13 16:45:22 +0000295 return 0;
296}
297
Uwe Hermann372eeb52007-12-04 21:49:06 +0000298static int enable_flash_sc1100(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000299{
Ollie Lho184a4042005-11-26 21:55:36 +0000300 uint8_t new;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000301
Ollie Lhocbbf1252004-03-17 22:22:08 +0000302 pci_write_byte(dev, 0x52, 0xee);
303
304 new = pci_read_byte(dev, 0x52);
305
306 if (new != 0xee) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000307 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 +0000308 return -1;
309 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000310
Ollie Lhocbbf1252004-03-17 22:22:08 +0000311 return 0;
312}
313
Uwe Hermann372eeb52007-12-04 21:49:06 +0000314static int enable_flash_sis5595(struct pci_dev *dev, const char *name)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000315{
Ollie Lho184a4042005-11-26 21:55:36 +0000316 uint8_t new, newer;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000317
Ollie Lhocbbf1252004-03-17 22:22:08 +0000318 new = pci_read_byte(dev, 0x45);
319
Uwe Hermann372eeb52007-12-04 21:49:06 +0000320 new &= (~0x20); /* Clear bit 5. */
321 new |= 0x4; /* Set bit 2. */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000322
323 pci_write_byte(dev, 0x45, new);
324
325 newer = pci_read_byte(dev, 0x45);
326 if (newer != new) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000327 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 +0000328 printf("Stuck at 0x%x\n", newer);
329 return -1;
330 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000331
Ollie Lhocbbf1252004-03-17 22:22:08 +0000332 return 0;
333}
334
Uwe Hermann372eeb52007-12-04 21:49:06 +0000335static int enable_flash_amd8111(struct pci_dev *dev, const char *name)
Ollie Lho761bf1b2004-03-20 16:46:10 +0000336{
Ollie Lho184a4042005-11-26 21:55:36 +0000337 uint8_t old, new;
Uwe Hermanna7e05482007-05-09 10:17:44 +0000338
Uwe Hermann372eeb52007-12-04 21:49:06 +0000339 /* Enable decoding at 0xffb00000 to 0xffffffff. */
Ollie Lhocbbf1252004-03-17 22:22:08 +0000340 old = pci_read_byte(dev, 0x43);
Ollie Lhod11f3612004-12-07 17:19:04 +0000341 new = old | 0xC0;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000342 if (new != old) {
343 pci_write_byte(dev, 0x43, new);
344 if (pci_read_byte(dev, 0x43) != new) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000345 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 +0000346 }
347 }
348
Ollie Lho761bf1b2004-03-20 16:46:10 +0000349 old = pci_read_byte(dev, 0x40);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000350 new = old | 0x01;
351 if (new == old)
352 return 0;
353 pci_write_byte(dev, 0x40, new);
354
355 if (pci_read_byte(dev, 0x40) != new) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000356 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 +0000357 return -1;
358 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000359
Ollie Lhocbbf1252004-03-17 22:22:08 +0000360 return 0;
361}
362
Uwe Hermann372eeb52007-12-04 21:49:06 +0000363static int enable_flash_ck804(struct pci_dev *dev, const char *name)
Yinghai Lu952dfce2005-07-06 17:13:46 +0000364{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000365 uint8_t old, new;
Yinghai Lu952dfce2005-07-06 17:13:46 +0000366
Uwe Hermanna7e05482007-05-09 10:17:44 +0000367 old = pci_read_byte(dev, 0x88);
368 new = old | 0xc0;
369 if (new != old) {
370 pci_write_byte(dev, 0x88, new);
371 if (pci_read_byte(dev, 0x88) != new) {
372 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x88, new, name);
373 }
374 }
Yinghai Lu952dfce2005-07-06 17:13:46 +0000375
Uwe Hermanna7e05482007-05-09 10:17:44 +0000376 old = pci_read_byte(dev, 0x6d);
377 new = old | 0x01;
378 if (new == old)
379 return 0;
380 pci_write_byte(dev, 0x6d, new);
381
382 if (pci_read_byte(dev, 0x6d) != new) {
383 printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n", 0x6d, new, name);
384 return -1;
385 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000386
Uwe Hermanna7e05482007-05-09 10:17:44 +0000387 return 0;
Yinghai Lu952dfce2005-07-06 17:13:46 +0000388}
389
Uwe Hermann372eeb52007-12-04 21:49:06 +0000390/* ATI Technologies Inc IXP SB400 PCI-ISA Bridge (rev 80) */
391static int enable_flash_sb400(struct pci_dev *dev, const char *name)
Stefan Reinauer86de2832006-03-31 11:26:55 +0000392{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000393 uint8_t tmp;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000394 struct pci_filter f;
395 struct pci_dev *smbusdev;
396
Uwe Hermann372eeb52007-12-04 21:49:06 +0000397 /* Look for the SMBus device. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000398 pci_filter_init((struct pci_access *)0, &f);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000399 f.vendor = 0x1002;
400 f.device = 0x4372;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000401
Stefan Reinauer86de2832006-03-31 11:26:55 +0000402 for (smbusdev = pacc->devices; smbusdev; smbusdev = smbusdev->next) {
403 if (pci_filter_match(&f, smbusdev)) {
404 break;
405 }
406 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000407
Uwe Hermanna7e05482007-05-09 10:17:44 +0000408 if (!smbusdev) {
Uwe Hermann372eeb52007-12-04 21:49:06 +0000409 fprintf(stderr, "ERROR: SMBus device not found. Aborting.\n");
Stefan Reinauer86de2832006-03-31 11:26:55 +0000410 exit(1);
411 }
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000412
Uwe Hermann372eeb52007-12-04 21:49:06 +0000413 /* Enable some SMBus stuff. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000414 tmp = pci_read_byte(smbusdev, 0x79);
415 tmp |= 0x01;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000416 pci_write_byte(smbusdev, 0x79, tmp);
417
Uwe Hermann372eeb52007-12-04 21:49:06 +0000418 /* Change southbridge. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000419 tmp = pci_read_byte(dev, 0x48);
420 tmp |= 0x21;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000421 pci_write_byte(dev, 0x48, tmp);
422
Uwe Hermann372eeb52007-12-04 21:49:06 +0000423 /* Now become a bit silly. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000424 tmp = inb(0xc6f);
Stefan Reinauer86de2832006-03-31 11:26:55 +0000425 outb(tmp, 0xeb);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000426 outb(tmp, 0xeb);
427 tmp |= 0x40;
Stefan Reinauer86de2832006-03-31 11:26:55 +0000428 outb(tmp, 0xc6f);
429 outb(tmp, 0xeb);
430 outb(tmp, 0xeb);
431
432 return 0;
433}
434
Uwe Hermann372eeb52007-12-04 21:49:06 +0000435static int enable_flash_mcp55(struct pci_dev *dev, const char *name)
Yinghai Luca782972007-01-22 20:21:17 +0000436{
Uwe Hermann372eeb52007-12-04 21:49:06 +0000437 uint8_t old, new, byte;
438 uint16_t word;
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000439
Uwe Hermann372eeb52007-12-04 21:49:06 +0000440 /* Set the 0-16 MB enable bits. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000441 byte = pci_read_byte(dev, 0x88);
442 byte |= 0xff; /* 256K */
443 pci_write_byte(dev, 0x88, byte);
444 byte = pci_read_byte(dev, 0x8c);
445 byte |= 0xff; /* 1M */
446 pci_write_byte(dev, 0x8c, byte);
447 word = pci_read_word(dev, 0x90);
Carl-Daniel Hailfingerdca0ab12007-10-17 22:30:07 +0000448 word |= 0x7fff; /* 16M */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000449 pci_write_word(dev, 0x90, word);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000450
Uwe Hermanna7e05482007-05-09 10:17:44 +0000451 old = pci_read_byte(dev, 0x6d);
452 new = old | 0x01;
453 if (new == old)
454 return 0;
455 pci_write_byte(dev, 0x6d, new);
Yinghai Luca782972007-01-22 20:21:17 +0000456
Uwe Hermanna7e05482007-05-09 10:17:44 +0000457 if (pci_read_byte(dev, 0x6d) != new) {
458 printf
459 ("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
460 0x6d, new, name);
461 return -1;
462 }
Yinghai Luca782972007-01-22 20:21:17 +0000463
464 return 0;
Yinghai Luca782972007-01-22 20:21:17 +0000465}
466
Uwe Hermann372eeb52007-12-04 21:49:06 +0000467static int enable_flash_ht1000(struct pci_dev *dev, const char *name)
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000468{
Uwe Hermanne823ee02007-06-05 15:02:18 +0000469 uint8_t byte;
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000470
Uwe Hermanne823ee02007-06-05 15:02:18 +0000471 /* Set the 4MB enable bit. */
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000472 byte = pci_read_byte(dev, 0x41);
473 byte |= 0x0e;
474 pci_write_byte(dev, 0x41, byte);
475
476 byte = pci_read_byte(dev, 0x43);
Uwe Hermannffec5f32007-08-23 16:08:21 +0000477 byte |= (1 << 4);
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000478 pci_write_byte(dev, 0x43, byte);
479
Stefan Reinauerc868b9e2007-06-05 10:28:39 +0000480 return 0;
481}
482
Ollie Lhocbbf1252004-03-17 22:22:08 +0000483typedef struct penable {
Uwe Hermann372eeb52007-12-04 21:49:06 +0000484 uint16_t vendor, device;
485 const char *name;
486 int (*doit) (struct pci_dev *dev, const char *name);
Ollie Lhocbbf1252004-03-17 22:22:08 +0000487} FLASH_ENABLE;
488
Uwe Hermann372eeb52007-12-04 21:49:06 +0000489static const FLASH_ENABLE enables[] = {
Stefan Reinauereb366472006-09-06 15:48:48 +0000490 {0x1039, 0x0630, "SIS630", enable_flash_sis630},
Uwe Hermannea2c66d2006-11-05 18:26:08 +0000491 {0x8086, 0x7110, "PIIX4/PIIX4E/PIIX4M", enable_flash_piix4},
Uwe Hermann97a64702007-10-30 00:56:50 +0000492 {0x8086, 0x7198, "Intel 440MX", enable_flash_piix4},
Stefan Reinauereb366472006-09-06 15:48:48 +0000493 {0x8086, 0x2410, "ICH", enable_flash_ich_4e},
494 {0x8086, 0x2420, "ICH0", enable_flash_ich_4e},
495 {0x8086, 0x2440, "ICH2", enable_flash_ich_4e},
496 {0x8086, 0x244c, "ICH2-M", enable_flash_ich_4e},
497 {0x8086, 0x2480, "ICH3-S", enable_flash_ich_4e},
498 {0x8086, 0x248c, "ICH3-M", enable_flash_ich_4e},
499 {0x8086, 0x24c0, "ICH4/ICH4-L", enable_flash_ich_4e},
500 {0x8086, 0x24cc, "ICH4-M", enable_flash_ich_4e},
501 {0x8086, 0x24d0, "ICH5/ICH5R", enable_flash_ich_4e},
502 {0x8086, 0x2640, "ICH6/ICH6R", enable_flash_ich_dc},
503 {0x8086, 0x2641, "ICH6-M", enable_flash_ich_dc},
Uwe Hermann3ad25182007-03-31 19:48:38 +0000504 {0x8086, 0x27b0, "ICH7DH", enable_flash_ich_dc},
Stefan Reinauereb366472006-09-06 15:48:48 +0000505 {0x8086, 0x27b8, "ICH7/ICH7R", enable_flash_ich_dc},
506 {0x8086, 0x27b9, "ICH7M", enable_flash_ich_dc},
507 {0x8086, 0x27bd, "ICH7MDH", enable_flash_ich_dc},
508 {0x8086, 0x2810, "ICH8/ICH8R", enable_flash_ich_dc},
509 {0x8086, 0x2812, "ICH8DH", enable_flash_ich_dc},
510 {0x8086, 0x2814, "ICH8DO", enable_flash_ich_dc},
Luc Verhaegen6382b442007-03-02 22:16:38 +0000511 {0x1106, 0x8231, "VT8231", enable_flash_vt823x},
512 {0x1106, 0x3177, "VT8235", enable_flash_vt823x},
513 {0x1106, 0x3227, "VT8237", enable_flash_vt823x},
Uwe Hermanna7e05482007-05-09 10:17:44 +0000514 {0x1106, 0x8324, "CX700", enable_flash_vt823x},
Stefan Reinauerc6b5f492006-11-07 10:22:20 +0000515 {0x1106, 0x0686, "VT82C686", enable_flash_amd8111},
Uwe Hermannf4a673b2007-06-06 21:35:45 +0000516 {0x1078, 0x0100, "CS5530/CS5530A", enable_flash_cs5530},
Ollie Lho761bf1b2004-03-20 16:46:10 +0000517 {0x100b, 0x0510, "SC1100", enable_flash_sc1100},
Ollie Lhocbbf1252004-03-17 22:22:08 +0000518 {0x1039, 0x0008, "SIS5595", enable_flash_sis5595},
Lane Brooksd54958a2007-11-13 16:45:22 +0000519 {0x1022, 0x2080, "AMD GEODE CS5536", enable_flash_cs5536},
Ollie Lhocbbf1252004-03-17 22:22:08 +0000520 {0x1022, 0x7468, "AMD8111", enable_flash_amd8111},
Luc Verhaegen6b141752007-05-20 16:16:13 +0000521 {0x10B9, 0x1533, "ALi M1533", enable_flash_ali_m1533},
Uwe Hermanna7e05482007-05-09 10:17:44 +0000522 {0x10de, 0x0050, "NVIDIA CK804", enable_flash_ck804}, /* LPC */
523 {0x10de, 0x0051, "NVIDIA CK804", enable_flash_ck804}, /* Pro */
524 {0x10de, 0x00d3, "NVIDIA CK804", enable_flash_ck804}, /* Slave, should not be here, to fix known bug for A01. */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000525 {0x10de, 0x0260, "NVidia MCP51", enable_flash_ck804},
526 {0x10de, 0x0261, "NVidia MCP51", enable_flash_ck804},
527 {0x10de, 0x0262, "NVidia MCP51", enable_flash_ck804},
528 {0x10de, 0x0263, "NVidia MCP51", enable_flash_ck804},
Uwe Hermann372eeb52007-12-04 21:49:06 +0000529 {0x10de, 0x0360, "NVIDIA MCP55", enable_flash_mcp55}, /* M57SLI-S4 */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000530 {0x10de, 0x0361, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
531 {0x10de, 0x0362, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
532 {0x10de, 0x0363, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
533 {0x10de, 0x0364, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
534 {0x10de, 0x0365, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
535 {0x10de, 0x0366, "NVIDIA MCP55", enable_flash_mcp55}, /* LPC */
536 {0x10de, 0x0367, "NVIDIA MCP55", enable_flash_mcp55}, /* Pro */
Uwe Hermann372eeb52007-12-04 21:49:06 +0000537 {0x1002, 0x4377, "ATI SB400", enable_flash_sb400},
Uwe Hermanne823ee02007-06-05 15:02:18 +0000538 {0x1166, 0x0205, "Broadcom HT-1000", enable_flash_ht1000},
Ollie Lhocbbf1252004-03-17 22:22:08 +0000539};
Ollie Lho761bf1b2004-03-20 16:46:10 +0000540
Uwe Hermanna7e05482007-05-09 10:17:44 +0000541int chipset_flash_enable(void)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000542{
Uwe Hermanna7e05482007-05-09 10:17:44 +0000543 struct pci_dev *dev = 0;
Uwe Hermann372eeb52007-12-04 21:49:06 +0000544 int ret = -2; /* Nothing! */
Uwe Hermanna7e05482007-05-09 10:17:44 +0000545 int i;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000546
Uwe Hermann372eeb52007-12-04 21:49:06 +0000547 /* Now let's try to find the chipset we have... */
548 /* TODO: Use ARRAY_SIZE. */
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000549 for (i = 0; i < sizeof(enables) / sizeof(enables[0]); i++) {
Uwe Hermanna7e05482007-05-09 10:17:44 +0000550 dev = pci_dev_find(enables[i].vendor, enables[i].device);
551 if (dev)
552 break;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000553 }
554
Uwe Hermanna7e05482007-05-09 10:17:44 +0000555 if (dev) {
Uwe Hermanna502dce2007-10-17 23:55:15 +0000556 printf("Found chipset \"%s\", enabling flash write... ",
Uwe Hermanna7e05482007-05-09 10:17:44 +0000557 enables[i].name);
558
559 ret = enables[i].doit(dev, enables[i].name);
560 if (ret)
Uwe Hermanna502dce2007-10-17 23:55:15 +0000561 printf("FAILED!\n");
Uwe Hermanna7e05482007-05-09 10:17:44 +0000562 else
Uwe Hermannac309342007-10-10 17:42:20 +0000563 printf("OK.\n");
Uwe Hermanna7e05482007-05-09 10:17:44 +0000564 }
565
566 return ret;
Ollie Lhocbbf1252004-03-17 22:22:08 +0000567}