1*5fd54aceSGreg 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 * This program is free software; you can redistribute it and/or 8958e8741SGreg Kroah-Hartman * modify it under the terms of the GNU General Public License version 9958e8741SGreg Kroah-Hartman * 2 as published by the Free Software Foundation. 10958e8741SGreg Kroah-Hartman */ 11958e8741SGreg Kroah-Hartman 125a0e3ad6STejun Heo #include <linux/gfp.h> 13958e8741SGreg Kroah-Hartman #include <linux/kernel.h> 14958e8741SGreg Kroah-Hartman #include <linux/tty.h> 15958e8741SGreg Kroah-Hartman #include <linux/module.h> 16958e8741SGreg Kroah-Hartman #include <linux/usb.h> 17958e8741SGreg Kroah-Hartman #include <linux/usb/serial.h> 18958e8741SGreg Kroah-Hartman 1971be4f81SAleksey Gorelov #define USB_DEBUG_MAX_PACKET_SIZE 8 2098fcb5f7SJason Wessel #define USB_DEBUG_BRK_SIZE 8 214f37fa54SJohan Hovold static const char USB_DEBUG_BRK[USB_DEBUG_BRK_SIZE] = { 2298fcb5f7SJason Wessel 0x00, 2398fcb5f7SJason Wessel 0xff, 2498fcb5f7SJason Wessel 0x01, 2598fcb5f7SJason Wessel 0xfe, 2698fcb5f7SJason Wessel 0x00, 2798fcb5f7SJason Wessel 0xfe, 2898fcb5f7SJason Wessel 0x01, 2998fcb5f7SJason Wessel 0xff, 3098fcb5f7SJason Wessel }; 3171be4f81SAleksey Gorelov 327d40d7e8SNémeth Márton static const struct usb_device_id id_table[] = { 33958e8741SGreg Kroah-Hartman { USB_DEVICE(0x0525, 0x127a) }, 34958e8741SGreg Kroah-Hartman { }, 35958e8741SGreg Kroah-Hartman }; 3657fb4727SLu Baolu 3757fb4727SLu Baolu static const struct usb_device_id dbc_id_table[] = { 3857fb4727SLu Baolu { USB_DEVICE(0x1d6b, 0x0004) }, 3957fb4727SLu Baolu { }, 4057fb4727SLu Baolu }; 4157fb4727SLu Baolu 4257fb4727SLu Baolu static const struct usb_device_id id_table_combined[] = { 4357fb4727SLu Baolu { USB_DEVICE(0x0525, 0x127a) }, 4457fb4727SLu Baolu { USB_DEVICE(0x1d6b, 0x0004) }, 4557fb4727SLu Baolu { }, 4657fb4727SLu Baolu }; 4757fb4727SLu Baolu MODULE_DEVICE_TABLE(usb, id_table_combined); 48958e8741SGreg Kroah-Hartman 4998fcb5f7SJason Wessel /* This HW really does not support a serial break, so one will be 5098fcb5f7SJason Wessel * emulated when ever the break state is set to true. 5198fcb5f7SJason Wessel */ 5298fcb5f7SJason Wessel static void usb_debug_break_ctl(struct tty_struct *tty, int break_state) 5398fcb5f7SJason Wessel { 5498fcb5f7SJason Wessel struct usb_serial_port *port = tty->driver_data; 5598fcb5f7SJason Wessel if (!break_state) 5698fcb5f7SJason Wessel return; 5798fcb5f7SJason Wessel usb_serial_generic_write(tty, port, USB_DEBUG_BRK, USB_DEBUG_BRK_SIZE); 5898fcb5f7SJason Wessel } 5998fcb5f7SJason Wessel 60ac3695fbSJohan Hovold static void usb_debug_process_read_urb(struct urb *urb) 6198fcb5f7SJason Wessel { 6298fcb5f7SJason Wessel struct usb_serial_port *port = urb->context; 6398fcb5f7SJason Wessel 6498fcb5f7SJason Wessel if (urb->actual_length == USB_DEBUG_BRK_SIZE && 6598fcb5f7SJason Wessel memcmp(urb->transfer_buffer, USB_DEBUG_BRK, 6698fcb5f7SJason Wessel USB_DEBUG_BRK_SIZE) == 0) { 6798fcb5f7SJason Wessel usb_serial_handle_break(port); 6898fcb5f7SJason Wessel return; 6998fcb5f7SJason Wessel } 7098fcb5f7SJason Wessel 71ac3695fbSJohan Hovold usb_serial_generic_process_read_urb(urb); 7298fcb5f7SJason Wessel } 7398fcb5f7SJason Wessel 74958e8741SGreg Kroah-Hartman static struct usb_serial_driver debug_device = { 75958e8741SGreg Kroah-Hartman .driver = { 76958e8741SGreg Kroah-Hartman .owner = THIS_MODULE, 77958e8741SGreg Kroah-Hartman .name = "debug", 78958e8741SGreg Kroah-Hartman }, 79958e8741SGreg Kroah-Hartman .id_table = id_table, 80958e8741SGreg Kroah-Hartman .num_ports = 1, 817288d755SJohan Hovold .bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE, 8298fcb5f7SJason Wessel .break_ctl = usb_debug_break_ctl, 83ac3695fbSJohan Hovold .process_read_urb = usb_debug_process_read_urb, 84958e8741SGreg Kroah-Hartman }; 85958e8741SGreg Kroah-Hartman 8657fb4727SLu Baolu static struct usb_serial_driver dbc_device = { 8757fb4727SLu Baolu .driver = { 8857fb4727SLu Baolu .owner = THIS_MODULE, 8957fb4727SLu Baolu .name = "xhci_dbc", 9057fb4727SLu Baolu }, 9157fb4727SLu Baolu .id_table = dbc_id_table, 9257fb4727SLu Baolu .num_ports = 1, 9357fb4727SLu Baolu .break_ctl = usb_debug_break_ctl, 9457fb4727SLu Baolu .process_read_urb = usb_debug_process_read_urb, 9529618e9fSAlan Stern }; 9629618e9fSAlan Stern 9757fb4727SLu Baolu static struct usb_serial_driver * const serial_drivers[] = { 9857fb4727SLu Baolu &debug_device, &dbc_device, NULL 9957fb4727SLu Baolu }; 10057fb4727SLu Baolu 10157fb4727SLu Baolu module_usb_serial_driver(serial_drivers, id_table_combined); 102958e8741SGreg Kroah-Hartman MODULE_LICENSE("GPL"); 103