InterfaceInit.c revision 949f6711b83d2809d1ccb9d830155a65fdacdff9
1#include "headers.h" 2 3static struct usb_device_id InterfaceUsbtable[] = { 4 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3) }, 5 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3B) }, 6 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3L) }, 7 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_SM250) }, 8 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_226) }, 9 { USB_DEVICE(BCM_USB_VENDOR_ID_FOXCONN, BCM_USB_PRODUCT_ID_1901) }, 10 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_ZTE_TU25) }, 11 { } 12}; 13MODULE_DEVICE_TABLE(usb, InterfaceUsbtable); 14 15static int debug = -1; 16module_param(debug, uint, 0600); 17MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); 18 19static const u32 default_msg = 20 NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK 21 | NETIF_MSG_TIMER | NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR 22 | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN; 23 24static int InterfaceAdapterInit(PS_INTERFACE_ADAPTER Adapter); 25 26static void InterfaceAdapterFree(PS_INTERFACE_ADAPTER psIntfAdapter) 27{ 28 int i = 0; 29 30 /* Wake up the wait_queue... */ 31 if (psIntfAdapter->psAdapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) { 32 psIntfAdapter->psAdapter->DriverState = DRIVER_HALT; 33 wake_up(&psIntfAdapter->psAdapter->LEDInfo.notify_led_event); 34 } 35 reset_card_proc(psIntfAdapter->psAdapter); 36 37 /* 38 * worst case time taken by the RDM/WRM will be 5 sec. will check after every 100 ms 39 * to accertain the device is not being accessed. After this No RDM/WRM should be made. 40 */ 41 while (psIntfAdapter->psAdapter->DeviceAccess) { 42 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 43 "Device is being accessed.\n"); 44 msleep(100); 45 } 46 /* Free interrupt URB */ 47 /* psIntfAdapter->psAdapter->device_removed = TRUE; */ 48 usb_free_urb(psIntfAdapter->psInterruptUrb); 49 50 /* Free transmit URBs */ 51 for (i = 0; i < MAXIMUM_USB_TCB; i++) { 52 if (psIntfAdapter->asUsbTcb[i].urb != NULL) { 53 usb_free_urb(psIntfAdapter->asUsbTcb[i].urb); 54 psIntfAdapter->asUsbTcb[i].urb = NULL; 55 } 56 } 57 /* Free receive URB and buffers */ 58 for (i = 0; i < MAXIMUM_USB_RCB; i++) { 59 if (psIntfAdapter->asUsbRcb[i].urb != NULL) { 60 kfree(psIntfAdapter->asUsbRcb[i].urb->transfer_buffer); 61 usb_free_urb(psIntfAdapter->asUsbRcb[i].urb); 62 psIntfAdapter->asUsbRcb[i].urb = NULL; 63 } 64 } 65 AdapterFree(psIntfAdapter->psAdapter); 66} 67 68static void ConfigureEndPointTypesThroughEEPROM(PMINI_ADAPTER Adapter) 69{ 70 unsigned long ulReg = 0; 71 int ret; 72 73 /* Program EP2 MAX_PKT_SIZE */ 74 ulReg = ntohl(EP2_MPS_REG); 75 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x128, 4, TRUE); 76 ulReg = ntohl(EP2_MPS); 77 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x12C, 4, TRUE); 78 79 ulReg = ntohl(EP2_CFG_REG); 80 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x132, 4, TRUE); 81 if (((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter))->bHighSpeedDevice == TRUE) { 82 ulReg = ntohl(EP2_CFG_INT); 83 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE); 84 } else { 85 /* USE BULK EP as TX in FS mode. */ 86 ulReg = ntohl(EP2_CFG_BULK); 87 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE); 88 } 89 90 /* Program EP4 MAX_PKT_SIZE. */ 91 ulReg = ntohl(EP4_MPS_REG); 92 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x13C, 4, TRUE); 93 ulReg = ntohl(EP4_MPS); 94 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x140, 4, TRUE); 95 96 /* Program TX EP as interrupt(Alternate Setting) */ 97 ret = rdmalt(Adapter, 0x0F0110F8, (u32 *)&ulReg, sizeof(u32)); 98 if (ret) { 99 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 100 "reading of Tx EP failed\n"); 101 return; 102 } 103 ulReg |= 0x6; 104 105 ulReg = ntohl(ulReg); 106 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1CC, 4, TRUE); 107 108 ulReg = ntohl(EP4_CFG_REG); 109 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C8, 4, TRUE); 110 /* Program ISOCHRONOUS EP size to zero. */ 111 ulReg = ntohl(ISO_MPS_REG); 112 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1D2, 4, TRUE); 113 ulReg = ntohl(ISO_MPS); 114 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1D6, 4, TRUE); 115 116 /* 117 * Update EEPROM Version. 118 * Read 4 bytes from 508 and modify 511 and 510. 119 */ 120 ReadBeceemEEPROM(Adapter, 0x1FC, (PUINT)&ulReg); 121 ulReg &= 0x0101FFFF; 122 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1FC, 4, TRUE); 123 124 /* Update length field if required. Also make the string NULL terminated. */ 125 126 ReadBeceemEEPROM(Adapter, 0xA8, (PUINT)&ulReg); 127 if ((ulReg&0x00FF0000)>>16 > 0x30) { 128 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16); 129 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0xA8, 4, TRUE); 130 } 131 ReadBeceemEEPROM(Adapter, 0x148, (PUINT)&ulReg); 132 if ((ulReg&0x00FF0000)>>16 > 0x30) { 133 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16); 134 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x148, 4, TRUE); 135 } 136 ulReg = 0; 137 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x122, 4, TRUE); 138 ulReg = 0; 139 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C2, 4, TRUE); 140} 141 142static int 143usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id) 144{ 145 struct usb_device *udev = interface_to_usbdev(intf); 146 int retval; 147 PMINI_ADAPTER psAdapter; 148 PS_INTERFACE_ADAPTER psIntfAdapter; 149 struct net_device *ndev; 150 151 /* Reserve one extra queue for the bit-bucket */ 152 ndev = alloc_etherdev_mq(sizeof(MINI_ADAPTER), NO_OF_QUEUES+1); 153 if (ndev == NULL) { 154 dev_err(&udev->dev, DRV_NAME ": no memory for device\n"); 155 return -ENOMEM; 156 } 157 158 SET_NETDEV_DEV(ndev, &intf->dev); 159 160 psAdapter = netdev_priv(ndev); 161 psAdapter->dev = ndev; 162 psAdapter->msg_enable = netif_msg_init(debug, default_msg); 163 164 /* Init default driver debug state */ 165 166 psAdapter->stDebugState.debug_level = DBG_LVL_CURR; 167 psAdapter->stDebugState.type = DBG_TYPE_INITEXIT; 168 169 /* 170 * Technically, one can start using BCM_DEBUG_PRINT after this point. 171 * However, realize that by default the Type/Subtype bitmaps are all zero now; 172 * so no prints will actually appear until the TestApp turns on debug paths via 173 * the ioctl(); so practically speaking, in early init, no logging happens. 174 * 175 * A solution (used below): we explicitly set the bitmaps to 1 for Type=DBG_TYPE_INITEXIT 176 * and ALL subtype's of the same. Now all bcm debug statements get logged, enabling debug 177 * during early init. 178 * Further, we turn this OFF once init_module() completes. 179 */ 180 181 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0xff; 182 BCM_SHOW_DEBUG_BITMAP(psAdapter); 183 184 retval = InitAdapter(psAdapter); 185 if (retval) { 186 dev_err(&udev->dev, DRV_NAME ": InitAdapter Failed\n"); 187 AdapterFree(psAdapter); 188 return retval; 189 } 190 191 /* Allocate interface adapter structure */ 192 psIntfAdapter = kzalloc(sizeof(S_INTERFACE_ADAPTER), GFP_KERNEL); 193 if (psIntfAdapter == NULL) { 194 dev_err(&udev->dev, DRV_NAME ": no memory for Interface adapter\n"); 195 AdapterFree(psAdapter); 196 return -ENOMEM; 197 } 198 199 psAdapter->pvInterfaceAdapter = psIntfAdapter; 200 psIntfAdapter->psAdapter = psAdapter; 201 202 /* Store usb interface in Interface Adapter */ 203 psIntfAdapter->interface = intf; 204 usb_set_intfdata(intf, psIntfAdapter); 205 206 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 207 "psIntfAdapter 0x%p\n", psIntfAdapter); 208 retval = InterfaceAdapterInit(psIntfAdapter); 209 if (retval) { 210 /* If the Firmware/Cfg File is not present 211 * then return success, let the application 212 * download the files. 213 */ 214 if (-ENOENT == retval) { 215 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 216 "File Not Found. Use app to download.\n"); 217 return STATUS_SUCCESS; 218 } 219 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 220 "InterfaceAdapterInit failed.\n"); 221 usb_set_intfdata(intf, NULL); 222 udev = interface_to_usbdev(intf); 223 usb_put_dev(udev); 224 InterfaceAdapterFree(psIntfAdapter); 225 return retval; 226 } 227 if (psAdapter->chip_id > T3) { 228 uint32_t uiNackZeroLengthInt = 4; 229 230 retval = wrmalt(psAdapter, DISABLE_USB_ZERO_LEN_INT, &uiNackZeroLengthInt, sizeof(uiNackZeroLengthInt)); 231 if (retval) 232 return retval; 233 } 234 235 /* Check whether the USB-Device Supports remote Wake-Up */ 236 if (USB_CONFIG_ATT_WAKEUP & udev->actconfig->desc.bmAttributes) { 237 /* If Suspend then only support dynamic suspend */ 238 if (psAdapter->bDoSuspend) { 239#ifdef CONFIG_PM 240 pm_runtime_set_autosuspend_delay(&udev->dev, 0); 241 intf->needs_remote_wakeup = 1; 242 usb_enable_autosuspend(udev); 243 device_init_wakeup(&intf->dev, 1); 244 INIT_WORK(&psIntfAdapter->usbSuspendWork, putUsbSuspend); 245 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 246 "Enabling USB Auto-Suspend\n"); 247#endif 248 } else { 249 intf->needs_remote_wakeup = 0; 250 usb_disable_autosuspend(udev); 251 } 252 } 253 254 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0x0; 255 return retval; 256} 257 258static void usbbcm_disconnect(struct usb_interface *intf) 259{ 260 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf); 261 PMINI_ADAPTER psAdapter; 262 struct usb_device *udev = interface_to_usbdev(intf); 263 264 if (psIntfAdapter == NULL) 265 return; 266 267 psAdapter = psIntfAdapter->psAdapter; 268 netif_device_detach(psAdapter->dev); 269 270 if (psAdapter->bDoSuspend) 271 intf->needs_remote_wakeup = 0; 272 273 psAdapter->device_removed = TRUE ; 274 usb_set_intfdata(intf, NULL); 275 InterfaceAdapterFree(psIntfAdapter); 276 usb_put_dev(udev); 277} 278 279static int AllocUsbCb(PS_INTERFACE_ADAPTER psIntfAdapter) 280{ 281 int i = 0; 282 283 for (i = 0; i < MAXIMUM_USB_TCB; i++) { 284 if ((psIntfAdapter->asUsbTcb[i].urb = 285 usb_alloc_urb(0, GFP_KERNEL)) == NULL) { 286 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, 287 "Can't allocate Tx urb for index %d\n", i); 288 return -ENOMEM; 289 } 290 } 291 292 for (i = 0; i < MAXIMUM_USB_RCB; i++) { 293 if ((psIntfAdapter->asUsbRcb[i].urb = 294 usb_alloc_urb(0, GFP_KERNEL)) == NULL) { 295 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, 296 "Can't allocate Rx urb for index %d\n", i); 297 return -ENOMEM; 298 } 299 if ((psIntfAdapter->asUsbRcb[i].urb->transfer_buffer = 300 kmalloc(MAX_DATA_BUFFER_SIZE, GFP_KERNEL)) == NULL) { 301 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, 302 "Can't allocate Rx buffer for index %d\n", i); 303 return -ENOMEM; 304 } 305 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer_length = MAX_DATA_BUFFER_SIZE; 306 } 307 return 0; 308} 309 310static int device_run(PS_INTERFACE_ADAPTER psIntfAdapter) 311{ 312 int value = 0; 313 UINT status = STATUS_SUCCESS; 314 315 status = InitCardAndDownloadFirmware(psIntfAdapter->psAdapter); 316 if (status != STATUS_SUCCESS) { 317 pr_err(DRV_NAME "InitCardAndDownloadFirmware failed.\n"); 318 return status; 319 } 320 if (TRUE == psIntfAdapter->psAdapter->fw_download_done) { 321 if (StartInterruptUrb(psIntfAdapter)) { 322 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 323 "Cannot send interrupt in URB\n"); 324 } 325 326 /* 327 * now register the cntrl interface. 328 * after downloading the f/w waiting for 5 sec to get the mailbox interrupt. 329 */ 330 psIntfAdapter->psAdapter->waiting_to_fw_download_done = FALSE; 331 value = wait_event_timeout(psIntfAdapter->psAdapter->ioctl_fw_dnld_wait_queue, 332 psIntfAdapter->psAdapter->waiting_to_fw_download_done, 5*HZ); 333 334 if (value == 0) 335 pr_err(DRV_NAME ": Timeout waiting for mailbox interrupt.\n"); 336 337 if (register_control_device_interface(psIntfAdapter->psAdapter) < 0) { 338 pr_err(DRV_NAME ": Register Control Device failed.\n"); 339 return -EIO; 340 } 341 } 342 return 0; 343} 344 345 346static inline int bcm_usb_endpoint_num(const struct usb_endpoint_descriptor *epd) 347{ 348 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 349} 350 351static inline int bcm_usb_endpoint_type(const struct usb_endpoint_descriptor *epd) 352{ 353 return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; 354} 355 356static inline int bcm_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd) 357{ 358 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN); 359} 360 361static inline int bcm_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd) 362{ 363 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT); 364} 365 366static inline int bcm_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd) 367{ 368 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 369 USB_ENDPOINT_XFER_BULK); 370} 371 372static inline int bcm_usb_endpoint_xfer_control(const struct usb_endpoint_descriptor *epd) 373{ 374 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 375 USB_ENDPOINT_XFER_CONTROL); 376} 377 378static inline int bcm_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd) 379{ 380 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 381 USB_ENDPOINT_XFER_INT); 382} 383 384static inline int bcm_usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd) 385{ 386 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 387 USB_ENDPOINT_XFER_ISOC); 388} 389 390static inline int bcm_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd) 391{ 392 return (bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_in(epd)); 393} 394 395static inline int bcm_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd) 396{ 397 return (bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_out(epd)); 398} 399 400static inline int bcm_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd) 401{ 402 return (bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_in(epd)); 403} 404 405static inline int bcm_usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd) 406{ 407 return (bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_out(epd)); 408} 409 410static inline int bcm_usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd) 411{ 412 return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_in(epd)); 413} 414 415static inline int bcm_usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd) 416{ 417 return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_out(epd)); 418} 419 420static int InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter) 421{ 422 struct usb_host_interface *iface_desc; 423 struct usb_endpoint_descriptor *endpoint; 424 size_t buffer_size; 425 unsigned long value; 426 int retval = 0; 427 int usedIntOutForBulkTransfer = 0 ; 428 BOOLEAN bBcm16 = FALSE; 429 UINT uiData = 0; 430 431 /* Store the usb dev into interface adapter */ 432 psIntfAdapter->udev = usb_get_dev(interface_to_usbdev(psIntfAdapter->interface)); 433 434 psIntfAdapter->bHighSpeedDevice = (psIntfAdapter->udev->speed == USB_SPEED_HIGH); 435 psIntfAdapter->psAdapter->interface_rdm = BcmRDM; 436 psIntfAdapter->psAdapter->interface_wrm = BcmWRM; 437 438 retval = rdmalt(psIntfAdapter->psAdapter, CHIP_ID_REG, 439 (u32 *)&(psIntfAdapter->psAdapter->chip_id), sizeof(u32)); 440 if (retval) { 441 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, "CHIP ID Read Failed\n"); 442 return retval; 443 } 444 445 if (0xbece3200 == (psIntfAdapter->psAdapter->chip_id & ~(0xF0))) 446 psIntfAdapter->psAdapter->chip_id &= ~0xF0; 447 448 dev_info(&psIntfAdapter->udev->dev, "RDM Chip ID 0x%lx\n", 449 psIntfAdapter->psAdapter->chip_id); 450 451 iface_desc = psIntfAdapter->interface->cur_altsetting; 452 453 if (psIntfAdapter->psAdapter->chip_id == T3B) { 454 /* T3B device will have EEPROM, check if EEPROM is proper and BCM16 can be done or not. */ 455 BeceemEEPROMBulkRead(psIntfAdapter->psAdapter, &uiData, 0x0, 4); 456 if (uiData == BECM) 457 bBcm16 = TRUE; 458 459 dev_info(&psIntfAdapter->udev->dev, "number of alternate setting %d\n", 460 psIntfAdapter->interface->num_altsetting); 461 462 if (bBcm16 == TRUE) { 463 /* selecting alternate setting one as a default setting for High Speed modem. */ 464 if (psIntfAdapter->bHighSpeedDevice) 465 retval= usb_set_interface(psIntfAdapter->udev, DEFAULT_SETTING_0, ALTERNATE_SETTING_1); 466 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 467 "BCM16 is applicable on this dongle\n"); 468 if (retval || (psIntfAdapter->bHighSpeedDevice == FALSE)) { 469 usedIntOutForBulkTransfer = EP2 ; 470 endpoint = &iface_desc->endpoint[EP2].desc; 471 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 472 "Interface altsetting failed or modem is configured to Full Speed, hence will work on default setting 0\n"); 473 /* 474 * If Modem is high speed device EP2 should be INT OUT End point 475 * If Mode is FS then EP2 should be bulk end point 476 */ 477 if (((psIntfAdapter->bHighSpeedDevice == TRUE) && (bcm_usb_endpoint_is_int_out(endpoint) == FALSE)) 478 || ((psIntfAdapter->bHighSpeedDevice == FALSE) && (bcm_usb_endpoint_is_bulk_out(endpoint) == FALSE))) { 479 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 480 "Configuring the EEPROM\n"); 481 /* change the EP2, EP4 to INT OUT end point */ 482 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter); 483 484 /* 485 * It resets the device and if any thing gets changed 486 * in USB descriptor it will show fail and re-enumerate 487 * the device 488 */ 489 retval = usb_reset_device(psIntfAdapter->udev); 490 if (retval) { 491 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 492 "reset failed. Re-enumerating the device.\n"); 493 return retval ; 494 } 495 496 } 497 if ((psIntfAdapter->bHighSpeedDevice == FALSE) && bcm_usb_endpoint_is_bulk_out(endpoint)) { 498 /* Once BULK is selected in FS mode. Revert it back to INT. Else USB_IF will fail. */ 499 UINT _uiData = ntohl(EP2_CFG_INT); 500 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 501 "Reverting Bulk to INT as it is in Full Speed mode.\n"); 502 BeceemEEPROMBulkWrite(psIntfAdapter->psAdapter, (PUCHAR)&_uiData, 0x136, 4, TRUE); 503 } 504 } else { 505 usedIntOutForBulkTransfer = EP4 ; 506 endpoint = &iface_desc->endpoint[EP4].desc; 507 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 508 "Choosing AltSetting as a default setting.\n"); 509 if (bcm_usb_endpoint_is_int_out(endpoint) == FALSE) { 510 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 511 "Dongle does not have BCM16 Fix.\n"); 512 /* change the EP2, EP4 to INT OUT end point and use EP4 in altsetting */ 513 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter); 514 515 /* 516 * It resets the device and if any thing gets changed in 517 * USB descriptor it will show fail and re-enumerate the 518 * device 519 */ 520 retval = usb_reset_device(psIntfAdapter->udev); 521 if (retval) { 522 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 523 "reset failed. Re-enumerating the device.\n"); 524 return retval; 525 } 526 527 } 528 } 529 } 530 } 531 532 iface_desc = psIntfAdapter->interface->cur_altsetting; 533 534 for (value = 0; value < iface_desc->desc.bNumEndpoints; ++value) { 535 endpoint = &iface_desc->endpoint[value].desc; 536 537 if (!psIntfAdapter->sBulkIn.bulk_in_endpointAddr && bcm_usb_endpoint_is_bulk_in(endpoint)) { 538 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 539 psIntfAdapter->sBulkIn.bulk_in_size = buffer_size; 540 psIntfAdapter->sBulkIn.bulk_in_endpointAddr = endpoint->bEndpointAddress; 541 psIntfAdapter->sBulkIn.bulk_in_pipe = 542 usb_rcvbulkpipe(psIntfAdapter->udev, 543 psIntfAdapter->sBulkIn.bulk_in_endpointAddr); 544 } 545 546 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr && bcm_usb_endpoint_is_bulk_out(endpoint)) { 547 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = endpoint->bEndpointAddress; 548 psIntfAdapter->sBulkOut.bulk_out_pipe = 549 usb_sndbulkpipe(psIntfAdapter->udev, 550 psIntfAdapter->sBulkOut.bulk_out_endpointAddr); 551 } 552 553 if (!psIntfAdapter->sIntrIn.int_in_endpointAddr && bcm_usb_endpoint_is_int_in(endpoint)) { 554 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 555 psIntfAdapter->sIntrIn.int_in_size = buffer_size; 556 psIntfAdapter->sIntrIn.int_in_endpointAddr = endpoint->bEndpointAddress; 557 psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval; 558 psIntfAdapter->sIntrIn.int_in_buffer = 559 kmalloc(buffer_size, GFP_KERNEL); 560 if (!psIntfAdapter->sIntrIn.int_in_buffer) { 561 dev_err(&psIntfAdapter->udev->dev, 562 "could not allocate interrupt_in_buffer\n"); 563 return -EINVAL; 564 } 565 } 566 567 if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint)) { 568 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr && 569 (psIntfAdapter->psAdapter->chip_id == T3B) && (value == usedIntOutForBulkTransfer)) { 570 /* use first intout end point as a bulk out end point */ 571 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 572 psIntfAdapter->sBulkOut.bulk_out_size = buffer_size; 573 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = endpoint->bEndpointAddress; 574 psIntfAdapter->sBulkOut.bulk_out_pipe = usb_sndintpipe(psIntfAdapter->udev, 575 psIntfAdapter->sBulkOut.bulk_out_endpointAddr); 576 psIntfAdapter->sBulkOut.int_out_interval = endpoint->bInterval; 577 } else if (value == EP6) { 578 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 579 psIntfAdapter->sIntrOut.int_out_size = buffer_size; 580 psIntfAdapter->sIntrOut.int_out_endpointAddr = endpoint->bEndpointAddress; 581 psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval; 582 psIntfAdapter->sIntrOut.int_out_buffer= kmalloc(buffer_size, GFP_KERNEL); 583 if (!psIntfAdapter->sIntrOut.int_out_buffer) { 584 dev_err(&psIntfAdapter->udev->dev, 585 "could not allocate interrupt_out_buffer\n"); 586 return -EINVAL; 587 } 588 } 589 } 590 } 591 592 usb_set_intfdata(psIntfAdapter->interface, psIntfAdapter); 593 594 psIntfAdapter->psAdapter->bcm_file_download = InterfaceFileDownload; 595 psIntfAdapter->psAdapter->bcm_file_readback_from_chip = 596 InterfaceFileReadbackFromChip; 597 psIntfAdapter->psAdapter->interface_transmit = InterfaceTransmitPacket; 598 599 retval = CreateInterruptUrb(psIntfAdapter); 600 601 if (retval) { 602 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, 603 "Cannot create interrupt urb\n"); 604 return retval; 605 } 606 607 retval = AllocUsbCb(psIntfAdapter); 608 if (retval) 609 return retval; 610 611 return device_run(psIntfAdapter); 612} 613 614static int InterfaceSuspend(struct usb_interface *intf, pm_message_t message) 615{ 616 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf); 617 618 psIntfAdapter->bSuspended = TRUE; 619 620 if (TRUE == psIntfAdapter->bPreparingForBusSuspend) { 621 psIntfAdapter->bPreparingForBusSuspend = FALSE; 622 623 if (psIntfAdapter->psAdapter->LinkStatus == LINKUP_DONE) { 624 psIntfAdapter->psAdapter->IdleMode = TRUE ; 625 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 626 "Host Entered in PMU Idle Mode.\n"); 627 } else { 628 psIntfAdapter->psAdapter->bShutStatus = TRUE; 629 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, 630 "Host Entered in PMU Shutdown Mode.\n"); 631 } 632 } 633 psIntfAdapter->psAdapter->bPreparingForLowPowerMode = FALSE; 634 635 /* Signaling the control pkt path */ 636 wake_up(&psIntfAdapter->psAdapter->lowpower_mode_wait_queue); 637 638 return 0; 639} 640 641static int InterfaceResume(struct usb_interface *intf) 642{ 643 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf); 644 mdelay(100); 645 646 psIntfAdapter->bSuspended = FALSE; 647 648 StartInterruptUrb(psIntfAdapter); 649 InterfaceRx(psIntfAdapter); 650 return 0; 651} 652 653static struct usb_driver usbbcm_driver = { 654 .name = "usbbcm", 655 .probe = usbbcm_device_probe, 656 .disconnect = usbbcm_disconnect, 657 .suspend = InterfaceSuspend, 658 .resume = InterfaceResume, 659 .id_table = InterfaceUsbtable, 660 .supports_autosuspend = 1, 661}; 662 663struct class *bcm_class; 664 665static __init int bcm_init(void) 666{ 667 printk(KERN_INFO "%s: %s, %s\n", DRV_NAME, DRV_DESCRIPTION, DRV_VERSION); 668 printk(KERN_INFO "%s\n", DRV_COPYRIGHT); 669 670 bcm_class = class_create(THIS_MODULE, DRV_NAME); 671 if (IS_ERR(bcm_class)) { 672 printk(KERN_ERR DRV_NAME ": could not create class\n"); 673 return PTR_ERR(bcm_class); 674 } 675 676 return usb_register(&usbbcm_driver); 677} 678 679static __exit void bcm_exit(void) 680{ 681 usb_deregister(&usbbcm_driver); 682 class_destroy(bcm_class); 683} 684 685module_init(bcm_init); 686module_exit(bcm_exit); 687 688MODULE_DESCRIPTION(DRV_DESCRIPTION); 689MODULE_VERSION(DRV_VERSION); 690MODULE_LICENSE("GPL"); 691