beceem: create class on module installation
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / bcm / InterfaceInit.c
blob161141d14565f3606947e5f2b3077a2f683dd50c
1 #include "headers.h"
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) },
10 { }
12 MODULE_DEVICE_TABLE(usb, InterfaceUsbtable);
14 static unsigned int debug_level = DBG_LVL_CURR;
15 module_param(debug_level, uint, 0644);
16 MODULE_PARM_DESC(debug_level, "Debug level (0=none,...,7=all)");
19 VOID InterfaceAdapterFree(PS_INTERFACE_ADAPTER psIntfAdapter)
21 INT i = 0;
22 // Wake up the wait_queue...
23 if(psIntfAdapter->psAdapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
25 psIntfAdapter->psAdapter->DriverState = DRIVER_HALT;
26 wake_up(&psIntfAdapter->psAdapter->LEDInfo.notify_led_event);
28 reset_card_proc(psIntfAdapter->psAdapter);
30 //worst case time taken by the RDM/WRM will be 5 sec. will check after every 100 ms
31 //to accertain the device is not being accessed. After this No RDM/WRM should be made.
32 while(psIntfAdapter->psAdapter->DeviceAccess)
34 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Device is being Accessed \n");
35 msleep(100);
37 /* Free interrupt URB */
38 //psIntfAdapter->psAdapter->device_removed = TRUE;
39 if(psIntfAdapter->psInterruptUrb)
41 usb_free_urb(psIntfAdapter->psInterruptUrb);
44 /* Free transmit URBs */
45 for(i = 0; i < MAXIMUM_USB_TCB; i++)
47 if(psIntfAdapter->asUsbTcb[i].urb != NULL)
49 usb_free_urb(psIntfAdapter->asUsbTcb[i].urb);
50 psIntfAdapter->asUsbTcb[i].urb = NULL;
53 /* Free receive URB and buffers */
54 for(i = 0; i < MAXIMUM_USB_RCB; i++)
56 if (psIntfAdapter->asUsbRcb[i].urb != NULL)
58 kfree(psIntfAdapter->asUsbRcb[i].urb->transfer_buffer);
59 usb_free_urb(psIntfAdapter->asUsbRcb[i].urb);
60 psIntfAdapter->asUsbRcb[i].urb = NULL;
63 AdapterFree(psIntfAdapter->psAdapter);
66 VOID ConfigureEndPointTypesThroughEEPROM(PMINI_ADAPTER Adapter)
68 ULONG ulReg = 0;
70 // Program EP2 MAX_PKT_SIZE
71 ulReg = ntohl(EP2_MPS_REG);
72 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x128,4,TRUE);
73 ulReg = ntohl(EP2_MPS);
74 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x12C,4,TRUE);
76 ulReg = ntohl(EP2_CFG_REG);
77 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x132,4,TRUE);
78 if(((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter))->bHighSpeedDevice == TRUE)
80 ulReg = ntohl(EP2_CFG_INT);
81 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x136,4,TRUE);
83 else
85 // USE BULK EP as TX in FS mode.
86 ulReg = ntohl(EP2_CFG_BULK);
87 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x136,4,TRUE);
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);
97 // Program TX EP as interrupt (Alternate Setting)
98 if( rdmalt(Adapter,0x0F0110F8, (PUINT)&ulReg,4))
100 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reading of Tx EP is failing");
101 return ;
103 ulReg |= 0x6;
105 ulReg = ntohl(ulReg);
106 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1CC,4,TRUE);
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);
116 // Update EEPROM Version.
117 // Read 4 bytes from 508 and modify 511 and 510.
119 ReadBeceemEEPROM(Adapter,0x1FC,(PUINT)&ulReg);
120 ulReg &= 0x0101FFFF;
121 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1FC,4,TRUE);
123 //Update length field if required. Also make the string NULL terminated.
125 ReadBeceemEEPROM(Adapter,0xA8,(PUINT)&ulReg);
126 if((ulReg&0x00FF0000)>>16 > 0x30)
128 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
129 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0xA8,4,TRUE);
131 ReadBeceemEEPROM(Adapter,0x148,(PUINT)&ulReg);
132 if((ulReg&0x00FF0000)>>16 > 0x30)
134 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
135 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x148,4,TRUE);
137 ulReg = 0;
138 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x122,4,TRUE);
139 ulReg = 0;
140 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1C2,4,TRUE);
144 static int
145 usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id)
147 struct usb_device *udev = interface_to_usbdev (intf);
148 int retval;
149 PMINI_ADAPTER psAdapter;
150 PS_INTERFACE_ADAPTER psIntfAdapter;
151 struct net_device *ndev;
153 /* Reserve one extra queue for the bit-bucket */
154 ndev = alloc_etherdev_mq(sizeof(MINI_ADAPTER), NO_OF_QUEUES+1);
155 if(ndev == NULL) {
156 dev_err(&udev->dev, DRV_NAME ": no memory for device\n");
157 return -ENOMEM;
160 SET_NETDEV_DEV(ndev, &intf->dev);
162 psAdapter = netdev_priv(ndev);
163 psAdapter->dev = ndev;
165 /* Init default driver debug state */
167 psAdapter->stDebugState.debug_level = debug_level;
168 psAdapter->stDebugState.type = DBG_TYPE_INITEXIT;
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.
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.
181 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0xff;
182 BCM_SHOW_DEBUG_BITMAP(psAdapter);
184 retval = InitAdapter(psAdapter);
185 if(retval)
187 dev_err(&udev->dev, DRV_NAME ": InitAdapter Failed\n");
188 AdapterFree(psAdapter);
189 return retval;
192 /* Allocate interface adapter structure */
193 psIntfAdapter = kzalloc(sizeof(S_INTERFACE_ADAPTER), GFP_KERNEL);
194 if (psIntfAdapter == NULL)
196 dev_err(&udev->dev, DRV_NAME ": no memory for Interface adapter\n");
197 AdapterFree (psAdapter);
198 return -ENOMEM;
201 psAdapter->pvInterfaceAdapter = psIntfAdapter;
202 psIntfAdapter->psAdapter = psAdapter;
204 /* Store usb interface in Interface Adapter */
205 psIntfAdapter->interface = intf;
206 usb_set_intfdata(intf, psIntfAdapter);
208 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "psIntfAdapter 0x%p",psIntfAdapter);
209 retval = InterfaceAdapterInit(psIntfAdapter);
210 if(retval)
212 /* If the Firmware/Cfg File is not present
213 * then return success, let the application
214 * download the files.
216 if(-ENOENT == retval){
217 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "File Not Found, Use App to Download\n");
218 return STATUS_SUCCESS;
220 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "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 ;
227 if(psAdapter->chip_id > T3)
229 uint32_t uiNackZeroLengthInt=4;
230 if(wrmalt(psAdapter, DISABLE_USB_ZERO_LEN_INT, &uiNackZeroLengthInt, sizeof(uiNackZeroLengthInt)))
232 return -EIO;;
236 /* Check whether the USB-Device Supports remote Wake-Up */
237 if(USB_CONFIG_ATT_WAKEUP & udev->actconfig->desc.bmAttributes)
239 /* If Suspend then only support dynamic suspend */
240 if(psAdapter->bDoSuspend)
242 #ifdef CONFIG_PM
243 udev->autosuspend_delay = 0;
244 intf->needs_remote_wakeup = 1;
245 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
246 udev->autosuspend_disabled = 0;
247 #else
248 usb_enable_autosuspend(udev);
249 #endif
250 device_init_wakeup(&intf->dev,1);
251 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32)
252 usb_autopm_disable(intf);
253 #endif
254 INIT_WORK(&psIntfAdapter->usbSuspendWork, putUsbSuspend);
255 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Enabling USB Auto-Suspend\n");
256 #endif
258 else
260 intf->needs_remote_wakeup = 0;
261 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
262 udev->autosuspend_disabled = 1;
263 #else
264 usb_disable_autosuspend(udev);
265 #endif
269 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0x0;
270 return retval;
273 static void usbbcm_disconnect (struct usb_interface *intf)
275 PS_INTERFACE_ADAPTER psIntfAdapter = NULL;
276 PMINI_ADAPTER psAdapter = NULL;
277 struct usb_device *udev = NULL;
278 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
280 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Usb disconnected");
281 if(intf == NULL)
283 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "intf pointer is NULL");
284 return;
286 psIntfAdapter = usb_get_intfdata(intf);
287 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "psIntfAdapter 0x%p",psIntfAdapter);
288 if(psIntfAdapter == NULL)
290 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "InterfaceAdapter pointer is NULL");
291 return;
293 psAdapter = psIntfAdapter->psAdapter;
294 if(psAdapter->bDoSuspend)
295 intf->needs_remote_wakeup = 0;
297 psAdapter->device_removed = TRUE ;
298 usb_set_intfdata(intf, NULL);
299 InterfaceAdapterFree(psIntfAdapter);
300 udev = interface_to_usbdev (intf);
301 usb_put_dev(udev);
304 static int AllocUsbCb(PS_INTERFACE_ADAPTER psIntfAdapter)
306 int i = 0;
307 for(i = 0; i < MAXIMUM_USB_TCB; i++)
309 if((psIntfAdapter->asUsbTcb[i].urb =
310 usb_alloc_urb(0, GFP_KERNEL)) == NULL)
312 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cant allocate Tx urb for index %d", i);
313 return -ENOMEM;
317 for(i = 0; i < MAXIMUM_USB_RCB; i++)
319 if ((psIntfAdapter->asUsbRcb[i].urb =
320 usb_alloc_urb(0, GFP_KERNEL)) == NULL)
322 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cant allocate Rx urb for index %d", i);
323 return -ENOMEM;
325 if((psIntfAdapter->asUsbRcb[i].urb->transfer_buffer =
326 kmalloc(MAX_DATA_BUFFER_SIZE, GFP_KERNEL)) == NULL)
328 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cant allocate Rx buffer for index %d", i);
329 return -ENOMEM;
331 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer_length = MAX_DATA_BUFFER_SIZE;
333 return 0;
338 static int device_run(PS_INTERFACE_ADAPTER psIntfAdapter)
340 INT value = 0;
341 UINT status = STATUS_SUCCESS;
343 status = InitCardAndDownloadFirmware(psIntfAdapter->psAdapter);
344 if(status != STATUS_SUCCESS)
346 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "InitCardAndDownloadFirmware failed.\n");
347 return status;
349 if(TRUE == psIntfAdapter->psAdapter->fw_download_done)
352 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Sending first interrupt URB down......");
353 if(StartInterruptUrb(psIntfAdapter))
355 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Cannot send interrupt in URB");
357 //now register the cntrl interface.
358 //after downloading the f/w waiting for 5 sec to get the mailbox interrupt.
360 psIntfAdapter->psAdapter->waiting_to_fw_download_done = FALSE;
361 value = wait_event_timeout(psIntfAdapter->psAdapter->ioctl_fw_dnld_wait_queue,
362 psIntfAdapter->psAdapter->waiting_to_fw_download_done, 5*HZ);
364 if(value == 0)
366 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Mailbox Interrupt has not reached to Driver..");
368 else
370 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Got the mailbox interrupt ...Registering control interface...\n ");
372 if(register_control_device_interface(psIntfAdapter->psAdapter) < 0)
374 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Register Control Device failed...");
375 return -EIO;
378 return 0;
382 static inline int bcm_usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
384 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
387 static inline int bcm_usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
389 return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
392 static inline int bcm_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
394 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
397 static inline int bcm_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)
399 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
402 static inline int bcm_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
404 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
405 USB_ENDPOINT_XFER_BULK);
408 static inline int bcm_usb_endpoint_xfer_control(const struct usb_endpoint_descriptor *epd)
410 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
411 USB_ENDPOINT_XFER_CONTROL);
414 static inline int bcm_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
416 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
417 USB_ENDPOINT_XFER_INT);
420 static inline int bcm_usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd)
422 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
423 USB_ENDPOINT_XFER_ISOC);
426 static inline int bcm_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
428 return (bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_in(epd));
431 static inline int bcm_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
433 return (bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_out(epd));
436 static inline int bcm_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
438 return (bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_in(epd));
441 static inline int bcm_usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd)
443 return (bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_out(epd));
446 static inline int bcm_usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd)
448 return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_in(epd));
451 static inline int bcm_usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd)
453 return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_out(epd));
456 INT InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter)
458 struct usb_host_interface *iface_desc;
459 struct usb_endpoint_descriptor *endpoint;
460 size_t buffer_size;
461 ULONG value;
462 INT retval = 0;
463 INT usedIntOutForBulkTransfer = 0 ;
464 BOOLEAN bBcm16 = FALSE;
465 UINT uiData = 0;
467 /* Store the usb dev into interface adapter */
468 psIntfAdapter->udev = usb_get_dev(interface_to_usbdev(
469 psIntfAdapter->interface));
471 if((psIntfAdapter->udev->speed == USB_SPEED_HIGH))
473 psIntfAdapter->bHighSpeedDevice = TRUE ;
474 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "MODEM IS CONFIGURED TO HIGH_SPEED ");
476 else
478 psIntfAdapter->bHighSpeedDevice = FALSE ;
479 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "MODEM IS CONFIGURED TO FULL_SPEED ");
482 psIntfAdapter->psAdapter->interface_rdm = BcmRDM;
483 psIntfAdapter->psAdapter->interface_wrm = BcmWRM;
485 if(rdmalt(psIntfAdapter->psAdapter, CHIP_ID_REG, (PUINT)&(psIntfAdapter->psAdapter->chip_id), sizeof(UINT)) < 0)
487 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "CHIP ID Read Failed\n");
488 return STATUS_FAILURE;
490 if(0xbece3200==(psIntfAdapter->psAdapter->chip_id&~(0xF0)))
492 psIntfAdapter->psAdapter->chip_id=(psIntfAdapter->psAdapter->chip_id&~(0xF0));
495 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "First RDM Chip ID 0x%lx\n", psIntfAdapter->psAdapter->chip_id);
497 iface_desc = psIntfAdapter->interface->cur_altsetting;
498 //print_usb_interface_desc(&(iface_desc->desc));
500 if(psIntfAdapter->psAdapter->chip_id == T3B)
504 //T3B device will have EEPROM,check if EEPROM is proper and BCM16 can be done or not.
506 BeceemEEPROMBulkRead(psIntfAdapter->psAdapter,&uiData,0x0,4);
507 if(uiData == BECM)
509 bBcm16 = TRUE;
511 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Number of Altsetting aviailable for This Modem 0x%x\n", psIntfAdapter->interface->num_altsetting);
512 if(bBcm16 == TRUE)
514 //selecting alternate setting one as a default setting for High Speed modem.
515 if(psIntfAdapter->bHighSpeedDevice)
516 retval= usb_set_interface(psIntfAdapter->udev,DEFAULT_SETTING_0,ALTERNATE_SETTING_1);
517 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "BCM16 is Applicable on this dongle");
518 if(retval || (psIntfAdapter->bHighSpeedDevice == FALSE))
520 usedIntOutForBulkTransfer = EP2 ;
521 endpoint = &iface_desc->endpoint[EP2].desc;
522 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");
524 If Modem is high speed device EP2 should be INT OUT End point
525 If Mode is FS then EP2 should be bulk end point
527 if(((psIntfAdapter->bHighSpeedDevice ==TRUE ) && (bcm_usb_endpoint_is_int_out(endpoint)== FALSE))
528 ||((psIntfAdapter->bHighSpeedDevice == FALSE)&& (bcm_usb_endpoint_is_bulk_out(endpoint)== FALSE)))
530 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Configuring the EEPROM ");
531 //change the EP2, EP4 to INT OUT end point
532 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter);
535 It resets the device and if any thing gets changed in USB descriptor it will show fail and
536 re-enumerate the device
538 retval = usb_reset_device(psIntfAdapter->udev);
539 if(retval)
541 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reset got failed. hence Re-enumerating the device \n");
542 return retval ;
546 if((psIntfAdapter->bHighSpeedDevice == FALSE) && bcm_usb_endpoint_is_bulk_out(endpoint))
548 // Once BULK is selected in FS mode. Revert it back to INT. Else USB_IF will fail.
549 UINT _uiData = ntohl(EP2_CFG_INT);
550 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Reverting Bulk to INT as it is FS MODE");
551 BeceemEEPROMBulkWrite(psIntfAdapter->psAdapter,(PUCHAR)&_uiData,0x136,4,TRUE);
554 else
556 usedIntOutForBulkTransfer = EP4 ;
557 endpoint = &iface_desc->endpoint[EP4].desc;
558 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Choosing AltSetting as a default setting");
559 if( bcm_usb_endpoint_is_int_out(endpoint) == FALSE)
561 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, " Dongle does not have BCM16 Fix");
562 //change the EP2, EP4 to INT OUT end point and use EP4 in altsetting
563 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter);
566 It resets the device and if any thing gets changed in USB descriptor it will show fail and
567 re-enumerate the device
569 retval = usb_reset_device(psIntfAdapter->udev);
570 if(retval)
572 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reset got failed. hence Re-enumerating the device \n");
573 return retval ;
581 iface_desc = psIntfAdapter->interface->cur_altsetting;
582 //print_usb_interface_desc(&(iface_desc->desc));
583 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Current number of endpoints :%x \n", iface_desc->desc.bNumEndpoints);
584 for (value = 0; value < iface_desc->desc.bNumEndpoints; ++value)
586 endpoint = &iface_desc->endpoint[value].desc;
587 //print_usb_endpoint_descriptor(endpoint);
589 if (!psIntfAdapter->sBulkIn.bulk_in_endpointAddr && bcm_usb_endpoint_is_bulk_in(endpoint))
591 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
592 psIntfAdapter->sBulkIn.bulk_in_size = buffer_size;
593 psIntfAdapter->sBulkIn.bulk_in_endpointAddr =
594 endpoint->bEndpointAddress;
595 psIntfAdapter->sBulkIn.bulk_in_pipe =
596 usb_rcvbulkpipe(psIntfAdapter->udev,
597 psIntfAdapter->sBulkIn.bulk_in_endpointAddr);
600 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr && bcm_usb_endpoint_is_bulk_out(endpoint))
603 psIntfAdapter->sBulkOut.bulk_out_endpointAddr =
604 endpoint->bEndpointAddress;
605 psIntfAdapter->sBulkOut.bulk_out_pipe =
606 usb_sndbulkpipe(psIntfAdapter->udev,
607 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
610 if (!psIntfAdapter->sIntrIn.int_in_endpointAddr && bcm_usb_endpoint_is_int_in(endpoint))
612 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
613 psIntfAdapter->sIntrIn.int_in_size = buffer_size;
614 psIntfAdapter->sIntrIn.int_in_endpointAddr =
615 endpoint->bEndpointAddress;
616 psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval;
617 psIntfAdapter->sIntrIn.int_in_buffer =
618 kmalloc(buffer_size, GFP_KERNEL);
619 if (!psIntfAdapter->sIntrIn.int_in_buffer) {
620 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Could not allocate interrupt_in_buffer");
621 return -EINVAL;
623 //psIntfAdapter->sIntrIn.int_in_pipe =
626 if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint))
629 if( !psIntfAdapter->sBulkOut.bulk_out_endpointAddr &&
630 (psIntfAdapter->psAdapter->chip_id == T3B) && (value == usedIntOutForBulkTransfer))
632 //use first intout end point as a bulk out end point
633 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
634 psIntfAdapter->sBulkOut.bulk_out_size = buffer_size;
635 //printk("\nINT OUT Endpoing buffer size :%x endpoint :%x\n", buffer_size, value +1);
636 psIntfAdapter->sBulkOut.bulk_out_endpointAddr =
637 endpoint->bEndpointAddress;
638 psIntfAdapter->sBulkOut.bulk_out_pipe =
639 usb_sndintpipe(psIntfAdapter->udev,
640 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
641 psIntfAdapter->sBulkOut.int_out_interval = endpoint->bInterval;
644 else if(value == EP6)
646 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
647 psIntfAdapter->sIntrOut.int_out_size = buffer_size;
648 psIntfAdapter->sIntrOut.int_out_endpointAddr =
649 endpoint->bEndpointAddress;
650 psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval;
651 psIntfAdapter->sIntrOut.int_out_buffer= kmalloc(buffer_size,
652 GFP_KERNEL);
653 if (!psIntfAdapter->sIntrOut.int_out_buffer)
655 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Could not allocate interrupt_out_buffer");
656 return -EINVAL;
661 usb_set_intfdata(psIntfAdapter->interface, psIntfAdapter);
663 psIntfAdapter->psAdapter->bcm_file_download = InterfaceFileDownload;
664 psIntfAdapter->psAdapter->bcm_file_readback_from_chip =
665 InterfaceFileReadbackFromChip;
666 psIntfAdapter->psAdapter->interface_transmit = InterfaceTransmitPacket;
668 retval = CreateInterruptUrb(psIntfAdapter);
670 if(retval)
672 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cannot create interrupt urb");
673 return retval;
676 retval = AllocUsbCb(psIntfAdapter);
677 if(retval)
679 return retval;
683 return device_run(psIntfAdapter);
686 static int InterfaceSuspend (struct usb_interface *intf, pm_message_t message)
688 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
689 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "=================================\n");
690 //Bcm_kill_all_URBs(psIntfAdapter);
691 psIntfAdapter->bSuspended = TRUE;
693 if(TRUE == psIntfAdapter->bPreparingForBusSuspend)
695 psIntfAdapter->bPreparingForBusSuspend = FALSE;
697 if(psIntfAdapter->psAdapter->LinkStatus == LINKUP_DONE)
699 psIntfAdapter->psAdapter->IdleMode = TRUE ;
700 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Host Entered in PMU Idle Mode..");
702 else
704 psIntfAdapter->psAdapter->bShutStatus = TRUE;
705 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Host Entered in PMU Shutdown Mode..");
708 psIntfAdapter->psAdapter->bPreparingForLowPowerMode = FALSE;
710 //Signaling the control pkt path
711 wake_up(&psIntfAdapter->psAdapter->lowpower_mode_wait_queue);
713 return 0;
716 static int InterfaceResume (struct usb_interface *intf)
718 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
719 printk("=================================\n");
720 mdelay(100);
721 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32)
722 intf->pm_usage_cnt =1 ;
723 #endif
724 psIntfAdapter->bSuspended = FALSE;
726 StartInterruptUrb(psIntfAdapter);
727 InterfaceRx(psIntfAdapter);
728 return 0;
731 static struct usb_driver usbbcm_driver = {
732 .name = "usbbcm",
733 .probe = usbbcm_device_probe,
734 .disconnect = usbbcm_disconnect,
735 .suspend = InterfaceSuspend,
736 .resume = InterfaceResume,
737 .id_table = InterfaceUsbtable,
738 .supports_autosuspend = 1,
741 struct class *bcm_class;
744 Function: InterfaceInitialize
746 Description: This is the hardware specific initialization Function.
747 Registering the driver with NDIS , other device specific NDIS
748 and hardware initializations are done here.
750 Input parameters: IN PMINI_ADAPTER Adapter - Miniport Adapter Context
753 Return: BCM_STATUS_SUCCESS - If Initialization of the
754 HW Interface was successful.
755 Other - If an error occured.
757 INT InterfaceInitialize(void)
759 bcm_class = class_create(THIS_MODULE, DRV_NAME);
760 if (IS_ERR(bcm_class)) {
761 printk(KERN_ERR DRV_NAME ": could not create class\n");
762 return PTR_ERR(bcm_class);
764 return usb_register(&usbbcm_driver);
767 INT InterfaceExit(void)
769 class_destroy (bcm_class);
770 usb_deregister(&usbbcm_driver);
771 return 0;