Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2009 Paul Fox <pgf@laptop.org> |
| 5 | * Copyright (C) 2009 Carl-Daniel Hailfinger |
| 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 | |
Carl-Daniel Hailfinger | 3426ef6 | 2009-08-19 13:27:58 +0000 | [diff] [blame] | 21 | #if FT2232_SPI_SUPPORT == 1 |
| 22 | |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <stdint.h> |
| 25 | #include <string.h> |
| 26 | #include <stdlib.h> |
Carl-Daniel Hailfinger | feea272 | 2009-07-01 00:02:23 +0000 | [diff] [blame] | 27 | #include <ctype.h> |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 28 | #include "flash.h" |
| 29 | #include "spi.h" |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 30 | #include <ftdi.h> |
| 31 | |
Carl-Daniel Hailfinger | 5609fa7 | 2010-01-07 03:32:17 +0000 | [diff] [blame^] | 32 | /* Change this to #define if you want lowlevel debugging of commands |
| 33 | * sent to the FT2232 SPI controller. |
| 34 | */ |
| 35 | #undef COMM_DEBUG |
| 36 | |
| 37 | #ifdef COMM_DEBUG |
| 38 | #define msg_comm_debug printf_debug |
| 39 | #else |
| 40 | #define msg_comm_debug(...) do {} while (0) |
| 41 | #endif |
| 42 | |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 43 | /* |
| 44 | * The 'H' chips can run internally at either 12MHz or 60MHz. |
| 45 | * The non-H chips can only run at 12MHz. |
| 46 | */ |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 47 | #define CLOCK_5X 1 |
| 48 | |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 49 | /* |
| 50 | * In either case, the divisor is a simple integer clock divider. |
| 51 | * If CLOCK_5X is set, this divisor divides 30MHz, else it divides 6MHz. |
| 52 | */ |
| 53 | #define DIVIDE_BY 3 /* e.g. '3' will give either 10MHz or 2MHz SPI clock. */ |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 54 | |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 55 | #define BITMODE_BITBANG_NORMAL 1 |
| 56 | #define BITMODE_BITBANG_SPI 2 |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 57 | |
| 58 | static struct ftdi_context ftdic_context; |
| 59 | |
| 60 | int send_buf(struct ftdi_context *ftdic, const unsigned char *buf, int size) |
| 61 | { |
| 62 | int r; |
| 63 | r = ftdi_write_data(ftdic, (unsigned char *) buf, size); |
| 64 | if (r < 0) { |
| 65 | fprintf(stderr, "ftdi_write_data: %d, %s\n", r, |
| 66 | ftdi_get_error_string(ftdic)); |
| 67 | return 1; |
| 68 | } |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | int get_buf(struct ftdi_context *ftdic, const unsigned char *buf, int size) |
| 73 | { |
| 74 | int r; |
| 75 | r = ftdi_read_data(ftdic, (unsigned char *) buf, size); |
| 76 | if (r < 0) { |
| 77 | fprintf(stderr, "ftdi_read_data: %d, %s\n", r, |
| 78 | ftdi_get_error_string(ftdic)); |
| 79 | return 1; |
| 80 | } |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | int ft2232_spi_init(void) |
| 85 | { |
| 86 | int f; |
| 87 | struct ftdi_context *ftdic = &ftdic_context; |
| 88 | unsigned char buf[512]; |
Carl-Daniel Hailfinger | feea272 | 2009-07-01 00:02:23 +0000 | [diff] [blame] | 89 | char *portpos = NULL; |
| 90 | int ft2232_type = FTDI_FT4232H; |
| 91 | enum ftdi_interface ft2232_interface = INTERFACE_B; |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 92 | |
| 93 | if (ftdi_init(ftdic) < 0) { |
| 94 | fprintf(stderr, "ftdi_init failed\n"); |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 95 | return EXIT_FAILURE; // TODO |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Carl-Daniel Hailfinger | ef58a9c | 2009-08-12 13:32:56 +0000 | [diff] [blame] | 98 | if (programmer_param && !strlen(programmer_param)) { |
| 99 | free(programmer_param); |
| 100 | programmer_param = NULL; |
Carl-Daniel Hailfinger | feea272 | 2009-07-01 00:02:23 +0000 | [diff] [blame] | 101 | } |
Carl-Daniel Hailfinger | ef58a9c | 2009-08-12 13:32:56 +0000 | [diff] [blame] | 102 | if (programmer_param) { |
| 103 | if (strstr(programmer_param, "2232")) |
Carl-Daniel Hailfinger | feea272 | 2009-07-01 00:02:23 +0000 | [diff] [blame] | 104 | ft2232_type = FTDI_FT2232H; |
Carl-Daniel Hailfinger | ef58a9c | 2009-08-12 13:32:56 +0000 | [diff] [blame] | 105 | if (strstr(programmer_param, "4232")) |
Carl-Daniel Hailfinger | feea272 | 2009-07-01 00:02:23 +0000 | [diff] [blame] | 106 | ft2232_type = FTDI_FT4232H; |
Carl-Daniel Hailfinger | ef58a9c | 2009-08-12 13:32:56 +0000 | [diff] [blame] | 107 | portpos = strstr(programmer_param, "port="); |
Carl-Daniel Hailfinger | feea272 | 2009-07-01 00:02:23 +0000 | [diff] [blame] | 108 | if (portpos) { |
| 109 | portpos += 5; |
| 110 | switch (toupper(*portpos)) { |
| 111 | case 'A': |
| 112 | ft2232_interface = INTERFACE_A; |
| 113 | break; |
| 114 | case 'B': |
| 115 | ft2232_interface = INTERFACE_B; |
| 116 | break; |
| 117 | default: |
| 118 | fprintf(stderr, "Invalid interface specified, " |
| 119 | "using default.\n"); |
| 120 | } |
| 121 | } |
Carl-Daniel Hailfinger | ef58a9c | 2009-08-12 13:32:56 +0000 | [diff] [blame] | 122 | free(programmer_param); |
Carl-Daniel Hailfinger | feea272 | 2009-07-01 00:02:23 +0000 | [diff] [blame] | 123 | } |
| 124 | printf_debug("Using device type %s ", |
| 125 | (ft2232_type == FTDI_FT2232H) ? "2232H" : "4232H"); |
| 126 | printf_debug("interface %s\n", |
| 127 | (ft2232_interface == INTERFACE_A) ? "A" : "B"); |
| 128 | |
| 129 | f = ftdi_usb_open(ftdic, 0x0403, ft2232_type); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 130 | |
| 131 | if (f < 0 && f != -5) { |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 132 | fprintf(stderr, "Unable to open FTDI device: %d (%s)\n", f, |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 133 | ftdi_get_error_string(ftdic)); |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 134 | exit(-1); // TODO |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Carl-Daniel Hailfinger | feea272 | 2009-07-01 00:02:23 +0000 | [diff] [blame] | 137 | if (ftdi_set_interface(ftdic, ft2232_interface) < 0) { |
| 138 | fprintf(stderr, "Unable to select interface: %s\n", |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 139 | ftdic->error_str); |
| 140 | } |
| 141 | |
| 142 | if (ftdi_usb_reset(ftdic) < 0) { |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 143 | fprintf(stderr, "Unable to reset FTDI device\n"); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | if (ftdi_set_latency_timer(ftdic, 2) < 0) { |
| 147 | fprintf(stderr, "Unable to set latency timer\n"); |
| 148 | } |
| 149 | |
| 150 | if (ftdi_write_data_set_chunksize(ftdic, 512)) { |
| 151 | fprintf(stderr, "Unable to set chunk size\n"); |
| 152 | } |
| 153 | |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 154 | if (ftdi_set_bitmode(ftdic, 0x00, BITMODE_BITBANG_SPI) < 0) { |
| 155 | fprintf(stderr, "Unable to set bitmode to SPI\n"); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | #if CLOCK_5X |
| 159 | printf_debug("Disable divide-by-5 front stage\n"); |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 160 | buf[0] = 0x8a; /* Disable divide-by-5. */ |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 161 | if (send_buf(ftdic, buf, 1)) |
| 162 | return -1; |
| 163 | #define MPSSE_CLK 60.0 |
| 164 | |
| 165 | #else |
| 166 | |
| 167 | #define MPSSE_CLK 12.0 |
| 168 | |
| 169 | #endif |
| 170 | printf_debug("Set clock divisor\n"); |
| 171 | buf[0] = 0x86; /* command "set divisor" */ |
| 172 | /* valueL/valueH are (desired_divisor - 1) */ |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 173 | buf[1] = (DIVIDE_BY - 1) & 0xff; |
| 174 | buf[2] = ((DIVIDE_BY - 1) >> 8) & 0xff; |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 175 | if (send_buf(ftdic, buf, 3)) |
| 176 | return -1; |
| 177 | |
| 178 | printf("SPI clock is %fMHz\n", |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 179 | (double)(MPSSE_CLK / (((DIVIDE_BY - 1) + 1) * 2))); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 180 | |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 181 | /* Disconnect TDI/DO to TDO/DI for loopback. */ |
| 182 | printf_debug("No loopback of TDI/DO TDO/DI\n"); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 183 | buf[0] = 0x85; |
| 184 | if (send_buf(ftdic, buf, 1)) |
| 185 | return -1; |
| 186 | |
| 187 | printf_debug("Set data bits\n"); |
| 188 | /* Set data bits low-byte command: |
| 189 | * value: 0x08 CS=high, DI=low, DO=low, SK=low |
| 190 | * dir: 0x0b CS=output, DI=input, DO=output, SK=output |
| 191 | */ |
| 192 | #define CS_BIT 0x08 |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 193 | buf[0] = SET_BITS_LOW; |
Stefan Reinauer | ab044b2 | 2009-09-16 08:26:59 +0000 | [diff] [blame] | 194 | buf[1] = CS_BIT; |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 195 | buf[2] = 0x0b; |
| 196 | if (send_buf(ftdic, buf, 3)) |
| 197 | return -1; |
| 198 | |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 199 | // printf_debug("\nft2232 chosen\n"); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 200 | |
| 201 | buses_supported = CHIP_BUSTYPE_SPI; |
| 202 | spi_controller = SPI_CONTROLLER_FT2232; |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | |
Carl-Daniel Hailfinger | d047829 | 2009-07-10 21:08:55 +0000 | [diff] [blame] | 207 | int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 208 | const unsigned char *writearr, unsigned char *readarr) |
| 209 | { |
| 210 | struct ftdi_context *ftdic = &ftdic_context; |
| 211 | static unsigned char *buf = NULL; |
Carl-Daniel Hailfinger | a2441ce | 2009-11-22 01:33:40 +0000 | [diff] [blame] | 212 | /* failed is special. We use bitwise ops, but it is essentially bool. */ |
| 213 | int i = 0, ret = 0, failed = 0; |
Carl-Daniel Hailfinger | b7e0145 | 2009-11-25 16:58:17 +0000 | [diff] [blame] | 214 | int bufsize; |
| 215 | static int oldbufsize = 0; |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 216 | |
Carl-Daniel Hailfinger | 142e30f | 2009-07-14 10:26:56 +0000 | [diff] [blame] | 217 | if (writecnt > 65536 || readcnt > 65536) |
| 218 | return SPI_INVALID_LENGTH; |
| 219 | |
Carl-Daniel Hailfinger | b7e0145 | 2009-11-25 16:58:17 +0000 | [diff] [blame] | 220 | /* buf is not used for the response from the chip. */ |
| 221 | bufsize = max(writecnt + 9, 260 + 9); |
| 222 | /* Never shrink. realloc() calls are expensive. */ |
| 223 | if (bufsize > oldbufsize) { |
| 224 | buf = realloc(buf, bufsize); |
| 225 | if (!buf) { |
| 226 | fprintf(stderr, "Out of memory!\n"); |
| 227 | exit(1); |
| 228 | } |
| 229 | oldbufsize = bufsize; |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 232 | /* |
| 233 | * Minimize USB transfers by packing as many commands as possible |
| 234 | * together. If we're not expecting to read, we can assert CS#, write, |
| 235 | * and deassert CS# all in one shot. If reading, we do three separate |
Stefan Reinauer | ab044b2 | 2009-09-16 08:26:59 +0000 | [diff] [blame] | 236 | * operations. |
| 237 | */ |
Carl-Daniel Hailfinger | 5609fa7 | 2010-01-07 03:32:17 +0000 | [diff] [blame^] | 238 | msg_comm_debug("Assert CS#\n"); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 239 | buf[i++] = SET_BITS_LOW; |
Stefan Reinauer | ab044b2 | 2009-09-16 08:26:59 +0000 | [diff] [blame] | 240 | buf[i++] = 0 & ~CS_BIT; /* assertive */ |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 241 | buf[i++] = 0x0b; |
| 242 | |
| 243 | if (writecnt) { |
| 244 | buf[i++] = 0x11; |
| 245 | buf[i++] = (writecnt - 1) & 0xff; |
| 246 | buf[i++] = ((writecnt - 1) >> 8) & 0xff; |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 247 | memcpy(buf + i, writearr, writecnt); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 248 | i += writecnt; |
| 249 | } |
| 250 | |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 251 | /* |
| 252 | * Optionally terminate this batch of commands with a |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 253 | * read command, then do the fetch of the results. |
| 254 | */ |
| 255 | if (readcnt) { |
| 256 | buf[i++] = 0x20; |
| 257 | buf[i++] = (readcnt - 1) & 0xff; |
| 258 | buf[i++] = ((readcnt - 1) >> 8) & 0xff; |
| 259 | ret = send_buf(ftdic, buf, i); |
Carl-Daniel Hailfinger | a2441ce | 2009-11-22 01:33:40 +0000 | [diff] [blame] | 260 | failed = ret; |
| 261 | /* We can't abort here, we still have to deassert CS#. */ |
| 262 | if (ret) |
| 263 | fprintf(stderr, "send_buf failed before read: %i\n", |
| 264 | ret); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 265 | i = 0; |
Stefan Reinauer | ab044b2 | 2009-09-16 08:26:59 +0000 | [diff] [blame] | 266 | if (ret == 0) { |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 267 | /* |
| 268 | * FIXME: This is unreliable. There's no guarantee that |
| 269 | * we read the response directly after sending the read |
| 270 | * command. We may be scheduled out etc. |
Stefan Reinauer | ab044b2 | 2009-09-16 08:26:59 +0000 | [diff] [blame] | 271 | */ |
| 272 | ret = get_buf(ftdic, readarr, readcnt); |
Carl-Daniel Hailfinger | a2441ce | 2009-11-22 01:33:40 +0000 | [diff] [blame] | 273 | failed |= ret; |
| 274 | /* We can't abort here either. */ |
| 275 | if (ret) |
| 276 | fprintf(stderr, "get_buf failed: %i\n", ret); |
Stefan Reinauer | ab044b2 | 2009-09-16 08:26:59 +0000 | [diff] [blame] | 277 | } |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Carl-Daniel Hailfinger | 5609fa7 | 2010-01-07 03:32:17 +0000 | [diff] [blame^] | 280 | msg_comm_debug("De-assert CS#\n"); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 281 | buf[i++] = SET_BITS_LOW; |
Stefan Reinauer | ab044b2 | 2009-09-16 08:26:59 +0000 | [diff] [blame] | 282 | buf[i++] = CS_BIT; |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 283 | buf[i++] = 0x0b; |
Carl-Daniel Hailfinger | a2441ce | 2009-11-22 01:33:40 +0000 | [diff] [blame] | 284 | ret = send_buf(ftdic, buf, i); |
| 285 | failed |= ret; |
| 286 | if (ret) |
| 287 | fprintf(stderr, "send_buf failed at end: %i\n", ret); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 288 | |
Carl-Daniel Hailfinger | a2441ce | 2009-11-22 01:33:40 +0000 | [diff] [blame] | 289 | return failed ? -1 : 0; |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) |
| 293 | { |
| 294 | /* Maximum read length is 64k bytes. */ |
| 295 | return spi_read_chunked(flash, buf, start, len, 64 * 1024); |
| 296 | } |
| 297 | |
| 298 | int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf) |
| 299 | { |
| 300 | int total_size = 1024 * flash->total_size; |
| 301 | int i; |
| 302 | |
Carl-Daniel Hailfinger | 116081a | 2009-08-10 02:29:21 +0000 | [diff] [blame] | 303 | spi_disable_blockprotect(); |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 304 | /* Erase first. */ |
Carl-Daniel Hailfinger | 116081a | 2009-08-10 02:29:21 +0000 | [diff] [blame] | 305 | printf("Erasing flash before programming... "); |
Carl-Daniel Hailfinger | f38431a | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 306 | if (erase_flash(flash)) { |
Carl-Daniel Hailfinger | 116081a | 2009-08-10 02:29:21 +0000 | [diff] [blame] | 307 | fprintf(stderr, "ERASE FAILED!\n"); |
| 308 | return -1; |
| 309 | } |
| 310 | printf("done.\n"); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 311 | printf_debug("total_size is %d\n", total_size); |
| 312 | for (i = 0; i < total_size; i += 256) { |
| 313 | int l, r; |
| 314 | if (i + 256 <= total_size) |
| 315 | l = 256; |
| 316 | else |
| 317 | l = total_size - i; |
| 318 | |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 319 | if ((r = spi_nbyte_program(i, &buf[i], l))) { |
Uwe Hermann | 04aa59a | 2009-09-02 22:09:00 +0000 | [diff] [blame] | 320 | fprintf(stderr, "%s: write fail %d\n", __func__, r); |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 321 | return 1; |
| 322 | } |
Uwe Hermann | c67d037 | 2009-10-01 18:40:02 +0000 | [diff] [blame] | 323 | |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 324 | while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) |
| 325 | /* loop */; |
| 326 | } |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
Paul Fox | 05dfbe6 | 2009-06-16 21:08:06 +0000 | [diff] [blame] | 331 | #endif |