usb_debug.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. .disconnect = usb_serial_disconnect,
  37. .id_table = id_table,
  38. };
  39. /* This HW really does not support a serial break, so one will be
  40. * emulated when ever the break state is set to true.
  41. */
  42. static void usb_debug_break_ctl(struct tty_struct *tty, int break_state)
  43. {
  44. struct usb_serial_port *port = tty->driver_data;
  45. if (!break_state)
  46. return;
  47. usb_serial_generic_write(tty, port, USB_DEBUG_BRK, USB_DEBUG_BRK_SIZE);
  48. }
  49. static void usb_debug_process_read_urb(struct urb *urb)
  50. {
  51. struct usb_serial_port *port = urb->context;
  52. if (urb->actual_length == USB_DEBUG_BRK_SIZE &&
  53. memcmp(urb->transfer_buffer, USB_DEBUG_BRK,
  54. USB_DEBUG_BRK_SIZE) == 0) {
  55. usb_serial_handle_break(port);
  56. return;
  57. }
  58. usb_serial_generic_process_read_urb(urb);
  59. }
  60. static struct usb_serial_driver debug_device = {
  61. .driver = {
  62. .owner = THIS_MODULE,
  63. .name = "debug",
  64. },
  65. .id_table = id_table,
  66. .num_ports = 1,
  67. .bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE,
  68. .break_ctl = usb_debug_break_ctl,
  69. .process_read_urb = usb_debug_process_read_urb,
  70. };
  71. static struct usb_serial_driver * const serial_drivers[] = {
  72. &debug_device, NULL
  73. };
  74. module_usb_serial_driver(debug_driver, serial_drivers);
  75. MODULE_LICENSE("GPL");