Staging: Beceem: add USB id for BCSM250 Mobile WiMAX
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / bcm / InterfaceInit.c
blob4a9d8c0d5de785c3fc7e6868f6c7cb26e5a727d6
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_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 { }
13 MODULE_DEVICE_TABLE(usb, InterfaceUsbtable);
15 static int debug = -1;
16 module_param(debug, uint, 0600);
17 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
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;
24 static INT InterfaceAdapterInit(PS_INTERFACE_ADAPTER Adapter);
26 static VOID InterfaceAdapterFree(PS_INTERFACE_ADAPTER psIntfAdapter)
28 INT i = 0;
29 // Wake up the wait_queue...
30 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);
35 reset_card_proc(psIntfAdapter->psAdapter);
37 //worst case time taken by the RDM/WRM will be 5 sec. will check after every 100 ms
38 //to accertain the device is not being accessed. After this No RDM/WRM should be made.
39 while(psIntfAdapter->psAdapter->DeviceAccess)
41 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Device is being Accessed \n");
42 msleep(100);
44 /* Free interrupt URB */
45 //psIntfAdapter->psAdapter->device_removed = TRUE;
46 if(psIntfAdapter->psInterruptUrb)
48 usb_free_urb(psIntfAdapter->psInterruptUrb);
51 /* Free transmit URBs */
52 for(i = 0; i < MAXIMUM_USB_TCB; i++)
54 if(psIntfAdapter->asUsbTcb[i].urb != NULL)
56 usb_free_urb(psIntfAdapter->asUsbTcb[i].urb);
57 psIntfAdapter->asUsbTcb[i].urb = NULL;
60 /* Free receive URB and buffers */
61 for(i = 0; i < MAXIMUM_USB_RCB; i++)
63 if (psIntfAdapter->asUsbRcb[i].urb != NULL)
65 kfree(psIntfAdapter->asUsbRcb[i].urb->transfer_buffer);
66 usb_free_urb(psIntfAdapter->asUsbRcb[i].urb);
67 psIntfAdapter->asUsbRcb[i].urb = NULL;
70 AdapterFree(psIntfAdapter->psAdapter);
73 static VOID ConfigureEndPointTypesThroughEEPROM(PMINI_ADAPTER Adapter)
75 ULONG ulReg = 0;
77 // Program EP2 MAX_PKT_SIZE
78 ulReg = ntohl(EP2_MPS_REG);
79 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x128,4,TRUE);
80 ulReg = ntohl(EP2_MPS);
81 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x12C,4,TRUE);
83 ulReg = ntohl(EP2_CFG_REG);
84 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x132,4,TRUE);
85 if(((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter))->bHighSpeedDevice == TRUE)
87 ulReg = ntohl(EP2_CFG_INT);
88 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x136,4,TRUE);
90 else
92 // USE BULK EP as TX in FS mode.
93 ulReg = ntohl(EP2_CFG_BULK);
94 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x136,4,TRUE);
98 // Program EP4 MAX_PKT_SIZE.
99 ulReg = ntohl(EP4_MPS_REG);
100 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x13C,4,TRUE);
101 ulReg = ntohl(EP4_MPS);
102 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x140,4,TRUE);
104 // Program TX EP as interrupt (Alternate Setting)
105 if( rdmalt(Adapter,0x0F0110F8, (PUINT)&ulReg,4))
107 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reading of Tx EP is failing");
108 return ;
110 ulReg |= 0x6;
112 ulReg = ntohl(ulReg);
113 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1CC,4,TRUE);
115 ulReg = ntohl(EP4_CFG_REG);
116 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1C8,4,TRUE);
117 // Program ISOCHRONOUS EP size to zero.
118 ulReg = ntohl(ISO_MPS_REG);
119 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1D2,4,TRUE);
120 ulReg = ntohl(ISO_MPS);
121 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1D6,4,TRUE);
123 // Update EEPROM Version.
124 // Read 4 bytes from 508 and modify 511 and 510.
126 ReadBeceemEEPROM(Adapter,0x1FC,(PUINT)&ulReg);
127 ulReg &= 0x0101FFFF;
128 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1FC,4,TRUE);
130 //Update length field if required. Also make the string NULL terminated.
132 ReadBeceemEEPROM(Adapter,0xA8,(PUINT)&ulReg);
133 if((ulReg&0x00FF0000)>>16 > 0x30)
135 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
136 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0xA8,4,TRUE);
138 ReadBeceemEEPROM(Adapter,0x148,(PUINT)&ulReg);
139 if((ulReg&0x00FF0000)>>16 > 0x30)
141 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
142 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x148,4,TRUE);
144 ulReg = 0;
145 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x122,4,TRUE);
146 ulReg = 0;
147 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1C2,4,TRUE);
151 static int
152 usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id)
154 struct usb_device *udev = interface_to_usbdev (intf);
155 int retval;
156 PMINI_ADAPTER psAdapter;
157 PS_INTERFACE_ADAPTER psIntfAdapter;
158 struct net_device *ndev;
160 /* Reserve one extra queue for the bit-bucket */
161 ndev = alloc_etherdev_mq(sizeof(MINI_ADAPTER), NO_OF_QUEUES+1);
162 if(ndev == NULL) {
163 dev_err(&udev->dev, DRV_NAME ": no memory for device\n");
164 return -ENOMEM;
167 SET_NETDEV_DEV(ndev, &intf->dev);
169 psAdapter = netdev_priv(ndev);
170 psAdapter->dev = ndev;
171 psAdapter->msg_enable = netif_msg_init(debug, default_msg);
173 /* Init default driver debug state */
175 psAdapter->stDebugState.debug_level = DBG_LVL_CURR;
176 psAdapter->stDebugState.type = DBG_TYPE_INITEXIT;
178 /* Technically, one can start using BCM_DEBUG_PRINT after this point.
179 * However, realize that by default the Type/Subtype bitmaps are all zero now;
180 * so no prints will actually appear until the TestApp turns on debug paths via
181 * the ioctl(); so practically speaking, in early init, no logging happens.
183 * A solution (used below): we explicitly set the bitmaps to 1 for Type=DBG_TYPE_INITEXIT
184 * and ALL subtype's of the same. Now all bcm debug statements get logged, enabling debug
185 * during early init.
186 * Further, we turn this OFF once init_module() completes.
189 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0xff;
190 BCM_SHOW_DEBUG_BITMAP(psAdapter);
192 retval = InitAdapter(psAdapter);
193 if(retval)
195 dev_err(&udev->dev, DRV_NAME ": InitAdapter Failed\n");
196 AdapterFree(psAdapter);
197 return retval;
200 /* Allocate interface adapter structure */
201 psIntfAdapter = kzalloc(sizeof(S_INTERFACE_ADAPTER), GFP_KERNEL);
202 if (psIntfAdapter == NULL)
204 dev_err(&udev->dev, DRV_NAME ": no memory for Interface adapter\n");
205 AdapterFree (psAdapter);
206 return -ENOMEM;
209 psAdapter->pvInterfaceAdapter = psIntfAdapter;
210 psIntfAdapter->psAdapter = psAdapter;
212 /* Store usb interface in Interface Adapter */
213 psIntfAdapter->interface = intf;
214 usb_set_intfdata(intf, psIntfAdapter);
216 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "psIntfAdapter 0x%p",psIntfAdapter);
217 retval = InterfaceAdapterInit(psIntfAdapter);
218 if(retval)
220 /* If the Firmware/Cfg File is not present
221 * then return success, let the application
222 * download the files.
224 if(-ENOENT == retval){
225 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "File Not Found, Use App to Download\n");
226 return STATUS_SUCCESS;
228 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "InterfaceAdapterInit Failed \n");
229 usb_set_intfdata(intf, NULL);
230 udev = interface_to_usbdev (intf);
231 usb_put_dev(udev);
232 InterfaceAdapterFree(psIntfAdapter);
233 return retval ;
235 if(psAdapter->chip_id > T3)
237 uint32_t uiNackZeroLengthInt=4;
238 if(wrmalt(psAdapter, DISABLE_USB_ZERO_LEN_INT, &uiNackZeroLengthInt, sizeof(uiNackZeroLengthInt)))
240 return -EIO;
244 /* Check whether the USB-Device Supports remote Wake-Up */
245 if(USB_CONFIG_ATT_WAKEUP & udev->actconfig->desc.bmAttributes)
247 /* If Suspend then only support dynamic suspend */
248 if(psAdapter->bDoSuspend)
250 #ifdef CONFIG_PM
251 udev->autosuspend_delay = 0;
252 intf->needs_remote_wakeup = 1;
253 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
254 udev->autosuspend_disabled = 0;
255 #else
256 usb_enable_autosuspend(udev);
257 #endif
258 device_init_wakeup(&intf->dev,1);
259 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32)
260 usb_autopm_disable(intf);
261 #endif
262 INIT_WORK(&psIntfAdapter->usbSuspendWork, putUsbSuspend);
263 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Enabling USB Auto-Suspend\n");
264 #endif
266 else
268 intf->needs_remote_wakeup = 0;
269 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
270 udev->autosuspend_disabled = 1;
271 #else
272 usb_disable_autosuspend(udev);
273 #endif
277 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0x0;
278 return retval;
281 static void usbbcm_disconnect (struct usb_interface *intf)
283 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
284 PMINI_ADAPTER psAdapter;
285 struct usb_device *udev = interface_to_usbdev (intf);
287 if(psIntfAdapter == NULL)
288 return;
290 psAdapter = psIntfAdapter->psAdapter;
291 netif_device_detach(psAdapter->dev);
293 if(psAdapter->bDoSuspend)
294 intf->needs_remote_wakeup = 0;
296 psAdapter->device_removed = TRUE ;
297 usb_set_intfdata(intf, NULL);
298 InterfaceAdapterFree(psIntfAdapter);
299 usb_put_dev(udev);
302 static int AllocUsbCb(PS_INTERFACE_ADAPTER psIntfAdapter)
304 int i = 0;
305 for(i = 0; i < MAXIMUM_USB_TCB; i++)
307 if((psIntfAdapter->asUsbTcb[i].urb =
308 usb_alloc_urb(0, GFP_KERNEL)) == NULL)
310 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cant allocate Tx urb for index %d", i);
311 return -ENOMEM;
315 for(i = 0; i < MAXIMUM_USB_RCB; i++)
317 if ((psIntfAdapter->asUsbRcb[i].urb =
318 usb_alloc_urb(0, GFP_KERNEL)) == NULL)
320 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cant allocate Rx urb for index %d", i);
321 return -ENOMEM;
323 if((psIntfAdapter->asUsbRcb[i].urb->transfer_buffer =
324 kmalloc(MAX_DATA_BUFFER_SIZE, GFP_KERNEL)) == NULL)
326 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cant allocate Rx buffer for index %d", i);
327 return -ENOMEM;
329 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer_length = MAX_DATA_BUFFER_SIZE;
331 return 0;
336 static int device_run(PS_INTERFACE_ADAPTER psIntfAdapter)
338 INT value = 0;
339 UINT status = STATUS_SUCCESS;
341 status = InitCardAndDownloadFirmware(psIntfAdapter->psAdapter);
342 if(status != STATUS_SUCCESS)
344 pr_err(DRV_NAME "InitCardAndDownloadFirmware failed.\n");
345 return status;
347 if(TRUE == psIntfAdapter->psAdapter->fw_download_done)
349 if(StartInterruptUrb(psIntfAdapter))
351 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Cannot send interrupt in URB");
353 //now register the cntrl interface.
354 //after downloading the f/w waiting for 5 sec to get the mailbox interrupt.
356 psIntfAdapter->psAdapter->waiting_to_fw_download_done = FALSE;
357 value = wait_event_timeout(psIntfAdapter->psAdapter->ioctl_fw_dnld_wait_queue,
358 psIntfAdapter->psAdapter->waiting_to_fw_download_done, 5*HZ);
360 if(value == 0)
361 pr_err(DRV_NAME ": Mailbox Interrupt has not reached to Driver..\n");
363 if(register_control_device_interface(psIntfAdapter->psAdapter) < 0)
365 pr_err(DRV_NAME ": Register Control Device failed...\n");
366 return -EIO;
369 return 0;
373 static inline int bcm_usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
375 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
378 static inline int bcm_usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
380 return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
383 static inline int bcm_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
385 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
388 static inline int bcm_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)
390 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
393 static inline int bcm_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
395 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
396 USB_ENDPOINT_XFER_BULK);
399 static inline int bcm_usb_endpoint_xfer_control(const struct usb_endpoint_descriptor *epd)
401 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
402 USB_ENDPOINT_XFER_CONTROL);
405 static inline int bcm_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
407 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
408 USB_ENDPOINT_XFER_INT);
411 static inline int bcm_usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd)
413 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
414 USB_ENDPOINT_XFER_ISOC);
417 static inline int bcm_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
419 return (bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_in(epd));
422 static inline int bcm_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
424 return (bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_out(epd));
427 static inline int bcm_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
429 return (bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_in(epd));
432 static inline int bcm_usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd)
434 return (bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_out(epd));
437 static inline int bcm_usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd)
439 return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_in(epd));
442 static inline int bcm_usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd)
444 return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_out(epd));
447 static INT InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter)
449 struct usb_host_interface *iface_desc;
450 struct usb_endpoint_descriptor *endpoint;
451 size_t buffer_size;
452 ULONG value;
453 INT retval = 0;
454 INT usedIntOutForBulkTransfer = 0 ;
455 BOOLEAN bBcm16 = FALSE;
456 UINT uiData = 0;
458 /* Store the usb dev into interface adapter */
459 psIntfAdapter->udev = usb_get_dev(interface_to_usbdev(psIntfAdapter->interface));
461 psIntfAdapter->bHighSpeedDevice = (psIntfAdapter->udev->speed == USB_SPEED_HIGH);
462 psIntfAdapter->psAdapter->interface_rdm = BcmRDM;
463 psIntfAdapter->psAdapter->interface_wrm = BcmWRM;
465 if(rdmalt(psIntfAdapter->psAdapter, CHIP_ID_REG, (PUINT)&(psIntfAdapter->psAdapter->chip_id), sizeof(UINT)) < 0)
467 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "CHIP ID Read Failed\n");
468 return STATUS_FAILURE;
471 if(0xbece3200==(psIntfAdapter->psAdapter->chip_id&~(0xF0)))
472 psIntfAdapter->psAdapter->chip_id &= ~0xF0;
474 dev_info(&psIntfAdapter->udev->dev, "RDM Chip ID 0x%lx\n",
475 psIntfAdapter->psAdapter->chip_id);
477 iface_desc = psIntfAdapter->interface->cur_altsetting;
479 if(psIntfAdapter->psAdapter->chip_id == T3B)
482 //T3B device will have EEPROM,check if EEPROM is proper and BCM16 can be done or not.
484 BeceemEEPROMBulkRead(psIntfAdapter->psAdapter,&uiData,0x0,4);
485 if(uiData == BECM)
486 bBcm16 = TRUE;
488 dev_info(&psIntfAdapter->udev->dev, "number of alternate setting %d\n",
489 psIntfAdapter->interface->num_altsetting);
491 if(bBcm16 == TRUE)
493 //selecting alternate setting one as a default setting for High Speed modem.
494 if(psIntfAdapter->bHighSpeedDevice)
495 retval= usb_set_interface(psIntfAdapter->udev,DEFAULT_SETTING_0,ALTERNATE_SETTING_1);
496 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "BCM16 is Applicable on this dongle");
497 if(retval || (psIntfAdapter->bHighSpeedDevice == FALSE))
499 usedIntOutForBulkTransfer = EP2 ;
500 endpoint = &iface_desc->endpoint[EP2].desc;
501 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");
503 If Modem is high speed device EP2 should be INT OUT End point
504 If Mode is FS then EP2 should be bulk end point
506 if(((psIntfAdapter->bHighSpeedDevice ==TRUE ) && (bcm_usb_endpoint_is_int_out(endpoint)== FALSE))
507 ||((psIntfAdapter->bHighSpeedDevice == FALSE)&& (bcm_usb_endpoint_is_bulk_out(endpoint)== FALSE)))
509 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Configuring the EEPROM ");
510 //change the EP2, EP4 to INT OUT end point
511 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter);
514 It resets the device and if any thing gets changed in USB descriptor it will show fail and
515 re-enumerate the device
517 retval = usb_reset_device(psIntfAdapter->udev);
518 if(retval)
520 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reset got failed. hence Re-enumerating the device \n");
521 return retval ;
525 if((psIntfAdapter->bHighSpeedDevice == FALSE) && bcm_usb_endpoint_is_bulk_out(endpoint))
527 // Once BULK is selected in FS mode. Revert it back to INT. Else USB_IF will fail.
528 UINT _uiData = ntohl(EP2_CFG_INT);
529 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Reverting Bulk to INT as it is FS MODE");
530 BeceemEEPROMBulkWrite(psIntfAdapter->psAdapter,(PUCHAR)&_uiData,0x136,4,TRUE);
533 else
535 usedIntOutForBulkTransfer = EP4 ;
536 endpoint = &iface_desc->endpoint[EP4].desc;
537 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Choosing AltSetting as a default setting");
538 if( bcm_usb_endpoint_is_int_out(endpoint) == FALSE)
540 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, " Dongle does not have BCM16 Fix");
541 //change the EP2, EP4 to INT OUT end point and use EP4 in altsetting
542 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter);
545 It resets the device and if any thing gets changed in USB descriptor it will show fail and
546 re-enumerate the device
548 retval = usb_reset_device(psIntfAdapter->udev);
549 if(retval)
551 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reset got failed. hence Re-enumerating the device \n");
552 return retval ;
560 iface_desc = psIntfAdapter->interface->cur_altsetting;
562 for (value = 0; value < iface_desc->desc.bNumEndpoints; ++value)
564 endpoint = &iface_desc->endpoint[value].desc;
566 if (!psIntfAdapter->sBulkIn.bulk_in_endpointAddr && bcm_usb_endpoint_is_bulk_in(endpoint))
568 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
569 psIntfAdapter->sBulkIn.bulk_in_size = buffer_size;
570 psIntfAdapter->sBulkIn.bulk_in_endpointAddr =
571 endpoint->bEndpointAddress;
572 psIntfAdapter->sBulkIn.bulk_in_pipe =
573 usb_rcvbulkpipe(psIntfAdapter->udev,
574 psIntfAdapter->sBulkIn.bulk_in_endpointAddr);
577 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr && bcm_usb_endpoint_is_bulk_out(endpoint))
580 psIntfAdapter->sBulkOut.bulk_out_endpointAddr =
581 endpoint->bEndpointAddress;
582 psIntfAdapter->sBulkOut.bulk_out_pipe =
583 usb_sndbulkpipe(psIntfAdapter->udev,
584 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
587 if (!psIntfAdapter->sIntrIn.int_in_endpointAddr && bcm_usb_endpoint_is_int_in(endpoint))
589 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
590 psIntfAdapter->sIntrIn.int_in_size = buffer_size;
591 psIntfAdapter->sIntrIn.int_in_endpointAddr =
592 endpoint->bEndpointAddress;
593 psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval;
594 psIntfAdapter->sIntrIn.int_in_buffer =
595 kmalloc(buffer_size, GFP_KERNEL);
596 if (!psIntfAdapter->sIntrIn.int_in_buffer) {
597 dev_err(&psIntfAdapter->udev->dev,
598 "could not allocate interrupt_in_buffer\n");
599 return -EINVAL;
603 if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint))
606 if( !psIntfAdapter->sBulkOut.bulk_out_endpointAddr &&
607 (psIntfAdapter->psAdapter->chip_id == T3B) && (value == usedIntOutForBulkTransfer))
609 //use first intout end point as a bulk out end point
610 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
611 psIntfAdapter->sBulkOut.bulk_out_size = buffer_size;
612 //printk("\nINT OUT Endpoing buffer size :%x endpoint :%x\n", buffer_size, value +1);
613 psIntfAdapter->sBulkOut.bulk_out_endpointAddr =
614 endpoint->bEndpointAddress;
615 psIntfAdapter->sBulkOut.bulk_out_pipe =
616 usb_sndintpipe(psIntfAdapter->udev,
617 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
618 psIntfAdapter->sBulkOut.int_out_interval = endpoint->bInterval;
621 else if(value == EP6)
623 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
624 psIntfAdapter->sIntrOut.int_out_size = buffer_size;
625 psIntfAdapter->sIntrOut.int_out_endpointAddr =
626 endpoint->bEndpointAddress;
627 psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval;
628 psIntfAdapter->sIntrOut.int_out_buffer= kmalloc(buffer_size,
629 GFP_KERNEL);
630 if (!psIntfAdapter->sIntrOut.int_out_buffer)
632 dev_err(&psIntfAdapter->udev->dev,
633 "could not allocate interrupt_out_buffer\n");
634 return -EINVAL;
639 usb_set_intfdata(psIntfAdapter->interface, psIntfAdapter);
641 psIntfAdapter->psAdapter->bcm_file_download = InterfaceFileDownload;
642 psIntfAdapter->psAdapter->bcm_file_readback_from_chip =
643 InterfaceFileReadbackFromChip;
644 psIntfAdapter->psAdapter->interface_transmit = InterfaceTransmitPacket;
646 retval = CreateInterruptUrb(psIntfAdapter);
648 if(retval)
650 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cannot create interrupt urb");
651 return retval;
654 retval = AllocUsbCb(psIntfAdapter);
655 if(retval)
657 return retval;
661 return device_run(psIntfAdapter);
664 static int InterfaceSuspend (struct usb_interface *intf, pm_message_t message)
666 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
668 psIntfAdapter->bSuspended = TRUE;
670 if(TRUE == psIntfAdapter->bPreparingForBusSuspend)
672 psIntfAdapter->bPreparingForBusSuspend = FALSE;
674 if(psIntfAdapter->psAdapter->LinkStatus == LINKUP_DONE)
676 psIntfAdapter->psAdapter->IdleMode = TRUE ;
677 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Host Entered in PMU Idle Mode..");
679 else
681 psIntfAdapter->psAdapter->bShutStatus = TRUE;
682 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Host Entered in PMU Shutdown Mode..");
685 psIntfAdapter->psAdapter->bPreparingForLowPowerMode = FALSE;
687 //Signaling the control pkt path
688 wake_up(&psIntfAdapter->psAdapter->lowpower_mode_wait_queue);
690 return 0;
693 static int InterfaceResume (struct usb_interface *intf)
695 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
696 printk("=================================\n");
697 mdelay(100);
698 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32)
699 intf->pm_usage_cnt =1 ;
700 #endif
701 psIntfAdapter->bSuspended = FALSE;
703 StartInterruptUrb(psIntfAdapter);
704 InterfaceRx(psIntfAdapter);
705 return 0;
708 static struct usb_driver usbbcm_driver = {
709 .name = "usbbcm",
710 .probe = usbbcm_device_probe,
711 .disconnect = usbbcm_disconnect,
712 .suspend = InterfaceSuspend,
713 .resume = InterfaceResume,
714 .id_table = InterfaceUsbtable,
715 .supports_autosuspend = 1,
718 struct class *bcm_class;
721 static __init int bcm_init(void)
723 printk(KERN_INFO "%s: %s, %s\n", DRV_NAME, DRV_DESCRIPTION, DRV_VERSION);
724 printk(KERN_INFO "%s\n", DRV_COPYRIGHT);
726 bcm_class = class_create(THIS_MODULE, DRV_NAME);
727 if (IS_ERR(bcm_class)) {
728 printk(KERN_ERR DRV_NAME ": could not create class\n");
729 return PTR_ERR(bcm_class);
732 return usb_register(&usbbcm_driver);
735 static __exit void bcm_exit(void)
737 class_destroy (bcm_class);
739 usb_deregister(&usbbcm_driver);
742 module_init(bcm_init);
743 module_exit(bcm_exit);
745 MODULE_DESCRIPTION(DRV_DESCRIPTION);
746 MODULE_VERSION(DRV_VERSION);
747 MODULE_LICENSE ("GPL");