qcserial.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. {USB_DEVICE(0x03f0, 0x1f1d)}, /* HP un2400 Gobi Modem Device */
  24. {USB_DEVICE(0x03f0, 0x201d)}, /* HP un2400 Gobi QDL Device */
  25. {USB_DEVICE(0x04da, 0x250d)}, /* Panasonic Gobi Modem device */
  26. {USB_DEVICE(0x04da, 0x250c)}, /* Panasonic Gobi QDL device */
  27. {USB_DEVICE(0x413c, 0x8172)}, /* Dell Gobi Modem device */
  28. {USB_DEVICE(0x413c, 0x8171)}, /* Dell Gobi QDL device */
  29. {USB_DEVICE(0x1410, 0xa001)}, /* Novatel Gobi Modem device */
  30. {USB_DEVICE(0x1410, 0xa008)}, /* Novatel Gobi QDL device */
  31. {USB_DEVICE(0x0b05, 0x1776)}, /* Asus Gobi Modem device */
  32. {USB_DEVICE(0x0b05, 0x1774)}, /* Asus Gobi QDL device */
  33. {USB_DEVICE(0x19d2, 0xfff3)}, /* ONDA Gobi Modem device */
  34. {USB_DEVICE(0x19d2, 0xfff2)}, /* ONDA Gobi QDL device */
  35. {USB_DEVICE(0x1557, 0x0a80)}, /* OQO Gobi QDL device */
  36. {USB_DEVICE(0x05c6, 0x9001)}, /* Generic Gobi Modem device */
  37. {USB_DEVICE(0x05c6, 0x9002)}, /* Generic Gobi Modem device */
  38. {USB_DEVICE(0x05c6, 0x9202)}, /* Generic Gobi Modem device */
  39. {USB_DEVICE(0x05c6, 0x9203)}, /* Generic Gobi Modem device */
  40. {USB_DEVICE(0x05c6, 0x9222)}, /* Generic Gobi Modem device */
  41. {USB_DEVICE(0x05c6, 0x9008)}, /* Generic Gobi QDL device */
  42. {USB_DEVICE(0x05c6, 0x9201)}, /* Generic Gobi QDL device */
  43. {USB_DEVICE(0x05c6, 0x9221)}, /* Generic Gobi QDL device */
  44. {USB_DEVICE(0x05c6, 0x9231)}, /* Generic Gobi QDL device */
  45. {USB_DEVICE(0x1f45, 0x0001)}, /* Unknown Gobi QDL device */
  46. { } /* Terminating entry */
  47. };
  48. MODULE_DEVICE_TABLE(usb, id_table);
  49. static struct usb_driver qcdriver = {
  50. .name = "qcserial",
  51. .probe = usb_serial_probe,
  52. .disconnect = usb_serial_disconnect,
  53. .id_table = id_table,
  54. .suspend = usb_serial_suspend,
  55. .resume = usb_serial_resume,
  56. .supports_autosuspend = true,
  57. };
  58. static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
  59. {
  60. int retval = -ENODEV;
  61. __u8 nintf;
  62. __u8 ifnum;
  63. dbg("%s", __func__);
  64. nintf = serial->dev->actconfig->desc.bNumInterfaces;
  65. dbg("Num Interfaces = %d", nintf);
  66. ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
  67. dbg("This Interface = %d", ifnum);
  68. switch (nintf) {
  69. case 1:
  70. /* QDL mode */
  71. if (serial->interface->num_altsetting == 2) {
  72. struct usb_host_interface *intf;
  73. intf = &serial->interface->altsetting[1];
  74. if (intf->desc.bNumEndpoints == 2) {
  75. if (usb_endpoint_is_bulk_in(&intf->endpoint[0].desc) &&
  76. usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) {
  77. dbg("QDL port found");
  78. retval = usb_set_interface(serial->dev, ifnum, 1);
  79. if (retval < 0) {
  80. dev_err(&serial->dev->dev,
  81. "Could not set interface, error %d\n",
  82. retval);
  83. retval = -ENODEV;
  84. }
  85. return retval;
  86. }
  87. }
  88. }
  89. break;
  90. case 4:
  91. /* Composite mode */
  92. if (ifnum == 2) {
  93. dbg("Modem port found");
  94. retval = usb_set_interface(serial->dev, ifnum, 0);
  95. if (retval < 0) {
  96. dev_err(&serial->dev->dev,
  97. "Could not set interface, error %d\n",
  98. retval);
  99. retval = -ENODEV;
  100. }
  101. return retval;
  102. }
  103. break;
  104. default:
  105. dev_err(&serial->dev->dev,
  106. "unknown number of interfaces: %d\n", nintf);
  107. return -ENODEV;
  108. }
  109. return retval;
  110. }
  111. static struct usb_serial_driver qcdevice = {
  112. .driver = {
  113. .owner = THIS_MODULE,
  114. .name = "qcserial",
  115. },
  116. .description = "Qualcomm USB modem",
  117. .id_table = id_table,
  118. .usb_driver = &qcdriver,
  119. .num_ports = 1,
  120. .probe = qcprobe,
  121. };
  122. static int __init qcinit(void)
  123. {
  124. int retval;
  125. retval = usb_serial_register(&qcdevice);
  126. if (retval)
  127. return retval;
  128. retval = usb_register(&qcdriver);
  129. if (retval) {
  130. usb_serial_deregister(&qcdevice);
  131. return retval;
  132. }
  133. return 0;
  134. }
  135. static void __exit qcexit(void)
  136. {
  137. usb_deregister(&qcdriver);
  138. usb_serial_deregister(&qcdevice);
  139. }
  140. module_init(qcinit);
  141. module_exit(qcexit);
  142. MODULE_AUTHOR(DRIVER_AUTHOR);
  143. MODULE_DESCRIPTION(DRIVER_DESC);
  144. MODULE_LICENSE("GPL v2");
  145. module_param(debug, bool, S_IRUGO | S_IWUSR);
  146. MODULE_PARM_DESC(debug, "Debug enabled or not");