usb_debug.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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, 0x0010) },
  31. { USB_DEVICE(0x1d6b, 0x0011) },
  32. { },
  33. };
  34. static const struct usb_device_id id_table_combined[] = {
  35. { USB_DEVICE(0x0525, 0x127a) },
  36. { USB_DEVICE(0x1d6b, 0x0010) },
  37. { USB_DEVICE(0x1d6b, 0x0011) },
  38. { },
  39. };
  40. MODULE_DEVICE_TABLE(usb, id_table_combined);
  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 int usb_debug_break_ctl(struct tty_struct *tty, int break_state)
  45. {
  46. struct usb_serial_port *port = tty->driver_data;
  47. int ret;
  48. if (!break_state)
  49. return 0;
  50. ret = usb_serial_generic_write(tty, port, USB_DEBUG_BRK, USB_DEBUG_BRK_SIZE);
  51. if (ret < 0)
  52. return ret;
  53. return 0;
  54. }
  55. static void usb_debug_process_read_urb(struct urb *urb)
  56. {
  57. struct usb_serial_port *port = urb->context;
  58. if (urb->actual_length == USB_DEBUG_BRK_SIZE &&
  59. memcmp(urb->transfer_buffer, USB_DEBUG_BRK,
  60. USB_DEBUG_BRK_SIZE) == 0) {
  61. usb_serial_handle_break(port);
  62. return;
  63. }
  64. usb_serial_generic_process_read_urb(urb);
  65. }
  66. static void usb_debug_init_termios(struct tty_struct *tty)
  67. {
  68. tty->termios.c_lflag &= ~(ECHO | ECHONL);
  69. }
  70. static struct usb_serial_driver debug_device = {
  71. .driver = {
  72. .name = "debug",
  73. },
  74. .id_table = id_table,
  75. .num_ports = 1,
  76. .bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE,
  77. .break_ctl = usb_debug_break_ctl,
  78. .init_termios = usb_debug_init_termios,
  79. .process_read_urb = usb_debug_process_read_urb,
  80. };
  81. static struct usb_serial_driver dbc_device = {
  82. .driver = {
  83. .name = "xhci_dbc",
  84. },
  85. .id_table = dbc_id_table,
  86. .num_ports = 1,
  87. .break_ctl = usb_debug_break_ctl,
  88. .init_termios = usb_debug_init_termios,
  89. .process_read_urb = usb_debug_process_read_urb,
  90. };
  91. static struct usb_serial_driver * const serial_drivers[] = {
  92. &debug_device, &dbc_device, NULL
  93. };
  94. module_usb_serial_driver(serial_drivers, id_table_combined);
  95. MODULE_DESCRIPTION("USB Debug cable driver");
  96. MODULE_LICENSE("GPL v2");