navman.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 const struct usb_device_id id_table[] = {
  23. { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */
  24. { USB_DEVICE(0x0df7, 0x0900) }, /* Mobile Action i-gotU */
  25. { },
  26. };
  27. MODULE_DEVICE_TABLE(usb, id_table);
  28. static void navman_read_int_callback(struct urb *urb)
  29. {
  30. struct usb_serial_port *port = urb->context;
  31. unsigned char *data = urb->transfer_buffer;
  32. int status = urb->status;
  33. int result;
  34. switch (status) {
  35. case 0:
  36. /* success */
  37. break;
  38. case -ECONNRESET:
  39. case -ENOENT:
  40. case -ESHUTDOWN:
  41. /* this urb is terminated, clean up */
  42. dev_dbg(&port->dev, "%s - urb shutting down with status: %d\n",
  43. __func__, status);
  44. return;
  45. default:
  46. dev_dbg(&port->dev, "%s - nonzero urb status received: %d\n",
  47. __func__, status);
  48. goto exit;
  49. }
  50. usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
  51. if (urb->actual_length) {
  52. tty_insert_flip_string(&port->port, data, urb->actual_length);
  53. tty_flip_buffer_push(&port->port);
  54. }
  55. exit:
  56. result = usb_submit_urb(urb, GFP_ATOMIC);
  57. if (result)
  58. dev_err(&urb->dev->dev,
  59. "%s - Error %d submitting interrupt urb\n",
  60. __func__, result);
  61. }
  62. static int navman_open(struct tty_struct *tty, struct usb_serial_port *port)
  63. {
  64. int result = 0;
  65. if (port->interrupt_in_urb) {
  66. dev_dbg(&port->dev, "%s - adding interrupt input for treo\n",
  67. __func__);
  68. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  69. if (result)
  70. dev_err(&port->dev,
  71. "%s - failed submitting interrupt urb, error %d\n",
  72. __func__, result);
  73. }
  74. return result;
  75. }
  76. static void navman_close(struct usb_serial_port *port)
  77. {
  78. usb_kill_urb(port->interrupt_in_urb);
  79. }
  80. static int navman_write(struct tty_struct *tty, struct usb_serial_port *port,
  81. const unsigned char *buf, int count)
  82. {
  83. /*
  84. * This device can't write any data, only read from the device
  85. */
  86. return -EOPNOTSUPP;
  87. }
  88. static struct usb_serial_driver navman_device = {
  89. .driver = {
  90. .owner = THIS_MODULE,
  91. .name = "navman",
  92. },
  93. .id_table = id_table,
  94. .num_ports = 1,
  95. .open = navman_open,
  96. .close = navman_close,
  97. .write = navman_write,
  98. .read_int_callback = navman_read_int_callback,
  99. };
  100. static struct usb_serial_driver * const serial_drivers[] = {
  101. &navman_device, NULL
  102. };
  103. module_usb_serial_driver(serial_drivers, id_table);
  104. MODULE_LICENSE("GPL");