Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: it85spi.c

Issue 3162005: add it8500 support (Closed) Base URL: ssh://git@gitrw.chromium.org/flashrom
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « internal.c ('k') | programmer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
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
25 */
26
27 #if defined(__i386__) || defined(__x86_64__)
28
29 #include <string.h>
30 #include <stdlib.h>
31 #include "flash.h"
32 #include "chipdrivers.h"
33 #include "spi.h"
34 #include "programmer.h"
35
36 /* Constans for I/O ports */
37 #define ITE_SUPERIO_PORT1 0x2e
38 #define ITE_SUPERIO_PORT2 0x4e
39
40 /* Legacy I/O */
41 #define LEGACY_KBC_PORT 0x64
42
43 /* Constants for Logical Device registers */
44 #define LDNSEL 0x07
45 #define CHIP_ID_BYTE1_REG 0x20
46 #define CHIP_ID_BYTE2_REG 0x21
47 #define CHIP_CHIP_VER_REG 0x22
48
49 /* These are standard Super I/O 16-bit base address registers */
50 #define SHM_IO_BAD0 0x60 /* big-endian, this is high bits */
51 #define SHM_IO_BAD1 0x61
52
53 /* IT8502 supports two access modes:
54 * LPC_MEMORY: through the memory window in 0xFFFFFxxx (follow mode)
55 * LPC_IO: through I/O port (so called indirect memory)
56 */
57 #undef LPC_MEMORY
58 #define LPC_IO
59
60 #ifdef LPC_IO
61 /* macro to fill in indirect-access registers. */
62 #define INDIRECT_A0(base, value) OUTB(value, (base) + 0) /* little-endian */
63 #define INDIRECT_A1(base, value) OUTB(value, (base) + 1)
64 #define INDIRECT_A2(base, value) OUTB(value, (base) + 2)
65 #define INDIRECT_A3(base, value) OUTB(value, (base) + 3)
66 #define INDIRECT_READ(base) INB((base) + 4)
67 #define INDIRECT_WRITE(base, value) OUTB(value, (base) + 4)
68 #endif /* LPC_IO */
69
70 #ifdef LPC_IO
71 unsigned int shm_io_base;
72 #endif
73 unsigned char *ce_high, *ce_low;
74 static int it85xx_scratch_rom_reenter = 0;
75
76 uint16_t probe_id_ite85(uint16_t port)
77 {
78 uint16_t id;
79
80 id = sio_read(port, CHIP_ID_BYTE1_REG) << 8 |
81 sio_read(port, CHIP_ID_BYTE2_REG);
82
83 return id;
84 }
85
86 struct superio probe_superio_ite85xx(void)
87 {
88 struct superio ret = {};
89 uint16_t ite_ports[] = {ITE_SUPERIO_PORT1, ITE_SUPERIO_PORT2, 0};
90 uint16_t *i = ite_ports;
91
92 ret.vendor = SUPERIO_VENDOR_ITE;
93 for (; *i; i++) {
94 ret.port = *i;
95 ret.model = probe_id_ite85(ret.port);
96 switch (ret.model >> 8) {
97 case 0x85:
98 msg_pinfo("Found EC: ITE85xx (Vendor:0x%02x,ID:0x%02x,"
99 "Rev:0x%02x) on sio_port:0x%x.\n",
100 ret.model >> 8, ret.model & 0xff,
101 sio_read(ret.port, CHIP_CHIP_VER_REG),
102 ret.port);
103 return ret;
104 }
105 }
106
107 /* No good ID found. */
108 ret.vendor = SUPERIO_VENDOR_NONE;
109 ret.port = 0;
110 ret.model = 0;
111 return ret;
112 }
113
114 /* IT8502 employs a scratch rom when flash is updating. Call the following two
115 * functions before/after flash erase/program. */
116 void it85xx_enter_scratch_rom()
117 {
118 if (it85xx_scratch_rom_reenter > 0) return;
119 it85xx_scratch_rom_reenter++;
120 OUTB(0xb4, LEGACY_KBC_PORT);
121 }
122
123 void it85xx_exit_scratch_rom()
124 {
125 if (it85xx_scratch_rom_reenter <= 0) return;
126 it85xx_scratch_rom_reenter = 0;
127 OUTB(0xfe, LEGACY_KBC_PORT);
128 }
129
130 int it85xx_spi_common_init(void)
131 {
132 chipaddr base;
133
134 msg_pdbg("%s():%d superio.vendor=0x%02x\n", __func__, __LINE__,
135 superio.vendor);
136 if (superio.vendor != SUPERIO_VENDOR_ITE)
137 return 1;
138
139 #ifdef LPC_IO
140 /* Get LPCPNP of SHM. That's big-endian */
141 sio_write(superio.port, LDNSEL, 0x0F); /* Set LDN to SHM (0x0F) */
142 shm_io_base = (sio_read(superio.port, SHM_IO_BAD0) << 8) +
143 sio_read(superio.port, SHM_IO_BAD1);
144 msg_pdbg("%s():%d shm_io_base=0x%04x\n", __func__, __LINE__,
145 shm_io_base);
146
147 /* These pointers are not used directly. They will be send to EC's
148 * register for indirect access. */
149 base = 0xFFFFF000;
150 ce_high = ((unsigned char*)base) + 0xE00; /* 0xFFFFFE00 */
151 ce_low = ((unsigned char*)base) + 0xD00; /* 0xFFFFFD00 */
152
153 /* pre-set indirect-access registers since in most of cases they are
154 * 0xFFFFxx00. */
155 INDIRECT_A0(shm_io_base, base & 0xFF);
156 INDIRECT_A2(shm_io_base, (base >> 16) & 0xFF);
157 INDIRECT_A3(shm_io_base, (base >> 24));
158 #endif
159 #ifdef LPC_MEMORY
160 base = (chipaddr)programmer_map_flash_region("flash base", 0xFFFFF000,
161 0x1000);
162 msg_pdbg("%s():%d base=0x%08x\n", __func__, __LINE__,
163 (unsigned int)base);
164 ce_high = (unsigned char*)(base + 0xE00); /* 0xFFFFFE00 */
165 ce_low = (unsigned char*)(base + 0xD00); /* 0xFFFFFD00 */
166 #endif
167
168 /* Set this as spi controller. */
169 spi_controller = SPI_CONTROLLER_IT85XX;
170
171 return 0;
172 }
173
174 /* Called by programmer_entry .init */
175 int it85xx_spi_init(void)
176 {
177 int ret;
178
179 get_io_perms();
180 /* Probe for the Super I/O chip and fill global struct superio. */
181 probe_superio();
182 ret = it85xx_spi_common_init();
183 if (!ret) {
184 buses_supported = CHIP_BUSTYPE_SPI;
185 } else {
186 buses_supported = CHIP_BUSTYPE_NONE;
187 }
188 return ret;
189 }
190
191 /* Called by internal_init() */
192 int it85xx_probe_spi_flash(const char *name)
193 {
194 int ret;
195
196 if (!(buses_supported & CHIP_BUSTYPE_FWH)) {
197 msg_pdbg("%s():%d buses not support FWH\n", __func__, __LINE__);
198 return 1;
199 }
200 ret = it85xx_spi_common_init();
201 msg_pdbg("FWH: %s():%d ret=%d\n", __func__, __LINE__, ret);
202 if (!ret) {
203 msg_pdbg("%s():%d buses_supported=0x%x\n", __func__, __LINE__,
204 buses_supported);
205 if (buses_supported & CHIP_BUSTYPE_FWH)
206 msg_pdbg("Overriding chipset SPI with IT85 FWH|SPI.\n");
207 buses_supported |= CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI;
208 }
209 return ret;
210 }
211
212 int it85xx_shutdown(void)
213 {
214 msg_pdbg("%s():%d\n", __func__, __LINE__);
215 it85xx_exit_scratch_rom();
216 return 0;
217 }
218
219 /* According to ITE 8502 document, the procedure to follow mode is following:
220 * 1. write 0x00 to LPC/FWH address 0xffff_fexxh (drive CE# high)
221 * 2. write data to LPC/FWH address 0xffff_fdxxh (drive CE# low and MOSI
222 * with data)
223 * 3. read date from LPC/FWH address 0xffff_fdxxh (drive CE# low and get
224 * data from MISO)
225 */
226 int it85xx_spi_send_command(unsigned int writecnt, unsigned int readcnt,
227 const unsigned char *writearr, unsigned char *readarr)
228 {
229 int i;
230
231 it85xx_enter_scratch_rom();
232 /* exit scratch rom ONLY when programmer shuts down. Otherwise, the
233 * temporary flash state may halt EC. */
234
235 #ifdef LPC_IO
236 INDIRECT_A1(shm_io_base, (((unsigned long int)ce_high) >> 8) & 0xff);
237 INDIRECT_WRITE(shm_io_base, 0xFF); /* Write anything to this address.*/
238 INDIRECT_A1(shm_io_base, (((unsigned long int)ce_low) >> 8) & 0xff);
239 #endif
240 #ifdef LPC_MEMORY
241 *ce_high = 0;
242 #endif
243 for (i = 0; i < writecnt; ++i) {
244 #ifdef LPC_IO
245 INDIRECT_WRITE(shm_io_base, writearr[i]);
246 #endif
247 #ifdef LPC_MEMORY
248 *ce_low = writearr[i];
249 #endif
250 }
251 for (i = 0; i < readcnt; ++i) {
252 #ifdef LPC_IO
253 readarr[i] = INDIRECT_READ(shm_io_base);
254 #endif
255 #ifdef LPC_MEMORY
256 readarr[i] = *ce_low;
257 #endif
258 }
259 return 0;
260 }
261
262 #endif
OLDNEW
« no previous file with comments | « internal.c ('k') | programmer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698