2 * Edgeport USB Serial Converter driver
4 * Copyright (C) 2000-2002 Inside Out Networks, All rights reserved.
5 * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
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.
12 * Supports the following devices:
13 * EP/1 EP/2 EP/4 EP/21 EP/22 EP/221 EP/42 EP/421 WATCHPORT
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>.
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)
27 #include <linux/kernel.h>
28 #include <linux/jiffies.h>
29 #include <linux/errno.h>
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/tty.h>
33 #include <linux/tty_driver.h>
34 #include <linux/tty_flip.h>
35 #include <linux/module.h>
36 #include <linux/spinlock.h>
37 #include <linux/mutex.h>
38 #include <linux/serial.h>
39 #include <linux/ioctl.h>
40 #include <linux/firmware.h>
41 #include <linux/uaccess.h>
42 #include <linux/usb.h>
43 #include <linux/usb/serial.h>
46 #include "io_usbvend.h"
52 #define DRIVER_VERSION "v0.7mode043006"
53 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
54 #define DRIVER_DESC "Edgeport USB Serial Driver"
56 #define EPROM_PAGE_SIZE 64
59 /* different hardware types */
60 #define HARDWARE_TYPE_930 0
61 #define HARDWARE_TYPE_TIUMP 1
63 /* IOCTL_PRIVATE_TI_GET_MODE Definitions */
64 #define TI_MODE_CONFIGURING 0 /* Device has not entered start device */
65 #define TI_MODE_BOOT 1 /* Staying in boot mode */
66 #define TI_MODE_DOWNLOAD 2 /* Made it to download mode */
67 #define TI_MODE_TRANSITIONING 3 /* Currently in boot mode but
68 transitioning to download mode */
71 #define EDGE_READ_URB_RUNNING 0
72 #define EDGE_READ_URB_STOPPING 1
73 #define EDGE_READ_URB_STOPPED 2
75 #define EDGE_CLOSING_WAIT 4000 /* in .01 sec */
77 #define EDGE_OUT_BUF_SIZE 1024
80 /* Product information read from the Edgeport */
82 int TiMode
; /* Current TI Mode */
83 __u8 hardware_type
; /* Type of hardware */
84 } __attribute__((packed
));
88 unsigned int buf_size
;
94 struct edgeport_port
{
101 __u32 ump_read_timeout
; /* Number of milliseconds the UMP will
102 wait without data before completing
107 struct async_icount icount
;
108 wait_queue_head_t delta_msr_wait
; /* for handling sleeping while
109 waiting for msr change to
111 struct edgeport_serial
*edge_serial
;
112 struct usb_serial_port
*port
;
113 __u8 bUartMode
; /* Port type, 0: RS232, etc. */
115 int ep_read_urb_state
;
116 int ep_write_urb_in_use
;
117 struct edge_buf
*ep_out_buf
;
120 struct edgeport_serial
{
121 struct product_info product_info
;
122 u8 TI_I2C_Type
; /* Type of I2C in UMP */
123 u8 TiReadI2C
; /* Set to TRUE if we have read the
125 struct mutex es_lock
;
127 struct usb_serial
*serial
;
131 /* Devices that this driver supports */
132 static const struct usb_device_id edgeport_1port_id_table
[] = {
133 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_1
) },
134 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1
) },
135 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I
) },
136 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_PROXIMITY
) },
137 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_MOTION
) },
138 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_MOISTURE
) },
139 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_TEMPERATURE
) },
140 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_HUMIDITY
) },
141 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_POWER
) },
142 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_LIGHT
) },
143 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_RADIATION
) },
144 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_DISTANCE
) },
145 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_ACCELERATION
) },
146 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_PROX_DIST
) },
147 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_PLUS_PWR_HP4CD
) },
148 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_PLUS_PWR_PCI
) },
152 static const struct usb_device_id edgeport_2port_id_table
[] = {
153 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2
) },
154 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2C
) },
155 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2I
) },
156 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_421
) },
157 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21
) },
158 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_42
) },
159 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4
) },
160 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4I
) },
161 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22I
) },
162 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_221C
) },
163 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22C
) },
164 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21C
) },
165 /* The 4, 8 and 16 port devices show up as multiple 2 port devices */
166 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4S
) },
167 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_8
) },
168 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_8S
) },
169 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_416
) },
170 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_416B
) },
174 /* Devices that this driver supports */
175 static const struct usb_device_id id_table_combined
[] = {
176 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_1
) },
177 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1
) },
178 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I
) },
179 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_PROXIMITY
) },
180 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_MOTION
) },
181 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_MOISTURE
) },
182 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_TEMPERATURE
) },
183 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_HUMIDITY
) },
184 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_POWER
) },
185 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_LIGHT
) },
186 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_RADIATION
) },
187 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_DISTANCE
) },
188 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_ACCELERATION
) },
189 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_PROX_DIST
) },
190 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_PLUS_PWR_HP4CD
) },
191 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_PLUS_PWR_PCI
) },
192 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2
) },
193 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2C
) },
194 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2I
) },
195 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_421
) },
196 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21
) },
197 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_42
) },
198 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4
) },
199 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4I
) },
200 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22I
) },
201 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_221C
) },
202 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22C
) },
203 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21C
) },
204 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4S
) },
205 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_8
) },
206 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_8S
) },
207 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_416
) },
208 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_416B
) },
212 MODULE_DEVICE_TABLE(usb
, id_table_combined
);
214 static struct usb_driver io_driver
= {
216 .probe
= usb_serial_probe
,
217 .disconnect
= usb_serial_disconnect
,
218 .id_table
= id_table_combined
,
223 static unsigned char OperationalMajorVersion
;
224 static unsigned char OperationalMinorVersion
;
225 static unsigned short OperationalBuildNumber
;
229 static int closing_wait
= EDGE_CLOSING_WAIT
;
230 static int ignore_cpu_rev
;
231 static int default_uart_mode
; /* RS232 */
233 static void edge_tty_recv(struct device
*dev
, struct tty_struct
*tty
,
234 unsigned char *data
, int length
);
236 static void stop_read(struct edgeport_port
*edge_port
);
237 static int restart_read(struct edgeport_port
*edge_port
);
239 static void edge_set_termios(struct tty_struct
*tty
,
240 struct usb_serial_port
*port
, struct ktermios
*old_termios
);
241 static void edge_send(struct tty_struct
*tty
);
243 /* sysfs attributes */
244 static int edge_create_sysfs_attrs(struct usb_serial_port
*port
);
245 static int edge_remove_sysfs_attrs(struct usb_serial_port
*port
);
247 /* circular buffer */
248 static struct edge_buf
*edge_buf_alloc(unsigned int size
);
249 static void edge_buf_free(struct edge_buf
*eb
);
250 static void edge_buf_clear(struct edge_buf
*eb
);
251 static unsigned int edge_buf_data_avail(struct edge_buf
*eb
);
252 static unsigned int edge_buf_space_avail(struct edge_buf
*eb
);
253 static unsigned int edge_buf_put(struct edge_buf
*eb
, const char *buf
,
255 static unsigned int edge_buf_get(struct edge_buf
*eb
, char *buf
,
259 static int ti_vread_sync(struct usb_device
*dev
, __u8 request
,
260 __u16 value
, __u16 index
, u8
*data
, int size
)
264 status
= usb_control_msg(dev
, usb_rcvctrlpipe(dev
, 0), request
,
265 (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
),
266 value
, index
, data
, size
, 1000);
269 if (status
!= size
) {
270 dbg("%s - wanted to write %d, but only wrote %d",
271 __func__
, size
, status
);
277 static int ti_vsend_sync(struct usb_device
*dev
, __u8 request
,
278 __u16 value
, __u16 index
, u8
*data
, int size
)
282 status
= usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0), request
,
283 (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
),
284 value
, index
, data
, size
, 1000);
287 if (status
!= size
) {
288 dbg("%s - wanted to write %d, but only wrote %d",
289 __func__
, size
, status
);
295 static int send_cmd(struct usb_device
*dev
, __u8 command
,
296 __u8 moduleid
, __u16 value
, u8
*data
,
299 return ti_vsend_sync(dev
, command
, value
, moduleid
, data
, size
);
302 /* clear tx/rx buffers and fifo in TI UMP */
303 static int purge_port(struct usb_serial_port
*port
, __u16 mask
)
305 int port_number
= port
->number
- port
->serial
->minor
;
307 dbg("%s - port %d, mask %x", __func__
, port_number
, mask
);
309 return send_cmd(port
->serial
->dev
,
311 (__u8
)(UMPM_UART1_PORT
+ port_number
),
318 * read_download_mem - Read edgeport memory from TI chip
319 * @dev: usb device pointer
320 * @start_address: Device CPU address at which to read
321 * @length: Length of above data
322 * @address_type: Can read both XDATA and I2C
323 * @buffer: pointer to input data buffer
325 static int read_download_mem(struct usb_device
*dev
, int start_address
,
326 int length
, __u8 address_type
, __u8
*buffer
)
330 __be16 be_start_address
;
332 dbg("%s - @ %x for %d", __func__
, start_address
, length
);
334 /* Read in blocks of 64 bytes
335 * (TI firmware can't handle more than 64 byte reads)
341 read_length
= (__u8
)length
;
343 if (read_length
> 1) {
344 dbg("%s - @ %x for %d", __func__
,
345 start_address
, read_length
);
347 be_start_address
= cpu_to_be16(start_address
);
348 status
= ti_vread_sync(dev
, UMPC_MEMORY_READ
,
350 (__force __u16
)be_start_address
,
351 buffer
, read_length
);
354 dbg("%s - ERROR %x", __func__
, status
);
359 usb_serial_debug_data(debug
, &dev
->dev
, __func__
,
360 read_length
, buffer
);
362 /* Update pointers/length */
363 start_address
+= read_length
;
364 buffer
+= read_length
;
365 length
-= read_length
;
371 static int read_ram(struct usb_device
*dev
, int start_address
,
372 int length
, __u8
*buffer
)
374 return read_download_mem(dev
, start_address
, length
,
375 DTK_ADDR_SPACE_XDATA
, buffer
);
378 /* Read edgeport memory to a given block */
379 static int read_boot_mem(struct edgeport_serial
*serial
,
380 int start_address
, int length
, __u8
*buffer
)
385 for (i
= 0; i
< length
; i
++) {
386 status
= ti_vread_sync(serial
->serial
->dev
,
387 UMPC_MEMORY_READ
, serial
->TI_I2C_Type
,
388 (__u16
)(start_address
+i
), &buffer
[i
], 0x01);
390 dbg("%s - ERROR %x", __func__
, status
);
395 dbg("%s - start_address = %x, length = %d",
396 __func__
, start_address
, length
);
397 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
,
398 __func__
, length
, buffer
);
400 serial
->TiReadI2C
= 1;
405 /* Write given block to TI EPROM memory */
406 static int write_boot_mem(struct edgeport_serial
*serial
,
407 int start_address
, int length
, __u8
*buffer
)
413 /* Must do a read before write */
414 if (!serial
->TiReadI2C
) {
415 temp
= kmalloc(1, GFP_KERNEL
);
417 dev_err(&serial
->serial
->dev
->dev
,
418 "%s - out of memory\n", __func__
);
421 status
= read_boot_mem(serial
, 0, 1, temp
);
427 for (i
= 0; i
< length
; ++i
) {
428 status
= ti_vsend_sync(serial
->serial
->dev
,
429 UMPC_MEMORY_WRITE
, buffer
[i
],
430 (__u16
)(i
+ start_address
), NULL
, 0);
435 dbg("%s - start_sddr = %x, length = %d",
436 __func__
, start_address
, length
);
437 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
,
438 __func__
, length
, buffer
);
444 /* Write edgeport I2C memory to TI chip */
445 static int write_i2c_mem(struct edgeport_serial
*serial
,
446 int start_address
, int length
, __u8 address_type
, __u8
*buffer
)
450 __be16 be_start_address
;
452 /* We can only send a maximum of 1 aligned byte page at a time */
454 /* calulate the number of bytes left in the first page */
455 write_length
= EPROM_PAGE_SIZE
-
456 (start_address
& (EPROM_PAGE_SIZE
- 1));
458 if (write_length
> length
)
459 write_length
= length
;
461 dbg("%s - BytesInFirstPage Addr = %x, length = %d",
462 __func__
, start_address
, write_length
);
463 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
,
464 __func__
, write_length
, buffer
);
466 /* Write first page */
467 be_start_address
= cpu_to_be16(start_address
);
468 status
= ti_vsend_sync(serial
->serial
->dev
,
469 UMPC_MEMORY_WRITE
, (__u16
)address_type
,
470 (__force __u16
)be_start_address
,
471 buffer
, write_length
);
473 dbg("%s - ERROR %d", __func__
, status
);
477 length
-= write_length
;
478 start_address
+= write_length
;
479 buffer
+= write_length
;
481 /* We should be aligned now -- can write
482 max page size bytes at a time */
484 if (length
> EPROM_PAGE_SIZE
)
485 write_length
= EPROM_PAGE_SIZE
;
487 write_length
= length
;
489 dbg("%s - Page Write Addr = %x, length = %d",
490 __func__
, start_address
, write_length
);
491 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
,
492 __func__
, write_length
, buffer
);
494 /* Write next page */
495 be_start_address
= cpu_to_be16(start_address
);
496 status
= ti_vsend_sync(serial
->serial
->dev
, UMPC_MEMORY_WRITE
,
498 (__force __u16
)be_start_address
,
499 buffer
, write_length
);
501 dev_err(&serial
->serial
->dev
->dev
, "%s - ERROR %d\n",
506 length
-= write_length
;
507 start_address
+= write_length
;
508 buffer
+= write_length
;
513 /* Examine the UMP DMA registers and LSR
515 * Check the MSBit of the X and Y DMA byte count registers.
516 * A zero in this bit indicates that the TX DMA buffers are empty
517 * then check the TX Empty bit in the UART.
519 static int tx_active(struct edgeport_port
*port
)
522 struct out_endpoint_desc_block
*oedb
;
526 oedb
= kmalloc(sizeof(*oedb
), GFP_KERNEL
);
528 dev_err(&port
->port
->dev
, "%s - out of memory\n", __func__
);
532 lsr
= kmalloc(1, GFP_KERNEL
); /* Sigh, that's right, just one byte,
533 as not all platforms can do DMA
539 /* Read the DMA Count Registers */
540 status
= read_ram(port
->port
->serial
->dev
, port
->dma_address
,
541 sizeof(*oedb
), (void *)oedb
);
543 goto exit_is_tx_active
;
545 dbg("%s - XByteCount 0x%X", __func__
, oedb
->XByteCount
);
548 status
= read_ram(port
->port
->serial
->dev
,
549 port
->uart_base
+ UMPMEM_OFFS_UART_LSR
, 1, lsr
);
552 goto exit_is_tx_active
;
553 dbg("%s - LSR = 0x%X", __func__
, *lsr
);
555 /* If either buffer has data or we are transmitting then return TRUE */
556 if ((oedb
->XByteCount
& 0x80) != 0)
559 if ((*lsr
& UMP_UART_LSR_TX_MASK
) == 0)
562 /* We return Not Active if we get any kind of error */
564 dbg("%s - return %d", __func__
, bytes_left
);
571 static void chase_port(struct edgeport_port
*port
, unsigned long timeout
,
575 struct tty_struct
*tty
= tty_port_tty_get(&port
->port
->port
);
580 timeout
= (HZ
* EDGE_CLOSING_WAIT
)/100;
582 /* wait for data to drain from the buffer */
583 spin_lock_irqsave(&port
->ep_lock
, flags
);
584 init_waitqueue_entry(&wait
, current
);
585 add_wait_queue(&tty
->write_wait
, &wait
);
587 set_current_state(TASK_INTERRUPTIBLE
);
588 if (edge_buf_data_avail(port
->ep_out_buf
) == 0
589 || timeout
== 0 || signal_pending(current
)
590 || !usb_get_intfdata(port
->port
->serial
->interface
))
593 spin_unlock_irqrestore(&port
->ep_lock
, flags
);
594 timeout
= schedule_timeout(timeout
);
595 spin_lock_irqsave(&port
->ep_lock
, flags
);
597 set_current_state(TASK_RUNNING
);
598 remove_wait_queue(&tty
->write_wait
, &wait
);
600 edge_buf_clear(port
->ep_out_buf
);
601 spin_unlock_irqrestore(&port
->ep_lock
, flags
);
604 /* wait for data to drain from the device */
606 while ((long)(jiffies
- timeout
) < 0 && !signal_pending(current
)
607 && usb_get_intfdata(port
->port
->serial
->interface
)) {
608 /* not disconnected */
609 if (!tx_active(port
))
615 if (!usb_get_intfdata(port
->port
->serial
->interface
))
618 /* wait one more character time, based on baud rate */
619 /* (tx_active doesn't seem to wait for the last byte) */
620 baud_rate
= port
->baud_rate
;
623 msleep(max(1, DIV_ROUND_UP(10000, baud_rate
)));
626 static int choose_config(struct usb_device
*dev
)
629 * There may be multiple configurations on this device, in which case
630 * we would need to read and parse all of them to find out which one
631 * we want. However, we just support one config at this point,
632 * configuration # 1, which is Config Descriptor 0.
635 dbg("%s - Number of Interfaces = %d",
636 __func__
, dev
->config
->desc
.bNumInterfaces
);
637 dbg("%s - MAX Power = %d",
638 __func__
, dev
->config
->desc
.bMaxPower
* 2);
640 if (dev
->config
->desc
.bNumInterfaces
!= 1) {
641 dev_err(&dev
->dev
, "%s - bNumInterfaces is not 1, ERROR!\n",
649 static int read_rom(struct edgeport_serial
*serial
,
650 int start_address
, int length
, __u8
*buffer
)
654 if (serial
->product_info
.TiMode
== TI_MODE_DOWNLOAD
) {
655 status
= read_download_mem(serial
->serial
->dev
,
661 status
= read_boot_mem(serial
, start_address
, length
,
667 static int write_rom(struct edgeport_serial
*serial
, int start_address
,
668 int length
, __u8
*buffer
)
670 if (serial
->product_info
.TiMode
== TI_MODE_BOOT
)
671 return write_boot_mem(serial
, start_address
, length
,
674 if (serial
->product_info
.TiMode
== TI_MODE_DOWNLOAD
)
675 return write_i2c_mem(serial
, start_address
, length
,
676 serial
->TI_I2C_Type
, buffer
);
682 /* Read a descriptor header from I2C based on type */
683 static int get_descriptor_addr(struct edgeport_serial
*serial
,
684 int desc_type
, struct ti_i2c_desc
*rom_desc
)
689 /* Search for requested descriptor in I2C */
692 status
= read_rom(serial
,
694 sizeof(struct ti_i2c_desc
),
699 if (rom_desc
->Type
== desc_type
)
700 return start_address
;
702 start_address
= start_address
+ sizeof(struct ti_i2c_desc
)
705 } while ((start_address
< TI_MAX_I2C_SIZE
) && rom_desc
->Type
);
710 /* Validate descriptor checksum */
711 static int valid_csum(struct ti_i2c_desc
*rom_desc
, __u8
*buffer
)
716 for (i
= 0; i
< rom_desc
->Size
; i
++)
717 cs
= (__u8
)(cs
+ buffer
[i
]);
719 if (cs
!= rom_desc
->CheckSum
) {
720 dbg("%s - Mismatch %x - %x", __func__
, rom_desc
->CheckSum
, cs
);
726 /* Make sure that the I2C image is good */
727 static int check_i2c_image(struct edgeport_serial
*serial
)
729 struct device
*dev
= &serial
->serial
->dev
->dev
;
731 struct ti_i2c_desc
*rom_desc
;
732 int start_address
= 2;
736 rom_desc
= kmalloc(sizeof(*rom_desc
), GFP_KERNEL
);
738 dev_err(dev
, "%s - out of memory\n", __func__
);
741 buffer
= kmalloc(TI_MAX_I2C_SIZE
, GFP_KERNEL
);
743 dev_err(dev
, "%s - out of memory when allocating buffer\n",
749 /* Read the first byte (Signature0) must be 0x52 or 0x10 */
750 status
= read_rom(serial
, 0, 1, buffer
);
754 if (*buffer
!= UMP5152
&& *buffer
!= UMP3410
) {
755 dev_err(dev
, "%s - invalid buffer signature\n", __func__
);
761 /* Validate the I2C */
762 status
= read_rom(serial
,
764 sizeof(struct ti_i2c_desc
),
769 if ((start_address
+ sizeof(struct ti_i2c_desc
) +
770 rom_desc
->Size
) > TI_MAX_I2C_SIZE
) {
772 dbg("%s - structure too big, erroring out.", __func__
);
776 dbg("%s Type = 0x%x", __func__
, rom_desc
->Type
);
778 /* Skip type 2 record */
779 ttype
= rom_desc
->Type
& 0x0f;
780 if (ttype
!= I2C_DESC_TYPE_FIRMWARE_BASIC
781 && ttype
!= I2C_DESC_TYPE_FIRMWARE_AUTO
) {
782 /* Read the descriptor data */
783 status
= read_rom(serial
, start_address
+
784 sizeof(struct ti_i2c_desc
),
785 rom_desc
->Size
, buffer
);
789 status
= valid_csum(rom_desc
, buffer
);
793 start_address
= start_address
+ sizeof(struct ti_i2c_desc
) +
796 } while ((rom_desc
->Type
!= I2C_DESC_TYPE_ION
) &&
797 (start_address
< TI_MAX_I2C_SIZE
));
799 if ((rom_desc
->Type
!= I2C_DESC_TYPE_ION
) ||
800 (start_address
> TI_MAX_I2C_SIZE
))
809 static int get_manuf_info(struct edgeport_serial
*serial
, __u8
*buffer
)
813 struct ti_i2c_desc
*rom_desc
;
814 struct edge_ti_manuf_descriptor
*desc
;
816 rom_desc
= kmalloc(sizeof(*rom_desc
), GFP_KERNEL
);
818 dev_err(&serial
->serial
->dev
->dev
, "%s - out of memory\n",
822 start_address
= get_descriptor_addr(serial
, I2C_DESC_TYPE_ION
,
825 if (!start_address
) {
826 dbg("%s - Edge Descriptor not found in I2C", __func__
);
831 /* Read the descriptor data */
832 status
= read_rom(serial
, start_address
+sizeof(struct ti_i2c_desc
),
833 rom_desc
->Size
, buffer
);
837 status
= valid_csum(rom_desc
, buffer
);
839 desc
= (struct edge_ti_manuf_descriptor
*)buffer
;
840 dbg("%s - IonConfig 0x%x", __func__
, desc
->IonConfig
);
841 dbg("%s - Version %d", __func__
, desc
->Version
);
842 dbg("%s - Cpu/Board 0x%x", __func__
, desc
->CpuRev_BoardRev
);
843 dbg("%s - NumPorts %d", __func__
, desc
->NumPorts
);
844 dbg("%s - NumVirtualPorts %d", __func__
, desc
->NumVirtualPorts
);
845 dbg("%s - TotalPorts %d", __func__
, desc
->TotalPorts
);
852 /* Build firmware header used for firmware update */
853 static int build_i2c_fw_hdr(__u8
*header
, struct device
*dev
)
860 struct ti_i2c_desc
*i2c_header
;
861 struct ti_i2c_image_header
*img_header
;
862 struct ti_i2c_firmware_rec
*firmware_rec
;
863 const struct firmware
*fw
;
864 const char *fw_name
= "edgeport/down3.bin";
866 /* In order to update the I2C firmware we must change the type 2 record
867 * to type 0xF2. This will force the UMP to come up in Boot Mode.
868 * Then while in boot mode, the driver will download the latest
869 * firmware (padded to 15.5k) into the UMP ram. And finally when the
870 * device comes back up in download mode the driver will cause the new
871 * firmware to be copied from the UMP Ram to I2C and the firmware will
872 * update the record type from 0xf2 to 0x02.
875 /* Allocate a 15.5k buffer + 2 bytes for version number
876 * (Firmware Record) */
877 buffer_size
= (((1024 * 16) - 512 ) +
878 sizeof(struct ti_i2c_firmware_rec
));
880 buffer
= kmalloc(buffer_size
, GFP_KERNEL
);
882 dev_err(dev
, "%s - out of memory\n", __func__
);
886 // Set entire image of 0xffs
887 memset(buffer
, 0xff, buffer_size
);
889 err
= request_firmware(&fw
, fw_name
, dev
);
891 printk(KERN_ERR
"Failed to load image \"%s\" err %d\n",
897 /* Save Download Version Number */
898 OperationalMajorVersion
= fw
->data
[0];
899 OperationalMinorVersion
= fw
->data
[1];
900 OperationalBuildNumber
= fw
->data
[2] | (fw
->data
[3] << 8);
902 /* Copy version number into firmware record */
903 firmware_rec
= (struct ti_i2c_firmware_rec
*)buffer
;
905 firmware_rec
->Ver_Major
= OperationalMajorVersion
;
906 firmware_rec
->Ver_Minor
= OperationalMinorVersion
;
908 /* Pointer to fw_down memory image */
909 img_header
= (struct ti_i2c_image_header
*)&fw
->data
[4];
911 memcpy(buffer
+ sizeof(struct ti_i2c_firmware_rec
),
912 &fw
->data
[4 + sizeof(struct ti_i2c_image_header
)],
913 le16_to_cpu(img_header
->Length
));
915 release_firmware(fw
);
917 for (i
=0; i
< buffer_size
; i
++) {
918 cs
= (__u8
)(cs
+ buffer
[i
]);
923 /* Build new header */
924 i2c_header
= (struct ti_i2c_desc
*)header
;
925 firmware_rec
= (struct ti_i2c_firmware_rec
*)i2c_header
->Data
;
927 i2c_header
->Type
= I2C_DESC_TYPE_FIRMWARE_BLANK
;
928 i2c_header
->Size
= (__u16
)buffer_size
;
929 i2c_header
->CheckSum
= cs
;
930 firmware_rec
->Ver_Major
= OperationalMajorVersion
;
931 firmware_rec
->Ver_Minor
= OperationalMinorVersion
;
936 /* Try to figure out what type of I2c we have */
937 static int i2c_type_bootmode(struct edgeport_serial
*serial
)
942 data
= kmalloc(1, GFP_KERNEL
);
944 dev_err(&serial
->serial
->dev
->dev
,
945 "%s - out of memory\n", __func__
);
949 /* Try to read type 2 */
950 status
= ti_vread_sync(serial
->serial
->dev
, UMPC_MEMORY_READ
,
951 DTK_ADDR_SPACE_I2C_TYPE_II
, 0, data
, 0x01);
953 dbg("%s - read 2 status error = %d", __func__
, status
);
955 dbg("%s - read 2 data = 0x%x", __func__
, *data
);
956 if ((!status
) && (*data
== UMP5152
|| *data
== UMP3410
)) {
957 dbg("%s - ROM_TYPE_II", __func__
);
958 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
962 /* Try to read type 3 */
963 status
= ti_vread_sync(serial
->serial
->dev
, UMPC_MEMORY_READ
,
964 DTK_ADDR_SPACE_I2C_TYPE_III
, 0, data
, 0x01);
966 dbg("%s - read 3 status error = %d", __func__
, status
);
968 dbg("%s - read 2 data = 0x%x", __func__
, *data
);
969 if ((!status
) && (*data
== UMP5152
|| *data
== UMP3410
)) {
970 dbg("%s - ROM_TYPE_III", __func__
);
971 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_III
;
975 dbg("%s - Unknown", __func__
);
976 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
983 static int bulk_xfer(struct usb_serial
*serial
, void *buffer
,
984 int length
, int *num_sent
)
988 status
= usb_bulk_msg(serial
->dev
,
989 usb_sndbulkpipe(serial
->dev
,
990 serial
->port
[0]->bulk_out_endpointAddress
),
991 buffer
, length
, num_sent
, 1000);
995 /* Download given firmware image to the device (IN BOOT MODE) */
996 static int download_code(struct edgeport_serial
*serial
, __u8
*image
,
1004 /* Transfer firmware image */
1005 for (pos
= 0; pos
< image_length
; ) {
1006 /* Read the next buffer from file */
1007 transfer
= image_length
- pos
;
1008 if (transfer
> EDGE_FW_BULK_MAX_PACKET_SIZE
)
1009 transfer
= EDGE_FW_BULK_MAX_PACKET_SIZE
;
1012 status
= bulk_xfer(serial
->serial
, &image
[pos
],
1016 /* Advance buffer pointer */
1024 static int config_boot_dev(struct usb_device
*dev
)
1029 static int ti_cpu_rev(struct edge_ti_manuf_descriptor
*desc
)
1031 return TI_GET_CPU_REVISION(desc
->CpuRev_BoardRev
);
1035 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
1037 * This routine downloads the main operating code into the TI5052, using the
1038 * boot code already burned into E2PROM or ROM.
1040 static int download_fw(struct edgeport_serial
*serial
)
1042 struct device
*dev
= &serial
->serial
->dev
->dev
;
1045 struct edge_ti_manuf_descriptor
*ti_manuf_desc
;
1046 struct usb_interface_descriptor
*interface
;
1047 int download_cur_ver
;
1048 int download_new_ver
;
1050 /* This routine is entered by both the BOOT mode and the Download mode
1051 * We can determine which code is running by the reading the config
1052 * descriptor and if we have only one bulk pipe it is in boot mode
1054 serial
->product_info
.hardware_type
= HARDWARE_TYPE_TIUMP
;
1056 /* Default to type 2 i2c */
1057 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
1059 status
= choose_config(serial
->serial
->dev
);
1063 interface
= &serial
->serial
->interface
->cur_altsetting
->desc
;
1065 dev_err(dev
, "%s - no interface set, error!\n", __func__
);
1070 * Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
1071 * if we have more than one endpoint we are definitely in download
1074 if (interface
->bNumEndpoints
> 1)
1075 serial
->product_info
.TiMode
= TI_MODE_DOWNLOAD
;
1077 /* Otherwise we will remain in configuring mode */
1078 serial
->product_info
.TiMode
= TI_MODE_CONFIGURING
;
1080 /********************************************************************/
1082 /********************************************************************/
1083 if (serial
->product_info
.TiMode
== TI_MODE_DOWNLOAD
) {
1084 struct ti_i2c_desc
*rom_desc
;
1086 dbg("%s - RUNNING IN DOWNLOAD MODE", __func__
);
1088 status
= check_i2c_image(serial
);
1090 dbg("%s - DOWNLOAD MODE -- BAD I2C", __func__
);
1094 /* Validate Hardware version number
1095 * Read Manufacturing Descriptor from TI Based Edgeport
1097 ti_manuf_desc
= kmalloc(sizeof(*ti_manuf_desc
), GFP_KERNEL
);
1098 if (!ti_manuf_desc
) {
1099 dev_err(dev
, "%s - out of memory.\n", __func__
);
1102 status
= get_manuf_info(serial
, (__u8
*)ti_manuf_desc
);
1104 kfree(ti_manuf_desc
);
1108 /* Check version number of ION descriptor */
1109 if (!ignore_cpu_rev
&& ti_cpu_rev(ti_manuf_desc
) < 2) {
1110 dbg("%s - Wrong CPU Rev %d (Must be 2)",
1111 __func__
, ti_cpu_rev(ti_manuf_desc
));
1112 kfree(ti_manuf_desc
);
1116 rom_desc
= kmalloc(sizeof(*rom_desc
), GFP_KERNEL
);
1118 dev_err(dev
, "%s - out of memory.\n", __func__
);
1119 kfree(ti_manuf_desc
);
1123 /* Search for type 2 record (firmware record) */
1124 start_address
= get_descriptor_addr(serial
,
1125 I2C_DESC_TYPE_FIRMWARE_BASIC
, rom_desc
);
1126 if (start_address
!= 0) {
1127 struct ti_i2c_firmware_rec
*firmware_version
;
1130 dbg("%s - Found Type FIRMWARE (Type 2) record",
1133 firmware_version
= kmalloc(sizeof(*firmware_version
),
1135 if (!firmware_version
) {
1136 dev_err(dev
, "%s - out of memory.\n", __func__
);
1138 kfree(ti_manuf_desc
);
1142 /* Validate version number
1143 * Read the descriptor data
1145 status
= read_rom(serial
, start_address
+
1146 sizeof(struct ti_i2c_desc
),
1147 sizeof(struct ti_i2c_firmware_rec
),
1148 (__u8
*)firmware_version
);
1150 kfree(firmware_version
);
1152 kfree(ti_manuf_desc
);
1156 /* Check version number of download with current
1158 download_cur_ver
= (firmware_version
->Ver_Major
<< 8) +
1159 (firmware_version
->Ver_Minor
);
1160 download_new_ver
= (OperationalMajorVersion
<< 8) +
1161 (OperationalMinorVersion
);
1163 dbg("%s - >> FW Versions Device %d.%d Driver %d.%d",
1165 firmware_version
->Ver_Major
,
1166 firmware_version
->Ver_Minor
,
1167 OperationalMajorVersion
,
1168 OperationalMinorVersion
);
1170 /* Check if we have an old version in the I2C and
1171 update if necessary */
1172 if (download_cur_ver
!= download_new_ver
) {
1173 dbg("%s - Update I2C dld from %d.%d to %d.%d",
1175 firmware_version
->Ver_Major
,
1176 firmware_version
->Ver_Minor
,
1177 OperationalMajorVersion
,
1178 OperationalMinorVersion
);
1180 record
= kmalloc(1, GFP_KERNEL
);
1182 dev_err(dev
, "%s - out of memory.\n",
1184 kfree(firmware_version
);
1186 kfree(ti_manuf_desc
);
1189 /* In order to update the I2C firmware we must
1190 * change the type 2 record to type 0xF2. This
1191 * will force the UMP to come up in Boot Mode.
1192 * Then while in boot mode, the driver will
1193 * download the latest firmware (padded to
1194 * 15.5k) into the UMP ram. Finally when the
1195 * device comes back up in download mode the
1196 * driver will cause the new firmware to be
1197 * copied from the UMP Ram to I2C and the
1198 * firmware will update the record type from
1201 *record
= I2C_DESC_TYPE_FIRMWARE_BLANK
;
1203 /* Change the I2C Firmware record type to
1204 0xf2 to trigger an update */
1205 status
= write_rom(serial
, start_address
,
1206 sizeof(*record
), record
);
1209 kfree(firmware_version
);
1211 kfree(ti_manuf_desc
);
1215 /* verify the write -- must do this in order
1216 * for write to complete before we do the
1219 status
= read_rom(serial
,
1225 kfree(firmware_version
);
1227 kfree(ti_manuf_desc
);
1231 if (*record
!= I2C_DESC_TYPE_FIRMWARE_BLANK
) {
1233 "%s - error resetting device\n",
1236 kfree(firmware_version
);
1238 kfree(ti_manuf_desc
);
1242 dbg("%s - HARDWARE RESET", __func__
);
1244 /* Reset UMP -- Back to BOOT MODE */
1245 status
= ti_vsend_sync(serial
->serial
->dev
,
1246 UMPC_HARDWARE_RESET
,
1249 dbg("%s - HARDWARE RESET return %d",
1252 /* return an error on purpose. */
1254 kfree(firmware_version
);
1256 kfree(ti_manuf_desc
);
1259 kfree(firmware_version
);
1261 /* Search for type 0xF2 record (firmware blank record) */
1262 else if ((start_address
= get_descriptor_addr(serial
, I2C_DESC_TYPE_FIRMWARE_BLANK
, rom_desc
)) != 0) {
1263 #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + \
1264 sizeof(struct ti_i2c_firmware_rec))
1268 header
= kmalloc(HEADER_SIZE
, GFP_KERNEL
);
1270 dev_err(dev
, "%s - out of memory.\n", __func__
);
1272 kfree(ti_manuf_desc
);
1276 vheader
= kmalloc(HEADER_SIZE
, GFP_KERNEL
);
1278 dev_err(dev
, "%s - out of memory.\n", __func__
);
1281 kfree(ti_manuf_desc
);
1285 dbg("%s - Found Type BLANK FIRMWARE (Type F2) record",
1289 * In order to update the I2C firmware we must change
1290 * the type 2 record to type 0xF2. This will force the
1291 * UMP to come up in Boot Mode. Then while in boot
1292 * mode, the driver will download the latest firmware
1293 * (padded to 15.5k) into the UMP ram. Finally when the
1294 * device comes back up in download mode the driver
1295 * will cause the new firmware to be copied from the
1296 * UMP Ram to I2C and the firmware will update the
1297 * record type from 0xf2 to 0x02.
1299 status
= build_i2c_fw_hdr(header
, dev
);
1304 kfree(ti_manuf_desc
);
1308 /* Update I2C with type 0xf2 record with correct
1309 size and checksum */
1310 status
= write_rom(serial
,
1318 kfree(ti_manuf_desc
);
1322 /* verify the write -- must do this in order for
1323 write to complete before we do the hardware reset */
1324 status
= read_rom(serial
, start_address
,
1325 HEADER_SIZE
, vheader
);
1328 dbg("%s - can't read header back", __func__
);
1332 kfree(ti_manuf_desc
);
1335 if (memcmp(vheader
, header
, HEADER_SIZE
)) {
1336 dbg("%s - write download record failed",
1341 kfree(ti_manuf_desc
);
1348 dbg("%s - Start firmware update", __func__
);
1350 /* Tell firmware to copy download image into I2C */
1351 status
= ti_vsend_sync(serial
->serial
->dev
,
1352 UMPC_COPY_DNLD_TO_I2C
, 0, 0, NULL
, 0);
1354 dbg("%s - Update complete 0x%x", __func__
, status
);
1357 "%s - UMPC_COPY_DNLD_TO_I2C failed\n",
1360 kfree(ti_manuf_desc
);
1365 // The device is running the download code
1367 kfree(ti_manuf_desc
);
1371 /********************************************************************/
1373 /********************************************************************/
1374 dbg("%s - RUNNING IN BOOT MODE", __func__
);
1376 /* Configure the TI device so we can use the BULK pipes for download */
1377 status
= config_boot_dev(serial
->serial
->dev
);
1381 if (le16_to_cpu(serial
->serial
->dev
->descriptor
.idVendor
)
1382 != USB_VENDOR_ID_ION
) {
1383 dbg("%s - VID = 0x%x", __func__
,
1384 le16_to_cpu(serial
->serial
->dev
->descriptor
.idVendor
));
1385 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
1386 goto stayinbootmode
;
1389 /* We have an ION device (I2c Must be programmed)
1390 Determine I2C image type */
1391 if (i2c_type_bootmode(serial
))
1392 goto stayinbootmode
;
1394 /* Check for ION Vendor ID and that the I2C is valid */
1395 if (!check_i2c_image(serial
)) {
1396 struct ti_i2c_image_header
*header
;
1402 const struct firmware
*fw
;
1403 const char *fw_name
= "edgeport/down3.bin";
1405 /* Validate Hardware version number
1406 * Read Manufacturing Descriptor from TI Based Edgeport
1408 ti_manuf_desc
= kmalloc(sizeof(*ti_manuf_desc
), GFP_KERNEL
);
1409 if (!ti_manuf_desc
) {
1410 dev_err(dev
, "%s - out of memory.\n", __func__
);
1413 status
= get_manuf_info(serial
, (__u8
*)ti_manuf_desc
);
1415 kfree(ti_manuf_desc
);
1416 goto stayinbootmode
;
1419 /* Check for version 2 */
1420 if (!ignore_cpu_rev
&& ti_cpu_rev(ti_manuf_desc
) < 2) {
1421 dbg("%s - Wrong CPU Rev %d (Must be 2)",
1422 __func__
, ti_cpu_rev(ti_manuf_desc
));
1423 kfree(ti_manuf_desc
);
1424 goto stayinbootmode
;
1427 kfree(ti_manuf_desc
);
1430 * In order to update the I2C firmware we must change the type
1431 * 2 record to type 0xF2. This will force the UMP to come up
1432 * in Boot Mode. Then while in boot mode, the driver will
1433 * download the latest firmware (padded to 15.5k) into the
1434 * UMP ram. Finally when the device comes back up in download
1435 * mode the driver will cause the new firmware to be copied
1436 * from the UMP Ram to I2C and the firmware will update the
1437 * record type from 0xf2 to 0x02.
1439 * Do we really have to copy the whole firmware image,
1440 * or could we do this in place!
1443 /* Allocate a 15.5k buffer + 3 byte header */
1444 buffer_size
= (((1024 * 16) - 512) +
1445 sizeof(struct ti_i2c_image_header
));
1446 buffer
= kmalloc(buffer_size
, GFP_KERNEL
);
1448 dev_err(dev
, "%s - out of memory\n", __func__
);
1452 /* Initialize the buffer to 0xff (pad the buffer) */
1453 memset(buffer
, 0xff, buffer_size
);
1455 err
= request_firmware(&fw
, fw_name
, dev
);
1457 printk(KERN_ERR
"Failed to load image \"%s\" err %d\n",
1462 memcpy(buffer
, &fw
->data
[4], fw
->size
- 4);
1463 release_firmware(fw
);
1465 for (i
= sizeof(struct ti_i2c_image_header
);
1466 i
< buffer_size
; i
++) {
1467 cs
= (__u8
)(cs
+ buffer
[i
]);
1470 header
= (struct ti_i2c_image_header
*)buffer
;
1472 /* update length and checksum after padding */
1473 header
->Length
= cpu_to_le16((__u16
)(buffer_size
-
1474 sizeof(struct ti_i2c_image_header
)));
1475 header
->CheckSum
= cs
;
1477 /* Download the operational code */
1478 dbg("%s - Downloading operational code image (TI UMP)",
1480 status
= download_code(serial
, buffer
, buffer_size
);
1485 dbg("%s - Error downloading operational code image",
1490 /* Device will reboot */
1491 serial
->product_info
.TiMode
= TI_MODE_TRANSITIONING
;
1493 dbg("%s - Download successful -- Device rebooting...",
1496 /* return an error on purpose */
1501 /* Eprom is invalid or blank stay in boot mode */
1502 dbg("%s - STAYING IN BOOT MODE", __func__
);
1503 serial
->product_info
.TiMode
= TI_MODE_BOOT
;
1509 static int ti_do_config(struct edgeport_port
*port
, int feature
, int on
)
1511 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1512 on
= !!on
; /* 1 or 0 not bitmask */
1513 return send_cmd(port
->port
->serial
->dev
,
1514 feature
, (__u8
)(UMPM_UART1_PORT
+ port_number
),
1519 static int restore_mcr(struct edgeport_port
*port
, __u8 mcr
)
1523 dbg("%s - %x", __func__
, mcr
);
1525 status
= ti_do_config(port
, UMPC_SET_CLR_DTR
, mcr
& MCR_DTR
);
1528 status
= ti_do_config(port
, UMPC_SET_CLR_RTS
, mcr
& MCR_RTS
);
1531 return ti_do_config(port
, UMPC_SET_CLR_LOOPBACK
, mcr
& MCR_LOOPBACK
);
1534 /* Convert TI LSR to standard UART flags */
1535 static __u8
map_line_status(__u8 ti_lsr
)
1539 #define MAP_FLAG(flagUmp, flagUart) \
1540 if (ti_lsr & flagUmp) \
1543 MAP_FLAG(UMP_UART_LSR_OV_MASK
, LSR_OVER_ERR
) /* overrun */
1544 MAP_FLAG(UMP_UART_LSR_PE_MASK
, LSR_PAR_ERR
) /* parity error */
1545 MAP_FLAG(UMP_UART_LSR_FE_MASK
, LSR_FRM_ERR
) /* framing error */
1546 MAP_FLAG(UMP_UART_LSR_BR_MASK
, LSR_BREAK
) /* break detected */
1547 MAP_FLAG(UMP_UART_LSR_RX_MASK
, LSR_RX_AVAIL
) /* rx data available */
1548 MAP_FLAG(UMP_UART_LSR_TX_MASK
, LSR_TX_EMPTY
) /* tx hold reg empty */
1555 static void handle_new_msr(struct edgeport_port
*edge_port
, __u8 msr
)
1557 struct async_icount
*icount
;
1558 struct tty_struct
*tty
;
1560 dbg("%s - %02x", __func__
, msr
);
1562 if (msr
& (EDGEPORT_MSR_DELTA_CTS
| EDGEPORT_MSR_DELTA_DSR
|
1563 EDGEPORT_MSR_DELTA_RI
| EDGEPORT_MSR_DELTA_CD
)) {
1564 icount
= &edge_port
->icount
;
1566 /* update input line counters */
1567 if (msr
& EDGEPORT_MSR_DELTA_CTS
)
1569 if (msr
& EDGEPORT_MSR_DELTA_DSR
)
1571 if (msr
& EDGEPORT_MSR_DELTA_CD
)
1573 if (msr
& EDGEPORT_MSR_DELTA_RI
)
1575 wake_up_interruptible(&edge_port
->delta_msr_wait
);
1578 /* Save the new modem status */
1579 edge_port
->shadow_msr
= msr
& 0xf0;
1581 tty
= tty_port_tty_get(&edge_port
->port
->port
);
1582 /* handle CTS flow control */
1583 if (tty
&& C_CRTSCTS(tty
)) {
1584 if (msr
& EDGEPORT_MSR_CTS
) {
1585 tty
->hw_stopped
= 0;
1588 tty
->hw_stopped
= 1;
1596 static void handle_new_lsr(struct edgeport_port
*edge_port
, int lsr_data
,
1597 __u8 lsr
, __u8 data
)
1599 struct async_icount
*icount
;
1600 __u8 new_lsr
= (__u8
)(lsr
& (__u8
)(LSR_OVER_ERR
| LSR_PAR_ERR
|
1601 LSR_FRM_ERR
| LSR_BREAK
));
1602 struct tty_struct
*tty
;
1604 dbg("%s - %02x", __func__
, new_lsr
);
1606 edge_port
->shadow_lsr
= lsr
;
1608 if (new_lsr
& LSR_BREAK
)
1610 * Parity and Framing errors only count if they
1611 * occur exclusive of a break being received.
1613 new_lsr
&= (__u8
)(LSR_OVER_ERR
| LSR_BREAK
);
1615 /* Place LSR data byte into Rx buffer */
1617 tty
= tty_port_tty_get(&edge_port
->port
->port
);
1619 edge_tty_recv(&edge_port
->port
->dev
, tty
, &data
, 1);
1624 /* update input line counters */
1625 icount
= &edge_port
->icount
;
1626 if (new_lsr
& LSR_BREAK
)
1628 if (new_lsr
& LSR_OVER_ERR
)
1630 if (new_lsr
& LSR_PAR_ERR
)
1632 if (new_lsr
& LSR_FRM_ERR
)
1637 static void edge_interrupt_callback(struct urb
*urb
)
1639 struct edgeport_serial
*edge_serial
= urb
->context
;
1640 struct usb_serial_port
*port
;
1641 struct edgeport_port
*edge_port
;
1642 unsigned char *data
= urb
->transfer_buffer
;
1643 int length
= urb
->actual_length
;
1649 int status
= urb
->status
;
1651 dbg("%s", __func__
);
1660 /* this urb is terminated, clean up */
1661 dbg("%s - urb shutting down with status: %d",
1665 dev_err(&urb
->dev
->dev
, "%s - nonzero urb status received: "
1666 "%d\n", __func__
, status
);
1671 dbg("%s - no data in urb", __func__
);
1675 usb_serial_debug_data(debug
, &edge_serial
->serial
->dev
->dev
,
1676 __func__
, length
, data
);
1679 dbg("%s - expecting packet of size 2, got %d",
1684 port_number
= TIUMP_GET_PORT_FROM_CODE(data
[0]);
1685 function
= TIUMP_GET_FUNC_FROM_CODE(data
[0]);
1686 dbg("%s - port_number %d, function %d, info 0x%x",
1687 __func__
, port_number
, function
, data
[1]);
1688 port
= edge_serial
->serial
->port
[port_number
];
1689 edge_port
= usb_get_serial_port_data(port
);
1691 dbg("%s - edge_port not found", __func__
);
1695 case TIUMP_INTERRUPT_CODE_LSR
:
1696 lsr
= map_line_status(data
[1]);
1697 if (lsr
& UMP_UART_LSR_DATA_MASK
) {
1698 /* Save the LSR event for bulk read
1699 completion routine */
1700 dbg("%s - LSR Event Port %u LSR Status = %02x",
1701 __func__
, port_number
, lsr
);
1702 edge_port
->lsr_event
= 1;
1703 edge_port
->lsr_mask
= lsr
;
1705 dbg("%s - ===== Port %d LSR Status = %02x ======",
1706 __func__
, port_number
, lsr
);
1707 handle_new_lsr(edge_port
, 0, lsr
, 0);
1711 case TIUMP_INTERRUPT_CODE_MSR
: /* MSR */
1712 /* Copy MSR from UMP */
1714 dbg("%s - ===== Port %u MSR Status = %02x ======",
1715 __func__
, port_number
, msr
);
1716 handle_new_msr(edge_port
, msr
);
1720 dev_err(&urb
->dev
->dev
,
1721 "%s - Unknown Interrupt code from UMP %x\n",
1728 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
1730 dev_err(&urb
->dev
->dev
,
1731 "%s - usb_submit_urb failed with result %d\n",
1735 static void edge_bulk_in_callback(struct urb
*urb
)
1737 struct edgeport_port
*edge_port
= urb
->context
;
1738 unsigned char *data
= urb
->transfer_buffer
;
1739 struct tty_struct
*tty
;
1742 int status
= urb
->status
;
1744 dbg("%s", __func__
);
1753 /* this urb is terminated, clean up */
1754 dbg("%s - urb shutting down with status: %d",
1758 dev_err(&urb
->dev
->dev
,
1759 "%s - nonzero read bulk status received: %d\n",
1763 if (status
== -EPIPE
)
1767 dev_err(&urb
->dev
->dev
, "%s - stopping read!\n", __func__
);
1771 port_number
= edge_port
->port
->number
- edge_port
->port
->serial
->minor
;
1773 if (edge_port
->lsr_event
) {
1774 edge_port
->lsr_event
= 0;
1775 dbg("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
1776 __func__
, port_number
, edge_port
->lsr_mask
, *data
);
1777 handle_new_lsr(edge_port
, 1, edge_port
->lsr_mask
, *data
);
1778 /* Adjust buffer length/pointer */
1779 --urb
->actual_length
;
1783 tty
= tty_port_tty_get(&edge_port
->port
->port
);
1784 if (tty
&& urb
->actual_length
) {
1785 usb_serial_debug_data(debug
, &edge_port
->port
->dev
,
1786 __func__
, urb
->actual_length
, data
);
1787 if (edge_port
->close_pending
)
1788 dbg("%s - close pending, dropping data on the floor",
1791 edge_tty_recv(&edge_port
->port
->dev
, tty
, data
,
1792 urb
->actual_length
);
1793 edge_port
->icount
.rx
+= urb
->actual_length
;
1798 /* continue read unless stopped */
1799 spin_lock(&edge_port
->ep_lock
);
1800 if (edge_port
->ep_read_urb_state
== EDGE_READ_URB_RUNNING
) {
1801 urb
->dev
= edge_port
->port
->serial
->dev
;
1802 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
1803 } else if (edge_port
->ep_read_urb_state
== EDGE_READ_URB_STOPPING
) {
1804 edge_port
->ep_read_urb_state
= EDGE_READ_URB_STOPPED
;
1806 spin_unlock(&edge_port
->ep_lock
);
1808 dev_err(&urb
->dev
->dev
,
1809 "%s - usb_submit_urb failed with result %d\n",
1813 static void edge_tty_recv(struct device
*dev
, struct tty_struct
*tty
,
1814 unsigned char *data
, int length
)
1818 queued
= tty_insert_flip_string(tty
, data
, length
);
1819 if (queued
< length
)
1820 dev_err(dev
, "%s - dropping data, %d bytes lost\n",
1821 __func__
, length
- queued
);
1822 tty_flip_buffer_push(tty
);
1825 static void edge_bulk_out_callback(struct urb
*urb
)
1827 struct usb_serial_port
*port
= urb
->context
;
1828 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
1829 int status
= urb
->status
;
1830 struct tty_struct
*tty
;
1832 dbg("%s - port %d", __func__
, port
->number
);
1834 edge_port
->ep_write_urb_in_use
= 0;
1843 /* this urb is terminated, clean up */
1844 dbg("%s - urb shutting down with status: %d",
1848 dev_err(&urb
->dev
->dev
, "%s - nonzero write bulk status "
1849 "received: %d\n", __func__
, status
);
1852 /* send any buffered data */
1853 tty
= tty_port_tty_get(&port
->port
);
1858 static int edge_open(struct tty_struct
*tty
, struct usb_serial_port
*port
)
1860 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
1861 struct edgeport_serial
*edge_serial
;
1862 struct usb_device
*dev
;
1867 u8 transaction_timeout
;
1869 dbg("%s - port %d", __func__
, port
->number
);
1871 if (edge_port
== NULL
)
1874 port_number
= port
->number
- port
->serial
->minor
;
1875 switch (port_number
) {
1877 edge_port
->uart_base
= UMPMEM_BASE_UART1
;
1878 edge_port
->dma_address
= UMPD_OEDB1_ADDRESS
;
1881 edge_port
->uart_base
= UMPMEM_BASE_UART2
;
1882 edge_port
->dma_address
= UMPD_OEDB2_ADDRESS
;
1885 dev_err(&port
->dev
, "Unknown port number!!!\n");
1889 dbg("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
1890 __func__
, port_number
, edge_port
->uart_base
,
1891 edge_port
->dma_address
);
1893 dev
= port
->serial
->dev
;
1895 memset(&(edge_port
->icount
), 0x00, sizeof(edge_port
->icount
));
1896 init_waitqueue_head(&edge_port
->delta_msr_wait
);
1898 /* turn off loopback */
1899 status
= ti_do_config(edge_port
, UMPC_SET_CLR_LOOPBACK
, 0);
1902 "%s - cannot send clear loopback command, %d\n",
1907 /* set up the port settings */
1909 edge_set_termios(tty
, port
, tty
->termios
);
1911 /* open up the port */
1913 /* milliseconds to timeout for DMA transfer */
1914 transaction_timeout
= 2;
1916 edge_port
->ump_read_timeout
=
1917 max(20, ((transaction_timeout
* 3) / 2));
1919 /* milliseconds to timeout for DMA transfer */
1920 open_settings
= (u8
)(UMP_DMA_MODE_CONTINOUS
|
1921 UMP_PIPE_TRANS_TIMEOUT_ENA
|
1922 (transaction_timeout
<< 2));
1924 dbg("%s - Sending UMPC_OPEN_PORT", __func__
);
1926 /* Tell TI to open and start the port */
1927 status
= send_cmd(dev
, UMPC_OPEN_PORT
,
1928 (u8
)(UMPM_UART1_PORT
+ port_number
), open_settings
, NULL
, 0);
1930 dev_err(&port
->dev
, "%s - cannot send open command, %d\n",
1935 /* Start the DMA? */
1936 status
= send_cmd(dev
, UMPC_START_PORT
,
1937 (u8
)(UMPM_UART1_PORT
+ port_number
), 0, NULL
, 0);
1939 dev_err(&port
->dev
, "%s - cannot send start DMA command, %d\n",
1944 /* Clear TX and RX buffers in UMP */
1945 status
= purge_port(port
, UMP_PORT_DIR_OUT
| UMP_PORT_DIR_IN
);
1948 "%s - cannot send clear buffers command, %d\n",
1953 /* Read Initial MSR */
1954 status
= ti_vread_sync(dev
, UMPC_READ_MSR
, 0,
1955 (__u16
)(UMPM_UART1_PORT
+ port_number
),
1956 &edge_port
->shadow_msr
, 1);
1958 dev_err(&port
->dev
, "%s - cannot send read MSR command, %d\n",
1963 dbg("ShadowMSR 0x%X", edge_port
->shadow_msr
);
1965 /* Set Initial MCR */
1966 edge_port
->shadow_mcr
= MCR_RTS
| MCR_DTR
;
1967 dbg("ShadowMCR 0x%X", edge_port
->shadow_mcr
);
1969 edge_serial
= edge_port
->edge_serial
;
1970 if (mutex_lock_interruptible(&edge_serial
->es_lock
))
1971 return -ERESTARTSYS
;
1972 if (edge_serial
->num_ports_open
== 0) {
1973 /* we are the first port to open, post the interrupt urb */
1974 urb
= edge_serial
->serial
->port
[0]->interrupt_in_urb
;
1977 "%s - no interrupt urb present, exiting\n",
1980 goto release_es_lock
;
1982 urb
->complete
= edge_interrupt_callback
;
1983 urb
->context
= edge_serial
;
1985 status
= usb_submit_urb(urb
, GFP_KERNEL
);
1988 "%s - usb_submit_urb failed with value %d\n",
1990 goto release_es_lock
;
1995 * reset the data toggle on the bulk endpoints to work around bug in
1996 * host controllers where things get out of sync some times
1998 usb_clear_halt(dev
, port
->write_urb
->pipe
);
1999 usb_clear_halt(dev
, port
->read_urb
->pipe
);
2001 /* start up our bulk read urb */
2002 urb
= port
->read_urb
;
2004 dev_err(&port
->dev
, "%s - no read urb present, exiting\n",
2007 goto unlink_int_urb
;
2009 edge_port
->ep_read_urb_state
= EDGE_READ_URB_RUNNING
;
2010 urb
->complete
= edge_bulk_in_callback
;
2011 urb
->context
= edge_port
;
2013 status
= usb_submit_urb(urb
, GFP_KERNEL
);
2016 "%s - read bulk usb_submit_urb failed with value %d\n",
2018 goto unlink_int_urb
;
2021 ++edge_serial
->num_ports_open
;
2023 dbg("%s - exited", __func__
);
2025 goto release_es_lock
;
2028 if (edge_port
->edge_serial
->num_ports_open
== 0)
2029 usb_kill_urb(port
->serial
->port
[0]->interrupt_in_urb
);
2031 mutex_unlock(&edge_serial
->es_lock
);
2035 static void edge_close(struct usb_serial_port
*port
)
2037 struct edgeport_serial
*edge_serial
;
2038 struct edgeport_port
*edge_port
;
2042 dbg("%s - port %d", __func__
, port
->number
);
2044 edge_serial
= usb_get_serial_data(port
->serial
);
2045 edge_port
= usb_get_serial_port_data(port
);
2046 if (edge_serial
== NULL
|| edge_port
== NULL
)
2049 /* The bulkreadcompletion routine will check
2050 * this flag and dump add read data */
2051 edge_port
->close_pending
= 1;
2053 /* chase the port close and flush */
2054 chase_port(edge_port
, (HZ
* closing_wait
) / 100, 1);
2056 usb_kill_urb(port
->read_urb
);
2057 usb_kill_urb(port
->write_urb
);
2058 edge_port
->ep_write_urb_in_use
= 0;
2060 /* assuming we can still talk to the device,
2061 * send a close port command to it */
2062 dbg("%s - send umpc_close_port", __func__
);
2063 port_number
= port
->number
- port
->serial
->minor
;
2064 status
= send_cmd(port
->serial
->dev
,
2066 (__u8
)(UMPM_UART1_PORT
+ port_number
),
2070 mutex_lock(&edge_serial
->es_lock
);
2071 --edge_port
->edge_serial
->num_ports_open
;
2072 if (edge_port
->edge_serial
->num_ports_open
<= 0) {
2073 /* last port is now closed, let's shut down our interrupt urb */
2074 usb_kill_urb(port
->serial
->port
[0]->interrupt_in_urb
);
2075 edge_port
->edge_serial
->num_ports_open
= 0;
2077 mutex_unlock(&edge_serial
->es_lock
);
2078 edge_port
->close_pending
= 0;
2080 dbg("%s - exited", __func__
);
2083 static int edge_write(struct tty_struct
*tty
, struct usb_serial_port
*port
,
2084 const unsigned char *data
, int count
)
2086 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2087 unsigned long flags
;
2089 dbg("%s - port %d", __func__
, port
->number
);
2092 dbg("%s - write request of 0 bytes", __func__
);
2096 if (edge_port
== NULL
)
2098 if (edge_port
->close_pending
== 1)
2101 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2102 count
= edge_buf_put(edge_port
->ep_out_buf
, data
, count
);
2103 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2110 static void edge_send(struct tty_struct
*tty
)
2112 struct usb_serial_port
*port
= tty
->driver_data
;
2114 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2115 unsigned long flags
;
2118 dbg("%s - port %d", __func__
, port
->number
);
2120 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2122 if (edge_port
->ep_write_urb_in_use
) {
2123 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2127 count
= edge_buf_get(edge_port
->ep_out_buf
,
2128 port
->write_urb
->transfer_buffer
,
2129 port
->bulk_out_size
);
2132 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2136 edge_port
->ep_write_urb_in_use
= 1;
2138 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2140 usb_serial_debug_data(debug
, &port
->dev
, __func__
, count
,
2141 port
->write_urb
->transfer_buffer
);
2143 /* set up our urb */
2144 usb_fill_bulk_urb(port
->write_urb
, port
->serial
->dev
,
2145 usb_sndbulkpipe(port
->serial
->dev
,
2146 port
->bulk_out_endpointAddress
),
2147 port
->write_urb
->transfer_buffer
, count
,
2148 edge_bulk_out_callback
,
2151 /* send the data out the bulk port */
2152 result
= usb_submit_urb(port
->write_urb
, GFP_ATOMIC
);
2155 "%s - failed submitting write urb, error %d\n",
2157 edge_port
->ep_write_urb_in_use
= 0;
2158 /* TODO: reschedule edge_send */
2160 edge_port
->icount
.tx
+= count
;
2162 /* wakeup any process waiting for writes to complete */
2163 /* there is now more room in the buffer for new writes */
2168 static int edge_write_room(struct tty_struct
*tty
)
2170 struct usb_serial_port
*port
= tty
->driver_data
;
2171 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2173 unsigned long flags
;
2175 dbg("%s - port %d", __func__
, port
->number
);
2177 if (edge_port
== NULL
)
2179 if (edge_port
->close_pending
== 1)
2182 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2183 room
= edge_buf_space_avail(edge_port
->ep_out_buf
);
2184 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2186 dbg("%s - returns %d", __func__
, room
);
2190 static int edge_chars_in_buffer(struct tty_struct
*tty
)
2192 struct usb_serial_port
*port
= tty
->driver_data
;
2193 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2195 unsigned long flags
;
2197 dbg("%s - port %d", __func__
, port
->number
);
2199 if (edge_port
== NULL
)
2201 if (edge_port
->close_pending
== 1)
2204 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2205 chars
= edge_buf_data_avail(edge_port
->ep_out_buf
);
2206 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2208 dbg("%s - returns %d", __func__
, chars
);
2212 static void edge_throttle(struct tty_struct
*tty
)
2214 struct usb_serial_port
*port
= tty
->driver_data
;
2215 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2218 dbg("%s - port %d", __func__
, port
->number
);
2220 if (edge_port
== NULL
)
2223 /* if we are implementing XON/XOFF, send the stop character */
2225 unsigned char stop_char
= STOP_CHAR(tty
);
2226 status
= edge_write(tty
, port
, &stop_char
, 1);
2228 dev_err(&port
->dev
, "%s - failed to write stop character, %d\n", __func__
, status
);
2232 /* if we are implementing RTS/CTS, stop reads */
2233 /* and the Edgeport will clear the RTS line */
2235 stop_read(edge_port
);
2239 static void edge_unthrottle(struct tty_struct
*tty
)
2241 struct usb_serial_port
*port
= tty
->driver_data
;
2242 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2245 dbg("%s - port %d", __func__
, port
->number
);
2247 if (edge_port
== NULL
)
2250 /* if we are implementing XON/XOFF, send the start character */
2252 unsigned char start_char
= START_CHAR(tty
);
2253 status
= edge_write(tty
, port
, &start_char
, 1);
2255 dev_err(&port
->dev
, "%s - failed to write start character, %d\n", __func__
, status
);
2258 /* if we are implementing RTS/CTS, restart reads */
2259 /* are the Edgeport will assert the RTS line */
2260 if (C_CRTSCTS(tty
)) {
2261 status
= restart_read(edge_port
);
2264 "%s - read bulk usb_submit_urb failed: %d\n",
2270 static void stop_read(struct edgeport_port
*edge_port
)
2272 unsigned long flags
;
2274 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2276 if (edge_port
->ep_read_urb_state
== EDGE_READ_URB_RUNNING
)
2277 edge_port
->ep_read_urb_state
= EDGE_READ_URB_STOPPING
;
2278 edge_port
->shadow_mcr
&= ~MCR_RTS
;
2280 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2283 static int restart_read(struct edgeport_port
*edge_port
)
2287 unsigned long flags
;
2289 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2291 if (edge_port
->ep_read_urb_state
== EDGE_READ_URB_STOPPED
) {
2292 urb
= edge_port
->port
->read_urb
;
2293 urb
->complete
= edge_bulk_in_callback
;
2294 urb
->context
= edge_port
;
2295 urb
->dev
= edge_port
->port
->serial
->dev
;
2296 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
2298 edge_port
->ep_read_urb_state
= EDGE_READ_URB_RUNNING
;
2299 edge_port
->shadow_mcr
|= MCR_RTS
;
2301 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2306 static void change_port_settings(struct tty_struct
*tty
,
2307 struct edgeport_port
*edge_port
, struct ktermios
*old_termios
)
2309 struct ump_uart_config
*config
;
2313 int port_number
= edge_port
->port
->number
-
2314 edge_port
->port
->serial
->minor
;
2316 dbg("%s - port %d", __func__
, edge_port
->port
->number
);
2318 config
= kmalloc (sizeof (*config
), GFP_KERNEL
);
2320 *tty
->termios
= *old_termios
;
2321 dev_err(&edge_port
->port
->dev
, "%s - out of memory\n",
2326 cflag
= tty
->termios
->c_cflag
;
2330 /* These flags must be set */
2331 config
->wFlags
|= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT
;
2332 config
->wFlags
|= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR
;
2333 config
->bUartMode
= (__u8
)(edge_port
->bUartMode
);
2335 switch (cflag
& CSIZE
) {
2337 config
->bDataBits
= UMP_UART_CHAR5BITS
;
2338 dbg("%s - data bits = 5", __func__
);
2341 config
->bDataBits
= UMP_UART_CHAR6BITS
;
2342 dbg("%s - data bits = 6", __func__
);
2345 config
->bDataBits
= UMP_UART_CHAR7BITS
;
2346 dbg("%s - data bits = 7", __func__
);
2350 config
->bDataBits
= UMP_UART_CHAR8BITS
;
2351 dbg("%s - data bits = 8", __func__
);
2355 if (cflag
& PARENB
) {
2356 if (cflag
& PARODD
) {
2357 config
->wFlags
|= UMP_MASK_UART_FLAGS_PARITY
;
2358 config
->bParity
= UMP_UART_ODDPARITY
;
2359 dbg("%s - parity = odd", __func__
);
2361 config
->wFlags
|= UMP_MASK_UART_FLAGS_PARITY
;
2362 config
->bParity
= UMP_UART_EVENPARITY
;
2363 dbg("%s - parity = even", __func__
);
2366 config
->bParity
= UMP_UART_NOPARITY
;
2367 dbg("%s - parity = none", __func__
);
2370 if (cflag
& CSTOPB
) {
2371 config
->bStopBits
= UMP_UART_STOPBIT2
;
2372 dbg("%s - stop bits = 2", __func__
);
2374 config
->bStopBits
= UMP_UART_STOPBIT1
;
2375 dbg("%s - stop bits = 1", __func__
);
2378 /* figure out the flow control settings */
2379 if (cflag
& CRTSCTS
) {
2380 config
->wFlags
|= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW
;
2381 config
->wFlags
|= UMP_MASK_UART_FLAGS_RTS_FLOW
;
2382 dbg("%s - RTS/CTS is enabled", __func__
);
2384 dbg("%s - RTS/CTS is disabled", __func__
);
2385 tty
->hw_stopped
= 0;
2386 restart_read(edge_port
);
2389 /* if we are implementing XON/XOFF, set the start and stop
2390 character in the device */
2391 config
->cXon
= START_CHAR(tty
);
2392 config
->cXoff
= STOP_CHAR(tty
);
2394 /* if we are implementing INBOUND XON/XOFF */
2396 config
->wFlags
|= UMP_MASK_UART_FLAGS_IN_X
;
2397 dbg("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2398 __func__
, config
->cXon
, config
->cXoff
);
2400 dbg("%s - INBOUND XON/XOFF is disabled", __func__
);
2402 /* if we are implementing OUTBOUND XON/XOFF */
2404 config
->wFlags
|= UMP_MASK_UART_FLAGS_OUT_X
;
2405 dbg("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2406 __func__
, config
->cXon
, config
->cXoff
);
2408 dbg("%s - OUTBOUND XON/XOFF is disabled", __func__
);
2410 tty
->termios
->c_cflag
&= ~CMSPAR
;
2412 /* Round the baud rate */
2413 baud
= tty_get_baud_rate(tty
);
2415 /* pick a default, any default... */
2418 tty_encode_baud_rate(tty
, baud
, baud
);
2420 edge_port
->baud_rate
= baud
;
2421 config
->wBaudRate
= (__u16
)((461550L + baud
/2) / baud
);
2423 /* FIXME: Recompute actual baud from divisor here */
2425 dbg("%s - baud rate = %d, wBaudRate = %d", __func__
, baud
,
2428 dbg("wBaudRate: %d", (int)(461550L / config
->wBaudRate
));
2429 dbg("wFlags: 0x%x", config
->wFlags
);
2430 dbg("bDataBits: %d", config
->bDataBits
);
2431 dbg("bParity: %d", config
->bParity
);
2432 dbg("bStopBits: %d", config
->bStopBits
);
2433 dbg("cXon: %d", config
->cXon
);
2434 dbg("cXoff: %d", config
->cXoff
);
2435 dbg("bUartMode: %d", config
->bUartMode
);
2437 /* move the word values into big endian mode */
2438 cpu_to_be16s(&config
->wFlags
);
2439 cpu_to_be16s(&config
->wBaudRate
);
2441 status
= send_cmd(edge_port
->port
->serial
->dev
, UMPC_SET_CONFIG
,
2442 (__u8
)(UMPM_UART1_PORT
+ port_number
),
2443 0, (__u8
*)config
, sizeof(*config
));
2445 dbg("%s - error %d when trying to write config to device",
2451 static void edge_set_termios(struct tty_struct
*tty
,
2452 struct usb_serial_port
*port
, struct ktermios
*old_termios
)
2454 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2457 cflag
= tty
->termios
->c_cflag
;
2459 dbg("%s - clfag %08x iflag %08x", __func__
,
2460 tty
->termios
->c_cflag
, tty
->termios
->c_iflag
);
2461 dbg("%s - old clfag %08x old iflag %08x", __func__
,
2462 old_termios
->c_cflag
, old_termios
->c_iflag
);
2463 dbg("%s - port %d", __func__
, port
->number
);
2465 if (edge_port
== NULL
)
2467 /* change the port settings to the new ones specified */
2468 change_port_settings(tty
, edge_port
, old_termios
);
2472 static int edge_tiocmset(struct tty_struct
*tty
, struct file
*file
,
2473 unsigned int set
, unsigned int clear
)
2475 struct usb_serial_port
*port
= tty
->driver_data
;
2476 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2478 unsigned long flags
;
2480 dbg("%s - port %d", __func__
, port
->number
);
2482 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2483 mcr
= edge_port
->shadow_mcr
;
2484 if (set
& TIOCM_RTS
)
2486 if (set
& TIOCM_DTR
)
2488 if (set
& TIOCM_LOOP
)
2489 mcr
|= MCR_LOOPBACK
;
2491 if (clear
& TIOCM_RTS
)
2493 if (clear
& TIOCM_DTR
)
2495 if (clear
& TIOCM_LOOP
)
2496 mcr
&= ~MCR_LOOPBACK
;
2498 edge_port
->shadow_mcr
= mcr
;
2499 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2501 restore_mcr(edge_port
, mcr
);
2505 static int edge_tiocmget(struct tty_struct
*tty
, struct file
*file
)
2507 struct usb_serial_port
*port
= tty
->driver_data
;
2508 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2509 unsigned int result
= 0;
2512 unsigned long flags
;
2514 dbg("%s - port %d", __func__
, port
->number
);
2516 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2518 msr
= edge_port
->shadow_msr
;
2519 mcr
= edge_port
->shadow_mcr
;
2520 result
= ((mcr
& MCR_DTR
) ? TIOCM_DTR
: 0) /* 0x002 */
2521 | ((mcr
& MCR_RTS
) ? TIOCM_RTS
: 0) /* 0x004 */
2522 | ((msr
& EDGEPORT_MSR_CTS
) ? TIOCM_CTS
: 0) /* 0x020 */
2523 | ((msr
& EDGEPORT_MSR_CD
) ? TIOCM_CAR
: 0) /* 0x040 */
2524 | ((msr
& EDGEPORT_MSR_RI
) ? TIOCM_RI
: 0) /* 0x080 */
2525 | ((msr
& EDGEPORT_MSR_DSR
) ? TIOCM_DSR
: 0); /* 0x100 */
2528 dbg("%s -- %x", __func__
, result
);
2529 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2534 static int get_serial_info(struct edgeport_port
*edge_port
,
2535 struct serial_struct __user
*retinfo
)
2537 struct serial_struct tmp
;
2542 memset(&tmp
, 0, sizeof(tmp
));
2544 tmp
.type
= PORT_16550A
;
2545 tmp
.line
= edge_port
->port
->serial
->minor
;
2546 tmp
.port
= edge_port
->port
->number
;
2548 tmp
.flags
= ASYNC_SKIP_TEST
| ASYNC_AUTO_IRQ
;
2549 tmp
.xmit_fifo_size
= edge_port
->port
->bulk_out_size
;
2550 tmp
.baud_base
= 9600;
2551 tmp
.close_delay
= 5*HZ
;
2552 tmp
.closing_wait
= closing_wait
;
2554 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2559 static int edge_ioctl(struct tty_struct
*tty
, struct file
*file
,
2560 unsigned int cmd
, unsigned long arg
)
2562 struct usb_serial_port
*port
= tty
->driver_data
;
2563 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2564 struct async_icount cnow
;
2565 struct async_icount cprev
;
2567 dbg("%s - port %d, cmd = 0x%x", __func__
, port
->number
, cmd
);
2571 dbg("%s - (%d) TIOCGSERIAL", __func__
, port
->number
);
2572 return get_serial_info(edge_port
,
2573 (struct serial_struct __user
*) arg
);
2575 dbg("%s - (%d) TIOCMIWAIT", __func__
, port
->number
);
2576 cprev
= edge_port
->icount
;
2578 interruptible_sleep_on(&edge_port
->delta_msr_wait
);
2579 /* see if a signal did it */
2580 if (signal_pending(current
))
2581 return -ERESTARTSYS
;
2582 cnow
= edge_port
->icount
;
2583 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
2584 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
2585 return -EIO
; /* no change => error */
2586 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
2587 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
2588 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
2589 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
))) {
2597 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__
,
2598 port
->number
, edge_port
->icount
.rx
, edge_port
->icount
.tx
);
2599 if (copy_to_user((void __user
*)arg
, &edge_port
->icount
,
2600 sizeof(edge_port
->icount
)))
2604 return -ENOIOCTLCMD
;
2607 static void edge_break(struct tty_struct
*tty
, int break_state
)
2609 struct usb_serial_port
*port
= tty
->driver_data
;
2610 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2612 int bv
= 0; /* Off */
2614 dbg("%s - state = %d", __func__
, break_state
);
2616 /* chase the port close */
2617 chase_port(edge_port
, 0, 0);
2619 if (break_state
== -1)
2621 status
= ti_do_config(edge_port
, UMPC_SET_CLR_BREAK
, bv
);
2623 dbg("%s - error %d sending break set/clear command.",
2627 static int edge_startup(struct usb_serial
*serial
)
2629 struct edgeport_serial
*edge_serial
;
2630 struct edgeport_port
*edge_port
;
2631 struct usb_device
*dev
;
2637 /* create our private serial structure */
2638 edge_serial
= kzalloc(sizeof(struct edgeport_serial
), GFP_KERNEL
);
2639 if (edge_serial
== NULL
) {
2640 dev_err(&serial
->dev
->dev
, "%s - Out of memory\n", __func__
);
2643 mutex_init(&edge_serial
->es_lock
);
2644 edge_serial
->serial
= serial
;
2645 usb_set_serial_data(serial
, edge_serial
);
2647 status
= download_fw(edge_serial
);
2653 /* set up our port private structures */
2654 for (i
= 0; i
< serial
->num_ports
; ++i
) {
2655 edge_port
= kzalloc(sizeof(struct edgeport_port
), GFP_KERNEL
);
2656 if (edge_port
== NULL
) {
2657 dev_err(&serial
->dev
->dev
, "%s - Out of memory\n",
2661 spin_lock_init(&edge_port
->ep_lock
);
2662 edge_port
->ep_out_buf
= edge_buf_alloc(EDGE_OUT_BUF_SIZE
);
2663 if (edge_port
->ep_out_buf
== NULL
) {
2664 dev_err(&serial
->dev
->dev
, "%s - Out of memory\n",
2669 edge_port
->port
= serial
->port
[i
];
2670 edge_port
->edge_serial
= edge_serial
;
2671 usb_set_serial_port_data(serial
->port
[i
], edge_port
);
2672 edge_port
->bUartMode
= default_uart_mode
;
2678 for (--i
; i
>= 0; --i
) {
2679 edge_port
= usb_get_serial_port_data(serial
->port
[i
]);
2680 edge_buf_free(edge_port
->ep_out_buf
);
2682 usb_set_serial_port_data(serial
->port
[i
], NULL
);
2685 usb_set_serial_data(serial
, NULL
);
2689 static void edge_disconnect(struct usb_serial
*serial
)
2692 struct edgeport_port
*edge_port
;
2694 dbg("%s", __func__
);
2696 for (i
= 0; i
< serial
->num_ports
; ++i
) {
2697 edge_port
= usb_get_serial_port_data(serial
->port
[i
]);
2698 edge_remove_sysfs_attrs(edge_port
->port
);
2702 static void edge_release(struct usb_serial
*serial
)
2705 struct edgeport_port
*edge_port
;
2707 dbg("%s", __func__
);
2709 for (i
= 0; i
< serial
->num_ports
; ++i
) {
2710 edge_port
= usb_get_serial_port_data(serial
->port
[i
]);
2711 edge_buf_free(edge_port
->ep_out_buf
);
2714 kfree(usb_get_serial_data(serial
));
2718 /* Sysfs Attributes */
2720 static ssize_t
show_uart_mode(struct device
*dev
,
2721 struct device_attribute
*attr
, char *buf
)
2723 struct usb_serial_port
*port
= to_usb_serial_port(dev
);
2724 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2726 return sprintf(buf
, "%d\n", edge_port
->bUartMode
);
2729 static ssize_t
store_uart_mode(struct device
*dev
,
2730 struct device_attribute
*attr
, const char *valbuf
, size_t count
)
2732 struct usb_serial_port
*port
= to_usb_serial_port(dev
);
2733 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2734 unsigned int v
= simple_strtoul(valbuf
, NULL
, 0);
2736 dbg("%s: setting uart_mode = %d", __func__
, v
);
2739 edge_port
->bUartMode
= v
;
2741 dev_err(dev
, "%s - uart_mode %d is invalid\n", __func__
, v
);
2746 static DEVICE_ATTR(uart_mode
, S_IWUSR
| S_IRUGO
, show_uart_mode
,
2749 static int edge_create_sysfs_attrs(struct usb_serial_port
*port
)
2751 return device_create_file(&port
->dev
, &dev_attr_uart_mode
);
2754 static int edge_remove_sysfs_attrs(struct usb_serial_port
*port
)
2756 device_remove_file(&port
->dev
, &dev_attr_uart_mode
);
2761 /* Circular Buffer */
2766 * Allocate a circular buffer and all associated memory.
2769 static struct edge_buf
*edge_buf_alloc(unsigned int size
)
2771 struct edge_buf
*eb
;
2777 eb
= kmalloc(sizeof(struct edge_buf
), GFP_KERNEL
);
2781 eb
->buf_buf
= kmalloc(size
, GFP_KERNEL
);
2782 if (eb
->buf_buf
== NULL
) {
2787 eb
->buf_size
= size
;
2788 eb
->buf_get
= eb
->buf_put
= eb
->buf_buf
;
2797 * Free the buffer and all associated memory.
2800 static void edge_buf_free(struct edge_buf
*eb
)
2812 * Clear out all data in the circular buffer.
2815 static void edge_buf_clear(struct edge_buf
*eb
)
2818 eb
->buf_get
= eb
->buf_put
;
2819 /* equivalent to a get of all data available */
2824 * edge_buf_data_avail
2826 * Return the number of bytes of data available in the circular
2830 static unsigned int edge_buf_data_avail(struct edge_buf
*eb
)
2834 return ((eb
->buf_size
+ eb
->buf_put
- eb
->buf_get
) % eb
->buf_size
);
2839 * edge_buf_space_avail
2841 * Return the number of bytes of space available in the circular
2845 static unsigned int edge_buf_space_avail(struct edge_buf
*eb
)
2849 return ((eb
->buf_size
+ eb
->buf_get
- eb
->buf_put
- 1) % eb
->buf_size
);
2856 * Copy data data from a user buffer and put it into the circular buffer.
2857 * Restrict to the amount of space available.
2859 * Return the number of bytes copied.
2862 static unsigned int edge_buf_put(struct edge_buf
*eb
, const char *buf
,
2871 len
= edge_buf_space_avail(eb
);
2878 len
= eb
->buf_buf
+ eb
->buf_size
- eb
->buf_put
;
2880 memcpy(eb
->buf_put
, buf
, len
);
2881 memcpy(eb
->buf_buf
, buf
+len
, count
- len
);
2882 eb
->buf_put
= eb
->buf_buf
+ count
- len
;
2884 memcpy(eb
->buf_put
, buf
, count
);
2886 eb
->buf_put
+= count
;
2887 else /* count == len */
2888 eb
->buf_put
= eb
->buf_buf
;
2898 * Get data from the circular buffer and copy to the given buffer.
2899 * Restrict to the amount of data available.
2901 * Return the number of bytes copied.
2904 static unsigned int edge_buf_get(struct edge_buf
*eb
, char *buf
,
2913 len
= edge_buf_data_avail(eb
);
2920 len
= eb
->buf_buf
+ eb
->buf_size
- eb
->buf_get
;
2922 memcpy(buf
, eb
->buf_get
, len
);
2923 memcpy(buf
+len
, eb
->buf_buf
, count
- len
);
2924 eb
->buf_get
= eb
->buf_buf
+ count
- len
;
2926 memcpy(buf
, eb
->buf_get
, count
);
2928 eb
->buf_get
+= count
;
2929 else /* count == len */
2930 eb
->buf_get
= eb
->buf_buf
;
2937 static struct usb_serial_driver edgeport_1port_device
= {
2939 .owner
= THIS_MODULE
,
2940 .name
= "edgeport_ti_1",
2942 .description
= "Edgeport TI 1 port adapter",
2943 .usb_driver
= &io_driver
,
2944 .id_table
= edgeport_1port_id_table
,
2947 .close
= edge_close
,
2948 .throttle
= edge_throttle
,
2949 .unthrottle
= edge_unthrottle
,
2950 .attach
= edge_startup
,
2951 .disconnect
= edge_disconnect
,
2952 .release
= edge_release
,
2953 .port_probe
= edge_create_sysfs_attrs
,
2954 .ioctl
= edge_ioctl
,
2955 .set_termios
= edge_set_termios
,
2956 .tiocmget
= edge_tiocmget
,
2957 .tiocmset
= edge_tiocmset
,
2958 .write
= edge_write
,
2959 .write_room
= edge_write_room
,
2960 .chars_in_buffer
= edge_chars_in_buffer
,
2961 .break_ctl
= edge_break
,
2962 .read_int_callback
= edge_interrupt_callback
,
2963 .read_bulk_callback
= edge_bulk_in_callback
,
2964 .write_bulk_callback
= edge_bulk_out_callback
,
2967 static struct usb_serial_driver edgeport_2port_device
= {
2969 .owner
= THIS_MODULE
,
2970 .name
= "edgeport_ti_2",
2972 .description
= "Edgeport TI 2 port adapter",
2973 .usb_driver
= &io_driver
,
2974 .id_table
= edgeport_2port_id_table
,
2977 .close
= edge_close
,
2978 .throttle
= edge_throttle
,
2979 .unthrottle
= edge_unthrottle
,
2980 .attach
= edge_startup
,
2981 .disconnect
= edge_disconnect
,
2982 .release
= edge_release
,
2983 .port_probe
= edge_create_sysfs_attrs
,
2984 .ioctl
= edge_ioctl
,
2985 .set_termios
= edge_set_termios
,
2986 .tiocmget
= edge_tiocmget
,
2987 .tiocmset
= edge_tiocmset
,
2988 .write
= edge_write
,
2989 .write_room
= edge_write_room
,
2990 .chars_in_buffer
= edge_chars_in_buffer
,
2991 .break_ctl
= edge_break
,
2992 .read_int_callback
= edge_interrupt_callback
,
2993 .read_bulk_callback
= edge_bulk_in_callback
,
2994 .write_bulk_callback
= edge_bulk_out_callback
,
2998 static int __init
edgeport_init(void)
3001 retval
= usb_serial_register(&edgeport_1port_device
);
3003 goto failed_1port_device_register
;
3004 retval
= usb_serial_register(&edgeport_2port_device
);
3006 goto failed_2port_device_register
;
3007 retval
= usb_register(&io_driver
);
3009 goto failed_usb_register
;
3010 printk(KERN_INFO KBUILD_MODNAME
": " DRIVER_VERSION
":"
3013 failed_usb_register
:
3014 usb_serial_deregister(&edgeport_2port_device
);
3015 failed_2port_device_register
:
3016 usb_serial_deregister(&edgeport_1port_device
);
3017 failed_1port_device_register
:
3021 static void __exit
edgeport_exit(void)
3023 usb_deregister(&io_driver
);
3024 usb_serial_deregister(&edgeport_1port_device
);
3025 usb_serial_deregister(&edgeport_2port_device
);
3028 module_init(edgeport_init
);
3029 module_exit(edgeport_exit
);
3031 /* Module information */
3032 MODULE_AUTHOR(DRIVER_AUTHOR
);
3033 MODULE_DESCRIPTION(DRIVER_DESC
);
3034 MODULE_LICENSE("GPL");
3035 MODULE_FIRMWARE("edgeport/down3.bin");
3037 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
3038 MODULE_PARM_DESC(debug
, "Debug enabled or not");
3040 module_param(closing_wait
, int, S_IRUGO
| S_IWUSR
);
3041 MODULE_PARM_DESC(closing_wait
, "Maximum wait for data to drain, in .01 secs");
3043 module_param(ignore_cpu_rev
, bool, S_IRUGO
| S_IWUSR
);
3044 MODULE_PARM_DESC(ignore_cpu_rev
,
3045 "Ignore the cpu revision when connecting to a device");
3047 module_param(default_uart_mode
, int, S_IRUGO
| S_IWUSR
);
3048 MODULE_PARM_DESC(default_uart_mode
, "Default uart_mode, 0=RS232, ...");