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