cdc-acm.c 45 KB

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