Merge tag 'gpio-v3.13-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw...
[linux-2.6.git] / drivers / staging / rtl8712 / usb_intf.c
blobdbefa43e4c2c50211cf4aa866896d875068b8147
1 /******************************************************************************
2 * usb_intf.c
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved.
23 * Contact information:
24 * WLAN FAE <wlanfae@realtek.com>
25 * Larry Finger <Larry.Finger@lwfinger.net>
27 ******************************************************************************/
29 #define _HCI_INTF_C_
31 #include <linux/usb.h>
32 #include <linux/module.h>
33 #include <linux/firmware.h>
35 #include "osdep_service.h"
36 #include "drv_types.h"
37 #include "recv_osdep.h"
38 #include "xmit_osdep.h"
39 #include "rtl8712_efuse.h"
40 #include "usb_ops.h"
41 #include "usb_osintf.h"
43 static struct usb_interface *pintf;
45 static int r871xu_drv_init(struct usb_interface *pusb_intf,
46 const struct usb_device_id *pdid);
48 static void r871xu_dev_remove(struct usb_interface *pusb_intf);
50 static struct usb_device_id rtl871x_usb_id_tbl[] = {
52 /* RTL8188SU */
53 /* Realtek */
54 {USB_DEVICE(0x0BDA, 0x8171)},
55 {USB_DEVICE(0x0bda, 0x8173)},
56 {USB_DEVICE(0x0bda, 0x8712)},
57 {USB_DEVICE(0x0bda, 0x8713)},
58 {USB_DEVICE(0x0bda, 0xC512)},
59 /* Abocom */
60 {USB_DEVICE(0x07B8, 0x8188)},
61 /* ASUS */
62 {USB_DEVICE(0x0B05, 0x1786)},
63 {USB_DEVICE(0x0B05, 0x1791)}, /* 11n mode disable */
64 /* Belkin */
65 {USB_DEVICE(0x050D, 0x945A)},
66 /* ISY IWL - Belkin clone */
67 {USB_DEVICE(0x050D, 0x11F1)},
68 /* Corega */
69 {USB_DEVICE(0x07AA, 0x0047)},
70 /* D-Link */
71 {USB_DEVICE(0x2001, 0x3306)},
72 {USB_DEVICE(0x07D1, 0x3306)}, /* 11n mode disable */
73 /* Edimax */
74 {USB_DEVICE(0x7392, 0x7611)},
75 /* EnGenius */
76 {USB_DEVICE(0x1740, 0x9603)},
77 /* Hawking */
78 {USB_DEVICE(0x0E66, 0x0016)},
79 /* Hercules */
80 {USB_DEVICE(0x06F8, 0xE034)},
81 {USB_DEVICE(0x06F8, 0xE032)},
82 /* Logitec */
83 {USB_DEVICE(0x0789, 0x0167)},
84 /* PCI */
85 {USB_DEVICE(0x2019, 0xAB28)},
86 {USB_DEVICE(0x2019, 0xED16)},
87 /* Sitecom */
88 {USB_DEVICE(0x0DF6, 0x0057)},
89 {USB_DEVICE(0x0DF6, 0x0045)},
90 {USB_DEVICE(0x0DF6, 0x0059)}, /* 11n mode disable */
91 {USB_DEVICE(0x0DF6, 0x004B)},
92 {USB_DEVICE(0x0DF6, 0x005B)},
93 {USB_DEVICE(0x0DF6, 0x005D)},
94 {USB_DEVICE(0x0DF6, 0x0063)},
95 /* Sweex */
96 {USB_DEVICE(0x177F, 0x0154)},
97 /* Thinkware */
98 {USB_DEVICE(0x0BDA, 0x5077)},
99 /* Toshiba */
100 {USB_DEVICE(0x1690, 0x0752)},
101 /* - */
102 {USB_DEVICE(0x20F4, 0x646B)},
103 {USB_DEVICE(0x083A, 0xC512)},
104 {USB_DEVICE(0x25D4, 0x4CA1)},
105 {USB_DEVICE(0x25D4, 0x4CAB)},
107 /* RTL8191SU */
108 /* Realtek */
109 {USB_DEVICE(0x0BDA, 0x8172)},
110 {USB_DEVICE(0x0BDA, 0x8192)},
111 /* Amigo */
112 {USB_DEVICE(0x0EB0, 0x9061)},
113 /* ASUS/EKB */
114 {USB_DEVICE(0x13D3, 0x3323)},
115 {USB_DEVICE(0x13D3, 0x3311)}, /* 11n mode disable */
116 {USB_DEVICE(0x13D3, 0x3342)},
117 /* ASUS/EKBLenovo */
118 {USB_DEVICE(0x13D3, 0x3333)},
119 {USB_DEVICE(0x13D3, 0x3334)},
120 {USB_DEVICE(0x13D3, 0x3335)}, /* 11n mode disable */
121 {USB_DEVICE(0x13D3, 0x3336)}, /* 11n mode disable */
122 /* ASUS/Media BOX */
123 {USB_DEVICE(0x13D3, 0x3309)},
124 /* Belkin */
125 {USB_DEVICE(0x050D, 0x815F)},
126 /* D-Link */
127 {USB_DEVICE(0x07D1, 0x3302)},
128 {USB_DEVICE(0x07D1, 0x3300)},
129 {USB_DEVICE(0x07D1, 0x3303)},
130 /* Edimax */
131 {USB_DEVICE(0x7392, 0x7612)},
132 /* EnGenius */
133 {USB_DEVICE(0x1740, 0x9605)},
134 /* Guillemot */
135 {USB_DEVICE(0x06F8, 0xE031)},
136 /* Hawking */
137 {USB_DEVICE(0x0E66, 0x0015)},
138 /* Mediao */
139 {USB_DEVICE(0x13D3, 0x3306)},
140 /* PCI */
141 {USB_DEVICE(0x2019, 0xED18)},
142 {USB_DEVICE(0x2019, 0x4901)},
143 /* Sitecom */
144 {USB_DEVICE(0x0DF6, 0x0058)},
145 {USB_DEVICE(0x0DF6, 0x0049)},
146 {USB_DEVICE(0x0DF6, 0x004C)},
147 {USB_DEVICE(0x0DF6, 0x0064)},
148 /* Skyworth */
149 {USB_DEVICE(0x14b2, 0x3300)},
150 {USB_DEVICE(0x14b2, 0x3301)},
151 {USB_DEVICE(0x14B2, 0x3302)},
152 /* - */
153 {USB_DEVICE(0x04F2, 0xAFF2)},
154 {USB_DEVICE(0x04F2, 0xAFF5)},
155 {USB_DEVICE(0x04F2, 0xAFF6)},
156 {USB_DEVICE(0x13D3, 0x3339)},
157 {USB_DEVICE(0x13D3, 0x3340)}, /* 11n mode disable */
158 {USB_DEVICE(0x13D3, 0x3341)}, /* 11n mode disable */
159 {USB_DEVICE(0x13D3, 0x3310)},
160 {USB_DEVICE(0x13D3, 0x3325)},
162 /* RTL8192SU */
163 /* Realtek */
164 {USB_DEVICE(0x0BDA, 0x8174)},
165 /* Belkin */
166 {USB_DEVICE(0x050D, 0x845A)},
167 /* Corega */
168 {USB_DEVICE(0x07AA, 0x0051)},
169 /* Edimax */
170 {USB_DEVICE(0x7392, 0x7622)},
171 /* NEC */
172 {USB_DEVICE(0x0409, 0x02B6)},
176 MODULE_DEVICE_TABLE(usb, rtl871x_usb_id_tbl);
178 static struct specific_device_id specific_device_id_tbl[] = {
179 {.idVendor = 0x0b05, .idProduct = 0x1791,
180 .flags = SPEC_DEV_ID_DISABLE_HT},
181 {.idVendor = 0x0df6, .idProduct = 0x0059,
182 .flags = SPEC_DEV_ID_DISABLE_HT},
183 {.idVendor = 0x13d3, .idProduct = 0x3306,
184 .flags = SPEC_DEV_ID_DISABLE_HT},
185 {.idVendor = 0x13D3, .idProduct = 0x3311,
186 .flags = SPEC_DEV_ID_DISABLE_HT},
187 {.idVendor = 0x13d3, .idProduct = 0x3335,
188 .flags = SPEC_DEV_ID_DISABLE_HT},
189 {.idVendor = 0x13d3, .idProduct = 0x3336,
190 .flags = SPEC_DEV_ID_DISABLE_HT},
191 {.idVendor = 0x13d3, .idProduct = 0x3340,
192 .flags = SPEC_DEV_ID_DISABLE_HT},
193 {.idVendor = 0x13d3, .idProduct = 0x3341,
194 .flags = SPEC_DEV_ID_DISABLE_HT},
198 struct drv_priv {
199 struct usb_driver r871xu_drv;
200 int drv_registered;
203 #ifdef CONFIG_PM
204 static int r871x_suspend(struct usb_interface *pusb_intf, pm_message_t state)
206 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
208 netdev_info(pnetdev, "Suspending...\n");
209 if (!pnetdev || !netif_running(pnetdev)) {
210 netdev_info(pnetdev, "Unable to suspend\n");
211 return 0;
213 if (pnetdev->netdev_ops->ndo_stop)
214 pnetdev->netdev_ops->ndo_stop(pnetdev);
215 mdelay(10);
216 netif_device_detach(pnetdev);
217 return 0;
220 static int r871x_resume(struct usb_interface *pusb_intf)
222 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
224 netdev_info(pnetdev, "Resuming...\n");
225 if (!pnetdev || !netif_running(pnetdev)) {
226 netdev_info(pnetdev, "Unable to resume\n");
227 return 0;
229 netif_device_attach(pnetdev);
230 if (pnetdev->netdev_ops->ndo_open)
231 pnetdev->netdev_ops->ndo_open(pnetdev);
232 return 0;
235 static int r871x_reset_resume(struct usb_interface *pusb_intf)
237 /* dummy routine */
238 return 0;
241 #endif
243 static struct drv_priv drvpriv = {
244 .r871xu_drv.name = "r8712u",
245 .r871xu_drv.id_table = rtl871x_usb_id_tbl,
246 .r871xu_drv.probe = r871xu_drv_init,
247 .r871xu_drv.disconnect = r871xu_dev_remove,
248 #ifdef CONFIG_PM
249 .r871xu_drv.suspend = r871x_suspend,
250 .r871xu_drv.resume = r871x_resume,
251 .r871xu_drv.reset_resume = r871x_reset_resume,
252 #endif
255 static uint r8712_usb_dvobj_init(struct _adapter *padapter)
257 uint status = _SUCCESS;
258 struct usb_device_descriptor *pdev_desc;
259 struct usb_host_config *phost_conf;
260 struct usb_config_descriptor *pconf_desc;
261 struct usb_host_interface *phost_iface;
262 struct usb_interface_descriptor *piface_desc;
263 struct dvobj_priv *pdvobjpriv = &padapter->dvobjpriv;
264 struct usb_device *pusbd = pdvobjpriv->pusbdev;
266 pdvobjpriv->padapter = padapter;
267 padapter->EepromAddressSize = 6;
268 pdev_desc = &pusbd->descriptor;
269 phost_conf = pusbd->actconfig;
270 pconf_desc = &phost_conf->desc;
271 phost_iface = &pintf->altsetting[0];
272 piface_desc = &phost_iface->desc;
273 pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
274 if (pusbd->speed == USB_SPEED_HIGH) {
275 pdvobjpriv->ishighspeed = true;
276 dev_info(&pusbd->dev, "r8712u: USB_SPEED_HIGH with %d endpoints\n",
277 pdvobjpriv->nr_endpoint);
278 } else {
279 pdvobjpriv->ishighspeed = false;
280 dev_info(&pusbd->dev, "r8712u: USB_SPEED_LOW with %d endpoints\n",
281 pdvobjpriv->nr_endpoint);
283 if ((r8712_alloc_io_queue(padapter)) == _FAIL)
284 status = _FAIL;
285 return status;
288 static void r8712_usb_dvobj_deinit(struct _adapter *padapter)
292 void rtl871x_intf_stop(struct _adapter *padapter)
294 /*disable_hw_interrupt*/
295 if (padapter->bSurpriseRemoved == false) {
296 /*device still exists, so driver can do i/o operation
297 * TODO: */
300 /* cancel in irp */
301 if (padapter->dvobjpriv.inirp_deinit != NULL)
302 padapter->dvobjpriv.inirp_deinit(padapter);
303 /* cancel out irp */
304 r8712_usb_write_port_cancel(padapter);
305 /* TODO:cancel other irps */
308 void r871x_dev_unload(struct _adapter *padapter)
310 if (padapter->bup == true) {
311 /*s1.*/
312 padapter->bDriverStopped = true;
314 /*s3.*/
315 rtl871x_intf_stop(padapter);
317 /*s4.*/
318 r8712_stop_drv_threads(padapter);
320 /*s5.*/
321 if (padapter->bSurpriseRemoved == false) {
322 padapter->hw_init_completed = false;
323 rtl8712_hal_deinit(padapter);
326 /*s6.*/
327 if (padapter->dvobj_deinit)
328 padapter->dvobj_deinit(padapter);
329 padapter->bup = false;
333 static void disable_ht_for_spec_devid(const struct usb_device_id *pdid,
334 struct _adapter *padapter)
336 u16 vid, pid;
337 u32 flags;
338 int i;
339 int num = sizeof(specific_device_id_tbl) /
340 sizeof(struct specific_device_id);
342 for (i = 0; i < num; i++) {
343 vid = specific_device_id_tbl[i].idVendor;
344 pid = specific_device_id_tbl[i].idProduct;
345 flags = specific_device_id_tbl[i].flags;
347 if ((pdid->idVendor == vid) && (pdid->idProduct == pid) &&
348 (flags&SPEC_DEV_ID_DISABLE_HT)) {
349 padapter->registrypriv.ht_enable = 0;
350 padapter->registrypriv.cbw40_enable = 0;
351 padapter->registrypriv.ampdu_enable = 0;
357 * drv_init() - a device potentially for us
359 * notes: drv_init() is called when the bus driver has located a card for us
360 * to support. We accept the new device by returning 0.
362 static int r871xu_drv_init(struct usb_interface *pusb_intf,
363 const struct usb_device_id *pdid)
365 uint status;
366 struct _adapter *padapter = NULL;
367 struct dvobj_priv *pdvobjpriv;
368 struct net_device *pnetdev;
369 struct usb_device *udev;
371 printk(KERN_INFO "r8712u: Staging version\n");
372 /* In this probe function, O.S. will provide the usb interface pointer
373 * to driver. We have to increase the reference count of the usb device
374 * structure by using the usb_get_dev function.
376 udev = interface_to_usbdev(pusb_intf);
377 usb_get_dev(udev);
378 pintf = pusb_intf;
379 /* step 1. */
380 pnetdev = r8712_init_netdev();
381 if (!pnetdev)
382 goto error;
383 padapter = netdev_priv(pnetdev);
384 disable_ht_for_spec_devid(pdid, padapter);
385 pdvobjpriv = &padapter->dvobjpriv;
386 pdvobjpriv->padapter = padapter;
387 padapter->dvobjpriv.pusbdev = udev;
388 padapter->pusb_intf = pusb_intf;
389 usb_set_intfdata(pusb_intf, pnetdev);
390 SET_NETDEV_DEV(pnetdev, &pusb_intf->dev);
391 /* step 2. */
392 padapter->dvobj_init = &r8712_usb_dvobj_init;
393 padapter->dvobj_deinit = &r8712_usb_dvobj_deinit;
394 padapter->halpriv.hal_bus_init = &r8712_usb_hal_bus_init;
395 padapter->dvobjpriv.inirp_init = &r8712_usb_inirp_init;
396 padapter->dvobjpriv.inirp_deinit = &r8712_usb_inirp_deinit;
397 /* step 3.
398 * initialize the dvobj_priv
400 if (padapter->dvobj_init == NULL)
401 goto error;
402 else {
403 status = padapter->dvobj_init(padapter);
404 if (status != _SUCCESS)
405 goto error;
407 /* step 4. */
408 status = r8712_init_drv_sw(padapter);
409 if (status == _FAIL)
410 goto error;
411 /* step 5. read efuse/eeprom data and get mac_addr */
413 int i, offset;
414 u8 mac[6];
415 u8 tmpU1b, AutoloadFail, eeprom_CustomerID;
416 u8 *pdata = padapter->eeprompriv.efuse_eeprom_data;
418 tmpU1b = r8712_read8(padapter, EE_9346CR);/*CR9346*/
420 /* To check system boot selection.*/
421 dev_info(&udev->dev, "r8712u: Boot from %s: Autoload %s\n",
422 (tmpU1b & _9356SEL) ? "EEPROM" : "EFUSE",
423 (tmpU1b & _EEPROM_EN) ? "OK" : "Failed");
425 /* To check autoload success or not.*/
426 if (tmpU1b & _EEPROM_EN) {
427 AutoloadFail = true;
428 /* The following operations prevent Efuse leakage by
429 * turning on 2.5V.
431 tmpU1b = r8712_read8(padapter, EFUSE_TEST+3);
432 r8712_write8(padapter, EFUSE_TEST + 3, tmpU1b | 0x80);
433 msleep(20);
434 r8712_write8(padapter, EFUSE_TEST + 3,
435 (tmpU1b & (~BIT(7))));
437 /* Retrieve Chip version.
438 * Recognize IC version by Reg0x4 BIT15.
440 tmpU1b = (u8)((r8712_read32(padapter, PMC_FSM) >> 15) &
441 0x1F);
442 if (tmpU1b == 0x3)
443 padapter->registrypriv.chip_version =
444 RTL8712_3rdCUT;
445 else
446 padapter->registrypriv.chip_version =
447 (tmpU1b >> 1) + 1;
448 switch (padapter->registrypriv.chip_version) {
449 case RTL8712_1stCUT:
450 case RTL8712_2ndCUT:
451 case RTL8712_3rdCUT:
452 break;
453 default:
454 padapter->registrypriv.chip_version =
455 RTL8712_2ndCUT;
456 break;
459 for (i = 0, offset = 0; i < 128; i += 8, offset++)
460 r8712_efuse_pg_packet_read(padapter, offset,
461 &pdata[i]);
463 if (!r8712_initmac || !mac_pton(r8712_initmac, mac)) {
464 /* Use the mac address stored in the Efuse
465 * offset = 0x12 for usb in efuse
467 memcpy(mac, &pdata[0x12], ETH_ALEN);
469 eeprom_CustomerID = pdata[0x52];
470 switch (eeprom_CustomerID) {
471 case EEPROM_CID_ALPHA:
472 padapter->eeprompriv.CustomerID =
473 RT_CID_819x_ALPHA;
474 break;
475 case EEPROM_CID_CAMEO:
476 padapter->eeprompriv.CustomerID =
477 RT_CID_819x_CAMEO;
478 break;
479 case EEPROM_CID_SITECOM:
480 padapter->eeprompriv.CustomerID =
481 RT_CID_819x_Sitecom;
482 break;
483 case EEPROM_CID_COREGA:
484 padapter->eeprompriv.CustomerID =
485 RT_CID_COREGA;
486 break;
487 case EEPROM_CID_Senao:
488 padapter->eeprompriv.CustomerID =
489 RT_CID_819x_Senao;
490 break;
491 case EEPROM_CID_EDIMAX_BELKIN:
492 padapter->eeprompriv.CustomerID =
493 RT_CID_819x_Edimax_Belkin;
494 break;
495 case EEPROM_CID_SERCOMM_BELKIN:
496 padapter->eeprompriv.CustomerID =
497 RT_CID_819x_Sercomm_Belkin;
498 break;
499 case EEPROM_CID_WNC_COREGA:
500 padapter->eeprompriv.CustomerID =
501 RT_CID_819x_WNC_COREGA;
502 break;
503 case EEPROM_CID_WHQL:
504 break;
505 case EEPROM_CID_NetCore:
506 padapter->eeprompriv.CustomerID =
507 RT_CID_819x_Netcore;
508 break;
509 case EEPROM_CID_CAMEO1:
510 padapter->eeprompriv.CustomerID =
511 RT_CID_819x_CAMEO1;
512 break;
513 case EEPROM_CID_CLEVO:
514 padapter->eeprompriv.CustomerID =
515 RT_CID_819x_CLEVO;
516 break;
517 default:
518 padapter->eeprompriv.CustomerID =
519 RT_CID_DEFAULT;
520 break;
522 dev_info(&udev->dev, "r8712u: CustomerID = 0x%.4x\n",
523 padapter->eeprompriv.CustomerID);
524 /* Led mode */
525 switch (padapter->eeprompriv.CustomerID) {
526 case RT_CID_DEFAULT:
527 case RT_CID_819x_ALPHA:
528 case RT_CID_819x_CAMEO:
529 padapter->ledpriv.LedStrategy = SW_LED_MODE1;
530 padapter->ledpriv.bRegUseLed = true;
531 break;
532 case RT_CID_819x_Sitecom:
533 padapter->ledpriv.LedStrategy = SW_LED_MODE2;
534 padapter->ledpriv.bRegUseLed = true;
535 break;
536 case RT_CID_COREGA:
537 case RT_CID_819x_Senao:
538 padapter->ledpriv.LedStrategy = SW_LED_MODE3;
539 padapter->ledpriv.bRegUseLed = true;
540 break;
541 case RT_CID_819x_Edimax_Belkin:
542 padapter->ledpriv.LedStrategy = SW_LED_MODE4;
543 padapter->ledpriv.bRegUseLed = true;
544 break;
545 case RT_CID_819x_Sercomm_Belkin:
546 padapter->ledpriv.LedStrategy = SW_LED_MODE5;
547 padapter->ledpriv.bRegUseLed = true;
548 break;
549 case RT_CID_819x_WNC_COREGA:
550 padapter->ledpriv.LedStrategy = SW_LED_MODE6;
551 padapter->ledpriv.bRegUseLed = true;
552 break;
553 default:
554 padapter->ledpriv.LedStrategy = SW_LED_MODE0;
555 padapter->ledpriv.bRegUseLed = false;
556 break;
558 } else
559 AutoloadFail = false;
560 if (((mac[0] == 0xff) && (mac[1] == 0xff) &&
561 (mac[2] == 0xff) && (mac[3] == 0xff) &&
562 (mac[4] == 0xff) && (mac[5] == 0xff)) ||
563 ((mac[0] == 0x00) && (mac[1] == 0x00) &&
564 (mac[2] == 0x00) && (mac[3] == 0x00) &&
565 (mac[4] == 0x00) && (mac[5] == 0x00)) ||
566 (AutoloadFail == false)) {
567 mac[0] = 0x00;
568 mac[1] = 0xe0;
569 mac[2] = 0x4c;
570 mac[3] = 0x87;
571 mac[4] = 0x00;
572 mac[5] = 0x00;
574 if (r8712_initmac) {
575 /* Make sure the user did not select a multicast
576 * address by setting bit 1 of first octet.
578 mac[0] &= 0xFE;
579 dev_info(&udev->dev, "r8712u: MAC Address from user = %pM\n", mac);
580 } else
581 dev_info(&udev->dev, "r8712u: MAC Address from efuse = %pM\n", mac);
582 memcpy(pnetdev->dev_addr, mac, ETH_ALEN);
584 /* step 6. Load the firmware asynchronously */
585 if (rtl871x_load_fw(padapter))
586 goto error;
587 spin_lock_init(&padapter->lockRxFF0Filter);
588 mutex_init(&padapter->mutex_start);
589 return 0;
590 error:
591 usb_put_dev(udev);
592 usb_set_intfdata(pusb_intf, NULL);
593 if (padapter->dvobj_deinit != NULL)
594 padapter->dvobj_deinit(padapter);
595 if (pnetdev)
596 free_netdev(pnetdev);
597 return -ENODEV;
600 /* rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove()
601 * => how to recognize both */
602 static void r871xu_dev_remove(struct usb_interface *pusb_intf)
604 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
605 struct _adapter *padapter = netdev_priv(pnetdev);
606 struct usb_device *udev = interface_to_usbdev(pusb_intf);
608 usb_set_intfdata(pusb_intf, NULL);
609 if (padapter->fw_found)
610 release_firmware(padapter->fw);
611 /* never exit with a firmware callback pending */
612 wait_for_completion(&padapter->rtl8712_fw_ready);
613 if (drvpriv.drv_registered == true)
614 padapter->bSurpriseRemoved = true;
615 if (pnetdev != NULL) {
616 /* will call netdev_close() */
617 unregister_netdev(pnetdev);
619 flush_scheduled_work();
620 udelay(1);
621 /*Stop driver mlme relation timer */
622 if (padapter->fw_found)
623 r8712_stop_drv_timers(padapter);
624 r871x_dev_unload(padapter);
625 r8712_free_drv_sw(padapter);
626 usb_set_intfdata(pusb_intf, NULL);
627 /* decrease the reference count of the usb device structure
628 * when disconnect */
629 usb_put_dev(udev);
630 /* If we didn't unplug usb dongle and remove/insert module, driver
631 * fails on sitesurvey for the first time when device is up.
632 * Reset usb port for sitesurvey fail issue. */
633 if (udev->state != USB_STATE_NOTATTACHED)
634 usb_reset_device(udev);
635 return;
638 static int __init r8712u_drv_entry(void)
640 drvpriv.drv_registered = true;
641 return usb_register(&drvpriv.r871xu_drv);
644 static void __exit r8712u_drv_halt(void)
646 drvpriv.drv_registered = false;
647 usb_deregister(&drvpriv.r871xu_drv);
650 module_init(r8712u_drv_entry);
651 module_exit(r8712u_drv_halt);