Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * cdc-acm.c | |
3 | * | |
4 | * Copyright (c) 1999 Armin Fuerst <fuerst@in.tum.de> | |
a2531293 | 5 | * Copyright (c) 1999 Pavel Machek <pavel@ucw.cz> |
1da177e4 LT |
6 | * Copyright (c) 1999 Johannes Erdfelt <johannes@erdfelt.com> |
7 | * Copyright (c) 2000 Vojtech Pavlik <vojtech@suse.cz> | |
8 | * Copyright (c) 2004 Oliver Neukum <oliver@neukum.name> | |
61a87adf | 9 | * Copyright (c) 2005 David Kubicek <dave@awk.cz> |
088c64f8 | 10 | * Copyright (c) 2011 Johan Hovold <jhovold@gmail.com> |
1da177e4 LT |
11 | * |
12 | * USB Abstract Control Model driver for USB modems and ISDN adapters | |
13 | * | |
14 | * Sponsored by SuSE | |
15 | * | |
1da177e4 LT |
16 | * This program is free software; you can redistribute it and/or modify |
17 | * it under the terms of the GNU General Public License as published by | |
18 | * the Free Software Foundation; either version 2 of the License, or | |
19 | * (at your option) any later version. | |
20 | * | |
21 | * This program is distributed in the hope that it will be useful, | |
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | * GNU General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU General Public License | |
27 | * along with this program; if not, write to the Free Software | |
28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
29 | */ | |
30 | ||
31 | #undef DEBUG | |
e5fbab51 | 32 | #undef VERBOSE_DEBUG |
1da177e4 LT |
33 | |
34 | #include <linux/kernel.h> | |
35 | #include <linux/errno.h> | |
36 | #include <linux/init.h> | |
37 | #include <linux/slab.h> | |
38 | #include <linux/tty.h> | |
7af25b4b | 39 | #include <linux/serial.h> |
1da177e4 LT |
40 | #include <linux/tty_driver.h> |
41 | #include <linux/tty_flip.h> | |
42 | #include <linux/module.h> | |
4186ecf8 | 43 | #include <linux/mutex.h> |
10077d4a | 44 | #include <linux/uaccess.h> |
1da177e4 | 45 | #include <linux/usb.h> |
a8c28f23 | 46 | #include <linux/usb/cdc.h> |
1da177e4 LT |
47 | #include <asm/byteorder.h> |
48 | #include <asm/unaligned.h> | |
61a87adf | 49 | #include <linux/list.h> |
1da177e4 LT |
50 | |
51 | #include "cdc-acm.h" | |
52 | ||
6fa3eb70 S |
53 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
54 | ||
55 | /* adjust to 1 to avoid musb bug when lots write with clean urb */ | |
56 | #undef ACM_NW | |
57 | #define ACM_NW 1 | |
58 | /* adjust SZ to hsmaxp*20 to prevent tty disc don't accept big size write */ | |
59 | #define ACM_WB_SZ (512*20) | |
60 | ||
61 | #define DATA_DUMP_BYTES 15 // wx, how many bytes we'll print out for each packet | |
62 | #define DATA_DUMP_SIZE 64 // wx, should be large enough to hold DATA_DUMP_DIGITS | |
63 | static unsigned char data_out[DATA_DUMP_SIZE]; | |
64 | static unsigned char data_in[DATA_DUMP_SIZE]; | |
65 | /* Debug functions */ | |
66 | static int enable_debug = 0; | |
67 | static int enable_dump = 0; | |
68 | //origninal CDC-ACM log, more detail | |
69 | #undef dev_dbg | |
70 | #define dev_dbg(dev, format, args...) \ | |
71 | do{ \ | |
72 | if(enable_debug) { \ | |
73 | dev_printk(KERN_WARNING, dev, "[CDC-ACM] " format, ##args); \ | |
74 | } \ | |
75 | }while(0) | |
76 | #undef dev_vdbg | |
77 | #define dev_vdbg dev_dbg | |
78 | //MTK added CDC-ACM log, more critical | |
79 | #define dbg_mtk(dev, format, args...) \ | |
80 | do{ \ | |
81 | dev_printk(KERN_WARNING, dev, "[CDC-ACM-MTK] " format "\n", ##args); \ | |
82 | }while(0) | |
83 | #else | |
84 | #define dbg_mtk(dev, format, args...) do{}while(0) | |
85 | #endif | |
86 | ||
e5fbab51 | 87 | |
088c64f8 | 88 | #define DRIVER_AUTHOR "Armin Fuerst, Pavel Machek, Johannes Erdfelt, Vojtech Pavlik, David Kubicek, Johan Hovold" |
1da177e4 LT |
89 | #define DRIVER_DESC "USB Abstract Control Model driver for USB modems and ISDN adapters" |
90 | ||
91 | static struct usb_driver acm_driver; | |
92 | static struct tty_driver *acm_tty_driver; | |
93 | static struct acm *acm_table[ACM_TTY_MINORS]; | |
94 | ||
7fb57a01 | 95 | static DEFINE_MUTEX(acm_table_lock); |
1da177e4 | 96 | |
6fa3eb70 S |
97 | #define MYDBG(fmt, args...) do {printk(KERN_WARNING "MTK_ACM, <%s(), %d> " fmt, __func__, __LINE__, ## args); }while(0) |
98 | ||
99 | #ifdef CONFIG_MTK_DT_USB_SUPPORT | |
100 | ||
101 | #define RECORD_SZ 100 | |
102 | #define DUMP_DELAY 3 | |
103 | struct record_entry | |
104 | { | |
105 | struct timeval cur_time; | |
106 | u32 transfer_buffer_length; | |
107 | u32 actual_length; | |
108 | int status; | |
109 | unsigned char data; | |
110 | ||
111 | }w1[RECORD_SZ], w2[RECORD_SZ], r1[RECORD_SZ], r2[RECORD_SZ]; | |
112 | ||
113 | static int w1_idx, w2_idx, r1_idx, r2_idx; | |
114 | static int record_enable = 0; | |
115 | static struct timeval tv_start; | |
116 | void dump_record(void) | |
117 | { | |
118 | int i, index_limit; | |
119 | struct record_entry *ptr; | |
120 | ||
121 | index_limit = w1_idx; | |
122 | ptr = w1; | |
123 | for(i = 0; i < index_limit; i++){ | |
124 | MYDBG("w1, time:(%d,%d), reqlen:%d, data:%x\n", | |
125 | (unsigned int)ptr[i].cur_time.tv_sec, (unsigned int)ptr[i].cur_time.tv_usec, (unsigned int)ptr[i].transfer_buffer_length, ptr[i].data); | |
126 | mdelay(DUMP_DELAY); | |
127 | } | |
128 | ||
129 | index_limit = r1_idx; | |
130 | ptr = r1; | |
131 | for(i = 0; i < index_limit; i++){ | |
132 | MYDBG("r1, time:(%d,%d), reqlen:%d\n", | |
133 | (unsigned int)ptr[i].cur_time.tv_sec, (unsigned int)ptr[i].cur_time.tv_usec, ptr[i].transfer_buffer_length); | |
134 | mdelay(DUMP_DELAY); | |
135 | } | |
136 | ||
137 | index_limit = w2_idx; | |
138 | ptr = w2; | |
139 | for(i = 0; i < index_limit; i++){ | |
140 | MYDBG("w2, time:(%d,%d), reqlen:%d, actlen:%d, status:%d, data:%x\n", | |
141 | (unsigned int)ptr[i].cur_time.tv_sec, (unsigned int)ptr[i].cur_time.tv_usec, ptr[i].transfer_buffer_length, ptr[i].actual_length, ptr[i].status, ptr[i].data); | |
142 | mdelay(DUMP_DELAY); | |
143 | } | |
144 | ||
145 | index_limit = r2_idx; | |
146 | ptr = r2; | |
147 | for(i = 0; i < index_limit; i++){ | |
148 | MYDBG("r2, time:(%d,%d), reqlen:%d, actlen:%d, status:%d, data:%x\n", | |
149 | (unsigned int)ptr[i].cur_time.tv_sec, (unsigned int)ptr[i].cur_time.tv_usec, ptr[i].transfer_buffer_length, ptr[i].actual_length, ptr[i].status, ptr[i].data); | |
150 | mdelay(DUMP_DELAY); | |
151 | } | |
152 | ||
153 | } | |
154 | void record_activity(struct urb *urb, int is_in, int is_complete) | |
155 | { | |
156 | struct timeval tv_time; | |
157 | ||
158 | if(!record_enable) | |
159 | return; | |
160 | ||
161 | do_gettimeofday(&tv_time); | |
162 | tv_time.tv_sec = tv_time.tv_sec - tv_start.tv_sec; | |
163 | tv_time.tv_usec = tv_time.tv_usec - tv_start.tv_usec; | |
164 | if(is_in){ | |
165 | if(is_complete){ | |
166 | if(r2_idx >= RECORD_SZ) | |
167 | return; | |
168 | ||
169 | r2[r2_idx].cur_time = tv_time; | |
170 | r2[r2_idx].transfer_buffer_length = urb->transfer_buffer_length; | |
171 | r2[r2_idx].actual_length = urb->actual_length; | |
172 | r2[r2_idx].status = urb->status; | |
173 | r2[r2_idx].data = *((unsigned char*)urb->transfer_buffer); | |
174 | r2_idx++; | |
175 | return; | |
176 | } | |
177 | if(r1_idx >= RECORD_SZ) | |
178 | return; | |
179 | r1[r1_idx].cur_time = tv_time; | |
180 | r1[r1_idx].transfer_buffer_length = urb->transfer_buffer_length; | |
181 | r1[r1_idx].actual_length = urb->actual_length; | |
182 | r1[r1_idx].status = urb->status; | |
183 | r1_idx++; | |
184 | }else{ | |
185 | if(is_complete){ | |
186 | if(w2_idx >= RECORD_SZ) | |
187 | return; | |
188 | w2[w2_idx].cur_time = tv_time; | |
189 | w2[w2_idx].transfer_buffer_length = urb->transfer_buffer_length; | |
190 | w2[w2_idx].actual_length = urb->actual_length; | |
191 | w2[w2_idx].status = urb->status; | |
192 | w2[w2_idx].data = *((unsigned char*)urb->transfer_buffer); | |
193 | w2_idx++; | |
194 | return; | |
195 | } | |
196 | if(w1_idx >= RECORD_SZ) | |
197 | return; | |
198 | w1[w1_idx].cur_time = tv_time; | |
199 | w1[w1_idx].transfer_buffer_length = urb->transfer_buffer_length; | |
200 | w1[w1_idx].actual_length = urb->actual_length; | |
201 | w1[w1_idx].status = urb->status; | |
202 | w1[w1_idx].data = *((unsigned char*)urb->transfer_buffer); | |
203 | w1_idx++; | |
204 | } | |
205 | } | |
206 | ||
207 | bool usb_h_acm_all_clear(void) | |
208 | { | |
209 | int i; | |
210 | int count = 0; | |
211 | for (i = 0; i < ACM_TTY_MINORS; i++) { | |
212 | if(acm_table[i] != NULL) { | |
213 | count++; | |
214 | } | |
215 | } | |
216 | MYDBG("count<%d>\n", count); | |
217 | return !count; | |
218 | } | |
219 | EXPORT_SYMBOL_GPL(usb_h_acm_all_clear); | |
220 | ||
221 | #define CHECK_INTERVAL 2 | |
222 | #define CB_NUM 3 | |
223 | extern unsigned long volatile jiffies; | |
224 | static unsigned long callback_check_timeout[CB_NUM]; | |
225 | static char *callback_name[CB_NUM] = { | |
226 | "acm_read_bulk_callback", | |
227 | "acm_write_bulk", | |
228 | "acm_ctrl_irq", | |
229 | }; | |
230 | void mark_callback_alive(char *func_name, struct urb *urb, struct acm *acm) | |
231 | { | |
232 | ||
233 | ||
234 | int i; | |
235 | for(i = 0; i < CB_NUM ; i++) | |
236 | { | |
237 | if(!strcmp(func_name, callback_name[i])){ | |
238 | if(enable_debug || time_after(jiffies, callback_check_timeout[i])) | |
239 | { | |
240 | MYDBG("%s,ep(%d),len(%d,%d),data(%x),sts(%d), minor(%d)\n", | |
241 | func_name, | |
242 | urb->ep->desc.bEndpointAddress, | |
243 | urb->actual_length, | |
244 | urb->transfer_buffer_length, | |
245 | *((unsigned char*)urb->transfer_buffer), | |
246 | urb->status, | |
247 | acm->minor); | |
248 | callback_check_timeout[i] = jiffies + HZ * CHECK_INTERVAL; | |
249 | } | |
250 | break; | |
251 | } | |
252 | } | |
253 | } | |
254 | ||
255 | ||
256 | #endif | |
257 | ||
7fb57a01 HS |
258 | /* |
259 | * acm_table accessors | |
260 | */ | |
1da177e4 | 261 | |
7fb57a01 HS |
262 | /* |
263 | * Look up an ACM structure by index. If found and not disconnected, increment | |
264 | * its refcount and return it with its mutex held. | |
265 | */ | |
266 | static struct acm *acm_get_by_index(unsigned index) | |
267 | { | |
268 | struct acm *acm; | |
269 | ||
270 | mutex_lock(&acm_table_lock); | |
271 | acm = acm_table[index]; | |
272 | if (acm) { | |
273 | mutex_lock(&acm->mutex); | |
274 | if (acm->disconnected) { | |
275 | mutex_unlock(&acm->mutex); | |
276 | acm = NULL; | |
277 | } else { | |
278 | tty_port_get(&acm->port); | |
279 | mutex_unlock(&acm->mutex); | |
280 | } | |
281 | } | |
282 | mutex_unlock(&acm_table_lock); | |
283 | return acm; | |
284 | } | |
285 | ||
286 | /* | |
287 | * Try to find an available minor number and if found, associate it with 'acm'. | |
288 | */ | |
289 | static int acm_alloc_minor(struct acm *acm) | |
290 | { | |
291 | int minor; | |
292 | ||
293 | mutex_lock(&acm_table_lock); | |
294 | for (minor = 0; minor < ACM_TTY_MINORS; minor++) { | |
295 | if (!acm_table[minor]) { | |
296 | acm_table[minor] = acm; | |
297 | break; | |
298 | } | |
299 | } | |
300 | mutex_unlock(&acm_table_lock); | |
301 | ||
302 | return minor; | |
303 | } | |
304 | ||
305 | /* Release the minor number associated with 'acm'. */ | |
306 | static void acm_release_minor(struct acm *acm) | |
307 | { | |
308 | mutex_lock(&acm_table_lock); | |
309 | acm_table[acm->minor] = NULL; | |
310 | mutex_unlock(&acm_table_lock); | |
311 | } | |
739e0285 | 312 | |
1da177e4 LT |
313 | /* |
314 | * Functions for ACM control messages. | |
315 | */ | |
316 | ||
6e47e069 AC |
317 | static int acm_ctrl_msg(struct acm *acm, int request, int value, |
318 | void *buf, int len) | |
1da177e4 | 319 | { |
60c64b0c JH |
320 | int retval; |
321 | ||
322 | retval = usb_autopm_get_interface(acm->control); | |
323 | if (retval) | |
324 | return retval; | |
325 | ||
326 | retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), | |
1da177e4 LT |
327 | request, USB_RT_ACM, value, |
328 | acm->control->altsetting[0].desc.bInterfaceNumber, | |
329 | buf, len, 5000); | |
60c64b0c | 330 | |
a5cc7ef9 JH |
331 | dev_dbg(&acm->control->dev, |
332 | "%s - rq 0x%02x, val %#x, len %#x, result %d\n", | |
333 | __func__, request, value, len, retval); | |
60c64b0c JH |
334 | |
335 | usb_autopm_put_interface(acm->control); | |
336 | ||
1da177e4 LT |
337 | return retval < 0 ? retval : 0; |
338 | } | |
339 | ||
340 | /* devices aren't required to support these requests. | |
341 | * the cdc acm descriptor tells whether they do... | |
342 | */ | |
343 | #define acm_set_control(acm, control) \ | |
344 | acm_ctrl_msg(acm, USB_CDC_REQ_SET_CONTROL_LINE_STATE, control, NULL, 0) | |
345 | #define acm_set_line(acm, line) \ | |
346 | acm_ctrl_msg(acm, USB_CDC_REQ_SET_LINE_CODING, 0, line, sizeof *(line)) | |
347 | #define acm_send_break(acm, ms) \ | |
348 | acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0) | |
349 | ||
884b600f ON |
350 | /* |
351 | * Write buffer management. | |
352 | * All of these assume proper locks taken by the caller. | |
353 | */ | |
354 | ||
355 | static int acm_wb_alloc(struct acm *acm) | |
356 | { | |
357 | int i, wbn; | |
358 | struct acm_wb *wb; | |
359 | ||
e4cf3aa8 | 360 | wbn = 0; |
884b600f ON |
361 | i = 0; |
362 | for (;;) { | |
363 | wb = &acm->wb[wbn]; | |
364 | if (!wb->use) { | |
365 | wb->use = 1; | |
366 | return wbn; | |
367 | } | |
86478944 ON |
368 | wbn = (wbn + 1) % ACM_NW; |
369 | if (++i >= ACM_NW) | |
884b600f ON |
370 | return -1; |
371 | } | |
372 | } | |
373 | ||
884b600f ON |
374 | static int acm_wb_is_avail(struct acm *acm) |
375 | { | |
376 | int i, n; | |
e5fbab51 | 377 | unsigned long flags; |
884b600f | 378 | |
86478944 | 379 | n = ACM_NW; |
e5fbab51 | 380 | spin_lock_irqsave(&acm->write_lock, flags); |
6e47e069 | 381 | for (i = 0; i < ACM_NW; i++) |
86478944 | 382 | n -= acm->wb[i].use; |
e5fbab51 | 383 | spin_unlock_irqrestore(&acm->write_lock, flags); |
884b600f ON |
384 | return n; |
385 | } | |
386 | ||
884b600f | 387 | /* |
ad0b65ef | 388 | * Finish write. Caller must hold acm->write_lock |
884b600f | 389 | */ |
e4cf3aa8 | 390 | static void acm_write_done(struct acm *acm, struct acm_wb *wb) |
884b600f | 391 | { |
e4cf3aa8 | 392 | wb->use = 0; |
11ea859d | 393 | acm->transmitting--; |
97d35f95 | 394 | usb_autopm_put_interface_async(acm->control); |
884b600f ON |
395 | } |
396 | ||
397 | /* | |
398 | * Poke write. | |
11ea859d ON |
399 | * |
400 | * the caller is responsible for locking | |
884b600f | 401 | */ |
11ea859d ON |
402 | |
403 | static int acm_start_wb(struct acm *acm, struct acm_wb *wb) | |
404 | { | |
405 | int rc; | |
406 | ||
407 | acm->transmitting++; | |
408 | ||
409 | wb->urb->transfer_buffer = wb->buf; | |
410 | wb->urb->transfer_dma = wb->dmah; | |
411 | wb->urb->transfer_buffer_length = wb->len; | |
412 | wb->urb->dev = acm->dev; | |
413 | ||
6fa3eb70 S |
414 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
415 | record_activity(wb->urb, 0, 0); | |
416 | #endif | |
6e47e069 AC |
417 | rc = usb_submit_urb(wb->urb, GFP_ATOMIC); |
418 | if (rc < 0) { | |
a5cc7ef9 JH |
419 | dev_err(&acm->data->dev, |
420 | "%s - usb_submit_urb(write bulk) failed: %d\n", | |
421 | __func__, rc); | |
11ea859d ON |
422 | acm_write_done(acm, wb); |
423 | } | |
424 | return rc; | |
425 | } | |
426 | ||
e4cf3aa8 | 427 | static int acm_write_start(struct acm *acm, int wbn) |
884b600f ON |
428 | { |
429 | unsigned long flags; | |
934da463 | 430 | struct acm_wb *wb = &acm->wb[wbn]; |
884b600f ON |
431 | int rc; |
432 | ||
433 | spin_lock_irqsave(&acm->write_lock, flags); | |
434 | if (!acm->dev) { | |
934da463 | 435 | wb->use = 0; |
884b600f ON |
436 | spin_unlock_irqrestore(&acm->write_lock, flags); |
437 | return -ENODEV; | |
438 | } | |
439 | ||
5e9e75f8 | 440 | dev_vdbg(&acm->data->dev, "%s - susp_count %d\n", __func__, |
a5cc7ef9 | 441 | acm->susp_count); |
97d35f95 | 442 | usb_autopm_get_interface_async(acm->control); |
11ea859d | 443 | if (acm->susp_count) { |
67e8477b | 444 | usb_anchor_urb(wb->urb, &acm->delayed); |
11ea859d | 445 | spin_unlock_irqrestore(&acm->write_lock, flags); |
67e8477b | 446 | return 0; |
11ea859d ON |
447 | } |
448 | usb_mark_last_busy(acm->dev); | |
449 | ||
11ea859d | 450 | rc = acm_start_wb(acm, wb); |
884b600f ON |
451 | spin_unlock_irqrestore(&acm->write_lock, flags); |
452 | ||
884b600f | 453 | return rc; |
11ea859d | 454 | |
884b600f | 455 | } |
c4cabd28 ON |
456 | /* |
457 | * attributes exported through sysfs | |
458 | */ | |
459 | static ssize_t show_caps | |
460 | (struct device *dev, struct device_attribute *attr, char *buf) | |
461 | { | |
462 | struct usb_interface *intf = to_usb_interface(dev); | |
463 | struct acm *acm = usb_get_intfdata(intf); | |
464 | ||
465 | return sprintf(buf, "%d", acm->ctrl_caps); | |
466 | } | |
467 | static DEVICE_ATTR(bmCapabilities, S_IRUGO, show_caps, NULL); | |
468 | ||
469 | static ssize_t show_country_codes | |
470 | (struct device *dev, struct device_attribute *attr, char *buf) | |
471 | { | |
472 | struct usb_interface *intf = to_usb_interface(dev); | |
473 | struct acm *acm = usb_get_intfdata(intf); | |
474 | ||
475 | memcpy(buf, acm->country_codes, acm->country_code_size); | |
476 | return acm->country_code_size; | |
477 | } | |
478 | ||
479 | static DEVICE_ATTR(wCountryCodes, S_IRUGO, show_country_codes, NULL); | |
480 | ||
481 | static ssize_t show_country_rel_date | |
482 | (struct device *dev, struct device_attribute *attr, char *buf) | |
483 | { | |
484 | struct usb_interface *intf = to_usb_interface(dev); | |
485 | struct acm *acm = usb_get_intfdata(intf); | |
486 | ||
487 | return sprintf(buf, "%d", acm->country_rel_date); | |
488 | } | |
884b600f | 489 | |
c4cabd28 | 490 | static DEVICE_ATTR(iCountryCodeRelDate, S_IRUGO, show_country_rel_date, NULL); |
1da177e4 LT |
491 | /* |
492 | * Interrupt handlers for various ACM device responses | |
493 | */ | |
494 | ||
495 | /* control interface reports status changes with "interrupt" transfers */ | |
7d12e780 | 496 | static void acm_ctrl_irq(struct urb *urb) |
1da177e4 LT |
497 | { |
498 | struct acm *acm = urb->context; | |
499 | struct usb_cdc_notification *dr = urb->transfer_buffer; | |
500 | unsigned char *data; | |
501 | int newctrl; | |
185d4058 GKH |
502 | int retval; |
503 | int status = urb->status; | |
1da177e4 | 504 | |
185d4058 | 505 | switch (status) { |
1da177e4 LT |
506 | case 0: |
507 | /* success */ | |
508 | break; | |
509 | case -ECONNRESET: | |
510 | case -ENOENT: | |
511 | case -ESHUTDOWN: | |
512 | /* this urb is terminated, clean up */ | |
6fa3eb70 | 513 | dev_err(&acm->control->dev, |
a5cc7ef9 JH |
514 | "%s - urb shutting down with status: %d\n", |
515 | __func__, status); | |
1da177e4 LT |
516 | return; |
517 | default: | |
6fa3eb70 | 518 | dev_err(&acm->control->dev, |
a5cc7ef9 JH |
519 | "%s - nonzero urb status received: %d\n", |
520 | __func__, status); | |
1da177e4 LT |
521 | goto exit; |
522 | } | |
523 | ||
7e7797e7 | 524 | usb_mark_last_busy(acm->dev); |
6fa3eb70 S |
525 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
526 | mark_callback_alive(__func__, urb, acm); | |
527 | #endif | |
7e7797e7 | 528 | |
1da177e4 LT |
529 | data = (unsigned char *)(dr + 1); |
530 | switch (dr->bNotificationType) { | |
6e47e069 | 531 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: |
a5cc7ef9 JH |
532 | dev_dbg(&acm->control->dev, "%s - network connection: %d\n", |
533 | __func__, dr->wValue); | |
6e47e069 | 534 | break; |
1da177e4 | 535 | |
6e47e069 | 536 | case USB_CDC_NOTIFY_SERIAL_STATE: |
6e47e069 | 537 | newctrl = get_unaligned_le16(data); |
1da177e4 | 538 | |
aa27a094 JS |
539 | if (!acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { |
540 | dev_dbg(&acm->control->dev, "%s - calling hangup\n", | |
541 | __func__); | |
542 | tty_port_tty_hangup(&acm->port, false); | |
6e47e069 | 543 | } |
1da177e4 | 544 | |
6e47e069 | 545 | acm->ctrlin = newctrl; |
1da177e4 | 546 | |
a5cc7ef9 JH |
547 | dev_dbg(&acm->control->dev, |
548 | "%s - input control lines: dcd%c dsr%c break%c " | |
549 | "ring%c framing%c parity%c overrun%c\n", | |
550 | __func__, | |
6e47e069 AC |
551 | acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', |
552 | acm->ctrlin & ACM_CTRL_DSR ? '+' : '-', | |
553 | acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', | |
554 | acm->ctrlin & ACM_CTRL_RI ? '+' : '-', | |
555 | acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-', | |
556 | acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-', | |
557 | acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-'); | |
1da177e4 LT |
558 | break; |
559 | ||
6e47e069 | 560 | default: |
a5cc7ef9 JH |
561 | dev_dbg(&acm->control->dev, |
562 | "%s - unknown notification %d received: index %d " | |
563 | "len %d data0 %d data1 %d\n", | |
564 | __func__, | |
6e47e069 AC |
565 | dr->bNotificationType, dr->wIndex, |
566 | dr->wLength, data[0], data[1]); | |
567 | break; | |
1da177e4 LT |
568 | } |
569 | exit: | |
6e47e069 | 570 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
185d4058 | 571 | if (retval) |
1d9846e5 JH |
572 | dev_err(&acm->control->dev, "%s - usb_submit_urb failed: %d\n", |
573 | __func__, retval); | |
1da177e4 LT |
574 | } |
575 | ||
088c64f8 | 576 | static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags) |
1da177e4 | 577 | { |
088c64f8 | 578 | int res; |
185d4058 | 579 | |
6fa3eb70 | 580 | if (!test_and_clear_bit(index, &acm->read_urbs_free)){ |
088c64f8 | 581 | return 0; |
6fa3eb70 | 582 | } |
1da177e4 | 583 | |
088c64f8 JH |
584 | dev_vdbg(&acm->data->dev, "%s - urb %d\n", __func__, index); |
585 | ||
6fa3eb70 S |
586 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
587 | record_activity(acm->read_urbs[index], 1, 0); | |
588 | #endif | |
589 | ||
088c64f8 JH |
590 | res = usb_submit_urb(acm->read_urbs[index], mem_flags); |
591 | if (res) { | |
6fa3eb70 | 592 | MYDBG("urb fail(%d)\n", res); |
088c64f8 JH |
593 | if (res != -EPERM) { |
594 | dev_err(&acm->data->dev, | |
595 | "%s - usb_submit_urb failed: %d\n", | |
596 | __func__, res); | |
597 | } | |
598 | set_bit(index, &acm->read_urbs_free); | |
599 | return res; | |
11ea859d | 600 | } |
1da177e4 | 601 | |
088c64f8 JH |
602 | return 0; |
603 | } | |
1da177e4 | 604 | |
088c64f8 JH |
605 | static int acm_submit_read_urbs(struct acm *acm, gfp_t mem_flags) |
606 | { | |
607 | int res; | |
608 | int i; | |
61a87adf | 609 | |
088c64f8 JH |
610 | for (i = 0; i < acm->rx_buflimit; ++i) { |
611 | res = acm_submit_read_urb(acm, i, mem_flags); | |
6fa3eb70 | 612 | if (res){ |
088c64f8 | 613 | return res; |
6fa3eb70 | 614 | } |
86478944 | 615 | } |
088c64f8 JH |
616 | |
617 | return 0; | |
1da177e4 LT |
618 | } |
619 | ||
088c64f8 | 620 | static void acm_process_read_urb(struct acm *acm, struct urb *urb) |
1da177e4 | 621 | { |
6fa3eb70 S |
622 | |
623 | #ifdef CONFIG_MTK_DT_USB_SUPPORT | |
624 | int i, len; | |
625 | #endif | |
626 | if (!urb->actual_length){ | |
ca79b7b4 | 627 | return; |
6fa3eb70 S |
628 | } |
629 | #ifdef CONFIG_MTK_DT_USB_SUPPORT | |
630 | if(enable_dump) { | |
631 | len = sprintf(data_in, "DT-I: "); | |
632 | for(i=0; i<urb->actual_length && i<DATA_DUMP_BYTES; i++) { | |
633 | len += sprintf(data_in+len, "%02X ", *(((unsigned char *)(urb->transfer_buffer))+i)); | |
634 | } | |
635 | sprintf(data_in+len, "\n"); | |
636 | dbg_mtk(&acm->data->dev, "%s", data_in); | |
637 | } | |
638 | #endif | |
61a87adf | 639 | |
05c7cd39 JS |
640 | tty_insert_flip_string(&acm->port, urb->transfer_buffer, |
641 | urb->actual_length); | |
2e124b4a | 642 | tty_flip_buffer_push(&acm->port); |
088c64f8 | 643 | } |
10077d4a | 644 | |
088c64f8 JH |
645 | static void acm_read_bulk_callback(struct urb *urb) |
646 | { | |
647 | struct acm_rb *rb = urb->context; | |
648 | struct acm *acm = rb->instance; | |
649 | unsigned long flags; | |
61a87adf | 650 | |
088c64f8 JH |
651 | dev_vdbg(&acm->data->dev, "%s - urb %d, len %d\n", __func__, |
652 | rb->index, urb->actual_length); | |
653 | set_bit(rb->index, &acm->read_urbs_free); | |
61a87adf | 654 | |
6fa3eb70 S |
655 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
656 | record_activity(urb, 1, 1); | |
657 | #endif | |
658 | ||
088c64f8 JH |
659 | if (!acm->dev) { |
660 | dev_dbg(&acm->data->dev, "%s - disconnected\n", __func__); | |
661 | return; | |
662 | } | |
663 | usb_mark_last_busy(acm->dev); | |
61a87adf | 664 | |
088c64f8 | 665 | if (urb->status) { |
6fa3eb70 | 666 | dev_err(&acm->data->dev, "%s - non-zero urb status: %d\n", |
088c64f8 JH |
667 | __func__, urb->status); |
668 | return; | |
61a87adf | 669 | } |
6fa3eb70 S |
670 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
671 | mark_callback_alive(__func__, urb, acm); | |
672 | #endif | |
088c64f8 JH |
673 | acm_process_read_urb(acm, urb); |
674 | ||
675 | /* throttle device if requested by tty */ | |
11ea859d | 676 | spin_lock_irqsave(&acm->read_lock, flags); |
088c64f8 JH |
677 | acm->throttled = acm->throttle_req; |
678 | if (!acm->throttled && !acm->susp_count) { | |
679 | spin_unlock_irqrestore(&acm->read_lock, flags); | |
680 | acm_submit_read_urb(acm, rb->index, GFP_ATOMIC); | |
681 | } else { | |
682 | spin_unlock_irqrestore(&acm->read_lock, flags); | |
683 | } | |
1da177e4 LT |
684 | } |
685 | ||
686 | /* data interface wrote those outgoing bytes */ | |
7d12e780 | 687 | static void acm_write_bulk(struct urb *urb) |
1da177e4 | 688 | { |
cdc97792 | 689 | struct acm_wb *wb = urb->context; |
e5fbab51 | 690 | struct acm *acm = wb->instance; |
ad0b65ef | 691 | unsigned long flags; |
1da177e4 | 692 | |
6fa3eb70 S |
693 | |
694 | if (urb->status || (urb->actual_length != urb->transfer_buffer_length)){ | |
695 | dev_err(&acm->data->dev, "%s - len %d/%d, status %d, data(%x)\n", | |
1d9846e5 | 696 | __func__, |
e5fbab51 DB |
697 | urb->actual_length, |
698 | urb->transfer_buffer_length, | |
6fa3eb70 S |
699 | urb->status, |
700 | *((char *)(urb->transfer_buffer))); | |
701 | } | |
702 | #ifdef CONFIG_MTK_DT_USB_SUPPORT | |
703 | record_activity(urb, 0, 1); | |
704 | #endif | |
1da177e4 | 705 | |
6fa3eb70 S |
706 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
707 | mark_callback_alive(__func__, urb, acm); | |
708 | #endif | |
ad0b65ef | 709 | spin_lock_irqsave(&acm->write_lock, flags); |
e4cf3aa8 | 710 | acm_write_done(acm, wb); |
ad0b65ef | 711 | spin_unlock_irqrestore(&acm->write_lock, flags); |
99823f45 | 712 | schedule_work(&acm->work); |
1da177e4 LT |
713 | } |
714 | ||
c4028958 | 715 | static void acm_softint(struct work_struct *work) |
1da177e4 | 716 | { |
c4028958 | 717 | struct acm *acm = container_of(work, struct acm, work); |
e5fbab51 | 718 | |
1d9846e5 JH |
719 | dev_vdbg(&acm->data->dev, "%s\n", __func__); |
720 | ||
6aad04f2 | 721 | tty_port_tty_wakeup(&acm->port); |
1da177e4 LT |
722 | } |
723 | ||
724 | /* | |
725 | * TTY handlers | |
726 | */ | |
727 | ||
7fb57a01 | 728 | static int acm_tty_install(struct tty_driver *driver, struct tty_struct *tty) |
1da177e4 LT |
729 | { |
730 | struct acm *acm; | |
7fb57a01 | 731 | int retval; |
1da177e4 | 732 | |
7fb57a01 | 733 | dev_dbg(tty->dev, "%s\n", __func__); |
1da177e4 | 734 | |
7fb57a01 HS |
735 | acm = acm_get_by_index(tty->index); |
736 | if (!acm) | |
737 | return -ENODEV; | |
a5cc7ef9 | 738 | |
f8a8c10f | 739 | retval = tty_standard_install(driver, tty); |
7fb57a01 HS |
740 | if (retval) |
741 | goto error_init_termios; | |
10077d4a | 742 | |
1da177e4 | 743 | tty->driver_data = acm; |
1da177e4 | 744 | |
7fb57a01 HS |
745 | return 0; |
746 | ||
747 | error_init_termios: | |
748 | tty_port_put(&acm->port); | |
749 | return retval; | |
750 | } | |
751 | ||
6fa3eb70 S |
752 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
753 | extern struct usb_device *get_usb11_child_udev(void); | |
754 | extern int usb_autoresume_device(struct usb_device *udev); | |
755 | #endif | |
7fb57a01 HS |
756 | static int acm_tty_open(struct tty_struct *tty, struct file *filp) |
757 | { | |
6fa3eb70 S |
758 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
759 | struct usb_device *udev; | |
760 | int result; | |
761 | #endif | |
762 | struct acm *acm; | |
763 | acm = tty->driver_data; | |
764 | ||
765 | #ifdef CONFIG_MTK_DT_USB_SUPPORT | |
766 | dbg_mtk(&acm->control->dev, "%s port_cnt=%d", __func__, acm->port.count); | |
767 | MYDBG("ctrl:%x, read:%x, write:%x\n", | |
768 | (acm->control->cur_altsetting->endpoint[0].desc).bEndpointAddress, | |
769 | (acm->data->cur_altsetting->endpoint[0].desc).bEndpointAddress, | |
770 | (acm->data->cur_altsetting->endpoint[1].desc).bEndpointAddress); | |
771 | ||
7fb57a01 | 772 | |
6fa3eb70 S |
773 | #define META_BIN_NAME "meta_tst" |
774 | #define MDDOWNLOADER_BIN_NAME "downloader" | |
775 | ||
776 | /* make sure usb1 is always alive in dl/meta mode */ | |
777 | if(!strcmp(META_BIN_NAME, current->comm) || !strcmp(MDDOWNLOADER_BIN_NAME, current->comm)){ | |
778 | udev = get_usb11_child_udev(); | |
779 | result = usb_autoresume_device(udev); | |
780 | dbg_mtk(&acm->control->dev, "%s, auto result:%d", __func__, result); | |
781 | } | |
782 | ||
783 | if(!strcmp(MDDOWNLOADER_BIN_NAME, current->comm)){ | |
784 | record_enable = 1; | |
785 | w1_idx = w2_idx = r1_idx = r2_idx = 0; | |
786 | do_gettimeofday(&tv_start); | |
787 | } | |
788 | ||
789 | #else | |
790 | dev_dbg(&acm->control->dev, "%s\n", __func__); | |
791 | #endif | |
7fb57a01 HS |
792 | dev_dbg(tty->dev, "%s\n", __func__); |
793 | ||
794 | return tty_port_open(&acm->port, tty, filp); | |
795 | } | |
796 | ||
797 | static int acm_port_activate(struct tty_port *port, struct tty_struct *tty) | |
798 | { | |
799 | struct acm *acm = container_of(port, struct acm, port); | |
800 | int retval = -ENODEV; | |
39166123 | 801 | int i; |
7fb57a01 HS |
802 | |
803 | dev_dbg(&acm->control->dev, "%s\n", __func__); | |
1365baf7 ON |
804 | |
805 | mutex_lock(&acm->mutex); | |
7fb57a01 HS |
806 | if (acm->disconnected) |
807 | goto disconnected; | |
808 | ||
809 | retval = usb_autopm_get_interface(acm->control); | |
810 | if (retval) | |
811 | goto error_get_interface; | |
812 | ||
813 | /* | |
814 | * FIXME: Why do we need this? Allocating 64K of physically contiguous | |
815 | * memory is really nasty... | |
816 | */ | |
817 | set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); | |
818 | acm->control->needs_remote_wakeup = 1; | |
6fa3eb70 S |
819 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
820 | #ifdef CONFIG_PM_RUNTIME | |
821 | acm->control->needs_remote_wakeup = 0; | |
822 | #endif | |
823 | #endif | |
1365baf7 | 824 | |
1da177e4 | 825 | acm->ctrlurb->dev = acm->dev; |
817a471a JH |
826 | retval = usb_submit_urb(acm->ctrlurb, GFP_KERNEL); |
827 | if (retval) { | |
a5cc7ef9 JH |
828 | dev_err(&acm->control->dev, |
829 | "%s - usb_submit_urb(ctrl irq) failed\n", __func__); | |
7fb57a01 | 830 | goto error_submit_urb; |
1da177e4 LT |
831 | } |
832 | ||
7fb57a01 | 833 | acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS; |
817a471a JH |
834 | retval = acm_set_control(acm, acm->ctrlout); |
835 | if (retval < 0 && (acm->ctrl_caps & USB_CDC_CAP_LINE)) | |
7fb57a01 | 836 | goto error_set_control; |
10077d4a | 837 | |
6c4707f3 OM |
838 | /* |
839 | * Unthrottle device in case the TTY was closed while throttled. | |
840 | */ | |
841 | spin_lock_irq(&acm->read_lock); | |
842 | acm->throttled = 0; | |
843 | acm->throttle_req = 0; | |
844 | spin_unlock_irq(&acm->read_lock); | |
845 | ||
817a471a JH |
846 | retval = acm_submit_read_urbs(acm, GFP_KERNEL); |
847 | if (retval) | |
7fb57a01 | 848 | goto error_submit_read_urbs; |
2b626dc1 | 849 | |
256d49ba JH |
850 | usb_autopm_put_interface(acm->control); |
851 | ||
1365baf7 | 852 | mutex_unlock(&acm->mutex); |
1da177e4 | 853 | |
7fb57a01 HS |
854 | return 0; |
855 | ||
856 | error_submit_read_urbs: | |
39166123 JH |
857 | for (i = 0; i < acm->rx_buflimit; i++) |
858 | usb_kill_urb(acm->read_urbs[i]); | |
7fb57a01 HS |
859 | acm->ctrlout = 0; |
860 | acm_set_control(acm, acm->ctrlout); | |
861 | error_set_control: | |
862 | usb_kill_urb(acm->ctrlurb); | |
863 | error_submit_urb: | |
2b626dc1 | 864 | usb_autopm_put_interface(acm->control); |
7fb57a01 HS |
865 | error_get_interface: |
866 | disconnected: | |
867 | mutex_unlock(&acm->mutex); | |
817a471a JH |
868 | |
869 | return usb_translate_errors(retval); | |
1da177e4 LT |
870 | } |
871 | ||
7fb57a01 | 872 | static void acm_port_destruct(struct tty_port *port) |
83ef344a | 873 | { |
7fb57a01 HS |
874 | struct acm *acm = container_of(port, struct acm, port); |
875 | ||
876 | dev_dbg(&acm->control->dev, "%s\n", __func__); | |
61a87adf | 877 | |
7fb57a01 | 878 | acm_release_minor(acm); |
83ef344a | 879 | usb_put_intf(acm->control); |
c4cabd28 | 880 | kfree(acm->country_codes); |
83ef344a | 881 | kfree(acm); |
882 | } | |
883 | ||
7fb57a01 | 884 | static void acm_port_shutdown(struct tty_port *port) |
10077d4a | 885 | { |
7fb57a01 | 886 | struct acm *acm = container_of(port, struct acm, port); |
67e8477b JH |
887 | struct urb *urb; |
888 | struct acm_wb *wb; | |
dab54c9f | 889 | int i; |
4421a014 | 890 | int pm_err; |
dab54c9f | 891 | |
7fb57a01 HS |
892 | dev_dbg(&acm->control->dev, "%s\n", __func__); |
893 | ||
894 | mutex_lock(&acm->mutex); | |
895 | if (!acm->disconnected) { | |
4421a014 | 896 | pm_err = usb_autopm_get_interface(acm->control); |
10077d4a | 897 | acm_set_control(acm, acm->ctrlout = 0); |
67e8477b JH |
898 | |
899 | for (;;) { | |
900 | urb = usb_get_from_anchor(&acm->delayed); | |
901 | if (!urb) | |
902 | break; | |
903 | wb = urb->context; | |
904 | wb->use = 0; | |
905 | usb_autopm_put_interface_async(acm->control); | |
906 | } | |
907 | ||
10077d4a AC |
908 | usb_kill_urb(acm->ctrlurb); |
909 | for (i = 0; i < ACM_NW; i++) | |
910 | usb_kill_urb(acm->wb[i].urb); | |
dab54c9f | 911 | for (i = 0; i < acm->rx_buflimit; i++) |
088c64f8 | 912 | usb_kill_urb(acm->read_urbs[i]); |
10077d4a | 913 | acm->control->needs_remote_wakeup = 0; |
4421a014 JH |
914 | if (!pm_err) |
915 | usb_autopm_put_interface(acm->control); | |
10077d4a | 916 | } |
7fb57a01 HS |
917 | mutex_unlock(&acm->mutex); |
918 | } | |
919 | ||
920 | static void acm_tty_cleanup(struct tty_struct *tty) | |
921 | { | |
922 | struct acm *acm = tty->driver_data; | |
923 | dev_dbg(&acm->control->dev, "%s\n", __func__); | |
924 | tty_port_put(&acm->port); | |
10077d4a AC |
925 | } |
926 | ||
927 | static void acm_tty_hangup(struct tty_struct *tty) | |
928 | { | |
929 | struct acm *acm = tty->driver_data; | |
7fb57a01 | 930 | dev_dbg(&acm->control->dev, "%s\n", __func__); |
10077d4a | 931 | tty_port_hangup(&acm->port); |
10077d4a AC |
932 | } |
933 | ||
1da177e4 LT |
934 | static void acm_tty_close(struct tty_struct *tty, struct file *filp) |
935 | { | |
936 | struct acm *acm = tty->driver_data; | |
7fb57a01 | 937 | dev_dbg(&acm->control->dev, "%s\n", __func__); |
6fa3eb70 S |
938 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
939 | dbg_mtk(&acm->control->dev, "%s port_cnt=%d", __func__, acm->port.count); | |
940 | if(!strcmp(MDDOWNLOADER_BIN_NAME, current->comm)){ | |
941 | record_enable = 0; | |
942 | dump_record(); | |
943 | } | |
944 | #endif | |
7fb57a01 | 945 | tty_port_close(&acm->port, tty, filp); |
1da177e4 LT |
946 | } |
947 | ||
6e47e069 AC |
948 | static int acm_tty_write(struct tty_struct *tty, |
949 | const unsigned char *buf, int count) | |
1da177e4 LT |
950 | { |
951 | struct acm *acm = tty->driver_data; | |
952 | int stat; | |
884b600f ON |
953 | unsigned long flags; |
954 | int wbn; | |
955 | struct acm_wb *wb; | |
6fa3eb70 S |
956 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
957 | int i, len; | |
958 | #endif | |
884b600f | 959 | |
1da177e4 LT |
960 | if (!count) |
961 | return 0; | |
962 | ||
5e9e75f8 | 963 | dev_vdbg(&acm->data->dev, "%s - count %d\n", __func__, count); |
a5cc7ef9 | 964 | |
6fa3eb70 S |
965 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
966 | if(enable_dump) { | |
967 | len = sprintf(data_out, "DT-O: "); | |
968 | for(i=0; i<count && i<DATA_DUMP_BYTES; i++) { | |
969 | len += sprintf(data_out+len, "%02X ", *(buf+i)); | |
970 | } | |
971 | sprintf(data_out+len, "\n"); | |
972 | dbg_mtk(&acm->data->dev, "%s", data_out); | |
973 | } | |
974 | #endif | |
884b600f | 975 | spin_lock_irqsave(&acm->write_lock, flags); |
6e47e069 AC |
976 | wbn = acm_wb_alloc(acm); |
977 | if (wbn < 0) { | |
884b600f | 978 | spin_unlock_irqrestore(&acm->write_lock, flags); |
884b600f ON |
979 | return 0; |
980 | } | |
981 | wb = &acm->wb[wbn]; | |
1da177e4 | 982 | |
884b600f | 983 | count = (count > acm->writesize) ? acm->writesize : count; |
5e9e75f8 | 984 | dev_vdbg(&acm->data->dev, "%s - write %d\n", __func__, count); |
884b600f ON |
985 | memcpy(wb->buf, buf, count); |
986 | wb->len = count; | |
987 | spin_unlock_irqrestore(&acm->write_lock, flags); | |
1da177e4 | 988 | |
6e47e069 AC |
989 | stat = acm_write_start(acm, wbn); |
990 | if (stat < 0) | |
1da177e4 | 991 | return stat; |
1da177e4 LT |
992 | return count; |
993 | } | |
994 | ||
995 | static int acm_tty_write_room(struct tty_struct *tty) | |
996 | { | |
997 | struct acm *acm = tty->driver_data; | |
884b600f ON |
998 | /* |
999 | * Do not let the line discipline to know that we have a reserve, | |
1000 | * or it might get too enthusiastic. | |
1001 | */ | |
934da463 | 1002 | return acm_wb_is_avail(acm) ? acm->writesize : 0; |
1da177e4 LT |
1003 | } |
1004 | ||
1005 | static int acm_tty_chars_in_buffer(struct tty_struct *tty) | |
1006 | { | |
1007 | struct acm *acm = tty->driver_data; | |
7fb57a01 HS |
1008 | /* |
1009 | * if the device was unplugged then any remaining characters fell out | |
1010 | * of the connector ;) | |
1011 | */ | |
1012 | if (acm->disconnected) | |
23198fda | 1013 | return 0; |
884b600f ON |
1014 | /* |
1015 | * This is inaccurate (overcounts), but it works. | |
1016 | */ | |
86478944 | 1017 | return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize; |
1da177e4 LT |
1018 | } |
1019 | ||
1020 | static void acm_tty_throttle(struct tty_struct *tty) | |
1021 | { | |
1022 | struct acm *acm = tty->driver_data; | |
088c64f8 | 1023 | |
088c64f8 JH |
1024 | spin_lock_irq(&acm->read_lock); |
1025 | acm->throttle_req = 1; | |
1026 | spin_unlock_irq(&acm->read_lock); | |
1da177e4 LT |
1027 | } |
1028 | ||
1029 | static void acm_tty_unthrottle(struct tty_struct *tty) | |
1030 | { | |
1031 | struct acm *acm = tty->driver_data; | |
088c64f8 JH |
1032 | unsigned int was_throttled; |
1033 | ||
088c64f8 JH |
1034 | spin_lock_irq(&acm->read_lock); |
1035 | was_throttled = acm->throttled; | |
1036 | acm->throttled = 0; | |
1037 | acm->throttle_req = 0; | |
1038 | spin_unlock_irq(&acm->read_lock); | |
1039 | ||
1040 | if (was_throttled) | |
1041 | acm_submit_read_urbs(acm, GFP_KERNEL); | |
1da177e4 LT |
1042 | } |
1043 | ||
9e98966c | 1044 | static int acm_tty_break_ctl(struct tty_struct *tty, int state) |
1da177e4 LT |
1045 | { |
1046 | struct acm *acm = tty->driver_data; | |
9e98966c | 1047 | int retval; |
7fb57a01 | 1048 | |
9e98966c AC |
1049 | retval = acm_send_break(acm, state ? 0xffff : 0); |
1050 | if (retval < 0) | |
a5cc7ef9 JH |
1051 | dev_dbg(&acm->control->dev, "%s - send break failed\n", |
1052 | __func__); | |
9e98966c | 1053 | return retval; |
1da177e4 LT |
1054 | } |
1055 | ||
60b33c13 | 1056 | static int acm_tty_tiocmget(struct tty_struct *tty) |
1da177e4 LT |
1057 | { |
1058 | struct acm *acm = tty->driver_data; | |
1059 | ||
6fa3eb70 S |
1060 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
1061 | if(enable_dump) { | |
1062 | dbg_mtk(&acm->control->dev, "tiocmget ctrlin=%x\n", acm->ctrlin); | |
1063 | } | |
1064 | #endif | |
1da177e4 LT |
1065 | return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) | |
1066 | (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) | | |
1067 | (acm->ctrlin & ACM_CTRL_DSR ? TIOCM_DSR : 0) | | |
1068 | (acm->ctrlin & ACM_CTRL_RI ? TIOCM_RI : 0) | | |
1069 | (acm->ctrlin & ACM_CTRL_DCD ? TIOCM_CD : 0) | | |
1070 | TIOCM_CTS; | |
1071 | } | |
1072 | ||
20b9d177 | 1073 | static int acm_tty_tiocmset(struct tty_struct *tty, |
1da177e4 LT |
1074 | unsigned int set, unsigned int clear) |
1075 | { | |
1076 | struct acm *acm = tty->driver_data; | |
1077 | unsigned int newctrl; | |
1078 | ||
6fa3eb70 S |
1079 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
1080 | if(enable_dump) { | |
1081 | dbg_mtk(&acm->control->dev, "tiocmset ctrlout=%x\n", acm->ctrlout); | |
1082 | } | |
1083 | #endif | |
1da177e4 | 1084 | newctrl = acm->ctrlout; |
6e47e069 AC |
1085 | set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | |
1086 | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); | |
1087 | clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | | |
1088 | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); | |
1da177e4 LT |
1089 | |
1090 | newctrl = (newctrl & ~clear) | set; | |
1091 | ||
1092 | if (acm->ctrlout == newctrl) | |
1093 | return 0; | |
1094 | return acm_set_control(acm, acm->ctrlout = newctrl); | |
1095 | } | |
1096 | ||
18c75720 ON |
1097 | static int get_serial_info(struct acm *acm, struct serial_struct __user *info) |
1098 | { | |
1099 | struct serial_struct tmp; | |
1100 | ||
1101 | if (!info) | |
1102 | return -EINVAL; | |
1103 | ||
1104 | memset(&tmp, 0, sizeof(tmp)); | |
1105 | tmp.flags = ASYNC_LOW_LATENCY; | |
1106 | tmp.xmit_fifo_size = acm->writesize; | |
1107 | tmp.baud_base = le32_to_cpu(acm->line.dwDTERate); | |
ba2d8ce9 DW |
1108 | tmp.close_delay = acm->port.close_delay / 10; |
1109 | tmp.closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? | |
1110 | ASYNC_CLOSING_WAIT_NONE : | |
1111 | acm->port.closing_wait / 10; | |
18c75720 ON |
1112 | |
1113 | if (copy_to_user(info, &tmp, sizeof(tmp))) | |
1114 | return -EFAULT; | |
1115 | else | |
1116 | return 0; | |
1117 | } | |
1118 | ||
ba2d8ce9 DW |
1119 | static int set_serial_info(struct acm *acm, |
1120 | struct serial_struct __user *newinfo) | |
1121 | { | |
1122 | struct serial_struct new_serial; | |
1123 | unsigned int closing_wait, close_delay; | |
1124 | int retval = 0; | |
1125 | ||
1126 | if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) | |
1127 | return -EFAULT; | |
1128 | ||
1129 | close_delay = new_serial.close_delay * 10; | |
1130 | closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ? | |
1131 | ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10; | |
1132 | ||
1133 | mutex_lock(&acm->port.mutex); | |
1134 | ||
1135 | if (!capable(CAP_SYS_ADMIN)) { | |
1136 | if ((close_delay != acm->port.close_delay) || | |
1137 | (closing_wait != acm->port.closing_wait)) | |
1138 | retval = -EPERM; | |
1139 | else | |
1140 | retval = -EOPNOTSUPP; | |
1141 | } else { | |
1142 | acm->port.close_delay = close_delay; | |
1143 | acm->port.closing_wait = closing_wait; | |
1144 | } | |
1145 | ||
1146 | mutex_unlock(&acm->port.mutex); | |
1147 | return retval; | |
1148 | } | |
1149 | ||
6caa76b7 | 1150 | static int acm_tty_ioctl(struct tty_struct *tty, |
6e47e069 | 1151 | unsigned int cmd, unsigned long arg) |
1da177e4 | 1152 | { |
18c75720 ON |
1153 | struct acm *acm = tty->driver_data; |
1154 | int rv = -ENOIOCTLCMD; | |
1155 | ||
1156 | switch (cmd) { | |
1157 | case TIOCGSERIAL: /* gets serial port data */ | |
1158 | rv = get_serial_info(acm, (struct serial_struct __user *) arg); | |
ba2d8ce9 DW |
1159 | break; |
1160 | case TIOCSSERIAL: | |
1161 | rv = set_serial_info(acm, (struct serial_struct __user *) arg); | |
18c75720 ON |
1162 | break; |
1163 | } | |
1164 | ||
1165 | return rv; | |
1da177e4 LT |
1166 | } |
1167 | ||
6e47e069 AC |
1168 | static void acm_tty_set_termios(struct tty_struct *tty, |
1169 | struct ktermios *termios_old) | |
1da177e4 LT |
1170 | { |
1171 | struct acm *acm = tty->driver_data; | |
adc8d746 | 1172 | struct ktermios *termios = &tty->termios; |
1da177e4 LT |
1173 | struct usb_cdc_line_coding newline; |
1174 | int newctrl = acm->ctrlout; | |
1175 | ||
9b80fee1 | 1176 | newline.dwDTERate = cpu_to_le32(tty_get_baud_rate(tty)); |
1da177e4 LT |
1177 | newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; |
1178 | newline.bParityType = termios->c_cflag & PARENB ? | |
6e47e069 AC |
1179 | (termios->c_cflag & PARODD ? 1 : 2) + |
1180 | (termios->c_cflag & CMSPAR ? 2 : 0) : 0; | |
301a29da NB |
1181 | switch (termios->c_cflag & CSIZE) { |
1182 | case CS5: | |
1183 | newline.bDataBits = 5; | |
1184 | break; | |
1185 | case CS6: | |
1186 | newline.bDataBits = 6; | |
1187 | break; | |
1188 | case CS7: | |
1189 | newline.bDataBits = 7; | |
1190 | break; | |
1191 | case CS8: | |
1192 | default: | |
1193 | newline.bDataBits = 8; | |
1194 | break; | |
1195 | } | |
6e47e069 | 1196 | /* FIXME: Needs to clear unsupported bits in the termios */ |
1da177e4 LT |
1197 | acm->clocal = ((termios->c_cflag & CLOCAL) != 0); |
1198 | ||
2a18a875 | 1199 | if (C_BAUD(tty) == B0) { |
1da177e4 LT |
1200 | newline.dwDTERate = acm->line.dwDTERate; |
1201 | newctrl &= ~ACM_CTRL_DTR; | |
2a18a875 | 1202 | } else if (termios_old && (termios_old->c_cflag & CBAUD) == B0) { |
6e47e069 | 1203 | newctrl |= ACM_CTRL_DTR; |
2a18a875 | 1204 | } |
1da177e4 LT |
1205 | |
1206 | if (newctrl != acm->ctrlout) | |
1207 | acm_set_control(acm, acm->ctrlout = newctrl); | |
1208 | ||
1209 | if (memcmp(&acm->line, &newline, sizeof newline)) { | |
1210 | memcpy(&acm->line, &newline, sizeof newline); | |
a5cc7ef9 JH |
1211 | dev_dbg(&acm->control->dev, "%s - set line: %d %d %d %d\n", |
1212 | __func__, | |
1213 | le32_to_cpu(newline.dwDTERate), | |
1da177e4 LT |
1214 | newline.bCharFormat, newline.bParityType, |
1215 | newline.bDataBits); | |
1216 | acm_set_line(acm, &acm->line); | |
1217 | } | |
1218 | } | |
1219 | ||
7fb57a01 HS |
1220 | static const struct tty_port_operations acm_port_ops = { |
1221 | .shutdown = acm_port_shutdown, | |
1222 | .activate = acm_port_activate, | |
1223 | .destruct = acm_port_destruct, | |
1224 | }; | |
1225 | ||
1da177e4 LT |
1226 | /* |
1227 | * USB probe and disconnect routines. | |
1228 | */ | |
1229 | ||
830f4021 | 1230 | /* Little helpers: write/read buffers free */ |
884b600f ON |
1231 | static void acm_write_buffers_free(struct acm *acm) |
1232 | { | |
1233 | int i; | |
1234 | struct acm_wb *wb; | |
a496c64f | 1235 | struct usb_device *usb_dev = interface_to_usbdev(acm->control); |
884b600f | 1236 | |
6e47e069 | 1237 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) |
997ea58e | 1238 | usb_free_coherent(usb_dev, acm->writesize, wb->buf, wb->dmah); |
884b600f ON |
1239 | } |
1240 | ||
830f4021 ON |
1241 | static void acm_read_buffers_free(struct acm *acm) |
1242 | { | |
1243 | struct usb_device *usb_dev = interface_to_usbdev(acm->control); | |
dab54c9f | 1244 | int i; |
830f4021 | 1245 | |
dab54c9f | 1246 | for (i = 0; i < acm->rx_buflimit; i++) |
997ea58e | 1247 | usb_free_coherent(usb_dev, acm->readsize, |
088c64f8 | 1248 | acm->read_buffers[i].base, acm->read_buffers[i].dma); |
830f4021 ON |
1249 | } |
1250 | ||
884b600f ON |
1251 | /* Little helper: write buffers allocate */ |
1252 | static int acm_write_buffers_alloc(struct acm *acm) | |
1253 | { | |
1254 | int i; | |
1255 | struct acm_wb *wb; | |
1256 | ||
86478944 | 1257 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { |
997ea58e | 1258 | wb->buf = usb_alloc_coherent(acm->dev, acm->writesize, GFP_KERNEL, |
884b600f ON |
1259 | &wb->dmah); |
1260 | if (!wb->buf) { | |
1261 | while (i != 0) { | |
1262 | --i; | |
1263 | --wb; | |
997ea58e | 1264 | usb_free_coherent(acm->dev, acm->writesize, |
884b600f ON |
1265 | wb->buf, wb->dmah); |
1266 | } | |
1267 | return -ENOMEM; | |
1268 | } | |
1269 | } | |
1270 | return 0; | |
1271 | } | |
1272 | ||
10077d4a AC |
1273 | static int acm_probe(struct usb_interface *intf, |
1274 | const struct usb_device_id *id) | |
1da177e4 LT |
1275 | { |
1276 | struct usb_cdc_union_desc *union_header = NULL; | |
c4cabd28 | 1277 | struct usb_cdc_country_functional_desc *cfd = NULL; |
c6dbf554 | 1278 | unsigned char *buffer = intf->altsetting->extra; |
1da177e4 LT |
1279 | int buflen = intf->altsetting->extralen; |
1280 | struct usb_interface *control_interface; | |
1281 | struct usb_interface *data_interface; | |
a2bfb4a3 ON |
1282 | struct usb_endpoint_descriptor *epctrl = NULL; |
1283 | struct usb_endpoint_descriptor *epread = NULL; | |
1284 | struct usb_endpoint_descriptor *epwrite = NULL; | |
1da177e4 LT |
1285 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
1286 | struct acm *acm; | |
1287 | int minor; | |
6e47e069 | 1288 | int ctrlsize, readsize; |
1da177e4 LT |
1289 | u8 *buf; |
1290 | u8 ac_management_function = 0; | |
1291 | u8 call_management_function = 0; | |
1292 | int call_interface_num = -1; | |
fd5054c1 | 1293 | int data_interface_num = -1; |
1da177e4 | 1294 | unsigned long quirks; |
86478944 | 1295 | int num_rx_buf; |
61a87adf | 1296 | int i; |
a2bfb4a3 | 1297 | int combined_interfaces = 0; |
c93d8195 AK |
1298 | struct device *tty_dev; |
1299 | int rv = -ENOMEM; | |
1da177e4 | 1300 | |
86478944 | 1301 | /* normal quirks */ |
1da177e4 | 1302 | quirks = (unsigned long)id->driver_info; |
16142655 DT |
1303 | |
1304 | if (quirks == IGNORE_DEVICE) | |
1305 | return -ENODEV; | |
1306 | ||
86478944 ON |
1307 | num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR; |
1308 | ||
1309 | /* handle quirks deadly to normal probing*/ | |
1da177e4 LT |
1310 | if (quirks == NO_UNION_NORMAL) { |
1311 | data_interface = usb_ifnum_to_if(usb_dev, 1); | |
1312 | control_interface = usb_ifnum_to_if(usb_dev, 0); | |
d5f08676 ON |
1313 | /* we would crash */ |
1314 | if (!data_interface || !control_interface) | |
1315 | return -ENODEV; | |
1da177e4 LT |
1316 | goto skip_normal_probe; |
1317 | } | |
6e47e069 | 1318 | |
1da177e4 LT |
1319 | /* normal probing*/ |
1320 | if (!buffer) { | |
9908a32e | 1321 | dev_err(&intf->dev, "Weird descriptor references\n"); |
1da177e4 LT |
1322 | return -EINVAL; |
1323 | } | |
1324 | ||
1325 | if (!buflen) { | |
577045c0 TG |
1326 | if (intf->cur_altsetting->endpoint && |
1327 | intf->cur_altsetting->endpoint->extralen && | |
6e47e069 AC |
1328 | intf->cur_altsetting->endpoint->extra) { |
1329 | dev_dbg(&intf->dev, | |
1330 | "Seeking extra descriptors on endpoint\n"); | |
1da177e4 LT |
1331 | buflen = intf->cur_altsetting->endpoint->extralen; |
1332 | buffer = intf->cur_altsetting->endpoint->extra; | |
1333 | } else { | |
9908a32e GKH |
1334 | dev_err(&intf->dev, |
1335 | "Zero length descriptor references\n"); | |
1da177e4 LT |
1336 | return -EINVAL; |
1337 | } | |
1338 | } | |
1339 | ||
1340 | while (buflen > 0) { | |
6e47e069 | 1341 | if (buffer[1] != USB_DT_CS_INTERFACE) { |
9908a32e | 1342 | dev_err(&intf->dev, "skipping garbage\n"); |
1da177e4 LT |
1343 | goto next_desc; |
1344 | } | |
1345 | ||
6e47e069 AC |
1346 | switch (buffer[2]) { |
1347 | case USB_CDC_UNION_TYPE: /* we've found it */ | |
1348 | if (union_header) { | |
1349 | dev_err(&intf->dev, "More than one " | |
1350 | "union descriptor, skipping ...\n"); | |
1351 | goto next_desc; | |
1da177e4 | 1352 | } |
6e47e069 AC |
1353 | union_header = (struct usb_cdc_union_desc *)buffer; |
1354 | break; | |
1355 | case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/ | |
1356 | cfd = (struct usb_cdc_country_functional_desc *)buffer; | |
1357 | break; | |
1358 | case USB_CDC_HEADER_TYPE: /* maybe check version */ | |
1359 | break; /* for now we ignore it */ | |
1360 | case USB_CDC_ACM_TYPE: | |
1361 | ac_management_function = buffer[3]; | |
1362 | break; | |
1363 | case USB_CDC_CALL_MANAGEMENT_TYPE: | |
1364 | call_management_function = buffer[3]; | |
1365 | call_interface_num = buffer[4]; | |
02f824ac | 1366 | if ((quirks & NOT_A_MODEM) == 0 && (call_management_function & 3) != 3) |
6e47e069 AC |
1367 | dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n"); |
1368 | break; | |
1369 | default: | |
1370 | /* there are LOTS more CDC descriptors that | |
1371 | * could legitimately be found here. | |
1372 | */ | |
1373 | dev_dbg(&intf->dev, "Ignoring descriptor: " | |
1374 | "type %02x, length %d\n", | |
1375 | buffer[2], buffer[0]); | |
1376 | break; | |
1377 | } | |
1da177e4 LT |
1378 | next_desc: |
1379 | buflen -= buffer[0]; | |
1380 | buffer += buffer[0]; | |
1381 | } | |
1382 | ||
1383 | if (!union_header) { | |
1384 | if (call_interface_num > 0) { | |
6e47e069 | 1385 | dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n"); |
fd5054c1 ES |
1386 | /* quirks for Droids MuIn LCD */ |
1387 | if (quirks & NO_DATA_INTERFACE) | |
1388 | data_interface = usb_ifnum_to_if(usb_dev, 0); | |
1389 | else | |
1390 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); | |
1da177e4 LT |
1391 | control_interface = intf; |
1392 | } else { | |
a2bfb4a3 ON |
1393 | if (intf->cur_altsetting->desc.bNumEndpoints != 3) { |
1394 | dev_dbg(&intf->dev,"No union descriptor, giving up\n"); | |
1395 | return -ENODEV; | |
1396 | } else { | |
1397 | dev_warn(&intf->dev,"No union descriptor, testing for castrated device\n"); | |
1398 | combined_interfaces = 1; | |
1399 | control_interface = data_interface = intf; | |
1400 | goto look_for_collapsed_interface; | |
1401 | } | |
1da177e4 LT |
1402 | } |
1403 | } else { | |
1404 | control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); | |
1405 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); | |
edefe206 GKH |
1406 | } |
1407 | ||
1408 | if (!control_interface || !data_interface) { | |
1409 | dev_dbg(&intf->dev, "no interfaces\n"); | |
1410 | return -ENODEV; | |
1da177e4 | 1411 | } |
6e47e069 | 1412 | |
1da177e4 | 1413 | if (data_interface_num != call_interface_num) |
6e47e069 | 1414 | dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n"); |
1da177e4 | 1415 | |
a2bfb4a3 ON |
1416 | if (control_interface == data_interface) { |
1417 | /* some broken devices designed for windows work this way */ | |
1418 | dev_warn(&intf->dev,"Control and data interfaces are not separated!\n"); | |
1419 | combined_interfaces = 1; | |
1420 | /* a popular other OS doesn't use it */ | |
1421 | quirks |= NO_CAP_LINE; | |
1422 | if (data_interface->cur_altsetting->desc.bNumEndpoints != 3) { | |
1423 | dev_err(&intf->dev, "This needs exactly 3 endpoints\n"); | |
1424 | return -EINVAL; | |
1425 | } | |
1426 | look_for_collapsed_interface: | |
1427 | for (i = 0; i < 3; i++) { | |
1428 | struct usb_endpoint_descriptor *ep; | |
1429 | ep = &data_interface->cur_altsetting->endpoint[i].desc; | |
1430 | ||
1431 | if (usb_endpoint_is_int_in(ep)) | |
1432 | epctrl = ep; | |
1433 | else if (usb_endpoint_is_bulk_out(ep)) | |
1434 | epwrite = ep; | |
1435 | else if (usb_endpoint_is_bulk_in(ep)) | |
1436 | epread = ep; | |
1437 | else | |
1438 | return -EINVAL; | |
1439 | } | |
1440 | if (!epctrl || !epread || !epwrite) | |
1441 | return -ENODEV; | |
1442 | else | |
1443 | goto made_compressed_probe; | |
1444 | } | |
1445 | ||
1da177e4 LT |
1446 | skip_normal_probe: |
1447 | ||
1448 | /*workaround for switched interfaces */ | |
6e47e069 AC |
1449 | if (data_interface->cur_altsetting->desc.bInterfaceClass |
1450 | != CDC_DATA_INTERFACE_TYPE) { | |
1451 | if (control_interface->cur_altsetting->desc.bInterfaceClass | |
1452 | == CDC_DATA_INTERFACE_TYPE) { | |
1da177e4 | 1453 | struct usb_interface *t; |
6e47e069 AC |
1454 | dev_dbg(&intf->dev, |
1455 | "Your device has switched interfaces.\n"); | |
1da177e4 LT |
1456 | t = control_interface; |
1457 | control_interface = data_interface; | |
1458 | data_interface = t; | |
1459 | } else { | |
1460 | return -EINVAL; | |
1461 | } | |
1462 | } | |
74da5d68 AS |
1463 | |
1464 | /* Accept probe requests only for the control interface */ | |
a2bfb4a3 | 1465 | if (!combined_interfaces && intf != control_interface) |
74da5d68 | 1466 | return -ENODEV; |
6e47e069 | 1467 | |
a2bfb4a3 ON |
1468 | if (!combined_interfaces && usb_interface_claimed(data_interface)) { |
1469 | /* valid in this context */ | |
6e47e069 | 1470 | dev_dbg(&intf->dev, "The data interface isn't available\n"); |
1da177e4 LT |
1471 | return -EBUSY; |
1472 | } | |
1473 | ||
1474 | ||
99f347ca SS |
1475 | if (data_interface->cur_altsetting->desc.bNumEndpoints < 2 || |
1476 | control_interface->cur_altsetting->desc.bNumEndpoints == 0) | |
1da177e4 LT |
1477 | return -EINVAL; |
1478 | ||
1479 | epctrl = &control_interface->cur_altsetting->endpoint[0].desc; | |
1480 | epread = &data_interface->cur_altsetting->endpoint[0].desc; | |
1481 | epwrite = &data_interface->cur_altsetting->endpoint[1].desc; | |
1482 | ||
1483 | ||
1484 | /* workaround for switched endpoints */ | |
45aea704 | 1485 | if (!usb_endpoint_dir_in(epread)) { |
1da177e4 LT |
1486 | /* descriptors are swapped */ |
1487 | struct usb_endpoint_descriptor *t; | |
6e47e069 AC |
1488 | dev_dbg(&intf->dev, |
1489 | "The data interface has switched endpoints\n"); | |
1da177e4 LT |
1490 | t = epread; |
1491 | epread = epwrite; | |
1492 | epwrite = t; | |
1493 | } | |
a2bfb4a3 | 1494 | made_compressed_probe: |
a5cc7ef9 | 1495 | dev_dbg(&intf->dev, "interfaces are valid\n"); |
1da177e4 | 1496 | |
6e47e069 AC |
1497 | acm = kzalloc(sizeof(struct acm), GFP_KERNEL); |
1498 | if (acm == NULL) { | |
255ab56c | 1499 | dev_err(&intf->dev, "out of memory (acm kzalloc)\n"); |
1da177e4 LT |
1500 | goto alloc_fail; |
1501 | } | |
1da177e4 | 1502 | |
7fb57a01 HS |
1503 | minor = acm_alloc_minor(acm); |
1504 | if (minor == ACM_TTY_MINORS) { | |
1505 | dev_err(&intf->dev, "no more free acm devices\n"); | |
1506 | kfree(acm); | |
1507 | return -ENODEV; | |
1508 | } | |
1509 | ||
29cc8897 KM |
1510 | ctrlsize = usb_endpoint_maxp(epctrl); |
1511 | readsize = usb_endpoint_maxp(epread) * | |
6e47e069 | 1512 | (quirks == SINGLE_RX_URB ? 1 : 2); |
a2bfb4a3 | 1513 | acm->combined_interfaces = combined_interfaces; |
6fa3eb70 S |
1514 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
1515 | acm->writesize = ACM_WB_SZ; | |
1516 | #else | |
29cc8897 | 1517 | acm->writesize = usb_endpoint_maxp(epwrite) * 20; |
6fa3eb70 | 1518 | #endif |
1da177e4 LT |
1519 | acm->control = control_interface; |
1520 | acm->data = data_interface; | |
1521 | acm->minor = minor; | |
1522 | acm->dev = usb_dev; | |
1523 | acm->ctrl_caps = ac_management_function; | |
a2bfb4a3 ON |
1524 | if (quirks & NO_CAP_LINE) |
1525 | acm->ctrl_caps &= ~USB_CDC_CAP_LINE; | |
1da177e4 LT |
1526 | acm->ctrlsize = ctrlsize; |
1527 | acm->readsize = readsize; | |
86478944 | 1528 | acm->rx_buflimit = num_rx_buf; |
c4028958 | 1529 | INIT_WORK(&acm->work, acm_softint); |
884b600f | 1530 | spin_lock_init(&acm->write_lock); |
61a87adf | 1531 | spin_lock_init(&acm->read_lock); |
1365baf7 | 1532 | mutex_init(&acm->mutex); |
cf7fdd57 ON |
1533 | acm->is_int_ep = usb_endpoint_xfer_int(epread); |
1534 | if (acm->is_int_ep) | |
1535 | acm->bInterval = epread->bInterval; | |
739e0285 AC |
1536 | tty_port_init(&acm->port); |
1537 | acm->port.ops = &acm_port_ops; | |
67e8477b | 1538 | init_usb_anchor(&acm->delayed); |
1da177e4 | 1539 | |
997ea58e | 1540 | buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); |
1da177e4 | 1541 | if (!buf) { |
255ab56c | 1542 | dev_err(&intf->dev, "out of memory (ctrl buffer alloc)\n"); |
1da177e4 LT |
1543 | goto alloc_fail2; |
1544 | } | |
1545 | acm->ctrl_buffer = buf; | |
1546 | ||
884b600f | 1547 | if (acm_write_buffers_alloc(acm) < 0) { |
255ab56c | 1548 | dev_err(&intf->dev, "out of memory (write buffer alloc)\n"); |
1da177e4 LT |
1549 | goto alloc_fail4; |
1550 | } | |
1da177e4 LT |
1551 | |
1552 | acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); | |
1553 | if (!acm->ctrlurb) { | |
255ab56c | 1554 | dev_err(&intf->dev, "out of memory (ctrlurb kmalloc)\n"); |
1da177e4 LT |
1555 | goto alloc_fail5; |
1556 | } | |
86478944 | 1557 | for (i = 0; i < num_rx_buf; i++) { |
088c64f8 JH |
1558 | struct acm_rb *rb = &(acm->read_buffers[i]); |
1559 | struct urb *urb; | |
61a87adf | 1560 | |
74f5e1ba JH |
1561 | rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL, |
1562 | &rb->dma); | |
1563 | if (!rb->base) { | |
1564 | dev_err(&intf->dev, "out of memory " | |
1565 | "(read bufs usb_alloc_coherent)\n"); | |
1566 | goto alloc_fail6; | |
1567 | } | |
088c64f8 JH |
1568 | rb->index = i; |
1569 | rb->instance = acm; | |
74f5e1ba | 1570 | |
088c64f8 JH |
1571 | urb = usb_alloc_urb(0, GFP_KERNEL); |
1572 | if (!urb) { | |
255ab56c | 1573 | dev_err(&intf->dev, |
6e47e069 | 1574 | "out of memory (read urbs usb_alloc_urb)\n"); |
c2572b78 | 1575 | goto alloc_fail6; |
61a87adf | 1576 | } |
088c64f8 JH |
1577 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1578 | urb->transfer_dma = rb->dma; | |
1579 | if (acm->is_int_ep) { | |
1580 | usb_fill_int_urb(urb, acm->dev, | |
d4898081 | 1581 | usb_rcvintpipe(usb_dev, epread->bEndpointAddress), |
088c64f8 JH |
1582 | rb->base, |
1583 | acm->readsize, | |
1584 | acm_read_bulk_callback, rb, | |
1585 | acm->bInterval); | |
1586 | } else { | |
1587 | usb_fill_bulk_urb(urb, acm->dev, | |
d4898081 | 1588 | usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress), |
088c64f8 JH |
1589 | rb->base, |
1590 | acm->readsize, | |
1591 | acm_read_bulk_callback, rb); | |
1592 | } | |
61a87adf | 1593 | |
088c64f8 JH |
1594 | acm->read_urbs[i] = urb; |
1595 | __set_bit(i, &acm->read_urbs_free); | |
61a87adf | 1596 | } |
6e47e069 | 1597 | for (i = 0; i < ACM_NW; i++) { |
e4cf3aa8 DE |
1598 | struct acm_wb *snd = &(acm->wb[i]); |
1599 | ||
6e47e069 AC |
1600 | snd->urb = usb_alloc_urb(0, GFP_KERNEL); |
1601 | if (snd->urb == NULL) { | |
255ab56c | 1602 | dev_err(&intf->dev, |
59d7fec7 | 1603 | "out of memory (write urbs usb_alloc_urb)\n"); |
74f5e1ba | 1604 | goto alloc_fail7; |
e4cf3aa8 DE |
1605 | } |
1606 | ||
5186ffee AL |
1607 | if (usb_endpoint_xfer_int(epwrite)) |
1608 | usb_fill_int_urb(snd->urb, usb_dev, | |
c5211187 | 1609 | usb_sndintpipe(usb_dev, epwrite->bEndpointAddress), |
5186ffee AL |
1610 | NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval); |
1611 | else | |
1612 | usb_fill_bulk_urb(snd->urb, usb_dev, | |
1613 | usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), | |
1614 | NULL, acm->writesize, acm_write_bulk, snd); | |
e4cf3aa8 DE |
1615 | snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1616 | snd->instance = acm; | |
1da177e4 LT |
1617 | } |
1618 | ||
6e47e069 | 1619 | usb_set_intfdata(intf, acm); |
c4cabd28 ON |
1620 | |
1621 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); | |
1622 | if (i < 0) | |
74f5e1ba | 1623 | goto alloc_fail7; |
c4cabd28 ON |
1624 | |
1625 | if (cfd) { /* export the country data */ | |
1626 | acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL); | |
1627 | if (!acm->country_codes) | |
1628 | goto skip_countries; | |
1629 | acm->country_code_size = cfd->bLength - 4; | |
6e47e069 AC |
1630 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, |
1631 | cfd->bLength - 4); | |
c4cabd28 ON |
1632 | acm->country_rel_date = cfd->iCountryCodeRelDate; |
1633 | ||
1634 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); | |
1635 | if (i < 0) { | |
1636 | kfree(acm->country_codes); | |
e7c8e860 JL |
1637 | acm->country_codes = NULL; |
1638 | acm->country_code_size = 0; | |
c4cabd28 ON |
1639 | goto skip_countries; |
1640 | } | |
1641 | ||
6e47e069 AC |
1642 | i = device_create_file(&intf->dev, |
1643 | &dev_attr_iCountryCodeRelDate); | |
c4cabd28 | 1644 | if (i < 0) { |
c2572b78 | 1645 | device_remove_file(&intf->dev, &dev_attr_wCountryCodes); |
c4cabd28 | 1646 | kfree(acm->country_codes); |
e7c8e860 JL |
1647 | acm->country_codes = NULL; |
1648 | acm->country_code_size = 0; | |
c4cabd28 ON |
1649 | goto skip_countries; |
1650 | } | |
1651 | } | |
1652 | ||
1653 | skip_countries: | |
6e47e069 | 1654 | usb_fill_int_urb(acm->ctrlurb, usb_dev, |
a2bfb4a3 ON |
1655 | usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), |
1656 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, | |
1657 | /* works around buggy devices */ | |
1658 | epctrl->bInterval ? epctrl->bInterval : 0xff); | |
1da177e4 LT |
1659 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1660 | acm->ctrlurb->transfer_dma = acm->ctrl_dma; | |
1661 | ||
1da177e4 LT |
1662 | dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); |
1663 | ||
1664 | acm_set_control(acm, acm->ctrlout); | |
1665 | ||
1666 | acm->line.dwDTERate = cpu_to_le32(9600); | |
1667 | acm->line.bDataBits = 8; | |
1668 | acm_set_line(acm, &acm->line); | |
1669 | ||
1670 | usb_driver_claim_interface(&acm_driver, data_interface, acm); | |
672c4e18 | 1671 | usb_set_intfdata(data_interface, acm); |
1da177e4 | 1672 | |
83ef344a | 1673 | usb_get_intf(control_interface); |
c93d8195 | 1674 | tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor, |
734cc178 | 1675 | &control_interface->dev); |
c93d8195 AK |
1676 | if (IS_ERR(tty_dev)) { |
1677 | rv = PTR_ERR(tty_dev); | |
1678 | goto alloc_fail8; | |
1679 | } | |
1da177e4 | 1680 | |
c4cabd28 | 1681 | return 0; |
c93d8195 AK |
1682 | alloc_fail8: |
1683 | if (acm->country_codes) { | |
1684 | device_remove_file(&acm->control->dev, | |
1685 | &dev_attr_wCountryCodes); | |
1686 | device_remove_file(&acm->control->dev, | |
1687 | &dev_attr_iCountryCodeRelDate); | |
b16c4055 | 1688 | kfree(acm->country_codes); |
c93d8195 AK |
1689 | } |
1690 | device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); | |
74f5e1ba | 1691 | alloc_fail7: |
c93d8195 | 1692 | usb_set_intfdata(intf, NULL); |
e4cf3aa8 DE |
1693 | for (i = 0; i < ACM_NW; i++) |
1694 | usb_free_urb(acm->wb[i].urb); | |
c2572b78 | 1695 | alloc_fail6: |
86478944 | 1696 | for (i = 0; i < num_rx_buf; i++) |
088c64f8 | 1697 | usb_free_urb(acm->read_urbs[i]); |
74f5e1ba | 1698 | acm_read_buffers_free(acm); |
1da177e4 LT |
1699 | usb_free_urb(acm->ctrlurb); |
1700 | alloc_fail5: | |
884b600f | 1701 | acm_write_buffers_free(acm); |
1da177e4 | 1702 | alloc_fail4: |
997ea58e | 1703 | usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); |
1da177e4 | 1704 | alloc_fail2: |
7fb57a01 | 1705 | acm_release_minor(acm); |
1da177e4 LT |
1706 | kfree(acm); |
1707 | alloc_fail: | |
c93d8195 | 1708 | return rv; |
1da177e4 LT |
1709 | } |
1710 | ||
1365baf7 ON |
1711 | static void stop_data_traffic(struct acm *acm) |
1712 | { | |
1713 | int i; | |
a5cc7ef9 JH |
1714 | |
1715 | dev_dbg(&acm->control->dev, "%s\n", __func__); | |
1365baf7 | 1716 | |
1365baf7 | 1717 | usb_kill_urb(acm->ctrlurb); |
6e47e069 | 1718 | for (i = 0; i < ACM_NW; i++) |
e4cf3aa8 | 1719 | usb_kill_urb(acm->wb[i].urb); |
1365baf7 | 1720 | for (i = 0; i < acm->rx_buflimit; i++) |
088c64f8 | 1721 | usb_kill_urb(acm->read_urbs[i]); |
1365baf7 ON |
1722 | |
1723 | cancel_work_sync(&acm->work); | |
1724 | } | |
1725 | ||
1da177e4 LT |
1726 | static void acm_disconnect(struct usb_interface *intf) |
1727 | { | |
c4cabd28 | 1728 | struct acm *acm = usb_get_intfdata(intf); |
1da177e4 | 1729 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
10077d4a | 1730 | struct tty_struct *tty; |
7fb57a01 HS |
1731 | int i; |
1732 | ||
1733 | dev_dbg(&intf->dev, "%s\n", __func__); | |
1da177e4 | 1734 | |
672c4e18 DB |
1735 | /* sibling interface is already cleaning up */ |
1736 | if (!acm) | |
86067eea | 1737 | return; |
672c4e18 | 1738 | |
7fb57a01 HS |
1739 | mutex_lock(&acm->mutex); |
1740 | acm->disconnected = true; | |
6e47e069 | 1741 | if (acm->country_codes) { |
74da5d68 AS |
1742 | device_remove_file(&acm->control->dev, |
1743 | &dev_attr_wCountryCodes); | |
1744 | device_remove_file(&acm->control->dev, | |
1745 | &dev_attr_iCountryCodeRelDate); | |
c4cabd28 | 1746 | } |
74da5d68 | 1747 | device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); |
86067eea ON |
1748 | usb_set_intfdata(acm->control, NULL); |
1749 | usb_set_intfdata(acm->data, NULL); | |
7fb57a01 HS |
1750 | mutex_unlock(&acm->mutex); |
1751 | ||
1752 | tty = tty_port_tty_get(&acm->port); | |
1753 | if (tty) { | |
1754 | tty_vhangup(tty); | |
1755 | tty_kref_put(tty); | |
1756 | } | |
1da177e4 | 1757 | |
1365baf7 | 1758 | stop_data_traffic(acm); |
1da177e4 | 1759 | |
cb25505f JH |
1760 | tty_unregister_device(acm_tty_driver, acm->minor); |
1761 | ||
7fb57a01 HS |
1762 | usb_free_urb(acm->ctrlurb); |
1763 | for (i = 0; i < ACM_NW; i++) | |
1764 | usb_free_urb(acm->wb[i].urb); | |
1765 | for (i = 0; i < acm->rx_buflimit; i++) | |
1766 | usb_free_urb(acm->read_urbs[i]); | |
884b600f | 1767 | acm_write_buffers_free(acm); |
7fb57a01 | 1768 | usb_free_coherent(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); |
830f4021 | 1769 | acm_read_buffers_free(acm); |
1da177e4 | 1770 | |
a2bfb4a3 ON |
1771 | if (!acm->combined_interfaces) |
1772 | usb_driver_release_interface(&acm_driver, intf == acm->control ? | |
830f4021 | 1773 | acm->data : acm->control); |
1da177e4 | 1774 | |
7fb57a01 | 1775 | tty_port_put(&acm->port); |
1da177e4 LT |
1776 | } |
1777 | ||
35758589 | 1778 | #ifdef CONFIG_PM |
1365baf7 ON |
1779 | static int acm_suspend(struct usb_interface *intf, pm_message_t message) |
1780 | { | |
1781 | struct acm *acm = usb_get_intfdata(intf); | |
11ea859d ON |
1782 | int cnt; |
1783 | ||
6fa3eb70 | 1784 | dbg_mtk(&acm->control->dev, "%s intf=%d", __func__, intf->cur_altsetting->desc.bInterfaceNumber); |
c5ece482 JH |
1785 | spin_lock_irq(&acm->read_lock); |
1786 | spin_lock(&acm->write_lock); | |
5b1b0b81 | 1787 | if (PMSG_IS_AUTO(message)) { |
c5ece482 JH |
1788 | if (acm->transmitting) { |
1789 | spin_unlock(&acm->write_lock); | |
1790 | spin_unlock_irq(&acm->read_lock); | |
11ea859d | 1791 | return -EBUSY; |
c5ece482 | 1792 | } |
6fa3eb70 S |
1793 | }else{ |
1794 | int i; | |
1795 | for (i = 0; i < ACM_NW; i++){ | |
1796 | if(acm->wb[i].use){ | |
1797 | spin_unlock(&acm->write_lock); | |
1798 | spin_unlock_irq(&acm->read_lock); | |
1799 | return -EBUSY; | |
1800 | } | |
1801 | } | |
11ea859d | 1802 | } |
6fa3eb70 | 1803 | |
11ea859d ON |
1804 | cnt = acm->susp_count++; |
1805 | spin_unlock(&acm->write_lock); | |
1806 | spin_unlock_irq(&acm->read_lock); | |
1365baf7 | 1807 | |
11ea859d | 1808 | if (cnt) |
1365baf7 | 1809 | return 0; |
1365baf7 | 1810 | |
52c84b33 | 1811 | stop_data_traffic(acm); |
1365baf7 | 1812 | |
1365baf7 ON |
1813 | return 0; |
1814 | } | |
1815 | ||
1816 | static int acm_resume(struct usb_interface *intf) | |
1817 | { | |
1818 | struct acm *acm = usb_get_intfdata(intf); | |
67e8477b | 1819 | struct urb *urb; |
1365baf7 ON |
1820 | int rv = 0; |
1821 | ||
6fa3eb70 S |
1822 | dbg_mtk(&acm->control->dev, "%s intf=%d", __func__, intf->cur_altsetting->desc.bInterfaceNumber); |
1823 | ||
11ea859d | 1824 | spin_lock_irq(&acm->read_lock); |
1b3fe006 | 1825 | spin_lock(&acm->write_lock); |
11ea859d | 1826 | |
1b3fe006 JH |
1827 | if (--acm->susp_count) |
1828 | goto out; | |
1365baf7 | 1829 | |
7fb57a01 | 1830 | if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) { |
1b3fe006 | 1831 | rv = usb_submit_urb(acm->ctrlurb, GFP_ATOMIC); |
97d35f95 | 1832 | |
67e8477b JH |
1833 | for (;;) { |
1834 | urb = usb_get_from_anchor(&acm->delayed); | |
1835 | if (!urb) | |
1836 | break; | |
1837 | ||
1838 | acm_start_wb(acm, urb->context); | |
97d35f95 ON |
1839 | } |
1840 | ||
1841 | /* | |
1842 | * delayed error checking because we must | |
1843 | * do the write path at all cost | |
1844 | */ | |
6fa3eb70 S |
1845 | if (rv < 0){ |
1846 | MYDBG("urb fail:%d\n", rv); | |
1b3fe006 | 1847 | goto out; |
6fa3eb70 | 1848 | } |
1365baf7 | 1849 | |
1b3fe006 | 1850 | rv = acm_submit_read_urbs(acm, GFP_ATOMIC); |
1365baf7 | 1851 | } |
1b3fe006 JH |
1852 | out: |
1853 | spin_unlock(&acm->write_lock); | |
1854 | spin_unlock_irq(&acm->read_lock); | |
1365baf7 | 1855 | |
1365baf7 ON |
1856 | return rv; |
1857 | } | |
35758589 | 1858 | |
a91b0c50 FL |
1859 | static int acm_reset_resume(struct usb_interface *intf) |
1860 | { | |
1861 | struct acm *acm = usb_get_intfdata(intf); | |
a91b0c50 | 1862 | |
aa27a094 JS |
1863 | if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) |
1864 | tty_port_tty_hangup(&acm->port, false); | |
7fb57a01 | 1865 | |
a91b0c50 FL |
1866 | return acm_resume(intf); |
1867 | } | |
1868 | ||
35758589 | 1869 | #endif /* CONFIG_PM */ |
c1479a92 AT |
1870 | |
1871 | #define NOKIA_PCSUITE_ACM_INFO(x) \ | |
1872 | USB_DEVICE_AND_INTERFACE_INFO(0x0421, x, \ | |
1873 | USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \ | |
1874 | USB_CDC_ACM_PROTO_VENDOR) | |
1875 | ||
4035e456 TG |
1876 | #define SAMSUNG_PCSUITE_ACM_INFO(x) \ |
1877 | USB_DEVICE_AND_INTERFACE_INFO(0x04e7, x, \ | |
1878 | USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \ | |
1879 | USB_CDC_ACM_PROTO_VENDOR) | |
1880 | ||
1da177e4 LT |
1881 | /* |
1882 | * USB driver structure. | |
1883 | */ | |
1884 | ||
6ef4852b | 1885 | static const struct usb_device_id acm_ids[] = { |
1da177e4 | 1886 | /* quirky and broken devices */ |
522a78be DC |
1887 | { USB_DEVICE(0x17ef, 0x7000), /* Lenovo USB modem */ |
1888 | .driver_info = NO_UNION_NORMAL, },/* has no union descriptor */ | |
1da177e4 LT |
1889 | { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */ |
1890 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1891 | }, | |
b0e2a705 AA |
1892 | { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */ |
1893 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1894 | }, | |
0f9c7b4a AL |
1895 | { USB_DEVICE(0x0e8d, 0x3329), /* MediaTek Inc GPS */ |
1896 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1897 | }, | |
8753e65e MO |
1898 | { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */ |
1899 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1900 | }, | |
91a9c921 CM |
1901 | { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */ |
1902 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1903 | }, | |
7abcf20b AC |
1904 | { USB_DEVICE(0x0ace, 0x1602), /* ZyDAS 56K USB MODEM */ |
1905 | .driver_info = SINGLE_RX_URB, | |
1906 | }, | |
86478944 ON |
1907 | { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */ |
1908 | .driver_info = SINGLE_RX_URB, /* firmware bug */ | |
1909 | }, | |
3dd2ae81 ON |
1910 | { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */ |
1911 | .driver_info = SINGLE_RX_URB, /* firmware bug */ | |
1912 | }, | |
9be8456c ON |
1913 | { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */ |
1914 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1915 | }, | |
6149ed5e IM |
1916 | { USB_DEVICE(0x0803, 0x3095), /* Zoom Telephonics Model 3095F USB MODEM */ |
1917 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1918 | }, | |
c8fd2c37 ES |
1919 | { USB_DEVICE(0x0572, 0x1321), /* Conexant USB MODEM CX93010 */ |
1920 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1921 | }, | |
c89c60e9 AC |
1922 | { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */ |
1923 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1924 | }, | |
cab98a0a XK |
1925 | { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */ |
1926 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1927 | }, | |
1e2dedaa | 1928 | { USB_DEVICE(0x2184, 0x001c) }, /* GW Instek AFG-2225 */ |
155df65a DT |
1929 | { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */ |
1930 | }, | |
6abff5dc KH |
1931 | /* Motorola H24 HSPA module: */ |
1932 | { USB_DEVICE(0x22b8, 0x2d91) }, /* modem */ | |
ed37e0cb MU |
1933 | { USB_DEVICE(0x22b8, 0x2d92), /* modem + diagnostics */ |
1934 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1935 | }, | |
1936 | { USB_DEVICE(0x22b8, 0x2d93), /* modem + AT port */ | |
1937 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1938 | }, | |
1939 | { USB_DEVICE(0x22b8, 0x2d95), /* modem + AT port + diagnostics */ | |
1940 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1941 | }, | |
1942 | { USB_DEVICE(0x22b8, 0x2d96), /* modem + NMEA */ | |
1943 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1944 | }, | |
1945 | { USB_DEVICE(0x22b8, 0x2d97), /* modem + diagnostics + NMEA */ | |
1946 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1947 | }, | |
1948 | { USB_DEVICE(0x22b8, 0x2d99), /* modem + AT port + NMEA */ | |
1949 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1950 | }, | |
1951 | { USB_DEVICE(0x22b8, 0x2d9a), /* modem + AT port + diagnostics + NMEA */ | |
1952 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1953 | }, | |
6abff5dc | 1954 | |
c332b4e1 AR |
1955 | { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */ |
1956 | .driver_info = NO_UNION_NORMAL, /* union descriptor misplaced on | |
1957 | data interface instead of | |
1958 | communications interface. | |
1959 | Maybe we should define a new | |
1960 | quirk for this. */ | |
1961 | }, | |
e7d491a1 JCR |
1962 | { USB_DEVICE(0x0572, 0x1340), /* Conexant CX93010-2x UCMxx */ |
1963 | .driver_info = NO_UNION_NORMAL, | |
1964 | }, | |
036915a7 DL |
1965 | { USB_DEVICE(0x05f9, 0x4002), /* PSC Scanning, Magellan 800i */ |
1966 | .driver_info = NO_UNION_NORMAL, | |
1967 | }, | |
1f17c502 KK |
1968 | { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */ |
1969 | .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */ | |
1970 | }, | |
c3baa19b RN |
1971 | { USB_DEVICE(0x1576, 0x03b1), /* Maretron USB100 */ |
1972 | .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */ | |
1973 | }, | |
9be8456c | 1974 | |
c1479a92 AT |
1975 | /* Nokia S60 phones expose two ACM channels. The first is |
1976 | * a modem and is picked up by the standard AT-command | |
1977 | * information below. The second is 'vendor-specific' but | |
1978 | * is treated as a serial device at the S60 end, so we want | |
1979 | * to expose it on Linux too. */ | |
1980 | { NOKIA_PCSUITE_ACM_INFO(0x042D), }, /* Nokia 3250 */ | |
1981 | { NOKIA_PCSUITE_ACM_INFO(0x04D8), }, /* Nokia 5500 Sport */ | |
1982 | { NOKIA_PCSUITE_ACM_INFO(0x04C9), }, /* Nokia E50 */ | |
1983 | { NOKIA_PCSUITE_ACM_INFO(0x0419), }, /* Nokia E60 */ | |
1984 | { NOKIA_PCSUITE_ACM_INFO(0x044D), }, /* Nokia E61 */ | |
1985 | { NOKIA_PCSUITE_ACM_INFO(0x0001), }, /* Nokia E61i */ | |
1986 | { NOKIA_PCSUITE_ACM_INFO(0x0475), }, /* Nokia E62 */ | |
1987 | { NOKIA_PCSUITE_ACM_INFO(0x0508), }, /* Nokia E65 */ | |
1988 | { NOKIA_PCSUITE_ACM_INFO(0x0418), }, /* Nokia E70 */ | |
1989 | { NOKIA_PCSUITE_ACM_INFO(0x0425), }, /* Nokia N71 */ | |
1990 | { NOKIA_PCSUITE_ACM_INFO(0x0486), }, /* Nokia N73 */ | |
1991 | { NOKIA_PCSUITE_ACM_INFO(0x04DF), }, /* Nokia N75 */ | |
1992 | { NOKIA_PCSUITE_ACM_INFO(0x000e), }, /* Nokia N77 */ | |
1993 | { NOKIA_PCSUITE_ACM_INFO(0x0445), }, /* Nokia N80 */ | |
1994 | { NOKIA_PCSUITE_ACM_INFO(0x042F), }, /* Nokia N91 & N91 8GB */ | |
1995 | { NOKIA_PCSUITE_ACM_INFO(0x048E), }, /* Nokia N92 */ | |
1996 | { NOKIA_PCSUITE_ACM_INFO(0x0420), }, /* Nokia N93 */ | |
1997 | { NOKIA_PCSUITE_ACM_INFO(0x04E6), }, /* Nokia N93i */ | |
1998 | { NOKIA_PCSUITE_ACM_INFO(0x04B2), }, /* Nokia 5700 XpressMusic */ | |
1999 | { NOKIA_PCSUITE_ACM_INFO(0x0134), }, /* Nokia 6110 Navigator (China) */ | |
2000 | { NOKIA_PCSUITE_ACM_INFO(0x046E), }, /* Nokia 6110 Navigator */ | |
2001 | { NOKIA_PCSUITE_ACM_INFO(0x002f), }, /* Nokia 6120 classic & */ | |
2002 | { NOKIA_PCSUITE_ACM_INFO(0x0088), }, /* Nokia 6121 classic */ | |
2003 | { NOKIA_PCSUITE_ACM_INFO(0x00fc), }, /* Nokia 6124 classic */ | |
2004 | { NOKIA_PCSUITE_ACM_INFO(0x0042), }, /* Nokia E51 */ | |
2005 | { NOKIA_PCSUITE_ACM_INFO(0x00b0), }, /* Nokia E66 */ | |
2006 | { NOKIA_PCSUITE_ACM_INFO(0x00ab), }, /* Nokia E71 */ | |
2007 | { NOKIA_PCSUITE_ACM_INFO(0x0481), }, /* Nokia N76 */ | |
2008 | { NOKIA_PCSUITE_ACM_INFO(0x0007), }, /* Nokia N81 & N81 8GB */ | |
2009 | { NOKIA_PCSUITE_ACM_INFO(0x0071), }, /* Nokia N82 */ | |
2010 | { NOKIA_PCSUITE_ACM_INFO(0x04F0), }, /* Nokia N95 & N95-3 NAM */ | |
2011 | { NOKIA_PCSUITE_ACM_INFO(0x0070), }, /* Nokia N95 8GB */ | |
2012 | { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */ | |
2013 | { NOKIA_PCSUITE_ACM_INFO(0x0099), }, /* Nokia 6210 Navigator, RM-367 */ | |
2014 | { NOKIA_PCSUITE_ACM_INFO(0x0128), }, /* Nokia 6210 Navigator, RM-419 */ | |
2015 | { NOKIA_PCSUITE_ACM_INFO(0x008f), }, /* Nokia 6220 Classic */ | |
2016 | { NOKIA_PCSUITE_ACM_INFO(0x00a0), }, /* Nokia 6650 */ | |
2017 | { NOKIA_PCSUITE_ACM_INFO(0x007b), }, /* Nokia N78 */ | |
2018 | { NOKIA_PCSUITE_ACM_INFO(0x0094), }, /* Nokia N85 */ | |
2019 | { NOKIA_PCSUITE_ACM_INFO(0x003a), }, /* Nokia N96 & N96-3 */ | |
2020 | { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */ | |
2021 | { NOKIA_PCSUITE_ACM_INFO(0x0108), }, /* Nokia 5320 XpressMusic 2G */ | |
2022 | { NOKIA_PCSUITE_ACM_INFO(0x01f5), }, /* Nokia N97, RM-505 */ | |
83a4eae9 | 2023 | { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */ |
4035e456 TG |
2024 | { NOKIA_PCSUITE_ACM_INFO(0x0178), }, /* Nokia E63 */ |
2025 | { NOKIA_PCSUITE_ACM_INFO(0x010e), }, /* Nokia E75 */ | |
2026 | { NOKIA_PCSUITE_ACM_INFO(0x02d9), }, /* Nokia 6760 Slide */ | |
2027 | { NOKIA_PCSUITE_ACM_INFO(0x01d0), }, /* Nokia E52 */ | |
2028 | { NOKIA_PCSUITE_ACM_INFO(0x0223), }, /* Nokia E72 */ | |
2029 | { NOKIA_PCSUITE_ACM_INFO(0x0275), }, /* Nokia X6 */ | |
2030 | { NOKIA_PCSUITE_ACM_INFO(0x026c), }, /* Nokia N97 Mini */ | |
2031 | { NOKIA_PCSUITE_ACM_INFO(0x0154), }, /* Nokia 5800 XpressMusic */ | |
2032 | { NOKIA_PCSUITE_ACM_INFO(0x04ce), }, /* Nokia E90 */ | |
2033 | { NOKIA_PCSUITE_ACM_INFO(0x01d4), }, /* Nokia E55 */ | |
721d92fc | 2034 | { NOKIA_PCSUITE_ACM_INFO(0x0302), }, /* Nokia N8 */ |
4061fde2 TG |
2035 | { NOKIA_PCSUITE_ACM_INFO(0x0335), }, /* Nokia E7 */ |
2036 | { NOKIA_PCSUITE_ACM_INFO(0x03cd), }, /* Nokia C7 */ | |
4035e456 | 2037 | { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */ |
c1479a92 | 2038 | |
65e52f41 DP |
2039 | /* Support for Owen devices */ |
2040 | { USB_DEVICE(0x03eb, 0x0030), }, /* Owen SI30 */ | |
2041 | ||
c1479a92 AT |
2042 | /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */ |
2043 | ||
7c5d8c39 | 2044 | /* Support Lego NXT using pbLua firmware */ |
ce126644 JC |
2045 | { USB_DEVICE(0x0694, 0xff00), |
2046 | .driver_info = NOT_A_MODEM, | |
7893afc0 | 2047 | }, |
7c5d8c39 | 2048 | |
fd5054c1 ES |
2049 | /* Support for Droids MuIn LCD */ |
2050 | { USB_DEVICE(0x04d8, 0x000b), | |
2051 | .driver_info = NO_DATA_INTERFACE, | |
2052 | }, | |
2053 | ||
16142655 DT |
2054 | #if IS_ENABLED(CONFIG_INPUT_IMS_PCU) |
2055 | { USB_DEVICE(0x04d8, 0x0082), /* Application mode */ | |
2056 | .driver_info = IGNORE_DEVICE, | |
2057 | }, | |
2058 | { USB_DEVICE(0x04d8, 0x0083), /* Bootloader mode */ | |
2059 | .driver_info = IGNORE_DEVICE, | |
2060 | }, | |
2061 | #endif | |
2062 | ||
eb80decb ON |
2063 | /*Samsung phone in firmware update mode */ |
2064 | { USB_DEVICE(0x04e8, 0x685d), | |
2065 | .driver_info = IGNORE_DEVICE, | |
2066 | }, | |
2067 | ||
7f877278 JJ |
2068 | /* Exclude Infineon Flash Loader utility */ |
2069 | { USB_DEVICE(0x058b, 0x0041), | |
2070 | .driver_info = IGNORE_DEVICE, | |
2071 | }, | |
2072 | ||
5b239f0a PC |
2073 | /* control interfaces without any protocol set */ |
2074 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | |
2075 | USB_CDC_PROTO_NONE) }, | |
2076 | ||
1da177e4 LT |
2077 | /* control interfaces with various AT-command sets */ |
2078 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | |
2079 | USB_CDC_ACM_PROTO_AT_V25TER) }, | |
2080 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | |
2081 | USB_CDC_ACM_PROTO_AT_PCCA101) }, | |
2082 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | |
2083 | USB_CDC_ACM_PROTO_AT_PCCA101_WAKE) }, | |
2084 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | |
2085 | USB_CDC_ACM_PROTO_AT_GSM) }, | |
2086 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | |
6e47e069 | 2087 | USB_CDC_ACM_PROTO_AT_3G) }, |
1da177e4 LT |
2088 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
2089 | USB_CDC_ACM_PROTO_AT_CDMA) }, | |
2090 | ||
1da177e4 LT |
2091 | { } |
2092 | }; | |
2093 | ||
6e47e069 | 2094 | MODULE_DEVICE_TABLE(usb, acm_ids); |
1da177e4 LT |
2095 | |
2096 | static struct usb_driver acm_driver = { | |
1da177e4 LT |
2097 | .name = "cdc_acm", |
2098 | .probe = acm_probe, | |
2099 | .disconnect = acm_disconnect, | |
35758589 | 2100 | #ifdef CONFIG_PM |
1365baf7 ON |
2101 | .suspend = acm_suspend, |
2102 | .resume = acm_resume, | |
a91b0c50 | 2103 | .reset_resume = acm_reset_resume, |
35758589 | 2104 | #endif |
1da177e4 | 2105 | .id_table = acm_ids, |
35758589 | 2106 | #ifdef CONFIG_PM |
1365baf7 | 2107 | .supports_autosuspend = 1, |
35758589 | 2108 | #endif |
e1f12eb6 | 2109 | .disable_hub_initiated_lpm = 1, |
1da177e4 LT |
2110 | }; |
2111 | ||
2112 | /* | |
2113 | * TTY driver structures. | |
2114 | */ | |
2115 | ||
b68e31d0 | 2116 | static const struct tty_operations acm_ops = { |
7fb57a01 | 2117 | .install = acm_tty_install, |
1da177e4 LT |
2118 | .open = acm_tty_open, |
2119 | .close = acm_tty_close, | |
7fb57a01 | 2120 | .cleanup = acm_tty_cleanup, |
10077d4a | 2121 | .hangup = acm_tty_hangup, |
1da177e4 LT |
2122 | .write = acm_tty_write, |
2123 | .write_room = acm_tty_write_room, | |
2124 | .ioctl = acm_tty_ioctl, | |
2125 | .throttle = acm_tty_throttle, | |
2126 | .unthrottle = acm_tty_unthrottle, | |
2127 | .chars_in_buffer = acm_tty_chars_in_buffer, | |
2128 | .break_ctl = acm_tty_break_ctl, | |
2129 | .set_termios = acm_tty_set_termios, | |
2130 | .tiocmget = acm_tty_tiocmget, | |
2131 | .tiocmset = acm_tty_tiocmset, | |
2132 | }; | |
2133 | ||
2134 | /* | |
2135 | * Init / exit. | |
2136 | */ | |
2137 | ||
2138 | static int __init acm_init(void) | |
2139 | { | |
2140 | int retval; | |
6fa3eb70 S |
2141 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
2142 | int i; | |
2143 | #endif | |
1da177e4 LT |
2144 | acm_tty_driver = alloc_tty_driver(ACM_TTY_MINORS); |
2145 | if (!acm_tty_driver) | |
2146 | return -ENOMEM; | |
1da177e4 LT |
2147 | acm_tty_driver->driver_name = "acm", |
2148 | acm_tty_driver->name = "ttyACM", | |
1da177e4 LT |
2149 | acm_tty_driver->major = ACM_TTY_MAJOR, |
2150 | acm_tty_driver->minor_start = 0, | |
2151 | acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL, | |
2152 | acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, | |
331b8319 | 2153 | acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
1da177e4 | 2154 | acm_tty_driver->init_termios = tty_std_termios; |
6e47e069 AC |
2155 | acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | |
2156 | HUPCL | CLOCAL; | |
6fa3eb70 S |
2157 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
2158 | /* wx, disable echo and other flags in the very beginning. | |
2159 | * otherwise RILD will disable them via calling tcsetattr() after it opened tty port, | |
2160 | * so there may be a gap between port opening and calling tcsetattr(). If modem send data | |
2161 | * at that time, things goes ugly. | |
2162 | */ | |
2163 | acm_tty_driver->init_termios.c_iflag = 0; | |
2164 | acm_tty_driver->init_termios.c_oflag = 0; | |
2165 | acm_tty_driver->init_termios.c_lflag = 0; | |
2166 | for(i= 0; i < CB_NUM ; i++){ | |
2167 | callback_check_timeout[i] = jiffies; | |
2168 | } | |
2169 | #endif | |
1da177e4 LT |
2170 | tty_set_operations(acm_tty_driver, &acm_ops); |
2171 | ||
2172 | retval = tty_register_driver(acm_tty_driver); | |
2173 | if (retval) { | |
2174 | put_tty_driver(acm_tty_driver); | |
2175 | return retval; | |
2176 | } | |
2177 | ||
2178 | retval = usb_register(&acm_driver); | |
2179 | if (retval) { | |
2180 | tty_unregister_driver(acm_tty_driver); | |
2181 | put_tty_driver(acm_tty_driver); | |
2182 | return retval; | |
2183 | } | |
2184 | ||
a2c7b935 | 2185 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n"); |
1da177e4 LT |
2186 | |
2187 | return 0; | |
2188 | } | |
2189 | ||
2190 | static void __exit acm_exit(void) | |
2191 | { | |
2192 | usb_deregister(&acm_driver); | |
2193 | tty_unregister_driver(acm_tty_driver); | |
2194 | put_tty_driver(acm_tty_driver); | |
2195 | } | |
2196 | ||
2197 | module_init(acm_init); | |
2198 | module_exit(acm_exit); | |
6fa3eb70 S |
2199 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
2200 | module_param(enable_debug, int, 0644); | |
2201 | module_param(enable_dump, int, 0644); | |
2202 | #endif | |
1da177e4 | 2203 | |
6e47e069 AC |
2204 | MODULE_AUTHOR(DRIVER_AUTHOR); |
2205 | MODULE_DESCRIPTION(DRIVER_DESC); | |
1da177e4 | 2206 | MODULE_LICENSE("GPL"); |
e766aeb8 | 2207 | MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); |