1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
22 #include <drv_types.h>
25 #include <platform_ops.h>
27 #ifndef CONFIG_USB_HCI
28 #error "CONFIG_USB_HCI shall be on!\n"
31 #if defined (PLATFORM_LINUX) && defined (PLATFORM_WINDOWS)
32 #error "Shall be Linux or Windows, but not both!\n"
35 #ifdef CONFIG_80211N_HT
36 extern int rtw_ht_enable;
37 extern int rtw_bw_mode;
38 extern int rtw_ampdu_enable;//for enable tx_ampdu
41 #ifdef CONFIG_GLOBAL_UI_PID
42 int ui_pid[3] = {0, 0, 0};
46 extern int pm_netdev_open(struct net_device *pnetdev,u8 bnormal);
47 static int rtw_suspend(struct usb_interface *intf, pm_message_t message);
48 static int rtw_resume(struct usb_interface *intf);
51 static int rtw_drv_init(struct usb_interface *pusb_intf,const struct usb_device_id *pdid);
52 static void rtw_dev_remove(struct usb_interface *pusb_intf);
54 static void rtw_dev_shutdown(struct device *dev)
56 struct usb_interface *usb_intf = container_of(dev, struct usb_interface, dev);
57 struct dvobj_priv *dvobj = NULL;
58 _adapter *adapter = NULL;
61 DBG_871X("%s\n", __func__);
65 dvobj = usb_get_intfdata(usb_intf);
68 rtw_set_surprise_removed(dvobj->padapters[IFACE_ID0]);
69 ATOMIC_SET(&dvobj->continual_io_error, MAX_CONTINUAL_IO_ERR+1);
74 #if (LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,23))
75 /* Some useful macros to use to create struct usb_device_id */
76 #define USB_DEVICE_ID_MATCH_VENDOR 0x0001
77 #define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
78 #define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
79 #define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
80 #define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
81 #define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
82 #define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
83 #define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
84 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
85 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
86 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
89 #define USB_DEVICE_ID_MATCH_INT_INFO \
90 (USB_DEVICE_ID_MATCH_INT_CLASS | \
91 USB_DEVICE_ID_MATCH_INT_SUBCLASS | \
92 USB_DEVICE_ID_MATCH_INT_PROTOCOL)
95 #define USB_DEVICE_AND_INTERFACE_INFO(vend, prod, cl, sc, pr) \
96 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
97 | USB_DEVICE_ID_MATCH_DEVICE, \
99 .idProduct = (prod), \
100 .bInterfaceClass = (cl), \
101 .bInterfaceSubClass = (sc), \
102 .bInterfaceProtocol = (pr)
105 * USB_VENDOR_AND_INTERFACE_INFO - describe a specific usb vendor with a class of usb interfaces
106 * @vend: the 16 bit USB Vendor ID
107 * @cl: bInterfaceClass value
108 * @sc: bInterfaceSubClass value
109 * @pr: bInterfaceProtocol value
111 * This macro is used to create a struct usb_device_id that matches a
112 * specific vendor with a specific class of interfaces.
114 * This is especially useful when explicitly matching devices that have
115 * vendor specific bDeviceClass values, but standards-compliant interfaces.
117 #define USB_VENDOR_AND_INTERFACE_INFO(vend, cl, sc, pr) \
118 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
119 | USB_DEVICE_ID_MATCH_VENDOR, \
120 .idVendor = (vend), \
121 .bInterfaceClass = (cl), \
122 .bInterfaceSubClass = (sc), \
123 .bInterfaceProtocol = (pr)
125 /* ----------------------------------------------------------------------- */
129 #define USB_VENDER_ID_REALTEK 0x0BDA
132 /* DID_USB_v916_20130116 */
133 static struct usb_device_id rtw_usb_id_tbl[] ={
134 #ifdef CONFIG_RTL8188E
135 /*=== Realtek demoboard ===*/
136 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8179),.driver_info = RTL8188E}, /* 8188EUS */
137 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0179),.driver_info = RTL8188E}, /* 8188ETV */
138 /*=== Customer ID ===*/
139 /****** 8188EUS ********/
140 {USB_DEVICE(0x07B8, 0x8179),.driver_info = RTL8188E}, /* Abocom - Abocom */
143 #ifdef CONFIG_RTL8812A
144 /*=== Realtek demoboard ===*/
145 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8812),.driver_info = RTL8812},/* Default ID */
146 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881A),.driver_info = RTL8812},/* Default ID */
147 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881B),.driver_info = RTL8812},/* Default ID */
148 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881C),.driver_info = RTL8812},/* Default ID */
149 /*=== Customer ID ===*/
150 {USB_DEVICE(0x050D, 0x1106),.driver_info = RTL8812}, /* Belkin - sercomm */
151 {USB_DEVICE(0x2001, 0x330E),.driver_info = RTL8812}, /* D-Link - ALPHA */
152 {USB_DEVICE(0x7392, 0xA822),.driver_info = RTL8812}, /* Edimax - Edimax */
153 {USB_DEVICE(0x0DF6, 0x0074),.driver_info = RTL8812}, /* Sitecom - Edimax */
154 {USB_DEVICE(0x04BB, 0x0952),.driver_info = RTL8812}, /* I-O DATA - Edimax */
155 {USB_DEVICE(0x0789, 0x016E),.driver_info = RTL8812}, /* Logitec - Edimax */
156 {USB_DEVICE(0x0409, 0x0408),.driver_info = RTL8812}, /* NEC - */
157 {USB_DEVICE(0x0B05, 0x17D2),.driver_info = RTL8812}, /* ASUS - Edimax */
158 {USB_DEVICE(0x0E66, 0x0022),.driver_info = RTL8812}, /* HAWKING - Edimax */
159 {USB_DEVICE(0x0586, 0x3426),.driver_info = RTL8812}, /* ZyXEL - */
160 {USB_DEVICE(0x2001, 0x3313),.driver_info = RTL8812}, /* D-Link - ALPHA */
161 {USB_DEVICE(0x1058, 0x0632),.driver_info = RTL8812}, /* WD - Cybertan*/
162 {USB_DEVICE(0x1740, 0x0100),.driver_info = RTL8812}, /* EnGenius - EnGenius */
163 {USB_DEVICE(0x2019, 0xAB30),.driver_info = RTL8812}, /* Planex - Abocom */
164 {USB_DEVICE(0x07B8, 0x8812),.driver_info = RTL8812}, /* Abocom - Abocom */
165 {USB_DEVICE(0x2001, 0x3315),.driver_info = RTL8812}, /* D-Link - Cameo */
166 {USB_DEVICE(0x2001, 0x3316),.driver_info = RTL8812}, /* D-Link - Cameo */
169 #ifdef CONFIG_RTL8821A
170 /*=== Realtek demoboard ===*/
171 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0811),.driver_info = RTL8821},/* Default ID */
172 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0821),.driver_info = RTL8821},/* Default ID */
173 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8822),.driver_info = RTL8821},/* Default ID */
174 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0xA811) , .driver_info = RTL8821},/* Default ID */
175 {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x0820,0xff,0xff,0xff),.driver_info = RTL8821}, /* 8821AU */
176 {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x0823,0xff,0xff,0xff),.driver_info = RTL8821}, /* 8821AU */
177 /*=== Customer ID ===*/
178 {USB_DEVICE(0x7392, 0xA811),.driver_info = RTL8821}, /* Edimax - Edimax */
179 {USB_DEVICE(0x04BB, 0x0953),.driver_info = RTL8821}, /* I-O DATA - Edimax */
180 {USB_DEVICE(0x2001, 0x3314),.driver_info = RTL8821}, /* D-Link - Cameo */
181 {USB_DEVICE(0x2001, 0x3318),.driver_info = RTL8821}, /* D-Link - Cameo */
182 {USB_DEVICE(0x0E66, 0x0023),.driver_info = RTL8821}, /* HAWKING - Edimax */
183 {USB_DEVICE(0x056E, 0x400E) , .driver_info = RTL8821}, /* ELECOM - ELECOM */
184 {USB_DEVICE(0x056E, 0x400F) , .driver_info = RTL8821}, /* ELECOM - ELECOM */
187 #ifdef CONFIG_RTL8192E
188 /*=== Realtek demoboard ===*/
189 {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x818B,0xff,0xff,0xff),.driver_info = RTL8192E},/* Default ID */
190 {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x818C,0xff,0xff,0xff),.driver_info = RTL8192E},/* Default ID */
193 #ifdef CONFIG_RTL8723B
194 //*=== Realtek demoboard ===*/
195 {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB720,0xff,0xff,0xff),.driver_info = RTL8723B}, /* 8723BU 1*1 */
196 //{USB_DEVICE(USB_VENDER_ID_REALTEK, 0xB720),.driver_info = RTL8723B}, /* 8723BU */
199 #ifdef CONFIG_RTL8703B
200 /*=== Realtek demoboard ===*/
201 {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB703, 0xff, 0xff, 0xff), .driver_info = RTL8703B}, /* 8723CU 1*1 */
202 /* {USB_DEVICE(USB_VENDER_ID_REALTEK, 0xB703), .driver_info = RTL723C}, */ /* 8723CU 1*1 */
203 #endif /* CONFIG_RTL8703B */
205 #ifdef CONFIG_RTL8814A
207 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8813),.driver_info = RTL8814A},
208 {USB_DEVICE(0x2001, 0x331a), .driver_info = RTL8814A}, /* D-Link - D-Link */
209 {USB_DEVICE(0x0b05, 0x1817), .driver_info = RTL8814A}, /* ASUS - ASUSTeK */
210 {USB_DEVICE(0x056E, 0x400B), .driver_info = RTL8814A}, /* ELECOM - ELECOM */
211 {USB_DEVICE(0x056E, 0x400D), .driver_info = RTL8814A}, /* ELECOM - ELECOM */
212 {USB_DEVICE(0x7392, 0xA834), .driver_info = RTL8814A}, /* Edimax - Edimax */
213 #endif /* CONFIG_RTL8814A */
215 #ifdef CONFIG_RTL8188F
216 /*=== Realtek demoboard ===*/
217 {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xF179, 0xff, 0xff, 0xff), .driver_info = RTL8188F}, /* 8188FU 1*1 */
220 {} /* Terminating entry */
223 MODULE_DEVICE_TABLE(usb, rtw_usb_id_tbl);
225 int const rtw_usb_id_len = sizeof(rtw_usb_id_tbl) / sizeof(struct usb_device_id);
227 static struct specific_device_id specific_device_id_tbl[] = {
228 {.idVendor=USB_VENDER_ID_REALTEK, .idProduct=0x8177, .flags=SPEC_DEV_ID_DISABLE_HT},//8188cu 1*1 dongole, (b/g mode only)
229 {.idVendor=USB_VENDER_ID_REALTEK, .idProduct=0x817E, .flags=SPEC_DEV_ID_DISABLE_HT},//8188CE-VAU USB minCard (b/g mode only)
230 {.idVendor=0x0b05, .idProduct=0x1791, .flags=SPEC_DEV_ID_DISABLE_HT},
231 {.idVendor=0x13D3, .idProduct=0x3311, .flags=SPEC_DEV_ID_DISABLE_HT},
232 {.idVendor=0x13D3, .idProduct=0x3359, .flags=SPEC_DEV_ID_DISABLE_HT},//Russian customer -Azwave (8188CE-VAU g mode)
233 #ifdef RTK_DMP_PLATFORM
234 {.idVendor=USB_VENDER_ID_REALTEK, .idProduct=0x8111, .flags=SPEC_DEV_ID_ASSIGN_IFNAME}, // Realtek 5G dongle for WiFi Display
235 {.idVendor=0x2019, .idProduct=0xAB2D, .flags=SPEC_DEV_ID_ASSIGN_IFNAME}, // PCI-Abocom 5G dongle for WiFi Display
236 #endif /* RTK_DMP_PLATFORM */
241 struct usb_driver usbdrv;
246 struct rtw_usb_drv usb_drv = {
247 .usbdrv.name =(char*)DRV_NAME,
248 .usbdrv.probe = rtw_drv_init,
249 .usbdrv.disconnect = rtw_dev_remove,
250 .usbdrv.id_table = rtw_usb_id_tbl,
251 .usbdrv.suspend = rtw_suspend,
252 .usbdrv.resume = rtw_resume,
253 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
254 .usbdrv.reset_resume = rtw_resume,
256 #ifdef CONFIG_AUTOSUSPEND
257 .usbdrv.supports_autosuspend = 1,
260 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19))
261 .usbdrv.drvwrap.driver.shutdown = rtw_dev_shutdown,
263 .usbdrv.driver.shutdown = rtw_dev_shutdown,
267 static inline int RT_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
269 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
272 static inline int RT_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)
274 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
277 static inline int RT_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
279 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT);
282 static inline int RT_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
284 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK);
287 static inline int RT_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
289 return (RT_usb_endpoint_xfer_bulk(epd) && RT_usb_endpoint_dir_in(epd));
292 static inline int RT_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
294 return (RT_usb_endpoint_xfer_bulk(epd) && RT_usb_endpoint_dir_out(epd));
297 static inline int RT_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
299 return (RT_usb_endpoint_xfer_int(epd) && RT_usb_endpoint_dir_in(epd));
302 static inline int RT_usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
304 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
307 static u8 rtw_init_intf_priv(struct dvobj_priv *dvobj)
311 #ifdef CONFIG_USB_VENDOR_REQ_MUTEX
312 _rtw_mutex_init(&dvobj->usb_vendor_req_mutex);
316 #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
317 dvobj->usb_alloc_vendor_req_buf = rtw_zmalloc(MAX_USB_IO_CTL_SIZE);
318 if (dvobj->usb_alloc_vendor_req_buf == NULL) {
319 DBG_871X("alloc usb_vendor_req_buf failed... /n");
323 dvobj->usb_vendor_req_buf =
324 (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(dvobj->usb_alloc_vendor_req_buf ), ALIGNMENT_UNIT);
332 static u8 rtw_deinit_intf_priv(struct dvobj_priv *dvobj)
336 #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
337 if(dvobj->usb_vendor_req_buf)
338 rtw_mfree(dvobj->usb_alloc_vendor_req_buf, MAX_USB_IO_CTL_SIZE);
341 #ifdef CONFIG_USB_VENDOR_REQ_MUTEX
342 _rtw_mutex_free(&dvobj->usb_vendor_req_mutex);
347 static void rtw_decide_chip_type_by_usb_info(struct dvobj_priv *pdvobjpriv, const struct usb_device_id *pdid)
349 pdvobjpriv->chip_type = pdid->driver_info;
351 #ifdef CONFIG_RTL8188E
352 if (pdvobjpriv->chip_type == RTL8188E)
353 rtl8188eu_set_hw_type(pdvobjpriv);
356 #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
357 if (pdvobjpriv->chip_type == RTL8812 || pdvobjpriv->chip_type == RTL8821)
358 rtl8812au_set_hw_type(pdvobjpriv);
361 #ifdef CONFIG_RTL8192E
362 if (pdvobjpriv->chip_type == RTL8192E)
363 rtl8192eu_set_hw_type(pdvobjpriv);
366 #ifdef CONFIG_RTL8723B
367 if (pdvobjpriv->chip_type == RTL8723B)
368 rtl8723bu_set_hw_type(pdvobjpriv);
371 #ifdef CONFIG_RTL8814A
372 if (pdvobjpriv->chip_type == RTL8814A)
373 rtl8814au_set_hw_type(pdvobjpriv);
374 #endif /* CONFIG_RTL8814A */
376 #ifdef CONFIG_RTL8188F
377 if (pdvobjpriv->chip_type == RTL8188F)
378 rtl8188fu_set_hw_type(pdvobjpriv);
381 #ifdef CONFIG_RTL8703B
382 if (pdvobjpriv->chip_type == RTL8703B)
383 rtl8703bu_set_hw_type(pdvobjpriv);
384 #endif /* CONFIG_RTL8703B */
388 static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf, const struct usb_device_id *pdid)
393 struct dvobj_priv *pdvobjpriv;
394 struct usb_device_descriptor *pdev_desc;
395 struct usb_host_config *phost_conf;
396 struct usb_config_descriptor *pconf_desc;
397 struct usb_host_interface *phost_iface;
398 struct usb_interface_descriptor *piface_desc;
399 struct usb_host_endpoint *phost_endp;
400 struct usb_endpoint_descriptor *pendp_desc;
401 struct usb_device *pusbd;
406 if((pdvobjpriv = devobj_init()) == NULL) {
411 pdvobjpriv->pusbintf = usb_intf ;
412 pusbd = pdvobjpriv->pusbdev = interface_to_usbdev(usb_intf);
413 usb_set_intfdata(usb_intf, pdvobjpriv);
415 pdvobjpriv->RtNumInPipes = 0;
416 pdvobjpriv->RtNumOutPipes = 0;
418 //padapter->EepromAddressSize = 6;
419 //pdvobjpriv->nr_endpoint = 6;
421 pdev_desc = &pusbd->descriptor;
424 DBG_871X("\n8712_usb_device_descriptor:\n");
425 DBG_871X("bLength=%x\n", pdev_desc->bLength);
426 DBG_871X("bDescriptorType=%x\n", pdev_desc->bDescriptorType);
427 DBG_871X("bcdUSB=%x\n", pdev_desc->bcdUSB);
428 DBG_871X("bDeviceClass=%x\n", pdev_desc->bDeviceClass);
429 DBG_871X("bDeviceSubClass=%x\n", pdev_desc->bDeviceSubClass);
430 DBG_871X("bDeviceProtocol=%x\n", pdev_desc->bDeviceProtocol);
431 DBG_871X("bMaxPacketSize0=%x\n", pdev_desc->bMaxPacketSize0);
432 DBG_871X("idVendor=%x\n", pdev_desc->idVendor);
433 DBG_871X("idProduct=%x\n", pdev_desc->idProduct);
434 DBG_871X("bcdDevice=%x\n", pdev_desc->bcdDevice);
435 DBG_871X("iManufacturer=%x\n", pdev_desc->iManufacturer);
436 DBG_871X("iProduct=%x\n", pdev_desc->iProduct);
437 DBG_871X("iSerialNumber=%x\n", pdev_desc->iSerialNumber);
438 DBG_871X("bNumConfigurations=%x\n", pdev_desc->bNumConfigurations);
441 phost_conf = pusbd->actconfig;
442 pconf_desc = &phost_conf->desc;
445 DBG_871X("\n8712_usb_configuration_descriptor:\n");
446 DBG_871X("bLength=%x\n", pconf_desc->bLength);
447 DBG_871X("bDescriptorType=%x\n", pconf_desc->bDescriptorType);
448 DBG_871X("wTotalLength=%x\n", pconf_desc->wTotalLength);
449 DBG_871X("bNumInterfaces=%x\n", pconf_desc->bNumInterfaces);
450 DBG_871X("bConfigurationValue=%x\n", pconf_desc->bConfigurationValue);
451 DBG_871X("iConfiguration=%x\n", pconf_desc->iConfiguration);
452 DBG_871X("bmAttributes=%x\n", pconf_desc->bmAttributes);
453 DBG_871X("bMaxPower=%x\n", pconf_desc->bMaxPower);
456 //DBG_871X("\n/****** num of altsetting = (%d) ******/\n", pusb_interface->num_altsetting);
458 phost_iface = &usb_intf->altsetting[0];
459 piface_desc = &phost_iface->desc;
462 DBG_871X("\n8712_usb_interface_descriptor:\n");
463 DBG_871X("bLength=%x\n", piface_desc->bLength);
464 DBG_871X("bDescriptorType=%x\n", piface_desc->bDescriptorType);
465 DBG_871X("bInterfaceNumber=%x\n", piface_desc->bInterfaceNumber);
466 DBG_871X("bAlternateSetting=%x\n", piface_desc->bAlternateSetting);
467 DBG_871X("bNumEndpoints=%x\n", piface_desc->bNumEndpoints);
468 DBG_871X("bInterfaceClass=%x\n", piface_desc->bInterfaceClass);
469 DBG_871X("bInterfaceSubClass=%x\n", piface_desc->bInterfaceSubClass);
470 DBG_871X("bInterfaceProtocol=%x\n", piface_desc->bInterfaceProtocol);
471 DBG_871X("iInterface=%x\n", piface_desc->iInterface);
474 pdvobjpriv->NumInterfaces = pconf_desc->bNumInterfaces;
475 pdvobjpriv->InterfaceNumber = piface_desc->bInterfaceNumber;
476 pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
478 //DBG_871X("\ndump usb_endpoint_descriptor:\n");
480 for (i = 0; i < pdvobjpriv->nr_endpoint; i++)
482 phost_endp = phost_iface->endpoint + i;
485 pendp_desc = &phost_endp->desc;
487 DBG_871X("\nusb_endpoint_descriptor(%d):\n", i);
488 DBG_871X("bLength=%x\n",pendp_desc->bLength);
489 DBG_871X("bDescriptorType=%x\n",pendp_desc->bDescriptorType);
490 DBG_871X("bEndpointAddress=%x\n",pendp_desc->bEndpointAddress);
491 //DBG_871X("bmAttributes=%x\n",pendp_desc->bmAttributes);
492 DBG_871X("wMaxPacketSize=%d\n",le16_to_cpu(pendp_desc->wMaxPacketSize));
493 DBG_871X("bInterval=%x\n",pendp_desc->bInterval);
494 //DBG_871X("bRefresh=%x\n",pendp_desc->bRefresh);
495 //DBG_871X("bSynchAddress=%x\n",pendp_desc->bSynchAddress);
497 if (RT_usb_endpoint_is_bulk_in(pendp_desc))
499 DBG_871X("RT_usb_endpoint_is_bulk_in = %x\n", RT_usb_endpoint_num(pendp_desc));
500 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = RT_usb_endpoint_num(pendp_desc);
501 pdvobjpriv->RtNumInPipes++;
503 else if (RT_usb_endpoint_is_int_in(pendp_desc))
505 DBG_871X("RT_usb_endpoint_is_int_in = %x, Interval = %x\n", RT_usb_endpoint_num(pendp_desc),pendp_desc->bInterval);
506 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = RT_usb_endpoint_num(pendp_desc);
507 pdvobjpriv->RtNumInPipes++;
509 else if (RT_usb_endpoint_is_bulk_out(pendp_desc))
511 DBG_871X("RT_usb_endpoint_is_bulk_out = %x\n", RT_usb_endpoint_num(pendp_desc));
512 pdvobjpriv->RtOutPipe[pdvobjpriv->RtNumOutPipes] = RT_usb_endpoint_num(pendp_desc);
513 pdvobjpriv->RtNumOutPipes++;
515 pdvobjpriv->ep_num[i] = RT_usb_endpoint_num(pendp_desc);
519 DBG_871X("nr_endpoint=%d, in_num=%d, out_num=%d\n\n", pdvobjpriv->nr_endpoint, pdvobjpriv->RtNumInPipes, pdvobjpriv->RtNumOutPipes);
521 switch(pusbd->speed) {
523 DBG_871X("USB_SPEED_LOW\n");
524 pdvobjpriv->usb_speed = RTW_USB_SPEED_1_1;
527 DBG_871X("USB_SPEED_FULL\n");
528 pdvobjpriv->usb_speed = RTW_USB_SPEED_1_1;
531 DBG_871X("USB_SPEED_HIGH\n");
532 pdvobjpriv->usb_speed = RTW_USB_SPEED_2;
534 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31))
535 case USB_SPEED_SUPER:
536 DBG_871X("USB_SPEED_SUPER\n");
537 pdvobjpriv->usb_speed = RTW_USB_SPEED_3;
541 DBG_871X("USB_SPEED_UNKNOWN(%x)\n",pusbd->speed);
542 pdvobjpriv->usb_speed = RTW_USB_SPEED_UNKNOWN;
546 if (pdvobjpriv->usb_speed == RTW_USB_SPEED_UNKNOWN) {
547 DBG_871X("UNKNOWN USB SPEED MODE, ERROR !!!\n");
551 if (rtw_init_intf_priv(pdvobjpriv) == _FAIL) {
552 RT_TRACE(_module_os_intfs_c_,_drv_err_,("\n Can't INIT rtw_init_intf_priv\n"));
556 /*step 1-1., decide the chip_type via driver_info*/
557 pdvobjpriv->interface_type = RTW_USB;
558 rtw_decide_chip_type_by_usb_info(pdvobjpriv, pdid);
561 _rtw_init_sema(&(pdvobjpriv->usb_suspend_sema), 0);
562 rtw_reset_continual_io_error(pdvobjpriv);
569 if (status != _SUCCESS && pdvobjpriv) {
570 usb_set_intfdata(usb_intf, NULL);
572 devobj_deinit(pdvobjpriv);
581 static void usb_dvobj_deinit(struct usb_interface *usb_intf)
583 struct dvobj_priv *dvobj = usb_get_intfdata(usb_intf);
587 usb_set_intfdata(usb_intf, NULL);
589 //Modify condition for 92DU DMDP 2010.11.18, by Thomas
590 if ((dvobj->NumInterfaces != 2 && dvobj->NumInterfaces != 3)
591 || (dvobj->InterfaceNumber == 1)) {
592 if (interface_to_usbdev(usb_intf)->state != USB_STATE_NOTATTACHED) {
593 //If we didn't unplug usb dongle and remove/insert modlue, driver fails on sitesurvey for the first time when device is up .
594 //Reset usb port for sitesurvey fail issue. 2009.8.13, by Thomas
595 DBG_871X("usb attached..., try to reset usb device\n");
596 usb_reset_device(interface_to_usbdev(usb_intf));
600 rtw_deinit_intf_priv(dvobj);
602 devobj_deinit(dvobj);
605 //DBG_871X("%s %d\n", __func__, ATOMIC_READ(&usb_intf->dev.kobj.kref.refcount));
606 usb_put_dev(interface_to_usbdev(usb_intf));
611 static int usb_reprobe_to_usb3(PADAPTER Adapter)
613 struct registry_priv *registry_par = &Adapter->registrypriv;
616 if (registry_par->switch_usb3 == _TRUE) {
617 if (IS_HIGH_SPEED_USB(Adapter)) {
618 if ((rtw_read8(Adapter, 0x74) & (BIT(2)|BIT(3))) != BIT(3)) {
619 rtw_write8(Adapter, 0x74, 0x8);
620 rtw_write8(Adapter, 0x70, 0x2);
621 rtw_write8(Adapter, 0x3e, 0x1);
622 rtw_write8(Adapter, 0x3d, 0x3);
624 rtw_write8(Adapter, 0x5, 0x80);
628 } else if (IS_SUPER_SPEED_USB(Adapter)) {
629 rtw_write8(Adapter, 0x70, rtw_read8(Adapter, 0x70) & (~BIT(1)));
630 rtw_write8(Adapter, 0x3e, rtw_read8(Adapter, 0x3e) & (~BIT(0)));
637 u8 rtw_set_hal_ops(_adapter *padapter)
639 //alloc memory for HAL DATA
640 if (rtw_hal_data_init(padapter) == _FAIL)
643 #ifdef CONFIG_RTL8188E
644 if (rtw_get_chip_type(padapter) == RTL8188E)
645 rtl8188eu_set_hal_ops(padapter);
648 #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
649 if (rtw_get_chip_type(padapter) == RTL8812 || rtw_get_chip_type(padapter) == RTL8821)
650 rtl8812au_set_hal_ops(padapter);
653 #ifdef CONFIG_RTL8192E
654 if (rtw_get_chip_type(padapter) == RTL8192E)
655 rtl8192eu_set_hal_ops(padapter);
657 #ifdef CONFIG_RTL8723B
658 if (rtw_get_chip_type(padapter) == RTL8723B)
659 rtl8723bu_set_hal_ops(padapter);
661 #ifdef CONFIG_RTL8814A
662 if (rtw_get_chip_type(padapter) == RTL8814A)
663 rtl8814au_set_hal_ops(padapter);
664 #endif /* CONFIG_RTL8814A */
666 #ifdef CONFIG_RTL8188F
667 if (rtw_get_chip_type(padapter) == RTL8188F)
668 rtl8188fu_set_hal_ops(padapter);
671 #ifdef CONFIG_RTL8703B
672 if (rtw_get_chip_type(padapter) == RTL8703B)
673 rtl8703bu_set_hal_ops(padapter);
674 #endif /* CONFIG_RTL8703B */
676 if (_FAIL == rtw_hal_ops_check(padapter) )
679 if (hal_spec_init(padapter) == _FAIL)
685 void usb_set_intf_ops(_adapter *padapter,struct _io_ops *pops)
687 #ifdef CONFIG_RTL8188E
688 if (rtw_get_chip_type(padapter) == RTL8188E)
689 rtl8188eu_set_intf_ops(pops);
692 #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
693 if (rtw_get_chip_type(padapter) == RTL8812 || rtw_get_chip_type(padapter) == RTL8821)
694 rtl8812au_set_intf_ops(pops);
697 #ifdef CONFIG_RTL8192E
698 if (rtw_get_chip_type(padapter) == RTL8192E)
699 rtl8192eu_set_intf_ops(pops);
702 #ifdef CONFIG_RTL8723B
703 if (rtw_get_chip_type(padapter) == RTL8723B)
704 rtl8723bu_set_intf_ops(pops);
707 #ifdef CONFIG_RTL8814A
708 if (rtw_get_chip_type(padapter) == RTL8814A)
709 rtl8814au_set_intf_ops(pops);
710 #endif /* CONFIG_RTL8814A */
712 #ifdef CONFIG_RTL8188F
713 if (rtw_get_chip_type(padapter) == RTL8188F)
714 rtl8188fu_set_intf_ops(pops);
717 #ifdef CONFIG_RTL8703B
718 if (rtw_get_chip_type(padapter) == RTL8703B)
719 rtl8703bu_set_intf_ops(pops);
720 #endif /* CONFIG_RTL8703B */
724 static void usb_intf_start(_adapter *padapter)
727 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+usb_intf_start\n"));
729 rtw_hal_inirp_init(padapter);
731 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-usb_intf_start\n"));
735 static void usb_intf_stop(_adapter *padapter)
738 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+usb_intf_stop\n"));
740 //disabel_hw_interrupt
741 if (!rtw_is_surprise_removed(padapter)) {
742 //device still exists, so driver can do i/o operation
744 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("SurpriseRemoved==_FALSE\n"));
748 rtw_hal_inirp_deinit(padapter);
751 rtw_write_port_cancel(padapter);
753 //todo:cancel other irps
755 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-usb_intf_stop\n"));
759 static void process_spec_devid(const struct usb_device_id *pdid)
764 int num = sizeof(specific_device_id_tbl)/sizeof(struct specific_device_id);
768 vid = specific_device_id_tbl[i].idVendor;
769 pid = specific_device_id_tbl[i].idProduct;
770 flags = specific_device_id_tbl[i].flags;
772 #ifdef CONFIG_80211N_HT
773 if((pdid->idVendor==vid) && (pdid->idProduct==pid) && (flags&SPEC_DEV_ID_DISABLE_HT))
777 rtw_ampdu_enable = 0;
781 #ifdef RTK_DMP_PLATFORM
782 // Change the ifname to wlan10 when PC side WFD dongle plugin on DMP platform.
783 // It is used to distinguish between normal and PC-side wifi dongle/module.
784 if((pdid->idVendor==vid) && (pdid->idProduct==pid) && (flags&SPEC_DEV_ID_ASSIGN_IFNAME))
787 strncpy(ifname, "wlan10", 6);
788 //DBG_871X("%s()-%d: ifname=%s, vid=%04X, pid=%04X\n", __FUNCTION__, __LINE__, ifname, vid, pid);
790 #endif /* RTK_DMP_PLATFORM */
795 #ifdef SUPPORT_HW_RFOFF_DETECTED
796 int rtw_hw_suspend(_adapter *padapter )
798 struct pwrctrl_priv *pwrpriv;
799 struct usb_interface *pusb_intf;
800 struct net_device *pnetdev;
806 if ((_FALSE == padapter->bup) || RTW_CANNOT_RUN(padapter)) {
807 DBG_871X("padapter->bup=%d bDriverStopped=%s bSurpriseRemoved = %s\n"
809 , rtw_is_drv_stopped(padapter)?"True":"False"
810 , rtw_is_surprise_removed(padapter)?"True":"False");
814 pwrpriv = adapter_to_pwrctl(padapter);
815 pusb_intf = adapter_to_dvobj(padapter)->pusbintf;
816 pnetdev = padapter->pnetdev;
818 LeaveAllPowerSaveMode(padapter);
820 DBG_871X("==> rtw_hw_suspend\n");
821 _enter_pwrlock(&pwrpriv->lock);
822 pwrpriv->bips_processing = _TRUE;
823 //padapter->net_closed = _TRUE;
827 netif_carrier_off(pnetdev);
828 rtw_netif_stop_queue(pnetdev);
832 rtw_disassoc_cmd(padapter, 500, _FALSE);
834 //s2-2. indicate disconnect to os
835 //rtw_indicate_disconnect(padapter);
837 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
838 if(check_fwstate(pmlmepriv, _FW_LINKED))
840 _clr_fwstate_(pmlmepriv, _FW_LINKED);
841 rtw_led_control(padapter, LED_CTL_NO_LINK);
843 rtw_os_indicate_disconnect(padapter);
847 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_DISCONNECT, 0);
852 rtw_free_assoc_resources(padapter, 1);
855 rtw_free_network_queue(padapter,_TRUE);
857 rtw_ips_dev_unload(padapter);
859 pwrpriv->rf_pwrstate = rf_off;
860 pwrpriv->bips_processing = _FALSE;
861 _exit_pwrlock(&pwrpriv->lock);
867 DBG_871X("%s, failed \n",__FUNCTION__);
872 int rtw_hw_resume(_adapter *padapter)
874 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
875 struct usb_interface *pusb_intf = adapter_to_dvobj(padapter)->pusbintf;
876 struct net_device *pnetdev = padapter->pnetdev;
879 DBG_871X("==> rtw_hw_resume\n");
880 _enter_pwrlock(&pwrpriv->lock);
881 pwrpriv->bips_processing = _TRUE;
882 rtw_reset_drv_sw(padapter);
884 if(pm_netdev_open(pnetdev,_FALSE) != 0)
886 _exit_pwrlock(&pwrpriv->lock);
890 netif_device_attach(pnetdev);
891 netif_carrier_on(pnetdev);
893 rtw_netif_wake_queue(pnetdev);
895 pwrpriv->bkeepfwalive = _FALSE;
896 pwrpriv->brfoffbyhw = _FALSE;
898 pwrpriv->rf_pwrstate = rf_on;
899 pwrpriv->bips_processing = _FALSE;
900 _exit_pwrlock(&pwrpriv->lock);
906 DBG_871X("%s, Open net dev failed \n",__FUNCTION__);
911 static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
913 struct dvobj_priv *dvobj;
914 struct pwrctrl_priv *pwrpriv;
915 struct debug_priv *pdbgpriv;
920 dvobj = usb_get_intfdata(pusb_intf);
921 pwrpriv = dvobj_to_pwrctl(dvobj);
922 pdbgpriv = &dvobj->drv_dbg;
923 padapter = dvobj->padapters[IFACE_ID0];
925 if (pwrpriv->bInSuspend == _TRUE) {
926 DBG_871X("%s bInSuspend = %d\n", __FUNCTION__, pwrpriv->bInSuspend);
927 pdbgpriv->dbg_suspend_error_cnt++;
931 if ((padapter->bup) || !rtw_is_drv_stopped(padapter) || !rtw_is_surprise_removed(padapter)) {
932 #ifdef CONFIG_AUTOSUSPEND
933 if(pwrpriv->bInternalAutoSuspend ){
935 #ifdef SUPPORT_HW_RFOFF_DETECTED
936 // The FW command register update must after MAC and FW init ready.
937 if((padapter->bFWReady) && (pwrpriv->bHWPwrPindetect ) && (padapter->registrypriv.usbss_enable ))
940 rtw_interface_ps_func(padapter,HAL_USB_SELECT_SUSPEND,&bOpen);
942 #endif//SUPPORT_HW_RFOFF_DETECTED
944 #endif//CONFIG_AUTOSUSPEND
947 ret = rtw_suspend_common(padapter);
953 int rtw_resume_process(_adapter *padapter)
956 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
957 struct dvobj_priv *pdvobj = padapter->dvobj;
958 struct debug_priv *pdbgpriv = &pdvobj->drv_dbg;
961 if (pwrpriv->bInSuspend == _FALSE)
963 pdbgpriv->dbg_resume_error_cnt++;
964 DBG_871X("%s bInSuspend = %d\n", __FUNCTION__, pwrpriv->bInSuspend);
968 #if defined(CONFIG_BT_COEXIST) && defined(CONFIG_AUTOSUSPEND) //add by amy for 8723as-vau
969 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
970 DBG_871X("%s...pm_usage_cnt(%d) pwrpriv->bAutoResume=%x. ....\n",__func__,atomic_read(&(adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt)),pwrpriv->bAutoResume);
971 pm_cnt=atomic_read(&(adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt));
972 #else // kernel < 2.6.32
973 DBG_871X("...pm_usage_cnt(%d).....\n", adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt);
974 pm_cnt = adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt;
975 #endif // kernel < 2.6.32
977 DBG_871X("pwrpriv->bAutoResume (%x)\n",pwrpriv->bAutoResume );
978 if( _TRUE == pwrpriv->bAutoResume ){
979 pwrpriv->bInternalAutoSuspend = _FALSE;
980 pwrpriv->bAutoResume=_FALSE;
981 DBG_871X("pwrpriv->bAutoResume (%x) pwrpriv->bInternalAutoSuspend(%x)\n",pwrpriv->bAutoResume,pwrpriv->bInternalAutoSuspend );
984 #endif //#ifdef CONFIG_BT_COEXIST &CONFIG_AUTOSUSPEND&
986 #if defined (CONFIG_WOWLAN) || defined (CONFIG_AP_WOWLAN)
988 * Due to usb wow suspend flow will cancel read/write port via intf_stop and
989 * bReadPortCancel and bWritePortCancel are set _TRUE in intf_stop.
990 * But they will not be clear in intf_start during wow resume flow.
991 * It should move to os_intf in the feature.
993 RTW_ENABLE_FUNC(padapter, DF_RX_BIT);
994 RTW_ENABLE_FUNC(padapter, DF_TX_BIT);
997 ret = rtw_resume_common(padapter);
999 #ifdef CONFIG_AUTOSUSPEND
1000 if(pwrpriv->bInternalAutoSuspend )
1002 #ifdef SUPPORT_HW_RFOFF_DETECTED
1003 // The FW command register update must after MAC and FW init ready.
1004 if((padapter->bFWReady) && (pwrpriv->bHWPwrPindetect) && (padapter->registrypriv.usbss_enable ))
1007 rtw_interface_ps_func(padapter,HAL_USB_SELECT_SUSPEND,&bOpen);
1010 #ifdef CONFIG_BT_COEXIST // for 8723as-vau
1011 DBG_871X("pwrpriv->bAutoResume (%x)\n",pwrpriv->bAutoResume );
1012 if( _TRUE == pwrpriv->bAutoResume ){
1013 pwrpriv->bInternalAutoSuspend = _FALSE;
1014 pwrpriv->bAutoResume=_FALSE;
1015 DBG_871X("pwrpriv->bAutoResume (%x) pwrpriv->bInternalAutoSuspend(%x)\n",pwrpriv->bAutoResume,pwrpriv->bInternalAutoSuspend );
1018 #else //#ifdef CONFIG_BT_COEXIST
1019 pwrpriv->bInternalAutoSuspend = _FALSE;
1020 #endif //#ifdef CONFIG_BT_COEXIST
1021 pwrpriv->brfoffbyhw = _FALSE;
1023 #endif//CONFIG_AUTOSUSPEND
1029 static int rtw_resume(struct usb_interface *pusb_intf)
1031 struct dvobj_priv *dvobj;
1032 struct pwrctrl_priv *pwrpriv;
1033 struct debug_priv *pdbgpriv;
1035 struct mlme_ext_priv *pmlmeext;
1039 dvobj = usb_get_intfdata(pusb_intf);
1040 pwrpriv = dvobj_to_pwrctl(dvobj);
1041 pdbgpriv = &dvobj->drv_dbg;
1042 padapter = dvobj->padapters[IFACE_ID0];
1043 pmlmeext = &padapter->mlmeextpriv;
1045 DBG_871X("==> %s (%s:%d)\n", __FUNCTION__, current->comm, current->pid);
1046 pdbgpriv->dbg_resume_cnt++;
1048 if(pwrpriv->bInternalAutoSuspend)
1050 ret = rtw_resume_process(padapter);
1054 if(pwrpriv->wowlan_mode || pwrpriv->wowlan_ap_mode)
1056 rtw_resume_lock_suspend();
1057 ret = rtw_resume_process(padapter);
1058 rtw_resume_unlock_suspend();
1062 #ifdef CONFIG_RESUME_IN_WORKQUEUE
1063 rtw_resume_in_workqueue(pwrpriv);
1065 if (rtw_is_earlysuspend_registered(pwrpriv))
1067 /* jeff: bypass resume here, do in late_resume */
1068 rtw_set_do_late_resume(pwrpriv, _TRUE);
1072 rtw_resume_lock_suspend();
1073 ret = rtw_resume_process(padapter);
1074 rtw_resume_unlock_suspend();
1080 pmlmeext->last_scan_time = rtw_get_current_time();
1081 DBG_871X("<======== %s return %d\n", __FUNCTION__, ret);
1088 #ifdef CONFIG_AUTOSUSPEND
1089 void autosuspend_enter(_adapter* padapter)
1091 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1092 struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
1094 DBG_871X("==>autosuspend_enter...........\n");
1096 pwrpriv->bInternalAutoSuspend = _TRUE;
1097 pwrpriv->bips_processing = _TRUE;
1099 if(rf_off == pwrpriv->change_rfpwrstate )
1101 #ifndef CONFIG_BT_COEXIST
1102 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1103 usb_enable_autosuspend(dvobj->pusbdev);
1105 dvobj->pusbdev->autosuspend_disabled = 0;//autosuspend disabled by the user
1108 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1109 usb_autopm_put_interface(dvobj->pusbintf);
1110 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1111 usb_autopm_enable(dvobj->pusbintf);
1113 usb_autosuspend_device(dvobj->pusbdev, 1);
1115 #else //#ifndef CONFIG_BT_COEXIST
1116 if(1==pwrpriv->autopm_cnt){
1117 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1118 usb_enable_autosuspend(dvobj->pusbdev);
1120 dvobj->pusbdev->autosuspend_disabled = 0;//autosuspend disabled by the user
1123 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1124 usb_autopm_put_interface(dvobj->pusbintf);
1125 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1126 usb_autopm_enable(dvobj->pusbintf);
1128 usb_autosuspend_device(dvobj->pusbdev, 1);
1130 pwrpriv->autopm_cnt --;
1133 DBG_871X("0!=pwrpriv->autopm_cnt[%d] didn't usb_autopm_put_interface\n", pwrpriv->autopm_cnt);
1135 #endif //#ifndef CONFIG_BT_COEXIST
1137 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1138 DBG_871X("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1140 DBG_871X("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1145 int autoresume_enter(_adapter* padapter)
1147 int result = _SUCCESS;
1148 struct security_priv* psecuritypriv=&(padapter->securitypriv);
1149 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1150 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1151 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1152 struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
1154 DBG_871X("====> autoresume_enter \n");
1156 if(rf_off == pwrpriv->rf_pwrstate )
1158 pwrpriv->ps_flag = _FALSE;
1159 #ifndef CONFIG_BT_COEXIST
1160 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1161 if (usb_autopm_get_interface(dvobj->pusbintf) < 0)
1163 DBG_871X( "can't get autopm: %d\n", result);
1167 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1168 usb_autopm_disable(dvobj->pusbintf);
1170 usb_autoresume_device(dvobj->pusbdev, 1);
1173 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1174 DBG_871X("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1176 DBG_871X("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1178 #else //#ifndef CONFIG_BT_COEXIST
1179 pwrpriv->bAutoResume=_TRUE;
1180 if(0==pwrpriv->autopm_cnt){
1181 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1182 if (usb_autopm_get_interface(dvobj->pusbintf) < 0)
1184 DBG_871X( "can't get autopm: %d\n", result);
1188 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1189 usb_autopm_disable(dvobj->pusbintf);
1191 usb_autoresume_device(dvobj->pusbdev, 1);
1193 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1194 DBG_871X("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1196 DBG_871X("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1198 pwrpriv->autopm_cnt++;
1201 DBG_871X("0!=pwrpriv->autopm_cnt[%d] didn't usb_autopm_get_interface\n",pwrpriv->autopm_cnt);
1202 #endif //#ifndef CONFIG_BT_COEXIST
1204 DBG_871X("<==== autoresume_enter \n");
1211 #ifdef CONFIG_PLATFORM_RTD2880B
1212 extern void rtd2885_wlan_netlink_sendMsg(char *action_string, char *name);
1216 * drv_init() - a device potentially for us
1218 * notes: drv_init() is called when the bus driver has located a card for us to support.
1219 * We accept the new device by returning 0.
1222 _adapter *rtw_sw_export = NULL;
1224 _adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
1225 struct usb_interface *pusb_intf)
1227 _adapter *padapter = NULL;
1230 padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter));
1231 if (padapter == NULL)
1234 if (loadparam(padapter) != _SUCCESS)
1237 padapter->dvobj = dvobj;
1240 rtw_set_drv_stopped(padapter);/*init*/
1242 dvobj->padapters[dvobj->iface_nums++] = padapter;
1243 padapter->iface_id = IFACE_ID0;
1245 #if defined(CONFIG_CONCURRENT_MODE)
1246 //set adapter_type/iface type for primary padapter
1247 padapter->isprimary = _TRUE;
1248 padapter->adapter_type = PRIMARY_ADAPTER;
1249 #ifndef CONFIG_HWPORT_SWAP
1250 padapter->iface_type = IFACE_PORT0;
1252 padapter->iface_type = IFACE_PORT1;
1256 //step 2. hook HalFunc, allocate HalData
1257 //hal_set_hal_ops(padapter);
1258 if(rtw_set_hal_ops(padapter) ==_FAIL)
1262 padapter->intf_start=&usb_intf_start;
1263 padapter->intf_stop=&usb_intf_stop;
1266 if( rtw_init_io_priv(padapter,usb_set_intf_ops) ==_FAIL)
1269 //step read_chip_version
1270 rtw_hal_read_chip_version(padapter);
1272 //step usb endpoint mapping
1273 rtw_hal_chip_configure(padapter);
1275 #ifdef CONFIG_BT_COEXIST
1276 rtw_btcoex_Initialize(padapter);
1277 #endif // CONFIG_BT_COEXIST
1279 //step read efuse/eeprom data and get mac_addr
1280 rtw_hal_read_chip_info(padapter);
1283 if(rtw_init_drv_sw(padapter) ==_FAIL) {
1284 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("Initialize driver software resource Failed!\n"));
1289 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18))
1290 if(dvobj_to_pwrctl(dvobj)->bSupportRemoteWakeup)
1292 dvobj->pusbdev->do_remote_wakeup=1;
1293 pusb_intf->needs_remote_wakeup = 1;
1294 device_init_wakeup(&pusb_intf->dev, 1);
1295 DBG_871X("pwrctrlpriv.bSupportRemoteWakeup~~~~~~\n");
1296 DBG_871X("pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n",device_may_wakeup(&pusb_intf->dev));
1301 #ifdef CONFIG_AUTOSUSPEND
1302 if( padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE )
1304 if(padapter->registrypriv.usbss_enable ){ /* autosuspend (2s delay) */
1305 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,38))
1306 dvobj->pusbdev->dev.power.autosuspend_delay = 0 * HZ;//15 * HZ; idle-delay time
1308 dvobj->pusbdev->autosuspend_delay = 0 * HZ;//15 * HZ; idle-delay time
1311 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1312 usb_enable_autosuspend(dvobj->pusbdev);
1313 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22) && LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,34))
1314 padapter->bDisableAutosuspend = dvobj->pusbdev->autosuspend_disabled ;
1315 dvobj->pusbdev->autosuspend_disabled = 0;//autosuspend disabled by the user
1318 //usb_autopm_get_interface(adapter_to_dvobj(padapter)->pusbintf );//init pm_usage_cnt ,let it start from 1
1320 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1321 DBG_871X("%s...pm_usage_cnt(%d).....\n",__FUNCTION__,atomic_read(&(dvobj->pusbintf ->pm_usage_cnt)));
1323 DBG_871X("%s...pm_usage_cnt(%d).....\n",__FUNCTION__,dvobj->pusbintf ->pm_usage_cnt);
1328 //2012-07-11 Move here to prevent the 8723AS-VAU BT auto suspend influence
1329 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1330 if (usb_autopm_get_interface(pusb_intf) < 0)
1332 DBG_871X( "can't get autopm: \n");
1335 #ifdef CONFIG_BT_COEXIST
1336 dvobj_to_pwrctl(dvobj)->autopm_cnt=1;
1340 rtw_macaddr_cfg(adapter_mac_addr(padapter), get_hal_mac_addr(padapter));
1342 rtw_init_wifidirect_addrs(padapter, adapter_mac_addr(padapter), adapter_mac_addr(padapter));
1343 #endif // CONFIG_P2P
1344 DBG_871X("bDriverStopped:%s, bSurpriseRemoved:%s, bup:%d, hw_init_completed:%d\n"
1345 , rtw_is_drv_stopped(padapter)?"True":"False"
1346 , rtw_is_surprise_removed(padapter)?"True":"False"
1348 , rtw_get_hw_init_completed(padapter)
1354 if (status != _SUCCESS && padapter->HalData)
1355 rtw_hal_free_data(padapter);
1357 if (status != _SUCCESS && padapter) {
1358 rtw_vmfree((u8 *)padapter, sizeof(*padapter));
1365 static void rtw_usb_if1_deinit(_adapter *if1)
1367 struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(if1);
1368 struct mlme_priv *pmlmepriv= &if1->mlmepriv;
1370 if(check_fwstate(pmlmepriv, _FW_LINKED))
1371 rtw_disassoc_cmd(if1, 0, _FALSE);
1374 #ifdef CONFIG_AP_MODE
1375 free_mlme_ap_info(if1);
1376 #ifdef CONFIG_HOSTAPD_MLME
1377 hostapd_mode_unload(if1);
1381 #ifdef CONFIG_WOWLAN
1382 pwrctl->wowlan_mode=_FALSE;
1383 #endif //CONFIG_WOWLAN
1385 rtw_dev_unload(if1);
1387 DBG_871X("+r871xu_dev_remove, hw_init_completed=%d\n", rtw_get_hw_init_completed(if1));
1389 #ifdef CONFIG_BT_COEXIST
1390 if(1 == pwrctl->autopm_cnt){
1391 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1392 usb_autopm_put_interface(adapter_to_dvobj(if1)->pusbintf);
1393 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1394 usb_autopm_enable(adapter_to_dvobj(if1)->pusbintf);
1396 usb_autosuspend_device(adapter_to_dvobj(if1)->pusbdev, 1);
1398 pwrctl->autopm_cnt --;
1402 rtw_free_drv_sw(if1);
1404 /* TODO: use rtw_os_ndevs_deinit instead at the first stage of driver's dev deinit function */
1405 rtw_os_ndev_free(if1);
1407 rtw_vmfree((u8 *)if1, sizeof(_adapter));
1409 #ifdef CONFIG_PLATFORM_RTD2880B
1410 DBG_871X("wlan link down\n");
1411 rtd2885_wlan_netlink_sendMsg("linkdown", "8712");
1416 static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
1418 _adapter *if1 = NULL, *if2 = NULL;
1420 struct dvobj_priv *dvobj;
1421 #ifdef CONFIG_MULTI_VIR_IFACES
1423 #endif //CONFIG_MULTI_VIR_IFACES
1425 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_drv_init\n"));
1426 //DBG_871X("+rtw_drv_init\n");
1429 process_spec_devid(pdid);
1431 /* Initialize dvobj_priv */
1432 if ((dvobj = usb_dvobj_init(pusb_intf, pdid)) == NULL) {
1433 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("initialize device object priv Failed!\n"));
1437 if ((if1 = rtw_usb_if1_init(dvobj, pusb_intf)) == NULL) {
1438 DBG_871X("rtw_usb_if1_init Failed!\n");
1442 if (usb_reprobe_to_usb3(if1) == _TRUE)
1445 #ifdef CONFIG_CONCURRENT_MODE
1446 if((if2 = rtw_drv_if2_init(if1, usb_set_intf_ops)) == NULL) {
1449 #ifdef CONFIG_MULTI_VIR_IFACES
1450 for(i=0; i<if1->registrypriv.ext_iface_num;i++)
1452 if(rtw_drv_add_vir_if(if1, usb_set_intf_ops) == NULL)
1454 DBG_871X("rtw_drv_add_iface failed! (%d)\n", i);
1458 #endif //CONFIG_MULTI_VIR_IFACES
1461 #ifdef CONFIG_INTEL_PROXIM
1465 #ifdef CONFIG_GLOBAL_UI_PID
1467 DBG_871X("ui_pid[1]:%d\n",ui_pid[1]);
1468 rtw_signal_process(ui_pid[1], SIGUSR2);
1472 //dev_alloc_name && register_netdev
1473 if (rtw_os_ndevs_init(dvobj) != _SUCCESS)
1476 #ifdef CONFIG_HOSTAPD_MLME
1477 hostapd_mode_init(if1);
1480 #ifdef CONFIG_PLATFORM_RTD2880B
1481 DBG_871X("wlan link up\n");
1482 rtd2885_wlan_netlink_sendMsg("linkup", "8712");
1485 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-871x_drv - drv_init, success!\n"));
1489 #if 0 /* not used now */
1491 if (status != _SUCCESS)
1492 rtw_os_ndevs_deinit(dvobj);
1495 if(status != _SUCCESS && if2) {
1496 #ifdef CONFIG_CONCURRENT_MODE
1497 rtw_drv_if2_stop(if2);
1498 rtw_drv_if2_free(if2);
1502 if (status != _SUCCESS && if1) {
1503 rtw_usb_if1_deinit(if1);
1506 if (status != _SUCCESS)
1507 usb_dvobj_deinit(pusb_intf);
1509 return status == _SUCCESS?0:-ENODEV;
1513 * dev_remove() - our device is being removed
1515 //rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove() => how to recognize both
1516 static void rtw_dev_remove(struct usb_interface *pusb_intf)
1518 struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
1519 struct pwrctrl_priv *pwrctl = dvobj_to_pwrctl(dvobj);
1520 _adapter *padapter = dvobj->padapters[IFACE_ID0];
1521 struct net_device *pnetdev = padapter->pnetdev;
1522 struct mlme_priv *pmlmepriv= &padapter->mlmepriv;
1526 DBG_871X("+rtw_dev_remove\n");
1527 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+dev_remove()\n"));
1529 dvobj->processing_dev_remove = _TRUE;
1531 /* TODO: use rtw_os_ndevs_deinit instead at the first stage of driver's dev deinit function */
1532 rtw_os_ndevs_unregister(dvobj);
1534 if(usb_drv.drv_registered == _TRUE)
1536 //DBG_871X("r871xu_dev_remove():padapter->bSurpriseRemoved == _TRUE\n");
1537 rtw_set_surprise_removed(padapter);
1541 //DBG_871X("r871xu_dev_remove():module removed\n");
1542 padapter->HalData->hw_init_completed = _FALSE;
1546 #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
1547 rtw_unregister_early_suspend(pwrctl);
1550 if (padapter->bFWReady == _TRUE) {
1551 rtw_pm_set_ips(padapter, IPS_NONE);
1552 rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
1554 LeaveAllPowerSaveMode(padapter);
1556 rtw_set_drv_stopped(padapter); /*for stop thread*/
1558 /* stop cmd thread */
1559 rtw_stop_cmd_thread(padapter);
1560 #ifdef CONFIG_CONCURRENT_MODE
1561 #ifdef CONFIG_MULTI_VIR_IFACES
1562 rtw_drv_stop_vir_ifaces(dvobj);
1563 #endif //CONFIG_MULTI_VIR_IFACES
1564 rtw_drv_if2_stop(dvobj->padapters[IFACE_ID1]);
1565 #endif //CONFIG_CONCURRENT_MODE
1567 #ifdef CONFIG_BT_COEXIST
1568 rtw_btcoex_HaltNotify(padapter);
1571 rtw_usb_if1_deinit(padapter);
1573 #ifdef CONFIG_CONCURRENT_MODE
1574 #ifdef CONFIG_MULTI_VIR_IFACES
1575 rtw_drv_free_vir_ifaces(dvobj);
1576 #endif //CONFIG_MULTI_VIR_IFACES
1577 rtw_drv_if2_free(dvobj->padapters[IFACE_ID1]);
1578 #endif //CONFIG_CONCURRENT_MODE
1580 usb_dvobj_deinit(pusb_intf);
1582 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-dev_remove()\n"));
1583 DBG_871X("-r871xu_dev_remove, done\n");
1586 #ifdef CONFIG_INTEL_PROXIM
1595 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
1596 extern int console_suspend_enabled;
1599 static int rtw_drv_entry(void)
1603 DBG_871X_LEVEL(_drv_always_, "module init start\n");
1604 dump_drv_version(RTW_DBGDUMP);
1605 #ifdef BTCOEXVERSION
1606 DBG_871X_LEVEL(_drv_always_, DRV_NAME" BT-Coex version = %s\n", BTCOEXVERSION);
1607 #endif // BTCOEXVERSION
1609 ret = platform_wifi_power_on();
1612 DBG_871X("%s: power on failed!!(%d)\n", __FUNCTION__, ret);
1616 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
1617 //console_suspend_enabled=0;
1620 usb_drv.drv_registered = _TRUE;
1621 rtw_suspend_lock_init();
1622 rtw_drv_proc_init();
1623 rtw_ndev_notifier_register();
1625 ret = usb_register(&usb_drv.usbdrv);
1628 usb_drv.drv_registered = _FALSE;
1629 rtw_suspend_lock_uninit();
1630 rtw_drv_proc_deinit();
1631 rtw_ndev_notifier_unregister();
1636 DBG_871X_LEVEL(_drv_always_, "module init ret=%d\n", ret);
1640 static void rtw_drv_halt(void)
1642 DBG_871X_LEVEL(_drv_always_, "module exit start\n");
1644 usb_drv.drv_registered = _FALSE;
1646 usb_deregister(&usb_drv.usbdrv);
1648 platform_wifi_power_off();
1650 rtw_suspend_lock_uninit();
1651 rtw_drv_proc_deinit();
1652 rtw_ndev_notifier_unregister();
1654 DBG_871X_LEVEL(_drv_always_, "module exit success\n");
1656 rtw_mstat_dump(RTW_DBGDUMP);
1660 #include <linux/rfkill-wlan.h>
1661 #include "wifi_version.h"
1662 extern int get_wifi_chip_type(void);
1664 int rockchip_wifi_init_module_rtkwifi(void)
1666 //#ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
1667 // int type = get_wifi_chip_type();
1668 // if (type < WIFI_AP6XXX_SERIES || type == WIFI_ESP8089) return 0;
1671 printk("=======================================================\n");
1672 printk("==== Launching Wi-Fi driver! (Powered by Rockchip) ====\n");
1673 printk("=======================================================\n");
1674 printk("Realtek 8188EU USB WiFi driver (Powered by Rockchip,Ver %s) init.\n", RTL8192_DRV_VERSION);
1675 rockchip_wifi_power(1);
1677 return rtw_drv_entry();
1680 void rockchip_wifi_exit_module_rtkwifi(void)
1682 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
1683 int type = get_wifi_chip_type();
1684 if (type < WIFI_AP6XXX_SERIES || type == WIFI_ESP8089) return;
1687 printk("=======================================================\n");
1688 printk("==== Dislaunching Wi-Fi driver! (Powered by Rockchip) ====\n");
1689 printk("=======================================================\n");
1690 printk("Realtek 8188EU USB WiFi driver (Powered by Rockchip,Ver %s) init.\n", RTL8192_DRV_VERSION);
1692 rockchip_wifi_power(0);
1695 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
1696 late_initcall(rockchip_wifi_init_module_rtkwifi);
1697 module_exit(rockchip_wifi_exit_module_rtkwifi);
1699 module_init(rockchip_wifi_init_module_rtkwifi);
1700 module_exit(rockchip_wifi_exit_module_rtkwifi);
1702 //module_init(rtw_drv_entry);
1703 //module_exit(rtw_drv_halt);
1705 #ifdef CONFIG_INTEL_PROXIM
1706 _adapter *rtw_usb_get_sw_pointer(void)
1708 return rtw_sw_export;
1710 EXPORT_SYMBOL(rtw_usb_get_sw_pointer);
1711 #endif //CONFIG_INTEL_PROXIM