1958e8741SGreg Kroah-Hartman /* 2958e8741SGreg Kroah-Hartman * USB Debug cable driver 3958e8741SGreg Kroah-Hartman * 4958e8741SGreg Kroah-Hartman * Copyright (C) 2006 Greg Kroah-Hartman <[email protected]> 5958e8741SGreg Kroah-Hartman * 6958e8741SGreg Kroah-Hartman * This program is free software; you can redistribute it and/or 7958e8741SGreg Kroah-Hartman * modify it under the terms of the GNU General Public License version 8958e8741SGreg Kroah-Hartman * 2 as published by the Free Software Foundation. 9958e8741SGreg Kroah-Hartman */ 10958e8741SGreg Kroah-Hartman 115a0e3ad6STejun Heo #include <linux/gfp.h> 12958e8741SGreg Kroah-Hartman #include <linux/kernel.h> 13958e8741SGreg Kroah-Hartman #include <linux/tty.h> 14958e8741SGreg Kroah-Hartman #include <linux/module.h> 15958e8741SGreg Kroah-Hartman #include <linux/usb.h> 16958e8741SGreg Kroah-Hartman #include <linux/usb/serial.h> 17958e8741SGreg Kroah-Hartman 1871be4f81SAleksey Gorelov #define USB_DEBUG_MAX_PACKET_SIZE 8 1998fcb5f7SJason Wessel #define USB_DEBUG_BRK_SIZE 8 20*4f37fa54SJohan Hovold static const char USB_DEBUG_BRK[USB_DEBUG_BRK_SIZE] = { 2198fcb5f7SJason Wessel 0x00, 2298fcb5f7SJason Wessel 0xff, 2398fcb5f7SJason Wessel 0x01, 2498fcb5f7SJason Wessel 0xfe, 2598fcb5f7SJason Wessel 0x00, 2698fcb5f7SJason Wessel 0xfe, 2798fcb5f7SJason Wessel 0x01, 2898fcb5f7SJason Wessel 0xff, 2998fcb5f7SJason Wessel }; 3071be4f81SAleksey Gorelov 317d40d7e8SNémeth Márton static const struct usb_device_id id_table[] = { 32958e8741SGreg Kroah-Hartman { USB_DEVICE(0x0525, 0x127a) }, 33958e8741SGreg Kroah-Hartman { }, 34958e8741SGreg Kroah-Hartman }; 35958e8741SGreg Kroah-Hartman MODULE_DEVICE_TABLE(usb, id_table); 36958e8741SGreg Kroah-Hartman 3798fcb5f7SJason Wessel /* This HW really does not support a serial break, so one will be 3898fcb5f7SJason Wessel * emulated when ever the break state is set to true. 3998fcb5f7SJason Wessel */ 4098fcb5f7SJason Wessel static void usb_debug_break_ctl(struct tty_struct *tty, int break_state) 4198fcb5f7SJason Wessel { 4298fcb5f7SJason Wessel struct usb_serial_port *port = tty->driver_data; 4398fcb5f7SJason Wessel if (!break_state) 4498fcb5f7SJason Wessel return; 4598fcb5f7SJason Wessel usb_serial_generic_write(tty, port, USB_DEBUG_BRK, USB_DEBUG_BRK_SIZE); 4698fcb5f7SJason Wessel } 4798fcb5f7SJason Wessel 48ac3695fbSJohan Hovold static void usb_debug_process_read_urb(struct urb *urb) 4998fcb5f7SJason Wessel { 5098fcb5f7SJason Wessel struct usb_serial_port *port = urb->context; 5198fcb5f7SJason Wessel 5298fcb5f7SJason Wessel if (urb->actual_length == USB_DEBUG_BRK_SIZE && 5398fcb5f7SJason Wessel memcmp(urb->transfer_buffer, USB_DEBUG_BRK, 5498fcb5f7SJason Wessel USB_DEBUG_BRK_SIZE) == 0) { 5598fcb5f7SJason Wessel usb_serial_handle_break(port); 5698fcb5f7SJason Wessel return; 5798fcb5f7SJason Wessel } 5898fcb5f7SJason Wessel 59ac3695fbSJohan Hovold usb_serial_generic_process_read_urb(urb); 6098fcb5f7SJason Wessel } 6198fcb5f7SJason Wessel 62958e8741SGreg Kroah-Hartman static struct usb_serial_driver debug_device = { 63958e8741SGreg Kroah-Hartman .driver = { 64958e8741SGreg Kroah-Hartman .owner = THIS_MODULE, 65958e8741SGreg Kroah-Hartman .name = "debug", 66958e8741SGreg Kroah-Hartman }, 67958e8741SGreg Kroah-Hartman .id_table = id_table, 68958e8741SGreg Kroah-Hartman .num_ports = 1, 697288d755SJohan Hovold .bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE, 7098fcb5f7SJason Wessel .break_ctl = usb_debug_break_ctl, 71ac3695fbSJohan Hovold .process_read_urb = usb_debug_process_read_urb, 72958e8741SGreg Kroah-Hartman }; 73958e8741SGreg Kroah-Hartman 7429618e9fSAlan Stern static struct usb_serial_driver * const serial_drivers[] = { 7529618e9fSAlan Stern &debug_device, NULL 7629618e9fSAlan Stern }; 7729618e9fSAlan Stern 7868e24113SGreg Kroah-Hartman module_usb_serial_driver(serial_drivers, id_table); 79958e8741SGreg Kroah-Hartman MODULE_LICENSE("GPL"); 80