cx88: fix locking of sub-driver operations
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / bcm / InterfaceInit.c
blobd78d5ef1f298c66a3cd4e580ead618389e094709
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;
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");
44 msleep(100);
46 /* Free interrupt URB */
47 /* psIntfAdapter->psAdapter->device_removed = TRUE; */
48 usb_free_urb(psIntfAdapter->psInterruptUrb);
50 /* Free transmit URBs */
51 for (i = 0; i < MAXIMUM_USB_TCB; i++) {
52 if (psIntfAdapter->asUsbTcb[i].urb != NULL) {
53 usb_free_urb(psIntfAdapter->asUsbTcb[i].urb);
54 psIntfAdapter->asUsbTcb[i].urb = NULL;
57 /* Free receive URB and buffers */
58 for (i = 0; i < MAXIMUM_USB_RCB; i++) {
59 if (psIntfAdapter->asUsbRcb[i].urb != NULL) {
60 kfree(psIntfAdapter->asUsbRcb[i].urb->transfer_buffer);
61 usb_free_urb(psIntfAdapter->asUsbRcb[i].urb);
62 psIntfAdapter->asUsbRcb[i].urb = NULL;
65 AdapterFree(psIntfAdapter->psAdapter);
68 static void ConfigureEndPointTypesThroughEEPROM(PMINI_ADAPTER Adapter)
70 unsigned long ulReg = 0;
71 int ret;
73 /* Program EP2 MAX_PKT_SIZE */
74 ulReg = ntohl(EP2_MPS_REG);
75 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x128, 4, TRUE);
76 ulReg = ntohl(EP2_MPS);
77 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x12C, 4, TRUE);
79 ulReg = ntohl(EP2_CFG_REG);
80 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x132, 4, TRUE);
81 if (((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter))->bHighSpeedDevice == TRUE) {
82 ulReg = ntohl(EP2_CFG_INT);
83 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE);
84 } else {
85 /* USE BULK EP as TX in FS mode. */
86 ulReg = ntohl(EP2_CFG_BULK);
87 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE);
90 /* Program EP4 MAX_PKT_SIZE. */
91 ulReg = ntohl(EP4_MPS_REG);
92 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x13C, 4, TRUE);
93 ulReg = ntohl(EP4_MPS);
94 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x140, 4, TRUE);
96 /* Program TX EP as interrupt(Alternate Setting) */
97 ret = rdmalt(Adapter, 0x0F0110F8, (u32 *)&ulReg, sizeof(u32));
98 if (ret) {
99 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
100 "reading of Tx EP failed\n");
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);
117 * Update EEPROM Version.
118 * Read 4 bytes from 508 and modify 511 and 510.
120 ReadBeceemEEPROM(Adapter, 0x1FC, (PUINT)&ulReg);
121 ulReg &= 0x0101FFFF;
122 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1FC, 4, TRUE);
124 /* Update length field if required. Also make the string NULL terminated. */
126 ReadBeceemEEPROM(Adapter, 0xA8, (PUINT)&ulReg);
127 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) {
133 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
134 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x148, 4, TRUE);
136 ulReg = 0;
137 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x122, 4, TRUE);
138 ulReg = 0;
139 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C2, 4, TRUE);
142 static int
143 usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id)
145 struct usb_device *udev = interface_to_usbdev(intf);
146 int retval;
147 PMINI_ADAPTER psAdapter;
148 PS_INTERFACE_ADAPTER psIntfAdapter;
149 struct net_device *ndev;
151 /* Reserve one extra queue for the bit-bucket */
152 ndev = alloc_etherdev_mq(sizeof(MINI_ADAPTER), NO_OF_QUEUES+1);
153 if (ndev == NULL) {
154 dev_err(&udev->dev, DRV_NAME ": no memory for device\n");
155 return -ENOMEM;
158 SET_NETDEV_DEV(ndev, &intf->dev);
160 psAdapter = netdev_priv(ndev);
161 psAdapter->dev = ndev;
162 psAdapter->msg_enable = netif_msg_init(debug, default_msg);
164 /* Init default driver debug state */
166 psAdapter->stDebugState.debug_level = DBG_LVL_CURR;
167 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) {
186 dev_err(&udev->dev, DRV_NAME ": InitAdapter Failed\n");
187 AdapterFree(psAdapter);
188 return retval;
191 /* Allocate interface adapter structure */
192 psIntfAdapter = kzalloc(sizeof(S_INTERFACE_ADAPTER), GFP_KERNEL);
193 if (psIntfAdapter == NULL) {
194 dev_err(&udev->dev, DRV_NAME ": no memory for Interface adapter\n");
195 AdapterFree(psAdapter);
196 return -ENOMEM;
199 psAdapter->pvInterfaceAdapter = psIntfAdapter;
200 psIntfAdapter->psAdapter = psAdapter;
202 /* Store usb interface in Interface Adapter */
203 psIntfAdapter->interface = intf;
204 usb_set_intfdata(intf, psIntfAdapter);
206 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
207 "psIntfAdapter 0x%p\n", psIntfAdapter);
208 retval = InterfaceAdapterInit(psIntfAdapter);
209 if (retval) {
210 /* If the Firmware/Cfg File is not present
211 * then return success, let the application
212 * download the files.
214 if (-ENOENT == retval) {
215 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
216 "File Not Found. Use app to download.\n");
217 return STATUS_SUCCESS;
219 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
220 "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) {
228 uint32_t uiNackZeroLengthInt = 4;
230 retval = wrmalt(psAdapter, DISABLE_USB_ZERO_LEN_INT, &uiNackZeroLengthInt, sizeof(uiNackZeroLengthInt));
231 if (retval)
232 return retval;
235 /* Check whether the USB-Device Supports remote Wake-Up */
236 if (USB_CONFIG_ATT_WAKEUP & udev->actconfig->desc.bmAttributes) {
237 /* If Suspend then only support dynamic suspend */
238 if (psAdapter->bDoSuspend) {
239 #ifdef CONFIG_PM
240 pm_runtime_set_autosuspend_delay(&udev->dev, 0);
241 intf->needs_remote_wakeup = 1;
242 usb_enable_autosuspend(udev);
243 device_init_wakeup(&intf->dev, 1);
244 INIT_WORK(&psIntfAdapter->usbSuspendWork, putUsbSuspend);
245 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
246 "Enabling USB Auto-Suspend\n");
247 #endif
248 } else {
249 intf->needs_remote_wakeup = 0;
250 usb_disable_autosuspend(udev);
254 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0x0;
255 return retval;
258 static void usbbcm_disconnect(struct usb_interface *intf)
260 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
261 PMINI_ADAPTER psAdapter;
262 struct usb_device *udev = interface_to_usbdev(intf);
264 if (psIntfAdapter == NULL)
265 return;
267 psAdapter = psIntfAdapter->psAdapter;
268 netif_device_detach(psAdapter->dev);
270 if (psAdapter->bDoSuspend)
271 intf->needs_remote_wakeup = 0;
273 psAdapter->device_removed = TRUE ;
274 usb_set_intfdata(intf, NULL);
275 InterfaceAdapterFree(psIntfAdapter);
276 usb_put_dev(udev);
279 static int AllocUsbCb(PS_INTERFACE_ADAPTER psIntfAdapter)
281 int i = 0;
283 for (i = 0; i < MAXIMUM_USB_TCB; i++) {
284 if ((psIntfAdapter->asUsbTcb[i].urb =
285 usb_alloc_urb(0, GFP_KERNEL)) == NULL) {
286 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
287 "Can't allocate Tx urb for index %d\n", i);
288 return -ENOMEM;
292 for (i = 0; i < MAXIMUM_USB_RCB; i++) {
293 if ((psIntfAdapter->asUsbRcb[i].urb =
294 usb_alloc_urb(0, GFP_KERNEL)) == NULL) {
295 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
296 "Can't allocate Rx urb for index %d\n", i);
297 return -ENOMEM;
299 if ((psIntfAdapter->asUsbRcb[i].urb->transfer_buffer =
300 kmalloc(MAX_DATA_BUFFER_SIZE, GFP_KERNEL)) == NULL) {
301 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
302 "Can't allocate Rx buffer for index %d\n", i);
303 return -ENOMEM;
305 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer_length = MAX_DATA_BUFFER_SIZE;
307 return 0;
310 static int device_run(PS_INTERFACE_ADAPTER psIntfAdapter)
312 int value = 0;
313 UINT status = STATUS_SUCCESS;
315 status = InitCardAndDownloadFirmware(psIntfAdapter->psAdapter);
316 if (status != STATUS_SUCCESS) {
317 pr_err(DRV_NAME "InitCardAndDownloadFirmware failed.\n");
318 return status;
320 if (TRUE == psIntfAdapter->psAdapter->fw_download_done) {
321 if (StartInterruptUrb(psIntfAdapter)) {
322 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
323 "Cannot send interrupt in URB\n");
327 * now register the cntrl interface.
328 * after downloading the f/w waiting for 5 sec to get the mailbox interrupt.
330 psIntfAdapter->psAdapter->waiting_to_fw_download_done = FALSE;
331 value = wait_event_timeout(psIntfAdapter->psAdapter->ioctl_fw_dnld_wait_queue,
332 psIntfAdapter->psAdapter->waiting_to_fw_download_done, 5*HZ);
334 if (value == 0)
335 pr_err(DRV_NAME ": Timeout waiting for mailbox interrupt.\n");
337 if (register_control_device_interface(psIntfAdapter->psAdapter) < 0) {
338 pr_err(DRV_NAME ": Register Control Device failed.\n");
339 return -EIO;
342 return 0;
346 static inline int bcm_usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
348 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
351 static inline int bcm_usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
353 return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
356 static inline int bcm_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
358 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
361 static inline int bcm_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)
363 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
366 static inline int bcm_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
368 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
369 USB_ENDPOINT_XFER_BULK);
372 static inline int bcm_usb_endpoint_xfer_control(const struct usb_endpoint_descriptor *epd)
374 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
375 USB_ENDPOINT_XFER_CONTROL);
378 static inline int bcm_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
380 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
381 USB_ENDPOINT_XFER_INT);
384 static inline int bcm_usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd)
386 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
387 USB_ENDPOINT_XFER_ISOC);
390 static inline int bcm_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
392 return (bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_in(epd));
395 static inline int bcm_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
397 return (bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_out(epd));
400 static inline int bcm_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
402 return (bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_in(epd));
405 static inline int bcm_usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd)
407 return (bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_out(epd));
410 static inline int bcm_usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd)
412 return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_in(epd));
415 static inline int bcm_usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd)
417 return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_out(epd));
420 static int InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter)
422 struct usb_host_interface *iface_desc;
423 struct usb_endpoint_descriptor *endpoint;
424 size_t buffer_size;
425 unsigned long value;
426 int retval = 0;
427 int usedIntOutForBulkTransfer = 0 ;
428 BOOLEAN bBcm16 = FALSE;
429 UINT uiData = 0;
431 /* Store the usb dev into interface adapter */
432 psIntfAdapter->udev = usb_get_dev(interface_to_usbdev(psIntfAdapter->interface));
434 psIntfAdapter->bHighSpeedDevice = (psIntfAdapter->udev->speed == USB_SPEED_HIGH);
435 psIntfAdapter->psAdapter->interface_rdm = BcmRDM;
436 psIntfAdapter->psAdapter->interface_wrm = BcmWRM;
438 retval = rdmalt(psIntfAdapter->psAdapter, CHIP_ID_REG,
439 (u32 *)&(psIntfAdapter->psAdapter->chip_id), sizeof(u32));
440 if (retval) {
441 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, "CHIP ID Read Failed\n");
442 return retval;
445 if (0xbece3200 == (psIntfAdapter->psAdapter->chip_id & ~(0xF0)))
446 psIntfAdapter->psAdapter->chip_id &= ~0xF0;
448 dev_info(&psIntfAdapter->udev->dev, "RDM Chip ID 0x%lx\n",
449 psIntfAdapter->psAdapter->chip_id);
451 iface_desc = psIntfAdapter->interface->cur_altsetting;
453 if (psIntfAdapter->psAdapter->chip_id == T3B) {
454 /* T3B device will have EEPROM, check if EEPROM is proper and BCM16 can be done or not. */
455 BeceemEEPROMBulkRead(psIntfAdapter->psAdapter, &uiData, 0x0, 4);
456 if (uiData == BECM)
457 bBcm16 = TRUE;
459 dev_info(&psIntfAdapter->udev->dev, "number of alternate setting %d\n",
460 psIntfAdapter->interface->num_altsetting);
462 if (bBcm16 == TRUE) {
463 /* selecting alternate setting one as a default setting for High Speed modem. */
464 if (psIntfAdapter->bHighSpeedDevice)
465 retval= usb_set_interface(psIntfAdapter->udev, DEFAULT_SETTING_0, ALTERNATE_SETTING_1);
466 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
467 "BCM16 is applicable on this dongle\n");
468 if (retval || (psIntfAdapter->bHighSpeedDevice == FALSE)) {
469 usedIntOutForBulkTransfer = EP2 ;
470 endpoint = &iface_desc->endpoint[EP2].desc;
471 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
472 "Interface altsetting failed or modem is configured to Full Speed, hence will work on default setting 0\n");
474 * If Modem is high speed device EP2 should be INT OUT End point
475 * If Mode is FS then EP2 should be bulk end point
477 if (((psIntfAdapter->bHighSpeedDevice == TRUE) && (bcm_usb_endpoint_is_int_out(endpoint) == FALSE))
478 || ((psIntfAdapter->bHighSpeedDevice == FALSE) && (bcm_usb_endpoint_is_bulk_out(endpoint) == FALSE))) {
479 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
480 "Configuring the EEPROM\n");
481 /* change the EP2, EP4 to INT OUT end point */
482 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter);
485 * It resets the device and if any thing gets changed
486 * in USB descriptor it will show fail and re-enumerate
487 * the device
489 retval = usb_reset_device(psIntfAdapter->udev);
490 if (retval) {
491 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
492 "reset failed. Re-enumerating the device.\n");
493 return retval ;
497 if ((psIntfAdapter->bHighSpeedDevice == FALSE) && bcm_usb_endpoint_is_bulk_out(endpoint)) {
498 /* Once BULK is selected in FS mode. Revert it back to INT. Else USB_IF will fail. */
499 UINT _uiData = ntohl(EP2_CFG_INT);
500 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
501 "Reverting Bulk to INT as it is in Full Speed mode.\n");
502 BeceemEEPROMBulkWrite(psIntfAdapter->psAdapter, (PUCHAR)&_uiData, 0x136, 4, TRUE);
504 } else {
505 usedIntOutForBulkTransfer = EP4 ;
506 endpoint = &iface_desc->endpoint[EP4].desc;
507 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
508 "Choosing AltSetting as a default setting.\n");
509 if (bcm_usb_endpoint_is_int_out(endpoint) == FALSE) {
510 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
511 "Dongle does not have BCM16 Fix.\n");
512 /* change the EP2, EP4 to INT OUT end point and use EP4 in altsetting */
513 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter);
516 * It resets the device and if any thing gets changed in
517 * USB descriptor it will show fail and re-enumerate the
518 * device
520 retval = usb_reset_device(psIntfAdapter->udev);
521 if (retval) {
522 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
523 "reset failed. Re-enumerating the device.\n");
524 return retval;
532 iface_desc = psIntfAdapter->interface->cur_altsetting;
534 for (value = 0; value < iface_desc->desc.bNumEndpoints; ++value) {
535 endpoint = &iface_desc->endpoint[value].desc;
537 if (!psIntfAdapter->sBulkIn.bulk_in_endpointAddr && bcm_usb_endpoint_is_bulk_in(endpoint)) {
538 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
539 psIntfAdapter->sBulkIn.bulk_in_size = buffer_size;
540 psIntfAdapter->sBulkIn.bulk_in_endpointAddr = endpoint->bEndpointAddress;
541 psIntfAdapter->sBulkIn.bulk_in_pipe =
542 usb_rcvbulkpipe(psIntfAdapter->udev,
543 psIntfAdapter->sBulkIn.bulk_in_endpointAddr);
546 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr && bcm_usb_endpoint_is_bulk_out(endpoint)) {
547 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = endpoint->bEndpointAddress;
548 psIntfAdapter->sBulkOut.bulk_out_pipe =
549 usb_sndbulkpipe(psIntfAdapter->udev,
550 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
553 if (!psIntfAdapter->sIntrIn.int_in_endpointAddr && bcm_usb_endpoint_is_int_in(endpoint)) {
554 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
555 psIntfAdapter->sIntrIn.int_in_size = buffer_size;
556 psIntfAdapter->sIntrIn.int_in_endpointAddr = endpoint->bEndpointAddress;
557 psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval;
558 psIntfAdapter->sIntrIn.int_in_buffer =
559 kmalloc(buffer_size, GFP_KERNEL);
560 if (!psIntfAdapter->sIntrIn.int_in_buffer) {
561 dev_err(&psIntfAdapter->udev->dev,
562 "could not allocate interrupt_in_buffer\n");
563 return -EINVAL;
567 if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint)) {
568 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr &&
569 (psIntfAdapter->psAdapter->chip_id == T3B) && (value == usedIntOutForBulkTransfer)) {
570 /* use first intout end point as a bulk out end point */
571 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
572 psIntfAdapter->sBulkOut.bulk_out_size = buffer_size;
573 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = endpoint->bEndpointAddress;
574 psIntfAdapter->sBulkOut.bulk_out_pipe = usb_sndintpipe(psIntfAdapter->udev,
575 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
576 psIntfAdapter->sBulkOut.int_out_interval = endpoint->bInterval;
577 } else if (value == EP6) {
578 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
579 psIntfAdapter->sIntrOut.int_out_size = buffer_size;
580 psIntfAdapter->sIntrOut.int_out_endpointAddr = endpoint->bEndpointAddress;
581 psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval;
582 psIntfAdapter->sIntrOut.int_out_buffer= kmalloc(buffer_size, GFP_KERNEL);
583 if (!psIntfAdapter->sIntrOut.int_out_buffer) {
584 dev_err(&psIntfAdapter->udev->dev,
585 "could not allocate interrupt_out_buffer\n");
586 return -EINVAL;
592 usb_set_intfdata(psIntfAdapter->interface, psIntfAdapter);
594 psIntfAdapter->psAdapter->bcm_file_download = InterfaceFileDownload;
595 psIntfAdapter->psAdapter->bcm_file_readback_from_chip =
596 InterfaceFileReadbackFromChip;
597 psIntfAdapter->psAdapter->interface_transmit = InterfaceTransmitPacket;
599 retval = CreateInterruptUrb(psIntfAdapter);
601 if (retval) {
602 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
603 "Cannot create interrupt urb\n");
604 return retval;
607 retval = AllocUsbCb(psIntfAdapter);
608 if (retval)
609 return retval;
611 return device_run(psIntfAdapter);
614 static int InterfaceSuspend(struct usb_interface *intf, pm_message_t message)
616 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
618 psIntfAdapter->bSuspended = TRUE;
620 if (TRUE == psIntfAdapter->bPreparingForBusSuspend) {
621 psIntfAdapter->bPreparingForBusSuspend = FALSE;
623 if (psIntfAdapter->psAdapter->LinkStatus == LINKUP_DONE) {
624 psIntfAdapter->psAdapter->IdleMode = TRUE ;
625 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
626 "Host Entered in PMU Idle Mode.\n");
627 } else {
628 psIntfAdapter->psAdapter->bShutStatus = TRUE;
629 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
630 "Host Entered in PMU Shutdown Mode.\n");
633 psIntfAdapter->psAdapter->bPreparingForLowPowerMode = FALSE;
635 /* Signaling the control pkt path */
636 wake_up(&psIntfAdapter->psAdapter->lowpower_mode_wait_queue);
638 return 0;
641 static int InterfaceResume(struct usb_interface *intf)
643 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
644 mdelay(100);
646 psIntfAdapter->bSuspended = FALSE;
648 StartInterruptUrb(psIntfAdapter);
649 InterfaceRx(psIntfAdapter);
650 return 0;
653 static struct usb_driver usbbcm_driver = {
654 .name = "usbbcm",
655 .probe = usbbcm_device_probe,
656 .disconnect = usbbcm_disconnect,
657 .suspend = InterfaceSuspend,
658 .resume = InterfaceResume,
659 .id_table = InterfaceUsbtable,
660 .supports_autosuspend = 1,
663 struct class *bcm_class;
665 static __init int bcm_init(void)
667 printk(KERN_INFO "%s: %s, %s\n", DRV_NAME, DRV_DESCRIPTION, DRV_VERSION);
668 printk(KERN_INFO "%s\n", DRV_COPYRIGHT);
670 bcm_class = class_create(THIS_MODULE, DRV_NAME);
671 if (IS_ERR(bcm_class)) {
672 printk(KERN_ERR DRV_NAME ": could not create class\n");
673 return PTR_ERR(bcm_class);
676 return usb_register(&usbbcm_driver);
679 static __exit void bcm_exit(void)
681 usb_deregister(&usbbcm_driver);
682 class_destroy(bcm_class);
685 module_init(bcm_init);
686 module_exit(bcm_exit);
688 MODULE_DESCRIPTION(DRV_DESCRIPTION);
689 MODULE_VERSION(DRV_VERSION);
690 MODULE_LICENSE("GPL");