]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/net/wireless/realtek/rtl8192cu/os_dep/linux/usb_intf.c
net: Fix rtl8192cu build errors on other platforms
[mirror_ubuntu-zesty-kernel.git] / drivers / net / wireless / realtek / rtl8192cu / 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_conf.h>
23 #include <osdep_service.h>
24 #include <drv_types.h>
25 #include <recv_osdep.h>
26 #include <xmit_osdep.h>
27 #include <hal_intf.h>
28 #include <rtw_version.h>
29
30 #ifndef CONFIG_USB_HCI
31
32 #error "CONFIG_USB_HCI shall be on!\n"
33
34 #endif
35
36 #include <usb_vendor_req.h>
37 #include <usb_ops.h>
38 #include <usb_osintf.h>
39 #include <usb_hal.h>
40 #ifdef CONFIG_PLATFORM_RTK_DMP
41 #include <asm/io.h>
42 #endif
43
44 #if defined (PLATFORM_LINUX) && defined (PLATFORM_WINDOWS)
45
46 #error "Shall be Linux or Windows, but not both!\n"
47
48 #endif
49
50 #ifdef CONFIG_80211N_HT
51 extern int rtw_ht_enable;
52 extern int rtw_cbw40_enable;
53 extern int rtw_ampdu_enable;//for enable tx_ampdu
54 #endif
55
56 #ifdef CONFIG_GLOBAL_UI_PID
57 int ui_pid[3] = {0, 0, 0};
58 #endif
59
60
61 extern int pm_netdev_open(struct net_device *pnetdev,u8 bnormal);
62 static int rtw_suspend(struct usb_interface *intf, pm_message_t message);
63 static int rtw_resume(struct usb_interface *intf);
64 int rtw_resume_process(_adapter *padapter);
65
66
67 static int rtw_drv_init(struct usb_interface *pusb_intf,const struct usb_device_id *pdid);
68 static void rtw_dev_remove(struct usb_interface *pusb_intf);
69
70 #define USB_VENDER_ID_REALTEK 0x0BDA
71
72 /* DID_USB_v915_20121224 */
73 #define RTL8192C_USB_IDS \
74 /*=== Realtek demoboard ===*/ \
75 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8191)},/* Default ID */ \
76 /****** 8188CUS ********/ \
77 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8176)},/* 8188cu 1*1 dongole */ \
78 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8170)},/* 8188CE-VAU USB minCard */ \
79 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817E)},/* 8188CE-VAU USB minCard */ \
80 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817A)},/* 8188cu Slim Solo */ \
81 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817B)},/* 8188cu Slim Combo */ \
82 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817D)},/* 8188RU High-power USB Dongle */ \
83 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8754)},/* 8188 Combo for BC4 */ \
84 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817F)},/* 8188RU */ \
85 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x818A)},/* RTL8188CUS-VL */ \
86 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x018A)},/* RTL8188CTV */ \
87 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x17C0)}, /* RTK demoboard - USB-N10E */ \
88 /****** 8192CUS ********/ \
89 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8177)},/* 8191cu 1*2 */ \
90 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8178)},/* 8192cu 2*2 */ \
91 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x817C)},/* 8192CE-VAU USB minCard */ \
92 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8191)},/* 8192CU 2*2 */ \
93 {USB_DEVICE(0x1058, 0x0631)},/* Alpha, 8192CU */ \
94 /*=== Customer ID ===*/ \
95 /****** 8188CUS Dongle ********/ \
96 {USB_DEVICE(0x2019, 0xED17)},/* PCI - Edimax */ \
97 {USB_DEVICE(0x0DF6, 0x0052)},/* Sitecom - Edimax */ \
98 {USB_DEVICE(0x7392, 0x7811)},/* Edimax - Edimax */ \
99 {USB_DEVICE(0x07B8, 0x8189)},/* Abocom - Abocom */ \
100 {USB_DEVICE(0x0EB0, 0x9071)},/* NO Brand - Etop */ \
101 {USB_DEVICE(0x06F8, 0xE033)},/* Hercules - Edimax */ \
102 {USB_DEVICE(0x103C, 0x1629)},/* HP - Lite-On ,8188CUS Slim Combo */ \
103 {USB_DEVICE(0x2001, 0x3308)},/* D-Link - Alpha */ \
104 {USB_DEVICE(0x050D, 0x1102)},/* Belkin - Edimax */ \
105 {USB_DEVICE(0x050D, 0x11F2)},/* ISY - Edimax */ \
106 {USB_DEVICE(0x2019, 0xAB2A)},/* Planex - Abocom */ \
107 {USB_DEVICE(0x20F4, 0x648B)},/* TRENDnet - Cameo */ \
108 {USB_DEVICE(0x4855, 0x0090)},/* - Feixun */ \
109 {USB_DEVICE(0x13D3, 0x3357)},/* - AzureWave */ \
110 {USB_DEVICE(0x0DF6, 0x005C)},/* Sitecom - Edimax */ \
111 {USB_DEVICE(0x0BDA, 0x5088)},/* Thinkware - CC&C */ \
112 {USB_DEVICE(0x4856, 0x0091)},/* NetweeN - Feixun */ \
113 {USB_DEVICE(0x0846, 0x9041)}, /* Netgear - Cameo */ \
114 {USB_DEVICE(0x0846, 0x9042)}, /* On Networks - N150MA */ \
115 {USB_DEVICE(0x0846, 0x9043)}, /* Netgear N150 -WNA1000M */ \
116 {USB_DEVICE(0x2019, 0x4902)},/* Planex - Etop */ \
117 {USB_DEVICE(0x2019, 0xAB2E)},/* SW-WF02-AD15 -Abocom */ \
118 {USB_DEVICE(0x2001, 0x330B)}, /* D-LINK - T&W */ \
119 {USB_DEVICE(0xCDAB, 0x8010)}, /* - - compare */ \
120 {USB_DEVICE(0x0B05, 0x17BA)}, /* ASUS - Edimax */ \
121 {USB_DEVICE(0x0BDA, 0x1E1E)}, /* Intel - - */ \
122 {USB_DEVICE(0x04BB, 0x094c)}, /* I-O DATA - Edimax */ \
123 {USB_DEVICE(0X0BDA, 0x8176)}, /* TP-Link TL-WN723N */ \
124 /****** 8188CTV ********/ \
125 {USB_DEVICE(0xCDAB, 0x8011)}, /* - - compare */ \
126 {USB_DEVICE(0x0BDA, 0x0A8A)}, /* Sony - Foxconn */ \
127 /****** 8188 RU ********/ \
128 {USB_DEVICE(0x0BDA, 0x317F)},/* Netcore,Netcore */ \
129 /****** 8188CE-VAU ********/ \
130 {USB_DEVICE(0x13D3, 0x3359)},/* - Azwave */ \
131 {USB_DEVICE(0x13D3, 0x3358)},/* - Azwave */ \
132 /****** 8188CUS Slim Solo********/ \
133 {USB_DEVICE(0x04F2, 0xAFF7)},/* XAVI - XAVI */ \
134 {USB_DEVICE(0x04F2, 0xAFF9)},/* XAVI - XAVI */ \
135 {USB_DEVICE(0x04F2, 0xAFFA)},/* XAVI - XAVI */ \
136 /****** 8188CUS Slim Combo ********/ \
137 {USB_DEVICE(0x04F2, 0xAFF8)},/* XAVI - XAVI */ \
138 {USB_DEVICE(0x04F2, 0xAFFB)},/* XAVI - XAVI */ \
139 {USB_DEVICE(0x04F2, 0xAFFC)},/* XAVI - XAVI */ \
140 {USB_DEVICE(0x2019, 0x1201)},/* Planex - Vencer */ \
141 /****** 8192CUS Dongle ********/ \
142 {USB_DEVICE(0x2001, 0x3307)},/* D-Link - Cameo */ \
143 {USB_DEVICE(0x2001, 0x330A)},/* D-Link - Alpha */ \
144 {USB_DEVICE(0x2001, 0x3309)},/* D-Link - Alpha */ \
145 {USB_DEVICE(0x2001, 0x330D)},/* D-Link - DWA 131 */ \
146 {USB_DEVICE(0x0586, 0x341F)},/* Zyxel - Abocom */ \
147 {USB_DEVICE(0x7392, 0x7822)},/* Edimax - Edimax */ \
148 {USB_DEVICE(0x2019, 0xAB2B)},/* Planex - Abocom */ \
149 {USB_DEVICE(0x07B8, 0x8178)},/* Abocom - Abocom */ \
150 {USB_DEVICE(0x07AA, 0x0056)},/* ATKK - Gemtek */ \
151 {USB_DEVICE(0x4855, 0x0091)},/* - Feixun */ \
152 {USB_DEVICE(0x050D, 0x2102)},/* Belkin - Sercomm */ \
153 {USB_DEVICE(0x050D, 0x2103)},/* Belkin - Edimax */ \
154 {USB_DEVICE(0x20F4, 0x624D)},/* TRENDnet */ \
155 {USB_DEVICE(0x0DF6, 0x0061)},/* Sitecom - Edimax */ \
156 {USB_DEVICE(0x0B05, 0x17AB)},/* ASUS - Edimax */ \
157 {USB_DEVICE(0x0846, 0x9021)},/* Netgear - Sercomm */ \
158 {USB_DEVICE(0x0846, 0xF001)}, /* Netgear - Sercomm */ \
159 {USB_DEVICE(0x0E66, 0x0019)},/* Hawking,Edimax */ \
160 {USB_DEVICE(0x0E66, 0x0020)}, /* Hawking - Edimax */ \
161 {USB_DEVICE(0x050D, 0x1004)}, /* Belkin - Edimax */ \
162 {USB_DEVICE(0x0BDA, 0x2E2E)}, /* Intel - - */ \
163 {USB_DEVICE(0x2357, 0x0100)}, /* TP-Link - TP-Link */ \
164 {USB_DEVICE(0x06F8, 0xE035)}, /* Hercules - Edimax */ \
165 {USB_DEVICE(0x04BB, 0x0950)}, /* IO-DATA - Edimax */ \
166 {USB_DEVICE(0x0DF6, 0x0070)}, /* Sitecom - Edimax */ \
167 {USB_DEVICE(0x0789, 0x016D)}, /* LOGITEC - Edimax */ \
168 /****** 8192CE-VAU ********/ \
169 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8186)},/* Intel-Xavi( Azwave) */
170
171 #define RTL8192D_USB_IDS \
172 /*=== Realtek demoboard ===*/ \
173 /****** 8192DU ********/ \
174 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8193)},/* 8192DU-VC */ \
175 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8194)},/* 8192DU-VS */ \
176 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8111)},/* Realtek 5G dongle for WiFi Display */ \
177 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0193)},/* 8192DE-VAU */ \
178 {USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8171)},/* 8192DU-VC */ \
179 /*=== Customer ID ===*/ \
180 /****** 8192DU-VC ********/ \
181 {USB_DEVICE(0x2019, 0xAB2C)},/* PCI - Abocm */ \
182 {USB_DEVICE(0x2019, 0x4903)},/* PCI - ETOP */ \
183 {USB_DEVICE(0x2019, 0x4904)},/* PCI - ETOP */ \
184 {USB_DEVICE(0x07B8, 0x8193)},/* Abocom - Abocom */ \
185 /****** 8192DU-VS ********/ \
186 {USB_DEVICE(0x20F4, 0x664B)}, /* TRENDnet - Cameo */ \
187 {USB_DEVICE(0x04DD, 0x954F)}, /* Sharp */ \
188 {USB_DEVICE(0x04DD, 0x96A6)}, /* Sharp */ \
189 {USB_DEVICE(0x050D, 0x110A)}, /* Belkin - Edimax */ \
190 {USB_DEVICE(0x050D, 0x1105)}, /* Belkin - Edimax */ \
191 {USB_DEVICE(0x050D, 0x120A)}, /* Belkin - Edimax */ \
192 {USB_DEVICE(0x1668, 0x8102)}, /* - */ \
193 {USB_DEVICE(0x0BDA, 0xE194)}, /* - Edimax */ \
194 /****** 8192DU-WiFi Display Dongle ********/ \
195 {USB_DEVICE(0x2019, 0xAB2D)},/* Planex - Abocom ,5G dongle for WiFi Display */
196
197 #ifndef CONFIG_RTL8192C
198 #undef RTL8192C_USB_IDS
199 #define RTL8192C_USB_IDS
200 #endif
201 #ifndef CONFIG_RTL8192D
202 #undef RTL8192D_USB_IDS
203 #define RTL8192D_USB_IDS
204 #endif
205
206
207 static struct usb_device_id rtw_usb_id_tbl[] ={
208 RTL8192C_USB_IDS
209 RTL8192D_USB_IDS
210 {} /* Terminating entry */
211 };
212 MODULE_DEVICE_TABLE(usb, rtw_usb_id_tbl);
213
214 int const rtw_usb_id_len = sizeof(rtw_usb_id_tbl) / sizeof(struct usb_device_id);
215
216 static struct specific_device_id specific_device_id_tbl[] = {
217 {.idVendor=USB_VENDER_ID_REALTEK, .idProduct=0x8177, .flags=SPEC_DEV_ID_DISABLE_HT},//8188cu 1*1 dongole, (b/g mode only)
218 {.idVendor=USB_VENDER_ID_REALTEK, .idProduct=0x817E, .flags=SPEC_DEV_ID_DISABLE_HT},//8188CE-VAU USB minCard (b/g mode only)
219 {.idVendor=0x0b05, .idProduct=0x1791, .flags=SPEC_DEV_ID_DISABLE_HT},
220 {.idVendor=0x13D3, .idProduct=0x3311, .flags=SPEC_DEV_ID_DISABLE_HT},
221 {.idVendor=0x13D3, .idProduct=0x3359, .flags=SPEC_DEV_ID_DISABLE_HT},//Russian customer -Azwave (8188CE-VAU g mode)
222 #ifdef RTK_DMP_PLATFORM
223 {.idVendor=USB_VENDER_ID_REALTEK, .idProduct=0x8111, .flags=SPEC_DEV_ID_ASSIGN_IFNAME}, // Realtek 5G dongle for WiFi Display
224 {.idVendor=0x2019, .idProduct=0xAB2D, .flags=SPEC_DEV_ID_ASSIGN_IFNAME}, // PCI-Abocom 5G dongle for WiFi Display
225 #endif /* RTK_DMP_PLATFORM */
226 {}
227 };
228
229 struct rtw_usb_drv {
230 struct usb_driver usbdrv;
231 int drv_registered;
232 };
233
234 static void rtw_dev_shutdown(struct device *dev)
235 {
236 struct usb_interface *usb_intf = container_of(dev, struct usb_interface, dev);
237 struct dvobj_priv *dvobj = usb_get_intfdata(usb_intf);
238 _adapter *adapter = dvobj->if1;
239 int i;
240
241 DBG_871X("%s\n", __func__);
242
243 for (i = 0; i<dvobj->iface_nums; i++) {
244 adapter = dvobj->padapters[i];
245 adapter->bSurpriseRemoved = _TRUE;
246 }
247
248 ATOMIC_SET(&dvobj->continual_urb_error, MAX_CONTINUAL_URB_ERR+1);
249 }
250
251 #ifdef CONFIG_RTL8192C
252 static struct usb_device_id rtl8192c_usb_id_tbl[] ={
253 RTL8192C_USB_IDS
254 {} /* Terminating entry */
255 };
256
257 struct rtw_usb_drv rtl8192c_usb_drv = {
258 .usbdrv.name = (char*)"rtl8192cu",
259 .usbdrv.probe = rtw_drv_init,
260 .usbdrv.disconnect = rtw_dev_remove,
261 .usbdrv.id_table = rtl8192c_usb_id_tbl,
262 .usbdrv.suspend = rtw_suspend,
263 .usbdrv.resume = rtw_resume,
264 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
265 .usbdrv.reset_resume = rtw_resume,
266 #endif
267 #ifdef CONFIG_AUTOSUSPEND
268 .usbdrv.supports_autosuspend = 1,
269 #endif
270
271 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19))
272 .usbdrv.drvwrap.driver.shutdown = rtw_dev_shutdown,
273 #else
274 .usbdrv.driver.shutdown = rtw_dev_shutdown,
275 #endif
276 };
277
278 static struct rtw_usb_drv *usb_drv = &rtl8192c_usb_drv;
279 #endif /* CONFIG_RTL8192C */
280
281 #ifdef CONFIG_RTL8192D
282 static struct usb_device_id rtl8192d_usb_id_tbl[] ={
283 RTL8192D_USB_IDS
284 {} /* Terminating entry */
285 };
286
287 struct rtw_usb_drv rtl8192d_usb_drv = {
288 .usbdrv.name = (char*)"rtl8192du",
289 .usbdrv.probe = rtw_drv_init,
290 .usbdrv.disconnect = rtw_dev_remove,
291 .usbdrv.id_table = rtl8192d_usb_id_tbl,
292 .usbdrv.suspend = rtw_suspend,
293 .usbdrv.resume = rtw_resume,
294 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
295 .usbdrv.reset_resume = rtw_resume,
296 #endif
297 #ifdef CONFIG_AUTOSUSPEND
298 .usbdrv.supports_autosuspend = 1,
299 #endif
300
301 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19))
302 .usbdrv.drvwrap.driver.shutdown = rtw_dev_shutdown,
303 #else
304 .usbdrv.driver.shutdown = rtw_dev_shutdown,
305 #endif
306 };
307 static struct rtw_usb_drv *usb_drv = &rtl8192d_usb_drv;
308 #endif /* CONFIG_RTL8192D */
309
310 static inline int RT_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
311 {
312 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
313 }
314
315 static inline int RT_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)
316 {
317 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
318 }
319
320 static inline int RT_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
321 {
322 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT);
323 }
324
325 static inline int RT_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
326 {
327 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK);
328 }
329
330 static inline int RT_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
331 {
332 return (RT_usb_endpoint_xfer_bulk(epd) && RT_usb_endpoint_dir_in(epd));
333 }
334
335 static inline int RT_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
336 {
337 return (RT_usb_endpoint_xfer_bulk(epd) && RT_usb_endpoint_dir_out(epd));
338 }
339
340 static inline int RT_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
341 {
342 return (RT_usb_endpoint_xfer_int(epd) && RT_usb_endpoint_dir_in(epd));
343 }
344
345 static inline int RT_usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
346 {
347 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
348 }
349
350 static u8 rtw_init_intf_priv(struct dvobj_priv *dvobj)
351 {
352 u8 rst = _SUCCESS;
353
354 #ifdef CONFIG_USB_VENDOR_REQ_MUTEX
355 _rtw_mutex_init(&dvobj->usb_vendor_req_mutex);
356 #endif
357
358
359 #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
360 dvobj->usb_alloc_vendor_req_buf = rtw_zmalloc(MAX_USB_IO_CTL_SIZE);
361 if (dvobj->usb_alloc_vendor_req_buf == NULL) {
362 DBG_871X("alloc usb_vendor_req_buf failed... /n");
363 rst = _FAIL;
364 goto exit;
365 }
366 dvobj->usb_vendor_req_buf =
367 (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(dvobj->usb_alloc_vendor_req_buf ), ALIGNMENT_UNIT);
368 exit:
369 #endif
370
371 return rst;
372
373 }
374
375 static u8 rtw_deinit_intf_priv(struct dvobj_priv *dvobj)
376 {
377 u8 rst = _SUCCESS;
378
379 #ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
380 if(dvobj->usb_vendor_req_buf)
381 rtw_mfree(dvobj->usb_alloc_vendor_req_buf, MAX_USB_IO_CTL_SIZE);
382 #endif
383
384 #ifdef CONFIG_USB_VENDOR_REQ_MUTEX
385 _rtw_mutex_free(&dvobj->usb_vendor_req_mutex);
386 #endif
387
388 return rst;
389 }
390
391 static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)
392 {
393 int i;
394 u8 val8;
395 int status = _FAIL;
396 struct dvobj_priv *pdvobjpriv = NULL;
397 struct usb_device *pusbd;
398 struct usb_device_descriptor *pdev_desc;
399 struct usb_host_config *phost_conf;
400 struct usb_config_descriptor *pconf_desc;
401 struct usb_host_interface *phost_iface;
402 struct usb_interface_descriptor *piface_desc;
403 struct usb_host_endpoint *phost_endp;
404 struct usb_endpoint_descriptor *pendp_desc;
405
406 _func_enter_;
407
408 if((pdvobjpriv = devobj_init()) == NULL) {
409 goto exit;
410 }
411
412 pdvobjpriv->pusbintf = usb_intf ;
413 pusbd = pdvobjpriv->pusbdev = interface_to_usbdev(usb_intf);
414 usb_set_intfdata(usb_intf, pdvobjpriv);
415
416 pdvobjpriv->RtNumInPipes = 0;
417 pdvobjpriv->RtNumOutPipes = 0;
418
419
420 pdev_desc = &pusbd->descriptor;
421 #if 0
422 DBG_871X("\n8712_usb_device_descriptor:\n");
423 DBG_871X("bLength=%x\n", pdev_desc->bLength);
424 DBG_871X("bDescriptorType=%x\n", pdev_desc->bDescriptorType);
425 DBG_871X("bcdUSB=%x\n", pdev_desc->bcdUSB);
426 DBG_871X("bDeviceClass=%x\n", pdev_desc->bDeviceClass);
427 DBG_871X("bDeviceSubClass=%x\n", pdev_desc->bDeviceSubClass);
428 DBG_871X("bDeviceProtocol=%x\n", pdev_desc->bDeviceProtocol);
429 DBG_871X("bMaxPacketSize0=%x\n", pdev_desc->bMaxPacketSize0);
430 DBG_871X("idVendor=%x\n", pdev_desc->idVendor);
431 DBG_871X("idProduct=%x\n", pdev_desc->idProduct);
432 DBG_871X("bcdDevice=%x\n", pdev_desc->bcdDevice);
433 DBG_871X("iManufacturer=%x\n", pdev_desc->iManufacturer);
434 DBG_871X("iProduct=%x\n", pdev_desc->iProduct);
435 DBG_871X("iSerialNumber=%x\n", pdev_desc->iSerialNumber);
436 DBG_871X("bNumConfigurations=%x\n", pdev_desc->bNumConfigurations);
437 #endif
438
439 phost_conf = pusbd->actconfig;
440 pconf_desc = &phost_conf->desc;
441
442 #if 0
443 DBG_871X("\n8712_usb_configuration_descriptor:\n");
444 DBG_871X("bLength=%x\n", pconf_desc->bLength);
445 DBG_871X("bDescriptorType=%x\n", pconf_desc->bDescriptorType);
446 DBG_871X("wTotalLength=%x\n", pconf_desc->wTotalLength);
447 DBG_871X("bNumInterfaces=%x\n", pconf_desc->bNumInterfaces);
448 DBG_871X("bConfigurationValue=%x\n", pconf_desc->bConfigurationValue);
449 DBG_871X("iConfiguration=%x\n", pconf_desc->iConfiguration);
450 DBG_871X("bmAttributes=%x\n", pconf_desc->bmAttributes);
451 DBG_871X("bMaxPower=%x\n", pconf_desc->bMaxPower);
452 #endif
453
454 //DBG_871X("\n/****** num of altsetting = (%d) ******/\n", usb_intf->num_altsetting);
455
456 phost_iface = &usb_intf->altsetting[0];
457 piface_desc = &phost_iface->desc;
458
459 #if 0
460 DBG_871X("\n8712_usb_interface_descriptor:\n");
461 DBG_871X("bLength=%x\n", piface_desc->bLength);
462 DBG_871X("bDescriptorType=%x\n", piface_desc->bDescriptorType);
463 DBG_871X("bInterfaceNumber=%x\n", piface_desc->bInterfaceNumber);
464 DBG_871X("bAlternateSetting=%x\n", piface_desc->bAlternateSetting);
465 DBG_871X("bNumEndpoints=%x\n", piface_desc->bNumEndpoints);
466 DBG_871X("bInterfaceClass=%x\n", piface_desc->bInterfaceClass);
467 DBG_871X("bInterfaceSubClass=%x\n", piface_desc->bInterfaceSubClass);
468 DBG_871X("bInterfaceProtocol=%x\n", piface_desc->bInterfaceProtocol);
469 DBG_871X("iInterface=%x\n", piface_desc->iInterface);
470 #endif
471
472 pdvobjpriv->NumInterfaces = pconf_desc->bNumInterfaces;
473 pdvobjpriv->InterfaceNumber = piface_desc->bInterfaceNumber;
474 pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
475
476 //DBG_871X("\ndump usb_endpoint_descriptor:\n");
477
478 for (i = 0; i < pdvobjpriv->nr_endpoint; i++)
479 {
480 phost_endp = phost_iface->endpoint + i;
481 if (phost_endp)
482 {
483 pendp_desc = &phost_endp->desc;
484
485 DBG_871X("\nusb_endpoint_descriptor(%d):\n", i);
486 DBG_871X("bLength=%x\n",pendp_desc->bLength);
487 DBG_871X("bDescriptorType=%x\n",pendp_desc->bDescriptorType);
488 DBG_871X("bEndpointAddress=%x\n",pendp_desc->bEndpointAddress);
489 //DBG_871X("bmAttributes=%x\n",pendp_desc->bmAttributes);
490 //DBG_871X("wMaxPacketSize=%x\n",pendp_desc->wMaxPacketSize);
491 DBG_871X("wMaxPacketSize=%x\n",le16_to_cpu(pendp_desc->wMaxPacketSize));
492 DBG_871X("bInterval=%x\n",pendp_desc->bInterval);
493 //DBG_871X("bRefresh=%x\n",pendp_desc->bRefresh);
494 //DBG_871X("bSynchAddress=%x\n",pendp_desc->bSynchAddress);
495
496 if (RT_usb_endpoint_is_bulk_in(pendp_desc))
497 {
498 DBG_871X("RT_usb_endpoint_is_bulk_in = %x\n", RT_usb_endpoint_num(pendp_desc));
499 pdvobjpriv->RtNumInPipes++;
500 }
501 else if (RT_usb_endpoint_is_int_in(pendp_desc))
502 {
503 DBG_871X("RT_usb_endpoint_is_int_in = %x, Interval = %x\n", RT_usb_endpoint_num(pendp_desc),pendp_desc->bInterval);
504 pdvobjpriv->RtNumInPipes++;
505 }
506 else if (RT_usb_endpoint_is_bulk_out(pendp_desc))
507 {
508 DBG_871X("RT_usb_endpoint_is_bulk_out = %x\n", RT_usb_endpoint_num(pendp_desc));
509 pdvobjpriv->RtNumOutPipes++;
510 }
511 pdvobjpriv->ep_num[i] = RT_usb_endpoint_num(pendp_desc);
512 }
513 }
514
515 DBG_871X("nr_endpoint=%d, in_num=%d, out_num=%d\n\n", pdvobjpriv->nr_endpoint, pdvobjpriv->RtNumInPipes, pdvobjpriv->RtNumOutPipes);
516
517 if (pusbd->speed == USB_SPEED_HIGH) {
518 pdvobjpriv->ishighspeed = _TRUE;
519 DBG_871X("USB_SPEED_HIGH\n");
520 } else {
521 pdvobjpriv->ishighspeed = _FALSE;
522 DBG_871X("NON USB_SPEED_HIGH\n");
523 }
524
525 if (rtw_init_intf_priv(pdvobjpriv) == _FAIL) {
526 RT_TRACE(_module_os_intfs_c_,_drv_err_,("\n Can't INIT rtw_init_intf_priv\n"));
527 goto free_dvobj;
528 }
529
530 //.3 misc
531 _rtw_init_sema(&(pdvobjpriv->usb_suspend_sema), 0);
532
533 rtw_reset_continual_urb_error(pdvobjpriv);
534
535 usb_get_dev(pusbd);
536
537 //DBG_871X("%s %d\n", __func__, ATOMIC_READ(&usb_intf->dev.kobj.kref.refcount));
538
539 status = _SUCCESS;
540
541 free_dvobj:
542 if (status != _SUCCESS && pdvobjpriv) {
543 usb_set_intfdata(usb_intf, NULL);
544 devobj_deinit(pdvobjpriv);
545 pdvobjpriv = NULL;
546 }
547 exit:
548 _func_exit_;
549 return pdvobjpriv;
550 }
551
552 static void usb_dvobj_deinit(struct usb_interface *usb_intf)
553 {
554 struct dvobj_priv *dvobj = usb_get_intfdata(usb_intf);
555
556 _func_enter_;
557
558 usb_set_intfdata(usb_intf, NULL);
559 if (dvobj) {
560 //Modify condition for 92DU DMDP 2010.11.18, by Thomas
561 /*if ((dvobj->NumInterfaces == 1)
562 || ((dvobj->InterfaceNumber == 1) && (dvobj->DualMacMode == _TRUE))) {
563 if (interface_to_usbdev(usb_intf)->state != USB_STATE_NOTATTACHED) {
564 //If we didn't unplug usb dongle and remove/insert modlue, driver fails on sitesurvey for the first time when device is up .
565 //Reset usb port for sitesurvey fail issue. 2009.8.13, by Thomas
566 DBG_871X("usb attached..., try to reset usb device\n");
567 usb_reset_device(interface_to_usbdev(usb_intf));
568 }
569 }*/
570 rtw_deinit_intf_priv(dvobj);
571 devobj_deinit(dvobj);
572 }
573
574 //DBG_871X("%s %d\n", __func__, ATOMIC_READ(&usb_intf->dev.kobj.kref.refcount));
575 usb_put_dev(interface_to_usbdev(usb_intf));
576
577 _func_exit_;
578 }
579
580 static void decide_chip_type_by_usb_device_id(_adapter *padapter, const struct usb_device_id *pdid)
581 {
582 padapter->chip_type = NULL_CHIP_TYPE;
583 #ifdef CONFIG_RTL8192C
584 padapter->chip_type = RTL8188C_8192C;
585 padapter->HardwareType = HARDWARE_TYPE_RTL8192CU;
586 DBG_871X("CHIP TYPE: RTL8188C_8192C\n");
587 #endif
588
589 #ifdef CONFIG_RTL8192D
590 padapter->chip_type = RTL8192D;
591 padapter->HardwareType = HARDWARE_TYPE_RTL8192DU;
592 DBG_871X("CHIP TYPE: RTL8192D\n");
593 #endif
594 }
595
596 static void usb_intf_start(_adapter *padapter)
597 {
598 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+usb_intf_start\n"));
599 rtw_hal_inirp_init(padapter);
600 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-usb_intf_start\n"));
601 }
602
603 static void usb_intf_stop(_adapter *padapter)
604 {
605
606 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+usb_intf_stop\n"));
607
608 //disabel_hw_interrupt
609 if(padapter->bSurpriseRemoved == _FALSE)
610 {
611 //device still exists, so driver can do i/o operation
612 //TODO:
613 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("SurpriseRemoved==_FALSE\n"));
614 }
615
616 //cancel in irp
617 rtw_hal_inirp_deinit(padapter);
618
619 //cancel out irp
620 rtw_write_port_cancel(padapter);
621
622 //todo:cancel other irps
623
624 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-usb_intf_stop\n"));
625
626 }
627
628 static void rtw_dev_unload(_adapter *padapter)
629 {
630 struct net_device *pnetdev= (struct net_device*)padapter->pnetdev;
631 u8 val8;
632 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+rtw_dev_unload\n"));
633
634 if(padapter->bup == _TRUE)
635 {
636 DBG_871X("===> rtw_dev_unload\n");
637
638 padapter->bDriverStopped = _TRUE;
639 #ifdef CONFIG_XMIT_ACK
640 if (padapter->xmitpriv.ack_tx)
641 rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP);
642 #endif
643
644 //s3.
645 if(padapter->intf_stop)
646 {
647 padapter->intf_stop(padapter);
648 }
649
650 //s4.
651 if(!padapter->pwrctrlpriv.bInternalAutoSuspend )
652 rtw_stop_drv_threads(padapter);
653
654
655 //s5.
656 if(padapter->bSurpriseRemoved == _FALSE)
657 {
658 //DBG_871X("r871x_dev_unload()->rtl871x_hal_deinit()\n");
659 #ifdef CONFIG_WOWLAN
660 if((padapter->pwrctrlpriv.bSupportRemoteWakeup==_TRUE)&&(padapter->pwrctrlpriv.wowlan_mode==_TRUE)){
661 DBG_871X("%s bSupportWakeOnWlan==_TRUE do not run rtw_hal_deinit()\n",__FUNCTION__);
662 }
663 else
664 #endif //CONFIG_WOWLAN
665 {
666 rtw_hal_deinit(padapter);
667 }
668 padapter->bSurpriseRemoved = _TRUE;
669 }
670
671 padapter->bup = _FALSE;
672 #ifdef CONFIG_WOWLAN
673 padapter->hw_init_completed=_FALSE;
674 #endif //CONFIG_WOWLAN
675 }
676 else
677 {
678 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("r871x_dev_unload():padapter->bup == _FALSE\n" ));
679 }
680
681 DBG_871X("<=== rtw_dev_unload\n");
682
683 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-rtw_dev_unload\n"));
684
685 }
686
687 static void process_spec_devid(const struct usb_device_id *pdid)
688 {
689 u16 vid, pid;
690 u32 flags;
691 int i;
692 int num = sizeof(specific_device_id_tbl)/sizeof(struct specific_device_id);
693
694 for(i=0; i<num; i++)
695 {
696 vid = specific_device_id_tbl[i].idVendor;
697 pid = specific_device_id_tbl[i].idProduct;
698 flags = specific_device_id_tbl[i].flags;
699
700 #ifdef CONFIG_80211N_HT
701 if((pdid->idVendor==vid) && (pdid->idProduct==pid) && (flags&SPEC_DEV_ID_DISABLE_HT))
702 {
703 rtw_ht_enable = 0;
704 rtw_cbw40_enable = 0;
705 rtw_ampdu_enable = 0;
706 }
707 #endif
708
709 #ifdef RTK_DMP_PLATFORM
710 // Change the ifname to wlan10 when PC side WFD dongle plugin on DMP platform.
711 // It is used to distinguish between normal and PC-side wifi dongle/module.
712 if((pdid->idVendor==vid) && (pdid->idProduct==pid) && (flags&SPEC_DEV_ID_ASSIGN_IFNAME))
713 {
714 extern char* ifname;
715 strncpy(ifname, "wlan10", 6);
716 //DBG_871X("%s()-%d: ifname=%s, vid=%04X, pid=%04X\n", __FUNCTION__, __LINE__, ifname, vid, pid);
717 }
718 #endif /* RTK_DMP_PLATFORM */
719
720 }
721 }
722
723 #ifdef SUPPORT_HW_RFOFF_DETECTED
724 int rtw_hw_suspend(_adapter *padapter )
725 {
726 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
727 struct usb_interface *pusb_intf = adapter_to_dvobj(padapter)->pusbintf;
728 struct net_device *pnetdev = padapter->pnetdev;
729
730 _func_enter_;
731
732 if((!padapter->bup) || (padapter->bDriverStopped)||(padapter->bSurpriseRemoved))
733 {
734 DBG_871X("padapter->bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n",
735 padapter->bup, padapter->bDriverStopped,padapter->bSurpriseRemoved);
736 goto error_exit;
737 }
738
739 if(padapter)//system suspend
740 {
741 LeaveAllPowerSaveMode(padapter);
742
743 DBG_871X("==> rtw_hw_suspend\n");
744 _enter_pwrlock(&pwrpriv->lock);
745 pwrpriv->bips_processing = _TRUE;
746 //padapter->net_closed = _TRUE;
747 //s1.
748 if(pnetdev)
749 {
750 netif_carrier_off(pnetdev);
751 rtw_netif_stop_queue(pnetdev);
752 }
753
754 //s2.
755 rtw_disassoc_cmd(padapter, 500, _FALSE);
756
757 //s2-2. indicate disconnect to os
758 //rtw_indicate_disconnect(padapter);
759 {
760 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
761
762 if(check_fwstate(pmlmepriv, _FW_LINKED))
763 {
764 _clr_fwstate_(pmlmepriv, _FW_LINKED);
765
766 rtw_led_control(padapter, LED_CTL_NO_LINK);
767
768 rtw_os_indicate_disconnect(padapter);
769
770 #ifdef CONFIG_LPS
771 //donnot enqueue cmd
772 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_DISCONNECT, 0);
773 #endif
774 }
775
776 }
777 //s2-3.
778 rtw_free_assoc_resources(padapter, 1);
779
780 //s2-4.
781 rtw_free_network_queue(padapter,_TRUE);
782 #ifdef CONFIG_IPS
783 rtw_ips_dev_unload(padapter);
784 #endif
785 pwrpriv->rf_pwrstate = rf_off;
786 pwrpriv->bips_processing = _FALSE;
787
788 _exit_pwrlock(&pwrpriv->lock);
789 }
790 else
791 goto error_exit;
792
793 _func_exit_;
794 return 0;
795
796 error_exit:
797 DBG_871X("%s, failed \n",__FUNCTION__);
798 return (-1);
799
800 }
801
802 int rtw_hw_resume(_adapter *padapter)
803 {
804 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
805 struct usb_interface *pusb_intf = adapter_to_dvobj(padapter)->pusbintf;
806 struct net_device *pnetdev = padapter->pnetdev;
807
808 _func_enter_;
809
810 if(padapter)//system resume
811 {
812 DBG_871X("==> rtw_hw_resume\n");
813 _enter_pwrlock(&pwrpriv->lock);
814 pwrpriv->bips_processing = _TRUE;
815 rtw_reset_drv_sw(padapter);
816
817 if(pm_netdev_open(pnetdev,_FALSE) != 0)
818 {
819 _exit_pwrlock(&pwrpriv->lock);
820 goto error_exit;
821 }
822
823 netif_device_attach(pnetdev);
824 netif_carrier_on(pnetdev);
825
826 if(!rtw_netif_queue_stopped(pnetdev))
827 rtw_netif_start_queue(pnetdev);
828 else
829 rtw_netif_wake_queue(pnetdev);
830
831 pwrpriv->bkeepfwalive = _FALSE;
832 pwrpriv->brfoffbyhw = _FALSE;
833
834 pwrpriv->rf_pwrstate = rf_on;
835 pwrpriv->bips_processing = _FALSE;
836
837 _exit_pwrlock(&pwrpriv->lock);
838 }
839 else
840 {
841 goto error_exit;
842 }
843
844 _func_exit_;
845
846 return 0;
847 error_exit:
848 DBG_871X("%s, Open net dev failed \n",__FUNCTION__);
849 return (-1);
850 }
851 #endif
852
853 static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
854 {
855 struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
856 _adapter *padapter = dvobj->if1;
857 struct net_device *pnetdev = padapter->pnetdev;
858 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
859 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
860 struct usb_device *usb_dev = interface_to_usbdev(pusb_intf);
861 #ifdef CONFIG_WOWLAN
862 struct wowlan_ioctl_param poidparam;
863 #endif // CONFIG_WOWLAN
864 int ret = 0;
865 u32 start_time = rtw_get_current_time();
866 _func_enter_;
867
868 DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid);
869
870 if((!padapter->bup) || (padapter->bDriverStopped)||(padapter->bSurpriseRemoved))
871 {
872 DBG_871X("padapter->bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n",
873 padapter->bup, padapter->bDriverStopped,padapter->bSurpriseRemoved);
874 goto exit;
875 }
876
877 if(pwrpriv->bInternalAutoSuspend )
878 {
879 #ifdef CONFIG_AUTOSUSPEND
880 #ifdef SUPPORT_HW_RFOFF_DETECTED
881 // The FW command register update must after MAC and FW init ready.
882 if((padapter->bFWReady) && ( padapter->pwrctrlpriv.bHWPwrPindetect ) && (padapter->registrypriv.usbss_enable ))
883 {
884 u8 bOpen = _TRUE;
885 rtw_interface_ps_func(padapter,HAL_USB_SELECT_SUSPEND,&bOpen);
886 //rtl8192c_set_FwSelectSuspend_cmd(padapter,_TRUE ,500);//note fw to support hw power down ping detect
887 }
888 #endif
889 #endif
890 }
891 pwrpriv->bInSuspend = _TRUE;
892 rtw_cancel_all_timer(padapter);
893 LeaveAllPowerSaveMode(padapter);
894
895 rtw_stop_cmd_thread(padapter);
896
897 _enter_pwrlock(&pwrpriv->lock);
898 //padapter->net_closed = _TRUE;
899 //s1.
900 if(pnetdev)
901 {
902 netif_carrier_off(pnetdev);
903 rtw_netif_stop_queue(pnetdev);
904 }
905 #ifdef CONFIG_WOWLAN
906 if(padapter->pwrctrlpriv.bSupportRemoteWakeup==_TRUE&&padapter->pwrctrlpriv.wowlan_mode==_TRUE){
907 u8 ps_mode=PS_MODE_MIN;
908 //set H2C command
909 poidparam.subcode=WOWLAN_ENABLE;
910 rtw_hal_set_hwreg(padapter,HW_VAR_WOWLAN,(u8 *)&poidparam);
911 //rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, &ps_mode);
912 //rtw_set_rpwm(padapter, PS_STATE_S2);
913 }
914 else
915 #endif //CONFIG_WOWLAN
916 {
917 //s2.
918 rtw_disassoc_cmd(padapter, 0, _FALSE);
919 }
920
921 #ifdef CONFIG_LAYER2_ROAMING_RESUME
922 if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) && check_fwstate(pmlmepriv, _FW_LINKED) )
923 {
924 //printk("%s:%d assoc_ssid:%s\n", __FUNCTION__, __LINE__, pmlmepriv->assoc_ssid.Ssid);
925 DBG_871X("%s:%d %s(" MAC_FMT "), length:%d assoc_ssid.length:%d\n",__FUNCTION__, __LINE__,
926 pmlmepriv->cur_network.network.Ssid.Ssid,
927 MAC_ARG(pmlmepriv->cur_network.network.MacAddress),
928 pmlmepriv->cur_network.network.Ssid.SsidLength,
929 pmlmepriv->assoc_ssid.SsidLength);
930 rtw_set_roaming(padapter, 1);
931 }
932 #endif
933 //s2-2. indicate disconnect to os
934 rtw_indicate_disconnect(padapter);
935 //s2-3.
936 rtw_free_assoc_resources(padapter, 1);
937 #ifdef CONFIG_AUTOSUSPEND
938 if(!pwrpriv->bInternalAutoSuspend )
939 #endif
940 //s2-4.
941 rtw_free_network_queue(padapter, _TRUE);
942
943 rtw_dev_unload(padapter);
944 #ifdef CONFIG_AUTOSUSPEND
945 pwrpriv->rf_pwrstate = rf_off;
946 pwrpriv->bips_processing = _FALSE;
947 #endif
948 _exit_pwrlock(&pwrpriv->lock);
949
950 if(check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
951 rtw_indicate_scan_done(padapter, 1);
952
953 if(check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
954 rtw_indicate_disconnect(padapter);
955
956 exit:
957 DBG_871X("<=== %s return %d.............. in %dms\n", __FUNCTION__
958 , ret, rtw_get_passing_time_ms(start_time));
959
960 _func_exit_;
961 return ret;
962 }
963
964 static int rtw_resume(struct usb_interface *pusb_intf)
965 {
966 struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
967 _adapter *padapter = dvobj->if1;
968 struct net_device *pnetdev = padapter->pnetdev;
969 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
970 int ret = 0;
971
972 if(pwrpriv->bInternalAutoSuspend ){
973 ret = rtw_resume_process(padapter);
974 } else {
975 #ifdef CONFIG_RESUME_IN_WORKQUEUE
976 rtw_resume_in_workqueue(pwrpriv);
977 #else
978 if (rtw_is_earlysuspend_registered(pwrpriv)
979 #ifdef CONFIG_WOWLAN
980 && !padapter->pwrctrlpriv.wowlan_mode
981 #endif /* CONFIG_WOWLAN */
982 ) {
983 /* jeff: bypass resume here, do in late_resume */
984 rtw_set_do_late_resume(pwrpriv, _TRUE);
985 } else {
986 ret = rtw_resume_process(padapter);
987 }
988 #endif /* CONFIG_RESUME_IN_WORKQUEUE */
989 }
990
991 return ret;
992
993 }
994
995 int rtw_resume_process(_adapter *padapter)
996 {
997 struct net_device *pnetdev;
998 struct pwrctrl_priv *pwrpriv=NULL;
999 int ret = -1;
1000 u32 start_time = rtw_get_current_time();
1001 _func_enter_;
1002
1003 DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid);
1004
1005 if(padapter) {
1006 pnetdev= padapter->pnetdev;
1007 pwrpriv = &padapter->pwrctrlpriv;
1008 } else {
1009 goto exit;
1010 }
1011
1012 _enter_pwrlock(&pwrpriv->lock);
1013 rtw_reset_drv_sw(padapter);
1014 pwrpriv->bkeepfwalive = _FALSE;
1015
1016 DBG_871X("bkeepfwalive(%x)\n",pwrpriv->bkeepfwalive);
1017 if(pm_netdev_open(pnetdev,_TRUE) != 0) {
1018 _exit_pwrlock(&pwrpriv->lock);
1019 goto exit;
1020 }
1021
1022 netif_device_attach(pnetdev);
1023 netif_carrier_on(pnetdev);
1024
1025 #ifdef CONFIG_AUTOSUSPEND
1026 if(pwrpriv->bInternalAutoSuspend )
1027 {
1028 #ifdef CONFIG_AUTOSUSPEND
1029 #ifdef SUPPORT_HW_RFOFF_DETECTED
1030 // The FW command register update must after MAC and FW init ready.
1031 if((padapter->bFWReady) && ( padapter->pwrctrlpriv.bHWPwrPindetect ) && (padapter->registrypriv.usbss_enable ))
1032 {
1033 //rtl8192c_set_FwSelectSuspend_cmd(padapter,_FALSE ,500);//note fw to support hw power down ping detect
1034 u8 bOpen = _FALSE;
1035 rtw_interface_ps_func(padapter,HAL_USB_SELECT_SUSPEND,&bOpen);
1036 }
1037 #endif
1038 #endif
1039
1040 pwrpriv->bInternalAutoSuspend = _FALSE;
1041 pwrpriv->brfoffbyhw = _FALSE;
1042 }
1043 #endif
1044 _exit_pwrlock(&pwrpriv->lock);
1045
1046 if( padapter->pid[1]!=0) {
1047 DBG_871X("pid[1]:%d\n",padapter->pid[1]);
1048 rtw_signal_process(padapter->pid[1], SIGUSR2);
1049 }
1050
1051 #ifdef CONFIG_LAYER2_ROAMING_RESUME
1052 rtw_roaming(padapter, NULL);
1053 #endif
1054
1055 ret = 0;
1056 exit:
1057 #ifdef CONFIG_RESUME_IN_WORKQUEUE
1058 rtw_unlock_suspend();
1059 #endif //CONFIG_RESUME_IN_WORKQUEUE
1060
1061 if (pwrpriv)
1062 pwrpriv->bInSuspend = _FALSE;
1063 DBG_871X("<=== %s return %d.............. in %dms\n", __FUNCTION__
1064 , ret, rtw_get_passing_time_ms(start_time));
1065
1066 _func_exit_;
1067
1068 return ret;
1069 }
1070
1071 #ifdef CONFIG_AUTOSUSPEND
1072 void autosuspend_enter(_adapter* padapter)
1073 {
1074 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
1075 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1076
1077 pwrpriv->bInternalAutoSuspend = _TRUE;
1078 pwrpriv->bips_processing = _TRUE;
1079
1080 DBG_871X("==>autosuspend_enter...........\n");
1081
1082 if(rf_off == pwrpriv->change_rfpwrstate )
1083 {
1084 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1085 usb_enable_autosuspend(dvobj->pusbdev);
1086 #else
1087 dvobj->pusbdev->autosuspend_disabled = 0;//autosuspend disabled by the user
1088 #endif
1089
1090 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1091 usb_autopm_put_interface(dvobj->pusbintf);
1092 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1093 usb_autopm_enable(dvobj->pusbintf);
1094 #else
1095 usb_autosuspend_device(dvobj->pusbdev, 1);
1096 #endif
1097 }
1098 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1099 DBG_871X("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1100 #else
1101 DBG_871X("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1102 #endif
1103
1104 }
1105 int autoresume_enter(_adapter* padapter)
1106 {
1107 int result = _SUCCESS;
1108 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
1109 struct security_priv* psecuritypriv=&(padapter->securitypriv);
1110 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1111 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1112 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1113
1114
1115 DBG_871X("====> autoresume_enter \n");
1116
1117 if(rf_off == pwrpriv->rf_pwrstate )
1118 {
1119 pwrpriv->ps_flag = _FALSE;
1120 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1121 if (usb_autopm_get_interface(dvobj->pusbintf) < 0)
1122 {
1123 DBG_871X( "can't get autopm: %d\n", result);
1124 result = _FAIL;
1125 goto error_exit;
1126 }
1127 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1128 usb_autopm_disable(dvobj->pusbintf);
1129 #else
1130 usb_autoresume_device(dvobj->pusbdev, 1);
1131 #endif
1132
1133 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1134 DBG_871X("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1135 #else
1136 DBG_871X("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1137 #endif
1138 }
1139 DBG_871X("<==== autoresume_enter \n");
1140 error_exit:
1141
1142 return result;
1143 }
1144 #endif
1145
1146 #ifdef CONFIG_PLATFORM_RTD2880B
1147 extern void rtd2885_wlan_netlink_sendMsg(char *action_string, char *name);
1148 #endif
1149
1150 #ifdef CONFIG_PLATFORM_ARM_SUNxI
1151 #include <mach/sys_config.h>
1152 extern int sw_usb_disable_hcd(__u32 usbc_no);
1153 extern int sw_usb_enable_hcd(__u32 usbc_no);
1154 static int usb_wifi_host = 2;
1155 #endif
1156
1157 #ifdef CONFIG_PLATFORM_ARM_SUN6I
1158 #include <mach/sys_config.h>
1159 extern int sw_usb_disable_hcd(__u32 usbc_no);
1160 extern int sw_usb_enable_hcd(__u32 usbc_no);
1161 extern void wifi_pm_power(int on);
1162 static script_item_u item;
1163 #endif
1164
1165 _adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
1166 struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
1167 {
1168 _adapter *padapter = NULL;
1169 struct net_device *pnetdev = NULL;
1170 int status = _FAIL;
1171
1172 if ((padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter))) == NULL) {
1173 goto exit;
1174 }
1175 padapter->dvobj = dvobj;
1176 dvobj->if1 = padapter;
1177
1178 padapter->bDriverStopped=_TRUE;
1179
1180 dvobj->padapters[dvobj->iface_nums++] = padapter;
1181 padapter->iface_id = IFACE_ID0;
1182
1183 #if defined(CONFIG_CONCURRENT_MODE) || defined(CONFIG_DUALMAC_CONCURRENT)
1184 //set adapter_type/iface type for primary padapter
1185 padapter->isprimary = _TRUE;
1186 padapter->adapter_type = PRIMARY_ADAPTER;
1187 #ifndef CONFIG_HWPORT_SWAP
1188 padapter->iface_type = IFACE_PORT0;
1189 #else
1190 padapter->iface_type = IFACE_PORT1;
1191 #endif
1192 #endif
1193
1194 #ifndef RTW_DVOBJ_CHIP_HW_TYPE
1195 //step 1-1., decide the chip_type via vid/pid
1196 padapter->interface_type = RTW_USB;
1197 decide_chip_type_by_usb_device_id(padapter, pdid);
1198 #endif
1199
1200 if((pnetdev = rtw_init_netdev(padapter)) == NULL) {
1201 goto free_adapter;
1202 }
1203 SET_NETDEV_DEV(pnetdev, dvobj_to_dev(dvobj));
1204 padapter = rtw_netdev_priv(pnetdev);
1205
1206 //step 2. hook HalFunc, allocate HalData
1207 if(padapter->chip_type == RTL8188C_8192C) {
1208 #ifdef CONFIG_RTL8192C
1209 rtl8192cu_set_hal_ops(padapter);
1210 #endif
1211 } else if(padapter->chip_type == RTL8192D) {
1212 #ifdef CONFIG_RTL8192D
1213 rtl8192du_set_hal_ops(padapter);
1214 #endif
1215 } else {
1216 DBG_871X("Detect NULL_CHIP_TYPE\n");
1217 goto free_hal_data;
1218 }
1219
1220 //step 3.
1221 padapter->intf_start=&usb_intf_start;
1222 padapter->intf_stop=&usb_intf_stop;
1223
1224 //.2
1225 if ((rtw_init_io_priv(padapter, usb_set_intf_ops)) == _FAIL) {
1226 RT_TRACE(_module_hci_intfs_c_,_drv_err_,(" \n Can't init io_reqs\n"));
1227 goto free_hal_data;
1228 }
1229
1230 rtw_hal_read_chip_version(padapter);
1231
1232 //.4 usb endpoint mapping
1233 rtw_hal_chip_configure(padapter);
1234
1235 //step 4. read efuse/eeprom data and get mac_addr
1236 rtw_hal_read_chip_info(padapter);
1237
1238 if (rtw_handle_dualmac(padapter, 1) != _SUCCESS)
1239 goto free_hal_data;
1240
1241 #ifdef CONFIG_IOCTL_CFG80211
1242 if(rtw_wdev_alloc(padapter, dvobj_to_dev(dvobj)) != 0) {
1243 goto handle_dualmac;
1244 }
1245 #endif
1246
1247 //step 5.
1248 if (rtw_init_drv_sw(padapter) == _FAIL) {
1249 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("Initialize driver software resource Failed!\n"));
1250 goto free_wdev;
1251 }
1252
1253 #ifdef CONFIG_PM
1254 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18))
1255 if(padapter->pwrctrlpriv.bSupportRemoteWakeup)
1256 {
1257 dvobj->pusbdev->do_remote_wakeup=1;
1258 pusb_intf->needs_remote_wakeup = 1;
1259 device_init_wakeup(&pusb_intf->dev, 1);
1260 DBG_871X("\n padapter->pwrctrlpriv.bSupportRemoteWakeup~~~~~~\n");
1261 DBG_871X("\n padapter->pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n",device_may_wakeup(&pusb_intf->dev));
1262 }
1263 #endif
1264 #endif
1265
1266 #ifdef CONFIG_AUTOSUSPEND
1267 if( padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE )
1268 {
1269 if(padapter->registrypriv.usbss_enable ){ /* autosuspend (2s delay) */
1270 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,38))
1271 dvobj->pusbdev->dev.power.autosuspend_delay = 0 * HZ;//15 * HZ; idle-delay time
1272 #else
1273 dvobj->pusbdev->autosuspend_delay = 0 * HZ;//15 * HZ; idle-delay time
1274 #endif
1275
1276 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1277 usb_enable_autosuspend(dvobj->pusbdev);
1278 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22) && LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,34))
1279 padapter->bDisableAutosuspend = dvobj->pusbdev->autosuspend_disabled ;
1280 dvobj->pusbdev->autosuspend_disabled = 0;//autosuspend disabled by the user
1281 #endif
1282
1283 usb_autopm_get_interface(dvobj->pusbintf );//init pm_usage_cnt ,let it start from 1
1284
1285 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1286 DBG_871X("%s...pm_usage_cnt(%d).....\n",__FUNCTION__, atomic_read(&(dvobj->pusbintf ->pm_usage_cnt)));
1287 #else
1288 DBG_871X("%s...pm_usage_cnt(%d).....\n",__FUNCTION__, dvobj->pusbintf ->pm_usage_cnt);
1289 #endif
1290 }
1291 }
1292 #endif
1293
1294 // set mac addr
1295 rtw_macaddr_cfg(padapter->eeprompriv.mac_addr);
1296 rtw_init_wifidirect_addrs(padapter, padapter->eeprompriv.mac_addr, padapter->eeprompriv.mac_addr);
1297
1298 DBG_871X("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d, hw_init_completed:%d\n"
1299 ,padapter->bDriverStopped
1300 ,padapter->bSurpriseRemoved
1301 ,padapter->bup
1302 ,padapter->hw_init_completed
1303 );
1304
1305 status = _SUCCESS;
1306
1307 free_wdev:
1308 if(status != _SUCCESS) {
1309 #ifdef CONFIG_IOCTL_CFG80211
1310 rtw_wdev_unregister(padapter->rtw_wdev);
1311 rtw_wdev_free(padapter->rtw_wdev);
1312 #endif
1313 }
1314 handle_dualmac:
1315 if (status != _SUCCESS)
1316 rtw_handle_dualmac(padapter, 0);
1317 free_hal_data:
1318 if(status != _SUCCESS && padapter->HalData)
1319 rtw_mfree(padapter->HalData, sizeof(*(padapter->HalData)));
1320 free_adapter:
1321 if (status != _SUCCESS) {
1322 if (pnetdev)
1323 rtw_free_netdev(pnetdev);
1324 else if (padapter)
1325 rtw_vmfree((u8*)padapter, sizeof(*padapter));
1326 padapter = NULL;
1327 }
1328 exit:
1329 return padapter;
1330 }
1331
1332 static void rtw_usb_if1_deinit(_adapter *if1)
1333 {
1334 struct net_device *pnetdev = if1->pnetdev;
1335 struct mlme_priv *pmlmepriv= &if1->mlmepriv;
1336
1337 if(check_fwstate(pmlmepriv, _FW_LINKED))
1338 rtw_disassoc_cmd(if1, 0, _FALSE);
1339
1340 #ifdef CONFIG_AP_MODE
1341 free_mlme_ap_info(if1);
1342 #ifdef CONFIG_HOSTAPD_MLME
1343 hostapd_mode_unload(if1);
1344 #endif
1345 #endif
1346
1347 rtw_cancel_all_timer(if1);
1348 #ifdef CONFIG_WOWLAN
1349 if1->pwrctrlpriv.wowlan_mode=_FALSE;
1350 #endif //CONFIG_WOWLAN
1351 rtw_dev_unload(if1);
1352
1353 DBG_871X("%s, hw_init_completed=%d\n", __func__, if1->hw_init_completed);
1354
1355 //s6.
1356 rtw_handle_dualmac(if1, 0);
1357
1358 #ifdef CONFIG_IOCTL_CFG80211
1359 if (if1->rtw_wdev)
1360 rtw_wdev_free(if1->rtw_wdev);
1361 #endif //CONFIG_IOCTL_CFG80211
1362
1363 rtw_free_drv_sw(if1);
1364
1365 if(pnetdev)
1366 rtw_free_netdev(pnetdev);
1367
1368 #ifdef CONFIG_PLATFORM_RTD2880B
1369 DBG_871X("wlan link down\n");
1370 rtd2885_wlan_netlink_sendMsg("linkdown", "8712");
1371 #endif
1372
1373 }
1374
1375 /*
1376 * drv_init() - a device potentially for us
1377 *
1378 * notes: drv_init() is called when the bus driver has located a card for us to support.
1379 * We accept the new device by returning 0.
1380 */
1381
1382 _adapter *rtw_sw_export = NULL;
1383
1384 static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *did)
1385 {
1386 int i;
1387 uint status = _FAIL;
1388 _adapter *if1 = NULL, *if2 = NULL;
1389 struct dvobj_priv *dvobj = NULL;
1390
1391
1392 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_drv_init\n"));
1393
1394
1395 //step 0.
1396 process_spec_devid(did);
1397
1398 /* Initialize dvobj_priv */
1399 if ((dvobj = usb_dvobj_init(pusb_intf)) == NULL) {
1400 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("initialize device object priv Failed!\n"));
1401 goto exit;
1402 }
1403
1404 /* Initialize if1 */
1405 if ((if1 = rtw_usb_if1_init(dvobj, pusb_intf, did)) == NULL) {
1406 DBG_871X("rtw_usb_if1_init Failed!\n");
1407 goto free_dvobj;
1408 }
1409
1410 /* Initialize if2 */
1411 #ifdef CONFIG_CONCURRENT_MODE
1412 if((if2 = rtw_drv_if2_init(if1, usb_set_intf_ops)) == NULL) {
1413 goto free_if1;
1414 }
1415 #ifdef CONFIG_MULTI_VIR_IFACES
1416 for(i=0; i<if1->registrypriv.ext_iface_num;i++)
1417 {
1418 if(rtw_drv_add_vir_if(if1, usb_set_intf_ops) == NULL)
1419 {
1420 DBG_871X("rtw_drv_add_iface failed! (%d)\n", i);
1421 goto free_if1;
1422 }
1423 }
1424 #endif //CONFIG_MULTI_VIR_IFACES
1425 #endif
1426
1427 #ifdef CONFIG_INTEL_PROXIM
1428 rtw_sw_export=if1;
1429 #endif
1430
1431 #ifdef CONFIG_GLOBAL_UI_PID
1432 if (ui_pid[1]!=0) {
1433 DBG_871X("ui_pid[1]:%d\n",ui_pid[1]);
1434 rtw_signal_process(ui_pid[1], SIGUSR2);
1435 }
1436 #endif
1437
1438 //dev_alloc_name && register_netdev
1439 if((status = rtw_drv_register_netdev(if1)) != _SUCCESS) {
1440 goto free_if1;
1441 }
1442
1443 #ifdef CONFIG_HOSTAPD_MLME
1444 hostapd_mode_init(if1);
1445 #endif
1446
1447 #ifdef CONFIG_PLATFORM_RTD2880B
1448 DBG_871X("wlan link up\n");
1449 rtd2885_wlan_netlink_sendMsg("linkup", "8712");
1450 #endif
1451
1452 #ifdef RTK_DMP_PLATFORM
1453 rtw_proc_init_one(if1->pnetdev);
1454 #endif
1455
1456 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-871x_drv - drv_init, success!\n"));
1457
1458 status = _SUCCESS;
1459
1460 free_if1:
1461 if (status != _SUCCESS && if1) {
1462 rtw_usb_if1_deinit(if1);
1463 }
1464 free_dvobj:
1465 if (status != _SUCCESS)
1466 usb_dvobj_deinit(pusb_intf);
1467 exit:
1468 return status == _SUCCESS?0:-ENODEV;
1469 }
1470
1471 /*
1472 * dev_remove() - our device is being removed
1473 */
1474 //rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove() => how to recognize both
1475 static void rtw_dev_remove(struct usb_interface *pusb_intf)
1476 {
1477 struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
1478 _adapter *padapter = dvobj->if1;
1479
1480 _func_exit_;
1481
1482 DBG_871X("+rtw_dev_remove\n");
1483 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+dev_remove()\n"));
1484
1485 dvobj->processing_dev_remove = _TRUE;
1486
1487 rtw_unregister_netdevs(dvobj);
1488
1489 if(usb_drv->drv_registered == _TRUE)
1490 {
1491 //DBG_871X("r871xu_dev_remove():padapter->bSurpriseRemoved == _TRUE\n");
1492 padapter->bSurpriseRemoved = _TRUE;
1493 }
1494 /*else
1495 {
1496 //DBG_871X("r871xu_dev_remove():module removed\n");
1497 padapter->hw_init_completed = _FALSE;
1498 }*/
1499
1500 #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
1501 rtw_unregister_early_suspend(&padapter->pwrctrlpriv);
1502 #endif
1503
1504 rtw_pm_set_ips(padapter, IPS_NONE);
1505 rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
1506
1507 LeaveAllPowerSaveMode(padapter);
1508
1509 #ifdef CONFIG_CONCURRENT_MODE
1510 #ifdef CONFIG_MULTI_VIR_IFACES
1511 rtw_drv_stop_vir_ifaces(dvobj);
1512 #endif //CONFIG_MULTI_VIR_IFACES
1513 rtw_drv_if2_stop(dvobj->if2);
1514 #endif //CONFIG_CONCURRENT_MODE
1515
1516 rtw_usb_if1_deinit(padapter);
1517
1518 #ifdef CONFIG_CONCURRENT_MODE
1519 #ifdef CONFIG_MULTI_VIR_IFACES
1520 rtw_drv_free_vir_ifaces(dvobj);
1521 #endif //CONFIG_MULTI_VIR_IFACES
1522 rtw_drv_if2_free(dvobj->if2);
1523 #endif //CONFIG_CONCURRENT_MODE
1524
1525 usb_dvobj_deinit(pusb_intf);
1526
1527 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-dev_remove()\n"));
1528 DBG_871X("-r871xu_dev_remove, done\n");
1529
1530
1531 #ifdef CONFIG_INTEL_PROXIM
1532 rtw_sw_export=NULL;
1533 #endif
1534
1535 _func_exit_;
1536
1537 return;
1538
1539 }
1540 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
1541 extern int console_suspend_enabled;
1542 #endif
1543
1544 static int __init rtw_drv_entry(void)
1545 {
1546 #ifdef CONFIG_PLATFORM_RTK_DMP
1547 u32 tmp;
1548 tmp=readl((volatile unsigned int*)0xb801a608);
1549 tmp &= 0xffffff00;
1550 tmp |= 0x55;
1551 writel(tmp,(volatile unsigned int*)0xb801a608);//write dummy register for 1055
1552 #endif
1553 #ifdef CONFIG_PLATFORM_ARM_SUNxI
1554 #ifndef CONFIG_RTL8723A
1555 int ret = 0;
1556 /* ----------get usb_wifi_usbc_num------------- */
1557 ret = script_parser_fetch("usb_wifi_para", "usb_wifi_usbc_num", (int *)&usb_wifi_host, 64);
1558 if(ret != 0){
1559 printk("ERR: script_parser_fetch usb_wifi_usbc_num failed\n");
1560 ret = -ENOMEM;
1561 return ret;
1562 }
1563 printk("sw_usb_enable_hcd: usbc_num = %d\n", usb_wifi_host);
1564 sw_usb_enable_hcd(usb_wifi_host);
1565 #endif //CONFIG_RTL8723A
1566 #endif //CONFIG_PLATFORM_ARM_SUNxI
1567
1568 #ifdef CONFIG_PLATFORM_ARM_SUN6I
1569 script_item_value_type_e type;
1570
1571 type = script_get_item("wifi_para", "wifi_usbc_id", &item);
1572 if(SCIRPT_ITEM_VALUE_TYPE_INT != type){
1573 printk("ERR: script_get_item wifi_usbc_id failed\n");
1574 return -ENOMEM;
1575 }
1576
1577 printk("sw_usb_enable_hcd: usbc_num = %d\n", item.val);
1578 wifi_pm_power(1);
1579 mdelay(10);
1580 sw_usb_enable_hcd(item.val);
1581 #endif //CONFIG_PLATFORM_ARM_SUN6I
1582
1583 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+rtw_drv_entry\n"));
1584
1585 DBG_871X(DRV_NAME " driver version=%s\n", DRIVERVERSION);
1586 DBG_871X("build time: %s %s\n", __DATE__, __TIME__);
1587
1588 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
1589 //console_suspend_enabled=0;
1590 #endif
1591
1592 rtw_suspend_lock_init();
1593
1594 usb_drv->drv_registered = _TRUE;
1595 return usb_register(&usb_drv->usbdrv);
1596 }
1597
1598 static void __exit rtw_drv_halt(void)
1599 {
1600 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+rtw_drv_halt\n"));
1601 DBG_871X("+rtw_drv_halt\n");
1602
1603 usb_drv->drv_registered = _FALSE;
1604 usb_deregister(&usb_drv->usbdrv);
1605
1606 #ifdef CONFIG_PLATFORM_ARM_SUNxI
1607 #ifndef CONFIG_RTL8723A
1608 printk("sw_usb_disable_hcd: usbc_num = %d\n", usb_wifi_host);
1609 sw_usb_disable_hcd(usb_wifi_host);
1610 #endif //ifndef CONFIG_RTL8723A
1611 #endif //CONFIG_PLATFORM_ARM_SUNxI
1612 #ifdef CONFIG_PLATFORM_ARM_SUN6I
1613 sw_usb_disable_hcd(item.val);
1614 wifi_pm_power(0);
1615 #endif
1616
1617 rtw_suspend_lock_uninit();
1618 DBG_871X("-rtw_drv_halt\n");
1619
1620 rtw_mstat_dump();
1621 }
1622
1623
1624 module_init(rtw_drv_entry);
1625 module_exit(rtw_drv_halt);
1626
1627 #ifdef CONFIG_WOWLAN
1628 #ifdef CONFIG_WOWLAN_MANUAL
1629
1630 int rtw_resume_toshiba(PADAPTER Adapter)
1631 {
1632 struct dvobj_priv *pdvobjpriv;
1633 pdvobjpriv = adapter_to_dvobj(Adapter);
1634
1635 rtw_resume(pdvobjpriv->pusbintf);
1636 return 0;
1637 }
1638
1639 int rtw_suspend_toshiba(PADAPTER Adapter)
1640 {
1641 pm_message_t msg;
1642 struct dvobj_priv *pdvobjpriv;
1643 pdvobjpriv = adapter_to_dvobj(Adapter);
1644 msg.event=0;
1645 //for Toshiba only, they should call rtw_suspend before suspend
1646 rtw_suspend(pdvobjpriv->pusbintf, msg);
1647 return 0;
1648 }
1649 EXPORT_SYMBOL(rtw_suspend_toshiba);
1650 EXPORT_SYMBOL(rtw_resume_toshiba);
1651 #endif //CONFIG_WOWLAN_MANUAL
1652 #endif //CONFIG_WOWLAN
1653
1654 #ifdef CONFIG_INTEL_PROXIM
1655 _adapter *rtw_usb_get_sw_pointer(void)
1656 {
1657 return rtw_sw_export;
1658 }
1659 EXPORT_SYMBOL(rtw_usb_get_sw_pointer);
1660 #endif //CONFIG_INTEL_PROXIM