usb_debug.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 void usb_debug_break_ctl(struct tty_struct *tty, int break_state)
  45. {
  46. struct usb_serial_port *port = tty->driver_data;
  47. if (!break_state)
  48. return;
  49. usb_serial_generic_write(tty, port, USB_DEBUG_BRK, USB_DEBUG_BRK_SIZE);
  50. }
  51. static void usb_debug_process_read_urb(struct urb *urb)
  52. {
  53. struct usb_serial_port *port = urb->context;
  54. if (urb->actual_length == USB_DEBUG_BRK_SIZE &&
  55. memcmp(urb->transfer_buffer, USB_DEBUG_BRK,
  56. USB_DEBUG_BRK_SIZE) == 0) {
  57. usb_serial_handle_break(port);
  58. return;
  59. }
  60. usb_serial_generic_process_read_urb(urb);
  61. }
  62. static struct usb_serial_driver debug_device = {
  63. .driver = {
  64. .owner = THIS_MODULE,
  65. .name = "debug",
  66. },
  67. .id_table = id_table,
  68. .num_ports = 1,
  69. .bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE,
  70. .break_ctl = usb_debug_break_ctl,
  71. .process_read_urb = usb_debug_process_read_urb,
  72. };
  73. static struct usb_serial_driver dbc_device = {
  74. .driver = {
  75. .owner = THIS_MODULE,
  76. .name = "xhci_dbc",
  77. },
  78. .id_table = dbc_id_table,
  79. .num_ports = 1,
  80. .break_ctl = usb_debug_break_ctl,
  81. .process_read_urb = usb_debug_process_read_urb,
  82. };
  83. static struct usb_serial_driver * const serial_drivers[] = {
  84. &debug_device, &dbc_device, NULL
  85. };
  86. module_usb_serial_driver(serial_drivers, id_table_combined);
  87. MODULE_LICENSE("GPL v2");