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/errno.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
28 #include <linux/tty.h>
29 #include <linux/tty_driver.h>
30 #include <linux/tty_flip.h>
31 #include <linux/module.h>
32 #include <linux/spinlock.h>
33 #include <linux/serial.h>
34 #include <linux/ioctl.h>
35 #include <asm/uaccess.h>
36 #include <linux/usb.h>
38 #ifdef CONFIG_USB_SERIAL_DEBUG
44 #include "usb-serial.h"
47 #include "io_usbvend.h"
53 #define DRIVER_VERSION "v0.2"
54 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
55 #define DRIVER_DESC "Edgeport USB Serial Driver"
58 /* firmware image code */
59 #define IMAGE_VERSION_NAME PagableOperationalCodeImageVersion
60 #define IMAGE_ARRAY_NAME PagableOperationalCodeImage
61 #define IMAGE_SIZE PagableOperationalCodeSize
62 #include "io_fw_down3.h" /* Define array OperationalCodeImage[] */
64 #define EPROM_PAGE_SIZE 64
67 struct edgeport_uart_buf_desc {
68 __u32 count; // Number of bytes currently in buffer
71 /* different hardware types */
72 #define HARDWARE_TYPE_930 0
73 #define HARDWARE_TYPE_TIUMP 1
75 // IOCTL_PRIVATE_TI_GET_MODE Definitions
76 #define TI_MODE_CONFIGURING 0 // Device has not entered start device
77 #define TI_MODE_BOOT 1 // Staying in boot mode
78 #define TI_MODE_DOWNLOAD 2 // Made it to download mode
79 #define TI_MODE_TRANSITIONING 3 // Currently in boot mode but transitioning to download mode
82 /* Product information read from the Edgeport */
85 int TiMode; // Current TI Mode
86 __u8 hardware_type; // Type of hardware
87 } __attribute__((packed));
90 struct edgeport_port {
97 __u32 ump_read_timeout; /* Number of miliseconds the UMP will
98 wait without data before completing
103 struct edgeport_uart_buf_desc tx;
104 struct async_icount icount;
105 wait_queue_head_t delta_msr_wait; /* for handling sleeping while
106 waiting for msr change to
108 struct edgeport_serial *edge_serial;
109 struct usb_serial_port *port;
112 struct edgeport_serial {
113 struct product_info product_info;
114 u8 TI_I2C_Type; // Type of I2C in UMP
115 u8 TiReadI2C; // Set to TRUE if we have read the I2c in Boot Mode
117 struct usb_serial *serial;
121 /* Devices that this driver supports */
122 static struct usb_device_id edgeport_1port_id_table [] = {
123 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
127 static struct usb_device_id edgeport_2port_id_table [] = {
128 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
129 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
130 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
131 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
132 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421_BOOT) },
133 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421_DOWN) },
134 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
135 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21_BOOT) },
136 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21_DOWN) },
137 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
138 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
139 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
140 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22) },
144 /* Devices that this driver supports */
145 static __devinitdata struct usb_device_id id_table_combined [] = {
146 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
147 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
148 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
149 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
150 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
151 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421_BOOT) },
152 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421_DOWN) },
153 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
154 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21_BOOT) },
155 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21_DOWN) },
156 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
157 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
158 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
159 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22) },
163 MODULE_DEVICE_TABLE (usb, id_table_combined);
166 static struct EDGE_FIRMWARE_VERSION_INFO OperationalCodeImageVersion;
168 static int TIStayInBootMode = 0;
169 static int ignore_cpu_rev = 0;
173 static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios);
175 static int TIReadVendorRequestSync (struct usb_device *dev,
184 status = usb_control_msg (dev,
185 usb_rcvctrlpipe(dev, 0),
197 if (status != size) {
198 dbg ("%s - wanted to write %d, but only wrote %d",
199 __FUNCTION__, size, status);
205 static int TISendVendorRequestSync (struct usb_device *dev,
214 status = usb_control_msg (dev,
215 usb_sndctrlpipe(dev, 0),
228 if (status != size) {
229 dbg ("%s - wanted to write %d, but only wrote %d",
230 __FUNCTION__, size, status);
236 static int TIWriteCommandSync (struct usb_device *dev, __u8 command,
237 __u8 moduleid, __u16 value, u8 *data,
240 return TISendVendorRequestSync (dev,
244 data, // TransferBuffer
245 size); // TransferBufferLength
250 /* clear tx/rx buffers and fifo in TI UMP */
251 static int TIPurgeDataSync (struct usb_serial_port *port, __u16 mask)
253 int port_number = port->number - port->serial->minor;
255 dbg ("%s - port %d, mask %x", __FUNCTION__, port_number, mask);
257 return TIWriteCommandSync (port->serial->dev,
259 (__u8)(UMPM_UART1_PORT + port_number),
266 * TIReadDownloadMemory - Read edgeport memory from TI chip
267 * @dev: usb device pointer
268 * @address: Device CPU address at which to read
269 * @length: Length of above data
270 * @address_type: Can read both XDATA and I2C
271 * @buffer: pointer to input data buffer
273 int TIReadDownloadMemory (struct usb_device *dev, int start_address, int length,
274 __u8 address_type, __u8 *buffer)
278 __u16 be_start_address;
280 dbg ("%s - @ %x for %d", __FUNCTION__, start_address, length);
282 /* Read in blocks of 64 bytes
283 * (TI firmware can't handle more than 64 byte reads)
289 read_length = (__u8)length;
291 if (read_length > 1) {
292 dbg ("%s - @ %x for %d", __FUNCTION__,
293 start_address, read_length);
295 be_start_address = cpu_to_be16 (start_address);
296 status = TIReadVendorRequestSync (dev,
297 UMPC_MEMORY_READ, // Request
298 (__u16)address_type, // wValue (Address type)
299 be_start_address, // wIndex (Address to read)
300 buffer, // TransferBuffer
301 read_length); // TransferBufferLength
304 dbg ("%s - ERROR %x", __FUNCTION__, status);
308 if (read_length > 1) {
309 usb_serial_debug_data (__FILE__, __FUNCTION__,
310 read_length, buffer);
313 /* Update pointers/length */
314 start_address += read_length;
315 buffer += read_length;
316 length -= read_length;
322 int TIReadRam (struct usb_device *dev, int start_address, int length, __u8 *buffer)
324 return TIReadDownloadMemory (dev,
327 DTK_ADDR_SPACE_XDATA,
331 /* Read edgeport memory to a given block */
332 static int TIReadBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 * buffer)
337 for (i=0; i< length; i++) {
338 status = TIReadVendorRequestSync (serial->serial->dev,
339 UMPC_MEMORY_READ, // Request
340 serial->TI_I2C_Type, // wValue (Address type)
341 (__u16)(start_address+i), // wIndex
342 &buffer[i], // TransferBuffer
343 0x01); // TransferBufferLength
345 dbg ("%s - ERROR %x", __FUNCTION__, status);
350 dbg ("%s - start_address = %x, length = %d", __FUNCTION__, start_address, length);
351 usb_serial_debug_data (__FILE__, __FUNCTION__, length, buffer);
353 serial->TiReadI2C = 1;
358 /* Write given block to TI EPROM memory */
359 static int TIWriteBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer)
365 /* Must do a read before write */
366 if (!serial->TiReadI2C) {
367 status = TIReadBootMemory(serial, 0, 1, &temp);
372 for (i=0; i < length; ++i) {
373 status = TISendVendorRequestSync (serial->serial->dev,
374 UMPC_MEMORY_WRITE, // Request
376 (__u16)(i+start_address), // wIndex
377 NULL, // TransferBuffer
378 0); // TransferBufferLength
383 dbg ("%s - start_sddr = %x, length = %d", __FUNCTION__, start_address, length);
384 usb_serial_debug_data (__FILE__, __FUNCTION__, length, buffer);
390 /* Write edgeport I2C memory to TI chip */
391 static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address, int length, __u8 address_type, __u8 *buffer)
395 __u16 be_start_address;
397 /* We can only send a maximum of 1 aligned byte page at a time */
399 /* calulate the number of bytes left in the first page */
400 write_length = EPROM_PAGE_SIZE - (start_address & (EPROM_PAGE_SIZE - 1));
402 if (write_length > length)
403 write_length = length;
405 dbg ("%s - BytesInFirstPage Addr = %x, length = %d", __FUNCTION__, start_address, write_length);
406 usb_serial_debug_data (__FILE__, __FUNCTION__, write_length, buffer);
408 /* Write first page */
409 be_start_address = cpu_to_be16 (start_address);
410 status = TISendVendorRequestSync (serial->serial->dev,
411 UMPC_MEMORY_WRITE, // Request
412 (__u16)address_type, // wValue
413 be_start_address, // wIndex
414 buffer, // TransferBuffer
417 dbg ("%s - ERROR %d", __FUNCTION__, status);
421 length -= write_length;
422 start_address += write_length;
423 buffer += write_length;
425 /* We should be aligned now -- can write max page size bytes at a time */
427 if (length > EPROM_PAGE_SIZE)
428 write_length = EPROM_PAGE_SIZE;
430 write_length = length;
432 dbg ("%s - Page Write Addr = %x, length = %d", __FUNCTION__, start_address, write_length);
433 usb_serial_debug_data (__FILE__, __FUNCTION__, write_length, buffer);
435 /* Write next page */
436 be_start_address = cpu_to_be16 (start_address);
437 status = TISendVendorRequestSync (serial->serial->dev,
438 UMPC_MEMORY_WRITE, // Request
439 (__u16)address_type, // wValue
440 be_start_address, // wIndex
441 buffer, // TransferBuffer
442 write_length); // TransferBufferLength
444 dbg ("%s - ERROR %d", __FUNCTION__, status);
448 length -= write_length;
449 start_address += write_length;
450 buffer += write_length;
455 /* Examine the UMP DMA registers and LSR
457 * Check the MSBit of the X and Y DMA byte count registers.
458 * A zero in this bit indicates that the TX DMA buffers are empty
459 * then check the TX Empty bit in the UART.
461 static int TIIsTxActive (struct edgeport_port *port)
464 struct out_endpoint_desc_block *oedb;
468 oedb = kmalloc (sizeof (* oedb), GFP_KERNEL);
470 err ("%s - out of memory", __FUNCTION__);
474 lsr = kmalloc (1, GFP_KERNEL); /* Sigh, that's right, just one byte,
475 as not all platforms can do DMA
481 /* Read the DMA Count Registers */
482 status = TIReadRam (port->port->serial->dev,
488 goto exit_is_tx_active;
490 dbg ("%s - XByteCount 0x%X", __FUNCTION__, oedb->XByteCount);
493 status = TIReadRam (port->port->serial->dev,
494 port->uart_base + UMPMEM_OFFS_UART_LSR,
499 goto exit_is_tx_active;
500 dbg ("%s - LSR = 0x%X", __FUNCTION__, *lsr);
502 /* If either buffer has data or we are transmitting then return TRUE */
503 if ((oedb->XByteCount & 0x80 ) != 0 )
506 if ((*lsr & UMP_UART_LSR_TX_MASK ) == 0 )
509 /* We return Not Active if we get any kind of error */
511 dbg ("%s - return %d", __FUNCTION__, bytes_left );
518 static void TIChasePort(struct edgeport_port *port)
525 // Base the LoopTime on the baud rate
526 if (port->baud_rate == 0)
527 port->baud_rate = 1200;
529 write_size = port->tx.count;
530 loops = max(100, (100*write_size)/(port->baud_rate/10));
531 dbg ("%s - write_size %d, baud %d loop = %d", __FUNCTION__,
532 write_size, port->baud_rate, loops);
536 last_count = port->tx.count;
538 dbg ("%s - Tx Buffer Size = %d loops = %d", __FUNCTION__,
541 /* Is the Edgeport Buffer empty? */
542 if (port->tx.count == 0)
545 /* Block the thread for 10ms */
548 if (last_count == port->tx.count) {
549 /* No activity.. count down. */
552 dbg ("%s - Wait for TxEmpty - TIMEOUT",
557 /* Reset timeout value back to a minimum of 1 second */
558 dbg ("%s - Wait for TxEmpty Reset Count", __FUNCTION__);
559 goto restart_tx_loop;
563 dbg ("%s - Local Tx Buffer Empty -- Waiting for TI UMP to EMPTY X/Y and FIFO",
566 write_size = TIIsTxActive (port);
567 loops = max(50, (100*write_size)/(port->baud_rate/10));
568 dbg ("%s - write_size %d, baud %d loop = %d", __FUNCTION__,
569 write_size, port->baud_rate, loops);
572 /* This function takes 4 ms; */
573 if (!TIIsTxActive (port)) {
574 /* Delay a few char times */
576 dbg ("%s - Empty", __FUNCTION__);
582 dbg ("%s - TIMEOUT", __FUNCTION__);
588 static int TIChooseConfiguration (struct usb_device *dev)
590 // There may be multiple configurations on this device, in which case
591 // we would need to read and parse all of them to find out which one
592 // we want. However, we just support one config at this point,
593 // configuration # 1, which is Config Descriptor 0.
595 dbg ("%s - Number of Interfaces = %d", __FUNCTION__, dev->config->bNumInterfaces);
596 dbg ("%s - MAX Power = %d", __FUNCTION__, dev->config->MaxPower*2);
598 if (dev->config->bNumInterfaces != 1) {
599 err ("%s - bNumInterfaces is not 1, ERROR!", __FUNCTION__);
606 int TIReadRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer)
610 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
611 status = TIReadDownloadMemory (serial->serial->dev,
617 status = TIReadBootMemory (serial,
626 int TIWriteRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer)
628 if (serial->product_info.TiMode == TI_MODE_BOOT)
629 return TIWriteBootMemory (serial,
634 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD)
635 return TIWriteDownloadI2C (serial,
646 /* Read a descriptor header from I2C based on type */
647 static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type, struct ti_i2c_desc *rom_desc)
652 /* Search for requested descriptor in I2C */
655 status = TIReadRom (serial,
657 sizeof(struct ti_i2c_desc),
662 if (rom_desc->Type == desc_type)
663 return start_address;
665 start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size;
667 } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type);
672 /* Validate descriptor checksum */
673 static int ValidChecksum(struct ti_i2c_desc *rom_desc, __u8 *buffer)
678 for (i=0; i < rom_desc->Size; i++) {
679 cs = (__u8)(cs + buffer[i]);
681 if (cs != rom_desc->CheckSum) {
682 dbg ("%s - Mismatch %x - %x", __FUNCTION__, rom_desc->CheckSum, cs);
688 /* Make sure that the I2C image is good */
689 static int TiValidateI2cImage (struct edgeport_serial *serial)
692 struct ti_i2c_desc *rom_desc;
693 int start_address = 2;
696 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
698 err ("%s - out of memory", __FUNCTION__);
701 buffer = kmalloc (TI_MAX_I2C_SIZE, GFP_KERNEL);
703 err ("%s - out of memory when allocating buffer", __FUNCTION__);
708 // Read the first byte (Signature0) must be 0x52
709 status = TIReadRom (serial, 0, 1, buffer);
711 goto ExitTiValidateI2cImage;
713 if (*buffer != 0x52) {
714 err ("%s - invalid buffer signature", __FUNCTION__);
716 goto ExitTiValidateI2cImage;
721 status = TIReadRom (serial,
723 sizeof(struct ti_i2c_desc),
728 if ((start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size) > TI_MAX_I2C_SIZE) {
730 dbg ("%s - structure too big, erroring out.", __FUNCTION__);
734 dbg ("%s Type = 0x%x", __FUNCTION__, rom_desc->Type);
736 // Skip type 2 record
737 if ((rom_desc->Type & 0x0f) != I2C_DESC_TYPE_FIRMWARE_BASIC) {
738 // Read the descriptor data
739 status = TIReadRom(serial,
740 start_address+sizeof(struct ti_i2c_desc),
746 status = ValidChecksum(rom_desc, buffer);
750 start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size;
752 } while ((rom_desc->Type != I2C_DESC_TYPE_ION) && (start_address < TI_MAX_I2C_SIZE));
754 if ((rom_desc->Type != I2C_DESC_TYPE_ION) || (start_address > TI_MAX_I2C_SIZE))
757 ExitTiValidateI2cImage:
763 static int TIReadManufDescriptor (struct edgeport_serial *serial, __u8 *buffer)
767 struct ti_i2c_desc *rom_desc;
768 struct edge_ti_manuf_descriptor *desc;
770 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
772 err ("%s - out of memory", __FUNCTION__);
775 start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_ION, rom_desc);
777 if (!start_address) {
778 dbg ("%s - Edge Descriptor not found in I2C", __FUNCTION__);
783 // Read the descriptor data
784 status = TIReadRom (serial,
785 start_address+sizeof(struct ti_i2c_desc),
791 status = ValidChecksum(rom_desc, buffer);
793 desc = (struct edge_ti_manuf_descriptor *)buffer;
794 dbg ( "%s - IonConfig 0x%x", __FUNCTION__, desc->IonConfig );
795 dbg ( "%s - Version %d", __FUNCTION__, desc->Version );
796 dbg ( "%s - Cpu/Board 0x%x", __FUNCTION__, desc->CpuRev_BoardRev );
797 dbg ( "%s - NumPorts %d", __FUNCTION__, desc->NumPorts );
798 dbg ( "%s - NumVirtualPorts %d", __FUNCTION__, desc->NumVirtualPorts );
799 dbg ( "%s - TotalPorts %d", __FUNCTION__, desc->TotalPorts );
806 /* Build firmware header used for firmware update */
807 static int BuildI2CFirmwareHeader (__u8 *header)
813 struct ti_i2c_desc *i2c_header;
814 struct ti_i2c_image_header *img_header;
815 struct ti_i2c_firmware_rec *firmware_rec;
817 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
818 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
819 // will download the latest firmware (padded to 15.5k) into the UMP ram.
820 // And finally when the device comes back up in download mode the driver will cause
821 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
822 // the record type from 0xf2 to 0x02.
824 // Allocate a 15.5k buffer + 2 bytes for version number (Firmware Record)
825 buffer_size = (((1024 * 16) - 512 )+ sizeof(struct ti_i2c_firmware_rec));
827 buffer = kmalloc (buffer_size, GFP_KERNEL);
829 err ("%s - out of memory", __FUNCTION__);
833 // Set entire image of 0xffs
834 memset (buffer, 0xff, buffer_size);
836 // Copy version number into firmware record
837 firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
839 firmware_rec->Ver_Major = OperationalCodeImageVersion.MajorVersion;
840 firmware_rec->Ver_Minor = OperationalCodeImageVersion.MinorVersion;
842 // Pointer to fw_down memory image
843 img_header = (struct ti_i2c_image_header *)&PagableOperationalCodeImage[0];
845 memcpy (buffer + sizeof(struct ti_i2c_firmware_rec),
846 &PagableOperationalCodeImage[sizeof(struct ti_i2c_image_header)],
849 for (i=0; i < buffer_size; i++) {
850 cs = (__u8)(cs + buffer[i]);
856 i2c_header = (struct ti_i2c_desc *)header;
857 firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data;
859 i2c_header->Type = I2C_DESC_TYPE_FIRMWARE_BLANK;
860 i2c_header->Size = (__u16)buffer_size;
861 i2c_header->CheckSum = cs;
862 firmware_rec->Ver_Major = OperationalCodeImageVersion.MajorVersion;
863 firmware_rec->Ver_Minor = OperationalCodeImageVersion.MinorVersion;
868 /* Try to figure out what type of I2c we have */
869 static int TIGetI2cTypeInBootMode (struct edgeport_serial *serial)
874 // Try to read type 2
875 status = TIReadVendorRequestSync (serial->serial->dev,
876 UMPC_MEMORY_READ, // Request
877 DTK_ADDR_SPACE_I2C_TYPE_II, // wValue (Address type)
879 &data, // TransferBuffer
880 0x01); // TransferBufferLength
882 dbg ("%s - read 2 status error = %d", __FUNCTION__, status);
884 dbg ("%s - read 2 data = 0x%x", __FUNCTION__, data);
885 if ((!status) && data == 0x52) {
886 dbg ("%s - ROM_TYPE_II", __FUNCTION__);
887 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
891 // Try to read type 3
892 status = TIReadVendorRequestSync (serial->serial->dev,
893 UMPC_MEMORY_READ, // Request
894 DTK_ADDR_SPACE_I2C_TYPE_III, // wValue (Address type)
896 &data, // TransferBuffer
897 0x01); // TransferBufferLength
899 dbg ("%s - read 3 status error = %d", __FUNCTION__, status);
901 dbg ("%s - read 2 data = 0x%x", __FUNCTION__, data);
902 if ((!status) && data == 0x52) {
903 dbg ("%s - ROM_TYPE_III", __FUNCTION__);
904 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
908 dbg ("%s - Unknown", __FUNCTION__);
909 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
913 static int TISendBulkTransferSync (struct usb_serial *serial, void *buffer, int length, int *num_sent)
917 status = usb_bulk_msg (serial->dev,
918 usb_sndbulkpipe(serial->dev,
919 serial->port[0].bulk_out_endpointAddress),
927 /* Download given firmware image to the device (IN BOOT MODE) */
928 static int TIDownloadCodeImage (struct edgeport_serial *serial, __u8 *image, int image_length)
935 // Transfer firmware image
936 for (pos = 0; pos < image_length; ) {
937 // Read the next buffer from file
938 transfer = image_length - pos;
939 if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE)
940 transfer = EDGE_FW_BULK_MAX_PACKET_SIZE;
943 status = TISendBulkTransferSync (serial->serial, &image[pos], transfer, &done);
946 // Advance buffer pointer
954 static int TIConfigureBootDevice (struct usb_device *dev)
960 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
962 * This routine downloads the main operating code into the TI5052, using the
963 * boot code already burned into E2PROM or ROM.
965 static int TIDownloadFirmware (struct edgeport_serial *serial)
969 struct edge_ti_manuf_descriptor *ti_manuf_desc;
970 struct usb_interface_descriptor *interface;
971 int download_cur_ver;
972 int download_new_ver;
974 /* This routine is entered by both the BOOT mode and the Download mode
975 * We can determine which code is running by the reading the config
976 * descriptor and if we have only one bulk pipe it is in boot mode
978 serial->product_info.hardware_type = HARDWARE_TYPE_TIUMP;
980 /* Default to type 2 i2c */
981 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
983 status = TIChooseConfiguration (serial->serial->dev);
987 interface = serial->serial->dev->config->interface->altsetting;
989 err ("%s - no interface set, error!", __FUNCTION__);
993 // Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
994 // if we have more than one endpoint we are definitely in download mode
995 if (interface->bNumEndpoints > 1)
996 serial->product_info.TiMode = TI_MODE_DOWNLOAD;
998 // Otherwise we will remain in configuring mode
999 serial->product_info.TiMode = TI_MODE_CONFIGURING;
1001 // Save Download Version Number
1002 OperationalCodeImageVersion.MajorVersion = PagableOperationalCodeImageVersion.MajorVersion;
1003 OperationalCodeImageVersion.MinorVersion = PagableOperationalCodeImageVersion.MinorVersion;
1004 OperationalCodeImageVersion.BuildNumber = PagableOperationalCodeImageVersion.BuildNumber;
1006 /********************************************************************/
1008 /********************************************************************/
1009 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
1010 struct ti_i2c_desc *rom_desc;
1012 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN DOWNLOAD MODE>>>>>>>>>>", __FUNCTION__);
1014 status = TiValidateI2cImage (serial);
1016 dbg ("%s - <<<<<<<<<<<<<<<DOWNLOAD MODE -- BAD I2C >>>>>>>>>>",
1021 /* Validate Hardware version number
1022 * Read Manufacturing Descriptor from TI Based Edgeport
1024 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL);
1025 if (!ti_manuf_desc) {
1026 err ("%s - out of memory.", __FUNCTION__);
1029 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc);
1031 kfree (ti_manuf_desc);
1035 // Check version number of ION descriptor
1036 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) {
1037 dbg ( "%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__,
1038 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev));
1039 kfree (ti_manuf_desc);
1043 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
1045 err ("%s - out of memory.", __FUNCTION__);
1046 kfree (ti_manuf_desc);
1050 // Search for type 2 record (firmware record)
1051 if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc)) != 0) {
1052 struct ti_i2c_firmware_rec *firmware_version;
1055 dbg ("%s - Found Type FIRMWARE (Type 2) record", __FUNCTION__);
1057 firmware_version = kmalloc (sizeof (*firmware_version), GFP_KERNEL);
1058 if (!firmware_version) {
1059 err ("%s - out of memory.", __FUNCTION__);
1061 kfree (ti_manuf_desc);
1065 // Validate version number
1066 // Read the descriptor data
1067 status = TIReadRom (serial,
1068 start_address+sizeof(struct ti_i2c_desc),
1069 sizeof(struct ti_i2c_firmware_rec),
1070 (__u8 *)firmware_version);
1072 kfree (firmware_version);
1074 kfree (ti_manuf_desc);
1078 // Check version number of download with current version in I2c
1079 download_cur_ver = (firmware_version->Ver_Major << 8) +
1080 (firmware_version->Ver_Minor);
1081 download_new_ver = (OperationalCodeImageVersion.MajorVersion << 8) +
1082 (OperationalCodeImageVersion.MinorVersion);
1084 dbg ("%s - >>>Firmware Versions Device %d.%d Driver %d.%d",
1086 firmware_version->Ver_Major,
1087 firmware_version->Ver_Minor,
1088 OperationalCodeImageVersion.MajorVersion,
1089 OperationalCodeImageVersion.MinorVersion);
1091 // Check if we have an old version in the I2C and update if necessary
1092 if (download_cur_ver != download_new_ver) {
1093 dbg ("%s - Update I2C Download from %d.%d to %d.%d",
1095 firmware_version->Ver_Major,
1096 firmware_version->Ver_Minor,
1097 OperationalCodeImageVersion.MajorVersion,
1098 OperationalCodeImageVersion.MinorVersion);
1100 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1101 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1102 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1103 // And finally when the device comes back up in download mode the driver will cause
1104 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1105 // the record type from 0xf2 to 0x02.
1107 record = I2C_DESC_TYPE_FIRMWARE_BLANK;
1109 // Change the I2C Firmware record type to 0xf2 to trigger an update
1110 status = TIWriteRom (serial,
1115 kfree (firmware_version);
1117 kfree (ti_manuf_desc);
1121 // verify the write -- must do this in order for write to
1122 // complete before we do the hardware reset
1123 status = TIReadRom (serial,
1129 kfree (firmware_version);
1131 kfree (ti_manuf_desc);
1135 if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
1136 err ("%s - error resetting device", __FUNCTION__);
1137 kfree (firmware_version);
1139 kfree (ti_manuf_desc);
1143 dbg ("%s - HARDWARE RESET", __FUNCTION__);
1145 // Reset UMP -- Back to BOOT MODE
1146 status = TISendVendorRequestSync (serial->serial->dev,
1147 UMPC_HARDWARE_RESET, // Request
1150 NULL, // TransferBuffer
1151 0); // TransferBufferLength
1153 dbg ( "%s - HARDWARE RESET return %d", __FUNCTION__, status);
1155 /* return an error on purpose. */
1156 kfree (firmware_version);
1158 kfree (ti_manuf_desc);
1161 kfree (firmware_version);
1163 // Search for type 0xF2 record (firmware blank record)
1164 else if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) {
1165 #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + sizeof(struct ti_i2c_firmware_rec))
1169 header = kmalloc (HEADER_SIZE, GFP_KERNEL);
1171 err ("%s - out of memory.", __FUNCTION__);
1173 kfree (ti_manuf_desc);
1177 vheader = kmalloc (HEADER_SIZE, GFP_KERNEL);
1179 err ("%s - out of memory.", __FUNCTION__);
1182 kfree (ti_manuf_desc);
1186 dbg ("%s - Found Type BLANK FIRMWARE (Type F2) record", __FUNCTION__);
1188 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1189 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1190 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1191 // And finally when the device comes back up in download mode the driver will cause
1192 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1193 // the record type from 0xf2 to 0x02.
1194 status = BuildI2CFirmwareHeader(header);
1199 kfree (ti_manuf_desc);
1203 // Update I2C with type 0xf2 record with correct size and checksum
1204 status = TIWriteRom (serial,
1212 kfree (ti_manuf_desc);
1216 // verify the write -- must do this in order for write to
1217 // complete before we do the hardware reset
1218 status = TIReadRom (serial,
1224 dbg ("%s - can't read header back", __FUNCTION__);
1228 kfree (ti_manuf_desc);
1231 if (memcmp(vheader, header, HEADER_SIZE)) {
1232 dbg ("%s - write download record failed", __FUNCTION__);
1236 kfree (ti_manuf_desc);
1243 dbg ("%s - Start firmware update", __FUNCTION__);
1245 // Tell firmware to copy download image into I2C
1246 status = TISendVendorRequestSync (serial->serial->dev,
1247 UMPC_COPY_DNLD_TO_I2C, // Request
1250 NULL, // TransferBuffer
1251 0); // TransferBufferLength
1253 dbg ("%s - Update complete 0x%x", __FUNCTION__, status);
1255 dbg ("%s - UMPC_COPY_DNLD_TO_I2C failed", __FUNCTION__);
1257 kfree (ti_manuf_desc);
1262 // The device is running the download code
1264 kfree (ti_manuf_desc);
1268 /********************************************************************/
1270 /********************************************************************/
1271 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN BOOT MODE>>>>>>>>>>>>>>>",
1274 // Configure the TI device so we can use the BULK pipes for download
1275 status = TIConfigureBootDevice (serial->serial->dev);
1279 if (serial->serial->dev->descriptor.idVendor != USB_VENDOR_ID_ION) {
1280 dbg ("%s - VID = 0x%x", __FUNCTION__,
1281 serial->serial->dev->descriptor.idVendor);
1282 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
1283 goto StayInBootMode;
1286 // We have an ION device (I2c Must be programmed)
1287 // Determine I2C image type
1288 if (TIGetI2cTypeInBootMode(serial)) {
1289 goto StayInBootMode;
1292 // Registry variable set?
1293 if (TIStayInBootMode) {
1294 dbg ("%s - TIStayInBootMode", __FUNCTION__);
1295 goto StayInBootMode;
1298 // Check for ION Vendor ID and that the I2C is valid
1299 if (!TiValidateI2cImage(serial)) {
1300 struct ti_i2c_image_header *header;
1306 /* Validate Hardware version number
1307 * Read Manufacturing Descriptor from TI Based Edgeport
1309 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL);
1310 if (!ti_manuf_desc) {
1311 err ("%s - out of memory.", __FUNCTION__);
1314 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc);
1316 kfree (ti_manuf_desc);
1317 goto StayInBootMode;
1320 // Check for version 2
1321 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) {
1322 dbg ("%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__,
1323 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev));
1324 kfree (ti_manuf_desc);
1325 goto StayInBootMode;
1328 kfree (ti_manuf_desc);
1330 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1331 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1332 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1333 // And finally when the device comes back up in download mode the driver will cause
1334 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1335 // the record type from 0xf2 to 0x02.
1338 * Do we really have to copy the whole firmware image,
1339 * or could we do this in place!
1342 // Allocate a 15.5k buffer + 3 byte header
1343 buffer_size = (((1024 * 16) - 512) + sizeof(struct ti_i2c_image_header));
1344 buffer = kmalloc (buffer_size, GFP_KERNEL);
1346 err ("%s - out of memory", __FUNCTION__);
1350 // Initialize the buffer to 0xff (pad the buffer)
1351 memset (buffer, 0xff, buffer_size);
1353 memcpy (buffer, &PagableOperationalCodeImage[0], PagableOperationalCodeSize);
1355 for(i = sizeof(struct ti_i2c_image_header); i < buffer_size; i++) {
1356 cs = (__u8)(cs + buffer[i]);
1359 header = (struct ti_i2c_image_header *)buffer;
1361 // update length and checksum after padding
1362 header->Length = (__u16)(buffer_size - sizeof(struct ti_i2c_image_header));
1363 header->CheckSum = cs;
1365 // Download the operational code
1366 dbg ("%s - Downloading operational code image (TI UMP)", __FUNCTION__);
1367 status = TIDownloadCodeImage (serial, buffer, buffer_size);
1372 dbg ("%s - Error downloading operational code image", __FUNCTION__);
1376 // Device will reboot
1377 serial->product_info.TiMode = TI_MODE_TRANSITIONING;
1379 dbg ("%s - Download successful -- Device rebooting...", __FUNCTION__);
1381 /* return an error on purpose */
1386 // Eprom is invalid or blank stay in boot mode
1387 dbg ("%s - <<<<<<<<<<<<<<<STAYING IN BOOT MODE>>>>>>>>>>>>", __FUNCTION__);
1388 serial->product_info.TiMode = TI_MODE_BOOT;
1394 static int TISetDtr (struct edgeport_port *port)
1396 int port_number = port->port->number - port->port->serial->minor;
1398 dbg ("%s", __FUNCTION__);
1399 port->shadow_mcr |= MCR_DTR;
1401 return TIWriteCommandSync (port->port->serial->dev,
1403 (__u8)(UMPM_UART1_PORT + port_number),
1409 static int TIClearDtr (struct edgeport_port *port)
1411 int port_number = port->port->number - port->port->serial->minor;
1413 dbg ("%s", __FUNCTION__);
1414 port->shadow_mcr &= ~MCR_DTR;
1416 return TIWriteCommandSync (port->port->serial->dev,
1418 (__u8)(UMPM_UART1_PORT + port_number),
1424 static int TISetRts (struct edgeport_port *port)
1426 int port_number = port->port->number - port->port->serial->minor;
1428 dbg ("%s", __FUNCTION__);
1429 port->shadow_mcr |= MCR_RTS;
1431 return TIWriteCommandSync (port->port->serial->dev,
1433 (__u8)(UMPM_UART1_PORT + port_number),
1439 static int TIClearRts (struct edgeport_port *port)
1441 int port_number = port->port->number - port->port->serial->minor;
1443 dbg ("%s", __FUNCTION__);
1444 port->shadow_mcr &= ~MCR_RTS;
1446 return TIWriteCommandSync (port->port->serial->dev,
1448 (__u8)(UMPM_UART1_PORT + port_number),
1454 static int TISetLoopBack (struct edgeport_port *port)
1456 int port_number = port->port->number - port->port->serial->minor;
1458 dbg ("%s", __FUNCTION__);
1460 return TIWriteCommandSync (port->port->serial->dev,
1461 UMPC_SET_CLR_LOOPBACK,
1462 (__u8)(UMPM_UART1_PORT + port_number),
1468 static int TIClearLoopBack (struct edgeport_port *port)
1470 int port_number = port->port->number - port->port->serial->minor;
1472 dbg ("%s", __FUNCTION__);
1474 return TIWriteCommandSync (port->port->serial->dev,
1475 UMPC_SET_CLR_LOOPBACK,
1476 (__u8)(UMPM_UART1_PORT + port_number),
1482 static int TISetBreak (struct edgeport_port *port)
1484 int port_number = port->port->number - port->port->serial->minor;
1486 dbg ("%s", __FUNCTION__);
1488 return TIWriteCommandSync (port->port->serial->dev,
1490 (__u8)(UMPM_UART1_PORT + port_number),
1496 static int TIClearBreak (struct edgeport_port *port)
1498 int port_number = port->port->number - port->port->serial->minor;
1500 dbg ("%s", __FUNCTION__);
1502 return TIWriteCommandSync (port->port->serial->dev,
1504 (__u8)(UMPM_UART1_PORT + port_number),
1510 static int TIRestoreMCR (struct edgeport_port *port, __u8 mcr)
1514 dbg ("%s - %x", __FUNCTION__, mcr);
1517 status = TISetDtr (port);
1519 status = TIClearDtr (port);
1525 status = TISetRts (port);
1527 status = TIClearRts (port);
1532 if (mcr & MCR_LOOPBACK)
1533 status = TISetLoopBack (port);
1535 status = TIClearLoopBack (port);
1542 /* Convert TI LSR to standard UART flags */
1543 static __u8 MapLineStatus (__u8 ti_lsr)
1547 #define MAP_FLAG(flagUmp, flagUart) \
1548 if (ti_lsr & flagUmp) lsr |= flagUart;
1550 MAP_FLAG(UMP_UART_LSR_OV_MASK, LSR_OVER_ERR) /* overrun */
1551 MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */
1552 MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */
1553 MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */
1554 MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* receive data available */
1555 MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* transmit holding register empty */
1562 static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr)
1564 struct async_icount *icount;
1566 dbg ("%s - %02x", __FUNCTION__, msr);
1568 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
1569 icount = &edge_port->icount;
1571 /* update input line counters */
1572 if (msr & EDGEPORT_MSR_DELTA_CTS)
1574 if (msr & EDGEPORT_MSR_DELTA_DSR)
1576 if (msr & EDGEPORT_MSR_DELTA_CD)
1578 if (msr & EDGEPORT_MSR_DELTA_RI)
1580 wake_up_interruptible (&edge_port->delta_msr_wait);
1583 /* Save the new modem status */
1584 edge_port->shadow_msr = msr & 0xf0;
1589 static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8 lsr, __u8 data)
1591 struct async_icount *icount;
1592 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK));
1594 dbg ("%s - %02x", __FUNCTION__, new_lsr);
1596 edge_port->shadow_lsr = lsr;
1598 if (new_lsr & LSR_BREAK) {
1600 * Parity and Framing errors only count if they
1601 * occur exclusive of a break being received.
1603 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
1606 /* Place LSR data byte into Rx buffer */
1607 if (lsr_data && edge_port->port->tty) {
1608 tty_insert_flip_char(edge_port->port->tty, data, 0);
1609 tty_flip_buffer_push(edge_port->port->tty);
1612 /* update input line counters */
1613 icount = &edge_port->icount;
1614 if (new_lsr & LSR_BREAK)
1616 if (new_lsr & LSR_OVER_ERR)
1618 if (new_lsr & LSR_PAR_ERR)
1620 if (new_lsr & LSR_FRM_ERR)
1625 static void edge_interrupt_callback (struct urb *urb)
1627 struct edgeport_serial *edge_serial = (struct edgeport_serial *)urb->context;
1628 struct usb_serial_port *port;
1629 struct edgeport_port *edge_port;
1630 unsigned char *data = urb->transfer_buffer;
1631 int length = urb->actual_length;
1637 dbg("%s", __FUNCTION__);
1639 if (serial_paranoia_check (edge_serial->serial, __FUNCTION__)) {
1644 dbg("%s - nonzero control read status received: %d", __FUNCTION__, urb->status);
1649 dbg ("%s - no data in urb", __FUNCTION__);
1653 usb_serial_debug_data (__FILE__, __FUNCTION__, length, data);
1656 dbg ("%s - expecting packet of size 2, got %d", __FUNCTION__, length);
1660 port_number = TIUMP_GET_PORT_FROM_CODE (data[0]);
1661 function = TIUMP_GET_FUNC_FROM_CODE (data[0]);
1662 dbg ("%s - port_number %d, function %d, info 0x%x",
1663 __FUNCTION__, port_number, function, data[1]);
1664 port = &edge_serial->serial->port[port_number];
1665 if (port_paranoia_check (port, __FUNCTION__)) {
1666 dbg ("%s - change found for port that is not present",
1670 edge_port = port->private;
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 err ("%s - Unknown Interrupt code from UMP %x\n",
1701 __FUNCTION__, data[1]);
1707 static void edge_bulk_in_callback (struct urb *urb)
1709 struct edgeport_port *edge_port = (struct edgeport_port *)urb->context;
1710 unsigned char *data = urb->transfer_buffer;
1711 struct tty_struct *tty;
1716 dbg("%s", __FUNCTION__);
1718 if (port_paranoia_check (edge_port->port, __FUNCTION__))
1722 dbg ("%s - nonzero read bulk status received: %d",
1723 __FUNCTION__, urb->status);
1725 if (urb->status == -EPIPE) {
1726 /* clear any problem that might have happened on this pipe */
1727 usb_clear_halt (edge_port->port->serial->dev, urb->pipe);
1733 port_number = edge_port->port->number - edge_port->port->serial->minor;
1735 if (edge_port->lsr_event) {
1736 edge_port->lsr_event = 0;
1737 dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
1738 __FUNCTION__, port_number, edge_port->lsr_mask, *data);
1739 handle_new_lsr (edge_port, 1, edge_port->lsr_mask, *data);
1740 /* Adjust buffer length/pointer */
1741 --urb->actual_length;
1745 tty = edge_port->port->tty;
1746 if (tty && urb->actual_length) {
1747 usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data);
1749 if (edge_port->close_pending) {
1750 dbg ("%s - close is pending, dropping data on the floor.", __FUNCTION__);
1752 for (i = 0; i < urb->actual_length ; ++i) {
1753 /* if we insert more than TTY_FLIPBUF_SIZE characters,
1755 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
1756 tty_flip_buffer_push(tty);
1758 /* this doesn't actually push the data through unless
1759 * tty->low_latency is set */
1760 tty_insert_flip_char(tty, data[i], 0);
1762 tty_flip_buffer_push(tty);
1764 edge_port->icount.rx += urb->actual_length;
1768 /* continue always trying to read */
1769 urb->dev = edge_port->port->serial->dev;
1770 status = usb_submit_urb (urb);
1772 err ("%s - usb_submit_urb failed with result %d",
1773 __FUNCTION__, status);
1776 static void edge_bulk_out_callback (struct urb *urb)
1778 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1779 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1780 struct tty_struct *tty;
1782 dbg ("%s - port %d", __FUNCTION__, port->number);
1785 dbg ("%s - bad serial pointer, exiting", __FUNCTION__);
1790 dbg ("%s - nonzero write bulk status received: %d",
1791 __FUNCTION__, urb->status);
1793 if (urb->status == -EPIPE) {
1794 /* clear any problem that might have happened on this pipe */
1795 usb_clear_halt (serial->dev, urb->pipe);
1802 /* let the tty driver wakeup if it has a special write_wakeup function */
1807 static int edge_open (struct usb_serial_port *port, struct file * filp)
1809 struct edgeport_port *edge_port = (struct edgeport_port *)port->private;
1810 struct edgeport_serial *edge_serial;
1811 struct usb_device *dev;
1816 u8 transaction_timeout;
1818 if (port_paranoia_check (port, __FUNCTION__))
1821 dbg("%s - port %d", __FUNCTION__, port->number);
1823 if (edge_port == NULL)
1826 /* force low_latency on so that our tty_push actually forces the data through,
1827 otherwise it is scheduled, and with high data rates (like with OHCI) data
1830 port->tty->low_latency = 1;
1832 port_number = port->number - port->serial->minor;
1833 switch (port_number) {
1835 edge_port->uart_base = UMPMEM_BASE_UART1;
1836 edge_port->dma_address = UMPD_OEDB1_ADDRESS;
1839 edge_port->uart_base = UMPMEM_BASE_UART2;
1840 edge_port->dma_address = UMPD_OEDB2_ADDRESS;
1843 err ("Unknown port number!!!");
1847 dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
1848 __FUNCTION__, port_number, edge_port->uart_base, edge_port->dma_address);
1850 dev = port->serial->dev;
1852 memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount));
1853 init_waitqueue_head (&edge_port->delta_msr_wait);
1855 /* turn off loopback */
1856 status = TIClearLoopBack (edge_port);
1860 /* set up the port settings */
1861 edge_set_termios (port, NULL);
1863 /* open up the port */
1865 /* milliseconds to timeout for DMA transfer */
1866 transaction_timeout = 2;
1868 edge_port->ump_read_timeout = max (20, ((transaction_timeout * 3) / 2) );
1870 // milliseconds to timeout for DMA transfer
1871 open_settings = (u8)(UMP_DMA_MODE_CONTINOUS |
1872 UMP_PIPE_TRANS_TIMEOUT_ENA |
1873 (transaction_timeout << 2));
1875 dbg ("%s - Sending UMPC_OPEN_PORT", __FUNCTION__);
1877 /* Tell TI to open and start the port */
1878 status = TIWriteCommandSync (dev,
1880 (u8)(UMPM_UART1_PORT + port_number),
1887 /* Start the DMA? */
1888 status = TIWriteCommandSync (dev,
1890 (u8)(UMPM_UART1_PORT + port_number),
1897 /* Clear TX and RX buffers in UMP */
1898 status = TIPurgeDataSync (port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
1902 /* Read Initial MSR */
1903 status = TIReadVendorRequestSync (dev,
1904 UMPC_READ_MSR, // Request
1906 (__u16)(UMPM_UART1_PORT + port_number), // wIndex (Address)
1907 &edge_port->shadow_msr, // TransferBuffer
1908 1); // TransferBufferLength
1912 dbg ("ShadowMSR 0x%X", edge_port->shadow_msr);
1914 edge_serial = edge_port->edge_serial;
1915 if (edge_serial->num_ports_open == 0) {
1916 dbg ("%s - setting up bulk in urb", __FUNCTION__);
1917 /* we are the first port to be opened, let's post the interrupt urb */
1918 urb = edge_serial->serial->port[0].interrupt_in_urb;
1920 err ("%s - no interrupt urb present, exiting", __FUNCTION__);
1923 urb->complete = edge_interrupt_callback;
1924 urb->context = edge_serial;
1926 status = usb_submit_urb (urb);
1928 err ("%s - usb_submit_urb failed with value %d", __FUNCTION__, status);
1934 * reset the data toggle on the bulk endpoints to work around bug in
1935 * host controllers where things get out of sync some times
1937 usb_clear_halt (dev, port->write_urb->pipe);
1938 usb_clear_halt (dev, port->read_urb->pipe);
1940 /* start up our bulk read urb */
1941 urb = port->read_urb;
1943 err ("%s - no read urb present, exiting", __FUNCTION__);
1946 urb->complete = edge_bulk_in_callback;
1947 urb->context = edge_port;
1949 status = usb_submit_urb (urb);
1951 err ("%s - read bulk usb_submit_urb failed with value %d", __FUNCTION__, status);
1955 ++edge_serial->num_ports_open;
1957 dbg("%s - exited", __FUNCTION__);
1962 static void edge_close (struct usb_serial_port *port, struct file * filp)
1964 struct usb_serial *serial;
1965 struct edgeport_serial *edge_serial;
1966 struct edgeport_port *edge_port;
1970 if (port_paranoia_check (port, __FUNCTION__))
1973 dbg("%s - port %d", __FUNCTION__, port->number);
1975 serial = get_usb_serial (port, __FUNCTION__);
1979 edge_serial = (struct edgeport_serial *)serial->private;
1980 edge_port = (struct edgeport_port *)port->private;
1981 if ((edge_serial == NULL) || (edge_port == NULL))
1985 /* The bulkreadcompletion routine will check
1986 * this flag and dump add read data */
1987 edge_port->close_pending = 1;
1989 /* chase the port close */
1990 TIChasePort (edge_port);
1992 usb_unlink_urb (port->read_urb);
1994 /* assuming we can still talk to the device,
1995 * send a close port command to it */
1996 dbg("%s - send umpc_close_port", __FUNCTION__);
1997 port_number = port->number - port->serial->minor;
1998 status = TIWriteCommandSync (port->serial->dev,
2000 (__u8)(UMPM_UART1_PORT + port_number),
2004 --edge_port->edge_serial->num_ports_open;
2005 if (edge_port->edge_serial->num_ports_open <= 0) {
2006 /* last port is now closed, let's shut down our interrupt urb */
2007 usb_unlink_urb (serial->port[0].interrupt_in_urb);
2008 edge_port->edge_serial->num_ports_open = 0;
2010 edge_port->close_pending = 0;
2013 dbg("%s - exited", __FUNCTION__);
2016 static int edge_write (struct usb_serial_port *port, int from_user, const unsigned char *data, int count)
2018 struct usb_serial *serial = port->serial;
2019 struct edgeport_port *edge_port = port->private;
2022 dbg("%s - port %d", __FUNCTION__, port->number);
2025 dbg("%s - write request of 0 bytes", __FUNCTION__);
2029 if (edge_port == NULL)
2031 if (edge_port->close_pending == 1)
2034 if (port->write_urb->status == -EINPROGRESS) {
2035 dbg ("%s - already writing", __FUNCTION__);
2039 count = min (count, port->bulk_out_size);
2042 if (copy_from_user(port->write_urb->transfer_buffer, data, count))
2045 memcpy (port->write_urb->transfer_buffer, data, count);
2048 usb_serial_debug_data (__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer);
2050 /* set up our urb */
2051 usb_fill_bulk_urb (port->write_urb, serial->dev,
2052 usb_sndbulkpipe (serial->dev,
2053 port->bulk_out_endpointAddress),
2054 port->write_urb->transfer_buffer, count,
2055 edge_bulk_out_callback,
2058 /* send the data out the bulk port */
2059 result = usb_submit_urb(port->write_urb);
2061 err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
2066 edge_port->icount.tx += count;
2071 static int edge_write_room (struct usb_serial_port *port)
2073 struct edgeport_port *edge_port = (struct edgeport_port *)(port->private);
2076 dbg("%s", __FUNCTION__);
2078 if (edge_port == NULL)
2080 if (edge_port->close_pending == 1)
2083 dbg("%s - port %d", __FUNCTION__, port->number);
2085 if (port->write_urb->status != -EINPROGRESS)
2086 room = port->bulk_out_size;
2088 dbg("%s - returns %d", __FUNCTION__, room);
2092 static int edge_chars_in_buffer (struct usb_serial_port *port)
2094 struct edgeport_port *edge_port = (struct edgeport_port *)(port->private);
2097 dbg("%s", __FUNCTION__);
2099 if (edge_port == NULL)
2101 if (edge_port->close_pending == 1)
2104 dbg("%s - port %d", __FUNCTION__, port->number);
2106 if (port->write_urb->status == -EINPROGRESS)
2107 chars = port->write_urb->transfer_buffer_length;
2109 dbg ("%s - returns %d", __FUNCTION__, chars);
2113 static void edge_throttle (struct usb_serial_port *port)
2115 struct edgeport_port *edge_port = (struct edgeport_port *)(port->private);
2116 struct tty_struct *tty;
2119 dbg("%s - port %d", __FUNCTION__, port->number);
2121 if (edge_port == NULL)
2126 dbg ("%s - no tty available", __FUNCTION__);
2129 /* if we are implementing XON/XOFF, send the stop character */
2131 unsigned char stop_char = STOP_CHAR(tty);
2132 status = edge_write (port, 0, &stop_char, 1);
2138 /* if we are implementing RTS/CTS, toggle that line */
2139 if (tty->termios->c_cflag & CRTSCTS) {
2140 status = TIClearRts (edge_port);
2143 usb_unlink_urb (port->read_urb);
2146 static void edge_unthrottle (struct usb_serial_port *port)
2148 struct edgeport_port *edge_port = (struct edgeport_port *)(port->private);
2149 struct tty_struct *tty;
2152 dbg("%s - port %d", __FUNCTION__, port->number);
2154 if (edge_port == NULL)
2159 dbg ("%s - no tty available", __FUNCTION__);
2163 /* if we are implementing XON/XOFF, send the start character */
2165 unsigned char start_char = START_CHAR(tty);
2166 status = edge_write (port, 0, &start_char, 1);
2172 /* if we are implementing RTS/CTS, toggle that line */
2173 if (tty->termios->c_cflag & CRTSCTS) {
2174 status = TISetRts (edge_port);
2177 port->read_urb->dev = port->serial->dev;
2178 status = usb_submit_urb (port->read_urb);
2180 err ("%s - usb_submit_urb failed with value %d", __FUNCTION__, status);
2185 static void change_port_settings (struct edgeport_port *edge_port, struct termios *old_termios)
2187 struct ump_uart_config *config;
2188 struct tty_struct *tty;
2193 int port_number = edge_port->port->number - edge_port->port->serial->minor;
2195 dbg("%s - port %d", __FUNCTION__, edge_port->port->number);
2197 tty = edge_port->port->tty;
2200 dbg("%s - no tty structures", __FUNCTION__);
2204 config = kmalloc (sizeof (*config), GFP_KERNEL);
2206 err ("%s - out of memory", __FUNCTION__);
2210 cflag = tty->termios->c_cflag;
2214 /* These flags must be set */
2215 config->wFlags |= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT;
2216 config->wFlags |= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR;
2217 config->bUartMode = 0;
2219 switch (cflag & CSIZE) {
2221 config->bDataBits = UMP_UART_CHAR5BITS;
2222 dbg ("%s - data bits = 5", __FUNCTION__);
2225 config->bDataBits = UMP_UART_CHAR6BITS;
2226 dbg ("%s - data bits = 6", __FUNCTION__);
2229 config->bDataBits = UMP_UART_CHAR7BITS;
2230 dbg ("%s - data bits = 7", __FUNCTION__);
2234 config->bDataBits = UMP_UART_CHAR8BITS;
2235 dbg ("%s - data bits = 8", __FUNCTION__);
2239 if (cflag & PARENB) {
2240 if (cflag & PARODD) {
2241 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2242 config->bParity = UMP_UART_ODDPARITY;
2243 dbg("%s - parity = odd", __FUNCTION__);
2245 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2246 config->bParity = UMP_UART_EVENPARITY;
2247 dbg("%s - parity = even", __FUNCTION__);
2250 config->bParity = UMP_UART_NOPARITY;
2251 dbg("%s - parity = none", __FUNCTION__);
2254 if (cflag & CSTOPB) {
2255 config->bStopBits = UMP_UART_STOPBIT2;
2256 dbg("%s - stop bits = 2", __FUNCTION__);
2258 config->bStopBits = UMP_UART_STOPBIT1;
2259 dbg("%s - stop bits = 1", __FUNCTION__);
2262 /* figure out the flow control settings */
2263 if (cflag & CRTSCTS) {
2264 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW;
2265 config->wFlags |= UMP_MASK_UART_FLAGS_RTS_FLOW;
2266 dbg("%s - RTS/CTS is enabled", __FUNCTION__);
2268 dbg("%s - RTS/CTS is disabled", __FUNCTION__);
2271 /* if we are implementing XON/XOFF, set the start and stop character in the device */
2272 if (I_IXOFF(tty) || I_IXON(tty)) {
2273 config->cXon = START_CHAR(tty);
2274 config->cXoff = STOP_CHAR(tty);
2276 /* if we are implementing INBOUND XON/XOFF */
2278 config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
2279 dbg ("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2280 __FUNCTION__, config->cXon, config->cXoff);
2282 dbg ("%s - INBOUND XON/XOFF is disabled", __FUNCTION__);
2285 /* if we are implementing OUTBOUND XON/XOFF */
2287 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
2288 dbg ("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2289 __FUNCTION__, config->cXon, config->cXoff);
2291 dbg ("%s - OUTBOUND XON/XOFF is disabled", __FUNCTION__);
2295 /* Round the baud rate */
2296 baud = tty_get_baud_rate(tty);
2298 /* pick a default, any default... */
2301 config->wBaudRate = (__u16)(461550L / baud);
2302 round = 4615500L / baud;
2303 if ((round - (config->wBaudRate * 10)) >= 5)
2304 config->wBaudRate++;
2306 dbg ("%s - baud rate = %d, wBaudRate = %d", __FUNCTION__, baud, config->wBaudRate);
2308 dbg ("wBaudRate: %d", (int)(461550L / config->wBaudRate));
2309 dbg ("wFlags: 0x%x", config->wFlags);
2310 dbg ("bDataBits: %d", config->bDataBits);
2311 dbg ("bParity: %d", config->bParity);
2312 dbg ("bStopBits: %d", config->bStopBits);
2313 dbg ("cXon: %d", config->cXon);
2314 dbg ("cXoff: %d", config->cXoff);
2315 dbg ("bUartMode: %d", config->bUartMode);
2317 /* move the word values into big endian mode */
2318 cpu_to_be16s (&config->wFlags);
2319 cpu_to_be16s (&config->wBaudRate);
2321 status = TIWriteCommandSync (edge_port->port->serial->dev,
2323 (__u8)(UMPM_UART1_PORT + port_number),
2328 dbg ("%s - error %d when trying to write config to device",
2329 __FUNCTION__, status);
2337 static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios)
2339 struct edgeport_port *edge_port = (struct edgeport_port *)(port->private);
2340 struct tty_struct *tty = port->tty;
2343 if (!port->tty || !port->tty->termios) {
2344 dbg ("%s - no tty or termios", __FUNCTION__);
2348 cflag = tty->termios->c_cflag;
2349 /* check that they really want us to change something */
2351 if ((cflag == old_termios->c_cflag) &&
2352 (RELEVANT_IFLAG(tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
2353 dbg ("%s - nothing to change", __FUNCTION__);
2358 dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
2359 tty->termios->c_cflag,
2360 RELEVANT_IFLAG(tty->termios->c_iflag));
2362 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
2363 old_termios->c_cflag,
2364 RELEVANT_IFLAG(old_termios->c_iflag));
2367 dbg("%s - port %d", __FUNCTION__, port->number);
2369 if (edge_port == NULL)
2372 /* change the port settings to the new ones specified */
2373 change_port_settings (edge_port, old_termios);
2378 static int set_modem_info (struct edgeport_port *edge_port, unsigned int cmd, unsigned int *value)
2380 unsigned int mcr = edge_port->shadow_mcr;
2383 if (copy_from_user(&arg, value, sizeof(int)))
2388 if (arg & TIOCM_RTS)
2390 if (arg & TIOCM_DTR)
2392 if (arg & TIOCM_LOOP)
2393 mcr |= MCR_LOOPBACK;
2397 if (arg & TIOCM_RTS)
2399 if (arg & TIOCM_DTR)
2401 if (arg & TIOCM_LOOP)
2402 mcr &= ~MCR_LOOPBACK;
2406 /* turn off the RTS and DTR and LOOPBACK
2407 * and then only turn on what was asked to */
2408 mcr &= ~(MCR_RTS | MCR_DTR | MCR_LOOPBACK);
2409 mcr |= ((arg & TIOCM_RTS) ? MCR_RTS : 0);
2410 mcr |= ((arg & TIOCM_DTR) ? MCR_DTR : 0);
2411 mcr |= ((arg & TIOCM_LOOP) ? MCR_LOOPBACK : 0);
2415 edge_port->shadow_mcr = mcr;
2417 TIRestoreMCR (edge_port, mcr);
2422 static int get_modem_info (struct edgeport_port *edge_port, unsigned int *value)
2424 unsigned int result = 0;
2425 unsigned int msr = edge_port->shadow_msr;
2426 unsigned int mcr = edge_port->shadow_mcr;
2428 result = ((mcr & MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */
2429 | ((mcr & MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */
2430 | ((msr & EDGEPORT_MSR_CTS) ? TIOCM_CTS: 0) /* 0x020 */
2431 | ((msr & EDGEPORT_MSR_CD) ? TIOCM_CAR: 0) /* 0x040 */
2432 | ((msr & EDGEPORT_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */
2433 | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
2436 dbg("%s -- %x", __FUNCTION__, result);
2438 if (copy_to_user(value, &result, sizeof(int)))
2443 static int get_serial_info (struct edgeport_port *edge_port, struct serial_struct * retinfo)
2445 struct serial_struct tmp;
2450 memset(&tmp, 0, sizeof(tmp));
2452 tmp.type = PORT_16550A;
2453 tmp.line = edge_port->port->serial->minor;
2454 tmp.port = edge_port->port->number;
2456 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2457 tmp.xmit_fifo_size = edge_port->port->bulk_out_size;
2458 tmp.baud_base = 9600;
2459 tmp.close_delay = 5*HZ;
2460 tmp.closing_wait = 30*HZ;
2461 // tmp.custom_divisor = state->custom_divisor;
2462 // tmp.hub6 = state->hub6;
2463 // tmp.io_type = state->io_type;
2466 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2471 static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg)
2473 struct edgeport_port *edge_port = (struct edgeport_port *)(port->private);
2474 struct async_icount cnow;
2475 struct async_icount cprev;
2477 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd);
2481 dbg("%s - (%d) TIOCINQ", __FUNCTION__, port->number);
2482 // return get_number_bytes_avail(edge_port, (unsigned int *) arg);
2486 dbg("%s - (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
2487 // return get_lsr_info(edge_port, (unsigned int *) arg);
2493 dbg("%s - (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__, port->number);
2494 return set_modem_info(edge_port, cmd, (unsigned int *) arg);
2498 dbg("%s - (%d) TIOCMGET", __FUNCTION__, port->number);
2499 return get_modem_info(edge_port, (unsigned int *) arg);
2503 dbg("%s - (%d) TIOCGSERIAL", __FUNCTION__, port->number);
2504 return get_serial_info(edge_port, (struct serial_struct *) arg);
2508 dbg("%s - (%d) TIOCSSERIAL", __FUNCTION__, port->number);
2512 dbg("%s - (%d) TIOCMIWAIT", __FUNCTION__, port->number);
2513 cprev = edge_port->icount;
2515 interruptible_sleep_on(&edge_port->delta_msr_wait);
2516 /* see if a signal did it */
2517 if (signal_pending(current))
2518 return -ERESTARTSYS;
2519 cnow = edge_port->icount;
2520 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2521 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2522 return -EIO; /* no change => error */
2523 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2524 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2525 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2526 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2535 dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__,
2536 port->number, edge_port->icount.rx, edge_port->icount.tx);
2537 if (copy_to_user((void *)arg, &edge_port->icount, sizeof(edge_port->icount)))
2542 return -ENOIOCTLCMD;
2545 static void edge_break (struct usb_serial_port *port, int break_state)
2547 struct edgeport_port *edge_port = (struct edgeport_port *)(port->private);
2550 dbg ("%s - state = %d", __FUNCTION__, break_state);
2552 /* chase the port close */
2553 TIChasePort (edge_port);
2555 if (break_state == -1) {
2556 status = TISetBreak (edge_port);
2558 status = TIClearBreak (edge_port);
2561 dbg ("%s - error %d sending break set/clear command.",
2562 __FUNCTION__, status);
2566 static int edge_startup (struct usb_serial *serial)
2568 struct edgeport_serial *edge_serial;
2569 struct edgeport_port *edge_port;
2570 struct usb_device *dev;
2576 /* create our private serial structure */
2577 edge_serial = kmalloc (sizeof(struct edgeport_serial), GFP_KERNEL);
2578 if (edge_serial == NULL) {
2579 err("%s - Out of memory", __FUNCTION__);
2582 memset (edge_serial, 0, sizeof(struct edgeport_serial));
2583 edge_serial->serial = serial;
2584 serial->private = edge_serial;
2586 status = TIDownloadFirmware (edge_serial);
2588 kfree (edge_serial);
2592 /* set up our port private structures */
2593 for (i = 0; i < serial->num_ports; ++i) {
2594 edge_port = kmalloc (sizeof(struct edgeport_port), GFP_KERNEL);
2595 if (edge_port == NULL) {
2596 err("%s - Out of memory", __FUNCTION__);
2599 memset (edge_port, 0, sizeof(struct edgeport_port));
2600 edge_port->port = &serial->port[i];
2601 edge_port->edge_serial = edge_serial;
2602 serial->port[i].private = edge_port;
2608 static void edge_shutdown (struct usb_serial *serial)
2612 dbg ("%s", __FUNCTION__);
2614 for (i=0; i < serial->num_ports; ++i) {
2615 kfree (serial->port[i].private);
2616 serial->port[i].private = NULL;
2618 kfree (serial->private);
2619 serial->private = NULL;
2623 static struct usb_serial_device_type edgeport_1port_device = {
2625 name: "Edgeport TI 1 port adapter",
2626 id_table: edgeport_1port_id_table,
2627 num_interrupt_in: 1,
2633 throttle: edge_throttle,
2634 unthrottle: edge_unthrottle,
2635 startup: edge_startup,
2636 shutdown: edge_shutdown,
2638 set_termios: edge_set_termios,
2640 write_room: edge_write_room,
2641 chars_in_buffer: edge_chars_in_buffer,
2642 break_ctl: edge_break,
2645 static struct usb_serial_device_type edgeport_2port_device = {
2647 name: "Edgeport TI 2 port adapter",
2648 id_table: edgeport_2port_id_table,
2649 num_interrupt_in: 1,
2655 throttle: edge_throttle,
2656 unthrottle: edge_unthrottle,
2657 startup: edge_startup,
2658 shutdown: edge_shutdown,
2660 set_termios: edge_set_termios,
2662 write_room: edge_write_room,
2663 chars_in_buffer: edge_chars_in_buffer,
2664 break_ctl: edge_break,
2668 static int __init edgeport_init(void)
2670 usb_serial_register (&edgeport_1port_device);
2671 usb_serial_register (&edgeport_2port_device);
2672 info(DRIVER_DESC " " DRIVER_VERSION);
2676 static void __exit edgeport_exit (void)
2678 usb_serial_deregister (&edgeport_1port_device);
2679 usb_serial_deregister (&edgeport_2port_device);
2682 module_init(edgeport_init);
2683 module_exit(edgeport_exit);
2685 /* Module information */
2686 MODULE_AUTHOR(DRIVER_AUTHOR);
2687 MODULE_DESCRIPTION(DRIVER_DESC);
2688 MODULE_LICENSE("GPL");
2690 MODULE_PARM(debug, "i");
2691 MODULE_PARM_DESC(debug, "Debug enabled or not");
2693 MODULE_PARM(ignore_cpu_rev, "i");
2694 MODULE_PARM_DESC(ignore_cpu_rev, "Ignore the cpu revision when connecting to a device");