iuu_phoenix.c 29.8 KB
Newer Older
A
Alain Degreffe 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
/*
 * Infinity Unlimited USB Phoenix driver
 *
 * Copyright (C) 2007 Alain Degreffe (eczema@ecze.com)
 *
 * Original code taken from iuutool (Copyright (C) 2006 Juan Carlos Borrás)
 *
 *	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.
 *
 *  And tested with help of WB Electronics
 *
 */
#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/serial.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/spinlock.h>
#include <linux/uaccess.h>
#include <linux/usb.h>
#include <linux/usb/serial.h>
#include "iuu_phoenix.h"
#include <linux/random.h>


#ifdef CONFIG_USB_SERIAL_DEBUG
static int debug = 1;
#else
static int debug;
#endif

/*
 * Version Information
 */
#define DRIVER_VERSION "v0.5"
#define DRIVER_DESC "Infinity USB Unlimited Phoenix driver"

static struct usb_device_id id_table[] = {
	{USB_DEVICE(IUU_USB_VENDOR_ID, IUU_USB_PRODUCT_ID)},
	{}			/* Terminating entry */
};
MODULE_DEVICE_TABLE(usb, id_table);

static struct usb_driver iuu_driver = {
	.name = "iuu_phoenix",
	.probe = usb_serial_probe,
	.disconnect = usb_serial_disconnect,
	.id_table = id_table,
	.no_dynamic_id = 1,
};

/* turbo parameter */
static int boost = 100;
static int clockmode = 1;
static int cdmode = 1;
static int iuu_cardin;
static int iuu_cardout;
static int xmas;

static void read_rxcmd_callback(struct urb *urb);

struct iuu_private {
	spinlock_t lock;	/* store irq state */
	wait_queue_head_t delta_msr_wait;
	u8 line_control;
	u8 line_status;
	u8 termios_initialized;
	int tiostatus;		/* store IUART SIGNAL for tiocmget call */
	u8 reset;		/* if 1 reset is needed */
	int poll;		/* number of poll */
	u8 *writebuf;		/* buffer for writing to device */
	int writelen;		/* num of byte to write to device */
	u8 *buf;		/* used for initialize speed */
	u8 *dbgbuf;		/* debug buffer */
	u8 len;
};


static void iuu_free_buf(struct iuu_private *priv)
{
	kfree(priv->buf);
	kfree(priv->dbgbuf);
	kfree(priv->writebuf);
}

static int iuu_alloc_buf(struct iuu_private *priv)
{
	priv->buf = kzalloc(256, GFP_KERNEL);
	priv->dbgbuf = kzalloc(256, GFP_KERNEL);
	priv->writebuf = kzalloc(256, GFP_KERNEL);
	if (!priv->buf || !priv->dbgbuf || !priv->writebuf) {
		iuu_free_buf(priv);
101
		dbg("%s problem allocation buffer", __func__);
A
Alain Degreffe 已提交
102 103
		return -ENOMEM;
	}
104
	dbg("%s - Privates buffers allocation success", __func__);
A
Alain Degreffe 已提交
105 106 107 108 109 110 111
	return 0;
}

static int iuu_startup(struct usb_serial *serial)
{
	struct iuu_private *priv;
	priv = kzalloc(sizeof(struct iuu_private), GFP_KERNEL);
112
	dbg("%s- priv allocation success", __func__);
A
Alain Degreffe 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
	if (!priv)
		return -ENOMEM;
	if (iuu_alloc_buf(priv)) {
		kfree(priv);
		return -ENOMEM;
	}
	spin_lock_init(&priv->lock);
	init_waitqueue_head(&priv->delta_msr_wait);
	usb_set_serial_port_data(serial->port[0], priv);
	return 0;
}

/* Shutdown function */
static void iuu_shutdown(struct usb_serial *serial)
{
	struct usb_serial_port *port = serial->port[0];
	struct iuu_private *priv = usb_get_serial_port_data(port);
	if (!port)
		return;

133
	dbg("%s", __func__);
A
Alain Degreffe 已提交
134 135 136

	if (priv) {
		iuu_free_buf(priv);
137
		dbg("%s - I will free all", __func__);
A
Alain Degreffe 已提交
138 139
		usb_set_serial_port_data(port, NULL);

140
		dbg("%s - priv is not anymore in port structure", __func__);
A
Alain Degreffe 已提交
141 142
		kfree(priv);

143
		dbg("%s priv is now kfree", __func__);
A
Alain Degreffe 已提交
144 145 146
	}
}

A
Alan Cox 已提交
147
static int iuu_tiocmset(struct tty_struct *tty, struct file *file,
A
Alain Degreffe 已提交
148 149
			unsigned int set, unsigned int clear)
{
A
Alan Cox 已提交
150
	struct usb_serial_port *port = tty->driver_data;
A
Alain Degreffe 已提交
151
	struct iuu_private *priv = usb_get_serial_port_data(port);
152
	unsigned long flags;
A
Alain Degreffe 已提交
153

154
	/* FIXME: locking on tiomstatus */
155
	dbg("%s (%d) msg : SET = 0x%04x, CLEAR = 0x%04x ", __func__,
A
Alain Degreffe 已提交
156
	    port->number, set, clear);
157 158

	spin_lock_irqsave(&priv->lock, flags);
A
Alain Degreffe 已提交
159 160 161 162
	if (set & TIOCM_RTS)
		priv->tiostatus = TIOCM_RTS;

	if (!(set & TIOCM_RTS) && priv->tiostatus == TIOCM_RTS) {
163
		dbg("%s TIOCMSET RESET called !!!", __func__);
A
Alain Degreffe 已提交
164 165
		priv->reset = 1;
	}
166
	spin_unlock_irqrestore(&priv->lock, flags);
A
Alain Degreffe 已提交
167 168 169 170 171 172 173 174
	return 0;
}

/* This is used to provide a carrier detect mechanism
 * When a card is present, the response is 0x00
 * When no card , the reader respond with TIOCM_CD
 * This is known as CD autodetect mechanism
 */
A
Alan Cox 已提交
175
static int iuu_tiocmget(struct tty_struct *tty, struct file *file)
A
Alain Degreffe 已提交
176
{
A
Alan Cox 已提交
177
	struct usb_serial_port *port = tty->driver_data;
A
Alain Degreffe 已提交
178
	struct iuu_private *priv = usb_get_serial_port_data(port);
179 180 181 182 183 184 185 186
	unsigned long flags;
	int rc;

	spin_lock_irqsave(&priv->lock, flags);
	rc = priv->tiostatus;
	spin_unlock_irqrestore(&priv->lock, flags);

	return rc;
A
Alain Degreffe 已提交
187 188 189 190
}

static void iuu_rxcmd(struct urb *urb)
{
191
	struct usb_serial_port *port = urb->context;
A
Alain Degreffe 已提交
192
	int result;
193 194
	int status = urb->status;

195
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
196

197 198
	if (status) {
		dbg("%s - status = %d", __func__, status);
A
Alain Degreffe 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
		/* error stop all */
		return;
	}


	memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1);
	usb_fill_bulk_urb(port->write_urb, port->serial->dev,
			  usb_sndbulkpipe(port->serial->dev,
					  port->bulk_out_endpointAddress),
			  port->write_urb->transfer_buffer, 1,
			  read_rxcmd_callback, port);
	result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
}

static int iuu_reset(struct usb_serial_port *port, u8 wt)
{
	struct iuu_private *priv = usb_get_serial_port_data(port);
	int result;
	char *buf_ptr = port->write_urb->transfer_buffer;
218
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246

	/* Prepare the reset sequence */

	*buf_ptr++ = IUU_RST_SET;
	*buf_ptr++ = IUU_DELAY_MS;
	*buf_ptr++ = wt;
	*buf_ptr = IUU_RST_CLEAR;

	/* send the sequence */

	usb_fill_bulk_urb(port->write_urb,
			  port->serial->dev,
			  usb_sndbulkpipe(port->serial->dev,
					  port->bulk_out_endpointAddress),
			  port->write_urb->transfer_buffer, 4, iuu_rxcmd, port);
	result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
	priv->reset = 0;
	return result;
}

/* Status Function
 * Return value is
 * 0x00 = no card
 * 0x01 = smartcard
 * 0x02 = sim card
 */
static void iuu_update_status_callback(struct urb *urb)
{
247
	struct usb_serial_port *port = urb->context;
A
Alain Degreffe 已提交
248 249
	struct iuu_private *priv = usb_get_serial_port_data(port);
	u8 *st;
250 251
	int status = urb->status;

252
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
253

254 255
	if (status) {
		dbg("%s - status = %d", __func__, status);
A
Alain Degreffe 已提交
256 257 258 259 260
		/* error stop all */
		return;
	}

	st = urb->transfer_buffer;
261
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
	if (urb->actual_length == 1) {
		switch (st[0]) {
		case 0x1:
			priv->tiostatus = iuu_cardout;
			break;
		case 0x0:
			priv->tiostatus = iuu_cardin;
			break;
		default:
			priv->tiostatus = iuu_cardin;
		}
	}
	iuu_rxcmd(urb);
}

static void iuu_status_callback(struct urb *urb)
{
279
	struct usb_serial_port *port = urb->context;
A
Alain Degreffe 已提交
280
	int result;
281
	int status = urb->status;
A
Alain Degreffe 已提交
282

283
	dbg("%s - status = %d", __func__, status);
A
Alain Degreffe 已提交
284 285 286 287 288 289 290 291 292 293 294 295
	usb_fill_bulk_urb(port->read_urb, port->serial->dev,
			  usb_rcvbulkpipe(port->serial->dev,
					  port->bulk_in_endpointAddress),
			  port->read_urb->transfer_buffer, 256,
			  iuu_update_status_callback, port);
	result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
}

static int iuu_status(struct usb_serial_port *port)
{
	int result;

296
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314

	memset(port->write_urb->transfer_buffer, IUU_GET_STATE_REGISTER, 1);
	usb_fill_bulk_urb(port->write_urb, port->serial->dev,
			  usb_sndbulkpipe(port->serial->dev,
					  port->bulk_out_endpointAddress),
			  port->write_urb->transfer_buffer, 1,
			  iuu_status_callback, port);
	result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
	return result;

}

static int bulk_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
{
	int status;
	struct usb_serial *serial = port->serial;
	int actual = 0;

315
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
316 317 318 319 320 321 322 323 324

	/* send the data out the bulk port */

	status =
	    usb_bulk_msg(serial->dev,
			 usb_sndbulkpipe(serial->dev,
					 port->bulk_out_endpointAddress), buf,
			 count, &actual, HZ * 1);

325
	if (status != IUU_OPERATION_OK)
326
		dbg("%s - error = %2x", __func__, status);
327
	else
328
		dbg("%s - write OK !", __func__);
A
Alain Degreffe 已提交
329 330 331 332 333 334 335 336 337
	return status;
}

static int read_immediate(struct usb_serial_port *port, u8 *buf, u8 count)
{
	int status;
	struct usb_serial *serial = port->serial;
	int actual = 0;

338
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
339 340 341 342 343 344 345 346 347

	/* send the data out the bulk port */

	status =
	    usb_bulk_msg(serial->dev,
			 usb_rcvbulkpipe(serial->dev,
					 port->bulk_in_endpointAddress), buf,
			 count, &actual, HZ * 1);

348
	if (status != IUU_OPERATION_OK)
349
		dbg("%s - error = %2x", __func__, status);
350
	else
351
		dbg("%s - read OK !", __func__);
A
Alain Degreffe 已提交
352 353 354 355 356 357 358 359 360 361 362 363
	return status;
}

static int iuu_led(struct usb_serial_port *port, unsigned int R,
		   unsigned int G, unsigned int B, u8 f)
{
	int status;
	u8 *buf;
	buf = kmalloc(8, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;

364
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
365 366 367 368 369 370 371 372 373 374 375 376

	buf[0] = IUU_SET_LED;
	buf[1] = R & 0xFF;
	buf[2] = (R >> 8) & 0xFF;
	buf[3] = G & 0xFF;
	buf[4] = (G >> 8) & 0xFF;
	buf[5] = B & 0xFF;
	buf[6] = (B >> 8) & 0xFF;
	buf[7] = f;
	status = bulk_immediate(port, buf, 8);
	kfree(buf);
	if (status != IUU_OPERATION_OK)
377
		dbg("%s - led error status = %2x", __func__, status);
A
Alain Degreffe 已提交
378
	else
379
		dbg("%s - led OK !", __func__);
A
Alain Degreffe 已提交
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
	return IUU_OPERATION_OK;
}

static void iuu_rgbf_fill_buffer(u8 *buf, u8 r1, u8 r2, u8 g1, u8 g2, u8 b1,
				 u8 b2, u8 freq)
{
	*buf++ = IUU_SET_LED;
	*buf++ = r1;
	*buf++ = r2;
	*buf++ = g1;
	*buf++ = g2;
	*buf++ = b1;
	*buf++ = b2;
	*buf = freq;
}

static void iuu_led_activity_on(struct urb *urb)
{
398
	struct usb_serial_port *port = urb->context;
A
Alain Degreffe 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
	int result;
	char *buf_ptr = port->write_urb->transfer_buffer;
	*buf_ptr++ = IUU_SET_LED;
	if (xmas == 1) {
		get_random_bytes(buf_ptr, 6);
		*(buf_ptr+7) = 1;
	} else {
		iuu_rgbf_fill_buffer(buf_ptr, 255, 255, 0, 0, 0, 0, 255);
	}

	usb_fill_bulk_urb(port->write_urb, port->serial->dev,
			  usb_sndbulkpipe(port->serial->dev,
					  port->bulk_out_endpointAddress),
			  port->write_urb->transfer_buffer, 8 ,
			  iuu_rxcmd, port);
	result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
}

static void iuu_led_activity_off(struct urb *urb)
{
419
	struct usb_serial_port *port = urb->context;
A
Alain Degreffe 已提交
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
	int result;
	char *buf_ptr = port->write_urb->transfer_buffer;
	if (xmas == 1) {
		iuu_rxcmd(urb);
		return;
	} else {
		*buf_ptr++ = IUU_SET_LED;
		iuu_rgbf_fill_buffer(buf_ptr, 0, 0, 255, 255, 0, 0, 255);
	}
	usb_fill_bulk_urb(port->write_urb, port->serial->dev,
			  usb_sndbulkpipe(port->serial->dev,
					  port->bulk_out_endpointAddress),
			  port->write_urb->transfer_buffer, 8 ,
			  iuu_rxcmd, port);
	result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
}



static int iuu_clk(struct usb_serial_port *port, int dwFrq)
{
	int status;
	struct iuu_private *priv = usb_get_serial_port_data(port);
	int Count = 0;
	u8 FrqGenAdr = 0x69;
	u8 DIV = 0;		/* 8bit */
	u8 XDRV = 0;		/* 8bit */
	u8 PUMP = 0;		/* 3bit */
	u8 PBmsb = 0;		/* 2bit */
	u8 PBlsb = 0;		/* 8bit */
	u8 PO = 0;		/* 1bit */
	u8 Q = 0;		/* 7bit */
	/* 24bit = 3bytes */
	unsigned int P = 0;
	unsigned int P2 = 0;
	int frq = (int)dwFrq;

457
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
458 459 460 461 462 463 464 465 466

	if (frq == 0) {
		priv->buf[Count++] = IUU_UART_WRITE_I2C;
		priv->buf[Count++] = FrqGenAdr << 1;
		priv->buf[Count++] = 0x09;
		priv->buf[Count++] = 0x00;

		status = bulk_immediate(port, (u8 *) priv->buf, Count);
		if (status != 0) {
467
			dbg("%s - write error ", __func__);
A
Alain Degreffe 已提交
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
			return status;
		}
	} else if (frq == 3579000) {
		DIV = 100;
		P = 1193;
		Q = 40;
		XDRV = 0;
	} else if (frq == 3680000) {
		DIV = 105;
		P = 161;
		Q = 5;
		XDRV = 0;
	} else if (frq == 6000000) {
		DIV = 66;
		P = 66;
		Q = 2;
		XDRV = 0x28;
	} else {
		unsigned int result = 0;
		unsigned int tmp = 0;
		unsigned int check;
		unsigned int check2;
		char found = 0x00;
		unsigned int lQ = 2;
		unsigned int lP = 2055;
		unsigned int lDiv = 4;

		for (lQ = 2; lQ <= 47 && !found; lQ++)
			for (lP = 2055; lP >= 8 && !found; lP--)
				for (lDiv = 4; lDiv <= 127 && !found; lDiv++) {
					tmp = (12000000 / lDiv) * (lP / lQ);
					if (abs((int)(tmp - frq)) <
					    abs((int)(frq - result))) {
						check2 = (12000000 / lQ);
						if (check2 < 250000)
							continue;
						check = (12000000 / lQ) * lP;
						if (check > 400000000)
							continue;
						if (check < 100000000)
							continue;
						if (lDiv < 4 || lDiv > 127)
							continue;
						result = tmp;
						P = lP;
						DIV = lDiv;
						Q = lQ;
						if (result == frq)
							found = 0x01;
					}
				}
	}
	P2 = ((P - PO) / 2) - 4;
	DIV = DIV;
	PUMP = 0x04;
	PBmsb = (P2 >> 8 & 0x03);
	PBlsb = P2 & 0xFF;
	PO = (P >> 10) & 0x01;
	Q = Q - 2;

	priv->buf[Count++] = IUU_UART_WRITE_I2C;	/* 0x4C */
	priv->buf[Count++] = FrqGenAdr << 1;
	priv->buf[Count++] = 0x09;
	priv->buf[Count++] = 0x20;	/* Adr = 0x09 */
	priv->buf[Count++] = IUU_UART_WRITE_I2C;	/* 0x4C */
	priv->buf[Count++] = FrqGenAdr << 1;
	priv->buf[Count++] = 0x0C;
	priv->buf[Count++] = DIV;	/* Adr = 0x0C */
	priv->buf[Count++] = IUU_UART_WRITE_I2C;	/* 0x4C */
	priv->buf[Count++] = FrqGenAdr << 1;
	priv->buf[Count++] = 0x12;
	priv->buf[Count++] = XDRV;	/* Adr = 0x12 */
	priv->buf[Count++] = IUU_UART_WRITE_I2C;	/*  0x4C */
	priv->buf[Count++] = FrqGenAdr << 1;
	priv->buf[Count++] = 0x13;
	priv->buf[Count++] = 0x6B;	/* Adr = 0x13 */
	priv->buf[Count++] = IUU_UART_WRITE_I2C;	/*  0x4C */
	priv->buf[Count++] = FrqGenAdr << 1;
	priv->buf[Count++] = 0x40;
	priv->buf[Count++] = (0xC0 | ((PUMP & 0x07) << 2)) |
			     (PBmsb & 0x03);	/* Adr = 0x40 */
	priv->buf[Count++] = IUU_UART_WRITE_I2C;	/*  0x4C */
	priv->buf[Count++] = FrqGenAdr << 1;
	priv->buf[Count++] = 0x41;
	priv->buf[Count++] = PBlsb;	/* Adr = 0x41 */
	priv->buf[Count++] = IUU_UART_WRITE_I2C;	/*  0x4C */
	priv->buf[Count++] = FrqGenAdr << 1;
	priv->buf[Count++] = 0x42;
	priv->buf[Count++] = Q | (((PO & 0x01) << 7));	/* Adr = 0x42 */
	priv->buf[Count++] = IUU_UART_WRITE_I2C;	/*  0x4C */
	priv->buf[Count++] = FrqGenAdr << 1;
	priv->buf[Count++] = 0x44;
	priv->buf[Count++] = (char)0xFF;	/* Adr = 0x44 */
	priv->buf[Count++] = IUU_UART_WRITE_I2C;	/*  0x4C */
	priv->buf[Count++] = FrqGenAdr << 1;
	priv->buf[Count++] = 0x45;
	priv->buf[Count++] = (char)0xFE;	/* Adr = 0x45 */
	priv->buf[Count++] = IUU_UART_WRITE_I2C;	/*  0x4C */
	priv->buf[Count++] = FrqGenAdr << 1;
	priv->buf[Count++] = 0x46;
	priv->buf[Count++] = 0x7F;	/* Adr = 0x46 */
	priv->buf[Count++] = IUU_UART_WRITE_I2C;	/*  0x4C */
	priv->buf[Count++] = FrqGenAdr << 1;
	priv->buf[Count++] = 0x47;
	priv->buf[Count++] = (char)0x84;	/* Adr = 0x47 */

	status = bulk_immediate(port, (u8 *) priv->buf, Count);
	if (status != IUU_OPERATION_OK)
576
		dbg("%s - write error ", __func__);
A
Alain Degreffe 已提交
577 578 579 580 581 582 583 584 585 586
	return status;
}

static int iuu_uart_flush(struct usb_serial_port *port)
{
	int i;
	int status;
	u8 rxcmd = IUU_UART_RX;
	struct iuu_private *priv = usb_get_serial_port_data(port);

587
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
588 589 590 591 592 593 594

	if (iuu_led(port, 0xF000, 0, 0, 0xFF) < 0)
		return -EIO;

	for (i = 0; i < 2; i++) {
		status = bulk_immediate(port, &rxcmd, 1);
		if (status != IUU_OPERATION_OK) {
595
			dbg("%s - uart_flush_write error", __func__);
A
Alain Degreffe 已提交
596 597 598 599 600
			return status;
		}

		status = read_immediate(port, &priv->len, 1);
		if (status != IUU_OPERATION_OK) {
601
			dbg("%s - uart_flush_read error", __func__);
A
Alain Degreffe 已提交
602 603 604 605
			return status;
		}

		if (priv->len > 0) {
606
			dbg("%s - uart_flush datalen is : %i ", __func__,
A
Alain Degreffe 已提交
607 608 609
			    priv->len);
			status = read_immediate(port, priv->buf, priv->len);
			if (status != IUU_OPERATION_OK) {
610
				dbg("%s - uart_flush_read error", __func__);
A
Alain Degreffe 已提交
611 612 613 614
				return status;
			}
		}
	}
615
	dbg("%s - uart_flush_read OK!", __func__);
A
Alain Degreffe 已提交
616 617 618 619 620 621
	iuu_led(port, 0, 0xF000, 0, 0xFF);
	return status;
}

static void read_buf_callback(struct urb *urb)
{
622
	struct usb_serial_port *port = urb->context;
A
Alain Degreffe 已提交
623 624
	unsigned char *data = urb->transfer_buffer;
	struct tty_struct *tty;
625
	int status = urb->status;
A
Alain Degreffe 已提交
626

627 628 629 630
	dbg("%s - status = %d", __func__, status);

	if (status) {
		if (status == -EPROTO) {
A
Alain Degreffe 已提交
631 632 633 634 635
			/* reschedule needed */
		}
		return;
	}

636
	dbg("%s - %i chars to write", __func__, urb->actual_length);
A
Alan Cox 已提交
637
	tty = tty_port_tty_get(&port->port);
A
Alain Degreffe 已提交
638
	if (data == NULL)
639
		dbg("%s - data is NULL !!!", __func__);
A
Alain Degreffe 已提交
640 641 642 643
	if (tty && urb->actual_length && data) {
		tty_insert_flip_string(tty, data, urb->actual_length);
		tty_flip_buffer_push(tty);
	}
A
Alan Cox 已提交
644
	tty_kref_put(tty);
A
Alain Degreffe 已提交
645 646 647 648 649 650
	iuu_led_activity_on(urb);
}

static int iuu_bulk_write(struct usb_serial_port *port)
{
	struct iuu_private *priv = usb_get_serial_port_data(port);
S
Steven Rostedt 已提交
651
	unsigned long flags;
A
Alain Degreffe 已提交
652 653 654
	int result;
	int i;
	char *buf_ptr = port->write_urb->transfer_buffer;
655
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
656 657 658 659 660 661 662 663 664 665 666 667

	*buf_ptr++ = IUU_UART_ESC;
	*buf_ptr++ = IUU_UART_TX;
	*buf_ptr++ = priv->writelen;

	memcpy(buf_ptr, priv->writebuf,
	       priv->writelen);
	if (debug == 1) {
		for (i = 0; i < priv->writelen; i++)
			sprintf(priv->dbgbuf + i*2 ,
				"%02X", priv->writebuf[i]);
		priv->dbgbuf[priv->writelen+i*2] = 0;
668
		dbg("%s - writing %i chars : %s", __func__,
A
Alain Degreffe 已提交
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
		    priv->writelen, priv->dbgbuf);
	}
	usb_fill_bulk_urb(port->write_urb, port->serial->dev,
			  usb_sndbulkpipe(port->serial->dev,
					  port->bulk_out_endpointAddress),
			  port->write_urb->transfer_buffer, priv->writelen + 3,
			  iuu_rxcmd, port);
	result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
	spin_lock_irqsave(&priv->lock, flags);
	priv->writelen = 0;
	spin_unlock_irqrestore(&priv->lock, flags);
	usb_serial_port_softint(port);
	return result;
}

static int iuu_read_buf(struct usb_serial_port *port, int len)
{
	int result;
687
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
688 689 690 691 692 693 694 695 696 697 698 699

	usb_fill_bulk_urb(port->read_urb, port->serial->dev,
			  usb_rcvbulkpipe(port->serial->dev,
					  port->bulk_in_endpointAddress),
			  port->read_urb->transfer_buffer, len,
			  read_buf_callback, port);
	result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
	return result;
}

static void iuu_uart_read_callback(struct urb *urb)
{
700
	struct usb_serial_port *port = urb->context;
A
Alain Degreffe 已提交
701
	struct iuu_private *priv = usb_get_serial_port_data(port);
S
Steven Rostedt 已提交
702
	unsigned long flags;
703
	int status = urb->status;
A
Alain Degreffe 已提交
704 705 706 707 708
	int error = 0;
	int len = 0;
	unsigned char *data = urb->transfer_buffer;
	priv->poll++;

709
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
710

711 712
	if (status) {
		dbg("%s - status = %d", __func__, status);
A
Alain Degreffe 已提交
713 714 715 716
		/* error stop all */
		return;
	}
	if (data == NULL)
717
		dbg("%s - data is NULL !!!", __func__);
A
Alain Degreffe 已提交
718 719 720 721 722

	if (urb->actual_length == 1  && data != NULL)
		len = (int) data[0];

	if (urb->actual_length > 1) {
723
		dbg("%s - urb->actual_length = %i", __func__,
A
Alain Degreffe 已提交
724 725 726 727 728 729 730 731
		    urb->actual_length);
		error = 1;
		return;
	}
	/* if len > 0 call readbuf */

	if (len > 0 && error == 0) {
		dbg("%s - call read buf - len to read is %i ",
732
			__func__, len);
A
Alain Degreffe 已提交
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
		status = iuu_read_buf(port, len);
		return;
	}
	/* need to update status  ? */
	if (priv->poll > 99) {
		status = iuu_status(port);
		priv->poll = 0;
		return;
	}

	/* reset waiting ? */

	if (priv->reset == 1) {
		status = iuu_reset(port, 0xC);
		return;
	}
	/* Writebuf is waiting */
	spin_lock_irqsave(&priv->lock, flags);
	if (priv->writelen > 0) {
		spin_unlock_irqrestore(&priv->lock, flags);
		status = iuu_bulk_write(port);
		return;
	}
	spin_unlock_irqrestore(&priv->lock, flags);
	/* if nothing to write call again rxcmd */
758
	dbg("%s - rxcmd recall", __func__);
A
Alain Degreffe 已提交
759 760 761
	iuu_led_activity_off(urb);
}

A
Alan Cox 已提交
762 763
static int iuu_uart_write(struct tty_struct *tty, struct usb_serial_port *port,
			  const u8 *buf, int count)
A
Alain Degreffe 已提交
764 765
{
	struct iuu_private *priv = usb_get_serial_port_data(port);
S
Steven Rostedt 已提交
766
	unsigned long flags;
767
	dbg("%s - enter", __func__);
A
Alain Degreffe 已提交
768 769 770 771 772 773 774 775

	if (count > 256)
		return -ENOMEM;

	spin_lock_irqsave(&priv->lock, flags);
	if (priv->writelen > 0) {
		/* buffer already filled but not commited */
		spin_unlock_irqrestore(&priv->lock, flags);
776
		return 0;
A
Alain Degreffe 已提交
777 778 779 780 781 782
	}
	/* fill the buffer */
	memcpy(priv->writebuf, buf, count);
	priv->writelen = count;
	spin_unlock_irqrestore(&priv->lock, flags);

783
	return count;
A
Alain Degreffe 已提交
784 785 786 787
}

static void read_rxcmd_callback(struct urb *urb)
{
788
	struct usb_serial_port *port = urb->context;
A
Alain Degreffe 已提交
789
	int result;
790
	int status = urb->status;
A
Alain Degreffe 已提交
791

792
	dbg("%s - status = %d", __func__, status);
A
Alain Degreffe 已提交
793

794
	if (status) {
A
Alain Degreffe 已提交
795 796 797 798 799 800 801 802 803 804
		/* error stop all */
		return;
	}

	usb_fill_bulk_urb(port->read_urb, port->serial->dev,
			  usb_rcvbulkpipe(port->serial->dev,
					  port->bulk_in_endpointAddress),
			  port->read_urb->transfer_buffer, 256,
			  iuu_uart_read_callback, port);
	result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
805
	dbg("%s - submit result = %d", __func__, result);
A
Alain Degreffe 已提交
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
	return;
}

static int iuu_uart_on(struct usb_serial_port *port)
{
	int status;
	u8 *buf;

	buf = kmalloc(sizeof(u8) * 4, GFP_KERNEL);

	if (!buf)
		return -ENOMEM;

	buf[0] = IUU_UART_ENABLE;
	buf[1] = (u8) ((IUU_BAUD_9600 >> 8) & 0x00FF);
	buf[2] = (u8) (0x00FF & IUU_BAUD_9600);
	buf[3] = (u8) (0x0F0 & IUU_TWO_STOP_BITS) | (0x07 & IUU_PARITY_EVEN);

	status = bulk_immediate(port, buf, 4);
	if (status != IUU_OPERATION_OK) {
826
		dbg("%s - uart_on error", __func__);
A
Alain Degreffe 已提交
827 828 829 830 831
		goto uart_enable_failed;
	}
	/*  iuu_reset() the card after iuu_uart_on() */
	status = iuu_uart_flush(port);
	if (status != IUU_OPERATION_OK)
832
		dbg("%s - uart_flush error", __func__);
A
Alain Degreffe 已提交
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
uart_enable_failed:
	kfree(buf);
	return status;
}

/*  Diables the IUU UART (a.k.a. the Phoenix voiderface) */
static int iuu_uart_off(struct usb_serial_port *port)
{
	int status;
	u8 *buf;
	buf = kmalloc(1, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
	buf[0] = IUU_UART_DISABLE;

	status = bulk_immediate(port, buf, 1);
	if (status != IUU_OPERATION_OK)
850
		dbg("%s - uart_off error", __func__);
A
Alain Degreffe 已提交
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943

	kfree(buf);
	return status;
}

static int iuu_uart_baud(struct usb_serial_port *port, u32 baud,
			 u32 *actual, u8 parity)
{
	int status;
	u8 *dataout;
	u8 DataCount = 0;
	u8 T1Frekvens = 0;
	u8 T1reload = 0;
	unsigned int T1FrekvensHZ = 0;

	dataout = kmalloc(sizeof(u8) * 5, GFP_KERNEL);

	if (!dataout)
		return -ENOMEM;

	if (baud < 1200 || baud > 230400) {
		kfree(dataout);
		return IUU_INVALID_PARAMETER;
	}
	if (baud > 977) {
		T1Frekvens = 3;
		T1FrekvensHZ = 500000;
	}

	if (baud > 3906) {
		T1Frekvens = 2;
		T1FrekvensHZ = 2000000;
	}

	if (baud > 11718) {
		T1Frekvens = 1;
		T1FrekvensHZ = 6000000;
	}

	if (baud > 46875) {
		T1Frekvens = 0;
		T1FrekvensHZ = 24000000;
	}

	T1reload = 256 - (u8) (T1FrekvensHZ / (baud * 2));

	/*  magic number here:  ENTER_FIRMWARE_UPDATE; */
	dataout[DataCount++] = IUU_UART_ESC;
	/*  magic number here:  CHANGE_BAUD; */
	dataout[DataCount++] = IUU_UART_CHANGE;
	dataout[DataCount++] = T1Frekvens;
	dataout[DataCount++] = T1reload;

	*actual = (T1FrekvensHZ / (256 - T1reload)) / 2;

	switch (parity & 0x0F) {
	case IUU_PARITY_NONE:
		dataout[DataCount++] = 0x00;
		break;
	case IUU_PARITY_EVEN:
		dataout[DataCount++] = 0x01;
		break;
	case IUU_PARITY_ODD:
		dataout[DataCount++] = 0x02;
		break;
	case IUU_PARITY_MARK:
		dataout[DataCount++] = 0x03;
		break;
	case IUU_PARITY_SPACE:
		dataout[DataCount++] = 0x04;
		break;
	default:
		kfree(dataout);
		return IUU_INVALID_PARAMETER;
		break;
	}

	switch (parity & 0xF0) {
	case IUU_ONE_STOP_BIT:
		dataout[DataCount - 1] |= IUU_ONE_STOP_BIT;
		break;

	case IUU_TWO_STOP_BITS:
		dataout[DataCount - 1] |= IUU_TWO_STOP_BITS;
		break;
	default:
		kfree(dataout);
		return IUU_INVALID_PARAMETER;
		break;
	}

	status = bulk_immediate(port, dataout, DataCount);
	if (status != IUU_OPERATION_OK)
944
		dbg("%s - uart_off error", __func__);
A
Alain Degreffe 已提交
945 946 947 948 949 950 951 952 953
	kfree(dataout);
	return status;
}

static int set_control_lines(struct usb_device *dev, u8 value)
{
	return 0;
}

A
Alan Cox 已提交
954 955
static void iuu_close(struct tty_struct *tty,
			struct usb_serial_port *port, struct file *filp)
A
Alain Degreffe 已提交
956 957 958 959 960 961 962 963 964 965 966
{
	/* iuu_led (port,255,0,0,0); */
	struct usb_serial *serial;
	struct iuu_private *priv = usb_get_serial_port_data(port);
	unsigned long flags;
	unsigned int c_cflag;

	serial = port->serial;
	if (!serial)
		return;

967
	dbg("%s - port %d", __func__, port->number);
A
Alain Degreffe 已提交
968 969 970

	iuu_uart_off(port);
	if (serial->dev) {
A
Alan Cox 已提交
971 972
		if (tty) {
			c_cflag = tty->termios->c_cflag;
A
Alain Degreffe 已提交
973 974 975 976 977 978 979 980 981 982 983
			if (c_cflag & HUPCL) {
				/* drop DTR and RTS */
				priv = usb_get_serial_port_data(port);
				spin_lock_irqsave(&priv->lock, flags);
				priv->line_control = 0;
				spin_unlock_irqrestore(&priv->lock, flags);
				set_control_lines(port->serial->dev, 0);
			}
		}
		/* free writebuf */
		/* shutdown our urbs */
984
		dbg("%s - shutting down urbs", __func__);
A
Alain Degreffe 已提交
985 986 987 988 989 990 991 992 993 994 995
		usb_kill_urb(port->write_urb);
		usb_kill_urb(port->read_urb);
		usb_kill_urb(port->interrupt_in_urb);
		msleep(1000);
		/* wait one second to free all buffers */
		iuu_led(port, 0, 0, 0xF000, 0xFF);
		msleep(1000);
		usb_reset_device(port->serial->dev);
	}
}

A
Alan Cox 已提交
996 997
static int iuu_open(struct tty_struct *tty,
			struct usb_serial_port *port, struct file *filp)
A
Alain Degreffe 已提交
998 999 1000 1001 1002 1003 1004 1005
{
	struct usb_serial *serial = port->serial;
	u8 *buf;
	int result;
	u32 actual;
	unsigned long flags;
	struct iuu_private *priv = usb_get_serial_port_data(port);

1006
	dbg("%s -  port %d", __func__, port->number);
A
Alain Degreffe 已提交
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
	usb_clear_halt(serial->dev, port->write_urb->pipe);
	usb_clear_halt(serial->dev, port->read_urb->pipe);

	buf = kmalloc(10, GFP_KERNEL);
	if (buf == NULL)
		return -ENOMEM;

	/* fixup the endpoint buffer size */
	kfree(port->bulk_out_buffer);
	port->bulk_out_buffer = kmalloc(512, GFP_KERNEL);
	port->bulk_out_size = 512;
	kfree(port->bulk_in_buffer);
	port->bulk_in_buffer = kmalloc(512, GFP_KERNEL);
	port->bulk_in_size = 512;

	if (!port->bulk_out_buffer || !port->bulk_in_buffer) {
		kfree(port->bulk_out_buffer);
		kfree(port->bulk_in_buffer);
		kfree(buf);
		return -ENOMEM;
	}

	usb_fill_bulk_urb(port->write_urb, port->serial->dev,
			  usb_sndbulkpipe(port->serial->dev,
					  port->bulk_out_endpointAddress),
			  port->bulk_out_buffer, 512,
			  NULL, NULL);


	usb_fill_bulk_urb(port->read_urb, port->serial->dev,
			  usb_rcvbulkpipe(port->serial->dev,
					  port->bulk_in_endpointAddress),
			  port->bulk_in_buffer, 512,
			  NULL, NULL);

	/* set the termios structure */
	spin_lock_irqsave(&priv->lock, flags);
A
Alan Cox 已提交
1044 1045 1046 1047 1048 1049 1050 1051 1052
	if (tty && !priv->termios_initialized) {
		*(tty->termios) = tty_std_termios;
		tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600
					| TIOCM_CTS | CSTOPB | PARENB;
		tty->termios->c_ispeed = 9600;
		tty->termios->c_ospeed = 9600;
		tty->termios->c_lflag = 0;
		tty->termios->c_oflag = 0;
		tty->termios->c_iflag = 0;
A
Alain Degreffe 已提交
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
		priv->termios_initialized = 1;
		priv->poll = 0;
	 }
	spin_unlock_irqrestore(&priv->lock, flags);

	/* initialize writebuf */
#define FISH(a, b, c, d) do { \
	result = usb_control_msg(port->serial->dev,	\
				usb_rcvctrlpipe(port->serial->dev, 0),	\
				b, a, c, d, buf, 1, 1000); \
	dbg("0x%x:0x%x:0x%x:0x%x  %d - %x", a, b, c, d, result, \
				buf[0]); } while (0);

#define SOUP(a, b, c, d)  do { \
	result = usb_control_msg(port->serial->dev,	\
				usb_sndctrlpipe(port->serial->dev, 0),	\
				b, a, c, d, NULL, 0, 1000); \
	dbg("0x%x:0x%x:0x%x:0x%x  %d", a, b, c, d, result); } while (0)

	/*  This is not UART related but IUU USB driver related or something */
	/*  like that. Basically no IUU will accept any commands from the USB */
	/*  host unless it has received the following message */
	/* sprintf(buf ,"%c%c%c%c",0x03,0x02,0x02,0x0); */

	SOUP(0x03, 0x02, 0x02, 0x0);
	kfree(buf);
	iuu_led(port, 0xF000, 0xF000, 0, 0xFF);
	iuu_uart_on(port);
	if (boost < 100)
		boost = 100;
	switch (clockmode) {
	case 2:		/*  3.680 Mhz */
		iuu_clk(port, IUU_CLK_3680000 * boost / 100);
		result =
		    iuu_uart_baud(port, 9600 * boost / 100, &actual,
				  IUU_PARITY_EVEN);
		break;
	case 3:		/*  6.00 Mhz */
		iuu_clk(port, IUU_CLK_6000000 * boost / 100);
		result =
		    iuu_uart_baud(port, 16457 * boost / 100, &actual,
				  IUU_PARITY_EVEN);
		break;
	default:		/*  3.579 Mhz */
		iuu_clk(port, IUU_CLK_3579000 * boost / 100);
		result =
		    iuu_uart_baud(port, 9600 * boost / 100, &actual,
				  IUU_PARITY_EVEN);
	}

	/* set the cardin cardout signals */
	switch (cdmode) {
	case 0:
		iuu_cardin = 0;
		iuu_cardout = 0;
		break;
	case 1:
		iuu_cardin = TIOCM_CD;
		iuu_cardout =  0;
		break;
	case 2:
		iuu_cardin = 0;
		iuu_cardout = TIOCM_CD;
		break;
	case 3:
		iuu_cardin = TIOCM_DSR;
		iuu_cardout = 0;
		break;
	case 4:
		iuu_cardin = 0;
		iuu_cardout = TIOCM_DSR;
		break;
	case 5:
		iuu_cardin = TIOCM_CTS;
		iuu_cardout = 0;
		break;
	case 6:
		iuu_cardin = 0;
		iuu_cardout = TIOCM_CTS;
		break;
	case 7:
		iuu_cardin = TIOCM_RNG;
		iuu_cardout = 0;
		break;
	case 8:
		iuu_cardin = 0;
		iuu_cardout = TIOCM_RNG;
	}

	iuu_uart_flush(port);

1144
	dbg("%s - initialization done", __func__);
A
Alain Degreffe 已提交
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155

	memset(port->write_urb->transfer_buffer, IUU_UART_RX, 1);
	usb_fill_bulk_urb(port->write_urb, port->serial->dev,
			  usb_sndbulkpipe(port->serial->dev,
					  port->bulk_out_endpointAddress),
			  port->write_urb->transfer_buffer, 1,
			  read_rxcmd_callback, port);
	result = usb_submit_urb(port->write_urb, GFP_KERNEL);

	if (result) {
		dev_err(&port->dev, "%s - failed submitting read urb,"
1156
			" error %d\n", __func__, result);
A
Alan Cox 已提交
1157
		iuu_close(tty, port, NULL);
A
Alain Degreffe 已提交
1158 1159
		return -EPROTO;
	} else {
1160
		dbg("%s - rxcmd OK", __func__);
A
Alain Degreffe 已提交
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
	}
	return result;
}

static struct usb_serial_driver iuu_device = {
	.driver = {
		   .owner = THIS_MODULE,
		   .name = "iuu_phoenix",
		   },
	.id_table = id_table,
	.num_ports = 1,
	.open = iuu_open,
	.close = iuu_close,
	.write = iuu_uart_write,
	.read_bulk_callback = iuu_uart_read_callback,
	.tiocmget = iuu_tiocmget,
	.tiocmset = iuu_tiocmset,
	.attach = iuu_startup,
	.shutdown = iuu_shutdown,
};

static int __init iuu_init(void)
{
	int retval;
	retval = usb_serial_register(&iuu_device);
	if (retval)
		goto failed_usb_serial_register;
	retval = usb_register(&iuu_driver);
	if (retval)
		goto failed_usb_register;
1191 1192
	printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
	       DRIVER_DESC "\n");
A
Alain Degreffe 已提交
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
	return 0;
failed_usb_register:
	usb_serial_deregister(&iuu_device);
failed_usb_serial_register:
	return retval;
}

static void __exit iuu_exit(void)
{
	usb_deregister(&iuu_driver);
	usb_serial_deregister(&iuu_device);
}

module_init(iuu_init);
module_exit(iuu_exit);

MODULE_AUTHOR("Alain Degreffe eczema@ecze.com");

MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");

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

module_param(xmas, bool, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(xmas, "xmas color enabled or not");

module_param(boost, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(boost, "overclock boost percent 100 to 500");

module_param(clockmode, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(clockmode, "1=3Mhz579,2=3Mhz680,3=6Mhz");

module_param(cdmode, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(cdmode, "Card detect mode 0=none, 1=CD, 2=!CD, 3=DSR, "
		 "4=!DSR, 5=CTS, 6=!CTS, 7=RING, 8=!RING");