SAMA5D4 Xplained Ultra Board BSP
guowenxue
2019-08-19 2e7235d10c6dbff81960282e1a1e2e798f9b8db8
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
/******************************************************************************
 *
 * Copyright(c) 2007 - 2011 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
 *
 *
 ******************************************************************************/
/* ************************************************************
 * Description:
 *
 * This file is for 92CE/92CU dynamic mechanism only
 *
 *
 * ************************************************************ */
#define _RTL8188E_DM_C_
 
/* ************************************************************
 * include files
 * ************************************************************ */
#include <drv_types.h>
#include <rtl8188e_hal.h>
 
/* ************************************************************
 * Global var
 * ************************************************************ */
 
 
static VOID
dm_CheckProtection(
    IN    PADAPTER    Adapter
)
{
#if 0
    PMGNT_INFO        pMgntInfo = &(Adapter->MgntInfo);
    u1Byte            CurRate, RateThreshold;
 
    if (pMgntInfo->pHTInfo->bCurBW40MHz)
        RateThreshold = MGN_MCS1;
    else
        RateThreshold = MGN_MCS3;
 
    if (Adapter->TxStats.CurrentInitTxRate <= RateThreshold) {
        pMgntInfo->bDmDisableProtect = TRUE;
        dbg_print("Forced disable protect: %x\n", Adapter->TxStats.CurrentInitTxRate);
    } else {
        pMgntInfo->bDmDisableProtect = FALSE;
        dbg_print("Enable protect: %x\n", Adapter->TxStats.CurrentInitTxRate);
    }
#endif
}
 
static VOID
dm_CheckStatistics(
    IN    PADAPTER    Adapter
)
{
#if 0
    if (!Adapter->MgntInfo.bMediaConnect)
        return;
 
    /* 2008.12.10 tynli Add for getting Current_Tx_Rate_Reg flexibly. */
    rtw_hal_get_hwreg(Adapter, HW_VAR_INIT_TX_RATE, (pu1Byte)(&Adapter->TxStats.CurrentInitTxRate));
 
    /* Calculate current Tx Rate(Successful transmited!!) */
 
    /* Calculate current Rx Rate(Successful received!!) */
 
    /* for tx tx retry count */
    rtw_hal_get_hwreg(Adapter, HW_VAR_RETRY_COUNT, (pu1Byte)(&Adapter->TxStats.NumTxRetryCount));
#endif
}
 
#ifdef CONFIG_SUPPORT_HW_WPS_PBC
static void dm_CheckPbcGPIO(_adapter *padapter)
{
    u8    tmp1byte;
    u8    bPbcPressed = _FALSE;
 
    if (!padapter->registrypriv.hw_wps_pbc)
        return;
 
#ifdef CONFIG_USB_HCI
    tmp1byte = rtw_read8(padapter, GPIO_IO_SEL);
    tmp1byte |= (HAL_8188E_HW_GPIO_WPS_BIT);
    rtw_write8(padapter, GPIO_IO_SEL, tmp1byte);    /* enable GPIO[2] as output mode */
 
    tmp1byte &= ~(HAL_8188E_HW_GPIO_WPS_BIT);
    rtw_write8(padapter,  GPIO_IN, tmp1byte);        /* reset the floating voltage level */
 
    tmp1byte = rtw_read8(padapter, GPIO_IO_SEL);
    tmp1byte &= ~(HAL_8188E_HW_GPIO_WPS_BIT);
    rtw_write8(padapter, GPIO_IO_SEL, tmp1byte);    /* enable GPIO[2] as input mode */
 
    tmp1byte = rtw_read8(padapter, GPIO_IN);
 
    if (tmp1byte == 0xff)
        return ;
 
    if (tmp1byte & HAL_8188E_HW_GPIO_WPS_BIT)
        bPbcPressed = _TRUE;
#else
    tmp1byte = rtw_read8(padapter, GPIO_IN);
 
    if (tmp1byte == 0xff || padapter->init_adpt_in_progress)
        return ;
 
    if ((tmp1byte & HAL_8188E_HW_GPIO_WPS_BIT) == 0)
        bPbcPressed = _TRUE;
#endif
 
    if (_TRUE == bPbcPressed) {
        /* Here we only set bPbcPressed to true */
        /* After trigger PBC, the variable will be set to false */
        RTW_INFO("CheckPbcGPIO - PBC is pressed\n");
        rtw_request_wps_pbc_event(padapter);
    }
}
#endif/* #ifdef CONFIG_SUPPORT_HW_WPS_PBC */
 
#ifdef CONFIG_PCI_HCI
/*
 *    Description:
 *        Perform interrupt migration dynamically to reduce CPU utilization.
 *
 *    Assumption:
 *        1. Do not enable migration under WIFI test.
 *
 *    Created by Roger, 2010.03.05.
 *   */
VOID
dm_InterruptMigration(
    IN    PADAPTER    Adapter
)
{
    HAL_DATA_TYPE    *pHalData = GET_HAL_DATA(Adapter);
    struct mlme_priv    *pmlmepriv = &(Adapter->mlmepriv);
    BOOLEAN            bCurrentIntMt, bCurrentACIntDisable;
    BOOLEAN            IntMtToSet = _FALSE;
    BOOLEAN            ACIntToSet = _FALSE;
 
 
    /* Retrieve current interrupt migration and Tx four ACs IMR settings first. */
    bCurrentIntMt = pHalData->bInterruptMigration;
    bCurrentACIntDisable = pHalData->bDisableTxInt;
 
    /*  */
    /* <Roger_Notes> Currently we use busy traffic for reference instead of RxIntOK counts to prevent non-linear Rx statistics */
    /* when interrupt migration is set before. 2010.03.05. */
    /*  */
    if (!Adapter->registrypriv.wifi_spec &&
        (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) &&
        pmlmepriv->LinkDetectInfo.bHigherBusyTraffic) {
        IntMtToSet = _TRUE;
 
        /* To check whether we should disable Tx interrupt or not. */
        if (pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic)
            ACIntToSet = _TRUE;
    }
 
    /* Update current settings. */
    if (bCurrentIntMt != IntMtToSet) {
        RTW_INFO("%s(): Update interrrupt migration(%d)\n", __FUNCTION__, IntMtToSet);
        if (IntMtToSet) {
            /*  */
            /* <Roger_Notes> Set interrrupt migration timer and corresponging Tx/Rx counter. */
            /* timer 25ns*0xfa0=100us for 0xf packets. */
            /* 2010.03.05. */
            /*  */
            rtw_write32(Adapter, REG_INT_MIG, 0xff000fa0);/* 0x306:Rx, 0x307:Tx */
            pHalData->bInterruptMigration = IntMtToSet;
        } else {
            /* Reset all interrupt migration settings. */
            rtw_write32(Adapter, REG_INT_MIG, 0);
            pHalData->bInterruptMigration = IntMtToSet;
        }
    }
 
#if 0
    if (bCurrentACIntDisable != ACIntToSet) {
        RTW_INFO("%s(): Update AC interrrupt(%d)\n", __FUNCTION__, ACIntToSet);
        if (ACIntToSet) { /*  Disable four ACs interrupts. */
            /* */
            /*  <Roger_Notes> Disable VO, VI, BE and BK four AC interrupts to gain more efficient CPU utilization. */
            /*  When extremely highly Rx OK occurs, we will disable Tx interrupts. */
            /*  2010.03.05. */
            /* */
            UpdateInterruptMask8192CE(Adapter, 0, RT_AC_INT_MASKS);
            pHalData->bDisableTxInt = ACIntToSet;
        } else { /*  Enable four ACs interrupts. */
            UpdateInterruptMask8192CE(Adapter, RT_AC_INT_MASKS, 0);
            pHalData->bDisableTxInt = ACIntToSet;
        }
    }
#endif
 
}
 
#endif
 
/*
 * Initialize GPIO setting registers
 *   */
static void
dm_InitGPIOSetting(
    IN    PADAPTER    Adapter
)
{
    PHAL_DATA_TYPE        pHalData = GET_HAL_DATA(Adapter);
 
    u8    tmp1byte;
 
    tmp1byte = rtw_read8(Adapter, REG_GPIO_MUXCFG);
    tmp1byte &= (GPIOSEL_GPIO | ~GPIOSEL_ENBT);
 
    rtw_write8(Adapter, REG_GPIO_MUXCFG, tmp1byte);
 
}
 
/* ************************************************************
 * functions
 * ************************************************************ */
static void Init_ODM_ComInfo_88E(PADAPTER    Adapter)
{
    PHAL_DATA_TYPE    pHalData = GET_HAL_DATA(Adapter);
    struct PHY_DM_STRUCT        *pDM_Odm = &(pHalData->odmpriv);
    u32  SupportAbility = 0;
    u8    cut_ver, fab_ver;
 
    Init_ODM_ComInfo(Adapter);
 
    fab_ver = ODM_TSMC;
    cut_ver = ODM_CUT_A;
 
    if (IS_VENDOR_8188E_I_CUT_SERIES(Adapter))
        cut_ver = ODM_CUT_I;
 
    odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_FAB_VER, fab_ver);
    odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_CUT_VER, cut_ver);
 
#ifdef CONFIG_DISABLE_ODM
    SupportAbility = 0;
#else
    SupportAbility =    ODM_RF_CALIBRATION |
                ODM_RF_TX_PWR_TRACK
                ;
#endif
 
    odm_cmn_info_update(pDM_Odm, ODM_CMNINFO_ABILITY, SupportAbility);
 
}
static void Update_ODM_ComInfo_88E(PADAPTER    Adapter)
{
    PHAL_DATA_TYPE    pHalData = GET_HAL_DATA(Adapter);
    struct PHY_DM_STRUCT        *pDM_Odm = &(pHalData->odmpriv);
    u32  SupportAbility = 0;
    int i;
 
    SupportAbility = 0
             | ODM_BB_DIG
             | ODM_BB_RA_MASK
             | ODM_BB_DYNAMIC_TXPWR
             | ODM_BB_FA_CNT
             | ODM_BB_RSSI_MONITOR
             | ODM_BB_CCK_PD
             /* | ODM_BB_PWR_SAVE     */
             | ODM_BB_CFO_TRACKING
             | ODM_RF_CALIBRATION
             | ODM_RF_TX_PWR_TRACK
             | ODM_BB_NHM_CNT
             | ODM_BB_PRIMARY_CCA
             /*        | ODM_BB_PWR_TRAIN */
             ;
 
    if (rtw_odm_adaptivity_needed(Adapter) == _TRUE) {
        rtw_odm_adaptivity_config_msg(RTW_DBGDUMP, Adapter);
        SupportAbility |= ODM_BB_ADAPTIVITY;
    }
 
    if (!Adapter->registrypriv.qos_opt_enable)
        SupportAbility |= ODM_MAC_EDCA_TURBO;
 
#ifdef CONFIG_ANTENNA_DIVERSITY
    if (pHalData->AntDivCfg)
        SupportAbility |= ODM_BB_ANT_DIV;
#endif
 
#if (MP_DRIVER == 1)
    if (Adapter->registrypriv.mp_mode == 1) {
        SupportAbility = 0
                 | ODM_RF_CALIBRATION
                 | ODM_RF_TX_PWR_TRACK
                 ;
    }
#endif/* (MP_DRIVER==1) */
 
#ifdef CONFIG_DISABLE_ODM
    SupportAbility = 0;
#endif/* CONFIG_DISABLE_ODM */
 
    odm_cmn_info_update(pDM_Odm, ODM_CMNINFO_ABILITY, SupportAbility);
}
 
void
rtl8188e_InitHalDm(
    IN    PADAPTER    Adapter
)
{
    PHAL_DATA_TYPE    pHalData = GET_HAL_DATA(Adapter);
    struct PHY_DM_STRUCT        *pDM_Odm = &(pHalData->odmpriv);
    u8    i;
 
#ifdef CONFIG_USB_HCI
    dm_InitGPIOSetting(Adapter);
#endif
 
    pHalData->DM_Type = dm_type_by_driver;
 
    Update_ODM_ComInfo_88E(Adapter);
    odm_dm_init(pDM_Odm);
}
 
 
VOID
rtl8188e_HalDmWatchDog(
    IN    PADAPTER    Adapter
)
{
    BOOLEAN        bFwCurrentInPSMode = _FALSE;
    BOOLEAN        bFwPSAwake = _TRUE;
    PHAL_DATA_TYPE    pHalData = GET_HAL_DATA(Adapter);
    struct PHY_DM_STRUCT        *pDM_Odm = &(pHalData->odmpriv);
 
 
    if (!rtw_is_hw_init_completed(Adapter))
        goto skip_dm;
 
#ifdef CONFIG_LPS
    bFwCurrentInPSMode = adapter_to_pwrctl(Adapter)->bFwCurrentInPSMode;
    rtw_hal_get_hwreg(Adapter, HW_VAR_FWLPS_RF_ON, (u8 *)(&bFwPSAwake));
#endif
 
#ifdef CONFIG_P2P_PS
    /* Fw is under p2p powersaving mode, driver should stop dynamic mechanism. */
    /* modifed by thomas. 2011.06.11. */
    if (Adapter->wdinfo.p2p_ps_mode)
        bFwPSAwake = _FALSE;
#endif /* CONFIG_P2P_PS */
 
    if ((rtw_is_hw_init_completed(Adapter))
        && ((!bFwCurrentInPSMode) && bFwPSAwake)) {
        /*  */
        /* Calculate Tx/Rx statistics. */
        /*  */
        dm_CheckStatistics(Adapter);
 
        rtw_hal_check_rxfifo_full(Adapter);
        /*  */
        /* Dynamically switch RTS/CTS protection. */
        /*  */
        /* dm_CheckProtection(Adapter); */
 
#ifdef CONFIG_PCI_HCI
        /* 20100630 Joseph: Disable Interrupt Migration mechanism temporarily because it degrades Rx throughput. */
        /* Tx Migration settings. */
        /* dm_InterruptMigration(Adapter); */
 
        /* if(Adapter->hal_func.TxCheckStuckHandler(Adapter)) */
        /*    PlatformScheduleWorkItem(&(GET_HAL_DATA(Adapter)->HalResetWorkItem)); */
#endif
 
    }
 
 
    /* ODM */
    if (rtw_is_hw_init_completed(Adapter)) {
        u8    bLinked = _FALSE;
        u8    bsta_state = _FALSE;
#ifdef CONFIG_DISABLE_ODM
        pHalData->odmpriv.support_ability = 0;
#endif
 
        if (rtw_mi_check_status(Adapter, MI_ASSOC)) {
            bLinked = _TRUE;
            if (rtw_mi_check_status(Adapter, MI_STA_LINKED))
                bsta_state = _TRUE;
        }
 
        odm_cmn_info_update(&pHalData->odmpriv , ODM_CMNINFO_LINK, bLinked);
        odm_cmn_info_update(&pHalData->odmpriv , ODM_CMNINFO_STATION_STATE, bsta_state);
 
 
        odm_dm_watchdog(&pHalData->odmpriv);
 
    }
 
skip_dm:
 
#ifdef CONFIG_SUPPORT_HW_WPS_PBC
    /* Check GPIO to determine current Pbc status. */
    dm_CheckPbcGPIO(Adapter);
#endif
    return;
}
 
void rtl8188e_init_dm_priv(IN PADAPTER Adapter)
{
    PHAL_DATA_TYPE    pHalData = GET_HAL_DATA(Adapter);
    struct PHY_DM_STRUCT        *podmpriv = &pHalData->odmpriv;
 
    /* _rtw_spinlock_init(&(pHalData->odm_stainfo_lock)); */
    Init_ODM_ComInfo_88E(Adapter);
    odm_init_all_timers(podmpriv);
    
}
 
void rtl8188e_deinit_dm_priv(IN PADAPTER Adapter)
{
    PHAL_DATA_TYPE    pHalData = GET_HAL_DATA(Adapter);
    struct PHY_DM_STRUCT        *podmpriv = &pHalData->odmpriv;
    /* _rtw_spinlock_free(&pHalData->odm_stainfo_lock); */
    odm_cancel_all_timers(podmpriv);
}