This repository has been archived by the owner on Jun 20, 2019. It is now read-only.
/
sdio_intf.c
1997 lines (1640 loc) · 49.4 KB
/
sdio_intf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
*
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
*
******************************************************************************/
#define _HCI_INTF_C_
#include <drv_conf.h>
#include <osdep_service.h>
#include <drv_types.h>
#include <recv_osdep.h>
#include <xmit_osdep.h>
#include <rtw_version.h>
#ifndef CONFIG_SDIO_HCI
#error "CONFIG_SDIO_HCI shall be on!\n"
#endif
#include <linux/mmc/sdio_func.h>
#include <linux/mmc/sdio_ids.h>
#if defined(CONFIG_WOWLAN) || defined(CONFIG_PLATFORM_SPRD)
#include <linux/mmc/host.h>
#include <linux/mmc/card.h>
#endif
#ifdef CONFIG_PLATFORM_HUAWEI_K3V2
#include <custom_gpio.h>
#endif //CONFIG_PLATFORM_HUAWEI_K3V2
#ifdef CONFIG_PLATFORM_SPRD
#include <custom_gpio.h>
#endif // CONFIG_PLATFORM_SPRD
#ifdef PLATFORM_LEADCORE_1813
#include <custom_gpio.h>
#endif //
#include <hal_intf.h>
#include <sdio_hal.h>
#include <sdio_ops.h>
#include <rtw_android.h>
#ifdef CONFIG_GPIO_WAKEUP
#include <rtw_io.h>
unsigned int oob_irq = 0;
static irqreturn_t gpio_hostwakeup_irq_thread(int irq, void *data)
{
PADAPTER padapter = (PADAPTER)data;
DBG_871X_LEVEL(_drv_always_, "gpio_hostwakeup_irq_thread\n");
/* Disable interrupt before calling handler */
#ifndef CONFIG_PLATFORM_HUAWEI_K3V2
disable_irq_nosync(oob_irq);
#endif
rtw_lock_suspend_timeout(HZ/2);
return IRQ_HANDLED;
}
static u8 gpio_hostwakeup_alloc_irq(PADAPTER padapter)
{
int err;
if (oob_irq == 0)
return _FAIL;
/* dont set it IRQF_TRIGGER_LOW, or wowlan */
/* power is high after suspend */
/* and failing can prevent can not sleep issue if */
/* wifi gpio12 pin is not linked with CPU */
err = request_irq(oob_irq, gpio_hostwakeup_irq_thread,
#ifdef CONFIG_PLATFORM_HUAWEI_K3V2
IRQF_NO_SUSPEND | IRQF_TRIGGER_FALLING,
#else
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
#endif
"rtw_wifi_gpio_wakeup", padapter);
//err = request_threaded_irq(oob_irq, gpio_hostwakeup_irq_thread, NULL,
//IRQF_TRIGGER_FALLING,
//"rtw_wifi_gpio_wakeup", padapter);
if (err < 0) {
DBG_871X("Oops: can't allocate gpio irq %d err:%d\n", oob_irq, err);
return _FAIL;
} else {
DBG_871X("allocate gpio irq %d ok\n", oob_irq);
}
enable_irq_wake(oob_irq);
return _SUCCESS;
}
static void gpio_hostwakeup_free_irq(PADAPTER padapter)
{
if (oob_irq == 0)
return;
disable_irq_wake(oob_irq);
free_irq(oob_irq, padapter);
}
#endif
#ifdef CONFIG_PLATFORM_ARM_SUN4I
#if defined(CONFIG_MMC_SUNXI_POWER_CONTROL)
#ifdef CONFIG_RTL8723B
#define SDIOID 3
#endif
#ifdef CONFIG_RTL8188E
#define SDIOID (CONFIG_CHIP_ID==1123 ? 3 : 1)
#endif
#define SUNXI_SDIO_WIFI_NUM_RTL8189ES 10
#define SUNXI_SDIO_WIFI_NUM_RTL8723BS 11
extern void sunximmc_rescan_card(unsigned id, unsigned insert);
extern int mmc_pm_get_mod_type(void);
extern int mmc_pm_gpio_ctrl(char* name, int level);
/*
* rtl8189es_shdn = port:PH09<1><default><default><0>
* rtl8189es_wakeup = port:PH10<1><default><default><1>
* rtl8189es_vdd_en = port:PH11<1><default><default><0>
* rtl8189es_vcc_en = port:PH12<1><default><default><0>
*/
int rtl8723bs_sdio_powerup(void)
{
mmc_pm_gpio_ctrl("rtk_rtl8723bs_wl_dis", 1);
return 0;
}
int rtl8723bs_sdio_poweroff(void)
{
mmc_pm_gpio_ctrl("rtk_rtl8723bs_wl_dis", 0);
return 0;
}
int rtl8189es_sdio_powerup(void)
{
mmc_pm_gpio_ctrl("rtl8189es_vdd_en", 1);
udelay(100);
mmc_pm_gpio_ctrl("rtl8189es_vcc_en", 1);
udelay(50);
mmc_pm_gpio_ctrl("rtl8189es_shdn", 1);
return 0;
}
int rtl8189es_sdio_poweroff(void)
{
mmc_pm_gpio_ctrl("rtl8189es_shdn", 0);
mmc_pm_gpio_ctrl("rtl8189es_vcc_en", 0);
mmc_pm_gpio_ctrl("rtl8189es_vdd_en", 0);
return 0;
}
#endif //defined(CONFIG_MMC_SUNXI_POWER_CONTROL)
#endif //CONFIG_PLATFORM_ARM_SUN4I
#ifndef dev_to_sdio_func
#define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev)
#endif
#ifdef CONFIG_WOWLAN
static struct mmc_host *mmc_host = NULL;
#endif
static const struct sdio_device_id sdio_ids[] = {
#ifdef CONFIG_RTL8723A
{ SDIO_DEVICE(0x024c, 0x8723) },
#endif //CONFIG_RTL8723A
#ifdef CONFIG_RTL8723B
{ SDIO_DEVICE(0x024c, 0xB723) },
#endif
#ifdef CONFIG_RTL8188E
{ SDIO_DEVICE(0x024c, 0x8179) },
#endif //CONFIG_RTL8188E
#if defined(RTW_ENABLE_WIFI_CONTROL_FUNC) /* temporarily add this to accept all sdio wlan id */
{ SDIO_DEVICE_CLASS(SDIO_CLASS_WLAN) },
#endif
// { /* end: all zeroes */ },
};
static int rtw_drv_init(struct sdio_func *func, const struct sdio_device_id *id);
static void rtw_dev_remove(struct sdio_func *func);
static int rtw_sdio_resume(struct device *dev);
static int rtw_sdio_suspend(struct device *dev);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
static const struct dev_pm_ops rtw_sdio_pm_ops = {
.suspend = rtw_sdio_suspend,
.resume = rtw_sdio_resume,
};
#endif
struct sdio_drv_priv {
struct sdio_driver r871xs_drv;
int drv_registered;
};
static struct sdio_drv_priv sdio_drvpriv = {
.r871xs_drv.probe = rtw_drv_init,
.r871xs_drv.remove = rtw_dev_remove,
.r871xs_drv.name = (char*)DRV_NAME,
.r871xs_drv.id_table = sdio_ids,
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
.r871xs_drv.drv = {
.pm = &rtw_sdio_pm_ops,
}
#endif
};
static void sd_sync_int_hdl(struct sdio_func *func)
{
struct dvobj_priv *psdpriv;
psdpriv = sdio_get_drvdata(func);
if (!psdpriv->if1) {
DBG_871X("%s if1 == NULL\n", __func__);
return;
}
sd_int_hdl(psdpriv->if1);
}
int sdio_alloc_irq(struct dvobj_priv *dvobj)
{
PSDIO_DATA psdio_data;
struct sdio_func *func;
int err;
psdio_data = &dvobj->intf_data;
func = psdio_data->func;
sdio_claim_host(func);
err = sdio_claim_irq(func, &sd_sync_int_hdl);
if (err)
DBG_871X_LEVEL(_drv_err_,"%s: sdio_claim_irq FAIL(%d)!\n", __func__, err);
else
dvobj->irq_alloc = 1;
sdio_release_host(func);
return err?_FAIL:_SUCCESS;
}
void sdio_free_irq(struct dvobj_priv *dvobj)
{
PSDIO_DATA psdio_data;
struct sdio_func *func;
int err;
if (dvobj->irq_alloc) {
psdio_data = &dvobj->intf_data;
func = psdio_data->func;
if (func) {
sdio_claim_host(func);
err = sdio_release_irq(func);
if (err)
DBG_871X_LEVEL(_drv_err_,"%s: sdio_release_irq FAIL(%d)!\n", __func__, err);
sdio_release_host(func);
}
dvobj->irq_alloc = 0;
}
}
static u32 sdio_init(struct dvobj_priv *dvobj)
{
PSDIO_DATA psdio_data;
struct sdio_func *func;
int err;
_func_enter_;
psdio_data = &dvobj->intf_data;
func = psdio_data->func;
//3 1. init SDIO bus
sdio_claim_host(func);
err = sdio_enable_func(func);
if (err) {
DBG_871X_LEVEL(_drv_err_, "%s: sdio_enable_func FAIL(%d)!\n", __func__, err);
goto release;
}
err = sdio_set_block_size(func, 512);
if (err) {
DBG_871X_LEVEL(_drv_err_, "%s: sdio_set_block_size FAIL(%d)!\n", __func__, err);
goto release;
}
psdio_data->block_transfer_len = 512;
psdio_data->tx_block_mode = 1;
psdio_data->rx_block_mode = 1;
release:
sdio_release_host(func);
exit:
_func_exit_;
if (err) return _FAIL;
return _SUCCESS;
}
static void sdio_deinit(struct dvobj_priv *dvobj)
{
struct sdio_func *func;
int err;
RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+sdio_deinit\n"));
func = dvobj->intf_data.func;
if (func) {
sdio_claim_host(func);
err = sdio_disable_func(func);
if (err)
DBG_8192C(KERN_ERR "%s: sdio_disable_func(%d)\n", __func__, err);
if (dvobj->irq_alloc) {
err = sdio_release_irq(func);
if (err)
DBG_8192C(KERN_ERR "%s: sdio_release_irq(%d)\n", __func__, err);
}
sdio_release_host(func);
}
}
static struct dvobj_priv *sdio_dvobj_init(struct sdio_func *func)
{
int status = _FAIL;
struct dvobj_priv *dvobj = NULL;
PSDIO_DATA psdio;
_func_enter_;
if ((dvobj = (struct dvobj_priv*)rtw_zmalloc(sizeof(*dvobj))) == NULL) {
goto exit;
}
_rtw_mutex_init(&dvobj->hw_init_mutex);
_rtw_mutex_init(&dvobj->h2c_fwcmd_mutex);
_rtw_mutex_init(&dvobj->setch_mutex);
_rtw_mutex_init(&dvobj->setbw_mutex);
sdio_set_drvdata(func, dvobj);
psdio = &dvobj->intf_data;
psdio->func = func;
if (sdio_init(dvobj) != _SUCCESS) {
RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: initialize SDIO Failed!\n", __FUNCTION__));
goto free_dvobj;
}
status = _SUCCESS;
free_dvobj:
if (status != _SUCCESS && dvobj) {
sdio_set_drvdata(func, NULL);
_rtw_mutex_free(&dvobj->hw_init_mutex);
_rtw_mutex_free(&dvobj->h2c_fwcmd_mutex);
_rtw_mutex_free(&dvobj->setch_mutex);
_rtw_mutex_free(&dvobj->setbw_mutex);
rtw_mfree((u8*)dvobj, sizeof(*dvobj));
dvobj = NULL;
}
exit:
_func_exit_;
return dvobj;
}
static void sdio_dvobj_deinit(struct sdio_func *func)
{
struct dvobj_priv *dvobj = sdio_get_drvdata(func);
_func_enter_;
sdio_set_drvdata(func, NULL);
if (dvobj) {
sdio_deinit(dvobj);
_rtw_mutex_free(&dvobj->hw_init_mutex);
_rtw_mutex_free(&dvobj->h2c_fwcmd_mutex);
_rtw_mutex_free(&dvobj->setch_mutex);
_rtw_mutex_free(&dvobj->setbw_mutex);
rtw_mfree((u8*)dvobj, sizeof(*dvobj));
}
_func_exit_;
return;
}
static void decide_chip_type_by_device_id(PADAPTER padapter, u32 id)
{
padapter->chip_type = NULL_CHIP_TYPE;
#if 0
switch (id)
{
case 0x8723:
padapter->chip_type = RTL8723A;
padapter->HardwareType = HARDWARE_TYPE_RTL8723AS;
break;
case 0x8179:
padapter->chip_type = RTL8188E;
padapter->HardwareType = HARDWARE_TYPE_RTL8188ES;
break;
}
#else
#if defined(CONFIG_RTL8723A)
padapter->chip_type = RTL8723A;
padapter->HardwareType = HARDWARE_TYPE_RTL8723AS;
#elif defined(CONFIG_RTL8188E)
padapter->chip_type = RTL8188E;
padapter->HardwareType = HARDWARE_TYPE_RTL8188ES;
#elif defined(CONFIG_RTL8723B)
padapter->chip_type = RTL8723B;
padapter->HardwareType = HARDWARE_TYPE_RTL8723BS;
#endif
#endif
}
static void sd_intf_start(PADAPTER padapter)
{
if (padapter == NULL) {
DBG_8192C(KERN_ERR "%s: padapter is NULL!\n", __func__);
return;
}
// hal dep
rtw_hal_enable_interrupt(padapter);
}
static void sd_intf_stop(PADAPTER padapter)
{
if (padapter == NULL) {
DBG_8192C(KERN_ERR "%s: padapter is NULL!\n", __func__);
return;
}
// hal dep
rtw_hal_disable_interrupt(padapter);
}
/*
* Do deinit job corresponding to netdev_open()
*/
static void rtw_dev_unload(PADAPTER padapter)
{
struct net_device *pnetdev = (struct net_device*)padapter->pnetdev;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+rtw_dev_unload\n"));
if (padapter->bup == _TRUE)
{
// stop TX
// val8 = 0xFF;
// rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE,&val8);
#if 0
if (padapter->intf_stop)
padapter->intf_stop(padapter);
#else
sd_intf_stop(padapter);
#endif
padapter->bDriverStopped = _TRUE;
RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ rtw_dev_unload: stop intf complete!\n"));
if (!pwrctrlpriv->bInternalAutoSuspend)
rtw_stop_drv_threads(padapter);
RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ rtw_dev_unload: stop thread complete!\n"));
if (padapter->bSurpriseRemoved == _FALSE)
{
#ifdef CONFIG_WOWLAN
if (pwrctrlpriv->bSupportRemoteWakeup == _TRUE &&
pwrctrlpriv->wowlan_mode ==_TRUE) {
DBG_871X("%s bSupportWakeOnWlan==_TRUE do not run rtw_hal_deinit()\n",__FUNCTION__);
}
else
#endif
{
//amy modify 20120221 for power seq is different between driver open and ips
rtw_hal_deinit(padapter);
}
padapter->bSurpriseRemoved = _TRUE;
}
RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ rtw_dev_unload: deinit hal complelt!\n"));
padapter->bup = _FALSE;
}
else {
padapter->bDriverStopped = _TRUE;
RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("rtw_dev_unload: bup==_FALSE\n"));
}
RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("-rtw_dev_unload\n"));
}
_adapter *rtw_sdio_if1_init(struct dvobj_priv *dvobj, const struct sdio_device_id *pdid)
{
int status = _FAIL;
struct net_device *pnetdev;
PADAPTER padapter = NULL;
if ((padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter))) == NULL) {
goto exit;
}
padapter->dvobj = dvobj;
dvobj->if1 = padapter;
dvobj->padapters[dvobj->iface_nums++] = padapter;
padapter->iface_id = IFACE_ID0;
padapter->bDriverStopped=_TRUE;
padapter->drv_in_test = NO_TEST;
#if defined(CONFIG_CONCURRENT_MODE) || defined(CONFIG_DUALMAC_CONCURRENT)
//set adapter_type/iface type for primary padapter
padapter->isprimary = _TRUE;
padapter->adapter_type = PRIMARY_ADAPTER;
#ifndef CONFIG_HWPORT_SWAP
padapter->iface_type = IFACE_PORT0;
#else
padapter->iface_type = IFACE_PORT1;
#endif
#endif
padapter->interface_type = RTW_SDIO;
decide_chip_type_by_device_id(padapter, (u32)pdid->device);
//3 1. init network device data
pnetdev = rtw_init_netdev(padapter);
if (!pnetdev)
goto free_adapter;
SET_NETDEV_DEV(pnetdev, dvobj_to_dev(dvobj));
padapter = rtw_netdev_priv(pnetdev);
padapter->bDriverStopped=_TRUE;
#ifdef CONFIG_IOCTL_CFG80211
rtw_wdev_alloc(padapter, dvobj_to_dev(dvobj));
#endif
//3 3. init driver special setting, interface, OS and hardware relative
//4 3.1 set hardware operation functions
hal_set_hal_ops(padapter);
//3 5. initialize Chip version
padapter->intf_start = &sd_intf_start;
padapter->intf_stop = &sd_intf_stop;
if (rtw_init_io_priv(padapter, sdio_set_intf_ops) == _FAIL)
{
RT_TRACE(_module_hci_intfs_c_, _drv_err_,
("rtw_drv_init: Can't init io_priv\n"));
goto free_hal_data;
}
rtw_hal_read_chip_version(padapter);
rtw_hal_chip_configure(padapter);
//3 6. read efuse/eeprom data
rtw_hal_read_chip_info(padapter);
//3 7. init driver common data
if (rtw_init_drv_sw(padapter) == _FAIL) {
RT_TRACE(_module_hci_intfs_c_, _drv_err_,
("rtw_drv_init: Initialize driver software resource Failed!\n"));
goto free_hal_data;
}
//3 8. get WLan MAC address
// alloc dev name after read efuse.
rtw_init_netdev_name(pnetdev, padapter->registrypriv.ifname);
rtw_macaddr_cfg(padapter->eeprompriv.mac_addr);
rtw_init_wifidirect_addrs(padapter, padapter->eeprompriv.mac_addr, padapter->eeprompriv.mac_addr);
rtw_hal_disable_interrupt(padapter);
DBG_871X("bDriverStopped:%d, bSurpriseRemoved:%d, bup:%d, hw_init_completed:%d\n"
,padapter->bDriverStopped
,padapter->bSurpriseRemoved
,padapter->bup
,padapter->hw_init_completed
);
#ifdef CONFIG_HOSTAPD_MLME
hostapd_mode_init(padapter);
#endif
#ifdef CONFIG_PLATFORM_RTD2880B
DBG_871X("wlan link up\n");
rtd2885_wlan_netlink_sendMsg("linkup", "8712");
#endif
#ifdef RTK_DMP_PLATFORM
rtw_proc_init_one(pnetdev);
#endif
status = _SUCCESS;
free_hal_data:
if(status != _SUCCESS && padapter->HalData)
rtw_mfree(padapter->HalData, sizeof(*(padapter->HalData)));
free_wdev:
if(status != _SUCCESS) {
#ifdef CONFIG_IOCTL_CFG80211
rtw_wdev_unregister(padapter->rtw_wdev);
rtw_wdev_free(padapter->rtw_wdev);
#endif
}
free_adapter:
if (status != _SUCCESS) {
if (pnetdev)
rtw_free_netdev(pnetdev);
else if (padapter)
rtw_vmfree((u8*)padapter, sizeof(*padapter));
padapter = NULL;
}
exit:
return padapter;
}
static void rtw_sdio_if1_deinit(_adapter *if1)
{
struct net_device *pnetdev = if1->pnetdev;
struct mlme_priv *pmlmepriv= &if1->mlmepriv;
#if 0
#if defined(CONFIG_HAS_EARLYSUSPEND ) || defined(CONFIG_ANDROID_POWER)
rtw_unregister_early_suspend(adapter_to_pwrctl(if1));
#endif
if (if1->bSurpriseRemoved == _FALSE)
{
struct sdio_func *func = adapter_to_dvobj(if1)->intf_data.func;
// test surprise remove
int err;
sdio_claim_host(func);
sdio_readb(func, 0, &err);
sdio_release_host(func);
if (err == -ENOMEDIUM) {
if1->bSurpriseRemoved = _TRUE;
DBG_871X(KERN_NOTICE "%s: device had been removed!\n", __func__);
}
}
rtw_pm_set_ips(if1, IPS_NONE);
rtw_pm_set_lps(if1, PS_MODE_ACTIVE);
LeaveAllPowerSaveMode(if1);
#endif
if(check_fwstate(pmlmepriv, _FW_LINKED))
disconnect_hdl(if1, NULL);
#ifdef CONFIG_AP_MODE
//free_mlme_ap_info(if1);
#ifdef CONFIG_HOSTAPD_MLME
hostapd_mode_unload(if1);
#endif
#endif
if(if1->DriverState != DRIVER_DISAPPEAR) {
if(pnetdev) {
unregister_netdev(pnetdev); //will call netdev_close()
rtw_proc_remove_one(pnetdev);
}
}
rtw_cancel_all_timer(if1);
#ifdef CONFIG_WOWLAN
adapter_to_pwrctl(if1)->wowlan_mode=_FALSE;
DBG_871X("%s wowlan_mode:%d\n", __func__, adapter_to_pwrctl(if1)->wowlan_mode);
#endif //CONFIG_WOWLAN
rtw_dev_unload(if1);
DBG_871X("+r871xu_dev_remove, hw_init_completed=%d\n", if1->hw_init_completed);
rtw_handle_dualmac(if1, 0);
#ifdef CONFIG_AP_MODE
free_mlme_ap_info(if1);
#endif
#ifdef CONFIG_IOCTL_CFG80211
rtw_wdev_unregister(if1->rtw_wdev);
rtw_wdev_free(if1->rtw_wdev);
#endif
rtw_free_drv_sw(if1);
if(pnetdev)
rtw_free_netdev(pnetdev);
#ifdef CONFIG_PLATFORM_RTD2880B
DBG_871X("wlan link down\n");
rtd2885_wlan_netlink_sendMsg("linkdown", "8712");
#endif
}
#if (!(defined ANDROID_2X) && (defined CONFIG_PLATFORM_SPRD))
#if defined(CONFIG_PM_RUNTIME)
#include <linux/pm_runtime.h>
static void rtw_start_runtime(struct sdio_func *func)
{
unsigned long flags;
struct mmc_card *card = func->card;
struct mmc_host *host = card->host;
DBG_871X("%s \n", __func__);
pm_runtime_no_callbacks(&func->dev);
pm_suspend_ignore_children(&func->dev, true);
pm_runtime_set_autosuspend_delay(&func->dev, 100);
pm_runtime_use_autosuspend(&func->dev);
pm_runtime_put_autosuspend(&func->dev);
}
#endif // CONFIG_PM_RUNTIME
#endif // (!(defined ANDROID_2X) && (defined CONFIG_PLATFORM_SPRD))
/*
* drv_init() - a device potentially for us
*
* notes: drv_init() is called when the bus driver has located a card for us to support.
* We accept the new device by returning 0.
*/
static int rtw_drv_init(
struct sdio_func *func,
const struct sdio_device_id *id)
{
int status = _FAIL;
struct net_device *pnetdev;
PADAPTER if1 = NULL, if2 = NULL;
struct dvobj_priv *dvobj;
RT_TRACE(_module_hci_intfs_c_, _drv_info_,
("+rtw_drv_init: vendor=0x%04x device=0x%04x class=0x%02x\n",
func->vendor, func->device, func->class));
if ((dvobj = sdio_dvobj_init(func)) == NULL) {
RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("initialize device object priv Failed!\n"));
goto exit;
}
if ((if1 = rtw_sdio_if1_init(dvobj, id)) == NULL) {
DBG_871X("rtw_init_primary_adapter Failed!\n");
goto free_dvobj;
}
#ifdef CONFIG_CONCURRENT_MODE
if ((if2 = rtw_drv_if2_init(if1, sdio_set_intf_ops)) == NULL) {
goto free_if1;
}
#endif
//dev_alloc_name && register_netdev
if((status = rtw_drv_register_netdev(if1)) != _SUCCESS) {
goto free_if2;
}
if (sdio_alloc_irq(dvobj) != _SUCCESS)
goto free_if2;
#ifdef CONFIG_GLOBAL_UI_PID
if(ui_pid[1]!=0) {
DBG_871X("ui_pid[1]:%d\n",ui_pid[1]);
rtw_signal_process(ui_pid[1], SIGUSR2);
}
#endif
#if (!(defined ANDROID_2X) && (defined CONFIG_PLATFORM_SPRD))
#if defined(CONFIG_PM_RUNTIME)
//rtw_start_runtime(func);
#endif // CONFIG_PM_RUNTIME
#endif // (!(defined ANDROID_2X) && (defined CONFIG_PLATFORM_SPRD))
RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-871x_drv - drv_init, success!\n"));
status = _SUCCESS;
free_if2:
if(status != _SUCCESS && if2) {
#ifdef CONFIG_CONCURRENT_MODE
rtw_drv_if2_stop(if2);
rtw_drv_if2_free(if2);
#endif
}
free_if1:
if (status != _SUCCESS && if1) {
rtw_sdio_if1_deinit(if1);
}
free_dvobj:
if (status != _SUCCESS)
sdio_dvobj_deinit(func);
exit:
return status == _SUCCESS?0:-ENODEV;
}
static void rtw_dev_remove(struct sdio_func *func)
{
struct dvobj_priv *dvobj = sdio_get_drvdata(func);
struct pwrctrl_priv *pwrctl = dvobj_to_pwrctl(dvobj);
PADAPTER padapter = dvobj->if1;
_func_enter_;
RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+rtw_dev_remove\n"));
if (padapter->bSurpriseRemoved == _FALSE) {
int err;
/* test surprise remove */
sdio_claim_host(func);
sdio_readb(func, 0, &err);
sdio_release_host(func);
if (err == -ENOMEDIUM) {
padapter->bSurpriseRemoved = _TRUE;
DBG_871X(KERN_NOTICE "%s: device had been removed!\n", __func__);
}
}
#if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
rtw_unregister_early_suspend(pwrctl);
#endif
rtw_pm_set_ips(padapter, IPS_NONE);
rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
LeaveAllPowerSaveMode(padapter);
#ifdef CONFIG_CONCURRENT_MODE
rtw_drv_if2_stop(dvobj->if2);
#endif
rtw_sdio_if1_deinit(padapter);
#ifdef CONFIG_CONCURRENT_MODE
rtw_drv_if2_free(dvobj->if2);
#endif
sdio_dvobj_deinit(func);
RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("-rtw_dev_remove\n"));
_func_exit_;
}
#ifndef CONFIG_SUSPEND_NEW_FLOW
static int rtw_sdio_suspend(struct device *dev)
{
struct sdio_func *func =dev_to_sdio_func(dev);
struct dvobj_priv *psdpriv = sdio_get_drvdata(func);
_adapter *padapter = psdpriv->if1;
struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct net_device *pnetdev = padapter->pnetdev;
int ret = 0;
#ifdef CONFIG_PLATFORM_SPRD
u32 value;
#endif // CONFIG_PLATFORM_SPRD
#ifdef CONFIG_WOWLAN
struct wowlan_ioctl_param poidparam;
u8 ps_mode;
#endif //CONFIG_WOWLAN
u32 start_time = rtw_get_current_time();
_func_enter_;
DBG_871X_LEVEL(_drv_always_, "sdio suspend start\n");
DBG_871X("==> %s (%s:%d)\n",__FUNCTION__, current->comm, current->pid);
#if (!(defined ANDROID_2X) && (defined CONFIG_PLATFORM_SPRD))
if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
//we should not suspend softap, bcm also do like this
DBG_871X("%s should not suspend hw and system in AP mode\n",__FUNCTION__);
goto exit;
}
#endif
#ifdef CONFIG_WOWLAN
if (check_fwstate(pmlmepriv, _FW_LINKED))
pwrpriv->wowlan_mode = _TRUE;
else
pwrpriv->wowlan_mode = _FALSE;
#endif
//pwrpriv->bInSuspend = _TRUE;
while (pwrpriv->bips_processing == _TRUE)
rtw_msleep_os(1);
if((!padapter->bup) || (padapter->bDriverStopped)||(padapter->bSurpriseRemoved))
{
DBG_871X("%s bup=%d bDriverStopped=%d bSurpriseRemoved = %d\n", __FUNCTION__
,padapter->bup, padapter->bDriverStopped,padapter->bSurpriseRemoved);
goto exit;
}
rtw_cancel_all_timer(padapter);
LeaveAllPowerSaveMode(padapter);
//for power down during suspend, need leave ips mode before entering power down.
pwrpriv->bInSuspend = _TRUE;
pwrpriv->do_late_resume = _FALSE;
//padapter->net_closed = _TRUE;
//s1.
#ifdef CONFIG_WOWLAN
if(pnetdev && !pwrpriv->wowlan_mode)
{
netif_carrier_off(pnetdev);
rtw_netif_stop_queue(pnetdev);
} else if(pnetdev){
DBG_871X("wowlan_mode: NO netif_carrier_off\n");
rtw_netif_stop_queue(pnetdev);
}
#else
if(pnetdev)
{
netif_carrier_off(pnetdev);
rtw_netif_stop_queue(pnetdev);
}
#endif
#ifdef CONFIG_WOWLAN
DBG_871X("wowlan_mode: %d\n", pwrpriv->wowlan_mode);
if ((pwrpriv->bSupportRemoteWakeup == _TRUE) &&
(pwrpriv->wowlan_mode == _TRUE))
{
poidparam.subcode = WOWLAN_ENABLE;
padapter->HalFunc.SetHwRegHandler(padapter,HW_VAR_WOWLAN,(u8 *)&poidparam);
}
else
#endif // CONFIG_WOWLAN
{
//s2.
//s2-1. issue rtw_disassoc_cmd to fw
disconnect_hdl(padapter, NULL);
//rtw_disassoc_cmd(padapter);
}
/* WOWLAN dont need roaming */
#ifndef CONFIG_WOWLAN
#ifdef CONFIG_LAYER2_ROAMING_RESUME
if(check_fwstate(pmlmepriv, WIFI_STATION_STATE) && check_fwstate(pmlmepriv, _FW_LINKED) )
{
DBG_871X("%s %s(" MAC_FMT "), length:%d assoc_ssid.length:%d\n",__FUNCTION__,
pmlmepriv->cur_network.network.Ssid.Ssid,
MAC_ARG(pmlmepriv->cur_network.network.MacAddress),
pmlmepriv->cur_network.network.Ssid.SsidLength,
pmlmepriv->assoc_ssid.SsidLength);
pmlmepriv->to_roaming = 1;
}
#endif
#endif
#ifdef CONFIG_WOWLAN
if (!pwrpriv->wowlan_mode)
{