navman.c 2.8 KB

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