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> |
Stefan Tauner | e34e3e8 | 2013-01-01 00:06:51 +0000 | [diff] [blame] | 22 | #include <limits.h> |
Nathan Laredo | 21541a6 | 2012-12-24 22:07:36 +0000 | [diff] [blame] | 23 | #include <errno.h> |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 24 | #include <usb.h> |
| 25 | #include "flash.h" |
Sean Nelson | 14ba668 | 2010-02-26 05:48:29 +0000 | [diff] [blame] | 26 | #include "chipdrivers.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 27 | #include "programmer.h" |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 28 | #include "spi.h" |
| 29 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 30 | #define FIRMWARE_VERSION(x,y,z) ((x << 16) | (y << 8) | z) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 31 | #define DEFAULT_TIMEOUT 3000 |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 32 | static usb_dev_handle *dediprog_handle; |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 33 | static int dediprog_firmwareversion; |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 34 | static int dediprog_endpoint; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 35 | |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 36 | #define DEDI_SPI_CMD_PAGEWRITE 0x1 |
| 37 | #define DEDI_SPI_CMD_AAIWRITE 0x4 |
| 38 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 39 | #if 0 |
| 40 | /* Might be useful for other pieces of code as well. */ |
| 41 | static void print_hex(void *buf, size_t len) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 42 | { |
| 43 | size_t i; |
| 44 | |
| 45 | for (i = 0; i < len; i++) |
| 46 | msg_pdbg(" %02x", ((uint8_t *)buf)[i]); |
| 47 | } |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 48 | #endif |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 49 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 50 | /* Might be useful for other USB devices as well. static for now. */ |
Nathan Laredo | 21541a6 | 2012-12-24 22:07:36 +0000 | [diff] [blame] | 51 | /* device parameter allows user to specify one device of multiple installed */ |
| 52 | static struct usb_device *get_device_by_vid_pid(uint16_t vid, uint16_t pid, unsigned int device) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 53 | { |
| 54 | struct usb_bus *bus; |
| 55 | struct usb_device *dev; |
| 56 | |
| 57 | for (bus = usb_get_busses(); bus; bus = bus->next) |
| 58 | for (dev = bus->devices; dev; dev = dev->next) |
| 59 | if ((dev->descriptor.idVendor == vid) && |
Nathan Laredo | 21541a6 | 2012-12-24 22:07:36 +0000 | [diff] [blame] | 60 | (dev->descriptor.idProduct == pid)) { |
| 61 | if (device == 0) |
| 62 | return dev; |
| 63 | device--; |
| 64 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 65 | |
| 66 | return NULL; |
| 67 | } |
| 68 | |
| 69 | //int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout); |
| 70 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 71 | /* Set/clear LEDs on dediprog */ |
| 72 | #define PASS_ON (0 << 0) |
| 73 | #define PASS_OFF (1 << 0) |
| 74 | #define BUSY_ON (0 << 1) |
| 75 | #define BUSY_OFF (1 << 1) |
| 76 | #define ERROR_ON (0 << 2) |
| 77 | #define ERROR_OFF (1 << 2) |
| 78 | static int current_led_status = -1; |
| 79 | |
| 80 | static int dediprog_set_leds(int leds) |
| 81 | { |
| 82 | int ret, target_leds; |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 83 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 84 | if (leds < 0 || leds > 7) |
| 85 | leds = 0; // Bogus value, enable all LEDs |
| 86 | |
| 87 | if (leds == current_led_status) |
| 88 | return 0; |
| 89 | |
| 90 | /* Older Dediprogs with 2.x.x and 3.x.x firmware only had |
| 91 | * two LEDs, and they were reversed. So map them around if |
| 92 | * we have an old device. On those devices the LEDs map as |
| 93 | * follows: |
| 94 | * bit 2 == 0: green light is on. |
| 95 | * bit 0 == 0: red light is on. |
| 96 | */ |
| 97 | if (dediprog_firmwareversion < FIRMWARE_VERSION(5,0,0)) { |
| 98 | target_leds = ((leds & ERROR_OFF) >> 2) | |
| 99 | ((leds & PASS_OFF) << 2); |
| 100 | } else { |
| 101 | target_leds = leds; |
| 102 | } |
| 103 | |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 104 | ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, target_leds, |
| 105 | NULL, 0x0, DEFAULT_TIMEOUT); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 106 | if (ret != 0x0) { |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 107 | msg_perr("Command Set LED 0x%x failed (%s)!\n", |
| 108 | leds, usb_strerror()); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 109 | return 1; |
| 110 | } |
| 111 | |
| 112 | current_led_status = leds; |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 117 | static int dediprog_set_spi_voltage(int millivolt) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 118 | { |
| 119 | int ret; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 120 | uint16_t voltage_selector; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 121 | |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 122 | switch (millivolt) { |
| 123 | case 0: |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 124 | /* Admittedly this one is an assumption. */ |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 125 | voltage_selector = 0x0; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 126 | break; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 127 | case 1800: |
| 128 | voltage_selector = 0x12; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 129 | break; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 130 | case 2500: |
| 131 | voltage_selector = 0x11; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 132 | break; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 133 | case 3500: |
| 134 | voltage_selector = 0x10; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 135 | break; |
| 136 | default: |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 137 | msg_perr("Unknown voltage %i mV! Aborting.\n", millivolt); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 138 | return 1; |
| 139 | } |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 140 | msg_pdbg("Setting SPI voltage to %u.%03u V\n", millivolt / 1000, |
| 141 | millivolt % 1000); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 142 | |
Nico Huber | 4099a8a | 2012-06-16 00:02:27 +0000 | [diff] [blame] | 143 | if (voltage_selector == 0) { |
| 144 | /* Wait some time as the original driver does. */ |
| 145 | programmer_delay(200 * 1000); |
| 146 | } |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 147 | ret = usb_control_msg(dediprog_handle, 0x42, 0x9, voltage_selector, |
| 148 | 0xff, NULL, 0x0, DEFAULT_TIMEOUT); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 149 | if (ret != 0x0) { |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 150 | msg_perr("Command Set SPI Voltage 0x%x failed!\n", |
| 151 | voltage_selector); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 152 | return 1; |
| 153 | } |
Nico Huber | 4099a8a | 2012-06-16 00:02:27 +0000 | [diff] [blame] | 154 | if (voltage_selector != 0) { |
| 155 | /* Wait some time as the original driver does. */ |
| 156 | programmer_delay(200 * 1000); |
| 157 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 158 | return 0; |
| 159 | } |
| 160 | |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 161 | struct dediprog_spispeeds { |
| 162 | const char *const name; |
| 163 | const int speed; |
| 164 | }; |
| 165 | |
| 166 | static const struct dediprog_spispeeds spispeeds[] = { |
| 167 | { "24M", 0x0 }, |
| 168 | { "12M", 0x2 }, |
| 169 | { "8M", 0x1 }, |
| 170 | { "3M", 0x3 }, |
| 171 | { "2.18M", 0x4 }, |
| 172 | { "1.5M", 0x5 }, |
| 173 | { "750k", 0x6 }, |
| 174 | { "375k", 0x7 }, |
| 175 | { NULL, 0x0 }, |
| 176 | }; |
| 177 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 178 | /* After dediprog_set_spi_speed, the original app always calls |
| 179 | * dediprog_set_spi_voltage(0) and then |
| 180 | * dediprog_check_devicestring() four times in a row. |
| 181 | * After that, dediprog_command_a() is called. |
| 182 | * This looks suspiciously like the microprocessor in the SF100 has to be |
| 183 | * restarted/reinitialized in case the speed changes. |
| 184 | */ |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 185 | static int dediprog_set_spi_speed(unsigned int spispeed_idx) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 186 | { |
| 187 | int ret; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 188 | |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 189 | msg_pdbg("SPI speed is %sHz\n", spispeeds[spispeed_idx].name); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 190 | |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 191 | ret = usb_control_msg(dediprog_handle, 0x42, 0x61, spispeeds[spispeed_idx].speed, 0xff, |
| 192 | NULL, 0x0, DEFAULT_TIMEOUT); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 193 | if (ret != 0x0) { |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 194 | msg_perr("Command Set SPI Speed 0x%x failed!\n", spispeeds[spispeed_idx].speed); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 195 | return 1; |
| 196 | } |
| 197 | return 0; |
| 198 | } |
| 199 | |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 200 | /* Bulk read interface, will read multiple 512 byte chunks aligned to 512 bytes. |
| 201 | * @start start address |
| 202 | * @len length |
| 203 | * @return 0 on success, 1 on failure |
| 204 | */ |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 205 | static int dediprog_spi_bulk_read(struct flashctx *flash, uint8_t *buf, |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 206 | unsigned int start, unsigned int len) |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 207 | { |
| 208 | int ret; |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 209 | unsigned int i; |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 210 | /* chunksize must be 512, other sizes will NOT work at all. */ |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 211 | const unsigned int chunksize = 0x200; |
| 212 | const unsigned int count = len / chunksize; |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 213 | const char count_and_chunk[] = {count & 0xff, |
| 214 | (count >> 8) & 0xff, |
| 215 | chunksize & 0xff, |
| 216 | (chunksize >> 8) & 0xff}; |
| 217 | |
| 218 | if ((start % chunksize) || (len % chunksize)) { |
| 219 | msg_perr("%s: Unaligned start=%i, len=%i! Please report a bug " |
| 220 | "at flashrom@flashrom.org\n", __func__, start, len); |
| 221 | return 1; |
| 222 | } |
| 223 | |
| 224 | /* No idea if the hardware can handle empty reads, so chicken out. */ |
| 225 | if (!len) |
| 226 | return 0; |
| 227 | /* Command Read SPI Bulk. No idea which read command is used on the |
| 228 | * SPI side. |
| 229 | */ |
| 230 | ret = usb_control_msg(dediprog_handle, 0x42, 0x20, start % 0x10000, |
| 231 | start / 0x10000, (char *)count_and_chunk, |
| 232 | sizeof(count_and_chunk), DEFAULT_TIMEOUT); |
| 233 | if (ret != sizeof(count_and_chunk)) { |
| 234 | msg_perr("Command Read SPI Bulk failed, %i %s!\n", ret, |
| 235 | usb_strerror()); |
| 236 | return 1; |
| 237 | } |
| 238 | |
| 239 | for (i = 0; i < count; i++) { |
| 240 | ret = usb_bulk_read(dediprog_handle, 0x80 | dediprog_endpoint, |
| 241 | (char *)buf + i * chunksize, chunksize, |
| 242 | DEFAULT_TIMEOUT); |
| 243 | if (ret != chunksize) { |
| 244 | msg_perr("SPI bulk read %i failed, expected %i, got %i " |
| 245 | "%s!\n", i, chunksize, ret, usb_strerror()); |
| 246 | return 1; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 253 | static int dediprog_spi_read(struct flashctx *flash, uint8_t *buf, |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 254 | unsigned int start, unsigned int len) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 255 | { |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 256 | int ret; |
| 257 | /* chunksize must be 512, other sizes will NOT work at all. */ |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 258 | const unsigned int chunksize = 0x200; |
| 259 | unsigned int residue = start % chunksize ? chunksize - start % chunksize : 0; |
| 260 | unsigned int bulklen; |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 261 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 262 | dediprog_set_leds(PASS_OFF|BUSY_ON|ERROR_OFF); |
| 263 | |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 264 | if (residue) { |
| 265 | msg_pdbg("Slow read for partial block from 0x%x, length 0x%x\n", |
| 266 | start, residue); |
| 267 | ret = spi_read_chunked(flash, buf, start, residue, 16); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 268 | if (ret) { |
| 269 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 270 | return ret; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 271 | } |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* Round down. */ |
| 275 | bulklen = (len - residue) / chunksize * chunksize; |
| 276 | ret = dediprog_spi_bulk_read(flash, buf + residue, start + residue, |
| 277 | bulklen); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 278 | if (ret) { |
| 279 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 280 | return ret; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 281 | } |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 282 | |
| 283 | len -= residue + bulklen; |
| 284 | if (len) { |
| 285 | msg_pdbg("Slow read for partial block from 0x%x, length 0x%x\n", |
| 286 | start, len); |
| 287 | ret = spi_read_chunked(flash, buf + residue + bulklen, |
| 288 | start + residue + bulklen, len, 16); |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 289 | if (ret) { |
| 290 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 291 | return ret; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 292 | } |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 295 | dediprog_set_leds(PASS_ON|BUSY_OFF|ERROR_OFF); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 296 | return 0; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 299 | /* Bulk write interface, will write multiple chunksize byte chunks aligned to chunksize bytes. |
| 300 | * @chunksize length of data chunks, only 256 supported by now |
| 301 | * @start start address |
| 302 | * @len length |
| 303 | * @dedi_spi_cmd dediprog specific write command for spi bus |
| 304 | * @return 0 on success, 1 on failure |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 305 | */ |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 306 | static int dediprog_spi_bulk_write(struct flashctx *flash, uint8_t *buf, unsigned int chunksize, |
| 307 | unsigned int start, unsigned int len, uint8_t dedi_spi_cmd) |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 308 | { |
| 309 | int ret; |
| 310 | unsigned int i; |
| 311 | /* USB transfer size must be 512, other sizes will NOT work at all. |
| 312 | * chunksize is the real data size per USB bulk transfer. The remaining |
| 313 | * space in a USB bulk transfer must be filled with 0xff padding. |
| 314 | */ |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 315 | const unsigned int count = len / chunksize; |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 316 | const char count_and_cmd[] = {count & 0xff, (count >> 8) & 0xff, 0x00, dedi_spi_cmd}; |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 317 | char usbbuf[512]; |
| 318 | |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 319 | /* |
| 320 | * We should change this check to |
| 321 | * chunksize > 512 |
| 322 | * once we know how to handle different chunk sizes. |
| 323 | */ |
| 324 | if (chunksize != 256) { |
| 325 | msg_perr("%s: Chunk sizes other than 256 bytes are unsupported, chunksize=%u!\n" |
| 326 | "Please report a bug at flashrom@flashrom.org\n", __func__, chunksize); |
| 327 | return 1; |
| 328 | } |
| 329 | |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 330 | if ((start % chunksize) || (len % chunksize)) { |
| 331 | msg_perr("%s: Unaligned start=%i, len=%i! Please report a bug " |
| 332 | "at flashrom@flashrom.org\n", __func__, start, len); |
| 333 | return 1; |
| 334 | } |
| 335 | |
| 336 | /* No idea if the hardware can handle empty writes, so chicken out. */ |
| 337 | if (!len) |
| 338 | return 0; |
| 339 | /* Command Write SPI Bulk. No idea which write command is used on the |
| 340 | * SPI side. |
| 341 | */ |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 342 | ret = usb_control_msg(dediprog_handle, 0x42, 0x30, start % 0x10000, start / 0x10000, |
| 343 | (char *)count_and_cmd, sizeof(count_and_cmd), DEFAULT_TIMEOUT); |
| 344 | if (ret != sizeof(count_and_cmd)) { |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 345 | msg_perr("Command Write SPI Bulk failed, %i %s!\n", ret, |
| 346 | usb_strerror()); |
| 347 | return 1; |
| 348 | } |
| 349 | |
| 350 | for (i = 0; i < count; i++) { |
| 351 | memset(usbbuf, 0xff, sizeof(usbbuf)); |
| 352 | memcpy(usbbuf, buf + i * chunksize, chunksize); |
| 353 | ret = usb_bulk_write(dediprog_handle, dediprog_endpoint, |
| 354 | usbbuf, 512, |
| 355 | DEFAULT_TIMEOUT); |
| 356 | if (ret != 512) { |
| 357 | msg_perr("SPI bulk write failed, expected %i, got %i " |
| 358 | "%s!\n", 512, ret, usb_strerror()); |
| 359 | return 1; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 366 | static int dediprog_spi_write(struct flashctx *flash, uint8_t *buf, |
| 367 | unsigned int start, unsigned int len, uint8_t dedi_spi_cmd) |
Carl-Daniel Hailfinger | 306b818 | 2010-11-23 21:28:16 +0000 | [diff] [blame] | 368 | { |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 369 | int ret; |
Carl-Daniel Hailfinger | 5a7cb84 | 2012-08-25 01:17:58 +0000 | [diff] [blame] | 370 | const unsigned int chunksize = flash->chip->page_size; |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 371 | unsigned int residue = start % chunksize ? chunksize - start % chunksize : 0; |
| 372 | unsigned int bulklen; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 373 | |
| 374 | dediprog_set_leds(PASS_OFF|BUSY_ON|ERROR_OFF); |
| 375 | |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 376 | if (chunksize != 256) { |
| 377 | msg_pdbg("Page sizes other than 256 bytes are unsupported as " |
| 378 | "we don't know how dediprog\nhandles them.\n"); |
| 379 | /* Write everything like it was residue. */ |
| 380 | residue = len; |
| 381 | } |
| 382 | |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 383 | if (residue) { |
| 384 | msg_pdbg("Slow write for partial block from 0x%x, length 0x%x\n", |
| 385 | start, residue); |
| 386 | /* No idea about the real limit. Maybe 12, maybe more. */ |
| 387 | ret = spi_write_chunked(flash, buf, start, residue, 12); |
| 388 | if (ret) { |
| 389 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
| 390 | return ret; |
| 391 | } |
| 392 | } |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 393 | |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 394 | /* Round down. */ |
| 395 | bulklen = (len - residue) / chunksize * chunksize; |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 396 | ret = dediprog_spi_bulk_write(flash, buf + residue, chunksize, start + residue, bulklen, dedi_spi_cmd); |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 397 | if (ret) { |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 398 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 399 | return ret; |
| 400 | } |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 401 | |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 402 | len -= residue + bulklen; |
| 403 | if (len) { |
| 404 | msg_pdbg("Slow write for partial block from 0x%x, length 0x%x\n", |
| 405 | start, len); |
| 406 | ret = spi_write_chunked(flash, buf + residue + bulklen, |
| 407 | start + residue + bulklen, len, 12); |
| 408 | if (ret) { |
| 409 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
| 410 | return ret; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | dediprog_set_leds(PASS_ON|BUSY_OFF|ERROR_OFF); |
| 415 | return 0; |
Carl-Daniel Hailfinger | 306b818 | 2010-11-23 21:28:16 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 418 | static int dediprog_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) |
| 419 | { |
| 420 | return dediprog_spi_write(flash, buf, start, len, DEDI_SPI_CMD_PAGEWRITE); |
| 421 | } |
| 422 | |
| 423 | static int dediprog_spi_write_aai(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) |
| 424 | { |
| 425 | return dediprog_spi_write(flash, buf, start, len, DEDI_SPI_CMD_AAIWRITE); |
| 426 | } |
| 427 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 428 | static int dediprog_spi_send_command(struct flashctx *flash, |
| 429 | unsigned int writecnt, |
| 430 | unsigned int readcnt, |
| 431 | const unsigned char *writearr, |
| 432 | unsigned char *readarr) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 433 | { |
| 434 | int ret; |
| 435 | |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 436 | msg_pspew("%s, writecnt=%i, readcnt=%i\n", __func__, writecnt, readcnt); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 437 | /* 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] | 438 | if (writecnt > 16) { |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 439 | msg_perr("Untested writecnt=%i, aborting.\n", writecnt); |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 440 | return 1; |
| 441 | } |
| 442 | /* 16 byte reads should work. */ |
| 443 | if (readcnt > 16) { |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 444 | msg_perr("Untested readcnt=%i, aborting.\n", readcnt); |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 445 | return 1; |
| 446 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 447 | |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 448 | ret = usb_control_msg(dediprog_handle, 0x42, 0x1, 0xff, |
| 449 | readcnt ? 0x1 : 0x0, (char *)writearr, writecnt, |
| 450 | DEFAULT_TIMEOUT); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 451 | if (ret != writecnt) { |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 452 | msg_perr("Send SPI failed, expected %i, got %i %s!\n", |
| 453 | writecnt, ret, usb_strerror()); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 454 | return 1; |
| 455 | } |
| 456 | if (!readcnt) |
| 457 | return 0; |
| 458 | memset(readarr, 0, readcnt); |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 459 | ret = usb_control_msg(dediprog_handle, 0xc2, 0x01, 0xbb8, 0x0000, |
| 460 | (char *)readarr, readcnt, DEFAULT_TIMEOUT); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 461 | if (ret != readcnt) { |
Carl-Daniel Hailfinger | eac6579 | 2010-01-22 02:53:30 +0000 | [diff] [blame] | 462 | msg_perr("Receive SPI failed, expected %i, got %i %s!\n", |
| 463 | readcnt, ret, usb_strerror()); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 464 | return 1; |
| 465 | } |
| 466 | return 0; |
| 467 | } |
| 468 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 469 | static int dediprog_check_devicestring(void) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 470 | { |
| 471 | int ret; |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 472 | int fw[3]; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 473 | char buf[0x11]; |
| 474 | |
| 475 | /* Command Prepare Receive Device String. */ |
| 476 | memset(buf, 0, sizeof(buf)); |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 477 | ret = usb_control_msg(dediprog_handle, 0xc3, 0x7, 0x0, 0xef03, buf, |
| 478 | 0x1, DEFAULT_TIMEOUT); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 479 | /* The char casting is needed to stop gcc complaining about an always true comparison. */ |
| 480 | if ((ret != 0x1) || (buf[0] != (char)0xff)) { |
| 481 | msg_perr("Unexpected response to Command Prepare Receive Device" |
| 482 | " String!\n"); |
| 483 | return 1; |
| 484 | } |
| 485 | /* Command Receive Device String. */ |
| 486 | memset(buf, 0, sizeof(buf)); |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 487 | ret = usb_control_msg(dediprog_handle, 0xc2, 0x8, 0xff, 0xff, buf, |
| 488 | 0x10, DEFAULT_TIMEOUT); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 489 | if (ret != 0x10) { |
| 490 | msg_perr("Incomplete/failed Command Receive Device String!\n"); |
| 491 | return 1; |
| 492 | } |
| 493 | buf[0x10] = '\0'; |
| 494 | msg_pdbg("Found a %s\n", buf); |
| 495 | if (memcmp(buf, "SF100", 0x5)) { |
| 496 | msg_perr("Device not a SF100!\n"); |
| 497 | return 1; |
| 498 | } |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 499 | if (sscanf(buf, "SF100 V:%d.%d.%d ", &fw[0], &fw[1], &fw[2]) != 3) { |
| 500 | msg_perr("Unexpected firmware version string!\n"); |
| 501 | return 1; |
| 502 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 503 | /* Only these versions were tested. */ |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 504 | if (fw[0] < 2 || fw[0] > 5) { |
| 505 | msg_perr("Unexpected firmware version %d.%d.%d!\n", fw[0], |
| 506 | fw[1], fw[2]); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 507 | return 1; |
| 508 | } |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 509 | dediprog_firmwareversion = FIRMWARE_VERSION(fw[0], fw[1], fw[2]); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | /* Command A seems to be some sort of device init. It is either followed by |
| 514 | * dediprog_check_devicestring (often) or Command A (often) or |
| 515 | * Command F (once). |
| 516 | */ |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 517 | static int dediprog_command_a(void) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 518 | { |
| 519 | int ret; |
| 520 | char buf[0x1]; |
| 521 | |
| 522 | memset(buf, 0, sizeof(buf)); |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 523 | ret = usb_control_msg(dediprog_handle, 0xc3, 0xb, 0x0, 0x0, buf, |
| 524 | 0x1, DEFAULT_TIMEOUT); |
Mathias Krause | db7afc5 | 2010-11-09 23:30:43 +0000 | [diff] [blame] | 525 | if (ret < 0) { |
| 526 | msg_perr("Command A failed (%s)!\n", usb_strerror()); |
| 527 | return 1; |
| 528 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 529 | if ((ret != 0x1) || (buf[0] != 0x6f)) { |
| 530 | msg_perr("Unexpected response to Command A!\n"); |
| 531 | return 1; |
| 532 | } |
| 533 | return 0; |
| 534 | } |
| 535 | |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 536 | #if 0 |
| 537 | /* Something. |
| 538 | * Present in eng_detect_blink.log with firmware 3.1.8 |
| 539 | * Always preceded by Command Receive Device String |
| 540 | */ |
| 541 | static int dediprog_command_b(void) |
| 542 | { |
| 543 | int ret; |
| 544 | char buf[0x3]; |
| 545 | |
| 546 | memset(buf, 0, sizeof(buf)); |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 547 | ret = usb_control_msg(dediprog_handle, 0xc3, 0x7, 0x0, 0xef00, buf, |
| 548 | 0x3, DEFAULT_TIMEOUT); |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 549 | if (ret < 0) { |
| 550 | msg_perr("Command B failed (%s)!\n", usb_strerror()); |
| 551 | return 1; |
| 552 | } |
| 553 | if ((ret != 0x3) || (buf[0] != 0xff) || (buf[1] != 0xff) || |
| 554 | (buf[2] != 0xff)) { |
| 555 | msg_perr("Unexpected response to Command B!\n"); |
| 556 | return 1; |
| 557 | } |
| 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | #endif |
| 562 | |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame^] | 563 | /* Command Chip Select is only sent after dediprog_check_devicestring, but not after every |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 564 | * invocation of dediprog_check_devicestring. It is only sent after the first |
| 565 | * dediprog_command_a(); dediprog_check_devicestring() sequence in each session. |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame^] | 566 | * Bit #1 of the value changes the chip select: 0 is target 1, 1 is target 2 and parameter target can be 1 or 2 |
| 567 | * respectively. We don't know how to encode "3, Socket" and "0, reference card" yet. On SF100 the vendor |
| 568 | * software "DpCmd 6.0.4.06" selects target 2 when requesting 3 (which is unavailable on that hardware). |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 569 | */ |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame^] | 570 | static int dediprog_chip_select(int target) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 571 | { |
| 572 | int ret; |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame^] | 573 | uint16_t value = ((target - 1) & 1) << 1; |
| 574 | msg_pdbg("Selecting target chip %i\n", target); |
| 575 | ret = usb_control_msg(dediprog_handle, 0x42, 0x4, value, 0x0, NULL, |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 576 | 0x0, DEFAULT_TIMEOUT); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 577 | if (ret != 0x0) { |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame^] | 578 | msg_perr("Command Chip Select failed (%s)!\n", usb_strerror()); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 579 | return 1; |
| 580 | } |
| 581 | return 0; |
| 582 | } |
| 583 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 584 | #if 0 |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 585 | /* Very strange. Seems to be a programmer keepalive or somesuch. |
| 586 | * Wait unsuccessfully for timeout ms to read one byte. |
| 587 | * Is usually called after setting voltage to 0. |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 588 | * 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] | 589 | */ |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 590 | static int dediprog_command_f(int timeout) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 591 | { |
| 592 | int ret; |
| 593 | char buf[0x1]; |
| 594 | |
| 595 | memset(buf, 0, sizeof(buf)); |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 596 | ret = usb_control_msg(dediprog_handle, 0xc2, 0x11, 0xff, 0xff, buf, |
| 597 | 0x1, timeout); |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 598 | /* This check is most probably wrong. Command F always causes a timeout |
| 599 | * in the logs, so we should check for timeout instead of checking for |
| 600 | * success. |
| 601 | */ |
| 602 | if (ret != 0x1) { |
| 603 | msg_perr("Command F failed (%s)!\n", usb_strerror()); |
| 604 | return 1; |
| 605 | } |
| 606 | return 0; |
| 607 | } |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 608 | |
| 609 | /* Start/stop blinking? |
| 610 | * Present in eng_detect_blink.log with firmware 3.1.8 |
| 611 | * Preceded by Command J |
| 612 | */ |
| 613 | static int dediprog_command_g(void) |
| 614 | { |
| 615 | int ret; |
| 616 | |
| 617 | ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, 0x03, NULL, 0x0, DEFAULT_TIMEOUT); |
| 618 | if (ret != 0x0) { |
| 619 | msg_perr("Command G failed (%s)!\n", usb_strerror()); |
| 620 | return 1; |
| 621 | } |
| 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | /* Something. |
| 626 | * Present in all logs with firmware 5.1.5 |
| 627 | * Always preceded by Command Receive Device String |
| 628 | * Always followed by Command Set SPI Voltage nonzero |
| 629 | */ |
| 630 | static int dediprog_command_h(void) |
| 631 | { |
| 632 | int ret; |
| 633 | |
| 634 | ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, 0x05, NULL, 0x0, DEFAULT_TIMEOUT); |
| 635 | if (ret != 0x0) { |
| 636 | msg_perr("Command H failed (%s)!\n", usb_strerror()); |
| 637 | return 1; |
| 638 | } |
| 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | /* Shutdown for firmware 5.x? |
| 643 | * Present in all logs with firmware 5.1.5 |
| 644 | * Often preceded by a SPI operation (Command Read SPI Bulk or Receive SPI) |
| 645 | * Always followed by Command Set SPI Voltage 0x0000 |
| 646 | */ |
| 647 | static int dediprog_command_i(void) |
| 648 | { |
| 649 | int ret; |
| 650 | |
| 651 | ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, 0x06, NULL, 0x0, DEFAULT_TIMEOUT); |
| 652 | if (ret != 0x0) { |
| 653 | msg_perr("Command I failed (%s)!\n", usb_strerror()); |
| 654 | return 1; |
| 655 | } |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | /* Start/stop blinking? |
| 660 | * Present in all logs with firmware 5.1.5 |
| 661 | * Always preceded by Command Receive Device String on 5.1.5 |
| 662 | * Always followed by Command Set SPI Voltage nonzero on 5.1.5 |
| 663 | * Present in eng_detect_blink.log with firmware 3.1.8 |
| 664 | * Preceded by Command B in eng_detect_blink.log |
| 665 | * Followed by Command G in eng_detect_blink.log |
| 666 | */ |
| 667 | static int dediprog_command_j(void) |
| 668 | { |
| 669 | int ret; |
| 670 | |
| 671 | ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, 0x07, NULL, 0x0, DEFAULT_TIMEOUT); |
| 672 | if (ret != 0x0) { |
| 673 | msg_perr("Command J failed (%s)!\n", usb_strerror()); |
| 674 | return 1; |
| 675 | } |
| 676 | return 0; |
| 677 | } |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 678 | #endif |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 679 | |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 680 | static int parse_voltage(char *voltage) |
| 681 | { |
| 682 | char *tmp = NULL; |
Carl-Daniel Hailfinger | 082c8b5 | 2011-08-15 19:54:20 +0000 | [diff] [blame] | 683 | int i; |
| 684 | int millivolt = 0, fraction = 0; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 685 | |
| 686 | if (!voltage || !strlen(voltage)) { |
| 687 | msg_perr("Empty voltage= specified.\n"); |
| 688 | return -1; |
| 689 | } |
| 690 | millivolt = (int)strtol(voltage, &tmp, 0); |
| 691 | voltage = tmp; |
| 692 | /* Handle "," and "." as decimal point. Everything after it is assumed |
| 693 | * to be in decimal notation. |
| 694 | */ |
| 695 | if ((*voltage == '.') || (*voltage == ',')) { |
| 696 | voltage++; |
| 697 | for (i = 0; i < 3; i++) { |
| 698 | fraction *= 10; |
| 699 | /* Don't advance if the current character is invalid, |
| 700 | * but continue multiplying. |
| 701 | */ |
| 702 | if ((*voltage < '0') || (*voltage > '9')) |
| 703 | continue; |
| 704 | fraction += *voltage - '0'; |
| 705 | voltage++; |
| 706 | } |
| 707 | /* Throw away remaining digits. */ |
| 708 | voltage += strspn(voltage, "0123456789"); |
| 709 | } |
| 710 | /* The remaining string must be empty or "mV" or "V". */ |
| 711 | tolower_string(voltage); |
| 712 | |
| 713 | /* No unit or "V". */ |
| 714 | if ((*voltage == '\0') || !strncmp(voltage, "v", 1)) { |
| 715 | millivolt *= 1000; |
| 716 | millivolt += fraction; |
| 717 | } else if (!strncmp(voltage, "mv", 2) || |
| 718 | !strncmp(voltage, "milliv", 6)) { |
| 719 | /* No adjustment. fraction is discarded. */ |
| 720 | } else { |
| 721 | /* Garbage at the end of the string. */ |
| 722 | msg_perr("Garbage voltage= specified.\n"); |
| 723 | return -1; |
| 724 | } |
| 725 | return millivolt; |
| 726 | } |
| 727 | |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame^] | 728 | static int dediprog_setup(long target) |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 729 | { |
| 730 | /* URB 6. Command A. */ |
| 731 | if (dediprog_command_a()) { |
| 732 | return 1; |
| 733 | } |
| 734 | /* URB 7. Command A. */ |
| 735 | if (dediprog_command_a()) { |
| 736 | return 1; |
| 737 | } |
| 738 | /* URB 8. Command Prepare Receive Device String. */ |
| 739 | /* URB 9. Command Receive Device String. */ |
| 740 | if (dediprog_check_devicestring()) { |
| 741 | return 1; |
| 742 | } |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame^] | 743 | /* URB 10. Command Chip Select */ |
| 744 | if (dediprog_chip_select(target)) { |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 745 | return 1; |
| 746 | } |
| 747 | return 0; |
| 748 | } |
| 749 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 750 | static const struct spi_programmer spi_programmer_dediprog = { |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 751 | .type = SPI_CONTROLLER_DEDIPROG, |
| 752 | .max_data_read = MAX_DATA_UNSPECIFIED, |
| 753 | .max_data_write = MAX_DATA_UNSPECIFIED, |
| 754 | .command = dediprog_spi_send_command, |
| 755 | .multicommand = default_spi_send_multicommand, |
| 756 | .read = dediprog_spi_read, |
| 757 | .write_256 = dediprog_spi_write_256, |
Nico Huber | a4b14f7 | 2012-06-19 12:06:53 +0000 | [diff] [blame] | 758 | .write_aai = dediprog_spi_write_aai, |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 759 | }; |
| 760 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 761 | static int dediprog_shutdown(void *data) |
| 762 | { |
| 763 | msg_pspew("%s\n", __func__); |
| 764 | |
Carl-Daniel Hailfinger | 64204b5 | 2011-12-20 01:54:19 +0000 | [diff] [blame] | 765 | #if 0 |
| 766 | /* Shutdown on firmware 5.x */ |
| 767 | if (dediprog_firmwareversion == 5) |
| 768 | if (dediprog_command_i()) |
| 769 | return 1; |
| 770 | #endif |
| 771 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 772 | /* URB 28. Command Set SPI Voltage to 0. */ |
| 773 | if (dediprog_set_spi_voltage(0x0)) |
| 774 | return 1; |
| 775 | |
| 776 | if (usb_release_interface(dediprog_handle, 0)) { |
| 777 | msg_perr("Could not release USB interface!\n"); |
| 778 | return 1; |
| 779 | } |
| 780 | if (usb_close(dediprog_handle)) { |
| 781 | msg_perr("Could not close USB device!\n"); |
| 782 | return 1; |
| 783 | } |
| 784 | return 0; |
| 785 | } |
| 786 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 787 | /* URB numbers refer to the first log ever captured. */ |
| 788 | int dediprog_init(void) |
| 789 | { |
| 790 | struct usb_device *dev; |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame^] | 791 | char *voltage, *device, *spispeed, *target_str; |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 792 | int spispeed_idx = 2; |
Carl-Daniel Hailfinger | 082c8b5 | 2011-08-15 19:54:20 +0000 | [diff] [blame] | 793 | int millivolt = 3500; |
Nathan Laredo | 21541a6 | 2012-12-24 22:07:36 +0000 | [diff] [blame] | 794 | long usedevice = 0; |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame^] | 795 | long target = 1; |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 796 | int i, ret; |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 797 | |
| 798 | msg_pspew("%s\n", __func__); |
| 799 | |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 800 | spispeed = extract_programmer_param("spispeed"); |
| 801 | if (spispeed) { |
| 802 | for (i = 0; spispeeds[i].name; ++i) { |
| 803 | if (!strcasecmp(spispeeds[i].name, spispeed)) { |
| 804 | spispeed_idx = i; |
| 805 | break; |
| 806 | } |
| 807 | } |
| 808 | if (!spispeeds[i].name) { |
| 809 | msg_perr("Error: Invalid 'spispeed' value.\n"); |
| 810 | free(spispeed); |
| 811 | return 1; |
| 812 | } |
| 813 | free(spispeed); |
| 814 | } |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 815 | voltage = extract_programmer_param("voltage"); |
| 816 | if (voltage) { |
| 817 | millivolt = parse_voltage(voltage); |
| 818 | free(voltage); |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 819 | if (millivolt < 0) |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 820 | return 1; |
Carl-Daniel Hailfinger | c244138 | 2010-11-09 22:00:31 +0000 | [diff] [blame] | 821 | msg_pinfo("Setting voltage to %i mV\n", millivolt); |
| 822 | } |
| 823 | |
Nathan Laredo | 21541a6 | 2012-12-24 22:07:36 +0000 | [diff] [blame] | 824 | device = extract_programmer_param("device"); |
| 825 | if (device) { |
| 826 | char *dev_suffix; |
| 827 | errno = 0; |
| 828 | usedevice = strtol(device, &dev_suffix, 10); |
| 829 | if (errno != 0 || device == dev_suffix) { |
| 830 | msg_perr("Error: Could not convert 'device'.\n"); |
| 831 | free(device); |
| 832 | return 1; |
| 833 | } |
| 834 | if (usedevice < 0 || usedevice > UINT_MAX) { |
| 835 | msg_perr("Error: Value for 'device' is out of range.\n"); |
| 836 | free(device); |
| 837 | return 1; |
| 838 | } |
| 839 | if (strlen(dev_suffix) > 0) { |
| 840 | msg_perr("Error: Garbage following 'device' value.\n"); |
| 841 | free(device); |
| 842 | return 1; |
| 843 | } |
| 844 | msg_pinfo("Using device %li.\n", usedevice); |
| 845 | } |
| 846 | free(device); |
| 847 | |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame^] | 848 | target_str = extract_programmer_param("target"); |
| 849 | if (target_str) { |
| 850 | char *target_suffix; |
| 851 | errno = 0; |
| 852 | target = strtol(target_str, &target_suffix, 10); |
| 853 | if (errno != 0 || target_str == target_suffix) { |
| 854 | msg_perr("Error: Could not convert 'target'.\n"); |
| 855 | free(target_str); |
| 856 | return 1; |
| 857 | } |
| 858 | if (target < 1 || target > 2) { |
| 859 | msg_perr("Error: Value for 'target' is out of range.\n"); |
| 860 | free(target_str); |
| 861 | return 1; |
| 862 | } |
| 863 | if (strlen(target_suffix) > 0) { |
| 864 | msg_perr("Error: Garbage following 'target' value.\n"); |
| 865 | free(target_str); |
| 866 | return 1; |
| 867 | } |
| 868 | msg_pinfo("Using target %li.\n", target); |
| 869 | } |
| 870 | free(target_str); |
| 871 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 872 | /* Here comes the USB stuff. */ |
| 873 | usb_init(); |
| 874 | usb_find_busses(); |
| 875 | usb_find_devices(); |
Nathan Laredo | 21541a6 | 2012-12-24 22:07:36 +0000 | [diff] [blame] | 876 | dev = get_device_by_vid_pid(0x0483, 0xdada, (unsigned int) usedevice); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 877 | if (!dev) { |
| 878 | msg_perr("Could not find a Dediprog SF100 on USB!\n"); |
| 879 | return 1; |
| 880 | } |
| 881 | msg_pdbg("Found USB device (%04x:%04x).\n", |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 882 | dev->descriptor.idVendor, dev->descriptor.idProduct); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 883 | dediprog_handle = usb_open(dev); |
Carl-Daniel Hailfinger | 482e974 | 2010-11-16 21:25:29 +0000 | [diff] [blame] | 884 | ret = usb_set_configuration(dediprog_handle, 1); |
| 885 | if (ret < 0) { |
| 886 | msg_perr("Could not set USB device configuration: %i %s\n", |
| 887 | ret, usb_strerror()); |
| 888 | if (usb_close(dediprog_handle)) |
| 889 | msg_perr("Could not close USB device!\n"); |
| 890 | return 1; |
| 891 | } |
| 892 | ret = usb_claim_interface(dediprog_handle, 0); |
| 893 | if (ret < 0) { |
| 894 | msg_perr("Could not claim USB device interface %i: %i %s\n", |
| 895 | 0, ret, usb_strerror()); |
| 896 | if (usb_close(dediprog_handle)) |
| 897 | msg_perr("Could not close USB device!\n"); |
| 898 | return 1; |
| 899 | } |
| 900 | dediprog_endpoint = 2; |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 901 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 902 | if (register_shutdown(dediprog_shutdown, NULL)) |
| 903 | return 1; |
| 904 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 905 | dediprog_set_leds(PASS_ON|BUSY_ON|ERROR_ON); |
| 906 | |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 907 | /* Perform basic setup. */ |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame^] | 908 | if (dediprog_setup(target)) { |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 909 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 910 | return 1; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 911 | } |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 912 | |
| 913 | /* After setting voltage and speed, perform setup again. */ |
Stefan Tauner | e659d2d | 2013-05-03 21:58:28 +0000 | [diff] [blame^] | 914 | if (dediprog_set_spi_voltage(0) || dediprog_set_spi_speed(spispeed_idx) || dediprog_setup(target)) { |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 915 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 916 | return 1; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 917 | } |
Nico Huber | 77fa67d | 2013-02-20 18:03:36 +0000 | [diff] [blame] | 918 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 919 | /* URB 11. Command Set SPI Voltage. */ |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 920 | if (dediprog_set_spi_voltage(millivolt)) { |
| 921 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_ON); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 922 | return 1; |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 923 | } |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 924 | |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 925 | register_spi_programmer(&spi_programmer_dediprog); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 926 | |
| 927 | /* RE leftover, leave in until the driver is complete. */ |
| 928 | #if 0 |
| 929 | /* Execute RDID by hand if you want to test it. */ |
| 930 | dediprog_do_stuff(); |
| 931 | #endif |
| 932 | |
Stefan Reinauer | 915b840 | 2011-01-28 09:00:15 +0000 | [diff] [blame] | 933 | dediprog_set_leds(PASS_OFF|BUSY_OFF|ERROR_OFF); |
| 934 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 935 | return 0; |
| 936 | } |
| 937 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 938 | #if 0 |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 939 | /* Leftovers from reverse engineering. Keep for documentation purposes until |
| 940 | * completely understood. |
| 941 | */ |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 942 | static int dediprog_do_stuff(void) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 943 | { |
| 944 | char buf[0x4]; |
| 945 | /* SPI command processing starts here. */ |
| 946 | |
| 947 | /* URB 12. Command Send SPI. */ |
| 948 | /* URB 13. Command Receive SPI. */ |
| 949 | memset(buf, 0, sizeof(buf)); |
| 950 | /* JEDEC RDID */ |
| 951 | msg_pdbg("Sending RDID\n"); |
| 952 | buf[0] = JEDEC_RDID; |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 953 | if (dediprog_spi_send_command(JEDEC_RDID_OUTSIZE, JEDEC_RDID_INSIZE, |
| 954 | (unsigned char *)buf, (unsigned char *)buf)) |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 955 | return 1; |
| 956 | msg_pdbg("Receiving response: "); |
| 957 | print_hex(buf, JEDEC_RDID_INSIZE); |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 958 | /* URB 14-27 are more SPI commands. */ |
| 959 | /* URB 28. Command Set SPI Voltage. */ |
| 960 | if (dediprog_set_spi_voltage(0x0)) |
| 961 | return 1; |
| 962 | /* URB 29-38. Command F, unsuccessful wait. */ |
| 963 | if (dediprog_command_f(544)) |
| 964 | return 1; |
| 965 | /* URB 39. Command Set SPI Voltage. */ |
| 966 | if (dediprog_set_spi_voltage(0x10)) |
| 967 | return 1; |
| 968 | /* URB 40. Command Set SPI Speed. */ |
| 969 | if (dediprog_set_spi_speed(0x2)) |
| 970 | return 1; |
| 971 | /* URB 41 is just URB 28. */ |
| 972 | /* URB 42,44,46,48,51,53 is just URB 8. */ |
| 973 | /* URB 43,45,47,49,52,54 is just URB 9. */ |
| 974 | /* URB 50 is just URB 6/7. */ |
| 975 | /* URB 55-131 is just URB 29-38. (wait unsuccessfully for 4695 (maybe 4751) ms)*/ |
| 976 | /* URB 132,134 is just URB 6/7. */ |
| 977 | /* URB 133 is just URB 29-38. */ |
| 978 | /* URB 135 is just URB 8. */ |
| 979 | /* URB 136 is just URB 9. */ |
| 980 | /* URB 137 is just URB 11. */ |
| 981 | |
Carl-Daniel Hailfinger | ff30d8a | 2011-01-20 21:05:15 +0000 | [diff] [blame] | 982 | /* Command Start Bulk Read. Data is u16 blockcount, u16 blocksize. */ |
| 983 | /* Command Start Bulk Write. Data is u16 blockcount, u16 blocksize. */ |
| 984 | /* Bulk transfer sizes for Command Start Bulk Read/Write are always |
| 985 | * 512 bytes, rest is filled with 0xff. |
| 986 | */ |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 987 | |
Carl-Daniel Hailfinger | d38fac8 | 2010-01-19 11:15:48 +0000 | [diff] [blame] | 988 | return 0; |
| 989 | } |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 990 | #endif |