Changeset 12063
- Timestamp:
- 05/08/09 15:46:41 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/linux/xscale/linux-2.6.23/drivers/usb/serial/sierra.c
r11999 r12063 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 41 #define N_IN_URB 8 40 42 #define N_OUT_URB 64 41 43 #define IN_BUFLEN 4096 42 44 43 44 #define MAX_TRANSFER (PAGE_SIZE - 512) 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 */ 45 49 46 50 static int debug; 47 51 static int nmea; 48 52 static int truinstall = 1; 53 static int suspend_support; 49 54 50 55 enum devicetype { 51 DEVICE_3_PORT = 0, 52 DEVICE_1_PORT = 1, 53 DEVICE_INSTALLER = 2, 56 DEVICE_MODEM = 0, 57 DEVICE_INSTALLER = 1, 54 58 }; 55 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 56 72 static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) 57 73 { 58 74 int result; 59 dev_dbg(&udev->dev, "%s ", __func__);75 dev_dbg(&udev->dev, "%s\n", __func__); 60 76 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 61 77 SWIMS_USB_REQUEST_SetPower, /* __u8 request */ … … 72 88 { 73 89 int result; 74 dev_dbg(&udev->dev, "%s ", "DEVICE MODE SWITCH\n");90 dev_dbg(&udev->dev, "%s\n", "DEVICE MODE SWITCH"); 75 91 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 76 92 SWIMS_USB_REQUEST_SetMode, /* __u8 request */ … … 87 103 { 88 104 int result; 89 dev_dbg(&udev->dev, "%s ", __func__);105 dev_dbg(&udev->dev, "%s\n", __func__); 90 106 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 91 107 SWIMS_USB_REQUEST_SetNmea, /* __u8 request */ … … 101 117 static int sierra_calc_num_ports(struct usb_serial *serial) 102 118 { 103 int result; 104 int *num_ports = usb_get_serial_data(serial); 105 dev_dbg(&serial->dev->dev, "%s", __func__); 106 107 result = *num_ports; 108 109 if (result) { 110 kfree(num_ports); 111 usb_set_serial_data(serial, NULL); 112 } 113 114 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; 115 151 } 116 152 … … 120 156 struct usb_interface *p_interface; 121 157 struct usb_host_interface *p_host_interface; 122 dev_dbg(&serial->dev->dev, "%s ", __func__);158 dev_dbg(&serial->dev->dev, "%s\n", __func__); 123 159 124 160 /* Get the interface structure pointer from the serial struct */ … … 139 175 const struct usb_device_id *id) 140 176 { 177 const struct sierra_device_static_info * info; 141 178 int result = 0; 142 179 struct usb_device *udev; 143 int *num_ports; 144 u8 ifnum, ifclass, numendpoints; 145 146 dev_dbg(&serial->dev->dev, "%s", __func__); 147 148 num_ports = kmalloc(sizeof(*num_ports), GFP_KERNEL); 149 if (!num_ports) 150 return -ENOMEM; 151 152 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; 153 187 ifclass = serial->interface->cur_altsetting->desc.bInterfaceClass; 154 numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints; 155 udev = serial->dev; 156 157 /* 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 158 197 ifnum = sierra_calc_interface(serial); 159 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 160 204 /* 161 205 * If this interface supports more than 1 alternate … … 168 212 usb_set_interface(udev, ifnum, 1); 169 213 } 170 171 if (ifclass == USB_CLASS_MASS_STORAGE) { 172 /* If TRU-Install support is enabled, force to modem mode */ 173 if (truinstall && id->driver_info == DEVICE_INSTALLER) { 174 dev_dbg(&udev->dev, "%s", "FOUND TRU-INSTALL DEVICE\n"); 175 result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem); 176 } 177 kfree(num_ports); 178 return -EIO; 179 /* Dummy interface present on some SKUs should be ignored */ 180 } else if (ifnum == 0x99) 181 *num_ports = 0; 182 else if (numendpoints <= 3) 183 *num_ports = 1; 184 else 185 *num_ports = (numendpoints-1)/2; 186 187 /* 188 * save off our num_ports info so that we can use it in the 189 * 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) 190 217 */ 191 usb_set_serial_data(serial, (void *)num_ports); 192 218 193 219 return result; 194 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 }; 195 234 196 235 static struct usb_device_id id_table [] = { … … 226 265 { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */ 227 266 { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */ 228 { USB_DEVICE(0x1199, 0x683C) }, /* Sierra Wireless MC8790 */ 229 { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8790 */ 230 { 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) }, 231 272 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ 232 273 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ … … 248 289 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ 249 290 { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */ 250 { USB_DEVICE(0x1199, 0x68A3) }, /* Sierra Wireless Direct IP modems */ 251 { USB_DEVICE(0x05C6, 0x6613) }, /* Onda H600/ZTE MF330 */ 252 253 { USB_DEVICE(0x1199, 0x0FFF), .driver_info = DEVICE_INSTALLER}, 291 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 254 300 { } 255 301 }; 256 302 MODULE_DEVICE_TABLE(usb, id_table); 257 303 258 static struct usb_driver sierra_driver = { 259 .name = "sierra", 260 .probe = usb_serial_probe, 261 .disconnect = usb_serial_disconnect, 262 .id_table = id_table, 263 }; 264 304 /* per port private data */ 265 305 struct sierra_port_private { 266 306 spinlock_t lock; /* lock the structure */ … … 269 309 /* Input endpoints and buffers for this port */ 270 310 struct urb *in_urbs[N_IN_URB]; 271 char *in_buffer[N_IN_URB];272 311 273 312 /* Settings for the port */ … … 286 325 __u16 interface = 0; 287 326 288 d bg("%s", __FUNCTION__);327 dev_dbg(&port->dev, "%s\n", __func__); 289 328 290 329 portdata = usb_get_serial_port_data(port); 291 330 292 331 if (port->tty) { 332 293 333 int val = 0; 294 334 if (portdata->dtr_state) … … 296 336 if (portdata->rts_state) 297 337 val |= 0x02; 298 338 299 339 /* If composite device then properly report interface */ 300 if (serial->num_ports == 1) 340 if (serial->num_ports == 1) { 301 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 } 302 353 303 354 /* Otherwise the need to do non-composite mapping */ … … 309 360 else if (port->bulk_out_endpointAddress == 5) 310 361 interface = 2; 311 } 312 313 return usb_control_msg(serial->dev, 362 363 return usb_control_msg(serial->dev, 314 364 usb_rcvctrlpipe(serial->dev, 0), 315 365 0x22, 0x21, val, interface, 316 366 NULL, 0, USB_CTRL_SET_TIMEOUT); 367 368 } 317 369 } 318 370 … … 323 375 struct ktermios *old_termios) 324 376 { 325 dev_dbg(&port->dev, "%s ", __func__);377 dev_dbg(&port->dev, "%s\n", __func__); 326 378 sierra_send_setup(port); 327 379 } … … 332 384 struct sierra_port_private *portdata; 333 385 386 dev_dbg(&port->dev, "%s\n", __func__); 334 387 portdata = usb_get_serial_port_data(port); 335 388 … … 362 415 return sierra_send_setup(port); 363 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 } 364 428 365 429 static void sierra_outdat_callback(struct urb *urb) … … 370 434 unsigned long flags; 371 435 372 dev_dbg(&port->dev, "%s - port %d ", __func__, port->number);436 dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); 373 437 374 438 /* free up the transfer buffer, as usb_free_urb() does not do this */ … … 377 441 if (status) 378 442 dev_dbg(&port->dev, "%s - nonzero write bulk status " 379 "received: %d ", __func__, status);443 "received: %d\n", __func__, status); 380 444 381 445 spin_lock_irqsave(&portdata->lock, flags); … … 397 461 size_t writesize = min((size_t)count, (size_t)MAX_TRANSFER); 398 462 int retval = 0; 399 400 if (count==0) 401 return 0; 463 464 /* verify that we actually have some data to write */ 465 if (count == 0) 466 return 0; 402 467 403 468 portdata = usb_get_serial_port_data(port); 404 469 405 dev_dbg(&port->dev, "%s: write (%d chars)", __func__, count);470 dev_dbg(&port->dev, "%s: write (%d bytes)\n", __func__, writesize); 406 471 407 472 spin_lock_irqsave(&portdata->lock, flags); … … 428 493 } 429 494 430 memcpy(buffer, buf, writesize); 495 memcpy(buffer, buf, writesize); 431 496 432 497 usb_serial_debug_data(debug, &port->dev, __func__, writesize, buffer); … … 436 501 port->bulk_out_endpointAddress), 437 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; 438 506 439 507 /* send it down the pipe */ … … 448 516 * really free it when it is finished with it */ 449 517 usb_free_urb(urb); 450 518 451 519 return writesize; 452 520 error: … … 470 538 int status = urb->status; 471 539 472 dbg("%s: %p", __func__, urb);473 474 540 endpoint = usb_pipeendpoint(urb->pipe); 475 541 port = urb->context; 542 543 dev_dbg(&port->dev, "%s: %p\n", __func__, urb); 476 544 477 545 if (status) { 478 546 dev_dbg(&port->dev, "%s: nonzero status: %d on" 479 " endpoint %02x.", __func__, status, endpoint);547 " endpoint %02x\n", __func__, status, endpoint); 480 548 } else { 481 549 tty = port->tty; … … 484 552 tty_insert_flip_string(tty, data, urb->actual_length); 485 553 tty_flip_buffer_push(tty); 554 usb_serial_debug_data(debug, &port->dev, __func__, 555 urb->actual_length, data); 486 556 } else { 487 557 dev_dbg(&port->dev, "%s: empty read urb" 488 " received", __func__); 489 } 490 491 /* Resubmit urb so we continue receiving */ 492 if (port->open_count && status != -ESHUTDOWN) { 493 err = usb_submit_urb(urb, GFP_ATOMIC); 494 if (err) 495 dev_err(&port->dev, "resubmit read urb failed." 496 "(%d)\n", err); 497 } 498 } 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 499 570 return; 500 571 } … … 508 579 struct usb_serial *serial = port->serial; 509 580 510 dev_dbg(&port->dev, "%s", __func__); 511 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__, 512 582 urb, port, portdata); 513 583 … … 528 598 sizeof(struct usb_ctrlrequest)); 529 599 530 dev_dbg(&port->dev, "%s: signal x%x ", __func__,600 dev_dbg(&port->dev, "%s: signal x%x\n", __func__, 531 601 signals); 532 602 … … 541 611 tty_hangup(port->tty); 542 612 } else { 543 dev_dbg(&port->dev, "%s: type %x req %x ",613 dev_dbg(&port->dev, "%s: type %x req %x\n", 544 614 __func__, req_pkt->bRequestType, 545 615 req_pkt->bRequest); 546 616 } 547 617 } else 548 dev_dbg(&port->dev, "%s: error %d ", __func__, status);618 dev_dbg(&port->dev, "%s: error %d\n", __func__, status); 549 619 550 620 /* Resubmit urb so we continue receiving IRQ data */ 551 if ( status != -ESHUTDOWN) {621 if (port->open_count && status != -ESHUTDOWN && status != -ENOENT) { 552 622 urb->dev = serial->dev; 553 623 err = usb_submit_urb(urb, GFP_ATOMIC); 554 624 if (err) 555 dev_ dbg(&port->dev, "%s: resubmit intr urb "556 "failed. (%d) ",__func__, err);625 dev_err(&port->dev, "%s: resubmit intr urb " 626 "failed. (%d)\n", __func__, err); 557 627 } 558 628 } … … 563 633 unsigned long flags; 564 634 565 dev_dbg(&port->dev, "%s - port %d ", __func__, port->number);635 dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); 566 636 567 637 /* try to give a good number back based on if we have any free urbs at … … 578 648 } 579 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 580 763 static int sierra_open(struct usb_serial_port *port, struct file *filp) 581 764 { … … 583 766 struct usb_serial *serial = port->serial; 584 767 int i; 768 int err; 769 int endpoint; 585 770 struct urb *urb; 586 int result;587 771 588 772 portdata = usb_get_serial_port_data(port); 589 773 590 dev_dbg(&port->dev, "%s ", __func__);774 dev_dbg(&port->dev, "%s\n", __func__); 591 775 592 776 /* Set some sane defaults */ 593 777 portdata->rts_state = 1; 594 778 portdata->dtr_state = 1; 595 596 /* Reset low level data toggle and start reading from endpoints */ 597 for (i = 0; i < N_IN_URB; i++) { 598 urb = portdata->in_urbs[i]; 599 if (!urb) 600 continue; 601 if (urb->dev != serial->dev) { 602 dev_dbg(&port->dev, "%s: dev %p != %p", 603 __func__, urb->dev, serial->dev); 604 continue; 605 } 606 607 /* 608 * make sure endpoint data toggle is synchronized with the 609 * device 610 */ 611 usb_clear_halt(urb->dev, urb->pipe); 612 613 result = usb_submit_urb(urb, GFP_KERNEL); 614 if (result) { 615 dev_err(&port->dev, "submit urb %d failed (%d) %d\n", 616 i, result, urb->transfer_buffer_length); 617 } 618 } 619 620 port->tty->low_latency = 1; 621 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 } 622 803 sierra_send_setup(port); 623 804 624 /* start up the interrupt endpoint if we have one */625 if (port->interrupt_in_urb) {626 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);627 if (result)628 dev_err(&port->dev, "submit irq_in urb failed %d\n",629 result);630 }631 805 return 0; 632 }633 634 static void sierra_close(struct usb_serial_port *port, struct file *filp)635 {636 int i;637 struct usb_serial *serial = port->serial;638 struct sierra_port_private *portdata;639 640 dev_dbg(&port->dev, "%s", __func__);641 portdata = usb_get_serial_port_data(port);642 643 portdata->rts_state = 0;644 portdata->dtr_state = 0;645 646 if (serial->dev) {647 sierra_send_setup(port);648 649 /* Stop reading/writing urbs */650 for (i = 0; i < N_IN_URB; i++)651 usb_kill_urb(portdata->in_urbs[i]);652 }653 654 usb_kill_urb(port->interrupt_in_urb);655 656 port->tty = NULL;657 806 } 658 807 … … 661 810 struct usb_serial_port *port; 662 811 struct sierra_port_private *portdata; 663 struct urb *urb;664 812 int i; 665 int j; 666 667 dev_dbg(&serial->dev->dev, "%s", __func__); 813 814 dev_dbg(&serial->dev->dev, "%s\n", __func__); 668 815 669 816 /* Set Device mode to D0 */ … … 680 827 if (!portdata) { 681 828 dev_dbg(&port->dev, "%s: kmalloc for " 682 "sierra_port_private (%d) failed! .",829 "sierra_port_private (%d) failed!\n", 683 830 __func__, i); 684 831 return -ENOMEM; 685 832 } 686 spin_lock_init(&portdata->lock); 687 for (j = 0; j < N_IN_URB; j++) { 688 portdata->in_buffer[j] = kmalloc(IN_BUFLEN, GFP_KERNEL); 689 if (!portdata->in_buffer[j]) { 690 for (--j; j >= 0; j--) 691 kfree(portdata->in_buffer[j]); 692 kfree(portdata); 693 return -ENOMEM; 694 } 695 } 696 833 /* Set the port private data pointer */ 697 834 usb_set_serial_port_data(port, portdata); 698 699 /* initialize the in urbs */700 for (j = 0; j < N_IN_URB; ++j) {701 urb = usb_alloc_urb(0, GFP_KERNEL);702 if (urb == NULL) {703 dev_dbg(&port->dev, "%s: alloc for in "704 "port failed.", __func__);705 continue;706 }707 /* Fill URB using supplied data. */708 usb_fill_bulk_urb(urb, serial->dev,709 usb_rcvbulkpipe(serial->dev,710 port->bulk_in_endpointAddress),711 portdata->in_buffer[j], IN_BUFLEN,712 sierra_indat_callback, port);713 portdata->in_urbs[j] = urb;714 }715 835 } 716 836 … … 720 840 static void sierra_shutdown(struct usb_serial *serial) 721 841 { 722 int i , j;842 int i; 723 843 struct usb_serial_port *port; 724 844 struct sierra_port_private *portdata; 725 845 726 dev_dbg(&serial->dev->dev, "%s ", __func__);846 dev_dbg(&serial->dev->dev, "%s\n", __func__); 727 847 728 848 for (i = 0; i < serial->num_ports; ++i) { … … 733 853 if (!portdata) 734 854 continue; 735 736 for (j = 0; j < N_IN_URB; j++) {737 usb_kill_urb(portdata->in_urbs[j]);738 usb_free_urb(portdata->in_urbs[j]);739 kfree(portdata->in_buffer[j]);740 }741 855 kfree(portdata); 742 856 usb_set_serial_port_data(port, NULL); 743 857 } 744 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 }; 745 903 746 904 static struct usb_serial_driver sierra_device = { … … 767 925 .shutdown = sierra_shutdown, 768 926 .read_int_callback = sierra_instat_callback, 927 .suspend = sierra_suspend, 928 .resume = sierra_resume, 769 929 }; 770 930 … … 814 974 module_param(debug, bool, S_IRUGO | S_IWUSR); 815 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.
