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 if (usb_submit_urb(acm
->ctrlurb
, GFP_KERNEL
)) {
827 dev_err(&acm
->control
->dev
,
828 "%s - usb_submit_urb(ctrl irq) failed\n", __func__
);
829 goto error_submit_urb
;
832 acm
->ctrlout
= ACM_CTRL_DTR
| ACM_CTRL_RTS
;
833 if (acm_set_control(acm
, acm
->ctrlout
) < 0 &&
834 (acm
->ctrl_caps
& USB_CDC_CAP_LINE
))
835 goto error_set_control
;
837 usb_autopm_put_interface(acm
->control
);
840 * Unthrottle device in case the TTY was closed while throttled.
842 spin_lock_irq(&acm
->read_lock
);
844 acm
->throttle_req
= 0;
845 spin_unlock_irq(&acm
->read_lock
);
847 if (acm_submit_read_urbs(acm
, GFP_KERNEL
))
848 goto error_submit_read_urbs
;
850 mutex_unlock(&acm
->mutex
);
854 error_submit_read_urbs
:
855 for (i
= 0; i
< acm
->rx_buflimit
; i
++)
856 usb_kill_urb(acm
->read_urbs
[i
]);
858 acm_set_control(acm
, acm
->ctrlout
);
860 usb_kill_urb(acm
->ctrlurb
);
862 usb_autopm_put_interface(acm
->control
);
865 mutex_unlock(&acm
->mutex
);
869 static void acm_port_destruct(struct tty_port
*port
)
871 struct acm
*acm
= container_of(port
, struct acm
, port
);
873 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
875 acm_release_minor(acm
);
876 usb_put_intf(acm
->control
);
877 kfree(acm
->country_codes
);
881 static void acm_port_shutdown(struct tty_port
*port
)
883 struct acm
*acm
= container_of(port
, struct acm
, port
);
889 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
891 mutex_lock(&acm
->mutex
);
892 if (!acm
->disconnected
) {
893 pm_err
= usb_autopm_get_interface(acm
->control
);
894 acm_set_control(acm
, acm
->ctrlout
= 0);
897 urb
= usb_get_from_anchor(&acm
->delayed
);
902 usb_autopm_put_interface_async(acm
->control
);
905 usb_kill_urb(acm
->ctrlurb
);
906 for (i
= 0; i
< ACM_NW
; i
++)
907 usb_kill_urb(acm
->wb
[i
].urb
);
908 for (i
= 0; i
< acm
->rx_buflimit
; i
++)
909 usb_kill_urb(acm
->read_urbs
[i
]);
910 acm
->control
->needs_remote_wakeup
= 0;
912 usb_autopm_put_interface(acm
->control
);
914 mutex_unlock(&acm
->mutex
);
917 static void acm_tty_cleanup(struct tty_struct
*tty
)
919 struct acm
*acm
= tty
->driver_data
;
920 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
921 tty_port_put(&acm
->port
);
924 static void acm_tty_hangup(struct tty_struct
*tty
)
926 struct acm
*acm
= tty
->driver_data
;
927 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
928 tty_port_hangup(&acm
->port
);
931 static void acm_tty_close(struct tty_struct
*tty
, struct file
*filp
)
933 struct acm
*acm
= tty
->driver_data
;
934 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
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
)){
942 tty_port_close(&acm
->port
, tty
, filp
);
945 static int acm_tty_write(struct tty_struct
*tty
,
946 const unsigned char *buf
, int count
)
948 struct acm
*acm
= tty
->driver_data
;
953 #ifdef CONFIG_MTK_DT_USB_SUPPORT
960 dev_vdbg(&acm
->data
->dev
, "%s - count %d\n", __func__
, count
);
962 #ifdef CONFIG_MTK_DT_USB_SUPPORT
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
));
968 sprintf(data_out
+len
, "\n");
969 dbg_mtk(&acm
->data
->dev
, "%s", data_out
);
972 spin_lock_irqsave(&acm
->write_lock
, flags
);
973 wbn
= acm_wb_alloc(acm
);
975 spin_unlock_irqrestore(&acm
->write_lock
, flags
);
980 count
= (count
> acm
->writesize
) ? acm
->writesize
: count
;
981 dev_vdbg(&acm
->data
->dev
, "%s - write %d\n", __func__
, count
);
982 memcpy(wb
->buf
, buf
, count
);
984 spin_unlock_irqrestore(&acm
->write_lock
, flags
);
986 stat
= acm_write_start(acm
, wbn
);
992 static int acm_tty_write_room(struct tty_struct
*tty
)
994 struct acm
*acm
= tty
->driver_data
;
996 * Do not let the line discipline to know that we have a reserve,
997 * or it might get too enthusiastic.
999 return acm_wb_is_avail(acm
) ? acm
->writesize
: 0;
1002 static int acm_tty_chars_in_buffer(struct tty_struct
*tty
)
1004 struct acm
*acm
= tty
->driver_data
;
1006 * if the device was unplugged then any remaining characters fell out
1007 * of the connector ;)
1009 if (acm
->disconnected
)
1012 * This is inaccurate (overcounts), but it works.
1014 return (ACM_NW
- acm_wb_is_avail(acm
)) * acm
->writesize
;
1017 static void acm_tty_throttle(struct tty_struct
*tty
)
1019 struct acm
*acm
= tty
->driver_data
;
1021 spin_lock_irq(&acm
->read_lock
);
1022 acm
->throttle_req
= 1;
1023 spin_unlock_irq(&acm
->read_lock
);
1026 static void acm_tty_unthrottle(struct tty_struct
*tty
)
1028 struct acm
*acm
= tty
->driver_data
;
1029 unsigned int was_throttled
;
1031 spin_lock_irq(&acm
->read_lock
);
1032 was_throttled
= acm
->throttled
;
1034 acm
->throttle_req
= 0;
1035 spin_unlock_irq(&acm
->read_lock
);
1038 acm_submit_read_urbs(acm
, GFP_KERNEL
);
1041 static int acm_tty_break_ctl(struct tty_struct
*tty
, int state
)
1043 struct acm
*acm
= tty
->driver_data
;
1046 retval
= acm_send_break(acm
, state
? 0xffff : 0);
1048 dev_dbg(&acm
->control
->dev
, "%s - send break failed\n",
1053 static int acm_tty_tiocmget(struct tty_struct
*tty
)
1055 struct acm
*acm
= tty
->driver_data
;
1057 #ifdef CONFIG_MTK_DT_USB_SUPPORT
1059 dbg_mtk(&acm
->control
->dev
, "tiocmget ctrlin=%x\n", acm
->ctrlin
);
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) |
1070 static int acm_tty_tiocmset(struct tty_struct
*tty
,
1071 unsigned int set
, unsigned int clear
)
1073 struct acm
*acm
= tty
->driver_data
;
1074 unsigned int newctrl
;
1076 #ifdef CONFIG_MTK_DT_USB_SUPPORT
1078 dbg_mtk(&acm
->control
->dev
, "tiocmset ctrlout=%x\n", acm
->ctrlout
);
1081 newctrl
= acm
->ctrlout
;
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);
1087 newctrl
= (newctrl
& ~clear
) | set
;
1089 if (acm
->ctrlout
== newctrl
)
1091 return acm_set_control(acm
, acm
->ctrlout
= newctrl
);
1094 static int get_serial_info(struct acm
*acm
, struct serial_struct __user
*info
)
1096 struct serial_struct tmp
;
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
);
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;
1110 if (copy_to_user(info
, &tmp
, sizeof(tmp
)))
1116 static int set_serial_info(struct acm
*acm
,
1117 struct serial_struct __user
*newinfo
)
1119 struct serial_struct new_serial
;
1120 unsigned int closing_wait
, close_delay
;
1123 if (copy_from_user(&new_serial
, newinfo
, sizeof(new_serial
)))
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;
1130 mutex_lock(&acm
->port
.mutex
);
1132 if (!capable(CAP_SYS_ADMIN
)) {
1133 if ((close_delay
!= acm
->port
.close_delay
) ||
1134 (closing_wait
!= acm
->port
.closing_wait
))
1137 retval
= -EOPNOTSUPP
;
1139 acm
->port
.close_delay
= close_delay
;
1140 acm
->port
.closing_wait
= closing_wait
;
1143 mutex_unlock(&acm
->port
.mutex
);
1147 static int acm_tty_ioctl(struct tty_struct
*tty
,
1148 unsigned int cmd
, unsigned long arg
)
1150 struct acm
*acm
= tty
->driver_data
;
1151 int rv
= -ENOIOCTLCMD
;
1154 case TIOCGSERIAL
: /* gets serial port data */
1155 rv
= get_serial_info(acm
, (struct serial_struct __user
*) arg
);
1158 rv
= set_serial_info(acm
, (struct serial_struct __user
*) arg
);
1165 static void acm_tty_set_termios(struct tty_struct
*tty
,
1166 struct ktermios
*termios_old
)
1168 struct acm
*acm
= tty
->driver_data
;
1169 struct ktermios
*termios
= &tty
->termios
;
1170 struct usb_cdc_line_coding newline
;
1171 int newctrl
= acm
->ctrlout
;
1173 newline
.dwDTERate
= cpu_to_le32(tty_get_baud_rate(tty
));
1174 newline
.bCharFormat
= termios
->c_cflag
& CSTOPB
? 2 : 0;
1175 newline
.bParityType
= termios
->c_cflag
& PARENB
?
1176 (termios
->c_cflag
& PARODD
? 1 : 2) +
1177 (termios
->c_cflag
& CMSPAR
? 2 : 0) : 0;
1178 switch (termios
->c_cflag
& CSIZE
) {
1180 newline
.bDataBits
= 5;
1183 newline
.bDataBits
= 6;
1186 newline
.bDataBits
= 7;
1190 newline
.bDataBits
= 8;
1193 /* FIXME: Needs to clear unsupported bits in the termios */
1194 acm
->clocal
= ((termios
->c_cflag
& CLOCAL
) != 0);
1196 if (C_BAUD(tty
) == B0
) {
1197 newline
.dwDTERate
= acm
->line
.dwDTERate
;
1198 newctrl
&= ~ACM_CTRL_DTR
;
1199 } else if (termios_old
&& (termios_old
->c_cflag
& CBAUD
) == B0
) {
1200 newctrl
|= ACM_CTRL_DTR
;
1203 if (newctrl
!= acm
->ctrlout
)
1204 acm_set_control(acm
, acm
->ctrlout
= newctrl
);
1206 if (memcmp(&acm
->line
, &newline
, sizeof newline
)) {
1207 memcpy(&acm
->line
, &newline
, sizeof newline
);
1208 dev_dbg(&acm
->control
->dev
, "%s - set line: %d %d %d %d\n",
1210 le32_to_cpu(newline
.dwDTERate
),
1211 newline
.bCharFormat
, newline
.bParityType
,
1213 acm_set_line(acm
, &acm
->line
);
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
,
1224 * USB probe and disconnect routines.
1227 /* Little helpers: write/read buffers free */
1228 static void acm_write_buffers_free(struct acm
*acm
)
1232 struct usb_device
*usb_dev
= interface_to_usbdev(acm
->control
);
1234 for (wb
= &acm
->wb
[0], i
= 0; i
< ACM_NW
; i
++, wb
++)
1235 usb_free_coherent(usb_dev
, acm
->writesize
, wb
->buf
, wb
->dmah
);
1238 static void acm_read_buffers_free(struct acm
*acm
)
1240 struct usb_device
*usb_dev
= interface_to_usbdev(acm
->control
);
1243 for (i
= 0; i
< acm
->rx_buflimit
; i
++)
1244 usb_free_coherent(usb_dev
, acm
->readsize
,
1245 acm
->read_buffers
[i
].base
, acm
->read_buffers
[i
].dma
);
1248 /* Little helper: write buffers allocate */
1249 static int acm_write_buffers_alloc(struct acm
*acm
)
1254 for (wb
= &acm
->wb
[0], i
= 0; i
< ACM_NW
; i
++, wb
++) {
1255 wb
->buf
= usb_alloc_coherent(acm
->dev
, acm
->writesize
, GFP_KERNEL
,
1261 usb_free_coherent(acm
->dev
, acm
->writesize
,
1270 static int acm_probe(struct usb_interface
*intf
,
1271 const struct usb_device_id
*id
)
1273 struct usb_cdc_union_desc
*union_header
= NULL
;
1274 struct usb_cdc_country_functional_desc
*cfd
= NULL
;
1275 unsigned char *buffer
= intf
->altsetting
->extra
;
1276 int buflen
= intf
->altsetting
->extralen
;
1277 struct usb_interface
*control_interface
;
1278 struct usb_interface
*data_interface
;
1279 struct usb_endpoint_descriptor
*epctrl
= NULL
;
1280 struct usb_endpoint_descriptor
*epread
= NULL
;
1281 struct usb_endpoint_descriptor
*epwrite
= NULL
;
1282 struct usb_device
*usb_dev
= interface_to_usbdev(intf
);
1285 int ctrlsize
, readsize
;
1287 u8 ac_management_function
= 0;
1288 u8 call_management_function
= 0;
1289 int call_interface_num
= -1;
1290 int data_interface_num
= -1;
1291 unsigned long quirks
;
1294 int combined_interfaces
= 0;
1295 struct device
*tty_dev
;
1299 quirks
= (unsigned long)id
->driver_info
;
1301 if (quirks
== IGNORE_DEVICE
)
1304 num_rx_buf
= (quirks
== SINGLE_RX_URB
) ? 1 : ACM_NR
;
1306 /* handle quirks deadly to normal probing*/
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
;
1315 dev_err(&intf
->dev
, "Weird descriptor references\n");
1320 if (intf
->cur_altsetting
->endpoint
&&
1321 intf
->cur_altsetting
->endpoint
->extralen
&&
1322 intf
->cur_altsetting
->endpoint
->extra
) {
1324 "Seeking extra descriptors on endpoint\n");
1325 buflen
= intf
->cur_altsetting
->endpoint
->extralen
;
1326 buffer
= intf
->cur_altsetting
->endpoint
->extra
;
1329 "Zero length descriptor references\n");
1334 while (buflen
> 0) {
1335 if (buffer
[1] != USB_DT_CS_INTERFACE
) {
1336 dev_err(&intf
->dev
, "skipping garbage\n");
1340 switch (buffer
[2]) {
1341 case USB_CDC_UNION_TYPE
: /* we've found it */
1343 dev_err(&intf
->dev
, "More than one "
1344 "union descriptor, skipping ...\n");
1347 union_header
= (struct usb_cdc_union_desc
*)buffer
;
1349 case USB_CDC_COUNTRY_TYPE
: /* export through sysfs*/
1350 cfd
= (struct usb_cdc_country_functional_desc
*)buffer
;
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];
1357 case USB_CDC_CALL_MANAGEMENT_TYPE
:
1358 call_management_function
= buffer
[3];
1359 call_interface_num
= buffer
[4];
1360 if ((quirks
& NOT_A_MODEM
) == 0 && (call_management_function
& 3) != 3)
1361 dev_err(&intf
->dev
, "This device cannot do calls on its own. It is not a modem.\n");
1364 /* there are LOTS more CDC descriptors that
1365 * could legitimately be found here.
1367 dev_dbg(&intf
->dev
, "Ignoring descriptor: "
1368 "type %02x, length %d\n",
1369 buffer
[2], buffer
[0]);
1373 buflen
-= buffer
[0];
1374 buffer
+= buffer
[0];
1377 if (!union_header
) {
1378 if (call_interface_num
> 0) {
1379 dev_dbg(&intf
->dev
, "No union descriptor, using call management descriptor\n");
1380 /* quirks for Droids MuIn LCD */
1381 if (quirks
& NO_DATA_INTERFACE
)
1382 data_interface
= usb_ifnum_to_if(usb_dev
, 0);
1384 data_interface
= usb_ifnum_to_if(usb_dev
, (data_interface_num
= call_interface_num
));
1385 control_interface
= intf
;
1387 if (intf
->cur_altsetting
->desc
.bNumEndpoints
!= 3) {
1388 dev_dbg(&intf
->dev
,"No union descriptor, giving up\n");
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
;
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
));
1402 if (!control_interface
|| !data_interface
) {
1403 dev_dbg(&intf
->dev
, "no interfaces\n");
1407 if (data_interface_num
!= call_interface_num
)
1408 dev_dbg(&intf
->dev
, "Separate call control interface. That is not fully supported.\n");
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");
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
;
1425 if (usb_endpoint_is_int_in(ep
))
1427 else if (usb_endpoint_is_bulk_out(ep
))
1429 else if (usb_endpoint_is_bulk_in(ep
))
1434 if (!epctrl
|| !epread
|| !epwrite
)
1437 goto made_compressed_probe
;
1442 /*workaround for switched interfaces */
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
) {
1447 struct usb_interface
*t
;
1449 "Your device has switched interfaces.\n");
1450 t
= control_interface
;
1451 control_interface
= data_interface
;
1458 /* Accept probe requests only for the control interface */
1459 if (!combined_interfaces
&& intf
!= control_interface
)
1462 if (!combined_interfaces
&& usb_interface_claimed(data_interface
)) {
1463 /* valid in this context */
1464 dev_dbg(&intf
->dev
, "The data interface isn't available\n");
1469 if (data_interface
->cur_altsetting
->desc
.bNumEndpoints
< 2 ||
1470 control_interface
->cur_altsetting
->desc
.bNumEndpoints
== 0)
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
;
1478 /* workaround for switched endpoints */
1479 if (!usb_endpoint_dir_in(epread
)) {
1480 /* descriptors are swapped */
1481 struct usb_endpoint_descriptor
*t
;
1483 "The data interface has switched endpoints\n");
1488 made_compressed_probe
:
1489 dev_dbg(&intf
->dev
, "interfaces are valid\n");
1491 acm
= kzalloc(sizeof(struct acm
), GFP_KERNEL
);
1493 dev_err(&intf
->dev
, "out of memory (acm kzalloc)\n");
1497 minor
= acm_alloc_minor(acm
);
1498 if (minor
== ACM_TTY_MINORS
) {
1499 dev_err(&intf
->dev
, "no more free acm devices\n");
1504 ctrlsize
= usb_endpoint_maxp(epctrl
);
1505 readsize
= usb_endpoint_maxp(epread
) *
1506 (quirks
== SINGLE_RX_URB
? 1 : 2);
1507 acm
->combined_interfaces
= combined_interfaces
;
1508 #ifdef CONFIG_MTK_DT_USB_SUPPORT
1509 acm
->writesize
= ACM_WB_SZ
;
1511 acm
->writesize
= usb_endpoint_maxp(epwrite
) * 20;
1513 acm
->control
= control_interface
;
1514 acm
->data
= data_interface
;
1517 acm
->ctrl_caps
= ac_management_function
;
1518 if (quirks
& NO_CAP_LINE
)
1519 acm
->ctrl_caps
&= ~USB_CDC_CAP_LINE
;
1520 acm
->ctrlsize
= ctrlsize
;
1521 acm
->readsize
= readsize
;
1522 acm
->rx_buflimit
= num_rx_buf
;
1523 INIT_WORK(&acm
->work
, acm_softint
);
1524 spin_lock_init(&acm
->write_lock
);
1525 spin_lock_init(&acm
->read_lock
);
1526 mutex_init(&acm
->mutex
);
1527 acm
->rx_endpoint
= usb_rcvbulkpipe(usb_dev
, epread
->bEndpointAddress
);
1528 acm
->is_int_ep
= usb_endpoint_xfer_int(epread
);
1530 acm
->bInterval
= epread
->bInterval
;
1531 tty_port_init(&acm
->port
);
1532 acm
->port
.ops
= &acm_port_ops
;
1533 init_usb_anchor(&acm
->delayed
);
1535 buf
= usb_alloc_coherent(usb_dev
, ctrlsize
, GFP_KERNEL
, &acm
->ctrl_dma
);
1537 dev_err(&intf
->dev
, "out of memory (ctrl buffer alloc)\n");
1540 acm
->ctrl_buffer
= buf
;
1542 if (acm_write_buffers_alloc(acm
) < 0) {
1543 dev_err(&intf
->dev
, "out of memory (write buffer alloc)\n");
1547 acm
->ctrlurb
= usb_alloc_urb(0, GFP_KERNEL
);
1548 if (!acm
->ctrlurb
) {
1549 dev_err(&intf
->dev
, "out of memory (ctrlurb kmalloc)\n");
1552 for (i
= 0; i
< num_rx_buf
; i
++) {
1553 struct acm_rb
*rb
= &(acm
->read_buffers
[i
]);
1556 rb
->base
= usb_alloc_coherent(acm
->dev
, readsize
, GFP_KERNEL
,
1559 dev_err(&intf
->dev
, "out of memory "
1560 "(read bufs usb_alloc_coherent)\n");
1566 urb
= usb_alloc_urb(0, GFP_KERNEL
);
1569 "out of memory (read urbs usb_alloc_urb)\n");
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
,
1579 acm_read_bulk_callback
, rb
,
1582 usb_fill_bulk_urb(urb
, acm
->dev
,
1586 acm_read_bulk_callback
, rb
);
1589 acm
->read_urbs
[i
] = urb
;
1590 __set_bit(i
, &acm
->read_urbs_free
);
1592 for (i
= 0; i
< ACM_NW
; i
++) {
1593 struct acm_wb
*snd
= &(acm
->wb
[i
]);
1595 snd
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
1596 if (snd
->urb
== NULL
) {
1598 "out of memory (write urbs usb_alloc_urb)\n");
1602 if (usb_endpoint_xfer_int(epwrite
))
1603 usb_fill_int_urb(snd
->urb
, usb_dev
,
1604 usb_sndintpipe(usb_dev
, epwrite
->bEndpointAddress
),
1605 NULL
, acm
->writesize
, acm_write_bulk
, snd
, epwrite
->bInterval
);
1607 usb_fill_bulk_urb(snd
->urb
, usb_dev
,
1608 usb_sndbulkpipe(usb_dev
, epwrite
->bEndpointAddress
),
1609 NULL
, acm
->writesize
, acm_write_bulk
, snd
);
1610 snd
->urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1611 snd
->instance
= acm
;
1614 usb_set_intfdata(intf
, acm
);
1616 i
= device_create_file(&intf
->dev
, &dev_attr_bmCapabilities
);
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;
1625 memcpy(acm
->country_codes
, (u8
*)&cfd
->wCountyCode0
,
1627 acm
->country_rel_date
= cfd
->iCountryCodeRelDate
;
1629 i
= device_create_file(&intf
->dev
, &dev_attr_wCountryCodes
);
1631 kfree(acm
->country_codes
);
1632 acm
->country_codes
= NULL
;
1633 acm
->country_code_size
= 0;
1634 goto skip_countries
;
1637 i
= device_create_file(&intf
->dev
,
1638 &dev_attr_iCountryCodeRelDate
);
1640 device_remove_file(&intf
->dev
, &dev_attr_wCountryCodes
);
1641 kfree(acm
->country_codes
);
1642 acm
->country_codes
= NULL
;
1643 acm
->country_code_size
= 0;
1644 goto skip_countries
;
1649 usb_fill_int_urb(acm
->ctrlurb
, usb_dev
,
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);
1654 acm
->ctrlurb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1655 acm
->ctrlurb
->transfer_dma
= acm
->ctrl_dma
;
1657 dev_info(&intf
->dev
, "ttyACM%d: USB ACM device\n", minor
);
1659 acm_set_control(acm
, acm
->ctrlout
);
1661 acm
->line
.dwDTERate
= cpu_to_le32(9600);
1662 acm
->line
.bDataBits
= 8;
1663 acm_set_line(acm
, &acm
->line
);
1665 usb_driver_claim_interface(&acm_driver
, data_interface
, acm
);
1666 usb_set_intfdata(data_interface
, acm
);
1668 usb_get_intf(control_interface
);
1669 tty_dev
= tty_port_register_device(&acm
->port
, acm_tty_driver
, minor
,
1670 &control_interface
->dev
);
1671 if (IS_ERR(tty_dev
)) {
1672 rv
= PTR_ERR(tty_dev
);
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
);
1683 kfree(acm
->country_codes
);
1685 device_remove_file(&acm
->control
->dev
, &dev_attr_bmCapabilities
);
1687 usb_set_intfdata(intf
, NULL
);
1688 for (i
= 0; i
< ACM_NW
; i
++)
1689 usb_free_urb(acm
->wb
[i
].urb
);
1691 for (i
= 0; i
< num_rx_buf
; i
++)
1692 usb_free_urb(acm
->read_urbs
[i
]);
1693 acm_read_buffers_free(acm
);
1694 usb_free_urb(acm
->ctrlurb
);
1696 acm_write_buffers_free(acm
);
1698 usb_free_coherent(usb_dev
, ctrlsize
, acm
->ctrl_buffer
, acm
->ctrl_dma
);
1700 acm_release_minor(acm
);
1706 static void stop_data_traffic(struct acm
*acm
)
1710 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
1712 usb_kill_urb(acm
->ctrlurb
);
1713 for (i
= 0; i
< ACM_NW
; i
++)
1714 usb_kill_urb(acm
->wb
[i
].urb
);
1715 for (i
= 0; i
< acm
->rx_buflimit
; i
++)
1716 usb_kill_urb(acm
->read_urbs
[i
]);
1718 cancel_work_sync(&acm
->work
);
1721 static void acm_disconnect(struct usb_interface
*intf
)
1723 struct acm
*acm
= usb_get_intfdata(intf
);
1724 struct usb_device
*usb_dev
= interface_to_usbdev(intf
);
1725 struct tty_struct
*tty
;
1728 dev_dbg(&intf
->dev
, "%s\n", __func__
);
1730 /* sibling interface is already cleaning up */
1734 mutex_lock(&acm
->mutex
);
1735 acm
->disconnected
= true;
1736 if (acm
->country_codes
) {
1737 device_remove_file(&acm
->control
->dev
,
1738 &dev_attr_wCountryCodes
);
1739 device_remove_file(&acm
->control
->dev
,
1740 &dev_attr_iCountryCodeRelDate
);
1742 device_remove_file(&acm
->control
->dev
, &dev_attr_bmCapabilities
);
1743 usb_set_intfdata(acm
->control
, NULL
);
1744 usb_set_intfdata(acm
->data
, NULL
);
1745 mutex_unlock(&acm
->mutex
);
1747 tty
= tty_port_tty_get(&acm
->port
);
1753 stop_data_traffic(acm
);
1755 tty_unregister_device(acm_tty_driver
, acm
->minor
);
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
]);
1762 acm_write_buffers_free(acm
);
1763 usb_free_coherent(usb_dev
, acm
->ctrlsize
, acm
->ctrl_buffer
, acm
->ctrl_dma
);
1764 acm_read_buffers_free(acm
);
1766 if (!acm
->combined_interfaces
)
1767 usb_driver_release_interface(&acm_driver
, intf
== acm
->control
?
1768 acm
->data
: acm
->control
);
1770 tty_port_put(&acm
->port
);
1774 static int acm_suspend(struct usb_interface
*intf
, pm_message_t message
)
1776 struct acm
*acm
= usb_get_intfdata(intf
);
1779 dbg_mtk(&acm
->control
->dev
, "%s intf=%d", __func__
, intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1780 spin_lock_irq(&acm
->read_lock
);
1781 spin_lock(&acm
->write_lock
);
1782 if (PMSG_IS_AUTO(message
)) {
1783 if (acm
->transmitting
) {
1784 spin_unlock(&acm
->write_lock
);
1785 spin_unlock_irq(&acm
->read_lock
);
1790 for (i
= 0; i
< ACM_NW
; i
++){
1792 spin_unlock(&acm
->write_lock
);
1793 spin_unlock_irq(&acm
->read_lock
);
1799 cnt
= acm
->susp_count
++;
1800 spin_unlock(&acm
->write_lock
);
1801 spin_unlock_irq(&acm
->read_lock
);
1806 stop_data_traffic(acm
);
1811 static int acm_resume(struct usb_interface
*intf
)
1813 struct acm
*acm
= usb_get_intfdata(intf
);
1817 dbg_mtk(&acm
->control
->dev
, "%s intf=%d", __func__
, intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1819 spin_lock_irq(&acm
->read_lock
);
1820 spin_lock(&acm
->write_lock
);
1822 if (--acm
->susp_count
)
1825 if (test_bit(ASYNCB_INITIALIZED
, &acm
->port
.flags
)) {
1826 rv
= usb_submit_urb(acm
->ctrlurb
, GFP_ATOMIC
);
1829 urb
= usb_get_from_anchor(&acm
->delayed
);
1833 acm_start_wb(acm
, urb
->context
);
1837 * delayed error checking because we must
1838 * do the write path at all cost
1841 MYDBG("urb fail:%d\n", rv
);
1845 rv
= acm_submit_read_urbs(acm
, GFP_ATOMIC
);
1848 spin_unlock(&acm
->write_lock
);
1849 spin_unlock_irq(&acm
->read_lock
);
1854 static int acm_reset_resume(struct usb_interface
*intf
)
1856 struct acm
*acm
= usb_get_intfdata(intf
);
1858 if (test_bit(ASYNCB_INITIALIZED
, &acm
->port
.flags
))
1859 tty_port_tty_hangup(&acm
->port
, false);
1861 return acm_resume(intf
);
1864 #endif /* CONFIG_PM */
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)
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)
1877 * USB driver structure.
1880 static const struct usb_device_id acm_ids
[] = {
1881 /* quirky and broken devices */
1882 { USB_DEVICE(0x17ef, 0x7000), /* Lenovo USB modem */
1883 .driver_info
= NO_UNION_NORMAL
, },/* has no union descriptor */
1884 { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */
1885 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1887 { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */
1888 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1890 { USB_DEVICE(0x0e8d, 0x3329), /* MediaTek Inc GPS */
1891 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1893 { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */
1894 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1896 { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */
1897 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1899 { USB_DEVICE(0x0ace, 0x1602), /* ZyDAS 56K USB MODEM */
1900 .driver_info
= SINGLE_RX_URB
,
1902 { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */
1903 .driver_info
= SINGLE_RX_URB
, /* firmware bug */
1905 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
1906 .driver_info
= SINGLE_RX_URB
, /* firmware bug */
1908 { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
1909 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1911 { USB_DEVICE(0x0803, 0x3095), /* Zoom Telephonics Model 3095F USB MODEM */
1912 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1914 { USB_DEVICE(0x0572, 0x1321), /* Conexant USB MODEM CX93010 */
1915 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1917 { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */
1918 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1920 { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */
1921 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1923 { USB_DEVICE(0x2184, 0x001c) }, /* GW Instek AFG-2225 */
1924 { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */
1926 /* Motorola H24 HSPA module: */
1927 { USB_DEVICE(0x22b8, 0x2d91) }, /* modem */
1928 { USB_DEVICE(0x22b8, 0x2d92), /* modem + diagnostics */
1929 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1931 { USB_DEVICE(0x22b8, 0x2d93), /* modem + AT port */
1932 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1934 { USB_DEVICE(0x22b8, 0x2d95), /* modem + AT port + diagnostics */
1935 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1937 { USB_DEVICE(0x22b8, 0x2d96), /* modem + NMEA */
1938 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1940 { USB_DEVICE(0x22b8, 0x2d97), /* modem + diagnostics + NMEA */
1941 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1943 { USB_DEVICE(0x22b8, 0x2d99), /* modem + AT port + NMEA */
1944 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1946 { USB_DEVICE(0x22b8, 0x2d9a), /* modem + AT port + diagnostics + NMEA */
1947 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
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
1957 { USB_DEVICE(0x0572, 0x1340), /* Conexant CX93010-2x UCMxx */
1958 .driver_info
= NO_UNION_NORMAL
,
1960 { USB_DEVICE(0x05f9, 0x4002), /* PSC Scanning, Magellan 800i */
1961 .driver_info
= NO_UNION_NORMAL
,
1963 { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */
1964 .driver_info
= NO_UNION_NORMAL
, /* reports zero length descriptor */
1966 { USB_DEVICE(0x1576, 0x03b1), /* Maretron USB100 */
1967 .driver_info
= NO_UNION_NORMAL
, /* reports zero length descriptor */
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 */
2018 { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */
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 */
2029 { NOKIA_PCSUITE_ACM_INFO(0x0302), }, /* Nokia N8 */
2030 { NOKIA_PCSUITE_ACM_INFO(0x0335), }, /* Nokia E7 */
2031 { NOKIA_PCSUITE_ACM_INFO(0x03cd), }, /* Nokia C7 */
2032 { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */
2034 /* Support for Owen devices */
2035 { USB_DEVICE(0x03eb, 0x0030), }, /* Owen SI30 */
2037 /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */
2039 /* Support Lego NXT using pbLua firmware */
2040 { USB_DEVICE(0x0694, 0xff00),
2041 .driver_info
= NOT_A_MODEM
,
2044 /* Support for Droids MuIn LCD */
2045 { USB_DEVICE(0x04d8, 0x000b),
2046 .driver_info
= NO_DATA_INTERFACE
,
2049 #if IS_ENABLED(CONFIG_INPUT_IMS_PCU)
2050 { USB_DEVICE(0x04d8, 0x0082), /* Application mode */
2051 .driver_info
= IGNORE_DEVICE
,
2053 { USB_DEVICE(0x04d8, 0x0083), /* Bootloader mode */
2054 .driver_info
= IGNORE_DEVICE
,
2058 /* Exclude Infineon Flash Loader utility */
2059 { USB_DEVICE(0x058b, 0x0041),
2060 .driver_info
= IGNORE_DEVICE
,
2063 /* control interfaces without any protocol set */
2064 { USB_INTERFACE_INFO(USB_CLASS_COMM
, USB_CDC_SUBCLASS_ACM
,
2065 USB_CDC_PROTO_NONE
) },
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
,
2077 USB_CDC_ACM_PROTO_AT_3G
) },
2078 { USB_INTERFACE_INFO(USB_CLASS_COMM
, USB_CDC_SUBCLASS_ACM
,
2079 USB_CDC_ACM_PROTO_AT_CDMA
) },
2084 MODULE_DEVICE_TABLE(usb
, acm_ids
);
2086 static struct usb_driver acm_driver
= {
2089 .disconnect
= acm_disconnect
,
2091 .suspend
= acm_suspend
,
2092 .resume
= acm_resume
,
2093 .reset_resume
= acm_reset_resume
,
2095 .id_table
= acm_ids
,
2097 .supports_autosuspend
= 1,
2099 .disable_hub_initiated_lpm
= 1,
2103 * TTY driver structures.
2106 static const struct tty_operations acm_ops
= {
2107 .install
= acm_tty_install
,
2108 .open
= acm_tty_open
,
2109 .close
= acm_tty_close
,
2110 .cleanup
= acm_tty_cleanup
,
2111 .hangup
= acm_tty_hangup
,
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
,
2128 static int __init
acm_init(void)
2131 #ifdef CONFIG_MTK_DT_USB_SUPPORT
2134 acm_tty_driver
= alloc_tty_driver(ACM_TTY_MINORS
);
2135 if (!acm_tty_driver
)
2137 acm_tty_driver
->driver_name
= "acm",
2138 acm_tty_driver
->name
= "ttyACM",
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
,
2143 acm_tty_driver
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
;
2144 acm_tty_driver
->init_termios
= tty_std_termios
;
2145 acm_tty_driver
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
|
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.
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
;
2160 tty_set_operations(acm_tty_driver
, &acm_ops
);
2162 retval
= tty_register_driver(acm_tty_driver
);
2164 put_tty_driver(acm_tty_driver
);
2168 retval
= usb_register(&acm_driver
);
2170 tty_unregister_driver(acm_tty_driver
);
2171 put_tty_driver(acm_tty_driver
);
2175 printk(KERN_INFO KBUILD_MODNAME
": " DRIVER_DESC
"\n");
2180 static void __exit
acm_exit(void)
2182 usb_deregister(&acm_driver
);
2183 tty_unregister_driver(acm_tty_driver
);
2184 put_tty_driver(acm_tty_driver
);
2187 module_init(acm_init
);
2188 module_exit(acm_exit
);
2189 #ifdef CONFIG_MTK_DT_USB_SUPPORT
2190 module_param(enable_debug
, int, 0644);
2191 module_param(enable_dump
, int, 0644);
2194 MODULE_AUTHOR(DRIVER_AUTHOR
);
2195 MODULE_DESCRIPTION(DRIVER_DESC
);
2196 MODULE_LICENSE("GPL");
2197 MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR
);