cdc-acm.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  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>
  9. * Copyright (c) 2005 David Kubicek <dave@awk.cz>
  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
  33. * v0.25 - downstream tasks paralelized to maximize throughput
  34. */
  35. /*
  36. * This program is free software; you can redistribute it and/or modify
  37. * it under the terms of the GNU General Public License as published by
  38. * the Free Software Foundation; either version 2 of the License, or
  39. * (at your option) any later version.
  40. *
  41. * This program is distributed in the hope that it will be useful,
  42. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  44. * GNU General Public License for more details.
  45. *
  46. * You should have received a copy of the GNU General Public License
  47. * along with this program; if not, write to the Free Software
  48. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  49. */
  50. #undef DEBUG
  51. #include <linux/kernel.h>
  52. #include <linux/errno.h>
  53. #include <linux/init.h>
  54. #include <linux/slab.h>
  55. #include <linux/tty.h>
  56. #include <linux/tty_driver.h>
  57. #include <linux/tty_flip.h>
  58. #include <linux/module.h>
  59. #include <linux/mutex.h>
  60. #include <asm/uaccess.h>
  61. #include <linux/usb.h>
  62. #include <linux/usb/cdc.h>
  63. #include <asm/byteorder.h>
  64. #include <asm/unaligned.h>
  65. #include <linux/list.h>
  66. #include "cdc-acm.h"
  67. /*
  68. * Version Information
  69. */
  70. #define DRIVER_VERSION "v0.25"
  71. #define DRIVER_AUTHOR "Armin Fuerst, Pavel Machek, Johannes Erdfelt, Vojtech Pavlik, David Kubicek"
  72. #define DRIVER_DESC "USB Abstract Control Model driver for USB modems and ISDN adapters"
  73. static struct usb_driver acm_driver;
  74. static struct tty_driver *acm_tty_driver;
  75. static struct acm *acm_table[ACM_TTY_MINORS];
  76. static DEFINE_MUTEX(open_mutex);
  77. #define ACM_READY(acm) (acm && acm->dev && acm->used)
  78. /*
  79. * Functions for ACM control messages.
  80. */
  81. static int acm_ctrl_msg(struct acm *acm, int request, int value, void *buf, int len)
  82. {
  83. int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0),
  84. request, USB_RT_ACM, value,
  85. acm->control->altsetting[0].desc.bInterfaceNumber,
  86. buf, len, 5000);
  87. dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", request, value, len, retval);
  88. return retval < 0 ? retval : 0;
  89. }
  90. /* devices aren't required to support these requests.
  91. * the cdc acm descriptor tells whether they do...
  92. */
  93. #define acm_set_control(acm, control) \
  94. acm_ctrl_msg(acm, USB_CDC_REQ_SET_CONTROL_LINE_STATE, control, NULL, 0)
  95. #define acm_set_line(acm, line) \
  96. acm_ctrl_msg(acm, USB_CDC_REQ_SET_LINE_CODING, 0, line, sizeof *(line))
  97. #define acm_send_break(acm, ms) \
  98. acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0)
  99. /*
  100. * Write buffer management.
  101. * All of these assume proper locks taken by the caller.
  102. */
  103. static int acm_wb_alloc(struct acm *acm)
  104. {
  105. int i, wbn;
  106. struct acm_wb *wb;
  107. wbn = acm->write_current;
  108. i = 0;
  109. for (;;) {
  110. wb = &acm->wb[wbn];
  111. if (!wb->use) {
  112. wb->use = 1;
  113. return wbn;
  114. }
  115. wbn = (wbn + 1) % ACM_NW;
  116. if (++i >= ACM_NW)
  117. return -1;
  118. }
  119. }
  120. static void acm_wb_free(struct acm *acm, int wbn)
  121. {
  122. acm->wb[wbn].use = 0;
  123. }
  124. static int acm_wb_is_avail(struct acm *acm)
  125. {
  126. int i, n;
  127. n = ACM_NW;
  128. for (i = 0; i < ACM_NW; i++) {
  129. n -= acm->wb[i].use;
  130. }
  131. return n;
  132. }
  133. static inline int acm_wb_is_used(struct acm *acm, int wbn)
  134. {
  135. return acm->wb[wbn].use;
  136. }
  137. /*
  138. * Finish write.
  139. */
  140. static void acm_write_done(struct acm *acm)
  141. {
  142. unsigned long flags;
  143. int wbn;
  144. spin_lock_irqsave(&acm->write_lock, flags);
  145. acm->write_ready = 1;
  146. wbn = acm->write_current;
  147. acm_wb_free(acm, wbn);
  148. acm->write_current = (wbn + 1) % ACM_NW;
  149. spin_unlock_irqrestore(&acm->write_lock, flags);
  150. }
  151. /*
  152. * Poke write.
  153. */
  154. static int acm_write_start(struct acm *acm)
  155. {
  156. unsigned long flags;
  157. int wbn;
  158. struct acm_wb *wb;
  159. int rc;
  160. spin_lock_irqsave(&acm->write_lock, flags);
  161. if (!acm->dev) {
  162. spin_unlock_irqrestore(&acm->write_lock, flags);
  163. return -ENODEV;
  164. }
  165. if (!acm->write_ready) {
  166. spin_unlock_irqrestore(&acm->write_lock, flags);
  167. return 0; /* A white lie */
  168. }
  169. wbn = acm->write_current;
  170. if (!acm_wb_is_used(acm, wbn)) {
  171. spin_unlock_irqrestore(&acm->write_lock, flags);
  172. return 0;
  173. }
  174. wb = &acm->wb[wbn];
  175. acm->write_ready = 0;
  176. spin_unlock_irqrestore(&acm->write_lock, flags);
  177. acm->writeurb->transfer_buffer = wb->buf;
  178. acm->writeurb->transfer_dma = wb->dmah;
  179. acm->writeurb->transfer_buffer_length = wb->len;
  180. acm->writeurb->dev = acm->dev;
  181. if ((rc = usb_submit_urb(acm->writeurb, GFP_ATOMIC)) < 0) {
  182. dbg("usb_submit_urb(write bulk) failed: %d", rc);
  183. acm_write_done(acm);
  184. }
  185. return rc;
  186. }
  187. /*
  188. * attributes exported through sysfs
  189. */
  190. static ssize_t show_caps
  191. (struct device *dev, struct device_attribute *attr, char *buf)
  192. {
  193. struct usb_interface *intf = to_usb_interface(dev);
  194. struct acm *acm = usb_get_intfdata(intf);
  195. return sprintf(buf, "%d", acm->ctrl_caps);
  196. }
  197. static DEVICE_ATTR(bmCapabilities, S_IRUGO, show_caps, NULL);
  198. static ssize_t show_country_codes
  199. (struct device *dev, struct device_attribute *attr, char *buf)
  200. {
  201. struct usb_interface *intf = to_usb_interface(dev);
  202. struct acm *acm = usb_get_intfdata(intf);
  203. memcpy(buf, acm->country_codes, acm->country_code_size);
  204. return acm->country_code_size;
  205. }
  206. static DEVICE_ATTR(wCountryCodes, S_IRUGO, show_country_codes, NULL);
  207. static ssize_t show_country_rel_date
  208. (struct device *dev, struct device_attribute *attr, char *buf)
  209. {
  210. struct usb_interface *intf = to_usb_interface(dev);
  211. struct acm *acm = usb_get_intfdata(intf);
  212. return sprintf(buf, "%d", acm->country_rel_date);
  213. }
  214. static DEVICE_ATTR(iCountryCodeRelDate, S_IRUGO, show_country_rel_date, NULL);
  215. /*
  216. * Interrupt handlers for various ACM device responses
  217. */
  218. /* control interface reports status changes with "interrupt" transfers */
  219. static void acm_ctrl_irq(struct urb *urb)
  220. {
  221. struct acm *acm = urb->context;
  222. struct usb_cdc_notification *dr = urb->transfer_buffer;
  223. unsigned char *data;
  224. int newctrl;
  225. int status;
  226. switch (urb->status) {
  227. case 0:
  228. /* success */
  229. break;
  230. case -ECONNRESET:
  231. case -ENOENT:
  232. case -ESHUTDOWN:
  233. /* this urb is terminated, clean up */
  234. dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
  235. return;
  236. default:
  237. dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
  238. goto exit;
  239. }
  240. if (!ACM_READY(acm))
  241. goto exit;
  242. data = (unsigned char *)(dr + 1);
  243. switch (dr->bNotificationType) {
  244. case USB_CDC_NOTIFY_NETWORK_CONNECTION:
  245. dbg("%s network", dr->wValue ? "connected to" : "disconnected from");
  246. break;
  247. case USB_CDC_NOTIFY_SERIAL_STATE:
  248. newctrl = le16_to_cpu(get_unaligned((__le16 *) data));
  249. if (acm->tty && !acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) {
  250. dbg("calling hangup");
  251. tty_hangup(acm->tty);
  252. }
  253. acm->ctrlin = newctrl;
  254. dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c",
  255. acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', acm->ctrlin & ACM_CTRL_DSR ? '+' : '-',
  256. acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', acm->ctrlin & ACM_CTRL_RI ? '+' : '-',
  257. acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-', acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-',
  258. acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-');
  259. break;
  260. default:
  261. dbg("unknown notification %d received: index %d len %d data0 %d data1 %d",
  262. dr->bNotificationType, dr->wIndex,
  263. dr->wLength, data[0], data[1]);
  264. break;
  265. }
  266. exit:
  267. status = usb_submit_urb (urb, GFP_ATOMIC);
  268. if (status)
  269. err ("%s - usb_submit_urb failed with result %d",
  270. __FUNCTION__, status);
  271. }
  272. /* data interface returns incoming bytes, or we got unthrottled */
  273. static void acm_read_bulk(struct urb *urb)
  274. {
  275. struct acm_rb *buf;
  276. struct acm_ru *rcv = urb->context;
  277. struct acm *acm = rcv->instance;
  278. int status = urb->status;
  279. dbg("Entering acm_read_bulk with status %d", urb->status);
  280. if (!ACM_READY(acm))
  281. return;
  282. if (status)
  283. dev_dbg(&acm->data->dev, "bulk rx status %d", status);
  284. buf = rcv->buffer;
  285. buf->size = urb->actual_length;
  286. if (likely(status == 0)) {
  287. spin_lock(&acm->read_lock);
  288. list_add_tail(&rcv->list, &acm->spare_read_urbs);
  289. list_add_tail(&buf->list, &acm->filled_read_bufs);
  290. spin_unlock(&acm->read_lock);
  291. } else {
  292. /* we drop the buffer due to an error */
  293. spin_lock(&acm->read_lock);
  294. list_add_tail(&rcv->list, &acm->spare_read_urbs);
  295. list_add(&buf->list, &acm->spare_read_bufs);
  296. spin_unlock(&acm->read_lock);
  297. /* nevertheless the tasklet must be kicked unconditionally
  298. so the queue cannot dry up */
  299. }
  300. tasklet_schedule(&acm->urb_task);
  301. }
  302. static void acm_rx_tasklet(unsigned long _acm)
  303. {
  304. struct acm *acm = (void *)_acm;
  305. struct acm_rb *buf;
  306. struct tty_struct *tty = acm->tty;
  307. struct acm_ru *rcv;
  308. unsigned long flags;
  309. unsigned char throttled;
  310. dbg("Entering acm_rx_tasklet");
  311. if (!ACM_READY(acm))
  312. return;
  313. spin_lock_irqsave(&acm->throttle_lock, flags);
  314. throttled = acm->throttle;
  315. spin_unlock_irqrestore(&acm->throttle_lock, flags);
  316. if (throttled)
  317. return;
  318. next_buffer:
  319. spin_lock_irqsave(&acm->read_lock, flags);
  320. if (list_empty(&acm->filled_read_bufs)) {
  321. spin_unlock_irqrestore(&acm->read_lock, flags);
  322. goto urbs;
  323. }
  324. buf = list_entry(acm->filled_read_bufs.next,
  325. struct acm_rb, list);
  326. list_del(&buf->list);
  327. spin_unlock_irqrestore(&acm->read_lock, flags);
  328. dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size);
  329. tty_buffer_request_room(tty, buf->size);
  330. spin_lock_irqsave(&acm->throttle_lock, flags);
  331. throttled = acm->throttle;
  332. spin_unlock_irqrestore(&acm->throttle_lock, flags);
  333. if (!throttled)
  334. tty_insert_flip_string(tty, buf->base, buf->size);
  335. tty_flip_buffer_push(tty);
  336. if (throttled) {
  337. dbg("Throttling noticed");
  338. spin_lock_irqsave(&acm->read_lock, flags);
  339. list_add(&buf->list, &acm->filled_read_bufs);
  340. spin_unlock_irqrestore(&acm->read_lock, flags);
  341. return;
  342. }
  343. spin_lock_irqsave(&acm->read_lock, flags);
  344. list_add(&buf->list, &acm->spare_read_bufs);
  345. spin_unlock_irqrestore(&acm->read_lock, flags);
  346. goto next_buffer;
  347. urbs:
  348. while (!list_empty(&acm->spare_read_bufs)) {
  349. spin_lock_irqsave(&acm->read_lock, flags);
  350. if (list_empty(&acm->spare_read_urbs)) {
  351. spin_unlock_irqrestore(&acm->read_lock, flags);
  352. return;
  353. }
  354. rcv = list_entry(acm->spare_read_urbs.next,
  355. struct acm_ru, list);
  356. list_del(&rcv->list);
  357. spin_unlock_irqrestore(&acm->read_lock, flags);
  358. buf = list_entry(acm->spare_read_bufs.next,
  359. struct acm_rb, list);
  360. list_del(&buf->list);
  361. rcv->buffer = buf;
  362. usb_fill_bulk_urb(rcv->urb, acm->dev,
  363. acm->rx_endpoint,
  364. buf->base,
  365. acm->readsize,
  366. acm_read_bulk, rcv);
  367. rcv->urb->transfer_dma = buf->dma;
  368. rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  369. dbg("acm_rx_tasklet: sending urb 0x%p, rcv 0x%p, buf 0x%p", rcv->urb, rcv, buf);
  370. /* This shouldn't kill the driver as unsuccessful URBs are returned to the
  371. free-urbs-pool and resubmited ASAP */
  372. if (usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) {
  373. list_add(&buf->list, &acm->spare_read_bufs);
  374. spin_lock_irqsave(&acm->read_lock, flags);
  375. list_add(&rcv->list, &acm->spare_read_urbs);
  376. spin_unlock_irqrestore(&acm->read_lock, flags);
  377. return;
  378. }
  379. }
  380. }
  381. /* data interface wrote those outgoing bytes */
  382. static void acm_write_bulk(struct urb *urb)
  383. {
  384. struct acm *acm = (struct acm *)urb->context;
  385. dbg("Entering acm_write_bulk with status %d", urb->status);
  386. acm_write_done(acm);
  387. acm_write_start(acm);
  388. if (ACM_READY(acm))
  389. schedule_work(&acm->work);
  390. }
  391. static void acm_softint(struct work_struct *work)
  392. {
  393. struct acm *acm = container_of(work, struct acm, work);
  394. dbg("Entering acm_softint.");
  395. if (!ACM_READY(acm))
  396. return;
  397. tty_wakeup(acm->tty);
  398. }
  399. /*
  400. * TTY handlers
  401. */
  402. static int acm_tty_open(struct tty_struct *tty, struct file *filp)
  403. {
  404. struct acm *acm;
  405. int rv = -EINVAL;
  406. int i;
  407. dbg("Entering acm_tty_open.");
  408. mutex_lock(&open_mutex);
  409. acm = acm_table[tty->index];
  410. if (!acm || !acm->dev)
  411. goto err_out;
  412. else
  413. rv = 0;
  414. tty->driver_data = acm;
  415. acm->tty = tty;
  416. /* force low_latency on so that our tty_push actually forces the data through,
  417. otherwise it is scheduled, and with high data rates data can get lost. */
  418. tty->low_latency = 1;
  419. if (acm->used++) {
  420. goto done;
  421. }
  422. acm->ctrlurb->dev = acm->dev;
  423. if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) {
  424. dbg("usb_submit_urb(ctrl irq) failed");
  425. goto bail_out;
  426. }
  427. if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) &&
  428. (acm->ctrl_caps & USB_CDC_CAP_LINE))
  429. goto full_bailout;
  430. INIT_LIST_HEAD(&acm->spare_read_urbs);
  431. INIT_LIST_HEAD(&acm->spare_read_bufs);
  432. INIT_LIST_HEAD(&acm->filled_read_bufs);
  433. for (i = 0; i < acm->rx_buflimit; i++) {
  434. list_add(&(acm->ru[i].list), &acm->spare_read_urbs);
  435. }
  436. for (i = 0; i < acm->rx_buflimit; i++) {
  437. list_add(&(acm->rb[i].list), &acm->spare_read_bufs);
  438. }
  439. acm->throttle = 0;
  440. tasklet_schedule(&acm->urb_task);
  441. done:
  442. err_out:
  443. mutex_unlock(&open_mutex);
  444. return rv;
  445. full_bailout:
  446. usb_kill_urb(acm->ctrlurb);
  447. bail_out:
  448. acm->used--;
  449. mutex_unlock(&open_mutex);
  450. return -EIO;
  451. }
  452. static void acm_tty_unregister(struct acm *acm)
  453. {
  454. int i,nr;
  455. nr = acm->rx_buflimit;
  456. tty_unregister_device(acm_tty_driver, acm->minor);
  457. usb_put_intf(acm->control);
  458. acm_table[acm->minor] = NULL;
  459. usb_free_urb(acm->ctrlurb);
  460. usb_free_urb(acm->writeurb);
  461. for (i = 0; i < nr; i++)
  462. usb_free_urb(acm->ru[i].urb);
  463. kfree(acm->country_codes);
  464. kfree(acm);
  465. }
  466. static void acm_tty_close(struct tty_struct *tty, struct file *filp)
  467. {
  468. struct acm *acm = tty->driver_data;
  469. int i,nr;
  470. if (!acm || !acm->used)
  471. return;
  472. nr = acm->rx_buflimit;
  473. mutex_lock(&open_mutex);
  474. if (!--acm->used) {
  475. if (acm->dev) {
  476. acm_set_control(acm, acm->ctrlout = 0);
  477. usb_kill_urb(acm->ctrlurb);
  478. usb_kill_urb(acm->writeurb);
  479. for (i = 0; i < nr; i++)
  480. usb_kill_urb(acm->ru[i].urb);
  481. } else
  482. acm_tty_unregister(acm);
  483. }
  484. mutex_unlock(&open_mutex);
  485. }
  486. static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
  487. {
  488. struct acm *acm = tty->driver_data;
  489. int stat;
  490. unsigned long flags;
  491. int wbn;
  492. struct acm_wb *wb;
  493. dbg("Entering acm_tty_write to write %d bytes,", count);
  494. if (!ACM_READY(acm))
  495. return -EINVAL;
  496. if (!count)
  497. return 0;
  498. spin_lock_irqsave(&acm->write_lock, flags);
  499. if ((wbn = acm_wb_alloc(acm)) < 0) {
  500. spin_unlock_irqrestore(&acm->write_lock, flags);
  501. acm_write_start(acm);
  502. return 0;
  503. }
  504. wb = &acm->wb[wbn];
  505. count = (count > acm->writesize) ? acm->writesize : count;
  506. dbg("Get %d bytes...", count);
  507. memcpy(wb->buf, buf, count);
  508. wb->len = count;
  509. spin_unlock_irqrestore(&acm->write_lock, flags);
  510. if ((stat = acm_write_start(acm)) < 0)
  511. return stat;
  512. return count;
  513. }
  514. static int acm_tty_write_room(struct tty_struct *tty)
  515. {
  516. struct acm *acm = tty->driver_data;
  517. if (!ACM_READY(acm))
  518. return -EINVAL;
  519. /*
  520. * Do not let the line discipline to know that we have a reserve,
  521. * or it might get too enthusiastic.
  522. */
  523. return (acm->write_ready && acm_wb_is_avail(acm)) ? acm->writesize : 0;
  524. }
  525. static int acm_tty_chars_in_buffer(struct tty_struct *tty)
  526. {
  527. struct acm *acm = tty->driver_data;
  528. if (!ACM_READY(acm))
  529. return -EINVAL;
  530. /*
  531. * This is inaccurate (overcounts), but it works.
  532. */
  533. return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize;
  534. }
  535. static void acm_tty_throttle(struct tty_struct *tty)
  536. {
  537. struct acm *acm = tty->driver_data;
  538. if (!ACM_READY(acm))
  539. return;
  540. spin_lock_bh(&acm->throttle_lock);
  541. acm->throttle = 1;
  542. spin_unlock_bh(&acm->throttle_lock);
  543. }
  544. static void acm_tty_unthrottle(struct tty_struct *tty)
  545. {
  546. struct acm *acm = tty->driver_data;
  547. if (!ACM_READY(acm))
  548. return;
  549. spin_lock_bh(&acm->throttle_lock);
  550. acm->throttle = 0;
  551. spin_unlock_bh(&acm->throttle_lock);
  552. tasklet_schedule(&acm->urb_task);
  553. }
  554. static void acm_tty_break_ctl(struct tty_struct *tty, int state)
  555. {
  556. struct acm *acm = tty->driver_data;
  557. if (!ACM_READY(acm))
  558. return;
  559. if (acm_send_break(acm, state ? 0xffff : 0))
  560. dbg("send break failed");
  561. }
  562. static int acm_tty_tiocmget(struct tty_struct *tty, struct file *file)
  563. {
  564. struct acm *acm = tty->driver_data;
  565. if (!ACM_READY(acm))
  566. return -EINVAL;
  567. return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) |
  568. (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) |
  569. (acm->ctrlin & ACM_CTRL_DSR ? TIOCM_DSR : 0) |
  570. (acm->ctrlin & ACM_CTRL_RI ? TIOCM_RI : 0) |
  571. (acm->ctrlin & ACM_CTRL_DCD ? TIOCM_CD : 0) |
  572. TIOCM_CTS;
  573. }
  574. static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file,
  575. unsigned int set, unsigned int clear)
  576. {
  577. struct acm *acm = tty->driver_data;
  578. unsigned int newctrl;
  579. if (!ACM_READY(acm))
  580. return -EINVAL;
  581. newctrl = acm->ctrlout;
  582. set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0);
  583. clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0);
  584. newctrl = (newctrl & ~clear) | set;
  585. if (acm->ctrlout == newctrl)
  586. return 0;
  587. return acm_set_control(acm, acm->ctrlout = newctrl);
  588. }
  589. static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  590. {
  591. struct acm *acm = tty->driver_data;
  592. if (!ACM_READY(acm))
  593. return -EINVAL;
  594. return -ENOIOCTLCMD;
  595. }
  596. static const __u32 acm_tty_speed[] = {
  597. 0, 50, 75, 110, 134, 150, 200, 300, 600,
  598. 1200, 1800, 2400, 4800, 9600, 19200, 38400,
  599. 57600, 115200, 230400, 460800, 500000, 576000,
  600. 921600, 1000000, 1152000, 1500000, 2000000,
  601. 2500000, 3000000, 3500000, 4000000
  602. };
  603. static const __u8 acm_tty_size[] = {
  604. 5, 6, 7, 8
  605. };
  606. static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old)
  607. {
  608. struct acm *acm = tty->driver_data;
  609. struct ktermios *termios = tty->termios;
  610. struct usb_cdc_line_coding newline;
  611. int newctrl = acm->ctrlout;
  612. if (!ACM_READY(acm))
  613. return;
  614. newline.dwDTERate = cpu_to_le32p(acm_tty_speed +
  615. (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0));
  616. newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0;
  617. newline.bParityType = termios->c_cflag & PARENB ?
  618. (termios->c_cflag & PARODD ? 1 : 2) + (termios->c_cflag & CMSPAR ? 2 : 0) : 0;
  619. newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4];
  620. acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
  621. if (!newline.dwDTERate) {
  622. newline.dwDTERate = acm->line.dwDTERate;
  623. newctrl &= ~ACM_CTRL_DTR;
  624. } else newctrl |= ACM_CTRL_DTR;
  625. if (newctrl != acm->ctrlout)
  626. acm_set_control(acm, acm->ctrlout = newctrl);
  627. if (memcmp(&acm->line, &newline, sizeof newline)) {
  628. memcpy(&acm->line, &newline, sizeof newline);
  629. dbg("set line: %d %d %d %d", le32_to_cpu(newline.dwDTERate),
  630. newline.bCharFormat, newline.bParityType,
  631. newline.bDataBits);
  632. acm_set_line(acm, &acm->line);
  633. }
  634. }
  635. /*
  636. * USB probe and disconnect routines.
  637. */
  638. /* Little helper: write buffers free */
  639. static void acm_write_buffers_free(struct acm *acm)
  640. {
  641. int i;
  642. struct acm_wb *wb;
  643. for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) {
  644. usb_buffer_free(acm->dev, acm->writesize, wb->buf, wb->dmah);
  645. }
  646. }
  647. /* Little helper: write buffers allocate */
  648. static int acm_write_buffers_alloc(struct acm *acm)
  649. {
  650. int i;
  651. struct acm_wb *wb;
  652. for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) {
  653. wb->buf = usb_buffer_alloc(acm->dev, acm->writesize, GFP_KERNEL,
  654. &wb->dmah);
  655. if (!wb->buf) {
  656. while (i != 0) {
  657. --i;
  658. --wb;
  659. usb_buffer_free(acm->dev, acm->writesize,
  660. wb->buf, wb->dmah);
  661. }
  662. return -ENOMEM;
  663. }
  664. }
  665. return 0;
  666. }
  667. static int acm_probe (struct usb_interface *intf,
  668. const struct usb_device_id *id)
  669. {
  670. struct usb_cdc_union_desc *union_header = NULL;
  671. struct usb_cdc_country_functional_desc *cfd = NULL;
  672. char *buffer = intf->altsetting->extra;
  673. int buflen = intf->altsetting->extralen;
  674. struct usb_interface *control_interface;
  675. struct usb_interface *data_interface;
  676. struct usb_endpoint_descriptor *epctrl;
  677. struct usb_endpoint_descriptor *epread;
  678. struct usb_endpoint_descriptor *epwrite;
  679. struct usb_device *usb_dev = interface_to_usbdev(intf);
  680. struct acm *acm;
  681. int minor;
  682. int ctrlsize,readsize;
  683. u8 *buf;
  684. u8 ac_management_function = 0;
  685. u8 call_management_function = 0;
  686. int call_interface_num = -1;
  687. int data_interface_num;
  688. unsigned long quirks;
  689. int num_rx_buf;
  690. int i;
  691. /* normal quirks */
  692. quirks = (unsigned long)id->driver_info;
  693. num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR;
  694. /* handle quirks deadly to normal probing*/
  695. if (quirks == NO_UNION_NORMAL) {
  696. data_interface = usb_ifnum_to_if(usb_dev, 1);
  697. control_interface = usb_ifnum_to_if(usb_dev, 0);
  698. goto skip_normal_probe;
  699. }
  700. /* normal probing*/
  701. if (!buffer) {
  702. err("Wierd descriptor references\n");
  703. return -EINVAL;
  704. }
  705. if (!buflen) {
  706. if (intf->cur_altsetting->endpoint->extralen && intf->cur_altsetting->endpoint->extra) {
  707. dev_dbg(&intf->dev,"Seeking extra descriptors on endpoint");
  708. buflen = intf->cur_altsetting->endpoint->extralen;
  709. buffer = intf->cur_altsetting->endpoint->extra;
  710. } else {
  711. err("Zero length descriptor references\n");
  712. return -EINVAL;
  713. }
  714. }
  715. while (buflen > 0) {
  716. if (buffer [1] != USB_DT_CS_INTERFACE) {
  717. err("skipping garbage\n");
  718. goto next_desc;
  719. }
  720. switch (buffer [2]) {
  721. case USB_CDC_UNION_TYPE: /* we've found it */
  722. if (union_header) {
  723. err("More than one union descriptor, skipping ...");
  724. goto next_desc;
  725. }
  726. union_header = (struct usb_cdc_union_desc *)
  727. buffer;
  728. break;
  729. case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/
  730. cfd = (struct usb_cdc_country_functional_desc *)buffer;
  731. break;
  732. case USB_CDC_HEADER_TYPE: /* maybe check version */
  733. break; /* for now we ignore it */
  734. case USB_CDC_ACM_TYPE:
  735. ac_management_function = buffer[3];
  736. break;
  737. case USB_CDC_CALL_MANAGEMENT_TYPE:
  738. call_management_function = buffer[3];
  739. call_interface_num = buffer[4];
  740. if ((call_management_function & 3) != 3)
  741. err("This device cannot do calls on its own. It is no modem.");
  742. break;
  743. default:
  744. err("Ignoring extra header, type %d, length %d", buffer[2], buffer[0]);
  745. break;
  746. }
  747. next_desc:
  748. buflen -= buffer[0];
  749. buffer += buffer[0];
  750. }
  751. if (!union_header) {
  752. if (call_interface_num > 0) {
  753. dev_dbg(&intf->dev,"No union descriptor, using call management descriptor");
  754. data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num));
  755. control_interface = intf;
  756. } else {
  757. dev_dbg(&intf->dev,"No union descriptor, giving up");
  758. return -ENODEV;
  759. }
  760. } else {
  761. control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0);
  762. data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0));
  763. if (!control_interface || !data_interface) {
  764. dev_dbg(&intf->dev,"no interfaces");
  765. return -ENODEV;
  766. }
  767. }
  768. if (data_interface_num != call_interface_num)
  769. dev_dbg(&intf->dev,"Seperate call control interface. That is not fully supported.");
  770. skip_normal_probe:
  771. /*workaround for switched interfaces */
  772. if (data_interface->cur_altsetting->desc.bInterfaceClass != CDC_DATA_INTERFACE_TYPE) {
  773. if (control_interface->cur_altsetting->desc.bInterfaceClass == CDC_DATA_INTERFACE_TYPE) {
  774. struct usb_interface *t;
  775. dev_dbg(&intf->dev,"Your device has switched interfaces.");
  776. t = control_interface;
  777. control_interface = data_interface;
  778. data_interface = t;
  779. } else {
  780. return -EINVAL;
  781. }
  782. }
  783. if (usb_interface_claimed(data_interface)) { /* valid in this context */
  784. dev_dbg(&intf->dev,"The data interface isn't available");
  785. return -EBUSY;
  786. }
  787. if (data_interface->cur_altsetting->desc.bNumEndpoints < 2)
  788. return -EINVAL;
  789. epctrl = &control_interface->cur_altsetting->endpoint[0].desc;
  790. epread = &data_interface->cur_altsetting->endpoint[0].desc;
  791. epwrite = &data_interface->cur_altsetting->endpoint[1].desc;
  792. /* workaround for switched endpoints */
  793. if (!usb_endpoint_dir_in(epread)) {
  794. /* descriptors are swapped */
  795. struct usb_endpoint_descriptor *t;
  796. dev_dbg(&intf->dev,"The data interface has switched endpoints");
  797. t = epread;
  798. epread = epwrite;
  799. epwrite = t;
  800. }
  801. dbg("interfaces are valid");
  802. for (minor = 0; minor < ACM_TTY_MINORS && acm_table[minor]; minor++);
  803. if (minor == ACM_TTY_MINORS) {
  804. err("no more free acm devices");
  805. return -ENODEV;
  806. }
  807. if (!(acm = kzalloc(sizeof(struct acm), GFP_KERNEL))) {
  808. dev_dbg(&intf->dev, "out of memory (acm kzalloc)");
  809. goto alloc_fail;
  810. }
  811. ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize);
  812. readsize = le16_to_cpu(epread->wMaxPacketSize)* ( quirks == SINGLE_RX_URB ? 1 : 2);
  813. acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize);
  814. acm->control = control_interface;
  815. acm->data = data_interface;
  816. acm->minor = minor;
  817. acm->dev = usb_dev;
  818. acm->ctrl_caps = ac_management_function;
  819. acm->ctrlsize = ctrlsize;
  820. acm->readsize = readsize;
  821. acm->rx_buflimit = num_rx_buf;
  822. acm->urb_task.func = acm_rx_tasklet;
  823. acm->urb_task.data = (unsigned long) acm;
  824. INIT_WORK(&acm->work, acm_softint);
  825. spin_lock_init(&acm->throttle_lock);
  826. spin_lock_init(&acm->write_lock);
  827. spin_lock_init(&acm->read_lock);
  828. acm->write_ready = 1;
  829. acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress);
  830. buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
  831. if (!buf) {
  832. dev_dbg(&intf->dev, "out of memory (ctrl buffer alloc)");
  833. goto alloc_fail2;
  834. }
  835. acm->ctrl_buffer = buf;
  836. if (acm_write_buffers_alloc(acm) < 0) {
  837. dev_dbg(&intf->dev, "out of memory (write buffer alloc)");
  838. goto alloc_fail4;
  839. }
  840. acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);
  841. if (!acm->ctrlurb) {
  842. dev_dbg(&intf->dev, "out of memory (ctrlurb kmalloc)");
  843. goto alloc_fail5;
  844. }
  845. for (i = 0; i < num_rx_buf; i++) {
  846. struct acm_ru *rcv = &(acm->ru[i]);
  847. if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) {
  848. dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)");
  849. goto alloc_fail7;
  850. }
  851. rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  852. rcv->instance = acm;
  853. }
  854. for (i = 0; i < num_rx_buf; i++) {
  855. struct acm_rb *buf = &(acm->rb[i]);
  856. if (!(buf->base = usb_buffer_alloc(acm->dev, readsize, GFP_KERNEL, &buf->dma))) {
  857. dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)");
  858. goto alloc_fail7;
  859. }
  860. }
  861. acm->writeurb = usb_alloc_urb(0, GFP_KERNEL);
  862. if (!acm->writeurb) {
  863. dev_dbg(&intf->dev, "out of memory (writeurb kmalloc)");
  864. goto alloc_fail7;
  865. }
  866. usb_set_intfdata (intf, acm);
  867. i = device_create_file(&intf->dev, &dev_attr_bmCapabilities);
  868. if (i < 0)
  869. goto alloc_fail8;
  870. if (cfd) { /* export the country data */
  871. acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL);
  872. if (!acm->country_codes)
  873. goto skip_countries;
  874. acm->country_code_size = cfd->bLength - 4;
  875. memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4);
  876. acm->country_rel_date = cfd->iCountryCodeRelDate;
  877. i = device_create_file(&intf->dev, &dev_attr_wCountryCodes);
  878. if (i < 0) {
  879. kfree(acm->country_codes);
  880. goto skip_countries;
  881. }
  882. i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate);
  883. if (i < 0) {
  884. kfree(acm->country_codes);
  885. goto skip_countries;
  886. }
  887. }
  888. skip_countries:
  889. usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress),
  890. acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval);
  891. acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  892. acm->ctrlurb->transfer_dma = acm->ctrl_dma;
  893. usb_fill_bulk_urb(acm->writeurb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
  894. NULL, acm->writesize, acm_write_bulk, acm);
  895. acm->writeurb->transfer_flags |= URB_NO_FSBR | URB_NO_TRANSFER_DMA_MAP;
  896. dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor);
  897. acm_set_control(acm, acm->ctrlout);
  898. acm->line.dwDTERate = cpu_to_le32(9600);
  899. acm->line.bDataBits = 8;
  900. acm_set_line(acm, &acm->line);
  901. usb_driver_claim_interface(&acm_driver, data_interface, acm);
  902. usb_get_intf(control_interface);
  903. tty_register_device(acm_tty_driver, minor, &control_interface->dev);
  904. acm_table[minor] = acm;
  905. return 0;
  906. alloc_fail8:
  907. usb_free_urb(acm->writeurb);
  908. alloc_fail7:
  909. for (i = 0; i < num_rx_buf; i++)
  910. usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma);
  911. for (i = 0; i < num_rx_buf; i++)
  912. usb_free_urb(acm->ru[i].urb);
  913. usb_free_urb(acm->ctrlurb);
  914. alloc_fail5:
  915. acm_write_buffers_free(acm);
  916. alloc_fail4:
  917. usb_buffer_free(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
  918. alloc_fail2:
  919. kfree(acm);
  920. alloc_fail:
  921. return -ENOMEM;
  922. }
  923. static void acm_disconnect(struct usb_interface *intf)
  924. {
  925. struct acm *acm = usb_get_intfdata(intf);
  926. struct usb_device *usb_dev = interface_to_usbdev(intf);
  927. int i;
  928. if (!acm || !acm->dev) {
  929. dbg("disconnect on nonexisting interface");
  930. return;
  931. }
  932. mutex_lock(&open_mutex);
  933. if (!usb_get_intfdata(intf)) {
  934. mutex_unlock(&open_mutex);
  935. return;
  936. }
  937. if (acm->country_codes){
  938. device_remove_file(&intf->dev, &dev_attr_wCountryCodes);
  939. device_remove_file(&intf->dev, &dev_attr_iCountryCodeRelDate);
  940. }
  941. device_remove_file(&intf->dev, &dev_attr_bmCapabilities);
  942. acm->dev = NULL;
  943. usb_set_intfdata(acm->control, NULL);
  944. usb_set_intfdata(acm->data, NULL);
  945. tasklet_disable(&acm->urb_task);
  946. usb_kill_urb(acm->ctrlurb);
  947. usb_kill_urb(acm->writeurb);
  948. for (i = 0; i < acm->rx_buflimit; i++)
  949. usb_kill_urb(acm->ru[i].urb);
  950. INIT_LIST_HEAD(&acm->filled_read_bufs);
  951. INIT_LIST_HEAD(&acm->spare_read_bufs);
  952. tasklet_enable(&acm->urb_task);
  953. flush_scheduled_work(); /* wait for acm_softint */
  954. acm_write_buffers_free(acm);
  955. usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
  956. for (i = 0; i < acm->rx_buflimit; i++)
  957. usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma);
  958. usb_driver_release_interface(&acm_driver, intf == acm->control ? acm->data : intf);
  959. if (!acm->used) {
  960. acm_tty_unregister(acm);
  961. mutex_unlock(&open_mutex);
  962. return;
  963. }
  964. mutex_unlock(&open_mutex);
  965. if (acm->tty)
  966. tty_hangup(acm->tty);
  967. }
  968. /*
  969. * USB driver structure.
  970. */
  971. static struct usb_device_id acm_ids[] = {
  972. /* quirky and broken devices */
  973. { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */
  974. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  975. },
  976. { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */
  977. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  978. },
  979. { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */
  980. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  981. },
  982. { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */
  983. .driver_info = SINGLE_RX_URB, /* firmware bug */
  984. },
  985. { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
  986. .driver_info = SINGLE_RX_URB, /* firmware bug */
  987. },
  988. { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
  989. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  990. },
  991. /* control interfaces with various AT-command sets */
  992. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  993. USB_CDC_ACM_PROTO_AT_V25TER) },
  994. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  995. USB_CDC_ACM_PROTO_AT_PCCA101) },
  996. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  997. USB_CDC_ACM_PROTO_AT_PCCA101_WAKE) },
  998. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  999. USB_CDC_ACM_PROTO_AT_GSM) },
  1000. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1001. USB_CDC_ACM_PROTO_AT_3G ) },
  1002. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1003. USB_CDC_ACM_PROTO_AT_CDMA) },
  1004. /* NOTE: COMM/ACM/0xff is likely MSFT RNDIS ... NOT a modem!! */
  1005. { }
  1006. };
  1007. MODULE_DEVICE_TABLE (usb, acm_ids);
  1008. static struct usb_driver acm_driver = {
  1009. .name = "cdc_acm",
  1010. .probe = acm_probe,
  1011. .disconnect = acm_disconnect,
  1012. .id_table = acm_ids,
  1013. };
  1014. /*
  1015. * TTY driver structures.
  1016. */
  1017. static const struct tty_operations acm_ops = {
  1018. .open = acm_tty_open,
  1019. .close = acm_tty_close,
  1020. .write = acm_tty_write,
  1021. .write_room = acm_tty_write_room,
  1022. .ioctl = acm_tty_ioctl,
  1023. .throttle = acm_tty_throttle,
  1024. .unthrottle = acm_tty_unthrottle,
  1025. .chars_in_buffer = acm_tty_chars_in_buffer,
  1026. .break_ctl = acm_tty_break_ctl,
  1027. .set_termios = acm_tty_set_termios,
  1028. .tiocmget = acm_tty_tiocmget,
  1029. .tiocmset = acm_tty_tiocmset,
  1030. };
  1031. /*
  1032. * Init / exit.
  1033. */
  1034. static int __init acm_init(void)
  1035. {
  1036. int retval;
  1037. acm_tty_driver = alloc_tty_driver(ACM_TTY_MINORS);
  1038. if (!acm_tty_driver)
  1039. return -ENOMEM;
  1040. acm_tty_driver->owner = THIS_MODULE,
  1041. acm_tty_driver->driver_name = "acm",
  1042. acm_tty_driver->name = "ttyACM",
  1043. acm_tty_driver->major = ACM_TTY_MAJOR,
  1044. acm_tty_driver->minor_start = 0,
  1045. acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL,
  1046. acm_tty_driver->subtype = SERIAL_TYPE_NORMAL,
  1047. acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  1048. acm_tty_driver->init_termios = tty_std_termios;
  1049. acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  1050. tty_set_operations(acm_tty_driver, &acm_ops);
  1051. retval = tty_register_driver(acm_tty_driver);
  1052. if (retval) {
  1053. put_tty_driver(acm_tty_driver);
  1054. return retval;
  1055. }
  1056. retval = usb_register(&acm_driver);
  1057. if (retval) {
  1058. tty_unregister_driver(acm_tty_driver);
  1059. put_tty_driver(acm_tty_driver);
  1060. return retval;
  1061. }
  1062. info(DRIVER_VERSION ":" DRIVER_DESC);
  1063. return 0;
  1064. }
  1065. static void __exit acm_exit(void)
  1066. {
  1067. usb_deregister(&acm_driver);
  1068. tty_unregister_driver(acm_tty_driver);
  1069. put_tty_driver(acm_tty_driver);
  1070. }
  1071. module_init(acm_init);
  1072. module_exit(acm_exit);
  1073. MODULE_AUTHOR( DRIVER_AUTHOR );
  1074. MODULE_DESCRIPTION( DRIVER_DESC );
  1075. MODULE_LICENSE("GPL");