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 LT |
825 | acm->ctrlurb->dev = acm->dev; |
826 | if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { | |
a5cc7ef9 JH |
827 | dev_err(&acm->control->dev, |
828 | "%s - usb_submit_urb(ctrl irq) failed\n", __func__); | |
7fb57a01 | 829 | goto error_submit_urb; |
1da177e4 LT |
830 | } |
831 | ||
7fb57a01 HS |
832 | acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS; |
833 | if (acm_set_control(acm, acm->ctrlout) < 0 && | |
ca79b7b4 | 834 | (acm->ctrl_caps & USB_CDC_CAP_LINE)) |
7fb57a01 | 835 | goto error_set_control; |
10077d4a | 836 | |
11ea859d | 837 | usb_autopm_put_interface(acm->control); |
1da177e4 | 838 | |
6c4707f3 OM |
839 | /* |
840 | * Unthrottle device in case the TTY was closed while throttled. | |
841 | */ | |
842 | spin_lock_irq(&acm->read_lock); | |
843 | acm->throttled = 0; | |
844 | acm->throttle_req = 0; | |
845 | spin_unlock_irq(&acm->read_lock); | |
846 | ||
088c64f8 | 847 | if (acm_submit_read_urbs(acm, GFP_KERNEL)) |
7fb57a01 | 848 | goto error_submit_read_urbs; |
2b626dc1 | 849 | |
1365baf7 | 850 | mutex_unlock(&acm->mutex); |
1da177e4 | 851 | |
7fb57a01 HS |
852 | return 0; |
853 | ||
854 | error_submit_read_urbs: | |
39166123 JH |
855 | for (i = 0; i < acm->rx_buflimit; i++) |
856 | usb_kill_urb(acm->read_urbs[i]); | |
7fb57a01 HS |
857 | acm->ctrlout = 0; |
858 | acm_set_control(acm, acm->ctrlout); | |
859 | error_set_control: | |
860 | usb_kill_urb(acm->ctrlurb); | |
861 | error_submit_urb: | |
2b626dc1 | 862 | usb_autopm_put_interface(acm->control); |
7fb57a01 HS |
863 | error_get_interface: |
864 | disconnected: | |
865 | mutex_unlock(&acm->mutex); | |
866 | return retval; | |
1da177e4 LT |
867 | } |
868 | ||
7fb57a01 | 869 | static void acm_port_destruct(struct tty_port *port) |
83ef344a | 870 | { |
7fb57a01 HS |
871 | struct acm *acm = container_of(port, struct acm, port); |
872 | ||
873 | dev_dbg(&acm->control->dev, "%s\n", __func__); | |
61a87adf | 874 | |
7fb57a01 | 875 | acm_release_minor(acm); |
83ef344a | 876 | usb_put_intf(acm->control); |
c4cabd28 | 877 | kfree(acm->country_codes); |
83ef344a | 878 | kfree(acm); |
879 | } | |
880 | ||
7fb57a01 | 881 | static void acm_port_shutdown(struct tty_port *port) |
10077d4a | 882 | { |
7fb57a01 | 883 | struct acm *acm = container_of(port, struct acm, port); |
67e8477b JH |
884 | struct urb *urb; |
885 | struct acm_wb *wb; | |
dab54c9f | 886 | int i; |
4421a014 | 887 | int pm_err; |
dab54c9f | 888 | |
7fb57a01 HS |
889 | dev_dbg(&acm->control->dev, "%s\n", __func__); |
890 | ||
891 | mutex_lock(&acm->mutex); | |
892 | if (!acm->disconnected) { | |
4421a014 | 893 | pm_err = usb_autopm_get_interface(acm->control); |
10077d4a | 894 | acm_set_control(acm, acm->ctrlout = 0); |
67e8477b JH |
895 | |
896 | for (;;) { | |
897 | urb = usb_get_from_anchor(&acm->delayed); | |
898 | if (!urb) | |
899 | break; | |
900 | wb = urb->context; | |
901 | wb->use = 0; | |
902 | usb_autopm_put_interface_async(acm->control); | |
903 | } | |
904 | ||
10077d4a AC |
905 | usb_kill_urb(acm->ctrlurb); |
906 | for (i = 0; i < ACM_NW; i++) | |
907 | usb_kill_urb(acm->wb[i].urb); | |
dab54c9f | 908 | for (i = 0; i < acm->rx_buflimit; i++) |
088c64f8 | 909 | usb_kill_urb(acm->read_urbs[i]); |
10077d4a | 910 | acm->control->needs_remote_wakeup = 0; |
4421a014 JH |
911 | if (!pm_err) |
912 | usb_autopm_put_interface(acm->control); | |
10077d4a | 913 | } |
7fb57a01 HS |
914 | mutex_unlock(&acm->mutex); |
915 | } | |
916 | ||
917 | static void acm_tty_cleanup(struct tty_struct *tty) | |
918 | { | |
919 | struct acm *acm = tty->driver_data; | |
920 | dev_dbg(&acm->control->dev, "%s\n", __func__); | |
921 | tty_port_put(&acm->port); | |
10077d4a AC |
922 | } |
923 | ||
924 | static void acm_tty_hangup(struct tty_struct *tty) | |
925 | { | |
926 | struct acm *acm = tty->driver_data; | |
7fb57a01 | 927 | dev_dbg(&acm->control->dev, "%s\n", __func__); |
10077d4a | 928 | tty_port_hangup(&acm->port); |
10077d4a AC |
929 | } |
930 | ||
1da177e4 LT |
931 | static void acm_tty_close(struct tty_struct *tty, struct file *filp) |
932 | { | |
933 | struct acm *acm = tty->driver_data; | |
7fb57a01 | 934 | dev_dbg(&acm->control->dev, "%s\n", __func__); |
6fa3eb70 S |
935 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
936 | dbg_mtk(&acm->control->dev, "%s port_cnt=%d", __func__, acm->port.count); | |
937 | if(!strcmp(MDDOWNLOADER_BIN_NAME, current->comm)){ | |
938 | record_enable = 0; | |
939 | dump_record(); | |
940 | } | |
941 | #endif | |
7fb57a01 | 942 | tty_port_close(&acm->port, tty, filp); |
1da177e4 LT |
943 | } |
944 | ||
6e47e069 AC |
945 | static int acm_tty_write(struct tty_struct *tty, |
946 | const unsigned char *buf, int count) | |
1da177e4 LT |
947 | { |
948 | struct acm *acm = tty->driver_data; | |
949 | int stat; | |
884b600f ON |
950 | unsigned long flags; |
951 | int wbn; | |
952 | struct acm_wb *wb; | |
6fa3eb70 S |
953 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
954 | int i, len; | |
955 | #endif | |
884b600f | 956 | |
1da177e4 LT |
957 | if (!count) |
958 | return 0; | |
959 | ||
5e9e75f8 | 960 | dev_vdbg(&acm->data->dev, "%s - count %d\n", __func__, count); |
a5cc7ef9 | 961 | |
6fa3eb70 S |
962 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
963 | if(enable_dump) { | |
964 | len = sprintf(data_out, "DT-O: "); | |
965 | for(i=0; i<count && i<DATA_DUMP_BYTES; i++) { | |
966 | len += sprintf(data_out+len, "%02X ", *(buf+i)); | |
967 | } | |
968 | sprintf(data_out+len, "\n"); | |
969 | dbg_mtk(&acm->data->dev, "%s", data_out); | |
970 | } | |
971 | #endif | |
884b600f | 972 | spin_lock_irqsave(&acm->write_lock, flags); |
6e47e069 AC |
973 | wbn = acm_wb_alloc(acm); |
974 | if (wbn < 0) { | |
884b600f | 975 | spin_unlock_irqrestore(&acm->write_lock, flags); |
884b600f ON |
976 | return 0; |
977 | } | |
978 | wb = &acm->wb[wbn]; | |
1da177e4 | 979 | |
884b600f | 980 | count = (count > acm->writesize) ? acm->writesize : count; |
5e9e75f8 | 981 | dev_vdbg(&acm->data->dev, "%s - write %d\n", __func__, count); |
884b600f ON |
982 | memcpy(wb->buf, buf, count); |
983 | wb->len = count; | |
984 | spin_unlock_irqrestore(&acm->write_lock, flags); | |
1da177e4 | 985 | |
6e47e069 AC |
986 | stat = acm_write_start(acm, wbn); |
987 | if (stat < 0) | |
1da177e4 | 988 | return stat; |
1da177e4 LT |
989 | return count; |
990 | } | |
991 | ||
992 | static int acm_tty_write_room(struct tty_struct *tty) | |
993 | { | |
994 | struct acm *acm = tty->driver_data; | |
884b600f ON |
995 | /* |
996 | * Do not let the line discipline to know that we have a reserve, | |
997 | * or it might get too enthusiastic. | |
998 | */ | |
934da463 | 999 | return acm_wb_is_avail(acm) ? acm->writesize : 0; |
1da177e4 LT |
1000 | } |
1001 | ||
1002 | static int acm_tty_chars_in_buffer(struct tty_struct *tty) | |
1003 | { | |
1004 | struct acm *acm = tty->driver_data; | |
7fb57a01 HS |
1005 | /* |
1006 | * if the device was unplugged then any remaining characters fell out | |
1007 | * of the connector ;) | |
1008 | */ | |
1009 | if (acm->disconnected) | |
23198fda | 1010 | return 0; |
884b600f ON |
1011 | /* |
1012 | * This is inaccurate (overcounts), but it works. | |
1013 | */ | |
86478944 | 1014 | return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize; |
1da177e4 LT |
1015 | } |
1016 | ||
1017 | static void acm_tty_throttle(struct tty_struct *tty) | |
1018 | { | |
1019 | struct acm *acm = tty->driver_data; | |
088c64f8 | 1020 | |
088c64f8 JH |
1021 | spin_lock_irq(&acm->read_lock); |
1022 | acm->throttle_req = 1; | |
1023 | spin_unlock_irq(&acm->read_lock); | |
1da177e4 LT |
1024 | } |
1025 | ||
1026 | static void acm_tty_unthrottle(struct tty_struct *tty) | |
1027 | { | |
1028 | struct acm *acm = tty->driver_data; | |
088c64f8 JH |
1029 | unsigned int was_throttled; |
1030 | ||
088c64f8 JH |
1031 | spin_lock_irq(&acm->read_lock); |
1032 | was_throttled = acm->throttled; | |
1033 | acm->throttled = 0; | |
1034 | acm->throttle_req = 0; | |
1035 | spin_unlock_irq(&acm->read_lock); | |
1036 | ||
1037 | if (was_throttled) | |
1038 | acm_submit_read_urbs(acm, GFP_KERNEL); | |
1da177e4 LT |
1039 | } |
1040 | ||
9e98966c | 1041 | static int acm_tty_break_ctl(struct tty_struct *tty, int state) |
1da177e4 LT |
1042 | { |
1043 | struct acm *acm = tty->driver_data; | |
9e98966c | 1044 | int retval; |
7fb57a01 | 1045 | |
9e98966c AC |
1046 | retval = acm_send_break(acm, state ? 0xffff : 0); |
1047 | if (retval < 0) | |
a5cc7ef9 JH |
1048 | dev_dbg(&acm->control->dev, "%s - send break failed\n", |
1049 | __func__); | |
9e98966c | 1050 | return retval; |
1da177e4 LT |
1051 | } |
1052 | ||
60b33c13 | 1053 | static int acm_tty_tiocmget(struct tty_struct *tty) |
1da177e4 LT |
1054 | { |
1055 | struct acm *acm = tty->driver_data; | |
1056 | ||
6fa3eb70 S |
1057 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
1058 | if(enable_dump) { | |
1059 | dbg_mtk(&acm->control->dev, "tiocmget ctrlin=%x\n", acm->ctrlin); | |
1060 | } | |
1061 | #endif | |
1da177e4 LT |
1062 | return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) | |
1063 | (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) | | |
1064 | (acm->ctrlin & ACM_CTRL_DSR ? TIOCM_DSR : 0) | | |
1065 | (acm->ctrlin & ACM_CTRL_RI ? TIOCM_RI : 0) | | |
1066 | (acm->ctrlin & ACM_CTRL_DCD ? TIOCM_CD : 0) | | |
1067 | TIOCM_CTS; | |
1068 | } | |
1069 | ||
20b9d177 | 1070 | static int acm_tty_tiocmset(struct tty_struct *tty, |
1da177e4 LT |
1071 | unsigned int set, unsigned int clear) |
1072 | { | |
1073 | struct acm *acm = tty->driver_data; | |
1074 | unsigned int newctrl; | |
1075 | ||
6fa3eb70 S |
1076 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
1077 | if(enable_dump) { | |
1078 | dbg_mtk(&acm->control->dev, "tiocmset ctrlout=%x\n", acm->ctrlout); | |
1079 | } | |
1080 | #endif | |
1da177e4 | 1081 | newctrl = acm->ctrlout; |
6e47e069 AC |
1082 | set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | |
1083 | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); | |
1084 | clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | | |
1085 | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); | |
1da177e4 LT |
1086 | |
1087 | newctrl = (newctrl & ~clear) | set; | |
1088 | ||
1089 | if (acm->ctrlout == newctrl) | |
1090 | return 0; | |
1091 | return acm_set_control(acm, acm->ctrlout = newctrl); | |
1092 | } | |
1093 | ||
18c75720 ON |
1094 | static int get_serial_info(struct acm *acm, struct serial_struct __user *info) |
1095 | { | |
1096 | struct serial_struct tmp; | |
1097 | ||
1098 | if (!info) | |
1099 | return -EINVAL; | |
1100 | ||
1101 | memset(&tmp, 0, sizeof(tmp)); | |
1102 | tmp.flags = ASYNC_LOW_LATENCY; | |
1103 | tmp.xmit_fifo_size = acm->writesize; | |
1104 | tmp.baud_base = le32_to_cpu(acm->line.dwDTERate); | |
ba2d8ce9 DW |
1105 | tmp.close_delay = acm->port.close_delay / 10; |
1106 | tmp.closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? | |
1107 | ASYNC_CLOSING_WAIT_NONE : | |
1108 | acm->port.closing_wait / 10; | |
18c75720 ON |
1109 | |
1110 | if (copy_to_user(info, &tmp, sizeof(tmp))) | |
1111 | return -EFAULT; | |
1112 | else | |
1113 | return 0; | |
1114 | } | |
1115 | ||
ba2d8ce9 DW |
1116 | static int set_serial_info(struct acm *acm, |
1117 | struct serial_struct __user *newinfo) | |
1118 | { | |
1119 | struct serial_struct new_serial; | |
1120 | unsigned int closing_wait, close_delay; | |
1121 | int retval = 0; | |
1122 | ||
1123 | if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) | |
1124 | return -EFAULT; | |
1125 | ||
1126 | close_delay = new_serial.close_delay * 10; | |
1127 | closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ? | |
1128 | ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10; | |
1129 | ||
1130 | mutex_lock(&acm->port.mutex); | |
1131 | ||
1132 | if (!capable(CAP_SYS_ADMIN)) { | |
1133 | if ((close_delay != acm->port.close_delay) || | |
1134 | (closing_wait != acm->port.closing_wait)) | |
1135 | retval = -EPERM; | |
1136 | else | |
1137 | retval = -EOPNOTSUPP; | |
1138 | } else { | |
1139 | acm->port.close_delay = close_delay; | |
1140 | acm->port.closing_wait = closing_wait; | |
1141 | } | |
1142 | ||
1143 | mutex_unlock(&acm->port.mutex); | |
1144 | return retval; | |
1145 | } | |
1146 | ||
6caa76b7 | 1147 | static int acm_tty_ioctl(struct tty_struct *tty, |
6e47e069 | 1148 | unsigned int cmd, unsigned long arg) |
1da177e4 | 1149 | { |
18c75720 ON |
1150 | struct acm *acm = tty->driver_data; |
1151 | int rv = -ENOIOCTLCMD; | |
1152 | ||
1153 | switch (cmd) { | |
1154 | case TIOCGSERIAL: /* gets serial port data */ | |
1155 | rv = get_serial_info(acm, (struct serial_struct __user *) arg); | |
ba2d8ce9 DW |
1156 | break; |
1157 | case TIOCSSERIAL: | |
1158 | rv = set_serial_info(acm, (struct serial_struct __user *) arg); | |
18c75720 ON |
1159 | break; |
1160 | } | |
1161 | ||
1162 | return rv; | |
1da177e4 LT |
1163 | } |
1164 | ||
6e47e069 AC |
1165 | static void acm_tty_set_termios(struct tty_struct *tty, |
1166 | struct ktermios *termios_old) | |
1da177e4 LT |
1167 | { |
1168 | struct acm *acm = tty->driver_data; | |
adc8d746 | 1169 | struct ktermios *termios = &tty->termios; |
1da177e4 LT |
1170 | struct usb_cdc_line_coding newline; |
1171 | int newctrl = acm->ctrlout; | |
1172 | ||
9b80fee1 | 1173 | newline.dwDTERate = cpu_to_le32(tty_get_baud_rate(tty)); |
1da177e4 LT |
1174 | newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; |
1175 | newline.bParityType = termios->c_cflag & PARENB ? | |
6e47e069 AC |
1176 | (termios->c_cflag & PARODD ? 1 : 2) + |
1177 | (termios->c_cflag & CMSPAR ? 2 : 0) : 0; | |
301a29da NB |
1178 | switch (termios->c_cflag & CSIZE) { |
1179 | case CS5: | |
1180 | newline.bDataBits = 5; | |
1181 | break; | |
1182 | case CS6: | |
1183 | newline.bDataBits = 6; | |
1184 | break; | |
1185 | case CS7: | |
1186 | newline.bDataBits = 7; | |
1187 | break; | |
1188 | case CS8: | |
1189 | default: | |
1190 | newline.bDataBits = 8; | |
1191 | break; | |
1192 | } | |
6e47e069 | 1193 | /* FIXME: Needs to clear unsupported bits in the termios */ |
1da177e4 LT |
1194 | acm->clocal = ((termios->c_cflag & CLOCAL) != 0); |
1195 | ||
2a18a875 | 1196 | if (C_BAUD(tty) == B0) { |
1da177e4 LT |
1197 | newline.dwDTERate = acm->line.dwDTERate; |
1198 | newctrl &= ~ACM_CTRL_DTR; | |
2a18a875 | 1199 | } else if (termios_old && (termios_old->c_cflag & CBAUD) == B0) { |
6e47e069 | 1200 | newctrl |= ACM_CTRL_DTR; |
2a18a875 | 1201 | } |
1da177e4 LT |
1202 | |
1203 | if (newctrl != acm->ctrlout) | |
1204 | acm_set_control(acm, acm->ctrlout = newctrl); | |
1205 | ||
1206 | if (memcmp(&acm->line, &newline, sizeof newline)) { | |
1207 | memcpy(&acm->line, &newline, sizeof newline); | |
a5cc7ef9 JH |
1208 | dev_dbg(&acm->control->dev, "%s - set line: %d %d %d %d\n", |
1209 | __func__, | |
1210 | le32_to_cpu(newline.dwDTERate), | |
1da177e4 LT |
1211 | newline.bCharFormat, newline.bParityType, |
1212 | newline.bDataBits); | |
1213 | acm_set_line(acm, &acm->line); | |
1214 | } | |
1215 | } | |
1216 | ||
7fb57a01 HS |
1217 | static const struct tty_port_operations acm_port_ops = { |
1218 | .shutdown = acm_port_shutdown, | |
1219 | .activate = acm_port_activate, | |
1220 | .destruct = acm_port_destruct, | |
1221 | }; | |
1222 | ||
1da177e4 LT |
1223 | /* |
1224 | * USB probe and disconnect routines. | |
1225 | */ | |
1226 | ||
830f4021 | 1227 | /* Little helpers: write/read buffers free */ |
884b600f ON |
1228 | static void acm_write_buffers_free(struct acm *acm) |
1229 | { | |
1230 | int i; | |
1231 | struct acm_wb *wb; | |
a496c64f | 1232 | struct usb_device *usb_dev = interface_to_usbdev(acm->control); |
884b600f | 1233 | |
6e47e069 | 1234 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) |
997ea58e | 1235 | usb_free_coherent(usb_dev, acm->writesize, wb->buf, wb->dmah); |
884b600f ON |
1236 | } |
1237 | ||
830f4021 ON |
1238 | static void acm_read_buffers_free(struct acm *acm) |
1239 | { | |
1240 | struct usb_device *usb_dev = interface_to_usbdev(acm->control); | |
dab54c9f | 1241 | int i; |
830f4021 | 1242 | |
dab54c9f | 1243 | for (i = 0; i < acm->rx_buflimit; i++) |
997ea58e | 1244 | usb_free_coherent(usb_dev, acm->readsize, |
088c64f8 | 1245 | acm->read_buffers[i].base, acm->read_buffers[i].dma); |
830f4021 ON |
1246 | } |
1247 | ||
884b600f ON |
1248 | /* Little helper: write buffers allocate */ |
1249 | static int acm_write_buffers_alloc(struct acm *acm) | |
1250 | { | |
1251 | int i; | |
1252 | struct acm_wb *wb; | |
1253 | ||
86478944 | 1254 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { |
997ea58e | 1255 | wb->buf = usb_alloc_coherent(acm->dev, acm->writesize, GFP_KERNEL, |
884b600f ON |
1256 | &wb->dmah); |
1257 | if (!wb->buf) { | |
1258 | while (i != 0) { | |
1259 | --i; | |
1260 | --wb; | |
997ea58e | 1261 | usb_free_coherent(acm->dev, acm->writesize, |
884b600f ON |
1262 | wb->buf, wb->dmah); |
1263 | } | |
1264 | return -ENOMEM; | |
1265 | } | |
1266 | } | |
1267 | return 0; | |
1268 | } | |
1269 | ||
10077d4a AC |
1270 | static int acm_probe(struct usb_interface *intf, |
1271 | const struct usb_device_id *id) | |
1da177e4 LT |
1272 | { |
1273 | struct usb_cdc_union_desc *union_header = NULL; | |
c4cabd28 | 1274 | struct usb_cdc_country_functional_desc *cfd = NULL; |
c6dbf554 | 1275 | unsigned char *buffer = intf->altsetting->extra; |
1da177e4 LT |
1276 | int buflen = intf->altsetting->extralen; |
1277 | struct usb_interface *control_interface; | |
1278 | struct usb_interface *data_interface; | |
a2bfb4a3 ON |
1279 | struct usb_endpoint_descriptor *epctrl = NULL; |
1280 | struct usb_endpoint_descriptor *epread = NULL; | |
1281 | struct usb_endpoint_descriptor *epwrite = NULL; | |
1da177e4 LT |
1282 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
1283 | struct acm *acm; | |
1284 | int minor; | |
6e47e069 | 1285 | int ctrlsize, readsize; |
1da177e4 LT |
1286 | u8 *buf; |
1287 | u8 ac_management_function = 0; | |
1288 | u8 call_management_function = 0; | |
1289 | int call_interface_num = -1; | |
fd5054c1 | 1290 | int data_interface_num = -1; |
1da177e4 | 1291 | unsigned long quirks; |
86478944 | 1292 | int num_rx_buf; |
61a87adf | 1293 | int i; |
a2bfb4a3 | 1294 | int combined_interfaces = 0; |
c93d8195 AK |
1295 | struct device *tty_dev; |
1296 | int rv = -ENOMEM; | |
1da177e4 | 1297 | |
86478944 | 1298 | /* normal quirks */ |
1da177e4 | 1299 | quirks = (unsigned long)id->driver_info; |
16142655 DT |
1300 | |
1301 | if (quirks == IGNORE_DEVICE) | |
1302 | return -ENODEV; | |
1303 | ||
86478944 ON |
1304 | num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR; |
1305 | ||
1306 | /* handle quirks deadly to normal probing*/ | |
1da177e4 LT |
1307 | if (quirks == NO_UNION_NORMAL) { |
1308 | data_interface = usb_ifnum_to_if(usb_dev, 1); | |
1309 | control_interface = usb_ifnum_to_if(usb_dev, 0); | |
1310 | goto skip_normal_probe; | |
1311 | } | |
6e47e069 | 1312 | |
1da177e4 LT |
1313 | /* normal probing*/ |
1314 | if (!buffer) { | |
9908a32e | 1315 | dev_err(&intf->dev, "Weird descriptor references\n"); |
1da177e4 LT |
1316 | return -EINVAL; |
1317 | } | |
1318 | ||
1319 | if (!buflen) { | |
577045c0 TG |
1320 | if (intf->cur_altsetting->endpoint && |
1321 | intf->cur_altsetting->endpoint->extralen && | |
6e47e069 AC |
1322 | intf->cur_altsetting->endpoint->extra) { |
1323 | dev_dbg(&intf->dev, | |
1324 | "Seeking extra descriptors on endpoint\n"); | |
1da177e4 LT |
1325 | buflen = intf->cur_altsetting->endpoint->extralen; |
1326 | buffer = intf->cur_altsetting->endpoint->extra; | |
1327 | } else { | |
9908a32e GKH |
1328 | dev_err(&intf->dev, |
1329 | "Zero length descriptor references\n"); | |
1da177e4 LT |
1330 | return -EINVAL; |
1331 | } | |
1332 | } | |
1333 | ||
1334 | while (buflen > 0) { | |
6e47e069 | 1335 | if (buffer[1] != USB_DT_CS_INTERFACE) { |
9908a32e | 1336 | dev_err(&intf->dev, "skipping garbage\n"); |
1da177e4 LT |
1337 | goto next_desc; |
1338 | } | |
1339 | ||
6e47e069 AC |
1340 | switch (buffer[2]) { |
1341 | case USB_CDC_UNION_TYPE: /* we've found it */ | |
1342 | if (union_header) { | |
1343 | dev_err(&intf->dev, "More than one " | |
1344 | "union descriptor, skipping ...\n"); | |
1345 | goto next_desc; | |
1da177e4 | 1346 | } |
6e47e069 AC |
1347 | union_header = (struct usb_cdc_union_desc *)buffer; |
1348 | break; | |
1349 | case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/ | |
1350 | cfd = (struct usb_cdc_country_functional_desc *)buffer; | |
1351 | break; | |
1352 | case USB_CDC_HEADER_TYPE: /* maybe check version */ | |
1353 | break; /* for now we ignore it */ | |
1354 | case USB_CDC_ACM_TYPE: | |
1355 | ac_management_function = buffer[3]; | |
1356 | break; | |
1357 | case USB_CDC_CALL_MANAGEMENT_TYPE: | |
1358 | call_management_function = buffer[3]; | |
1359 | call_interface_num = buffer[4]; | |
02f824ac | 1360 | if ((quirks & NOT_A_MODEM) == 0 && (call_management_function & 3) != 3) |
6e47e069 AC |
1361 | dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n"); |
1362 | break; | |
1363 | default: | |
1364 | /* there are LOTS more CDC descriptors that | |
1365 | * could legitimately be found here. | |
1366 | */ | |
1367 | dev_dbg(&intf->dev, "Ignoring descriptor: " | |
1368 | "type %02x, length %d\n", | |
1369 | buffer[2], buffer[0]); | |
1370 | break; | |
1371 | } | |
1da177e4 LT |
1372 | next_desc: |
1373 | buflen -= buffer[0]; | |
1374 | buffer += buffer[0]; | |
1375 | } | |
1376 | ||
1377 | if (!union_header) { | |
1378 | if (call_interface_num > 0) { | |
6e47e069 | 1379 | dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n"); |
fd5054c1 ES |
1380 | /* quirks for Droids MuIn LCD */ |
1381 | if (quirks & NO_DATA_INTERFACE) | |
1382 | data_interface = usb_ifnum_to_if(usb_dev, 0); | |
1383 | else | |
1384 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); | |
1da177e4 LT |
1385 | control_interface = intf; |
1386 | } else { | |
a2bfb4a3 ON |
1387 | if (intf->cur_altsetting->desc.bNumEndpoints != 3) { |
1388 | dev_dbg(&intf->dev,"No union descriptor, giving up\n"); | |
1389 | return -ENODEV; | |
1390 | } else { | |
1391 | dev_warn(&intf->dev,"No union descriptor, testing for castrated device\n"); | |
1392 | combined_interfaces = 1; | |
1393 | control_interface = data_interface = intf; | |
1394 | goto look_for_collapsed_interface; | |
1395 | } | |
1da177e4 LT |
1396 | } |
1397 | } else { | |
1398 | control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); | |
1399 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); | |
edefe206 GKH |
1400 | } |
1401 | ||
1402 | if (!control_interface || !data_interface) { | |
1403 | dev_dbg(&intf->dev, "no interfaces\n"); | |
1404 | return -ENODEV; | |
1da177e4 | 1405 | } |
6e47e069 | 1406 | |
1da177e4 | 1407 | if (data_interface_num != call_interface_num) |
6e47e069 | 1408 | dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n"); |
1da177e4 | 1409 | |
a2bfb4a3 ON |
1410 | if (control_interface == data_interface) { |
1411 | /* some broken devices designed for windows work this way */ | |
1412 | dev_warn(&intf->dev,"Control and data interfaces are not separated!\n"); | |
1413 | combined_interfaces = 1; | |
1414 | /* a popular other OS doesn't use it */ | |
1415 | quirks |= NO_CAP_LINE; | |
1416 | if (data_interface->cur_altsetting->desc.bNumEndpoints != 3) { | |
1417 | dev_err(&intf->dev, "This needs exactly 3 endpoints\n"); | |
1418 | return -EINVAL; | |
1419 | } | |
1420 | look_for_collapsed_interface: | |
1421 | for (i = 0; i < 3; i++) { | |
1422 | struct usb_endpoint_descriptor *ep; | |
1423 | ep = &data_interface->cur_altsetting->endpoint[i].desc; | |
1424 | ||
1425 | if (usb_endpoint_is_int_in(ep)) | |
1426 | epctrl = ep; | |
1427 | else if (usb_endpoint_is_bulk_out(ep)) | |
1428 | epwrite = ep; | |
1429 | else if (usb_endpoint_is_bulk_in(ep)) | |
1430 | epread = ep; | |
1431 | else | |
1432 | return -EINVAL; | |
1433 | } | |
1434 | if (!epctrl || !epread || !epwrite) | |
1435 | return -ENODEV; | |
1436 | else | |
1437 | goto made_compressed_probe; | |
1438 | } | |
1439 | ||
1da177e4 LT |
1440 | skip_normal_probe: |
1441 | ||
1442 | /*workaround for switched interfaces */ | |
6e47e069 AC |
1443 | if (data_interface->cur_altsetting->desc.bInterfaceClass |
1444 | != CDC_DATA_INTERFACE_TYPE) { | |
1445 | if (control_interface->cur_altsetting->desc.bInterfaceClass | |
1446 | == CDC_DATA_INTERFACE_TYPE) { | |
1da177e4 | 1447 | struct usb_interface *t; |
6e47e069 AC |
1448 | dev_dbg(&intf->dev, |
1449 | "Your device has switched interfaces.\n"); | |
1da177e4 LT |
1450 | t = control_interface; |
1451 | control_interface = data_interface; | |
1452 | data_interface = t; | |
1453 | } else { | |
1454 | return -EINVAL; | |
1455 | } | |
1456 | } | |
74da5d68 AS |
1457 | |
1458 | /* Accept probe requests only for the control interface */ | |
a2bfb4a3 | 1459 | if (!combined_interfaces && intf != control_interface) |
74da5d68 | 1460 | return -ENODEV; |
6e47e069 | 1461 | |
a2bfb4a3 ON |
1462 | if (!combined_interfaces && usb_interface_claimed(data_interface)) { |
1463 | /* valid in this context */ | |
6e47e069 | 1464 | dev_dbg(&intf->dev, "The data interface isn't available\n"); |
1da177e4 LT |
1465 | return -EBUSY; |
1466 | } | |
1467 | ||
1468 | ||
99f347ca SS |
1469 | if (data_interface->cur_altsetting->desc.bNumEndpoints < 2 || |
1470 | control_interface->cur_altsetting->desc.bNumEndpoints == 0) | |
1da177e4 LT |
1471 | return -EINVAL; |
1472 | ||
1473 | epctrl = &control_interface->cur_altsetting->endpoint[0].desc; | |
1474 | epread = &data_interface->cur_altsetting->endpoint[0].desc; | |
1475 | epwrite = &data_interface->cur_altsetting->endpoint[1].desc; | |
1476 | ||
1477 | ||
1478 | /* workaround for switched endpoints */ | |
45aea704 | 1479 | if (!usb_endpoint_dir_in(epread)) { |
1da177e4 LT |
1480 | /* descriptors are swapped */ |
1481 | struct usb_endpoint_descriptor *t; | |
6e47e069 AC |
1482 | dev_dbg(&intf->dev, |
1483 | "The data interface has switched endpoints\n"); | |
1da177e4 LT |
1484 | t = epread; |
1485 | epread = epwrite; | |
1486 | epwrite = t; | |
1487 | } | |
a2bfb4a3 | 1488 | made_compressed_probe: |
a5cc7ef9 | 1489 | dev_dbg(&intf->dev, "interfaces are valid\n"); |
1da177e4 | 1490 | |
6e47e069 AC |
1491 | acm = kzalloc(sizeof(struct acm), GFP_KERNEL); |
1492 | if (acm == NULL) { | |
255ab56c | 1493 | dev_err(&intf->dev, "out of memory (acm kzalloc)\n"); |
1da177e4 LT |
1494 | goto alloc_fail; |
1495 | } | |
1da177e4 | 1496 | |
7fb57a01 HS |
1497 | minor = acm_alloc_minor(acm); |
1498 | if (minor == ACM_TTY_MINORS) { | |
1499 | dev_err(&intf->dev, "no more free acm devices\n"); | |
1500 | kfree(acm); | |
1501 | return -ENODEV; | |
1502 | } | |
1503 | ||
29cc8897 KM |
1504 | ctrlsize = usb_endpoint_maxp(epctrl); |
1505 | readsize = usb_endpoint_maxp(epread) * | |
6e47e069 | 1506 | (quirks == SINGLE_RX_URB ? 1 : 2); |
a2bfb4a3 | 1507 | acm->combined_interfaces = combined_interfaces; |
6fa3eb70 S |
1508 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
1509 | acm->writesize = ACM_WB_SZ; | |
1510 | #else | |
29cc8897 | 1511 | acm->writesize = usb_endpoint_maxp(epwrite) * 20; |
6fa3eb70 | 1512 | #endif |
1da177e4 LT |
1513 | acm->control = control_interface; |
1514 | acm->data = data_interface; | |
1515 | acm->minor = minor; | |
1516 | acm->dev = usb_dev; | |
1517 | acm->ctrl_caps = ac_management_function; | |
a2bfb4a3 ON |
1518 | if (quirks & NO_CAP_LINE) |
1519 | acm->ctrl_caps &= ~USB_CDC_CAP_LINE; | |
1da177e4 LT |
1520 | acm->ctrlsize = ctrlsize; |
1521 | acm->readsize = readsize; | |
86478944 | 1522 | acm->rx_buflimit = num_rx_buf; |
c4028958 | 1523 | INIT_WORK(&acm->work, acm_softint); |
884b600f | 1524 | spin_lock_init(&acm->write_lock); |
61a87adf | 1525 | spin_lock_init(&acm->read_lock); |
1365baf7 | 1526 | mutex_init(&acm->mutex); |
61a87adf | 1527 | acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); |
cf7fdd57 ON |
1528 | acm->is_int_ep = usb_endpoint_xfer_int(epread); |
1529 | if (acm->is_int_ep) | |
1530 | acm->bInterval = epread->bInterval; | |
739e0285 AC |
1531 | tty_port_init(&acm->port); |
1532 | acm->port.ops = &acm_port_ops; | |
67e8477b | 1533 | init_usb_anchor(&acm->delayed); |
1da177e4 | 1534 | |
997ea58e | 1535 | buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); |
1da177e4 | 1536 | if (!buf) { |
255ab56c | 1537 | dev_err(&intf->dev, "out of memory (ctrl buffer alloc)\n"); |
1da177e4 LT |
1538 | goto alloc_fail2; |
1539 | } | |
1540 | acm->ctrl_buffer = buf; | |
1541 | ||
884b600f | 1542 | if (acm_write_buffers_alloc(acm) < 0) { |
255ab56c | 1543 | dev_err(&intf->dev, "out of memory (write buffer alloc)\n"); |
1da177e4 LT |
1544 | goto alloc_fail4; |
1545 | } | |
1da177e4 LT |
1546 | |
1547 | acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); | |
1548 | if (!acm->ctrlurb) { | |
255ab56c | 1549 | dev_err(&intf->dev, "out of memory (ctrlurb kmalloc)\n"); |
1da177e4 LT |
1550 | goto alloc_fail5; |
1551 | } | |
86478944 | 1552 | for (i = 0; i < num_rx_buf; i++) { |
088c64f8 JH |
1553 | struct acm_rb *rb = &(acm->read_buffers[i]); |
1554 | struct urb *urb; | |
61a87adf | 1555 | |
74f5e1ba JH |
1556 | rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL, |
1557 | &rb->dma); | |
1558 | if (!rb->base) { | |
1559 | dev_err(&intf->dev, "out of memory " | |
1560 | "(read bufs usb_alloc_coherent)\n"); | |
1561 | goto alloc_fail6; | |
1562 | } | |
088c64f8 JH |
1563 | rb->index = i; |
1564 | rb->instance = acm; | |
74f5e1ba | 1565 | |
088c64f8 JH |
1566 | urb = usb_alloc_urb(0, GFP_KERNEL); |
1567 | if (!urb) { | |
255ab56c | 1568 | dev_err(&intf->dev, |
6e47e069 | 1569 | "out of memory (read urbs usb_alloc_urb)\n"); |
c2572b78 | 1570 | goto alloc_fail6; |
61a87adf | 1571 | } |
088c64f8 JH |
1572 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1573 | urb->transfer_dma = rb->dma; | |
1574 | if (acm->is_int_ep) { | |
1575 | usb_fill_int_urb(urb, acm->dev, | |
1576 | acm->rx_endpoint, | |
1577 | rb->base, | |
1578 | acm->readsize, | |
1579 | acm_read_bulk_callback, rb, | |
1580 | acm->bInterval); | |
1581 | } else { | |
1582 | usb_fill_bulk_urb(urb, acm->dev, | |
1583 | acm->rx_endpoint, | |
1584 | rb->base, | |
1585 | acm->readsize, | |
1586 | acm_read_bulk_callback, rb); | |
1587 | } | |
61a87adf | 1588 | |
088c64f8 JH |
1589 | acm->read_urbs[i] = urb; |
1590 | __set_bit(i, &acm->read_urbs_free); | |
61a87adf | 1591 | } |
6e47e069 | 1592 | for (i = 0; i < ACM_NW; i++) { |
e4cf3aa8 DE |
1593 | struct acm_wb *snd = &(acm->wb[i]); |
1594 | ||
6e47e069 AC |
1595 | snd->urb = usb_alloc_urb(0, GFP_KERNEL); |
1596 | if (snd->urb == NULL) { | |
255ab56c | 1597 | dev_err(&intf->dev, |
59d7fec7 | 1598 | "out of memory (write urbs usb_alloc_urb)\n"); |
74f5e1ba | 1599 | goto alloc_fail7; |
e4cf3aa8 DE |
1600 | } |
1601 | ||
5186ffee AL |
1602 | if (usb_endpoint_xfer_int(epwrite)) |
1603 | usb_fill_int_urb(snd->urb, usb_dev, | |
c5211187 | 1604 | usb_sndintpipe(usb_dev, epwrite->bEndpointAddress), |
5186ffee AL |
1605 | NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval); |
1606 | else | |
1607 | usb_fill_bulk_urb(snd->urb, usb_dev, | |
1608 | usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), | |
1609 | NULL, acm->writesize, acm_write_bulk, snd); | |
e4cf3aa8 DE |
1610 | snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1611 | snd->instance = acm; | |
1da177e4 LT |
1612 | } |
1613 | ||
6e47e069 | 1614 | usb_set_intfdata(intf, acm); |
c4cabd28 ON |
1615 | |
1616 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); | |
1617 | if (i < 0) | |
74f5e1ba | 1618 | goto alloc_fail7; |
c4cabd28 ON |
1619 | |
1620 | if (cfd) { /* export the country data */ | |
1621 | acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL); | |
1622 | if (!acm->country_codes) | |
1623 | goto skip_countries; | |
1624 | acm->country_code_size = cfd->bLength - 4; | |
6e47e069 AC |
1625 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, |
1626 | cfd->bLength - 4); | |
c4cabd28 ON |
1627 | acm->country_rel_date = cfd->iCountryCodeRelDate; |
1628 | ||
1629 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); | |
1630 | if (i < 0) { | |
1631 | kfree(acm->country_codes); | |
e7c8e860 JL |
1632 | acm->country_codes = NULL; |
1633 | acm->country_code_size = 0; | |
c4cabd28 ON |
1634 | goto skip_countries; |
1635 | } | |
1636 | ||
6e47e069 AC |
1637 | i = device_create_file(&intf->dev, |
1638 | &dev_attr_iCountryCodeRelDate); | |
c4cabd28 | 1639 | if (i < 0) { |
c2572b78 | 1640 | device_remove_file(&intf->dev, &dev_attr_wCountryCodes); |
c4cabd28 | 1641 | kfree(acm->country_codes); |
e7c8e860 JL |
1642 | acm->country_codes = NULL; |
1643 | acm->country_code_size = 0; | |
c4cabd28 ON |
1644 | goto skip_countries; |
1645 | } | |
1646 | } | |
1647 | ||
1648 | skip_countries: | |
6e47e069 | 1649 | usb_fill_int_urb(acm->ctrlurb, usb_dev, |
a2bfb4a3 ON |
1650 | usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), |
1651 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, | |
1652 | /* works around buggy devices */ | |
1653 | epctrl->bInterval ? epctrl->bInterval : 0xff); | |
1da177e4 LT |
1654 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1655 | acm->ctrlurb->transfer_dma = acm->ctrl_dma; | |
1656 | ||
1da177e4 LT |
1657 | dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); |
1658 | ||
1659 | acm_set_control(acm, acm->ctrlout); | |
1660 | ||
1661 | acm->line.dwDTERate = cpu_to_le32(9600); | |
1662 | acm->line.bDataBits = 8; | |
1663 | acm_set_line(acm, &acm->line); | |
1664 | ||
1665 | usb_driver_claim_interface(&acm_driver, data_interface, acm); | |
672c4e18 | 1666 | usb_set_intfdata(data_interface, acm); |
1da177e4 | 1667 | |
83ef344a | 1668 | usb_get_intf(control_interface); |
c93d8195 | 1669 | tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor, |
734cc178 | 1670 | &control_interface->dev); |
c93d8195 AK |
1671 | if (IS_ERR(tty_dev)) { |
1672 | rv = PTR_ERR(tty_dev); | |
1673 | goto alloc_fail8; | |
1674 | } | |
1da177e4 | 1675 | |
c4cabd28 | 1676 | return 0; |
c93d8195 AK |
1677 | alloc_fail8: |
1678 | if (acm->country_codes) { | |
1679 | device_remove_file(&acm->control->dev, | |
1680 | &dev_attr_wCountryCodes); | |
1681 | device_remove_file(&acm->control->dev, | |
1682 | &dev_attr_iCountryCodeRelDate); | |
b16c4055 | 1683 | kfree(acm->country_codes); |
c93d8195 AK |
1684 | } |
1685 | device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); | |
74f5e1ba | 1686 | alloc_fail7: |
c93d8195 | 1687 | usb_set_intfdata(intf, NULL); |
e4cf3aa8 DE |
1688 | for (i = 0; i < ACM_NW; i++) |
1689 | usb_free_urb(acm->wb[i].urb); | |
c2572b78 | 1690 | alloc_fail6: |
86478944 | 1691 | for (i = 0; i < num_rx_buf; i++) |
088c64f8 | 1692 | usb_free_urb(acm->read_urbs[i]); |
74f5e1ba | 1693 | acm_read_buffers_free(acm); |
1da177e4 LT |
1694 | usb_free_urb(acm->ctrlurb); |
1695 | alloc_fail5: | |
884b600f | 1696 | acm_write_buffers_free(acm); |
1da177e4 | 1697 | alloc_fail4: |
997ea58e | 1698 | usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); |
1da177e4 | 1699 | alloc_fail2: |
7fb57a01 | 1700 | acm_release_minor(acm); |
1da177e4 LT |
1701 | kfree(acm); |
1702 | alloc_fail: | |
c93d8195 | 1703 | return rv; |
1da177e4 LT |
1704 | } |
1705 | ||
1365baf7 ON |
1706 | static void stop_data_traffic(struct acm *acm) |
1707 | { | |
1708 | int i; | |
a5cc7ef9 JH |
1709 | |
1710 | dev_dbg(&acm->control->dev, "%s\n", __func__); | |
1365baf7 | 1711 | |
1365baf7 | 1712 | usb_kill_urb(acm->ctrlurb); |
6e47e069 | 1713 | for (i = 0; i < ACM_NW; i++) |
e4cf3aa8 | 1714 | usb_kill_urb(acm->wb[i].urb); |
1365baf7 | 1715 | for (i = 0; i < acm->rx_buflimit; i++) |
088c64f8 | 1716 | usb_kill_urb(acm->read_urbs[i]); |
1365baf7 ON |
1717 | |
1718 | cancel_work_sync(&acm->work); | |
1719 | } | |
1720 | ||
1da177e4 LT |
1721 | static void acm_disconnect(struct usb_interface *intf) |
1722 | { | |
c4cabd28 | 1723 | struct acm *acm = usb_get_intfdata(intf); |
1da177e4 | 1724 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
10077d4a | 1725 | struct tty_struct *tty; |
7fb57a01 HS |
1726 | int i; |
1727 | ||
1728 | dev_dbg(&intf->dev, "%s\n", __func__); | |
1da177e4 | 1729 | |
672c4e18 DB |
1730 | /* sibling interface is already cleaning up */ |
1731 | if (!acm) | |
86067eea | 1732 | return; |
672c4e18 | 1733 | |
7fb57a01 HS |
1734 | mutex_lock(&acm->mutex); |
1735 | acm->disconnected = true; | |
6e47e069 | 1736 | if (acm->country_codes) { |
74da5d68 AS |
1737 | device_remove_file(&acm->control->dev, |
1738 | &dev_attr_wCountryCodes); | |
1739 | device_remove_file(&acm->control->dev, | |
1740 | &dev_attr_iCountryCodeRelDate); | |
c4cabd28 | 1741 | } |
74da5d68 | 1742 | device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); |
86067eea ON |
1743 | usb_set_intfdata(acm->control, NULL); |
1744 | usb_set_intfdata(acm->data, NULL); | |
7fb57a01 HS |
1745 | mutex_unlock(&acm->mutex); |
1746 | ||
1747 | tty = tty_port_tty_get(&acm->port); | |
1748 | if (tty) { | |
1749 | tty_vhangup(tty); | |
1750 | tty_kref_put(tty); | |
1751 | } | |
1da177e4 | 1752 | |
1365baf7 | 1753 | stop_data_traffic(acm); |
1da177e4 | 1754 | |
cb25505f JH |
1755 | tty_unregister_device(acm_tty_driver, acm->minor); |
1756 | ||
7fb57a01 HS |
1757 | usb_free_urb(acm->ctrlurb); |
1758 | for (i = 0; i < ACM_NW; i++) | |
1759 | usb_free_urb(acm->wb[i].urb); | |
1760 | for (i = 0; i < acm->rx_buflimit; i++) | |
1761 | usb_free_urb(acm->read_urbs[i]); | |
884b600f | 1762 | acm_write_buffers_free(acm); |
7fb57a01 | 1763 | usb_free_coherent(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); |
830f4021 | 1764 | acm_read_buffers_free(acm); |
1da177e4 | 1765 | |
a2bfb4a3 ON |
1766 | if (!acm->combined_interfaces) |
1767 | usb_driver_release_interface(&acm_driver, intf == acm->control ? | |
830f4021 | 1768 | acm->data : acm->control); |
1da177e4 | 1769 | |
7fb57a01 | 1770 | tty_port_put(&acm->port); |
1da177e4 LT |
1771 | } |
1772 | ||
35758589 | 1773 | #ifdef CONFIG_PM |
1365baf7 ON |
1774 | static int acm_suspend(struct usb_interface *intf, pm_message_t message) |
1775 | { | |
1776 | struct acm *acm = usb_get_intfdata(intf); | |
11ea859d ON |
1777 | int cnt; |
1778 | ||
6fa3eb70 | 1779 | dbg_mtk(&acm->control->dev, "%s intf=%d", __func__, intf->cur_altsetting->desc.bInterfaceNumber); |
c5ece482 JH |
1780 | spin_lock_irq(&acm->read_lock); |
1781 | spin_lock(&acm->write_lock); | |
5b1b0b81 | 1782 | if (PMSG_IS_AUTO(message)) { |
c5ece482 JH |
1783 | if (acm->transmitting) { |
1784 | spin_unlock(&acm->write_lock); | |
1785 | spin_unlock_irq(&acm->read_lock); | |
11ea859d | 1786 | return -EBUSY; |
c5ece482 | 1787 | } |
6fa3eb70 S |
1788 | }else{ |
1789 | int i; | |
1790 | for (i = 0; i < ACM_NW; i++){ | |
1791 | if(acm->wb[i].use){ | |
1792 | spin_unlock(&acm->write_lock); | |
1793 | spin_unlock_irq(&acm->read_lock); | |
1794 | return -EBUSY; | |
1795 | } | |
1796 | } | |
11ea859d | 1797 | } |
6fa3eb70 | 1798 | |
11ea859d ON |
1799 | cnt = acm->susp_count++; |
1800 | spin_unlock(&acm->write_lock); | |
1801 | spin_unlock_irq(&acm->read_lock); | |
1365baf7 | 1802 | |
11ea859d | 1803 | if (cnt) |
1365baf7 | 1804 | return 0; |
1365baf7 | 1805 | |
52c84b33 | 1806 | stop_data_traffic(acm); |
1365baf7 | 1807 | |
1365baf7 ON |
1808 | return 0; |
1809 | } | |
1810 | ||
1811 | static int acm_resume(struct usb_interface *intf) | |
1812 | { | |
1813 | struct acm *acm = usb_get_intfdata(intf); | |
67e8477b | 1814 | struct urb *urb; |
1365baf7 ON |
1815 | int rv = 0; |
1816 | ||
6fa3eb70 S |
1817 | dbg_mtk(&acm->control->dev, "%s intf=%d", __func__, intf->cur_altsetting->desc.bInterfaceNumber); |
1818 | ||
11ea859d | 1819 | spin_lock_irq(&acm->read_lock); |
1b3fe006 | 1820 | spin_lock(&acm->write_lock); |
11ea859d | 1821 | |
1b3fe006 JH |
1822 | if (--acm->susp_count) |
1823 | goto out; | |
1365baf7 | 1824 | |
7fb57a01 | 1825 | if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) { |
1b3fe006 | 1826 | rv = usb_submit_urb(acm->ctrlurb, GFP_ATOMIC); |
97d35f95 | 1827 | |
67e8477b JH |
1828 | for (;;) { |
1829 | urb = usb_get_from_anchor(&acm->delayed); | |
1830 | if (!urb) | |
1831 | break; | |
1832 | ||
1833 | acm_start_wb(acm, urb->context); | |
97d35f95 ON |
1834 | } |
1835 | ||
1836 | /* | |
1837 | * delayed error checking because we must | |
1838 | * do the write path at all cost | |
1839 | */ | |
6fa3eb70 S |
1840 | if (rv < 0){ |
1841 | MYDBG("urb fail:%d\n", rv); | |
1b3fe006 | 1842 | goto out; |
6fa3eb70 | 1843 | } |
1365baf7 | 1844 | |
1b3fe006 | 1845 | rv = acm_submit_read_urbs(acm, GFP_ATOMIC); |
1365baf7 | 1846 | } |
1b3fe006 JH |
1847 | out: |
1848 | spin_unlock(&acm->write_lock); | |
1849 | spin_unlock_irq(&acm->read_lock); | |
1365baf7 | 1850 | |
1365baf7 ON |
1851 | return rv; |
1852 | } | |
35758589 | 1853 | |
a91b0c50 FL |
1854 | static int acm_reset_resume(struct usb_interface *intf) |
1855 | { | |
1856 | struct acm *acm = usb_get_intfdata(intf); | |
a91b0c50 | 1857 | |
aa27a094 JS |
1858 | if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) |
1859 | tty_port_tty_hangup(&acm->port, false); | |
7fb57a01 | 1860 | |
a91b0c50 FL |
1861 | return acm_resume(intf); |
1862 | } | |
1863 | ||
35758589 | 1864 | #endif /* CONFIG_PM */ |
c1479a92 AT |
1865 | |
1866 | #define NOKIA_PCSUITE_ACM_INFO(x) \ | |
1867 | USB_DEVICE_AND_INTERFACE_INFO(0x0421, x, \ | |
1868 | USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \ | |
1869 | USB_CDC_ACM_PROTO_VENDOR) | |
1870 | ||
4035e456 TG |
1871 | #define SAMSUNG_PCSUITE_ACM_INFO(x) \ |
1872 | USB_DEVICE_AND_INTERFACE_INFO(0x04e7, x, \ | |
1873 | USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \ | |
1874 | USB_CDC_ACM_PROTO_VENDOR) | |
1875 | ||
1da177e4 LT |
1876 | /* |
1877 | * USB driver structure. | |
1878 | */ | |
1879 | ||
6ef4852b | 1880 | static const struct usb_device_id acm_ids[] = { |
1da177e4 | 1881 | /* quirky and broken devices */ |
522a78be DC |
1882 | { USB_DEVICE(0x17ef, 0x7000), /* Lenovo USB modem */ |
1883 | .driver_info = NO_UNION_NORMAL, },/* has no union descriptor */ | |
1da177e4 LT |
1884 | { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */ |
1885 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1886 | }, | |
b0e2a705 AA |
1887 | { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */ |
1888 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1889 | }, | |
0f9c7b4a AL |
1890 | { USB_DEVICE(0x0e8d, 0x3329), /* MediaTek Inc GPS */ |
1891 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1892 | }, | |
8753e65e MO |
1893 | { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */ |
1894 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1895 | }, | |
91a9c921 CM |
1896 | { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */ |
1897 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1898 | }, | |
7abcf20b AC |
1899 | { USB_DEVICE(0x0ace, 0x1602), /* ZyDAS 56K USB MODEM */ |
1900 | .driver_info = SINGLE_RX_URB, | |
1901 | }, | |
86478944 ON |
1902 | { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */ |
1903 | .driver_info = SINGLE_RX_URB, /* firmware bug */ | |
1904 | }, | |
3dd2ae81 ON |
1905 | { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */ |
1906 | .driver_info = SINGLE_RX_URB, /* firmware bug */ | |
1907 | }, | |
9be8456c ON |
1908 | { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */ |
1909 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1910 | }, | |
6149ed5e IM |
1911 | { USB_DEVICE(0x0803, 0x3095), /* Zoom Telephonics Model 3095F USB MODEM */ |
1912 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1913 | }, | |
c8fd2c37 ES |
1914 | { USB_DEVICE(0x0572, 0x1321), /* Conexant USB MODEM CX93010 */ |
1915 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1916 | }, | |
c89c60e9 AC |
1917 | { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */ |
1918 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1919 | }, | |
cab98a0a XK |
1920 | { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */ |
1921 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | |
1922 | }, | |
1e2dedaa | 1923 | { USB_DEVICE(0x2184, 0x001c) }, /* GW Instek AFG-2225 */ |
155df65a DT |
1924 | { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */ |
1925 | }, | |
6abff5dc KH |
1926 | /* Motorola H24 HSPA module: */ |
1927 | { USB_DEVICE(0x22b8, 0x2d91) }, /* modem */ | |
ed37e0cb MU |
1928 | { USB_DEVICE(0x22b8, 0x2d92), /* modem + diagnostics */ |
1929 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1930 | }, | |
1931 | { USB_DEVICE(0x22b8, 0x2d93), /* modem + AT port */ | |
1932 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1933 | }, | |
1934 | { USB_DEVICE(0x22b8, 0x2d95), /* modem + AT port + diagnostics */ | |
1935 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1936 | }, | |
1937 | { USB_DEVICE(0x22b8, 0x2d96), /* modem + NMEA */ | |
1938 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1939 | }, | |
1940 | { USB_DEVICE(0x22b8, 0x2d97), /* modem + diagnostics + NMEA */ | |
1941 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1942 | }, | |
1943 | { USB_DEVICE(0x22b8, 0x2d99), /* modem + AT port + NMEA */ | |
1944 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1945 | }, | |
1946 | { USB_DEVICE(0x22b8, 0x2d9a), /* modem + AT port + diagnostics + NMEA */ | |
1947 | .driver_info = NO_UNION_NORMAL, /* handle only modem interface */ | |
1948 | }, | |
6abff5dc | 1949 | |
c332b4e1 AR |
1950 | { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */ |
1951 | .driver_info = NO_UNION_NORMAL, /* union descriptor misplaced on | |
1952 | data interface instead of | |
1953 | communications interface. | |
1954 | Maybe we should define a new | |
1955 | quirk for this. */ | |
1956 | }, | |
e7d491a1 JCR |
1957 | { USB_DEVICE(0x0572, 0x1340), /* Conexant CX93010-2x UCMxx */ |
1958 | .driver_info = NO_UNION_NORMAL, | |
1959 | }, | |
036915a7 DL |
1960 | { USB_DEVICE(0x05f9, 0x4002), /* PSC Scanning, Magellan 800i */ |
1961 | .driver_info = NO_UNION_NORMAL, | |
1962 | }, | |
1f17c502 KK |
1963 | { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */ |
1964 | .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */ | |
1965 | }, | |
c3baa19b RN |
1966 | { USB_DEVICE(0x1576, 0x03b1), /* Maretron USB100 */ |
1967 | .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */ | |
1968 | }, | |
9be8456c | 1969 | |
c1479a92 AT |
1970 | /* Nokia S60 phones expose two ACM channels. The first is |
1971 | * a modem and is picked up by the standard AT-command | |
1972 | * information below. The second is 'vendor-specific' but | |
1973 | * is treated as a serial device at the S60 end, so we want | |
1974 | * to expose it on Linux too. */ | |
1975 | { NOKIA_PCSUITE_ACM_INFO(0x042D), }, /* Nokia 3250 */ | |
1976 | { NOKIA_PCSUITE_ACM_INFO(0x04D8), }, /* Nokia 5500 Sport */ | |
1977 | { NOKIA_PCSUITE_ACM_INFO(0x04C9), }, /* Nokia E50 */ | |
1978 | { NOKIA_PCSUITE_ACM_INFO(0x0419), }, /* Nokia E60 */ | |
1979 | { NOKIA_PCSUITE_ACM_INFO(0x044D), }, /* Nokia E61 */ | |
1980 | { NOKIA_PCSUITE_ACM_INFO(0x0001), }, /* Nokia E61i */ | |
1981 | { NOKIA_PCSUITE_ACM_INFO(0x0475), }, /* Nokia E62 */ | |
1982 | { NOKIA_PCSUITE_ACM_INFO(0x0508), }, /* Nokia E65 */ | |
1983 | { NOKIA_PCSUITE_ACM_INFO(0x0418), }, /* Nokia E70 */ | |
1984 | { NOKIA_PCSUITE_ACM_INFO(0x0425), }, /* Nokia N71 */ | |
1985 | { NOKIA_PCSUITE_ACM_INFO(0x0486), }, /* Nokia N73 */ | |
1986 | { NOKIA_PCSUITE_ACM_INFO(0x04DF), }, /* Nokia N75 */ | |
1987 | { NOKIA_PCSUITE_ACM_INFO(0x000e), }, /* Nokia N77 */ | |
1988 | { NOKIA_PCSUITE_ACM_INFO(0x0445), }, /* Nokia N80 */ | |
1989 | { NOKIA_PCSUITE_ACM_INFO(0x042F), }, /* Nokia N91 & N91 8GB */ | |
1990 | { NOKIA_PCSUITE_ACM_INFO(0x048E), }, /* Nokia N92 */ | |
1991 | { NOKIA_PCSUITE_ACM_INFO(0x0420), }, /* Nokia N93 */ | |
1992 | { NOKIA_PCSUITE_ACM_INFO(0x04E6), }, /* Nokia N93i */ | |
1993 | { NOKIA_PCSUITE_ACM_INFO(0x04B2), }, /* Nokia 5700 XpressMusic */ | |
1994 | { NOKIA_PCSUITE_ACM_INFO(0x0134), }, /* Nokia 6110 Navigator (China) */ | |
1995 | { NOKIA_PCSUITE_ACM_INFO(0x046E), }, /* Nokia 6110 Navigator */ | |
1996 | { NOKIA_PCSUITE_ACM_INFO(0x002f), }, /* Nokia 6120 classic & */ | |
1997 | { NOKIA_PCSUITE_ACM_INFO(0x0088), }, /* Nokia 6121 classic */ | |
1998 | { NOKIA_PCSUITE_ACM_INFO(0x00fc), }, /* Nokia 6124 classic */ | |
1999 | { NOKIA_PCSUITE_ACM_INFO(0x0042), }, /* Nokia E51 */ | |
2000 | { NOKIA_PCSUITE_ACM_INFO(0x00b0), }, /* Nokia E66 */ | |
2001 | { NOKIA_PCSUITE_ACM_INFO(0x00ab), }, /* Nokia E71 */ | |
2002 | { NOKIA_PCSUITE_ACM_INFO(0x0481), }, /* Nokia N76 */ | |
2003 | { NOKIA_PCSUITE_ACM_INFO(0x0007), }, /* Nokia N81 & N81 8GB */ | |
2004 | { NOKIA_PCSUITE_ACM_INFO(0x0071), }, /* Nokia N82 */ | |
2005 | { NOKIA_PCSUITE_ACM_INFO(0x04F0), }, /* Nokia N95 & N95-3 NAM */ | |
2006 | { NOKIA_PCSUITE_ACM_INFO(0x0070), }, /* Nokia N95 8GB */ | |
2007 | { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */ | |
2008 | { NOKIA_PCSUITE_ACM_INFO(0x0099), }, /* Nokia 6210 Navigator, RM-367 */ | |
2009 | { NOKIA_PCSUITE_ACM_INFO(0x0128), }, /* Nokia 6210 Navigator, RM-419 */ | |
2010 | { NOKIA_PCSUITE_ACM_INFO(0x008f), }, /* Nokia 6220 Classic */ | |
2011 | { NOKIA_PCSUITE_ACM_INFO(0x00a0), }, /* Nokia 6650 */ | |
2012 | { NOKIA_PCSUITE_ACM_INFO(0x007b), }, /* Nokia N78 */ | |
2013 | { NOKIA_PCSUITE_ACM_INFO(0x0094), }, /* Nokia N85 */ | |
2014 | { NOKIA_PCSUITE_ACM_INFO(0x003a), }, /* Nokia N96 & N96-3 */ | |
2015 | { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */ | |
2016 | { NOKIA_PCSUITE_ACM_INFO(0x0108), }, /* Nokia 5320 XpressMusic 2G */ | |
2017 | { NOKIA_PCSUITE_ACM_INFO(0x01f5), }, /* Nokia N97, RM-505 */ | |
83a4eae9 | 2018 | { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */ |
4035e456 TG |
2019 | { NOKIA_PCSUITE_ACM_INFO(0x0178), }, /* Nokia E63 */ |
2020 | { NOKIA_PCSUITE_ACM_INFO(0x010e), }, /* Nokia E75 */ | |
2021 | { NOKIA_PCSUITE_ACM_INFO(0x02d9), }, /* Nokia 6760 Slide */ | |
2022 | { NOKIA_PCSUITE_ACM_INFO(0x01d0), }, /* Nokia E52 */ | |
2023 | { NOKIA_PCSUITE_ACM_INFO(0x0223), }, /* Nokia E72 */ | |
2024 | { NOKIA_PCSUITE_ACM_INFO(0x0275), }, /* Nokia X6 */ | |
2025 | { NOKIA_PCSUITE_ACM_INFO(0x026c), }, /* Nokia N97 Mini */ | |
2026 | { NOKIA_PCSUITE_ACM_INFO(0x0154), }, /* Nokia 5800 XpressMusic */ | |
2027 | { NOKIA_PCSUITE_ACM_INFO(0x04ce), }, /* Nokia E90 */ | |
2028 | { NOKIA_PCSUITE_ACM_INFO(0x01d4), }, /* Nokia E55 */ | |
721d92fc | 2029 | { NOKIA_PCSUITE_ACM_INFO(0x0302), }, /* Nokia N8 */ |
4061fde2 TG |
2030 | { NOKIA_PCSUITE_ACM_INFO(0x0335), }, /* Nokia E7 */ |
2031 | { NOKIA_PCSUITE_ACM_INFO(0x03cd), }, /* Nokia C7 */ | |
4035e456 | 2032 | { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */ |
c1479a92 | 2033 | |
65e52f41 DP |
2034 | /* Support for Owen devices */ |
2035 | { USB_DEVICE(0x03eb, 0x0030), }, /* Owen SI30 */ | |
2036 | ||
c1479a92 AT |
2037 | /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */ |
2038 | ||
7c5d8c39 | 2039 | /* Support Lego NXT using pbLua firmware */ |
ce126644 JC |
2040 | { USB_DEVICE(0x0694, 0xff00), |
2041 | .driver_info = NOT_A_MODEM, | |
7893afc0 | 2042 | }, |
7c5d8c39 | 2043 | |
fd5054c1 ES |
2044 | /* Support for Droids MuIn LCD */ |
2045 | { USB_DEVICE(0x04d8, 0x000b), | |
2046 | .driver_info = NO_DATA_INTERFACE, | |
2047 | }, | |
2048 | ||
16142655 DT |
2049 | #if IS_ENABLED(CONFIG_INPUT_IMS_PCU) |
2050 | { USB_DEVICE(0x04d8, 0x0082), /* Application mode */ | |
2051 | .driver_info = IGNORE_DEVICE, | |
2052 | }, | |
2053 | { USB_DEVICE(0x04d8, 0x0083), /* Bootloader mode */ | |
2054 | .driver_info = IGNORE_DEVICE, | |
2055 | }, | |
2056 | #endif | |
2057 | ||
7f877278 JJ |
2058 | /* Exclude Infineon Flash Loader utility */ |
2059 | { USB_DEVICE(0x058b, 0x0041), | |
2060 | .driver_info = IGNORE_DEVICE, | |
2061 | }, | |
2062 | ||
5b239f0a PC |
2063 | /* control interfaces without any protocol set */ |
2064 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | |
2065 | USB_CDC_PROTO_NONE) }, | |
2066 | ||
1da177e4 LT |
2067 | /* control interfaces with various AT-command sets */ |
2068 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | |
2069 | USB_CDC_ACM_PROTO_AT_V25TER) }, | |
2070 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | |
2071 | USB_CDC_ACM_PROTO_AT_PCCA101) }, | |
2072 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | |
2073 | USB_CDC_ACM_PROTO_AT_PCCA101_WAKE) }, | |
2074 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | |
2075 | USB_CDC_ACM_PROTO_AT_GSM) }, | |
2076 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | |
6e47e069 | 2077 | USB_CDC_ACM_PROTO_AT_3G) }, |
1da177e4 LT |
2078 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
2079 | USB_CDC_ACM_PROTO_AT_CDMA) }, | |
2080 | ||
1da177e4 LT |
2081 | { } |
2082 | }; | |
2083 | ||
6e47e069 | 2084 | MODULE_DEVICE_TABLE(usb, acm_ids); |
1da177e4 LT |
2085 | |
2086 | static struct usb_driver acm_driver = { | |
1da177e4 LT |
2087 | .name = "cdc_acm", |
2088 | .probe = acm_probe, | |
2089 | .disconnect = acm_disconnect, | |
35758589 | 2090 | #ifdef CONFIG_PM |
1365baf7 ON |
2091 | .suspend = acm_suspend, |
2092 | .resume = acm_resume, | |
a91b0c50 | 2093 | .reset_resume = acm_reset_resume, |
35758589 | 2094 | #endif |
1da177e4 | 2095 | .id_table = acm_ids, |
35758589 | 2096 | #ifdef CONFIG_PM |
1365baf7 | 2097 | .supports_autosuspend = 1, |
35758589 | 2098 | #endif |
e1f12eb6 | 2099 | .disable_hub_initiated_lpm = 1, |
1da177e4 LT |
2100 | }; |
2101 | ||
2102 | /* | |
2103 | * TTY driver structures. | |
2104 | */ | |
2105 | ||
b68e31d0 | 2106 | static const struct tty_operations acm_ops = { |
7fb57a01 | 2107 | .install = acm_tty_install, |
1da177e4 LT |
2108 | .open = acm_tty_open, |
2109 | .close = acm_tty_close, | |
7fb57a01 | 2110 | .cleanup = acm_tty_cleanup, |
10077d4a | 2111 | .hangup = acm_tty_hangup, |
1da177e4 LT |
2112 | .write = acm_tty_write, |
2113 | .write_room = acm_tty_write_room, | |
2114 | .ioctl = acm_tty_ioctl, | |
2115 | .throttle = acm_tty_throttle, | |
2116 | .unthrottle = acm_tty_unthrottle, | |
2117 | .chars_in_buffer = acm_tty_chars_in_buffer, | |
2118 | .break_ctl = acm_tty_break_ctl, | |
2119 | .set_termios = acm_tty_set_termios, | |
2120 | .tiocmget = acm_tty_tiocmget, | |
2121 | .tiocmset = acm_tty_tiocmset, | |
2122 | }; | |
2123 | ||
2124 | /* | |
2125 | * Init / exit. | |
2126 | */ | |
2127 | ||
2128 | static int __init acm_init(void) | |
2129 | { | |
2130 | int retval; | |
6fa3eb70 S |
2131 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
2132 | int i; | |
2133 | #endif | |
1da177e4 LT |
2134 | acm_tty_driver = alloc_tty_driver(ACM_TTY_MINORS); |
2135 | if (!acm_tty_driver) | |
2136 | return -ENOMEM; | |
1da177e4 LT |
2137 | acm_tty_driver->driver_name = "acm", |
2138 | acm_tty_driver->name = "ttyACM", | |
1da177e4 LT |
2139 | acm_tty_driver->major = ACM_TTY_MAJOR, |
2140 | acm_tty_driver->minor_start = 0, | |
2141 | acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL, | |
2142 | acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, | |
331b8319 | 2143 | acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
1da177e4 | 2144 | acm_tty_driver->init_termios = tty_std_termios; |
6e47e069 AC |
2145 | acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | |
2146 | HUPCL | CLOCAL; | |
6fa3eb70 S |
2147 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
2148 | /* wx, disable echo and other flags in the very beginning. | |
2149 | * otherwise RILD will disable them via calling tcsetattr() after it opened tty port, | |
2150 | * so there may be a gap between port opening and calling tcsetattr(). If modem send data | |
2151 | * at that time, things goes ugly. | |
2152 | */ | |
2153 | acm_tty_driver->init_termios.c_iflag = 0; | |
2154 | acm_tty_driver->init_termios.c_oflag = 0; | |
2155 | acm_tty_driver->init_termios.c_lflag = 0; | |
2156 | for(i= 0; i < CB_NUM ; i++){ | |
2157 | callback_check_timeout[i] = jiffies; | |
2158 | } | |
2159 | #endif | |
1da177e4 LT |
2160 | tty_set_operations(acm_tty_driver, &acm_ops); |
2161 | ||
2162 | retval = tty_register_driver(acm_tty_driver); | |
2163 | if (retval) { | |
2164 | put_tty_driver(acm_tty_driver); | |
2165 | return retval; | |
2166 | } | |
2167 | ||
2168 | retval = usb_register(&acm_driver); | |
2169 | if (retval) { | |
2170 | tty_unregister_driver(acm_tty_driver); | |
2171 | put_tty_driver(acm_tty_driver); | |
2172 | return retval; | |
2173 | } | |
2174 | ||
a2c7b935 | 2175 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n"); |
1da177e4 LT |
2176 | |
2177 | return 0; | |
2178 | } | |
2179 | ||
2180 | static void __exit acm_exit(void) | |
2181 | { | |
2182 | usb_deregister(&acm_driver); | |
2183 | tty_unregister_driver(acm_tty_driver); | |
2184 | put_tty_driver(acm_tty_driver); | |
2185 | } | |
2186 | ||
2187 | module_init(acm_init); | |
2188 | module_exit(acm_exit); | |
6fa3eb70 S |
2189 | #ifdef CONFIG_MTK_DT_USB_SUPPORT |
2190 | module_param(enable_debug, int, 0644); | |
2191 | module_param(enable_dump, int, 0644); | |
2192 | #endif | |
1da177e4 | 2193 | |
6e47e069 AC |
2194 | MODULE_AUTHOR(DRIVER_AUTHOR); |
2195 | MODULE_DESCRIPTION(DRIVER_DESC); | |
1da177e4 | 2196 | MODULE_LICENSE("GPL"); |
e766aeb8 | 2197 | MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); |