20 #include <linux/kernel.h>
22 #include <linux/errno.h>
24 #include <linux/slab.h>
25 #include <linux/tty.h>
28 #include <linux/module.h>
31 #include <linux/serial.h>
46 #define DRIVER_VERSION "v0.7mode043006"
48 #define DRIVER_DESC "Edgeport USB Serial Driver"
50 #define EPROM_PAGE_SIZE 64
54 #define HARDWARE_TYPE_930 0
55 #define HARDWARE_TYPE_TIUMP 1
58 #define TI_MODE_CONFIGURING 0
59 #define TI_MODE_BOOT 1
60 #define TI_MODE_DOWNLOAD 2
61 #define TI_MODE_TRANSITIONING 3
65 #define EDGE_READ_URB_RUNNING 0
66 #define EDGE_READ_URB_STOPPING 1
67 #define EDGE_READ_URB_STOPPED 2
69 #define EDGE_CLOSING_WAIT 4000
71 #define EDGE_OUT_BUF_SIZE 1024
118 static const struct usb_device_id edgeport_1port_id_table[] = {
138 static const struct usb_device_id edgeport_2port_id_table[] = {
200 static unsigned char OperationalMajorVersion;
201 static unsigned char OperationalMinorVersion;
202 static unsigned short OperationalBuildNumber;
205 static bool ignore_cpu_rev;
206 static int default_uart_mode;
214 static void edge_set_termios(
struct tty_struct *tty,
216 static void edge_send(
struct tty_struct *tty);
230 value, index, data, size, 1000);
233 if (status != size) {
234 dev_dbg(&dev->dev,
"%s - wanted to write %d, but only wrote %d\n",
235 __func__, size, status);
241 static int ti_vsend_sync(
struct usb_device *dev,
__u8 request,
248 value, index, data, size, 1000);
251 if (status != size) {
252 dev_dbg(&dev->dev,
"%s - wanted to write %d, but only wrote %d\n",
253 __func__, size, status);
259 static int send_cmd(
struct usb_device *dev,
__u8 command,
263 return ti_vsend_sync(dev, command, value, moduleid, data, size);
271 dev_dbg(&port->
dev,
"%s - port %d, mask %x\n", __func__, port_number, mask);
273 return send_cmd(port->
serial->dev,
289 static int read_download_mem(
struct usb_device *dev,
int start_address,
296 dev_dbg(&dev->dev,
"%s - @ %x for %d\n", __func__, start_address, length);
305 read_length = (
__u8)length;
307 if (read_length > 1) {
308 dev_dbg(&dev->dev,
"%s - @ %x for %d\n", __func__, start_address, read_length);
314 buffer, read_length);
317 dev_dbg(&dev->dev,
"%s - ERROR %x\n", __func__, status);
322 usb_serial_debug_data(&dev->dev, __func__, read_length, buffer);
325 start_address += read_length;
326 buffer += read_length;
327 length -= read_length;
333 static int read_ram(
struct usb_device *dev,
int start_address,
334 int length,
__u8 *buffer)
336 return read_download_mem(dev, start_address, length,
342 int start_address,
int length,
__u8 *buffer)
347 for (i = 0; i <
length; i++) {
348 status = ti_vread_sync(serial->
serial->dev,
350 (
__u16)(start_address+i), &buffer[i], 0x01);
352 dev_dbg(&serial->
serial->dev->dev,
"%s - ERROR %x\n", __func__, status);
357 dev_dbg(&serial->
serial->dev->dev,
"%s - start_address = %x, length = %d\n",
358 __func__, start_address, length);
359 usb_serial_debug_data(&serial->
serial->dev->dev, __func__, length, buffer);
368 int start_address,
int length,
__u8 *buffer)
379 "%s - out of memory\n", __func__);
382 status = read_boot_mem(serial, 0, 1, temp);
389 status = ti_vsend_sync(serial->
serial->dev,
396 dev_dbg(&serial->
serial->dev->dev,
"%s - start_sddr = %x, length = %d\n", __func__, start_address, length);
397 usb_serial_debug_data(&serial->
serial->dev->dev, __func__, length, buffer);
405 int start_address,
int length,
__u8 address_type,
__u8 *buffer)
418 if (write_length > length)
421 dev_dbg(dev,
"%s - BytesInFirstPage Addr = %x, length = %d\n",
422 __func__, start_address, write_length);
423 usb_serial_debug_data(dev, __func__, write_length, buffer);
427 status = ti_vsend_sync(serial->
serial->dev,
430 buffer, write_length);
432 dev_dbg(dev,
"%s - ERROR %d\n", __func__, status);
436 length -= write_length;
437 start_address += write_length;
438 buffer += write_length;
448 dev_dbg(dev,
"%s - Page Write Addr = %x, length = %d\n",
449 __func__, start_address, write_length);
450 usb_serial_debug_data(dev, __func__, write_length, buffer);
457 buffer, write_length);
459 dev_err(dev,
"%s - ERROR %d\n", __func__, status);
463 length -= write_length;
464 start_address += write_length;
465 buffer += write_length;
485 dev_err(&port->
port->dev,
"%s - out of memory\n", __func__);
498 sizeof(*oedb), (
void *)oedb);
500 goto exit_is_tx_active;
505 status = read_ram(port->
port->serial->dev,
509 goto exit_is_tx_active;
510 dev_dbg(&port->
port->dev,
"%s - LSR = 0x%X\n", __func__, *lsr);
521 dev_dbg(&port->
port->dev,
"%s - return %d\n", __func__, bytes_left);
528 static void chase_port(
struct edgeport_port *port,
unsigned long timeout,
542 init_waitqueue_entry(&wait,
current);
547 || timeout == 0 || signal_pending(
current)
551 spin_unlock_irqrestore(&port->
ep_lock, flags);
559 spin_unlock_irqrestore(&port->
ep_lock, flags);
564 while ((
long)(jiffies - timeout) < 0 && !signal_pending(
current)
567 if (!tx_active(port))
584 static int choose_config(
struct usb_device *dev)
593 dev_dbg(&dev->dev,
"%s - Number of Interfaces = %d\n",
594 __func__, dev->config->desc.bNumInterfaces);
595 dev_dbg(&dev->dev,
"%s - MAX Power = %d\n",
596 __func__, dev->config->desc.bMaxPower * 2);
598 if (dev->config->desc.bNumInterfaces != 1) {
599 dev_err(&dev->dev,
"%s - bNumInterfaces is not 1, ERROR!\n", __func__);
607 int start_address,
int length,
__u8 *buffer)
612 status = read_download_mem(serial->
serial->dev,
618 status = read_boot_mem(serial, start_address, length,
624 static int write_rom(
struct edgeport_serial *serial,
int start_address,
625 int length,
__u8 *buffer)
628 return write_boot_mem(serial, start_address, length,
632 return write_i2c_mem(serial, start_address, length,
649 status = read_rom(serial,
656 if (rom_desc->
Type == desc_type)
657 return start_address;
659 start_address = start_address +
sizeof(
struct ti_i2c_desc)
673 for (i = 0; i < rom_desc->
Size; i++)
674 cs = (
__u8)(cs + buffer[
i]);
689 int start_address = 2;
695 dev_err(dev,
"%s - out of memory\n", __func__);
700 dev_err(dev,
"%s - out of memory when allocating buffer\n",
707 status = read_rom(serial, 0, 1, buffer);
712 dev_err(dev,
"%s - invalid buffer signature\n", __func__);
719 status = read_rom(serial,
729 dev_dbg(dev,
"%s - structure too big, erroring out.\n", __func__);
733 dev_dbg(dev,
"%s Type = 0x%x\n", __func__, rom_desc->
Type);
736 ttype = rom_desc->
Type & 0x0f;
740 status = read_rom(serial, start_address +
742 rom_desc->
Size, buffer);
746 status = valid_csum(rom_desc, buffer);
750 start_address = start_address +
sizeof(
struct ti_i2c_desc) +
776 dev_err(dev,
"%s - out of memory\n", __func__);
782 if (!start_address) {
783 dev_dbg(dev,
"%s - Edge Descriptor not found in I2C\n", __func__);
789 status = read_rom(serial, start_address+
sizeof(
struct ti_i2c_desc),
790 rom_desc->
Size, buffer);
794 status = valid_csum(rom_desc, buffer);
821 const char *
fw_name =
"edgeport/down3.bin";
834 buffer_size = (((1024 * 16) - 512 ) +
839 dev_err(dev,
"%s - out of memory\n", __func__);
844 memset(buffer, 0xff, buffer_size);
848 dev_err(dev,
"Failed to load image \"%s\" err %d\n",
855 OperationalMajorVersion = fw->
data[0];
856 OperationalMinorVersion = fw->
data[1];
857 OperationalBuildNumber = fw->
data[2] | (fw->
data[3] << 8);
862 firmware_rec->
Ver_Major = OperationalMajorVersion;
863 firmware_rec->
Ver_Minor = OperationalMinorVersion;
874 for (i=0; i < buffer_size; i++) {
875 cs = (
__u8)(cs + buffer[i]);
887 firmware_rec->
Ver_Major = OperationalMajorVersion;
888 firmware_rec->
Ver_Minor = OperationalMinorVersion;
902 dev_err(dev,
"%s - out of memory\n", __func__);
910 dev_dbg(dev,
"%s - read 2 status error = %d\n", __func__, status);
912 dev_dbg(dev,
"%s - read 2 data = 0x%x\n", __func__, *data);
914 dev_dbg(dev,
"%s - ROM_TYPE_II\n", __func__);
923 dev_dbg(dev,
"%s - read 3 status error = %d\n", __func__, status);
925 dev_dbg(dev,
"%s - read 2 data = 0x%x\n", __func__, *data);
927 dev_dbg(dev,
"%s - ROM_TYPE_III\n", __func__);
932 dev_dbg(dev,
"%s - Unknown\n", __func__);
940 static int bulk_xfer(
struct usb_serial *serial,
void *buffer,
941 int length,
int *num_sent)
946 usb_sndbulkpipe(serial->
dev,
947 serial->
port[0]->bulk_out_endpointAddress),
948 buffer, length, num_sent, 1000);
964 transfer = image_length -
pos;
969 status = bulk_xfer(serial->
serial, &image[pos],
981 static int config_boot_dev(
struct usb_device *dev)
1004 int download_cur_ver;
1005 int download_new_ver;
1016 status = choose_config(serial->
serial->dev);
1020 interface = &serial->
serial->interface->cur_altsetting->desc;
1022 dev_err(dev,
"%s - no interface set, error!\n", __func__);
1043 dev_dbg(dev,
"%s - RUNNING IN DOWNLOAD MODE\n", __func__);
1045 status = check_i2c_image(serial);
1047 dev_dbg(dev,
"%s - DOWNLOAD MODE -- BAD I2C\n", __func__);
1055 if (!ti_manuf_desc) {
1056 dev_err(dev,
"%s - out of memory.\n", __func__);
1059 status = get_manuf_info(serial, (
__u8 *)ti_manuf_desc);
1061 kfree(ti_manuf_desc);
1066 if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
1067 dev_dbg(dev,
"%s - Wrong CPU Rev %d (Must be 2)\n",
1068 __func__, ti_cpu_rev(ti_manuf_desc));
1069 kfree(ti_manuf_desc);
1075 dev_err(dev,
"%s - out of memory.\n", __func__);
1076 kfree(ti_manuf_desc);
1081 start_address = get_descriptor_addr(serial,
1083 if (start_address != 0) {
1087 dev_dbg(dev,
"%s - Found Type FIRMWARE (Type 2) record\n", __func__);
1089 firmware_version =
kmalloc(
sizeof(*firmware_version),
1091 if (!firmware_version) {
1092 dev_err(dev,
"%s - out of memory.\n", __func__);
1094 kfree(ti_manuf_desc);
1101 status = read_rom(serial, start_address +
1104 (
__u8 *)firmware_version);
1106 kfree(firmware_version);
1108 kfree(ti_manuf_desc);
1114 download_cur_ver = (firmware_version->
Ver_Major << 8) +
1116 download_new_ver = (OperationalMajorVersion << 8) +
1117 (OperationalMinorVersion);
1119 dev_dbg(dev,
"%s - >> FW Versions Device %d.%d Driver %d.%d\n",
1122 OperationalMajorVersion,
1123 OperationalMinorVersion);
1127 if (download_cur_ver < download_new_ver) {
1128 dev_dbg(dev,
"%s - Update I2C dld from %d.%d to %d.%d\n",
1132 OperationalMajorVersion,
1133 OperationalMinorVersion);
1137 dev_err(dev,
"%s - out of memory.\n",
1139 kfree(firmware_version);
1141 kfree(ti_manuf_desc);
1160 status = write_rom(serial, start_address,
1161 sizeof(*record), record);
1164 kfree(firmware_version);
1166 kfree(ti_manuf_desc);
1174 status = read_rom(serial,
1180 kfree(firmware_version);
1182 kfree(ti_manuf_desc);
1187 dev_err(dev,
"%s - error resetting device\n", __func__);
1189 kfree(firmware_version);
1191 kfree(ti_manuf_desc);
1195 dev_dbg(dev,
"%s - HARDWARE RESET\n", __func__);
1198 status = ti_vsend_sync(serial->
serial->dev,
1202 dev_dbg(dev,
"%s - HARDWARE RESET return %d\n", __func__, status);
1206 kfree(firmware_version);
1208 kfree(ti_manuf_desc);
1211 kfree(firmware_version);
1215 #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + \
1216 sizeof(struct ti_i2c_firmware_rec))
1222 dev_err(dev,
"%s - out of memory.\n", __func__);
1224 kfree(ti_manuf_desc);
1230 dev_err(dev,
"%s - out of memory.\n", __func__);
1233 kfree(ti_manuf_desc);
1237 dev_dbg(dev,
"%s - Found Type BLANK FIRMWARE (Type F2) record\n", __func__);
1250 status = build_i2c_fw_hdr(header, dev);
1255 kfree(ti_manuf_desc);
1261 status = write_rom(serial,
1269 kfree(ti_manuf_desc);
1275 status = read_rom(serial, start_address,
1276 HEADER_SIZE, vheader);
1279 dev_dbg(dev,
"%s - can't read header back\n", __func__);
1283 kfree(ti_manuf_desc);
1286 if (
memcmp(vheader, header, HEADER_SIZE)) {
1287 dev_dbg(dev,
"%s - write download record failed\n", __func__);
1291 kfree(ti_manuf_desc);
1298 dev_dbg(dev,
"%s - Start firmware update\n", __func__);
1301 status = ti_vsend_sync(serial->
serial->dev,
1304 dev_dbg(dev,
"%s - Update complete 0x%x\n", __func__, status);
1307 "%s - UMPC_COPY_DNLD_TO_I2C failed\n",
1310 kfree(ti_manuf_desc);
1317 kfree(ti_manuf_desc);
1324 dev_dbg(dev,
"%s - RUNNING IN BOOT MODE\n", __func__);
1327 status = config_boot_dev(serial->
serial->dev);
1333 dev_dbg(dev,
"%s - VID = 0x%x\n", __func__,
1336 goto stayinbootmode;
1341 if (i2c_type_bootmode(serial))
1342 goto stayinbootmode;
1345 if (!check_i2c_image(serial)) {
1353 const char *fw_name =
"edgeport/down3.bin";
1359 if (!ti_manuf_desc) {
1360 dev_err(dev,
"%s - out of memory.\n", __func__);
1363 status = get_manuf_info(serial, (
__u8 *)ti_manuf_desc);
1365 kfree(ti_manuf_desc);
1366 goto stayinbootmode;
1370 if (!ignore_cpu_rev && ti_cpu_rev(ti_manuf_desc) < 2) {
1371 dev_dbg(dev,
"%s - Wrong CPU Rev %d (Must be 2)\n",
1372 __func__, ti_cpu_rev(ti_manuf_desc));
1373 kfree(ti_manuf_desc);
1374 goto stayinbootmode;
1377 kfree(ti_manuf_desc);
1394 buffer_size = (((1024 * 16) - 512) +
1398 dev_err(dev,
"%s - out of memory\n", __func__);
1403 memset(buffer, 0xff, buffer_size);
1407 dev_err(dev,
"Failed to load image \"%s\" err %d\n",
1416 i < buffer_size; i++) {
1417 cs = (
__u8)(cs + buffer[i]);
1428 dev_dbg(dev,
"%s - Downloading operational code image (TI UMP)\n", __func__);
1429 status = download_code(serial, buffer, buffer_size);
1434 dev_dbg(dev,
"%s - Error downloading operational code image\n", __func__);
1441 dev_dbg(dev,
"%s - Download successful -- Device rebooting...\n", __func__);
1449 dev_dbg(dev,
"%s - STAYING IN BOOT MODE\n", __func__);
1460 return send_cmd(port->
port->serial->dev,
1470 dev_dbg(&port->
port->dev,
"%s - %x\n", __func__, mcr);
1482 static __u8 map_line_status(
__u8 ti_lsr)
1486 #define MAP_FLAG(flagUmp, flagUart) \
1487 if (ti_lsr & flagUmp) \
1507 dev_dbg(&edge_port->
port->dev,
"%s - %02x\n", __func__, msr);
1511 icount = &edge_port->
icount;
1541 static void handle_new_lsr(
struct edgeport_port *edge_port,
int lsr_data,
1549 dev_dbg(&edge_port->
port->dev,
"%s - %02x\n", __func__, new_lsr);
1564 edge_tty_recv(&edge_port->
port->dev, tty, &data, 1);
1570 icount = &edge_port->
icount;
1571 if (new_lsr & LSR_BREAK)
1582 static void edge_interrupt_callback(
struct urb *
urb)
1588 unsigned char *data = urb->transfer_buffer;
1589 int length = urb->actual_length;
1595 int status = urb->status;
1605 dev_dbg(&urb->dev->dev,
"%s - urb shutting down with status: %d\n",
1609 dev_err(&urb->dev->dev,
"%s - nonzero urb status received: "
1610 "%d\n", __func__, status);
1615 dev_dbg(&urb->dev->dev,
"%s - no data in urb\n", __func__);
1619 dev = &edge_serial->
serial->dev->dev;
1620 usb_serial_debug_data(dev, __func__, length, data);
1623 dev_dbg(dev,
"%s - expecting packet of size 2, got %d\n", __func__, length);
1629 dev_dbg(dev,
"%s - port_number %d, function %d, info 0x%x\n", __func__,
1630 port_number,
function, data[1]);
1632 edge_port = usb_get_serial_port_data(port);
1634 dev_dbg(dev,
"%s - edge_port not found\n", __func__);
1639 lsr = map_line_status(data[1]);
1643 dev_dbg(dev,
"%s - LSR Event Port %u LSR Status = %02x\n",
1644 __func__, port_number, lsr);
1648 dev_dbg(dev,
"%s - ===== Port %d LSR Status = %02x ======\n",
1649 __func__, port_number, lsr);
1650 handle_new_lsr(edge_port, 0, lsr, 0);
1657 dev_dbg(dev,
"%s - ===== Port %u MSR Status = %02x ======\n",
1658 __func__, port_number, msr);
1659 handle_new_msr(edge_port, msr);
1664 "%s - Unknown Interrupt code from UMP %x\n",
1674 "%s - usb_submit_urb failed with result %d\n",
1678 static void edge_bulk_in_callback(
struct urb *urb)
1682 unsigned char *data = urb->transfer_buffer;
1686 int status = urb->status;
1696 dev_dbg(&urb->dev->dev,
"%s - urb shutting down with status: %d\n", __func__, status);
1699 dev_err(&urb->dev->dev,
"%s - nonzero read bulk status received: %d\n", __func__, status);
1702 if (status == -
EPIPE)
1706 dev_err(&urb->dev->dev,
"%s - stopping read!\n", __func__);
1710 port_number = edge_port->
port->number - edge_port->
port->serial->minor;
1714 dev_dbg(dev,
"%s ===== Port %u LSR Status = %02x, Data = %02x ======\n",
1715 __func__, port_number, edge_port->
lsr_mask, *data);
1716 handle_new_lsr(edge_port, 1, edge_port->
lsr_mask, *data);
1718 --urb->actual_length;
1723 if (tty && urb->actual_length) {
1724 usb_serial_debug_data(dev, __func__, urb->actual_length, data);
1726 dev_dbg(dev,
"%s - close pending, dropping data on the floor\n",
1729 edge_tty_recv(dev, tty, data, urb->actual_length);
1730 edge_port->
icount.rx += urb->actual_length;
1736 spin_lock(&edge_port->
ep_lock);
1742 spin_unlock(&edge_port->
ep_lock);
1744 dev_err(dev,
"%s - usb_submit_urb failed with result %d\n", __func__, retval);
1748 unsigned char *data,
int length)
1752 queued = tty_insert_flip_string(tty, data, length);
1753 if (queued < length)
1754 dev_err(dev,
"%s - dropping data, %d bytes lost\n",
1755 __func__, length - queued);
1759 static void edge_bulk_out_callback(
struct urb *urb)
1762 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1763 int status = urb->status;
1776 dev_dbg(&urb->dev->dev,
"%s - urb shutting down with status: %d\n",
1781 "received: %d\n", __func__, status);
1792 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1794 struct usb_device *
dev;
1799 u8 transaction_timeout;
1801 if (edge_port ==
NULL)
1805 switch (port_number) {
1815 dev_err(&port->
dev,
"Unknown port number!!!\n");
1819 dev_dbg(&port->
dev,
"%s - port_number = %d, uart_base = %04x, dma_address = %04x\n",
1831 "%s - cannot send clear loopback command, %d\n",
1838 edge_set_termios(tty, port, &tty->termios);
1843 transaction_timeout = 2;
1846 max(20, ((transaction_timeout * 3) / 2));
1851 (transaction_timeout << 2));
1853 dev_dbg(&port->
dev,
"%s - Sending UMPC_OPEN_PORT\n", __func__);
1859 dev_err(&port->
dev,
"%s - cannot send open command, %d\n",
1868 dev_err(&port->
dev,
"%s - cannot send start DMA command, %d\n",
1877 "%s - cannot send clear buffers command, %d\n",
1887 dev_err(&port->
dev,
"%s - cannot send read MSR command, %d\n",
1903 urb = edge_serial->
serial->port[0]->interrupt_in_urb;
1906 "%s - no interrupt urb present, exiting\n",
1909 goto release_es_lock;
1911 urb->context = edge_serial;
1915 "%s - usb_submit_urb failed with value %d\n",
1917 goto release_es_lock;
1931 dev_err(&port->
dev,
"%s - no read urb present, exiting\n",
1934 goto unlink_int_urb;
1937 urb->context = edge_port;
1941 "%s - read bulk usb_submit_urb failed with value %d\n",
1943 goto unlink_int_urb;
1948 goto release_es_lock;
1965 edge_serial = usb_get_serial_data(port->
serial);
1966 edge_port = usb_get_serial_port_data(port);
1967 if (edge_serial ==
NULL || edge_port ==
NULL)
1975 chase_port(edge_port, (
HZ * closing_wait) / 100, 1);
1983 dev_dbg(&port->
dev,
"%s - send umpc_close_port\n", __func__);
1988 send_cmd(serial->
dev,
1999 if (edge_port->
edge_serial->num_ports_open <= 0) {
2009 const unsigned char *data,
int count)
2011 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2014 dev_dbg(&port->
dev,
"%s - write request of 0 bytes\n", __func__);
2018 if (edge_port ==
NULL)
2030 static void edge_send(
struct tty_struct *tty)
2034 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2035 unsigned long flags;
2040 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
2049 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
2055 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
2057 usb_serial_debug_data(&port->
dev, __func__, count, port->
write_urb->transfer_buffer);
2066 "%s - failed submitting write urb, error %d\n",
2079 static int edge_write_room(
struct tty_struct *tty)
2082 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2084 unsigned long flags;
2086 if (edge_port ==
NULL)
2093 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
2095 dev_dbg(&port->
dev,
"%s - returns %d\n", __func__, room);
2099 static int edge_chars_in_buffer(
struct tty_struct *tty)
2102 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2104 unsigned long flags;
2106 if (edge_port ==
NULL)
2113 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
2115 dev_dbg(&port->
dev,
"%s - returns %d\n", __func__, chars);
2119 static void edge_throttle(
struct tty_struct *tty)
2122 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2125 if (edge_port ==
NULL)
2130 unsigned char stop_char =
STOP_CHAR(tty);
2131 status = edge_write(tty, port, &stop_char, 1);
2133 dev_err(&port->
dev,
"%s - failed to write stop character, %d\n", __func__, status);
2140 stop_read(edge_port);
2144 static void edge_unthrottle(
struct tty_struct *tty)
2147 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2150 if (edge_port ==
NULL)
2156 status = edge_write(tty, port, &start_char, 1);
2158 dev_err(&port->
dev,
"%s - failed to write start character, %d\n", __func__, status);
2164 status = restart_read(edge_port);
2167 "%s - read bulk usb_submit_urb failed: %d\n",
2175 unsigned long flags;
2183 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
2190 unsigned long flags;
2195 urb = edge_port->
port->read_urb;
2201 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
2206 static void change_port_settings(
struct tty_struct *tty,
2214 int port_number = edge_port->
port->number -
2215 edge_port->
port->serial->minor;
2217 dev_dbg(dev,
"%s - port %d\n", __func__, edge_port->
port->number);
2221 tty->termios = *old_termios;
2222 dev_err(dev,
"%s - out of memory\n", __func__);
2226 cflag = tty->termios.c_cflag;
2235 switch (cflag &
CSIZE) {
2238 dev_dbg(dev,
"%s - data bits = 5\n", __func__);
2242 dev_dbg(dev,
"%s - data bits = 6\n", __func__);
2246 dev_dbg(dev,
"%s - data bits = 7\n", __func__);
2251 dev_dbg(dev,
"%s - data bits = 8\n", __func__);
2259 dev_dbg(dev,
"%s - parity = odd\n", __func__);
2263 dev_dbg(dev,
"%s - parity = even\n", __func__);
2267 dev_dbg(dev,
"%s - parity = none\n", __func__);
2272 dev_dbg(dev,
"%s - stop bits = 2\n", __func__);
2275 dev_dbg(dev,
"%s - stop bits = 1\n", __func__);
2282 dev_dbg(dev,
"%s - RTS/CTS is enabled\n", __func__);
2284 dev_dbg(dev,
"%s - RTS/CTS is disabled\n", __func__);
2286 restart_read(edge_port);
2297 dev_dbg(dev,
"%s - INBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
2300 dev_dbg(dev,
"%s - INBOUND XON/XOFF is disabled\n", __func__);
2305 dev_dbg(dev,
"%s - OUTBOUND XON/XOFF is enabled, XON = %2x, XOFF = %2x\n",
2308 dev_dbg(dev,
"%s - OUTBOUND XON/XOFF is disabled\n", __func__);
2310 tty->termios.c_cflag &= ~
CMSPAR;
2325 dev_dbg(dev,
"%s - baud rate = %d, wBaudRate = %d\n", __func__, baud, config->
wBaudRate);
2342 0, (
__u8 *)config,
sizeof(*config));
2344 dev_dbg(dev,
"%s - error %d when trying to write config to device\n",
2349 static void edge_set_termios(
struct tty_struct *tty,
2352 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2355 cflag = tty->termios.c_cflag;
2357 dev_dbg(&port->
dev,
"%s - clfag %08x iflag %08x\n", __func__,
2358 tty->termios.c_cflag, tty->termios.c_iflag);
2359 dev_dbg(&port->
dev,
"%s - old clfag %08x old iflag %08x\n", __func__,
2363 if (edge_port ==
NULL)
2366 change_port_settings(tty, edge_port, old_termios);
2369 static int edge_tiocmset(
struct tty_struct *tty,
2370 unsigned int set,
unsigned int clear)
2373 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2375 unsigned long flags;
2394 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
2396 restore_mcr(edge_port, mcr);
2400 static int edge_tiocmget(
struct tty_struct *tty)
2403 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2404 unsigned int result = 0;
2407 unsigned long flags;
2413 result = ((mcr &
MCR_DTR) ? TIOCM_DTR: 0)
2414 | ((mcr &
MCR_RTS) ? TIOCM_RTS: 0)
2421 dev_dbg(&port->
dev,
"%s -- %x\n", __func__, result);
2422 spin_unlock_irqrestore(&edge_port->
ep_lock, flags);
2427 static int edge_get_icount(
struct tty_struct *tty,
2431 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2438 icount->
tx = ic->
tx;
2439 icount->
rx = ic->
rx;
2459 tmp.line = edge_port->
port->serial->minor;
2460 tmp.port = edge_port->
port->number;
2463 tmp.xmit_fifo_size = edge_port->
port->bulk_out_size;
2464 tmp.baud_base = 9600;
2465 tmp.close_delay = 5*
HZ;
2473 static int edge_ioctl(
struct tty_struct *tty,
2474 unsigned int cmd,
unsigned long arg)
2477 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2481 dev_dbg(&port->
dev,
"%s - port %d, cmd = 0x%x\n", __func__, port->
number, cmd);
2485 dev_dbg(&port->
dev,
"%s - TIOCGSERIAL\n", __func__);
2486 return get_serial_info(edge_port,
2489 dev_dbg(&port->
dev,
"%s - TIOCMIWAIT\n", __func__);
2490 cprev = edge_port->
icount;
2496 cnow = edge_port->
icount;
2497 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2498 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2500 if (((arg &
TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2501 ((arg &
TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2502 ((arg &
TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2503 ((arg &
TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2514 static void edge_break(
struct tty_struct *tty,
int break_state)
2517 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2522 chase_port(edge_port, 0, 0);
2524 if (break_state == -1)
2528 dev_dbg(&port->
dev,
"%s - error %d sending break set/clear command.\n",
2532 static int edge_startup(
struct usb_serial *serial)
2539 if (edge_serial ==
NULL) {
2540 dev_err(&serial->
dev->dev,
"%s - Out of memory\n", __func__);
2545 usb_set_serial_data(serial, edge_serial);
2547 status = download_fw(edge_serial);
2556 static void edge_disconnect(
struct usb_serial *serial)
2560 static void edge_release(
struct usb_serial *serial)
2562 kfree(usb_get_serial_data(serial));
2570 edge_port = kzalloc(
sizeof(*edge_port),
GFP_KERNEL);
2584 edge_port->
bUartMode = default_uart_mode;
2586 usb_set_serial_port_data(port, edge_port);
2588 ret = edge_create_sysfs_attrs(port);
2602 edge_port = usb_get_serial_port_data(port);
2604 edge_remove_sysfs_attrs(port);
2617 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2626 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2629 dev_dbg(dev,
"%s: setting uart_mode = %d\n", __func__, v);
2634 dev_err(dev,
"%s - uart_mode %d is invalid\n", __func__, v);
2657 .name =
"edgeport_ti_1",
2659 .description =
"Edgeport TI 1 port adapter",
2660 .id_table = edgeport_1port_id_table,
2663 .close = edge_close,
2664 .throttle = edge_throttle,
2665 .unthrottle = edge_unthrottle,
2666 .attach = edge_startup,
2667 .disconnect = edge_disconnect,
2668 .release = edge_release,
2669 .port_probe = edge_port_probe,
2670 .port_remove = edge_port_remove,
2671 .ioctl = edge_ioctl,
2672 .set_termios = edge_set_termios,
2673 .tiocmget = edge_tiocmget,
2674 .tiocmset = edge_tiocmset,
2675 .get_icount = edge_get_icount,
2676 .write = edge_write,
2677 .write_room = edge_write_room,
2678 .chars_in_buffer = edge_chars_in_buffer,
2679 .break_ctl = edge_break,
2680 .read_int_callback = edge_interrupt_callback,
2681 .read_bulk_callback = edge_bulk_in_callback,
2682 .write_bulk_callback = edge_bulk_out_callback,
2688 .name =
"edgeport_ti_2",
2690 .description =
"Edgeport TI 2 port adapter",
2691 .id_table = edgeport_2port_id_table,
2694 .close = edge_close,
2695 .throttle = edge_throttle,
2696 .unthrottle = edge_unthrottle,
2697 .attach = edge_startup,
2698 .disconnect = edge_disconnect,
2699 .release = edge_release,
2700 .port_probe = edge_port_probe,
2701 .port_remove = edge_port_remove,
2702 .ioctl = edge_ioctl,
2703 .set_termios = edge_set_termios,
2704 .tiocmget = edge_tiocmget,
2705 .tiocmset = edge_tiocmset,
2706 .write = edge_write,
2707 .write_room = edge_write_room,
2708 .chars_in_buffer = edge_chars_in_buffer,
2709 .break_ctl = edge_break,
2710 .read_int_callback = edge_interrupt_callback,
2711 .read_bulk_callback = edge_bulk_in_callback,
2712 .write_bulk_callback = edge_bulk_out_callback,
2716 &edgeport_1port_device, &edgeport_2port_device,
NULL
2727 MODULE_PARM_DESC(closing_wait,
"Maximum wait for data to drain, in .01 secs");
2731 "Ignore the cpu revision when connecting to a device");