blob: 8018d6229a7d44d30558359e10880bc5eeb3413d [file] [log] [blame]
hailfinger8f091492011-02-22 17:16:34 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2007, 2008, 2009 Carl-Daniel Hailfinger
5 * Copyright (C) 2008 Ronald Hoogenboom <ronald@zonnet.nl>
6 * Copyright (C) 2008 coresystems GmbH
7 * Copyright (C) 2010 Google Inc.
8 *
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.
12 *
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
21 */
22
23/*
24 * Contains the ITE IT85* SPI specific routines
David Hendricks42ad6522011-08-09 16:08:10 -070025 *
26 * FIXME: EC firmware updates on this chip can be interrupted due to factors
27 * such as SMBus traffic. YOU MUST DISABLE any services, such as power
28 * management daemons, which can interact with the EC during firmware update.
hailfinger8f091492011-02-22 17:16:34 +000029 */
30
31#if defined(__i386__) || defined(__x86_64__)
32
33#include <string.h>
hailfinger2b46a862011-02-28 23:58:15 +000034#include <stdio.h>
hailfinger8f091492011-02-22 17:16:34 +000035#include <stdlib.h>
36#include "flash.h"
hailfinger8f091492011-02-22 17:16:34 +000037#include "spi.h"
38#include "programmer.h"
39
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -070040/* Supported ECs, ITE_LAST should always be LAST member */
41enum ite_chip_id {
42 ITE_IT85XX,
43 ITE_IT8518,
44 ITE_LAST
45};
46
47/* chip-specific parameters */
48typedef struct {
49 enum ite_chip_id chip_id;
50 uint8_t port_data;
51 uint8_t port_cmd;
52 uint8_t copy_to_sram_cmd;
53 uint8_t exit_sram_cmd;
54 uint32_t exit_sram_delay;
55} ite_chip;
56
57/* table of supported chips + parameters, order by ite_chip_id index */
58static ite_chip ite_chips[] = {
59 { ITE_IT85XX,
60 0x60,
61 0x64,
62 0xB4,
63 0xFE,
64 0,
65 },
66
67 { ITE_IT8518,
68 0x62,
69 0x66,
David Hendricks74915852012-09-27 16:39:37 -070070 0xDD, /* default value, see note in it85xx_spi_send_command */
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -070071 0xFF,
72 500000,
73 }
74};
75
76/* pointer to table entry of identified chip */
77static ite_chip *found_chip;
78
hailfinger2b46a862011-02-28 23:58:15 +000079#define MAX_TIMEOUT 100000
80#define MAX_TRY 5
81
hailfinger177cdd82011-03-08 00:23:49 +000082/* Constants for I/O ports */
hailfinger8f091492011-02-22 17:16:34 +000083#define ITE_SUPERIO_PORT1 0x2e
84#define ITE_SUPERIO_PORT2 0x4e
85
hailfinger8f091492011-02-22 17:16:34 +000086/* Constants for Logical Device registers */
87#define LDNSEL 0x07
hailfinger8f091492011-02-22 17:16:34 +000088
89/* These are standard Super I/O 16-bit base address registers */
hailfinger177cdd82011-03-08 00:23:49 +000090#define SHM_IO_BAR0 0x60 /* big-endian, this is high bits */
91#define SHM_IO_BAR1 0x61
hailfinger8f091492011-02-22 17:16:34 +000092
hailfinger177cdd82011-03-08 00:23:49 +000093/* The 8042 keyboard controller uses an input buffer and an output buffer to
94 * communicate with the host CPU. Both buffers are 1-byte depth. That means
95 * IBF is set to 1 when the host CPU sends a command to the input buffer
96 * of the EC. IBF is cleared to 0 once the command is read by the EC.
97 */
hailfinger2b46a862011-02-28 23:58:15 +000098#define KB_IBF (1 << 1) /* Input Buffer Full */
99#define KB_OBF (1 << 0) /* Output Buffer Full */
100
hailfinger8f091492011-02-22 17:16:34 +0000101/* IT8502 supports two access modes:
102 * LPC_MEMORY: through the memory window in 0xFFFFFxxx (follow mode)
103 * LPC_IO: through I/O port (so called indirect memory)
104 */
105#undef LPC_MEMORY
106#define LPC_IO
107
108#ifdef LPC_IO
109/* macro to fill in indirect-access registers. */
110#define INDIRECT_A0(base, value) OUTB(value, (base) + 0) /* little-endian */
111#define INDIRECT_A1(base, value) OUTB(value, (base) + 1)
112#define INDIRECT_A2(base, value) OUTB(value, (base) + 2)
113#define INDIRECT_A3(base, value) OUTB(value, (base) + 3)
114#define INDIRECT_READ(base) INB((base) + 4)
115#define INDIRECT_WRITE(base, value) OUTB(value, (base) + 4)
116#endif /* LPC_IO */
117
118#ifdef LPC_IO
119unsigned int shm_io_base;
120#endif
121unsigned char *ce_high, *ce_low;
122static int it85xx_scratch_rom_reenter = 0;
123
hailfinger2b46a862011-02-28 23:58:15 +0000124/* This function will poll the keyboard status register until either
hailfingerb91c08c2011-08-15 19:54:20 +0000125 * an expected value shows up, or the timeout is reached.
126 * timeout is in usec.
hailfinger2b46a862011-02-28 23:58:15 +0000127 *
hailfingerb91c08c2011-08-15 19:54:20 +0000128 * Returns: 0 -- the expected value showed up.
129 * 1 -- timeout.
hailfinger2b46a862011-02-28 23:58:15 +0000130 */
uwe8d342eb2011-07-28 08:13:25 +0000131static int wait_for(const unsigned int mask, const unsigned int expected_value,
hailfingerb91c08c2011-08-15 19:54:20 +0000132 const int timeout, const char * error_message,
133 const char * function_name, const int lineno)
uwe8d342eb2011-07-28 08:13:25 +0000134{
hailfinger2b46a862011-02-28 23:58:15 +0000135 int time_passed;
136
137 for (time_passed = 0;; ++time_passed) {
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700138 if ((INB(found_chip->port_cmd) & mask) == expected_value)
hailfinger2b46a862011-02-28 23:58:15 +0000139 return 0;
140 if (time_passed >= timeout)
141 break;
142 programmer_delay(1);
143 }
144 if (error_message)
145 msg_perr("%s():%d %s", function_name, lineno, error_message);
146 return 1;
147}
148
uwe8d342eb2011-07-28 08:13:25 +0000149/* IT8502 employs a scratch RAM when flash is being updated. Call the following
hailfinger2b46a862011-02-28 23:58:15 +0000150 * two functions before/after flash erase/program. */
uwe8d342eb2011-07-28 08:13:25 +0000151void it85xx_enter_scratch_rom(void)
hailfinger8f091492011-02-22 17:16:34 +0000152{
uwe8d342eb2011-07-28 08:13:25 +0000153 int ret, tries;
hailfinger2b46a862011-02-28 23:58:15 +0000154
uwe8d342eb2011-07-28 08:13:25 +0000155 if (it85xx_scratch_rom_reenter > 0)
156 return;
David Hendricks932dfe42012-09-21 14:46:41 -0700157
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700158 msg_pdbg("%s: entering scratch rom mode\n", __func__);
159
hailfinger2b46a862011-02-28 23:58:15 +0000160 for (tries = 0; tries < MAX_TRY; ++tries) {
161 /* Wait until IBF (input buffer) is not full. */
162 if (wait_for(KB_IBF, 0, MAX_TIMEOUT,
163 "* timeout at waiting for IBF==0.\n",
uwe44e2dc42011-07-29 20:13:45 +0000164 __func__, __LINE__))
hailfinger2b46a862011-02-28 23:58:15 +0000165 continue;
166
167 /* Copy EC firmware to SRAM. */
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700168 OUTB(found_chip->copy_to_sram_cmd, found_chip->port_cmd);
hailfinger2b46a862011-02-28 23:58:15 +0000169
170 /* Confirm EC has taken away the command. */
171 if (wait_for(KB_IBF, 0, MAX_TIMEOUT,
172 "* timeout at taking command.\n",
uwe44e2dc42011-07-29 20:13:45 +0000173 __func__, __LINE__))
hailfinger2b46a862011-02-28 23:58:15 +0000174 continue;
175
176 /* Waiting for OBF (output buffer) has data.
177 * Note sometimes the replied command might be stolen by kernel
178 * ISR so that it is okay as long as the command is 0xFA. */
179 if (wait_for(KB_OBF, KB_OBF, MAX_TIMEOUT, NULL, NULL, 0))
180 msg_pdbg("%s():%d * timeout at waiting for OBF.\n",
uwe44e2dc42011-07-29 20:13:45 +0000181 __func__, __LINE__);
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700182 if ((ret = INB(found_chip->port_data)) == 0xFA) {
hailfinger2b46a862011-02-28 23:58:15 +0000183 break;
184 } else {
185 msg_perr("%s():%d * not run on SRAM ret=%d\n",
uwe44e2dc42011-07-29 20:13:45 +0000186 __func__, __LINE__, ret);
hailfinger2b46a862011-02-28 23:58:15 +0000187 continue;
188 }
189 }
190
191 if (tries < MAX_TRY) {
192 /* EC already runs on SRAM */
193 it85xx_scratch_rom_reenter++;
uwe44e2dc42011-07-29 20:13:45 +0000194 msg_pdbg("%s():%d * SUCCESS.\n", __func__, __LINE__);
hailfinger2b46a862011-02-28 23:58:15 +0000195 } else {
uwe44e2dc42011-07-29 20:13:45 +0000196 msg_perr("%s():%d * Max try reached.\n", __func__, __LINE__);
hailfinger2b46a862011-02-28 23:58:15 +0000197 }
hailfinger8f091492011-02-22 17:16:34 +0000198}
199
uwe8d342eb2011-07-28 08:13:25 +0000200void it85xx_exit_scratch_rom(void)
hailfinger8f091492011-02-22 17:16:34 +0000201{
hailfinger2b46a862011-02-28 23:58:15 +0000202 int tries;
203
uwe44e2dc42011-07-29 20:13:45 +0000204 msg_pdbg("%s():%d was called ...\n", __func__, __LINE__);
uwe8d342eb2011-07-28 08:13:25 +0000205 if (it85xx_scratch_rom_reenter <= 0)
206 return;
hailfinger2b46a862011-02-28 23:58:15 +0000207
208 for (tries = 0; tries < MAX_TRY; ++tries) {
209 /* Wait until IBF (input buffer) is not full. */
210 if (wait_for(KB_IBF, 0, MAX_TIMEOUT,
211 "* timeout at waiting for IBF==0.\n",
uwe44e2dc42011-07-29 20:13:45 +0000212 __func__, __LINE__))
hailfinger2b46a862011-02-28 23:58:15 +0000213 continue;
214
215 /* Exit SRAM. Run on flash. */
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700216 OUTB(found_chip->exit_sram_cmd, found_chip->port_cmd);
hailfinger2b46a862011-02-28 23:58:15 +0000217
218 /* Confirm EC has taken away the command. */
219 if (wait_for(KB_IBF, 0, MAX_TIMEOUT,
220 "* timeout at taking command.\n",
uwe44e2dc42011-07-29 20:13:45 +0000221 __func__, __LINE__)) {
hailfinger2b46a862011-02-28 23:58:15 +0000222 /* We cannot ensure if EC has exited update mode.
223 * If EC is in normal mode already, a further 0xFE
224 * command will reboot system. So, exit loop here. */
225 tries = MAX_TRY;
226 break;
227 }
228
229 break;
230 }
231
232 if (tries < MAX_TRY) {
233 it85xx_scratch_rom_reenter = 0;
uwe44e2dc42011-07-29 20:13:45 +0000234 msg_pdbg("%s():%d * SUCCESS.\n", __func__, __LINE__);
hailfinger2b46a862011-02-28 23:58:15 +0000235 } else {
uwe44e2dc42011-07-29 20:13:45 +0000236 msg_perr("%s():%d * Max try reached.\n", __func__, __LINE__);
hailfinger2b46a862011-02-28 23:58:15 +0000237 }
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700238
239 programmer_delay(found_chip->exit_sram_delay);
hailfinger8f091492011-02-22 17:16:34 +0000240}
241
David Hendricks93784b42016-08-09 17:00:38 -0700242static int it85xx_shutdown(void *data)
dhendrix0ffc2eb2011-06-14 01:35:36 +0000243{
244 msg_pdbg("%s():%d\n", __func__, __LINE__);
245 it85xx_exit_scratch_rom();
246
David Hendricks932dfe42012-09-21 14:46:41 -0700247 return 0; /* FIXME: Should probably return something meaningful */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000248}
249
hailfinger94e090c2011-04-27 14:34:08 +0000250static int it85xx_spi_common_init(struct superio s)
hailfinger8f091492011-02-22 17:16:34 +0000251{
252 chipaddr base;
253
254 msg_pdbg("%s():%d superio.vendor=0x%02x\n", __func__, __LINE__,
hailfinger94e090c2011-04-27 14:34:08 +0000255 s.vendor);
hailfinger8f091492011-02-22 17:16:34 +0000256
dhendrix0ffc2eb2011-06-14 01:35:36 +0000257 if (register_shutdown(it85xx_shutdown, NULL))
258 return 1;
259
hailfinger8f091492011-02-22 17:16:34 +0000260#ifdef LPC_IO
uwe8d342eb2011-07-28 08:13:25 +0000261 /* Get LPCPNP of SHM. That's big-endian. */
hailfinger94e090c2011-04-27 14:34:08 +0000262 sio_write(s.port, LDNSEL, 0x0F); /* Set LDN to SHM (0x0F) */
263 shm_io_base = (sio_read(s.port, SHM_IO_BAR0) << 8) +
264 sio_read(s.port, SHM_IO_BAR1);
hailfinger8f091492011-02-22 17:16:34 +0000265 msg_pdbg("%s():%d shm_io_base=0x%04x\n", __func__, __LINE__,
266 shm_io_base);
267
268 /* These pointers are not used directly. They will be send to EC's
269 * register for indirect access. */
270 base = 0xFFFFF000;
uwe8d342eb2011-07-28 08:13:25 +0000271 ce_high = ((unsigned char *)base) + 0xE00; /* 0xFFFFFE00 */
272 ce_low = ((unsigned char *)base) + 0xD00; /* 0xFFFFFD00 */
hailfinger8f091492011-02-22 17:16:34 +0000273
274 /* pre-set indirect-access registers since in most of cases they are
275 * 0xFFFFxx00. */
276 INDIRECT_A0(shm_io_base, base & 0xFF);
277 INDIRECT_A2(shm_io_base, (base >> 16) & 0xFF);
278 INDIRECT_A3(shm_io_base, (base >> 24));
279#endif
280#ifdef LPC_MEMORY
hailfinger76bb7e92011-11-09 23:40:00 +0000281 /* FIXME: We should block accessing that region for anything else.
282 * Major TODO here, and it will be a lot of work.
283 */
284 base = (chipaddr)physmap("it85 communication", 0xFFFFF000, 0x1000);
hailfinger8f091492011-02-22 17:16:34 +0000285 msg_pdbg("%s():%d base=0x%08x\n", __func__, __LINE__,
286 (unsigned int)base);
uwe8d342eb2011-07-28 08:13:25 +0000287 ce_high = (unsigned char *)(base + 0xE00); /* 0xFFFFFE00 */
288 ce_low = (unsigned char *)(base + 0xD00); /* 0xFFFFFD00 */
hailfinger8f091492011-02-22 17:16:34 +0000289#endif
290
hailfinger8f091492011-02-22 17:16:34 +0000291 return 0;
292}
293
hailfinger8f091492011-02-22 17:16:34 +0000294/* According to ITE 8502 document, the procedure to follow mode is following:
295 * 1. write 0x00 to LPC/FWH address 0xffff_fexxh (drive CE# high)
296 * 2. write data to LPC/FWH address 0xffff_fdxxh (drive CE# low and MOSI
297 * with data)
298 * 3. read date from LPC/FWH address 0xffff_fdxxh (drive CE# low and get
299 * data from MISO)
300 */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700301static int it85xx_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger8f091492011-02-22 17:16:34 +0000302 const unsigned char *writearr, unsigned char *readarr)
303{
304 int i;
David Hendricks74915852012-09-27 16:39:37 -0700305 static int wdt_reset_flag_set = 0;
306
307 if (found_chip->chip_id == ITE_IT8518) {
308 /*
309 * 0xd8 - Sets WDT reset flag to reboot EC after exiting from
310 * scratch mode. This flag will be be checked when
311 * command 0x8c is received. Use this when changing
312 * ROM content (erase / write commands).
313 * 0xdd - Same as d8, but without setting the WDT reset flag.
314 * Use this for commands that do not change EC code.
315 *
316 * If opcode will cause ROM content to change and scratch
317 * mode has been previously entered, then we need to re-enter
318 * scratch mode using 0xd8.
319 *
320 * FIXME(dhendrix): This is specific to Stout. We should use
321 * better method to apply board hacks rather than using the
322 * EC's chip ID as the condition.
323 */
324 switch (writearr[0]) {
325 case JEDEC_BYTE_PROGRAM:
326 case JEDEC_BE_52:
327 case JEDEC_BE_D7:
328 case JEDEC_BE_D8:
329 case JEDEC_CE_60:
330 case JEDEC_CE_C7:
331 case JEDEC_SE:
332 if (!wdt_reset_flag_set) {
333 msg_pdbg("%s: changing copy_to_sram_cmd\n",
334 __func__);
335 found_chip->copy_to_sram_cmd = 0xd8;
336 it85xx_exit_scratch_rom();
337 wdt_reset_flag_set = 1;
338 }
339 break;
340 default:
341 break;
342 }
343 }
hailfinger8f091492011-02-22 17:16:34 +0000344
345 it85xx_enter_scratch_rom();
hailfingerb91c08c2011-08-15 19:54:20 +0000346 /* Exit scratch ROM ONLY when programmer shuts down. Otherwise, the
347 * temporary flash state may halt the EC.
348 */
hailfinger8f091492011-02-22 17:16:34 +0000349
350#ifdef LPC_IO
351 INDIRECT_A1(shm_io_base, (((unsigned long int)ce_high) >> 8) & 0xff);
352 INDIRECT_WRITE(shm_io_base, 0xFF); /* Write anything to this address.*/
353 INDIRECT_A1(shm_io_base, (((unsigned long int)ce_low) >> 8) & 0xff);
354#endif
355#ifdef LPC_MEMORY
hailfinger177cdd82011-03-08 00:23:49 +0000356 mmio_writeb(0, ce_high);
hailfinger8f091492011-02-22 17:16:34 +0000357#endif
358 for (i = 0; i < writecnt; ++i) {
359#ifdef LPC_IO
360 INDIRECT_WRITE(shm_io_base, writearr[i]);
361#endif
362#ifdef LPC_MEMORY
hailfinger177cdd82011-03-08 00:23:49 +0000363 mmio_writeb(writearr[i], ce_low);
hailfinger8f091492011-02-22 17:16:34 +0000364#endif
365 }
366 for (i = 0; i < readcnt; ++i) {
367#ifdef LPC_IO
368 readarr[i] = INDIRECT_READ(shm_io_base);
369#endif
370#ifdef LPC_MEMORY
hailfinger177cdd82011-03-08 00:23:49 +0000371 readarr[i] = mmio_readb(ce_low);
hailfinger8f091492011-02-22 17:16:34 +0000372#endif
373 }
hailfinger2b46a862011-02-28 23:58:15 +0000374#ifdef LPC_IO
375 INDIRECT_A1(shm_io_base, (((unsigned long int)ce_high) >> 8) & 0xff);
376 INDIRECT_WRITE(shm_io_base, 0xFF); /* Write anything to this address.*/
377#endif
378#ifdef LPC_MEMORY
hailfinger177cdd82011-03-08 00:23:49 +0000379 mmio_writeb(0, ce_high);
hailfinger2b46a862011-02-28 23:58:15 +0000380#endif
381
hailfinger8f091492011-02-22 17:16:34 +0000382 return 0;
383}
384
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700385static const struct spi_programmer spi_programmer_it8518 = {
386 .type = SPI_CONTROLLER_IT85XX,
387 .max_data_read = 256,
388 .max_data_write = 256,
389 .command = it85xx_spi_send_command,
390 .multicommand = default_spi_send_multicommand,
391 .read = default_spi_read,
392 .write_256 = default_spi_write_256,
393};
394
David Hendricks91040832011-07-08 20:01:09 -0700395static const struct spi_programmer spi_programmer_it85xx = {
396 .type = SPI_CONTROLLER_IT85XX,
397 .max_data_read = 1,
398 .max_data_write = 1,
399 .command = it85xx_spi_send_command,
400 .multicommand = default_spi_send_multicommand,
401 .read = default_spi_read,
402 .write_256 = default_spi_write_256,
403};
404
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700405/* it8518-specific i/o initialization */
406void setup_it8518_io_base()
407{
408 OUTB(0x07, 0x2e); /* Set LDN to SHM */
409 OUTB(0x0f, 0x2f);
410 OUTB(0x60, 0x2e); /* Set IO space to 0x3F0 */
411 OUTB(0x03, 0x2f);
412 OUTB(0x61, 0x2e);
413 OUTB(0xf0, 0x2f);
414 OUTB(0x30, 0x2e); /* Enable this Logical Device */
415 OUTB(0x01, 0x2f);
416}
417
David Hendricksac1d25c2016-08-09 17:00:58 -0700418int it8518_spi_init(struct superio s)
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700419{
420 int ret;
421 if (!(internal_buses_supported & BUS_FWH)) {
422 msg_pdbg("%s():%d buses not support FWH\n", __func__, __LINE__);
423 return 1;
424 }
425
426 found_chip = &ite_chips[ITE_IT8518];
427
428#ifdef LPC_IO
429 setup_it8518_io_base();
430#endif
431
432 ret = it85xx_spi_common_init(s);
433 if (!ret) {
434 msg_pdbg("%s: internal_buses_supported=0x%x\n", __func__,
435 internal_buses_supported);
436 /* Check for FWH because IT85 listens to FWH cycles.
437 * FIXME: The big question is whether FWH cycles are necessary
438 * for communication even if LPC_IO is defined.
439 */
440 if (internal_buses_supported & BUS_FWH)
441 msg_pdbg("Registering IT85 SPI.\n");
442 /* FIXME: Really leave FWH enabled? We can't use this region
443 * anymore since accessing it would mess up IT85 communication.
444 * If we decide to disable FWH for this region, we should print
445 * a debug message about it.
446 */
447 /* Set this as SPI controller and add FWH | LPC to
448 * supported buses. */
David Hendricksac1d25c2016-08-09 17:00:58 -0700449 buses_supported |= BUS_LPC | BUS_FWH;
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700450 register_spi_programmer(&spi_programmer_it8518);
451 }
452 return ret;
453}
454
David Hendricksac1d25c2016-08-09 17:00:58 -0700455int it85xx_spi_init(struct superio s)
David Hendricks91040832011-07-08 20:01:09 -0700456{
457 int ret;
458
David Hendricksba0827a2013-05-03 20:25:40 -0700459 if (alias && alias->type != ALIAS_EC)
David Hendricks91040832011-07-08 20:01:09 -0700460 return 1;
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700461
462 found_chip = &ite_chips[ITE_IT85XX];
463
David Hendricksba0827a2013-05-03 20:25:40 -0700464 /*
465 * FIXME: This is necessary to ensure that access to the shared access
466 * window region is sent on the LPC bus. The old CLI syntax
467 * (-p internal:bus=lpc) would cause the chipset enable code to set the
468 * target bus appropriately before this function gets run, but the new
469 * syntax ("-p ec") does not cause that to happen.
470 */
471 target_bus = BUS_LPC;
472 msg_pdbg("%s: forcing target bus: 0x%08x\n", __func__, target_bus);
473 chipset_flash_enable();
474
David Hendricks91040832011-07-08 20:01:09 -0700475 ret = it85xx_spi_common_init(s);
476 msg_pdbg("FWH: %s():%d ret=%d\n", __func__, __LINE__, ret);
477 if (!ret) {
hailfinger76bb7e92011-11-09 23:40:00 +0000478 msg_pdbg("%s: internal_buses_supported=0x%x\n", __func__,
479 internal_buses_supported);
480 /* Check for FWH because IT85 listens to FWH cycles.
481 * FIXME: The big question is whether FWH cycles are necessary
482 * for communication even if LPC_IO is defined.
483 */
484 if (internal_buses_supported & BUS_FWH)
485 msg_pdbg("Registering IT85 SPI.\n");
486 /* FIXME: Really leave FWH enabled? We can't use this region
487 * anymore since accessing it would mess up IT85 communication.
488 * If we decide to disable FWH for this region, we should print
489 * a debug message about it.
490 */
David Hendricksac97ece2011-12-15 15:27:22 -0800491 /* Set this as SPI controller and add FWH | LPC to
492 * supported buses. */
David Hendricksac1d25c2016-08-09 17:00:58 -0700493 buses_supported |= BUS_LPC | BUS_FWH;
David Hendricks91040832011-07-08 20:01:09 -0700494 register_spi_programmer(&spi_programmer_it85xx);
495 }
496 return ret;
497}
498
hailfinger8f091492011-02-22 17:16:34 +0000499#endif