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