sierra.c 19 KB

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