/*
 * USB FTDI client driver for Elan Digital Systems's Uxxx adapters
 *
 * Copyright(C) 2006 Elan Digital Systems Limited
 * http://www.elandigitalsystems.com
 *
 * Author and Maintainer - Tony Olech - Elan Digital Systems
 * tony.olech@elandigitalsystems.com
 *
 * This program is free software;you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, version 2.
 *
 *
 * This driver was written by Tony Olech(tony.olech@elandigitalsystems.com)
 * based on various USB client drivers in the 2.6.15 linux kernel
 * with constant reference to the 3rd Edition of Linux Device Drivers
 * published by O'Reilly
 *
 * The U132 adapter is a USB to CardBus adapter specifically designed
 * for PC cards that contain an OHCI host controller. Typical PC cards
 * are the Orange Mobile 3G Option GlobeTrotter Fusion card.
 *
 * The U132 adapter will *NOT *work with PC cards that do not contain
 * an OHCI controller. A simple way to test whether a PC card has an
 * OHCI controller as an interface is to insert the PC card directly
 * into a laptop(or desktop) with a CardBus slot and if "lspci" shows
 * a new USB controller and "lsusb -v" shows a new OHCI Host Controller
 * then there is a good chance that the U132 adapter will support the
 * PC card.(you also need the specific client driver for the PC card)
 *
 * Please inform the Author and Maintainer about any PC cards that
 * contain OHCI Host Controller and work when directly connected to
 * an embedded CardBus slot but do not work when they are connected
 * via an ELAN U132 adapter.
 *
 */

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/ioctl.h>
#include <linux/pci_ids.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/kref.h>
#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <linux/usb.h>
#include <linux/workqueue.h>
#include <linux/platform_device.h>
MODULE_AUTHOR("Tony Olech");
MODULE_DESCRIPTION("FTDI ELAN driver");
MODULE_LICENSE("GPL");
#define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
static bool distrust_firmware = 1;
module_param(distrust_firmware, bool, 0);
MODULE_PARM_DESC(distrust_firmware,
		 "true to distrust firmware power/overcurrent setup");
extern struct platform_driver u132_platform_driver;
static struct workqueue_struct *status_queue;
static struct workqueue_struct *command_queue;
static struct workqueue_struct *respond_queue;
/*
 * ftdi_module_lock exists to protect access to global variables
 *
 */
static struct mutex ftdi_module_lock;
static int ftdi_instances = 0;
static struct list_head ftdi_static_list;
/*
 * end of the global variables protected by ftdi_module_lock
 */
#include "usb_u132.h"
#include <asm/io.h>
#include <linux/usb/hcd.h>

/* FIXME ohci.h is ONLY for internal use by the OHCI driver.
 * If you're going to try stuff like this, you need to split
 * out shareable stuff (register declarations?) into its own
 * file, maybe name <linux/usb/ohci.h>
 */

#include "../host/ohci.h"
/* Define these values to match your devices*/
#define USB_FTDI_ELAN_VENDOR_ID 0x0403
#define USB_FTDI_ELAN_PRODUCT_ID 0xd6ea
/* table of devices that work with this driver*/
static const struct usb_device_id ftdi_elan_table[] = {
	{USB_DEVICE(USB_FTDI_ELAN_VENDOR_ID, USB_FTDI_ELAN_PRODUCT_ID)},
	{ /* Terminating entry */ }
};

MODULE_DEVICE_TABLE(usb, ftdi_elan_table);
/* only the jtag(firmware upgrade device) interface requires
 * a device file and corresponding minor number, but the
 * interface is created unconditionally - I suppose it could
 * be configured or not according to a module parameter.
 * But since we(now) require one interface per device,
 * and since it unlikely that a normal installation would
 * require more than a couple of elan-ftdi devices, 8 seems
 * like a reasonable limit to have here, and if someone
 * really requires more than 8 devices, then they can frig the
 * code and recompile
 */
#define USB_FTDI_ELAN_MINOR_BASE 192
#define COMMAND_BITS 5
#define COMMAND_SIZE (1<<COMMAND_BITS)
#define COMMAND_MASK (COMMAND_SIZE-1)
struct u132_command {
	u8 header;
	u16 length;
	u8 address;
	u8 width;
	u32 value;
	int follows;
	void *buffer;
};
#define RESPOND_BITS 5
#define RESPOND_SIZE (1<<RESPOND_BITS)
#define RESPOND_MASK (RESPOND_SIZE-1)
struct u132_respond {
	u8 header;
	u8 address;
	u32 *value;
	int *result;
	struct completion wait_completion;
};
struct u132_target {
	void *endp;
	struct urb *urb;
	int toggle_bits;
	int error_count;
	int condition_code;
	int repeat_number;
	int halted;
	int skipped;
	int actual;
	int non_null;
	int active;
	int abandoning;
	void (*callback)(void *endp, struct urb *urb, u8 *buf, int len,
			 int toggle_bits, int error_count, int condition_code,
			 int repeat_number, int halted, int skipped, int actual,
			 int non_null);
};
/* Structure to hold all of our device specific stuff*/
struct usb_ftdi {
	struct list_head ftdi_list;
	struct mutex u132_lock;
	int command_next;
	int command_head;
	struct u132_command command[COMMAND_SIZE];
	int respond_next;
	int respond_head;
	struct u132_respond respond[RESPOND_SIZE];
	struct u132_target target[4];
	char device_name[16];
	unsigned synchronized:1;
	unsigned enumerated:1;
	unsigned registered:1;
	unsigned initialized:1;
	unsigned card_ejected:1;
	int function;
	int sequence_num;
	int disconnected;
	int gone_away;
	int stuck_status;
	int status_queue_delay;
	struct semaphore sw_lock;
	struct usb_device *udev;
	struct usb_interface *interface;
	struct usb_class_driver *class;
	struct delayed_work status_work;
	struct delayed_work command_work;
	struct delayed_work respond_work;
	struct u132_platform_data platform_data;
	struct resource resources[0];
	struct platform_device platform_dev;
	unsigned char *bulk_in_buffer;
	size_t bulk_in_size;
	size_t bulk_in_last;
	size_t bulk_in_left;
	__u8 bulk_in_endpointAddr;
	__u8 bulk_out_endpointAddr;
	struct kref kref;
	u32 controlreg;
	u8 response[4 + 1024];
	int expected;
	int received;
	int ed_found;
};
#define kref_to_usb_ftdi(d) container_of(d, struct usb_ftdi, kref)
#define platform_device_to_usb_ftdi(d) container_of(d, struct usb_ftdi, \
						    platform_dev)
static struct usb_driver ftdi_elan_driver;
static void ftdi_elan_delete(struct kref *kref)
{
	struct usb_ftdi *ftdi = kref_to_usb_ftdi(kref);
	dev_warn(&ftdi->udev->dev, "FREEING ftdi=%p\n", ftdi);
	usb_put_dev(ftdi->udev);
	ftdi->disconnected += 1;
	mutex_lock(&ftdi_module_lock);
	list_del_init(&ftdi->ftdi_list);
	ftdi_instances -= 1;
	mutex_unlock(&ftdi_module_lock);
	kfree(ftdi->bulk_in_buffer);
	ftdi->bulk_in_buffer = NULL;
}

static void ftdi_elan_put_kref(struct usb_ftdi *ftdi)
{
	kref_put(&ftdi->kref, ftdi_elan_delete);
}

static void ftdi_elan_get_kref(struct usb_ftdi *ftdi)
{
	kref_get(&ftdi->kref);
}

static void ftdi_elan_init_kref(struct usb_ftdi *ftdi)
{
	kref_init(&ftdi->kref);
}

static void ftdi_status_requeue_work(struct usb_ftdi *ftdi, unsigned int delta)
{
	if (!queue_delayed_work(status_queue, &ftdi->status_work, delta))
		kref_put(&ftdi->kref, ftdi_elan_delete);
}

static void ftdi_status_queue_work(struct usb_ftdi *ftdi, unsigned int delta)
{
	if (queue_delayed_work(status_queue, &ftdi->status_work, delta))
		kref_get(&ftdi->kref);
}

static void ftdi_status_cancel_work(struct usb_ftdi *ftdi)
{
	if (cancel_delayed_work(&ftdi->status_work))
		kref_put(&ftdi->kref, ftdi_elan_delete);
}

static void ftdi_command_requeue_work(struct usb_ftdi *ftdi, unsigned int delta)
{
	if (!queue_delayed_work(command_queue, &ftdi->command_work, delta))
		kref_put(&ftdi->kref, ftdi_elan_delete);
}

static void ftdi_command_queue_work(struct usb_ftdi *ftdi, unsigned int delta)
{
	if (queue_delayed_work(command_queue, &ftdi->command_work, delta))
		kref_get(&ftdi->kref);
}

static void ftdi_command_cancel_work(struct usb_ftdi *ftdi)
{
	if (cancel_delayed_work(&ftdi->command_work))
		kref_put(&ftdi->kref, ftdi_elan_delete);
}

static void ftdi_response_requeue_work(struct usb_ftdi *ftdi,
				       unsigned int delta)
{
	if (!queue_delayed_work(respond_queue, &ftdi->respond_work, delta))
		kref_put(&ftdi->kref, ftdi_elan_delete);
}

static void ftdi_respond_queue_work(struct usb_ftdi *ftdi, unsigned int delta)
{
	if (queue_delayed_work(respond_queue, &ftdi->respond_work, delta))
		kref_get(&ftdi->kref);
}

static void ftdi_response_cancel_work(struct usb_ftdi *ftdi)
{
	if (cancel_delayed_work(&ftdi->respond_work))
		kref_put(&ftdi->kref, ftdi_elan_delete);
}

void ftdi_elan_gone_away(struct platform_device *pdev)
{
	struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
	ftdi->gone_away += 1;
	ftdi_elan_put_kref(ftdi);
}


EXPORT_SYMBOL_GPL(ftdi_elan_gone_away);
static void ftdi_release_platform_dev(struct device *dev)
{
	dev->parent = NULL;
}

static void ftdi_elan_do_callback(struct usb_ftdi *ftdi,
				  struct u132_target *target, u8 *buffer, int length);
static void ftdi_elan_kick_command_queue(struct usb_ftdi *ftdi);
static void ftdi_elan_kick_respond_queue(struct usb_ftdi *ftdi);
static int ftdi_elan_setupOHCI(struct usb_ftdi *ftdi);
static int ftdi_elan_checkingPCI(struct usb_ftdi *ftdi);
static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi);
static int ftdi_elan_synchronize(struct usb_ftdi *ftdi);
static int ftdi_elan_stuck_waiting(struct usb_ftdi *ftdi);
static int ftdi_elan_command_engine(struct usb_ftdi *ftdi);
static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi);
static int ftdi_elan_hcd_init(struct usb_ftdi *ftdi)
{
	int result;
	if (ftdi->platform_dev.dev.parent)
		return -EBUSY;
	ftdi_elan_get_kref(ftdi);
	ftdi->platform_data.potpg = 100;
	ftdi->platform_data.reset = NULL;
	ftdi->platform_dev.id = ftdi->sequence_num;
	ftdi->platform_dev.resource = ftdi->resources;
	ftdi->platform_dev.num_resources = ARRAY_SIZE(ftdi->resources);
	ftdi->platform_dev.dev.platform_data = &ftdi->platform_data;
	ftdi->platform_dev.dev.parent = NULL;
	ftdi->platform_dev.dev.release = ftdi_release_platform_dev;
	ftdi->platform_dev.dev.dma_mask = NULL;
	snprintf(ftdi->device_name, sizeof(ftdi->device_name), "u132_hcd");
	ftdi->platform_dev.name = ftdi->device_name;
	dev_info(&ftdi->udev->dev, "requesting module '%s'\n", "u132_hcd");
	request_module("u132_hcd");
	dev_info(&ftdi->udev->dev, "registering '%s'\n",
		 ftdi->platform_dev.name);
	result = platform_device_register(&ftdi->platform_dev);
	return result;
}

static void ftdi_elan_abandon_completions(struct usb_ftdi *ftdi)
{
	mutex_lock(&ftdi->u132_lock);
	while (ftdi->respond_next > ftdi->respond_head) {
		struct u132_respond *respond = &ftdi->respond[RESPOND_MASK &
							      ftdi->respond_head++];
		*respond->result = -ESHUTDOWN;
		*respond->value = 0;
		complete(&respond->wait_completion);
	} mutex_unlock(&ftdi->u132_lock);
}

static void ftdi_elan_abandon_targets(struct usb_ftdi *ftdi)
{
	int ed_number = 4;
	mutex_lock(&ftdi->u132_lock);
	while (ed_number-- > 0) {
		struct u132_target *target = &ftdi->target[ed_number];
		if (target->active == 1) {
			target->condition_code = TD_DEVNOTRESP;
			mutex_unlock(&ftdi->u132_lock);
			ftdi_elan_do_callback(ftdi, target, NULL, 0);
			mutex_lock(&ftdi->u132_lock);
		}
	}
	ftdi->received = 0;
	ftdi->expected = 4;
	ftdi->ed_found = 0;
	mutex_unlock(&ftdi->u132_lock);
}

static void ftdi_elan_flush_targets(struct usb_ftdi *ftdi)
{
	int ed_number = 4;
	mutex_lock(&ftdi->u132_lock);
	while (ed_number-- > 0) {
		struct u132_target *target = &ftdi->target[ed_number];
		target->abandoning = 1;
	wait_1:if (target->active == 1) {
			int command_size = ftdi->command_next -
				ftdi->command_head;
			if (command_size < COMMAND_SIZE) {
				struct u132_command *command = &ftdi->command[
					COMMAND_MASK & ftdi->command_next];
				command->header = 0x80 | (ed_number << 5) | 0x4;
				command->length = 0x00;
				command->address = 0x00;
				command->width = 0x00;
				command->follows = 0;
				command->value = 0;
				command->buffer = &command->value;
				ftdi->command_next += 1;
				ftdi_elan_kick_command_queue(ftdi);
			} else {
				mutex_unlock(&ftdi->u132_lock);
				msleep(100);
				mutex_lock(&ftdi->u132_lock);
				goto wait_1;
			}
		}
	wait_2:if (target->active == 1) {
			int command_size = ftdi->command_next -
				ftdi->command_head;
			if (command_size < COMMAND_SIZE) {
				struct u132_command *command = &ftdi->command[
					COMMAND_MASK & ftdi->command_next];
				command->header = 0x90 | (ed_number << 5);
				command->length = 0x00;
				command->address = 0x00;
				command->width = 0x00;
				command->follows = 0;
				command->value = 0;
				command->buffer = &command->value;
				ftdi->command_next += 1;
				ftdi_elan_kick_command_queue(ftdi);
			} else {
				mutex_unlock(&ftdi->u132_lock);
				msleep(100);
				mutex_lock(&ftdi->u132_lock);
				goto wait_2;
			}
		}
	}
	ftdi->received = 0;
	ftdi->expected = 4;
	ftdi->ed_found = 0;
	mutex_unlock(&ftdi->u132_lock);
}

static void ftdi_elan_cancel_targets(struct usb_ftdi *ftdi)
{
	int ed_number = 4;
	mutex_lock(&ftdi->u132_lock);
	while (ed_number-- > 0) {
		struct u132_target *target = &ftdi->target[ed_number];
		target->abandoning = 1;
	wait:if (target->active == 1) {
			int command_size = ftdi->command_next -
				ftdi->command_head;
			if (command_size < COMMAND_SIZE) {
				struct u132_command *command = &ftdi->command[
					COMMAND_MASK & ftdi->command_next];
				command->header = 0x80 | (ed_number << 5) | 0x4;
				command->length = 0x00;
				command->address = 0x00;
				command->width = 0x00;
				command->follows = 0;
				command->value = 0;
				command->buffer = &command->value;
				ftdi->command_next += 1;
				ftdi_elan_kick_command_queue(ftdi);
			} else {
				mutex_unlock(&ftdi->u132_lock);
				msleep(100);
				mutex_lock(&ftdi->u132_lock);
				goto wait;
			}
		}
	}
	ftdi->received = 0;
	ftdi->expected = 4;
	ftdi->ed_found = 0;
	mutex_unlock(&ftdi->u132_lock);
}

static void ftdi_elan_kick_command_queue(struct usb_ftdi *ftdi)
{
	ftdi_command_queue_work(ftdi, 0);
}

static void ftdi_elan_command_work(struct work_struct *work)
{
	struct usb_ftdi *ftdi =
		container_of(work, struct usb_ftdi, command_work.work);

	if (ftdi->disconnected > 0) {
		ftdi_elan_put_kref(ftdi);
		return;
	} else {
		int retval = ftdi_elan_command_engine(ftdi);
		if (retval == -ESHUTDOWN) {
			ftdi->disconnected += 1;
		} else if (retval == -ENODEV) {
			ftdi->disconnected += 1;
		} else if (retval)
			dev_err(&ftdi->udev->dev, "command error %d\n", retval);
		ftdi_command_requeue_work(ftdi, msecs_to_jiffies(10));
		return;
	}
}

static void ftdi_elan_kick_respond_queue(struct usb_ftdi *ftdi)
{
	ftdi_respond_queue_work(ftdi, 0);
}

static void ftdi_elan_respond_work(struct work_struct *work)
{
	struct usb_ftdi *ftdi =
		container_of(work, struct usb_ftdi, respond_work.work);
	if (ftdi->disconnected > 0) {
		ftdi_elan_put_kref(ftdi);
		return;
	} else {
		int retval = ftdi_elan_respond_engine(ftdi);
		if (retval == 0) {
		} else if (retval == -ESHUTDOWN) {
			ftdi->disconnected += 1;
		} else if (retval == -ENODEV) {
			ftdi->disconnected += 1;
		} else if (retval == -EILSEQ) {
			ftdi->disconnected += 1;
		} else {
			ftdi->disconnected += 1;
			dev_err(&ftdi->udev->dev, "respond error %d\n", retval);
		}
		if (ftdi->disconnected > 0) {
			ftdi_elan_abandon_completions(ftdi);
			ftdi_elan_abandon_targets(ftdi);
		}
		ftdi_response_requeue_work(ftdi, msecs_to_jiffies(10));
		return;
	}
}


/*
 * the sw_lock is initially held and will be freed
 * after the FTDI has been synchronized
 *
 */
static void ftdi_elan_status_work(struct work_struct *work)
{
	struct usb_ftdi *ftdi =
		container_of(work, struct usb_ftdi, status_work.work);
	int work_delay_in_msec = 0;
	if (ftdi->disconnected > 0) {
		ftdi_elan_put_kref(ftdi);
		return;
	} else if (ftdi->synchronized == 0) {
		down(&ftdi->sw_lock);
		if (ftdi_elan_synchronize(ftdi) == 0) {
			ftdi->synchronized = 1;
			ftdi_command_queue_work(ftdi, 1);
			ftdi_respond_queue_work(ftdi, 1);
			up(&ftdi->sw_lock);
			work_delay_in_msec = 100;
		} else {
			dev_err(&ftdi->udev->dev, "synchronize failed\n");
			up(&ftdi->sw_lock);
			work_delay_in_msec = 10 *1000;
		}
	} else if (ftdi->stuck_status > 0) {
		if (ftdi_elan_stuck_waiting(ftdi) == 0) {
			ftdi->stuck_status = 0;
			ftdi->synchronized = 0;
		} else if ((ftdi->stuck_status++ % 60) == 1) {
			dev_err(&ftdi->udev->dev, "WRONG type of card inserted - please remove\n");
		} else
			dev_err(&ftdi->udev->dev, "WRONG type of card inserted - checked %d times\n",
				ftdi->stuck_status);
		work_delay_in_msec = 100;
	} else if (ftdi->enumerated == 0) {
		if (ftdi_elan_enumeratePCI(ftdi) == 0) {
			ftdi->enumerated = 1;
			work_delay_in_msec = 250;
		} else
			work_delay_in_msec = 1000;
	} else if (ftdi->initialized == 0) {
		if (ftdi_elan_setupOHCI(ftdi) == 0) {
			ftdi->initialized = 1;
			work_delay_in_msec = 500;
		} else {
			dev_err(&ftdi->udev->dev, "initialized failed - trying again in 10 seconds\n");
			work_delay_in_msec = 1 *1000;
		}
	} else if (ftdi->registered == 0) {
		work_delay_in_msec = 10;
		if (ftdi_elan_hcd_init(ftdi) == 0) {
			ftdi->registered = 1;
		} else
			dev_err(&ftdi->udev->dev, "register failed\n");
		work_delay_in_msec = 250;
	} else {
		if (ftdi_elan_checkingPCI(ftdi) == 0) {
			work_delay_in_msec = 250;
		} else if (ftdi->controlreg & 0x00400000) {
			if (ftdi->gone_away > 0) {
				dev_err(&ftdi->udev->dev, "PCI device eject confirmed platform_dev.dev.parent=%p platform_dev.dev=%p\n",
					ftdi->platform_dev.dev.parent,
					&ftdi->platform_dev.dev);
				platform_device_unregister(&ftdi->platform_dev);
				ftdi->platform_dev.dev.parent = NULL;
				ftdi->registered = 0;
				ftdi->enumerated = 0;
				ftdi->card_ejected = 0;
				ftdi->initialized = 0;
				ftdi->gone_away = 0;
			} else
				ftdi_elan_flush_targets(ftdi);
			work_delay_in_msec = 250;
		} else {
			dev_err(&ftdi->udev->dev, "PCI device has disappeared\n");
			ftdi_elan_cancel_targets(ftdi);
			work_delay_in_msec = 500;
			ftdi->enumerated = 0;
			ftdi->initialized = 0;
		}
	}
	if (ftdi->disconnected > 0) {
		ftdi_elan_put_kref(ftdi);
		return;
	} else {
		ftdi_status_requeue_work(ftdi,
					 msecs_to_jiffies(work_delay_in_msec));
		return;
	}
}


/*
 * file_operations for the jtag interface
 *
 * the usage count for the device is incremented on open()
 * and decremented on release()
 */
static int ftdi_elan_open(struct inode *inode, struct file *file)
{
	int subminor;
	struct usb_interface *interface;

	subminor = iminor(inode);
	interface = usb_find_interface(&ftdi_elan_driver, subminor);

	if (!interface) {
		pr_err("can't find device for minor %d\n", subminor);
		return -ENODEV;
	} else {
		struct usb_ftdi *ftdi = usb_get_intfdata(interface);
		if (!ftdi) {
			return -ENODEV;
		} else {
			if (down_interruptible(&ftdi->sw_lock)) {
				return -EINTR;
			} else {
				ftdi_elan_get_kref(ftdi);
				file->private_data = ftdi;
				return 0;
			}
		}
	}
}

static int ftdi_elan_release(struct inode *inode, struct file *file)
{
	struct usb_ftdi *ftdi = file->private_data;
	if (ftdi == NULL)
		return -ENODEV;
	up(&ftdi->sw_lock);        /* decrement the count on our device */
	ftdi_elan_put_kref(ftdi);
	return 0;
}


/*
 *
 * blocking bulk reads are used to get data from the device
 *
 */
static ssize_t ftdi_elan_read(struct file *file, char __user *buffer,
			      size_t count, loff_t *ppos)
{
	char data[30 *3 + 4];
	char *d = data;
	int m = (sizeof(data) - 1) / 3 - 1;
	int bytes_read = 0;
	int retry_on_empty = 10;
	int retry_on_timeout = 5;
	struct usb_ftdi *ftdi = file->private_data;
	if (ftdi->disconnected > 0) {
		return -ENODEV;
	}
	data[0] = 0;
have:if (ftdi->bulk_in_left > 0) {
		if (count-- > 0) {
			char *p = ++ftdi->bulk_in_last + ftdi->bulk_in_buffer;
			ftdi->bulk_in_left -= 1;
			if (bytes_read < m) {
				d += sprintf(d, " %02X", 0x000000FF & *p);
			} else if (bytes_read > m) {
			} else
				d += sprintf(d, " ..");
			if (copy_to_user(buffer++, p, 1)) {
				return -EFAULT;
			} else {
				bytes_read += 1;
				goto have;
			}
		} else
			return bytes_read;
	}
more:if (count > 0) {
		int packet_bytes = 0;
		int retval = usb_bulk_msg(ftdi->udev,
					  usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr),
					  ftdi->bulk_in_buffer, ftdi->bulk_in_size,
					  &packet_bytes, 50);
		if (packet_bytes > 2) {
			ftdi->bulk_in_left = packet_bytes - 2;
			ftdi->bulk_in_last = 1;
			goto have;
		} else if (retval == -ETIMEDOUT) {
			if (retry_on_timeout-- > 0) {
				goto more;
			} else if (bytes_read > 0) {
				return bytes_read;
			} else
				return retval;
		} else if (retval == 0) {
			if (retry_on_empty-- > 0) {
				goto more;
			} else
				return bytes_read;
		} else
			return retval;
	} else
		return bytes_read;
}

static void ftdi_elan_write_bulk_callback(struct urb *urb)
{
	struct usb_ftdi *ftdi = urb->context;
	int status = urb->status;

	if (status && !(status == -ENOENT || status == -ECONNRESET ||
			status == -ESHUTDOWN)) {
		dev_err(&ftdi->udev->dev,
			"urb=%p write bulk status received: %d\n", urb, status);
	}
	usb_free_coherent(urb->dev, urb->transfer_buffer_length,
			  urb->transfer_buffer, urb->transfer_dma);
}

static int fill_buffer_with_all_queued_commands(struct usb_ftdi *ftdi,
						char *buf, int command_size, int total_size)
{
	int ed_commands = 0;
	int b = 0;
	int I = command_size;
	int i = ftdi->command_head;
	while (I-- > 0) {
		struct u132_command *command = &ftdi->command[COMMAND_MASK &
							      i++];
		int F = command->follows;
		u8 *f = command->buffer;
		if (command->header & 0x80) {
			ed_commands |= 1 << (0x3 & (command->header >> 5));
		}
		buf[b++] = command->header;
		buf[b++] = (command->length >> 0) & 0x00FF;
		buf[b++] = (command->length >> 8) & 0x00FF;
		buf[b++] = command->address;
		buf[b++] = command->width;
		while (F-- > 0) {
			buf[b++] = *f++;
		}
	}
	return ed_commands;
}

static int ftdi_elan_total_command_size(struct usb_ftdi *ftdi, int command_size)
{
	int total_size = 0;
	int I = command_size;
	int i = ftdi->command_head;
	while (I-- > 0) {
		struct u132_command *command = &ftdi->command[COMMAND_MASK &
							      i++];
		total_size += 5 + command->follows;
	} return total_size;
}

static int ftdi_elan_command_engine(struct usb_ftdi *ftdi)
{
	int retval;
	char *buf;
	int ed_commands;
	int total_size;
	struct urb *urb;
	int command_size = ftdi->command_next - ftdi->command_head;
	if (command_size == 0)
		return 0;
	total_size = ftdi_elan_total_command_size(ftdi, command_size);
	urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!urb) {
		dev_err(&ftdi->udev->dev, "could not get a urb to write %d commands totaling %d bytes to the Uxxx\n",
			command_size, total_size);
		return -ENOMEM;
	}
	buf = usb_alloc_coherent(ftdi->udev, total_size, GFP_KERNEL,
				 &urb->transfer_dma);
	if (!buf) {
		dev_err(&ftdi->udev->dev, "could not get a buffer to write %d commands totaling %d bytes to the Uxxx\n",
			command_size, total_size);
		usb_free_urb(urb);
		return -ENOMEM;
	}
	ed_commands = fill_buffer_with_all_queued_commands(ftdi, buf,
							   command_size, total_size);
	usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev,
							   ftdi->bulk_out_endpointAddr), buf, total_size,
			  ftdi_elan_write_bulk_callback, ftdi);
	urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
	if (ed_commands) {
		char diag[40 *3 + 4];
		char *d = diag;
		int m = total_size;
		u8 *c = buf;
		int s = (sizeof(diag) - 1) / 3;
		diag[0] = 0;
		while (s-- > 0 && m-- > 0) {
			if (s > 0 || m == 0) {
				d += sprintf(d, " %02X", *c++);
			} else
				d += sprintf(d, " ..");
		}
	}
	retval = usb_submit_urb(urb, GFP_KERNEL);
	if (retval) {
		dev_err(&ftdi->udev->dev, "failed %d to submit urb %p to write %d commands totaling %d bytes to the Uxxx\n",
			retval, urb, command_size, total_size);
		usb_free_coherent(ftdi->udev, total_size, buf, urb->transfer_dma);
		usb_free_urb(urb);
		return retval;
	}
	usb_free_urb(urb);        /* release our reference to this urb,
				     the USB core will eventually free it entirely */
	ftdi->command_head += command_size;
	ftdi_elan_kick_respond_queue(ftdi);
	return 0;
}

static void ftdi_elan_do_callback(struct usb_ftdi *ftdi,
				  struct u132_target *target, u8 *buffer, int length)
{
	struct urb *urb = target->urb;
	int halted = target->halted;
	int skipped = target->skipped;
	int actual = target->actual;
	int non_null = target->non_null;
	int toggle_bits = target->toggle_bits;
	int error_count = target->error_count;
	int condition_code = target->condition_code;
	int repeat_number = target->repeat_number;
	void (*callback) (void *, struct urb *, u8 *, int, int, int, int, int,
			  int, int, int, int) = target->callback;
	target->active -= 1;
	target->callback = NULL;
	(*callback) (target->endp, urb, buffer, length, toggle_bits,
		     error_count, condition_code, repeat_number, halted, skipped,
		     actual, non_null);
}

static char *have_ed_set_response(struct usb_ftdi *ftdi,
				  struct u132_target *target, u16 ed_length, int ed_number, int ed_type,
				  char *b)
{
	int payload = (ed_length >> 0) & 0x07FF;
	mutex_lock(&ftdi->u132_lock);
	target->actual = 0;
	target->non_null = (ed_length >> 15) & 0x0001;
	target->repeat_number = (ed_length >> 11) & 0x000F;
	if (ed_type == 0x02) {
		if (payload == 0 || target->abandoning > 0) {
			target->abandoning = 0;
			mutex_unlock(&ftdi->u132_lock);
			ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response,
					      payload);
			ftdi->received = 0;
			ftdi->expected = 4;
			ftdi->ed_found = 0;
			return ftdi->response;
		} else {
			ftdi->expected = 4 + payload;
			ftdi->ed_found = 1;
			mutex_unlock(&ftdi->u132_lock);
			return b;
		}
	} else if (ed_type == 0x03) {
		if (payload == 0 || target->abandoning > 0) {
			target->abandoning = 0;
			mutex_unlock(&ftdi->u132_lock);
			ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response,
					      payload);
			ftdi->received = 0;
			ftdi->expected = 4;
			ftdi->ed_found = 0;
			return ftdi->response;
		} else {
			ftdi->expected = 4 + payload;
			ftdi->ed_found = 1;
			mutex_unlock(&ftdi->u132_lock);
			return b;
		}
	} else if (ed_type == 0x01) {
		target->abandoning = 0;
		mutex_unlock(&ftdi->u132_lock);
		ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response,
				      payload);
		ftdi->received = 0;
		ftdi->expected = 4;
		ftdi->ed_found = 0;
		return ftdi->response;
	} else {
		target->abandoning = 0;
		mutex_unlock(&ftdi->u132_lock);
		ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response,
				      payload);
		ftdi->received = 0;
		ftdi->expected = 4;
		ftdi->ed_found = 0;
		return ftdi->response;
	}
}

static char *have_ed_get_response(struct usb_ftdi *ftdi,
				  struct u132_target *target, u16 ed_length, int ed_number, int ed_type,
				  char *b)
{
	mutex_lock(&ftdi->u132_lock);
	target->condition_code = TD_DEVNOTRESP;
	target->actual = (ed_length >> 0) & 0x01FF;
	target->non_null = (ed_length >> 15) & 0x0001;
	target->repeat_number = (ed_length >> 11) & 0x000F;
	mutex_unlock(&ftdi->u132_lock);
	if (target->active)
		ftdi_elan_do_callback(ftdi, target, NULL, 0);
	target->abandoning = 0;
	ftdi->received = 0;
	ftdi->expected = 4;
	ftdi->ed_found = 0;
	return ftdi->response;
}


/*
 * The engine tries to empty the FTDI fifo
 *
 * all responses found in the fifo data are dispatched thus
 * the response buffer can only ever hold a maximum sized
 * response from the Uxxx.
 *
 */
static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi)
{
	u8 *b = ftdi->response + ftdi->received;
	int bytes_read = 0;
	int retry_on_empty = 1;
	int retry_on_timeout = 3;
	int empty_packets = 0;
read:{
		int packet_bytes = 0;
		int retval = usb_bulk_msg(ftdi->udev,
					  usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr),
					  ftdi->bulk_in_buffer, ftdi->bulk_in_size,
					  &packet_bytes, 500);
		char diag[30 *3 + 4];
		char *d = diag;
		int m = packet_bytes;
		u8 *c = ftdi->bulk_in_buffer;
		int s = (sizeof(diag) - 1) / 3;
		diag[0] = 0;
		while (s-- > 0 && m-- > 0) {
			if (s > 0 || m == 0) {
				d += sprintf(d, " %02X", *c++);
			} else
				d += sprintf(d, " ..");
		}
		if (packet_bytes > 2) {
			ftdi->bulk_in_left = packet_bytes - 2;
			ftdi->bulk_in_last = 1;
			goto have;
		} else if (retval == -ETIMEDOUT) {
			if (retry_on_timeout-- > 0) {
				dev_err(&ftdi->udev->dev, "TIMED OUT with packet_bytes = %d with total %d bytes%s\n",
					packet_bytes, bytes_read, diag);
				goto more;
			} else if (bytes_read > 0) {
				dev_err(&ftdi->udev->dev, "ONLY %d bytes%s\n",
					bytes_read, diag);
				return -ENOMEM;
			} else {
				dev_err(&ftdi->udev->dev, "TIMED OUT with packet_bytes = %d with total %d bytes%s\n",
					packet_bytes, bytes_read, diag);
				return -ENOMEM;
			}
		} else if (retval == -EILSEQ) {
			dev_err(&ftdi->udev->dev, "error = %d with packet_bytes = %d with total %d bytes%s\n",
				retval, packet_bytes, bytes_read, diag);
			return retval;
		} else if (retval) {
			dev_err(&ftdi->udev->dev, "error = %d with packet_bytes = %d with total %d bytes%s\n",
				retval, packet_bytes, bytes_read, diag);
			return retval;
		} else if (packet_bytes == 2) {
			unsigned char s0 = ftdi->bulk_in_buffer[0];
			unsigned char s1 = ftdi->bulk_in_buffer[1];
			empty_packets += 1;
			if (s0 == 0x31 && s1 == 0x60) {
				if (retry_on_empty-- > 0) {
					goto more;
				} else
					return 0;
			} else if (s0 == 0x31 && s1 == 0x00) {
				if (retry_on_empty-- > 0) {
					goto more;
				} else
					return 0;
			} else {
				if (retry_on_empty-- > 0) {
					goto more;
				} else
					return 0;
			}
		} else if (packet_bytes == 1) {
			if (retry_on_empty-- > 0) {
				goto more;
			} else
				return 0;
		} else {
			if (retry_on_empty-- > 0) {
				goto more;
			} else
				return 0;
		}
	}
more:{
		goto read;
	}
have:if (ftdi->bulk_in_left > 0) {
		u8 c = ftdi->bulk_in_buffer[++ftdi->bulk_in_last];
		bytes_read += 1;
		ftdi->bulk_in_left -= 1;
		if (ftdi->received == 0 && c == 0xFF) {
			goto have;
		} else
			*b++ = c;
		if (++ftdi->received < ftdi->expected) {
			goto have;
		} else if (ftdi->ed_found) {
			int ed_number = (ftdi->response[0] >> 5) & 0x03;
			u16 ed_length = (ftdi->response[2] << 8) |
				ftdi->response[1];
			struct u132_target *target = &ftdi->target[ed_number];
			int payload = (ed_length >> 0) & 0x07FF;
			char diag[30 *3 + 4];
			char *d = diag;
			int m = payload;
			u8 *c = 4 + ftdi->response;
			int s = (sizeof(diag) - 1) / 3;
			diag[0] = 0;
			while (s-- > 0 && m-- > 0) {
				if (s > 0 || m == 0) {
					d += sprintf(d, " %02X", *c++);
				} else
					d += sprintf(d, " ..");
			}
			ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response,
					      payload);
			ftdi->received = 0;
			ftdi->expected = 4;
			ftdi->ed_found = 0;
			b = ftdi->response;
			goto have;
		} else if (ftdi->expected == 8) {
			u8 buscmd;
			int respond_head = ftdi->respond_head++;
			struct u132_respond *respond = &ftdi->respond[
				RESPOND_MASK & respond_head];
			u32 data = ftdi->response[7];
			data <<= 8;
			data |= ftdi->response[6];
			data <<= 8;
			data |= ftdi->response[5];
			data <<= 8;
			data |= ftdi->response[4];
			*respond->value = data;
			*respond->result = 0;
			complete(&respond->wait_completion);
			ftdi->received = 0;
			ftdi->expected = 4;
			ftdi->ed_found = 0;
			b = ftdi->response;
			buscmd = (ftdi->response[0] >> 0) & 0x0F;
			if (buscmd == 0x00) {
			} else if (buscmd == 0x02) {
			} else if (buscmd == 0x06) {
			} else if (buscmd == 0x0A) {
			} else
				dev_err(&ftdi->udev->dev, "Uxxx unknown(%0X) value = %08X\n",
					buscmd, data);
			goto have;
		} else {
			if ((ftdi->response[0] & 0x80) == 0x00) {
				ftdi->expected = 8;
				goto have;
			} else {
				int ed_number = (ftdi->response[0] >> 5) & 0x03;
				int ed_type = (ftdi->response[0] >> 0) & 0x03;
				u16 ed_length = (ftdi->response[2] << 8) |
					ftdi->response[1];
				struct u132_target *target = &ftdi->target[
					ed_number];
				target->halted = (ftdi->response[0] >> 3) &
					0x01;
				target->skipped = (ftdi->response[0] >> 2) &
					0x01;
				target->toggle_bits = (ftdi->response[3] >> 6)
					& 0x03;
				target->error_count = (ftdi->response[3] >> 4)
					& 0x03;
				target->condition_code = (ftdi->response[
								  3] >> 0) & 0x0F;
				if ((ftdi->response[0] & 0x10) == 0x00) {
					b = have_ed_set_response(ftdi, target,
								 ed_length, ed_number, ed_type,
								 b);
					goto have;
				} else {
					b = have_ed_get_response(ftdi, target,
								 ed_length, ed_number, ed_type,
								 b);
					goto have;
				}
			}
		}
	} else
		goto more;
}


/*
 * create a urb, and a buffer for it, and copy the data to the urb
 *
 */
static ssize_t ftdi_elan_write(struct file *file,
			       const char __user *user_buffer, size_t count,
			       loff_t *ppos)
{
	int retval = 0;
	struct urb *urb;
	char *buf;
	struct usb_ftdi *ftdi = file->private_data;

	if (ftdi->disconnected > 0) {
		return -ENODEV;
	}
	if (count == 0) {
		goto exit;
	}
	urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!urb) {
		retval = -ENOMEM;
		goto error_1;
	}
	buf = usb_alloc_coherent(ftdi->udev, count, GFP_KERNEL,
				 &urb->transfer_dma);
	if (!buf) {
		retval = -ENOMEM;
		goto error_2;
	}
	if (copy_from_user(buf, user_buffer, count)) {
		retval = -EFAULT;
		goto error_3;
	}
	usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev,
							   ftdi->bulk_out_endpointAddr), buf, count,
			  ftdi_elan_write_bulk_callback, ftdi);
	urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
	retval = usb_submit_urb(urb, GFP_KERNEL);
	if (retval) {
		dev_err(&ftdi->udev->dev,
			"failed submitting write urb, error %d\n", retval);
		goto error_3;
	}
	usb_free_urb(urb);

exit:
	return count;
error_3:
	usb_free_coherent(ftdi->udev, count, buf, urb->transfer_dma);
error_2:
	usb_free_urb(urb);
error_1:
	return retval;
}

static const struct file_operations ftdi_elan_fops = {
	.owner = THIS_MODULE,
	.llseek = no_llseek,
	.read = ftdi_elan_read,
	.write = ftdi_elan_write,
	.open = ftdi_elan_open,
	.release = ftdi_elan_release,
};

/*
 * usb class driver info in order to get a minor number from the usb core,
 * and to have the device registered with the driver core
 */
static struct usb_class_driver ftdi_elan_jtag_class = {
	.name = "ftdi-%d-jtag",
	.fops = &ftdi_elan_fops,
	.minor_base = USB_FTDI_ELAN_MINOR_BASE,
};

/*
 * the following definitions are for the
 * ELAN FPGA state machgine processor that
 * lies on the other side of the FTDI chip
 */
#define cPCIu132rd 0x0
#define cPCIu132wr 0x1
#define cPCIiord 0x2
#define cPCIiowr 0x3
#define cPCImemrd 0x6
#define cPCImemwr 0x7
#define cPCIcfgrd 0xA
#define cPCIcfgwr 0xB
#define cPCInull 0xF
#define cU132cmd_status 0x0
#define cU132flash 0x1
#define cPIDsetup 0x0
#define cPIDout 0x1
#define cPIDin 0x2
#define cPIDinonce 0x3
#define cCCnoerror 0x0
#define cCCcrc 0x1
#define cCCbitstuff 0x2
#define cCCtoggle 0x3
#define cCCstall 0x4
#define cCCnoresp 0x5
#define cCCbadpid1 0x6
#define cCCbadpid2 0x7
#define cCCdataoverrun 0x8
#define cCCdataunderrun 0x9
#define cCCbuffoverrun 0xC
#define cCCbuffunderrun 0xD
#define cCCnotaccessed 0xF
static int ftdi_elan_write_reg(struct usb_ftdi *ftdi, u32 data)
{
wait:if (ftdi->disconnected > 0) {
		return -ENODEV;
	} else {
		int command_size;
		mutex_lock(&ftdi->u132_lock);
		command_size = ftdi->command_next - ftdi->command_head;
		if (command_size < COMMAND_SIZE) {
			struct u132_command *command = &ftdi->command[
				COMMAND_MASK & ftdi->command_next];
			command->header = 0x00 | cPCIu132wr;
			command->length = 0x04;
			command->address = 0x00;
			command->width = 0x00;
			command->follows = 4;
			command->value = data;
			command->buffer = &command->value;
			ftdi->command_next += 1;
			ftdi_elan_kick_command_queue(ftdi);
			mutex_unlock(&ftdi->u132_lock);
			return 0;
		} else {
			mutex_unlock(&ftdi->u132_lock);
			msleep(100);
			goto wait;
		}
	}
}

static int ftdi_elan_write_config(struct usb_ftdi *ftdi, int config_offset,
				  u8 width, u32 data)
{
	u8 addressofs = config_offset / 4;
wait:if (ftdi->disconnected > 0) {
		return -ENODEV;
	} else {
		int command_size;
		mutex_lock(&ftdi->u132_lock);
		command_size = ftdi->command_next - ftdi->command_head;
		if (command_size < COMMAND_SIZE) {
			struct u132_command *command = &ftdi->command[
				COMMAND_MASK & ftdi->command_next];
			command->header = 0x00 | (cPCIcfgwr & 0x0F);
			command->length = 0x04;
			command->address = addressofs;
			command->width = 0x00 | (width & 0x0F);
			command->follows = 4;
			command->value = data;
			command->buffer = &command->value;
			ftdi->command_next += 1;
			ftdi_elan_kick_command_queue(ftdi);
			mutex_unlock(&ftdi->u132_lock);
			return 0;
		} else {
			mutex_unlock(&ftdi->u132_lock);
			msleep(100);
			goto wait;
		}
	}
}

static int ftdi_elan_write_pcimem(struct usb_ftdi *ftdi, int mem_offset,
				  u8 width, u32 data)
{
	u8 addressofs = mem_offset / 4;
wait:if (ftdi->disconnected > 0) {
		return -ENODEV;
	} else {
		int command_size;
		mutex_lock(&ftdi->u132_lock);
		command_size = ftdi->command_next - ftdi->command_head;
		if (command_size < COMMAND_SIZE) {
			struct u132_command *command = &ftdi->command[
				COMMAND_MASK & ftdi->command_next];
			command->header = 0x00 | (cPCImemwr & 0x0F);
			command->length = 0x04;
			command->address = addressofs;
			command->width = 0x00 | (width & 0x0F);
			command->follows = 4;
			command->value = data;
			command->buffer = &command->value;
			ftdi->command_next += 1;
			ftdi_elan_kick_command_queue(ftdi);
			mutex_unlock(&ftdi->u132_lock);
			return 0;
		} else {
			mutex_unlock(&ftdi->u132_lock);
			msleep(100);
			goto wait;
		}
	}
}

int usb_ftdi_elan_write_pcimem(struct platform_device *pdev, int mem_offset,
			       u8 width, u32 data)
{
	struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
	return ftdi_elan_write_pcimem(ftdi, mem_offset, width, data);
}


EXPORT_SYMBOL_GPL(usb_ftdi_elan_write_pcimem);
static int ftdi_elan_read_reg(struct usb_ftdi *ftdi, u32 *data)
{
wait:if (ftdi->disconnected > 0) {
		return -ENODEV;
	} else {
		int command_size;
		int respond_size;
		mutex_lock(&ftdi->u132_lock);
		command_size = ftdi->command_next - ftdi->command_head;
		respond_size = ftdi->respond_next - ftdi->respond_head;
		if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE)
		{
			struct u132_command *command = &ftdi->command[
				COMMAND_MASK & ftdi->command_next];
			struct u132_respond *respond = &ftdi->respond[
				RESPOND_MASK & ftdi->respond_next];
			int result = -ENODEV;
			respond->result = &result;
			respond->header = command->header = 0x00 | cPCIu132rd;
			command->length = 0x04;
			respond->address = command->address = cU132cmd_status;
			command->width = 0x00;
			command->follows = 0;
			command->value = 0;
			command->buffer = NULL;
			respond->value = data;
			init_completion(&respond->wait_completion);
			ftdi->command_next += 1;
			ftdi->respond_next += 1;
			ftdi_elan_kick_command_queue(ftdi);
			mutex_unlock(&ftdi->u132_lock);
			wait_for_completion(&respond->wait_completion);
			return result;
		} else {
			mutex_unlock(&ftdi->u132_lock);
			msleep(100);
			goto wait;
		}
	}
}

static int ftdi_elan_read_config(struct usb_ftdi *ftdi, int config_offset,
				 u8 width, u32 *data)
{
	u8 addressofs = config_offset / 4;
wait:if (ftdi->disconnected > 0) {
		return -ENODEV;
	} else {
		int command_size;
		int respond_size;
		mutex_lock(&ftdi->u132_lock);
		command_size = ftdi->command_next - ftdi->command_head;
		respond_size = ftdi->respond_next - ftdi->respond_head;
		if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE)
		{
			struct u132_command *command = &ftdi->command[
				COMMAND_MASK & ftdi->command_next];
			struct u132_respond *respond = &ftdi->respond[
				RESPOND_MASK & ftdi->respond_next];
			int result = -ENODEV;
			respond->result = &result;
			respond->header = command->header = 0x00 | (cPCIcfgrd &
								    0x0F);
			command->length = 0x04;
			respond->address = command->address = addressofs;
			command->width = 0x00 | (width & 0x0F);
			command->follows = 0;
			command->value = 0;
			command->buffer = NULL;
			respond->value = data;
			init_completion(&respond->wait_completion);
			ftdi->command_next += 1;
			ftdi->respond_next += 1;
			ftdi_elan_kick_command_queue(ftdi);
			mutex_unlock(&ftdi->u132_lock);
			wait_for_completion(&respond->wait_completion);
			return result;
		} else {
			mutex_unlock(&ftdi->u132_lock);
			msleep(100);
			goto wait;
		}
	}
}

static int ftdi_elan_read_pcimem(struct usb_ftdi *ftdi, int mem_offset,
				 u8 width, u32 *data)
{
	u8 addressofs = mem_offset / 4;
wait:if (ftdi->disconnected > 0) {
		return -ENODEV;
	} else {
		int command_size;
		int respond_size;
		mutex_lock(&ftdi->u132_lock);
		command_size = ftdi->command_next - ftdi->command_head;
		respond_size = ftdi->respond_next - ftdi->respond_head;
		if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE)
		{
			struct u132_command *command = &ftdi->command[
				COMMAND_MASK & ftdi->command_next];
			struct u132_respond *respond = &ftdi->respond[
				RESPOND_MASK & ftdi->respond_next];
			int result = -ENODEV;
			respond->result = &result;
			respond->header = command->header = 0x00 | (cPCImemrd &
								    0x0F);
			command->length = 0x04;
			respond->address = command->address = addressofs;
			command->width = 0x00 | (width & 0x0F);
			command->follows = 0;
			command->value = 0;
			command->buffer = NULL;
			respond->value = data;
			init_completion(&respond->wait_completion);
			ftdi->command_next += 1;
			ftdi->respond_next += 1;
			ftdi_elan_kick_command_queue(ftdi);
			mutex_unlock(&ftdi->u132_lock);
			wait_for_completion(&respond->wait_completion);
			return result;
		} else {
			mutex_unlock(&ftdi->u132_lock);
			msleep(100);
			goto wait;
		}
	}
}

int usb_ftdi_elan_read_pcimem(struct platform_device *pdev, int mem_offset,
			      u8 width, u32 *data)
{
	struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
	if (ftdi->initialized == 0) {
		return -ENODEV;
	} else
		return ftdi_elan_read_pcimem(ftdi, mem_offset, width, data);
}


EXPORT_SYMBOL_GPL(usb_ftdi_elan_read_pcimem);
static int ftdi_elan_edset_setup(struct usb_ftdi *ftdi, u8 ed_number,
				 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
				 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
						   int toggle_bits, int error_count, int condition_code, int repeat_number,
						   int halted, int skipped, int actual, int non_null))
{
	u8 ed = ed_number - 1;
wait:if (ftdi->disconnected > 0) {
		return -ENODEV;
	} else if (ftdi->initialized == 0) {
		return -ENODEV;
	} else {
		int command_size;
		mutex_lock(&ftdi->u132_lock);
		command_size = ftdi->command_next - ftdi->command_head;
		if (command_size < COMMAND_SIZE) {
			struct u132_target *target = &ftdi->target[ed];
			struct u132_command *command = &ftdi->command[
				COMMAND_MASK & ftdi->command_next];
			command->header = 0x80 | (ed << 5);
			command->length = 0x8007;
			command->address = (toggle_bits << 6) | (ep_number << 2)
				| (address << 0);
			command->width = usb_maxpacket(urb->dev, urb->pipe,
						       usb_pipeout(urb->pipe));
			command->follows = 8;
			command->value = 0;
			command->buffer = urb->setup_packet;
			target->callback = callback;
			target->endp = endp;
			target->urb = urb;
			target->active = 1;
			ftdi->command_next += 1;
			ftdi_elan_kick_command_queue(ftdi);
			mutex_unlock(&ftdi->u132_lock);
			return 0;
		} else {
			mutex_unlock(&ftdi->u132_lock);
			msleep(100);
			goto wait;
		}
	}
}

int usb_ftdi_elan_edset_setup(struct platform_device *pdev, u8 ed_number,
			      void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
			      void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
						int toggle_bits, int error_count, int condition_code, int repeat_number,
						int halted, int skipped, int actual, int non_null))
{
	struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
	return ftdi_elan_edset_setup(ftdi, ed_number, endp, urb, address,
				     ep_number, toggle_bits, callback);
}


EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_setup);
static int ftdi_elan_edset_input(struct usb_ftdi *ftdi, u8 ed_number,
				 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
				 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
						   int toggle_bits, int error_count, int condition_code, int repeat_number,
						   int halted, int skipped, int actual, int non_null))
{
	u8 ed = ed_number - 1;
wait:if (ftdi->disconnected > 0) {
		return -ENODEV;
	} else if (ftdi->initialized == 0) {
		return -ENODEV;
	} else {
		int command_size;
		mutex_lock(&ftdi->u132_lock);
		command_size = ftdi->command_next - ftdi->command_head;
		if (command_size < COMMAND_SIZE) {
			struct u132_target *target = &ftdi->target[ed];
			struct u132_command *command = &ftdi->command[
				COMMAND_MASK & ftdi->command_next];
			u32 remaining_length = urb->transfer_buffer_length -
				urb->actual_length;
			command->header = 0x82 | (ed << 5);
			if (remaining_length == 0) {
				command->length = 0x0000;
			} else if (remaining_length > 1024) {
				command->length = 0x8000 | 1023;
			} else
				command->length = 0x8000 | (remaining_length -
							    1);
			command->address = (toggle_bits << 6) | (ep_number << 2)
				| (address << 0);
			command->width = usb_maxpacket(urb->dev, urb->pipe,
						       usb_pipeout(urb->pipe));
			command->follows = 0;
			command->value = 0;
			command->buffer = NULL;
			target->callback = callback;
			target->endp = endp;
			target->urb = urb;
			target->active = 1;
			ftdi->command_next += 1;
			ftdi_elan_kick_command_queue(ftdi);
			mutex_unlock(&ftdi->u132_lock);
			return 0;
		} else {
			mutex_unlock(&ftdi->u132_lock);
			msleep(100);
			goto wait;
		}
	}
}

int usb_ftdi_elan_edset_input(struct platform_device *pdev, u8 ed_number,
			      void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
			      void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
						int toggle_bits, int error_count, int condition_code, int repeat_number,
						int halted, int skipped, int actual, int non_null))
{
	struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
	return ftdi_elan_edset_input(ftdi, ed_number, endp, urb, address,
				     ep_number, toggle_bits, callback);
}


EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_input);
static int ftdi_elan_edset_empty(struct usb_ftdi *ftdi, u8 ed_number,
				 void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
				 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
						   int toggle_bits, int error_count, int condition_code, int repeat_number,
						   int halted, int skipped, int actual, int non_null))
{
	u8 ed = ed_number - 1;
wait:if (ftdi->disconnected > 0) {
		return -ENODEV;
	} else if (ftdi->initialized == 0) {
		return -ENODEV;
	} else {
		int command_size;
		mutex_lock(&ftdi->u132_lock);
		command_size = ftdi->command_next - ftdi->command_head;
		if (command_size < COMMAND_SIZE) {
			struct u132_target *target = &ftdi->target[ed];
			struct u132_command *command = &ftdi->command[
				COMMAND_MASK & ftdi->command_next];
			command->header = 0x81 | (ed << 5);
			command->length = 0x0000;
			command->address = (toggle_bits << 6) | (ep_number << 2)
				| (address << 0);
			command->width = usb_maxpacket(urb->dev, urb->pipe,
						       usb_pipeout(urb->pipe));
			command->follows = 0;
			command->value = 0;
			command->buffer = NULL;
			target->callback = callback;
			target->endp = endp;
			target->urb = urb;
			target->active = 1;
			ftdi->command_next += 1;
			ftdi_elan_kick_command_queue(ftdi);
			mutex_unlock(&ftdi->u132_lock);
			return 0;
		} else {
			mutex_unlock(&ftdi->u132_lock);
			msleep(100);
			goto wait;
		}
	}
}

int usb_ftdi_elan_edset_empty(struct platform_device *pdev, u8 ed_number,
			      void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
			      void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
						int toggle_bits, int error_count, int condition_code, int repeat_number,
						int halted, int skipped, int actual, int non_null))
{
	struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
	return ftdi_elan_edset_empty(ftdi, ed_number, endp, urb, address,
				     ep_number, toggle_bits, callback);
}


EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_empty);
static int ftdi_elan_edset_output(struct usb_ftdi *ftdi, u8 ed_number,
				  void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
				  void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
						    int toggle_bits, int error_count, int condition_code, int repeat_number,
						    int halted, int skipped, int actual, int non_null))
{
	u8 ed = ed_number - 1;
wait:if (ftdi->disconnected > 0) {
		return -ENODEV;
	} else if (ftdi->initialized == 0) {
		return -ENODEV;
	} else {
		int command_size;
		mutex_lock(&ftdi->u132_lock);
		command_size = ftdi->command_next - ftdi->command_head;
		if (command_size < COMMAND_SIZE) {
			u8 *b;
			u16 urb_size;
			int i = 0;
			char data[30 *3 + 4];
			char *d = data;
			int m = (sizeof(data) - 1) / 3 - 1;
			int l = 0;
			struct u132_target *target = &ftdi->target[ed];
			struct u132_command *command = &ftdi->command[
				COMMAND_MASK & ftdi->command_next];
			command->header = 0x81 | (ed << 5);
			command->address = (toggle_bits << 6) | (ep_number << 2)
				| (address << 0);
			command->width = usb_maxpacket(urb->dev, urb->pipe,
						       usb_pipeout(urb->pipe));
			command->follows = min_t(u32, 1024,
						 urb->transfer_buffer_length -
						 urb->actual_length);
			command->value = 0;
			command->buffer = urb->transfer_buffer +
				urb->actual_length;
			command->length = 0x8000 | (command->follows - 1);
			b = command->buffer;
			urb_size = command->follows;
			data[0] = 0;
			while (urb_size-- > 0) {
				if (i > m) {
				} else if (i++ < m) {
					int w = sprintf(d, " %02X", *b++);
					d += w;
					l += w;
				} else
					d += sprintf(d, " ..");
			}
			target->callback = callback;
			target->endp = endp;
			target->urb = urb;
			target->active = 1;
			ftdi->command_next += 1;
			ftdi_elan_kick_command_queue(ftdi);
			mutex_unlock(&ftdi->u132_lock);
			return 0;
		} else {
			mutex_unlock(&ftdi->u132_lock);
			msleep(100);
			goto wait;
		}
	}
}

int usb_ftdi_elan_edset_output(struct platform_device *pdev, u8 ed_number,
			       void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
			       void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
						 int toggle_bits, int error_count, int condition_code, int repeat_number,
						 int halted, int skipped, int actual, int non_null))
{
	struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
	return ftdi_elan_edset_output(ftdi, ed_number, endp, urb, address,
				      ep_number, toggle_bits, callback);
}


EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_output);
static int ftdi_elan_edset_single(struct usb_ftdi *ftdi, u8 ed_number,
				  void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
				  void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
						    int toggle_bits, int error_count, int condition_code, int repeat_number,
						    int halted, int skipped, int actual, int non_null))
{
	u8 ed = ed_number - 1;
wait:if (ftdi->disconnected > 0) {
		return -ENODEV;
	} else if (ftdi->initialized == 0) {
		return -ENODEV;
	} else {
		int command_size;
		mutex_lock(&ftdi->u132_lock);
		command_size = ftdi->command_next - ftdi->command_head;
		if (command_size < COMMAND_SIZE) {
			u32 remaining_length = urb->transfer_buffer_length -
				urb->actual_length;
			struct u132_target *target = &ftdi->target[ed];
			struct u132_command *command = &ftdi->command[
				COMMAND_MASK & ftdi->command_next];
			command->header = 0x83 | (ed << 5);
			if (remaining_length == 0) {
				command->length = 0x0000;
			} else if (remaining_length > 1024) {
				command->length = 0x8000 | 1023;
			} else
				command->length = 0x8000 | (remaining_length -
							    1);
			command->address = (toggle_bits << 6) | (ep_number << 2)
				| (address << 0);
			command->width = usb_maxpacket(urb->dev, urb->pipe,
						       usb_pipeout(urb->pipe));
			command->follows = 0;
			command->value = 0;
			command->buffer = NULL;
			target->callback = callback;
			target->endp = endp;
			target->urb = urb;
			target->active = 1;
			ftdi->command_next += 1;
			ftdi_elan_kick_command_queue(ftdi);
			mutex_unlock(&ftdi->u132_lock);
			return 0;
		} else {
			mutex_unlock(&ftdi->u132_lock);
			msleep(100);
			goto wait;
		}
	}
}

int usb_ftdi_elan_edset_single(struct platform_device *pdev, u8 ed_number,
			       void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,
			       void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
						 int toggle_bits, int error_count, int condition_code, int repeat_number,
						 int halted, int skipped, int actual, int non_null))
{
	struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
	return ftdi_elan_edset_single(ftdi, ed_number, endp, urb, address,
				      ep_number, toggle_bits, callback);
}


EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_single);
static int ftdi_elan_edset_flush(struct usb_ftdi *ftdi, u8 ed_number,
				 void *endp)
{
	u8 ed = ed_number - 1;
	if (ftdi->disconnected > 0) {
		return -ENODEV;
	} else if (ftdi->initialized == 0) {
		return -ENODEV;
	} else {
		struct u132_target *target = &ftdi->target[ed];
		mutex_lock(&ftdi->u132_lock);
		if (target->abandoning > 0) {
			mutex_unlock(&ftdi->u132_lock);
			return 0;
		} else {
			target->abandoning = 1;
		wait_1:if (target->active == 1) {
				int command_size = ftdi->command_next -
					ftdi->command_head;
				if (command_size < COMMAND_SIZE) {
					struct u132_command *command =
						&ftdi->command[COMMAND_MASK &
							       ftdi->command_next];
					command->header = 0x80 | (ed << 5) |
						0x4;
					command->length = 0x00;
					command->address = 0x00;
					command->width = 0x00;
					command->follows = 0;
					command->value = 0;
					command->buffer = &command->value;
					ftdi->command_next += 1;
					ftdi_elan_kick_command_queue(ftdi);
				} else {
					mutex_unlock(&ftdi->u132_lock);
					msleep(100);
					mutex_lock(&ftdi->u132_lock);
					goto wait_1;
				}
			}
			mutex_unlock(&ftdi->u132_lock);
			return 0;
		}
	}
}

int usb_ftdi_elan_edset_flush(struct platform_device *pdev, u8 ed_number,
			      void *endp)
{
	struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);
	return ftdi_elan_edset_flush(ftdi, ed_number, endp);
}


EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_flush);
static int ftdi_elan_flush_input_fifo(struct usb_ftdi *ftdi)
{
	int retry_on_empty = 10;
	int retry_on_timeout = 5;
	int retry_on_status = 20;
more:{
		int packet_bytes = 0;
		int retval = usb_bulk_msg(ftdi->udev,
					  usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr),
					  ftdi->bulk_in_buffer, ftdi->bulk_in_size,
					  &packet_bytes, 100);
		if (packet_bytes > 2) {
			char diag[30 *3 + 4];
			char *d = diag;
			int m = (sizeof(diag) - 1) / 3 - 1;
			char *b = ftdi->bulk_in_buffer;
			int bytes_read = 0;
			diag[0] = 0;
			while (packet_bytes-- > 0) {
				char c = *b++;
				if (bytes_read < m) {
					d += sprintf(d, " %02X",
						     0x000000FF & c);
				} else if (bytes_read > m) {
				} else
					d += sprintf(d, " ..");
				bytes_read += 1;
				continue;
			}
			goto more;
		} else if (packet_bytes > 1) {
			char s1 = ftdi->bulk_in_buffer[0];
			char s2 = ftdi->bulk_in_buffer[1];
			if (s1 == 0x31 && s2 == 0x60) {
				return 0;
			} else if (retry_on_status-- > 0) {
				goto more;
			} else {
				dev_err(&ftdi->udev->dev, "STATUS ERROR retry limit reached\n");
				return -EFAULT;
			}
		} else if (packet_bytes > 0) {
			char b1 = ftdi->bulk_in_buffer[0];
			dev_err(&ftdi->udev->dev, "only one byte flushed from FTDI = %02X\n",
				b1);
			if (retry_on_status-- > 0) {
				goto more;
			} else {
				dev_err(&ftdi->udev->dev, "STATUS ERROR retry limit reached\n");
				return -EFAULT;
			}
		} else if (retval == -ETIMEDOUT) {
			if (retry_on_timeout-- > 0) {
				goto more;
			} else {
				dev_err(&ftdi->udev->dev, "TIMED OUT retry limit reached\n");
				return -ENOMEM;
			}
		} else if (retval == 0) {
			if (retry_on_empty-- > 0) {
				goto more;
			} else {
				dev_err(&ftdi->udev->dev, "empty packet retry limit reached\n");
				return -ENOMEM;
			}
		} else {
			dev_err(&ftdi->udev->dev, "error = %d\n", retval);
			return retval;
		}
	}
	return -1;
}


/*
 * send the long flush sequence
 *
 */
static int ftdi_elan_synchronize_flush(struct usb_ftdi *ftdi)
{
	int retval;
	struct urb *urb;
	char *buf;
	int I = 257;
	int i = 0;
	urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!urb) {
		dev_err(&ftdi->udev->dev, "could not alloc a urb for flush sequence\n");
		return -ENOMEM;
	}
	buf = usb_alloc_coherent(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma);
	if (!buf) {
		dev_err(&ftdi->udev->dev, "could not get a buffer for flush sequence\n");
		usb_free_urb(urb);
		return -ENOMEM;
	}
	while (I-- > 0)
		buf[i++] = 0x55;
	usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev,
							   ftdi->bulk_out_endpointAddr), buf, i,
			  ftdi_elan_write_bulk_callback, ftdi);
	urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
	retval = usb_submit_urb(urb, GFP_KERNEL);
	if (retval) {
		dev_err(&ftdi->udev->dev, "failed to submit urb containing the flush sequence\n");
		usb_free_coherent(ftdi->udev, i, buf, urb->transfer_dma);
		usb_free_urb(urb);
		return -ENOMEM;
	}
	usb_free_urb(urb);
	return 0;
}


/*
 * send the reset sequence
 *
 */
static int ftdi_elan_synchronize_reset(struct usb_ftdi *ftdi)
{
	int retval;
	struct urb *urb;
	char *buf;
	int I = 4;
	int i = 0;
	urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!urb) {
		dev_err(&ftdi->udev->dev, "could not get a urb for the reset sequence\n");
		return -ENOMEM;
	}
	buf = usb_alloc_coherent(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma);
	if (!buf) {
		dev_err(&ftdi->udev->dev, "could not get a buffer for the reset sequence\n");
		usb_free_urb(urb);
		return -ENOMEM;
	}
	buf[i++] = 0x55;
	buf[i++] = 0xAA;
	buf[i++] = 0x5A;
	buf[i++] = 0xA5;
	usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev,
							   ftdi->bulk_out_endpointAddr), buf, i,
			  ftdi_elan_write_bulk_callback, ftdi);
	urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
	retval = usb_submit_urb(urb, GFP_KERNEL);
	if (retval) {
		dev_err(&ftdi->udev->dev, "failed to submit urb containing the reset sequence\n");
		usb_free_coherent(ftdi->udev, i, buf, urb->transfer_dma);
		usb_free_urb(urb);
		return -ENOMEM;
	}
	usb_free_urb(urb);
	return 0;
}

static int ftdi_elan_synchronize(struct usb_ftdi *ftdi)
{
	int retval;
	int long_stop = 10;
	int retry_on_timeout = 5;
	int retry_on_empty = 10;
	int err_count = 0;
	retval = ftdi_elan_flush_input_fifo(ftdi);
	if (retval)
		return retval;
	ftdi->bulk_in_left = 0;
	ftdi->bulk_in_last = -1;
	while (long_stop-- > 0) {
		int read_stop;
		int read_stuck;
		retval = ftdi_elan_synchronize_flush(ftdi);
		if (retval)
			return retval;
		retval = ftdi_elan_flush_input_fifo(ftdi);
		if (retval)
			return retval;
	reset:retval = ftdi_elan_synchronize_reset(ftdi);
		if (retval)
			return retval;
		read_stop = 100;
		read_stuck = 10;
	read:{
			int packet_bytes = 0;
			retval = usb_bulk_msg(ftdi->udev,
					      usb_rcvbulkpipe(ftdi->udev,
							      ftdi->bulk_in_endpointAddr),
					      ftdi->bulk_in_buffer, ftdi->bulk_in_size,
					      &packet_bytes, 500);
			if (packet_bytes > 2) {
				char diag[30 *3 + 4];
				char *d = diag;
				int m = (sizeof(diag) - 1) / 3 - 1;
				char *b = ftdi->bulk_in_buffer;
				int bytes_read = 0;
				unsigned char c = 0;
				diag[0] = 0;
				while (packet_bytes-- > 0) {
					c = *b++;
					if (bytes_read < m) {
						d += sprintf(d, " %02X", c);
					} else if (bytes_read > m) {
					} else
						d += sprintf(d, " ..");
					bytes_read += 1;
					continue;
				}
				if (c == 0x7E) {
					return 0;
				} else {
					if (c == 0x55) {
						goto read;
					} else if (read_stop-- > 0) {
						goto read;
					} else {
						dev_err(&ftdi->udev->dev, "retry limit reached\n");
						continue;
					}
				}
			} else if (packet_bytes > 1) {
				unsigned char s1 = ftdi->bulk_in_buffer[0];
				unsigned char s2 = ftdi->bulk_in_buffer[1];
				if (s1 == 0x31 && s2 == 0x00) {
					if (read_stuck-- > 0) {
						goto read;
					} else
						goto reset;
				} else if (s1 == 0x31 && s2 == 0x60) {
					if (read_stop-- > 0) {
						goto read;
					} else {
						dev_err(&ftdi->udev->dev, "retry limit reached\n");
						continue;
					}
				} else {
					if (read_stop-- > 0) {
						goto read;
					} else {
						dev_err(&ftdi->udev->dev, "retry limit reached\n");
						continue;
					}
				}
			} else if (packet_bytes > 0) {
				if (read_stop-- > 0) {
					goto read;
				} else {
					dev_err(&ftdi->udev->dev, "retry limit reached\n");
					continue;
				}
			} else if (retval == -ETIMEDOUT) {
				if (retry_on_timeout-- > 0) {
					goto read;
				} else {
					dev_err(&ftdi->udev->dev, "TIMED OUT retry limit reached\n");
					continue;
				}
			} else if (retval == 0) {
				if (retry_on_empty-- > 0) {
					goto read;
				} else {
					dev_err(&ftdi->udev->dev, "empty packet retry limit reached\n");
					continue;
				}
			} else {
				err_count += 1;
				dev_err(&ftdi->udev->dev, "error = %d\n",
					retval);
				if (read_stop-- > 0) {
					goto read;
				} else {
					dev_err(&ftdi->udev->dev, "retry limit reached\n");
					continue;
				}
			}
		}
	}
	dev_err(&ftdi->udev->dev, "failed to synchronize\n");
	return -EFAULT;
}

static int ftdi_elan_stuck_waiting(struct usb_ftdi *ftdi)
{
	int retry_on_empty = 10;
	int retry_on_timeout = 5;
	int retry_on_status = 50;
more:{
		int packet_bytes = 0;
		int retval = usb_bulk_msg(ftdi->udev,
					  usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr),
					  ftdi->bulk_in_buffer, ftdi->bulk_in_size,
					  &packet_bytes, 1000);
		if (packet_bytes > 2) {
			char diag[30 *3 + 4];
			char *d = diag;
			int m = (sizeof(diag) - 1) / 3 - 1;
			char *b = ftdi->bulk_in_buffer;
			int bytes_read = 0;
			diag[0] = 0;
			while (packet_bytes-- > 0) {
				char c = *b++;
				if (bytes_read < m) {
					d += sprintf(d, " %02X",
						     0x000000FF & c);
				} else if (bytes_read > m) {
				} else
					d += sprintf(d, " ..");
				bytes_read += 1;
				continue;
			}
			goto more;
		} else if (packet_bytes > 1) {
			char s1 = ftdi->bulk_in_buffer[0];
			char s2 = ftdi->bulk_in_buffer[1];
			if (s1 == 0x31 && s2 == 0x60) {
				return 0;
			} else if (retry_on_status-- > 0) {
				msleep(5);
				goto more;
			} else
				return -EFAULT;
		} else if (packet_bytes > 0) {
			char b1 = ftdi->bulk_in_buffer[0];
			dev_err(&ftdi->udev->dev, "only one byte flushed from FTDI = %02X\n", b1);
			if (retry_on_status-- > 0) {
				msleep(5);
				goto more;
			} else {
				dev_err(&ftdi->udev->dev, "STATUS ERROR retry limit reached\n");
				return -EFAULT;
			}
		} else if (retval == -ETIMEDOUT) {
			if (retry_on_timeout-- > 0) {
				goto more;
			} else {
				dev_err(&ftdi->udev->dev, "TIMED OUT retry limit reached\n");
				return -ENOMEM;
			}
		} else if (retval == 0) {
			if (retry_on_empty-- > 0) {
				goto more;
			} else {
				dev_err(&ftdi->udev->dev, "empty packet retry limit reached\n");
				return -ENOMEM;
			}
		} else {
			dev_err(&ftdi->udev->dev, "error = %d\n", retval);
			return -ENOMEM;
		}
	}
	return -1;
}

static int ftdi_elan_checkingPCI(struct usb_ftdi *ftdi)
{
	int UxxxStatus = ftdi_elan_read_reg(ftdi, &ftdi->controlreg);
	if (UxxxStatus)
		return UxxxStatus;
	if (ftdi->controlreg & 0x00400000) {
		if (ftdi->card_ejected) {
		} else {
			ftdi->card_ejected = 1;
			dev_err(&ftdi->udev->dev, "CARD EJECTED - controlreg = %08X\n",
				ftdi->controlreg);
		}
		return -ENODEV;
	} else {
		u8 fn = ftdi->function - 1;
		int activePCIfn = fn << 8;
		u32 pcidata;
		u32 pciVID;
		u32 pciPID;
		int reg = 0;
		UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
						   &pcidata);
		if (UxxxStatus)
			return UxxxStatus;
		pciVID = pcidata & 0xFFFF;
		pciPID = (pcidata >> 16) & 0xFFFF;
		if (pciVID == ftdi->platform_data.vendor && pciPID ==
		    ftdi->platform_data.device) {
			return 0;
		} else {
			dev_err(&ftdi->udev->dev, "vendor=%04X pciVID=%04X device=%04X pciPID=%04X\n",
				ftdi->platform_data.vendor, pciVID,
				ftdi->platform_data.device, pciPID);
			return -ENODEV;
		}
	}
}


#define ftdi_read_pcimem(ftdi, member, data) ftdi_elan_read_pcimem(ftdi, \
								   offsetof(struct ohci_regs, member), 0, data);
#define ftdi_write_pcimem(ftdi, member, data) ftdi_elan_write_pcimem(ftdi, \
								     offsetof(struct ohci_regs, member), 0, data);

#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
#define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD |	\
			OHCI_INTR_WDH)
static int ftdi_elan_check_controller(struct usb_ftdi *ftdi, int quirk)
{
	int devices = 0;
	int retval;
	u32 hc_control;
	int num_ports;
	u32 control;
	u32 rh_a = -1;
	u32 status;
	u32 fminterval;
	u32 hc_fminterval;
	u32 periodicstart;
	u32 cmdstatus;
	u32 roothub_a;
	int mask = OHCI_INTR_INIT;
	int sleep_time = 0;
	int reset_timeout = 30;        /* ... allow extra time */
	int temp;
	retval = ftdi_write_pcimem(ftdi, intrdisable, OHCI_INTR_MIE);
	if (retval)
		return retval;
	retval = ftdi_read_pcimem(ftdi, control, &control);
	if (retval)
		return retval;
	retval = ftdi_read_pcimem(ftdi, roothub.a, &rh_a);
	if (retval)
		return retval;
	num_ports = rh_a & RH_A_NDP;
	retval = ftdi_read_pcimem(ftdi, fminterval, &hc_fminterval);
	if (retval)
		return retval;
	hc_fminterval &= 0x3fff;
	if (hc_fminterval != FI) {
	}
	hc_fminterval |= FSMP(hc_fminterval) << 16;
	retval = ftdi_read_pcimem(ftdi, control, &hc_control);
	if (retval)
		return retval;
	switch (hc_control & OHCI_CTRL_HCFS) {
	case OHCI_USB_OPER:
		sleep_time = 0;
		break;
	case OHCI_USB_SUSPEND:
	case OHCI_USB_RESUME:
		hc_control &= OHCI_CTRL_RWC;
		hc_control |= OHCI_USB_RESUME;
		sleep_time = 10;
		break;
	default:
		hc_control &= OHCI_CTRL_RWC;
		hc_control |= OHCI_USB_RESET;
		sleep_time = 50;
		break;
	}
	retval = ftdi_write_pcimem(ftdi, control, hc_control);
	if (retval)
		return retval;
	retval = ftdi_read_pcimem(ftdi, control, &control);
	if (retval)
		return retval;
	msleep(sleep_time);
	retval = ftdi_read_pcimem(ftdi, roothub.a, &roothub_a);
	if (retval)
		return retval;
	if (!(roothub_a & RH_A_NPS)) {        /* power down each port */
		for (temp = 0; temp < num_ports; temp++) {
			retval = ftdi_write_pcimem(ftdi,
						   roothub.portstatus[temp], RH_PS_LSDA);
			if (retval)
				return retval;
		}
	}
	retval = ftdi_read_pcimem(ftdi, control, &control);
	if (retval)
		return retval;
retry:retval = ftdi_read_pcimem(ftdi, cmdstatus, &status);
	if (retval)
		return retval;
	retval = ftdi_write_pcimem(ftdi, cmdstatus, OHCI_HCR);
	if (retval)
		return retval;
extra:{
		retval = ftdi_read_pcimem(ftdi, cmdstatus, &status);
		if (retval)
			return retval;
		if (0 != (status & OHCI_HCR)) {
			if (--reset_timeout == 0) {
				dev_err(&ftdi->udev->dev, "USB HC reset timed out!\n");
				return -ENODEV;
			} else {
				msleep(5);
				goto extra;
			}
		}
	}
	if (quirk & OHCI_QUIRK_INITRESET) {
		retval = ftdi_write_pcimem(ftdi, control, hc_control);
		if (retval)
			return retval;
		retval = ftdi_read_pcimem(ftdi, control, &control);
		if (retval)
			return retval;
	}
	retval = ftdi_write_pcimem(ftdi, ed_controlhead, 0x00000000);
	if (retval)
		return retval;
	retval = ftdi_write_pcimem(ftdi, ed_bulkhead, 0x11000000);
	if (retval)
		return retval;
	retval = ftdi_write_pcimem(ftdi, hcca, 0x00000000);
	if (retval)
		return retval;
	retval = ftdi_read_pcimem(ftdi, fminterval, &fminterval);
	if (retval)
		return retval;
	retval = ftdi_write_pcimem(ftdi, fminterval,
				   ((fminterval & FIT) ^ FIT) | hc_fminterval);
	if (retval)
		return retval;
	retval = ftdi_write_pcimem(ftdi, periodicstart,
				   ((9 *hc_fminterval) / 10) & 0x3fff);
	if (retval)
		return retval;
	retval = ftdi_read_pcimem(ftdi, fminterval, &fminterval);
	if (retval)
		return retval;
	retval = ftdi_read_pcimem(ftdi, periodicstart, &periodicstart);
	if (retval)
		return retval;
	if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
		if (!(quirk & OHCI_QUIRK_INITRESET)) {
			quirk |= OHCI_QUIRK_INITRESET;
			goto retry;
		} else
			dev_err(&ftdi->udev->dev, "init err(%08x %04x)\n",
				fminterval, periodicstart);
	}                        /* start controller operations */
	hc_control &= OHCI_CTRL_RWC;
	hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
	retval = ftdi_write_pcimem(ftdi, control, hc_control);
	if (retval)
		return retval;
	retval = ftdi_write_pcimem(ftdi, cmdstatus, OHCI_BLF);
	if (retval)
		return retval;
	retval = ftdi_read_pcimem(ftdi, cmdstatus, &cmdstatus);
	if (retval)
		return retval;
	retval = ftdi_read_pcimem(ftdi, control, &control);
	if (retval)
		return retval;
	retval = ftdi_write_pcimem(ftdi, roothub.status, RH_HS_DRWE);
	if (retval)
		return retval;
	retval = ftdi_write_pcimem(ftdi, intrstatus, mask);
	if (retval)
		return retval;
	retval = ftdi_write_pcimem(ftdi, intrdisable,
				   OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
				   OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
				   OHCI_INTR_SO);
	if (retval)
		return retval;        /* handle root hub init quirks ... */
	retval = ftdi_read_pcimem(ftdi, roothub.a, &roothub_a);
	if (retval)
		return retval;
	roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
	if (quirk & OHCI_QUIRK_SUPERIO) {
		roothub_a |= RH_A_NOCP;
		roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
		retval = ftdi_write_pcimem(ftdi, roothub.a, roothub_a);
		if (retval)
			return retval;
	} else if ((quirk & OHCI_QUIRK_AMD756) || distrust_firmware) {
		roothub_a |= RH_A_NPS;
		retval = ftdi_write_pcimem(ftdi, roothub.a, roothub_a);
		if (retval)
			return retval;
	}
	retval = ftdi_write_pcimem(ftdi, roothub.status, RH_HS_LPSC);
	if (retval)
		return retval;
	retval = ftdi_write_pcimem(ftdi, roothub.b,
				   (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
	if (retval)
		return retval;
	retval = ftdi_read_pcimem(ftdi, control, &control);
	if (retval)
		return retval;
	mdelay((roothub_a >> 23) & 0x1fe);
	for (temp = 0; temp < num_ports; temp++) {
		u32 portstatus;
		retval = ftdi_read_pcimem(ftdi, roothub.portstatus[temp],
					  &portstatus);
		if (retval)
			return retval;
		if (1 & portstatus)
			devices += 1;
	}
	return devices;
}

static int ftdi_elan_setup_controller(struct usb_ftdi *ftdi, int fn)
{
	u32 latence_timer;
	int UxxxStatus;
	u32 pcidata;
	int reg = 0;
	int activePCIfn = fn << 8;
	UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800);
	if (UxxxStatus)
		return UxxxStatus;
	reg = 16;
	UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0,
					    0xFFFFFFFF);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
					   &pcidata);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0,
					    0xF0000000);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
					   &pcidata);
	if (UxxxStatus)
		return UxxxStatus;
	reg = 12;
	UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
					   &latence_timer);
	if (UxxxStatus)
		return UxxxStatus;
	latence_timer &= 0xFFFF00FF;
	latence_timer |= 0x00001600;
	UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00,
					    latence_timer);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
					   &pcidata);
	if (UxxxStatus)
		return UxxxStatus;
	reg = 4;
	UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00,
					    0x06);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
					   &pcidata);
	if (UxxxStatus)
		return UxxxStatus;
	for (reg = 0; reg <= 0x54; reg += 4) {
		UxxxStatus = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
		if (UxxxStatus)
			return UxxxStatus;
	}
	return 0;
}

static int ftdi_elan_close_controller(struct usb_ftdi *ftdi, int fn)
{
	u32 latence_timer;
	int UxxxStatus;
	u32 pcidata;
	int reg = 0;
	int activePCIfn = fn << 8;
	UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800);
	if (UxxxStatus)
		return UxxxStatus;
	reg = 16;
	UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0,
					    0xFFFFFFFF);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
					   &pcidata);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0,
					    0x00000000);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
					   &pcidata);
	if (UxxxStatus)
		return UxxxStatus;
	reg = 12;
	UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
					   &latence_timer);
	if (UxxxStatus)
		return UxxxStatus;
	latence_timer &= 0xFFFF00FF;
	latence_timer |= 0x00001600;
	UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00,
					    latence_timer);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
					   &pcidata);
	if (UxxxStatus)
		return UxxxStatus;
	reg = 4;
	UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00,
					    0x00);
	if (UxxxStatus)
		return UxxxStatus;
	return ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, &pcidata);
}

static int ftdi_elan_found_controller(struct usb_ftdi *ftdi, int fn, int quirk)
{
	int result;
	int UxxxStatus;
	UxxxStatus = ftdi_elan_setup_controller(ftdi, fn);
	if (UxxxStatus)
		return UxxxStatus;
	result = ftdi_elan_check_controller(ftdi, quirk);
	UxxxStatus = ftdi_elan_close_controller(ftdi, fn);
	if (UxxxStatus)
		return UxxxStatus;
	return result;
}

static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi)
{
	u32 controlreg;
	u8 sensebits;
	int UxxxStatus;
	UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000000L);
	if (UxxxStatus)
		return UxxxStatus;
	msleep(750);
	UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x100);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x500);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020CL | 0x000);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020DL | 0x000);
	if (UxxxStatus)
		return UxxxStatus;
	msleep(250);
	UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020FL | 0x000);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x800);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
	if (UxxxStatus)
		return UxxxStatus;
	UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
	if (UxxxStatus)
		return UxxxStatus;
	msleep(1000);
	sensebits = (controlreg >> 16) & 0x000F;
	if (0x0D == sensebits)
		return 0;
	else
		return - ENXIO;
}

static int ftdi_elan_setupOHCI(struct usb_ftdi *ftdi)
{
	int UxxxStatus;
	u32 pcidata;
	int reg = 0;
	u8 fn;
	int activePCIfn = 0;
	int max_devices = 0;
	int controllers = 0;
	int unrecognized = 0;
	ftdi->function = 0;
	for (fn = 0; (fn < 4); fn++) {
		u32 pciVID = 0;
		u32 pciPID = 0;
		int devices = 0;
		activePCIfn = fn << 8;
		UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
						   &pcidata);
		if (UxxxStatus)
			return UxxxStatus;
		pciVID = pcidata & 0xFFFF;
		pciPID = (pcidata >> 16) & 0xFFFF;
		if ((pciVID == PCI_VENDOR_ID_OPTI) && (pciPID == 0xc861)) {
			devices = ftdi_elan_found_controller(ftdi, fn, 0);
			controllers += 1;
		} else if ((pciVID == PCI_VENDOR_ID_NEC) && (pciPID == 0x0035))
		{
			devices = ftdi_elan_found_controller(ftdi, fn, 0);
			controllers += 1;
		} else if ((pciVID == PCI_VENDOR_ID_AL) && (pciPID == 0x5237)) {
			devices = ftdi_elan_found_controller(ftdi, fn, 0);
			controllers += 1;
		} else if ((pciVID == PCI_VENDOR_ID_ATT) && (pciPID == 0x5802))
		{
			devices = ftdi_elan_found_controller(ftdi, fn, 0);
			controllers += 1;
		} else if (pciVID == PCI_VENDOR_ID_AMD && pciPID == 0x740c) {
			devices = ftdi_elan_found_controller(ftdi, fn,
							     OHCI_QUIRK_AMD756);
			controllers += 1;
		} else if (pciVID == PCI_VENDOR_ID_COMPAQ && pciPID == 0xa0f8) {
			devices = ftdi_elan_found_controller(ftdi, fn,
							     OHCI_QUIRK_ZFMICRO);
			controllers += 1;
		} else if (0 == pcidata) {
		} else
			unrecognized += 1;
		if (devices > max_devices) {
			max_devices = devices;
			ftdi->function = fn + 1;
			ftdi->platform_data.vendor = pciVID;
			ftdi->platform_data.device = pciPID;
		}
	}
	if (ftdi->function > 0) {
		return ftdi_elan_setup_controller(ftdi,	ftdi->function - 1);
	} else if (controllers > 0) {
		return -ENXIO;
	} else if (unrecognized > 0) {
		return -ENXIO;
	} else {
		ftdi->enumerated = 0;
		return -ENXIO;
	}
}


/*
 * we use only the first bulk-in and bulk-out endpoints
 */
static int ftdi_elan_probe(struct usb_interface *interface,
			   const struct usb_device_id *id)
{
	struct usb_host_interface *iface_desc;
	struct usb_endpoint_descriptor *endpoint;
	size_t buffer_size;
	int i;
	int retval = -ENOMEM;
	struct usb_ftdi *ftdi;

	ftdi = kzalloc(sizeof(struct usb_ftdi), GFP_KERNEL);
	if (!ftdi)
		return -ENOMEM;

	mutex_lock(&ftdi_module_lock);
	list_add_tail(&ftdi->ftdi_list, &ftdi_static_list);
	ftdi->sequence_num = ++ftdi_instances;
	mutex_unlock(&ftdi_module_lock);
	ftdi_elan_init_kref(ftdi);
	sema_init(&ftdi->sw_lock, 1);
	ftdi->udev = usb_get_dev(interface_to_usbdev(interface));
	ftdi->interface = interface;
	mutex_init(&ftdi->u132_lock);
	ftdi->expected = 4;
	iface_desc = interface->cur_altsetting;
	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
		endpoint = &iface_desc->endpoint[i].desc;
		if (!ftdi->bulk_in_endpointAddr &&
		    usb_endpoint_is_bulk_in(endpoint)) {
			buffer_size = usb_endpoint_maxp(endpoint);
			ftdi->bulk_in_size = buffer_size;
			ftdi->bulk_in_endpointAddr = endpoint->bEndpointAddress;
			ftdi->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
			if (!ftdi->bulk_in_buffer) {
				dev_err(&ftdi->udev->dev, "Could not allocate bulk_in_buffer\n");
				retval = -ENOMEM;
				goto error;
			}
		}
		if (!ftdi->bulk_out_endpointAddr &&
		    usb_endpoint_is_bulk_out(endpoint)) {
			ftdi->bulk_out_endpointAddr =
				endpoint->bEndpointAddress;
		}
	}
	if (!(ftdi->bulk_in_endpointAddr && ftdi->bulk_out_endpointAddr)) {
		dev_err(&ftdi->udev->dev, "Could not find both bulk-in and bulk-out endpoints\n");
		retval = -ENODEV;
		goto error;
	}
	dev_info(&ftdi->udev->dev, "interface %d has I=%02X O=%02X\n",
		 iface_desc->desc.bInterfaceNumber, ftdi->bulk_in_endpointAddr,
		 ftdi->bulk_out_endpointAddr);
	usb_set_intfdata(interface, ftdi);
	if (iface_desc->desc.bInterfaceNumber == 0 &&
	    ftdi->bulk_in_endpointAddr == 0x81 &&
	    ftdi->bulk_out_endpointAddr == 0x02) {
		retval = usb_register_dev(interface, &ftdi_elan_jtag_class);
		if (retval) {
			dev_err(&ftdi->udev->dev, "Not able to get a minor for this device\n");
			usb_set_intfdata(interface, NULL);
			retval = -ENOMEM;
			goto error;
		} else {
			ftdi->class = &ftdi_elan_jtag_class;
			dev_info(&ftdi->udev->dev, "USB FDTI=%p JTAG interface %d now attached to ftdi%d\n",
				 ftdi, iface_desc->desc.bInterfaceNumber,
				 interface->minor);
			return 0;
		}
	} else if (iface_desc->desc.bInterfaceNumber == 1 &&
		   ftdi->bulk_in_endpointAddr == 0x83 &&
		   ftdi->bulk_out_endpointAddr == 0x04) {
		ftdi->class = NULL;
		dev_info(&ftdi->udev->dev, "USB FDTI=%p ELAN interface %d now activated\n",
			 ftdi, iface_desc->desc.bInterfaceNumber);
		INIT_DELAYED_WORK(&ftdi->status_work, ftdi_elan_status_work);
		INIT_DELAYED_WORK(&ftdi->command_work, ftdi_elan_command_work);
		INIT_DELAYED_WORK(&ftdi->respond_work, ftdi_elan_respond_work);
		ftdi_status_queue_work(ftdi, msecs_to_jiffies(3 *1000));
		return 0;
	} else {
		dev_err(&ftdi->udev->dev,
			"Could not find ELAN's U132 device\n");
		retval = -ENODEV;
		goto error;
	}
error:if (ftdi) {
		ftdi_elan_put_kref(ftdi);
	}
	return retval;
}

static void ftdi_elan_disconnect(struct usb_interface *interface)
{
	struct usb_ftdi *ftdi = usb_get_intfdata(interface);
	ftdi->disconnected += 1;
	if (ftdi->class) {
		int minor = interface->minor;
		struct usb_class_driver *class = ftdi->class;
		usb_set_intfdata(interface, NULL);
		usb_deregister_dev(interface, class);
		dev_info(&ftdi->udev->dev, "USB FTDI U132 jtag interface on minor %d now disconnected\n",
			 minor);
	} else {
		ftdi_status_cancel_work(ftdi);
		ftdi_command_cancel_work(ftdi);
		ftdi_response_cancel_work(ftdi);
		ftdi_elan_abandon_completions(ftdi);
		ftdi_elan_abandon_targets(ftdi);
		if (ftdi->registered) {
			platform_device_unregister(&ftdi->platform_dev);
			ftdi->synchronized = 0;
			ftdi->enumerated = 0;
			ftdi->initialized = 0;
			ftdi->registered = 0;
		}
		flush_workqueue(status_queue);
		flush_workqueue(command_queue);
		flush_workqueue(respond_queue);
		ftdi->disconnected += 1;
		usb_set_intfdata(interface, NULL);
		dev_info(&ftdi->udev->dev, "USB FTDI U132 host controller interface now disconnected\n");
	}
	ftdi_elan_put_kref(ftdi);
}

static struct usb_driver ftdi_elan_driver = {
	.name = "ftdi-elan",
	.probe = ftdi_elan_probe,
	.disconnect = ftdi_elan_disconnect,
	.id_table = ftdi_elan_table,
};
static int __init ftdi_elan_init(void)
{
	int result;
	pr_info("driver %s\n", ftdi_elan_driver.name);
	mutex_init(&ftdi_module_lock);
	INIT_LIST_HEAD(&ftdi_static_list);
	status_queue = create_singlethread_workqueue("ftdi-status-control");
	if (!status_queue)
		goto err_status_queue;
	command_queue = create_singlethread_workqueue("ftdi-command-engine");
	if (!command_queue)
		goto err_command_queue;
	respond_queue = create_singlethread_workqueue("ftdi-respond-engine");
	if (!respond_queue)
		goto err_respond_queue;
	result = usb_register(&ftdi_elan_driver);
	if (result) {
		destroy_workqueue(status_queue);
		destroy_workqueue(command_queue);
		destroy_workqueue(respond_queue);
		pr_err("usb_register failed. Error number %d\n", result);
	}
	return result;

err_respond_queue:
	destroy_workqueue(command_queue);
err_command_queue:
	destroy_workqueue(status_queue);
err_status_queue:
	pr_err("%s couldn't create workqueue\n", ftdi_elan_driver.name);
	return -ENOMEM;
}

static void __exit ftdi_elan_exit(void)
{
	struct usb_ftdi *ftdi;
	struct usb_ftdi *temp;
	usb_deregister(&ftdi_elan_driver);
	pr_info("ftdi_u132 driver deregistered\n");
	list_for_each_entry_safe(ftdi, temp, &ftdi_static_list, ftdi_list) {
		ftdi_status_cancel_work(ftdi);
		ftdi_command_cancel_work(ftdi);
		ftdi_response_cancel_work(ftdi);
	} flush_workqueue(status_queue);
	destroy_workqueue(status_queue);
	status_queue = NULL;
	flush_workqueue(command_queue);
	destroy_workqueue(command_queue);
	command_queue = NULL;
	flush_workqueue(respond_queue);
	destroy_workqueue(respond_queue);
	respond_queue = NULL;
}


module_init(ftdi_elan_init);
module_exit(ftdi_elan_exit);
