| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Linux driver for TerraTec DMX 6Fire USB |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 6 | 7 | * Author: Torsten Schenk <torsten.schenk@zoho.com> |
|---|
| 7 | 8 | * Created: Jan 01, 2011 |
|---|
| 8 | 9 | * Copyright: (C) Torsten Schenk |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 12 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 13 | | - * (at your option) any later version. |
|---|
| 14 | 10 | */ |
|---|
| 15 | 11 | |
|---|
| 16 | 12 | #include <linux/firmware.h> |
|---|
| .. | .. |
|---|
| 162 | 158 | static int usb6fire_fw_ezusb_write(struct usb_device *device, |
|---|
| 163 | 159 | int type, int value, char *data, int len) |
|---|
| 164 | 160 | { |
|---|
| 165 | | - int ret; |
|---|
| 166 | | - |
|---|
| 167 | | - ret = usb_control_msg(device, usb_sndctrlpipe(device, 0), type, |
|---|
| 168 | | - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
|---|
| 169 | | - value, 0, data, len, 1000); |
|---|
| 170 | | - if (ret < 0) |
|---|
| 171 | | - return ret; |
|---|
| 172 | | - else if (ret != len) |
|---|
| 173 | | - return -EIO; |
|---|
| 174 | | - return 0; |
|---|
| 161 | + return usb_control_msg_send(device, 0, type, |
|---|
| 162 | + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
|---|
| 163 | + value, 0, data, len, 1000, GFP_KERNEL); |
|---|
| 175 | 164 | } |
|---|
| 176 | 165 | |
|---|
| 177 | 166 | static int usb6fire_fw_ezusb_read(struct usb_device *device, |
|---|
| 178 | 167 | int type, int value, char *data, int len) |
|---|
| 179 | 168 | { |
|---|
| 180 | | - int ret = usb_control_msg(device, usb_rcvctrlpipe(device, 0), type, |
|---|
| 181 | | - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, value, |
|---|
| 182 | | - 0, data, len, 1000); |
|---|
| 183 | | - if (ret < 0) |
|---|
| 184 | | - return ret; |
|---|
| 185 | | - else if (ret != len) |
|---|
| 186 | | - return -EIO; |
|---|
| 187 | | - return 0; |
|---|
| 169 | + return usb_control_msg_recv(device, 0, type, |
|---|
| 170 | + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
|---|
| 171 | + value, 0, data, len, 1000, GFP_KERNEL); |
|---|
| 188 | 172 | } |
|---|
| 189 | 173 | |
|---|
| 190 | 174 | static int usb6fire_fw_fpga_write(struct usb_device *device, |
|---|
| .. | .. |
|---|
| 234 | 218 | /* upload firmware image */ |
|---|
| 235 | 219 | data = 0x01; /* stop ezusb cpu */ |
|---|
| 236 | 220 | ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1); |
|---|
| 237 | | - if (ret < 0) { |
|---|
| 221 | + if (ret) { |
|---|
| 238 | 222 | kfree(rec); |
|---|
| 239 | 223 | release_firmware(fw); |
|---|
| 240 | 224 | dev_err(&intf->dev, |
|---|
| .. | .. |
|---|
| 246 | 230 | while (usb6fire_fw_ihex_next_record(rec)) { /* write firmware */ |
|---|
| 247 | 231 | ret = usb6fire_fw_ezusb_write(device, 0xa0, rec->address, |
|---|
| 248 | 232 | rec->data, rec->len); |
|---|
| 249 | | - if (ret < 0) { |
|---|
| 233 | + if (ret) { |
|---|
| 250 | 234 | kfree(rec); |
|---|
| 251 | 235 | release_firmware(fw); |
|---|
| 252 | 236 | dev_err(&intf->dev, |
|---|
| .. | .. |
|---|
| 261 | 245 | if (postdata) { /* write data after firmware has been uploaded */ |
|---|
| 262 | 246 | ret = usb6fire_fw_ezusb_write(device, 0xa0, postaddr, |
|---|
| 263 | 247 | postdata, postlen); |
|---|
| 264 | | - if (ret < 0) { |
|---|
| 248 | + if (ret) { |
|---|
| 265 | 249 | dev_err(&intf->dev, |
|---|
| 266 | 250 | "unable to upload ezusb firmware %s: post urb.\n", |
|---|
| 267 | 251 | fwname); |
|---|
| .. | .. |
|---|
| 271 | 255 | |
|---|
| 272 | 256 | data = 0x00; /* resume ezusb cpu */ |
|---|
| 273 | 257 | ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1); |
|---|
| 274 | | - if (ret < 0) { |
|---|
| 258 | + if (ret) { |
|---|
| 275 | 259 | dev_err(&intf->dev, |
|---|
| 276 | 260 | "unable to upload ezusb firmware %s: end message.\n", |
|---|
| 277 | 261 | fwname); |
|---|
| .. | .. |
|---|
| 306 | 290 | end = fw->data + fw->size; |
|---|
| 307 | 291 | |
|---|
| 308 | 292 | ret = usb6fire_fw_ezusb_write(device, 8, 0, NULL, 0); |
|---|
| 309 | | - if (ret < 0) { |
|---|
| 293 | + if (ret) { |
|---|
| 310 | 294 | kfree(buffer); |
|---|
| 311 | 295 | release_firmware(fw); |
|---|
| 312 | 296 | dev_err(&intf->dev, |
|---|
| .. | .. |
|---|
| 331 | 315 | kfree(buffer); |
|---|
| 332 | 316 | |
|---|
| 333 | 317 | ret = usb6fire_fw_ezusb_write(device, 9, 0, NULL, 0); |
|---|
| 334 | | - if (ret < 0) { |
|---|
| 318 | + if (ret) { |
|---|
| 335 | 319 | dev_err(&intf->dev, |
|---|
| 336 | 320 | "unable to upload fpga firmware: end urb.\n"); |
|---|
| 337 | 321 | return ret; |
|---|
| .. | .. |
|---|
| 367 | 351 | u8 buffer[12]; |
|---|
| 368 | 352 | |
|---|
| 369 | 353 | ret = usb6fire_fw_ezusb_read(device, 1, 0, buffer, 8); |
|---|
| 370 | | - if (ret < 0) { |
|---|
| 354 | + if (ret) { |
|---|
| 371 | 355 | dev_err(&intf->dev, |
|---|
| 372 | 356 | "unable to receive device firmware state.\n"); |
|---|
| 373 | 357 | return ret; |
|---|