navman.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. * TODO:
  11. * Add termios method that uses copy_hw but also kills all echo
  12. * flags as the navman is rx only so cannot echo.
  13. */
  14. #include <linux/gfp.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/tty.h>
  18. #include <linux/tty_flip.h>
  19. #include <linux/module.h>
  20. #include <linux/usb.h>
  21. #include <linux/usb/serial.h>
  22. static int debug;
  23. static const struct usb_device_id id_table[] = {
  24. { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */
  25. { USB_DEVICE(0x0df7, 0x0900) }, /* Mobile Action i-gotU */
  26. { },
  27. };
  28. MODULE_DEVICE_TABLE(usb, id_table);
  29. static struct usb_driver navman_driver = {
  30. .name = "navman",
  31. .probe = usb_serial_probe,
  32. .disconnect = usb_serial_disconnect,
  33. .id_table = id_table,
  34. .no_dynamic_id = 1,
  35. };
  36. static void navman_read_int_callback(struct urb *urb)
  37. {
  38. struct usb_serial_port *port = urb->context;
  39. unsigned char *data = urb->transfer_buffer;
  40. struct tty_struct *tty;
  41. int status = urb->status;
  42. int result;
  43. switch (status) {
  44. case 0:
  45. /* success */
  46. break;
  47. case -ECONNRESET:
  48. case -ENOENT:
  49. case -ESHUTDOWN:
  50. /* this urb is terminated, clean up */
  51. dbg("%s - urb shutting down with status: %d",
  52. __func__, status);
  53. return;
  54. default:
  55. dbg("%s - nonzero urb status received: %d",
  56. __func__, status);
  57. goto exit;
  58. }
  59. usb_serial_debug_data(debug, &port->dev, __func__,
  60. urb->actual_length, data);
  61. tty = tty_port_tty_get(&port->port);
  62. if (tty && urb->actual_length) {
  63. tty_insert_flip_string(tty, data, urb->actual_length);
  64. tty_flip_buffer_push(tty);
  65. }
  66. tty_kref_put(tty);
  67. exit:
  68. result = usb_submit_urb(urb, GFP_ATOMIC);
  69. if (result)
  70. dev_err(&urb->dev->dev,
  71. "%s - Error %d submitting interrupt urb\n",
  72. __func__, result);
  73. }
  74. static int navman_open(struct tty_struct *tty, struct usb_serial_port *port)
  75. {
  76. int result = 0;
  77. dbg("%s - port %d", __func__, port->number);
  78. if (port->interrupt_in_urb) {
  79. dbg("%s - adding interrupt input for treo", __func__);
  80. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  81. if (result)
  82. dev_err(&port->dev,
  83. "%s - failed submitting interrupt urb, error %d\n",
  84. __func__, result);
  85. }
  86. return result;
  87. }
  88. static void navman_close(struct usb_serial_port *port)
  89. {
  90. dbg("%s - port %d", __func__, port->number);
  91. usb_kill_urb(port->interrupt_in_urb);
  92. }
  93. static int navman_write(struct tty_struct *tty, struct usb_serial_port *port,
  94. const unsigned char *buf, int count)
  95. {
  96. dbg("%s - port %d", __func__, port->number);
  97. /*
  98. * This device can't write any data, only read from the device
  99. */
  100. return -EOPNOTSUPP;
  101. }
  102. static struct usb_serial_driver navman_device = {
  103. .driver = {
  104. .owner = THIS_MODULE,
  105. .name = "navman",
  106. },
  107. .id_table = id_table,
  108. .usb_driver = &navman_driver,
  109. .num_ports = 1,
  110. .open = navman_open,
  111. .close = navman_close,
  112. .write = navman_write,
  113. .read_int_callback = navman_read_int_callback,
  114. };
  115. static int __init navman_init(void)
  116. {
  117. int retval;
  118. retval = usb_serial_register(&navman_device);
  119. if (retval)
  120. return retval;
  121. retval = usb_register(&navman_driver);
  122. if (retval)
  123. usb_serial_deregister(&navman_device);
  124. return retval;
  125. }
  126. static void __exit navman_exit(void)
  127. {
  128. usb_deregister(&navman_driver);
  129. usb_serial_deregister(&navman_device);
  130. }
  131. module_init(navman_init);
  132. module_exit(navman_exit);
  133. MODULE_LICENSE("GPL");
  134. module_param(debug, bool, S_IRUGO | S_IWUSR);
  135. MODULE_PARM_DESC(debug, "Debug enabled or not");