Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 2 | * This file is part of the flashrom project. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 3 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 4 | * Copyright (C) 2005-2007 coresystems GmbH <stepan@coresystems.de> |
| 5 | * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de> |
| 6 | * Copyright (C) 2007 Luc Verhaegen <libv@skynet.be> |
Carl-Daniel Hailfinger | 9224262 | 2007-09-27 14:29:57 +0000 | [diff] [blame^] | 7 | * Copyright (C) 2007 Carl-Daniel Hailfinger |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 8 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; version 2 of the License. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 12 | * |
Uwe Hermann | d110764 | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * Contains the board specific flash enables. |
| 25 | */ |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <pci/pci.h> |
| 29 | #include <stdint.h> |
| 30 | #include <string.h> |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 31 | #include "flash.h" |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 32 | |
Carl-Daniel Hailfinger | 9224262 | 2007-09-27 14:29:57 +0000 | [diff] [blame^] | 33 | /* Generic Super I/O helper functions */ |
| 34 | uint8_t regval(uint16_t port, uint8_t reg) |
| 35 | { |
| 36 | outb(reg, port); |
| 37 | return inb(port + 1); |
| 38 | } |
| 39 | |
| 40 | void regwrite(uint16_t port, uint8_t reg, uint8_t val) |
| 41 | { |
| 42 | outb(reg, port); |
| 43 | outb(val, port + 1); |
| 44 | } |
| 45 | |
| 46 | /* Helper functions for most recent ITE IT87xx Super I/O chips */ |
| 47 | #define CHIP_ID_BYTE1_REG 0x20 |
| 48 | #define CHIP_ID_BYTE2_REG 0x21 |
| 49 | static void enter_conf_mode_ite(uint16_t port) |
| 50 | { |
| 51 | outb(0x87, port); |
| 52 | outb(0x01, port); |
| 53 | outb(0x55, port); |
| 54 | if (port == 0x2e) |
| 55 | outb(0x55, port); |
| 56 | else |
| 57 | outb(0xaa, port); |
| 58 | } |
| 59 | |
| 60 | static void exit_conf_mode_ite(uint16_t port) |
| 61 | { |
| 62 | regwrite(port, 0x02, 0x02); |
| 63 | } |
| 64 | |
| 65 | static uint16_t find_ite_serial_flash_port(uint16_t port) |
| 66 | { |
| 67 | uint8_t tmp = 0; |
| 68 | uint16_t id, flashport = 0; |
| 69 | |
| 70 | enter_conf_mode_ite(port); |
| 71 | |
| 72 | id = regval(port, CHIP_ID_BYTE1_REG) << 8; |
| 73 | id |= regval(port, CHIP_ID_BYTE2_REG); |
| 74 | |
| 75 | /* TODO: Handle more IT87xx if they support flash translation */ |
| 76 | if (id == 0x8716) { |
| 77 | /* NOLDN, reg 0x24, mask out lowest bit (suspend) */ |
| 78 | tmp = regval(port, 0x24) & 0xFE; |
| 79 | printf("Serial flash segment 0x%08x-0x%08x %sabled\n", |
| 80 | 0xFFFE0000, 0xFFFFFFFF, (tmp & 1 << 1) ? "en" : "dis"); |
| 81 | printf("Serial flash segment 0x%08x-0x%08x %sabled\n", |
| 82 | 0x000E0000, 0x000FFFFF, (tmp & 1 << 1) ? "en" : "dis"); |
| 83 | printf("Serial flash segment 0x%08x-0x%08x %sabled\n", |
| 84 | 0xFFEE0000, 0xFFEFFFFF, (tmp & 1 << 2) ? "en" : "dis"); |
| 85 | printf("Serial flash segment 0x%08x-0x%08x %sabled\n", |
| 86 | 0xFFF80000, 0xFFFEFFFF, (tmp & 1 << 3) ? "en" : "dis"); |
| 87 | printf("LPC write to serial flash %sabled\n", |
| 88 | (tmp & 1 << 4) ? "en" : "dis"); |
| 89 | printf("serial flash pin %i\n", (tmp & 1 << 5) ? 87 : 29); |
| 90 | /* LDN 0x7, reg 0x64/0x65 */ |
| 91 | regwrite(port, 0x07, 0x7); |
| 92 | flashport = regval(port, 0x64) << 8; |
| 93 | flashport |= regval(port, 0x65); |
| 94 | } |
| 95 | exit_conf_mode_ite(port); |
| 96 | return flashport; |
| 97 | } |
| 98 | |
| 99 | static void it8716_serial_rdid(uint16_t port) |
| 100 | { |
| 101 | uint8_t busy, data0, data1, data2; |
| 102 | do { |
| 103 | busy = inb(port) & 0x80; |
| 104 | } while (busy); |
| 105 | /* RDID */ |
| 106 | outb(0x9f, port + 1); |
| 107 | /* Start IO, 33MHz, 3 input bytes, 0 output bytes*/ |
| 108 | outb((0x5<<4)|(0x3<<2)|(0x0), port); |
| 109 | do { |
| 110 | busy = inb(port) & 0x80; |
| 111 | } while (busy); |
| 112 | data0 = inb(port + 5); |
| 113 | data1 = inb(port + 6); |
| 114 | data2 = inb(port + 7); |
| 115 | printf("RDID returned %02x %02x %02x\n", data0, data1, data2); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | static int it87xx_probe_serial_flash(const char *name) |
| 120 | { |
| 121 | uint16_t flashport; |
| 122 | flashport = find_ite_serial_flash_port(0x2e); |
| 123 | if (flashport) |
| 124 | it8716_serial_rdid(flashport); |
| 125 | flashport = find_ite_serial_flash_port(0x4e); |
| 126 | if (flashport) |
| 127 | it8716_serial_rdid(flashport); |
| 128 | return 0; |
| 129 | } |
| 130 | |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 131 | /* |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 132 | * Helper functions for many Winbond Super I/Os of the W836xx range. |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 133 | */ |
| 134 | #define W836_INDEX 0x2E |
| 135 | #define W836_DATA 0x2F |
| 136 | |
| 137 | /* Enter extended functions */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 138 | static void w836xx_ext_enter(void) |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 139 | { |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 140 | outb(0x87, W836_INDEX); |
| 141 | outb(0x87, W836_INDEX); |
| 142 | } |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 143 | |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 144 | /* Leave extended functions */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 145 | static void w836xx_ext_leave(void) |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 146 | { |
| 147 | outb(0xAA, W836_INDEX); |
| 148 | } |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 149 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 150 | /* General functions for reading/writing Winbond Super I/Os. */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 151 | static unsigned char wbsio_read(unsigned char index) |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 152 | { |
| 153 | outb(index, W836_INDEX); |
| 154 | return inb(W836_DATA); |
| 155 | } |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 156 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 157 | static void wbsio_write(unsigned char index, unsigned char data) |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 158 | { |
| 159 | outb(index, W836_INDEX); |
| 160 | outb(data, W836_DATA); |
| 161 | } |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 162 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 163 | static void wbsio_mask(unsigned char index, unsigned char data, |
| 164 | unsigned char mask) |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 165 | { |
| 166 | unsigned char tmp; |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 167 | |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 168 | outb(index, W836_INDEX); |
| 169 | tmp = inb(W836_DATA) & ~mask; |
| 170 | outb(tmp | (data & mask), W836_DATA); |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 173 | /** |
| 174 | * Winbond W83627HF: Raise GPIO24. |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 175 | * |
| 176 | * Suited for: |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 177 | * - Agami Aruma |
| 178 | * - IWILL DK8-HTX |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 179 | */ |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 180 | static int w83627hf_gpio24_raise(const char *name) |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 181 | { |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 182 | w836xx_ext_enter(); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 183 | |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 184 | /* Is this the w83627hf? */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 185 | if (wbsio_read(0x20) != 0x52) { /* SIO device ID register */ |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 186 | fprintf(stderr, "\nERROR: %s: W83627HF: Wrong ID: 0x%02X.\n", |
| 187 | name, wbsio_read(0x20)); |
| 188 | w836xx_ext_leave(); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 189 | return -1; |
| 190 | } |
| 191 | |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 192 | /* PIN89S: WDTO/GP24 multiplex -> GPIO24 */ |
| 193 | wbsio_mask(0x2B, 0x10, 0x10); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 194 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 195 | wbsio_write(0x07, 0x08); /* Select logical device 8: GPIO port 2 */ |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 196 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 197 | wbsio_mask(0x30, 0x01, 0x01); /* Activate logical device. */ |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 198 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 199 | wbsio_mask(0xF0, 0x00, 0x10); /* GPIO24 -> output */ |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 200 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 201 | wbsio_mask(0xF2, 0x00, 0x10); /* Clear GPIO24 inversion */ |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 202 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 203 | wbsio_mask(0xF1, 0x10, 0x10); /* Raise GPIO24 */ |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 204 | |
| 205 | w836xx_ext_leave(); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 206 | |
| 207 | return 0; |
| 208 | } |
| 209 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 210 | /** |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 211 | * Suited for VIAs EPIA M and MII, and maybe other CLE266 based EPIAs. |
| 212 | * |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 213 | * We don't need to do this when using LinuxBIOS, GPIO15 is never lowered there. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 214 | */ |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 215 | static int board_via_epia_m(const char *name) |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 216 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 217 | struct pci_dev *dev; |
| 218 | unsigned int base; |
| 219 | uint8_t val; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 220 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 221 | dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */ |
| 222 | if (!dev) { |
| 223 | fprintf(stderr, "\nERROR: VT8235 ISA Bridge not found.\n"); |
| 224 | return -1; |
| 225 | } |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 226 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 227 | /* GPIO12-15 -> output */ |
| 228 | val = pci_read_byte(dev, 0xE4); |
| 229 | val |= 0x10; |
| 230 | pci_write_byte(dev, 0xE4, val); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 231 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 232 | /* Get Power Management IO address. */ |
| 233 | base = pci_read_word(dev, 0x88) & 0xFF80; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 234 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 235 | /* enable GPIO15 which is connected to write protect. */ |
| 236 | val = inb(base + 0x4D); |
| 237 | val |= 0x80; |
| 238 | outb(val, base + 0x4D); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 239 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 240 | return 0; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 243 | /** |
Luc Verhaegen | 3270754 | 2007-07-04 17:51:49 +0000 | [diff] [blame] | 244 | * Suited for: |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 245 | * - ASUS A7V8X-MX SE and A7V400-MX: AMD K7 + VIA KM400A + VT8235 |
| 246 | * - Tyan Tomcat K7M: AMD Geode NX + VIA KM400 + VT8237. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 247 | */ |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 248 | static int board_asus_a7v8x_mx(const char *name) |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 249 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 250 | struct pci_dev *dev; |
| 251 | uint8_t val; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 252 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 253 | dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */ |
Luc Verhaegen | 3270754 | 2007-07-04 17:51:49 +0000 | [diff] [blame] | 254 | if (!dev) |
| 255 | dev = pci_dev_find(0x1106, 0x3227); /* VT8237 ISA bridge */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 256 | if (!dev) { |
Luc Verhaegen | 3270754 | 2007-07-04 17:51:49 +0000 | [diff] [blame] | 257 | fprintf(stderr, "\nERROR: VT823x ISA bridge not found.\n"); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 258 | return -1; |
| 259 | } |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 260 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 261 | /* This bit is marked reserved actually */ |
| 262 | val = pci_read_byte(dev, 0x59); |
| 263 | val &= 0x7F; |
| 264 | pci_write_byte(dev, 0x59, val); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 265 | |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 266 | /* Raise ROM MEMW# line on Winbond w83697 SuperIO */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 267 | w836xx_ext_enter(); |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 268 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 269 | if (!(wbsio_read(0x24) & 0x02)) /* flash rom enabled? */ |
| 270 | wbsio_mask(0x24, 0x08, 0x08); /* enable MEMW# */ |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 271 | |
| 272 | w836xx_ext_leave(); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 273 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 274 | return 0; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 277 | /** |
Luc Verhaegen | 6b14175 | 2007-05-20 16:16:13 +0000 | [diff] [blame] | 278 | * Suited for ASUS P5A. |
| 279 | * |
| 280 | * This is rather nasty code, but there's no way to do this cleanly. |
| 281 | * We're basically talking to some unknown device on SMBus, my guess |
| 282 | * is that it is the Winbond W83781D that lives near the DIP BIOS. |
| 283 | */ |
Luc Verhaegen | 6b14175 | 2007-05-20 16:16:13 +0000 | [diff] [blame] | 284 | static int board_asus_p5a(const char *name) |
| 285 | { |
| 286 | uint8_t tmp; |
| 287 | int i; |
| 288 | |
| 289 | #define ASUSP5A_LOOP 5000 |
| 290 | |
| 291 | outb(0x00, 0xE807); |
| 292 | outb(0xEF, 0xE803); |
| 293 | |
| 294 | outb(0xFF, 0xE800); |
| 295 | |
| 296 | for (i = 0; i < ASUSP5A_LOOP; i++) { |
| 297 | outb(0xE1, 0xFF); |
| 298 | if (inb(0xE800) & 0x04) |
| 299 | break; |
| 300 | } |
| 301 | |
| 302 | if (i == ASUSP5A_LOOP) { |
| 303 | printf("%s: Unable to contact device.\n", name); |
| 304 | return -1; |
| 305 | } |
| 306 | |
| 307 | outb(0x20, 0xE801); |
| 308 | outb(0x20, 0xE1); |
| 309 | |
| 310 | outb(0xFF, 0xE802); |
| 311 | |
| 312 | for (i = 0; i < ASUSP5A_LOOP; i++) { |
| 313 | tmp = inb(0xE800); |
| 314 | if (tmp & 0x70) |
| 315 | break; |
| 316 | } |
| 317 | |
| 318 | if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) { |
| 319 | printf("%s: failed to read device.\n", name); |
| 320 | return -1; |
| 321 | } |
| 322 | |
| 323 | tmp = inb(0xE804); |
| 324 | tmp &= ~0x02; |
| 325 | |
| 326 | outb(0x00, 0xE807); |
| 327 | outb(0xEE, 0xE803); |
| 328 | |
| 329 | outb(tmp, 0xE804); |
| 330 | |
| 331 | outb(0xFF, 0xE800); |
| 332 | outb(0xE1, 0xFF); |
| 333 | |
| 334 | outb(0x20, 0xE801); |
| 335 | outb(0x20, 0xE1); |
| 336 | |
| 337 | outb(0xFF, 0xE802); |
| 338 | |
| 339 | for (i = 0; i < ASUSP5A_LOOP; i++) { |
| 340 | tmp = inb(0xE800); |
| 341 | if (tmp & 0x70) |
| 342 | break; |
| 343 | } |
| 344 | |
| 345 | if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) { |
| 346 | printf("%s: failed to write to device.\n", name); |
| 347 | return -1; |
| 348 | } |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
Stefan Reinauer | 1c283f4 | 2007-06-05 12:51:52 +0000 | [diff] [blame] | 353 | static int board_ibm_x3455(const char *name) |
| 354 | { |
| 355 | uint8_t byte; |
| 356 | |
Uwe Hermann | e823ee0 | 2007-06-05 15:02:18 +0000 | [diff] [blame] | 357 | /* Set GPIO lines in the Broadcom HT-1000 southbridge. */ |
Stefan Reinauer | 1c283f4 | 2007-06-05 12:51:52 +0000 | [diff] [blame] | 358 | outb(0x45, 0xcd6); |
| 359 | byte = inb(0xcd7); |
Uwe Hermann | e823ee0 | 2007-06-05 15:02:18 +0000 | [diff] [blame] | 360 | outb(byte | 0x20, 0xcd7); |
Stefan Reinauer | 1c283f4 | 2007-06-05 12:51:52 +0000 | [diff] [blame] | 361 | |
| 362 | return 0; |
| 363 | } |
| 364 | |
Luc Verhaegen | fdd0c58 | 2007-08-11 16:59:11 +0000 | [diff] [blame] | 365 | /** |
| 366 | * Suited for EPoX EP-BX3, and maybe some other Intel 440BX based boards. |
| 367 | */ |
| 368 | static int board_epox_ep_bx3(const char *name) |
| 369 | { |
| 370 | uint8_t tmp; |
| 371 | |
| 372 | /* Raise GPIO22. */ |
| 373 | tmp = inb(0x4036); |
| 374 | outb(tmp, 0xEB); |
| 375 | |
| 376 | tmp |= 0x40; |
| 377 | |
| 378 | outb(tmp, 0x4036); |
| 379 | outb(tmp, 0xEB); |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 384 | /** |
| 385 | * We use 2 sets of IDs here, you're free to choose which is which. This |
| 386 | * is to provide a very high degree of certainty when matching a board on |
| 387 | * the basis of subsystem/card IDs. As not every vendor handles |
| 388 | * subsystem/card IDs in a sane manner. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 389 | * |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 390 | * Keep the second set NULLed if it should be ignored. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 391 | */ |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 392 | struct board_pciid_enable { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 393 | /* Any device, but make it sensible, like the isa bridge. */ |
| 394 | uint16_t first_vendor; |
| 395 | uint16_t first_device; |
| 396 | uint16_t first_card_vendor; |
| 397 | uint16_t first_card_device; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 398 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 399 | /* Any device, but make it sensible, like |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 400 | * the host bridge. May be NULL |
| 401 | */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 402 | uint16_t second_vendor; |
| 403 | uint16_t second_device; |
| 404 | uint16_t second_card_vendor; |
| 405 | uint16_t second_card_device; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 406 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 407 | /* From linuxbios table */ |
| 408 | char *lb_vendor; |
| 409 | char *lb_part; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 410 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 411 | char *name; |
| 412 | int (*enable) (const char *name); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 413 | }; |
| 414 | |
| 415 | struct board_pciid_enable board_pciid_enables[] = { |
Carl-Daniel Hailfinger | 9224262 | 2007-09-27 14:29:57 +0000 | [diff] [blame^] | 416 | {0x10de, 0x0360, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 417 | "gigabyte", "m57sli", "GIGABYTE GA-M57SLI", it87xx_probe_serial_flash}, |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 418 | {0x1022, 0x7468, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 419 | "iwill", "dk8_htx", "IWILL DK8-HTX", w83627hf_gpio24_raise}, |
| 420 | {0x1022, 0x746B, 0x1022, 0x36C0, 0x0000, 0x0000, 0x0000, 0x0000, |
| 421 | "AGAMI", "ARUMA", "agami Aruma", w83627hf_gpio24_raise}, |
| 422 | {0x1106, 0x3177, 0x1106, 0xAA01, 0x1106, 0x3123, 0x1106, 0xAA01, |
| 423 | NULL, NULL, "VIA EPIA M/MII/...", board_via_epia_m}, |
| 424 | {0x1106, 0x3177, 0x1043, 0x80A1, 0x1106, 0x3205, 0x1043, 0x8118, |
| 425 | NULL, NULL, "ASUS A7V8-MX SE", board_asus_a7v8x_mx}, |
Luc Verhaegen | 3270754 | 2007-07-04 17:51:49 +0000 | [diff] [blame] | 426 | {0x8086, 0x1076, 0x8086, 0x1176, 0x1106, 0x3059, 0x10f1, 0x2498, |
| 427 | NULL, NULL, "Tyan Tomcat K7M", board_asus_a7v8x_mx}, |
Luc Verhaegen | 6b14175 | 2007-05-20 16:16:13 +0000 | [diff] [blame] | 428 | {0x10B9, 0x1541, 0x0000, 0x0000, 0x10B9, 0x1533, 0x0000, 0x0000, |
| 429 | "asus", "p5a", "ASUS P5A", board_asus_p5a}, |
Stefan Reinauer | 1c283f4 | 2007-06-05 12:51:52 +0000 | [diff] [blame] | 430 | {0x1166, 0x0205, 0x1014, 0x0347, 0x0000, 0x0000, 0x0000, 0x0000, |
| 431 | "ibm", "x3455", "IBM x3455", board_ibm_x3455}, |
Luc Verhaegen | fdd0c58 | 2007-08-11 16:59:11 +0000 | [diff] [blame] | 432 | {0x8086, 0x7110, 0x0000, 0x0000, 0x8086, 0x7190, 0x0000, 0x0000, |
| 433 | "epox", "ep-bx3", "EPoX EP-BX3", board_epox_ep_bx3}, |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 434 | {0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL} /* Keep this */ |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 435 | }; |
| 436 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 437 | /** |
| 438 | * Match boards on LinuxBIOS table gathered vendor and part name. |
| 439 | * Require main PCI IDs to match too as extra safety. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 440 | */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 441 | static struct board_pciid_enable *board_match_linuxbios_name(char *vendor, |
| 442 | char *part) |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 443 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 444 | struct board_pciid_enable *board = board_pciid_enables; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 445 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 446 | for (; board->name; board++) { |
| 447 | if (!board->lb_vendor || strcmp(board->lb_vendor, vendor)) |
| 448 | continue; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 449 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 450 | if (!board->lb_part || strcmp(board->lb_part, part)) |
| 451 | continue; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 452 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 453 | if (!pci_dev_find(board->first_vendor, board->first_device)) |
| 454 | continue; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 455 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 456 | if (board->second_vendor && |
| 457 | !pci_dev_find(board->second_vendor, board->second_device)) |
| 458 | continue; |
| 459 | return board; |
| 460 | } |
| 461 | return NULL; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 464 | /** |
| 465 | * Match boards on PCI IDs and subsystem IDs. |
| 466 | * Second set of IDs can be main only or missing completely. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 467 | */ |
| 468 | static struct board_pciid_enable *board_match_pci_card_ids(void) |
| 469 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 470 | struct board_pciid_enable *board = board_pciid_enables; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 471 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 472 | for (; board->name; board++) { |
| 473 | if (!board->first_card_vendor || !board->first_card_device) |
| 474 | continue; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 475 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 476 | if (!pci_card_find(board->first_vendor, board->first_device, |
| 477 | board->first_card_vendor, |
| 478 | board->first_card_device)) |
| 479 | continue; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 480 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 481 | if (board->second_vendor) { |
| 482 | if (board->second_card_vendor) { |
| 483 | if (!pci_card_find(board->second_vendor, |
| 484 | board->second_device, |
| 485 | board->second_card_vendor, |
| 486 | board->second_card_device)) |
| 487 | continue; |
| 488 | } else { |
| 489 | if (!pci_dev_find(board->second_vendor, |
| 490 | board->second_device)) |
| 491 | continue; |
| 492 | } |
| 493 | } |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 494 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 495 | return board; |
| 496 | } |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 497 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 498 | return NULL; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 499 | } |
| 500 | |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 501 | int board_flash_enable(char *vendor, char *part) |
| 502 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 503 | struct board_pciid_enable *board = NULL; |
| 504 | int ret = 0; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 505 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 506 | if (vendor && part) |
| 507 | board = board_match_linuxbios_name(vendor, part); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 508 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 509 | if (!board) |
| 510 | board = board_match_pci_card_ids(); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 511 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 512 | if (board) { |
| 513 | printf("Found board \"%s\": Enabling flash write... ", |
| 514 | board->name); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 515 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 516 | ret = board->enable(board->name); |
| 517 | if (ret) |
| 518 | printf("Failed!\n"); |
| 519 | else |
| 520 | printf("OK.\n"); |
| 521 | } |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 522 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 523 | return ret; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 524 | } |