aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/digi_acceleport.c
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-07-22 06:11:02 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-22 16:03:23 -0400
commit41ad427da1f9303e2e34811398b31c999c3d39d1 (patch)
tree8c956a0c1df0b9eccd7c110f547d89ce1eb25919 /drivers/usb/serial/digi_acceleport.c
parent77336828c01933d37102c4bef6e2a2cf7e3243b3 (diff)
digi_acceleport: coding style
Code tidy Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/usb/serial/digi_acceleport.c')
-rw-r--r--drivers/usb/serial/digi_acceleport.c344
1 files changed, 184 insertions, 160 deletions
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index dc92dbfc962e..240aad1acaab 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -241,7 +241,7 @@
241#include <linux/module.h> 241#include <linux/module.h>
242#include <linux/spinlock.h> 242#include <linux/spinlock.h>
243#include <linux/workqueue.h> 243#include <linux/workqueue.h>
244#include <asm/uaccess.h> 244#include <linux/uaccess.h>
245#include <linux/usb.h> 245#include <linux/usb.h>
246#include <linux/wait.h> 246#include <linux/wait.h>
247#include <linux/usb/serial.h> 247#include <linux/usb/serial.h>
@@ -441,8 +441,8 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
441 unsigned int modem_signals, int interruptible); 441 unsigned int modem_signals, int interruptible);
442static int digi_transmit_idle(struct usb_serial_port *port, 442static int digi_transmit_idle(struct usb_serial_port *port,
443 unsigned long timeout); 443 unsigned long timeout);
444static void digi_rx_throttle (struct tty_struct *tty); 444static void digi_rx_throttle(struct tty_struct *tty);
445static void digi_rx_unthrottle (struct tty_struct *tty); 445static void digi_rx_unthrottle(struct tty_struct *tty);
446static void digi_set_termios(struct tty_struct *tty, 446static void digi_set_termios(struct tty_struct *tty,
447 struct usb_serial_port *port, struct ktermios *old_termios); 447 struct usb_serial_port *port, struct ktermios *old_termios);
448static void digi_break_ctl(struct tty_struct *tty, int break_state); 448static void digi_break_ctl(struct tty_struct *tty, int break_state);
@@ -486,7 +486,7 @@ static struct usb_device_id id_table_4 [] = {
486 { } /* Terminating entry */ 486 { } /* Terminating entry */
487}; 487};
488 488
489MODULE_DEVICE_TABLE (usb, id_table_combined); 489MODULE_DEVICE_TABLE(usb, id_table_combined);
490 490
491static struct usb_driver digi_driver = { 491static struct usb_driver digi_driver = {
492 .name = "digi_acceleport", 492 .name = "digi_acceleport",
@@ -555,17 +555,17 @@ static struct usb_serial_driver digi_acceleport_4_device = {
555/* Functions */ 555/* Functions */
556 556
557/* 557/*
558* Cond Wait Interruptible Timeout Irqrestore 558 * Cond Wait Interruptible Timeout Irqrestore
559* 559 *
560* Do spin_unlock_irqrestore and interruptible_sleep_on_timeout 560 * Do spin_unlock_irqrestore and interruptible_sleep_on_timeout
561* so that wake ups are not lost if they occur between the unlock 561 * so that wake ups are not lost if they occur between the unlock
562* and the sleep. In other words, spin_unlock_irqrestore and 562 * and the sleep. In other words, spin_unlock_irqrestore and
563* interruptible_sleep_on_timeout are "atomic" with respect to 563 * interruptible_sleep_on_timeout are "atomic" with respect to
564* wake ups. This is used to implement condition variables. 564 * wake ups. This is used to implement condition variables.
565* 565 *
566* interruptible_sleep_on_timeout is deprecated and has been replaced 566 * interruptible_sleep_on_timeout is deprecated and has been replaced
567* with the equivalent code. 567 * with the equivalent code.
568*/ 568 */
569 569
570static long cond_wait_interruptible_timeout_irqrestore( 570static long cond_wait_interruptible_timeout_irqrestore(
571 wait_queue_head_t *q, long timeout, 571 wait_queue_head_t *q, long timeout,
@@ -584,15 +584,16 @@ __releases(lock)
584 584
585 585
586/* 586/*
587* Digi Wakeup Write 587 * Digi Wakeup Write
588* 588 *
589* Wake up port, line discipline, and tty processes sleeping 589 * Wake up port, line discipline, and tty processes sleeping
590* on writes. 590 * on writes.
591*/ 591 */
592 592
593static void digi_wakeup_write_lock(struct work_struct *work) 593static void digi_wakeup_write_lock(struct work_struct *work)
594{ 594{
595 struct digi_port *priv = container_of(work, struct digi_port, dp_wakeup_work); 595 struct digi_port *priv =
596 container_of(work, struct digi_port, dp_wakeup_work);
596 struct usb_serial_port *port = priv->dp_port; 597 struct usb_serial_port *port = priv->dp_port;
597 unsigned long flags; 598 unsigned long flags;
598 599
@@ -608,15 +609,15 @@ static void digi_wakeup_write(struct usb_serial_port *port)
608 609
609 610
610/* 611/*
611* Digi Write OOB Command 612 * Digi Write OOB Command
612* 613 *
613* Write commands on the out of band port. Commands are 4 614 * Write commands on the out of band port. Commands are 4
614* bytes each, multiple commands can be sent at once, and 615 * bytes each, multiple commands can be sent at once, and
615* no command will be split across USB packets. Returns 0 616 * no command will be split across USB packets. Returns 0
616* if successful, -EINTR if interrupted while sleeping and 617 * if successful, -EINTR if interrupted while sleeping and
617* the interruptible flag is true, or a negative error 618 * the interruptible flag is true, or a negative error
618* returned by usb_submit_urb. 619 * returned by usb_submit_urb.
619*/ 620 */
620 621
621static int digi_write_oob_command(struct usb_serial_port *port, 622static int digi_write_oob_command(struct usb_serial_port *port,
622 unsigned char *buf, int count, int interruptible) 623 unsigned char *buf, int count, int interruptible)
@@ -631,8 +632,8 @@ static int digi_write_oob_command(struct usb_serial_port *port,
631 dbg("digi_write_oob_command: TOP: port=%d, count=%d", oob_priv->dp_port_num, count); 632 dbg("digi_write_oob_command: TOP: port=%d, count=%d", oob_priv->dp_port_num, count);
632 633
633 spin_lock_irqsave(&oob_priv->dp_port_lock, flags); 634 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
634 while(count > 0) { 635 while (count > 0) {
635 while(oob_port->write_urb->status == -EINPROGRESS 636 while (oob_port->write_urb->status == -EINPROGRESS
636 || oob_priv->dp_write_urb_in_use) { 637 || oob_priv->dp_write_urb_in_use) {
637 cond_wait_interruptible_timeout_irqrestore( 638 cond_wait_interruptible_timeout_irqrestore(
638 &oob_port->write_wait, DIGI_RETRY_TIMEOUT, 639 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
@@ -649,7 +650,8 @@ static int digi_write_oob_command(struct usb_serial_port *port,
649 memcpy(oob_port->write_urb->transfer_buffer, buf, len); 650 memcpy(oob_port->write_urb->transfer_buffer, buf, len);
650 oob_port->write_urb->transfer_buffer_length = len; 651 oob_port->write_urb->transfer_buffer_length = len;
651 oob_port->write_urb->dev = port->serial->dev; 652 oob_port->write_urb->dev = port->serial->dev;
652 if ((ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC)) == 0) { 653 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
654 if (ret == 0) {
653 oob_priv->dp_write_urb_in_use = 1; 655 oob_priv->dp_write_urb_in_use = 1;
654 count -= len; 656 count -= len;
655 buf += len; 657 buf += len;
@@ -664,16 +666,16 @@ static int digi_write_oob_command(struct usb_serial_port *port,
664 666
665 667
666/* 668/*
667* Digi Write In Band Command 669 * Digi Write In Band Command
668* 670 *
669* Write commands on the given port. Commands are 4 671 * Write commands on the given port. Commands are 4
670* bytes each, multiple commands can be sent at once, and 672 * bytes each, multiple commands can be sent at once, and
671* no command will be split across USB packets. If timeout 673 * no command will be split across USB packets. If timeout
672* is non-zero, write in band command will return after 674 * is non-zero, write in band command will return after
673* waiting unsuccessfully for the URB status to clear for 675 * waiting unsuccessfully for the URB status to clear for
674* timeout ticks. Returns 0 if successful, or a negative 676 * timeout ticks. Returns 0 if successful, or a negative
675* error returned by digi_write. 677 * error returned by digi_write.
676*/ 678 */
677 679
678static int digi_write_inb_command(struct usb_serial_port *port, 680static int digi_write_inb_command(struct usb_serial_port *port,
679 unsigned char *buf, int count, unsigned long timeout) 681 unsigned char *buf, int count, unsigned long timeout)
@@ -693,9 +695,10 @@ static int digi_write_inb_command(struct usb_serial_port *port,
693 timeout = ULONG_MAX; 695 timeout = ULONG_MAX;
694 696
695 spin_lock_irqsave(&priv->dp_port_lock, flags); 697 spin_lock_irqsave(&priv->dp_port_lock, flags);
696 while(count > 0 && ret == 0) { 698 while (count > 0 && ret == 0) {
697 while((port->write_urb->status == -EINPROGRESS 699 while ((port->write_urb->status == -EINPROGRESS
698 || priv->dp_write_urb_in_use) && time_before(jiffies, timeout)) { 700 || priv->dp_write_urb_in_use)
701 && time_before(jiffies, timeout)) {
699 cond_wait_interruptible_timeout_irqrestore( 702 cond_wait_interruptible_timeout_irqrestore(
700 &port->write_wait, DIGI_RETRY_TIMEOUT, 703 &port->write_wait, DIGI_RETRY_TIMEOUT,
701 &priv->dp_port_lock, flags); 704 &priv->dp_port_lock, flags);
@@ -726,7 +729,8 @@ static int digi_write_inb_command(struct usb_serial_port *port,
726 } 729 }
727 port->write_urb->dev = port->serial->dev; 730 port->write_urb->dev = port->serial->dev;
728 731
729 if ((ret = usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0) { 732 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
733 if (ret == 0) {
730 priv->dp_write_urb_in_use = 1; 734 priv->dp_write_urb_in_use = 1;
731 priv->dp_out_buf_len = 0; 735 priv->dp_out_buf_len = 0;
732 count -= len; 736 count -= len;
@@ -744,14 +748,14 @@ static int digi_write_inb_command(struct usb_serial_port *port,
744 748
745 749
746/* 750/*
747* Digi Set Modem Signals 751 * Digi Set Modem Signals
748* 752 *
749* Sets or clears DTR and RTS on the port, according to the 753 * Sets or clears DTR and RTS on the port, according to the
750* modem_signals argument. Use TIOCM_DTR and TIOCM_RTS flags 754 * modem_signals argument. Use TIOCM_DTR and TIOCM_RTS flags
751* for the modem_signals argument. Returns 0 if successful, 755 * for the modem_signals argument. Returns 0 if successful,
752* -EINTR if interrupted while sleeping, or a non-zero error 756 * -EINTR if interrupted while sleeping, or a non-zero error
753* returned by usb_submit_urb. 757 * returned by usb_submit_urb.
754*/ 758 */
755 759
756static int digi_set_modem_signals(struct usb_serial_port *port, 760static int digi_set_modem_signals(struct usb_serial_port *port,
757 unsigned int modem_signals, int interruptible) 761 unsigned int modem_signals, int interruptible)
@@ -759,7 +763,7 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
759 763
760 int ret; 764 int ret;
761 struct digi_port *port_priv = usb_get_serial_port_data(port); 765 struct digi_port *port_priv = usb_get_serial_port_data(port);
762 struct usb_serial_port *oob_port = (struct usb_serial_port *)((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port; 766 struct usb_serial_port *oob_port = (struct usb_serial_port *) ((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port;
763 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port); 767 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port);
764 unsigned char *data = oob_port->write_urb->transfer_buffer; 768 unsigned char *data = oob_port->write_urb->transfer_buffer;
765 unsigned long flags = 0; 769 unsigned long flags = 0;
@@ -771,7 +775,8 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
771 spin_lock_irqsave(&oob_priv->dp_port_lock, flags); 775 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
772 spin_lock(&port_priv->dp_port_lock); 776 spin_lock(&port_priv->dp_port_lock);
773 777
774 while(oob_port->write_urb->status == -EINPROGRESS || oob_priv->dp_write_urb_in_use) { 778 while (oob_port->write_urb->status == -EINPROGRESS ||
779 oob_priv->dp_write_urb_in_use) {
775 spin_unlock(&port_priv->dp_port_lock); 780 spin_unlock(&port_priv->dp_port_lock);
776 cond_wait_interruptible_timeout_irqrestore( 781 cond_wait_interruptible_timeout_irqrestore(
777 &oob_port->write_wait, DIGI_RETRY_TIMEOUT, 782 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
@@ -783,17 +788,20 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
783 } 788 }
784 data[0] = DIGI_CMD_SET_DTR_SIGNAL; 789 data[0] = DIGI_CMD_SET_DTR_SIGNAL;
785 data[1] = port_priv->dp_port_num; 790 data[1] = port_priv->dp_port_num;
786 data[2] = (modem_signals&TIOCM_DTR) ? DIGI_DTR_ACTIVE : DIGI_DTR_INACTIVE; 791 data[2] = (modem_signals & TIOCM_DTR) ?
792 DIGI_DTR_ACTIVE : DIGI_DTR_INACTIVE;
787 data[3] = 0; 793 data[3] = 0;
788 data[4] = DIGI_CMD_SET_RTS_SIGNAL; 794 data[4] = DIGI_CMD_SET_RTS_SIGNAL;
789 data[5] = port_priv->dp_port_num; 795 data[5] = port_priv->dp_port_num;
790 data[6] = (modem_signals&TIOCM_RTS) ? DIGI_RTS_ACTIVE : DIGI_RTS_INACTIVE; 796 data[6] = (modem_signals & TIOCM_RTS) ?
797 DIGI_RTS_ACTIVE : DIGI_RTS_INACTIVE;
791 data[7] = 0; 798 data[7] = 0;
792 799
793 oob_port->write_urb->transfer_buffer_length = 8; 800 oob_port->write_urb->transfer_buffer_length = 8;
794 oob_port->write_urb->dev = port->serial->dev; 801 oob_port->write_urb->dev = port->serial->dev;
795 802
796 if ((ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC)) == 0) { 803 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
804 if (ret == 0) {
797 oob_priv->dp_write_urb_in_use = 1; 805 oob_priv->dp_write_urb_in_use = 1;
798 port_priv->dp_modem_signals = 806 port_priv->dp_modem_signals =
799 (port_priv->dp_modem_signals&~(TIOCM_DTR|TIOCM_RTS)) 807 (port_priv->dp_modem_signals&~(TIOCM_DTR|TIOCM_RTS))
@@ -807,16 +815,16 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
807} 815}
808 816
809/* 817/*
810* Digi Transmit Idle 818 * Digi Transmit Idle
811* 819 *
812* Digi transmit idle waits, up to timeout ticks, for the transmitter 820 * Digi transmit idle waits, up to timeout ticks, for the transmitter
813* to go idle. It returns 0 if successful or a negative error. 821 * to go idle. It returns 0 if successful or a negative error.
814* 822 *
815* There are race conditions here if more than one process is calling 823 * There are race conditions here if more than one process is calling
816* digi_transmit_idle on the same port at the same time. However, this 824 * digi_transmit_idle on the same port at the same time. However, this
817* is only called from close, and only one process can be in close on a 825 * is only called from close, and only one process can be in close on a
818* port at a time, so its ok. 826 * port at a time, so its ok.
819*/ 827 */
820 828
821static int digi_transmit_idle(struct usb_serial_port *port, 829static int digi_transmit_idle(struct usb_serial_port *port,
822 unsigned long timeout) 830 unsigned long timeout)
@@ -835,12 +843,13 @@ static int digi_transmit_idle(struct usb_serial_port *port,
835 843
836 timeout += jiffies; 844 timeout += jiffies;
837 845
838 if ((ret = digi_write_inb_command(port, buf, 2, timeout - jiffies)) != 0) 846 ret = digi_write_inb_command(port, buf, 2, timeout - jiffies);
847 if (ret != 0)
839 return ret; 848 return ret;
840 849
841 spin_lock_irqsave(&priv->dp_port_lock, flags); 850 spin_lock_irqsave(&priv->dp_port_lock, flags);
842 851
843 while(time_before(jiffies, timeout) && !priv->dp_transmit_idle) { 852 while (time_before(jiffies, timeout) && !priv->dp_transmit_idle) {
844 cond_wait_interruptible_timeout_irqrestore( 853 cond_wait_interruptible_timeout_irqrestore(
845 &priv->dp_transmit_idle_wait, DIGI_RETRY_TIMEOUT, 854 &priv->dp_transmit_idle_wait, DIGI_RETRY_TIMEOUT,
846 &priv->dp_port_lock, flags); 855 &priv->dp_port_lock, flags);
@@ -901,7 +910,7 @@ static void digi_rx_unthrottle(struct tty_struct *tty)
901} 910}
902 911
903 912
904static void digi_set_termios(struct tty_struct *tty, 913static void digi_set_termios(struct tty_struct *tty,
905 struct usb_serial_port *port, struct ktermios *old_termios) 914 struct usb_serial_port *port, struct ktermios *old_termios)
906{ 915{
907 struct digi_port *priv = usb_get_serial_port_data(port); 916 struct digi_port *priv = usb_get_serial_port_data(port);
@@ -911,14 +920,15 @@ static void digi_set_termios(struct tty_struct *tty,
911 unsigned int old_cflag = old_termios->c_cflag; 920 unsigned int old_cflag = old_termios->c_cflag;
912 unsigned char buf[32]; 921 unsigned char buf[32];
913 unsigned int modem_signals; 922 unsigned int modem_signals;
914 int arg,ret; 923 int arg, ret;
915 int i = 0; 924 int i = 0;
916 speed_t baud; 925 speed_t baud;
917 926
918 dbg("digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, old_cflag=0x%x", priv->dp_port_num, iflag, old_iflag, cflag, old_cflag); 927 dbg("digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, old_cflag=0x%x", priv->dp_port_num, iflag, old_iflag, cflag, old_cflag);
919 928
920 /* set baud rate */ 929 /* set baud rate */
921 if ((baud = tty_get_baud_rate(tty)) != tty_termios_baud_rate(old_termios)) { 930 baud = tty_get_baud_rate(tty);
931 if (baud != tty_termios_baud_rate(old_termios)) {
922 arg = -1; 932 arg = -1;
923 933
924 /* reassert DTR and (maybe) RTS on transition from B0 */ 934 /* reassert DTR and (maybe) RTS on transition from B0 */
@@ -932,30 +942,30 @@ static void digi_set_termios(struct tty_struct *tty,
932 digi_set_modem_signals(port, modem_signals, 1); 942 digi_set_modem_signals(port, modem_signals, 1);
933 } 943 }
934 switch (baud) { 944 switch (baud) {
935 /* drop DTR and RTS on transition to B0 */ 945 /* drop DTR and RTS on transition to B0 */
936 case 0: digi_set_modem_signals(port, 0, 1); break; 946 case 0: digi_set_modem_signals(port, 0, 1); break;
937 case 50: arg = DIGI_BAUD_50; break; 947 case 50: arg = DIGI_BAUD_50; break;
938 case 75: arg = DIGI_BAUD_75; break; 948 case 75: arg = DIGI_BAUD_75; break;
939 case 110: arg = DIGI_BAUD_110; break; 949 case 110: arg = DIGI_BAUD_110; break;
940 case 150: arg = DIGI_BAUD_150; break; 950 case 150: arg = DIGI_BAUD_150; break;
941 case 200: arg = DIGI_BAUD_200; break; 951 case 200: arg = DIGI_BAUD_200; break;
942 case 300: arg = DIGI_BAUD_300; break; 952 case 300: arg = DIGI_BAUD_300; break;
943 case 600: arg = DIGI_BAUD_600; break; 953 case 600: arg = DIGI_BAUD_600; break;
944 case 1200: arg = DIGI_BAUD_1200; break; 954 case 1200: arg = DIGI_BAUD_1200; break;
945 case 1800: arg = DIGI_BAUD_1800; break; 955 case 1800: arg = DIGI_BAUD_1800; break;
946 case 2400: arg = DIGI_BAUD_2400; break; 956 case 2400: arg = DIGI_BAUD_2400; break;
947 case 4800: arg = DIGI_BAUD_4800; break; 957 case 4800: arg = DIGI_BAUD_4800; break;
948 case 9600: arg = DIGI_BAUD_9600; break; 958 case 9600: arg = DIGI_BAUD_9600; break;
949 case 19200: arg = DIGI_BAUD_19200; break; 959 case 19200: arg = DIGI_BAUD_19200; break;
950 case 38400: arg = DIGI_BAUD_38400; break; 960 case 38400: arg = DIGI_BAUD_38400; break;
951 case 57600: arg = DIGI_BAUD_57600; break; 961 case 57600: arg = DIGI_BAUD_57600; break;
952 case 115200: arg = DIGI_BAUD_115200; break; 962 case 115200: arg = DIGI_BAUD_115200; break;
953 case 230400: arg = DIGI_BAUD_230400; break; 963 case 230400: arg = DIGI_BAUD_230400; break;
954 case 460800: arg = DIGI_BAUD_460800; break; 964 case 460800: arg = DIGI_BAUD_460800; break;
955 default: 965 default:
956 arg = DIGI_BAUD_9600; 966 arg = DIGI_BAUD_9600;
957 baud = 9600; 967 baud = 9600;
958 break; 968 break;
959 } 969 }
960 if (arg != -1) { 970 if (arg != -1) {
961 buf[i++] = DIGI_CMD_SET_BAUD_RATE; 971 buf[i++] = DIGI_CMD_SET_BAUD_RATE;
@@ -1081,7 +1091,8 @@ static void digi_set_termios(struct tty_struct *tty,
1081 buf[i++] = arg; 1091 buf[i++] = arg;
1082 buf[i++] = 0; 1092 buf[i++] = 0;
1083 } 1093 }
1084 if ((ret = digi_write_oob_command(port, buf, i, 1)) != 0) 1094 ret = digi_write_oob_command(port, buf, i, 1);
1095 if (ret != 0)
1085 dbg("digi_set_termios: write oob failed, ret=%d", ret); 1096 dbg("digi_set_termios: write oob failed, ret=%d", ret);
1086 tty_encode_baud_rate(tty, baud, baud); 1097 tty_encode_baud_rate(tty, baud, baud);
1087} 1098}
@@ -1137,7 +1148,7 @@ static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
1137 const unsigned char *buf, int count) 1148 const unsigned char *buf, int count)
1138{ 1149{
1139 1150
1140 int ret,data_len,new_len; 1151 int ret, data_len, new_len;
1141 struct digi_port *priv = usb_get_serial_port_data(port); 1152 struct digi_port *priv = usb_get_serial_port_data(port);
1142 unsigned char *data = port->write_urb->transfer_buffer; 1153 unsigned char *data = port->write_urb->transfer_buffer;
1143 unsigned long flags = 0; 1154 unsigned long flags = 0;
@@ -1155,7 +1166,8 @@ static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
1155 spin_lock_irqsave(&priv->dp_port_lock, flags); 1166 spin_lock_irqsave(&priv->dp_port_lock, flags);
1156 1167
1157 /* wait for urb status clear to submit another urb */ 1168 /* wait for urb status clear to submit another urb */
1158 if (port->write_urb->status == -EINPROGRESS || priv->dp_write_urb_in_use) { 1169 if (port->write_urb->status == -EINPROGRESS ||
1170 priv->dp_write_urb_in_use) {
1159 /* buffer data if count is 1 (probably put_char) if possible */ 1171 /* buffer data if count is 1 (probably put_char) if possible */
1160 if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) { 1172 if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) {
1161 priv->dp_out_buf[priv->dp_out_buf_len++] = *buf; 1173 priv->dp_out_buf[priv->dp_out_buf_len++] = *buf;
@@ -1190,7 +1202,8 @@ static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
1190 /* copy in new data */ 1202 /* copy in new data */
1191 memcpy(data, buf, new_len); 1203 memcpy(data, buf, new_len);
1192 1204
1193 if ((ret = usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0) { 1205 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1206 if (ret == 0) {
1194 priv->dp_write_urb_in_use = 1; 1207 priv->dp_write_urb_in_use = 1;
1195 ret = new_len; 1208 ret = new_len;
1196 priv->dp_out_buf_len = 0; 1209 priv->dp_out_buf_len = 0;
@@ -1204,7 +1217,7 @@ static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
1204 dbg("digi_write: returning %d", ret); 1217 dbg("digi_write: returning %d", ret);
1205 return ret; 1218 return ret;
1206 1219
1207} 1220}
1208 1221
1209static void digi_write_bulk_callback(struct urb *urb) 1222static void digi_write_bulk_callback(struct urb *urb)
1210{ 1223{
@@ -1219,13 +1232,13 @@ static void digi_write_bulk_callback(struct urb *urb)
1219 dbg("digi_write_bulk_callback: TOP, urb->status=%d", status); 1232 dbg("digi_write_bulk_callback: TOP, urb->status=%d", status);
1220 1233
1221 /* port and serial sanity check */ 1234 /* port and serial sanity check */
1222 if (port == NULL || (priv=usb_get_serial_port_data(port)) == NULL) { 1235 if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) {
1223 err("%s: port or port->private is NULL, status=%d", 1236 err("%s: port or port->private is NULL, status=%d",
1224 __func__, status); 1237 __func__, status);
1225 return; 1238 return;
1226 } 1239 }
1227 serial = port->serial; 1240 serial = port->serial;
1228 if (serial == NULL || (serial_priv=usb_get_serial_data(serial)) == NULL) { 1241 if (serial == NULL || (serial_priv = usb_get_serial_data(serial)) == NULL) {
1229 err("%s: serial or serial->private is NULL, status=%d", 1242 err("%s: serial or serial->private is NULL, status=%d",
1230 __func__, status); 1243 __func__, status);
1231 return; 1244 return;
@@ -1248,13 +1261,15 @@ static void digi_write_bulk_callback(struct urb *urb)
1248 && priv->dp_out_buf_len > 0) { 1261 && priv->dp_out_buf_len > 0) {
1249 *((unsigned char *)(port->write_urb->transfer_buffer)) 1262 *((unsigned char *)(port->write_urb->transfer_buffer))
1250 = (unsigned char)DIGI_CMD_SEND_DATA; 1263 = (unsigned char)DIGI_CMD_SEND_DATA;
1251 *((unsigned char *)(port->write_urb->transfer_buffer)+1) 1264 *((unsigned char *)(port->write_urb->transfer_buffer) + 1)
1252 = (unsigned char)priv->dp_out_buf_len; 1265 = (unsigned char)priv->dp_out_buf_len;
1253 port->write_urb->transfer_buffer_length = priv->dp_out_buf_len+2; 1266 port->write_urb->transfer_buffer_length =
1267 priv->dp_out_buf_len + 2;
1254 port->write_urb->dev = serial->dev; 1268 port->write_urb->dev = serial->dev;
1255 memcpy(port->write_urb->transfer_buffer+2, priv->dp_out_buf, 1269 memcpy(port->write_urb->transfer_buffer + 2, priv->dp_out_buf,
1256 priv->dp_out_buf_len); 1270 priv->dp_out_buf_len);
1257 if ((ret = usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0) { 1271 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1272 if (ret == 0) {
1258 priv->dp_write_urb_in_use = 1; 1273 priv->dp_write_urb_in_use = 1;
1259 priv->dp_out_buf_len = 0; 1274 priv->dp_out_buf_len = 0;
1260 } 1275 }
@@ -1280,7 +1295,8 @@ static int digi_write_room(struct tty_struct *tty)
1280 1295
1281 spin_lock_irqsave(&priv->dp_port_lock, flags); 1296 spin_lock_irqsave(&priv->dp_port_lock, flags);
1282 1297
1283 if (port->write_urb->status == -EINPROGRESS || priv->dp_write_urb_in_use) 1298 if (port->write_urb->status == -EINPROGRESS ||
1299 priv->dp_write_urb_in_use)
1284 room = 0; 1300 room = 0;
1285 else 1301 else
1286 room = port->bulk_out_size - 2 - priv->dp_out_buf_len; 1302 room = port->bulk_out_size - 2 - priv->dp_out_buf_len;
@@ -1336,7 +1352,7 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port,
1336 } 1352 }
1337 1353
1338 /* wait for a close in progress to finish */ 1354 /* wait for a close in progress to finish */
1339 while(priv->dp_in_close) { 1355 while (priv->dp_in_close) {
1340 cond_wait_interruptible_timeout_irqrestore( 1356 cond_wait_interruptible_timeout_irqrestore(
1341 &priv->dp_close_wait, DIGI_RETRY_TIMEOUT, 1357 &priv->dp_close_wait, DIGI_RETRY_TIMEOUT,
1342 &priv->dp_port_lock, flags); 1358 &priv->dp_port_lock, flags);
@@ -1346,7 +1362,7 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port,
1346 } 1362 }
1347 1363
1348 spin_unlock_irqrestore(&priv->dp_port_lock, flags); 1364 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1349 1365
1350 /* read modem signals automatically whenever they change */ 1366 /* read modem signals automatically whenever they change */
1351 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS; 1367 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS;
1352 buf[1] = priv->dp_port_num; 1368 buf[1] = priv->dp_port_num;
@@ -1359,7 +1375,8 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port,
1359 buf[6] = DIGI_FLUSH_TX | DIGI_FLUSH_RX; 1375 buf[6] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1360 buf[7] = 0; 1376 buf[7] = 0;
1361 1377
1362 if ((ret = digi_write_oob_command(port, buf, 8, 1)) != 0) 1378 ret = digi_write_oob_command(port, buf, 8, 1);
1379 if (ret != 0)
1363 dbg("digi_open: write oob failed, ret=%d", ret); 1380 dbg("digi_open: write oob failed, ret=%d", ret);
1364 1381
1365 /* set termios settings */ 1382 /* set termios settings */
@@ -1410,9 +1427,8 @@ static void digi_close(struct tty_struct *tty, struct usb_serial_port *port,
1410 1427
1411 if (port->serial->dev) { 1428 if (port->serial->dev) {
1412 /* wait for transmit idle */ 1429 /* wait for transmit idle */
1413 if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) { 1430 if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0)
1414 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT); 1431 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT);
1415 }
1416 /* drop DTR and RTS */ 1432 /* drop DTR and RTS */
1417 digi_set_modem_signals(port, 0, 0); 1433 digi_set_modem_signals(port, 0, 0);
1418 1434
@@ -1446,11 +1462,13 @@ static void digi_close(struct tty_struct *tty, struct usb_serial_port *port,
1446 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX; 1462 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1447 buf[19] = 0; 1463 buf[19] = 0;
1448 1464
1449 if ((ret = digi_write_oob_command(port, buf, 20, 0)) != 0) 1465 ret = digi_write_oob_command(port, buf, 20, 0);
1466 if (ret != 0)
1450 dbg("digi_close: write oob failed, ret=%d", ret); 1467 dbg("digi_close: write oob failed, ret=%d", ret);
1451 1468
1452 /* wait for final commands on oob port to complete */ 1469 /* wait for final commands on oob port to complete */
1453 prepare_to_wait(&priv->dp_flush_wait, &wait, TASK_INTERRUPTIBLE); 1470 prepare_to_wait(&priv->dp_flush_wait, &wait,
1471 TASK_INTERRUPTIBLE);
1454 schedule_timeout(DIGI_CLOSE_TIMEOUT); 1472 schedule_timeout(DIGI_CLOSE_TIMEOUT);
1455 finish_wait(&priv->dp_flush_wait, &wait); 1473 finish_wait(&priv->dp_flush_wait, &wait);
1456 1474
@@ -1470,15 +1488,15 @@ exit:
1470 1488
1471 1489
1472/* 1490/*
1473* Digi Startup Device 1491 * Digi Startup Device
1474* 1492 *
1475* Starts reads on all ports. Must be called AFTER startup, with 1493 * Starts reads on all ports. Must be called AFTER startup, with
1476* urbs initialized. Returns 0 if successful, non-zero error otherwise. 1494 * urbs initialized. Returns 0 if successful, non-zero error otherwise.
1477*/ 1495 */
1478 1496
1479static int digi_startup_device(struct usb_serial *serial) 1497static int digi_startup_device(struct usb_serial *serial)
1480{ 1498{
1481 int i,ret = 0; 1499 int i, ret = 0;
1482 struct digi_serial *serial_priv = usb_get_serial_data(serial); 1500 struct digi_serial *serial_priv = usb_get_serial_data(serial);
1483 struct usb_serial_port *port; 1501 struct usb_serial_port *port;
1484 1502
@@ -1496,7 +1514,8 @@ static int digi_startup_device(struct usb_serial *serial)
1496 for (i = 0; i < serial->type->num_ports + 1; i++) { 1514 for (i = 0; i < serial->type->num_ports + 1; i++) {
1497 port = serial->port[i]; 1515 port = serial->port[i];
1498 port->write_urb->dev = port->serial->dev; 1516 port->write_urb->dev = port->serial->dev;
1499 if ((ret = usb_submit_urb(port->read_urb, GFP_KERNEL)) != 0) { 1517 ret = usb_submit_urb(port->read_urb, GFP_KERNEL);
1518 if (ret != 0) {
1500 err("%s: usb_submit_urb failed, ret=%d, port=%d", 1519 err("%s: usb_submit_urb failed, ret=%d, port=%d",
1501 __func__, ret, i); 1520 __func__, ret, i);
1502 break; 1521 break;
@@ -1517,7 +1536,7 @@ static int digi_startup(struct usb_serial *serial)
1517 1536
1518 /* allocate the private data structures for all ports */ 1537 /* allocate the private data structures for all ports */
1519 /* number of regular ports + 1 for the out-of-band port */ 1538 /* number of regular ports + 1 for the out-of-band port */
1520 for(i = 0; i < serial->type->num_ports + 1; i++) { 1539 for (i = 0; i < serial->type->num_ports + 1; i++) {
1521 /* allocate port private structure */ 1540 /* allocate port private structure */
1522 priv = kmalloc(sizeof(struct digi_port), GFP_KERNEL); 1541 priv = kmalloc(sizeof(struct digi_port), GFP_KERNEL);
1523 if (priv == NULL) { 1542 if (priv == NULL) {
@@ -1580,7 +1599,7 @@ static void digi_shutdown(struct usb_serial *serial)
1580 1599
1581 /* free the private data structures for all ports */ 1600 /* free the private data structures for all ports */
1582 /* number of regular ports + 1 for the out-of-band port */ 1601 /* number of regular ports + 1 for the out-of-band port */
1583 for(i = 0; i < serial->type->num_ports + 1; i++) 1602 for (i = 0; i < serial->type->num_ports + 1; i++)
1584 kfree(usb_get_serial_port_data(serial->port[i])); 1603 kfree(usb_get_serial_port_data(serial->port[i]));
1585 kfree(usb_get_serial_data(serial)); 1604 kfree(usb_get_serial_data(serial));
1586} 1605}
@@ -1603,7 +1622,7 @@ static void digi_read_bulk_callback(struct urb *urb)
1603 return; 1622 return;
1604 } 1623 }
1605 if (port->serial == NULL || 1624 if (port->serial == NULL ||
1606 (serial_priv=usb_get_serial_data(port->serial)) == NULL) { 1625 (serial_priv = usb_get_serial_data(port->serial)) == NULL) {
1607 err("%s: serial is bad or serial->private is NULL, status=%d", 1626 err("%s: serial is bad or serial->private is NULL, status=%d",
1608 __func__, status); 1627 __func__, status);
1609 return; 1628 return;
@@ -1627,22 +1646,23 @@ static void digi_read_bulk_callback(struct urb *urb)
1627 1646
1628 /* continue read */ 1647 /* continue read */
1629 urb->dev = port->serial->dev; 1648 urb->dev = port->serial->dev;
1630 if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) != 0) { 1649 ret = usb_submit_urb(urb, GFP_ATOMIC);
1650 if (ret != 0) {
1631 err("%s: failed resubmitting urb, ret=%d, port=%d", 1651 err("%s: failed resubmitting urb, ret=%d, port=%d",
1632 __func__, ret, priv->dp_port_num); 1652 __func__, ret, priv->dp_port_num);
1633 } 1653 }
1634 1654
1635} 1655}
1636 1656
1637/* 1657/*
1638* Digi Read INB Callback 1658 * Digi Read INB Callback
1639* 1659 *
1640* Digi Read INB Callback handles reads on the in band ports, sending 1660 * Digi Read INB Callback handles reads on the in band ports, sending
1641* the data on to the tty subsystem. When called we know port and 1661 * the data on to the tty subsystem. When called we know port and
1642* port->private are not NULL and port->serial has been validated. 1662 * port->private are not NULL and port->serial has been validated.
1643* It returns 0 if successful, 1 if successful but the port is 1663 * It returns 0 if successful, 1 if successful but the port is
1644* throttled, and -1 if the sanity checks failed. 1664 * throttled, and -1 if the sanity checks failed.
1645*/ 1665 */
1646 1666
1647static int digi_read_inb_callback(struct urb *urb) 1667static int digi_read_inb_callback(struct urb *urb)
1648{ 1668{
@@ -1653,8 +1673,8 @@ static int digi_read_inb_callback(struct urb *urb)
1653 int opcode = ((unsigned char *)urb->transfer_buffer)[0]; 1673 int opcode = ((unsigned char *)urb->transfer_buffer)[0];
1654 int len = ((unsigned char *)urb->transfer_buffer)[1]; 1674 int len = ((unsigned char *)urb->transfer_buffer)[1];
1655 int port_status = ((unsigned char *)urb->transfer_buffer)[2]; 1675 int port_status = ((unsigned char *)urb->transfer_buffer)[2];
1656 unsigned char *data = ((unsigned char *)urb->transfer_buffer)+3; 1676 unsigned char *data = ((unsigned char *)urb->transfer_buffer) + 3;
1657 int flag,throttled; 1677 int flag, throttled;
1658 int i; 1678 int i;
1659 int status = urb->status; 1679 int status = urb->status;
1660 1680
@@ -1665,7 +1685,7 @@ static int digi_read_inb_callback(struct urb *urb)
1665 1685
1666 /* short/multiple packet check */ 1686 /* short/multiple packet check */
1667 if (urb->actual_length != len + 2) { 1687 if (urb->actual_length != len + 2) {
1668 err("%s: INCOMPLETE OR MULTIPLE PACKET, urb->status=%d, " 1688 err("%s: INCOMPLETE OR MULTIPLE PACKET, urb->status=%d, "
1669 "port=%d, opcode=%d, len=%d, actual_length=%d, " 1689 "port=%d, opcode=%d, len=%d, actual_length=%d, "
1670 "status=%d", __func__, status, priv->dp_port_num, 1690 "status=%d", __func__, status, priv->dp_port_num,
1671 opcode, len, urb->actual_length, port_status); 1691 opcode, len, urb->actual_length, port_status);
@@ -1707,8 +1727,9 @@ static int digi_read_inb_callback(struct urb *urb)
1707 if (flag == TTY_NORMAL) 1727 if (flag == TTY_NORMAL)
1708 tty_insert_flip_string(tty, data, len); 1728 tty_insert_flip_string(tty, data, len);
1709 else { 1729 else {
1710 for(i = 0; i < len; i++) 1730 for (i = 0; i < len; i++)
1711 tty_insert_flip_char(tty, data[i], flag); 1731 tty_insert_flip_char(tty,
1732 data[i], flag);
1712 } 1733 }
1713 tty_flip_buffer_push(tty); 1734 tty_flip_buffer_push(tty);
1714 } 1735 }
@@ -1720,19 +1741,19 @@ static int digi_read_inb_callback(struct urb *urb)
1720 else if (opcode != DIGI_CMD_RECEIVE_DATA) 1741 else if (opcode != DIGI_CMD_RECEIVE_DATA)
1721 dbg("%s: unknown opcode: %d", __func__, opcode); 1742 dbg("%s: unknown opcode: %d", __func__, opcode);
1722 1743
1723 return(throttled ? 1 : 0); 1744 return throttled ? 1 : 0;
1724 1745
1725} 1746}
1726 1747
1727 1748
1728/* 1749/*
1729* Digi Read OOB Callback 1750 * Digi Read OOB Callback
1730* 1751 *
1731* Digi Read OOB Callback handles reads on the out of band port. 1752 * Digi Read OOB Callback handles reads on the out of band port.
1732* When called we know port and port->private are not NULL and 1753 * When called we know port and port->private are not NULL and
1733* the port->serial is valid. It returns 0 if successful, and 1754 * the port->serial is valid. It returns 0 if successful, and
1734* -1 if the sanity checks failed. 1755 * -1 if the sanity checks failed.
1735*/ 1756 */
1736 1757
1737static int digi_read_oob_callback(struct urb *urb) 1758static int digi_read_oob_callback(struct urb *urb)
1738{ 1759{
@@ -1742,12 +1763,13 @@ static int digi_read_oob_callback(struct urb *urb)
1742 struct digi_port *priv = usb_get_serial_port_data(port); 1763 struct digi_port *priv = usb_get_serial_port_data(port);
1743 int opcode, line, status, val; 1764 int opcode, line, status, val;
1744 int i; 1765 int i;
1766 unsigned int rts;
1745 1767
1746 dbg("digi_read_oob_callback: port=%d, len=%d", 1768 dbg("digi_read_oob_callback: port=%d, len=%d",
1747 priv->dp_port_num, urb->actual_length); 1769 priv->dp_port_num, urb->actual_length);
1748 1770
1749 /* handle each oob command */ 1771 /* handle each oob command */
1750 for(i = 0; i < urb->actual_length - 3;) { 1772 for (i = 0; i < urb->actual_length - 3;) {
1751 opcode = ((unsigned char *)urb->transfer_buffer)[i++]; 1773 opcode = ((unsigned char *)urb->transfer_buffer)[i++];
1752 line = ((unsigned char *)urb->transfer_buffer)[i++]; 1774 line = ((unsigned char *)urb->transfer_buffer)[i++];
1753 status = ((unsigned char *)urb->transfer_buffer)[i++]; 1775 status = ((unsigned char *)urb->transfer_buffer)[i++];
@@ -1761,27 +1783,29 @@ static int digi_read_oob_callback(struct urb *urb)
1761 1783
1762 port = serial->port[line]; 1784 port = serial->port[line];
1763 1785
1764 if ((priv=usb_get_serial_port_data(port)) == NULL) 1786 priv = usb_get_serial_port_data(port);
1787 if (priv == NULL)
1765 return -1; 1788 return -1;
1766 1789
1790 rts = 0;
1791 if (port->port.count)
1792 rts = port->port.tty->termios->c_cflag & CRTSCTS;
1793
1767 if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) { 1794 if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) {
1768 spin_lock(&priv->dp_port_lock); 1795 spin_lock(&priv->dp_port_lock);
1769 /* convert from digi flags to termiox flags */ 1796 /* convert from digi flags to termiox flags */
1770 if (val & DIGI_READ_INPUT_SIGNALS_CTS) { 1797 if (val & DIGI_READ_INPUT_SIGNALS_CTS) {
1771 priv->dp_modem_signals |= TIOCM_CTS; 1798 priv->dp_modem_signals |= TIOCM_CTS;
1772 /* port must be open to use tty struct */ 1799 /* port must be open to use tty struct */
1773 if (port->port.count 1800 if (rts) {
1774 && port->port.tty->termios->c_cflag & CRTSCTS) {
1775 port->port.tty->hw_stopped = 0; 1801 port->port.tty->hw_stopped = 0;
1776 digi_wakeup_write(port); 1802 digi_wakeup_write(port);
1777 } 1803 }
1778 } else { 1804 } else {
1779 priv->dp_modem_signals &= ~TIOCM_CTS; 1805 priv->dp_modem_signals &= ~TIOCM_CTS;
1780 /* port must be open to use tty struct */ 1806 /* port must be open to use tty struct */
1781 if (port->port.count 1807 if (rts)
1782 && port->port.tty->termios->c_cflag & CRTSCTS) {
1783 port->port.tty->hw_stopped = 1; 1808 port->port.tty->hw_stopped = 1;
1784 }
1785 } 1809 }
1786 if (val & DIGI_READ_INPUT_SIGNALS_DSR) 1810 if (val & DIGI_READ_INPUT_SIGNALS_DSR)
1787 priv->dp_modem_signals |= TIOCM_DSR; 1811 priv->dp_modem_signals |= TIOCM_DSR;
@@ -1818,7 +1842,7 @@ static int __init digi_init(void)
1818 if (retval) 1842 if (retval)
1819 goto failed_acceleport_2_device; 1843 goto failed_acceleport_2_device;
1820 retval = usb_serial_register(&digi_acceleport_4_device); 1844 retval = usb_serial_register(&digi_acceleport_4_device);
1821 if (retval) 1845 if (retval)
1822 goto failed_acceleport_4_device; 1846 goto failed_acceleport_4_device;
1823 retval = usb_register(&digi_driver); 1847 retval = usb_register(&digi_driver);
1824 if (retval) 1848 if (retval)