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_SYM) },
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 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_ZTE_226) },
12 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_ZTE_326) },
15 MODULE_DEVICE_TABLE(usb, InterfaceUsbtable);
17 static int debug = -1;
18 module_param(debug, uint, 0600);
19 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
21 static const u32 default_msg =
22 NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK
23 | NETIF_MSG_TIMER | NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR
24 | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN;
26 static int InterfaceAdapterInit(PS_INTERFACE_ADAPTER Adapter);
28 static void InterfaceAdapterFree(PS_INTERFACE_ADAPTER psIntfAdapter)
32 /* Wake up the wait_queue... */
33 if (psIntfAdapter->psAdapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
34 psIntfAdapter->psAdapter->DriverState = DRIVER_HALT;
35 wake_up(&psIntfAdapter->psAdapter->LEDInfo.notify_led_event);
37 reset_card_proc(psIntfAdapter->psAdapter);
40 * worst case time taken by the RDM/WRM will be 5 sec. will check after every 100 ms
41 * to accertain the device is not being accessed. After this No RDM/WRM should be made.
43 while (psIntfAdapter->psAdapter->DeviceAccess) {
44 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
45 "Device is being accessed.\n");
48 /* Free interrupt URB */
49 /* psIntfAdapter->psAdapter->device_removed = TRUE; */
50 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;
75 /* Program EP2 MAX_PKT_SIZE */
76 ulReg = ntohl(EP2_MPS_REG);
77 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x128, 4, TRUE);
78 ulReg = ntohl(EP2_MPS);
79 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x12C, 4, TRUE);
81 ulReg = ntohl(EP2_CFG_REG);
82 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x132, 4, TRUE);
83 if (((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter))->bHighSpeedDevice == TRUE) {
84 ulReg = ntohl(EP2_CFG_INT);
85 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE);
87 /* USE BULK EP as TX in FS mode. */
88 ulReg = ntohl(EP2_CFG_BULK);
89 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE);
92 /* Program EP4 MAX_PKT_SIZE. */
93 ulReg = ntohl(EP4_MPS_REG);
94 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x13C, 4, TRUE);
95 ulReg = ntohl(EP4_MPS);
96 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x140, 4, TRUE);
98 /* Program TX EP as interrupt(Alternate Setting) */
99 ret = rdmalt(Adapter, 0x0F0110F8, (u32 *)&ulReg, sizeof(u32));
101 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
102 "reading of Tx EP failed\n");
107 ulReg = ntohl(ulReg);
108 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1CC, 4, TRUE);
110 ulReg = ntohl(EP4_CFG_REG);
111 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C8, 4, TRUE);
112 /* Program ISOCHRONOUS EP size to zero. */
113 ulReg = ntohl(ISO_MPS_REG);
114 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1D2, 4, TRUE);
115 ulReg = ntohl(ISO_MPS);
116 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1D6, 4, TRUE);
119 * Update EEPROM Version.
120 * Read 4 bytes from 508 and modify 511 and 510.
122 ReadBeceemEEPROM(Adapter, 0x1FC, (PUINT)&ulReg);
124 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1FC, 4, TRUE);
126 /* Update length field if required. Also make the string NULL terminated. */
128 ReadBeceemEEPROM(Adapter, 0xA8, (PUINT)&ulReg);
129 if ((ulReg&0x00FF0000)>>16 > 0x30) {
130 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
131 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0xA8, 4, TRUE);
133 ReadBeceemEEPROM(Adapter, 0x148, (PUINT)&ulReg);
134 if ((ulReg&0x00FF0000)>>16 > 0x30) {
135 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
136 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x148, 4, TRUE);
139 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x122, 4, TRUE);
141 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C2, 4, TRUE);
144 static int usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id)
146 struct usb_device *udev = interface_to_usbdev(intf);
148 PMINI_ADAPTER psAdapter;
149 PS_INTERFACE_ADAPTER psIntfAdapter;
150 struct net_device *ndev;
152 /* Reserve one extra queue for the bit-bucket */
153 ndev = alloc_etherdev_mq(sizeof(MINI_ADAPTER), NO_OF_QUEUES+1);
155 dev_err(&udev->dev, DRV_NAME ": no memory for device\n");
159 SET_NETDEV_DEV(ndev, &intf->dev);
161 psAdapter = netdev_priv(ndev);
162 psAdapter->dev = ndev;
163 psAdapter->msg_enable = netif_msg_init(debug, default_msg);
165 /* Init default driver debug state */
167 psAdapter->stDebugState.debug_level = DBG_LVL_CURR;
168 psAdapter->stDebugState.type = DBG_TYPE_INITEXIT;
171 * Technically, one can start using BCM_DEBUG_PRINT after this point.
172 * However, realize that by default the Type/Subtype bitmaps are all zero now;
173 * so no prints will actually appear until the TestApp turns on debug paths via
174 * the ioctl(); so practically speaking, in early init, no logging happens.
176 * A solution (used below): we explicitly set the bitmaps to 1 for Type=DBG_TYPE_INITEXIT
177 * and ALL subtype's of the same. Now all bcm debug statements get logged, enabling debug
179 * Further, we turn this OFF once init_module() completes.
182 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0xff;
183 BCM_SHOW_DEBUG_BITMAP(psAdapter);
185 retval = InitAdapter(psAdapter);
187 dev_err(&udev->dev, DRV_NAME ": InitAdapter Failed\n");
188 AdapterFree(psAdapter);
192 /* Allocate interface adapter structure */
193 psIntfAdapter = kzalloc(sizeof(S_INTERFACE_ADAPTER), GFP_KERNEL);
194 if (psIntfAdapter == NULL) {
195 dev_err(&udev->dev, DRV_NAME ": no memory for Interface adapter\n");
196 AdapterFree(psAdapter);
200 psAdapter->pvInterfaceAdapter = psIntfAdapter;
201 psIntfAdapter->psAdapter = psAdapter;
203 /* Store usb interface in Interface Adapter */
204 psIntfAdapter->interface = intf;
205 usb_set_intfdata(intf, psIntfAdapter);
207 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
208 "psIntfAdapter 0x%p\n", psIntfAdapter);
209 retval = InterfaceAdapterInit(psIntfAdapter);
211 /* If the Firmware/Cfg File is not present
212 * then return success, let the application
213 * download the files.
215 if (-ENOENT == retval) {
216 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
217 "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,
221 "InterfaceAdapterInit failed.\n");
222 usb_set_intfdata(intf, NULL);
223 udev = interface_to_usbdev(intf);
225 InterfaceAdapterFree(psIntfAdapter);
228 if (psAdapter->chip_id > T3) {
229 uint32_t uiNackZeroLengthInt = 4;
231 retval = wrmalt(psAdapter, DISABLE_USB_ZERO_LEN_INT, &uiNackZeroLengthInt, sizeof(uiNackZeroLengthInt));
236 /* Check whether the USB-Device Supports remote Wake-Up */
237 if (USB_CONFIG_ATT_WAKEUP & udev->actconfig->desc.bmAttributes) {
238 /* If Suspend then only support dynamic suspend */
239 if (psAdapter->bDoSuspend) {
241 pm_runtime_set_autosuspend_delay(&udev->dev, 0);
242 intf->needs_remote_wakeup = 1;
243 usb_enable_autosuspend(udev);
244 device_init_wakeup(&intf->dev, 1);
245 INIT_WORK(&psIntfAdapter->usbSuspendWork, putUsbSuspend);
246 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
247 "Enabling USB Auto-Suspend\n");
250 intf->needs_remote_wakeup = 0;
251 usb_disable_autosuspend(udev);
255 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0x0;
259 static void usbbcm_disconnect(struct usb_interface *intf)
261 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
262 PMINI_ADAPTER psAdapter;
263 struct usb_device *udev = interface_to_usbdev(intf);
265 if (psIntfAdapter == NULL)
268 psAdapter = psIntfAdapter->psAdapter;
269 netif_device_detach(psAdapter->dev);
271 if (psAdapter->bDoSuspend)
272 intf->needs_remote_wakeup = 0;
274 psAdapter->device_removed = TRUE ;
275 usb_set_intfdata(intf, NULL);
276 InterfaceAdapterFree(psIntfAdapter);
280 static int AllocUsbCb(PS_INTERFACE_ADAPTER psIntfAdapter)
284 for (i = 0; i < MAXIMUM_USB_TCB; i++) {
285 psIntfAdapter->asUsbTcb[i].urb = usb_alloc_urb(0, GFP_KERNEL);
287 if (psIntfAdapter->asUsbTcb[i].urb == NULL) {
288 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
289 "Can't allocate Tx urb for index %d\n", i);
294 for (i = 0; i < MAXIMUM_USB_RCB; i++) {
295 psIntfAdapter->asUsbRcb[i].urb = usb_alloc_urb(0, GFP_KERNEL);
297 if (psIntfAdapter->asUsbRcb[i].urb == NULL) {
298 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
299 "Can't allocate Rx urb for index %d\n", i);
303 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer = kmalloc(MAX_DATA_BUFFER_SIZE, GFP_KERNEL);
305 if (psIntfAdapter->asUsbRcb[i].urb->transfer_buffer == NULL) {
306 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
307 "Can't allocate Rx buffer for index %d\n", i);
310 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer_length = MAX_DATA_BUFFER_SIZE;
315 static int device_run(PS_INTERFACE_ADAPTER psIntfAdapter)
318 UINT status = STATUS_SUCCESS;
320 status = InitCardAndDownloadFirmware(psIntfAdapter->psAdapter);
321 if (status != STATUS_SUCCESS) {
322 pr_err(DRV_NAME "InitCardAndDownloadFirmware failed.\n");
325 if (TRUE == psIntfAdapter->psAdapter->fw_download_done) {
326 if (StartInterruptUrb(psIntfAdapter)) {
327 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
328 "Cannot send interrupt in URB\n");
332 * now register the cntrl interface.
333 * after downloading the f/w waiting for 5 sec to get the mailbox interrupt.
335 psIntfAdapter->psAdapter->waiting_to_fw_download_done = FALSE;
336 value = wait_event_timeout(psIntfAdapter->psAdapter->ioctl_fw_dnld_wait_queue,
337 psIntfAdapter->psAdapter->waiting_to_fw_download_done, 5*HZ);
340 pr_err(DRV_NAME ": Timeout waiting for mailbox interrupt.\n");
342 if (register_control_device_interface(psIntfAdapter->psAdapter) < 0) {
343 pr_err(DRV_NAME ": Register Control Device failed.\n");
351 static inline int bcm_usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
353 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
356 static inline int bcm_usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
358 return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
361 static inline int bcm_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
363 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
366 static inline int bcm_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)
368 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
371 static inline int bcm_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
373 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
374 USB_ENDPOINT_XFER_BULK);
377 static inline int bcm_usb_endpoint_xfer_control(const struct usb_endpoint_descriptor *epd)
379 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
380 USB_ENDPOINT_XFER_CONTROL);
383 static inline int bcm_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
385 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
386 USB_ENDPOINT_XFER_INT);
389 static inline int bcm_usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd)
391 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
392 USB_ENDPOINT_XFER_ISOC);
395 static inline int bcm_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
397 return bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_in(epd);
400 static inline int bcm_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
402 return bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_out(epd);
405 static inline int bcm_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
407 return bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_in(epd);
410 static inline int bcm_usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd)
412 return bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_out(epd);
415 static inline int bcm_usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd)
417 return bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_in(epd);
420 static inline int bcm_usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd)
422 return bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_out(epd);
425 static int InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter)
427 struct usb_host_interface *iface_desc;
428 struct usb_endpoint_descriptor *endpoint;
432 int usedIntOutForBulkTransfer = 0 ;
433 BOOLEAN bBcm16 = FALSE;
436 /* Store the usb dev into interface adapter */
437 psIntfAdapter->udev = usb_get_dev(interface_to_usbdev(psIntfAdapter->interface));
439 psIntfAdapter->bHighSpeedDevice = (psIntfAdapter->udev->speed == USB_SPEED_HIGH);
440 psIntfAdapter->psAdapter->interface_rdm = BcmRDM;
441 psIntfAdapter->psAdapter->interface_wrm = BcmWRM;
443 retval = rdmalt(psIntfAdapter->psAdapter, CHIP_ID_REG,
444 (u32 *)&(psIntfAdapter->psAdapter->chip_id), sizeof(u32));
446 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, "CHIP ID Read Failed\n");
450 if (0xbece3200 == (psIntfAdapter->psAdapter->chip_id & ~(0xF0)))
451 psIntfAdapter->psAdapter->chip_id &= ~0xF0;
453 dev_info(&psIntfAdapter->udev->dev, "RDM Chip ID 0x%lx\n",
454 psIntfAdapter->psAdapter->chip_id);
456 iface_desc = psIntfAdapter->interface->cur_altsetting;
458 if (psIntfAdapter->psAdapter->chip_id == T3B) {
459 /* T3B device will have EEPROM, check if EEPROM is proper and BCM16 can be done or not. */
460 BeceemEEPROMBulkRead(psIntfAdapter->psAdapter, &uiData, 0x0, 4);
464 dev_info(&psIntfAdapter->udev->dev, "number of alternate setting %d\n",
465 psIntfAdapter->interface->num_altsetting);
467 if (bBcm16 == TRUE) {
468 /* selecting alternate setting one as a default setting for High Speed modem. */
469 if (psIntfAdapter->bHighSpeedDevice)
470 retval = usb_set_interface(psIntfAdapter->udev, DEFAULT_SETTING_0, ALTERNATE_SETTING_1);
471 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
472 "BCM16 is applicable on this dongle\n");
473 if (retval || (psIntfAdapter->bHighSpeedDevice == FALSE)) {
474 usedIntOutForBulkTransfer = EP2 ;
475 endpoint = &iface_desc->endpoint[EP2].desc;
476 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
477 "Interface altsetting failed or modem is configured to Full Speed, hence will work on default setting 0\n");
479 * If Modem is high speed device EP2 should be INT OUT End point
480 * If Mode is FS then EP2 should be bulk end point
482 if (((psIntfAdapter->bHighSpeedDevice == TRUE) && (bcm_usb_endpoint_is_int_out(endpoint) == FALSE))
483 || ((psIntfAdapter->bHighSpeedDevice == FALSE) && (bcm_usb_endpoint_is_bulk_out(endpoint) == FALSE))) {
484 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
485 "Configuring the EEPROM\n");
486 /* change the EP2, EP4 to INT OUT end point */
487 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter);
490 * It resets the device and if any thing gets changed
491 * in USB descriptor it will show fail and re-enumerate
494 retval = usb_reset_device(psIntfAdapter->udev);
496 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
497 "reset failed. Re-enumerating the device.\n");
502 if ((psIntfAdapter->bHighSpeedDevice == FALSE) && bcm_usb_endpoint_is_bulk_out(endpoint)) {
503 /* Once BULK is selected in FS mode. Revert it back to INT. Else USB_IF will fail. */
504 UINT _uiData = ntohl(EP2_CFG_INT);
505 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
506 "Reverting Bulk to INT as it is in Full Speed mode.\n");
507 BeceemEEPROMBulkWrite(psIntfAdapter->psAdapter, (PUCHAR)&_uiData, 0x136, 4, TRUE);
510 usedIntOutForBulkTransfer = EP4 ;
511 endpoint = &iface_desc->endpoint[EP4].desc;
512 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
513 "Choosing AltSetting as a default setting.\n");
514 if (bcm_usb_endpoint_is_int_out(endpoint) == FALSE) {
515 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
516 "Dongle does not have BCM16 Fix.\n");
517 /* change the EP2, EP4 to INT OUT end point and use EP4 in altsetting */
518 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter);
521 * It resets the device and if any thing gets changed in
522 * USB descriptor it will show fail and re-enumerate the
525 retval = usb_reset_device(psIntfAdapter->udev);
527 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
528 "reset failed. Re-enumerating the device.\n");
537 iface_desc = psIntfAdapter->interface->cur_altsetting;
539 for (value = 0; value < iface_desc->desc.bNumEndpoints; ++value) {
540 endpoint = &iface_desc->endpoint[value].desc;
542 if (!psIntfAdapter->sBulkIn.bulk_in_endpointAddr && bcm_usb_endpoint_is_bulk_in(endpoint)) {
543 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
544 psIntfAdapter->sBulkIn.bulk_in_size = buffer_size;
545 psIntfAdapter->sBulkIn.bulk_in_endpointAddr = endpoint->bEndpointAddress;
546 psIntfAdapter->sBulkIn.bulk_in_pipe =
547 usb_rcvbulkpipe(psIntfAdapter->udev,
548 psIntfAdapter->sBulkIn.bulk_in_endpointAddr);
551 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr && bcm_usb_endpoint_is_bulk_out(endpoint)) {
552 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = endpoint->bEndpointAddress;
553 psIntfAdapter->sBulkOut.bulk_out_pipe =
554 usb_sndbulkpipe(psIntfAdapter->udev,
555 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
558 if (!psIntfAdapter->sIntrIn.int_in_endpointAddr && bcm_usb_endpoint_is_int_in(endpoint)) {
559 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
560 psIntfAdapter->sIntrIn.int_in_size = buffer_size;
561 psIntfAdapter->sIntrIn.int_in_endpointAddr = endpoint->bEndpointAddress;
562 psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval;
563 psIntfAdapter->sIntrIn.int_in_buffer =
564 kmalloc(buffer_size, GFP_KERNEL);
565 if (!psIntfAdapter->sIntrIn.int_in_buffer) {
566 dev_err(&psIntfAdapter->udev->dev,
567 "could not allocate interrupt_in_buffer\n");
572 if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint)) {
573 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr &&
574 (psIntfAdapter->psAdapter->chip_id == T3B) && (value == usedIntOutForBulkTransfer)) {
575 /* use first intout end point as a bulk out end point */
576 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
577 psIntfAdapter->sBulkOut.bulk_out_size = buffer_size;
578 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = endpoint->bEndpointAddress;
579 psIntfAdapter->sBulkOut.bulk_out_pipe = usb_sndintpipe(psIntfAdapter->udev,
580 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
581 psIntfAdapter->sBulkOut.int_out_interval = endpoint->bInterval;
582 } else if (value == EP6) {
583 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
584 psIntfAdapter->sIntrOut.int_out_size = buffer_size;
585 psIntfAdapter->sIntrOut.int_out_endpointAddr = endpoint->bEndpointAddress;
586 psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval;
587 psIntfAdapter->sIntrOut.int_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
588 if (!psIntfAdapter->sIntrOut.int_out_buffer) {
589 dev_err(&psIntfAdapter->udev->dev,
590 "could not allocate interrupt_out_buffer\n");
597 usb_set_intfdata(psIntfAdapter->interface, psIntfAdapter);
599 psIntfAdapter->psAdapter->bcm_file_download = InterfaceFileDownload;
600 psIntfAdapter->psAdapter->bcm_file_readback_from_chip =
601 InterfaceFileReadbackFromChip;
602 psIntfAdapter->psAdapter->interface_transmit = InterfaceTransmitPacket;
604 retval = CreateInterruptUrb(psIntfAdapter);
607 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
608 "Cannot create interrupt urb\n");
612 retval = AllocUsbCb(psIntfAdapter);
616 return device_run(psIntfAdapter);
619 static int InterfaceSuspend(struct usb_interface *intf, pm_message_t message)
621 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
623 psIntfAdapter->bSuspended = TRUE;
625 if (TRUE == psIntfAdapter->bPreparingForBusSuspend) {
626 psIntfAdapter->bPreparingForBusSuspend = FALSE;
628 if (psIntfAdapter->psAdapter->LinkStatus == LINKUP_DONE) {
629 psIntfAdapter->psAdapter->IdleMode = TRUE ;
630 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
631 "Host Entered in PMU Idle Mode.\n");
633 psIntfAdapter->psAdapter->bShutStatus = TRUE;
634 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
635 "Host Entered in PMU Shutdown Mode.\n");
638 psIntfAdapter->psAdapter->bPreparingForLowPowerMode = FALSE;
640 /* Signaling the control pkt path */
641 wake_up(&psIntfAdapter->psAdapter->lowpower_mode_wait_queue);
646 static int InterfaceResume(struct usb_interface *intf)
648 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
651 psIntfAdapter->bSuspended = FALSE;
653 StartInterruptUrb(psIntfAdapter);
654 InterfaceRx(psIntfAdapter);
658 static struct usb_driver usbbcm_driver = {
660 .probe = usbbcm_device_probe,
661 .disconnect = usbbcm_disconnect,
662 .suspend = InterfaceSuspend,
663 .resume = InterfaceResume,
664 .id_table = InterfaceUsbtable,
665 .supports_autosuspend = 1,
668 struct class *bcm_class;
670 static __init int bcm_init(void)
672 printk(KERN_INFO "%s: %s, %s\n", DRV_NAME, DRV_DESCRIPTION, DRV_VERSION);
673 printk(KERN_INFO "%s\n", DRV_COPYRIGHT);
675 bcm_class = class_create(THIS_MODULE, DRV_NAME);
676 if (IS_ERR(bcm_class)) {
677 printk(KERN_ERR DRV_NAME ": could not create class\n");
678 return PTR_ERR(bcm_class);
681 return usb_register(&usbbcm_driver);
684 static __exit void bcm_exit(void)
686 usb_deregister(&usbbcm_driver);
687 class_destroy(bcm_class);
690 module_init(bcm_init);
691 module_exit(bcm_exit);
693 MODULE_DESCRIPTION(DRV_DESCRIPTION);
694 MODULE_VERSION(DRV_VERSION);
695 MODULE_LICENSE("GPL");