usb_debug.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * USB Debug cable driver
  4. *
  5. * Copyright (C) 2006 Greg Kroah-Hartman <greg@kroah.com>
  6. */
  7. #include <linux/gfp.h>
  8. #include <linux/kernel.h>
  9. #include <linux/tty.h>
  10. #include <linux/module.h>
  11. #include <linux/usb.h>
  12. #include <linux/usb/serial.h>
  13. #define USB_DEBUG_MAX_PACKET_SIZE 8
  14. #define USB_DEBUG_BRK_SIZE 8
  15. static const char USB_DEBUG_BRK[USB_DEBUG_BRK_SIZE] = {
  16. 0x00,
  17. 0xff,
  18. 0x01,
  19. 0xfe,
  20. 0x00,
  21. 0xfe,
  22. 0x01,
  23. 0xff,
  24. };
  25. static const struct usb_device_id id_table[] = {
  26. { USB_DEVICE(0x0525, 0x127a) },
  27. { },
  28. };
  29. static const struct usb_device_id dbc_id_table[] = {
  30. { USB_DEVICE(0x1d6b, 0x0011) },
  31. { },
  32. };
  33. static const struct usb_device_id id_table_combined[] = {
  34. { USB_DEVICE(0x0525, 0x127a) },
  35. { USB_DEVICE(0x1d6b, 0x0011) },
  36. { },
  37. };
  38. MODULE_DEVICE_TABLE(usb, id_table_combined);
  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 dbc_device = {
  72. .driver = {
  73. .owner = THIS_MODULE,
  74. .name = "xhci_dbc",
  75. },
  76. .id_table = dbc_id_table,
  77. .num_ports = 1,
  78. .break_ctl = usb_debug_break_ctl,
  79. .process_read_urb = usb_debug_process_read_urb,
  80. };
  81. static struct usb_serial_driver * const serial_drivers[] = {
  82. &debug_device, &dbc_device, NULL
  83. };
  84. module_usb_serial_driver(serial_drivers, id_table_combined);
  85. MODULE_LICENSE("GPL v2");