aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Cox <alan@lxorguk.ukuu.org.uk>2007-07-26 13:57:52 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-30 16:27:46 -0400
commitc6d61269f530e3f7da6bad32e8b42ab7993a5927 (patch)
tree3d97b956fc5f4425c018c46d169ff41ab59a193c
parent01e96d282a062f09923fea33e1039719925d09b8 (diff)
digi_acceleport: Drag the driver kicking and screaming into coding style
- The outbreak of acute bracketitus has been cured - The belief that brackets should have spaces everywhere likewise - Various other coding style tweaks - Use baud rates not Bfoo in the speed setup switch Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/usb/serial/digi_acceleport.c970
1 files changed, 410 insertions, 560 deletions
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 976f54ec26e6..dab2e66d111d 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -433,38 +433,38 @@ struct digi_port {
433 433
434/* Local Function Declarations */ 434/* Local Function Declarations */
435 435
436static void digi_wakeup_write( struct usb_serial_port *port ); 436static void digi_wakeup_write(struct usb_serial_port *port);
437static void digi_wakeup_write_lock(struct work_struct *work); 437static void digi_wakeup_write_lock(struct work_struct *work);
438static int digi_write_oob_command( struct usb_serial_port *port, 438static int digi_write_oob_command(struct usb_serial_port *port,
439 unsigned char *buf, int count, int interruptible ); 439 unsigned char *buf, int count, int interruptible);
440static int digi_write_inb_command( struct usb_serial_port *port, 440static int digi_write_inb_command(struct usb_serial_port *port,
441 unsigned char *buf, int count, unsigned long timeout ); 441 unsigned char *buf, int count, unsigned long timeout);
442static int digi_set_modem_signals( struct usb_serial_port *port, 442static int digi_set_modem_signals(struct usb_serial_port *port,
443 unsigned int modem_signals, int interruptible ); 443 unsigned int modem_signals, int interruptible);
444static int digi_transmit_idle( struct usb_serial_port *port, 444static int digi_transmit_idle(struct usb_serial_port *port,
445 unsigned long timeout ); 445 unsigned long timeout);
446static void digi_rx_throttle (struct usb_serial_port *port); 446static void digi_rx_throttle (struct usb_serial_port *port);
447static void digi_rx_unthrottle (struct usb_serial_port *port); 447static void digi_rx_unthrottle (struct usb_serial_port *port);
448static void digi_set_termios( struct usb_serial_port *port, 448static void digi_set_termios(struct usb_serial_port *port,
449 struct ktermios *old_termios ); 449 struct ktermios *old_termios);
450static void digi_break_ctl( struct usb_serial_port *port, int break_state ); 450static void digi_break_ctl(struct usb_serial_port *port, int break_state);
451static int digi_ioctl( struct usb_serial_port *port, struct file *file, 451static int digi_ioctl(struct usb_serial_port *port, struct file *file,
452 unsigned int cmd, unsigned long arg ); 452 unsigned int cmd, unsigned long arg);
453static int digi_tiocmget( struct usb_serial_port *port, struct file *file ); 453static int digi_tiocmget(struct usb_serial_port *port, struct file *file);
454static int digi_tiocmset( struct usb_serial_port *port, struct file *file, 454static int digi_tiocmset(struct usb_serial_port *port, struct file *file,
455 unsigned int set, unsigned int clear ); 455 unsigned int set, unsigned int clear);
456static int digi_write( struct usb_serial_port *port, const unsigned char *buf, int count ); 456static int digi_write(struct usb_serial_port *port, const unsigned char *buf, int count);
457static void digi_write_bulk_callback( struct urb *urb ); 457static void digi_write_bulk_callback(struct urb *urb);
458static int digi_write_room( struct usb_serial_port *port ); 458static int digi_write_room(struct usb_serial_port *port);
459static int digi_chars_in_buffer( struct usb_serial_port *port ); 459static int digi_chars_in_buffer(struct usb_serial_port *port);
460static int digi_open( struct usb_serial_port *port, struct file *filp ); 460static int digi_open(struct usb_serial_port *port, struct file *filp);
461static void digi_close( struct usb_serial_port *port, struct file *filp ); 461static void digi_close(struct usb_serial_port *port, struct file *filp);
462static int digi_startup_device( struct usb_serial *serial ); 462static int digi_startup_device(struct usb_serial *serial);
463static int digi_startup( struct usb_serial *serial ); 463static int digi_startup(struct usb_serial *serial);
464static void digi_shutdown( struct usb_serial *serial ); 464static void digi_shutdown(struct usb_serial *serial);
465static void digi_read_bulk_callback( struct urb *urb ); 465static void digi_read_bulk_callback(struct urb *urb);
466static int digi_read_inb_callback( struct urb *urb ); 466static int digi_read_inb_callback(struct urb *urb);
467static int digi_read_oob_callback( struct urb *urb ); 467static int digi_read_oob_callback(struct urb *urb);
468 468
469 469
470/* Statics */ 470/* Statics */
@@ -576,9 +576,9 @@ static struct usb_serial_driver digi_acceleport_4_device = {
576* with the equivalent code. 576* with the equivalent code.
577*/ 577*/
578 578
579static inline long cond_wait_interruptible_timeout_irqrestore( 579static long cond_wait_interruptible_timeout_irqrestore(
580 wait_queue_head_t *q, long timeout, 580 wait_queue_head_t *q, long timeout,
581 spinlock_t *lock, unsigned long flags ) 581 spinlock_t *lock, unsigned long flags)
582{ 582{
583 DEFINE_WAIT(wait); 583 DEFINE_WAIT(wait);
584 584
@@ -600,18 +600,16 @@ static inline long cond_wait_interruptible_timeout_irqrestore(
600 600
601static void digi_wakeup_write_lock(struct work_struct *work) 601static void digi_wakeup_write_lock(struct work_struct *work)
602{ 602{
603 struct digi_port *priv = 603 struct digi_port *priv = container_of(work, struct digi_port, dp_wakeup_work);
604 container_of(work, struct digi_port, dp_wakeup_work);
605 struct usb_serial_port *port = priv->dp_port; 604 struct usb_serial_port *port = priv->dp_port;
606 unsigned long flags; 605 unsigned long flags;
607 606
608 607 spin_lock_irqsave(&priv->dp_port_lock, flags);
609 spin_lock_irqsave( &priv->dp_port_lock, flags ); 608 digi_wakeup_write(port);
610 digi_wakeup_write( port ); 609 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
611 spin_unlock_irqrestore( &priv->dp_port_lock, flags );
612} 610}
613 611
614static void digi_wakeup_write( struct usb_serial_port *port ) 612static void digi_wakeup_write(struct usb_serial_port *port)
615{ 613{
616 tty_wakeup(port->tty); 614 tty_wakeup(port->tty);
617} 615}
@@ -628,8 +626,8 @@ static void digi_wakeup_write( struct usb_serial_port *port )
628* returned by usb_submit_urb. 626* returned by usb_submit_urb.
629*/ 627*/
630 628
631static int digi_write_oob_command( struct usb_serial_port *port, 629static int digi_write_oob_command(struct usb_serial_port *port,
632 unsigned char *buf, int count, int interruptible ) 630 unsigned char *buf, int count, int interruptible)
633{ 631{
634 632
635 int ret = 0; 633 int ret = 0;
@@ -638,49 +636,37 @@ static int digi_write_oob_command( struct usb_serial_port *port,
638 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port); 636 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port);
639 unsigned long flags = 0; 637 unsigned long flags = 0;
640 638
639 dbg("digi_write_oob_command: TOP: port=%d, count=%d", oob_priv->dp_port_num, count);
641 640
642dbg( "digi_write_oob_command: TOP: port=%d, count=%d", oob_priv->dp_port_num, count ); 641 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
643 642 while(count > 0) {
644 spin_lock_irqsave( &oob_priv->dp_port_lock, flags ); 643 while(oob_port->write_urb->status == -EINPROGRESS
645 644 || oob_priv->dp_write_urb_in_use) {
646 while( count > 0 ) {
647
648 while( oob_port->write_urb->status == -EINPROGRESS
649 || oob_priv->dp_write_urb_in_use ) {
650 cond_wait_interruptible_timeout_irqrestore( 645 cond_wait_interruptible_timeout_irqrestore(
651 &oob_port->write_wait, DIGI_RETRY_TIMEOUT, 646 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
652 &oob_priv->dp_port_lock, flags ); 647 &oob_priv->dp_port_lock, flags);
653 if( interruptible && signal_pending(current) ) { 648 if (interruptible && signal_pending(current))
654 return( -EINTR ); 649 return -EINTR;
655 } 650 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
656 spin_lock_irqsave( &oob_priv->dp_port_lock, flags );
657 } 651 }
658 652
659 /* len must be a multiple of 4, so commands are not split */ 653 /* len must be a multiple of 4, so commands are not split */
660 len = min(count, oob_port->bulk_out_size ); 654 len = min(count, oob_port->bulk_out_size);
661 if( len > 4 ) 655 if (len > 4)
662 len &= ~3; 656 len &= ~3;
663 657 memcpy(oob_port->write_urb->transfer_buffer, buf, len);
664 memcpy( oob_port->write_urb->transfer_buffer, buf, len );
665 oob_port->write_urb->transfer_buffer_length = len; 658 oob_port->write_urb->transfer_buffer_length = len;
666 oob_port->write_urb->dev = port->serial->dev; 659 oob_port->write_urb->dev = port->serial->dev;
667 660 if ((ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC)) == 0) {
668 if( (ret=usb_submit_urb(oob_port->write_urb, GFP_ATOMIC)) == 0 ) {
669 oob_priv->dp_write_urb_in_use = 1; 661 oob_priv->dp_write_urb_in_use = 1;
670 count -= len; 662 count -= len;
671 buf += len; 663 buf += len;
672 } 664 }
673
674 }
675
676 spin_unlock_irqrestore( &oob_priv->dp_port_lock, flags );
677
678 if( ret ) {
679 err("%s: usb_submit_urb failed, ret=%d", __FUNCTION__,
680 ret );
681 } 665 }
682 666 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags);
683 return( ret ); 667 if (ret)
668 err("%s: usb_submit_urb failed, ret=%d", __FUNCTION__, ret);
669 return ret;
684 670
685} 671}
686 672
@@ -697,63 +683,58 @@ dbg( "digi_write_oob_command: TOP: port=%d, count=%d", oob_priv->dp_port_num, co
697* error returned by digi_write. 683* error returned by digi_write.
698*/ 684*/
699 685
700static int digi_write_inb_command( struct usb_serial_port *port, 686static int digi_write_inb_command(struct usb_serial_port *port,
701 unsigned char *buf, int count, unsigned long timeout ) 687 unsigned char *buf, int count, unsigned long timeout)
702{ 688{
703
704 int ret = 0; 689 int ret = 0;
705 int len; 690 int len;
706 struct digi_port *priv = usb_get_serial_port_data(port); 691 struct digi_port *priv = usb_get_serial_port_data(port);
707 unsigned char *data = port->write_urb->transfer_buffer; 692 unsigned char *data = port->write_urb->transfer_buffer;
708 unsigned long flags = 0; 693 unsigned long flags = 0;
709 694
695 dbg("digi_write_inb_command: TOP: port=%d, count=%d",
696 priv->dp_port_num, count);
710 697
711dbg( "digi_write_inb_command: TOP: port=%d, count=%d", priv->dp_port_num, 698 if (timeout)
712count );
713
714 if( timeout )
715 timeout += jiffies; 699 timeout += jiffies;
716 else 700 else
717 timeout = ULONG_MAX; 701 timeout = ULONG_MAX;
718 702
719 spin_lock_irqsave( &priv->dp_port_lock, flags ); 703 spin_lock_irqsave(&priv->dp_port_lock, flags);
720 704 while(count > 0 && ret == 0) {
721 while( count > 0 && ret == 0 ) { 705 while((port->write_urb->status == -EINPROGRESS
722 706 || priv->dp_write_urb_in_use) && time_before(jiffies, timeout)) {
723 while( (port->write_urb->status == -EINPROGRESS
724 || priv->dp_write_urb_in_use) && time_before(jiffies, timeout)) {
725 cond_wait_interruptible_timeout_irqrestore( 707 cond_wait_interruptible_timeout_irqrestore(
726 &port->write_wait, DIGI_RETRY_TIMEOUT, 708 &port->write_wait, DIGI_RETRY_TIMEOUT,
727 &priv->dp_port_lock, flags ); 709 &priv->dp_port_lock, flags);
728 if( signal_pending(current) ) { 710 if (signal_pending(current))
729 return( -EINTR ); 711 return -EINTR;
730 } 712 spin_lock_irqsave(&priv->dp_port_lock, flags);
731 spin_lock_irqsave( &priv->dp_port_lock, flags );
732 } 713 }
733 714
734 /* len must be a multiple of 4 and small enough to */ 715 /* len must be a multiple of 4 and small enough to */
735 /* guarantee the write will send buffered data first, */ 716 /* guarantee the write will send buffered data first, */
736 /* so commands are in order with data and not split */ 717 /* so commands are in order with data and not split */
737 len = min(count, port->bulk_out_size-2-priv->dp_out_buf_len ); 718 len = min(count, port->bulk_out_size-2-priv->dp_out_buf_len);
738 if( len > 4 ) 719 if (len > 4)
739 len &= ~3; 720 len &= ~3;
740 721
741 /* write any buffered data first */ 722 /* write any buffered data first */
742 if( priv->dp_out_buf_len > 0 ) { 723 if (priv->dp_out_buf_len > 0) {
743 data[0] = DIGI_CMD_SEND_DATA; 724 data[0] = DIGI_CMD_SEND_DATA;
744 data[1] = priv->dp_out_buf_len; 725 data[1] = priv->dp_out_buf_len;
745 memcpy( data+2, priv->dp_out_buf, 726 memcpy(data + 2, priv->dp_out_buf,
746 priv->dp_out_buf_len ); 727 priv->dp_out_buf_len);
747 memcpy( data+2+priv->dp_out_buf_len, buf, len ); 728 memcpy(data + 2 + priv->dp_out_buf_len, buf, len);
748 port->write_urb->transfer_buffer_length 729 port->write_urb->transfer_buffer_length
749 = priv->dp_out_buf_len+2+len; 730 = priv->dp_out_buf_len + 2 + len;
750 } else { 731 } else {
751 memcpy( data, buf, len ); 732 memcpy(data, buf, len);
752 port->write_urb->transfer_buffer_length = len; 733 port->write_urb->transfer_buffer_length = len;
753 } 734 }
754 port->write_urb->dev = port->serial->dev; 735 port->write_urb->dev = port->serial->dev;
755 736
756 if( (ret=usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0 ) { 737 if ((ret = usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0) {
757 priv->dp_write_urb_in_use = 1; 738 priv->dp_write_urb_in_use = 1;
758 priv->dp_out_buf_len = 0; 739 priv->dp_out_buf_len = 0;
759 count -= len; 740 count -= len;
@@ -761,16 +742,12 @@ count );
761 } 742 }
762 743
763 } 744 }
745 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
764 746
765 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 747 if (ret)
766 748 err("%s: usb_submit_urb failed, ret=%d, port=%d",
767 if( ret ) { 749 __FUNCTION__, ret, priv->dp_port_num);
768 err("%s: usb_submit_urb failed, ret=%d, port=%d", __FUNCTION__, 750 return ret;
769 ret, priv->dp_port_num );
770 }
771
772 return( ret );
773
774} 751}
775 752
776 753
@@ -784,8 +761,8 @@ count );
784* returned by usb_submit_urb. 761* returned by usb_submit_urb.
785*/ 762*/
786 763
787static int digi_set_modem_signals( struct usb_serial_port *port, 764static int digi_set_modem_signals(struct usb_serial_port *port,
788 unsigned int modem_signals, int interruptible ) 765 unsigned int modem_signals, int interruptible)
789{ 766{
790 767
791 int ret; 768 int ret;
@@ -796,60 +773,47 @@ static int digi_set_modem_signals( struct usb_serial_port *port,
796 unsigned long flags = 0; 773 unsigned long flags = 0;
797 774
798 775
799dbg( "digi_set_modem_signals: TOP: port=%d, modem_signals=0x%x", 776 dbg("digi_set_modem_signals: TOP: port=%d, modem_signals=0x%x",
800port_priv->dp_port_num, modem_signals ); 777 port_priv->dp_port_num, modem_signals);
801 778
802 spin_lock_irqsave( &oob_priv->dp_port_lock, flags ); 779 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
803 spin_lock( &port_priv->dp_port_lock ); 780 spin_lock(&port_priv->dp_port_lock);
804 781
805 while( oob_port->write_urb->status == -EINPROGRESS 782 while(oob_port->write_urb->status == -EINPROGRESS || oob_priv->dp_write_urb_in_use) {
806 || oob_priv->dp_write_urb_in_use ) { 783 spin_unlock(&port_priv->dp_port_lock);
807 spin_unlock( &port_priv->dp_port_lock );
808 cond_wait_interruptible_timeout_irqrestore( 784 cond_wait_interruptible_timeout_irqrestore(
809 &oob_port->write_wait, DIGI_RETRY_TIMEOUT, 785 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
810 &oob_priv->dp_port_lock, flags ); 786 &oob_priv->dp_port_lock, flags);
811 if( interruptible && signal_pending(current) ) { 787 if (interruptible && signal_pending(current))
812 return( -EINTR ); 788 return -EINTR;
813 } 789 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
814 spin_lock_irqsave( &oob_priv->dp_port_lock, flags ); 790 spin_lock(&port_priv->dp_port_lock);
815 spin_lock( &port_priv->dp_port_lock );
816 } 791 }
817
818 data[0] = DIGI_CMD_SET_DTR_SIGNAL; 792 data[0] = DIGI_CMD_SET_DTR_SIGNAL;
819 data[1] = port_priv->dp_port_num; 793 data[1] = port_priv->dp_port_num;
820 data[2] = (modem_signals&TIOCM_DTR) ? 794 data[2] = (modem_signals&TIOCM_DTR) ? DIGI_DTR_ACTIVE : DIGI_DTR_INACTIVE;
821 DIGI_DTR_ACTIVE : DIGI_DTR_INACTIVE;
822 data[3] = 0; 795 data[3] = 0;
823
824 data[4] = DIGI_CMD_SET_RTS_SIGNAL; 796 data[4] = DIGI_CMD_SET_RTS_SIGNAL;
825 data[5] = port_priv->dp_port_num; 797 data[5] = port_priv->dp_port_num;
826 data[6] = (modem_signals&TIOCM_RTS) ? 798 data[6] = (modem_signals&TIOCM_RTS) ? DIGI_RTS_ACTIVE : DIGI_RTS_INACTIVE;
827 DIGI_RTS_ACTIVE : DIGI_RTS_INACTIVE;
828 data[7] = 0; 799 data[7] = 0;
829 800
830 oob_port->write_urb->transfer_buffer_length = 8; 801 oob_port->write_urb->transfer_buffer_length = 8;
831 oob_port->write_urb->dev = port->serial->dev; 802 oob_port->write_urb->dev = port->serial->dev;
832 803
833 if( (ret=usb_submit_urb(oob_port->write_urb, GFP_ATOMIC)) == 0 ) { 804 if ((ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC)) == 0) {
834 oob_priv->dp_write_urb_in_use = 1; 805 oob_priv->dp_write_urb_in_use = 1;
835 port_priv->dp_modem_signals = 806 port_priv->dp_modem_signals =
836 (port_priv->dp_modem_signals&~(TIOCM_DTR|TIOCM_RTS)) 807 (port_priv->dp_modem_signals&~(TIOCM_DTR|TIOCM_RTS))
837 | (modem_signals&(TIOCM_DTR|TIOCM_RTS)); 808 | (modem_signals&(TIOCM_DTR|TIOCM_RTS));
838 } 809 }
839 810 spin_unlock(&port_priv->dp_port_lock);
840 spin_unlock( &port_priv->dp_port_lock ); 811 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags);
841 spin_unlock_irqrestore( &oob_priv->dp_port_lock, flags ); 812 if (ret)
842 813 err("%s: usb_submit_urb failed, ret=%d", __FUNCTION__, ret);
843 if( ret ) { 814 return ret;
844 err("%s: usb_submit_urb failed, ret=%d", __FUNCTION__,
845 ret );
846 }
847
848 return( ret );
849
850} 815}
851 816
852
853/* 817/*
854* Digi Transmit Idle 818* Digi Transmit Idle
855* 819*
@@ -862,203 +826,182 @@ port_priv->dp_port_num, modem_signals );
862* port at a time, so its ok. 826* port at a time, so its ok.
863*/ 827*/
864 828
865static int digi_transmit_idle( struct usb_serial_port *port, 829static int digi_transmit_idle(struct usb_serial_port *port,
866 unsigned long timeout ) 830 unsigned long timeout)
867{ 831{
868
869 int ret; 832 int ret;
870 unsigned char buf[2]; 833 unsigned char buf[2];
871 struct digi_port *priv = usb_get_serial_port_data(port); 834 struct digi_port *priv = usb_get_serial_port_data(port);
872 unsigned long flags = 0; 835 unsigned long flags = 0;
873 836
874 837 spin_lock_irqsave(&priv->dp_port_lock, flags);
875 spin_lock_irqsave( &priv->dp_port_lock, flags );
876 priv->dp_transmit_idle = 0; 838 priv->dp_transmit_idle = 0;
877 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 839 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
878 840
879 buf[0] = DIGI_CMD_TRANSMIT_IDLE; 841 buf[0] = DIGI_CMD_TRANSMIT_IDLE;
880 buf[1] = 0; 842 buf[1] = 0;
881 843
882 timeout += jiffies; 844 timeout += jiffies;
883 845
884 if( (ret=digi_write_inb_command( port, buf, 2, timeout-jiffies )) != 0 ) 846 if ((ret = digi_write_inb_command(port, buf, 2, timeout - jiffies)) != 0)
885 return( ret ); 847 return ret;
886 848
887 spin_lock_irqsave( &priv->dp_port_lock, flags ); 849 spin_lock_irqsave(&priv->dp_port_lock, flags);
888 850
889 while( time_before(jiffies, timeout) && !priv->dp_transmit_idle ) { 851 while(time_before(jiffies, timeout) && !priv->dp_transmit_idle) {
890 cond_wait_interruptible_timeout_irqrestore( 852 cond_wait_interruptible_timeout_irqrestore(
891 &priv->dp_transmit_idle_wait, DIGI_RETRY_TIMEOUT, 853 &priv->dp_transmit_idle_wait, DIGI_RETRY_TIMEOUT,
892 &priv->dp_port_lock, flags ); 854 &priv->dp_port_lock, flags);
893 if( signal_pending(current) ) { 855 if (signal_pending(current))
894 return( -EINTR ); 856 return -EINTR;
895 } 857 spin_lock_irqsave(&priv->dp_port_lock, flags);
896 spin_lock_irqsave( &priv->dp_port_lock, flags );
897 } 858 }
898
899 priv->dp_transmit_idle = 0; 859 priv->dp_transmit_idle = 0;
900 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 860 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
901 861 return 0;
902 return( 0 );
903 862
904} 863}
905 864
906 865
907static void digi_rx_throttle( struct usb_serial_port *port ) 866static void digi_rx_throttle(struct usb_serial_port *port)
908{ 867{
909
910 unsigned long flags; 868 unsigned long flags;
911 struct digi_port *priv = usb_get_serial_port_data(port); 869 struct digi_port *priv = usb_get_serial_port_data(port);
912 870
913 871
914dbg( "digi_rx_throttle: TOP: port=%d", priv->dp_port_num ); 872 dbg("digi_rx_throttle: TOP: port=%d", priv->dp_port_num);
915 873
916 /* stop receiving characters by not resubmitting the read urb */ 874 /* stop receiving characters by not resubmitting the read urb */
917 spin_lock_irqsave( &priv->dp_port_lock, flags ); 875 spin_lock_irqsave(&priv->dp_port_lock, flags);
918 priv->dp_throttled = 1; 876 priv->dp_throttled = 1;
919 priv->dp_throttle_restart = 0; 877 priv->dp_throttle_restart = 0;
920 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 878 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
921
922} 879}
923 880
924 881
925static void digi_rx_unthrottle( struct usb_serial_port *port ) 882static void digi_rx_unthrottle(struct usb_serial_port *port)
926{ 883{
927
928 int ret = 0; 884 int ret = 0;
929 unsigned long flags; 885 unsigned long flags;
930 struct digi_port *priv = usb_get_serial_port_data(port); 886 struct digi_port *priv = usb_get_serial_port_data(port);
931 887
932dbg( "digi_rx_unthrottle: TOP: port=%d", priv->dp_port_num ); 888 dbg("digi_rx_unthrottle: TOP: port=%d", priv->dp_port_num);
933 889
934 spin_lock_irqsave( &priv->dp_port_lock, flags ); 890 spin_lock_irqsave(&priv->dp_port_lock, flags);
935 891
936 /* turn throttle off */ 892 /* turn throttle off */
937 priv->dp_throttled = 0; 893 priv->dp_throttled = 0;
938 priv->dp_throttle_restart = 0; 894 priv->dp_throttle_restart = 0;
939 895
940 /* restart read chain */ 896 /* restart read chain */
941 if( priv->dp_throttle_restart ) { 897 if (priv->dp_throttle_restart) {
942 port->read_urb->dev = port->serial->dev; 898 port->read_urb->dev = port->serial->dev;
943 ret = usb_submit_urb( port->read_urb, GFP_ATOMIC ); 899 ret = usb_submit_urb(port->read_urb, GFP_ATOMIC);
944 } 900 }
945 901
946 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 902 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
947
948 if( ret ) {
949 err("%s: usb_submit_urb failed, ret=%d, port=%d", __FUNCTION__,
950 ret, priv->dp_port_num );
951 }
952 903
904 if (ret)
905 err("%s: usb_submit_urb failed, ret=%d, port=%d",
906 __FUNCTION__, ret, priv->dp_port_num);
953} 907}
954 908
955 909
956static void digi_set_termios( struct usb_serial_port *port, 910static void digi_set_termios(struct usb_serial_port *port,
957 struct ktermios *old_termios ) 911 struct ktermios *old_termios)
958{ 912{
959 913
960 struct digi_port *priv = usb_get_serial_port_data(port); 914 struct digi_port *priv = usb_get_serial_port_data(port);
961 unsigned int iflag = port->tty->termios->c_iflag; 915 struct tty_struct *tty = port->tty;
962 unsigned int cflag = port->tty->termios->c_cflag; 916 unsigned int iflag = tty->termios->c_iflag;
917 unsigned int cflag = tty->termios->c_cflag;
963 unsigned int old_iflag = old_termios->c_iflag; 918 unsigned int old_iflag = old_termios->c_iflag;
964 unsigned int old_cflag = old_termios->c_cflag; 919 unsigned int old_cflag = old_termios->c_cflag;
965 unsigned char buf[32]; 920 unsigned char buf[32];
966 unsigned int modem_signals; 921 unsigned int modem_signals;
967 int arg,ret; 922 int arg,ret;
968 int i = 0; 923 int i = 0;
924 speed_t baud;
969 925
970 926 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);
971dbg( "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 );
972 927
973 /* set baud rate */ 928 /* set baud rate */
974 if( (cflag&CBAUD) != (old_cflag&CBAUD) ) { 929 if ((baud = tty_get_baud_rate(tty)) != tty_termios_baud_rate(old_termios)) {
975
976 arg = -1; 930 arg = -1;
977 931
978 /* reassert DTR and (maybe) RTS on transition from B0 */ 932 /* reassert DTR and (maybe) RTS on transition from B0 */
979 if( (old_cflag&CBAUD) == B0 ) { 933 if ((old_cflag&CBAUD) == B0) {
980 /* don't set RTS if using hardware flow control */ 934 /* don't set RTS if using hardware flow control */
981 /* and throttling input */ 935 /* and throttling input */
982 modem_signals = TIOCM_DTR; 936 modem_signals = TIOCM_DTR;
983 if( !(port->tty->termios->c_cflag & CRTSCTS) || 937 if (!(tty->termios->c_cflag & CRTSCTS) ||
984 !test_bit(TTY_THROTTLED, &port->tty->flags) ) { 938 !test_bit(TTY_THROTTLED, &tty->flags))
985 modem_signals |= TIOCM_RTS; 939 modem_signals |= TIOCM_RTS;
986 } 940 digi_set_modem_signals(port, modem_signals, 1);
987 digi_set_modem_signals( port, modem_signals, 1 );
988 } 941 }
989 942 switch (baud) {
990 switch( (cflag&CBAUD) ) {
991 /* drop DTR and RTS on transition to B0 */ 943 /* drop DTR and RTS on transition to B0 */
992 case B0: digi_set_modem_signals( port, 0, 1 ); break; 944 case 0: digi_set_modem_signals(port, 0, 1); break;
993 case B50: arg = DIGI_BAUD_50; break; 945 case 50: arg = DIGI_BAUD_50; break;
994 case B75: arg = DIGI_BAUD_75; break; 946 case 75: arg = DIGI_BAUD_75; break;
995 case B110: arg = DIGI_BAUD_110; break; 947 case 110: arg = DIGI_BAUD_110; break;
996 case B150: arg = DIGI_BAUD_150; break; 948 case 150: arg = DIGI_BAUD_150; break;
997 case B200: arg = DIGI_BAUD_200; break; 949 case 200: arg = DIGI_BAUD_200; break;
998 case B300: arg = DIGI_BAUD_300; break; 950 case 300: arg = DIGI_BAUD_300; break;
999 case B600: arg = DIGI_BAUD_600; break; 951 case 600: arg = DIGI_BAUD_600; break;
1000 case B1200: arg = DIGI_BAUD_1200; break; 952 case 1200: arg = DIGI_BAUD_1200; break;
1001 case B1800: arg = DIGI_BAUD_1800; break; 953 case 1800: arg = DIGI_BAUD_1800; break;
1002 case B2400: arg = DIGI_BAUD_2400; break; 954 case 2400: arg = DIGI_BAUD_2400; break;
1003 case B4800: arg = DIGI_BAUD_4800; break; 955 case 4800: arg = DIGI_BAUD_4800; break;
1004 case B9600: arg = DIGI_BAUD_9600; break; 956 case 9600: arg = DIGI_BAUD_9600; break;
1005 case B19200: arg = DIGI_BAUD_19200; break; 957 case 19200: arg = DIGI_BAUD_19200; break;
1006 case B38400: arg = DIGI_BAUD_38400; break; 958 case 38400: arg = DIGI_BAUD_38400; break;
1007 case B57600: arg = DIGI_BAUD_57600; break; 959 case 57600: arg = DIGI_BAUD_57600; break;
1008 case B115200: arg = DIGI_BAUD_115200; break; 960 case 115200: arg = DIGI_BAUD_115200; break;
1009 case B230400: arg = DIGI_BAUD_230400; break; 961 case 230400: arg = DIGI_BAUD_230400; break;
1010 case B460800: arg = DIGI_BAUD_460800; break; 962 case 460800: arg = DIGI_BAUD_460800; break;
1011 default: 963 default:
1012 dbg( "digi_set_termios: can't handle baud rate 0x%x", 964 arg = DIGI_BAUD_9600;
1013 (cflag&CBAUD) ); 965 baud = 9600;
1014 break; 966 break;
1015 } 967 }
1016 968 if (arg != -1) {
1017 if( arg != -1 ) {
1018 buf[i++] = DIGI_CMD_SET_BAUD_RATE; 969 buf[i++] = DIGI_CMD_SET_BAUD_RATE;
1019 buf[i++] = priv->dp_port_num; 970 buf[i++] = priv->dp_port_num;
1020 buf[i++] = arg; 971 buf[i++] = arg;
1021 buf[i++] = 0; 972 buf[i++] = 0;
1022 } 973 }
1023
1024 } 974 }
1025
1026 /* set parity */ 975 /* set parity */
1027 if( (cflag&(PARENB|PARODD)) != (old_cflag&(PARENB|PARODD)) ) { 976 if ((cflag&(PARENB|PARODD)) != (old_cflag&(PARENB|PARODD))) {
1028 977 if (cflag&PARENB) {
1029 if( (cflag&PARENB) ) { 978 if (cflag&PARODD)
1030 if( (cflag&PARODD) )
1031 arg = DIGI_PARITY_ODD; 979 arg = DIGI_PARITY_ODD;
1032 else 980 else
1033 arg = DIGI_PARITY_EVEN; 981 arg = DIGI_PARITY_EVEN;
1034 } else { 982 } else {
1035 arg = DIGI_PARITY_NONE; 983 arg = DIGI_PARITY_NONE;
1036 } 984 }
1037
1038 buf[i++] = DIGI_CMD_SET_PARITY; 985 buf[i++] = DIGI_CMD_SET_PARITY;
1039 buf[i++] = priv->dp_port_num; 986 buf[i++] = priv->dp_port_num;
1040 buf[i++] = arg; 987 buf[i++] = arg;
1041 buf[i++] = 0; 988 buf[i++] = 0;
1042
1043 } 989 }
1044
1045 /* set word size */ 990 /* set word size */
1046 if( (cflag&CSIZE) != (old_cflag&CSIZE) ) { 991 if ((cflag&CSIZE) != (old_cflag&CSIZE)) {
1047
1048 arg = -1; 992 arg = -1;
1049 993 switch (cflag&CSIZE) {
1050 switch( (cflag&CSIZE) ) {
1051 case CS5: arg = DIGI_WORD_SIZE_5; break; 994 case CS5: arg = DIGI_WORD_SIZE_5; break;
1052 case CS6: arg = DIGI_WORD_SIZE_6; break; 995 case CS6: arg = DIGI_WORD_SIZE_6; break;
1053 case CS7: arg = DIGI_WORD_SIZE_7; break; 996 case CS7: arg = DIGI_WORD_SIZE_7; break;
1054 case CS8: arg = DIGI_WORD_SIZE_8; break; 997 case CS8: arg = DIGI_WORD_SIZE_8; break;
1055 default: 998 default:
1056 dbg( "digi_set_termios: can't handle word size %d", 999 dbg("digi_set_termios: can't handle word size %d",
1057 (cflag&CSIZE) ); 1000 (cflag&CSIZE));
1058 break; 1001 break;
1059 } 1002 }
1060 1003
1061 if( arg != -1 ) { 1004 if (arg != -1) {
1062 buf[i++] = DIGI_CMD_SET_WORD_SIZE; 1005 buf[i++] = DIGI_CMD_SET_WORD_SIZE;
1063 buf[i++] = priv->dp_port_num; 1006 buf[i++] = priv->dp_port_num;
1064 buf[i++] = arg; 1007 buf[i++] = arg;
@@ -1068,9 +1011,9 @@ dbg( "digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, ol
1068 } 1011 }
1069 1012
1070 /* set stop bits */ 1013 /* set stop bits */
1071 if( (cflag&CSTOPB) != (old_cflag&CSTOPB) ) { 1014 if ((cflag&CSTOPB) != (old_cflag&CSTOPB)) {
1072 1015
1073 if( (cflag&CSTOPB) ) 1016 if ((cflag&CSTOPB))
1074 arg = DIGI_STOP_BITS_2; 1017 arg = DIGI_STOP_BITS_2;
1075 else 1018 else
1076 arg = DIGI_STOP_BITS_1; 1019 arg = DIGI_STOP_BITS_1;
@@ -1083,18 +1026,15 @@ dbg( "digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, ol
1083 } 1026 }
1084 1027
1085 /* set input flow control */ 1028 /* set input flow control */
1086 if( (iflag&IXOFF) != (old_iflag&IXOFF) 1029 if ((iflag&IXOFF) != (old_iflag&IXOFF)
1087 || (cflag&CRTSCTS) != (old_cflag&CRTSCTS) ) { 1030 || (cflag&CRTSCTS) != (old_cflag&CRTSCTS)) {
1088
1089 arg = 0; 1031 arg = 0;
1090 1032 if (iflag&IXOFF)
1091 if( (iflag&IXOFF) )
1092 arg |= DIGI_INPUT_FLOW_CONTROL_XON_XOFF; 1033 arg |= DIGI_INPUT_FLOW_CONTROL_XON_XOFF;
1093 else 1034 else
1094 arg &= ~DIGI_INPUT_FLOW_CONTROL_XON_XOFF; 1035 arg &= ~DIGI_INPUT_FLOW_CONTROL_XON_XOFF;
1095 1036
1096 if( (cflag&CRTSCTS) ) { 1037 if (cflag&CRTSCTS) {
1097
1098 arg |= DIGI_INPUT_FLOW_CONTROL_RTS; 1038 arg |= DIGI_INPUT_FLOW_CONTROL_RTS;
1099 1039
1100 /* On USB-4 it is necessary to assert RTS prior */ 1040 /* On USB-4 it is necessary to assert RTS prior */
@@ -1107,43 +1047,37 @@ dbg( "digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, ol
1107 } else { 1047 } else {
1108 arg &= ~DIGI_INPUT_FLOW_CONTROL_RTS; 1048 arg &= ~DIGI_INPUT_FLOW_CONTROL_RTS;
1109 } 1049 }
1110
1111 buf[i++] = DIGI_CMD_SET_INPUT_FLOW_CONTROL; 1050 buf[i++] = DIGI_CMD_SET_INPUT_FLOW_CONTROL;
1112 buf[i++] = priv->dp_port_num; 1051 buf[i++] = priv->dp_port_num;
1113 buf[i++] = arg; 1052 buf[i++] = arg;
1114 buf[i++] = 0; 1053 buf[i++] = 0;
1115
1116 } 1054 }
1117 1055
1118 /* set output flow control */ 1056 /* set output flow control */
1119 if( (iflag&IXON) != (old_iflag&IXON) 1057 if ((iflag&IXON) != (old_iflag&IXON)
1120 || (cflag&CRTSCTS) != (old_cflag&CRTSCTS) ) { 1058 || (cflag&CRTSCTS) != (old_cflag&CRTSCTS)) {
1121
1122 arg = 0; 1059 arg = 0;
1123 1060 if (iflag&IXON)
1124 if( (iflag&IXON) )
1125 arg |= DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF; 1061 arg |= DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF;
1126 else 1062 else
1127 arg &= ~DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF; 1063 arg &= ~DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF;
1128 1064
1129 if( (cflag&CRTSCTS) ) { 1065 if (cflag&CRTSCTS) {
1130 arg |= DIGI_OUTPUT_FLOW_CONTROL_CTS; 1066 arg |= DIGI_OUTPUT_FLOW_CONTROL_CTS;
1131 } else { 1067 } else {
1132 arg &= ~DIGI_OUTPUT_FLOW_CONTROL_CTS; 1068 arg &= ~DIGI_OUTPUT_FLOW_CONTROL_CTS;
1133 port->tty->hw_stopped = 0; 1069 tty->hw_stopped = 0;
1134 } 1070 }
1135 1071
1136 buf[i++] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL; 1072 buf[i++] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL;
1137 buf[i++] = priv->dp_port_num; 1073 buf[i++] = priv->dp_port_num;
1138 buf[i++] = arg; 1074 buf[i++] = arg;
1139 buf[i++] = 0; 1075 buf[i++] = 0;
1140
1141 } 1076 }
1142 1077
1143 /* set receive enable/disable */ 1078 /* set receive enable/disable */
1144 if( (cflag&CREAD) != (old_cflag&CREAD) ) { 1079 if ((cflag&CREAD) != (old_cflag&CREAD)) {
1145 1080 if (cflag&CREAD)
1146 if( (cflag&CREAD) )
1147 arg = DIGI_ENABLE; 1081 arg = DIGI_ENABLE;
1148 else 1082 else
1149 arg = DIGI_DISABLE; 1083 arg = DIGI_DISABLE;
@@ -1152,32 +1086,26 @@ dbg( "digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, ol
1152 buf[i++] = priv->dp_port_num; 1086 buf[i++] = priv->dp_port_num;
1153 buf[i++] = arg; 1087 buf[i++] = arg;
1154 buf[i++] = 0; 1088 buf[i++] = 0;
1155
1156 } 1089 }
1157 1090 if ((ret = digi_write_oob_command(port, buf, i, 1)) != 0)
1158 if( (ret=digi_write_oob_command( port, buf, i, 1 )) != 0 ) 1091 dbg("digi_set_termios: write oob failed, ret=%d", ret);
1159 dbg( "digi_set_termios: write oob failed, ret=%d", ret );
1160 1092
1161} 1093}
1162 1094
1163 1095
1164static void digi_break_ctl( struct usb_serial_port *port, int break_state ) 1096static void digi_break_ctl(struct usb_serial_port *port, int break_state)
1165{ 1097{
1166
1167 unsigned char buf[4]; 1098 unsigned char buf[4];
1168 1099
1169
1170 buf[0] = DIGI_CMD_BREAK_CONTROL; 1100 buf[0] = DIGI_CMD_BREAK_CONTROL;
1171 buf[1] = 2; /* length */ 1101 buf[1] = 2; /* length */
1172 buf[2] = break_state ? 1 : 0; 1102 buf[2] = break_state ? 1 : 0;
1173 buf[3] = 0; /* pad */ 1103 buf[3] = 0; /* pad */
1174 1104 digi_write_inb_command(port, buf, 4, 0);
1175 digi_write_inb_command( port, buf, 4, 0 );
1176
1177} 1105}
1178 1106
1179 1107
1180static int digi_tiocmget( struct usb_serial_port *port, struct file *file ) 1108static int digi_tiocmget(struct usb_serial_port *port, struct file *file)
1181{ 1109{
1182 struct digi_port *priv = usb_get_serial_port_data(port); 1110 struct digi_port *priv = usb_get_serial_port_data(port);
1183 unsigned int val; 1111 unsigned int val;
@@ -1185,15 +1113,15 @@ static int digi_tiocmget( struct usb_serial_port *port, struct file *file )
1185 1113
1186 dbg("%s: TOP: port=%d", __FUNCTION__, priv->dp_port_num); 1114 dbg("%s: TOP: port=%d", __FUNCTION__, priv->dp_port_num);
1187 1115
1188 spin_lock_irqsave( &priv->dp_port_lock, flags ); 1116 spin_lock_irqsave(&priv->dp_port_lock, flags);
1189 val = priv->dp_modem_signals; 1117 val = priv->dp_modem_signals;
1190 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 1118 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1191 return val; 1119 return val;
1192} 1120}
1193 1121
1194 1122
1195static int digi_tiocmset( struct usb_serial_port *port, struct file *file, 1123static int digi_tiocmset(struct usb_serial_port *port, struct file *file,
1196 unsigned int set, unsigned int clear ) 1124 unsigned int set, unsigned int clear)
1197{ 1125{
1198 struct digi_port *priv = usb_get_serial_port_data(port); 1126 struct digi_port *priv = usb_get_serial_port_data(port);
1199 unsigned int val; 1127 unsigned int val;
@@ -1201,41 +1129,34 @@ static int digi_tiocmset( struct usb_serial_port *port, struct file *file,
1201 1129
1202 dbg("%s: TOP: port=%d", __FUNCTION__, priv->dp_port_num); 1130 dbg("%s: TOP: port=%d", __FUNCTION__, priv->dp_port_num);
1203 1131
1204 spin_lock_irqsave( &priv->dp_port_lock, flags ); 1132 spin_lock_irqsave(&priv->dp_port_lock, flags);
1205 val = (priv->dp_modem_signals & ~clear) | set; 1133 val = (priv->dp_modem_signals & ~clear) | set;
1206 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 1134 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1207 return digi_set_modem_signals( port, val, 1 ); 1135 return digi_set_modem_signals(port, val, 1);
1208} 1136}
1209 1137
1210 1138
1211static int digi_ioctl( struct usb_serial_port *port, struct file *file, 1139static int digi_ioctl(struct usb_serial_port *port, struct file *file,
1212 unsigned int cmd, unsigned long arg ) 1140 unsigned int cmd, unsigned long arg)
1213{ 1141{
1214
1215 struct digi_port *priv = usb_get_serial_port_data(port); 1142 struct digi_port *priv = usb_get_serial_port_data(port);
1216 1143 dbg("digi_ioctl: TOP: port=%d, cmd=0x%x", priv->dp_port_num, cmd);
1217dbg( "digi_ioctl: TOP: port=%d, cmd=0x%x", priv->dp_port_num, cmd );
1218 1144
1219 switch (cmd) { 1145 switch (cmd) {
1220
1221 case TIOCMIWAIT: 1146 case TIOCMIWAIT:
1222 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/ 1147 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
1223 /* TODO */ 1148 /* TODO */
1224 return( 0 ); 1149 return 0;
1225
1226 case TIOCGICOUNT: 1150 case TIOCGICOUNT:
1227 /* return count of modemline transitions */ 1151 /* return count of modemline transitions */
1228 /* TODO */ 1152 /* TODO */
1229 return 0; 1153 return 0;
1230
1231 } 1154 }
1232 1155 return -ENOIOCTLCMD;
1233 return( -ENOIOCTLCMD );
1234 1156
1235} 1157}
1236 1158
1237 1159static int digi_write(struct usb_serial_port *port, const unsigned char *buf, int count)
1238static int digi_write( struct usb_serial_port *port, const unsigned char *buf, int count )
1239{ 1160{
1240 1161
1241 int ret,data_len,new_len; 1162 int ret,data_len,new_len;
@@ -1243,35 +1164,29 @@ static int digi_write( struct usb_serial_port *port, const unsigned char *buf, i
1243 unsigned char *data = port->write_urb->transfer_buffer; 1164 unsigned char *data = port->write_urb->transfer_buffer;
1244 unsigned long flags = 0; 1165 unsigned long flags = 0;
1245 1166
1246 1167 dbg("digi_write: TOP: port=%d, count=%d, in_interrupt=%ld",
1247dbg( "digi_write: TOP: port=%d, count=%d, in_interrupt=%ld", 1168 priv->dp_port_num, count, in_interrupt());
1248priv->dp_port_num, count, in_interrupt() );
1249 1169
1250 /* copy user data (which can sleep) before getting spin lock */ 1170 /* copy user data (which can sleep) before getting spin lock */
1251 count = min( count, port->bulk_out_size-2 ); 1171 count = min(count, port->bulk_out_size-2);
1252 count = min( 64, count); 1172 count = min(64, count);
1253 1173
1254 /* be sure only one write proceeds at a time */ 1174 /* be sure only one write proceeds at a time */
1255 /* there are races on the port private buffer */ 1175 /* there are races on the port private buffer */
1256 /* and races to check write_urb->status */ 1176 /* and races to check write_urb->status */
1257 spin_lock_irqsave( &priv->dp_port_lock, flags ); 1177 spin_lock_irqsave(&priv->dp_port_lock, flags);
1258 1178
1259 /* wait for urb status clear to submit another urb */ 1179 /* wait for urb status clear to submit another urb */
1260 if( port->write_urb->status == -EINPROGRESS 1180 if (port->write_urb->status == -EINPROGRESS || priv->dp_write_urb_in_use) {
1261 || priv->dp_write_urb_in_use ) {
1262
1263 /* buffer data if count is 1 (probably put_char) if possible */ 1181 /* buffer data if count is 1 (probably put_char) if possible */
1264 if( count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE ) { 1182 if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) {
1265 priv->dp_out_buf[priv->dp_out_buf_len++] = *buf; 1183 priv->dp_out_buf[priv->dp_out_buf_len++] = *buf;
1266 new_len = 1; 1184 new_len = 1;
1267 } else { 1185 } else {
1268 new_len = 0; 1186 new_len = 0;
1269 } 1187 }
1270 1188 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1271 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 1189 return new_len;
1272
1273 return( new_len );
1274
1275 } 1190 }
1276 1191
1277 /* allow space for any buffered data and for new data, up to */ 1192 /* allow space for any buffered data and for new data, up to */
@@ -1279,9 +1194,9 @@ priv->dp_port_num, count, in_interrupt() );
1279 new_len = min(count, port->bulk_out_size-2-priv->dp_out_buf_len); 1194 new_len = min(count, port->bulk_out_size-2-priv->dp_out_buf_len);
1280 data_len = new_len + priv->dp_out_buf_len; 1195 data_len = new_len + priv->dp_out_buf_len;
1281 1196
1282 if( data_len == 0 ) { 1197 if (data_len == 0) {
1283 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 1198 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1284 return( 0 ); 1199 return 0;
1285 } 1200 }
1286 1201
1287 port->write_urb->transfer_buffer_length = data_len+2; 1202 port->write_urb->transfer_buffer_length = data_len+2;
@@ -1291,32 +1206,29 @@ priv->dp_port_num, count, in_interrupt() );
1291 *data++ = data_len; 1206 *data++ = data_len;
1292 1207
1293 /* copy in buffered data first */ 1208 /* copy in buffered data first */
1294 memcpy( data, priv->dp_out_buf, priv->dp_out_buf_len ); 1209 memcpy(data, priv->dp_out_buf, priv->dp_out_buf_len);
1295 data += priv->dp_out_buf_len; 1210 data += priv->dp_out_buf_len;
1296 1211
1297 /* copy in new data */ 1212 /* copy in new data */
1298 memcpy( data, buf, new_len ); 1213 memcpy(data, buf, new_len);
1299 1214
1300 if( (ret=usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0 ) { 1215 if ((ret = usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0) {
1301 priv->dp_write_urb_in_use = 1; 1216 priv->dp_write_urb_in_use = 1;
1302 ret = new_len; 1217 ret = new_len;
1303 priv->dp_out_buf_len = 0; 1218 priv->dp_out_buf_len = 0;
1304 } 1219 }
1305 1220
1306 /* return length of new data written, or error */ 1221 /* return length of new data written, or error */
1307 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 1222 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1308 if( ret < 0 ) { 1223 if (ret < 0)
1309 err("%s: usb_submit_urb failed, ret=%d, port=%d", __FUNCTION__, 1224 err("%s: usb_submit_urb failed, ret=%d, port=%d",
1310 ret, priv->dp_port_num ); 1225 __FUNCTION__, ret, priv->dp_port_num);
1311 } 1226 dbg("digi_write: returning %d", ret);
1312 1227 return ret;
1313dbg( "digi_write: returning %d", ret );
1314 return( ret );
1315 1228
1316} 1229}
1317 1230
1318 1231static void digi_write_bulk_callback(struct urb *urb)
1319static void digi_write_bulk_callback( struct urb *urb )
1320{ 1232{
1321 1233
1322 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1234 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
@@ -1326,153 +1238,136 @@ static void digi_write_bulk_callback( struct urb *urb )
1326 int ret = 0; 1238 int ret = 0;
1327 int status = urb->status; 1239 int status = urb->status;
1328 1240
1329 1241 dbg("digi_write_bulk_callback: TOP, urb->status=%d", status);
1330 dbg("digi_write_bulk_callback: TOP, urb status=%d", status);
1331 1242
1332 /* port and serial sanity check */ 1243 /* port and serial sanity check */
1333 if( port == NULL || (priv=usb_get_serial_port_data(port)) == NULL ) { 1244 if (port == NULL || (priv=usb_get_serial_port_data(port)) == NULL) {
1334 err("%s: port or port->private is NULL, status=%d", 1245 err("%s: port or port->private is NULL, status=%d",
1335 __FUNCTION__, status); 1246 __FUNCTION__, status);
1336 return; 1247 return;
1337 } 1248 }
1338 serial = port->serial; 1249 serial = port->serial;
1339 if( serial == NULL || (serial_priv=usb_get_serial_data(serial)) == NULL ) { 1250 if (serial == NULL || (serial_priv=usb_get_serial_data(serial)) == NULL) {
1340 err("%s: serial or serial->private is NULL, status=%d", 1251 err("%s: serial or serial->private is NULL, status=%d",
1341 __FUNCTION__, status); 1252 __FUNCTION__, status);
1342 return; 1253 return;
1343 } 1254 }
1344 1255
1345 /* handle oob callback */ 1256 /* handle oob callback */
1346 if( priv->dp_port_num == serial_priv->ds_oob_port_num ) { 1257 if (priv->dp_port_num == serial_priv->ds_oob_port_num) {
1347 dbg( "digi_write_bulk_callback: oob callback" ); 1258 dbg("digi_write_bulk_callback: oob callback");
1348 spin_lock( &priv->dp_port_lock ); 1259 spin_lock(&priv->dp_port_lock);
1349 priv->dp_write_urb_in_use = 0; 1260 priv->dp_write_urb_in_use = 0;
1350 wake_up_interruptible( &port->write_wait ); 1261 wake_up_interruptible(&port->write_wait);
1351 spin_unlock( &priv->dp_port_lock ); 1262 spin_unlock(&priv->dp_port_lock);
1352 return; 1263 return;
1353 } 1264 }
1354 1265
1355 /* try to send any buffered data on this port, if it is open */ 1266 /* try to send any buffered data on this port, if it is open */
1356 spin_lock( &priv->dp_port_lock ); 1267 spin_lock(&priv->dp_port_lock);
1357 priv->dp_write_urb_in_use = 0; 1268 priv->dp_write_urb_in_use = 0;
1358 if( port->open_count && port->write_urb->status != -EINPROGRESS 1269 if (port->open_count && port->write_urb->status != -EINPROGRESS
1359 && priv->dp_out_buf_len > 0 ) { 1270 && priv->dp_out_buf_len > 0) {
1360
1361 *((unsigned char *)(port->write_urb->transfer_buffer)) 1271 *((unsigned char *)(port->write_urb->transfer_buffer))
1362 = (unsigned char)DIGI_CMD_SEND_DATA; 1272 = (unsigned char)DIGI_CMD_SEND_DATA;
1363 *((unsigned char *)(port->write_urb->transfer_buffer)+1) 1273 *((unsigned char *)(port->write_urb->transfer_buffer)+1)
1364 = (unsigned char)priv->dp_out_buf_len; 1274 = (unsigned char)priv->dp_out_buf_len;
1365 1275 port->write_urb->transfer_buffer_length = priv->dp_out_buf_len+2;
1366 port->write_urb->transfer_buffer_length
1367 = priv->dp_out_buf_len+2;
1368 port->write_urb->dev = serial->dev; 1276 port->write_urb->dev = serial->dev;
1369 1277 memcpy(port->write_urb->transfer_buffer+2, priv->dp_out_buf,
1370 memcpy( port->write_urb->transfer_buffer+2, priv->dp_out_buf, 1278 priv->dp_out_buf_len);
1371 priv->dp_out_buf_len ); 1279 if ((ret = usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0) {
1372
1373 if( (ret=usb_submit_urb(port->write_urb, GFP_ATOMIC)) == 0 ) {
1374 priv->dp_write_urb_in_use = 1; 1280 priv->dp_write_urb_in_use = 1;
1375 priv->dp_out_buf_len = 0; 1281 priv->dp_out_buf_len = 0;
1376 } 1282 }
1377
1378 } 1283 }
1379
1380 /* wake up processes sleeping on writes immediately */ 1284 /* wake up processes sleeping on writes immediately */
1381 digi_wakeup_write( port ); 1285 digi_wakeup_write(port);
1382
1383 /* also queue up a wakeup at scheduler time, in case we */ 1286 /* also queue up a wakeup at scheduler time, in case we */
1384 /* lost the race in write_chan(). */ 1287 /* lost the race in write_chan(). */
1385 schedule_work(&priv->dp_wakeup_work); 1288 schedule_work(&priv->dp_wakeup_work);
1386 1289
1387 spin_unlock( &priv->dp_port_lock ); 1290 spin_unlock(&priv->dp_port_lock);
1388 1291 if (ret)
1389 if( ret ) { 1292 err("%s: usb_submit_urb failed, ret=%d, port=%d",
1390 err("%s: usb_submit_urb failed, ret=%d, port=%d", __FUNCTION__, 1293 __FUNCTION__, ret, priv->dp_port_num);
1391 ret, priv->dp_port_num );
1392 }
1393
1394} 1294}
1395 1295
1396 1296static int digi_write_room(struct usb_serial_port *port)
1397static int digi_write_room( struct usb_serial_port *port )
1398{ 1297{
1399 1298
1400 int room; 1299 int room;
1401 struct digi_port *priv = usb_get_serial_port_data(port); 1300 struct digi_port *priv = usb_get_serial_port_data(port);
1402 unsigned long flags = 0; 1301 unsigned long flags = 0;
1403 1302
1303 spin_lock_irqsave(&priv->dp_port_lock, flags);
1404 1304
1405 spin_lock_irqsave( &priv->dp_port_lock, flags ); 1305 if (port->write_urb->status == -EINPROGRESS || priv->dp_write_urb_in_use)
1406
1407 if( port->write_urb->status == -EINPROGRESS
1408 || priv->dp_write_urb_in_use )
1409 room = 0; 1306 room = 0;
1410 else 1307 else
1411 room = port->bulk_out_size - 2 - priv->dp_out_buf_len; 1308 room = port->bulk_out_size - 2 - priv->dp_out_buf_len;
1412 1309
1413 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 1310 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1414 1311 dbg("digi_write_room: port=%d, room=%d", priv->dp_port_num, room);
1415dbg( "digi_write_room: port=%d, room=%d", priv->dp_port_num, room ); 1312 return room;
1416 return( room );
1417 1313
1418} 1314}
1419 1315
1420 1316static int digi_chars_in_buffer(struct usb_serial_port *port)
1421static int digi_chars_in_buffer( struct usb_serial_port *port )
1422{ 1317{
1423 1318
1424 struct digi_port *priv = usb_get_serial_port_data(port); 1319 struct digi_port *priv = usb_get_serial_port_data(port);
1425 1320
1426 1321
1427 if( port->write_urb->status == -EINPROGRESS 1322 if (port->write_urb->status == -EINPROGRESS
1428 || priv->dp_write_urb_in_use ) { 1323 || priv->dp_write_urb_in_use) {
1429dbg( "digi_chars_in_buffer: port=%d, chars=%d", priv->dp_port_num, port->bulk_out_size - 2 ); 1324 dbg("digi_chars_in_buffer: port=%d, chars=%d",
1430 /* return( port->bulk_out_size - 2 ); */ 1325 priv->dp_port_num, port->bulk_out_size - 2);
1431 return( 256 ); 1326 /* return(port->bulk_out_size - 2); */
1327 return 256;
1432 } else { 1328 } else {
1433dbg( "digi_chars_in_buffer: port=%d, chars=%d", priv->dp_port_num, priv->dp_out_buf_len ); 1329 dbg("digi_chars_in_buffer: port=%d, chars=%d",
1434 return( priv->dp_out_buf_len ); 1330 priv->dp_port_num, priv->dp_out_buf_len);
1331 return priv->dp_out_buf_len;
1435 } 1332 }
1436 1333
1437} 1334}
1438 1335
1439 1336
1440static int digi_open( struct usb_serial_port *port, struct file *filp ) 1337static int digi_open(struct usb_serial_port *port, struct file *filp)
1441{ 1338{
1442
1443 int ret; 1339 int ret;
1444 unsigned char buf[32]; 1340 unsigned char buf[32];
1445 struct digi_port *priv = usb_get_serial_port_data(port); 1341 struct digi_port *priv = usb_get_serial_port_data(port);
1446 struct ktermios not_termios; 1342 struct ktermios not_termios;
1447 unsigned long flags = 0; 1343 unsigned long flags = 0;
1448 1344
1449 1345 dbg("digi_open: TOP: port=%d, open_count=%d",
1450dbg( "digi_open: TOP: port=%d, open_count=%d", priv->dp_port_num, port->open_count ); 1346 priv->dp_port_num, port->open_count);
1451 1347
1452 /* be sure the device is started up */ 1348 /* be sure the device is started up */
1453 if( digi_startup_device( port->serial ) != 0 ) 1349 if (digi_startup_device(port->serial) != 0)
1454 return( -ENXIO ); 1350 return -ENXIO;
1455 1351
1456 spin_lock_irqsave( &priv->dp_port_lock, flags ); 1352 spin_lock_irqsave(&priv->dp_port_lock, flags);
1457 1353
1458 /* don't wait on a close in progress for non-blocking opens */ 1354 /* don't wait on a close in progress for non-blocking opens */
1459 if( priv->dp_in_close && (filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0 ) { 1355 if (priv->dp_in_close && (filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) {
1460 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 1356 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1461 return( -EAGAIN ); 1357 return -EAGAIN;
1462 } 1358 }
1463 1359
1464 /* wait for a close in progress to finish */ 1360 /* wait for a close in progress to finish */
1465 while( priv->dp_in_close ) { 1361 while(priv->dp_in_close) {
1466 cond_wait_interruptible_timeout_irqrestore( 1362 cond_wait_interruptible_timeout_irqrestore(
1467 &priv->dp_close_wait, DIGI_RETRY_TIMEOUT, 1363 &priv->dp_close_wait, DIGI_RETRY_TIMEOUT,
1468 &priv->dp_port_lock, flags ); 1364 &priv->dp_port_lock, flags);
1469 if( signal_pending(current) ) { 1365 if (signal_pending(current))
1470 return( -EINTR ); 1366 return -EINTR;
1471 } 1367 spin_lock_irqsave(&priv->dp_port_lock, flags);
1472 spin_lock_irqsave( &priv->dp_port_lock, flags );
1473 } 1368 }
1474 1369
1475 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 1370 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1476 1371
1477 /* read modem signals automatically whenever they change */ 1372 /* read modem signals automatically whenever they change */
1478 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS; 1373 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS;
@@ -1486,23 +1381,22 @@ dbg( "digi_open: TOP: port=%d, open_count=%d", priv->dp_port_num, port->open_cou
1486 buf[6] = DIGI_FLUSH_TX | DIGI_FLUSH_RX; 1381 buf[6] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1487 buf[7] = 0; 1382 buf[7] = 0;
1488 1383
1489 if( (ret=digi_write_oob_command( port, buf, 8, 1 )) != 0 ) 1384 if ((ret = digi_write_oob_command(port, buf, 8, 1)) != 0)
1490 dbg( "digi_open: write oob failed, ret=%d", ret ); 1385 dbg("digi_open: write oob failed, ret=%d", ret);
1491 1386
1492 /* set termios settings */ 1387 /* set termios settings */
1493 not_termios.c_cflag = ~port->tty->termios->c_cflag; 1388 not_termios.c_cflag = ~port->tty->termios->c_cflag;
1494 not_termios.c_iflag = ~port->tty->termios->c_iflag; 1389 not_termios.c_iflag = ~port->tty->termios->c_iflag;
1495 digi_set_termios( port, &not_termios ); 1390 digi_set_termios(port, &not_termios);
1496 1391
1497 /* set DTR and RTS */ 1392 /* set DTR and RTS */
1498 digi_set_modem_signals( port, TIOCM_DTR|TIOCM_RTS, 1 ); 1393 digi_set_modem_signals(port, TIOCM_DTR|TIOCM_RTS, 1);
1499
1500 return( 0 );
1501 1394
1395 return 0;
1502} 1396}
1503 1397
1504 1398
1505static void digi_close( struct usb_serial_port *port, struct file *filp ) 1399static void digi_close(struct usb_serial_port *port, struct file *filp)
1506{ 1400{
1507 DEFINE_WAIT(wait); 1401 DEFINE_WAIT(wait);
1508 int ret; 1402 int ret;
@@ -1511,40 +1405,37 @@ static void digi_close( struct usb_serial_port *port, struct file *filp )
1511 struct digi_port *priv = usb_get_serial_port_data(port); 1405 struct digi_port *priv = usb_get_serial_port_data(port);
1512 unsigned long flags = 0; 1406 unsigned long flags = 0;
1513 1407
1514 1408 dbg("digi_close: TOP: port=%d, open_count=%d",
1515dbg( "digi_close: TOP: port=%d, open_count=%d", priv->dp_port_num, port->open_count ); 1409 priv->dp_port_num, port->open_count);
1516
1517 1410
1518 /* if disconnected, just clear flags */ 1411 /* if disconnected, just clear flags */
1519 if (!usb_get_intfdata(port->serial->interface)) 1412 if (!usb_get_intfdata(port->serial->interface))
1520 goto exit; 1413 goto exit;
1521 1414
1522 /* do cleanup only after final close on this port */ 1415 /* do cleanup only after final close on this port */
1523 spin_lock_irqsave( &priv->dp_port_lock, flags ); 1416 spin_lock_irqsave(&priv->dp_port_lock, flags);
1524 priv->dp_in_close = 1; 1417 priv->dp_in_close = 1;
1525 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 1418 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1526 1419
1527 /* tell line discipline to process only XON/XOFF */ 1420 /* tell line discipline to process only XON/XOFF */
1528 tty->closing = 1; 1421 tty->closing = 1;
1529 1422
1530 /* wait for output to drain */ 1423 /* wait for output to drain */
1531 if( (filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0 ) { 1424 if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0)
1532 tty_wait_until_sent( tty, DIGI_CLOSE_TIMEOUT ); 1425 tty_wait_until_sent(tty, DIGI_CLOSE_TIMEOUT);
1533 }
1534 1426
1535 /* flush driver and line discipline buffers */ 1427 /* flush driver and line discipline buffers */
1536 if( tty->driver->flush_buffer ) 1428 if (tty->driver->flush_buffer)
1537 tty->driver->flush_buffer( tty ); 1429 tty->driver->flush_buffer(tty);
1538 tty_ldisc_flush(tty); 1430 tty_ldisc_flush(tty);
1539 1431
1540 if (port->serial->dev) { 1432 if (port->serial->dev) {
1541 /* wait for transmit idle */ 1433 /* wait for transmit idle */
1542 if( (filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0 ) { 1434 if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) {
1543 digi_transmit_idle( port, DIGI_CLOSE_TIMEOUT ); 1435 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT);
1544 } 1436 }
1545
1546 /* drop DTR and RTS */ 1437 /* drop DTR and RTS */
1547 digi_set_modem_signals( port, 0, 0 ); 1438 digi_set_modem_signals(port, 0, 0);
1548 1439
1549 /* disable input flow control */ 1440 /* disable input flow control */
1550 buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL; 1441 buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL;
@@ -1576,8 +1467,8 @@ dbg( "digi_close: TOP: port=%d, open_count=%d", priv->dp_port_num, port->open_co
1576 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX; 1467 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1577 buf[19] = 0; 1468 buf[19] = 0;
1578 1469
1579 if( (ret=digi_write_oob_command( port, buf, 20, 0 )) != 0 ) 1470 if ((ret = digi_write_oob_command(port, buf, 20, 0)) != 0)
1580 dbg( "digi_close: write oob failed, ret=%d", ret ); 1471 dbg("digi_close: write oob failed, ret=%d", ret);
1581 1472
1582 /* wait for final commands on oob port to complete */ 1473 /* wait for final commands on oob port to complete */
1583 prepare_to_wait(&priv->dp_flush_wait, &wait, TASK_INTERRUPTIBLE); 1474 prepare_to_wait(&priv->dp_flush_wait, &wait, TASK_INTERRUPTIBLE);
@@ -1587,17 +1478,14 @@ dbg( "digi_close: TOP: port=%d, open_count=%d", priv->dp_port_num, port->open_co
1587 /* shutdown any outstanding bulk writes */ 1478 /* shutdown any outstanding bulk writes */
1588 usb_kill_urb(port->write_urb); 1479 usb_kill_urb(port->write_urb);
1589 } 1480 }
1590
1591 tty->closing = 0; 1481 tty->closing = 0;
1592
1593exit: 1482exit:
1594 spin_lock_irqsave( &priv->dp_port_lock, flags ); 1483 spin_lock_irqsave(&priv->dp_port_lock, flags);
1595 priv->dp_write_urb_in_use = 0; 1484 priv->dp_write_urb_in_use = 0;
1596 priv->dp_in_close = 0; 1485 priv->dp_in_close = 0;
1597 wake_up_interruptible( &priv->dp_close_wait ); 1486 wake_up_interruptible(&priv->dp_close_wait);
1598 spin_unlock_irqrestore( &priv->dp_port_lock, flags ); 1487 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1599 1488 dbg("digi_close: done");
1600dbg( "digi_close: done" );
1601} 1489}
1602 1490
1603 1491
@@ -1608,155 +1496,136 @@ dbg( "digi_close: done" );
1608* urbs initialized. Returns 0 if successful, non-zero error otherwise. 1496* urbs initialized. Returns 0 if successful, non-zero error otherwise.
1609*/ 1497*/
1610 1498
1611static int digi_startup_device( struct usb_serial *serial ) 1499static int digi_startup_device(struct usb_serial *serial)
1612{ 1500{
1613
1614 int i,ret = 0; 1501 int i,ret = 0;
1615 struct digi_serial *serial_priv = usb_get_serial_data(serial); 1502 struct digi_serial *serial_priv = usb_get_serial_data(serial);
1616 struct usb_serial_port *port; 1503 struct usb_serial_port *port;
1617 1504
1618
1619 /* be sure this happens exactly once */ 1505 /* be sure this happens exactly once */
1620 spin_lock( &serial_priv->ds_serial_lock ); 1506 spin_lock(&serial_priv->ds_serial_lock);
1621 if( serial_priv->ds_device_started ) { 1507 if (serial_priv->ds_device_started) {
1622 spin_unlock( &serial_priv->ds_serial_lock ); 1508 spin_unlock(&serial_priv->ds_serial_lock);
1623 return( 0 ); 1509 return 0;
1624 } 1510 }
1625 serial_priv->ds_device_started = 1; 1511 serial_priv->ds_device_started = 1;
1626 spin_unlock( &serial_priv->ds_serial_lock ); 1512 spin_unlock(&serial_priv->ds_serial_lock);
1627 1513
1628 /* start reading from each bulk in endpoint for the device */ 1514 /* start reading from each bulk in endpoint for the device */
1629 /* set USB_DISABLE_SPD flag for write bulk urbs */ 1515 /* set USB_DISABLE_SPD flag for write bulk urbs */
1630 for( i=0; i<serial->type->num_ports+1; i++ ) { 1516 for (i = 0; i < serial->type->num_ports + 1; i++) {
1631
1632 port = serial->port[i]; 1517 port = serial->port[i];
1633
1634 port->write_urb->dev = port->serial->dev; 1518 port->write_urb->dev = port->serial->dev;
1635 1519 if ((ret = usb_submit_urb(port->read_urb, GFP_KERNEL)) != 0) {
1636 if( (ret=usb_submit_urb(port->read_urb, GFP_KERNEL)) != 0 ) { 1520 err("%s: usb_submit_urb failed, ret=%d, port=%d",
1637 err("%s: usb_submit_urb failed, ret=%d, port=%d", __FUNCTION__, 1521 __FUNCTION__, ret, i);
1638 ret, i );
1639 break; 1522 break;
1640 } 1523 }
1641
1642 } 1524 }
1643 1525 return ret;
1644 return( ret );
1645
1646} 1526}
1647 1527
1648 1528
1649static int digi_startup( struct usb_serial *serial ) 1529static int digi_startup(struct usb_serial *serial)
1650{ 1530{
1651 1531
1652 int i; 1532 int i;
1653 struct digi_port *priv; 1533 struct digi_port *priv;
1654 struct digi_serial *serial_priv; 1534 struct digi_serial *serial_priv;
1655 1535
1656 1536 dbg("digi_startup: TOP");
1657dbg( "digi_startup: TOP" );
1658 1537
1659 /* allocate the private data structures for all ports */ 1538 /* allocate the private data structures for all ports */
1660 /* number of regular ports + 1 for the out-of-band port */ 1539 /* number of regular ports + 1 for the out-of-band port */
1661 for( i=0; i<serial->type->num_ports+1; i++ ) { 1540 for(i = 0; i < serial->type->num_ports + 1; i++) {
1662
1663 /* allocate port private structure */ 1541 /* allocate port private structure */
1664 priv = kmalloc( sizeof(struct digi_port), 1542 priv = kmalloc(sizeof(struct digi_port), GFP_KERNEL);
1665 GFP_KERNEL ); 1543 if (priv == NULL) {
1666 if( priv == (struct digi_port *)0 ) { 1544 while (--i >= 0)
1667 while( --i >= 0 ) 1545 kfree(usb_get_serial_port_data(serial->port[i]));
1668 kfree( usb_get_serial_port_data(serial->port[i]) ); 1546 return 1; /* error */
1669 return( 1 ); /* error */
1670 } 1547 }
1671 1548
1672 /* initialize port private structure */ 1549 /* initialize port private structure */
1673 spin_lock_init( &priv->dp_port_lock ); 1550 spin_lock_init(&priv->dp_port_lock);
1674 priv->dp_port_num = i; 1551 priv->dp_port_num = i;
1675 priv->dp_out_buf_len = 0; 1552 priv->dp_out_buf_len = 0;
1676 priv->dp_write_urb_in_use = 0; 1553 priv->dp_write_urb_in_use = 0;
1677 priv->dp_modem_signals = 0; 1554 priv->dp_modem_signals = 0;
1678 init_waitqueue_head( &priv->dp_modem_change_wait ); 1555 init_waitqueue_head(&priv->dp_modem_change_wait);
1679 priv->dp_transmit_idle = 0; 1556 priv->dp_transmit_idle = 0;
1680 init_waitqueue_head( &priv->dp_transmit_idle_wait ); 1557 init_waitqueue_head(&priv->dp_transmit_idle_wait);
1681 priv->dp_throttled = 0; 1558 priv->dp_throttled = 0;
1682 priv->dp_throttle_restart = 0; 1559 priv->dp_throttle_restart = 0;
1683 init_waitqueue_head( &priv->dp_flush_wait ); 1560 init_waitqueue_head(&priv->dp_flush_wait);
1684 priv->dp_in_close = 0; 1561 priv->dp_in_close = 0;
1685 init_waitqueue_head( &priv->dp_close_wait ); 1562 init_waitqueue_head(&priv->dp_close_wait);
1686 INIT_WORK(&priv->dp_wakeup_work, digi_wakeup_write_lock); 1563 INIT_WORK(&priv->dp_wakeup_work, digi_wakeup_write_lock);
1687 priv->dp_port = serial->port[i]; 1564 priv->dp_port = serial->port[i];
1688
1689 /* initialize write wait queue for this port */ 1565 /* initialize write wait queue for this port */
1690 init_waitqueue_head( &serial->port[i]->write_wait ); 1566 init_waitqueue_head(&serial->port[i]->write_wait);
1691 1567
1692 usb_set_serial_port_data(serial->port[i], priv); 1568 usb_set_serial_port_data(serial->port[i], priv);
1693 } 1569 }
1694 1570
1695 /* allocate serial private structure */ 1571 /* allocate serial private structure */
1696 serial_priv = kmalloc( sizeof(struct digi_serial), 1572 serial_priv = kmalloc(sizeof(struct digi_serial), GFP_KERNEL);
1697 GFP_KERNEL ); 1573 if (serial_priv == NULL) {
1698 if( serial_priv == (struct digi_serial *)0 ) { 1574 for (i = 0; i < serial->type->num_ports + 1; i++)
1699 for( i=0; i<serial->type->num_ports+1; i++ ) 1575 kfree(usb_get_serial_port_data(serial->port[i]));
1700 kfree( usb_get_serial_port_data(serial->port[i]) ); 1576 return 1; /* error */
1701 return( 1 ); /* error */
1702 } 1577 }
1703 1578
1704 /* initialize serial private structure */ 1579 /* initialize serial private structure */
1705 spin_lock_init( &serial_priv->ds_serial_lock ); 1580 spin_lock_init(&serial_priv->ds_serial_lock);
1706 serial_priv->ds_oob_port_num = serial->type->num_ports; 1581 serial_priv->ds_oob_port_num = serial->type->num_ports;
1707 serial_priv->ds_oob_port = serial->port[serial_priv->ds_oob_port_num]; 1582 serial_priv->ds_oob_port = serial->port[serial_priv->ds_oob_port_num];
1708 serial_priv->ds_device_started = 0; 1583 serial_priv->ds_device_started = 0;
1709 usb_set_serial_data(serial, serial_priv); 1584 usb_set_serial_data(serial, serial_priv);
1710 1585
1711 return( 0 ); 1586 return 0;
1712
1713} 1587}
1714 1588
1715 1589
1716static void digi_shutdown( struct usb_serial *serial ) 1590static void digi_shutdown(struct usb_serial *serial)
1717{ 1591{
1718
1719 int i; 1592 int i;
1720 1593 dbg("digi_shutdown: TOP, in_interrupt()=%ld", in_interrupt());
1721
1722dbg( "digi_shutdown: TOP, in_interrupt()=%ld", in_interrupt() );
1723 1594
1724 /* stop reads and writes on all ports */ 1595 /* stop reads and writes on all ports */
1725 for( i=0; i<serial->type->num_ports+1; i++ ) { 1596 for (i = 0; i < serial->type->num_ports + 1; i++) {
1726 usb_kill_urb(serial->port[i]->read_urb); 1597 usb_kill_urb(serial->port[i]->read_urb);
1727 usb_kill_urb(serial->port[i]->write_urb); 1598 usb_kill_urb(serial->port[i]->write_urb);
1728 } 1599 }
1729 1600
1730 /* free the private data structures for all ports */ 1601 /* free the private data structures for all ports */
1731 /* number of regular ports + 1 for the out-of-band port */ 1602 /* number of regular ports + 1 for the out-of-band port */
1732 for( i=0; i<serial->type->num_ports+1; i++ ) 1603 for(i = 0; i < serial->type->num_ports + 1; i++)
1733 kfree( usb_get_serial_port_data(serial->port[i]) ); 1604 kfree(usb_get_serial_port_data(serial->port[i]));
1734 kfree( usb_get_serial_data(serial) ); 1605 kfree(usb_get_serial_data(serial));
1735} 1606}
1736 1607
1737 1608
1738static void digi_read_bulk_callback( struct urb *urb ) 1609static void digi_read_bulk_callback(struct urb *urb)
1739{ 1610{
1740
1741 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1611 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1742 struct digi_port *priv; 1612 struct digi_port *priv;
1743 struct digi_serial *serial_priv; 1613 struct digi_serial *serial_priv;
1744 int ret; 1614 int ret;
1745 int status = urb->status; 1615 int status = urb->status;
1746 1616
1747 1617 dbg("digi_read_bulk_callback: TOP");
1748dbg( "digi_read_bulk_callback: TOP" );
1749 1618
1750 /* port sanity check, do not resubmit if port is not valid */ 1619 /* port sanity check, do not resubmit if port is not valid */
1751 if( port == NULL || (priv=usb_get_serial_port_data(port)) == NULL ) { 1620 if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) {
1752 err("%s: port or port->private is NULL, status=%d", 1621 err("%s: port or port->private is NULL, status=%d",
1753 __FUNCTION__, status); 1622 __FUNCTION__, status);
1754 return; 1623 return;
1755 } 1624 }
1756 if( port->serial == NULL 1625 if (port->serial == NULL ||
1757 || (serial_priv=usb_get_serial_data(port->serial)) == NULL ) { 1626 (serial_priv=usb_get_serial_data(port->serial)) == NULL) {
1758 err("%s: serial is bad or serial->private is NULL, status=%d", 1627 err("%s: serial is bad or serial->private is NULL, status=%d",
1759 __FUNCTION__, status); 1628 __FUNCTION__, status);
1760 return; 1629 return;
1761 } 1630 }
1762 1631
@@ -1768,24 +1637,23 @@ dbg( "digi_read_bulk_callback: TOP" );
1768 } 1637 }
1769 1638
1770 /* handle oob or inb callback, do not resubmit if error */ 1639 /* handle oob or inb callback, do not resubmit if error */
1771 if( priv->dp_port_num == serial_priv->ds_oob_port_num ) { 1640 if (priv->dp_port_num == serial_priv->ds_oob_port_num) {
1772 if( digi_read_oob_callback( urb ) != 0 ) 1641 if (digi_read_oob_callback(urb) != 0)
1773 return; 1642 return;
1774 } else { 1643 } else {
1775 if( digi_read_inb_callback( urb ) != 0 ) 1644 if (digi_read_inb_callback(urb) != 0)
1776 return; 1645 return;
1777 } 1646 }
1778 1647
1779 /* continue read */ 1648 /* continue read */
1780 urb->dev = port->serial->dev; 1649 urb->dev = port->serial->dev;
1781 if( (ret=usb_submit_urb(urb, GFP_ATOMIC)) != 0 ) { 1650 if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
1782 err("%s: failed resubmitting urb, ret=%d, port=%d", __FUNCTION__, 1651 err("%s: failed resubmitting urb, ret=%d, port=%d",
1783 ret, priv->dp_port_num ); 1652 __FUNCTION__, ret, priv->dp_port_num);
1784 } 1653 }
1785 1654
1786} 1655}
1787 1656
1788
1789/* 1657/*
1790* Digi Read INB Callback 1658* Digi Read INB Callback
1791* 1659*
@@ -1796,7 +1664,7 @@ dbg( "digi_read_bulk_callback: TOP" );
1796* throttled, and -1 if the sanity checks failed. 1664* throttled, and -1 if the sanity checks failed.
1797*/ 1665*/
1798 1666
1799static int digi_read_inb_callback( struct urb *urb ) 1667static int digi_read_inb_callback(struct urb *urb)
1800{ 1668{
1801 1669
1802 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1670 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
@@ -1812,72 +1680,67 @@ static int digi_read_inb_callback( struct urb *urb )
1812 1680
1813 /* do not process callbacks on closed ports */ 1681 /* do not process callbacks on closed ports */
1814 /* but do continue the read chain */ 1682 /* but do continue the read chain */
1815 if( port->open_count == 0 ) 1683 if (port->open_count == 0)
1816 return( 0 ); 1684 return 0;
1817 1685
1818 /* short/multiple packet check */ 1686 /* short/multiple packet check */
1819 if( urb->actual_length != len + 2 ) { 1687 if (urb->actual_length != len + 2) {
1820 err("%s: INCOMPLETE OR MULTIPLE PACKET, urb status=%d, " 1688 err("%s: INCOMPLETE OR MULTIPLE PACKET, urb->status=%d, "
1821 "port=%d, opcode=%d, len=%d, actual_length=%d, " 1689 "port=%d, opcode=%d, len=%d, actual_length=%d, "
1822 "port_status=%d", __FUNCTION__, status, priv->dp_port_num, 1690 "status=%d", __FUNCTION__, status, priv->dp_port_num,
1823 opcode, len, urb->actual_length, port_status); 1691 opcode, len, urb->actual_length, port_status);
1824 return( -1 ); 1692 return -1;
1825 } 1693 }
1826 1694
1827 spin_lock( &priv->dp_port_lock ); 1695 spin_lock(&priv->dp_port_lock);
1828 1696
1829 /* check for throttle; if set, do not resubmit read urb */ 1697 /* check for throttle; if set, do not resubmit read urb */
1830 /* indicate the read chain needs to be restarted on unthrottle */ 1698 /* indicate the read chain needs to be restarted on unthrottle */
1831 throttled = priv->dp_throttled; 1699 throttled = priv->dp_throttled;
1832 if( throttled ) 1700 if (throttled)
1833 priv->dp_throttle_restart = 1; 1701 priv->dp_throttle_restart = 1;
1834 1702
1835 /* receive data */ 1703 /* receive data */
1836 if( opcode == DIGI_CMD_RECEIVE_DATA ) { 1704 if (opcode == DIGI_CMD_RECEIVE_DATA) {
1837
1838 /* get flag from port_status */ 1705 /* get flag from port_status */
1839 flag = 0; 1706 flag = 0;
1840 1707
1841 /* overrun is special, not associated with a char */ 1708 /* overrun is special, not associated with a char */
1842 if (port_status & DIGI_OVERRUN_ERROR) { 1709 if (port_status & DIGI_OVERRUN_ERROR)
1843 tty_insert_flip_char( tty, 0, TTY_OVERRUN ); 1710 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1844 }
1845 1711
1846 /* break takes precedence over parity, */ 1712 /* break takes precedence over parity, */
1847 /* which takes precedence over framing errors */ 1713 /* which takes precedence over framing errors */
1848 if (port_status & DIGI_BREAK_ERROR) { 1714 if (port_status & DIGI_BREAK_ERROR)
1849 flag = TTY_BREAK; 1715 flag = TTY_BREAK;
1850 } else if (port_status & DIGI_PARITY_ERROR) { 1716 else if (port_status & DIGI_PARITY_ERROR)
1851 flag = TTY_PARITY; 1717 flag = TTY_PARITY;
1852 } else if (port_status & DIGI_FRAMING_ERROR) { 1718 else if (port_status & DIGI_FRAMING_ERROR)
1853 flag = TTY_FRAME; 1719 flag = TTY_FRAME;
1854 }
1855 1720
1856 /* data length is len-1 (one byte of len is port_status) */ 1721 /* data length is len-1 (one byte of len is port_status) */
1857 --len; 1722 --len;
1858 1723
1859 len = tty_buffer_request_room(tty, len); 1724 len = tty_buffer_request_room(tty, len);
1860 if( len > 0 ) { 1725 if (len > 0) {
1861 /* Hot path */ 1726 /* Hot path */
1862 if(flag == TTY_NORMAL) 1727 if (flag == TTY_NORMAL)
1863 tty_insert_flip_string(tty, data, len); 1728 tty_insert_flip_string(tty, data, len);
1864 else { 1729 else {
1865 for(i = 0; i < len; i++) 1730 for(i = 0; i < len; i++)
1866 tty_insert_flip_char(tty, data[i], flag); 1731 tty_insert_flip_char(tty, data[i], flag);
1867 } 1732 }
1868 tty_flip_buffer_push( tty ); 1733 tty_flip_buffer_push(tty);
1869 } 1734 }
1870 } 1735 }
1736 spin_unlock(&priv->dp_port_lock);
1871 1737
1872 spin_unlock( &priv->dp_port_lock ); 1738 if (opcode == DIGI_CMD_RECEIVE_DISABLE)
1873 1739 dbg("%s: got RECEIVE_DISABLE", __FUNCTION__);
1874 if( opcode == DIGI_CMD_RECEIVE_DISABLE ) { 1740 else if (opcode != DIGI_CMD_RECEIVE_DATA)
1875 dbg("%s: got RECEIVE_DISABLE", __FUNCTION__ ); 1741 dbg("%s: unknown opcode: %d", __FUNCTION__, opcode);
1876 } else if( opcode != DIGI_CMD_RECEIVE_DATA ) {
1877 dbg("%s: unknown opcode: %d", __FUNCTION__, opcode );
1878 }
1879 1742
1880 return( throttled ? 1 : 0 ); 1743 return(throttled ? 1 : 0);
1881 1744
1882} 1745}
1883 1746
@@ -1891,7 +1754,7 @@ static int digi_read_inb_callback( struct urb *urb )
1891* -1 if the sanity checks failed. 1754* -1 if the sanity checks failed.
1892*/ 1755*/
1893 1756
1894static int digi_read_oob_callback( struct urb *urb ) 1757static int digi_read_oob_callback(struct urb *urb)
1895{ 1758{
1896 1759
1897 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 1760 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
@@ -1900,87 +1763,75 @@ static int digi_read_oob_callback( struct urb *urb )
1900 int opcode, line, status, val; 1763 int opcode, line, status, val;
1901 int i; 1764 int i;
1902 1765
1903 1766 dbg("digi_read_oob_callback: port=%d, len=%d",
1904dbg( "digi_read_oob_callback: port=%d, len=%d", priv->dp_port_num, 1767 priv->dp_port_num, urb->actual_length);
1905urb->actual_length );
1906 1768
1907 /* handle each oob command */ 1769 /* handle each oob command */
1908 for( i=0; i<urb->actual_length-3; ) { 1770 for(i = 0; i < urb->actual_length - 3;) {
1909
1910 opcode = ((unsigned char *)urb->transfer_buffer)[i++]; 1771 opcode = ((unsigned char *)urb->transfer_buffer)[i++];
1911 line = ((unsigned char *)urb->transfer_buffer)[i++]; 1772 line = ((unsigned char *)urb->transfer_buffer)[i++];
1912 status = ((unsigned char *)urb->transfer_buffer)[i++]; 1773 status = ((unsigned char *)urb->transfer_buffer)[i++];
1913 val = ((unsigned char *)urb->transfer_buffer)[i++]; 1774 val = ((unsigned char *)urb->transfer_buffer)[i++];
1914 1775
1915dbg( "digi_read_oob_callback: opcode=%d, line=%d, status=%d, val=%d", 1776 dbg("digi_read_oob_callback: opcode=%d, line=%d, status=%d, val=%d",
1916opcode, line, status, val ); 1777 opcode, line, status, val);
1917 1778
1918 if( status != 0 || line >= serial->type->num_ports ) 1779 if (status != 0 || line >= serial->type->num_ports)
1919 continue; 1780 continue;
1920 1781
1921 port = serial->port[line]; 1782 port = serial->port[line];
1922 1783
1923 if ((priv=usb_get_serial_port_data(port)) == NULL ) 1784 if ((priv=usb_get_serial_port_data(port)) == NULL)
1924 return -1; 1785 return -1;
1925 1786
1926 if( opcode == DIGI_CMD_READ_INPUT_SIGNALS ) { 1787 if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) {
1927 1788 spin_lock(&priv->dp_port_lock);
1928 spin_lock( &priv->dp_port_lock );
1929
1930 /* convert from digi flags to termiox flags */ 1789 /* convert from digi flags to termiox flags */
1931 if( val & DIGI_READ_INPUT_SIGNALS_CTS ) { 1790 if (val & DIGI_READ_INPUT_SIGNALS_CTS) {
1932 priv->dp_modem_signals |= TIOCM_CTS; 1791 priv->dp_modem_signals |= TIOCM_CTS;
1933 /* port must be open to use tty struct */ 1792 /* port must be open to use tty struct */
1934 if( port->open_count 1793 if (port->open_count
1935 && port->tty->termios->c_cflag & CRTSCTS ) { 1794 && port->tty->termios->c_cflag & CRTSCTS) {
1936 port->tty->hw_stopped = 0; 1795 port->tty->hw_stopped = 0;
1937 digi_wakeup_write( port ); 1796 digi_wakeup_write(port);
1938 } 1797 }
1939 } else { 1798 } else {
1940 priv->dp_modem_signals &= ~TIOCM_CTS; 1799 priv->dp_modem_signals &= ~TIOCM_CTS;
1941 /* port must be open to use tty struct */ 1800 /* port must be open to use tty struct */
1942 if( port->open_count 1801 if (port->open_count
1943 && port->tty->termios->c_cflag & CRTSCTS ) { 1802 && port->tty->termios->c_cflag & CRTSCTS) {
1944 port->tty->hw_stopped = 1; 1803 port->tty->hw_stopped = 1;
1945 } 1804 }
1946 } 1805 }
1947 if( val & DIGI_READ_INPUT_SIGNALS_DSR ) 1806 if (val & DIGI_READ_INPUT_SIGNALS_DSR)
1948 priv->dp_modem_signals |= TIOCM_DSR; 1807 priv->dp_modem_signals |= TIOCM_DSR;
1949 else 1808 else
1950 priv->dp_modem_signals &= ~TIOCM_DSR; 1809 priv->dp_modem_signals &= ~TIOCM_DSR;
1951 if( val & DIGI_READ_INPUT_SIGNALS_RI ) 1810 if (val & DIGI_READ_INPUT_SIGNALS_RI)
1952 priv->dp_modem_signals |= TIOCM_RI; 1811 priv->dp_modem_signals |= TIOCM_RI;
1953 else 1812 else
1954 priv->dp_modem_signals &= ~TIOCM_RI; 1813 priv->dp_modem_signals &= ~TIOCM_RI;
1955 if( val & DIGI_READ_INPUT_SIGNALS_DCD ) 1814 if (val & DIGI_READ_INPUT_SIGNALS_DCD)
1956 priv->dp_modem_signals |= TIOCM_CD; 1815 priv->dp_modem_signals |= TIOCM_CD;
1957 else 1816 else
1958 priv->dp_modem_signals &= ~TIOCM_CD; 1817 priv->dp_modem_signals &= ~TIOCM_CD;
1959 1818
1960 wake_up_interruptible( &priv->dp_modem_change_wait ); 1819 wake_up_interruptible(&priv->dp_modem_change_wait);
1961 spin_unlock( &priv->dp_port_lock ); 1820 spin_unlock(&priv->dp_port_lock);
1962 1821 } else if (opcode == DIGI_CMD_TRANSMIT_IDLE) {
1963 } else if( opcode == DIGI_CMD_TRANSMIT_IDLE ) { 1822 spin_lock(&priv->dp_port_lock);
1964
1965 spin_lock( &priv->dp_port_lock );
1966 priv->dp_transmit_idle = 1; 1823 priv->dp_transmit_idle = 1;
1967 wake_up_interruptible( &priv->dp_transmit_idle_wait ); 1824 wake_up_interruptible(&priv->dp_transmit_idle_wait);
1968 spin_unlock( &priv->dp_port_lock ); 1825 spin_unlock(&priv->dp_port_lock);
1969 1826 } else if (opcode == DIGI_CMD_IFLUSH_FIFO) {
1970 } else if( opcode == DIGI_CMD_IFLUSH_FIFO ) { 1827 wake_up_interruptible(&priv->dp_flush_wait);
1971
1972 wake_up_interruptible( &priv->dp_flush_wait );
1973
1974 } 1828 }
1975
1976 } 1829 }
1977 1830 return 0;
1978 return( 0 );
1979 1831
1980} 1832}
1981 1833
1982 1834static int __init digi_init(void)
1983static int __init digi_init (void)
1984{ 1835{
1985 int retval; 1836 int retval;
1986 retval = usb_serial_register(&digi_acceleport_2_device); 1837 retval = usb_serial_register(&digi_acceleport_2_device);
@@ -2002,12 +1853,11 @@ failed_acceleport_2_device:
2002 return retval; 1853 return retval;
2003} 1854}
2004 1855
2005
2006static void __exit digi_exit (void) 1856static void __exit digi_exit (void)
2007{ 1857{
2008 usb_deregister (&digi_driver); 1858 usb_deregister(&digi_driver);
2009 usb_serial_deregister (&digi_acceleport_2_device); 1859 usb_serial_deregister(&digi_acceleport_2_device);
2010 usb_serial_deregister (&digi_acceleport_4_device); 1860 usb_serial_deregister(&digi_acceleport_4_device);
2011} 1861}
2012 1862
2013 1863
@@ -2015,8 +1865,8 @@ module_init(digi_init);
2015module_exit(digi_exit); 1865module_exit(digi_exit);
2016 1866
2017 1867
2018MODULE_AUTHOR( DRIVER_AUTHOR ); 1868MODULE_AUTHOR(DRIVER_AUTHOR);
2019MODULE_DESCRIPTION( DRIVER_DESC ); 1869MODULE_DESCRIPTION(DRIVER_DESC);
2020MODULE_LICENSE("GPL"); 1870MODULE_LICENSE("GPL");
2021 1871
2022module_param(debug, bool, S_IRUGO | S_IWUSR); 1872module_param(debug, bool, S_IRUGO | S_IWUSR);