Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright 2014, Google Inc. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions are |
| 9 | * met: |
| 10 | * |
| 11 | * * Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * * Redistributions in binary form must reproduce the above |
| 14 | * copyright notice, this list of conditions and the following disclaimer |
| 15 | * in the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * * Neither the name of Google Inc. nor the names of its |
| 18 | * contributors may be used to endorse or promote products derived from |
| 19 | * this software without specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | * |
| 33 | * Alternatively, this software may be distributed under the terms of the |
| 34 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 35 | * Software Foundation. |
| 36 | */ |
| 37 | |
| 38 | /* |
| 39 | * This SPI flash programming interface is designed to talk to a Chromium OS |
| 40 | * device over a Raiden USB connection. The USB connection is routed to a |
| 41 | * microcontroller running an image compiled from: |
| 42 | * |
| 43 | * https://chromium.googlesource.com/chromiumos/platform/ec |
| 44 | * |
| 45 | * The protocol for the USB-SPI bridge is documented in the following file in |
| 46 | * that respository: |
| 47 | * |
| 48 | * chip/stm32/usb_spi.c |
| 49 | */ |
| 50 | |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 51 | #include "check.h" |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 52 | #include "programmer.h" |
| 53 | #include "spi.h" |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 54 | #include "usb_device.h" |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 55 | |
| 56 | #include <libusb.h> |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 57 | #include <stdio.h> |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 58 | #include <stdlib.h> |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 59 | #include <string.h> |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 60 | |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 61 | #define GOOGLE_VID 0x18D1 |
| 62 | #define GOOGLE_RAIDEN_SPI_SUBCLASS 0x51 |
| 63 | #define GOOGLE_RAIDEN_SPI_PROTOCOL 0x01 |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 64 | |
Anton Staaf | 4589cd1 | 2015-03-23 13:36:44 -0700 | [diff] [blame] | 65 | enum raiden_debug_spi_request { |
Mary Ruthven | eafafd8 | 2016-05-03 14:33:53 -0700 | [diff] [blame] | 66 | RAIDEN_DEBUG_SPI_REQ_ENABLE = 0x0000, |
| 67 | RAIDEN_DEBUG_SPI_REQ_DISABLE = 0x0001, |
| 68 | RAIDEN_DEBUG_SPI_REQ_ENABLE_AP = 0x0002, |
| 69 | RAIDEN_DEBUG_SPI_REQ_ENABLE_EC = 0x0003, |
Anton Staaf | 4589cd1 | 2015-03-23 13:36:44 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Anton Staaf | d27536d | 2014-09-30 08:10:17 -0700 | [diff] [blame] | 72 | #define PACKET_HEADER_SIZE 2 |
| 73 | #define MAX_PACKET_SIZE 64 |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * This timeout is so large because the Raiden SPI timeout is 800ms. |
| 77 | */ |
| 78 | #define TRANSFER_TIMEOUT_MS 1000 |
| 79 | |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 80 | struct usb_device *device = NULL; |
| 81 | uint8_t in_endpoint = 0; |
| 82 | uint8_t out_endpoint = 0; |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 83 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 84 | static int send_command(const struct flashctx *flash, |
| 85 | unsigned int write_count, |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 86 | unsigned int read_count, |
| 87 | const unsigned char *write_buffer, |
| 88 | unsigned char *read_buffer) |
| 89 | { |
| 90 | uint8_t buffer[MAX_PACKET_SIZE]; |
| 91 | int transferred; |
| 92 | |
| 93 | if (write_count > MAX_PACKET_SIZE - PACKET_HEADER_SIZE) { |
| 94 | msg_perr("Raiden: invalid write_count of %d\n", write_count); |
| 95 | return SPI_INVALID_LENGTH; |
| 96 | } |
| 97 | |
| 98 | if (read_count > MAX_PACKET_SIZE - PACKET_HEADER_SIZE) { |
| 99 | msg_perr("Raiden: invalid read_count of %d\n", read_count); |
| 100 | return SPI_INVALID_LENGTH; |
| 101 | } |
| 102 | |
| 103 | buffer[0] = write_count; |
| 104 | buffer[1] = read_count; |
| 105 | |
| 106 | memcpy(buffer + PACKET_HEADER_SIZE, write_buffer, write_count); |
| 107 | |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 108 | CHECK(LIBUSB(libusb_bulk_transfer(device->handle, |
| 109 | out_endpoint, |
| 110 | buffer, |
| 111 | write_count + PACKET_HEADER_SIZE, |
| 112 | &transferred, |
| 113 | TRANSFER_TIMEOUT_MS)), |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 114 | "Raiden: OUT transfer failed\n" |
| 115 | " write_count = %d\n" |
| 116 | " read_count = %d\n", |
| 117 | write_count, |
| 118 | read_count); |
| 119 | |
| 120 | if (transferred != write_count + PACKET_HEADER_SIZE) { |
| 121 | msg_perr("Raiden: Write failure (wrote %d, expected %d)\n", |
| 122 | transferred, write_count + PACKET_HEADER_SIZE); |
| 123 | return 0x10001; |
| 124 | } |
| 125 | |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 126 | CHECK(LIBUSB(libusb_bulk_transfer(device->handle, |
| 127 | in_endpoint, |
| 128 | buffer, |
| 129 | read_count + PACKET_HEADER_SIZE, |
| 130 | &transferred, |
| 131 | TRANSFER_TIMEOUT_MS)), |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 132 | "Raiden: IN transfer failed\n" |
| 133 | " write_count = %d\n" |
| 134 | " read_count = %d\n", |
| 135 | write_count, |
| 136 | read_count); |
| 137 | |
| 138 | if (transferred != read_count + PACKET_HEADER_SIZE) { |
| 139 | msg_perr("Raiden: Read failure (read %d, expected %d)\n", |
| 140 | transferred, read_count + PACKET_HEADER_SIZE); |
| 141 | return 0x10002; |
| 142 | } |
| 143 | |
| 144 | memcpy(read_buffer, buffer + PACKET_HEADER_SIZE, read_count); |
| 145 | |
| 146 | return buffer[0] | (buffer[1] << 8); |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | * Unfortunately there doesn't seem to be a way to specify the maximum number |
| 151 | * of bytes that your SPI device can read/write, these values are the maximum |
Duncan Laurie | 537fd1d | 2018-10-05 10:53:20 -0700 | [diff] [blame] | 152 | * data chunk size that flashrom will package up with an additional five bytes |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 153 | * of command for the flash device, resulting in a 62 byte packet, that we then |
| 154 | * add two bytes to in either direction, making our way up to the 64 byte |
| 155 | * maximum USB packet size for the device. |
| 156 | * |
| 157 | * The largest command that flashrom generates is the byte program command, so |
Duncan Laurie | 537fd1d | 2018-10-05 10:53:20 -0700 | [diff] [blame] | 158 | * we use that command header maximum size here. |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 159 | */ |
| 160 | #define MAX_DATA_SIZE (MAX_PACKET_SIZE - \ |
| 161 | PACKET_HEADER_SIZE - \ |
Duncan Laurie | 537fd1d | 2018-10-05 10:53:20 -0700 | [diff] [blame] | 162 | JEDEC_BYTE_PROGRAM_OUTSIZE) |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 163 | |
Patrick Georgi | f4f1e2f | 2017-03-10 17:38:40 +0100 | [diff] [blame] | 164 | static const struct spi_master spi_master_raiden_debug = { |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 165 | .type = SPI_CONTROLLER_RAIDEN_DEBUG, |
Mathew King | bd9670f | 2019-08-07 14:17:48 -0600 | [diff] [blame] | 166 | .features = SPI_MASTER_4BA, |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 167 | .max_data_read = MAX_DATA_SIZE, |
| 168 | .max_data_write = MAX_DATA_SIZE, |
| 169 | .command = send_command, |
| 170 | .multicommand = default_spi_send_multicommand, |
| 171 | .read = default_spi_read, |
| 172 | .write_256 = default_spi_write_256, |
| 173 | }; |
| 174 | |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 175 | static int match_endpoint(struct libusb_endpoint_descriptor const *descriptor, |
| 176 | enum libusb_endpoint_direction direction) |
Anton Staaf | d27536d | 2014-09-30 08:10:17 -0700 | [diff] [blame] | 177 | { |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 178 | return (((descriptor->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) == |
| 179 | direction) && |
| 180 | ((descriptor->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) == |
| 181 | LIBUSB_TRANSFER_TYPE_BULK)); |
| 182 | } |
Anton Staaf | d27536d | 2014-09-30 08:10:17 -0700 | [diff] [blame] | 183 | |
Edward O'Callaghan | dabf7e8 | 2019-11-19 15:11:18 +1100 | [diff] [blame^] | 184 | static int find_endpoints(struct usb_device *dev, uint8_t *in_ep, uint8_t *out_ep) |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 185 | { |
| 186 | int i; |
| 187 | int in_count = 0; |
| 188 | int out_count = 0; |
Anton Staaf | d27536d | 2014-09-30 08:10:17 -0700 | [diff] [blame] | 189 | |
Edward O'Callaghan | dabf7e8 | 2019-11-19 15:11:18 +1100 | [diff] [blame^] | 190 | for (i = 0; i < dev->interface_descriptor->bNumEndpoints; i++) { |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 191 | struct libusb_endpoint_descriptor const *endpoint = |
Edward O'Callaghan | dabf7e8 | 2019-11-19 15:11:18 +1100 | [diff] [blame^] | 192 | &dev->interface_descriptor->endpoint[i]; |
Anton Staaf | d27536d | 2014-09-30 08:10:17 -0700 | [diff] [blame] | 193 | |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 194 | if (match_endpoint(endpoint, LIBUSB_ENDPOINT_IN)) { |
| 195 | in_count++; |
Edward O'Callaghan | dabf7e8 | 2019-11-19 15:11:18 +1100 | [diff] [blame^] | 196 | *in_ep = endpoint->bEndpointAddress; |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 197 | } else if (match_endpoint(endpoint, LIBUSB_ENDPOINT_OUT)) { |
| 198 | out_count++; |
Edward O'Callaghan | dabf7e8 | 2019-11-19 15:11:18 +1100 | [diff] [blame^] | 199 | *out_ep = endpoint->bEndpointAddress; |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
| 203 | if (in_count != 1 || out_count != 1) { |
| 204 | msg_perr("Raiden: Failed to find one IN and one OUT endpoint\n" |
| 205 | " found %d IN and %d OUT endpoints\n", |
| 206 | in_count, |
| 207 | out_count); |
| 208 | return 1; |
| 209 | } |
| 210 | |
Edward O'Callaghan | dabf7e8 | 2019-11-19 15:11:18 +1100 | [diff] [blame^] | 211 | msg_pdbg("Raiden: Found IN endpoint = 0x%02x\n", *in_ep); |
| 212 | msg_pdbg("Raiden: Found OUT endpoint = 0x%02x\n", *out_ep); |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 213 | |
| 214 | return 0; |
Anton Staaf | d27536d | 2014-09-30 08:10:17 -0700 | [diff] [blame] | 215 | } |
| 216 | |
David Hendricks | 93784b4 | 2016-08-09 17:00:38 -0700 | [diff] [blame] | 217 | static int shutdown(void * data) |
Anton Staaf | 4589cd1 | 2015-03-23 13:36:44 -0700 | [diff] [blame] | 218 | { |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 219 | CHECK(LIBUSB(libusb_control_transfer( |
| 220 | device->handle, |
| 221 | LIBUSB_ENDPOINT_OUT | |
| 222 | LIBUSB_REQUEST_TYPE_VENDOR | |
| 223 | LIBUSB_RECIPIENT_INTERFACE, |
| 224 | RAIDEN_DEBUG_SPI_REQ_DISABLE, |
| 225 | 0, |
| 226 | device->interface_descriptor->bInterfaceNumber, |
| 227 | NULL, |
| 228 | 0, |
| 229 | TRANSFER_TIMEOUT_MS)), |
Anton Staaf | 4589cd1 | 2015-03-23 13:36:44 -0700 | [diff] [blame] | 230 | "Raiden: Failed to disable SPI bridge\n"); |
| 231 | |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 232 | usb_device_free(device); |
| 233 | |
| 234 | device = NULL; |
Anton Staaf | 4589cd1 | 2015-03-23 13:36:44 -0700 | [diff] [blame] | 235 | libusb_exit(NULL); |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
David Hendricks | ac1d25c | 2016-08-09 17:00:58 -0700 | [diff] [blame] | 240 | int raiden_debug_spi_init(void) |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 241 | { |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 242 | struct usb_match match; |
Mary Ruthven | eafafd8 | 2016-05-03 14:33:53 -0700 | [diff] [blame] | 243 | int request_enable = RAIDEN_DEBUG_SPI_REQ_ENABLE; |
| 244 | char *target_str = extract_programmer_param("target"); |
David Hendricks | 5c79a49 | 2016-06-14 20:56:36 -0700 | [diff] [blame] | 245 | char *serial = extract_programmer_param("serial"); |
| 246 | struct usb_device *current; |
| 247 | int found = 0; |
Mary Ruthven | eafafd8 | 2016-05-03 14:33:53 -0700 | [diff] [blame] | 248 | |
| 249 | if (target_str) { |
| 250 | if (!strcasecmp(target_str, "ap")) |
| 251 | request_enable = RAIDEN_DEBUG_SPI_REQ_ENABLE_AP; |
| 252 | else if (!strcasecmp(target_str, "ec")) |
| 253 | request_enable = RAIDEN_DEBUG_SPI_REQ_ENABLE_EC; |
| 254 | else { |
| 255 | msg_perr("Invalid target: %s\n", target_str); |
| 256 | free(target_str); |
David Hendricks | 98b3c57 | 2016-11-30 01:50:08 +0000 | [diff] [blame] | 257 | return 1; |
Mary Ruthven | eafafd8 | 2016-05-03 14:33:53 -0700 | [diff] [blame] | 258 | } |
| 259 | } |
David Hendricks | 98b3c57 | 2016-11-30 01:50:08 +0000 | [diff] [blame] | 260 | free(target_str); |
Anton Staaf | d27536d | 2014-09-30 08:10:17 -0700 | [diff] [blame] | 261 | |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 262 | usb_match_init(&match); |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 263 | |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 264 | usb_match_value_default(&match.vid, GOOGLE_VID); |
| 265 | usb_match_value_default(&match.class, LIBUSB_CLASS_VENDOR_SPEC); |
| 266 | usb_match_value_default(&match.subclass, GOOGLE_RAIDEN_SPI_SUBCLASS); |
| 267 | usb_match_value_default(&match.protocol, GOOGLE_RAIDEN_SPI_PROTOCOL); |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 268 | |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 269 | CHECK(LIBUSB(libusb_init(NULL)), "Raiden: libusb_init failed\n"); |
| 270 | |
David Hendricks | 5c79a49 | 2016-06-14 20:56:36 -0700 | [diff] [blame] | 271 | CHECK(usb_device_find(&match, ¤t), |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 272 | "Raiden: Failed to find devices\n"); |
| 273 | |
David Hendricks | 5c79a49 | 2016-06-14 20:56:36 -0700 | [diff] [blame] | 274 | while (current) { |
| 275 | device = current; |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 276 | |
Edward O'Callaghan | dabf7e8 | 2019-11-19 15:11:18 +1100 | [diff] [blame^] | 277 | if (find_endpoints(device, &in_endpoint, &out_endpoint)) { |
David Hendricks | 5c79a49 | 2016-06-14 20:56:36 -0700 | [diff] [blame] | 278 | msg_pdbg("Raiden: Failed to find valid endpoints on device"); |
| 279 | usb_device_show(" ", current); |
| 280 | goto loop_end; |
| 281 | } |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 282 | |
David Hendricks | 5c79a49 | 2016-06-14 20:56:36 -0700 | [diff] [blame] | 283 | if (usb_device_claim(device)) { |
| 284 | msg_pdbg("Raiden: Failed to claim USB device"); |
| 285 | usb_device_show(" ", current); |
| 286 | goto loop_end; |
| 287 | } |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 288 | |
David Hendricks | 5c79a49 | 2016-06-14 20:56:36 -0700 | [diff] [blame] | 289 | if (!serial) { |
| 290 | found = 1; |
| 291 | goto loop_end; |
| 292 | } else { |
| 293 | unsigned char dev_serial[32]; |
| 294 | struct libusb_device_descriptor descriptor; |
| 295 | int rc; |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 296 | |
David Hendricks | 5c79a49 | 2016-06-14 20:56:36 -0700 | [diff] [blame] | 297 | memset(dev_serial, 0, sizeof(dev_serial)); |
| 298 | |
| 299 | if (libusb_get_device_descriptor(device->device, &descriptor)) { |
| 300 | msg_pdbg("USB: Failed to get device descriptor.\n"); |
| 301 | goto loop_end; |
| 302 | } |
| 303 | |
| 304 | rc = libusb_get_string_descriptor_ascii(device->handle, |
| 305 | descriptor.iSerialNumber, |
| 306 | dev_serial, |
| 307 | sizeof(dev_serial)); |
| 308 | if (rc < 0) { |
| 309 | LIBUSB(rc); |
| 310 | } else { |
| 311 | if (strcmp(serial, (char *)dev_serial)) { |
| 312 | msg_pdbg("Raiden: Serial number %s did not match device", serial); |
| 313 | usb_device_show(" ", current); |
| 314 | } else { |
| 315 | msg_pinfo("Raiden: Serial number %s matched device", serial); |
| 316 | usb_device_show(" ", current); |
| 317 | found = 1; |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | loop_end: |
| 323 | if (found) |
| 324 | break; |
| 325 | else |
| 326 | current = usb_device_free(current); |
| 327 | } |
| 328 | |
| 329 | if (!device || !found) { |
| 330 | msg_perr("Raiden: No usable device found.\n"); |
David Hendricks | 98b3c57 | 2016-11-30 01:50:08 +0000 | [diff] [blame] | 331 | return 1; |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 332 | } |
| 333 | |
David Hendricks | 5c79a49 | 2016-06-14 20:56:36 -0700 | [diff] [blame] | 334 | /* free devices we don't care about */ |
| 335 | current = current->next; |
| 336 | while (current) |
| 337 | current = usb_device_free(current); |
Anton Staaf | b4661ee | 2014-10-21 11:24:36 -0700 | [diff] [blame] | 338 | |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 339 | CHECK(LIBUSB(libusb_control_transfer( |
| 340 | device->handle, |
| 341 | LIBUSB_ENDPOINT_OUT | |
| 342 | LIBUSB_REQUEST_TYPE_VENDOR | |
| 343 | LIBUSB_RECIPIENT_INTERFACE, |
Mary Ruthven | eafafd8 | 2016-05-03 14:33:53 -0700 | [diff] [blame] | 344 | request_enable, |
Anton Staaf | 5614e25 | 2015-03-24 14:33:33 -0700 | [diff] [blame] | 345 | 0, |
| 346 | device->interface_descriptor->bInterfaceNumber, |
| 347 | NULL, |
| 348 | 0, |
| 349 | TRANSFER_TIMEOUT_MS)), |
Anton Staaf | 4589cd1 | 2015-03-23 13:36:44 -0700 | [diff] [blame] | 350 | "Raiden: Failed to enable SPI bridge\n"); |
| 351 | |
Patrick Georgi | f4f1e2f | 2017-03-10 17:38:40 +0100 | [diff] [blame] | 352 | register_spi_master(&spi_master_raiden_debug); |
Anton Staaf | 4589cd1 | 2015-03-23 13:36:44 -0700 | [diff] [blame] | 353 | register_shutdown(shutdown, NULL); |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 354 | |
David Hendricks | 98b3c57 | 2016-11-30 01:50:08 +0000 | [diff] [blame] | 355 | return 0; |
Anton Staaf | b264788 | 2014-09-17 15:13:43 -0700 | [diff] [blame] | 356 | } |