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) },
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)
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);
35 reset_card_proc(psIntfAdapter->psAdapter);
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.
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");
46 /* Free interrupt URB */
47 /* psIntfAdapter->psAdapter->device_removed = TRUE; */
48 if (psIntfAdapter->psInterruptUrb) {
49 usb_free_urb(psIntfAdapter->psInterruptUrb);
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;
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;
67 AdapterFree(psIntfAdapter->psAdapter);
70 static void ConfigureEndPointTypesThroughEEPROM(PMINI_ADAPTER Adapter)
72 unsigned long ulReg = 0;
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);
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);
86 /* USE BULK EP as TX in FS mode. */
87 ulReg = ntohl(EP2_CFG_BULK);
88 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)) {
99 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reading of Tx EP is failing");
104 ulReg = ntohl(ulReg);
105 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1CC, 4, TRUE);
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);
116 * Update EEPROM Version.
117 * Read 4 bytes from 508 and modify 511 and 510.
119 ReadBeceemEEPROM(Adapter, 0x1FC, (PUINT)&ulReg);
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) {
127 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
128 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0xA8, 4, TRUE);
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);
136 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x122, 4, TRUE);
138 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C2, 4, TRUE);
142 usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id)
144 struct usb_device *udev = interface_to_usbdev(intf);
146 PMINI_ADAPTER psAdapter;
147 PS_INTERFACE_ADAPTER psIntfAdapter;
148 struct net_device *ndev;
150 /* Reserve one extra queue for the bit-bucket */
151 ndev = alloc_etherdev_mq(sizeof(MINI_ADAPTER), NO_OF_QUEUES+1);
153 dev_err(&udev->dev, DRV_NAME ": no memory for device\n");
157 SET_NETDEV_DEV(ndev, &intf->dev);
159 psAdapter = netdev_priv(ndev);
160 psAdapter->dev = ndev;
161 psAdapter->msg_enable = netif_msg_init(debug, default_msg);
163 /* Init default driver debug state */
165 psAdapter->stDebugState.debug_level = DBG_LVL_CURR;
166 psAdapter->stDebugState.type = DBG_TYPE_INITEXIT;
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.
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
177 * Further, we turn this OFF once init_module() completes.
180 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0xff;
181 BCM_SHOW_DEBUG_BITMAP(psAdapter);
183 retval = InitAdapter(psAdapter);
185 dev_err(&udev->dev, DRV_NAME ": InitAdapter Failed\n");
186 AdapterFree(psAdapter);
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);
198 psAdapter->pvInterfaceAdapter = psIntfAdapter;
199 psIntfAdapter->psAdapter = psAdapter;
201 /* Store usb interface in Interface Adapter */
202 psIntfAdapter->interface = intf;
203 usb_set_intfdata(intf, psIntfAdapter);
205 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "psIntfAdapter 0x%p", psIntfAdapter);
206 retval = InterfaceAdapterInit(psIntfAdapter);
208 /* If the Firmware/Cfg File is not present
209 * then return success, let the application
210 * download the files.
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;
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);
220 InterfaceAdapterFree(psIntfAdapter);
223 if (psAdapter->chip_id > T3) {
224 uint32_t uiNackZeroLengthInt = 4;
226 if (wrmalt(psAdapter, DISABLE_USB_ZERO_LEN_INT, &uiNackZeroLengthInt, sizeof(uiNackZeroLengthInt))) {
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) {
236 udev->autosuspend_delay = 0;
237 intf->needs_remote_wakeup = 1;
238 usb_enable_autosuspend(udev);
239 device_init_wakeup(&intf->dev, 1);
240 INIT_WORK(&psIntfAdapter->usbSuspendWork, putUsbSuspend);
241 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Enabling USB Auto-Suspend\n");
244 intf->needs_remote_wakeup = 0;
245 usb_disable_autosuspend(udev);
249 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0x0;
253 static void usbbcm_disconnect(struct usb_interface *intf)
255 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
256 PMINI_ADAPTER psAdapter;
257 struct usb_device *udev = interface_to_usbdev(intf);
259 if (psIntfAdapter == NULL)
262 psAdapter = psIntfAdapter->psAdapter;
263 netif_device_detach(psAdapter->dev);
265 if (psAdapter->bDoSuspend)
266 intf->needs_remote_wakeup = 0;
268 psAdapter->device_removed = TRUE ;
269 usb_set_intfdata(intf, NULL);
270 InterfaceAdapterFree(psIntfAdapter);
274 static int AllocUsbCb(PS_INTERFACE_ADAPTER psIntfAdapter)
278 for (i = 0; i < MAXIMUM_USB_TCB; i++) {
279 if ((psIntfAdapter->asUsbTcb[i].urb =
280 usb_alloc_urb(0, GFP_KERNEL)) == NULL) {
281 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, "Cant allocate Tx urb for index %d", i);
286 for (i = 0; i < MAXIMUM_USB_RCB; i++) {
287 if ((psIntfAdapter->asUsbRcb[i].urb =
288 usb_alloc_urb(0, GFP_KERNEL)) == NULL) {
289 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, "Cant allocate Rx urb for index %d", i);
292 if ((psIntfAdapter->asUsbRcb[i].urb->transfer_buffer =
293 kmalloc(MAX_DATA_BUFFER_SIZE, GFP_KERNEL)) == NULL) {
294 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, "Cant allocate Rx buffer for index %d", i);
297 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer_length = MAX_DATA_BUFFER_SIZE;
302 static int device_run(PS_INTERFACE_ADAPTER psIntfAdapter)
305 UINT status = STATUS_SUCCESS;
307 status = InitCardAndDownloadFirmware(psIntfAdapter->psAdapter);
308 if (status != STATUS_SUCCESS) {
309 pr_err(DRV_NAME "InitCardAndDownloadFirmware failed.\n");
312 if (TRUE == psIntfAdapter->psAdapter->fw_download_done) {
313 if (StartInterruptUrb(psIntfAdapter)) {
314 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Cannot send interrupt in URB");
318 * now register the cntrl interface.
319 * after downloading the f/w waiting for 5 sec to get the mailbox interrupt.
321 psIntfAdapter->psAdapter->waiting_to_fw_download_done = FALSE;
322 value = wait_event_timeout(psIntfAdapter->psAdapter->ioctl_fw_dnld_wait_queue,
323 psIntfAdapter->psAdapter->waiting_to_fw_download_done, 5*HZ);
326 pr_err(DRV_NAME ": Mailbox Interrupt has not reached to Driver..\n");
328 if (register_control_device_interface(psIntfAdapter->psAdapter) < 0) {
329 pr_err(DRV_NAME ": Register Control Device failed...\n");
337 static inline int bcm_usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
339 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
342 static inline int bcm_usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
344 return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
347 static inline int bcm_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
349 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
352 static inline int bcm_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)
354 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
357 static inline int bcm_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
359 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
360 USB_ENDPOINT_XFER_BULK);
363 static inline int bcm_usb_endpoint_xfer_control(const struct usb_endpoint_descriptor *epd)
365 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
366 USB_ENDPOINT_XFER_CONTROL);
369 static inline int bcm_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
371 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
372 USB_ENDPOINT_XFER_INT);
375 static inline int bcm_usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd)
377 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
378 USB_ENDPOINT_XFER_ISOC);
381 static inline int bcm_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
383 return (bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_in(epd));
386 static inline int bcm_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
388 return (bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_out(epd));
391 static inline int bcm_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
393 return (bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_in(epd));
396 static inline int bcm_usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd)
398 return (bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_out(epd));
401 static inline int bcm_usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd)
403 return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_in(epd));
406 static inline int bcm_usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd)
408 return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_out(epd));
411 static int InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter)
413 struct usb_host_interface *iface_desc;
414 struct usb_endpoint_descriptor *endpoint;
418 int usedIntOutForBulkTransfer = 0 ;
419 BOOLEAN bBcm16 = FALSE;
422 /* Store the usb dev into interface adapter */
423 psIntfAdapter->udev = usb_get_dev(interface_to_usbdev(psIntfAdapter->interface));
425 psIntfAdapter->bHighSpeedDevice = (psIntfAdapter->udev->speed == USB_SPEED_HIGH);
426 psIntfAdapter->psAdapter->interface_rdm = BcmRDM;
427 psIntfAdapter->psAdapter->interface_wrm = BcmWRM;
429 if (rdmalt(psIntfAdapter->psAdapter, CHIP_ID_REG, (PUINT)&(psIntfAdapter->psAdapter->chip_id), sizeof(UINT)) < 0) {
430 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, "CHIP ID Read Failed\n");
431 return STATUS_FAILURE;
434 if (0xbece3200 == (psIntfAdapter->psAdapter->chip_id & ~(0xF0)))
435 psIntfAdapter->psAdapter->chip_id &= ~0xF0;
437 dev_info(&psIntfAdapter->udev->dev, "RDM Chip ID 0x%lx\n",
438 psIntfAdapter->psAdapter->chip_id);
440 iface_desc = psIntfAdapter->interface->cur_altsetting;
442 if (psIntfAdapter->psAdapter->chip_id == T3B) {
443 /* T3B device will have EEPROM, check if EEPROM is proper and BCM16 can be done or not. */
444 BeceemEEPROMBulkRead(psIntfAdapter->psAdapter, &uiData, 0x0, 4);
448 dev_info(&psIntfAdapter->udev->dev, "number of alternate setting %d\n",
449 psIntfAdapter->interface->num_altsetting);
451 if (bBcm16 == TRUE) {
452 /* selecting alternate setting one as a default setting for High Speed modem. */
453 if (psIntfAdapter->bHighSpeedDevice)
454 retval= usb_set_interface(psIntfAdapter->udev, DEFAULT_SETTING_0, ALTERNATE_SETTING_1);
455 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "BCM16 is Applicable on this dongle");
456 if (retval || (psIntfAdapter->bHighSpeedDevice == FALSE)) {
457 usedIntOutForBulkTransfer = EP2 ;
458 endpoint = &iface_desc->endpoint[EP2].desc;
459 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");
461 * If Modem is high speed device EP2 should be INT OUT End point
462 * If Mode is FS then EP2 should be bulk end point
464 if (((psIntfAdapter->bHighSpeedDevice == TRUE) && (bcm_usb_endpoint_is_int_out(endpoint) == FALSE))
465 || ((psIntfAdapter->bHighSpeedDevice == FALSE) && (bcm_usb_endpoint_is_bulk_out(endpoint) == FALSE))) {
466 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Configuring the EEPROM ");
467 /* change the EP2, EP4 to INT OUT end point */
468 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter);
471 * It resets the device and if any thing gets changed
472 * in USB descriptor it will show fail and re-enumerate
475 retval = usb_reset_device(psIntfAdapter->udev);
477 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reset got failed. hence Re-enumerating the device \n");
482 if ((psIntfAdapter->bHighSpeedDevice == FALSE) && bcm_usb_endpoint_is_bulk_out(endpoint)) {
483 /* Once BULK is selected in FS mode. Revert it back to INT. Else USB_IF will fail. */
484 UINT _uiData = ntohl(EP2_CFG_INT);
485 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Reverting Bulk to INT as it is FS MODE");
486 BeceemEEPROMBulkWrite(psIntfAdapter->psAdapter, (PUCHAR)&_uiData, 0x136, 4, TRUE);
489 usedIntOutForBulkTransfer = EP4 ;
490 endpoint = &iface_desc->endpoint[EP4].desc;
491 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Choosing AltSetting as a default setting");
492 if (bcm_usb_endpoint_is_int_out(endpoint) == FALSE) {
493 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, " Dongle does not have BCM16 Fix");
494 /* change the EP2, EP4 to INT OUT end point and use EP4 in altsetting */
495 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter);
498 * It resets the device and if any thing gets changed in
499 * USB descriptor it will show fail and re-enumerate the
502 retval = usb_reset_device(psIntfAdapter->udev);
504 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reset got failed. hence Re-enumerating the device \n");
513 iface_desc = psIntfAdapter->interface->cur_altsetting;
515 for (value = 0; value < iface_desc->desc.bNumEndpoints; ++value) {
516 endpoint = &iface_desc->endpoint[value].desc;
518 if (!psIntfAdapter->sBulkIn.bulk_in_endpointAddr && bcm_usb_endpoint_is_bulk_in(endpoint)) {
519 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
520 psIntfAdapter->sBulkIn.bulk_in_size = buffer_size;
521 psIntfAdapter->sBulkIn.bulk_in_endpointAddr = endpoint->bEndpointAddress;
522 psIntfAdapter->sBulkIn.bulk_in_pipe =
523 usb_rcvbulkpipe(psIntfAdapter->udev,
524 psIntfAdapter->sBulkIn.bulk_in_endpointAddr);
527 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr && bcm_usb_endpoint_is_bulk_out(endpoint)) {
528 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = endpoint->bEndpointAddress;
529 psIntfAdapter->sBulkOut.bulk_out_pipe =
530 usb_sndbulkpipe(psIntfAdapter->udev,
531 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
534 if (!psIntfAdapter->sIntrIn.int_in_endpointAddr && bcm_usb_endpoint_is_int_in(endpoint)) {
535 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
536 psIntfAdapter->sIntrIn.int_in_size = buffer_size;
537 psIntfAdapter->sIntrIn.int_in_endpointAddr = endpoint->bEndpointAddress;
538 psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval;
539 psIntfAdapter->sIntrIn.int_in_buffer =
540 kmalloc(buffer_size, GFP_KERNEL);
541 if (!psIntfAdapter->sIntrIn.int_in_buffer) {
542 dev_err(&psIntfAdapter->udev->dev,
543 "could not allocate interrupt_in_buffer\n");
548 if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint)) {
549 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr &&
550 (psIntfAdapter->psAdapter->chip_id == T3B) && (value == usedIntOutForBulkTransfer)) {
551 /* use first intout end point as a bulk out end point */
552 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
553 psIntfAdapter->sBulkOut.bulk_out_size = buffer_size;
554 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = endpoint->bEndpointAddress;
555 psIntfAdapter->sBulkOut.bulk_out_pipe = usb_sndintpipe(psIntfAdapter->udev,
556 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
557 psIntfAdapter->sBulkOut.int_out_interval = endpoint->bInterval;
558 } else if (value == EP6) {
559 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
560 psIntfAdapter->sIntrOut.int_out_size = buffer_size;
561 psIntfAdapter->sIntrOut.int_out_endpointAddr = endpoint->bEndpointAddress;
562 psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval;
563 psIntfAdapter->sIntrOut.int_out_buffer= kmalloc(buffer_size, GFP_KERNEL);
564 if (!psIntfAdapter->sIntrOut.int_out_buffer) {
565 dev_err(&psIntfAdapter->udev->dev,
566 "could not allocate interrupt_out_buffer\n");
573 usb_set_intfdata(psIntfAdapter->interface, psIntfAdapter);
575 psIntfAdapter->psAdapter->bcm_file_download = InterfaceFileDownload;
576 psIntfAdapter->psAdapter->bcm_file_readback_from_chip =
577 InterfaceFileReadbackFromChip;
578 psIntfAdapter->psAdapter->interface_transmit = InterfaceTransmitPacket;
580 retval = CreateInterruptUrb(psIntfAdapter);
583 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, "Cannot create interrupt urb");
587 retval = AllocUsbCb(psIntfAdapter);
592 return device_run(psIntfAdapter);
595 static int InterfaceSuspend(struct usb_interface *intf, pm_message_t message)
597 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
599 psIntfAdapter->bSuspended = TRUE;
601 if (TRUE == psIntfAdapter->bPreparingForBusSuspend) {
602 psIntfAdapter->bPreparingForBusSuspend = FALSE;
604 if (psIntfAdapter->psAdapter->LinkStatus == LINKUP_DONE) {
605 psIntfAdapter->psAdapter->IdleMode = TRUE ;
606 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Host Entered in PMU Idle Mode..");
608 psIntfAdapter->psAdapter->bShutStatus = TRUE;
609 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Host Entered in PMU Shutdown Mode..");
612 psIntfAdapter->psAdapter->bPreparingForLowPowerMode = FALSE;
614 /* Signaling the control pkt path */
615 wake_up(&psIntfAdapter->psAdapter->lowpower_mode_wait_queue);
620 static int InterfaceResume(struct usb_interface *intf)
622 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
623 printk("=================================\n");
626 psIntfAdapter->bSuspended = FALSE;
628 StartInterruptUrb(psIntfAdapter);
629 InterfaceRx(psIntfAdapter);
633 static struct usb_driver usbbcm_driver = {
635 .probe = usbbcm_device_probe,
636 .disconnect = usbbcm_disconnect,
637 .suspend = InterfaceSuspend,
638 .resume = InterfaceResume,
639 .id_table = InterfaceUsbtable,
640 .supports_autosuspend = 1,
643 struct class *bcm_class;
645 static __init int bcm_init(void)
647 printk(KERN_INFO "%s: %s, %s\n", DRV_NAME, DRV_DESCRIPTION, DRV_VERSION);
648 printk(KERN_INFO "%s\n", DRV_COPYRIGHT);
650 bcm_class = class_create(THIS_MODULE, DRV_NAME);
651 if (IS_ERR(bcm_class)) {
652 printk(KERN_ERR DRV_NAME ": could not create class\n");
653 return PTR_ERR(bcm_class);
656 return usb_register(&usbbcm_driver);
659 static __exit void bcm_exit(void)
661 class_destroy(bcm_class);
663 usb_deregister(&usbbcm_driver);
666 module_init(bcm_init);
667 module_exit(bcm_exit);
669 MODULE_DESCRIPTION(DRV_DESCRIPTION);
670 MODULE_VERSION(DRV_VERSION);
671 MODULE_LICENSE("GPL");