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:
17 * July 11, 2002 Removed 4 port device structure since all TI UMP
18 * chips have only 2 ports
19 * David Iacovelli (davidi@ionetworks.com)
23 #include <linux/config.h>
24 #include <linux/kernel.h>
25 #include <linux/jiffies.h>
26 #include <linux/errno.h>
27 #include <linux/init.h>
28 #include <linux/slab.h>
29 #include <linux/tty.h>
30 #include <linux/tty_driver.h>
31 #include <linux/tty_flip.h>
32 #include <linux/module.h>
33 #include <linux/spinlock.h>
34 #include <linux/serial.h>
35 #include <linux/ioctl.h>
36 #include <asm/uaccess.h>
37 #include <linux/usb.h>
38 #include "usb-serial.h"
40 #include "io_usbvend.h"
48 #define DRIVER_VERSION "v0.2"
49 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
50 #define DRIVER_DESC "Edgeport USB Serial Driver"
53 /* firmware image code */
54 #define IMAGE_VERSION_NAME PagableOperationalCodeImageVersion
55 #define IMAGE_ARRAY_NAME PagableOperationalCodeImage
56 #define IMAGE_SIZE PagableOperationalCodeSize
57 #include "io_fw_down3.h" /* Define array OperationalCodeImage[] */
59 #define EPROM_PAGE_SIZE 64
62 struct edgeport_uart_buf_desc
{
63 __u32 count
; // Number of bytes currently in buffer
66 /* different hardware types */
67 #define HARDWARE_TYPE_930 0
68 #define HARDWARE_TYPE_TIUMP 1
70 // IOCTL_PRIVATE_TI_GET_MODE Definitions
71 #define TI_MODE_CONFIGURING 0 // Device has not entered start device
72 #define TI_MODE_BOOT 1 // Staying in boot mode
73 #define TI_MODE_DOWNLOAD 2 // Made it to download mode
74 #define TI_MODE_TRANSITIONING 3 // Currently in boot mode but transitioning to download mode
77 /* Product information read from the Edgeport */
80 int TiMode
; // Current TI Mode
81 __u8 hardware_type
; // Type of hardware
82 } __attribute__((packed
));
85 struct edgeport_port
{
92 __u32 ump_read_timeout
; /* Number of miliseconds the UMP will
93 wait without data before completing
98 struct edgeport_uart_buf_desc tx
;
99 struct async_icount icount
;
100 wait_queue_head_t delta_msr_wait
; /* for handling sleeping while
101 waiting for msr change to
103 struct edgeport_serial
*edge_serial
;
104 struct usb_serial_port
*port
;
107 struct edgeport_serial
{
108 struct product_info product_info
;
109 u8 TI_I2C_Type
; // Type of I2C in UMP
110 u8 TiReadI2C
; // Set to TRUE if we have read the I2c in Boot Mode
112 struct usb_serial
*serial
;
116 /* Devices that this driver supports */
117 static struct usb_device_id edgeport_1port_id_table
[] = {
118 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_1
) },
122 static struct usb_device_id edgeport_2port_id_table
[] = {
123 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2
) },
124 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2C
) },
125 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2I
) },
126 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_421
) },
127 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21
) },
128 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_42
) },
129 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4
) },
130 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4I
) },
131 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22I
) },
135 /* Devices that this driver supports */
136 static struct usb_device_id id_table_combined
[] = {
137 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_1
) },
138 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2
) },
139 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2C
) },
140 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_2I
) },
141 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_421
) },
142 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_21
) },
143 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_42
) },
144 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4
) },
145 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_4I
) },
146 { USB_DEVICE(USB_VENDOR_ID_ION
, ION_DEVICE_ID_TI_EDGEPORT_22I
) },
150 MODULE_DEVICE_TABLE (usb
, id_table_combined
);
152 static struct usb_driver io_driver
= {
153 .owner
= THIS_MODULE
,
155 .probe
= usb_serial_probe
,
156 .disconnect
= usb_serial_disconnect
,
157 .id_table
= id_table_combined
,
161 static struct EDGE_FIRMWARE_VERSION_INFO OperationalCodeImageVersion
;
163 static int TIStayInBootMode
= 0;
164 static int ignore_cpu_rev
= 0;
168 static void edge_set_termios (struct usb_serial_port
*port
, struct termios
*old_termios
);
170 static int TIReadVendorRequestSync (struct usb_device
*dev
,
179 status
= usb_control_msg (dev
,
180 usb_rcvctrlpipe(dev
, 0),
192 if (status
!= size
) {
193 dbg ("%s - wanted to write %d, but only wrote %d",
194 __FUNCTION__
, size
, status
);
200 static int TISendVendorRequestSync (struct usb_device
*dev
,
209 status
= usb_control_msg (dev
,
210 usb_sndctrlpipe(dev
, 0),
223 if (status
!= size
) {
224 dbg ("%s - wanted to write %d, but only wrote %d",
225 __FUNCTION__
, size
, status
);
231 static int TIWriteCommandSync (struct usb_device
*dev
, __u8 command
,
232 __u8 moduleid
, __u16 value
, u8
*data
,
235 return TISendVendorRequestSync (dev
,
239 data
, // TransferBuffer
240 size
); // TransferBufferLength
245 /* clear tx/rx buffers and fifo in TI UMP */
246 static int TIPurgeDataSync (struct usb_serial_port
*port
, __u16 mask
)
248 int port_number
= port
->number
- port
->serial
->minor
;
250 dbg ("%s - port %d, mask %x", __FUNCTION__
, port_number
, mask
);
252 return TIWriteCommandSync (port
->serial
->dev
,
254 (__u8
)(UMPM_UART1_PORT
+ port_number
),
261 * TIReadDownloadMemory - Read edgeport memory from TI chip
262 * @dev: usb device pointer
263 * @start_address: Device CPU address at which to read
264 * @length: Length of above data
265 * @address_type: Can read both XDATA and I2C
266 * @buffer: pointer to input data buffer
268 static int TIReadDownloadMemory(struct usb_device
*dev
, int start_address
,
269 int length
, __u8 address_type
, __u8
*buffer
)
273 __be16 be_start_address
;
275 dbg ("%s - @ %x for %d", __FUNCTION__
, start_address
, length
);
277 /* Read in blocks of 64 bytes
278 * (TI firmware can't handle more than 64 byte reads)
284 read_length
= (__u8
)length
;
286 if (read_length
> 1) {
287 dbg ("%s - @ %x for %d", __FUNCTION__
,
288 start_address
, read_length
);
290 be_start_address
= cpu_to_be16 (start_address
);
291 status
= TIReadVendorRequestSync (dev
,
292 UMPC_MEMORY_READ
, // Request
293 (__u16
)address_type
, // wValue (Address type)
294 be_start_address
, // wIndex (Address to read)
295 buffer
, // TransferBuffer
296 read_length
); // TransferBufferLength
299 dbg ("%s - ERROR %x", __FUNCTION__
, status
);
303 if (read_length
> 1) {
304 usb_serial_debug_data(debug
, &dev
->dev
, __FUNCTION__
,
305 read_length
, buffer
);
308 /* Update pointers/length */
309 start_address
+= read_length
;
310 buffer
+= read_length
;
311 length
-= read_length
;
317 static int TIReadRam (struct usb_device
*dev
, int start_address
, int length
, __u8
*buffer
)
319 return TIReadDownloadMemory (dev
,
322 DTK_ADDR_SPACE_XDATA
,
326 /* Read edgeport memory to a given block */
327 static int TIReadBootMemory (struct edgeport_serial
*serial
, int start_address
, int length
, __u8
* buffer
)
332 for (i
=0; i
< length
; i
++) {
333 status
= TIReadVendorRequestSync (serial
->serial
->dev
,
334 UMPC_MEMORY_READ
, // Request
335 serial
->TI_I2C_Type
, // wValue (Address type)
336 (__u16
)(start_address
+i
), // wIndex
337 &buffer
[i
], // TransferBuffer
338 0x01); // TransferBufferLength
340 dbg ("%s - ERROR %x", __FUNCTION__
, status
);
345 dbg ("%s - start_address = %x, length = %d", __FUNCTION__
, start_address
, length
);
346 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
, __FUNCTION__
, length
, buffer
);
348 serial
->TiReadI2C
= 1;
353 /* Write given block to TI EPROM memory */
354 static int TIWriteBootMemory (struct edgeport_serial
*serial
, int start_address
, int length
, __u8
*buffer
)
360 /* Must do a read before write */
361 if (!serial
->TiReadI2C
) {
362 status
= TIReadBootMemory(serial
, 0, 1, &temp
);
367 for (i
=0; i
< length
; ++i
) {
368 status
= TISendVendorRequestSync (serial
->serial
->dev
,
369 UMPC_MEMORY_WRITE
, // Request
371 (__u16
)(i
+start_address
), // wIndex
372 NULL
, // TransferBuffer
373 0); // TransferBufferLength
378 dbg ("%s - start_sddr = %x, length = %d", __FUNCTION__
, start_address
, length
);
379 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
, __FUNCTION__
, length
, buffer
);
385 /* Write edgeport I2C memory to TI chip */
386 static int TIWriteDownloadI2C (struct edgeport_serial
*serial
, int start_address
, int length
, __u8 address_type
, __u8
*buffer
)
390 __be16 be_start_address
;
392 /* We can only send a maximum of 1 aligned byte page at a time */
394 /* calulate the number of bytes left in the first page */
395 write_length
= EPROM_PAGE_SIZE
- (start_address
& (EPROM_PAGE_SIZE
- 1));
397 if (write_length
> length
)
398 write_length
= length
;
400 dbg ("%s - BytesInFirstPage Addr = %x, length = %d", __FUNCTION__
, start_address
, write_length
);
401 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
, __FUNCTION__
, write_length
, buffer
);
403 /* Write first page */
404 be_start_address
= cpu_to_be16 (start_address
);
405 status
= TISendVendorRequestSync (serial
->serial
->dev
,
406 UMPC_MEMORY_WRITE
, // Request
407 (__u16
)address_type
, // wValue
408 be_start_address
, // wIndex
409 buffer
, // TransferBuffer
412 dbg ("%s - ERROR %d", __FUNCTION__
, status
);
416 length
-= write_length
;
417 start_address
+= write_length
;
418 buffer
+= write_length
;
420 /* We should be aligned now -- can write max page size bytes at a time */
422 if (length
> EPROM_PAGE_SIZE
)
423 write_length
= EPROM_PAGE_SIZE
;
425 write_length
= length
;
427 dbg ("%s - Page Write Addr = %x, length = %d", __FUNCTION__
, start_address
, write_length
);
428 usb_serial_debug_data(debug
, &serial
->serial
->dev
->dev
, __FUNCTION__
, write_length
, buffer
);
430 /* Write next page */
431 be_start_address
= cpu_to_be16 (start_address
);
432 status
= TISendVendorRequestSync (serial
->serial
->dev
,
433 UMPC_MEMORY_WRITE
, // Request
434 (__u16
)address_type
, // wValue
435 be_start_address
, // wIndex
436 buffer
, // TransferBuffer
437 write_length
); // TransferBufferLength
439 dbg ("%s - ERROR %d", __FUNCTION__
, status
);
443 length
-= write_length
;
444 start_address
+= write_length
;
445 buffer
+= write_length
;
450 /* Examine the UMP DMA registers and LSR
452 * Check the MSBit of the X and Y DMA byte count registers.
453 * A zero in this bit indicates that the TX DMA buffers are empty
454 * then check the TX Empty bit in the UART.
456 static int TIIsTxActive (struct edgeport_port
*port
)
459 struct out_endpoint_desc_block
*oedb
;
463 oedb
= kmalloc (sizeof (* oedb
), GFP_KERNEL
);
465 dev_err (&port
->port
->dev
, "%s - out of memory\n", __FUNCTION__
);
469 lsr
= kmalloc (1, GFP_KERNEL
); /* Sigh, that's right, just one byte,
470 as not all platforms can do DMA
476 /* Read the DMA Count Registers */
477 status
= TIReadRam (port
->port
->serial
->dev
,
483 goto exit_is_tx_active
;
485 dbg ("%s - XByteCount 0x%X", __FUNCTION__
, oedb
->XByteCount
);
488 status
= TIReadRam (port
->port
->serial
->dev
,
489 port
->uart_base
+ UMPMEM_OFFS_UART_LSR
,
494 goto exit_is_tx_active
;
495 dbg ("%s - LSR = 0x%X", __FUNCTION__
, *lsr
);
497 /* If either buffer has data or we are transmitting then return TRUE */
498 if ((oedb
->XByteCount
& 0x80 ) != 0 )
501 if ((*lsr
& UMP_UART_LSR_TX_MASK
) == 0 )
504 /* We return Not Active if we get any kind of error */
506 dbg ("%s - return %d", __FUNCTION__
, bytes_left
);
513 static void TIChasePort(struct edgeport_port
*port
)
520 // Base the LoopTime on the baud rate
521 if (port
->baud_rate
== 0)
522 port
->baud_rate
= 1200;
524 write_size
= port
->tx
.count
;
525 loops
= max(100, (100*write_size
)/(port
->baud_rate
/10));
526 dbg ("%s - write_size %d, baud %d loop = %d", __FUNCTION__
,
527 write_size
, port
->baud_rate
, loops
);
531 last_count
= port
->tx
.count
;
533 dbg ("%s - Tx Buffer Size = %d loops = %d", __FUNCTION__
,
536 /* Is the Edgeport Buffer empty? */
537 if (port
->tx
.count
== 0)
540 /* Block the thread for 10ms */
543 if (last_count
== port
->tx
.count
) {
544 /* No activity.. count down. */
547 dbg ("%s - Wait for TxEmpty - TIMEOUT",
552 /* Reset timeout value back to a minimum of 1 second */
553 dbg ("%s - Wait for TxEmpty Reset Count", __FUNCTION__
);
554 goto restart_tx_loop
;
558 dbg ("%s - Local Tx Buffer Empty -- Waiting for TI UMP to EMPTY X/Y and FIFO",
561 write_size
= TIIsTxActive (port
);
562 loops
= max(50, (100*write_size
)/(port
->baud_rate
/10));
563 dbg ("%s - write_size %d, baud %d loop = %d", __FUNCTION__
,
564 write_size
, port
->baud_rate
, loops
);
567 /* This function takes 4 ms; */
568 if (!TIIsTxActive (port
)) {
569 /* Delay a few char times */
571 dbg ("%s - Empty", __FUNCTION__
);
577 dbg ("%s - TIMEOUT", __FUNCTION__
);
583 static int TIChooseConfiguration (struct usb_device
*dev
)
585 // There may be multiple configurations on this device, in which case
586 // we would need to read and parse all of them to find out which one
587 // we want. However, we just support one config at this point,
588 // configuration # 1, which is Config Descriptor 0.
590 dbg ("%s - Number of Interfaces = %d", __FUNCTION__
, dev
->config
->desc
.bNumInterfaces
);
591 dbg ("%s - MAX Power = %d", __FUNCTION__
, dev
->config
->desc
.bMaxPower
*2);
593 if (dev
->config
->desc
.bNumInterfaces
!= 1) {
594 dev_err (&dev
->dev
, "%s - bNumInterfaces is not 1, ERROR!\n", __FUNCTION__
);
601 static int TIReadRom (struct edgeport_serial
*serial
, int start_address
, int length
, __u8
*buffer
)
605 if (serial
->product_info
.TiMode
== TI_MODE_DOWNLOAD
) {
606 status
= TIReadDownloadMemory (serial
->serial
->dev
,
612 status
= TIReadBootMemory (serial
,
621 static int TIWriteRom (struct edgeport_serial
*serial
, int start_address
, int length
, __u8
*buffer
)
623 if (serial
->product_info
.TiMode
== TI_MODE_BOOT
)
624 return TIWriteBootMemory (serial
,
629 if (serial
->product_info
.TiMode
== TI_MODE_DOWNLOAD
)
630 return TIWriteDownloadI2C (serial
,
641 /* Read a descriptor header from I2C based on type */
642 static int TIGetDescriptorAddress (struct edgeport_serial
*serial
, int desc_type
, struct ti_i2c_desc
*rom_desc
)
647 /* Search for requested descriptor in I2C */
650 status
= TIReadRom (serial
,
652 sizeof(struct ti_i2c_desc
),
657 if (rom_desc
->Type
== desc_type
)
658 return start_address
;
660 start_address
= start_address
+ sizeof(struct ti_i2c_desc
) + rom_desc
->Size
;
662 } while ((start_address
< TI_MAX_I2C_SIZE
) && rom_desc
->Type
);
667 /* Validate descriptor checksum */
668 static int ValidChecksum(struct ti_i2c_desc
*rom_desc
, __u8
*buffer
)
673 for (i
=0; i
< rom_desc
->Size
; i
++) {
674 cs
= (__u8
)(cs
+ buffer
[i
]);
676 if (cs
!= rom_desc
->CheckSum
) {
677 dbg ("%s - Mismatch %x - %x", __FUNCTION__
, rom_desc
->CheckSum
, cs
);
683 /* Make sure that the I2C image is good */
684 static int TiValidateI2cImage (struct edgeport_serial
*serial
)
686 struct device
*dev
= &serial
->serial
->dev
->dev
;
688 struct ti_i2c_desc
*rom_desc
;
689 int start_address
= 2;
692 rom_desc
= kmalloc (sizeof (*rom_desc
), GFP_KERNEL
);
694 dev_err (dev
, "%s - out of memory\n", __FUNCTION__
);
697 buffer
= kmalloc (TI_MAX_I2C_SIZE
, GFP_KERNEL
);
699 dev_err (dev
, "%s - out of memory when allocating buffer\n", __FUNCTION__
);
704 // Read the first byte (Signature0) must be 0x52
705 status
= TIReadRom (serial
, 0, 1, buffer
);
707 goto ExitTiValidateI2cImage
;
709 if (*buffer
!= 0x52) {
710 dev_err (dev
, "%s - invalid buffer signature\n", __FUNCTION__
);
712 goto ExitTiValidateI2cImage
;
717 status
= TIReadRom (serial
,
719 sizeof(struct ti_i2c_desc
),
724 if ((start_address
+ sizeof(struct ti_i2c_desc
) + rom_desc
->Size
) > TI_MAX_I2C_SIZE
) {
726 dbg ("%s - structure too big, erroring out.", __FUNCTION__
);
730 dbg ("%s Type = 0x%x", __FUNCTION__
, rom_desc
->Type
);
732 // Skip type 2 record
733 if ((rom_desc
->Type
& 0x0f) != I2C_DESC_TYPE_FIRMWARE_BASIC
) {
734 // Read the descriptor data
735 status
= TIReadRom(serial
,
736 start_address
+sizeof(struct ti_i2c_desc
),
742 status
= ValidChecksum(rom_desc
, buffer
);
746 start_address
= start_address
+ sizeof(struct ti_i2c_desc
) + rom_desc
->Size
;
748 } while ((rom_desc
->Type
!= I2C_DESC_TYPE_ION
) && (start_address
< TI_MAX_I2C_SIZE
));
750 if ((rom_desc
->Type
!= I2C_DESC_TYPE_ION
) || (start_address
> TI_MAX_I2C_SIZE
))
753 ExitTiValidateI2cImage
:
759 static int TIReadManufDescriptor (struct edgeport_serial
*serial
, __u8
*buffer
)
763 struct ti_i2c_desc
*rom_desc
;
764 struct edge_ti_manuf_descriptor
*desc
;
766 rom_desc
= kmalloc (sizeof (*rom_desc
), GFP_KERNEL
);
768 dev_err (&serial
->serial
->dev
->dev
, "%s - out of memory\n", __FUNCTION__
);
771 start_address
= TIGetDescriptorAddress (serial
, I2C_DESC_TYPE_ION
, rom_desc
);
773 if (!start_address
) {
774 dbg ("%s - Edge Descriptor not found in I2C", __FUNCTION__
);
779 // Read the descriptor data
780 status
= TIReadRom (serial
,
781 start_address
+sizeof(struct ti_i2c_desc
),
787 status
= ValidChecksum(rom_desc
, buffer
);
789 desc
= (struct edge_ti_manuf_descriptor
*)buffer
;
790 dbg ( "%s - IonConfig 0x%x", __FUNCTION__
, desc
->IonConfig
);
791 dbg ( "%s - Version %d", __FUNCTION__
, desc
->Version
);
792 dbg ( "%s - Cpu/Board 0x%x", __FUNCTION__
, desc
->CpuRev_BoardRev
);
793 dbg ( "%s - NumPorts %d", __FUNCTION__
, desc
->NumPorts
);
794 dbg ( "%s - NumVirtualPorts %d", __FUNCTION__
, desc
->NumVirtualPorts
);
795 dbg ( "%s - TotalPorts %d", __FUNCTION__
, desc
->TotalPorts
);
802 /* Build firmware header used for firmware update */
803 static int BuildI2CFirmwareHeader (__u8
*header
, struct device
*dev
)
809 struct ti_i2c_desc
*i2c_header
;
810 struct ti_i2c_image_header
*img_header
;
811 struct ti_i2c_firmware_rec
*firmware_rec
;
813 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
814 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
815 // will download the latest firmware (padded to 15.5k) into the UMP ram.
816 // And finally when the device comes back up in download mode the driver will cause
817 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
818 // the record type from 0xf2 to 0x02.
820 // Allocate a 15.5k buffer + 2 bytes for version number (Firmware Record)
821 buffer_size
= (((1024 * 16) - 512 )+ sizeof(struct ti_i2c_firmware_rec
));
823 buffer
= kmalloc (buffer_size
, GFP_KERNEL
);
825 dev_err (dev
, "%s - out of memory\n", __FUNCTION__
);
829 // Set entire image of 0xffs
830 memset (buffer
, 0xff, buffer_size
);
832 // Copy version number into firmware record
833 firmware_rec
= (struct ti_i2c_firmware_rec
*)buffer
;
835 firmware_rec
->Ver_Major
= OperationalCodeImageVersion
.MajorVersion
;
836 firmware_rec
->Ver_Minor
= OperationalCodeImageVersion
.MinorVersion
;
838 // Pointer to fw_down memory image
839 img_header
= (struct ti_i2c_image_header
*)&PagableOperationalCodeImage
[0];
841 memcpy (buffer
+ sizeof(struct ti_i2c_firmware_rec
),
842 &PagableOperationalCodeImage
[sizeof(struct ti_i2c_image_header
)],
845 for (i
=0; i
< buffer_size
; i
++) {
846 cs
= (__u8
)(cs
+ buffer
[i
]);
852 i2c_header
= (struct ti_i2c_desc
*)header
;
853 firmware_rec
= (struct ti_i2c_firmware_rec
*)i2c_header
->Data
;
855 i2c_header
->Type
= I2C_DESC_TYPE_FIRMWARE_BLANK
;
856 i2c_header
->Size
= (__u16
)buffer_size
;
857 i2c_header
->CheckSum
= cs
;
858 firmware_rec
->Ver_Major
= OperationalCodeImageVersion
.MajorVersion
;
859 firmware_rec
->Ver_Minor
= OperationalCodeImageVersion
.MinorVersion
;
864 /* Try to figure out what type of I2c we have */
865 static int TIGetI2cTypeInBootMode (struct edgeport_serial
*serial
)
870 // Try to read type 2
871 status
= TIReadVendorRequestSync (serial
->serial
->dev
,
872 UMPC_MEMORY_READ
, // Request
873 DTK_ADDR_SPACE_I2C_TYPE_II
, // wValue (Address type)
875 &data
, // TransferBuffer
876 0x01); // TransferBufferLength
878 dbg ("%s - read 2 status error = %d", __FUNCTION__
, status
);
880 dbg ("%s - read 2 data = 0x%x", __FUNCTION__
, data
);
881 if ((!status
) && data
== 0x52) {
882 dbg ("%s - ROM_TYPE_II", __FUNCTION__
);
883 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
887 // Try to read type 3
888 status
= TIReadVendorRequestSync (serial
->serial
->dev
,
889 UMPC_MEMORY_READ
, // Request
890 DTK_ADDR_SPACE_I2C_TYPE_III
, // wValue (Address type)
892 &data
, // TransferBuffer
893 0x01); // TransferBufferLength
895 dbg ("%s - read 3 status error = %d", __FUNCTION__
, status
);
897 dbg ("%s - read 2 data = 0x%x", __FUNCTION__
, data
);
898 if ((!status
) && data
== 0x52) {
899 dbg ("%s - ROM_TYPE_III", __FUNCTION__
);
900 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_III
;
904 dbg ("%s - Unknown", __FUNCTION__
);
905 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
909 static int TISendBulkTransferSync (struct usb_serial
*serial
, void *buffer
, int length
, int *num_sent
)
913 status
= usb_bulk_msg (serial
->dev
,
914 usb_sndbulkpipe(serial
->dev
,
915 serial
->port
[0]->bulk_out_endpointAddress
),
923 /* Download given firmware image to the device (IN BOOT MODE) */
924 static int TIDownloadCodeImage (struct edgeport_serial
*serial
, __u8
*image
, int image_length
)
931 // Transfer firmware image
932 for (pos
= 0; pos
< image_length
; ) {
933 // Read the next buffer from file
934 transfer
= image_length
- pos
;
935 if (transfer
> EDGE_FW_BULK_MAX_PACKET_SIZE
)
936 transfer
= EDGE_FW_BULK_MAX_PACKET_SIZE
;
939 status
= TISendBulkTransferSync (serial
->serial
, &image
[pos
], transfer
, &done
);
942 // Advance buffer pointer
950 static int TIConfigureBootDevice (struct usb_device
*dev
)
956 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
958 * This routine downloads the main operating code into the TI5052, using the
959 * boot code already burned into E2PROM or ROM.
961 static int TIDownloadFirmware (struct edgeport_serial
*serial
)
963 struct device
*dev
= &serial
->serial
->dev
->dev
;
966 struct edge_ti_manuf_descriptor
*ti_manuf_desc
;
967 struct usb_interface_descriptor
*interface
;
968 int download_cur_ver
;
969 int download_new_ver
;
971 /* This routine is entered by both the BOOT mode and the Download mode
972 * We can determine which code is running by the reading the config
973 * descriptor and if we have only one bulk pipe it is in boot mode
975 serial
->product_info
.hardware_type
= HARDWARE_TYPE_TIUMP
;
977 /* Default to type 2 i2c */
978 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
980 status
= TIChooseConfiguration (serial
->serial
->dev
);
984 interface
= &serial
->serial
->interface
->cur_altsetting
->desc
;
986 dev_err (&serial
->serial
->dev
->dev
, "%s - no interface set, error!", __FUNCTION__
);
990 // Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
991 // if we have more than one endpoint we are definitely in download mode
992 if (interface
->bNumEndpoints
> 1)
993 serial
->product_info
.TiMode
= TI_MODE_DOWNLOAD
;
995 // Otherwise we will remain in configuring mode
996 serial
->product_info
.TiMode
= TI_MODE_CONFIGURING
;
998 // Save Download Version Number
999 OperationalCodeImageVersion
.MajorVersion
= PagableOperationalCodeImageVersion
.MajorVersion
;
1000 OperationalCodeImageVersion
.MinorVersion
= PagableOperationalCodeImageVersion
.MinorVersion
;
1001 OperationalCodeImageVersion
.BuildNumber
= PagableOperationalCodeImageVersion
.BuildNumber
;
1003 /********************************************************************/
1005 /********************************************************************/
1006 if (serial
->product_info
.TiMode
== TI_MODE_DOWNLOAD
) {
1007 struct ti_i2c_desc
*rom_desc
;
1009 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN DOWNLOAD MODE>>>>>>>>>>", __FUNCTION__
);
1011 status
= TiValidateI2cImage (serial
);
1013 dbg ("%s - <<<<<<<<<<<<<<<DOWNLOAD MODE -- BAD I2C >>>>>>>>>>",
1018 /* Validate Hardware version number
1019 * Read Manufacturing Descriptor from TI Based Edgeport
1021 ti_manuf_desc
= kmalloc (sizeof (*ti_manuf_desc
), GFP_KERNEL
);
1022 if (!ti_manuf_desc
) {
1023 dev_err (dev
, "%s - out of memory.\n", __FUNCTION__
);
1026 status
= TIReadManufDescriptor (serial
, (__u8
*)ti_manuf_desc
);
1028 kfree (ti_manuf_desc
);
1032 // Check version number of ION descriptor
1033 if (!ignore_cpu_rev
&& TI_GET_CPU_REVISION(ti_manuf_desc
->CpuRev_BoardRev
) < 2) {
1034 dbg ( "%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__
,
1035 TI_GET_CPU_REVISION(ti_manuf_desc
->CpuRev_BoardRev
));
1036 kfree (ti_manuf_desc
);
1040 rom_desc
= kmalloc (sizeof (*rom_desc
), GFP_KERNEL
);
1042 dev_err (dev
, "%s - out of memory.\n", __FUNCTION__
);
1043 kfree (ti_manuf_desc
);
1047 // Search for type 2 record (firmware record)
1048 if ((start_address
= TIGetDescriptorAddress (serial
, I2C_DESC_TYPE_FIRMWARE_BASIC
, rom_desc
)) != 0) {
1049 struct ti_i2c_firmware_rec
*firmware_version
;
1052 dbg ("%s - Found Type FIRMWARE (Type 2) record", __FUNCTION__
);
1054 firmware_version
= kmalloc (sizeof (*firmware_version
), GFP_KERNEL
);
1055 if (!firmware_version
) {
1056 dev_err (dev
, "%s - out of memory.\n", __FUNCTION__
);
1058 kfree (ti_manuf_desc
);
1062 // Validate version number
1063 // Read the descriptor data
1064 status
= TIReadRom (serial
,
1065 start_address
+sizeof(struct ti_i2c_desc
),
1066 sizeof(struct ti_i2c_firmware_rec
),
1067 (__u8
*)firmware_version
);
1069 kfree (firmware_version
);
1071 kfree (ti_manuf_desc
);
1075 // Check version number of download with current version in I2c
1076 download_cur_ver
= (firmware_version
->Ver_Major
<< 8) +
1077 (firmware_version
->Ver_Minor
);
1078 download_new_ver
= (OperationalCodeImageVersion
.MajorVersion
<< 8) +
1079 (OperationalCodeImageVersion
.MinorVersion
);
1081 dbg ("%s - >>>Firmware Versions Device %d.%d Driver %d.%d",
1083 firmware_version
->Ver_Major
,
1084 firmware_version
->Ver_Minor
,
1085 OperationalCodeImageVersion
.MajorVersion
,
1086 OperationalCodeImageVersion
.MinorVersion
);
1088 // Check if we have an old version in the I2C and update if necessary
1089 if (download_cur_ver
!= download_new_ver
) {
1090 dbg ("%s - Update I2C Download from %d.%d to %d.%d",
1092 firmware_version
->Ver_Major
,
1093 firmware_version
->Ver_Minor
,
1094 OperationalCodeImageVersion
.MajorVersion
,
1095 OperationalCodeImageVersion
.MinorVersion
);
1097 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1098 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1099 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1100 // And finally when the device comes back up in download mode the driver will cause
1101 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1102 // the record type from 0xf2 to 0x02.
1104 record
= I2C_DESC_TYPE_FIRMWARE_BLANK
;
1106 // Change the I2C Firmware record type to 0xf2 to trigger an update
1107 status
= TIWriteRom (serial
,
1112 kfree (firmware_version
);
1114 kfree (ti_manuf_desc
);
1118 // verify the write -- must do this in order for write to
1119 // complete before we do the hardware reset
1120 status
= TIReadRom (serial
,
1126 kfree (firmware_version
);
1128 kfree (ti_manuf_desc
);
1132 if (record
!= I2C_DESC_TYPE_FIRMWARE_BLANK
) {
1133 dev_err (dev
, "%s - error resetting device\n", __FUNCTION__
);
1134 kfree (firmware_version
);
1136 kfree (ti_manuf_desc
);
1140 dbg ("%s - HARDWARE RESET", __FUNCTION__
);
1142 // Reset UMP -- Back to BOOT MODE
1143 status
= TISendVendorRequestSync (serial
->serial
->dev
,
1144 UMPC_HARDWARE_RESET
, // Request
1147 NULL
, // TransferBuffer
1148 0); // TransferBufferLength
1150 dbg ( "%s - HARDWARE RESET return %d", __FUNCTION__
, status
);
1152 /* return an error on purpose. */
1153 kfree (firmware_version
);
1155 kfree (ti_manuf_desc
);
1158 kfree (firmware_version
);
1160 // Search for type 0xF2 record (firmware blank record)
1161 else if ((start_address
= TIGetDescriptorAddress (serial
, I2C_DESC_TYPE_FIRMWARE_BLANK
, rom_desc
)) != 0) {
1162 #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + sizeof(struct ti_i2c_firmware_rec))
1166 header
= kmalloc (HEADER_SIZE
, GFP_KERNEL
);
1168 dev_err (dev
, "%s - out of memory.\n", __FUNCTION__
);
1170 kfree (ti_manuf_desc
);
1174 vheader
= kmalloc (HEADER_SIZE
, GFP_KERNEL
);
1176 dev_err (dev
, "%s - out of memory.\n", __FUNCTION__
);
1179 kfree (ti_manuf_desc
);
1183 dbg ("%s - Found Type BLANK FIRMWARE (Type F2) record", __FUNCTION__
);
1185 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1186 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1187 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1188 // And finally when the device comes back up in download mode the driver will cause
1189 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1190 // the record type from 0xf2 to 0x02.
1191 status
= BuildI2CFirmwareHeader(header
, dev
);
1196 kfree (ti_manuf_desc
);
1200 // Update I2C with type 0xf2 record with correct size and checksum
1201 status
= TIWriteRom (serial
,
1209 kfree (ti_manuf_desc
);
1213 // verify the write -- must do this in order for write to
1214 // complete before we do the hardware reset
1215 status
= TIReadRom (serial
,
1221 dbg ("%s - can't read header back", __FUNCTION__
);
1225 kfree (ti_manuf_desc
);
1228 if (memcmp(vheader
, header
, HEADER_SIZE
)) {
1229 dbg ("%s - write download record failed", __FUNCTION__
);
1233 kfree (ti_manuf_desc
);
1240 dbg ("%s - Start firmware update", __FUNCTION__
);
1242 // Tell firmware to copy download image into I2C
1243 status
= TISendVendorRequestSync (serial
->serial
->dev
,
1244 UMPC_COPY_DNLD_TO_I2C
, // Request
1247 NULL
, // TransferBuffer
1248 0); // TransferBufferLength
1250 dbg ("%s - Update complete 0x%x", __FUNCTION__
, status
);
1252 dbg ("%s - UMPC_COPY_DNLD_TO_I2C failed", __FUNCTION__
);
1254 kfree (ti_manuf_desc
);
1259 // The device is running the download code
1261 kfree (ti_manuf_desc
);
1265 /********************************************************************/
1267 /********************************************************************/
1268 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN BOOT MODE>>>>>>>>>>>>>>>",
1271 // Configure the TI device so we can use the BULK pipes for download
1272 status
= TIConfigureBootDevice (serial
->serial
->dev
);
1276 if (serial
->serial
->dev
->descriptor
.idVendor
!= USB_VENDOR_ID_ION
) {
1277 dbg ("%s - VID = 0x%x", __FUNCTION__
,
1278 serial
->serial
->dev
->descriptor
.idVendor
);
1279 serial
->TI_I2C_Type
= DTK_ADDR_SPACE_I2C_TYPE_II
;
1280 goto StayInBootMode
;
1283 // We have an ION device (I2c Must be programmed)
1284 // Determine I2C image type
1285 if (TIGetI2cTypeInBootMode(serial
)) {
1286 goto StayInBootMode
;
1289 // Registry variable set?
1290 if (TIStayInBootMode
) {
1291 dbg ("%s - TIStayInBootMode", __FUNCTION__
);
1292 goto StayInBootMode
;
1295 // Check for ION Vendor ID and that the I2C is valid
1296 if (!TiValidateI2cImage(serial
)) {
1297 struct ti_i2c_image_header
*header
;
1303 /* Validate Hardware version number
1304 * Read Manufacturing Descriptor from TI Based Edgeport
1306 ti_manuf_desc
= kmalloc (sizeof (*ti_manuf_desc
), GFP_KERNEL
);
1307 if (!ti_manuf_desc
) {
1308 dev_err (dev
, "%s - out of memory.\n", __FUNCTION__
);
1311 status
= TIReadManufDescriptor (serial
, (__u8
*)ti_manuf_desc
);
1313 kfree (ti_manuf_desc
);
1314 goto StayInBootMode
;
1317 // Check for version 2
1318 if (!ignore_cpu_rev
&& TI_GET_CPU_REVISION(ti_manuf_desc
->CpuRev_BoardRev
) < 2) {
1319 dbg ("%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__
,
1320 TI_GET_CPU_REVISION(ti_manuf_desc
->CpuRev_BoardRev
));
1321 kfree (ti_manuf_desc
);
1322 goto StayInBootMode
;
1325 kfree (ti_manuf_desc
);
1327 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1328 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1329 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1330 // And finally when the device comes back up in download mode the driver will cause
1331 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1332 // the record type from 0xf2 to 0x02.
1335 * Do we really have to copy the whole firmware image,
1336 * or could we do this in place!
1339 // Allocate a 15.5k buffer + 3 byte header
1340 buffer_size
= (((1024 * 16) - 512) + sizeof(struct ti_i2c_image_header
));
1341 buffer
= kmalloc (buffer_size
, GFP_KERNEL
);
1343 dev_err (dev
, "%s - out of memory\n", __FUNCTION__
);
1347 // Initialize the buffer to 0xff (pad the buffer)
1348 memset (buffer
, 0xff, buffer_size
);
1350 memcpy (buffer
, &PagableOperationalCodeImage
[0], PagableOperationalCodeSize
);
1352 for(i
= sizeof(struct ti_i2c_image_header
); i
< buffer_size
; i
++) {
1353 cs
= (__u8
)(cs
+ buffer
[i
]);
1356 header
= (struct ti_i2c_image_header
*)buffer
;
1358 // update length and checksum after padding
1359 header
->Length
= (__u16
)(buffer_size
- sizeof(struct ti_i2c_image_header
));
1360 header
->CheckSum
= cs
;
1362 // Download the operational code
1363 dbg ("%s - Downloading operational code image (TI UMP)", __FUNCTION__
);
1364 status
= TIDownloadCodeImage (serial
, buffer
, buffer_size
);
1369 dbg ("%s - Error downloading operational code image", __FUNCTION__
);
1373 // Device will reboot
1374 serial
->product_info
.TiMode
= TI_MODE_TRANSITIONING
;
1376 dbg ("%s - Download successful -- Device rebooting...", __FUNCTION__
);
1378 /* return an error on purpose */
1383 // Eprom is invalid or blank stay in boot mode
1384 dbg ("%s - <<<<<<<<<<<<<<<STAYING IN BOOT MODE>>>>>>>>>>>>", __FUNCTION__
);
1385 serial
->product_info
.TiMode
= TI_MODE_BOOT
;
1391 static int TISetDtr (struct edgeport_port
*port
)
1393 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1395 dbg ("%s", __FUNCTION__
);
1396 port
->shadow_mcr
|= MCR_DTR
;
1398 return TIWriteCommandSync (port
->port
->serial
->dev
,
1400 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1406 static int TIClearDtr (struct edgeport_port
*port
)
1408 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1410 dbg ("%s", __FUNCTION__
);
1411 port
->shadow_mcr
&= ~MCR_DTR
;
1413 return TIWriteCommandSync (port
->port
->serial
->dev
,
1415 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1421 static int TISetRts (struct edgeport_port
*port
)
1423 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1425 dbg ("%s", __FUNCTION__
);
1426 port
->shadow_mcr
|= MCR_RTS
;
1428 return TIWriteCommandSync (port
->port
->serial
->dev
,
1430 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1436 static int TIClearRts (struct edgeport_port
*port
)
1438 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1440 dbg ("%s", __FUNCTION__
);
1441 port
->shadow_mcr
&= ~MCR_RTS
;
1443 return TIWriteCommandSync (port
->port
->serial
->dev
,
1445 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1451 static int TISetLoopBack (struct edgeport_port
*port
)
1453 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1455 dbg ("%s", __FUNCTION__
);
1457 return TIWriteCommandSync (port
->port
->serial
->dev
,
1458 UMPC_SET_CLR_LOOPBACK
,
1459 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1465 static int TIClearLoopBack (struct edgeport_port
*port
)
1467 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1469 dbg ("%s", __FUNCTION__
);
1471 return TIWriteCommandSync (port
->port
->serial
->dev
,
1472 UMPC_SET_CLR_LOOPBACK
,
1473 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1479 static int TISetBreak (struct edgeport_port
*port
)
1481 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1483 dbg ("%s", __FUNCTION__
);
1485 return TIWriteCommandSync (port
->port
->serial
->dev
,
1487 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1493 static int TIClearBreak (struct edgeport_port
*port
)
1495 int port_number
= port
->port
->number
- port
->port
->serial
->minor
;
1497 dbg ("%s", __FUNCTION__
);
1499 return TIWriteCommandSync (port
->port
->serial
->dev
,
1501 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1507 static int TIRestoreMCR (struct edgeport_port
*port
, __u8 mcr
)
1511 dbg ("%s - %x", __FUNCTION__
, mcr
);
1514 status
= TISetDtr (port
);
1516 status
= TIClearDtr (port
);
1522 status
= TISetRts (port
);
1524 status
= TIClearRts (port
);
1529 if (mcr
& MCR_LOOPBACK
)
1530 status
= TISetLoopBack (port
);
1532 status
= TIClearLoopBack (port
);
1539 /* Convert TI LSR to standard UART flags */
1540 static __u8
MapLineStatus (__u8 ti_lsr
)
1544 #define MAP_FLAG(flagUmp, flagUart) \
1545 if (ti_lsr & flagUmp) \
1548 MAP_FLAG(UMP_UART_LSR_OV_MASK
, LSR_OVER_ERR
) /* overrun */
1549 MAP_FLAG(UMP_UART_LSR_PE_MASK
, LSR_PAR_ERR
) /* parity error */
1550 MAP_FLAG(UMP_UART_LSR_FE_MASK
, LSR_FRM_ERR
) /* framing error */
1551 MAP_FLAG(UMP_UART_LSR_BR_MASK
, LSR_BREAK
) /* break detected */
1552 MAP_FLAG(UMP_UART_LSR_RX_MASK
, LSR_RX_AVAIL
) /* receive data available */
1553 MAP_FLAG(UMP_UART_LSR_TX_MASK
, LSR_TX_EMPTY
) /* transmit holding register empty */
1560 static void handle_new_msr (struct edgeport_port
*edge_port
, __u8 msr
)
1562 struct async_icount
*icount
;
1564 dbg ("%s - %02x", __FUNCTION__
, msr
);
1566 if (msr
& (EDGEPORT_MSR_DELTA_CTS
| EDGEPORT_MSR_DELTA_DSR
| EDGEPORT_MSR_DELTA_RI
| EDGEPORT_MSR_DELTA_CD
)) {
1567 icount
= &edge_port
->icount
;
1569 /* update input line counters */
1570 if (msr
& EDGEPORT_MSR_DELTA_CTS
)
1572 if (msr
& EDGEPORT_MSR_DELTA_DSR
)
1574 if (msr
& EDGEPORT_MSR_DELTA_CD
)
1576 if (msr
& EDGEPORT_MSR_DELTA_RI
)
1578 wake_up_interruptible (&edge_port
->delta_msr_wait
);
1581 /* Save the new modem status */
1582 edge_port
->shadow_msr
= msr
& 0xf0;
1587 static void handle_new_lsr (struct edgeport_port
*edge_port
, int lsr_data
, __u8 lsr
, __u8 data
)
1589 struct async_icount
*icount
;
1590 __u8 new_lsr
= (__u8
)(lsr
& (__u8
)(LSR_OVER_ERR
| LSR_PAR_ERR
| LSR_FRM_ERR
| LSR_BREAK
));
1592 dbg ("%s - %02x", __FUNCTION__
, new_lsr
);
1594 edge_port
->shadow_lsr
= lsr
;
1596 if (new_lsr
& LSR_BREAK
) {
1598 * Parity and Framing errors only count if they
1599 * occur exclusive of a break being received.
1601 new_lsr
&= (__u8
)(LSR_OVER_ERR
| LSR_BREAK
);
1604 /* Place LSR data byte into Rx buffer */
1605 if (lsr_data
&& edge_port
->port
->tty
) {
1606 tty_insert_flip_char(edge_port
->port
->tty
, data
, 0);
1607 tty_flip_buffer_push(edge_port
->port
->tty
);
1610 /* update input line counters */
1611 icount
= &edge_port
->icount
;
1612 if (new_lsr
& LSR_BREAK
)
1614 if (new_lsr
& LSR_OVER_ERR
)
1616 if (new_lsr
& LSR_PAR_ERR
)
1618 if (new_lsr
& LSR_FRM_ERR
)
1623 static void edge_interrupt_callback (struct urb
*urb
, struct pt_regs
*regs
)
1625 struct edgeport_serial
*edge_serial
= (struct edgeport_serial
*)urb
->context
;
1626 struct usb_serial_port
*port
;
1627 struct edgeport_port
*edge_port
;
1628 unsigned char *data
= urb
->transfer_buffer
;
1629 int length
= urb
->actual_length
;
1636 dbg("%s", __FUNCTION__
);
1638 switch (urb
->status
) {
1645 /* this urb is terminated, clean up */
1646 dbg("%s - urb shutting down with status: %d", __FUNCTION__
, urb
->status
);
1649 dbg("%s - nonzero urb status received: %d", __FUNCTION__
, urb
->status
);
1654 dbg ("%s - no data in urb", __FUNCTION__
);
1658 usb_serial_debug_data(debug
, &edge_serial
->serial
->dev
->dev
, __FUNCTION__
, length
, data
);
1661 dbg ("%s - expecting packet of size 2, got %d", __FUNCTION__
, length
);
1665 port_number
= TIUMP_GET_PORT_FROM_CODE (data
[0]);
1666 function
= TIUMP_GET_FUNC_FROM_CODE (data
[0]);
1667 dbg ("%s - port_number %d, function %d, info 0x%x",
1668 __FUNCTION__
, port_number
, function
, data
[1]);
1669 port
= edge_serial
->serial
->port
[port_number
];
1670 edge_port
= usb_get_serial_port_data(port
);
1672 dbg ("%s - edge_port not found", __FUNCTION__
);
1676 case TIUMP_INTERRUPT_CODE_LSR
:
1677 lsr
= MapLineStatus(data
[1]);
1678 if (lsr
& UMP_UART_LSR_DATA_MASK
) {
1679 /* Save the LSR event for bulk read completion routine */
1680 dbg ("%s - LSR Event Port %u LSR Status = %02x",
1681 __FUNCTION__
, port_number
, lsr
);
1682 edge_port
->lsr_event
= 1;
1683 edge_port
->lsr_mask
= lsr
;
1685 dbg ("%s - ===== Port %d LSR Status = %02x ======",
1686 __FUNCTION__
, port_number
, lsr
);
1687 handle_new_lsr (edge_port
, 0, lsr
, 0);
1691 case TIUMP_INTERRUPT_CODE_MSR
: // MSR
1692 /* Copy MSR from UMP */
1694 dbg ("%s - ===== Port %u MSR Status = %02x ======\n",
1695 __FUNCTION__
, port_number
, msr
);
1696 handle_new_msr (edge_port
, msr
);
1700 dev_err (&urb
->dev
->dev
, "%s - Unknown Interrupt code from UMP %x\n",
1701 __FUNCTION__
, data
[1]);
1707 status
= usb_submit_urb (urb
, GFP_ATOMIC
);
1709 dev_err (&urb
->dev
->dev
, "%s - usb_submit_urb failed with result %d\n",
1710 __FUNCTION__
, status
);
1713 static void edge_bulk_in_callback (struct urb
*urb
, struct pt_regs
*regs
)
1715 struct edgeport_port
*edge_port
= (struct edgeport_port
*)urb
->context
;
1716 unsigned char *data
= urb
->transfer_buffer
;
1717 struct tty_struct
*tty
;
1722 dbg("%s", __FUNCTION__
);
1725 dbg ("%s - nonzero read bulk status received: %d",
1726 __FUNCTION__
, urb
->status
);
1728 if (urb
->status
== -EPIPE
) {
1729 /* clear any problem that might have happened on this pipe */
1730 usb_clear_halt (edge_port
->port
->serial
->dev
, urb
->pipe
);
1736 port_number
= edge_port
->port
->number
- edge_port
->port
->serial
->minor
;
1738 if (edge_port
->lsr_event
) {
1739 edge_port
->lsr_event
= 0;
1740 dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
1741 __FUNCTION__
, port_number
, edge_port
->lsr_mask
, *data
);
1742 handle_new_lsr (edge_port
, 1, edge_port
->lsr_mask
, *data
);
1743 /* Adjust buffer length/pointer */
1744 --urb
->actual_length
;
1748 tty
= edge_port
->port
->tty
;
1749 if (tty
&& urb
->actual_length
) {
1750 usb_serial_debug_data(debug
, &edge_port
->port
->dev
, __FUNCTION__
, urb
->actual_length
, data
);
1752 if (edge_port
->close_pending
) {
1753 dbg ("%s - close is pending, dropping data on the floor.", __FUNCTION__
);
1755 for (i
= 0; i
< urb
->actual_length
; ++i
) {
1756 /* if we insert more than TTY_FLIPBUF_SIZE characters,
1758 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
1759 tty_flip_buffer_push(tty
);
1761 /* this doesn't actually push the data through unless
1762 * tty->low_latency is set */
1763 tty_insert_flip_char(tty
, data
[i
], 0);
1765 tty_flip_buffer_push(tty
);
1767 edge_port
->icount
.rx
+= urb
->actual_length
;
1771 /* continue always trying to read */
1772 status
= usb_submit_urb (urb
, GFP_ATOMIC
);
1774 dev_err (&urb
->dev
->dev
, "%s - usb_submit_urb failed with result %d\n",
1775 __FUNCTION__
, status
);
1778 static void edge_bulk_out_callback (struct urb
*urb
, struct pt_regs
*regs
)
1780 struct usb_serial_port
*port
= (struct usb_serial_port
*)urb
->context
;
1781 struct tty_struct
*tty
;
1783 dbg ("%s - port %d", __FUNCTION__
, port
->number
);
1786 dbg ("%s - nonzero write bulk status received: %d",
1787 __FUNCTION__
, urb
->status
);
1789 if (urb
->status
== -EPIPE
) {
1790 /* clear any problem that might have happened on this pipe */
1791 usb_clear_halt (port
->serial
->dev
, urb
->pipe
);
1798 /* let the tty driver wakeup if it has a special write_wakeup function */
1803 static int edge_open (struct usb_serial_port
*port
, struct file
* filp
)
1805 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
1806 struct edgeport_serial
*edge_serial
;
1807 struct usb_device
*dev
;
1812 u8 transaction_timeout
;
1814 dbg("%s - port %d", __FUNCTION__
, port
->number
);
1816 if (edge_port
== NULL
)
1819 /* force low_latency on so that our tty_push actually forces the data through,
1820 otherwise it is scheduled, and with high data rates (like with OHCI) data
1823 port
->tty
->low_latency
= 1;
1825 port_number
= port
->number
- port
->serial
->minor
;
1826 switch (port_number
) {
1828 edge_port
->uart_base
= UMPMEM_BASE_UART1
;
1829 edge_port
->dma_address
= UMPD_OEDB1_ADDRESS
;
1832 edge_port
->uart_base
= UMPMEM_BASE_UART2
;
1833 edge_port
->dma_address
= UMPD_OEDB2_ADDRESS
;
1836 dev_err (&port
->dev
, "Unknown port number!!!\n");
1840 dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
1841 __FUNCTION__
, port_number
, edge_port
->uart_base
, edge_port
->dma_address
);
1843 dev
= port
->serial
->dev
;
1845 memset (&(edge_port
->icount
), 0x00, sizeof(edge_port
->icount
));
1846 init_waitqueue_head (&edge_port
->delta_msr_wait
);
1848 /* turn off loopback */
1849 status
= TIClearLoopBack (edge_port
);
1853 /* set up the port settings */
1854 edge_set_termios (port
, NULL
);
1856 /* open up the port */
1858 /* milliseconds to timeout for DMA transfer */
1859 transaction_timeout
= 2;
1861 edge_port
->ump_read_timeout
= max (20, ((transaction_timeout
* 3) / 2) );
1863 // milliseconds to timeout for DMA transfer
1864 open_settings
= (u8
)(UMP_DMA_MODE_CONTINOUS
|
1865 UMP_PIPE_TRANS_TIMEOUT_ENA
|
1866 (transaction_timeout
<< 2));
1868 dbg ("%s - Sending UMPC_OPEN_PORT", __FUNCTION__
);
1870 /* Tell TI to open and start the port */
1871 status
= TIWriteCommandSync (dev
,
1873 (u8
)(UMPM_UART1_PORT
+ port_number
),
1880 /* Start the DMA? */
1881 status
= TIWriteCommandSync (dev
,
1883 (u8
)(UMPM_UART1_PORT
+ port_number
),
1890 /* Clear TX and RX buffers in UMP */
1891 status
= TIPurgeDataSync (port
, UMP_PORT_DIR_OUT
| UMP_PORT_DIR_IN
);
1895 /* Read Initial MSR */
1896 status
= TIReadVendorRequestSync (dev
,
1897 UMPC_READ_MSR
, // Request
1899 (__u16
)(UMPM_UART1_PORT
+ port_number
), // wIndex (Address)
1900 &edge_port
->shadow_msr
, // TransferBuffer
1901 1); // TransferBufferLength
1905 dbg ("ShadowMSR 0x%X", edge_port
->shadow_msr
);
1907 edge_serial
= edge_port
->edge_serial
;
1908 if (edge_serial
->num_ports_open
== 0) {
1909 /* we are the first port to be opened, let's post the interrupt urb */
1910 urb
= edge_serial
->serial
->port
[0]->interrupt_in_urb
;
1912 dev_err (&port
->dev
, "%s - no interrupt urb present, exiting\n", __FUNCTION__
);
1915 urb
->complete
= edge_interrupt_callback
;
1916 urb
->context
= edge_serial
;
1918 status
= usb_submit_urb (urb
, GFP_KERNEL
);
1920 dev_err (&port
->dev
, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__
, status
);
1926 * reset the data toggle on the bulk endpoints to work around bug in
1927 * host controllers where things get out of sync some times
1929 usb_clear_halt (dev
, port
->write_urb
->pipe
);
1930 usb_clear_halt (dev
, port
->read_urb
->pipe
);
1932 /* start up our bulk read urb */
1933 urb
= port
->read_urb
;
1935 dev_err (&port
->dev
, "%s - no read urb present, exiting\n", __FUNCTION__
);
1938 urb
->complete
= edge_bulk_in_callback
;
1939 urb
->context
= edge_port
;
1941 status
= usb_submit_urb (urb
, GFP_KERNEL
);
1943 dev_err (&port
->dev
, "%s - read bulk usb_submit_urb failed with value %d\n", __FUNCTION__
, status
);
1947 ++edge_serial
->num_ports_open
;
1949 dbg("%s - exited", __FUNCTION__
);
1954 static void edge_close (struct usb_serial_port
*port
, struct file
* filp
)
1956 struct edgeport_serial
*edge_serial
;
1957 struct edgeport_port
*edge_port
;
1961 dbg("%s - port %d", __FUNCTION__
, port
->number
);
1963 edge_serial
= usb_get_serial_data(port
->serial
);
1964 edge_port
= usb_get_serial_port_data(port
);
1965 if ((edge_serial
== NULL
) || (edge_port
== NULL
))
1968 /* The bulkreadcompletion routine will check
1969 * this flag and dump add read data */
1970 edge_port
->close_pending
= 1;
1972 /* chase the port close */
1973 TIChasePort (edge_port
);
1975 usb_unlink_urb (port
->read_urb
);
1977 /* assuming we can still talk to the device,
1978 * send a close port command to it */
1979 dbg("%s - send umpc_close_port", __FUNCTION__
);
1980 port_number
= port
->number
- port
->serial
->minor
;
1981 status
= TIWriteCommandSync (port
->serial
->dev
,
1983 (__u8
)(UMPM_UART1_PORT
+ port_number
),
1987 --edge_port
->edge_serial
->num_ports_open
;
1988 if (edge_port
->edge_serial
->num_ports_open
<= 0) {
1989 /* last port is now closed, let's shut down our interrupt urb */
1990 usb_unlink_urb (port
->serial
->port
[0]->interrupt_in_urb
);
1991 edge_port
->edge_serial
->num_ports_open
= 0;
1993 edge_port
->close_pending
= 0;
1995 dbg("%s - exited", __FUNCTION__
);
1998 static int edge_write (struct usb_serial_port
*port
, int from_user
, const unsigned char *data
, int count
)
2000 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2003 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2006 dbg("%s - write request of 0 bytes", __FUNCTION__
);
2010 if (edge_port
== NULL
)
2012 if (edge_port
->close_pending
== 1)
2015 if (port
->write_urb
->status
== -EINPROGRESS
) {
2016 dbg ("%s - already writing", __FUNCTION__
);
2020 count
= min (count
, port
->bulk_out_size
);
2023 if (copy_from_user(port
->write_urb
->transfer_buffer
, data
, count
))
2026 memcpy (port
->write_urb
->transfer_buffer
, data
, count
);
2029 usb_serial_debug_data(debug
, &port
->dev
, __FUNCTION__
, count
, port
->write_urb
->transfer_buffer
);
2031 /* set up our urb */
2032 usb_fill_bulk_urb (port
->write_urb
, port
->serial
->dev
,
2033 usb_sndbulkpipe (port
->serial
->dev
,
2034 port
->bulk_out_endpointAddress
),
2035 port
->write_urb
->transfer_buffer
, count
,
2036 edge_bulk_out_callback
,
2039 /* send the data out the bulk port */
2040 result
= usb_submit_urb(port
->write_urb
, GFP_ATOMIC
);
2042 dev_err(&port
->dev
, "%s - failed submitting write urb, error %d\n", __FUNCTION__
, result
);
2047 edge_port
->icount
.tx
+= count
;
2052 static int edge_write_room (struct usb_serial_port
*port
)
2054 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2057 dbg("%s", __FUNCTION__
);
2059 if (edge_port
== NULL
)
2061 if (edge_port
->close_pending
== 1)
2064 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2066 if (port
->write_urb
->status
!= -EINPROGRESS
)
2067 room
= port
->bulk_out_size
;
2069 dbg("%s - returns %d", __FUNCTION__
, room
);
2073 static int edge_chars_in_buffer (struct usb_serial_port
*port
)
2075 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2078 dbg("%s", __FUNCTION__
);
2080 if (edge_port
== NULL
)
2082 if (edge_port
->close_pending
== 1)
2085 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2087 if (port
->write_urb
->status
== -EINPROGRESS
)
2088 chars
= port
->write_urb
->transfer_buffer_length
;
2090 dbg ("%s - returns %d", __FUNCTION__
, chars
);
2094 static void edge_throttle (struct usb_serial_port
*port
)
2096 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2097 struct tty_struct
*tty
;
2100 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2102 if (edge_port
== NULL
)
2107 dbg ("%s - no tty available", __FUNCTION__
);
2110 /* if we are implementing XON/XOFF, send the stop character */
2112 unsigned char stop_char
= STOP_CHAR(tty
);
2113 status
= edge_write (port
, 0, &stop_char
, 1);
2119 /* if we are implementing RTS/CTS, toggle that line */
2120 if (tty
->termios
->c_cflag
& CRTSCTS
) {
2121 status
= TIClearRts (edge_port
);
2124 usb_unlink_urb (port
->read_urb
);
2127 static void edge_unthrottle (struct usb_serial_port
*port
)
2129 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2130 struct tty_struct
*tty
;
2133 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2135 if (edge_port
== NULL
)
2140 dbg ("%s - no tty available", __FUNCTION__
);
2144 /* if we are implementing XON/XOFF, send the start character */
2146 unsigned char start_char
= START_CHAR(tty
);
2147 status
= edge_write (port
, 0, &start_char
, 1);
2153 /* if we are implementing RTS/CTS, toggle that line */
2154 if (tty
->termios
->c_cflag
& CRTSCTS
) {
2155 status
= TISetRts (edge_port
);
2158 port
->read_urb
->dev
= port
->serial
->dev
;
2159 status
= usb_submit_urb (port
->read_urb
, GFP_ATOMIC
);
2161 dev_err (&port
->dev
, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__
, status
);
2166 static void change_port_settings (struct edgeport_port
*edge_port
, struct termios
*old_termios
)
2168 struct ump_uart_config
*config
;
2169 struct tty_struct
*tty
;
2174 int port_number
= edge_port
->port
->number
- edge_port
->port
->serial
->minor
;
2176 dbg("%s - port %d", __FUNCTION__
, edge_port
->port
->number
);
2178 tty
= edge_port
->port
->tty
;
2181 dbg("%s - no tty structures", __FUNCTION__
);
2185 config
= kmalloc (sizeof (*config
), GFP_KERNEL
);
2187 dev_err (&edge_port
->port
->dev
, "%s - out of memory\n", __FUNCTION__
);
2191 cflag
= tty
->termios
->c_cflag
;
2195 /* These flags must be set */
2196 config
->wFlags
|= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT
;
2197 config
->wFlags
|= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR
;
2198 config
->bUartMode
= 0;
2200 switch (cflag
& CSIZE
) {
2202 config
->bDataBits
= UMP_UART_CHAR5BITS
;
2203 dbg ("%s - data bits = 5", __FUNCTION__
);
2206 config
->bDataBits
= UMP_UART_CHAR6BITS
;
2207 dbg ("%s - data bits = 6", __FUNCTION__
);
2210 config
->bDataBits
= UMP_UART_CHAR7BITS
;
2211 dbg ("%s - data bits = 7", __FUNCTION__
);
2215 config
->bDataBits
= UMP_UART_CHAR8BITS
;
2216 dbg ("%s - data bits = 8", __FUNCTION__
);
2220 if (cflag
& PARENB
) {
2221 if (cflag
& PARODD
) {
2222 config
->wFlags
|= UMP_MASK_UART_FLAGS_PARITY
;
2223 config
->bParity
= UMP_UART_ODDPARITY
;
2224 dbg("%s - parity = odd", __FUNCTION__
);
2226 config
->wFlags
|= UMP_MASK_UART_FLAGS_PARITY
;
2227 config
->bParity
= UMP_UART_EVENPARITY
;
2228 dbg("%s - parity = even", __FUNCTION__
);
2231 config
->bParity
= UMP_UART_NOPARITY
;
2232 dbg("%s - parity = none", __FUNCTION__
);
2235 if (cflag
& CSTOPB
) {
2236 config
->bStopBits
= UMP_UART_STOPBIT2
;
2237 dbg("%s - stop bits = 2", __FUNCTION__
);
2239 config
->bStopBits
= UMP_UART_STOPBIT1
;
2240 dbg("%s - stop bits = 1", __FUNCTION__
);
2243 /* figure out the flow control settings */
2244 if (cflag
& CRTSCTS
) {
2245 config
->wFlags
|= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW
;
2246 config
->wFlags
|= UMP_MASK_UART_FLAGS_RTS_FLOW
;
2247 dbg("%s - RTS/CTS is enabled", __FUNCTION__
);
2249 dbg("%s - RTS/CTS is disabled", __FUNCTION__
);
2252 /* if we are implementing XON/XOFF, set the start and stop character in the device */
2253 if (I_IXOFF(tty
) || I_IXON(tty
)) {
2254 config
->cXon
= START_CHAR(tty
);
2255 config
->cXoff
= STOP_CHAR(tty
);
2257 /* if we are implementing INBOUND XON/XOFF */
2259 config
->wFlags
|= UMP_MASK_UART_FLAGS_IN_X
;
2260 dbg ("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2261 __FUNCTION__
, config
->cXon
, config
->cXoff
);
2263 dbg ("%s - INBOUND XON/XOFF is disabled", __FUNCTION__
);
2266 /* if we are implementing OUTBOUND XON/XOFF */
2268 config
->wFlags
|= UMP_MASK_UART_FLAGS_OUT_X
;
2269 dbg ("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2270 __FUNCTION__
, config
->cXon
, config
->cXoff
);
2272 dbg ("%s - OUTBOUND XON/XOFF is disabled", __FUNCTION__
);
2276 /* Round the baud rate */
2277 baud
= tty_get_baud_rate(tty
);
2279 /* pick a default, any default... */
2282 config
->wBaudRate
= (__u16
)(461550L / baud
);
2283 round
= 4615500L / baud
;
2284 if ((round
- (config
->wBaudRate
* 10)) >= 5)
2285 config
->wBaudRate
++;
2287 dbg ("%s - baud rate = %d, wBaudRate = %d", __FUNCTION__
, baud
, config
->wBaudRate
);
2289 dbg ("wBaudRate: %d", (int)(461550L / config
->wBaudRate
));
2290 dbg ("wFlags: 0x%x", config
->wFlags
);
2291 dbg ("bDataBits: %d", config
->bDataBits
);
2292 dbg ("bParity: %d", config
->bParity
);
2293 dbg ("bStopBits: %d", config
->bStopBits
);
2294 dbg ("cXon: %d", config
->cXon
);
2295 dbg ("cXoff: %d", config
->cXoff
);
2296 dbg ("bUartMode: %d", config
->bUartMode
);
2298 /* move the word values into big endian mode */
2299 cpu_to_be16s (&config
->wFlags
);
2300 cpu_to_be16s (&config
->wBaudRate
);
2302 status
= TIWriteCommandSync (edge_port
->port
->serial
->dev
,
2304 (__u8
)(UMPM_UART1_PORT
+ port_number
),
2309 dbg ("%s - error %d when trying to write config to device",
2310 __FUNCTION__
, status
);
2318 static void edge_set_termios (struct usb_serial_port
*port
, struct termios
*old_termios
)
2320 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2321 struct tty_struct
*tty
= port
->tty
;
2324 if (!port
->tty
|| !port
->tty
->termios
) {
2325 dbg ("%s - no tty or termios", __FUNCTION__
);
2329 cflag
= tty
->termios
->c_cflag
;
2330 /* check that they really want us to change something */
2332 if ((cflag
== old_termios
->c_cflag
) &&
2333 (RELEVANT_IFLAG(tty
->termios
->c_iflag
) == RELEVANT_IFLAG(old_termios
->c_iflag
))) {
2334 dbg ("%s - nothing to change", __FUNCTION__
);
2339 dbg("%s - clfag %08x iflag %08x", __FUNCTION__
,
2340 tty
->termios
->c_cflag
,
2341 RELEVANT_IFLAG(tty
->termios
->c_iflag
));
2343 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__
,
2344 old_termios
->c_cflag
,
2345 RELEVANT_IFLAG(old_termios
->c_iflag
));
2348 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2350 if (edge_port
== NULL
)
2353 /* change the port settings to the new ones specified */
2354 change_port_settings (edge_port
, old_termios
);
2359 static int edge_tiocmset (struct usb_serial_port
*port
, struct file
*file
, unsigned int set
, unsigned int clear
)
2361 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2364 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2366 mcr
= edge_port
->shadow_mcr
;
2367 if (set
& TIOCM_RTS
)
2369 if (set
& TIOCM_DTR
)
2371 if (set
& TIOCM_LOOP
)
2372 mcr
|= MCR_LOOPBACK
;
2374 if (clear
& TIOCM_RTS
)
2376 if (clear
& TIOCM_DTR
)
2378 if (clear
& TIOCM_LOOP
)
2379 mcr
&= ~MCR_LOOPBACK
;
2381 edge_port
->shadow_mcr
= mcr
;
2383 TIRestoreMCR (edge_port
, mcr
);
2388 static int edge_tiocmget(struct usb_serial_port
*port
, struct file
*file
)
2390 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2391 unsigned int result
= 0;
2395 dbg("%s - port %d", __FUNCTION__
, port
->number
);
2397 msr
= edge_port
->shadow_msr
;
2398 mcr
= edge_port
->shadow_mcr
;
2399 result
= ((mcr
& MCR_DTR
) ? TIOCM_DTR
: 0) /* 0x002 */
2400 | ((mcr
& MCR_RTS
) ? TIOCM_RTS
: 0) /* 0x004 */
2401 | ((msr
& EDGEPORT_MSR_CTS
) ? TIOCM_CTS
: 0) /* 0x020 */
2402 | ((msr
& EDGEPORT_MSR_CD
) ? TIOCM_CAR
: 0) /* 0x040 */
2403 | ((msr
& EDGEPORT_MSR_RI
) ? TIOCM_RI
: 0) /* 0x080 */
2404 | ((msr
& EDGEPORT_MSR_DSR
) ? TIOCM_DSR
: 0); /* 0x100 */
2407 dbg("%s -- %x", __FUNCTION__
, result
);
2412 static int get_serial_info (struct edgeport_port
*edge_port
, struct serial_struct __user
*retinfo
)
2414 struct serial_struct tmp
;
2419 memset(&tmp
, 0, sizeof(tmp
));
2421 tmp
.type
= PORT_16550A
;
2422 tmp
.line
= edge_port
->port
->serial
->minor
;
2423 tmp
.port
= edge_port
->port
->number
;
2425 tmp
.flags
= ASYNC_SKIP_TEST
| ASYNC_AUTO_IRQ
;
2426 tmp
.xmit_fifo_size
= edge_port
->port
->bulk_out_size
;
2427 tmp
.baud_base
= 9600;
2428 tmp
.close_delay
= 5*HZ
;
2429 tmp
.closing_wait
= 30*HZ
;
2430 // tmp.custom_divisor = state->custom_divisor;
2431 // tmp.hub6 = state->hub6;
2432 // tmp.io_type = state->io_type;
2435 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2440 static int edge_ioctl (struct usb_serial_port
*port
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
2442 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2443 struct async_icount cnow
;
2444 struct async_icount cprev
;
2446 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__
, port
->number
, cmd
);
2450 dbg("%s - (%d) TIOCINQ", __FUNCTION__
, port
->number
);
2451 // return get_number_bytes_avail(edge_port, (unsigned int *) arg);
2455 dbg("%s - (%d) TIOCSERGETLSR", __FUNCTION__
, port
->number
);
2456 // return get_lsr_info(edge_port, (unsigned int *) arg);
2460 dbg("%s - (%d) TIOCGSERIAL", __FUNCTION__
, port
->number
);
2461 return get_serial_info(edge_port
, (struct serial_struct __user
*) arg
);
2465 dbg("%s - (%d) TIOCSSERIAL", __FUNCTION__
, port
->number
);
2469 dbg("%s - (%d) TIOCMIWAIT", __FUNCTION__
, port
->number
);
2470 cprev
= edge_port
->icount
;
2472 interruptible_sleep_on(&edge_port
->delta_msr_wait
);
2473 /* see if a signal did it */
2474 if (signal_pending(current
))
2475 return -ERESTARTSYS
;
2476 cnow
= edge_port
->icount
;
2477 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
2478 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
2479 return -EIO
; /* no change => error */
2480 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
2481 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
2482 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
2483 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
2492 dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__
,
2493 port
->number
, edge_port
->icount
.rx
, edge_port
->icount
.tx
);
2494 if (copy_to_user((void __user
*)arg
, &edge_port
->icount
, sizeof(edge_port
->icount
)))
2499 return -ENOIOCTLCMD
;
2502 static void edge_break (struct usb_serial_port
*port
, int break_state
)
2504 struct edgeport_port
*edge_port
= usb_get_serial_port_data(port
);
2507 dbg ("%s - state = %d", __FUNCTION__
, break_state
);
2509 /* chase the port close */
2510 TIChasePort (edge_port
);
2512 if (break_state
== -1) {
2513 status
= TISetBreak (edge_port
);
2515 status
= TIClearBreak (edge_port
);
2518 dbg ("%s - error %d sending break set/clear command.",
2519 __FUNCTION__
, status
);
2523 static int edge_startup (struct usb_serial
*serial
)
2525 struct edgeport_serial
*edge_serial
;
2526 struct edgeport_port
*edge_port
;
2527 struct usb_device
*dev
;
2533 /* create our private serial structure */
2534 edge_serial
= kmalloc (sizeof(struct edgeport_serial
), GFP_KERNEL
);
2535 if (edge_serial
== NULL
) {
2536 dev_err(&serial
->dev
->dev
, "%s - Out of memory\n", __FUNCTION__
);
2539 memset (edge_serial
, 0, sizeof(struct edgeport_serial
));
2540 edge_serial
->serial
= serial
;
2541 usb_set_serial_data(serial
, edge_serial
);
2543 status
= TIDownloadFirmware (edge_serial
);
2545 kfree (edge_serial
);
2549 /* set up our port private structures */
2550 for (i
= 0; i
< serial
->num_ports
; ++i
) {
2551 edge_port
= kmalloc (sizeof(struct edgeport_port
), GFP_KERNEL
);
2552 if (edge_port
== NULL
) {
2553 dev_err(&serial
->dev
->dev
, "%s - Out of memory\n", __FUNCTION__
);
2556 memset (edge_port
, 0, sizeof(struct edgeport_port
));
2557 edge_port
->port
= serial
->port
[i
];
2558 edge_port
->edge_serial
= edge_serial
;
2559 usb_set_serial_port_data(serial
->port
[i
], edge_port
);
2565 static void edge_shutdown (struct usb_serial
*serial
)
2569 dbg ("%s", __FUNCTION__
);
2571 for (i
=0; i
< serial
->num_ports
; ++i
) {
2572 kfree (usb_get_serial_port_data(serial
->port
[i
]));
2573 usb_set_serial_port_data(serial
->port
[i
], NULL
);
2575 kfree (usb_get_serial_data(serial
));
2576 usb_set_serial_data(serial
, NULL
);
2580 static struct usb_serial_device_type edgeport_1port_device
= {
2581 .owner
= THIS_MODULE
,
2582 .name
= "Edgeport TI 1 port adapter",
2583 .short_name
= "edgeport_ti_1",
2584 .id_table
= edgeport_1port_id_table
,
2585 .num_interrupt_in
= 1,
2590 .close
= edge_close
,
2591 .throttle
= edge_throttle
,
2592 .unthrottle
= edge_unthrottle
,
2593 .attach
= edge_startup
,
2594 .shutdown
= edge_shutdown
,
2595 .ioctl
= edge_ioctl
,
2596 .set_termios
= edge_set_termios
,
2597 .tiocmget
= edge_tiocmget
,
2598 .tiocmset
= edge_tiocmset
,
2599 .write
= edge_write
,
2600 .write_room
= edge_write_room
,
2601 .chars_in_buffer
= edge_chars_in_buffer
,
2602 .break_ctl
= edge_break
,
2605 static struct usb_serial_device_type edgeport_2port_device
= {
2606 .owner
= THIS_MODULE
,
2607 .name
= "Edgeport TI 2 port adapter",
2608 .short_name
= "edgeport_ti_2",
2609 .id_table
= edgeport_2port_id_table
,
2610 .num_interrupt_in
= 1,
2615 .close
= edge_close
,
2616 .throttle
= edge_throttle
,
2617 .unthrottle
= edge_unthrottle
,
2618 .attach
= edge_startup
,
2619 .shutdown
= edge_shutdown
,
2620 .ioctl
= edge_ioctl
,
2621 .set_termios
= edge_set_termios
,
2622 .tiocmget
= edge_tiocmget
,
2623 .tiocmset
= edge_tiocmset
,
2624 .write
= edge_write
,
2625 .write_room
= edge_write_room
,
2626 .chars_in_buffer
= edge_chars_in_buffer
,
2627 .break_ctl
= edge_break
,
2631 static int __init
edgeport_init(void)
2634 retval
= usb_serial_register(&edgeport_1port_device
);
2636 goto failed_1port_device_register
;
2637 retval
= usb_serial_register(&edgeport_2port_device
);
2639 goto failed_2port_device_register
;
2640 retval
= usb_register(&io_driver
);
2642 goto failed_usb_register
;
2643 info(DRIVER_DESC
" " DRIVER_VERSION
);
2645 failed_usb_register
:
2646 usb_serial_deregister(&edgeport_2port_device
);
2647 failed_2port_device_register
:
2648 usb_serial_deregister(&edgeport_1port_device
);
2649 failed_1port_device_register
:
2653 static void __exit
edgeport_exit (void)
2655 usb_deregister (&io_driver
);
2656 usb_serial_deregister (&edgeport_1port_device
);
2657 usb_serial_deregister (&edgeport_2port_device
);
2660 module_init(edgeport_init
);
2661 module_exit(edgeport_exit
);
2663 /* Module information */
2664 MODULE_AUTHOR(DRIVER_AUTHOR
);
2665 MODULE_DESCRIPTION(DRIVER_DESC
);
2666 MODULE_LICENSE("GPL");
2668 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
2669 MODULE_PARM_DESC(debug
, "Debug enabled or not");
2671 module_param(ignore_cpu_rev
, bool, S_IRUGO
| S_IWUSR
);
2672 MODULE_PARM_DESC(ignore_cpu_rev
, "Ignore the cpu revision when connecting to a device");