blob: a17bacdef59a2304480a05871d06d1b11cd5fbae [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.
hailfinger8f091492011-02-22 17:16:34 +000017 */
18
19/*
20 * Contains the ITE IT85* SPI specific routines
David Hendricks42ad6522011-08-09 16:08:10 -070021 *
22 * FIXME: EC firmware updates on this chip can be interrupted due to factors
23 * such as SMBus traffic. YOU MUST DISABLE any services, such as power
24 * management daemons, which can interact with the EC during firmware update.
hailfinger8f091492011-02-22 17:16:34 +000025 */
26
27#if defined(__i386__) || defined(__x86_64__)
28
29#include <string.h>
hailfinger2b46a862011-02-28 23:58:15 +000030#include <stdio.h>
hailfinger8f091492011-02-22 17:16:34 +000031#include <stdlib.h>
32#include "flash.h"
hailfinger8f091492011-02-22 17:16:34 +000033#include "spi.h"
34#include "programmer.h"
Mayur Panchalf4796862019-08-05 15:46:12 +100035#include "hwaccess.h"
hailfinger8f091492011-02-22 17:16:34 +000036
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -070037/* Supported ECs, ITE_LAST should always be LAST member */
38enum ite_chip_id {
39 ITE_IT85XX,
40 ITE_IT8518,
41 ITE_LAST
42};
43
44/* chip-specific parameters */
45typedef struct {
46 enum ite_chip_id chip_id;
47 uint8_t port_data;
48 uint8_t port_cmd;
49 uint8_t copy_to_sram_cmd;
50 uint8_t exit_sram_cmd;
51 uint32_t exit_sram_delay;
52} ite_chip;
53
54/* table of supported chips + parameters, order by ite_chip_id index */
55static ite_chip ite_chips[] = {
56 { ITE_IT85XX,
57 0x60,
58 0x64,
59 0xB4,
60 0xFE,
61 0,
62 },
63
64 { ITE_IT8518,
65 0x62,
66 0x66,
David Hendricks74915852012-09-27 16:39:37 -070067 0xDD, /* default value, see note in it85xx_spi_send_command */
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -070068 0xFF,
69 500000,
70 }
71};
72
73/* pointer to table entry of identified chip */
74static ite_chip *found_chip;
75
hailfinger2b46a862011-02-28 23:58:15 +000076#define MAX_TIMEOUT 100000
77#define MAX_TRY 5
78
hailfinger177cdd82011-03-08 00:23:49 +000079/* Constants for I/O ports */
hailfinger8f091492011-02-22 17:16:34 +000080#define ITE_SUPERIO_PORT1 0x2e
81#define ITE_SUPERIO_PORT2 0x4e
82
hailfinger8f091492011-02-22 17:16:34 +000083/* Constants for Logical Device registers */
84#define LDNSEL 0x07
hailfinger8f091492011-02-22 17:16:34 +000085
86/* These are standard Super I/O 16-bit base address registers */
hailfinger177cdd82011-03-08 00:23:49 +000087#define SHM_IO_BAR0 0x60 /* big-endian, this is high bits */
88#define SHM_IO_BAR1 0x61
hailfinger8f091492011-02-22 17:16:34 +000089
hailfinger177cdd82011-03-08 00:23:49 +000090/* The 8042 keyboard controller uses an input buffer and an output buffer to
91 * communicate with the host CPU. Both buffers are 1-byte depth. That means
92 * IBF is set to 1 when the host CPU sends a command to the input buffer
93 * of the EC. IBF is cleared to 0 once the command is read by the EC.
94 */
hailfinger2b46a862011-02-28 23:58:15 +000095#define KB_IBF (1 << 1) /* Input Buffer Full */
96#define KB_OBF (1 << 0) /* Output Buffer Full */
97
hailfinger8f091492011-02-22 17:16:34 +000098/* IT8502 supports two access modes:
99 * LPC_MEMORY: through the memory window in 0xFFFFFxxx (follow mode)
100 * LPC_IO: through I/O port (so called indirect memory)
101 */
102#undef LPC_MEMORY
103#define LPC_IO
104
105#ifdef LPC_IO
106/* macro to fill in indirect-access registers. */
107#define INDIRECT_A0(base, value) OUTB(value, (base) + 0) /* little-endian */
108#define INDIRECT_A1(base, value) OUTB(value, (base) + 1)
109#define INDIRECT_A2(base, value) OUTB(value, (base) + 2)
110#define INDIRECT_A3(base, value) OUTB(value, (base) + 3)
111#define INDIRECT_READ(base) INB((base) + 4)
112#define INDIRECT_WRITE(base, value) OUTB(value, (base) + 4)
113#endif /* LPC_IO */
114
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100115struct it85spi_data {
hailfinger8f091492011-02-22 17:16:34 +0000116#ifdef LPC_IO
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100117 unsigned int shm_io_base;
hailfinger8f091492011-02-22 17:16:34 +0000118#endif
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100119 unsigned char *ce_high, *ce_low;
120 int it85xx_scratch_rom_reenter;
121};
hailfinger8f091492011-02-22 17:16:34 +0000122
hailfinger2b46a862011-02-28 23:58:15 +0000123/* This function will poll the keyboard status register until either
hailfingerb91c08c2011-08-15 19:54:20 +0000124 * an expected value shows up, or the timeout is reached.
125 * timeout is in usec.
hailfinger2b46a862011-02-28 23:58:15 +0000126 *
hailfingerb91c08c2011-08-15 19:54:20 +0000127 * Returns: 0 -- the expected value showed up.
128 * 1 -- timeout.
hailfinger2b46a862011-02-28 23:58:15 +0000129 */
uwe8d342eb2011-07-28 08:13:25 +0000130static int wait_for(const unsigned int mask, const unsigned int expected_value,
hailfingerb91c08c2011-08-15 19:54:20 +0000131 const int timeout, const char * error_message,
132 const char * function_name, const int lineno)
uwe8d342eb2011-07-28 08:13:25 +0000133{
hailfinger2b46a862011-02-28 23:58:15 +0000134 int time_passed;
135
136 for (time_passed = 0;; ++time_passed) {
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700137 if ((INB(found_chip->port_cmd) & mask) == expected_value)
hailfinger2b46a862011-02-28 23:58:15 +0000138 return 0;
139 if (time_passed >= timeout)
140 break;
141 programmer_delay(1);
142 }
143 if (error_message)
144 msg_perr("%s():%d %s", function_name, lineno, error_message);
145 return 1;
146}
147
uwe8d342eb2011-07-28 08:13:25 +0000148/* IT8502 employs a scratch RAM when flash is being updated. Call the following
hailfinger2b46a862011-02-28 23:58:15 +0000149 * two functions before/after flash erase/program. */
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100150static void it85xx_enter_scratch_rom(struct it85spi_data *data)
hailfinger8f091492011-02-22 17:16:34 +0000151{
uwe8d342eb2011-07-28 08:13:25 +0000152 int ret, tries;
hailfinger2b46a862011-02-28 23:58:15 +0000153
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100154 if (data->it85xx_scratch_rom_reenter > 0)
uwe8d342eb2011-07-28 08:13:25 +0000155 return;
David Hendricks932dfe42012-09-21 14:46:41 -0700156
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700157 msg_pdbg("%s: entering scratch rom mode\n", __func__);
158
hailfinger2b46a862011-02-28 23:58:15 +0000159 for (tries = 0; tries < MAX_TRY; ++tries) {
160 /* Wait until IBF (input buffer) is not full. */
161 if (wait_for(KB_IBF, 0, MAX_TIMEOUT,
162 "* timeout at waiting for IBF==0.\n",
uwe44e2dc42011-07-29 20:13:45 +0000163 __func__, __LINE__))
hailfinger2b46a862011-02-28 23:58:15 +0000164 continue;
165
166 /* Copy EC firmware to SRAM. */
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700167 OUTB(found_chip->copy_to_sram_cmd, found_chip->port_cmd);
hailfinger2b46a862011-02-28 23:58:15 +0000168
169 /* Confirm EC has taken away the command. */
170 if (wait_for(KB_IBF, 0, MAX_TIMEOUT,
171 "* timeout at taking command.\n",
uwe44e2dc42011-07-29 20:13:45 +0000172 __func__, __LINE__))
hailfinger2b46a862011-02-28 23:58:15 +0000173 continue;
174
175 /* Waiting for OBF (output buffer) has data.
176 * Note sometimes the replied command might be stolen by kernel
177 * ISR so that it is okay as long as the command is 0xFA. */
178 if (wait_for(KB_OBF, KB_OBF, MAX_TIMEOUT, NULL, NULL, 0))
179 msg_pdbg("%s():%d * timeout at waiting for OBF.\n",
uwe44e2dc42011-07-29 20:13:45 +0000180 __func__, __LINE__);
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700181 if ((ret = INB(found_chip->port_data)) == 0xFA) {
hailfinger2b46a862011-02-28 23:58:15 +0000182 break;
183 } else {
184 msg_perr("%s():%d * not run on SRAM ret=%d\n",
uwe44e2dc42011-07-29 20:13:45 +0000185 __func__, __LINE__, ret);
hailfinger2b46a862011-02-28 23:58:15 +0000186 continue;
187 }
188 }
189
190 if (tries < MAX_TRY) {
191 /* EC already runs on SRAM */
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100192 data->it85xx_scratch_rom_reenter++;
uwe44e2dc42011-07-29 20:13:45 +0000193 msg_pdbg("%s():%d * SUCCESS.\n", __func__, __LINE__);
hailfinger2b46a862011-02-28 23:58:15 +0000194 } else {
uwe44e2dc42011-07-29 20:13:45 +0000195 msg_perr("%s():%d * Max try reached.\n", __func__, __LINE__);
hailfinger2b46a862011-02-28 23:58:15 +0000196 }
hailfinger8f091492011-02-22 17:16:34 +0000197}
198
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100199static void it85xx_exit_scratch_rom(struct it85spi_data *data)
hailfinger8f091492011-02-22 17:16:34 +0000200{
hailfinger2b46a862011-02-28 23:58:15 +0000201 int tries;
202
uwe44e2dc42011-07-29 20:13:45 +0000203 msg_pdbg("%s():%d was called ...\n", __func__, __LINE__);
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100204 if (data->it85xx_scratch_rom_reenter <= 0)
uwe8d342eb2011-07-28 08:13:25 +0000205 return;
hailfinger2b46a862011-02-28 23:58:15 +0000206
207 for (tries = 0; tries < MAX_TRY; ++tries) {
208 /* Wait until IBF (input buffer) is not full. */
209 if (wait_for(KB_IBF, 0, MAX_TIMEOUT,
210 "* timeout at waiting for IBF==0.\n",
uwe44e2dc42011-07-29 20:13:45 +0000211 __func__, __LINE__))
hailfinger2b46a862011-02-28 23:58:15 +0000212 continue;
213
214 /* Exit SRAM. Run on flash. */
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700215 OUTB(found_chip->exit_sram_cmd, found_chip->port_cmd);
hailfinger2b46a862011-02-28 23:58:15 +0000216
217 /* Confirm EC has taken away the command. */
218 if (wait_for(KB_IBF, 0, MAX_TIMEOUT,
219 "* timeout at taking command.\n",
uwe44e2dc42011-07-29 20:13:45 +0000220 __func__, __LINE__)) {
hailfinger2b46a862011-02-28 23:58:15 +0000221 /* We cannot ensure if EC has exited update mode.
222 * If EC is in normal mode already, a further 0xFE
223 * command will reboot system. So, exit loop here. */
224 tries = MAX_TRY;
225 break;
226 }
227
228 break;
229 }
230
231 if (tries < MAX_TRY) {
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100232 data->it85xx_scratch_rom_reenter = 0;
uwe44e2dc42011-07-29 20:13:45 +0000233 msg_pdbg("%s():%d * SUCCESS.\n", __func__, __LINE__);
hailfinger2b46a862011-02-28 23:58:15 +0000234 } else {
uwe44e2dc42011-07-29 20:13:45 +0000235 msg_perr("%s():%d * Max try reached.\n", __func__, __LINE__);
hailfinger2b46a862011-02-28 23:58:15 +0000236 }
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700237
238 programmer_delay(found_chip->exit_sram_delay);
hailfinger8f091492011-02-22 17:16:34 +0000239}
240
David Hendricks93784b42016-08-09 17:00:38 -0700241static int it85xx_shutdown(void *data)
dhendrix0ffc2eb2011-06-14 01:35:36 +0000242{
243 msg_pdbg("%s():%d\n", __func__, __LINE__);
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100244 it85xx_exit_scratch_rom(data);
245 free(data);
dhendrix0ffc2eb2011-06-14 01:35:36 +0000246
David Hendricks932dfe42012-09-21 14:46:41 -0700247 return 0; /* FIXME: Should probably return something meaningful */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000248}
249
hailfinger8f091492011-02-22 17:16:34 +0000250/* According to ITE 8502 document, the procedure to follow mode is following:
251 * 1. write 0x00 to LPC/FWH address 0xffff_fexxh (drive CE# high)
252 * 2. write data to LPC/FWH address 0xffff_fdxxh (drive CE# low and MOSI
253 * with data)
254 * 3. read date from LPC/FWH address 0xffff_fdxxh (drive CE# low and get
255 * data from MISO)
256 */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700257static int it85xx_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger8f091492011-02-22 17:16:34 +0000258 const unsigned char *writearr, unsigned char *readarr)
259{
Edward O'Callaghan82d7a4d2021-01-08 12:19:23 +1100260 unsigned i;
David Hendricks74915852012-09-27 16:39:37 -0700261 static int wdt_reset_flag_set = 0;
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100262 struct it85spi_data *data = flash->mst->spi.data;
David Hendricks74915852012-09-27 16:39:37 -0700263
264 if (found_chip->chip_id == ITE_IT8518) {
265 /*
266 * 0xd8 - Sets WDT reset flag to reboot EC after exiting from
267 * scratch mode. This flag will be be checked when
268 * command 0x8c is received. Use this when changing
269 * ROM content (erase / write commands).
270 * 0xdd - Same as d8, but without setting the WDT reset flag.
271 * Use this for commands that do not change EC code.
272 *
273 * If opcode will cause ROM content to change and scratch
274 * mode has been previously entered, then we need to re-enter
275 * scratch mode using 0xd8.
276 *
277 * FIXME(dhendrix): This is specific to Stout. We should use
278 * better method to apply board hacks rather than using the
279 * EC's chip ID as the condition.
280 */
281 switch (writearr[0]) {
282 case JEDEC_BYTE_PROGRAM:
283 case JEDEC_BE_52:
284 case JEDEC_BE_D7:
285 case JEDEC_BE_D8:
286 case JEDEC_CE_60:
287 case JEDEC_CE_C7:
288 case JEDEC_SE:
289 if (!wdt_reset_flag_set) {
290 msg_pdbg("%s: changing copy_to_sram_cmd\n",
291 __func__);
292 found_chip->copy_to_sram_cmd = 0xd8;
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100293 it85xx_exit_scratch_rom(data);
David Hendricks74915852012-09-27 16:39:37 -0700294 wdt_reset_flag_set = 1;
295 }
296 break;
297 default:
298 break;
299 }
300 }
hailfinger8f091492011-02-22 17:16:34 +0000301
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100302 it85xx_enter_scratch_rom(data);
hailfingerb91c08c2011-08-15 19:54:20 +0000303 /* Exit scratch ROM ONLY when programmer shuts down. Otherwise, the
304 * temporary flash state may halt the EC.
305 */
hailfinger8f091492011-02-22 17:16:34 +0000306
307#ifdef LPC_IO
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100308 INDIRECT_A1(data->shm_io_base, (((unsigned long int)data->ce_high) >> 8) & 0xff);
309 INDIRECT_WRITE(data->shm_io_base, 0xFF); /* Write anything to this address.*/
310 INDIRECT_A1(data->shm_io_base, (((unsigned long int)data->ce_low) >> 8) & 0xff);
hailfinger8f091492011-02-22 17:16:34 +0000311#endif
312#ifdef LPC_MEMORY
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100313 mmio_writeb(0, data->ce_high);
hailfinger8f091492011-02-22 17:16:34 +0000314#endif
315 for (i = 0; i < writecnt; ++i) {
316#ifdef LPC_IO
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100317 INDIRECT_WRITE(data->shm_io_base, writearr[i]);
hailfinger8f091492011-02-22 17:16:34 +0000318#endif
319#ifdef LPC_MEMORY
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100320 mmio_writeb(writearr[i], data->ce_low);
hailfinger8f091492011-02-22 17:16:34 +0000321#endif
322 }
323 for (i = 0; i < readcnt; ++i) {
324#ifdef LPC_IO
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100325 readarr[i] = INDIRECT_READ(data->shm_io_base);
hailfinger8f091492011-02-22 17:16:34 +0000326#endif
327#ifdef LPC_MEMORY
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100328 readarr[i] = mmio_readb(data->ce_low);
hailfinger8f091492011-02-22 17:16:34 +0000329#endif
330 }
hailfinger2b46a862011-02-28 23:58:15 +0000331#ifdef LPC_IO
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100332 INDIRECT_A1(data->shm_io_base, (((unsigned long int)data->ce_high) >> 8) & 0xff);
333 INDIRECT_WRITE(data->shm_io_base, 0xFF); /* Write anything to this address.*/
hailfinger2b46a862011-02-28 23:58:15 +0000334#endif
335#ifdef LPC_MEMORY
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100336 mmio_writeb(0, data->ce_high);
hailfinger2b46a862011-02-28 23:58:15 +0000337#endif
338
hailfinger8f091492011-02-22 17:16:34 +0000339 return 0;
340}
341
Nico Huber2ef004f2021-05-11 17:53:34 +0200342static const struct spi_master spi_master_it8518 = {
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700343 .max_data_read = 256,
344 .max_data_write = 256,
345 .command = it85xx_spi_send_command,
346 .multicommand = default_spi_send_multicommand,
347 .read = default_spi_read,
348 .write_256 = default_spi_write_256,
349};
350
Nico Huber2ef004f2021-05-11 17:53:34 +0200351static const struct spi_master spi_master_it85xx = {
David Hendricks91040832011-07-08 20:01:09 -0700352 .max_data_read = 1,
353 .max_data_write = 1,
354 .command = it85xx_spi_send_command,
355 .multicommand = default_spi_send_multicommand,
356 .read = default_spi_read,
357 .write_256 = default_spi_write_256,
358};
359
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700360/* it8518-specific i/o initialization */
Edward O'Callaghand22a9e72020-11-18 11:19:50 +1100361static void setup_it8518_io_base()
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700362{
363 OUTB(0x07, 0x2e); /* Set LDN to SHM */
364 OUTB(0x0f, 0x2f);
365 OUTB(0x60, 0x2e); /* Set IO space to 0x3F0 */
366 OUTB(0x03, 0x2f);
367 OUTB(0x61, 0x2e);
368 OUTB(0xf0, 0x2f);
369 OUTB(0x30, 0x2e); /* Enable this Logical Device */
370 OUTB(0x01, 0x2f);
371}
372
David Hendricks2b56e472016-10-21 19:05:21 -0700373static int check_params(void)
374{
375 int ret = 0;
376 char *p = NULL;
377
378 p = extract_programmer_param("type");
379 if (p && strcmp(p, "ec")) {
380 msg_pdbg("it85xx only supports \"ec\" type devices\n");
381 ret = 1;
382 }
383
384 free(p);
385 return ret;
386}
387
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100388static int it85xx_spi_common_init(struct superio s, struct it85spi_data *data)
Edward O'Callaghan98704352020-11-18 10:59:00 +1100389{
390 chipaddr base;
391
392 msg_pdbg("%s():%d superio.vendor=0x%02x\n", __func__, __LINE__,
393 s.vendor);
394
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100395 if (register_shutdown(it85xx_shutdown, data)) {
396 free(data);
Edward O'Callaghan98704352020-11-18 10:59:00 +1100397 return 1;
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100398 }
Edward O'Callaghan98704352020-11-18 10:59:00 +1100399
400#ifdef LPC_IO
401 /* Get LPCPNP of SHM. That's big-endian. */
402 sio_write(s.port, LDNSEL, 0x0F); /* Set LDN to SHM (0x0F) */
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100403 data->shm_io_base = (sio_read(s.port, SHM_IO_BAR0) << 8) +
Edward O'Callaghan98704352020-11-18 10:59:00 +1100404 sio_read(s.port, SHM_IO_BAR1);
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100405 msg_pdbg("%s():%d it85spi_data->shm_io_base=0x%04x\n", __func__, __LINE__,
406 data->shm_io_base);
Edward O'Callaghan98704352020-11-18 10:59:00 +1100407
408 /* These pointers are not used directly. They will be send to EC's
409 * register for indirect access. */
410 base = 0xFFFFF000;
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100411 data->ce_high = ((unsigned char *)base) + 0xE00; /* 0xFFFFFE00 */
412 data->ce_low = ((unsigned char *)base) + 0xD00; /* 0xFFFFFD00 */
Edward O'Callaghan98704352020-11-18 10:59:00 +1100413
414 /* pre-set indirect-access registers since in most of cases they are
415 * 0xFFFFxx00. */
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100416 INDIRECT_A0(data->shm_io_base, base & 0xFF);
417 INDIRECT_A2(data->shm_io_base, (base >> 16) & 0xFF);
418 INDIRECT_A3(data->shm_io_base, (base >> 24));
Edward O'Callaghan98704352020-11-18 10:59:00 +1100419#endif
420#ifdef LPC_MEMORY
421 /* FIXME: We should block accessing that region for anything else.
422 * Major TODO here, and it will be a lot of work.
423 */
424 base = (chipaddr)physmap("it85 communication", 0xFFFFF000, 0x1000);
425 msg_pdbg("%s():%d base=0x%08x\n", __func__, __LINE__,
426 (unsigned int)base);
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100427 data->ce_high = (unsigned char *)(base + 0xE00); /* 0xFFFFFE00 */
428 data->ce_low = (unsigned char *)(base + 0xD00); /* 0xFFFFFD00 */
Edward O'Callaghan98704352020-11-18 10:59:00 +1100429#endif
430
431 return 0;
432}
433
David Hendricksac1d25c2016-08-09 17:00:58 -0700434int it8518_spi_init(struct superio s)
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700435{
436 int ret;
David Hendricks2b56e472016-10-21 19:05:21 -0700437
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100438 struct it85spi_data *data = calloc(1, sizeof(struct it85spi_data));
439 if (!data) {
440 msg_perr("Unable to allocate space for extra SPI master data.\n");
441 return SPI_GENERIC_ERROR;
442 }
443
David Hendricks2b56e472016-10-21 19:05:21 -0700444 if (check_params())
445 return 1;
446
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700447 if (!(internal_buses_supported & BUS_FWH)) {
448 msg_pdbg("%s():%d buses not support FWH\n", __func__, __LINE__);
449 return 1;
450 }
451
452 found_chip = &ite_chips[ITE_IT8518];
453
454#ifdef LPC_IO
455 setup_it8518_io_base();
456#endif
457
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100458 ret = it85xx_spi_common_init(s, data);
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700459 if (!ret) {
460 msg_pdbg("%s: internal_buses_supported=0x%x\n", __func__,
461 internal_buses_supported);
462 /* Check for FWH because IT85 listens to FWH cycles.
463 * FIXME: The big question is whether FWH cycles are necessary
464 * for communication even if LPC_IO is defined.
465 */
466 if (internal_buses_supported & BUS_FWH)
467 msg_pdbg("Registering IT85 SPI.\n");
468 /* FIXME: Really leave FWH enabled? We can't use this region
469 * anymore since accessing it would mess up IT85 communication.
470 * If we decide to disable FWH for this region, we should print
471 * a debug message about it.
472 */
473 /* Set this as SPI controller and add FWH | LPC to
474 * supported buses. */
Edward O'Callaghanc66827e2020-10-09 12:22:04 +1100475 internal_buses_supported |= BUS_LPC | BUS_FWH;
Nico Huber2ef004f2021-05-11 17:53:34 +0200476 register_spi_master(&spi_master_it8518, data);
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700477 }
478 return ret;
479}
480
David Hendricksac1d25c2016-08-09 17:00:58 -0700481int it85xx_spi_init(struct superio s)
David Hendricks91040832011-07-08 20:01:09 -0700482{
483 int ret;
484
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100485 struct it85spi_data *data = calloc(1, sizeof(struct it85spi_data));
486 if (!data) {
487 msg_perr("Unable to allocate space for extra SPI master data.\n");
488 return SPI_GENERIC_ERROR;
489 }
490
David Hendricks2b56e472016-10-21 19:05:21 -0700491 if (check_params())
492 return 1;
493
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700494 found_chip = &ite_chips[ITE_IT85XX];
495
David Hendricksba0827a2013-05-03 20:25:40 -0700496 chipset_flash_enable();
497
Anastasia Klimchuk39c3a352020-11-17 13:25:46 +1100498 ret = it85xx_spi_common_init(s, data);
David Hendricks91040832011-07-08 20:01:09 -0700499 msg_pdbg("FWH: %s():%d ret=%d\n", __func__, __LINE__, ret);
500 if (!ret) {
hailfinger76bb7e92011-11-09 23:40:00 +0000501 msg_pdbg("%s: internal_buses_supported=0x%x\n", __func__,
502 internal_buses_supported);
503 /* Check for FWH because IT85 listens to FWH cycles.
504 * FIXME: The big question is whether FWH cycles are necessary
505 * for communication even if LPC_IO is defined.
506 */
507 if (internal_buses_supported & BUS_FWH)
508 msg_pdbg("Registering IT85 SPI.\n");
509 /* FIXME: Really leave FWH enabled? We can't use this region
510 * anymore since accessing it would mess up IT85 communication.
511 * If we decide to disable FWH for this region, we should print
512 * a debug message about it.
513 */
David Hendricksac97ece2011-12-15 15:27:22 -0800514 /* Set this as SPI controller and add FWH | LPC to
515 * supported buses. */
Edward O'Callaghanc66827e2020-10-09 12:22:04 +1100516 internal_buses_supported |= BUS_LPC | BUS_FWH;
Nico Huber2ef004f2021-05-11 17:53:34 +0200517 register_spi_master(&spi_master_it85xx, data);
David Hendricks91040832011-07-08 20:01:09 -0700518 }
David Hendricks2b56e472016-10-21 19:05:21 -0700519
David Hendricks91040832011-07-08 20:01:09 -0700520 return ret;
521}
522
hailfinger8f091492011-02-22 17:16:34 +0000523#endif