usb_debug.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/gfp.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/tty.h>
  14. #include <linux/module.h>
  15. #include <linux/usb.h>
  16. #include <linux/usb/serial.h>
  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 const 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. /* This HW really does not support a serial break, so one will be
  42. * emulated when ever the break state is set to true.
  43. */
  44. static void usb_debug_break_ctl(struct tty_struct *tty, int break_state)
  45. {
  46. struct usb_serial_port *port = tty->driver_data;
  47. if (!break_state)
  48. return;
  49. usb_serial_generic_write(tty, port, USB_DEBUG_BRK, USB_DEBUG_BRK_SIZE);
  50. }
  51. static void usb_debug_read_bulk_callback(struct urb *urb)
  52. {
  53. struct usb_serial_port *port = urb->context;
  54. if (urb->actual_length == USB_DEBUG_BRK_SIZE &&
  55. memcmp(urb->transfer_buffer, USB_DEBUG_BRK,
  56. USB_DEBUG_BRK_SIZE) == 0) {
  57. usb_serial_handle_break(port);
  58. usb_serial_generic_submit_read_urb(port, GFP_ATOMIC);
  59. return;
  60. }
  61. usb_serial_generic_read_bulk_callback(urb);
  62. }
  63. static struct usb_serial_driver debug_device = {
  64. .driver = {
  65. .owner = THIS_MODULE,
  66. .name = "debug",
  67. },
  68. .id_table = id_table,
  69. .usb_driver = &debug_driver,
  70. .num_ports = 1,
  71. .bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE,
  72. .break_ctl = usb_debug_break_ctl,
  73. .read_bulk_callback = usb_debug_read_bulk_callback,
  74. };
  75. static int __init debug_init(void)
  76. {
  77. int retval;
  78. retval = usb_serial_register(&debug_device);
  79. if (retval)
  80. return retval;
  81. retval = usb_register(&debug_driver);
  82. if (retval)
  83. usb_serial_deregister(&debug_device);
  84. return retval;
  85. }
  86. static void __exit debug_exit(void)
  87. {
  88. usb_deregister(&debug_driver);
  89. usb_serial_deregister(&debug_device);
  90. }
  91. module_init(debug_init);
  92. module_exit(debug_exit);
  93. MODULE_LICENSE("GPL");