xref: /linux/drivers/usb/serial/usb_debug.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
15fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2958e8741SGreg Kroah-Hartman /*
3958e8741SGreg Kroah-Hartman  * USB Debug cable driver
4958e8741SGreg Kroah-Hartman  *
5958e8741SGreg Kroah-Hartman  * Copyright (C) 2006 Greg Kroah-Hartman <greg@kroah.com>
6958e8741SGreg Kroah-Hartman  */
7958e8741SGreg Kroah-Hartman 
85a0e3ad6STejun Heo #include <linux/gfp.h>
9958e8741SGreg Kroah-Hartman #include <linux/kernel.h>
10958e8741SGreg Kroah-Hartman #include <linux/tty.h>
11958e8741SGreg Kroah-Hartman #include <linux/module.h>
12958e8741SGreg Kroah-Hartman #include <linux/usb.h>
13958e8741SGreg Kroah-Hartman #include <linux/usb/serial.h>
14958e8741SGreg Kroah-Hartman 
1571be4f81SAleksey Gorelov #define USB_DEBUG_MAX_PACKET_SIZE	8
1698fcb5f7SJason Wessel #define USB_DEBUG_BRK_SIZE		8
174f37fa54SJohan Hovold static const char USB_DEBUG_BRK[USB_DEBUG_BRK_SIZE] = {
1898fcb5f7SJason Wessel 	0x00,
1998fcb5f7SJason Wessel 	0xff,
2098fcb5f7SJason Wessel 	0x01,
2198fcb5f7SJason Wessel 	0xfe,
2298fcb5f7SJason Wessel 	0x00,
2398fcb5f7SJason Wessel 	0xfe,
2498fcb5f7SJason Wessel 	0x01,
2598fcb5f7SJason Wessel 	0xff,
2698fcb5f7SJason Wessel };
2771be4f81SAleksey Gorelov 
287d40d7e8SNémeth Márton static const struct usb_device_id id_table[] = {
29958e8741SGreg Kroah-Hartman 	{ USB_DEVICE(0x0525, 0x127a) },
30958e8741SGreg Kroah-Hartman 	{ },
31958e8741SGreg Kroah-Hartman };
3257fb4727SLu Baolu 
3357fb4727SLu Baolu static const struct usb_device_id dbc_id_table[] = {
34762ff467SLu Baolu 	{ USB_DEVICE(0x1d6b, 0x0010) },
3512f28144SLu Baolu 	{ USB_DEVICE(0x1d6b, 0x0011) },
3657fb4727SLu Baolu 	{ },
3757fb4727SLu Baolu };
3857fb4727SLu Baolu 
3957fb4727SLu Baolu static const struct usb_device_id id_table_combined[] = {
4057fb4727SLu Baolu 	{ USB_DEVICE(0x0525, 0x127a) },
41762ff467SLu Baolu 	{ USB_DEVICE(0x1d6b, 0x0010) },
4212f28144SLu Baolu 	{ USB_DEVICE(0x1d6b, 0x0011) },
4357fb4727SLu Baolu 	{ },
4457fb4727SLu Baolu };
4557fb4727SLu Baolu MODULE_DEVICE_TABLE(usb, id_table_combined);
46958e8741SGreg Kroah-Hartman 
4798fcb5f7SJason Wessel /* This HW really does not support a serial break, so one will be
4898fcb5f7SJason Wessel  * emulated when ever the break state is set to true.
4998fcb5f7SJason Wessel  */
usb_debug_break_ctl(struct tty_struct * tty,int break_state)506ff58ae1SJohan Hovold static int usb_debug_break_ctl(struct tty_struct *tty, int break_state)
5198fcb5f7SJason Wessel {
5298fcb5f7SJason Wessel 	struct usb_serial_port *port = tty->driver_data;
536ff58ae1SJohan Hovold 	int ret;
546ff58ae1SJohan Hovold 
5598fcb5f7SJason Wessel 	if (!break_state)
566ff58ae1SJohan Hovold 		return 0;
576ff58ae1SJohan Hovold 
586ff58ae1SJohan Hovold 	ret = usb_serial_generic_write(tty, port, USB_DEBUG_BRK, USB_DEBUG_BRK_SIZE);
596ff58ae1SJohan Hovold 	if (ret < 0)
606ff58ae1SJohan Hovold 		return ret;
616ff58ae1SJohan Hovold 
626ff58ae1SJohan Hovold 	return 0;
6398fcb5f7SJason Wessel }
6498fcb5f7SJason Wessel 
usb_debug_process_read_urb(struct urb * urb)65ac3695fbSJohan Hovold static void usb_debug_process_read_urb(struct urb *urb)
6698fcb5f7SJason Wessel {
6798fcb5f7SJason Wessel 	struct usb_serial_port *port = urb->context;
6898fcb5f7SJason Wessel 
6998fcb5f7SJason Wessel 	if (urb->actual_length == USB_DEBUG_BRK_SIZE &&
7098fcb5f7SJason Wessel 		memcmp(urb->transfer_buffer, USB_DEBUG_BRK,
7198fcb5f7SJason Wessel 						USB_DEBUG_BRK_SIZE) == 0) {
7298fcb5f7SJason Wessel 		usb_serial_handle_break(port);
7398fcb5f7SJason Wessel 		return;
7498fcb5f7SJason Wessel 	}
7598fcb5f7SJason Wessel 
76ac3695fbSJohan Hovold 	usb_serial_generic_process_read_urb(urb);
7798fcb5f7SJason Wessel }
7898fcb5f7SJason Wessel 
usb_debug_init_termios(struct tty_struct * tty)79*00af4f3dSMarek Marczykowski-Górecki static void usb_debug_init_termios(struct tty_struct *tty)
80*00af4f3dSMarek Marczykowski-Górecki {
81*00af4f3dSMarek Marczykowski-Górecki 	tty->termios.c_lflag &= ~(ECHO | ECHONL);
82*00af4f3dSMarek Marczykowski-Górecki }
83*00af4f3dSMarek Marczykowski-Górecki 
84958e8741SGreg Kroah-Hartman static struct usb_serial_driver debug_device = {
85958e8741SGreg Kroah-Hartman 	.driver = {
86958e8741SGreg Kroah-Hartman 		.name =		"debug",
87958e8741SGreg Kroah-Hartman 	},
88958e8741SGreg Kroah-Hartman 	.id_table =		id_table,
89958e8741SGreg Kroah-Hartman 	.num_ports =		1,
907288d755SJohan Hovold 	.bulk_out_size =	USB_DEBUG_MAX_PACKET_SIZE,
9198fcb5f7SJason Wessel 	.break_ctl =		usb_debug_break_ctl,
92*00af4f3dSMarek Marczykowski-Górecki 	.init_termios =		usb_debug_init_termios,
93ac3695fbSJohan Hovold 	.process_read_urb =	usb_debug_process_read_urb,
94958e8741SGreg Kroah-Hartman };
95958e8741SGreg Kroah-Hartman 
9657fb4727SLu Baolu static struct usb_serial_driver dbc_device = {
9757fb4727SLu Baolu 	.driver = {
9857fb4727SLu Baolu 		.name =		"xhci_dbc",
9957fb4727SLu Baolu 	},
10057fb4727SLu Baolu 	.id_table =		dbc_id_table,
10157fb4727SLu Baolu 	.num_ports =		1,
10257fb4727SLu Baolu 	.break_ctl =		usb_debug_break_ctl,
103*00af4f3dSMarek Marczykowski-Górecki 	.init_termios =		usb_debug_init_termios,
10457fb4727SLu Baolu 	.process_read_urb =	usb_debug_process_read_urb,
10529618e9fSAlan Stern };
10629618e9fSAlan Stern 
10757fb4727SLu Baolu static struct usb_serial_driver * const serial_drivers[] = {
10857fb4727SLu Baolu 	&debug_device, &dbc_device, NULL
10957fb4727SLu Baolu };
11057fb4727SLu Baolu 
11157fb4727SLu Baolu module_usb_serial_driver(serial_drivers, id_table_combined);
1129f4dc051SJeff Johnson MODULE_DESCRIPTION("USB Debug cable driver");
113627cfa89SJohan Hovold MODULE_LICENSE("GPL v2");
114