usb_debug.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * USB Debug cable driver
  3. *
  4. * Copyright (C) 2006 Greg Kroah-Hartman <greg@kroah.com>
  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 version
  8. * 2 as published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/tty.h>
  13. #include <linux/module.h>
  14. #include <linux/usb.h>
  15. #include <linux/usb/serial.h>
  16. #define URB_DEBUG_MAX_IN_FLIGHT_URBS 4000
  17. #define USB_DEBUG_MAX_PACKET_SIZE 8
  18. #define USB_DEBUG_BRK_SIZE 8
  19. static char USB_DEBUG_BRK[USB_DEBUG_BRK_SIZE] = {
  20. 0x00,
  21. 0xff,
  22. 0x01,
  23. 0xfe,
  24. 0x00,
  25. 0xfe,
  26. 0x01,
  27. 0xff,
  28. };
  29. static struct usb_device_id id_table [] = {
  30. { USB_DEVICE(0x0525, 0x127a) },
  31. { },
  32. };
  33. MODULE_DEVICE_TABLE(usb, id_table);
  34. static struct usb_driver debug_driver = {
  35. .name = "debug",
  36. .probe = usb_serial_probe,
  37. .disconnect = usb_serial_disconnect,
  38. .id_table = id_table,
  39. .no_dynamic_id = 1,
  40. };
  41. static int usb_debug_open(struct tty_struct *tty, struct usb_serial_port *port,
  42. struct file *filp)
  43. {
  44. port->bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE;
  45. return usb_serial_generic_open(tty, port, filp);
  46. }
  47. /* This HW really does not support a serial break, so one will be
  48. * emulated when ever the break state is set to true.
  49. */
  50. static void usb_debug_break_ctl(struct tty_struct *tty, int break_state)
  51. {
  52. struct usb_serial_port *port = tty->driver_data;
  53. if (!break_state)
  54. return;
  55. usb_serial_generic_write(tty, port, USB_DEBUG_BRK, USB_DEBUG_BRK_SIZE);
  56. }
  57. static void usb_debug_read_bulk_callback(struct urb *urb)
  58. {
  59. struct usb_serial_port *port = urb->context;
  60. if (urb->actual_length == USB_DEBUG_BRK_SIZE &&
  61. memcmp(urb->transfer_buffer, USB_DEBUG_BRK,
  62. USB_DEBUG_BRK_SIZE) == 0) {
  63. usb_serial_handle_break(port);
  64. usb_serial_generic_resubmit_read_urb(port, GFP_ATOMIC);
  65. return;
  66. }
  67. usb_serial_generic_read_bulk_callback(urb);
  68. }
  69. static struct usb_serial_driver debug_device = {
  70. .driver = {
  71. .owner = THIS_MODULE,
  72. .name = "debug",
  73. },
  74. .id_table = id_table,
  75. .num_ports = 1,
  76. .open = usb_debug_open,
  77. .max_in_flight_urbs = URB_DEBUG_MAX_IN_FLIGHT_URBS,
  78. .break_ctl = usb_debug_break_ctl,
  79. .read_bulk_callback = usb_debug_read_bulk_callback,
  80. };
  81. static int __init debug_init(void)
  82. {
  83. int retval;
  84. retval = usb_serial_register(&debug_device);
  85. if (retval)
  86. return retval;
  87. retval = usb_register(&debug_driver);
  88. if (retval)
  89. usb_serial_deregister(&debug_device);
  90. return retval;
  91. }
  92. static void __exit debug_exit(void)
  93. {
  94. usb_deregister(&debug_driver);
  95. usb_serial_deregister(&debug_device);
  96. }
  97. module_init(debug_init);
  98. module_exit(debug_exit);
  99. MODULE_LICENSE("GPL");