1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/tty.h>
15#include <linux/tty_flip.h>
16#include <linux/module.h>
17#include <linux/usb.h>
18#include <linux/usb/serial.h>
19#include <linux/slab.h>
20#include "usb-wwan.h"
21
22#define DRIVER_AUTHOR "Qualcomm Inc"
23#define DRIVER_DESC "Qualcomm USB Serial driver"
24
25static int debug;
26
27static const struct usb_device_id id_table[] = {
28 {USB_DEVICE(0x05c6, 0x9211)},
29 {USB_DEVICE(0x05c6, 0x9212)},
30 {USB_DEVICE(0x03f0, 0x1f1d)},
31 {USB_DEVICE(0x03f0, 0x201d)},
32 {USB_DEVICE(0x03f0, 0x371d)},
33 {USB_DEVICE(0x04da, 0x250d)},
34 {USB_DEVICE(0x04da, 0x250c)},
35 {USB_DEVICE(0x413c, 0x8172)},
36 {USB_DEVICE(0x413c, 0x8171)},
37 {USB_DEVICE(0x1410, 0xa001)},
38 {USB_DEVICE(0x1410, 0xa008)},
39 {USB_DEVICE(0x0b05, 0x1776)},
40 {USB_DEVICE(0x0b05, 0x1774)},
41 {USB_DEVICE(0x19d2, 0xfff3)},
42 {USB_DEVICE(0x19d2, 0xfff2)},
43 {USB_DEVICE(0x1557, 0x0a80)},
44 {USB_DEVICE(0x05c6, 0x9001)},
45 {USB_DEVICE(0x05c6, 0x9002)},
46 {USB_DEVICE(0x05c6, 0x9202)},
47 {USB_DEVICE(0x05c6, 0x9203)},
48 {USB_DEVICE(0x05c6, 0x9222)},
49 {USB_DEVICE(0x05c6, 0x9008)},
50 {USB_DEVICE(0x05c6, 0x9009)},
51 {USB_DEVICE(0x05c6, 0x9201)},
52 {USB_DEVICE(0x05c6, 0x9221)},
53 {USB_DEVICE(0x05c6, 0x9231)},
54 {USB_DEVICE(0x1f45, 0x0001)},
55 {USB_DEVICE(0x413c, 0x8185)},
56 {USB_DEVICE(0x413c, 0x8186)},
57 {USB_DEVICE(0x05c6, 0x9208)},
58 {USB_DEVICE(0x05c6, 0x920b)},
59 {USB_DEVICE(0x05c6, 0x9224)},
60 {USB_DEVICE(0x05c6, 0x9225)},
61 {USB_DEVICE(0x05c6, 0x9244)},
62 {USB_DEVICE(0x05c6, 0x9245)},
63 {USB_DEVICE(0x03f0, 0x241d)},
64 {USB_DEVICE(0x03f0, 0x251d)},
65 {USB_DEVICE(0x05c6, 0x9214)},
66 {USB_DEVICE(0x05c6, 0x9215)},
67 {USB_DEVICE(0x05c6, 0x9264)},
68 {USB_DEVICE(0x05c6, 0x9265)},
69 {USB_DEVICE(0x05c6, 0x9234)},
70 {USB_DEVICE(0x05c6, 0x9235)},
71 {USB_DEVICE(0x05c6, 0x9274)},
72 {USB_DEVICE(0x05c6, 0x9275)},
73 {USB_DEVICE(0x1199, 0x9000)},
74 {USB_DEVICE(0x1199, 0x9001)},
75 {USB_DEVICE(0x1199, 0x9002)},
76 {USB_DEVICE(0x1199, 0x9003)},
77 {USB_DEVICE(0x1199, 0x9004)},
78 {USB_DEVICE(0x1199, 0x9005)},
79 {USB_DEVICE(0x1199, 0x9006)},
80 {USB_DEVICE(0x1199, 0x9007)},
81 {USB_DEVICE(0x1199, 0x9008)},
82 {USB_DEVICE(0x1199, 0x9009)},
83 {USB_DEVICE(0x1199, 0x900a)},
84 {USB_DEVICE(0x1199, 0x9011)},
85 {USB_DEVICE(0x16d8, 0x8001)},
86 {USB_DEVICE(0x16d8, 0x8002)},
87 {USB_DEVICE(0x05c6, 0x9204)},
88 {USB_DEVICE(0x05c6, 0x9205)},
89 {USB_DEVICE(0x1199, 0x9013)},
90 { }
91};
92MODULE_DEVICE_TABLE(usb, id_table);
93
94static struct usb_driver qcdriver = {
95 .name = "qcserial",
96 .probe = usb_serial_probe,
97 .disconnect = usb_serial_disconnect,
98 .id_table = id_table,
99 .suspend = usb_serial_suspend,
100 .resume = usb_serial_resume,
101 .supports_autosuspend = true,
102};
103
104static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
105{
106 struct usb_wwan_intf_private *data;
107 struct usb_host_interface *intf = serial->interface->cur_altsetting;
108 int retval = -ENODEV;
109 __u8 nintf;
110 __u8 ifnum;
111
112 dbg("%s", __func__);
113
114 nintf = serial->dev->actconfig->desc.bNumInterfaces;
115 dbg("Num Interfaces = %d", nintf);
116 ifnum = intf->desc.bInterfaceNumber;
117 dbg("This Interface = %d", ifnum);
118
119 data = kzalloc(sizeof(struct usb_wwan_intf_private),
120 GFP_KERNEL);
121 if (!data)
122 return -ENOMEM;
123
124 spin_lock_init(&data->susp_lock);
125
126 usb_enable_autosuspend(serial->dev);
127
128 switch (nintf) {
129 case 1:
130
131
132 if (serial->interface->num_altsetting == 2)
133 intf = &serial->interface->altsetting[1];
134 else if (serial->interface->num_altsetting > 2)
135 break;
136
137 if (intf->desc.bNumEndpoints == 2 &&
138 usb_endpoint_is_bulk_in(&intf->endpoint[0].desc) &&
139 usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) {
140 dbg("QDL port found");
141
142 if (serial->interface->num_altsetting == 1) {
143 retval = 0;
144 break;
145 }
146
147 retval = usb_set_interface(serial->dev, ifnum, 1);
148 if (retval < 0) {
149 dev_err(&serial->dev->dev,
150 "Could not set interface, error %d\n",
151 retval);
152 retval = -ENODEV;
153 kfree(data);
154 }
155 }
156 break;
157
158 case 3:
159 case 4:
160
161
162 if (ifnum == 1) {
163
164
165
166
167
168 dbg("Diagnostics Monitor found");
169 retval = usb_set_interface(serial->dev, ifnum, 0);
170 if (retval < 0) {
171 dev_err(&serial->dev->dev,
172 "Could not set interface, error %d\n",
173 retval);
174 retval = -ENODEV;
175 kfree(data);
176 }
177 } else if (ifnum == 2) {
178 dbg("Modem port found");
179 retval = usb_set_interface(serial->dev, ifnum, 0);
180 if (retval < 0) {
181 dev_err(&serial->dev->dev,
182 "Could not set interface, error %d\n",
183 retval);
184 retval = -ENODEV;
185 kfree(data);
186 }
187 } else if (ifnum==3) {
188
189
190
191
192
193 dbg("NMEA GPS interface found");
194 retval = usb_set_interface(serial->dev, ifnum, 0);
195 if (retval < 0) {
196 dev_err(&serial->dev->dev,
197 "Could not set interface, error %d\n",
198 retval);
199 retval = -ENODEV;
200 kfree(data);
201 }
202 }
203 break;
204
205 default:
206 dev_err(&serial->dev->dev,
207 "unknown number of interfaces: %d\n", nintf);
208 kfree(data);
209 retval = -ENODEV;
210 }
211
212
213 if (retval != -ENODEV)
214 usb_set_serial_data(serial, data);
215 return retval;
216}
217
218static void qc_release(struct usb_serial *serial)
219{
220 struct usb_wwan_intf_private *priv = usb_get_serial_data(serial);
221
222 dbg("%s", __func__);
223
224
225 usb_wwan_release(serial);
226 usb_set_serial_data(serial, NULL);
227 kfree(priv);
228}
229
230static struct usb_serial_driver qcdevice = {
231 .driver = {
232 .owner = THIS_MODULE,
233 .name = "qcserial",
234 },
235 .description = "Qualcomm USB modem",
236 .id_table = id_table,
237 .usb_driver = &qcdriver,
238 .num_ports = 1,
239 .probe = qcprobe,
240 .open = usb_wwan_open,
241 .close = usb_wwan_close,
242 .write = usb_wwan_write,
243 .write_room = usb_wwan_write_room,
244 .chars_in_buffer = usb_wwan_chars_in_buffer,
245 .attach = usb_wwan_startup,
246 .disconnect = usb_wwan_disconnect,
247 .release = qc_release,
248#ifdef CONFIG_PM
249 .suspend = usb_wwan_suspend,
250 .resume = usb_wwan_resume,
251#endif
252};
253
254static int __init qcinit(void)
255{
256 int retval;
257
258 retval = usb_serial_register(&qcdevice);
259 if (retval)
260 return retval;
261
262 retval = usb_register(&qcdriver);
263 if (retval) {
264 usb_serial_deregister(&qcdevice);
265 return retval;
266 }
267
268 return 0;
269}
270
271static void __exit qcexit(void)
272{
273 usb_deregister(&qcdriver);
274 usb_serial_deregister(&qcdevice);
275}
276
277module_init(qcinit);
278module_exit(qcexit);
279
280MODULE_AUTHOR(DRIVER_AUTHOR);
281MODULE_DESCRIPTION(DRIVER_DESC);
282MODULE_LICENSE("GPL v2");
283
284module_param(debug, bool, S_IRUGO | S_IWUSR);
285MODULE_PARM_DESC(debug, "Debug enabled or not");
286