sierra.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. #define OUT_BUFLEN 128
  74. struct sierra_port_private {
  75. /* Input endpoints and buffer for this port */
  76. struct urb *in_urbs[N_IN_URB];
  77. char in_buffer[N_IN_URB][IN_BUFLEN];
  78. /* Output endpoints and buffer for this port */
  79. struct urb *out_urbs[N_OUT_URB];
  80. char out_buffer[N_OUT_URB][OUT_BUFLEN];
  81. /* Settings for the port */
  82. int rts_state; /* Handshaking pins (outputs) */
  83. int dtr_state;
  84. int cts_state; /* Handshaking pins (inputs) */
  85. int dsr_state;
  86. int dcd_state;
  87. int ri_state;
  88. unsigned long tx_start_time[N_OUT_URB];
  89. };
  90. static int sierra_send_setup(struct usb_serial_port *port)
  91. {
  92. struct usb_serial *serial = port->serial;
  93. struct sierra_port_private *portdata;
  94. dbg("%s", __FUNCTION__);
  95. portdata = usb_get_serial_port_data(port);
  96. if (port->tty) {
  97. int val = 0;
  98. if (portdata->dtr_state)
  99. val |= 0x01;
  100. if (portdata->rts_state)
  101. val |= 0x02;
  102. return usb_control_msg(serial->dev,
  103. usb_rcvctrlpipe(serial->dev, 0),
  104. 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
  105. }
  106. return 0;
  107. }
  108. static void sierra_rx_throttle(struct usb_serial_port *port)
  109. {
  110. dbg("%s", __FUNCTION__);
  111. }
  112. static void sierra_rx_unthrottle(struct usb_serial_port *port)
  113. {
  114. dbg("%s", __FUNCTION__);
  115. }
  116. static void sierra_break_ctl(struct usb_serial_port *port, int break_state)
  117. {
  118. /* Unfortunately, I don't know how to send a break */
  119. dbg("%s", __FUNCTION__);
  120. }
  121. static void sierra_set_termios(struct usb_serial_port *port,
  122. struct ktermios *old_termios)
  123. {
  124. dbg("%s", __FUNCTION__);
  125. sierra_send_setup(port);
  126. }
  127. static int sierra_tiocmget(struct usb_serial_port *port, struct file *file)
  128. {
  129. unsigned int value;
  130. struct sierra_port_private *portdata;
  131. portdata = usb_get_serial_port_data(port);
  132. value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
  133. ((portdata->dtr_state) ? TIOCM_DTR : 0) |
  134. ((portdata->cts_state) ? TIOCM_CTS : 0) |
  135. ((portdata->dsr_state) ? TIOCM_DSR : 0) |
  136. ((portdata->dcd_state) ? TIOCM_CAR : 0) |
  137. ((portdata->ri_state) ? TIOCM_RNG : 0);
  138. return value;
  139. }
  140. static int sierra_tiocmset(struct usb_serial_port *port, struct file *file,
  141. unsigned int set, unsigned int clear)
  142. {
  143. struct sierra_port_private *portdata;
  144. portdata = usb_get_serial_port_data(port);
  145. if (set & TIOCM_RTS)
  146. portdata->rts_state = 1;
  147. if (set & TIOCM_DTR)
  148. portdata->dtr_state = 1;
  149. if (clear & TIOCM_RTS)
  150. portdata->rts_state = 0;
  151. if (clear & TIOCM_DTR)
  152. portdata->dtr_state = 0;
  153. return sierra_send_setup(port);
  154. }
  155. static int sierra_ioctl(struct usb_serial_port *port, struct file *file,
  156. unsigned int cmd, unsigned long arg)
  157. {
  158. return -ENOIOCTLCMD;
  159. }
  160. /* Write */
  161. static int sierra_write(struct usb_serial_port *port,
  162. const unsigned char *buf, int count)
  163. {
  164. struct sierra_port_private *portdata;
  165. int i;
  166. int left, todo;
  167. struct urb *this_urb = NULL; /* spurious */
  168. int err;
  169. portdata = usb_get_serial_port_data(port);
  170. dbg("%s: write (%d chars)", __FUNCTION__, count);
  171. i = 0;
  172. left = count;
  173. for (i=0; left > 0 && i < N_OUT_URB; i++) {
  174. todo = left;
  175. if (todo > OUT_BUFLEN)
  176. todo = OUT_BUFLEN;
  177. this_urb = portdata->out_urbs[i];
  178. if (this_urb->status == -EINPROGRESS) {
  179. if (time_before(jiffies,
  180. portdata->tx_start_time[i] + 10 * HZ))
  181. continue;
  182. usb_unlink_urb(this_urb);
  183. continue;
  184. }
  185. if (this_urb->status != 0)
  186. dbg("usb_write %p failed (err=%d)",
  187. this_urb, this_urb->status);
  188. dbg("%s: endpoint %d buf %d", __FUNCTION__,
  189. usb_pipeendpoint(this_urb->pipe), i);
  190. /* send the data */
  191. memcpy (this_urb->transfer_buffer, buf, todo);
  192. this_urb->transfer_buffer_length = todo;
  193. this_urb->dev = port->serial->dev;
  194. err = usb_submit_urb(this_urb, GFP_ATOMIC);
  195. if (err) {
  196. dbg("usb_submit_urb %p (write bulk) failed "
  197. "(%d, has %d)", this_urb,
  198. err, this_urb->status);
  199. continue;
  200. }
  201. portdata->tx_start_time[i] = jiffies;
  202. buf += todo;
  203. left -= todo;
  204. }
  205. count -= left;
  206. dbg("%s: wrote (did %d)", __FUNCTION__, count);
  207. return count;
  208. }
  209. static void sierra_indat_callback(struct urb *urb)
  210. {
  211. int err;
  212. int endpoint;
  213. struct usb_serial_port *port;
  214. struct tty_struct *tty;
  215. unsigned char *data = urb->transfer_buffer;
  216. int status = urb->status;
  217. dbg("%s: %p", __FUNCTION__, urb);
  218. endpoint = usb_pipeendpoint(urb->pipe);
  219. port = (struct usb_serial_port *) urb->context;
  220. if (status) {
  221. dbg("%s: nonzero status: %d on endpoint %02x.",
  222. __FUNCTION__, status, endpoint);
  223. } else {
  224. tty = port->tty;
  225. if (urb->actual_length) {
  226. tty_buffer_request_room(tty, urb->actual_length);
  227. tty_insert_flip_string(tty, data, urb->actual_length);
  228. tty_flip_buffer_push(tty);
  229. } else {
  230. dbg("%s: empty read urb received", __FUNCTION__);
  231. }
  232. /* Resubmit urb so we continue receiving */
  233. if (port->open_count && status != -ESHUTDOWN) {
  234. err = usb_submit_urb(urb, GFP_ATOMIC);
  235. if (err)
  236. printk(KERN_ERR "%s: resubmit read urb failed. "
  237. "(%d)", __FUNCTION__, err);
  238. }
  239. }
  240. return;
  241. }
  242. static void sierra_outdat_callback(struct urb *urb)
  243. {
  244. struct usb_serial_port *port;
  245. dbg("%s", __FUNCTION__);
  246. port = (struct usb_serial_port *) urb->context;
  247. usb_serial_port_softint(port);
  248. }
  249. static void sierra_instat_callback(struct urb *urb)
  250. {
  251. int err;
  252. int status = urb->status;
  253. struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
  254. struct sierra_port_private *portdata = usb_get_serial_port_data(port);
  255. struct usb_serial *serial = port->serial;
  256. dbg("%s", __FUNCTION__);
  257. dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata);
  258. if (status == 0) {
  259. struct usb_ctrlrequest *req_pkt =
  260. (struct usb_ctrlrequest *)urb->transfer_buffer;
  261. if (!req_pkt) {
  262. dbg("%s: NULL req_pkt\n", __FUNCTION__);
  263. return;
  264. }
  265. if ((req_pkt->bRequestType == 0xA1) &&
  266. (req_pkt->bRequest == 0x20)) {
  267. int old_dcd_state;
  268. unsigned char signals = *((unsigned char *)
  269. urb->transfer_buffer +
  270. sizeof(struct usb_ctrlrequest));
  271. dbg("%s: signal x%x", __FUNCTION__, signals);
  272. old_dcd_state = portdata->dcd_state;
  273. portdata->cts_state = 1;
  274. portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
  275. portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
  276. portdata->ri_state = ((signals & 0x08) ? 1 : 0);
  277. if (port->tty && !C_CLOCAL(port->tty) &&
  278. old_dcd_state && !portdata->dcd_state)
  279. tty_hangup(port->tty);
  280. } else {
  281. dbg("%s: type %x req %x", __FUNCTION__,
  282. req_pkt->bRequestType,req_pkt->bRequest);
  283. }
  284. } else
  285. dbg("%s: error %d", __FUNCTION__, status);
  286. /* Resubmit urb so we continue receiving IRQ data */
  287. if (status != -ESHUTDOWN) {
  288. urb->dev = serial->dev;
  289. err = usb_submit_urb(urb, GFP_ATOMIC);
  290. if (err)
  291. dbg("%s: resubmit intr urb failed. (%d)",
  292. __FUNCTION__, err);
  293. }
  294. }
  295. static int sierra_write_room(struct usb_serial_port *port)
  296. {
  297. struct sierra_port_private *portdata;
  298. int i;
  299. int data_len = 0;
  300. struct urb *this_urb;
  301. portdata = usb_get_serial_port_data(port);
  302. for (i=0; i < N_OUT_URB; i++) {
  303. this_urb = portdata->out_urbs[i];
  304. if (this_urb && this_urb->status != -EINPROGRESS)
  305. data_len += OUT_BUFLEN;
  306. }
  307. dbg("%s: %d", __FUNCTION__, data_len);
  308. return data_len;
  309. }
  310. static int sierra_chars_in_buffer(struct usb_serial_port *port)
  311. {
  312. struct sierra_port_private *portdata;
  313. int i;
  314. int data_len = 0;
  315. struct urb *this_urb;
  316. portdata = usb_get_serial_port_data(port);
  317. for (i=0; i < N_OUT_URB; i++) {
  318. this_urb = portdata->out_urbs[i];
  319. if (this_urb && this_urb->status == -EINPROGRESS)
  320. data_len += this_urb->transfer_buffer_length;
  321. }
  322. dbg("%s: %d", __FUNCTION__, data_len);
  323. return data_len;
  324. }
  325. static int sierra_open(struct usb_serial_port *port, struct file *filp)
  326. {
  327. struct sierra_port_private *portdata;
  328. struct usb_serial *serial = port->serial;
  329. int i, err;
  330. struct urb *urb;
  331. int result;
  332. __u16 set_mode_dzero = 0x0000;
  333. portdata = usb_get_serial_port_data(port);
  334. dbg("%s", __FUNCTION__);
  335. /* Set some sane defaults */
  336. portdata->rts_state = 1;
  337. portdata->dtr_state = 1;
  338. /* Reset low level data toggle and start reading from endpoints */
  339. for (i = 0; i < N_IN_URB; i++) {
  340. urb = portdata->in_urbs[i];
  341. if (! urb)
  342. continue;
  343. if (urb->dev != serial->dev) {
  344. dbg("%s: dev %p != %p", __FUNCTION__,
  345. urb->dev, serial->dev);
  346. continue;
  347. }
  348. /*
  349. * make sure endpoint data toggle is synchronized with the
  350. * device
  351. */
  352. usb_clear_halt(urb->dev, urb->pipe);
  353. err = usb_submit_urb(urb, GFP_KERNEL);
  354. if (err) {
  355. dbg("%s: submit urb %d failed (%d) %d",
  356. __FUNCTION__, i, err,
  357. urb->transfer_buffer_length);
  358. }
  359. }
  360. /* Reset low level data toggle on out endpoints */
  361. for (i = 0; i < N_OUT_URB; i++) {
  362. urb = portdata->out_urbs[i];
  363. if (! urb)
  364. continue;
  365. urb->dev = serial->dev;
  366. /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
  367. usb_pipeout(urb->pipe), 0); */
  368. }
  369. port->tty->low_latency = 1;
  370. /* set mode to D0 */
  371. result = usb_control_msg(serial->dev,
  372. usb_rcvctrlpipe(serial->dev, 0),
  373. 0x00, 0x40, set_mode_dzero, 0, NULL,
  374. 0, USB_CTRL_SET_TIMEOUT);
  375. sierra_send_setup(port);
  376. return (0);
  377. }
  378. static void sierra_close(struct usb_serial_port *port, struct file *filp)
  379. {
  380. int i;
  381. struct usb_serial *serial = port->serial;
  382. struct sierra_port_private *portdata;
  383. dbg("%s", __FUNCTION__);
  384. portdata = usb_get_serial_port_data(port);
  385. portdata->rts_state = 0;
  386. portdata->dtr_state = 0;
  387. if (serial->dev) {
  388. sierra_send_setup(port);
  389. /* Stop reading/writing urbs */
  390. for (i = 0; i < N_IN_URB; i++)
  391. usb_unlink_urb(portdata->in_urbs[i]);
  392. for (i = 0; i < N_OUT_URB; i++)
  393. usb_unlink_urb(portdata->out_urbs[i]);
  394. }
  395. port->tty = NULL;
  396. }
  397. /* Helper functions used by sierra_setup_urbs */
  398. static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint,
  399. int dir, void *ctx, char *buf, int len,
  400. usb_complete_t callback)
  401. {
  402. struct urb *urb;
  403. if (endpoint == -1)
  404. return NULL; /* endpoint not needed */
  405. urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
  406. if (urb == NULL) {
  407. dbg("%s: alloc for endpoint %d failed.", __FUNCTION__, endpoint);
  408. return NULL;
  409. }
  410. /* Fill URB using supplied data. */
  411. usb_fill_bulk_urb(urb, serial->dev,
  412. usb_sndbulkpipe(serial->dev, endpoint) | dir,
  413. buf, len, callback, ctx);
  414. return urb;
  415. }
  416. /* Setup urbs */
  417. static void sierra_setup_urbs(struct usb_serial *serial)
  418. {
  419. int i,j;
  420. struct usb_serial_port *port;
  421. struct sierra_port_private *portdata;
  422. dbg("%s", __FUNCTION__);
  423. for (i = 0; i < serial->num_ports; i++) {
  424. port = serial->port[i];
  425. portdata = usb_get_serial_port_data(port);
  426. /* Do indat endpoints first */
  427. for (j = 0; j < N_IN_URB; ++j) {
  428. portdata->in_urbs[j] = sierra_setup_urb (serial,
  429. port->bulk_in_endpointAddress, USB_DIR_IN, port,
  430. portdata->in_buffer[j], IN_BUFLEN, sierra_indat_callback);
  431. }
  432. /* outdat endpoints */
  433. for (j = 0; j < N_OUT_URB; ++j) {
  434. portdata->out_urbs[j] = sierra_setup_urb (serial,
  435. port->bulk_out_endpointAddress, USB_DIR_OUT, port,
  436. portdata->out_buffer[j], OUT_BUFLEN, sierra_outdat_callback);
  437. }
  438. }
  439. }
  440. static int sierra_startup(struct usb_serial *serial)
  441. {
  442. int i, err;
  443. struct usb_serial_port *port;
  444. struct sierra_port_private *portdata;
  445. dbg("%s", __FUNCTION__);
  446. /* Now setup per port private data */
  447. for (i = 0; i < serial->num_ports; i++) {
  448. port = serial->port[i];
  449. portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
  450. if (!portdata) {
  451. dbg("%s: kmalloc for sierra_port_private (%d) failed!.",
  452. __FUNCTION__, i);
  453. return (1);
  454. }
  455. usb_set_serial_port_data(port, portdata);
  456. if (! port->interrupt_in_urb)
  457. continue;
  458. err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  459. if (err)
  460. dbg("%s: submit irq_in urb failed %d",
  461. __FUNCTION__, err);
  462. }
  463. sierra_setup_urbs(serial);
  464. return (0);
  465. }
  466. static void sierra_shutdown(struct usb_serial *serial)
  467. {
  468. int i, j;
  469. struct usb_serial_port *port;
  470. struct sierra_port_private *portdata;
  471. dbg("%s", __FUNCTION__);
  472. /* Stop reading/writing urbs */
  473. for (i = 0; i < serial->num_ports; ++i) {
  474. port = serial->port[i];
  475. if (!port)
  476. continue;
  477. portdata = usb_get_serial_port_data(port);
  478. if (!portdata)
  479. continue;
  480. for (j = 0; j < N_IN_URB; j++)
  481. usb_unlink_urb(portdata->in_urbs[j]);
  482. for (j = 0; j < N_OUT_URB; j++)
  483. usb_unlink_urb(portdata->out_urbs[j]);
  484. }
  485. /* Now free them */
  486. for (i = 0; i < serial->num_ports; ++i) {
  487. port = serial->port[i];
  488. if (!port)
  489. continue;
  490. portdata = usb_get_serial_port_data(port);
  491. if (!portdata)
  492. continue;
  493. for (j = 0; j < N_IN_URB; j++) {
  494. if (portdata->in_urbs[j]) {
  495. usb_free_urb(portdata->in_urbs[j]);
  496. portdata->in_urbs[j] = NULL;
  497. }
  498. }
  499. for (j = 0; j < N_OUT_URB; j++) {
  500. if (portdata->out_urbs[j]) {
  501. usb_free_urb(portdata->out_urbs[j]);
  502. portdata->out_urbs[j] = NULL;
  503. }
  504. }
  505. }
  506. /* Now free per port private data */
  507. for (i = 0; i < serial->num_ports; i++) {
  508. port = serial->port[i];
  509. if (!port)
  510. continue;
  511. kfree(usb_get_serial_port_data(port));
  512. }
  513. }
  514. static struct usb_serial_driver sierra_1port_device = {
  515. .driver = {
  516. .owner = THIS_MODULE,
  517. .name = "sierra1",
  518. },
  519. .description = "Sierra USB modem (1 port)",
  520. .id_table = id_table_1port,
  521. .usb_driver = &sierra_driver,
  522. .num_interrupt_in = NUM_DONT_CARE,
  523. .num_bulk_in = 1,
  524. .num_bulk_out = 1,
  525. .num_ports = 1,
  526. .open = sierra_open,
  527. .close = sierra_close,
  528. .write = sierra_write,
  529. .write_room = sierra_write_room,
  530. .chars_in_buffer = sierra_chars_in_buffer,
  531. .throttle = sierra_rx_throttle,
  532. .unthrottle = sierra_rx_unthrottle,
  533. .ioctl = sierra_ioctl,
  534. .set_termios = sierra_set_termios,
  535. .break_ctl = sierra_break_ctl,
  536. .tiocmget = sierra_tiocmget,
  537. .tiocmset = sierra_tiocmset,
  538. .attach = sierra_startup,
  539. .shutdown = sierra_shutdown,
  540. .read_int_callback = sierra_instat_callback,
  541. };
  542. static struct usb_serial_driver sierra_3port_device = {
  543. .driver = {
  544. .owner = THIS_MODULE,
  545. .name = "sierra3",
  546. },
  547. .description = "Sierra USB modem (3 port)",
  548. .id_table = id_table_3port,
  549. .usb_driver = &sierra_driver,
  550. .num_interrupt_in = NUM_DONT_CARE,
  551. .num_bulk_in = 3,
  552. .num_bulk_out = 3,
  553. .num_ports = 3,
  554. .open = sierra_open,
  555. .close = sierra_close,
  556. .write = sierra_write,
  557. .write_room = sierra_write_room,
  558. .chars_in_buffer = sierra_chars_in_buffer,
  559. .throttle = sierra_rx_throttle,
  560. .unthrottle = sierra_rx_unthrottle,
  561. .ioctl = sierra_ioctl,
  562. .set_termios = sierra_set_termios,
  563. .break_ctl = sierra_break_ctl,
  564. .tiocmget = sierra_tiocmget,
  565. .tiocmset = sierra_tiocmset,
  566. .attach = sierra_startup,
  567. .shutdown = sierra_shutdown,
  568. .read_int_callback = sierra_instat_callback,
  569. };
  570. /* Functions used by new usb-serial code. */
  571. static int __init sierra_init(void)
  572. {
  573. int retval;
  574. retval = usb_serial_register(&sierra_1port_device);
  575. if (retval)
  576. goto failed_1port_device_register;
  577. retval = usb_serial_register(&sierra_3port_device);
  578. if (retval)
  579. goto failed_3port_device_register;
  580. retval = usb_register(&sierra_driver);
  581. if (retval)
  582. goto failed_driver_register;
  583. info(DRIVER_DESC ": " DRIVER_VERSION);
  584. return 0;
  585. failed_driver_register:
  586. usb_serial_deregister(&sierra_3port_device);
  587. failed_3port_device_register:
  588. usb_serial_deregister(&sierra_1port_device);
  589. failed_1port_device_register:
  590. return retval;
  591. }
  592. static void __exit sierra_exit(void)
  593. {
  594. usb_deregister (&sierra_driver);
  595. usb_serial_deregister(&sierra_1port_device);
  596. usb_serial_deregister(&sierra_3port_device);
  597. }
  598. module_init(sierra_init);
  599. module_exit(sierra_exit);
  600. MODULE_AUTHOR(DRIVER_AUTHOR);
  601. MODULE_DESCRIPTION(DRIVER_DESC);
  602. MODULE_VERSION(DRIVER_VERSION);
  603. MODULE_LICENSE("GPL");
  604. #ifdef CONFIG_USB_DEBUG
  605. module_param(debug, bool, S_IRUGO | S_IWUSR);
  606. MODULE_PARM_DESC(debug, "Debug messages");
  607. #endif