2 * Edgeport USB Serial Converter driver
4 * Copyright (C) 2000-2002 Inside Out Networks, All rights reserved.
5 * Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Supports the following devices:
17 * July 11, 2002 Removed 4 port device structure since all TI UMP
18 * chips have only 2 ports
19 * David Iacovelli (davidi@ionetworks.com)
23 #include <linux/config.h>
24 #include <linux/kernel.h>
25 #include <linux/jiffies.h>
26 #include <linux/errno.h>
27 #include <linux/init.h>
28 #include <linux/slab.h>
29 #include <linux/tty.h>
30 #include <linux/tty_driver.h>
31 #include <linux/tty_flip.h>
32 #include <linux/module.h>
33 #include <linux/spinlock.h>
34 #include <linux/serial.h>
35 #include <linux/ioctl.h>
36 #include <asm/uaccess.h>
37 #include <linux/usb.h>
38 #include "usb-serial.h"
40 #include "io_usbvend.h"
48 #define DRIVER_VERSION "v0.2"
49 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
50 #define DRIVER_DESC "Edgeport USB Serial Driver"
53 /* firmware image code */
54 #define IMAGE_VERSION_NAME PagableOperationalCodeImageVersion
55 #define IMAGE_ARRAY_NAME PagableOperationalCodeImage
56 #define IMAGE_SIZE PagableOperationalCodeSize
57 #include "io_fw_down3.h" /* Define array OperationalCodeImage[] */
59 #define EPROM_PAGE_SIZE 64
62 struct edgeport_uart_buf_desc {
63 __u32 count; // Number of bytes currently in buffer
66 /* different hardware types */
67 #define HARDWARE_TYPE_930 0
68 #define HARDWARE_TYPE_TIUMP 1
70 // IOCTL_PRIVATE_TI_GET_MODE Definitions
71 #define TI_MODE_CONFIGURING 0 // Device has not entered start device
72 #define TI_MODE_BOOT 1 // Staying in boot mode
73 #define TI_MODE_DOWNLOAD 2 // Made it to download mode
74 #define TI_MODE_TRANSITIONING 3 // Currently in boot mode but transitioning to download mode
77 /* Product information read from the Edgeport */
80 int TiMode; // Current TI Mode
81 __u8 hardware_type; // Type of hardware
82 } __attribute__((packed));
85 struct edgeport_port {
92 __u32 ump_read_timeout; /* Number of miliseconds the UMP will
93 wait without data before completing
98 struct edgeport_uart_buf_desc tx;
99 struct async_icount icount;
100 wait_queue_head_t delta_msr_wait; /* for handling sleeping while
101 waiting for msr change to
103 struct edgeport_serial *edge_serial;
104 struct usb_serial_port *port;
107 struct edgeport_serial {
108 struct product_info product_info;
109 u8 TI_I2C_Type; // Type of I2C in UMP
110 u8 TiReadI2C; // Set to TRUE if we have read the I2c in Boot Mode
112 struct usb_serial *serial;
116 /* Devices that this driver supports */
117 static struct usb_device_id edgeport_1port_id_table [] = {
118 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
122 static struct usb_device_id edgeport_2port_id_table [] = {
123 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
124 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
125 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
126 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
127 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421_BOOT) },
128 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421_DOWN) },
129 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
130 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21_BOOT) },
131 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21_DOWN) },
132 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
133 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
134 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
135 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22) },
139 /* Devices that this driver supports */
140 static struct usb_device_id id_table_combined [] = {
141 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
142 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
143 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
144 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
145 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421) },
146 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421_BOOT) },
147 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_421_DOWN) },
148 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21) },
149 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21_BOOT) },
150 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_21_DOWN) },
151 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_42) },
152 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4) },
153 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_4I) },
154 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_22) },
158 MODULE_DEVICE_TABLE (usb, id_table_combined);
160 static struct usb_driver io_driver = {
161 .owner = THIS_MODULE,
163 .probe = usb_serial_probe,
164 .disconnect = usb_serial_disconnect,
165 .id_table = id_table_combined,
169 static struct EDGE_FIRMWARE_VERSION_INFO OperationalCodeImageVersion;
171 static int TIStayInBootMode = 0;
172 static int ignore_cpu_rev = 0;
176 static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios);
178 static int TIReadVendorRequestSync (struct usb_device *dev,
187 status = usb_control_msg (dev,
188 usb_rcvctrlpipe(dev, 0),
200 if (status != size) {
201 dbg ("%s - wanted to write %d, but only wrote %d",
202 __FUNCTION__, size, status);
208 static int TISendVendorRequestSync (struct usb_device *dev,
217 status = usb_control_msg (dev,
218 usb_sndctrlpipe(dev, 0),
231 if (status != size) {
232 dbg ("%s - wanted to write %d, but only wrote %d",
233 __FUNCTION__, size, status);
239 static int TIWriteCommandSync (struct usb_device *dev, __u8 command,
240 __u8 moduleid, __u16 value, u8 *data,
243 return TISendVendorRequestSync (dev,
247 data, // TransferBuffer
248 size); // TransferBufferLength
253 /* clear tx/rx buffers and fifo in TI UMP */
254 static int TIPurgeDataSync (struct usb_serial_port *port, __u16 mask)
256 int port_number = port->number - port->serial->minor;
258 dbg ("%s - port %d, mask %x", __FUNCTION__, port_number, mask);
260 return TIWriteCommandSync (port->serial->dev,
262 (__u8)(UMPM_UART1_PORT + port_number),
269 * TIReadDownloadMemory - Read edgeport memory from TI chip
270 * @dev: usb device pointer
271 * @start_address: Device CPU address at which to read
272 * @length: Length of above data
273 * @address_type: Can read both XDATA and I2C
274 * @buffer: pointer to input data buffer
276 static int TIReadDownloadMemory(struct usb_device *dev, int start_address,
277 int length, __u8 address_type, __u8 *buffer)
281 __u16 be_start_address;
283 dbg ("%s - @ %x for %d", __FUNCTION__, start_address, length);
285 /* Read in blocks of 64 bytes
286 * (TI firmware can't handle more than 64 byte reads)
292 read_length = (__u8)length;
294 if (read_length > 1) {
295 dbg ("%s - @ %x for %d", __FUNCTION__,
296 start_address, read_length);
298 be_start_address = cpu_to_be16 (start_address);
299 status = TIReadVendorRequestSync (dev,
300 UMPC_MEMORY_READ, // Request
301 (__u16)address_type, // wValue (Address type)
302 be_start_address, // wIndex (Address to read)
303 buffer, // TransferBuffer
304 read_length); // TransferBufferLength
307 dbg ("%s - ERROR %x", __FUNCTION__, status);
311 if (read_length > 1) {
312 usb_serial_debug_data(debug, &dev->dev, __FUNCTION__,
313 read_length, buffer);
316 /* Update pointers/length */
317 start_address += read_length;
318 buffer += read_length;
319 length -= read_length;
325 static int TIReadRam (struct usb_device *dev, int start_address, int length, __u8 *buffer)
327 return TIReadDownloadMemory (dev,
330 DTK_ADDR_SPACE_XDATA,
334 /* Read edgeport memory to a given block */
335 static int TIReadBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 * buffer)
340 for (i=0; i< length; i++) {
341 status = TIReadVendorRequestSync (serial->serial->dev,
342 UMPC_MEMORY_READ, // Request
343 serial->TI_I2C_Type, // wValue (Address type)
344 (__u16)(start_address+i), // wIndex
345 &buffer[i], // TransferBuffer
346 0x01); // TransferBufferLength
348 dbg ("%s - ERROR %x", __FUNCTION__, status);
353 dbg ("%s - start_address = %x, length = %d", __FUNCTION__, start_address, length);
354 usb_serial_debug_data(debug, &serial->serial->dev->dev, __FUNCTION__, length, buffer);
356 serial->TiReadI2C = 1;
361 /* Write given block to TI EPROM memory */
362 static int TIWriteBootMemory (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer)
368 /* Must do a read before write */
369 if (!serial->TiReadI2C) {
370 status = TIReadBootMemory(serial, 0, 1, &temp);
375 for (i=0; i < length; ++i) {
376 status = TISendVendorRequestSync (serial->serial->dev,
377 UMPC_MEMORY_WRITE, // Request
379 (__u16)(i+start_address), // wIndex
380 NULL, // TransferBuffer
381 0); // TransferBufferLength
386 dbg ("%s - start_sddr = %x, length = %d", __FUNCTION__, start_address, length);
387 usb_serial_debug_data(debug, &serial->serial->dev->dev, __FUNCTION__, length, buffer);
393 /* Write edgeport I2C memory to TI chip */
394 static int TIWriteDownloadI2C (struct edgeport_serial *serial, int start_address, int length, __u8 address_type, __u8 *buffer)
398 __u16 be_start_address;
400 /* We can only send a maximum of 1 aligned byte page at a time */
402 /* calulate the number of bytes left in the first page */
403 write_length = EPROM_PAGE_SIZE - (start_address & (EPROM_PAGE_SIZE - 1));
405 if (write_length > length)
406 write_length = length;
408 dbg ("%s - BytesInFirstPage Addr = %x, length = %d", __FUNCTION__, start_address, write_length);
409 usb_serial_debug_data(debug, &serial->serial->dev->dev, __FUNCTION__, write_length, buffer);
411 /* Write first page */
412 be_start_address = cpu_to_be16 (start_address);
413 status = TISendVendorRequestSync (serial->serial->dev,
414 UMPC_MEMORY_WRITE, // Request
415 (__u16)address_type, // wValue
416 be_start_address, // wIndex
417 buffer, // TransferBuffer
420 dbg ("%s - ERROR %d", __FUNCTION__, status);
424 length -= write_length;
425 start_address += write_length;
426 buffer += write_length;
428 /* We should be aligned now -- can write max page size bytes at a time */
430 if (length > EPROM_PAGE_SIZE)
431 write_length = EPROM_PAGE_SIZE;
433 write_length = length;
435 dbg ("%s - Page Write Addr = %x, length = %d", __FUNCTION__, start_address, write_length);
436 usb_serial_debug_data(debug, &serial->serial->dev->dev, __FUNCTION__, write_length, buffer);
438 /* Write next page */
439 be_start_address = cpu_to_be16 (start_address);
440 status = TISendVendorRequestSync (serial->serial->dev,
441 UMPC_MEMORY_WRITE, // Request
442 (__u16)address_type, // wValue
443 be_start_address, // wIndex
444 buffer, // TransferBuffer
445 write_length); // TransferBufferLength
447 dbg ("%s - ERROR %d", __FUNCTION__, status);
451 length -= write_length;
452 start_address += write_length;
453 buffer += write_length;
458 /* Examine the UMP DMA registers and LSR
460 * Check the MSBit of the X and Y DMA byte count registers.
461 * A zero in this bit indicates that the TX DMA buffers are empty
462 * then check the TX Empty bit in the UART.
464 static int TIIsTxActive (struct edgeport_port *port)
467 struct out_endpoint_desc_block *oedb;
471 oedb = kmalloc (sizeof (* oedb), GFP_KERNEL);
473 dev_err (&port->port->dev, "%s - out of memory\n", __FUNCTION__);
477 lsr = kmalloc (1, GFP_KERNEL); /* Sigh, that's right, just one byte,
478 as not all platforms can do DMA
484 /* Read the DMA Count Registers */
485 status = TIReadRam (port->port->serial->dev,
491 goto exit_is_tx_active;
493 dbg ("%s - XByteCount 0x%X", __FUNCTION__, oedb->XByteCount);
496 status = TIReadRam (port->port->serial->dev,
497 port->uart_base + UMPMEM_OFFS_UART_LSR,
502 goto exit_is_tx_active;
503 dbg ("%s - LSR = 0x%X", __FUNCTION__, *lsr);
505 /* If either buffer has data or we are transmitting then return TRUE */
506 if ((oedb->XByteCount & 0x80 ) != 0 )
509 if ((*lsr & UMP_UART_LSR_TX_MASK ) == 0 )
512 /* We return Not Active if we get any kind of error */
514 dbg ("%s - return %d", __FUNCTION__, bytes_left );
521 static void TIChasePort(struct edgeport_port *port)
528 // Base the LoopTime on the baud rate
529 if (port->baud_rate == 0)
530 port->baud_rate = 1200;
532 write_size = port->tx.count;
533 loops = max(100, (100*write_size)/(port->baud_rate/10));
534 dbg ("%s - write_size %d, baud %d loop = %d", __FUNCTION__,
535 write_size, port->baud_rate, loops);
539 last_count = port->tx.count;
541 dbg ("%s - Tx Buffer Size = %d loops = %d", __FUNCTION__,
544 /* Is the Edgeport Buffer empty? */
545 if (port->tx.count == 0)
548 /* Block the thread for 10ms */
551 if (last_count == port->tx.count) {
552 /* No activity.. count down. */
555 dbg ("%s - Wait for TxEmpty - TIMEOUT",
560 /* Reset timeout value back to a minimum of 1 second */
561 dbg ("%s - Wait for TxEmpty Reset Count", __FUNCTION__);
562 goto restart_tx_loop;
566 dbg ("%s - Local Tx Buffer Empty -- Waiting for TI UMP to EMPTY X/Y and FIFO",
569 write_size = TIIsTxActive (port);
570 loops = max(50, (100*write_size)/(port->baud_rate/10));
571 dbg ("%s - write_size %d, baud %d loop = %d", __FUNCTION__,
572 write_size, port->baud_rate, loops);
575 /* This function takes 4 ms; */
576 if (!TIIsTxActive (port)) {
577 /* Delay a few char times */
579 dbg ("%s - Empty", __FUNCTION__);
585 dbg ("%s - TIMEOUT", __FUNCTION__);
591 static int TIChooseConfiguration (struct usb_device *dev)
593 // There may be multiple configurations on this device, in which case
594 // we would need to read and parse all of them to find out which one
595 // we want. However, we just support one config at this point,
596 // configuration # 1, which is Config Descriptor 0.
598 dbg ("%s - Number of Interfaces = %d", __FUNCTION__, dev->config->desc.bNumInterfaces);
599 dbg ("%s - MAX Power = %d", __FUNCTION__, dev->config->desc.bMaxPower*2);
601 if (dev->config->desc.bNumInterfaces != 1) {
602 dev_err (&dev->dev, "%s - bNumInterfaces is not 1, ERROR!\n", __FUNCTION__);
609 static int TIReadRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer)
613 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
614 status = TIReadDownloadMemory (serial->serial->dev,
620 status = TIReadBootMemory (serial,
629 static int TIWriteRom (struct edgeport_serial *serial, int start_address, int length, __u8 *buffer)
631 if (serial->product_info.TiMode == TI_MODE_BOOT)
632 return TIWriteBootMemory (serial,
637 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD)
638 return TIWriteDownloadI2C (serial,
649 /* Read a descriptor header from I2C based on type */
650 static int TIGetDescriptorAddress (struct edgeport_serial *serial, int desc_type, struct ti_i2c_desc *rom_desc)
655 /* Search for requested descriptor in I2C */
658 status = TIReadRom (serial,
660 sizeof(struct ti_i2c_desc),
665 if (rom_desc->Type == desc_type)
666 return start_address;
668 start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size;
670 } while ((start_address < TI_MAX_I2C_SIZE) && rom_desc->Type);
675 /* Validate descriptor checksum */
676 static int ValidChecksum(struct ti_i2c_desc *rom_desc, __u8 *buffer)
681 for (i=0; i < rom_desc->Size; i++) {
682 cs = (__u8)(cs + buffer[i]);
684 if (cs != rom_desc->CheckSum) {
685 dbg ("%s - Mismatch %x - %x", __FUNCTION__, rom_desc->CheckSum, cs);
691 /* Make sure that the I2C image is good */
692 static int TiValidateI2cImage (struct edgeport_serial *serial)
694 struct device *dev = &serial->serial->dev->dev;
696 struct ti_i2c_desc *rom_desc;
697 int start_address = 2;
700 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
702 dev_err (dev, "%s - out of memory\n", __FUNCTION__);
705 buffer = kmalloc (TI_MAX_I2C_SIZE, GFP_KERNEL);
707 dev_err (dev, "%s - out of memory when allocating buffer\n", __FUNCTION__);
712 // Read the first byte (Signature0) must be 0x52
713 status = TIReadRom (serial, 0, 1, buffer);
715 goto ExitTiValidateI2cImage;
717 if (*buffer != 0x52) {
718 dev_err (dev, "%s - invalid buffer signature\n", __FUNCTION__);
720 goto ExitTiValidateI2cImage;
725 status = TIReadRom (serial,
727 sizeof(struct ti_i2c_desc),
732 if ((start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size) > TI_MAX_I2C_SIZE) {
734 dbg ("%s - structure too big, erroring out.", __FUNCTION__);
738 dbg ("%s Type = 0x%x", __FUNCTION__, rom_desc->Type);
740 // Skip type 2 record
741 if ((rom_desc->Type & 0x0f) != I2C_DESC_TYPE_FIRMWARE_BASIC) {
742 // Read the descriptor data
743 status = TIReadRom(serial,
744 start_address+sizeof(struct ti_i2c_desc),
750 status = ValidChecksum(rom_desc, buffer);
754 start_address = start_address + sizeof(struct ti_i2c_desc) + rom_desc->Size;
756 } while ((rom_desc->Type != I2C_DESC_TYPE_ION) && (start_address < TI_MAX_I2C_SIZE));
758 if ((rom_desc->Type != I2C_DESC_TYPE_ION) || (start_address > TI_MAX_I2C_SIZE))
761 ExitTiValidateI2cImage:
767 static int TIReadManufDescriptor (struct edgeport_serial *serial, __u8 *buffer)
771 struct ti_i2c_desc *rom_desc;
772 struct edge_ti_manuf_descriptor *desc;
774 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
776 dev_err (&serial->serial->dev->dev, "%s - out of memory\n", __FUNCTION__);
779 start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_ION, rom_desc);
781 if (!start_address) {
782 dbg ("%s - Edge Descriptor not found in I2C", __FUNCTION__);
787 // Read the descriptor data
788 status = TIReadRom (serial,
789 start_address+sizeof(struct ti_i2c_desc),
795 status = ValidChecksum(rom_desc, buffer);
797 desc = (struct edge_ti_manuf_descriptor *)buffer;
798 dbg ( "%s - IonConfig 0x%x", __FUNCTION__, desc->IonConfig );
799 dbg ( "%s - Version %d", __FUNCTION__, desc->Version );
800 dbg ( "%s - Cpu/Board 0x%x", __FUNCTION__, desc->CpuRev_BoardRev );
801 dbg ( "%s - NumPorts %d", __FUNCTION__, desc->NumPorts );
802 dbg ( "%s - NumVirtualPorts %d", __FUNCTION__, desc->NumVirtualPorts );
803 dbg ( "%s - TotalPorts %d", __FUNCTION__, desc->TotalPorts );
810 /* Build firmware header used for firmware update */
811 static int BuildI2CFirmwareHeader (__u8 *header, struct device *dev)
817 struct ti_i2c_desc *i2c_header;
818 struct ti_i2c_image_header *img_header;
819 struct ti_i2c_firmware_rec *firmware_rec;
821 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
822 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
823 // will download the latest firmware (padded to 15.5k) into the UMP ram.
824 // And finally when the device comes back up in download mode the driver will cause
825 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
826 // the record type from 0xf2 to 0x02.
828 // Allocate a 15.5k buffer + 2 bytes for version number (Firmware Record)
829 buffer_size = (((1024 * 16) - 512 )+ sizeof(struct ti_i2c_firmware_rec));
831 buffer = kmalloc (buffer_size, GFP_KERNEL);
833 dev_err (dev, "%s - out of memory\n", __FUNCTION__);
837 // Set entire image of 0xffs
838 memset (buffer, 0xff, buffer_size);
840 // Copy version number into firmware record
841 firmware_rec = (struct ti_i2c_firmware_rec *)buffer;
843 firmware_rec->Ver_Major = OperationalCodeImageVersion.MajorVersion;
844 firmware_rec->Ver_Minor = OperationalCodeImageVersion.MinorVersion;
846 // Pointer to fw_down memory image
847 img_header = (struct ti_i2c_image_header *)&PagableOperationalCodeImage[0];
849 memcpy (buffer + sizeof(struct ti_i2c_firmware_rec),
850 &PagableOperationalCodeImage[sizeof(struct ti_i2c_image_header)],
853 for (i=0; i < buffer_size; i++) {
854 cs = (__u8)(cs + buffer[i]);
860 i2c_header = (struct ti_i2c_desc *)header;
861 firmware_rec = (struct ti_i2c_firmware_rec*)i2c_header->Data;
863 i2c_header->Type = I2C_DESC_TYPE_FIRMWARE_BLANK;
864 i2c_header->Size = (__u16)buffer_size;
865 i2c_header->CheckSum = cs;
866 firmware_rec->Ver_Major = OperationalCodeImageVersion.MajorVersion;
867 firmware_rec->Ver_Minor = OperationalCodeImageVersion.MinorVersion;
872 /* Try to figure out what type of I2c we have */
873 static int TIGetI2cTypeInBootMode (struct edgeport_serial *serial)
878 // Try to read type 2
879 status = TIReadVendorRequestSync (serial->serial->dev,
880 UMPC_MEMORY_READ, // Request
881 DTK_ADDR_SPACE_I2C_TYPE_II, // wValue (Address type)
883 &data, // TransferBuffer
884 0x01); // TransferBufferLength
886 dbg ("%s - read 2 status error = %d", __FUNCTION__, status);
888 dbg ("%s - read 2 data = 0x%x", __FUNCTION__, data);
889 if ((!status) && data == 0x52) {
890 dbg ("%s - ROM_TYPE_II", __FUNCTION__);
891 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
895 // Try to read type 3
896 status = TIReadVendorRequestSync (serial->serial->dev,
897 UMPC_MEMORY_READ, // Request
898 DTK_ADDR_SPACE_I2C_TYPE_III, // wValue (Address type)
900 &data, // TransferBuffer
901 0x01); // TransferBufferLength
903 dbg ("%s - read 3 status error = %d", __FUNCTION__, status);
905 dbg ("%s - read 2 data = 0x%x", __FUNCTION__, data);
906 if ((!status) && data == 0x52) {
907 dbg ("%s - ROM_TYPE_III", __FUNCTION__);
908 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
912 dbg ("%s - Unknown", __FUNCTION__);
913 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
917 static int TISendBulkTransferSync (struct usb_serial *serial, void *buffer, int length, int *num_sent)
921 status = usb_bulk_msg (serial->dev,
922 usb_sndbulkpipe(serial->dev,
923 serial->port[0]->bulk_out_endpointAddress),
931 /* Download given firmware image to the device (IN BOOT MODE) */
932 static int TIDownloadCodeImage (struct edgeport_serial *serial, __u8 *image, int image_length)
939 // Transfer firmware image
940 for (pos = 0; pos < image_length; ) {
941 // Read the next buffer from file
942 transfer = image_length - pos;
943 if (transfer > EDGE_FW_BULK_MAX_PACKET_SIZE)
944 transfer = EDGE_FW_BULK_MAX_PACKET_SIZE;
947 status = TISendBulkTransferSync (serial->serial, &image[pos], transfer, &done);
950 // Advance buffer pointer
958 static int TIConfigureBootDevice (struct usb_device *dev)
964 * DownloadTIFirmware - Download run-time operating firmware to the TI5052
966 * This routine downloads the main operating code into the TI5052, using the
967 * boot code already burned into E2PROM or ROM.
969 static int TIDownloadFirmware (struct edgeport_serial *serial)
971 struct device *dev = &serial->serial->dev->dev;
974 struct edge_ti_manuf_descriptor *ti_manuf_desc;
975 struct usb_interface_descriptor *interface;
976 int download_cur_ver;
977 int download_new_ver;
979 /* This routine is entered by both the BOOT mode and the Download mode
980 * We can determine which code is running by the reading the config
981 * descriptor and if we have only one bulk pipe it is in boot mode
983 serial->product_info.hardware_type = HARDWARE_TYPE_TIUMP;
985 /* Default to type 2 i2c */
986 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
988 status = TIChooseConfiguration (serial->serial->dev);
992 interface = &serial->serial->interface->cur_altsetting->desc;
994 dev_err (&serial->serial->dev->dev, "%s - no interface set, error!", __FUNCTION__);
998 // Setup initial mode -- the default mode 0 is TI_MODE_CONFIGURING
999 // if we have more than one endpoint we are definitely in download mode
1000 if (interface->bNumEndpoints > 1)
1001 serial->product_info.TiMode = TI_MODE_DOWNLOAD;
1003 // Otherwise we will remain in configuring mode
1004 serial->product_info.TiMode = TI_MODE_CONFIGURING;
1006 // Save Download Version Number
1007 OperationalCodeImageVersion.MajorVersion = PagableOperationalCodeImageVersion.MajorVersion;
1008 OperationalCodeImageVersion.MinorVersion = PagableOperationalCodeImageVersion.MinorVersion;
1009 OperationalCodeImageVersion.BuildNumber = PagableOperationalCodeImageVersion.BuildNumber;
1011 /********************************************************************/
1013 /********************************************************************/
1014 if (serial->product_info.TiMode == TI_MODE_DOWNLOAD) {
1015 struct ti_i2c_desc *rom_desc;
1017 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN DOWNLOAD MODE>>>>>>>>>>", __FUNCTION__);
1019 status = TiValidateI2cImage (serial);
1021 dbg ("%s - <<<<<<<<<<<<<<<DOWNLOAD MODE -- BAD I2C >>>>>>>>>>",
1026 /* Validate Hardware version number
1027 * Read Manufacturing Descriptor from TI Based Edgeport
1029 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL);
1030 if (!ti_manuf_desc) {
1031 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1034 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc);
1036 kfree (ti_manuf_desc);
1040 // Check version number of ION descriptor
1041 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) {
1042 dbg ( "%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__,
1043 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev));
1044 kfree (ti_manuf_desc);
1048 rom_desc = kmalloc (sizeof (*rom_desc), GFP_KERNEL);
1050 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1051 kfree (ti_manuf_desc);
1055 // Search for type 2 record (firmware record)
1056 if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc)) != 0) {
1057 struct ti_i2c_firmware_rec *firmware_version;
1060 dbg ("%s - Found Type FIRMWARE (Type 2) record", __FUNCTION__);
1062 firmware_version = kmalloc (sizeof (*firmware_version), GFP_KERNEL);
1063 if (!firmware_version) {
1064 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1066 kfree (ti_manuf_desc);
1070 // Validate version number
1071 // Read the descriptor data
1072 status = TIReadRom (serial,
1073 start_address+sizeof(struct ti_i2c_desc),
1074 sizeof(struct ti_i2c_firmware_rec),
1075 (__u8 *)firmware_version);
1077 kfree (firmware_version);
1079 kfree (ti_manuf_desc);
1083 // Check version number of download with current version in I2c
1084 download_cur_ver = (firmware_version->Ver_Major << 8) +
1085 (firmware_version->Ver_Minor);
1086 download_new_ver = (OperationalCodeImageVersion.MajorVersion << 8) +
1087 (OperationalCodeImageVersion.MinorVersion);
1089 dbg ("%s - >>>Firmware Versions Device %d.%d Driver %d.%d",
1091 firmware_version->Ver_Major,
1092 firmware_version->Ver_Minor,
1093 OperationalCodeImageVersion.MajorVersion,
1094 OperationalCodeImageVersion.MinorVersion);
1096 // Check if we have an old version in the I2C and update if necessary
1097 if (download_cur_ver != download_new_ver) {
1098 dbg ("%s - Update I2C Download from %d.%d to %d.%d",
1100 firmware_version->Ver_Major,
1101 firmware_version->Ver_Minor,
1102 OperationalCodeImageVersion.MajorVersion,
1103 OperationalCodeImageVersion.MinorVersion);
1105 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1106 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1107 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1108 // And finally when the device comes back up in download mode the driver will cause
1109 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1110 // the record type from 0xf2 to 0x02.
1112 record = I2C_DESC_TYPE_FIRMWARE_BLANK;
1114 // Change the I2C Firmware record type to 0xf2 to trigger an update
1115 status = TIWriteRom (serial,
1120 kfree (firmware_version);
1122 kfree (ti_manuf_desc);
1126 // verify the write -- must do this in order for write to
1127 // complete before we do the hardware reset
1128 status = TIReadRom (serial,
1134 kfree (firmware_version);
1136 kfree (ti_manuf_desc);
1140 if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
1141 dev_err (dev, "%s - error resetting device\n", __FUNCTION__);
1142 kfree (firmware_version);
1144 kfree (ti_manuf_desc);
1148 dbg ("%s - HARDWARE RESET", __FUNCTION__);
1150 // Reset UMP -- Back to BOOT MODE
1151 status = TISendVendorRequestSync (serial->serial->dev,
1152 UMPC_HARDWARE_RESET, // Request
1155 NULL, // TransferBuffer
1156 0); // TransferBufferLength
1158 dbg ( "%s - HARDWARE RESET return %d", __FUNCTION__, status);
1160 /* return an error on purpose. */
1161 kfree (firmware_version);
1163 kfree (ti_manuf_desc);
1166 kfree (firmware_version);
1168 // Search for type 0xF2 record (firmware blank record)
1169 else if ((start_address = TIGetDescriptorAddress (serial, I2C_DESC_TYPE_FIRMWARE_BLANK, rom_desc)) != 0) {
1170 #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + sizeof(struct ti_i2c_firmware_rec))
1174 header = kmalloc (HEADER_SIZE, GFP_KERNEL);
1176 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1178 kfree (ti_manuf_desc);
1182 vheader = kmalloc (HEADER_SIZE, GFP_KERNEL);
1184 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1187 kfree (ti_manuf_desc);
1191 dbg ("%s - Found Type BLANK FIRMWARE (Type F2) record", __FUNCTION__);
1193 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1194 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1195 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1196 // And finally when the device comes back up in download mode the driver will cause
1197 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1198 // the record type from 0xf2 to 0x02.
1199 status = BuildI2CFirmwareHeader(header, dev);
1204 kfree (ti_manuf_desc);
1208 // Update I2C with type 0xf2 record with correct size and checksum
1209 status = TIWriteRom (serial,
1217 kfree (ti_manuf_desc);
1221 // verify the write -- must do this in order for write to
1222 // complete before we do the hardware reset
1223 status = TIReadRom (serial,
1229 dbg ("%s - can't read header back", __FUNCTION__);
1233 kfree (ti_manuf_desc);
1236 if (memcmp(vheader, header, HEADER_SIZE)) {
1237 dbg ("%s - write download record failed", __FUNCTION__);
1241 kfree (ti_manuf_desc);
1248 dbg ("%s - Start firmware update", __FUNCTION__);
1250 // Tell firmware to copy download image into I2C
1251 status = TISendVendorRequestSync (serial->serial->dev,
1252 UMPC_COPY_DNLD_TO_I2C, // Request
1255 NULL, // TransferBuffer
1256 0); // TransferBufferLength
1258 dbg ("%s - Update complete 0x%x", __FUNCTION__, status);
1260 dbg ("%s - UMPC_COPY_DNLD_TO_I2C failed", __FUNCTION__);
1262 kfree (ti_manuf_desc);
1267 // The device is running the download code
1269 kfree (ti_manuf_desc);
1273 /********************************************************************/
1275 /********************************************************************/
1276 dbg ("%s - <<<<<<<<<<<<<<<RUNNING IN BOOT MODE>>>>>>>>>>>>>>>",
1279 // Configure the TI device so we can use the BULK pipes for download
1280 status = TIConfigureBootDevice (serial->serial->dev);
1284 if (serial->serial->dev->descriptor.idVendor != USB_VENDOR_ID_ION) {
1285 dbg ("%s - VID = 0x%x", __FUNCTION__,
1286 serial->serial->dev->descriptor.idVendor);
1287 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
1288 goto StayInBootMode;
1291 // We have an ION device (I2c Must be programmed)
1292 // Determine I2C image type
1293 if (TIGetI2cTypeInBootMode(serial)) {
1294 goto StayInBootMode;
1297 // Registry variable set?
1298 if (TIStayInBootMode) {
1299 dbg ("%s - TIStayInBootMode", __FUNCTION__);
1300 goto StayInBootMode;
1303 // Check for ION Vendor ID and that the I2C is valid
1304 if (!TiValidateI2cImage(serial)) {
1305 struct ti_i2c_image_header *header;
1311 /* Validate Hardware version number
1312 * Read Manufacturing Descriptor from TI Based Edgeport
1314 ti_manuf_desc = kmalloc (sizeof (*ti_manuf_desc), GFP_KERNEL);
1315 if (!ti_manuf_desc) {
1316 dev_err (dev, "%s - out of memory.\n", __FUNCTION__);
1319 status = TIReadManufDescriptor (serial, (__u8 *)ti_manuf_desc);
1321 kfree (ti_manuf_desc);
1322 goto StayInBootMode;
1325 // Check for version 2
1326 if (!ignore_cpu_rev && TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev) < 2) {
1327 dbg ("%s - Wrong CPU Rev %d (Must be 2)", __FUNCTION__,
1328 TI_GET_CPU_REVISION(ti_manuf_desc->CpuRev_BoardRev));
1329 kfree (ti_manuf_desc);
1330 goto StayInBootMode;
1333 kfree (ti_manuf_desc);
1335 // In order to update the I2C firmware we must change the type 2 record to type 0xF2.
1336 // This will force the UMP to come up in Boot Mode. Then while in boot mode, the driver
1337 // will download the latest firmware (padded to 15.5k) into the UMP ram.
1338 // And finally when the device comes back up in download mode the driver will cause
1339 // the new firmware to be copied from the UMP Ram to I2C and the firmware will update
1340 // the record type from 0xf2 to 0x02.
1343 * Do we really have to copy the whole firmware image,
1344 * or could we do this in place!
1347 // Allocate a 15.5k buffer + 3 byte header
1348 buffer_size = (((1024 * 16) - 512) + sizeof(struct ti_i2c_image_header));
1349 buffer = kmalloc (buffer_size, GFP_KERNEL);
1351 dev_err (dev, "%s - out of memory\n", __FUNCTION__);
1355 // Initialize the buffer to 0xff (pad the buffer)
1356 memset (buffer, 0xff, buffer_size);
1358 memcpy (buffer, &PagableOperationalCodeImage[0], PagableOperationalCodeSize);
1360 for(i = sizeof(struct ti_i2c_image_header); i < buffer_size; i++) {
1361 cs = (__u8)(cs + buffer[i]);
1364 header = (struct ti_i2c_image_header *)buffer;
1366 // update length and checksum after padding
1367 header->Length = (__u16)(buffer_size - sizeof(struct ti_i2c_image_header));
1368 header->CheckSum = cs;
1370 // Download the operational code
1371 dbg ("%s - Downloading operational code image (TI UMP)", __FUNCTION__);
1372 status = TIDownloadCodeImage (serial, buffer, buffer_size);
1377 dbg ("%s - Error downloading operational code image", __FUNCTION__);
1381 // Device will reboot
1382 serial->product_info.TiMode = TI_MODE_TRANSITIONING;
1384 dbg ("%s - Download successful -- Device rebooting...", __FUNCTION__);
1386 /* return an error on purpose */
1391 // Eprom is invalid or blank stay in boot mode
1392 dbg ("%s - <<<<<<<<<<<<<<<STAYING IN BOOT MODE>>>>>>>>>>>>", __FUNCTION__);
1393 serial->product_info.TiMode = TI_MODE_BOOT;
1399 static int TISetDtr (struct edgeport_port *port)
1401 int port_number = port->port->number - port->port->serial->minor;
1403 dbg ("%s", __FUNCTION__);
1404 port->shadow_mcr |= MCR_DTR;
1406 return TIWriteCommandSync (port->port->serial->dev,
1408 (__u8)(UMPM_UART1_PORT + port_number),
1414 static int TIClearDtr (struct edgeport_port *port)
1416 int port_number = port->port->number - port->port->serial->minor;
1418 dbg ("%s", __FUNCTION__);
1419 port->shadow_mcr &= ~MCR_DTR;
1421 return TIWriteCommandSync (port->port->serial->dev,
1423 (__u8)(UMPM_UART1_PORT + port_number),
1429 static int TISetRts (struct edgeport_port *port)
1431 int port_number = port->port->number - port->port->serial->minor;
1433 dbg ("%s", __FUNCTION__);
1434 port->shadow_mcr |= MCR_RTS;
1436 return TIWriteCommandSync (port->port->serial->dev,
1438 (__u8)(UMPM_UART1_PORT + port_number),
1444 static int TIClearRts (struct edgeport_port *port)
1446 int port_number = port->port->number - port->port->serial->minor;
1448 dbg ("%s", __FUNCTION__);
1449 port->shadow_mcr &= ~MCR_RTS;
1451 return TIWriteCommandSync (port->port->serial->dev,
1453 (__u8)(UMPM_UART1_PORT + port_number),
1459 static int TISetLoopBack (struct edgeport_port *port)
1461 int port_number = port->port->number - port->port->serial->minor;
1463 dbg ("%s", __FUNCTION__);
1465 return TIWriteCommandSync (port->port->serial->dev,
1466 UMPC_SET_CLR_LOOPBACK,
1467 (__u8)(UMPM_UART1_PORT + port_number),
1473 static int TIClearLoopBack (struct edgeport_port *port)
1475 int port_number = port->port->number - port->port->serial->minor;
1477 dbg ("%s", __FUNCTION__);
1479 return TIWriteCommandSync (port->port->serial->dev,
1480 UMPC_SET_CLR_LOOPBACK,
1481 (__u8)(UMPM_UART1_PORT + port_number),
1487 static int TISetBreak (struct edgeport_port *port)
1489 int port_number = port->port->number - port->port->serial->minor;
1491 dbg ("%s", __FUNCTION__);
1493 return TIWriteCommandSync (port->port->serial->dev,
1495 (__u8)(UMPM_UART1_PORT + port_number),
1501 static int TIClearBreak (struct edgeport_port *port)
1503 int port_number = port->port->number - port->port->serial->minor;
1505 dbg ("%s", __FUNCTION__);
1507 return TIWriteCommandSync (port->port->serial->dev,
1509 (__u8)(UMPM_UART1_PORT + port_number),
1515 static int TIRestoreMCR (struct edgeport_port *port, __u8 mcr)
1519 dbg ("%s - %x", __FUNCTION__, mcr);
1522 status = TISetDtr (port);
1524 status = TIClearDtr (port);
1530 status = TISetRts (port);
1532 status = TIClearRts (port);
1537 if (mcr & MCR_LOOPBACK)
1538 status = TISetLoopBack (port);
1540 status = TIClearLoopBack (port);
1547 /* Convert TI LSR to standard UART flags */
1548 static __u8 MapLineStatus (__u8 ti_lsr)
1552 #define MAP_FLAG(flagUmp, flagUart) \
1553 if (ti_lsr & flagUmp) \
1556 MAP_FLAG(UMP_UART_LSR_OV_MASK, LSR_OVER_ERR) /* overrun */
1557 MAP_FLAG(UMP_UART_LSR_PE_MASK, LSR_PAR_ERR) /* parity error */
1558 MAP_FLAG(UMP_UART_LSR_FE_MASK, LSR_FRM_ERR) /* framing error */
1559 MAP_FLAG(UMP_UART_LSR_BR_MASK, LSR_BREAK) /* break detected */
1560 MAP_FLAG(UMP_UART_LSR_RX_MASK, LSR_RX_AVAIL) /* receive data available */
1561 MAP_FLAG(UMP_UART_LSR_TX_MASK, LSR_TX_EMPTY) /* transmit holding register empty */
1568 static void handle_new_msr (struct edgeport_port *edge_port, __u8 msr)
1570 struct async_icount *icount;
1572 dbg ("%s - %02x", __FUNCTION__, msr);
1574 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
1575 icount = &edge_port->icount;
1577 /* update input line counters */
1578 if (msr & EDGEPORT_MSR_DELTA_CTS)
1580 if (msr & EDGEPORT_MSR_DELTA_DSR)
1582 if (msr & EDGEPORT_MSR_DELTA_CD)
1584 if (msr & EDGEPORT_MSR_DELTA_RI)
1586 wake_up_interruptible (&edge_port->delta_msr_wait);
1589 /* Save the new modem status */
1590 edge_port->shadow_msr = msr & 0xf0;
1595 static void handle_new_lsr (struct edgeport_port *edge_port, int lsr_data, __u8 lsr, __u8 data)
1597 struct async_icount *icount;
1598 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK));
1600 dbg ("%s - %02x", __FUNCTION__, new_lsr);
1602 edge_port->shadow_lsr = lsr;
1604 if (new_lsr & LSR_BREAK) {
1606 * Parity and Framing errors only count if they
1607 * occur exclusive of a break being received.
1609 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
1612 /* Place LSR data byte into Rx buffer */
1613 if (lsr_data && edge_port->port->tty) {
1614 tty_insert_flip_char(edge_port->port->tty, data, 0);
1615 tty_flip_buffer_push(edge_port->port->tty);
1618 /* update input line counters */
1619 icount = &edge_port->icount;
1620 if (new_lsr & LSR_BREAK)
1622 if (new_lsr & LSR_OVER_ERR)
1624 if (new_lsr & LSR_PAR_ERR)
1626 if (new_lsr & LSR_FRM_ERR)
1631 static void edge_interrupt_callback (struct urb *urb, struct pt_regs *regs)
1633 struct edgeport_serial *edge_serial = (struct edgeport_serial *)urb->context;
1634 struct usb_serial_port *port;
1635 struct edgeport_port *edge_port;
1636 unsigned char *data = urb->transfer_buffer;
1637 int length = urb->actual_length;
1644 dbg("%s", __FUNCTION__);
1646 switch (urb->status) {
1653 /* this urb is terminated, clean up */
1654 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
1657 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
1662 dbg ("%s - no data in urb", __FUNCTION__);
1666 usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __FUNCTION__, length, data);
1669 dbg ("%s - expecting packet of size 2, got %d", __FUNCTION__, length);
1673 port_number = TIUMP_GET_PORT_FROM_CODE (data[0]);
1674 function = TIUMP_GET_FUNC_FROM_CODE (data[0]);
1675 dbg ("%s - port_number %d, function %d, info 0x%x",
1676 __FUNCTION__, port_number, function, data[1]);
1677 port = edge_serial->serial->port[port_number];
1678 edge_port = usb_get_serial_port_data(port);
1680 dbg ("%s - edge_port not found", __FUNCTION__);
1684 case TIUMP_INTERRUPT_CODE_LSR:
1685 lsr = MapLineStatus(data[1]);
1686 if (lsr & UMP_UART_LSR_DATA_MASK) {
1687 /* Save the LSR event for bulk read completion routine */
1688 dbg ("%s - LSR Event Port %u LSR Status = %02x",
1689 __FUNCTION__, port_number, lsr);
1690 edge_port->lsr_event = 1;
1691 edge_port->lsr_mask = lsr;
1693 dbg ("%s - ===== Port %d LSR Status = %02x ======",
1694 __FUNCTION__, port_number, lsr);
1695 handle_new_lsr (edge_port, 0, lsr, 0);
1699 case TIUMP_INTERRUPT_CODE_MSR: // MSR
1700 /* Copy MSR from UMP */
1702 dbg ("%s - ===== Port %u MSR Status = %02x ======\n",
1703 __FUNCTION__, port_number, msr);
1704 handle_new_msr (edge_port, msr);
1708 dev_err (&urb->dev->dev, "%s - Unknown Interrupt code from UMP %x\n",
1709 __FUNCTION__, data[1]);
1715 status = usb_submit_urb (urb, GFP_ATOMIC);
1717 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
1718 __FUNCTION__, status);
1721 static void edge_bulk_in_callback (struct urb *urb, struct pt_regs *regs)
1723 struct edgeport_port *edge_port = (struct edgeport_port *)urb->context;
1724 unsigned char *data = urb->transfer_buffer;
1725 struct tty_struct *tty;
1730 dbg("%s", __FUNCTION__);
1733 dbg ("%s - nonzero read bulk status received: %d",
1734 __FUNCTION__, urb->status);
1736 if (urb->status == -EPIPE) {
1737 /* clear any problem that might have happened on this pipe */
1738 usb_clear_halt (edge_port->port->serial->dev, urb->pipe);
1744 port_number = edge_port->port->number - edge_port->port->serial->minor;
1746 if (edge_port->lsr_event) {
1747 edge_port->lsr_event = 0;
1748 dbg ("%s ===== Port %u LSR Status = %02x, Data = %02x ======",
1749 __FUNCTION__, port_number, edge_port->lsr_mask, *data);
1750 handle_new_lsr (edge_port, 1, edge_port->lsr_mask, *data);
1751 /* Adjust buffer length/pointer */
1752 --urb->actual_length;
1756 tty = edge_port->port->tty;
1757 if (tty && urb->actual_length) {
1758 usb_serial_debug_data(debug, &edge_port->port->dev, __FUNCTION__, urb->actual_length, data);
1760 if (edge_port->close_pending) {
1761 dbg ("%s - close is pending, dropping data on the floor.", __FUNCTION__);
1763 for (i = 0; i < urb->actual_length ; ++i) {
1764 /* if we insert more than TTY_FLIPBUF_SIZE characters,
1766 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
1767 tty_flip_buffer_push(tty);
1769 /* this doesn't actually push the data through unless
1770 * tty->low_latency is set */
1771 tty_insert_flip_char(tty, data[i], 0);
1773 tty_flip_buffer_push(tty);
1775 edge_port->icount.rx += urb->actual_length;
1779 /* continue always trying to read */
1780 status = usb_submit_urb (urb, GFP_ATOMIC);
1782 dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
1783 __FUNCTION__, status);
1786 static void edge_bulk_out_callback (struct urb *urb, struct pt_regs *regs)
1788 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1789 struct tty_struct *tty;
1791 dbg ("%s - port %d", __FUNCTION__, port->number);
1794 dbg ("%s - nonzero write bulk status received: %d",
1795 __FUNCTION__, urb->status);
1797 if (urb->status == -EPIPE) {
1798 /* clear any problem that might have happened on this pipe */
1799 usb_clear_halt (port->serial->dev, urb->pipe);
1806 /* let the tty driver wakeup if it has a special write_wakeup function */
1807 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) {
1808 (tty->ldisc.write_wakeup)(tty);
1811 /* tell the tty driver that something has changed */
1812 wake_up_interruptible(&tty->write_wait);
1816 static int edge_open (struct usb_serial_port *port, struct file * filp)
1818 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1819 struct edgeport_serial *edge_serial;
1820 struct usb_device *dev;
1825 u8 transaction_timeout;
1827 dbg("%s - port %d", __FUNCTION__, port->number);
1829 if (edge_port == NULL)
1832 /* force low_latency on so that our tty_push actually forces the data through,
1833 otherwise it is scheduled, and with high data rates (like with OHCI) data
1836 port->tty->low_latency = 1;
1838 port_number = port->number - port->serial->minor;
1839 switch (port_number) {
1841 edge_port->uart_base = UMPMEM_BASE_UART1;
1842 edge_port->dma_address = UMPD_OEDB1_ADDRESS;
1845 edge_port->uart_base = UMPMEM_BASE_UART2;
1846 edge_port->dma_address = UMPD_OEDB2_ADDRESS;
1849 dev_err (&port->dev, "Unknown port number!!!\n");
1853 dbg ("%s - port_number = %d, uart_base = %04x, dma_address = %04x",
1854 __FUNCTION__, port_number, edge_port->uart_base, edge_port->dma_address);
1856 dev = port->serial->dev;
1858 memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount));
1859 init_waitqueue_head (&edge_port->delta_msr_wait);
1861 /* turn off loopback */
1862 status = TIClearLoopBack (edge_port);
1866 /* set up the port settings */
1867 edge_set_termios (port, NULL);
1869 /* open up the port */
1871 /* milliseconds to timeout for DMA transfer */
1872 transaction_timeout = 2;
1874 edge_port->ump_read_timeout = max (20, ((transaction_timeout * 3) / 2) );
1876 // milliseconds to timeout for DMA transfer
1877 open_settings = (u8)(UMP_DMA_MODE_CONTINOUS |
1878 UMP_PIPE_TRANS_TIMEOUT_ENA |
1879 (transaction_timeout << 2));
1881 dbg ("%s - Sending UMPC_OPEN_PORT", __FUNCTION__);
1883 /* Tell TI to open and start the port */
1884 status = TIWriteCommandSync (dev,
1886 (u8)(UMPM_UART1_PORT + port_number),
1893 /* Start the DMA? */
1894 status = TIWriteCommandSync (dev,
1896 (u8)(UMPM_UART1_PORT + port_number),
1903 /* Clear TX and RX buffers in UMP */
1904 status = TIPurgeDataSync (port, UMP_PORT_DIR_OUT | UMP_PORT_DIR_IN);
1908 /* Read Initial MSR */
1909 status = TIReadVendorRequestSync (dev,
1910 UMPC_READ_MSR, // Request
1912 (__u16)(UMPM_UART1_PORT + port_number), // wIndex (Address)
1913 &edge_port->shadow_msr, // TransferBuffer
1914 1); // TransferBufferLength
1918 dbg ("ShadowMSR 0x%X", edge_port->shadow_msr);
1920 edge_serial = edge_port->edge_serial;
1921 if (edge_serial->num_ports_open == 0) {
1922 /* we are the first port to be opened, let's post the interrupt urb */
1923 urb = edge_serial->serial->port[0]->interrupt_in_urb;
1925 dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __FUNCTION__);
1928 urb->complete = edge_interrupt_callback;
1929 urb->context = edge_serial;
1931 status = usb_submit_urb (urb, GFP_KERNEL);
1933 dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__, status);
1939 * reset the data toggle on the bulk endpoints to work around bug in
1940 * host controllers where things get out of sync some times
1942 usb_clear_halt (dev, port->write_urb->pipe);
1943 usb_clear_halt (dev, port->read_urb->pipe);
1945 /* start up our bulk read urb */
1946 urb = port->read_urb;
1948 dev_err (&port->dev, "%s - no read urb present, exiting\n", __FUNCTION__);
1951 urb->complete = edge_bulk_in_callback;
1952 urb->context = edge_port;
1954 status = usb_submit_urb (urb, GFP_KERNEL);
1956 dev_err (&port->dev, "%s - read bulk usb_submit_urb failed with value %d\n", __FUNCTION__, status);
1960 ++edge_serial->num_ports_open;
1962 dbg("%s - exited", __FUNCTION__);
1967 static void edge_close (struct usb_serial_port *port, struct file * filp)
1969 struct edgeport_serial *edge_serial;
1970 struct edgeport_port *edge_port;
1974 dbg("%s - port %d", __FUNCTION__, port->number);
1976 edge_serial = usb_get_serial_data(port->serial);
1977 edge_port = usb_get_serial_port_data(port);
1978 if ((edge_serial == NULL) || (edge_port == NULL))
1981 /* The bulkreadcompletion routine will check
1982 * this flag and dump add read data */
1983 edge_port->close_pending = 1;
1985 /* chase the port close */
1986 TIChasePort (edge_port);
1988 usb_unlink_urb (port->read_urb);
1990 /* assuming we can still talk to the device,
1991 * send a close port command to it */
1992 dbg("%s - send umpc_close_port", __FUNCTION__);
1993 port_number = port->number - port->serial->minor;
1994 status = TIWriteCommandSync (port->serial->dev,
1996 (__u8)(UMPM_UART1_PORT + port_number),
2000 --edge_port->edge_serial->num_ports_open;
2001 if (edge_port->edge_serial->num_ports_open <= 0) {
2002 /* last port is now closed, let's shut down our interrupt urb */
2003 usb_unlink_urb (port->serial->port[0]->interrupt_in_urb);
2004 edge_port->edge_serial->num_ports_open = 0;
2006 edge_port->close_pending = 0;
2008 dbg("%s - exited", __FUNCTION__);
2011 static int edge_write (struct usb_serial_port *port, int from_user, const unsigned char *data, int count)
2013 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2016 dbg("%s - port %d", __FUNCTION__, port->number);
2019 dbg("%s - write request of 0 bytes", __FUNCTION__);
2023 if (edge_port == NULL)
2025 if (edge_port->close_pending == 1)
2028 if (port->write_urb->status == -EINPROGRESS) {
2029 dbg ("%s - already writing", __FUNCTION__);
2033 count = min (count, port->bulk_out_size);
2036 if (copy_from_user(port->write_urb->transfer_buffer, data, count))
2039 memcpy (port->write_urb->transfer_buffer, data, count);
2042 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, port->write_urb->transfer_buffer);
2044 /* set up our urb */
2045 usb_fill_bulk_urb (port->write_urb, port->serial->dev,
2046 usb_sndbulkpipe (port->serial->dev,
2047 port->bulk_out_endpointAddress),
2048 port->write_urb->transfer_buffer, count,
2049 edge_bulk_out_callback,
2052 /* send the data out the bulk port */
2053 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
2055 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result);
2060 edge_port->icount.tx += count;
2065 static int edge_write_room (struct usb_serial_port *port)
2067 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2070 dbg("%s", __FUNCTION__);
2072 if (edge_port == NULL)
2074 if (edge_port->close_pending == 1)
2077 dbg("%s - port %d", __FUNCTION__, port->number);
2079 if (port->write_urb->status != -EINPROGRESS)
2080 room = port->bulk_out_size;
2082 dbg("%s - returns %d", __FUNCTION__, room);
2086 static int edge_chars_in_buffer (struct usb_serial_port *port)
2088 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2091 dbg("%s", __FUNCTION__);
2093 if (edge_port == NULL)
2095 if (edge_port->close_pending == 1)
2098 dbg("%s - port %d", __FUNCTION__, port->number);
2100 if (port->write_urb->status == -EINPROGRESS)
2101 chars = port->write_urb->transfer_buffer_length;
2103 dbg ("%s - returns %d", __FUNCTION__, chars);
2107 static void edge_throttle (struct usb_serial_port *port)
2109 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2110 struct tty_struct *tty;
2113 dbg("%s - port %d", __FUNCTION__, port->number);
2115 if (edge_port == NULL)
2120 dbg ("%s - no tty available", __FUNCTION__);
2123 /* if we are implementing XON/XOFF, send the stop character */
2125 unsigned char stop_char = STOP_CHAR(tty);
2126 status = edge_write (port, 0, &stop_char, 1);
2132 /* if we are implementing RTS/CTS, toggle that line */
2133 if (tty->termios->c_cflag & CRTSCTS) {
2134 status = TIClearRts (edge_port);
2137 usb_unlink_urb (port->read_urb);
2140 static void edge_unthrottle (struct usb_serial_port *port)
2142 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2143 struct tty_struct *tty;
2146 dbg("%s - port %d", __FUNCTION__, port->number);
2148 if (edge_port == NULL)
2153 dbg ("%s - no tty available", __FUNCTION__);
2157 /* if we are implementing XON/XOFF, send the start character */
2159 unsigned char start_char = START_CHAR(tty);
2160 status = edge_write (port, 0, &start_char, 1);
2166 /* if we are implementing RTS/CTS, toggle that line */
2167 if (tty->termios->c_cflag & CRTSCTS) {
2168 status = TISetRts (edge_port);
2171 port->read_urb->dev = port->serial->dev;
2172 status = usb_submit_urb (port->read_urb, GFP_ATOMIC);
2174 dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__, status);
2179 static void change_port_settings (struct edgeport_port *edge_port, struct termios *old_termios)
2181 struct ump_uart_config *config;
2182 struct tty_struct *tty;
2187 int port_number = edge_port->port->number - edge_port->port->serial->minor;
2189 dbg("%s - port %d", __FUNCTION__, edge_port->port->number);
2191 tty = edge_port->port->tty;
2194 dbg("%s - no tty structures", __FUNCTION__);
2198 config = kmalloc (sizeof (*config), GFP_KERNEL);
2200 dev_err (&edge_port->port->dev, "%s - out of memory\n", __FUNCTION__);
2204 cflag = tty->termios->c_cflag;
2208 /* These flags must be set */
2209 config->wFlags |= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT;
2210 config->wFlags |= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR;
2211 config->bUartMode = 0;
2213 switch (cflag & CSIZE) {
2215 config->bDataBits = UMP_UART_CHAR5BITS;
2216 dbg ("%s - data bits = 5", __FUNCTION__);
2219 config->bDataBits = UMP_UART_CHAR6BITS;
2220 dbg ("%s - data bits = 6", __FUNCTION__);
2223 config->bDataBits = UMP_UART_CHAR7BITS;
2224 dbg ("%s - data bits = 7", __FUNCTION__);
2228 config->bDataBits = UMP_UART_CHAR8BITS;
2229 dbg ("%s - data bits = 8", __FUNCTION__);
2233 if (cflag & PARENB) {
2234 if (cflag & PARODD) {
2235 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2236 config->bParity = UMP_UART_ODDPARITY;
2237 dbg("%s - parity = odd", __FUNCTION__);
2239 config->wFlags |= UMP_MASK_UART_FLAGS_PARITY;
2240 config->bParity = UMP_UART_EVENPARITY;
2241 dbg("%s - parity = even", __FUNCTION__);
2244 config->bParity = UMP_UART_NOPARITY;
2245 dbg("%s - parity = none", __FUNCTION__);
2248 if (cflag & CSTOPB) {
2249 config->bStopBits = UMP_UART_STOPBIT2;
2250 dbg("%s - stop bits = 2", __FUNCTION__);
2252 config->bStopBits = UMP_UART_STOPBIT1;
2253 dbg("%s - stop bits = 1", __FUNCTION__);
2256 /* figure out the flow control settings */
2257 if (cflag & CRTSCTS) {
2258 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X_CTS_FLOW;
2259 config->wFlags |= UMP_MASK_UART_FLAGS_RTS_FLOW;
2260 dbg("%s - RTS/CTS is enabled", __FUNCTION__);
2262 dbg("%s - RTS/CTS is disabled", __FUNCTION__);
2265 /* if we are implementing XON/XOFF, set the start and stop character in the device */
2266 if (I_IXOFF(tty) || I_IXON(tty)) {
2267 config->cXon = START_CHAR(tty);
2268 config->cXoff = STOP_CHAR(tty);
2270 /* if we are implementing INBOUND XON/XOFF */
2272 config->wFlags |= UMP_MASK_UART_FLAGS_IN_X;
2273 dbg ("%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2274 __FUNCTION__, config->cXon, config->cXoff);
2276 dbg ("%s - INBOUND XON/XOFF is disabled", __FUNCTION__);
2279 /* if we are implementing OUTBOUND XON/XOFF */
2281 config->wFlags |= UMP_MASK_UART_FLAGS_OUT_X;
2282 dbg ("%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x",
2283 __FUNCTION__, config->cXon, config->cXoff);
2285 dbg ("%s - OUTBOUND XON/XOFF is disabled", __FUNCTION__);
2289 /* Round the baud rate */
2290 baud = tty_get_baud_rate(tty);
2292 /* pick a default, any default... */
2295 config->wBaudRate = (__u16)(461550L / baud);
2296 round = 4615500L / baud;
2297 if ((round - (config->wBaudRate * 10)) >= 5)
2298 config->wBaudRate++;
2300 dbg ("%s - baud rate = %d, wBaudRate = %d", __FUNCTION__, baud, config->wBaudRate);
2302 dbg ("wBaudRate: %d", (int)(461550L / config->wBaudRate));
2303 dbg ("wFlags: 0x%x", config->wFlags);
2304 dbg ("bDataBits: %d", config->bDataBits);
2305 dbg ("bParity: %d", config->bParity);
2306 dbg ("bStopBits: %d", config->bStopBits);
2307 dbg ("cXon: %d", config->cXon);
2308 dbg ("cXoff: %d", config->cXoff);
2309 dbg ("bUartMode: %d", config->bUartMode);
2311 /* move the word values into big endian mode */
2312 cpu_to_be16s (&config->wFlags);
2313 cpu_to_be16s (&config->wBaudRate);
2315 status = TIWriteCommandSync (edge_port->port->serial->dev,
2317 (__u8)(UMPM_UART1_PORT + port_number),
2322 dbg ("%s - error %d when trying to write config to device",
2323 __FUNCTION__, status);
2331 static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios)
2333 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2334 struct tty_struct *tty = port->tty;
2337 if (!port->tty || !port->tty->termios) {
2338 dbg ("%s - no tty or termios", __FUNCTION__);
2342 cflag = tty->termios->c_cflag;
2343 /* check that they really want us to change something */
2345 if ((cflag == old_termios->c_cflag) &&
2346 (RELEVANT_IFLAG(tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
2347 dbg ("%s - nothing to change", __FUNCTION__);
2352 dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
2353 tty->termios->c_cflag,
2354 RELEVANT_IFLAG(tty->termios->c_iflag));
2356 dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
2357 old_termios->c_cflag,
2358 RELEVANT_IFLAG(old_termios->c_iflag));
2361 dbg("%s - port %d", __FUNCTION__, port->number);
2363 if (edge_port == NULL)
2366 /* change the port settings to the new ones specified */
2367 change_port_settings (edge_port, old_termios);
2372 static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear)
2374 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2377 dbg("%s - port %d", __FUNCTION__, port->number);
2379 mcr = edge_port->shadow_mcr;
2380 if (set & TIOCM_RTS)
2382 if (set & TIOCM_DTR)
2384 if (set & TIOCM_LOOP)
2385 mcr |= MCR_LOOPBACK;
2387 if (clear & TIOCM_RTS)
2389 if (clear & TIOCM_DTR)
2391 if (clear & TIOCM_LOOP)
2392 mcr &= ~MCR_LOOPBACK;
2394 edge_port->shadow_mcr = mcr;
2396 TIRestoreMCR (edge_port, mcr);
2401 static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
2403 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2404 unsigned int result = 0;
2408 dbg("%s - port %d", __FUNCTION__, port->number);
2410 msr = edge_port->shadow_msr;
2411 mcr = edge_port->shadow_mcr;
2412 result = ((mcr & MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */
2413 | ((mcr & MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */
2414 | ((msr & EDGEPORT_MSR_CTS) ? TIOCM_CTS: 0) /* 0x020 */
2415 | ((msr & EDGEPORT_MSR_CD) ? TIOCM_CAR: 0) /* 0x040 */
2416 | ((msr & EDGEPORT_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */
2417 | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */
2420 dbg("%s -- %x", __FUNCTION__, result);
2425 static int get_serial_info (struct edgeport_port *edge_port, struct serial_struct __user *retinfo)
2427 struct serial_struct tmp;
2432 memset(&tmp, 0, sizeof(tmp));
2434 tmp.type = PORT_16550A;
2435 tmp.line = edge_port->port->serial->minor;
2436 tmp.port = edge_port->port->number;
2438 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
2439 tmp.xmit_fifo_size = edge_port->port->bulk_out_size;
2440 tmp.baud_base = 9600;
2441 tmp.close_delay = 5*HZ;
2442 tmp.closing_wait = 30*HZ;
2443 // tmp.custom_divisor = state->custom_divisor;
2444 // tmp.hub6 = state->hub6;
2445 // tmp.io_type = state->io_type;
2448 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2453 static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg)
2455 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2456 struct async_icount cnow;
2457 struct async_icount cprev;
2459 dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd);
2463 dbg("%s - (%d) TIOCINQ", __FUNCTION__, port->number);
2464 // return get_number_bytes_avail(edge_port, (unsigned int *) arg);
2468 dbg("%s - (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
2469 // return get_lsr_info(edge_port, (unsigned int *) arg);
2473 dbg("%s - (%d) TIOCGSERIAL", __FUNCTION__, port->number);
2474 return get_serial_info(edge_port, (struct serial_struct __user *) arg);
2478 dbg("%s - (%d) TIOCSSERIAL", __FUNCTION__, port->number);
2482 dbg("%s - (%d) TIOCMIWAIT", __FUNCTION__, port->number);
2483 cprev = edge_port->icount;
2485 interruptible_sleep_on(&edge_port->delta_msr_wait);
2486 /* see if a signal did it */
2487 if (signal_pending(current))
2488 return -ERESTARTSYS;
2489 cnow = edge_port->icount;
2490 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2491 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2492 return -EIO; /* no change => error */
2493 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2494 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2495 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2496 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2505 dbg ("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__,
2506 port->number, edge_port->icount.rx, edge_port->icount.tx);
2507 if (copy_to_user((void __user *)arg, &edge_port->icount, sizeof(edge_port->icount)))
2512 return -ENOIOCTLCMD;
2515 static void edge_break (struct usb_serial_port *port, int break_state)
2517 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2520 dbg ("%s - state = %d", __FUNCTION__, break_state);
2522 /* chase the port close */
2523 TIChasePort (edge_port);
2525 if (break_state == -1) {
2526 status = TISetBreak (edge_port);
2528 status = TIClearBreak (edge_port);
2531 dbg ("%s - error %d sending break set/clear command.",
2532 __FUNCTION__, status);
2536 static int edge_startup (struct usb_serial *serial)
2538 struct edgeport_serial *edge_serial;
2539 struct edgeport_port *edge_port;
2540 struct usb_device *dev;
2546 /* create our private serial structure */
2547 edge_serial = kmalloc (sizeof(struct edgeport_serial), GFP_KERNEL);
2548 if (edge_serial == NULL) {
2549 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2552 memset (edge_serial, 0, sizeof(struct edgeport_serial));
2553 edge_serial->serial = serial;
2554 usb_set_serial_data(serial, edge_serial);
2556 status = TIDownloadFirmware (edge_serial);
2558 kfree (edge_serial);
2562 /* set up our port private structures */
2563 for (i = 0; i < serial->num_ports; ++i) {
2564 edge_port = kmalloc (sizeof(struct edgeport_port), GFP_KERNEL);
2565 if (edge_port == NULL) {
2566 dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
2569 memset (edge_port, 0, sizeof(struct edgeport_port));
2570 edge_port->port = serial->port[i];
2571 edge_port->edge_serial = edge_serial;
2572 usb_set_serial_port_data(serial->port[i], edge_port);
2578 static void edge_shutdown (struct usb_serial *serial)
2582 dbg ("%s", __FUNCTION__);
2584 for (i=0; i < serial->num_ports; ++i) {
2585 kfree (usb_get_serial_port_data(serial->port[i]));
2586 usb_set_serial_port_data(serial->port[i], NULL);
2588 kfree (usb_get_serial_data(serial));
2589 usb_set_serial_data(serial, NULL);
2593 static struct usb_serial_device_type edgeport_1port_device = {
2594 .owner = THIS_MODULE,
2595 .name = "Edgeport TI 1 port adapter",
2596 .short_name = "edgeport_ti_1",
2597 .id_table = edgeport_1port_id_table,
2598 .num_interrupt_in = 1,
2603 .close = edge_close,
2604 .throttle = edge_throttle,
2605 .unthrottle = edge_unthrottle,
2606 .attach = edge_startup,
2607 .shutdown = edge_shutdown,
2608 .ioctl = edge_ioctl,
2609 .set_termios = edge_set_termios,
2610 .tiocmget = edge_tiocmget,
2611 .tiocmset = edge_tiocmset,
2612 .write = edge_write,
2613 .write_room = edge_write_room,
2614 .chars_in_buffer = edge_chars_in_buffer,
2615 .break_ctl = edge_break,
2618 static struct usb_serial_device_type edgeport_2port_device = {
2619 .owner = THIS_MODULE,
2620 .name = "Edgeport TI 2 port adapter",
2621 .short_name = "edgeport_ti_2",
2622 .id_table = edgeport_2port_id_table,
2623 .num_interrupt_in = 1,
2628 .close = edge_close,
2629 .throttle = edge_throttle,
2630 .unthrottle = edge_unthrottle,
2631 .attach = edge_startup,
2632 .shutdown = edge_shutdown,
2633 .ioctl = edge_ioctl,
2634 .set_termios = edge_set_termios,
2635 .tiocmget = edge_tiocmget,
2636 .tiocmset = edge_tiocmset,
2637 .write = edge_write,
2638 .write_room = edge_write_room,
2639 .chars_in_buffer = edge_chars_in_buffer,
2640 .break_ctl = edge_break,
2644 static int __init edgeport_init(void)
2647 retval = usb_serial_register(&edgeport_1port_device);
2649 goto failed_1port_device_register;
2650 retval = usb_serial_register(&edgeport_2port_device);
2652 goto failed_2port_device_register;
2653 retval = usb_register(&io_driver);
2655 goto failed_usb_register;
2656 info(DRIVER_DESC " " DRIVER_VERSION);
2658 failed_usb_register:
2659 usb_serial_deregister(&edgeport_2port_device);
2660 failed_2port_device_register:
2661 usb_serial_deregister(&edgeport_1port_device);
2662 failed_1port_device_register:
2666 static void __exit edgeport_exit (void)
2668 usb_deregister (&io_driver);
2669 usb_serial_deregister (&edgeport_1port_device);
2670 usb_serial_deregister (&edgeport_2port_device);
2673 module_init(edgeport_init);
2674 module_exit(edgeport_exit);
2676 /* Module information */
2677 MODULE_AUTHOR(DRIVER_AUTHOR);
2678 MODULE_DESCRIPTION(DRIVER_DESC);
2679 MODULE_LICENSE("GPL");
2681 module_param(debug, bool, S_IRUGO | S_IWUSR);
2682 MODULE_PARM_DESC(debug, "Debug enabled or not");
2684 module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR);
2685 MODULE_PARM_DESC(ignore_cpu_rev, "Ignore the cpu revision when connecting to a device");