1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/tty.h>
16#include <linux/module.h>
17#include <linux/usb.h>
18#include <linux/usb/serial.h>
19#include <linux/uaccess.h>
20
21#define GSI_VENDOR_OPENCLOSE 0xB0
22
23static const struct usb_device_id id_table[] = {
24 { USB_DEVICE_AND_INTERFACE_INFO(0x1D50, 0x6062, 0xFF, 0xFF, 0xFF) },
25 { },
26};
27MODULE_DEVICE_TABLE(usb, id_table);
28
29
30
31
32
33
34
35static int usb_gsi_openclose(struct usb_serial_port *port, int value)
36{
37 struct usb_device *dev = port->serial->dev;
38
39 return usb_control_msg(
40 dev,
41 usb_sndctrlpipe(dev, 0),
42 GSI_VENDOR_OPENCLOSE,
43 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
44 value,
45 port->serial->interface->cur_altsetting->desc.bInterfaceNumber,
46 NULL, 0,
47 5000);
48}
49
50static int wishbone_serial_open(struct tty_struct *tty,
51 struct usb_serial_port *port)
52{
53 int retval;
54
55 retval = usb_gsi_openclose(port, 1);
56 if (retval) {
57 dev_err(&port->serial->dev->dev,
58 "Could not mark device as open (%d)\n",
59 retval);
60 return retval;
61 }
62
63 retval = usb_serial_generic_open(tty, port);
64 if (retval)
65 usb_gsi_openclose(port, 0);
66
67 return retval;
68}
69
70static void wishbone_serial_close(struct usb_serial_port *port)
71{
72 usb_serial_generic_close(port);
73 usb_gsi_openclose(port, 0);
74}
75
76static struct usb_serial_driver wishbone_serial_device = {
77 .driver = {
78 .owner = THIS_MODULE,
79 .name = "wishbone_serial",
80 },
81 .id_table = id_table,
82 .num_ports = 1,
83 .open = &wishbone_serial_open,
84 .close = &wishbone_serial_close,
85};
86
87static struct usb_serial_driver * const serial_drivers[] = {
88 &wishbone_serial_device, NULL
89};
90
91module_usb_serial_driver(serial_drivers, id_table);
92
93MODULE_AUTHOR("Wesley W. Terpstra <w.terpstra@gsi.de>");
94MODULE_DESCRIPTION("USB Wishbone-Serial adapter");
95MODULE_LICENSE("GPL");
96