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