aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/option.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/option.c')
-rw-r--r--drivers/usb/serial/option.c166
1 files changed, 73 insertions, 93 deletions
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 1e936a1cbe0b..e4eca95f2b0f 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -43,29 +43,25 @@
43#include <linux/usb/serial.h> 43#include <linux/usb/serial.h>
44 44
45/* Function prototypes */ 45/* Function prototypes */
46static int option_open(struct usb_serial_port *port, struct file *filp); 46static int option_open(struct tty_struct *tty, struct usb_serial_port *port,
47static void option_close(struct usb_serial_port *port, struct file *filp); 47 struct file *filp);
48static void option_close(struct tty_struct *tty, struct usb_serial_port *port,
49 struct file *filp);
48static int option_startup(struct usb_serial *serial); 50static int option_startup(struct usb_serial *serial);
49static void option_shutdown(struct usb_serial *serial); 51static void option_shutdown(struct usb_serial *serial);
50static void option_rx_throttle(struct usb_serial_port *port); 52static int option_write_room(struct tty_struct *tty);
51static void option_rx_unthrottle(struct usb_serial_port *port);
52static int option_write_room(struct usb_serial_port *port);
53 53
54static void option_instat_callback(struct urb *urb); 54static void option_instat_callback(struct urb *urb);
55 55
56static int option_write(struct usb_serial_port *port, 56static int option_write(struct tty_struct *tty, struct usb_serial_port *port,
57 const unsigned char *buf, int count); 57 const unsigned char *buf, int count);
58 58static int option_chars_in_buffer(struct tty_struct *tty);
59static int option_chars_in_buffer(struct usb_serial_port *port); 59static void option_set_termios(struct tty_struct *tty,
60static int option_ioctl(struct usb_serial_port *port, struct file *file, 60 struct usb_serial_port *port, struct ktermios *old);
61 unsigned int cmd, unsigned long arg); 61static int option_tiocmget(struct tty_struct *tty, struct file *file);
62static void option_set_termios(struct usb_serial_port *port, 62static int option_tiocmset(struct tty_struct *tty, struct file *file,
63 struct ktermios *old);
64static void option_break_ctl(struct usb_serial_port *port, int break_state);
65static int option_tiocmget(struct usb_serial_port *port, struct file *file);
66static int option_tiocmset(struct usb_serial_port *port, struct file *file,
67 unsigned int set, unsigned int clear); 63 unsigned int set, unsigned int clear);
68static int option_send_setup(struct usb_serial_port *port); 64static int option_send_setup(struct tty_struct *tty, struct usb_serial_port *port);
69 65
70/* Vendor and product IDs */ 66/* Vendor and product IDs */
71#define OPTION_VENDOR_ID 0x0AF0 67#define OPTION_VENDOR_ID 0x0AF0
@@ -342,11 +338,7 @@ static struct usb_serial_driver option_1port_device = {
342 .write = option_write, 338 .write = option_write,
343 .write_room = option_write_room, 339 .write_room = option_write_room,
344 .chars_in_buffer = option_chars_in_buffer, 340 .chars_in_buffer = option_chars_in_buffer,
345 .throttle = option_rx_throttle,
346 .unthrottle = option_rx_unthrottle,
347 .ioctl = option_ioctl,
348 .set_termios = option_set_termios, 341 .set_termios = option_set_termios,
349 .break_ctl = option_break_ctl,
350 .tiocmget = option_tiocmget, 342 .tiocmget = option_tiocmget,
351 .tiocmset = option_tiocmset, 343 .tiocmset = option_tiocmset,
352 .attach = option_startup, 344 .attach = option_startup,
@@ -403,47 +395,32 @@ static int __init option_init(void)
403 return 0; 395 return 0;
404 396
405failed_driver_register: 397failed_driver_register:
406 usb_serial_deregister (&option_1port_device); 398 usb_serial_deregister(&option_1port_device);
407failed_1port_device_register: 399failed_1port_device_register:
408 return retval; 400 return retval;
409} 401}
410 402
411static void __exit option_exit(void) 403static void __exit option_exit(void)
412{ 404{
413 usb_deregister (&option_driver); 405 usb_deregister(&option_driver);
414 usb_serial_deregister (&option_1port_device); 406 usb_serial_deregister(&option_1port_device);
415} 407}
416 408
417module_init(option_init); 409module_init(option_init);
418module_exit(option_exit); 410module_exit(option_exit);
419 411
420static void option_rx_throttle(struct usb_serial_port *port) 412static void option_set_termios(struct tty_struct *tty,
421{ 413 struct usb_serial_port *port, struct ktermios *old_termios)
422 dbg("%s", __func__);
423}
424
425static void option_rx_unthrottle(struct usb_serial_port *port)
426{
427 dbg("%s", __func__);
428}
429
430static void option_break_ctl(struct usb_serial_port *port, int break_state)
431{
432 /* Unfortunately, I don't know how to send a break */
433 dbg("%s", __func__);
434}
435
436static void option_set_termios(struct usb_serial_port *port,
437 struct ktermios *old_termios)
438{ 414{
439 dbg("%s", __func__); 415 dbg("%s", __func__);
440 /* Doesn't support option setting */ 416 /* Doesn't support option setting */
441 tty_termios_copy_hw(port->tty->termios, old_termios); 417 tty_termios_copy_hw(tty->termios, old_termios);
442 option_send_setup(port); 418 option_send_setup(tty, port);
443} 419}
444 420
445static int option_tiocmget(struct usb_serial_port *port, struct file *file) 421static int option_tiocmget(struct tty_struct *tty, struct file *file)
446{ 422{
423 struct usb_serial_port *port = tty->driver_data;
447 unsigned int value; 424 unsigned int value;
448 struct option_port_private *portdata; 425 struct option_port_private *portdata;
449 426
@@ -459,9 +436,10 @@ static int option_tiocmget(struct usb_serial_port *port, struct file *file)
459 return value; 436 return value;
460} 437}
461 438
462static int option_tiocmset(struct usb_serial_port *port, struct file *file, 439static int option_tiocmset(struct tty_struct *tty, struct file *file,
463 unsigned int set, unsigned int clear) 440 unsigned int set, unsigned int clear)
464{ 441{
442 struct usb_serial_port *port = tty->driver_data;
465 struct option_port_private *portdata; 443 struct option_port_private *portdata;
466 444
467 portdata = usb_get_serial_port_data(port); 445 portdata = usb_get_serial_port_data(port);
@@ -476,17 +454,11 @@ static int option_tiocmset(struct usb_serial_port *port, struct file *file,
476 portdata->rts_state = 0; 454 portdata->rts_state = 0;
477 if (clear & TIOCM_DTR) 455 if (clear & TIOCM_DTR)
478 portdata->dtr_state = 0; 456 portdata->dtr_state = 0;
479 return option_send_setup(port); 457 return option_send_setup(tty, port);
480}
481
482static int option_ioctl(struct usb_serial_port *port, struct file *file,
483 unsigned int cmd, unsigned long arg)
484{
485 return -ENOIOCTLCMD;
486} 458}
487 459
488/* Write */ 460/* Write */
489static int option_write(struct usb_serial_port *port, 461static int option_write(struct tty_struct *tty, struct usb_serial_port *port,
490 const unsigned char *buf, int count) 462 const unsigned char *buf, int count)
491{ 463{
492 struct option_port_private *portdata; 464 struct option_port_private *portdata;
@@ -501,7 +473,7 @@ static int option_write(struct usb_serial_port *port,
501 473
502 i = 0; 474 i = 0;
503 left = count; 475 left = count;
504 for (i=0; left > 0 && i < N_OUT_URB; i++) { 476 for (i = 0; left > 0 && i < N_OUT_URB; i++) {
505 todo = left; 477 todo = left;
506 if (todo > OUT_BUFLEN) 478 if (todo > OUT_BUFLEN)
507 todo = OUT_BUFLEN; 479 todo = OUT_BUFLEN;
@@ -522,7 +494,7 @@ static int option_write(struct usb_serial_port *port,
522 usb_pipeendpoint(this_urb->pipe), i); 494 usb_pipeendpoint(this_urb->pipe), i);
523 495
524 /* send the data */ 496 /* send the data */
525 memcpy (this_urb->transfer_buffer, buf, todo); 497 memcpy(this_urb->transfer_buffer, buf, todo);
526 this_urb->transfer_buffer_length = todo; 498 this_urb->transfer_buffer_length = todo;
527 499
528 this_urb->dev = port->serial->dev; 500 this_urb->dev = port->serial->dev;
@@ -562,7 +534,7 @@ static void option_indat_callback(struct urb *urb)
562 dbg("%s: nonzero status: %d on endpoint %02x.", 534 dbg("%s: nonzero status: %d on endpoint %02x.",
563 __func__, status, endpoint); 535 __func__, status, endpoint);
564 } else { 536 } else {
565 tty = port->tty; 537 tty = port->port.tty;
566 if (urb->actual_length) { 538 if (urb->actual_length) {
567 tty_buffer_request_room(tty, urb->actual_length); 539 tty_buffer_request_room(tty, urb->actual_length);
568 tty_insert_flip_string(tty, data, urb->actual_length); 540 tty_insert_flip_string(tty, data, urb->actual_length);
@@ -572,7 +544,7 @@ static void option_indat_callback(struct urb *urb)
572 } 544 }
573 545
574 /* Resubmit urb so we continue receiving */ 546 /* Resubmit urb so we continue receiving */
575 if (port->open_count && status != -ESHUTDOWN) { 547 if (port->port.count && status != -ESHUTDOWN) {
576 err = usb_submit_urb(urb, GFP_ATOMIC); 548 err = usb_submit_urb(urb, GFP_ATOMIC);
577 if (err) 549 if (err)
578 printk(KERN_ERR "%s: resubmit read urb failed. " 550 printk(KERN_ERR "%s: resubmit read urb failed. "
@@ -613,7 +585,7 @@ static void option_instat_callback(struct urb *urb)
613 struct usb_serial *serial = port->serial; 585 struct usb_serial *serial = port->serial;
614 586
615 dbg("%s", __func__); 587 dbg("%s", __func__);
616 dbg("%s: urb %p port %p has data %p", __func__,urb,port,portdata); 588 dbg("%s: urb %p port %p has data %p", __func__, urb, port, portdata);
617 589
618 if (status == 0) { 590 if (status == 0) {
619 struct usb_ctrlrequest *req_pkt = 591 struct usb_ctrlrequest *req_pkt =
@@ -638,12 +610,12 @@ static void option_instat_callback(struct urb *urb)
638 portdata->dsr_state = ((signals & 0x02) ? 1 : 0); 610 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
639 portdata->ri_state = ((signals & 0x08) ? 1 : 0); 611 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
640 612
641 if (port->tty && !C_CLOCAL(port->tty) && 613 if (port->port.tty && !C_CLOCAL(port->port.tty) &&
642 old_dcd_state && !portdata->dcd_state) 614 old_dcd_state && !portdata->dcd_state)
643 tty_hangup(port->tty); 615 tty_hangup(port->port.tty);
644 } else { 616 } else {
645 dbg("%s: type %x req %x", __func__, 617 dbg("%s: type %x req %x", __func__,
646 req_pkt->bRequestType,req_pkt->bRequest); 618 req_pkt->bRequestType, req_pkt->bRequest);
647 } 619 }
648 } else 620 } else
649 dbg("%s: error %d", __func__, status); 621 dbg("%s: error %d", __func__, status);
@@ -658,8 +630,9 @@ static void option_instat_callback(struct urb *urb)
658 } 630 }
659} 631}
660 632
661static int option_write_room(struct usb_serial_port *port) 633static int option_write_room(struct tty_struct *tty)
662{ 634{
635 struct usb_serial_port *port = tty->driver_data;
663 struct option_port_private *portdata; 636 struct option_port_private *portdata;
664 int i; 637 int i;
665 int data_len = 0; 638 int data_len = 0;
@@ -668,7 +641,7 @@ static int option_write_room(struct usb_serial_port *port)
668 portdata = usb_get_serial_port_data(port); 641 portdata = usb_get_serial_port_data(port);
669 642
670 643
671 for (i=0; i < N_OUT_URB; i++) { 644 for (i = 0; i < N_OUT_URB; i++) {
672 this_urb = portdata->out_urbs[i]; 645 this_urb = portdata->out_urbs[i];
673 if (this_urb && !test_bit(i, &portdata->out_busy)) 646 if (this_urb && !test_bit(i, &portdata->out_busy))
674 data_len += OUT_BUFLEN; 647 data_len += OUT_BUFLEN;
@@ -678,8 +651,9 @@ static int option_write_room(struct usb_serial_port *port)
678 return data_len; 651 return data_len;
679} 652}
680 653
681static int option_chars_in_buffer(struct usb_serial_port *port) 654static int option_chars_in_buffer(struct tty_struct *tty)
682{ 655{
656 struct usb_serial_port *port = tty->driver_data;
683 struct option_port_private *portdata; 657 struct option_port_private *portdata;
684 int i; 658 int i;
685 int data_len = 0; 659 int data_len = 0;
@@ -687,7 +661,7 @@ static int option_chars_in_buffer(struct usb_serial_port *port)
687 661
688 portdata = usb_get_serial_port_data(port); 662 portdata = usb_get_serial_port_data(port);
689 663
690 for (i=0; i < N_OUT_URB; i++) { 664 for (i = 0; i < N_OUT_URB; i++) {
691 this_urb = portdata->out_urbs[i]; 665 this_urb = portdata->out_urbs[i];
692 /* FIXME: This locking is insufficient as this_urb may 666 /* FIXME: This locking is insufficient as this_urb may
693 go unused during the test */ 667 go unused during the test */
@@ -698,7 +672,8 @@ static int option_chars_in_buffer(struct usb_serial_port *port)
698 return data_len; 672 return data_len;
699} 673}
700 674
701static int option_open(struct usb_serial_port *port, struct file *filp) 675static int option_open(struct tty_struct *tty,
676 struct usb_serial_port *port, struct file *filp)
702{ 677{
703 struct option_port_private *portdata; 678 struct option_port_private *portdata;
704 struct usb_serial *serial = port->serial; 679 struct usb_serial *serial = port->serial;
@@ -716,7 +691,7 @@ static int option_open(struct usb_serial_port *port, struct file *filp)
716 /* Reset low level data toggle and start reading from endpoints */ 691 /* Reset low level data toggle and start reading from endpoints */
717 for (i = 0; i < N_IN_URB; i++) { 692 for (i = 0; i < N_IN_URB; i++) {
718 urb = portdata->in_urbs[i]; 693 urb = portdata->in_urbs[i];
719 if (! urb) 694 if (!urb)
720 continue; 695 continue;
721 if (urb->dev != serial->dev) { 696 if (urb->dev != serial->dev) {
722 dbg("%s: dev %p != %p", __func__, 697 dbg("%s: dev %p != %p", __func__,
@@ -741,21 +716,23 @@ static int option_open(struct usb_serial_port *port, struct file *filp)
741 /* Reset low level data toggle on out endpoints */ 716 /* Reset low level data toggle on out endpoints */
742 for (i = 0; i < N_OUT_URB; i++) { 717 for (i = 0; i < N_OUT_URB; i++) {
743 urb = portdata->out_urbs[i]; 718 urb = portdata->out_urbs[i];
744 if (! urb) 719 if (!urb)
745 continue; 720 continue;
746 urb->dev = serial->dev; 721 urb->dev = serial->dev;
747 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), 722 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
748 usb_pipeout(urb->pipe), 0); */ 723 usb_pipeout(urb->pipe), 0); */
749 } 724 }
750 725
751 port->tty->low_latency = 1; 726 if (tty)
727 tty->low_latency = 1;
752 728
753 option_send_setup(port); 729 option_send_setup(tty, port);
754 730
755 return (0); 731 return 0;
756} 732}
757 733
758static void option_close(struct usb_serial_port *port, struct file *filp) 734static void option_close(struct tty_struct *tty,
735 struct usb_serial_port *port, struct file *filp)
759{ 736{
760 int i; 737 int i;
761 struct usb_serial *serial = port->serial; 738 struct usb_serial *serial = port->serial;
@@ -770,7 +747,7 @@ static void option_close(struct usb_serial_port *port, struct file *filp)
770 if (serial->dev) { 747 if (serial->dev) {
771 mutex_lock(&serial->disc_mutex); 748 mutex_lock(&serial->disc_mutex);
772 if (!serial->disconnected) 749 if (!serial->disconnected)
773 option_send_setup(port); 750 option_send_setup(tty, port);
774 mutex_unlock(&serial->disc_mutex); 751 mutex_unlock(&serial->disc_mutex);
775 752
776 /* Stop reading/writing urbs */ 753 /* Stop reading/writing urbs */
@@ -779,7 +756,7 @@ static void option_close(struct usb_serial_port *port, struct file *filp)
779 for (i = 0; i < N_OUT_URB; i++) 756 for (i = 0; i < N_OUT_URB; i++)
780 usb_kill_urb(portdata->out_urbs[i]); 757 usb_kill_urb(portdata->out_urbs[i]);
781 } 758 }
782 port->tty = NULL; 759 port->port.tty = NULL; /* FIXME */
783} 760}
784 761
785/* Helper functions used by option_setup_urbs */ 762/* Helper functions used by option_setup_urbs */
@@ -809,7 +786,7 @@ static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
809/* Setup urbs */ 786/* Setup urbs */
810static void option_setup_urbs(struct usb_serial *serial) 787static void option_setup_urbs(struct usb_serial *serial)
811{ 788{
812 int i,j; 789 int i, j;
813 struct usb_serial_port *port; 790 struct usb_serial_port *port;
814 struct option_port_private *portdata; 791 struct option_port_private *portdata;
815 792
@@ -819,18 +796,22 @@ static void option_setup_urbs(struct usb_serial *serial)
819 port = serial->port[i]; 796 port = serial->port[i];
820 portdata = usb_get_serial_port_data(port); 797 portdata = usb_get_serial_port_data(port);
821 798
822 /* Do indat endpoints first */ 799 /* Do indat endpoints first */
823 for (j = 0; j < N_IN_URB; ++j) { 800 for (j = 0; j < N_IN_URB; ++j) {
824 portdata->in_urbs[j] = option_setup_urb (serial, 801 portdata->in_urbs[j] = option_setup_urb(serial,
825 port->bulk_in_endpointAddress, USB_DIR_IN, port, 802 port->bulk_in_endpointAddress,
826 portdata->in_buffer[j], IN_BUFLEN, option_indat_callback); 803 USB_DIR_IN, port,
804 portdata->in_buffer[j],
805 IN_BUFLEN, option_indat_callback);
827 } 806 }
828 807
829 /* outdat endpoints */ 808 /* outdat endpoints */
830 for (j = 0; j < N_OUT_URB; ++j) { 809 for (j = 0; j < N_OUT_URB; ++j) {
831 portdata->out_urbs[j] = option_setup_urb (serial, 810 portdata->out_urbs[j] = option_setup_urb(serial,
832 port->bulk_out_endpointAddress, USB_DIR_OUT, port, 811 port->bulk_out_endpointAddress,
833 portdata->out_buffer[j], OUT_BUFLEN, option_outdat_callback); 812 USB_DIR_OUT, port,
813 portdata->out_buffer[j],
814 OUT_BUFLEN, option_outdat_callback);
834 } 815 }
835 } 816 }
836} 817}
@@ -841,7 +822,8 @@ static void option_setup_urbs(struct usb_serial *serial)
841 * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN 822 * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN
842 * CDC. 823 * CDC.
843*/ 824*/
844static int option_send_setup(struct usb_serial_port *port) 825static int option_send_setup(struct tty_struct *tty,
826 struct usb_serial_port *port)
845{ 827{
846 struct usb_serial *serial = port->serial; 828 struct usb_serial *serial = port->serial;
847 struct option_port_private *portdata; 829 struct option_port_private *portdata;
@@ -850,7 +832,7 @@ static int option_send_setup(struct usb_serial_port *port)
850 832
851 portdata = usb_get_serial_port_data(port); 833 portdata = usb_get_serial_port_data(port);
852 834
853 if (port->tty) { 835 if (tty) {
854 int val = 0; 836 int val = 0;
855 if (portdata->dtr_state) 837 if (portdata->dtr_state)
856 val |= 0x01; 838 val |= 0x01;
@@ -858,10 +840,9 @@ static int option_send_setup(struct usb_serial_port *port)
858 val |= 0x02; 840 val |= 0x02;
859 841
860 return usb_control_msg(serial->dev, 842 return usb_control_msg(serial->dev,
861 usb_rcvctrlpipe(serial->dev, 0), 843 usb_rcvctrlpipe(serial->dev, 0),
862 0x22,0x21,val,ifNum,NULL,0,USB_CTRL_SET_TIMEOUT); 844 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT);
863 } 845 }
864
865 return 0; 846 return 0;
866} 847}
867 848
@@ -881,7 +862,7 @@ static int option_startup(struct usb_serial *serial)
881 if (!portdata) { 862 if (!portdata) {
882 dbg("%s: kmalloc for option_port_private (%d) failed!.", 863 dbg("%s: kmalloc for option_port_private (%d) failed!.",
883 __func__, i); 864 __func__, i);
884 return (1); 865 return 1;
885 } 866 }
886 867
887 for (j = 0; j < N_IN_URB; j++) { 868 for (j = 0; j < N_IN_URB; j++) {
@@ -900,17 +881,15 @@ static int option_startup(struct usb_serial *serial)
900 881
901 usb_set_serial_port_data(port, portdata); 882 usb_set_serial_port_data(port, portdata);
902 883
903 if (! port->interrupt_in_urb) 884 if (!port->interrupt_in_urb)
904 continue; 885 continue;
905 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 886 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
906 if (err) 887 if (err)
907 dbg("%s: submit irq_in urb failed %d", 888 dbg("%s: submit irq_in urb failed %d",
908 __func__, err); 889 __func__, err);
909 } 890 }
910
911 option_setup_urbs(serial); 891 option_setup_urbs(serial);
912 892 return 0;
913 return (0);
914 893
915bail_out_error2: 894bail_out_error2:
916 for (j = 0; j < N_OUT_URB; j++) 895 for (j = 0; j < N_OUT_URB; j++)
@@ -949,7 +928,8 @@ static void option_shutdown(struct usb_serial *serial)
949 for (j = 0; j < N_IN_URB; j++) { 928 for (j = 0; j < N_IN_URB; j++) {
950 if (portdata->in_urbs[j]) { 929 if (portdata->in_urbs[j]) {
951 usb_free_urb(portdata->in_urbs[j]); 930 usb_free_urb(portdata->in_urbs[j]);
952 free_page((unsigned long)portdata->in_buffer[j]); 931 free_page((unsigned long)
932 portdata->in_buffer[j]);
953 portdata->in_urbs[j] = NULL; 933 portdata->in_urbs[j] = NULL;
954 } 934 }
955 } 935 }