cdc-acm.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  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)
  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)
  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. unsigned char throttled;
  283. dbg("Entering acm_rx_tasklet");
  284. if (!ACM_READY(acm))
  285. return;
  286. spin_lock_irqsave(&acm->throttle_lock, flags);
  287. throttled = acm->throttle;
  288. spin_unlock_irqrestore(&acm->throttle_lock, flags);
  289. if (throttled)
  290. return;
  291. next_buffer:
  292. spin_lock_irqsave(&acm->read_lock, flags);
  293. if (list_empty(&acm->filled_read_bufs)) {
  294. spin_unlock_irqrestore(&acm->read_lock, flags);
  295. goto urbs;
  296. }
  297. buf = list_entry(acm->filled_read_bufs.next,
  298. struct acm_rb, list);
  299. list_del(&buf->list);
  300. spin_unlock_irqrestore(&acm->read_lock, flags);
  301. dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size);
  302. tty_buffer_request_room(tty, buf->size);
  303. spin_lock_irqsave(&acm->throttle_lock, flags);
  304. throttled = acm->throttle;
  305. spin_unlock_irqrestore(&acm->throttle_lock, flags);
  306. if (!throttled)
  307. tty_insert_flip_string(tty, buf->base, buf->size);
  308. tty_flip_buffer_push(tty);
  309. if (throttled) {
  310. dbg("Throttling noticed");
  311. spin_lock_irqsave(&acm->read_lock, flags);
  312. list_add(&buf->list, &acm->filled_read_bufs);
  313. spin_unlock_irqrestore(&acm->read_lock, flags);
  314. return;
  315. }
  316. spin_lock_irqsave(&acm->read_lock, flags);
  317. list_add(&buf->list, &acm->spare_read_bufs);
  318. spin_unlock_irqrestore(&acm->read_lock, flags);
  319. goto next_buffer;
  320. urbs:
  321. while (!list_empty(&acm->spare_read_bufs)) {
  322. spin_lock_irqsave(&acm->read_lock, flags);
  323. if (list_empty(&acm->spare_read_urbs)) {
  324. spin_unlock_irqrestore(&acm->read_lock, flags);
  325. return;
  326. }
  327. rcv = list_entry(acm->spare_read_urbs.next,
  328. struct acm_ru, list);
  329. list_del(&rcv->list);
  330. spin_unlock_irqrestore(&acm->read_lock, flags);
  331. buf = list_entry(acm->spare_read_bufs.next,
  332. struct acm_rb, list);
  333. list_del(&buf->list);
  334. rcv->buffer = buf;
  335. usb_fill_bulk_urb(rcv->urb, acm->dev,
  336. acm->rx_endpoint,
  337. buf->base,
  338. acm->readsize,
  339. acm_read_bulk, rcv);
  340. rcv->urb->transfer_dma = buf->dma;
  341. rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  342. dbg("acm_rx_tasklet: sending urb 0x%p, rcv 0x%p, buf 0x%p", rcv->urb, rcv, buf);
  343. /* This shouldn't kill the driver as unsuccessful URBs are returned to the
  344. free-urbs-pool and resubmited ASAP */
  345. if (usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) {
  346. list_add(&buf->list, &acm->spare_read_bufs);
  347. spin_lock_irqsave(&acm->read_lock, flags);
  348. list_add(&rcv->list, &acm->spare_read_urbs);
  349. spin_unlock_irqrestore(&acm->read_lock, flags);
  350. return;
  351. }
  352. }
  353. }
  354. /* data interface wrote those outgoing bytes */
  355. static void acm_write_bulk(struct urb *urb)
  356. {
  357. struct acm *acm = (struct acm *)urb->context;
  358. dbg("Entering acm_write_bulk with status %d", urb->status);
  359. acm_write_done(acm);
  360. acm_write_start(acm);
  361. if (ACM_READY(acm))
  362. schedule_work(&acm->work);
  363. }
  364. static void acm_softint(struct work_struct *work)
  365. {
  366. struct acm *acm = container_of(work, struct acm, work);
  367. dbg("Entering acm_softint.");
  368. if (!ACM_READY(acm))
  369. return;
  370. tty_wakeup(acm->tty);
  371. }
  372. /*
  373. * TTY handlers
  374. */
  375. static int acm_tty_open(struct tty_struct *tty, struct file *filp)
  376. {
  377. struct acm *acm;
  378. int rv = -EINVAL;
  379. int i;
  380. dbg("Entering acm_tty_open.");
  381. mutex_lock(&open_mutex);
  382. acm = acm_table[tty->index];
  383. if (!acm || !acm->dev)
  384. goto err_out;
  385. else
  386. rv = 0;
  387. tty->driver_data = acm;
  388. acm->tty = tty;
  389. /* force low_latency on so that our tty_push actually forces the data through,
  390. otherwise it is scheduled, and with high data rates data can get lost. */
  391. tty->low_latency = 1;
  392. if (acm->used++) {
  393. goto done;
  394. }
  395. acm->ctrlurb->dev = acm->dev;
  396. if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) {
  397. dbg("usb_submit_urb(ctrl irq) failed");
  398. goto bail_out;
  399. }
  400. if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) &&
  401. (acm->ctrl_caps & USB_CDC_CAP_LINE))
  402. goto full_bailout;
  403. INIT_LIST_HEAD(&acm->spare_read_urbs);
  404. INIT_LIST_HEAD(&acm->spare_read_bufs);
  405. INIT_LIST_HEAD(&acm->filled_read_bufs);
  406. for (i = 0; i < acm->rx_buflimit; i++) {
  407. list_add(&(acm->ru[i].list), &acm->spare_read_urbs);
  408. }
  409. for (i = 0; i < acm->rx_buflimit; i++) {
  410. list_add(&(acm->rb[i].list), &acm->spare_read_bufs);
  411. }
  412. acm->throttle = 0;
  413. tasklet_schedule(&acm->urb_task);
  414. done:
  415. err_out:
  416. mutex_unlock(&open_mutex);
  417. return rv;
  418. full_bailout:
  419. usb_kill_urb(acm->ctrlurb);
  420. bail_out:
  421. acm->used--;
  422. mutex_unlock(&open_mutex);
  423. return -EIO;
  424. }
  425. static void acm_tty_unregister(struct acm *acm)
  426. {
  427. int i,nr;
  428. nr = acm->rx_buflimit;
  429. tty_unregister_device(acm_tty_driver, acm->minor);
  430. usb_put_intf(acm->control);
  431. acm_table[acm->minor] = NULL;
  432. usb_free_urb(acm->ctrlurb);
  433. usb_free_urb(acm->writeurb);
  434. for (i = 0; i < nr; i++)
  435. usb_free_urb(acm->ru[i].urb);
  436. kfree(acm);
  437. }
  438. static void acm_tty_close(struct tty_struct *tty, struct file *filp)
  439. {
  440. struct acm *acm = tty->driver_data;
  441. int i,nr;
  442. if (!acm || !acm->used)
  443. return;
  444. nr = acm->rx_buflimit;
  445. mutex_lock(&open_mutex);
  446. if (!--acm->used) {
  447. if (acm->dev) {
  448. acm_set_control(acm, acm->ctrlout = 0);
  449. usb_kill_urb(acm->ctrlurb);
  450. usb_kill_urb(acm->writeurb);
  451. for (i = 0; i < nr; i++)
  452. usb_kill_urb(acm->ru[i].urb);
  453. } else
  454. acm_tty_unregister(acm);
  455. }
  456. mutex_unlock(&open_mutex);
  457. }
  458. static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
  459. {
  460. struct acm *acm = tty->driver_data;
  461. int stat;
  462. unsigned long flags;
  463. int wbn;
  464. struct acm_wb *wb;
  465. dbg("Entering acm_tty_write to write %d bytes,", count);
  466. if (!ACM_READY(acm))
  467. return -EINVAL;
  468. if (!count)
  469. return 0;
  470. spin_lock_irqsave(&acm->write_lock, flags);
  471. if ((wbn = acm_wb_alloc(acm)) < 0) {
  472. spin_unlock_irqrestore(&acm->write_lock, flags);
  473. acm_write_start(acm);
  474. return 0;
  475. }
  476. wb = &acm->wb[wbn];
  477. count = (count > acm->writesize) ? acm->writesize : count;
  478. dbg("Get %d bytes...", count);
  479. memcpy(wb->buf, buf, count);
  480. wb->len = count;
  481. spin_unlock_irqrestore(&acm->write_lock, flags);
  482. if ((stat = acm_write_start(acm)) < 0)
  483. return stat;
  484. return count;
  485. }
  486. static int acm_tty_write_room(struct tty_struct *tty)
  487. {
  488. struct acm *acm = tty->driver_data;
  489. if (!ACM_READY(acm))
  490. return -EINVAL;
  491. /*
  492. * Do not let the line discipline to know that we have a reserve,
  493. * or it might get too enthusiastic.
  494. */
  495. return (acm->write_ready && acm_wb_is_avail(acm)) ? acm->writesize : 0;
  496. }
  497. static int acm_tty_chars_in_buffer(struct tty_struct *tty)
  498. {
  499. struct acm *acm = tty->driver_data;
  500. if (!ACM_READY(acm))
  501. return -EINVAL;
  502. /*
  503. * This is inaccurate (overcounts), but it works.
  504. */
  505. return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize;
  506. }
  507. static void acm_tty_throttle(struct tty_struct *tty)
  508. {
  509. struct acm *acm = tty->driver_data;
  510. if (!ACM_READY(acm))
  511. return;
  512. spin_lock_bh(&acm->throttle_lock);
  513. acm->throttle = 1;
  514. spin_unlock_bh(&acm->throttle_lock);
  515. }
  516. static void acm_tty_unthrottle(struct tty_struct *tty)
  517. {
  518. struct acm *acm = tty->driver_data;
  519. if (!ACM_READY(acm))
  520. return;
  521. spin_lock_bh(&acm->throttle_lock);
  522. acm->throttle = 0;
  523. spin_unlock_bh(&acm->throttle_lock);
  524. tasklet_schedule(&acm->urb_task);
  525. }
  526. static void acm_tty_break_ctl(struct tty_struct *tty, int state)
  527. {
  528. struct acm *acm = tty->driver_data;
  529. if (!ACM_READY(acm))
  530. return;
  531. if (acm_send_break(acm, state ? 0xffff : 0))
  532. dbg("send break failed");
  533. }
  534. static int acm_tty_tiocmget(struct tty_struct *tty, struct file *file)
  535. {
  536. struct acm *acm = tty->driver_data;
  537. if (!ACM_READY(acm))
  538. return -EINVAL;
  539. return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) |
  540. (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) |
  541. (acm->ctrlin & ACM_CTRL_DSR ? TIOCM_DSR : 0) |
  542. (acm->ctrlin & ACM_CTRL_RI ? TIOCM_RI : 0) |
  543. (acm->ctrlin & ACM_CTRL_DCD ? TIOCM_CD : 0) |
  544. TIOCM_CTS;
  545. }
  546. static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file,
  547. unsigned int set, unsigned int clear)
  548. {
  549. struct acm *acm = tty->driver_data;
  550. unsigned int newctrl;
  551. if (!ACM_READY(acm))
  552. return -EINVAL;
  553. newctrl = acm->ctrlout;
  554. set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0);
  555. clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0);
  556. newctrl = (newctrl & ~clear) | set;
  557. if (acm->ctrlout == newctrl)
  558. return 0;
  559. return acm_set_control(acm, acm->ctrlout = newctrl);
  560. }
  561. static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  562. {
  563. struct acm *acm = tty->driver_data;
  564. if (!ACM_READY(acm))
  565. return -EINVAL;
  566. return -ENOIOCTLCMD;
  567. }
  568. static const __u32 acm_tty_speed[] = {
  569. 0, 50, 75, 110, 134, 150, 200, 300, 600,
  570. 1200, 1800, 2400, 4800, 9600, 19200, 38400,
  571. 57600, 115200, 230400, 460800, 500000, 576000,
  572. 921600, 1000000, 1152000, 1500000, 2000000,
  573. 2500000, 3000000, 3500000, 4000000
  574. };
  575. static const __u8 acm_tty_size[] = {
  576. 5, 6, 7, 8
  577. };
  578. static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old)
  579. {
  580. struct acm *acm = tty->driver_data;
  581. struct ktermios *termios = tty->termios;
  582. struct usb_cdc_line_coding newline;
  583. int newctrl = acm->ctrlout;
  584. if (!ACM_READY(acm))
  585. return;
  586. newline.dwDTERate = cpu_to_le32p(acm_tty_speed +
  587. (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0));
  588. newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0;
  589. newline.bParityType = termios->c_cflag & PARENB ?
  590. (termios->c_cflag & PARODD ? 1 : 2) + (termios->c_cflag & CMSPAR ? 2 : 0) : 0;
  591. newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4];
  592. acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
  593. if (!newline.dwDTERate) {
  594. newline.dwDTERate = acm->line.dwDTERate;
  595. newctrl &= ~ACM_CTRL_DTR;
  596. } else newctrl |= ACM_CTRL_DTR;
  597. if (newctrl != acm->ctrlout)
  598. acm_set_control(acm, acm->ctrlout = newctrl);
  599. if (memcmp(&acm->line, &newline, sizeof newline)) {
  600. memcpy(&acm->line, &newline, sizeof newline);
  601. dbg("set line: %d %d %d %d", le32_to_cpu(newline.dwDTERate),
  602. newline.bCharFormat, newline.bParityType,
  603. newline.bDataBits);
  604. acm_set_line(acm, &acm->line);
  605. }
  606. }
  607. /*
  608. * USB probe and disconnect routines.
  609. */
  610. /* Little helper: write buffers free */
  611. static void acm_write_buffers_free(struct acm *acm)
  612. {
  613. int i;
  614. struct acm_wb *wb;
  615. for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) {
  616. usb_buffer_free(acm->dev, acm->writesize, wb->buf, wb->dmah);
  617. }
  618. }
  619. /* Little helper: write buffers allocate */
  620. static int acm_write_buffers_alloc(struct acm *acm)
  621. {
  622. int i;
  623. struct acm_wb *wb;
  624. for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) {
  625. wb->buf = usb_buffer_alloc(acm->dev, acm->writesize, GFP_KERNEL,
  626. &wb->dmah);
  627. if (!wb->buf) {
  628. while (i != 0) {
  629. --i;
  630. --wb;
  631. usb_buffer_free(acm->dev, acm->writesize,
  632. wb->buf, wb->dmah);
  633. }
  634. return -ENOMEM;
  635. }
  636. }
  637. return 0;
  638. }
  639. static int acm_probe (struct usb_interface *intf,
  640. const struct usb_device_id *id)
  641. {
  642. struct usb_cdc_union_desc *union_header = NULL;
  643. char *buffer = intf->altsetting->extra;
  644. int buflen = intf->altsetting->extralen;
  645. struct usb_interface *control_interface;
  646. struct usb_interface *data_interface;
  647. struct usb_endpoint_descriptor *epctrl;
  648. struct usb_endpoint_descriptor *epread;
  649. struct usb_endpoint_descriptor *epwrite;
  650. struct usb_device *usb_dev = interface_to_usbdev(intf);
  651. struct acm *acm;
  652. int minor;
  653. int ctrlsize,readsize;
  654. u8 *buf;
  655. u8 ac_management_function = 0;
  656. u8 call_management_function = 0;
  657. int call_interface_num = -1;
  658. int data_interface_num;
  659. unsigned long quirks;
  660. int num_rx_buf;
  661. int i;
  662. /* normal quirks */
  663. quirks = (unsigned long)id->driver_info;
  664. num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR;
  665. /* handle quirks deadly to normal probing*/
  666. if (quirks == NO_UNION_NORMAL) {
  667. data_interface = usb_ifnum_to_if(usb_dev, 1);
  668. control_interface = usb_ifnum_to_if(usb_dev, 0);
  669. goto skip_normal_probe;
  670. }
  671. /* normal probing*/
  672. if (!buffer) {
  673. err("Wierd descriptor references\n");
  674. return -EINVAL;
  675. }
  676. if (!buflen) {
  677. if (intf->cur_altsetting->endpoint->extralen && intf->cur_altsetting->endpoint->extra) {
  678. dev_dbg(&intf->dev,"Seeking extra descriptors on endpoint");
  679. buflen = intf->cur_altsetting->endpoint->extralen;
  680. buffer = intf->cur_altsetting->endpoint->extra;
  681. } else {
  682. err("Zero length descriptor references\n");
  683. return -EINVAL;
  684. }
  685. }
  686. while (buflen > 0) {
  687. if (buffer [1] != USB_DT_CS_INTERFACE) {
  688. err("skipping garbage\n");
  689. goto next_desc;
  690. }
  691. switch (buffer [2]) {
  692. case USB_CDC_UNION_TYPE: /* we've found it */
  693. if (union_header) {
  694. err("More than one union descriptor, skipping ...");
  695. goto next_desc;
  696. }
  697. union_header = (struct usb_cdc_union_desc *)
  698. buffer;
  699. break;
  700. case USB_CDC_COUNTRY_TYPE: /* maybe somehow export */
  701. break; /* for now we ignore it */
  702. case USB_CDC_HEADER_TYPE: /* maybe check version */
  703. break; /* for now we ignore it */
  704. case USB_CDC_ACM_TYPE:
  705. ac_management_function = buffer[3];
  706. break;
  707. case USB_CDC_CALL_MANAGEMENT_TYPE:
  708. call_management_function = buffer[3];
  709. call_interface_num = buffer[4];
  710. if ((call_management_function & 3) != 3)
  711. err("This device cannot do calls on its own. It is no modem.");
  712. break;
  713. default:
  714. err("Ignoring extra header, type %d, length %d", buffer[2], buffer[0]);
  715. break;
  716. }
  717. next_desc:
  718. buflen -= buffer[0];
  719. buffer += buffer[0];
  720. }
  721. if (!union_header) {
  722. if (call_interface_num > 0) {
  723. dev_dbg(&intf->dev,"No union descriptor, using call management descriptor");
  724. data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num));
  725. control_interface = intf;
  726. } else {
  727. dev_dbg(&intf->dev,"No union descriptor, giving up");
  728. return -ENODEV;
  729. }
  730. } else {
  731. control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0);
  732. data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0));
  733. if (!control_interface || !data_interface) {
  734. dev_dbg(&intf->dev,"no interfaces");
  735. return -ENODEV;
  736. }
  737. }
  738. if (data_interface_num != call_interface_num)
  739. dev_dbg(&intf->dev,"Seperate call control interface. That is not fully supported.");
  740. skip_normal_probe:
  741. /*workaround for switched interfaces */
  742. if (data_interface->cur_altsetting->desc.bInterfaceClass != CDC_DATA_INTERFACE_TYPE) {
  743. if (control_interface->cur_altsetting->desc.bInterfaceClass == CDC_DATA_INTERFACE_TYPE) {
  744. struct usb_interface *t;
  745. dev_dbg(&intf->dev,"Your device has switched interfaces.");
  746. t = control_interface;
  747. control_interface = data_interface;
  748. data_interface = t;
  749. } else {
  750. return -EINVAL;
  751. }
  752. }
  753. if (usb_interface_claimed(data_interface)) { /* valid in this context */
  754. dev_dbg(&intf->dev,"The data interface isn't available");
  755. return -EBUSY;
  756. }
  757. if (data_interface->cur_altsetting->desc.bNumEndpoints < 2)
  758. return -EINVAL;
  759. epctrl = &control_interface->cur_altsetting->endpoint[0].desc;
  760. epread = &data_interface->cur_altsetting->endpoint[0].desc;
  761. epwrite = &data_interface->cur_altsetting->endpoint[1].desc;
  762. /* workaround for switched endpoints */
  763. if (!usb_endpoint_dir_in(epread)) {
  764. /* descriptors are swapped */
  765. struct usb_endpoint_descriptor *t;
  766. dev_dbg(&intf->dev,"The data interface has switched endpoints");
  767. t = epread;
  768. epread = epwrite;
  769. epwrite = t;
  770. }
  771. dbg("interfaces are valid");
  772. for (minor = 0; minor < ACM_TTY_MINORS && acm_table[minor]; minor++);
  773. if (minor == ACM_TTY_MINORS) {
  774. err("no more free acm devices");
  775. return -ENODEV;
  776. }
  777. if (!(acm = kzalloc(sizeof(struct acm), GFP_KERNEL))) {
  778. dev_dbg(&intf->dev, "out of memory (acm kzalloc)");
  779. goto alloc_fail;
  780. }
  781. ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize);
  782. readsize = le16_to_cpu(epread->wMaxPacketSize)* ( quirks == SINGLE_RX_URB ? 1 : 2);
  783. acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize);
  784. acm->control = control_interface;
  785. acm->data = data_interface;
  786. acm->minor = minor;
  787. acm->dev = usb_dev;
  788. acm->ctrl_caps = ac_management_function;
  789. acm->ctrlsize = ctrlsize;
  790. acm->readsize = readsize;
  791. acm->rx_buflimit = num_rx_buf;
  792. acm->urb_task.func = acm_rx_tasklet;
  793. acm->urb_task.data = (unsigned long) acm;
  794. INIT_WORK(&acm->work, acm_softint);
  795. spin_lock_init(&acm->throttle_lock);
  796. spin_lock_init(&acm->write_lock);
  797. spin_lock_init(&acm->read_lock);
  798. acm->write_ready = 1;
  799. acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress);
  800. buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
  801. if (!buf) {
  802. dev_dbg(&intf->dev, "out of memory (ctrl buffer alloc)");
  803. goto alloc_fail2;
  804. }
  805. acm->ctrl_buffer = buf;
  806. if (acm_write_buffers_alloc(acm) < 0) {
  807. dev_dbg(&intf->dev, "out of memory (write buffer alloc)");
  808. goto alloc_fail4;
  809. }
  810. acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);
  811. if (!acm->ctrlurb) {
  812. dev_dbg(&intf->dev, "out of memory (ctrlurb kmalloc)");
  813. goto alloc_fail5;
  814. }
  815. for (i = 0; i < num_rx_buf; i++) {
  816. struct acm_ru *rcv = &(acm->ru[i]);
  817. if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) {
  818. dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)");
  819. goto alloc_fail7;
  820. }
  821. rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  822. rcv->instance = acm;
  823. }
  824. for (i = 0; i < num_rx_buf; i++) {
  825. struct acm_rb *buf = &(acm->rb[i]);
  826. if (!(buf->base = usb_buffer_alloc(acm->dev, readsize, GFP_KERNEL, &buf->dma))) {
  827. dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)");
  828. goto alloc_fail7;
  829. }
  830. }
  831. acm->writeurb = usb_alloc_urb(0, GFP_KERNEL);
  832. if (!acm->writeurb) {
  833. dev_dbg(&intf->dev, "out of memory (writeurb kmalloc)");
  834. goto alloc_fail7;
  835. }
  836. usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress),
  837. acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval);
  838. acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  839. acm->ctrlurb->transfer_dma = acm->ctrl_dma;
  840. usb_fill_bulk_urb(acm->writeurb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
  841. NULL, acm->writesize, acm_write_bulk, acm);
  842. acm->writeurb->transfer_flags |= URB_NO_FSBR | URB_NO_TRANSFER_DMA_MAP;
  843. dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor);
  844. acm_set_control(acm, acm->ctrlout);
  845. acm->line.dwDTERate = cpu_to_le32(9600);
  846. acm->line.bDataBits = 8;
  847. acm_set_line(acm, &acm->line);
  848. usb_driver_claim_interface(&acm_driver, data_interface, acm);
  849. usb_get_intf(control_interface);
  850. tty_register_device(acm_tty_driver, minor, &control_interface->dev);
  851. acm_table[minor] = acm;
  852. usb_set_intfdata (intf, acm);
  853. return 0;
  854. alloc_fail7:
  855. for (i = 0; i < num_rx_buf; i++)
  856. usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma);
  857. for (i = 0; i < num_rx_buf; i++)
  858. usb_free_urb(acm->ru[i].urb);
  859. usb_free_urb(acm->ctrlurb);
  860. alloc_fail5:
  861. acm_write_buffers_free(acm);
  862. alloc_fail4:
  863. usb_buffer_free(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
  864. alloc_fail2:
  865. kfree(acm);
  866. alloc_fail:
  867. return -ENOMEM;
  868. }
  869. static void acm_disconnect(struct usb_interface *intf)
  870. {
  871. struct acm *acm = usb_get_intfdata (intf);
  872. struct usb_device *usb_dev = interface_to_usbdev(intf);
  873. int i;
  874. if (!acm || !acm->dev) {
  875. dbg("disconnect on nonexisting interface");
  876. return;
  877. }
  878. mutex_lock(&open_mutex);
  879. if (!usb_get_intfdata(intf)) {
  880. mutex_unlock(&open_mutex);
  881. return;
  882. }
  883. acm->dev = NULL;
  884. usb_set_intfdata(acm->control, NULL);
  885. usb_set_intfdata(acm->data, NULL);
  886. tasklet_disable(&acm->urb_task);
  887. usb_kill_urb(acm->ctrlurb);
  888. usb_kill_urb(acm->writeurb);
  889. for (i = 0; i < acm->rx_buflimit; i++)
  890. usb_kill_urb(acm->ru[i].urb);
  891. INIT_LIST_HEAD(&acm->filled_read_bufs);
  892. INIT_LIST_HEAD(&acm->spare_read_bufs);
  893. tasklet_enable(&acm->urb_task);
  894. flush_scheduled_work(); /* wait for acm_softint */
  895. acm_write_buffers_free(acm);
  896. usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
  897. for (i = 0; i < acm->rx_buflimit; i++)
  898. usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma);
  899. usb_driver_release_interface(&acm_driver, intf == acm->control ? acm->data : intf);
  900. if (!acm->used) {
  901. acm_tty_unregister(acm);
  902. mutex_unlock(&open_mutex);
  903. return;
  904. }
  905. mutex_unlock(&open_mutex);
  906. if (acm->tty)
  907. tty_hangup(acm->tty);
  908. }
  909. /*
  910. * USB driver structure.
  911. */
  912. static struct usb_device_id acm_ids[] = {
  913. /* quirky and broken devices */
  914. { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */
  915. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  916. },
  917. { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */
  918. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  919. },
  920. { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */
  921. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  922. },
  923. { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */
  924. .driver_info = SINGLE_RX_URB, /* firmware bug */
  925. },
  926. { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
  927. .driver_info = SINGLE_RX_URB, /* firmware bug */
  928. },
  929. { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
  930. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  931. },
  932. /* control interfaces with various AT-command sets */
  933. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  934. USB_CDC_ACM_PROTO_AT_V25TER) },
  935. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  936. USB_CDC_ACM_PROTO_AT_PCCA101) },
  937. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  938. USB_CDC_ACM_PROTO_AT_PCCA101_WAKE) },
  939. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  940. USB_CDC_ACM_PROTO_AT_GSM) },
  941. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  942. USB_CDC_ACM_PROTO_AT_3G ) },
  943. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  944. USB_CDC_ACM_PROTO_AT_CDMA) },
  945. /* NOTE: COMM/ACM/0xff is likely MSFT RNDIS ... NOT a modem!! */
  946. { }
  947. };
  948. MODULE_DEVICE_TABLE (usb, acm_ids);
  949. static struct usb_driver acm_driver = {
  950. .name = "cdc_acm",
  951. .probe = acm_probe,
  952. .disconnect = acm_disconnect,
  953. .id_table = acm_ids,
  954. };
  955. /*
  956. * TTY driver structures.
  957. */
  958. static const struct tty_operations acm_ops = {
  959. .open = acm_tty_open,
  960. .close = acm_tty_close,
  961. .write = acm_tty_write,
  962. .write_room = acm_tty_write_room,
  963. .ioctl = acm_tty_ioctl,
  964. .throttle = acm_tty_throttle,
  965. .unthrottle = acm_tty_unthrottle,
  966. .chars_in_buffer = acm_tty_chars_in_buffer,
  967. .break_ctl = acm_tty_break_ctl,
  968. .set_termios = acm_tty_set_termios,
  969. .tiocmget = acm_tty_tiocmget,
  970. .tiocmset = acm_tty_tiocmset,
  971. };
  972. /*
  973. * Init / exit.
  974. */
  975. static int __init acm_init(void)
  976. {
  977. int retval;
  978. acm_tty_driver = alloc_tty_driver(ACM_TTY_MINORS);
  979. if (!acm_tty_driver)
  980. return -ENOMEM;
  981. acm_tty_driver->owner = THIS_MODULE,
  982. acm_tty_driver->driver_name = "acm",
  983. acm_tty_driver->name = "ttyACM",
  984. acm_tty_driver->major = ACM_TTY_MAJOR,
  985. acm_tty_driver->minor_start = 0,
  986. acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL,
  987. acm_tty_driver->subtype = SERIAL_TYPE_NORMAL,
  988. acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  989. acm_tty_driver->init_termios = tty_std_termios;
  990. acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  991. tty_set_operations(acm_tty_driver, &acm_ops);
  992. retval = tty_register_driver(acm_tty_driver);
  993. if (retval) {
  994. put_tty_driver(acm_tty_driver);
  995. return retval;
  996. }
  997. retval = usb_register(&acm_driver);
  998. if (retval) {
  999. tty_unregister_driver(acm_tty_driver);
  1000. put_tty_driver(acm_tty_driver);
  1001. return retval;
  1002. }
  1003. info(DRIVER_VERSION ":" DRIVER_DESC);
  1004. return 0;
  1005. }
  1006. static void __exit acm_exit(void)
  1007. {
  1008. usb_deregister(&acm_driver);
  1009. tty_unregister_driver(acm_tty_driver);
  1010. put_tty_driver(acm_tty_driver);
  1011. }
  1012. module_init(acm_init);
  1013. module_exit(acm_exit);
  1014. MODULE_AUTHOR( DRIVER_AUTHOR );
  1015. MODULE_DESCRIPTION( DRIVER_DESC );
  1016. MODULE_LICENSE("GPL");