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