cdc-acm.c 51 KB

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