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