2 * ZTE_EV USB serial driver
4 * Copyright (C) 2012 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
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/init.h>
17 #include <linux/tty.h>
18 #include <linux/slab.h>
19 #include <linux/module.h>
20 #include <linux/usb.h>
21 #include <linux/usb/serial.h>
22 #include <linux/uaccess.h>
24 #define MAX_SETUP_DATA_SIZE 32
26 static void debug_data(struct device *dev, const char *function, int len,
27 const unsigned char *data, int result)
29 dev_dbg(dev, "result = %d\n", result);
31 dev_dbg(dev, "%s - length = %d, data = %*ph\n", function,
35 static int zte_ev_usb_serial_open(struct tty_struct *tty,
36 struct usb_serial_port *port)
38 struct usb_device *udev = port->serial->dev;
39 struct device *dev = &port->dev;
44 buf = kmalloc(MAX_SETUP_DATA_SIZE, GFP_KERNEL);
48 /* send 1st ctl cmd(CTL 21 22 01 00 00 00 00 00) */
50 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
52 0x0001, 0x0000, NULL, len,
53 USB_CTRL_GET_TIMEOUT);
54 dev_dbg(dev, "result = %d\n", result);
56 /* send 2st cmd and recieve data */
58 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 25.1.0(5)
59 * 16.0 DI 00 96 00 00 00 00 08
62 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
64 0x0000, 0x0000, buf, len,
65 USB_CTRL_GET_TIMEOUT);
66 debug_data(dev, __func__, len, buf, result);
70 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 30.1.0
71 * 16.0 DO 80 25 00 00 00 00 08 .%..... 30.2.0
81 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
83 0x0000, 0x0000, buf, len,
84 USB_CTRL_GET_TIMEOUT);
85 debug_data(dev, __func__, len, buf, result);
89 * 16.0 CTL 21 22 03 00 00 00 00 00
92 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
94 0x0003, 0x0000, NULL, len,
95 USB_CTRL_GET_TIMEOUT);
96 dev_dbg(dev, "result = %d\n", result);
100 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 33.1.0
101 * 16.0 DI 80 25 00 00 00 00 08
104 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
106 0x0000, 0x0000, buf, len,
107 USB_CTRL_GET_TIMEOUT);
108 debug_data(dev, __func__, len, buf, result);
112 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 34.1.0
113 * 16.0 DO 80 25 00 00 00 00 08
123 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
125 0x0000, 0x0000, buf, len,
126 USB_CTRL_GET_TIMEOUT);
127 debug_data(dev, __func__, len, buf, result);
130 return usb_serial_generic_open(tty, port);
134 * CTL 21 22 02 00 00 00 00 00 CLASS 338.1.0
136 * 16.1 DI a1 20 00 00 00 00 02 00 02 00 . ........ 340.1.0
137 * 16.0 CTL 21 22 03 00 00 00 00 00 CLASS 341.1.0
139 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 346.1.0(3)
140 * 16.0 DI 00 08 07 00 00 00 08 ....... 346.2.0
142 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 349.1.0
143 * 16.0 DO 00 c2 01 00 00 00 08 ....... 349.2.0
145 * 16.0 CTL 21 22 03 00 00 00 00 00 CLASS 350.1.0(2)
147 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 352.1.0
148 * 16.0 DI 00 c2 01 00 00 00 08 ....... 352.2.0
150 * 16.1 DI a1 20 00 00 00 00 02 00 02 00 . ........ 353.1.0
152 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 354.1.0
153 * 16.0 DO 00 c2 01 00 00 00 08 ....... 354.2.0
155 * 16.0 CTL 21 22 03 00 00 00 00 00
158 static void zte_ev_usb_serial_close(struct usb_serial_port *port)
160 struct usb_device *udev = port->serial->dev;
161 struct device *dev = &port->dev;
166 buf = kmalloc(MAX_SETUP_DATA_SIZE, GFP_KERNEL);
170 /* send 1st ctl cmd(CTL 21 22 02 00 00 00 00 00) */
172 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
174 0x0002, 0x0000, NULL, len,
175 USB_CTRL_GET_TIMEOUT);
176 dev_dbg(dev, "result = %d\n", result);
178 /* send 2st ctl cmd(CTL 21 22 03 00 00 00 00 00 ) */
180 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
182 0x0003, 0x0000, NULL, len,
183 USB_CTRL_GET_TIMEOUT);
184 dev_dbg(dev, "result = %d\n", result);
186 /* send 3st cmd and recieve data */
188 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 25.1.0(5)
189 * 16.0 DI 00 08 07 00 00 00 08
192 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
194 0x0000, 0x0000, buf, len,
195 USB_CTRL_GET_TIMEOUT);
196 debug_data(dev, __func__, len, buf, result);
200 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 30.1.0
201 * 16.0 DO 00 c2 01 00 00 00 08 .%..... 30.2.0
211 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
213 0x0000, 0x0000, buf, len,
214 USB_CTRL_GET_TIMEOUT);
215 debug_data(dev, __func__, len, buf, result);
219 * 16.0 CTL 21 22 03 00 00 00 00 00
222 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
224 0x0003, 0x0000, NULL, len,
225 USB_CTRL_GET_TIMEOUT);
226 dev_dbg(dev, "result = %d\n", result);
230 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 33.1.0
231 * 16.0 DI 00 c2 01 00 00 00 08
234 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
236 0x0000, 0x0000, buf, len,
237 USB_CTRL_GET_TIMEOUT);
238 debug_data(dev, __func__, len, buf, result);
242 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 354.1.0
243 * 16.0 DO 00 c2 01 00 00 00 08 ....... 354.2.0
253 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
255 0x0000, 0x0000, buf, len,
256 USB_CTRL_GET_TIMEOUT);
257 debug_data(dev, __func__, len, buf, result);
261 * 16.0 CTL 21 22 03 00 00 00 00 00
264 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
266 0x0003, 0x0000, NULL, len,
267 USB_CTRL_GET_TIMEOUT);
268 dev_dbg(dev, "result = %d\n", result);
272 usb_serial_generic_close(port);
275 static const struct usb_device_id id_table[] = {
276 /* AC8710, AC8710T */
277 { USB_DEVICE_AND_INTERFACE_INFO(0x19d2, 0xffff, 0xff, 0xff, 0xff) },
279 { USB_DEVICE_AND_INTERFACE_INFO(0x19d2, 0xfffe, 0xff, 0xff, 0xff) },
281 { USB_DEVICE(0x19d2, 0xfffd) },
282 { USB_DEVICE(0x19d2, 0xfffc) },
283 { USB_DEVICE(0x19d2, 0xfffb) },
284 /* AC2726, AC8710_V3 */
285 { USB_DEVICE_AND_INTERFACE_INFO(0x19d2, 0xfff1, 0xff, 0xff, 0xff) },
286 { USB_DEVICE(0x19d2, 0xfff6) },
287 { USB_DEVICE(0x19d2, 0xfff7) },
288 { USB_DEVICE(0x19d2, 0xfff8) },
289 { USB_DEVICE(0x19d2, 0xfff9) },
290 { USB_DEVICE(0x19d2, 0xffee) },
292 { USB_DEVICE_AND_INTERFACE_INFO(0x19d2, 0xffed, 0xff, 0xff, 0xff) },
294 { USB_DEVICE_AND_INTERFACE_INFO(0x19d2, 0xffeb, 0xff, 0xff, 0xff) },
295 { USB_DEVICE(0x19d2, 0xffec) },
296 { USB_DEVICE(0x05C6, 0x3197) },
297 { USB_DEVICE(0x05C6, 0x6000) },
298 { USB_DEVICE(0x05C6, 0x9008) },
301 MODULE_DEVICE_TABLE(usb, id_table);
303 static struct usb_serial_driver zio_device = {
305 .owner = THIS_MODULE,
308 .id_table = id_table,
310 .open = zte_ev_usb_serial_open,
311 .close = zte_ev_usb_serial_close,
314 static struct usb_serial_driver * const serial_drivers[] = {
318 module_usb_serial_driver(serial_drivers, id_table);
319 MODULE_LICENSE("GPL v2");