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