blob: 25bc1d6e7d5873795c3289dff99b4bd4dd9a26bb [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
2 * cdc-acm.c
3 *
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>
11 *
12 * USB Abstract Control Model driver for USB modems and ISDN adapters
13 *
14 * Sponsored by SuSE
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 */
30
31#undef DEBUG
32#undef VERBOSE_DEBUG
33
34#include <linux/kernel.h>
35#include <linux/errno.h>
36#include <linux/init.h>
37#include <linux/slab.h>
38#include <linux/tty.h>
39#include <linux/serial.h>
40#include <linux/tty_driver.h>
41#include <linux/tty_flip.h>
42#include <linux/serial.h>
43#include <linux/module.h>
44#include <linux/mutex.h>
45#include <linux/uaccess.h>
46#include <linux/usb.h>
47#include <linux/usb/cdc.h>
48#include <asm/byteorder.h>
49#include <asm/unaligned.h>
50#include <linux/list.h>
51
52#include "cdc-acm.h"
53
54
55#define DRIVER_AUTHOR "Armin Fuerst, Pavel Machek, Johannes Erdfelt, Vojtech Pavlik, David Kubicek, Johan Hovold"
56#define DRIVER_DESC "USB Abstract Control Model driver for USB modems and ISDN adapters"
57
58static struct usb_driver acm_driver;
59static struct tty_driver *acm_tty_driver;
60static struct acm *acm_table[ACM_TTY_MINORS];
61
62static DEFINE_MUTEX(acm_table_lock);
63
64/*
65 * acm_table accessors
66 */
67
68/*
69 * Look up an ACM structure by index. If found and not disconnected, increment
70 * its refcount and return it with its mutex held.
71 */
72static struct acm *acm_get_by_index(unsigned index)
73{
74 struct acm *acm;
75
76 mutex_lock(&acm_table_lock);
77 acm = acm_table[index];
78 if (acm) {
79 mutex_lock(&acm->mutex);
80 if (acm->disconnected) {
81 mutex_unlock(&acm->mutex);
82 acm = NULL;
83 } else {
84 tty_port_get(&acm->port);
85 mutex_unlock(&acm->mutex);
86 }
87 }
88 mutex_unlock(&acm_table_lock);
89 return acm;
90}
91
92/*
93 * Try to find an available minor number and if found, associate it with 'acm'.
94 */
95static int acm_alloc_minor(struct acm *acm)
96{
97 int minor;
98
99 mutex_lock(&acm_table_lock);
100 for (minor = 0; minor < ACM_TTY_MINORS; minor++) {
101 if (!acm_table[minor]) {
102 acm_table[minor] = acm;
103 break;
104 }
105 }
106 mutex_unlock(&acm_table_lock);
107
108 return minor;
109}
110
111/* Release the minor number associated with 'acm'. */
112static void acm_release_minor(struct acm *acm)
113{
114 mutex_lock(&acm_table_lock);
115 acm_table[acm->minor] = NULL;
116 mutex_unlock(&acm_table_lock);
117}
118
119/*
120 * Functions for ACM control messages.
121 */
122
123static int acm_ctrl_msg(struct acm *acm, int request, int value,
124 void *buf, int len)
125{
126 int retval;
127
128 retval = usb_autopm_get_interface(acm->control);
129 if (retval)
130 return retval;
131
132 retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0),
133 request, USB_RT_ACM, value,
134 acm->control->altsetting[0].desc.bInterfaceNumber,
135 buf, len, 5000);
136
137 dev_dbg(&acm->control->dev,
138 "%s - rq 0x%02x, val %#x, len %#x, result %d\n",
139 __func__, request, value, len, retval);
140
141 usb_autopm_put_interface(acm->control);
142
143 return retval < 0 ? retval : 0;
144}
145
146/* devices aren't required to support these requests.
147 * the cdc acm descriptor tells whether they do...
148 */
149#define acm_set_control(acm, control) \
150 acm_ctrl_msg(acm, USB_CDC_REQ_SET_CONTROL_LINE_STATE, control, NULL, 0)
151#define acm_set_line(acm, line) \
152 acm_ctrl_msg(acm, USB_CDC_REQ_SET_LINE_CODING, 0, line, sizeof *(line))
153#define acm_send_break(acm, ms) \
154 acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0)
155
156/*
157 * Write buffer management.
158 * All of these assume proper locks taken by the caller.
159 */
160
161static int acm_wb_alloc(struct acm *acm)
162{
163 int i, wbn;
164 struct acm_wb *wb;
165
166 wbn = 0;
167 i = 0;
168 for (;;) {
169 wb = &acm->wb[wbn];
170 if (!wb->use) {
171 wb->use = 1;
172 return wbn;
173 }
174 wbn = (wbn + 1) % ACM_NW;
175 if (++i >= ACM_NW)
176 return -1;
177 }
178}
179
180static int acm_wb_is_avail(struct acm *acm)
181{
182 int i, n;
183 unsigned long flags;
184
185 n = ACM_NW;
186 spin_lock_irqsave(&acm->write_lock, flags);
187 for (i = 0; i < ACM_NW; i++)
188 n -= acm->wb[i].use;
189 spin_unlock_irqrestore(&acm->write_lock, flags);
190 return n;
191}
192
193/*
194 * Finish write. Caller must hold acm->write_lock
195 */
196static void acm_write_done(struct acm *acm, struct acm_wb *wb)
197{
198 wb->use = 0;
199 acm->transmitting--;
200 usb_autopm_put_interface_async(acm->control);
201}
202
203/*
204 * Poke write.
205 *
206 * the caller is responsible for locking
207 */
208
209static int acm_start_wb(struct acm *acm, struct acm_wb *wb)
210{
211 int rc;
212
213 acm->transmitting++;
214
215 wb->urb->transfer_buffer = wb->buf;
216 wb->urb->transfer_dma = wb->dmah;
217 wb->urb->transfer_buffer_length = wb->len;
218 wb->urb->dev = acm->dev;
219
220 rc = usb_submit_urb(wb->urb, GFP_ATOMIC);
221 if (rc < 0) {
222 dev_err(&acm->data->dev,
223 "%s - usb_submit_urb(write bulk) failed: %d\n",
224 __func__, rc);
225 acm_write_done(acm, wb);
226 }
227 return rc;
228}
229
230static int acm_write_start(struct acm *acm, int wbn)
231{
232 unsigned long flags;
233 struct acm_wb *wb = &acm->wb[wbn];
234 int rc;
235
236 spin_lock_irqsave(&acm->write_lock, flags);
237 if (!acm->dev) {
238 wb->use = 0;
239 spin_unlock_irqrestore(&acm->write_lock, flags);
240 return -ENODEV;
241 }
242
243 dev_vdbg(&acm->data->dev, "%s - susp_count %d\n", __func__,
244 acm->susp_count);
245 usb_autopm_get_interface_async(acm->control);
246 if (acm->susp_count) {
247 usb_anchor_urb(wb->urb, &acm->delayed);
248 spin_unlock_irqrestore(&acm->write_lock, flags);
249 return 0;
250 }
251 usb_mark_last_busy(acm->dev);
252
253 rc = acm_start_wb(acm, wb);
254 spin_unlock_irqrestore(&acm->write_lock, flags);
255
256 return rc;
257
258}
259/*
260 * attributes exported through sysfs
261 */
262static ssize_t show_caps
263(struct device *dev, struct device_attribute *attr, char *buf)
264{
265 struct usb_interface *intf = to_usb_interface(dev);
266 struct acm *acm = usb_get_intfdata(intf);
267
268 return sprintf(buf, "%d", acm->ctrl_caps);
269}
270static DEVICE_ATTR(bmCapabilities, S_IRUGO, show_caps, NULL);
271
272static ssize_t show_country_codes
273(struct device *dev, struct device_attribute *attr, char *buf)
274{
275 struct usb_interface *intf = to_usb_interface(dev);
276 struct acm *acm = usb_get_intfdata(intf);
277
278 memcpy(buf, acm->country_codes, acm->country_code_size);
279 return acm->country_code_size;
280}
281
282static DEVICE_ATTR(wCountryCodes, S_IRUGO, show_country_codes, NULL);
283
284static ssize_t show_country_rel_date
285(struct device *dev, struct device_attribute *attr, char *buf)
286{
287 struct usb_interface *intf = to_usb_interface(dev);
288 struct acm *acm = usb_get_intfdata(intf);
289
290 return sprintf(buf, "%d", acm->country_rel_date);
291}
292
293static DEVICE_ATTR(iCountryCodeRelDate, S_IRUGO, show_country_rel_date, NULL);
294/*
295 * Interrupt handlers for various ACM device responses
296 */
297
298/* control interface reports status changes with "interrupt" transfers */
299static void acm_ctrl_irq(struct urb *urb)
300{
301 struct acm *acm = urb->context;
302 struct usb_cdc_notification *dr = urb->transfer_buffer;
303 struct tty_struct *tty;
304 unsigned char *data;
305 int newctrl;
306 int retval;
307 int status = urb->status;
308
309 switch (status) {
310 case 0:
311 /* success */
312 break;
313 case -ECONNRESET:
314 case -ENOENT:
315 case -ESHUTDOWN:
316 /* this urb is terminated, clean up */
317 dev_dbg(&acm->control->dev,
318 "%s - urb shutting down with status: %d\n",
319 __func__, status);
320 return;
321 default:
322 dev_dbg(&acm->control->dev,
323 "%s - nonzero urb status received: %d\n",
324 __func__, status);
325 goto exit;
326 }
327
328 usb_mark_last_busy(acm->dev);
329
330 data = (unsigned char *)(dr + 1);
331 switch (dr->bNotificationType) {
332 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
333 dev_dbg(&acm->control->dev, "%s - network connection: %d\n",
334 __func__, dr->wValue);
335 break;
336
337 case USB_CDC_NOTIFY_SERIAL_STATE:
338 tty = tty_port_tty_get(&acm->port);
339 newctrl = get_unaligned_le16(data);
340
341 if (tty) {
342 if (!acm->clocal &&
343 (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) {
344 dev_dbg(&acm->control->dev,
345 "%s - calling hangup\n", __func__);
346 tty_hangup(tty);
347 }
348 tty_kref_put(tty);
349 }
350
351 acm->ctrlin = newctrl;
352
353 dev_dbg(&acm->control->dev,
354 "%s - input control lines: dcd%c dsr%c break%c "
355 "ring%c framing%c parity%c overrun%c\n",
356 __func__,
357 acm->ctrlin & ACM_CTRL_DCD ? '+' : '-',
358 acm->ctrlin & ACM_CTRL_DSR ? '+' : '-',
359 acm->ctrlin & ACM_CTRL_BRK ? '+' : '-',
360 acm->ctrlin & ACM_CTRL_RI ? '+' : '-',
361 acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-',
362 acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-',
363 acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-');
364 break;
365
366 default:
367 dev_dbg(&acm->control->dev,
368 "%s - unknown notification %d received: index %d "
369 "len %d data0 %d data1 %d\n",
370 __func__,
371 dr->bNotificationType, dr->wIndex,
372 dr->wLength, data[0], data[1]);
373 break;
374 }
375exit:
376 retval = usb_submit_urb(urb, GFP_ATOMIC);
377 if (retval)
378 dev_err(&acm->control->dev, "%s - usb_submit_urb failed: %d\n",
379 __func__, retval);
380}
381
382static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags)
383{
384 int res;
385
386 if (!test_and_clear_bit(index, &acm->read_urbs_free))
387 return 0;
388
389 dev_vdbg(&acm->data->dev, "%s - urb %d\n", __func__, index);
390
391 res = usb_submit_urb(acm->read_urbs[index], mem_flags);
392 if (res) {
393 if (res != -EPERM) {
394 dev_err(&acm->data->dev,
395 "%s - usb_submit_urb failed: %d\n",
396 __func__, res);
397 }
398 set_bit(index, &acm->read_urbs_free);
399 return res;
400 }
401
402 return 0;
403}
404
405static int acm_submit_read_urbs(struct acm *acm, gfp_t mem_flags)
406{
407 int res;
408 int i;
409
410 for (i = 0; i < acm->rx_buflimit; ++i) {
411 res = acm_submit_read_urb(acm, i, mem_flags);
412 if (res)
413 return res;
414 }
415
416 return 0;
417}
418
419static void acm_process_read_urb(struct acm *acm, struct urb *urb)
420{
421 struct tty_struct *tty;
422
423 if (!urb->actual_length)
424 return;
425
426 tty = tty_port_tty_get(&acm->port);
427 if (!tty)
428 return;
429
430 tty_insert_flip_string(tty, urb->transfer_buffer, urb->actual_length);
431 tty_flip_buffer_push(tty);
432
433 tty_kref_put(tty);
434}
435
436static void acm_read_bulk_callback(struct urb *urb)
437{
438 struct acm_rb *rb = urb->context;
439 struct acm *acm = rb->instance;
440 unsigned long flags;
441
442 dev_vdbg(&acm->data->dev, "%s - urb %d, len %d\n", __func__,
443 rb->index, urb->actual_length);
444 set_bit(rb->index, &acm->read_urbs_free);
445
446 if (!acm->dev) {
447 dev_dbg(&acm->data->dev, "%s - disconnected\n", __func__);
448 return;
449 }
450 usb_mark_last_busy(acm->dev);
451
452 if (urb->status) {
453 dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n",
454 __func__, urb->status);
455 return;
456 }
457 acm_process_read_urb(acm, urb);
458
459 /* throttle device if requested by tty */
460 spin_lock_irqsave(&acm->read_lock, flags);
461 acm->throttled = acm->throttle_req;
462 if (!acm->throttled && !acm->susp_count) {
463 spin_unlock_irqrestore(&acm->read_lock, flags);
464 acm_submit_read_urb(acm, rb->index, GFP_ATOMIC);
465 } else {
466 spin_unlock_irqrestore(&acm->read_lock, flags);
467 }
468}
469
470/* data interface wrote those outgoing bytes */
471static void acm_write_bulk(struct urb *urb)
472{
473 struct acm_wb *wb = urb->context;
474 struct acm *acm = wb->instance;
475 unsigned long flags;
476
477 if (urb->status || (urb->actual_length != urb->transfer_buffer_length))
478 dev_vdbg(&acm->data->dev, "%s - len %d/%d, status %d\n",
479 __func__,
480 urb->actual_length,
481 urb->transfer_buffer_length,
482 urb->status);
483
484 spin_lock_irqsave(&acm->write_lock, flags);
485 acm_write_done(acm, wb);
486 spin_unlock_irqrestore(&acm->write_lock, flags);
487 schedule_work(&acm->work);
488}
489
490static void acm_softint(struct work_struct *work)
491{
492 struct acm *acm = container_of(work, struct acm, work);
493 struct tty_struct *tty;
494
495 dev_vdbg(&acm->data->dev, "%s\n", __func__);
496
497 tty = tty_port_tty_get(&acm->port);
498 if (!tty)
499 return;
500 tty_wakeup(tty);
501 tty_kref_put(tty);
502}
503
504/*
505 * TTY handlers
506 */
507
508static int acm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
509{
510 struct acm *acm;
511 int retval;
512
513 dev_dbg(tty->dev, "%s\n", __func__);
514
515 acm = acm_get_by_index(tty->index);
516 if (!acm)
517 return -ENODEV;
518
519 retval = tty_standard_install(driver, tty);
520 if (retval)
521 goto error_init_termios;
522
523 tty->driver_data = acm;
524
525 return 0;
526
527error_init_termios:
528 tty_port_put(&acm->port);
529 return retval;
530}
531
532static int acm_tty_open(struct tty_struct *tty, struct file *filp)
533{
534 struct acm *acm = tty->driver_data;
535
536 dev_dbg(tty->dev, "%s\n", __func__);
537
538 return tty_port_open(&acm->port, tty, filp);
539}
540
541static int acm_port_activate(struct tty_port *port, struct tty_struct *tty)
542{
543 struct acm *acm = container_of(port, struct acm, port);
544 int retval = -ENODEV;
545 int i;
546
547 dev_dbg(&acm->control->dev, "%s\n", __func__);
548
549 mutex_lock(&acm->mutex);
550 if (acm->disconnected)
551 goto disconnected;
552
553 retval = usb_autopm_get_interface(acm->control);
554 if (retval)
555 goto error_get_interface;
556
557 /*
558 * FIXME: Why do we need this? Allocating 64K of physically contiguous
559 * memory is really nasty...
560 */
561 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags);
562 acm->control->needs_remote_wakeup = 1;
563
564 acm->ctrlurb->dev = acm->dev;
565 if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) {
566 dev_err(&acm->control->dev,
567 "%s - usb_submit_urb(ctrl irq) failed\n", __func__);
568 goto error_submit_urb;
569 }
570
571 acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS;
572 if (acm_set_control(acm, acm->ctrlout) < 0 &&
573 (acm->ctrl_caps & USB_CDC_CAP_LINE))
574 goto error_set_control;
575
576 usb_autopm_put_interface(acm->control);
577
578 /*
579 * Unthrottle device in case the TTY was closed while throttled.
580 */
581 spin_lock_irq(&acm->read_lock);
582 acm->throttled = 0;
583 acm->throttle_req = 0;
584 spin_unlock_irq(&acm->read_lock);
585
586 if (acm_submit_read_urbs(acm, GFP_KERNEL))
587 goto error_submit_read_urbs;
588
589 mutex_unlock(&acm->mutex);
590
591 return 0;
592
593error_submit_read_urbs:
594 for (i = 0; i < acm->rx_buflimit; i++)
595 usb_kill_urb(acm->read_urbs[i]);
596 acm->ctrlout = 0;
597 acm_set_control(acm, acm->ctrlout);
598error_set_control:
599 usb_kill_urb(acm->ctrlurb);
600error_submit_urb:
601 usb_autopm_put_interface(acm->control);
602error_get_interface:
603disconnected:
604 mutex_unlock(&acm->mutex);
605 return retval;
606}
607
608static void acm_port_destruct(struct tty_port *port)
609{
610 struct acm *acm = container_of(port, struct acm, port);
611
612 dev_dbg(&acm->control->dev, "%s\n", __func__);
613
614 acm_release_minor(acm);
615 usb_put_intf(acm->control);
616 kfree(acm->country_codes);
617 kfree(acm);
618}
619
620static void acm_port_shutdown(struct tty_port *port)
621{
622 struct acm *acm = container_of(port, struct acm, port);
623 struct urb *urb;
624 struct acm_wb *wb;
625 int i;
626 int pm_err;
627
628 dev_dbg(&acm->control->dev, "%s\n", __func__);
629
630 mutex_lock(&acm->mutex);
631 if (!acm->disconnected) {
632 pm_err = usb_autopm_get_interface(acm->control);
633 acm_set_control(acm, acm->ctrlout = 0);
634
635 for (;;) {
636 urb = usb_get_from_anchor(&acm->delayed);
637 if (!urb)
638 break;
639 wb = urb->context;
640 wb->use = 0;
641 usb_autopm_put_interface_async(acm->control);
642 }
643
644 usb_kill_urb(acm->ctrlurb);
645 for (i = 0; i < ACM_NW; i++)
646 usb_kill_urb(acm->wb[i].urb);
647 for (i = 0; i < acm->rx_buflimit; i++)
648 usb_kill_urb(acm->read_urbs[i]);
649 acm->control->needs_remote_wakeup = 0;
650 if (!pm_err)
651 usb_autopm_put_interface(acm->control);
652 }
653 mutex_unlock(&acm->mutex);
654}
655
656static void acm_tty_cleanup(struct tty_struct *tty)
657{
658 struct acm *acm = tty->driver_data;
659 dev_dbg(&acm->control->dev, "%s\n", __func__);
660 tty_port_put(&acm->port);
661}
662
663static void acm_tty_hangup(struct tty_struct *tty)
664{
665 struct acm *acm = tty->driver_data;
666 dev_dbg(&acm->control->dev, "%s\n", __func__);
667 tty_port_hangup(&acm->port);
668}
669
670static void acm_tty_close(struct tty_struct *tty, struct file *filp)
671{
672 struct acm *acm = tty->driver_data;
673 dev_dbg(&acm->control->dev, "%s\n", __func__);
674 tty_port_close(&acm->port, tty, filp);
675}
676
677static int acm_tty_write(struct tty_struct *tty,
678 const unsigned char *buf, int count)
679{
680 struct acm *acm = tty->driver_data;
681 int stat;
682 unsigned long flags;
683 int wbn;
684 struct acm_wb *wb;
685
686 if (!count)
687 return 0;
688
689 dev_vdbg(&acm->data->dev, "%s - count %d\n", __func__, count);
690
691 spin_lock_irqsave(&acm->write_lock, flags);
692 wbn = acm_wb_alloc(acm);
693 if (wbn < 0) {
694 spin_unlock_irqrestore(&acm->write_lock, flags);
695 return 0;
696 }
697 wb = &acm->wb[wbn];
698
699 count = (count > acm->writesize) ? acm->writesize : count;
700 dev_vdbg(&acm->data->dev, "%s - write %d\n", __func__, count);
701 memcpy(wb->buf, buf, count);
702 wb->len = count;
703 spin_unlock_irqrestore(&acm->write_lock, flags);
704
705 stat = acm_write_start(acm, wbn);
706 if (stat < 0)
707 return stat;
708 return count;
709}
710
711static int acm_tty_write_room(struct tty_struct *tty)
712{
713 struct acm *acm = tty->driver_data;
714 /*
715 * Do not let the line discipline to know that we have a reserve,
716 * or it might get too enthusiastic.
717 */
718 return acm_wb_is_avail(acm) ? acm->writesize : 0;
719}
720
721static int acm_tty_chars_in_buffer(struct tty_struct *tty)
722{
723 struct acm *acm = tty->driver_data;
724 /*
725 * if the device was unplugged then any remaining characters fell out
726 * of the connector ;)
727 */
728 if (acm->disconnected)
729 return 0;
730 /*
731 * This is inaccurate (overcounts), but it works.
732 */
733 return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize;
734}
735
736static void acm_tty_throttle(struct tty_struct *tty)
737{
738 struct acm *acm = tty->driver_data;
739
740 spin_lock_irq(&acm->read_lock);
741 acm->throttle_req = 1;
742 spin_unlock_irq(&acm->read_lock);
743}
744
745static void acm_tty_unthrottle(struct tty_struct *tty)
746{
747 struct acm *acm = tty->driver_data;
748 unsigned int was_throttled;
749
750 spin_lock_irq(&acm->read_lock);
751 was_throttled = acm->throttled;
752 acm->throttled = 0;
753 acm->throttle_req = 0;
754 spin_unlock_irq(&acm->read_lock);
755
756 if (was_throttled)
757 acm_submit_read_urbs(acm, GFP_KERNEL);
758}
759
760static int acm_tty_break_ctl(struct tty_struct *tty, int state)
761{
762 struct acm *acm = tty->driver_data;
763 int retval;
764
765 retval = acm_send_break(acm, state ? 0xffff : 0);
766 if (retval < 0)
767 dev_dbg(&acm->control->dev, "%s - send break failed\n",
768 __func__);
769 return retval;
770}
771
772static int acm_tty_tiocmget(struct tty_struct *tty)
773{
774 struct acm *acm = tty->driver_data;
775
776 return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) |
777 (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) |
778 (acm->ctrlin & ACM_CTRL_DSR ? TIOCM_DSR : 0) |
779 (acm->ctrlin & ACM_CTRL_RI ? TIOCM_RI : 0) |
780 (acm->ctrlin & ACM_CTRL_DCD ? TIOCM_CD : 0) |
781 TIOCM_CTS;
782}
783
784static int acm_tty_tiocmset(struct tty_struct *tty,
785 unsigned int set, unsigned int clear)
786{
787 struct acm *acm = tty->driver_data;
788 unsigned int newctrl;
789
790 newctrl = acm->ctrlout;
791 set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) |
792 (set & TIOCM_RTS ? ACM_CTRL_RTS : 0);
793 clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) |
794 (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0);
795
796 newctrl = (newctrl & ~clear) | set;
797
798 if (acm->ctrlout == newctrl)
799 return 0;
800 return acm_set_control(acm, acm->ctrlout = newctrl);
801}
802
803static int get_serial_info(struct acm *acm, struct serial_struct __user *info)
804{
805 struct serial_struct tmp;
806
807 if (!info)
808 return -EINVAL;
809
810 memset(&tmp, 0, sizeof(tmp));
811 tmp.flags = ASYNC_LOW_LATENCY;
812 tmp.xmit_fifo_size = acm->writesize;
813 tmp.baud_base = le32_to_cpu(acm->line.dwDTERate);
814 tmp.close_delay = acm->port.close_delay / 10;
815 tmp.closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
816 ASYNC_CLOSING_WAIT_NONE :
817 acm->port.closing_wait / 10;
818
819 if (copy_to_user(info, &tmp, sizeof(tmp)))
820 return -EFAULT;
821 else
822 return 0;
823}
824
825static int set_serial_info(struct acm *acm,
826 struct serial_struct __user *newinfo)
827{
828 struct serial_struct new_serial;
829 unsigned int closing_wait, close_delay;
830 int retval = 0;
831
832 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
833 return -EFAULT;
834
835 close_delay = new_serial.close_delay * 10;
836 closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
837 ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10;
838
839 mutex_lock(&acm->port.mutex);
840
841 if (!capable(CAP_SYS_ADMIN)) {
842 if ((close_delay != acm->port.close_delay) ||
843 (closing_wait != acm->port.closing_wait))
844 retval = -EPERM;
845 else
846 retval = -EOPNOTSUPP;
847 } else {
848 acm->port.close_delay = close_delay;
849 acm->port.closing_wait = closing_wait;
850 }
851
852 mutex_unlock(&acm->port.mutex);
853 return retval;
854}
855
856static int acm_tty_ioctl(struct tty_struct *tty,
857 unsigned int cmd, unsigned long arg)
858{
859 struct acm *acm = tty->driver_data;
860 int rv = -ENOIOCTLCMD;
861
862 switch (cmd) {
863 case TIOCGSERIAL: /* gets serial port data */
864 rv = get_serial_info(acm, (struct serial_struct __user *) arg);
865 break;
866 case TIOCSSERIAL:
867 rv = set_serial_info(acm, (struct serial_struct __user *) arg);
868 break;
869 }
870
871 return rv;
872}
873
874static const __u32 acm_tty_speed[] = {
875 0, 50, 75, 110, 134, 150, 200, 300, 600,
876 1200, 1800, 2400, 4800, 9600, 19200, 38400,
877 57600, 115200, 230400, 460800, 500000, 576000,
878 921600, 1000000, 1152000, 1500000, 2000000,
879 2500000, 3000000, 3500000, 4000000
880};
881
882static void acm_tty_set_termios(struct tty_struct *tty,
883 struct ktermios *termios_old)
884{
885 struct acm *acm = tty->driver_data;
886 struct ktermios *termios = tty->termios;
887 struct usb_cdc_line_coding newline;
888 int newctrl = acm->ctrlout;
889
890 newline.dwDTERate = cpu_to_le32(tty_get_baud_rate(tty));
891 newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0;
892 newline.bParityType = termios->c_cflag & PARENB ?
893 (termios->c_cflag & PARODD ? 1 : 2) +
894 (termios->c_cflag & CMSPAR ? 2 : 0) : 0;
895 switch (termios->c_cflag & CSIZE) {
896 case CS5:
897 newline.bDataBits = 5;
898 break;
899 case CS6:
900 newline.bDataBits = 6;
901 break;
902 case CS7:
903 newline.bDataBits = 7;
904 break;
905 case CS8:
906 default:
907 newline.bDataBits = 8;
908 break;
909 }
910 /* FIXME: Needs to clear unsupported bits in the termios */
911 acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
912
913 if (C_BAUD(tty) == B0) {
914 newline.dwDTERate = acm->line.dwDTERate;
915 newctrl &= ~ACM_CTRL_DTR;
916 } else if (termios_old && (termios_old->c_cflag & CBAUD) == B0) {
917 newctrl |= ACM_CTRL_DTR;
918 }
919
920 if (newctrl != acm->ctrlout)
921 acm_set_control(acm, acm->ctrlout = newctrl);
922
923 if (memcmp(&acm->line, &newline, sizeof newline)) {
924 memcpy(&acm->line, &newline, sizeof newline);
925 dev_dbg(&acm->control->dev, "%s - set line: %d %d %d %d\n",
926 __func__,
927 le32_to_cpu(newline.dwDTERate),
928 newline.bCharFormat, newline.bParityType,
929 newline.bDataBits);
930 acm_set_line(acm, &acm->line);
931 }
932}
933
934static const struct tty_port_operations acm_port_ops = {
935 .shutdown = acm_port_shutdown,
936 .activate = acm_port_activate,
937 .destruct = acm_port_destruct,
938};
939
940/*
941 * USB probe and disconnect routines.
942 */
943
944/* Little helpers: write/read buffers free */
945static void acm_write_buffers_free(struct acm *acm)
946{
947 int i;
948 struct acm_wb *wb;
949 struct usb_device *usb_dev = interface_to_usbdev(acm->control);
950
951 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++)
952 usb_free_coherent(usb_dev, acm->writesize, wb->buf, wb->dmah);
953}
954
955static void acm_read_buffers_free(struct acm *acm)
956{
957 struct usb_device *usb_dev = interface_to_usbdev(acm->control);
958 int i;
959
960 for (i = 0; i < acm->rx_buflimit; i++)
961 usb_free_coherent(usb_dev, acm->readsize,
962 acm->read_buffers[i].base, acm->read_buffers[i].dma);
963}
964
965/* Little helper: write buffers allocate */
966static int acm_write_buffers_alloc(struct acm *acm)
967{
968 int i;
969 struct acm_wb *wb;
970
971 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) {
972 wb->buf = usb_alloc_coherent(acm->dev, acm->writesize, GFP_KERNEL,
973 &wb->dmah);
974 if (!wb->buf) {
975 while (i != 0) {
976 --i;
977 --wb;
978 usb_free_coherent(acm->dev, acm->writesize,
979 wb->buf, wb->dmah);
980 }
981 return -ENOMEM;
982 }
983 }
984 return 0;
985}
986
987static int acm_probe(struct usb_interface *intf,
988 const struct usb_device_id *id)
989{
990 struct usb_cdc_union_desc *union_header = NULL;
991 struct usb_cdc_country_functional_desc *cfd = NULL;
992 unsigned char *buffer = intf->altsetting->extra;
993 int buflen = intf->altsetting->extralen;
994 struct usb_interface *control_interface;
995 struct usb_interface *data_interface;
996 struct usb_endpoint_descriptor *epctrl = NULL;
997 struct usb_endpoint_descriptor *epread = NULL;
998 struct usb_endpoint_descriptor *epwrite = NULL;
999 struct usb_device *usb_dev = interface_to_usbdev(intf);
1000 struct acm *acm;
1001 int minor;
1002 int ctrlsize, readsize;
1003 u8 *buf;
1004 u8 ac_management_function = 0;
1005 u8 call_management_function = 0;
1006 int call_interface_num = -1;
1007 int data_interface_num = -1;
1008 unsigned long quirks;
1009 int num_rx_buf;
1010 int i;
1011 unsigned int elength = 0;
1012 int combined_interfaces = 0;
1013
1014 /* normal quirks */
1015 quirks = (unsigned long)id->driver_info;
1016 num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR;
1017
1018 /* handle quirks deadly to normal probing*/
1019 if (quirks == NO_UNION_NORMAL) {
1020 data_interface = usb_ifnum_to_if(usb_dev, 1);
1021 control_interface = usb_ifnum_to_if(usb_dev, 0);
1022 goto skip_normal_probe;
1023 }
1024
1025 /* normal probing*/
1026 if (!buffer) {
1027 dev_err(&intf->dev, "Weird descriptor references\n");
1028 return -EINVAL;
1029 }
1030
1031 if (!buflen) {
1032 if (intf->cur_altsetting->endpoint &&
1033 intf->cur_altsetting->endpoint->extralen &&
1034 intf->cur_altsetting->endpoint->extra) {
1035 dev_dbg(&intf->dev,
1036 "Seeking extra descriptors on endpoint\n");
1037 buflen = intf->cur_altsetting->endpoint->extralen;
1038 buffer = intf->cur_altsetting->endpoint->extra;
1039 } else {
1040 dev_err(&intf->dev,
1041 "Zero length descriptor references\n");
1042 return -EINVAL;
1043 }
1044 }
1045
1046 while (buflen > 0) {
1047 elength = buffer[0];
1048 if (!elength) {
1049 dev_err(&intf->dev, "skipping garbage byte\n");
1050 elength = 1;
1051 goto next_desc;
1052 }
1053 if (buffer[1] != USB_DT_CS_INTERFACE) {
1054 dev_err(&intf->dev, "skipping garbage\n");
1055 goto next_desc;
1056 }
1057
1058 switch (buffer[2]) {
1059 case USB_CDC_UNION_TYPE: /* we've found it */
1060 if (elength < sizeof(struct usb_cdc_union_desc))
1061 goto next_desc;
1062 if (union_header) {
1063 dev_err(&intf->dev, "More than one "
1064 "union descriptor, skipping ...\n");
1065 goto next_desc;
1066 }
1067 union_header = (struct usb_cdc_union_desc *)buffer;
1068 break;
1069 case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/
1070 if (elength < sizeof(struct usb_cdc_country_functional_desc))
1071 goto next_desc;
1072 cfd = (struct usb_cdc_country_functional_desc *)buffer;
1073 break;
1074 case USB_CDC_HEADER_TYPE: /* maybe check version */
1075 break; /* for now we ignore it */
1076 case USB_CDC_ACM_TYPE:
1077 if (elength < 4)
1078 goto next_desc;
1079 ac_management_function = buffer[3];
1080 break;
1081 case USB_CDC_CALL_MANAGEMENT_TYPE:
1082 if (elength < 5)
1083 goto next_desc;
1084 call_management_function = buffer[3];
1085 call_interface_num = buffer[4];
1086 if ( (quirks & NOT_A_MODEM) == 0 && (call_management_function & 3) != 3)
1087 dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n");
1088 break;
1089 default:
1090 /*
1091 * there are LOTS more CDC descriptors that
1092 * could legitimately be found here.
1093 */
1094 dev_dbg(&intf->dev, "Ignoring descriptor: "
1095 "type %02x, length %ud\n",
1096 buffer[2], elength);
1097 break;
1098 }
1099next_desc:
1100 buflen -= elength;
1101 buffer += elength;
1102 }
1103
1104 if (!union_header) {
1105 if (call_interface_num > 0) {
1106 dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n");
1107 /* quirks for Droids MuIn LCD */
1108 if (quirks & NO_DATA_INTERFACE)
1109 data_interface = usb_ifnum_to_if(usb_dev, 0);
1110 else
1111 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num));
1112 control_interface = intf;
1113 } else {
1114 if (intf->cur_altsetting->desc.bNumEndpoints != 3) {
1115 dev_dbg(&intf->dev,"No union descriptor, giving up\n");
1116 return -ENODEV;
1117 } else {
1118 dev_warn(&intf->dev,"No union descriptor, testing for castrated device\n");
1119 combined_interfaces = 1;
1120 control_interface = data_interface = intf;
1121 goto look_for_collapsed_interface;
1122 }
1123 }
1124 } else {
1125 control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0);
1126 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0));
1127 }
1128
1129 if (!control_interface || !data_interface) {
1130 dev_dbg(&intf->dev, "no interfaces\n");
1131 return -ENODEV;
1132 }
1133
1134 if (data_interface_num != call_interface_num)
1135 dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n");
1136
1137 if (control_interface == data_interface) {
1138 /* some broken devices designed for windows work this way */
1139 dev_warn(&intf->dev,"Control and data interfaces are not separated!\n");
1140 combined_interfaces = 1;
1141 /* a popular other OS doesn't use it */
1142 quirks |= NO_CAP_LINE;
1143 if (data_interface->cur_altsetting->desc.bNumEndpoints != 3) {
1144 dev_err(&intf->dev, "This needs exactly 3 endpoints\n");
1145 return -EINVAL;
1146 }
1147look_for_collapsed_interface:
1148 for (i = 0; i < 3; i++) {
1149 struct usb_endpoint_descriptor *ep;
1150 ep = &data_interface->cur_altsetting->endpoint[i].desc;
1151
1152 if (usb_endpoint_is_int_in(ep))
1153 epctrl = ep;
1154 else if (usb_endpoint_is_bulk_out(ep))
1155 epwrite = ep;
1156 else if (usb_endpoint_is_bulk_in(ep))
1157 epread = ep;
1158 else
1159 return -EINVAL;
1160 }
1161 if (!epctrl || !epread || !epwrite)
1162 return -ENODEV;
1163 else
1164 goto made_compressed_probe;
1165 }
1166
1167skip_normal_probe:
1168
1169 /*workaround for switched interfaces */
1170 if (data_interface->cur_altsetting->desc.bInterfaceClass
1171 != CDC_DATA_INTERFACE_TYPE) {
1172 if (control_interface->cur_altsetting->desc.bInterfaceClass
1173 == CDC_DATA_INTERFACE_TYPE) {
1174 struct usb_interface *t;
1175 dev_dbg(&intf->dev,
1176 "Your device has switched interfaces.\n");
1177 t = control_interface;
1178 control_interface = data_interface;
1179 data_interface = t;
1180 } else {
1181 return -EINVAL;
1182 }
1183 }
1184
1185 /* Accept probe requests only for the control interface */
1186 if (!combined_interfaces && intf != control_interface)
1187 return -ENODEV;
1188
1189 if (!combined_interfaces && usb_interface_claimed(data_interface)) {
1190 /* valid in this context */
1191 dev_dbg(&intf->dev, "The data interface isn't available\n");
1192 return -EBUSY;
1193 }
1194
1195
1196 if (data_interface->cur_altsetting->desc.bNumEndpoints < 2 ||
1197 control_interface->cur_altsetting->desc.bNumEndpoints == 0)
1198 return -EINVAL;
1199
1200 epctrl = &control_interface->cur_altsetting->endpoint[0].desc;
1201 epread = &data_interface->cur_altsetting->endpoint[0].desc;
1202 epwrite = &data_interface->cur_altsetting->endpoint[1].desc;
1203
1204
1205 /* workaround for switched endpoints */
1206 if (!usb_endpoint_dir_in(epread)) {
1207 /* descriptors are swapped */
1208 struct usb_endpoint_descriptor *t;
1209 dev_dbg(&intf->dev,
1210 "The data interface has switched endpoints\n");
1211 t = epread;
1212 epread = epwrite;
1213 epwrite = t;
1214 }
1215made_compressed_probe:
1216 dev_dbg(&intf->dev, "interfaces are valid\n");
1217
1218 acm = kzalloc(sizeof(struct acm), GFP_KERNEL);
1219 if (acm == NULL) {
1220 dev_err(&intf->dev, "out of memory (acm kzalloc)\n");
1221 goto alloc_fail;
1222 }
1223
1224 minor = acm_alloc_minor(acm);
1225 if (minor == ACM_TTY_MINORS) {
1226 dev_err(&intf->dev, "no more free acm devices\n");
1227 kfree(acm);
1228 return -ENODEV;
1229 }
1230
1231 ctrlsize = usb_endpoint_maxp(epctrl);
1232 readsize = usb_endpoint_maxp(epread) *
1233 (quirks == SINGLE_RX_URB ? 1 : 2);
1234 acm->combined_interfaces = combined_interfaces;
1235 acm->writesize = usb_endpoint_maxp(epwrite) * 20;
1236 acm->control = control_interface;
1237 acm->data = data_interface;
1238 acm->minor = minor;
1239 acm->dev = usb_dev;
1240 acm->ctrl_caps = ac_management_function;
1241 if (quirks & NO_CAP_LINE)
1242 acm->ctrl_caps &= ~USB_CDC_CAP_LINE;
1243 acm->ctrlsize = ctrlsize;
1244 acm->readsize = readsize;
1245 acm->rx_buflimit = num_rx_buf;
1246 INIT_WORK(&acm->work, acm_softint);
1247 spin_lock_init(&acm->write_lock);
1248 spin_lock_init(&acm->read_lock);
1249 mutex_init(&acm->mutex);
1250 acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress);
1251 acm->is_int_ep = usb_endpoint_xfer_int(epread);
1252 if (acm->is_int_ep)
1253 acm->bInterval = epread->bInterval;
1254 tty_port_init(&acm->port);
1255 acm->port.ops = &acm_port_ops;
1256 init_usb_anchor(&acm->delayed);
1257
1258 buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
1259 if (!buf) {
1260 dev_err(&intf->dev, "out of memory (ctrl buffer alloc)\n");
1261 goto alloc_fail2;
1262 }
1263 acm->ctrl_buffer = buf;
1264
1265 if (acm_write_buffers_alloc(acm) < 0) {
1266 dev_err(&intf->dev, "out of memory (write buffer alloc)\n");
1267 goto alloc_fail4;
1268 }
1269
1270 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);
1271 if (!acm->ctrlurb) {
1272 dev_err(&intf->dev, "out of memory (ctrlurb kmalloc)\n");
1273 goto alloc_fail5;
1274 }
1275 for (i = 0; i < num_rx_buf; i++) {
1276 struct acm_rb *rb = &(acm->read_buffers[i]);
1277 struct urb *urb;
1278
1279 rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL,
1280 &rb->dma);
1281 if (!rb->base) {
1282 dev_err(&intf->dev, "out of memory "
1283 "(read bufs usb_alloc_coherent)\n");
1284 goto alloc_fail6;
1285 }
1286 rb->index = i;
1287 rb->instance = acm;
1288
1289 urb = usb_alloc_urb(0, GFP_KERNEL);
1290 if (!urb) {
1291 dev_err(&intf->dev,
1292 "out of memory (read urbs usb_alloc_urb)\n");
1293 goto alloc_fail6;
1294 }
1295 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1296 urb->transfer_dma = rb->dma;
1297 if (acm->is_int_ep) {
1298 usb_fill_int_urb(urb, acm->dev,
1299 acm->rx_endpoint,
1300 rb->base,
1301 acm->readsize,
1302 acm_read_bulk_callback, rb,
1303 acm->bInterval);
1304 } else {
1305 usb_fill_bulk_urb(urb, acm->dev,
1306 acm->rx_endpoint,
1307 rb->base,
1308 acm->readsize,
1309 acm_read_bulk_callback, rb);
1310 }
1311
1312 acm->read_urbs[i] = urb;
1313 __set_bit(i, &acm->read_urbs_free);
1314 }
1315 for (i = 0; i < ACM_NW; i++) {
1316 struct acm_wb *snd = &(acm->wb[i]);
1317
1318 snd->urb = usb_alloc_urb(0, GFP_KERNEL);
1319 if (snd->urb == NULL) {
1320 dev_err(&intf->dev,
1321 "out of memory (write urbs usb_alloc_urb)\n");
1322 goto alloc_fail7;
1323 }
1324
1325 if (usb_endpoint_xfer_int(epwrite))
1326 usb_fill_int_urb(snd->urb, usb_dev,
1327 usb_sndintpipe(usb_dev, epwrite->bEndpointAddress),
1328 NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval);
1329 else
1330 usb_fill_bulk_urb(snd->urb, usb_dev,
1331 usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
1332 NULL, acm->writesize, acm_write_bulk, snd);
1333 snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1334 snd->instance = acm;
1335 }
1336
1337 usb_set_intfdata(intf, acm);
1338
1339 i = device_create_file(&intf->dev, &dev_attr_bmCapabilities);
1340 if (i < 0)
1341 goto alloc_fail7;
1342
1343 if (cfd) { /* export the country data */
1344 acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL);
1345 if (!acm->country_codes)
1346 goto skip_countries;
1347 acm->country_code_size = cfd->bLength - 4;
1348 memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0,
1349 cfd->bLength - 4);
1350 acm->country_rel_date = cfd->iCountryCodeRelDate;
1351
1352 i = device_create_file(&intf->dev, &dev_attr_wCountryCodes);
1353 if (i < 0) {
1354 kfree(acm->country_codes);
1355 acm->country_codes = NULL;
1356 acm->country_code_size = 0;
1357 goto skip_countries;
1358 }
1359
1360 i = device_create_file(&intf->dev,
1361 &dev_attr_iCountryCodeRelDate);
1362 if (i < 0) {
1363 device_remove_file(&intf->dev, &dev_attr_wCountryCodes);
1364 kfree(acm->country_codes);
1365 acm->country_codes = NULL;
1366 acm->country_code_size = 0;
1367 goto skip_countries;
1368 }
1369 }
1370
1371skip_countries:
1372 usb_fill_int_urb(acm->ctrlurb, usb_dev,
1373 usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress),
1374 acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm,
1375 /* works around buggy devices */
1376 epctrl->bInterval ? epctrl->bInterval : 0xff);
1377 acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1378 acm->ctrlurb->transfer_dma = acm->ctrl_dma;
1379
1380 dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor);
1381
1382 acm_set_control(acm, acm->ctrlout);
1383
1384 acm->line.dwDTERate = cpu_to_le32(9600);
1385 acm->line.bDataBits = 8;
1386 acm_set_line(acm, &acm->line);
1387
1388 usb_driver_claim_interface(&acm_driver, data_interface, acm);
1389 usb_set_intfdata(data_interface, acm);
1390
1391 usb_get_intf(control_interface);
1392 tty_register_device(acm_tty_driver, minor, &control_interface->dev);
1393
1394 return 0;
1395alloc_fail7:
1396 for (i = 0; i < ACM_NW; i++)
1397 usb_free_urb(acm->wb[i].urb);
1398alloc_fail6:
1399 for (i = 0; i < num_rx_buf; i++)
1400 usb_free_urb(acm->read_urbs[i]);
1401 acm_read_buffers_free(acm);
1402 usb_free_urb(acm->ctrlurb);
1403alloc_fail5:
1404 acm_write_buffers_free(acm);
1405alloc_fail4:
1406 usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
1407alloc_fail2:
1408 acm_release_minor(acm);
1409 kfree(acm);
1410alloc_fail:
1411 return -ENOMEM;
1412}
1413
1414static void stop_data_traffic(struct acm *acm)
1415{
1416 int i;
1417
1418 dev_dbg(&acm->control->dev, "%s\n", __func__);
1419
1420 usb_kill_urb(acm->ctrlurb);
1421 for (i = 0; i < ACM_NW; i++)
1422 usb_kill_urb(acm->wb[i].urb);
1423 for (i = 0; i < acm->rx_buflimit; i++)
1424 usb_kill_urb(acm->read_urbs[i]);
1425
1426 cancel_work_sync(&acm->work);
1427}
1428
1429static void acm_disconnect(struct usb_interface *intf)
1430{
1431 struct acm *acm = usb_get_intfdata(intf);
1432 struct usb_device *usb_dev = interface_to_usbdev(intf);
1433 struct tty_struct *tty;
1434 int i;
1435
1436 dev_dbg(&intf->dev, "%s\n", __func__);
1437
1438 /* sibling interface is already cleaning up */
1439 if (!acm)
1440 return;
1441
1442 mutex_lock(&acm->mutex);
1443 acm->disconnected = true;
1444 if (acm->country_codes) {
1445 device_remove_file(&acm->control->dev,
1446 &dev_attr_wCountryCodes);
1447 device_remove_file(&acm->control->dev,
1448 &dev_attr_iCountryCodeRelDate);
1449 kfree(acm->country_codes);
1450 }
1451 device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities);
1452 usb_set_intfdata(acm->control, NULL);
1453 usb_set_intfdata(acm->data, NULL);
1454 mutex_unlock(&acm->mutex);
1455
1456 tty = tty_port_tty_get(&acm->port);
1457 if (tty) {
1458 tty_vhangup(tty);
1459 tty_kref_put(tty);
1460 }
1461
1462 stop_data_traffic(acm);
1463
1464 tty_unregister_device(acm_tty_driver, acm->minor);
1465
1466 usb_free_urb(acm->ctrlurb);
1467 for (i = 0; i < ACM_NW; i++)
1468 usb_free_urb(acm->wb[i].urb);
1469 for (i = 0; i < acm->rx_buflimit; i++)
1470 usb_free_urb(acm->read_urbs[i]);
1471 acm_write_buffers_free(acm);
1472 usb_free_coherent(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
1473 acm_read_buffers_free(acm);
1474
1475 if (!acm->combined_interfaces)
1476 usb_driver_release_interface(&acm_driver, intf == acm->control ?
1477 acm->data : acm->control);
1478
1479 tty_port_put(&acm->port);
1480}
1481
1482#ifdef CONFIG_PM
1483static int acm_suspend(struct usb_interface *intf, pm_message_t message)
1484{
1485 struct acm *acm = usb_get_intfdata(intf);
1486 int cnt;
1487
1488 spin_lock_irq(&acm->read_lock);
1489 spin_lock(&acm->write_lock);
1490 if (PMSG_IS_AUTO(message)) {
1491 if (acm->transmitting) {
1492 spin_unlock(&acm->write_lock);
1493 spin_unlock_irq(&acm->read_lock);
1494 return -EBUSY;
1495 }
1496 }
1497 cnt = acm->susp_count++;
1498 spin_unlock(&acm->write_lock);
1499 spin_unlock_irq(&acm->read_lock);
1500
1501 if (cnt)
1502 return 0;
1503
1504 stop_data_traffic(acm);
1505
1506 return 0;
1507}
1508
1509static int acm_resume(struct usb_interface *intf)
1510{
1511 struct acm *acm = usb_get_intfdata(intf);
1512 struct urb *urb;
1513 int rv = 0;
1514
1515 spin_lock_irq(&acm->read_lock);
1516 spin_lock(&acm->write_lock);
1517
1518 if (--acm->susp_count)
1519 goto out;
1520
1521 if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) {
1522 rv = usb_submit_urb(acm->ctrlurb, GFP_ATOMIC);
1523
1524 for (;;) {
1525 urb = usb_get_from_anchor(&acm->delayed);
1526 if (!urb)
1527 break;
1528
1529 acm_start_wb(acm, urb->context);
1530 }
1531
1532 /*
1533 * delayed error checking because we must
1534 * do the write path at all cost
1535 */
1536 if (rv < 0)
1537 goto out;
1538
1539 rv = acm_submit_read_urbs(acm, GFP_ATOMIC);
1540 }
1541out:
1542 spin_unlock(&acm->write_lock);
1543 spin_unlock_irq(&acm->read_lock);
1544
1545 return rv;
1546}
1547
1548static int acm_reset_resume(struct usb_interface *intf)
1549{
1550 struct acm *acm = usb_get_intfdata(intf);
1551 struct tty_struct *tty;
1552
1553 if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) {
1554 tty = tty_port_tty_get(&acm->port);
1555 if (tty) {
1556 tty_hangup(tty);
1557 tty_kref_put(tty);
1558 }
1559 }
1560
1561 return acm_resume(intf);
1562}
1563
1564#endif /* CONFIG_PM */
1565
1566#define NOKIA_PCSUITE_ACM_INFO(x) \
1567 USB_DEVICE_AND_INTERFACE_INFO(0x0421, x, \
1568 USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \
1569 USB_CDC_ACM_PROTO_VENDOR)
1570
1571#define SAMSUNG_PCSUITE_ACM_INFO(x) \
1572 USB_DEVICE_AND_INTERFACE_INFO(0x04e7, x, \
1573 USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \
1574 USB_CDC_ACM_PROTO_VENDOR)
1575
1576/*
1577 * USB driver structure.
1578 */
1579
1580static const struct usb_device_id acm_ids[] = {
1581 /* quirky and broken devices */
1582 { USB_DEVICE(0x17ef, 0x7000), /* Lenovo USB modem */
1583 .driver_info = NO_UNION_NORMAL, },/* has no union descriptor */
1584 { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */
1585 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1586 },
1587 { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */
1588 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1589 },
1590 { USB_DEVICE(0x0e8d, 0x3329), /* MediaTek Inc GPS */
1591 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1592 },
1593 { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */
1594 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1595 },
1596 { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */
1597 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1598 },
1599 { USB_DEVICE(0x0ace, 0x1602), /* ZyDAS 56K USB MODEM */
1600 .driver_info = SINGLE_RX_URB,
1601 },
1602 { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */
1603 .driver_info = SINGLE_RX_URB, /* firmware bug */
1604 },
1605 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
1606 .driver_info = SINGLE_RX_URB, /* firmware bug */
1607 },
1608 { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
1609 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1610 },
1611 { USB_DEVICE(0x0803, 0x3095), /* Zoom Telephonics Model 3095F USB MODEM */
1612 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1613 },
1614 { USB_DEVICE(0x0572, 0x1321), /* Conexant USB MODEM CX93010 */
1615 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1616 },
1617 { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */
1618 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1619 },
1620 { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */
1621 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1622 },
1623 { USB_DEVICE(0x2184, 0x001c) }, /* GW Instek AFG-2225 */
1624 { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */
1625 },
1626 /* Motorola H24 HSPA module: */
1627 { USB_DEVICE(0x22b8, 0x2d91) }, /* modem */
1628 { USB_DEVICE(0x22b8, 0x2d92), /* modem + diagnostics */
1629 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1630 },
1631 { USB_DEVICE(0x22b8, 0x2d93), /* modem + AT port */
1632 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1633 },
1634 { USB_DEVICE(0x22b8, 0x2d95), /* modem + AT port + diagnostics */
1635 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1636 },
1637 { USB_DEVICE(0x22b8, 0x2d96), /* modem + NMEA */
1638 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1639 },
1640 { USB_DEVICE(0x22b8, 0x2d97), /* modem + diagnostics + NMEA */
1641 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1642 },
1643 { USB_DEVICE(0x22b8, 0x2d99), /* modem + AT port + NMEA */
1644 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1645 },
1646 { USB_DEVICE(0x22b8, 0x2d9a), /* modem + AT port + diagnostics + NMEA */
1647 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1648 },
1649
1650 { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */
1651 .driver_info = NO_UNION_NORMAL, /* union descriptor misplaced on
1652 data interface instead of
1653 communications interface.
1654 Maybe we should define a new
1655 quirk for this. */
1656 },
1657 { USB_DEVICE(0x0572, 0x1340), /* Conexant CX93010-2x UCMxx */
1658 .driver_info = NO_UNION_NORMAL,
1659 },
1660 { USB_DEVICE(0x05f9, 0x4002), /* PSC Scanning, Magellan 800i */
1661 .driver_info = NO_UNION_NORMAL,
1662 },
1663 { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */
1664 .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
1665 },
1666 { USB_DEVICE(0x1576, 0x03b1), /* Maretron USB100 */
1667 .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
1668 },
1669
1670 /* Nokia S60 phones expose two ACM channels. The first is
1671 * a modem and is picked up by the standard AT-command
1672 * information below. The second is 'vendor-specific' but
1673 * is treated as a serial device at the S60 end, so we want
1674 * to expose it on Linux too. */
1675 { NOKIA_PCSUITE_ACM_INFO(0x042D), }, /* Nokia 3250 */
1676 { NOKIA_PCSUITE_ACM_INFO(0x04D8), }, /* Nokia 5500 Sport */
1677 { NOKIA_PCSUITE_ACM_INFO(0x04C9), }, /* Nokia E50 */
1678 { NOKIA_PCSUITE_ACM_INFO(0x0419), }, /* Nokia E60 */
1679 { NOKIA_PCSUITE_ACM_INFO(0x044D), }, /* Nokia E61 */
1680 { NOKIA_PCSUITE_ACM_INFO(0x0001), }, /* Nokia E61i */
1681 { NOKIA_PCSUITE_ACM_INFO(0x0475), }, /* Nokia E62 */
1682 { NOKIA_PCSUITE_ACM_INFO(0x0508), }, /* Nokia E65 */
1683 { NOKIA_PCSUITE_ACM_INFO(0x0418), }, /* Nokia E70 */
1684 { NOKIA_PCSUITE_ACM_INFO(0x0425), }, /* Nokia N71 */
1685 { NOKIA_PCSUITE_ACM_INFO(0x0486), }, /* Nokia N73 */
1686 { NOKIA_PCSUITE_ACM_INFO(0x04DF), }, /* Nokia N75 */
1687 { NOKIA_PCSUITE_ACM_INFO(0x000e), }, /* Nokia N77 */
1688 { NOKIA_PCSUITE_ACM_INFO(0x0445), }, /* Nokia N80 */
1689 { NOKIA_PCSUITE_ACM_INFO(0x042F), }, /* Nokia N91 & N91 8GB */
1690 { NOKIA_PCSUITE_ACM_INFO(0x048E), }, /* Nokia N92 */
1691 { NOKIA_PCSUITE_ACM_INFO(0x0420), }, /* Nokia N93 */
1692 { NOKIA_PCSUITE_ACM_INFO(0x04E6), }, /* Nokia N93i */
1693 { NOKIA_PCSUITE_ACM_INFO(0x04B2), }, /* Nokia 5700 XpressMusic */
1694 { NOKIA_PCSUITE_ACM_INFO(0x0134), }, /* Nokia 6110 Navigator (China) */
1695 { NOKIA_PCSUITE_ACM_INFO(0x046E), }, /* Nokia 6110 Navigator */
1696 { NOKIA_PCSUITE_ACM_INFO(0x002f), }, /* Nokia 6120 classic & */
1697 { NOKIA_PCSUITE_ACM_INFO(0x0088), }, /* Nokia 6121 classic */
1698 { NOKIA_PCSUITE_ACM_INFO(0x00fc), }, /* Nokia 6124 classic */
1699 { NOKIA_PCSUITE_ACM_INFO(0x0042), }, /* Nokia E51 */
1700 { NOKIA_PCSUITE_ACM_INFO(0x00b0), }, /* Nokia E66 */
1701 { NOKIA_PCSUITE_ACM_INFO(0x00ab), }, /* Nokia E71 */
1702 { NOKIA_PCSUITE_ACM_INFO(0x0481), }, /* Nokia N76 */
1703 { NOKIA_PCSUITE_ACM_INFO(0x0007), }, /* Nokia N81 & N81 8GB */
1704 { NOKIA_PCSUITE_ACM_INFO(0x0071), }, /* Nokia N82 */
1705 { NOKIA_PCSUITE_ACM_INFO(0x04F0), }, /* Nokia N95 & N95-3 NAM */
1706 { NOKIA_PCSUITE_ACM_INFO(0x0070), }, /* Nokia N95 8GB */
1707 { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */
1708 { NOKIA_PCSUITE_ACM_INFO(0x0099), }, /* Nokia 6210 Navigator, RM-367 */
1709 { NOKIA_PCSUITE_ACM_INFO(0x0128), }, /* Nokia 6210 Navigator, RM-419 */
1710 { NOKIA_PCSUITE_ACM_INFO(0x008f), }, /* Nokia 6220 Classic */
1711 { NOKIA_PCSUITE_ACM_INFO(0x00a0), }, /* Nokia 6650 */
1712 { NOKIA_PCSUITE_ACM_INFO(0x007b), }, /* Nokia N78 */
1713 { NOKIA_PCSUITE_ACM_INFO(0x0094), }, /* Nokia N85 */
1714 { NOKIA_PCSUITE_ACM_INFO(0x003a), }, /* Nokia N96 & N96-3 */
1715 { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */
1716 { NOKIA_PCSUITE_ACM_INFO(0x0108), }, /* Nokia 5320 XpressMusic 2G */
1717 { NOKIA_PCSUITE_ACM_INFO(0x01f5), }, /* Nokia N97, RM-505 */
1718 { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */
1719 { NOKIA_PCSUITE_ACM_INFO(0x0178), }, /* Nokia E63 */
1720 { NOKIA_PCSUITE_ACM_INFO(0x010e), }, /* Nokia E75 */
1721 { NOKIA_PCSUITE_ACM_INFO(0x02d9), }, /* Nokia 6760 Slide */
1722 { NOKIA_PCSUITE_ACM_INFO(0x01d0), }, /* Nokia E52 */
1723 { NOKIA_PCSUITE_ACM_INFO(0x0223), }, /* Nokia E72 */
1724 { NOKIA_PCSUITE_ACM_INFO(0x0275), }, /* Nokia X6 */
1725 { NOKIA_PCSUITE_ACM_INFO(0x026c), }, /* Nokia N97 Mini */
1726 { NOKIA_PCSUITE_ACM_INFO(0x0154), }, /* Nokia 5800 XpressMusic */
1727 { NOKIA_PCSUITE_ACM_INFO(0x04ce), }, /* Nokia E90 */
1728 { NOKIA_PCSUITE_ACM_INFO(0x01d4), }, /* Nokia E55 */
1729 { NOKIA_PCSUITE_ACM_INFO(0x0302), }, /* Nokia N8 */
1730 { NOKIA_PCSUITE_ACM_INFO(0x0335), }, /* Nokia E7 */
1731 { NOKIA_PCSUITE_ACM_INFO(0x03cd), }, /* Nokia C7 */
1732 { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */
1733
1734 /* Support for Owen devices */
1735 { USB_DEVICE(0x03eb, 0x0030), }, /* Owen SI30 */
1736
1737 /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */
1738
1739 /* Support Lego NXT using pbLua firmware */
1740 { USB_DEVICE(0x0694, 0xff00),
1741 .driver_info = NOT_A_MODEM,
1742 },
1743
1744 /* Support for Droids MuIn LCD */
1745 { USB_DEVICE(0x04d8, 0x000b),
1746 .driver_info = NO_DATA_INTERFACE,
1747 },
1748
1749 /* control interfaces without any protocol set */
1750 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1751 USB_CDC_PROTO_NONE) },
1752
1753 /* control interfaces with various AT-command sets */
1754 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1755 USB_CDC_ACM_PROTO_AT_V25TER) },
1756 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1757 USB_CDC_ACM_PROTO_AT_PCCA101) },
1758 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1759 USB_CDC_ACM_PROTO_AT_PCCA101_WAKE) },
1760 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1761 USB_CDC_ACM_PROTO_AT_GSM) },
1762 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1763 USB_CDC_ACM_PROTO_AT_3G) },
1764 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1765 USB_CDC_ACM_PROTO_AT_CDMA) },
1766
1767 { }
1768};
1769
1770MODULE_DEVICE_TABLE(usb, acm_ids);
1771
1772static struct usb_driver acm_driver = {
1773 .name = "cdc_acm",
1774 .probe = acm_probe,
1775 .disconnect = acm_disconnect,
1776#ifdef CONFIG_PM
1777 .suspend = acm_suspend,
1778 .resume = acm_resume,
1779 .reset_resume = acm_reset_resume,
1780#endif
1781 .id_table = acm_ids,
1782#ifdef CONFIG_PM
1783 .supports_autosuspend = 1,
1784#endif
1785};
1786
1787/*
1788 * TTY driver structures.
1789 */
1790
1791static const struct tty_operations acm_ops = {
1792 .install = acm_tty_install,
1793 .open = acm_tty_open,
1794 .close = acm_tty_close,
1795 .cleanup = acm_tty_cleanup,
1796 .hangup = acm_tty_hangup,
1797 .write = acm_tty_write,
1798 .write_room = acm_tty_write_room,
1799 .ioctl = acm_tty_ioctl,
1800 .throttle = acm_tty_throttle,
1801 .unthrottle = acm_tty_unthrottle,
1802 .chars_in_buffer = acm_tty_chars_in_buffer,
1803 .break_ctl = acm_tty_break_ctl,
1804 .set_termios = acm_tty_set_termios,
1805 .tiocmget = acm_tty_tiocmget,
1806 .tiocmset = acm_tty_tiocmset,
1807};
1808
1809/*
1810 * Init / exit.
1811 */
1812
1813static int __init acm_init(void)
1814{
1815 int retval;
1816 acm_tty_driver = alloc_tty_driver(ACM_TTY_MINORS);
1817 if (!acm_tty_driver)
1818 return -ENOMEM;
1819 acm_tty_driver->driver_name = "acm",
1820 acm_tty_driver->name = "ttyACM",
1821 acm_tty_driver->major = ACM_TTY_MAJOR,
1822 acm_tty_driver->minor_start = 0,
1823 acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL,
1824 acm_tty_driver->subtype = SERIAL_TYPE_NORMAL,
1825 acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
1826 acm_tty_driver->init_termios = tty_std_termios;
1827 acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD |
1828 HUPCL | CLOCAL;
1829 tty_set_operations(acm_tty_driver, &acm_ops);
1830
1831 retval = tty_register_driver(acm_tty_driver);
1832 if (retval) {
1833 put_tty_driver(acm_tty_driver);
1834 return retval;
1835 }
1836
1837 retval = usb_register(&acm_driver);
1838 if (retval) {
1839 tty_unregister_driver(acm_tty_driver);
1840 put_tty_driver(acm_tty_driver);
1841 return retval;
1842 }
1843
1844 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
1845
1846 return 0;
1847}
1848
1849static void __exit acm_exit(void)
1850{
1851 usb_deregister(&acm_driver);
1852 tty_unregister_driver(acm_tty_driver);
1853 put_tty_driver(acm_tty_driver);
1854}
1855
1856module_init(acm_init);
1857module_exit(acm_exit);
1858
1859MODULE_AUTHOR(DRIVER_AUTHOR);
1860MODULE_DESCRIPTION(DRIVER_DESC);
1861MODULE_LICENSE("GPL");
1862MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR);