usb_debug.c 1.8 KB

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