InterfaceInit.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. #include "headers.h"
  2. #include <linux/usb/ch9.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_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) },
  13. { }
  14. };
  15. MODULE_DEVICE_TABLE(usb, InterfaceUsbtable);
  16. static int debug = -1;
  17. module_param(debug, uint, 0600);
  18. 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;
  23. static int InterfaceAdapterInit(struct bcm_interface_adapter *Adapter);
  24. static void InterfaceAdapterFree(struct bcm_interface_adapter *psIntfAdapter)
  25. {
  26. int i = 0;
  27. struct bcm_mini_adapter *ps_ad = psIntfAdapter->psAdapter;
  28. /* Wake up the wait_queue... */
  29. if (ps_ad->LEDInfo.led_thread_running &
  30. BCM_LED_THREAD_RUNNING_ACTIVELY) {
  31. ps_ad->DriverState = DRIVER_HALT;
  32. wake_up(&ps_ad->LEDInfo.notify_led_event);
  33. }
  34. reset_card_proc(ps_ad);
  35. /*
  36. * worst case time taken by the RDM/WRM will be 5 sec. will check after
  37. * every 100 ms to accertain the device is not being accessed. After
  38. * this No RDM/WRM should be made.
  39. */
  40. while (ps_ad->DeviceAccess) {
  41. BCM_DEBUG_PRINT(ps_ad, DBG_TYPE_INITEXIT, DRV_ENTRY,
  42. DBG_LVL_ALL, "Device is being accessed.\n");
  43. msleep(100);
  44. }
  45. /* Free interrupt URB */
  46. /* ps_ad->device_removed = TRUE; */
  47. usb_free_urb(psIntfAdapter->psInterruptUrb);
  48. /* Free transmit URBs */
  49. for (i = 0; i < MAXIMUM_USB_TCB; i++) {
  50. if (psIntfAdapter->asUsbTcb[i].urb != NULL) {
  51. usb_free_urb(psIntfAdapter->asUsbTcb[i].urb);
  52. psIntfAdapter->asUsbTcb[i].urb = NULL;
  53. }
  54. }
  55. /* Free receive URB and buffers */
  56. for (i = 0; i < MAXIMUM_USB_RCB; i++) {
  57. if (psIntfAdapter->asUsbRcb[i].urb != NULL) {
  58. kfree(psIntfAdapter->asUsbRcb[i].urb->transfer_buffer);
  59. usb_free_urb(psIntfAdapter->asUsbRcb[i].urb);
  60. psIntfAdapter->asUsbRcb[i].urb = NULL;
  61. }
  62. }
  63. AdapterFree(ps_ad);
  64. }
  65. static void ConfigureEndPointTypesThroughEEPROM(
  66. struct bcm_mini_adapter *Adapter)
  67. {
  68. u32 ulReg;
  69. int bytes;
  70. struct bcm_interface_adapter *interfaceAdapter;
  71. /* Program EP2 MAX_PKT_SIZE */
  72. ulReg = ntohl(EP2_MPS_REG);
  73. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x128, 4, TRUE);
  74. ulReg = ntohl(EP2_MPS);
  75. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x12C, 4, TRUE);
  76. ulReg = ntohl(EP2_CFG_REG);
  77. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x132, 4, TRUE);
  78. interfaceAdapter =
  79. (struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter);
  80. if (interfaceAdapter->bHighSpeedDevice) {
  81. ulReg = ntohl(EP2_CFG_INT);
  82. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE);
  83. } else {
  84. /* USE BULK EP as TX in FS mode. */
  85. ulReg = ntohl(EP2_CFG_BULK);
  86. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE);
  87. }
  88. /* Program EP4 MAX_PKT_SIZE. */
  89. ulReg = ntohl(EP4_MPS_REG);
  90. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x13C, 4, TRUE);
  91. ulReg = ntohl(EP4_MPS);
  92. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x140, 4, TRUE);
  93. /* Program TX EP as interrupt(Alternate Setting) */
  94. bytes = rdmalt(Adapter, 0x0F0110F8, &ulReg, sizeof(u32));
  95. if (bytes < 0) {
  96. BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, DRV_ENTRY,
  97. DBG_LVL_ALL, "reading of Tx EP failed\n");
  98. return;
  99. }
  100. ulReg |= 0x6;
  101. ulReg = ntohl(ulReg);
  102. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1CC, 4, TRUE);
  103. ulReg = ntohl(EP4_CFG_REG);
  104. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C8, 4, TRUE);
  105. /* Program ISOCHRONOUS EP size to zero. */
  106. ulReg = ntohl(ISO_MPS_REG);
  107. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1D2, 4, TRUE);
  108. ulReg = ntohl(ISO_MPS);
  109. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1D6, 4, TRUE);
  110. /*
  111. * Update EEPROM Version.
  112. * Read 4 bytes from 508 and modify 511 and 510.
  113. */
  114. ReadBeceemEEPROM(Adapter, 0x1FC, &ulReg);
  115. ulReg &= 0x0101FFFF;
  116. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1FC, 4, TRUE);
  117. /*
  118. * Update length field if required.
  119. * Also make the string NULL terminated.
  120. */
  121. ReadBeceemEEPROM(Adapter, 0xA8, &ulReg);
  122. if ((ulReg&0x00FF0000)>>16 > 0x30) {
  123. ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
  124. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0xA8, 4, TRUE);
  125. }
  126. ReadBeceemEEPROM(Adapter, 0x148, &ulReg);
  127. if ((ulReg&0x00FF0000)>>16 > 0x30) {
  128. ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
  129. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x148, 4, TRUE);
  130. }
  131. ulReg = 0;
  132. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x122, 4, TRUE);
  133. ulReg = 0;
  134. BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C2, 4, TRUE);
  135. }
  136. static int usbbcm_device_probe(struct usb_interface *intf,
  137. const struct usb_device_id *id)
  138. {
  139. struct usb_device *udev = interface_to_usbdev(intf);
  140. int retval;
  141. struct bcm_mini_adapter *psAdapter;
  142. struct bcm_interface_adapter *psIntfAdapter;
  143. struct net_device *ndev;
  144. /* Reserve one extra queue for the bit-bucket */
  145. ndev = alloc_etherdev_mq(sizeof(struct bcm_mini_adapter),
  146. NO_OF_QUEUES + 1);
  147. if (ndev == NULL) {
  148. dev_err(&udev->dev, DRV_NAME ": no memory for device\n");
  149. return -ENOMEM;
  150. }
  151. SET_NETDEV_DEV(ndev, &intf->dev);
  152. psAdapter = netdev_priv(ndev);
  153. psAdapter->dev = ndev;
  154. psAdapter->msg_enable = netif_msg_init(debug, default_msg);
  155. /* Init default driver debug state */
  156. psAdapter->stDebugState.debug_level = DBG_LVL_CURR;
  157. psAdapter->stDebugState.type = DBG_TYPE_INITEXIT;
  158. /*
  159. * Technically, one can start using BCM_DEBUG_PRINT after this point.
  160. * However, realize that by default the Type/Subtype bitmaps are all
  161. * zero now; so no prints will actually appear until the TestApp turns
  162. * on debug paths via the ioctl(); so practically speaking, in early
  163. * init, no logging happens.
  164. *
  165. * A solution (used below): we explicitly set the bitmaps to 1 for
  166. * Type=DBG_TYPE_INITEXIT and ALL subtype's of the same. Now all bcm
  167. * debug statements get logged, enabling debug during early init.
  168. * Further, we turn this OFF once init_module() completes.
  169. */
  170. psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0xff;
  171. BCM_SHOW_DEBUG_BITMAP(psAdapter);
  172. retval = InitAdapter(psAdapter);
  173. if (retval) {
  174. dev_err(&udev->dev, DRV_NAME ": InitAdapter Failed\n");
  175. AdapterFree(psAdapter);
  176. return retval;
  177. }
  178. /* Allocate interface adapter structure */
  179. psIntfAdapter = kzalloc(sizeof(struct bcm_interface_adapter),
  180. GFP_KERNEL);
  181. if (psIntfAdapter == NULL) {
  182. AdapterFree(psAdapter);
  183. return -ENOMEM;
  184. }
  185. psAdapter->pvInterfaceAdapter = psIntfAdapter;
  186. psIntfAdapter->psAdapter = psAdapter;
  187. /* Store usb interface in Interface Adapter */
  188. psIntfAdapter->interface = intf;
  189. usb_set_intfdata(intf, psIntfAdapter);
  190. BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
  191. "psIntfAdapter 0x%p\n", psIntfAdapter);
  192. retval = InterfaceAdapterInit(psIntfAdapter);
  193. if (retval) {
  194. /* If the Firmware/Cfg File is not present
  195. * then return success, let the application
  196. * download the files.
  197. */
  198. if (-ENOENT == retval) {
  199. BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY,
  200. DBG_LVL_ALL,
  201. "File Not Found. Use app to download.\n");
  202. return STATUS_SUCCESS;
  203. }
  204. BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY,
  205. DBG_LVL_ALL, "InterfaceAdapterInit failed.\n");
  206. usb_set_intfdata(intf, NULL);
  207. udev = interface_to_usbdev(intf);
  208. usb_put_dev(udev);
  209. InterfaceAdapterFree(psIntfAdapter);
  210. return retval;
  211. }
  212. if (psAdapter->chip_id > T3) {
  213. uint32_t uiNackZeroLengthInt = 4;
  214. retval =
  215. wrmalt(psAdapter, DISABLE_USB_ZERO_LEN_INT,
  216. &uiNackZeroLengthInt,
  217. sizeof(uiNackZeroLengthInt));
  218. if (retval)
  219. return retval;
  220. }
  221. /* Check whether the USB-Device Supports remote Wake-Up */
  222. if (USB_CONFIG_ATT_WAKEUP & udev->actconfig->desc.bmAttributes) {
  223. /* If Suspend then only support dynamic suspend */
  224. if (psAdapter->bDoSuspend) {
  225. #ifdef CONFIG_PM
  226. pm_runtime_set_autosuspend_delay(&udev->dev, 0);
  227. intf->needs_remote_wakeup = 1;
  228. usb_enable_autosuspend(udev);
  229. device_init_wakeup(&intf->dev, 1);
  230. INIT_WORK(&psIntfAdapter->usbSuspendWork,
  231. putUsbSuspend);
  232. BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY,
  233. DBG_LVL_ALL,
  234. "Enabling USB Auto-Suspend\n");
  235. #endif
  236. } else {
  237. intf->needs_remote_wakeup = 0;
  238. usb_disable_autosuspend(udev);
  239. }
  240. }
  241. psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0x0;
  242. return retval;
  243. }
  244. static void usbbcm_disconnect(struct usb_interface *intf)
  245. {
  246. struct bcm_interface_adapter *psIntfAdapter = usb_get_intfdata(intf);
  247. struct bcm_mini_adapter *psAdapter;
  248. struct usb_device *udev = interface_to_usbdev(intf);
  249. if (psIntfAdapter == NULL)
  250. return;
  251. psAdapter = psIntfAdapter->psAdapter;
  252. netif_device_detach(psAdapter->dev);
  253. if (psAdapter->bDoSuspend)
  254. intf->needs_remote_wakeup = 0;
  255. psAdapter->device_removed = TRUE;
  256. usb_set_intfdata(intf, NULL);
  257. InterfaceAdapterFree(psIntfAdapter);
  258. usb_put_dev(udev);
  259. }
  260. static int AllocUsbCb(struct bcm_interface_adapter *psIntfAdapter)
  261. {
  262. int i = 0;
  263. for (i = 0; i < MAXIMUM_USB_TCB; i++) {
  264. psIntfAdapter->asUsbTcb[i].urb = usb_alloc_urb(0, GFP_KERNEL);
  265. if (psIntfAdapter->asUsbTcb[i].urb == NULL) {
  266. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,
  267. DBG_TYPE_PRINTK, 0, 0,
  268. "Can't allocate Tx urb for index %d\n",
  269. i);
  270. return -ENOMEM;
  271. }
  272. }
  273. for (i = 0; i < MAXIMUM_USB_RCB; i++) {
  274. psIntfAdapter->asUsbRcb[i].urb = usb_alloc_urb(0, GFP_KERNEL);
  275. if (psIntfAdapter->asUsbRcb[i].urb == NULL) {
  276. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,
  277. DBG_TYPE_PRINTK, 0, 0,
  278. "Can't allocate Rx urb for index %d\n",
  279. i);
  280. return -ENOMEM;
  281. }
  282. psIntfAdapter->asUsbRcb[i].urb->transfer_buffer =
  283. kmalloc(MAX_DATA_BUFFER_SIZE, GFP_KERNEL);
  284. if (psIntfAdapter->asUsbRcb[i].urb->transfer_buffer == NULL) {
  285. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,
  286. DBG_TYPE_PRINTK, 0, 0,
  287. "Can't allocate Rx buffer for index %d\n",
  288. i);
  289. return -ENOMEM;
  290. }
  291. psIntfAdapter->asUsbRcb[i].urb->transfer_buffer_length =
  292. MAX_DATA_BUFFER_SIZE;
  293. }
  294. return 0;
  295. }
  296. static int device_run(struct bcm_interface_adapter *psIntfAdapter)
  297. {
  298. int value = 0;
  299. UINT status = STATUS_SUCCESS;
  300. struct bcm_mini_adapter *psAd = psIntfAdapter->psAdapter;
  301. status = InitCardAndDownloadFirmware(psAd);
  302. if (status != STATUS_SUCCESS) {
  303. pr_err(DRV_NAME "InitCardAndDownloadFirmware failed.\n");
  304. return status;
  305. }
  306. if (psAd->fw_download_done) {
  307. if (StartInterruptUrb(psIntfAdapter)) {
  308. BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY,
  309. DBG_LVL_ALL,
  310. "Cannot send interrupt in URB\n");
  311. }
  312. /*
  313. * now register the cntrl interface. after downloading the f/w
  314. * waiting for 5 sec to get the mailbox interrupt.
  315. */
  316. psAd->waiting_to_fw_download_done = false;
  317. value = wait_event_timeout(psAd->ioctl_fw_dnld_wait_queue,
  318. psAd->waiting_to_fw_download_done,
  319. 5 * HZ);
  320. if (value == 0)
  321. pr_err(DRV_NAME ": Timeout waiting for mailbox interrupt.\n");
  322. if (register_control_device_interface(psAd) < 0) {
  323. pr_err(DRV_NAME ": Register Control Device failed.\n");
  324. return -EIO;
  325. }
  326. }
  327. return 0;
  328. }
  329. static int select_alternate_setting_for_highspeed_modem(
  330. struct bcm_interface_adapter *psIntfAdapter,
  331. struct usb_endpoint_descriptor **endpoint,
  332. const struct usb_host_interface *iface_desc,
  333. int *usedIntOutForBulkTransfer)
  334. {
  335. int retval = 0;
  336. struct bcm_mini_adapter *psAd = psIntfAdapter->psAdapter;
  337. /* selecting alternate setting one as a default setting
  338. * for High Speed modem. */
  339. if (psIntfAdapter->bHighSpeedDevice)
  340. retval = usb_set_interface(psIntfAdapter->udev,
  341. DEFAULT_SETTING_0,
  342. ALTERNATE_SETTING_1);
  343. BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
  344. "BCM16 is applicable on this dongle\n");
  345. if (retval || !psIntfAdapter->bHighSpeedDevice) {
  346. *usedIntOutForBulkTransfer = EP2;
  347. *endpoint = &iface_desc->endpoint[EP2].desc;
  348. BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
  349. "Interface altsetting failed or modem is configured to Full Speed, hence will work on default setting 0\n");
  350. /*
  351. * If Modem is high speed device EP2 should be
  352. * INT OUT End point
  353. *
  354. * If Mode is FS then EP2 should be bulk end
  355. * point
  356. */
  357. if ((psIntfAdapter->bHighSpeedDevice &&
  358. !usb_endpoint_is_int_out(*endpoint)) ||
  359. (!psIntfAdapter->bHighSpeedDevice &&
  360. !usb_endpoint_is_bulk_out(*endpoint))) {
  361. BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY,
  362. DBG_LVL_ALL,
  363. "Configuring the EEPROM\n");
  364. /* change the EP2, EP4 to INT OUT end point */
  365. ConfigureEndPointTypesThroughEEPROM(
  366. psAd);
  367. /*
  368. * It resets the device and if any thing
  369. * gets changed in USB descriptor it
  370. * will show fail and re-enumerate the
  371. * device
  372. */
  373. retval = usb_reset_device(psIntfAdapter->udev);
  374. if (retval) {
  375. BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT,
  376. DRV_ENTRY, DBG_LVL_ALL,
  377. "reset failed. Re-enumerating the device.\n");
  378. return retval;
  379. }
  380. }
  381. if (!psIntfAdapter->bHighSpeedDevice &&
  382. usb_endpoint_is_bulk_out(*endpoint)) {
  383. /*
  384. * Once BULK is selected in FS mode.
  385. * Revert it back to INT.
  386. * Else USB_IF will fail.
  387. */
  388. UINT _uiData = ntohl(EP2_CFG_INT);
  389. BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY,
  390. DBG_LVL_ALL,
  391. "Reverting Bulk to INT as it is in Full Speed mode.\n");
  392. BeceemEEPROMBulkWrite(psAd, (PUCHAR) & _uiData, 0x136,
  393. 4, TRUE);
  394. }
  395. } else {
  396. *usedIntOutForBulkTransfer = EP4;
  397. *endpoint = &iface_desc->endpoint[EP4].desc;
  398. BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
  399. "Choosing AltSetting as a default setting.\n");
  400. if (!usb_endpoint_is_int_out(*endpoint)) {
  401. BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY,
  402. DBG_LVL_ALL,
  403. "Dongle does not have BCM16 Fix.\n");
  404. /*
  405. * change the EP2, EP4 to INT OUT end point and use EP4
  406. * in altsetting
  407. */
  408. ConfigureEndPointTypesThroughEEPROM(psAd);
  409. /*
  410. * It resets the device and if any thing
  411. * gets changed in USB descriptor it
  412. * will show fail and re-enumerate the
  413. * device
  414. */
  415. retval = usb_reset_device(psIntfAdapter->udev);
  416. if (retval) {
  417. BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT,
  418. DRV_ENTRY, DBG_LVL_ALL,
  419. "reset failed. Re-enumerating the device.\n");
  420. return retval;
  421. }
  422. }
  423. }
  424. return 0;
  425. }
  426. static int InterfaceAdapterInit(struct bcm_interface_adapter *psIntfAdapter)
  427. {
  428. struct usb_host_interface *iface_desc;
  429. struct usb_endpoint_descriptor *endpoint;
  430. size_t buffer_size;
  431. unsigned long value;
  432. int retval = 0;
  433. int usedIntOutForBulkTransfer = 0;
  434. bool bBcm16 = false;
  435. UINT uiData = 0;
  436. int bytes;
  437. struct bcm_mini_adapter *psAd = psIntfAdapter->psAdapter;
  438. /* Store the usb dev into interface adapter */
  439. psIntfAdapter->udev =
  440. usb_get_dev(interface_to_usbdev(psIntfAdapter->interface));
  441. psIntfAdapter->bHighSpeedDevice =
  442. (psIntfAdapter->udev->speed == USB_SPEED_HIGH);
  443. psAd->interface_rdm = BcmRDM;
  444. psAd->interface_wrm = BcmWRM;
  445. bytes = rdmalt(psAd, CHIP_ID_REG, (u32 *) &(psAd->chip_id),
  446. sizeof(u32));
  447. if (bytes < 0) {
  448. retval = bytes;
  449. BCM_DEBUG_PRINT(psAd, DBG_TYPE_PRINTK, 0, 0,
  450. "CHIP ID Read Failed\n");
  451. return retval;
  452. }
  453. if (0xbece3200 == (psAd->chip_id & ~(0xF0)))
  454. psAd->chip_id &= ~0xF0;
  455. dev_info(&psIntfAdapter->udev->dev, "RDM Chip ID 0x%lx\n",
  456. psAd->chip_id);
  457. iface_desc = psIntfAdapter->interface->cur_altsetting;
  458. if (psAd->chip_id == T3B) {
  459. /* T3B device will have EEPROM, check if EEPROM is proper and
  460. * BCM16 can be done or not. */
  461. BeceemEEPROMBulkRead(psAd, &uiData, 0x0, 4);
  462. if (uiData == BECM)
  463. bBcm16 = TRUE;
  464. dev_info(&psIntfAdapter->udev->dev,
  465. "number of alternate setting %d\n",
  466. psIntfAdapter->interface->num_altsetting);
  467. if (bBcm16 == TRUE) {
  468. retval = select_alternate_setting_for_highspeed_modem(
  469. psIntfAdapter, &endpoint, iface_desc,
  470. &usedIntOutForBulkTransfer);
  471. if (retval)
  472. return retval;
  473. }
  474. }
  475. iface_desc = psIntfAdapter->interface->cur_altsetting;
  476. for (value = 0; value < iface_desc->desc.bNumEndpoints; ++value) {
  477. endpoint = &iface_desc->endpoint[value].desc;
  478. if (!psIntfAdapter->sBulkIn.bulk_in_endpointAddr &&
  479. usb_endpoint_is_bulk_in(endpoint)) {
  480. buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
  481. psIntfAdapter->sBulkIn.bulk_in_size = buffer_size;
  482. psIntfAdapter->sBulkIn.bulk_in_endpointAddr =
  483. endpoint->bEndpointAddress;
  484. psIntfAdapter->sBulkIn.bulk_in_pipe = usb_rcvbulkpipe(
  485. psIntfAdapter->udev,
  486. psIntfAdapter->sBulkIn.bulk_in_endpointAddr);
  487. }
  488. if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr &&
  489. usb_endpoint_is_bulk_out(endpoint)) {
  490. psIntfAdapter->sBulkOut.bulk_out_endpointAddr =
  491. endpoint->bEndpointAddress;
  492. psIntfAdapter->sBulkOut.bulk_out_pipe = usb_sndbulkpipe(
  493. psIntfAdapter->udev,
  494. psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
  495. }
  496. if (!psIntfAdapter->sIntrIn.int_in_endpointAddr &&
  497. usb_endpoint_is_int_in(endpoint)) {
  498. buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
  499. psIntfAdapter->sIntrIn.int_in_size = buffer_size;
  500. psIntfAdapter->sIntrIn.int_in_endpointAddr =
  501. endpoint->bEndpointAddress;
  502. psIntfAdapter->sIntrIn.int_in_interval =
  503. endpoint->bInterval;
  504. psIntfAdapter->sIntrIn.int_in_buffer =
  505. kmalloc(buffer_size, GFP_KERNEL);
  506. if (!psIntfAdapter->sIntrIn.int_in_buffer)
  507. return -EINVAL;
  508. }
  509. if (!psIntfAdapter->sIntrOut.int_out_endpointAddr &&
  510. usb_endpoint_is_int_out(endpoint)) {
  511. if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr &&
  512. (psAd->chip_id == T3B) &&
  513. (value == usedIntOutForBulkTransfer)) {
  514. /*
  515. * use first intout end point as a bulk out end
  516. * point
  517. */
  518. buffer_size =
  519. le16_to_cpu(endpoint->wMaxPacketSize);
  520. psIntfAdapter->sBulkOut.bulk_out_size =
  521. buffer_size;
  522. psIntfAdapter->sBulkOut.bulk_out_endpointAddr =
  523. endpoint->bEndpointAddress;
  524. psIntfAdapter->sBulkOut.bulk_out_pipe =
  525. usb_sndintpipe(psIntfAdapter->udev,
  526. psIntfAdapter->sBulkOut
  527. .bulk_out_endpointAddr);
  528. psIntfAdapter->sBulkOut.int_out_interval =
  529. endpoint->bInterval;
  530. } else if (value == EP6) {
  531. buffer_size =
  532. le16_to_cpu(endpoint->wMaxPacketSize);
  533. psIntfAdapter->sIntrOut.int_out_size =
  534. buffer_size;
  535. psIntfAdapter->sIntrOut.int_out_endpointAddr =
  536. endpoint->bEndpointAddress;
  537. psIntfAdapter->sIntrOut.int_out_interval =
  538. endpoint->bInterval;
  539. psIntfAdapter->sIntrOut.int_out_buffer =
  540. kmalloc(buffer_size, GFP_KERNEL);
  541. if (!psIntfAdapter->sIntrOut.int_out_buffer)
  542. return -EINVAL;
  543. }
  544. }
  545. }
  546. usb_set_intfdata(psIntfAdapter->interface, psIntfAdapter);
  547. psAd->bcm_file_download = InterfaceFileDownload;
  548. psAd->bcm_file_readback_from_chip = InterfaceFileReadbackFromChip;
  549. psAd->interface_transmit = InterfaceTransmitPacket;
  550. retval = CreateInterruptUrb(psIntfAdapter);
  551. if (retval) {
  552. BCM_DEBUG_PRINT(psAd, DBG_TYPE_PRINTK, 0, 0,
  553. "Cannot create interrupt urb\n");
  554. return retval;
  555. }
  556. retval = AllocUsbCb(psIntfAdapter);
  557. if (retval)
  558. return retval;
  559. return device_run(psIntfAdapter);
  560. }
  561. static int InterfaceSuspend(struct usb_interface *intf, pm_message_t message)
  562. {
  563. struct bcm_interface_adapter *psIntfAdapter = usb_get_intfdata(intf);
  564. psIntfAdapter->bSuspended = TRUE;
  565. if (psIntfAdapter->bPreparingForBusSuspend) {
  566. psIntfAdapter->bPreparingForBusSuspend = false;
  567. if (psIntfAdapter->psAdapter->LinkStatus == LINKUP_DONE) {
  568. psIntfAdapter->psAdapter->IdleMode = TRUE;
  569. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,
  570. DBG_TYPE_INITEXIT, DRV_ENTRY,
  571. DBG_LVL_ALL,
  572. "Host Entered in PMU Idle Mode.\n");
  573. } else {
  574. psIntfAdapter->psAdapter->bShutStatus = TRUE;
  575. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,
  576. DBG_TYPE_INITEXIT, DRV_ENTRY,
  577. DBG_LVL_ALL,
  578. "Host Entered in PMU Shutdown Mode.\n");
  579. }
  580. }
  581. psIntfAdapter->psAdapter->bPreparingForLowPowerMode = false;
  582. /* Signaling the control pkt path */
  583. wake_up(&psIntfAdapter->psAdapter->lowpower_mode_wait_queue);
  584. return 0;
  585. }
  586. static int InterfaceResume(struct usb_interface *intf)
  587. {
  588. struct bcm_interface_adapter *psIntfAdapter = usb_get_intfdata(intf);
  589. mdelay(100);
  590. psIntfAdapter->bSuspended = false;
  591. StartInterruptUrb(psIntfAdapter);
  592. InterfaceRx(psIntfAdapter);
  593. return 0;
  594. }
  595. static struct usb_driver usbbcm_driver = {
  596. .name = "usbbcm",
  597. .probe = usbbcm_device_probe,
  598. .disconnect = usbbcm_disconnect,
  599. .suspend = InterfaceSuspend,
  600. .resume = InterfaceResume,
  601. .id_table = InterfaceUsbtable,
  602. .supports_autosuspend = 1,
  603. };
  604. struct class *bcm_class;
  605. static __init int bcm_init(void)
  606. {
  607. int retval;
  608. pr_info("%s: %s, %s\n", DRV_NAME, DRV_DESCRIPTION, DRV_VERSION);
  609. pr_info("%s\n", DRV_COPYRIGHT);
  610. bcm_class = class_create(THIS_MODULE, DRV_NAME);
  611. if (IS_ERR(bcm_class)) {
  612. pr_err(DRV_NAME ": could not create class\n");
  613. return PTR_ERR(bcm_class);
  614. }
  615. retval = usb_register(&usbbcm_driver);
  616. if (retval < 0) {
  617. pr_err(DRV_NAME ": could not register usb driver\n");
  618. class_destroy(bcm_class);
  619. return retval;
  620. }
  621. return 0;
  622. }
  623. static __exit void bcm_exit(void)
  624. {
  625. usb_deregister(&usbbcm_driver);
  626. class_destroy(bcm_class);
  627. }
  628. module_init(bcm_init);
  629. module_exit(bcm_exit);
  630. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  631. MODULE_VERSION(DRV_VERSION);
  632. MODULE_LICENSE("GPL");