hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
hailfinger | 4500b08 | 2009-07-11 18:05:42 +0000 | [diff] [blame] | 4 | * Copyright (C) 2007, 2008, 2009 Carl-Daniel Hailfinger |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 5 | * Copyright (C) 2008 Ronald Hoogenboom <ronald@zonnet.nl> |
stepan | 3bdf618 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 6 | * Copyright (C) 2008 coresystems GmbH |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | /* |
| 19 | * Contains the ITE IT87* SPI specific routines |
| 20 | */ |
| 21 | |
hailfinger | 324a9cc | 2010-05-26 01:45:41 +0000 | [diff] [blame] | 22 | #if defined(__i386__) || defined(__x86_64__) |
| 23 | |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 24 | #include <string.h> |
hailfinger | 4500b08 | 2009-07-11 18:05:42 +0000 | [diff] [blame] | 25 | #include <stdlib.h> |
Patrick Georgi | 048dbdb | 2017-04-11 20:45:07 +0200 | [diff] [blame] | 26 | #include <errno.h> |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 27 | #include "flash.h" |
snelson | 8913d08 | 2010-02-26 05:48:29 +0000 | [diff] [blame] | 28 | #include "chipdrivers.h" |
hailfinger | 428f685 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 29 | #include "programmer.h" |
Patrick Georgi | 048dbdb | 2017-04-11 20:45:07 +0200 | [diff] [blame] | 30 | #include "hwaccess.h" |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 31 | #include "spi.h" |
| 32 | |
| 33 | #define ITE_SUPERIO_PORT1 0x2e |
| 34 | #define ITE_SUPERIO_PORT2 0x4e |
| 35 | |
Edward O'Callaghan | 85726e5 | 2020-11-17 18:11:47 +1100 | [diff] [blame^] | 36 | #define CHIP_ID_BYTE1_REG 0x20 |
| 37 | #define CHIP_ID_BYTE2_REG 0x21 |
| 38 | #define CHIP_VER_REG 0x22 |
| 39 | |
Patrick Georgi | 048dbdb | 2017-04-11 20:45:07 +0200 | [diff] [blame] | 40 | static uint16_t it8716f_flashport = 0; |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 41 | /* use fast 33MHz SPI (<>0) or slow 16MHz (0) */ |
hailfinger | 1ff33dc | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 42 | static int fast_spi = 1; |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 43 | |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 44 | /* Helper functions for most recent ITE IT87xx Super I/O chips */ |
hailfinger | 7bac0e5 | 2009-05-25 23:26:50 +0000 | [diff] [blame] | 45 | void enter_conf_mode_ite(uint16_t port) |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 46 | { |
hailfinger | e1f062f | 2008-05-22 13:22:45 +0000 | [diff] [blame] | 47 | OUTB(0x87, port); |
| 48 | OUTB(0x01, port); |
| 49 | OUTB(0x55, port); |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 50 | if (port == ITE_SUPERIO_PORT1) |
hailfinger | e1f062f | 2008-05-22 13:22:45 +0000 | [diff] [blame] | 51 | OUTB(0x55, port); |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 52 | else |
hailfinger | e1f062f | 2008-05-22 13:22:45 +0000 | [diff] [blame] | 53 | OUTB(0xaa, port); |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 54 | } |
| 55 | |
hailfinger | 7bac0e5 | 2009-05-25 23:26:50 +0000 | [diff] [blame] | 56 | void exit_conf_mode_ite(uint16_t port) |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 57 | { |
hailfinger | 7bac0e5 | 2009-05-25 23:26:50 +0000 | [diff] [blame] | 58 | sio_write(port, 0x02, 0x02); |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Edward O'Callaghan | 9505295 | 2020-05-09 22:22:37 +1000 | [diff] [blame] | 61 | static uint16_t probe_id_ite(uint16_t port) |
hailfinger | c236f9e | 2009-12-22 23:42:04 +0000 | [diff] [blame] | 62 | { |
| 63 | uint16_t id; |
| 64 | |
| 65 | enter_conf_mode_ite(port); |
| 66 | id = sio_read(port, CHIP_ID_BYTE1_REG) << 8; |
| 67 | id |= sio_read(port, CHIP_ID_BYTE2_REG); |
| 68 | exit_conf_mode_ite(port); |
| 69 | |
| 70 | return id; |
| 71 | } |
| 72 | |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 73 | void probe_superio_ite(void) |
hailfinger | c236f9e | 2009-12-22 23:42:04 +0000 | [diff] [blame] | 74 | { |
Patrick Georgi | 8ddfee9 | 2017-03-20 14:54:28 +0100 | [diff] [blame] | 75 | struct superio s = {0}; |
hailfinger | c236f9e | 2009-12-22 23:42:04 +0000 | [diff] [blame] | 76 | uint16_t ite_ports[] = {ITE_SUPERIO_PORT1, ITE_SUPERIO_PORT2, 0}; |
| 77 | uint16_t *i = ite_ports; |
| 78 | |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 79 | s.vendor = SUPERIO_VENDOR_ITE; |
hailfinger | c236f9e | 2009-12-22 23:42:04 +0000 | [diff] [blame] | 80 | for (; *i; i++) { |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 81 | s.port = *i; |
| 82 | s.model = probe_id_ite(s.port); |
| 83 | switch (s.model >> 8) { |
hailfinger | c236f9e | 2009-12-22 23:42:04 +0000 | [diff] [blame] | 84 | case 0x82: |
| 85 | case 0x86: |
| 86 | case 0x87: |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 87 | /* FIXME: Print revision for all models? */ |
Patrick Georgi | 0548299 | 2017-03-20 21:56:33 +0100 | [diff] [blame] | 88 | msg_pdbg("Found ITE Super I/O, ID 0x%04hx on port 0x%x\n", s.model, s.port); |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 89 | register_superio(s); |
| 90 | break; |
| 91 | case 0x85: |
Patrick Georgi | 0548299 | 2017-03-20 21:56:33 +0100 | [diff] [blame] | 92 | msg_pdbg("Found ITE EC, ID 0x%04hx, Rev 0x%02x on port 0x%x.\n", |
Edward O'Callaghan | 9505295 | 2020-05-09 22:22:37 +1000 | [diff] [blame] | 93 | s.model, sio_read(s.port, CHIP_VER_REG), s.port); |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 94 | register_superio(s); |
| 95 | break; |
hailfinger | c236f9e | 2009-12-22 23:42:04 +0000 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 99 | return; |
hailfinger | c236f9e | 2009-12-22 23:42:04 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Edward O'Callaghan | 85726e5 | 2020-11-17 18:11:47 +1100 | [diff] [blame^] | 102 | /* Page size is usually 256 bytes */ |
| 103 | static int it8716f_spi_page_program(struct flashctx *flash, const uint8_t *buf, unsigned int start) |
| 104 | { |
| 105 | unsigned int i; |
| 106 | int result; |
| 107 | chipaddr bios = flash->virtual_memory; |
| 108 | |
| 109 | result = spi_write_enable(flash); |
| 110 | if (result) |
| 111 | return result; |
| 112 | /* FIXME: The command below seems to be redundant or wrong. */ |
| 113 | OUTB(0x06, it8716f_flashport + 1); |
| 114 | OUTB(((2 + (fast_spi ? 1 : 0)) << 4), it8716f_flashport); |
| 115 | for (i = 0; i < flash->chip->page_size; i++) |
| 116 | mmio_writeb(buf[i], (void *)(bios + start + i)); |
| 117 | OUTB(0, it8716f_flashport); |
| 118 | /* Wait until the Write-In-Progress bit is cleared. |
| 119 | * This usually takes 1-10 ms, so wait in 1 ms steps. |
| 120 | */ |
| 121 | while (spi_read_status_register(flash) & SPI_SR_WIP) |
| 122 | programmer_delay(1000); |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * The IT8716F only supports commands with length 1,2,4,5 bytes including |
| 128 | * command byte and can not read more than 3 bytes from the device. |
| 129 | * |
| 130 | * This function expects writearr[0] to be the first byte sent to the device, |
| 131 | * whereas the IT8716F splits commands internally into address and non-address |
| 132 | * commands with the address in inverse wire order. That's why the register |
| 133 | * ordering in case 4 and 5 may seem strange. |
| 134 | */ |
Patrick Georgi | 0548299 | 2017-03-20 21:56:33 +0100 | [diff] [blame] | 135 | static int it8716f_spi_send_command(const struct flashctx *flash, |
| 136 | unsigned int writecnt, unsigned int readcnt, |
| 137 | const unsigned char *writearr, |
Edward O'Callaghan | 85726e5 | 2020-11-17 18:11:47 +1100 | [diff] [blame^] | 138 | unsigned char *readarr) |
| 139 | { |
| 140 | uint8_t busy, writeenc; |
| 141 | |
| 142 | do { |
| 143 | busy = INB(it8716f_flashport) & 0x80; |
| 144 | } while (busy); |
| 145 | if (readcnt > 3) { |
| 146 | msg_pinfo("%s called with unsupported readcnt %i.\n", |
| 147 | __func__, readcnt); |
| 148 | return SPI_INVALID_LENGTH; |
| 149 | } |
| 150 | switch (writecnt) { |
| 151 | case 1: |
| 152 | OUTB(writearr[0], it8716f_flashport + 1); |
| 153 | writeenc = 0x0; |
| 154 | break; |
| 155 | case 2: |
| 156 | OUTB(writearr[0], it8716f_flashport + 1); |
| 157 | OUTB(writearr[1], it8716f_flashport + 7); |
| 158 | writeenc = 0x1; |
| 159 | break; |
| 160 | case 4: |
| 161 | OUTB(writearr[0], it8716f_flashport + 1); |
| 162 | OUTB(writearr[1], it8716f_flashport + 4); |
| 163 | OUTB(writearr[2], it8716f_flashport + 3); |
| 164 | OUTB(writearr[3], it8716f_flashport + 2); |
| 165 | writeenc = 0x2; |
| 166 | break; |
| 167 | case 5: |
| 168 | OUTB(writearr[0], it8716f_flashport + 1); |
| 169 | OUTB(writearr[1], it8716f_flashport + 4); |
| 170 | OUTB(writearr[2], it8716f_flashport + 3); |
| 171 | OUTB(writearr[3], it8716f_flashport + 2); |
| 172 | OUTB(writearr[4], it8716f_flashport + 7); |
| 173 | writeenc = 0x3; |
| 174 | break; |
| 175 | default: |
| 176 | msg_pinfo("%s called with unsupported writecnt %i.\n", |
| 177 | __func__, writecnt); |
| 178 | return SPI_INVALID_LENGTH; |
| 179 | } |
| 180 | /* |
| 181 | * Start IO, 33 or 16 MHz, readcnt input bytes, writecnt output bytes. |
| 182 | * Note: |
| 183 | * We can't use writecnt directly, but have to use a strange encoding. |
| 184 | */ |
| 185 | OUTB(((0x4 + (fast_spi ? 1 : 0)) << 4) |
| 186 | | ((readcnt & 0x3) << 2) | (writeenc), it8716f_flashport); |
| 187 | |
| 188 | if (readcnt > 0) { |
| 189 | unsigned int i; |
| 190 | |
| 191 | do { |
| 192 | busy = INB(it8716f_flashport) & 0x80; |
| 193 | } while (busy); |
| 194 | |
| 195 | for (i = 0; i < readcnt; i++) |
| 196 | readarr[i] = INB(it8716f_flashport + 5 + i); |
| 197 | } |
| 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | /* |
| 203 | * IT8716F only allows maximum of 512 kb SPI mapped to LPC memory cycles |
| 204 | * Need to read this big flash using firmware cycles 3 byte at a time. |
| 205 | */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 206 | static int it8716f_spi_chip_read(struct flashctx *flash, uint8_t *buf, |
Edward O'Callaghan | 85726e5 | 2020-11-17 18:11:47 +1100 | [diff] [blame^] | 207 | unsigned int start, unsigned int len) |
| 208 | { |
| 209 | fast_spi = 0; |
| 210 | |
| 211 | /* FIXME: Check if someone explicitly requested to use IT87 SPI although |
| 212 | * the mainboard does not use IT87 SPI translation. This should be done |
| 213 | * via a programmer parameter for the internal programmer. |
| 214 | */ |
| 215 | if ((flash->chip->total_size * 1024 > 512 * 1024)) { |
| 216 | default_spi_read(flash, buf, start, len); |
| 217 | } else { |
| 218 | mmio_readn((void *)(flash->virtual_memory + start), buf, len); |
| 219 | } |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
Patrick Georgi | ab8353e | 2017-02-03 18:32:01 +0100 | [diff] [blame] | 224 | static int it8716f_spi_chip_write_256(struct flashctx *flash, const uint8_t *buf, |
Edward O'Callaghan | 85726e5 | 2020-11-17 18:11:47 +1100 | [diff] [blame^] | 225 | unsigned int start, unsigned int len) |
| 226 | { |
| 227 | const struct flashchip *chip = flash->chip; |
| 228 | /* |
| 229 | * IT8716F only allows maximum of 512 kb SPI chip size for memory |
| 230 | * mapped access. It also can't write more than 1+3+256 bytes at once, |
| 231 | * so page_size > 256 bytes needs a fallback. |
| 232 | * FIXME: Split too big page writes into chunks IT87* can handle instead |
| 233 | * of degrading to single-byte program. |
| 234 | * FIXME: Check if someone explicitly requested to use IT87 SPI although |
| 235 | * the mainboard does not use IT87 SPI translation. This should be done |
| 236 | * via a programmer parameter for the internal programmer. |
| 237 | */ |
| 238 | if ((chip->total_size * 1024 > 512 * 1024) || (chip->page_size > 256)) { |
| 239 | spi_chip_write_1(flash, buf, start, len); |
| 240 | } else { |
| 241 | unsigned int lenhere; |
| 242 | |
| 243 | if (start % chip->page_size) { |
| 244 | /* start to the end of the page or to start + len, |
| 245 | * whichever is smaller. |
| 246 | */ |
| 247 | lenhere = min(len, chip->page_size - start % chip->page_size); |
| 248 | spi_chip_write_1(flash, buf, start, lenhere); |
| 249 | start += lenhere; |
| 250 | len -= lenhere; |
| 251 | buf += lenhere; |
| 252 | } |
| 253 | |
| 254 | while (len >= chip->page_size) { |
| 255 | it8716f_spi_page_program(flash, buf, start); |
| 256 | start += chip->page_size; |
| 257 | len -= chip->page_size; |
| 258 | buf += chip->page_size; |
| 259 | } |
| 260 | if (len) |
| 261 | spi_chip_write_1(flash, buf, start, len); |
| 262 | } |
| 263 | |
| 264 | return 0; |
| 265 | } |
mkarcher | d264e9e | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 266 | |
Patrick Georgi | f4f1e2f | 2017-03-10 17:38:40 +0100 | [diff] [blame] | 267 | static const struct spi_master spi_master_it87xx = { |
Edward O'Callaghan | 3941bee | 2020-10-09 13:00:17 +1100 | [diff] [blame] | 268 | .max_data_read = 3, |
uwe | 8d342eb | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 269 | .max_data_write = MAX_DATA_UNSPECIFIED, |
| 270 | .command = it8716f_spi_send_command, |
| 271 | .multicommand = default_spi_send_multicommand, |
| 272 | .read = it8716f_spi_chip_read, |
| 273 | .write_256 = it8716f_spi_chip_write_256, |
Edward O'Callaghan | 04ac730 | 2020-05-14 18:03:40 +1000 | [diff] [blame] | 274 | .write_aai = spi_chip_write_1, |
mkarcher | d264e9e | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 275 | }; |
| 276 | |
hailfinger | c73ce6e | 2010-07-10 16:56:32 +0000 | [diff] [blame] | 277 | static uint16_t it87spi_probe(uint16_t port) |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 278 | { |
| 279 | uint8_t tmp = 0; |
hailfinger | c236f9e | 2009-12-22 23:42:04 +0000 | [diff] [blame] | 280 | uint16_t flashport = 0; |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 281 | |
hailfinger | c73ce6e | 2010-07-10 16:56:32 +0000 | [diff] [blame] | 282 | enter_conf_mode_ite(port); |
Edward O'Callaghan | 9505295 | 2020-05-09 22:22:37 +1000 | [diff] [blame] | 283 | |
| 284 | char *param = extract_programmer_param("dualbiosindex"); |
| 285 | if (param != NULL) { |
| 286 | sio_write(port, 0x07, 0x07); /* Select GPIO LDN */ |
| 287 | tmp = sio_read(port, 0xEF); |
| 288 | if (*param == '\0') { /* Print current setting only. */ |
| 289 | free(param); |
| 290 | } else { |
| 291 | char *dualbiosindex_suffix; |
| 292 | errno = 0; |
| 293 | long chip_index = strtol(param, &dualbiosindex_suffix, 0); |
| 294 | free(param); |
| 295 | if (errno != 0 || *dualbiosindex_suffix != '\0' || chip_index < 0 || chip_index > 1) { |
| 296 | msg_perr("DualBIOS: Invalid chip index requested - choose 0 or 1.\n"); |
| 297 | exit_conf_mode_ite(port); |
| 298 | return 1; |
| 299 | } |
| 300 | if (chip_index != (tmp & 1)) { |
| 301 | msg_pdbg("DualBIOS: Previous chip index: %d\n", tmp & 1); |
| 302 | sio_write(port, 0xEF, (tmp & 0xFE) | chip_index); |
| 303 | tmp = sio_read(port, 0xEF); |
| 304 | if ((tmp & 1) != chip_index) { |
| 305 | msg_perr("DualBIOS: Chip selection failed.\n"); |
| 306 | exit_conf_mode_ite(port); |
| 307 | return 1; |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | msg_pinfo("DualBIOS: Selected chip: %d\n", tmp & 1); |
| 312 | } |
| 313 | |
hailfinger | c73ce6e | 2010-07-10 16:56:32 +0000 | [diff] [blame] | 314 | /* NOLDN, reg 0x24, mask out lowest bit (suspend) */ |
| 315 | tmp = sio_read(port, 0x24) & 0xFE; |
hailfinger | 969e2f3 | 2011-09-08 00:00:29 +0000 | [diff] [blame] | 316 | /* Check if LPC->SPI translation is active. */ |
| 317 | if (!(tmp & 0x0e)) { |
hailfinger | c73ce6e | 2010-07-10 16:56:32 +0000 | [diff] [blame] | 318 | msg_pdbg("No IT87* serial flash segment enabled.\n"); |
| 319 | exit_conf_mode_ite(port); |
| 320 | /* Nothing to do. */ |
David Hendricks | 5e79c9f | 2013-11-04 22:05:08 -0800 | [diff] [blame] | 321 | return 1; |
hailfinger | c73ce6e | 2010-07-10 16:56:32 +0000 | [diff] [blame] | 322 | } |
| 323 | msg_pdbg("Serial flash segment 0x%08x-0x%08x %sabled\n", |
| 324 | 0xFFFE0000, 0xFFFFFFFF, (tmp & 1 << 1) ? "en" : "dis"); |
| 325 | msg_pdbg("Serial flash segment 0x%08x-0x%08x %sabled\n", |
| 326 | 0x000E0000, 0x000FFFFF, (tmp & 1 << 1) ? "en" : "dis"); |
| 327 | msg_pdbg("Serial flash segment 0x%08x-0x%08x %sabled\n", |
| 328 | 0xFFEE0000, 0xFFEFFFFF, (tmp & 1 << 2) ? "en" : "dis"); |
| 329 | msg_pdbg("Serial flash segment 0x%08x-0x%08x %sabled\n", |
| 330 | 0xFFF80000, 0xFFFEFFFF, (tmp & 1 << 3) ? "en" : "dis"); |
| 331 | msg_pdbg("LPC write to serial flash %sabled\n", |
| 332 | (tmp & 1 << 4) ? "en" : "dis"); |
| 333 | /* The LPC->SPI force write enable below only makes sense for |
| 334 | * non-programmer mode. |
| 335 | */ |
| 336 | /* If any serial flash segment is enabled, enable writing. */ |
| 337 | if ((tmp & 0xe) && (!(tmp & 1 << 4))) { |
| 338 | msg_pdbg("Enabling LPC write to serial flash\n"); |
| 339 | tmp |= 1 << 4; |
| 340 | sio_write(port, 0x24, tmp); |
| 341 | } |
| 342 | msg_pdbg("Serial flash pin %i\n", (tmp & 1 << 5) ? 87 : 29); |
| 343 | /* LDN 0x7, reg 0x64/0x65 */ |
| 344 | sio_write(port, 0x07, 0x7); |
| 345 | flashport = sio_read(port, 0x64) << 8; |
| 346 | flashport |= sio_read(port, 0x65); |
| 347 | msg_pdbg("Serial flash port 0x%04x\n", flashport); |
| 348 | /* Non-default port requested? */ |
Patrick Georgi | 048dbdb | 2017-04-11 20:45:07 +0200 | [diff] [blame] | 349 | param = extract_programmer_param("it87spiport"); |
| 350 | if (param) { |
hailfinger | c73ce6e | 2010-07-10 16:56:32 +0000 | [diff] [blame] | 351 | char *endptr = NULL; |
| 352 | unsigned long forced_flashport; |
Patrick Georgi | 048dbdb | 2017-04-11 20:45:07 +0200 | [diff] [blame] | 353 | forced_flashport = strtoul(param, &endptr, 0); |
hailfinger | c73ce6e | 2010-07-10 16:56:32 +0000 | [diff] [blame] | 354 | /* Port 0, port >0x1000, unaligned ports and garbage strings |
| 355 | * are rejected. |
hailfinger | ddd5d7b | 2010-03-25 02:50:40 +0000 | [diff] [blame] | 356 | */ |
hailfinger | c73ce6e | 2010-07-10 16:56:32 +0000 | [diff] [blame] | 357 | if (!forced_flashport || (forced_flashport >= 0x1000) || |
| 358 | (forced_flashport & 0x7) || (*endptr != '\0')) { |
| 359 | /* Using ports below 0x100 is a really bad idea, and |
| 360 | * should only be done if no port between 0x100 and |
| 361 | * 0xff8 works due to routing issues. |
| 362 | */ |
| 363 | msg_perr("Error: it87spiport specified, but no valid " |
| 364 | "port specified.\nPort must be a multiple of " |
| 365 | "0x8 and lie between 0x100 and 0xff8.\n"); |
Patrick Georgi | 048dbdb | 2017-04-11 20:45:07 +0200 | [diff] [blame] | 366 | exit_conf_mode_ite(port); |
| 367 | free(param); |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 368 | return 1; |
hailfinger | c73ce6e | 2010-07-10 16:56:32 +0000 | [diff] [blame] | 369 | } else { |
| 370 | flashport = (uint16_t)forced_flashport; |
| 371 | msg_pinfo("Forcing serial flash port 0x%04x\n", |
| 372 | flashport); |
| 373 | sio_write(port, 0x64, (flashport >> 8)); |
| 374 | sio_write(port, 0x65, (flashport & 0xff)); |
hailfinger | 4500b08 | 2009-07-11 18:05:42 +0000 | [diff] [blame] | 375 | } |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 376 | } |
Patrick Georgi | 048dbdb | 2017-04-11 20:45:07 +0200 | [diff] [blame] | 377 | free(param); |
hailfinger | c73ce6e | 2010-07-10 16:56:32 +0000 | [diff] [blame] | 378 | exit_conf_mode_ite(port); |
| 379 | it8716f_flashport = flashport; |
hailfinger | 76bb7e9 | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 380 | if (internal_buses_supported & BUS_SPI) |
hailfinger | c73ce6e | 2010-07-10 16:56:32 +0000 | [diff] [blame] | 381 | msg_pdbg("Overriding chipset SPI with IT87 SPI.\n"); |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 382 | /* FIXME: Add the SPI bus or replace the other buses with it? */ |
Patrick Georgi | f4f1e2f | 2017-03-10 17:38:40 +0100 | [diff] [blame] | 383 | register_spi_master(&spi_master_it87xx); |
hailfinger | c73ce6e | 2010-07-10 16:56:32 +0000 | [diff] [blame] | 384 | return 0; |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 385 | } |
| 386 | |
David Hendricks | ac1d25c | 2016-08-09 17:00:58 -0700 | [diff] [blame] | 387 | int init_superio_ite(void) |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 388 | { |
Patrick Georgi | 048dbdb | 2017-04-11 20:45:07 +0200 | [diff] [blame] | 389 | int i; |
| 390 | int ret = 0; |
| 391 | int chips_found = 0; |
stepan | 3bdf618 | 2008-06-30 23:45:22 +0000 | [diff] [blame] | 392 | |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 393 | for (i = 0; i < superio_count; i++) { |
| 394 | if (superios[i].vendor != SUPERIO_VENDOR_ITE) |
| 395 | continue; |
hailfinger | 2c361e4 | 2008-05-13 23:03:12 +0000 | [diff] [blame] | 396 | |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 397 | switch (superios[i].model) { |
| 398 | case 0x8500: |
| 399 | case 0x8502: |
| 400 | case 0x8510: |
| 401 | case 0x8511: |
| 402 | case 0x8512: |
| 403 | /* FIXME: This should be enabled, but we need a check |
| 404 | * for laptop whitelisting due to the amount of things |
| 405 | * which can go wrong if the EC firmware does not |
| 406 | * implement the interface we want. |
| 407 | */ |
David Hendricks | ac1d25c | 2016-08-09 17:00:58 -0700 | [diff] [blame] | 408 | if (!it85xx_spi_init(superios[i])) |
David Hendricks | 5e79c9f | 2013-11-04 22:05:08 -0800 | [diff] [blame] | 409 | chips_found++; |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 410 | break; |
Shawn Nematbakhsh | 3404b1a | 2012-07-26 15:19:58 -0700 | [diff] [blame] | 411 | case 0x8518: |
David Hendricks | ac1d25c | 2016-08-09 17:00:58 -0700 | [diff] [blame] | 412 | if (!it8518_spi_init(superios[i])) |
David Hendricks | 5e79c9f | 2013-11-04 22:05:08 -0800 | [diff] [blame] | 413 | chips_found++; |
Shawn Nematbakhsh | 3404b1a | 2012-07-26 15:19:58 -0700 | [diff] [blame] | 414 | break; |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 415 | case 0x8705: |
David Hendricks | 5e79c9f | 2013-11-04 22:05:08 -0800 | [diff] [blame] | 416 | if (!it8705f_write_enable(superios[i].port)) |
| 417 | chips_found++; |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 418 | break; |
| 419 | case 0x8716: |
| 420 | case 0x8718: |
| 421 | case 0x8720: |
Edward O'Callaghan | 9505295 | 2020-05-09 22:22:37 +1000 | [diff] [blame] | 422 | case 0x8728: |
David Hendricks | 5e79c9f | 2013-11-04 22:05:08 -0800 | [diff] [blame] | 423 | if (!it87spi_probe(superios[i].port)) |
| 424 | chips_found++; |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 425 | break; |
| 426 | default: |
Patrick Georgi | 048dbdb | 2017-04-11 20:45:07 +0200 | [diff] [blame] | 427 | msg_pdbg2("Super I/O ID 0x%04hx is not on the list of flash-capable controllers.\n", |
| 428 | superios[i].model); |
hailfinger | 94e090c | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 429 | } |
hailfinger | d9f5da2 | 2009-06-28 10:57:58 +0000 | [diff] [blame] | 430 | } |
David Hendricks | 5e79c9f | 2013-11-04 22:05:08 -0800 | [diff] [blame] | 431 | |
| 432 | if (chips_found == 0) { |
| 433 | ret = 1; /* failed to probe/initialize/enable chip */ |
| 434 | } else if (chips_found == 1) { |
| 435 | ret = 0; /* success */ |
| 436 | } else { |
| 437 | msg_pdbg("%s: Found %d programmable ECs/SuperIOs, aborting.\n", |
| 438 | __func__, chips_found); |
| 439 | ret = 1; |
| 440 | } |
hailfinger | a916b42 | 2009-06-01 02:08:58 +0000 | [diff] [blame] | 441 | return ret; |
hailfinger | 26e212b | 2009-05-31 18:00:57 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Edward O'Callaghan | 85726e5 | 2020-11-17 18:11:47 +1100 | [diff] [blame^] | 444 | #endif /* defined(__i386__) || defined(__x86_64__) */ |