navman.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Navman Serial USB driver
  4. *
  5. * Copyright (C) 2006 Greg Kroah-Hartman <[email protected]>
  6. *
  7. * TODO:
  8. * Add termios method that uses copy_hw but also kills all echo
  9. * flags as the navman is rx only so cannot echo.
  10. */
  11. #include <linux/gfp.h>
  12. #include <linux/kernel.h>
  13. #include <linux/tty.h>
  14. #include <linux/tty_flip.h>
  15. #include <linux/module.h>
  16. #include <linux/usb.h>
  17. #include <linux/usb/serial.h>
  18. static const struct usb_device_id id_table[] = {
  19. { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */
  20. { USB_DEVICE(0x0df7, 0x0900) }, /* Mobile Action i-gotU */
  21. { },
  22. };
  23. MODULE_DEVICE_TABLE(usb, id_table);
  24. static void navman_read_int_callback(struct urb *urb)
  25. {
  26. struct usb_serial_port *port = urb->context;
  27. unsigned char *data = urb->transfer_buffer;
  28. int status = urb->status;
  29. int result;
  30. switch (status) {
  31. case 0:
  32. /* success */
  33. break;
  34. case -ECONNRESET:
  35. case -ENOENT:
  36. case -ESHUTDOWN:
  37. /* this urb is terminated, clean up */
  38. dev_dbg(&port->dev, "%s - urb shutting down with status: %d\n",
  39. __func__, status);
  40. return;
  41. default:
  42. dev_dbg(&port->dev, "%s - nonzero urb status received: %d\n",
  43. __func__, status);
  44. goto exit;
  45. }
  46. usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
  47. if (urb->actual_length) {
  48. tty_insert_flip_string(&port->port, data, urb->actual_length);
  49. tty_flip_buffer_push(&port->port);
  50. }
  51. exit:
  52. result = usb_submit_urb(urb, GFP_ATOMIC);
  53. if (result)
  54. dev_err(&urb->dev->dev,
  55. "%s - Error %d submitting interrupt urb\n",
  56. __func__, result);
  57. }
  58. static int navman_open(struct tty_struct *tty, struct usb_serial_port *port)
  59. {
  60. int result = 0;
  61. if (port->interrupt_in_urb) {
  62. dev_dbg(&port->dev, "%s - adding interrupt input for treo\n",
  63. __func__);
  64. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  65. if (result)
  66. dev_err(&port->dev,
  67. "%s - failed submitting interrupt urb, error %d\n",
  68. __func__, result);
  69. }
  70. return result;
  71. }
  72. static void navman_close(struct usb_serial_port *port)
  73. {
  74. usb_kill_urb(port->interrupt_in_urb);
  75. }
  76. static int navman_write(struct tty_struct *tty, struct usb_serial_port *port,
  77. const unsigned char *buf, int count)
  78. {
  79. /*
  80. * This device can't write any data, only read from the device
  81. */
  82. return -EOPNOTSUPP;
  83. }
  84. static struct usb_serial_driver navman_device = {
  85. .driver = {
  86. .owner = THIS_MODULE,
  87. .name = "navman",
  88. },
  89. .id_table = id_table,
  90. .num_ports = 1,
  91. .open = navman_open,
  92. .close = navman_close,
  93. .write = navman_write,
  94. .read_int_callback = navman_read_int_callback,
  95. };
  96. static struct usb_serial_driver * const serial_drivers[] = {
  97. &navman_device, NULL
  98. };
  99. module_usb_serial_driver(serial_drivers, id_table);
  100. MODULE_LICENSE("GPL v2");