cdc-acm.c 48 KB

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