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 int TIReadDownloadMemory (struct usb_device *dev, int start_address, int length,
283 __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 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 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 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->dev->config->interface[0]->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 if (serial_paranoia_check (edge_serial->serial, __FUNCTION__)) {
1656 switch (urb->status) {
1663 /* this urb is terminated, clean up */
1664 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
1667 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
1672 dbg ("%s - no data in urb", __FUNCTION__);
1676 usb_serial_debug_data (__FILE__, __FUNCTION__, length, data);
1679 dbg ("%s - expecting packet of size 2, got %d", __FUNCTION__, length);
1683 port_number = TIUMP_GET_PORT_FROM_CODE (data[0]);
1684 function = TIUMP_GET_FUNC_FROM_CODE (data[0]);
1685 dbg ("%s - port_number %d, function %d, info 0x%x",
1686 __FUNCTION__, port_number, function, data[1]);
1687 port = edge_serial->serial->port[port_number];
1688 if (port_paranoia_check (port, __FUNCTION__)) {
1689 dbg ("%s - change found for port that is not present",
1693 edge_port = usb_get_serial_port_data(port);
1695 dbg ("%s - edge_port not found", __FUNCTION__);
1699 case TIUMP_INTERRUPT_CODE_LSR:
1700 lsr = MapLineStatus(data[1]);
1701 if (lsr & UMP_UART_LSR_DATA_MASK) {
1702 /* Save the LSR event for bulk read completion routine */
1703 dbg ("%s - LSR Event Port %u LSR Status = %02x",
1704 __FUNCTION__, port_number, lsr);
1705 edge_port->lsr_event = 1;
1706 edge_port->lsr_mask = lsr;
1708 dbg ("%s - ===== Port %d LSR Status = %02x ======",
1709 __FUNCTION__, port_number, lsr);
1710 handle_new_lsr (edge_port, 0, lsr, 0);
1714 case TIUMP_INTERRUPT_CODE_MSR: // MSR
1715 /* Copy MSR from UMP */
1717 dbg ("%s - ===== Port %u MSR Status = %02x ======\n",
1718 __FUNCTION__, port_number, msr);
1719 handle_new_msr (edge_port, msr);
1723 dev_err (&urb->dev->dev, "%s - Unknown Interrupt code from UMP %x\n",
1724 __FUNCTION__, data[1]);
1730 status = usb_submit_urb (urb, GFP_ATOMIC);
1732 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
1733 __FUNCTION__, status);
1736 static void edge_bulk_in_callback (struct urb *urb, struct pt_regs *regs)
1738 struct edgeport_port *edge_port = (struct edgeport_port *)urb->context;
1739 unsigned char *data = urb->transfer_buffer;
1740 struct tty_struct *tty;
1745 dbg("%s", __FUNCTION__);
1747 if (port_paranoia_check (edge_port->port, __FUNCTION__))
1751 dbg ("%s - nonzero read bulk status received: %d",
1752 __FUNCTION__, urb->status);
1754 if (urb->status == -EPIPE) {
1755 /* clear any problem that might have happened on this pipe */
1756 usb_clear_halt (edge_port->port->serial->dev, urb->pipe);
1762 port_number = edge_port->port->number - edge_port->port->serial->minor;
1764 if (edge_port->lsr_event) {
1765 edge_port->lsr_event = 0;
1766 dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
1767 __FUNCTION__, port_number, edge_port->lsr_mask, *data);
1768 handle_new_lsr (edge_port, 1, edge_port->lsr_mask, *data);
1769 /* Adjust buffer length/pointer */
1770 --urb->actual_length;
1774 tty = edge_port->port->tty;
1775 if (tty && urb->actual_length) {
1776 usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data);
1778 if (edge_port->close_pending) {
1779 dbg ("%s - close is pending, dropping data on the floor.", __FUNCTION__);
1781 for (i = 0; i < urb->actual_length ; ++i) {
1782 /* if we insert more than TTY_FLIPBUF_SIZE characters,
1784 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
1785 tty_flip_buffer_push(tty);
1787 /* this doesn't actually push the data through unless
1788 * tty->low_latency is set */
1789 tty_insert_flip_char(tty, data[i], 0);
1791 tty_flip_buffer_push(tty);
1793 edge_port->icount.rx += urb->actual_length;
1797 /* continue always trying to read */
1798 status = usb_submit_urb (urb, GFP_ATOMIC);
1800 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
1801 __FUNCTION__, status);
1804 static void edge_bulk_out_callback (struct urb *urb, struct pt_regs *regs)
1806 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1807 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1808 struct tty_struct *tty;
1810 dbg ("%s - port %d", __FUNCTION__, port->number);
1813 dbg ("%s - bad serial pointer, exiting", __FUNCTION__);
1818 dbg ("%s - nonzero write bulk status received: %d",
1819 __FUNCTION__, urb->status);
1821 if (urb->status == -EPIPE) {
1822 /* clear any problem that might have happened on this pipe */
1823 usb_clear_halt (serial->dev, urb->pipe);
1830 /* let the tty driver wakeup if it has a special write_wakeup function */
1831 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) {
1832 (tty->ldisc.write_wakeup)(tty);
1835 /* tell the tty driver that something has changed */
1836 wake_up_interruptible(&tty->write_wait);
1840 static int edge_open (struct usb_serial_port *port, struct file * filp)
1842 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1843 struct edgeport_serial *edge_serial;
1844 struct usb_device *dev;
1849 u8 transaction_timeout;
1851 if (port_paranoia_check (port, __FUNCTION__))
1854 dbg("%s - port %d", __FUNCTION__, port->number);
1856 if (edge_port == NULL)
1859 /* force low_latency on so that our tty_push actually forces the data through,
1860 otherwise it is scheduled, and with high data rates (like with OHCI) data
1863 port->tty->low_latency = 1;
1865 port_number = port->number - port->serial->minor;
1866 switch (port_number) {
1868 edge_port->uart_base = UMPMEM_BASE_UART1;
1869 edge_port->dma_address = UMPD_OEDB1_ADDRESS;
1872 edge_port->uart_base = UMPMEM_BASE_UART2;
1873 edge_port->dma_address = UMPD_OEDB2_ADDRESS;
1876 dev_err (&port->dev, "Unknown port number!!!\n");
1880 dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
1881 __FUNCTION__, port_number, edge_port->uart_base, edge_port->dma_address);
1883 dev = port->serial->dev;
1885 memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount));
1886 init_waitqueue_head (&edge_port->delta_msr_wait);
1888 /* turn off loopback */
1889 status = TIClearLoopBack (edge_port);
1893 /* set up the port settings */
1894 edge_set_termios (port, NULL);
1896 /* open up the port */
1898 /* milliseconds to timeout for DMA transfer */
1899 transaction_timeout = 2;
1901 edge_port->ump_read_timeout = max (20, ((transaction_timeout * 3) / 2) );
1903 // milliseconds to timeout for DMA transfer
1904 open_settings = (u8)(UMP_DMA_MODE_CONTINOUS |
1905 UMP_PIPE_TRANS_TIMEOUT_ENA |
1906 (transaction_timeout << 2));
1908 dbg ("%s - Sending UMPC_OPEN_PORT", __FUNCTION__);
1910 /* Tell TI to open and start the port */
1911 status = TIWriteCommandSync (dev,
1913 (u8)(UMPM_UART1_PORT + port_number),
1920 /* Start the DMA? */
1921 status = TIWriteCommandSync (dev,
1923 (u8)(UMPM_UART1_PORT + port_number),
1930 /* Clear TX and RX buffers in UMP */
1931 status = TIPurgeDataSync (port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
1935 /* Read Initial MSR */
1936 status = TIReadVendorRequestSync (dev,
1937 UMPC_READ_MSR, // Request
1939 (__u16)(UMPM_UART1_PORT + port_number), // wIndex (Address)
1940 &edge_port->shadow_msr, // TransferBuffer
1941 1); // TransferBufferLength
1945 dbg ("ShadowMSR 0x%X", edge_port->shadow_msr);
1947 edge_serial = edge_port->edge_serial;
1948 if (edge_serial->num_ports_open == 0) {
1949 /* we are the first port to be opened, let's post the interrupt urb */
1950 urb = edge_serial->serial->port[0]->interrupt_in_urb;
1952 dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __FUNCTION__);
1955 urb->complete = edge_interrupt_callback;
1956 urb->context = edge_serial;
1958 status = usb_submit_urb (urb, GFP_KERNEL);
1960 dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__, status);
1966 * reset the data toggle on the bulk endpoints to work around bug in
1967 * host controllers where things get out of sync some times
1969 usb_clear_halt (dev, port->write_urb->pipe);
1970 usb_clear_halt (dev, port->read_urb->pipe);
1972 /* start up our bulk read urb */
1973 urb = port->read_urb;
1975 dev_err (&port->dev, "%s - no read urb present, exiting\n", __FUNCTION__);
1978 urb->complete = edge_bulk_in_callback;
1979 urb->context = edge_port;
1981 status = usb_submit_urb (urb, GFP_KERNEL);
1983 dev_err (&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __FUNCTION__, status);
1987 ++edge_serial->num_ports_open;
1989 dbg("%s - exited", __FUNCTION__);
1994 static void edge_close (struct usb_serial_port *port, struct file * filp)
1996 struct usb_serial *serial;
1997 struct edgeport_serial *edge_serial;
1998 struct edgeport_port *edge_port;
2002 if (port_paranoia_check (port, __FUNCTION__))
2005 dbg("%s - port %d", __FUNCTION__, port->number);
2007 serial = get_usb_serial (port, __FUNCTION__);
2011 edge_serial = usb_get_serial_data(serial);
2012 edge_port = usb_get_serial_port_data(port);
2013 if ((edge_serial == NULL) || (edge_port == NULL))
2017 /* The bulkreadcompletion routine will check
2018 * this flag and dump add read data */
2019 edge_port->close_pending = 1;
2021 /* chase the port close */
2022 TIChasePort (edge_port);
2024 usb_unlink_urb (port->read_urb);
2026 /* assuming we can still talk to the device,
2027 * send a close port command to it */
2028 dbg("%s - send umpc_close_port", __FUNCTION__);
2029 port_number = port->number - port->serial->minor;
2030 status = TIWriteCommandSync (port->serial->dev,
2032 (__u8)(UMPM_UART1_PORT + port_number),
2036 --edge_port->edge_serial->num_ports_open;
2037 if (edge_port->edge_serial->num_ports_open <= 0) {
2038 /* last port is now closed, let's shut down our interrupt urb */
2039 usb_unlink_urb (serial->port[0]->interrupt_in_urb);
2040 edge_port->edge_serial->num_ports_open = 0;
2042 edge_port->close_pending = 0;
2045 dbg("%s - exited", __FUNCTION__);
2048 static int edge_write (struct usb_serial_port *port, int from_user, const unsigned char *data, int count)
2050 struct usb_serial *serial = port->serial;
2051 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2054 dbg("%s - port %d", __FUNCTION__, port->number);
2057 dbg("%s - write request of 0 bytes", __FUNCTION__);
2061 if (edge_port == NULL)
2063 if (edge_port->close_pending == 1)
2066 if (port->write_urb->status == -EINPROGRESS) {
2067 dbg ("%s - already writing", __FUNCTION__);
2071 count = min (count, port->bulk_out_size);
2074 if (copy_from_user(port->write_urb->transfer_buffer, data, count))
2077 memcpy (port->write_urb->transfer_buffer, data, count);
2080 usb_serial_debug_data (__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer);
2082 /* set up our urb */
2083 usb_fill_bulk_urb (port->write_urb, serial->dev,
2084 usb_sndbulkpipe (serial->dev,
2085 port->bulk_out_endpointAddress),
2086 port->write_urb->transfer_buffer, count,
2087 edge_bulk_out_callback,
2090 /* send the data out the bulk port */
2091 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
2093 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result);
2098 edge_port->icount.tx += count;
2103 static int edge_write_room (struct usb_serial_port *port)
2105 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2108 dbg("%s", __FUNCTION__);
2110 if (edge_port == NULL)
2112 if (edge_port->close_pending == 1)
2115 dbg("%s - port %d", __FUNCTION__, port->number);
2117 if (port->write_urb->status != -EINPROGRESS)
2118 room = port->bulk_out_size;
2120 dbg("%s - returns %d", __FUNCTION__, room);
2124 static int edge_chars_in_buffer (struct usb_serial_port *port)
2126 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2129 dbg("%s", __FUNCTION__);
2131 if (edge_port == NULL)
2133 if (edge_port->close_pending == 1)
2136 dbg("%s - port %d", __FUNCTION__, port->number);
2138 if (port->write_urb->status == -EINPROGRESS)
2139 chars = port->write_urb->transfer_buffer_length;
2141 dbg ("%s - returns %d", __FUNCTION__, chars);
2145 static void edge_throttle (struct usb_serial_port *port)
2147 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2148 struct tty_struct *tty;
2151 dbg("%s - port %d", __FUNCTION__, port->number);
2153 if (edge_port == NULL)
2158 dbg ("%s - no tty available", __FUNCTION__);
2161 /* if we are implementing XON/XOFF, send the stop character */
2163 unsigned char stop_char = STOP_CHAR(tty);
2164 status = edge_write (port, 0, &stop_char, 1);
2170 /* if we are implementing RTS/CTS, toggle that line */
2171 if (tty->termios->c_cflag & CRTSCTS) {
2172 status = TIClearRts (edge_port);
2175 usb_unlink_urb (port->read_urb);
2178 static void edge_unthrottle (struct usb_serial_port *port)
2180 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2181 struct tty_struct *tty;
2184 dbg("%s - port %d", __FUNCTION__, port->number);
2186 if (edge_port == NULL)
2191 dbg ("%s - no tty available", __FUNCTION__);
2195 /* if we are implementing XON/XOFF, send the start character */
2197 unsigned char start_char = START_CHAR(tty);
2198 status = edge_write (port, 0, &start_char, 1);
2204 /* if we are implementing RTS/CTS, toggle that line */
2205 if (tty->termios->c_cflag & CRTSCTS) {
2206 status = TISetRts (edge_port);
2209 port->read_urb->dev = port->serial->dev;
2210 status = usb_submit_urb (port->read_urb, GFP_ATOMIC);
2212 dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__, status);
2217 static void change_port_settings (struct edgeport_port *edge_port, struct termios *old_termios)
2219 struct ump_uart_config *config;
2220 struct tty_struct *tty;
2225 int port_number = edge_port->port->number - edge_port->port->serial->minor;
2227 dbg("%s - port %d", __FUNCTION__, edge_port->port->number);
2229 tty = edge_port->port->tty;
2232 dbg("%s - no tty structures", __FUNCTION__);
2236 config = kmalloc (sizeof (*config), GFP_KERNEL);
2238 dev_err (&edge_port->port->dev, "%s - out of memory\n", __FUNCTION__);
2242 cflag = tty->termios->c_cflag;
2246 /* These flags must be set */
2247 config->wFlags |= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT;
2248 config->wFlags |= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR;
2249 config->bUartMode = 0;
2251 switch (cflag & CSIZE) {
2253 config->bDataBits = UMP_UART_CHAR5BITS;
2254 dbg ("%s - data bits = 5", __FUNCTION__);
2257 config->bDataBits = UMP_UART_CHAR6BITS;
2258 dbg ("%s - data bits = 6", __FUNCTION__);
2261 config->bDataBits = UMP_UART_CHAR7BITS;
2262 dbg ("%s - data bits = 7", __FUNCTION__);
2266 config->bDataBits = UMP_UART_CHAR8BITS;
2267 dbg ("%s - data bits = 8", __FUNCTION__);
2271 if (cflag & PARENB) {
2272 if (cflag & PARODD) {
2273 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2274 config->bParity = UMP_UART_ODDPARITY;
2275 dbg("%s - parity = odd", __FUNCTION__);
2277 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2278 config->bParity = UMP_UART_EVENPARITY;
2279 dbg("%s - parity = even", __FUNCTION__);
2282 config->bParity = UMP_UART_NOPARITY;
2283 dbg("%s - parity = none", __FUNCTION__);
2286 if (cflag & CSTOPB) {
2287 config->bStopBits = UMP_UART_STOPBIT2;
2288 dbg("%s - stop bits = 2", __FUNCTION__);
2290 config->bStopBits = UMP_UART_STOPBIT1;
2291 dbg("%s - stop bits = 1", __FUNCTION__);
2294 /* figure out the flow control settings */
2295 if (cflag & CRTSCTS) {
2296 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW;
2297 config->wFlags |= UMP_MASK_UART_FLAGS_RTS_FLOW;
2298 dbg("%s - RTS/CTS is enabled", __FUNCTION__);
2300 dbg("%s - RTS/CTS is disabled", __FUNCTION__);
2303 /* if we are implementing XON/XOFF, set the start and stop character in the device */
2304 if (I_IXOFF(tty) || I_IXON(tty)) {
2305 config->cXon = START_CHAR(tty);
2306 config->cXoff = STOP_CHAR(tty);
2308 /* if we are implementing INBOUND XON/XOFF */
2310 config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
2311 dbg ("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2312 __FUNCTION__, config->cXon, config->cXoff);
2314 dbg ("%s - INBOUND XON/XOFF is disabled", __FUNCTION__);
2317 /* if we are implementing OUTBOUND XON/XOFF */
2319 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
2320 dbg ("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2321 __FUNCTION__, config->cXon, config->cXoff);
2323 dbg ("%s - OUTBOUND XON/XOFF is disabled", __FUNCTION__);
2327 /* Round the baud rate */
2328 baud = tty_get_baud_rate(tty);
2330 /* pick a default, any default... */
2333 config->wBaudRate = (__u16)(461550L / baud);
2334 round = 4615500L / baud;
2335 if ((round - (config->wBaudRate * 10)) >= 5)
2336 config->wBaudRate++;
2338 dbg ("%s - baud rate = %d, wBaudRate = %d", __FUNCTION__, baud, config->wBaudRate);
2340 dbg ("wBaudRate: %d", (int)(461550L / config->wBaudRate));
2341 dbg ("wFlags: 0x%x", config->wFlags);
2342 dbg ("bDataBits: %d", config->bDataBits);
2343 dbg ("bParity: %d", config->bParity);
2344 dbg ("bStopBits: %d", config->bStopBits);
2345 dbg ("cXon: %d", config->cXon);
2346 dbg ("cXoff: %d", config->cXoff);
2347 dbg ("bUartMode: %d", config->bUartMode);
2349 /* move the word values into big endian mode */
2350 cpu_to_be16s (&config->wFlags);
2351 cpu_to_be16s (&config->wBaudRate);
2353 status = TIWriteCommandSync (edge_port->port->serial->dev,
2355 (__u8)(UMPM_UART1_PORT + port_number),
2360 dbg ("%s - error %d when trying to write config to device",
2361 __FUNCTION__, status);
2369 static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios)
2371 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2372 struct tty_struct *tty = port->tty;
2375 if (!port->tty || !port->tty->termios) {
2376 dbg ("%s - no tty or termios", __FUNCTION__);
2380 cflag = tty->termios->c_cflag;
2381 /* check that they really want us to change something */
2383 if ((cflag == old_termios->c_cflag) &&
2384 (RELEVANT_IFLAG(tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
2385 dbg ("%s - nothing to change", __FUNCTION__);
2390 dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
2391 tty->termios->c_cflag,
2392 RELEVANT_IFLAG(tty->termios->c_iflag));
2394 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
2395 old_termios->c_cflag,
2396 RELEVANT_IFLAG(old_termios->c_iflag));
2399 dbg("%s - port %d", __FUNCTION__, port->number);
2401 if (edge_port == NULL)
2404 /* change the port settings to the new ones specified */
2405 change_port_settings (edge_port, old_termios);
2410 static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear)
2412 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2415 dbg("%s - port %d", __FUNCTION__, port->number);
2417 mcr = edge_port->shadow_mcr;
2418 if (set & TIOCM_RTS)
2420 if (set & TIOCM_DTR)
2422 if (set & TIOCM_LOOP)
2423 mcr |= MCR_LOOPBACK;
2425 if (clear & TIOCM_RTS)
2427 if (clear & TIOCM_DTR)
2429 if (clear & TIOCM_LOOP)
2430 mcr &= ~MCR_LOOPBACK;
2432 edge_port->shadow_mcr = mcr;
2434 TIRestoreMCR (edge_port, mcr);
2439 static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
2441 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2442 unsigned int result = 0;
2446 dbg("%s - port %d", __FUNCTION__, port->number);
2448 msr = edge_port->shadow_msr;
2449 mcr = edge_port->shadow_mcr;
2450 result = ((mcr & MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */
2451 | ((mcr & MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */
2452 | ((msr & EDGEPORT_MSR_CTS) ? TIOCM_CTS: 0) /* 0x020 */
2453 | ((msr & EDGEPORT_MSR_CD) ? TIOCM_CAR: 0) /* 0x040 */
2454 | ((msr & EDGEPORT_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */
2455 | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
2458 dbg("%s -- %x", __FUNCTION__, result);
2463 static int get_serial_info (struct edgeport_port *edge_port, struct serial_struct * retinfo)
2465 struct serial_struct tmp;
2470 memset(&tmp, 0, sizeof(tmp));
2472 tmp.type = PORT_16550A;
2473 tmp.line = edge_port->port->serial->minor;
2474 tmp.port = edge_port->port->number;
2476 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2477 tmp.xmit_fifo_size = edge_port->port->bulk_out_size;
2478 tmp.baud_base = 9600;
2479 tmp.close_delay = 5*HZ;
2480 tmp.closing_wait = 30*HZ;
2481 // tmp.custom_divisor = state->custom_divisor;
2482 // tmp.hub6 = state->hub6;
2483 // tmp.io_type = state->io_type;
2486 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2491 static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg)
2493 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2494 struct async_icount cnow;
2495 struct async_icount cprev;
2497 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd);
2501 dbg("%s - (%d) TIOCINQ", __FUNCTION__, port->number);
2502 // return get_number_bytes_avail(edge_port, (unsigned int *) arg);
2506 dbg("%s - (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
2507 // return get_lsr_info(edge_port, (unsigned int *) arg);
2511 dbg("%s - (%d) TIOCGSERIAL", __FUNCTION__, port->number);
2512 return get_serial_info(edge_port, (struct serial_struct *) arg);
2516 dbg("%s - (%d) TIOCSSERIAL", __FUNCTION__, port->number);
2520 dbg("%s - (%d) TIOCMIWAIT", __FUNCTION__, port->number);
2521 cprev = edge_port->icount;
2523 interruptible_sleep_on(&edge_port->delta_msr_wait);
2524 /* see if a signal did it */
2525 if (signal_pending(current))
2526 return -ERESTARTSYS;
2527 cnow = edge_port->icount;
2528 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2529 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2530 return -EIO; /* no change => error */
2531 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2532 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2533 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2534 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2543 dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__,
2544 port->number, edge_port->icount.rx, edge_port->icount.tx);
2545 if (copy_to_user((void *)arg, &edge_port->icount, sizeof(edge_port->icount)))
2550 return -ENOIOCTLCMD;
2553 static void edge_break (struct usb_serial_port *port, int break_state)
2555 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2558 dbg ("%s - state = %d", __FUNCTION__, break_state);
2560 /* chase the port close */
2561 TIChasePort (edge_port);
2563 if (break_state == -1) {
2564 status = TISetBreak (edge_port);
2566 status = TIClearBreak (edge_port);
2569 dbg ("%s - error %d sending break set/clear command.",
2570 __FUNCTION__, status);
2574 static int edge_startup (struct usb_serial *serial)
2576 struct edgeport_serial *edge_serial;
2577 struct edgeport_port *edge_port;
2578 struct usb_device *dev;
2584 /* create our private serial structure */
2585 edge_serial = kmalloc (sizeof(struct edgeport_serial), GFP_KERNEL);
2586 if (edge_serial == NULL) {
2587 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2590 memset (edge_serial, 0, sizeof(struct edgeport_serial));
2591 edge_serial->serial = serial;
2592 usb_set_serial_data(serial, edge_serial);
2594 status = TIDownloadFirmware (edge_serial);
2596 kfree (edge_serial);
2600 /* set up our port private structures */
2601 for (i = 0; i < serial->num_ports; ++i) {
2602 edge_port = kmalloc (sizeof(struct edgeport_port), GFP_KERNEL);
2603 if (edge_port == NULL) {
2604 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2607 memset (edge_port, 0, sizeof(struct edgeport_port));
2608 edge_port->port = serial->port[i];
2609 edge_port->edge_serial = edge_serial;
2610 usb_set_serial_port_data(serial->port[i], edge_port);
2616 static void edge_shutdown (struct usb_serial *serial)
2620 dbg ("%s", __FUNCTION__);
2622 for (i=0; i < serial->num_ports; ++i) {
2623 kfree (usb_get_serial_port_data(serial->port[i]));
2624 usb_set_serial_port_data(serial->port[i], NULL);
2626 kfree (usb_get_serial_data(serial));
2627 usb_set_serial_data(serial, NULL);
2631 static struct usb_serial_device_type edgeport_1port_device = {
2632 .owner = THIS_MODULE,
2633 .name = "Edgeport TI 1 port adapter",
2634 .short_name = "edgeport_ti_1",
2635 .id_table = edgeport_1port_id_table,
2636 .num_interrupt_in = 1,
2641 .close = edge_close,
2642 .throttle = edge_throttle,
2643 .unthrottle = edge_unthrottle,
2644 .attach = edge_startup,
2645 .shutdown = edge_shutdown,
2646 .ioctl = edge_ioctl,
2647 .set_termios = edge_set_termios,
2648 .tiocmget = edge_tiocmget,
2649 .tiocmset = edge_tiocmset,
2650 .write = edge_write,
2651 .write_room = edge_write_room,
2652 .chars_in_buffer = edge_chars_in_buffer,
2653 .break_ctl = edge_break,
2656 static struct usb_serial_device_type edgeport_2port_device = {
2657 .owner = THIS_MODULE,
2658 .name = "Edgeport TI 2 port adapter",
2659 .short_name = "edgeport_ti_2",
2660 .id_table = edgeport_2port_id_table,
2661 .num_interrupt_in = 1,
2666 .close = edge_close,
2667 .throttle = edge_throttle,
2668 .unthrottle = edge_unthrottle,
2669 .attach = edge_startup,
2670 .shutdown = edge_shutdown,
2671 .ioctl = edge_ioctl,
2672 .set_termios = edge_set_termios,
2673 .tiocmget = edge_tiocmget,
2674 .tiocmset = edge_tiocmset,
2675 .write = edge_write,
2676 .write_room = edge_write_room,
2677 .chars_in_buffer = edge_chars_in_buffer,
2678 .break_ctl = edge_break,
2682 static int __init edgeport_init(void)
2685 retval = usb_serial_register(&edgeport_1port_device);
2687 goto failed_1port_device_register;
2688 retval = usb_serial_register(&edgeport_2port_device);
2690 goto failed_2port_device_register;
2691 retval = usb_register(&io_driver);
2693 goto failed_usb_register;
2694 info(DRIVER_DESC " " DRIVER_VERSION);
2696 failed_usb_register:
2697 usb_serial_deregister(&edgeport_2port_device);
2698 failed_2port_device_register:
2699 usb_serial_deregister(&edgeport_1port_device);
2700 failed_1port_device_register:
2704 static void __exit edgeport_exit (void)
2706 usb_deregister (&io_driver);
2707 usb_serial_deregister (&edgeport_1port_device);
2708 usb_serial_deregister (&edgeport_2port_device);
2711 module_init(edgeport_init);
2712 module_exit(edgeport_exit);
2714 /* Module information */
2715 MODULE_AUTHOR(DRIVER_AUTHOR);
2716 MODULE_DESCRIPTION(DRIVER_DESC);
2717 MODULE_LICENSE("GPL");
2719 MODULE_PARM(debug, "i");
2720 MODULE_PARM_DESC(debug, "Debug enabled or not");
2722 MODULE_PARM(ignore_cpu_rev, "i");
2723 MODULE_PARM_DESC(ignore_cpu_rev, "Ignore the cpu revision when connecting to a device");