diff options
Diffstat (limited to 'drivers/usb/serial/io_ti.c')
-rw-r--r-- | drivers/usb/serial/io_ti.c | 89 |
1 files changed, 22 insertions, 67 deletions
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index 82afc4d6a327..641ab3da2d83 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c | |||
@@ -521,65 +521,6 @@ exit_is_tx_active: | |||
521 | return bytes_left; | 521 | return bytes_left; |
522 | } | 522 | } |
523 | 523 | ||
524 | static void chase_port(struct edgeport_port *port, unsigned long timeout, | ||
525 | int flush) | ||
526 | { | ||
527 | int baud_rate; | ||
528 | struct tty_struct *tty = tty_port_tty_get(&port->port->port); | ||
529 | struct usb_serial *serial = port->port->serial; | ||
530 | wait_queue_t wait; | ||
531 | unsigned long flags; | ||
532 | |||
533 | if (!tty) | ||
534 | return; | ||
535 | |||
536 | if (!timeout) | ||
537 | timeout = (HZ * EDGE_CLOSING_WAIT)/100; | ||
538 | |||
539 | /* wait for data to drain from the buffer */ | ||
540 | spin_lock_irqsave(&port->ep_lock, flags); | ||
541 | init_waitqueue_entry(&wait, current); | ||
542 | add_wait_queue(&tty->write_wait, &wait); | ||
543 | for (;;) { | ||
544 | set_current_state(TASK_INTERRUPTIBLE); | ||
545 | if (kfifo_len(&port->write_fifo) == 0 | ||
546 | || timeout == 0 || signal_pending(current) | ||
547 | || serial->disconnected) | ||
548 | /* disconnect */ | ||
549 | break; | ||
550 | spin_unlock_irqrestore(&port->ep_lock, flags); | ||
551 | timeout = schedule_timeout(timeout); | ||
552 | spin_lock_irqsave(&port->ep_lock, flags); | ||
553 | } | ||
554 | set_current_state(TASK_RUNNING); | ||
555 | remove_wait_queue(&tty->write_wait, &wait); | ||
556 | if (flush) | ||
557 | kfifo_reset_out(&port->write_fifo); | ||
558 | spin_unlock_irqrestore(&port->ep_lock, flags); | ||
559 | tty_kref_put(tty); | ||
560 | |||
561 | /* wait for data to drain from the device */ | ||
562 | timeout += jiffies; | ||
563 | while ((long)(jiffies - timeout) < 0 && !signal_pending(current) | ||
564 | && !serial->disconnected) { | ||
565 | /* not disconnected */ | ||
566 | if (!tx_active(port)) | ||
567 | break; | ||
568 | msleep(10); | ||
569 | } | ||
570 | |||
571 | /* disconnected */ | ||
572 | if (serial->disconnected) | ||
573 | return; | ||
574 | |||
575 | /* wait one more character time, based on baud rate */ | ||
576 | /* (tx_active doesn't seem to wait for the last byte) */ | ||
577 | baud_rate = port->baud_rate; | ||
578 | if (baud_rate == 0) | ||
579 | baud_rate = 50; | ||
580 | msleep(max(1, DIV_ROUND_UP(10000, baud_rate))); | ||
581 | } | ||
582 | |||
583 | static int choose_config(struct usb_device *dev) | 524 | static int choose_config(struct usb_device *dev) |
584 | { | 525 | { |
585 | /* | 526 | /* |
@@ -1944,6 +1885,8 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
1944 | 1885 | ||
1945 | ++edge_serial->num_ports_open; | 1886 | ++edge_serial->num_ports_open; |
1946 | 1887 | ||
1888 | port->port.drain_delay = 1; | ||
1889 | |||
1947 | goto release_es_lock; | 1890 | goto release_es_lock; |
1948 | 1891 | ||
1949 | unlink_int_urb: | 1892 | unlink_int_urb: |
@@ -1959,6 +1902,7 @@ static void edge_close(struct usb_serial_port *port) | |||
1959 | struct edgeport_serial *edge_serial; | 1902 | struct edgeport_serial *edge_serial; |
1960 | struct edgeport_port *edge_port; | 1903 | struct edgeport_port *edge_port; |
1961 | struct usb_serial *serial = port->serial; | 1904 | struct usb_serial *serial = port->serial; |
1905 | unsigned long flags; | ||
1962 | int port_number; | 1906 | int port_number; |
1963 | 1907 | ||
1964 | edge_serial = usb_get_serial_data(port->serial); | 1908 | edge_serial = usb_get_serial_data(port->serial); |
@@ -1970,12 +1914,12 @@ static void edge_close(struct usb_serial_port *port) | |||
1970 | * this flag and dump add read data */ | 1914 | * this flag and dump add read data */ |
1971 | edge_port->close_pending = 1; | 1915 | edge_port->close_pending = 1; |
1972 | 1916 | ||
1973 | /* chase the port close and flush */ | ||
1974 | chase_port(edge_port, (HZ * closing_wait) / 100, 1); | ||
1975 | |||
1976 | usb_kill_urb(port->read_urb); | 1917 | usb_kill_urb(port->read_urb); |
1977 | usb_kill_urb(port->write_urb); | 1918 | usb_kill_urb(port->write_urb); |
1978 | edge_port->ep_write_urb_in_use = 0; | 1919 | edge_port->ep_write_urb_in_use = 0; |
1920 | spin_lock_irqsave(&edge_port->ep_lock, flags); | ||
1921 | kfifo_reset_out(&edge_port->write_fifo); | ||
1922 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | ||
1979 | 1923 | ||
1980 | /* assuming we can still talk to the device, | 1924 | /* assuming we can still talk to the device, |
1981 | * send a close port command to it */ | 1925 | * send a close port command to it */ |
@@ -2101,16 +2045,21 @@ static int edge_chars_in_buffer(struct tty_struct *tty) | |||
2101 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); | 2045 | struct edgeport_port *edge_port = usb_get_serial_port_data(port); |
2102 | int chars = 0; | 2046 | int chars = 0; |
2103 | unsigned long flags; | 2047 | unsigned long flags; |
2048 | int ret; | ||
2104 | 2049 | ||
2105 | if (edge_port == NULL) | 2050 | if (edge_port == NULL) |
2106 | return 0; | 2051 | return 0; |
2107 | if (edge_port->close_pending == 1) | ||
2108 | return 0; | ||
2109 | 2052 | ||
2110 | spin_lock_irqsave(&edge_port->ep_lock, flags); | 2053 | spin_lock_irqsave(&edge_port->ep_lock, flags); |
2111 | chars = kfifo_len(&edge_port->write_fifo); | 2054 | chars = kfifo_len(&edge_port->write_fifo); |
2112 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); | 2055 | spin_unlock_irqrestore(&edge_port->ep_lock, flags); |
2113 | 2056 | ||
2057 | if (!chars) { | ||
2058 | ret = tx_active(edge_port); | ||
2059 | if (ret > 0) | ||
2060 | chars = ret; | ||
2061 | } | ||
2062 | |||
2114 | dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); | 2063 | dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); |
2115 | return chars; | 2064 | return chars; |
2116 | } | 2065 | } |
@@ -2448,10 +2397,15 @@ static int get_serial_info(struct edgeport_port *edge_port, | |||
2448 | struct serial_struct __user *retinfo) | 2397 | struct serial_struct __user *retinfo) |
2449 | { | 2398 | { |
2450 | struct serial_struct tmp; | 2399 | struct serial_struct tmp; |
2400 | unsigned cwait; | ||
2451 | 2401 | ||
2452 | if (!retinfo) | 2402 | if (!retinfo) |
2453 | return -EFAULT; | 2403 | return -EFAULT; |
2454 | 2404 | ||
2405 | cwait = edge_port->port->port.closing_wait; | ||
2406 | if (cwait != ASYNC_CLOSING_WAIT_NONE) | ||
2407 | cwait = jiffies_to_msecs(closing_wait) / 10; | ||
2408 | |||
2455 | memset(&tmp, 0, sizeof(tmp)); | 2409 | memset(&tmp, 0, sizeof(tmp)); |
2456 | 2410 | ||
2457 | tmp.type = PORT_16550A; | 2411 | tmp.type = PORT_16550A; |
@@ -2462,7 +2416,7 @@ static int get_serial_info(struct edgeport_port *edge_port, | |||
2462 | tmp.xmit_fifo_size = edge_port->port->bulk_out_size; | 2416 | tmp.xmit_fifo_size = edge_port->port->bulk_out_size; |
2463 | tmp.baud_base = 9600; | 2417 | tmp.baud_base = 9600; |
2464 | tmp.close_delay = 5*HZ; | 2418 | tmp.close_delay = 5*HZ; |
2465 | tmp.closing_wait = closing_wait; | 2419 | tmp.closing_wait = cwait; |
2466 | 2420 | ||
2467 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) | 2421 | if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
2468 | return -EFAULT; | 2422 | return -EFAULT; |
@@ -2517,8 +2471,7 @@ static void edge_break(struct tty_struct *tty, int break_state) | |||
2517 | int status; | 2471 | int status; |
2518 | int bv = 0; /* Off */ | 2472 | int bv = 0; /* Off */ |
2519 | 2473 | ||
2520 | /* chase the port close */ | 2474 | tty_wait_until_sent(tty, 0); |
2521 | chase_port(edge_port, 0, 0); | ||
2522 | 2475 | ||
2523 | if (break_state == -1) | 2476 | if (break_state == -1) |
2524 | bv = 1; /* On */ | 2477 | bv = 1; /* On */ |
@@ -2591,6 +2544,8 @@ static int edge_port_probe(struct usb_serial_port *port) | |||
2591 | return ret; | 2544 | return ret; |
2592 | } | 2545 | } |
2593 | 2546 | ||
2547 | port->port.closing_wait = msecs_to_jiffies(closing_wait * 10); | ||
2548 | |||
2594 | return 0; | 2549 | return 0; |
2595 | } | 2550 | } |
2596 | 2551 | ||