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 | |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 33 | /* |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 34 | * Helper functions for many Winbond Super I/Os of the W836xx range. |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 35 | */ |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 36 | /* Enter extended functions */ |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 37 | static void w836xx_ext_enter(uint16_t port) |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 38 | { |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 39 | outb(0x87, port); |
| 40 | outb(0x87, port); |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 41 | } |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 42 | |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 43 | /* Leave extended functions */ |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 44 | static void w836xx_ext_leave(uint16_t port) |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 45 | { |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 46 | outb(0xAA, port); |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 47 | } |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 48 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 49 | /* General functions for reading/writing Winbond Super I/Os. */ |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 50 | static unsigned char wbsio_read(uint16_t index, uint8_t reg) |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 51 | { |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 52 | outb(reg, index); |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 53 | return inb(index + 1); |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 54 | } |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 55 | |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 56 | static void wbsio_write(uint16_t index, uint8_t reg, uint8_t data) |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 57 | { |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 58 | outb(reg, index); |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 59 | outb(data, index + 1); |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 60 | } |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 61 | |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 62 | static void wbsio_mask(uint16_t index, uint8_t reg, uint8_t data, uint8_t mask) |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 63 | { |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 64 | uint8_t tmp; |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 65 | |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 66 | outb(reg, index); |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 67 | tmp = inb(index + 1) & ~mask; |
| 68 | outb(tmp | (data & mask), index + 1); |
Mondrian Nuessle | aef1c7c | 2007-05-03 10:09:23 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 71 | /** |
| 72 | * Winbond W83627HF: Raise GPIO24. |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 73 | * |
| 74 | * Suited for: |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 75 | * - Agami Aruma |
| 76 | * - IWILL DK8-HTX |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 77 | */ |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 78 | static int w83627hf_gpio24_raise(uint16_t index, const char *name) |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 79 | { |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 80 | w836xx_ext_enter(index); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 81 | |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 82 | /* Is this the W83627HF? */ |
| 83 | if (wbsio_read(index, 0x20) != 0x52) { /* Super I/O device ID reg. */ |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 84 | fprintf(stderr, "\nERROR: %s: W83627HF: Wrong ID: 0x%02X.\n", |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 85 | name, wbsio_read(index, 0x20)); |
| 86 | w836xx_ext_leave(index); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 87 | return -1; |
| 88 | } |
| 89 | |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 90 | /* PIN89S: WDTO/GP24 multiplex -> GPIO24 */ |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 91 | wbsio_mask(index, 0x2B, 0x10, 0x10); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 92 | |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 93 | /* Select logical device 8: GPIO port 2 */ |
| 94 | wbsio_write(index, 0x07, 0x08); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 95 | |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 96 | wbsio_mask(index, 0x30, 0x01, 0x01); /* Activate logical device. */ |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 97 | wbsio_mask(index, 0xF0, 0x00, 0x10); /* GPIO24 -> output */ |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 98 | wbsio_mask(index, 0xF2, 0x00, 0x10); /* Clear GPIO24 inversion */ |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 99 | wbsio_mask(index, 0xF1, 0x10, 0x10); /* Raise GPIO24 */ |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 100 | |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 101 | w836xx_ext_leave(index); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 106 | static int w83627hf_gpio24_raise_2e(const char *name) |
| 107 | { |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 108 | /* TODO: Typo? Shouldn't this be 0x2e? */ |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 109 | return w83627hf_gpio24_raise(0x2d, name); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Winbond W83627THF: GPIO 4, bit 4 |
| 114 | * |
| 115 | * Suited for: |
| 116 | * - MSI K8N-NEO3 |
| 117 | */ |
| 118 | static int w83627thf_gpio4_4_raise(uint16_t index, const char *name) |
| 119 | { |
| 120 | w836xx_ext_enter(index); |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 121 | |
| 122 | /* Is this the W83627THF? */ |
| 123 | if (wbsio_read(index, 0x20) != 0x82) { /* Super I/O device ID reg. */ |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 124 | fprintf(stderr, "\nERROR: %s: W83627THF: Wrong ID: 0x%02X.\n", |
| 125 | name, wbsio_read(index, 0x20)); |
| 126 | w836xx_ext_leave(index); |
| 127 | return -1; |
| 128 | } |
| 129 | |
| 130 | /* PINxxxxS: GPIO4/bit 4 multiplex -> GPIOXXX */ |
| 131 | |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 132 | wbsio_write(index, 0x07, 0x09); /* Select LDN 9: GPIO port 4 */ |
| 133 | wbsio_mask(index, 0x30, 0x02, 0x02); /* Activate logical device. */ |
| 134 | wbsio_mask(index, 0xF4, 0x00, 0x10); /* GPIO4 bit 4 -> output */ |
| 135 | wbsio_mask(index, 0xF6, 0x00, 0x10); /* Clear GPIO4 bit 4 inversion */ |
| 136 | wbsio_mask(index, 0xF5, 0x10, 0x10); /* Raise GPIO4 bit 4 */ |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 137 | |
| 138 | w836xx_ext_leave(index); |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | static int w83627thf_gpio4_4_raise_4e(const char *name) |
| 144 | { |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 145 | return w83627thf_gpio4_4_raise(0x4e, name); |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 146 | } |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 147 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 148 | /** |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 149 | * Suited for VIAs EPIA M and MII, and maybe other CLE266 based EPIAs. |
| 150 | * |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 151 | * 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] | 152 | */ |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 153 | static int board_via_epia_m(const char *name) |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 154 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 155 | struct pci_dev *dev; |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 156 | uint16_t base; |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 157 | uint8_t val; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 158 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 159 | dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */ |
| 160 | if (!dev) { |
Uwe Hermann | a502dce | 2007-10-17 23:55:15 +0000 | [diff] [blame] | 161 | fprintf(stderr, "\nERROR: VT8235 ISA bridge not found.\n"); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 162 | return -1; |
| 163 | } |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 164 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 165 | /* GPIO12-15 -> output */ |
| 166 | val = pci_read_byte(dev, 0xE4); |
| 167 | val |= 0x10; |
| 168 | pci_write_byte(dev, 0xE4, val); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 169 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 170 | /* Get Power Management IO address. */ |
| 171 | base = pci_read_word(dev, 0x88) & 0xFF80; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 172 | |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 173 | /* Enable GPIO15 which is connected to write protect. */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 174 | val = inb(base + 0x4D); |
| 175 | val |= 0x80; |
| 176 | outb(val, base + 0x4D); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 177 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 178 | return 0; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 181 | /** |
Luc Verhaegen | 3270754 | 2007-07-04 17:51:49 +0000 | [diff] [blame] | 182 | * Suited for: |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 183 | * - ASUS A7V8X-MX SE and A7V400-MX: AMD K7 + VIA KM400A + VT8235 |
| 184 | * - Tyan Tomcat K7M: AMD Geode NX + VIA KM400 + VT8237. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 185 | */ |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 186 | static int board_asus_a7v8x_mx(const char *name) |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 187 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 188 | struct pci_dev *dev; |
| 189 | uint8_t val; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 190 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 191 | dev = pci_dev_find(0x1106, 0x3177); /* VT8235 ISA bridge */ |
Luc Verhaegen | 3270754 | 2007-07-04 17:51:49 +0000 | [diff] [blame] | 192 | if (!dev) |
| 193 | dev = pci_dev_find(0x1106, 0x3227); /* VT8237 ISA bridge */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 194 | if (!dev) { |
Luc Verhaegen | 3270754 | 2007-07-04 17:51:49 +0000 | [diff] [blame] | 195 | fprintf(stderr, "\nERROR: VT823x ISA bridge not found.\n"); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 196 | return -1; |
| 197 | } |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 198 | |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 199 | /* This bit is marked reserved actually. */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 200 | val = pci_read_byte(dev, 0x59); |
| 201 | val &= 0x7F; |
| 202 | pci_write_byte(dev, 0x59, val); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 203 | |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 204 | /* Raise ROM MEMW# line on Winbond W83697 Super I/O. */ |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 205 | w836xx_ext_enter(0x2E); |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 206 | |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 207 | if (!(wbsio_read(0x2E, 0x24) & 0x02)) /* Flash ROM enabled? */ |
| 208 | wbsio_mask(0x2E, 0x24, 0x08, 0x08); /* Enable MEMW#. */ |
Luc Verhaegen | 7977f4e | 2007-05-04 04:47:04 +0000 | [diff] [blame] | 209 | |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 210 | w836xx_ext_leave(0x2E); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 211 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 212 | return 0; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 215 | /** |
Luc Verhaegen | 6b14175 | 2007-05-20 16:16:13 +0000 | [diff] [blame] | 216 | * Suited for ASUS P5A. |
| 217 | * |
| 218 | * This is rather nasty code, but there's no way to do this cleanly. |
| 219 | * We're basically talking to some unknown device on SMBus, my guess |
| 220 | * is that it is the Winbond W83781D that lives near the DIP BIOS. |
| 221 | */ |
Luc Verhaegen | 6b14175 | 2007-05-20 16:16:13 +0000 | [diff] [blame] | 222 | static int board_asus_p5a(const char *name) |
| 223 | { |
| 224 | uint8_t tmp; |
| 225 | int i; |
| 226 | |
| 227 | #define ASUSP5A_LOOP 5000 |
| 228 | |
| 229 | outb(0x00, 0xE807); |
| 230 | outb(0xEF, 0xE803); |
| 231 | |
| 232 | outb(0xFF, 0xE800); |
| 233 | |
| 234 | for (i = 0; i < ASUSP5A_LOOP; i++) { |
| 235 | outb(0xE1, 0xFF); |
| 236 | if (inb(0xE800) & 0x04) |
| 237 | break; |
| 238 | } |
| 239 | |
| 240 | if (i == ASUSP5A_LOOP) { |
| 241 | printf("%s: Unable to contact device.\n", name); |
| 242 | return -1; |
| 243 | } |
| 244 | |
| 245 | outb(0x20, 0xE801); |
| 246 | outb(0x20, 0xE1); |
| 247 | |
| 248 | outb(0xFF, 0xE802); |
| 249 | |
| 250 | for (i = 0; i < ASUSP5A_LOOP; i++) { |
| 251 | tmp = inb(0xE800); |
| 252 | if (tmp & 0x70) |
| 253 | break; |
| 254 | } |
| 255 | |
| 256 | if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) { |
| 257 | printf("%s: failed to read device.\n", name); |
| 258 | return -1; |
| 259 | } |
| 260 | |
| 261 | tmp = inb(0xE804); |
| 262 | tmp &= ~0x02; |
| 263 | |
| 264 | outb(0x00, 0xE807); |
| 265 | outb(0xEE, 0xE803); |
| 266 | |
| 267 | outb(tmp, 0xE804); |
| 268 | |
| 269 | outb(0xFF, 0xE800); |
| 270 | outb(0xE1, 0xFF); |
| 271 | |
| 272 | outb(0x20, 0xE801); |
| 273 | outb(0x20, 0xE1); |
| 274 | |
| 275 | outb(0xFF, 0xE802); |
| 276 | |
| 277 | for (i = 0; i < ASUSP5A_LOOP; i++) { |
| 278 | tmp = inb(0xE800); |
| 279 | if (tmp & 0x70) |
| 280 | break; |
| 281 | } |
| 282 | |
| 283 | if ((i == ASUSP5A_LOOP) || !(tmp & 0x10)) { |
| 284 | printf("%s: failed to write to device.\n", name); |
| 285 | return -1; |
| 286 | } |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
Stefan Reinauer | 1c283f4 | 2007-06-05 12:51:52 +0000 | [diff] [blame] | 291 | static int board_ibm_x3455(const char *name) |
| 292 | { |
| 293 | uint8_t byte; |
| 294 | |
Uwe Hermann | e823ee0 | 2007-06-05 15:02:18 +0000 | [diff] [blame] | 295 | /* Set GPIO lines in the Broadcom HT-1000 southbridge. */ |
Stefan Reinauer | 1c283f4 | 2007-06-05 12:51:52 +0000 | [diff] [blame] | 296 | outb(0x45, 0xcd6); |
| 297 | byte = inb(0xcd7); |
Uwe Hermann | e823ee0 | 2007-06-05 15:02:18 +0000 | [diff] [blame] | 298 | outb(byte | 0x20, 0xcd7); |
Stefan Reinauer | 1c283f4 | 2007-06-05 12:51:52 +0000 | [diff] [blame] | 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
Luc Verhaegen | fdd0c58 | 2007-08-11 16:59:11 +0000 | [diff] [blame] | 303 | /** |
| 304 | * Suited for EPoX EP-BX3, and maybe some other Intel 440BX based boards. |
| 305 | */ |
| 306 | static int board_epox_ep_bx3(const char *name) |
| 307 | { |
| 308 | uint8_t tmp; |
| 309 | |
| 310 | /* Raise GPIO22. */ |
| 311 | tmp = inb(0x4036); |
| 312 | outb(tmp, 0xEB); |
| 313 | |
| 314 | tmp |= 0x40; |
| 315 | |
| 316 | outb(tmp, 0x4036); |
| 317 | outb(tmp, 0xEB); |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 322 | /** |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 323 | * Suited for Acorp 6A815EPD. |
Jonathan A. Kollasch | c778556 | 2007-12-02 19:03:23 +0000 | [diff] [blame] | 324 | */ |
| 325 | static int board_acorp_6a815epd(const char *name) |
| 326 | { |
| 327 | struct pci_dev *dev; |
| 328 | uint16_t port; |
| 329 | uint8_t val; |
| 330 | |
| 331 | dev = pci_dev_find(0x8086, 0x2440); /* Intel ICH2 LPC */ |
| 332 | if (!dev) { |
| 333 | fprintf(stderr, "\nERROR: ICH2 LPC bridge not found.\n"); |
| 334 | return -1; |
| 335 | } |
| 336 | |
| 337 | /* Use GPIOBASE register to find where the GPIO is mapped. */ |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 338 | port = (pci_read_word(dev, 0x58) & 0xFFC0) + 0xE; |
Jonathan A. Kollasch | c778556 | 2007-12-02 19:03:23 +0000 | [diff] [blame] | 339 | |
| 340 | val = inb(port); |
| 341 | val |= 0x80; /* Top Block Lock -- pin 8 of PLCC32 */ |
| 342 | val |= 0x40; /* Lower Blocks Lock -- pin 7 of PLCC32 */ |
| 343 | outb(val, port); |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | /** |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 349 | * We use 2 sets of IDs here, you're free to choose which is which. This |
| 350 | * is to provide a very high degree of certainty when matching a board on |
| 351 | * the basis of subsystem/card IDs. As not every vendor handles |
| 352 | * subsystem/card IDs in a sane manner. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 353 | * |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 354 | * Keep the second set NULLed if it should be ignored. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 355 | */ |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 356 | struct board_pciid_enable { |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 357 | /* Any device, but make it sensible, like the ISA bridge. */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 358 | uint16_t first_vendor; |
| 359 | uint16_t first_device; |
| 360 | uint16_t first_card_vendor; |
| 361 | uint16_t first_card_device; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 362 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 363 | /* Any device, but make it sensible, like |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 364 | * the host bridge. May be NULL. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 365 | */ |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 366 | uint16_t second_vendor; |
| 367 | uint16_t second_device; |
| 368 | uint16_t second_card_vendor; |
| 369 | uint16_t second_card_device; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 370 | |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 371 | /* The vendor / part name from the LinuxBIOS table. */ |
| 372 | const char *lb_vendor; |
| 373 | const char *lb_part; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 374 | |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 375 | const char *name; |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 376 | int (*enable) (const char *name); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 377 | }; |
| 378 | |
| 379 | struct board_pciid_enable board_pciid_enables[] = { |
Carl-Daniel Hailfinger | 9224262 | 2007-09-27 14:29:57 +0000 | [diff] [blame] | 380 | {0x10de, 0x0360, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
Uwe Hermann | a502dce | 2007-10-17 23:55:15 +0000 | [diff] [blame] | 381 | "gigabyte", "m57sli", "GIGABYTE GA-M57SLI-S4", it87xx_probe_spi_flash}, |
Michael van der Kolff | 3385cb8 | 2007-10-16 21:18:43 +0000 | [diff] [blame] | 382 | {0x10de, 0x03e0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
Uwe Hermann | a502dce | 2007-10-17 23:55:15 +0000 | [diff] [blame] | 383 | "gigabyte", "m61p", "GIGABYTE GA-M61P-S3", it87xx_probe_spi_flash}, |
Ronald G. Minnich | 8484d5a | 2008-01-04 17:22:44 +0000 | [diff] [blame] | 384 | {0x1039, 0x0761, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 385 | "gigabyte", "2761gxdk", "GIGABYTE GA-2761GXDK", it87xx_probe_spi_flash}, |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 386 | {0x1022, 0x7468, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 387 | "iwill", "dk8_htx", "IWILL DK8-HTX", w83627hf_gpio24_raise_2e}, |
| 388 | {0x10de, 0x005e, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
| 389 | "msi", "k8n-neo3", "MSI K8N Neo3", w83627thf_gpio4_4_raise_4e}, |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 390 | {0x1022, 0x746B, 0x1022, 0x36C0, 0x0000, 0x0000, 0x0000, 0x0000, |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 391 | "AGAMI", "ARUMA", "agami Aruma", w83627hf_gpio24_raise_2e}, |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 392 | {0x1106, 0x3177, 0x1106, 0xAA01, 0x1106, 0x3123, 0x1106, 0xAA01, |
| 393 | NULL, NULL, "VIA EPIA M/MII/...", board_via_epia_m}, |
| 394 | {0x1106, 0x3177, 0x1043, 0x80A1, 0x1106, 0x3205, 0x1043, 0x8118, |
| 395 | NULL, NULL, "ASUS A7V8-MX SE", board_asus_a7v8x_mx}, |
Luc Verhaegen | 3270754 | 2007-07-04 17:51:49 +0000 | [diff] [blame] | 396 | {0x8086, 0x1076, 0x8086, 0x1176, 0x1106, 0x3059, 0x10f1, 0x2498, |
| 397 | NULL, NULL, "Tyan Tomcat K7M", board_asus_a7v8x_mx}, |
Luc Verhaegen | 6b14175 | 2007-05-20 16:16:13 +0000 | [diff] [blame] | 398 | {0x10B9, 0x1541, 0x0000, 0x0000, 0x10B9, 0x1533, 0x0000, 0x0000, |
| 399 | "asus", "p5a", "ASUS P5A", board_asus_p5a}, |
Stefan Reinauer | 1c283f4 | 2007-06-05 12:51:52 +0000 | [diff] [blame] | 400 | {0x1166, 0x0205, 0x1014, 0x0347, 0x0000, 0x0000, 0x0000, 0x0000, |
| 401 | "ibm", "x3455", "IBM x3455", board_ibm_x3455}, |
Luc Verhaegen | fdd0c58 | 2007-08-11 16:59:11 +0000 | [diff] [blame] | 402 | {0x8086, 0x7110, 0x0000, 0x0000, 0x8086, 0x7190, 0x0000, 0x0000, |
| 403 | "epox", "ep-bx3", "EPoX EP-BX3", board_epox_ep_bx3}, |
Jonathan A. Kollasch | c778556 | 2007-12-02 19:03:23 +0000 | [diff] [blame] | 404 | {0x8086, 0x1130, 0x0000, 0x0000, 0x105a, 0x0d30, 0x105a, 0x4d33, |
| 405 | "acorp", "6a815epd", "Acorp 6A815EPD", board_acorp_6a815epd}, |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 406 | {0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL} /* Keep this */ |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 407 | }; |
| 408 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 409 | /** |
| 410 | * Match boards on LinuxBIOS table gathered vendor and part name. |
| 411 | * Require main PCI IDs to match too as extra safety. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 412 | */ |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 413 | static struct board_pciid_enable *board_match_linuxbios_name(const char *vendor, const char *part) |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 414 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 415 | struct board_pciid_enable *board = board_pciid_enables; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 416 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 417 | for (; board->name; board++) { |
| 418 | if (!board->lb_vendor || strcmp(board->lb_vendor, vendor)) |
| 419 | continue; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 420 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 421 | if (!board->lb_part || strcmp(board->lb_part, part)) |
| 422 | continue; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 423 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 424 | if (!pci_dev_find(board->first_vendor, board->first_device)) |
| 425 | continue; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 426 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 427 | if (board->second_vendor && |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 428 | !pci_dev_find(board->second_vendor, board->second_device)) |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 429 | continue; |
| 430 | return board; |
| 431 | } |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 432 | |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 433 | printf("NOT FOUND %s:%s\n", vendor, part); |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 434 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 435 | return NULL; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 438 | /** |
| 439 | * Match boards on PCI IDs and subsystem IDs. |
| 440 | * Second set of IDs can be main only or missing completely. |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 441 | */ |
| 442 | static struct board_pciid_enable *board_match_pci_card_ids(void) |
| 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->first_card_vendor || !board->first_card_device) |
| 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 (!pci_card_find(board->first_vendor, board->first_device, |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 451 | board->first_card_vendor, |
| 452 | board->first_card_device)) |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 453 | continue; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 454 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 455 | if (board->second_vendor) { |
| 456 | if (board->second_card_vendor) { |
| 457 | if (!pci_card_find(board->second_vendor, |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 458 | board->second_device, |
| 459 | board->second_card_vendor, |
| 460 | board->second_card_device)) |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 461 | continue; |
| 462 | } else { |
| 463 | if (!pci_dev_find(board->second_vendor, |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 464 | board->second_device)) |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 465 | continue; |
| 466 | } |
| 467 | } |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 468 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 469 | return board; |
| 470 | } |
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 | return NULL; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Uwe Hermann | 372eeb5 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 475 | int board_flash_enable(const char *vendor, const char *part) |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 476 | { |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 477 | struct board_pciid_enable *board = NULL; |
| 478 | int ret = 0; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 479 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 480 | if (vendor && part) |
| 481 | board = board_match_linuxbios_name(vendor, part); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 482 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 483 | if (!board) |
| 484 | board = board_match_pci_card_ids(); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 485 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 486 | if (board) { |
Uwe Hermann | a502dce | 2007-10-17 23:55:15 +0000 | [diff] [blame] | 487 | printf("Found board \"%s\": enabling flash write... ", |
Ronald G. Minnich | fa49692 | 2007-10-12 21:22:40 +0000 | [diff] [blame] | 488 | board->name); |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 489 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 490 | ret = board->enable(board->name); |
| 491 | if (ret) |
Uwe Hermann | a502dce | 2007-10-17 23:55:15 +0000 | [diff] [blame] | 492 | printf("FAILED!\n"); |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 493 | else |
| 494 | printf("OK.\n"); |
| 495 | } |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 496 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 497 | return ret; |
Luc Verhaegen | 8e3a600 | 2007-04-04 22:45:58 +0000 | [diff] [blame] | 498 | } |