whiteheat.c 44.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * USB ConnectTech WhiteHEAT driver
 *
 *	Copyright (C) 2002
 *	    Connect Tech Inc.
 *
 *	Copyright (C) 1999 - 2001
 *	    Greg Kroah-Hartman (greg@kroah.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; either version 2 of the License, or
 *	(at your option) any later version.
 *
A
Alan Cox 已提交
15 16
 * See Documentation/usb/usb-serial.txt for more information on using this
 * driver
L
Linus Torvalds 已提交
17 18 19 20 21
 *
 * (10/09/2002) Stuart MacDonald (stuartm@connecttech.com)
 *	Upgrade to full working driver
 *
 * (05/30/2001) gkh
A
Alan Cox 已提交
22 23
 *	switched from using spinlock to a semaphore, which fixes lots of
 *	problems.
L
Linus Torvalds 已提交
24 25 26
 *
 * (04/08/2001) gb
 *	Identify version on module load.
A
Alan Cox 已提交
27
 *
L
Linus Torvalds 已提交
28
 * 2001_Mar_19 gkh
A
Alan Cox 已提交
29
 *	Fixed MOD_INC and MOD_DEC logic, the ability to open a port more
L
Linus Torvalds 已提交
30 31 32 33 34
 *	than once, and the got the proper usb_device_id table entries so
 *	the driver works again.
 *
 * (11/01/2000) Adam J. Richter
 *	usb_device_id table support
A
Alan Cox 已提交
35
 *
L
Linus Torvalds 已提交
36 37 38
 * (10/05/2000) gkh
 *	Fixed bug with urb->dev not being set properly, now that the usb
 *	core needs it.
A
Alan Cox 已提交
39
 *
L
Linus Torvalds 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
 * (10/03/2000) smd
 *	firmware is improved to guard against crap sent to device
 *	firmware now replies CMD_FAILURE on bad things
 *	read_callback fix you provided for private info struct
 *	command_finished now indicates success or fail
 *	setup_port struct now packed to avoid gcc padding
 *	firmware uses 1 based port numbering, driver now handles that
 *
 * (09/11/2000) gkh
 *	Removed DEBUG #ifdefs with call to usb_serial_debug_data
 *
 * (07/19/2000) gkh
 *	Added module_init and module_exit functions to handle the fact that this
 *	driver is a loadable module now.
 *	Fixed bug with port->minor that was found by Al Borchers
 *
 * (07/04/2000) gkh
A
Alan Cox 已提交
57 58 59
 *	Added support for port settings. Baud rate can now be changed. Line
 *	signals are not transferred to and from the tty layer yet, but things
 *	seem to be working well now.
L
Linus Torvalds 已提交
60 61 62 63 64 65 66
 *
 * (05/04/2000) gkh
 *	First cut at open and close commands. Data can flow through the ports at
 *	default speeds now.
 *
 * (03/26/2000) gkh
 *	Split driver up into device specific pieces.
A
Alan Cox 已提交
67
 *
L
Linus Torvalds 已提交
68 69 70 71 72 73 74 75 76 77 78
 */

#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/module.h>
#include <linux/spinlock.h>
O
Oliver Neukum 已提交
79
#include <linux/mutex.h>
A
Alan Cox 已提交
80
#include <linux/uaccess.h>
L
Linus Torvalds 已提交
81 82 83 84
#include <asm/termbits.h>
#include <linux/usb.h>
#include <linux/serial_reg.h>
#include <linux/serial.h>
85
#include <linux/usb/serial.h>
86 87
#include <linux/firmware.h>
#include <linux/ihex.h>
L
Linus Torvalds 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
#include "whiteheat.h"			/* WhiteHEAT specific commands */

static int debug;

#ifndef CMSPAR
#define CMSPAR 0
#endif

/*
 * Version Information
 */
#define DRIVER_VERSION "v2.0"
#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Stuart MacDonald <stuartm@connecttech.com>"
#define DRIVER_DESC "USB ConnectTech WhiteHEAT driver"

#define CONNECT_TECH_VENDOR_ID		0x0710
#define CONNECT_TECH_FAKE_WHITE_HEAT_ID	0x0001
#define CONNECT_TECH_WHITE_HEAT_ID	0x8001

/*
   ID tables for whiteheat are unusual, because we want to different
   things for different versions of the device.  Eventually, this
   will be doable from a single table.  But, for now, we define two
   separate ID tables, and then a third table that combines them
   just for the purpose of exporting the autoloading information.
*/
static struct usb_device_id id_table_std [] = {
	{ USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
	{ }						/* Terminating entry */
};

static struct usb_device_id id_table_prerenumeration [] = {
	{ USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
	{ }						/* Terminating entry */
};

static struct usb_device_id id_table_combined [] = {
	{ USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
	{ USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
	{ }						/* Terminating entry */
};

A
Alan Cox 已提交
130
MODULE_DEVICE_TABLE(usb, id_table_combined);
L
Linus Torvalds 已提交
131 132 133 134 135 136

static struct usb_driver whiteheat_driver = {
	.name =		"whiteheat",
	.probe =	usb_serial_probe,
	.disconnect =	usb_serial_disconnect,
	.id_table =	id_table_combined,
137
	.no_dynamic_id = 	1,
L
Linus Torvalds 已提交
138 139 140
};

/* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */
A
Alan Cox 已提交
141 142 143
static int  whiteheat_firmware_download(struct usb_serial *serial,
					const struct usb_device_id *id);
static int  whiteheat_firmware_attach(struct usb_serial *serial);
L
Linus Torvalds 已提交
144 145

/* function prototypes for the Connect Tech WhiteHEAT serial converter */
A
Alan Cox 已提交
146
static int  whiteheat_attach(struct usb_serial *serial);
147
static void whiteheat_release(struct usb_serial *serial);
A
Alan Cox 已提交
148
static int  whiteheat_open(struct tty_struct *tty,
149
			struct usb_serial_port *port);
150
static void whiteheat_close(struct usb_serial_port *port);
A
Alan Cox 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
static int  whiteheat_write(struct tty_struct *tty,
			struct usb_serial_port *port,
			const unsigned char *buf, int count);
static int  whiteheat_write_room(struct tty_struct *tty);
static int  whiteheat_ioctl(struct tty_struct *tty, struct file *file,
			unsigned int cmd, unsigned long arg);
static void whiteheat_set_termios(struct tty_struct *tty,
			struct usb_serial_port *port, struct ktermios *old);
static int  whiteheat_tiocmget(struct tty_struct *tty, struct file *file);
static int  whiteheat_tiocmset(struct tty_struct *tty, struct file *file,
			unsigned int set, unsigned int clear);
static void whiteheat_break_ctl(struct tty_struct *tty, int break_state);
static int  whiteheat_chars_in_buffer(struct tty_struct *tty);
static void whiteheat_throttle(struct tty_struct *tty);
static void whiteheat_unthrottle(struct tty_struct *tty);
static void whiteheat_read_callback(struct urb *urb);
static void whiteheat_write_callback(struct urb *urb);
L
Linus Torvalds 已提交
168

169
static struct usb_serial_driver whiteheat_fake_device = {
170 171
	.driver = {
		.owner =	THIS_MODULE,
172
		.name =		"whiteheatnofirm",
173
	},
174
	.description =		"Connect Tech - WhiteHEAT - (prerenumeration)",
175
	.usb_driver =		&whiteheat_driver,
L
Linus Torvalds 已提交
176 177 178 179 180 181
	.id_table =		id_table_prerenumeration,
	.num_ports =		1,
	.probe =		whiteheat_firmware_download,
	.attach =		whiteheat_firmware_attach,
};

182
static struct usb_serial_driver whiteheat_device = {
183 184
	.driver = {
		.owner =	THIS_MODULE,
185
		.name =		"whiteheat",
186
	},
187
	.description =		"Connect Tech - WhiteHEAT",
188
	.usb_driver =		&whiteheat_driver,
L
Linus Torvalds 已提交
189 190 191
	.id_table =		id_table_std,
	.num_ports =		4,
	.attach =		whiteheat_attach,
192
	.release =		whiteheat_release,
L
Linus Torvalds 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
	.open =			whiteheat_open,
	.close =		whiteheat_close,
	.write =		whiteheat_write,
	.write_room =		whiteheat_write_room,
	.ioctl =		whiteheat_ioctl,
	.set_termios =		whiteheat_set_termios,
	.break_ctl =		whiteheat_break_ctl,
	.tiocmget =		whiteheat_tiocmget,
	.tiocmset =		whiteheat_tiocmset,
	.chars_in_buffer =	whiteheat_chars_in_buffer,
	.throttle =		whiteheat_throttle,
	.unthrottle =		whiteheat_unthrottle,
	.read_bulk_callback =	whiteheat_read_callback,
	.write_bulk_callback =	whiteheat_write_callback,
};


struct whiteheat_command_private {
O
Oliver Neukum 已提交
211
	struct mutex		mutex;
L
Linus Torvalds 已提交
212 213
	__u8			port_running;
	__u8			command_finished;
A
Alan Cox 已提交
214 215 216
	wait_queue_head_t	wait_command; /* for handling sleeping whilst
						 waiting for a command to
						 finish */
L
Linus Torvalds 已提交
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
	__u8			result_buffer[64];
};


#define THROTTLED		0x01
#define ACTUALLY_THROTTLED	0x02

static int urb_pool_size = 8;

struct whiteheat_urb_wrap {
	struct list_head	list;
	struct urb		*urb;
};

struct whiteheat_private {
	spinlock_t		lock;
	__u8			flags;
234
	__u8			mcr;		/* FIXME: no locking on mcr */
L
Linus Torvalds 已提交
235 236 237 238
	struct list_head	rx_urbs_free;
	struct list_head	rx_urbs_submitted;
	struct list_head	rx_urb_q;
	struct work_struct	rx_work;
D
David Howells 已提交
239
	struct usb_serial_port	*port;
L
Linus Torvalds 已提交
240 241
	struct list_head	tx_urbs_free;
	struct list_head	tx_urbs_submitted;
O
Oliver Neukum 已提交
242
	struct mutex		deathwarrant;
L
Linus Torvalds 已提交
243 244 245 246 247 248
};


/* local function prototypes */
static int start_command_port(struct usb_serial *serial);
static void stop_command_port(struct usb_serial *serial);
249 250
static void command_port_write_callback(struct urb *urb);
static void command_port_read_callback(struct urb *urb);
L
Linus Torvalds 已提交
251 252

static int start_port_read(struct usb_serial_port *port);
A
Alan Cox 已提交
253 254
static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb,
						struct list_head *head);
L
Linus Torvalds 已提交
255
static struct list_head *list_first(struct list_head *head);
D
David Howells 已提交
256
static void rx_data_softint(struct work_struct *work);
L
Linus Torvalds 已提交
257

A
Alan Cox 已提交
258 259
static int firm_send_command(struct usb_serial_port *port, __u8 command,
						__u8 *data, __u8 datasize);
L
Linus Torvalds 已提交
260 261
static int firm_open(struct usb_serial_port *port);
static int firm_close(struct usb_serial_port *port);
A
Alan Cox 已提交
262
static void firm_setup_port(struct tty_struct *tty);
L
Linus Torvalds 已提交
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
static int firm_set_rts(struct usb_serial_port *port, __u8 onoff);
static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff);
static int firm_set_break(struct usb_serial_port *port, __u8 onoff);
static int firm_purge(struct usb_serial_port *port, __u8 rxtx);
static int firm_get_dtr_rts(struct usb_serial_port *port);
static int firm_report_tx_done(struct usb_serial_port *port);


#define COMMAND_PORT		4
#define COMMAND_TIMEOUT		(2*HZ)	/* 2 second timeout for a command */
#define	COMMAND_TIMEOUT_MS	2000
#define CLOSING_DELAY		(30 * HZ)


/*****************************************************************************
 * Connect Tech's White Heat prerenumeration driver functions
 *****************************************************************************/

/* steps to download the firmware to the WhiteHEAT device:
 - hold the reset (by writing to the reset bit of the CPUCS register)
 - download the VEND_AX.HEX file to the chip using VENDOR_REQUEST-ANCHOR_LOAD
 - release the reset (by writing to the CPUCS register)
 - download the WH.HEX file for all addresses greater than 0x1b3f using
   VENDOR_REQUEST-ANCHOR_EXTERNAL_RAM_LOAD
 - hold the reset
 - download the WH.HEX file for all addresses less than 0x1b40 using
   VENDOR_REQUEST_ANCHOR_LOAD
 - release the reset
 - device renumerated itself and comes up as new device id with all
   firmware download completed.
*/
A
Alan Cox 已提交
294 295
static int whiteheat_firmware_download(struct usb_serial *serial,
					const struct usb_device_id *id)
L
Linus Torvalds 已提交
296
{
297 298 299 300
	int response, ret = -ENOENT;
	const struct firmware *loader_fw = NULL, *firmware_fw = NULL;
	const struct ihex_binrec *record;

301
	dbg("%s", __func__);
302 303 304

	if (request_ihex_firmware(&firmware_fw, "whiteheat.fw",
				  &serial->dev->dev)) {
305 306
		dev_err(&serial->dev->dev,
			"%s - request \"whiteheat.fw\" failed\n", __func__);
307 308 309 310
		goto out;
	}
	if (request_ihex_firmware(&loader_fw, "whiteheat_loader.fw",
			     &serial->dev->dev)) {
311 312 313
		dev_err(&serial->dev->dev,
			"%s - request \"whiteheat_loader.fw\" failed\n",
			__func__);
314 315 316
		goto out;
	}
	ret = 0;
L
Linus Torvalds 已提交
317 318
	response = ezusb_set_reset (serial, 1);

319 320 321 322 323
	record = (const struct ihex_binrec *)loader_fw->data;
	while (record) {
		response = ezusb_writememory (serial, be32_to_cpu(record->addr),
					      (unsigned char *)record->data,
					      be16_to_cpu(record->len), 0xa0);
L
Linus Torvalds 已提交
324
		if (response < 0) {
325 326 327 328
			dev_err(&serial->dev->dev, "%s - ezusb_writememory "
				"failed for loader (%d %04X %p %d)\n",
				__func__, response, be32_to_cpu(record->addr),
				record->data, be16_to_cpu(record->len));
L
Linus Torvalds 已提交
329 330
			break;
		}
331
		record = ihex_next_binrec(record);
L
Linus Torvalds 已提交
332 333
	}

A
Alan Cox 已提交
334
	response = ezusb_set_reset(serial, 0);
L
Linus Torvalds 已提交
335

336 337 338 339 340 341 342
	record = (const struct ihex_binrec *)firmware_fw->data;
	while (record && be32_to_cpu(record->addr) < 0x1b40)
		record = ihex_next_binrec(record);
	while (record) {
		response = ezusb_writememory (serial, be32_to_cpu(record->addr),
					      (unsigned char *)record->data,
					      be16_to_cpu(record->len), 0xa3);
L
Linus Torvalds 已提交
343
		if (response < 0) {
344 345 346 347 348
			dev_err(&serial->dev->dev, "%s - ezusb_writememory "
				"failed for first firmware step "
				"(%d %04X %p %d)\n", __func__, response,
				be32_to_cpu(record->addr), record->data,
				be16_to_cpu(record->len));
L
Linus Torvalds 已提交
349 350 351 352
			break;
		}
		++record;
	}
A
Alan Cox 已提交
353 354

	response = ezusb_set_reset(serial, 1);
L
Linus Torvalds 已提交
355

356 357 358 359 360
	record = (const struct ihex_binrec *)firmware_fw->data;
	while (record && be32_to_cpu(record->addr) < 0x1b40) {
		response = ezusb_writememory (serial, be32_to_cpu(record->addr),
					      (unsigned char *)record->data,
					      be16_to_cpu(record->len), 0xa0);
L
Linus Torvalds 已提交
361
		if (response < 0) {
362 363 364 365 366
			dev_err(&serial->dev->dev, "%s - ezusb_writememory "
				"failed for second firmware step "
				"(%d %04X %p %d)\n", __func__, response,
				be32_to_cpu(record->addr), record->data,
				be16_to_cpu(record->len));
L
Linus Torvalds 已提交
367 368 369 370
			break;
		}
		++record;
	}
371
	ret = 0;
L
Linus Torvalds 已提交
372
	response = ezusb_set_reset (serial, 0);
373 374 375 376
 out:
	release_firmware(loader_fw);
	release_firmware(firmware_fw);
	return ret;
L
Linus Torvalds 已提交
377 378 379
}


A
Alan Cox 已提交
380
static int whiteheat_firmware_attach(struct usb_serial *serial)
L
Linus Torvalds 已提交
381 382 383 384 385 386 387 388 389
{
	/* We want this device to fail to have a driver assigned to it */
	return 1;
}


/*****************************************************************************
 * Connect Tech's White Heat serial driver functions
 *****************************************************************************/
A
Alan Cox 已提交
390
static int whiteheat_attach(struct usb_serial *serial)
L
Linus Torvalds 已提交
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
{
	struct usb_serial_port *command_port;
	struct whiteheat_command_private *command_info;
	struct usb_serial_port *port;
	struct whiteheat_private *info;
	struct whiteheat_hw_info *hw_info;
	int pipe;
	int ret;
	int alen;
	__u8 *command;
	__u8 *result;
	int i;
	int j;
	struct urb *urb;
	int buf_size;
	struct whiteheat_urb_wrap *wrap;
	struct list_head *tmp;

	command_port = serial->port[COMMAND_PORT];

A
Alan Cox 已提交
411 412
	pipe = usb_sndbulkpipe(serial->dev,
			command_port->bulk_out_endpointAddress);
L
Linus Torvalds 已提交
413 414 415 416 417
	command = kmalloc(2, GFP_KERNEL);
	if (!command)
		goto no_command_buffer;
	command[0] = WHITEHEAT_GET_HW_INFO;
	command[1] = 0;
A
Alan Cox 已提交
418

L
Linus Torvalds 已提交
419 420 421 422 423 424
	result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL);
	if (!result)
		goto no_result_buffer;
	/*
	 * When the module is reloaded the firmware is still there and
	 * the endpoints are still in the usb core unchanged. This is the
A
Alan Cox 已提交
425 426
	 * unlinking bug in disguise. Same for the call below.
	 */
L
Linus Torvalds 已提交
427
	usb_clear_halt(serial->dev, pipe);
A
Alan Cox 已提交
428 429
	ret = usb_bulk_msg(serial->dev, pipe, command, 2,
						&alen, COMMAND_TIMEOUT_MS);
L
Linus Torvalds 已提交
430
	if (ret) {
431 432
		dev_err(&serial->dev->dev, "%s: Couldn't send command [%d]\n",
			serial->type->description, ret);
L
Linus Torvalds 已提交
433
		goto no_firmware;
434
	} else if (alen != 2) {
435 436
		dev_err(&serial->dev->dev, "%s: Send command incomplete [%d]\n",
			serial->type->description, alen);
L
Linus Torvalds 已提交
437 438 439
		goto no_firmware;
	}

A
Alan Cox 已提交
440 441
	pipe = usb_rcvbulkpipe(serial->dev,
				command_port->bulk_in_endpointAddress);
L
Linus Torvalds 已提交
442 443
	/* See the comment on the usb_clear_halt() above */
	usb_clear_halt(serial->dev, pipe);
A
Alan Cox 已提交
444 445
	ret = usb_bulk_msg(serial->dev, pipe, result,
			sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS);
L
Linus Torvalds 已提交
446
	if (ret) {
447 448
		dev_err(&serial->dev->dev, "%s: Couldn't get results [%d]\n",
			serial->type->description, ret);
L
Linus Torvalds 已提交
449
		goto no_firmware;
450
	} else if (alen != sizeof(*hw_info) + 1) {
451 452
		dev_err(&serial->dev->dev, "%s: Get results incomplete [%d]\n",
			serial->type->description, alen);
L
Linus Torvalds 已提交
453 454
		goto no_firmware;
	} else if (result[0] != command[0]) {
455 456
		dev_err(&serial->dev->dev, "%s: Command failed [%d]\n",
			serial->type->description, result[0]);
L
Linus Torvalds 已提交
457 458 459 460 461
		goto no_firmware;
	}

	hw_info = (struct whiteheat_hw_info *)&result[1];

462 463 464
	dev_info(&serial->dev->dev, "%s: Driver %s: Firmware v%d.%02d\n",
		 serial->type->description, DRIVER_VERSION,
		 hw_info->sw_major_rev, hw_info->sw_minor_rev);
L
Linus Torvalds 已提交
465 466 467 468

	for (i = 0; i < serial->num_ports; i++) {
		port = serial->port[i];

469
		info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL);
L
Linus Torvalds 已提交
470
		if (info == NULL) {
471 472 473
			dev_err(&port->dev,
				"%s: Out of memory for port structures\n",
				serial->type->description);
L
Linus Torvalds 已提交
474 475 476 477
			goto no_private;
		}

		spin_lock_init(&info->lock);
O
Oliver Neukum 已提交
478
		mutex_init(&info->deathwarrant);
L
Linus Torvalds 已提交
479 480
		info->flags = 0;
		info->mcr = 0;
D
David Howells 已提交
481 482
		INIT_WORK(&info->rx_work, rx_data_softint);
		info->port = port;
L
Linus Torvalds 已提交
483 484 485 486 487 488 489 490 491 492

		INIT_LIST_HEAD(&info->rx_urbs_free);
		INIT_LIST_HEAD(&info->rx_urbs_submitted);
		INIT_LIST_HEAD(&info->rx_urb_q);
		INIT_LIST_HEAD(&info->tx_urbs_free);
		INIT_LIST_HEAD(&info->tx_urbs_submitted);

		for (j = 0; j < urb_pool_size; j++) {
			urb = usb_alloc_urb(0, GFP_KERNEL);
			if (!urb) {
493
				dev_err(&port->dev, "No free urbs available\n");
L
Linus Torvalds 已提交
494 495 496 497 498
				goto no_rx_urb;
			}
			buf_size = port->read_urb->transfer_buffer_length;
			urb->transfer_buffer = kmalloc(buf_size, GFP_KERNEL);
			if (!urb->transfer_buffer) {
499 500
				dev_err(&port->dev,
					"Couldn't allocate urb buffer\n");
L
Linus Torvalds 已提交
501 502 503 504
				goto no_rx_buf;
			}
			wrap = kmalloc(sizeof(*wrap), GFP_KERNEL);
			if (!wrap) {
505 506
				dev_err(&port->dev,
					"Couldn't allocate urb wrapper\n");
L
Linus Torvalds 已提交
507 508 509 510 511 512 513 514 515 516 517 518
				goto no_rx_wrap;
			}
			usb_fill_bulk_urb(urb, serial->dev,
					usb_rcvbulkpipe(serial->dev,
						port->bulk_in_endpointAddress),
					urb->transfer_buffer, buf_size,
					whiteheat_read_callback, port);
			wrap->urb = urb;
			list_add(&wrap->list, &info->rx_urbs_free);

			urb = usb_alloc_urb(0, GFP_KERNEL);
			if (!urb) {
519
				dev_err(&port->dev, "No free urbs available\n");
L
Linus Torvalds 已提交
520 521 522 523 524
				goto no_tx_urb;
			}
			buf_size = port->write_urb->transfer_buffer_length;
			urb->transfer_buffer = kmalloc(buf_size, GFP_KERNEL);
			if (!urb->transfer_buffer) {
525 526
				dev_err(&port->dev,
					"Couldn't allocate urb buffer\n");
L
Linus Torvalds 已提交
527 528 529 530
				goto no_tx_buf;
			}
			wrap = kmalloc(sizeof(*wrap), GFP_KERNEL);
			if (!wrap) {
531 532
				dev_err(&port->dev,
					"Couldn't allocate urb wrapper\n");
L
Linus Torvalds 已提交
533 534 535 536 537 538 539 540 541 542 543 544 545 546
				goto no_tx_wrap;
			}
			usb_fill_bulk_urb(urb, serial->dev,
					usb_sndbulkpipe(serial->dev,
						port->bulk_out_endpointAddress),
					urb->transfer_buffer, buf_size,
					whiteheat_write_callback, port);
			wrap->urb = urb;
			list_add(&wrap->list, &info->tx_urbs_free);
		}

		usb_set_serial_port_data(port, info);
	}

A
Alan Cox 已提交
547 548
	command_info = kmalloc(sizeof(struct whiteheat_command_private),
								GFP_KERNEL);
L
Linus Torvalds 已提交
549
	if (command_info == NULL) {
550 551 552
		dev_err(&serial->dev->dev,
			"%s: Out of memory for port structures\n",
			serial->type->description);
L
Linus Torvalds 已提交
553 554 555
		goto no_command_private;
	}

O
Oliver Neukum 已提交
556
	mutex_init(&command_info->mutex);
L
Linus Torvalds 已提交
557 558 559 560 561 562 563 564 565 566 567 568
	command_info->port_running = 0;
	init_waitqueue_head(&command_info->wait_command);
	usb_set_serial_port_data(command_port, command_info);
	command_port->write_urb->complete = command_port_write_callback;
	command_port->read_urb->complete = command_port_read_callback;
	kfree(result);
	kfree(command);

	return 0;

no_firmware:
	/* Firmware likely not running */
569 570 571 572 573 574 575 576 577
	dev_err(&serial->dev->dev,
		"%s: Unable to retrieve firmware version, try replugging\n",
		serial->type->description);
	dev_err(&serial->dev->dev,
		"%s: If the firmware is not running (status led not blinking)\n",
		serial->type->description);
	dev_err(&serial->dev->dev,
		"%s: please contact support@connecttech.com\n",
		serial->type->description);
578
	kfree(result);
L
Linus Torvalds 已提交
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
	return -ENODEV;

no_command_private:
	for (i = serial->num_ports - 1; i >= 0; i--) {
		port = serial->port[i];
		info = usb_get_serial_port_data(port);
		for (j = urb_pool_size - 1; j >= 0; j--) {
			tmp = list_first(&info->tx_urbs_free);
			list_del(tmp);
			wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
			urb = wrap->urb;
			kfree(wrap);
no_tx_wrap:
			kfree(urb->transfer_buffer);
no_tx_buf:
			usb_free_urb(urb);
no_tx_urb:
			tmp = list_first(&info->rx_urbs_free);
			list_del(tmp);
			wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
			urb = wrap->urb;
			kfree(wrap);
no_rx_wrap:
			kfree(urb->transfer_buffer);
no_rx_buf:
			usb_free_urb(urb);
no_rx_urb:
			;
		}
		kfree(info);
no_private:
		;
	}
	kfree(result);
no_result_buffer:
	kfree(command);
no_command_buffer:
	return -ENOMEM;
}


620
static void whiteheat_release(struct usb_serial *serial)
L
Linus Torvalds 已提交
621 622 623 624 625 626 627 628 629 630
{
	struct usb_serial_port *command_port;
	struct usb_serial_port *port;
	struct whiteheat_private *info;
	struct whiteheat_urb_wrap *wrap;
	struct urb *urb;
	struct list_head *tmp;
	struct list_head *tmp2;
	int i;

631
	dbg("%s", __func__);
L
Linus Torvalds 已提交
632 633 634

	/* free up our private data for our command port */
	command_port = serial->port[COMMAND_PORT];
A
Alan Cox 已提交
635
	kfree(usb_get_serial_port_data(command_port));
L
Linus Torvalds 已提交
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661

	for (i = 0; i < serial->num_ports; i++) {
		port = serial->port[i];
		info = usb_get_serial_port_data(port);
		list_for_each_safe(tmp, tmp2, &info->rx_urbs_free) {
			list_del(tmp);
			wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
			urb = wrap->urb;
			kfree(wrap);
			kfree(urb->transfer_buffer);
			usb_free_urb(urb);
		}
		list_for_each_safe(tmp, tmp2, &info->tx_urbs_free) {
			list_del(tmp);
			wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
			urb = wrap->urb;
			kfree(wrap);
			kfree(urb->transfer_buffer);
			usb_free_urb(urb);
		}
		kfree(info);
	}

	return;
}

662
static int whiteheat_open(struct tty_struct *tty, struct usb_serial_port *port)
L
Linus Torvalds 已提交
663 664 665
{
	int		retval = 0;

666
	dbg("%s - port %d", __func__, port->number);
L
Linus Torvalds 已提交
667 668 669 670 671

	retval = start_command_port(port->serial);
	if (retval)
		goto exit;

A
Alan Cox 已提交
672 673
	if (tty)
		tty->low_latency = 1;
L
Linus Torvalds 已提交
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688

	/* send an open port command */
	retval = firm_open(port);
	if (retval) {
		stop_command_port(port->serial);
		goto exit;
	}

	retval = firm_purge(port, WHITEHEAT_PURGE_RX | WHITEHEAT_PURGE_TX);
	if (retval) {
		firm_close(port);
		stop_command_port(port->serial);
		goto exit;
	}

689 690
	if (tty)
		firm_setup_port(tty);
L
Linus Torvalds 已提交
691 692 693 694 695 696 697 698

	/* Work around HCD bugs */
	usb_clear_halt(port->serial->dev, port->read_urb->pipe);
	usb_clear_halt(port->serial->dev, port->write_urb->pipe);

	/* Start reading from the device */
	retval = start_port_read(port);
	if (retval) {
699 700 701
		dev_err(&port->dev,
			"%s - failed submitting read urb, error %d\n",
			__func__, retval);
L
Linus Torvalds 已提交
702 703 704 705 706 707
		firm_close(port);
		stop_command_port(port->serial);
		goto exit;
	}

exit:
708
	dbg("%s - exit, retval = %d", __func__, retval);
L
Linus Torvalds 已提交
709 710 711 712
	return retval;
}


713
static void whiteheat_close(struct usb_serial_port *port)
L
Linus Torvalds 已提交
714 715 716 717 718 719 720
{
	struct whiteheat_private *info = usb_get_serial_port_data(port);
	struct whiteheat_urb_wrap *wrap;
	struct urb *urb;
	struct list_head *tmp;
	struct list_head *tmp2;

721
	dbg("%s - port %d", __func__, port->number);
722

L
Linus Torvalds 已提交
723 724 725 726
	firm_report_tx_done(port);
	firm_close(port);

	/* shutdown our bulk reads and writes */
O
Oliver Neukum 已提交
727 728
	mutex_lock(&info->deathwarrant);
	spin_lock_irq(&info->lock);
L
Linus Torvalds 已提交
729 730 731
	list_for_each_safe(tmp, tmp2, &info->rx_urbs_submitted) {
		wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
		urb = wrap->urb;
O
Oliver Neukum 已提交
732 733
		list_del(tmp);
		spin_unlock_irq(&info->lock);
L
Linus Torvalds 已提交
734
		usb_kill_urb(urb);
O
Oliver Neukum 已提交
735 736
		spin_lock_irq(&info->lock);
		list_add(tmp, &info->rx_urbs_free);
L
Linus Torvalds 已提交
737
	}
A
Akinobu Mita 已提交
738 739
	list_for_each_safe(tmp, tmp2, &info->rx_urb_q)
		list_move(tmp, &info->rx_urbs_free);
L
Linus Torvalds 已提交
740 741 742
	list_for_each_safe(tmp, tmp2, &info->tx_urbs_submitted) {
		wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
		urb = wrap->urb;
O
Oliver Neukum 已提交
743 744
		list_del(tmp);
		spin_unlock_irq(&info->lock);
L
Linus Torvalds 已提交
745
		usb_kill_urb(urb);
O
Oliver Neukum 已提交
746 747
		spin_lock_irq(&info->lock);
		list_add(tmp, &info->tx_urbs_free);
L
Linus Torvalds 已提交
748
	}
O
Oliver Neukum 已提交
749 750
	spin_unlock_irq(&info->lock);
	mutex_unlock(&info->deathwarrant);
L
Linus Torvalds 已提交
751 752 753 754
	stop_command_port(port->serial);
}


A
Alan Cox 已提交
755 756
static int whiteheat_write(struct tty_struct *tty,
	struct usb_serial_port *port, const unsigned char *buf, int count)
L
Linus Torvalds 已提交
757 758 759 760 761 762 763 764 765 766 767
{
	struct usb_serial *serial = port->serial;
	struct whiteheat_private *info = usb_get_serial_port_data(port);
	struct whiteheat_urb_wrap *wrap;
	struct urb *urb;
	int result;
	int bytes;
	int sent = 0;
	unsigned long flags;
	struct list_head *tmp;

768
	dbg("%s - port %d", __func__, port->number);
L
Linus Torvalds 已提交
769 770

	if (count == 0) {
771
		dbg("%s - write request of 0 bytes", __func__);
L
Linus Torvalds 已提交
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
		return (0);
	}

	while (count) {
		spin_lock_irqsave(&info->lock, flags);
		if (list_empty(&info->tx_urbs_free)) {
			spin_unlock_irqrestore(&info->lock, flags);
			break;
		}
		tmp = list_first(&info->tx_urbs_free);
		list_del(tmp);
		spin_unlock_irqrestore(&info->lock, flags);

		wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
		urb = wrap->urb;
A
Alan Cox 已提交
787 788 789
		bytes = (count > port->bulk_out_size) ?
					port->bulk_out_size : count;
		memcpy(urb->transfer_buffer, buf + sent, bytes);
L
Linus Torvalds 已提交
790

A
Alan Cox 已提交
791 792
		usb_serial_debug_data(debug, &port->dev,
				__func__, bytes, urb->transfer_buffer);
L
Linus Torvalds 已提交
793 794 795 796 797

		urb->dev = serial->dev;
		urb->transfer_buffer_length = bytes;
		result = usb_submit_urb(urb, GFP_ATOMIC);
		if (result) {
798 799 800
			dev_err(&port->dev,
				"%s - failed submitting write urb, error %d\n",
				__func__, result);
L
Linus Torvalds 已提交
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
			sent = result;
			spin_lock_irqsave(&info->lock, flags);
			list_add(tmp, &info->tx_urbs_free);
			spin_unlock_irqrestore(&info->lock, flags);
			break;
		} else {
			sent += bytes;
			count -= bytes;
			spin_lock_irqsave(&info->lock, flags);
			list_add(tmp, &info->tx_urbs_submitted);
			spin_unlock_irqrestore(&info->lock, flags);
		}
	}

	return sent;
}

A
Alan Cox 已提交
818
static int whiteheat_write_room(struct tty_struct *tty)
L
Linus Torvalds 已提交
819
{
A
Alan Cox 已提交
820
	struct usb_serial_port *port = tty->driver_data;
L
Linus Torvalds 已提交
821 822 823 824 825
	struct whiteheat_private *info = usb_get_serial_port_data(port);
	struct list_head *tmp;
	int room = 0;
	unsigned long flags;

826
	dbg("%s - port %d", __func__, port->number);
A
Alan Cox 已提交
827

L
Linus Torvalds 已提交
828 829 830 831 832 833
	spin_lock_irqsave(&info->lock, flags);
	list_for_each(tmp, &info->tx_urbs_free)
		room++;
	spin_unlock_irqrestore(&info->lock, flags);
	room *= port->bulk_out_size;

834
	dbg("%s - returns %d", __func__, room);
L
Linus Torvalds 已提交
835 836 837
	return (room);
}

A
Alan Cox 已提交
838
static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file)
L
Linus Torvalds 已提交
839
{
A
Alan Cox 已提交
840
	struct usb_serial_port *port = tty->driver_data;
L
Linus Torvalds 已提交
841 842 843
	struct whiteheat_private *info = usb_get_serial_port_data(port);
	unsigned int modem_signals = 0;

844
	dbg("%s - port %d", __func__, port->number);
L
Linus Torvalds 已提交
845 846 847 848 849 850 851 852 853 854

	firm_get_dtr_rts(port);
	if (info->mcr & UART_MCR_DTR)
		modem_signals |= TIOCM_DTR;
	if (info->mcr & UART_MCR_RTS)
		modem_signals |= TIOCM_RTS;

	return modem_signals;
}

A
Alan Cox 已提交
855
static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file,
L
Linus Torvalds 已提交
856 857
			       unsigned int set, unsigned int clear)
{
A
Alan Cox 已提交
858
	struct usb_serial_port *port = tty->driver_data;
L
Linus Torvalds 已提交
859 860
	struct whiteheat_private *info = usb_get_serial_port_data(port);

861
	dbg("%s - port %d", __func__, port->number);
L
Linus Torvalds 已提交
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878

	if (set & TIOCM_RTS)
		info->mcr |= UART_MCR_RTS;
	if (set & TIOCM_DTR)
		info->mcr |= UART_MCR_DTR;

	if (clear & TIOCM_RTS)
		info->mcr &= ~UART_MCR_RTS;
	if (clear & TIOCM_DTR)
		info->mcr &= ~UART_MCR_DTR;

	firm_set_dtr(port, info->mcr & UART_MCR_DTR);
	firm_set_rts(port, info->mcr & UART_MCR_RTS);
	return 0;
}


A
Alan Cox 已提交
879 880
static int whiteheat_ioctl(struct tty_struct *tty, struct file *file,
					unsigned int cmd, unsigned long arg)
L
Linus Torvalds 已提交
881
{
A
Alan Cox 已提交
882
	struct usb_serial_port *port = tty->driver_data;
L
Linus Torvalds 已提交
883 884 885
	struct serial_struct serstruct;
	void __user *user_arg = (void __user *)arg;

886
	dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
L
Linus Torvalds 已提交
887 888

	switch (cmd) {
A
Alan Cox 已提交
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
	case TIOCGSERIAL:
		memset(&serstruct, 0, sizeof(serstruct));
		serstruct.type = PORT_16654;
		serstruct.line = port->serial->minor;
		serstruct.port = port->number;
		serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
		serstruct.xmit_fifo_size = port->bulk_out_size;
		serstruct.custom_divisor = 0;
		serstruct.baud_base = 460800;
		serstruct.close_delay = CLOSING_DELAY;
		serstruct.closing_wait = CLOSING_DELAY;

		if (copy_to_user(user_arg, &serstruct, sizeof(serstruct)))
			return -EFAULT;
		break;
	default:
		break;
L
Linus Torvalds 已提交
906 907 908 909 910 911
	}

	return -ENOIOCTLCMD;
}


A
Alan Cox 已提交
912 913
static void whiteheat_set_termios(struct tty_struct *tty,
	struct usb_serial_port *port, struct ktermios *old_termios)
L
Linus Torvalds 已提交
914
{
A
Alan Cox 已提交
915
	firm_setup_port(tty);
L
Linus Torvalds 已提交
916 917
}

A
Alan Cox 已提交
918 919
static void whiteheat_break_ctl(struct tty_struct *tty, int break_state)
{
A
Alan Cox 已提交
920
	struct usb_serial_port *port = tty->driver_data;
L
Linus Torvalds 已提交
921 922 923 924
	firm_set_break(port, break_state);
}


A
Alan Cox 已提交
925
static int whiteheat_chars_in_buffer(struct tty_struct *tty)
L
Linus Torvalds 已提交
926
{
A
Alan Cox 已提交
927
	struct usb_serial_port *port = tty->driver_data;
L
Linus Torvalds 已提交
928 929 930 931 932 933
	struct whiteheat_private *info = usb_get_serial_port_data(port);
	struct list_head *tmp;
	struct whiteheat_urb_wrap *wrap;
	int chars = 0;
	unsigned long flags;

934
	dbg("%s - port %d", __func__, port->number);
L
Linus Torvalds 已提交
935 936 937 938 939 940 941 942

	spin_lock_irqsave(&info->lock, flags);
	list_for_each(tmp, &info->tx_urbs_submitted) {
		wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
		chars += wrap->urb->transfer_buffer_length;
	}
	spin_unlock_irqrestore(&info->lock, flags);

A
Alan Cox 已提交
943
	dbg("%s - returns %d", __func__, chars);
O
Oliver Neukum 已提交
944
	return chars;
L
Linus Torvalds 已提交
945 946 947
}


A
Alan Cox 已提交
948
static void whiteheat_throttle(struct tty_struct *tty)
L
Linus Torvalds 已提交
949
{
A
Alan Cox 已提交
950
	struct usb_serial_port *port = tty->driver_data;
L
Linus Torvalds 已提交
951 952 953
	struct whiteheat_private *info = usb_get_serial_port_data(port);
	unsigned long flags;

954
	dbg("%s - port %d", __func__, port->number);
L
Linus Torvalds 已提交
955 956 957 958 959 960 961 962 963

	spin_lock_irqsave(&info->lock, flags);
	info->flags |= THROTTLED;
	spin_unlock_irqrestore(&info->lock, flags);

	return;
}


A
Alan Cox 已提交
964
static void whiteheat_unthrottle(struct tty_struct *tty)
L
Linus Torvalds 已提交
965
{
A
Alan Cox 已提交
966
	struct usb_serial_port *port = tty->driver_data;
L
Linus Torvalds 已提交
967 968 969 970
	struct whiteheat_private *info = usb_get_serial_port_data(port);
	int actually_throttled;
	unsigned long flags;

971
	dbg("%s - port %d", __func__, port->number);
L
Linus Torvalds 已提交
972 973 974 975 976 977 978

	spin_lock_irqsave(&info->lock, flags);
	actually_throttled = info->flags & ACTUALLY_THROTTLED;
	info->flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
	spin_unlock_irqrestore(&info->lock, flags);

	if (actually_throttled)
D
David Howells 已提交
979
		rx_data_softint(&info->rx_work);
L
Linus Torvalds 已提交
980 981 982 983 984 985 986 987

	return;
}


/*****************************************************************************
 * Connect Tech's White Heat callback routines
 *****************************************************************************/
O
Oliver Neukum 已提交
988
static void command_port_write_callback(struct urb *urb)
L
Linus Torvalds 已提交
989
{
990 991
	int status = urb->status;

992
	dbg("%s", __func__);
L
Linus Torvalds 已提交
993

994 995
	if (status) {
		dbg("nonzero urb status: %d", status);
L
Linus Torvalds 已提交
996 997 998 999 1000
		return;
	}
}


O
Oliver Neukum 已提交
1001
static void command_port_read_callback(struct urb *urb)
L
Linus Torvalds 已提交
1002
{
1003
	struct usb_serial_port *command_port = urb->context;
L
Linus Torvalds 已提交
1004
	struct whiteheat_command_private *command_info;
1005
	int status = urb->status;
L
Linus Torvalds 已提交
1006 1007 1008
	unsigned char *data = urb->transfer_buffer;
	int result;

1009
	dbg("%s", __func__);
L
Linus Torvalds 已提交
1010

O
Oliver Neukum 已提交
1011 1012
	command_info = usb_get_serial_port_data(command_port);
	if (!command_info) {
A
Alan Cox 已提交
1013
		dbg("%s - command_info is NULL, exiting.", __func__);
O
Oliver Neukum 已提交
1014 1015
		return;
	}
1016
	if (status) {
1017
		dbg("%s - nonzero urb status: %d", __func__, status);
1018
		if (status != -ENOENT)
O
Oliver Neukum 已提交
1019 1020
			command_info->command_finished = WHITEHEAT_CMD_FAILURE;
		wake_up(&command_info->wait_command);
L
Linus Torvalds 已提交
1021 1022 1023
		return;
	}

A
Alan Cox 已提交
1024 1025
	usb_serial_debug_data(debug, &command_port->dev,
				__func__, urb->actual_length, data);
L
Linus Torvalds 已提交
1026 1027 1028

	if (data[0] == WHITEHEAT_CMD_COMPLETE) {
		command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
O
Oliver Neukum 已提交
1029
		wake_up(&command_info->wait_command);
L
Linus Torvalds 已提交
1030 1031
	} else if (data[0] == WHITEHEAT_CMD_FAILURE) {
		command_info->command_finished = WHITEHEAT_CMD_FAILURE;
O
Oliver Neukum 已提交
1032
		wake_up(&command_info->wait_command);
L
Linus Torvalds 已提交
1033
	} else if (data[0] == WHITEHEAT_EVENT) {
A
Alan Cox 已提交
1034 1035
		/* These are unsolicited reports from the firmware, hence no
		   waiting command to wakeup */
1036
		dbg("%s - event received", __func__);
L
Linus Torvalds 已提交
1037
	} else if (data[0] == WHITEHEAT_GET_DTR_RTS) {
A
Alan Cox 已提交
1038 1039
		memcpy(command_info->result_buffer, &data[1],
						urb->actual_length - 1);
L
Linus Torvalds 已提交
1040
		command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
O
Oliver Neukum 已提交
1041
		wake_up(&command_info->wait_command);
A
Alan Cox 已提交
1042
	} else
1043
		dbg("%s - bad reply from firmware", __func__);
A
Alan Cox 已提交
1044

L
Linus Torvalds 已提交
1045 1046 1047 1048
	/* Continue trying to always read */
	command_port->read_urb->dev = command_port->serial->dev;
	result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC);
	if (result)
A
Alan Cox 已提交
1049 1050
		dbg("%s - failed resubmitting read urb, error %d",
			__func__, result);
L
Linus Torvalds 已提交
1051 1052 1053
}


1054
static void whiteheat_read_callback(struct urb *urb)
L
Linus Torvalds 已提交
1055
{
1056
	struct usb_serial_port *port = urb->context;
L
Linus Torvalds 已提交
1057 1058 1059
	struct whiteheat_urb_wrap *wrap;
	unsigned char *data = urb->transfer_buffer;
	struct whiteheat_private *info = usb_get_serial_port_data(port);
1060
	int status = urb->status;
L
Linus Torvalds 已提交
1061

1062
	dbg("%s - port %d", __func__, port->number);
L
Linus Torvalds 已提交
1063 1064 1065 1066 1067

	spin_lock(&info->lock);
	wrap = urb_to_wrap(urb, &info->rx_urbs_submitted);
	if (!wrap) {
		spin_unlock(&info->lock);
1068
		dev_err(&port->dev, "%s - Not my urb!\n", __func__);
L
Linus Torvalds 已提交
1069 1070 1071 1072 1073
		return;
	}
	list_del(&wrap->list);
	spin_unlock(&info->lock);

1074 1075
	if (status) {
		dbg("%s - nonzero read bulk status received: %d",
1076
		    __func__, status);
L
Linus Torvalds 已提交
1077 1078 1079 1080 1081 1082
		spin_lock(&info->lock);
		list_add(&wrap->list, &info->rx_urbs_free);
		spin_unlock(&info->lock);
		return;
	}

A
Alan Cox 已提交
1083 1084
	usb_serial_debug_data(debug, &port->dev,
				__func__, urb->actual_length, data);
L
Linus Torvalds 已提交
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098

	spin_lock(&info->lock);
	list_add_tail(&wrap->list, &info->rx_urb_q);
	if (info->flags & THROTTLED) {
		info->flags |= ACTUALLY_THROTTLED;
		spin_unlock(&info->lock);
		return;
	}
	spin_unlock(&info->lock);

	schedule_work(&info->rx_work);
}


1099
static void whiteheat_write_callback(struct urb *urb)
L
Linus Torvalds 已提交
1100
{
1101
	struct usb_serial_port *port = urb->context;
L
Linus Torvalds 已提交
1102 1103
	struct whiteheat_private *info = usb_get_serial_port_data(port);
	struct whiteheat_urb_wrap *wrap;
1104
	int status = urb->status;
L
Linus Torvalds 已提交
1105

1106
	dbg("%s - port %d", __func__, port->number);
L
Linus Torvalds 已提交
1107 1108 1109 1110 1111

	spin_lock(&info->lock);
	wrap = urb_to_wrap(urb, &info->tx_urbs_submitted);
	if (!wrap) {
		spin_unlock(&info->lock);
1112
		dev_err(&port->dev, "%s - Not my urb!\n", __func__);
L
Linus Torvalds 已提交
1113 1114
		return;
	}
A
Akinobu Mita 已提交
1115
	list_move(&wrap->list, &info->tx_urbs_free);
L
Linus Torvalds 已提交
1116 1117
	spin_unlock(&info->lock);

1118 1119
	if (status) {
		dbg("%s - nonzero write bulk status received: %d",
1120
		    __func__, status);
L
Linus Torvalds 已提交
1121 1122 1123
		return;
	}

1124
	usb_serial_port_softint(port);
L
Linus Torvalds 已提交
1125 1126 1127 1128 1129 1130
}


/*****************************************************************************
 * Connect Tech's White Heat firmware interface
 *****************************************************************************/
A
Alan Cox 已提交
1131 1132
static int firm_send_command(struct usb_serial_port *port, __u8 command,
						__u8 *data, __u8 datasize)
L
Linus Torvalds 已提交
1133 1134 1135 1136 1137 1138
{
	struct usb_serial_port *command_port;
	struct whiteheat_command_private *command_info;
	struct whiteheat_private *info;
	__u8 *transfer_buffer;
	int retval = 0;
O
Oliver Neukum 已提交
1139
	int t;
L
Linus Torvalds 已提交
1140

1141
	dbg("%s - command %d", __func__, command);
L
Linus Torvalds 已提交
1142 1143 1144

	command_port = port->serial->port[COMMAND_PORT];
	command_info = usb_get_serial_port_data(command_port);
O
Oliver Neukum 已提交
1145
	mutex_lock(&command_info->mutex);
1146
	command_info->command_finished = false;
A
Alan Cox 已提交
1147

L
Linus Torvalds 已提交
1148 1149
	transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer;
	transfer_buffer[0] = command;
A
Alan Cox 已提交
1150
	memcpy(&transfer_buffer[1], data, datasize);
L
Linus Torvalds 已提交
1151 1152
	command_port->write_urb->transfer_buffer_length = datasize + 1;
	command_port->write_urb->dev = port->serial->dev;
A
Alan Cox 已提交
1153
	retval = usb_submit_urb(command_port->write_urb, GFP_NOIO);
L
Linus Torvalds 已提交
1154
	if (retval) {
1155
		dbg("%s - submit urb failed", __func__);
L
Linus Torvalds 已提交
1156 1157 1158 1159
		goto exit;
	}

	/* wait for the command to complete */
O
Oliver Neukum 已提交
1160
	t = wait_event_timeout(command_info->wait_command,
1161
		(bool)command_info->command_finished, COMMAND_TIMEOUT);
O
Oliver Neukum 已提交
1162 1163
	if (!t)
		usb_kill_urb(command_port->write_urb);
L
Linus Torvalds 已提交
1164

1165
	if (command_info->command_finished == false) {
1166
		dbg("%s - command timed out.", __func__);
L
Linus Torvalds 已提交
1167 1168 1169 1170 1171
		retval = -ETIMEDOUT;
		goto exit;
	}

	if (command_info->command_finished == WHITEHEAT_CMD_FAILURE) {
1172
		dbg("%s - command failed.", __func__);
L
Linus Torvalds 已提交
1173 1174 1175 1176 1177
		retval = -EIO;
		goto exit;
	}

	if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) {
1178
		dbg("%s - command completed.", __func__);
L
Linus Torvalds 已提交
1179
		switch (command) {
A
Alan Cox 已提交
1180 1181 1182 1183
		case WHITEHEAT_GET_DTR_RTS:
			info = usb_get_serial_port_data(port);
			memcpy(&info->mcr, command_info->result_buffer,
					sizeof(struct whiteheat_dr_info));
L
Linus Torvalds 已提交
1184 1185 1186 1187
				break;
		}
	}
exit:
O
Oliver Neukum 已提交
1188
	mutex_unlock(&command_info->mutex);
L
Linus Torvalds 已提交
1189 1190 1191 1192
	return retval;
}


A
Alan Cox 已提交
1193 1194
static int firm_open(struct usb_serial_port *port)
{
L
Linus Torvalds 已提交
1195 1196 1197
	struct whiteheat_simple open_command;

	open_command.port = port->number - port->serial->minor + 1;
A
Alan Cox 已提交
1198 1199
	return firm_send_command(port, WHITEHEAT_OPEN,
		(__u8 *)&open_command, sizeof(open_command));
L
Linus Torvalds 已提交
1200 1201 1202
}


A
Alan Cox 已提交
1203 1204
static int firm_close(struct usb_serial_port *port)
{
L
Linus Torvalds 已提交
1205 1206 1207
	struct whiteheat_simple close_command;

	close_command.port = port->number - port->serial->minor + 1;
A
Alan Cox 已提交
1208 1209
	return firm_send_command(port, WHITEHEAT_CLOSE,
			(__u8 *)&close_command, sizeof(close_command));
L
Linus Torvalds 已提交
1210 1211 1212
}


A
Alan Cox 已提交
1213
static void firm_setup_port(struct tty_struct *tty)
A
Alan Cox 已提交
1214
{
A
Alan Cox 已提交
1215
	struct usb_serial_port *port = tty->driver_data;
L
Linus Torvalds 已提交
1216
	struct whiteheat_port_settings port_settings;
A
Alan Cox 已提交
1217
	unsigned int cflag = tty->termios->c_cflag;
L
Linus Torvalds 已提交
1218 1219 1220 1221 1222

	port_settings.port = port->number + 1;

	/* get the byte size */
	switch (cflag & CSIZE) {
A
Alan Cox 已提交
1223 1224 1225 1226 1227
	case CS5:	port_settings.bits = 5;   break;
	case CS6:	port_settings.bits = 6;   break;
	case CS7:	port_settings.bits = 7;   break;
	default:
	case CS8:	port_settings.bits = 8;   break;
L
Linus Torvalds 已提交
1228
	}
1229
	dbg("%s - data bits = %d", __func__, port_settings.bits);
A
Alan Cox 已提交
1230

L
Linus Torvalds 已提交
1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
	/* determine the parity */
	if (cflag & PARENB)
		if (cflag & CMSPAR)
			if (cflag & PARODD)
				port_settings.parity = WHITEHEAT_PAR_MARK;
			else
				port_settings.parity = WHITEHEAT_PAR_SPACE;
		else
			if (cflag & PARODD)
				port_settings.parity = WHITEHEAT_PAR_ODD;
			else
				port_settings.parity = WHITEHEAT_PAR_EVEN;
	else
		port_settings.parity = WHITEHEAT_PAR_NONE;
1245
	dbg("%s - parity = %c", __func__, port_settings.parity);
L
Linus Torvalds 已提交
1246 1247 1248 1249 1250 1251

	/* figure out the stop bits requested */
	if (cflag & CSTOPB)
		port_settings.stop = 2;
	else
		port_settings.stop = 1;
1252
	dbg("%s - stop bits = %d", __func__, port_settings.stop);
L
Linus Torvalds 已提交
1253 1254 1255

	/* figure out the flow control settings */
	if (cflag & CRTSCTS)
A
Alan Cox 已提交
1256 1257
		port_settings.hflow = (WHITEHEAT_HFLOW_CTS |
						WHITEHEAT_HFLOW_RTS);
L
Linus Torvalds 已提交
1258 1259
	else
		port_settings.hflow = WHITEHEAT_HFLOW_NONE;
1260
	dbg("%s - hardware flow control = %s %s %s %s", __func__,
L
Linus Torvalds 已提交
1261 1262 1263 1264
	    (port_settings.hflow & WHITEHEAT_HFLOW_CTS) ? "CTS" : "",
	    (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "",
	    (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "",
	    (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : "");
A
Alan Cox 已提交
1265

L
Linus Torvalds 已提交
1266
	/* determine software flow control */
A
Alan Cox 已提交
1267
	if (I_IXOFF(tty))
L
Linus Torvalds 已提交
1268 1269 1270
		port_settings.sflow = WHITEHEAT_SFLOW_RXTX;
	else
		port_settings.sflow = WHITEHEAT_SFLOW_NONE;
1271
	dbg("%s - software flow control = %c", __func__, port_settings.sflow);
A
Alan Cox 已提交
1272

A
Alan Cox 已提交
1273 1274
	port_settings.xon = START_CHAR(tty);
	port_settings.xoff = STOP_CHAR(tty);
A
Alan Cox 已提交
1275 1276
	dbg("%s - XON = %2x, XOFF = %2x",
			__func__, port_settings.xon, port_settings.xoff);
L
Linus Torvalds 已提交
1277 1278

	/* get the baud rate wanted */
A
Alan Cox 已提交
1279
	port_settings.baud = tty_get_baud_rate(tty);
1280
	dbg("%s - baud rate = %d", __func__, port_settings.baud);
L
Linus Torvalds 已提交
1281

1282
	/* fixme: should set validated settings */
A
Alan Cox 已提交
1283
	tty_encode_baud_rate(tty, port_settings.baud, port_settings.baud);
L
Linus Torvalds 已提交
1284 1285
	/* handle any settings that aren't specified in the tty structure */
	port_settings.lloop = 0;
A
Alan Cox 已提交
1286

L
Linus Torvalds 已提交
1287
	/* now send the message to the device */
A
Alan Cox 已提交
1288
	firm_send_command(port, WHITEHEAT_SETUP_PORT,
A
Alan Cox 已提交
1289
			(__u8 *)&port_settings, sizeof(port_settings));
L
Linus Torvalds 已提交
1290 1291 1292
}


A
Alan Cox 已提交
1293 1294
static int firm_set_rts(struct usb_serial_port *port, __u8 onoff)
{
L
Linus Torvalds 已提交
1295 1296 1297 1298
	struct whiteheat_set_rdb rts_command;

	rts_command.port = port->number - port->serial->minor + 1;
	rts_command.state = onoff;
A
Alan Cox 已提交
1299 1300
	return firm_send_command(port, WHITEHEAT_SET_RTS,
			(__u8 *)&rts_command, sizeof(rts_command));
L
Linus Torvalds 已提交
1301 1302 1303
}


A
Alan Cox 已提交
1304 1305
static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff)
{
L
Linus Torvalds 已提交
1306 1307 1308 1309
	struct whiteheat_set_rdb dtr_command;

	dtr_command.port = port->number - port->serial->minor + 1;
	dtr_command.state = onoff;
1310
	return firm_send_command(port, WHITEHEAT_SET_DTR,
A
Alan Cox 已提交
1311
			(__u8 *)&dtr_command, sizeof(dtr_command));
L
Linus Torvalds 已提交
1312 1313 1314
}


A
Alan Cox 已提交
1315 1316
static int firm_set_break(struct usb_serial_port *port, __u8 onoff)
{
L
Linus Torvalds 已提交
1317 1318 1319 1320
	struct whiteheat_set_rdb break_command;

	break_command.port = port->number - port->serial->minor + 1;
	break_command.state = onoff;
1321
	return firm_send_command(port, WHITEHEAT_SET_BREAK,
A
Alan Cox 已提交
1322
			(__u8 *)&break_command, sizeof(break_command));
L
Linus Torvalds 已提交
1323 1324 1325
}


A
Alan Cox 已提交
1326 1327
static int firm_purge(struct usb_serial_port *port, __u8 rxtx)
{
L
Linus Torvalds 已提交
1328 1329 1330 1331
	struct whiteheat_purge purge_command;

	purge_command.port = port->number - port->serial->minor + 1;
	purge_command.what = rxtx;
A
Alan Cox 已提交
1332 1333
	return firm_send_command(port, WHITEHEAT_PURGE,
			(__u8 *)&purge_command, sizeof(purge_command));
L
Linus Torvalds 已提交
1334 1335 1336
}


A
Alan Cox 已提交
1337 1338
static int firm_get_dtr_rts(struct usb_serial_port *port)
{
L
Linus Torvalds 已提交
1339 1340 1341
	struct whiteheat_simple get_dr_command;

	get_dr_command.port = port->number - port->serial->minor + 1;
A
Alan Cox 已提交
1342 1343
	return firm_send_command(port, WHITEHEAT_GET_DTR_RTS,
			(__u8 *)&get_dr_command, sizeof(get_dr_command));
L
Linus Torvalds 已提交
1344 1345 1346
}


A
Alan Cox 已提交
1347 1348
static int firm_report_tx_done(struct usb_serial_port *port)
{
L
Linus Torvalds 已提交
1349 1350 1351
	struct whiteheat_simple close_command;

	close_command.port = port->number - port->serial->minor + 1;
A
Alan Cox 已提交
1352 1353
	return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE,
			(__u8 *)&close_command, sizeof(close_command));
L
Linus Torvalds 已提交
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364
}


/*****************************************************************************
 * Connect Tech's White Heat utility functions
 *****************************************************************************/
static int start_command_port(struct usb_serial *serial)
{
	struct usb_serial_port *command_port;
	struct whiteheat_command_private *command_info;
	int retval = 0;
A
Alan Cox 已提交
1365

L
Linus Torvalds 已提交
1366 1367
	command_port = serial->port[COMMAND_PORT];
	command_info = usb_get_serial_port_data(command_port);
O
Oliver Neukum 已提交
1368
	mutex_lock(&command_info->mutex);
L
Linus Torvalds 已提交
1369 1370 1371 1372 1373 1374 1375
	if (!command_info->port_running) {
		/* Work around HCD bugs */
		usb_clear_halt(serial->dev, command_port->read_urb->pipe);

		command_port->read_urb->dev = serial->dev;
		retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL);
		if (retval) {
1376 1377 1378
			dev_err(&serial->dev->dev,
				"%s - failed submitting read urb, error %d\n",
				__func__, retval);
L
Linus Torvalds 已提交
1379 1380 1381 1382 1383 1384
			goto exit;
		}
	}
	command_info->port_running++;

exit:
O
Oliver Neukum 已提交
1385
	mutex_unlock(&command_info->mutex);
L
Linus Torvalds 已提交
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
	return retval;
}


static void stop_command_port(struct usb_serial *serial)
{
	struct usb_serial_port *command_port;
	struct whiteheat_command_private *command_info;

	command_port = serial->port[COMMAND_PORT];
	command_info = usb_get_serial_port_data(command_port);
O
Oliver Neukum 已提交
1397
	mutex_lock(&command_info->mutex);
L
Linus Torvalds 已提交
1398 1399 1400
	command_info->port_running--;
	if (!command_info->port_running)
		usb_kill_urb(command_port->read_urb);
O
Oliver Neukum 已提交
1401
	mutex_unlock(&command_info->mutex);
L
Linus Torvalds 已提交
1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
}


static int start_port_read(struct usb_serial_port *port)
{
	struct whiteheat_private *info = usb_get_serial_port_data(port);
	struct whiteheat_urb_wrap *wrap;
	struct urb *urb;
	int retval = 0;
	unsigned long flags;
	struct list_head *tmp;
	struct list_head *tmp2;

	spin_lock_irqsave(&info->lock, flags);

	list_for_each_safe(tmp, tmp2, &info->rx_urbs_free) {
		list_del(tmp);
		wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
		urb = wrap->urb;
		urb->dev = port->serial->dev;
O
Oliver Neukum 已提交
1422
		spin_unlock_irqrestore(&info->lock, flags);
L
Linus Torvalds 已提交
1423 1424
		retval = usb_submit_urb(urb, GFP_KERNEL);
		if (retval) {
O
Oliver Neukum 已提交
1425
			spin_lock_irqsave(&info->lock, flags);
L
Linus Torvalds 已提交
1426 1427 1428 1429
			list_add(tmp, &info->rx_urbs_free);
			list_for_each_safe(tmp, tmp2, &info->rx_urbs_submitted) {
				wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
				urb = wrap->urb;
O
Oliver Neukum 已提交
1430 1431
				list_del(tmp);
				spin_unlock_irqrestore(&info->lock, flags);
L
Linus Torvalds 已提交
1432
				usb_kill_urb(urb);
O
Oliver Neukum 已提交
1433 1434
				spin_lock_irqsave(&info->lock, flags);
				list_add(tmp, &info->rx_urbs_free);
L
Linus Torvalds 已提交
1435 1436 1437
			}
			break;
		}
O
Oliver Neukum 已提交
1438
		spin_lock_irqsave(&info->lock, flags);
L
Linus Torvalds 已提交
1439 1440 1441 1442 1443 1444 1445 1446 1447
		list_add(tmp, &info->rx_urbs_submitted);
	}

	spin_unlock_irqrestore(&info->lock, flags);

	return retval;
}


A
Alan Cox 已提交
1448 1449
static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb,
						struct list_head *head)
L
Linus Torvalds 已提交
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469
{
	struct whiteheat_urb_wrap *wrap;
	struct list_head *tmp;

	list_for_each(tmp, head) {
		wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
		if (wrap->urb == urb)
			return wrap;
	}

	return NULL;
}


static struct list_head *list_first(struct list_head *head)
{
	return head->next;
}


D
David Howells 已提交
1470
static void rx_data_softint(struct work_struct *work)
L
Linus Torvalds 已提交
1471
{
D
David Howells 已提交
1472 1473 1474
	struct whiteheat_private *info =
		container_of(work, struct whiteheat_private, rx_work);
	struct usb_serial_port *port = info->port;
A
Alan Cox 已提交
1475
	struct tty_struct *tty = tty_port_tty_get(&port->port);
L
Linus Torvalds 已提交
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486
	struct whiteheat_urb_wrap *wrap;
	struct urb *urb;
	unsigned long flags;
	struct list_head *tmp;
	struct list_head *tmp2;
	int result;
	int sent = 0;

	spin_lock_irqsave(&info->lock, flags);
	if (info->flags & THROTTLED) {
		spin_unlock_irqrestore(&info->lock, flags);
A
Alan Cox 已提交
1487
		goto out;
L
Linus Torvalds 已提交
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
	}

	list_for_each_safe(tmp, tmp2, &info->rx_urb_q) {
		list_del(tmp);
		spin_unlock_irqrestore(&info->lock, flags);

		wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
		urb = wrap->urb;

		if (tty && urb->actual_length) {
A
Alan Cox 已提交
1498 1499
			int len = tty_buffer_request_room(tty,
							urb->actual_length);
A
Alan Cox 已提交
1500 1501
			/* This stuff can go away now I suspect */
			if (unlikely(len < urb->actual_length)) {
L
Linus Torvalds 已提交
1502 1503 1504 1505 1506
				spin_lock_irqsave(&info->lock, flags);
				list_add(tmp, &info->rx_urb_q);
				spin_unlock_irqrestore(&info->lock, flags);
				tty_flip_buffer_push(tty);
				schedule_work(&info->rx_work);
A
Alan Cox 已提交
1507
				goto out;
L
Linus Torvalds 已提交
1508
			}
A
Alan Cox 已提交
1509 1510
			tty_insert_flip_string(tty, urb->transfer_buffer, len);
			sent += len;
L
Linus Torvalds 已提交
1511 1512 1513 1514 1515
		}

		urb->dev = port->serial->dev;
		result = usb_submit_urb(urb, GFP_ATOMIC);
		if (result) {
1516 1517
			dev_err(&port->dev,
				"%s - failed resubmitting read urb, error %d\n",
A
Alan Cox 已提交
1518
				__func__, result);
L
Linus Torvalds 已提交
1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530
			spin_lock_irqsave(&info->lock, flags);
			list_add(tmp, &info->rx_urbs_free);
			continue;
		}

		spin_lock_irqsave(&info->lock, flags);
		list_add(tmp, &info->rx_urbs_submitted);
	}
	spin_unlock_irqrestore(&info->lock, flags);

	if (sent)
		tty_flip_buffer_push(tty);
A
Alan Cox 已提交
1531 1532
out:
	tty_kref_put(tty);
L
Linus Torvalds 已提交
1533 1534 1535 1536 1537 1538
}


/*****************************************************************************
 * Connect Tech's White Heat module functions
 *****************************************************************************/
A
Alan Cox 已提交
1539
static int __init whiteheat_init(void)
L
Linus Torvalds 已提交
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550
{
	int retval;
	retval = usb_serial_register(&whiteheat_fake_device);
	if (retval)
		goto failed_fake_register;
	retval = usb_serial_register(&whiteheat_device);
	if (retval)
		goto failed_device_register;
	retval = usb_register(&whiteheat_driver);
	if (retval)
		goto failed_usb_register;
1551 1552
	printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
	       DRIVER_DESC "\n");
L
Linus Torvalds 已提交
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562
	return 0;
failed_usb_register:
	usb_serial_deregister(&whiteheat_device);
failed_device_register:
	usb_serial_deregister(&whiteheat_fake_device);
failed_fake_register:
	return retval;
}


A
Alan Cox 已提交
1563
static void __exit whiteheat_exit(void)
L
Linus Torvalds 已提交
1564
{
A
Alan Cox 已提交
1565 1566 1567
	usb_deregister(&whiteheat_driver);
	usb_serial_deregister(&whiteheat_fake_device);
	usb_serial_deregister(&whiteheat_device);
L
Linus Torvalds 已提交
1568 1569 1570 1571 1572 1573
}


module_init(whiteheat_init);
module_exit(whiteheat_exit);

A
Alan Cox 已提交
1574 1575
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
L
Linus Torvalds 已提交
1576 1577
MODULE_LICENSE("GPL");

1578 1579 1580
MODULE_FIRMWARE("whiteheat.fw");
MODULE_FIRMWARE("whiteheat_loader.fw");

L
Linus Torvalds 已提交
1581 1582 1583 1584 1585
module_param(urb_pool_size, int, 0);
MODULE_PARM_DESC(urb_pool_size, "Number of urbs to use for buffering");

module_param(debug, bool, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(debug, "Debug enabled or not");