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 /* we would crash */
1311 if (!data_interface
|| !control_interface
)
1313 goto skip_normal_probe
;
1318 dev_err(&intf
->dev
, "Weird descriptor references\n");
1323 if (intf
->cur_altsetting
->endpoint
&&
1324 intf
->cur_altsetting
->endpoint
->extralen
&&
1325 intf
->cur_altsetting
->endpoint
->extra
) {
1327 "Seeking extra descriptors on endpoint\n");
1328 buflen
= intf
->cur_altsetting
->endpoint
->extralen
;
1329 buffer
= intf
->cur_altsetting
->endpoint
->extra
;
1332 "Zero length descriptor references\n");
1337 while (buflen
> 0) {
1338 if (buffer
[1] != USB_DT_CS_INTERFACE
) {
1339 dev_err(&intf
->dev
, "skipping garbage\n");
1343 switch (buffer
[2]) {
1344 case USB_CDC_UNION_TYPE
: /* we've found it */
1346 dev_err(&intf
->dev
, "More than one "
1347 "union descriptor, skipping ...\n");
1350 union_header
= (struct usb_cdc_union_desc
*)buffer
;
1352 case USB_CDC_COUNTRY_TYPE
: /* export through sysfs*/
1353 cfd
= (struct usb_cdc_country_functional_desc
*)buffer
;
1355 case USB_CDC_HEADER_TYPE
: /* maybe check version */
1356 break; /* for now we ignore it */
1357 case USB_CDC_ACM_TYPE
:
1358 ac_management_function
= buffer
[3];
1360 case USB_CDC_CALL_MANAGEMENT_TYPE
:
1361 call_management_function
= buffer
[3];
1362 call_interface_num
= buffer
[4];
1363 if ((quirks
& NOT_A_MODEM
) == 0 && (call_management_function
& 3) != 3)
1364 dev_err(&intf
->dev
, "This device cannot do calls on its own. It is not a modem.\n");
1367 /* there are LOTS more CDC descriptors that
1368 * could legitimately be found here.
1370 dev_dbg(&intf
->dev
, "Ignoring descriptor: "
1371 "type %02x, length %d\n",
1372 buffer
[2], buffer
[0]);
1376 buflen
-= buffer
[0];
1377 buffer
+= buffer
[0];
1380 if (!union_header
) {
1381 if (call_interface_num
> 0) {
1382 dev_dbg(&intf
->dev
, "No union descriptor, using call management descriptor\n");
1383 /* quirks for Droids MuIn LCD */
1384 if (quirks
& NO_DATA_INTERFACE
)
1385 data_interface
= usb_ifnum_to_if(usb_dev
, 0);
1387 data_interface
= usb_ifnum_to_if(usb_dev
, (data_interface_num
= call_interface_num
));
1388 control_interface
= intf
;
1390 if (intf
->cur_altsetting
->desc
.bNumEndpoints
!= 3) {
1391 dev_dbg(&intf
->dev
,"No union descriptor, giving up\n");
1394 dev_warn(&intf
->dev
,"No union descriptor, testing for castrated device\n");
1395 combined_interfaces
= 1;
1396 control_interface
= data_interface
= intf
;
1397 goto look_for_collapsed_interface
;
1401 control_interface
= usb_ifnum_to_if(usb_dev
, union_header
->bMasterInterface0
);
1402 data_interface
= usb_ifnum_to_if(usb_dev
, (data_interface_num
= union_header
->bSlaveInterface0
));
1405 if (!control_interface
|| !data_interface
) {
1406 dev_dbg(&intf
->dev
, "no interfaces\n");
1410 if (data_interface_num
!= call_interface_num
)
1411 dev_dbg(&intf
->dev
, "Separate call control interface. That is not fully supported.\n");
1413 if (control_interface
== data_interface
) {
1414 /* some broken devices designed for windows work this way */
1415 dev_warn(&intf
->dev
,"Control and data interfaces are not separated!\n");
1416 combined_interfaces
= 1;
1417 /* a popular other OS doesn't use it */
1418 quirks
|= NO_CAP_LINE
;
1419 if (data_interface
->cur_altsetting
->desc
.bNumEndpoints
!= 3) {
1420 dev_err(&intf
->dev
, "This needs exactly 3 endpoints\n");
1423 look_for_collapsed_interface
:
1424 for (i
= 0; i
< 3; i
++) {
1425 struct usb_endpoint_descriptor
*ep
;
1426 ep
= &data_interface
->cur_altsetting
->endpoint
[i
].desc
;
1428 if (usb_endpoint_is_int_in(ep
))
1430 else if (usb_endpoint_is_bulk_out(ep
))
1432 else if (usb_endpoint_is_bulk_in(ep
))
1437 if (!epctrl
|| !epread
|| !epwrite
)
1440 goto made_compressed_probe
;
1445 /*workaround for switched interfaces */
1446 if (data_interface
->cur_altsetting
->desc
.bInterfaceClass
1447 != CDC_DATA_INTERFACE_TYPE
) {
1448 if (control_interface
->cur_altsetting
->desc
.bInterfaceClass
1449 == CDC_DATA_INTERFACE_TYPE
) {
1450 struct usb_interface
*t
;
1452 "Your device has switched interfaces.\n");
1453 t
= control_interface
;
1454 control_interface
= data_interface
;
1461 /* Accept probe requests only for the control interface */
1462 if (!combined_interfaces
&& intf
!= control_interface
)
1465 if (!combined_interfaces
&& usb_interface_claimed(data_interface
)) {
1466 /* valid in this context */
1467 dev_dbg(&intf
->dev
, "The data interface isn't available\n");
1472 if (data_interface
->cur_altsetting
->desc
.bNumEndpoints
< 2 ||
1473 control_interface
->cur_altsetting
->desc
.bNumEndpoints
== 0)
1476 epctrl
= &control_interface
->cur_altsetting
->endpoint
[0].desc
;
1477 epread
= &data_interface
->cur_altsetting
->endpoint
[0].desc
;
1478 epwrite
= &data_interface
->cur_altsetting
->endpoint
[1].desc
;
1481 /* workaround for switched endpoints */
1482 if (!usb_endpoint_dir_in(epread
)) {
1483 /* descriptors are swapped */
1484 struct usb_endpoint_descriptor
*t
;
1486 "The data interface has switched endpoints\n");
1491 made_compressed_probe
:
1492 dev_dbg(&intf
->dev
, "interfaces are valid\n");
1494 acm
= kzalloc(sizeof(struct acm
), GFP_KERNEL
);
1496 dev_err(&intf
->dev
, "out of memory (acm kzalloc)\n");
1500 minor
= acm_alloc_minor(acm
);
1501 if (minor
== ACM_TTY_MINORS
) {
1502 dev_err(&intf
->dev
, "no more free acm devices\n");
1507 ctrlsize
= usb_endpoint_maxp(epctrl
);
1508 readsize
= usb_endpoint_maxp(epread
) *
1509 (quirks
== SINGLE_RX_URB
? 1 : 2);
1510 acm
->combined_interfaces
= combined_interfaces
;
1511 #ifdef CONFIG_MTK_DT_USB_SUPPORT
1512 acm
->writesize
= ACM_WB_SZ
;
1514 acm
->writesize
= usb_endpoint_maxp(epwrite
) * 20;
1516 acm
->control
= control_interface
;
1517 acm
->data
= data_interface
;
1520 acm
->ctrl_caps
= ac_management_function
;
1521 if (quirks
& NO_CAP_LINE
)
1522 acm
->ctrl_caps
&= ~USB_CDC_CAP_LINE
;
1523 acm
->ctrlsize
= ctrlsize
;
1524 acm
->readsize
= readsize
;
1525 acm
->rx_buflimit
= num_rx_buf
;
1526 INIT_WORK(&acm
->work
, acm_softint
);
1527 spin_lock_init(&acm
->write_lock
);
1528 spin_lock_init(&acm
->read_lock
);
1529 mutex_init(&acm
->mutex
);
1530 acm
->is_int_ep
= usb_endpoint_xfer_int(epread
);
1532 acm
->bInterval
= epread
->bInterval
;
1533 tty_port_init(&acm
->port
);
1534 acm
->port
.ops
= &acm_port_ops
;
1535 init_usb_anchor(&acm
->delayed
);
1537 buf
= usb_alloc_coherent(usb_dev
, ctrlsize
, GFP_KERNEL
, &acm
->ctrl_dma
);
1539 dev_err(&intf
->dev
, "out of memory (ctrl buffer alloc)\n");
1542 acm
->ctrl_buffer
= buf
;
1544 if (acm_write_buffers_alloc(acm
) < 0) {
1545 dev_err(&intf
->dev
, "out of memory (write buffer alloc)\n");
1549 acm
->ctrlurb
= usb_alloc_urb(0, GFP_KERNEL
);
1550 if (!acm
->ctrlurb
) {
1551 dev_err(&intf
->dev
, "out of memory (ctrlurb kmalloc)\n");
1554 for (i
= 0; i
< num_rx_buf
; i
++) {
1555 struct acm_rb
*rb
= &(acm
->read_buffers
[i
]);
1558 rb
->base
= usb_alloc_coherent(acm
->dev
, readsize
, GFP_KERNEL
,
1561 dev_err(&intf
->dev
, "out of memory "
1562 "(read bufs usb_alloc_coherent)\n");
1568 urb
= usb_alloc_urb(0, GFP_KERNEL
);
1571 "out of memory (read urbs usb_alloc_urb)\n");
1574 urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1575 urb
->transfer_dma
= rb
->dma
;
1576 if (acm
->is_int_ep
) {
1577 usb_fill_int_urb(urb
, acm
->dev
,
1578 usb_rcvintpipe(usb_dev
, epread
->bEndpointAddress
),
1581 acm_read_bulk_callback
, rb
,
1584 usb_fill_bulk_urb(urb
, acm
->dev
,
1585 usb_rcvbulkpipe(usb_dev
, epread
->bEndpointAddress
),
1588 acm_read_bulk_callback
, rb
);
1591 acm
->read_urbs
[i
] = urb
;
1592 __set_bit(i
, &acm
->read_urbs_free
);
1594 for (i
= 0; i
< ACM_NW
; i
++) {
1595 struct acm_wb
*snd
= &(acm
->wb
[i
]);
1597 snd
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
1598 if (snd
->urb
== NULL
) {
1600 "out of memory (write urbs usb_alloc_urb)\n");
1604 if (usb_endpoint_xfer_int(epwrite
))
1605 usb_fill_int_urb(snd
->urb
, usb_dev
,
1606 usb_sndintpipe(usb_dev
, epwrite
->bEndpointAddress
),
1607 NULL
, acm
->writesize
, acm_write_bulk
, snd
, epwrite
->bInterval
);
1609 usb_fill_bulk_urb(snd
->urb
, usb_dev
,
1610 usb_sndbulkpipe(usb_dev
, epwrite
->bEndpointAddress
),
1611 NULL
, acm
->writesize
, acm_write_bulk
, snd
);
1612 snd
->urb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1613 snd
->instance
= acm
;
1616 usb_set_intfdata(intf
, acm
);
1618 i
= device_create_file(&intf
->dev
, &dev_attr_bmCapabilities
);
1622 if (cfd
) { /* export the country data */
1623 acm
->country_codes
= kmalloc(cfd
->bLength
- 4, GFP_KERNEL
);
1624 if (!acm
->country_codes
)
1625 goto skip_countries
;
1626 acm
->country_code_size
= cfd
->bLength
- 4;
1627 memcpy(acm
->country_codes
, (u8
*)&cfd
->wCountyCode0
,
1629 acm
->country_rel_date
= cfd
->iCountryCodeRelDate
;
1631 i
= device_create_file(&intf
->dev
, &dev_attr_wCountryCodes
);
1633 kfree(acm
->country_codes
);
1634 acm
->country_codes
= NULL
;
1635 acm
->country_code_size
= 0;
1636 goto skip_countries
;
1639 i
= device_create_file(&intf
->dev
,
1640 &dev_attr_iCountryCodeRelDate
);
1642 device_remove_file(&intf
->dev
, &dev_attr_wCountryCodes
);
1643 kfree(acm
->country_codes
);
1644 acm
->country_codes
= NULL
;
1645 acm
->country_code_size
= 0;
1646 goto skip_countries
;
1651 usb_fill_int_urb(acm
->ctrlurb
, usb_dev
,
1652 usb_rcvintpipe(usb_dev
, epctrl
->bEndpointAddress
),
1653 acm
->ctrl_buffer
, ctrlsize
, acm_ctrl_irq
, acm
,
1654 /* works around buggy devices */
1655 epctrl
->bInterval
? epctrl
->bInterval
: 0xff);
1656 acm
->ctrlurb
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1657 acm
->ctrlurb
->transfer_dma
= acm
->ctrl_dma
;
1659 dev_info(&intf
->dev
, "ttyACM%d: USB ACM device\n", minor
);
1661 acm_set_control(acm
, acm
->ctrlout
);
1663 acm
->line
.dwDTERate
= cpu_to_le32(9600);
1664 acm
->line
.bDataBits
= 8;
1665 acm_set_line(acm
, &acm
->line
);
1667 usb_driver_claim_interface(&acm_driver
, data_interface
, acm
);
1668 usb_set_intfdata(data_interface
, acm
);
1670 usb_get_intf(control_interface
);
1671 tty_dev
= tty_port_register_device(&acm
->port
, acm_tty_driver
, minor
,
1672 &control_interface
->dev
);
1673 if (IS_ERR(tty_dev
)) {
1674 rv
= PTR_ERR(tty_dev
);
1680 if (acm
->country_codes
) {
1681 device_remove_file(&acm
->control
->dev
,
1682 &dev_attr_wCountryCodes
);
1683 device_remove_file(&acm
->control
->dev
,
1684 &dev_attr_iCountryCodeRelDate
);
1685 kfree(acm
->country_codes
);
1687 device_remove_file(&acm
->control
->dev
, &dev_attr_bmCapabilities
);
1689 usb_set_intfdata(intf
, NULL
);
1690 for (i
= 0; i
< ACM_NW
; i
++)
1691 usb_free_urb(acm
->wb
[i
].urb
);
1693 for (i
= 0; i
< num_rx_buf
; i
++)
1694 usb_free_urb(acm
->read_urbs
[i
]);
1695 acm_read_buffers_free(acm
);
1696 usb_free_urb(acm
->ctrlurb
);
1698 acm_write_buffers_free(acm
);
1700 usb_free_coherent(usb_dev
, ctrlsize
, acm
->ctrl_buffer
, acm
->ctrl_dma
);
1702 acm_release_minor(acm
);
1708 static void stop_data_traffic(struct acm
*acm
)
1712 dev_dbg(&acm
->control
->dev
, "%s\n", __func__
);
1714 usb_kill_urb(acm
->ctrlurb
);
1715 for (i
= 0; i
< ACM_NW
; i
++)
1716 usb_kill_urb(acm
->wb
[i
].urb
);
1717 for (i
= 0; i
< acm
->rx_buflimit
; i
++)
1718 usb_kill_urb(acm
->read_urbs
[i
]);
1720 cancel_work_sync(&acm
->work
);
1723 static void acm_disconnect(struct usb_interface
*intf
)
1725 struct acm
*acm
= usb_get_intfdata(intf
);
1726 struct usb_device
*usb_dev
= interface_to_usbdev(intf
);
1727 struct tty_struct
*tty
;
1730 dev_dbg(&intf
->dev
, "%s\n", __func__
);
1732 /* sibling interface is already cleaning up */
1736 mutex_lock(&acm
->mutex
);
1737 acm
->disconnected
= true;
1738 if (acm
->country_codes
) {
1739 device_remove_file(&acm
->control
->dev
,
1740 &dev_attr_wCountryCodes
);
1741 device_remove_file(&acm
->control
->dev
,
1742 &dev_attr_iCountryCodeRelDate
);
1744 device_remove_file(&acm
->control
->dev
, &dev_attr_bmCapabilities
);
1745 usb_set_intfdata(acm
->control
, NULL
);
1746 usb_set_intfdata(acm
->data
, NULL
);
1747 mutex_unlock(&acm
->mutex
);
1749 tty
= tty_port_tty_get(&acm
->port
);
1755 stop_data_traffic(acm
);
1757 tty_unregister_device(acm_tty_driver
, acm
->minor
);
1759 usb_free_urb(acm
->ctrlurb
);
1760 for (i
= 0; i
< ACM_NW
; i
++)
1761 usb_free_urb(acm
->wb
[i
].urb
);
1762 for (i
= 0; i
< acm
->rx_buflimit
; i
++)
1763 usb_free_urb(acm
->read_urbs
[i
]);
1764 acm_write_buffers_free(acm
);
1765 usb_free_coherent(usb_dev
, acm
->ctrlsize
, acm
->ctrl_buffer
, acm
->ctrl_dma
);
1766 acm_read_buffers_free(acm
);
1768 if (!acm
->combined_interfaces
)
1769 usb_driver_release_interface(&acm_driver
, intf
== acm
->control
?
1770 acm
->data
: acm
->control
);
1772 tty_port_put(&acm
->port
);
1776 static int acm_suspend(struct usb_interface
*intf
, pm_message_t message
)
1778 struct acm
*acm
= usb_get_intfdata(intf
);
1781 dbg_mtk(&acm
->control
->dev
, "%s intf=%d", __func__
, intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1782 spin_lock_irq(&acm
->read_lock
);
1783 spin_lock(&acm
->write_lock
);
1784 if (PMSG_IS_AUTO(message
)) {
1785 if (acm
->transmitting
) {
1786 spin_unlock(&acm
->write_lock
);
1787 spin_unlock_irq(&acm
->read_lock
);
1792 for (i
= 0; i
< ACM_NW
; i
++){
1794 spin_unlock(&acm
->write_lock
);
1795 spin_unlock_irq(&acm
->read_lock
);
1801 cnt
= acm
->susp_count
++;
1802 spin_unlock(&acm
->write_lock
);
1803 spin_unlock_irq(&acm
->read_lock
);
1808 stop_data_traffic(acm
);
1813 static int acm_resume(struct usb_interface
*intf
)
1815 struct acm
*acm
= usb_get_intfdata(intf
);
1819 dbg_mtk(&acm
->control
->dev
, "%s intf=%d", __func__
, intf
->cur_altsetting
->desc
.bInterfaceNumber
);
1821 spin_lock_irq(&acm
->read_lock
);
1822 spin_lock(&acm
->write_lock
);
1824 if (--acm
->susp_count
)
1827 if (test_bit(ASYNCB_INITIALIZED
, &acm
->port
.flags
)) {
1828 rv
= usb_submit_urb(acm
->ctrlurb
, GFP_ATOMIC
);
1831 urb
= usb_get_from_anchor(&acm
->delayed
);
1835 acm_start_wb(acm
, urb
->context
);
1839 * delayed error checking because we must
1840 * do the write path at all cost
1843 MYDBG("urb fail:%d\n", rv
);
1847 rv
= acm_submit_read_urbs(acm
, GFP_ATOMIC
);
1850 spin_unlock(&acm
->write_lock
);
1851 spin_unlock_irq(&acm
->read_lock
);
1856 static int acm_reset_resume(struct usb_interface
*intf
)
1858 struct acm
*acm
= usb_get_intfdata(intf
);
1860 if (test_bit(ASYNCB_INITIALIZED
, &acm
->port
.flags
))
1861 tty_port_tty_hangup(&acm
->port
, false);
1863 return acm_resume(intf
);
1866 #endif /* CONFIG_PM */
1868 #define NOKIA_PCSUITE_ACM_INFO(x) \
1869 USB_DEVICE_AND_INTERFACE_INFO(0x0421, x, \
1870 USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \
1871 USB_CDC_ACM_PROTO_VENDOR)
1873 #define SAMSUNG_PCSUITE_ACM_INFO(x) \
1874 USB_DEVICE_AND_INTERFACE_INFO(0x04e7, x, \
1875 USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \
1876 USB_CDC_ACM_PROTO_VENDOR)
1879 * USB driver structure.
1882 static const struct usb_device_id acm_ids
[] = {
1883 /* quirky and broken devices */
1884 { USB_DEVICE(0x17ef, 0x7000), /* Lenovo USB modem */
1885 .driver_info
= NO_UNION_NORMAL
, },/* has no union descriptor */
1886 { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */
1887 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1889 { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */
1890 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1892 { USB_DEVICE(0x0e8d, 0x3329), /* MediaTek Inc GPS */
1893 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1895 { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */
1896 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1898 { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */
1899 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1901 { USB_DEVICE(0x0ace, 0x1602), /* ZyDAS 56K USB MODEM */
1902 .driver_info
= SINGLE_RX_URB
,
1904 { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */
1905 .driver_info
= SINGLE_RX_URB
, /* firmware bug */
1907 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
1908 .driver_info
= SINGLE_RX_URB
, /* firmware bug */
1910 { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
1911 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1913 { USB_DEVICE(0x0803, 0x3095), /* Zoom Telephonics Model 3095F USB MODEM */
1914 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1916 { USB_DEVICE(0x0572, 0x1321), /* Conexant USB MODEM CX93010 */
1917 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1919 { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */
1920 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1922 { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */
1923 .driver_info
= NO_UNION_NORMAL
, /* has no union descriptor */
1925 { USB_DEVICE(0x2184, 0x001c) }, /* GW Instek AFG-2225 */
1926 { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */
1928 /* Motorola H24 HSPA module: */
1929 { USB_DEVICE(0x22b8, 0x2d91) }, /* modem */
1930 { USB_DEVICE(0x22b8, 0x2d92), /* modem + diagnostics */
1931 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1933 { USB_DEVICE(0x22b8, 0x2d93), /* modem + AT port */
1934 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1936 { USB_DEVICE(0x22b8, 0x2d95), /* modem + AT port + diagnostics */
1937 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1939 { USB_DEVICE(0x22b8, 0x2d96), /* modem + NMEA */
1940 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1942 { USB_DEVICE(0x22b8, 0x2d97), /* modem + diagnostics + NMEA */
1943 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1945 { USB_DEVICE(0x22b8, 0x2d99), /* modem + AT port + NMEA */
1946 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1948 { USB_DEVICE(0x22b8, 0x2d9a), /* modem + AT port + diagnostics + NMEA */
1949 .driver_info
= NO_UNION_NORMAL
, /* handle only modem interface */
1952 { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */
1953 .driver_info
= NO_UNION_NORMAL
, /* union descriptor misplaced on
1954 data interface instead of
1955 communications interface.
1956 Maybe we should define a new
1959 { USB_DEVICE(0x0572, 0x1340), /* Conexant CX93010-2x UCMxx */
1960 .driver_info
= NO_UNION_NORMAL
,
1962 { USB_DEVICE(0x05f9, 0x4002), /* PSC Scanning, Magellan 800i */
1963 .driver_info
= NO_UNION_NORMAL
,
1965 { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */
1966 .driver_info
= NO_UNION_NORMAL
, /* reports zero length descriptor */
1968 { USB_DEVICE(0x1576, 0x03b1), /* Maretron USB100 */
1969 .driver_info
= NO_UNION_NORMAL
, /* reports zero length descriptor */
1972 /* Nokia S60 phones expose two ACM channels. The first is
1973 * a modem and is picked up by the standard AT-command
1974 * information below. The second is 'vendor-specific' but
1975 * is treated as a serial device at the S60 end, so we want
1976 * to expose it on Linux too. */
1977 { NOKIA_PCSUITE_ACM_INFO(0x042D), }, /* Nokia 3250 */
1978 { NOKIA_PCSUITE_ACM_INFO(0x04D8), }, /* Nokia 5500 Sport */
1979 { NOKIA_PCSUITE_ACM_INFO(0x04C9), }, /* Nokia E50 */
1980 { NOKIA_PCSUITE_ACM_INFO(0x0419), }, /* Nokia E60 */
1981 { NOKIA_PCSUITE_ACM_INFO(0x044D), }, /* Nokia E61 */
1982 { NOKIA_PCSUITE_ACM_INFO(0x0001), }, /* Nokia E61i */
1983 { NOKIA_PCSUITE_ACM_INFO(0x0475), }, /* Nokia E62 */
1984 { NOKIA_PCSUITE_ACM_INFO(0x0508), }, /* Nokia E65 */
1985 { NOKIA_PCSUITE_ACM_INFO(0x0418), }, /* Nokia E70 */
1986 { NOKIA_PCSUITE_ACM_INFO(0x0425), }, /* Nokia N71 */
1987 { NOKIA_PCSUITE_ACM_INFO(0x0486), }, /* Nokia N73 */
1988 { NOKIA_PCSUITE_ACM_INFO(0x04DF), }, /* Nokia N75 */
1989 { NOKIA_PCSUITE_ACM_INFO(0x000e), }, /* Nokia N77 */
1990 { NOKIA_PCSUITE_ACM_INFO(0x0445), }, /* Nokia N80 */
1991 { NOKIA_PCSUITE_ACM_INFO(0x042F), }, /* Nokia N91 & N91 8GB */
1992 { NOKIA_PCSUITE_ACM_INFO(0x048E), }, /* Nokia N92 */
1993 { NOKIA_PCSUITE_ACM_INFO(0x0420), }, /* Nokia N93 */
1994 { NOKIA_PCSUITE_ACM_INFO(0x04E6), }, /* Nokia N93i */
1995 { NOKIA_PCSUITE_ACM_INFO(0x04B2), }, /* Nokia 5700 XpressMusic */
1996 { NOKIA_PCSUITE_ACM_INFO(0x0134), }, /* Nokia 6110 Navigator (China) */
1997 { NOKIA_PCSUITE_ACM_INFO(0x046E), }, /* Nokia 6110 Navigator */
1998 { NOKIA_PCSUITE_ACM_INFO(0x002f), }, /* Nokia 6120 classic & */
1999 { NOKIA_PCSUITE_ACM_INFO(0x0088), }, /* Nokia 6121 classic */
2000 { NOKIA_PCSUITE_ACM_INFO(0x00fc), }, /* Nokia 6124 classic */
2001 { NOKIA_PCSUITE_ACM_INFO(0x0042), }, /* Nokia E51 */
2002 { NOKIA_PCSUITE_ACM_INFO(0x00b0), }, /* Nokia E66 */
2003 { NOKIA_PCSUITE_ACM_INFO(0x00ab), }, /* Nokia E71 */
2004 { NOKIA_PCSUITE_ACM_INFO(0x0481), }, /* Nokia N76 */
2005 { NOKIA_PCSUITE_ACM_INFO(0x0007), }, /* Nokia N81 & N81 8GB */
2006 { NOKIA_PCSUITE_ACM_INFO(0x0071), }, /* Nokia N82 */
2007 { NOKIA_PCSUITE_ACM_INFO(0x04F0), }, /* Nokia N95 & N95-3 NAM */
2008 { NOKIA_PCSUITE_ACM_INFO(0x0070), }, /* Nokia N95 8GB */
2009 { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */
2010 { NOKIA_PCSUITE_ACM_INFO(0x0099), }, /* Nokia 6210 Navigator, RM-367 */
2011 { NOKIA_PCSUITE_ACM_INFO(0x0128), }, /* Nokia 6210 Navigator, RM-419 */
2012 { NOKIA_PCSUITE_ACM_INFO(0x008f), }, /* Nokia 6220 Classic */
2013 { NOKIA_PCSUITE_ACM_INFO(0x00a0), }, /* Nokia 6650 */
2014 { NOKIA_PCSUITE_ACM_INFO(0x007b), }, /* Nokia N78 */
2015 { NOKIA_PCSUITE_ACM_INFO(0x0094), }, /* Nokia N85 */
2016 { NOKIA_PCSUITE_ACM_INFO(0x003a), }, /* Nokia N96 & N96-3 */
2017 { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */
2018 { NOKIA_PCSUITE_ACM_INFO(0x0108), }, /* Nokia 5320 XpressMusic 2G */
2019 { NOKIA_PCSUITE_ACM_INFO(0x01f5), }, /* Nokia N97, RM-505 */
2020 { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */
2021 { NOKIA_PCSUITE_ACM_INFO(0x0178), }, /* Nokia E63 */
2022 { NOKIA_PCSUITE_ACM_INFO(0x010e), }, /* Nokia E75 */
2023 { NOKIA_PCSUITE_ACM_INFO(0x02d9), }, /* Nokia 6760 Slide */
2024 { NOKIA_PCSUITE_ACM_INFO(0x01d0), }, /* Nokia E52 */
2025 { NOKIA_PCSUITE_ACM_INFO(0x0223), }, /* Nokia E72 */
2026 { NOKIA_PCSUITE_ACM_INFO(0x0275), }, /* Nokia X6 */
2027 { NOKIA_PCSUITE_ACM_INFO(0x026c), }, /* Nokia N97 Mini */
2028 { NOKIA_PCSUITE_ACM_INFO(0x0154), }, /* Nokia 5800 XpressMusic */
2029 { NOKIA_PCSUITE_ACM_INFO(0x04ce), }, /* Nokia E90 */
2030 { NOKIA_PCSUITE_ACM_INFO(0x01d4), }, /* Nokia E55 */
2031 { NOKIA_PCSUITE_ACM_INFO(0x0302), }, /* Nokia N8 */
2032 { NOKIA_PCSUITE_ACM_INFO(0x0335), }, /* Nokia E7 */
2033 { NOKIA_PCSUITE_ACM_INFO(0x03cd), }, /* Nokia C7 */
2034 { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */
2036 /* Support for Owen devices */
2037 { USB_DEVICE(0x03eb, 0x0030), }, /* Owen SI30 */
2039 /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */
2041 /* Support Lego NXT using pbLua firmware */
2042 { USB_DEVICE(0x0694, 0xff00),
2043 .driver_info
= NOT_A_MODEM
,
2046 /* Support for Droids MuIn LCD */
2047 { USB_DEVICE(0x04d8, 0x000b),
2048 .driver_info
= NO_DATA_INTERFACE
,
2051 #if IS_ENABLED(CONFIG_INPUT_IMS_PCU)
2052 { USB_DEVICE(0x04d8, 0x0082), /* Application mode */
2053 .driver_info
= IGNORE_DEVICE
,
2055 { USB_DEVICE(0x04d8, 0x0083), /* Bootloader mode */
2056 .driver_info
= IGNORE_DEVICE
,
2060 /*Samsung phone in firmware update mode */
2061 { USB_DEVICE(0x04e8, 0x685d),
2062 .driver_info
= IGNORE_DEVICE
,
2065 /* Exclude Infineon Flash Loader utility */
2066 { USB_DEVICE(0x058b, 0x0041),
2067 .driver_info
= IGNORE_DEVICE
,
2070 /* control interfaces without any protocol set */
2071 { USB_INTERFACE_INFO(USB_CLASS_COMM
, USB_CDC_SUBCLASS_ACM
,
2072 USB_CDC_PROTO_NONE
) },
2074 /* control interfaces with various AT-command sets */
2075 { USB_INTERFACE_INFO(USB_CLASS_COMM
, USB_CDC_SUBCLASS_ACM
,
2076 USB_CDC_ACM_PROTO_AT_V25TER
) },
2077 { USB_INTERFACE_INFO(USB_CLASS_COMM
, USB_CDC_SUBCLASS_ACM
,
2078 USB_CDC_ACM_PROTO_AT_PCCA101
) },
2079 { USB_INTERFACE_INFO(USB_CLASS_COMM
, USB_CDC_SUBCLASS_ACM
,
2080 USB_CDC_ACM_PROTO_AT_PCCA101_WAKE
) },
2081 { USB_INTERFACE_INFO(USB_CLASS_COMM
, USB_CDC_SUBCLASS_ACM
,
2082 USB_CDC_ACM_PROTO_AT_GSM
) },
2083 { USB_INTERFACE_INFO(USB_CLASS_COMM
, USB_CDC_SUBCLASS_ACM
,
2084 USB_CDC_ACM_PROTO_AT_3G
) },
2085 { USB_INTERFACE_INFO(USB_CLASS_COMM
, USB_CDC_SUBCLASS_ACM
,
2086 USB_CDC_ACM_PROTO_AT_CDMA
) },
2091 MODULE_DEVICE_TABLE(usb
, acm_ids
);
2093 static struct usb_driver acm_driver
= {
2096 .disconnect
= acm_disconnect
,
2098 .suspend
= acm_suspend
,
2099 .resume
= acm_resume
,
2100 .reset_resume
= acm_reset_resume
,
2102 .id_table
= acm_ids
,
2104 .supports_autosuspend
= 1,
2106 .disable_hub_initiated_lpm
= 1,
2110 * TTY driver structures.
2113 static const struct tty_operations acm_ops
= {
2114 .install
= acm_tty_install
,
2115 .open
= acm_tty_open
,
2116 .close
= acm_tty_close
,
2117 .cleanup
= acm_tty_cleanup
,
2118 .hangup
= acm_tty_hangup
,
2119 .write
= acm_tty_write
,
2120 .write_room
= acm_tty_write_room
,
2121 .ioctl
= acm_tty_ioctl
,
2122 .throttle
= acm_tty_throttle
,
2123 .unthrottle
= acm_tty_unthrottle
,
2124 .chars_in_buffer
= acm_tty_chars_in_buffer
,
2125 .break_ctl
= acm_tty_break_ctl
,
2126 .set_termios
= acm_tty_set_termios
,
2127 .tiocmget
= acm_tty_tiocmget
,
2128 .tiocmset
= acm_tty_tiocmset
,
2135 static int __init
acm_init(void)
2138 #ifdef CONFIG_MTK_DT_USB_SUPPORT
2141 acm_tty_driver
= alloc_tty_driver(ACM_TTY_MINORS
);
2142 if (!acm_tty_driver
)
2144 acm_tty_driver
->driver_name
= "acm",
2145 acm_tty_driver
->name
= "ttyACM",
2146 acm_tty_driver
->major
= ACM_TTY_MAJOR
,
2147 acm_tty_driver
->minor_start
= 0,
2148 acm_tty_driver
->type
= TTY_DRIVER_TYPE_SERIAL
,
2149 acm_tty_driver
->subtype
= SERIAL_TYPE_NORMAL
,
2150 acm_tty_driver
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
;
2151 acm_tty_driver
->init_termios
= tty_std_termios
;
2152 acm_tty_driver
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
|
2154 #ifdef CONFIG_MTK_DT_USB_SUPPORT
2155 /* wx, disable echo and other flags in the very beginning.
2156 * otherwise RILD will disable them via calling tcsetattr() after it opened tty port,
2157 * so there may be a gap between port opening and calling tcsetattr(). If modem send data
2158 * at that time, things goes ugly.
2160 acm_tty_driver
->init_termios
.c_iflag
= 0;
2161 acm_tty_driver
->init_termios
.c_oflag
= 0;
2162 acm_tty_driver
->init_termios
.c_lflag
= 0;
2163 for(i
= 0; i
< CB_NUM
; i
++){
2164 callback_check_timeout
[i
] = jiffies
;
2167 tty_set_operations(acm_tty_driver
, &acm_ops
);
2169 retval
= tty_register_driver(acm_tty_driver
);
2171 put_tty_driver(acm_tty_driver
);
2175 retval
= usb_register(&acm_driver
);
2177 tty_unregister_driver(acm_tty_driver
);
2178 put_tty_driver(acm_tty_driver
);
2182 printk(KERN_INFO KBUILD_MODNAME
": " DRIVER_DESC
"\n");
2187 static void __exit
acm_exit(void)
2189 usb_deregister(&acm_driver
);
2190 tty_unregister_driver(acm_tty_driver
);
2191 put_tty_driver(acm_tty_driver
);
2194 module_init(acm_init
);
2195 module_exit(acm_exit
);
2196 #ifdef CONFIG_MTK_DT_USB_SUPPORT
2197 module_param(enable_debug
, int, 0644);
2198 module_param(enable_dump
, int, 0644);
2201 MODULE_AUTHOR(DRIVER_AUTHOR
);
2202 MODULE_DESCRIPTION(DRIVER_DESC
);
2203 MODULE_LICENSE("GPL");
2204 MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR
);