blob: 32bb73c87b3bc8b4ec9ec6de9a23100976e49415 [file] [log] [blame]
Sean Nelson14ba6682010-02-26 05:48:29 +00001/*
2 * This file is part of the flashrom project.
3 *
Carl-Daniel Hailfinger5824fbf2010-05-21 23:09:42 +00004 * Copyright (C) 2007, 2008, 2009, 2010 Carl-Daniel Hailfinger
Sean Nelson14ba6682010-02-26 05:48:29 +00005 * Copyright (C) 2008 coresystems GmbH
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
22 * Contains the common SPI chip driver functions
23 */
24
25#include <string.h>
26#include "flash.h"
27#include "flashchips.h"
28#include "chipdrivers.h"
29#include "spi.h"
30
31void spi_prettyprint_status_register(struct flashchip *flash);
32
33static int spi_rdid(unsigned char *readarr, int bytes)
34{
35 const unsigned char cmd[JEDEC_RDID_OUTSIZE] = { JEDEC_RDID };
36 int ret;
37 int i;
38
39 ret = spi_send_command(sizeof(cmd), bytes, cmd, readarr);
40 if (ret)
41 return ret;
Sean Nelsoned479d22010-03-24 23:14:32 +000042 msg_cspew("RDID returned");
Sean Nelson14ba6682010-02-26 05:48:29 +000043 for (i = 0; i < bytes; i++)
Sean Nelsoned479d22010-03-24 23:14:32 +000044 msg_cspew(" 0x%02x", readarr[i]);
45 msg_cspew(". ");
Sean Nelson14ba6682010-02-26 05:48:29 +000046 return 0;
47}
48
49static int spi_rems(unsigned char *readarr)
50{
51 unsigned char cmd[JEDEC_REMS_OUTSIZE] = { JEDEC_REMS, 0, 0, 0 };
52 uint32_t readaddr;
53 int ret;
54
55 ret = spi_send_command(sizeof(cmd), JEDEC_REMS_INSIZE, cmd, readarr);
56 if (ret == SPI_INVALID_ADDRESS) {
57 /* Find the lowest even address allowed for reads. */
58 readaddr = (spi_get_valid_read_addr() + 1) & ~1;
59 cmd[1] = (readaddr >> 16) & 0xff,
60 cmd[2] = (readaddr >> 8) & 0xff,
61 cmd[3] = (readaddr >> 0) & 0xff,
62 ret = spi_send_command(sizeof(cmd), JEDEC_REMS_INSIZE, cmd, readarr);
63 }
64 if (ret)
65 return ret;
Sean Nelsoned479d22010-03-24 23:14:32 +000066 msg_cspew("REMS returned %02x %02x. ", readarr[0], readarr[1]);
Sean Nelson14ba6682010-02-26 05:48:29 +000067 return 0;
68}
69
Carl-Daniel Hailfingerdc1cda12010-05-28 17:07:57 +000070static int spi_res(unsigned char *readarr, int bytes)
Sean Nelson14ba6682010-02-26 05:48:29 +000071{
72 unsigned char cmd[JEDEC_RES_OUTSIZE] = { JEDEC_RES, 0, 0, 0 };
73 uint32_t readaddr;
74 int ret;
Carl-Daniel Hailfinger8ae500e2010-06-20 10:39:33 +000075 int i;
Sean Nelson14ba6682010-02-26 05:48:29 +000076
Carl-Daniel Hailfingerdc1cda12010-05-28 17:07:57 +000077 ret = spi_send_command(sizeof(cmd), bytes, cmd, readarr);
Sean Nelson14ba6682010-02-26 05:48:29 +000078 if (ret == SPI_INVALID_ADDRESS) {
79 /* Find the lowest even address allowed for reads. */
80 readaddr = (spi_get_valid_read_addr() + 1) & ~1;
81 cmd[1] = (readaddr >> 16) & 0xff,
82 cmd[2] = (readaddr >> 8) & 0xff,
83 cmd[3] = (readaddr >> 0) & 0xff,
Carl-Daniel Hailfingerdc1cda12010-05-28 17:07:57 +000084 ret = spi_send_command(sizeof(cmd), bytes, cmd, readarr);
Sean Nelson14ba6682010-02-26 05:48:29 +000085 }
86 if (ret)
87 return ret;
Carl-Daniel Hailfinger8ae500e2010-06-20 10:39:33 +000088 msg_cspew("RES returned");
89 for (i = 0; i < bytes; i++)
90 msg_cspew(" 0x%02x", readarr[i]);
91 msg_cspew(". ");
Sean Nelson14ba6682010-02-26 05:48:29 +000092 return 0;
93}
94
95int spi_write_enable(void)
96{
97 const unsigned char cmd[JEDEC_WREN_OUTSIZE] = { JEDEC_WREN };
98 int result;
99
100 /* Send WREN (Write Enable) */
101 result = spi_send_command(sizeof(cmd), 0, cmd, NULL);
102
103 if (result)
Sean Nelsoned479d22010-03-24 23:14:32 +0000104 msg_cerr("%s failed\n", __func__);
Sean Nelson14ba6682010-02-26 05:48:29 +0000105
106 return result;
107}
108
109int spi_write_disable(void)
110{
111 const unsigned char cmd[JEDEC_WRDI_OUTSIZE] = { JEDEC_WRDI };
112
113 /* Send WRDI (Write Disable) */
114 return spi_send_command(sizeof(cmd), 0, cmd, NULL);
115}
116
117static int probe_spi_rdid_generic(struct flashchip *flash, int bytes)
118{
119 unsigned char readarr[4];
120 uint32_t id1;
121 uint32_t id2;
122
123 if (spi_rdid(readarr, bytes))
124 return 0;
125
126 if (!oddparity(readarr[0]))
Sean Nelsoned479d22010-03-24 23:14:32 +0000127 msg_cdbg("RDID byte 0 parity violation. ");
Sean Nelson14ba6682010-02-26 05:48:29 +0000128
Carl-Daniel Hailfinger8ae500e2010-06-20 10:39:33 +0000129 /* Check if this is a continuation vendor ID.
130 * FIXME: Handle continuation device IDs.
131 */
Sean Nelson14ba6682010-02-26 05:48:29 +0000132 if (readarr[0] == 0x7f) {
133 if (!oddparity(readarr[1]))
Sean Nelsoned479d22010-03-24 23:14:32 +0000134 msg_cdbg("RDID byte 1 parity violation. ");
Sean Nelson14ba6682010-02-26 05:48:29 +0000135 id1 = (readarr[0] << 8) | readarr[1];
136 id2 = readarr[2];
137 if (bytes > 3) {
138 id2 <<= 8;
139 id2 |= readarr[3];
140 }
141 } else {
142 id1 = readarr[0];
143 id2 = (readarr[1] << 8) | readarr[2];
144 }
145
Sean Nelsoned479d22010-03-24 23:14:32 +0000146 msg_cdbg("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2);
Sean Nelson14ba6682010-02-26 05:48:29 +0000147
148 if (id1 == flash->manufacture_id && id2 == flash->model_id) {
149 /* Print the status register to tell the
150 * user about possible write protection.
151 */
152 spi_prettyprint_status_register(flash);
153
154 return 1;
155 }
156
157 /* Test if this is a pure vendor match. */
158 if (id1 == flash->manufacture_id &&
159 GENERIC_DEVICE_ID == flash->model_id)
160 return 1;
161
162 /* Test if there is any vendor ID. */
163 if (GENERIC_MANUF_ID == flash->manufacture_id &&
164 id1 != 0xff)
165 return 1;
166
167 return 0;
168}
169
170int probe_spi_rdid(struct flashchip *flash)
171{
172 return probe_spi_rdid_generic(flash, 3);
173}
174
Sean Nelson14ba6682010-02-26 05:48:29 +0000175int probe_spi_rdid4(struct flashchip *flash)
176{
Carl-Daniel Hailfinger8ae500e2010-06-20 10:39:33 +0000177 /* Some SPI controllers do not support commands with writecnt=1 and
178 * readcnt=4.
179 */
Sean Nelson14ba6682010-02-26 05:48:29 +0000180 switch (spi_controller) {
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000181#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +0000182#if defined(__i386__) || defined(__x86_64__)
Carl-Daniel Hailfinger8ae500e2010-06-20 10:39:33 +0000183 case SPI_CONTROLLER_IT87XX:
Sean Nelson14ba6682010-02-26 05:48:29 +0000184 case SPI_CONTROLLER_WBSIO:
Carl-Daniel Hailfinger8ae500e2010-06-20 10:39:33 +0000185 msg_cinfo("4 byte RDID not supported on this SPI controller\n");
186 return 0;
187 break;
Sean Nelson14ba6682010-02-26 05:48:29 +0000188#endif
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +0000189#endif
Sean Nelson14ba6682010-02-26 05:48:29 +0000190 default:
Carl-Daniel Hailfinger8ae500e2010-06-20 10:39:33 +0000191 return probe_spi_rdid_generic(flash, 4);
Sean Nelson14ba6682010-02-26 05:48:29 +0000192 }
193
194 return 0;
195}
196
197int probe_spi_rems(struct flashchip *flash)
198{
199 unsigned char readarr[JEDEC_REMS_INSIZE];
200 uint32_t id1, id2;
201
202 if (spi_rems(readarr))
203 return 0;
204
205 id1 = readarr[0];
206 id2 = readarr[1];
207
Sean Nelsoned479d22010-03-24 23:14:32 +0000208 msg_cdbg("%s: id1 0x%x, id2 0x%x\n", __func__, id1, id2);
Sean Nelson14ba6682010-02-26 05:48:29 +0000209
210 if (id1 == flash->manufacture_id && id2 == flash->model_id) {
211 /* Print the status register to tell the
212 * user about possible write protection.
213 */
214 spi_prettyprint_status_register(flash);
215
216 return 1;
217 }
218
219 /* Test if this is a pure vendor match. */
220 if (id1 == flash->manufacture_id &&
221 GENERIC_DEVICE_ID == flash->model_id)
222 return 1;
223
224 /* Test if there is any vendor ID. */
225 if (GENERIC_MANUF_ID == flash->manufacture_id &&
226 id1 != 0xff)
227 return 1;
228
229 return 0;
230}
231
Carl-Daniel Hailfingerdc1cda12010-05-28 17:07:57 +0000232int probe_spi_res1(struct flashchip *flash)
Sean Nelson14ba6682010-02-26 05:48:29 +0000233{
234 unsigned char readarr[3];
235 uint32_t id2;
236 const unsigned char allff[] = {0xff, 0xff, 0xff};
237 const unsigned char all00[] = {0x00, 0x00, 0x00};
238
Carl-Daniel Hailfingerdc1cda12010-05-28 17:07:57 +0000239 /* We only want one-byte RES if RDID and REMS are unusable. */
240
Sean Nelson14ba6682010-02-26 05:48:29 +0000241 /* Check if RDID is usable and does not return 0xff 0xff 0xff or
242 * 0x00 0x00 0x00. In that case, RES is pointless.
243 */
244 if (!spi_rdid(readarr, 3) && memcmp(readarr, allff, 3) &&
245 memcmp(readarr, all00, 3)) {
246 msg_cdbg("Ignoring RES in favour of RDID.\n");
247 return 0;
248 }
249 /* Check if REMS is usable and does not return 0xff 0xff or
250 * 0x00 0x00. In that case, RES is pointless.
251 */
252 if (!spi_rems(readarr) && memcmp(readarr, allff, JEDEC_REMS_INSIZE) &&
253 memcmp(readarr, all00, JEDEC_REMS_INSIZE)) {
254 msg_cdbg("Ignoring RES in favour of REMS.\n");
255 return 0;
256 }
257
Carl-Daniel Hailfingerdc1cda12010-05-28 17:07:57 +0000258 if (spi_res(readarr, 1))
Sean Nelson14ba6682010-02-26 05:48:29 +0000259 return 0;
260
Sean Nelson14ba6682010-02-26 05:48:29 +0000261 id2 = readarr[0];
Carl-Daniel Hailfingerdc1cda12010-05-28 17:07:57 +0000262
Sean Nelsoned479d22010-03-24 23:14:32 +0000263 msg_cdbg("%s: id 0x%x\n", __func__, id2);
Carl-Daniel Hailfingerdc1cda12010-05-28 17:07:57 +0000264
Sean Nelson14ba6682010-02-26 05:48:29 +0000265 if (id2 != flash->model_id)
266 return 0;
267
268 /* Print the status register to tell the
269 * user about possible write protection.
270 */
271 spi_prettyprint_status_register(flash);
272 return 1;
273}
274
Carl-Daniel Hailfingerdc1cda12010-05-28 17:07:57 +0000275int probe_spi_res2(struct flashchip *flash)
276{
277 unsigned char readarr[2];
278 uint32_t id1, id2;
279
280 if (spi_res(readarr, 2))
281 return 0;
282
283 id1 = readarr[0];
284 id2 = readarr[1];
285
286 msg_cdbg("%s: id1 0x%x, id2 0x%x\n", __func__, id1, id2);
287
288 if (id1 != flash->manufacture_id || id2 != flash->model_id)
289 return 0;
290
291 /* Print the status register to tell the
292 * user about possible write protection.
293 */
294 spi_prettyprint_status_register(flash);
295 return 1;
296}
297
Sean Nelson14ba6682010-02-26 05:48:29 +0000298uint8_t spi_read_status_register(void)
299{
300 const unsigned char cmd[JEDEC_RDSR_OUTSIZE] = { JEDEC_RDSR };
301 /* FIXME: No workarounds for driver/hardware bugs in generic code. */
302 unsigned char readarr[2]; /* JEDEC_RDSR_INSIZE=1 but wbsio needs 2 */
303 int ret;
304
305 /* Read Status Register */
306 ret = spi_send_command(sizeof(cmd), sizeof(readarr), cmd, readarr);
307 if (ret)
Sean Nelsoned479d22010-03-24 23:14:32 +0000308 msg_cerr("RDSR failed!\n");
Sean Nelson14ba6682010-02-26 05:48:29 +0000309
310 return readarr[0];
311}
312
313/* Prettyprint the status register. Common definitions. */
314void spi_prettyprint_status_register_common(uint8_t status)
315{
Sean Nelsoned479d22010-03-24 23:14:32 +0000316 msg_cdbg("Chip status register: Bit 5 / Block Protect 3 (BP3) is "
Sean Nelson14ba6682010-02-26 05:48:29 +0000317 "%sset\n", (status & (1 << 5)) ? "" : "not ");
Sean Nelsoned479d22010-03-24 23:14:32 +0000318 msg_cdbg("Chip status register: Bit 4 / Block Protect 2 (BP2) is "
Sean Nelson14ba6682010-02-26 05:48:29 +0000319 "%sset\n", (status & (1 << 4)) ? "" : "not ");
Sean Nelsoned479d22010-03-24 23:14:32 +0000320 msg_cdbg("Chip status register: Bit 3 / Block Protect 1 (BP1) is "
Sean Nelson14ba6682010-02-26 05:48:29 +0000321 "%sset\n", (status & (1 << 3)) ? "" : "not ");
Sean Nelsoned479d22010-03-24 23:14:32 +0000322 msg_cdbg("Chip status register: Bit 2 / Block Protect 0 (BP0) is "
Sean Nelson14ba6682010-02-26 05:48:29 +0000323 "%sset\n", (status & (1 << 2)) ? "" : "not ");
Sean Nelsoned479d22010-03-24 23:14:32 +0000324 msg_cdbg("Chip status register: Write Enable Latch (WEL) is "
Sean Nelson14ba6682010-02-26 05:48:29 +0000325 "%sset\n", (status & (1 << 1)) ? "" : "not ");
Sean Nelsoned479d22010-03-24 23:14:32 +0000326 msg_cdbg("Chip status register: Write In Progress (WIP/BUSY) is "
Sean Nelson14ba6682010-02-26 05:48:29 +0000327 "%sset\n", (status & (1 << 0)) ? "" : "not ");
328}
329
330/* Prettyprint the status register. Works for
331 * ST M25P series
332 * MX MX25L series
333 */
334void spi_prettyprint_status_register_st_m25p(uint8_t status)
335{
Sean Nelsoned479d22010-03-24 23:14:32 +0000336 msg_cdbg("Chip status register: Status Register Write Disable "
Sean Nelson14ba6682010-02-26 05:48:29 +0000337 "(SRWD) is %sset\n", (status & (1 << 7)) ? "" : "not ");
Sean Nelsoned479d22010-03-24 23:14:32 +0000338 msg_cdbg("Chip status register: Bit 6 is "
Sean Nelson14ba6682010-02-26 05:48:29 +0000339 "%sset\n", (status & (1 << 6)) ? "" : "not ");
340 spi_prettyprint_status_register_common(status);
341}
342
343void spi_prettyprint_status_register_sst25(uint8_t status)
344{
Sean Nelsoned479d22010-03-24 23:14:32 +0000345 msg_cdbg("Chip status register: Block Protect Write Disable "
Sean Nelson14ba6682010-02-26 05:48:29 +0000346 "(BPL) is %sset\n", (status & (1 << 7)) ? "" : "not ");
Sean Nelsoned479d22010-03-24 23:14:32 +0000347 msg_cdbg("Chip status register: Auto Address Increment Programming "
Sean Nelson14ba6682010-02-26 05:48:29 +0000348 "(AAI) is %sset\n", (status & (1 << 6)) ? "" : "not ");
349 spi_prettyprint_status_register_common(status);
350}
351
352/* Prettyprint the status register. Works for
353 * SST 25VF016
354 */
355void spi_prettyprint_status_register_sst25vf016(uint8_t status)
356{
357 const char *bpt[] = {
358 "none",
359 "1F0000H-1FFFFFH",
360 "1E0000H-1FFFFFH",
361 "1C0000H-1FFFFFH",
362 "180000H-1FFFFFH",
363 "100000H-1FFFFFH",
364 "all", "all"
365 };
366 spi_prettyprint_status_register_sst25(status);
Sean Nelsoned479d22010-03-24 23:14:32 +0000367 msg_cdbg("Resulting block protection : %s\n",
Sean Nelson14ba6682010-02-26 05:48:29 +0000368 bpt[(status & 0x1c) >> 2]);
369}
370
371void spi_prettyprint_status_register_sst25vf040b(uint8_t status)
372{
373 const char *bpt[] = {
374 "none",
375 "0x70000-0x7ffff",
376 "0x60000-0x7ffff",
377 "0x40000-0x7ffff",
378 "all blocks", "all blocks", "all blocks", "all blocks"
379 };
380 spi_prettyprint_status_register_sst25(status);
Sean Nelsoned479d22010-03-24 23:14:32 +0000381 msg_cdbg("Resulting block protection : %s\n",
Sean Nelson14ba6682010-02-26 05:48:29 +0000382 bpt[(status & 0x1c) >> 2]);
383}
384
385void spi_prettyprint_status_register(struct flashchip *flash)
386{
387 uint8_t status;
388
389 status = spi_read_status_register();
Sean Nelsoned479d22010-03-24 23:14:32 +0000390 msg_cdbg("Chip status register is %02x\n", status);
Sean Nelson14ba6682010-02-26 05:48:29 +0000391 switch (flash->manufacture_id) {
392 case ST_ID:
393 if (((flash->model_id & 0xff00) == 0x2000) ||
394 ((flash->model_id & 0xff00) == 0x2500))
395 spi_prettyprint_status_register_st_m25p(status);
396 break;
397 case MX_ID:
398 if ((flash->model_id & 0xff00) == 0x2000)
399 spi_prettyprint_status_register_st_m25p(status);
400 break;
401 case SST_ID:
402 switch (flash->model_id) {
403 case 0x2541:
404 spi_prettyprint_status_register_sst25vf016(status);
405 break;
406 case 0x8d:
407 case 0x258d:
408 spi_prettyprint_status_register_sst25vf040b(status);
409 break;
410 default:
411 spi_prettyprint_status_register_sst25(status);
412 break;
413 }
414 break;
415 }
416}
417
418int spi_chip_erase_60(struct flashchip *flash)
419{
420 int result;
421 struct spi_command cmds[] = {
422 {
423 .writecnt = JEDEC_WREN_OUTSIZE,
424 .writearr = (const unsigned char[]){ JEDEC_WREN },
425 .readcnt = 0,
426 .readarr = NULL,
427 }, {
428 .writecnt = JEDEC_CE_60_OUTSIZE,
429 .writearr = (const unsigned char[]){ JEDEC_CE_60 },
430 .readcnt = 0,
431 .readarr = NULL,
432 }, {
433 .writecnt = 0,
434 .writearr = NULL,
435 .readcnt = 0,
436 .readarr = NULL,
437 }};
438
Sean Nelson14ba6682010-02-26 05:48:29 +0000439 result = spi_send_multicommand(cmds);
440 if (result) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000441 msg_cerr("%s failed during command execution\n",
Sean Nelson14ba6682010-02-26 05:48:29 +0000442 __func__);
443 return result;
444 }
445 /* Wait until the Write-In-Progress bit is cleared.
446 * This usually takes 1-85 s, so wait in 1 s steps.
447 */
448 /* FIXME: We assume spi_read_status_register will never fail. */
449 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP)
450 programmer_delay(1000 * 1000);
451 if (check_erased_range(flash, 0, flash->total_size * 1024)) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000452 msg_cerr("ERASE FAILED!\n");
Sean Nelson14ba6682010-02-26 05:48:29 +0000453 return -1;
454 }
455 return 0;
456}
457
458int spi_chip_erase_c7(struct flashchip *flash)
459{
460 int result;
461 struct spi_command cmds[] = {
462 {
463 .writecnt = JEDEC_WREN_OUTSIZE,
464 .writearr = (const unsigned char[]){ JEDEC_WREN },
465 .readcnt = 0,
466 .readarr = NULL,
467 }, {
468 .writecnt = JEDEC_CE_C7_OUTSIZE,
469 .writearr = (const unsigned char[]){ JEDEC_CE_C7 },
470 .readcnt = 0,
471 .readarr = NULL,
472 }, {
473 .writecnt = 0,
474 .writearr = NULL,
475 .readcnt = 0,
476 .readarr = NULL,
477 }};
478
Sean Nelson14ba6682010-02-26 05:48:29 +0000479 result = spi_send_multicommand(cmds);
480 if (result) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000481 msg_cerr("%s failed during command execution\n", __func__);
Sean Nelson14ba6682010-02-26 05:48:29 +0000482 return result;
483 }
484 /* Wait until the Write-In-Progress bit is cleared.
485 * This usually takes 1-85 s, so wait in 1 s steps.
486 */
487 /* FIXME: We assume spi_read_status_register will never fail. */
488 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP)
489 programmer_delay(1000 * 1000);
490 if (check_erased_range(flash, 0, flash->total_size * 1024)) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000491 msg_cerr("ERASE FAILED!\n");
Sean Nelson14ba6682010-02-26 05:48:29 +0000492 return -1;
493 }
494 return 0;
495}
496
Sean Nelson14ba6682010-02-26 05:48:29 +0000497int spi_block_erase_52(struct flashchip *flash, unsigned int addr, unsigned int blocklen)
498{
499 int result;
500 struct spi_command cmds[] = {
501 {
502 .writecnt = JEDEC_WREN_OUTSIZE,
503 .writearr = (const unsigned char[]){ JEDEC_WREN },
504 .readcnt = 0,
505 .readarr = NULL,
506 }, {
507 .writecnt = JEDEC_BE_52_OUTSIZE,
508 .writearr = (const unsigned char[]){
509 JEDEC_BE_52,
510 (addr >> 16) & 0xff,
511 (addr >> 8) & 0xff,
512 (addr & 0xff)
513 },
514 .readcnt = 0,
515 .readarr = NULL,
516 }, {
517 .writecnt = 0,
518 .writearr = NULL,
519 .readcnt = 0,
520 .readarr = NULL,
521 }};
522
523 result = spi_send_multicommand(cmds);
524 if (result) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000525 msg_cerr("%s failed during command execution at address 0x%x\n",
Sean Nelson14ba6682010-02-26 05:48:29 +0000526 __func__, addr);
527 return result;
528 }
529 /* Wait until the Write-In-Progress bit is cleared.
530 * This usually takes 100-4000 ms, so wait in 100 ms steps.
531 */
532 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP)
533 programmer_delay(100 * 1000);
534 if (check_erased_range(flash, addr, blocklen)) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000535 msg_cerr("ERASE FAILED!\n");
Sean Nelson14ba6682010-02-26 05:48:29 +0000536 return -1;
537 }
538 return 0;
539}
540
541/* Block size is usually
542 * 64k for Macronix
543 * 32k for SST
544 * 4-32k non-uniform for EON
545 */
546int spi_block_erase_d8(struct flashchip *flash, unsigned int addr, unsigned int blocklen)
547{
548 int result;
549 struct spi_command cmds[] = {
550 {
551 .writecnt = JEDEC_WREN_OUTSIZE,
552 .writearr = (const unsigned char[]){ JEDEC_WREN },
553 .readcnt = 0,
554 .readarr = NULL,
555 }, {
556 .writecnt = JEDEC_BE_D8_OUTSIZE,
557 .writearr = (const unsigned char[]){
558 JEDEC_BE_D8,
559 (addr >> 16) & 0xff,
560 (addr >> 8) & 0xff,
561 (addr & 0xff)
562 },
563 .readcnt = 0,
564 .readarr = NULL,
565 }, {
566 .writecnt = 0,
567 .writearr = NULL,
568 .readcnt = 0,
569 .readarr = NULL,
570 }};
571
572 result = spi_send_multicommand(cmds);
573 if (result) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000574 msg_cerr("%s failed during command execution at address 0x%x\n",
Sean Nelson14ba6682010-02-26 05:48:29 +0000575 __func__, addr);
576 return result;
577 }
578 /* Wait until the Write-In-Progress bit is cleared.
579 * This usually takes 100-4000 ms, so wait in 100 ms steps.
580 */
581 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP)
582 programmer_delay(100 * 1000);
583 if (check_erased_range(flash, addr, blocklen)) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000584 msg_cerr("ERASE FAILED!\n");
Sean Nelson14ba6682010-02-26 05:48:29 +0000585 return -1;
586 }
587 return 0;
588}
589
590/* Block size is usually
591 * 4k for PMC
592 */
593int spi_block_erase_d7(struct flashchip *flash, unsigned int addr, unsigned int blocklen)
594{
595 int result;
596 struct spi_command cmds[] = {
597 {
598 .writecnt = JEDEC_WREN_OUTSIZE,
599 .writearr = (const unsigned char[]){ JEDEC_WREN },
600 .readcnt = 0,
601 .readarr = NULL,
602 }, {
603 .writecnt = JEDEC_BE_D7_OUTSIZE,
604 .writearr = (const unsigned char[]){
605 JEDEC_BE_D7,
606 (addr >> 16) & 0xff,
607 (addr >> 8) & 0xff,
608 (addr & 0xff)
609 },
610 .readcnt = 0,
611 .readarr = NULL,
612 }, {
613 .writecnt = 0,
614 .writearr = NULL,
615 .readcnt = 0,
616 .readarr = NULL,
617 }};
618
619 result = spi_send_multicommand(cmds);
620 if (result) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000621 msg_cerr("%s failed during command execution at address 0x%x\n",
Sean Nelson14ba6682010-02-26 05:48:29 +0000622 __func__, addr);
623 return result;
624 }
625 /* Wait until the Write-In-Progress bit is cleared.
626 * This usually takes 100-4000 ms, so wait in 100 ms steps.
627 */
628 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP)
629 programmer_delay(100 * 1000);
630 if (check_erased_range(flash, addr, blocklen)) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000631 msg_cerr("ERASE FAILED!\n");
Sean Nelson14ba6682010-02-26 05:48:29 +0000632 return -1;
633 }
634 return 0;
635}
636
Sean Nelson14ba6682010-02-26 05:48:29 +0000637/* Sector size is usually 4k, though Macronix eliteflash has 64k */
638int spi_block_erase_20(struct flashchip *flash, unsigned int addr, unsigned int blocklen)
639{
640 int result;
641 struct spi_command cmds[] = {
642 {
643 .writecnt = JEDEC_WREN_OUTSIZE,
644 .writearr = (const unsigned char[]){ JEDEC_WREN },
645 .readcnt = 0,
646 .readarr = NULL,
647 }, {
648 .writecnt = JEDEC_SE_OUTSIZE,
649 .writearr = (const unsigned char[]){
650 JEDEC_SE,
651 (addr >> 16) & 0xff,
652 (addr >> 8) & 0xff,
653 (addr & 0xff)
654 },
655 .readcnt = 0,
656 .readarr = NULL,
657 }, {
658 .writecnt = 0,
659 .writearr = NULL,
660 .readcnt = 0,
661 .readarr = NULL,
662 }};
663
664 result = spi_send_multicommand(cmds);
665 if (result) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000666 msg_cerr("%s failed during command execution at address 0x%x\n",
Sean Nelson14ba6682010-02-26 05:48:29 +0000667 __func__, addr);
668 return result;
669 }
670 /* Wait until the Write-In-Progress bit is cleared.
671 * This usually takes 15-800 ms, so wait in 10 ms steps.
672 */
673 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP)
674 programmer_delay(10 * 1000);
675 if (check_erased_range(flash, addr, blocklen)) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000676 msg_cerr("ERASE FAILED!\n");
Sean Nelson14ba6682010-02-26 05:48:29 +0000677 return -1;
678 }
679 return 0;
680}
681
682int spi_block_erase_60(struct flashchip *flash, unsigned int addr, unsigned int blocklen)
683{
684 if ((addr != 0) || (blocklen != flash->total_size * 1024)) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000685 msg_cerr("%s called with incorrect arguments\n",
Sean Nelson14ba6682010-02-26 05:48:29 +0000686 __func__);
687 return -1;
688 }
689 return spi_chip_erase_60(flash);
690}
691
692int spi_block_erase_c7(struct flashchip *flash, unsigned int addr, unsigned int blocklen)
693{
694 if ((addr != 0) || (blocklen != flash->total_size * 1024)) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000695 msg_cerr("%s called with incorrect arguments\n",
Sean Nelson14ba6682010-02-26 05:48:29 +0000696 __func__);
697 return -1;
698 }
699 return spi_chip_erase_c7(flash);
700}
701
702int spi_write_status_enable(void)
703{
704 const unsigned char cmd[JEDEC_EWSR_OUTSIZE] = { JEDEC_EWSR };
705 int result;
706
707 /* Send EWSR (Enable Write Status Register). */
708 result = spi_send_command(sizeof(cmd), JEDEC_EWSR_INSIZE, cmd, NULL);
709
710 if (result)
Sean Nelsoned479d22010-03-24 23:14:32 +0000711 msg_cerr("%s failed\n", __func__);
Sean Nelson14ba6682010-02-26 05:48:29 +0000712
713 return result;
714}
715
716/*
717 * This is according the SST25VF016 datasheet, who knows it is more
718 * generic that this...
719 */
720int spi_write_status_register(int status)
721{
722 int result;
723 struct spi_command cmds[] = {
724 {
725 /* FIXME: WRSR requires either EWSR or WREN depending on chip type. */
726 .writecnt = JEDEC_EWSR_OUTSIZE,
727 .writearr = (const unsigned char[]){ JEDEC_EWSR },
728 .readcnt = 0,
729 .readarr = NULL,
730 }, {
731 .writecnt = JEDEC_WRSR_OUTSIZE,
732 .writearr = (const unsigned char[]){ JEDEC_WRSR, (unsigned char) status },
733 .readcnt = 0,
734 .readarr = NULL,
735 }, {
736 .writecnt = 0,
737 .writearr = NULL,
738 .readcnt = 0,
739 .readarr = NULL,
740 }};
741
742 result = spi_send_multicommand(cmds);
743 if (result) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000744 msg_cerr("%s failed during command execution\n",
Sean Nelson14ba6682010-02-26 05:48:29 +0000745 __func__);
746 }
747 return result;
748}
749
750int spi_byte_program(int addr, uint8_t databyte)
751{
752 int result;
753 struct spi_command cmds[] = {
754 {
755 .writecnt = JEDEC_WREN_OUTSIZE,
756 .writearr = (const unsigned char[]){ JEDEC_WREN },
757 .readcnt = 0,
758 .readarr = NULL,
759 }, {
760 .writecnt = JEDEC_BYTE_PROGRAM_OUTSIZE,
761 .writearr = (const unsigned char[]){
762 JEDEC_BYTE_PROGRAM,
763 (addr >> 16) & 0xff,
764 (addr >> 8) & 0xff,
765 (addr & 0xff),
766 databyte
767 },
768 .readcnt = 0,
769 .readarr = NULL,
770 }, {
771 .writecnt = 0,
772 .writearr = NULL,
773 .readcnt = 0,
774 .readarr = NULL,
775 }};
776
777 result = spi_send_multicommand(cmds);
778 if (result) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000779 msg_cerr("%s failed during command execution at address 0x%x\n",
Sean Nelson14ba6682010-02-26 05:48:29 +0000780 __func__, addr);
781 }
782 return result;
783}
784
785int spi_nbyte_program(int addr, uint8_t *bytes, int len)
786{
787 int result;
788 /* FIXME: Switch to malloc based on len unless that kills speed. */
789 unsigned char cmd[JEDEC_BYTE_PROGRAM_OUTSIZE - 1 + 256] = {
790 JEDEC_BYTE_PROGRAM,
791 (addr >> 16) & 0xff,
792 (addr >> 8) & 0xff,
793 (addr >> 0) & 0xff,
794 };
795 struct spi_command cmds[] = {
796 {
797 .writecnt = JEDEC_WREN_OUTSIZE,
798 .writearr = (const unsigned char[]){ JEDEC_WREN },
799 .readcnt = 0,
800 .readarr = NULL,
801 }, {
802 .writecnt = JEDEC_BYTE_PROGRAM_OUTSIZE - 1 + len,
803 .writearr = cmd,
804 .readcnt = 0,
805 .readarr = NULL,
806 }, {
807 .writecnt = 0,
808 .writearr = NULL,
809 .readcnt = 0,
810 .readarr = NULL,
811 }};
812
813 if (!len) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000814 msg_cerr("%s called for zero-length write\n", __func__);
Sean Nelson14ba6682010-02-26 05:48:29 +0000815 return 1;
816 }
817 if (len > 256) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000818 msg_cerr("%s called for too long a write\n", __func__);
Sean Nelson14ba6682010-02-26 05:48:29 +0000819 return 1;
820 }
821
822 memcpy(&cmd[4], bytes, len);
823
824 result = spi_send_multicommand(cmds);
825 if (result) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000826 msg_cerr("%s failed during command execution at address 0x%x\n",
Sean Nelson14ba6682010-02-26 05:48:29 +0000827 __func__, addr);
828 }
829 return result;
830}
831
Carl-Daniel Hailfinger29a1c662010-07-14 20:21:22 +0000832int spi_disable_blockprotect(struct flashchip *flash)
Sean Nelson14ba6682010-02-26 05:48:29 +0000833{
834 uint8_t status;
835 int result;
836
837 status = spi_read_status_register();
838 /* If there is block protection in effect, unprotect it first. */
839 if ((status & 0x3c) != 0) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000840 msg_cdbg("Some block protection in effect, disabling\n");
Sean Nelson14ba6682010-02-26 05:48:29 +0000841 result = spi_write_status_register(status & ~0x3c);
842 if (result) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000843 msg_cerr("spi_write_status_register failed\n");
Sean Nelson14ba6682010-02-26 05:48:29 +0000844 return result;
845 }
Carl-Daniel Hailfinger29a1c662010-07-14 20:21:22 +0000846 status = spi_read_status_register();
847 if ((status & 0x3c) != 0) {
848 msg_cerr("Block protection could not be disabled!\n");
849 return 1;
850 }
Sean Nelson14ba6682010-02-26 05:48:29 +0000851 }
852 return 0;
853}
854
855int spi_nbyte_read(int address, uint8_t *bytes, int len)
856{
857 const unsigned char cmd[JEDEC_READ_OUTSIZE] = {
858 JEDEC_READ,
859 (address >> 16) & 0xff,
860 (address >> 8) & 0xff,
861 (address >> 0) & 0xff,
862 };
863
864 /* Send Read */
865 return spi_send_command(sizeof(cmd), len, cmd, bytes);
866}
867
868/*
Carl-Daniel Hailfinger5824fbf2010-05-21 23:09:42 +0000869 * Read a part of the flash chip.
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +0000870 * FIXME: Use the chunk code from Michael Karcher instead.
Sean Nelson14ba6682010-02-26 05:48:29 +0000871 * Each page is read separately in chunks with a maximum size of chunksize.
872 */
873int spi_read_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize)
874{
875 int rc = 0;
876 int i, j, starthere, lenhere;
877 int page_size = flash->page_size;
878 int toread;
879
880 /* Warning: This loop has a very unusual condition and body.
881 * The loop needs to go through each page with at least one affected
882 * byte. The lowest page number is (start / page_size) since that
883 * division rounds down. The highest page number we want is the page
884 * where the last byte of the range lives. That last byte has the
885 * address (start + len - 1), thus the highest page number is
886 * (start + len - 1) / page_size. Since we want to include that last
887 * page as well, the loop condition uses <=.
888 */
889 for (i = start / page_size; i <= (start + len - 1) / page_size; i++) {
890 /* Byte position of the first byte in the range in this page. */
891 /* starthere is an offset to the base address of the chip. */
892 starthere = max(start, i * page_size);
893 /* Length of bytes in the range in this page. */
894 lenhere = min(start + len, (i + 1) * page_size) - starthere;
895 for (j = 0; j < lenhere; j += chunksize) {
896 toread = min(chunksize, lenhere - j);
897 rc = spi_nbyte_read(starthere + j, buf + starthere - start + j, toread);
898 if (rc)
899 break;
900 }
901 if (rc)
902 break;
903 }
904
905 return rc;
906}
907
908/*
Carl-Daniel Hailfinger5824fbf2010-05-21 23:09:42 +0000909 * Write a part of the flash chip.
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +0000910 * FIXME: Use the chunk code from Michael Karcher instead.
Carl-Daniel Hailfinger5824fbf2010-05-21 23:09:42 +0000911 * Each page is written separately in chunks with a maximum size of chunksize.
912 */
913int spi_write_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize)
914{
915 int rc = 0;
916 int i, j, starthere, lenhere;
917 /* FIXME: page_size is the wrong variable. We need max_writechunk_size
918 * in struct flashchip to do this properly. All chips using
919 * spi_chip_write_256 have page_size set to max_writechunk_size, so
920 * we're OK for now.
921 */
922 int page_size = flash->page_size;
923 int towrite;
924
925 /* Warning: This loop has a very unusual condition and body.
926 * The loop needs to go through each page with at least one affected
927 * byte. The lowest page number is (start / page_size) since that
928 * division rounds down. The highest page number we want is the page
929 * where the last byte of the range lives. That last byte has the
930 * address (start + len - 1), thus the highest page number is
931 * (start + len - 1) / page_size. Since we want to include that last
932 * page as well, the loop condition uses <=.
933 */
934 for (i = start / page_size; i <= (start + len - 1) / page_size; i++) {
935 /* Byte position of the first byte in the range in this page. */
936 /* starthere is an offset to the base address of the chip. */
937 starthere = max(start, i * page_size);
938 /* Length of bytes in the range in this page. */
939 lenhere = min(start + len, (i + 1) * page_size) - starthere;
940 for (j = 0; j < lenhere; j += chunksize) {
941 towrite = min(chunksize, lenhere - j);
942 rc = spi_nbyte_program(starthere + j, buf + starthere - start + j, towrite);
943 if (rc)
944 break;
945 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP)
946 programmer_delay(10);
947 }
948 if (rc)
949 break;
950 }
951
952 return rc;
953}
954
955/*
Sean Nelson14ba6682010-02-26 05:48:29 +0000956 * Program chip using byte programming. (SLOW!)
957 * This is for chips which can only handle one byte writes
958 * and for chips where memory mapped programming is impossible
959 * (e.g. due to size constraints in IT87* for over 512 kB)
960 */
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +0000961/* real chunksize is 1, logical chunksize is 1 */
962int spi_chip_write_1_new(struct flashchip *flash, uint8_t *buf, int start, int len)
Sean Nelson14ba6682010-02-26 05:48:29 +0000963{
Sean Nelson14ba6682010-02-26 05:48:29 +0000964 int i, result = 0;
965
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +0000966 for (i = start; i < start + len; i++) {
Sean Nelson14ba6682010-02-26 05:48:29 +0000967 result = spi_byte_program(i, buf[i]);
968 if (result)
969 return 1;
970 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP)
971 programmer_delay(10);
972 }
973
974 return 0;
975}
976
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +0000977int spi_chip_write_1(struct flashchip *flash, uint8_t *buf)
Sean Nelson14ba6682010-02-26 05:48:29 +0000978{
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +0000979 /* Erase first */
980 msg_cinfo("Erasing flash before programming... ");
981 if (erase_flash(flash)) {
982 msg_cerr("ERASE FAILED!\n");
983 return -1;
984 }
985 msg_cinfo("done.\n");
986
987 return spi_chip_write_1_new(flash, buf, 0, flash->total_size * 1024);
988}
989
990int spi_aai_write(struct flashchip *flash, uint8_t *buf, int start, int len)
991{
992 uint32_t pos = start;
Sean Nelson14ba6682010-02-26 05:48:29 +0000993 int result;
Carl-Daniel Hailfinger9c62d112010-06-20 10:41:35 +0000994 unsigned char cmd[JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE] = {
995 JEDEC_AAI_WORD_PROGRAM,
996 };
997 struct spi_command cmds[] = {
998 {
999 .writecnt = JEDEC_WREN_OUTSIZE,
1000 .writearr = (const unsigned char[]){ JEDEC_WREN },
1001 .readcnt = 0,
1002 .readarr = NULL,
1003 }, {
1004 .writecnt = JEDEC_AAI_WORD_PROGRAM_OUTSIZE,
1005 .writearr = (const unsigned char[]){
1006 JEDEC_AAI_WORD_PROGRAM,
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +00001007 (start >> 16) & 0xff,
1008 (start >> 8) & 0xff,
1009 (start & 0xff),
Carl-Daniel Hailfinger9c62d112010-06-20 10:41:35 +00001010 buf[0],
1011 buf[1]
1012 },
1013 .readcnt = 0,
1014 .readarr = NULL,
1015 }, {
1016 .writecnt = 0,
1017 .writearr = NULL,
1018 .readcnt = 0,
1019 .readarr = NULL,
1020 }};
Sean Nelson14ba6682010-02-26 05:48:29 +00001021
1022 switch (spi_controller) {
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +00001023#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +00001024#if defined(__i386__) || defined(__x86_64__)
Carl-Daniel Hailfinger9c62d112010-06-20 10:41:35 +00001025 case SPI_CONTROLLER_IT87XX:
Sean Nelson14ba6682010-02-26 05:48:29 +00001026 case SPI_CONTROLLER_WBSIO:
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +00001027 msg_perr("%s: impossible with this SPI controller,"
Sean Nelson14ba6682010-02-26 05:48:29 +00001028 " degrading to byte program\n", __func__);
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +00001029 return spi_chip_write_1_new(flash, buf, start, len);
Sean Nelson14ba6682010-02-26 05:48:29 +00001030#endif
Carl-Daniel Hailfingercceafa22010-05-26 01:45:41 +00001031#endif
Sean Nelson14ba6682010-02-26 05:48:29 +00001032 default:
1033 break;
1034 }
Carl-Daniel Hailfinger9c62d112010-06-20 10:41:35 +00001035
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +00001036 /* The even start address and even length requirements can be either
1037 * honored outside this function, or we can call spi_byte_program
1038 * for the first and/or last byte and use AAI for the rest.
1039 */
Carl-Daniel Hailfinger9c62d112010-06-20 10:41:35 +00001040 /* The data sheet requires a start address with the low bit cleared. */
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +00001041 if (start % 2) {
Carl-Daniel Hailfinger9c62d112010-06-20 10:41:35 +00001042 msg_cerr("%s: start address not even! Please report a bug at "
1043 "flashrom@flashrom.org\n", __func__);
1044 return SPI_GENERIC_ERROR;
1045 }
1046 /* The data sheet requires total AAI write length to be even. */
1047 if (len % 2) {
1048 msg_cerr("%s: total write length not even! Please report a "
1049 "bug at flashrom@flashrom.org\n", __func__);
1050 return SPI_GENERIC_ERROR;
1051 }
1052
Carl-Daniel Hailfinger9c62d112010-06-20 10:41:35 +00001053
1054 result = spi_send_multicommand(cmds);
1055 if (result) {
1056 msg_cerr("%s failed during start command execution\n",
1057 __func__);
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +00001058 /* FIXME: Should we send WRDI here as well to make sure the chip
1059 * is not in AAI mode?
1060 */
Sean Nelson14ba6682010-02-26 05:48:29 +00001061 return result;
Sean Nelson14ba6682010-02-26 05:48:29 +00001062 }
Carl-Daniel Hailfinger9c62d112010-06-20 10:41:35 +00001063 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP)
1064 programmer_delay(10);
1065
1066 /* We already wrote 2 bytes in the multicommand step. */
1067 pos += 2;
1068
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +00001069 while (pos < start + len) {
Carl-Daniel Hailfinger9c62d112010-06-20 10:41:35 +00001070 cmd[1] = buf[pos++];
1071 cmd[2] = buf[pos++];
1072 spi_send_command(JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE, 0, cmd, NULL);
1073 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP)
1074 programmer_delay(10);
1075 }
1076
1077 /* Use WRDI to exit AAI mode. */
Sean Nelson14ba6682010-02-26 05:48:29 +00001078 spi_write_disable();
1079 return 0;
1080}