cdc-acm.c 50 KB

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