usb_debug.c 2.5 KB

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