navman.c 3.0 KB

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