cdc-acm.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  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_standard_install(driver, tty);
  433. if (retval)
  434. goto error_init_termios;
  435. tty->driver_data = acm;
  436. return 0;
  437. error_init_termios:
  438. tty_port_put(&acm->port);
  439. return retval;
  440. }
  441. static int acm_tty_open(struct tty_struct *tty, struct file *filp)
  442. {
  443. struct acm *acm = tty->driver_data;
  444. dev_dbg(tty->dev, "%s\n", __func__);
  445. return tty_port_open(&acm->port, tty, filp);
  446. }
  447. static int acm_port_activate(struct tty_port *port, struct tty_struct *tty)
  448. {
  449. struct acm *acm = container_of(port, struct acm, port);
  450. int retval = -ENODEV;
  451. dev_dbg(&acm->control->dev, "%s\n", __func__);
  452. mutex_lock(&acm->mutex);
  453. if (acm->disconnected)
  454. goto disconnected;
  455. retval = usb_autopm_get_interface(acm->control);
  456. if (retval)
  457. goto error_get_interface;
  458. /*
  459. * FIXME: Why do we need this? Allocating 64K of physically contiguous
  460. * memory is really nasty...
  461. */
  462. set_bit(TTY_NO_WRITE_SPLIT, &tty->flags);
  463. acm->control->needs_remote_wakeup = 1;
  464. acm->ctrlurb->dev = acm->dev;
  465. if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) {
  466. dev_err(&acm->control->dev,
  467. "%s - usb_submit_urb(ctrl irq) failed\n", __func__);
  468. goto error_submit_urb;
  469. }
  470. acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS;
  471. if (acm_set_control(acm, acm->ctrlout) < 0 &&
  472. (acm->ctrl_caps & USB_CDC_CAP_LINE))
  473. goto error_set_control;
  474. usb_autopm_put_interface(acm->control);
  475. /*
  476. * Unthrottle device in case the TTY was closed while throttled.
  477. */
  478. spin_lock_irq(&acm->read_lock);
  479. acm->throttled = 0;
  480. acm->throttle_req = 0;
  481. spin_unlock_irq(&acm->read_lock);
  482. if (acm_submit_read_urbs(acm, GFP_KERNEL))
  483. goto error_submit_read_urbs;
  484. mutex_unlock(&acm->mutex);
  485. return 0;
  486. error_submit_read_urbs:
  487. acm->ctrlout = 0;
  488. acm_set_control(acm, acm->ctrlout);
  489. error_set_control:
  490. usb_kill_urb(acm->ctrlurb);
  491. error_submit_urb:
  492. usb_autopm_put_interface(acm->control);
  493. error_get_interface:
  494. disconnected:
  495. mutex_unlock(&acm->mutex);
  496. return retval;
  497. }
  498. static void acm_port_destruct(struct tty_port *port)
  499. {
  500. struct acm *acm = container_of(port, struct acm, port);
  501. dev_dbg(&acm->control->dev, "%s\n", __func__);
  502. tty_unregister_device(acm_tty_driver, acm->minor);
  503. acm_release_minor(acm);
  504. usb_put_intf(acm->control);
  505. kfree(acm->country_codes);
  506. kfree(acm);
  507. }
  508. static void acm_port_shutdown(struct tty_port *port)
  509. {
  510. struct acm *acm = container_of(port, struct acm, port);
  511. int i;
  512. dev_dbg(&acm->control->dev, "%s\n", __func__);
  513. mutex_lock(&acm->mutex);
  514. if (!acm->disconnected) {
  515. usb_autopm_get_interface(acm->control);
  516. acm_set_control(acm, acm->ctrlout = 0);
  517. usb_kill_urb(acm->ctrlurb);
  518. for (i = 0; i < ACM_NW; i++)
  519. usb_kill_urb(acm->wb[i].urb);
  520. for (i = 0; i < acm->rx_buflimit; i++)
  521. usb_kill_urb(acm->read_urbs[i]);
  522. acm->control->needs_remote_wakeup = 0;
  523. usb_autopm_put_interface(acm->control);
  524. }
  525. mutex_unlock(&acm->mutex);
  526. }
  527. static void acm_tty_cleanup(struct tty_struct *tty)
  528. {
  529. struct acm *acm = tty->driver_data;
  530. dev_dbg(&acm->control->dev, "%s\n", __func__);
  531. tty_port_put(&acm->port);
  532. }
  533. static void acm_tty_hangup(struct tty_struct *tty)
  534. {
  535. struct acm *acm = tty->driver_data;
  536. dev_dbg(&acm->control->dev, "%s\n", __func__);
  537. tty_port_hangup(&acm->port);
  538. }
  539. static void acm_tty_close(struct tty_struct *tty, struct file *filp)
  540. {
  541. struct acm *acm = tty->driver_data;
  542. dev_dbg(&acm->control->dev, "%s\n", __func__);
  543. tty_port_close(&acm->port, tty, filp);
  544. }
  545. static int acm_tty_write(struct tty_struct *tty,
  546. const unsigned char *buf, int count)
  547. {
  548. struct acm *acm = tty->driver_data;
  549. int stat;
  550. unsigned long flags;
  551. int wbn;
  552. struct acm_wb *wb;
  553. if (!count)
  554. return 0;
  555. dev_vdbg(&acm->data->dev, "%s - count %d\n", __func__, count);
  556. spin_lock_irqsave(&acm->write_lock, flags);
  557. wbn = acm_wb_alloc(acm);
  558. if (wbn < 0) {
  559. spin_unlock_irqrestore(&acm->write_lock, flags);
  560. return 0;
  561. }
  562. wb = &acm->wb[wbn];
  563. count = (count > acm->writesize) ? acm->writesize : count;
  564. dev_vdbg(&acm->data->dev, "%s - write %d\n", __func__, count);
  565. memcpy(wb->buf, buf, count);
  566. wb->len = count;
  567. spin_unlock_irqrestore(&acm->write_lock, flags);
  568. stat = acm_write_start(acm, wbn);
  569. if (stat < 0)
  570. return stat;
  571. return count;
  572. }
  573. static int acm_tty_write_room(struct tty_struct *tty)
  574. {
  575. struct acm *acm = tty->driver_data;
  576. /*
  577. * Do not let the line discipline to know that we have a reserve,
  578. * or it might get too enthusiastic.
  579. */
  580. return acm_wb_is_avail(acm) ? acm->writesize : 0;
  581. }
  582. static int acm_tty_chars_in_buffer(struct tty_struct *tty)
  583. {
  584. struct acm *acm = tty->driver_data;
  585. /*
  586. * if the device was unplugged then any remaining characters fell out
  587. * of the connector ;)
  588. */
  589. if (acm->disconnected)
  590. return 0;
  591. /*
  592. * This is inaccurate (overcounts), but it works.
  593. */
  594. return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize;
  595. }
  596. static void acm_tty_throttle(struct tty_struct *tty)
  597. {
  598. struct acm *acm = tty->driver_data;
  599. spin_lock_irq(&acm->read_lock);
  600. acm->throttle_req = 1;
  601. spin_unlock_irq(&acm->read_lock);
  602. }
  603. static void acm_tty_unthrottle(struct tty_struct *tty)
  604. {
  605. struct acm *acm = tty->driver_data;
  606. unsigned int was_throttled;
  607. spin_lock_irq(&acm->read_lock);
  608. was_throttled = acm->throttled;
  609. acm->throttled = 0;
  610. acm->throttle_req = 0;
  611. spin_unlock_irq(&acm->read_lock);
  612. if (was_throttled)
  613. acm_submit_read_urbs(acm, GFP_KERNEL);
  614. }
  615. static int acm_tty_break_ctl(struct tty_struct *tty, int state)
  616. {
  617. struct acm *acm = tty->driver_data;
  618. int retval;
  619. retval = acm_send_break(acm, state ? 0xffff : 0);
  620. if (retval < 0)
  621. dev_dbg(&acm->control->dev, "%s - send break failed\n",
  622. __func__);
  623. return retval;
  624. }
  625. static int acm_tty_tiocmget(struct tty_struct *tty)
  626. {
  627. struct acm *acm = tty->driver_data;
  628. return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) |
  629. (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) |
  630. (acm->ctrlin & ACM_CTRL_DSR ? TIOCM_DSR : 0) |
  631. (acm->ctrlin & ACM_CTRL_RI ? TIOCM_RI : 0) |
  632. (acm->ctrlin & ACM_CTRL_DCD ? TIOCM_CD : 0) |
  633. TIOCM_CTS;
  634. }
  635. static int acm_tty_tiocmset(struct tty_struct *tty,
  636. unsigned int set, unsigned int clear)
  637. {
  638. struct acm *acm = tty->driver_data;
  639. unsigned int newctrl;
  640. newctrl = acm->ctrlout;
  641. set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) |
  642. (set & TIOCM_RTS ? ACM_CTRL_RTS : 0);
  643. clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) |
  644. (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0);
  645. newctrl = (newctrl & ~clear) | set;
  646. if (acm->ctrlout == newctrl)
  647. return 0;
  648. return acm_set_control(acm, acm->ctrlout = newctrl);
  649. }
  650. static int get_serial_info(struct acm *acm, struct serial_struct __user *info)
  651. {
  652. struct serial_struct tmp;
  653. if (!info)
  654. return -EINVAL;
  655. memset(&tmp, 0, sizeof(tmp));
  656. tmp.flags = ASYNC_LOW_LATENCY;
  657. tmp.xmit_fifo_size = acm->writesize;
  658. tmp.baud_base = le32_to_cpu(acm->line.dwDTERate);
  659. if (copy_to_user(info, &tmp, sizeof(tmp)))
  660. return -EFAULT;
  661. else
  662. return 0;
  663. }
  664. static int acm_tty_ioctl(struct tty_struct *tty,
  665. unsigned int cmd, unsigned long arg)
  666. {
  667. struct acm *acm = tty->driver_data;
  668. int rv = -ENOIOCTLCMD;
  669. switch (cmd) {
  670. case TIOCGSERIAL: /* gets serial port data */
  671. rv = get_serial_info(acm, (struct serial_struct __user *) arg);
  672. break;
  673. }
  674. return rv;
  675. }
  676. static const __u32 acm_tty_speed[] = {
  677. 0, 50, 75, 110, 134, 150, 200, 300, 600,
  678. 1200, 1800, 2400, 4800, 9600, 19200, 38400,
  679. 57600, 115200, 230400, 460800, 500000, 576000,
  680. 921600, 1000000, 1152000, 1500000, 2000000,
  681. 2500000, 3000000, 3500000, 4000000
  682. };
  683. static void acm_tty_set_termios(struct tty_struct *tty,
  684. struct ktermios *termios_old)
  685. {
  686. struct acm *acm = tty->driver_data;
  687. struct ktermios *termios = &tty->termios;
  688. struct usb_cdc_line_coding newline;
  689. int newctrl = acm->ctrlout;
  690. newline.dwDTERate = cpu_to_le32(tty_get_baud_rate(tty));
  691. newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0;
  692. newline.bParityType = termios->c_cflag & PARENB ?
  693. (termios->c_cflag & PARODD ? 1 : 2) +
  694. (termios->c_cflag & CMSPAR ? 2 : 0) : 0;
  695. switch (termios->c_cflag & CSIZE) {
  696. case CS5:
  697. newline.bDataBits = 5;
  698. break;
  699. case CS6:
  700. newline.bDataBits = 6;
  701. break;
  702. case CS7:
  703. newline.bDataBits = 7;
  704. break;
  705. case CS8:
  706. default:
  707. newline.bDataBits = 8;
  708. break;
  709. }
  710. /* FIXME: Needs to clear unsupported bits in the termios */
  711. acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
  712. if (!newline.dwDTERate) {
  713. newline.dwDTERate = acm->line.dwDTERate;
  714. newctrl &= ~ACM_CTRL_DTR;
  715. } else
  716. newctrl |= ACM_CTRL_DTR;
  717. if (newctrl != acm->ctrlout)
  718. acm_set_control(acm, acm->ctrlout = newctrl);
  719. if (memcmp(&acm->line, &newline, sizeof newline)) {
  720. memcpy(&acm->line, &newline, sizeof newline);
  721. dev_dbg(&acm->control->dev, "%s - set line: %d %d %d %d\n",
  722. __func__,
  723. le32_to_cpu(newline.dwDTERate),
  724. newline.bCharFormat, newline.bParityType,
  725. newline.bDataBits);
  726. acm_set_line(acm, &acm->line);
  727. }
  728. }
  729. static const struct tty_port_operations acm_port_ops = {
  730. .shutdown = acm_port_shutdown,
  731. .activate = acm_port_activate,
  732. .destruct = acm_port_destruct,
  733. };
  734. /*
  735. * USB probe and disconnect routines.
  736. */
  737. /* Little helpers: write/read buffers free */
  738. static void acm_write_buffers_free(struct acm *acm)
  739. {
  740. int i;
  741. struct acm_wb *wb;
  742. struct usb_device *usb_dev = interface_to_usbdev(acm->control);
  743. for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++)
  744. usb_free_coherent(usb_dev, acm->writesize, wb->buf, wb->dmah);
  745. }
  746. static void acm_read_buffers_free(struct acm *acm)
  747. {
  748. struct usb_device *usb_dev = interface_to_usbdev(acm->control);
  749. int i;
  750. for (i = 0; i < acm->rx_buflimit; i++)
  751. usb_free_coherent(usb_dev, acm->readsize,
  752. acm->read_buffers[i].base, acm->read_buffers[i].dma);
  753. }
  754. /* Little helper: write buffers allocate */
  755. static int acm_write_buffers_alloc(struct acm *acm)
  756. {
  757. int i;
  758. struct acm_wb *wb;
  759. for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) {
  760. wb->buf = usb_alloc_coherent(acm->dev, acm->writesize, GFP_KERNEL,
  761. &wb->dmah);
  762. if (!wb->buf) {
  763. while (i != 0) {
  764. --i;
  765. --wb;
  766. usb_free_coherent(acm->dev, acm->writesize,
  767. wb->buf, wb->dmah);
  768. }
  769. return -ENOMEM;
  770. }
  771. }
  772. return 0;
  773. }
  774. static int acm_probe(struct usb_interface *intf,
  775. const struct usb_device_id *id)
  776. {
  777. struct usb_cdc_union_desc *union_header = NULL;
  778. struct usb_cdc_country_functional_desc *cfd = NULL;
  779. unsigned char *buffer = intf->altsetting->extra;
  780. int buflen = intf->altsetting->extralen;
  781. struct usb_interface *control_interface;
  782. struct usb_interface *data_interface;
  783. struct usb_endpoint_descriptor *epctrl = NULL;
  784. struct usb_endpoint_descriptor *epread = NULL;
  785. struct usb_endpoint_descriptor *epwrite = NULL;
  786. struct usb_device *usb_dev = interface_to_usbdev(intf);
  787. struct acm *acm;
  788. int minor;
  789. int ctrlsize, readsize;
  790. u8 *buf;
  791. u8 ac_management_function = 0;
  792. u8 call_management_function = 0;
  793. int call_interface_num = -1;
  794. int data_interface_num = -1;
  795. unsigned long quirks;
  796. int num_rx_buf;
  797. int i;
  798. int combined_interfaces = 0;
  799. /* normal quirks */
  800. quirks = (unsigned long)id->driver_info;
  801. num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR;
  802. /* handle quirks deadly to normal probing*/
  803. if (quirks == NO_UNION_NORMAL) {
  804. data_interface = usb_ifnum_to_if(usb_dev, 1);
  805. control_interface = usb_ifnum_to_if(usb_dev, 0);
  806. goto skip_normal_probe;
  807. }
  808. /* normal probing*/
  809. if (!buffer) {
  810. dev_err(&intf->dev, "Weird descriptor references\n");
  811. return -EINVAL;
  812. }
  813. if (!buflen) {
  814. if (intf->cur_altsetting->endpoint &&
  815. intf->cur_altsetting->endpoint->extralen &&
  816. intf->cur_altsetting->endpoint->extra) {
  817. dev_dbg(&intf->dev,
  818. "Seeking extra descriptors on endpoint\n");
  819. buflen = intf->cur_altsetting->endpoint->extralen;
  820. buffer = intf->cur_altsetting->endpoint->extra;
  821. } else {
  822. dev_err(&intf->dev,
  823. "Zero length descriptor references\n");
  824. return -EINVAL;
  825. }
  826. }
  827. while (buflen > 0) {
  828. if (buffer[1] != USB_DT_CS_INTERFACE) {
  829. dev_err(&intf->dev, "skipping garbage\n");
  830. goto next_desc;
  831. }
  832. switch (buffer[2]) {
  833. case USB_CDC_UNION_TYPE: /* we've found it */
  834. if (union_header) {
  835. dev_err(&intf->dev, "More than one "
  836. "union descriptor, skipping ...\n");
  837. goto next_desc;
  838. }
  839. union_header = (struct usb_cdc_union_desc *)buffer;
  840. break;
  841. case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/
  842. cfd = (struct usb_cdc_country_functional_desc *)buffer;
  843. break;
  844. case USB_CDC_HEADER_TYPE: /* maybe check version */
  845. break; /* for now we ignore it */
  846. case USB_CDC_ACM_TYPE:
  847. ac_management_function = buffer[3];
  848. break;
  849. case USB_CDC_CALL_MANAGEMENT_TYPE:
  850. call_management_function = buffer[3];
  851. call_interface_num = buffer[4];
  852. if ((quirks & NOT_A_MODEM) == 0 && (call_management_function & 3) != 3)
  853. dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n");
  854. break;
  855. default:
  856. /* there are LOTS more CDC descriptors that
  857. * could legitimately be found here.
  858. */
  859. dev_dbg(&intf->dev, "Ignoring descriptor: "
  860. "type %02x, length %d\n",
  861. buffer[2], buffer[0]);
  862. break;
  863. }
  864. next_desc:
  865. buflen -= buffer[0];
  866. buffer += buffer[0];
  867. }
  868. if (!union_header) {
  869. if (call_interface_num > 0) {
  870. dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n");
  871. /* quirks for Droids MuIn LCD */
  872. if (quirks & NO_DATA_INTERFACE)
  873. data_interface = usb_ifnum_to_if(usb_dev, 0);
  874. else
  875. data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num));
  876. control_interface = intf;
  877. } else {
  878. if (intf->cur_altsetting->desc.bNumEndpoints != 3) {
  879. dev_dbg(&intf->dev,"No union descriptor, giving up\n");
  880. return -ENODEV;
  881. } else {
  882. dev_warn(&intf->dev,"No union descriptor, testing for castrated device\n");
  883. combined_interfaces = 1;
  884. control_interface = data_interface = intf;
  885. goto look_for_collapsed_interface;
  886. }
  887. }
  888. } else {
  889. control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0);
  890. data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0));
  891. if (!control_interface || !data_interface) {
  892. dev_dbg(&intf->dev, "no interfaces\n");
  893. return -ENODEV;
  894. }
  895. }
  896. if (data_interface_num != call_interface_num)
  897. dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n");
  898. if (control_interface == data_interface) {
  899. /* some broken devices designed for windows work this way */
  900. dev_warn(&intf->dev,"Control and data interfaces are not separated!\n");
  901. combined_interfaces = 1;
  902. /* a popular other OS doesn't use it */
  903. quirks |= NO_CAP_LINE;
  904. if (data_interface->cur_altsetting->desc.bNumEndpoints != 3) {
  905. dev_err(&intf->dev, "This needs exactly 3 endpoints\n");
  906. return -EINVAL;
  907. }
  908. look_for_collapsed_interface:
  909. for (i = 0; i < 3; i++) {
  910. struct usb_endpoint_descriptor *ep;
  911. ep = &data_interface->cur_altsetting->endpoint[i].desc;
  912. if (usb_endpoint_is_int_in(ep))
  913. epctrl = ep;
  914. else if (usb_endpoint_is_bulk_out(ep))
  915. epwrite = ep;
  916. else if (usb_endpoint_is_bulk_in(ep))
  917. epread = ep;
  918. else
  919. return -EINVAL;
  920. }
  921. if (!epctrl || !epread || !epwrite)
  922. return -ENODEV;
  923. else
  924. goto made_compressed_probe;
  925. }
  926. skip_normal_probe:
  927. /*workaround for switched interfaces */
  928. if (data_interface->cur_altsetting->desc.bInterfaceClass
  929. != CDC_DATA_INTERFACE_TYPE) {
  930. if (control_interface->cur_altsetting->desc.bInterfaceClass
  931. == CDC_DATA_INTERFACE_TYPE) {
  932. struct usb_interface *t;
  933. dev_dbg(&intf->dev,
  934. "Your device has switched interfaces.\n");
  935. t = control_interface;
  936. control_interface = data_interface;
  937. data_interface = t;
  938. } else {
  939. return -EINVAL;
  940. }
  941. }
  942. /* Accept probe requests only for the control interface */
  943. if (!combined_interfaces && intf != control_interface)
  944. return -ENODEV;
  945. if (!combined_interfaces && usb_interface_claimed(data_interface)) {
  946. /* valid in this context */
  947. dev_dbg(&intf->dev, "The data interface isn't available\n");
  948. return -EBUSY;
  949. }
  950. if (data_interface->cur_altsetting->desc.bNumEndpoints < 2 ||
  951. control_interface->cur_altsetting->desc.bNumEndpoints == 0)
  952. return -EINVAL;
  953. epctrl = &control_interface->cur_altsetting->endpoint[0].desc;
  954. epread = &data_interface->cur_altsetting->endpoint[0].desc;
  955. epwrite = &data_interface->cur_altsetting->endpoint[1].desc;
  956. /* workaround for switched endpoints */
  957. if (!usb_endpoint_dir_in(epread)) {
  958. /* descriptors are swapped */
  959. struct usb_endpoint_descriptor *t;
  960. dev_dbg(&intf->dev,
  961. "The data interface has switched endpoints\n");
  962. t = epread;
  963. epread = epwrite;
  964. epwrite = t;
  965. }
  966. made_compressed_probe:
  967. dev_dbg(&intf->dev, "interfaces are valid\n");
  968. acm = kzalloc(sizeof(struct acm), GFP_KERNEL);
  969. if (acm == NULL) {
  970. dev_err(&intf->dev, "out of memory (acm kzalloc)\n");
  971. goto alloc_fail;
  972. }
  973. minor = acm_alloc_minor(acm);
  974. if (minor == ACM_TTY_MINORS) {
  975. dev_err(&intf->dev, "no more free acm devices\n");
  976. kfree(acm);
  977. return -ENODEV;
  978. }
  979. ctrlsize = usb_endpoint_maxp(epctrl);
  980. readsize = usb_endpoint_maxp(epread) *
  981. (quirks == SINGLE_RX_URB ? 1 : 2);
  982. acm->combined_interfaces = combined_interfaces;
  983. acm->writesize = usb_endpoint_maxp(epwrite) * 20;
  984. acm->control = control_interface;
  985. acm->data = data_interface;
  986. acm->minor = minor;
  987. acm->dev = usb_dev;
  988. acm->ctrl_caps = ac_management_function;
  989. if (quirks & NO_CAP_LINE)
  990. acm->ctrl_caps &= ~USB_CDC_CAP_LINE;
  991. acm->ctrlsize = ctrlsize;
  992. acm->readsize = readsize;
  993. acm->rx_buflimit = num_rx_buf;
  994. INIT_WORK(&acm->work, acm_softint);
  995. spin_lock_init(&acm->write_lock);
  996. spin_lock_init(&acm->read_lock);
  997. mutex_init(&acm->mutex);
  998. acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress);
  999. acm->is_int_ep = usb_endpoint_xfer_int(epread);
  1000. if (acm->is_int_ep)
  1001. acm->bInterval = epread->bInterval;
  1002. tty_port_init(&acm->port);
  1003. acm->port.ops = &acm_port_ops;
  1004. buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
  1005. if (!buf) {
  1006. dev_err(&intf->dev, "out of memory (ctrl buffer alloc)\n");
  1007. goto alloc_fail2;
  1008. }
  1009. acm->ctrl_buffer = buf;
  1010. if (acm_write_buffers_alloc(acm) < 0) {
  1011. dev_err(&intf->dev, "out of memory (write buffer alloc)\n");
  1012. goto alloc_fail4;
  1013. }
  1014. acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);
  1015. if (!acm->ctrlurb) {
  1016. dev_err(&intf->dev, "out of memory (ctrlurb kmalloc)\n");
  1017. goto alloc_fail5;
  1018. }
  1019. for (i = 0; i < num_rx_buf; i++) {
  1020. struct acm_rb *rb = &(acm->read_buffers[i]);
  1021. struct urb *urb;
  1022. rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL,
  1023. &rb->dma);
  1024. if (!rb->base) {
  1025. dev_err(&intf->dev, "out of memory "
  1026. "(read bufs usb_alloc_coherent)\n");
  1027. goto alloc_fail6;
  1028. }
  1029. rb->index = i;
  1030. rb->instance = acm;
  1031. urb = usb_alloc_urb(0, GFP_KERNEL);
  1032. if (!urb) {
  1033. dev_err(&intf->dev,
  1034. "out of memory (read urbs usb_alloc_urb)\n");
  1035. goto alloc_fail6;
  1036. }
  1037. urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1038. urb->transfer_dma = rb->dma;
  1039. if (acm->is_int_ep) {
  1040. usb_fill_int_urb(urb, acm->dev,
  1041. acm->rx_endpoint,
  1042. rb->base,
  1043. acm->readsize,
  1044. acm_read_bulk_callback, rb,
  1045. acm->bInterval);
  1046. } else {
  1047. usb_fill_bulk_urb(urb, acm->dev,
  1048. acm->rx_endpoint,
  1049. rb->base,
  1050. acm->readsize,
  1051. acm_read_bulk_callback, rb);
  1052. }
  1053. acm->read_urbs[i] = urb;
  1054. __set_bit(i, &acm->read_urbs_free);
  1055. }
  1056. for (i = 0; i < ACM_NW; i++) {
  1057. struct acm_wb *snd = &(acm->wb[i]);
  1058. snd->urb = usb_alloc_urb(0, GFP_KERNEL);
  1059. if (snd->urb == NULL) {
  1060. dev_err(&intf->dev,
  1061. "out of memory (write urbs usb_alloc_urb)\n");
  1062. goto alloc_fail7;
  1063. }
  1064. if (usb_endpoint_xfer_int(epwrite))
  1065. usb_fill_int_urb(snd->urb, usb_dev,
  1066. usb_sndintpipe(usb_dev, epwrite->bEndpointAddress),
  1067. NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval);
  1068. else
  1069. usb_fill_bulk_urb(snd->urb, usb_dev,
  1070. usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
  1071. NULL, acm->writesize, acm_write_bulk, snd);
  1072. snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1073. snd->instance = acm;
  1074. }
  1075. usb_set_intfdata(intf, acm);
  1076. i = device_create_file(&intf->dev, &dev_attr_bmCapabilities);
  1077. if (i < 0)
  1078. goto alloc_fail7;
  1079. if (cfd) { /* export the country data */
  1080. acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL);
  1081. if (!acm->country_codes)
  1082. goto skip_countries;
  1083. acm->country_code_size = cfd->bLength - 4;
  1084. memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0,
  1085. cfd->bLength - 4);
  1086. acm->country_rel_date = cfd->iCountryCodeRelDate;
  1087. i = device_create_file(&intf->dev, &dev_attr_wCountryCodes);
  1088. if (i < 0) {
  1089. kfree(acm->country_codes);
  1090. acm->country_codes = NULL;
  1091. acm->country_code_size = 0;
  1092. goto skip_countries;
  1093. }
  1094. i = device_create_file(&intf->dev,
  1095. &dev_attr_iCountryCodeRelDate);
  1096. if (i < 0) {
  1097. device_remove_file(&intf->dev, &dev_attr_wCountryCodes);
  1098. kfree(acm->country_codes);
  1099. acm->country_codes = NULL;
  1100. acm->country_code_size = 0;
  1101. goto skip_countries;
  1102. }
  1103. }
  1104. skip_countries:
  1105. usb_fill_int_urb(acm->ctrlurb, usb_dev,
  1106. usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress),
  1107. acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm,
  1108. /* works around buggy devices */
  1109. epctrl->bInterval ? epctrl->bInterval : 0xff);
  1110. acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1111. acm->ctrlurb->transfer_dma = acm->ctrl_dma;
  1112. dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor);
  1113. acm_set_control(acm, acm->ctrlout);
  1114. acm->line.dwDTERate = cpu_to_le32(9600);
  1115. acm->line.bDataBits = 8;
  1116. acm_set_line(acm, &acm->line);
  1117. usb_driver_claim_interface(&acm_driver, data_interface, acm);
  1118. usb_set_intfdata(data_interface, acm);
  1119. usb_get_intf(control_interface);
  1120. tty_port_register_device(&acm->port, acm_tty_driver, minor,
  1121. &control_interface->dev);
  1122. return 0;
  1123. alloc_fail7:
  1124. for (i = 0; i < ACM_NW; i++)
  1125. usb_free_urb(acm->wb[i].urb);
  1126. alloc_fail6:
  1127. for (i = 0; i < num_rx_buf; i++)
  1128. usb_free_urb(acm->read_urbs[i]);
  1129. acm_read_buffers_free(acm);
  1130. usb_free_urb(acm->ctrlurb);
  1131. alloc_fail5:
  1132. acm_write_buffers_free(acm);
  1133. alloc_fail4:
  1134. usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
  1135. alloc_fail2:
  1136. acm_release_minor(acm);
  1137. kfree(acm);
  1138. alloc_fail:
  1139. return -ENOMEM;
  1140. }
  1141. static void stop_data_traffic(struct acm *acm)
  1142. {
  1143. int i;
  1144. dev_dbg(&acm->control->dev, "%s\n", __func__);
  1145. usb_kill_urb(acm->ctrlurb);
  1146. for (i = 0; i < ACM_NW; i++)
  1147. usb_kill_urb(acm->wb[i].urb);
  1148. for (i = 0; i < acm->rx_buflimit; i++)
  1149. usb_kill_urb(acm->read_urbs[i]);
  1150. cancel_work_sync(&acm->work);
  1151. }
  1152. static void acm_disconnect(struct usb_interface *intf)
  1153. {
  1154. struct acm *acm = usb_get_intfdata(intf);
  1155. struct usb_device *usb_dev = interface_to_usbdev(intf);
  1156. struct tty_struct *tty;
  1157. int i;
  1158. dev_dbg(&intf->dev, "%s\n", __func__);
  1159. /* sibling interface is already cleaning up */
  1160. if (!acm)
  1161. return;
  1162. mutex_lock(&acm->mutex);
  1163. acm->disconnected = true;
  1164. if (acm->country_codes) {
  1165. device_remove_file(&acm->control->dev,
  1166. &dev_attr_wCountryCodes);
  1167. device_remove_file(&acm->control->dev,
  1168. &dev_attr_iCountryCodeRelDate);
  1169. }
  1170. device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities);
  1171. usb_set_intfdata(acm->control, NULL);
  1172. usb_set_intfdata(acm->data, NULL);
  1173. mutex_unlock(&acm->mutex);
  1174. tty = tty_port_tty_get(&acm->port);
  1175. if (tty) {
  1176. tty_vhangup(tty);
  1177. tty_kref_put(tty);
  1178. }
  1179. stop_data_traffic(acm);
  1180. usb_free_urb(acm->ctrlurb);
  1181. for (i = 0; i < ACM_NW; i++)
  1182. usb_free_urb(acm->wb[i].urb);
  1183. for (i = 0; i < acm->rx_buflimit; i++)
  1184. usb_free_urb(acm->read_urbs[i]);
  1185. acm_write_buffers_free(acm);
  1186. usb_free_coherent(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
  1187. acm_read_buffers_free(acm);
  1188. if (!acm->combined_interfaces)
  1189. usb_driver_release_interface(&acm_driver, intf == acm->control ?
  1190. acm->data : acm->control);
  1191. tty_port_put(&acm->port);
  1192. }
  1193. #ifdef CONFIG_PM
  1194. static int acm_suspend(struct usb_interface *intf, pm_message_t message)
  1195. {
  1196. struct acm *acm = usb_get_intfdata(intf);
  1197. int cnt;
  1198. if (PMSG_IS_AUTO(message)) {
  1199. int b;
  1200. spin_lock_irq(&acm->write_lock);
  1201. b = acm->transmitting;
  1202. spin_unlock_irq(&acm->write_lock);
  1203. if (b)
  1204. return -EBUSY;
  1205. }
  1206. spin_lock_irq(&acm->read_lock);
  1207. spin_lock(&acm->write_lock);
  1208. cnt = acm->susp_count++;
  1209. spin_unlock(&acm->write_lock);
  1210. spin_unlock_irq(&acm->read_lock);
  1211. if (cnt)
  1212. return 0;
  1213. if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags))
  1214. stop_data_traffic(acm);
  1215. return 0;
  1216. }
  1217. static int acm_resume(struct usb_interface *intf)
  1218. {
  1219. struct acm *acm = usb_get_intfdata(intf);
  1220. struct acm_wb *wb;
  1221. int rv = 0;
  1222. int cnt;
  1223. spin_lock_irq(&acm->read_lock);
  1224. acm->susp_count -= 1;
  1225. cnt = acm->susp_count;
  1226. spin_unlock_irq(&acm->read_lock);
  1227. if (cnt)
  1228. return 0;
  1229. if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) {
  1230. rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO);
  1231. spin_lock_irq(&acm->write_lock);
  1232. if (acm->delayed_wb) {
  1233. wb = acm->delayed_wb;
  1234. acm->delayed_wb = NULL;
  1235. spin_unlock_irq(&acm->write_lock);
  1236. acm_start_wb(acm, wb);
  1237. } else {
  1238. spin_unlock_irq(&acm->write_lock);
  1239. }
  1240. /*
  1241. * delayed error checking because we must
  1242. * do the write path at all cost
  1243. */
  1244. if (rv < 0)
  1245. goto err_out;
  1246. rv = acm_submit_read_urbs(acm, GFP_NOIO);
  1247. }
  1248. err_out:
  1249. return rv;
  1250. }
  1251. static int acm_reset_resume(struct usb_interface *intf)
  1252. {
  1253. struct acm *acm = usb_get_intfdata(intf);
  1254. struct tty_struct *tty;
  1255. if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) {
  1256. tty = tty_port_tty_get(&acm->port);
  1257. if (tty) {
  1258. tty_hangup(tty);
  1259. tty_kref_put(tty);
  1260. }
  1261. }
  1262. return acm_resume(intf);
  1263. }
  1264. #endif /* CONFIG_PM */
  1265. #define NOKIA_PCSUITE_ACM_INFO(x) \
  1266. USB_DEVICE_AND_INTERFACE_INFO(0x0421, x, \
  1267. USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \
  1268. USB_CDC_ACM_PROTO_VENDOR)
  1269. #define SAMSUNG_PCSUITE_ACM_INFO(x) \
  1270. USB_DEVICE_AND_INTERFACE_INFO(0x04e7, x, \
  1271. USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \
  1272. USB_CDC_ACM_PROTO_VENDOR)
  1273. /*
  1274. * USB driver structure.
  1275. */
  1276. static const struct usb_device_id acm_ids[] = {
  1277. /* quirky and broken devices */
  1278. { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */
  1279. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1280. },
  1281. { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */
  1282. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1283. },
  1284. { USB_DEVICE(0x0e8d, 0x3329), /* MediaTek Inc GPS */
  1285. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1286. },
  1287. { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */
  1288. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1289. },
  1290. { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */
  1291. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1292. },
  1293. { USB_DEVICE(0x0ace, 0x1602), /* ZyDAS 56K USB MODEM */
  1294. .driver_info = SINGLE_RX_URB,
  1295. },
  1296. { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */
  1297. .driver_info = SINGLE_RX_URB, /* firmware bug */
  1298. },
  1299. { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
  1300. .driver_info = SINGLE_RX_URB, /* firmware bug */
  1301. },
  1302. { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
  1303. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1304. },
  1305. { USB_DEVICE(0x0803, 0x3095), /* Zoom Telephonics Model 3095F USB MODEM */
  1306. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1307. },
  1308. { USB_DEVICE(0x0572, 0x1321), /* Conexant USB MODEM CX93010 */
  1309. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1310. },
  1311. { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */
  1312. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1313. },
  1314. { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */
  1315. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1316. },
  1317. { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */
  1318. },
  1319. /* Motorola H24 HSPA module: */
  1320. { USB_DEVICE(0x22b8, 0x2d91) }, /* modem */
  1321. { USB_DEVICE(0x22b8, 0x2d92) }, /* modem + diagnostics */
  1322. { USB_DEVICE(0x22b8, 0x2d93) }, /* modem + AT port */
  1323. { USB_DEVICE(0x22b8, 0x2d95) }, /* modem + AT port + diagnostics */
  1324. { USB_DEVICE(0x22b8, 0x2d96) }, /* modem + NMEA */
  1325. { USB_DEVICE(0x22b8, 0x2d97) }, /* modem + diagnostics + NMEA */
  1326. { USB_DEVICE(0x22b8, 0x2d99) }, /* modem + AT port + NMEA */
  1327. { USB_DEVICE(0x22b8, 0x2d9a) }, /* modem + AT port + diagnostics + NMEA */
  1328. { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */
  1329. .driver_info = NO_UNION_NORMAL, /* union descriptor misplaced on
  1330. data interface instead of
  1331. communications interface.
  1332. Maybe we should define a new
  1333. quirk for this. */
  1334. },
  1335. { USB_DEVICE(0x0572, 0x1340), /* Conexant CX93010-2x UCMxx */
  1336. .driver_info = NO_UNION_NORMAL,
  1337. },
  1338. { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */
  1339. .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
  1340. },
  1341. { USB_DEVICE(0x1576, 0x03b1), /* Maretron USB100 */
  1342. .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
  1343. },
  1344. /* Nokia S60 phones expose two ACM channels. The first is
  1345. * a modem and is picked up by the standard AT-command
  1346. * information below. The second is 'vendor-specific' but
  1347. * is treated as a serial device at the S60 end, so we want
  1348. * to expose it on Linux too. */
  1349. { NOKIA_PCSUITE_ACM_INFO(0x042D), }, /* Nokia 3250 */
  1350. { NOKIA_PCSUITE_ACM_INFO(0x04D8), }, /* Nokia 5500 Sport */
  1351. { NOKIA_PCSUITE_ACM_INFO(0x04C9), }, /* Nokia E50 */
  1352. { NOKIA_PCSUITE_ACM_INFO(0x0419), }, /* Nokia E60 */
  1353. { NOKIA_PCSUITE_ACM_INFO(0x044D), }, /* Nokia E61 */
  1354. { NOKIA_PCSUITE_ACM_INFO(0x0001), }, /* Nokia E61i */
  1355. { NOKIA_PCSUITE_ACM_INFO(0x0475), }, /* Nokia E62 */
  1356. { NOKIA_PCSUITE_ACM_INFO(0x0508), }, /* Nokia E65 */
  1357. { NOKIA_PCSUITE_ACM_INFO(0x0418), }, /* Nokia E70 */
  1358. { NOKIA_PCSUITE_ACM_INFO(0x0425), }, /* Nokia N71 */
  1359. { NOKIA_PCSUITE_ACM_INFO(0x0486), }, /* Nokia N73 */
  1360. { NOKIA_PCSUITE_ACM_INFO(0x04DF), }, /* Nokia N75 */
  1361. { NOKIA_PCSUITE_ACM_INFO(0x000e), }, /* Nokia N77 */
  1362. { NOKIA_PCSUITE_ACM_INFO(0x0445), }, /* Nokia N80 */
  1363. { NOKIA_PCSUITE_ACM_INFO(0x042F), }, /* Nokia N91 & N91 8GB */
  1364. { NOKIA_PCSUITE_ACM_INFO(0x048E), }, /* Nokia N92 */
  1365. { NOKIA_PCSUITE_ACM_INFO(0x0420), }, /* Nokia N93 */
  1366. { NOKIA_PCSUITE_ACM_INFO(0x04E6), }, /* Nokia N93i */
  1367. { NOKIA_PCSUITE_ACM_INFO(0x04B2), }, /* Nokia 5700 XpressMusic */
  1368. { NOKIA_PCSUITE_ACM_INFO(0x0134), }, /* Nokia 6110 Navigator (China) */
  1369. { NOKIA_PCSUITE_ACM_INFO(0x046E), }, /* Nokia 6110 Navigator */
  1370. { NOKIA_PCSUITE_ACM_INFO(0x002f), }, /* Nokia 6120 classic & */
  1371. { NOKIA_PCSUITE_ACM_INFO(0x0088), }, /* Nokia 6121 classic */
  1372. { NOKIA_PCSUITE_ACM_INFO(0x00fc), }, /* Nokia 6124 classic */
  1373. { NOKIA_PCSUITE_ACM_INFO(0x0042), }, /* Nokia E51 */
  1374. { NOKIA_PCSUITE_ACM_INFO(0x00b0), }, /* Nokia E66 */
  1375. { NOKIA_PCSUITE_ACM_INFO(0x00ab), }, /* Nokia E71 */
  1376. { NOKIA_PCSUITE_ACM_INFO(0x0481), }, /* Nokia N76 */
  1377. { NOKIA_PCSUITE_ACM_INFO(0x0007), }, /* Nokia N81 & N81 8GB */
  1378. { NOKIA_PCSUITE_ACM_INFO(0x0071), }, /* Nokia N82 */
  1379. { NOKIA_PCSUITE_ACM_INFO(0x04F0), }, /* Nokia N95 & N95-3 NAM */
  1380. { NOKIA_PCSUITE_ACM_INFO(0x0070), }, /* Nokia N95 8GB */
  1381. { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */
  1382. { NOKIA_PCSUITE_ACM_INFO(0x0099), }, /* Nokia 6210 Navigator, RM-367 */
  1383. { NOKIA_PCSUITE_ACM_INFO(0x0128), }, /* Nokia 6210 Navigator, RM-419 */
  1384. { NOKIA_PCSUITE_ACM_INFO(0x008f), }, /* Nokia 6220 Classic */
  1385. { NOKIA_PCSUITE_ACM_INFO(0x00a0), }, /* Nokia 6650 */
  1386. { NOKIA_PCSUITE_ACM_INFO(0x007b), }, /* Nokia N78 */
  1387. { NOKIA_PCSUITE_ACM_INFO(0x0094), }, /* Nokia N85 */
  1388. { NOKIA_PCSUITE_ACM_INFO(0x003a), }, /* Nokia N96 & N96-3 */
  1389. { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */
  1390. { NOKIA_PCSUITE_ACM_INFO(0x0108), }, /* Nokia 5320 XpressMusic 2G */
  1391. { NOKIA_PCSUITE_ACM_INFO(0x01f5), }, /* Nokia N97, RM-505 */
  1392. { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */
  1393. { NOKIA_PCSUITE_ACM_INFO(0x0178), }, /* Nokia E63 */
  1394. { NOKIA_PCSUITE_ACM_INFO(0x010e), }, /* Nokia E75 */
  1395. { NOKIA_PCSUITE_ACM_INFO(0x02d9), }, /* Nokia 6760 Slide */
  1396. { NOKIA_PCSUITE_ACM_INFO(0x01d0), }, /* Nokia E52 */
  1397. { NOKIA_PCSUITE_ACM_INFO(0x0223), }, /* Nokia E72 */
  1398. { NOKIA_PCSUITE_ACM_INFO(0x0275), }, /* Nokia X6 */
  1399. { NOKIA_PCSUITE_ACM_INFO(0x026c), }, /* Nokia N97 Mini */
  1400. { NOKIA_PCSUITE_ACM_INFO(0x0154), }, /* Nokia 5800 XpressMusic */
  1401. { NOKIA_PCSUITE_ACM_INFO(0x04ce), }, /* Nokia E90 */
  1402. { NOKIA_PCSUITE_ACM_INFO(0x01d4), }, /* Nokia E55 */
  1403. { NOKIA_PCSUITE_ACM_INFO(0x0302), }, /* Nokia N8 */
  1404. { NOKIA_PCSUITE_ACM_INFO(0x0335), }, /* Nokia E7 */
  1405. { NOKIA_PCSUITE_ACM_INFO(0x03cd), }, /* Nokia C7 */
  1406. { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */
  1407. /* Support for Owen devices */
  1408. { USB_DEVICE(0x03eb, 0x0030), }, /* Owen SI30 */
  1409. /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */
  1410. /* Support Lego NXT using pbLua firmware */
  1411. { USB_DEVICE(0x0694, 0xff00),
  1412. .driver_info = NOT_A_MODEM,
  1413. },
  1414. /* Support for Droids MuIn LCD */
  1415. { USB_DEVICE(0x04d8, 0x000b),
  1416. .driver_info = NO_DATA_INTERFACE,
  1417. },
  1418. /* control interfaces without any protocol set */
  1419. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1420. USB_CDC_PROTO_NONE) },
  1421. /* control interfaces with various AT-command sets */
  1422. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1423. USB_CDC_ACM_PROTO_AT_V25TER) },
  1424. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1425. USB_CDC_ACM_PROTO_AT_PCCA101) },
  1426. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1427. USB_CDC_ACM_PROTO_AT_PCCA101_WAKE) },
  1428. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1429. USB_CDC_ACM_PROTO_AT_GSM) },
  1430. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1431. USB_CDC_ACM_PROTO_AT_3G) },
  1432. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1433. USB_CDC_ACM_PROTO_AT_CDMA) },
  1434. { }
  1435. };
  1436. MODULE_DEVICE_TABLE(usb, acm_ids);
  1437. static struct usb_driver acm_driver = {
  1438. .name = "cdc_acm",
  1439. .probe = acm_probe,
  1440. .disconnect = acm_disconnect,
  1441. #ifdef CONFIG_PM
  1442. .suspend = acm_suspend,
  1443. .resume = acm_resume,
  1444. .reset_resume = acm_reset_resume,
  1445. #endif
  1446. .id_table = acm_ids,
  1447. #ifdef CONFIG_PM
  1448. .supports_autosuspend = 1,
  1449. #endif
  1450. .disable_hub_initiated_lpm = 1,
  1451. };
  1452. /*
  1453. * TTY driver structures.
  1454. */
  1455. static const struct tty_operations acm_ops = {
  1456. .install = acm_tty_install,
  1457. .open = acm_tty_open,
  1458. .close = acm_tty_close,
  1459. .cleanup = acm_tty_cleanup,
  1460. .hangup = acm_tty_hangup,
  1461. .write = acm_tty_write,
  1462. .write_room = acm_tty_write_room,
  1463. .ioctl = acm_tty_ioctl,
  1464. .throttle = acm_tty_throttle,
  1465. .unthrottle = acm_tty_unthrottle,
  1466. .chars_in_buffer = acm_tty_chars_in_buffer,
  1467. .break_ctl = acm_tty_break_ctl,
  1468. .set_termios = acm_tty_set_termios,
  1469. .tiocmget = acm_tty_tiocmget,
  1470. .tiocmset = acm_tty_tiocmset,
  1471. };
  1472. /*
  1473. * Init / exit.
  1474. */
  1475. static int __init acm_init(void)
  1476. {
  1477. int retval;
  1478. acm_tty_driver = alloc_tty_driver(ACM_TTY_MINORS);
  1479. if (!acm_tty_driver)
  1480. return -ENOMEM;
  1481. acm_tty_driver->driver_name = "acm",
  1482. acm_tty_driver->name = "ttyACM",
  1483. acm_tty_driver->major = ACM_TTY_MAJOR,
  1484. acm_tty_driver->minor_start = 0,
  1485. acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL,
  1486. acm_tty_driver->subtype = SERIAL_TYPE_NORMAL,
  1487. acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  1488. acm_tty_driver->init_termios = tty_std_termios;
  1489. acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD |
  1490. HUPCL | CLOCAL;
  1491. tty_set_operations(acm_tty_driver, &acm_ops);
  1492. retval = tty_register_driver(acm_tty_driver);
  1493. if (retval) {
  1494. put_tty_driver(acm_tty_driver);
  1495. return retval;
  1496. }
  1497. retval = usb_register(&acm_driver);
  1498. if (retval) {
  1499. tty_unregister_driver(acm_tty_driver);
  1500. put_tty_driver(acm_tty_driver);
  1501. return retval;
  1502. }
  1503. printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
  1504. return 0;
  1505. }
  1506. static void __exit acm_exit(void)
  1507. {
  1508. usb_deregister(&acm_driver);
  1509. tty_unregister_driver(acm_tty_driver);
  1510. put_tty_driver(acm_tty_driver);
  1511. }
  1512. module_init(acm_init);
  1513. module_exit(acm_exit);
  1514. MODULE_AUTHOR(DRIVER_AUTHOR);
  1515. MODULE_DESCRIPTION(DRIVER_DESC);
  1516. MODULE_LICENSE("GPL");
  1517. MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR);