1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * USB Debug cable driver
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2006 Greg Kroah-Hartman <greg@kroah.com>
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include <linux/gfp.h>
9*4882a593Smuzhiyun #include <linux/kernel.h>
10*4882a593Smuzhiyun #include <linux/tty.h>
11*4882a593Smuzhiyun #include <linux/module.h>
12*4882a593Smuzhiyun #include <linux/usb.h>
13*4882a593Smuzhiyun #include <linux/usb/serial.h>
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #define USB_DEBUG_MAX_PACKET_SIZE 8
16*4882a593Smuzhiyun #define USB_DEBUG_BRK_SIZE 8
17*4882a593Smuzhiyun static const char USB_DEBUG_BRK[USB_DEBUG_BRK_SIZE] = {
18*4882a593Smuzhiyun 0x00,
19*4882a593Smuzhiyun 0xff,
20*4882a593Smuzhiyun 0x01,
21*4882a593Smuzhiyun 0xfe,
22*4882a593Smuzhiyun 0x00,
23*4882a593Smuzhiyun 0xfe,
24*4882a593Smuzhiyun 0x01,
25*4882a593Smuzhiyun 0xff,
26*4882a593Smuzhiyun };
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun static const struct usb_device_id id_table[] = {
29*4882a593Smuzhiyun { USB_DEVICE(0x0525, 0x127a) },
30*4882a593Smuzhiyun { },
31*4882a593Smuzhiyun };
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun static const struct usb_device_id dbc_id_table[] = {
34*4882a593Smuzhiyun { USB_DEVICE(0x1d6b, 0x0010) },
35*4882a593Smuzhiyun { USB_DEVICE(0x1d6b, 0x0011) },
36*4882a593Smuzhiyun { },
37*4882a593Smuzhiyun };
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun static const struct usb_device_id id_table_combined[] = {
40*4882a593Smuzhiyun { USB_DEVICE(0x0525, 0x127a) },
41*4882a593Smuzhiyun { USB_DEVICE(0x1d6b, 0x0010) },
42*4882a593Smuzhiyun { USB_DEVICE(0x1d6b, 0x0011) },
43*4882a593Smuzhiyun { },
44*4882a593Smuzhiyun };
45*4882a593Smuzhiyun MODULE_DEVICE_TABLE(usb, id_table_combined);
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun /* This HW really does not support a serial break, so one will be
48*4882a593Smuzhiyun * emulated when ever the break state is set to true.
49*4882a593Smuzhiyun */
usb_debug_break_ctl(struct tty_struct * tty,int break_state)50*4882a593Smuzhiyun static void usb_debug_break_ctl(struct tty_struct *tty, int break_state)
51*4882a593Smuzhiyun {
52*4882a593Smuzhiyun struct usb_serial_port *port = tty->driver_data;
53*4882a593Smuzhiyun if (!break_state)
54*4882a593Smuzhiyun return;
55*4882a593Smuzhiyun usb_serial_generic_write(tty, port, USB_DEBUG_BRK, USB_DEBUG_BRK_SIZE);
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun
usb_debug_process_read_urb(struct urb * urb)58*4882a593Smuzhiyun static void usb_debug_process_read_urb(struct urb *urb)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun struct usb_serial_port *port = urb->context;
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun if (urb->actual_length == USB_DEBUG_BRK_SIZE &&
63*4882a593Smuzhiyun memcmp(urb->transfer_buffer, USB_DEBUG_BRK,
64*4882a593Smuzhiyun USB_DEBUG_BRK_SIZE) == 0) {
65*4882a593Smuzhiyun usb_serial_handle_break(port);
66*4882a593Smuzhiyun return;
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun usb_serial_generic_process_read_urb(urb);
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun static struct usb_serial_driver debug_device = {
73*4882a593Smuzhiyun .driver = {
74*4882a593Smuzhiyun .owner = THIS_MODULE,
75*4882a593Smuzhiyun .name = "debug",
76*4882a593Smuzhiyun },
77*4882a593Smuzhiyun .id_table = id_table,
78*4882a593Smuzhiyun .num_ports = 1,
79*4882a593Smuzhiyun .bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE,
80*4882a593Smuzhiyun .break_ctl = usb_debug_break_ctl,
81*4882a593Smuzhiyun .process_read_urb = usb_debug_process_read_urb,
82*4882a593Smuzhiyun };
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun static struct usb_serial_driver dbc_device = {
85*4882a593Smuzhiyun .driver = {
86*4882a593Smuzhiyun .owner = THIS_MODULE,
87*4882a593Smuzhiyun .name = "xhci_dbc",
88*4882a593Smuzhiyun },
89*4882a593Smuzhiyun .id_table = dbc_id_table,
90*4882a593Smuzhiyun .num_ports = 1,
91*4882a593Smuzhiyun .break_ctl = usb_debug_break_ctl,
92*4882a593Smuzhiyun .process_read_urb = usb_debug_process_read_urb,
93*4882a593Smuzhiyun };
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun static struct usb_serial_driver * const serial_drivers[] = {
96*4882a593Smuzhiyun &debug_device, &dbc_device, NULL
97*4882a593Smuzhiyun };
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun module_usb_serial_driver(serial_drivers, id_table_combined);
100*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
101