cdc-acm.c 47 KB

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