12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/slab.h>
15 #include <linux/module.h>
22 #define EMI26_VENDOR_ID 0x086a
23 #define EMI26_PRODUCT_ID 0x0100
24 #define EMI26B_PRODUCT_ID 0x0102
26 #define ANCHOR_LOAD_INTERNAL 0xA0
27 #define ANCHOR_LOAD_EXTERNAL 0xA3
28 #define ANCHOR_LOAD_FPGA 0xA5
29 #define MAX_INTERNAL_ADDRESS 0x1B3F
30 #define CPUCS_REG 0x7F92
31 #define INTERNAL_RAM(address) (address <= MAX_INTERNAL_ADDRESS)
33 static int emi26_writememory(
struct usb_device *
dev,
int address,
36 static int emi26_set_reset(
struct usb_device *
dev,
unsigned char reset_bit);
37 static int emi26_load_firmware (
struct usb_device *
dev);
42 static int emi26_writememory (
struct usb_device *
dev,
int address,
50 dev_err(&dev->dev,
"kmalloc(%d) failed.\n", length);
55 result =
usb_control_msg (dev, usb_sndctrlpipe(dev, 0), request, 0x40, address, 0, buffer, length, 300);
61 static int emi26_set_reset (
struct usb_device *dev,
unsigned char reset_bit)
64 dev_info(&dev->dev,
"%s - %d\n", __func__, reset_bit);
66 response = emi26_writememory (dev,
CPUCS_REG, &reset_bit, 1, 0xa0);
68 dev_err(&dev->dev,
"set_reset (%d) failed\n", reset_bit);
73 #define FW_LOAD_SIZE 1023
75 static int emi26_load_firmware (
struct usb_device *dev)
90 err = request_ihex_firmware(&loader_fw,
"emi26/loader.fw", &dev->dev);
94 err = request_ihex_firmware(&bitstream_fw,
"emi26/bitstream.fw",
99 err = request_ihex_firmware(&firmware_fw,
"emi26/firmware.fw",
103 dev_err(&dev->dev,
"%s - request_firmware() failed\n",
109 err = emi26_set_reset(dev,1);
121 rec = ihex_next_binrec(rec);
125 err = emi26_set_reset(dev,0);
142 rec = ihex_next_binrec(rec);
150 err = emi26_set_reset(dev,1);
155 for (rec = (
const struct ihex_binrec *)loader_fw->data;
156 rec; rec = ihex_next_binrec(rec)) {
166 err = emi26_set_reset(dev,0);
172 for (rec = (
const struct ihex_binrec *)firmware_fw->data;
173 rec; rec = ihex_next_binrec(rec)) {
184 err = emi26_set_reset(dev,1);
188 for (rec = (
const struct ihex_binrec *)firmware_fw->data;
189 rec; rec = ihex_next_binrec(rec)) {
200 err = emi26_set_reset(dev,0);
211 dev_err(&dev->dev,
"%s - error loading firmware: error = %d\n",
232 struct usb_device *dev = interface_to_usbdev(intf);
234 dev_info(&intf->dev,
"%s start\n", __func__);
236 emi26_load_firmware(dev);
246 static struct usb_driver emi26_driver = {
247 .name =
"emi26 - firmware loader",
248 .probe = emi26_probe,
249 .disconnect = emi26_disconnect,
250 .id_table = id_table,