cdc-acm.c 51 KB

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