Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * USB Wishbone-Serial adapter driver
0004  *
0005  * Copyright (C) 2013 Wesley W. Terpstra <w.terpstra@gsi.de>
0006  * Copyright (C) 2013 GSI Helmholtz Centre for Heavy Ion Research GmbH
0007  */
0008 
0009 #include <linux/kernel.h>
0010 #include <linux/tty.h>
0011 #include <linux/module.h>
0012 #include <linux/usb.h>
0013 #include <linux/usb/serial.h>
0014 #include <linux/uaccess.h>
0015 
0016 #define GSI_VENDOR_OPENCLOSE 0xB0
0017 
0018 static const struct usb_device_id id_table[] = {
0019     { USB_DEVICE_AND_INTERFACE_INFO(0x1D50, 0x6062, 0xFF, 0xFF, 0xFF) },
0020     { },
0021 };
0022 MODULE_DEVICE_TABLE(usb, id_table);
0023 
0024 /*
0025  * Etherbone must be told that a new stream has begun before data arrives.
0026  * This is necessary to restart the negotiation of Wishbone bus parameters.
0027  * Similarly, when the stream ends, Etherbone must be told so that the cycle
0028  * line can be driven low in the case that userspace failed to do so.
0029  */
0030 static int usb_gsi_openclose(struct usb_serial_port *port, int value)
0031 {
0032     struct usb_device *dev = port->serial->dev;
0033 
0034     return usb_control_msg(
0035         dev,
0036         usb_sndctrlpipe(dev, 0), /* Send to EP0OUT */
0037         GSI_VENDOR_OPENCLOSE,
0038         USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
0039         value, /* wValue = device is open(1) or closed(0) */
0040         port->serial->interface->cur_altsetting->desc.bInterfaceNumber,
0041         NULL, 0,  /* There is no data stage */
0042         5000); /* Timeout till operation fails */
0043 }
0044 
0045 static int wishbone_serial_open(struct tty_struct *tty,
0046                 struct usb_serial_port *port)
0047 {
0048     int retval;
0049 
0050     retval = usb_gsi_openclose(port, 1);
0051     if (retval) {
0052         dev_err(&port->serial->dev->dev,
0053                "Could not mark device as open (%d)\n",
0054                retval);
0055         return retval;
0056     }
0057 
0058     retval = usb_serial_generic_open(tty, port);
0059     if (retval)
0060         usb_gsi_openclose(port, 0);
0061 
0062     return retval;
0063 }
0064 
0065 static void wishbone_serial_close(struct usb_serial_port *port)
0066 {
0067     usb_serial_generic_close(port);
0068     usb_gsi_openclose(port, 0);
0069 }
0070 
0071 static struct usb_serial_driver wishbone_serial_device = {
0072     .driver = {
0073         .owner =    THIS_MODULE,
0074         .name =     "wishbone_serial",
0075     },
0076     .id_table =     id_table,
0077     .num_ports =        1,
0078     .open =         &wishbone_serial_open,
0079     .close =        &wishbone_serial_close,
0080 };
0081 
0082 static struct usb_serial_driver * const serial_drivers[] = {
0083     &wishbone_serial_device, NULL
0084 };
0085 
0086 module_usb_serial_driver(serial_drivers, id_table);
0087 
0088 MODULE_AUTHOR("Wesley W. Terpstra <w.terpstra@gsi.de>");
0089 MODULE_DESCRIPTION("USB Wishbone-Serial adapter");
0090 MODULE_LICENSE("GPL");