cdc-acm.c 46 KB

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