sierra.c 21 KB

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