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>
39 #ifdef CONFIG_USB_SERIAL_DEBUG
45 #include "usb-serial.h"
48 #include "io_usbvend.h"
54 #define DRIVER_VERSION "v0.2"
55 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
56 #define DRIVER_DESC "Edgeport USB Serial Driver"
59 /* firmware image code */
60 #define IMAGE_VERSION_NAME PagableOperationalCodeImageVersion
61 #define IMAGE_ARRAY_NAME PagableOperationalCodeImage
62 #define IMAGE_SIZE PagableOperationalCodeSize
63 #include "io_fw_down3.h" /* Define array OperationalCodeImage[] */
65 #define EPROM_PAGE_SIZE 64
68 struct edgeport_uart_buf_desc {
69 __u32 count; // Number of bytes currently in buffer
72 /* different hardware types */
73 #define HARDWARE_TYPE_930 0
74 #define HARDWARE_TYPE_TIUMP 1
76 // IOCTL_PRIVATE_TI_GET_MODE Definitions
77 #define TI_MODE_CONFIGURING 0 // Device has not entered start device
78 #define TI_MODE_BOOT 1 // Staying in boot mode
79 #define TI_MODE_DOWNLOAD 2 // Made it to download mode
80 #define TI_MODE_TRANSITIONING 3 // Currently in boot mode but transitioning to download mode
83 /* Product information read from the Edgeport */
86 int TiMode; // Current TI Mode
87 __u8 hardware_type; // Type of hardware
88 } __attribute__((packed));
91 struct edgeport_port {
98 __u32 ump_read_timeout; /* Number of miliseconds the UMP will
99 wait without data before completing
104 struct edgeport_uart_buf_desc tx;
105 struct async_icount icount;
106 wait_queue_head_t delta_msr_wait; /* for handling sleeping while
107 waiting for msr change to
109 struct edgeport_serial *edge_serial;
110 struct usb_serial_port *port;
113 struct edgeport_serial {
114 struct product_info product_info;
115 u8 TI_I2C_Type; // Type of I2C in UMP
116 u8 TiReadI2C; // Set to TRUE if we have read the I2c in Boot Mode
118 struct usb_serial *serial;
122 /* Devices that this driver supports */
123 static struct usb_device_id edgeport_1port_id_table [] = {
124 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
128 static struct usb_device_id edgeport_2port_id_table [] = {
129 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
130 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
131 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
132 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
133 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421_BOOT) },
134 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421_DOWN) },
135 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
136 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21_BOOT) },
137 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21_DOWN) },
138 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
139 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
140 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
141 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22) },
145 /* Devices that this driver supports */
146 static struct usb_device_id id_table_combined [] = {
147 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
148 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
149 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
150 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
151 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
152 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421_BOOT) },
153 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421_DOWN) },
154 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
155 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21_BOOT) },
156 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21_DOWN) },
157 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
158 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
159 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
160 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22) },
164 MODULE_DEVICE_TABLE (usb, id_table_combined);
166 static struct usb_driver io_driver = {
167 .owner = THIS_MODULE,
169 .probe = usb_serial_probe,
170 .disconnect = usb_serial_disconnect,
171 .id_table = id_table_combined,
175 static struct EDGE_FIRMWARE_VERSION_INFO OperationalCodeImageVersion;
177 static int TIStayInBootMode = 0;
178 static int ignore_cpu_rev = 0;
182 static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios);
184 static int TIReadVendorRequestSync (struct usb_device *dev,
193 status = usb_control_msg (dev,
194 usb_rcvctrlpipe(dev, 0),
206 if (status != size) {
207 dbg ("%s - wanted to write %d, but only wrote %d",
208 __FUNCTION__, size, status);
214 static int TISendVendorRequestSync (struct usb_device *dev,
223 status = usb_control_msg (dev,
224 usb_sndctrlpipe(dev, 0),
237 if (status != size) {
238 dbg ("%s - wanted to write %d, but only wrote %d",
239 __FUNCTION__, size, status);
245 static int TIWriteCommandSync (struct usb_device *dev, __u8 command,
246 __u8 moduleid, __u16 value, u8 *data,
249 return TISendVendorRequestSync (dev,
253 data, // TransferBuffer
254 size); // TransferBufferLength
259 /* clear tx/rx buffers and fifo in TI UMP */
260 static int TIPurgeDataSync (struct usb_serial_port *port, __u16 mask)
262 int port_number = port->number - port->serial->minor;
264 dbg ("%s - port %d, mask %x", __FUNCTION__, port_number, mask);
266 return TIWriteCommandSync (port->serial->dev,
268 (__u8)(UMPM_UART1_PORT + port_number),
275 * TIReadDownloadMemory - Read edgeport memory from TI chip
276 * @dev: usb device pointer
277 * @start_address: Device CPU address at which to read
278 * @length: Length of above data
279 * @address_type: Can read both XDATA and I2C
280 * @buffer: pointer to input data buffer
282 static int TIReadDownloadMemory(struct usb_device *dev, int start_address,
283 int length, __u8 address_type, __u8 *buffer)
287 __u16 be_start_address;
289 dbg ("%s - @ %x for %d", __FUNCTION__, start_address, length);
291 /* Read in blocks of 64 bytes
292 * (TI firmware can't handle more than 64 byte reads)
298 read_length = (__u8)length;
300 if (read_length > 1) {
301 dbg ("%s - @ %x for %d", __FUNCTION__,
302 start_address, read_length);
304 be_start_address = cpu_to_be16 (start_address);
305 status = TIReadVendorRequestSync (dev,
306 UMPC_MEMORY_READ, // Request
307 (__u16)address_type, // wValue (Address type)
308 be_start_address, // wIndex (Address to read)
309 buffer, // TransferBuffer
310 read_length); // TransferBufferLength
313 dbg ("%s - ERROR %x", __FUNCTION__, status);
317 if (read_length > 1) {
318 usb_serial_debug_data (__FILE__, __FUNCTION__,
319 read_length, buffer);
322 /* Update pointers/length */
323 start_address += read_length;
324 buffer += read_length;
325 length -= read_length;
331 static int TIReadRam (struct usb_device *dev, int start_address, int length, __u8 *buffer)
333 return TIReadDownloadMemory (dev,
336 DTK_ADDR_SPACE_XDATA,
340 /* Read edgeport memory to a given block */
341 static int TIReadBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 * buffer)
346 for (i=0; i< length; i++) {
347 status = TIReadVendorRequestSync (serial->serial->dev,
348 UMPC_MEMORY_READ, // Request
349 serial->TI_I2C_Type, // wValue (Address type)
350 (__u16)(start_address+i), // wIndex
351 &buffer[i], // TransferBuffer
352 0x01); // TransferBufferLength
354 dbg ("%s - ERROR %x", __FUNCTION__, status);
359 dbg ("%s - start_address = %x, length = %d", __FUNCTION__, start_address, length);
360 usb_serial_debug_data (__FILE__, __FUNCTION__, length, buffer);
362 serial->TiReadI2C = 1;
367 /* Write given block to TI EPROM memory */
368 static int TIWriteBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer)
374 /* Must do a read before write */
375 if (!serial->TiReadI2C) {
376 status = TIReadBootMemory(serial, 0, 1, &temp);
381 for (i=0; i < length; ++i) {
382 status = TISendVendorRequestSync (serial->serial->dev,
383 UMPC_MEMORY_WRITE, // Request
385 (__u16)(i+start_address), // wIndex
386 NULL, // TransferBuffer
387 0); // TransferBufferLength
392 dbg ("%s - start_sddr = %x, length = %d", __FUNCTION__, start_address, length);
393 usb_serial_debug_data (__FILE__, __FUNCTION__, length, buffer);
399 /* Write edgeport I2C memory to TI chip */
400 static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address, int length, __u8 address_type, __u8 *buffer)
404 __u16 be_start_address;
406 /* We can only send a maximum of 1 aligned byte page at a time */
408 /* calulate the number of bytes left in the first page */
409 write_length = EPROM_PAGE_SIZE - (start_address & (EPROM_PAGE_SIZE - 1));
411 if (write_length > length)
412 write_length = length;
414 dbg ("%s - BytesInFirstPage Addr = %x, length = %d", __FUNCTION__, start_address, write_length);
415 usb_serial_debug_data (__FILE__, __FUNCTION__, write_length, buffer);
417 /* Write first page */
418 be_start_address = cpu_to_be16 (start_address);
419 status = TISendVendorRequestSync (serial->serial->dev,
420 UMPC_MEMORY_WRITE, // Request
421 (__u16)address_type, // wValue
422 be_start_address, // wIndex
423 buffer, // TransferBuffer
426 dbg ("%s - ERROR %d", __FUNCTION__, status);
430 length -= write_length;
431 start_address += write_length;
432 buffer += write_length;
434 /* We should be aligned now -- can write max page size bytes at a time */
436 if (length > EPROM_PAGE_SIZE)
437 write_length = EPROM_PAGE_SIZE;
439 write_length = length;
441 dbg ("%s - Page Write Addr = %x, length = %d", __FUNCTION__, start_address, write_length);
442 usb_serial_debug_data (__FILE__, __FUNCTION__, write_length, buffer);
444 /* Write next page */
445 be_start_address = cpu_to_be16 (start_address);
446 status = TISendVendorRequestSync (serial->serial->dev,
447 UMPC_MEMORY_WRITE, // Request
448 (__u16)address_type, // wValue
449 be_start_address, // wIndex
450 buffer, // TransferBuffer
451 write_length); // TransferBufferLength
453 dbg ("%s - ERROR %d", __FUNCTION__, status);
457 length -= write_length;
458 start_address += write_length;
459 buffer += write_length;
464 /* Examine the UMP DMA registers and LSR
466 * Check the MSBit of the X and Y DMA byte count registers.
467 * A zero in this bit indicates that the TX DMA buffers are empty
468 * then check the TX Empty bit in the UART.
470 static int TIIsTxActive (struct edgeport_port *port)
473 struct out_endpoint_desc_block *oedb;
477 oedb = kmalloc (sizeof (* oedb), GFP_KERNEL);
479 dev_err (&port->port->dev, "%s - out of memory\n", __FUNCTION__);
483 lsr = kmalloc (1, GFP_KERNEL); /* Sigh, that's right, just one byte,
484 as not all platforms can do DMA
490 /* Read the DMA Count Registers */
491 status = TIReadRam (port->port->serial->dev,
497 goto exit_is_tx_active;
499 dbg ("%s - XByteCount 0x%X", __FUNCTION__, oedb->XByteCount);
502 status = TIReadRam (port->port->serial->dev,
503 port->uart_base + UMPMEM_OFFS_UART_LSR,
508 goto exit_is_tx_active;
509 dbg ("%s - LSR = 0x%X", __FUNCTION__, *lsr);
511 /* If either buffer has data or we are transmitting then return TRUE */
512 if ((oedb->XByteCount & 0x80 ) != 0 )
515 if ((*lsr & UMP_UART_LSR_TX_MASK ) == 0 )
518 /* We return Not Active if we get any kind of error */
520 dbg ("%s - return %d", __FUNCTION__, bytes_left );
527 static void TIChasePort(struct edgeport_port *port)
534 // Base the LoopTime on the baud rate
535 if (port->baud_rate == 0)
536 port->baud_rate = 1200;
538 write_size = port->tx.count;
539 loops = max(100, (100*write_size)/(port->baud_rate/10));
540 dbg ("%s - write_size %d, baud %d loop = %d", __FUNCTION__,
541 write_size, port->baud_rate, loops);
545 last_count = port->tx.count;
547 dbg ("%s - Tx Buffer Size = %d loops = %d", __FUNCTION__,
550 /* Is the Edgeport Buffer empty? */
551 if (port->tx.count == 0)
554 /* Block the thread for 10ms */
557 if (last_count == port->tx.count) {
558 /* No activity.. count down. */
561 dbg ("%s - Wait for TxEmpty - TIMEOUT",
566 /* Reset timeout value back to a minimum of 1 second */
567 dbg ("%s - Wait for TxEmpty Reset Count", __FUNCTION__);
568 goto restart_tx_loop;
572 dbg ("%s - Local Tx Buffer Empty -- Waiting for TI UMP to EMPTY X/Y and FIFO",
575 write_size = TIIsTxActive (port);
576 loops = max(50, (100*write_size)/(port->baud_rate/10));
577 dbg ("%s - write_size %d, baud %d loop = %d", __FUNCTION__,
578 write_size, port->baud_rate, loops);
581 /* This function takes 4 ms; */
582 if (!TIIsTxActive (port)) {
583 /* Delay a few char times */
585 dbg ("%s - Empty", __FUNCTION__);
591 dbg ("%s - TIMEOUT", __FUNCTION__);
597 static int TIChooseConfiguration (struct usb_device *dev)
599 // There may be multiple configurations on this device, in which case
600 // we would need to read and parse all of them to find out which one
601 // we want. However, we just support one config at this point,
602 // configuration # 1, which is Config Descriptor 0.
604 dbg ("%s - Number of Interfaces = %d", __FUNCTION__, dev->config->desc.bNumInterfaces);
605 dbg ("%s - MAX Power = %d", __FUNCTION__, dev->config->desc.bMaxPower*2);
607 if (dev->config->desc.bNumInterfaces != 1) {
608 dev_err (&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", __FUNCTION__);
615 static int TIReadRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer)
619 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
620 status = TIReadDownloadMemory (serial->serial->dev,
626 status = TIReadBootMemory (serial,
635 static int TIWriteRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer)
637 if (serial->product_info.TiMode == TI_MODE_BOOT)
638 return TIWriteBootMemory (serial,
643 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD)
644 return TIWriteDownloadI2C (serial,
655 /* Read a descriptor header from I2C based on type */
656 static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type, struct ti_i2c_desc *rom_desc)
661 /* Search for requested descriptor in I2C */
664 status = TIReadRom (serial,
666 sizeof(struct ti_i2c_desc),
671 if (rom_desc->Type == desc_type)
672 return start_address;
674 start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size;
676 } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type);
681 /* Validate descriptor checksum */
682 static int ValidChecksum(struct ti_i2c_desc *rom_desc, __u8 *buffer)
687 for (i=0; i < rom_desc->Size; i++) {
688 cs = (__u8)(cs + buffer[i]);
690 if (cs != rom_desc->CheckSum) {
691 dbg ("%s - Mismatch %x - %x", __FUNCTION__, rom_desc->CheckSum, cs);
697 /* Make sure that the I2C image is good */
698 static int TiValidateI2cImage (struct edgeport_serial *serial)
700 struct device *dev = &serial->serial->dev->dev;
702 struct ti_i2c_desc *rom_desc;
703 int start_address = 2;
706 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
708 dev_err (dev, "%s - out of memory\n", __FUNCTION__);
711 buffer = kmalloc (TI_MAX_I2C_SIZE, GFP_KERNEL);
713 dev_err (dev, "%s - out of memory when allocating buffer\n", __FUNCTION__);
718 // Read the first byte (Signature0) must be 0x52
719 status = TIReadRom (serial, 0, 1, buffer);
721 goto ExitTiValidateI2cImage;
723 if (*buffer != 0x52) {
724 dev_err (dev, "%s - invalid buffer signature\n", __FUNCTION__);
726 goto ExitTiValidateI2cImage;
731 status = TIReadRom (serial,
733 sizeof(struct ti_i2c_desc),
738 if ((start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size) > TI_MAX_I2C_SIZE) {
740 dbg ("%s - structure too big, erroring out.", __FUNCTION__);
744 dbg ("%s Type = 0x%x", __FUNCTION__, rom_desc->Type);
746 // Skip type 2 record
747 if ((rom_desc->Type & 0x0f) != I2C_DESC_TYPE_FIRMWARE_BASIC) {
748 // Read the descriptor data
749 status = TIReadRom(serial,
750 start_address+sizeof(struct ti_i2c_desc),
756 status = ValidChecksum(rom_desc, buffer);
760 start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size;
762 } while ((rom_desc->Type != I2C_DESC_TYPE_ION) && (start_address < TI_MAX_I2C_SIZE));
764 if ((rom_desc->Type != I2C_DESC_TYPE_ION) || (start_address > TI_MAX_I2C_SIZE))
767 ExitTiValidateI2cImage:
773 static int TIReadManufDescriptor (struct edgeport_serial *serial, __u8 *buffer)
777 struct ti_i2c_desc *rom_desc;
778 struct edge_ti_manuf_descriptor *desc;
780 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
782 dev_err (&serial->serial->dev->dev, "%s - out of memory\n", __FUNCTION__);
785 start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_ION, rom_desc);
787 if (!start_address) {
788 dbg ("%s - Edge Descriptor not found in I2C", __FUNCTION__);
793 // Read the descriptor data
794 status = TIReadRom (serial,
795 start_address+sizeof(struct ti_i2c_desc),
801 status = ValidChecksum(rom_desc, buffer);
803 desc = (struct edge_ti_manuf_descriptor *)buffer;
804 dbg ( "%s - IonConfig 0x%x", __FUNCTION__, desc->IonConfig );
805 dbg ( "%s - Version %d", __FUNCTION__, desc->Version );
806 dbg ( "%s - Cpu/Board 0x%x", __FUNCTION__, desc->CpuRev_BoardRev );
807 dbg ( "%s - NumPorts %d", __FUNCTION__, desc->NumPorts );
808 dbg ( "%s - NumVirtualPorts %d", __FUNCTION__, desc->NumVirtualPorts );
809 dbg ( "%s - TotalPorts %d", __FUNCTION__, desc->TotalPorts );
816 /* Build firmware header used for firmware update */
817 static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
823 struct ti_i2c_desc *i2c_header;
824 struct ti_i2c_image_header *img_header;
825 struct ti_i2c_firmware_rec *firmware_rec;
827 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
828 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
829 // will download the latest firmware (padded to 15.5k) into the UMP ram.
830 // And finally when the device comes back up in download mode the driver will cause
831 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
832 // the record type from 0xf2 to 0x02.
834 // Allocate a 15.5k buffer + 2 bytes for version number (Firmware Record)
835 buffer_size = (((1024 * 16) - 512 )+ sizeof(struct ti_i2c_firmware_rec));
837 buffer = kmalloc (buffer_size, GFP_KERNEL);
839 dev_err (dev, "%s - out of memory\n", __FUNCTION__);
843 // Set entire image of 0xffs
844 memset (buffer, 0xff, buffer_size);
846 // Copy version number into firmware record
847 firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
849 firmware_rec->Ver_Major = OperationalCodeImageVersion.MajorVersion;
850 firmware_rec->Ver_Minor = OperationalCodeImageVersion.MinorVersion;
852 // Pointer to fw_down memory image
853 img_header = (struct ti_i2c_image_header *)&PagableOperationalCodeImage[0];
855 memcpy (buffer + sizeof(struct ti_i2c_firmware_rec),
856 &PagableOperationalCodeImage[sizeof(struct ti_i2c_image_header)],
859 for (i=0; i < buffer_size; i++) {
860 cs = (__u8)(cs + buffer[i]);
866 i2c_header = (struct ti_i2c_desc *)header;
867 firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data;
869 i2c_header->Type = I2C_DESC_TYPE_FIRMWARE_BLANK;
870 i2c_header->Size = (__u16)buffer_size;
871 i2c_header->CheckSum = cs;
872 firmware_rec->Ver_Major = OperationalCodeImageVersion.MajorVersion;
873 firmware_rec->Ver_Minor = OperationalCodeImageVersion.MinorVersion;
878 /* Try to figure out what type of I2c we have */
879 static int TIGetI2cTypeInBootMode (struct edgeport_serial *serial)
884 // Try to read type 2
885 status = TIReadVendorRequestSync (serial->serial->dev,
886 UMPC_MEMORY_READ, // Request
887 DTK_ADDR_SPACE_I2C_TYPE_II, // wValue (Address type)
889 &data, // TransferBuffer
890 0x01); // TransferBufferLength
892 dbg ("%s - read 2 status error = %d", __FUNCTION__, status);
894 dbg ("%s - read 2 data = 0x%x", __FUNCTION__, data);
895 if ((!status) && data == 0x52) {
896 dbg ("%s - ROM_TYPE_II", __FUNCTION__);
897 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
901 // Try to read type 3
902 status = TIReadVendorRequestSync (serial->serial->dev,
903 UMPC_MEMORY_READ, // Request
904 DTK_ADDR_SPACE_I2C_TYPE_III, // wValue (Address type)
906 &data, // TransferBuffer
907 0x01); // TransferBufferLength
909 dbg ("%s - read 3 status error = %d", __FUNCTION__, status);
911 dbg ("%s - read 2 data = 0x%x", __FUNCTION__, data);
912 if ((!status) && data == 0x52) {
913 dbg ("%s - ROM_TYPE_III", __FUNCTION__);
914 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
918 dbg ("%s - Unknown", __FUNCTION__);
919 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
923 static int TISendBulkTransferSync (struct usb_serial *serial, void *buffer, int length, int *num_sent)
927 status = usb_bulk_msg (serial->dev,
928 usb_sndbulkpipe(serial->dev,
929 serial->port[0]->bulk_out_endpointAddress),
937 /* Download given firmware image to the device (IN BOOT MODE) */
938 static int TIDownloadCodeImage (struct edgeport_serial *serial, __u8 *image, int image_length)
945 // Transfer firmware image
946 for (pos = 0; pos < image_length; ) {
947 // Read the next buffer from file
948 transfer = image_length - pos;
949 if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE)
950 transfer = EDGE_FW_BULK_MAX_PACKET_SIZE;
953 status = TISendBulkTransferSync (serial->serial, &image[pos], transfer, &done);
956 // Advance buffer pointer
964 static int TIConfigureBootDevice (struct usb_device *dev)
970 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
972 * This routine downloads the main operating code into the TI5052, using the
973 * boot code already burned into E2PROM or ROM.
975 static int TIDownloadFirmware (struct edgeport_serial *serial)
977 struct device *dev = &serial->serial->dev->dev;
980 struct edge_ti_manuf_descriptor *ti_manuf_desc;
981 struct usb_interface_descriptor *interface;
982 int download_cur_ver;
983 int download_new_ver;
985 /* This routine is entered by both the BOOT mode and the Download mode
986 * We can determine which code is running by the reading the config
987 * descriptor and if we have only one bulk pipe it is in boot mode
989 serial->product_info.hardware_type = HARDWARE_TYPE_TIUMP;
991 /* Default to type 2 i2c */
992 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
994 status = TIChooseConfiguration (serial->serial->dev);
998 interface = &serial->serial->interface->cur_altsetting->desc;
1000 dev_err (&serial->serial->dev->dev, "%s - no interface set, error!", __FUNCTION__);
1004 // Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
1005 // if we have more than one endpoint we are definitely in download mode
1006 if (interface->bNumEndpoints > 1)
1007 serial->product_info.TiMode = TI_MODE_DOWNLOAD;
1009 // Otherwise we will remain in configuring mode
1010 serial->product_info.TiMode = TI_MODE_CONFIGURING;
1012 // Save Download Version Number
1013 OperationalCodeImageVersion.MajorVersion = PagableOperationalCodeImageVersion.MajorVersion;
1014 OperationalCodeImageVersion.MinorVersion = PagableOperationalCodeImageVersion.MinorVersion;
1015 OperationalCodeImageVersion.BuildNumber = PagableOperationalCodeImageVersion.BuildNumber;
1017 /********************************************************************/
1019 /********************************************************************/
1020 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
1021 struct ti_i2c_desc *rom_desc;
1023 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN DOWNLOAD MODE>>>>>>>>>>", __FUNCTION__);
1025 status = TiValidateI2cImage (serial);
1027 dbg ("%s - <<<<<<<<<<<<<<<DOWNLOAD MODE -- BAD I2C >>>>>>>>>>",
1032 /* Validate Hardware version number
1033 * Read Manufacturing Descriptor from TI Based Edgeport
1035 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL);
1036 if (!ti_manuf_desc) {
1037 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1040 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc);
1042 kfree (ti_manuf_desc);
1046 // Check version number of ION descriptor
1047 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) {
1048 dbg ( "%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__,
1049 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev));
1050 kfree (ti_manuf_desc);
1054 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
1056 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1057 kfree (ti_manuf_desc);
1061 // Search for type 2 record (firmware record)
1062 if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc)) != 0) {
1063 struct ti_i2c_firmware_rec *firmware_version;
1066 dbg ("%s - Found Type FIRMWARE (Type 2) record", __FUNCTION__);
1068 firmware_version = kmalloc (sizeof (*firmware_version), GFP_KERNEL);
1069 if (!firmware_version) {
1070 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1072 kfree (ti_manuf_desc);
1076 // Validate version number
1077 // Read the descriptor data
1078 status = TIReadRom (serial,
1079 start_address+sizeof(struct ti_i2c_desc),
1080 sizeof(struct ti_i2c_firmware_rec),
1081 (__u8 *)firmware_version);
1083 kfree (firmware_version);
1085 kfree (ti_manuf_desc);
1089 // Check version number of download with current version in I2c
1090 download_cur_ver = (firmware_version->Ver_Major << 8) +
1091 (firmware_version->Ver_Minor);
1092 download_new_ver = (OperationalCodeImageVersion.MajorVersion << 8) +
1093 (OperationalCodeImageVersion.MinorVersion);
1095 dbg ("%s - >>>Firmware Versions Device %d.%d Driver %d.%d",
1097 firmware_version->Ver_Major,
1098 firmware_version->Ver_Minor,
1099 OperationalCodeImageVersion.MajorVersion,
1100 OperationalCodeImageVersion.MinorVersion);
1102 // Check if we have an old version in the I2C and update if necessary
1103 if (download_cur_ver != download_new_ver) {
1104 dbg ("%s - Update I2C Download from %d.%d to %d.%d",
1106 firmware_version->Ver_Major,
1107 firmware_version->Ver_Minor,
1108 OperationalCodeImageVersion.MajorVersion,
1109 OperationalCodeImageVersion.MinorVersion);
1111 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1112 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1113 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1114 // And finally when the device comes back up in download mode the driver will cause
1115 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1116 // the record type from 0xf2 to 0x02.
1118 record = I2C_DESC_TYPE_FIRMWARE_BLANK;
1120 // Change the I2C Firmware record type to 0xf2 to trigger an update
1121 status = TIWriteRom (serial,
1126 kfree (firmware_version);
1128 kfree (ti_manuf_desc);
1132 // verify the write -- must do this in order for write to
1133 // complete before we do the hardware reset
1134 status = TIReadRom (serial,
1140 kfree (firmware_version);
1142 kfree (ti_manuf_desc);
1146 if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
1147 dev_err (dev, "%s - error resetting device\n", __FUNCTION__);
1148 kfree (firmware_version);
1150 kfree (ti_manuf_desc);
1154 dbg ("%s - HARDWARE RESET", __FUNCTION__);
1156 // Reset UMP -- Back to BOOT MODE
1157 status = TISendVendorRequestSync (serial->serial->dev,
1158 UMPC_HARDWARE_RESET, // Request
1161 NULL, // TransferBuffer
1162 0); // TransferBufferLength
1164 dbg ( "%s - HARDWARE RESET return %d", __FUNCTION__, status);
1166 /* return an error on purpose. */
1167 kfree (firmware_version);
1169 kfree (ti_manuf_desc);
1172 kfree (firmware_version);
1174 // Search for type 0xF2 record (firmware blank record)
1175 else if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) {
1176 #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + sizeof(struct ti_i2c_firmware_rec))
1180 header = kmalloc (HEADER_SIZE, GFP_KERNEL);
1182 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1184 kfree (ti_manuf_desc);
1188 vheader = kmalloc (HEADER_SIZE, GFP_KERNEL);
1190 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1193 kfree (ti_manuf_desc);
1197 dbg ("%s - Found Type BLANK FIRMWARE (Type F2) record", __FUNCTION__);
1199 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1200 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1201 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1202 // And finally when the device comes back up in download mode the driver will cause
1203 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1204 // the record type from 0xf2 to 0x02.
1205 status = BuildI2CFirmwareHeader(header, dev);
1210 kfree (ti_manuf_desc);
1214 // Update I2C with type 0xf2 record with correct size and checksum
1215 status = TIWriteRom (serial,
1223 kfree (ti_manuf_desc);
1227 // verify the write -- must do this in order for write to
1228 // complete before we do the hardware reset
1229 status = TIReadRom (serial,
1235 dbg ("%s - can't read header back", __FUNCTION__);
1239 kfree (ti_manuf_desc);
1242 if (memcmp(vheader, header, HEADER_SIZE)) {
1243 dbg ("%s - write download record failed", __FUNCTION__);
1247 kfree (ti_manuf_desc);
1254 dbg ("%s - Start firmware update", __FUNCTION__);
1256 // Tell firmware to copy download image into I2C
1257 status = TISendVendorRequestSync (serial->serial->dev,
1258 UMPC_COPY_DNLD_TO_I2C, // Request
1261 NULL, // TransferBuffer
1262 0); // TransferBufferLength
1264 dbg ("%s - Update complete 0x%x", __FUNCTION__, status);
1266 dbg ("%s - UMPC_COPY_DNLD_TO_I2C failed", __FUNCTION__);
1268 kfree (ti_manuf_desc);
1273 // The device is running the download code
1275 kfree (ti_manuf_desc);
1279 /********************************************************************/
1281 /********************************************************************/
1282 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN BOOT MODE>>>>>>>>>>>>>>>",
1285 // Configure the TI device so we can use the BULK pipes for download
1286 status = TIConfigureBootDevice (serial->serial->dev);
1290 if (serial->serial->dev->descriptor.idVendor != USB_VENDOR_ID_ION) {
1291 dbg ("%s - VID = 0x%x", __FUNCTION__,
1292 serial->serial->dev->descriptor.idVendor);
1293 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
1294 goto StayInBootMode;
1297 // We have an ION device (I2c Must be programmed)
1298 // Determine I2C image type
1299 if (TIGetI2cTypeInBootMode(serial)) {
1300 goto StayInBootMode;
1303 // Registry variable set?
1304 if (TIStayInBootMode) {
1305 dbg ("%s - TIStayInBootMode", __FUNCTION__);
1306 goto StayInBootMode;
1309 // Check for ION Vendor ID and that the I2C is valid
1310 if (!TiValidateI2cImage(serial)) {
1311 struct ti_i2c_image_header *header;
1317 /* Validate Hardware version number
1318 * Read Manufacturing Descriptor from TI Based Edgeport
1320 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL);
1321 if (!ti_manuf_desc) {
1322 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1325 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc);
1327 kfree (ti_manuf_desc);
1328 goto StayInBootMode;
1331 // Check for version 2
1332 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) {
1333 dbg ("%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__,
1334 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev));
1335 kfree (ti_manuf_desc);
1336 goto StayInBootMode;
1339 kfree (ti_manuf_desc);
1341 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1342 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1343 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1344 // And finally when the device comes back up in download mode the driver will cause
1345 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1346 // the record type from 0xf2 to 0x02.
1349 * Do we really have to copy the whole firmware image,
1350 * or could we do this in place!
1353 // Allocate a 15.5k buffer + 3 byte header
1354 buffer_size = (((1024 * 16) - 512) + sizeof(struct ti_i2c_image_header));
1355 buffer = kmalloc (buffer_size, GFP_KERNEL);
1357 dev_err (dev, "%s - out of memory\n", __FUNCTION__);
1361 // Initialize the buffer to 0xff (pad the buffer)
1362 memset (buffer, 0xff, buffer_size);
1364 memcpy (buffer, &PagableOperationalCodeImage[0], PagableOperationalCodeSize);
1366 for(i = sizeof(struct ti_i2c_image_header); i < buffer_size; i++) {
1367 cs = (__u8)(cs + buffer[i]);
1370 header = (struct ti_i2c_image_header *)buffer;
1372 // update length and checksum after padding
1373 header->Length = (__u16)(buffer_size - sizeof(struct ti_i2c_image_header));
1374 header->CheckSum = cs;
1376 // Download the operational code
1377 dbg ("%s - Downloading operational code image (TI UMP)", __FUNCTION__);
1378 status = TIDownloadCodeImage (serial, buffer, buffer_size);
1383 dbg ("%s - Error downloading operational code image", __FUNCTION__);
1387 // Device will reboot
1388 serial->product_info.TiMode = TI_MODE_TRANSITIONING;
1390 dbg ("%s - Download successful -- Device rebooting...", __FUNCTION__);
1392 /* return an error on purpose */
1397 // Eprom is invalid or blank stay in boot mode
1398 dbg ("%s - <<<<<<<<<<<<<<<STAYING IN BOOT MODE>>>>>>>>>>>>", __FUNCTION__);
1399 serial->product_info.TiMode = TI_MODE_BOOT;
1405 static int TISetDtr (struct edgeport_port *port)
1407 int port_number = port->port->number - port->port->serial->minor;
1409 dbg ("%s", __FUNCTION__);
1410 port->shadow_mcr |= MCR_DTR;
1412 return TIWriteCommandSync (port->port->serial->dev,
1414 (__u8)(UMPM_UART1_PORT + port_number),
1420 static int TIClearDtr (struct edgeport_port *port)
1422 int port_number = port->port->number - port->port->serial->minor;
1424 dbg ("%s", __FUNCTION__);
1425 port->shadow_mcr &= ~MCR_DTR;
1427 return TIWriteCommandSync (port->port->serial->dev,
1429 (__u8)(UMPM_UART1_PORT + port_number),
1435 static int TISetRts (struct edgeport_port *port)
1437 int port_number = port->port->number - port->port->serial->minor;
1439 dbg ("%s", __FUNCTION__);
1440 port->shadow_mcr |= MCR_RTS;
1442 return TIWriteCommandSync (port->port->serial->dev,
1444 (__u8)(UMPM_UART1_PORT + port_number),
1450 static int TIClearRts (struct edgeport_port *port)
1452 int port_number = port->port->number - port->port->serial->minor;
1454 dbg ("%s", __FUNCTION__);
1455 port->shadow_mcr &= ~MCR_RTS;
1457 return TIWriteCommandSync (port->port->serial->dev,
1459 (__u8)(UMPM_UART1_PORT + port_number),
1465 static int TISetLoopBack (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 TIClearLoopBack (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,
1486 UMPC_SET_CLR_LOOPBACK,
1487 (__u8)(UMPM_UART1_PORT + port_number),
1493 static int TISetBreak (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 TIClearBreak (struct edgeport_port *port)
1509 int port_number = port->port->number - port->port->serial->minor;
1511 dbg ("%s", __FUNCTION__);
1513 return TIWriteCommandSync (port->port->serial->dev,
1515 (__u8)(UMPM_UART1_PORT + port_number),
1521 static int TIRestoreMCR (struct edgeport_port *port, __u8 mcr)
1525 dbg ("%s - %x", __FUNCTION__, mcr);
1528 status = TISetDtr (port);
1530 status = TIClearDtr (port);
1536 status = TISetRts (port);
1538 status = TIClearRts (port);
1543 if (mcr & MCR_LOOPBACK)
1544 status = TISetLoopBack (port);
1546 status = TIClearLoopBack (port);
1553 /* Convert TI LSR to standard UART flags */
1554 static __u8 MapLineStatus (__u8 ti_lsr)
1558 #define MAP_FLAG(flagUmp, flagUart) \
1559 if (ti_lsr & flagUmp) \
1562 MAP_FLAG(UMP_UART_LSR_OV_MASK, LSR_OVER_ERR) /* overrun */
1563 MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */
1564 MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */
1565 MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */
1566 MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* receive data available */
1567 MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* transmit holding register empty */
1574 static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr)
1576 struct async_icount *icount;
1578 dbg ("%s - %02x", __FUNCTION__, msr);
1580 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
1581 icount = &edge_port->icount;
1583 /* update input line counters */
1584 if (msr & EDGEPORT_MSR_DELTA_CTS)
1586 if (msr & EDGEPORT_MSR_DELTA_DSR)
1588 if (msr & EDGEPORT_MSR_DELTA_CD)
1590 if (msr & EDGEPORT_MSR_DELTA_RI)
1592 wake_up_interruptible (&edge_port->delta_msr_wait);
1595 /* Save the new modem status */
1596 edge_port->shadow_msr = msr & 0xf0;
1601 static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8 lsr, __u8 data)
1603 struct async_icount *icount;
1604 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK));
1606 dbg ("%s - %02x", __FUNCTION__, new_lsr);
1608 edge_port->shadow_lsr = lsr;
1610 if (new_lsr & LSR_BREAK) {
1612 * Parity and Framing errors only count if they
1613 * occur exclusive of a break being received.
1615 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
1618 /* Place LSR data byte into Rx buffer */
1619 if (lsr_data && edge_port->port->tty) {
1620 tty_insert_flip_char(edge_port->port->tty, data, 0);
1621 tty_flip_buffer_push(edge_port->port->tty);
1624 /* update input line counters */
1625 icount = &edge_port->icount;
1626 if (new_lsr & LSR_BREAK)
1628 if (new_lsr & LSR_OVER_ERR)
1630 if (new_lsr & LSR_PAR_ERR)
1632 if (new_lsr & LSR_FRM_ERR)
1637 static void edge_interrupt_callback (struct urb *urb, struct pt_regs *regs)
1639 struct edgeport_serial *edge_serial = (struct edgeport_serial *)urb->context;
1640 struct usb_serial_port *port;
1641 struct edgeport_port *edge_port;
1642 unsigned char *data = urb->transfer_buffer;
1643 int length = urb->actual_length;
1650 dbg("%s", __FUNCTION__);
1652 switch (urb->status) {
1659 /* this urb is terminated, clean up */
1660 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
1663 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
1668 dbg ("%s - no data in urb", __FUNCTION__);
1672 usb_serial_debug_data (__FILE__, __FUNCTION__, length, data);
1675 dbg ("%s - expecting packet of size 2, got %d", __FUNCTION__, length);
1679 port_number = TIUMP_GET_PORT_FROM_CODE (data[0]);
1680 function = TIUMP_GET_FUNC_FROM_CODE (data[0]);
1681 dbg ("%s - port_number %d, function %d, info 0x%x",
1682 __FUNCTION__, port_number, function, data[1]);
1683 port = edge_serial->serial->port[port_number];
1684 edge_port = usb_get_serial_port_data(port);
1686 dbg ("%s - edge_port not found", __FUNCTION__);
1690 case TIUMP_INTERRUPT_CODE_LSR:
1691 lsr = MapLineStatus(data[1]);
1692 if (lsr & UMP_UART_LSR_DATA_MASK) {
1693 /* Save the LSR event for bulk read completion routine */
1694 dbg ("%s - LSR Event Port %u LSR Status = %02x",
1695 __FUNCTION__, port_number, lsr);
1696 edge_port->lsr_event = 1;
1697 edge_port->lsr_mask = lsr;
1699 dbg ("%s - ===== Port %d LSR Status = %02x ======",
1700 __FUNCTION__, port_number, lsr);
1701 handle_new_lsr (edge_port, 0, lsr, 0);
1705 case TIUMP_INTERRUPT_CODE_MSR: // MSR
1706 /* Copy MSR from UMP */
1708 dbg ("%s - ===== Port %u MSR Status = %02x ======\n",
1709 __FUNCTION__, port_number, msr);
1710 handle_new_msr (edge_port, msr);
1714 dev_err (&urb->dev->dev, "%s - Unknown Interrupt code from UMP %x\n",
1715 __FUNCTION__, data[1]);
1721 status = usb_submit_urb (urb, GFP_ATOMIC);
1723 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
1724 __FUNCTION__, status);
1727 static void edge_bulk_in_callback (struct urb *urb, struct pt_regs *regs)
1729 struct edgeport_port *edge_port = (struct edgeport_port *)urb->context;
1730 unsigned char *data = urb->transfer_buffer;
1731 struct tty_struct *tty;
1736 dbg("%s", __FUNCTION__);
1739 dbg ("%s - nonzero read bulk status received: %d",
1740 __FUNCTION__, urb->status);
1742 if (urb->status == -EPIPE) {
1743 /* clear any problem that might have happened on this pipe */
1744 usb_clear_halt (edge_port->port->serial->dev, urb->pipe);
1750 port_number = edge_port->port->number - edge_port->port->serial->minor;
1752 if (edge_port->lsr_event) {
1753 edge_port->lsr_event = 0;
1754 dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
1755 __FUNCTION__, port_number, edge_port->lsr_mask, *data);
1756 handle_new_lsr (edge_port, 1, edge_port->lsr_mask, *data);
1757 /* Adjust buffer length/pointer */
1758 --urb->actual_length;
1762 tty = edge_port->port->tty;
1763 if (tty && urb->actual_length) {
1764 usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data);
1766 if (edge_port->close_pending) {
1767 dbg ("%s - close is pending, dropping data on the floor.", __FUNCTION__);
1769 for (i = 0; i < urb->actual_length ; ++i) {
1770 /* if we insert more than TTY_FLIPBUF_SIZE characters,
1772 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
1773 tty_flip_buffer_push(tty);
1775 /* this doesn't actually push the data through unless
1776 * tty->low_latency is set */
1777 tty_insert_flip_char(tty, data[i], 0);
1779 tty_flip_buffer_push(tty);
1781 edge_port->icount.rx += urb->actual_length;
1785 /* continue always trying to read */
1786 status = usb_submit_urb (urb, GFP_ATOMIC);
1788 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
1789 __FUNCTION__, status);
1792 static void edge_bulk_out_callback (struct urb *urb, struct pt_regs *regs)
1794 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1795 struct tty_struct *tty;
1797 dbg ("%s - port %d", __FUNCTION__, port->number);
1800 dbg ("%s - nonzero write bulk status received: %d",
1801 __FUNCTION__, urb->status);
1803 if (urb->status == -EPIPE) {
1804 /* clear any problem that might have happened on this pipe */
1805 usb_clear_halt (port->serial->dev, urb->pipe);
1812 /* let the tty driver wakeup if it has a special write_wakeup function */
1813 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) {
1814 (tty->ldisc.write_wakeup)(tty);
1817 /* tell the tty driver that something has changed */
1818 wake_up_interruptible(&tty->write_wait);
1822 static int edge_open (struct usb_serial_port *port, struct file * filp)
1824 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1825 struct edgeport_serial *edge_serial;
1826 struct usb_device *dev;
1831 u8 transaction_timeout;
1833 dbg("%s - port %d", __FUNCTION__, port->number);
1835 if (edge_port == NULL)
1838 /* force low_latency on so that our tty_push actually forces the data through,
1839 otherwise it is scheduled, and with high data rates (like with OHCI) data
1842 port->tty->low_latency = 1;
1844 port_number = port->number - port->serial->minor;
1845 switch (port_number) {
1847 edge_port->uart_base = UMPMEM_BASE_UART1;
1848 edge_port->dma_address = UMPD_OEDB1_ADDRESS;
1851 edge_port->uart_base = UMPMEM_BASE_UART2;
1852 edge_port->dma_address = UMPD_OEDB2_ADDRESS;
1855 dev_err (&port->dev, "Unknown port number!!!\n");
1859 dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
1860 __FUNCTION__, port_number, edge_port->uart_base, edge_port->dma_address);
1862 dev = port->serial->dev;
1864 memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount));
1865 init_waitqueue_head (&edge_port->delta_msr_wait);
1867 /* turn off loopback */
1868 status = TIClearLoopBack (edge_port);
1872 /* set up the port settings */
1873 edge_set_termios (port, NULL);
1875 /* open up the port */
1877 /* milliseconds to timeout for DMA transfer */
1878 transaction_timeout = 2;
1880 edge_port->ump_read_timeout = max (20, ((transaction_timeout * 3) / 2) );
1882 // milliseconds to timeout for DMA transfer
1883 open_settings = (u8)(UMP_DMA_MODE_CONTINOUS |
1884 UMP_PIPE_TRANS_TIMEOUT_ENA |
1885 (transaction_timeout << 2));
1887 dbg ("%s - Sending UMPC_OPEN_PORT", __FUNCTION__);
1889 /* Tell TI to open and start the port */
1890 status = TIWriteCommandSync (dev,
1892 (u8)(UMPM_UART1_PORT + port_number),
1899 /* Start the DMA? */
1900 status = TIWriteCommandSync (dev,
1902 (u8)(UMPM_UART1_PORT + port_number),
1909 /* Clear TX and RX buffers in UMP */
1910 status = TIPurgeDataSync (port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
1914 /* Read Initial MSR */
1915 status = TIReadVendorRequestSync (dev,
1916 UMPC_READ_MSR, // Request
1918 (__u16)(UMPM_UART1_PORT + port_number), // wIndex (Address)
1919 &edge_port->shadow_msr, // TransferBuffer
1920 1); // TransferBufferLength
1924 dbg ("ShadowMSR 0x%X", edge_port->shadow_msr);
1926 edge_serial = edge_port->edge_serial;
1927 if (edge_serial->num_ports_open == 0) {
1928 /* we are the first port to be opened, let's post the interrupt urb */
1929 urb = edge_serial->serial->port[0]->interrupt_in_urb;
1931 dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __FUNCTION__);
1934 urb->complete = edge_interrupt_callback;
1935 urb->context = edge_serial;
1937 status = usb_submit_urb (urb, GFP_KERNEL);
1939 dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__, status);
1945 * reset the data toggle on the bulk endpoints to work around bug in
1946 * host controllers where things get out of sync some times
1948 usb_clear_halt (dev, port->write_urb->pipe);
1949 usb_clear_halt (dev, port->read_urb->pipe);
1951 /* start up our bulk read urb */
1952 urb = port->read_urb;
1954 dev_err (&port->dev, "%s - no read urb present, exiting\n", __FUNCTION__);
1957 urb->complete = edge_bulk_in_callback;
1958 urb->context = edge_port;
1960 status = usb_submit_urb (urb, GFP_KERNEL);
1962 dev_err (&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __FUNCTION__, status);
1966 ++edge_serial->num_ports_open;
1968 dbg("%s - exited", __FUNCTION__);
1973 static void edge_close (struct usb_serial_port *port, struct file * filp)
1975 struct edgeport_serial *edge_serial;
1976 struct edgeport_port *edge_port;
1980 dbg("%s - port %d", __FUNCTION__, port->number);
1982 edge_serial = usb_get_serial_data(port->serial);
1983 edge_port = usb_get_serial_port_data(port);
1984 if ((edge_serial == NULL) || (edge_port == NULL))
1987 /* The bulkreadcompletion routine will check
1988 * this flag and dump add read data */
1989 edge_port->close_pending = 1;
1991 /* chase the port close */
1992 TIChasePort (edge_port);
1994 usb_unlink_urb (port->read_urb);
1996 /* assuming we can still talk to the device,
1997 * send a close port command to it */
1998 dbg("%s - send umpc_close_port", __FUNCTION__);
1999 port_number = port->number - port->serial->minor;
2000 status = TIWriteCommandSync (port->serial->dev,
2002 (__u8)(UMPM_UART1_PORT + port_number),
2006 --edge_port->edge_serial->num_ports_open;
2007 if (edge_port->edge_serial->num_ports_open <= 0) {
2008 /* last port is now closed, let's shut down our interrupt urb */
2009 usb_unlink_urb (port->serial->port[0]->interrupt_in_urb);
2010 edge_port->edge_serial->num_ports_open = 0;
2012 edge_port->close_pending = 0;
2014 dbg("%s - exited", __FUNCTION__);
2017 static int edge_write (struct usb_serial_port *port, int from_user, const unsigned char *data, int count)
2019 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
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, port->serial->dev,
2052 usb_sndbulkpipe (port->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, GFP_ATOMIC);
2061 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __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 = usb_get_serial_port_data(port);
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 = usb_get_serial_port_data(port);
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 = usb_get_serial_port_data(port);
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 = usb_get_serial_port_data(port);
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, GFP_ATOMIC);
2180 dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __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 dev_err (&edge_port->port->dev, "%s - out of memory\n", __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 = usb_get_serial_port_data(port);
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 edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear)
2380 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2383 dbg("%s - port %d", __FUNCTION__, port->number);
2385 mcr = edge_port->shadow_mcr;
2386 if (set & TIOCM_RTS)
2388 if (set & TIOCM_DTR)
2390 if (set & TIOCM_LOOP)
2391 mcr |= MCR_LOOPBACK;
2393 if (clear & TIOCM_RTS)
2395 if (clear & TIOCM_DTR)
2397 if (clear & TIOCM_LOOP)
2398 mcr &= ~MCR_LOOPBACK;
2400 edge_port->shadow_mcr = mcr;
2402 TIRestoreMCR (edge_port, mcr);
2407 static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
2409 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2410 unsigned int result = 0;
2414 dbg("%s - port %d", __FUNCTION__, port->number);
2416 msr = edge_port->shadow_msr;
2417 mcr = edge_port->shadow_mcr;
2418 result = ((mcr & MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */
2419 | ((mcr & MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */
2420 | ((msr & EDGEPORT_MSR_CTS) ? TIOCM_CTS: 0) /* 0x020 */
2421 | ((msr & EDGEPORT_MSR_CD) ? TIOCM_CAR: 0) /* 0x040 */
2422 | ((msr & EDGEPORT_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */
2423 | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
2426 dbg("%s -- %x", __FUNCTION__, result);
2431 static int get_serial_info (struct edgeport_port *edge_port, struct serial_struct * retinfo)
2433 struct serial_struct tmp;
2438 memset(&tmp, 0, sizeof(tmp));
2440 tmp.type = PORT_16550A;
2441 tmp.line = edge_port->port->serial->minor;
2442 tmp.port = edge_port->port->number;
2444 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2445 tmp.xmit_fifo_size = edge_port->port->bulk_out_size;
2446 tmp.baud_base = 9600;
2447 tmp.close_delay = 5*HZ;
2448 tmp.closing_wait = 30*HZ;
2449 // tmp.custom_divisor = state->custom_divisor;
2450 // tmp.hub6 = state->hub6;
2451 // tmp.io_type = state->io_type;
2454 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2459 static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg)
2461 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2462 struct async_icount cnow;
2463 struct async_icount cprev;
2465 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd);
2469 dbg("%s - (%d) TIOCINQ", __FUNCTION__, port->number);
2470 // return get_number_bytes_avail(edge_port, (unsigned int *) arg);
2474 dbg("%s - (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
2475 // return get_lsr_info(edge_port, (unsigned int *) arg);
2479 dbg("%s - (%d) TIOCGSERIAL", __FUNCTION__, port->number);
2480 return get_serial_info(edge_port, (struct serial_struct *) arg);
2484 dbg("%s - (%d) TIOCSSERIAL", __FUNCTION__, port->number);
2488 dbg("%s - (%d) TIOCMIWAIT", __FUNCTION__, port->number);
2489 cprev = edge_port->icount;
2491 interruptible_sleep_on(&edge_port->delta_msr_wait);
2492 /* see if a signal did it */
2493 if (signal_pending(current))
2494 return -ERESTARTSYS;
2495 cnow = edge_port->icount;
2496 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2497 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2498 return -EIO; /* no change => error */
2499 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2500 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2501 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2502 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2511 dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__,
2512 port->number, edge_port->icount.rx, edge_port->icount.tx);
2513 if (copy_to_user((void *)arg, &edge_port->icount, sizeof(edge_port->icount)))
2518 return -ENOIOCTLCMD;
2521 static void edge_break (struct usb_serial_port *port, int break_state)
2523 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2526 dbg ("%s - state = %d", __FUNCTION__, break_state);
2528 /* chase the port close */
2529 TIChasePort (edge_port);
2531 if (break_state == -1) {
2532 status = TISetBreak (edge_port);
2534 status = TIClearBreak (edge_port);
2537 dbg ("%s - error %d sending break set/clear command.",
2538 __FUNCTION__, status);
2542 static int edge_startup (struct usb_serial *serial)
2544 struct edgeport_serial *edge_serial;
2545 struct edgeport_port *edge_port;
2546 struct usb_device *dev;
2552 /* create our private serial structure */
2553 edge_serial = kmalloc (sizeof(struct edgeport_serial), GFP_KERNEL);
2554 if (edge_serial == NULL) {
2555 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2558 memset (edge_serial, 0, sizeof(struct edgeport_serial));
2559 edge_serial->serial = serial;
2560 usb_set_serial_data(serial, edge_serial);
2562 status = TIDownloadFirmware (edge_serial);
2564 kfree (edge_serial);
2568 /* set up our port private structures */
2569 for (i = 0; i < serial->num_ports; ++i) {
2570 edge_port = kmalloc (sizeof(struct edgeport_port), GFP_KERNEL);
2571 if (edge_port == NULL) {
2572 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2575 memset (edge_port, 0, sizeof(struct edgeport_port));
2576 edge_port->port = serial->port[i];
2577 edge_port->edge_serial = edge_serial;
2578 usb_set_serial_port_data(serial->port[i], edge_port);
2584 static void edge_shutdown (struct usb_serial *serial)
2588 dbg ("%s", __FUNCTION__);
2590 for (i=0; i < serial->num_ports; ++i) {
2591 kfree (usb_get_serial_port_data(serial->port[i]));
2592 usb_set_serial_port_data(serial->port[i], NULL);
2594 kfree (usb_get_serial_data(serial));
2595 usb_set_serial_data(serial, NULL);
2599 static struct usb_serial_device_type edgeport_1port_device = {
2600 .owner = THIS_MODULE,
2601 .name = "Edgeport TI 1 port adapter",
2602 .short_name = "edgeport_ti_1",
2603 .id_table = edgeport_1port_id_table,
2604 .num_interrupt_in = 1,
2609 .close = edge_close,
2610 .throttle = edge_throttle,
2611 .unthrottle = edge_unthrottle,
2612 .attach = edge_startup,
2613 .shutdown = edge_shutdown,
2614 .ioctl = edge_ioctl,
2615 .set_termios = edge_set_termios,
2616 .tiocmget = edge_tiocmget,
2617 .tiocmset = edge_tiocmset,
2618 .write = edge_write,
2619 .write_room = edge_write_room,
2620 .chars_in_buffer = edge_chars_in_buffer,
2621 .break_ctl = edge_break,
2624 static struct usb_serial_device_type edgeport_2port_device = {
2625 .owner = THIS_MODULE,
2626 .name = "Edgeport TI 2 port adapter",
2627 .short_name = "edgeport_ti_2",
2628 .id_table = edgeport_2port_id_table,
2629 .num_interrupt_in = 1,
2634 .close = edge_close,
2635 .throttle = edge_throttle,
2636 .unthrottle = edge_unthrottle,
2637 .attach = edge_startup,
2638 .shutdown = edge_shutdown,
2639 .ioctl = edge_ioctl,
2640 .set_termios = edge_set_termios,
2641 .tiocmget = edge_tiocmget,
2642 .tiocmset = edge_tiocmset,
2643 .write = edge_write,
2644 .write_room = edge_write_room,
2645 .chars_in_buffer = edge_chars_in_buffer,
2646 .break_ctl = edge_break,
2650 static int __init edgeport_init(void)
2653 retval = usb_serial_register(&edgeport_1port_device);
2655 goto failed_1port_device_register;
2656 retval = usb_serial_register(&edgeport_2port_device);
2658 goto failed_2port_device_register;
2659 retval = usb_register(&io_driver);
2661 goto failed_usb_register;
2662 info(DRIVER_DESC " " DRIVER_VERSION);
2664 failed_usb_register:
2665 usb_serial_deregister(&edgeport_2port_device);
2666 failed_2port_device_register:
2667 usb_serial_deregister(&edgeport_1port_device);
2668 failed_1port_device_register:
2672 static void __exit edgeport_exit (void)
2674 usb_deregister (&io_driver);
2675 usb_serial_deregister (&edgeport_1port_device);
2676 usb_serial_deregister (&edgeport_2port_device);
2679 module_init(edgeport_init);
2680 module_exit(edgeport_exit);
2682 /* Module information */
2683 MODULE_AUTHOR(DRIVER_AUTHOR);
2684 MODULE_DESCRIPTION(DRIVER_DESC);
2685 MODULE_LICENSE("GPL");
2687 MODULE_PARM(debug, "i");
2688 MODULE_PARM_DESC(debug, "Debug enabled or not");
2690 MODULE_PARM(ignore_cpu_rev, "i");
2691 MODULE_PARM_DESC(ignore_cpu_rev, "Ignore the cpu revision when connecting to a device");