Merge git://git.infradead.org/~dwmw2/rbtree-2.6
[linux-2.6] / drivers / usb / serial / io_ti.c
1 /*
2  * Edgeport USB Serial Converter driver
3  *
4  * Copyright (C) 2000-2002 Inside Out Networks, All rights reserved.
5  * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
6  *
7  *      This program is free software; you can redistribute it and/or modify
8  *      it under the terms of the GNU General Public License as published by
9  *      the Free Software Foundation; either version 2 of the License, or
10  *      (at your option) any later version.
11  *
12  * Supports the following devices:
13  *      EP/1 EP/2 EP/4 EP/21 EP/22 EP/221 EP/42 EP/421 WATCHPORT
14  *
15  * For questions or problems with this driver, contact Inside Out
16  * Networks technical support, or Peter Berger <pberger@brimson.com>,
17  * or Al Borchers <alborchers@steinerpoint.com>.
18  *
19  * Version history:
20  *
21  *      July 11, 2002   Removed 4 port device structure since all TI UMP 
22  *                      chips have only 2 ports 
23  *                      David Iacovelli (davidi@ionetworks.com)
24  *
25  */
26
27 #include <linux/config.h>
28 #include <linux/kernel.h>
29 #include <linux/jiffies.h>
30 #include <linux/errno.h>
31 #include <linux/init.h>
32 #include <linux/slab.h>
33 #include <linux/tty.h>
34 #include <linux/tty_driver.h>
35 #include <linux/tty_flip.h>
36 #include <linux/module.h>
37 #include <linux/spinlock.h>
38 #include <linux/serial.h>
39 #include <linux/ioctl.h>
40 #include <asm/uaccess.h>
41 #include <asm/semaphore.h>
42 #include <linux/usb.h>
43
44 #include "usb-serial.h"
45 #include "io_16654.h"
46 #include "io_usbvend.h"
47 #include "io_ti.h"
48
49 /*
50  * Version Information
51  */
52 #define DRIVER_VERSION "v0.7"
53 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
54 #define DRIVER_DESC "Edgeport USB Serial Driver"
55
56
57 /* firmware image code */
58 #define IMAGE_VERSION_NAME      PagableOperationalCodeImageVersion
59 #define IMAGE_ARRAY_NAME        PagableOperationalCodeImage
60 #define IMAGE_SIZE              PagableOperationalCodeSize
61 #include "io_fw_down3.h"        /* Define array OperationalCodeImage[] */
62
63 #define EPROM_PAGE_SIZE         64
64
65
66 struct edgeport_uart_buf_desc {
67         __u32 count;            // Number of bytes currently in buffer
68 };
69
70 /* different hardware types */
71 #define HARDWARE_TYPE_930       0
72 #define HARDWARE_TYPE_TIUMP     1
73
74 // IOCTL_PRIVATE_TI_GET_MODE Definitions
75 #define TI_MODE_CONFIGURING     0   // Device has not entered start device 
76 #define TI_MODE_BOOT            1   // Staying in boot mode
77 #define TI_MODE_DOWNLOAD        2   // Made it to download mode
78 #define TI_MODE_TRANSITIONING   3   // Currently in boot mode but transitioning to download mode
79
80 /* read urb state */
81 #define EDGE_READ_URB_RUNNING   0
82 #define EDGE_READ_URB_STOPPING  1
83 #define EDGE_READ_URB_STOPPED   2
84
85 #define EDGE_LOW_LATENCY        1
86 #define EDGE_CLOSING_WAIT       4000    /* in .01 sec */
87
88 #define EDGE_OUT_BUF_SIZE       1024
89
90
91 /* Product information read from the Edgeport */
92 struct product_info
93 {
94         int     TiMode;                 // Current TI Mode
95         __u8    hardware_type;          // Type of hardware
96 } __attribute__((packed));
97
98 /* circular buffer */
99 struct edge_buf {
100         unsigned int    buf_size;
101         char            *buf_buf;
102         char            *buf_get;
103         char            *buf_put;
104 };
105
106 struct edgeport_port {
107         __u16 uart_base;
108         __u16 dma_address;
109         __u8 shadow_msr;
110         __u8 shadow_mcr;
111         __u8 shadow_lsr;
112         __u8 lsr_mask;
113         __u32 ump_read_timeout;         /* Number of miliseconds the UMP will
114                                            wait without data before completing
115                                            a read short */
116         int baud_rate;
117         int close_pending;
118         int lsr_event;
119         struct edgeport_uart_buf_desc tx;
120         struct async_icount     icount;
121         wait_queue_head_t       delta_msr_wait; /* for handling sleeping while
122                                                    waiting for msr change to
123                                                    happen */
124         struct edgeport_serial  *edge_serial;
125         struct usb_serial_port  *port;
126         __u8 bUartMode;         /* Port type, 0: RS232, etc. */ 
127         spinlock_t ep_lock;
128         int ep_read_urb_state;
129         int ep_write_urb_in_use;
130         struct edge_buf *ep_out_buf;
131 };
132
133 struct edgeport_serial {
134         struct product_info product_info;
135         u8 TI_I2C_Type;                 // Type of I2C in UMP
136         u8 TiReadI2C;                   // Set to TRUE if we have read the I2c in Boot Mode
137         struct semaphore es_sem;
138         int num_ports_open;
139         struct usb_serial *serial;
140 };
141
142
143 /* Devices that this driver supports */
144 static struct usb_device_id edgeport_1port_id_table [] = {
145         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
146         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
147         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
148         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) },
149         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) },
150         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) },
151         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) },
152         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) },
153         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) },
154         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) },
155         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) },
156         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) },
157         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) },
158         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) },
159         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) },
160         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) },
161         { }
162 };
163
164 static struct usb_device_id edgeport_2port_id_table [] = {
165         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
166         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
167         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
168         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
169         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
170         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
171         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
172         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
173         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) },
174         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) },
175         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) },
176         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) },
177 // The 4-port shows up as two 2-port devices
178         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) },
179         { }
180 };
181
182 /* Devices that this driver supports */
183 static struct usb_device_id id_table_combined [] = {
184         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
185         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
186         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
187         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROXIMITY) },
188         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOTION) },
189         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_MOISTURE) },
190         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_TEMPERATURE) },
191         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_HUMIDITY) },
192         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_POWER) },
193         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_LIGHT) },
194         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_RADIATION) },
195         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_DISTANCE) },
196         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_ACCELERATION) },
197         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_WP_PROX_DIST) },
198         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_HP4CD) },
199         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_PLUS_PWR_PCI) },
200         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
201         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
202         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
203         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
204         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
205         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
206         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
207         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
208         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22I) },
209         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_221C) },
210         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22C) },
211         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21C) },
212         { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4S) },
213         { }
214 };
215
216 MODULE_DEVICE_TABLE (usb, id_table_combined);
217
218 static struct usb_driver io_driver = {
219         .name =         "io_ti",
220         .probe =        usb_serial_probe,
221         .disconnect =   usb_serial_disconnect,
222         .id_table =     id_table_combined,
223         .no_dynamic_id =        1,
224 };
225
226
227 static struct EDGE_FIRMWARE_VERSION_INFO OperationalCodeImageVersion;
228
229 static int debug;
230
231 static int TIStayInBootMode = 0;
232 static int low_latency = EDGE_LOW_LATENCY;
233 static int closing_wait = EDGE_CLOSING_WAIT;
234 static int ignore_cpu_rev = 0;
235
236
237 static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length);
238
239 static void stop_read(struct edgeport_port *edge_port);
240 static int restart_read(struct edgeport_port *edge_port);
241
242 static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios);
243 static void edge_send(struct usb_serial_port *port);
244
245 /* circular buffer */
246 static struct edge_buf *edge_buf_alloc(unsigned int size);
247 static void edge_buf_free(struct edge_buf *eb);
248 static void edge_buf_clear(struct edge_buf *eb);
249 static unsigned int edge_buf_data_avail(struct edge_buf *eb);
250 static unsigned int edge_buf_space_avail(struct edge_buf *eb);
251 static unsigned int edge_buf_put(struct edge_buf *eb, const char *buf,
252         unsigned int count);
253 static unsigned int edge_buf_get(struct edge_buf *eb, char *buf,
254         unsigned int count);
255
256
257 static int TIReadVendorRequestSync (struct usb_device *dev,
258                                 __u8            request,
259                                 __u16           value,
260                                 __u16           index,
261                                 u8              *data,
262                                 int             size)
263 {
264         int status;
265
266         status = usb_control_msg (dev,
267                                 usb_rcvctrlpipe(dev, 0),
268                                 request,
269                                 (USB_TYPE_VENDOR | 
270                                  USB_RECIP_DEVICE | 
271                                  USB_DIR_IN),
272                                 value,
273                                 index,
274                                 data,
275                                 size,
276                                 1000);
277         if (status < 0)
278                 return status;
279         if (status != size) {
280                 dbg ("%s - wanted to write %d, but only wrote %d",
281                      __FUNCTION__, size, status);
282                 return -ECOMM;
283         }
284         return 0;
285 }
286
287 static int TISendVendorRequestSync (struct usb_device *dev,
288                                 __u8            request,
289                                 __u16           value,
290                                 __u16           index,
291                                 u8              *data,
292                                 int             size)
293 {
294         int status;
295
296         status = usb_control_msg (dev,
297                                 usb_sndctrlpipe(dev, 0),
298                                 request,
299                                 (USB_TYPE_VENDOR | 
300                                  USB_RECIP_DEVICE | 
301                                  USB_DIR_OUT),
302                                 value,
303                                 index,
304                                 data,
305                                 size,
306                                 1000);
307         if (status < 0)
308                 return status;
309         if (status != size) {
310                 dbg ("%s - wanted to write %d, but only wrote %d",
311                      __FUNCTION__, size, status);
312                 return -ECOMM;
313         }
314         return 0;
315 }
316
317 static int TIWriteCommandSync (struct usb_device *dev, __u8 command,
318                                 __u8 moduleid, __u16 value, u8 *data,
319                                 int size)
320 {
321         return TISendVendorRequestSync (dev,
322                                           command,                      // Request
323                                           value,                        // wValue 
324                                           moduleid,                     // wIndex
325                                           data,                         // TransferBuffer
326                                           size);                        // TransferBufferLength
327
328 }
329
330 /* clear tx/rx buffers and fifo in TI UMP */
331 static int TIPurgeDataSync (struct usb_serial_port *port, __u16 mask)
332 {
333         int port_number = port->number - port->serial->minor;
334
335         dbg ("%s - port %d, mask %x", __FUNCTION__, port_number, mask);
336
337         return TIWriteCommandSync (port->serial->dev,
338                                         UMPC_PURGE_PORT,
339                                         (__u8)(UMPM_UART1_PORT + port_number),
340                                         mask,
341                                         NULL,
342                                         0);
343 }
344
345 /**
346  * TIReadDownloadMemory - Read edgeport memory from TI chip
347  * @dev: usb device pointer
348  * @start_address: Device CPU address at which to read
349  * @length: Length of above data
350  * @address_type: Can read both XDATA and I2C
351  * @buffer: pointer to input data buffer
352  */
353 static int TIReadDownloadMemory(struct usb_device *dev, int start_address,
354                                 int length, __u8 address_type, __u8 *buffer)
355 {
356         int status = 0;
357         __u8 read_length;
358         __be16 be_start_address;
359         
360         dbg ("%s - @ %x for %d", __FUNCTION__, start_address, length);
361
362         /* Read in blocks of 64 bytes
363          * (TI firmware can't handle more than 64 byte reads)
364          */
365         while (length) {
366                 if (length > 64)
367                         read_length= 64;
368                 else
369                         read_length = (__u8)length;
370
371                 if (read_length > 1) {
372                         dbg ("%s - @ %x for %d", __FUNCTION__, 
373                              start_address, read_length);
374                 }
375                 be_start_address = cpu_to_be16 (start_address);
376                 status = TIReadVendorRequestSync (dev,
377                                                   UMPC_MEMORY_READ,     // Request
378                                                   (__u16)address_type,  // wValue (Address type)
379                                                   (__force __u16)be_start_address,      // wIndex (Address to read)
380                                                   buffer,               // TransferBuffer
381                                                   read_length); // TransferBufferLength
382
383                 if (status) {
384                         dbg ("%s - ERROR %x", __FUNCTION__, status);
385                         return status;
386                 }
387
388                 if (read_length > 1) {
389                         usb_serial_debug_data(debug, &dev->dev, __FUNCTION__,
390                                               read_length, buffer);
391                 }
392
393                 /* Update pointers/length */
394                 start_address += read_length;
395                 buffer += read_length;
396                 length -= read_length;
397         }
398         
399         return status;
400 }
401
402 static int TIReadRam (struct usb_device *dev, int start_address, int length, __u8 *buffer)
403 {
404         return TIReadDownloadMemory (dev,
405                                      start_address,
406                                      length,
407                                      DTK_ADDR_SPACE_XDATA,
408                                      buffer);
409 }
410
411 /* Read edgeport memory to a given block */
412 static int TIReadBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 * buffer)
413 {
414         int status = 0;
415         int i;
416
417         for (i=0; i< length; i++) {
418                 status = TIReadVendorRequestSync (serial->serial->dev,
419                                         UMPC_MEMORY_READ,               // Request
420                                         serial->TI_I2C_Type,            // wValue (Address type)
421                                         (__u16)(start_address+i),       // wIndex
422                                         &buffer[i],                     // TransferBuffer
423                                         0x01);                          // TransferBufferLength
424                 if (status) {
425                         dbg ("%s - ERROR %x", __FUNCTION__, status);
426                         return status;
427                 }
428         }
429
430         dbg ("%s - start_address = %x, length = %d", __FUNCTION__, start_address, length);
431         usb_serial_debug_data(debug, &serial->serial->dev->dev, __FUNCTION__, length, buffer);
432
433         serial->TiReadI2C = 1;
434
435         return status;
436 }
437
438 /* Write given block to TI EPROM memory */
439 static int TIWriteBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer)
440 {
441         int status = 0;
442         int i;
443         __u8 temp;
444
445         /* Must do a read before write */
446         if (!serial->TiReadI2C) {
447                 status = TIReadBootMemory(serial, 0, 1, &temp);
448                 if (status)
449                         return status;
450         }
451
452         for (i=0; i < length; ++i) {
453                 status = TISendVendorRequestSync (serial->serial->dev,
454                                                 UMPC_MEMORY_WRITE,              // Request
455                                                 buffer[i],                      // wValue
456                                                 (__u16)(i+start_address),       // wIndex
457                                                 NULL,                           // TransferBuffer
458                                                 0);                             // TransferBufferLength
459                 if (status)
460                         return status;
461         }
462
463         dbg ("%s - start_sddr = %x, length = %d", __FUNCTION__, start_address, length);
464         usb_serial_debug_data(debug, &serial->serial->dev->dev, __FUNCTION__, length, buffer);
465
466         return status;
467 }
468
469
470 /* Write edgeport I2C memory to TI chip */
471 static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address, int length, __u8 address_type, __u8 *buffer)
472 {
473         int status = 0;
474         int write_length;
475         __be16 be_start_address;
476
477         /* We can only send a maximum of 1 aligned byte page at a time */
478         
479         /* calulate the number of bytes left in the first page */
480         write_length = EPROM_PAGE_SIZE - (start_address & (EPROM_PAGE_SIZE - 1));
481
482         if (write_length > length)
483                 write_length = length;
484
485         dbg ("%s - BytesInFirstPage Addr = %x, length = %d", __FUNCTION__, start_address, write_length);
486         usb_serial_debug_data(debug, &serial->serial->dev->dev, __FUNCTION__, write_length, buffer);
487
488         /* Write first page */
489         be_start_address = cpu_to_be16 (start_address);
490         status = TISendVendorRequestSync (serial->serial->dev,
491                                         UMPC_MEMORY_WRITE,      // Request
492                                         (__u16)address_type,    // wValue
493                                         (__force __u16)be_start_address,        // wIndex
494                                         buffer,                 // TransferBuffer
495                                         write_length);
496         if (status) {
497                 dbg ("%s - ERROR %d", __FUNCTION__, status);
498                 return status;
499         }
500
501         length          -= write_length;
502         start_address   += write_length;
503         buffer          += write_length;
504
505         /* We should be aligned now -- can write max page size bytes at a time */
506         while (length) {
507                 if (length > EPROM_PAGE_SIZE)
508                         write_length = EPROM_PAGE_SIZE;
509                 else
510                         write_length = length;
511
512                 dbg ("%s - Page Write Addr = %x, length = %d", __FUNCTION__, start_address, write_length);
513                 usb_serial_debug_data(debug, &serial->serial->dev->dev, __FUNCTION__, write_length, buffer);
514
515                 /* Write next page */
516                 be_start_address = cpu_to_be16 (start_address);
517                 status = TISendVendorRequestSync (serial->serial->dev,
518                                                 UMPC_MEMORY_WRITE,      // Request
519                                                 (__u16)address_type,    // wValue
520                                                 (__force __u16)be_start_address,        // wIndex
521                                                 buffer,                 // TransferBuffer
522                                                 write_length);          // TransferBufferLength
523                 if (status) {
524                         dev_err (&serial->serial->dev->dev, "%s - ERROR %d\n", __FUNCTION__, status);
525                         return status;
526                 }
527                 
528                 length          -= write_length;
529                 start_address   += write_length;
530                 buffer          += write_length;
531         }
532         return status;
533 }
534
535 /* Examine the UMP DMA registers and LSR
536  * 
537  * Check the MSBit of the X and Y DMA byte count registers.
538  * A zero in this bit indicates that the TX DMA buffers are empty
539  * then check the TX Empty bit in the UART.
540  */
541 static int TIIsTxActive (struct edgeport_port *port)
542 {
543         int status;
544         struct out_endpoint_desc_block *oedb;
545         __u8 *lsr;
546         int bytes_left = 0;
547
548         oedb = kmalloc (sizeof (* oedb), GFP_KERNEL);
549         if (!oedb) {
550                 dev_err (&port->port->dev, "%s - out of memory\n", __FUNCTION__);
551                 return -ENOMEM;
552         }
553
554         lsr = kmalloc (1, GFP_KERNEL);  /* Sigh, that's right, just one byte,
555                                            as not all platforms can do DMA
556                                            from stack */
557         if (!lsr) {
558                 kfree(oedb);
559                 return -ENOMEM;
560         }
561         /* Read the DMA Count Registers */
562         status = TIReadRam (port->port->serial->dev,
563                             port->dma_address,
564                             sizeof( *oedb),
565                             (void *)oedb);
566
567         if (status)
568                 goto exit_is_tx_active;
569
570         dbg ("%s - XByteCount    0x%X", __FUNCTION__, oedb->XByteCount);
571
572         /* and the LSR */
573         status = TIReadRam (port->port->serial->dev, 
574                             port->uart_base + UMPMEM_OFFS_UART_LSR,
575                             1,
576                             lsr);
577
578         if (status)
579                 goto exit_is_tx_active;
580         dbg ("%s - LSR = 0x%X", __FUNCTION__, *lsr);
581         
582         /* If either buffer has data or we are transmitting then return TRUE */
583         if ((oedb->XByteCount & 0x80 ) != 0 )
584                 bytes_left += 64;
585
586         if ((*lsr & UMP_UART_LSR_TX_MASK ) == 0 )
587                 bytes_left += 1;
588
589         /* We return Not Active if we get any kind of error */
590 exit_is_tx_active:
591         dbg ("%s - return %d", __FUNCTION__, bytes_left );
592
593         kfree(lsr);
594         kfree(oedb);
595         return bytes_left;
596 }
597
598 static void TIChasePort(struct edgeport_port *port, unsigned long timeout, int flush)
599 {
600         int baud_rate;
601         struct tty_struct *tty = port->port->tty;
602         wait_queue_t wait;
603         unsigned long flags;
604
605         if (!timeout)
606                 timeout = (HZ*EDGE_CLOSING_WAIT)/100;
607
608         /* wait for data to drain from the buffer */
609         spin_lock_irqsave(&port->ep_lock, flags);
610         init_waitqueue_entry(&wait, current);
611         add_wait_queue(&tty->write_wait, &wait);
612         for (;;) {
613                 set_current_state(TASK_INTERRUPTIBLE);
614                 if (edge_buf_data_avail(port->ep_out_buf) == 0
615                 || timeout == 0 || signal_pending(current)
616                 || !usb_get_intfdata(port->port->serial->interface))  /* disconnect */
617                         break;
618                 spin_unlock_irqrestore(&port->ep_lock, flags);
619                 timeout = schedule_timeout(timeout);
620                 spin_lock_irqsave(&port->ep_lock, flags);
621         }
622         set_current_state(TASK_RUNNING);
623         remove_wait_queue(&tty->write_wait, &wait);
624         if (flush)
625                 edge_buf_clear(port->ep_out_buf);
626         spin_unlock_irqrestore(&port->ep_lock, flags);
627
628         /* wait for data to drain from the device */
629         timeout += jiffies;
630         while ((long)(jiffies - timeout) < 0 && !signal_pending(current)
631         && usb_get_intfdata(port->port->serial->interface)) {  /* not disconnected */
632                 if (!TIIsTxActive(port))
633                         break;
634                 msleep(10);
635         }
636
637         /* disconnected */
638         if (!usb_get_intfdata(port->port->serial->interface))
639                 return;
640
641         /* wait one more character time, based on baud rate */
642         /* (TIIsTxActive doesn't seem to wait for the last byte) */
643         if ((baud_rate=port->baud_rate) == 0)
644                 baud_rate = 50;
645         msleep(max(1,(10000+baud_rate-1)/baud_rate));
646 }
647
648 static int TIChooseConfiguration (struct usb_device *dev)
649 {
650         // There may be multiple configurations on this device, in which case
651         // we would need to read and parse all of them to find out which one
652         // we want. However, we just support one config at this point,
653         // configuration # 1, which is Config Descriptor 0.
654
655         dbg ("%s - Number of Interfaces = %d", __FUNCTION__, dev->config->desc.bNumInterfaces);
656         dbg ("%s - MAX Power            = %d", __FUNCTION__, dev->config->desc.bMaxPower*2);
657
658         if (dev->config->desc.bNumInterfaces != 1) {
659                 dev_err (&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", __FUNCTION__);
660                 return -ENODEV;
661         }
662
663         return 0;
664 }
665
666 static int TIReadRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer)
667 {
668         int status;
669
670         if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
671                 status = TIReadDownloadMemory (serial->serial->dev,
672                                                start_address,
673                                                length,
674                                                serial->TI_I2C_Type,
675                                                buffer);
676         } else {
677                 status = TIReadBootMemory (serial,
678                                            start_address,
679                                            length,
680                                            buffer);
681         }
682
683         return status;
684 }
685
686 static int TIWriteRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer)
687 {
688         if (serial->product_info.TiMode == TI_MODE_BOOT)
689                 return TIWriteBootMemory (serial,
690                                           start_address,
691                                           length,
692                                           buffer);
693
694         if (serial->product_info.TiMode == TI_MODE_DOWNLOAD)
695                 return TIWriteDownloadI2C (serial,
696                                            start_address,
697                                            length,
698                                            serial->TI_I2C_Type,
699                                            buffer);
700
701         return -EINVAL;
702 }
703
704
705
706 /* Read a descriptor header from I2C based on type */
707 static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type, struct ti_i2c_desc *rom_desc)
708 {
709         int start_address;
710         int status;
711
712         /* Search for requested descriptor in I2C */
713         start_address = 2;
714         do {
715                 status = TIReadRom (serial,
716                                    start_address,
717                                    sizeof(struct ti_i2c_desc),
718                                    (__u8 *)rom_desc );
719                 if (status)
720                         return 0;
721
722                 if (rom_desc->Type == desc_type)
723                         return start_address;
724
725                 start_address = start_address + sizeof(struct ti_i2c_desc) +  rom_desc->Size;
726
727         } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type);
728         
729         return 0;
730 }
731
732 /* Validate descriptor checksum */
733 static int ValidChecksum(struct ti_i2c_desc *rom_desc, __u8 *buffer)
734 {
735         __u16 i;
736         __u8 cs = 0;
737
738         for (i=0; i < rom_desc->Size; i++) {
739                 cs = (__u8)(cs + buffer[i]);
740         }
741         if (cs != rom_desc->CheckSum) {
742                 dbg ("%s - Mismatch %x - %x", __FUNCTION__, rom_desc->CheckSum, cs);
743                 return -EINVAL;
744         }
745         return 0;
746 }
747
748 /* Make sure that the I2C image is good */
749 static int TiValidateI2cImage (struct edgeport_serial *serial)
750 {
751         struct device *dev = &serial->serial->dev->dev;
752         int status = 0;
753         struct ti_i2c_desc *rom_desc;
754         int start_address = 2;
755         __u8 *buffer;
756         __u16 ttype;
757
758         rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
759         if (!rom_desc) {
760                 dev_err (dev, "%s - out of memory\n", __FUNCTION__);
761                 return -ENOMEM;
762         }
763         buffer = kmalloc (TI_MAX_I2C_SIZE, GFP_KERNEL);
764         if (!buffer) {
765                 dev_err (dev, "%s - out of memory when allocating buffer\n", __FUNCTION__);
766                 kfree (rom_desc);
767                 return -ENOMEM;
768         }
769
770         // Read the first byte (Signature0) must be 0x52 or 0x10
771         status = TIReadRom (serial, 0, 1, buffer);
772         if (status)
773                 goto ExitTiValidateI2cImage; 
774
775         if (*buffer != UMP5152 && *buffer != UMP3410) {
776                 dev_err (dev, "%s - invalid buffer signature\n", __FUNCTION__);
777                 status = -ENODEV;
778                 goto ExitTiValidateI2cImage;
779         }
780
781         do {
782                 // Validate the I2C
783                 status = TIReadRom (serial,
784                                 start_address,
785                                 sizeof(struct ti_i2c_desc),
786                                 (__u8 *)rom_desc);
787                 if (status)
788                         break;
789
790                 if ((start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size) > TI_MAX_I2C_SIZE) {
791                         status = -ENODEV;
792                         dbg ("%s - structure too big, erroring out.", __FUNCTION__);
793                         break;
794                 }
795
796                 dbg ("%s Type = 0x%x", __FUNCTION__, rom_desc->Type);
797
798                 // Skip type 2 record
799                 ttype = rom_desc->Type & 0x0f;
800                 if ( ttype != I2C_DESC_TYPE_FIRMWARE_BASIC
801                         && ttype != I2C_DESC_TYPE_FIRMWARE_AUTO ) {
802                         // Read the descriptor data
803                         status = TIReadRom(serial,
804                                                 start_address+sizeof(struct ti_i2c_desc),
805                                                 rom_desc->Size,
806                                                 buffer);
807                         if (status)
808                                 break;
809
810                         status = ValidChecksum(rom_desc, buffer);
811                         if (status)
812                                 break;
813                 }
814                 start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size;
815
816         } while ((rom_desc->Type != I2C_DESC_TYPE_ION) && (start_address < TI_MAX_I2C_SIZE));
817
818         if ((rom_desc->Type != I2C_DESC_TYPE_ION) || (start_address > TI_MAX_I2C_SIZE))
819                 status = -ENODEV;
820
821 ExitTiValidateI2cImage: 
822         kfree (buffer);
823         kfree (rom_desc);
824         return status;
825 }
826
827 static int TIReadManufDescriptor (struct edgeport_serial *serial, __u8 *buffer)
828 {
829         int status;
830         int start_address;
831         struct ti_i2c_desc *rom_desc;
832         struct edge_ti_manuf_descriptor *desc;
833
834         rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
835         if (!rom_desc) {
836                 dev_err (&serial->serial->dev->dev, "%s - out of memory\n", __FUNCTION__);
837                 return -ENOMEM;
838         }
839         start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_ION, rom_desc);
840
841         if (!start_address) {
842                 dbg ("%s - Edge Descriptor not found in I2C", __FUNCTION__);
843                 status = -ENODEV;
844                 goto exit;
845         }
846
847         // Read the descriptor data
848         status = TIReadRom (serial,
849                                 start_address+sizeof(struct ti_i2c_desc),
850                                 rom_desc->Size,
851                                 buffer);
852         if (status)
853                 goto exit;
854         
855         status = ValidChecksum(rom_desc, buffer);
856         
857         desc = (struct edge_ti_manuf_descriptor *)buffer;
858         dbg ( "%s - IonConfig      0x%x", __FUNCTION__, desc->IonConfig         );
859         dbg ( "%s - Version          %d", __FUNCTION__, desc->Version           );
860         dbg ( "%s - Cpu/Board      0x%x", __FUNCTION__, desc->CpuRev_BoardRev   );
861         dbg ( "%s - NumPorts         %d", __FUNCTION__, desc->NumPorts          );      
862         dbg ( "%s - NumVirtualPorts  %d", __FUNCTION__, desc->NumVirtualPorts   );      
863         dbg ( "%s - TotalPorts       %d", __FUNCTION__, desc->TotalPorts        );      
864
865 exit:
866         kfree (rom_desc);
867         return status;
868 }
869
870 /* Build firmware header used for firmware update */
871 static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
872 {
873         __u8 *buffer;
874         int buffer_size;
875         int i;
876         __u8 cs = 0;
877         struct ti_i2c_desc *i2c_header;
878         struct ti_i2c_image_header *img_header;
879         struct ti_i2c_firmware_rec *firmware_rec;
880
881         // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
882         // This will force the UMP to come up in Boot Mode.  Then while in boot mode, the driver 
883         // will download the latest firmware (padded to 15.5k) into the UMP ram. 
884         // And finally when the device comes back up in download mode the driver will cause 
885         // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
886         // the record type from 0xf2 to 0x02.
887         
888         // Allocate a 15.5k buffer + 2 bytes for version number (Firmware Record)
889         buffer_size = (((1024 * 16) - 512 )+ sizeof(struct ti_i2c_firmware_rec));
890
891         buffer = kmalloc (buffer_size, GFP_KERNEL);
892         if (!buffer) {
893                 dev_err (dev, "%s - out of memory\n", __FUNCTION__);
894                 return -ENOMEM;
895         }
896         
897         // Set entire image of 0xffs
898         memset (buffer, 0xff, buffer_size);
899
900         // Copy version number into firmware record
901         firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
902
903         firmware_rec->Ver_Major = OperationalCodeImageVersion.MajorVersion;
904         firmware_rec->Ver_Minor = OperationalCodeImageVersion.MinorVersion;
905
906         // Pointer to fw_down memory image
907         img_header = (struct ti_i2c_image_header *)&PagableOperationalCodeImage[0];
908
909         memcpy (buffer + sizeof(struct ti_i2c_firmware_rec),
910                 &PagableOperationalCodeImage[sizeof(struct ti_i2c_image_header)],
911                 le16_to_cpu(img_header->Length));
912
913         for (i=0; i < buffer_size; i++) {
914                 cs = (__u8)(cs + buffer[i]);
915         }
916
917         kfree (buffer);
918
919         // Build new header
920         i2c_header =  (struct ti_i2c_desc *)header;
921         firmware_rec =  (struct ti_i2c_firmware_rec*)i2c_header->Data;
922         
923         i2c_header->Type        = I2C_DESC_TYPE_FIRMWARE_BLANK;
924         i2c_header->Size        = (__u16)buffer_size;
925         i2c_header->CheckSum    = cs;
926         firmware_rec->Ver_Major = OperationalCodeImageVersion.MajorVersion;
927         firmware_rec->Ver_Minor = OperationalCodeImageVersion.MinorVersion;
928
929         return 0;
930 }
931
932 /* Try to figure out what type of I2c we have */
933 static int TIGetI2cTypeInBootMode (struct edgeport_serial *serial)
934 {
935         int status;
936         __u8 data;
937                 
938         // Try to read type 2
939         status = TIReadVendorRequestSync (serial->serial->dev,
940                                         UMPC_MEMORY_READ,               // Request
941                                         DTK_ADDR_SPACE_I2C_TYPE_II,     // wValue (Address type)
942                                         0,                              // wIndex
943                                         &data,                          // TransferBuffer
944                                         0x01);                          // TransferBufferLength
945         if (status)
946                 dbg ("%s - read 2 status error = %d", __FUNCTION__, status);
947         else
948                 dbg ("%s - read 2 data = 0x%x", __FUNCTION__, data);
949         if ((!status) && (data == UMP5152 || data == UMP3410)) {
950                 dbg ("%s - ROM_TYPE_II", __FUNCTION__);
951                 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
952                 return 0;
953         }
954
955         // Try to read type 3
956         status = TIReadVendorRequestSync (serial->serial->dev,
957                                         UMPC_MEMORY_READ,               // Request
958                                         DTK_ADDR_SPACE_I2C_TYPE_III,    // wValue (Address type)
959                                         0,                              // wIndex
960                                         &data,                          // TransferBuffer
961                                         0x01);                          // TransferBufferLength
962         if (status)
963                 dbg ("%s - read 3 status error = %d", __FUNCTION__, status);
964         else
965                 dbg ("%s - read 2 data = 0x%x", __FUNCTION__, data);
966         if ((!status) && (data == UMP5152 || data == UMP3410)) {
967                 dbg ("%s - ROM_TYPE_III", __FUNCTION__);
968                 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
969                 return 0;
970         }
971
972         dbg ("%s - Unknown", __FUNCTION__);
973         serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
974         return -ENODEV;
975 }
976
977 static int TISendBulkTransferSync (struct usb_serial *serial, void *buffer, int length, int *num_sent)
978 {
979         int status;
980
981         status = usb_bulk_msg (serial->dev,
982                                 usb_sndbulkpipe(serial->dev,
983                                                 serial->port[0]->bulk_out_endpointAddress),
984                                 buffer,
985                                 length,
986                                 num_sent,
987                                 1000);
988         return status;
989 }
990
991 /* Download given firmware image to the device (IN BOOT MODE) */
992 static int TIDownloadCodeImage (struct edgeport_serial *serial, __u8 *image, int image_length)
993 {
994         int status = 0;
995         int pos;
996         int transfer;
997         int done;
998
999         // Transfer firmware image
1000         for (pos = 0; pos < image_length; ) {
1001                 // Read the next buffer from file
1002                 transfer = image_length - pos;
1003                 if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE)
1004                         transfer = EDGE_FW_BULK_MAX_PACKET_SIZE;
1005
1006                 // Transfer data
1007                 status = TISendBulkTransferSync (serial->serial, &image[pos], transfer, &done);
1008                 if (status)
1009                         break;
1010                 // Advance buffer pointer
1011                 pos += done;
1012         }
1013
1014         return status;
1015 }
1016
1017 // FIXME!!!
1018 static int TIConfigureBootDevice (struct usb_device *dev)
1019 {
1020         return 0;
1021 }
1022
1023 /**
1024  * DownloadTIFirmware - Download run-time operating firmware to the TI5052
1025  * 
1026  * This routine downloads the main operating code into the TI5052, using the
1027  * boot code already burned into E2PROM or ROM.
1028  */
1029 static int TIDownloadFirmware (struct edgeport_serial *serial)
1030 {
1031         struct device *dev = &serial->serial->dev->dev;
1032         int status = 0;
1033         int start_address;
1034         struct edge_ti_manuf_descriptor *ti_manuf_desc;
1035         struct usb_interface_descriptor *interface;
1036         int download_cur_ver;
1037         int download_new_ver;
1038
1039         /* This routine is entered by both the BOOT mode and the Download mode
1040          * We can determine which code is running by the reading the config
1041          * descriptor and if we have only one bulk pipe it is in boot mode
1042          */
1043         serial->product_info.hardware_type = HARDWARE_TYPE_TIUMP;
1044
1045         /* Default to type 2 i2c */
1046         serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
1047
1048         status = TIChooseConfiguration (serial->serial->dev);
1049         if (status)
1050                 return status;
1051
1052         interface = &serial->serial->interface->cur_altsetting->desc;
1053         if (!interface) {
1054                 dev_err (dev, "%s - no interface set, error!\n", __FUNCTION__);
1055                 return -ENODEV;
1056         }
1057
1058         // Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
1059         // if we have more than one endpoint we are definitely in download mode
1060         if (interface->bNumEndpoints > 1)
1061                 serial->product_info.TiMode = TI_MODE_DOWNLOAD;
1062         else
1063                 // Otherwise we will remain in configuring mode
1064                 serial->product_info.TiMode = TI_MODE_CONFIGURING;
1065
1066         // Save Download Version Number
1067         OperationalCodeImageVersion.MajorVersion = PagableOperationalCodeImageVersion.MajorVersion;
1068         OperationalCodeImageVersion.MinorVersion = PagableOperationalCodeImageVersion.MinorVersion;
1069         OperationalCodeImageVersion.BuildNumber  = PagableOperationalCodeImageVersion.BuildNumber;
1070
1071         /********************************************************************/
1072         /* Download Mode */
1073         /********************************************************************/
1074         if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
1075                 struct ti_i2c_desc *rom_desc;
1076
1077                 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN DOWNLOAD MODE>>>>>>>>>>", __FUNCTION__);
1078
1079                 status = TiValidateI2cImage (serial);
1080                 if (status) {
1081                         dbg ("%s - <<<<<<<<<<<<<<<DOWNLOAD MODE -- BAD I2C >>>>>>>>>>",
1082                              __FUNCTION__);
1083                         return status;
1084                 }
1085                 
1086                 /* Validate Hardware version number
1087                  * Read Manufacturing Descriptor from TI Based Edgeport
1088                  */
1089                 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL);
1090                 if (!ti_manuf_desc) {
1091                         dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1092                         return -ENOMEM;
1093                 }
1094                 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc);
1095                 if (status) {
1096                         kfree (ti_manuf_desc);
1097                         return status;
1098                 }
1099
1100                 // Check version number of ION descriptor
1101                 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) {
1102                         dbg ( "%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__, 
1103                              TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev));
1104                         kfree (ti_manuf_desc);
1105                         return -EINVAL;
1106                 }
1107
1108                 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
1109                 if (!rom_desc) {
1110                         dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1111                         kfree (ti_manuf_desc);
1112                         return -ENOMEM;
1113                 }
1114
1115                 // Search for type 2 record (firmware record)
1116                 if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc)) != 0) {
1117                         struct ti_i2c_firmware_rec *firmware_version;
1118                         __u8 record;
1119
1120                         dbg ("%s - Found Type FIRMWARE (Type 2) record", __FUNCTION__);
1121
1122                         firmware_version = kmalloc (sizeof (*firmware_version), GFP_KERNEL);
1123                         if (!firmware_version) {
1124                                 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1125                                 kfree (rom_desc);
1126                                 kfree (ti_manuf_desc);
1127                                 return -ENOMEM;
1128                         }
1129
1130                         // Validate version number                              
1131                         // Read the descriptor data
1132                         status = TIReadRom (serial,
1133                                         start_address+sizeof(struct ti_i2c_desc),
1134                                         sizeof(struct ti_i2c_firmware_rec),
1135                                         (__u8 *)firmware_version);
1136                         if (status) {
1137                                 kfree (firmware_version);
1138                                 kfree (rom_desc);
1139                                 kfree (ti_manuf_desc);
1140                                 return status;
1141                         }
1142
1143                         // Check version number of download with current version in I2c
1144                         download_cur_ver = (firmware_version->Ver_Major << 8) + 
1145                                            (firmware_version->Ver_Minor);
1146                         download_new_ver = (OperationalCodeImageVersion.MajorVersion << 8) +
1147                                            (OperationalCodeImageVersion.MinorVersion);
1148
1149                         dbg ("%s - >>>Firmware Versions Device %d.%d  Driver %d.%d",
1150                              __FUNCTION__,
1151                              firmware_version->Ver_Major,
1152                              firmware_version->Ver_Minor,
1153                              OperationalCodeImageVersion.MajorVersion,
1154                              OperationalCodeImageVersion.MinorVersion);
1155
1156                         // Check if we have an old version in the I2C and update if necessary
1157                         if (download_cur_ver != download_new_ver) {
1158                                 dbg ("%s - Update I2C Download from %d.%d to %d.%d",
1159                                      __FUNCTION__,
1160                                      firmware_version->Ver_Major,
1161                                      firmware_version->Ver_Minor,
1162                                      OperationalCodeImageVersion.MajorVersion,
1163                                      OperationalCodeImageVersion.MinorVersion);
1164
1165                                 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1166                                 // This will force the UMP to come up in Boot Mode.  Then while in boot mode, the driver 
1167                                 // will download the latest firmware (padded to 15.5k) into the UMP ram. 
1168                                 // And finally when the device comes back up in download mode the driver will cause 
1169                                 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1170                                 // the record type from 0xf2 to 0x02.
1171
1172                                 record = I2C_DESC_TYPE_FIRMWARE_BLANK;
1173
1174                                 // Change the I2C Firmware record type to 0xf2 to trigger an update
1175                                 status = TIWriteRom (serial,
1176                                                         start_address,
1177                                                         sizeof(record),
1178                                                         &record);
1179                                 if (status) {
1180                                         kfree (firmware_version);
1181                                         kfree (rom_desc);
1182                                         kfree (ti_manuf_desc);
1183                                         return status;
1184                                 }
1185
1186                                 // verify the write -- must do this in order for write to 
1187                                 // complete before we do the hardware reset
1188                                 status = TIReadRom (serial,
1189                                                         start_address,
1190                                                         sizeof(record),
1191                                                         &record);
1192
1193                                 if (status) {
1194                                         kfree (firmware_version);
1195                                         kfree (rom_desc);
1196                                         kfree (ti_manuf_desc);
1197                                         return status;
1198                                 }
1199
1200                                 if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
1201                                         dev_err (dev, "%s - error resetting device\n", __FUNCTION__);
1202                                         kfree (firmware_version);
1203                                         kfree (rom_desc);
1204                                         kfree (ti_manuf_desc);
1205                                         return -ENODEV;
1206                                 }
1207
1208                                 dbg ("%s - HARDWARE RESET", __FUNCTION__);
1209
1210                                 // Reset UMP -- Back to BOOT MODE
1211                                 status = TISendVendorRequestSync (serial->serial->dev,
1212                                                                 UMPC_HARDWARE_RESET,    // Request
1213                                                                 0,                      // wValue
1214                                                                 0,                      // wIndex
1215                                                                 NULL,                   // TransferBuffer
1216                                                                 0);                     // TransferBufferLength
1217
1218                                 dbg ( "%s - HARDWARE RESET return %d", __FUNCTION__, status);
1219
1220                                 /* return an error on purpose. */
1221                                 kfree (firmware_version);
1222                                 kfree (rom_desc);
1223                                 kfree (ti_manuf_desc);
1224                                 return -ENODEV;
1225                         }
1226                         kfree (firmware_version);
1227                 }
1228                 // Search for type 0xF2 record (firmware blank record)
1229                 else if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) {
1230                         #define HEADER_SIZE     (sizeof(struct ti_i2c_desc) + sizeof(struct ti_i2c_firmware_rec))
1231                         __u8 *header;
1232                         __u8 *vheader;
1233
1234                         header  = kmalloc (HEADER_SIZE, GFP_KERNEL);
1235                         if (!header) {
1236                                 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1237                                 kfree (rom_desc);
1238                                 kfree (ti_manuf_desc);
1239                                 return -ENOMEM;
1240                         }
1241                                 
1242                         vheader = kmalloc (HEADER_SIZE, GFP_KERNEL);
1243                         if (!vheader) {
1244                                 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1245                                 kfree (header);
1246                                 kfree (rom_desc);
1247                                 kfree (ti_manuf_desc);
1248                                 return -ENOMEM;
1249                         }
1250                         
1251                         dbg ("%s - Found Type BLANK FIRMWARE (Type F2) record", __FUNCTION__);
1252
1253                         // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1254                         // This will force the UMP to come up in Boot Mode.  Then while in boot mode, the driver 
1255                         // will download the latest firmware (padded to 15.5k) into the UMP ram. 
1256                         // And finally when the device comes back up in download mode the driver will cause 
1257                         // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1258                         // the record type from 0xf2 to 0x02.
1259                         status = BuildI2CFirmwareHeader(header, dev);
1260                         if (status) {
1261                                 kfree (vheader);
1262                                 kfree (header);
1263                                 kfree (rom_desc);
1264                                 kfree (ti_manuf_desc);
1265                                 return status;
1266                         }
1267
1268                         // Update I2C with type 0xf2 record with correct size and checksum
1269                         status = TIWriteRom (serial,
1270                                                 start_address,
1271                                                 HEADER_SIZE,
1272                                                 header);
1273                         if (status) {
1274                                 kfree (vheader);
1275                                 kfree (header);
1276                                 kfree (rom_desc);
1277                                 kfree (ti_manuf_desc);
1278                                 return status;
1279                         }
1280
1281                         // verify the write -- must do this in order for write to 
1282                         // complete before we do the hardware reset
1283                         status = TIReadRom (serial,
1284                                                 start_address,
1285                                                 HEADER_SIZE,
1286                                                 vheader);
1287
1288                         if (status) {
1289                                 dbg ("%s - can't read header back", __FUNCTION__);
1290                                 kfree (vheader);
1291                                 kfree (header);
1292                                 kfree (rom_desc);
1293                                 kfree (ti_manuf_desc);
1294                                 return status;
1295                         }
1296                         if (memcmp(vheader, header, HEADER_SIZE)) {
1297                                 dbg ("%s - write download record failed", __FUNCTION__);
1298                                 kfree (vheader);
1299                                 kfree (header);
1300                                 kfree (rom_desc);
1301                                 kfree (ti_manuf_desc);
1302                                 return status;
1303                         }
1304
1305                         kfree (vheader);
1306                         kfree (header);
1307
1308                         dbg ("%s - Start firmware update", __FUNCTION__);
1309
1310                         // Tell firmware to copy download image into I2C 
1311                         status = TISendVendorRequestSync (serial->serial->dev,
1312                                                 UMPC_COPY_DNLD_TO_I2C,  // Request
1313                                                 0,                      // wValue 
1314                                                 0,                      // wIndex
1315                                                 NULL,                   // TransferBuffer
1316                                                 0);                     // TransferBufferLength
1317
1318                         dbg ("%s - Update complete 0x%x", __FUNCTION__, status);
1319                         if (status) {
1320                                 dev_err (dev, "%s - UMPC_COPY_DNLD_TO_I2C failed\n", __FUNCTION__);
1321                                 kfree (rom_desc);
1322                                 kfree (ti_manuf_desc);
1323                                 return status;
1324                         }
1325                 }
1326
1327                 // The device is running the download code
1328                 kfree (rom_desc);
1329                 kfree (ti_manuf_desc);
1330                 return 0;
1331         }
1332
1333         /********************************************************************/
1334         /* Boot Mode */
1335         /********************************************************************/
1336         dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN BOOT MODE>>>>>>>>>>>>>>>",
1337              __FUNCTION__);
1338
1339         // Configure the TI device so we can use the BULK pipes for download
1340         status = TIConfigureBootDevice (serial->serial->dev);
1341         if (status)
1342                 return status;
1343
1344         if (le16_to_cpu(serial->serial->dev->descriptor.idVendor) != USB_VENDOR_ID_ION) {
1345                 dbg ("%s - VID = 0x%x", __FUNCTION__,
1346                      le16_to_cpu(serial->serial->dev->descriptor.idVendor));
1347                 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
1348                 goto StayInBootMode;
1349         }
1350
1351         // We have an ION device (I2c Must be programmed)
1352         // Determine I2C image type
1353         if (TIGetI2cTypeInBootMode(serial)) {
1354                 goto StayInBootMode;
1355         }
1356
1357         // Registry variable set?
1358         if (TIStayInBootMode) {
1359                 dbg ("%s - TIStayInBootMode", __FUNCTION__);
1360                 goto StayInBootMode;
1361         }
1362
1363         // Check for ION Vendor ID and that the I2C is valid
1364         if (!TiValidateI2cImage(serial)) {
1365                 struct ti_i2c_image_header *header;
1366                 int i;
1367                 __u8 cs = 0;
1368                 __u8 *buffer;
1369                 int buffer_size;
1370
1371                 /* Validate Hardware version number
1372                  * Read Manufacturing Descriptor from TI Based Edgeport
1373                  */
1374                 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL);
1375                 if (!ti_manuf_desc) {
1376                         dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1377                         return -ENOMEM;
1378                 }
1379                 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc);
1380                 if (status) {
1381                         kfree (ti_manuf_desc);
1382                         goto StayInBootMode;
1383                 }
1384
1385                 // Check for version 2
1386                 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) {
1387                         dbg ("%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__,
1388                              TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev));
1389                         kfree (ti_manuf_desc);
1390                         goto StayInBootMode;
1391                 }
1392
1393                 kfree (ti_manuf_desc);
1394
1395                 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1396                 // This will force the UMP to come up in Boot Mode.  Then while in boot mode, the driver 
1397                 // will download the latest firmware (padded to 15.5k) into the UMP ram. 
1398                 // And finally when the device comes back up in download mode the driver will cause 
1399                 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1400                 // the record type from 0xf2 to 0x02.
1401                 
1402                 /*
1403                  * Do we really have to copy the whole firmware image,
1404                  * or could we do this in place!
1405                  */
1406
1407                 // Allocate a 15.5k buffer + 3 byte header
1408                 buffer_size = (((1024 * 16) - 512) + sizeof(struct ti_i2c_image_header));
1409                 buffer = kmalloc (buffer_size, GFP_KERNEL);
1410                 if (!buffer) {
1411                         dev_err (dev, "%s - out of memory\n", __FUNCTION__);
1412                         return -ENOMEM;
1413                 }
1414                 
1415                 // Initialize the buffer to 0xff (pad the buffer)
1416                 memset (buffer, 0xff, buffer_size);
1417
1418                 memcpy (buffer, &PagableOperationalCodeImage[0], PagableOperationalCodeSize);
1419
1420                 for(i = sizeof(struct ti_i2c_image_header); i < buffer_size; i++) {
1421                         cs = (__u8)(cs + buffer[i]);
1422                 }
1423                 
1424                 header = (struct ti_i2c_image_header *)buffer;
1425                 
1426                 // update length and checksum after padding
1427                 header->Length   = cpu_to_le16((__u16)(buffer_size - sizeof(struct ti_i2c_image_header)));
1428                 header->CheckSum = cs;
1429
1430                 // Download the operational code 
1431                 dbg ("%s - Downloading operational code image (TI UMP)", __FUNCTION__);
1432                 status = TIDownloadCodeImage (serial, buffer, buffer_size);
1433
1434                 kfree (buffer);
1435
1436                 if (status) {
1437                         dbg ("%s - Error downloading operational code image", __FUNCTION__);
1438                         return status;
1439                 }
1440
1441                 // Device will reboot
1442                 serial->product_info.TiMode = TI_MODE_TRANSITIONING;
1443
1444                 dbg ("%s - Download successful -- Device rebooting...", __FUNCTION__);
1445
1446                 /* return an error on purpose */
1447                 return -ENODEV;
1448         }
1449
1450 StayInBootMode:
1451         // Eprom is invalid or blank stay in boot mode
1452         dbg ("%s - <<<<<<<<<<<<<<<STAYING IN BOOT MODE>>>>>>>>>>>>", __FUNCTION__);
1453         serial->product_info.TiMode = TI_MODE_BOOT;
1454
1455         return 0;
1456 }
1457
1458
1459 static int TISetDtr (struct edgeport_port *port)
1460 {
1461         int port_number = port->port->number - port->port->serial->minor;
1462
1463         dbg ("%s", __FUNCTION__);
1464         port->shadow_mcr |= MCR_DTR;
1465
1466         return TIWriteCommandSync (port->port->serial->dev,
1467                                 UMPC_SET_CLR_DTR,
1468                                 (__u8)(UMPM_UART1_PORT + port_number),
1469                                 1,      /* set */
1470                                 NULL,
1471                                 0);
1472 }
1473
1474 static int TIClearDtr (struct edgeport_port *port)
1475 {
1476         int port_number = port->port->number - port->port->serial->minor;
1477
1478         dbg ("%s", __FUNCTION__);
1479         port->shadow_mcr &= ~MCR_DTR;
1480
1481         return TIWriteCommandSync (port->port->serial->dev,
1482                                 UMPC_SET_CLR_DTR,
1483                                 (__u8)(UMPM_UART1_PORT + port_number),
1484                                 0,      /* clear */
1485                                 NULL,
1486                                 0);
1487 }
1488
1489 static int TISetRts (struct edgeport_port *port)
1490 {
1491         int port_number = port->port->number - port->port->serial->minor;
1492
1493         dbg ("%s", __FUNCTION__);
1494         port->shadow_mcr |= MCR_RTS;
1495
1496         return TIWriteCommandSync (port->port->serial->dev,
1497                                 UMPC_SET_CLR_RTS,
1498                                 (__u8)(UMPM_UART1_PORT + port_number),
1499                                 1,      /* set */
1500                                 NULL,
1501                                 0);
1502 }
1503
1504 static int TIClearRts (struct edgeport_port *port)
1505 {
1506         int port_number = port->port->number - port->port->serial->minor;
1507
1508         dbg ("%s", __FUNCTION__);
1509         port->shadow_mcr &= ~MCR_RTS;
1510
1511         return TIWriteCommandSync (port->port->serial->dev,
1512                                 UMPC_SET_CLR_RTS,
1513                                 (__u8)(UMPM_UART1_PORT + port_number),
1514                                 0,      /* clear */
1515                                 NULL,
1516                                 0);
1517 }
1518
1519 static int TISetLoopBack (struct edgeport_port *port)
1520 {
1521         int port_number = port->port->number - port->port->serial->minor;
1522
1523         dbg ("%s", __FUNCTION__);
1524
1525         return TIWriteCommandSync (port->port->serial->dev,
1526                                 UMPC_SET_CLR_LOOPBACK,
1527                                 (__u8)(UMPM_UART1_PORT + port_number),
1528                                 1,      /* set */
1529                                 NULL,
1530                                 0);
1531 }
1532
1533 static int TIClearLoopBack (struct edgeport_port *port)
1534 {
1535         int port_number = port->port->number - port->port->serial->minor;
1536
1537         dbg ("%s", __FUNCTION__);
1538
1539         return TIWriteCommandSync (port->port->serial->dev,
1540                                 UMPC_SET_CLR_LOOPBACK,
1541                                 (__u8)(UMPM_UART1_PORT + port_number),
1542                                 0,      /* clear */
1543                                 NULL,
1544                                 0);
1545 }
1546
1547 static int TISetBreak (struct edgeport_port *port)
1548 {
1549         int port_number = port->port->number - port->port->serial->minor;
1550
1551         dbg ("%s", __FUNCTION__);
1552
1553         return TIWriteCommandSync (port->port->serial->dev,
1554                                 UMPC_SET_CLR_BREAK,
1555                                 (__u8)(UMPM_UART1_PORT + port_number),
1556                                 1,      /* set */
1557                                 NULL,
1558                                 0);
1559 }
1560
1561 static int TIClearBreak (struct edgeport_port *port)
1562 {
1563         int port_number = port->port->number - port->port->serial->minor;
1564
1565         dbg ("%s", __FUNCTION__);
1566
1567         return TIWriteCommandSync (port->port->serial->dev,
1568                                 UMPC_SET_CLR_BREAK,
1569                                 (__u8)(UMPM_UART1_PORT + port_number),
1570                                 0,      /* clear */
1571                                 NULL,
1572                                 0);
1573 }
1574
1575 static int TIRestoreMCR (struct edgeport_port *port, __u8 mcr)
1576 {
1577         int status = 0;
1578
1579         dbg ("%s - %x", __FUNCTION__, mcr);
1580
1581         if (mcr & MCR_DTR)
1582                 status = TISetDtr (port);
1583         else
1584                 status = TIClearDtr (port);
1585
1586         if (status)
1587                 return status;
1588
1589         if (mcr & MCR_RTS)
1590                 status = TISetRts (port);
1591         else
1592                 status = TIClearRts (port);
1593
1594         if (status)
1595                 return status;
1596
1597         if (mcr & MCR_LOOPBACK)
1598                 status = TISetLoopBack (port);
1599         else
1600                 status = TIClearLoopBack (port);
1601
1602         return status;
1603 }
1604
1605
1606
1607 /* Convert TI LSR to standard UART flags */
1608 static __u8 MapLineStatus (__u8 ti_lsr)
1609 {
1610         __u8 lsr = 0;
1611
1612 #define MAP_FLAG(flagUmp, flagUart)    \
1613         if (ti_lsr & flagUmp) \
1614                 lsr |= flagUart;
1615
1616         MAP_FLAG(UMP_UART_LSR_OV_MASK, LSR_OVER_ERR)    /* overrun */
1617         MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR)     /* parity error */
1618         MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR)     /* framing error */
1619         MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK)       /* break detected */
1620         MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL)    /* receive data available */
1621         MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY)    /* transmit holding register empty */
1622
1623 #undef MAP_FLAG
1624
1625         return lsr;
1626 }
1627
1628 static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr)
1629 {
1630         struct async_icount *icount;
1631         struct tty_struct *tty;
1632
1633         dbg ("%s - %02x", __FUNCTION__, msr);
1634
1635         if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
1636                 icount = &edge_port->icount;
1637
1638                 /* update input line counters */
1639                 if (msr & EDGEPORT_MSR_DELTA_CTS)
1640                         icount->cts++;
1641                 if (msr & EDGEPORT_MSR_DELTA_DSR)
1642                         icount->dsr++;
1643                 if (msr & EDGEPORT_MSR_DELTA_CD)
1644                         icount->dcd++;
1645                 if (msr & EDGEPORT_MSR_DELTA_RI)
1646                         icount->rng++;
1647                 wake_up_interruptible (&edge_port->delta_msr_wait);
1648         }
1649
1650         /* Save the new modem status */
1651         edge_port->shadow_msr = msr & 0xf0;
1652
1653         tty = edge_port->port->tty;
1654         /* handle CTS flow control */
1655         if (tty && C_CRTSCTS(tty)) {
1656                 if (msr & EDGEPORT_MSR_CTS) {
1657                         tty->hw_stopped = 0;
1658                         tty_wakeup(tty);
1659                 } else {
1660                         tty->hw_stopped = 1;
1661                 }
1662         }
1663
1664         return;
1665 }
1666
1667 static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8 lsr, __u8 data)
1668 {
1669         struct async_icount *icount;
1670         __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK));
1671
1672         dbg ("%s - %02x", __FUNCTION__, new_lsr);
1673
1674         edge_port->shadow_lsr = lsr;
1675
1676         if (new_lsr & LSR_BREAK) {
1677                 /*
1678                  * Parity and Framing errors only count if they
1679                  * occur exclusive of a break being received.
1680                  */
1681                 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
1682         }
1683
1684         /* Place LSR data byte into Rx buffer */
1685         if (lsr_data && edge_port->port->tty)
1686                 edge_tty_recv(&edge_port->port->dev, edge_port->port->tty, &data, 1);
1687
1688         /* update input line counters */
1689         icount = &edge_port->icount;
1690         if (new_lsr & LSR_BREAK)
1691                 icount->brk++;
1692         if (new_lsr & LSR_OVER_ERR)
1693                 icount->overrun++;
1694         if (new_lsr & LSR_PAR_ERR)
1695                 icount->parity++;
1696         if (new_lsr & LSR_FRM_ERR)
1697                 icount->frame++;
1698 }
1699
1700
1701 static void edge_interrupt_callback (struct urb *urb, struct pt_regs *regs)
1702 {
1703         struct edgeport_serial *edge_serial = (struct edgeport_serial *)urb->context;
1704         struct usb_serial_port *port;
1705         struct edgeport_port *edge_port;
1706         unsigned char *data = urb->transfer_buffer;
1707         int length = urb->actual_length;
1708         int port_number;
1709         int function;
1710         int status;
1711         __u8 lsr;
1712         __u8 msr;
1713
1714         dbg("%s", __FUNCTION__);
1715
1716         switch (urb->status) {
1717         case 0:
1718                 /* success */
1719                 break;
1720         case -ECONNRESET:
1721         case -ENOENT:
1722         case -ESHUTDOWN:
1723                 /* this urb is terminated, clean up */
1724                 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
1725                 return;
1726         default:
1727                 dev_err(&urb->dev->dev, "%s - nonzero urb status received: %d\n", __FUNCTION__, urb->status);
1728                 goto exit;
1729         }
1730
1731         if (!length) {
1732                 dbg ("%s - no data in urb", __FUNCTION__);
1733                 goto exit;
1734         }
1735                 
1736         usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __FUNCTION__, length, data);
1737                 
1738         if (length != 2) {
1739                 dbg ("%s - expecting packet of size 2, got %d", __FUNCTION__, length);
1740                 goto exit;
1741         }
1742
1743         port_number = TIUMP_GET_PORT_FROM_CODE (data[0]);
1744         function    = TIUMP_GET_FUNC_FROM_CODE (data[0]);
1745         dbg ("%s - port_number %d, function %d, info 0x%x",
1746              __FUNCTION__, port_number, function, data[1]);
1747         port = edge_serial->serial->port[port_number];
1748         edge_port = usb_get_serial_port_data(port);
1749         if (!edge_port) {
1750                 dbg ("%s - edge_port not found", __FUNCTION__);
1751                 return;
1752         }
1753         switch (function) {
1754         case TIUMP_INTERRUPT_CODE_LSR:
1755                 lsr = MapLineStatus(data[1]);
1756                 if (lsr & UMP_UART_LSR_DATA_MASK) {
1757                         /* Save the LSR event for bulk read completion routine */
1758                         dbg ("%s - LSR Event Port %u LSR Status = %02x",
1759                              __FUNCTION__, port_number, lsr);
1760                         edge_port->lsr_event = 1;
1761                         edge_port->lsr_mask = lsr;
1762                 } else {
1763                         dbg ("%s - ===== Port %d LSR Status = %02x ======",
1764                              __FUNCTION__, port_number, lsr);
1765                         handle_new_lsr (edge_port, 0, lsr, 0);
1766                 }
1767                 break;
1768
1769         case TIUMP_INTERRUPT_CODE_MSR:  // MSR
1770                 /* Copy MSR from UMP */
1771                 msr = data[1];
1772                 dbg ("%s - ===== Port %u MSR Status = %02x ======\n",
1773                      __FUNCTION__, port_number, msr);
1774                 handle_new_msr (edge_port, msr);
1775                 break;
1776
1777         default:
1778                 dev_err (&urb->dev->dev, "%s - Unknown Interrupt code from UMP %x\n",
1779                          __FUNCTION__, data[1]);
1780                 break;
1781                 
1782         }
1783
1784 exit:
1785         status = usb_submit_urb (urb, GFP_ATOMIC);
1786         if (status)
1787                 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
1788                          __FUNCTION__, status);
1789 }
1790
1791 static void edge_bulk_in_callback (struct urb *urb, struct pt_regs *regs)
1792 {
1793         struct edgeport_port *edge_port = (struct edgeport_port *)urb->context;
1794         unsigned char *data = urb->transfer_buffer;
1795         struct tty_struct *tty;
1796         int status = 0;
1797         int port_number;
1798
1799         dbg("%s", __FUNCTION__);
1800
1801         switch (urb->status) {
1802         case 0:
1803                 /* success */
1804                 break;
1805         case -ECONNRESET:
1806         case -ENOENT:
1807         case -ESHUTDOWN:
1808                 /* this urb is terminated, clean up */
1809                 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
1810                 return;
1811         default:
1812                 dev_err (&urb->dev->dev,"%s - nonzero read bulk status received: %d\n",
1813                      __FUNCTION__, urb->status );
1814         }
1815
1816         if (urb->status == -EPIPE)
1817                 goto exit;
1818
1819         if (urb->status) {
1820                 dev_err(&urb->dev->dev,"%s - stopping read!\n", __FUNCTION__);
1821                 return;
1822         }
1823
1824         port_number = edge_port->port->number - edge_port->port->serial->minor;
1825
1826         if (edge_port->lsr_event) {
1827                 edge_port->lsr_event = 0;
1828                 dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
1829                      __FUNCTION__, port_number, edge_port->lsr_mask, *data);
1830                 handle_new_lsr (edge_port, 1, edge_port->lsr_mask, *data);
1831                 /* Adjust buffer length/pointer */
1832                 --urb->actual_length;
1833                 ++data;
1834         }
1835
1836         tty = edge_port->port->tty;
1837         if (tty && urb->actual_length) {
1838                 usb_serial_debug_data(debug, &edge_port->port->dev, __FUNCTION__, urb->actual_length, data);
1839
1840                 if (edge_port->close_pending) {
1841                         dbg ("%s - close is pending, dropping data on the floor.", __FUNCTION__);
1842                 } else {
1843                         edge_tty_recv(&edge_port->port->dev, tty, data, urb->actual_length);
1844                 }
1845                 edge_port->icount.rx += urb->actual_length;
1846         }
1847
1848 exit:
1849         /* continue read unless stopped */
1850         spin_lock(&edge_port->ep_lock);
1851         if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING) {
1852                 urb->dev = edge_port->port->serial->dev;
1853                 status = usb_submit_urb(urb, GFP_ATOMIC);
1854         } else if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPING) {
1855                 edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPED;
1856         }
1857         spin_unlock(&edge_port->ep_lock);
1858         if (status)
1859                 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
1860                          __FUNCTION__, status);
1861 }
1862
1863 static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length)
1864 {
1865         int cnt;
1866
1867         do {
1868                 cnt = tty_buffer_request_room(tty, length);
1869                 if (cnt < length) {
1870                         dev_err(dev, "%s - dropping data, %d bytes lost\n",
1871                                 __FUNCTION__, length - cnt);
1872                         if(cnt == 0)
1873                                 break;
1874                 }
1875                 tty_insert_flip_string(tty, data, cnt);
1876                 data += cnt;
1877                 length -= cnt;
1878         } while (length > 0);
1879
1880         tty_flip_buffer_push(tty);
1881 }
1882
1883 static void edge_bulk_out_callback (struct urb *urb, struct pt_regs *regs)
1884 {
1885         struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1886         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1887
1888         dbg ("%s - port %d", __FUNCTION__, port->number);
1889
1890         edge_port->ep_write_urb_in_use = 0;
1891
1892         switch (urb->status) {
1893         case 0:
1894                 /* success */
1895                 break;
1896         case -ECONNRESET:
1897         case -ENOENT:
1898         case -ESHUTDOWN:
1899                 /* this urb is terminated, clean up */
1900                 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
1901                 return;
1902         default:
1903                 dev_err (&urb->dev->dev,"%s - nonzero write bulk status received: %d\n",
1904                      __FUNCTION__, urb->status);
1905         }
1906
1907         /* send any buffered data */
1908         edge_send(port);
1909 }
1910
1911 static int edge_open (struct usb_serial_port *port, struct file * filp)
1912 {
1913         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1914         struct edgeport_serial *edge_serial;
1915         struct usb_device *dev;
1916         struct urb *urb;
1917         int port_number;
1918         int status;
1919         u16 open_settings;
1920         u8 transaction_timeout;
1921
1922         dbg("%s - port %d", __FUNCTION__, port->number);
1923
1924         if (edge_port == NULL)
1925                 return -ENODEV;
1926
1927         if (port->tty)
1928                 port->tty->low_latency = low_latency;
1929
1930         port_number = port->number - port->serial->minor;
1931         switch (port_number) {
1932                 case 0:
1933                         edge_port->uart_base = UMPMEM_BASE_UART1;
1934                         edge_port->dma_address = UMPD_OEDB1_ADDRESS;
1935                         break;
1936                 case 1:
1937                         edge_port->uart_base = UMPMEM_BASE_UART2;
1938                         edge_port->dma_address = UMPD_OEDB2_ADDRESS;
1939                         break;
1940                 default:
1941                         dev_err (&port->dev, "Unknown port number!!!\n");
1942                         return -ENODEV;
1943         }
1944
1945         dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
1946              __FUNCTION__, port_number, edge_port->uart_base, edge_port->dma_address);
1947
1948         dev = port->serial->dev;
1949
1950         memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount));
1951         init_waitqueue_head (&edge_port->delta_msr_wait);
1952
1953         /* turn off loopback */
1954         status = TIClearLoopBack (edge_port);
1955         if (status) {
1956                 dev_err(&port->dev,"%s - cannot send clear loopback command, %d\n",
1957                         __FUNCTION__, status);
1958                 return status;
1959         }
1960         
1961         /* set up the port settings */
1962         edge_set_termios (port, NULL);
1963
1964         /* open up the port */
1965
1966         /* milliseconds to timeout for DMA transfer */
1967         transaction_timeout = 2;
1968
1969         edge_port->ump_read_timeout = max (20, ((transaction_timeout * 3) / 2) );
1970
1971         // milliseconds to timeout for DMA transfer
1972         open_settings = (u8)(UMP_DMA_MODE_CONTINOUS | 
1973                              UMP_PIPE_TRANS_TIMEOUT_ENA | 
1974                              (transaction_timeout << 2));
1975
1976         dbg ("%s - Sending UMPC_OPEN_PORT", __FUNCTION__);
1977
1978         /* Tell TI to open and start the port */
1979         status = TIWriteCommandSync (dev,
1980                                         UMPC_OPEN_PORT,
1981                                         (u8)(UMPM_UART1_PORT + port_number),
1982                                         open_settings,
1983                                         NULL,
1984                                         0);
1985         if (status) {
1986                 dev_err(&port->dev,"%s - cannot send open command, %d\n", __FUNCTION__, status);
1987                 return status;
1988         }
1989
1990         /* Start the DMA? */
1991         status = TIWriteCommandSync (dev,
1992                                         UMPC_START_PORT,
1993                                         (u8)(UMPM_UART1_PORT + port_number),
1994                                         0,
1995                                         NULL,
1996                                         0);
1997         if (status) {
1998                 dev_err(&port->dev,"%s - cannot send start DMA command, %d\n", __FUNCTION__, status);
1999                 return status;
2000         }
2001
2002         /* Clear TX and RX buffers in UMP */
2003         status = TIPurgeDataSync (port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
2004         if (status) {
2005                 dev_err(&port->dev,"%s - cannot send clear buffers command, %d\n", __FUNCTION__, status);
2006                 return status;
2007         }
2008
2009         /* Read Initial MSR */
2010         status = TIReadVendorRequestSync (dev,
2011                                         UMPC_READ_MSR,  // Request
2012                                         0,              // wValue
2013                                         (__u16)(UMPM_UART1_PORT + port_number), // wIndex (Address)
2014                                         &edge_port->shadow_msr,                 // TransferBuffer
2015                                         1);                                     // TransferBufferLength
2016         if (status) {
2017                 dev_err(&port->dev,"%s - cannot send read MSR command, %d\n", __FUNCTION__, status);
2018                 return status;
2019         }
2020
2021         dbg ("ShadowMSR 0x%X", edge_port->shadow_msr);
2022  
2023         /* Set Initial MCR */
2024         edge_port->shadow_mcr = MCR_RTS | MCR_DTR;
2025         dbg ("ShadowMCR 0x%X", edge_port->shadow_mcr);
2026
2027         edge_serial = edge_port->edge_serial;
2028         if (down_interruptible(&edge_serial->es_sem))
2029                 return -ERESTARTSYS;
2030         if (edge_serial->num_ports_open == 0) {
2031                 /* we are the first port to be opened, let's post the interrupt urb */
2032                 urb = edge_serial->serial->port[0]->interrupt_in_urb;
2033                 if (!urb) {
2034                         dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __FUNCTION__);
2035                         status = -EINVAL;
2036                         goto up_es_sem;
2037                 }
2038                 urb->complete = edge_interrupt_callback;
2039                 urb->context = edge_serial;
2040                 urb->dev = dev;
2041                 status = usb_submit_urb (urb, GFP_KERNEL);
2042                 if (status) {
2043                         dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__, status);
2044                         goto up_es_sem;
2045                 }
2046         }
2047
2048         /*
2049          * reset the data toggle on the bulk endpoints to work around bug in
2050          * host controllers where things get out of sync some times
2051          */
2052         usb_clear_halt (dev, port->write_urb->pipe);
2053         usb_clear_halt (dev, port->read_urb->pipe);
2054
2055         /* start up our bulk read urb */
2056         urb = port->read_urb;
2057         if (!urb) {
2058                 dev_err (&port->dev, "%s - no read urb present, exiting\n", __FUNCTION__);
2059                 status = -EINVAL;
2060                 goto unlink_int_urb;
2061         }
2062         edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING;
2063         urb->complete = edge_bulk_in_callback;
2064         urb->context = edge_port;
2065         urb->dev = dev;
2066         status = usb_submit_urb (urb, GFP_KERNEL);
2067         if (status) {
2068                 dev_err (&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __FUNCTION__, status);
2069                 goto unlink_int_urb;
2070         }
2071
2072         ++edge_serial->num_ports_open;
2073
2074         dbg("%s - exited", __FUNCTION__);
2075
2076         goto up_es_sem;
2077
2078 unlink_int_urb:
2079         if (edge_port->edge_serial->num_ports_open == 0)
2080                 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
2081 up_es_sem:
2082         up(&edge_serial->es_sem);
2083         return status;
2084 }
2085
2086 static void edge_close (struct usb_serial_port *port, struct file *filp)
2087 {
2088         struct edgeport_serial *edge_serial;
2089         struct edgeport_port *edge_port;
2090         int port_number;
2091         int status;
2092
2093         dbg("%s - port %d", __FUNCTION__, port->number);
2094                          
2095         edge_serial = usb_get_serial_data(port->serial);
2096         edge_port = usb_get_serial_port_data(port);
2097         if ((edge_serial == NULL) || (edge_port == NULL))
2098                 return;
2099         
2100         /* The bulkreadcompletion routine will check 
2101          * this flag and dump add read data */
2102         edge_port->close_pending = 1;
2103
2104         /* chase the port close and flush */
2105         TIChasePort (edge_port, (HZ*closing_wait)/100, 1);
2106
2107         usb_kill_urb(port->read_urb);
2108         usb_kill_urb(port->write_urb);
2109         edge_port->ep_write_urb_in_use = 0;
2110
2111         /* assuming we can still talk to the device,
2112          * send a close port command to it */
2113         dbg("%s - send umpc_close_port", __FUNCTION__);
2114         port_number = port->number - port->serial->minor;
2115         status = TIWriteCommandSync (port->serial->dev,
2116                                      UMPC_CLOSE_PORT,
2117                                      (__u8)(UMPM_UART1_PORT + port_number),
2118                                      0,
2119                                      NULL,
2120                                      0);
2121         down(&edge_serial->es_sem);
2122         --edge_port->edge_serial->num_ports_open;
2123         if (edge_port->edge_serial->num_ports_open <= 0) {
2124                 /* last port is now closed, let's shut down our interrupt urb */
2125                 usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
2126                 edge_port->edge_serial->num_ports_open = 0;
2127         }
2128         up(&edge_serial->es_sem);
2129         edge_port->close_pending = 0;
2130
2131         dbg("%s - exited", __FUNCTION__);
2132 }
2133
2134 static int edge_write (struct usb_serial_port *port, const unsigned char *data, int count)
2135 {
2136         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2137         unsigned long flags;
2138
2139         dbg("%s - port %d", __FUNCTION__, port->number);
2140
2141         if (count == 0) {
2142                 dbg("%s - write request of 0 bytes", __FUNCTION__);
2143                 return 0;
2144         }
2145
2146         if (edge_port == NULL)
2147                 return -ENODEV;
2148         if (edge_port->close_pending == 1)
2149                 return -ENODEV;
2150
2151         spin_lock_irqsave(&edge_port->ep_lock, flags);
2152         count = edge_buf_put(edge_port->ep_out_buf, data, count);
2153         spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2154
2155         edge_send(port);
2156
2157         return count;
2158 }
2159
2160 static void edge_send(struct usb_serial_port *port)
2161 {
2162         int count, result;
2163         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2164         struct tty_struct *tty = port->tty;
2165         unsigned long flags;
2166
2167
2168         dbg("%s - port %d", __FUNCTION__, port->number);
2169
2170         spin_lock_irqsave(&edge_port->ep_lock, flags);
2171
2172         if (edge_port->ep_write_urb_in_use) {
2173                 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2174                 return;
2175         }
2176
2177         count = edge_buf_get(edge_port->ep_out_buf,
2178                                 port->write_urb->transfer_buffer,
2179                                 port->bulk_out_size);
2180
2181         if (count == 0) {
2182                 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2183                 return;
2184         }
2185
2186         edge_port->ep_write_urb_in_use = 1;
2187
2188         spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2189
2190         usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, port->write_urb->transfer_buffer);
2191
2192         /* set up our urb */
2193         usb_fill_bulk_urb (port->write_urb, port->serial->dev,
2194                            usb_sndbulkpipe (port->serial->dev,
2195                                             port->bulk_out_endpointAddress),
2196                            port->write_urb->transfer_buffer, count,
2197                            edge_bulk_out_callback,
2198                            port);
2199
2200         /* send the data out the bulk port */
2201         result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
2202         if (result) {
2203                 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result);
2204                 edge_port->ep_write_urb_in_use = 0;
2205                 // TODO: reschedule edge_send
2206         } else {
2207                 edge_port->icount.tx += count;
2208         }
2209
2210         /* wakeup any process waiting for writes to complete */
2211         /* there is now more room in the buffer for new writes */
2212         if (tty) {
2213                 /* let the tty driver wakeup if it has a special write_wakeup function */
2214                 tty_wakeup(tty);
2215         }
2216 }
2217
2218 static int edge_write_room (struct usb_serial_port *port)
2219 {
2220         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2221         int room = 0;
2222         unsigned long flags;
2223
2224         dbg("%s - port %d", __FUNCTION__, port->number);
2225
2226         if (edge_port == NULL)
2227                 return -ENODEV;
2228         if (edge_port->close_pending == 1)
2229                 return -ENODEV;
2230
2231         spin_lock_irqsave(&edge_port->ep_lock, flags);
2232         room = edge_buf_space_avail(edge_port->ep_out_buf);
2233         spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2234
2235         dbg("%s - returns %d", __FUNCTION__, room);
2236         return room;
2237 }
2238
2239 static int edge_chars_in_buffer (struct usb_serial_port *port)
2240 {
2241         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2242         int chars = 0;
2243         unsigned long flags;
2244
2245         dbg("%s - port %d", __FUNCTION__, port->number);
2246
2247         if (edge_port == NULL)
2248                 return -ENODEV;
2249         if (edge_port->close_pending == 1)
2250                 return -ENODEV;
2251
2252         spin_lock_irqsave(&edge_port->ep_lock, flags);
2253         chars = edge_buf_data_avail(edge_port->ep_out_buf);
2254         spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2255
2256         dbg ("%s - returns %d", __FUNCTION__, chars);
2257         return chars;
2258 }
2259
2260 static void edge_throttle (struct usb_serial_port *port)
2261 {
2262         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2263         struct tty_struct *tty;
2264         int status;
2265
2266         dbg("%s - port %d", __FUNCTION__, port->number);
2267
2268         if (edge_port == NULL)
2269                 return;
2270
2271         tty = port->tty;
2272         if (!tty) {
2273                 dbg ("%s - no tty available", __FUNCTION__);
2274                 return;
2275         }
2276
2277         /* if we are implementing XON/XOFF, send the stop character */
2278         if (I_IXOFF(tty)) {
2279                 unsigned char stop_char = STOP_CHAR(tty);
2280                 status = edge_write (port, &stop_char, 1);
2281                 if (status <= 0) {
2282                         dev_err(&port->dev, "%s - failed to write stop character, %d\n", __FUNCTION__, status);
2283                 }
2284         }
2285
2286         /* if we are implementing RTS/CTS, stop reads */
2287         /* and the Edgeport will clear the RTS line */
2288         if (C_CRTSCTS(tty))
2289                 stop_read(edge_port);
2290
2291 }
2292
2293 static void edge_unthrottle (struct usb_serial_port *port)
2294 {
2295         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2296         struct tty_struct *tty;
2297         int status;
2298
2299         dbg("%s - port %d", __FUNCTION__, port->number);
2300
2301         if (edge_port == NULL)
2302                 return;
2303
2304         tty = port->tty;
2305         if (!tty) {
2306                 dbg ("%s - no tty available", __FUNCTION__);
2307                 return;
2308         }
2309
2310         /* if we are implementing XON/XOFF, send the start character */
2311         if (I_IXOFF(tty)) {
2312                 unsigned char start_char = START_CHAR(tty);
2313                 status = edge_write (port, &start_char, 1);
2314                 if (status <= 0) {
2315                         dev_err(&port->dev, "%s - failed to write start character, %d\n", __FUNCTION__, status);
2316                 }
2317         }
2318
2319         /* if we are implementing RTS/CTS, restart reads */
2320         /* are the Edgeport will assert the RTS line */
2321         if (C_CRTSCTS(tty)) {
2322                 status = restart_read(edge_port);
2323                 if (status)
2324                         dev_err(&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __FUNCTION__, status);
2325         }
2326
2327 }
2328
2329 static void stop_read(struct edgeport_port *edge_port)
2330 {
2331         unsigned long flags;
2332
2333         spin_lock_irqsave(&edge_port->ep_lock, flags);
2334
2335         if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING)
2336                 edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPING;
2337         edge_port->shadow_mcr &= ~MCR_RTS;
2338
2339         spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2340 }
2341
2342 static int restart_read(struct edgeport_port *edge_port)
2343 {
2344         struct urb *urb;
2345         int status = 0;
2346         unsigned long flags;
2347
2348         spin_lock_irqsave(&edge_port->ep_lock, flags);
2349
2350         if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPED) {
2351                 urb = edge_port->port->read_urb;
2352                 urb->complete = edge_bulk_in_callback;
2353                 urb->context = edge_port;
2354                 urb->dev = edge_port->port->serial->dev;
2355                 status = usb_submit_urb(urb, GFP_KERNEL);
2356         }
2357         edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING;
2358         edge_port->shadow_mcr |= MCR_RTS;
2359
2360         spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2361
2362         return status;
2363 }
2364
2365 static void change_port_settings (struct edgeport_port *edge_port, struct termios *old_termios)
2366 {
2367         struct ump_uart_config *config;
2368         struct tty_struct *tty;
2369         int baud;
2370         unsigned cflag;
2371         int status;
2372         int port_number = edge_port->port->number - edge_port->port->serial->minor;
2373
2374         dbg("%s - port %d", __FUNCTION__, edge_port->port->number);
2375
2376         tty = edge_port->port->tty;
2377         if ((!tty) ||
2378             (!tty->termios)) {
2379                 dbg("%s - no tty structures", __FUNCTION__);
2380                 return;
2381         }
2382
2383         config = kmalloc (sizeof (*config), GFP_KERNEL);
2384         if (!config) {
2385                 dev_err (&edge_port->port->dev, "%s - out of memory\n", __FUNCTION__);
2386                 return;
2387         }
2388
2389         cflag = tty->termios->c_cflag;
2390
2391         config->wFlags = 0;
2392
2393         /* These flags must be set */
2394         config->wFlags |= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT;
2395         config->wFlags |= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR;
2396         config->bUartMode = (__u8)(edge_port->bUartMode);
2397
2398         switch (cflag & CSIZE) {
2399                 case CS5:
2400                             config->bDataBits = UMP_UART_CHAR5BITS;
2401                             dbg ("%s - data bits = 5", __FUNCTION__);
2402                             break;
2403                 case CS6:
2404                             config->bDataBits = UMP_UART_CHAR6BITS;
2405                             dbg ("%s - data bits = 6", __FUNCTION__);
2406                             break;
2407                 case CS7:
2408                             config->bDataBits = UMP_UART_CHAR7BITS;
2409                             dbg ("%s - data bits = 7", __FUNCTION__);
2410                             break;
2411                 default:
2412                 case CS8:
2413                             config->bDataBits = UMP_UART_CHAR8BITS;
2414                             dbg ("%s - data bits = 8", __FUNCTION__);
2415                             break;
2416         }
2417
2418         if (cflag & PARENB) {
2419                 if (cflag & PARODD) {
2420                         config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2421                         config->bParity = UMP_UART_ODDPARITY;
2422                         dbg("%s - parity = odd", __FUNCTION__);
2423                 } else {
2424                         config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2425                         config->bParity = UMP_UART_EVENPARITY;
2426                         dbg("%s - parity = even", __FUNCTION__);
2427                 }
2428         } else {
2429                 config->bParity = UMP_UART_NOPARITY;    
2430                 dbg("%s - parity = none", __FUNCTION__);
2431         }
2432
2433         if (cflag & CSTOPB) {
2434                 config->bStopBits = UMP_UART_STOPBIT2;
2435                 dbg("%s - stop bits = 2", __FUNCTION__);
2436         } else {
2437                 config->bStopBits = UMP_UART_STOPBIT1;
2438                 dbg("%s - stop bits = 1", __FUNCTION__);
2439         }
2440
2441         /* figure out the flow control settings */
2442         if (cflag & CRTSCTS) {
2443                 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW;
2444                 config->wFlags |= UMP_MASK_UART_FLAGS_RTS_FLOW;
2445                 dbg("%s - RTS/CTS is enabled", __FUNCTION__);
2446         } else {
2447                 dbg("%s - RTS/CTS is disabled", __FUNCTION__);
2448                 tty->hw_stopped = 0;
2449                 restart_read(edge_port);
2450         }
2451
2452         /* if we are implementing XON/XOFF, set the start and stop character in the device */
2453         if (I_IXOFF(tty) || I_IXON(tty)) {
2454                 config->cXon  = START_CHAR(tty);
2455                 config->cXoff = STOP_CHAR(tty);
2456
2457                 /* if we are implementing INBOUND XON/XOFF */
2458                 if (I_IXOFF(tty)) {
2459                         config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
2460                         dbg ("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2461                              __FUNCTION__, config->cXon, config->cXoff);
2462                 } else {
2463                         dbg ("%s - INBOUND XON/XOFF is disabled", __FUNCTION__);
2464                 }
2465
2466                 /* if we are implementing OUTBOUND XON/XOFF */
2467                 if (I_IXON(tty)) {
2468                         config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
2469                         dbg ("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2470                              __FUNCTION__, config->cXon, config->cXoff);
2471                 } else {
2472                         dbg ("%s - OUTBOUND XON/XOFF is disabled", __FUNCTION__);
2473                 }
2474         }
2475
2476         /* Round the baud rate */
2477         baud = tty_get_baud_rate(tty);
2478         if (!baud) {
2479                 /* pick a default, any default... */
2480                 baud = 9600;
2481         }
2482         edge_port->baud_rate = baud;
2483         config->wBaudRate = (__u16)((461550L + baud/2) / baud);
2484
2485         dbg ("%s - baud rate = %d, wBaudRate = %d", __FUNCTION__, baud, config->wBaudRate);
2486
2487         dbg ("wBaudRate:   %d", (int)(461550L / config->wBaudRate));
2488         dbg ("wFlags:    0x%x", config->wFlags);
2489         dbg ("bDataBits:   %d", config->bDataBits);
2490         dbg ("bParity:     %d", config->bParity);
2491         dbg ("bStopBits:   %d", config->bStopBits);
2492         dbg ("cXon:        %d", config->cXon);
2493         dbg ("cXoff:       %d", config->cXoff);
2494         dbg ("bUartMode:   %d", config->bUartMode);
2495
2496         /* move the word values into big endian mode */
2497         cpu_to_be16s (&config->wFlags);
2498         cpu_to_be16s (&config->wBaudRate);
2499
2500         status = TIWriteCommandSync (edge_port->port->serial->dev,
2501                                 UMPC_SET_CONFIG,
2502                                 (__u8)(UMPM_UART1_PORT + port_number),
2503                                 0,
2504                                 (__u8 *)config,
2505                                 sizeof(*config));
2506         if (status) {
2507                 dbg ("%s - error %d when trying to write config to device",
2508                      __FUNCTION__, status);
2509         }
2510
2511         kfree (config);
2512         
2513         return;
2514 }
2515
2516 static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios)
2517 {
2518         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2519         struct tty_struct *tty = port->tty;
2520         unsigned int cflag;
2521
2522         if (!port->tty || !port->tty->termios) {
2523                 dbg ("%s - no tty or termios", __FUNCTION__);
2524                 return;
2525         }
2526
2527         cflag = tty->termios->c_cflag;
2528         /* check that they really want us to change something */
2529         if (old_termios) {
2530                 if (cflag == old_termios->c_cflag &&
2531                     tty->termios->c_iflag == old_termios->c_iflag) {
2532                         dbg ("%s - nothing to change", __FUNCTION__);
2533                         return;
2534                 }
2535         }
2536
2537         dbg("%s - clfag %08x iflag %08x", __FUNCTION__, 
2538             tty->termios->c_cflag, tty->termios->c_iflag);
2539         if (old_termios) {
2540                 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
2541                     old_termios->c_cflag, old_termios->c_iflag);
2542         }
2543
2544         dbg("%s - port %d", __FUNCTION__, port->number);
2545
2546         if (edge_port == NULL)
2547                 return;
2548
2549         /* change the port settings to the new ones specified */
2550         change_port_settings (edge_port, old_termios);
2551
2552         return;
2553 }
2554
2555 static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear)
2556 {
2557         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2558         unsigned int mcr;
2559
2560         dbg("%s - port %d", __FUNCTION__, port->number);
2561
2562         mcr = edge_port->shadow_mcr;
2563         if (set & TIOCM_RTS)
2564                 mcr |= MCR_RTS;
2565         if (set & TIOCM_DTR)
2566                 mcr |= MCR_DTR;
2567         if (set & TIOCM_LOOP)
2568                 mcr |= MCR_LOOPBACK;
2569
2570         if (clear & TIOCM_RTS)
2571                 mcr &= ~MCR_RTS;
2572         if (clear & TIOCM_DTR)
2573                 mcr &= ~MCR_DTR;
2574         if (clear & TIOCM_LOOP)
2575                 mcr &= ~MCR_LOOPBACK;
2576
2577         edge_port->shadow_mcr = mcr;
2578
2579         TIRestoreMCR (edge_port, mcr);
2580
2581         return 0;
2582 }
2583
2584 static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
2585 {
2586         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2587         unsigned int result = 0;
2588         unsigned int msr;
2589         unsigned int mcr;
2590
2591         dbg("%s - port %d", __FUNCTION__, port->number);
2592
2593         msr = edge_port->shadow_msr;
2594         mcr = edge_port->shadow_mcr;
2595         result = ((mcr & MCR_DTR)       ? TIOCM_DTR: 0)   /* 0x002 */
2596                   | ((mcr & MCR_RTS)    ? TIOCM_RTS: 0)   /* 0x004 */
2597                   | ((msr & EDGEPORT_MSR_CTS)   ? TIOCM_CTS: 0)   /* 0x020 */
2598                   | ((msr & EDGEPORT_MSR_CD)    ? TIOCM_CAR: 0)   /* 0x040 */
2599                   | ((msr & EDGEPORT_MSR_RI)    ? TIOCM_RI:  0)   /* 0x080 */
2600                   | ((msr & EDGEPORT_MSR_DSR)   ? TIOCM_DSR: 0);  /* 0x100 */
2601
2602
2603         dbg("%s -- %x", __FUNCTION__, result);
2604
2605         return result;
2606 }
2607
2608 static int get_serial_info (struct edgeport_port *edge_port, struct serial_struct __user *retinfo)
2609 {
2610         struct serial_struct tmp;
2611
2612         if (!retinfo)
2613                 return -EFAULT;
2614
2615         memset(&tmp, 0, sizeof(tmp));
2616
2617         tmp.type                = PORT_16550A;
2618         tmp.line                = edge_port->port->serial->minor;
2619         tmp.port                = edge_port->port->number;
2620         tmp.irq                 = 0;
2621         tmp.flags               = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2622         tmp.xmit_fifo_size      = edge_port->port->bulk_out_size;
2623         tmp.baud_base           = 9600;
2624         tmp.close_delay         = 5*HZ;
2625         tmp.closing_wait        = closing_wait;
2626 //      tmp.custom_divisor      = state->custom_divisor;
2627 //      tmp.hub6                = state->hub6;
2628 //      tmp.io_type             = state->io_type;
2629
2630
2631         if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2632                 return -EFAULT;
2633         return 0;
2634 }
2635
2636 static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg)
2637 {
2638         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2639         struct async_icount cnow;
2640         struct async_icount cprev;
2641
2642         dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd);
2643
2644         switch (cmd) {
2645                 case TIOCINQ:
2646                         dbg("%s - (%d) TIOCINQ", __FUNCTION__, port->number);
2647 //                      return get_number_bytes_avail(edge_port, (unsigned int *) arg);
2648                         break;
2649
2650                 case TIOCSERGETLSR:
2651                         dbg("%s - (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
2652 //                      return get_lsr_info(edge_port, (unsigned int *) arg);
2653                         break;
2654
2655                 case TIOCGSERIAL:
2656                         dbg("%s - (%d) TIOCGSERIAL", __FUNCTION__, port->number);
2657                         return get_serial_info(edge_port, (struct serial_struct __user *) arg);
2658                         break;
2659
2660                 case TIOCSSERIAL:
2661                         dbg("%s - (%d) TIOCSSERIAL", __FUNCTION__, port->number);
2662                         break;
2663
2664                 case TIOCMIWAIT:
2665                         dbg("%s - (%d) TIOCMIWAIT", __FUNCTION__, port->number);
2666                         cprev = edge_port->icount;
2667                         while (1) {
2668                                 interruptible_sleep_on(&edge_port->delta_msr_wait);
2669                                 /* see if a signal did it */
2670                                 if (signal_pending(current))
2671                                         return -ERESTARTSYS;
2672                                 cnow = edge_port->icount;
2673                                 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2674                                     cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2675                                         return -EIO; /* no change => error */
2676                                 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2677                                     ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2678                                     ((arg & TIOCM_CD)  && (cnow.dcd != cprev.dcd)) ||
2679                                     ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2680                                         return 0;
2681                                 }
2682                                 cprev = cnow;
2683                         }
2684                         /* not reached */
2685                         break;
2686
2687                 case TIOCGICOUNT:
2688                         dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__,
2689                              port->number, edge_port->icount.rx, edge_port->icount.tx);
2690                         if (copy_to_user((void __user *)arg, &edge_port->icount, sizeof(edge_port->icount)))
2691                                 return -EFAULT;
2692                         return 0;
2693         }
2694
2695         return -ENOIOCTLCMD;
2696 }
2697
2698 static void edge_break (struct usb_serial_port *port, int break_state)
2699 {
2700         struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2701         int status;
2702
2703         dbg ("%s - state = %d", __FUNCTION__, break_state);
2704
2705         /* chase the port close */
2706         TIChasePort (edge_port, 0, 0);
2707
2708         if (break_state == -1) {
2709                 status = TISetBreak (edge_port);
2710         } else {
2711                 status = TIClearBreak (edge_port);
2712         }
2713         if (status) {
2714                 dbg ("%s - error %d sending break set/clear command.",
2715                      __FUNCTION__, status);
2716         }
2717 }
2718
2719 static int edge_startup (struct usb_serial *serial)
2720 {
2721         struct edgeport_serial *edge_serial;
2722         struct edgeport_port *edge_port;
2723         struct usb_device *dev;
2724         int status;
2725         int i;
2726
2727         dev = serial->dev;
2728
2729         /* create our private serial structure */
2730         edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL);
2731         if (edge_serial == NULL) {
2732                 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2733                 return -ENOMEM;
2734         }
2735         sema_init(&edge_serial->es_sem, 1);
2736         edge_serial->serial = serial;
2737         usb_set_serial_data(serial, edge_serial);
2738
2739         status = TIDownloadFirmware (edge_serial);
2740         if (status) {
2741                 kfree (edge_serial);
2742                 return status;
2743         }
2744
2745         /* set up our port private structures */
2746         for (i = 0; i < serial->num_ports; ++i) {
2747                 edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL);
2748                 if (edge_port == NULL) {
2749                         dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2750                         goto cleanup;
2751                 }
2752                 spin_lock_init(&edge_port->ep_lock);
2753                 edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE);
2754                 if (edge_port->ep_out_buf == NULL) {
2755                         dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2756                         kfree(edge_port);
2757                         goto cleanup;
2758                 }
2759                 edge_port->port = serial->port[i];
2760                 edge_port->edge_serial = edge_serial;
2761                 usb_set_serial_port_data(serial->port[i], edge_port);
2762                 edge_port->bUartMode = 0;       /* Default is RS232 */
2763         }
2764         
2765         return 0;
2766
2767 cleanup:
2768         for (--i; i>=0; --i) {
2769                 edge_port = usb_get_serial_port_data(serial->port[i]);
2770                 edge_buf_free(edge_port->ep_out_buf);
2771                 kfree(edge_port);
2772                 usb_set_serial_port_data(serial->port[i], NULL);
2773         }
2774         kfree (edge_serial);
2775         usb_set_serial_data(serial, NULL);
2776         return -ENOMEM;
2777 }
2778
2779 static void edge_shutdown (struct usb_serial *serial)
2780 {
2781         int i;
2782         struct edgeport_port *edge_port;
2783
2784         dbg ("%s", __FUNCTION__);
2785
2786         for (i=0; i < serial->num_ports; ++i) {
2787                 edge_port = usb_get_serial_port_data(serial->port[i]);
2788                 if (edge_port) {
2789                         edge_buf_free(edge_port->ep_out_buf);
2790                         kfree(edge_port);
2791                 }
2792                 usb_set_serial_port_data(serial->port[i], NULL);
2793         }
2794         kfree (usb_get_serial_data(serial));
2795         usb_set_serial_data(serial, NULL);
2796 }
2797
2798
2799 /* Circular Buffer */
2800
2801 /*
2802  * edge_buf_alloc
2803  *
2804  * Allocate a circular buffer and all associated memory.
2805  */
2806
2807 static struct edge_buf *edge_buf_alloc(unsigned int size)
2808 {
2809         struct edge_buf *eb;
2810
2811
2812         if (size == 0)
2813                 return NULL;
2814
2815         eb = (struct edge_buf *)kmalloc(sizeof(struct edge_buf), GFP_KERNEL);
2816         if (eb == NULL)
2817                 return NULL;
2818
2819         eb->buf_buf = kmalloc(size, GFP_KERNEL);
2820         if (eb->buf_buf == NULL) {
2821                 kfree(eb);
2822                 return NULL;
2823         }
2824
2825         eb->buf_size = size;
2826         eb->buf_get = eb->buf_put = eb->buf_buf;
2827
2828         return eb;
2829 }
2830
2831
2832 /*
2833  * edge_buf_free
2834  *
2835  * Free the buffer and all associated memory.
2836  */
2837
2838 static void edge_buf_free(struct edge_buf *eb)
2839 {
2840         if (eb) {
2841                 kfree(eb->buf_buf);
2842                 kfree(eb);
2843         }
2844 }
2845
2846
2847 /*
2848  * edge_buf_clear
2849  *
2850  * Clear out all data in the circular buffer.
2851  */
2852
2853 static void edge_buf_clear(struct edge_buf *eb)
2854 {
2855         if (eb != NULL)
2856                 eb->buf_get = eb->buf_put;
2857                 /* equivalent to a get of all data available */
2858 }
2859
2860
2861 /*
2862  * edge_buf_data_avail
2863  *
2864  * Return the number of bytes of data available in the circular
2865  * buffer.
2866  */
2867
2868 static unsigned int edge_buf_data_avail(struct edge_buf *eb)
2869 {
2870         if (eb != NULL)
2871                 return ((eb->buf_size + eb->buf_put - eb->buf_get) % eb->buf_size);
2872         else
2873                 return 0;
2874 }
2875
2876
2877 /*
2878  * edge_buf_space_avail
2879  *
2880  * Return the number of bytes of space available in the circular
2881  * buffer.
2882  */
2883
2884 static unsigned int edge_buf_space_avail(struct edge_buf *eb)
2885 {
2886         if (eb != NULL)
2887                 return ((eb->buf_size + eb->buf_get - eb->buf_put - 1) % eb->buf_size);
2888         else
2889                 return 0;
2890 }
2891
2892
2893 /*
2894  * edge_buf_put
2895  *
2896  * Copy data data from a user buffer and put it into the circular buffer.
2897  * Restrict to the amount of space available.
2898  *
2899  * Return the number of bytes copied.
2900  */
2901
2902 static unsigned int edge_buf_put(struct edge_buf *eb, const char *buf,
2903         unsigned int count)
2904 {
2905         unsigned int len;
2906
2907
2908         if (eb == NULL)
2909                 return 0;
2910
2911         len  = edge_buf_space_avail(eb);
2912         if (count > len)
2913                 count = len;
2914
2915         if (count == 0)
2916                 return 0;
2917
2918         len = eb->buf_buf + eb->buf_size - eb->buf_put;
2919         if (count > len) {
2920                 memcpy(eb->buf_put, buf, len);
2921                 memcpy(eb->buf_buf, buf+len, count - len);
2922                 eb->buf_put = eb->buf_buf + count - len;
2923         } else {
2924                 memcpy(eb->buf_put, buf, count);
2925                 if (count < len)
2926                         eb->buf_put += count;
2927                 else /* count == len */
2928                         eb->buf_put = eb->buf_buf;
2929         }
2930
2931         return count;
2932 }
2933
2934
2935 /*
2936  * edge_buf_get
2937  *
2938  * Get data from the circular buffer and copy to the given buffer.
2939  * Restrict to the amount of data available.
2940  *
2941  * Return the number of bytes copied.
2942  */
2943
2944 static unsigned int edge_buf_get(struct edge_buf *eb, char *buf,
2945         unsigned int count)
2946 {
2947         unsigned int len;
2948
2949
2950         if (eb == NULL)
2951                 return 0;
2952
2953         len = edge_buf_data_avail(eb);
2954         if (count > len)
2955                 count = len;
2956
2957         if (count == 0)
2958                 return 0;
2959
2960         len = eb->buf_buf + eb->buf_size - eb->buf_get;
2961         if (count > len) {
2962                 memcpy(buf, eb->buf_get, len);
2963                 memcpy(buf+len, eb->buf_buf, count - len);
2964                 eb->buf_get = eb->buf_buf + count - len;
2965         } else {
2966                 memcpy(buf, eb->buf_get, count);
2967                 if (count < len)
2968                         eb->buf_get += count;
2969                 else /* count == len */
2970                         eb->buf_get = eb->buf_buf;
2971         }
2972
2973         return count;
2974 }
2975
2976
2977 static struct usb_serial_driver edgeport_1port_device = {
2978         .driver = {
2979                 .owner          = THIS_MODULE,
2980                 .name           = "edgeport_ti_1",
2981         },
2982         .description            = "Edgeport TI 1 port adapter",
2983         .id_table               = edgeport_1port_id_table,
2984         .num_interrupt_in       = 1,
2985         .num_bulk_in            = 1,
2986         .num_bulk_out           = 1,
2987         .num_ports              = 1,
2988         .open                   = edge_open,
2989         .close                  = edge_close,
2990         .throttle               = edge_throttle,
2991         .unthrottle             = edge_unthrottle,
2992         .attach                 = edge_startup,
2993         .shutdown               = edge_shutdown,
2994         .ioctl                  = edge_ioctl,
2995         .set_termios            = edge_set_termios,
2996         .tiocmget               = edge_tiocmget,
2997         .tiocmset               = edge_tiocmset,
2998         .write                  = edge_write,
2999         .write_room             = edge_write_room,
3000         .chars_in_buffer        = edge_chars_in_buffer,
3001         .break_ctl              = edge_break,
3002         .read_int_callback      = edge_interrupt_callback,
3003         .read_bulk_callback     = edge_bulk_in_callback,
3004         .write_bulk_callback    = edge_bulk_out_callback,
3005 };
3006
3007 static struct usb_serial_driver edgeport_2port_device = {
3008         .driver = {
3009                 .owner          = THIS_MODULE,
3010                 .name           = "edgeport_ti_2",
3011         },
3012         .description            = "Edgeport TI 2 port adapter",
3013         .id_table               = edgeport_2port_id_table,
3014         .num_interrupt_in       = 1,
3015         .num_bulk_in            = 2,
3016         .num_bulk_out           = 2,
3017         .num_ports              = 2,
3018         .open                   = edge_open,
3019         .close                  = edge_close,
3020         .throttle               = edge_throttle,
3021         .unthrottle             = edge_unthrottle,
3022         .attach                 = edge_startup,
3023         .shutdown               = edge_shutdown,
3024         .ioctl                  = edge_ioctl,
3025         .set_termios            = edge_set_termios,
3026         .tiocmget               = edge_tiocmget,
3027         .tiocmset               = edge_tiocmset,
3028         .write                  = edge_write,
3029         .write_room             = edge_write_room,
3030         .chars_in_buffer        = edge_chars_in_buffer,
3031         .break_ctl              = edge_break,
3032         .read_int_callback      = edge_interrupt_callback,
3033         .read_bulk_callback     = edge_bulk_in_callback,
3034         .write_bulk_callback    = edge_bulk_out_callback,
3035 };
3036
3037
3038 static int __init edgeport_init(void)
3039 {
3040         int retval;
3041         retval = usb_serial_register(&edgeport_1port_device);
3042         if (retval)
3043                 goto failed_1port_device_register;
3044         retval = usb_serial_register(&edgeport_2port_device);
3045         if (retval)
3046                 goto failed_2port_device_register;
3047         retval = usb_register(&io_driver);
3048         if (retval) 
3049                 goto failed_usb_register;
3050         info(DRIVER_DESC " " DRIVER_VERSION);
3051         return 0;
3052 failed_usb_register:
3053         usb_serial_deregister(&edgeport_2port_device);
3054 failed_2port_device_register:
3055         usb_serial_deregister(&edgeport_1port_device);
3056 failed_1port_device_register:
3057         return retval;
3058 }
3059
3060 static void __exit edgeport_exit (void)
3061 {
3062         usb_deregister (&io_driver);
3063         usb_serial_deregister (&edgeport_1port_device);
3064         usb_serial_deregister (&edgeport_2port_device);
3065 }
3066
3067 module_init(edgeport_init);
3068 module_exit(edgeport_exit);
3069
3070 /* Module information */
3071 MODULE_AUTHOR(DRIVER_AUTHOR);
3072 MODULE_DESCRIPTION(DRIVER_DESC);
3073 MODULE_LICENSE("GPL");
3074
3075 module_param(debug, bool, S_IRUGO | S_IWUSR);
3076 MODULE_PARM_DESC(debug, "Debug enabled or not");
3077
3078 module_param(low_latency, bool, S_IRUGO | S_IWUSR);
3079 MODULE_PARM_DESC(low_latency, "Low latency enabled or not");
3080
3081 module_param(closing_wait, int, S_IRUGO | S_IWUSR);
3082 MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs");
3083
3084 module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR);
3085 MODULE_PARM_DESC(ignore_cpu_rev, "Ignore the cpu revision when connecting to a device");
3086