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