cdc-acm.c 31 KB

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