Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 1 | #include "headers.h" |
| 2 | |
| 3 | static struct usb_device_id InterfaceUsbtable[] = { |
| 4 | { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3) }, |
Stephen Hemminger | 2e44f76 | 2010-10-29 07:44:45 -0700 | [diff] [blame] | 5 | { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3B) }, |
| 6 | { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3L) }, |
| 7 | { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_226) }, |
| 8 | { USB_DEVICE(BCM_USB_VENDOR_ID_FOXCONN, BCM_USB_PRODUCT_ID_1901) }, |
| 9 | |
| 10 | { } |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 11 | }; |
Stephen Hemminger | 2e44f76 | 2010-10-29 07:44:45 -0700 | [diff] [blame] | 12 | MODULE_DEVICE_TABLE(usb, InterfaceUsbtable); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 13 | |
Stephen Hemminger | 2564a14 | 2010-10-29 08:11:12 -0700 | [diff] [blame] | 14 | static unsigned int debug_level = DBG_LVL_CURR; |
| 15 | module_param(debug_level, uint, 0644); |
| 16 | MODULE_PARM_DESC(debug_level, "Debug level (0=none,...,7=all)"); |
| 17 | |
| 18 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 19 | VOID InterfaceAdapterFree(PS_INTERFACE_ADAPTER psIntfAdapter) |
| 20 | { |
| 21 | INT i = 0; |
| 22 | // Wake up the wait_queue... |
| 23 | if(psIntfAdapter->psAdapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) |
| 24 | { |
| 25 | psIntfAdapter->psAdapter->DriverState = DRIVER_HALT; |
| 26 | wake_up(&psIntfAdapter->psAdapter->LEDInfo.notify_led_event); |
| 27 | } |
| 28 | reset_card_proc(psIntfAdapter->psAdapter); |
| 29 | |
| 30 | //worst case time taken by the RDM/WRM will be 5 sec. will check after every 100 ms |
| 31 | //to accertain the device is not being accessed. After this No RDM/WRM should be made. |
| 32 | while(psIntfAdapter->psAdapter->DeviceAccess) |
| 33 | { |
| 34 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Device is being Accessed \n"); |
| 35 | msleep(100); |
| 36 | } |
| 37 | /* Free interrupt URB */ |
| 38 | //psIntfAdapter->psAdapter->device_removed = TRUE; |
| 39 | if(psIntfAdapter->psInterruptUrb) |
| 40 | { |
| 41 | usb_free_urb(psIntfAdapter->psInterruptUrb); |
| 42 | } |
| 43 | |
| 44 | /* Free transmit URBs */ |
| 45 | for(i = 0; i < MAXIMUM_USB_TCB; i++) |
| 46 | { |
| 47 | if(psIntfAdapter->asUsbTcb[i].urb != NULL) |
| 48 | { |
| 49 | usb_free_urb(psIntfAdapter->asUsbTcb[i].urb); |
| 50 | psIntfAdapter->asUsbTcb[i].urb = NULL; |
| 51 | } |
| 52 | } |
| 53 | /* Free receive URB and buffers */ |
| 54 | for(i = 0; i < MAXIMUM_USB_RCB; i++) |
| 55 | { |
| 56 | if (psIntfAdapter->asUsbRcb[i].urb != NULL) |
| 57 | { |
Stephen Hemminger | 082e889 | 2010-11-01 09:35:21 -0400 | [diff] [blame] | 58 | kfree(psIntfAdapter->asUsbRcb[i].urb->transfer_buffer); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 59 | usb_free_urb(psIntfAdapter->asUsbRcb[i].urb); |
| 60 | psIntfAdapter->asUsbRcb[i].urb = NULL; |
| 61 | } |
| 62 | } |
| 63 | AdapterFree(psIntfAdapter->psAdapter); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | |
| 68 | static int usbbcm_open(struct inode *inode, struct file *file) |
| 69 | { |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static int usbbcm_release(struct inode *inode, struct file *file) |
| 74 | { |
| 75 | return 0; |
| 76 | } |
| 77 | |
Arnd Bergmann | 44a17eff | 2010-09-30 10:24:12 +0200 | [diff] [blame] | 78 | static ssize_t usbbcm_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 79 | { |
| 80 | return 0; |
| 81 | } |
| 82 | |
Arnd Bergmann | 44a17eff | 2010-09-30 10:24:12 +0200 | [diff] [blame] | 83 | static ssize_t usbbcm_write(struct file *file, const char __user *user_buffer, size_t count, loff_t *ppos) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 84 | { |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | VOID ConfigureEndPointTypesThroughEEPROM(PMINI_ADAPTER Adapter) |
| 90 | { |
| 91 | ULONG ulReg = 0; |
| 92 | |
| 93 | // Program EP2 MAX_PKT_SIZE |
| 94 | ulReg = ntohl(EP2_MPS_REG); |
| 95 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x128,4,TRUE); |
| 96 | ulReg = ntohl(EP2_MPS); |
| 97 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x12C,4,TRUE); |
| 98 | |
| 99 | ulReg = ntohl(EP2_CFG_REG); |
| 100 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x132,4,TRUE); |
| 101 | if(((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter))->bHighSpeedDevice == TRUE) |
| 102 | { |
| 103 | ulReg = ntohl(EP2_CFG_INT); |
| 104 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x136,4,TRUE); |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | // USE BULK EP as TX in FS mode. |
| 109 | ulReg = ntohl(EP2_CFG_BULK); |
| 110 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x136,4,TRUE); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | // Program EP4 MAX_PKT_SIZE. |
| 115 | ulReg = ntohl(EP4_MPS_REG); |
| 116 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x13C,4,TRUE); |
| 117 | ulReg = ntohl(EP4_MPS); |
| 118 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x140,4,TRUE); |
| 119 | |
| 120 | // Program TX EP as interrupt (Alternate Setting) |
| 121 | if( rdmalt(Adapter,0x0F0110F8, (PUINT)&ulReg,4)) |
| 122 | { |
| 123 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reading of Tx EP is failing"); |
| 124 | return ; |
| 125 | } |
| 126 | ulReg |= 0x6; |
| 127 | |
| 128 | ulReg = ntohl(ulReg); |
| 129 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1CC,4,TRUE); |
| 130 | |
| 131 | ulReg = ntohl(EP4_CFG_REG); |
| 132 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1C8,4,TRUE); |
| 133 | // Program ISOCHRONOUS EP size to zero. |
| 134 | ulReg = ntohl(ISO_MPS_REG); |
| 135 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1D2,4,TRUE); |
| 136 | ulReg = ntohl(ISO_MPS); |
| 137 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1D6,4,TRUE); |
| 138 | |
| 139 | // Update EEPROM Version. |
| 140 | // Read 4 bytes from 508 and modify 511 and 510. |
| 141 | // |
| 142 | ReadBeceemEEPROM(Adapter,0x1FC,(PUINT)&ulReg); |
| 143 | ulReg &= 0x0101FFFF; |
| 144 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1FC,4,TRUE); |
| 145 | // |
| 146 | //Update length field if required. Also make the string NULL terminated. |
| 147 | // |
| 148 | ReadBeceemEEPROM(Adapter,0xA8,(PUINT)&ulReg); |
| 149 | if((ulReg&0x00FF0000)>>16 > 0x30) |
| 150 | { |
| 151 | ulReg = (ulReg&0xFF00FFFF)|(0x30<<16); |
| 152 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0xA8,4,TRUE); |
| 153 | } |
| 154 | ReadBeceemEEPROM(Adapter,0x148,(PUINT)&ulReg); |
| 155 | if((ulReg&0x00FF0000)>>16 > 0x30) |
| 156 | { |
| 157 | ulReg = (ulReg&0xFF00FFFF)|(0x30<<16); |
| 158 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x148,4,TRUE); |
| 159 | } |
| 160 | ulReg = 0; |
| 161 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x122,4,TRUE); |
| 162 | ulReg = 0; |
| 163 | BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1C2,4,TRUE); |
| 164 | |
| 165 | } |
| 166 | |
| 167 | static struct file_operations usbbcm_fops = { |
| 168 | .open = usbbcm_open, |
| 169 | .release = usbbcm_release, |
| 170 | .read = usbbcm_read, |
| 171 | .write = usbbcm_write, |
| 172 | .owner = THIS_MODULE, |
Arnd Bergmann | d16044cf | 2010-09-30 10:24:07 +0200 | [diff] [blame] | 173 | .llseek = no_llseek, |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | static struct usb_class_driver usbbcm_class = { |
| 177 | .name = "usbbcm", |
| 178 | .fops = &usbbcm_fops, |
| 179 | .minor_base = BCM_USB_MINOR_BASE, |
| 180 | }; |
| 181 | |
| 182 | static int |
| 183 | usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 184 | { |
Stephen Hemminger | e614e28 | 2010-11-01 09:52:14 -0400 | [diff] [blame^] | 185 | struct usb_device *udev = interface_to_usbdev (intf); |
| 186 | int retval; |
| 187 | PMINI_ADAPTER psAdapter; |
| 188 | PS_INTERFACE_ADAPTER psIntfAdapter; |
| 189 | struct net_device *ndev; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 190 | |
Stephen Hemminger | e614e28 | 2010-11-01 09:52:14 -0400 | [diff] [blame^] | 191 | ndev = alloc_etherdev(sizeof(MINI_ADAPTER)); |
| 192 | if(ndev == NULL) { |
| 193 | dev_err(&udev->dev, DRV_NAME ": no memory for device\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 194 | return -ENOMEM; |
| 195 | } |
| 196 | |
Stephen Hemminger | e614e28 | 2010-11-01 09:52:14 -0400 | [diff] [blame^] | 197 | SET_NETDEV_DEV(ndev, &intf->dev); |
| 198 | |
| 199 | psAdapter = netdev_priv(ndev); |
| 200 | psAdapter->dev = ndev; |
| 201 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 202 | /* Init default driver debug state */ |
| 203 | |
Stephen Hemminger | 2564a14 | 2010-10-29 08:11:12 -0700 | [diff] [blame] | 204 | psAdapter->stDebugState.debug_level = debug_level; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 205 | psAdapter->stDebugState.type = DBG_TYPE_INITEXIT; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 206 | |
| 207 | /* Technically, one can start using BCM_DEBUG_PRINT after this point. |
| 208 | * However, realize that by default the Type/Subtype bitmaps are all zero now; |
| 209 | * so no prints will actually appear until the TestApp turns on debug paths via |
| 210 | * the ioctl(); so practically speaking, in early init, no logging happens. |
| 211 | * |
| 212 | * A solution (used below): we explicitly set the bitmaps to 1 for Type=DBG_TYPE_INITEXIT |
| 213 | * and ALL subtype's of the same. Now all bcm debug statements get logged, enabling debug |
| 214 | * during early init. |
| 215 | * Further, we turn this OFF once init_module() completes. |
| 216 | */ |
| 217 | |
| 218 | psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0xff; |
| 219 | BCM_SHOW_DEBUG_BITMAP(psAdapter); |
| 220 | |
| 221 | retval = InitAdapter(psAdapter); |
| 222 | if(retval) |
| 223 | { |
Stephen Hemminger | e614e28 | 2010-11-01 09:52:14 -0400 | [diff] [blame^] | 224 | dev_err(&udev->dev, DRV_NAME ": InitAdapter Failed\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 225 | AdapterFree(psAdapter); |
| 226 | return retval; |
| 227 | } |
| 228 | |
| 229 | /* Allocate interface adapter structure */ |
Stephen Hemminger | e614e28 | 2010-11-01 09:52:14 -0400 | [diff] [blame^] | 230 | psIntfAdapter = kzalloc(sizeof(S_INTERFACE_ADAPTER), GFP_KERNEL); |
| 231 | if (psIntfAdapter == NULL) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 232 | { |
Stephen Hemminger | e614e28 | 2010-11-01 09:52:14 -0400 | [diff] [blame^] | 233 | dev_err(&udev->dev, DRV_NAME ": no memory for Interface adapter\n"); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 234 | AdapterFree (psAdapter); |
| 235 | return -ENOMEM; |
| 236 | } |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 237 | |
Stephen Hemminger | e614e28 | 2010-11-01 09:52:14 -0400 | [diff] [blame^] | 238 | psAdapter->pvInterfaceAdapter = psIntfAdapter; |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 239 | psIntfAdapter->psAdapter = psAdapter; |
| 240 | |
| 241 | /* Store usb interface in Interface Adapter */ |
| 242 | psIntfAdapter->interface = intf; |
| 243 | usb_set_intfdata(intf, psIntfAdapter); |
| 244 | |
Arnd Bergmann | 9f1c75a | 2010-09-30 10:24:11 +0200 | [diff] [blame] | 245 | BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "psIntfAdapter 0x%p",psIntfAdapter); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 246 | retval = InterfaceAdapterInit(psIntfAdapter); |
| 247 | if(retval) |
| 248 | { |
| 249 | /* If the Firmware/Cfg File is not present |
| 250 | * then return success, let the application |
| 251 | * download the files. |
| 252 | */ |
| 253 | if(-ENOENT == retval){ |
| 254 | BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "File Not Found, Use App to Download\n"); |
| 255 | return STATUS_SUCCESS; |
| 256 | } |
| 257 | BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "InterfaceAdapterInit Failed \n"); |
| 258 | usb_set_intfdata(intf, NULL); |
| 259 | udev = interface_to_usbdev (intf); |
| 260 | usb_put_dev(udev); |
| 261 | if(psAdapter->bUsbClassDriverRegistered == TRUE) |
| 262 | usb_deregister_dev (intf, &usbbcm_class); |
| 263 | InterfaceAdapterFree(psIntfAdapter); |
| 264 | return retval ; |
| 265 | } |
| 266 | if(psAdapter->chip_id > T3) |
| 267 | { |
| 268 | uint32_t uiNackZeroLengthInt=4; |
| 269 | if(wrmalt(psAdapter, DISABLE_USB_ZERO_LEN_INT, &uiNackZeroLengthInt, sizeof(uiNackZeroLengthInt))) |
| 270 | { |
| 271 | return -EIO;; |
| 272 | } |
| 273 | } |
| 274 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 275 | /* Check whether the USB-Device Supports remote Wake-Up */ |
| 276 | if(USB_CONFIG_ATT_WAKEUP & udev->actconfig->desc.bmAttributes) |
| 277 | { |
| 278 | /* If Suspend then only support dynamic suspend */ |
| 279 | if(psAdapter->bDoSuspend) |
| 280 | { |
Randy Dunlap | 5fe1f1e | 2010-09-14 15:39:50 -0700 | [diff] [blame] | 281 | #ifdef CONFIG_PM |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 282 | udev->autosuspend_delay = 0; |
| 283 | intf->needs_remote_wakeup = 1; |
| 284 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) |
| 285 | udev->autosuspend_disabled = 0; |
| 286 | #else |
| 287 | usb_enable_autosuspend(udev); |
| 288 | #endif |
| 289 | device_init_wakeup(&intf->dev,1); |
| 290 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32) |
| 291 | usb_autopm_disable(intf); |
| 292 | #endif |
| 293 | INIT_WORK(&psIntfAdapter->usbSuspendWork, putUsbSuspend); |
| 294 | BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Enabling USB Auto-Suspend\n"); |
Randy Dunlap | 5fe1f1e | 2010-09-14 15:39:50 -0700 | [diff] [blame] | 295 | #endif |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 296 | } |
| 297 | else |
| 298 | { |
| 299 | intf->needs_remote_wakeup = 0; |
| 300 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) |
| 301 | udev->autosuspend_disabled = 1; |
| 302 | #else |
| 303 | usb_disable_autosuspend(udev); |
| 304 | #endif |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0x0; |
| 309 | return retval; |
| 310 | } |
| 311 | |
| 312 | static void usbbcm_disconnect (struct usb_interface *intf) |
| 313 | { |
| 314 | PS_INTERFACE_ADAPTER psIntfAdapter = NULL; |
| 315 | PMINI_ADAPTER psAdapter = NULL; |
| 316 | struct usb_device *udev = NULL; |
| 317 | PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); |
| 318 | |
| 319 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Usb disconnected"); |
| 320 | if(intf == NULL) |
| 321 | { |
| 322 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "intf pointer is NULL"); |
| 323 | return; |
| 324 | } |
| 325 | psIntfAdapter = usb_get_intfdata(intf); |
Arnd Bergmann | 9f1c75a | 2010-09-30 10:24:11 +0200 | [diff] [blame] | 326 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "psIntfAdapter 0x%p",psIntfAdapter); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 327 | if(psIntfAdapter == NULL) |
| 328 | { |
| 329 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "InterfaceAdapter pointer is NULL"); |
| 330 | return; |
| 331 | } |
| 332 | psAdapter = psIntfAdapter->psAdapter; |
| 333 | if(psAdapter->bDoSuspend) |
| 334 | intf->needs_remote_wakeup = 0; |
| 335 | |
| 336 | psAdapter->device_removed = TRUE ; |
| 337 | usb_set_intfdata(intf, NULL); |
| 338 | InterfaceAdapterFree(psIntfAdapter); |
| 339 | udev = interface_to_usbdev (intf); |
| 340 | usb_put_dev(udev); |
| 341 | usb_deregister_dev (intf, &usbbcm_class); |
| 342 | } |
| 343 | |
| 344 | |
| 345 | static __inline int AllocUsbCb(PS_INTERFACE_ADAPTER psIntfAdapter) |
| 346 | { |
| 347 | int i = 0; |
| 348 | for(i = 0; i < MAXIMUM_USB_TCB; i++) |
| 349 | { |
| 350 | if((psIntfAdapter->asUsbTcb[i].urb = |
| 351 | usb_alloc_urb(0, GFP_KERNEL)) == NULL) |
| 352 | { |
| 353 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cant allocate Tx urb for index %d", i); |
| 354 | return -ENOMEM; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | for(i = 0; i < MAXIMUM_USB_RCB; i++) |
| 359 | { |
| 360 | if ((psIntfAdapter->asUsbRcb[i].urb = |
| 361 | usb_alloc_urb(0, GFP_KERNEL)) == NULL) |
| 362 | { |
| 363 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cant allocate Rx urb for index %d", i); |
| 364 | return -ENOMEM; |
| 365 | } |
| 366 | if((psIntfAdapter->asUsbRcb[i].urb->transfer_buffer = |
| 367 | kmalloc(MAX_DATA_BUFFER_SIZE, GFP_KERNEL)) == NULL) |
| 368 | { |
| 369 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cant allocate Rx buffer for index %d", i); |
| 370 | return -ENOMEM; |
| 371 | } |
| 372 | psIntfAdapter->asUsbRcb[i].urb->transfer_buffer_length = MAX_DATA_BUFFER_SIZE; |
| 373 | } |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | |
| 378 | |
| 379 | static int device_run(PS_INTERFACE_ADAPTER psIntfAdapter) |
| 380 | { |
| 381 | INT value = 0; |
| 382 | UINT status = STATUS_SUCCESS; |
| 383 | |
| 384 | status = InitCardAndDownloadFirmware(psIntfAdapter->psAdapter); |
| 385 | if(status != STATUS_SUCCESS) |
| 386 | { |
| 387 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "InitCardAndDownloadFirmware failed.\n"); |
| 388 | return status; |
| 389 | } |
| 390 | if(TRUE == psIntfAdapter->psAdapter->fw_download_done) |
| 391 | { |
| 392 | |
| 393 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Sending first interrupt URB down......"); |
| 394 | if(StartInterruptUrb(psIntfAdapter)) |
| 395 | { |
| 396 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Cannot send interrupt in URB"); |
| 397 | } |
| 398 | //now register the cntrl interface. |
| 399 | //after downloading the f/w waiting for 5 sec to get the mailbox interrupt. |
| 400 | |
| 401 | psIntfAdapter->psAdapter->waiting_to_fw_download_done = FALSE; |
| 402 | value = wait_event_timeout(psIntfAdapter->psAdapter->ioctl_fw_dnld_wait_queue, |
| 403 | psIntfAdapter->psAdapter->waiting_to_fw_download_done, 5*HZ); |
| 404 | |
| 405 | if(value == 0) |
| 406 | { |
| 407 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Mailbox Interrupt has not reached to Driver.."); |
| 408 | } |
| 409 | else |
| 410 | { |
| 411 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Got the mailbox interrupt ...Registering control interface...\n "); |
| 412 | } |
| 413 | if(register_control_device_interface(psIntfAdapter->psAdapter) < 0) |
| 414 | { |
| 415 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Register Control Device failed..."); |
| 416 | return -EIO; |
| 417 | } |
| 418 | } |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | #if 0 |
| 423 | static void print_usb_interface_desc(struct usb_interface_descriptor *usb_intf_desc) |
| 424 | { |
| 425 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "**************** INTERFACE DESCRIPTOR *********************"); |
| 426 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bLength: %x", usb_intf_desc->bLength); |
| 427 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bDescriptorType: %x", usb_intf_desc->bDescriptorType); |
| 428 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bInterfaceNumber: %x", usb_intf_desc->bInterfaceNumber); |
| 429 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bAlternateSetting: %x", usb_intf_desc->bAlternateSetting); |
| 430 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bNumEndpoints: %x", usb_intf_desc->bNumEndpoints); |
| 431 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bInterfaceClass: %x", usb_intf_desc->bInterfaceClass); |
| 432 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bInterfaceSubClass: %x", usb_intf_desc->bInterfaceSubClass); |
| 433 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bInterfaceProtocol: %x", usb_intf_desc->bInterfaceProtocol); |
| 434 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "iInterface :%x\n",usb_intf_desc->iInterface); |
| 435 | } |
| 436 | static void print_usb_endpoint_descriptor(struct usb_endpoint_descriptor *usb_ep_desc) |
| 437 | { |
| 438 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "**************** ENDPOINT DESCRIPTOR *********************"); |
| 439 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bLength :%x ", usb_ep_desc->bLength); |
| 440 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bDescriptorType :%x ", usb_ep_desc->bDescriptorType); |
| 441 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bEndpointAddress :%x ", usb_ep_desc->bEndpointAddress); |
| 442 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bmAttributes :%x ", usb_ep_desc->bmAttributes); |
| 443 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "wMaxPacketSize :%x ",usb_ep_desc->wMaxPacketSize); |
| 444 | BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bInterval :%x ",usb_ep_desc->bInterval); |
| 445 | } |
| 446 | |
| 447 | #endif |
| 448 | |
| 449 | static inline int bcm_usb_endpoint_num(const struct usb_endpoint_descriptor *epd) |
| 450 | { |
| 451 | return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; |
| 452 | } |
| 453 | |
| 454 | static inline int bcm_usb_endpoint_type(const struct usb_endpoint_descriptor *epd) |
| 455 | { |
| 456 | return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; |
| 457 | } |
| 458 | |
| 459 | static inline int bcm_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd) |
| 460 | { |
| 461 | return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN); |
| 462 | } |
| 463 | |
| 464 | static inline int bcm_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd) |
| 465 | { |
| 466 | return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT); |
| 467 | } |
| 468 | |
| 469 | static inline int bcm_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd) |
| 470 | { |
| 471 | return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == |
| 472 | USB_ENDPOINT_XFER_BULK); |
| 473 | } |
| 474 | |
| 475 | static inline int bcm_usb_endpoint_xfer_control(const struct usb_endpoint_descriptor *epd) |
| 476 | { |
| 477 | return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == |
| 478 | USB_ENDPOINT_XFER_CONTROL); |
| 479 | } |
| 480 | |
| 481 | static inline int bcm_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd) |
| 482 | { |
| 483 | return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == |
| 484 | USB_ENDPOINT_XFER_INT); |
| 485 | } |
| 486 | |
| 487 | static inline int bcm_usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd) |
| 488 | { |
| 489 | return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == |
| 490 | USB_ENDPOINT_XFER_ISOC); |
| 491 | } |
| 492 | |
| 493 | static inline int bcm_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd) |
| 494 | { |
| 495 | return (bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_in(epd)); |
| 496 | } |
| 497 | |
| 498 | static inline int bcm_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd) |
| 499 | { |
| 500 | return (bcm_usb_endpoint_xfer_bulk(epd) && bcm_usb_endpoint_dir_out(epd)); |
| 501 | } |
| 502 | |
| 503 | static inline int bcm_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd) |
| 504 | { |
| 505 | return (bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_in(epd)); |
| 506 | } |
| 507 | |
| 508 | static inline int bcm_usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd) |
| 509 | { |
| 510 | return (bcm_usb_endpoint_xfer_int(epd) && bcm_usb_endpoint_dir_out(epd)); |
| 511 | } |
| 512 | |
| 513 | static inline int bcm_usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd) |
| 514 | { |
| 515 | return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_in(epd)); |
| 516 | } |
| 517 | |
| 518 | static inline int bcm_usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd) |
| 519 | { |
| 520 | return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_out(epd)); |
| 521 | } |
| 522 | |
| 523 | INT InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter) |
| 524 | { |
| 525 | struct usb_host_interface *iface_desc; |
| 526 | struct usb_endpoint_descriptor *endpoint; |
| 527 | size_t buffer_size; |
| 528 | ULONG value; |
| 529 | INT retval = 0; |
| 530 | INT usedIntOutForBulkTransfer = 0 ; |
| 531 | BOOLEAN bBcm16 = FALSE; |
| 532 | UINT uiData = 0; |
| 533 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 534 | /* Store the usb dev into interface adapter */ |
| 535 | psIntfAdapter->udev = usb_get_dev(interface_to_usbdev( |
| 536 | psIntfAdapter->interface)); |
| 537 | |
| 538 | if((psIntfAdapter->udev->speed == USB_SPEED_HIGH)) |
| 539 | { |
| 540 | psIntfAdapter->bHighSpeedDevice = TRUE ; |
| 541 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "MODEM IS CONFIGURED TO HIGH_SPEED "); |
| 542 | } |
| 543 | else |
| 544 | { |
| 545 | psIntfAdapter->bHighSpeedDevice = FALSE ; |
| 546 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "MODEM IS CONFIGURED TO FULL_SPEED "); |
| 547 | } |
| 548 | |
| 549 | psIntfAdapter->psAdapter->interface_rdm = BcmRDM; |
| 550 | psIntfAdapter->psAdapter->interface_wrm = BcmWRM; |
| 551 | |
| 552 | if(rdmalt(psIntfAdapter->psAdapter, CHIP_ID_REG, (PUINT)&(psIntfAdapter->psAdapter->chip_id), sizeof(UINT)) < 0) |
| 553 | { |
| 554 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "CHIP ID Read Failed\n"); |
| 555 | return STATUS_FAILURE; |
| 556 | } |
| 557 | if(0xbece3200==(psIntfAdapter->psAdapter->chip_id&~(0xF0))) |
| 558 | { |
| 559 | psIntfAdapter->psAdapter->chip_id=(psIntfAdapter->psAdapter->chip_id&~(0xF0)); |
| 560 | } |
| 561 | |
| 562 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "First RDM Chip ID 0x%lx\n", psIntfAdapter->psAdapter->chip_id); |
| 563 | |
| 564 | iface_desc = psIntfAdapter->interface->cur_altsetting; |
| 565 | //print_usb_interface_desc(&(iface_desc->desc)); |
| 566 | |
| 567 | if(psIntfAdapter->psAdapter->chip_id == T3B) |
| 568 | { |
| 569 | |
| 570 | // |
| 571 | //T3B device will have EEPROM,check if EEPROM is proper and BCM16 can be done or not. |
| 572 | // |
| 573 | BeceemEEPROMBulkRead(psIntfAdapter->psAdapter,&uiData,0x0,4); |
| 574 | if(uiData == BECM) |
| 575 | { |
| 576 | bBcm16 = TRUE; |
| 577 | } |
| 578 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Number of Altsetting aviailable for This Modem 0x%x\n", psIntfAdapter->interface->num_altsetting); |
| 579 | if(bBcm16 == TRUE) |
| 580 | { |
| 581 | //selecting alternate setting one as a default setting for High Speed modem. |
| 582 | if(psIntfAdapter->bHighSpeedDevice) |
| 583 | retval= usb_set_interface(psIntfAdapter->udev,DEFAULT_SETTING_0,ALTERNATE_SETTING_1); |
| 584 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "BCM16 is Applicable on this dongle"); |
| 585 | if(retval || (psIntfAdapter->bHighSpeedDevice == FALSE)) |
| 586 | { |
| 587 | usedIntOutForBulkTransfer = EP2 ; |
| 588 | endpoint = &iface_desc->endpoint[EP2].desc; |
| 589 | 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"); |
| 590 | /* |
| 591 | If Modem is high speed device EP2 should be INT OUT End point |
| 592 | If Mode is FS then EP2 should be bulk end point |
| 593 | */ |
| 594 | if(((psIntfAdapter->bHighSpeedDevice ==TRUE ) && (bcm_usb_endpoint_is_int_out(endpoint)== FALSE)) |
| 595 | ||((psIntfAdapter->bHighSpeedDevice == FALSE)&& (bcm_usb_endpoint_is_bulk_out(endpoint)== FALSE))) |
| 596 | { |
| 597 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Configuring the EEPROM "); |
| 598 | //change the EP2, EP4 to INT OUT end point |
| 599 | ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter); |
| 600 | |
| 601 | /* |
| 602 | It resets the device and if any thing gets changed in USB descriptor it will show fail and |
| 603 | re-enumerate the device |
| 604 | */ |
| 605 | retval = usb_reset_device(psIntfAdapter->udev); |
| 606 | if(retval) |
| 607 | { |
| 608 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reset got failed. hence Re-enumerating the device \n"); |
| 609 | return retval ; |
| 610 | } |
| 611 | |
| 612 | } |
| 613 | if((psIntfAdapter->bHighSpeedDevice == FALSE) && bcm_usb_endpoint_is_bulk_out(endpoint)) |
| 614 | { |
| 615 | // Once BULK is selected in FS mode. Revert it back to INT. Else USB_IF will fail. |
Arnd Bergmann | 44a17eff | 2010-09-30 10:24:12 +0200 | [diff] [blame] | 616 | UINT _uiData = ntohl(EP2_CFG_INT); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 617 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Reverting Bulk to INT as it is FS MODE"); |
Arnd Bergmann | 44a17eff | 2010-09-30 10:24:12 +0200 | [diff] [blame] | 618 | BeceemEEPROMBulkWrite(psIntfAdapter->psAdapter,(PUCHAR)&_uiData,0x136,4,TRUE); |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | else |
| 622 | { |
| 623 | usedIntOutForBulkTransfer = EP4 ; |
| 624 | endpoint = &iface_desc->endpoint[EP4].desc; |
| 625 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Choosing AltSetting as a default setting"); |
| 626 | if( bcm_usb_endpoint_is_int_out(endpoint) == FALSE) |
| 627 | { |
| 628 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, " Dongle does not have BCM16 Fix"); |
| 629 | //change the EP2, EP4 to INT OUT end point and use EP4 in altsetting |
| 630 | ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter); |
| 631 | |
| 632 | /* |
| 633 | It resets the device and if any thing gets changed in USB descriptor it will show fail and |
| 634 | re-enumerate the device |
| 635 | */ |
| 636 | retval = usb_reset_device(psIntfAdapter->udev); |
| 637 | if(retval) |
| 638 | { |
| 639 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reset got failed. hence Re-enumerating the device \n"); |
| 640 | return retval ; |
| 641 | } |
| 642 | |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | iface_desc = psIntfAdapter->interface->cur_altsetting; |
| 649 | //print_usb_interface_desc(&(iface_desc->desc)); |
| 650 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Current number of endpoints :%x \n", iface_desc->desc.bNumEndpoints); |
| 651 | for (value = 0; value < iface_desc->desc.bNumEndpoints; ++value) |
| 652 | { |
| 653 | endpoint = &iface_desc->endpoint[value].desc; |
| 654 | //print_usb_endpoint_descriptor(endpoint); |
| 655 | |
| 656 | if (!psIntfAdapter->sBulkIn.bulk_in_endpointAddr && bcm_usb_endpoint_is_bulk_in(endpoint)) |
| 657 | { |
| 658 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
| 659 | psIntfAdapter->sBulkIn.bulk_in_size = buffer_size; |
| 660 | psIntfAdapter->sBulkIn.bulk_in_endpointAddr = |
| 661 | endpoint->bEndpointAddress; |
| 662 | psIntfAdapter->sBulkIn.bulk_in_pipe = |
| 663 | usb_rcvbulkpipe(psIntfAdapter->udev, |
| 664 | psIntfAdapter->sBulkIn.bulk_in_endpointAddr); |
| 665 | } |
| 666 | |
| 667 | if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr && bcm_usb_endpoint_is_bulk_out(endpoint)) |
| 668 | { |
| 669 | |
| 670 | psIntfAdapter->sBulkOut.bulk_out_endpointAddr = |
| 671 | endpoint->bEndpointAddress; |
| 672 | psIntfAdapter->sBulkOut.bulk_out_pipe = |
| 673 | usb_sndbulkpipe(psIntfAdapter->udev, |
| 674 | psIntfAdapter->sBulkOut.bulk_out_endpointAddr); |
| 675 | } |
| 676 | |
| 677 | if (!psIntfAdapter->sIntrIn.int_in_endpointAddr && bcm_usb_endpoint_is_int_in(endpoint)) |
| 678 | { |
| 679 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
| 680 | psIntfAdapter->sIntrIn.int_in_size = buffer_size; |
| 681 | psIntfAdapter->sIntrIn.int_in_endpointAddr = |
| 682 | endpoint->bEndpointAddress; |
| 683 | psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval; |
| 684 | psIntfAdapter->sIntrIn.int_in_buffer = |
| 685 | kmalloc(buffer_size, GFP_KERNEL); |
| 686 | if (!psIntfAdapter->sIntrIn.int_in_buffer) { |
| 687 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Could not allocate interrupt_in_buffer"); |
| 688 | return -EINVAL; |
| 689 | } |
| 690 | //psIntfAdapter->sIntrIn.int_in_pipe = |
| 691 | } |
| 692 | |
| 693 | if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint)) |
| 694 | { |
| 695 | |
| 696 | if( !psIntfAdapter->sBulkOut.bulk_out_endpointAddr && |
| 697 | (psIntfAdapter->psAdapter->chip_id == T3B) && (value == usedIntOutForBulkTransfer)) |
| 698 | { |
| 699 | //use first intout end point as a bulk out end point |
| 700 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
| 701 | psIntfAdapter->sBulkOut.bulk_out_size = buffer_size; |
| 702 | //printk("\nINT OUT Endpoing buffer size :%x endpoint :%x\n", buffer_size, value +1); |
| 703 | psIntfAdapter->sBulkOut.bulk_out_endpointAddr = |
| 704 | endpoint->bEndpointAddress; |
| 705 | psIntfAdapter->sBulkOut.bulk_out_pipe = |
| 706 | usb_sndintpipe(psIntfAdapter->udev, |
| 707 | psIntfAdapter->sBulkOut.bulk_out_endpointAddr); |
| 708 | psIntfAdapter->sBulkOut.int_out_interval = endpoint->bInterval; |
| 709 | |
| 710 | } |
| 711 | else if(value == EP6) |
| 712 | { |
| 713 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
| 714 | psIntfAdapter->sIntrOut.int_out_size = buffer_size; |
| 715 | psIntfAdapter->sIntrOut.int_out_endpointAddr = |
| 716 | endpoint->bEndpointAddress; |
| 717 | psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval; |
| 718 | psIntfAdapter->sIntrOut.int_out_buffer= kmalloc(buffer_size, |
| 719 | GFP_KERNEL); |
| 720 | if (!psIntfAdapter->sIntrOut.int_out_buffer) |
| 721 | { |
| 722 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Could not allocate interrupt_out_buffer"); |
| 723 | return -EINVAL; |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | usb_set_intfdata(psIntfAdapter->interface, psIntfAdapter); |
| 729 | retval = usb_register_dev(psIntfAdapter->interface, &usbbcm_class); |
| 730 | if(retval) |
| 731 | { |
| 732 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "usb register dev failed = %d", retval); |
| 733 | psIntfAdapter->psAdapter->bUsbClassDriverRegistered = FALSE; |
| 734 | return retval; |
| 735 | } |
| 736 | else |
| 737 | { |
| 738 | psIntfAdapter->psAdapter->bUsbClassDriverRegistered = TRUE; |
| 739 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "usb dev registered"); |
| 740 | } |
| 741 | |
| 742 | psIntfAdapter->psAdapter->bcm_file_download = InterfaceFileDownload; |
| 743 | psIntfAdapter->psAdapter->bcm_file_readback_from_chip = |
| 744 | InterfaceFileReadbackFromChip; |
| 745 | psIntfAdapter->psAdapter->interface_transmit = InterfaceTransmitPacket; |
| 746 | |
| 747 | retval = CreateInterruptUrb(psIntfAdapter); |
| 748 | |
| 749 | if(retval) |
| 750 | { |
| 751 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cannot create interrupt urb"); |
| 752 | return retval; |
| 753 | } |
| 754 | |
| 755 | retval = AllocUsbCb(psIntfAdapter); |
| 756 | if(retval) |
| 757 | { |
| 758 | return retval; |
| 759 | } |
| 760 | |
| 761 | |
| 762 | retval = device_run(psIntfAdapter); |
| 763 | if(retval) |
| 764 | { |
| 765 | return retval; |
| 766 | } |
| 767 | |
| 768 | |
| 769 | return 0; |
| 770 | } |
Arnd Bergmann | 44a17eff | 2010-09-30 10:24:12 +0200 | [diff] [blame] | 771 | |
| 772 | static int InterfaceSuspend (struct usb_interface *intf, pm_message_t message) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 773 | { |
| 774 | PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf); |
| 775 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "=================================\n"); |
| 776 | //Bcm_kill_all_URBs(psIntfAdapter); |
| 777 | psIntfAdapter->bSuspended = TRUE; |
| 778 | |
| 779 | if(TRUE == psIntfAdapter->bPreparingForBusSuspend) |
| 780 | { |
| 781 | psIntfAdapter->bPreparingForBusSuspend = FALSE; |
| 782 | |
| 783 | if(psIntfAdapter->psAdapter->LinkStatus == LINKUP_DONE) |
| 784 | { |
| 785 | psIntfAdapter->psAdapter->IdleMode = TRUE ; |
| 786 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Host Entered in PMU Idle Mode.."); |
| 787 | } |
| 788 | else |
| 789 | { |
| 790 | psIntfAdapter->psAdapter->bShutStatus = TRUE; |
| 791 | BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Host Entered in PMU Shutdown Mode.."); |
| 792 | } |
| 793 | } |
| 794 | psIntfAdapter->psAdapter->bPreparingForLowPowerMode = FALSE; |
| 795 | |
| 796 | //Signaling the control pkt path |
| 797 | wake_up(&psIntfAdapter->psAdapter->lowpower_mode_wait_queue); |
| 798 | |
| 799 | return 0; |
| 800 | } |
Arnd Bergmann | 44a17eff | 2010-09-30 10:24:12 +0200 | [diff] [blame] | 801 | |
| 802 | static int InterfaceResume (struct usb_interface *intf) |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 803 | { |
| 804 | PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf); |
| 805 | printk("=================================\n"); |
| 806 | mdelay(100); |
| 807 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32) |
| 808 | intf->pm_usage_cnt =1 ; |
| 809 | #endif |
| 810 | psIntfAdapter->bSuspended = FALSE; |
| 811 | |
| 812 | StartInterruptUrb(psIntfAdapter); |
| 813 | InterfaceRx(psIntfAdapter); |
| 814 | return 0; |
| 815 | } |
Arnd Bergmann | 44a17eff | 2010-09-30 10:24:12 +0200 | [diff] [blame] | 816 | |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 817 | static struct usb_driver usbbcm_driver = { |
| 818 | .name = "usbbcm", |
| 819 | .probe = usbbcm_device_probe, |
| 820 | .disconnect = usbbcm_disconnect, |
| 821 | .suspend = InterfaceSuspend, |
| 822 | .resume = InterfaceResume, |
Stephen Hemminger | f8942e0 | 2010-09-08 14:46:36 -0700 | [diff] [blame] | 823 | .id_table = InterfaceUsbtable, |
| 824 | .supports_autosuspend = 1, |
| 825 | }; |
| 826 | |
| 827 | |
| 828 | /* |
| 829 | Function: InterfaceInitialize |
| 830 | |
| 831 | Description: This is the hardware specific initialization Function. |
| 832 | Registering the driver with NDIS , other device specific NDIS |
| 833 | and hardware initializations are done here. |
| 834 | |
| 835 | Input parameters: IN PMINI_ADAPTER Adapter - Miniport Adapter Context |
| 836 | |
| 837 | |
| 838 | Return: BCM_STATUS_SUCCESS - If Initialization of the |
| 839 | HW Interface was successful. |
| 840 | Other - If an error occured. |
| 841 | */ |
| 842 | INT InterfaceInitialize(void) |
| 843 | { |
| 844 | // BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Registering Usb driver!!"); |
| 845 | return usb_register(&usbbcm_driver); |
| 846 | } |
| 847 | |
| 848 | INT InterfaceExit(void) |
| 849 | { |
| 850 | //PMINI_ADAPTER psAdapter = NULL; |
| 851 | int status = 0; |
| 852 | |
| 853 | //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Deregistering Usb driver!!"); |
| 854 | usb_deregister(&usbbcm_driver); |
| 855 | return status; |
| 856 | } |