4 * Copyright (c) 1999 Armin Fuerst <fuerst@in.tum.de>
5 * Copyright (c) 1999 Pavel Machek <pavel@ucw.cz>
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>
9 * Copyright (c) 2005 David Kubicek <dave@awk.cz>
10 * Copyright (c) 2011 Johan Hovold <jhovold@gmail.com>
12 * USB Abstract Control Model driver for USB modems and ISDN adapters
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.
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.
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
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>
39 #include <linux/serial.h>
40 #include <linux/tty_driver.h>
41 #include <linux/tty_flip.h>
42 #include <linux/module.h>
43 #include <linux/mutex.h>
44 #include <linux/uaccess.h>
45 #include <linux/usb.h>
46 #include <linux/usb/cdc.h>
47 #include <asm/byteorder.h>
48 #include <asm/unaligned.h>
49 #include <linux/list.h>
53 #ifdef CONFIG_MTK_DT_USB_SUPPORT
55 /* adjust to 1 to avoid musb bug when lots write with clean urb */
58 /* adjust SZ to hsmaxp*20 to prevent tty disc don't accept big size write */
59 #define ACM_WB_SZ (512*20)
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
];
66 static int enable_debug
= 0;
67 static int enable_dump
= 0;
68 //origninal CDC-ACM log, more detail
70 #define dev_dbg(dev, format, args...) \
73 dev_printk(KERN_WARNING, dev, "[CDC-ACM] " format, ##args); \
77 #define dev_vdbg dev_dbg
78 //MTK added CDC-ACM log, more critical
79 #define dbg_mtk(dev, format, args...) \
81 dev_printk(KERN_WARNING, dev, "[CDC-ACM-MTK] " format "\n", ##args); \
84 #define dbg_mtk(dev, format, args...) do{}while(0)
88 #define DRIVER_AUTHOR "Armin Fuerst, Pavel Machek, Johannes Erdfelt, Vojtech Pavlik, David Kubicek, Johan Hovold"
89 #define DRIVER_DESC "USB Abstract Control Model driver for USB modems and ISDN adapters"
91 static struct usb_driver acm_driver
;
92 static struct tty_driver
*acm_tty_driver
;
93 static struct acm
*acm_table
[ACM_TTY_MINORS
];
95 static DEFINE_MUTEX(acm_table_lock
);
97 #define MYDBG(fmt, args...) do {printk(KERN_WARNING "MTK_ACM, <%s(), %d> " fmt, __func__, __LINE__, ## args); }while(0)
99 #ifdef CONFIG_MTK_DT_USB_SUPPORT
101 #define RECORD_SZ 100
105 struct timeval cur_time
;
106 u32 transfer_buffer_length
;
111 }w1
[RECORD_SZ
], w2
[RECORD_SZ
], r1
[RECORD_SZ
], r2
[RECORD_SZ
];
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)
119 struct record_entry
*ptr
;
121 index_limit
= w1_idx
;
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
);
129 index_limit
= r1_idx
;
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
);
137 index_limit
= w2_idx
;
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
);
145 index_limit
= r2_idx
;
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
);
154 void record_activity(struct urb
*urb
, int is_in
, int is_complete
)
156 struct timeval tv_time
;
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
;
166 if(r2_idx
>= RECORD_SZ
)
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
);
177 if(r1_idx
>= RECORD_SZ
)
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
;
186 if(w2_idx
>= RECORD_SZ
)
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
);
196 if(w1_idx
>= RECORD_SZ
)
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
);
207 bool usb_h_acm_all_clear(void)
211 for (i
= 0; i
< ACM_TTY_MINORS
; i
++) {
212 if(acm_table
[i
] != NULL
) {
216 MYDBG("count<%d>\n", count
);
219 EXPORT_SYMBOL_GPL(usb_h_acm_all_clear
);
221 #define CHECK_INTERVAL 2
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",
230 void mark_callback_alive(char *func_name
, struct urb
*urb
, struct acm
*acm
)
235 for(i
= 0; i
< CB_NUM
; i
++)
237 if(!strcmp(func_name
, callback_name
[i
])){
238 if(enable_debug
|| time_after(jiffies
, callback_check_timeout
[i
]))
240 MYDBG("%s,ep(%d),len(%d,%d),data(%x),sts(%d), minor(%d)\n",
242 urb
->ep
->desc
.bEndpointAddress
,
244 urb
->transfer_buffer_length
,
245 *((unsigned char*)urb
->transfer_buffer
),
248 callback_check_timeout
[i
] = jiffies
+ HZ
* CHECK_INTERVAL
;
259 * acm_table accessors
263 * Look up an ACM structure by index. If found and not disconnected, increment
264 * its refcount and return it with its mutex held.
266 static struct acm
*acm_get_by_index(unsigned index
)
270 mutex_lock(&acm_table_lock
);
271 acm
= acm_table
[index
];
273 mutex_lock(&acm
->mutex
);
274 if (acm
->disconnected
) {
275 mutex_unlock(&acm
->mutex
);
278 tty_port_get(&acm
->port
);
279 mutex_unlock(&acm
->mutex
);
282 mutex_unlock(&acm_table_lock
);
287 * Try to find an available minor number and if found, associate it with 'acm'.
289 static int acm_alloc_minor(struct acm
*acm
)
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
;
300 mutex_unlock(&acm_table_lock
);
305 /* Release the minor number associated with 'acm'. */
306 static void acm_release_minor(struct acm
*acm
)
308 mutex_lock(&acm_table_lock
);
309 acm_table
[acm
->minor
] = NULL
;
310 mutex_unlock(&acm_table_lock
);
314 * Functions for ACM control messages.
317 static int acm_ctrl_msg(struct acm
*acm
, int request
, int value
,
322 retval
= usb_autopm_get_interface(acm
->control
);
326 retval
= usb_control_msg(acm
->dev
, usb_sndctrlpipe(acm
->dev
, 0),
327 request
, USB_RT_ACM
, value
,
328 acm
->control
->altsetting
[0].desc
.bInterfaceNumber
,
331 dev_dbg(&acm
->control
->dev
,
332 "%s - rq 0x%02x, val %#x, len %#x, result %d\n",
333 __func__
, request
, value
, len
, retval
);
335 usb_autopm_put_interface(acm
->control
);
337 return retval
< 0 ? retval
: 0;
340 /* devices aren't required to support these requests.
341 * the cdc acm descriptor tells whether they do...
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)
351 * Write buffer management.
352 * All of these assume proper locks taken by the caller.
355 static int acm_wb_alloc(struct acm
*acm
)
368 wbn
= (wbn
+ 1) % ACM_NW
;
374 static int acm_wb_is_avail(struct acm
*acm
)
380 spin_lock_irqsave(&acm
->write_lock
, flags
);
381 for (i
= 0; i
< ACM_NW
; i
++)
383 spin_unlock_irqrestore(&acm
->write_lock
, flags
);
388 * Finish write. Caller must hold acm->write_lock
390 static void acm_write_done(struct acm
*acm
, struct acm_wb
*wb
)
394 usb_autopm_put_interface_async(acm
->control
);
400 * the caller is responsible for locking
403 static int acm_start_wb(struct acm
*acm
, struct acm_wb
*wb
)
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
;
414 #ifdef CONFIG_MTK_DT_USB_SUPPORT
415 record_activity(wb
->urb
, 0, 0);
417 rc
= usb_submit_urb(wb
->urb
, GFP_ATOMIC
);
419 dev_err(&acm
->data
->dev
,
420 "%s - usb_submit_urb(write bulk) failed: %d\n",
422 acm_write_done(acm
, wb
);
427 static int acm_write_start(struct acm
*acm
, int wbn
)
430 struct acm_wb
*wb
= &acm
->wb
[wbn
];
433 spin_lock_irqsave(&acm
->write_lock
, flags
);
436 spin_unlock_irqrestore(&acm
->write_lock
, flags
);
440 dev_vdbg(&acm
->data
->dev
, "%s - susp_count %d\n", __func__
,
442 usb_autopm_get_interface_async(acm
->control
);
443 if (acm
->susp_count
) {
444 usb_anchor_urb(wb
->urb
, &acm
->delayed
);
445 spin_unlock_irqrestore(&acm
->write_lock
, flags
);
448 usb_mark_last_busy(acm
->dev
);
450 rc
= acm_start_wb(acm
, wb
);
451 spin_unlock_irqrestore(&acm
->write_lock
, flags
);
457 * attributes exported through sysfs
459 static ssize_t show_caps
460 (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
462 struct usb_interface
*intf
= to_usb_interface(dev
);
463 struct acm
*acm
= usb_get_intfdata(intf
);
465 return sprintf(buf
, "%d", acm
->ctrl_caps
);
467 static DEVICE_ATTR(bmCapabilities
, S_IRUGO
, show_caps
, NULL
);
469 static ssize_t show_country_codes
470 (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
472 struct usb_interface
*intf
= to_usb_interface(dev
);
473 struct acm
*acm
= usb_get_intfdata(intf
);
475 memcpy(buf
, acm
->country_codes
, acm
->country_code_size
);
476 return acm
->country_code_size
;
479 static DEVICE_ATTR(wCountryCodes
, S_IRUGO
, show_country_codes
, NULL
);
481 static ssize_t show_country_rel_date
482 (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
484 struct usb_interface
*intf
= to_usb_interface(dev
);
485 struct acm
*acm
= usb_get_intfdata(intf
);
487 return sprintf(buf
, "%d", acm
->country_rel_date
);
490 static DEVICE_ATTR(iCountryCodeRelDate
, S_IRUGO
, show_country_rel_date
, NULL
);
492 * Interrupt handlers for various ACM device responses
495 /* control interface reports status changes with "interrupt" transfers */
496 static void acm_ctrl_irq(struct urb
*urb
)
498 struct acm
*acm
= urb
->context
;
499 struct usb_cdc_notification
*dr
= urb
->transfer_buffer
;
503 int status
= urb
->status
;
512 /* this urb is terminated, clean up */
513 dev_err(&acm
->control
->dev
,
514 "%s - urb shutting down with status: %d\n",
518 dev_err(&acm
->control
->dev
,
519 "%s - nonzero urb status received: %d\n",
524 usb_mark_last_busy(acm
->dev
);
525 #ifdef CONFIG_MTK_DT_USB_SUPPORT
526 mark_callback_alive(__func__
, urb
, acm
);
529 data
= (unsigned char *)(dr
+ 1);
530 switch (dr
->bNotificationType
) {
531 case USB_CDC_NOTIFY_NETWORK_CONNECTION
:
532 dev_dbg(&acm
->control
->dev
, "%s - network connection: %d\n",
533 __func__
, dr
->wValue
);
536 case USB_CDC_NOTIFY_SERIAL_STATE
:
537 newctrl
= get_unaligned_le16(data
);
539 if (!acm
->clocal
&& (acm
->ctrlin
& ~newctrl
& ACM_CTRL_DCD
)) {
540 dev_dbg(&acm
->control
->dev
, "%s - calling hangup\n",
542 tty_port_tty_hangup(&acm
->port
, false);
545 acm
->ctrlin
= newctrl
;
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",
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
? '+' : '-');
561 dev_dbg(&acm
->control
->dev
,
562 "%s - unknown notification %d received: index %d "
563 "len %d data0 %d data1 %d\n",
565 dr
->bNotificationType
, dr
->wIndex
,
566 dr
->wLength
, data
[0], data
[1]);
570 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
572 dev_err(&acm
->control
->dev
, "%s - usb_submit_urb failed: %d\n",
576 static int acm_submit_read_urb(struct acm
*acm
, int index
, gfp_t mem_flags
)
580 if (!test_and_clear_bit(index
, &acm
->read_urbs_free
)){
584 dev_vdbg(&acm
->data
->dev
, "%s - urb %d\n", __func__
, index
);
586 #ifdef CONFIG_MTK_DT_USB_SUPPORT
587 record_activity(acm
->read_urbs
[index
], 1, 0);
590 res
= usb_submit_urb(acm
->read_urbs
[index
], mem_flags
);
592 MYDBG("urb fail(%d)\n", res
);
594 dev_err(&acm
->data
->dev
,
595 "%s - usb_submit_urb failed: %d\n",
598 set_bit(index
, &acm
->read_urbs_free
);
605 static int acm_submit_read_urbs(struct acm
*acm
, gfp_t mem_flags
)
610 for (i
= 0; i
< acm
->rx_buflimit
; ++i
) {
611 res
= acm_submit_read_urb(acm
, i
, mem_flags
);
620 static void acm_process_read_urb(struct acm
*acm
, struct urb
*urb
)
623 #ifdef CONFIG_MTK_DT_USB_SUPPORT
626 if (!urb
->actual_length
){
629 #ifdef CONFIG_MTK_DT_USB_SUPPORT
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
));
635 sprintf(data_in
+len
, "\n");
636 dbg_mtk(&acm
->data
->dev
, "%s", data_in
);
640 tty_insert_flip_string(&acm
->port
, urb
->transfer_buffer
,
642 tty_flip_buffer_push(&acm
->port
);
645 static void acm_read_bulk_callback(struct urb
*urb
)
647 struct acm_rb
*rb
= urb
->context
;
648 struct acm
*acm
= rb
->instance
;
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
);
655 #ifdef CONFIG_MTK_DT_USB_SUPPORT
656 record_activity(urb
, 1, 1);
660 dev_dbg(&acm
->data
->dev
, "%s - disconnected\n", __func__
);
663 usb_mark_last_busy(acm
->dev
);
666 dev_err(&acm
->data
->dev
, "%s - non-zero urb status: %d\n",
667 __func__
, urb
->status
);
670 #ifdef CONFIG_MTK_DT_USB_SUPPORT
671 mark_callback_alive(__func__
, urb
, acm
);
673 acm_process_read_urb(acm
, urb
);
675 /* throttle device if requested by tty */
676 spin_lock_irqsave(&acm
->read_lock
, flags
);
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
);
682 spin_unlock_irqrestore(&acm
->read_lock
, flags
);
686 /* data interface wrote those outgoing bytes */
687 static void acm_write_bulk(struct urb
*urb
)
689 struct acm_wb
*wb
= urb
->context
;
690 struct acm
*acm
= wb
->instance
;
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",
698 urb
->transfer_buffer_length
,
700 *((char *)(urb
->transfer_buffer
)));
702 #ifdef CONFIG_MTK_DT_USB_SUPPORT
703 record_activity(urb
, 0, 1);
706 #ifdef CONFIG_MTK_DT_USB_SUPPORT
707 mark_callback_alive(__func__
, urb
, acm
);
709 spin_lock_irqsave(&acm
->write_lock
, flags
);
710 acm_write_done(acm
, wb
);
711 spin_unlock_irqrestore(&acm
->write_lock
, flags
);
712 schedule_work(&acm
->work
);
715 static void acm_softint(struct work_struct
*work
)
717 struct acm
*acm
= container_of(work
, struct acm
, work
);
719 dev_vdbg(&acm
->data
->dev
, "%s\n", __func__
);
721 tty_port_tty_wakeup(&acm
->port
);
728 static int acm_tty_install(struct tty_driver
*driver
, struct tty_struct
*tty
)
733 dev_dbg(tty
->dev
, "%s\n", __func__
);
735 acm
= acm_get_by_index(tty
->index
);
739 retval
= tty_standard_install(driver
, tty
);
741 goto error_init_termios
;
743 tty
->driver_data
= acm
;
748 tty_port_put(&acm
->port
);
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
);
756 static int acm_tty_open(struct tty_struct
*tty
, struct file
*filp
)
758 #ifdef CONFIG_MTK_DT_USB_SUPPORT
759 struct usb_device
*udev
;
763 acm
= tty
->driver_data
;
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
);
773 #define META_BIN_NAME "meta_tst"
774 #define MDDOWNLOADER_BIN_NAME "downloader"
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
);
783 if(!strcmp(MDDOWNLOADER_BIN_NAME
, current
->comm
)){
785 w1_idx
= w2_idx
= r1_idx
= r2_idx
= 0;
786 do_gettimeofday(&tv_start
);
790 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
792 dev_dbg(tty
->dev
, "%s\n", __func__
);
794 return tty_port_open(&acm
->port
, tty
, filp
);
797 static int acm_port_activate(struct tty_port
*port
, struct tty_struct
*tty
)
799 struct acm
*acm
= container_of(port
, struct acm
, port
);
800 int retval
= -ENODEV
;
803 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
805 mutex_lock(&acm
->mutex
);
806 if (acm
->disconnected
)
809 retval
= usb_autopm_get_interface(acm
->control
);
811 goto error_get_interface
;
814 * FIXME: Why do we need this? Allocating 64K of physically contiguous
815 * memory is really nasty...
817 set_bit(TTY_NO_WRITE_SPLIT
, &tty
->flags
);
818 acm
->control
->needs_remote_wakeup
= 1;
819 #ifdef CONFIG_MTK_DT_USB_SUPPORT
820 #ifdef CONFIG_PM_RUNTIME
821 acm
->control
->needs_remote_wakeup
= 0;
825 acm
->ctrlurb
->dev
= acm
->dev
;
826 retval
= usb_submit_urb(acm
->ctrlurb
, GFP_KERNEL
);
828 dev_err(&acm
->control
->dev
,
829 "%s - usb_submit_urb(ctrl irq) failed\n", __func__
);
830 goto error_submit_urb
;
833 acm
->ctrlout
= ACM_CTRL_DTR
| ACM_CTRL_RTS
;
834 retval
= acm_set_control(acm
, acm
->ctrlout
);
835 if (retval
< 0 && (acm
->ctrl_caps
& USB_CDC_CAP_LINE
))
836 goto error_set_control
;
839 * Unthrottle device in case the TTY was closed while throttled.
841 spin_lock_irq(&acm
->read_lock
);
843 acm
->throttle_req
= 0;
844 spin_unlock_irq(&acm
->read_lock
);
846 retval
= acm_submit_read_urbs(acm
, GFP_KERNEL
);
848 goto error_submit_read_urbs
;
850 usb_autopm_put_interface(acm
->control
);
852 mutex_unlock(&acm
->mutex
);
856 error_submit_read_urbs
:
857 for (i
= 0; i
< acm
->rx_buflimit
; i
++)
858 usb_kill_urb(acm
->read_urbs
[i
]);
860 acm_set_control(acm
, acm
->ctrlout
);
862 usb_kill_urb(acm
->ctrlurb
);
864 usb_autopm_put_interface(acm
->control
);
867 mutex_unlock(&acm
->mutex
);
869 return usb_translate_errors(retval
);
872 static void acm_port_destruct(struct tty_port
*port
)
874 struct acm
*acm
= container_of(port
, struct acm
, port
);
876 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
878 acm_release_minor(acm
);
879 usb_put_intf(acm
->control
);
880 kfree(acm
->country_codes
);
884 static void acm_port_shutdown(struct tty_port
*port
)
886 struct acm
*acm
= container_of(port
, struct acm
, port
);
892 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
894 mutex_lock(&acm
->mutex
);
895 if (!acm
->disconnected
) {
896 pm_err
= usb_autopm_get_interface(acm
->control
);
897 acm_set_control(acm
, acm
->ctrlout
= 0);
900 urb
= usb_get_from_anchor(&acm
->delayed
);
905 usb_autopm_put_interface_async(acm
->control
);
908 usb_kill_urb(acm
->ctrlurb
);
909 for (i
= 0; i
< ACM_NW
; i
++)
910 usb_kill_urb(acm
->wb
[i
].urb
);
911 for (i
= 0; i
< acm
->rx_buflimit
; i
++)
912 usb_kill_urb(acm
->read_urbs
[i
]);
913 acm
->control
->needs_remote_wakeup
= 0;
915 usb_autopm_put_interface(acm
->control
);
917 mutex_unlock(&acm
->mutex
);
920 static void acm_tty_cleanup(struct tty_struct
*tty
)
922 struct acm
*acm
= tty
->driver_data
;
923 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
924 tty_port_put(&acm
->port
);
927 static void acm_tty_hangup(struct tty_struct
*tty
)
929 struct acm
*acm
= tty
->driver_data
;
930 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
931 tty_port_hangup(&acm
->port
);
934 static void acm_tty_close(struct tty_struct
*tty
, struct file
*filp
)
936 struct acm
*acm
= tty
->driver_data
;
937 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
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
)){
945 tty_port_close(&acm
->port
, tty
, filp
);
948 static int acm_tty_write(struct tty_struct
*tty
,
949 const unsigned char *buf
, int count
)
951 struct acm
*acm
= tty
->driver_data
;
956 #ifdef CONFIG_MTK_DT_USB_SUPPORT
963 dev_vdbg(&acm
->data
->dev
, "%s - count %d\n", __func__
, count
);
965 #ifdef CONFIG_MTK_DT_USB_SUPPORT
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
));
971 sprintf(data_out
+len
, "\n");
972 dbg_mtk(&acm
->data
->dev
, "%s", data_out
);
975 spin_lock_irqsave(&acm
->write_lock
, flags
);
976 wbn
= acm_wb_alloc(acm
);
978 spin_unlock_irqrestore(&acm
->write_lock
, flags
);
983 count
= (count
> acm
->writesize
) ? acm
->writesize
: count
;
984 dev_vdbg(&acm
->data
->dev
, "%s - write %d\n", __func__
, count
);
985 memcpy(wb
->buf
, buf
, count
);
987 spin_unlock_irqrestore(&acm
->write_lock
, flags
);
989 stat
= acm_write_start(acm
, wbn
);
995 static int acm_tty_write_room(struct tty_struct
*tty
)
997 struct acm
*acm
= tty
->driver_data
;
999 * Do not let the line discipline to know that we have a reserve,
1000 * or it might get too enthusiastic.
1002 return acm_wb_is_avail(acm
) ? acm
->writesize
: 0;
1005 static int acm_tty_chars_in_buffer(struct tty_struct
*tty
)
1007 struct acm
*acm
= tty
->driver_data
;
1009 * if the device was unplugged then any remaining characters fell out
1010 * of the connector ;)
1012 if (acm
->disconnected
)
1015 * This is inaccurate (overcounts), but it works.
1017 return (ACM_NW
- acm_wb_is_avail(acm
)) * acm
->writesize
;
1020 static void acm_tty_throttle(struct tty_struct
*tty
)
1022 struct acm
*acm
= tty
->driver_data
;
1024 spin_lock_irq(&acm
->read_lock
);
1025 acm
->throttle_req
= 1;
1026 spin_unlock_irq(&acm
->read_lock
);
1029 static void acm_tty_unthrottle(struct tty_struct
*tty
)
1031 struct acm
*acm
= tty
->driver_data
;
1032 unsigned int was_throttled
;
1034 spin_lock_irq(&acm
->read_lock
);
1035 was_throttled
= acm
->throttled
;
1037 acm
->throttle_req
= 0;
1038 spin_unlock_irq(&acm
->read_lock
);
1041 acm_submit_read_urbs(acm
, GFP_KERNEL
);
1044 static int acm_tty_break_ctl(struct tty_struct
*tty
, int state
)
1046 struct acm
*acm
= tty
->driver_data
;
1049 retval
= acm_send_break(acm
, state
? 0xffff : 0);
1051 dev_dbg(&acm
->control
->dev
, "%s - send break failed\n",
1056 static int acm_tty_tiocmget(struct tty_struct
*tty
)
1058 struct acm
*acm
= tty
->driver_data
;
1060 #ifdef CONFIG_MTK_DT_USB_SUPPORT
1062 dbg_mtk(&acm
->control
->dev
, "tiocmget ctrlin=%x\n", acm
->ctrlin
);
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) |
1073 static int acm_tty_tiocmset(struct tty_struct
*tty
,
1074 unsigned int set
, unsigned int clear
)
1076 struct acm
*acm
= tty
->driver_data
;
1077 unsigned int newctrl
;
1079 #ifdef CONFIG_MTK_DT_USB_SUPPORT
1081 dbg_mtk(&acm
->control
->dev
, "tiocmset ctrlout=%x\n", acm
->ctrlout
);
1084 newctrl
= acm
->ctrlout
;
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);
1090 newctrl
= (newctrl
& ~clear
) | set
;
1092 if (acm
->ctrlout
== newctrl
)
1094 return acm_set_control(acm
, acm
->ctrlout
= newctrl
);
1097 static int get_serial_info(struct acm
*acm
, struct serial_struct __user
*info
)
1099 struct serial_struct tmp
;
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
);
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;
1113 if (copy_to_user(info
, &tmp
, sizeof(tmp
)))
1119 static int set_serial_info(struct acm
*acm
,
1120 struct serial_struct __user
*newinfo
)
1122 struct serial_struct new_serial
;
1123 unsigned int closing_wait
, close_delay
;
1126 if (copy_from_user(&new_serial
, newinfo
, sizeof(new_serial
)))
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;
1133 mutex_lock(&acm
->port
.mutex
);
1135 if (!capable(CAP_SYS_ADMIN
)) {
1136 if ((close_delay
!= acm
->port
.close_delay
) ||
1137 (closing_wait
!= acm
->port
.closing_wait
))
1140 retval
= -EOPNOTSUPP
;
1142 acm
->port
.close_delay
= close_delay
;
1143 acm
->port
.closing_wait
= closing_wait
;
1146 mutex_unlock(&acm
->port
.mutex
);
1150 static int acm_tty_ioctl(struct tty_struct
*tty
,
1151 unsigned int cmd
, unsigned long arg
)
1153 struct acm
*acm
= tty
->driver_data
;
1154 int rv
= -ENOIOCTLCMD
;
1157 case TIOCGSERIAL
: /* gets serial port data */
1158 rv
= get_serial_info(acm
, (struct serial_struct __user
*) arg
);
1161 rv
= set_serial_info(acm
, (struct serial_struct __user
*) arg
);
1168 static void acm_tty_set_termios(struct tty_struct
*tty
,
1169 struct ktermios
*termios_old
)
1171 struct acm
*acm
= tty
->driver_data
;
1172 struct ktermios
*termios
= &tty
->termios
;
1173 struct usb_cdc_line_coding newline
;
1174 int newctrl
= acm
->ctrlout
;
1176 newline
.dwDTERate
= cpu_to_le32(tty_get_baud_rate(tty
));
1177 newline
.bCharFormat
= termios
->c_cflag
& CSTOPB
? 2 : 0;
1178 newline
.bParityType
= termios
->c_cflag
& PARENB
?
1179 (termios
->c_cflag
& PARODD
? 1 : 2) +
1180 (termios
->c_cflag
& CMSPAR
? 2 : 0) : 0;
1181 switch (termios
->c_cflag
& CSIZE
) {
1183 newline
.bDataBits
= 5;
1186 newline
.bDataBits
= 6;
1189 newline
.bDataBits
= 7;
1193 newline
.bDataBits
= 8;
1196 /* FIXME: Needs to clear unsupported bits in the termios */
1197 acm
->clocal
= ((termios
->c_cflag
& CLOCAL
) != 0);
1199 if (C_BAUD(tty
) == B0
) {
1200 newline
.dwDTERate
= acm
->line
.dwDTERate
;
1201 newctrl
&= ~ACM_CTRL_DTR
;
1202 } else if (termios_old
&& (termios_old
->c_cflag
& CBAUD
) == B0
) {
1203 newctrl
|= ACM_CTRL_DTR
;
1206 if (newctrl
!= acm
->ctrlout
)
1207 acm_set_control(acm
, acm
->ctrlout
= newctrl
);
1209 if (memcmp(&acm
->line
, &newline
, sizeof newline
)) {
1210 memcpy(&acm
->line
, &newline
, sizeof newline
);
1211 dev_dbg(&acm
->control
->dev
, "%s - set line: %d %d %d %d\n",
1213 le32_to_cpu(newline
.dwDTERate
),
1214 newline
.bCharFormat
, newline
.bParityType
,
1216 acm_set_line(acm
, &acm
->line
);
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
,
1227 * USB probe and disconnect routines.
1230 /* Little helpers: write/read buffers free */
1231 static void acm_write_buffers_free(struct acm
*acm
)
1235 struct usb_device
*usb_dev
= interface_to_usbdev(acm
->control
);
1237 for (wb
= &acm
->wb
[0], i
= 0; i
< ACM_NW
; i
++, wb
++)
1238 usb_free_coherent(usb_dev
, acm
->writesize
, wb
->buf
, wb
->dmah
);
1241 static void acm_read_buffers_free(struct acm
*acm
)
1243 struct usb_device
*usb_dev
= interface_to_usbdev(acm
->control
);
1246 for (i
= 0; i
< acm
->rx_buflimit
; i
++)
1247 usb_free_coherent(usb_dev
, acm
->readsize
,
1248 acm
->read_buffers
[i
].base
, acm
->read_buffers
[i
].dma
);
1251 /* Little helper: write buffers allocate */
1252 static int acm_write_buffers_alloc(struct acm
*acm
)
1257 for (wb
= &acm
->wb
[0], i
= 0; i
< ACM_NW
; i
++, wb
++) {
1258 wb
->buf
= usb_alloc_coherent(acm
->dev
, acm
->writesize
, GFP_KERNEL
,
1264 usb_free_coherent(acm
->dev
, acm
->writesize
,
1273 static int acm_probe(struct usb_interface
*intf
,
1274 const struct usb_device_id
*id
)
1276 struct usb_cdc_union_desc
*union_header
= NULL
;
1277 struct usb_cdc_country_functional_desc
*cfd
= NULL
;
1278 unsigned char *buffer
= intf
->altsetting
->extra
;
1279 int buflen
= intf
->altsetting
->extralen
;
1280 struct usb_interface
*control_interface
;
1281 struct usb_interface
*data_interface
;
1282 struct usb_endpoint_descriptor
*epctrl
= NULL
;
1283 struct usb_endpoint_descriptor
*epread
= NULL
;
1284 struct usb_endpoint_descriptor
*epwrite
= NULL
;
1285 struct usb_device
*usb_dev
= interface_to_usbdev(intf
);
1288 int ctrlsize
, readsize
;
1290 u8 ac_management_function
= 0;
1291 u8 call_management_function
= 0;
1292 int call_interface_num
= -1;
1293 int data_interface_num
= -1;
1294 unsigned long quirks
;
1297 int combined_interfaces
= 0;
1298 struct device
*tty_dev
;
1302 quirks
= (unsigned long)id
->driver_info
;
1304 if (quirks
== IGNORE_DEVICE
)
1307 num_rx_buf
= (quirks
== SINGLE_RX_URB
) ? 1 : ACM_NR
;
1309 /* handle quirks deadly to normal probing*/
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);
1313 /* we would crash */
1314 if (!data_interface
|| !control_interface
)
1316 goto skip_normal_probe
;
1321 dev_err(&intf
->dev
, "Weird descriptor references\n");
1326 if (intf
->cur_altsetting
->endpoint
&&
1327 intf
->cur_altsetting
->endpoint
->extralen
&&
1328 intf
->cur_altsetting
->endpoint
->extra
) {
1330 "Seeking extra descriptors on endpoint\n");
1331 buflen
= intf
->cur_altsetting
->endpoint
->extralen
;
1332 buffer
= intf
->cur_altsetting
->endpoint
->extra
;
1335 "Zero length descriptor references\n");
1340 while (buflen
> 0) {
1341 if (buffer
[1] != USB_DT_CS_INTERFACE
) {
1342 dev_err(&intf
->dev
, "skipping garbage\n");
1346 switch (buffer
[2]) {
1347 case USB_CDC_UNION_TYPE
: /* we've found it */
1349 dev_err(&intf
->dev
, "More than one "
1350 "union descriptor, skipping ...\n");
1353 union_header
= (struct usb_cdc_union_desc
*)buffer
;
1355 case USB_CDC_COUNTRY_TYPE
: /* export through sysfs*/
1356 cfd
= (struct usb_cdc_country_functional_desc
*)buffer
;
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];
1363 case USB_CDC_CALL_MANAGEMENT_TYPE
:
1364 call_management_function
= buffer
[3];
1365 call_interface_num
= buffer
[4];
1366 if ((quirks
& NOT_A_MODEM
) == 0 && (call_management_function
& 3) != 3)
1367 dev_err(&intf
->dev
, "This device cannot do calls on its own. It is not a modem.\n");
1370 /* there are LOTS more CDC descriptors that
1371 * could legitimately be found here.
1373 dev_dbg(&intf
->dev
, "Ignoring descriptor: "
1374 "type %02x, length %d\n",
1375 buffer
[2], buffer
[0]);
1379 buflen
-= buffer
[0];
1380 buffer
+= buffer
[0];
1383 if (!union_header
) {
1384 if (call_interface_num
> 0) {
1385 dev_dbg(&intf
->dev
, "No union descriptor, using call management descriptor\n");
1386 /* quirks for Droids MuIn LCD */
1387 if (quirks
& NO_DATA_INTERFACE
)
1388 data_interface
= usb_ifnum_to_if(usb_dev
, 0);
1390 data_interface
= usb_ifnum_to_if(usb_dev
, (data_interface_num
= call_interface_num
));
1391 control_interface
= intf
;
1393 if (intf
->cur_altsetting
->desc
.bNumEndpoints
!= 3) {
1394 dev_dbg(&intf
->dev
,"No union descriptor, giving up\n");
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
;
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
));
1408 if (!control_interface
|| !data_interface
) {
1409 dev_dbg(&intf
->dev
, "no interfaces\n");
1413 if (data_interface_num
!= call_interface_num
)
1414 dev_dbg(&intf
->dev
, "Separate call control interface. That is not fully supported.\n");
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");
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
;
1431 if (usb_endpoint_is_int_in(ep
))
1433 else if (usb_endpoint_is_bulk_out(ep
))
1435 else if (usb_endpoint_is_bulk_in(ep
))
1440 if (!epctrl
|| !epread
|| !epwrite
)
1443 goto made_compressed_probe
;
1448 /*workaround for switched interfaces */
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
) {
1453 struct usb_interface
*t
;
1455 "Your device has switched interfaces.\n");
1456 t
= control_interface
;
1457 control_interface
= data_interface
;
1464 /* Accept probe requests only for the control interface */
1465 if (!combined_interfaces
&& intf
!= control_interface
)
1468 if (!combined_interfaces
&& usb_interface_claimed(data_interface
)) {
1469 /* valid in this context */
1470 dev_dbg(&intf
->dev
, "The data interface isn't available\n");
1475 if (data_interface
->cur_altsetting
->desc
.bNumEndpoints
< 2 ||
1476 control_interface
->cur_altsetting
->desc
.bNumEndpoints
== 0)
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
;
1484 /* workaround for switched endpoints */
1485 if (!usb_endpoint_dir_in(epread
)) {
1486 /* descriptors are swapped */
1487 struct usb_endpoint_descriptor
*t
;
1489 "The data interface has switched endpoints\n");
1494 made_compressed_probe
:
1495 dev_dbg(&intf
->dev
, "interfaces are valid\n");
1497 acm
= kzalloc(sizeof(struct acm
), GFP_KERNEL
);
1499 dev_err(&intf
->dev
, "out of memory (acm kzalloc)\n");
1503 minor
= acm_alloc_minor(acm
);
1504 if (minor
== ACM_TTY_MINORS
) {
1505 dev_err(&intf
->dev
, "no more free acm devices\n");
1510 ctrlsize
= usb_endpoint_maxp(epctrl
);
1511 readsize
= usb_endpoint_maxp(epread
) *
1512 (quirks
== SINGLE_RX_URB
? 1 : 2);
1513 acm
->combined_interfaces
= combined_interfaces
;
1514 #ifdef CONFIG_MTK_DT_USB_SUPPORT
1515 acm
->writesize
= ACM_WB_SZ
;
1517 acm
->writesize
= usb_endpoint_maxp(epwrite
) * 20;
1519 acm
->control
= control_interface
;
1520 acm
->data
= data_interface
;
1523 acm
->ctrl_caps
= ac_management_function
;
1524 if (quirks
& NO_CAP_LINE
)
1525 acm
->ctrl_caps
&= ~USB_CDC_CAP_LINE
;
1526 acm
->ctrlsize
= ctrlsize
;
1527 acm
->readsize
= readsize
;
1528 acm
->rx_buflimit
= num_rx_buf
;
1529 INIT_WORK(&acm
->work
, acm_softint
);
1530 spin_lock_init(&acm
->write_lock
);
1531 spin_lock_init(&acm
->read_lock
);
1532 mutex_init(&acm
->mutex
);
1533 acm
->is_int_ep
= usb_endpoint_xfer_int(epread
);
1535 acm
->bInterval
= epread
->bInterval
;
1536 tty_port_init(&acm
->port
);
1537 acm
->port
.ops
= &acm_port_ops
;
1538 init_usb_anchor(&acm
->delayed
);
1540 buf
= usb_alloc_coherent(usb_dev
, ctrlsize
, GFP_KERNEL
, &acm
->ctrl_dma
);
1542 dev_err(&intf
->dev
, "out of memory (ctrl buffer alloc)\n");
1545 acm
->ctrl_buffer
= buf
;
1547 if (acm_write_buffers_alloc(acm
) < 0) {
1548 dev_err(&intf
->dev
, "out of memory (write buffer alloc)\n");
1552 acm
->ctrlurb
= usb_alloc_urb(0, GFP_KERNEL
);
1553 if (!acm
->ctrlurb
) {
1554 dev_err(&intf
->dev
, "out of memory (ctrlurb kmalloc)\n");
1557 for (i
= 0; i
< num_rx_buf
; i
++) {
1558 struct acm_rb
*rb
= &(acm
->read_buffers
[i
]);
1561 rb
->base
= usb_alloc_coherent(acm
->dev
, readsize
, GFP_KERNEL
,
1564 dev_err(&intf
->dev
, "out of memory "
1565 "(read bufs usb_alloc_coherent)\n");
1571 urb
= usb_alloc_urb(0, GFP_KERNEL
);
1574 "out of memory (read urbs usb_alloc_urb)\n");
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
,
1581 usb_rcvintpipe(usb_dev
, epread
->bEndpointAddress
),
1584 acm_read_bulk_callback
, rb
,
1587 usb_fill_bulk_urb(urb
, acm
->dev
,
1588 usb_rcvbulkpipe(usb_dev
, epread
->bEndpointAddress
),
1591 acm_read_bulk_callback
, rb
);
1594 acm
->read_urbs
[i
] = urb
;
1595 __set_bit(i
, &acm
->read_urbs_free
);
1597 for (i
= 0; i
< ACM_NW
; i
++) {
1598 struct acm_wb
*snd
= &(acm
->wb
[i
]);
1600 snd
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
1601 if (snd
->urb
== NULL
) {
1603 "out of memory (write urbs usb_alloc_urb)\n");
1607 if (usb_endpoint_xfer_int(epwrite
))
1608 usb_fill_int_urb(snd
->urb
, usb_dev
,
1609 usb_sndintpipe(usb_dev
, epwrite
->bEndpointAddress
),
1610 NULL
, acm
->writesize
, acm_write_bulk
, snd
, epwrite
->bInterval
);
1612 usb_fill_bulk_urb(snd
->urb
, usb_dev
,
1613 usb_sndbulkpipe(usb_dev
, epwrite
->bEndpointAddress
),
1614 NULL
, acm
->writesize
, acm_write_bulk
, snd
);
1615 snd
->urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1616 snd
->instance
= acm
;
1619 usb_set_intfdata(intf
, acm
);
1621 i
= device_create_file(&intf
->dev
, &dev_attr_bmCapabilities
);
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;
1630 memcpy(acm
->country_codes
, (u8
*)&cfd
->wCountyCode0
,
1632 acm
->country_rel_date
= cfd
->iCountryCodeRelDate
;
1634 i
= device_create_file(&intf
->dev
, &dev_attr_wCountryCodes
);
1636 kfree(acm
->country_codes
);
1637 acm
->country_codes
= NULL
;
1638 acm
->country_code_size
= 0;
1639 goto skip_countries
;
1642 i
= device_create_file(&intf
->dev
,
1643 &dev_attr_iCountryCodeRelDate
);
1645 device_remove_file(&intf
->dev
, &dev_attr_wCountryCodes
);
1646 kfree(acm
->country_codes
);
1647 acm
->country_codes
= NULL
;
1648 acm
->country_code_size
= 0;
1649 goto skip_countries
;
1654 usb_fill_int_urb(acm
->ctrlurb
, usb_dev
,
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);
1659 acm
->ctrlurb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1660 acm
->ctrlurb
->transfer_dma
= acm
->ctrl_dma
;
1662 dev_info(&intf
->dev
, "ttyACM%d: USB ACM device\n", minor
);
1664 acm_set_control(acm
, acm
->ctrlout
);
1666 acm
->line
.dwDTERate
= cpu_to_le32(9600);
1667 acm
->line
.bDataBits
= 8;
1668 acm_set_line(acm
, &acm
->line
);
1670 usb_driver_claim_interface(&acm_driver
, data_interface
, acm
);
1671 usb_set_intfdata(data_interface
, acm
);
1673 usb_get_intf(control_interface
);
1674 tty_dev
= tty_port_register_device(&acm
->port
, acm_tty_driver
, minor
,
1675 &control_interface
->dev
);
1676 if (IS_ERR(tty_dev
)) {
1677 rv
= PTR_ERR(tty_dev
);
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
);
1688 kfree(acm
->country_codes
);
1690 device_remove_file(&acm
->control
->dev
, &dev_attr_bmCapabilities
);
1692 usb_set_intfdata(intf
, NULL
);
1693 for (i
= 0; i
< ACM_NW
; i
++)
1694 usb_free_urb(acm
->wb
[i
].urb
);
1696 for (i
= 0; i
< num_rx_buf
; i
++)
1697 usb_free_urb(acm
->read_urbs
[i
]);
1698 acm_read_buffers_free(acm
);
1699 usb_free_urb(acm
->ctrlurb
);
1701 acm_write_buffers_free(acm
);
1703 usb_free_coherent(usb_dev
, ctrlsize
, acm
->ctrl_buffer
, acm
->ctrl_dma
);
1705 acm_release_minor(acm
);
1711 static void stop_data_traffic(struct acm
*acm
)
1715 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
1717 usb_kill_urb(acm
->ctrlurb
);
1718 for (i
= 0; i
< ACM_NW
; i
++)
1719 usb_kill_urb(acm
->wb
[i
].urb
);
1720 for (i
= 0; i
< acm
->rx_buflimit
; i
++)
1721 usb_kill_urb(acm
->read_urbs
[i
]);
1723 cancel_work_sync(&acm
->work
);
1726 static void acm_disconnect(struct usb_interface
*intf
)
1728 struct acm
*acm
= usb_get_intfdata(intf
);
1729 struct usb_device
*usb_dev
= interface_to_usbdev(intf
);
1730 struct tty_struct
*tty
;
1733 dev_dbg(&intf
->dev
, "%s\n", __func__
);
1735 /* sibling interface is already cleaning up */
1739 mutex_lock(&acm
->mutex
);
1740 acm
->disconnected
= true;
1741 if (acm
->country_codes
) {
1742 device_remove_file(&acm
->control
->dev
,
1743 &dev_attr_wCountryCodes
);
1744 device_remove_file(&acm
->control
->dev
,
1745 &dev_attr_iCountryCodeRelDate
);
1747 device_remove_file(&acm
->control
->dev
, &dev_attr_bmCapabilities
);
1748 usb_set_intfdata(acm
->control
, NULL
);
1749 usb_set_intfdata(acm
->data
, NULL
);
1750 mutex_unlock(&acm
->mutex
);
1752 tty
= tty_port_tty_get(&acm
->port
);
1758 stop_data_traffic(acm
);
1760 tty_unregister_device(acm_tty_driver
, acm
->minor
);
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
]);
1767 acm_write_buffers_free(acm
);
1768 usb_free_coherent(usb_dev
, acm
->ctrlsize
, acm
->ctrl_buffer
, acm
->ctrl_dma
);
1769 acm_read_buffers_free(acm
);
1771 if (!acm
->combined_interfaces
)
1772 usb_driver_release_interface(&acm_driver
, intf
== acm
->control
?
1773 acm
->data
: acm
->control
);
1775 tty_port_put(&acm
->port
);
1779 static int acm_suspend(struct usb_interface
*intf
, pm_message_t message
)
1781 struct acm
*acm
= usb_get_intfdata(intf
);
1784 dbg_mtk(&acm
->control
->dev
, "%s intf=%d", __func__
, intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1785 spin_lock_irq(&acm
->read_lock
);
1786 spin_lock(&acm
->write_lock
);
1787 if (PMSG_IS_AUTO(message
)) {
1788 if (acm
->transmitting
) {
1789 spin_unlock(&acm
->write_lock
);
1790 spin_unlock_irq(&acm
->read_lock
);
1795 for (i
= 0; i
< ACM_NW
; i
++){
1797 spin_unlock(&acm
->write_lock
);
1798 spin_unlock_irq(&acm
->read_lock
);
1804 cnt
= acm
->susp_count
++;
1805 spin_unlock(&acm
->write_lock
);
1806 spin_unlock_irq(&acm
->read_lock
);
1811 stop_data_traffic(acm
);
1816 static int acm_resume(struct usb_interface
*intf
)
1818 struct acm
*acm
= usb_get_intfdata(intf
);
1822 dbg_mtk(&acm
->control
->dev
, "%s intf=%d", __func__
, intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1824 spin_lock_irq(&acm
->read_lock
);
1825 spin_lock(&acm
->write_lock
);
1827 if (--acm
->susp_count
)
1830 if (test_bit(ASYNCB_INITIALIZED
, &acm
->port
.flags
)) {
1831 rv
= usb_submit_urb(acm
->ctrlurb
, GFP_ATOMIC
);
1834 urb
= usb_get_from_anchor(&acm
->delayed
);
1838 acm_start_wb(acm
, urb
->context
);
1842 * delayed error checking because we must
1843 * do the write path at all cost
1846 MYDBG("urb fail:%d\n", rv
);
1850 rv
= acm_submit_read_urbs(acm
, GFP_ATOMIC
);
1853 spin_unlock(&acm
->write_lock
);
1854 spin_unlock_irq(&acm
->read_lock
);
1859 static int acm_reset_resume(struct usb_interface
*intf
)
1861 struct acm
*acm
= usb_get_intfdata(intf
);
1863 if (test_bit(ASYNCB_INITIALIZED
, &acm
->port
.flags
))
1864 tty_port_tty_hangup(&acm
->port
, false);
1866 return acm_resume(intf
);
1869 #endif /* CONFIG_PM */
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)
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)
1882 * USB driver structure.
1885 static const struct usb_device_id acm_ids
[] = {
1886 /* quirky and broken devices */
1887 { USB_DEVICE(0x17ef, 0x7000), /* Lenovo USB modem */
1888 .driver_info
= NO_UNION_NORMAL
, },/* has no union descriptor */
1889 { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */
1890 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1892 { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */
1893 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1895 { USB_DEVICE(0x0e8d, 0x3329), /* MediaTek Inc GPS */
1896 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1898 { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */
1899 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1901 { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */
1902 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1904 { USB_DEVICE(0x0ace, 0x1602), /* ZyDAS 56K USB MODEM */
1905 .driver_info
= SINGLE_RX_URB
,
1907 { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */
1908 .driver_info
= SINGLE_RX_URB
, /* firmware bug */
1910 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
1911 .driver_info
= SINGLE_RX_URB
, /* firmware bug */
1913 { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
1914 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1916 { USB_DEVICE(0x0803, 0x3095), /* Zoom Telephonics Model 3095F USB MODEM */
1917 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1919 { USB_DEVICE(0x0572, 0x1321), /* Conexant USB MODEM CX93010 */
1920 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1922 { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */
1923 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1925 { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */
1926 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1928 { USB_DEVICE(0x2184, 0x001c) }, /* GW Instek AFG-2225 */
1929 { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */
1931 /* Motorola H24 HSPA module: */
1932 { USB_DEVICE(0x22b8, 0x2d91) }, /* modem */
1933 { USB_DEVICE(0x22b8, 0x2d92), /* modem + diagnostics */
1934 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1936 { USB_DEVICE(0x22b8, 0x2d93), /* modem + AT port */
1937 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1939 { USB_DEVICE(0x22b8, 0x2d95), /* modem + AT port + diagnostics */
1940 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1942 { USB_DEVICE(0x22b8, 0x2d96), /* modem + NMEA */
1943 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1945 { USB_DEVICE(0x22b8, 0x2d97), /* modem + diagnostics + NMEA */
1946 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1948 { USB_DEVICE(0x22b8, 0x2d99), /* modem + AT port + NMEA */
1949 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1951 { USB_DEVICE(0x22b8, 0x2d9a), /* modem + AT port + diagnostics + NMEA */
1952 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
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
1962 { USB_DEVICE(0x0572, 0x1340), /* Conexant CX93010-2x UCMxx */
1963 .driver_info
= NO_UNION_NORMAL
,
1965 { USB_DEVICE(0x05f9, 0x4002), /* PSC Scanning, Magellan 800i */
1966 .driver_info
= NO_UNION_NORMAL
,
1968 { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */
1969 .driver_info
= NO_UNION_NORMAL
, /* reports zero length descriptor */
1971 { USB_DEVICE(0x1576, 0x03b1), /* Maretron USB100 */
1972 .driver_info
= NO_UNION_NORMAL
, /* reports zero length descriptor */
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 */
2023 { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */
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 */
2034 { NOKIA_PCSUITE_ACM_INFO(0x0302), }, /* Nokia N8 */
2035 { NOKIA_PCSUITE_ACM_INFO(0x0335), }, /* Nokia E7 */
2036 { NOKIA_PCSUITE_ACM_INFO(0x03cd), }, /* Nokia C7 */
2037 { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */
2039 /* Support for Owen devices */
2040 { USB_DEVICE(0x03eb, 0x0030), }, /* Owen SI30 */
2042 /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */
2044 /* Support Lego NXT using pbLua firmware */
2045 { USB_DEVICE(0x0694, 0xff00),
2046 .driver_info
= NOT_A_MODEM
,
2049 /* Support for Droids MuIn LCD */
2050 { USB_DEVICE(0x04d8, 0x000b),
2051 .driver_info
= NO_DATA_INTERFACE
,
2054 #if IS_ENABLED(CONFIG_INPUT_IMS_PCU)
2055 { USB_DEVICE(0x04d8, 0x0082), /* Application mode */
2056 .driver_info
= IGNORE_DEVICE
,
2058 { USB_DEVICE(0x04d8, 0x0083), /* Bootloader mode */
2059 .driver_info
= IGNORE_DEVICE
,
2063 /*Samsung phone in firmware update mode */
2064 { USB_DEVICE(0x04e8, 0x685d),
2065 .driver_info
= IGNORE_DEVICE
,
2068 /* Exclude Infineon Flash Loader utility */
2069 { USB_DEVICE(0x058b, 0x0041),
2070 .driver_info
= IGNORE_DEVICE
,
2073 /* control interfaces without any protocol set */
2074 { USB_INTERFACE_INFO(USB_CLASS_COMM
, USB_CDC_SUBCLASS_ACM
,
2075 USB_CDC_PROTO_NONE
) },
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
,
2087 USB_CDC_ACM_PROTO_AT_3G
) },
2088 { USB_INTERFACE_INFO(USB_CLASS_COMM
, USB_CDC_SUBCLASS_ACM
,
2089 USB_CDC_ACM_PROTO_AT_CDMA
) },
2094 MODULE_DEVICE_TABLE(usb
, acm_ids
);
2096 static struct usb_driver acm_driver
= {
2099 .disconnect
= acm_disconnect
,
2101 .suspend
= acm_suspend
,
2102 .resume
= acm_resume
,
2103 .reset_resume
= acm_reset_resume
,
2105 .id_table
= acm_ids
,
2107 .supports_autosuspend
= 1,
2109 .disable_hub_initiated_lpm
= 1,
2113 * TTY driver structures.
2116 static const struct tty_operations acm_ops
= {
2117 .install
= acm_tty_install
,
2118 .open
= acm_tty_open
,
2119 .close
= acm_tty_close
,
2120 .cleanup
= acm_tty_cleanup
,
2121 .hangup
= acm_tty_hangup
,
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
,
2138 static int __init
acm_init(void)
2141 #ifdef CONFIG_MTK_DT_USB_SUPPORT
2144 acm_tty_driver
= alloc_tty_driver(ACM_TTY_MINORS
);
2145 if (!acm_tty_driver
)
2147 acm_tty_driver
->driver_name
= "acm",
2148 acm_tty_driver
->name
= "ttyACM",
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
,
2153 acm_tty_driver
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
;
2154 acm_tty_driver
->init_termios
= tty_std_termios
;
2155 acm_tty_driver
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
|
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.
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
;
2170 tty_set_operations(acm_tty_driver
, &acm_ops
);
2172 retval
= tty_register_driver(acm_tty_driver
);
2174 put_tty_driver(acm_tty_driver
);
2178 retval
= usb_register(&acm_driver
);
2180 tty_unregister_driver(acm_tty_driver
);
2181 put_tty_driver(acm_tty_driver
);
2185 printk(KERN_INFO KBUILD_MODNAME
": " DRIVER_DESC
"\n");
2190 static void __exit
acm_exit(void)
2192 usb_deregister(&acm_driver
);
2193 tty_unregister_driver(acm_tty_driver
);
2194 put_tty_driver(acm_tty_driver
);
2197 module_init(acm_init
);
2198 module_exit(acm_exit
);
2199 #ifdef CONFIG_MTK_DT_USB_SUPPORT
2200 module_param(enable_debug
, int, 0644);
2201 module_param(enable_dump
, int, 0644);
2204 MODULE_AUTHOR(DRIVER_AUTHOR
);
2205 MODULE_DESCRIPTION(DRIVER_DESC
);
2206 MODULE_LICENSE("GPL");
2207 MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR
);