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 <[email protected]> 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 */ 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 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 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 .owner = THIS_MODULE, 87958e8741SGreg Kroah-Hartman .name = "debug", 88958e8741SGreg Kroah-Hartman }, 89958e8741SGreg Kroah-Hartman .id_table = id_table, 90958e8741SGreg Kroah-Hartman .num_ports = 1, 917288d755SJohan Hovold .bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE, 9298fcb5f7SJason Wessel .break_ctl = usb_debug_break_ctl, 93*00af4f3dSMarek Marczykowski-Górecki .init_termios = usb_debug_init_termios, 94ac3695fbSJohan Hovold .process_read_urb = usb_debug_process_read_urb, 95958e8741SGreg Kroah-Hartman }; 96958e8741SGreg Kroah-Hartman 9757fb4727SLu Baolu static struct usb_serial_driver dbc_device = { 9857fb4727SLu Baolu .driver = { 9957fb4727SLu Baolu .owner = THIS_MODULE, 10057fb4727SLu Baolu .name = "xhci_dbc", 10157fb4727SLu Baolu }, 10257fb4727SLu Baolu .id_table = dbc_id_table, 10357fb4727SLu Baolu .num_ports = 1, 10457fb4727SLu Baolu .break_ctl = usb_debug_break_ctl, 105*00af4f3dSMarek Marczykowski-Górecki .init_termios = usb_debug_init_termios, 10657fb4727SLu Baolu .process_read_urb = usb_debug_process_read_urb, 10729618e9fSAlan Stern }; 10829618e9fSAlan Stern 10957fb4727SLu Baolu static struct usb_serial_driver * const serial_drivers[] = { 11057fb4727SLu Baolu &debug_device, &dbc_device, NULL 11157fb4727SLu Baolu }; 11257fb4727SLu Baolu 11357fb4727SLu Baolu module_usb_serial_driver(serial_drivers, id_table_combined); 114627cfa89SJohan Hovold MODULE_LICENSE("GPL v2"); 115