qcserial.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Qualcomm Serial USB driver
  3. *
  4. * Copyright (c) 2008 QUALCOMM Incorporated.
  5. * Copyright (c) 2009 Greg Kroah-Hartman <gregkh@suse.de>
  6. * Copyright (c) 2009 Novell Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License version
  10. * 2 as published by the Free Software Foundation.
  11. *
  12. */
  13. #include <linux/tty.h>
  14. #include <linux/tty_flip.h>
  15. #include <linux/usb.h>
  16. #include <linux/usb/serial.h>
  17. #define DRIVER_AUTHOR "Qualcomm Inc"
  18. #define DRIVER_DESC "Qualcomm USB Serial driver"
  19. static int debug;
  20. static struct usb_device_id id_table[] = {
  21. {USB_DEVICE(0x05c6, 0x9211)}, /* Acer Gobi QDL device */
  22. {USB_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */
  23. { } /* Terminating entry */
  24. };
  25. MODULE_DEVICE_TABLE(usb, id_table);
  26. static struct usb_driver qcdriver = {
  27. .name = "qcserial",
  28. .probe = usb_serial_probe,
  29. .disconnect = usb_serial_disconnect,
  30. .id_table = id_table,
  31. .suspend = usb_serial_suspend,
  32. .resume = usb_serial_resume,
  33. .supports_autosuspend = true,
  34. };
  35. static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
  36. {
  37. int retval = -ENODEV;
  38. __u8 nintf;
  39. __u8 ifnum;
  40. dbg("%s", __func__);
  41. nintf = serial->dev->actconfig->desc.bNumInterfaces;
  42. dbg("Num Interfaces = %d", nintf);
  43. ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
  44. dbg("This Interface = %d", ifnum);
  45. switch (nintf) {
  46. case 1:
  47. /* QDL mode */
  48. if (serial->interface->num_altsetting == 2) {
  49. struct usb_host_interface *intf;
  50. intf = &serial->interface->altsetting[1];
  51. if (intf->desc.bNumEndpoints == 2) {
  52. if (usb_endpoint_is_bulk_in(&intf->endpoint[0].desc) &&
  53. usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) {
  54. dbg("QDL port found");
  55. retval = usb_set_interface(serial->dev, ifnum, 1);
  56. if (retval < 0) {
  57. dev_err(&serial->dev->dev,
  58. "Could not set interface, error %d\n",
  59. retval);
  60. retval = -ENODEV;
  61. }
  62. return retval;
  63. }
  64. }
  65. }
  66. break;
  67. case 4:
  68. /* Composite mode */
  69. if (ifnum == 2) {
  70. dbg("Modem port found");
  71. retval = usb_set_interface(serial->dev, ifnum, 0);
  72. if (retval < 0) {
  73. dev_err(&serial->dev->dev,
  74. "Could not set interface, error %d\n",
  75. retval);
  76. retval = -ENODEV;
  77. }
  78. return retval;
  79. }
  80. break;
  81. default:
  82. dev_err(&serial->dev->dev,
  83. "unknown number of interfaces: %d\n", nintf);
  84. return -ENODEV;
  85. }
  86. return retval;
  87. }
  88. static struct usb_serial_driver qcdevice = {
  89. .driver = {
  90. .owner = THIS_MODULE,
  91. .name = "qcserial",
  92. },
  93. .description = "Qualcomm USB modem",
  94. .id_table = id_table,
  95. .usb_driver = &qcdriver,
  96. .num_ports = 1,
  97. .probe = qcprobe,
  98. };
  99. static int __init qcinit(void)
  100. {
  101. int retval;
  102. retval = usb_serial_register(&qcdevice);
  103. if (retval)
  104. return retval;
  105. retval = usb_register(&qcdriver);
  106. if (retval) {
  107. usb_serial_deregister(&qcdevice);
  108. return retval;
  109. }
  110. return 0;
  111. }
  112. static void __exit qcexit(void)
  113. {
  114. usb_deregister(&qcdriver);
  115. usb_serial_deregister(&qcdevice);
  116. }
  117. module_init(qcinit);
  118. module_exit(qcexit);
  119. MODULE_AUTHOR(DRIVER_AUTHOR);
  120. MODULE_DESCRIPTION(DRIVER_DESC);
  121. MODULE_LICENSE("GPL v2");
  122. module_param(debug, bool, S_IRUGO | S_IWUSR);
  123. MODULE_PARM_DESC(debug, "Debug enabled or not");