emi26.c revision b412284b969845615e860001b2f34614ece1d576
11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Emagic EMI 2|6 usb audio interface firmware loader.
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2002
496de0e252cedffad61b3cb5e05662c591898e69aJan Engelhardt * 	Tapio Laxström (tapio.laxstrom@iptime.fi)
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This program is free software; you can redistribute it and/or modify
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * it under the terms of the GNU General Public License, as published by
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the Free Software Foundation, version 2.
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * emi26.c,v 1.13 2002/03/08 13:10:26 tapio Exp
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/kernel.h>
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/errno.h>
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/slab.h>
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/module.h>
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h>
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/usb.h>
1816c23f7d88cbcce491f9370b2846fad66e8ef319Monty#include <linux/delay.h>
19ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse#include <linux/firmware.h>
20ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse#include <linux/ihex.h>
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EMI26_VENDOR_ID 		0x086a  /* Emagic Soft-und Hardware GmBH */
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EMI26_PRODUCT_ID		0x0100	/* EMI 2|6 without firmware */
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define EMI26B_PRODUCT_ID		0x0102	/* EMI 2|6 without firmware */
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ANCHOR_LOAD_INTERNAL	0xA0	/* Vendor specific request code for Anchor Upload/Download (This one is implemented in the core) */
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ANCHOR_LOAD_EXTERNAL	0xA3	/* This command is not implemented in the core. Requires firmware */
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ANCHOR_LOAD_FPGA	0xA5	/* This command is not implemented in the core. Requires firmware. Emagic extension */
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define MAX_INTERNAL_ADDRESS	0x1B3F	/* This is the highest internal RAM address for the AN2131Q */
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CPUCS_REG		0x7F92  /* EZ-USB Control and Status Register.  Bit 0 controls 8051 reset */
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define INTERNAL_RAM(address)   (address <= MAX_INTERNAL_ADDRESS)
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
33ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhousestatic int emi26_writememory( struct usb_device *dev, int address,
34ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse			      const unsigned char *data, int length,
35ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse			      __u8 bRequest);
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int emi26_set_reset(struct usb_device *dev, unsigned char reset_bit);
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int emi26_load_firmware (struct usb_device *dev);
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int emi26_probe(struct usb_interface *intf, const struct usb_device_id *id);
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void emi26_disconnect(struct usb_interface *intf);
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* thanks to drivers/usb/serial/keyspan_pda.c code */
42ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhousestatic int emi26_writememory (struct usb_device *dev, int address,
43ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse			      const unsigned char *data, int length,
44ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse			      __u8 request)
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int result;
475d7efe5b3768bf53df9b87380ea68baacf11f933Eric Sesterhenn	unsigned char *buffer =  kmemdup(data, length, GFP_KERNEL);
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (!buffer) {
50fd3f1917e345d852ef9ae36178719f4e639f70aeGreg Kroah-Hartman		dev_err(&dev->dev, "kmalloc(%d) failed.\n", length);
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		return -ENOMEM;
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* Note: usb_control_msg returns negative value on error or length of the
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * 		 data that was written! */
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	result = usb_control_msg (dev, usb_sndctrlpipe(dev, 0), request, 0x40, address, 0, buffer, length, 300);
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	kfree (buffer);
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return result;
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* thanks to drivers/usb/serial/keyspan_pda.c code */
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int emi26_set_reset (struct usb_device *dev, unsigned char reset_bit)
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int response;
641b29a375fb0b79a11a2d18e7bf5f6da422a35025Greg Kroah-Hartman	dev_info(&dev->dev, "%s - %d\n", __func__, reset_bit);
65441b62c1edb986827154768d89bbac0ba779984fHarvey Harrison	/* printk(KERN_DEBUG "%s - %d", __func__, reset_bit); */
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	response = emi26_writememory (dev, CPUCS_REG, &reset_bit, 1, 0xa0);
671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	if (response < 0) {
68fd3f1917e345d852ef9ae36178719f4e639f70aeGreg Kroah-Hartman		dev_err(&dev->dev, "set_reset (%d) failed\n", reset_bit);
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return response;
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FW_LOAD_SIZE		1023
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int emi26_load_firmware (struct usb_device *dev)
761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
77ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	const struct firmware *loader_fw = NULL;
78ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	const struct firmware *bitstream_fw = NULL;
79ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	const struct firmware *firmware_fw = NULL;
80ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	const struct ihex_binrec *rec;
81b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman	int err = -ENOMEM;
821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	int i;
831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u32 addr;	/* Address to write */
841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	__u8 *buf;
851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	buf = kmalloc(FW_LOAD_SIZE, GFP_KERNEL);
87b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman	if (!buf)
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto wraperr;
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
90ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	err = request_ihex_firmware(&loader_fw, "emi26/loader.fw", &dev->dev);
91ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	if (err)
92ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse		goto nofw;
93ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse
94ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	err = request_ihex_firmware(&bitstream_fw, "emi26/bitstream.fw",
95ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse				    &dev->dev);
96ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	if (err)
97ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse		goto nofw;
98ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse
99ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	err = request_ihex_firmware(&firmware_fw, "emi26/firmware.fw",
100ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse				    &dev->dev);
101ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	if (err) {
102ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	nofw:
103fd3f1917e345d852ef9ae36178719f4e639f70aeGreg Kroah-Hartman		dev_err(&dev->dev, "%s - request_firmware() failed\n",
104fd3f1917e345d852ef9ae36178719f4e639f70aeGreg Kroah-Hartman			__func__);
105ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse		goto wraperr;
106ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	}
107ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse
1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* Assert reset (stop the CPU in the EMI) */
1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	err = emi26_set_reset(dev,1);
110b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman	if (err < 0)
1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto wraperr;
1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
113ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	rec = (const struct ihex_binrec *)loader_fw->data;
1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* 1. We need to put the loader for the FPGA into the EZ-USB */
115ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	while (rec) {
116ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse		err = emi26_writememory(dev, be32_to_cpu(rec->addr),
117ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse					rec->data, be16_to_cpu(rec->len),
118ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse					ANCHOR_LOAD_INTERNAL);
119b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman		if (err < 0)
1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			goto wraperr;
121ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse		rec = ihex_next_binrec(rec);
1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* De-assert reset (let the CPU run) */
1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	err = emi26_set_reset(dev,0);
126b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman	if (err < 0)
127cf4cf0bb89cbff95c5be8f8d3c68e55f38f94ba7Oliver Neukum		goto wraperr;
12816c23f7d88cbcce491f9370b2846fad66e8ef319Monty	msleep(250);	/* let device settle */
1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* 2. We upload the FPGA firmware into the EMI
1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * Note: collect up to 1023 (yes!) bytes and send them with
1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * a single request. This is _much_ faster! */
133ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	rec = (const struct ihex_binrec *)bitstream_fw->data;
1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	do {
1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		i = 0;
136ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse		addr = be32_to_cpu(rec->addr);
1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		/* intel hex records are terminated with type 0 element */
139ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse		while (rec && (i + be16_to_cpu(rec->len) < FW_LOAD_SIZE)) {
140ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse			memcpy(buf + i, rec->data, be16_to_cpu(rec->len));
141ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse			i += be16_to_cpu(rec->len);
142ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse			rec = ihex_next_binrec(rec);
1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		err = emi26_writememory(dev, addr, buf, i, ANCHOR_LOAD_FPGA);
145b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman		if (err < 0)
1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			goto wraperr;
147327d74f6b65ddc8a042c43c11fdd4be0bb354668Marcin Slusarz	} while (rec);
1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* Assert reset (stop the CPU in the EMI) */
1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	err = emi26_set_reset(dev,1);
151b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman	if (err < 0)
1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto wraperr;
1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* 3. We need to put the loader for the firmware into the EZ-USB (again...) */
155ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	for (rec = (const struct ihex_binrec *)loader_fw->data;
156ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	     rec; rec = ihex_next_binrec(rec)) {
157ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse		err = emi26_writememory(dev, be32_to_cpu(rec->addr),
158ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse					rec->data, be16_to_cpu(rec->len),
159ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse					ANCHOR_LOAD_INTERNAL);
160b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman		if (err < 0)
1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds			goto wraperr;
1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
16316c23f7d88cbcce491f9370b2846fad66e8ef319Monty	msleep(250);	/* let device settle */
1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* De-assert reset (let the CPU run) */
1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	err = emi26_set_reset(dev,0);
167b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman	if (err < 0)
1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto wraperr;
1691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* 4. We put the part of the firmware that lies in the external RAM into the EZ-USB */
171ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse
172ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	for (rec = (const struct ihex_binrec *)firmware_fw->data;
173ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	     rec; rec = ihex_next_binrec(rec)) {
174ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse		if (!INTERNAL_RAM(be32_to_cpu(rec->addr))) {
175ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse			err = emi26_writememory(dev, be32_to_cpu(rec->addr),
176ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse						rec->data, be16_to_cpu(rec->len),
177ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse						ANCHOR_LOAD_EXTERNAL);
178b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman			if (err < 0)
1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				goto wraperr;
1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
182b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman
1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* Assert reset (stop the CPU in the EMI) */
1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	err = emi26_set_reset(dev,1);
185b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman	if (err < 0)
1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto wraperr;
1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
188ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	for (rec = (const struct ihex_binrec *)firmware_fw->data;
189ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	     rec; rec = ihex_next_binrec(rec)) {
190ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse		if (INTERNAL_RAM(be32_to_cpu(rec->addr))) {
191ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse			err = emi26_writememory(dev, be32_to_cpu(rec->addr),
192ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse						rec->data, be16_to_cpu(rec->len),
193ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse						ANCHOR_LOAD_INTERNAL);
194b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman			if (err < 0)
1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds				goto wraperr;
1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		}
1971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	}
1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* De-assert reset (let the CPU run) */
2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	err = emi26_set_reset(dev,0);
201b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman	if (err < 0)
2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds		goto wraperr;
20316c23f7d88cbcce491f9370b2846fad66e8ef319Monty	msleep(250);	/* let device settle */
2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* return 1 to fail the driver inialization
2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	 * and give real driver change to load */
2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	err = 1;
2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldswraperr:
210b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman	if (err < 0)
211b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman		dev_err(&dev->dev,"%s - error loading firmware: error = %d\n",
212b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman			__func__, err);
213b412284b969845615e860001b2f34614ece1d576Greg Kroah-Hartman
214ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	release_firmware(loader_fw);
215ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	release_firmware(bitstream_fw);
216ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse	release_firmware(firmware_fw);
217ae93a55bf948753de0bb8e43fa9c027f786abb05David Woodhouse
2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	kfree(buf);
2191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return err;
2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
22233b9e16243fd69493be3ddda7be73226c8be586aNémeth Mártonstatic const struct usb_device_id id_table[] = {
2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	{ USB_DEVICE(EMI26_VENDOR_ID, EMI26_PRODUCT_ID) },
2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	{ USB_DEVICE(EMI26_VENDOR_ID, EMI26B_PRODUCT_ID) },
2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	{ }                                             /* Terminating entry */
2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_DEVICE_TABLE (usb, id_table);
2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int emi26_probe(struct usb_interface *intf, const struct usb_device_id *id)
2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	struct usb_device *dev = interface_to_usbdev(intf);
2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2341b29a375fb0b79a11a2d18e7bf5f6da422a35025Greg Kroah-Hartman	dev_info(&intf->dev, "%s start\n", __func__);
2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	emi26_load_firmware(dev);
2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	/* do not return the driver context, let real audio driver do that */
2391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	return -EIO;
2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
2411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void emi26_disconnect(struct usb_interface *intf)
2431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
2441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct usb_driver emi26_driver = {
2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.name		= "emi26 - firmware loader",
2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.probe		= emi26_probe,
2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.disconnect	= emi26_disconnect,
2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.id_table	= id_table,
2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds};
2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
25365db43054065790a75291b0834657445fea2cf56Greg Kroah-Hartmanmodule_usb_driver(emi26_driver);
2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
25596de0e252cedffad61b3cb5e05662c591898e69aJan EngelhardtMODULE_AUTHOR("Tapio Laxström");
2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_DESCRIPTION("Emagic EMI 2|6 firmware loader.");
2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("GPL");
2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
259ae93a55bf948753de0bb8e43fa9c027f786abb05David WoodhouseMODULE_FIRMWARE("emi26/loader.fw");
260ae93a55bf948753de0bb8e43fa9c027f786abb05David WoodhouseMODULE_FIRMWARE("emi26/bitstream.fw");
261ae93a55bf948753de0bb8e43fa9c027f786abb05David WoodhouseMODULE_FIRMWARE("emi26/firmware.fw");
2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* vi:ai:syntax=c:sw=8:ts=8:tw=80
2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
264