navman.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Navman Serial USB driver
  3. *
  4. * Copyright (C) 2006 Greg Kroah-Hartman <gregkh@suse.de>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/tty.h>
  13. #include <linux/tty_flip.h>
  14. #include <linux/module.h>
  15. #include <linux/usb.h>
  16. #include "usb-serial.h"
  17. static int debug;
  18. static struct usb_device_id id_table [] = {
  19. { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */
  20. { },
  21. };
  22. MODULE_DEVICE_TABLE(usb, id_table);
  23. static struct usb_driver navman_driver = {
  24. .name = "navman",
  25. .probe = usb_serial_probe,
  26. .disconnect = usb_serial_disconnect,
  27. .id_table = id_table,
  28. .no_dynamic_id = 1,
  29. };
  30. static void navman_read_int_callback(struct urb *urb, struct pt_regs *regs)
  31. {
  32. struct usb_serial_port *port = urb->context;
  33. unsigned char *data = urb->transfer_buffer;
  34. struct tty_struct *tty;
  35. int result;
  36. switch (urb->status) {
  37. case 0:
  38. /* success */
  39. break;
  40. case -ECONNRESET:
  41. case -ENOENT:
  42. case -ESHUTDOWN:
  43. /* this urb is terminated, clean up */
  44. dbg("%s - urb shutting down with status: %d",
  45. __FUNCTION__, urb->status);
  46. return;
  47. default:
  48. dbg("%s - nonzero urb status received: %d",
  49. __FUNCTION__, urb->status);
  50. goto exit;
  51. }
  52. usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
  53. urb->actual_length, data);
  54. tty = port->tty;
  55. if (tty && urb->actual_length) {
  56. tty_buffer_request_room(tty, urb->actual_length);
  57. tty_insert_flip_string(tty, data, urb->actual_length);
  58. tty_flip_buffer_push(tty);
  59. }
  60. exit:
  61. result = usb_submit_urb(urb, GFP_ATOMIC);
  62. if (result)
  63. dev_err(&urb->dev->dev,
  64. "%s - Error %d submitting interrupt urb\n",
  65. __FUNCTION__, result);
  66. }
  67. static int navman_open(struct usb_serial_port *port, struct file *filp)
  68. {
  69. int result = 0;
  70. dbg("%s - port %d", __FUNCTION__, port->number);
  71. if (port->interrupt_in_urb) {
  72. dbg("%s - adding interrupt input for treo", __FUNCTION__);
  73. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  74. if (result)
  75. dev_err(&port->dev,
  76. "%s - failed submitting interrupt urb, error %d\n",
  77. __FUNCTION__, result);
  78. }
  79. return result;
  80. }
  81. static void navman_close(struct usb_serial_port *port, struct file *filp)
  82. {
  83. dbg("%s - port %d", __FUNCTION__, port->number);
  84. if (port->interrupt_in_urb)
  85. usb_kill_urb(port->interrupt_in_urb);
  86. }
  87. static int navman_write(struct usb_serial_port *port,
  88. const unsigned char *buf, int count)
  89. {
  90. dbg("%s - port %d", __FUNCTION__, port->number);
  91. /*
  92. * This device can't write any data, only read from the device
  93. * so we just silently eat all data sent to us and say it was
  94. * successfully sent.
  95. * Evil, I know, but do you have a better idea?
  96. */
  97. return count;
  98. }
  99. static struct usb_serial_driver navman_device = {
  100. .driver = {
  101. .owner = THIS_MODULE,
  102. .name = "navman",
  103. },
  104. .id_table = id_table,
  105. .num_interrupt_in = NUM_DONT_CARE,
  106. .num_bulk_in = NUM_DONT_CARE,
  107. .num_bulk_out = NUM_DONT_CARE,
  108. .num_ports = 1,
  109. .open = navman_open,
  110. .close = navman_close,
  111. .write = navman_write,
  112. .read_int_callback = navman_read_int_callback,
  113. };
  114. static int __init navman_init(void)
  115. {
  116. int retval;
  117. retval = usb_serial_register(&navman_device);
  118. if (retval)
  119. return retval;
  120. retval = usb_register(&navman_driver);
  121. if (retval)
  122. usb_serial_deregister(&navman_device);
  123. return retval;
  124. }
  125. static void __exit navman_exit(void)
  126. {
  127. usb_deregister(&navman_driver);
  128. usb_serial_deregister(&navman_device);
  129. }
  130. module_init(navman_init);
  131. module_exit(navman_exit);
  132. MODULE_LICENSE("GPL");
  133. module_param(debug, bool, S_IRUGO | S_IWUSR);
  134. MODULE_PARM_DESC(debug, "Debug enabled or not");