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