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