Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-btrfs-devel.git] / drivers / staging / rtl8712 / usb_intf.c
blobfb2e89c3056c0c0c0ff1b1b02ada8f60eab8a551
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>
34 #include "osdep_service.h"
35 #include "drv_types.h"
36 #include "recv_osdep.h"
37 #include "xmit_osdep.h"
38 #include "rtl8712_efuse.h"
39 #include "usb_vendor_req.h"
40 #include "usb_ops.h"
41 #include "usb_osintf.h"
43 #define DRVER "v7_0.20100831"
45 static struct usb_interface *pintf;
47 static int r871xu_drv_init(struct usb_interface *pusb_intf,
48 const struct usb_device_id *pdid);
50 static void r871xu_dev_remove(struct usb_interface *pusb_intf);
52 static struct usb_device_id rtl871x_usb_id_tbl[] = {
54 /* RTL8188SU */
55 /* Realtek */
56 {USB_DEVICE(0x0BDA, 0x8171)},
57 {USB_DEVICE(0x0bda, 0x8173)},
58 {USB_DEVICE(0x0bda, 0x8712)},
59 {USB_DEVICE(0x0bda, 0x8713)},
60 {USB_DEVICE(0x0bda, 0xC512)},
61 /* Abocom */
62 {USB_DEVICE(0x07B8, 0x8188)},
63 /* ASUS */
64 {USB_DEVICE(0x0B05, 0x1786)},
65 {USB_DEVICE(0x0B05, 0x1791)}, /* 11n mode disable */
66 /* Belkin */
67 {USB_DEVICE(0x050D, 0x945A)},
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, 0x0063)},
93 /* Sweex */
94 {USB_DEVICE(0x177F, 0x0154)},
95 /* Thinkware */
96 {USB_DEVICE(0x0BDA, 0x5077)},
97 /* Toshiba */
98 {USB_DEVICE(0x1690, 0x0752)},
99 /* - */
100 {USB_DEVICE(0x20F4, 0x646B)},
101 {USB_DEVICE(0x083A, 0xC512)},
103 /* RTL8191SU */
104 /* Realtek */
105 {USB_DEVICE(0x0BDA, 0x8172)},
106 /* Amigo */
107 {USB_DEVICE(0x0EB0, 0x9061)},
108 /* ASUS/EKB */
109 {USB_DEVICE(0x0BDA, 0x8172)},
110 {USB_DEVICE(0x13D3, 0x3323)},
111 {USB_DEVICE(0x13D3, 0x3311)}, /* 11n mode disable */
112 {USB_DEVICE(0x13D3, 0x3342)},
113 /* ASUS/EKBLenovo */
114 {USB_DEVICE(0x13D3, 0x3333)},
115 {USB_DEVICE(0x13D3, 0x3334)},
116 {USB_DEVICE(0x13D3, 0x3335)}, /* 11n mode disable */
117 {USB_DEVICE(0x13D3, 0x3336)}, /* 11n mode disable */
118 /* ASUS/Media BOX */
119 {USB_DEVICE(0x13D3, 0x3309)},
120 /* Belkin */
121 {USB_DEVICE(0x050D, 0x815F)},
122 /* D-Link */
123 {USB_DEVICE(0x07D1, 0x3302)},
124 {USB_DEVICE(0x07D1, 0x3300)},
125 {USB_DEVICE(0x07D1, 0x3303)},
126 /* Edimax */
127 {USB_DEVICE(0x7392, 0x7612)},
128 /* EnGenius */
129 {USB_DEVICE(0x1740, 0x9605)},
130 /* Guillemot */
131 {USB_DEVICE(0x06F8, 0xE031)},
132 /* Hawking */
133 {USB_DEVICE(0x0E66, 0x0015)},
134 /* Mediao */
135 {USB_DEVICE(0x13D3, 0x3306)},
136 /* PCI */
137 {USB_DEVICE(0x2019, 0xED18)},
138 {USB_DEVICE(0x2019, 0x4901)},
139 /* Sitecom */
140 {USB_DEVICE(0x0DF6, 0x0058)},
141 {USB_DEVICE(0x0DF6, 0x0049)},
142 {USB_DEVICE(0x0DF6, 0x004C)},
143 {USB_DEVICE(0x0DF6, 0x0064)},
144 /* Skyworth */
145 {USB_DEVICE(0x14b2, 0x3300)},
146 {USB_DEVICE(0x14b2, 0x3301)},
147 {USB_DEVICE(0x14B2, 0x3302)},
148 /* - */
149 {USB_DEVICE(0x04F2, 0xAFF2)},
150 {USB_DEVICE(0x04F2, 0xAFF5)},
151 {USB_DEVICE(0x04F2, 0xAFF6)},
152 {USB_DEVICE(0x13D3, 0x3339)},
153 {USB_DEVICE(0x13D3, 0x3340)}, /* 11n mode disable */
154 {USB_DEVICE(0x13D3, 0x3341)}, /* 11n mode disable */
155 {USB_DEVICE(0x13D3, 0x3310)},
156 {USB_DEVICE(0x13D3, 0x3325)},
158 /* RTL8192SU */
159 /* Realtek */
160 {USB_DEVICE(0x0BDA, 0x8174)},
161 {USB_DEVICE(0x0BDA, 0x8174)},
162 /* Belkin */
163 {USB_DEVICE(0x050D, 0x845A)},
164 /* Corega */
165 {USB_DEVICE(0x07AA, 0x0051)},
166 /* Edimax */
167 {USB_DEVICE(0x7392, 0x7622)},
168 /* NEC */
169 {USB_DEVICE(0x0409, 0x02B6)},
173 MODULE_DEVICE_TABLE(usb, rtl871x_usb_id_tbl);
175 static struct specific_device_id specific_device_id_tbl[] = {
176 {.idVendor = 0x0b05, .idProduct = 0x1791,
177 .flags = SPEC_DEV_ID_DISABLE_HT},
178 {.idVendor = 0x0df6, .idProduct = 0x0059,
179 .flags = SPEC_DEV_ID_DISABLE_HT},
180 {.idVendor = 0x13d3, .idProduct = 0x3306,
181 .flags = SPEC_DEV_ID_DISABLE_HT},
182 {.idVendor = 0x13D3, .idProduct = 0x3311,
183 .flags = SPEC_DEV_ID_DISABLE_HT},
184 {.idVendor = 0x13d3, .idProduct = 0x3335,
185 .flags = SPEC_DEV_ID_DISABLE_HT},
186 {.idVendor = 0x13d3, .idProduct = 0x3336,
187 .flags = SPEC_DEV_ID_DISABLE_HT},
188 {.idVendor = 0x13d3, .idProduct = 0x3340,
189 .flags = SPEC_DEV_ID_DISABLE_HT},
190 {.idVendor = 0x13d3, .idProduct = 0x3341,
191 .flags = SPEC_DEV_ID_DISABLE_HT},
195 struct drv_priv {
196 struct usb_driver r871xu_drv;
197 int drv_registered;
200 #ifdef CONFIG_PM
201 static int r871x_suspend(struct usb_interface *pusb_intf, pm_message_t state)
203 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
205 printk(KERN_INFO "r8712: suspending...\n");
206 if (!pnetdev || !netif_running(pnetdev)) {
207 printk(KERN_INFO "r8712: unable to suspend\n");
208 return 0;
210 if (pnetdev->netdev_ops->ndo_stop)
211 pnetdev->netdev_ops->ndo_stop(pnetdev);
212 mdelay(10);
213 netif_device_detach(pnetdev);
214 return 0;
217 static int r871x_resume(struct usb_interface *pusb_intf)
219 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
221 printk(KERN_INFO "r8712: resuming...\n");
222 if (!pnetdev || !netif_running(pnetdev)) {
223 printk(KERN_INFO "r8712: unable to resume\n");
224 return 0;
226 netif_device_attach(pnetdev);
227 if (pnetdev->netdev_ops->ndo_open)
228 pnetdev->netdev_ops->ndo_open(pnetdev);
229 return 0;
232 static int r871x_reset_resume(struct usb_interface *pusb_intf)
234 /* dummy routine */
235 return 0;
238 #endif
240 static struct drv_priv drvpriv = {
241 .r871xu_drv.name = "r8712u",
242 .r871xu_drv.id_table = rtl871x_usb_id_tbl,
243 .r871xu_drv.probe = r871xu_drv_init,
244 .r871xu_drv.disconnect = r871xu_dev_remove,
245 #ifdef CONFIG_PM
246 .r871xu_drv.suspend = r871x_suspend,
247 .r871xu_drv.resume = r871x_resume,
248 .r871xu_drv.reset_resume = r871x_reset_resume,
249 #endif
252 static uint r8712_usb_dvobj_init(struct _adapter *padapter)
254 uint status = _SUCCESS;
255 struct usb_device_descriptor *pdev_desc;
256 struct usb_host_config *phost_conf;
257 struct usb_config_descriptor *pconf_desc;
258 struct usb_host_interface *phost_iface;
259 struct usb_interface_descriptor *piface_desc;
260 struct dvobj_priv *pdvobjpriv = &padapter->dvobjpriv;
261 struct usb_device *pusbd = pdvobjpriv->pusbdev;
263 pdvobjpriv->padapter = padapter;
264 padapter->EepromAddressSize = 6;
265 pdev_desc = &pusbd->descriptor;
266 phost_conf = pusbd->actconfig;
267 pconf_desc = &phost_conf->desc;
268 phost_iface = &pintf->altsetting[0];
269 piface_desc = &phost_iface->desc;
270 pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
271 if (pusbd->speed == USB_SPEED_HIGH) {
272 pdvobjpriv->ishighspeed = true;
273 printk(KERN_INFO "r8712u: USB_SPEED_HIGH with %d endpoints\n",
274 pdvobjpriv->nr_endpoint);
275 } else {
276 pdvobjpriv->ishighspeed = false;
277 printk(KERN_INFO "r8712u: USB_SPEED_LOW with %d endpoints\n",
278 pdvobjpriv->nr_endpoint);
280 if ((r8712_alloc_io_queue(padapter)) == _FAIL)
281 status = _FAIL;
282 sema_init(&(padapter->dvobjpriv.usb_suspend_sema), 0);
283 return status;
286 static void r8712_usb_dvobj_deinit(struct _adapter *padapter)
290 void rtl871x_intf_stop(struct _adapter *padapter)
292 /*disable_hw_interrupt*/
293 if (padapter->bSurpriseRemoved == false) {
294 /*device still exists, so driver can do i/o operation
295 * TODO: */
298 /* cancel in irp */
299 if (padapter->dvobjpriv.inirp_deinit != NULL)
300 padapter->dvobjpriv.inirp_deinit(padapter);
301 /* cancel out irp */
302 r8712_usb_write_port_cancel(padapter);
303 /* TODO:cancel other irps */
306 void r871x_dev_unload(struct _adapter *padapter)
308 if (padapter->bup == true) {
309 /*s1.*/
310 padapter->bDriverStopped = true;
312 /*s3.*/
313 rtl871x_intf_stop(padapter);
315 /*s4.*/
316 r8712_stop_drv_threads(padapter);
318 /*s5.*/
319 if (padapter->bSurpriseRemoved == false) {
320 padapter->hw_init_completed = false;
321 rtl8712_hal_deinit(padapter);
324 /*s6.*/
325 if (padapter->dvobj_deinit)
326 padapter->dvobj_deinit(padapter);
327 padapter->bup = false;
331 static void disable_ht_for_spec_devid(const struct usb_device_id *pdid,
332 struct _adapter *padapter)
334 u16 vid, pid;
335 u32 flags;
336 int i;
337 int num = sizeof(specific_device_id_tbl) /
338 sizeof(struct specific_device_id);
340 for (i = 0; i < num; i++) {
341 vid = specific_device_id_tbl[i].idVendor;
342 pid = specific_device_id_tbl[i].idProduct;
343 flags = specific_device_id_tbl[i].flags;
345 if ((pdid->idVendor == vid) && (pdid->idProduct == pid) &&
346 (flags&SPEC_DEV_ID_DISABLE_HT)) {
347 padapter->registrypriv.ht_enable = 0;
348 padapter->registrypriv.cbw40_enable = 0;
349 padapter->registrypriv.ampdu_enable = 0;
354 static u8 key_2char2num(u8 hch, u8 lch)
356 return (hex_to_bin(hch) << 4) | hex_to_bin(lch);
360 * drv_init() - a device potentially for us
362 * notes: drv_init() is called when the bus driver has located a card for us
363 * to support. We accept the new device by returning 0.
365 static int r871xu_drv_init(struct usb_interface *pusb_intf,
366 const struct usb_device_id *pdid)
368 uint status;
369 struct _adapter *padapter = NULL;
370 struct dvobj_priv *pdvobjpriv;
371 struct net_device *pnetdev;
372 struct usb_device *udev;
374 printk(KERN_INFO "r8712u: DriverVersion: %s\n", DRVER);
375 /* In this probe function, O.S. will provide the usb interface pointer
376 * to driver. We have to increase the reference count of the usb device
377 * structure by using the usb_get_dev function.
379 udev = interface_to_usbdev(pusb_intf);
380 usb_get_dev(udev);
381 pintf = pusb_intf;
382 /* step 1. */
383 pnetdev = r8712_init_netdev();
384 if (!pnetdev)
385 goto error;
386 padapter = netdev_priv(pnetdev);
387 disable_ht_for_spec_devid(pdid, padapter);
388 pdvobjpriv = &padapter->dvobjpriv;
389 pdvobjpriv->padapter = padapter;
390 padapter->dvobjpriv.pusbdev = udev;
391 usb_set_intfdata(pusb_intf, pnetdev);
392 SET_NETDEV_DEV(pnetdev, &pusb_intf->dev);
393 /* step 2. */
394 padapter->dvobj_init = &r8712_usb_dvobj_init;
395 padapter->dvobj_deinit = &r8712_usb_dvobj_deinit;
396 padapter->halpriv.hal_bus_init = &r8712_usb_hal_bus_init;
397 padapter->dvobjpriv.inirp_init = &r8712_usb_inirp_init;
398 padapter->dvobjpriv.inirp_deinit = &r8712_usb_inirp_deinit;
399 /* step 3.
400 * initialize the dvobj_priv
402 if (padapter->dvobj_init == NULL)
403 goto error;
404 else {
405 status = padapter->dvobj_init(padapter);
406 if (status != _SUCCESS)
407 goto error;
409 /* step 4. */
410 status = r8712_init_drv_sw(padapter);
411 if (status == _FAIL)
412 goto error;
413 /* step 5. read efuse/eeprom data and get mac_addr */
415 int i, offset;
416 u8 mac[6];
417 u8 tmpU1b, AutoloadFail, eeprom_CustomerID;
418 u8 *pdata = padapter->eeprompriv.efuse_eeprom_data;
420 tmpU1b = r8712_read8(padapter, EE_9346CR);/*CR9346*/
422 /* To check system boot selection.*/
423 printk(KERN_INFO "r8712u: Boot from %s: Autoload %s\n",
424 (tmpU1b & _9356SEL) ? "EEPROM" : "EFUSE",
425 (tmpU1b & _EEPROM_EN) ? "OK" : "Failed");
427 /* To check autoload success or not.*/
428 if (tmpU1b & _EEPROM_EN) {
429 AutoloadFail = true;
430 /* The following operations prevent Efuse leakage by
431 * turning on 2.5V.
433 tmpU1b = r8712_read8(padapter, EFUSE_TEST+3);
434 r8712_write8(padapter, EFUSE_TEST + 3, tmpU1b | 0x80);
435 msleep(20);
436 r8712_write8(padapter, EFUSE_TEST + 3,
437 (tmpU1b & (~BIT(7))));
439 /* Retrieve Chip version.
440 * Recognize IC version by Reg0x4 BIT15.
442 tmpU1b = (u8)((r8712_read32(padapter, PMC_FSM) >> 15) &
443 0x1F);
444 if (tmpU1b == 0x3)
445 padapter->registrypriv.chip_version =
446 RTL8712_3rdCUT;
447 else
448 padapter->registrypriv.chip_version =
449 (tmpU1b >> 1) + 1;
450 switch (padapter->registrypriv.chip_version) {
451 case RTL8712_1stCUT:
452 case RTL8712_2ndCUT:
453 case RTL8712_3rdCUT:
454 break;
455 default:
456 padapter->registrypriv.chip_version =
457 RTL8712_2ndCUT;
458 break;
461 for (i = 0, offset = 0; i < 128; i += 8, offset++)
462 r8712_efuse_pg_packet_read(padapter, offset,
463 &pdata[i]);
465 if (r8712_initmac) {
466 /* Users specify the mac address */
467 int jj, kk;
469 for (jj = 0, kk = 0; jj < ETH_ALEN;
470 jj++, kk += 3)
471 mac[jj] =
472 key_2char2num(r8712_initmac[kk],
473 r8712_initmac[kk + 1]);
474 } else {
475 /* Use the mac address stored in the Efuse
476 * offset = 0x12 for usb in efuse
478 memcpy(mac, &pdata[0x12], ETH_ALEN);
480 eeprom_CustomerID = pdata[0x52];
481 switch (eeprom_CustomerID) {
482 case EEPROM_CID_ALPHA:
483 padapter->eeprompriv.CustomerID =
484 RT_CID_819x_ALPHA;
485 break;
486 case EEPROM_CID_CAMEO:
487 padapter->eeprompriv.CustomerID =
488 RT_CID_819x_CAMEO;
489 break;
490 case EEPROM_CID_SITECOM:
491 padapter->eeprompriv.CustomerID =
492 RT_CID_819x_Sitecom;
493 break;
494 case EEPROM_CID_COREGA:
495 padapter->eeprompriv.CustomerID =
496 RT_CID_COREGA;
497 break;
498 case EEPROM_CID_Senao:
499 padapter->eeprompriv.CustomerID =
500 RT_CID_819x_Senao;
501 break;
502 case EEPROM_CID_EDIMAX_BELKIN:
503 padapter->eeprompriv.CustomerID =
504 RT_CID_819x_Edimax_Belkin;
505 break;
506 case EEPROM_CID_SERCOMM_BELKIN:
507 padapter->eeprompriv.CustomerID =
508 RT_CID_819x_Sercomm_Belkin;
509 break;
510 case EEPROM_CID_WNC_COREGA:
511 padapter->eeprompriv.CustomerID =
512 RT_CID_819x_WNC_COREGA;
513 break;
514 case EEPROM_CID_WHQL:
515 break;
516 case EEPROM_CID_NetCore:
517 padapter->eeprompriv.CustomerID =
518 RT_CID_819x_Netcore;
519 break;
520 case EEPROM_CID_CAMEO1:
521 padapter->eeprompriv.CustomerID =
522 RT_CID_819x_CAMEO1;
523 break;
524 case EEPROM_CID_CLEVO:
525 padapter->eeprompriv.CustomerID =
526 RT_CID_819x_CLEVO;
527 break;
528 default:
529 padapter->eeprompriv.CustomerID =
530 RT_CID_DEFAULT;
531 break;
533 printk(KERN_INFO "r8712u: CustomerID = 0x%.4x\n",
534 padapter->eeprompriv.CustomerID);
535 /* Led mode */
536 switch (padapter->eeprompriv.CustomerID) {
537 case RT_CID_DEFAULT:
538 case RT_CID_819x_ALPHA:
539 case RT_CID_819x_CAMEO:
540 padapter->ledpriv.LedStrategy = SW_LED_MODE1;
541 padapter->ledpriv.bRegUseLed = true;
542 break;
543 case RT_CID_819x_Sitecom:
544 padapter->ledpriv.LedStrategy = SW_LED_MODE2;
545 padapter->ledpriv.bRegUseLed = true;
546 break;
547 case RT_CID_COREGA:
548 case RT_CID_819x_Senao:
549 padapter->ledpriv.LedStrategy = SW_LED_MODE3;
550 padapter->ledpriv.bRegUseLed = true;
551 break;
552 case RT_CID_819x_Edimax_Belkin:
553 padapter->ledpriv.LedStrategy = SW_LED_MODE4;
554 padapter->ledpriv.bRegUseLed = true;
555 break;
556 case RT_CID_819x_Sercomm_Belkin:
557 padapter->ledpriv.LedStrategy = SW_LED_MODE5;
558 padapter->ledpriv.bRegUseLed = true;
559 break;
560 case RT_CID_819x_WNC_COREGA:
561 padapter->ledpriv.LedStrategy = SW_LED_MODE6;
562 padapter->ledpriv.bRegUseLed = true;
563 break;
564 default:
565 padapter->ledpriv.LedStrategy = SW_LED_MODE0;
566 padapter->ledpriv.bRegUseLed = false;
567 break;
569 } else
570 AutoloadFail = false;
571 if (((mac[0] == 0xff) && (mac[1] == 0xff) &&
572 (mac[2] == 0xff) && (mac[3] == 0xff) &&
573 (mac[4] == 0xff) && (mac[5] == 0xff)) ||
574 ((mac[0] == 0x00) && (mac[1] == 0x00) &&
575 (mac[2] == 0x00) && (mac[3] == 0x00) &&
576 (mac[4] == 0x00) && (mac[5] == 0x00)) ||
577 (AutoloadFail == false)) {
578 mac[0] = 0x00;
579 mac[1] = 0xe0;
580 mac[2] = 0x4c;
581 mac[3] = 0x87;
582 mac[4] = 0x00;
583 mac[5] = 0x00;
585 if (r8712_initmac) {
586 /* Make sure the user did not select a multicast
587 * address by setting bit 1 of first octet.
589 mac[0] &= 0xFE;
590 printk(KERN_INFO "r8712u: MAC Address from user = "
591 "%pM\n", mac);
592 } else
593 printk(KERN_INFO "r8712u: MAC Address from efuse = "
594 "%pM\n", mac);
595 memcpy(pnetdev->dev_addr, mac, ETH_ALEN);
597 /* step 6. Tell the network stack we exist */
598 if (register_netdev(pnetdev) != 0)
599 goto error;
600 spin_lock_init(&padapter->lockRxFF0Filter);
601 return 0;
602 error:
603 usb_put_dev(udev);
604 usb_set_intfdata(pusb_intf, NULL);
605 if (padapter->dvobj_deinit != NULL)
606 padapter->dvobj_deinit(padapter);
607 if (pnetdev)
608 free_netdev(pnetdev);
609 return -ENODEV;
612 /* rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove()
613 * => how to recognize both */
614 static void r871xu_dev_remove(struct usb_interface *pusb_intf)
616 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
617 struct _adapter *padapter = netdev_priv(pnetdev);
618 struct usb_device *udev = interface_to_usbdev(pusb_intf);
620 usb_set_intfdata(pusb_intf, NULL);
621 if (padapter) {
622 if (drvpriv.drv_registered == true)
623 padapter->bSurpriseRemoved = true;
624 if (pnetdev != NULL) {
625 /* will call netdev_close() */
626 unregister_netdev(pnetdev);
628 flush_scheduled_work();
629 udelay(1);
630 /*Stop driver mlme relation timer */
631 r8712_stop_drv_timers(padapter);
632 r871x_dev_unload(padapter);
633 r8712_free_drv_sw(padapter);
635 usb_set_intfdata(pusb_intf, NULL);
636 /* decrease the reference count of the usb device structure
637 * when disconnect */
638 usb_put_dev(udev);
639 /* If we didn't unplug usb dongle and remove/insert modlue, driver
640 * fails on sitesurvey for the first time when device is up.
641 * Reset usb port for sitesurvey fail issue. */
642 if (udev->state != USB_STATE_NOTATTACHED)
643 usb_reset_device(udev);
644 return;
647 static int __init r8712u_drv_entry(void)
649 drvpriv.drv_registered = true;
650 return usb_register(&drvpriv.r871xu_drv);
653 static void __exit r8712u_drv_halt(void)
655 drvpriv.drv_registered = false;
656 usb_deregister(&drvpriv.r871xu_drv);
657 printk(KERN_INFO "r8712u: Driver unloaded\n");
660 module_init(r8712u_drv_entry);
661 module_exit(r8712u_drv_halt);