aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial
diff options
context:
space:
mode:
authorAlan Cox <alan@lxorguk.ukuu.org.uk>2007-08-22 18:09:16 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:55:20 -0400
commit94d0f7eac77a84da2cee41b8038796891f75f09e (patch)
treed7720a684ada866fdd62ca35faf84879cfa54821 /drivers/usb/serial
parentc4e41562e09961df6ba72b49269793d21c0034dc (diff)
USB: kobil_sct: Rework driver
No hardware but this driver is currently totally broken so we can't make it much worse. Remove all tbe broken invalid termios handling and replace it with a proper set_termios method. Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/serial')
-rw-r--r--drivers/usb/serial/kobil_sct.c144
1 files changed, 55 insertions, 89 deletions
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 02a86dbc0e97..6f224195bd25 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -82,6 +82,7 @@ static int kobil_tiocmset(struct usb_serial_port *port, struct file *file,
82 unsigned int set, unsigned int clear); 82 unsigned int set, unsigned int clear);
83static void kobil_read_int_callback( struct urb *urb ); 83static void kobil_read_int_callback( struct urb *urb );
84static void kobil_write_callback( struct urb *purb ); 84static void kobil_write_callback( struct urb *purb );
85static void kobil_set_termios(struct usb_serial_port *port, struct ktermios *old);
85 86
86 87
87static struct usb_device_id id_table [] = { 88static struct usb_device_id id_table [] = {
@@ -119,6 +120,7 @@ static struct usb_serial_driver kobil_device = {
119 .attach = kobil_startup, 120 .attach = kobil_startup,
120 .shutdown = kobil_shutdown, 121 .shutdown = kobil_shutdown,
121 .ioctl = kobil_ioctl, 122 .ioctl = kobil_ioctl,
123 .set_termios = kobil_set_termios,
122 .tiocmget = kobil_tiocmget, 124 .tiocmget = kobil_tiocmget,
123 .tiocmset = kobil_tiocmset, 125 .tiocmset = kobil_tiocmset,
124 .open = kobil_open, 126 .open = kobil_open,
@@ -137,7 +139,6 @@ struct kobil_private {
137 int cur_pos; // index of the next char to send in buf 139 int cur_pos; // index of the next char to send in buf
138 __u16 device_type; 140 __u16 device_type;
139 int line_state; 141 int line_state;
140 struct ktermios internal_termios;
141}; 142};
142 143
143 144
@@ -216,7 +217,7 @@ static void kobil_shutdown (struct usb_serial *serial)
216 217
217static int kobil_open (struct usb_serial_port *port, struct file *filp) 218static int kobil_open (struct usb_serial_port *port, struct file *filp)
218{ 219{
219 int i, result = 0; 220 int result = 0;
220 struct kobil_private *priv; 221 struct kobil_private *priv;
221 unsigned char *transfer_buffer; 222 unsigned char *transfer_buffer;
222 int transfer_buffer_length = 8; 223 int transfer_buffer_length = 8;
@@ -242,16 +243,6 @@ static int kobil_open (struct usb_serial_port *port, struct file *filp)
242 port->tty->termios->c_iflag = IGNBRK | IGNPAR | IXOFF; 243 port->tty->termios->c_iflag = IGNBRK | IGNPAR | IXOFF;
243 port->tty->termios->c_oflag &= ~ONLCR; // do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D) 244 port->tty->termios->c_oflag &= ~ONLCR; // do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D)
244 245
245 // set up internal termios structure
246 priv->internal_termios.c_iflag = port->tty->termios->c_iflag;
247 priv->internal_termios.c_oflag = port->tty->termios->c_oflag;
248 priv->internal_termios.c_cflag = port->tty->termios->c_cflag;
249 priv->internal_termios.c_lflag = port->tty->termios->c_lflag;
250
251 for (i=0; i<NCCS; i++) {
252 priv->internal_termios.c_cc[i] = port->tty->termios->c_cc[i];
253 }
254
255 // allocate memory for transfer buffer 246 // allocate memory for transfer buffer
256 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL); 247 transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
257 if (! transfer_buffer) { 248 if (! transfer_buffer) {
@@ -607,102 +598,79 @@ static int kobil_tiocmset(struct usb_serial_port *port, struct file *file,
607 return (result < 0) ? result : 0; 598 return (result < 0) ? result : 0;
608} 599}
609 600
610 601static void kobil_set_termios(struct usb_serial_port *port, struct ktermios *old)
611static int kobil_ioctl(struct usb_serial_port *port, struct file *file,
612 unsigned int cmd, unsigned long arg)
613{ 602{
614 struct kobil_private * priv; 603 struct kobil_private * priv;
615 int result; 604 int result;
616 unsigned short urb_val = 0; 605 unsigned short urb_val = 0;
617 unsigned char *transfer_buffer; 606 int c_cflag = port->tty->termios->c_cflag;
618 int transfer_buffer_length = 8; 607 speed_t speed;
619 char *settings; 608 void * settings;
620 void __user *user_arg = (void __user *)arg;
621 609
622 priv = usb_get_serial_port_data(port); 610 priv = usb_get_serial_port_data(port);
623 if ((priv->device_type == KOBIL_USBTWIN_PRODUCT_ID) || (priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID)) { 611 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID)
624 // This device doesn't support ioctl calls 612 // This device doesn't support ioctl calls
625 return 0; 613 return;
626 }
627
628 switch (cmd) {
629 case TCGETS: // 0x5401
630 if (!access_ok(VERIFY_WRITE, user_arg, sizeof(struct ktermios))) {
631 dbg("%s - port %d Error in access_ok", __FUNCTION__, port->number);
632 return -EFAULT;
633 }
634 if (kernel_termios_to_user_termios((struct ktermios __user *)arg,
635 &priv->internal_termios))
636 return -EFAULT;
637 return 0;
638
639 case TCSETS: // 0x5402
640 if (!(port->tty->termios)) {
641 dbg("%s - port %d Error: port->tty->termios is NULL", __FUNCTION__, port->number);
642 return -ENOTTY;
643 }
644 if (!access_ok(VERIFY_READ, user_arg, sizeof(struct ktermios))) {
645 dbg("%s - port %d Error in access_ok", __FUNCTION__, port->number);
646 return -EFAULT;
647 }
648 if (user_termios_to_kernel_termios(&priv->internal_termios,
649 (struct ktermios __user *)arg))
650 return -EFAULT;
651
652 settings = kzalloc(50, GFP_KERNEL);
653 if (! settings) {
654 return -ENOBUFS;
655 }
656 614
657 switch (priv->internal_termios.c_cflag & CBAUD) { 615 switch (speed = tty_get_baud_rate(port->tty)) {
658 case B1200: 616 case 1200:
659 urb_val = SUSBCR_SBR_1200; 617 urb_val = SUSBCR_SBR_1200;
660 strcat(settings, "1200 ");
661 break; 618 break;
662 case B9600: 619 case 9600:
663 default: 620 default:
664 urb_val = SUSBCR_SBR_9600; 621 urb_val = SUSBCR_SBR_9600;
665 strcat(settings, "9600 ");
666 break; 622 break;
667 } 623 }
624 urb_val |= (c_cflag & CSTOPB) ? SUSBCR_SPASB_2StopBits : SUSBCR_SPASB_1StopBit;
625
626 settings = kzalloc(50, GFP_KERNEL);
627 if (! settings)
628 return;
668 629
669 urb_val |= (priv->internal_termios.c_cflag & CSTOPB) ? SUSBCR_SPASB_2StopBits : SUSBCR_SPASB_1StopBit; 630 sprintf(settings, "%d ", speed);
670 strcat(settings, (priv->internal_termios.c_cflag & CSTOPB) ? "2 StopBits " : "1 StopBit ");
671 631
672 if (priv->internal_termios.c_cflag & PARENB) { 632 if (c_cflag & PARENB) {
673 if (priv->internal_termios.c_cflag & PARODD) { 633 if (c_cflag & PARODD) {
674 urb_val |= SUSBCR_SPASB_OddParity; 634 urb_val |= SUSBCR_SPASB_OddParity;
675 strcat(settings, "Odd Parity"); 635 strcat(settings, "Odd Parity");
676 } else {
677 urb_val |= SUSBCR_SPASB_EvenParity;
678 strcat(settings, "Even Parity");
679 }
680 } else { 636 } else {
681 urb_val |= SUSBCR_SPASB_NoParity; 637 urb_val |= SUSBCR_SPASB_EvenParity;
682 strcat(settings, "No Parity"); 638 strcat(settings, "Even Parity");
683 } 639 }
684 dbg("%s - port %d setting port to: %s", __FUNCTION__, port->number, settings ); 640 } else {
641 urb_val |= SUSBCR_SPASB_NoParity;
642 strcat(settings, "No Parity");
643 }
685 644
686 result = usb_control_msg( port->serial->dev, 645 result = usb_control_msg( port->serial->dev,
687 usb_rcvctrlpipe(port->serial->dev, 0 ), 646 usb_rcvctrlpipe(port->serial->dev, 0 ),
688 SUSBCRequest_SetBaudRateParityAndStopBits, 647 SUSBCRequest_SetBaudRateParityAndStopBits,
689 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, 648 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
690 urb_val, 649 urb_val,
691 0, 650 0,
692 settings, 651 settings,
693 0, 652 0,
694 KOBIL_TIMEOUT 653 KOBIL_TIMEOUT
695 ); 654 );
655 kfree(settings);
656}
696 657
697 dbg("%s - port %d Send set_baudrate URB returns: %i", __FUNCTION__, port->number, result); 658static int kobil_ioctl(struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
698 kfree(settings); 659{
660 struct kobil_private * priv = usb_get_serial_port_data(port);
661 unsigned char *transfer_buffer;
662 int transfer_buffer_length = 8;
663 int result;
664
665 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || priv->device_type == KOBIL_KAAN_SIM_PRODUCT_ID)
666 // This device doesn't support ioctl calls
699 return 0; 667 return 0;
700 668
669 switch (cmd) {
701 case TCFLSH: // 0x540B 670 case TCFLSH: // 0x540B
702 transfer_buffer = kmalloc(transfer_buffer_length, GFP_KERNEL); 671 transfer_buffer = kmalloc(transfer_buffer_length, GFP_KERNEL);
703 if (! transfer_buffer) { 672 if (! transfer_buffer)
704 return -ENOBUFS; 673 return -ENOBUFS;
705 }
706 674
707 result = usb_control_msg( port->serial->dev, 675 result = usb_control_msg( port->serial->dev,
708 usb_rcvctrlpipe(port->serial->dev, 0 ), 676 usb_rcvctrlpipe(port->serial->dev, 0 ),
@@ -716,15 +684,13 @@ static int kobil_ioctl(struct usb_serial_port *port, struct file *file,
716 ); 684 );
717 685
718 dbg("%s - port %d Send reset_all_queues (FLUSH) URB returns: %i", __FUNCTION__, port->number, result); 686 dbg("%s - port %d Send reset_all_queues (FLUSH) URB returns: %i", __FUNCTION__, port->number, result);
719
720 kfree(transfer_buffer); 687 kfree(transfer_buffer);
721 return ((result < 0) ? -EFAULT : 0); 688 return (result < 0) ? -EFAULT : 0;
722 689 default:
690 return -ENOIOCTLCMD;
723 } 691 }
724 return -ENOIOCTLCMD;
725} 692}
726 693
727
728static int __init kobil_init (void) 694static int __init kobil_init (void)
729{ 695{
730 int retval; 696 int retval;