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 if (port->number != 0)
47 buf = kmalloc(MAX_SETUP_DATA_SIZE, GFP_KERNEL);
51 /* send 1st ctl cmd(CTL 21 22 01 00 00 00 00 00) */
53 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
55 0x0001, 0x0000, NULL, len,
56 HZ * USB_CTRL_GET_TIMEOUT);
57 dev_dbg(dev, "result = %d\n", result);
59 /* send 2st cmd and recieve data */
61 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 25.1.0(5)
62 * 16.0 DI 00 96 00 00 00 00 08
65 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
67 0x0000, 0x0000, buf, len,
68 HZ * USB_CTRL_GET_TIMEOUT);
69 debug_data(dev, __func__, len, buf, result);
73 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 30.1.0
74 * 16.0 DO 80 25 00 00 00 00 08 .%..... 30.2.0
84 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
86 0x0000, 0x0000, buf, len,
87 HZ * USB_CTRL_GET_TIMEOUT);
88 debug_data(dev, __func__, len, buf, result);
92 * 16.0 CTL 21 22 03 00 00 00 00 00
95 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
97 0x0003, 0x0000, NULL, len,
98 HZ * USB_CTRL_GET_TIMEOUT);
99 dev_dbg(dev, "result = %d\n", result);
103 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 33.1.0
104 * 16.0 DI 80 25 00 00 00 00 08
107 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
109 0x0000, 0x0000, buf, len,
110 HZ * USB_CTRL_GET_TIMEOUT);
111 debug_data(dev, __func__, len, buf, result);
115 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 34.1.0
116 * 16.0 DO 80 25 00 00 00 00 08
126 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
128 0x0000, 0x0000, buf, len,
129 HZ * USB_CTRL_GET_TIMEOUT);
130 debug_data(dev, __func__, len, buf, result);
133 return usb_serial_generic_open(tty, port);
137 * CTL 21 22 02 00 00 00 00 00 CLASS 338.1.0
139 * 16.1 DI a1 20 00 00 00 00 02 00 02 00 . ........ 340.1.0
140 * 16.0 CTL 21 22 03 00 00 00 00 00 CLASS 341.1.0
142 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 346.1.0(3)
143 * 16.0 DI 00 08 07 00 00 00 08 ....... 346.2.0
145 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 349.1.0
146 * 16.0 DO 00 c2 01 00 00 00 08 ....... 349.2.0
148 * 16.0 CTL 21 22 03 00 00 00 00 00 CLASS 350.1.0(2)
150 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 352.1.0
151 * 16.0 DI 00 c2 01 00 00 00 08 ....... 352.2.0
153 * 16.1 DI a1 20 00 00 00 00 02 00 02 00 . ........ 353.1.0
155 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 354.1.0
156 * 16.0 DO 00 c2 01 00 00 00 08 ....... 354.2.0
158 * 16.0 CTL 21 22 03 00 00 00 00 00
161 static void zte_ev_usb_serial_close(struct usb_serial_port *port)
163 struct usb_device *udev = port->serial->dev;
164 struct device *dev = &port->dev;
169 if (port->number != 0)
172 buf = kmalloc(MAX_SETUP_DATA_SIZE, GFP_KERNEL);
176 /* send 1st ctl cmd(CTL 21 22 02 00 00 00 00 00) */
178 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
180 0x0002, 0x0000, NULL, len,
181 HZ * USB_CTRL_GET_TIMEOUT);
182 dev_dbg(dev, "result = %d\n", result);
184 /* send 2st ctl cmd(CTL 21 22 03 00 00 00 00 00 ) */
186 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
188 0x0003, 0x0000, NULL, len,
189 HZ * USB_CTRL_GET_TIMEOUT);
190 dev_dbg(dev, "result = %d\n", result);
192 /* send 3st cmd and recieve data */
194 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 25.1.0(5)
195 * 16.0 DI 00 08 07 00 00 00 08
198 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
200 0x0000, 0x0000, buf, len,
201 HZ * USB_CTRL_GET_TIMEOUT);
202 debug_data(dev, __func__, len, buf, result);
206 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 30.1.0
207 * 16.0 DO 00 c2 01 00 00 00 08 .%..... 30.2.0
217 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
219 0x0000, 0x0000, buf, len,
220 HZ * USB_CTRL_GET_TIMEOUT);
221 debug_data(dev, __func__, len, buf, result);
225 * 16.0 CTL 21 22 03 00 00 00 00 00
228 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
230 0x0003, 0x0000, NULL, len,
231 HZ * USB_CTRL_GET_TIMEOUT);
232 dev_dbg(dev, "result = %d\n", result);
236 * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 33.1.0
237 * 16.0 DI 00 c2 01 00 00 00 08
240 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
242 0x0000, 0x0000, buf, len,
243 HZ * USB_CTRL_GET_TIMEOUT);
244 debug_data(dev, __func__, len, buf, result);
248 * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 354.1.0
249 * 16.0 DO 00 c2 01 00 00 00 08 ....... 354.2.0
259 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
261 0x0000, 0x0000, buf, len,
262 HZ * USB_CTRL_GET_TIMEOUT);
263 debug_data(dev, __func__, len, buf, result);
267 * 16.0 CTL 21 22 03 00 00 00 00 00
270 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
272 0x0003, 0x0000, NULL, len,
273 HZ * USB_CTRL_GET_TIMEOUT);
274 dev_dbg(dev, "result = %d\n", result);
278 usb_serial_generic_close(port);
281 static const struct usb_device_id id_table[] = {
282 { USB_DEVICE(0x19d2, 0xffff) }, /* AC8700 */
283 { USB_DEVICE(0x19d2, 0xfffe) },
284 { USB_DEVICE(0x19d2, 0xfffd) }, /* MG880 */
285 { USB_DEVICE(0x05C6, 0x3197) },
286 { USB_DEVICE(0x05C6, 0x6000) },
289 MODULE_DEVICE_TABLE(usb, id_table);
291 static struct usb_serial_driver zio_device = {
293 .owner = THIS_MODULE,
296 .id_table = id_table,
298 .open = zte_ev_usb_serial_open,
299 .close = zte_ev_usb_serial_close,
302 static struct usb_serial_driver * const serial_drivers[] = {
306 module_usb_serial_driver(serial_drivers, id_table);
307 MODULE_LICENSE("GPL v2");