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