cdc-acm.c 48 KB

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