sierra.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. USB Driver for Sierra Wireless
  3. Copyright (C) 2006 Kevin Lloyd <linux@sierrawireless.com>
  4. IMPORTANT DISCLAIMER: This driver is not commercially supported by
  5. Sierra Wireless. Use at your own risk.
  6. This driver is free software; you can redistribute it and/or modify
  7. it under the terms of Version 2 of the GNU General Public License as
  8. published by the Free Software Foundation.
  9. Portions based on the option driver by Matthias Urlichs <smurf@smurf.noris.de>
  10. Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org>
  11. */
  12. #define DRIVER_VERSION "v.1.0.6"
  13. #define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>"
  14. #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems"
  15. #include <linux/kernel.h>
  16. #include <linux/jiffies.h>
  17. #include <linux/errno.h>
  18. #include <linux/tty.h>
  19. #include <linux/tty_flip.h>
  20. #include <linux/module.h>
  21. #include <linux/usb.h>
  22. #include <linux/usb/serial.h>
  23. static struct usb_device_id id_table [] = {
  24. { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
  25. { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
  26. { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
  27. { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
  28. { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
  29. { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless AirCard 595U */
  30. { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
  31. { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
  32. { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
  33. { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
  34. { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */
  35. { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
  36. { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
  37. { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */
  38. { }
  39. };
  40. MODULE_DEVICE_TABLE(usb, id_table);
  41. static struct usb_device_id id_table_1port [] = {
  42. { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
  43. { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */
  44. { }
  45. };
  46. static struct usb_device_id id_table_3port [] = {
  47. { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
  48. { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
  49. { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
  50. { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
  51. { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
  52. { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless AirCard 595U */
  53. { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
  54. { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
  55. { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
  56. { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
  57. { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */
  58. { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
  59. { }
  60. };
  61. static struct usb_driver sierra_driver = {
  62. .name = "sierra",
  63. .probe = usb_serial_probe,
  64. .disconnect = usb_serial_disconnect,
  65. .id_table = id_table,
  66. .no_dynamic_id = 1,
  67. };
  68. static int debug;
  69. /* per port private data */
  70. #define N_IN_URB 4
  71. #define N_OUT_URB 4
  72. #define IN_BUFLEN 4096
  73. struct sierra_port_private {
  74. spinlock_t lock; /* lock the structure */
  75. int outstanding_urbs; /* number of out urbs in flight */
  76. /* Input endpoints and buffer for this port */
  77. struct urb *in_urbs[N_IN_URB];
  78. char in_buffer[N_IN_URB][IN_BUFLEN];
  79. /* Settings for the port */
  80. int rts_state; /* Handshaking pins (outputs) */
  81. int dtr_state;
  82. int cts_state; /* Handshaking pins (inputs) */
  83. int dsr_state;
  84. int dcd_state;
  85. int ri_state;
  86. };
  87. static int sierra_send_setup(struct usb_serial_port *port)
  88. {
  89. struct usb_serial *serial = port->serial;
  90. struct sierra_port_private *portdata;
  91. dbg("%s", __FUNCTION__);
  92. portdata = usb_get_serial_port_data(port);
  93. if (port->tty) {
  94. int val = 0;
  95. if (portdata->dtr_state)
  96. val |= 0x01;
  97. if (portdata->rts_state)
  98. val |= 0x02;
  99. return usb_control_msg(serial->dev,
  100. usb_rcvctrlpipe(serial->dev, 0),
  101. 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
  102. }
  103. return 0;
  104. }
  105. static void sierra_rx_throttle(struct usb_serial_port *port)
  106. {
  107. dbg("%s", __FUNCTION__);
  108. }
  109. static void sierra_rx_unthrottle(struct usb_serial_port *port)
  110. {
  111. dbg("%s", __FUNCTION__);
  112. }
  113. static void sierra_break_ctl(struct usb_serial_port *port, int break_state)
  114. {
  115. /* Unfortunately, I don't know how to send a break */
  116. dbg("%s", __FUNCTION__);
  117. }
  118. static void sierra_set_termios(struct usb_serial_port *port,
  119. struct ktermios *old_termios)
  120. {
  121. dbg("%s", __FUNCTION__);
  122. sierra_send_setup(port);
  123. }
  124. static int sierra_tiocmget(struct usb_serial_port *port, struct file *file)
  125. {
  126. unsigned int value;
  127. struct sierra_port_private *portdata;
  128. portdata = usb_get_serial_port_data(port);
  129. value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
  130. ((portdata->dtr_state) ? TIOCM_DTR : 0) |
  131. ((portdata->cts_state) ? TIOCM_CTS : 0) |
  132. ((portdata->dsr_state) ? TIOCM_DSR : 0) |
  133. ((portdata->dcd_state) ? TIOCM_CAR : 0) |
  134. ((portdata->ri_state) ? TIOCM_RNG : 0);
  135. return value;
  136. }
  137. static int sierra_tiocmset(struct usb_serial_port *port, struct file *file,
  138. unsigned int set, unsigned int clear)
  139. {
  140. struct sierra_port_private *portdata;
  141. portdata = usb_get_serial_port_data(port);
  142. if (set & TIOCM_RTS)
  143. portdata->rts_state = 1;
  144. if (set & TIOCM_DTR)
  145. portdata->dtr_state = 1;
  146. if (clear & TIOCM_RTS)
  147. portdata->rts_state = 0;
  148. if (clear & TIOCM_DTR)
  149. portdata->dtr_state = 0;
  150. return sierra_send_setup(port);
  151. }
  152. static int sierra_ioctl(struct usb_serial_port *port, struct file *file,
  153. unsigned int cmd, unsigned long arg)
  154. {
  155. return -ENOIOCTLCMD;
  156. }
  157. static void sierra_outdat_callback(struct urb *urb)
  158. {
  159. struct usb_serial_port *port = urb->context;
  160. struct sierra_port_private *portdata = usb_get_serial_port_data(port);
  161. int status = urb->status;
  162. unsigned long flags;
  163. dbg("%s - port %d", __FUNCTION__, port->number);
  164. /* free up the transfer buffer, as usb_free_urb() does not do this */
  165. kfree(urb->transfer_buffer);
  166. if (status)
  167. dbg("%s - nonzero write bulk status received: %d",
  168. __FUNCTION__, status);
  169. spin_lock_irqsave(&portdata->lock, flags);
  170. --portdata->outstanding_urbs;
  171. spin_unlock_irqrestore(&portdata->lock, flags);
  172. usb_serial_port_softint(port);
  173. }
  174. /* Write */
  175. static int sierra_write(struct usb_serial_port *port,
  176. const unsigned char *buf, int count)
  177. {
  178. struct sierra_port_private *portdata = usb_get_serial_port_data(port);
  179. struct usb_serial *serial = port->serial;
  180. unsigned long flags;
  181. unsigned char *buffer;
  182. struct urb *urb;
  183. int status;
  184. portdata = usb_get_serial_port_data(port);
  185. dbg("%s: write (%d chars)", __FUNCTION__, count);
  186. spin_lock_irqsave(&portdata->lock, flags);
  187. if (portdata->outstanding_urbs > N_OUT_URB) {
  188. spin_unlock_irqrestore(&portdata->lock, flags);
  189. dbg("%s - write limit hit\n", __FUNCTION__);
  190. return 0;
  191. }
  192. portdata->outstanding_urbs++;
  193. spin_unlock_irqrestore(&portdata->lock, flags);
  194. buffer = kmalloc(count, GFP_ATOMIC);
  195. if (!buffer) {
  196. dev_err(&port->dev, "out of memory\n");
  197. count = -ENOMEM;
  198. goto error_no_buffer;
  199. }
  200. urb = usb_alloc_urb(0, GFP_ATOMIC);
  201. if (!urb) {
  202. dev_err(&port->dev, "no more free urbs\n");
  203. count = -ENOMEM;
  204. goto error_no_urb;
  205. }
  206. memcpy(buffer, buf, count);
  207. usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buffer);
  208. usb_fill_bulk_urb(urb, serial->dev,
  209. usb_sndbulkpipe(serial->dev,
  210. port->bulk_out_endpointAddress),
  211. buffer, count, sierra_outdat_callback, port);
  212. /* send it down the pipe */
  213. status = usb_submit_urb(urb, GFP_ATOMIC);
  214. if (status) {
  215. dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed "
  216. "with status = %d\n", __FUNCTION__, status);
  217. count = status;
  218. goto error;
  219. }
  220. /* we are done with this urb, so let the host driver
  221. * really free it when it is finished with it */
  222. usb_free_urb(urb);
  223. return count;
  224. error:
  225. usb_free_urb(urb);
  226. error_no_urb:
  227. kfree(buffer);
  228. error_no_buffer:
  229. spin_lock_irqsave(&portdata->lock, flags);
  230. --portdata->outstanding_urbs;
  231. spin_unlock_irqrestore(&portdata->lock, flags);
  232. return count;
  233. }
  234. static void sierra_indat_callback(struct urb *urb)
  235. {
  236. int err;
  237. int endpoint;
  238. struct usb_serial_port *port;
  239. struct tty_struct *tty;
  240. unsigned char *data = urb->transfer_buffer;
  241. int status = urb->status;
  242. dbg("%s: %p", __FUNCTION__, urb);
  243. endpoint = usb_pipeendpoint(urb->pipe);
  244. port = (struct usb_serial_port *) urb->context;
  245. if (status) {
  246. dbg("%s: nonzero status: %d on endpoint %02x.",
  247. __FUNCTION__, status, endpoint);
  248. } else {
  249. tty = port->tty;
  250. if (urb->actual_length) {
  251. tty_buffer_request_room(tty, urb->actual_length);
  252. tty_insert_flip_string(tty, data, urb->actual_length);
  253. tty_flip_buffer_push(tty);
  254. } else {
  255. dbg("%s: empty read urb received", __FUNCTION__);
  256. }
  257. /* Resubmit urb so we continue receiving */
  258. if (port->open_count && status != -ESHUTDOWN) {
  259. err = usb_submit_urb(urb, GFP_ATOMIC);
  260. if (err)
  261. dev_err(&port->dev, "resubmit read urb failed."
  262. "(%d)", err);
  263. }
  264. }
  265. return;
  266. }
  267. static void sierra_instat_callback(struct urb *urb)
  268. {
  269. int err;
  270. int status = urb->status;
  271. struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
  272. struct sierra_port_private *portdata = usb_get_serial_port_data(port);
  273. struct usb_serial *serial = port->serial;
  274. dbg("%s", __FUNCTION__);
  275. dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata);
  276. if (status == 0) {
  277. struct usb_ctrlrequest *req_pkt =
  278. (struct usb_ctrlrequest *)urb->transfer_buffer;
  279. if (!req_pkt) {
  280. dbg("%s: NULL req_pkt\n", __FUNCTION__);
  281. return;
  282. }
  283. if ((req_pkt->bRequestType == 0xA1) &&
  284. (req_pkt->bRequest == 0x20)) {
  285. int old_dcd_state;
  286. unsigned char signals = *((unsigned char *)
  287. urb->transfer_buffer +
  288. sizeof(struct usb_ctrlrequest));
  289. dbg("%s: signal x%x", __FUNCTION__, signals);
  290. old_dcd_state = portdata->dcd_state;
  291. portdata->cts_state = 1;
  292. portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
  293. portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
  294. portdata->ri_state = ((signals & 0x08) ? 1 : 0);
  295. if (port->tty && !C_CLOCAL(port->tty) &&
  296. old_dcd_state && !portdata->dcd_state)
  297. tty_hangup(port->tty);
  298. } else {
  299. dbg("%s: type %x req %x", __FUNCTION__,
  300. req_pkt->bRequestType,req_pkt->bRequest);
  301. }
  302. } else
  303. dbg("%s: error %d", __FUNCTION__, status);
  304. /* Resubmit urb so we continue receiving IRQ data */
  305. if (status != -ESHUTDOWN) {
  306. urb->dev = serial->dev;
  307. err = usb_submit_urb(urb, GFP_ATOMIC);
  308. if (err)
  309. dbg("%s: resubmit intr urb failed. (%d)",
  310. __FUNCTION__, err);
  311. }
  312. }
  313. static int sierra_write_room(struct usb_serial_port *port)
  314. {
  315. struct sierra_port_private *portdata = usb_get_serial_port_data(port);
  316. unsigned long flags;
  317. dbg("%s - port %d", __FUNCTION__, port->number);
  318. /* try to give a good number back based on if we have any free urbs at
  319. * this point in time */
  320. spin_lock_irqsave(&portdata->lock, flags);
  321. if (portdata->outstanding_urbs > N_OUT_URB * 2 / 3) {
  322. spin_unlock_irqrestore(&portdata->lock, flags);
  323. dbg("%s - write limit hit\n", __FUNCTION__);
  324. return 0;
  325. }
  326. spin_unlock_irqrestore(&portdata->lock, flags);
  327. return 2048;
  328. }
  329. static int sierra_chars_in_buffer(struct usb_serial_port *port)
  330. {
  331. dbg("%s - port %d", __FUNCTION__, port->number);
  332. /*
  333. * We can't really account for how much data we
  334. * have sent out, but hasn't made it through to the
  335. * device as we can't see the backend here, so just
  336. * tell the tty layer that everything is flushed.
  337. */
  338. return 0;
  339. }
  340. static int sierra_open(struct usb_serial_port *port, struct file *filp)
  341. {
  342. struct sierra_port_private *portdata;
  343. struct usb_serial *serial = port->serial;
  344. int i;
  345. struct urb *urb;
  346. int result;
  347. __u16 set_mode_dzero = 0x0000;
  348. portdata = usb_get_serial_port_data(port);
  349. dbg("%s", __FUNCTION__);
  350. /* Set some sane defaults */
  351. portdata->rts_state = 1;
  352. portdata->dtr_state = 1;
  353. /* Reset low level data toggle and start reading from endpoints */
  354. for (i = 0; i < N_IN_URB; i++) {
  355. urb = portdata->in_urbs[i];
  356. if (!urb)
  357. continue;
  358. if (urb->dev != serial->dev) {
  359. dbg("%s: dev %p != %p", __FUNCTION__,
  360. urb->dev, serial->dev);
  361. continue;
  362. }
  363. /*
  364. * make sure endpoint data toggle is synchronized with the
  365. * device
  366. */
  367. usb_clear_halt(urb->dev, urb->pipe);
  368. result = usb_submit_urb(urb, GFP_KERNEL);
  369. if (result) {
  370. dev_err(&port->dev, "submit urb %d failed (%d) %d",
  371. i, result, urb->transfer_buffer_length);
  372. }
  373. }
  374. port->tty->low_latency = 1;
  375. /* set mode to D0 */
  376. result = usb_control_msg(serial->dev,
  377. usb_rcvctrlpipe(serial->dev, 0),
  378. 0x00, 0x40, set_mode_dzero, 0, NULL,
  379. 0, USB_CTRL_SET_TIMEOUT);
  380. sierra_send_setup(port);
  381. /* start up the interrupt endpoint if we have one */
  382. if (port->interrupt_in_urb) {
  383. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  384. if (result)
  385. dev_err(&port->dev, "submit irq_in urb failed %d",
  386. result);
  387. }
  388. return 0;
  389. }
  390. static void sierra_close(struct usb_serial_port *port, struct file *filp)
  391. {
  392. int i;
  393. struct usb_serial *serial = port->serial;
  394. struct sierra_port_private *portdata;
  395. dbg("%s", __FUNCTION__);
  396. portdata = usb_get_serial_port_data(port);
  397. portdata->rts_state = 0;
  398. portdata->dtr_state = 0;
  399. if (serial->dev) {
  400. sierra_send_setup(port);
  401. /* Stop reading/writing urbs */
  402. for (i = 0; i < N_IN_URB; i++)
  403. usb_kill_urb(portdata->in_urbs[i]);
  404. }
  405. usb_kill_urb(port->interrupt_in_urb);
  406. port->tty = NULL;
  407. }
  408. static int sierra_startup(struct usb_serial *serial)
  409. {
  410. struct usb_serial_port *port;
  411. struct sierra_port_private *portdata;
  412. struct urb *urb;
  413. int i;
  414. int j;
  415. dbg("%s", __FUNCTION__);
  416. /* Now setup per port private data */
  417. for (i = 0; i < serial->num_ports; i++) {
  418. port = serial->port[i];
  419. portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
  420. if (!portdata) {
  421. dbg("%s: kmalloc for sierra_port_private (%d) failed!.",
  422. __FUNCTION__, i);
  423. return -ENOMEM;
  424. }
  425. spin_lock_init(&portdata->lock);
  426. usb_set_serial_port_data(port, portdata);
  427. /* initialize the in urbs */
  428. for (j = 0; j < N_IN_URB; ++j) {
  429. urb = usb_alloc_urb(0, GFP_KERNEL);
  430. if (urb == NULL) {
  431. dbg("%s: alloc for in port failed.",
  432. __FUNCTION__);
  433. continue;
  434. }
  435. /* Fill URB using supplied data. */
  436. usb_fill_bulk_urb(urb, serial->dev,
  437. usb_rcvbulkpipe(serial->dev,
  438. port->bulk_in_endpointAddress),
  439. portdata->in_buffer[j], IN_BUFLEN,
  440. sierra_indat_callback, port);
  441. portdata->in_urbs[j] = urb;
  442. }
  443. }
  444. return 0;
  445. }
  446. static void sierra_shutdown(struct usb_serial *serial)
  447. {
  448. int i, j;
  449. struct usb_serial_port *port;
  450. struct sierra_port_private *portdata;
  451. dbg("%s", __FUNCTION__);
  452. for (i = 0; i < serial->num_ports; ++i) {
  453. port = serial->port[i];
  454. if (!port)
  455. continue;
  456. portdata = usb_get_serial_port_data(port);
  457. if (!portdata)
  458. continue;
  459. for (j = 0; j < N_IN_URB; j++) {
  460. usb_kill_urb(portdata->in_urbs[j]);
  461. usb_free_urb(portdata->in_urbs[j]);
  462. portdata->in_urbs[j] = NULL;
  463. }
  464. kfree(portdata);
  465. usb_set_serial_port_data(port, NULL);
  466. }
  467. }
  468. static struct usb_serial_driver sierra_1port_device = {
  469. .driver = {
  470. .owner = THIS_MODULE,
  471. .name = "sierra1",
  472. },
  473. .description = "Sierra USB modem (1 port)",
  474. .id_table = id_table_1port,
  475. .usb_driver = &sierra_driver,
  476. .num_interrupt_in = NUM_DONT_CARE,
  477. .num_bulk_in = 1,
  478. .num_bulk_out = 1,
  479. .num_ports = 1,
  480. .open = sierra_open,
  481. .close = sierra_close,
  482. .write = sierra_write,
  483. .write_room = sierra_write_room,
  484. .chars_in_buffer = sierra_chars_in_buffer,
  485. .throttle = sierra_rx_throttle,
  486. .unthrottle = sierra_rx_unthrottle,
  487. .ioctl = sierra_ioctl,
  488. .set_termios = sierra_set_termios,
  489. .break_ctl = sierra_break_ctl,
  490. .tiocmget = sierra_tiocmget,
  491. .tiocmset = sierra_tiocmset,
  492. .attach = sierra_startup,
  493. .shutdown = sierra_shutdown,
  494. .read_int_callback = sierra_instat_callback,
  495. };
  496. static struct usb_serial_driver sierra_3port_device = {
  497. .driver = {
  498. .owner = THIS_MODULE,
  499. .name = "sierra3",
  500. },
  501. .description = "Sierra USB modem (3 port)",
  502. .id_table = id_table_3port,
  503. .usb_driver = &sierra_driver,
  504. .num_interrupt_in = NUM_DONT_CARE,
  505. .num_bulk_in = 3,
  506. .num_bulk_out = 3,
  507. .num_ports = 3,
  508. .open = sierra_open,
  509. .close = sierra_close,
  510. .write = sierra_write,
  511. .write_room = sierra_write_room,
  512. .chars_in_buffer = sierra_chars_in_buffer,
  513. .throttle = sierra_rx_throttle,
  514. .unthrottle = sierra_rx_unthrottle,
  515. .ioctl = sierra_ioctl,
  516. .set_termios = sierra_set_termios,
  517. .break_ctl = sierra_break_ctl,
  518. .tiocmget = sierra_tiocmget,
  519. .tiocmset = sierra_tiocmset,
  520. .attach = sierra_startup,
  521. .shutdown = sierra_shutdown,
  522. .read_int_callback = sierra_instat_callback,
  523. };
  524. /* Functions used by new usb-serial code. */
  525. static int __init sierra_init(void)
  526. {
  527. int retval;
  528. retval = usb_serial_register(&sierra_1port_device);
  529. if (retval)
  530. goto failed_1port_device_register;
  531. retval = usb_serial_register(&sierra_3port_device);
  532. if (retval)
  533. goto failed_3port_device_register;
  534. retval = usb_register(&sierra_driver);
  535. if (retval)
  536. goto failed_driver_register;
  537. info(DRIVER_DESC ": " DRIVER_VERSION);
  538. return 0;
  539. failed_driver_register:
  540. usb_serial_deregister(&sierra_3port_device);
  541. failed_3port_device_register:
  542. usb_serial_deregister(&sierra_1port_device);
  543. failed_1port_device_register:
  544. return retval;
  545. }
  546. static void __exit sierra_exit(void)
  547. {
  548. usb_deregister (&sierra_driver);
  549. usb_serial_deregister(&sierra_1port_device);
  550. usb_serial_deregister(&sierra_3port_device);
  551. }
  552. module_init(sierra_init);
  553. module_exit(sierra_exit);
  554. MODULE_AUTHOR(DRIVER_AUTHOR);
  555. MODULE_DESCRIPTION(DRIVER_DESC);
  556. MODULE_VERSION(DRIVER_VERSION);
  557. MODULE_LICENSE("GPL");
  558. #ifdef CONFIG_USB_DEBUG
  559. module_param(debug, bool, S_IRUGO | S_IWUSR);
  560. MODULE_PARM_DESC(debug, "Debug messages");
  561. #endif