cdc-acm.c 51 KB

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