Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 1 | /* |
| 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. |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * Contains the ITE IT85* SPI specific routines |
| 21 | */ |
| 22 | |
| 23 | #if defined(__i386__) || defined(__x86_64__) |
| 24 | |
| 25 | #include <string.h> |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 27 | #include <stdlib.h> |
| 28 | #include "flash.h" |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 29 | #include "spi.h" |
| 30 | #include "programmer.h" |
Patrick Georgi | 32508eb | 2012-07-20 20:35:14 +0000 | [diff] [blame] | 31 | #include "hwaccess.h" |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 32 | |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 33 | #define MAX_TIMEOUT 100000 |
| 34 | #define MAX_TRY 5 |
| 35 | |
Carl-Daniel Hailfinger | 7f517a7 | 2011-03-08 00:23:49 +0000 | [diff] [blame] | 36 | /* Constants for I/O ports */ |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 37 | #define ITE_SUPERIO_PORT1 0x2e |
| 38 | #define ITE_SUPERIO_PORT2 0x4e |
| 39 | |
| 40 | /* Legacy I/O */ |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 41 | #define LEGACY_KBC_PORT_DATA 0x60 |
| 42 | #define LEGACY_KBC_PORT_CMD 0x64 |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 43 | |
| 44 | /* Constants for Logical Device registers */ |
| 45 | #define LDNSEL 0x07 |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 46 | |
| 47 | /* These are standard Super I/O 16-bit base address registers */ |
Carl-Daniel Hailfinger | 7f517a7 | 2011-03-08 00:23:49 +0000 | [diff] [blame] | 48 | #define SHM_IO_BAR0 0x60 /* big-endian, this is high bits */ |
| 49 | #define SHM_IO_BAR1 0x61 |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 50 | |
Carl-Daniel Hailfinger | 7f517a7 | 2011-03-08 00:23:49 +0000 | [diff] [blame] | 51 | /* The 8042 keyboard controller uses an input buffer and an output buffer to |
| 52 | * communicate with the host CPU. Both buffers are 1-byte depth. That means |
Elyes HAOUAS | 124ef38 | 2018-03-27 12:15:09 +0200 | [diff] [blame] | 53 | * IBF is set to 1 when the host CPU sends a command to the input buffer |
Carl-Daniel Hailfinger | 7f517a7 | 2011-03-08 00:23:49 +0000 | [diff] [blame] | 54 | * of the EC. IBF is cleared to 0 once the command is read by the EC. |
| 55 | */ |
Elyes HAOUAS | ac01baa | 2018-05-28 16:52:21 +0200 | [diff] [blame] | 56 | #define KB_IBF (1 << 1) /* Input Buffer Full */ |
| 57 | #define KB_OBF (1 << 0) /* Output Buffer Full */ |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 58 | |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 59 | /* IT8502 supports two access modes: |
| 60 | * LPC_MEMORY: through the memory window in 0xFFFFFxxx (follow mode) |
| 61 | * LPC_IO: through I/O port (so called indirect memory) |
| 62 | */ |
| 63 | #undef LPC_MEMORY |
| 64 | #define LPC_IO |
| 65 | |
| 66 | #ifdef LPC_IO |
| 67 | /* macro to fill in indirect-access registers. */ |
| 68 | #define INDIRECT_A0(base, value) OUTB(value, (base) + 0) /* little-endian */ |
| 69 | #define INDIRECT_A1(base, value) OUTB(value, (base) + 1) |
| 70 | #define INDIRECT_A2(base, value) OUTB(value, (base) + 2) |
| 71 | #define INDIRECT_A3(base, value) OUTB(value, (base) + 3) |
| 72 | #define INDIRECT_READ(base) INB((base) + 4) |
| 73 | #define INDIRECT_WRITE(base, value) OUTB(value, (base) + 4) |
| 74 | #endif /* LPC_IO */ |
| 75 | |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 76 | struct it85spi_data { |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 77 | #ifdef LPC_IO |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 78 | unsigned int shm_io_base; |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 79 | #endif |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 80 | unsigned char *ce_high, *ce_low; |
| 81 | int it85xx_scratch_rom_reenter; |
| 82 | }; |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 83 | |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 84 | /* This function will poll the keyboard status register until either |
Carl-Daniel Hailfinger | 082c8b5 | 2011-08-15 19:54:20 +0000 | [diff] [blame] | 85 | * an expected value shows up, or the timeout is reached. |
| 86 | * timeout is in usec. |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 87 | * |
Carl-Daniel Hailfinger | 082c8b5 | 2011-08-15 19:54:20 +0000 | [diff] [blame] | 88 | * Returns: 0 -- the expected value showed up. |
| 89 | * 1 -- timeout. |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 90 | */ |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 91 | static int wait_for(const unsigned int mask, const unsigned int expected_value, |
Carl-Daniel Hailfinger | 082c8b5 | 2011-08-15 19:54:20 +0000 | [diff] [blame] | 92 | const int timeout, const char * error_message, |
| 93 | const char * function_name, const int lineno) |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 94 | { |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 95 | int time_passed; |
| 96 | |
| 97 | for (time_passed = 0;; ++time_passed) { |
| 98 | if ((INB(LEGACY_KBC_PORT_CMD) & mask) == expected_value) |
| 99 | return 0; |
| 100 | if (time_passed >= timeout) |
| 101 | break; |
| 102 | programmer_delay(1); |
| 103 | } |
| 104 | if (error_message) |
| 105 | msg_perr("%s():%d %s", function_name, lineno, error_message); |
| 106 | return 1; |
| 107 | } |
| 108 | |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 109 | /* IT8502 employs a scratch RAM when flash is being updated. Call the following |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 110 | * two functions before/after flash erase/program. */ |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 111 | static void it85xx_enter_scratch_rom(struct it85spi_data *data) |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 112 | { |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 113 | int ret, tries; |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 114 | |
Uwe Hermann | e187d5e | 2011-07-29 20:13:45 +0000 | [diff] [blame] | 115 | msg_pdbg("%s():%d was called ...\n", __func__, __LINE__); |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 116 | if (data->it85xx_scratch_rom_reenter > 0) |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 117 | return; |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 118 | |
| 119 | #if 0 |
| 120 | /* FIXME: this a workaround for the bug that SMBus signal would |
| 121 | * interfere the EC firmware update. Should be removed if |
| 122 | * we find out the root cause. */ |
| 123 | ret = system("stop powerd >&2"); |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 124 | if (ret) |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 125 | msg_perr("Cannot stop powerd.\n"); |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 126 | #endif |
| 127 | |
| 128 | for (tries = 0; tries < MAX_TRY; ++tries) { |
| 129 | /* Wait until IBF (input buffer) is not full. */ |
| 130 | if (wait_for(KB_IBF, 0, MAX_TIMEOUT, |
| 131 | "* timeout at waiting for IBF==0.\n", |
Uwe Hermann | e187d5e | 2011-07-29 20:13:45 +0000 | [diff] [blame] | 132 | __func__, __LINE__)) |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 133 | continue; |
| 134 | |
| 135 | /* Copy EC firmware to SRAM. */ |
| 136 | OUTB(0xb4, LEGACY_KBC_PORT_CMD); |
| 137 | |
| 138 | /* Confirm EC has taken away the command. */ |
| 139 | if (wait_for(KB_IBF, 0, MAX_TIMEOUT, |
| 140 | "* timeout at taking command.\n", |
Uwe Hermann | e187d5e | 2011-07-29 20:13:45 +0000 | [diff] [blame] | 141 | __func__, __LINE__)) |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 142 | continue; |
| 143 | |
| 144 | /* Waiting for OBF (output buffer) has data. |
| 145 | * Note sometimes the replied command might be stolen by kernel |
| 146 | * ISR so that it is okay as long as the command is 0xFA. */ |
| 147 | if (wait_for(KB_OBF, KB_OBF, MAX_TIMEOUT, NULL, NULL, 0)) |
| 148 | msg_pdbg("%s():%d * timeout at waiting for OBF.\n", |
Uwe Hermann | e187d5e | 2011-07-29 20:13:45 +0000 | [diff] [blame] | 149 | __func__, __LINE__); |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 150 | if ((ret = INB(LEGACY_KBC_PORT_DATA)) == 0xFA) { |
| 151 | break; |
| 152 | } else { |
| 153 | msg_perr("%s():%d * not run on SRAM ret=%d\n", |
Uwe Hermann | e187d5e | 2011-07-29 20:13:45 +0000 | [diff] [blame] | 154 | __func__, __LINE__, ret); |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 155 | continue; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | if (tries < MAX_TRY) { |
| 160 | /* EC already runs on SRAM */ |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 161 | data->it85xx_scratch_rom_reenter++; |
Uwe Hermann | e187d5e | 2011-07-29 20:13:45 +0000 | [diff] [blame] | 162 | msg_pdbg("%s():%d * SUCCESS.\n", __func__, __LINE__); |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 163 | } else { |
Uwe Hermann | e187d5e | 2011-07-29 20:13:45 +0000 | [diff] [blame] | 164 | msg_perr("%s():%d * Max try reached.\n", __func__, __LINE__); |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 165 | } |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 168 | static void it85xx_exit_scratch_rom(struct it85spi_data *data) |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 169 | { |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 170 | #if 0 |
| 171 | int ret; |
| 172 | #endif |
| 173 | int tries; |
| 174 | |
Uwe Hermann | e187d5e | 2011-07-29 20:13:45 +0000 | [diff] [blame] | 175 | msg_pdbg("%s():%d was called ...\n", __func__, __LINE__); |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 176 | if (data->it85xx_scratch_rom_reenter <= 0) |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 177 | return; |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 178 | |
| 179 | for (tries = 0; tries < MAX_TRY; ++tries) { |
| 180 | /* Wait until IBF (input buffer) is not full. */ |
| 181 | if (wait_for(KB_IBF, 0, MAX_TIMEOUT, |
| 182 | "* timeout at waiting for IBF==0.\n", |
Uwe Hermann | e187d5e | 2011-07-29 20:13:45 +0000 | [diff] [blame] | 183 | __func__, __LINE__)) |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 184 | continue; |
| 185 | |
| 186 | /* Exit SRAM. Run on flash. */ |
| 187 | OUTB(0xFE, LEGACY_KBC_PORT_CMD); |
| 188 | |
| 189 | /* Confirm EC has taken away the command. */ |
| 190 | if (wait_for(KB_IBF, 0, MAX_TIMEOUT, |
| 191 | "* timeout at taking command.\n", |
Uwe Hermann | e187d5e | 2011-07-29 20:13:45 +0000 | [diff] [blame] | 192 | __func__, __LINE__)) { |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 193 | /* We cannot ensure if EC has exited update mode. |
| 194 | * If EC is in normal mode already, a further 0xFE |
| 195 | * command will reboot system. So, exit loop here. */ |
| 196 | tries = MAX_TRY; |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | break; |
| 201 | } |
| 202 | |
| 203 | if (tries < MAX_TRY) { |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 204 | data->it85xx_scratch_rom_reenter = 0; |
Uwe Hermann | e187d5e | 2011-07-29 20:13:45 +0000 | [diff] [blame] | 205 | msg_pdbg("%s():%d * SUCCESS.\n", __func__, __LINE__); |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 206 | } else { |
Uwe Hermann | e187d5e | 2011-07-29 20:13:45 +0000 | [diff] [blame] | 207 | msg_perr("%s():%d * Max try reached.\n", __func__, __LINE__); |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | #if 0 |
| 211 | /* FIXME: this a workaround for the bug that SMBus signal would |
| 212 | * interfere the EC firmware update. Should be removed if |
| 213 | * we find out the root cause. */ |
| 214 | ret = system("start powerd >&2"); |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 215 | if (ret) |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 216 | msg_perr("Cannot start powerd again.\n"); |
David Hendricks | 4e74839 | 2011-02-28 23:58:15 +0000 | [diff] [blame] | 217 | #endif |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 218 | } |
| 219 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 220 | static int it85xx_shutdown(void *data) |
| 221 | { |
| 222 | msg_pdbg("%s():%d\n", __func__, __LINE__); |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 223 | it85xx_exit_scratch_rom(data); |
| 224 | free(data); |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 225 | |
| 226 | return 0; /* FIXME: Should probably return something meaningful */ |
| 227 | } |
| 228 | |
Anastasia Klimchuk | 5783c04 | 2020-11-17 16:09:51 +1100 | [diff] [blame] | 229 | /* According to ITE 8502 document, the procedure to follow mode is following: |
| 230 | * 1. write 0x00 to LPC/FWH address 0xffff_fexxh (drive CE# high) |
| 231 | * 2. write data to LPC/FWH address 0xffff_fdxxh (drive CE# low and MOSI |
| 232 | * with data) |
| 233 | * 3. read date from LPC/FWH address 0xffff_fdxxh (drive CE# low and get |
| 234 | * data from MISO) |
| 235 | */ |
| 236 | static int it85xx_spi_send_command(const struct flashctx *flash, |
| 237 | unsigned int writecnt, unsigned int readcnt, |
| 238 | const unsigned char *writearr, |
| 239 | unsigned char *readarr) |
| 240 | { |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 241 | unsigned int i; |
| 242 | struct it85spi_data *data = flash->mst->spi.data; |
Anastasia Klimchuk | 5783c04 | 2020-11-17 16:09:51 +1100 | [diff] [blame] | 243 | |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 244 | it85xx_enter_scratch_rom(data); |
Anastasia Klimchuk | 5783c04 | 2020-11-17 16:09:51 +1100 | [diff] [blame] | 245 | /* Exit scratch ROM ONLY when programmer shuts down. Otherwise, the |
| 246 | * temporary flash state may halt the EC. |
| 247 | */ |
| 248 | |
| 249 | #ifdef LPC_IO |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 250 | INDIRECT_A1(data->shm_io_base, (((unsigned long int)data->ce_high) >> 8) & 0xff); |
| 251 | INDIRECT_WRITE(data->shm_io_base, 0xFF); /* Write anything to this address.*/ |
| 252 | INDIRECT_A1(data->shm_io_base, (((unsigned long int)data->ce_low) >> 8) & 0xff); |
Anastasia Klimchuk | 5783c04 | 2020-11-17 16:09:51 +1100 | [diff] [blame] | 253 | #endif |
| 254 | #ifdef LPC_MEMORY |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 255 | mmio_writeb(0, data->ce_high); |
Anastasia Klimchuk | 5783c04 | 2020-11-17 16:09:51 +1100 | [diff] [blame] | 256 | #endif |
| 257 | for (i = 0; i < writecnt; ++i) { |
| 258 | #ifdef LPC_IO |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 259 | INDIRECT_WRITE(data->shm_io_base, writearr[i]); |
Anastasia Klimchuk | 5783c04 | 2020-11-17 16:09:51 +1100 | [diff] [blame] | 260 | #endif |
| 261 | #ifdef LPC_MEMORY |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 262 | mmio_writeb(writearr[i], data->ce_low); |
Anastasia Klimchuk | 5783c04 | 2020-11-17 16:09:51 +1100 | [diff] [blame] | 263 | #endif |
| 264 | } |
| 265 | for (i = 0; i < readcnt; ++i) { |
| 266 | #ifdef LPC_IO |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 267 | readarr[i] = INDIRECT_READ(data->shm_io_base); |
Anastasia Klimchuk | 5783c04 | 2020-11-17 16:09:51 +1100 | [diff] [blame] | 268 | #endif |
| 269 | #ifdef LPC_MEMORY |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 270 | readarr[i] = mmio_readb(data->ce_low); |
Anastasia Klimchuk | 5783c04 | 2020-11-17 16:09:51 +1100 | [diff] [blame] | 271 | #endif |
| 272 | } |
| 273 | #ifdef LPC_IO |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 274 | INDIRECT_A1(data->shm_io_base, (((unsigned long int)data->ce_high) >> 8) & 0xff); |
| 275 | INDIRECT_WRITE(data->shm_io_base, 0xFF); /* Write anything to this address.*/ |
Anastasia Klimchuk | 5783c04 | 2020-11-17 16:09:51 +1100 | [diff] [blame] | 276 | #endif |
| 277 | #ifdef LPC_MEMORY |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 278 | mmio_writeb(0, data->ce_high); |
Anastasia Klimchuk | 5783c04 | 2020-11-17 16:09:51 +1100 | [diff] [blame] | 279 | #endif |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 284 | static struct spi_master spi_master_it85xx = { |
Anastasia Klimchuk | 5783c04 | 2020-11-17 16:09:51 +1100 | [diff] [blame] | 285 | .max_data_read = 64, |
| 286 | .max_data_write = 64, |
| 287 | .command = it85xx_spi_send_command, |
| 288 | .multicommand = default_spi_send_multicommand, |
| 289 | .read = default_spi_read, |
| 290 | .write_256 = default_spi_write_256, |
| 291 | .write_aai = default_spi_write_aai, |
| 292 | }; |
| 293 | |
Carl-Daniel Hailfinger | bfecef6 | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 294 | static int it85xx_spi_common_init(struct superio s) |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 295 | { |
| 296 | chipaddr base; |
| 297 | |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 298 | struct it85spi_data *data = calloc(1, sizeof(struct it85spi_data)); |
| 299 | if (!data) { |
| 300 | msg_perr("Unable to allocate space for extra SPI master data.\n"); |
| 301 | return SPI_GENERIC_ERROR; |
| 302 | } |
| 303 | |
| 304 | spi_master_it85xx.data = data; |
| 305 | |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 306 | msg_pdbg("%s():%d superio.vendor=0x%02x\n", __func__, __LINE__, |
Carl-Daniel Hailfinger | bfecef6 | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 307 | s.vendor); |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 308 | |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 309 | if (register_shutdown(it85xx_shutdown, data)) { |
| 310 | free(data); |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 311 | return 1; |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 312 | } |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 313 | |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 314 | #ifdef LPC_IO |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 315 | /* Get LPCPNP of SHM. That's big-endian. */ |
Carl-Daniel Hailfinger | bfecef6 | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 316 | sio_write(s.port, LDNSEL, 0x0F); /* Set LDN to SHM (0x0F) */ |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 317 | data->shm_io_base = (sio_read(s.port, SHM_IO_BAR0) << 8) + |
Carl-Daniel Hailfinger | bfecef6 | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 318 | sio_read(s.port, SHM_IO_BAR1); |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 319 | msg_pdbg("%s():%d it85spi_data->shm_io_base=0x%04x\n", __func__, __LINE__, |
| 320 | data->shm_io_base); |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 321 | |
| 322 | /* These pointers are not used directly. They will be send to EC's |
| 323 | * register for indirect access. */ |
| 324 | base = 0xFFFFF000; |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 325 | data->ce_high = ((unsigned char *)base) + 0xE00; /* 0xFFFFFE00 */ |
| 326 | data->ce_low = ((unsigned char *)base) + 0xD00; /* 0xFFFFFD00 */ |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 327 | |
| 328 | /* pre-set indirect-access registers since in most of cases they are |
| 329 | * 0xFFFFxx00. */ |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 330 | INDIRECT_A0(data->shm_io_base, base & 0xFF); |
| 331 | INDIRECT_A2(data->shm_io_base, (base >> 16) & 0xFF); |
| 332 | INDIRECT_A3(data->shm_io_base, (base >> 24)); |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 333 | #endif |
| 334 | #ifdef LPC_MEMORY |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 335 | /* FIXME: We should block accessing that region for anything else. |
| 336 | * Major TODO here, and it will be a lot of work. |
| 337 | */ |
| 338 | base = (chipaddr)physmap("it85 communication", 0xFFFFF000, 0x1000); |
Stefan Tauner | 7fb5aa0 | 2013-08-14 15:48:44 +0000 | [diff] [blame] | 339 | if (base == (chipaddr)ERROR_PTR) |
| 340 | return 1; |
| 341 | |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 342 | msg_pdbg("%s():%d base=0x%08x\n", __func__, __LINE__, |
| 343 | (unsigned int)base); |
Anastasia Klimchuk | 22f0b06 | 2020-11-17 13:25:46 +1100 | [diff] [blame^] | 344 | data->ce_high = (unsigned char *)(base + 0xE00); /* 0xFFFFFE00 */ |
| 345 | data->ce_low = (unsigned char *)(base + 0xD00); /* 0xFFFFFD00 */ |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 346 | #endif |
| 347 | |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 348 | return 0; |
| 349 | } |
| 350 | |
Carl-Daniel Hailfinger | bfecef6 | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 351 | int it85xx_spi_init(struct superio s) |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 352 | { |
| 353 | int ret; |
| 354 | |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 355 | if (!(internal_buses_supported & BUS_FWH)) { |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 356 | msg_pdbg("%s():%d buses not support FWH\n", __func__, __LINE__); |
| 357 | return 1; |
| 358 | } |
Carl-Daniel Hailfinger | bfecef6 | 2011-04-27 14:34:08 +0000 | [diff] [blame] | 359 | ret = it85xx_spi_common_init(s); |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 360 | msg_pdbg("FWH: %s():%d ret=%d\n", __func__, __LINE__, ret); |
| 361 | if (!ret) { |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 362 | msg_pdbg("%s: internal_buses_supported=0x%x\n", __func__, |
| 363 | internal_buses_supported); |
| 364 | /* Check for FWH because IT85 listens to FWH cycles. |
| 365 | * FIXME: The big question is whether FWH cycles are necessary |
| 366 | * for communication even if LPC_IO is defined. |
| 367 | */ |
| 368 | if (internal_buses_supported & BUS_FWH) |
| 369 | msg_pdbg("Registering IT85 SPI.\n"); |
| 370 | /* FIXME: Really leave FWH enabled? We can't use this region |
| 371 | * anymore since accessing it would mess up IT85 communication. |
| 372 | * If we decide to disable FWH for this region, we should print |
| 373 | * a debug message about it. |
| 374 | */ |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 375 | /* Set this as SPI controller. */ |
Carl-Daniel Hailfinger | a5bcbce | 2014-07-19 22:03:29 +0000 | [diff] [blame] | 376 | register_spi_master(&spi_master_it85xx); |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 377 | } |
| 378 | return ret; |
| 379 | } |
| 380 | |
Donald Huang | 44ebb04 | 2011-02-22 17:16:34 +0000 | [diff] [blame] | 381 | #endif |