cdc-acm.c 48 KB

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