inet: frag: enforce memory limits earlier
[linux/fpc-iii.git] / drivers / usb / class / cdc-acm.c
bloba9c950d29ce2840421b3f92694f78a3bdc9a3bd3
1 /*
2 * cdc-acm.c
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
14 * Sponsored by SuSE
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
31 #undef DEBUG
32 #undef VERBOSE_DEBUG
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/idr.h>
50 #include <linux/list.h>
52 #include "cdc-acm.h"
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"
58 static struct usb_driver acm_driver;
59 static struct tty_driver *acm_tty_driver;
61 static DEFINE_IDR(acm_minors);
62 static DEFINE_MUTEX(acm_minors_lock);
64 static void acm_tty_set_termios(struct tty_struct *tty,
65 struct ktermios *termios_old);
68 * acm_minors accessors
72 * Look up an ACM structure by minor. If found and not disconnected, increment
73 * its refcount and return it with its mutex held.
75 static struct acm *acm_get_by_minor(unsigned int minor)
77 struct acm *acm;
79 mutex_lock(&acm_minors_lock);
80 acm = idr_find(&acm_minors, minor);
81 if (acm) {
82 mutex_lock(&acm->mutex);
83 if (acm->disconnected) {
84 mutex_unlock(&acm->mutex);
85 acm = NULL;
86 } else {
87 tty_port_get(&acm->port);
88 mutex_unlock(&acm->mutex);
91 mutex_unlock(&acm_minors_lock);
92 return acm;
96 * Try to find an available minor number and if found, associate it with 'acm'.
98 static int acm_alloc_minor(struct acm *acm)
100 int minor;
102 mutex_lock(&acm_minors_lock);
103 minor = idr_alloc(&acm_minors, acm, 0, ACM_TTY_MINORS, GFP_KERNEL);
104 mutex_unlock(&acm_minors_lock);
106 return minor;
109 /* Release the minor number associated with 'acm'. */
110 static void acm_release_minor(struct acm *acm)
112 mutex_lock(&acm_minors_lock);
113 idr_remove(&acm_minors, acm->minor);
114 mutex_unlock(&acm_minors_lock);
118 * Functions for ACM control messages.
121 static int acm_ctrl_msg(struct acm *acm, int request, int value,
122 void *buf, int len)
124 int retval;
126 retval = usb_autopm_get_interface(acm->control);
127 if (retval)
128 return retval;
130 retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0),
131 request, USB_RT_ACM, value,
132 acm->control->altsetting[0].desc.bInterfaceNumber,
133 buf, len, 5000);
135 dev_dbg(&acm->control->dev,
136 "%s - rq 0x%02x, val %#x, len %#x, result %d\n",
137 __func__, request, value, len, retval);
139 usb_autopm_put_interface(acm->control);
141 return retval < 0 ? retval : 0;
144 /* devices aren't required to support these requests.
145 * the cdc acm descriptor tells whether they do...
147 static inline int acm_set_control(struct acm *acm, int control)
149 if (acm->quirks & QUIRK_CONTROL_LINE_STATE)
150 return -EOPNOTSUPP;
152 return acm_ctrl_msg(acm, USB_CDC_REQ_SET_CONTROL_LINE_STATE,
153 control, NULL, 0);
156 #define acm_set_line(acm, line) \
157 acm_ctrl_msg(acm, USB_CDC_REQ_SET_LINE_CODING, 0, line, sizeof *(line))
158 #define acm_send_break(acm, ms) \
159 acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0)
162 * Write buffer management.
163 * All of these assume proper locks taken by the caller.
166 static int acm_wb_alloc(struct acm *acm)
168 int i, wbn;
169 struct acm_wb *wb;
171 wbn = 0;
172 i = 0;
173 for (;;) {
174 wb = &acm->wb[wbn];
175 if (!wb->use) {
176 wb->use = 1;
177 wb->len = 0;
178 return wbn;
180 wbn = (wbn + 1) % ACM_NW;
181 if (++i >= ACM_NW)
182 return -1;
186 static int acm_wb_is_avail(struct acm *acm)
188 int i, n;
189 unsigned long flags;
191 n = ACM_NW;
192 spin_lock_irqsave(&acm->write_lock, flags);
193 for (i = 0; i < ACM_NW; i++)
194 n -= acm->wb[i].use;
195 spin_unlock_irqrestore(&acm->write_lock, flags);
196 return n;
200 * Finish write. Caller must hold acm->write_lock
202 static void acm_write_done(struct acm *acm, struct acm_wb *wb)
204 wb->use = 0;
205 acm->transmitting--;
206 usb_autopm_put_interface_async(acm->control);
210 * Poke write.
212 * the caller is responsible for locking
215 static int acm_start_wb(struct acm *acm, struct acm_wb *wb)
217 int rc;
219 acm->transmitting++;
221 wb->urb->transfer_buffer = wb->buf;
222 wb->urb->transfer_dma = wb->dmah;
223 wb->urb->transfer_buffer_length = wb->len;
224 wb->urb->dev = acm->dev;
226 rc = usb_submit_urb(wb->urb, GFP_ATOMIC);
227 if (rc < 0) {
228 dev_err(&acm->data->dev,
229 "%s - usb_submit_urb(write bulk) failed: %d\n",
230 __func__, rc);
231 acm_write_done(acm, wb);
233 return rc;
237 * attributes exported through sysfs
239 static ssize_t show_caps
240 (struct device *dev, struct device_attribute *attr, char *buf)
242 struct usb_interface *intf = to_usb_interface(dev);
243 struct acm *acm = usb_get_intfdata(intf);
245 return sprintf(buf, "%d", acm->ctrl_caps);
247 static DEVICE_ATTR(bmCapabilities, S_IRUGO, show_caps, NULL);
249 static ssize_t show_country_codes
250 (struct device *dev, struct device_attribute *attr, char *buf)
252 struct usb_interface *intf = to_usb_interface(dev);
253 struct acm *acm = usb_get_intfdata(intf);
255 memcpy(buf, acm->country_codes, acm->country_code_size);
256 return acm->country_code_size;
259 static DEVICE_ATTR(wCountryCodes, S_IRUGO, show_country_codes, NULL);
261 static ssize_t show_country_rel_date
262 (struct device *dev, struct device_attribute *attr, char *buf)
264 struct usb_interface *intf = to_usb_interface(dev);
265 struct acm *acm = usb_get_intfdata(intf);
267 return sprintf(buf, "%d", acm->country_rel_date);
270 static DEVICE_ATTR(iCountryCodeRelDate, S_IRUGO, show_country_rel_date, NULL);
272 * Interrupt handlers for various ACM device responses
275 /* control interface reports status changes with "interrupt" transfers */
276 static void acm_ctrl_irq(struct urb *urb)
278 struct acm *acm = urb->context;
279 struct usb_cdc_notification *dr = urb->transfer_buffer;
280 unsigned char *data;
281 int newctrl;
282 int difference;
283 int retval;
284 int status = urb->status;
286 switch (status) {
287 case 0:
288 /* success */
289 break;
290 case -ECONNRESET:
291 case -ENOENT:
292 case -ESHUTDOWN:
293 /* this urb is terminated, clean up */
294 dev_dbg(&acm->control->dev,
295 "%s - urb shutting down with status: %d\n",
296 __func__, status);
297 return;
298 default:
299 dev_dbg(&acm->control->dev,
300 "%s - nonzero urb status received: %d\n",
301 __func__, status);
302 goto exit;
305 usb_mark_last_busy(acm->dev);
307 data = (unsigned char *)(dr + 1);
308 switch (dr->bNotificationType) {
309 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
310 dev_dbg(&acm->control->dev, "%s - network connection: %d\n",
311 __func__, dr->wValue);
312 break;
314 case USB_CDC_NOTIFY_SERIAL_STATE:
315 if (le16_to_cpu(dr->wLength) != 2) {
316 dev_dbg(&acm->control->dev,
317 "%s - malformed serial state\n", __func__);
318 break;
321 newctrl = get_unaligned_le16(data);
323 if (!acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) {
324 dev_dbg(&acm->control->dev, "%s - calling hangup\n",
325 __func__);
326 tty_port_tty_hangup(&acm->port, false);
329 difference = acm->ctrlin ^ newctrl;
330 spin_lock(&acm->read_lock);
331 acm->ctrlin = newctrl;
332 acm->oldcount = acm->iocount;
334 if (difference & ACM_CTRL_DSR)
335 acm->iocount.dsr++;
336 if (difference & ACM_CTRL_BRK)
337 acm->iocount.brk++;
338 if (difference & ACM_CTRL_RI)
339 acm->iocount.rng++;
340 if (difference & ACM_CTRL_DCD)
341 acm->iocount.dcd++;
342 if (difference & ACM_CTRL_FRAMING)
343 acm->iocount.frame++;
344 if (difference & ACM_CTRL_PARITY)
345 acm->iocount.parity++;
346 if (difference & ACM_CTRL_OVERRUN)
347 acm->iocount.overrun++;
348 spin_unlock(&acm->read_lock);
350 if (difference)
351 wake_up_all(&acm->wioctl);
353 break;
355 default:
356 dev_dbg(&acm->control->dev,
357 "%s - unknown notification %d received: index %d len %d\n",
358 __func__,
359 dr->bNotificationType, dr->wIndex, dr->wLength);
361 break;
363 exit:
364 retval = usb_submit_urb(urb, GFP_ATOMIC);
365 if (retval && retval != -EPERM)
366 dev_err(&acm->control->dev, "%s - usb_submit_urb failed: %d\n",
367 __func__, retval);
370 static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags)
372 int res;
374 if (!test_and_clear_bit(index, &acm->read_urbs_free))
375 return 0;
377 res = usb_submit_urb(acm->read_urbs[index], mem_flags);
378 if (res) {
379 if (res != -EPERM && res != -ENODEV) {
380 dev_err(&acm->data->dev,
381 "urb %d failed submission with %d\n",
382 index, res);
384 set_bit(index, &acm->read_urbs_free);
385 return res;
386 } else {
387 dev_vdbg(&acm->data->dev, "submitted urb %d\n", index);
390 return 0;
393 static int acm_submit_read_urbs(struct acm *acm, gfp_t mem_flags)
395 int res;
396 int i;
398 for (i = 0; i < acm->rx_buflimit; ++i) {
399 res = acm_submit_read_urb(acm, i, mem_flags);
400 if (res)
401 return res;
404 return 0;
407 static void acm_process_read_urb(struct acm *acm, struct urb *urb)
409 if (!urb->actual_length)
410 return;
412 tty_insert_flip_string(&acm->port, urb->transfer_buffer,
413 urb->actual_length);
414 tty_flip_buffer_push(&acm->port);
417 static void acm_read_bulk_callback(struct urb *urb)
419 struct acm_rb *rb = urb->context;
420 struct acm *acm = rb->instance;
421 unsigned long flags;
422 int status = urb->status;
424 dev_vdbg(&acm->data->dev, "got urb %d, len %d, status %d\n",
425 rb->index, urb->actual_length,
426 status);
428 if (!acm->dev) {
429 set_bit(rb->index, &acm->read_urbs_free);
430 dev_dbg(&acm->data->dev, "%s - disconnected\n", __func__);
431 return;
434 if (status) {
435 set_bit(rb->index, &acm->read_urbs_free);
436 if ((status != -ENOENT) || (urb->actual_length == 0))
437 return;
440 usb_mark_last_busy(acm->dev);
442 acm_process_read_urb(acm, urb);
444 * Unthrottle may run on another CPU which needs to see events
445 * in the same order. Submission has an implict barrier
447 smp_mb__before_atomic();
448 set_bit(rb->index, &acm->read_urbs_free);
450 /* throttle device if requested by tty */
451 spin_lock_irqsave(&acm->read_lock, flags);
452 acm->throttled = acm->throttle_req;
453 if (!acm->throttled) {
454 spin_unlock_irqrestore(&acm->read_lock, flags);
455 acm_submit_read_urb(acm, rb->index, GFP_ATOMIC);
456 } else {
457 spin_unlock_irqrestore(&acm->read_lock, flags);
461 /* data interface wrote those outgoing bytes */
462 static void acm_write_bulk(struct urb *urb)
464 struct acm_wb *wb = urb->context;
465 struct acm *acm = wb->instance;
466 unsigned long flags;
467 int status = urb->status;
469 if (status || (urb->actual_length != urb->transfer_buffer_length))
470 dev_vdbg(&acm->data->dev, "wrote len %d/%d, status %d\n",
471 urb->actual_length,
472 urb->transfer_buffer_length,
473 status);
475 spin_lock_irqsave(&acm->write_lock, flags);
476 acm_write_done(acm, wb);
477 spin_unlock_irqrestore(&acm->write_lock, flags);
478 schedule_work(&acm->work);
481 static void acm_softint(struct work_struct *work)
483 struct acm *acm = container_of(work, struct acm, work);
485 tty_port_tty_wakeup(&acm->port);
489 * TTY handlers
492 static int acm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
494 struct acm *acm;
495 int retval;
497 acm = acm_get_by_minor(tty->index);
498 if (!acm)
499 return -ENODEV;
501 retval = tty_standard_install(driver, tty);
502 if (retval)
503 goto error_init_termios;
505 tty->driver_data = acm;
507 return 0;
509 error_init_termios:
510 tty_port_put(&acm->port);
511 return retval;
514 static int acm_tty_open(struct tty_struct *tty, struct file *filp)
516 struct acm *acm = tty->driver_data;
518 return tty_port_open(&acm->port, tty, filp);
521 static void acm_port_dtr_rts(struct tty_port *port, int raise)
523 struct acm *acm = container_of(port, struct acm, port);
524 int val;
525 int res;
527 if (raise)
528 val = ACM_CTRL_DTR | ACM_CTRL_RTS;
529 else
530 val = 0;
532 /* FIXME: add missing ctrlout locking throughout driver */
533 acm->ctrlout = val;
535 res = acm_set_control(acm, val);
536 if (res && (acm->ctrl_caps & USB_CDC_CAP_LINE))
537 dev_err(&acm->control->dev, "failed to set dtr/rts\n");
540 static int acm_port_activate(struct tty_port *port, struct tty_struct *tty)
542 struct acm *acm = container_of(port, struct acm, port);
543 int retval = -ENODEV;
544 int i;
546 mutex_lock(&acm->mutex);
547 if (acm->disconnected)
548 goto disconnected;
550 retval = usb_autopm_get_interface(acm->control);
551 if (retval)
552 goto error_get_interface;
555 * FIXME: Why do we need this? Allocating 64K of physically contiguous
556 * memory is really nasty...
558 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags);
559 acm->control->needs_remote_wakeup = 1;
561 acm->ctrlurb->dev = acm->dev;
562 retval = usb_submit_urb(acm->ctrlurb, GFP_KERNEL);
563 if (retval) {
564 dev_err(&acm->control->dev,
565 "%s - usb_submit_urb(ctrl irq) failed\n", __func__);
566 goto error_submit_urb;
569 acm_tty_set_termios(tty, NULL);
572 * Unthrottle device in case the TTY was closed while throttled.
574 spin_lock_irq(&acm->read_lock);
575 acm->throttled = 0;
576 acm->throttle_req = 0;
577 spin_unlock_irq(&acm->read_lock);
579 retval = acm_submit_read_urbs(acm, GFP_KERNEL);
580 if (retval)
581 goto error_submit_read_urbs;
583 usb_autopm_put_interface(acm->control);
585 mutex_unlock(&acm->mutex);
587 return 0;
589 error_submit_read_urbs:
590 for (i = 0; i < acm->rx_buflimit; i++)
591 usb_kill_urb(acm->read_urbs[i]);
592 usb_kill_urb(acm->ctrlurb);
593 error_submit_urb:
594 usb_autopm_put_interface(acm->control);
595 error_get_interface:
596 disconnected:
597 mutex_unlock(&acm->mutex);
599 return usb_translate_errors(retval);
602 static void acm_port_destruct(struct tty_port *port)
604 struct acm *acm = container_of(port, struct acm, port);
606 acm_release_minor(acm);
607 usb_put_intf(acm->control);
608 kfree(acm->country_codes);
609 kfree(acm);
612 static void acm_port_shutdown(struct tty_port *port)
614 struct acm *acm = container_of(port, struct acm, port);
615 struct urb *urb;
616 struct acm_wb *wb;
617 int i;
620 * Need to grab write_lock to prevent race with resume, but no need to
621 * hold it due to the tty-port initialised flag.
623 spin_lock_irq(&acm->write_lock);
624 spin_unlock_irq(&acm->write_lock);
626 usb_autopm_get_interface_no_resume(acm->control);
627 acm->control->needs_remote_wakeup = 0;
628 usb_autopm_put_interface(acm->control);
630 for (;;) {
631 urb = usb_get_from_anchor(&acm->delayed);
632 if (!urb)
633 break;
634 wb = urb->context;
635 wb->use = 0;
636 usb_autopm_put_interface_async(acm->control);
639 usb_kill_urb(acm->ctrlurb);
640 for (i = 0; i < ACM_NW; i++)
641 usb_kill_urb(acm->wb[i].urb);
642 for (i = 0; i < acm->rx_buflimit; i++)
643 usb_kill_urb(acm->read_urbs[i]);
646 static void acm_tty_cleanup(struct tty_struct *tty)
648 struct acm *acm = tty->driver_data;
650 tty_port_put(&acm->port);
653 static void acm_tty_hangup(struct tty_struct *tty)
655 struct acm *acm = tty->driver_data;
657 tty_port_hangup(&acm->port);
660 static void acm_tty_close(struct tty_struct *tty, struct file *filp)
662 struct acm *acm = tty->driver_data;
664 tty_port_close(&acm->port, tty, filp);
667 static int acm_tty_write(struct tty_struct *tty,
668 const unsigned char *buf, int count)
670 struct acm *acm = tty->driver_data;
671 int stat;
672 unsigned long flags;
673 int wbn;
674 struct acm_wb *wb;
676 if (!count)
677 return 0;
679 dev_vdbg(&acm->data->dev, "%d bytes from tty layer\n", count);
681 spin_lock_irqsave(&acm->write_lock, flags);
682 wbn = acm_wb_alloc(acm);
683 if (wbn < 0) {
684 spin_unlock_irqrestore(&acm->write_lock, flags);
685 return 0;
687 wb = &acm->wb[wbn];
689 if (!acm->dev) {
690 wb->use = 0;
691 spin_unlock_irqrestore(&acm->write_lock, flags);
692 return -ENODEV;
695 count = (count > acm->writesize) ? acm->writesize : count;
696 dev_vdbg(&acm->data->dev, "writing %d bytes\n", count);
697 memcpy(wb->buf, buf, count);
698 wb->len = count;
700 stat = usb_autopm_get_interface_async(acm->control);
701 if (stat) {
702 wb->use = 0;
703 spin_unlock_irqrestore(&acm->write_lock, flags);
704 return stat;
707 if (acm->susp_count) {
708 if (acm->putbuffer) {
709 /* now to preserve order */
710 usb_anchor_urb(acm->putbuffer->urb, &acm->delayed);
711 acm->putbuffer = NULL;
713 usb_anchor_urb(wb->urb, &acm->delayed);
714 spin_unlock_irqrestore(&acm->write_lock, flags);
715 return count;
716 } else {
717 if (acm->putbuffer) {
718 /* at this point there is no good way to handle errors */
719 acm_start_wb(acm, acm->putbuffer);
720 acm->putbuffer = NULL;
724 stat = acm_start_wb(acm, wb);
725 spin_unlock_irqrestore(&acm->write_lock, flags);
727 if (stat < 0)
728 return stat;
729 return count;
732 static void acm_tty_flush_chars(struct tty_struct *tty)
734 struct acm *acm = tty->driver_data;
735 struct acm_wb *cur;
736 int err;
737 unsigned long flags;
739 spin_lock_irqsave(&acm->write_lock, flags);
741 cur = acm->putbuffer;
742 if (!cur) /* nothing to do */
743 goto out;
745 acm->putbuffer = NULL;
746 err = usb_autopm_get_interface_async(acm->control);
747 if (err < 0) {
748 cur->use = 0;
749 acm->putbuffer = cur;
750 goto out;
753 if (acm->susp_count)
754 usb_anchor_urb(cur->urb, &acm->delayed);
755 else
756 acm_start_wb(acm, cur);
757 out:
758 spin_unlock_irqrestore(&acm->write_lock, flags);
759 return;
762 static int acm_tty_put_char(struct tty_struct *tty, unsigned char ch)
764 struct acm *acm = tty->driver_data;
765 struct acm_wb *cur;
766 int wbn;
767 unsigned long flags;
769 overflow:
770 cur = acm->putbuffer;
771 if (!cur) {
772 spin_lock_irqsave(&acm->write_lock, flags);
773 wbn = acm_wb_alloc(acm);
774 if (wbn >= 0) {
775 cur = &acm->wb[wbn];
776 acm->putbuffer = cur;
778 spin_unlock_irqrestore(&acm->write_lock, flags);
779 if (!cur)
780 return 0;
783 if (cur->len == acm->writesize) {
784 acm_tty_flush_chars(tty);
785 goto overflow;
788 cur->buf[cur->len++] = ch;
789 return 1;
792 static int acm_tty_write_room(struct tty_struct *tty)
794 struct acm *acm = tty->driver_data;
796 * Do not let the line discipline to know that we have a reserve,
797 * or it might get too enthusiastic.
799 return acm_wb_is_avail(acm) ? acm->writesize : 0;
802 static int acm_tty_chars_in_buffer(struct tty_struct *tty)
804 struct acm *acm = tty->driver_data;
806 * if the device was unplugged then any remaining characters fell out
807 * of the connector ;)
809 if (acm->disconnected)
810 return 0;
812 * This is inaccurate (overcounts), but it works.
814 return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize;
817 static void acm_tty_throttle(struct tty_struct *tty)
819 struct acm *acm = tty->driver_data;
821 spin_lock_irq(&acm->read_lock);
822 acm->throttle_req = 1;
823 spin_unlock_irq(&acm->read_lock);
826 static void acm_tty_unthrottle(struct tty_struct *tty)
828 struct acm *acm = tty->driver_data;
829 unsigned int was_throttled;
831 spin_lock_irq(&acm->read_lock);
832 was_throttled = acm->throttled;
833 acm->throttled = 0;
834 acm->throttle_req = 0;
835 spin_unlock_irq(&acm->read_lock);
837 if (was_throttled)
838 acm_submit_read_urbs(acm, GFP_KERNEL);
841 static int acm_tty_break_ctl(struct tty_struct *tty, int state)
843 struct acm *acm = tty->driver_data;
844 int retval;
846 retval = acm_send_break(acm, state ? 0xffff : 0);
847 if (retval < 0)
848 dev_dbg(&acm->control->dev, "%s - send break failed\n",
849 __func__);
850 return retval;
853 static int acm_tty_tiocmget(struct tty_struct *tty)
855 struct acm *acm = tty->driver_data;
857 return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) |
858 (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) |
859 (acm->ctrlin & ACM_CTRL_DSR ? TIOCM_DSR : 0) |
860 (acm->ctrlin & ACM_CTRL_RI ? TIOCM_RI : 0) |
861 (acm->ctrlin & ACM_CTRL_DCD ? TIOCM_CD : 0) |
862 TIOCM_CTS;
865 static int acm_tty_tiocmset(struct tty_struct *tty,
866 unsigned int set, unsigned int clear)
868 struct acm *acm = tty->driver_data;
869 unsigned int newctrl;
871 newctrl = acm->ctrlout;
872 set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) |
873 (set & TIOCM_RTS ? ACM_CTRL_RTS : 0);
874 clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) |
875 (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0);
877 newctrl = (newctrl & ~clear) | set;
879 if (acm->ctrlout == newctrl)
880 return 0;
881 return acm_set_control(acm, acm->ctrlout = newctrl);
884 static int get_serial_info(struct acm *acm, struct serial_struct __user *info)
886 struct serial_struct tmp;
888 if (!info)
889 return -EINVAL;
891 memset(&tmp, 0, sizeof(tmp));
892 tmp.flags = ASYNC_LOW_LATENCY;
893 tmp.xmit_fifo_size = acm->writesize;
894 tmp.baud_base = le32_to_cpu(acm->line.dwDTERate);
895 tmp.close_delay = acm->port.close_delay / 10;
896 tmp.closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
897 ASYNC_CLOSING_WAIT_NONE :
898 acm->port.closing_wait / 10;
900 if (copy_to_user(info, &tmp, sizeof(tmp)))
901 return -EFAULT;
902 else
903 return 0;
906 static int set_serial_info(struct acm *acm,
907 struct serial_struct __user *newinfo)
909 struct serial_struct new_serial;
910 unsigned int closing_wait, close_delay;
911 int retval = 0;
913 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
914 return -EFAULT;
916 close_delay = new_serial.close_delay * 10;
917 closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
918 ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10;
920 mutex_lock(&acm->port.mutex);
922 if (!capable(CAP_SYS_ADMIN)) {
923 if ((close_delay != acm->port.close_delay) ||
924 (closing_wait != acm->port.closing_wait))
925 retval = -EPERM;
926 else
927 retval = -EOPNOTSUPP;
928 } else {
929 acm->port.close_delay = close_delay;
930 acm->port.closing_wait = closing_wait;
933 mutex_unlock(&acm->port.mutex);
934 return retval;
937 static int wait_serial_change(struct acm *acm, unsigned long arg)
939 int rv = 0;
940 DECLARE_WAITQUEUE(wait, current);
941 struct async_icount old, new;
943 do {
944 spin_lock_irq(&acm->read_lock);
945 old = acm->oldcount;
946 new = acm->iocount;
947 acm->oldcount = new;
948 spin_unlock_irq(&acm->read_lock);
950 if ((arg & TIOCM_DSR) &&
951 old.dsr != new.dsr)
952 break;
953 if ((arg & TIOCM_CD) &&
954 old.dcd != new.dcd)
955 break;
956 if ((arg & TIOCM_RI) &&
957 old.rng != new.rng)
958 break;
960 add_wait_queue(&acm->wioctl, &wait);
961 set_current_state(TASK_INTERRUPTIBLE);
962 schedule();
963 remove_wait_queue(&acm->wioctl, &wait);
964 if (acm->disconnected) {
965 if (arg & TIOCM_CD)
966 break;
967 else
968 rv = -ENODEV;
969 } else {
970 if (signal_pending(current))
971 rv = -ERESTARTSYS;
973 } while (!rv);
977 return rv;
980 static int get_serial_usage(struct acm *acm,
981 struct serial_icounter_struct __user *count)
983 struct serial_icounter_struct icount;
984 int rv = 0;
986 memset(&icount, 0, sizeof(icount));
987 icount.dsr = acm->iocount.dsr;
988 icount.rng = acm->iocount.rng;
989 icount.dcd = acm->iocount.dcd;
990 icount.frame = acm->iocount.frame;
991 icount.overrun = acm->iocount.overrun;
992 icount.parity = acm->iocount.parity;
993 icount.brk = acm->iocount.brk;
995 if (copy_to_user(count, &icount, sizeof(icount)) > 0)
996 rv = -EFAULT;
998 return rv;
1001 static int acm_tty_ioctl(struct tty_struct *tty,
1002 unsigned int cmd, unsigned long arg)
1004 struct acm *acm = tty->driver_data;
1005 int rv = -ENOIOCTLCMD;
1007 switch (cmd) {
1008 case TIOCGSERIAL: /* gets serial port data */
1009 rv = get_serial_info(acm, (struct serial_struct __user *) arg);
1010 break;
1011 case TIOCSSERIAL:
1012 rv = set_serial_info(acm, (struct serial_struct __user *) arg);
1013 break;
1014 case TIOCMIWAIT:
1015 rv = usb_autopm_get_interface(acm->control);
1016 if (rv < 0) {
1017 rv = -EIO;
1018 break;
1020 rv = wait_serial_change(acm, arg);
1021 usb_autopm_put_interface(acm->control);
1022 break;
1023 case TIOCGICOUNT:
1024 rv = get_serial_usage(acm, (struct serial_icounter_struct __user *) arg);
1025 break;
1028 return rv;
1031 static void acm_tty_set_termios(struct tty_struct *tty,
1032 struct ktermios *termios_old)
1034 struct acm *acm = tty->driver_data;
1035 struct ktermios *termios = &tty->termios;
1036 struct usb_cdc_line_coding newline;
1037 int newctrl = acm->ctrlout;
1039 newline.dwDTERate = cpu_to_le32(tty_get_baud_rate(tty));
1040 newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0;
1041 newline.bParityType = termios->c_cflag & PARENB ?
1042 (termios->c_cflag & PARODD ? 1 : 2) +
1043 (termios->c_cflag & CMSPAR ? 2 : 0) : 0;
1044 switch (termios->c_cflag & CSIZE) {
1045 case CS5:
1046 newline.bDataBits = 5;
1047 break;
1048 case CS6:
1049 newline.bDataBits = 6;
1050 break;
1051 case CS7:
1052 newline.bDataBits = 7;
1053 break;
1054 case CS8:
1055 default:
1056 newline.bDataBits = 8;
1057 break;
1059 /* FIXME: Needs to clear unsupported bits in the termios */
1060 acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
1062 if (C_BAUD(tty) == B0) {
1063 newline.dwDTERate = acm->line.dwDTERate;
1064 newctrl &= ~ACM_CTRL_DTR;
1065 } else if (termios_old && (termios_old->c_cflag & CBAUD) == B0) {
1066 newctrl |= ACM_CTRL_DTR;
1069 if (newctrl != acm->ctrlout)
1070 acm_set_control(acm, acm->ctrlout = newctrl);
1072 if (memcmp(&acm->line, &newline, sizeof newline)) {
1073 memcpy(&acm->line, &newline, sizeof newline);
1074 dev_dbg(&acm->control->dev, "%s - set line: %d %d %d %d\n",
1075 __func__,
1076 le32_to_cpu(newline.dwDTERate),
1077 newline.bCharFormat, newline.bParityType,
1078 newline.bDataBits);
1079 acm_set_line(acm, &acm->line);
1083 static const struct tty_port_operations acm_port_ops = {
1084 .dtr_rts = acm_port_dtr_rts,
1085 .shutdown = acm_port_shutdown,
1086 .activate = acm_port_activate,
1087 .destruct = acm_port_destruct,
1091 * USB probe and disconnect routines.
1094 /* Little helpers: write/read buffers free */
1095 static void acm_write_buffers_free(struct acm *acm)
1097 int i;
1098 struct acm_wb *wb;
1099 struct usb_device *usb_dev = interface_to_usbdev(acm->control);
1101 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++)
1102 usb_free_coherent(usb_dev, acm->writesize, wb->buf, wb->dmah);
1105 static void acm_read_buffers_free(struct acm *acm)
1107 struct usb_device *usb_dev = interface_to_usbdev(acm->control);
1108 int i;
1110 for (i = 0; i < acm->rx_buflimit; i++)
1111 usb_free_coherent(usb_dev, acm->readsize,
1112 acm->read_buffers[i].base, acm->read_buffers[i].dma);
1115 /* Little helper: write buffers allocate */
1116 static int acm_write_buffers_alloc(struct acm *acm)
1118 int i;
1119 struct acm_wb *wb;
1121 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) {
1122 wb->buf = usb_alloc_coherent(acm->dev, acm->writesize, GFP_KERNEL,
1123 &wb->dmah);
1124 if (!wb->buf) {
1125 while (i != 0) {
1126 --i;
1127 --wb;
1128 usb_free_coherent(acm->dev, acm->writesize,
1129 wb->buf, wb->dmah);
1131 return -ENOMEM;
1134 return 0;
1137 static int acm_probe(struct usb_interface *intf,
1138 const struct usb_device_id *id)
1140 struct usb_cdc_union_desc *union_header = NULL;
1141 struct usb_cdc_call_mgmt_descriptor *cmgmd = NULL;
1142 unsigned char *buffer = intf->altsetting->extra;
1143 int buflen = intf->altsetting->extralen;
1144 struct usb_interface *control_interface;
1145 struct usb_interface *data_interface;
1146 struct usb_endpoint_descriptor *epctrl = NULL;
1147 struct usb_endpoint_descriptor *epread = NULL;
1148 struct usb_endpoint_descriptor *epwrite = NULL;
1149 struct usb_device *usb_dev = interface_to_usbdev(intf);
1150 struct usb_cdc_parsed_header h;
1151 struct acm *acm;
1152 int minor;
1153 int ctrlsize, readsize;
1154 u8 *buf;
1155 int call_intf_num = -1;
1156 int data_intf_num = -1;
1157 unsigned long quirks;
1158 int num_rx_buf;
1159 int i;
1160 int combined_interfaces = 0;
1161 struct device *tty_dev;
1162 int rv = -ENOMEM;
1164 /* normal quirks */
1165 quirks = (unsigned long)id->driver_info;
1167 if (quirks == IGNORE_DEVICE)
1168 return -ENODEV;
1170 memset(&h, 0x00, sizeof(struct usb_cdc_parsed_header));
1172 num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR;
1174 /* handle quirks deadly to normal probing*/
1175 if (quirks == NO_UNION_NORMAL) {
1176 data_interface = usb_ifnum_to_if(usb_dev, 1);
1177 control_interface = usb_ifnum_to_if(usb_dev, 0);
1178 /* we would crash */
1179 if (!data_interface || !control_interface)
1180 return -ENODEV;
1181 goto skip_normal_probe;
1184 /* normal probing*/
1185 if (!buffer) {
1186 dev_err(&intf->dev, "Weird descriptor references\n");
1187 return -EINVAL;
1190 if (!intf->cur_altsetting)
1191 return -EINVAL;
1193 if (!buflen) {
1194 if (intf->cur_altsetting->endpoint &&
1195 intf->cur_altsetting->endpoint->extralen &&
1196 intf->cur_altsetting->endpoint->extra) {
1197 dev_dbg(&intf->dev,
1198 "Seeking extra descriptors on endpoint\n");
1199 buflen = intf->cur_altsetting->endpoint->extralen;
1200 buffer = intf->cur_altsetting->endpoint->extra;
1201 } else {
1202 dev_err(&intf->dev,
1203 "Zero length descriptor references\n");
1204 return -EINVAL;
1208 cdc_parse_cdc_header(&h, intf, buffer, buflen);
1209 union_header = h.usb_cdc_union_desc;
1210 cmgmd = h.usb_cdc_call_mgmt_descriptor;
1211 if (cmgmd)
1212 call_intf_num = cmgmd->bDataInterface;
1214 if (!union_header) {
1215 if (call_intf_num > 0) {
1216 dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n");
1217 /* quirks for Droids MuIn LCD */
1218 if (quirks & NO_DATA_INTERFACE) {
1219 data_interface = usb_ifnum_to_if(usb_dev, 0);
1220 } else {
1221 data_intf_num = call_intf_num;
1222 data_interface = usb_ifnum_to_if(usb_dev, data_intf_num);
1224 control_interface = intf;
1225 } else {
1226 if (intf->cur_altsetting->desc.bNumEndpoints != 3) {
1227 dev_dbg(&intf->dev,"No union descriptor, giving up\n");
1228 return -ENODEV;
1229 } else {
1230 dev_warn(&intf->dev,"No union descriptor, testing for castrated device\n");
1231 combined_interfaces = 1;
1232 control_interface = data_interface = intf;
1233 goto look_for_collapsed_interface;
1236 } else {
1237 data_intf_num = union_header->bSlaveInterface0;
1238 control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0);
1239 data_interface = usb_ifnum_to_if(usb_dev, data_intf_num);
1242 if (!control_interface || !data_interface) {
1243 dev_dbg(&intf->dev, "no interfaces\n");
1244 return -ENODEV;
1246 if (!data_interface->cur_altsetting || !control_interface->cur_altsetting)
1247 return -ENODEV;
1249 if (data_intf_num != call_intf_num)
1250 dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n");
1252 if (control_interface == data_interface) {
1253 /* some broken devices designed for windows work this way */
1254 dev_warn(&intf->dev,"Control and data interfaces are not separated!\n");
1255 combined_interfaces = 1;
1256 /* a popular other OS doesn't use it */
1257 quirks |= NO_CAP_LINE;
1258 if (data_interface->cur_altsetting->desc.bNumEndpoints != 3) {
1259 dev_err(&intf->dev, "This needs exactly 3 endpoints\n");
1260 return -EINVAL;
1262 look_for_collapsed_interface:
1263 for (i = 0; i < 3; i++) {
1264 struct usb_endpoint_descriptor *ep;
1265 ep = &data_interface->cur_altsetting->endpoint[i].desc;
1267 if (usb_endpoint_is_int_in(ep))
1268 epctrl = ep;
1269 else if (usb_endpoint_is_bulk_out(ep))
1270 epwrite = ep;
1271 else if (usb_endpoint_is_bulk_in(ep))
1272 epread = ep;
1273 else
1274 return -EINVAL;
1276 if (!epctrl || !epread || !epwrite)
1277 return -ENODEV;
1278 else
1279 goto made_compressed_probe;
1282 skip_normal_probe:
1284 /*workaround for switched interfaces */
1285 if (data_interface->cur_altsetting->desc.bInterfaceClass
1286 != CDC_DATA_INTERFACE_TYPE) {
1287 if (control_interface->cur_altsetting->desc.bInterfaceClass
1288 == CDC_DATA_INTERFACE_TYPE) {
1289 dev_dbg(&intf->dev,
1290 "Your device has switched interfaces.\n");
1291 swap(control_interface, data_interface);
1292 } else {
1293 return -EINVAL;
1297 /* Accept probe requests only for the control interface */
1298 if (!combined_interfaces && intf != control_interface)
1299 return -ENODEV;
1301 if (!combined_interfaces && usb_interface_claimed(data_interface)) {
1302 /* valid in this context */
1303 dev_dbg(&intf->dev, "The data interface isn't available\n");
1304 return -EBUSY;
1308 if (data_interface->cur_altsetting->desc.bNumEndpoints < 2 ||
1309 control_interface->cur_altsetting->desc.bNumEndpoints == 0)
1310 return -EINVAL;
1312 epctrl = &control_interface->cur_altsetting->endpoint[0].desc;
1313 epread = &data_interface->cur_altsetting->endpoint[0].desc;
1314 epwrite = &data_interface->cur_altsetting->endpoint[1].desc;
1317 /* workaround for switched endpoints */
1318 if (!usb_endpoint_dir_in(epread)) {
1319 /* descriptors are swapped */
1320 dev_dbg(&intf->dev,
1321 "The data interface has switched endpoints\n");
1322 swap(epread, epwrite);
1324 made_compressed_probe:
1325 dev_dbg(&intf->dev, "interfaces are valid\n");
1327 acm = kzalloc(sizeof(struct acm), GFP_KERNEL);
1328 if (acm == NULL)
1329 goto alloc_fail;
1331 minor = acm_alloc_minor(acm);
1332 if (minor < 0)
1333 goto alloc_fail1;
1335 ctrlsize = usb_endpoint_maxp(epctrl);
1336 readsize = usb_endpoint_maxp(epread) *
1337 (quirks == SINGLE_RX_URB ? 1 : 2);
1338 acm->combined_interfaces = combined_interfaces;
1339 acm->writesize = usb_endpoint_maxp(epwrite) * 20;
1340 acm->control = control_interface;
1341 acm->data = data_interface;
1342 acm->minor = minor;
1343 acm->dev = usb_dev;
1344 if (h.usb_cdc_acm_descriptor)
1345 acm->ctrl_caps = h.usb_cdc_acm_descriptor->bmCapabilities;
1346 if (quirks & NO_CAP_LINE)
1347 acm->ctrl_caps &= ~USB_CDC_CAP_LINE;
1348 acm->ctrlsize = ctrlsize;
1349 acm->readsize = readsize;
1350 acm->rx_buflimit = num_rx_buf;
1351 INIT_WORK(&acm->work, acm_softint);
1352 init_waitqueue_head(&acm->wioctl);
1353 spin_lock_init(&acm->write_lock);
1354 spin_lock_init(&acm->read_lock);
1355 mutex_init(&acm->mutex);
1356 acm->is_int_ep = usb_endpoint_xfer_int(epread);
1357 if (acm->is_int_ep)
1358 acm->bInterval = epread->bInterval;
1359 tty_port_init(&acm->port);
1360 acm->port.ops = &acm_port_ops;
1361 init_usb_anchor(&acm->delayed);
1362 acm->quirks = quirks;
1364 buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
1365 if (!buf)
1366 goto alloc_fail2;
1367 acm->ctrl_buffer = buf;
1369 if (acm_write_buffers_alloc(acm) < 0)
1370 goto alloc_fail4;
1372 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);
1373 if (!acm->ctrlurb)
1374 goto alloc_fail5;
1376 for (i = 0; i < num_rx_buf; i++) {
1377 struct acm_rb *rb = &(acm->read_buffers[i]);
1378 struct urb *urb;
1380 rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL,
1381 &rb->dma);
1382 if (!rb->base)
1383 goto alloc_fail6;
1384 rb->index = i;
1385 rb->instance = acm;
1387 urb = usb_alloc_urb(0, GFP_KERNEL);
1388 if (!urb)
1389 goto alloc_fail6;
1391 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1392 urb->transfer_dma = rb->dma;
1393 if (acm->is_int_ep) {
1394 usb_fill_int_urb(urb, acm->dev,
1395 usb_rcvintpipe(usb_dev, epread->bEndpointAddress),
1396 rb->base,
1397 acm->readsize,
1398 acm_read_bulk_callback, rb,
1399 acm->bInterval);
1400 } else {
1401 usb_fill_bulk_urb(urb, acm->dev,
1402 usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress),
1403 rb->base,
1404 acm->readsize,
1405 acm_read_bulk_callback, rb);
1408 acm->read_urbs[i] = urb;
1409 __set_bit(i, &acm->read_urbs_free);
1411 for (i = 0; i < ACM_NW; i++) {
1412 struct acm_wb *snd = &(acm->wb[i]);
1414 snd->urb = usb_alloc_urb(0, GFP_KERNEL);
1415 if (snd->urb == NULL)
1416 goto alloc_fail7;
1418 if (usb_endpoint_xfer_int(epwrite))
1419 usb_fill_int_urb(snd->urb, usb_dev,
1420 usb_sndintpipe(usb_dev, epwrite->bEndpointAddress),
1421 NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval);
1422 else
1423 usb_fill_bulk_urb(snd->urb, usb_dev,
1424 usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
1425 NULL, acm->writesize, acm_write_bulk, snd);
1426 snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1427 if (quirks & SEND_ZERO_PACKET)
1428 snd->urb->transfer_flags |= URB_ZERO_PACKET;
1429 snd->instance = acm;
1432 usb_set_intfdata(intf, acm);
1434 i = device_create_file(&intf->dev, &dev_attr_bmCapabilities);
1435 if (i < 0)
1436 goto alloc_fail7;
1438 if (h.usb_cdc_country_functional_desc) { /* export the country data */
1439 struct usb_cdc_country_functional_desc * cfd =
1440 h.usb_cdc_country_functional_desc;
1442 acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL);
1443 if (!acm->country_codes)
1444 goto skip_countries;
1445 acm->country_code_size = cfd->bLength - 4;
1446 memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0,
1447 cfd->bLength - 4);
1448 acm->country_rel_date = cfd->iCountryCodeRelDate;
1450 i = device_create_file(&intf->dev, &dev_attr_wCountryCodes);
1451 if (i < 0) {
1452 kfree(acm->country_codes);
1453 acm->country_codes = NULL;
1454 acm->country_code_size = 0;
1455 goto skip_countries;
1458 i = device_create_file(&intf->dev,
1459 &dev_attr_iCountryCodeRelDate);
1460 if (i < 0) {
1461 device_remove_file(&intf->dev, &dev_attr_wCountryCodes);
1462 kfree(acm->country_codes);
1463 acm->country_codes = NULL;
1464 acm->country_code_size = 0;
1465 goto skip_countries;
1469 skip_countries:
1470 usb_fill_int_urb(acm->ctrlurb, usb_dev,
1471 usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress),
1472 acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm,
1473 /* works around buggy devices */
1474 epctrl->bInterval ? epctrl->bInterval : 16);
1475 acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1476 acm->ctrlurb->transfer_dma = acm->ctrl_dma;
1478 dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor);
1480 acm->line.dwDTERate = cpu_to_le32(9600);
1481 acm->line.bDataBits = 8;
1482 acm_set_line(acm, &acm->line);
1484 usb_driver_claim_interface(&acm_driver, data_interface, acm);
1485 usb_set_intfdata(data_interface, acm);
1487 usb_get_intf(control_interface);
1488 tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor,
1489 &control_interface->dev);
1490 if (IS_ERR(tty_dev)) {
1491 rv = PTR_ERR(tty_dev);
1492 goto alloc_fail8;
1495 if (quirks & CLEAR_HALT_CONDITIONS) {
1496 usb_clear_halt(usb_dev, usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress));
1497 usb_clear_halt(usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress));
1500 return 0;
1501 alloc_fail8:
1502 if (acm->country_codes) {
1503 device_remove_file(&acm->control->dev,
1504 &dev_attr_wCountryCodes);
1505 device_remove_file(&acm->control->dev,
1506 &dev_attr_iCountryCodeRelDate);
1507 kfree(acm->country_codes);
1509 device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities);
1510 alloc_fail7:
1511 usb_set_intfdata(intf, NULL);
1512 for (i = 0; i < ACM_NW; i++)
1513 usb_free_urb(acm->wb[i].urb);
1514 alloc_fail6:
1515 for (i = 0; i < num_rx_buf; i++)
1516 usb_free_urb(acm->read_urbs[i]);
1517 acm_read_buffers_free(acm);
1518 usb_free_urb(acm->ctrlurb);
1519 alloc_fail5:
1520 acm_write_buffers_free(acm);
1521 alloc_fail4:
1522 usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
1523 alloc_fail2:
1524 acm_release_minor(acm);
1525 alloc_fail1:
1526 kfree(acm);
1527 alloc_fail:
1528 return rv;
1531 static void stop_data_traffic(struct acm *acm)
1533 int i;
1535 usb_kill_urb(acm->ctrlurb);
1536 for (i = 0; i < ACM_NW; i++)
1537 usb_kill_urb(acm->wb[i].urb);
1538 for (i = 0; i < acm->rx_buflimit; i++)
1539 usb_kill_urb(acm->read_urbs[i]);
1541 cancel_work_sync(&acm->work);
1544 static void acm_disconnect(struct usb_interface *intf)
1546 struct acm *acm = usb_get_intfdata(intf);
1547 struct usb_device *usb_dev = interface_to_usbdev(intf);
1548 struct tty_struct *tty;
1549 int i;
1551 /* sibling interface is already cleaning up */
1552 if (!acm)
1553 return;
1555 mutex_lock(&acm->mutex);
1556 acm->disconnected = true;
1557 if (acm->country_codes) {
1558 device_remove_file(&acm->control->dev,
1559 &dev_attr_wCountryCodes);
1560 device_remove_file(&acm->control->dev,
1561 &dev_attr_iCountryCodeRelDate);
1563 wake_up_all(&acm->wioctl);
1564 device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities);
1565 usb_set_intfdata(acm->control, NULL);
1566 usb_set_intfdata(acm->data, NULL);
1567 mutex_unlock(&acm->mutex);
1569 tty = tty_port_tty_get(&acm->port);
1570 if (tty) {
1571 tty_vhangup(tty);
1572 tty_kref_put(tty);
1575 stop_data_traffic(acm);
1577 tty_unregister_device(acm_tty_driver, acm->minor);
1579 usb_free_urb(acm->ctrlurb);
1580 for (i = 0; i < ACM_NW; i++)
1581 usb_free_urb(acm->wb[i].urb);
1582 for (i = 0; i < acm->rx_buflimit; i++)
1583 usb_free_urb(acm->read_urbs[i]);
1584 acm_write_buffers_free(acm);
1585 usb_free_coherent(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
1586 acm_read_buffers_free(acm);
1588 if (!acm->combined_interfaces)
1589 usb_driver_release_interface(&acm_driver, intf == acm->control ?
1590 acm->data : acm->control);
1592 tty_port_put(&acm->port);
1595 #ifdef CONFIG_PM
1596 static int acm_suspend(struct usb_interface *intf, pm_message_t message)
1598 struct acm *acm = usb_get_intfdata(intf);
1599 int cnt;
1601 spin_lock_irq(&acm->write_lock);
1602 if (PMSG_IS_AUTO(message)) {
1603 if (acm->transmitting) {
1604 spin_unlock_irq(&acm->write_lock);
1605 return -EBUSY;
1608 cnt = acm->susp_count++;
1609 spin_unlock_irq(&acm->write_lock);
1611 if (cnt)
1612 return 0;
1614 stop_data_traffic(acm);
1616 return 0;
1619 static int acm_resume(struct usb_interface *intf)
1621 struct acm *acm = usb_get_intfdata(intf);
1622 struct urb *urb;
1623 int rv = 0;
1625 spin_lock_irq(&acm->write_lock);
1627 if (--acm->susp_count)
1628 goto out;
1630 if (tty_port_initialized(&acm->port)) {
1631 rv = usb_submit_urb(acm->ctrlurb, GFP_ATOMIC);
1633 for (;;) {
1634 urb = usb_get_from_anchor(&acm->delayed);
1635 if (!urb)
1636 break;
1638 acm_start_wb(acm, urb->context);
1642 * delayed error checking because we must
1643 * do the write path at all cost
1645 if (rv < 0)
1646 goto out;
1648 rv = acm_submit_read_urbs(acm, GFP_ATOMIC);
1650 out:
1651 spin_unlock_irq(&acm->write_lock);
1653 return rv;
1656 static int acm_reset_resume(struct usb_interface *intf)
1658 struct acm *acm = usb_get_intfdata(intf);
1660 if (tty_port_initialized(&acm->port))
1661 tty_port_tty_hangup(&acm->port, false);
1663 return acm_resume(intf);
1666 #endif /* CONFIG_PM */
1668 #define NOKIA_PCSUITE_ACM_INFO(x) \
1669 USB_DEVICE_AND_INTERFACE_INFO(0x0421, x, \
1670 USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \
1671 USB_CDC_ACM_PROTO_VENDOR)
1673 #define SAMSUNG_PCSUITE_ACM_INFO(x) \
1674 USB_DEVICE_AND_INTERFACE_INFO(0x04e7, x, \
1675 USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \
1676 USB_CDC_ACM_PROTO_VENDOR)
1679 * USB driver structure.
1682 static const struct usb_device_id acm_ids[] = {
1683 /* quirky and broken devices */
1684 { USB_DEVICE(0x076d, 0x0006), /* Denso Cradle CU-321 */
1685 .driver_info = NO_UNION_NORMAL, },/* has no union descriptor */
1686 { USB_DEVICE(0x17ef, 0x7000), /* Lenovo USB modem */
1687 .driver_info = NO_UNION_NORMAL, },/* has no union descriptor */
1688 { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */
1689 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1691 { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */
1692 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1694 { USB_DEVICE(0x0e8d, 0x3329), /* MediaTek Inc GPS */
1695 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1697 { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */
1698 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1700 { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */
1701 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1703 { USB_DEVICE(0x0ace, 0x1602), /* ZyDAS 56K USB MODEM */
1704 .driver_info = SINGLE_RX_URB,
1706 { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */
1707 .driver_info = SINGLE_RX_URB, /* firmware bug */
1709 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
1710 .driver_info = SINGLE_RX_URB, /* firmware bug */
1712 { USB_DEVICE(0x11ca, 0x0201), /* VeriFone Mx870 Gadget Serial */
1713 .driver_info = SINGLE_RX_URB,
1715 { USB_DEVICE(0x1965, 0x0018), /* Uniden UBC125XLT */
1716 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1718 { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
1719 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1721 { USB_DEVICE(0x0803, 0x3095), /* Zoom Telephonics Model 3095F USB MODEM */
1722 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1724 { USB_DEVICE(0x0572, 0x1321), /* Conexant USB MODEM CX93010 */
1725 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1727 { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */
1728 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1730 { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */
1731 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1733 { USB_DEVICE(0x20df, 0x0001), /* Simtec Electronics Entropy Key */
1734 .driver_info = QUIRK_CONTROL_LINE_STATE, },
1735 { USB_DEVICE(0x2184, 0x001c) }, /* GW Instek AFG-2225 */
1736 { USB_DEVICE(0x2184, 0x0036) }, /* GW Instek AFG-125 */
1737 { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */
1739 /* Motorola H24 HSPA module: */
1740 { USB_DEVICE(0x22b8, 0x2d91) }, /* modem */
1741 { USB_DEVICE(0x22b8, 0x2d92), /* modem + diagnostics */
1742 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1744 { USB_DEVICE(0x22b8, 0x2d93), /* modem + AT port */
1745 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1747 { USB_DEVICE(0x22b8, 0x2d95), /* modem + AT port + diagnostics */
1748 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1750 { USB_DEVICE(0x22b8, 0x2d96), /* modem + NMEA */
1751 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1753 { USB_DEVICE(0x22b8, 0x2d97), /* modem + diagnostics + NMEA */
1754 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1756 { USB_DEVICE(0x22b8, 0x2d99), /* modem + AT port + NMEA */
1757 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1759 { USB_DEVICE(0x22b8, 0x2d9a), /* modem + AT port + diagnostics + NMEA */
1760 .driver_info = NO_UNION_NORMAL, /* handle only modem interface */
1763 { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */
1764 .driver_info = NO_UNION_NORMAL, /* union descriptor misplaced on
1765 data interface instead of
1766 communications interface.
1767 Maybe we should define a new
1768 quirk for this. */
1770 { USB_DEVICE(0x0572, 0x1340), /* Conexant CX93010-2x UCMxx */
1771 .driver_info = NO_UNION_NORMAL,
1773 { USB_DEVICE(0x05f9, 0x4002), /* PSC Scanning, Magellan 800i */
1774 .driver_info = NO_UNION_NORMAL,
1776 { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */
1777 .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
1779 { USB_DEVICE(0x1576, 0x03b1), /* Maretron USB100 */
1780 .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
1782 { USB_DEVICE(0xfff0, 0x0100), /* DATECS FP-2000 */
1783 .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
1785 { USB_DEVICE(0x09d8, 0x0320), /* Elatec GmbH TWN3 */
1786 .driver_info = NO_UNION_NORMAL, /* has misplaced union descriptor */
1788 { USB_DEVICE(0x0ca6, 0xa050), /* Castles VEGA3000 */
1789 .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
1792 { USB_DEVICE(0x2912, 0x0001), /* ATOL FPrint */
1793 .driver_info = CLEAR_HALT_CONDITIONS,
1796 /* Nokia S60 phones expose two ACM channels. The first is
1797 * a modem and is picked up by the standard AT-command
1798 * information below. The second is 'vendor-specific' but
1799 * is treated as a serial device at the S60 end, so we want
1800 * to expose it on Linux too. */
1801 { NOKIA_PCSUITE_ACM_INFO(0x042D), }, /* Nokia 3250 */
1802 { NOKIA_PCSUITE_ACM_INFO(0x04D8), }, /* Nokia 5500 Sport */
1803 { NOKIA_PCSUITE_ACM_INFO(0x04C9), }, /* Nokia E50 */
1804 { NOKIA_PCSUITE_ACM_INFO(0x0419), }, /* Nokia E60 */
1805 { NOKIA_PCSUITE_ACM_INFO(0x044D), }, /* Nokia E61 */
1806 { NOKIA_PCSUITE_ACM_INFO(0x0001), }, /* Nokia E61i */
1807 { NOKIA_PCSUITE_ACM_INFO(0x0475), }, /* Nokia E62 */
1808 { NOKIA_PCSUITE_ACM_INFO(0x0508), }, /* Nokia E65 */
1809 { NOKIA_PCSUITE_ACM_INFO(0x0418), }, /* Nokia E70 */
1810 { NOKIA_PCSUITE_ACM_INFO(0x0425), }, /* Nokia N71 */
1811 { NOKIA_PCSUITE_ACM_INFO(0x0486), }, /* Nokia N73 */
1812 { NOKIA_PCSUITE_ACM_INFO(0x04DF), }, /* Nokia N75 */
1813 { NOKIA_PCSUITE_ACM_INFO(0x000e), }, /* Nokia N77 */
1814 { NOKIA_PCSUITE_ACM_INFO(0x0445), }, /* Nokia N80 */
1815 { NOKIA_PCSUITE_ACM_INFO(0x042F), }, /* Nokia N91 & N91 8GB */
1816 { NOKIA_PCSUITE_ACM_INFO(0x048E), }, /* Nokia N92 */
1817 { NOKIA_PCSUITE_ACM_INFO(0x0420), }, /* Nokia N93 */
1818 { NOKIA_PCSUITE_ACM_INFO(0x04E6), }, /* Nokia N93i */
1819 { NOKIA_PCSUITE_ACM_INFO(0x04B2), }, /* Nokia 5700 XpressMusic */
1820 { NOKIA_PCSUITE_ACM_INFO(0x0134), }, /* Nokia 6110 Navigator (China) */
1821 { NOKIA_PCSUITE_ACM_INFO(0x046E), }, /* Nokia 6110 Navigator */
1822 { NOKIA_PCSUITE_ACM_INFO(0x002f), }, /* Nokia 6120 classic & */
1823 { NOKIA_PCSUITE_ACM_INFO(0x0088), }, /* Nokia 6121 classic */
1824 { NOKIA_PCSUITE_ACM_INFO(0x00fc), }, /* Nokia 6124 classic */
1825 { NOKIA_PCSUITE_ACM_INFO(0x0042), }, /* Nokia E51 */
1826 { NOKIA_PCSUITE_ACM_INFO(0x00b0), }, /* Nokia E66 */
1827 { NOKIA_PCSUITE_ACM_INFO(0x00ab), }, /* Nokia E71 */
1828 { NOKIA_PCSUITE_ACM_INFO(0x0481), }, /* Nokia N76 */
1829 { NOKIA_PCSUITE_ACM_INFO(0x0007), }, /* Nokia N81 & N81 8GB */
1830 { NOKIA_PCSUITE_ACM_INFO(0x0071), }, /* Nokia N82 */
1831 { NOKIA_PCSUITE_ACM_INFO(0x04F0), }, /* Nokia N95 & N95-3 NAM */
1832 { NOKIA_PCSUITE_ACM_INFO(0x0070), }, /* Nokia N95 8GB */
1833 { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */
1834 { NOKIA_PCSUITE_ACM_INFO(0x0099), }, /* Nokia 6210 Navigator, RM-367 */
1835 { NOKIA_PCSUITE_ACM_INFO(0x0128), }, /* Nokia 6210 Navigator, RM-419 */
1836 { NOKIA_PCSUITE_ACM_INFO(0x008f), }, /* Nokia 6220 Classic */
1837 { NOKIA_PCSUITE_ACM_INFO(0x00a0), }, /* Nokia 6650 */
1838 { NOKIA_PCSUITE_ACM_INFO(0x007b), }, /* Nokia N78 */
1839 { NOKIA_PCSUITE_ACM_INFO(0x0094), }, /* Nokia N85 */
1840 { NOKIA_PCSUITE_ACM_INFO(0x003a), }, /* Nokia N96 & N96-3 */
1841 { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */
1842 { NOKIA_PCSUITE_ACM_INFO(0x0108), }, /* Nokia 5320 XpressMusic 2G */
1843 { NOKIA_PCSUITE_ACM_INFO(0x01f5), }, /* Nokia N97, RM-505 */
1844 { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */
1845 { NOKIA_PCSUITE_ACM_INFO(0x0178), }, /* Nokia E63 */
1846 { NOKIA_PCSUITE_ACM_INFO(0x010e), }, /* Nokia E75 */
1847 { NOKIA_PCSUITE_ACM_INFO(0x02d9), }, /* Nokia 6760 Slide */
1848 { NOKIA_PCSUITE_ACM_INFO(0x01d0), }, /* Nokia E52 */
1849 { NOKIA_PCSUITE_ACM_INFO(0x0223), }, /* Nokia E72 */
1850 { NOKIA_PCSUITE_ACM_INFO(0x0275), }, /* Nokia X6 */
1851 { NOKIA_PCSUITE_ACM_INFO(0x026c), }, /* Nokia N97 Mini */
1852 { NOKIA_PCSUITE_ACM_INFO(0x0154), }, /* Nokia 5800 XpressMusic */
1853 { NOKIA_PCSUITE_ACM_INFO(0x04ce), }, /* Nokia E90 */
1854 { NOKIA_PCSUITE_ACM_INFO(0x01d4), }, /* Nokia E55 */
1855 { NOKIA_PCSUITE_ACM_INFO(0x0302), }, /* Nokia N8 */
1856 { NOKIA_PCSUITE_ACM_INFO(0x0335), }, /* Nokia E7 */
1857 { NOKIA_PCSUITE_ACM_INFO(0x03cd), }, /* Nokia C7 */
1858 { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */
1860 /* Support for Owen devices */
1861 { USB_DEVICE(0x03eb, 0x0030), }, /* Owen SI30 */
1863 /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */
1865 /* Support for Droids MuIn LCD */
1866 { USB_DEVICE(0x04d8, 0x000b),
1867 .driver_info = NO_DATA_INTERFACE,
1870 #if IS_ENABLED(CONFIG_INPUT_IMS_PCU)
1871 { USB_DEVICE(0x04d8, 0x0082), /* Application mode */
1872 .driver_info = IGNORE_DEVICE,
1874 { USB_DEVICE(0x04d8, 0x0083), /* Bootloader mode */
1875 .driver_info = IGNORE_DEVICE,
1877 #endif
1879 /*Samsung phone in firmware update mode */
1880 { USB_DEVICE(0x04e8, 0x685d),
1881 .driver_info = IGNORE_DEVICE,
1884 /* Exclude Infineon Flash Loader utility */
1885 { USB_DEVICE(0x058b, 0x0041),
1886 .driver_info = IGNORE_DEVICE,
1889 /* control interfaces without any protocol set */
1890 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1891 USB_CDC_PROTO_NONE) },
1893 /* control interfaces with various AT-command sets */
1894 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1895 USB_CDC_ACM_PROTO_AT_V25TER) },
1896 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1897 USB_CDC_ACM_PROTO_AT_PCCA101) },
1898 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1899 USB_CDC_ACM_PROTO_AT_PCCA101_WAKE) },
1900 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1901 USB_CDC_ACM_PROTO_AT_GSM) },
1902 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1903 USB_CDC_ACM_PROTO_AT_3G) },
1904 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1905 USB_CDC_ACM_PROTO_AT_CDMA) },
1907 { USB_DEVICE(0x1519, 0x0452), /* Intel 7260 modem */
1908 .driver_info = SEND_ZERO_PACKET,
1914 MODULE_DEVICE_TABLE(usb, acm_ids);
1916 static struct usb_driver acm_driver = {
1917 .name = "cdc_acm",
1918 .probe = acm_probe,
1919 .disconnect = acm_disconnect,
1920 #ifdef CONFIG_PM
1921 .suspend = acm_suspend,
1922 .resume = acm_resume,
1923 .reset_resume = acm_reset_resume,
1924 #endif
1925 .id_table = acm_ids,
1926 #ifdef CONFIG_PM
1927 .supports_autosuspend = 1,
1928 #endif
1929 .disable_hub_initiated_lpm = 1,
1933 * TTY driver structures.
1936 static const struct tty_operations acm_ops = {
1937 .install = acm_tty_install,
1938 .open = acm_tty_open,
1939 .close = acm_tty_close,
1940 .cleanup = acm_tty_cleanup,
1941 .hangup = acm_tty_hangup,
1942 .write = acm_tty_write,
1943 .put_char = acm_tty_put_char,
1944 .flush_chars = acm_tty_flush_chars,
1945 .write_room = acm_tty_write_room,
1946 .ioctl = acm_tty_ioctl,
1947 .throttle = acm_tty_throttle,
1948 .unthrottle = acm_tty_unthrottle,
1949 .chars_in_buffer = acm_tty_chars_in_buffer,
1950 .break_ctl = acm_tty_break_ctl,
1951 .set_termios = acm_tty_set_termios,
1952 .tiocmget = acm_tty_tiocmget,
1953 .tiocmset = acm_tty_tiocmset,
1957 * Init / exit.
1960 static int __init acm_init(void)
1962 int retval;
1963 acm_tty_driver = alloc_tty_driver(ACM_TTY_MINORS);
1964 if (!acm_tty_driver)
1965 return -ENOMEM;
1966 acm_tty_driver->driver_name = "acm",
1967 acm_tty_driver->name = "ttyACM",
1968 acm_tty_driver->major = ACM_TTY_MAJOR,
1969 acm_tty_driver->minor_start = 0,
1970 acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL,
1971 acm_tty_driver->subtype = SERIAL_TYPE_NORMAL,
1972 acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
1973 acm_tty_driver->init_termios = tty_std_termios;
1974 acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD |
1975 HUPCL | CLOCAL;
1976 tty_set_operations(acm_tty_driver, &acm_ops);
1978 retval = tty_register_driver(acm_tty_driver);
1979 if (retval) {
1980 put_tty_driver(acm_tty_driver);
1981 return retval;
1984 retval = usb_register(&acm_driver);
1985 if (retval) {
1986 tty_unregister_driver(acm_tty_driver);
1987 put_tty_driver(acm_tty_driver);
1988 return retval;
1991 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
1993 return 0;
1996 static void __exit acm_exit(void)
1998 usb_deregister(&acm_driver);
1999 tty_unregister_driver(acm_tty_driver);
2000 put_tty_driver(acm_tty_driver);
2001 idr_destroy(&acm_minors);
2004 module_init(acm_init);
2005 module_exit(acm_exit);
2007 MODULE_AUTHOR(DRIVER_AUTHOR);
2008 MODULE_DESCRIPTION(DRIVER_DESC);
2009 MODULE_LICENSE("GPL");
2010 MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR);