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 <asm/uaccess.h>
41 #include <linux/usb.h>
42 #include <linux/usb/serial.h>
45 #include "io_usbvend.h"
51 #define DRIVER_VERSION "v0.7mode043006"
52 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
53 #define DRIVER_DESC "Edgeport USB Serial Driver"
56 /* firmware image code */
57 #define IMAGE_VERSION_NAME PagableOperationalCodeImageVersion
58 #define IMAGE_ARRAY_NAME PagableOperationalCodeImage
59 #define IMAGE_SIZE PagableOperationalCodeSize
60 #include "io_fw_down3.h" /* Define array OperationalCodeImage[] */
62 #define EPROM_PAGE_SIZE 64
65 struct edgeport_uart_buf_desc
{
66 __u32 count
; // Number of bytes currently in buffer
69 /* different hardware types */
70 #define HARDWARE_TYPE_930 0
71 #define HARDWARE_TYPE_TIUMP 1
73 // IOCTL_PRIVATE_TI_GET_MODE Definitions
74 #define TI_MODE_CONFIGURING 0 // Device has not entered start device
75 #define TI_MODE_BOOT 1 // Staying in boot mode
76 #define TI_MODE_DOWNLOAD 2 // Made it to download mode
77 #define TI_MODE_TRANSITIONING 3 // Currently in boot mode but transitioning to download mode
80 #define EDGE_READ_URB_RUNNING 0
81 #define EDGE_READ_URB_STOPPING 1
82 #define EDGE_READ_URB_STOPPED 2
84 #define EDGE_LOW_LATENCY 1
85 #define EDGE_CLOSING_WAIT 4000 /* in .01 sec */
87 #define EDGE_OUT_BUF_SIZE 1024
90 /* Product information read from the Edgeport */
93 int TiMode
; // Current TI Mode
94 __u8 hardware_type
; // Type of hardware
95 } __attribute__((packed
));
99 unsigned int buf_size
;
105 struct edgeport_port
{
112 __u32 ump_read_timeout
; /* Number of miliseconds the UMP will
113 wait without data before completing
118 struct edgeport_uart_buf_desc tx
;
119 struct async_icount icount
;
120 wait_queue_head_t delta_msr_wait
; /* for handling sleeping while
121 waiting for msr change to
123 struct edgeport_serial
*edge_serial
;
124 struct usb_serial_port
*port
;
125 __u8 bUartMode
; /* Port type, 0: RS232, etc. */
127 int ep_read_urb_state
;
128 int ep_write_urb_in_use
;
129 struct edge_buf
*ep_out_buf
;
132 struct edgeport_serial
{
133 struct product_info product_info
;
134 u8 TI_I2C_Type
; // Type of I2C in UMP
135 u8 TiReadI2C
; // Set to TRUE if we have read the I2c in Boot Mode
136 struct mutex es_lock
;
138 struct usb_serial
*serial
;
142 /* Devices that this driver supports */
143 static struct usb_device_id edgeport_1port_id_table
[] = {
144 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_1
) },
145 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1
) },
146 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I
) },
147 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_PROXIMITY
) },
148 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_MOTION
) },
149 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_MOISTURE
) },
150 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_TEMPERATURE
) },
151 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_HUMIDITY
) },
152 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_POWER
) },
153 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_LIGHT
) },
154 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_RADIATION
) },
155 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_DISTANCE
) },
156 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_ACCELERATION
) },
157 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_PROX_DIST
) },
158 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_PLUS_PWR_HP4CD
) },
159 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_PLUS_PWR_PCI
) },
163 static struct usb_device_id edgeport_2port_id_table
[] = {
164 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2
) },
165 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2C
) },
166 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2I
) },
167 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_421
) },
168 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21
) },
169 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_42
) },
170 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4
) },
171 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4I
) },
172 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22I
) },
173 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_221C
) },
174 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22C
) },
175 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21C
) },
176 /* The 4, 8 and 16 port devices show up as multiple 2 port devices */
177 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4S
) },
178 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_8
) },
179 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_8S
) },
180 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_416
) },
181 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_416B
) },
185 /* Devices that this driver supports */
186 static struct usb_device_id id_table_combined
[] = {
187 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_1
) },
188 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1
) },
189 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I
) },
190 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_PROXIMITY
) },
191 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_MOTION
) },
192 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_MOISTURE
) },
193 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_TEMPERATURE
) },
194 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_HUMIDITY
) },
195 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_POWER
) },
196 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_LIGHT
) },
197 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_RADIATION
) },
198 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_DISTANCE
) },
199 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_ACCELERATION
) },
200 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_PROX_DIST
) },
201 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_PLUS_PWR_HP4CD
) },
202 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_PLUS_PWR_PCI
) },
203 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2
) },
204 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2C
) },
205 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2I
) },
206 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_421
) },
207 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21
) },
208 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_42
) },
209 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4
) },
210 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4I
) },
211 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22I
) },
212 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_221C
) },
213 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22C
) },
214 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21C
) },
215 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4S
) },
216 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_8
) },
217 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_8S
) },
218 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_416
) },
219 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_416B
) },
223 MODULE_DEVICE_TABLE (usb
, id_table_combined
);
225 static struct usb_driver io_driver
= {
227 .probe
= usb_serial_probe
,
228 .disconnect
= usb_serial_disconnect
,
229 .id_table
= id_table_combined
,
234 static struct EDGE_FIRMWARE_VERSION_INFO OperationalCodeImageVersion
;
238 static int TIStayInBootMode
= 0;
239 static int low_latency
= EDGE_LOW_LATENCY
;
240 static int closing_wait
= EDGE_CLOSING_WAIT
;
241 static int ignore_cpu_rev
= 0;
242 static int default_uart_mode
= 0; /* RS232 */
245 static void edge_tty_recv(struct device
*dev
, struct tty_struct
*tty
, unsigned char *data
, int length
);
247 static void stop_read(struct edgeport_port
*edge_port
);
248 static int restart_read(struct edgeport_port
*edge_port
);
250 static void edge_set_termios (struct usb_serial_port
*port
, struct ktermios
*old_termios
);
251 static void edge_send(struct usb_serial_port
*port
);
253 /* sysfs attributes */
254 static int edge_create_sysfs_attrs(struct usb_serial_port
*port
);
255 static int edge_remove_sysfs_attrs(struct usb_serial_port
*port
);
257 /* circular buffer */
258 static struct edge_buf
*edge_buf_alloc(unsigned int size
);
259 static void edge_buf_free(struct edge_buf
*eb
);
260 static void edge_buf_clear(struct edge_buf
*eb
);
261 static unsigned int edge_buf_data_avail(struct edge_buf
*eb
);
262 static unsigned int edge_buf_space_avail(struct edge_buf
*eb
);
263 static unsigned int edge_buf_put(struct edge_buf
*eb
, const char *buf
,
265 static unsigned int edge_buf_get(struct edge_buf
*eb
, char *buf
,
269 static int TIReadVendorRequestSync (struct usb_device
*dev
,
278 status
= usb_control_msg (dev
,
279 usb_rcvctrlpipe(dev
, 0),
291 if (status
!= size
) {
292 dbg ("%s - wanted to write %d, but only wrote %d",
293 __func__
, size
, status
);
299 static int TISendVendorRequestSync (struct usb_device
*dev
,
308 status
= usb_control_msg (dev
,
309 usb_sndctrlpipe(dev
, 0),
321 if (status
!= size
) {
322 dbg ("%s - wanted to write %d, but only wrote %d",
323 __func__
, size
, status
);
329 static int TIWriteCommandSync (struct usb_device
*dev
, __u8 command
,
330 __u8 moduleid
, __u16 value
, u8
*data
,
333 return TISendVendorRequestSync (dev
,
337 data
, // TransferBuffer
338 size
); // TransferBufferLength
342 /* clear tx/rx buffers and fifo in TI UMP */
343 static int TIPurgeDataSync (struct usb_serial_port
*port
, __u16 mask
)
345 int port_number
= port
->number
- port
->serial
->minor
;
347 dbg ("%s - port %d, mask %x", __func__
, port_number
, mask
);
349 return TIWriteCommandSync (port
->serial
->dev
,
351 (__u8
)(UMPM_UART1_PORT
+ port_number
),
358 * TIReadDownloadMemory - Read edgeport memory from TI chip
359 * @dev: usb device pointer
360 * @start_address: Device CPU address at which to read
361 * @length: Length of above data
362 * @address_type: Can read both XDATA and I2C
363 * @buffer: pointer to input data buffer
365 static int TIReadDownloadMemory(struct usb_device
*dev
, int start_address
,
366 int length
, __u8 address_type
, __u8
*buffer
)
370 __be16 be_start_address
;
372 dbg ("%s - @ %x for %d", __func__
, start_address
, length
);
374 /* Read in blocks of 64 bytes
375 * (TI firmware can't handle more than 64 byte reads)
381 read_length
= (__u8
)length
;
383 if (read_length
> 1) {
384 dbg ("%s - @ %x for %d", __func__
,
385 start_address
, read_length
);
387 be_start_address
= cpu_to_be16 (start_address
);
388 status
= TIReadVendorRequestSync (dev
,
389 UMPC_MEMORY_READ
, // Request
390 (__u16
)address_type
, // wValue (Address type)
391 (__force __u16
)be_start_address
, // wIndex (Address to read)
392 buffer
, // TransferBuffer
393 read_length
); // TransferBufferLength
396 dbg ("%s - ERROR %x", __func__
, status
);
400 if (read_length
> 1) {
401 usb_serial_debug_data(debug
, &dev
->dev
, __func__
,
402 read_length
, buffer
);
405 /* Update pointers/length */
406 start_address
+= read_length
;
407 buffer
+= read_length
;
408 length
-= read_length
;
414 static int TIReadRam (struct usb_device
*dev
, int start_address
, int length
, __u8
*buffer
)
416 return TIReadDownloadMemory (dev
,
419 DTK_ADDR_SPACE_XDATA
,
423 /* Read edgeport memory to a given block */
424 static int TIReadBootMemory (struct edgeport_serial
*serial
, int start_address
, int length
, __u8
* buffer
)
429 for (i
=0; i
< length
; i
++) {
430 status
= TIReadVendorRequestSync (serial
->serial
->dev
,
431 UMPC_MEMORY_READ
, // Request
432 serial
->TI_I2C_Type
, // wValue (Address type)
433 (__u16
)(start_address
+i
), // wIndex
434 &buffer
[i
], // TransferBuffer
435 0x01); // TransferBufferLength
437 dbg ("%s - ERROR %x", __func__
, status
);
442 dbg ("%s - start_address = %x, length = %d", __func__
, start_address
, length
);
443 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
, __func__
, length
, buffer
);
445 serial
->TiReadI2C
= 1;
450 /* Write given block to TI EPROM memory */
451 static int TIWriteBootMemory (struct edgeport_serial
*serial
, int start_address
, int length
, __u8
*buffer
)
457 /* Must do a read before write */
458 if (!serial
->TiReadI2C
) {
459 status
= TIReadBootMemory(serial
, 0, 1, &temp
);
464 for (i
=0; i
< length
; ++i
) {
465 status
= TISendVendorRequestSync (serial
->serial
->dev
,
466 UMPC_MEMORY_WRITE
, // Request
468 (__u16
)(i
+start_address
), // wIndex
469 NULL
, // TransferBuffer
470 0); // TransferBufferLength
475 dbg ("%s - start_sddr = %x, length = %d", __func__
, start_address
, length
);
476 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
, __func__
, length
, buffer
);
482 /* Write edgeport I2C memory to TI chip */
483 static int TIWriteDownloadI2C (struct edgeport_serial
*serial
, int start_address
, int length
, __u8 address_type
, __u8
*buffer
)
487 __be16 be_start_address
;
489 /* We can only send a maximum of 1 aligned byte page at a time */
491 /* calulate the number of bytes left in the first page */
492 write_length
= EPROM_PAGE_SIZE
- (start_address
& (EPROM_PAGE_SIZE
- 1));
494 if (write_length
> length
)
495 write_length
= length
;
497 dbg ("%s - BytesInFirstPage Addr = %x, length = %d", __func__
, start_address
, write_length
);
498 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
, __func__
, write_length
, buffer
);
500 /* Write first page */
501 be_start_address
= cpu_to_be16 (start_address
);
502 status
= TISendVendorRequestSync (serial
->serial
->dev
,
503 UMPC_MEMORY_WRITE
, // Request
504 (__u16
)address_type
, // wValue
505 (__force __u16
)be_start_address
, // wIndex
506 buffer
, // TransferBuffer
509 dbg ("%s - ERROR %d", __func__
, status
);
513 length
-= write_length
;
514 start_address
+= write_length
;
515 buffer
+= write_length
;
517 /* We should be aligned now -- can write max page size bytes at a time */
519 if (length
> EPROM_PAGE_SIZE
)
520 write_length
= EPROM_PAGE_SIZE
;
522 write_length
= length
;
524 dbg ("%s - Page Write Addr = %x, length = %d", __func__
, start_address
, write_length
);
525 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
, __func__
, write_length
, buffer
);
527 /* Write next page */
528 be_start_address
= cpu_to_be16 (start_address
);
529 status
= TISendVendorRequestSync (serial
->serial
->dev
,
530 UMPC_MEMORY_WRITE
, // Request
531 (__u16
)address_type
, // wValue
532 (__force __u16
)be_start_address
, // wIndex
533 buffer
, // TransferBuffer
534 write_length
); // TransferBufferLength
536 dev_err (&serial
->serial
->dev
->dev
, "%s - ERROR %d\n", __func__
, status
);
540 length
-= write_length
;
541 start_address
+= write_length
;
542 buffer
+= write_length
;
547 /* Examine the UMP DMA registers and LSR
549 * Check the MSBit of the X and Y DMA byte count registers.
550 * A zero in this bit indicates that the TX DMA buffers are empty
551 * then check the TX Empty bit in the UART.
553 static int TIIsTxActive (struct edgeport_port
*port
)
556 struct out_endpoint_desc_block
*oedb
;
560 oedb
= kmalloc (sizeof (* oedb
), GFP_KERNEL
);
562 dev_err (&port
->port
->dev
, "%s - out of memory\n", __func__
);
566 lsr
= kmalloc (1, GFP_KERNEL
); /* Sigh, that's right, just one byte,
567 as not all platforms can do DMA
573 /* Read the DMA Count Registers */
574 status
= TIReadRam (port
->port
->serial
->dev
,
580 goto exit_is_tx_active
;
582 dbg ("%s - XByteCount 0x%X", __func__
, oedb
->XByteCount
);
585 status
= TIReadRam (port
->port
->serial
->dev
,
586 port
->uart_base
+ UMPMEM_OFFS_UART_LSR
,
591 goto exit_is_tx_active
;
592 dbg ("%s - LSR = 0x%X", __func__
, *lsr
);
594 /* If either buffer has data or we are transmitting then return TRUE */
595 if ((oedb
->XByteCount
& 0x80 ) != 0 )
598 if ((*lsr
& UMP_UART_LSR_TX_MASK
) == 0 )
601 /* We return Not Active if we get any kind of error */
603 dbg ("%s - return %d", __func__
, bytes_left
);
610 static void TIChasePort(struct edgeport_port
*port
, unsigned long timeout
, int flush
)
613 struct tty_struct
*tty
= port
->port
->tty
;
618 timeout
= (HZ
*EDGE_CLOSING_WAIT
)/100;
620 /* wait for data to drain from the buffer */
621 spin_lock_irqsave(&port
->ep_lock
, flags
);
622 init_waitqueue_entry(&wait
, current
);
623 add_wait_queue(&tty
->write_wait
, &wait
);
625 set_current_state(TASK_INTERRUPTIBLE
);
626 if (edge_buf_data_avail(port
->ep_out_buf
) == 0
627 || timeout
== 0 || signal_pending(current
)
628 || !usb_get_intfdata(port
->port
->serial
->interface
)) /* disconnect */
630 spin_unlock_irqrestore(&port
->ep_lock
, flags
);
631 timeout
= schedule_timeout(timeout
);
632 spin_lock_irqsave(&port
->ep_lock
, flags
);
634 set_current_state(TASK_RUNNING
);
635 remove_wait_queue(&tty
->write_wait
, &wait
);
637 edge_buf_clear(port
->ep_out_buf
);
638 spin_unlock_irqrestore(&port
->ep_lock
, flags
);
640 /* wait for data to drain from the device */
642 while ((long)(jiffies
- timeout
) < 0 && !signal_pending(current
)
643 && usb_get_intfdata(port
->port
->serial
->interface
)) { /* not disconnected */
644 if (!TIIsTxActive(port
))
650 if (!usb_get_intfdata(port
->port
->serial
->interface
))
653 /* wait one more character time, based on baud rate */
654 /* (TIIsTxActive doesn't seem to wait for the last byte) */
655 if ((baud_rate
=port
->baud_rate
) == 0)
657 msleep(max(1, DIV_ROUND_UP(10000, baud_rate
)));
660 static int TIChooseConfiguration (struct usb_device
*dev
)
662 // There may be multiple configurations on this device, in which case
663 // we would need to read and parse all of them to find out which one
664 // we want. However, we just support one config at this point,
665 // configuration # 1, which is Config Descriptor 0.
667 dbg ("%s - Number of Interfaces = %d", __func__
, dev
->config
->desc
.bNumInterfaces
);
668 dbg ("%s - MAX Power = %d", __func__
, dev
->config
->desc
.bMaxPower
*2);
670 if (dev
->config
->desc
.bNumInterfaces
!= 1) {
671 dev_err (&dev
->dev
, "%s - bNumInterfaces is not 1, ERROR!\n", __func__
);
678 static int TIReadRom (struct edgeport_serial
*serial
, int start_address
, int length
, __u8
*buffer
)
682 if (serial
->product_info
.TiMode
== TI_MODE_DOWNLOAD
) {
683 status
= TIReadDownloadMemory (serial
->serial
->dev
,
689 status
= TIReadBootMemory (serial
,
698 static int TIWriteRom (struct edgeport_serial
*serial
, int start_address
, int length
, __u8
*buffer
)
700 if (serial
->product_info
.TiMode
== TI_MODE_BOOT
)
701 return TIWriteBootMemory (serial
,
706 if (serial
->product_info
.TiMode
== TI_MODE_DOWNLOAD
)
707 return TIWriteDownloadI2C (serial
,
718 /* Read a descriptor header from I2C based on type */
719 static int TIGetDescriptorAddress (struct edgeport_serial
*serial
, int desc_type
, struct ti_i2c_desc
*rom_desc
)
724 /* Search for requested descriptor in I2C */
727 status
= TIReadRom (serial
,
729 sizeof(struct ti_i2c_desc
),
734 if (rom_desc
->Type
== desc_type
)
735 return start_address
;
737 start_address
= start_address
+ sizeof(struct ti_i2c_desc
) + rom_desc
->Size
;
739 } while ((start_address
< TI_MAX_I2C_SIZE
) && rom_desc
->Type
);
744 /* Validate descriptor checksum */
745 static int ValidChecksum(struct ti_i2c_desc
*rom_desc
, __u8
*buffer
)
750 for (i
=0; i
< rom_desc
->Size
; i
++) {
751 cs
= (__u8
)(cs
+ buffer
[i
]);
753 if (cs
!= rom_desc
->CheckSum
) {
754 dbg ("%s - Mismatch %x - %x", __func__
, rom_desc
->CheckSum
, cs
);
760 /* Make sure that the I2C image is good */
761 static int TiValidateI2cImage (struct edgeport_serial
*serial
)
763 struct device
*dev
= &serial
->serial
->dev
->dev
;
765 struct ti_i2c_desc
*rom_desc
;
766 int start_address
= 2;
770 rom_desc
= kmalloc (sizeof (*rom_desc
), GFP_KERNEL
);
772 dev_err (dev
, "%s - out of memory\n", __func__
);
775 buffer
= kmalloc (TI_MAX_I2C_SIZE
, GFP_KERNEL
);
777 dev_err (dev
, "%s - out of memory when allocating buffer\n", __func__
);
782 // Read the first byte (Signature0) must be 0x52 or 0x10
783 status
= TIReadRom (serial
, 0, 1, buffer
);
785 goto ExitTiValidateI2cImage
;
787 if (*buffer
!= UMP5152
&& *buffer
!= UMP3410
) {
788 dev_err (dev
, "%s - invalid buffer signature\n", __func__
);
790 goto ExitTiValidateI2cImage
;
795 status
= TIReadRom (serial
,
797 sizeof(struct ti_i2c_desc
),
802 if ((start_address
+ sizeof(struct ti_i2c_desc
) + rom_desc
->Size
) > TI_MAX_I2C_SIZE
) {
804 dbg ("%s - structure too big, erroring out.", __func__
);
808 dbg ("%s Type = 0x%x", __func__
, rom_desc
->Type
);
810 // Skip type 2 record
811 ttype
= rom_desc
->Type
& 0x0f;
812 if ( ttype
!= I2C_DESC_TYPE_FIRMWARE_BASIC
813 && ttype
!= I2C_DESC_TYPE_FIRMWARE_AUTO
) {
814 // Read the descriptor data
815 status
= TIReadRom(serial
,
816 start_address
+sizeof(struct ti_i2c_desc
),
822 status
= ValidChecksum(rom_desc
, buffer
);
826 start_address
= start_address
+ sizeof(struct ti_i2c_desc
) + rom_desc
->Size
;
828 } while ((rom_desc
->Type
!= I2C_DESC_TYPE_ION
) && (start_address
< TI_MAX_I2C_SIZE
));
830 if ((rom_desc
->Type
!= I2C_DESC_TYPE_ION
) || (start_address
> TI_MAX_I2C_SIZE
))
833 ExitTiValidateI2cImage
:
839 static int TIReadManufDescriptor (struct edgeport_serial
*serial
, __u8
*buffer
)
843 struct ti_i2c_desc
*rom_desc
;
844 struct edge_ti_manuf_descriptor
*desc
;
846 rom_desc
= kmalloc (sizeof (*rom_desc
), GFP_KERNEL
);
848 dev_err (&serial
->serial
->dev
->dev
, "%s - out of memory\n", __func__
);
851 start_address
= TIGetDescriptorAddress (serial
, I2C_DESC_TYPE_ION
, rom_desc
);
853 if (!start_address
) {
854 dbg ("%s - Edge Descriptor not found in I2C", __func__
);
859 // Read the descriptor data
860 status
= TIReadRom (serial
,
861 start_address
+sizeof(struct ti_i2c_desc
),
867 status
= ValidChecksum(rom_desc
, buffer
);
869 desc
= (struct edge_ti_manuf_descriptor
*)buffer
;
870 dbg ( "%s - IonConfig 0x%x", __func__
, desc
->IonConfig
);
871 dbg ( "%s - Version %d", __func__
, desc
->Version
);
872 dbg ( "%s - Cpu/Board 0x%x", __func__
, desc
->CpuRev_BoardRev
);
873 dbg ( "%s - NumPorts %d", __func__
, desc
->NumPorts
);
874 dbg ( "%s - NumVirtualPorts %d", __func__
, desc
->NumVirtualPorts
);
875 dbg ( "%s - TotalPorts %d", __func__
, desc
->TotalPorts
);
882 /* Build firmware header used for firmware update */
883 static int BuildI2CFirmwareHeader (__u8
*header
, struct device
*dev
)
889 struct ti_i2c_desc
*i2c_header
;
890 struct ti_i2c_image_header
*img_header
;
891 struct ti_i2c_firmware_rec
*firmware_rec
;
893 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
894 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
895 // will download the latest firmware (padded to 15.5k) into the UMP ram.
896 // And finally when the device comes back up in download mode the driver will cause
897 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
898 // the record type from 0xf2 to 0x02.
900 // Allocate a 15.5k buffer + 2 bytes for version number (Firmware Record)
901 buffer_size
= (((1024 * 16) - 512 )+ sizeof(struct ti_i2c_firmware_rec
));
903 buffer
= kmalloc (buffer_size
, GFP_KERNEL
);
905 dev_err (dev
, "%s - out of memory\n", __func__
);
909 // Set entire image of 0xffs
910 memset (buffer
, 0xff, buffer_size
);
912 // Copy version number into firmware record
913 firmware_rec
= (struct ti_i2c_firmware_rec
*)buffer
;
915 firmware_rec
->Ver_Major
= OperationalCodeImageVersion
.MajorVersion
;
916 firmware_rec
->Ver_Minor
= OperationalCodeImageVersion
.MinorVersion
;
918 // Pointer to fw_down memory image
919 img_header
= (struct ti_i2c_image_header
*)&PagableOperationalCodeImage
[0];
921 memcpy (buffer
+ sizeof(struct ti_i2c_firmware_rec
),
922 &PagableOperationalCodeImage
[sizeof(struct ti_i2c_image_header
)],
923 le16_to_cpu(img_header
->Length
));
925 for (i
=0; i
< buffer_size
; i
++) {
926 cs
= (__u8
)(cs
+ buffer
[i
]);
932 i2c_header
= (struct ti_i2c_desc
*)header
;
933 firmware_rec
= (struct ti_i2c_firmware_rec
*)i2c_header
->Data
;
935 i2c_header
->Type
= I2C_DESC_TYPE_FIRMWARE_BLANK
;
936 i2c_header
->Size
= (__u16
)buffer_size
;
937 i2c_header
->CheckSum
= cs
;
938 firmware_rec
->Ver_Major
= OperationalCodeImageVersion
.MajorVersion
;
939 firmware_rec
->Ver_Minor
= OperationalCodeImageVersion
.MinorVersion
;
944 /* Try to figure out what type of I2c we have */
945 static int TIGetI2cTypeInBootMode (struct edgeport_serial
*serial
)
950 // Try to read type 2
951 status
= TIReadVendorRequestSync (serial
->serial
->dev
,
952 UMPC_MEMORY_READ
, // Request
953 DTK_ADDR_SPACE_I2C_TYPE_II
, // wValue (Address type)
955 &data
, // TransferBuffer
956 0x01); // TransferBufferLength
958 dbg ("%s - read 2 status error = %d", __func__
, status
);
960 dbg ("%s - read 2 data = 0x%x", __func__
, data
);
961 if ((!status
) && (data
== UMP5152
|| data
== UMP3410
)) {
962 dbg ("%s - ROM_TYPE_II", __func__
);
963 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
967 // Try to read type 3
968 status
= TIReadVendorRequestSync (serial
->serial
->dev
,
969 UMPC_MEMORY_READ
, // Request
970 DTK_ADDR_SPACE_I2C_TYPE_III
, // wValue (Address type)
972 &data
, // TransferBuffer
973 0x01); // TransferBufferLength
975 dbg ("%s - read 3 status error = %d", __func__
, status
);
977 dbg ("%s - read 2 data = 0x%x", __func__
, data
);
978 if ((!status
) && (data
== UMP5152
|| data
== UMP3410
)) {
979 dbg ("%s - ROM_TYPE_III", __func__
);
980 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_III
;
984 dbg ("%s - Unknown", __func__
);
985 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
989 static int TISendBulkTransferSync (struct usb_serial
*serial
, void *buffer
, int length
, int *num_sent
)
993 status
= usb_bulk_msg (serial
->dev
,
994 usb_sndbulkpipe(serial
->dev
,
995 serial
->port
[0]->bulk_out_endpointAddress
),
1003 /* Download given firmware image to the device (IN BOOT MODE) */
1004 static int TIDownloadCodeImage (struct edgeport_serial
*serial
, __u8
*image
, int image_length
)
1011 // Transfer firmware image
1012 for (pos
= 0; pos
< image_length
; ) {
1013 // Read the next buffer from file
1014 transfer
= image_length
- pos
;
1015 if (transfer
> EDGE_FW_BULK_MAX_PACKET_SIZE
)
1016 transfer
= EDGE_FW_BULK_MAX_PACKET_SIZE
;
1019 status
= TISendBulkTransferSync (serial
->serial
, &image
[pos
], transfer
, &done
);
1022 // Advance buffer pointer
1030 static int TIConfigureBootDevice (struct usb_device
*dev
)
1036 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
1038 * This routine downloads the main operating code into the TI5052, using the
1039 * boot code already burned into E2PROM or ROM.
1041 static int TIDownloadFirmware (struct edgeport_serial
*serial
)
1043 struct device
*dev
= &serial
->serial
->dev
->dev
;
1046 struct edge_ti_manuf_descriptor
*ti_manuf_desc
;
1047 struct usb_interface_descriptor
*interface
;
1048 int download_cur_ver
;
1049 int download_new_ver
;
1051 /* This routine is entered by both the BOOT mode and the Download mode
1052 * We can determine which code is running by the reading the config
1053 * descriptor and if we have only one bulk pipe it is in boot mode
1055 serial
->product_info
.hardware_type
= HARDWARE_TYPE_TIUMP
;
1057 /* Default to type 2 i2c */
1058 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
1060 status
= TIChooseConfiguration (serial
->serial
->dev
);
1064 interface
= &serial
->serial
->interface
->cur_altsetting
->desc
;
1066 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 mode
1072 if (interface
->bNumEndpoints
> 1)
1073 serial
->product_info
.TiMode
= TI_MODE_DOWNLOAD
;
1075 // Otherwise we will remain in configuring mode
1076 serial
->product_info
.TiMode
= TI_MODE_CONFIGURING
;
1078 // Save Download Version Number
1079 OperationalCodeImageVersion
.MajorVersion
= PagableOperationalCodeImageVersion
.MajorVersion
;
1080 OperationalCodeImageVersion
.MinorVersion
= PagableOperationalCodeImageVersion
.MinorVersion
;
1081 OperationalCodeImageVersion
.BuildNumber
= PagableOperationalCodeImageVersion
.BuildNumber
;
1083 /********************************************************************/
1085 /********************************************************************/
1086 if (serial
->product_info
.TiMode
== TI_MODE_DOWNLOAD
) {
1087 struct ti_i2c_desc
*rom_desc
;
1089 dbg("%s - RUNNING IN DOWNLOAD MODE", __func__
);
1091 status
= TiValidateI2cImage (serial
);
1093 dbg("%s - DOWNLOAD MODE -- BAD I2C", __func__
);
1097 /* Validate Hardware version number
1098 * Read Manufacturing Descriptor from TI Based Edgeport
1100 ti_manuf_desc
= kmalloc (sizeof (*ti_manuf_desc
), GFP_KERNEL
);
1101 if (!ti_manuf_desc
) {
1102 dev_err (dev
, "%s - out of memory.\n", __func__
);
1105 status
= TIReadManufDescriptor (serial
, (__u8
*)ti_manuf_desc
);
1107 kfree (ti_manuf_desc
);
1111 // Check version number of ION descriptor
1112 if (!ignore_cpu_rev
&& TI_GET_CPU_REVISION(ti_manuf_desc
->CpuRev_BoardRev
) < 2) {
1113 dbg ( "%s - Wrong CPU Rev %d (Must be 2)", __func__
,
1114 TI_GET_CPU_REVISION(ti_manuf_desc
->CpuRev_BoardRev
));
1115 kfree (ti_manuf_desc
);
1119 rom_desc
= kmalloc (sizeof (*rom_desc
), GFP_KERNEL
);
1121 dev_err (dev
, "%s - out of memory.\n", __func__
);
1122 kfree (ti_manuf_desc
);
1126 // Search for type 2 record (firmware record)
1127 if ((start_address
= TIGetDescriptorAddress (serial
, I2C_DESC_TYPE_FIRMWARE_BASIC
, rom_desc
)) != 0) {
1128 struct ti_i2c_firmware_rec
*firmware_version
;
1131 dbg ("%s - Found Type FIRMWARE (Type 2) record", __func__
);
1133 firmware_version
= kmalloc (sizeof (*firmware_version
), GFP_KERNEL
);
1134 if (!firmware_version
) {
1135 dev_err (dev
, "%s - out of memory.\n", __func__
);
1137 kfree (ti_manuf_desc
);
1141 // Validate version number
1142 // Read the descriptor data
1143 status
= TIReadRom (serial
,
1144 start_address
+sizeof(struct ti_i2c_desc
),
1145 sizeof(struct ti_i2c_firmware_rec
),
1146 (__u8
*)firmware_version
);
1148 kfree (firmware_version
);
1150 kfree (ti_manuf_desc
);
1154 // Check version number of download with current version in I2c
1155 download_cur_ver
= (firmware_version
->Ver_Major
<< 8) +
1156 (firmware_version
->Ver_Minor
);
1157 download_new_ver
= (OperationalCodeImageVersion
.MajorVersion
<< 8) +
1158 (OperationalCodeImageVersion
.MinorVersion
);
1160 dbg ("%s - >>>Firmware Versions Device %d.%d Driver %d.%d",
1162 firmware_version
->Ver_Major
,
1163 firmware_version
->Ver_Minor
,
1164 OperationalCodeImageVersion
.MajorVersion
,
1165 OperationalCodeImageVersion
.MinorVersion
);
1167 // Check if we have an old version in the I2C and update if necessary
1168 if (download_cur_ver
!= download_new_ver
) {
1169 dbg ("%s - Update I2C Download from %d.%d to %d.%d",
1171 firmware_version
->Ver_Major
,
1172 firmware_version
->Ver_Minor
,
1173 OperationalCodeImageVersion
.MajorVersion
,
1174 OperationalCodeImageVersion
.MinorVersion
);
1176 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1177 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1178 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1179 // And finally when the device comes back up in download mode the driver will cause
1180 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1181 // the record type from 0xf2 to 0x02.
1183 record
= I2C_DESC_TYPE_FIRMWARE_BLANK
;
1185 // Change the I2C Firmware record type to 0xf2 to trigger an update
1186 status
= TIWriteRom (serial
,
1191 kfree (firmware_version
);
1193 kfree (ti_manuf_desc
);
1197 // verify the write -- must do this in order for write to
1198 // complete before we do the hardware reset
1199 status
= TIReadRom (serial
,
1205 kfree (firmware_version
);
1207 kfree (ti_manuf_desc
);
1211 if (record
!= I2C_DESC_TYPE_FIRMWARE_BLANK
) {
1212 dev_err (dev
, "%s - error resetting device\n", __func__
);
1213 kfree (firmware_version
);
1215 kfree (ti_manuf_desc
);
1219 dbg ("%s - HARDWARE RESET", __func__
);
1221 // Reset UMP -- Back to BOOT MODE
1222 status
= TISendVendorRequestSync (serial
->serial
->dev
,
1223 UMPC_HARDWARE_RESET
, // Request
1226 NULL
, // TransferBuffer
1227 0); // TransferBufferLength
1229 dbg ( "%s - HARDWARE RESET return %d", __func__
, status
);
1231 /* return an error on purpose. */
1232 kfree (firmware_version
);
1234 kfree (ti_manuf_desc
);
1237 kfree (firmware_version
);
1239 // Search for type 0xF2 record (firmware blank record)
1240 else if ((start_address
= TIGetDescriptorAddress (serial
, I2C_DESC_TYPE_FIRMWARE_BLANK
, rom_desc
)) != 0) {
1241 #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + sizeof(struct ti_i2c_firmware_rec))
1245 header
= kmalloc (HEADER_SIZE
, GFP_KERNEL
);
1247 dev_err (dev
, "%s - out of memory.\n", __func__
);
1249 kfree (ti_manuf_desc
);
1253 vheader
= kmalloc (HEADER_SIZE
, GFP_KERNEL
);
1255 dev_err (dev
, "%s - out of memory.\n", __func__
);
1258 kfree (ti_manuf_desc
);
1262 dbg ("%s - Found Type BLANK FIRMWARE (Type F2) record", __func__
);
1264 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1265 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1266 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1267 // And finally when the device comes back up in download mode the driver will cause
1268 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1269 // the record type from 0xf2 to 0x02.
1270 status
= BuildI2CFirmwareHeader(header
, dev
);
1275 kfree (ti_manuf_desc
);
1279 // Update I2C with type 0xf2 record with correct size and checksum
1280 status
= TIWriteRom (serial
,
1288 kfree (ti_manuf_desc
);
1292 // verify the write -- must do this in order for write to
1293 // complete before we do the hardware reset
1294 status
= TIReadRom (serial
,
1300 dbg ("%s - can't read header back", __func__
);
1304 kfree (ti_manuf_desc
);
1307 if (memcmp(vheader
, header
, HEADER_SIZE
)) {
1308 dbg ("%s - write download record failed", __func__
);
1312 kfree (ti_manuf_desc
);
1319 dbg ("%s - Start firmware update", __func__
);
1321 // Tell firmware to copy download image into I2C
1322 status
= TISendVendorRequestSync (serial
->serial
->dev
,
1323 UMPC_COPY_DNLD_TO_I2C
, // Request
1326 NULL
, // TransferBuffer
1327 0); // TransferBufferLength
1329 dbg ("%s - Update complete 0x%x", __func__
, status
);
1331 dev_err (dev
, "%s - UMPC_COPY_DNLD_TO_I2C failed\n", __func__
);
1333 kfree (ti_manuf_desc
);
1338 // The device is running the download code
1340 kfree (ti_manuf_desc
);
1344 /********************************************************************/
1346 /********************************************************************/
1347 dbg("%s - RUNNING IN BOOT MODE", __func__
);
1349 // Configure the TI device so we can use the BULK pipes for download
1350 status
= TIConfigureBootDevice (serial
->serial
->dev
);
1354 if (le16_to_cpu(serial
->serial
->dev
->descriptor
.idVendor
) != USB_VENDOR_ID_ION
) {
1355 dbg ("%s - VID = 0x%x", __func__
,
1356 le16_to_cpu(serial
->serial
->dev
->descriptor
.idVendor
));
1357 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
1358 goto StayInBootMode
;
1361 // We have an ION device (I2c Must be programmed)
1362 // Determine I2C image type
1363 if (TIGetI2cTypeInBootMode(serial
)) {
1364 goto StayInBootMode
;
1367 // Registry variable set?
1368 if (TIStayInBootMode
) {
1369 dbg ("%s - TIStayInBootMode", __func__
);
1370 goto StayInBootMode
;
1373 // Check for ION Vendor ID and that the I2C is valid
1374 if (!TiValidateI2cImage(serial
)) {
1375 struct ti_i2c_image_header
*header
;
1381 /* Validate Hardware version number
1382 * Read Manufacturing Descriptor from TI Based Edgeport
1384 ti_manuf_desc
= kmalloc (sizeof (*ti_manuf_desc
), GFP_KERNEL
);
1385 if (!ti_manuf_desc
) {
1386 dev_err (dev
, "%s - out of memory.\n", __func__
);
1389 status
= TIReadManufDescriptor (serial
, (__u8
*)ti_manuf_desc
);
1391 kfree (ti_manuf_desc
);
1392 goto StayInBootMode
;
1395 // Check for version 2
1396 if (!ignore_cpu_rev
&& TI_GET_CPU_REVISION(ti_manuf_desc
->CpuRev_BoardRev
) < 2) {
1397 dbg ("%s - Wrong CPU Rev %d (Must be 2)", __func__
,
1398 TI_GET_CPU_REVISION(ti_manuf_desc
->CpuRev_BoardRev
));
1399 kfree (ti_manuf_desc
);
1400 goto StayInBootMode
;
1403 kfree (ti_manuf_desc
);
1405 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1406 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1407 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1408 // And finally when the device comes back up in download mode the driver will cause
1409 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1410 // the record type from 0xf2 to 0x02.
1413 * Do we really have to copy the whole firmware image,
1414 * or could we do this in place!
1417 // Allocate a 15.5k buffer + 3 byte header
1418 buffer_size
= (((1024 * 16) - 512) + sizeof(struct ti_i2c_image_header
));
1419 buffer
= kmalloc (buffer_size
, GFP_KERNEL
);
1421 dev_err (dev
, "%s - out of memory\n", __func__
);
1425 // Initialize the buffer to 0xff (pad the buffer)
1426 memset (buffer
, 0xff, buffer_size
);
1428 memcpy (buffer
, &PagableOperationalCodeImage
[0], PagableOperationalCodeSize
);
1430 for(i
= sizeof(struct ti_i2c_image_header
); i
< buffer_size
; i
++) {
1431 cs
= (__u8
)(cs
+ buffer
[i
]);
1434 header
= (struct ti_i2c_image_header
*)buffer
;
1436 // update length and checksum after padding
1437 header
->Length
= cpu_to_le16((__u16
)(buffer_size
- sizeof(struct ti_i2c_image_header
)));
1438 header
->CheckSum
= cs
;
1440 // Download the operational code
1441 dbg ("%s - Downloading operational code image (TI UMP)", __func__
);
1442 status
= TIDownloadCodeImage (serial
, buffer
, buffer_size
);
1447 dbg ("%s - Error downloading operational code image", __func__
);
1451 // Device will reboot
1452 serial
->product_info
.TiMode
= TI_MODE_TRANSITIONING
;
1454 dbg ("%s - Download successful -- Device rebooting...", __func__
);
1456 /* return an error on purpose */
1461 // Eprom is invalid or blank stay in boot mode
1462 dbg("%s - STAYING IN BOOT MODE", __func__
);
1463 serial
->product_info
.TiMode
= TI_MODE_BOOT
;
1469 static int TISetDtr (struct edgeport_port
*port
)
1471 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1473 dbg ("%s", __func__
);
1474 port
->shadow_mcr
|= MCR_DTR
;
1476 return TIWriteCommandSync (port
->port
->serial
->dev
,
1478 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1484 static int TIClearDtr (struct edgeport_port
*port
)
1486 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1488 dbg ("%s", __func__
);
1489 port
->shadow_mcr
&= ~MCR_DTR
;
1491 return TIWriteCommandSync (port
->port
->serial
->dev
,
1493 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1499 static int TISetRts (struct edgeport_port
*port
)
1501 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1503 dbg ("%s", __func__
);
1504 port
->shadow_mcr
|= MCR_RTS
;
1506 return TIWriteCommandSync (port
->port
->serial
->dev
,
1508 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1514 static int TIClearRts (struct edgeport_port
*port
)
1516 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1518 dbg ("%s", __func__
);
1519 port
->shadow_mcr
&= ~MCR_RTS
;
1521 return TIWriteCommandSync (port
->port
->serial
->dev
,
1523 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1529 static int TISetLoopBack (struct edgeport_port
*port
)
1531 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1533 dbg ("%s", __func__
);
1535 return TIWriteCommandSync (port
->port
->serial
->dev
,
1536 UMPC_SET_CLR_LOOPBACK
,
1537 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1543 static int TIClearLoopBack (struct edgeport_port
*port
)
1545 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1547 dbg ("%s", __func__
);
1549 return TIWriteCommandSync (port
->port
->serial
->dev
,
1550 UMPC_SET_CLR_LOOPBACK
,
1551 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1557 static int TISetBreak (struct edgeport_port
*port
)
1559 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1561 dbg ("%s", __func__
);
1563 return TIWriteCommandSync (port
->port
->serial
->dev
,
1565 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1571 static int TIClearBreak (struct edgeport_port
*port
)
1573 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1575 dbg ("%s", __func__
);
1577 return TIWriteCommandSync (port
->port
->serial
->dev
,
1579 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1585 static int TIRestoreMCR (struct edgeport_port
*port
, __u8 mcr
)
1589 dbg ("%s - %x", __func__
, mcr
);
1592 status
= TISetDtr (port
);
1594 status
= TIClearDtr (port
);
1600 status
= TISetRts (port
);
1602 status
= TIClearRts (port
);
1607 if (mcr
& MCR_LOOPBACK
)
1608 status
= TISetLoopBack (port
);
1610 status
= TIClearLoopBack (port
);
1617 /* Convert TI LSR to standard UART flags */
1618 static __u8
MapLineStatus (__u8 ti_lsr
)
1622 #define MAP_FLAG(flagUmp, flagUart) \
1623 if (ti_lsr & flagUmp) \
1626 MAP_FLAG(UMP_UART_LSR_OV_MASK
, LSR_OVER_ERR
) /* overrun */
1627 MAP_FLAG(UMP_UART_LSR_PE_MASK
, LSR_PAR_ERR
) /* parity error */
1628 MAP_FLAG(UMP_UART_LSR_FE_MASK
, LSR_FRM_ERR
) /* framing error */
1629 MAP_FLAG(UMP_UART_LSR_BR_MASK
, LSR_BREAK
) /* break detected */
1630 MAP_FLAG(UMP_UART_LSR_RX_MASK
, LSR_RX_AVAIL
) /* receive data available */
1631 MAP_FLAG(UMP_UART_LSR_TX_MASK
, LSR_TX_EMPTY
) /* transmit holding register empty */
1638 static void handle_new_msr (struct edgeport_port
*edge_port
, __u8 msr
)
1640 struct async_icount
*icount
;
1641 struct tty_struct
*tty
;
1643 dbg ("%s - %02x", __func__
, msr
);
1645 if (msr
& (EDGEPORT_MSR_DELTA_CTS
| EDGEPORT_MSR_DELTA_DSR
| EDGEPORT_MSR_DELTA_RI
| EDGEPORT_MSR_DELTA_CD
)) {
1646 icount
= &edge_port
->icount
;
1648 /* update input line counters */
1649 if (msr
& EDGEPORT_MSR_DELTA_CTS
)
1651 if (msr
& EDGEPORT_MSR_DELTA_DSR
)
1653 if (msr
& EDGEPORT_MSR_DELTA_CD
)
1655 if (msr
& EDGEPORT_MSR_DELTA_RI
)
1657 wake_up_interruptible (&edge_port
->delta_msr_wait
);
1660 /* Save the new modem status */
1661 edge_port
->shadow_msr
= msr
& 0xf0;
1663 tty
= edge_port
->port
->tty
;
1664 /* handle CTS flow control */
1665 if (tty
&& C_CRTSCTS(tty
)) {
1666 if (msr
& EDGEPORT_MSR_CTS
) {
1667 tty
->hw_stopped
= 0;
1670 tty
->hw_stopped
= 1;
1677 static void handle_new_lsr (struct edgeport_port
*edge_port
, int lsr_data
, __u8 lsr
, __u8 data
)
1679 struct async_icount
*icount
;
1680 __u8 new_lsr
= (__u8
)(lsr
& (__u8
)(LSR_OVER_ERR
| LSR_PAR_ERR
| LSR_FRM_ERR
| LSR_BREAK
));
1682 dbg ("%s - %02x", __func__
, new_lsr
);
1684 edge_port
->shadow_lsr
= lsr
;
1686 if (new_lsr
& LSR_BREAK
) {
1688 * Parity and Framing errors only count if they
1689 * occur exclusive of a break being received.
1691 new_lsr
&= (__u8
)(LSR_OVER_ERR
| LSR_BREAK
);
1694 /* Place LSR data byte into Rx buffer */
1695 if (lsr_data
&& edge_port
->port
->tty
)
1696 edge_tty_recv(&edge_port
->port
->dev
, edge_port
->port
->tty
, &data
, 1);
1698 /* update input line counters */
1699 icount
= &edge_port
->icount
;
1700 if (new_lsr
& LSR_BREAK
)
1702 if (new_lsr
& LSR_OVER_ERR
)
1704 if (new_lsr
& LSR_PAR_ERR
)
1706 if (new_lsr
& LSR_FRM_ERR
)
1711 static void edge_interrupt_callback (struct urb
*urb
)
1713 struct edgeport_serial
*edge_serial
= urb
->context
;
1714 struct usb_serial_port
*port
;
1715 struct edgeport_port
*edge_port
;
1716 unsigned char *data
= urb
->transfer_buffer
;
1717 int length
= urb
->actual_length
;
1723 int status
= urb
->status
;
1725 dbg("%s", __func__
);
1734 /* this urb is terminated, clean up */
1735 dbg("%s - urb shutting down with status: %d",
1739 dev_err(&urb
->dev
->dev
, "%s - nonzero urb status received: "
1740 "%d\n", __func__
, status
);
1745 dbg ("%s - no data in urb", __func__
);
1749 usb_serial_debug_data(debug
, &edge_serial
->serial
->dev
->dev
, __func__
, length
, data
);
1752 dbg ("%s - expecting packet of size 2, got %d", __func__
, length
);
1756 port_number
= TIUMP_GET_PORT_FROM_CODE (data
[0]);
1757 function
= TIUMP_GET_FUNC_FROM_CODE (data
[0]);
1758 dbg ("%s - port_number %d, function %d, info 0x%x",
1759 __func__
, port_number
, function
, data
[1]);
1760 port
= edge_serial
->serial
->port
[port_number
];
1761 edge_port
= usb_get_serial_port_data(port
);
1763 dbg ("%s - edge_port not found", __func__
);
1767 case TIUMP_INTERRUPT_CODE_LSR
:
1768 lsr
= MapLineStatus(data
[1]);
1769 if (lsr
& UMP_UART_LSR_DATA_MASK
) {
1770 /* Save the LSR event for bulk read completion routine */
1771 dbg ("%s - LSR Event Port %u LSR Status = %02x",
1772 __func__
, port_number
, lsr
);
1773 edge_port
->lsr_event
= 1;
1774 edge_port
->lsr_mask
= lsr
;
1776 dbg ("%s - ===== Port %d LSR Status = %02x ======",
1777 __func__
, port_number
, lsr
);
1778 handle_new_lsr (edge_port
, 0, lsr
, 0);
1782 case TIUMP_INTERRUPT_CODE_MSR
: // MSR
1783 /* Copy MSR from UMP */
1785 dbg ("%s - ===== Port %u MSR Status = %02x ======\n",
1786 __func__
, port_number
, msr
);
1787 handle_new_msr (edge_port
, msr
);
1791 dev_err (&urb
->dev
->dev
, "%s - Unknown Interrupt code from UMP %x\n",
1798 retval
= usb_submit_urb (urb
, GFP_ATOMIC
);
1800 dev_err (&urb
->dev
->dev
, "%s - usb_submit_urb failed with result %d\n",
1804 static void edge_bulk_in_callback (struct urb
*urb
)
1806 struct edgeport_port
*edge_port
= urb
->context
;
1807 unsigned char *data
= urb
->transfer_buffer
;
1808 struct tty_struct
*tty
;
1811 int status
= urb
->status
;
1813 dbg("%s", __func__
);
1822 /* this urb is terminated, clean up */
1823 dbg("%s - urb shutting down with status: %d",
1827 dev_err (&urb
->dev
->dev
,"%s - nonzero read bulk status received: %d\n",
1831 if (status
== -EPIPE
)
1835 dev_err(&urb
->dev
->dev
,"%s - stopping read!\n", __func__
);
1839 port_number
= edge_port
->port
->number
- edge_port
->port
->serial
->minor
;
1841 if (edge_port
->lsr_event
) {
1842 edge_port
->lsr_event
= 0;
1843 dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
1844 __func__
, port_number
, edge_port
->lsr_mask
, *data
);
1845 handle_new_lsr (edge_port
, 1, edge_port
->lsr_mask
, *data
);
1846 /* Adjust buffer length/pointer */
1847 --urb
->actual_length
;
1851 tty
= edge_port
->port
->tty
;
1852 if (tty
&& urb
->actual_length
) {
1853 usb_serial_debug_data(debug
, &edge_port
->port
->dev
, __func__
, urb
->actual_length
, data
);
1855 if (edge_port
->close_pending
) {
1856 dbg ("%s - close is pending, dropping data on the floor.", __func__
);
1858 edge_tty_recv(&edge_port
->port
->dev
, tty
, data
, urb
->actual_length
);
1860 edge_port
->icount
.rx
+= urb
->actual_length
;
1864 /* continue read unless stopped */
1865 spin_lock(&edge_port
->ep_lock
);
1866 if (edge_port
->ep_read_urb_state
== EDGE_READ_URB_RUNNING
) {
1867 urb
->dev
= edge_port
->port
->serial
->dev
;
1868 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
1869 } else if (edge_port
->ep_read_urb_state
== EDGE_READ_URB_STOPPING
) {
1870 edge_port
->ep_read_urb_state
= EDGE_READ_URB_STOPPED
;
1872 spin_unlock(&edge_port
->ep_lock
);
1874 dev_err (&urb
->dev
->dev
, "%s - usb_submit_urb failed with result %d\n",
1878 static void edge_tty_recv(struct device
*dev
, struct tty_struct
*tty
, unsigned char *data
, int length
)
1883 cnt
= tty_buffer_request_room(tty
, length
);
1885 dev_err(dev
, "%s - dropping data, %d bytes lost\n",
1886 __func__
, length
- cnt
);
1890 tty_insert_flip_string(tty
, data
, cnt
);
1893 } while (length
> 0);
1895 tty_flip_buffer_push(tty
);
1898 static void edge_bulk_out_callback (struct urb
*urb
)
1900 struct usb_serial_port
*port
= urb
->context
;
1901 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
1902 int status
= urb
->status
;
1904 dbg ("%s - port %d", __func__
, port
->number
);
1906 edge_port
->ep_write_urb_in_use
= 0;
1915 /* this urb is terminated, clean up */
1916 dbg("%s - urb shutting down with status: %d",
1920 dev_err(&urb
->dev
->dev
, "%s - nonzero write bulk status "
1921 "received: %d\n", __func__
, status
);
1924 /* send any buffered data */
1928 static int edge_open (struct usb_serial_port
*port
, struct file
* filp
)
1930 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
1931 struct edgeport_serial
*edge_serial
;
1932 struct usb_device
*dev
;
1937 u8 transaction_timeout
;
1939 dbg("%s - port %d", __func__
, port
->number
);
1941 if (edge_port
== NULL
)
1944 port
->tty
->low_latency
= low_latency
;
1946 port_number
= port
->number
- port
->serial
->minor
;
1947 switch (port_number
) {
1949 edge_port
->uart_base
= UMPMEM_BASE_UART1
;
1950 edge_port
->dma_address
= UMPD_OEDB1_ADDRESS
;
1953 edge_port
->uart_base
= UMPMEM_BASE_UART2
;
1954 edge_port
->dma_address
= UMPD_OEDB2_ADDRESS
;
1957 dev_err (&port
->dev
, "Unknown port number!!!\n");
1961 dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
1962 __func__
, port_number
, edge_port
->uart_base
, edge_port
->dma_address
);
1964 dev
= port
->serial
->dev
;
1966 memset (&(edge_port
->icount
), 0x00, sizeof(edge_port
->icount
));
1967 init_waitqueue_head (&edge_port
->delta_msr_wait
);
1969 /* turn off loopback */
1970 status
= TIClearLoopBack (edge_port
);
1972 dev_err(&port
->dev
,"%s - cannot send clear loopback command, %d\n",
1977 /* set up the port settings */
1978 edge_set_termios (port
, port
->tty
->termios
);
1980 /* open up the port */
1982 /* milliseconds to timeout for DMA transfer */
1983 transaction_timeout
= 2;
1985 edge_port
->ump_read_timeout
= max (20, ((transaction_timeout
* 3) / 2) );
1987 // milliseconds to timeout for DMA transfer
1988 open_settings
= (u8
)(UMP_DMA_MODE_CONTINOUS
|
1989 UMP_PIPE_TRANS_TIMEOUT_ENA
|
1990 (transaction_timeout
<< 2));
1992 dbg ("%s - Sending UMPC_OPEN_PORT", __func__
);
1994 /* Tell TI to open and start the port */
1995 status
= TIWriteCommandSync (dev
,
1997 (u8
)(UMPM_UART1_PORT
+ port_number
),
2002 dev_err(&port
->dev
,"%s - cannot send open command, %d\n", __func__
, status
);
2006 /* Start the DMA? */
2007 status
= TIWriteCommandSync (dev
,
2009 (u8
)(UMPM_UART1_PORT
+ port_number
),
2014 dev_err(&port
->dev
,"%s - cannot send start DMA command, %d\n", __func__
, status
);
2018 /* Clear TX and RX buffers in UMP */
2019 status
= TIPurgeDataSync (port
, UMP_PORT_DIR_OUT
| UMP_PORT_DIR_IN
);
2021 dev_err(&port
->dev
,"%s - cannot send clear buffers command, %d\n", __func__
, status
);
2025 /* Read Initial MSR */
2026 status
= TIReadVendorRequestSync (dev
,
2027 UMPC_READ_MSR
, // Request
2029 (__u16
)(UMPM_UART1_PORT
+ port_number
), // wIndex (Address)
2030 &edge_port
->shadow_msr
, // TransferBuffer
2031 1); // TransferBufferLength
2033 dev_err(&port
->dev
,"%s - cannot send read MSR command, %d\n", __func__
, status
);
2037 dbg ("ShadowMSR 0x%X", edge_port
->shadow_msr
);
2039 /* Set Initial MCR */
2040 edge_port
->shadow_mcr
= MCR_RTS
| MCR_DTR
;
2041 dbg ("ShadowMCR 0x%X", edge_port
->shadow_mcr
);
2043 edge_serial
= edge_port
->edge_serial
;
2044 if (mutex_lock_interruptible(&edge_serial
->es_lock
))
2045 return -ERESTARTSYS
;
2046 if (edge_serial
->num_ports_open
== 0) {
2047 /* we are the first port to be opened, let's post the interrupt urb */
2048 urb
= edge_serial
->serial
->port
[0]->interrupt_in_urb
;
2050 dev_err (&port
->dev
, "%s - no interrupt urb present, exiting\n", __func__
);
2052 goto release_es_lock
;
2054 urb
->complete
= edge_interrupt_callback
;
2055 urb
->context
= edge_serial
;
2057 status
= usb_submit_urb (urb
, GFP_KERNEL
);
2059 dev_err (&port
->dev
, "%s - usb_submit_urb failed with value %d\n", __func__
, status
);
2060 goto release_es_lock
;
2065 * reset the data toggle on the bulk endpoints to work around bug in
2066 * host controllers where things get out of sync some times
2068 usb_clear_halt (dev
, port
->write_urb
->pipe
);
2069 usb_clear_halt (dev
, port
->read_urb
->pipe
);
2071 /* start up our bulk read urb */
2072 urb
= port
->read_urb
;
2074 dev_err (&port
->dev
, "%s - no read urb present, exiting\n", __func__
);
2076 goto unlink_int_urb
;
2078 edge_port
->ep_read_urb_state
= EDGE_READ_URB_RUNNING
;
2079 urb
->complete
= edge_bulk_in_callback
;
2080 urb
->context
= edge_port
;
2082 status
= usb_submit_urb (urb
, GFP_KERNEL
);
2084 dev_err (&port
->dev
, "%s - read bulk usb_submit_urb failed with value %d\n", __func__
, status
);
2085 goto unlink_int_urb
;
2088 ++edge_serial
->num_ports_open
;
2090 dbg("%s - exited", __func__
);
2092 goto release_es_lock
;
2095 if (edge_port
->edge_serial
->num_ports_open
== 0)
2096 usb_kill_urb(port
->serial
->port
[0]->interrupt_in_urb
);
2098 mutex_unlock(&edge_serial
->es_lock
);
2102 static void edge_close (struct usb_serial_port
*port
, struct file
*filp
)
2104 struct edgeport_serial
*edge_serial
;
2105 struct edgeport_port
*edge_port
;
2109 dbg("%s - port %d", __func__
, port
->number
);
2111 edge_serial
= usb_get_serial_data(port
->serial
);
2112 edge_port
= usb_get_serial_port_data(port
);
2113 if ((edge_serial
== NULL
) || (edge_port
== NULL
))
2116 /* The bulkreadcompletion routine will check
2117 * this flag and dump add read data */
2118 edge_port
->close_pending
= 1;
2120 /* chase the port close and flush */
2121 TIChasePort (edge_port
, (HZ
*closing_wait
)/100, 1);
2123 usb_kill_urb(port
->read_urb
);
2124 usb_kill_urb(port
->write_urb
);
2125 edge_port
->ep_write_urb_in_use
= 0;
2127 /* assuming we can still talk to the device,
2128 * send a close port command to it */
2129 dbg("%s - send umpc_close_port", __func__
);
2130 port_number
= port
->number
- port
->serial
->minor
;
2131 status
= TIWriteCommandSync (port
->serial
->dev
,
2133 (__u8
)(UMPM_UART1_PORT
+ port_number
),
2137 mutex_lock(&edge_serial
->es_lock
);
2138 --edge_port
->edge_serial
->num_ports_open
;
2139 if (edge_port
->edge_serial
->num_ports_open
<= 0) {
2140 /* last port is now closed, let's shut down our interrupt urb */
2141 usb_kill_urb(port
->serial
->port
[0]->interrupt_in_urb
);
2142 edge_port
->edge_serial
->num_ports_open
= 0;
2144 mutex_unlock(&edge_serial
->es_lock
);
2145 edge_port
->close_pending
= 0;
2147 dbg("%s - exited", __func__
);
2150 static int edge_write (struct usb_serial_port
*port
, const unsigned char *data
, int count
)
2152 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2153 unsigned long flags
;
2155 dbg("%s - port %d", __func__
, port
->number
);
2158 dbg("%s - write request of 0 bytes", __func__
);
2162 if (edge_port
== NULL
)
2164 if (edge_port
->close_pending
== 1)
2167 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2168 count
= edge_buf_put(edge_port
->ep_out_buf
, data
, count
);
2169 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2176 static void edge_send(struct usb_serial_port
*port
)
2179 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2180 struct tty_struct
*tty
= port
->tty
;
2181 unsigned long flags
;
2184 dbg("%s - port %d", __func__
, port
->number
);
2186 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2188 if (edge_port
->ep_write_urb_in_use
) {
2189 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2193 count
= edge_buf_get(edge_port
->ep_out_buf
,
2194 port
->write_urb
->transfer_buffer
,
2195 port
->bulk_out_size
);
2198 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2202 edge_port
->ep_write_urb_in_use
= 1;
2204 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2206 usb_serial_debug_data(debug
, &port
->dev
, __func__
, count
, port
->write_urb
->transfer_buffer
);
2208 /* set up our urb */
2209 usb_fill_bulk_urb (port
->write_urb
, port
->serial
->dev
,
2210 usb_sndbulkpipe (port
->serial
->dev
,
2211 port
->bulk_out_endpointAddress
),
2212 port
->write_urb
->transfer_buffer
, count
,
2213 edge_bulk_out_callback
,
2216 /* send the data out the bulk port */
2217 result
= usb_submit_urb(port
->write_urb
, GFP_ATOMIC
);
2219 dev_err(&port
->dev
, "%s - failed submitting write urb, error %d\n", __func__
, result
);
2220 edge_port
->ep_write_urb_in_use
= 0;
2221 // TODO: reschedule edge_send
2223 edge_port
->icount
.tx
+= count
;
2226 /* wakeup any process waiting for writes to complete */
2227 /* there is now more room in the buffer for new writes */
2229 /* let the tty driver wakeup if it has a special write_wakeup function */
2234 static int edge_write_room (struct usb_serial_port
*port
)
2236 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2238 unsigned long flags
;
2240 dbg("%s - port %d", __func__
, port
->number
);
2242 if (edge_port
== NULL
)
2244 if (edge_port
->close_pending
== 1)
2247 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2248 room
= edge_buf_space_avail(edge_port
->ep_out_buf
);
2249 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2251 dbg("%s - returns %d", __func__
, room
);
2255 static int edge_chars_in_buffer (struct usb_serial_port
*port
)
2257 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2259 unsigned long flags
;
2261 dbg("%s - port %d", __func__
, port
->number
);
2263 if (edge_port
== NULL
)
2265 if (edge_port
->close_pending
== 1)
2268 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2269 chars
= edge_buf_data_avail(edge_port
->ep_out_buf
);
2270 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2272 dbg ("%s - returns %d", __func__
, chars
);
2276 static void edge_throttle (struct usb_serial_port
*port
)
2278 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2279 struct tty_struct
*tty
;
2282 dbg("%s - port %d", __func__
, port
->number
);
2284 if (edge_port
== NULL
)
2289 dbg ("%s - no tty available", __func__
);
2293 /* if we are implementing XON/XOFF, send the stop character */
2295 unsigned char stop_char
= STOP_CHAR(tty
);
2296 status
= edge_write (port
, &stop_char
, 1);
2298 dev_err(&port
->dev
, "%s - failed to write stop character, %d\n", __func__
, status
);
2302 /* if we are implementing RTS/CTS, stop reads */
2303 /* and the Edgeport will clear the RTS line */
2305 stop_read(edge_port
);
2309 static void edge_unthrottle (struct usb_serial_port
*port
)
2311 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2312 struct tty_struct
*tty
;
2315 dbg("%s - port %d", __func__
, port
->number
);
2317 if (edge_port
== NULL
)
2322 dbg ("%s - no tty available", __func__
);
2326 /* if we are implementing XON/XOFF, send the start character */
2328 unsigned char start_char
= START_CHAR(tty
);
2329 status
= edge_write (port
, &start_char
, 1);
2331 dev_err(&port
->dev
, "%s - failed to write start character, %d\n", __func__
, status
);
2335 /* if we are implementing RTS/CTS, restart reads */
2336 /* are the Edgeport will assert the RTS line */
2337 if (C_CRTSCTS(tty
)) {
2338 status
= restart_read(edge_port
);
2340 dev_err(&port
->dev
, "%s - read bulk usb_submit_urb failed with value %d\n", __func__
, status
);
2345 static void stop_read(struct edgeport_port
*edge_port
)
2347 unsigned long flags
;
2349 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2351 if (edge_port
->ep_read_urb_state
== EDGE_READ_URB_RUNNING
)
2352 edge_port
->ep_read_urb_state
= EDGE_READ_URB_STOPPING
;
2353 edge_port
->shadow_mcr
&= ~MCR_RTS
;
2355 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2358 static int restart_read(struct edgeport_port
*edge_port
)
2362 unsigned long flags
;
2364 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2366 if (edge_port
->ep_read_urb_state
== EDGE_READ_URB_STOPPED
) {
2367 urb
= edge_port
->port
->read_urb
;
2368 urb
->complete
= edge_bulk_in_callback
;
2369 urb
->context
= edge_port
;
2370 urb
->dev
= edge_port
->port
->serial
->dev
;
2371 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
2373 edge_port
->ep_read_urb_state
= EDGE_READ_URB_RUNNING
;
2374 edge_port
->shadow_mcr
|= MCR_RTS
;
2376 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2381 static void change_port_settings (struct edgeport_port
*edge_port
, struct ktermios
*old_termios
)
2383 struct ump_uart_config
*config
;
2384 struct tty_struct
*tty
;
2388 int port_number
= edge_port
->port
->number
- edge_port
->port
->serial
->minor
;
2390 dbg("%s - port %d", __func__
, edge_port
->port
->number
);
2392 tty
= edge_port
->port
->tty
;
2394 config
= kmalloc (sizeof (*config
), GFP_KERNEL
);
2396 dev_err (&edge_port
->port
->dev
, "%s - out of memory\n", __func__
);
2400 cflag
= tty
->termios
->c_cflag
;
2404 /* These flags must be set */
2405 config
->wFlags
|= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT
;
2406 config
->wFlags
|= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR
;
2407 config
->bUartMode
= (__u8
)(edge_port
->bUartMode
);
2409 switch (cflag
& CSIZE
) {
2411 config
->bDataBits
= UMP_UART_CHAR5BITS
;
2412 dbg ("%s - data bits = 5", __func__
);
2415 config
->bDataBits
= UMP_UART_CHAR6BITS
;
2416 dbg ("%s - data bits = 6", __func__
);
2419 config
->bDataBits
= UMP_UART_CHAR7BITS
;
2420 dbg ("%s - data bits = 7", __func__
);
2424 config
->bDataBits
= UMP_UART_CHAR8BITS
;
2425 dbg ("%s - data bits = 8", __func__
);
2429 if (cflag
& PARENB
) {
2430 if (cflag
& PARODD
) {
2431 config
->wFlags
|= UMP_MASK_UART_FLAGS_PARITY
;
2432 config
->bParity
= UMP_UART_ODDPARITY
;
2433 dbg("%s - parity = odd", __func__
);
2435 config
->wFlags
|= UMP_MASK_UART_FLAGS_PARITY
;
2436 config
->bParity
= UMP_UART_EVENPARITY
;
2437 dbg("%s - parity = even", __func__
);
2440 config
->bParity
= UMP_UART_NOPARITY
;
2441 dbg("%s - parity = none", __func__
);
2444 if (cflag
& CSTOPB
) {
2445 config
->bStopBits
= UMP_UART_STOPBIT2
;
2446 dbg("%s - stop bits = 2", __func__
);
2448 config
->bStopBits
= UMP_UART_STOPBIT1
;
2449 dbg("%s - stop bits = 1", __func__
);
2452 /* figure out the flow control settings */
2453 if (cflag
& CRTSCTS
) {
2454 config
->wFlags
|= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW
;
2455 config
->wFlags
|= UMP_MASK_UART_FLAGS_RTS_FLOW
;
2456 dbg("%s - RTS/CTS is enabled", __func__
);
2458 dbg("%s - RTS/CTS is disabled", __func__
);
2459 tty
->hw_stopped
= 0;
2460 restart_read(edge_port
);
2463 /* if we are implementing XON/XOFF, set the start and stop character in the device */
2464 if (I_IXOFF(tty
) || I_IXON(tty
)) {
2465 config
->cXon
= START_CHAR(tty
);
2466 config
->cXoff
= STOP_CHAR(tty
);
2468 /* if we are implementing INBOUND XON/XOFF */
2470 config
->wFlags
|= UMP_MASK_UART_FLAGS_IN_X
;
2471 dbg ("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2472 __func__
, config
->cXon
, config
->cXoff
);
2474 dbg ("%s - INBOUND XON/XOFF is disabled", __func__
);
2477 /* if we are implementing OUTBOUND XON/XOFF */
2479 config
->wFlags
|= UMP_MASK_UART_FLAGS_OUT_X
;
2480 dbg ("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2481 __func__
, config
->cXon
, config
->cXoff
);
2483 dbg ("%s - OUTBOUND XON/XOFF is disabled", __func__
);
2487 tty
->termios
->c_cflag
&= ~CMSPAR
;
2489 /* Round the baud rate */
2490 baud
= tty_get_baud_rate(tty
);
2492 /* pick a default, any default... */
2495 tty_encode_baud_rate(tty
, baud
, baud
);
2497 edge_port
->baud_rate
= baud
;
2498 config
->wBaudRate
= (__u16
)((461550L + baud
/2) / baud
);
2500 /* FIXME: Recompute actual baud from divisor here */
2502 dbg ("%s - baud rate = %d, wBaudRate = %d", __func__
, baud
, config
->wBaudRate
);
2504 dbg ("wBaudRate: %d", (int)(461550L / config
->wBaudRate
));
2505 dbg ("wFlags: 0x%x", config
->wFlags
);
2506 dbg ("bDataBits: %d", config
->bDataBits
);
2507 dbg ("bParity: %d", config
->bParity
);
2508 dbg ("bStopBits: %d", config
->bStopBits
);
2509 dbg ("cXon: %d", config
->cXon
);
2510 dbg ("cXoff: %d", config
->cXoff
);
2511 dbg ("bUartMode: %d", config
->bUartMode
);
2513 /* move the word values into big endian mode */
2514 cpu_to_be16s (&config
->wFlags
);
2515 cpu_to_be16s (&config
->wBaudRate
);
2517 status
= TIWriteCommandSync (edge_port
->port
->serial
->dev
,
2519 (__u8
)(UMPM_UART1_PORT
+ port_number
),
2524 dbg ("%s - error %d when trying to write config to device",
2533 static void edge_set_termios (struct usb_serial_port
*port
, struct ktermios
*old_termios
)
2535 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2536 struct tty_struct
*tty
= port
->tty
;
2539 cflag
= tty
->termios
->c_cflag
;
2541 dbg("%s - clfag %08x iflag %08x", __func__
,
2542 tty
->termios
->c_cflag
, tty
->termios
->c_iflag
);
2543 dbg("%s - old clfag %08x old iflag %08x", __func__
,
2544 old_termios
->c_cflag
, old_termios
->c_iflag
);
2546 dbg("%s - port %d", __func__
, port
->number
);
2548 if (edge_port
== NULL
)
2551 /* change the port settings to the new ones specified */
2552 change_port_settings (edge_port
, old_termios
);
2557 static int edge_tiocmset (struct usb_serial_port
*port
, struct file
*file
, unsigned int set
, unsigned int clear
)
2559 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2561 unsigned long flags
;
2563 dbg("%s - port %d", __func__
, port
->number
);
2565 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2566 mcr
= edge_port
->shadow_mcr
;
2567 if (set
& TIOCM_RTS
)
2569 if (set
& TIOCM_DTR
)
2571 if (set
& TIOCM_LOOP
)
2572 mcr
|= MCR_LOOPBACK
;
2574 if (clear
& TIOCM_RTS
)
2576 if (clear
& TIOCM_DTR
)
2578 if (clear
& TIOCM_LOOP
)
2579 mcr
&= ~MCR_LOOPBACK
;
2581 edge_port
->shadow_mcr
= mcr
;
2582 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2584 TIRestoreMCR (edge_port
, mcr
);
2589 static int edge_tiocmget(struct usb_serial_port
*port
, struct file
*file
)
2591 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2592 unsigned int result
= 0;
2595 unsigned long flags
;
2597 dbg("%s - port %d", __func__
, port
->number
);
2599 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2601 msr
= edge_port
->shadow_msr
;
2602 mcr
= edge_port
->shadow_mcr
;
2603 result
= ((mcr
& MCR_DTR
) ? TIOCM_DTR
: 0) /* 0x002 */
2604 | ((mcr
& MCR_RTS
) ? TIOCM_RTS
: 0) /* 0x004 */
2605 | ((msr
& EDGEPORT_MSR_CTS
) ? TIOCM_CTS
: 0) /* 0x020 */
2606 | ((msr
& EDGEPORT_MSR_CD
) ? TIOCM_CAR
: 0) /* 0x040 */
2607 | ((msr
& EDGEPORT_MSR_RI
) ? TIOCM_RI
: 0) /* 0x080 */
2608 | ((msr
& EDGEPORT_MSR_DSR
) ? TIOCM_DSR
: 0); /* 0x100 */
2611 dbg("%s -- %x", __func__
, result
);
2612 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2617 static int get_serial_info (struct edgeport_port
*edge_port
, struct serial_struct __user
*retinfo
)
2619 struct serial_struct tmp
;
2624 memset(&tmp
, 0, sizeof(tmp
));
2626 tmp
.type
= PORT_16550A
;
2627 tmp
.line
= edge_port
->port
->serial
->minor
;
2628 tmp
.port
= edge_port
->port
->number
;
2630 tmp
.flags
= ASYNC_SKIP_TEST
| ASYNC_AUTO_IRQ
;
2631 tmp
.xmit_fifo_size
= edge_port
->port
->bulk_out_size
;
2632 tmp
.baud_base
= 9600;
2633 tmp
.close_delay
= 5*HZ
;
2634 tmp
.closing_wait
= closing_wait
;
2635 // tmp.custom_divisor = state->custom_divisor;
2636 // tmp.hub6 = state->hub6;
2637 // tmp.io_type = state->io_type;
2640 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2645 static int edge_ioctl (struct usb_serial_port
*port
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
2647 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2648 struct async_icount cnow
;
2649 struct async_icount cprev
;
2651 dbg("%s - port %d, cmd = 0x%x", __func__
, port
->number
, cmd
);
2655 dbg("%s - (%d) TIOCINQ", __func__
, port
->number
);
2656 // return get_number_bytes_avail(edge_port, (unsigned int *) arg);
2660 dbg("%s - (%d) TIOCSERGETLSR", __func__
, port
->number
);
2661 // return get_lsr_info(edge_port, (unsigned int *) arg);
2665 dbg("%s - (%d) TIOCGSERIAL", __func__
, port
->number
);
2666 return get_serial_info(edge_port
, (struct serial_struct __user
*) arg
);
2670 dbg("%s - (%d) TIOCSSERIAL", __func__
, port
->number
);
2674 dbg("%s - (%d) TIOCMIWAIT", __func__
, port
->number
);
2675 cprev
= edge_port
->icount
;
2677 interruptible_sleep_on(&edge_port
->delta_msr_wait
);
2678 /* see if a signal did it */
2679 if (signal_pending(current
))
2680 return -ERESTARTSYS
;
2681 cnow
= edge_port
->icount
;
2682 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
2683 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
2684 return -EIO
; /* no change => error */
2685 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
2686 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
2687 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
2688 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
2697 dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__
,
2698 port
->number
, edge_port
->icount
.rx
, edge_port
->icount
.tx
);
2699 if (copy_to_user((void __user
*)arg
, &edge_port
->icount
, sizeof(edge_port
->icount
)))
2704 return -ENOIOCTLCMD
;
2707 static void edge_break (struct usb_serial_port
*port
, int break_state
)
2709 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2712 dbg ("%s - state = %d", __func__
, break_state
);
2714 /* chase the port close */
2715 TIChasePort (edge_port
, 0, 0);
2717 if (break_state
== -1) {
2718 status
= TISetBreak (edge_port
);
2720 status
= TIClearBreak (edge_port
);
2723 dbg ("%s - error %d sending break set/clear command.",
2728 static int edge_startup (struct usb_serial
*serial
)
2730 struct edgeport_serial
*edge_serial
;
2731 struct edgeport_port
*edge_port
;
2732 struct usb_device
*dev
;
2738 /* create our private serial structure */
2739 edge_serial
= kzalloc(sizeof(struct edgeport_serial
), GFP_KERNEL
);
2740 if (edge_serial
== NULL
) {
2741 dev_err(&serial
->dev
->dev
, "%s - Out of memory\n", __func__
);
2744 mutex_init(&edge_serial
->es_lock
);
2745 edge_serial
->serial
= serial
;
2746 usb_set_serial_data(serial
, edge_serial
);
2748 status
= TIDownloadFirmware (edge_serial
);
2750 kfree (edge_serial
);
2754 /* set up our port private structures */
2755 for (i
= 0; i
< serial
->num_ports
; ++i
) {
2756 edge_port
= kzalloc(sizeof(struct edgeport_port
), GFP_KERNEL
);
2757 if (edge_port
== NULL
) {
2758 dev_err(&serial
->dev
->dev
, "%s - Out of memory\n", __func__
);
2761 spin_lock_init(&edge_port
->ep_lock
);
2762 edge_port
->ep_out_buf
= edge_buf_alloc(EDGE_OUT_BUF_SIZE
);
2763 if (edge_port
->ep_out_buf
== NULL
) {
2764 dev_err(&serial
->dev
->dev
, "%s - Out of memory\n", __func__
);
2768 edge_port
->port
= serial
->port
[i
];
2769 edge_port
->edge_serial
= edge_serial
;
2770 usb_set_serial_port_data(serial
->port
[i
], edge_port
);
2771 edge_port
->bUartMode
= default_uart_mode
;
2777 for (--i
; i
>=0; --i
) {
2778 edge_port
= usb_get_serial_port_data(serial
->port
[i
]);
2779 edge_buf_free(edge_port
->ep_out_buf
);
2781 usb_set_serial_port_data(serial
->port
[i
], NULL
);
2783 kfree (edge_serial
);
2784 usb_set_serial_data(serial
, NULL
);
2788 static void edge_shutdown (struct usb_serial
*serial
)
2791 struct edgeport_port
*edge_port
;
2793 dbg ("%s", __func__
);
2795 for (i
= 0; i
< serial
->num_ports
; ++i
) {
2796 edge_port
= usb_get_serial_port_data(serial
->port
[i
]);
2797 edge_remove_sysfs_attrs(edge_port
->port
);
2798 edge_buf_free(edge_port
->ep_out_buf
);
2800 usb_set_serial_port_data(serial
->port
[i
], NULL
);
2802 kfree(usb_get_serial_data(serial
));
2803 usb_set_serial_data(serial
, NULL
);
2807 /* Sysfs Attributes */
2809 static ssize_t
show_uart_mode(struct device
*dev
,
2810 struct device_attribute
*attr
, char *buf
)
2812 struct usb_serial_port
*port
= to_usb_serial_port(dev
);
2813 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2815 return sprintf(buf
, "%d\n", edge_port
->bUartMode
);
2818 static ssize_t
store_uart_mode(struct device
*dev
,
2819 struct device_attribute
*attr
, const char *valbuf
, size_t count
)
2821 struct usb_serial_port
*port
= to_usb_serial_port(dev
);
2822 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2823 unsigned int v
= simple_strtoul(valbuf
, NULL
, 0);
2825 dbg("%s: setting uart_mode = %d", __func__
, v
);
2828 edge_port
->bUartMode
= v
;
2830 dev_err(dev
, "%s - uart_mode %d is invalid\n", __func__
, v
);
2835 static DEVICE_ATTR(uart_mode
, S_IWUSR
| S_IRUGO
, show_uart_mode
, store_uart_mode
);
2837 static int edge_create_sysfs_attrs(struct usb_serial_port
*port
)
2839 return device_create_file(&port
->dev
, &dev_attr_uart_mode
);
2842 static int edge_remove_sysfs_attrs(struct usb_serial_port
*port
)
2844 device_remove_file(&port
->dev
, &dev_attr_uart_mode
);
2849 /* Circular Buffer */
2854 * Allocate a circular buffer and all associated memory.
2857 static struct edge_buf
*edge_buf_alloc(unsigned int size
)
2859 struct edge_buf
*eb
;
2865 eb
= kmalloc(sizeof(struct edge_buf
), GFP_KERNEL
);
2869 eb
->buf_buf
= kmalloc(size
, GFP_KERNEL
);
2870 if (eb
->buf_buf
== NULL
) {
2875 eb
->buf_size
= size
;
2876 eb
->buf_get
= eb
->buf_put
= eb
->buf_buf
;
2885 * Free the buffer and all associated memory.
2888 static void edge_buf_free(struct edge_buf
*eb
)
2900 * Clear out all data in the circular buffer.
2903 static void edge_buf_clear(struct edge_buf
*eb
)
2906 eb
->buf_get
= eb
->buf_put
;
2907 /* equivalent to a get of all data available */
2912 * edge_buf_data_avail
2914 * Return the number of bytes of data available in the circular
2918 static unsigned int edge_buf_data_avail(struct edge_buf
*eb
)
2921 return ((eb
->buf_size
+ eb
->buf_put
- eb
->buf_get
) % eb
->buf_size
);
2928 * edge_buf_space_avail
2930 * Return the number of bytes of space available in the circular
2934 static unsigned int edge_buf_space_avail(struct edge_buf
*eb
)
2937 return ((eb
->buf_size
+ eb
->buf_get
- eb
->buf_put
- 1) % eb
->buf_size
);
2946 * Copy data data from a user buffer and put it into the circular buffer.
2947 * Restrict to the amount of space available.
2949 * Return the number of bytes copied.
2952 static unsigned int edge_buf_put(struct edge_buf
*eb
, const char *buf
,
2961 len
= edge_buf_space_avail(eb
);
2968 len
= eb
->buf_buf
+ eb
->buf_size
- eb
->buf_put
;
2970 memcpy(eb
->buf_put
, buf
, len
);
2971 memcpy(eb
->buf_buf
, buf
+len
, count
- len
);
2972 eb
->buf_put
= eb
->buf_buf
+ count
- len
;
2974 memcpy(eb
->buf_put
, buf
, count
);
2976 eb
->buf_put
+= count
;
2977 else /* count == len */
2978 eb
->buf_put
= eb
->buf_buf
;
2988 * Get data from the circular buffer and copy to the given buffer.
2989 * Restrict to the amount of data available.
2991 * Return the number of bytes copied.
2994 static unsigned int edge_buf_get(struct edge_buf
*eb
, char *buf
,
3003 len
= edge_buf_data_avail(eb
);
3010 len
= eb
->buf_buf
+ eb
->buf_size
- eb
->buf_get
;
3012 memcpy(buf
, eb
->buf_get
, len
);
3013 memcpy(buf
+len
, eb
->buf_buf
, count
- len
);
3014 eb
->buf_get
= eb
->buf_buf
+ count
- len
;
3016 memcpy(buf
, eb
->buf_get
, count
);
3018 eb
->buf_get
+= count
;
3019 else /* count == len */
3020 eb
->buf_get
= eb
->buf_buf
;
3027 static struct usb_serial_driver edgeport_1port_device
= {
3029 .owner
= THIS_MODULE
,
3030 .name
= "edgeport_ti_1",
3032 .description
= "Edgeport TI 1 port adapter",
3033 .usb_driver
= &io_driver
,
3034 .id_table
= edgeport_1port_id_table
,
3037 .close
= edge_close
,
3038 .throttle
= edge_throttle
,
3039 .unthrottle
= edge_unthrottle
,
3040 .attach
= edge_startup
,
3041 .shutdown
= edge_shutdown
,
3042 .port_probe
= edge_create_sysfs_attrs
,
3043 .ioctl
= edge_ioctl
,
3044 .set_termios
= edge_set_termios
,
3045 .tiocmget
= edge_tiocmget
,
3046 .tiocmset
= edge_tiocmset
,
3047 .write
= edge_write
,
3048 .write_room
= edge_write_room
,
3049 .chars_in_buffer
= edge_chars_in_buffer
,
3050 .break_ctl
= edge_break
,
3051 .read_int_callback
= edge_interrupt_callback
,
3052 .read_bulk_callback
= edge_bulk_in_callback
,
3053 .write_bulk_callback
= edge_bulk_out_callback
,
3056 static struct usb_serial_driver edgeport_2port_device
= {
3058 .owner
= THIS_MODULE
,
3059 .name
= "edgeport_ti_2",
3061 .description
= "Edgeport TI 2 port adapter",
3062 .usb_driver
= &io_driver
,
3063 .id_table
= edgeport_2port_id_table
,
3066 .close
= edge_close
,
3067 .throttle
= edge_throttle
,
3068 .unthrottle
= edge_unthrottle
,
3069 .attach
= edge_startup
,
3070 .shutdown
= edge_shutdown
,
3071 .port_probe
= edge_create_sysfs_attrs
,
3072 .ioctl
= edge_ioctl
,
3073 .set_termios
= edge_set_termios
,
3074 .tiocmget
= edge_tiocmget
,
3075 .tiocmset
= edge_tiocmset
,
3076 .write
= edge_write
,
3077 .write_room
= edge_write_room
,
3078 .chars_in_buffer
= edge_chars_in_buffer
,
3079 .break_ctl
= edge_break
,
3080 .read_int_callback
= edge_interrupt_callback
,
3081 .read_bulk_callback
= edge_bulk_in_callback
,
3082 .write_bulk_callback
= edge_bulk_out_callback
,
3086 static int __init
edgeport_init(void)
3089 retval
= usb_serial_register(&edgeport_1port_device
);
3091 goto failed_1port_device_register
;
3092 retval
= usb_serial_register(&edgeport_2port_device
);
3094 goto failed_2port_device_register
;
3095 retval
= usb_register(&io_driver
);
3097 goto failed_usb_register
;
3098 info(DRIVER_DESC
" " DRIVER_VERSION
);
3100 failed_usb_register
:
3101 usb_serial_deregister(&edgeport_2port_device
);
3102 failed_2port_device_register
:
3103 usb_serial_deregister(&edgeport_1port_device
);
3104 failed_1port_device_register
:
3108 static void __exit
edgeport_exit (void)
3110 usb_deregister (&io_driver
);
3111 usb_serial_deregister (&edgeport_1port_device
);
3112 usb_serial_deregister (&edgeport_2port_device
);
3115 module_init(edgeport_init
);
3116 module_exit(edgeport_exit
);
3118 /* Module information */
3119 MODULE_AUTHOR(DRIVER_AUTHOR
);
3120 MODULE_DESCRIPTION(DRIVER_DESC
);
3121 MODULE_LICENSE("GPL");
3123 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
3124 MODULE_PARM_DESC(debug
, "Debug enabled or not");
3126 module_param(low_latency
, bool, S_IRUGO
| S_IWUSR
);
3127 MODULE_PARM_DESC(low_latency
, "Low latency enabled or not");
3129 module_param(closing_wait
, int, S_IRUGO
| S_IWUSR
);
3130 MODULE_PARM_DESC(closing_wait
, "Maximum wait for data to drain, in .01 secs");
3132 module_param(ignore_cpu_rev
, bool, S_IRUGO
| S_IWUSR
);
3133 MODULE_PARM_DESC(ignore_cpu_rev
, "Ignore the cpu revision when connecting to a device");
3135 module_param(default_uart_mode
, int, S_IRUGO
| S_IWUSR
);
3136 MODULE_PARM_DESC(default_uart_mode
, "Default uart_mode, 0=RS232, ...");