navman.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 bool 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. .id_table = id_table,
  32. };
  33. static void navman_read_int_callback(struct urb *urb)
  34. {
  35. struct usb_serial_port *port = urb->context;
  36. unsigned char *data = urb->transfer_buffer;
  37. struct tty_struct *tty;
  38. int status = urb->status;
  39. int result;
  40. switch (status) {
  41. case 0:
  42. /* success */
  43. break;
  44. case -ECONNRESET:
  45. case -ENOENT:
  46. case -ESHUTDOWN:
  47. /* this urb is terminated, clean up */
  48. dbg("%s - urb shutting down with status: %d",
  49. __func__, status);
  50. return;
  51. default:
  52. dbg("%s - nonzero urb status received: %d",
  53. __func__, status);
  54. goto exit;
  55. }
  56. usb_serial_debug_data(debug, &port->dev, __func__,
  57. urb->actual_length, data);
  58. tty = tty_port_tty_get(&port->port);
  59. if (tty && urb->actual_length) {
  60. tty_insert_flip_string(tty, data, urb->actual_length);
  61. tty_flip_buffer_push(tty);
  62. }
  63. tty_kref_put(tty);
  64. exit:
  65. result = usb_submit_urb(urb, GFP_ATOMIC);
  66. if (result)
  67. dev_err(&urb->dev->dev,
  68. "%s - Error %d submitting interrupt urb\n",
  69. __func__, result);
  70. }
  71. static int navman_open(struct tty_struct *tty, struct usb_serial_port *port)
  72. {
  73. int result = 0;
  74. if (port->interrupt_in_urb) {
  75. dbg("%s - adding interrupt input for treo", __func__);
  76. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  77. if (result)
  78. dev_err(&port->dev,
  79. "%s - failed submitting interrupt urb, error %d\n",
  80. __func__, result);
  81. }
  82. return result;
  83. }
  84. static void navman_close(struct usb_serial_port *port)
  85. {
  86. usb_kill_urb(port->interrupt_in_urb);
  87. }
  88. static int navman_write(struct tty_struct *tty, struct usb_serial_port *port,
  89. const unsigned char *buf, int count)
  90. {
  91. /*
  92. * This device can't write any data, only read from the device
  93. */
  94. return -EOPNOTSUPP;
  95. }
  96. static struct usb_serial_driver navman_device = {
  97. .driver = {
  98. .owner = THIS_MODULE,
  99. .name = "navman",
  100. },
  101. .id_table = id_table,
  102. .num_ports = 1,
  103. .open = navman_open,
  104. .close = navman_close,
  105. .write = navman_write,
  106. .read_int_callback = navman_read_int_callback,
  107. };
  108. static struct usb_serial_driver * const serial_drivers[] = {
  109. &navman_device, NULL
  110. };
  111. module_usb_serial_driver(navman_driver, serial_drivers);
  112. MODULE_LICENSE("GPL");
  113. module_param(debug, bool, S_IRUGO | S_IWUSR);
  114. MODULE_PARM_DESC(debug, "Debug enabled or not");