2 * ZTE_EV USB serial driver
5 * Copyright (C) 2012 Linux Foundation
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This driver is based on code found in a ZTE_ENV patch that modified
12 * the usb-serial generic driver. Comments were left in that I think
13 * show the commands used to talk to the device, but I am not sure.
15 #include <linux/kernel.h>
16 #include <linux/tty.h>
17 #include <linux/slab.h>
18 #include <linux/module.h>
19 #include <linux/usb.h>
20 #include <linux/usb/serial.h>
21 #include <linux/uaccess.h>
23 #define MAX_SETUP_DATA_SIZE 32
25 static void debug_data(struct device *dev, const char *function, int len,
26 const unsigned char *data, int result)
28 dev_dbg(dev, "result = %d\n", result);
30 dev_dbg(dev, "%s - length = %d, data = %*ph\n", function,
34 static int zte_ev_usb_serial_open(struct tty_struct *tty,
35 struct usb_serial_port *port)
37 struct usb_device *udev = port->serial->dev;
38 struct device *dev = &port->dev;
43 buf = kmalloc(MAX_SETUP_DATA_SIZE, GFP_KERNEL);
47 /* send 1st ctl cmd(CTL 21 22 01 00 00 00 00 00) */
49 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
51 0x0001, 0x0000, NULL, len,
52 USB_CTRL_GET_TIMEOUT);
53 dev_dbg(dev, "result = %d\n", result);
55 /* send 2st cmd and receive data */
57 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 25.1.0(5)
58 * 16.0 DI 00 96 00 00 00 00 08
61 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
63 0x0000, 0x0000, buf, len,
64 USB_CTRL_GET_TIMEOUT);
65 debug_data(dev, __func__, len, buf, result);
69 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 30.1.0
70 * 16.0 DO 80 25 00 00 00 00 08 .%..... 30.2.0
80 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
82 0x0000, 0x0000, buf, len,
83 USB_CTRL_GET_TIMEOUT);
84 debug_data(dev, __func__, len, buf, result);
88 * 16.0 CTL 21 22 03 00 00 00 00 00
91 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
93 0x0003, 0x0000, NULL, len,
94 USB_CTRL_GET_TIMEOUT);
95 dev_dbg(dev, "result = %d\n", result);
99 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 33.1.0
100 * 16.0 DI 80 25 00 00 00 00 08
103 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
105 0x0000, 0x0000, buf, len,
106 USB_CTRL_GET_TIMEOUT);
107 debug_data(dev, __func__, len, buf, result);
111 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 34.1.0
112 * 16.0 DO 80 25 00 00 00 00 08
122 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
124 0x0000, 0x0000, buf, len,
125 USB_CTRL_GET_TIMEOUT);
126 debug_data(dev, __func__, len, buf, result);
129 return usb_serial_generic_open(tty, port);
133 * CTL 21 22 02 00 00 00 00 00 CLASS 338.1.0
135 * 16.1 DI a1 20 00 00 00 00 02 00 02 00 . ........ 340.1.0
136 * 16.0 CTL 21 22 03 00 00 00 00 00 CLASS 341.1.0
138 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 346.1.0(3)
139 * 16.0 DI 00 08 07 00 00 00 08 ....... 346.2.0
141 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 349.1.0
142 * 16.0 DO 00 c2 01 00 00 00 08 ....... 349.2.0
144 * 16.0 CTL 21 22 03 00 00 00 00 00 CLASS 350.1.0(2)
146 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 352.1.0
147 * 16.0 DI 00 c2 01 00 00 00 08 ....... 352.2.0
149 * 16.1 DI a1 20 00 00 00 00 02 00 02 00 . ........ 353.1.0
151 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 354.1.0
152 * 16.0 DO 00 c2 01 00 00 00 08 ....... 354.2.0
154 * 16.0 CTL 21 22 03 00 00 00 00 00
157 static void zte_ev_usb_serial_close(struct usb_serial_port *port)
159 struct usb_device *udev = port->serial->dev;
160 struct device *dev = &port->dev;
165 buf = kmalloc(MAX_SETUP_DATA_SIZE, GFP_KERNEL);
169 /* send 1st ctl cmd(CTL 21 22 02 00 00 00 00 00) */
171 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
173 0x0002, 0x0000, NULL, len,
174 USB_CTRL_GET_TIMEOUT);
175 dev_dbg(dev, "result = %d\n", result);
177 /* send 2st ctl cmd(CTL 21 22 03 00 00 00 00 00 ) */
179 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
181 0x0003, 0x0000, NULL, len,
182 USB_CTRL_GET_TIMEOUT);
183 dev_dbg(dev, "result = %d\n", result);
185 /* send 3st cmd and recieve data */
187 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 25.1.0(5)
188 * 16.0 DI 00 08 07 00 00 00 08
191 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
193 0x0000, 0x0000, buf, len,
194 USB_CTRL_GET_TIMEOUT);
195 debug_data(dev, __func__, len, buf, result);
199 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 30.1.0
200 * 16.0 DO 00 c2 01 00 00 00 08 .%..... 30.2.0
210 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
212 0x0000, 0x0000, buf, len,
213 USB_CTRL_GET_TIMEOUT);
214 debug_data(dev, __func__, len, buf, result);
218 * 16.0 CTL 21 22 03 00 00 00 00 00
221 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
223 0x0003, 0x0000, NULL, len,
224 USB_CTRL_GET_TIMEOUT);
225 dev_dbg(dev, "result = %d\n", result);
229 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 33.1.0
230 * 16.0 DI 00 c2 01 00 00 00 08
233 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
235 0x0000, 0x0000, buf, len,
236 USB_CTRL_GET_TIMEOUT);
237 debug_data(dev, __func__, len, buf, result);
241 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 354.1.0
242 * 16.0 DO 00 c2 01 00 00 00 08 ....... 354.2.0
252 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
254 0x0000, 0x0000, buf, len,
255 USB_CTRL_GET_TIMEOUT);
256 debug_data(dev, __func__, len, buf, result);
260 * 16.0 CTL 21 22 03 00 00 00 00 00
263 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
265 0x0003, 0x0000, NULL, len,
266 USB_CTRL_GET_TIMEOUT);
267 dev_dbg(dev, "result = %d\n", result);
271 usb_serial_generic_close(port);
274 static const struct usb_device_id id_table[] = {
275 /* AC8710, AC8710T */
276 { USB_DEVICE_AND_INTERFACE_INFO(0x19d2, 0xffff, 0xff, 0xff, 0xff) },
278 { USB_DEVICE_AND_INTERFACE_INFO(0x19d2, 0xfffe, 0xff, 0xff, 0xff) },
280 { USB_DEVICE(0x19d2, 0xfffd) },
281 { USB_DEVICE(0x19d2, 0xfffc) },
282 { USB_DEVICE(0x19d2, 0xfffb) },
284 { USB_DEVICE(0x19d2, 0xfff6) },
285 { USB_DEVICE(0x19d2, 0xfff7) },
286 { USB_DEVICE(0x19d2, 0xfff8) },
287 { USB_DEVICE(0x19d2, 0xfff9) },
288 { USB_DEVICE(0x19d2, 0xffee) },
290 { USB_DEVICE_AND_INTERFACE_INFO(0x19d2, 0xffed, 0xff, 0xff, 0xff) },
292 { USB_DEVICE_AND_INTERFACE_INFO(0x19d2, 0xffeb, 0xff, 0xff, 0xff) },
293 { USB_DEVICE(0x19d2, 0xffec) },
294 { USB_DEVICE(0x05C6, 0x3197) },
295 { USB_DEVICE(0x05C6, 0x6000) },
296 { USB_DEVICE(0x05C6, 0x9008) },
299 MODULE_DEVICE_TABLE(usb, id_table);
301 static struct usb_serial_driver zio_device = {
303 .owner = THIS_MODULE,
306 .id_table = id_table,
308 .open = zte_ev_usb_serial_open,
309 .close = zte_ev_usb_serial_close,
312 static struct usb_serial_driver * const serial_drivers[] = {
316 module_usb_serial_driver(serial_drivers, id_table);
317 MODULE_LICENSE("GPL v2");