10 #include <linux/kernel.h>
11 #include <linux/errno.h>
12 #include <linux/slab.h>
14 #include <linux/module.h>
27 #define FIRMWARE_FW "emi62/spdif.fw"
29 #define FIRMWARE_FW "emi62/midi.fw"
32 #define EMI62_VENDOR_ID 0x086a
33 #define EMI62_PRODUCT_ID 0x0110
35 #define ANCHOR_LOAD_INTERNAL 0xA0
36 #define ANCHOR_LOAD_EXTERNAL 0xA3
37 #define ANCHOR_LOAD_FPGA 0xA5
38 #define MAX_INTERNAL_ADDRESS 0x1B3F
39 #define CPUCS_REG 0x7F92
40 #define INTERNAL_RAM(address) (address <= MAX_INTERNAL_ADDRESS)
42 static int emi62_writememory(
struct usb_device *
dev,
int address,
45 static int emi62_set_reset(
struct usb_device *
dev,
unsigned char reset_bit);
46 static int emi62_load_firmware (
struct usb_device *
dev);
51 static int emi62_writememory(
struct usb_device *
dev,
int address,
59 dev_err(&dev->dev,
"kmalloc(%d) failed.\n", length);
64 result =
usb_control_msg (dev, usb_sndctrlpipe(dev, 0), request, 0x40, address, 0, buffer, length, 300);
70 static int emi62_set_reset (
struct usb_device *dev,
unsigned char reset_bit)
73 dev_info(&dev->dev,
"%s - %d\n", __func__, reset_bit);
75 response = emi62_writememory (dev,
CPUCS_REG, &reset_bit, 1, 0xa0);
77 dev_err(&dev->dev,
"set_reset (%d) failed\n", reset_bit);
81 #define FW_LOAD_SIZE 1023
83 static int emi62_load_firmware (
struct usb_device *dev)
94 dev_dbg(&dev->dev,
"load_firmware\n");
99 err = request_ihex_firmware(&loader_fw,
"emi62/loader.fw", &dev->dev);
103 err = request_ihex_firmware(&bitstream_fw,
"emi62/bitstream.fw",
108 err = request_ihex_firmware(&firmware_fw,
FIRMWARE_FW, &dev->dev);
115 err = emi62_set_reset(dev,1);
128 rec = ihex_next_binrec(rec);
132 err = emi62_set_reset(dev,0);
149 rec = ihex_next_binrec(rec);
157 err = emi62_set_reset(dev,1);
162 for (rec = (
const struct ihex_binrec *)loader_fw->data;
163 rec; rec = ihex_next_binrec(rec)) {
172 err = emi62_set_reset(dev,0);
179 for (rec = (
const struct ihex_binrec *)firmware_fw->data;
180 rec; rec = ihex_next_binrec(rec)) {
191 err = emi62_set_reset(dev,1);
195 for (rec = (
const struct ihex_binrec *)firmware_fw->data;
196 rec; rec = ihex_next_binrec(rec)) {
207 err = emi62_set_reset(dev,0);
224 dev_err(&dev->dev,
"%s - error loading firmware: error = %d\n",
244 struct usb_device *dev = interface_to_usbdev(intf);
245 dev_dbg(&intf->dev,
"emi62_probe\n");
247 dev_info(&intf->dev,
"%s start\n", __func__);
249 emi62_load_firmware(dev);
259 static struct usb_driver emi62_driver = {
260 .name =
"emi62 - firmware loader",
261 .probe = emi62_probe,
262 .disconnect = emi62_disconnect,
263 .id_table = id_table,