blob: 71470a109958835320d605bf127a07f24e79a5e7 [file] [log] [blame]
hailfinger2c361e42008-05-13 23:03:12 +00001/*
2 * This file is part of the flashrom project.
3 *
hailfinger4500b082009-07-11 18:05:42 +00004 * Copyright (C) 2007, 2008, 2009 Carl-Daniel Hailfinger
hailfinger2c361e42008-05-13 23:03:12 +00005 * Copyright (C) 2008 Ronald Hoogenboom <ronald@zonnet.nl>
stepan3bdf6182008-06-30 23:45:22 +00006 * Copyright (C) 2008 coresystems GmbH
hailfinger2c361e42008-05-13 23:03:12 +00007 *
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.
hailfinger2c361e42008-05-13 23:03:12 +000016 */
17
18/*
19 * Contains the ITE IT87* SPI specific routines
20 */
21
hailfinger324a9cc2010-05-26 01:45:41 +000022#if defined(__i386__) || defined(__x86_64__)
23
hailfinger2c361e42008-05-13 23:03:12 +000024#include <string.h>
hailfinger4500b082009-07-11 18:05:42 +000025#include <stdlib.h>
Patrick Georgi048dbdb2017-04-11 20:45:07 +020026#include <errno.h>
hailfinger2c361e42008-05-13 23:03:12 +000027#include "flash.h"
snelson8913d082010-02-26 05:48:29 +000028#include "chipdrivers.h"
hailfinger428f6852010-07-27 22:41:39 +000029#include "programmer.h"
Patrick Georgi048dbdb2017-04-11 20:45:07 +020030#include "hwaccess.h"
hailfinger2c361e42008-05-13 23:03:12 +000031#include "spi.h"
32
33#define ITE_SUPERIO_PORT1 0x2e
34#define ITE_SUPERIO_PORT2 0x4e
35
Edward O'Callaghan85726e52020-11-17 18:11:47 +110036#define CHIP_ID_BYTE1_REG 0x20
37#define CHIP_ID_BYTE2_REG 0x21
38#define CHIP_VER_REG 0x22
39
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +110040struct it8716f_spi_data {
41 uint16_t it8716f_flashport;
42 /* use fast 33MHz SPI (<>0) or slow 16MHz (0) */
43 int fast_spi;
44};
45
46static int get_data_from_context(const struct flashctx *flash, struct it8716f_spi_data **data)
47{
48 if (!flash || !flash->mst || !flash->mst->spi.data) {
49 msg_perr("Unable to extract fd from flash context.\n");
50 return SPI_GENERIC_ERROR;
51 }
52 *data = (struct it8716f_spi_data *)flash->mst->spi.data;
53
54 return 0;
55}
hailfinger2c361e42008-05-13 23:03:12 +000056
hailfinger2c361e42008-05-13 23:03:12 +000057/* Helper functions for most recent ITE IT87xx Super I/O chips */
hailfinger7bac0e52009-05-25 23:26:50 +000058void enter_conf_mode_ite(uint16_t port)
hailfinger2c361e42008-05-13 23:03:12 +000059{
hailfingere1f062f2008-05-22 13:22:45 +000060 OUTB(0x87, port);
61 OUTB(0x01, port);
62 OUTB(0x55, port);
hailfinger2c361e42008-05-13 23:03:12 +000063 if (port == ITE_SUPERIO_PORT1)
hailfingere1f062f2008-05-22 13:22:45 +000064 OUTB(0x55, port);
hailfinger2c361e42008-05-13 23:03:12 +000065 else
hailfingere1f062f2008-05-22 13:22:45 +000066 OUTB(0xaa, port);
hailfinger2c361e42008-05-13 23:03:12 +000067}
68
hailfinger7bac0e52009-05-25 23:26:50 +000069void exit_conf_mode_ite(uint16_t port)
hailfinger2c361e42008-05-13 23:03:12 +000070{
hailfinger7bac0e52009-05-25 23:26:50 +000071 sio_write(port, 0x02, 0x02);
hailfinger2c361e42008-05-13 23:03:12 +000072}
73
Edward O'Callaghan95052952020-05-09 22:22:37 +100074static uint16_t probe_id_ite(uint16_t port)
hailfingerc236f9e2009-12-22 23:42:04 +000075{
76 uint16_t id;
77
78 enter_conf_mode_ite(port);
79 id = sio_read(port, CHIP_ID_BYTE1_REG) << 8;
80 id |= sio_read(port, CHIP_ID_BYTE2_REG);
81 exit_conf_mode_ite(port);
82
83 return id;
84}
85
hailfinger94e090c2011-04-27 14:34:08 +000086void probe_superio_ite(void)
hailfingerc236f9e2009-12-22 23:42:04 +000087{
Patrick Georgi8ddfee92017-03-20 14:54:28 +010088 struct superio s = {0};
hailfingerc236f9e2009-12-22 23:42:04 +000089 uint16_t ite_ports[] = {ITE_SUPERIO_PORT1, ITE_SUPERIO_PORT2, 0};
90 uint16_t *i = ite_ports;
91
hailfinger94e090c2011-04-27 14:34:08 +000092 s.vendor = SUPERIO_VENDOR_ITE;
hailfingerc236f9e2009-12-22 23:42:04 +000093 for (; *i; i++) {
hailfinger94e090c2011-04-27 14:34:08 +000094 s.port = *i;
95 s.model = probe_id_ite(s.port);
96 switch (s.model >> 8) {
hailfingerc236f9e2009-12-22 23:42:04 +000097 case 0x82:
98 case 0x86:
99 case 0x87:
hailfinger94e090c2011-04-27 14:34:08 +0000100 /* FIXME: Print revision for all models? */
Patrick Georgi05482992017-03-20 21:56:33 +0100101 msg_pdbg("Found ITE Super I/O, ID 0x%04hx on port 0x%x\n", s.model, s.port);
hailfinger94e090c2011-04-27 14:34:08 +0000102 register_superio(s);
103 break;
104 case 0x85:
Patrick Georgi05482992017-03-20 21:56:33 +0100105 msg_pdbg("Found ITE EC, ID 0x%04hx, Rev 0x%02x on port 0x%x.\n",
Edward O'Callaghan95052952020-05-09 22:22:37 +1000106 s.model, sio_read(s.port, CHIP_VER_REG), s.port);
hailfinger94e090c2011-04-27 14:34:08 +0000107 register_superio(s);
108 break;
hailfingerc236f9e2009-12-22 23:42:04 +0000109 }
110 }
111
hailfinger94e090c2011-04-27 14:34:08 +0000112 return;
hailfingerc236f9e2009-12-22 23:42:04 +0000113}
114
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100115/* Page size is usually 256 bytes */
116static int it8716f_spi_page_program(struct flashctx *flash, const uint8_t *buf, unsigned int start)
117{
118 unsigned int i;
119 int result;
120 chipaddr bios = flash->virtual_memory;
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100121 struct it8716f_spi_data *data;
122
123 if (get_data_from_context(flash, &data) < 0)
124 return SPI_GENERIC_ERROR;
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100125
126 result = spi_write_enable(flash);
127 if (result)
128 return result;
129 /* FIXME: The command below seems to be redundant or wrong. */
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100130 OUTB(0x06, data->it8716f_flashport + 1);
131 OUTB(((2 + (data->fast_spi ? 1 : 0)) << 4), data->it8716f_flashport);
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100132 for (i = 0; i < flash->chip->page_size; i++)
133 mmio_writeb(buf[i], (void *)(bios + start + i));
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100134 OUTB(0, data->it8716f_flashport);
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100135 /* Wait until the Write-In-Progress bit is cleared.
136 * This usually takes 1-10 ms, so wait in 1 ms steps.
137 */
138 while (spi_read_status_register(flash) & SPI_SR_WIP)
139 programmer_delay(1000);
140 return 0;
141}
142
143/*
144 * The IT8716F only supports commands with length 1,2,4,5 bytes including
145 * command byte and can not read more than 3 bytes from the device.
146 *
147 * This function expects writearr[0] to be the first byte sent to the device,
148 * whereas the IT8716F splits commands internally into address and non-address
149 * commands with the address in inverse wire order. That's why the register
150 * ordering in case 4 and 5 may seem strange.
151 */
Patrick Georgi05482992017-03-20 21:56:33 +0100152static int it8716f_spi_send_command(const struct flashctx *flash,
153 unsigned int writecnt, unsigned int readcnt,
154 const unsigned char *writearr,
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100155 unsigned char *readarr)
156{
157 uint8_t busy, writeenc;
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100158 struct it8716f_spi_data *data;
159
160 if (get_data_from_context(flash, &data) < 0)
161 return SPI_GENERIC_ERROR;
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100162
163 do {
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100164 busy = INB(data->it8716f_flashport) & 0x80;
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100165 } while (busy);
166 if (readcnt > 3) {
167 msg_pinfo("%s called with unsupported readcnt %i.\n",
168 __func__, readcnt);
169 return SPI_INVALID_LENGTH;
170 }
171 switch (writecnt) {
172 case 1:
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100173 OUTB(writearr[0], data->it8716f_flashport + 1);
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100174 writeenc = 0x0;
175 break;
176 case 2:
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100177 OUTB(writearr[0], data->it8716f_flashport + 1);
178 OUTB(writearr[1], data->it8716f_flashport + 7);
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100179 writeenc = 0x1;
180 break;
181 case 4:
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100182 OUTB(writearr[0], data->it8716f_flashport + 1);
183 OUTB(writearr[1], data->it8716f_flashport + 4);
184 OUTB(writearr[2], data->it8716f_flashport + 3);
185 OUTB(writearr[3], data->it8716f_flashport + 2);
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100186 writeenc = 0x2;
187 break;
188 case 5:
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100189 OUTB(writearr[0], data->it8716f_flashport + 1);
190 OUTB(writearr[1], data->it8716f_flashport + 4);
191 OUTB(writearr[2], data->it8716f_flashport + 3);
192 OUTB(writearr[3], data->it8716f_flashport + 2);
193 OUTB(writearr[4], data->it8716f_flashport + 7);
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100194 writeenc = 0x3;
195 break;
196 default:
197 msg_pinfo("%s called with unsupported writecnt %i.\n",
198 __func__, writecnt);
199 return SPI_INVALID_LENGTH;
200 }
201 /*
202 * Start IO, 33 or 16 MHz, readcnt input bytes, writecnt output bytes.
203 * Note:
204 * We can't use writecnt directly, but have to use a strange encoding.
205 */
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100206 OUTB(((0x4 + (data->fast_spi ? 1 : 0)) << 4)
207 | ((readcnt & 0x3) << 2) | (writeenc), data->it8716f_flashport);
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100208
209 if (readcnt > 0) {
210 unsigned int i;
211
212 do {
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100213 busy = INB(data->it8716f_flashport) & 0x80;
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100214 } while (busy);
215
216 for (i = 0; i < readcnt; i++)
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100217 readarr[i] = INB(data->it8716f_flashport + 5 + i);
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100218 }
219
220 return 0;
221}
222
223/*
224 * IT8716F only allows maximum of 512 kb SPI mapped to LPC memory cycles
225 * Need to read this big flash using firmware cycles 3 byte at a time.
226 */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700227static int it8716f_spi_chip_read(struct flashctx *flash, uint8_t *buf,
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100228 unsigned int start, unsigned int len)
229{
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100230 struct it8716f_spi_data *data;
231
232 if (get_data_from_context(flash, &data) < 0)
233 return SPI_GENERIC_ERROR;
234
235 data->fast_spi = 0;
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100236
237 /* FIXME: Check if someone explicitly requested to use IT87 SPI although
238 * the mainboard does not use IT87 SPI translation. This should be done
239 * via a programmer parameter for the internal programmer.
240 */
241 if ((flash->chip->total_size * 1024 > 512 * 1024)) {
242 default_spi_read(flash, buf, start, len);
243 } else {
244 mmio_readn((void *)(flash->virtual_memory + start), buf, len);
245 }
246
247 return 0;
248}
249
Patrick Georgiab8353e2017-02-03 18:32:01 +0100250static int it8716f_spi_chip_write_256(struct flashctx *flash, const uint8_t *buf,
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100251 unsigned int start, unsigned int len)
252{
253 const struct flashchip *chip = flash->chip;
254 /*
255 * IT8716F only allows maximum of 512 kb SPI chip size for memory
256 * mapped access. It also can't write more than 1+3+256 bytes at once,
257 * so page_size > 256 bytes needs a fallback.
258 * FIXME: Split too big page writes into chunks IT87* can handle instead
259 * of degrading to single-byte program.
260 * FIXME: Check if someone explicitly requested to use IT87 SPI although
261 * the mainboard does not use IT87 SPI translation. This should be done
262 * via a programmer parameter for the internal programmer.
263 */
264 if ((chip->total_size * 1024 > 512 * 1024) || (chip->page_size > 256)) {
265 spi_chip_write_1(flash, buf, start, len);
266 } else {
267 unsigned int lenhere;
268
269 if (start % chip->page_size) {
270 /* start to the end of the page or to start + len,
271 * whichever is smaller.
272 */
273 lenhere = min(len, chip->page_size - start % chip->page_size);
274 spi_chip_write_1(flash, buf, start, lenhere);
275 start += lenhere;
276 len -= lenhere;
277 buf += lenhere;
278 }
279
280 while (len >= chip->page_size) {
281 it8716f_spi_page_program(flash, buf, start);
282 start += chip->page_size;
283 len -= chip->page_size;
284 buf += chip->page_size;
285 }
286 if (len)
287 spi_chip_write_1(flash, buf, start, len);
288 }
289
290 return 0;
291}
mkarcherd264e9e2011-05-11 17:07:07 +0000292
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100293static struct spi_master spi_master_it87xx = {
Edward O'Callaghan3941bee2020-10-09 13:00:17 +1100294 .max_data_read = 3,
uwe8d342eb2011-07-28 08:13:25 +0000295 .max_data_write = MAX_DATA_UNSPECIFIED,
296 .command = it8716f_spi_send_command,
297 .multicommand = default_spi_send_multicommand,
298 .read = it8716f_spi_chip_read,
299 .write_256 = it8716f_spi_chip_write_256,
Edward O'Callaghan04ac7302020-05-14 18:03:40 +1000300 .write_aai = spi_chip_write_1,
mkarcherd264e9e2011-05-11 17:07:07 +0000301};
302
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100303
304static int it8716f_shutdown(void *data)
305{
306 free(data);
307 return 0;
308}
309
hailfingerc73ce6e2010-07-10 16:56:32 +0000310static uint16_t it87spi_probe(uint16_t port)
hailfinger2c361e42008-05-13 23:03:12 +0000311{
312 uint8_t tmp = 0;
hailfingerc236f9e2009-12-22 23:42:04 +0000313 uint16_t flashport = 0;
hailfinger2c361e42008-05-13 23:03:12 +0000314
hailfingerc73ce6e2010-07-10 16:56:32 +0000315 enter_conf_mode_ite(port);
Edward O'Callaghan95052952020-05-09 22:22:37 +1000316
317 char *param = extract_programmer_param("dualbiosindex");
318 if (param != NULL) {
319 sio_write(port, 0x07, 0x07); /* Select GPIO LDN */
320 tmp = sio_read(port, 0xEF);
321 if (*param == '\0') { /* Print current setting only. */
322 free(param);
323 } else {
324 char *dualbiosindex_suffix;
325 errno = 0;
326 long chip_index = strtol(param, &dualbiosindex_suffix, 0);
327 free(param);
328 if (errno != 0 || *dualbiosindex_suffix != '\0' || chip_index < 0 || chip_index > 1) {
329 msg_perr("DualBIOS: Invalid chip index requested - choose 0 or 1.\n");
330 exit_conf_mode_ite(port);
331 return 1;
332 }
333 if (chip_index != (tmp & 1)) {
334 msg_pdbg("DualBIOS: Previous chip index: %d\n", tmp & 1);
335 sio_write(port, 0xEF, (tmp & 0xFE) | chip_index);
336 tmp = sio_read(port, 0xEF);
337 if ((tmp & 1) != chip_index) {
338 msg_perr("DualBIOS: Chip selection failed.\n");
339 exit_conf_mode_ite(port);
340 return 1;
341 }
342 }
343 }
344 msg_pinfo("DualBIOS: Selected chip: %d\n", tmp & 1);
345 }
346
hailfingerc73ce6e2010-07-10 16:56:32 +0000347 /* NOLDN, reg 0x24, mask out lowest bit (suspend) */
348 tmp = sio_read(port, 0x24) & 0xFE;
hailfinger969e2f32011-09-08 00:00:29 +0000349 /* Check if LPC->SPI translation is active. */
350 if (!(tmp & 0x0e)) {
hailfingerc73ce6e2010-07-10 16:56:32 +0000351 msg_pdbg("No IT87* serial flash segment enabled.\n");
352 exit_conf_mode_ite(port);
353 /* Nothing to do. */
David Hendricks5e79c9f2013-11-04 22:05:08 -0800354 return 1;
hailfingerc73ce6e2010-07-10 16:56:32 +0000355 }
356 msg_pdbg("Serial flash segment 0x%08x-0x%08x %sabled\n",
357 0xFFFE0000, 0xFFFFFFFF, (tmp & 1 << 1) ? "en" : "dis");
358 msg_pdbg("Serial flash segment 0x%08x-0x%08x %sabled\n",
359 0x000E0000, 0x000FFFFF, (tmp & 1 << 1) ? "en" : "dis");
360 msg_pdbg("Serial flash segment 0x%08x-0x%08x %sabled\n",
361 0xFFEE0000, 0xFFEFFFFF, (tmp & 1 << 2) ? "en" : "dis");
362 msg_pdbg("Serial flash segment 0x%08x-0x%08x %sabled\n",
363 0xFFF80000, 0xFFFEFFFF, (tmp & 1 << 3) ? "en" : "dis");
364 msg_pdbg("LPC write to serial flash %sabled\n",
365 (tmp & 1 << 4) ? "en" : "dis");
366 /* The LPC->SPI force write enable below only makes sense for
367 * non-programmer mode.
368 */
369 /* If any serial flash segment is enabled, enable writing. */
370 if ((tmp & 0xe) && (!(tmp & 1 << 4))) {
371 msg_pdbg("Enabling LPC write to serial flash\n");
372 tmp |= 1 << 4;
373 sio_write(port, 0x24, tmp);
374 }
375 msg_pdbg("Serial flash pin %i\n", (tmp & 1 << 5) ? 87 : 29);
376 /* LDN 0x7, reg 0x64/0x65 */
377 sio_write(port, 0x07, 0x7);
378 flashport = sio_read(port, 0x64) << 8;
379 flashport |= sio_read(port, 0x65);
380 msg_pdbg("Serial flash port 0x%04x\n", flashport);
381 /* Non-default port requested? */
Patrick Georgi048dbdb2017-04-11 20:45:07 +0200382 param = extract_programmer_param("it87spiport");
383 if (param) {
hailfingerc73ce6e2010-07-10 16:56:32 +0000384 char *endptr = NULL;
385 unsigned long forced_flashport;
Patrick Georgi048dbdb2017-04-11 20:45:07 +0200386 forced_flashport = strtoul(param, &endptr, 0);
hailfingerc73ce6e2010-07-10 16:56:32 +0000387 /* Port 0, port >0x1000, unaligned ports and garbage strings
388 * are rejected.
hailfingerddd5d7b2010-03-25 02:50:40 +0000389 */
hailfingerc73ce6e2010-07-10 16:56:32 +0000390 if (!forced_flashport || (forced_flashport >= 0x1000) ||
391 (forced_flashport & 0x7) || (*endptr != '\0')) {
392 /* Using ports below 0x100 is a really bad idea, and
393 * should only be done if no port between 0x100 and
394 * 0xff8 works due to routing issues.
395 */
396 msg_perr("Error: it87spiport specified, but no valid "
397 "port specified.\nPort must be a multiple of "
398 "0x8 and lie between 0x100 and 0xff8.\n");
Patrick Georgi048dbdb2017-04-11 20:45:07 +0200399 exit_conf_mode_ite(port);
400 free(param);
hailfinger94e090c2011-04-27 14:34:08 +0000401 return 1;
hailfingerc73ce6e2010-07-10 16:56:32 +0000402 } else {
403 flashport = (uint16_t)forced_flashport;
404 msg_pinfo("Forcing serial flash port 0x%04x\n",
405 flashport);
406 sio_write(port, 0x64, (flashport >> 8));
407 sio_write(port, 0x65, (flashport & 0xff));
hailfinger4500b082009-07-11 18:05:42 +0000408 }
hailfinger2c361e42008-05-13 23:03:12 +0000409 }
Patrick Georgi048dbdb2017-04-11 20:45:07 +0200410 free(param);
hailfingerc73ce6e2010-07-10 16:56:32 +0000411 exit_conf_mode_ite(port);
Edward O'Callaghanc1d3adc2020-11-17 18:33:45 +1100412
413 struct it8716f_spi_data *data = calloc(1, sizeof(struct it8716f_spi_data));
414 if (!data) {
415 msg_perr("Unable to allocate space for extra SPI master data.\n");
416 return SPI_GENERIC_ERROR;
417 }
418
419 data->it8716f_flashport = flashport;
420 data->fast_spi = 1;
421 spi_master_it87xx.data = data;
422
423 register_shutdown(it8716f_shutdown, data);
424
hailfinger76bb7e92011-11-09 23:40:00 +0000425 if (internal_buses_supported & BUS_SPI)
hailfingerc73ce6e2010-07-10 16:56:32 +0000426 msg_pdbg("Overriding chipset SPI with IT87 SPI.\n");
hailfinger94e090c2011-04-27 14:34:08 +0000427 /* FIXME: Add the SPI bus or replace the other buses with it? */
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100428 register_spi_master(&spi_master_it87xx);
hailfingerc73ce6e2010-07-10 16:56:32 +0000429 return 0;
hailfinger2c361e42008-05-13 23:03:12 +0000430}
431
David Hendricksac1d25c2016-08-09 17:00:58 -0700432int init_superio_ite(void)
hailfinger2c361e42008-05-13 23:03:12 +0000433{
Patrick Georgi048dbdb2017-04-11 20:45:07 +0200434 int i;
435 int ret = 0;
436 int chips_found = 0;
stepan3bdf6182008-06-30 23:45:22 +0000437
hailfinger94e090c2011-04-27 14:34:08 +0000438 for (i = 0; i < superio_count; i++) {
439 if (superios[i].vendor != SUPERIO_VENDOR_ITE)
440 continue;
hailfinger2c361e42008-05-13 23:03:12 +0000441
hailfinger94e090c2011-04-27 14:34:08 +0000442 switch (superios[i].model) {
443 case 0x8500:
444 case 0x8502:
445 case 0x8510:
446 case 0x8511:
447 case 0x8512:
448 /* FIXME: This should be enabled, but we need a check
449 * for laptop whitelisting due to the amount of things
450 * which can go wrong if the EC firmware does not
451 * implement the interface we want.
452 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700453 if (!it85xx_spi_init(superios[i]))
David Hendricks5e79c9f2013-11-04 22:05:08 -0800454 chips_found++;
hailfinger94e090c2011-04-27 14:34:08 +0000455 break;
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700456 case 0x8518:
David Hendricksac1d25c2016-08-09 17:00:58 -0700457 if (!it8518_spi_init(superios[i]))
David Hendricks5e79c9f2013-11-04 22:05:08 -0800458 chips_found++;
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700459 break;
hailfinger94e090c2011-04-27 14:34:08 +0000460 case 0x8705:
David Hendricks5e79c9f2013-11-04 22:05:08 -0800461 if (!it8705f_write_enable(superios[i].port))
462 chips_found++;
hailfinger94e090c2011-04-27 14:34:08 +0000463 break;
464 case 0x8716:
465 case 0x8718:
466 case 0x8720:
Edward O'Callaghan95052952020-05-09 22:22:37 +1000467 case 0x8728:
David Hendricks5e79c9f2013-11-04 22:05:08 -0800468 if (!it87spi_probe(superios[i].port))
469 chips_found++;
hailfinger94e090c2011-04-27 14:34:08 +0000470 break;
471 default:
Patrick Georgi048dbdb2017-04-11 20:45:07 +0200472 msg_pdbg2("Super I/O ID 0x%04hx is not on the list of flash-capable controllers.\n",
473 superios[i].model);
hailfinger94e090c2011-04-27 14:34:08 +0000474 }
hailfingerd9f5da22009-06-28 10:57:58 +0000475 }
David Hendricks5e79c9f2013-11-04 22:05:08 -0800476
477 if (chips_found == 0) {
478 ret = 1; /* failed to probe/initialize/enable chip */
479 } else if (chips_found == 1) {
480 ret = 0; /* success */
481 } else {
482 msg_pdbg("%s: Found %d programmable ECs/SuperIOs, aborting.\n",
483 __func__, chips_found);
484 ret = 1;
485 }
hailfingera916b422009-06-01 02:08:58 +0000486 return ret;
hailfinger26e212b2009-05-31 18:00:57 +0000487}
488
Edward O'Callaghan85726e52020-11-17 18:11:47 +1100489#endif /* defined(__i386__) || defined(__x86_64__) */