xref: /linux/drivers/usb/serial/usb_debug.c (revision 5fd54ace4721fc5ce2bb5aef6318fcf17f421460)
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  *	This program is free software; you can redistribute it and/or
8  *	modify it under the terms of the GNU General Public License version
9  *	2 as published by the Free Software Foundation.
10  */
11 
12 #include <linux/gfp.h>
13 #include <linux/kernel.h>
14 #include <linux/tty.h>
15 #include <linux/module.h>
16 #include <linux/usb.h>
17 #include <linux/usb/serial.h>
18 
19 #define USB_DEBUG_MAX_PACKET_SIZE	8
20 #define USB_DEBUG_BRK_SIZE		8
21 static const char USB_DEBUG_BRK[USB_DEBUG_BRK_SIZE] = {
22 	0x00,
23 	0xff,
24 	0x01,
25 	0xfe,
26 	0x00,
27 	0xfe,
28 	0x01,
29 	0xff,
30 };
31 
32 static const struct usb_device_id id_table[] = {
33 	{ USB_DEVICE(0x0525, 0x127a) },
34 	{ },
35 };
36 
37 static const struct usb_device_id dbc_id_table[] = {
38 	{ USB_DEVICE(0x1d6b, 0x0004) },
39 	{ },
40 };
41 
42 static const struct usb_device_id id_table_combined[] = {
43 	{ USB_DEVICE(0x0525, 0x127a) },
44 	{ USB_DEVICE(0x1d6b, 0x0004) },
45 	{ },
46 };
47 MODULE_DEVICE_TABLE(usb, id_table_combined);
48 
49 /* This HW really does not support a serial break, so one will be
50  * emulated when ever the break state is set to true.
51  */
52 static void usb_debug_break_ctl(struct tty_struct *tty, int break_state)
53 {
54 	struct usb_serial_port *port = tty->driver_data;
55 	if (!break_state)
56 		return;
57 	usb_serial_generic_write(tty, port, USB_DEBUG_BRK, USB_DEBUG_BRK_SIZE);
58 }
59 
60 static void usb_debug_process_read_urb(struct urb *urb)
61 {
62 	struct usb_serial_port *port = urb->context;
63 
64 	if (urb->actual_length == USB_DEBUG_BRK_SIZE &&
65 		memcmp(urb->transfer_buffer, USB_DEBUG_BRK,
66 						USB_DEBUG_BRK_SIZE) == 0) {
67 		usb_serial_handle_break(port);
68 		return;
69 	}
70 
71 	usb_serial_generic_process_read_urb(urb);
72 }
73 
74 static struct usb_serial_driver debug_device = {
75 	.driver = {
76 		.owner =	THIS_MODULE,
77 		.name =		"debug",
78 	},
79 	.id_table =		id_table,
80 	.num_ports =		1,
81 	.bulk_out_size =	USB_DEBUG_MAX_PACKET_SIZE,
82 	.break_ctl =		usb_debug_break_ctl,
83 	.process_read_urb =	usb_debug_process_read_urb,
84 };
85 
86 static struct usb_serial_driver dbc_device = {
87 	.driver = {
88 		.owner =	THIS_MODULE,
89 		.name =		"xhci_dbc",
90 	},
91 	.id_table =		dbc_id_table,
92 	.num_ports =		1,
93 	.break_ctl =		usb_debug_break_ctl,
94 	.process_read_urb =	usb_debug_process_read_urb,
95 };
96 
97 static struct usb_serial_driver * const serial_drivers[] = {
98 	&debug_device, &dbc_device, NULL
99 };
100 
101 module_usb_serial_driver(serial_drivers, id_table_combined);
102 MODULE_LICENSE("GPL");
103