| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * cdc-acm.c | 
|  | 3 | * | 
|  | 4 | * Copyright (c) 1999 Armin Fuerst	<fuerst@in.tum.de> | 
|  | 5 | * Copyright (c) 1999 Pavel Machek	<pavel@suse.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> | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 9 | * Copyright (c) 2005 David Kubicek	<dave@awk.cz> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * | 
|  | 11 | * USB Abstract Control Model driver for USB modems and ISDN adapters | 
|  | 12 | * | 
|  | 13 | * Sponsored by SuSE | 
|  | 14 | * | 
|  | 15 | * ChangeLog: | 
|  | 16 | *	v0.9  - thorough cleaning, URBification, almost a rewrite | 
|  | 17 | *	v0.10 - some more cleanups | 
|  | 18 | *	v0.11 - fixed flow control, read error doesn't stop reads | 
|  | 19 | *	v0.12 - added TIOCM ioctls, added break handling, made struct acm kmalloced | 
|  | 20 | *	v0.13 - added termios, added hangup | 
|  | 21 | *	v0.14 - sized down struct acm | 
|  | 22 | *	v0.15 - fixed flow control again - characters could be lost | 
|  | 23 | *	v0.16 - added code for modems with swapped data and control interfaces | 
|  | 24 | *	v0.17 - added new style probing | 
|  | 25 | *	v0.18 - fixed new style probing for devices with more configurations | 
|  | 26 | *	v0.19 - fixed CLOCAL handling (thanks to Richard Shih-Ping Chan) | 
|  | 27 | *	v0.20 - switched to probing on interface (rather than device) class | 
|  | 28 | *	v0.21 - revert to probing on device for devices with multiple configs | 
|  | 29 | *	v0.22 - probe only the control interface. if usbcore doesn't choose the | 
|  | 30 | *		config we want, sysadmin changes bConfigurationValue in sysfs. | 
|  | 31 | *	v0.23 - use softirq for rx processing, as needed by tty layer | 
|  | 32 | *	v0.24 - change probe method to evaluate CDC union descriptor | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 33 | *	v0.25 - downstream tasks paralelized to maximize throughput | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 34 | *	v0.26 - multiple write urbs, writesize increased | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | */ | 
|  | 36 |  | 
|  | 37 | /* | 
|  | 38 | * This program is free software; you can redistribute it and/or modify | 
|  | 39 | * it under the terms of the GNU General Public License as published by | 
|  | 40 | * the Free Software Foundation; either version 2 of the License, or | 
|  | 41 | * (at your option) any later version. | 
|  | 42 | * | 
|  | 43 | * This program is distributed in the hope that it will be useful, | 
|  | 44 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 45 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 46 | * GNU General Public License for more details. | 
|  | 47 | * | 
|  | 48 | * You should have received a copy of the GNU General Public License | 
|  | 49 | * along with this program; if not, write to the Free Software | 
|  | 50 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 
|  | 51 | */ | 
|  | 52 |  | 
|  | 53 | #undef DEBUG | 
|  | 54 |  | 
|  | 55 | #include <linux/kernel.h> | 
|  | 56 | #include <linux/errno.h> | 
|  | 57 | #include <linux/init.h> | 
|  | 58 | #include <linux/slab.h> | 
|  | 59 | #include <linux/tty.h> | 
|  | 60 | #include <linux/tty_driver.h> | 
|  | 61 | #include <linux/tty_flip.h> | 
|  | 62 | #include <linux/module.h> | 
| Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 63 | #include <linux/mutex.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #include <asm/uaccess.h> | 
|  | 65 | #include <linux/usb.h> | 
| David Brownell | a8c28f2 | 2006-06-13 09:57:47 -0700 | [diff] [blame] | 66 | #include <linux/usb/cdc.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #include <asm/byteorder.h> | 
|  | 68 | #include <asm/unaligned.h> | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 69 | #include <linux/list.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 |  | 
|  | 71 | #include "cdc-acm.h" | 
|  | 72 |  | 
|  | 73 | /* | 
|  | 74 | * Version Information | 
|  | 75 | */ | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 76 | #define DRIVER_VERSION "v0.26" | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 77 | #define DRIVER_AUTHOR "Armin Fuerst, Pavel Machek, Johannes Erdfelt, Vojtech Pavlik, David Kubicek" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #define DRIVER_DESC "USB Abstract Control Model driver for USB modems and ISDN adapters" | 
|  | 79 |  | 
|  | 80 | static struct usb_driver acm_driver; | 
|  | 81 | static struct tty_driver *acm_tty_driver; | 
|  | 82 | static struct acm *acm_table[ACM_TTY_MINORS]; | 
|  | 83 |  | 
| Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 84 | static DEFINE_MUTEX(open_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 |  | 
|  | 86 | #define ACM_READY(acm)	(acm && acm->dev && acm->used) | 
|  | 87 |  | 
|  | 88 | /* | 
|  | 89 | * Functions for ACM control messages. | 
|  | 90 | */ | 
|  | 91 |  | 
|  | 92 | static int acm_ctrl_msg(struct acm *acm, int request, int value, void *buf, int len) | 
|  | 93 | { | 
|  | 94 | int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), | 
|  | 95 | request, USB_RT_ACM, value, | 
|  | 96 | acm->control->altsetting[0].desc.bInterfaceNumber, | 
|  | 97 | buf, len, 5000); | 
|  | 98 | dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", request, value, len, retval); | 
|  | 99 | return retval < 0 ? retval : 0; | 
|  | 100 | } | 
|  | 101 |  | 
|  | 102 | /* devices aren't required to support these requests. | 
|  | 103 | * the cdc acm descriptor tells whether they do... | 
|  | 104 | */ | 
|  | 105 | #define acm_set_control(acm, control) \ | 
|  | 106 | acm_ctrl_msg(acm, USB_CDC_REQ_SET_CONTROL_LINE_STATE, control, NULL, 0) | 
|  | 107 | #define acm_set_line(acm, line) \ | 
|  | 108 | acm_ctrl_msg(acm, USB_CDC_REQ_SET_LINE_CODING, 0, line, sizeof *(line)) | 
|  | 109 | #define acm_send_break(acm, ms) \ | 
|  | 110 | acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0) | 
|  | 111 |  | 
|  | 112 | /* | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 113 | * Write buffer management. | 
|  | 114 | * All of these assume proper locks taken by the caller. | 
|  | 115 | */ | 
|  | 116 |  | 
|  | 117 | static int acm_wb_alloc(struct acm *acm) | 
|  | 118 | { | 
|  | 119 | int i, wbn; | 
|  | 120 | struct acm_wb *wb; | 
|  | 121 |  | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 122 | wbn = 0; | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 123 | i = 0; | 
|  | 124 | for (;;) { | 
|  | 125 | wb = &acm->wb[wbn]; | 
|  | 126 | if (!wb->use) { | 
|  | 127 | wb->use = 1; | 
|  | 128 | return wbn; | 
|  | 129 | } | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 130 | wbn = (wbn + 1) % ACM_NW; | 
|  | 131 | if (++i >= ACM_NW) | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 132 | return -1; | 
|  | 133 | } | 
|  | 134 | } | 
|  | 135 |  | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 136 | static int acm_wb_is_avail(struct acm *acm) | 
|  | 137 | { | 
|  | 138 | int i, n; | 
|  | 139 |  | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 140 | n = ACM_NW; | 
|  | 141 | for (i = 0; i < ACM_NW; i++) { | 
|  | 142 | n -= acm->wb[i].use; | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 143 | } | 
|  | 144 | return n; | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | static inline int acm_wb_is_used(struct acm *acm, int wbn) | 
|  | 148 | { | 
|  | 149 | return acm->wb[wbn].use; | 
|  | 150 | } | 
|  | 151 |  | 
|  | 152 | /* | 
|  | 153 | * Finish write. | 
|  | 154 | */ | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 155 | static void acm_write_done(struct acm *acm, struct acm_wb *wb) | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 156 | { | 
|  | 157 | unsigned long flags; | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 158 |  | 
|  | 159 | spin_lock_irqsave(&acm->write_lock, flags); | 
|  | 160 | acm->write_ready = 1; | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 161 | wb->use = 0; | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 162 | acm->transmitting--; | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 163 | spin_unlock_irqrestore(&acm->write_lock, flags); | 
|  | 164 | } | 
|  | 165 |  | 
|  | 166 | /* | 
|  | 167 | * Poke write. | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 168 | * | 
|  | 169 | * the caller is responsible for locking | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 170 | */ | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 171 |  | 
|  | 172 | static int acm_start_wb(struct acm *acm, struct acm_wb *wb) | 
|  | 173 | { | 
|  | 174 | int rc; | 
|  | 175 |  | 
|  | 176 | acm->transmitting++; | 
|  | 177 |  | 
|  | 178 | wb->urb->transfer_buffer = wb->buf; | 
|  | 179 | wb->urb->transfer_dma = wb->dmah; | 
|  | 180 | wb->urb->transfer_buffer_length = wb->len; | 
|  | 181 | wb->urb->dev = acm->dev; | 
|  | 182 |  | 
|  | 183 | if ((rc = usb_submit_urb(wb->urb, GFP_ATOMIC)) < 0) { | 
|  | 184 | dbg("usb_submit_urb(write bulk) failed: %d", rc); | 
|  | 185 | acm_write_done(acm, wb); | 
|  | 186 | } | 
|  | 187 | return rc; | 
|  | 188 | } | 
|  | 189 |  | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 190 | static int acm_write_start(struct acm *acm, int wbn) | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 191 | { | 
|  | 192 | unsigned long flags; | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 193 | struct acm_wb *wb; | 
|  | 194 | int rc; | 
|  | 195 |  | 
|  | 196 | spin_lock_irqsave(&acm->write_lock, flags); | 
|  | 197 | if (!acm->dev) { | 
|  | 198 | spin_unlock_irqrestore(&acm->write_lock, flags); | 
|  | 199 | return -ENODEV; | 
|  | 200 | } | 
|  | 201 |  | 
|  | 202 | if (!acm->write_ready) { | 
|  | 203 | spin_unlock_irqrestore(&acm->write_lock, flags); | 
|  | 204 | return 0;	/* A white lie */ | 
|  | 205 | } | 
|  | 206 |  | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 207 | wb = &acm->wb[wbn]; | 
|  | 208 | if(acm_wb_is_avail(acm) <= 1) | 
|  | 209 | acm->write_ready = 0; | 
|  | 210 |  | 
|  | 211 | dbg("%s susp_count: %d", __func__, acm->susp_count); | 
|  | 212 | if (acm->susp_count) { | 
|  | 213 | acm->old_ready = acm->write_ready; | 
|  | 214 | acm->delayed_wb = wb; | 
|  | 215 | acm->write_ready = 0; | 
|  | 216 | schedule_work(&acm->waker); | 
|  | 217 | spin_unlock_irqrestore(&acm->write_lock, flags); | 
|  | 218 | return 0;	/* A white lie */ | 
|  | 219 | } | 
|  | 220 | usb_mark_last_busy(acm->dev); | 
|  | 221 |  | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 222 | if (!acm_wb_is_used(acm, wbn)) { | 
|  | 223 | spin_unlock_irqrestore(&acm->write_lock, flags); | 
|  | 224 | return 0; | 
|  | 225 | } | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 226 |  | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 227 | rc = acm_start_wb(acm, wb); | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 228 | spin_unlock_irqrestore(&acm->write_lock, flags); | 
|  | 229 |  | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 230 | return rc; | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 231 |  | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 232 | } | 
| Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 233 | /* | 
|  | 234 | * attributes exported through sysfs | 
|  | 235 | */ | 
|  | 236 | static ssize_t show_caps | 
|  | 237 | (struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 238 | { | 
|  | 239 | struct usb_interface *intf = to_usb_interface(dev); | 
|  | 240 | struct acm *acm = usb_get_intfdata(intf); | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 241 |  | 
| Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 242 | return sprintf(buf, "%d", acm->ctrl_caps); | 
|  | 243 | } | 
|  | 244 | static DEVICE_ATTR(bmCapabilities, S_IRUGO, show_caps, NULL); | 
|  | 245 |  | 
|  | 246 | static ssize_t show_country_codes | 
|  | 247 | (struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 248 | { | 
|  | 249 | struct usb_interface *intf = to_usb_interface(dev); | 
|  | 250 | struct acm *acm = usb_get_intfdata(intf); | 
|  | 251 |  | 
|  | 252 | memcpy(buf, acm->country_codes, acm->country_code_size); | 
|  | 253 | return acm->country_code_size; | 
|  | 254 | } | 
|  | 255 |  | 
|  | 256 | static DEVICE_ATTR(wCountryCodes, S_IRUGO, show_country_codes, NULL); | 
|  | 257 |  | 
|  | 258 | static ssize_t show_country_rel_date | 
|  | 259 | (struct device *dev, struct device_attribute *attr, char *buf) | 
|  | 260 | { | 
|  | 261 | struct usb_interface *intf = to_usb_interface(dev); | 
|  | 262 | struct acm *acm = usb_get_intfdata(intf); | 
|  | 263 |  | 
|  | 264 | return sprintf(buf, "%d", acm->country_rel_date); | 
|  | 265 | } | 
|  | 266 |  | 
|  | 267 | static DEVICE_ATTR(iCountryCodeRelDate, S_IRUGO, show_country_rel_date, NULL); | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 268 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | * Interrupt handlers for various ACM device responses | 
|  | 270 | */ | 
|  | 271 |  | 
|  | 272 | /* control interface reports status changes with "interrupt" transfers */ | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 273 | static void acm_ctrl_irq(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { | 
|  | 275 | struct acm *acm = urb->context; | 
|  | 276 | struct usb_cdc_notification *dr = urb->transfer_buffer; | 
|  | 277 | unsigned char *data; | 
|  | 278 | int newctrl; | 
| Greg Kroah-Hartman | 185d405 | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 279 | int retval; | 
|  | 280 | int status = urb->status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 |  | 
| Greg Kroah-Hartman | 185d405 | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 282 | switch (status) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | case 0: | 
|  | 284 | /* success */ | 
|  | 285 | break; | 
|  | 286 | case -ECONNRESET: | 
|  | 287 | case -ENOENT: | 
|  | 288 | case -ESHUTDOWN: | 
|  | 289 | /* this urb is terminated, clean up */ | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 290 | dbg("%s - urb shutting down with status: %d", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | return; | 
|  | 292 | default: | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 293 | dbg("%s - nonzero urb status received: %d", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | goto exit; | 
|  | 295 | } | 
|  | 296 |  | 
|  | 297 | if (!ACM_READY(acm)) | 
|  | 298 | goto exit; | 
|  | 299 |  | 
|  | 300 | data = (unsigned char *)(dr + 1); | 
|  | 301 | switch (dr->bNotificationType) { | 
|  | 302 |  | 
|  | 303 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: | 
|  | 304 |  | 
|  | 305 | dbg("%s network", dr->wValue ? "connected to" : "disconnected from"); | 
|  | 306 | break; | 
|  | 307 |  | 
|  | 308 | case USB_CDC_NOTIFY_SERIAL_STATE: | 
|  | 309 |  | 
| Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 310 | newctrl = get_unaligned_le16(data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 |  | 
|  | 312 | if (acm->tty && !acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { | 
|  | 313 | dbg("calling hangup"); | 
|  | 314 | tty_hangup(acm->tty); | 
|  | 315 | } | 
|  | 316 |  | 
|  | 317 | acm->ctrlin = newctrl; | 
|  | 318 |  | 
|  | 319 | dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c", | 
|  | 320 | acm->ctrlin & ACM_CTRL_DCD ? '+' : '-',	acm->ctrlin & ACM_CTRL_DSR ? '+' : '-', | 
|  | 321 | acm->ctrlin & ACM_CTRL_BRK ? '+' : '-',	acm->ctrlin & ACM_CTRL_RI  ? '+' : '-', | 
|  | 322 | acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-',	acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-', | 
|  | 323 | acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-'); | 
|  | 324 |  | 
|  | 325 | break; | 
|  | 326 |  | 
|  | 327 | default: | 
|  | 328 | dbg("unknown notification %d received: index %d len %d data0 %d data1 %d", | 
|  | 329 | dr->bNotificationType, dr->wIndex, | 
|  | 330 | dr->wLength, data[0], data[1]); | 
|  | 331 | break; | 
|  | 332 | } | 
|  | 333 | exit: | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 334 | usb_mark_last_busy(acm->dev); | 
| Greg Kroah-Hartman | 185d405 | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 335 | retval = usb_submit_urb (urb, GFP_ATOMIC); | 
|  | 336 | if (retval) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | err ("%s - usb_submit_urb failed with result %d", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 338 | __func__, retval); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } | 
|  | 340 |  | 
|  | 341 | /* data interface returns incoming bytes, or we got unthrottled */ | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 342 | static void acm_read_bulk(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 344 | struct acm_rb *buf; | 
|  | 345 | struct acm_ru *rcv = urb->context; | 
|  | 346 | struct acm *acm = rcv->instance; | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 347 | int status = urb->status; | 
| Greg Kroah-Hartman | 185d405 | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 348 |  | 
|  | 349 | dbg("Entering acm_read_bulk with status %d", status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 |  | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 351 | if (!ACM_READY(acm)) { | 
|  | 352 | dev_dbg(&acm->data->dev, "Aborting, acm not ready"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return; | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 354 | } | 
|  | 355 | usb_mark_last_busy(acm->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 |  | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 357 | if (status) | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 358 | dev_dbg(&acm->data->dev, "bulk rx status %d\n", status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 |  | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 360 | buf = rcv->buffer; | 
|  | 361 | buf->size = urb->actual_length; | 
|  | 362 |  | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 363 | if (likely(status == 0)) { | 
|  | 364 | spin_lock(&acm->read_lock); | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 365 | acm->processing++; | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 366 | list_add_tail(&rcv->list, &acm->spare_read_urbs); | 
|  | 367 | list_add_tail(&buf->list, &acm->filled_read_bufs); | 
|  | 368 | spin_unlock(&acm->read_lock); | 
|  | 369 | } else { | 
|  | 370 | /* we drop the buffer due to an error */ | 
|  | 371 | spin_lock(&acm->read_lock); | 
|  | 372 | list_add_tail(&rcv->list, &acm->spare_read_urbs); | 
|  | 373 | list_add(&buf->list, &acm->spare_read_bufs); | 
|  | 374 | spin_unlock(&acm->read_lock); | 
|  | 375 | /* nevertheless the tasklet must be kicked unconditionally | 
|  | 376 | so the queue cannot dry up */ | 
|  | 377 | } | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 378 | if (likely(!acm->susp_count)) | 
|  | 379 | tasklet_schedule(&acm->urb_task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } | 
|  | 381 |  | 
|  | 382 | static void acm_rx_tasklet(unsigned long _acm) | 
|  | 383 | { | 
|  | 384 | struct acm *acm = (void *)_acm; | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 385 | struct acm_rb *buf; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | struct tty_struct *tty = acm->tty; | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 387 | struct acm_ru *rcv; | 
| Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 388 | unsigned long flags; | 
| Oliver Neukum | ca79b7b | 2007-02-12 08:41:35 +0100 | [diff] [blame] | 389 | unsigned char throttled; | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 390 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | dbg("Entering acm_rx_tasklet"); | 
|  | 392 |  | 
| Oliver Neukum | ca79b7b | 2007-02-12 08:41:35 +0100 | [diff] [blame] | 393 | if (!ACM_READY(acm)) | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 394 | { | 
|  | 395 | dbg("acm_rx_tasklet: ACM not ready"); | 
| Oliver Neukum | ca79b7b | 2007-02-12 08:41:35 +0100 | [diff] [blame] | 396 | return; | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 397 | } | 
| Oliver Neukum | ca79b7b | 2007-02-12 08:41:35 +0100 | [diff] [blame] | 398 |  | 
| Oliver Neukum | 834dbca | 2007-03-06 10:47:04 +0100 | [diff] [blame] | 399 | spin_lock_irqsave(&acm->throttle_lock, flags); | 
| Oliver Neukum | ca79b7b | 2007-02-12 08:41:35 +0100 | [diff] [blame] | 400 | throttled = acm->throttle; | 
| Oliver Neukum | 834dbca | 2007-03-06 10:47:04 +0100 | [diff] [blame] | 401 | spin_unlock_irqrestore(&acm->throttle_lock, flags); | 
| Oliver Neukum | ca79b7b | 2007-02-12 08:41:35 +0100 | [diff] [blame] | 402 | if (throttled) | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 403 | { | 
|  | 404 | dbg("acm_rx_tasklet: throttled"); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 405 | return; | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 406 | } | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 407 |  | 
|  | 408 | next_buffer: | 
| Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 409 | spin_lock_irqsave(&acm->read_lock, flags); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 410 | if (list_empty(&acm->filled_read_bufs)) { | 
| Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 411 | spin_unlock_irqrestore(&acm->read_lock, flags); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 412 | goto urbs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 414 | buf = list_entry(acm->filled_read_bufs.next, | 
|  | 415 | struct acm_rb, list); | 
|  | 416 | list_del(&buf->list); | 
| Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 417 | spin_unlock_irqrestore(&acm->read_lock, flags); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 418 |  | 
| Oliver Neukum | 3dd2ae8 | 2006-06-23 09:14:17 +0200 | [diff] [blame] | 419 | dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 420 |  | 
| Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 421 | tty_buffer_request_room(tty, buf->size); | 
| Oliver Neukum | 834dbca | 2007-03-06 10:47:04 +0100 | [diff] [blame] | 422 | spin_lock_irqsave(&acm->throttle_lock, flags); | 
| Oliver Neukum | ca79b7b | 2007-02-12 08:41:35 +0100 | [diff] [blame] | 423 | throttled = acm->throttle; | 
| Oliver Neukum | 834dbca | 2007-03-06 10:47:04 +0100 | [diff] [blame] | 424 | spin_unlock_irqrestore(&acm->throttle_lock, flags); | 
| Oliver Neukum | ca79b7b | 2007-02-12 08:41:35 +0100 | [diff] [blame] | 425 | if (!throttled) | 
| Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 426 | tty_insert_flip_string(tty, buf->base, buf->size); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 427 | tty_flip_buffer_push(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 |  | 
| Oliver Neukum | ca79b7b | 2007-02-12 08:41:35 +0100 | [diff] [blame] | 429 | if (throttled) { | 
|  | 430 | dbg("Throttling noticed"); | 
| Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 431 | spin_lock_irqsave(&acm->read_lock, flags); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 432 | list_add(&buf->list, &acm->filled_read_bufs); | 
| Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 433 | spin_unlock_irqrestore(&acm->read_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | return; | 
|  | 435 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 |  | 
| Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 437 | spin_lock_irqsave(&acm->read_lock, flags); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 438 | list_add(&buf->list, &acm->spare_read_bufs); | 
| Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 439 | spin_unlock_irqrestore(&acm->read_lock, flags); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 440 | goto next_buffer; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 |  | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 442 | urbs: | 
|  | 443 | while (!list_empty(&acm->spare_read_bufs)) { | 
| Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 444 | spin_lock_irqsave(&acm->read_lock, flags); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 445 | if (list_empty(&acm->spare_read_urbs)) { | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 446 | acm->processing = 0; | 
| Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 447 | spin_unlock_irqrestore(&acm->read_lock, flags); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 448 | return; | 
|  | 449 | } | 
|  | 450 | rcv = list_entry(acm->spare_read_urbs.next, | 
|  | 451 | struct acm_ru, list); | 
|  | 452 | list_del(&rcv->list); | 
| Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 453 | spin_unlock_irqrestore(&acm->read_lock, flags); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 454 |  | 
|  | 455 | buf = list_entry(acm->spare_read_bufs.next, | 
|  | 456 | struct acm_rb, list); | 
|  | 457 | list_del(&buf->list); | 
|  | 458 |  | 
|  | 459 | rcv->buffer = buf; | 
|  | 460 |  | 
|  | 461 | usb_fill_bulk_urb(rcv->urb, acm->dev, | 
|  | 462 | acm->rx_endpoint, | 
|  | 463 | buf->base, | 
|  | 464 | acm->readsize, | 
|  | 465 | acm_read_bulk, rcv); | 
|  | 466 | rcv->urb->transfer_dma = buf->dma; | 
|  | 467 | rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 
|  | 468 |  | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 469 | /* This shouldn't kill the driver as unsuccessful URBs are returned to the | 
|  | 470 | free-urbs-pool and resubmited ASAP */ | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 471 | spin_lock_irqsave(&acm->read_lock, flags); | 
|  | 472 | if (acm->susp_count || usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) { | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 473 | list_add(&buf->list, &acm->spare_read_bufs); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 474 | list_add(&rcv->list, &acm->spare_read_urbs); | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 475 | acm->processing = 0; | 
| Jarek Poplawski | 762f007 | 2006-10-06 07:23:11 +0200 | [diff] [blame] | 476 | spin_unlock_irqrestore(&acm->read_lock, flags); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 477 | return; | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 478 | } else { | 
|  | 479 | spin_unlock_irqrestore(&acm->read_lock, flags); | 
|  | 480 | dbg("acm_rx_tasklet: sending urb 0x%p, rcv 0x%p, buf 0x%p", rcv->urb, rcv, buf); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 481 | } | 
|  | 482 | } | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 483 | spin_lock_irqsave(&acm->read_lock, flags); | 
|  | 484 | acm->processing = 0; | 
|  | 485 | spin_unlock_irqrestore(&acm->read_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | } | 
|  | 487 |  | 
|  | 488 | /* data interface wrote those outgoing bytes */ | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 489 | static void acm_write_bulk(struct urb *urb) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 491 | struct acm *acm; | 
| Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 492 | struct acm_wb *wb = urb->context; | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 493 |  | 
| Oliver Neukum | 3dd2ae8 | 2006-06-23 09:14:17 +0200 | [diff] [blame] | 494 | dbg("Entering acm_write_bulk with status %d", urb->status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 |  | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 496 | acm = wb->instance; | 
|  | 497 | acm_write_done(acm, wb); | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 498 | if (ACM_READY(acm)) | 
|  | 499 | schedule_work(&acm->work); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | } | 
|  | 501 |  | 
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 502 | static void acm_softint(struct work_struct *work) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { | 
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 504 | struct acm *acm = container_of(work, struct acm, work); | 
| Oliver Neukum | 3dd2ae8 | 2006-06-23 09:14:17 +0200 | [diff] [blame] | 505 | dbg("Entering acm_softint."); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 |  | 
|  | 507 | if (!ACM_READY(acm)) | 
|  | 508 | return; | 
|  | 509 | tty_wakeup(acm->tty); | 
|  | 510 | } | 
|  | 511 |  | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 512 | static void acm_waker(struct work_struct *waker) | 
|  | 513 | { | 
|  | 514 | struct acm *acm = container_of(waker, struct acm, waker); | 
|  | 515 | long flags; | 
|  | 516 | int rv; | 
|  | 517 |  | 
|  | 518 | rv = usb_autopm_get_interface(acm->control); | 
|  | 519 | if (rv < 0) { | 
|  | 520 | err("Autopm failure in %s", __func__); | 
|  | 521 | return; | 
|  | 522 | } | 
|  | 523 | if (acm->delayed_wb) { | 
|  | 524 | acm_start_wb(acm, acm->delayed_wb); | 
|  | 525 | acm->delayed_wb = NULL; | 
|  | 526 | } | 
|  | 527 | spin_lock_irqsave(&acm->write_lock, flags); | 
|  | 528 | acm->write_ready = acm->old_ready; | 
|  | 529 | spin_unlock_irqrestore(&acm->write_lock, flags); | 
|  | 530 | usb_autopm_put_interface(acm->control); | 
|  | 531 | } | 
|  | 532 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | /* | 
|  | 534 | * TTY handlers | 
|  | 535 | */ | 
|  | 536 |  | 
|  | 537 | static int acm_tty_open(struct tty_struct *tty, struct file *filp) | 
|  | 538 | { | 
|  | 539 | struct acm *acm; | 
|  | 540 | int rv = -EINVAL; | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 541 | int i; | 
| Oliver Neukum | 3dd2ae8 | 2006-06-23 09:14:17 +0200 | [diff] [blame] | 542 | dbg("Entering acm_tty_open."); | 
| Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 543 |  | 
|  | 544 | mutex_lock(&open_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 |  | 
|  | 546 | acm = acm_table[tty->index]; | 
|  | 547 | if (!acm || !acm->dev) | 
|  | 548 | goto err_out; | 
|  | 549 | else | 
|  | 550 | rv = 0; | 
|  | 551 |  | 
| David Engraf | 28d1dfa | 2008-03-20 10:53:52 +0100 | [diff] [blame] | 552 | set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | tty->driver_data = acm; | 
|  | 554 | acm->tty = tty; | 
|  | 555 |  | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 556 | /* force low_latency on so that our tty_push actually forces the data through, | 
|  | 557 | otherwise it is scheduled, and with high data rates data can get lost. */ | 
|  | 558 | tty->low_latency = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 |  | 
| Oliver Neukum | 94409cc | 2008-02-11 15:22:29 +0100 | [diff] [blame] | 560 | if (usb_autopm_get_interface(acm->control) < 0) | 
|  | 561 | goto early_bail; | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 562 | else | 
|  | 563 | acm->control->needs_remote_wakeup = 1; | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 564 |  | 
|  | 565 | mutex_lock(&acm->mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | if (acm->used++) { | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 567 | usb_autopm_put_interface(acm->control); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | goto done; | 
|  | 569 | } | 
|  | 570 |  | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 571 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | acm->ctrlurb->dev = acm->dev; | 
|  | 573 | if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { | 
|  | 574 | dbg("usb_submit_urb(ctrl irq) failed"); | 
|  | 575 | goto bail_out; | 
|  | 576 | } | 
|  | 577 |  | 
| Oliver Neukum | ca79b7b | 2007-02-12 08:41:35 +0100 | [diff] [blame] | 578 | if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) && | 
|  | 579 | (acm->ctrl_caps & USB_CDC_CAP_LINE)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | goto full_bailout; | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 581 | usb_autopm_put_interface(acm->control); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 |  | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 583 | INIT_LIST_HEAD(&acm->spare_read_urbs); | 
|  | 584 | INIT_LIST_HEAD(&acm->spare_read_bufs); | 
|  | 585 | INIT_LIST_HEAD(&acm->filled_read_bufs); | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 586 | for (i = 0; i < acm->rx_buflimit; i++) { | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 587 | list_add(&(acm->ru[i].list), &acm->spare_read_urbs); | 
|  | 588 | } | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 589 | for (i = 0; i < acm->rx_buflimit; i++) { | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 590 | list_add(&(acm->rb[i].list), &acm->spare_read_bufs); | 
|  | 591 | } | 
|  | 592 |  | 
| Oliver Neukum | ca79b7b | 2007-02-12 08:41:35 +0100 | [diff] [blame] | 593 | acm->throttle = 0; | 
|  | 594 |  | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 595 | tasklet_schedule(&acm->urb_task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 |  | 
|  | 597 | done: | 
|  | 598 | err_out: | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 599 | mutex_unlock(&acm->mutex); | 
| Oliver Neukum | 94409cc | 2008-02-11 15:22:29 +0100 | [diff] [blame] | 600 | mutex_unlock(&open_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | return rv; | 
|  | 602 |  | 
|  | 603 | full_bailout: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | usb_kill_urb(acm->ctrlurb); | 
|  | 605 | bail_out: | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 606 | usb_autopm_put_interface(acm->control); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | acm->used--; | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 608 | mutex_unlock(&acm->mutex); | 
| Oliver Neukum | 94409cc | 2008-02-11 15:22:29 +0100 | [diff] [blame] | 609 | early_bail: | 
|  | 610 | mutex_unlock(&open_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | return -EIO; | 
|  | 612 | } | 
|  | 613 |  | 
| brian@murphy.dk | 83ef344 | 2005-06-29 16:53:29 -0700 | [diff] [blame] | 614 | static void acm_tty_unregister(struct acm *acm) | 
|  | 615 | { | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 616 | int i,nr; | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 617 |  | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 618 | nr = acm->rx_buflimit; | 
| brian@murphy.dk | 83ef344 | 2005-06-29 16:53:29 -0700 | [diff] [blame] | 619 | tty_unregister_device(acm_tty_driver, acm->minor); | 
|  | 620 | usb_put_intf(acm->control); | 
|  | 621 | acm_table[acm->minor] = NULL; | 
|  | 622 | usb_free_urb(acm->ctrlurb); | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 623 | for (i = 0; i < ACM_NW; i++) | 
|  | 624 | usb_free_urb(acm->wb[i].urb); | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 625 | for (i = 0; i < nr; i++) | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 626 | usb_free_urb(acm->ru[i].urb); | 
| Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 627 | kfree(acm->country_codes); | 
| brian@murphy.dk | 83ef344 | 2005-06-29 16:53:29 -0700 | [diff] [blame] | 628 | kfree(acm); | 
|  | 629 | } | 
|  | 630 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | static void acm_tty_close(struct tty_struct *tty, struct file *filp) | 
|  | 632 | { | 
|  | 633 | struct acm *acm = tty->driver_data; | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 634 | int i,nr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 |  | 
|  | 636 | if (!acm || !acm->used) | 
|  | 637 | return; | 
|  | 638 |  | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 639 | nr = acm->rx_buflimit; | 
| Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 640 | mutex_lock(&open_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | if (!--acm->used) { | 
|  | 642 | if (acm->dev) { | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 643 | usb_autopm_get_interface(acm->control); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | acm_set_control(acm, acm->ctrlout = 0); | 
|  | 645 | usb_kill_urb(acm->ctrlurb); | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 646 | for (i = 0; i < ACM_NW; i++) | 
|  | 647 | usb_kill_urb(acm->wb[i].urb); | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 648 | for (i = 0; i < nr; i++) | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 649 | usb_kill_urb(acm->ru[i].urb); | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 650 | acm->control->needs_remote_wakeup = 0; | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 651 | usb_autopm_put_interface(acm->control); | 
| brian@murphy.dk | 83ef344 | 2005-06-29 16:53:29 -0700 | [diff] [blame] | 652 | } else | 
|  | 653 | acm_tty_unregister(acm); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } | 
| Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 655 | mutex_unlock(&open_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } | 
|  | 657 |  | 
|  | 658 | static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) | 
|  | 659 | { | 
|  | 660 | struct acm *acm = tty->driver_data; | 
|  | 661 | int stat; | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 662 | unsigned long flags; | 
|  | 663 | int wbn; | 
|  | 664 | struct acm_wb *wb; | 
|  | 665 |  | 
| Oliver Neukum | 3dd2ae8 | 2006-06-23 09:14:17 +0200 | [diff] [blame] | 666 | dbg("Entering acm_tty_write to write %d bytes,", count); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 |  | 
|  | 668 | if (!ACM_READY(acm)) | 
|  | 669 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | if (!count) | 
|  | 671 | return 0; | 
|  | 672 |  | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 673 | spin_lock_irqsave(&acm->write_lock, flags); | 
|  | 674 | if ((wbn = acm_wb_alloc(acm)) < 0) { | 
|  | 675 | spin_unlock_irqrestore(&acm->write_lock, flags); | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 676 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | } | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 678 | wb = &acm->wb[wbn]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 |  | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 680 | count = (count > acm->writesize) ? acm->writesize : count; | 
|  | 681 | dbg("Get %d bytes...", count); | 
|  | 682 | memcpy(wb->buf, buf, count); | 
|  | 683 | wb->len = count; | 
|  | 684 | spin_unlock_irqrestore(&acm->write_lock, flags); | 
|  | 685 |  | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 686 | if ((stat = acm_write_start(acm, wbn)) < 0) | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 687 | return stat; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | return count; | 
|  | 689 | } | 
|  | 690 |  | 
|  | 691 | static int acm_tty_write_room(struct tty_struct *tty) | 
|  | 692 | { | 
|  | 693 | struct acm *acm = tty->driver_data; | 
|  | 694 | if (!ACM_READY(acm)) | 
|  | 695 | return -EINVAL; | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 696 | /* | 
|  | 697 | * Do not let the line discipline to know that we have a reserve, | 
|  | 698 | * or it might get too enthusiastic. | 
|  | 699 | */ | 
|  | 700 | return (acm->write_ready && acm_wb_is_avail(acm)) ? acm->writesize : 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | } | 
|  | 702 |  | 
|  | 703 | static int acm_tty_chars_in_buffer(struct tty_struct *tty) | 
|  | 704 | { | 
|  | 705 | struct acm *acm = tty->driver_data; | 
|  | 706 | if (!ACM_READY(acm)) | 
|  | 707 | return -EINVAL; | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 708 | /* | 
|  | 709 | * This is inaccurate (overcounts), but it works. | 
|  | 710 | */ | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 711 | return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } | 
|  | 713 |  | 
|  | 714 | static void acm_tty_throttle(struct tty_struct *tty) | 
|  | 715 | { | 
|  | 716 | struct acm *acm = tty->driver_data; | 
|  | 717 | if (!ACM_READY(acm)) | 
|  | 718 | return; | 
|  | 719 | spin_lock_bh(&acm->throttle_lock); | 
|  | 720 | acm->throttle = 1; | 
|  | 721 | spin_unlock_bh(&acm->throttle_lock); | 
|  | 722 | } | 
|  | 723 |  | 
|  | 724 | static void acm_tty_unthrottle(struct tty_struct *tty) | 
|  | 725 | { | 
|  | 726 | struct acm *acm = tty->driver_data; | 
|  | 727 | if (!ACM_READY(acm)) | 
|  | 728 | return; | 
|  | 729 | spin_lock_bh(&acm->throttle_lock); | 
|  | 730 | acm->throttle = 0; | 
|  | 731 | spin_unlock_bh(&acm->throttle_lock); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 732 | tasklet_schedule(&acm->urb_task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } | 
|  | 734 |  | 
|  | 735 | static void acm_tty_break_ctl(struct tty_struct *tty, int state) | 
|  | 736 | { | 
|  | 737 | struct acm *acm = tty->driver_data; | 
|  | 738 | if (!ACM_READY(acm)) | 
|  | 739 | return; | 
|  | 740 | if (acm_send_break(acm, state ? 0xffff : 0)) | 
|  | 741 | dbg("send break failed"); | 
|  | 742 | } | 
|  | 743 |  | 
|  | 744 | static int acm_tty_tiocmget(struct tty_struct *tty, struct file *file) | 
|  | 745 | { | 
|  | 746 | struct acm *acm = tty->driver_data; | 
|  | 747 |  | 
|  | 748 | if (!ACM_READY(acm)) | 
|  | 749 | return -EINVAL; | 
|  | 750 |  | 
|  | 751 | return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) | | 
|  | 752 | (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) | | 
|  | 753 | (acm->ctrlin  & ACM_CTRL_DSR ? TIOCM_DSR : 0) | | 
|  | 754 | (acm->ctrlin  & ACM_CTRL_RI  ? TIOCM_RI  : 0) | | 
|  | 755 | (acm->ctrlin  & ACM_CTRL_DCD ? TIOCM_CD  : 0) | | 
|  | 756 | TIOCM_CTS; | 
|  | 757 | } | 
|  | 758 |  | 
|  | 759 | static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file, | 
|  | 760 | unsigned int set, unsigned int clear) | 
|  | 761 | { | 
|  | 762 | struct acm *acm = tty->driver_data; | 
|  | 763 | unsigned int newctrl; | 
|  | 764 |  | 
|  | 765 | if (!ACM_READY(acm)) | 
|  | 766 | return -EINVAL; | 
|  | 767 |  | 
|  | 768 | newctrl = acm->ctrlout; | 
|  | 769 | set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); | 
|  | 770 | clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); | 
|  | 771 |  | 
|  | 772 | newctrl = (newctrl & ~clear) | set; | 
|  | 773 |  | 
|  | 774 | if (acm->ctrlout == newctrl) | 
|  | 775 | return 0; | 
|  | 776 | return acm_set_control(acm, acm->ctrlout = newctrl); | 
|  | 777 | } | 
|  | 778 |  | 
|  | 779 | static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) | 
|  | 780 | { | 
|  | 781 | struct acm *acm = tty->driver_data; | 
|  | 782 |  | 
|  | 783 | if (!ACM_READY(acm)) | 
|  | 784 | return -EINVAL; | 
|  | 785 |  | 
|  | 786 | return -ENOIOCTLCMD; | 
|  | 787 | } | 
|  | 788 |  | 
| Arjan van de Ven | 4c4c943 | 2005-11-29 09:43:42 +0100 | [diff] [blame] | 789 | static const __u32 acm_tty_speed[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | 0, 50, 75, 110, 134, 150, 200, 300, 600, | 
|  | 791 | 1200, 1800, 2400, 4800, 9600, 19200, 38400, | 
|  | 792 | 57600, 115200, 230400, 460800, 500000, 576000, | 
|  | 793 | 921600, 1000000, 1152000, 1500000, 2000000, | 
|  | 794 | 2500000, 3000000, 3500000, 4000000 | 
|  | 795 | }; | 
|  | 796 |  | 
| Arjan van de Ven | 4c4c943 | 2005-11-29 09:43:42 +0100 | [diff] [blame] | 797 | static const __u8 acm_tty_size[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | 5, 6, 7, 8 | 
|  | 799 | }; | 
|  | 800 |  | 
| Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 801 | static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | { | 
|  | 803 | struct acm *acm = tty->driver_data; | 
| Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 804 | struct ktermios *termios = tty->termios; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | struct usb_cdc_line_coding newline; | 
|  | 806 | int newctrl = acm->ctrlout; | 
|  | 807 |  | 
|  | 808 | if (!ACM_READY(acm)) | 
|  | 809 | return; | 
|  | 810 |  | 
|  | 811 | newline.dwDTERate = cpu_to_le32p(acm_tty_speed + | 
|  | 812 | (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0)); | 
|  | 813 | newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; | 
|  | 814 | newline.bParityType = termios->c_cflag & PARENB ? | 
|  | 815 | (termios->c_cflag & PARODD ? 1 : 2) + (termios->c_cflag & CMSPAR ? 2 : 0) : 0; | 
|  | 816 | newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4]; | 
|  | 817 |  | 
|  | 818 | acm->clocal = ((termios->c_cflag & CLOCAL) != 0); | 
|  | 819 |  | 
|  | 820 | if (!newline.dwDTERate) { | 
|  | 821 | newline.dwDTERate = acm->line.dwDTERate; | 
|  | 822 | newctrl &= ~ACM_CTRL_DTR; | 
|  | 823 | } else  newctrl |=  ACM_CTRL_DTR; | 
|  | 824 |  | 
|  | 825 | if (newctrl != acm->ctrlout) | 
|  | 826 | acm_set_control(acm, acm->ctrlout = newctrl); | 
|  | 827 |  | 
|  | 828 | if (memcmp(&acm->line, &newline, sizeof newline)) { | 
|  | 829 | memcpy(&acm->line, &newline, sizeof newline); | 
|  | 830 | dbg("set line: %d %d %d %d", le32_to_cpu(newline.dwDTERate), | 
|  | 831 | newline.bCharFormat, newline.bParityType, | 
|  | 832 | newline.bDataBits); | 
|  | 833 | acm_set_line(acm, &acm->line); | 
|  | 834 | } | 
|  | 835 | } | 
|  | 836 |  | 
|  | 837 | /* | 
|  | 838 | * USB probe and disconnect routines. | 
|  | 839 | */ | 
|  | 840 |  | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 841 | /* Little helper: write buffers free */ | 
|  | 842 | static void acm_write_buffers_free(struct acm *acm) | 
|  | 843 | { | 
|  | 844 | int i; | 
|  | 845 | struct acm_wb *wb; | 
|  | 846 |  | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 847 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 848 | usb_buffer_free(acm->dev, acm->writesize, wb->buf, wb->dmah); | 
|  | 849 | } | 
|  | 850 | } | 
|  | 851 |  | 
|  | 852 | /* Little helper: write buffers allocate */ | 
|  | 853 | static int acm_write_buffers_alloc(struct acm *acm) | 
|  | 854 | { | 
|  | 855 | int i; | 
|  | 856 | struct acm_wb *wb; | 
|  | 857 |  | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 858 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 859 | wb->buf = usb_buffer_alloc(acm->dev, acm->writesize, GFP_KERNEL, | 
|  | 860 | &wb->dmah); | 
|  | 861 | if (!wb->buf) { | 
|  | 862 | while (i != 0) { | 
|  | 863 | --i; | 
|  | 864 | --wb; | 
|  | 865 | usb_buffer_free(acm->dev, acm->writesize, | 
|  | 866 | wb->buf, wb->dmah); | 
|  | 867 | } | 
|  | 868 | return -ENOMEM; | 
|  | 869 | } | 
|  | 870 | } | 
|  | 871 | return 0; | 
|  | 872 | } | 
|  | 873 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | static int acm_probe (struct usb_interface *intf, | 
|  | 875 | const struct usb_device_id *id) | 
|  | 876 | { | 
|  | 877 | struct usb_cdc_union_desc *union_header = NULL; | 
| Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 878 | struct usb_cdc_country_functional_desc *cfd = NULL; | 
| David Brownell | c6dbf55 | 2008-04-13 14:00:44 -0700 | [diff] [blame] | 879 | unsigned char *buffer = intf->altsetting->extra; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | int buflen = intf->altsetting->extralen; | 
|  | 881 | struct usb_interface *control_interface; | 
|  | 882 | struct usb_interface *data_interface; | 
|  | 883 | struct usb_endpoint_descriptor *epctrl; | 
|  | 884 | struct usb_endpoint_descriptor *epread; | 
|  | 885 | struct usb_endpoint_descriptor *epwrite; | 
|  | 886 | struct usb_device *usb_dev = interface_to_usbdev(intf); | 
|  | 887 | struct acm *acm; | 
|  | 888 | int minor; | 
|  | 889 | int ctrlsize,readsize; | 
|  | 890 | u8 *buf; | 
|  | 891 | u8 ac_management_function = 0; | 
|  | 892 | u8 call_management_function = 0; | 
|  | 893 | int call_interface_num = -1; | 
|  | 894 | int data_interface_num; | 
|  | 895 | unsigned long quirks; | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 896 | int num_rx_buf; | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 897 | int i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 |  | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 899 | /* normal quirks */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | quirks = (unsigned long)id->driver_info; | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 901 | num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR; | 
|  | 902 |  | 
|  | 903 | /* handle quirks deadly to normal probing*/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | if (quirks == NO_UNION_NORMAL) { | 
|  | 905 | data_interface = usb_ifnum_to_if(usb_dev, 1); | 
|  | 906 | control_interface = usb_ifnum_to_if(usb_dev, 0); | 
|  | 907 | goto skip_normal_probe; | 
|  | 908 | } | 
|  | 909 |  | 
|  | 910 | /* normal probing*/ | 
|  | 911 | if (!buffer) { | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 912 | err("Weird descriptor references\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | return -EINVAL; | 
|  | 914 | } | 
|  | 915 |  | 
|  | 916 | if (!buflen) { | 
|  | 917 | if (intf->cur_altsetting->endpoint->extralen && intf->cur_altsetting->endpoint->extra) { | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 918 | dev_dbg(&intf->dev,"Seeking extra descriptors on endpoint\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | buflen = intf->cur_altsetting->endpoint->extralen; | 
|  | 920 | buffer = intf->cur_altsetting->endpoint->extra; | 
|  | 921 | } else { | 
|  | 922 | err("Zero length descriptor references\n"); | 
|  | 923 | return -EINVAL; | 
|  | 924 | } | 
|  | 925 | } | 
|  | 926 |  | 
|  | 927 | while (buflen > 0) { | 
|  | 928 | if (buffer [1] != USB_DT_CS_INTERFACE) { | 
|  | 929 | err("skipping garbage\n"); | 
|  | 930 | goto next_desc; | 
|  | 931 | } | 
|  | 932 |  | 
|  | 933 | switch (buffer [2]) { | 
|  | 934 | case USB_CDC_UNION_TYPE: /* we've found it */ | 
|  | 935 | if (union_header) { | 
|  | 936 | err("More than one union descriptor, skipping ..."); | 
|  | 937 | goto next_desc; | 
|  | 938 | } | 
|  | 939 | union_header = (struct usb_cdc_union_desc *) | 
|  | 940 | buffer; | 
|  | 941 | break; | 
| Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 942 | case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/ | 
|  | 943 | cfd = (struct usb_cdc_country_functional_desc *)buffer; | 
|  | 944 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | case USB_CDC_HEADER_TYPE: /* maybe check version */ | 
|  | 946 | break; /* for now we ignore it */ | 
|  | 947 | case USB_CDC_ACM_TYPE: | 
|  | 948 | ac_management_function = buffer[3]; | 
|  | 949 | break; | 
|  | 950 | case USB_CDC_CALL_MANAGEMENT_TYPE: | 
|  | 951 | call_management_function = buffer[3]; | 
|  | 952 | call_interface_num = buffer[4]; | 
|  | 953 | if ((call_management_function & 3) != 3) | 
|  | 954 | err("This device cannot do calls on its own. It is no modem."); | 
|  | 955 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | default: | 
| David Brownell | c6dbf55 | 2008-04-13 14:00:44 -0700 | [diff] [blame] | 957 | /* there are LOTS more CDC descriptors that | 
|  | 958 | * could legitimately be found here. | 
|  | 959 | */ | 
|  | 960 | dev_dbg(&intf->dev, "Ignoring descriptor: " | 
|  | 961 | "type %02x, length %d\n", | 
|  | 962 | buffer[2], buffer[0]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | break; | 
|  | 964 | } | 
|  | 965 | next_desc: | 
|  | 966 | buflen -= buffer[0]; | 
|  | 967 | buffer += buffer[0]; | 
|  | 968 | } | 
|  | 969 |  | 
|  | 970 | if (!union_header) { | 
|  | 971 | if (call_interface_num > 0) { | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 972 | dev_dbg(&intf->dev,"No union descriptor, using call management descriptor\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); | 
|  | 974 | control_interface = intf; | 
|  | 975 | } else { | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 976 | dev_dbg(&intf->dev,"No union descriptor, giving up\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | return -ENODEV; | 
|  | 978 | } | 
|  | 979 | } else { | 
|  | 980 | control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); | 
|  | 981 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); | 
|  | 982 | if (!control_interface || !data_interface) { | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 983 | dev_dbg(&intf->dev,"no interfaces\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | return -ENODEV; | 
|  | 985 | } | 
|  | 986 | } | 
|  | 987 |  | 
|  | 988 | if (data_interface_num != call_interface_num) | 
| Joe Perches | dc0d5c1 | 2007-12-17 11:40:18 -0800 | [diff] [blame] | 989 | dev_dbg(&intf->dev,"Separate call control interface. That is not fully supported.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 |  | 
|  | 991 | skip_normal_probe: | 
|  | 992 |  | 
|  | 993 | /*workaround for switched interfaces */ | 
|  | 994 | if (data_interface->cur_altsetting->desc.bInterfaceClass != CDC_DATA_INTERFACE_TYPE) { | 
|  | 995 | if (control_interface->cur_altsetting->desc.bInterfaceClass == CDC_DATA_INTERFACE_TYPE) { | 
|  | 996 | struct usb_interface *t; | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 997 | dev_dbg(&intf->dev,"Your device has switched interfaces.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 |  | 
|  | 999 | t = control_interface; | 
|  | 1000 | control_interface = data_interface; | 
|  | 1001 | data_interface = t; | 
|  | 1002 | } else { | 
|  | 1003 | return -EINVAL; | 
|  | 1004 | } | 
|  | 1005 | } | 
| Alan Stern | 74da5d6 | 2007-08-02 13:29:10 -0400 | [diff] [blame] | 1006 |  | 
|  | 1007 | /* Accept probe requests only for the control interface */ | 
|  | 1008 | if (intf != control_interface) | 
|  | 1009 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 |  | 
|  | 1011 | if (usb_interface_claimed(data_interface)) { /* valid in this context */ | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1012 | dev_dbg(&intf->dev,"The data interface isn't available\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | return -EBUSY; | 
|  | 1014 | } | 
|  | 1015 |  | 
|  | 1016 |  | 
|  | 1017 | if (data_interface->cur_altsetting->desc.bNumEndpoints < 2) | 
|  | 1018 | return -EINVAL; | 
|  | 1019 |  | 
|  | 1020 | epctrl = &control_interface->cur_altsetting->endpoint[0].desc; | 
|  | 1021 | epread = &data_interface->cur_altsetting->endpoint[0].desc; | 
|  | 1022 | epwrite = &data_interface->cur_altsetting->endpoint[1].desc; | 
|  | 1023 |  | 
|  | 1024 |  | 
|  | 1025 | /* workaround for switched endpoints */ | 
| Luiz Fernando N. Capitulino | 45aea70 | 2006-10-26 13:02:48 -0300 | [diff] [blame] | 1026 | if (!usb_endpoint_dir_in(epread)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | /* descriptors are swapped */ | 
|  | 1028 | struct usb_endpoint_descriptor *t; | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1029 | dev_dbg(&intf->dev,"The data interface has switched endpoints\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 |  | 
|  | 1031 | t = epread; | 
|  | 1032 | epread = epwrite; | 
|  | 1033 | epwrite = t; | 
|  | 1034 | } | 
|  | 1035 | dbg("interfaces are valid"); | 
|  | 1036 | for (minor = 0; minor < ACM_TTY_MINORS && acm_table[minor]; minor++); | 
|  | 1037 |  | 
|  | 1038 | if (minor == ACM_TTY_MINORS) { | 
|  | 1039 | err("no more free acm devices"); | 
|  | 1040 | return -ENODEV; | 
|  | 1041 | } | 
|  | 1042 |  | 
| Oliver Neukum | 46f116e | 2005-10-24 22:42:35 +0200 | [diff] [blame] | 1043 | if (!(acm = kzalloc(sizeof(struct acm), GFP_KERNEL))) { | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1044 | dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | goto alloc_fail; | 
|  | 1046 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 |  | 
|  | 1048 | ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1049 | readsize = le16_to_cpu(epread->wMaxPacketSize)* ( quirks == SINGLE_RX_URB ? 1 : 2); | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 1050 | acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | acm->control = control_interface; | 
|  | 1052 | acm->data = data_interface; | 
|  | 1053 | acm->minor = minor; | 
|  | 1054 | acm->dev = usb_dev; | 
|  | 1055 | acm->ctrl_caps = ac_management_function; | 
|  | 1056 | acm->ctrlsize = ctrlsize; | 
|  | 1057 | acm->readsize = readsize; | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1058 | acm->rx_buflimit = num_rx_buf; | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1059 | acm->urb_task.func = acm_rx_tasklet; | 
|  | 1060 | acm->urb_task.data = (unsigned long) acm; | 
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1061 | INIT_WORK(&acm->work, acm_softint); | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 1062 | INIT_WORK(&acm->waker, acm_waker); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | spin_lock_init(&acm->throttle_lock); | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1064 | spin_lock_init(&acm->write_lock); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1065 | spin_lock_init(&acm->read_lock); | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1066 | mutex_init(&acm->mutex); | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1067 | acm->write_ready = 1; | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1068 | acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 |  | 
|  | 1070 | buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); | 
|  | 1071 | if (!buf) { | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1072 | dev_dbg(&intf->dev, "out of memory (ctrl buffer alloc)\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | goto alloc_fail2; | 
|  | 1074 | } | 
|  | 1075 | acm->ctrl_buffer = buf; | 
|  | 1076 |  | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1077 | if (acm_write_buffers_alloc(acm) < 0) { | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1078 | dev_dbg(&intf->dev, "out of memory (write buffer alloc)\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | goto alloc_fail4; | 
|  | 1080 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 |  | 
|  | 1082 | acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); | 
|  | 1083 | if (!acm->ctrlurb) { | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1084 | dev_dbg(&intf->dev, "out of memory (ctrlurb kmalloc)\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | goto alloc_fail5; | 
|  | 1086 | } | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1087 | for (i = 0; i < num_rx_buf; i++) { | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1088 | struct acm_ru *rcv = &(acm->ru[i]); | 
|  | 1089 |  | 
|  | 1090 | if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) { | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1091 | dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)\n"); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1092 | goto alloc_fail7; | 
|  | 1093 | } | 
|  | 1094 |  | 
|  | 1095 | rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 
|  | 1096 | rcv->instance = acm; | 
|  | 1097 | } | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1098 | for (i = 0; i < num_rx_buf; i++) { | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1099 | struct acm_rb *buf = &(acm->rb[i]); | 
|  | 1100 |  | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1101 | if (!(buf->base = usb_buffer_alloc(acm->dev, readsize, GFP_KERNEL, &buf->dma))) { | 
| Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 1102 | dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)\n"); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1103 | goto alloc_fail7; | 
|  | 1104 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | } | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 1106 | for(i = 0; i < ACM_NW; i++) | 
|  | 1107 | { | 
|  | 1108 | struct acm_wb *snd = &(acm->wb[i]); | 
|  | 1109 |  | 
|  | 1110 | if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) { | 
|  | 1111 | dev_dbg(&intf->dev, "out of memory (write urbs usb_alloc_urb)"); | 
|  | 1112 | goto alloc_fail7; | 
|  | 1113 | } | 
|  | 1114 |  | 
|  | 1115 | usb_fill_bulk_urb(snd->urb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), | 
|  | 1116 | NULL, acm->writesize, acm_write_bulk, snd); | 
|  | 1117 | snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 
|  | 1118 | snd->instance = acm; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | } | 
|  | 1120 |  | 
| Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1121 | usb_set_intfdata (intf, acm); | 
|  | 1122 |  | 
|  | 1123 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); | 
|  | 1124 | if (i < 0) | 
|  | 1125 | goto alloc_fail8; | 
|  | 1126 |  | 
|  | 1127 | if (cfd) { /* export the country data */ | 
|  | 1128 | acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL); | 
|  | 1129 | if (!acm->country_codes) | 
|  | 1130 | goto skip_countries; | 
|  | 1131 | acm->country_code_size = cfd->bLength - 4; | 
|  | 1132 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4); | 
|  | 1133 | acm->country_rel_date = cfd->iCountryCodeRelDate; | 
|  | 1134 |  | 
|  | 1135 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); | 
|  | 1136 | if (i < 0) { | 
|  | 1137 | kfree(acm->country_codes); | 
|  | 1138 | goto skip_countries; | 
|  | 1139 | } | 
|  | 1140 |  | 
|  | 1141 | i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate); | 
|  | 1142 | if (i < 0) { | 
|  | 1143 | kfree(acm->country_codes); | 
|  | 1144 | goto skip_countries; | 
|  | 1145 | } | 
|  | 1146 | } | 
|  | 1147 |  | 
|  | 1148 | skip_countries: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), | 
|  | 1150 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval); | 
|  | 1151 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 
|  | 1152 | acm->ctrlurb->transfer_dma = acm->ctrl_dma; | 
|  | 1153 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); | 
|  | 1155 |  | 
|  | 1156 | acm_set_control(acm, acm->ctrlout); | 
|  | 1157 |  | 
|  | 1158 | acm->line.dwDTERate = cpu_to_le32(9600); | 
|  | 1159 | acm->line.bDataBits = 8; | 
|  | 1160 | acm_set_line(acm, &acm->line); | 
|  | 1161 |  | 
|  | 1162 | usb_driver_claim_interface(&acm_driver, data_interface, acm); | 
|  | 1163 |  | 
| brian@murphy.dk | 83ef344 | 2005-06-29 16:53:29 -0700 | [diff] [blame] | 1164 | usb_get_intf(control_interface); | 
|  | 1165 | tty_register_device(acm_tty_driver, minor, &control_interface->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 |  | 
|  | 1167 | acm_table[minor] = acm; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 |  | 
| Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1169 | return 0; | 
|  | 1170 | alloc_fail8: | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 1171 | for (i = 0; i < ACM_NW; i++) | 
|  | 1172 | usb_free_urb(acm->wb[i].urb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | alloc_fail7: | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1174 | for (i = 0; i < num_rx_buf; i++) | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1175 | usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma); | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1176 | for (i = 0; i < num_rx_buf; i++) | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1177 | usb_free_urb(acm->ru[i].urb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | usb_free_urb(acm->ctrlurb); | 
|  | 1179 | alloc_fail5: | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1180 | acm_write_buffers_free(acm); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | alloc_fail4: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | usb_buffer_free(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); | 
|  | 1183 | alloc_fail2: | 
|  | 1184 | kfree(acm); | 
|  | 1185 | alloc_fail: | 
|  | 1186 | return -ENOMEM; | 
|  | 1187 | } | 
|  | 1188 |  | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1189 | static void stop_data_traffic(struct acm *acm) | 
|  | 1190 | { | 
|  | 1191 | int i; | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 1192 | dbg("Entering stop_data_traffic"); | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1193 |  | 
|  | 1194 | tasklet_disable(&acm->urb_task); | 
|  | 1195 |  | 
|  | 1196 | usb_kill_urb(acm->ctrlurb); | 
| David Engraf | e4cf3aa | 2008-03-20 10:01:34 +0100 | [diff] [blame] | 1197 | for(i = 0; i < ACM_NW; i++) | 
|  | 1198 | usb_kill_urb(acm->wb[i].urb); | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1199 | for (i = 0; i < acm->rx_buflimit; i++) | 
|  | 1200 | usb_kill_urb(acm->ru[i].urb); | 
|  | 1201 |  | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1202 | tasklet_enable(&acm->urb_task); | 
|  | 1203 |  | 
|  | 1204 | cancel_work_sync(&acm->work); | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 1205 | cancel_work_sync(&acm->waker); | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1206 | } | 
|  | 1207 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | static void acm_disconnect(struct usb_interface *intf) | 
|  | 1209 | { | 
| Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1210 | struct acm *acm = usb_get_intfdata(intf); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | struct usb_device *usb_dev = interface_to_usbdev(intf); | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1212 | int i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 |  | 
|  | 1214 | if (!acm || !acm->dev) { | 
|  | 1215 | dbg("disconnect on nonexisting interface"); | 
|  | 1216 | return; | 
|  | 1217 | } | 
|  | 1218 |  | 
| Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 1219 | mutex_lock(&open_mutex); | 
| Oliver Neukum | 86067eea | 2006-01-08 12:39:13 +0100 | [diff] [blame] | 1220 | if (!usb_get_intfdata(intf)) { | 
| Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 1221 | mutex_unlock(&open_mutex); | 
| Oliver Neukum | 86067eea | 2006-01-08 12:39:13 +0100 | [diff] [blame] | 1222 | return; | 
|  | 1223 | } | 
| Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1224 | if (acm->country_codes){ | 
| Alan Stern | 74da5d6 | 2007-08-02 13:29:10 -0400 | [diff] [blame] | 1225 | device_remove_file(&acm->control->dev, | 
|  | 1226 | &dev_attr_wCountryCodes); | 
|  | 1227 | device_remove_file(&acm->control->dev, | 
|  | 1228 | &dev_attr_iCountryCodeRelDate); | 
| Oliver Neukum | c4cabd2 | 2007-02-27 15:28:55 +0100 | [diff] [blame] | 1229 | } | 
| Alan Stern | 74da5d6 | 2007-08-02 13:29:10 -0400 | [diff] [blame] | 1230 | device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | acm->dev = NULL; | 
| Oliver Neukum | 86067eea | 2006-01-08 12:39:13 +0100 | [diff] [blame] | 1232 | usb_set_intfdata(acm->control, NULL); | 
|  | 1233 | usb_set_intfdata(acm->data, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 |  | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1235 | stop_data_traffic(acm); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 |  | 
| Oliver Neukum | 884b600 | 2005-04-21 21:28:02 +0200 | [diff] [blame] | 1237 | acm_write_buffers_free(acm); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1239 | for (i = 0; i < acm->rx_buflimit; i++) | 
| David Kubicek | 61a87ad | 2005-11-01 18:51:34 +0100 | [diff] [blame] | 1240 | usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 |  | 
| Oliver Neukum | 86067eea | 2006-01-08 12:39:13 +0100 | [diff] [blame] | 1242 | usb_driver_release_interface(&acm_driver, intf == acm->control ? acm->data : intf); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 |  | 
|  | 1244 | if (!acm->used) { | 
| brian@murphy.dk | 83ef344 | 2005-06-29 16:53:29 -0700 | [diff] [blame] | 1245 | acm_tty_unregister(acm); | 
| Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 1246 | mutex_unlock(&open_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | return; | 
|  | 1248 | } | 
|  | 1249 |  | 
| Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 1250 | mutex_unlock(&open_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 |  | 
|  | 1252 | if (acm->tty) | 
|  | 1253 | tty_hangup(acm->tty); | 
|  | 1254 | } | 
|  | 1255 |  | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1256 | static int acm_suspend(struct usb_interface *intf, pm_message_t message) | 
|  | 1257 | { | 
|  | 1258 | struct acm *acm = usb_get_intfdata(intf); | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 1259 | int cnt; | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1260 |  | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 1261 | if (acm->dev->auto_pm) { | 
|  | 1262 | int b; | 
|  | 1263 |  | 
|  | 1264 | spin_lock_irq(&acm->read_lock); | 
|  | 1265 | spin_lock(&acm->write_lock); | 
|  | 1266 | b = acm->processing + acm->transmitting; | 
|  | 1267 | spin_unlock(&acm->write_lock); | 
|  | 1268 | spin_unlock_irq(&acm->read_lock); | 
|  | 1269 | if (b) | 
|  | 1270 | return -EBUSY; | 
|  | 1271 | } | 
|  | 1272 |  | 
|  | 1273 | spin_lock_irq(&acm->read_lock); | 
|  | 1274 | spin_lock(&acm->write_lock); | 
|  | 1275 | cnt = acm->susp_count++; | 
|  | 1276 | spin_unlock(&acm->write_lock); | 
|  | 1277 | spin_unlock_irq(&acm->read_lock); | 
|  | 1278 |  | 
|  | 1279 | if (cnt) | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1280 | return 0; | 
|  | 1281 | /* | 
|  | 1282 | we treat opened interfaces differently, | 
|  | 1283 | we must guard against open | 
|  | 1284 | */ | 
|  | 1285 | mutex_lock(&acm->mutex); | 
|  | 1286 |  | 
|  | 1287 | if (acm->used) | 
|  | 1288 | stop_data_traffic(acm); | 
|  | 1289 |  | 
|  | 1290 | mutex_unlock(&acm->mutex); | 
|  | 1291 | return 0; | 
|  | 1292 | } | 
|  | 1293 |  | 
|  | 1294 | static int acm_resume(struct usb_interface *intf) | 
|  | 1295 | { | 
|  | 1296 | struct acm *acm = usb_get_intfdata(intf); | 
|  | 1297 | int rv = 0; | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 1298 | int cnt; | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1299 |  | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 1300 | spin_lock_irq(&acm->read_lock); | 
|  | 1301 | acm->susp_count -= 1; | 
|  | 1302 | cnt = acm->susp_count; | 
|  | 1303 | spin_unlock_irq(&acm->read_lock); | 
|  | 1304 |  | 
|  | 1305 | if (cnt) | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1306 | return 0; | 
|  | 1307 |  | 
|  | 1308 | mutex_lock(&acm->mutex); | 
|  | 1309 | if (acm->used) { | 
|  | 1310 | rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); | 
|  | 1311 | if (rv < 0) | 
| Oliver Neukum | 11ea859 | 2008-06-20 11:25:57 +0200 | [diff] [blame^] | 1312 | goto err_out; | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1313 |  | 
|  | 1314 | tasklet_schedule(&acm->urb_task); | 
|  | 1315 | } | 
|  | 1316 |  | 
|  | 1317 | err_out: | 
|  | 1318 | mutex_unlock(&acm->mutex); | 
|  | 1319 | return rv; | 
|  | 1320 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | /* | 
|  | 1322 | * USB driver structure. | 
|  | 1323 | */ | 
|  | 1324 |  | 
|  | 1325 | static struct usb_device_id acm_ids[] = { | 
|  | 1326 | /* quirky and broken devices */ | 
|  | 1327 | { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */ | 
|  | 1328 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | 
|  | 1329 | }, | 
| Andrey Arapov | b0e2a70 | 2007-07-04 17:11:42 +0200 | [diff] [blame] | 1330 | { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */ | 
|  | 1331 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | 
|  | 1332 | }, | 
| Masahito Omote | 8753e65 | 2005-07-29 12:17:25 -0700 | [diff] [blame] | 1333 | { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */ | 
|  | 1334 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | 
|  | 1335 | }, | 
| Chris Malley | 91a9c92 | 2006-10-03 10:08:28 +0100 | [diff] [blame] | 1336 | { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */ | 
|  | 1337 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | 
|  | 1338 | }, | 
| Oliver Neukum | 8647894 | 2006-05-13 22:50:47 +0200 | [diff] [blame] | 1339 | { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */ | 
|  | 1340 | .driver_info = SINGLE_RX_URB, /* firmware bug */ | 
|  | 1341 | }, | 
| Oliver Neukum | 3dd2ae8 | 2006-06-23 09:14:17 +0200 | [diff] [blame] | 1342 | { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */ | 
|  | 1343 | .driver_info = SINGLE_RX_URB, /* firmware bug */ | 
|  | 1344 | }, | 
| Oliver Neukum | 9be8456 | 2007-02-12 08:50:03 +0100 | [diff] [blame] | 1345 | { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */ | 
|  | 1346 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | 
|  | 1347 | }, | 
| Iain McFarlane | 6149ed5 | 2008-05-04 00:13:49 +0100 | [diff] [blame] | 1348 | { USB_DEVICE(0x0803, 0x3095), /* Zoom Telephonics Model 3095F USB MODEM */ | 
|  | 1349 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | 
|  | 1350 | }, | 
| Oliver Neukum | 9be8456 | 2007-02-12 08:50:03 +0100 | [diff] [blame] | 1351 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | /* control interfaces with various AT-command sets */ | 
|  | 1353 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 
|  | 1354 | USB_CDC_ACM_PROTO_AT_V25TER) }, | 
|  | 1355 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 
|  | 1356 | USB_CDC_ACM_PROTO_AT_PCCA101) }, | 
|  | 1357 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 
|  | 1358 | USB_CDC_ACM_PROTO_AT_PCCA101_WAKE) }, | 
|  | 1359 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 
|  | 1360 | USB_CDC_ACM_PROTO_AT_GSM) }, | 
|  | 1361 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 
|  | 1362 | USB_CDC_ACM_PROTO_AT_3G	) }, | 
|  | 1363 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 
|  | 1364 | USB_CDC_ACM_PROTO_AT_CDMA) }, | 
|  | 1365 |  | 
|  | 1366 | /* NOTE:  COMM/ACM/0xff is likely MSFT RNDIS ... NOT a modem!! */ | 
|  | 1367 | { } | 
|  | 1368 | }; | 
|  | 1369 |  | 
|  | 1370 | MODULE_DEVICE_TABLE (usb, acm_ids); | 
|  | 1371 |  | 
|  | 1372 | static struct usb_driver acm_driver = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | .name =		"cdc_acm", | 
|  | 1374 | .probe =	acm_probe, | 
|  | 1375 | .disconnect =	acm_disconnect, | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1376 | .suspend =	acm_suspend, | 
|  | 1377 | .resume =	acm_resume, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | .id_table =	acm_ids, | 
| Oliver Neukum | 1365baf7 | 2007-10-12 17:24:28 +0200 | [diff] [blame] | 1379 | .supports_autosuspend = 1, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | }; | 
|  | 1381 |  | 
|  | 1382 | /* | 
|  | 1383 | * TTY driver structures. | 
|  | 1384 | */ | 
|  | 1385 |  | 
| Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 1386 | static const struct tty_operations acm_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | .open =			acm_tty_open, | 
|  | 1388 | .close =		acm_tty_close, | 
|  | 1389 | .write =		acm_tty_write, | 
|  | 1390 | .write_room =		acm_tty_write_room, | 
|  | 1391 | .ioctl =		acm_tty_ioctl, | 
|  | 1392 | .throttle =		acm_tty_throttle, | 
|  | 1393 | .unthrottle =		acm_tty_unthrottle, | 
|  | 1394 | .chars_in_buffer =	acm_tty_chars_in_buffer, | 
|  | 1395 | .break_ctl =		acm_tty_break_ctl, | 
|  | 1396 | .set_termios =		acm_tty_set_termios, | 
|  | 1397 | .tiocmget =		acm_tty_tiocmget, | 
|  | 1398 | .tiocmset =		acm_tty_tiocmset, | 
|  | 1399 | }; | 
|  | 1400 |  | 
|  | 1401 | /* | 
|  | 1402 | * Init / exit. | 
|  | 1403 | */ | 
|  | 1404 |  | 
|  | 1405 | static int __init acm_init(void) | 
|  | 1406 | { | 
|  | 1407 | int retval; | 
|  | 1408 | acm_tty_driver = alloc_tty_driver(ACM_TTY_MINORS); | 
|  | 1409 | if (!acm_tty_driver) | 
|  | 1410 | return -ENOMEM; | 
|  | 1411 | acm_tty_driver->owner = THIS_MODULE, | 
|  | 1412 | acm_tty_driver->driver_name = "acm", | 
|  | 1413 | acm_tty_driver->name = "ttyACM", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | acm_tty_driver->major = ACM_TTY_MAJOR, | 
|  | 1415 | acm_tty_driver->minor_start = 0, | 
|  | 1416 | acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL, | 
|  | 1417 | acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, | 
| Greg Kroah-Hartman | 331b831 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 1418 | acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | acm_tty_driver->init_termios = tty_std_termios; | 
|  | 1420 | acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | 
|  | 1421 | tty_set_operations(acm_tty_driver, &acm_ops); | 
|  | 1422 |  | 
|  | 1423 | retval = tty_register_driver(acm_tty_driver); | 
|  | 1424 | if (retval) { | 
|  | 1425 | put_tty_driver(acm_tty_driver); | 
|  | 1426 | return retval; | 
|  | 1427 | } | 
|  | 1428 |  | 
|  | 1429 | retval = usb_register(&acm_driver); | 
|  | 1430 | if (retval) { | 
|  | 1431 | tty_unregister_driver(acm_tty_driver); | 
|  | 1432 | put_tty_driver(acm_tty_driver); | 
|  | 1433 | return retval; | 
|  | 1434 | } | 
|  | 1435 |  | 
|  | 1436 | info(DRIVER_VERSION ":" DRIVER_DESC); | 
|  | 1437 |  | 
|  | 1438 | return 0; | 
|  | 1439 | } | 
|  | 1440 |  | 
|  | 1441 | static void __exit acm_exit(void) | 
|  | 1442 | { | 
|  | 1443 | usb_deregister(&acm_driver); | 
|  | 1444 | tty_unregister_driver(acm_tty_driver); | 
|  | 1445 | put_tty_driver(acm_tty_driver); | 
|  | 1446 | } | 
|  | 1447 |  | 
|  | 1448 | module_init(acm_init); | 
|  | 1449 | module_exit(acm_exit); | 
|  | 1450 |  | 
|  | 1451 | MODULE_AUTHOR( DRIVER_AUTHOR ); | 
|  | 1452 | MODULE_DESCRIPTION( DRIVER_DESC ); | 
|  | 1453 | MODULE_LICENSE("GPL"); | 
|  | 1454 |  |