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/config.h>
28 #include <linux/kernel.h>
29 #include <linux/jiffies.h>
30 #include <linux/errno.h>
31 #include <linux/init.h>
32 #include <linux/slab.h>
33 #include <linux/tty.h>
34 #include <linux/tty_driver.h>
35 #include <linux/tty_flip.h>
36 #include <linux/module.h>
37 #include <linux/spinlock.h>
38 #include <linux/serial.h>
39 #include <linux/ioctl.h>
40 #include <asm/uaccess.h>
41 #include <asm/semaphore.h>
42 #include <linux/usb.h>
44 #include "usb-serial.h"
46 #include "io_usbvend.h"
52 #define DRIVER_VERSION "v0.7"
53 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
54 #define DRIVER_DESC "Edgeport USB Serial Driver"
57 /* firmware image code */
58 #define IMAGE_VERSION_NAME PagableOperationalCodeImageVersion
59 #define IMAGE_ARRAY_NAME PagableOperationalCodeImage
60 #define IMAGE_SIZE PagableOperationalCodeSize
61 #include "io_fw_down3.h" /* Define array OperationalCodeImage[] */
63 #define EPROM_PAGE_SIZE 64
66 struct edgeport_uart_buf_desc
{
67 __u32 count
; // Number of bytes currently in buffer
70 /* different hardware types */
71 #define HARDWARE_TYPE_930 0
72 #define HARDWARE_TYPE_TIUMP 1
74 // IOCTL_PRIVATE_TI_GET_MODE Definitions
75 #define TI_MODE_CONFIGURING 0 // Device has not entered start device
76 #define TI_MODE_BOOT 1 // Staying in boot mode
77 #define TI_MODE_DOWNLOAD 2 // Made it to download mode
78 #define TI_MODE_TRANSITIONING 3 // Currently in boot mode but transitioning to download mode
81 #define EDGE_READ_URB_RUNNING 0
82 #define EDGE_READ_URB_STOPPING 1
83 #define EDGE_READ_URB_STOPPED 2
85 #define EDGE_LOW_LATENCY 1
86 #define EDGE_CLOSING_WAIT 4000 /* in .01 sec */
88 #define EDGE_OUT_BUF_SIZE 1024
91 /* Product information read from the Edgeport */
94 int TiMode
; // Current TI Mode
95 __u8 hardware_type
; // Type of hardware
96 } __attribute__((packed
));
100 unsigned int buf_size
;
106 struct edgeport_port
{
113 __u32 ump_read_timeout
; /* Number of miliseconds the UMP will
114 wait without data before completing
119 struct edgeport_uart_buf_desc tx
;
120 struct async_icount icount
;
121 wait_queue_head_t delta_msr_wait
; /* for handling sleeping while
122 waiting for msr change to
124 struct edgeport_serial
*edge_serial
;
125 struct usb_serial_port
*port
;
126 __u8 bUartMode
; /* Port type, 0: RS232, etc. */
128 int ep_read_urb_state
;
129 int ep_write_urb_in_use
;
130 struct edge_buf
*ep_out_buf
;
133 struct edgeport_serial
{
134 struct product_info product_info
;
135 u8 TI_I2C_Type
; // Type of I2C in UMP
136 u8 TiReadI2C
; // Set to TRUE if we have read the I2c in Boot Mode
137 struct semaphore es_sem
;
139 struct usb_serial
*serial
;
143 /* Devices that this driver supports */
144 static struct usb_device_id edgeport_1port_id_table
[] = {
145 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_1
) },
146 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1
) },
147 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I
) },
148 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_PROXIMITY
) },
149 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_MOTION
) },
150 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_MOISTURE
) },
151 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_TEMPERATURE
) },
152 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_HUMIDITY
) },
153 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_POWER
) },
154 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_LIGHT
) },
155 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_RADIATION
) },
156 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_DISTANCE
) },
157 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_ACCELERATION
) },
158 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_PROX_DIST
) },
159 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_PLUS_PWR_HP4CD
) },
160 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_PLUS_PWR_PCI
) },
164 static struct usb_device_id edgeport_2port_id_table
[] = {
165 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2
) },
166 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2C
) },
167 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2I
) },
168 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_421
) },
169 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21
) },
170 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_42
) },
171 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4
) },
172 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4I
) },
173 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22I
) },
174 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_221C
) },
175 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22C
) },
176 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21C
) },
177 // The 4-port shows up as two 2-port devices
178 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4S
) },
182 /* Devices that this driver supports */
183 static struct usb_device_id id_table_combined
[] = {
184 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_1
) },
185 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1
) },
186 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I
) },
187 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_PROXIMITY
) },
188 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_MOTION
) },
189 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_MOISTURE
) },
190 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_TEMPERATURE
) },
191 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_HUMIDITY
) },
192 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_POWER
) },
193 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_LIGHT
) },
194 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_RADIATION
) },
195 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_DISTANCE
) },
196 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_ACCELERATION
) },
197 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_WP_PROX_DIST
) },
198 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_PLUS_PWR_HP4CD
) },
199 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_PLUS_PWR_PCI
) },
200 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2
) },
201 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2C
) },
202 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2I
) },
203 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_421
) },
204 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21
) },
205 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_42
) },
206 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4
) },
207 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4I
) },
208 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22I
) },
209 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_221C
) },
210 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22C
) },
211 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21C
) },
212 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4S
) },
216 MODULE_DEVICE_TABLE (usb
, id_table_combined
);
218 static struct usb_driver io_driver
= {
219 .owner
= THIS_MODULE
,
221 .probe
= usb_serial_probe
,
222 .disconnect
= usb_serial_disconnect
,
223 .id_table
= id_table_combined
,
227 static struct EDGE_FIRMWARE_VERSION_INFO OperationalCodeImageVersion
;
231 static int TIStayInBootMode
= 0;
232 static int low_latency
= EDGE_LOW_LATENCY
;
233 static int closing_wait
= EDGE_CLOSING_WAIT
;
234 static int ignore_cpu_rev
= 0;
237 static void edge_tty_recv(struct device
*dev
, struct tty_struct
*tty
, unsigned char *data
, int length
);
239 static void stop_read(struct edgeport_port
*edge_port
);
240 static int restart_read(struct edgeport_port
*edge_port
);
242 static void edge_set_termios (struct usb_serial_port
*port
, struct termios
*old_termios
);
243 static void edge_send(struct usb_serial_port
*port
);
245 /* circular buffer */
246 static struct edge_buf
*edge_buf_alloc(unsigned int size
);
247 static void edge_buf_free(struct edge_buf
*eb
);
248 static void edge_buf_clear(struct edge_buf
*eb
);
249 static unsigned int edge_buf_data_avail(struct edge_buf
*eb
);
250 static unsigned int edge_buf_space_avail(struct edge_buf
*eb
);
251 static unsigned int edge_buf_put(struct edge_buf
*eb
, const char *buf
,
253 static unsigned int edge_buf_get(struct edge_buf
*eb
, char *buf
,
257 static int TIReadVendorRequestSync (struct usb_device
*dev
,
266 status
= usb_control_msg (dev
,
267 usb_rcvctrlpipe(dev
, 0),
279 if (status
!= size
) {
280 dbg ("%s - wanted to write %d, but only wrote %d",
281 __FUNCTION__
, size
, status
);
287 static int TISendVendorRequestSync (struct usb_device
*dev
,
296 status
= usb_control_msg (dev
,
297 usb_sndctrlpipe(dev
, 0),
309 if (status
!= size
) {
310 dbg ("%s - wanted to write %d, but only wrote %d",
311 __FUNCTION__
, size
, status
);
317 static int TIWriteCommandSync (struct usb_device
*dev
, __u8 command
,
318 __u8 moduleid
, __u16 value
, u8
*data
,
321 return TISendVendorRequestSync (dev
,
325 data
, // TransferBuffer
326 size
); // TransferBufferLength
330 /* clear tx/rx buffers and fifo in TI UMP */
331 static int TIPurgeDataSync (struct usb_serial_port
*port
, __u16 mask
)
333 int port_number
= port
->number
- port
->serial
->minor
;
335 dbg ("%s - port %d, mask %x", __FUNCTION__
, port_number
, mask
);
337 return TIWriteCommandSync (port
->serial
->dev
,
339 (__u8
)(UMPM_UART1_PORT
+ port_number
),
346 * TIReadDownloadMemory - Read edgeport memory from TI chip
347 * @dev: usb device pointer
348 * @start_address: Device CPU address at which to read
349 * @length: Length of above data
350 * @address_type: Can read both XDATA and I2C
351 * @buffer: pointer to input data buffer
353 static int TIReadDownloadMemory(struct usb_device
*dev
, int start_address
,
354 int length
, __u8 address_type
, __u8
*buffer
)
358 __be16 be_start_address
;
360 dbg ("%s - @ %x for %d", __FUNCTION__
, start_address
, length
);
362 /* Read in blocks of 64 bytes
363 * (TI firmware can't handle more than 64 byte reads)
369 read_length
= (__u8
)length
;
371 if (read_length
> 1) {
372 dbg ("%s - @ %x for %d", __FUNCTION__
,
373 start_address
, read_length
);
375 be_start_address
= cpu_to_be16 (start_address
);
376 status
= TIReadVendorRequestSync (dev
,
377 UMPC_MEMORY_READ
, // Request
378 (__u16
)address_type
, // wValue (Address type)
379 (__force __u16
)be_start_address
, // wIndex (Address to read)
380 buffer
, // TransferBuffer
381 read_length
); // TransferBufferLength
384 dbg ("%s - ERROR %x", __FUNCTION__
, status
);
388 if (read_length
> 1) {
389 usb_serial_debug_data(debug
, &dev
->dev
, __FUNCTION__
,
390 read_length
, buffer
);
393 /* Update pointers/length */
394 start_address
+= read_length
;
395 buffer
+= read_length
;
396 length
-= read_length
;
402 static int TIReadRam (struct usb_device
*dev
, int start_address
, int length
, __u8
*buffer
)
404 return TIReadDownloadMemory (dev
,
407 DTK_ADDR_SPACE_XDATA
,
411 /* Read edgeport memory to a given block */
412 static int TIReadBootMemory (struct edgeport_serial
*serial
, int start_address
, int length
, __u8
* buffer
)
417 for (i
=0; i
< length
; i
++) {
418 status
= TIReadVendorRequestSync (serial
->serial
->dev
,
419 UMPC_MEMORY_READ
, // Request
420 serial
->TI_I2C_Type
, // wValue (Address type)
421 (__u16
)(start_address
+i
), // wIndex
422 &buffer
[i
], // TransferBuffer
423 0x01); // TransferBufferLength
425 dbg ("%s - ERROR %x", __FUNCTION__
, status
);
430 dbg ("%s - start_address = %x, length = %d", __FUNCTION__
, start_address
, length
);
431 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
, __FUNCTION__
, length
, buffer
);
433 serial
->TiReadI2C
= 1;
438 /* Write given block to TI EPROM memory */
439 static int TIWriteBootMemory (struct edgeport_serial
*serial
, int start_address
, int length
, __u8
*buffer
)
445 /* Must do a read before write */
446 if (!serial
->TiReadI2C
) {
447 status
= TIReadBootMemory(serial
, 0, 1, &temp
);
452 for (i
=0; i
< length
; ++i
) {
453 status
= TISendVendorRequestSync (serial
->serial
->dev
,
454 UMPC_MEMORY_WRITE
, // Request
456 (__u16
)(i
+start_address
), // wIndex
457 NULL
, // TransferBuffer
458 0); // TransferBufferLength
463 dbg ("%s - start_sddr = %x, length = %d", __FUNCTION__
, start_address
, length
);
464 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
, __FUNCTION__
, length
, buffer
);
470 /* Write edgeport I2C memory to TI chip */
471 static int TIWriteDownloadI2C (struct edgeport_serial
*serial
, int start_address
, int length
, __u8 address_type
, __u8
*buffer
)
475 __be16 be_start_address
;
477 /* We can only send a maximum of 1 aligned byte page at a time */
479 /* calulate the number of bytes left in the first page */
480 write_length
= EPROM_PAGE_SIZE
- (start_address
& (EPROM_PAGE_SIZE
- 1));
482 if (write_length
> length
)
483 write_length
= length
;
485 dbg ("%s - BytesInFirstPage Addr = %x, length = %d", __FUNCTION__
, start_address
, write_length
);
486 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
, __FUNCTION__
, write_length
, buffer
);
488 /* Write first page */
489 be_start_address
= cpu_to_be16 (start_address
);
490 status
= TISendVendorRequestSync (serial
->serial
->dev
,
491 UMPC_MEMORY_WRITE
, // Request
492 (__u16
)address_type
, // wValue
493 (__force __u16
)be_start_address
, // wIndex
494 buffer
, // TransferBuffer
497 dbg ("%s - ERROR %d", __FUNCTION__
, status
);
501 length
-= write_length
;
502 start_address
+= write_length
;
503 buffer
+= write_length
;
505 /* We should be aligned now -- can write max page size bytes at a time */
507 if (length
> EPROM_PAGE_SIZE
)
508 write_length
= EPROM_PAGE_SIZE
;
510 write_length
= length
;
512 dbg ("%s - Page Write Addr = %x, length = %d", __FUNCTION__
, start_address
, write_length
);
513 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
, __FUNCTION__
, write_length
, buffer
);
515 /* Write next page */
516 be_start_address
= cpu_to_be16 (start_address
);
517 status
= TISendVendorRequestSync (serial
->serial
->dev
,
518 UMPC_MEMORY_WRITE
, // Request
519 (__u16
)address_type
, // wValue
520 (__force __u16
)be_start_address
, // wIndex
521 buffer
, // TransferBuffer
522 write_length
); // TransferBufferLength
524 dev_err (&serial
->serial
->dev
->dev
, "%s - ERROR %d\n", __FUNCTION__
, status
);
528 length
-= write_length
;
529 start_address
+= write_length
;
530 buffer
+= write_length
;
535 /* Examine the UMP DMA registers and LSR
537 * Check the MSBit of the X and Y DMA byte count registers.
538 * A zero in this bit indicates that the TX DMA buffers are empty
539 * then check the TX Empty bit in the UART.
541 static int TIIsTxActive (struct edgeport_port
*port
)
544 struct out_endpoint_desc_block
*oedb
;
548 oedb
= kmalloc (sizeof (* oedb
), GFP_KERNEL
);
550 dev_err (&port
->port
->dev
, "%s - out of memory\n", __FUNCTION__
);
554 lsr
= kmalloc (1, GFP_KERNEL
); /* Sigh, that's right, just one byte,
555 as not all platforms can do DMA
561 /* Read the DMA Count Registers */
562 status
= TIReadRam (port
->port
->serial
->dev
,
568 goto exit_is_tx_active
;
570 dbg ("%s - XByteCount 0x%X", __FUNCTION__
, oedb
->XByteCount
);
573 status
= TIReadRam (port
->port
->serial
->dev
,
574 port
->uart_base
+ UMPMEM_OFFS_UART_LSR
,
579 goto exit_is_tx_active
;
580 dbg ("%s - LSR = 0x%X", __FUNCTION__
, *lsr
);
582 /* If either buffer has data or we are transmitting then return TRUE */
583 if ((oedb
->XByteCount
& 0x80 ) != 0 )
586 if ((*lsr
& UMP_UART_LSR_TX_MASK
) == 0 )
589 /* We return Not Active if we get any kind of error */
591 dbg ("%s - return %d", __FUNCTION__
, bytes_left
);
598 static void TIChasePort(struct edgeport_port
*port
, unsigned long timeout
, int flush
)
601 struct tty_struct
*tty
= port
->port
->tty
;
606 timeout
= (HZ
*EDGE_CLOSING_WAIT
)/100;
608 /* wait for data to drain from the buffer */
609 spin_lock_irqsave(&port
->ep_lock
, flags
);
610 init_waitqueue_entry(&wait
, current
);
611 add_wait_queue(&tty
->write_wait
, &wait
);
613 set_current_state(TASK_INTERRUPTIBLE
);
614 if (edge_buf_data_avail(port
->ep_out_buf
) == 0
615 || timeout
== 0 || signal_pending(current
)
616 || !usb_get_intfdata(port
->port
->serial
->interface
)) /* disconnect */
618 spin_unlock_irqrestore(&port
->ep_lock
, flags
);
619 timeout
= schedule_timeout(timeout
);
620 spin_lock_irqsave(&port
->ep_lock
, flags
);
622 set_current_state(TASK_RUNNING
);
623 remove_wait_queue(&tty
->write_wait
, &wait
);
625 edge_buf_clear(port
->ep_out_buf
);
626 spin_unlock_irqrestore(&port
->ep_lock
, flags
);
628 /* wait for data to drain from the device */
630 while ((long)(jiffies
- timeout
) < 0 && !signal_pending(current
)
631 && usb_get_intfdata(port
->port
->serial
->interface
)) { /* not disconnected */
632 if (!TIIsTxActive(port
))
638 if (!usb_get_intfdata(port
->port
->serial
->interface
))
641 /* wait one more character time, based on baud rate */
642 /* (TIIsTxActive doesn't seem to wait for the last byte) */
643 if ((baud_rate
=port
->baud_rate
) == 0)
645 msleep(max(1,(10000+baud_rate
-1)/baud_rate
));
648 static int TIChooseConfiguration (struct usb_device
*dev
)
650 // There may be multiple configurations on this device, in which case
651 // we would need to read and parse all of them to find out which one
652 // we want. However, we just support one config at this point,
653 // configuration # 1, which is Config Descriptor 0.
655 dbg ("%s - Number of Interfaces = %d", __FUNCTION__
, dev
->config
->desc
.bNumInterfaces
);
656 dbg ("%s - MAX Power = %d", __FUNCTION__
, dev
->config
->desc
.bMaxPower
*2);
658 if (dev
->config
->desc
.bNumInterfaces
!= 1) {
659 dev_err (&dev
->dev
, "%s - bNumInterfaces is not 1, ERROR!\n", __FUNCTION__
);
666 static int TIReadRom (struct edgeport_serial
*serial
, int start_address
, int length
, __u8
*buffer
)
670 if (serial
->product_info
.TiMode
== TI_MODE_DOWNLOAD
) {
671 status
= TIReadDownloadMemory (serial
->serial
->dev
,
677 status
= TIReadBootMemory (serial
,
686 static int TIWriteRom (struct edgeport_serial
*serial
, int start_address
, int length
, __u8
*buffer
)
688 if (serial
->product_info
.TiMode
== TI_MODE_BOOT
)
689 return TIWriteBootMemory (serial
,
694 if (serial
->product_info
.TiMode
== TI_MODE_DOWNLOAD
)
695 return TIWriteDownloadI2C (serial
,
706 /* Read a descriptor header from I2C based on type */
707 static int TIGetDescriptorAddress (struct edgeport_serial
*serial
, int desc_type
, struct ti_i2c_desc
*rom_desc
)
712 /* Search for requested descriptor in I2C */
715 status
= TIReadRom (serial
,
717 sizeof(struct ti_i2c_desc
),
722 if (rom_desc
->Type
== desc_type
)
723 return start_address
;
725 start_address
= start_address
+ sizeof(struct ti_i2c_desc
) + rom_desc
->Size
;
727 } while ((start_address
< TI_MAX_I2C_SIZE
) && rom_desc
->Type
);
732 /* Validate descriptor checksum */
733 static int ValidChecksum(struct ti_i2c_desc
*rom_desc
, __u8
*buffer
)
738 for (i
=0; i
< rom_desc
->Size
; i
++) {
739 cs
= (__u8
)(cs
+ buffer
[i
]);
741 if (cs
!= rom_desc
->CheckSum
) {
742 dbg ("%s - Mismatch %x - %x", __FUNCTION__
, rom_desc
->CheckSum
, cs
);
748 /* Make sure that the I2C image is good */
749 static int TiValidateI2cImage (struct edgeport_serial
*serial
)
751 struct device
*dev
= &serial
->serial
->dev
->dev
;
753 struct ti_i2c_desc
*rom_desc
;
754 int start_address
= 2;
758 rom_desc
= kmalloc (sizeof (*rom_desc
), GFP_KERNEL
);
760 dev_err (dev
, "%s - out of memory\n", __FUNCTION__
);
763 buffer
= kmalloc (TI_MAX_I2C_SIZE
, GFP_KERNEL
);
765 dev_err (dev
, "%s - out of memory when allocating buffer\n", __FUNCTION__
);
770 // Read the first byte (Signature0) must be 0x52 or 0x10
771 status
= TIReadRom (serial
, 0, 1, buffer
);
773 goto ExitTiValidateI2cImage
;
775 if (*buffer
!= UMP5152
&& *buffer
!= UMP3410
) {
776 dev_err (dev
, "%s - invalid buffer signature\n", __FUNCTION__
);
778 goto ExitTiValidateI2cImage
;
783 status
= TIReadRom (serial
,
785 sizeof(struct ti_i2c_desc
),
790 if ((start_address
+ sizeof(struct ti_i2c_desc
) + rom_desc
->Size
) > TI_MAX_I2C_SIZE
) {
792 dbg ("%s - structure too big, erroring out.", __FUNCTION__
);
796 dbg ("%s Type = 0x%x", __FUNCTION__
, rom_desc
->Type
);
798 // Skip type 2 record
799 ttype
= rom_desc
->Type
& 0x0f;
800 if ( ttype
!= I2C_DESC_TYPE_FIRMWARE_BASIC
801 && ttype
!= I2C_DESC_TYPE_FIRMWARE_AUTO
) {
802 // Read the descriptor data
803 status
= TIReadRom(serial
,
804 start_address
+sizeof(struct ti_i2c_desc
),
810 status
= ValidChecksum(rom_desc
, buffer
);
814 start_address
= start_address
+ sizeof(struct ti_i2c_desc
) + rom_desc
->Size
;
816 } while ((rom_desc
->Type
!= I2C_DESC_TYPE_ION
) && (start_address
< TI_MAX_I2C_SIZE
));
818 if ((rom_desc
->Type
!= I2C_DESC_TYPE_ION
) || (start_address
> TI_MAX_I2C_SIZE
))
821 ExitTiValidateI2cImage
:
827 static int TIReadManufDescriptor (struct edgeport_serial
*serial
, __u8
*buffer
)
831 struct ti_i2c_desc
*rom_desc
;
832 struct edge_ti_manuf_descriptor
*desc
;
834 rom_desc
= kmalloc (sizeof (*rom_desc
), GFP_KERNEL
);
836 dev_err (&serial
->serial
->dev
->dev
, "%s - out of memory\n", __FUNCTION__
);
839 start_address
= TIGetDescriptorAddress (serial
, I2C_DESC_TYPE_ION
, rom_desc
);
841 if (!start_address
) {
842 dbg ("%s - Edge Descriptor not found in I2C", __FUNCTION__
);
847 // Read the descriptor data
848 status
= TIReadRom (serial
,
849 start_address
+sizeof(struct ti_i2c_desc
),
855 status
= ValidChecksum(rom_desc
, buffer
);
857 desc
= (struct edge_ti_manuf_descriptor
*)buffer
;
858 dbg ( "%s - IonConfig 0x%x", __FUNCTION__
, desc
->IonConfig
);
859 dbg ( "%s - Version %d", __FUNCTION__
, desc
->Version
);
860 dbg ( "%s - Cpu/Board 0x%x", __FUNCTION__
, desc
->CpuRev_BoardRev
);
861 dbg ( "%s - NumPorts %d", __FUNCTION__
, desc
->NumPorts
);
862 dbg ( "%s - NumVirtualPorts %d", __FUNCTION__
, desc
->NumVirtualPorts
);
863 dbg ( "%s - TotalPorts %d", __FUNCTION__
, desc
->TotalPorts
);
870 /* Build firmware header used for firmware update */
871 static int BuildI2CFirmwareHeader (__u8
*header
, struct device
*dev
)
877 struct ti_i2c_desc
*i2c_header
;
878 struct ti_i2c_image_header
*img_header
;
879 struct ti_i2c_firmware_rec
*firmware_rec
;
881 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
882 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
883 // will download the latest firmware (padded to 15.5k) into the UMP ram.
884 // And finally when the device comes back up in download mode the driver will cause
885 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
886 // the record type from 0xf2 to 0x02.
888 // Allocate a 15.5k buffer + 2 bytes for version number (Firmware Record)
889 buffer_size
= (((1024 * 16) - 512 )+ sizeof(struct ti_i2c_firmware_rec
));
891 buffer
= kmalloc (buffer_size
, GFP_KERNEL
);
893 dev_err (dev
, "%s - out of memory\n", __FUNCTION__
);
897 // Set entire image of 0xffs
898 memset (buffer
, 0xff, buffer_size
);
900 // Copy version number into firmware record
901 firmware_rec
= (struct ti_i2c_firmware_rec
*)buffer
;
903 firmware_rec
->Ver_Major
= OperationalCodeImageVersion
.MajorVersion
;
904 firmware_rec
->Ver_Minor
= OperationalCodeImageVersion
.MinorVersion
;
906 // Pointer to fw_down memory image
907 img_header
= (struct ti_i2c_image_header
*)&PagableOperationalCodeImage
[0];
909 memcpy (buffer
+ sizeof(struct ti_i2c_firmware_rec
),
910 &PagableOperationalCodeImage
[sizeof(struct ti_i2c_image_header
)],
911 le16_to_cpu(img_header
->Length
));
913 for (i
=0; i
< buffer_size
; i
++) {
914 cs
= (__u8
)(cs
+ buffer
[i
]);
920 i2c_header
= (struct ti_i2c_desc
*)header
;
921 firmware_rec
= (struct ti_i2c_firmware_rec
*)i2c_header
->Data
;
923 i2c_header
->Type
= I2C_DESC_TYPE_FIRMWARE_BLANK
;
924 i2c_header
->Size
= (__u16
)buffer_size
;
925 i2c_header
->CheckSum
= cs
;
926 firmware_rec
->Ver_Major
= OperationalCodeImageVersion
.MajorVersion
;
927 firmware_rec
->Ver_Minor
= OperationalCodeImageVersion
.MinorVersion
;
932 /* Try to figure out what type of I2c we have */
933 static int TIGetI2cTypeInBootMode (struct edgeport_serial
*serial
)
938 // Try to read type 2
939 status
= TIReadVendorRequestSync (serial
->serial
->dev
,
940 UMPC_MEMORY_READ
, // Request
941 DTK_ADDR_SPACE_I2C_TYPE_II
, // wValue (Address type)
943 &data
, // TransferBuffer
944 0x01); // TransferBufferLength
946 dbg ("%s - read 2 status error = %d", __FUNCTION__
, status
);
948 dbg ("%s - read 2 data = 0x%x", __FUNCTION__
, data
);
949 if ((!status
) && (data
== UMP5152
|| data
== UMP3410
)) {
950 dbg ("%s - ROM_TYPE_II", __FUNCTION__
);
951 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
955 // Try to read type 3
956 status
= TIReadVendorRequestSync (serial
->serial
->dev
,
957 UMPC_MEMORY_READ
, // Request
958 DTK_ADDR_SPACE_I2C_TYPE_III
, // wValue (Address type)
960 &data
, // TransferBuffer
961 0x01); // TransferBufferLength
963 dbg ("%s - read 3 status error = %d", __FUNCTION__
, status
);
965 dbg ("%s - read 2 data = 0x%x", __FUNCTION__
, data
);
966 if ((!status
) && (data
== UMP5152
|| data
== UMP3410
)) {
967 dbg ("%s - ROM_TYPE_III", __FUNCTION__
);
968 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_III
;
972 dbg ("%s - Unknown", __FUNCTION__
);
973 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
977 static int TISendBulkTransferSync (struct usb_serial
*serial
, void *buffer
, int length
, int *num_sent
)
981 status
= usb_bulk_msg (serial
->dev
,
982 usb_sndbulkpipe(serial
->dev
,
983 serial
->port
[0]->bulk_out_endpointAddress
),
991 /* Download given firmware image to the device (IN BOOT MODE) */
992 static int TIDownloadCodeImage (struct edgeport_serial
*serial
, __u8
*image
, int image_length
)
999 // Transfer firmware image
1000 for (pos
= 0; pos
< image_length
; ) {
1001 // Read the next buffer from file
1002 transfer
= image_length
- pos
;
1003 if (transfer
> EDGE_FW_BULK_MAX_PACKET_SIZE
)
1004 transfer
= EDGE_FW_BULK_MAX_PACKET_SIZE
;
1007 status
= TISendBulkTransferSync (serial
->serial
, &image
[pos
], transfer
, &done
);
1010 // Advance buffer pointer
1018 static int TIConfigureBootDevice (struct usb_device
*dev
)
1024 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
1026 * This routine downloads the main operating code into the TI5052, using the
1027 * boot code already burned into E2PROM or ROM.
1029 static int TIDownloadFirmware (struct edgeport_serial
*serial
)
1031 struct device
*dev
= &serial
->serial
->dev
->dev
;
1034 struct edge_ti_manuf_descriptor
*ti_manuf_desc
;
1035 struct usb_interface_descriptor
*interface
;
1036 int download_cur_ver
;
1037 int download_new_ver
;
1039 /* This routine is entered by both the BOOT mode and the Download mode
1040 * We can determine which code is running by the reading the config
1041 * descriptor and if we have only one bulk pipe it is in boot mode
1043 serial
->product_info
.hardware_type
= HARDWARE_TYPE_TIUMP
;
1045 /* Default to type 2 i2c */
1046 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
1048 status
= TIChooseConfiguration (serial
->serial
->dev
);
1052 interface
= &serial
->serial
->interface
->cur_altsetting
->desc
;
1054 dev_err (dev
, "%s - no interface set, error!\n", __FUNCTION__
);
1058 // Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
1059 // if we have more than one endpoint we are definitely in download mode
1060 if (interface
->bNumEndpoints
> 1)
1061 serial
->product_info
.TiMode
= TI_MODE_DOWNLOAD
;
1063 // Otherwise we will remain in configuring mode
1064 serial
->product_info
.TiMode
= TI_MODE_CONFIGURING
;
1066 // Save Download Version Number
1067 OperationalCodeImageVersion
.MajorVersion
= PagableOperationalCodeImageVersion
.MajorVersion
;
1068 OperationalCodeImageVersion
.MinorVersion
= PagableOperationalCodeImageVersion
.MinorVersion
;
1069 OperationalCodeImageVersion
.BuildNumber
= PagableOperationalCodeImageVersion
.BuildNumber
;
1071 /********************************************************************/
1073 /********************************************************************/
1074 if (serial
->product_info
.TiMode
== TI_MODE_DOWNLOAD
) {
1075 struct ti_i2c_desc
*rom_desc
;
1077 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN DOWNLOAD MODE>>>>>>>>>>", __FUNCTION__
);
1079 status
= TiValidateI2cImage (serial
);
1081 dbg ("%s - <<<<<<<<<<<<<<<DOWNLOAD MODE -- BAD I2C >>>>>>>>>>",
1086 /* Validate Hardware version number
1087 * Read Manufacturing Descriptor from TI Based Edgeport
1089 ti_manuf_desc
= kmalloc (sizeof (*ti_manuf_desc
), GFP_KERNEL
);
1090 if (!ti_manuf_desc
) {
1091 dev_err (dev
, "%s - out of memory.\n", __FUNCTION__
);
1094 status
= TIReadManufDescriptor (serial
, (__u8
*)ti_manuf_desc
);
1096 kfree (ti_manuf_desc
);
1100 // Check version number of ION descriptor
1101 if (!ignore_cpu_rev
&& TI_GET_CPU_REVISION(ti_manuf_desc
->CpuRev_BoardRev
) < 2) {
1102 dbg ( "%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__
,
1103 TI_GET_CPU_REVISION(ti_manuf_desc
->CpuRev_BoardRev
));
1104 kfree (ti_manuf_desc
);
1108 rom_desc
= kmalloc (sizeof (*rom_desc
), GFP_KERNEL
);
1110 dev_err (dev
, "%s - out of memory.\n", __FUNCTION__
);
1111 kfree (ti_manuf_desc
);
1115 // Search for type 2 record (firmware record)
1116 if ((start_address
= TIGetDescriptorAddress (serial
, I2C_DESC_TYPE_FIRMWARE_BASIC
, rom_desc
)) != 0) {
1117 struct ti_i2c_firmware_rec
*firmware_version
;
1120 dbg ("%s - Found Type FIRMWARE (Type 2) record", __FUNCTION__
);
1122 firmware_version
= kmalloc (sizeof (*firmware_version
), GFP_KERNEL
);
1123 if (!firmware_version
) {
1124 dev_err (dev
, "%s - out of memory.\n", __FUNCTION__
);
1126 kfree (ti_manuf_desc
);
1130 // Validate version number
1131 // Read the descriptor data
1132 status
= TIReadRom (serial
,
1133 start_address
+sizeof(struct ti_i2c_desc
),
1134 sizeof(struct ti_i2c_firmware_rec
),
1135 (__u8
*)firmware_version
);
1137 kfree (firmware_version
);
1139 kfree (ti_manuf_desc
);
1143 // Check version number of download with current version in I2c
1144 download_cur_ver
= (firmware_version
->Ver_Major
<< 8) +
1145 (firmware_version
->Ver_Minor
);
1146 download_new_ver
= (OperationalCodeImageVersion
.MajorVersion
<< 8) +
1147 (OperationalCodeImageVersion
.MinorVersion
);
1149 dbg ("%s - >>>Firmware Versions Device %d.%d Driver %d.%d",
1151 firmware_version
->Ver_Major
,
1152 firmware_version
->Ver_Minor
,
1153 OperationalCodeImageVersion
.MajorVersion
,
1154 OperationalCodeImageVersion
.MinorVersion
);
1156 // Check if we have an old version in the I2C and update if necessary
1157 if (download_cur_ver
!= download_new_ver
) {
1158 dbg ("%s - Update I2C Download from %d.%d to %d.%d",
1160 firmware_version
->Ver_Major
,
1161 firmware_version
->Ver_Minor
,
1162 OperationalCodeImageVersion
.MajorVersion
,
1163 OperationalCodeImageVersion
.MinorVersion
);
1165 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1166 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1167 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1168 // And finally when the device comes back up in download mode the driver will cause
1169 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1170 // the record type from 0xf2 to 0x02.
1172 record
= I2C_DESC_TYPE_FIRMWARE_BLANK
;
1174 // Change the I2C Firmware record type to 0xf2 to trigger an update
1175 status
= TIWriteRom (serial
,
1180 kfree (firmware_version
);
1182 kfree (ti_manuf_desc
);
1186 // verify the write -- must do this in order for write to
1187 // complete before we do the hardware reset
1188 status
= TIReadRom (serial
,
1194 kfree (firmware_version
);
1196 kfree (ti_manuf_desc
);
1200 if (record
!= I2C_DESC_TYPE_FIRMWARE_BLANK
) {
1201 dev_err (dev
, "%s - error resetting device\n", __FUNCTION__
);
1202 kfree (firmware_version
);
1204 kfree (ti_manuf_desc
);
1208 dbg ("%s - HARDWARE RESET", __FUNCTION__
);
1210 // Reset UMP -- Back to BOOT MODE
1211 status
= TISendVendorRequestSync (serial
->serial
->dev
,
1212 UMPC_HARDWARE_RESET
, // Request
1215 NULL
, // TransferBuffer
1216 0); // TransferBufferLength
1218 dbg ( "%s - HARDWARE RESET return %d", __FUNCTION__
, status
);
1220 /* return an error on purpose. */
1221 kfree (firmware_version
);
1223 kfree (ti_manuf_desc
);
1226 kfree (firmware_version
);
1228 // Search for type 0xF2 record (firmware blank record)
1229 else if ((start_address
= TIGetDescriptorAddress (serial
, I2C_DESC_TYPE_FIRMWARE_BLANK
, rom_desc
)) != 0) {
1230 #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + sizeof(struct ti_i2c_firmware_rec))
1234 header
= kmalloc (HEADER_SIZE
, GFP_KERNEL
);
1236 dev_err (dev
, "%s - out of memory.\n", __FUNCTION__
);
1238 kfree (ti_manuf_desc
);
1242 vheader
= kmalloc (HEADER_SIZE
, GFP_KERNEL
);
1244 dev_err (dev
, "%s - out of memory.\n", __FUNCTION__
);
1247 kfree (ti_manuf_desc
);
1251 dbg ("%s - Found Type BLANK FIRMWARE (Type F2) record", __FUNCTION__
);
1253 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1254 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1255 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1256 // And finally when the device comes back up in download mode the driver will cause
1257 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1258 // the record type from 0xf2 to 0x02.
1259 status
= BuildI2CFirmwareHeader(header
, dev
);
1264 kfree (ti_manuf_desc
);
1268 // Update I2C with type 0xf2 record with correct size and checksum
1269 status
= TIWriteRom (serial
,
1277 kfree (ti_manuf_desc
);
1281 // verify the write -- must do this in order for write to
1282 // complete before we do the hardware reset
1283 status
= TIReadRom (serial
,
1289 dbg ("%s - can't read header back", __FUNCTION__
);
1293 kfree (ti_manuf_desc
);
1296 if (memcmp(vheader
, header
, HEADER_SIZE
)) {
1297 dbg ("%s - write download record failed", __FUNCTION__
);
1301 kfree (ti_manuf_desc
);
1308 dbg ("%s - Start firmware update", __FUNCTION__
);
1310 // Tell firmware to copy download image into I2C
1311 status
= TISendVendorRequestSync (serial
->serial
->dev
,
1312 UMPC_COPY_DNLD_TO_I2C
, // Request
1315 NULL
, // TransferBuffer
1316 0); // TransferBufferLength
1318 dbg ("%s - Update complete 0x%x", __FUNCTION__
, status
);
1320 dev_err (dev
, "%s - UMPC_COPY_DNLD_TO_I2C failed\n", __FUNCTION__
);
1322 kfree (ti_manuf_desc
);
1327 // The device is running the download code
1329 kfree (ti_manuf_desc
);
1333 /********************************************************************/
1335 /********************************************************************/
1336 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN BOOT MODE>>>>>>>>>>>>>>>",
1339 // Configure the TI device so we can use the BULK pipes for download
1340 status
= TIConfigureBootDevice (serial
->serial
->dev
);
1344 if (le16_to_cpu(serial
->serial
->dev
->descriptor
.idVendor
) != USB_VENDOR_ID_ION
) {
1345 dbg ("%s - VID = 0x%x", __FUNCTION__
,
1346 le16_to_cpu(serial
->serial
->dev
->descriptor
.idVendor
));
1347 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
1348 goto StayInBootMode
;
1351 // We have an ION device (I2c Must be programmed)
1352 // Determine I2C image type
1353 if (TIGetI2cTypeInBootMode(serial
)) {
1354 goto StayInBootMode
;
1357 // Registry variable set?
1358 if (TIStayInBootMode
) {
1359 dbg ("%s - TIStayInBootMode", __FUNCTION__
);
1360 goto StayInBootMode
;
1363 // Check for ION Vendor ID and that the I2C is valid
1364 if (!TiValidateI2cImage(serial
)) {
1365 struct ti_i2c_image_header
*header
;
1371 /* Validate Hardware version number
1372 * Read Manufacturing Descriptor from TI Based Edgeport
1374 ti_manuf_desc
= kmalloc (sizeof (*ti_manuf_desc
), GFP_KERNEL
);
1375 if (!ti_manuf_desc
) {
1376 dev_err (dev
, "%s - out of memory.\n", __FUNCTION__
);
1379 status
= TIReadManufDescriptor (serial
, (__u8
*)ti_manuf_desc
);
1381 kfree (ti_manuf_desc
);
1382 goto StayInBootMode
;
1385 // Check for version 2
1386 if (!ignore_cpu_rev
&& TI_GET_CPU_REVISION(ti_manuf_desc
->CpuRev_BoardRev
) < 2) {
1387 dbg ("%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__
,
1388 TI_GET_CPU_REVISION(ti_manuf_desc
->CpuRev_BoardRev
));
1389 kfree (ti_manuf_desc
);
1390 goto StayInBootMode
;
1393 kfree (ti_manuf_desc
);
1395 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1396 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1397 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1398 // And finally when the device comes back up in download mode the driver will cause
1399 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1400 // the record type from 0xf2 to 0x02.
1403 * Do we really have to copy the whole firmware image,
1404 * or could we do this in place!
1407 // Allocate a 15.5k buffer + 3 byte header
1408 buffer_size
= (((1024 * 16) - 512) + sizeof(struct ti_i2c_image_header
));
1409 buffer
= kmalloc (buffer_size
, GFP_KERNEL
);
1411 dev_err (dev
, "%s - out of memory\n", __FUNCTION__
);
1415 // Initialize the buffer to 0xff (pad the buffer)
1416 memset (buffer
, 0xff, buffer_size
);
1418 memcpy (buffer
, &PagableOperationalCodeImage
[0], PagableOperationalCodeSize
);
1420 for(i
= sizeof(struct ti_i2c_image_header
); i
< buffer_size
; i
++) {
1421 cs
= (__u8
)(cs
+ buffer
[i
]);
1424 header
= (struct ti_i2c_image_header
*)buffer
;
1426 // update length and checksum after padding
1427 header
->Length
= cpu_to_le16((__u16
)(buffer_size
- sizeof(struct ti_i2c_image_header
)));
1428 header
->CheckSum
= cs
;
1430 // Download the operational code
1431 dbg ("%s - Downloading operational code image (TI UMP)", __FUNCTION__
);
1432 status
= TIDownloadCodeImage (serial
, buffer
, buffer_size
);
1437 dbg ("%s - Error downloading operational code image", __FUNCTION__
);
1441 // Device will reboot
1442 serial
->product_info
.TiMode
= TI_MODE_TRANSITIONING
;
1444 dbg ("%s - Download successful -- Device rebooting...", __FUNCTION__
);
1446 /* return an error on purpose */
1451 // Eprom is invalid or blank stay in boot mode
1452 dbg ("%s - <<<<<<<<<<<<<<<STAYING IN BOOT MODE>>>>>>>>>>>>", __FUNCTION__
);
1453 serial
->product_info
.TiMode
= TI_MODE_BOOT
;
1459 static int TISetDtr (struct edgeport_port
*port
)
1461 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1463 dbg ("%s", __FUNCTION__
);
1464 port
->shadow_mcr
|= MCR_DTR
;
1466 return TIWriteCommandSync (port
->port
->serial
->dev
,
1468 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1474 static int TIClearDtr (struct edgeport_port
*port
)
1476 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1478 dbg ("%s", __FUNCTION__
);
1479 port
->shadow_mcr
&= ~MCR_DTR
;
1481 return TIWriteCommandSync (port
->port
->serial
->dev
,
1483 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1489 static int TISetRts (struct edgeport_port
*port
)
1491 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1493 dbg ("%s", __FUNCTION__
);
1494 port
->shadow_mcr
|= MCR_RTS
;
1496 return TIWriteCommandSync (port
->port
->serial
->dev
,
1498 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1504 static int TIClearRts (struct edgeport_port
*port
)
1506 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1508 dbg ("%s", __FUNCTION__
);
1509 port
->shadow_mcr
&= ~MCR_RTS
;
1511 return TIWriteCommandSync (port
->port
->serial
->dev
,
1513 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1519 static int TISetLoopBack (struct edgeport_port
*port
)
1521 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1523 dbg ("%s", __FUNCTION__
);
1525 return TIWriteCommandSync (port
->port
->serial
->dev
,
1526 UMPC_SET_CLR_LOOPBACK
,
1527 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1533 static int TIClearLoopBack (struct edgeport_port
*port
)
1535 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1537 dbg ("%s", __FUNCTION__
);
1539 return TIWriteCommandSync (port
->port
->serial
->dev
,
1540 UMPC_SET_CLR_LOOPBACK
,
1541 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1547 static int TISetBreak (struct edgeport_port
*port
)
1549 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1551 dbg ("%s", __FUNCTION__
);
1553 return TIWriteCommandSync (port
->port
->serial
->dev
,
1555 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1561 static int TIClearBreak (struct edgeport_port
*port
)
1563 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1565 dbg ("%s", __FUNCTION__
);
1567 return TIWriteCommandSync (port
->port
->serial
->dev
,
1569 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1575 static int TIRestoreMCR (struct edgeport_port
*port
, __u8 mcr
)
1579 dbg ("%s - %x", __FUNCTION__
, mcr
);
1582 status
= TISetDtr (port
);
1584 status
= TIClearDtr (port
);
1590 status
= TISetRts (port
);
1592 status
= TIClearRts (port
);
1597 if (mcr
& MCR_LOOPBACK
)
1598 status
= TISetLoopBack (port
);
1600 status
= TIClearLoopBack (port
);
1607 /* Convert TI LSR to standard UART flags */
1608 static __u8
MapLineStatus (__u8 ti_lsr
)
1612 #define MAP_FLAG(flagUmp, flagUart) \
1613 if (ti_lsr & flagUmp) \
1616 MAP_FLAG(UMP_UART_LSR_OV_MASK
, LSR_OVER_ERR
) /* overrun */
1617 MAP_FLAG(UMP_UART_LSR_PE_MASK
, LSR_PAR_ERR
) /* parity error */
1618 MAP_FLAG(UMP_UART_LSR_FE_MASK
, LSR_FRM_ERR
) /* framing error */
1619 MAP_FLAG(UMP_UART_LSR_BR_MASK
, LSR_BREAK
) /* break detected */
1620 MAP_FLAG(UMP_UART_LSR_RX_MASK
, LSR_RX_AVAIL
) /* receive data available */
1621 MAP_FLAG(UMP_UART_LSR_TX_MASK
, LSR_TX_EMPTY
) /* transmit holding register empty */
1628 static void handle_new_msr (struct edgeport_port
*edge_port
, __u8 msr
)
1630 struct async_icount
*icount
;
1631 struct tty_struct
*tty
;
1633 dbg ("%s - %02x", __FUNCTION__
, msr
);
1635 if (msr
& (EDGEPORT_MSR_DELTA_CTS
| EDGEPORT_MSR_DELTA_DSR
| EDGEPORT_MSR_DELTA_RI
| EDGEPORT_MSR_DELTA_CD
)) {
1636 icount
= &edge_port
->icount
;
1638 /* update input line counters */
1639 if (msr
& EDGEPORT_MSR_DELTA_CTS
)
1641 if (msr
& EDGEPORT_MSR_DELTA_DSR
)
1643 if (msr
& EDGEPORT_MSR_DELTA_CD
)
1645 if (msr
& EDGEPORT_MSR_DELTA_RI
)
1647 wake_up_interruptible (&edge_port
->delta_msr_wait
);
1650 /* Save the new modem status */
1651 edge_port
->shadow_msr
= msr
& 0xf0;
1653 tty
= edge_port
->port
->tty
;
1654 /* handle CTS flow control */
1655 if (tty
&& C_CRTSCTS(tty
)) {
1656 if (msr
& EDGEPORT_MSR_CTS
) {
1657 tty
->hw_stopped
= 0;
1660 tty
->hw_stopped
= 1;
1667 static void handle_new_lsr (struct edgeport_port
*edge_port
, int lsr_data
, __u8 lsr
, __u8 data
)
1669 struct async_icount
*icount
;
1670 __u8 new_lsr
= (__u8
)(lsr
& (__u8
)(LSR_OVER_ERR
| LSR_PAR_ERR
| LSR_FRM_ERR
| LSR_BREAK
));
1672 dbg ("%s - %02x", __FUNCTION__
, new_lsr
);
1674 edge_port
->shadow_lsr
= lsr
;
1676 if (new_lsr
& LSR_BREAK
) {
1678 * Parity and Framing errors only count if they
1679 * occur exclusive of a break being received.
1681 new_lsr
&= (__u8
)(LSR_OVER_ERR
| LSR_BREAK
);
1684 /* Place LSR data byte into Rx buffer */
1685 if (lsr_data
&& edge_port
->port
->tty
)
1686 edge_tty_recv(&edge_port
->port
->dev
, edge_port
->port
->tty
, &data
, 1);
1688 /* update input line counters */
1689 icount
= &edge_port
->icount
;
1690 if (new_lsr
& LSR_BREAK
)
1692 if (new_lsr
& LSR_OVER_ERR
)
1694 if (new_lsr
& LSR_PAR_ERR
)
1696 if (new_lsr
& LSR_FRM_ERR
)
1701 static void edge_interrupt_callback (struct urb
*urb
, struct pt_regs
*regs
)
1703 struct edgeport_serial
*edge_serial
= (struct edgeport_serial
*)urb
->context
;
1704 struct usb_serial_port
*port
;
1705 struct edgeport_port
*edge_port
;
1706 unsigned char *data
= urb
->transfer_buffer
;
1707 int length
= urb
->actual_length
;
1714 dbg("%s", __FUNCTION__
);
1716 switch (urb
->status
) {
1723 /* this urb is terminated, clean up */
1724 dbg("%s - urb shutting down with status: %d", __FUNCTION__
, urb
->status
);
1727 dev_err(&urb
->dev
->dev
, "%s - nonzero urb status received: %d\n", __FUNCTION__
, urb
->status
);
1732 dbg ("%s - no data in urb", __FUNCTION__
);
1736 usb_serial_debug_data(debug
, &edge_serial
->serial
->dev
->dev
, __FUNCTION__
, length
, data
);
1739 dbg ("%s - expecting packet of size 2, got %d", __FUNCTION__
, length
);
1743 port_number
= TIUMP_GET_PORT_FROM_CODE (data
[0]);
1744 function
= TIUMP_GET_FUNC_FROM_CODE (data
[0]);
1745 dbg ("%s - port_number %d, function %d, info 0x%x",
1746 __FUNCTION__
, port_number
, function
, data
[1]);
1747 port
= edge_serial
->serial
->port
[port_number
];
1748 edge_port
= usb_get_serial_port_data(port
);
1750 dbg ("%s - edge_port not found", __FUNCTION__
);
1754 case TIUMP_INTERRUPT_CODE_LSR
:
1755 lsr
= MapLineStatus(data
[1]);
1756 if (lsr
& UMP_UART_LSR_DATA_MASK
) {
1757 /* Save the LSR event for bulk read completion routine */
1758 dbg ("%s - LSR Event Port %u LSR Status = %02x",
1759 __FUNCTION__
, port_number
, lsr
);
1760 edge_port
->lsr_event
= 1;
1761 edge_port
->lsr_mask
= lsr
;
1763 dbg ("%s - ===== Port %d LSR Status = %02x ======",
1764 __FUNCTION__
, port_number
, lsr
);
1765 handle_new_lsr (edge_port
, 0, lsr
, 0);
1769 case TIUMP_INTERRUPT_CODE_MSR
: // MSR
1770 /* Copy MSR from UMP */
1772 dbg ("%s - ===== Port %u MSR Status = %02x ======\n",
1773 __FUNCTION__
, port_number
, msr
);
1774 handle_new_msr (edge_port
, msr
);
1778 dev_err (&urb
->dev
->dev
, "%s - Unknown Interrupt code from UMP %x\n",
1779 __FUNCTION__
, data
[1]);
1785 status
= usb_submit_urb (urb
, GFP_ATOMIC
);
1787 dev_err (&urb
->dev
->dev
, "%s - usb_submit_urb failed with result %d\n",
1788 __FUNCTION__
, status
);
1791 static void edge_bulk_in_callback (struct urb
*urb
, struct pt_regs
*regs
)
1793 struct edgeport_port
*edge_port
= (struct edgeport_port
*)urb
->context
;
1794 unsigned char *data
= urb
->transfer_buffer
;
1795 struct tty_struct
*tty
;
1799 dbg("%s", __FUNCTION__
);
1801 switch (urb
->status
) {
1808 /* this urb is terminated, clean up */
1809 dbg("%s - urb shutting down with status: %d", __FUNCTION__
, urb
->status
);
1812 dev_err (&urb
->dev
->dev
,"%s - nonzero read bulk status received: %d\n",
1813 __FUNCTION__
, urb
->status
);
1816 if (urb
->status
== -EPIPE
)
1820 dev_err(&urb
->dev
->dev
,"%s - stopping read!\n", __FUNCTION__
);
1824 port_number
= edge_port
->port
->number
- edge_port
->port
->serial
->minor
;
1826 if (edge_port
->lsr_event
) {
1827 edge_port
->lsr_event
= 0;
1828 dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
1829 __FUNCTION__
, port_number
, edge_port
->lsr_mask
, *data
);
1830 handle_new_lsr (edge_port
, 1, edge_port
->lsr_mask
, *data
);
1831 /* Adjust buffer length/pointer */
1832 --urb
->actual_length
;
1836 tty
= edge_port
->port
->tty
;
1837 if (tty
&& urb
->actual_length
) {
1838 usb_serial_debug_data(debug
, &edge_port
->port
->dev
, __FUNCTION__
, urb
->actual_length
, data
);
1840 if (edge_port
->close_pending
) {
1841 dbg ("%s - close is pending, dropping data on the floor.", __FUNCTION__
);
1843 edge_tty_recv(&edge_port
->port
->dev
, tty
, data
, urb
->actual_length
);
1845 edge_port
->icount
.rx
+= urb
->actual_length
;
1849 /* continue read unless stopped */
1850 spin_lock(&edge_port
->ep_lock
);
1851 if (edge_port
->ep_read_urb_state
== EDGE_READ_URB_RUNNING
) {
1852 urb
->dev
= edge_port
->port
->serial
->dev
;
1853 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
1854 } else if (edge_port
->ep_read_urb_state
== EDGE_READ_URB_STOPPING
) {
1855 edge_port
->ep_read_urb_state
= EDGE_READ_URB_STOPPED
;
1857 spin_unlock(&edge_port
->ep_lock
);
1859 dev_err (&urb
->dev
->dev
, "%s - usb_submit_urb failed with result %d\n",
1860 __FUNCTION__
, status
);
1863 static void edge_tty_recv(struct device
*dev
, struct tty_struct
*tty
, unsigned char *data
, int length
)
1868 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
1869 tty_flip_buffer_push(tty
);
1870 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
1871 dev_err(dev
, "%s - dropping data, %d bytes lost\n",
1872 __FUNCTION__
, length
);
1876 cnt
= min(length
, TTY_FLIPBUF_SIZE
- tty
->flip
.count
);
1877 memcpy(tty
->flip
.char_buf_ptr
, data
, cnt
);
1878 memset(tty
->flip
.flag_buf_ptr
, 0, cnt
);
1879 tty
->flip
.char_buf_ptr
+= cnt
;
1880 tty
->flip
.flag_buf_ptr
+= cnt
;
1881 tty
->flip
.count
+= cnt
;
1884 } while (length
> 0);
1886 tty_flip_buffer_push(tty
);
1889 static void edge_bulk_out_callback (struct urb
*urb
, struct pt_regs
*regs
)
1891 struct usb_serial_port
*port
= (struct usb_serial_port
*)urb
->context
;
1892 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
1894 dbg ("%s - port %d", __FUNCTION__
, port
->number
);
1896 edge_port
->ep_write_urb_in_use
= 0;
1898 switch (urb
->status
) {
1905 /* this urb is terminated, clean up */
1906 dbg("%s - urb shutting down with status: %d", __FUNCTION__
, urb
->status
);
1909 dev_err (&urb
->dev
->dev
,"%s - nonzero write bulk status received: %d\n",
1910 __FUNCTION__
, urb
->status
);
1913 /* send any buffered data */
1917 static int edge_open (struct usb_serial_port
*port
, struct file
* filp
)
1919 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
1920 struct edgeport_serial
*edge_serial
;
1921 struct usb_device
*dev
;
1926 u8 transaction_timeout
;
1928 dbg("%s - port %d", __FUNCTION__
, port
->number
);
1930 if (edge_port
== NULL
)
1934 port
->tty
->low_latency
= low_latency
;
1936 port_number
= port
->number
- port
->serial
->minor
;
1937 switch (port_number
) {
1939 edge_port
->uart_base
= UMPMEM_BASE_UART1
;
1940 edge_port
->dma_address
= UMPD_OEDB1_ADDRESS
;
1943 edge_port
->uart_base
= UMPMEM_BASE_UART2
;
1944 edge_port
->dma_address
= UMPD_OEDB2_ADDRESS
;
1947 dev_err (&port
->dev
, "Unknown port number!!!\n");
1951 dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
1952 __FUNCTION__
, port_number
, edge_port
->uart_base
, edge_port
->dma_address
);
1954 dev
= port
->serial
->dev
;
1956 memset (&(edge_port
->icount
), 0x00, sizeof(edge_port
->icount
));
1957 init_waitqueue_head (&edge_port
->delta_msr_wait
);
1959 /* turn off loopback */
1960 status
= TIClearLoopBack (edge_port
);
1962 dev_err(&port
->dev
,"%s - cannot send clear loopback command, %d\n",
1963 __FUNCTION__
, status
);
1967 /* set up the port settings */
1968 edge_set_termios (port
, NULL
);
1970 /* open up the port */
1972 /* milliseconds to timeout for DMA transfer */
1973 transaction_timeout
= 2;
1975 edge_port
->ump_read_timeout
= max (20, ((transaction_timeout
* 3) / 2) );
1977 // milliseconds to timeout for DMA transfer
1978 open_settings
= (u8
)(UMP_DMA_MODE_CONTINOUS
|
1979 UMP_PIPE_TRANS_TIMEOUT_ENA
|
1980 (transaction_timeout
<< 2));
1982 dbg ("%s - Sending UMPC_OPEN_PORT", __FUNCTION__
);
1984 /* Tell TI to open and start the port */
1985 status
= TIWriteCommandSync (dev
,
1987 (u8
)(UMPM_UART1_PORT
+ port_number
),
1992 dev_err(&port
->dev
,"%s - cannot send open command, %d\n", __FUNCTION__
, status
);
1996 /* Start the DMA? */
1997 status
= TIWriteCommandSync (dev
,
1999 (u8
)(UMPM_UART1_PORT
+ port_number
),
2004 dev_err(&port
->dev
,"%s - cannot send start DMA command, %d\n", __FUNCTION__
, status
);
2008 /* Clear TX and RX buffers in UMP */
2009 status
= TIPurgeDataSync (port
, UMP_PORT_DIR_OUT
| UMP_PORT_DIR_IN
);
2011 dev_err(&port
->dev
,"%s - cannot send clear buffers command, %d\n", __FUNCTION__
, status
);
2015 /* Read Initial MSR */
2016 status
= TIReadVendorRequestSync (dev
,
2017 UMPC_READ_MSR
, // Request
2019 (__u16
)(UMPM_UART1_PORT
+ port_number
), // wIndex (Address)
2020 &edge_port
->shadow_msr
, // TransferBuffer
2021 1); // TransferBufferLength
2023 dev_err(&port
->dev
,"%s - cannot send read MSR command, %d\n", __FUNCTION__
, status
);
2027 dbg ("ShadowMSR 0x%X", edge_port
->shadow_msr
);
2029 /* Set Initial MCR */
2030 edge_port
->shadow_mcr
= MCR_RTS
| MCR_DTR
;
2031 dbg ("ShadowMCR 0x%X", edge_port
->shadow_mcr
);
2033 edge_serial
= edge_port
->edge_serial
;
2034 if (down_interruptible(&edge_serial
->es_sem
))
2035 return -ERESTARTSYS
;
2036 if (edge_serial
->num_ports_open
== 0) {
2037 /* we are the first port to be opened, let's post the interrupt urb */
2038 urb
= edge_serial
->serial
->port
[0]->interrupt_in_urb
;
2040 dev_err (&port
->dev
, "%s - no interrupt urb present, exiting\n", __FUNCTION__
);
2044 urb
->complete
= edge_interrupt_callback
;
2045 urb
->context
= edge_serial
;
2047 status
= usb_submit_urb (urb
, GFP_KERNEL
);
2049 dev_err (&port
->dev
, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__
, status
);
2055 * reset the data toggle on the bulk endpoints to work around bug in
2056 * host controllers where things get out of sync some times
2058 usb_clear_halt (dev
, port
->write_urb
->pipe
);
2059 usb_clear_halt (dev
, port
->read_urb
->pipe
);
2061 /* start up our bulk read urb */
2062 urb
= port
->read_urb
;
2064 dev_err (&port
->dev
, "%s - no read urb present, exiting\n", __FUNCTION__
);
2066 goto unlink_int_urb
;
2068 edge_port
->ep_read_urb_state
= EDGE_READ_URB_RUNNING
;
2069 urb
->complete
= edge_bulk_in_callback
;
2070 urb
->context
= edge_port
;
2072 status
= usb_submit_urb (urb
, GFP_KERNEL
);
2074 dev_err (&port
->dev
, "%s - read bulk usb_submit_urb failed with value %d\n", __FUNCTION__
, status
);
2075 goto unlink_int_urb
;
2078 ++edge_serial
->num_ports_open
;
2080 dbg("%s - exited", __FUNCTION__
);
2085 if (edge_port
->edge_serial
->num_ports_open
== 0)
2086 usb_kill_urb(port
->serial
->port
[0]->interrupt_in_urb
);
2088 up(&edge_serial
->es_sem
);
2092 static void edge_close (struct usb_serial_port
*port
, struct file
*filp
)
2094 struct edgeport_serial
*edge_serial
;
2095 struct edgeport_port
*edge_port
;
2099 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2101 edge_serial
= usb_get_serial_data(port
->serial
);
2102 edge_port
= usb_get_serial_port_data(port
);
2103 if ((edge_serial
== NULL
) || (edge_port
== NULL
))
2106 /* The bulkreadcompletion routine will check
2107 * this flag and dump add read data */
2108 edge_port
->close_pending
= 1;
2110 /* chase the port close and flush */
2111 TIChasePort (edge_port
, (HZ
*closing_wait
)/100, 1);
2113 usb_kill_urb(port
->read_urb
);
2114 usb_kill_urb(port
->write_urb
);
2115 edge_port
->ep_write_urb_in_use
= 0;
2117 /* assuming we can still talk to the device,
2118 * send a close port command to it */
2119 dbg("%s - send umpc_close_port", __FUNCTION__
);
2120 port_number
= port
->number
- port
->serial
->minor
;
2121 status
= TIWriteCommandSync (port
->serial
->dev
,
2123 (__u8
)(UMPM_UART1_PORT
+ port_number
),
2127 down(&edge_serial
->es_sem
);
2128 --edge_port
->edge_serial
->num_ports_open
;
2129 if (edge_port
->edge_serial
->num_ports_open
<= 0) {
2130 /* last port is now closed, let's shut down our interrupt urb */
2131 usb_kill_urb(port
->serial
->port
[0]->interrupt_in_urb
);
2132 edge_port
->edge_serial
->num_ports_open
= 0;
2134 up(&edge_serial
->es_sem
);
2135 edge_port
->close_pending
= 0;
2137 dbg("%s - exited", __FUNCTION__
);
2140 static int edge_write (struct usb_serial_port
*port
, const unsigned char *data
, int count
)
2142 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2143 unsigned long flags
;
2145 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2148 dbg("%s - write request of 0 bytes", __FUNCTION__
);
2152 if (edge_port
== NULL
)
2154 if (edge_port
->close_pending
== 1)
2157 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2158 count
= edge_buf_put(edge_port
->ep_out_buf
, data
, count
);
2159 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2166 static void edge_send(struct usb_serial_port
*port
)
2169 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2170 struct tty_struct
*tty
= port
->tty
;
2171 unsigned long flags
;
2174 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2176 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2178 if (edge_port
->ep_write_urb_in_use
) {
2179 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2183 count
= edge_buf_get(edge_port
->ep_out_buf
,
2184 port
->write_urb
->transfer_buffer
,
2185 port
->bulk_out_size
);
2188 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2192 edge_port
->ep_write_urb_in_use
= 1;
2194 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2196 usb_serial_debug_data(debug
, &port
->dev
, __FUNCTION__
, count
, port
->write_urb
->transfer_buffer
);
2198 /* set up our urb */
2199 usb_fill_bulk_urb (port
->write_urb
, port
->serial
->dev
,
2200 usb_sndbulkpipe (port
->serial
->dev
,
2201 port
->bulk_out_endpointAddress
),
2202 port
->write_urb
->transfer_buffer
, count
,
2203 edge_bulk_out_callback
,
2206 /* send the data out the bulk port */
2207 result
= usb_submit_urb(port
->write_urb
, GFP_ATOMIC
);
2209 dev_err(&port
->dev
, "%s - failed submitting write urb, error %d\n", __FUNCTION__
, result
);
2210 edge_port
->ep_write_urb_in_use
= 0;
2211 // TODO: reschedule edge_send
2213 edge_port
->icount
.tx
+= count
;
2216 /* wakeup any process waiting for writes to complete */
2217 /* there is now more room in the buffer for new writes */
2219 /* let the tty driver wakeup if it has a special write_wakeup function */
2224 static int edge_write_room (struct usb_serial_port
*port
)
2226 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2228 unsigned long flags
;
2230 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2232 if (edge_port
== NULL
)
2234 if (edge_port
->close_pending
== 1)
2237 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2238 room
= edge_buf_space_avail(edge_port
->ep_out_buf
);
2239 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2241 dbg("%s - returns %d", __FUNCTION__
, room
);
2245 static int edge_chars_in_buffer (struct usb_serial_port
*port
)
2247 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2249 unsigned long flags
;
2251 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2253 if (edge_port
== NULL
)
2255 if (edge_port
->close_pending
== 1)
2258 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2259 chars
= edge_buf_data_avail(edge_port
->ep_out_buf
);
2260 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2262 dbg ("%s - returns %d", __FUNCTION__
, chars
);
2266 static void edge_throttle (struct usb_serial_port
*port
)
2268 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2269 struct tty_struct
*tty
;
2272 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2274 if (edge_port
== NULL
)
2279 dbg ("%s - no tty available", __FUNCTION__
);
2283 /* if we are implementing XON/XOFF, send the stop character */
2285 unsigned char stop_char
= STOP_CHAR(tty
);
2286 status
= edge_write (port
, &stop_char
, 1);
2288 dev_err(&port
->dev
, "%s - failed to write stop character, %d\n", __FUNCTION__
, status
);
2292 /* if we are implementing RTS/CTS, stop reads */
2293 /* and the Edgeport will clear the RTS line */
2295 stop_read(edge_port
);
2299 static void edge_unthrottle (struct usb_serial_port
*port
)
2301 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2302 struct tty_struct
*tty
;
2305 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2307 if (edge_port
== NULL
)
2312 dbg ("%s - no tty available", __FUNCTION__
);
2316 /* if we are implementing XON/XOFF, send the start character */
2318 unsigned char start_char
= START_CHAR(tty
);
2319 status
= edge_write (port
, &start_char
, 1);
2321 dev_err(&port
->dev
, "%s - failed to write start character, %d\n", __FUNCTION__
, status
);
2325 /* if we are implementing RTS/CTS, restart reads */
2326 /* are the Edgeport will assert the RTS line */
2327 if (C_CRTSCTS(tty
)) {
2328 status
= restart_read(edge_port
);
2330 dev_err(&port
->dev
, "%s - read bulk usb_submit_urb failed with value %d\n", __FUNCTION__
, status
);
2335 static void stop_read(struct edgeport_port
*edge_port
)
2337 unsigned long flags
;
2339 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2341 if (edge_port
->ep_read_urb_state
== EDGE_READ_URB_RUNNING
)
2342 edge_port
->ep_read_urb_state
= EDGE_READ_URB_STOPPING
;
2343 edge_port
->shadow_mcr
&= ~MCR_RTS
;
2345 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2348 static int restart_read(struct edgeport_port
*edge_port
)
2352 unsigned long flags
;
2354 spin_lock_irqsave(&edge_port
->ep_lock
, flags
);
2356 if (edge_port
->ep_read_urb_state
== EDGE_READ_URB_STOPPED
) {
2357 urb
= edge_port
->port
->read_urb
;
2358 urb
->complete
= edge_bulk_in_callback
;
2359 urb
->context
= edge_port
;
2360 urb
->dev
= edge_port
->port
->serial
->dev
;
2361 status
= usb_submit_urb(urb
, GFP_KERNEL
);
2363 edge_port
->ep_read_urb_state
= EDGE_READ_URB_RUNNING
;
2364 edge_port
->shadow_mcr
|= MCR_RTS
;
2366 spin_unlock_irqrestore(&edge_port
->ep_lock
, flags
);
2371 static void change_port_settings (struct edgeport_port
*edge_port
, struct termios
*old_termios
)
2373 struct ump_uart_config
*config
;
2374 struct tty_struct
*tty
;
2378 int port_number
= edge_port
->port
->number
- edge_port
->port
->serial
->minor
;
2380 dbg("%s - port %d", __FUNCTION__
, edge_port
->port
->number
);
2382 tty
= edge_port
->port
->tty
;
2385 dbg("%s - no tty structures", __FUNCTION__
);
2389 config
= kmalloc (sizeof (*config
), GFP_KERNEL
);
2391 dev_err (&edge_port
->port
->dev
, "%s - out of memory\n", __FUNCTION__
);
2395 cflag
= tty
->termios
->c_cflag
;
2399 /* These flags must be set */
2400 config
->wFlags
|= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT
;
2401 config
->wFlags
|= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR
;
2402 config
->bUartMode
= (__u8
)(edge_port
->bUartMode
);
2404 switch (cflag
& CSIZE
) {
2406 config
->bDataBits
= UMP_UART_CHAR5BITS
;
2407 dbg ("%s - data bits = 5", __FUNCTION__
);
2410 config
->bDataBits
= UMP_UART_CHAR6BITS
;
2411 dbg ("%s - data bits = 6", __FUNCTION__
);
2414 config
->bDataBits
= UMP_UART_CHAR7BITS
;
2415 dbg ("%s - data bits = 7", __FUNCTION__
);
2419 config
->bDataBits
= UMP_UART_CHAR8BITS
;
2420 dbg ("%s - data bits = 8", __FUNCTION__
);
2424 if (cflag
& PARENB
) {
2425 if (cflag
& PARODD
) {
2426 config
->wFlags
|= UMP_MASK_UART_FLAGS_PARITY
;
2427 config
->bParity
= UMP_UART_ODDPARITY
;
2428 dbg("%s - parity = odd", __FUNCTION__
);
2430 config
->wFlags
|= UMP_MASK_UART_FLAGS_PARITY
;
2431 config
->bParity
= UMP_UART_EVENPARITY
;
2432 dbg("%s - parity = even", __FUNCTION__
);
2435 config
->bParity
= UMP_UART_NOPARITY
;
2436 dbg("%s - parity = none", __FUNCTION__
);
2439 if (cflag
& CSTOPB
) {
2440 config
->bStopBits
= UMP_UART_STOPBIT2
;
2441 dbg("%s - stop bits = 2", __FUNCTION__
);
2443 config
->bStopBits
= UMP_UART_STOPBIT1
;
2444 dbg("%s - stop bits = 1", __FUNCTION__
);
2447 /* figure out the flow control settings */
2448 if (cflag
& CRTSCTS
) {
2449 config
->wFlags
|= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW
;
2450 config
->wFlags
|= UMP_MASK_UART_FLAGS_RTS_FLOW
;
2451 dbg("%s - RTS/CTS is enabled", __FUNCTION__
);
2453 dbg("%s - RTS/CTS is disabled", __FUNCTION__
);
2454 tty
->hw_stopped
= 0;
2455 restart_read(edge_port
);
2458 /* if we are implementing XON/XOFF, set the start and stop character in the device */
2459 if (I_IXOFF(tty
) || I_IXON(tty
)) {
2460 config
->cXon
= START_CHAR(tty
);
2461 config
->cXoff
= STOP_CHAR(tty
);
2463 /* if we are implementing INBOUND XON/XOFF */
2465 config
->wFlags
|= UMP_MASK_UART_FLAGS_IN_X
;
2466 dbg ("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2467 __FUNCTION__
, config
->cXon
, config
->cXoff
);
2469 dbg ("%s - INBOUND XON/XOFF is disabled", __FUNCTION__
);
2472 /* if we are implementing OUTBOUND XON/XOFF */
2474 config
->wFlags
|= UMP_MASK_UART_FLAGS_OUT_X
;
2475 dbg ("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2476 __FUNCTION__
, config
->cXon
, config
->cXoff
);
2478 dbg ("%s - OUTBOUND XON/XOFF is disabled", __FUNCTION__
);
2482 /* Round the baud rate */
2483 baud
= tty_get_baud_rate(tty
);
2485 /* pick a default, any default... */
2488 edge_port
->baud_rate
= baud
;
2489 config
->wBaudRate
= (__u16
)((461550L + baud
/2) / baud
);
2491 dbg ("%s - baud rate = %d, wBaudRate = %d", __FUNCTION__
, baud
, config
->wBaudRate
);
2493 dbg ("wBaudRate: %d", (int)(461550L / config
->wBaudRate
));
2494 dbg ("wFlags: 0x%x", config
->wFlags
);
2495 dbg ("bDataBits: %d", config
->bDataBits
);
2496 dbg ("bParity: %d", config
->bParity
);
2497 dbg ("bStopBits: %d", config
->bStopBits
);
2498 dbg ("cXon: %d", config
->cXon
);
2499 dbg ("cXoff: %d", config
->cXoff
);
2500 dbg ("bUartMode: %d", config
->bUartMode
);
2502 /* move the word values into big endian mode */
2503 cpu_to_be16s (&config
->wFlags
);
2504 cpu_to_be16s (&config
->wBaudRate
);
2506 status
= TIWriteCommandSync (edge_port
->port
->serial
->dev
,
2508 (__u8
)(UMPM_UART1_PORT
+ port_number
),
2513 dbg ("%s - error %d when trying to write config to device",
2514 __FUNCTION__
, status
);
2522 static void edge_set_termios (struct usb_serial_port
*port
, struct termios
*old_termios
)
2524 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2525 struct tty_struct
*tty
= port
->tty
;
2528 if (!port
->tty
|| !port
->tty
->termios
) {
2529 dbg ("%s - no tty or termios", __FUNCTION__
);
2533 cflag
= tty
->termios
->c_cflag
;
2534 /* check that they really want us to change something */
2536 if (cflag
== old_termios
->c_cflag
&&
2537 tty
->termios
->c_iflag
== old_termios
->c_iflag
) {
2538 dbg ("%s - nothing to change", __FUNCTION__
);
2543 dbg("%s - clfag %08x iflag %08x", __FUNCTION__
,
2544 tty
->termios
->c_cflag
, tty
->termios
->c_iflag
);
2546 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__
,
2547 old_termios
->c_cflag
, old_termios
->c_iflag
);
2550 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2552 if (edge_port
== NULL
)
2555 /* change the port settings to the new ones specified */
2556 change_port_settings (edge_port
, old_termios
);
2561 static int edge_tiocmset (struct usb_serial_port
*port
, struct file
*file
, unsigned int set
, unsigned int clear
)
2563 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2566 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2568 mcr
= edge_port
->shadow_mcr
;
2569 if (set
& TIOCM_RTS
)
2571 if (set
& TIOCM_DTR
)
2573 if (set
& TIOCM_LOOP
)
2574 mcr
|= MCR_LOOPBACK
;
2576 if (clear
& TIOCM_RTS
)
2578 if (clear
& TIOCM_DTR
)
2580 if (clear
& TIOCM_LOOP
)
2581 mcr
&= ~MCR_LOOPBACK
;
2583 edge_port
->shadow_mcr
= mcr
;
2585 TIRestoreMCR (edge_port
, mcr
);
2590 static int edge_tiocmget(struct usb_serial_port
*port
, struct file
*file
)
2592 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2593 unsigned int result
= 0;
2597 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2599 msr
= edge_port
->shadow_msr
;
2600 mcr
= edge_port
->shadow_mcr
;
2601 result
= ((mcr
& MCR_DTR
) ? TIOCM_DTR
: 0) /* 0x002 */
2602 | ((mcr
& MCR_RTS
) ? TIOCM_RTS
: 0) /* 0x004 */
2603 | ((msr
& EDGEPORT_MSR_CTS
) ? TIOCM_CTS
: 0) /* 0x020 */
2604 | ((msr
& EDGEPORT_MSR_CD
) ? TIOCM_CAR
: 0) /* 0x040 */
2605 | ((msr
& EDGEPORT_MSR_RI
) ? TIOCM_RI
: 0) /* 0x080 */
2606 | ((msr
& EDGEPORT_MSR_DSR
) ? TIOCM_DSR
: 0); /* 0x100 */
2609 dbg("%s -- %x", __FUNCTION__
, result
);
2614 static int get_serial_info (struct edgeport_port
*edge_port
, struct serial_struct __user
*retinfo
)
2616 struct serial_struct tmp
;
2621 memset(&tmp
, 0, sizeof(tmp
));
2623 tmp
.type
= PORT_16550A
;
2624 tmp
.line
= edge_port
->port
->serial
->minor
;
2625 tmp
.port
= edge_port
->port
->number
;
2627 tmp
.flags
= ASYNC_SKIP_TEST
| ASYNC_AUTO_IRQ
;
2628 tmp
.xmit_fifo_size
= edge_port
->port
->bulk_out_size
;
2629 tmp
.baud_base
= 9600;
2630 tmp
.close_delay
= 5*HZ
;
2631 tmp
.closing_wait
= closing_wait
;
2632 // tmp.custom_divisor = state->custom_divisor;
2633 // tmp.hub6 = state->hub6;
2634 // tmp.io_type = state->io_type;
2637 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2642 static int edge_ioctl (struct usb_serial_port
*port
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
2644 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2645 struct async_icount cnow
;
2646 struct async_icount cprev
;
2648 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__
, port
->number
, cmd
);
2652 dbg("%s - (%d) TIOCINQ", __FUNCTION__
, port
->number
);
2653 // return get_number_bytes_avail(edge_port, (unsigned int *) arg);
2657 dbg("%s - (%d) TIOCSERGETLSR", __FUNCTION__
, port
->number
);
2658 // return get_lsr_info(edge_port, (unsigned int *) arg);
2662 dbg("%s - (%d) TIOCGSERIAL", __FUNCTION__
, port
->number
);
2663 return get_serial_info(edge_port
, (struct serial_struct __user
*) arg
);
2667 dbg("%s - (%d) TIOCSSERIAL", __FUNCTION__
, port
->number
);
2671 dbg("%s - (%d) TIOCMIWAIT", __FUNCTION__
, port
->number
);
2672 cprev
= edge_port
->icount
;
2674 interruptible_sleep_on(&edge_port
->delta_msr_wait
);
2675 /* see if a signal did it */
2676 if (signal_pending(current
))
2677 return -ERESTARTSYS
;
2678 cnow
= edge_port
->icount
;
2679 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
2680 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
2681 return -EIO
; /* no change => error */
2682 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
2683 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
2684 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
2685 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
2694 dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__
,
2695 port
->number
, edge_port
->icount
.rx
, edge_port
->icount
.tx
);
2696 if (copy_to_user((void __user
*)arg
, &edge_port
->icount
, sizeof(edge_port
->icount
)))
2701 return -ENOIOCTLCMD
;
2704 static void edge_break (struct usb_serial_port
*port
, int break_state
)
2706 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2709 dbg ("%s - state = %d", __FUNCTION__
, break_state
);
2711 /* chase the port close */
2712 TIChasePort (edge_port
, 0, 0);
2714 if (break_state
== -1) {
2715 status
= TISetBreak (edge_port
);
2717 status
= TIClearBreak (edge_port
);
2720 dbg ("%s - error %d sending break set/clear command.",
2721 __FUNCTION__
, status
);
2725 static int edge_startup (struct usb_serial
*serial
)
2727 struct edgeport_serial
*edge_serial
;
2728 struct edgeport_port
*edge_port
;
2729 struct usb_device
*dev
;
2735 /* create our private serial structure */
2736 edge_serial
= kmalloc (sizeof(struct edgeport_serial
), GFP_KERNEL
);
2737 if (edge_serial
== NULL
) {
2738 dev_err(&serial
->dev
->dev
, "%s - Out of memory\n", __FUNCTION__
);
2741 memset (edge_serial
, 0, sizeof(struct edgeport_serial
));
2742 sema_init(&edge_serial
->es_sem
, 1);
2743 edge_serial
->serial
= serial
;
2744 usb_set_serial_data(serial
, edge_serial
);
2746 status
= TIDownloadFirmware (edge_serial
);
2748 kfree (edge_serial
);
2752 /* set up our port private structures */
2753 for (i
= 0; i
< serial
->num_ports
; ++i
) {
2754 edge_port
= kmalloc (sizeof(struct edgeport_port
), GFP_KERNEL
);
2755 if (edge_port
== NULL
) {
2756 dev_err(&serial
->dev
->dev
, "%s - Out of memory\n", __FUNCTION__
);
2759 memset (edge_port
, 0, sizeof(struct edgeport_port
));
2760 spin_lock_init(&edge_port
->ep_lock
);
2761 edge_port
->ep_out_buf
= edge_buf_alloc(EDGE_OUT_BUF_SIZE
);
2762 if (edge_port
->ep_out_buf
== NULL
) {
2763 dev_err(&serial
->dev
->dev
, "%s - Out of memory\n", __FUNCTION__
);
2767 edge_port
->port
= serial
->port
[i
];
2768 edge_port
->edge_serial
= edge_serial
;
2769 usb_set_serial_port_data(serial
->port
[i
], edge_port
);
2770 edge_port
->bUartMode
= 0; /* Default is RS232 */
2776 for (--i
; i
>=0; --i
) {
2777 edge_port
= usb_get_serial_port_data(serial
->port
[i
]);
2778 edge_buf_free(edge_port
->ep_out_buf
);
2780 usb_set_serial_port_data(serial
->port
[i
], NULL
);
2782 kfree (edge_serial
);
2783 usb_set_serial_data(serial
, NULL
);
2787 static void edge_shutdown (struct usb_serial
*serial
)
2790 struct edgeport_port
*edge_port
;
2792 dbg ("%s", __FUNCTION__
);
2794 for (i
=0; i
< serial
->num_ports
; ++i
) {
2795 edge_port
= usb_get_serial_port_data(serial
->port
[i
]);
2797 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 /* Circular Buffer */
2812 * Allocate a circular buffer and all associated memory.
2815 static struct edge_buf
*edge_buf_alloc(unsigned int size
)
2817 struct edge_buf
*eb
;
2823 eb
= (struct edge_buf
*)kmalloc(sizeof(struct edge_buf
), GFP_KERNEL
);
2827 eb
->buf_buf
= kmalloc(size
, GFP_KERNEL
);
2828 if (eb
->buf_buf
== NULL
) {
2833 eb
->buf_size
= size
;
2834 eb
->buf_get
= eb
->buf_put
= eb
->buf_buf
;
2843 * Free the buffer and all associated memory.
2846 void edge_buf_free(struct edge_buf
*eb
)
2858 * Clear out all data in the circular buffer.
2861 static void edge_buf_clear(struct edge_buf
*eb
)
2864 eb
->buf_get
= eb
->buf_put
;
2865 /* equivalent to a get of all data available */
2870 * edge_buf_data_avail
2872 * Return the number of bytes of data available in the circular
2876 static unsigned int edge_buf_data_avail(struct edge_buf
*eb
)
2879 return ((eb
->buf_size
+ eb
->buf_put
- eb
->buf_get
) % eb
->buf_size
);
2886 * edge_buf_space_avail
2888 * Return the number of bytes of space available in the circular
2892 static unsigned int edge_buf_space_avail(struct edge_buf
*eb
)
2895 return ((eb
->buf_size
+ eb
->buf_get
- eb
->buf_put
- 1) % eb
->buf_size
);
2904 * Copy data data from a user buffer and put it into the circular buffer.
2905 * Restrict to the amount of space available.
2907 * Return the number of bytes copied.
2910 static unsigned int edge_buf_put(struct edge_buf
*eb
, const char *buf
,
2919 len
= edge_buf_space_avail(eb
);
2926 len
= eb
->buf_buf
+ eb
->buf_size
- eb
->buf_put
;
2928 memcpy(eb
->buf_put
, buf
, len
);
2929 memcpy(eb
->buf_buf
, buf
+len
, count
- len
);
2930 eb
->buf_put
= eb
->buf_buf
+ count
- len
;
2932 memcpy(eb
->buf_put
, buf
, count
);
2934 eb
->buf_put
+= count
;
2935 else /* count == len */
2936 eb
->buf_put
= eb
->buf_buf
;
2946 * Get data from the circular buffer and copy to the given buffer.
2947 * Restrict to the amount of data available.
2949 * Return the number of bytes copied.
2952 static unsigned int edge_buf_get(struct edge_buf
*eb
, char *buf
,
2961 len
= edge_buf_data_avail(eb
);
2968 len
= eb
->buf_buf
+ eb
->buf_size
- eb
->buf_get
;
2970 memcpy(buf
, eb
->buf_get
, len
);
2971 memcpy(buf
+len
, eb
->buf_buf
, count
- len
);
2972 eb
->buf_get
= eb
->buf_buf
+ count
- len
;
2974 memcpy(buf
, eb
->buf_get
, count
);
2976 eb
->buf_get
+= count
;
2977 else /* count == len */
2978 eb
->buf_get
= eb
->buf_buf
;
2985 static struct usb_serial_device_type edgeport_1port_device
= {
2986 .owner
= THIS_MODULE
,
2987 .name
= "Edgeport TI 1 port adapter",
2988 .short_name
= "edgeport_ti_1",
2989 .id_table
= edgeport_1port_id_table
,
2990 .num_interrupt_in
= 1,
2995 .close
= edge_close
,
2996 .throttle
= edge_throttle
,
2997 .unthrottle
= edge_unthrottle
,
2998 .attach
= edge_startup
,
2999 .shutdown
= edge_shutdown
,
3000 .ioctl
= edge_ioctl
,
3001 .set_termios
= edge_set_termios
,
3002 .tiocmget
= edge_tiocmget
,
3003 .tiocmset
= edge_tiocmset
,
3004 .write
= edge_write
,
3005 .write_room
= edge_write_room
,
3006 .chars_in_buffer
= edge_chars_in_buffer
,
3007 .break_ctl
= edge_break
,
3008 .read_int_callback
= edge_interrupt_callback
,
3009 .read_bulk_callback
= edge_bulk_in_callback
,
3010 .write_bulk_callback
= edge_bulk_out_callback
,
3013 static struct usb_serial_device_type edgeport_2port_device
= {
3014 .owner
= THIS_MODULE
,
3015 .name
= "Edgeport TI 2 port adapter",
3016 .short_name
= "edgeport_ti_2",
3017 .id_table
= edgeport_2port_id_table
,
3018 .num_interrupt_in
= 1,
3023 .close
= edge_close
,
3024 .throttle
= edge_throttle
,
3025 .unthrottle
= edge_unthrottle
,
3026 .attach
= edge_startup
,
3027 .shutdown
= edge_shutdown
,
3028 .ioctl
= edge_ioctl
,
3029 .set_termios
= edge_set_termios
,
3030 .tiocmget
= edge_tiocmget
,
3031 .tiocmset
= edge_tiocmset
,
3032 .write
= edge_write
,
3033 .write_room
= edge_write_room
,
3034 .chars_in_buffer
= edge_chars_in_buffer
,
3035 .break_ctl
= edge_break
,
3036 .read_int_callback
= edge_interrupt_callback
,
3037 .read_bulk_callback
= edge_bulk_in_callback
,
3038 .write_bulk_callback
= edge_bulk_out_callback
,
3042 static int __init
edgeport_init(void)
3045 retval
= usb_serial_register(&edgeport_1port_device
);
3047 goto failed_1port_device_register
;
3048 retval
= usb_serial_register(&edgeport_2port_device
);
3050 goto failed_2port_device_register
;
3051 retval
= usb_register(&io_driver
);
3053 goto failed_usb_register
;
3054 info(DRIVER_DESC
" " DRIVER_VERSION
);
3056 failed_usb_register
:
3057 usb_serial_deregister(&edgeport_2port_device
);
3058 failed_2port_device_register
:
3059 usb_serial_deregister(&edgeport_1port_device
);
3060 failed_1port_device_register
:
3064 static void __exit
edgeport_exit (void)
3066 usb_deregister (&io_driver
);
3067 usb_serial_deregister (&edgeport_1port_device
);
3068 usb_serial_deregister (&edgeport_2port_device
);
3071 module_init(edgeport_init
);
3072 module_exit(edgeport_exit
);
3074 /* Module information */
3075 MODULE_AUTHOR(DRIVER_AUTHOR
);
3076 MODULE_DESCRIPTION(DRIVER_DESC
);
3077 MODULE_LICENSE("GPL");
3079 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
3080 MODULE_PARM_DESC(debug
, "Debug enabled or not");
3082 module_param(low_latency
, bool, S_IRUGO
| S_IWUSR
);
3083 MODULE_PARM_DESC(low_latency
, "Low latency enabled or not");
3085 module_param(closing_wait
, int, S_IRUGO
| S_IWUSR
);
3086 MODULE_PARM_DESC(closing_wait
, "Maximum wait for data to drain, in .01 secs");
3088 module_param(ignore_cpu_rev
, bool, S_IRUGO
| S_IWUSR
);
3089 MODULE_PARM_DESC(ignore_cpu_rev
, "Ignore the cpu revision when connecting to a device");