Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Carl-Daniel Hailfinger |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 20 | #include <stdio.h> |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 21 | #include <string.h> |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 22 | #include <usb.h> |
| 23 | #include "flash.h" |
Sean Nelson | 14ba668 | 2010-02-26 05:48:29 +0000 | [diff] [blame] | 24 | #include "chipdrivers.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 25 | #include "programmer.h" |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 26 | #include "spi.h" |
| 27 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 28 | #define FIRMWARE_VERSION(x,y,z) ((x << 16) | (y << 8) | z) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 29 | #define DEFAULT_TIMEOUT 3000 |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 30 | static usb_dev_handle *dediprog_handle; |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 31 | static int dediprog_firmwareversion; |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 32 | static int dediprog_endpoint; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 33 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 34 | #if 0 |
| 35 | /* Might be useful for other pieces of code as well. */ |
| 36 | static void print_hex(void *buf, size_t len) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 37 | { |
| 38 | size_t i; |
| 39 | |
| 40 | for (i = 0; i < len; i++) |
| 41 | msg_pdbg(" %02x", ((uint8_t *)buf)[i]); |
| 42 | } |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 43 | #endif |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 44 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 45 | /* Might be useful for other USB devices as well. static for now. */ |
| 46 | static struct usb_device *get_device_by_vid_pid(uint16_t vid, uint16_t pid) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 47 | { |
| 48 | struct usb_bus *bus; |
| 49 | struct usb_device *dev; |
| 50 | |
| 51 | for (bus = usb_get_busses(); bus; bus = bus->next) |
| 52 | for (dev = bus->devices; dev; dev = dev->next) |
| 53 | if ((dev->descriptor.idVendor == vid) && |
| 54 | (dev->descriptor.idProduct == pid)) |
| 55 | return dev; |
| 56 | |
| 57 | return NULL; |
| 58 | } |
| 59 | |
| 60 | //int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout); |
| 61 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 62 | /* Set/clear LEDs on dediprog */ |
| 63 | #define PASS_ON (0 << 0) |
| 64 | #define PASS_OFF (1 << 0) |
| 65 | #define BUSY_ON (0 << 1) |
| 66 | #define BUSY_OFF (1 << 1) |
| 67 | #define ERROR_ON (0 << 2) |
| 68 | #define ERROR_OFF (1 << 2) |
| 69 | static int current_led_status = -1; |
| 70 | |
| 71 | static int dediprog_set_leds(int leds) |
| 72 | { |
| 73 | int ret, target_leds; |
| 74 | |
| 75 | if (leds < 0 || leds > 7) |
| 76 | leds = 0; // Bogus value, enable all LEDs |
| 77 | |
| 78 | if (leds == current_led_status) |
| 79 | return 0; |
| 80 | |
| 81 | /* Older Dediprogs with 2.x.x and 3.x.x firmware only had |
| 82 | * two LEDs, and they were reversed. So map them around if |
| 83 | * we have an old device. On those devices the LEDs map as |
| 84 | * follows: |
| 85 | * bit 2 == 0: green light is on. |
| 86 | * bit 0 == 0: red light is on. |
| 87 | */ |
| 88 | if (dediprog_firmwareversion < FIRMWARE_VERSION(5,0,0)) { |
| 89 | target_leds = ((leds & ERROR_OFF) >> 2) | |
| 90 | ((leds & PASS_OFF) << 2); |
| 91 | } else { |
| 92 | target_leds = leds; |
| 93 | } |
| 94 | |
| 95 | ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, target_leds, NULL, 0x0, DEFAULT_TIMEOUT); |
| 96 | if (ret != 0x0) { |
| 97 | msg_perr("Command Set LED 0x%x failed (%s)!\n", leds, usb_strerror()); |
| 98 | return 1; |
| 99 | } |
| 100 | |
| 101 | current_led_status = leds; |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 106 | static int dediprog_set_spi_voltage(int millivolt) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 107 | { |
| 108 | int ret; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 109 | uint16_t voltage_selector; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 110 | |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 111 | switch (millivolt) { |
| 112 | case 0: |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 113 | /* Admittedly this one is an assumption. */ |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 114 | voltage_selector = 0x0; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 115 | break; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 116 | case 1800: |
| 117 | voltage_selector = 0x12; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 118 | break; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 119 | case 2500: |
| 120 | voltage_selector = 0x11; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 121 | break; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 122 | case 3500: |
| 123 | voltage_selector = 0x10; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 124 | break; |
| 125 | default: |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 126 | msg_perr("Unknown voltage %i mV! Aborting.\n", millivolt); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 127 | return 1; |
| 128 | } |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 129 | msg_pdbg("Setting SPI voltage to %u.%03u V\n", millivolt / 1000, |
| 130 | millivolt % 1000); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 131 | |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 132 | ret = usb_control_msg(dediprog_handle, 0x42, 0x9, voltage_selector, 0xff, NULL, 0x0, DEFAULT_TIMEOUT); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 133 | if (ret != 0x0) { |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 134 | msg_perr("Command Set SPI Voltage 0x%x failed!\n", voltage_selector); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 135 | return 1; |
| 136 | } |
| 137 | return 0; |
| 138 | } |
| 139 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 140 | #if 0 |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 141 | /* After dediprog_set_spi_speed, the original app always calls |
| 142 | * dediprog_set_spi_voltage(0) and then |
| 143 | * dediprog_check_devicestring() four times in a row. |
| 144 | * After that, dediprog_command_a() is called. |
| 145 | * This looks suspiciously like the microprocessor in the SF100 has to be |
| 146 | * restarted/reinitialized in case the speed changes. |
| 147 | */ |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 148 | static int dediprog_set_spi_speed(uint16_t speed) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 149 | { |
| 150 | int ret; |
| 151 | unsigned int khz; |
| 152 | |
| 153 | /* Case 1 and 2 are in weird order. Probably an organically "grown" |
| 154 | * interface. |
| 155 | * Base frequency is 24000 kHz, divisors are (in order) |
| 156 | * 1, 3, 2, 8, 11, 16, 32, 64. |
| 157 | */ |
| 158 | switch (speed) { |
| 159 | case 0x0: |
| 160 | khz = 24000; |
| 161 | break; |
| 162 | case 0x1: |
| 163 | khz = 8000; |
| 164 | break; |
| 165 | case 0x2: |
| 166 | khz = 12000; |
| 167 | break; |
| 168 | case 0x3: |
| 169 | khz = 3000; |
| 170 | break; |
| 171 | case 0x4: |
| 172 | khz = 2180; |
| 173 | break; |
| 174 | case 0x5: |
| 175 | khz = 1500; |
| 176 | break; |
| 177 | case 0x6: |
| 178 | khz = 750; |
| 179 | break; |
| 180 | case 0x7: |
| 181 | khz = 375; |
| 182 | break; |
| 183 | default: |
| 184 | msg_perr("Unknown frequency selector 0x%x! Aborting.\n", speed); |
| 185 | return 1; |
| 186 | } |
| 187 | msg_pdbg("Setting SPI speed to %u kHz\n", khz); |
| 188 | |
| 189 | ret = usb_control_msg(dediprog_handle, 0x42, 0x61, speed, 0xff, NULL, 0x0, DEFAULT_TIMEOUT); |
| 190 | if (ret != 0x0) { |
| 191 | msg_perr("Command Set SPI Speed 0x%x failed!\n", speed); |
| 192 | return 1; |
| 193 | } |
| 194 | return 0; |
| 195 | } |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 196 | #endif |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 197 | |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 198 | /* Bulk read interface, will read multiple 512 byte chunks aligned to 512 bytes. |
| 199 | * @start start address |
| 200 | * @len length |
| 201 | * @return 0 on success, 1 on failure |
| 202 | */ |
| 203 | static int dediprog_spi_bulk_read(struct flashchip *flash, uint8_t *buf, |
| 204 | int start, int len) |
| 205 | { |
| 206 | int ret; |
| 207 | int i; |
| 208 | /* chunksize must be 512, other sizes will NOT work at all. */ |
| 209 | const int chunksize = 0x200; |
| 210 | const int count = len / chunksize; |
| 211 | const char count_and_chunk[] = {count & 0xff, |
| 212 | (count >> 8) & 0xff, |
| 213 | chunksize & 0xff, |
| 214 | (chunksize >> 8) & 0xff}; |
| 215 | |
| 216 | if ((start % chunksize) || (len % chunksize)) { |
| 217 | msg_perr("%s: Unaligned start=%i, len=%i! Please report a bug " |
| 218 | "at flashrom@flashrom.org\n", __func__, start, len); |
| 219 | return 1; |
| 220 | } |
| 221 | |
| 222 | /* No idea if the hardware can handle empty reads, so chicken out. */ |
| 223 | if (!len) |
| 224 | return 0; |
| 225 | /* Command Read SPI Bulk. No idea which read command is used on the |
| 226 | * SPI side. |
| 227 | */ |
| 228 | ret = usb_control_msg(dediprog_handle, 0x42, 0x20, start % 0x10000, |
| 229 | start / 0x10000, (char *)count_and_chunk, |
| 230 | sizeof(count_and_chunk), DEFAULT_TIMEOUT); |
| 231 | if (ret != sizeof(count_and_chunk)) { |
| 232 | msg_perr("Command Read SPI Bulk failed, %i %s!\n", ret, |
| 233 | usb_strerror()); |
| 234 | return 1; |
| 235 | } |
| 236 | |
| 237 | for (i = 0; i < count; i++) { |
| 238 | ret = usb_bulk_read(dediprog_handle, 0x80 | dediprog_endpoint, |
| 239 | (char *)buf + i * chunksize, chunksize, |
| 240 | DEFAULT_TIMEOUT); |
| 241 | if (ret != chunksize) { |
| 242 | msg_perr("SPI bulk read %i failed, expected %i, got %i " |
| 243 | "%s!\n", i, chunksize, ret, usb_strerror()); |
| 244 | return 1; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 251 | static int dediprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 252 | { |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 253 | int ret; |
| 254 | /* chunksize must be 512, other sizes will NOT work at all. */ |
| 255 | const int chunksize = 0x200; |
| 256 | int residue = start % chunksize ? chunksize - start % chunksize : 0; |
| 257 | int bulklen; |
| 258 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 259 | dediprog_set_leds(PASS_OFF|BUSY_ON|ERROR_OFF); |
| 260 | |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 261 | if (residue) { |
| 262 | msg_pdbg("Slow read for partial block from 0x%x, length 0x%x\n", |
| 263 | start, residue); |
| 264 | ret = spi_read_chunked(flash, buf, start, residue, 16); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 265 | if (ret) { |
| 266 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 267 | return ret; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 268 | } |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /* Round down. */ |
| 272 | bulklen = (len - residue) / chunksize * chunksize; |
| 273 | ret = dediprog_spi_bulk_read(flash, buf + residue, start + residue, |
| 274 | bulklen); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 275 | if (ret) { |
| 276 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 277 | return ret; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 278 | } |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 279 | |
| 280 | len -= residue + bulklen; |
| 281 | if (len) { |
| 282 | msg_pdbg("Slow read for partial block from 0x%x, length 0x%x\n", |
| 283 | start, len); |
| 284 | ret = spi_read_chunked(flash, buf + residue + bulklen, |
| 285 | start + residue + bulklen, len, 16); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 286 | if (ret) { |
| 287 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 288 | return ret; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 289 | } |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 292 | dediprog_set_leds(PASS_ON|BUSY_OFF|ERROR_OFF); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 293 | return 0; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 296 | static int dediprog_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) |
Carl-Daniel Hailfinger | 306b818 | 2010-11-23 21:28:16 +0000 | [diff] [blame] | 297 | { |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 298 | int ret; |
| 299 | |
| 300 | dediprog_set_leds(PASS_OFF|BUSY_ON|ERROR_OFF); |
| 301 | |
Carl-Daniel Hailfinger | 306b818 | 2010-11-23 21:28:16 +0000 | [diff] [blame] | 302 | /* No idea about the real limit. Maybe 12, maybe more, maybe less. */ |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 303 | ret = spi_write_chunked(flash, buf, start, len, 12); |
| 304 | |
| 305 | if (ret) |
| 306 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
| 307 | else |
| 308 | dediprog_set_leds(PASS_ON|BUSY_OFF|ERROR_OFF); |
| 309 | |
| 310 | return ret; |
Carl-Daniel Hailfinger | 306b818 | 2010-11-23 21:28:16 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 313 | static int dediprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 314 | const unsigned char *writearr, unsigned char *readarr) |
| 315 | { |
| 316 | int ret; |
| 317 | |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 318 | msg_pspew("%s, writecnt=%i, readcnt=%i\n", __func__, writecnt, readcnt); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 319 | /* Paranoid, but I don't want to be blamed if anything explodes. */ |
Carl-Daniel Hailfinger | 306b818 | 2010-11-23 21:28:16 +0000 | [diff] [blame] | 320 | if (writecnt > 16) { |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 321 | msg_perr("Untested writecnt=%i, aborting.\n", writecnt); |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 322 | return 1; |
| 323 | } |
| 324 | /* 16 byte reads should work. */ |
| 325 | if (readcnt > 16) { |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 326 | msg_perr("Untested readcnt=%i, aborting.\n", readcnt); |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 327 | return 1; |
| 328 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 329 | |
| 330 | ret = usb_control_msg(dediprog_handle, 0x42, 0x1, 0xff, readcnt ? 0x1 : 0x0, (char *)writearr, writecnt, DEFAULT_TIMEOUT); |
| 331 | if (ret != writecnt) { |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 332 | msg_perr("Send SPI failed, expected %i, got %i %s!\n", |
| 333 | writecnt, ret, usb_strerror()); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 334 | return 1; |
| 335 | } |
| 336 | if (!readcnt) |
| 337 | return 0; |
| 338 | memset(readarr, 0, readcnt); |
| 339 | ret = usb_control_msg(dediprog_handle, 0xc2, 0x01, 0xbb8, 0x0000, (char *)readarr, readcnt, DEFAULT_TIMEOUT); |
| 340 | if (ret != readcnt) { |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 341 | msg_perr("Receive SPI failed, expected %i, got %i %s!\n", |
| 342 | readcnt, ret, usb_strerror()); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 343 | return 1; |
| 344 | } |
| 345 | return 0; |
| 346 | } |
| 347 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 348 | static int dediprog_check_devicestring(void) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 349 | { |
| 350 | int ret; |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 351 | int fw[3]; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 352 | char buf[0x11]; |
| 353 | |
| 354 | /* Command Prepare Receive Device String. */ |
| 355 | memset(buf, 0, sizeof(buf)); |
| 356 | ret = usb_control_msg(dediprog_handle, 0xc3, 0x7, 0x0, 0xef03, buf, 0x1, DEFAULT_TIMEOUT); |
| 357 | /* The char casting is needed to stop gcc complaining about an always true comparison. */ |
| 358 | if ((ret != 0x1) || (buf[0] != (char)0xff)) { |
| 359 | msg_perr("Unexpected response to Command Prepare Receive Device" |
| 360 | " String!\n"); |
| 361 | return 1; |
| 362 | } |
| 363 | /* Command Receive Device String. */ |
| 364 | memset(buf, 0, sizeof(buf)); |
| 365 | ret = usb_control_msg(dediprog_handle, 0xc2, 0x8, 0xff, 0xff, buf, 0x10, DEFAULT_TIMEOUT); |
| 366 | if (ret != 0x10) { |
| 367 | msg_perr("Incomplete/failed Command Receive Device String!\n"); |
| 368 | return 1; |
| 369 | } |
| 370 | buf[0x10] = '\0'; |
| 371 | msg_pdbg("Found a %s\n", buf); |
| 372 | if (memcmp(buf, "SF100", 0x5)) { |
| 373 | msg_perr("Device not a SF100!\n"); |
| 374 | return 1; |
| 375 | } |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 376 | if (sscanf(buf, "SF100 V:%d.%d.%d ", &fw[0], &fw[1], &fw[2]) != 3) { |
| 377 | msg_perr("Unexpected firmware version string!\n"); |
| 378 | return 1; |
| 379 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 380 | /* Only these versions were tested. */ |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 381 | if (fw[0] < 2 || fw[0] > 5) { |
| 382 | msg_perr("Unexpected firmware version %d.%d.%d!\n", fw[0], |
| 383 | fw[1], fw[2]); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 384 | return 1; |
| 385 | } |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 386 | dediprog_firmwareversion = FIRMWARE_VERSION(fw[0], fw[1], fw[2]); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | /* Command A seems to be some sort of device init. It is either followed by |
| 391 | * dediprog_check_devicestring (often) or Command A (often) or |
| 392 | * Command F (once). |
| 393 | */ |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 394 | static int dediprog_command_a(void) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 395 | { |
| 396 | int ret; |
| 397 | char buf[0x1]; |
| 398 | |
| 399 | memset(buf, 0, sizeof(buf)); |
| 400 | ret = usb_control_msg(dediprog_handle, 0xc3, 0xb, 0x0, 0x0, buf, 0x1, DEFAULT_TIMEOUT); |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 401 | if (ret < 0) { |
| 402 | msg_perr("Command A failed (%s)!\n", usb_strerror()); |
| 403 | return 1; |
| 404 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 405 | if ((ret != 0x1) || (buf[0] != 0x6f)) { |
| 406 | msg_perr("Unexpected response to Command A!\n"); |
| 407 | return 1; |
| 408 | } |
| 409 | return 0; |
| 410 | } |
| 411 | |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 412 | #if 0 |
| 413 | /* Something. |
| 414 | * Present in eng_detect_blink.log with firmware 3.1.8 |
| 415 | * Always preceded by Command Receive Device String |
| 416 | */ |
| 417 | static int dediprog_command_b(void) |
| 418 | { |
| 419 | int ret; |
| 420 | char buf[0x3]; |
| 421 | |
| 422 | memset(buf, 0, sizeof(buf)); |
| 423 | ret = usb_control_msg(dediprog_handle, 0xc3, 0x7, 0x0, 0xef00, buf, 0x3, DEFAULT_TIMEOUT); |
| 424 | if (ret < 0) { |
| 425 | msg_perr("Command B failed (%s)!\n", usb_strerror()); |
| 426 | return 1; |
| 427 | } |
| 428 | if ((ret != 0x3) || (buf[0] != 0xff) || (buf[1] != 0xff) || |
| 429 | (buf[2] != 0xff)) { |
| 430 | msg_perr("Unexpected response to Command B!\n"); |
| 431 | return 1; |
| 432 | } |
| 433 | |
| 434 | return 0; |
| 435 | } |
| 436 | #endif |
| 437 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 438 | /* Command C is only sent after dediprog_check_devicestring, but not after every |
| 439 | * invocation of dediprog_check_devicestring. It is only sent after the first |
| 440 | * dediprog_command_a(); dediprog_check_devicestring() sequence in each session. |
| 441 | * I'm tempted to call this one start_SPI_engine or finish_init. |
| 442 | */ |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 443 | static int dediprog_command_c(void) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 444 | { |
| 445 | int ret; |
| 446 | |
| 447 | ret = usb_control_msg(dediprog_handle, 0x42, 0x4, 0x0, 0x0, NULL, 0x0, DEFAULT_TIMEOUT); |
| 448 | if (ret != 0x0) { |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 449 | msg_perr("Command C failed (%s)!\n", usb_strerror()); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 450 | return 1; |
| 451 | } |
| 452 | return 0; |
| 453 | } |
| 454 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 455 | #if 0 |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 456 | /* Very strange. Seems to be a programmer keepalive or somesuch. |
| 457 | * Wait unsuccessfully for timeout ms to read one byte. |
| 458 | * Is usually called after setting voltage to 0. |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 459 | * Present in all logs with Firmware 2.1.1 and 3.1.8 |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 460 | */ |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 461 | static int dediprog_command_f(int timeout) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 462 | { |
| 463 | int ret; |
| 464 | char buf[0x1]; |
| 465 | |
| 466 | memset(buf, 0, sizeof(buf)); |
| 467 | ret = usb_control_msg(dediprog_handle, 0xc2, 0x11, 0xff, 0xff, buf, 0x1, timeout); |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 468 | /* This check is most probably wrong. Command F always causes a timeout |
| 469 | * in the logs, so we should check for timeout instead of checking for |
| 470 | * success. |
| 471 | */ |
| 472 | if (ret != 0x1) { |
| 473 | msg_perr("Command F failed (%s)!\n", usb_strerror()); |
| 474 | return 1; |
| 475 | } |
| 476 | return 0; |
| 477 | } |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 478 | #endif |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 479 | |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 480 | static int parse_voltage(char *voltage) |
| 481 | { |
| 482 | char *tmp = NULL; |
| 483 | int i; |
| 484 | int millivolt; |
| 485 | int fraction = 0; |
| 486 | |
| 487 | if (!voltage || !strlen(voltage)) { |
| 488 | msg_perr("Empty voltage= specified.\n"); |
| 489 | return -1; |
| 490 | } |
| 491 | millivolt = (int)strtol(voltage, &tmp, 0); |
| 492 | voltage = tmp; |
| 493 | /* Handle "," and "." as decimal point. Everything after it is assumed |
| 494 | * to be in decimal notation. |
| 495 | */ |
| 496 | if ((*voltage == '.') || (*voltage == ',')) { |
| 497 | voltage++; |
| 498 | for (i = 0; i < 3; i++) { |
| 499 | fraction *= 10; |
| 500 | /* Don't advance if the current character is invalid, |
| 501 | * but continue multiplying. |
| 502 | */ |
| 503 | if ((*voltage < '0') || (*voltage > '9')) |
| 504 | continue; |
| 505 | fraction += *voltage - '0'; |
| 506 | voltage++; |
| 507 | } |
| 508 | /* Throw away remaining digits. */ |
| 509 | voltage += strspn(voltage, "0123456789"); |
| 510 | } |
| 511 | /* The remaining string must be empty or "mV" or "V". */ |
| 512 | tolower_string(voltage); |
| 513 | |
| 514 | /* No unit or "V". */ |
| 515 | if ((*voltage == '\0') || !strncmp(voltage, "v", 1)) { |
| 516 | millivolt *= 1000; |
| 517 | millivolt += fraction; |
| 518 | } else if (!strncmp(voltage, "mv", 2) || |
| 519 | !strncmp(voltage, "milliv", 6)) { |
| 520 | /* No adjustment. fraction is discarded. */ |
| 521 | } else { |
| 522 | /* Garbage at the end of the string. */ |
| 523 | msg_perr("Garbage voltage= specified.\n"); |
| 524 | return -1; |
| 525 | } |
| 526 | return millivolt; |
| 527 | } |
| 528 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 529 | static const struct spi_programmer spi_programmer_dediprog = { |
| 530 | .type = SPI_CONTROLLER_DEDIPROG, |
| 531 | .max_data_read = MAX_DATA_UNSPECIFIED, |
| 532 | .max_data_write = MAX_DATA_UNSPECIFIED, |
| 533 | .command = dediprog_spi_send_command, |
| 534 | .multicommand = default_spi_send_multicommand, |
| 535 | .read = dediprog_spi_read, |
| 536 | .write_256 = dediprog_spi_write_256, |
| 537 | }; |
| 538 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame^] | 539 | static int dediprog_shutdown(void *data) |
| 540 | { |
| 541 | msg_pspew("%s\n", __func__); |
| 542 | |
| 543 | /* URB 28. Command Set SPI Voltage to 0. */ |
| 544 | if (dediprog_set_spi_voltage(0x0)) |
| 545 | return 1; |
| 546 | |
| 547 | if (usb_release_interface(dediprog_handle, 0)) { |
| 548 | msg_perr("Could not release USB interface!\n"); |
| 549 | return 1; |
| 550 | } |
| 551 | if (usb_close(dediprog_handle)) { |
| 552 | msg_perr("Could not close USB device!\n"); |
| 553 | return 1; |
| 554 | } |
| 555 | return 0; |
| 556 | } |
| 557 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 558 | /* URB numbers refer to the first log ever captured. */ |
| 559 | int dediprog_init(void) |
| 560 | { |
| 561 | struct usb_device *dev; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 562 | char *voltage; |
| 563 | int millivolt = 3500; |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 564 | int ret; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 565 | |
| 566 | msg_pspew("%s\n", __func__); |
| 567 | |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 568 | voltage = extract_programmer_param("voltage"); |
| 569 | if (voltage) { |
| 570 | millivolt = parse_voltage(voltage); |
| 571 | free(voltage); |
| 572 | if (millivolt < 0) { |
| 573 | return 1; |
| 574 | } |
| 575 | msg_pinfo("Setting voltage to %i mV\n", millivolt); |
| 576 | } |
| 577 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 578 | /* Here comes the USB stuff. */ |
| 579 | usb_init(); |
| 580 | usb_find_busses(); |
| 581 | usb_find_devices(); |
| 582 | dev = get_device_by_vid_pid(0x0483, 0xdada); |
| 583 | if (!dev) { |
| 584 | msg_perr("Could not find a Dediprog SF100 on USB!\n"); |
| 585 | return 1; |
| 586 | } |
| 587 | msg_pdbg("Found USB device (%04x:%04x).\n", |
| 588 | dev->descriptor.idVendor, |
| 589 | dev->descriptor.idProduct); |
| 590 | dediprog_handle = usb_open(dev); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 591 | ret = usb_set_configuration(dediprog_handle, 1); |
| 592 | if (ret < 0) { |
| 593 | msg_perr("Could not set USB device configuration: %i %s\n", |
| 594 | ret, usb_strerror()); |
| 595 | if (usb_close(dediprog_handle)) |
| 596 | msg_perr("Could not close USB device!\n"); |
| 597 | return 1; |
| 598 | } |
| 599 | ret = usb_claim_interface(dediprog_handle, 0); |
| 600 | if (ret < 0) { |
| 601 | msg_perr("Could not claim USB device interface %i: %i %s\n", |
| 602 | 0, ret, usb_strerror()); |
| 603 | if (usb_close(dediprog_handle)) |
| 604 | msg_perr("Could not close USB device!\n"); |
| 605 | return 1; |
| 606 | } |
| 607 | dediprog_endpoint = 2; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 608 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame^] | 609 | if (register_shutdown(dediprog_shutdown, NULL)) |
| 610 | return 1; |
| 611 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 612 | dediprog_set_leds(PASS_ON|BUSY_ON|ERROR_ON); |
| 613 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 614 | /* URB 6. Command A. */ |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 615 | if (dediprog_command_a()) { |
| 616 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 617 | return 1; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 618 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 619 | /* URB 7. Command A. */ |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 620 | if (dediprog_command_a()) { |
| 621 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 622 | return 1; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 623 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 624 | /* URB 8. Command Prepare Receive Device String. */ |
| 625 | /* URB 9. Command Receive Device String. */ |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 626 | if (dediprog_check_devicestring()) { |
| 627 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 628 | return 1; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 629 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 630 | /* URB 10. Command C. */ |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 631 | if (dediprog_command_c()) { |
| 632 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 633 | return 1; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 634 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 635 | /* URB 11. Command Set SPI Voltage. */ |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 636 | if (dediprog_set_spi_voltage(millivolt)) { |
| 637 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 638 | return 1; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 639 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 640 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 641 | register_spi_programmer(&spi_programmer_dediprog); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 642 | |
| 643 | /* RE leftover, leave in until the driver is complete. */ |
| 644 | #if 0 |
| 645 | /* Execute RDID by hand if you want to test it. */ |
| 646 | dediprog_do_stuff(); |
| 647 | #endif |
| 648 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 649 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_OFF); |
| 650 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 651 | return 0; |
| 652 | } |
| 653 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 654 | #if 0 |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 655 | /* Leftovers from reverse engineering. Keep for documentation purposes until |
| 656 | * completely understood. |
| 657 | */ |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 658 | static int dediprog_do_stuff(void) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 659 | { |
| 660 | char buf[0x4]; |
| 661 | /* SPI command processing starts here. */ |
| 662 | |
| 663 | /* URB 12. Command Send SPI. */ |
| 664 | /* URB 13. Command Receive SPI. */ |
| 665 | memset(buf, 0, sizeof(buf)); |
| 666 | /* JEDEC RDID */ |
| 667 | msg_pdbg("Sending RDID\n"); |
| 668 | buf[0] = JEDEC_RDID; |
| 669 | if (dediprog_spi_send_command(JEDEC_RDID_OUTSIZE, JEDEC_RDID_INSIZE, (unsigned char *)buf, (unsigned char *)buf)) |
| 670 | return 1; |
| 671 | msg_pdbg("Receiving response: "); |
| 672 | print_hex(buf, JEDEC_RDID_INSIZE); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 673 | /* URB 14-27 are more SPI commands. */ |
| 674 | /* URB 28. Command Set SPI Voltage. */ |
| 675 | if (dediprog_set_spi_voltage(0x0)) |
| 676 | return 1; |
| 677 | /* URB 29-38. Command F, unsuccessful wait. */ |
| 678 | if (dediprog_command_f(544)) |
| 679 | return 1; |
| 680 | /* URB 39. Command Set SPI Voltage. */ |
| 681 | if (dediprog_set_spi_voltage(0x10)) |
| 682 | return 1; |
| 683 | /* URB 40. Command Set SPI Speed. */ |
| 684 | if (dediprog_set_spi_speed(0x2)) |
| 685 | return 1; |
| 686 | /* URB 41 is just URB 28. */ |
| 687 | /* URB 42,44,46,48,51,53 is just URB 8. */ |
| 688 | /* URB 43,45,47,49,52,54 is just URB 9. */ |
| 689 | /* URB 50 is just URB 6/7. */ |
| 690 | /* URB 55-131 is just URB 29-38. (wait unsuccessfully for 4695 (maybe 4751) ms)*/ |
| 691 | /* URB 132,134 is just URB 6/7. */ |
| 692 | /* URB 133 is just URB 29-38. */ |
| 693 | /* URB 135 is just URB 8. */ |
| 694 | /* URB 136 is just URB 9. */ |
| 695 | /* URB 137 is just URB 11. */ |
| 696 | |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 697 | /* Command Start Bulk Read. Data is u16 blockcount, u16 blocksize. */ |
| 698 | /* Command Start Bulk Write. Data is u16 blockcount, u16 blocksize. */ |
| 699 | /* Bulk transfer sizes for Command Start Bulk Read/Write are always |
| 700 | * 512 bytes, rest is filled with 0xff. |
| 701 | */ |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 702 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 703 | return 0; |
| 704 | } |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 705 | #endif |