17 #include <linux/module.h>
19 #include <linux/kernel.h>
39 static const u8 ep_w_max_packet_size[] = {
40 0xe4, 0x00, 0xe4, 0x00,
41 0xa4, 0x01, 0xa4, 0x01,
42 0x94, 0x01, 0x5c, 0x02
45 static const u8 known_fw_versions[][4] = {
46 { 0x03, 0x01, 0x0b, 0x00 }
90 record->
error =
false;
102 record->
error =
true;
106 record->
len = usb6fire_fw_ihex_hex(record->
txt_data +
115 type = usb6fire_fw_ihex_hex(record->
txt_data +
121 record->
error =
true;
124 for (i = 0; i < record->
len; i++) {
131 record->
error =
true;
135 if (type == 1 || !record->
len)
140 record->
error =
true;
145 static int usb6fire_fw_ihex_init(
const struct firmware *
fw,
154 while (usb6fire_fw_ihex_next_record(record))
162 static int usb6fire_fw_ezusb_write(
struct usb_device *
device,
163 int type,
int value,
char *
data,
int len)
169 value, 0, data, len,
HZ);
177 static int usb6fire_fw_ezusb_read(
struct usb_device *device,
178 int type,
int value,
char *data,
int len)
190 static int usb6fire_fw_fpga_write(
struct usb_device *device,
200 else if (actual_len != len)
205 static int usb6fire_fw_ezusb_upload(
207 unsigned int postaddr,
u8 *postdata,
unsigned int postlen)
211 struct usb_device *device = interface_to_usbdev(intf);
223 "firmware %s.\n", fwname);
226 ret = usb6fire_fw_ihex_init(fw, rec);
231 "firmware %s.\n", fwname);
236 ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1);
241 "firmware %s: begin message.\n", fwname);
245 while (usb6fire_fw_ihex_next_record(rec)) {
246 ret = usb6fire_fw_ezusb_write(device, 0xa0, rec->
address,
252 "firmware %s: data urb.\n", fwname);
260 ret = usb6fire_fw_ezusb_write(device, 0xa0, postaddr,
264 "firmware %s: post urb.\n", fwname);
270 ret = usb6fire_fw_ezusb_write(device, 0xa0, 0xe600, &data, 1);
273 "firmware %s: end message.\n", fwname);
279 static int usb6fire_fw_fpga_upload(
284 struct usb_device *device = interface_to_usbdev(intf);
304 ret = usb6fire_fw_ezusb_write(device, 8, 0,
NULL, 0);
317 ret = usb6fire_fw_fpga_write(device, buffer, i);
322 "firmware: fw urb.\n");
329 ret = usb6fire_fw_ezusb_write(device, 9, 0,
NULL, 0);
341 static int usb6fire_fw_check(
u8 *
version)
345 for (i = 0; i <
ARRAY_SIZE(known_fw_versions); i++)
346 if (!
memcmp(version, known_fw_versions + i, 4))
350 "please reconnect to power. if this failure "
351 "still happens, check your firmware installation.",
360 struct usb_device *device = interface_to_usbdev(intf);
365 ret = usb6fire_fw_ezusb_read(device, 1, 0, buffer, 8);
368 "firmware state.\n");
371 if (buffer[0] != 0xeb || buffer[1] != 0xaa || buffer[2] != 0x55) {
373 "received from device: ");
374 for (i = 0; i < 8; i++)
380 if (buffer[3] == 0x01) {
381 ret = usb6fire_fw_ezusb_upload(intf,
382 "6fire/dmx6firel2.ihx", 0,
NULL, 0);
388 else if (buffer[3] == 0x02) {
389 ret = usb6fire_fw_check(buffer + 4);
392 ret = usb6fire_fw_fpga_upload(intf,
"6fire/dmx6firecf.bin");
395 memcpy(buffer, ep_w_max_packet_size,
396 sizeof(ep_w_max_packet_size));
397 ret = usb6fire_fw_ezusb_upload(intf,
"6fire/dmx6fireap.ihx",
398 0x0003, buffer,
sizeof(ep_w_max_packet_size));
404 else if (buffer[3] == 0x03)
405 return usb6fire_fw_check(buffer + 4);
409 "received from device: ");
410 for (i = 0; i < 8; i++)