Merge tag 'lsk-v3.10-android-15.01'
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / os_dep / linux / usb_intf.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4  *
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.
8  *
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
12  * more details.
13  *
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
17  *
18  *
19  ******************************************************************************/
20 #define _HCI_INTF_C_
21
22 #include <drv_types.h>
23 #include <platform_ops.h>
24
25 #ifndef CONFIG_USB_HCI
26 #error "CONFIG_USB_HCI shall be on!\n"
27 #endif
28
29 #if defined (PLATFORM_LINUX) && defined (PLATFORM_WINDOWS)
30 #error "Shall be Linux or Windows, but not both!\n"
31 #endif
32
33 #ifdef CONFIG_80211N_HT
34 extern int rtw_ht_enable;
35 extern int rtw_bw_mode;
36 extern int rtw_ampdu_enable;//for enable tx_ampdu
37 #endif
38
39 #ifdef CONFIG_GLOBAL_UI_PID
40 int ui_pid[3] = {0, 0, 0};
41 #endif
42
43
44 extern int pm_netdev_open(struct net_device *pnetdev,u8 bnormal);
45 static int rtw_suspend(struct usb_interface *intf, pm_message_t message);
46 static int rtw_resume(struct usb_interface *intf);
47 int rtw_resume_process(_adapter *padapter);
48
49
50 static int rtw_drv_init(struct usb_interface *pusb_intf,const struct usb_device_id *pdid);
51 static void rtw_dev_remove(struct usb_interface *pusb_intf);
52
53 static void rtw_dev_shutdown(struct device *dev)
54 {
55         struct usb_interface *usb_intf = container_of(dev, struct usb_interface, dev);
56         struct dvobj_priv *dvobj = NULL;
57         _adapter *adapter = NULL;
58         int i;
59
60         DBG_871X("%s\n", __func__);
61
62         if(usb_intf)
63         {
64                 dvobj = usb_get_intfdata(usb_intf);
65                 if (dvobj)
66                 {
67                         for (i = 0; i<dvobj->iface_nums; i++)
68                         {
69                                 adapter = dvobj->padapters[i];
70                                 if (adapter)
71                                 {
72                                         adapter->bSurpriseRemoved = _TRUE;
73                                 }
74                         }
75
76                         ATOMIC_SET(&dvobj->continual_io_error, MAX_CONTINUAL_IO_ERR+1);
77                 }
78         }
79 }
80
81 #if (LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,23))
82 /* Some useful macros to use to create struct usb_device_id */
83  #define USB_DEVICE_ID_MATCH_VENDOR                      0x0001
84  #define USB_DEVICE_ID_MATCH_PRODUCT                     0x0002
85  #define USB_DEVICE_ID_MATCH_DEV_LO                      0x0004
86  #define USB_DEVICE_ID_MATCH_DEV_HI                      0x0008
87  #define USB_DEVICE_ID_MATCH_DEV_CLASS                   0x0010
88  #define USB_DEVICE_ID_MATCH_DEV_SUBCLASS                0x0020
89  #define USB_DEVICE_ID_MATCH_DEV_PROTOCOL                0x0040
90  #define USB_DEVICE_ID_MATCH_INT_CLASS                   0x0080
91  #define USB_DEVICE_ID_MATCH_INT_SUBCLASS                0x0100
92  #define USB_DEVICE_ID_MATCH_INT_PROTOCOL                0x0200
93  #define USB_DEVICE_ID_MATCH_INT_NUMBER                  0x0400
94
95
96 #define USB_DEVICE_ID_MATCH_INT_INFO \
97                                  (USB_DEVICE_ID_MATCH_INT_CLASS | \
98                                  USB_DEVICE_ID_MATCH_INT_SUBCLASS | \
99                                  USB_DEVICE_ID_MATCH_INT_PROTOCOL)
100
101
102 #define USB_DEVICE_AND_INTERFACE_INFO(vend, prod, cl, sc, pr) \
103                  .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
104                                  | USB_DEVICE_ID_MATCH_DEVICE, \
105                  .idVendor = (vend), \
106                  .idProduct = (prod), \
107                  .bInterfaceClass = (cl), \
108                  .bInterfaceSubClass = (sc), \
109                  .bInterfaceProtocol = (pr)
110
111  /**
112   * USB_VENDOR_AND_INTERFACE_INFO - describe a specific usb vendor with a class of usb interfaces
113   * @vend: the 16 bit USB Vendor ID
114   * @cl: bInterfaceClass value
115   * @sc: bInterfaceSubClass value
116   * @pr: bInterfaceProtocol value
117   *
118   * This macro is used to create a struct usb_device_id that matches a
119   * specific vendor with a specific class of interfaces.
120   *
121   * This is especially useful when explicitly matching devices that have
122   * vendor specific bDeviceClass values, but standards-compliant interfaces.
123   */
124 #define USB_VENDOR_AND_INTERFACE_INFO(vend, cl, sc, pr) \
125                  .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
126                                  | USB_DEVICE_ID_MATCH_VENDOR, \
127                  .idVendor = (vend), \
128                  .bInterfaceClass = (cl), \
129                  .bInterfaceSubClass = (sc), \
130                  .bInterfaceProtocol = (pr)
131
132 /* ----------------------------------------------------------------------- */
133 #endif
134
135
136 #define USB_VENDER_ID_REALTEK           0x0BDA
137
138
139 /* DID_USB_v916_20130116 */
140 static struct usb_device_id rtw_usb_id_tbl[] ={
141
142 #ifdef CONFIG_RTL8192C
143         /*=== Realtek demoboard ===*/
144         /****** 8188CUS ********/
145         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8176),.driver_info = RTL8188C_8192C},/* 8188cu 1*1 dongole */
146         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8170),.driver_info = RTL8188C_8192C},/* 8188CE-VAU USB minCard */
147         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817E),.driver_info = RTL8188C_8192C},/* 8188CE-VAU USB minCard */
148         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817A),.driver_info = RTL8188C_8192C},/* 8188cu Slim Solo */
149         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817B),.driver_info = RTL8188C_8192C},/* 8188cu Slim Combo */
150         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817D),.driver_info = RTL8188C_8192C},/* 8188RU High-power USB Dongle */
151         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8754),.driver_info = RTL8188C_8192C},/* 8188 Combo for BC4 */
152         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817F),.driver_info = RTL8188C_8192C},/* 8188RU */
153         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x818A),.driver_info = RTL8188C_8192C},/* RTL8188CUS-VL */
154         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x018A),.driver_info = RTL8188C_8192C},/* RTL8188CTV */
155         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x17C0),.driver_info = RTL8188C_8192C},/* RTK demoboard - USB-N10E */
156         /****** 8192CUS ********/
157         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8177),.driver_info = RTL8188C_8192C},/* 8191cu 1*2 */
158         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8178),.driver_info = RTL8188C_8192C},/* 8192cu 2*2 */
159         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817C),.driver_info = RTL8188C_8192C},/* 8192CE-VAU USB minCard */
160         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8191),.driver_info = RTL8188C_8192C},/* 8192CU 2*2 */
161         {USB_DEVICE(0x1058, 0x0631),.driver_info = RTL8188C_8192C},/* Alpha, 8192CU */
162         /*=== Customer ID ===*/
163         /****** 8188CUS Dongle ********/
164         {USB_DEVICE(0x2019, 0xED17),.driver_info = RTL8188C_8192C},/* PCI - Edimax */
165         {USB_DEVICE(0x0DF6, 0x0052),.driver_info = RTL8188C_8192C},/* Sitecom - Edimax */
166         {USB_DEVICE(0x7392, 0x7811),.driver_info = RTL8188C_8192C},/* Edimax - Edimax */
167         {USB_DEVICE(0x07B8, 0x8189),.driver_info = RTL8188C_8192C},/* Abocom - Abocom */
168         {USB_DEVICE(0x0EB0, 0x9071),.driver_info = RTL8188C_8192C},/* NO Brand - Etop */
169         {USB_DEVICE(0x06F8, 0xE033),.driver_info = RTL8188C_8192C},/* Hercules - Edimax */
170         {USB_DEVICE(0x103C, 0x1629),.driver_info = RTL8188C_8192C},/* HP - Lite-On ,8188CUS Slim Combo */
171         {USB_DEVICE(0x2001, 0x3308),.driver_info = RTL8188C_8192C},/* D-Link - Alpha */
172         {USB_DEVICE(0x050D, 0x1102),.driver_info = RTL8188C_8192C},/* Belkin - Edimax */
173         {USB_DEVICE(0x2019, 0xAB2A),.driver_info = RTL8188C_8192C},/* Planex - Abocom */
174         {USB_DEVICE(0x20F4, 0x648B),.driver_info = RTL8188C_8192C},/* TRENDnet - Cameo */
175         {USB_DEVICE(0x4855, 0x0090),.driver_info = RTL8188C_8192C},/*  - Feixun */
176         {USB_DEVICE(0x13D3, 0x3357),.driver_info = RTL8188C_8192C},/*  - AzureWave */
177         {USB_DEVICE(0x0DF6, 0x005C),.driver_info = RTL8188C_8192C},/* Sitecom - Edimax */
178         {USB_DEVICE(0x0BDA, 0x5088),.driver_info = RTL8188C_8192C},/* Thinkware - CC&C */
179         {USB_DEVICE(0x4856, 0x0091),.driver_info = RTL8188C_8192C},/* NetweeN - Feixun */
180         {USB_DEVICE(0x0846, 0x9041),.driver_info = RTL8188C_8192C}, /* Netgear - Cameo */
181         {USB_DEVICE(0x2019, 0x4902),.driver_info = RTL8188C_8192C},/* Planex - Etop */
182         {USB_DEVICE(0x2019, 0xAB2E),.driver_info = RTL8188C_8192C},/* SW-WF02-AD15 -Abocom */
183         {USB_DEVICE(0x2001, 0x330B),.driver_info = RTL8188C_8192C}, /* D-LINK - T&W */
184         {USB_DEVICE(0xCDAB, 0x8010),.driver_info = RTL8188C_8192C}, /* - - compare */
185         {USB_DEVICE(0x0B05, 0x17BA),.driver_info = RTL8188C_8192C}, /* ASUS - Edimax */
186         {USB_DEVICE(0x0BDA, 0x1E1E),.driver_info = RTL8188C_8192C}, /* Intel - - */
187         {USB_DEVICE(0x04BB, 0x094c),.driver_info = RTL8188C_8192C}, /* I-O DATA - Edimax */
188         /****** 8188CTV ********/
189         {USB_DEVICE(0xCDAB, 0x8011),.driver_info = RTL8188C_8192C}, /* - - compare */
190         {USB_DEVICE(0x0BDA, 0x0A8A),.driver_info = RTL8188C_8192C}, /* Sony - Foxconn */
191         /****** 8188 RU ********/
192         {USB_DEVICE(0x0BDA, 0x317F),.driver_info = RTL8188C_8192C},/* Netcore,Netcore */
193         /****** 8188CE-VAU ********/
194         {USB_DEVICE(0x13D3, 0x3359),.driver_info = RTL8188C_8192C},/*  - Azwave */
195         {USB_DEVICE(0x13D3, 0x3358),.driver_info = RTL8188C_8192C},/*  - Azwave */
196         /****** 8188CUS Slim Solo********/
197         {USB_DEVICE(0x04F2, 0xAFF7),.driver_info = RTL8188C_8192C},/* XAVI - XAVI */
198         {USB_DEVICE(0x04F2, 0xAFF9),.driver_info = RTL8188C_8192C},/* XAVI - XAVI */
199         {USB_DEVICE(0x04F2, 0xAFFA),.driver_info = RTL8188C_8192C},/* XAVI - XAVI */
200         /****** 8188CUS Slim Combo ********/
201         {USB_DEVICE(0x04F2, 0xAFF8),.driver_info = RTL8188C_8192C},/* XAVI - XAVI */
202         {USB_DEVICE(0x04F2, 0xAFFB),.driver_info = RTL8188C_8192C},/* XAVI - XAVI */
203         {USB_DEVICE(0x04F2, 0xAFFC),.driver_info = RTL8188C_8192C},/* XAVI - XAVI */
204         {USB_DEVICE(0x2019, 0x1201),.driver_info = RTL8188C_8192C},/* Planex - Vencer */
205         /****** 8192CUS Dongle ********/
206         {USB_DEVICE(0x2001, 0x3307),.driver_info = RTL8188C_8192C},/* D-Link - Cameo */
207         {USB_DEVICE(0x2001, 0x330A),.driver_info = RTL8188C_8192C},/* D-Link - Alpha */
208         {USB_DEVICE(0x2001, 0x3309),.driver_info = RTL8188C_8192C},/* D-Link - Alpha */
209         {USB_DEVICE(0x0586, 0x341F),.driver_info = RTL8188C_8192C},/* Zyxel - Abocom */
210         {USB_DEVICE(0x7392, 0x7822),.driver_info = RTL8188C_8192C},/* Edimax - Edimax */
211         {USB_DEVICE(0x2019, 0xAB2B),.driver_info = RTL8188C_8192C},/* Planex - Abocom */
212         {USB_DEVICE(0x07B8, 0x8178),.driver_info = RTL8188C_8192C},/* Abocom - Abocom */
213         {USB_DEVICE(0x07AA, 0x0056),.driver_info = RTL8188C_8192C},/* ATKK - Gemtek */
214         {USB_DEVICE(0x4855, 0x0091),.driver_info = RTL8188C_8192C},/*  - Feixun */
215         {USB_DEVICE(0x050D, 0x2102),.driver_info = RTL8188C_8192C},/* Belkin - Sercomm */
216         {USB_DEVICE(0x050D, 0x2103),.driver_info = RTL8188C_8192C},/* Belkin - Edimax */
217         {USB_DEVICE(0x20F4, 0x624D),.driver_info = RTL8188C_8192C},/* TRENDnet */
218         {USB_DEVICE(0x0DF6, 0x0061),.driver_info = RTL8188C_8192C},/* Sitecom - Edimax */
219         {USB_DEVICE(0x0B05, 0x17AB),.driver_info = RTL8188C_8192C},/* ASUS - Edimax */
220         {USB_DEVICE(0x0846, 0x9021),.driver_info = RTL8188C_8192C},/* Netgear - Sercomm */
221         {USB_DEVICE(0x0846, 0xF001),.driver_info = RTL8188C_8192C}, /* Netgear - Sercomm */
222         {USB_DEVICE(0x0E66, 0x0019),.driver_info = RTL8188C_8192C},/* Hawking,Edimax */
223         {USB_DEVICE(0x0E66, 0x0020),.driver_info = RTL8188C_8192C}, /* Hawking  - Edimax */
224         {USB_DEVICE(0x050D, 0x1004),.driver_info = RTL8188C_8192C}, /* Belkin - Edimax */
225         {USB_DEVICE(0x0BDA, 0x2E2E),.driver_info = RTL8188C_8192C}, /* Intel - - */
226         {USB_DEVICE(0x2357, 0x0100),.driver_info = RTL8188C_8192C}, /* TP-Link - TP-Link */
227         {USB_DEVICE(0x06F8, 0xE035),.driver_info = RTL8188C_8192C}, /* Hercules - Edimax */
228         {USB_DEVICE(0x04BB, 0x0950),.driver_info = RTL8188C_8192C}, /* IO-DATA - Edimax */
229         {USB_DEVICE(0x0DF6, 0x0070),.driver_info = RTL8188C_8192C}, /* Sitecom - Edimax */
230         {USB_DEVICE(0x0789, 0x016D),.driver_info = RTL8188C_8192C}, /* LOGITEC - Edimax */
231         /****** 8192CE-VAU  ********/
232         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8186),.driver_info = RTL8188C_8192C},/* Intel-Xavi( Azwave) */
233 #endif
234
235 #ifdef CONFIG_RTL8192D
236         /*=== Realtek demoboard ===*/
237         /****** 8192DU ********/
238         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8193),.driver_info = RTL8192D},/* 8192DU-VC */
239         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8194),.driver_info = RTL8192D},/* 8192DU-VS */
240         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8111),.driver_info = RTL8192D},/* Realtek 5G dongle for WiFi Display */
241         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0193),.driver_info = RTL8192D},/* 8192DE-VAU */
242         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8171),.driver_info = RTL8192D},/* 8192DU-VC */
243         /*=== Customer ID ===*/
244         /****** 8192DU-VC ********/
245         {USB_DEVICE(0x2019, 0xAB2C),.driver_info = RTL8192D},/* PCI - Abocm */
246         {USB_DEVICE(0x2019, 0x4903),.driver_info = RTL8192D},/* PCI - ETOP */
247         {USB_DEVICE(0x2019, 0x4904),.driver_info = RTL8192D},/* PCI - ETOP */
248         {USB_DEVICE(0x07B8, 0x8193),.driver_info = RTL8192D},/* Abocom - Abocom */
249         /****** 8192DU-VS ********/
250         {USB_DEVICE(0x20F4, 0x664B),.driver_info = RTL8192D},/* TRENDnet */
251         {USB_DEVICE(0x04DD, 0x954F),.driver_info = RTL8192D},  /* Sharp */
252         {USB_DEVICE(0x04DD, 0x96A6),.driver_info = RTL8192D},  /* Sharp */
253         {USB_DEVICE(0x050D, 0x110A),.driver_info = RTL8192D}, /* Belkin - Edimax */
254         {USB_DEVICE(0x050D, 0x1105),.driver_info = RTL8192D}, /* Belkin - Edimax */
255         {USB_DEVICE(0x050D, 0x120A),.driver_info = RTL8192D}, /* Belkin - Edimax */
256         {USB_DEVICE(0x1668, 0x8102),.driver_info = RTL8192D}, /*  -  */
257         {USB_DEVICE(0x0BDA, 0xE194),.driver_info = RTL8192D}, /*  - Edimax */
258         /****** 8192DU-WiFi Display Dongle ********/
259         {USB_DEVICE(0x2019, 0xAB2D),.driver_info = RTL8192D},/* Planex - Abocom ,5G dongle for WiFi Display */
260 #endif
261
262 #ifdef CONFIG_RTL8723A
263         {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x8724,0xff,0xff,0xff),.driver_info = RTL8723A}, /* 8723AU 1*1 */
264         {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x1724,0xff,0xff,0xff),.driver_info = RTL8723A}, /* 8723AU 1*1 */
265         {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x0724,0xff,0xff,0xff),.driver_info = RTL8723A}, /* 8723AU 1*1 */
266 #endif
267
268 #ifdef CONFIG_RTL8188E
269         /*=== Realtek demoboard ===*/
270         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8179),.driver_info = RTL8188E}, /* 8188EUS */
271         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0179),.driver_info = RTL8188E}, /* 8188ETV */
272         /*=== Customer ID ===*/
273         /****** 8188EUS ********/
274         {USB_DEVICE(0x07B8, 0x8179),.driver_info = RTL8188E}, /* Abocom - Abocom */
275 #endif
276
277 #ifdef CONFIG_RTL8812A
278         /*=== Realtek demoboard ===*/
279         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8812),.driver_info = RTL8812},/* Default ID */
280         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881A),.driver_info = RTL8812},/* Default ID */
281         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881B),.driver_info = RTL8812},/* Default ID */
282         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881C),.driver_info = RTL8812},/* Default ID */
283         /*=== Customer ID ===*/
284         {USB_DEVICE(0x050D, 0x1106),.driver_info = RTL8812}, /* Belkin - sercomm */
285         {USB_DEVICE(0x2001, 0x330E),.driver_info = RTL8812}, /* D-Link - ALPHA */
286         {USB_DEVICE(0x7392, 0xA822),.driver_info = RTL8812}, /* Edimax - Edimax */
287         {USB_DEVICE(0x0DF6, 0x0074),.driver_info = RTL8812}, /* Sitecom - Edimax */
288         {USB_DEVICE(0x04BB, 0x0952),.driver_info = RTL8812}, /* I-O DATA - Edimax */
289         {USB_DEVICE(0x0789, 0x016E),.driver_info = RTL8812}, /* Logitec - Edimax */
290         {USB_DEVICE(0x0409, 0x0408),.driver_info = RTL8812}, /* NEC - */
291         {USB_DEVICE(0x0B05, 0x17D2),.driver_info = RTL8812}, /* ASUS - Edimax */
292         {USB_DEVICE(0x0E66, 0x0022),.driver_info = RTL8812}, /* HAWKING - Edimax */
293         {USB_DEVICE(0x0586, 0x3426),.driver_info = RTL8812}, /* ZyXEL - */
294         {USB_DEVICE(0x2001, 0x3313),.driver_info = RTL8812}, /* D-Link - ALPHA */
295         {USB_DEVICE(0x1058, 0x0632),.driver_info = RTL8812}, /* WD - Cybertan*/
296         {USB_DEVICE(0x1740, 0x0100),.driver_info = RTL8812}, /* EnGenius - EnGenius */
297         {USB_DEVICE(0x2019, 0xAB30),.driver_info = RTL8812}, /* Planex - Abocom */
298         {USB_DEVICE(0x07B8, 0x8812),.driver_info = RTL8812}, /* Abocom - Abocom */
299         {USB_DEVICE(0x2001, 0x3315),.driver_info = RTL8812}, /* D-Link - Cameo */
300         {USB_DEVICE(0x2001, 0x3316),.driver_info = RTL8812}, /* D-Link - Cameo */
301 #endif
302
303 #ifdef CONFIG_RTL8821A
304         /*=== Realtek demoboard ===*/
305         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0811),.driver_info = RTL8821},/* Default ID */
306         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0821),.driver_info = RTL8821},/* Default ID */
307         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8822),.driver_info = RTL8821},/* Default ID */
308         {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0820),.driver_info = RTL8821},/* Default ID */
309         /*=== Customer ID ===*/
310         {USB_DEVICE(0x7392, 0xA811),.driver_info = RTL8821}, /* Edimax - Edimax */
311         {USB_DEVICE(0x04BB, 0x0953),.driver_info = RTL8821}, /* I-O DATA - Edimax */
312         {USB_DEVICE(0x2001, 0x3314),.driver_info = RTL8821}, /* D-Link - Cameo */
313         {USB_DEVICE(0x2001, 0x3318),.driver_info = RTL8821}, /* D-Link - Cameo */
314         {USB_DEVICE(0x0E66, 0x0023),.driver_info = RTL8821}, /* HAWKING - Edimax */
315 #endif
316
317 #ifdef CONFIG_RTL8192E
318         /*=== Realtek demoboard ===*/
319         {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x818B,0xff,0xff,0xff),.driver_info = RTL8192E},/* Default ID */
320         {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x818C,0xff,0xff,0xff),.driver_info = RTL8192E},/* Default ID */
321 #endif
322
323 #ifdef CONFIG_RTL8723B
324         //*=== Realtek demoboard ===*/
325         {USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB720,0xff,0xff,0xff),.driver_info = RTL8723B}, /* 8723BU 1*1 */
326         //{USB_DEVICE(USB_VENDER_ID_REALTEK, 0xB720),.driver_info = RTL8723B}, /* 8723BU */
327 #endif
328         {}      /* Terminating entry */
329 };
330
331 MODULE_DEVICE_TABLE(usb, rtw_usb_id_tbl);
332
333 int const rtw_usb_id_len = sizeof(rtw_usb_id_tbl) / sizeof(struct usb_device_id);
334
335 static struct specific_device_id specific_device_id_tbl[] = {
336         {.idVendor=USB_VENDER_ID_REALTEK, .idProduct=0x8177, .flags=SPEC_DEV_ID_DISABLE_HT},//8188cu 1*1 dongole, (b/g mode only)
337         {.idVendor=USB_VENDER_ID_REALTEK, .idProduct=0x817E, .flags=SPEC_DEV_ID_DISABLE_HT},//8188CE-VAU USB minCard (b/g mode only)
338         {.idVendor=0x0b05, .idProduct=0x1791, .flags=SPEC_DEV_ID_DISABLE_HT},
339         {.idVendor=0x13D3, .idProduct=0x3311, .flags=SPEC_DEV_ID_DISABLE_HT},
340         {.idVendor=0x13D3, .idProduct=0x3359, .flags=SPEC_DEV_ID_DISABLE_HT},//Russian customer -Azwave (8188CE-VAU  g mode)
341 #ifdef RTK_DMP_PLATFORM
342         {.idVendor=USB_VENDER_ID_REALTEK, .idProduct=0x8111, .flags=SPEC_DEV_ID_ASSIGN_IFNAME}, // Realtek 5G dongle for WiFi Display
343         {.idVendor=0x2019, .idProduct=0xAB2D, .flags=SPEC_DEV_ID_ASSIGN_IFNAME}, // PCI-Abocom 5G dongle for WiFi Display
344 #endif /* RTK_DMP_PLATFORM */
345         {}
346 };
347
348 struct rtw_usb_drv {
349         struct usb_driver usbdrv;
350         int drv_registered;
351         u8 hw_type;
352 };
353
354 struct rtw_usb_drv usb_drv = {
355         .usbdrv.name =(char*)DRV_NAME,
356         .usbdrv.probe = rtw_drv_init,
357         .usbdrv.disconnect = rtw_dev_remove,
358         .usbdrv.id_table = rtw_usb_id_tbl,
359         .usbdrv.suspend =  rtw_suspend,
360         .usbdrv.resume = rtw_resume,
361         #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
362         .usbdrv.reset_resume   = rtw_resume,
363         #endif
364         #ifdef CONFIG_AUTOSUSPEND
365         .usbdrv.supports_autosuspend = 1,
366         #endif
367
368         #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19))
369         .usbdrv.drvwrap.driver.shutdown = rtw_dev_shutdown,
370         #else
371         .usbdrv.driver.shutdown = rtw_dev_shutdown,
372         #endif
373 };
374
375 static inline int RT_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
376 {
377         return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
378 }
379
380 static inline int RT_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)
381 {
382         return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
383 }
384
385 static inline int RT_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
386 {
387         return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT);
388 }
389
390 static inline int RT_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
391 {
392         return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK);
393 }
394
395 static inline int RT_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
396 {
397         return (RT_usb_endpoint_xfer_bulk(epd) && RT_usb_endpoint_dir_in(epd));
398 }
399
400 static inline int RT_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
401 {
402         return (RT_usb_endpoint_xfer_bulk(epd) && RT_usb_endpoint_dir_out(epd));
403 }
404
405 static inline int RT_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
406 {
407         return (RT_usb_endpoint_xfer_int(epd) && RT_usb_endpoint_dir_in(epd));
408 }
409
410 static inline int RT_usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
411 {
412         return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
413 }
414
415 static u8 rtw_init_intf_priv(struct dvobj_priv *dvobj)
416 {
417         u8 rst = _SUCCESS;
418
419         #ifdef CONFIG_USB_VENDOR_REQ_MUTEX
420         _rtw_mutex_init(&dvobj->usb_vendor_req_mutex);
421         #endif
422
423
424         #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
425         dvobj->usb_alloc_vendor_req_buf = rtw_zmalloc(MAX_USB_IO_CTL_SIZE);
426         if (dvobj->usb_alloc_vendor_req_buf == NULL) {
427                 DBG_871X("alloc usb_vendor_req_buf failed... /n");
428                 rst = _FAIL;
429                 goto exit;
430         }
431         dvobj->usb_vendor_req_buf  =
432                 (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(dvobj->usb_alloc_vendor_req_buf ), ALIGNMENT_UNIT);
433 exit:
434         #endif
435
436         return rst;
437
438 }
439
440 static u8 rtw_deinit_intf_priv(struct dvobj_priv *dvobj)
441 {
442         u8 rst = _SUCCESS;
443
444         #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
445         if(dvobj->usb_vendor_req_buf)
446                 rtw_mfree(dvobj->usb_alloc_vendor_req_buf, MAX_USB_IO_CTL_SIZE);
447         #endif
448
449         #ifdef CONFIG_USB_VENDOR_REQ_MUTEX
450         _rtw_mutex_free(&dvobj->usb_vendor_req_mutex);
451         #endif
452
453         return rst;
454 }
455
456 static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)
457 {
458         int     i;
459         u8      val8;
460         int     status = _FAIL;
461         struct dvobj_priv *pdvobjpriv;
462         struct usb_device_descriptor    *pdev_desc;
463         struct usb_host_config                  *phost_conf;
464         struct usb_config_descriptor            *pconf_desc;
465         struct usb_host_interface               *phost_iface;
466         struct usb_interface_descriptor *piface_desc;
467         struct usb_host_endpoint                *phost_endp;
468         struct usb_endpoint_descriptor  *pendp_desc;
469         struct usb_device                               *pusbd;
470
471 _func_enter_;
472
473
474         if((pdvobjpriv = devobj_init()) == NULL) {
475                 goto exit;
476         }
477
478
479         pdvobjpriv->pusbintf = usb_intf ;
480         pusbd = pdvobjpriv->pusbdev = interface_to_usbdev(usb_intf);
481         usb_set_intfdata(usb_intf, pdvobjpriv);
482
483         pdvobjpriv->RtNumInPipes = 0;
484         pdvobjpriv->RtNumOutPipes = 0;
485
486         //padapter->EepromAddressSize = 6;
487         //pdvobjpriv->nr_endpoint = 6;
488
489         pdev_desc = &pusbd->descriptor;
490
491 #if 0
492         DBG_871X("\n8712_usb_device_descriptor:\n");
493         DBG_871X("bLength=%x\n", pdev_desc->bLength);
494         DBG_871X("bDescriptorType=%x\n", pdev_desc->bDescriptorType);
495         DBG_871X("bcdUSB=%x\n", pdev_desc->bcdUSB);
496         DBG_871X("bDeviceClass=%x\n", pdev_desc->bDeviceClass);
497         DBG_871X("bDeviceSubClass=%x\n", pdev_desc->bDeviceSubClass);
498         DBG_871X("bDeviceProtocol=%x\n", pdev_desc->bDeviceProtocol);
499         DBG_871X("bMaxPacketSize0=%x\n", pdev_desc->bMaxPacketSize0);
500         DBG_871X("idVendor=%x\n", pdev_desc->idVendor);
501         DBG_871X("idProduct=%x\n", pdev_desc->idProduct);
502         DBG_871X("bcdDevice=%x\n", pdev_desc->bcdDevice);
503         DBG_871X("iManufacturer=%x\n", pdev_desc->iManufacturer);
504         DBG_871X("iProduct=%x\n", pdev_desc->iProduct);
505         DBG_871X("iSerialNumber=%x\n", pdev_desc->iSerialNumber);
506         DBG_871X("bNumConfigurations=%x\n", pdev_desc->bNumConfigurations);
507 #endif
508
509         phost_conf = pusbd->actconfig;
510         pconf_desc = &phost_conf->desc;
511
512 #if 0
513         DBG_871X("\n8712_usb_configuration_descriptor:\n");
514         DBG_871X("bLength=%x\n", pconf_desc->bLength);
515         DBG_871X("bDescriptorType=%x\n", pconf_desc->bDescriptorType);
516         DBG_871X("wTotalLength=%x\n", pconf_desc->wTotalLength);
517         DBG_871X("bNumInterfaces=%x\n", pconf_desc->bNumInterfaces);
518         DBG_871X("bConfigurationValue=%x\n", pconf_desc->bConfigurationValue);
519         DBG_871X("iConfiguration=%x\n", pconf_desc->iConfiguration);
520         DBG_871X("bmAttributes=%x\n", pconf_desc->bmAttributes);
521         DBG_871X("bMaxPower=%x\n", pconf_desc->bMaxPower);
522 #endif
523
524         //DBG_871X("\n/****** num of altsetting = (%d) ******/\n", pusb_interface->num_altsetting);
525
526         phost_iface = &usb_intf->altsetting[0];
527         piface_desc = &phost_iface->desc;
528
529 #if 0
530         DBG_871X("\n8712_usb_interface_descriptor:\n");
531         DBG_871X("bLength=%x\n", piface_desc->bLength);
532         DBG_871X("bDescriptorType=%x\n", piface_desc->bDescriptorType);
533         DBG_871X("bInterfaceNumber=%x\n", piface_desc->bInterfaceNumber);
534         DBG_871X("bAlternateSetting=%x\n", piface_desc->bAlternateSetting);
535         DBG_871X("bNumEndpoints=%x\n", piface_desc->bNumEndpoints);
536         DBG_871X("bInterfaceClass=%x\n", piface_desc->bInterfaceClass);
537         DBG_871X("bInterfaceSubClass=%x\n", piface_desc->bInterfaceSubClass);
538         DBG_871X("bInterfaceProtocol=%x\n", piface_desc->bInterfaceProtocol);
539         DBG_871X("iInterface=%x\n", piface_desc->iInterface);
540 #endif
541
542         pdvobjpriv->NumInterfaces = pconf_desc->bNumInterfaces;
543         pdvobjpriv->InterfaceNumber = piface_desc->bInterfaceNumber;
544         pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
545
546         //DBG_871X("\ndump usb_endpoint_descriptor:\n");
547
548         for (i = 0; i < pdvobjpriv->nr_endpoint; i++)
549         {
550                 phost_endp = phost_iface->endpoint + i;
551                 if (phost_endp)
552                 {
553                         pendp_desc = &phost_endp->desc;
554
555                         DBG_871X("\nusb_endpoint_descriptor(%d):\n", i);
556                         DBG_871X("bLength=%x\n",pendp_desc->bLength);
557                         DBG_871X("bDescriptorType=%x\n",pendp_desc->bDescriptorType);
558                         DBG_871X("bEndpointAddress=%x\n",pendp_desc->bEndpointAddress);
559                         //DBG_871X("bmAttributes=%x\n",pendp_desc->bmAttributes);
560                         DBG_871X("wMaxPacketSize=%d\n",le16_to_cpu(pendp_desc->wMaxPacketSize));
561                         DBG_871X("bInterval=%x\n",pendp_desc->bInterval);
562                         //DBG_871X("bRefresh=%x\n",pendp_desc->bRefresh);
563                         //DBG_871X("bSynchAddress=%x\n",pendp_desc->bSynchAddress);
564
565                         if (RT_usb_endpoint_is_bulk_in(pendp_desc))
566                         {
567                                 DBG_871X("RT_usb_endpoint_is_bulk_in = %x\n", RT_usb_endpoint_num(pendp_desc));
568                                 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = RT_usb_endpoint_num(pendp_desc);
569                                 pdvobjpriv->RtNumInPipes++;
570                         }
571                         else if (RT_usb_endpoint_is_int_in(pendp_desc))
572                         {
573                                 DBG_871X("RT_usb_endpoint_is_int_in = %x, Interval = %x\n", RT_usb_endpoint_num(pendp_desc),pendp_desc->bInterval);
574                                 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = RT_usb_endpoint_num(pendp_desc);
575                                 pdvobjpriv->RtNumInPipes++;
576                         }
577                         else if (RT_usb_endpoint_is_bulk_out(pendp_desc))
578                         {
579                                 DBG_871X("RT_usb_endpoint_is_bulk_out = %x\n", RT_usb_endpoint_num(pendp_desc));
580                                 pdvobjpriv->RtOutPipe[pdvobjpriv->RtNumOutPipes] = RT_usb_endpoint_num(pendp_desc);
581                                 pdvobjpriv->RtNumOutPipes++;
582                         }
583                         pdvobjpriv->ep_num[i] = RT_usb_endpoint_num(pendp_desc);
584                 }
585         }
586
587         DBG_871X("nr_endpoint=%d, in_num=%d, out_num=%d\n\n", pdvobjpriv->nr_endpoint, pdvobjpriv->RtNumInPipes, pdvobjpriv->RtNumOutPipes);
588
589         switch(pusbd->speed) {
590                 case USB_SPEED_LOW:
591                         DBG_871X("USB_SPEED_LOW\n");
592                         pdvobjpriv->usb_speed = RTW_USB_SPEED_1_1;
593                         break;
594                 case USB_SPEED_FULL:
595                         DBG_871X("USB_SPEED_FULL\n");
596                         pdvobjpriv->usb_speed = RTW_USB_SPEED_1_1;
597                         break;
598                 case USB_SPEED_HIGH:
599                         DBG_871X("USB_SPEED_HIGH\n");
600                         pdvobjpriv->usb_speed = RTW_USB_SPEED_2;
601                         break;
602 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31))
603                 case USB_SPEED_SUPER:
604                         DBG_871X("USB_SPEED_SUPER\n");
605                         pdvobjpriv->usb_speed = RTW_USB_SPEED_3;
606                         break;
607 #endif
608                 default:
609                         DBG_871X("USB_SPEED_UNKNOWN(%x)\n",pusbd->speed);
610                         pdvobjpriv->usb_speed = RTW_USB_SPEED_UNKNOWN;
611                         break;
612         }
613
614         if (pdvobjpriv->usb_speed == RTW_USB_SPEED_UNKNOWN) {
615                 DBG_871X("UNKNOWN USB SPEED MODE, ERROR !!!\n");
616                 goto free_dvobj;
617         }
618
619         if (rtw_init_intf_priv(pdvobjpriv) == _FAIL) {
620                 RT_TRACE(_module_os_intfs_c_,_drv_err_,("\n Can't INIT rtw_init_intf_priv\n"));
621                 goto free_dvobj;
622         }
623
624         //.3 misc
625         _rtw_init_sema(&(pdvobjpriv->usb_suspend_sema), 0);
626         rtw_reset_continual_io_error(pdvobjpriv);
627
628         usb_get_dev(pusbd);
629
630         status = _SUCCESS;
631
632 free_dvobj:
633         if (status != _SUCCESS && pdvobjpriv) {
634                 usb_set_intfdata(usb_intf, NULL);
635                 
636                 devobj_deinit(pdvobjpriv);
637                 
638                 pdvobjpriv = NULL;
639         }
640 exit:
641 _func_exit_;
642         return pdvobjpriv;
643 }
644
645 static void usb_dvobj_deinit(struct usb_interface *usb_intf)
646 {
647         struct dvobj_priv *dvobj = usb_get_intfdata(usb_intf);
648
649 _func_enter_;
650
651         usb_set_intfdata(usb_intf, NULL);
652         if (dvobj) {
653                 //Modify condition for 92DU DMDP 2010.11.18, by Thomas
654                 if ((dvobj->NumInterfaces != 2 && dvobj->NumInterfaces != 3)
655                         || (dvobj->InterfaceNumber == 1)) {
656                         if (interface_to_usbdev(usb_intf)->state != USB_STATE_NOTATTACHED) {
657                                 //If we didn't unplug usb dongle and remove/insert modlue, driver fails on sitesurvey for the first time when device is up .
658                                 //Reset usb port for sitesurvey fail issue. 2009.8.13, by Thomas
659                                 DBG_871X("usb attached..., try to reset usb device\n");
660                                 usb_reset_device(interface_to_usbdev(usb_intf));
661                         }
662                 }
663
664                 rtw_deinit_intf_priv(dvobj);
665         
666                 devobj_deinit(dvobj);           
667         }
668
669         //DBG_871X("%s %d\n", __func__, ATOMIC_READ(&usb_intf->dev.kobj.kref.refcount));
670         usb_put_dev(interface_to_usbdev(usb_intf));
671
672 _func_exit_;
673 }
674
675 static void rtw_decide_chip_type_by_usb_info(_adapter *padapter, const struct usb_device_id *pdid)
676 {
677         padapter->chip_type = pdid->driver_info;
678
679         #ifdef CONFIG_RTL8192C
680         if(padapter->chip_type == RTL8188C_8192C)
681                 rtl8192cu_set_hw_type(padapter);
682         #endif
683
684         #ifdef CONFIG_RTL8192D
685         if(padapter->chip_type == RTL8192D)
686                 rtl8192du_set_hw_type(padapter);
687         #endif
688
689         #ifdef CONFIG_RTL8723A
690         if(padapter->chip_type == RTL8723A)
691                 rtl8723au_set_hw_type(padapter);
692         #endif
693
694         #ifdef CONFIG_RTL8188E
695         if(padapter->chip_type == RTL8188E)
696                 rtl8188eu_set_hw_type(padapter);
697         #endif
698
699         #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
700         if(padapter->chip_type == RTL8812 || padapter->chip_type == RTL8821)
701                 rtl8812au_set_hw_type(padapter);
702         #endif
703
704         #ifdef CONFIG_RTL8192E
705         if(padapter->chip_type == RTL8192E)
706                 rtl8192eu_set_hw_type(padapter);
707         #endif
708
709         #ifdef CONFIG_RTL8723B
710         if(padapter->chip_type == RTL8723B)
711                 rtl8723bu_set_hw_type(padapter);
712         #endif
713
714 }
715 void rtw_set_hal_ops(_adapter *padapter)
716 {
717         #ifdef CONFIG_RTL8192C
718         if(padapter->chip_type == RTL8188C_8192C)
719                 rtl8192cu_set_hal_ops(padapter);
720         #endif
721
722         #ifdef CONFIG_RTL8192D
723         if(padapter->chip_type == RTL8192D)
724                 rtl8192du_set_hal_ops(padapter);
725         #endif
726
727         #ifdef CONFIG_RTL8723A
728         if(padapter->chip_type == RTL8723A)
729                 rtl8723au_set_hal_ops(padapter);
730         #endif
731
732         #ifdef CONFIG_RTL8188E
733         if(padapter->chip_type == RTL8188E)
734                 rtl8188eu_set_hal_ops(padapter);
735         #endif
736
737         #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
738         if(padapter->chip_type == RTL8812 || padapter->chip_type == RTL8821)
739                 rtl8812au_set_hal_ops(padapter);
740         #endif
741
742         #ifdef CONFIG_RTL8192E
743         if(padapter->chip_type == RTL8192E)
744                 rtl8192eu_set_hal_ops(padapter);
745         #endif
746         #ifdef CONFIG_RTL8723B
747         if(padapter->chip_type == RTL8723B)
748                 rtl8723bu_set_hal_ops(padapter);
749         #endif
750 }
751
752 void usb_set_intf_ops(_adapter *padapter,struct _io_ops *pops)
753 {
754         #ifdef CONFIG_RTL8192C
755         if(padapter->chip_type == RTL8188C_8192C)
756                 rtl8192cu_set_intf_ops(pops);
757         #endif
758
759         #ifdef CONFIG_RTL8192D
760         if(padapter->chip_type == RTL8192D)
761                 rtl8192du_set_intf_ops(pops);
762         #endif
763
764         #ifdef CONFIG_RTL8723A
765         if(padapter->chip_type == RTL8723A)
766                 rtl8723au_set_intf_ops(pops);
767         #endif
768
769         #ifdef CONFIG_RTL8188E
770         if(padapter->chip_type == RTL8188E)
771                 rtl8188eu_set_intf_ops(pops);
772         #endif
773
774         #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
775         if(padapter->chip_type == RTL8812 || padapter->chip_type == RTL8821)
776                 rtl8812au_set_intf_ops(pops);
777         #endif
778
779         #ifdef CONFIG_RTL8192E
780         if(padapter->chip_type == RTL8192E)
781                 rtl8192eu_set_intf_ops(pops);
782         #endif
783
784         #ifdef CONFIG_RTL8723B
785         if(padapter->chip_type == RTL8723B)
786                 rtl8723bu_set_intf_ops(pops);
787         #endif
788 }
789
790
791 static void usb_intf_start(_adapter *padapter)
792 {
793
794         RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+usb_intf_start\n"));
795
796         rtw_hal_inirp_init(padapter);
797
798         RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-usb_intf_start\n"));
799
800 }
801
802 static void usb_intf_stop(_adapter *padapter)
803 {
804
805         RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+usb_intf_stop\n"));
806
807         //disabel_hw_interrupt
808         if(padapter->bSurpriseRemoved == _FALSE)
809         {
810                 //device still exists, so driver can do i/o operation
811                 //TODO:
812                 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("SurpriseRemoved==_FALSE\n"));
813         }
814
815         //cancel in irp
816         rtw_hal_inirp_deinit(padapter);
817
818         //cancel out irp
819         rtw_write_port_cancel(padapter);
820
821         //todo:cancel other irps
822
823         RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-usb_intf_stop\n"));
824
825 }
826
827 static void process_spec_devid(const struct usb_device_id *pdid)
828 {
829         u16 vid, pid;
830         u32 flags;
831         int i;
832         int num = sizeof(specific_device_id_tbl)/sizeof(struct specific_device_id);
833
834         for(i=0; i<num; i++)
835         {
836                 vid = specific_device_id_tbl[i].idVendor;
837                 pid = specific_device_id_tbl[i].idProduct;
838                 flags = specific_device_id_tbl[i].flags;
839
840 #ifdef CONFIG_80211N_HT
841                 if((pdid->idVendor==vid) && (pdid->idProduct==pid) && (flags&SPEC_DEV_ID_DISABLE_HT))
842                 {
843                          rtw_ht_enable = 0;
844                          rtw_bw_mode = 0;
845                          rtw_ampdu_enable = 0;
846                 }
847 #endif
848
849 #ifdef RTK_DMP_PLATFORM
850                 // Change the ifname to wlan10 when PC side WFD dongle plugin on DMP platform.
851                 // It is used to distinguish between normal and PC-side wifi dongle/module.
852                 if((pdid->idVendor==vid) && (pdid->idProduct==pid) && (flags&SPEC_DEV_ID_ASSIGN_IFNAME))
853                 {
854                         extern char* ifname;
855                         strncpy(ifname, "wlan10", 6);
856                         //DBG_871X("%s()-%d: ifname=%s, vid=%04X, pid=%04X\n", __FUNCTION__, __LINE__, ifname, vid, pid);
857                 }
858 #endif /* RTK_DMP_PLATFORM */
859
860         }
861 }
862
863 #ifdef SUPPORT_HW_RFOFF_DETECTED
864 int rtw_hw_suspend(_adapter *padapter )
865 {
866         struct pwrctrl_priv *pwrpriv;
867         struct usb_interface *pusb_intf;
868         struct net_device *pnetdev;
869
870         _func_enter_;
871         if(NULL==padapter)
872                 goto error_exit;
873
874         if((_FALSE==padapter->bup) || (_TRUE == padapter->bDriverStopped)||(_TRUE==padapter->bSurpriseRemoved))
875         {
876                 DBG_871X("padapter->bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n",
877                         padapter->bup, padapter->bDriverStopped,padapter->bSurpriseRemoved);
878                 goto error_exit;
879         }
880         
881         pwrpriv = adapter_to_pwrctl(padapter);
882         pusb_intf = adapter_to_dvobj(padapter)->pusbintf;
883         pnetdev = padapter->pnetdev;
884         
885         LeaveAllPowerSaveMode(padapter);
886
887         DBG_871X("==> rtw_hw_suspend\n");
888         _enter_pwrlock(&pwrpriv->lock);
889         pwrpriv->bips_processing = _TRUE;
890         //padapter->net_closed = _TRUE;
891         //s1.
892         if(pnetdev)
893         {
894                 netif_carrier_off(pnetdev);
895                 rtw_netif_stop_queue(pnetdev);
896         }
897
898         //s2.
899         rtw_disassoc_cmd(padapter, 500, _FALSE);
900
901         //s2-2.  indicate disconnect to os
902         //rtw_indicate_disconnect(padapter);
903         {
904                 struct  mlme_priv *pmlmepriv = &padapter->mlmepriv;
905                 if(check_fwstate(pmlmepriv, _FW_LINKED))
906                 {
907                         _clr_fwstate_(pmlmepriv, _FW_LINKED);
908                         rtw_led_control(padapter, LED_CTL_NO_LINK);
909
910                         rtw_os_indicate_disconnect(padapter);
911
912                         #ifdef CONFIG_LPS
913                         //donnot enqueue cmd
914                         rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_DISCONNECT, 0);
915                         #endif
916                 }
917         }
918         //s2-3.
919         rtw_free_assoc_resources(padapter, 1);
920
921         //s2-4.
922         rtw_free_network_queue(padapter,_TRUE);
923         #ifdef CONFIG_IPS
924         rtw_ips_dev_unload(padapter);
925         #endif
926         pwrpriv->rf_pwrstate = rf_off;
927         pwrpriv->bips_processing = _FALSE;
928         _exit_pwrlock(&pwrpriv->lock);
929         
930         _func_exit_;
931         return 0;
932
933 error_exit:
934         DBG_871X("%s, failed \n",__FUNCTION__);
935         return (-1);
936
937 }
938
939 int rtw_hw_resume(_adapter *padapter)
940 {
941         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
942         struct usb_interface *pusb_intf = adapter_to_dvobj(padapter)->pusbintf;
943         struct net_device *pnetdev = padapter->pnetdev;
944
945         _func_enter_;   
946         DBG_871X("==> rtw_hw_resume\n");
947         _enter_pwrlock(&pwrpriv->lock);
948         pwrpriv->bips_processing = _TRUE;
949         rtw_reset_drv_sw(padapter);
950
951         if(pm_netdev_open(pnetdev,_FALSE) != 0)
952         {
953                 _exit_pwrlock(&pwrpriv->lock);
954                 goto error_exit;
955         }
956
957         netif_device_attach(pnetdev);
958         netif_carrier_on(pnetdev);
959
960         if(!rtw_netif_queue_stopped(pnetdev))
961                 rtw_netif_start_queue(pnetdev);
962         else
963                 rtw_netif_wake_queue(pnetdev);
964
965         pwrpriv->bkeepfwalive = _FALSE;
966         pwrpriv->brfoffbyhw = _FALSE;
967
968         pwrpriv->rf_pwrstate = rf_on;
969         pwrpriv->bips_processing = _FALSE;
970         _exit_pwrlock(&pwrpriv->lock);
971
972         _func_exit_;
973
974         return 0;
975 error_exit:
976         DBG_871X("%s, Open net dev failed \n",__FUNCTION__);
977         return (-1);
978 }
979 #endif
980
981 #ifdef CONFIG_SUSPEND_REFINE    
982 static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
983 {
984         int ret = 0;
985         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
986         _adapter *padapter = dvobj->if1;
987         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
988         if((padapter->bup) || (padapter->bDriverStopped == _FALSE)||(padapter->bSurpriseRemoved == _FALSE))
989         {
990 #ifdef CONFIG_AUTOSUSPEND
991                 if(pwrpriv->bInternalAutoSuspend ){
992
993                         #ifdef SUPPORT_HW_RFOFF_DETECTED
994                         // The FW command register update must after MAC and FW init ready.
995                         if((padapter->bFWReady) && (pwrpriv->bHWPwrPindetect ) && (padapter->registrypriv.usbss_enable ))
996                         {
997                                 u8 bOpen = _TRUE;
998                                 rtw_interface_ps_func(padapter,HAL_USB_SELECT_SUSPEND,&bOpen);
999                                 //rtl8192c_set_FwSelectSuspend_cmd(padapter,_TRUE ,500);//note fw to support hw power down ping detect
1000                         }
1001                         #endif//SUPPORT_HW_RFOFF_DETECTED
1002                 }
1003 #endif//CONFIG_AUTOSUSPEND
1004         }
1005         ret =  rtw_suspend_common(padapter);
1006
1007         return ret;
1008 }
1009 int rtw_resume_process(_adapter *padapter)
1010 {
1011         int ret,pm_cnt = 0;
1012         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1013         
1014         #if defined(CONFIG_BT_COEXIST) && defined(CONFIG_AUTOSUSPEND) //add by amy for 8723as-vau
1015         #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1016         DBG_871X("%s...pm_usage_cnt(%d)  pwrpriv->bAutoResume=%x.  ....\n",__func__,atomic_read(&(adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt)),pwrpriv->bAutoResume);
1017         pm_cnt=atomic_read(&(adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt));
1018         #else
1019         DBG_871X("...pm_usage_cnt(%d).....\n", adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt);
1020         pm_cnt = adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt;
1021         #endif
1022         DBG_871X("pwrpriv->bAutoResume (%x)\n",pwrpriv->bAutoResume );
1023         if( _TRUE == pwrpriv->bAutoResume ){
1024                 pwrpriv->bInternalAutoSuspend = _FALSE;
1025                 pwrpriv->bAutoResume=_FALSE;
1026                 DBG_871X("pwrpriv->bAutoResume (%x)  pwrpriv->bInternalAutoSuspend(%x)\n",pwrpriv->bAutoResume,pwrpriv->bInternalAutoSuspend );
1027
1028         }
1029         #endif //#ifdef CONFIG_BT_COEXIST &CONFIG_AUTOSUSPEND&
1030
1031 #if defined (CONFIG_WOWLAN) || defined (CONFIG_AP_WOWLAN)
1032         /*
1033          * Due to usb wow suspend flow will cancel read/write port via intf_stop and
1034          * bReadPortCancel and bWritePortCancel are set _TRUE in intf_stop.
1035          * But they will not be clear in intf_start during wow resume flow. 
1036          * It should move to os_intf in the feature.
1037          */
1038         RTW_ENABLE_FUNC(padapter, DF_RX_BIT);
1039         RTW_ENABLE_FUNC(padapter, DF_TX_BIT);
1040 #endif
1041
1042         ret =  rtw_resume_common(padapter);
1043
1044         #ifdef CONFIG_AUTOSUSPEND
1045         if(pwrpriv->bInternalAutoSuspend )
1046         {
1047                 #ifdef SUPPORT_HW_RFOFF_DETECTED
1048                         // The FW command register update must after MAC and FW init ready.
1049                 if((padapter->bFWReady) && (pwrpriv->bHWPwrPindetect) && (padapter->registrypriv.usbss_enable ))
1050                 {
1051                         //rtl8192c_set_FwSelectSuspend_cmd(padapter,_FALSE ,500);//note fw to support hw power down ping detect
1052                         u8 bOpen = _FALSE;
1053                         rtw_interface_ps_func(padapter,HAL_USB_SELECT_SUSPEND,&bOpen);
1054                 }       
1055                 #endif
1056                 #ifdef CONFIG_BT_COEXIST // for 8723as-vau
1057                 DBG_871X("pwrpriv->bAutoResume (%x)\n",pwrpriv->bAutoResume );
1058                 if( _TRUE == pwrpriv->bAutoResume ){
1059                 pwrpriv->bInternalAutoSuspend = _FALSE;
1060                         pwrpriv->bAutoResume=_FALSE;
1061                         DBG_871X("pwrpriv->bAutoResume (%x)  pwrpriv->bInternalAutoSuspend(%x)\n",pwrpriv->bAutoResume,pwrpriv->bInternalAutoSuspend );
1062                 }
1063
1064                 #else   //#ifdef CONFIG_BT_COEXIST
1065                 pwrpriv->bInternalAutoSuspend = _FALSE;
1066                 #endif  //#ifdef CONFIG_BT_COEXIST
1067                 pwrpriv->brfoffbyhw = _FALSE;
1068         }
1069         #endif//CONFIG_AUTOSUSPEND
1070
1071
1072         return ret;
1073 }
1074 #else
1075 static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
1076 {
1077         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
1078         _adapter *padapter = dvobj->if1;
1079         struct net_device *pnetdev = padapter->pnetdev;
1080         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1081         struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
1082         struct usb_device *usb_dev = interface_to_usbdev(pusb_intf);
1083         
1084 #ifdef CONFIG_WOWLAN
1085         struct wowlan_ioctl_param poidparam;
1086 #endif // CONFIG_WOWLAN
1087
1088         int ret = 0;
1089         u32 start_time = rtw_get_current_time();
1090
1091         _func_enter_;
1092
1093         DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid);
1094
1095 #ifdef CONFIG_WOWLAN
1096         if (check_fwstate(pmlmepriv, _FW_LINKED))
1097                 pwrpriv->wowlan_mode = _TRUE;
1098         else
1099                 pwrpriv->wowlan_mode = _FALSE;
1100 #endif
1101
1102 #ifdef CONFIG_IOL_READ_EFUSE_MAP
1103         if(!padapter->bup){
1104                 u8 bMacPwrCtrlOn = _FALSE;
1105                 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
1106                 if(bMacPwrCtrlOn)
1107                         rtw_hal_power_off(padapter);
1108         }
1109 #endif
1110
1111         if((!padapter->bup) || (padapter->bDriverStopped)||(padapter->bSurpriseRemoved))
1112         {
1113                 DBG_871X("padapter->bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n",
1114                         padapter->bup, padapter->bDriverStopped,padapter->bSurpriseRemoved);
1115                 goto exit;
1116         }
1117
1118         if(pwrpriv->bInternalAutoSuspend )
1119         {
1120         #ifdef CONFIG_AUTOSUSPEND
1121         #ifdef SUPPORT_HW_RFOFF_DETECTED
1122                 // The FW command register update must after MAC and FW init ready.
1123                 if((padapter->bFWReady) && (pwrpriv->bHWPwrPindetect ) && (padapter->registrypriv.usbss_enable ))
1124                 {
1125                         u8 bOpen = _TRUE;
1126                         rtw_interface_ps_func(padapter,HAL_USB_SELECT_SUSPEND,&bOpen);
1127                         //rtl8192c_set_FwSelectSuspend_cmd(padapter,_TRUE ,500);//note fw to support hw power down ping detect
1128                 }
1129         #endif
1130         #endif
1131         }
1132         pwrpriv->bInSuspend = _TRUE;
1133         rtw_cancel_all_timer(padapter);
1134         LeaveAllPowerSaveMode(padapter);
1135
1136         rtw_stop_cmd_thread(padapter);
1137
1138         _enter_pwrlock(&pwrpriv->lock);
1139         //padapter->net_closed = _TRUE;
1140         //s1.
1141         if(pnetdev)
1142         {
1143                 netif_carrier_off(pnetdev);
1144                 rtw_netif_stop_queue(pnetdev);
1145         }
1146
1147 #ifdef CONFIG_WOWLAN
1148         if(pwrpriv->bSupportRemoteWakeup==_TRUE && pwrpriv->wowlan_mode==_TRUE){
1149                 if (rtw_port_switch_chk(padapter))
1150                         rtw_hal_set_hwreg(padapter, HW_VAR_PORT_SWITCH, NULL);
1151
1152                 //set H2C command
1153                 poidparam.subcode=WOWLAN_ENABLE;
1154                 padapter->HalFunc.SetHwRegHandler(padapter,HW_VAR_WOWLAN,(u8 *)&poidparam);
1155         }
1156         else
1157 #else
1158         {
1159         //s2.
1160         rtw_disassoc_cmd(padapter, 0, _FALSE);
1161         }
1162 #endif //CONFIG_WOWLAN
1163
1164         if (rtw_chk_roam_flags(padapter, RTW_ROAM_ON_RESUME)) {
1165                 if(check_fwstate(pmlmepriv, WIFI_STATION_STATE)
1166                         && check_fwstate(pmlmepriv, _FW_LINKED))
1167                 {
1168                         //DBG_871X("%s:%d assoc_ssid:%s\n", __FUNCTION__, __LINE__, pmlmepriv->assoc_ssid.Ssid);
1169                         DBG_871X("%s:%d %s(" MAC_FMT "), length:%d assoc_ssid.length:%d\n",__FUNCTION__, __LINE__,
1170                                         pmlmepriv->cur_network.network.Ssid.Ssid,
1171                                         MAC_ARG(pmlmepriv->cur_network.network.MacAddress),
1172                                         pmlmepriv->cur_network.network.Ssid.SsidLength,
1173                                         pmlmepriv->assoc_ssid.SsidLength);
1174
1175                         rtw_set_to_roam(padapter, 1);
1176                 }
1177         }
1178
1179         //s2-2.  indicate disconnect to os
1180         rtw_indicate_disconnect(padapter);
1181         //s2-3.
1182         rtw_free_assoc_resources(padapter, 1);
1183 #ifdef CONFIG_AUTOSUSPEND
1184         if(!pwrpriv->bInternalAutoSuspend )
1185 #endif
1186         //s2-4.
1187         rtw_free_network_queue(padapter, _TRUE);
1188
1189         rtw_dev_unload(padapter);
1190 #ifdef CONFIG_AUTOSUSPEND
1191         pwrpriv->rf_pwrstate = rf_off;
1192         pwrpriv->bips_processing = _FALSE;
1193 #endif
1194         _exit_pwrlock(&pwrpriv->lock);
1195
1196         if(check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
1197                 rtw_indicate_scan_done(padapter, 1);
1198
1199         if(check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
1200                 rtw_indicate_disconnect(padapter);
1201
1202 exit:
1203         DBG_871X("<===  %s return %d.............. in %dms\n", __FUNCTION__
1204                 , ret, rtw_get_passing_time_ms(start_time));
1205
1206         _func_exit_;
1207         return ret;
1208 }
1209
1210
1211 int rtw_resume_process(_adapter *padapter)
1212 {
1213         struct net_device *pnetdev;
1214         struct pwrctrl_priv *pwrpriv = NULL;
1215         int ret = -1;
1216         u32 start_time = rtw_get_current_time();
1217 #ifdef CONFIG_BT_COEXIST
1218         u8 pm_cnt;
1219 #endif  //#ifdef CONFIG_BT_COEXIST
1220         _func_enter_;
1221
1222         DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid);
1223
1224         if(padapter) {
1225                 pnetdev= padapter->pnetdev;
1226                 pwrpriv = adapter_to_pwrctl(padapter);
1227         } else {
1228                 goto exit;
1229         }
1230
1231         _enter_pwrlock(&pwrpriv->lock);
1232 #ifdef CONFIG_BT_COEXIST
1233 #ifdef CONFIG_AUTOSUSPEND
1234         #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1235         DBG_871X("%s...pm_usage_cnt(%d)  pwrpriv->bAutoResume=%x.  ....\n",__func__,atomic_read(&(adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt)),pwrpriv->bAutoResume);
1236         pm_cnt=atomic_read(&(adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt));
1237         #else
1238         DBG_871X("...pm_usage_cnt(%d).....\n", adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt);
1239         pm_cnt = adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt;
1240         #endif
1241
1242         DBG_871X("pwrpriv->bAutoResume (%x)\n",pwrpriv->bAutoResume );
1243         if( _TRUE == pwrpriv->bAutoResume ){
1244                 pwrpriv->bInternalAutoSuspend = _FALSE;
1245                 pwrpriv->bAutoResume=_FALSE;
1246                 DBG_871X("pwrpriv->bAutoResume (%x)  pwrpriv->bInternalAutoSuspend(%x)\n",pwrpriv->bAutoResume,pwrpriv->bInternalAutoSuspend );
1247
1248         }
1249 #endif //#ifdef CONFIG_AUTOSUSPEND
1250 #endif //#ifdef CONFIG_BT_COEXIST
1251         rtw_reset_drv_sw(padapter);
1252         pwrpriv->bkeepfwalive = _FALSE;
1253
1254         DBG_871X("bkeepfwalive(%x)\n",pwrpriv->bkeepfwalive);
1255         if(pm_netdev_open(pnetdev,_TRUE) != 0){
1256                 _exit_pwrlock(&pwrpriv->lock);
1257                 goto exit;
1258         }
1259         
1260         netif_device_attach(pnetdev);
1261         netif_carrier_on(pnetdev);
1262
1263 #ifdef CONFIG_AUTOSUSPEND
1264         if(pwrpriv->bInternalAutoSuspend )
1265         {
1266                 #ifdef CONFIG_AUTOSUSPEND
1267                 #ifdef SUPPORT_HW_RFOFF_DETECTED
1268                         // The FW command register update must after MAC and FW init ready.
1269                 if((padapter->bFWReady) && (pwrpriv->bHWPwrPindetect) && (padapter->registrypriv.usbss_enable ))
1270                 {
1271                         //rtl8192c_set_FwSelectSuspend_cmd(padapter,_FALSE ,500);//note fw to support hw power down ping detect
1272                         u8 bOpen = _FALSE;
1273                         rtw_interface_ps_func(padapter,HAL_USB_SELECT_SUSPEND,&bOpen);
1274                 }
1275                 #endif
1276                 #endif
1277 #ifdef CONFIG_BT_COEXIST
1278                 DBG_871X("pwrpriv->bAutoResume (%x)\n",pwrpriv->bAutoResume );
1279                 if( _TRUE == pwrpriv->bAutoResume ){
1280                 pwrpriv->bInternalAutoSuspend = _FALSE;
1281                         pwrpriv->bAutoResume=_FALSE;
1282                         DBG_871X("pwrpriv->bAutoResume (%x)  pwrpriv->bInternalAutoSuspend(%x)\n",pwrpriv->bAutoResume,pwrpriv->bInternalAutoSuspend );
1283                 }
1284
1285 #else   //#ifdef CONFIG_BT_COEXIST
1286                 pwrpriv->bInternalAutoSuspend = _FALSE;
1287 #endif  //#ifdef CONFIG_BT_COEXIST
1288                 pwrpriv->brfoffbyhw = _FALSE;
1289         }
1290 #endif
1291         _exit_pwrlock(&pwrpriv->lock);
1292
1293         if( padapter->pid[1]!=0) {
1294                 DBG_871X("pid[1]:%d\n",padapter->pid[1]);
1295                 rtw_signal_process(padapter->pid[1], SIGUSR2);
1296         }
1297
1298         if (rtw_chk_roam_flags(padapter, RTW_ROAM_ON_RESUME))
1299                 rtw_roaming(padapter, NULL);
1300
1301         ret = 0;
1302 exit:
1303         #ifdef CONFIG_RESUME_IN_WORKQUEUE
1304         rtw_unlock_suspend();
1305         #endif //CONFIG_RESUME_IN_WORKQUEUE
1306
1307         pwrpriv->bInSuspend = _FALSE;
1308         DBG_871X("<===  %s return %d.............. in %dms\n", __FUNCTION__
1309                 , ret, rtw_get_passing_time_ms(start_time));
1310
1311         _func_exit_;
1312
1313         return ret;
1314 }
1315 #endif
1316 static int rtw_resume(struct usb_interface *pusb_intf)
1317 {
1318         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
1319         _adapter *padapter = dvobj->if1;
1320         struct net_device *pnetdev = padapter->pnetdev;
1321         struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
1322          int ret = 0;
1323
1324         if(pwrpriv->bInternalAutoSuspend ){
1325                 ret = rtw_resume_process(padapter);
1326         } else {
1327 #ifdef CONFIG_RESUME_IN_WORKQUEUE
1328                 rtw_resume_in_workqueue(pwrpriv);
1329 #else
1330                 if (rtw_is_earlysuspend_registered(pwrpriv)
1331                         #ifdef CONFIG_WOWLAN
1332                         && !pwrpriv->wowlan_mode
1333                         #endif /* CONFIG_WOWLAN */
1334                 ) {
1335                         /* jeff: bypass resume here, do in late_resume */
1336                         rtw_set_do_late_resume(pwrpriv, _TRUE);
1337                 } else {
1338                         ret = rtw_resume_process(padapter);
1339                 }
1340 #endif /* CONFIG_RESUME_IN_WORKQUEUE */
1341         }
1342
1343         return ret;
1344
1345 }
1346
1347
1348
1349 #ifdef CONFIG_AUTOSUSPEND
1350 void autosuspend_enter(_adapter* padapter)
1351 {
1352         struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1353         struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
1354
1355         DBG_871X("==>autosuspend_enter...........\n");
1356
1357         pwrpriv->bInternalAutoSuspend = _TRUE;
1358         pwrpriv->bips_processing = _TRUE;
1359
1360         if(rf_off == pwrpriv->change_rfpwrstate )
1361         {
1362 #ifndef CONFIG_BT_COEXIST
1363                 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1364                 usb_enable_autosuspend(dvobj->pusbdev);
1365                 #else
1366                 dvobj->pusbdev->autosuspend_disabled = 0;//autosuspend disabled by the user
1367                 #endif
1368
1369                 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1370                         usb_autopm_put_interface(dvobj->pusbintf);
1371                 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1372                         usb_autopm_enable(dvobj->pusbintf);
1373                 #else
1374                         usb_autosuspend_device(dvobj->pusbdev, 1);
1375                 #endif
1376 #else   //#ifndef       CONFIG_BT_COEXIST
1377                 if(1==pwrpriv->autopm_cnt){
1378                 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1379                 usb_enable_autosuspend(dvobj->pusbdev);
1380                 #else
1381                 dvobj->pusbdev->autosuspend_disabled = 0;//autosuspend disabled by the user
1382                 #endif
1383
1384                 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1385                         usb_autopm_put_interface(dvobj->pusbintf);
1386                 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1387                         usb_autopm_enable(dvobj->pusbintf);
1388                 #else
1389                         usb_autosuspend_device(dvobj->pusbdev, 1);
1390                 #endif
1391                         pwrpriv->autopm_cnt --;
1392                 }
1393                 else
1394                 DBG_871X("0!=pwrpriv->autopm_cnt[%d]   didn't usb_autopm_put_interface\n", pwrpriv->autopm_cnt);
1395
1396 #endif  //#ifndef       CONFIG_BT_COEXIST
1397         }
1398         #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1399         DBG_871X("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1400         #else
1401         DBG_871X("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1402         #endif
1403
1404 }
1405 int autoresume_enter(_adapter* padapter)
1406 {
1407         int result = _SUCCESS;
1408         struct security_priv* psecuritypriv=&(padapter->securitypriv);
1409         struct mlme_ext_priv    *pmlmeext = &padapter->mlmeextpriv;
1410         struct mlme_ext_info    *pmlmeinfo = &(pmlmeext->mlmext_info);
1411         struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1412         struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
1413
1414         DBG_871X("====> autoresume_enter \n");
1415
1416         if(rf_off == pwrpriv->rf_pwrstate )
1417         {
1418                 pwrpriv->ps_flag = _FALSE;
1419 #ifndef CONFIG_BT_COEXIST
1420                 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1421                         if (usb_autopm_get_interface(dvobj->pusbintf) < 0)
1422                         {
1423                                 DBG_871X( "can't get autopm: %d\n", result);
1424                                 result = _FAIL;
1425                                 goto error_exit;
1426                         }
1427                 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1428                         usb_autopm_disable(dvobj->pusbintf);
1429                 #else
1430                         usb_autoresume_device(dvobj->pusbdev, 1);
1431                 #endif
1432
1433                 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1434                 DBG_871X("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1435                 #else
1436                 DBG_871X("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1437                 #endif
1438 #else   //#ifndef       CONFIG_BT_COEXIST
1439                 pwrpriv->bAutoResume=_TRUE;
1440                 if(0==pwrpriv->autopm_cnt){
1441                 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1442                         if (usb_autopm_get_interface(dvobj->pusbintf) < 0)
1443                         {
1444                                 DBG_871X( "can't get autopm: %d\n", result);
1445                                 result = _FAIL;
1446                                 goto error_exit;
1447                         }
1448                 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1449                         usb_autopm_disable(dvobj->pusbintf);
1450                 #else
1451                         usb_autoresume_device(dvobj->pusbdev, 1);
1452                 #endif
1453                 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1454                         DBG_871X("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1455                 #else
1456                         DBG_871X("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1457                 #endif
1458                         pwrpriv->autopm_cnt++;
1459                 }
1460                 else
1461                         DBG_871X("0!=pwrpriv->autopm_cnt[%d]   didn't usb_autopm_get_interface\n",pwrpriv->autopm_cnt);
1462 #endif //#ifndef        CONFIG_BT_COEXIST
1463         }
1464         DBG_871X("<==== autoresume_enter \n");
1465 error_exit:
1466
1467         return result;
1468 }
1469 #endif
1470
1471 #ifdef CONFIG_PLATFORM_RTD2880B
1472 extern void rtd2885_wlan_netlink_sendMsg(char *action_string, char *name);
1473 #endif
1474
1475 /*
1476  * drv_init() - a device potentially for us
1477  *
1478  * notes: drv_init() is called when the bus driver has located a card for us to support.
1479  *        We accept the new device by returning 0.
1480 */
1481
1482 _adapter  *rtw_sw_export = NULL;
1483
1484 _adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
1485         struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
1486 {
1487         _adapter *padapter = NULL;
1488         struct net_device *pnetdev = NULL;
1489         int status = _FAIL;
1490
1491         if ((padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter))) == NULL) {
1492                 goto exit;
1493         }
1494         padapter->dvobj = dvobj;
1495         dvobj->if1 = padapter;
1496
1497         padapter->bDriverStopped=_TRUE;
1498
1499         dvobj->padapters[dvobj->iface_nums++] = padapter;
1500         padapter->iface_id = IFACE_ID0;
1501
1502 #if defined(CONFIG_CONCURRENT_MODE) || defined(CONFIG_DUALMAC_CONCURRENT)
1503         //set adapter_type/iface type for primary padapter
1504         padapter->isprimary = _TRUE;
1505         padapter->adapter_type = PRIMARY_ADAPTER;
1506         #ifndef CONFIG_HWPORT_SWAP
1507         padapter->iface_type = IFACE_PORT0;
1508         #else
1509         padapter->iface_type = IFACE_PORT1;
1510         #endif  
1511 #endif
1512
1513         //step 1-1., decide the chip_type via driver_info
1514         padapter->interface_type = RTW_USB;
1515         rtw_decide_chip_type_by_usb_info(padapter, pdid);
1516
1517         if (rtw_handle_dualmac(padapter, 1) != _SUCCESS)
1518                 goto free_adapter;
1519
1520         if((pnetdev = rtw_init_netdev(padapter)) == NULL) {
1521                 goto handle_dualmac;
1522         }
1523         SET_NETDEV_DEV(pnetdev, dvobj_to_dev(dvobj));
1524         padapter = rtw_netdev_priv(pnetdev);
1525
1526 #ifdef CONFIG_IOCTL_CFG80211
1527         if(rtw_wdev_alloc(padapter, dvobj_to_dev(dvobj)) != 0) {
1528                 goto handle_dualmac;
1529         }
1530 #endif
1531
1532         //step 2. hook HalFunc, allocate HalData
1533         //hal_set_hal_ops(padapter);
1534         rtw_set_hal_ops(padapter);
1535
1536         padapter->intf_start=&usb_intf_start;
1537         padapter->intf_stop=&usb_intf_stop;
1538
1539         //step init_io_priv
1540         rtw_init_io_priv(padapter,usb_set_intf_ops);
1541
1542         //step read_chip_version
1543         rtw_hal_read_chip_version(padapter);
1544
1545         //step usb endpoint mapping
1546         rtw_hal_chip_configure(padapter);
1547
1548 #ifdef CONFIG_BT_COEXIST
1549         rtw_btcoex_Initialize(padapter);
1550 #endif // CONFIG_BT_COEXIST
1551
1552         //step read efuse/eeprom data and get mac_addr
1553         rtw_hal_read_chip_info(padapter);
1554
1555         //step 5.
1556         if(rtw_init_drv_sw(padapter) ==_FAIL) {
1557                 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("Initialize driver software resource Failed!\n"));
1558                 goto free_hal_data;
1559         }
1560
1561 #ifdef CONFIG_PM
1562 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18))
1563         if(dvobj_to_pwrctl(dvobj)->bSupportRemoteWakeup)
1564         {
1565                 dvobj->pusbdev->do_remote_wakeup=1;
1566                 pusb_intf->needs_remote_wakeup = 1;
1567                 device_init_wakeup(&pusb_intf->dev, 1);
1568                 DBG_871X("pwrctrlpriv.bSupportRemoteWakeup~~~~~~\n");
1569                 DBG_871X("pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n",device_may_wakeup(&pusb_intf->dev));
1570         }
1571 #endif
1572 #endif
1573
1574 #ifdef CONFIG_AUTOSUSPEND
1575         if( padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE )
1576         {
1577                 if(padapter->registrypriv.usbss_enable ){       /* autosuspend (2s delay) */
1578                         #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,38))
1579                         dvobj->pusbdev->dev.power.autosuspend_delay = 0 * HZ;//15 * HZ; idle-delay time
1580                         #else
1581                         dvobj->pusbdev->autosuspend_delay = 0 * HZ;//15 * HZ; idle-delay time
1582                         #endif
1583
1584                         #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1585                         usb_enable_autosuspend(dvobj->pusbdev);
1586                         #elif  (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22) && LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,34))
1587                         padapter->bDisableAutosuspend = dvobj->pusbdev->autosuspend_disabled ;
1588                         dvobj->pusbdev->autosuspend_disabled = 0;//autosuspend disabled by the user
1589                         #endif
1590
1591                         //usb_autopm_get_interface(adapter_to_dvobj(padapter)->pusbintf );//init pm_usage_cnt ,let it start from 1
1592
1593                         #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1594                         DBG_871X("%s...pm_usage_cnt(%d).....\n",__FUNCTION__,atomic_read(&(dvobj->pusbintf ->pm_usage_cnt)));
1595                         #else
1596                         DBG_871X("%s...pm_usage_cnt(%d).....\n",__FUNCTION__,dvobj->pusbintf ->pm_usage_cnt);
1597                         #endif
1598                 }
1599         }
1600 #endif
1601         //2012-07-11 Move here to prevent the 8723AS-VAU BT auto suspend influence
1602         #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1603                         if (usb_autopm_get_interface(pusb_intf) < 0)
1604                                 {
1605                                         DBG_871X( "can't get autopm: \n");
1606                                 }
1607         #endif
1608 #ifdef  CONFIG_BT_COEXIST
1609         dvobj_to_pwrctl(dvobj)->autopm_cnt=1;
1610 #endif
1611
1612         // set mac addr
1613         rtw_macaddr_cfg(padapter->eeprompriv.mac_addr);
1614 #ifdef CONFIG_P2P       
1615         rtw_init_wifidirect_addrs(padapter, padapter->eeprompriv.mac_addr, padapter->eeprompriv.mac_addr);
1616 #endif // CONFIG_P2P
1617         DBG_871X("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d, hw_init_completed:%d\n"
1618                 , padapter->bDriverStopped
1619                 , padapter->bSurpriseRemoved
1620                 , padapter->bup
1621                 , padapter->hw_init_completed
1622         );
1623
1624         status = _SUCCESS;
1625
1626 free_hal_data:
1627         if(status != _SUCCESS && padapter->HalData)
1628                 rtw_mfree(padapter->HalData, sizeof(*(padapter->HalData)));
1629 free_wdev:
1630         if(status != _SUCCESS) {
1631                 #ifdef CONFIG_IOCTL_CFG80211
1632                 rtw_wdev_unregister(padapter->rtw_wdev);
1633                 rtw_wdev_free(padapter->rtw_wdev);
1634                 #endif
1635         }
1636 handle_dualmac:
1637         if (status != _SUCCESS)
1638                 rtw_handle_dualmac(padapter, 0);
1639 free_adapter:
1640         if (status != _SUCCESS) {
1641                 if (pnetdev)
1642                         rtw_free_netdev(pnetdev);
1643                 else
1644                         rtw_vmfree((u8*)padapter, sizeof(*padapter));
1645                 padapter = NULL;
1646         }
1647 exit:
1648         return padapter;
1649 }
1650
1651 static void rtw_usb_if1_deinit(_adapter *if1)
1652 {
1653         struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(if1);
1654         struct net_device *pnetdev = if1->pnetdev;
1655         struct mlme_priv *pmlmepriv= &if1->mlmepriv;
1656
1657         if(check_fwstate(pmlmepriv, _FW_LINKED))
1658                 rtw_disassoc_cmd(if1, 0, _FALSE);
1659
1660
1661 #ifdef CONFIG_AP_MODE
1662         free_mlme_ap_info(if1);
1663         #ifdef CONFIG_HOSTAPD_MLME
1664         hostapd_mode_unload(if1);
1665         #endif
1666 #endif
1667
1668         rtw_cancel_all_timer(if1);
1669
1670 #ifdef CONFIG_WOWLAN
1671         pwrctl->wowlan_mode=_FALSE;
1672 #endif //CONFIG_WOWLAN
1673
1674         rtw_dev_unload(if1);
1675
1676         DBG_871X("+r871xu_dev_remove, hw_init_completed=%d\n", if1->hw_init_completed);
1677
1678         rtw_handle_dualmac(if1, 0);
1679
1680 #ifdef CONFIG_IOCTL_CFG80211
1681         if(if1->rtw_wdev) {
1682                 rtw_wdev_free(if1->rtw_wdev);
1683         }
1684 #endif
1685
1686 #ifdef CONFIG_BT_COEXIST
1687         if(1 == pwrctl->autopm_cnt){
1688                 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1689                         usb_autopm_put_interface(adapter_to_dvobj(if1)->pusbintf);
1690                 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1691                         usb_autopm_enable(adapter_to_dvobj(if1)->pusbintf);
1692                 #else
1693                         usb_autosuspend_device(adapter_to_dvobj(if1)->pusbdev, 1);
1694                 #endif
1695                 pwrctl->autopm_cnt --;
1696         }
1697 #endif
1698
1699         rtw_free_drv_sw(if1);
1700
1701         if(pnetdev)
1702                 rtw_free_netdev(pnetdev);
1703
1704 #ifdef CONFIG_PLATFORM_RTD2880B
1705         DBG_871X("wlan link down\n");
1706         rtd2885_wlan_netlink_sendMsg("linkdown", "8712");
1707 #endif
1708
1709 }
1710
1711 static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
1712 {
1713         _adapter *if1 = NULL, *if2 = NULL;
1714         int status = _FAIL;
1715         struct dvobj_priv *dvobj;
1716 #ifdef CONFIG_MULTI_VIR_IFACES
1717         int i;
1718 #endif //CONFIG_MULTI_VIR_IFACES
1719
1720         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_drv_init\n"));
1721         //DBG_871X("+rtw_drv_init\n");
1722
1723         //step 0.
1724         process_spec_devid(pdid);
1725
1726         /* Initialize dvobj_priv */
1727         if ((dvobj = usb_dvobj_init(pusb_intf)) == NULL) {
1728                 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("initialize device object priv Failed!\n"));
1729                 goto exit;
1730         }
1731
1732         if ((if1 = rtw_usb_if1_init(dvobj, pusb_intf, pdid)) == NULL) {
1733                 DBG_871X("rtw_usb_if1_init Failed!\n");
1734                 goto free_dvobj;
1735         }
1736
1737 #ifdef CONFIG_CONCURRENT_MODE
1738         if((if2 = rtw_drv_if2_init(if1, usb_set_intf_ops)) == NULL) {
1739                 goto free_if1;
1740         }
1741 #ifdef CONFIG_MULTI_VIR_IFACES
1742         for(i=0; i<if1->registrypriv.ext_iface_num;i++)
1743         {
1744                 if(rtw_drv_add_vir_if(if1, usb_set_intf_ops) == NULL)
1745                 {
1746                         DBG_871X("rtw_drv_add_iface failed! (%d)\n", i);
1747                         goto free_if2;
1748                 }
1749         }
1750 #endif //CONFIG_MULTI_VIR_IFACES
1751 #endif
1752
1753 #ifdef CONFIG_INTEL_PROXIM
1754         rtw_sw_export=if1;
1755 #endif
1756
1757 #ifdef CONFIG_GLOBAL_UI_PID
1758         if(ui_pid[1]!=0) {
1759                 DBG_871X("ui_pid[1]:%d\n",ui_pid[1]);
1760                 rtw_signal_process(ui_pid[1], SIGUSR2);
1761         }
1762 #endif
1763
1764         //dev_alloc_name && register_netdev
1765         if((status = rtw_drv_register_netdev(if1)) != _SUCCESS) {
1766                 goto free_if2;
1767         }
1768
1769 #ifdef CONFIG_HOSTAPD_MLME
1770         hostapd_mode_init(if1);
1771 #endif
1772
1773 #ifdef CONFIG_PLATFORM_RTD2880B
1774         DBG_871X("wlan link up\n");
1775         rtd2885_wlan_netlink_sendMsg("linkup", "8712");
1776 #endif
1777
1778         RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-871x_drv - drv_init, success!\n"));
1779
1780         status = _SUCCESS;
1781
1782 free_if2:
1783         if(status != _SUCCESS && if2) {
1784                 #ifdef CONFIG_CONCURRENT_MODE
1785                 rtw_drv_if2_stop(if2);
1786                 rtw_drv_if2_free(if2);
1787                 #endif
1788         }
1789 free_if1:
1790         if (status != _SUCCESS && if1) {
1791                 rtw_usb_if1_deinit(if1);
1792         }
1793 free_dvobj:
1794         if (status != _SUCCESS)
1795                 usb_dvobj_deinit(pusb_intf);
1796 exit:
1797         return status == _SUCCESS?0:-ENODEV;
1798 }
1799
1800 /*
1801  * dev_remove() - our device is being removed
1802 */
1803 //rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove() => how to recognize both
1804 static void rtw_dev_remove(struct usb_interface *pusb_intf)
1805 {
1806         struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
1807         struct pwrctrl_priv *pwrctl = dvobj_to_pwrctl(dvobj);
1808         _adapter *padapter = dvobj->if1;
1809         struct net_device *pnetdev = padapter->pnetdev;
1810         struct mlme_priv *pmlmepriv= &padapter->mlmepriv;
1811
1812 _func_enter_;
1813
1814         DBG_871X("+rtw_dev_remove\n");
1815         RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+dev_remove()\n"));
1816
1817         dvobj->processing_dev_remove = _TRUE;
1818
1819         rtw_unregister_netdevs(dvobj);
1820
1821         if(usb_drv.drv_registered == _TRUE)
1822         {
1823                 //DBG_871X("r871xu_dev_remove():padapter->bSurpriseRemoved == _TRUE\n");
1824                 padapter->bSurpriseRemoved = _TRUE;
1825         }
1826         /*else
1827         {
1828                 //DBG_871X("r871xu_dev_remove():module removed\n");
1829                 padapter->hw_init_completed = _FALSE;
1830         }*/
1831
1832
1833 #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
1834         rtw_unregister_early_suspend(pwrctl);
1835 #endif
1836
1837         rtw_pm_set_ips(padapter, IPS_NONE);
1838         rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
1839
1840         LeaveAllPowerSaveMode(padapter);
1841
1842 #ifdef CONFIG_CONCURRENT_MODE
1843 #ifdef CONFIG_MULTI_VIR_IFACES
1844         rtw_drv_stop_vir_ifaces(dvobj);
1845 #endif //CONFIG_MULTI_VIR_IFACES
1846         rtw_drv_if2_stop(dvobj->if2);
1847 #endif //CONFIG_CONCURRENT_MODE
1848
1849         #ifdef CONFIG_BT_COEXIST
1850         rtw_btcoex_HaltNotify(padapter);
1851         #endif
1852
1853         rtw_usb_if1_deinit(padapter);
1854
1855 #ifdef CONFIG_CONCURRENT_MODE
1856 #ifdef CONFIG_MULTI_VIR_IFACES
1857         rtw_drv_free_vir_ifaces(dvobj);
1858 #endif //CONFIG_MULTI_VIR_IFACES
1859         rtw_drv_if2_free(dvobj->if2);
1860 #endif //CONFIG_CONCURRENT_MODE
1861
1862         usb_dvobj_deinit(pusb_intf);
1863
1864         RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-dev_remove()\n"));
1865         DBG_871X("-r871xu_dev_remove, done\n");
1866
1867
1868 #ifdef CONFIG_INTEL_PROXIM
1869         rtw_sw_export=NULL;
1870 #endif
1871
1872 _func_exit_;
1873
1874         return;
1875
1876 }
1877 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
1878 extern int console_suspend_enabled;
1879 #endif
1880
1881 static int rtw_drv_entry(void)
1882 {
1883         int ret = 0;
1884
1885         DBG_871X_LEVEL(_drv_always_, "module init start\n");
1886         dump_drv_version(RTW_DBGDUMP);
1887 #ifdef BTCOEXVERSION
1888         DBG_871X_LEVEL(_drv_always_, DRV_NAME" BT-Coex version = %s\n", BTCOEXVERSION);
1889 #endif // BTCOEXVERSION
1890
1891         ret = platform_wifi_power_on();
1892         if(ret != 0)
1893         {
1894                 DBG_871X("%s: power on failed!!(%d)\n", __FUNCTION__, ret);
1895                 ret = -1;
1896                 goto exit;
1897         }
1898 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
1899         //console_suspend_enabled=0;
1900 #endif
1901
1902         usb_drv.drv_registered = _TRUE;
1903         rtw_suspend_lock_init();
1904         rtw_drv_proc_init();
1905         rtw_ndev_notifier_register();
1906
1907         ret = usb_register(&usb_drv.usbdrv);
1908
1909         if (ret != 0) {
1910                 usb_drv.drv_registered = _FALSE;
1911                 rtw_suspend_lock_uninit();
1912                 rtw_drv_proc_deinit();
1913                 rtw_ndev_notifier_unregister();
1914                 goto exit;
1915         }
1916
1917 exit:
1918         DBG_871X_LEVEL(_drv_always_, "module init ret=%d\n", ret);
1919         return ret;
1920 }
1921
1922 static void rtw_drv_halt(void)
1923 {
1924         DBG_871X_LEVEL(_drv_always_, "module exit start\n");
1925
1926         usb_drv.drv_registered = _FALSE;
1927
1928         usb_deregister(&usb_drv.usbdrv);
1929
1930         platform_wifi_power_off();
1931
1932         rtw_suspend_lock_uninit();
1933         rtw_drv_proc_deinit();
1934         rtw_ndev_notifier_unregister();
1935
1936         DBG_871X_LEVEL(_drv_always_, "module exit success\n");
1937
1938         rtw_mstat_dump(RTW_DBGDUMP);
1939 }
1940
1941 #include "wifi_version.h"
1942 #include <linux/rfkill-wlan.h>
1943
1944 int rockchip_wifi_init_module_rtkwifi(void)
1945 {
1946     printk("\n");
1947     printk("=======================================================\n");
1948     printk("==== Launching Wi-Fi driver! (Powered by Rockchip) ====\n");
1949     printk("=======================================================\n");
1950     printk("Realtek 8723BU USB WiFi driver (Powered by Rockchip,Ver %s) init.\n", RTL8192_DRV_VERSION);
1951     rockchip_wifi_power(1);
1952
1953     return rtw_drv_entry();
1954 }
1955
1956 void rockchip_wifi_exit_module_rtkwifi(void)
1957 {
1958     printk("\n");
1959     printk("=======================================================\n");
1960     printk("==== Dislaunching Wi-Fi driver! (Powered by Rockchip) ====\n");
1961     printk("=======================================================\n");
1962     printk("Realtek 8723BU USB WiFi driver (Powered by Rockchip,Ver %s) init.\n", RTL8192_DRV_VERSION);
1963     rtw_drv_halt();
1964     rockchip_wifi_power(0);
1965 }
1966
1967 EXPORT_SYMBOL(rockchip_wifi_init_module_rtkwifi);
1968 EXPORT_SYMBOL(rockchip_wifi_exit_module_rtkwifi);
1969 //module_init(rtw_drv_entry);
1970 //module_exit(rtw_drv_halt);
1971                  
1972 #ifdef CONFIG_INTEL_PROXIM
1973 _adapter  *rtw_usb_get_sw_pointer(void)
1974 {
1975         return rtw_sw_export;
1976 }
1977 EXPORT_SYMBOL(rtw_usb_get_sw_pointer);
1978 #endif  //CONFIG_INTEL_PROXIM
1979