Changeset 12066
- Timestamp:
- 05/08/09 15:47:37 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/linux/sl2312/linux-2.6.23/drivers/usb/serial/sierra.c
r11897 r12066 3 3 4 4 Copyright (C) 2006, 2007, 2008 Kevin Lloyd <klloyd@sierrawireless.com> 5 6 Copyright (C) 2008, 2009 Elina Pasheva, Matthew Safar, Rory Filer 7 <linux@sierrawireless.com> 5 8 6 9 IMPORTANT DISCLAIMER: This driver is not commercially supported by … … 16 19 Back ported to kernel 2.6.23 17 20 */ 18 19 #define DRIVER_VERSION "v.1.3.1b" 20 #define DRIVER_AUTHOR "Kevin Lloyd <klloyd@sierrawireless.com>" 21 /* Uncomment to log function calls */ 22 /*#define DEBUG*/ 23 #define DRIVER_VERSION "v.1.7.0" 24 #define DRIVER_AUTHOR "Kevin Lloyd, Elina Pasheva, Matthew Safar, Rory Filer" 21 25 #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" 22 26 … … 29 33 #include <linux/usb.h> 30 34 #include <linux/usb/serial.h> 31 #include <linux/usb/ch9.h>32 35 33 36 #define SWIMS_USB_REQUEST_SetPower 0x00 … … 36 39 #define SWIMS_SET_MODE_Modem 0x0001 37 40 38 /* per port private data */ 39 #define N_IN_URB 4 40 #define N_OUT_URB 4 41 #define N_IN_URB 8 42 #define N_OUT_URB 64 41 43 #define IN_BUFLEN 4096 44 45 #define MAX_TRANSFER (PAGE_SIZE - 512) 46 /* MAX_TRANSFER is chosen so that the VM is not stressed by 47 allocations > PAGE_SIZE and the number of packets in a page 48 is an integer 512 is the largest possible packet on EHCI */ 42 49 43 50 static int debug; 44 51 static int nmea; 45 52 static int truinstall = 1; 53 static int suspend_support; 46 54 47 55 enum devicetype { 48 DEVICE_3_PORT = 0, 49 DEVICE_1_PORT = 1, 50 DEVICE_INSTALLER = 2, 56 DEVICE_MODEM = 0, 57 DEVICE_INSTALLER = 1, 51 58 }; 52 59 60 /* list of interface numbers - used for constructing interface blacklists */ 61 struct list { 62 const u32 listlen; /* number of interface numbers on list */ 63 const u8 *list; /* pointer to the array holding the numbers */ 64 }; 65 66 /* static device type specific data */ 67 struct sierra_device_static_info { 68 const enum devicetype dev_type; 69 const struct list iface_blacklist; 70 }; 71 53 72 static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) 54 73 { 55 74 int result; 56 dev_dbg(&udev->dev, "%s ", __func__);75 dev_dbg(&udev->dev, "%s\n", __func__); 57 76 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 58 77 SWIMS_USB_REQUEST_SetPower, /* __u8 request */ … … 69 88 { 70 89 int result; 71 dev_dbg(&udev->dev, "%s ", "DEVICE MODE SWITCH\n");90 dev_dbg(&udev->dev, "%s\n", "DEVICE MODE SWITCH"); 72 91 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 73 92 SWIMS_USB_REQUEST_SetMode, /* __u8 request */ … … 84 103 { 85 104 int result; 86 dev_dbg(&udev->dev, "%s ", __func__);105 dev_dbg(&udev->dev, "%s\n", __func__); 87 106 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 88 107 SWIMS_USB_REQUEST_SetNmea, /* __u8 request */ … … 98 117 static int sierra_calc_num_ports(struct usb_serial *serial) 99 118 { 100 int result; 101 int *num_ports = usb_get_serial_data(serial); 102 dev_dbg(&serial->dev->dev, "%s", __func__); 103 104 result = *num_ports; 105 106 if (result) { 107 kfree(num_ports); 108 usb_set_serial_data(serial, NULL); 109 } 110 111 return result; 119 int num_ports = 0; 120 u8 ifnum, numendpoints; 121 122 dev_dbg(&serial->dev->dev, "%s\n", __func__); 123 124 ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 125 numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints; 126 127 /* Dummy interface present on some SKUs should be ignored */ 128 if (ifnum == 0x99) 129 num_ports = 0; 130 else if (numendpoints <= 3) 131 num_ports = 1; 132 else 133 num_ports = (numendpoints-1)/2; 134 return num_ports; 135 } 136 137 static int is_blacklisted(const u8 ifnum, const struct list *blacklist) 138 { 139 const u8 *list; 140 int i; 141 142 if (blacklist) { 143 list = blacklist->list; 144 145 for (i=0; i < blacklist->listlen; i++) { 146 if (list[i] == ifnum) 147 return 1; 148 } 149 } 150 return 0; 112 151 } 113 152 … … 117 156 struct usb_interface *p_interface; 118 157 struct usb_host_interface *p_host_interface; 119 dev_dbg(&serial->dev->dev, "%s ", __func__);158 dev_dbg(&serial->dev->dev, "%s\n", __func__); 120 159 121 160 /* Get the interface structure pointer from the serial struct */ … … 136 175 const struct usb_device_id *id) 137 176 { 177 const struct sierra_device_static_info * info; 138 178 int result = 0; 139 179 struct usb_device *udev; 140 int *num_ports; 141 u8 ifnum, ifclass, numendpoints; 142 143 dev_dbg(&serial->dev->dev, "%s", __func__); 144 145 num_ports = kmalloc(sizeof(*num_ports), GFP_KERNEL); 146 if (!num_ports) 147 return -ENOMEM; 148 149 ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 180 u8 ifnum, ifclass; 181 182 udev = serial->dev; 183 dev_dbg(&udev->dev, "%s\n", __func__); 184 185 /* Check TRU-Install first */ 186 info = (const struct sierra_device_static_info *)id->driver_info; 150 187 ifclass = serial->interface->cur_altsetting->desc.bInterfaceClass; 151 numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints; 152 udev = serial->dev; 153 154 /* Figure out the interface number from the serial structure */ 188 if (ifclass == USB_CLASS_MASS_STORAGE) { 189 /* If TRU-Install support is enabled, force to modem mode */ 190 if (truinstall && info && info->dev_type == DEVICE_INSTALLER) { 191 dev_dbg(&udev->dev, "%s\n", "FOUND TRU-INSTALL DEVICE"); 192 result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem); 193 } 194 return -ENODEV; 195 } 196 155 197 ifnum = sierra_calc_interface(serial); 156 198 if (info && is_blacklisted(ifnum, &info->iface_blacklist)) { 199 dev_dbg(&serial->dev->dev, 200 "Ignoring blacklisted interface #%d\n", ifnum); 201 return -ENODEV; 202 } 203 157 204 /* 158 205 * If this interface supports more than 1 alternate … … 165 212 usb_set_interface(udev, ifnum, 1); 166 213 } 167 168 if (ifclass == USB_CLASS_MASS_STORAGE) { 169 /* If TRU-Install support is enabled, force to modem mode */ 170 if (truinstall && id->driver_info == DEVICE_INSTALLER) { 171 dev_dbg(&udev->dev, "%s", "FOUND TRU-INSTALL DEVICE\n"); 172 result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem); 173 } 174 kfree(num_ports); 175 return -EIO; 176 /* Dummy interface present on some SKUs should be ignored */ 177 } else if (ifnum == 0x99) 178 *num_ports = 0; 179 else if (numendpoints <= 3) 180 *num_ports = 1; 181 else 182 *num_ports = (numendpoints-1)/2; 183 184 /* 185 * save off our num_ports info so that we can use it in the 186 * calc_num_ports callback 214 /* Be careful here, The ifnum, ifclass etc. might be incorrect, because 215 * of the usb_set_interface call. (all obtained using 216 * serial->interface->cur_altsetting that was changed by that call) 187 217 */ 188 usb_set_serial_data(serial, (void *)num_ports); 189 218 190 219 return result; 191 220 } 221 222 static const struct sierra_device_static_info tru_inst_info = { 223 .dev_type = DEVICE_INSTALLER, 224 }; 225 226 static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11 }; 227 static const struct sierra_device_static_info direct_ip_interface_blacklist = { 228 .dev_type = DEVICE_MODEM, 229 .iface_blacklist = { 230 .listlen = ARRAY_SIZE( direct_ip_non_serial_ifaces ), 231 .list = direct_ip_non_serial_ifaces, 232 }, 233 }; 192 234 193 235 static struct usb_device_id id_table [] = { … … 223 265 { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */ 224 266 { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */ 225 { USB_DEVICE(0x1199, 0x683C) }, /* Sierra Wireless MC8790 */ 226 { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8790 */ 227 { USB_DEVICE(0x1199, 0x683E) }, /* Sierra Wireless MC8790 */ 267 /* Sierra Wireless MC8790, MC8791, MC8792 Composite */ 268 { USB_DEVICE(0x1199, 0x683C) }, 269 { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8791 Composite */ 270 /* Sierra Wireless MC8790, MC8791, MC8792 */ 271 { USB_DEVICE(0x1199, 0x683E) }, 228 272 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ 229 273 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ … … 246 290 { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */ 247 291 248 { USB_DEVICE(0x1199, 0x0FFF), .driver_info = DEVICE_INSTALLER}, 292 { USB_DEVICE(0x1199, 0x0FFF), 293 .driver_info = (kernel_ulong_t)&tru_inst_info 294 }, 295 296 { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */ 297 .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist 298 }, 299 249 300 { } 250 301 }; 251 302 MODULE_DEVICE_TABLE(usb, id_table); 252 303 253 static struct usb_driver sierra_driver = { 254 .name = "sierra", 255 .probe = usb_serial_probe, 256 .disconnect = usb_serial_disconnect, 257 .id_table = id_table, 258 .no_dynamic_id = 1, 259 }; 260 304 /* per port private data */ 261 305 struct sierra_port_private { 262 306 spinlock_t lock; /* lock the structure */ … … 265 309 /* Input endpoints and buffers for this port */ 266 310 struct urb *in_urbs[N_IN_URB]; 267 char *in_buffer[N_IN_URB];268 311 269 312 /* Settings for the port */ … … 282 325 __u16 interface = 0; 283 326 284 d bg("%s", __FUNCTION__);327 dev_dbg(&port->dev, "%s\n", __func__); 285 328 286 329 portdata = usb_get_serial_port_data(port); 287 330 288 331 if (port->tty) { 332 289 333 int val = 0; 290 334 if (portdata->dtr_state) … … 292 336 if (portdata->rts_state) 293 337 val |= 0x02; 294 338 295 339 /* If composite device then properly report interface */ 296 if (serial->num_ports == 1) 340 if (serial->num_ports == 1) { 297 341 interface = sierra_calc_interface(serial); 342 /* Control message is send only to interfaces with 343 * interrupt_in endpoints 344 */ 345 if(port->interrupt_in_urb) { 346 /* send control message */ 347 return usb_control_msg(serial->dev, 348 usb_rcvctrlpipe(serial->dev, 0), 349 0x22, 0x21, val, interface, 350 NULL, 0, USB_CTRL_SET_TIMEOUT); 351 } 352 } 298 353 299 354 /* Otherwise the need to do non-composite mapping */ … … 305 360 else if (port->bulk_out_endpointAddress == 5) 306 361 interface = 2; 307 } 308 309 return usb_control_msg(serial->dev, 362 363 return usb_control_msg(serial->dev, 310 364 usb_rcvctrlpipe(serial->dev, 0), 311 365 0x22, 0x21, val, interface, 312 366 NULL, 0, USB_CTRL_SET_TIMEOUT); 367 368 } 313 369 } 314 370 … … 319 375 struct ktermios *old_termios) 320 376 { 321 dev_dbg(&port->dev, "%s ", __func__);377 dev_dbg(&port->dev, "%s\n", __func__); 322 378 sierra_send_setup(port); 323 379 } … … 328 384 struct sierra_port_private *portdata; 329 385 386 dev_dbg(&port->dev, "%s\n", __func__); 330 387 portdata = usb_get_serial_port_data(port); 331 388 … … 358 415 return sierra_send_setup(port); 359 416 } 417 static void sierra_release_urb(struct urb *urb) 418 { 419 struct usb_serial_port *port; 420 if (urb) { 421 port = urb->context; 422 dev_dbg(&port->dev, "%s: %p\n", __func__, urb); 423 if (urb->transfer_buffer) 424 kfree(urb->transfer_buffer); 425 usb_free_urb(urb); 426 } 427 } 360 428 361 429 static void sierra_outdat_callback(struct urb *urb) … … 366 434 unsigned long flags; 367 435 368 dev_dbg(&port->dev, "%s - port %d ", __func__, port->number);436 dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); 369 437 370 438 /* free up the transfer buffer, as usb_free_urb() does not do this */ … … 373 441 if (status) 374 442 dev_dbg(&port->dev, "%s - nonzero write bulk status " 375 "received: %d ", __func__, status);443 "received: %d\n", __func__, status); 376 444 377 445 spin_lock_irqsave(&portdata->lock, flags); … … 391 459 unsigned char *buffer; 392 460 struct urb *urb; 393 int status; 461 size_t writesize = min((size_t)count, (size_t)MAX_TRANSFER); 462 int retval = 0; 463 464 /* verify that we actually have some data to write */ 465 if (count == 0) 466 return 0; 394 467 395 468 portdata = usb_get_serial_port_data(port); 396 469 397 dev_dbg(&port->dev, "%s: write (%d chars)", __func__, count);470 dev_dbg(&port->dev, "%s: write (%d bytes)\n", __func__, writesize); 398 471 399 472 spin_lock_irqsave(&portdata->lock, flags); … … 406 479 spin_unlock_irqrestore(&portdata->lock, flags); 407 480 408 buffer = kmalloc( count, GFP_ATOMIC);481 buffer = kmalloc(writesize, GFP_ATOMIC); 409 482 if (!buffer) { 410 483 dev_err(&port->dev, "out of memory\n"); 411 count= -ENOMEM;484 retval = -ENOMEM; 412 485 goto error_no_buffer; 413 486 } … … 416 489 if (!urb) { 417 490 dev_err(&port->dev, "no more free urbs\n"); 418 count= -ENOMEM;491 retval = -ENOMEM; 419 492 goto error_no_urb; 420 493 } 421 494 422 memcpy(buffer, buf, count);423 424 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);495 memcpy(buffer, buf, writesize); 496 497 usb_serial_debug_data(debug, &port->dev, __func__, writesize, buffer); 425 498 426 499 usb_fill_bulk_urb(urb, serial->dev, 427 500 usb_sndbulkpipe(serial->dev, 428 501 port->bulk_out_endpointAddress), 429 buffer, count, sierra_outdat_callback, port); 502 buffer, writesize, sierra_outdat_callback, port); 503 504 /* Handle the need to send a zero length packet */ 505 urb->transfer_flags |= URB_ZERO_PACKET; 430 506 431 507 /* send it down the pipe */ 432 status= usb_submit_urb(urb, GFP_ATOMIC);433 if ( status) {508 retval = usb_submit_urb(urb, GFP_ATOMIC); 509 if (retval) { 434 510 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed " 435 "with status = %d\n", __func__, status); 436 count = status; 511 "with status = %d\n", __func__, retval); 437 512 goto error; 438 513 } … … 441 516 * really free it when it is finished with it */ 442 517 usb_free_urb(urb); 443 444 return count;518 519 return writesize; 445 520 error: 446 521 usb_free_urb(urb); … … 451 526 --portdata->outstanding_urbs; 452 527 spin_unlock_irqrestore(&portdata->lock, flags); 453 return count;528 return retval; 454 529 } 455 530 … … 463 538 int status = urb->status; 464 539 465 dbg("%s: %p", __func__, urb);466 467 540 endpoint = usb_pipeendpoint(urb->pipe); 468 541 port = urb->context; 542 543 dev_dbg(&port->dev, "%s: %p\n", __func__, urb); 469 544 470 545 if (status) { 471 546 dev_dbg(&port->dev, "%s: nonzero status: %d on" 472 " endpoint %02x.", __func__, status, endpoint);547 " endpoint %02x\n", __func__, status, endpoint); 473 548 } else { 474 549 tty = port->tty; … … 477 552 tty_insert_flip_string(tty, data, urb->actual_length); 478 553 tty_flip_buffer_push(tty); 554 usb_serial_debug_data(debug, &port->dev, __func__, 555 urb->actual_length, data); 479 556 } else { 480 557 dev_dbg(&port->dev, "%s: empty read urb" 481 " received", __func__); 482 } 483 484 /* Resubmit urb so we continue receiving */ 485 if (port->open_count && status != -ESHUTDOWN) { 486 err = usb_submit_urb(urb, GFP_ATOMIC); 487 if (err) 488 dev_err(&port->dev, "resubmit read urb failed." 489 "(%d)\n", err); 490 } 491 } 558 " received\n", __func__); 559 } 560 } 561 562 /* Resubmit urb so we continue receiving */ 563 if (port->open_count && status != -ESHUTDOWN && status != -ENOENT) { 564 err = usb_submit_urb(urb, GFP_ATOMIC); 565 if (err) 566 dev_err(&port->dev, "resubmit read urb failed." 567 "(%d)\n", err); 568 } 569 492 570 return; 493 571 } … … 501 579 struct usb_serial *serial = port->serial; 502 580 503 dev_dbg(&port->dev, "%s", __func__); 504 dev_dbg(&port->dev, "%s: urb %p port %p has data %p", __func__, 581 dev_dbg(&port->dev, "%s: urb %p port %p has data %p\n", __func__, 505 582 urb, port, portdata); 506 583 … … 521 598 sizeof(struct usb_ctrlrequest)); 522 599 523 dev_dbg(&port->dev, "%s: signal x%x ", __func__,600 dev_dbg(&port->dev, "%s: signal x%x\n", __func__, 524 601 signals); 525 602 … … 534 611 tty_hangup(port->tty); 535 612 } else { 536 dev_dbg(&port->dev, "%s: type %x req %x ",613 dev_dbg(&port->dev, "%s: type %x req %x\n", 537 614 __func__, req_pkt->bRequestType, 538 615 req_pkt->bRequest); 539 616 } 540 617 } else 541 dev_dbg(&port->dev, "%s: error %d ", __func__, status);618 dev_dbg(&port->dev, "%s: error %d\n", __func__, status); 542 619 543 620 /* Resubmit urb so we continue receiving IRQ data */ 544 if ( status != -ESHUTDOWN) {621 if (port->open_count && status != -ESHUTDOWN && status != -ENOENT) { 545 622 urb->dev = serial->dev; 546 623 err = usb_submit_urb(urb, GFP_ATOMIC); 547 624 if (err) 548 dev_ dbg(&port->dev, "%s: resubmit intr urb "549 "failed. (%d) ",__func__, err);625 dev_err(&port->dev, "%s: resubmit intr urb " 626 "failed. (%d)\n", __func__, err); 550 627 } 551 628 } … … 556 633 unsigned long flags; 557 634 558 dev_dbg(&port->dev, "%s - port %d ", __func__, port->number);635 dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); 559 636 560 637 /* try to give a good number back based on if we have any free urbs at … … 571 648 } 572 649 650 static void sierra_stop_rx_urbs(struct usb_serial_port *port) 651 { 652 int i; 653 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 654 655 for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { 656 usb_kill_urb(portdata->in_urbs[i]); 657 } 658 usb_kill_urb(port->interrupt_in_urb); 659 } 660 661 static int sierra_submit_rx_urbs(struct usb_serial_port *port) 662 { 663 int ok_cnt; 664 int err = -EINVAL; 665 int i; 666 struct urb * urb; 667 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 668 669 ok_cnt = 0; 670 for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { 671 urb = portdata->in_urbs[i]; 672 if (!urb) 673 continue; 674 err = usb_submit_urb(urb, GFP_KERNEL); 675 if (err) { 676 dev_err(&port->dev, "%s: submit urb failed: %d\n", 677 __func__, err ); 678 } else { 679 ok_cnt ++; 680 } 681 } 682 683 if (ok_cnt && port->interrupt_in_urb) { 684 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 685 if (err) { 686 dev_err(&port->dev, "%s: submit intr urb failed: %d\n", 687 __func__, err ); 688 } 689 } 690 691 if (ok_cnt > 0) /* at least one rx urb submitted */ 692 return 0; 693 else 694 return err; 695 } 696 697 static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint, 698 int dir, void *ctx, int len, 699 usb_complete_t callback) 700 { 701 struct urb *urb; 702 u8 *buf; 703 704 if (endpoint == -1) 705 return NULL; 706 707 urb = usb_alloc_urb( 0, GFP_KERNEL ); 708 if (urb == NULL) { 709 dev_dbg(&serial->dev->dev, "%s: alloc for endpoint %d failed\n", 710 __func__, endpoint); 711 return NULL; 712 } 713 714 buf = kmalloc(len, GFP_KERNEL); 715 if (buf) 716 { 717 /* Fill URB using supplied data */ 718 usb_fill_bulk_urb(urb, serial->dev, 719 usb_sndbulkpipe(serial->dev, endpoint) | dir, 720 buf, len, callback, ctx); 721 722 /* debug */ 723 dev_dbg(&serial->dev->dev,"%s %c u:%p d:%p\n", __func__, 724 dir == USB_DIR_IN?'i':'o', urb, buf ); 725 } else { 726 dev_dbg(&serial->dev->dev,"%s %c u:%p d:%p\n", __func__, 727 dir == USB_DIR_IN?'i':'o', urb, buf ); 728 729 sierra_release_urb(urb); 730 urb = NULL; 731 } 732 733 return urb; 734 } 735 736 static void sierra_close(struct usb_serial_port *port, struct file *filp) 737 { 738 int i; 739 struct usb_serial *serial = port->serial; 740 struct sierra_port_private *portdata; 741 742 dev_dbg(&port->dev, "%s\n", __func__); 743 portdata = usb_get_serial_port_data(port); 744 745 portdata->rts_state = 0; 746 portdata->dtr_state = 0; 747 748 if (serial->dev) { 749 sierra_send_setup(port); 750 751 /* Stop reading urbs */ 752 sierra_stop_rx_urbs(port); 753 /* .. and release them */ 754 for (i = 0; i < N_IN_URB; i++) { 755 sierra_release_urb(portdata->in_urbs[i]); 756 portdata->in_urbs[i] = NULL; 757 } 758 } 759 760 port->tty = NULL; 761 } 762 573 763 static int sierra_open(struct usb_serial_port *port, struct file *filp) 574 764 { … … 576 766 struct usb_serial *serial = port->serial; 577 767 int i; 768 int err; 769 int endpoint; 578 770 struct urb *urb; 579 int result;580 771 581 772 portdata = usb_get_serial_port_data(port); 582 773 583 dev_dbg(&port->dev, "%s ", __func__);774 dev_dbg(&port->dev, "%s\n", __func__); 584 775 585 776 /* Set some sane defaults */ 586 777 portdata->rts_state = 1; 587 778 portdata->dtr_state = 1; 588 589 /* Reset low level data toggle and start reading from endpoints */ 590 for (i = 0; i < N_IN_URB; i++) { 591 urb = portdata->in_urbs[i]; 592 if (!urb) 593 continue; 594 if (urb->dev != serial->dev) { 595 dev_dbg(&port->dev, "%s: dev %p != %p", 596 __func__, urb->dev, serial->dev); 597 continue; 598 } 599 600 /* 601 * make sure endpoint data toggle is synchronized with the 602 * device 603 */ 604 usb_clear_halt(urb->dev, urb->pipe); 605 606 result = usb_submit_urb(urb, GFP_KERNEL); 607 if (result) { 608 dev_err(&port->dev, "submit urb %d failed (%d) %d\n", 609 i, result, urb->transfer_buffer_length); 610 } 611 } 612 613 port->tty->low_latency = 1; 614 779 780 if (port->tty) { 781 port->tty->low_latency = 1; 782 } 783 784 spin_lock_init(&portdata->lock); 785 786 endpoint = port->bulk_in_endpointAddress; 787 788 for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { 789 urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port, 790 IN_BUFLEN, sierra_indat_callback); 791 portdata->in_urbs[i] = urb; 792 } 793 /* clear halt condition */ 794 usb_clear_halt(serial->dev, 795 usb_sndbulkpipe(serial->dev, endpoint) | USB_DIR_IN); 796 797 err = sierra_submit_rx_urbs(port); 798 if (err) { 799 /* get rid of everything as in close */ 800 sierra_close(port, filp); 801 return err; 802 } 615 803 sierra_send_setup(port); 616 804 617 /* start up the interrupt endpoint if we have one */618 if (port->interrupt_in_urb) {619 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);620 if (result)621 dev_err(&port->dev, "submit irq_in urb failed %d\n",622 result);623 }624 805 return 0; 625 }626 627 static void sierra_close(struct usb_serial_port *port, struct file *filp)628 {629 int i;630 struct usb_serial *serial = port->serial;631 struct sierra_port_private *portdata;632 633 dev_dbg(&port->dev, "%s", __func__);634 portdata = usb_get_serial_port_data(port);635 636 portdata->rts_state = 0;637 portdata->dtr_state = 0;638 639 if (serial->dev) {640 sierra_send_setup(port);641 642 /* Stop reading/writing urbs */643 for (i = 0; i < N_IN_URB; i++)644 usb_kill_urb(portdata->in_urbs[i]);645 }646 647 usb_kill_urb(port->interrupt_in_urb);648 649 port->tty = NULL;650 806 } 651 807 … … 654 810 struct usb_serial_port *port; 655 811 struct sierra_port_private *portdata; 656 struct urb *urb;657 812 int i; 658 int j; 659 660 dev_dbg(&serial->dev->dev, "%s", __func__); 813 814 dev_dbg(&serial->dev->dev, "%s\n", __func__); 661 815 662 816 /* Set Device mode to D0 */ … … 673 827 if (!portdata) { 674 828 dev_dbg(&port->dev, "%s: kmalloc for " 675 "sierra_port_private (%d) failed! .",829 "sierra_port_private (%d) failed!\n", 676 830 __func__, i); 677 831 return -ENOMEM; 678 832 } 679 spin_lock_init(&portdata->lock); 680 for (j = 0; j < N_IN_URB; j++) { 681 portdata->in_buffer[j] = kmalloc(IN_BUFLEN, GFP_KERNEL); 682 if (!portdata->in_buffer[j]) { 683 for (--j; j >= 0; j--) 684 kfree(portdata->in_buffer[j]); 685 kfree(portdata); 686 return -ENOMEM; 687 } 688 } 689 833 /* Set the port private data pointer */ 690 834 usb_set_serial_port_data(port, portdata); 691 692 /* initialize the in urbs */693 for (j = 0; j < N_IN_URB; ++j) {694 urb = usb_alloc_urb(0, GFP_KERNEL);695 if (urb == NULL) {696 dev_dbg(&port->dev, "%s: alloc for in "697 "port failed.", __func__);698 continue;699 }700 /* Fill URB using supplied data. */701 usb_fill_bulk_urb(urb, serial->dev,702 usb_rcvbulkpipe(serial->dev,703 port->bulk_in_endpointAddress),704 portdata->in_buffer[j], IN_BUFLEN,705 sierra_indat_callback, port);706 portdata->in_urbs[j] = urb;707 }708 835 } 709 836 … … 713 840 static void sierra_shutdown(struct usb_serial *serial) 714 841 { 715 int i , j;842 int i; 716 843 struct usb_serial_port *port; 717 844 struct sierra_port_private *portdata; 718 845 719 dev_dbg(&serial->dev->dev, "%s ", __func__);846 dev_dbg(&serial->dev->dev, "%s\n", __func__); 720 847 721 848 for (i = 0; i < serial->num_ports; ++i) { … … 726 853 if (!portdata) 727 854 continue; 728 729 for (j = 0; j < N_IN_URB; j++) {730 usb_kill_urb(portdata->in_urbs[j]);731 usb_free_urb(portdata->in_urbs[j]);732 kfree(portdata->in_buffer[j]);733 }734 855 kfree(portdata); 735 856 usb_set_serial_port_data(port, NULL); 736 857 } 737 858 } 859 860 int sierra_suspend(struct usb_serial *serial, pm_message_t message) 861 { 862 int i; 863 864 dev_dbg(&serial->dev->dev, "%s\n", __func__); 865 866 /* The dummy interface doesn't prevent suspended state */ 867 if (serial->num_ports == 0) 868 return 0; 869 870 if (!suspend_support) 871 return -EOPNOTSUPP; 872 873 for (i=0; i < serial->num_ports ; i++) { 874 sierra_stop_rx_urbs(serial->port[i]); 875 } 876 return 0; 877 } 878 879 int sierra_resume(struct usb_serial *serial) 880 { 881 int i; 882 883 dev_dbg(&serial->dev->dev, "%s\n", __func__); 884 885 for (i=0; i < serial->num_ports ; i++) { 886 sierra_submit_rx_urbs(serial->port[i]); 887 } 888 889 return 0; 890 } 891 892 static struct usb_driver sierra_driver = { 893 .name = "sierra", 894 .probe = usb_serial_probe, 895 .disconnect = usb_serial_disconnect, 896 .suspend = usb_serial_suspend, 897 .resume = usb_serial_resume, 898 .id_table = id_table, 899 900 .no_dynamic_id = 1, 901 .supports_autosuspend = 1, 902 }; 738 903 739 904 static struct usb_serial_driver sierra_device = { … … 760 925 .shutdown = sierra_shutdown, 761 926 .read_int_callback = sierra_instat_callback, 927 .suspend = sierra_suspend, 928 .resume = sierra_resume, 762 929 }; 763 930 … … 807 974 module_param(debug, bool, S_IRUGO | S_IWUSR); 808 975 MODULE_PARM_DESC(debug, "Debug messages"); 976 977 module_param(suspend_support, bool, S_IRUGO | S_IWUSR); 978 MODULE_PARM_DESC(suspend_support, "Selective Suspend support");
Note: See TracChangeset
for help on using the changeset viewer.
